fied 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bin.js +2 -4566
  2. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -1,4576 +1,12 @@
1
1
  #!/usr/bin/env node
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
- }) : x)(function(x) {
11
- if (typeof require !== "undefined") return require.apply(this, arguments);
12
- throw Error('Dynamic require of "' + x + '" is not supported');
13
- });
14
- var __commonJS = (cb, mod) => function __require2() {
15
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
- };
17
- var __copyProps = (to, from, except, desc) => {
18
- if (from && typeof from === "object" || typeof from === "function") {
19
- for (let key of __getOwnPropNames(from))
20
- if (!__hasOwnProp.call(to, key) && key !== except)
21
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
- }
23
- return to;
24
- };
25
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
- // If the importer is in node compatibility mode or this is not an ESM
27
- // file that has been converted to a CommonJS file using a Babel-
28
- // compatible transform (i.e. "__esModule" has not been set), then set
29
- // "default" to the CommonJS "module.exports" for node compatibility.
30
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
- mod
32
- ));
33
-
34
- // ../../node_modules/qrcode/lib/can-promise.js
35
- var require_can_promise = __commonJS({
36
- "../../node_modules/qrcode/lib/can-promise.js"(exports, module) {
37
- module.exports = function() {
38
- return typeof Promise === "function" && Promise.prototype && Promise.prototype.then;
39
- };
40
- }
41
- });
42
-
43
- // ../../node_modules/qrcode/lib/core/utils.js
44
- var require_utils = __commonJS({
45
- "../../node_modules/qrcode/lib/core/utils.js"(exports) {
46
- var toSJISFunction;
47
- var CODEWORDS_COUNT = [
48
- 0,
49
- // Not used
50
- 26,
51
- 44,
52
- 70,
53
- 100,
54
- 134,
55
- 172,
56
- 196,
57
- 242,
58
- 292,
59
- 346,
60
- 404,
61
- 466,
62
- 532,
63
- 581,
64
- 655,
65
- 733,
66
- 815,
67
- 901,
68
- 991,
69
- 1085,
70
- 1156,
71
- 1258,
72
- 1364,
73
- 1474,
74
- 1588,
75
- 1706,
76
- 1828,
77
- 1921,
78
- 2051,
79
- 2185,
80
- 2323,
81
- 2465,
82
- 2611,
83
- 2761,
84
- 2876,
85
- 3034,
86
- 3196,
87
- 3362,
88
- 3532,
89
- 3706
90
- ];
91
- exports.getSymbolSize = function getSymbolSize(version) {
92
- if (!version) throw new Error('"version" cannot be null or undefined');
93
- if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40');
94
- return version * 4 + 17;
95
- };
96
- exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
97
- return CODEWORDS_COUNT[version];
98
- };
99
- exports.getBCHDigit = function(data) {
100
- let digit = 0;
101
- while (data !== 0) {
102
- digit++;
103
- data >>>= 1;
104
- }
105
- return digit;
106
- };
107
- exports.setToSJISFunction = function setToSJISFunction(f) {
108
- if (typeof f !== "function") {
109
- throw new Error('"toSJISFunc" is not a valid function.');
110
- }
111
- toSJISFunction = f;
112
- };
113
- exports.isKanjiModeEnabled = function() {
114
- return typeof toSJISFunction !== "undefined";
115
- };
116
- exports.toSJIS = function toSJIS(kanji) {
117
- return toSJISFunction(kanji);
118
- };
119
- }
120
- });
121
-
122
- // ../../node_modules/qrcode/lib/core/error-correction-level.js
123
- var require_error_correction_level = __commonJS({
124
- "../../node_modules/qrcode/lib/core/error-correction-level.js"(exports) {
125
- exports.L = { bit: 1 };
126
- exports.M = { bit: 0 };
127
- exports.Q = { bit: 3 };
128
- exports.H = { bit: 2 };
129
- function fromString(string) {
130
- if (typeof string !== "string") {
131
- throw new Error("Param is not a string");
132
- }
133
- const lcStr = string.toLowerCase();
134
- switch (lcStr) {
135
- case "l":
136
- case "low":
137
- return exports.L;
138
- case "m":
139
- case "medium":
140
- return exports.M;
141
- case "q":
142
- case "quartile":
143
- return exports.Q;
144
- case "h":
145
- case "high":
146
- return exports.H;
147
- default:
148
- throw new Error("Unknown EC Level: " + string);
149
- }
150
- }
151
- exports.isValid = function isValid(level) {
152
- return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
153
- };
154
- exports.from = function from(value, defaultValue) {
155
- if (exports.isValid(value)) {
156
- return value;
157
- }
158
- try {
159
- return fromString(value);
160
- } catch (e) {
161
- return defaultValue;
162
- }
163
- };
164
- }
165
- });
166
-
167
- // ../../node_modules/qrcode/lib/core/bit-buffer.js
168
- var require_bit_buffer = __commonJS({
169
- "../../node_modules/qrcode/lib/core/bit-buffer.js"(exports, module) {
170
- function BitBuffer() {
171
- this.buffer = [];
172
- this.length = 0;
173
- }
174
- BitBuffer.prototype = {
175
- get: function(index) {
176
- const bufIndex = Math.floor(index / 8);
177
- return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
178
- },
179
- put: function(num, length) {
180
- for (let i = 0; i < length; i++) {
181
- this.putBit((num >>> length - i - 1 & 1) === 1);
182
- }
183
- },
184
- getLengthInBits: function() {
185
- return this.length;
186
- },
187
- putBit: function(bit) {
188
- const bufIndex = Math.floor(this.length / 8);
189
- if (this.buffer.length <= bufIndex) {
190
- this.buffer.push(0);
191
- }
192
- if (bit) {
193
- this.buffer[bufIndex] |= 128 >>> this.length % 8;
194
- }
195
- this.length++;
196
- }
197
- };
198
- module.exports = BitBuffer;
199
- }
200
- });
201
-
202
- // ../../node_modules/qrcode/lib/core/bit-matrix.js
203
- var require_bit_matrix = __commonJS({
204
- "../../node_modules/qrcode/lib/core/bit-matrix.js"(exports, module) {
205
- function BitMatrix(size) {
206
- if (!size || size < 1) {
207
- throw new Error("BitMatrix size must be defined and greater than 0");
208
- }
209
- this.size = size;
210
- this.data = new Uint8Array(size * size);
211
- this.reservedBit = new Uint8Array(size * size);
212
- }
213
- BitMatrix.prototype.set = function(row, col, value, reserved) {
214
- const index = row * this.size + col;
215
- this.data[index] = value;
216
- if (reserved) this.reservedBit[index] = true;
217
- };
218
- BitMatrix.prototype.get = function(row, col) {
219
- return this.data[row * this.size + col];
220
- };
221
- BitMatrix.prototype.xor = function(row, col, value) {
222
- this.data[row * this.size + col] ^= value;
223
- };
224
- BitMatrix.prototype.isReserved = function(row, col) {
225
- return this.reservedBit[row * this.size + col];
226
- };
227
- module.exports = BitMatrix;
228
- }
229
- });
230
-
231
- // ../../node_modules/qrcode/lib/core/alignment-pattern.js
232
- var require_alignment_pattern = __commonJS({
233
- "../../node_modules/qrcode/lib/core/alignment-pattern.js"(exports) {
234
- var getSymbolSize = require_utils().getSymbolSize;
235
- exports.getRowColCoords = function getRowColCoords(version) {
236
- if (version === 1) return [];
237
- const posCount = Math.floor(version / 7) + 2;
238
- const size = getSymbolSize(version);
239
- const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
240
- const positions = [size - 7];
241
- for (let i = 1; i < posCount - 1; i++) {
242
- positions[i] = positions[i - 1] - intervals;
243
- }
244
- positions.push(6);
245
- return positions.reverse();
246
- };
247
- exports.getPositions = function getPositions(version) {
248
- const coords = [];
249
- const pos = exports.getRowColCoords(version);
250
- const posLength = pos.length;
251
- for (let i = 0; i < posLength; i++) {
252
- for (let j = 0; j < posLength; j++) {
253
- if (i === 0 && j === 0 || // top-left
254
- i === 0 && j === posLength - 1 || // bottom-left
255
- i === posLength - 1 && j === 0) {
256
- continue;
257
- }
258
- coords.push([pos[i], pos[j]]);
259
- }
260
- }
261
- return coords;
262
- };
263
- }
264
- });
265
-
266
- // ../../node_modules/qrcode/lib/core/finder-pattern.js
267
- var require_finder_pattern = __commonJS({
268
- "../../node_modules/qrcode/lib/core/finder-pattern.js"(exports) {
269
- var getSymbolSize = require_utils().getSymbolSize;
270
- var FINDER_PATTERN_SIZE = 7;
271
- exports.getPositions = function getPositions(version) {
272
- const size = getSymbolSize(version);
273
- return [
274
- // top-left
275
- [0, 0],
276
- // top-right
277
- [size - FINDER_PATTERN_SIZE, 0],
278
- // bottom-left
279
- [0, size - FINDER_PATTERN_SIZE]
280
- ];
281
- };
282
- }
283
- });
284
-
285
- // ../../node_modules/qrcode/lib/core/mask-pattern.js
286
- var require_mask_pattern = __commonJS({
287
- "../../node_modules/qrcode/lib/core/mask-pattern.js"(exports) {
288
- exports.Patterns = {
289
- PATTERN000: 0,
290
- PATTERN001: 1,
291
- PATTERN010: 2,
292
- PATTERN011: 3,
293
- PATTERN100: 4,
294
- PATTERN101: 5,
295
- PATTERN110: 6,
296
- PATTERN111: 7
297
- };
298
- var PenaltyScores = {
299
- N1: 3,
300
- N2: 3,
301
- N3: 40,
302
- N4: 10
303
- };
304
- exports.isValid = function isValid(mask) {
305
- return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
306
- };
307
- exports.from = function from(value) {
308
- return exports.isValid(value) ? parseInt(value, 10) : void 0;
309
- };
310
- exports.getPenaltyN1 = function getPenaltyN1(data) {
311
- const size = data.size;
312
- let points = 0;
313
- let sameCountCol = 0;
314
- let sameCountRow = 0;
315
- let lastCol = null;
316
- let lastRow = null;
317
- for (let row = 0; row < size; row++) {
318
- sameCountCol = sameCountRow = 0;
319
- lastCol = lastRow = null;
320
- for (let col = 0; col < size; col++) {
321
- let module2 = data.get(row, col);
322
- if (module2 === lastCol) {
323
- sameCountCol++;
324
- } else {
325
- if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
326
- lastCol = module2;
327
- sameCountCol = 1;
328
- }
329
- module2 = data.get(col, row);
330
- if (module2 === lastRow) {
331
- sameCountRow++;
332
- } else {
333
- if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
334
- lastRow = module2;
335
- sameCountRow = 1;
336
- }
337
- }
338
- if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
339
- if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
340
- }
341
- return points;
342
- };
343
- exports.getPenaltyN2 = function getPenaltyN2(data) {
344
- const size = data.size;
345
- let points = 0;
346
- for (let row = 0; row < size - 1; row++) {
347
- for (let col = 0; col < size - 1; col++) {
348
- const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
349
- if (last === 4 || last === 0) points++;
350
- }
351
- }
352
- return points * PenaltyScores.N2;
353
- };
354
- exports.getPenaltyN3 = function getPenaltyN3(data) {
355
- const size = data.size;
356
- let points = 0;
357
- let bitsCol = 0;
358
- let bitsRow = 0;
359
- for (let row = 0; row < size; row++) {
360
- bitsCol = bitsRow = 0;
361
- for (let col = 0; col < size; col++) {
362
- bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
363
- if (col >= 10 && (bitsCol === 1488 || bitsCol === 93)) points++;
364
- bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
365
- if (col >= 10 && (bitsRow === 1488 || bitsRow === 93)) points++;
366
- }
367
- }
368
- return points * PenaltyScores.N3;
369
- };
370
- exports.getPenaltyN4 = function getPenaltyN4(data) {
371
- let darkCount = 0;
372
- const modulesCount = data.data.length;
373
- for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
374
- const k = Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10);
375
- return k * PenaltyScores.N4;
376
- };
377
- function getMaskAt(maskPattern, i, j) {
378
- switch (maskPattern) {
379
- case exports.Patterns.PATTERN000:
380
- return (i + j) % 2 === 0;
381
- case exports.Patterns.PATTERN001:
382
- return i % 2 === 0;
383
- case exports.Patterns.PATTERN010:
384
- return j % 3 === 0;
385
- case exports.Patterns.PATTERN011:
386
- return (i + j) % 3 === 0;
387
- case exports.Patterns.PATTERN100:
388
- return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
389
- case exports.Patterns.PATTERN101:
390
- return i * j % 2 + i * j % 3 === 0;
391
- case exports.Patterns.PATTERN110:
392
- return (i * j % 2 + i * j % 3) % 2 === 0;
393
- case exports.Patterns.PATTERN111:
394
- return (i * j % 3 + (i + j) % 2) % 2 === 0;
395
- default:
396
- throw new Error("bad maskPattern:" + maskPattern);
397
- }
398
- }
399
- exports.applyMask = function applyMask(pattern, data) {
400
- const size = data.size;
401
- for (let col = 0; col < size; col++) {
402
- for (let row = 0; row < size; row++) {
403
- if (data.isReserved(row, col)) continue;
404
- data.xor(row, col, getMaskAt(pattern, row, col));
405
- }
406
- }
407
- };
408
- exports.getBestMask = function getBestMask(data, setupFormatFunc) {
409
- const numPatterns = Object.keys(exports.Patterns).length;
410
- let bestPattern = 0;
411
- let lowerPenalty = Infinity;
412
- for (let p = 0; p < numPatterns; p++) {
413
- setupFormatFunc(p);
414
- exports.applyMask(p, data);
415
- const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
416
- exports.applyMask(p, data);
417
- if (penalty < lowerPenalty) {
418
- lowerPenalty = penalty;
419
- bestPattern = p;
420
- }
421
- }
422
- return bestPattern;
423
- };
424
- }
425
- });
426
-
427
- // ../../node_modules/qrcode/lib/core/error-correction-code.js
428
- var require_error_correction_code = __commonJS({
429
- "../../node_modules/qrcode/lib/core/error-correction-code.js"(exports) {
430
- var ECLevel = require_error_correction_level();
431
- var EC_BLOCKS_TABLE = [
432
- // L M Q H
433
- 1,
434
- 1,
435
- 1,
436
- 1,
437
- 1,
438
- 1,
439
- 1,
440
- 1,
441
- 1,
442
- 1,
443
- 2,
444
- 2,
445
- 1,
446
- 2,
447
- 2,
448
- 4,
449
- 1,
450
- 2,
451
- 4,
452
- 4,
453
- 2,
454
- 4,
455
- 4,
456
- 4,
457
- 2,
458
- 4,
459
- 6,
460
- 5,
461
- 2,
462
- 4,
463
- 6,
464
- 6,
465
- 2,
466
- 5,
467
- 8,
468
- 8,
469
- 4,
470
- 5,
471
- 8,
472
- 8,
473
- 4,
474
- 5,
475
- 8,
476
- 11,
477
- 4,
478
- 8,
479
- 10,
480
- 11,
481
- 4,
482
- 9,
483
- 12,
484
- 16,
485
- 4,
486
- 9,
487
- 16,
488
- 16,
489
- 6,
490
- 10,
491
- 12,
492
- 18,
493
- 6,
494
- 10,
495
- 17,
496
- 16,
497
- 6,
498
- 11,
499
- 16,
500
- 19,
501
- 6,
502
- 13,
503
- 18,
504
- 21,
505
- 7,
506
- 14,
507
- 21,
508
- 25,
509
- 8,
510
- 16,
511
- 20,
512
- 25,
513
- 8,
514
- 17,
515
- 23,
516
- 25,
517
- 9,
518
- 17,
519
- 23,
520
- 34,
521
- 9,
522
- 18,
523
- 25,
524
- 30,
525
- 10,
526
- 20,
527
- 27,
528
- 32,
529
- 12,
530
- 21,
531
- 29,
532
- 35,
533
- 12,
534
- 23,
535
- 34,
536
- 37,
537
- 12,
538
- 25,
539
- 34,
540
- 40,
541
- 13,
542
- 26,
543
- 35,
544
- 42,
545
- 14,
546
- 28,
547
- 38,
548
- 45,
549
- 15,
550
- 29,
551
- 40,
552
- 48,
553
- 16,
554
- 31,
555
- 43,
556
- 51,
557
- 17,
558
- 33,
559
- 45,
560
- 54,
561
- 18,
562
- 35,
563
- 48,
564
- 57,
565
- 19,
566
- 37,
567
- 51,
568
- 60,
569
- 19,
570
- 38,
571
- 53,
572
- 63,
573
- 20,
574
- 40,
575
- 56,
576
- 66,
577
- 21,
578
- 43,
579
- 59,
580
- 70,
581
- 22,
582
- 45,
583
- 62,
584
- 74,
585
- 24,
586
- 47,
587
- 65,
588
- 77,
589
- 25,
590
- 49,
591
- 68,
592
- 81
593
- ];
594
- var EC_CODEWORDS_TABLE = [
595
- // L M Q H
596
- 7,
597
- 10,
598
- 13,
599
- 17,
600
- 10,
601
- 16,
602
- 22,
603
- 28,
604
- 15,
605
- 26,
606
- 36,
607
- 44,
608
- 20,
609
- 36,
610
- 52,
611
- 64,
612
- 26,
613
- 48,
614
- 72,
615
- 88,
616
- 36,
617
- 64,
618
- 96,
619
- 112,
620
- 40,
621
- 72,
622
- 108,
623
- 130,
624
- 48,
625
- 88,
626
- 132,
627
- 156,
628
- 60,
629
- 110,
630
- 160,
631
- 192,
632
- 72,
633
- 130,
634
- 192,
635
- 224,
636
- 80,
637
- 150,
638
- 224,
639
- 264,
640
- 96,
641
- 176,
642
- 260,
643
- 308,
644
- 104,
645
- 198,
646
- 288,
647
- 352,
648
- 120,
649
- 216,
650
- 320,
651
- 384,
652
- 132,
653
- 240,
654
- 360,
655
- 432,
656
- 144,
657
- 280,
658
- 408,
659
- 480,
660
- 168,
661
- 308,
662
- 448,
663
- 532,
664
- 180,
665
- 338,
666
- 504,
667
- 588,
668
- 196,
669
- 364,
670
- 546,
671
- 650,
672
- 224,
673
- 416,
674
- 600,
675
- 700,
676
- 224,
677
- 442,
678
- 644,
679
- 750,
680
- 252,
681
- 476,
682
- 690,
683
- 816,
684
- 270,
685
- 504,
686
- 750,
687
- 900,
688
- 300,
689
- 560,
690
- 810,
691
- 960,
692
- 312,
693
- 588,
694
- 870,
695
- 1050,
696
- 336,
697
- 644,
698
- 952,
699
- 1110,
700
- 360,
701
- 700,
702
- 1020,
703
- 1200,
704
- 390,
705
- 728,
706
- 1050,
707
- 1260,
708
- 420,
709
- 784,
710
- 1140,
711
- 1350,
712
- 450,
713
- 812,
714
- 1200,
715
- 1440,
716
- 480,
717
- 868,
718
- 1290,
719
- 1530,
720
- 510,
721
- 924,
722
- 1350,
723
- 1620,
724
- 540,
725
- 980,
726
- 1440,
727
- 1710,
728
- 570,
729
- 1036,
730
- 1530,
731
- 1800,
732
- 570,
733
- 1064,
734
- 1590,
735
- 1890,
736
- 600,
737
- 1120,
738
- 1680,
739
- 1980,
740
- 630,
741
- 1204,
742
- 1770,
743
- 2100,
744
- 660,
745
- 1260,
746
- 1860,
747
- 2220,
748
- 720,
749
- 1316,
750
- 1950,
751
- 2310,
752
- 750,
753
- 1372,
754
- 2040,
755
- 2430
756
- ];
757
- exports.getBlocksCount = function getBlocksCount(version, errorCorrectionLevel) {
758
- switch (errorCorrectionLevel) {
759
- case ECLevel.L:
760
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
761
- case ECLevel.M:
762
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
763
- case ECLevel.Q:
764
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
765
- case ECLevel.H:
766
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
767
- default:
768
- return void 0;
769
- }
770
- };
771
- exports.getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel) {
772
- switch (errorCorrectionLevel) {
773
- case ECLevel.L:
774
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
775
- case ECLevel.M:
776
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
777
- case ECLevel.Q:
778
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
779
- case ECLevel.H:
780
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
781
- default:
782
- return void 0;
783
- }
784
- };
785
- }
786
- });
787
-
788
- // ../../node_modules/qrcode/lib/core/galois-field.js
789
- var require_galois_field = __commonJS({
790
- "../../node_modules/qrcode/lib/core/galois-field.js"(exports) {
791
- var EXP_TABLE = new Uint8Array(512);
792
- var LOG_TABLE = new Uint8Array(256);
793
- (function initTables() {
794
- let x = 1;
795
- for (let i = 0; i < 255; i++) {
796
- EXP_TABLE[i] = x;
797
- LOG_TABLE[x] = i;
798
- x <<= 1;
799
- if (x & 256) {
800
- x ^= 285;
801
- }
802
- }
803
- for (let i = 255; i < 512; i++) {
804
- EXP_TABLE[i] = EXP_TABLE[i - 255];
805
- }
806
- })();
807
- exports.log = function log(n) {
808
- if (n < 1) throw new Error("log(" + n + ")");
809
- return LOG_TABLE[n];
810
- };
811
- exports.exp = function exp(n) {
812
- return EXP_TABLE[n];
813
- };
814
- exports.mul = function mul(x, y) {
815
- if (x === 0 || y === 0) return 0;
816
- return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]];
817
- };
818
- }
819
- });
820
-
821
- // ../../node_modules/qrcode/lib/core/polynomial.js
822
- var require_polynomial = __commonJS({
823
- "../../node_modules/qrcode/lib/core/polynomial.js"(exports) {
824
- var GF = require_galois_field();
825
- exports.mul = function mul(p1, p2) {
826
- const coeff = new Uint8Array(p1.length + p2.length - 1);
827
- for (let i = 0; i < p1.length; i++) {
828
- for (let j = 0; j < p2.length; j++) {
829
- coeff[i + j] ^= GF.mul(p1[i], p2[j]);
830
- }
831
- }
832
- return coeff;
833
- };
834
- exports.mod = function mod(divident, divisor) {
835
- let result = new Uint8Array(divident);
836
- while (result.length - divisor.length >= 0) {
837
- const coeff = result[0];
838
- for (let i = 0; i < divisor.length; i++) {
839
- result[i] ^= GF.mul(divisor[i], coeff);
840
- }
841
- let offset = 0;
842
- while (offset < result.length && result[offset] === 0) offset++;
843
- result = result.slice(offset);
844
- }
845
- return result;
846
- };
847
- exports.generateECPolynomial = function generateECPolynomial(degree) {
848
- let poly = new Uint8Array([1]);
849
- for (let i = 0; i < degree; i++) {
850
- poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]));
851
- }
852
- return poly;
853
- };
854
- }
855
- });
856
-
857
- // ../../node_modules/qrcode/lib/core/reed-solomon-encoder.js
858
- var require_reed_solomon_encoder = __commonJS({
859
- "../../node_modules/qrcode/lib/core/reed-solomon-encoder.js"(exports, module) {
860
- var Polynomial = require_polynomial();
861
- function ReedSolomonEncoder(degree) {
862
- this.genPoly = void 0;
863
- this.degree = degree;
864
- if (this.degree) this.initialize(this.degree);
865
- }
866
- ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
867
- this.degree = degree;
868
- this.genPoly = Polynomial.generateECPolynomial(this.degree);
869
- };
870
- ReedSolomonEncoder.prototype.encode = function encode(data) {
871
- if (!this.genPoly) {
872
- throw new Error("Encoder not initialized");
873
- }
874
- const paddedData = new Uint8Array(data.length + this.degree);
875
- paddedData.set(data);
876
- const remainder = Polynomial.mod(paddedData, this.genPoly);
877
- const start = this.degree - remainder.length;
878
- if (start > 0) {
879
- const buff = new Uint8Array(this.degree);
880
- buff.set(remainder, start);
881
- return buff;
882
- }
883
- return remainder;
884
- };
885
- module.exports = ReedSolomonEncoder;
886
- }
887
- });
888
-
889
- // ../../node_modules/qrcode/lib/core/version-check.js
890
- var require_version_check = __commonJS({
891
- "../../node_modules/qrcode/lib/core/version-check.js"(exports) {
892
- exports.isValid = function isValid(version) {
893
- return !isNaN(version) && version >= 1 && version <= 40;
894
- };
895
- }
896
- });
897
-
898
- // ../../node_modules/qrcode/lib/core/regex.js
899
- var require_regex = __commonJS({
900
- "../../node_modules/qrcode/lib/core/regex.js"(exports) {
901
- var numeric = "[0-9]+";
902
- var alphanumeric = "[A-Z $%*+\\-./:]+";
903
- var kanji = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
904
- kanji = kanji.replace(/u/g, "\\u");
905
- var byte = "(?:(?![A-Z0-9 $%*+\\-./:]|" + kanji + ")(?:.|[\r\n]))+";
906
- exports.KANJI = new RegExp(kanji, "g");
907
- exports.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g");
908
- exports.BYTE = new RegExp(byte, "g");
909
- exports.NUMERIC = new RegExp(numeric, "g");
910
- exports.ALPHANUMERIC = new RegExp(alphanumeric, "g");
911
- var TEST_KANJI = new RegExp("^" + kanji + "$");
912
- var TEST_NUMERIC = new RegExp("^" + numeric + "$");
913
- var TEST_ALPHANUMERIC = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
914
- exports.testKanji = function testKanji(str) {
915
- return TEST_KANJI.test(str);
916
- };
917
- exports.testNumeric = function testNumeric(str) {
918
- return TEST_NUMERIC.test(str);
919
- };
920
- exports.testAlphanumeric = function testAlphanumeric(str) {
921
- return TEST_ALPHANUMERIC.test(str);
922
- };
923
- }
924
- });
925
-
926
- // ../../node_modules/qrcode/lib/core/mode.js
927
- var require_mode = __commonJS({
928
- "../../node_modules/qrcode/lib/core/mode.js"(exports) {
929
- var VersionCheck = require_version_check();
930
- var Regex = require_regex();
931
- exports.NUMERIC = {
932
- id: "Numeric",
933
- bit: 1 << 0,
934
- ccBits: [10, 12, 14]
935
- };
936
- exports.ALPHANUMERIC = {
937
- id: "Alphanumeric",
938
- bit: 1 << 1,
939
- ccBits: [9, 11, 13]
940
- };
941
- exports.BYTE = {
942
- id: "Byte",
943
- bit: 1 << 2,
944
- ccBits: [8, 16, 16]
945
- };
946
- exports.KANJI = {
947
- id: "Kanji",
948
- bit: 1 << 3,
949
- ccBits: [8, 10, 12]
950
- };
951
- exports.MIXED = {
952
- bit: -1
953
- };
954
- exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
955
- if (!mode.ccBits) throw new Error("Invalid mode: " + mode);
956
- if (!VersionCheck.isValid(version)) {
957
- throw new Error("Invalid version: " + version);
958
- }
959
- if (version >= 1 && version < 10) return mode.ccBits[0];
960
- else if (version < 27) return mode.ccBits[1];
961
- return mode.ccBits[2];
962
- };
963
- exports.getBestModeForData = function getBestModeForData(dataStr) {
964
- if (Regex.testNumeric(dataStr)) return exports.NUMERIC;
965
- else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC;
966
- else if (Regex.testKanji(dataStr)) return exports.KANJI;
967
- else return exports.BYTE;
968
- };
969
- exports.toString = function toString(mode) {
970
- if (mode && mode.id) return mode.id;
971
- throw new Error("Invalid mode");
972
- };
973
- exports.isValid = function isValid(mode) {
974
- return mode && mode.bit && mode.ccBits;
975
- };
976
- function fromString(string) {
977
- if (typeof string !== "string") {
978
- throw new Error("Param is not a string");
979
- }
980
- const lcStr = string.toLowerCase();
981
- switch (lcStr) {
982
- case "numeric":
983
- return exports.NUMERIC;
984
- case "alphanumeric":
985
- return exports.ALPHANUMERIC;
986
- case "kanji":
987
- return exports.KANJI;
988
- case "byte":
989
- return exports.BYTE;
990
- default:
991
- throw new Error("Unknown mode: " + string);
992
- }
993
- }
994
- exports.from = function from(value, defaultValue) {
995
- if (exports.isValid(value)) {
996
- return value;
997
- }
998
- try {
999
- return fromString(value);
1000
- } catch (e) {
1001
- return defaultValue;
1002
- }
1003
- };
1004
- }
1005
- });
1006
-
1007
- // ../../node_modules/qrcode/lib/core/version.js
1008
- var require_version = __commonJS({
1009
- "../../node_modules/qrcode/lib/core/version.js"(exports) {
1010
- var Utils = require_utils();
1011
- var ECCode = require_error_correction_code();
1012
- var ECLevel = require_error_correction_level();
1013
- var Mode = require_mode();
1014
- var VersionCheck = require_version_check();
1015
- var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
1016
- var G18_BCH = Utils.getBCHDigit(G18);
1017
- function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
1018
- for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1019
- if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
1020
- return currentVersion;
1021
- }
1022
- }
1023
- return void 0;
1024
- }
1025
- function getReservedBitsCount(mode, version) {
1026
- return Mode.getCharCountIndicator(mode, version) + 4;
1027
- }
1028
- function getTotalBitsFromDataArray(segments, version) {
1029
- let totalBits = 0;
1030
- segments.forEach(function(data) {
1031
- const reservedBits = getReservedBitsCount(data.mode, version);
1032
- totalBits += reservedBits + data.getBitsLength();
1033
- });
1034
- return totalBits;
1035
- }
1036
- function getBestVersionForMixedData(segments, errorCorrectionLevel) {
1037
- for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1038
- const length = getTotalBitsFromDataArray(segments, currentVersion);
1039
- if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
1040
- return currentVersion;
1041
- }
1042
- }
1043
- return void 0;
1044
- }
1045
- exports.from = function from(value, defaultValue) {
1046
- if (VersionCheck.isValid(value)) {
1047
- return parseInt(value, 10);
1048
- }
1049
- return defaultValue;
1050
- };
1051
- exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode) {
1052
- if (!VersionCheck.isValid(version)) {
1053
- throw new Error("Invalid QR Code version");
1054
- }
1055
- if (typeof mode === "undefined") mode = Mode.BYTE;
1056
- const totalCodewords = Utils.getSymbolTotalCodewords(version);
1057
- const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
1058
- const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
1059
- if (mode === Mode.MIXED) return dataTotalCodewordsBits;
1060
- const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
1061
- switch (mode) {
1062
- case Mode.NUMERIC:
1063
- return Math.floor(usableBits / 10 * 3);
1064
- case Mode.ALPHANUMERIC:
1065
- return Math.floor(usableBits / 11 * 2);
1066
- case Mode.KANJI:
1067
- return Math.floor(usableBits / 13);
1068
- case Mode.BYTE:
1069
- default:
1070
- return Math.floor(usableBits / 8);
1071
- }
1072
- };
1073
- exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel) {
1074
- let seg;
1075
- const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
1076
- if (Array.isArray(data)) {
1077
- if (data.length > 1) {
1078
- return getBestVersionForMixedData(data, ecl);
1079
- }
1080
- if (data.length === 0) {
1081
- return 1;
1082
- }
1083
- seg = data[0];
1084
- } else {
1085
- seg = data;
1086
- }
1087
- return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
1088
- };
1089
- exports.getEncodedBits = function getEncodedBits(version) {
1090
- if (!VersionCheck.isValid(version) || version < 7) {
1091
- throw new Error("Invalid QR Code version");
1092
- }
1093
- let d = version << 12;
1094
- while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
1095
- d ^= G18 << Utils.getBCHDigit(d) - G18_BCH;
1096
- }
1097
- return version << 12 | d;
1098
- };
1099
- }
1100
- });
1101
-
1102
- // ../../node_modules/qrcode/lib/core/format-info.js
1103
- var require_format_info = __commonJS({
1104
- "../../node_modules/qrcode/lib/core/format-info.js"(exports) {
1105
- var Utils = require_utils();
1106
- var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
1107
- var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
1108
- var G15_BCH = Utils.getBCHDigit(G15);
1109
- exports.getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
1110
- const data = errorCorrectionLevel.bit << 3 | mask;
1111
- let d = data << 10;
1112
- while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
1113
- d ^= G15 << Utils.getBCHDigit(d) - G15_BCH;
1114
- }
1115
- return (data << 10 | d) ^ G15_MASK;
1116
- };
1117
- }
1118
- });
1119
-
1120
- // ../../node_modules/qrcode/lib/core/numeric-data.js
1121
- var require_numeric_data = __commonJS({
1122
- "../../node_modules/qrcode/lib/core/numeric-data.js"(exports, module) {
1123
- var Mode = require_mode();
1124
- function NumericData(data) {
1125
- this.mode = Mode.NUMERIC;
1126
- this.data = data.toString();
1127
- }
1128
- NumericData.getBitsLength = function getBitsLength(length) {
1129
- return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
1130
- };
1131
- NumericData.prototype.getLength = function getLength() {
1132
- return this.data.length;
1133
- };
1134
- NumericData.prototype.getBitsLength = function getBitsLength() {
1135
- return NumericData.getBitsLength(this.data.length);
1136
- };
1137
- NumericData.prototype.write = function write(bitBuffer) {
1138
- let i, group, value;
1139
- for (i = 0; i + 3 <= this.data.length; i += 3) {
1140
- group = this.data.substr(i, 3);
1141
- value = parseInt(group, 10);
1142
- bitBuffer.put(value, 10);
1143
- }
1144
- const remainingNum = this.data.length - i;
1145
- if (remainingNum > 0) {
1146
- group = this.data.substr(i);
1147
- value = parseInt(group, 10);
1148
- bitBuffer.put(value, remainingNum * 3 + 1);
1149
- }
1150
- };
1151
- module.exports = NumericData;
1152
- }
1153
- });
1154
-
1155
- // ../../node_modules/qrcode/lib/core/alphanumeric-data.js
1156
- var require_alphanumeric_data = __commonJS({
1157
- "../../node_modules/qrcode/lib/core/alphanumeric-data.js"(exports, module) {
1158
- var Mode = require_mode();
1159
- var ALPHA_NUM_CHARS = [
1160
- "0",
1161
- "1",
1162
- "2",
1163
- "3",
1164
- "4",
1165
- "5",
1166
- "6",
1167
- "7",
1168
- "8",
1169
- "9",
1170
- "A",
1171
- "B",
1172
- "C",
1173
- "D",
1174
- "E",
1175
- "F",
1176
- "G",
1177
- "H",
1178
- "I",
1179
- "J",
1180
- "K",
1181
- "L",
1182
- "M",
1183
- "N",
1184
- "O",
1185
- "P",
1186
- "Q",
1187
- "R",
1188
- "S",
1189
- "T",
1190
- "U",
1191
- "V",
1192
- "W",
1193
- "X",
1194
- "Y",
1195
- "Z",
1196
- " ",
1197
- "$",
1198
- "%",
1199
- "*",
1200
- "+",
1201
- "-",
1202
- ".",
1203
- "/",
1204
- ":"
1205
- ];
1206
- function AlphanumericData(data) {
1207
- this.mode = Mode.ALPHANUMERIC;
1208
- this.data = data;
1209
- }
1210
- AlphanumericData.getBitsLength = function getBitsLength(length) {
1211
- return 11 * Math.floor(length / 2) + 6 * (length % 2);
1212
- };
1213
- AlphanumericData.prototype.getLength = function getLength() {
1214
- return this.data.length;
1215
- };
1216
- AlphanumericData.prototype.getBitsLength = function getBitsLength() {
1217
- return AlphanumericData.getBitsLength(this.data.length);
1218
- };
1219
- AlphanumericData.prototype.write = function write(bitBuffer) {
1220
- let i;
1221
- for (i = 0; i + 2 <= this.data.length; i += 2) {
1222
- let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
1223
- value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
1224
- bitBuffer.put(value, 11);
1225
- }
1226
- if (this.data.length % 2) {
1227
- bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
1228
- }
1229
- };
1230
- module.exports = AlphanumericData;
1231
- }
1232
- });
1233
-
1234
- // ../../node_modules/qrcode/lib/core/byte-data.js
1235
- var require_byte_data = __commonJS({
1236
- "../../node_modules/qrcode/lib/core/byte-data.js"(exports, module) {
1237
- var Mode = require_mode();
1238
- function ByteData(data) {
1239
- this.mode = Mode.BYTE;
1240
- if (typeof data === "string") {
1241
- this.data = new TextEncoder().encode(data);
1242
- } else {
1243
- this.data = new Uint8Array(data);
1244
- }
1245
- }
1246
- ByteData.getBitsLength = function getBitsLength(length) {
1247
- return length * 8;
1248
- };
1249
- ByteData.prototype.getLength = function getLength() {
1250
- return this.data.length;
1251
- };
1252
- ByteData.prototype.getBitsLength = function getBitsLength() {
1253
- return ByteData.getBitsLength(this.data.length);
1254
- };
1255
- ByteData.prototype.write = function(bitBuffer) {
1256
- for (let i = 0, l = this.data.length; i < l; i++) {
1257
- bitBuffer.put(this.data[i], 8);
1258
- }
1259
- };
1260
- module.exports = ByteData;
1261
- }
1262
- });
1263
-
1264
- // ../../node_modules/qrcode/lib/core/kanji-data.js
1265
- var require_kanji_data = __commonJS({
1266
- "../../node_modules/qrcode/lib/core/kanji-data.js"(exports, module) {
1267
- var Mode = require_mode();
1268
- var Utils = require_utils();
1269
- function KanjiData(data) {
1270
- this.mode = Mode.KANJI;
1271
- this.data = data;
1272
- }
1273
- KanjiData.getBitsLength = function getBitsLength(length) {
1274
- return length * 13;
1275
- };
1276
- KanjiData.prototype.getLength = function getLength() {
1277
- return this.data.length;
1278
- };
1279
- KanjiData.prototype.getBitsLength = function getBitsLength() {
1280
- return KanjiData.getBitsLength(this.data.length);
1281
- };
1282
- KanjiData.prototype.write = function(bitBuffer) {
1283
- let i;
1284
- for (i = 0; i < this.data.length; i++) {
1285
- let value = Utils.toSJIS(this.data[i]);
1286
- if (value >= 33088 && value <= 40956) {
1287
- value -= 33088;
1288
- } else if (value >= 57408 && value <= 60351) {
1289
- value -= 49472;
1290
- } else {
1291
- throw new Error(
1292
- "Invalid SJIS character: " + this.data[i] + "\nMake sure your charset is UTF-8"
1293
- );
1294
- }
1295
- value = (value >>> 8 & 255) * 192 + (value & 255);
1296
- bitBuffer.put(value, 13);
1297
- }
1298
- };
1299
- module.exports = KanjiData;
1300
- }
1301
- });
1302
-
1303
- // ../../node_modules/dijkstrajs/dijkstra.js
1304
- var require_dijkstra = __commonJS({
1305
- "../../node_modules/dijkstrajs/dijkstra.js"(exports, module) {
1306
- "use strict";
1307
- var dijkstra = {
1308
- single_source_shortest_paths: function(graph, s, d) {
1309
- var predecessors = {};
1310
- var costs = {};
1311
- costs[s] = 0;
1312
- var open = dijkstra.PriorityQueue.make();
1313
- open.push(s, 0);
1314
- var closest, u, v, cost_of_s_to_u, adjacent_nodes, cost_of_e, cost_of_s_to_u_plus_cost_of_e, cost_of_s_to_v, first_visit;
1315
- while (!open.empty()) {
1316
- closest = open.pop();
1317
- u = closest.value;
1318
- cost_of_s_to_u = closest.cost;
1319
- adjacent_nodes = graph[u] || {};
1320
- for (v in adjacent_nodes) {
1321
- if (adjacent_nodes.hasOwnProperty(v)) {
1322
- cost_of_e = adjacent_nodes[v];
1323
- cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
1324
- cost_of_s_to_v = costs[v];
1325
- first_visit = typeof costs[v] === "undefined";
1326
- if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
1327
- costs[v] = cost_of_s_to_u_plus_cost_of_e;
1328
- open.push(v, cost_of_s_to_u_plus_cost_of_e);
1329
- predecessors[v] = u;
1330
- }
1331
- }
1332
- }
1333
- }
1334
- if (typeof d !== "undefined" && typeof costs[d] === "undefined") {
1335
- var msg = ["Could not find a path from ", s, " to ", d, "."].join("");
1336
- throw new Error(msg);
1337
- }
1338
- return predecessors;
1339
- },
1340
- extract_shortest_path_from_predecessor_list: function(predecessors, d) {
1341
- var nodes = [];
1342
- var u = d;
1343
- var predecessor;
1344
- while (u) {
1345
- nodes.push(u);
1346
- predecessor = predecessors[u];
1347
- u = predecessors[u];
1348
- }
1349
- nodes.reverse();
1350
- return nodes;
1351
- },
1352
- find_path: function(graph, s, d) {
1353
- var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
1354
- return dijkstra.extract_shortest_path_from_predecessor_list(
1355
- predecessors,
1356
- d
1357
- );
1358
- },
1359
- /**
1360
- * A very naive priority queue implementation.
1361
- */
1362
- PriorityQueue: {
1363
- make: function(opts) {
1364
- var T = dijkstra.PriorityQueue, t = {}, key;
1365
- opts = opts || {};
1366
- for (key in T) {
1367
- if (T.hasOwnProperty(key)) {
1368
- t[key] = T[key];
1369
- }
1370
- }
1371
- t.queue = [];
1372
- t.sorter = opts.sorter || T.default_sorter;
1373
- return t;
1374
- },
1375
- default_sorter: function(a, b) {
1376
- return a.cost - b.cost;
1377
- },
1378
- /**
1379
- * Add a new item to the queue and ensure the highest priority element
1380
- * is at the front of the queue.
1381
- */
1382
- push: function(value, cost) {
1383
- var item = { value, cost };
1384
- this.queue.push(item);
1385
- this.queue.sort(this.sorter);
1386
- },
1387
- /**
1388
- * Return the highest priority element in the queue.
1389
- */
1390
- pop: function() {
1391
- return this.queue.shift();
1392
- },
1393
- empty: function() {
1394
- return this.queue.length === 0;
1395
- }
1396
- }
1397
- };
1398
- if (typeof module !== "undefined") {
1399
- module.exports = dijkstra;
1400
- }
1401
- }
1402
- });
1403
-
1404
- // ../../node_modules/qrcode/lib/core/segments.js
1405
- var require_segments = __commonJS({
1406
- "../../node_modules/qrcode/lib/core/segments.js"(exports) {
1407
- var Mode = require_mode();
1408
- var NumericData = require_numeric_data();
1409
- var AlphanumericData = require_alphanumeric_data();
1410
- var ByteData = require_byte_data();
1411
- var KanjiData = require_kanji_data();
1412
- var Regex = require_regex();
1413
- var Utils = require_utils();
1414
- var dijkstra = require_dijkstra();
1415
- function getStringByteLength(str) {
1416
- return unescape(encodeURIComponent(str)).length;
1417
- }
1418
- function getSegments(regex, mode, str) {
1419
- const segments = [];
1420
- let result;
1421
- while ((result = regex.exec(str)) !== null) {
1422
- segments.push({
1423
- data: result[0],
1424
- index: result.index,
1425
- mode,
1426
- length: result[0].length
1427
- });
1428
- }
1429
- return segments;
1430
- }
1431
- function getSegmentsFromString(dataStr) {
1432
- const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
1433
- const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
1434
- let byteSegs;
1435
- let kanjiSegs;
1436
- if (Utils.isKanjiModeEnabled()) {
1437
- byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
1438
- kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
1439
- } else {
1440
- byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
1441
- kanjiSegs = [];
1442
- }
1443
- const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
1444
- return segs.sort(function(s1, s2) {
1445
- return s1.index - s2.index;
1446
- }).map(function(obj) {
1447
- return {
1448
- data: obj.data,
1449
- mode: obj.mode,
1450
- length: obj.length
1451
- };
1452
- });
1453
- }
1454
- function getSegmentBitsLength(length, mode) {
1455
- switch (mode) {
1456
- case Mode.NUMERIC:
1457
- return NumericData.getBitsLength(length);
1458
- case Mode.ALPHANUMERIC:
1459
- return AlphanumericData.getBitsLength(length);
1460
- case Mode.KANJI:
1461
- return KanjiData.getBitsLength(length);
1462
- case Mode.BYTE:
1463
- return ByteData.getBitsLength(length);
1464
- }
1465
- }
1466
- function mergeSegments(segs) {
1467
- return segs.reduce(function(acc, curr) {
1468
- const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
1469
- if (prevSeg && prevSeg.mode === curr.mode) {
1470
- acc[acc.length - 1].data += curr.data;
1471
- return acc;
1472
- }
1473
- acc.push(curr);
1474
- return acc;
1475
- }, []);
1476
- }
1477
- function buildNodes(segs) {
1478
- const nodes = [];
1479
- for (let i = 0; i < segs.length; i++) {
1480
- const seg = segs[i];
1481
- switch (seg.mode) {
1482
- case Mode.NUMERIC:
1483
- nodes.push([
1484
- seg,
1485
- { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
1486
- { data: seg.data, mode: Mode.BYTE, length: seg.length }
1487
- ]);
1488
- break;
1489
- case Mode.ALPHANUMERIC:
1490
- nodes.push([
1491
- seg,
1492
- { data: seg.data, mode: Mode.BYTE, length: seg.length }
1493
- ]);
1494
- break;
1495
- case Mode.KANJI:
1496
- nodes.push([
1497
- seg,
1498
- { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
1499
- ]);
1500
- break;
1501
- case Mode.BYTE:
1502
- nodes.push([
1503
- { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
1504
- ]);
1505
- }
1506
- }
1507
- return nodes;
1508
- }
1509
- function buildGraph(nodes, version) {
1510
- const table = {};
1511
- const graph = { start: {} };
1512
- let prevNodeIds = ["start"];
1513
- for (let i = 0; i < nodes.length; i++) {
1514
- const nodeGroup = nodes[i];
1515
- const currentNodeIds = [];
1516
- for (let j = 0; j < nodeGroup.length; j++) {
1517
- const node = nodeGroup[j];
1518
- const key = "" + i + j;
1519
- currentNodeIds.push(key);
1520
- table[key] = { node, lastCount: 0 };
1521
- graph[key] = {};
1522
- for (let n = 0; n < prevNodeIds.length; n++) {
1523
- const prevNodeId = prevNodeIds[n];
1524
- if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
1525
- graph[prevNodeId][key] = getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
1526
- table[prevNodeId].lastCount += node.length;
1527
- } else {
1528
- if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
1529
- graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + Mode.getCharCountIndicator(node.mode, version);
1530
- }
1531
- }
1532
- }
1533
- prevNodeIds = currentNodeIds;
1534
- }
1535
- for (let n = 0; n < prevNodeIds.length; n++) {
1536
- graph[prevNodeIds[n]].end = 0;
1537
- }
1538
- return { map: graph, table };
1539
- }
1540
- function buildSingleSegment(data, modesHint) {
1541
- let mode;
1542
- const bestMode = Mode.getBestModeForData(data);
1543
- mode = Mode.from(modesHint, bestMode);
1544
- if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
1545
- throw new Error('"' + data + '" cannot be encoded with mode ' + Mode.toString(mode) + ".\n Suggested mode is: " + Mode.toString(bestMode));
1546
- }
1547
- if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
1548
- mode = Mode.BYTE;
1549
- }
1550
- switch (mode) {
1551
- case Mode.NUMERIC:
1552
- return new NumericData(data);
1553
- case Mode.ALPHANUMERIC:
1554
- return new AlphanumericData(data);
1555
- case Mode.KANJI:
1556
- return new KanjiData(data);
1557
- case Mode.BYTE:
1558
- return new ByteData(data);
1559
- }
1560
- }
1561
- exports.fromArray = function fromArray(array) {
1562
- return array.reduce(function(acc, seg) {
1563
- if (typeof seg === "string") {
1564
- acc.push(buildSingleSegment(seg, null));
1565
- } else if (seg.data) {
1566
- acc.push(buildSingleSegment(seg.data, seg.mode));
1567
- }
1568
- return acc;
1569
- }, []);
1570
- };
1571
- exports.fromString = function fromString(data, version) {
1572
- const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
1573
- const nodes = buildNodes(segs);
1574
- const graph = buildGraph(nodes, version);
1575
- const path = dijkstra.find_path(graph.map, "start", "end");
1576
- const optimizedSegs = [];
1577
- for (let i = 1; i < path.length - 1; i++) {
1578
- optimizedSegs.push(graph.table[path[i]].node);
1579
- }
1580
- return exports.fromArray(mergeSegments(optimizedSegs));
1581
- };
1582
- exports.rawSplit = function rawSplit(data) {
1583
- return exports.fromArray(
1584
- getSegmentsFromString(data, Utils.isKanjiModeEnabled())
1585
- );
1586
- };
1587
- }
1588
- });
1589
-
1590
- // ../../node_modules/qrcode/lib/core/qrcode.js
1591
- var require_qrcode = __commonJS({
1592
- "../../node_modules/qrcode/lib/core/qrcode.js"(exports) {
1593
- var Utils = require_utils();
1594
- var ECLevel = require_error_correction_level();
1595
- var BitBuffer = require_bit_buffer();
1596
- var BitMatrix = require_bit_matrix();
1597
- var AlignmentPattern = require_alignment_pattern();
1598
- var FinderPattern = require_finder_pattern();
1599
- var MaskPattern = require_mask_pattern();
1600
- var ECCode = require_error_correction_code();
1601
- var ReedSolomonEncoder = require_reed_solomon_encoder();
1602
- var Version = require_version();
1603
- var FormatInfo = require_format_info();
1604
- var Mode = require_mode();
1605
- var Segments = require_segments();
1606
- function setupFinderPattern(matrix, version) {
1607
- const size = matrix.size;
1608
- const pos = FinderPattern.getPositions(version);
1609
- for (let i = 0; i < pos.length; i++) {
1610
- const row = pos[i][0];
1611
- const col = pos[i][1];
1612
- for (let r = -1; r <= 7; r++) {
1613
- if (row + r <= -1 || size <= row + r) continue;
1614
- for (let c = -1; c <= 7; c++) {
1615
- if (col + c <= -1 || size <= col + c) continue;
1616
- if (r >= 0 && r <= 6 && (c === 0 || c === 6) || c >= 0 && c <= 6 && (r === 0 || r === 6) || r >= 2 && r <= 4 && c >= 2 && c <= 4) {
1617
- matrix.set(row + r, col + c, true, true);
1618
- } else {
1619
- matrix.set(row + r, col + c, false, true);
1620
- }
1621
- }
1622
- }
1623
- }
1624
- }
1625
- function setupTimingPattern(matrix) {
1626
- const size = matrix.size;
1627
- for (let r = 8; r < size - 8; r++) {
1628
- const value = r % 2 === 0;
1629
- matrix.set(r, 6, value, true);
1630
- matrix.set(6, r, value, true);
1631
- }
1632
- }
1633
- function setupAlignmentPattern(matrix, version) {
1634
- const pos = AlignmentPattern.getPositions(version);
1635
- for (let i = 0; i < pos.length; i++) {
1636
- const row = pos[i][0];
1637
- const col = pos[i][1];
1638
- for (let r = -2; r <= 2; r++) {
1639
- for (let c = -2; c <= 2; c++) {
1640
- if (r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0) {
1641
- matrix.set(row + r, col + c, true, true);
1642
- } else {
1643
- matrix.set(row + r, col + c, false, true);
1644
- }
1645
- }
1646
- }
1647
- }
1648
- }
1649
- function setupVersionInfo(matrix, version) {
1650
- const size = matrix.size;
1651
- const bits = Version.getEncodedBits(version);
1652
- let row, col, mod;
1653
- for (let i = 0; i < 18; i++) {
1654
- row = Math.floor(i / 3);
1655
- col = i % 3 + size - 8 - 3;
1656
- mod = (bits >> i & 1) === 1;
1657
- matrix.set(row, col, mod, true);
1658
- matrix.set(col, row, mod, true);
1659
- }
1660
- }
1661
- function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
1662
- const size = matrix.size;
1663
- const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
1664
- let i, mod;
1665
- for (i = 0; i < 15; i++) {
1666
- mod = (bits >> i & 1) === 1;
1667
- if (i < 6) {
1668
- matrix.set(i, 8, mod, true);
1669
- } else if (i < 8) {
1670
- matrix.set(i + 1, 8, mod, true);
1671
- } else {
1672
- matrix.set(size - 15 + i, 8, mod, true);
1673
- }
1674
- if (i < 8) {
1675
- matrix.set(8, size - i - 1, mod, true);
1676
- } else if (i < 9) {
1677
- matrix.set(8, 15 - i - 1 + 1, mod, true);
1678
- } else {
1679
- matrix.set(8, 15 - i - 1, mod, true);
1680
- }
1681
- }
1682
- matrix.set(size - 8, 8, 1, true);
1683
- }
1684
- function setupData(matrix, data) {
1685
- const size = matrix.size;
1686
- let inc = -1;
1687
- let row = size - 1;
1688
- let bitIndex = 7;
1689
- let byteIndex = 0;
1690
- for (let col = size - 1; col > 0; col -= 2) {
1691
- if (col === 6) col--;
1692
- while (true) {
1693
- for (let c = 0; c < 2; c++) {
1694
- if (!matrix.isReserved(row, col - c)) {
1695
- let dark = false;
1696
- if (byteIndex < data.length) {
1697
- dark = (data[byteIndex] >>> bitIndex & 1) === 1;
1698
- }
1699
- matrix.set(row, col - c, dark);
1700
- bitIndex--;
1701
- if (bitIndex === -1) {
1702
- byteIndex++;
1703
- bitIndex = 7;
1704
- }
1705
- }
1706
- }
1707
- row += inc;
1708
- if (row < 0 || size <= row) {
1709
- row -= inc;
1710
- inc = -inc;
1711
- break;
1712
- }
1713
- }
1714
- }
1715
- }
1716
- function createData(version, errorCorrectionLevel, segments) {
1717
- const buffer = new BitBuffer();
1718
- segments.forEach(function(data) {
1719
- buffer.put(data.mode.bit, 4);
1720
- buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
1721
- data.write(buffer);
1722
- });
1723
- const totalCodewords = Utils.getSymbolTotalCodewords(version);
1724
- const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
1725
- const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
1726
- if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
1727
- buffer.put(0, 4);
1728
- }
1729
- while (buffer.getLengthInBits() % 8 !== 0) {
1730
- buffer.putBit(0);
1731
- }
1732
- const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
1733
- for (let i = 0; i < remainingByte; i++) {
1734
- buffer.put(i % 2 ? 17 : 236, 8);
1735
- }
1736
- return createCodewords(buffer, version, errorCorrectionLevel);
1737
- }
1738
- function createCodewords(bitBuffer, version, errorCorrectionLevel) {
1739
- const totalCodewords = Utils.getSymbolTotalCodewords(version);
1740
- const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
1741
- const dataTotalCodewords = totalCodewords - ecTotalCodewords;
1742
- const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
1743
- const blocksInGroup2 = totalCodewords % ecTotalBlocks;
1744
- const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
1745
- const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
1746
- const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
1747
- const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
1748
- const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
1749
- const rs = new ReedSolomonEncoder(ecCount);
1750
- let offset = 0;
1751
- const dcData = new Array(ecTotalBlocks);
1752
- const ecData = new Array(ecTotalBlocks);
1753
- let maxDataSize = 0;
1754
- const buffer = new Uint8Array(bitBuffer.buffer);
1755
- for (let b = 0; b < ecTotalBlocks; b++) {
1756
- const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
1757
- dcData[b] = buffer.slice(offset, offset + dataSize);
1758
- ecData[b] = rs.encode(dcData[b]);
1759
- offset += dataSize;
1760
- maxDataSize = Math.max(maxDataSize, dataSize);
1761
- }
1762
- const data = new Uint8Array(totalCodewords);
1763
- let index = 0;
1764
- let i, r;
1765
- for (i = 0; i < maxDataSize; i++) {
1766
- for (r = 0; r < ecTotalBlocks; r++) {
1767
- if (i < dcData[r].length) {
1768
- data[index++] = dcData[r][i];
1769
- }
1770
- }
1771
- }
1772
- for (i = 0; i < ecCount; i++) {
1773
- for (r = 0; r < ecTotalBlocks; r++) {
1774
- data[index++] = ecData[r][i];
1775
- }
1776
- }
1777
- return data;
1778
- }
1779
- function createSymbol(data, version, errorCorrectionLevel, maskPattern) {
1780
- let segments;
1781
- if (Array.isArray(data)) {
1782
- segments = Segments.fromArray(data);
1783
- } else if (typeof data === "string") {
1784
- let estimatedVersion = version;
1785
- if (!estimatedVersion) {
1786
- const rawSegments = Segments.rawSplit(data);
1787
- estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
1788
- }
1789
- segments = Segments.fromString(data, estimatedVersion || 40);
1790
- } else {
1791
- throw new Error("Invalid data");
1792
- }
1793
- const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
1794
- if (!bestVersion) {
1795
- throw new Error("The amount of data is too big to be stored in a QR Code");
1796
- }
1797
- if (!version) {
1798
- version = bestVersion;
1799
- } else if (version < bestVersion) {
1800
- throw new Error(
1801
- "\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: " + bestVersion + ".\n"
1802
- );
1803
- }
1804
- const dataBits = createData(version, errorCorrectionLevel, segments);
1805
- const moduleCount = Utils.getSymbolSize(version);
1806
- const modules = new BitMatrix(moduleCount);
1807
- setupFinderPattern(modules, version);
1808
- setupTimingPattern(modules);
1809
- setupAlignmentPattern(modules, version);
1810
- setupFormatInfo(modules, errorCorrectionLevel, 0);
1811
- if (version >= 7) {
1812
- setupVersionInfo(modules, version);
1813
- }
1814
- setupData(modules, dataBits);
1815
- if (isNaN(maskPattern)) {
1816
- maskPattern = MaskPattern.getBestMask(
1817
- modules,
1818
- setupFormatInfo.bind(null, modules, errorCorrectionLevel)
1819
- );
1820
- }
1821
- MaskPattern.applyMask(maskPattern, modules);
1822
- setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
1823
- return {
1824
- modules,
1825
- version,
1826
- errorCorrectionLevel,
1827
- maskPattern,
1828
- segments
1829
- };
1830
- }
1831
- exports.create = function create(data, options) {
1832
- if (typeof data === "undefined" || data === "") {
1833
- throw new Error("No input text");
1834
- }
1835
- let errorCorrectionLevel = ECLevel.M;
1836
- let version;
1837
- let mask;
1838
- if (typeof options !== "undefined") {
1839
- errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
1840
- version = Version.from(options.version);
1841
- mask = MaskPattern.from(options.maskPattern);
1842
- if (options.toSJISFunc) {
1843
- Utils.setToSJISFunction(options.toSJISFunc);
1844
- }
1845
- }
1846
- return createSymbol(data, version, errorCorrectionLevel, mask);
1847
- };
1848
- }
1849
- });
1850
-
1851
- // ../../node_modules/pngjs/lib/chunkstream.js
1852
- var require_chunkstream = __commonJS({
1853
- "../../node_modules/pngjs/lib/chunkstream.js"(exports, module) {
1854
- "use strict";
1855
- var util = __require("util");
1856
- var Stream = __require("stream");
1857
- var ChunkStream = module.exports = function() {
1858
- Stream.call(this);
1859
- this._buffers = [];
1860
- this._buffered = 0;
1861
- this._reads = [];
1862
- this._paused = false;
1863
- this._encoding = "utf8";
1864
- this.writable = true;
1865
- };
1866
- util.inherits(ChunkStream, Stream);
1867
- ChunkStream.prototype.read = function(length, callback) {
1868
- this._reads.push({
1869
- length: Math.abs(length),
1870
- // if length < 0 then at most this length
1871
- allowLess: length < 0,
1872
- func: callback
1873
- });
1874
- process.nextTick(
1875
- function() {
1876
- this._process();
1877
- if (this._paused && this._reads && this._reads.length > 0) {
1878
- this._paused = false;
1879
- this.emit("drain");
1880
- }
1881
- }.bind(this)
1882
- );
1883
- };
1884
- ChunkStream.prototype.write = function(data, encoding) {
1885
- if (!this.writable) {
1886
- this.emit("error", new Error("Stream not writable"));
1887
- return false;
1888
- }
1889
- let dataBuffer;
1890
- if (Buffer.isBuffer(data)) {
1891
- dataBuffer = data;
1892
- } else {
1893
- dataBuffer = Buffer.from(data, encoding || this._encoding);
1894
- }
1895
- this._buffers.push(dataBuffer);
1896
- this._buffered += dataBuffer.length;
1897
- this._process();
1898
- if (this._reads && this._reads.length === 0) {
1899
- this._paused = true;
1900
- }
1901
- return this.writable && !this._paused;
1902
- };
1903
- ChunkStream.prototype.end = function(data, encoding) {
1904
- if (data) {
1905
- this.write(data, encoding);
1906
- }
1907
- this.writable = false;
1908
- if (!this._buffers) {
1909
- return;
1910
- }
1911
- if (this._buffers.length === 0) {
1912
- this._end();
1913
- } else {
1914
- this._buffers.push(null);
1915
- this._process();
1916
- }
1917
- };
1918
- ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
1919
- ChunkStream.prototype._end = function() {
1920
- if (this._reads.length > 0) {
1921
- this.emit("error", new Error("Unexpected end of input"));
1922
- }
1923
- this.destroy();
1924
- };
1925
- ChunkStream.prototype.destroy = function() {
1926
- if (!this._buffers) {
1927
- return;
1928
- }
1929
- this.writable = false;
1930
- this._reads = null;
1931
- this._buffers = null;
1932
- this.emit("close");
1933
- };
1934
- ChunkStream.prototype._processReadAllowingLess = function(read) {
1935
- this._reads.shift();
1936
- let smallerBuf = this._buffers[0];
1937
- if (smallerBuf.length > read.length) {
1938
- this._buffered -= read.length;
1939
- this._buffers[0] = smallerBuf.slice(read.length);
1940
- read.func.call(this, smallerBuf.slice(0, read.length));
1941
- } else {
1942
- this._buffered -= smallerBuf.length;
1943
- this._buffers.shift();
1944
- read.func.call(this, smallerBuf);
1945
- }
1946
- };
1947
- ChunkStream.prototype._processRead = function(read) {
1948
- this._reads.shift();
1949
- let pos = 0;
1950
- let count = 0;
1951
- let data = Buffer.alloc(read.length);
1952
- while (pos < read.length) {
1953
- let buf = this._buffers[count++];
1954
- let len = Math.min(buf.length, read.length - pos);
1955
- buf.copy(data, pos, 0, len);
1956
- pos += len;
1957
- if (len !== buf.length) {
1958
- this._buffers[--count] = buf.slice(len);
1959
- }
1960
- }
1961
- if (count > 0) {
1962
- this._buffers.splice(0, count);
1963
- }
1964
- this._buffered -= read.length;
1965
- read.func.call(this, data);
1966
- };
1967
- ChunkStream.prototype._process = function() {
1968
- try {
1969
- while (this._buffered > 0 && this._reads && this._reads.length > 0) {
1970
- let read = this._reads[0];
1971
- if (read.allowLess) {
1972
- this._processReadAllowingLess(read);
1973
- } else if (this._buffered >= read.length) {
1974
- this._processRead(read);
1975
- } else {
1976
- break;
1977
- }
1978
- }
1979
- if (this._buffers && !this.writable) {
1980
- this._end();
1981
- }
1982
- } catch (ex) {
1983
- this.emit("error", ex);
1984
- }
1985
- };
1986
- }
1987
- });
1988
-
1989
- // ../../node_modules/pngjs/lib/interlace.js
1990
- var require_interlace = __commonJS({
1991
- "../../node_modules/pngjs/lib/interlace.js"(exports) {
1992
- "use strict";
1993
- var imagePasses = [
1994
- {
1995
- // pass 1 - 1px
1996
- x: [0],
1997
- y: [0]
1998
- },
1999
- {
2000
- // pass 2 - 1px
2001
- x: [4],
2002
- y: [0]
2003
- },
2004
- {
2005
- // pass 3 - 2px
2006
- x: [0, 4],
2007
- y: [4]
2008
- },
2009
- {
2010
- // pass 4 - 4px
2011
- x: [2, 6],
2012
- y: [0, 4]
2013
- },
2014
- {
2015
- // pass 5 - 8px
2016
- x: [0, 2, 4, 6],
2017
- y: [2, 6]
2018
- },
2019
- {
2020
- // pass 6 - 16px
2021
- x: [1, 3, 5, 7],
2022
- y: [0, 2, 4, 6]
2023
- },
2024
- {
2025
- // pass 7 - 32px
2026
- x: [0, 1, 2, 3, 4, 5, 6, 7],
2027
- y: [1, 3, 5, 7]
2028
- }
2029
- ];
2030
- exports.getImagePasses = function(width, height) {
2031
- let images = [];
2032
- let xLeftOver = width % 8;
2033
- let yLeftOver = height % 8;
2034
- let xRepeats = (width - xLeftOver) / 8;
2035
- let yRepeats = (height - yLeftOver) / 8;
2036
- for (let i = 0; i < imagePasses.length; i++) {
2037
- let pass = imagePasses[i];
2038
- let passWidth = xRepeats * pass.x.length;
2039
- let passHeight = yRepeats * pass.y.length;
2040
- for (let j = 0; j < pass.x.length; j++) {
2041
- if (pass.x[j] < xLeftOver) {
2042
- passWidth++;
2043
- } else {
2044
- break;
2045
- }
2046
- }
2047
- for (let j = 0; j < pass.y.length; j++) {
2048
- if (pass.y[j] < yLeftOver) {
2049
- passHeight++;
2050
- } else {
2051
- break;
2052
- }
2053
- }
2054
- if (passWidth > 0 && passHeight > 0) {
2055
- images.push({ width: passWidth, height: passHeight, index: i });
2056
- }
2057
- }
2058
- return images;
2059
- };
2060
- exports.getInterlaceIterator = function(width) {
2061
- return function(x, y, pass) {
2062
- let outerXLeftOver = x % imagePasses[pass].x.length;
2063
- let outerX = (x - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
2064
- let outerYLeftOver = y % imagePasses[pass].y.length;
2065
- let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
2066
- return outerX * 4 + outerY * width * 4;
2067
- };
2068
- };
2069
- }
2070
- });
2071
-
2072
- // ../../node_modules/pngjs/lib/paeth-predictor.js
2073
- var require_paeth_predictor = __commonJS({
2074
- "../../node_modules/pngjs/lib/paeth-predictor.js"(exports, module) {
2075
- "use strict";
2076
- module.exports = function paethPredictor(left, above, upLeft) {
2077
- let paeth = left + above - upLeft;
2078
- let pLeft = Math.abs(paeth - left);
2079
- let pAbove = Math.abs(paeth - above);
2080
- let pUpLeft = Math.abs(paeth - upLeft);
2081
- if (pLeft <= pAbove && pLeft <= pUpLeft) {
2082
- return left;
2083
- }
2084
- if (pAbove <= pUpLeft) {
2085
- return above;
2086
- }
2087
- return upLeft;
2088
- };
2089
- }
2090
- });
2091
-
2092
- // ../../node_modules/pngjs/lib/filter-parse.js
2093
- var require_filter_parse = __commonJS({
2094
- "../../node_modules/pngjs/lib/filter-parse.js"(exports, module) {
2095
- "use strict";
2096
- var interlaceUtils = require_interlace();
2097
- var paethPredictor = require_paeth_predictor();
2098
- function getByteWidth(width, bpp, depth) {
2099
- let byteWidth = width * bpp;
2100
- if (depth !== 8) {
2101
- byteWidth = Math.ceil(byteWidth / (8 / depth));
2102
- }
2103
- return byteWidth;
2104
- }
2105
- var Filter = module.exports = function(bitmapInfo, dependencies) {
2106
- let width = bitmapInfo.width;
2107
- let height = bitmapInfo.height;
2108
- let interlace = bitmapInfo.interlace;
2109
- let bpp = bitmapInfo.bpp;
2110
- let depth = bitmapInfo.depth;
2111
- this.read = dependencies.read;
2112
- this.write = dependencies.write;
2113
- this.complete = dependencies.complete;
2114
- this._imageIndex = 0;
2115
- this._images = [];
2116
- if (interlace) {
2117
- let passes = interlaceUtils.getImagePasses(width, height);
2118
- for (let i = 0; i < passes.length; i++) {
2119
- this._images.push({
2120
- byteWidth: getByteWidth(passes[i].width, bpp, depth),
2121
- height: passes[i].height,
2122
- lineIndex: 0
2123
- });
2124
- }
2125
- } else {
2126
- this._images.push({
2127
- byteWidth: getByteWidth(width, bpp, depth),
2128
- height,
2129
- lineIndex: 0
2130
- });
2131
- }
2132
- if (depth === 8) {
2133
- this._xComparison = bpp;
2134
- } else if (depth === 16) {
2135
- this._xComparison = bpp * 2;
2136
- } else {
2137
- this._xComparison = 1;
2138
- }
2139
- };
2140
- Filter.prototype.start = function() {
2141
- this.read(
2142
- this._images[this._imageIndex].byteWidth + 1,
2143
- this._reverseFilterLine.bind(this)
2144
- );
2145
- };
2146
- Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
2147
- let xComparison = this._xComparison;
2148
- let xBiggerThan = xComparison - 1;
2149
- for (let x = 0; x < byteWidth; x++) {
2150
- let rawByte = rawData[1 + x];
2151
- let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
2152
- unfilteredLine[x] = rawByte + f1Left;
2153
- }
2154
- };
2155
- Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
2156
- let lastLine = this._lastLine;
2157
- for (let x = 0; x < byteWidth; x++) {
2158
- let rawByte = rawData[1 + x];
2159
- let f2Up = lastLine ? lastLine[x] : 0;
2160
- unfilteredLine[x] = rawByte + f2Up;
2161
- }
2162
- };
2163
- Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
2164
- let xComparison = this._xComparison;
2165
- let xBiggerThan = xComparison - 1;
2166
- let lastLine = this._lastLine;
2167
- for (let x = 0; x < byteWidth; x++) {
2168
- let rawByte = rawData[1 + x];
2169
- let f3Up = lastLine ? lastLine[x] : 0;
2170
- let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
2171
- let f3Add = Math.floor((f3Left + f3Up) / 2);
2172
- unfilteredLine[x] = rawByte + f3Add;
2173
- }
2174
- };
2175
- Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
2176
- let xComparison = this._xComparison;
2177
- let xBiggerThan = xComparison - 1;
2178
- let lastLine = this._lastLine;
2179
- for (let x = 0; x < byteWidth; x++) {
2180
- let rawByte = rawData[1 + x];
2181
- let f4Up = lastLine ? lastLine[x] : 0;
2182
- let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
2183
- let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
2184
- let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
2185
- unfilteredLine[x] = rawByte + f4Add;
2186
- }
2187
- };
2188
- Filter.prototype._reverseFilterLine = function(rawData) {
2189
- let filter = rawData[0];
2190
- let unfilteredLine;
2191
- let currentImage = this._images[this._imageIndex];
2192
- let byteWidth = currentImage.byteWidth;
2193
- if (filter === 0) {
2194
- unfilteredLine = rawData.slice(1, byteWidth + 1);
2195
- } else {
2196
- unfilteredLine = Buffer.alloc(byteWidth);
2197
- switch (filter) {
2198
- case 1:
2199
- this._unFilterType1(rawData, unfilteredLine, byteWidth);
2200
- break;
2201
- case 2:
2202
- this._unFilterType2(rawData, unfilteredLine, byteWidth);
2203
- break;
2204
- case 3:
2205
- this._unFilterType3(rawData, unfilteredLine, byteWidth);
2206
- break;
2207
- case 4:
2208
- this._unFilterType4(rawData, unfilteredLine, byteWidth);
2209
- break;
2210
- default:
2211
- throw new Error("Unrecognised filter type - " + filter);
2212
- }
2213
- }
2214
- this.write(unfilteredLine);
2215
- currentImage.lineIndex++;
2216
- if (currentImage.lineIndex >= currentImage.height) {
2217
- this._lastLine = null;
2218
- this._imageIndex++;
2219
- currentImage = this._images[this._imageIndex];
2220
- } else {
2221
- this._lastLine = unfilteredLine;
2222
- }
2223
- if (currentImage) {
2224
- this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
2225
- } else {
2226
- this._lastLine = null;
2227
- this.complete();
2228
- }
2229
- };
2230
- }
2231
- });
2232
-
2233
- // ../../node_modules/pngjs/lib/filter-parse-async.js
2234
- var require_filter_parse_async = __commonJS({
2235
- "../../node_modules/pngjs/lib/filter-parse-async.js"(exports, module) {
2236
- "use strict";
2237
- var util = __require("util");
2238
- var ChunkStream = require_chunkstream();
2239
- var Filter = require_filter_parse();
2240
- var FilterAsync = module.exports = function(bitmapInfo) {
2241
- ChunkStream.call(this);
2242
- let buffers = [];
2243
- let that = this;
2244
- this._filter = new Filter(bitmapInfo, {
2245
- read: this.read.bind(this),
2246
- write: function(buffer) {
2247
- buffers.push(buffer);
2248
- },
2249
- complete: function() {
2250
- that.emit("complete", Buffer.concat(buffers));
2251
- }
2252
- });
2253
- this._filter.start();
2254
- };
2255
- util.inherits(FilterAsync, ChunkStream);
2256
- }
2257
- });
2258
-
2259
- // ../../node_modules/pngjs/lib/constants.js
2260
- var require_constants = __commonJS({
2261
- "../../node_modules/pngjs/lib/constants.js"(exports, module) {
2262
- "use strict";
2263
- module.exports = {
2264
- PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
2265
- TYPE_IHDR: 1229472850,
2266
- TYPE_IEND: 1229278788,
2267
- TYPE_IDAT: 1229209940,
2268
- TYPE_PLTE: 1347179589,
2269
- TYPE_tRNS: 1951551059,
2270
- // eslint-disable-line camelcase
2271
- TYPE_gAMA: 1732332865,
2272
- // eslint-disable-line camelcase
2273
- // color-type bits
2274
- COLORTYPE_GRAYSCALE: 0,
2275
- COLORTYPE_PALETTE: 1,
2276
- COLORTYPE_COLOR: 2,
2277
- COLORTYPE_ALPHA: 4,
2278
- // e.g. grayscale and alpha
2279
- // color-type combinations
2280
- COLORTYPE_PALETTE_COLOR: 3,
2281
- COLORTYPE_COLOR_ALPHA: 6,
2282
- COLORTYPE_TO_BPP_MAP: {
2283
- 0: 1,
2284
- 2: 3,
2285
- 3: 1,
2286
- 4: 2,
2287
- 6: 4
2288
- },
2289
- GAMMA_DIVISION: 1e5
2290
- };
2291
- }
2292
- });
2293
-
2294
- // ../../node_modules/pngjs/lib/crc.js
2295
- var require_crc = __commonJS({
2296
- "../../node_modules/pngjs/lib/crc.js"(exports, module) {
2297
- "use strict";
2298
- var crcTable = [];
2299
- (function() {
2300
- for (let i = 0; i < 256; i++) {
2301
- let currentCrc = i;
2302
- for (let j = 0; j < 8; j++) {
2303
- if (currentCrc & 1) {
2304
- currentCrc = 3988292384 ^ currentCrc >>> 1;
2305
- } else {
2306
- currentCrc = currentCrc >>> 1;
2307
- }
2308
- }
2309
- crcTable[i] = currentCrc;
2310
- }
2311
- })();
2312
- var CrcCalculator = module.exports = function() {
2313
- this._crc = -1;
2314
- };
2315
- CrcCalculator.prototype.write = function(data) {
2316
- for (let i = 0; i < data.length; i++) {
2317
- this._crc = crcTable[(this._crc ^ data[i]) & 255] ^ this._crc >>> 8;
2318
- }
2319
- return true;
2320
- };
2321
- CrcCalculator.prototype.crc32 = function() {
2322
- return this._crc ^ -1;
2323
- };
2324
- CrcCalculator.crc32 = function(buf) {
2325
- let crc = -1;
2326
- for (let i = 0; i < buf.length; i++) {
2327
- crc = crcTable[(crc ^ buf[i]) & 255] ^ crc >>> 8;
2328
- }
2329
- return crc ^ -1;
2330
- };
2331
- }
2332
- });
2333
-
2334
- // ../../node_modules/pngjs/lib/parser.js
2335
- var require_parser = __commonJS({
2336
- "../../node_modules/pngjs/lib/parser.js"(exports, module) {
2337
- "use strict";
2338
- var constants = require_constants();
2339
- var CrcCalculator = require_crc();
2340
- var Parser = module.exports = function(options, dependencies) {
2341
- this._options = options;
2342
- options.checkCRC = options.checkCRC !== false;
2343
- this._hasIHDR = false;
2344
- this._hasIEND = false;
2345
- this._emittedHeadersFinished = false;
2346
- this._palette = [];
2347
- this._colorType = 0;
2348
- this._chunks = {};
2349
- this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
2350
- this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
2351
- this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
2352
- this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
2353
- this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
2354
- this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
2355
- this.read = dependencies.read;
2356
- this.error = dependencies.error;
2357
- this.metadata = dependencies.metadata;
2358
- this.gamma = dependencies.gamma;
2359
- this.transColor = dependencies.transColor;
2360
- this.palette = dependencies.palette;
2361
- this.parsed = dependencies.parsed;
2362
- this.inflateData = dependencies.inflateData;
2363
- this.finished = dependencies.finished;
2364
- this.simpleTransparency = dependencies.simpleTransparency;
2365
- this.headersFinished = dependencies.headersFinished || function() {
2366
- };
2367
- };
2368
- Parser.prototype.start = function() {
2369
- this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
2370
- };
2371
- Parser.prototype._parseSignature = function(data) {
2372
- let signature = constants.PNG_SIGNATURE;
2373
- for (let i = 0; i < signature.length; i++) {
2374
- if (data[i] !== signature[i]) {
2375
- this.error(new Error("Invalid file signature"));
2376
- return;
2377
- }
2378
- }
2379
- this.read(8, this._parseChunkBegin.bind(this));
2380
- };
2381
- Parser.prototype._parseChunkBegin = function(data) {
2382
- let length = data.readUInt32BE(0);
2383
- let type = data.readUInt32BE(4);
2384
- let name = "";
2385
- for (let i = 4; i < 8; i++) {
2386
- name += String.fromCharCode(data[i]);
2387
- }
2388
- let ancillary = Boolean(data[4] & 32);
2389
- if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
2390
- this.error(new Error("Expected IHDR on beggining"));
2391
- return;
2392
- }
2393
- this._crc = new CrcCalculator();
2394
- this._crc.write(Buffer.from(name));
2395
- if (this._chunks[type]) {
2396
- return this._chunks[type](length);
2397
- }
2398
- if (!ancillary) {
2399
- this.error(new Error("Unsupported critical chunk type " + name));
2400
- return;
2401
- }
2402
- this.read(length + 4, this._skipChunk.bind(this));
2403
- };
2404
- Parser.prototype._skipChunk = function() {
2405
- this.read(8, this._parseChunkBegin.bind(this));
2406
- };
2407
- Parser.prototype._handleChunkEnd = function() {
2408
- this.read(4, this._parseChunkEnd.bind(this));
2409
- };
2410
- Parser.prototype._parseChunkEnd = function(data) {
2411
- let fileCrc = data.readInt32BE(0);
2412
- let calcCrc = this._crc.crc32();
2413
- if (this._options.checkCRC && calcCrc !== fileCrc) {
2414
- this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
2415
- return;
2416
- }
2417
- if (!this._hasIEND) {
2418
- this.read(8, this._parseChunkBegin.bind(this));
2419
- }
2420
- };
2421
- Parser.prototype._handleIHDR = function(length) {
2422
- this.read(length, this._parseIHDR.bind(this));
2423
- };
2424
- Parser.prototype._parseIHDR = function(data) {
2425
- this._crc.write(data);
2426
- let width = data.readUInt32BE(0);
2427
- let height = data.readUInt32BE(4);
2428
- let depth = data[8];
2429
- let colorType = data[9];
2430
- let compr = data[10];
2431
- let filter = data[11];
2432
- let interlace = data[12];
2433
- if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
2434
- this.error(new Error("Unsupported bit depth " + depth));
2435
- return;
2436
- }
2437
- if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
2438
- this.error(new Error("Unsupported color type"));
2439
- return;
2440
- }
2441
- if (compr !== 0) {
2442
- this.error(new Error("Unsupported compression method"));
2443
- return;
2444
- }
2445
- if (filter !== 0) {
2446
- this.error(new Error("Unsupported filter method"));
2447
- return;
2448
- }
2449
- if (interlace !== 0 && interlace !== 1) {
2450
- this.error(new Error("Unsupported interlace method"));
2451
- return;
2452
- }
2453
- this._colorType = colorType;
2454
- let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
2455
- this._hasIHDR = true;
2456
- this.metadata({
2457
- width,
2458
- height,
2459
- depth,
2460
- interlace: Boolean(interlace),
2461
- palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
2462
- color: Boolean(colorType & constants.COLORTYPE_COLOR),
2463
- alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
2464
- bpp,
2465
- colorType
2466
- });
2467
- this._handleChunkEnd();
2468
- };
2469
- Parser.prototype._handlePLTE = function(length) {
2470
- this.read(length, this._parsePLTE.bind(this));
2471
- };
2472
- Parser.prototype._parsePLTE = function(data) {
2473
- this._crc.write(data);
2474
- let entries = Math.floor(data.length / 3);
2475
- for (let i = 0; i < entries; i++) {
2476
- this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 255]);
2477
- }
2478
- this.palette(this._palette);
2479
- this._handleChunkEnd();
2480
- };
2481
- Parser.prototype._handleTRNS = function(length) {
2482
- this.simpleTransparency();
2483
- this.read(length, this._parseTRNS.bind(this));
2484
- };
2485
- Parser.prototype._parseTRNS = function(data) {
2486
- this._crc.write(data);
2487
- if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
2488
- if (this._palette.length === 0) {
2489
- this.error(new Error("Transparency chunk must be after palette"));
2490
- return;
2491
- }
2492
- if (data.length > this._palette.length) {
2493
- this.error(new Error("More transparent colors than palette size"));
2494
- return;
2495
- }
2496
- for (let i = 0; i < data.length; i++) {
2497
- this._palette[i][3] = data[i];
2498
- }
2499
- this.palette(this._palette);
2500
- }
2501
- if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
2502
- this.transColor([data.readUInt16BE(0)]);
2503
- }
2504
- if (this._colorType === constants.COLORTYPE_COLOR) {
2505
- this.transColor([
2506
- data.readUInt16BE(0),
2507
- data.readUInt16BE(2),
2508
- data.readUInt16BE(4)
2509
- ]);
2510
- }
2511
- this._handleChunkEnd();
2512
- };
2513
- Parser.prototype._handleGAMA = function(length) {
2514
- this.read(length, this._parseGAMA.bind(this));
2515
- };
2516
- Parser.prototype._parseGAMA = function(data) {
2517
- this._crc.write(data);
2518
- this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
2519
- this._handleChunkEnd();
2520
- };
2521
- Parser.prototype._handleIDAT = function(length) {
2522
- if (!this._emittedHeadersFinished) {
2523
- this._emittedHeadersFinished = true;
2524
- this.headersFinished();
2525
- }
2526
- this.read(-length, this._parseIDAT.bind(this, length));
2527
- };
2528
- Parser.prototype._parseIDAT = function(length, data) {
2529
- this._crc.write(data);
2530
- if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
2531
- throw new Error("Expected palette not found");
2532
- }
2533
- this.inflateData(data);
2534
- let leftOverLength = length - data.length;
2535
- if (leftOverLength > 0) {
2536
- this._handleIDAT(leftOverLength);
2537
- } else {
2538
- this._handleChunkEnd();
2539
- }
2540
- };
2541
- Parser.prototype._handleIEND = function(length) {
2542
- this.read(length, this._parseIEND.bind(this));
2543
- };
2544
- Parser.prototype._parseIEND = function(data) {
2545
- this._crc.write(data);
2546
- this._hasIEND = true;
2547
- this._handleChunkEnd();
2548
- if (this.finished) {
2549
- this.finished();
2550
- }
2551
- };
2552
- }
2553
- });
2554
-
2555
- // ../../node_modules/pngjs/lib/bitmapper.js
2556
- var require_bitmapper = __commonJS({
2557
- "../../node_modules/pngjs/lib/bitmapper.js"(exports) {
2558
- "use strict";
2559
- var interlaceUtils = require_interlace();
2560
- var pixelBppMapper = [
2561
- // 0 - dummy entry
2562
- function() {
2563
- },
2564
- // 1 - L
2565
- // 0: 0, 1: 0, 2: 0, 3: 0xff
2566
- function(pxData, data, pxPos, rawPos) {
2567
- if (rawPos === data.length) {
2568
- throw new Error("Ran out of data");
2569
- }
2570
- let pixel = data[rawPos];
2571
- pxData[pxPos] = pixel;
2572
- pxData[pxPos + 1] = pixel;
2573
- pxData[pxPos + 2] = pixel;
2574
- pxData[pxPos + 3] = 255;
2575
- },
2576
- // 2 - LA
2577
- // 0: 0, 1: 0, 2: 0, 3: 1
2578
- function(pxData, data, pxPos, rawPos) {
2579
- if (rawPos + 1 >= data.length) {
2580
- throw new Error("Ran out of data");
2581
- }
2582
- let pixel = data[rawPos];
2583
- pxData[pxPos] = pixel;
2584
- pxData[pxPos + 1] = pixel;
2585
- pxData[pxPos + 2] = pixel;
2586
- pxData[pxPos + 3] = data[rawPos + 1];
2587
- },
2588
- // 3 - RGB
2589
- // 0: 0, 1: 1, 2: 2, 3: 0xff
2590
- function(pxData, data, pxPos, rawPos) {
2591
- if (rawPos + 2 >= data.length) {
2592
- throw new Error("Ran out of data");
2593
- }
2594
- pxData[pxPos] = data[rawPos];
2595
- pxData[pxPos + 1] = data[rawPos + 1];
2596
- pxData[pxPos + 2] = data[rawPos + 2];
2597
- pxData[pxPos + 3] = 255;
2598
- },
2599
- // 4 - RGBA
2600
- // 0: 0, 1: 1, 2: 2, 3: 3
2601
- function(pxData, data, pxPos, rawPos) {
2602
- if (rawPos + 3 >= data.length) {
2603
- throw new Error("Ran out of data");
2604
- }
2605
- pxData[pxPos] = data[rawPos];
2606
- pxData[pxPos + 1] = data[rawPos + 1];
2607
- pxData[pxPos + 2] = data[rawPos + 2];
2608
- pxData[pxPos + 3] = data[rawPos + 3];
2609
- }
2610
- ];
2611
- var pixelBppCustomMapper = [
2612
- // 0 - dummy entry
2613
- function() {
2614
- },
2615
- // 1 - L
2616
- // 0: 0, 1: 0, 2: 0, 3: 0xff
2617
- function(pxData, pixelData, pxPos, maxBit) {
2618
- let pixel = pixelData[0];
2619
- pxData[pxPos] = pixel;
2620
- pxData[pxPos + 1] = pixel;
2621
- pxData[pxPos + 2] = pixel;
2622
- pxData[pxPos + 3] = maxBit;
2623
- },
2624
- // 2 - LA
2625
- // 0: 0, 1: 0, 2: 0, 3: 1
2626
- function(pxData, pixelData, pxPos) {
2627
- let pixel = pixelData[0];
2628
- pxData[pxPos] = pixel;
2629
- pxData[pxPos + 1] = pixel;
2630
- pxData[pxPos + 2] = pixel;
2631
- pxData[pxPos + 3] = pixelData[1];
2632
- },
2633
- // 3 - RGB
2634
- // 0: 0, 1: 1, 2: 2, 3: 0xff
2635
- function(pxData, pixelData, pxPos, maxBit) {
2636
- pxData[pxPos] = pixelData[0];
2637
- pxData[pxPos + 1] = pixelData[1];
2638
- pxData[pxPos + 2] = pixelData[2];
2639
- pxData[pxPos + 3] = maxBit;
2640
- },
2641
- // 4 - RGBA
2642
- // 0: 0, 1: 1, 2: 2, 3: 3
2643
- function(pxData, pixelData, pxPos) {
2644
- pxData[pxPos] = pixelData[0];
2645
- pxData[pxPos + 1] = pixelData[1];
2646
- pxData[pxPos + 2] = pixelData[2];
2647
- pxData[pxPos + 3] = pixelData[3];
2648
- }
2649
- ];
2650
- function bitRetriever(data, depth) {
2651
- let leftOver = [];
2652
- let i = 0;
2653
- function split() {
2654
- if (i === data.length) {
2655
- throw new Error("Ran out of data");
2656
- }
2657
- let byte = data[i];
2658
- i++;
2659
- let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
2660
- switch (depth) {
2661
- default:
2662
- throw new Error("unrecognised depth");
2663
- case 16:
2664
- byte2 = data[i];
2665
- i++;
2666
- leftOver.push((byte << 8) + byte2);
2667
- break;
2668
- case 4:
2669
- byte2 = byte & 15;
2670
- byte1 = byte >> 4;
2671
- leftOver.push(byte1, byte2);
2672
- break;
2673
- case 2:
2674
- byte4 = byte & 3;
2675
- byte3 = byte >> 2 & 3;
2676
- byte2 = byte >> 4 & 3;
2677
- byte1 = byte >> 6 & 3;
2678
- leftOver.push(byte1, byte2, byte3, byte4);
2679
- break;
2680
- case 1:
2681
- byte8 = byte & 1;
2682
- byte7 = byte >> 1 & 1;
2683
- byte6 = byte >> 2 & 1;
2684
- byte5 = byte >> 3 & 1;
2685
- byte4 = byte >> 4 & 1;
2686
- byte3 = byte >> 5 & 1;
2687
- byte2 = byte >> 6 & 1;
2688
- byte1 = byte >> 7 & 1;
2689
- leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
2690
- break;
2691
- }
2692
- }
2693
- return {
2694
- get: function(count) {
2695
- while (leftOver.length < count) {
2696
- split();
2697
- }
2698
- let returner = leftOver.slice(0, count);
2699
- leftOver = leftOver.slice(count);
2700
- return returner;
2701
- },
2702
- resetAfterLine: function() {
2703
- leftOver.length = 0;
2704
- },
2705
- end: function() {
2706
- if (i !== data.length) {
2707
- throw new Error("extra data found");
2708
- }
2709
- }
2710
- };
2711
- }
2712
- function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
2713
- let imageWidth = image.width;
2714
- let imageHeight = image.height;
2715
- let imagePass = image.index;
2716
- for (let y = 0; y < imageHeight; y++) {
2717
- for (let x = 0; x < imageWidth; x++) {
2718
- let pxPos = getPxPos(x, y, imagePass);
2719
- pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
2720
- rawPos += bpp;
2721
- }
2722
- }
2723
- return rawPos;
2724
- }
2725
- function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
2726
- let imageWidth = image.width;
2727
- let imageHeight = image.height;
2728
- let imagePass = image.index;
2729
- for (let y = 0; y < imageHeight; y++) {
2730
- for (let x = 0; x < imageWidth; x++) {
2731
- let pixelData = bits.get(bpp);
2732
- let pxPos = getPxPos(x, y, imagePass);
2733
- pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
2734
- }
2735
- bits.resetAfterLine();
2736
- }
2737
- }
2738
- exports.dataToBitMap = function(data, bitmapInfo) {
2739
- let width = bitmapInfo.width;
2740
- let height = bitmapInfo.height;
2741
- let depth = bitmapInfo.depth;
2742
- let bpp = bitmapInfo.bpp;
2743
- let interlace = bitmapInfo.interlace;
2744
- let bits;
2745
- if (depth !== 8) {
2746
- bits = bitRetriever(data, depth);
2747
- }
2748
- let pxData;
2749
- if (depth <= 8) {
2750
- pxData = Buffer.alloc(width * height * 4);
2751
- } else {
2752
- pxData = new Uint16Array(width * height * 4);
2753
- }
2754
- let maxBit = Math.pow(2, depth) - 1;
2755
- let rawPos = 0;
2756
- let images;
2757
- let getPxPos;
2758
- if (interlace) {
2759
- images = interlaceUtils.getImagePasses(width, height);
2760
- getPxPos = interlaceUtils.getInterlaceIterator(width, height);
2761
- } else {
2762
- let nonInterlacedPxPos = 0;
2763
- getPxPos = function() {
2764
- let returner = nonInterlacedPxPos;
2765
- nonInterlacedPxPos += 4;
2766
- return returner;
2767
- };
2768
- images = [{ width, height }];
2769
- }
2770
- for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
2771
- if (depth === 8) {
2772
- rawPos = mapImage8Bit(
2773
- images[imageIndex],
2774
- pxData,
2775
- getPxPos,
2776
- bpp,
2777
- data,
2778
- rawPos
2779
- );
2780
- } else {
2781
- mapImageCustomBit(
2782
- images[imageIndex],
2783
- pxData,
2784
- getPxPos,
2785
- bpp,
2786
- bits,
2787
- maxBit
2788
- );
2789
- }
2790
- }
2791
- if (depth === 8) {
2792
- if (rawPos !== data.length) {
2793
- throw new Error("extra data found");
2794
- }
2795
- } else {
2796
- bits.end();
2797
- }
2798
- return pxData;
2799
- };
2800
- }
2801
- });
2802
-
2803
- // ../../node_modules/pngjs/lib/format-normaliser.js
2804
- var require_format_normaliser = __commonJS({
2805
- "../../node_modules/pngjs/lib/format-normaliser.js"(exports, module) {
2806
- "use strict";
2807
- function dePalette(indata, outdata, width, height, palette) {
2808
- let pxPos = 0;
2809
- for (let y = 0; y < height; y++) {
2810
- for (let x = 0; x < width; x++) {
2811
- let color = palette[indata[pxPos]];
2812
- if (!color) {
2813
- throw new Error("index " + indata[pxPos] + " not in palette");
2814
- }
2815
- for (let i = 0; i < 4; i++) {
2816
- outdata[pxPos + i] = color[i];
2817
- }
2818
- pxPos += 4;
2819
- }
2820
- }
2821
- }
2822
- function replaceTransparentColor(indata, outdata, width, height, transColor) {
2823
- let pxPos = 0;
2824
- for (let y = 0; y < height; y++) {
2825
- for (let x = 0; x < width; x++) {
2826
- let makeTrans = false;
2827
- if (transColor.length === 1) {
2828
- if (transColor[0] === indata[pxPos]) {
2829
- makeTrans = true;
2830
- }
2831
- } else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
2832
- makeTrans = true;
2833
- }
2834
- if (makeTrans) {
2835
- for (let i = 0; i < 4; i++) {
2836
- outdata[pxPos + i] = 0;
2837
- }
2838
- }
2839
- pxPos += 4;
2840
- }
2841
- }
2842
- }
2843
- function scaleDepth(indata, outdata, width, height, depth) {
2844
- let maxOutSample = 255;
2845
- let maxInSample = Math.pow(2, depth) - 1;
2846
- let pxPos = 0;
2847
- for (let y = 0; y < height; y++) {
2848
- for (let x = 0; x < width; x++) {
2849
- for (let i = 0; i < 4; i++) {
2850
- outdata[pxPos + i] = Math.floor(
2851
- indata[pxPos + i] * maxOutSample / maxInSample + 0.5
2852
- );
2853
- }
2854
- pxPos += 4;
2855
- }
2856
- }
2857
- }
2858
- module.exports = function(indata, imageData) {
2859
- let depth = imageData.depth;
2860
- let width = imageData.width;
2861
- let height = imageData.height;
2862
- let colorType = imageData.colorType;
2863
- let transColor = imageData.transColor;
2864
- let palette = imageData.palette;
2865
- let outdata = indata;
2866
- if (colorType === 3) {
2867
- dePalette(indata, outdata, width, height, palette);
2868
- } else {
2869
- if (transColor) {
2870
- replaceTransparentColor(indata, outdata, width, height, transColor);
2871
- }
2872
- if (depth !== 8) {
2873
- if (depth === 16) {
2874
- outdata = Buffer.alloc(width * height * 4);
2875
- }
2876
- scaleDepth(indata, outdata, width, height, depth);
2877
- }
2878
- }
2879
- return outdata;
2880
- };
2881
- }
2882
- });
2883
-
2884
- // ../../node_modules/pngjs/lib/parser-async.js
2885
- var require_parser_async = __commonJS({
2886
- "../../node_modules/pngjs/lib/parser-async.js"(exports, module) {
2887
- "use strict";
2888
- var util = __require("util");
2889
- var zlib = __require("zlib");
2890
- var ChunkStream = require_chunkstream();
2891
- var FilterAsync = require_filter_parse_async();
2892
- var Parser = require_parser();
2893
- var bitmapper = require_bitmapper();
2894
- var formatNormaliser = require_format_normaliser();
2895
- var ParserAsync = module.exports = function(options) {
2896
- ChunkStream.call(this);
2897
- this._parser = new Parser(options, {
2898
- read: this.read.bind(this),
2899
- error: this._handleError.bind(this),
2900
- metadata: this._handleMetaData.bind(this),
2901
- gamma: this.emit.bind(this, "gamma"),
2902
- palette: this._handlePalette.bind(this),
2903
- transColor: this._handleTransColor.bind(this),
2904
- finished: this._finished.bind(this),
2905
- inflateData: this._inflateData.bind(this),
2906
- simpleTransparency: this._simpleTransparency.bind(this),
2907
- headersFinished: this._headersFinished.bind(this)
2908
- });
2909
- this._options = options;
2910
- this.writable = true;
2911
- this._parser.start();
2912
- };
2913
- util.inherits(ParserAsync, ChunkStream);
2914
- ParserAsync.prototype._handleError = function(err) {
2915
- this.emit("error", err);
2916
- this.writable = false;
2917
- this.destroy();
2918
- if (this._inflate && this._inflate.destroy) {
2919
- this._inflate.destroy();
2920
- }
2921
- if (this._filter) {
2922
- this._filter.destroy();
2923
- this._filter.on("error", function() {
2924
- });
2925
- }
2926
- this.errord = true;
2927
- };
2928
- ParserAsync.prototype._inflateData = function(data) {
2929
- if (!this._inflate) {
2930
- if (this._bitmapInfo.interlace) {
2931
- this._inflate = zlib.createInflate();
2932
- this._inflate.on("error", this.emit.bind(this, "error"));
2933
- this._filter.on("complete", this._complete.bind(this));
2934
- this._inflate.pipe(this._filter);
2935
- } else {
2936
- let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
2937
- let imageSize = rowSize * this._bitmapInfo.height;
2938
- let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
2939
- this._inflate = zlib.createInflate({ chunkSize });
2940
- let leftToInflate = imageSize;
2941
- let emitError = this.emit.bind(this, "error");
2942
- this._inflate.on("error", function(err) {
2943
- if (!leftToInflate) {
2944
- return;
2945
- }
2946
- emitError(err);
2947
- });
2948
- this._filter.on("complete", this._complete.bind(this));
2949
- let filterWrite = this._filter.write.bind(this._filter);
2950
- this._inflate.on("data", function(chunk) {
2951
- if (!leftToInflate) {
2952
- return;
2953
- }
2954
- if (chunk.length > leftToInflate) {
2955
- chunk = chunk.slice(0, leftToInflate);
2956
- }
2957
- leftToInflate -= chunk.length;
2958
- filterWrite(chunk);
2959
- });
2960
- this._inflate.on("end", this._filter.end.bind(this._filter));
2961
- }
2962
- }
2963
- this._inflate.write(data);
2964
- };
2965
- ParserAsync.prototype._handleMetaData = function(metaData) {
2966
- this._metaData = metaData;
2967
- this._bitmapInfo = Object.create(metaData);
2968
- this._filter = new FilterAsync(this._bitmapInfo);
2969
- };
2970
- ParserAsync.prototype._handleTransColor = function(transColor) {
2971
- this._bitmapInfo.transColor = transColor;
2972
- };
2973
- ParserAsync.prototype._handlePalette = function(palette) {
2974
- this._bitmapInfo.palette = palette;
2975
- };
2976
- ParserAsync.prototype._simpleTransparency = function() {
2977
- this._metaData.alpha = true;
2978
- };
2979
- ParserAsync.prototype._headersFinished = function() {
2980
- this.emit("metadata", this._metaData);
2981
- };
2982
- ParserAsync.prototype._finished = function() {
2983
- if (this.errord) {
2984
- return;
2985
- }
2986
- if (!this._inflate) {
2987
- this.emit("error", "No Inflate block");
2988
- } else {
2989
- this._inflate.end();
2990
- }
2991
- };
2992
- ParserAsync.prototype._complete = function(filteredData) {
2993
- if (this.errord) {
2994
- return;
2995
- }
2996
- let normalisedBitmapData;
2997
- try {
2998
- let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
2999
- normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo);
3000
- bitmapData = null;
3001
- } catch (ex) {
3002
- this._handleError(ex);
3003
- return;
3004
- }
3005
- this.emit("parsed", normalisedBitmapData);
3006
- };
3007
- }
3008
- });
3009
-
3010
- // ../../node_modules/pngjs/lib/bitpacker.js
3011
- var require_bitpacker = __commonJS({
3012
- "../../node_modules/pngjs/lib/bitpacker.js"(exports, module) {
3013
- "use strict";
3014
- var constants = require_constants();
3015
- module.exports = function(dataIn, width, height, options) {
3016
- let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(
3017
- options.colorType
3018
- ) !== -1;
3019
- if (options.colorType === options.inputColorType) {
3020
- let bigEndian = (function() {
3021
- let buffer = new ArrayBuffer(2);
3022
- new DataView(buffer).setInt16(
3023
- 0,
3024
- 256,
3025
- true
3026
- /* littleEndian */
3027
- );
3028
- return new Int16Array(buffer)[0] !== 256;
3029
- })();
3030
- if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
3031
- return dataIn;
3032
- }
3033
- }
3034
- let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
3035
- let maxValue = 255;
3036
- let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
3037
- if (inBpp === 4 && !options.inputHasAlpha) {
3038
- inBpp = 3;
3039
- }
3040
- let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
3041
- if (options.bitDepth === 16) {
3042
- maxValue = 65535;
3043
- outBpp *= 2;
3044
- }
3045
- let outData = Buffer.alloc(width * height * outBpp);
3046
- let inIndex = 0;
3047
- let outIndex = 0;
3048
- let bgColor = options.bgColor || {};
3049
- if (bgColor.red === void 0) {
3050
- bgColor.red = maxValue;
3051
- }
3052
- if (bgColor.green === void 0) {
3053
- bgColor.green = maxValue;
3054
- }
3055
- if (bgColor.blue === void 0) {
3056
- bgColor.blue = maxValue;
3057
- }
3058
- function getRGBA() {
3059
- let red;
3060
- let green;
3061
- let blue;
3062
- let alpha = maxValue;
3063
- switch (options.inputColorType) {
3064
- case constants.COLORTYPE_COLOR_ALPHA:
3065
- alpha = data[inIndex + 3];
3066
- red = data[inIndex];
3067
- green = data[inIndex + 1];
3068
- blue = data[inIndex + 2];
3069
- break;
3070
- case constants.COLORTYPE_COLOR:
3071
- red = data[inIndex];
3072
- green = data[inIndex + 1];
3073
- blue = data[inIndex + 2];
3074
- break;
3075
- case constants.COLORTYPE_ALPHA:
3076
- alpha = data[inIndex + 1];
3077
- red = data[inIndex];
3078
- green = red;
3079
- blue = red;
3080
- break;
3081
- case constants.COLORTYPE_GRAYSCALE:
3082
- red = data[inIndex];
3083
- green = red;
3084
- blue = red;
3085
- break;
3086
- default:
3087
- throw new Error(
3088
- "input color type:" + options.inputColorType + " is not supported at present"
3089
- );
3090
- }
3091
- if (options.inputHasAlpha) {
3092
- if (!outHasAlpha) {
3093
- alpha /= maxValue;
3094
- red = Math.min(
3095
- Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
3096
- maxValue
3097
- );
3098
- green = Math.min(
3099
- Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
3100
- maxValue
3101
- );
3102
- blue = Math.min(
3103
- Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
3104
- maxValue
3105
- );
3106
- }
3107
- }
3108
- return { red, green, blue, alpha };
3109
- }
3110
- for (let y = 0; y < height; y++) {
3111
- for (let x = 0; x < width; x++) {
3112
- let rgba = getRGBA(data, inIndex);
3113
- switch (options.colorType) {
3114
- case constants.COLORTYPE_COLOR_ALPHA:
3115
- case constants.COLORTYPE_COLOR:
3116
- if (options.bitDepth === 8) {
3117
- outData[outIndex] = rgba.red;
3118
- outData[outIndex + 1] = rgba.green;
3119
- outData[outIndex + 2] = rgba.blue;
3120
- if (outHasAlpha) {
3121
- outData[outIndex + 3] = rgba.alpha;
3122
- }
3123
- } else {
3124
- outData.writeUInt16BE(rgba.red, outIndex);
3125
- outData.writeUInt16BE(rgba.green, outIndex + 2);
3126
- outData.writeUInt16BE(rgba.blue, outIndex + 4);
3127
- if (outHasAlpha) {
3128
- outData.writeUInt16BE(rgba.alpha, outIndex + 6);
3129
- }
3130
- }
3131
- break;
3132
- case constants.COLORTYPE_ALPHA:
3133
- case constants.COLORTYPE_GRAYSCALE: {
3134
- let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
3135
- if (options.bitDepth === 8) {
3136
- outData[outIndex] = grayscale;
3137
- if (outHasAlpha) {
3138
- outData[outIndex + 1] = rgba.alpha;
3139
- }
3140
- } else {
3141
- outData.writeUInt16BE(grayscale, outIndex);
3142
- if (outHasAlpha) {
3143
- outData.writeUInt16BE(rgba.alpha, outIndex + 2);
3144
- }
3145
- }
3146
- break;
3147
- }
3148
- default:
3149
- throw new Error("unrecognised color Type " + options.colorType);
3150
- }
3151
- inIndex += inBpp;
3152
- outIndex += outBpp;
3153
- }
3154
- }
3155
- return outData;
3156
- };
3157
- }
3158
- });
3159
-
3160
- // ../../node_modules/pngjs/lib/filter-pack.js
3161
- var require_filter_pack = __commonJS({
3162
- "../../node_modules/pngjs/lib/filter-pack.js"(exports, module) {
3163
- "use strict";
3164
- var paethPredictor = require_paeth_predictor();
3165
- function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
3166
- for (let x = 0; x < byteWidth; x++) {
3167
- rawData[rawPos + x] = pxData[pxPos + x];
3168
- }
3169
- }
3170
- function filterSumNone(pxData, pxPos, byteWidth) {
3171
- let sum = 0;
3172
- let length = pxPos + byteWidth;
3173
- for (let i = pxPos; i < length; i++) {
3174
- sum += Math.abs(pxData[i]);
3175
- }
3176
- return sum;
3177
- }
3178
- function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
3179
- for (let x = 0; x < byteWidth; x++) {
3180
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
3181
- let val = pxData[pxPos + x] - left;
3182
- rawData[rawPos + x] = val;
3183
- }
3184
- }
3185
- function filterSumSub(pxData, pxPos, byteWidth, bpp) {
3186
- let sum = 0;
3187
- for (let x = 0; x < byteWidth; x++) {
3188
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
3189
- let val = pxData[pxPos + x] - left;
3190
- sum += Math.abs(val);
3191
- }
3192
- return sum;
3193
- }
3194
- function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
3195
- for (let x = 0; x < byteWidth; x++) {
3196
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
3197
- let val = pxData[pxPos + x] - up;
3198
- rawData[rawPos + x] = val;
3199
- }
3200
- }
3201
- function filterSumUp(pxData, pxPos, byteWidth) {
3202
- let sum = 0;
3203
- let length = pxPos + byteWidth;
3204
- for (let x = pxPos; x < length; x++) {
3205
- let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
3206
- let val = pxData[x] - up;
3207
- sum += Math.abs(val);
3208
- }
3209
- return sum;
3210
- }
3211
- function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
3212
- for (let x = 0; x < byteWidth; x++) {
3213
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
3214
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
3215
- let val = pxData[pxPos + x] - (left + up >> 1);
3216
- rawData[rawPos + x] = val;
3217
- }
3218
- }
3219
- function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
3220
- let sum = 0;
3221
- for (let x = 0; x < byteWidth; x++) {
3222
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
3223
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
3224
- let val = pxData[pxPos + x] - (left + up >> 1);
3225
- sum += Math.abs(val);
3226
- }
3227
- return sum;
3228
- }
3229
- function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
3230
- for (let x = 0; x < byteWidth; x++) {
3231
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
3232
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
3233
- let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
3234
- let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
3235
- rawData[rawPos + x] = val;
3236
- }
3237
- }
3238
- function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
3239
- let sum = 0;
3240
- for (let x = 0; x < byteWidth; x++) {
3241
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
3242
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
3243
- let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
3244
- let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
3245
- sum += Math.abs(val);
3246
- }
3247
- return sum;
3248
- }
3249
- var filters = {
3250
- 0: filterNone,
3251
- 1: filterSub,
3252
- 2: filterUp,
3253
- 3: filterAvg,
3254
- 4: filterPaeth
3255
- };
3256
- var filterSums = {
3257
- 0: filterSumNone,
3258
- 1: filterSumSub,
3259
- 2: filterSumUp,
3260
- 3: filterSumAvg,
3261
- 4: filterSumPaeth
3262
- };
3263
- module.exports = function(pxData, width, height, options, bpp) {
3264
- let filterTypes;
3265
- if (!("filterType" in options) || options.filterType === -1) {
3266
- filterTypes = [0, 1, 2, 3, 4];
3267
- } else if (typeof options.filterType === "number") {
3268
- filterTypes = [options.filterType];
3269
- } else {
3270
- throw new Error("unrecognised filter types");
3271
- }
3272
- if (options.bitDepth === 16) {
3273
- bpp *= 2;
3274
- }
3275
- let byteWidth = width * bpp;
3276
- let rawPos = 0;
3277
- let pxPos = 0;
3278
- let rawData = Buffer.alloc((byteWidth + 1) * height);
3279
- let sel = filterTypes[0];
3280
- for (let y = 0; y < height; y++) {
3281
- if (filterTypes.length > 1) {
3282
- let min = Infinity;
3283
- for (let i = 0; i < filterTypes.length; i++) {
3284
- let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
3285
- if (sum < min) {
3286
- sel = filterTypes[i];
3287
- min = sum;
3288
- }
3289
- }
3290
- }
3291
- rawData[rawPos] = sel;
3292
- rawPos++;
3293
- filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
3294
- rawPos += byteWidth;
3295
- pxPos += byteWidth;
3296
- }
3297
- return rawData;
3298
- };
3299
- }
3300
- });
3301
-
3302
- // ../../node_modules/pngjs/lib/packer.js
3303
- var require_packer = __commonJS({
3304
- "../../node_modules/pngjs/lib/packer.js"(exports, module) {
3305
- "use strict";
3306
- var constants = require_constants();
3307
- var CrcStream = require_crc();
3308
- var bitPacker = require_bitpacker();
3309
- var filter = require_filter_pack();
3310
- var zlib = __require("zlib");
3311
- var Packer = module.exports = function(options) {
3312
- this._options = options;
3313
- options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
3314
- options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
3315
- options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
3316
- options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
3317
- options.deflateFactory = options.deflateFactory || zlib.createDeflate;
3318
- options.bitDepth = options.bitDepth || 8;
3319
- options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
3320
- options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
3321
- if ([
3322
- constants.COLORTYPE_GRAYSCALE,
3323
- constants.COLORTYPE_COLOR,
3324
- constants.COLORTYPE_COLOR_ALPHA,
3325
- constants.COLORTYPE_ALPHA
3326
- ].indexOf(options.colorType) === -1) {
3327
- throw new Error(
3328
- "option color type:" + options.colorType + " is not supported at present"
3329
- );
3330
- }
3331
- if ([
3332
- constants.COLORTYPE_GRAYSCALE,
3333
- constants.COLORTYPE_COLOR,
3334
- constants.COLORTYPE_COLOR_ALPHA,
3335
- constants.COLORTYPE_ALPHA
3336
- ].indexOf(options.inputColorType) === -1) {
3337
- throw new Error(
3338
- "option input color type:" + options.inputColorType + " is not supported at present"
3339
- );
3340
- }
3341
- if (options.bitDepth !== 8 && options.bitDepth !== 16) {
3342
- throw new Error(
3343
- "option bit depth:" + options.bitDepth + " is not supported at present"
3344
- );
3345
- }
3346
- };
3347
- Packer.prototype.getDeflateOptions = function() {
3348
- return {
3349
- chunkSize: this._options.deflateChunkSize,
3350
- level: this._options.deflateLevel,
3351
- strategy: this._options.deflateStrategy
3352
- };
3353
- };
3354
- Packer.prototype.createDeflate = function() {
3355
- return this._options.deflateFactory(this.getDeflateOptions());
3356
- };
3357
- Packer.prototype.filterData = function(data, width, height) {
3358
- let packedData = bitPacker(data, width, height, this._options);
3359
- let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
3360
- let filteredData = filter(packedData, width, height, this._options, bpp);
3361
- return filteredData;
3362
- };
3363
- Packer.prototype._packChunk = function(type, data) {
3364
- let len = data ? data.length : 0;
3365
- let buf = Buffer.alloc(len + 12);
3366
- buf.writeUInt32BE(len, 0);
3367
- buf.writeUInt32BE(type, 4);
3368
- if (data) {
3369
- data.copy(buf, 8);
3370
- }
3371
- buf.writeInt32BE(
3372
- CrcStream.crc32(buf.slice(4, buf.length - 4)),
3373
- buf.length - 4
3374
- );
3375
- return buf;
3376
- };
3377
- Packer.prototype.packGAMA = function(gamma) {
3378
- let buf = Buffer.alloc(4);
3379
- buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
3380
- return this._packChunk(constants.TYPE_gAMA, buf);
3381
- };
3382
- Packer.prototype.packIHDR = function(width, height) {
3383
- let buf = Buffer.alloc(13);
3384
- buf.writeUInt32BE(width, 0);
3385
- buf.writeUInt32BE(height, 4);
3386
- buf[8] = this._options.bitDepth;
3387
- buf[9] = this._options.colorType;
3388
- buf[10] = 0;
3389
- buf[11] = 0;
3390
- buf[12] = 0;
3391
- return this._packChunk(constants.TYPE_IHDR, buf);
3392
- };
3393
- Packer.prototype.packIDAT = function(data) {
3394
- return this._packChunk(constants.TYPE_IDAT, data);
3395
- };
3396
- Packer.prototype.packIEND = function() {
3397
- return this._packChunk(constants.TYPE_IEND, null);
3398
- };
3399
- }
3400
- });
3401
-
3402
- // ../../node_modules/pngjs/lib/packer-async.js
3403
- var require_packer_async = __commonJS({
3404
- "../../node_modules/pngjs/lib/packer-async.js"(exports, module) {
3405
- "use strict";
3406
- var util = __require("util");
3407
- var Stream = __require("stream");
3408
- var constants = require_constants();
3409
- var Packer = require_packer();
3410
- var PackerAsync = module.exports = function(opt) {
3411
- Stream.call(this);
3412
- let options = opt || {};
3413
- this._packer = new Packer(options);
3414
- this._deflate = this._packer.createDeflate();
3415
- this.readable = true;
3416
- };
3417
- util.inherits(PackerAsync, Stream);
3418
- PackerAsync.prototype.pack = function(data, width, height, gamma) {
3419
- this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
3420
- this.emit("data", this._packer.packIHDR(width, height));
3421
- if (gamma) {
3422
- this.emit("data", this._packer.packGAMA(gamma));
3423
- }
3424
- let filteredData = this._packer.filterData(data, width, height);
3425
- this._deflate.on("error", this.emit.bind(this, "error"));
3426
- this._deflate.on(
3427
- "data",
3428
- function(compressedData) {
3429
- this.emit("data", this._packer.packIDAT(compressedData));
3430
- }.bind(this)
3431
- );
3432
- this._deflate.on(
3433
- "end",
3434
- function() {
3435
- this.emit("data", this._packer.packIEND());
3436
- this.emit("end");
3437
- }.bind(this)
3438
- );
3439
- this._deflate.end(filteredData);
3440
- };
3441
- }
3442
- });
3443
-
3444
- // ../../node_modules/pngjs/lib/sync-inflate.js
3445
- var require_sync_inflate = __commonJS({
3446
- "../../node_modules/pngjs/lib/sync-inflate.js"(exports, module) {
3447
- "use strict";
3448
- var assert = __require("assert").ok;
3449
- var zlib = __require("zlib");
3450
- var util = __require("util");
3451
- var kMaxLength = __require("buffer").kMaxLength;
3452
- function Inflate(opts) {
3453
- if (!(this instanceof Inflate)) {
3454
- return new Inflate(opts);
3455
- }
3456
- if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
3457
- opts.chunkSize = zlib.Z_MIN_CHUNK;
3458
- }
3459
- zlib.Inflate.call(this, opts);
3460
- this._offset = this._offset === void 0 ? this._outOffset : this._offset;
3461
- this._buffer = this._buffer || this._outBuffer;
3462
- if (opts && opts.maxLength != null) {
3463
- this._maxLength = opts.maxLength;
3464
- }
3465
- }
3466
- function createInflate(opts) {
3467
- return new Inflate(opts);
3468
- }
3469
- function _close(engine, callback) {
3470
- if (callback) {
3471
- process.nextTick(callback);
3472
- }
3473
- if (!engine._handle) {
3474
- return;
3475
- }
3476
- engine._handle.close();
3477
- engine._handle = null;
3478
- }
3479
- Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
3480
- if (typeof asyncCb === "function") {
3481
- return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
3482
- }
3483
- let self = this;
3484
- let availInBefore = chunk && chunk.length;
3485
- let availOutBefore = this._chunkSize - this._offset;
3486
- let leftToInflate = this._maxLength;
3487
- let inOff = 0;
3488
- let buffers = [];
3489
- let nread = 0;
3490
- let error;
3491
- this.on("error", function(err) {
3492
- error = err;
3493
- });
3494
- function handleChunk(availInAfter, availOutAfter) {
3495
- if (self._hadError) {
3496
- return;
3497
- }
3498
- let have = availOutBefore - availOutAfter;
3499
- assert(have >= 0, "have should not go down");
3500
- if (have > 0) {
3501
- let out = self._buffer.slice(self._offset, self._offset + have);
3502
- self._offset += have;
3503
- if (out.length > leftToInflate) {
3504
- out = out.slice(0, leftToInflate);
3505
- }
3506
- buffers.push(out);
3507
- nread += out.length;
3508
- leftToInflate -= out.length;
3509
- if (leftToInflate === 0) {
3510
- return false;
3511
- }
3512
- }
3513
- if (availOutAfter === 0 || self._offset >= self._chunkSize) {
3514
- availOutBefore = self._chunkSize;
3515
- self._offset = 0;
3516
- self._buffer = Buffer.allocUnsafe(self._chunkSize);
3517
- }
3518
- if (availOutAfter === 0) {
3519
- inOff += availInBefore - availInAfter;
3520
- availInBefore = availInAfter;
3521
- return true;
3522
- }
3523
- return false;
3524
- }
3525
- assert(this._handle, "zlib binding closed");
3526
- let res;
3527
- do {
3528
- res = this._handle.writeSync(
3529
- flushFlag,
3530
- chunk,
3531
- // in
3532
- inOff,
3533
- // in_off
3534
- availInBefore,
3535
- // in_len
3536
- this._buffer,
3537
- // out
3538
- this._offset,
3539
- //out_off
3540
- availOutBefore
3541
- );
3542
- res = res || this._writeState;
3543
- } while (!this._hadError && handleChunk(res[0], res[1]));
3544
- if (this._hadError) {
3545
- throw error;
3546
- }
3547
- if (nread >= kMaxLength) {
3548
- _close(this);
3549
- throw new RangeError(
3550
- "Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes"
3551
- );
3552
- }
3553
- let buf = Buffer.concat(buffers, nread);
3554
- _close(this);
3555
- return buf;
3556
- };
3557
- util.inherits(Inflate, zlib.Inflate);
3558
- function zlibBufferSync(engine, buffer) {
3559
- if (typeof buffer === "string") {
3560
- buffer = Buffer.from(buffer);
3561
- }
3562
- if (!(buffer instanceof Buffer)) {
3563
- throw new TypeError("Not a string or buffer");
3564
- }
3565
- let flushFlag = engine._finishFlushFlag;
3566
- if (flushFlag == null) {
3567
- flushFlag = zlib.Z_FINISH;
3568
- }
3569
- return engine._processChunk(buffer, flushFlag);
3570
- }
3571
- function inflateSync(buffer, opts) {
3572
- return zlibBufferSync(new Inflate(opts), buffer);
3573
- }
3574
- module.exports = exports = inflateSync;
3575
- exports.Inflate = Inflate;
3576
- exports.createInflate = createInflate;
3577
- exports.inflateSync = inflateSync;
3578
- }
3579
- });
3580
-
3581
- // ../../node_modules/pngjs/lib/sync-reader.js
3582
- var require_sync_reader = __commonJS({
3583
- "../../node_modules/pngjs/lib/sync-reader.js"(exports, module) {
3584
- "use strict";
3585
- var SyncReader = module.exports = function(buffer) {
3586
- this._buffer = buffer;
3587
- this._reads = [];
3588
- };
3589
- SyncReader.prototype.read = function(length, callback) {
3590
- this._reads.push({
3591
- length: Math.abs(length),
3592
- // if length < 0 then at most this length
3593
- allowLess: length < 0,
3594
- func: callback
3595
- });
3596
- };
3597
- SyncReader.prototype.process = function() {
3598
- while (this._reads.length > 0 && this._buffer.length) {
3599
- let read = this._reads[0];
3600
- if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
3601
- this._reads.shift();
3602
- let buf = this._buffer;
3603
- this._buffer = buf.slice(read.length);
3604
- read.func.call(this, buf.slice(0, read.length));
3605
- } else {
3606
- break;
3607
- }
3608
- }
3609
- if (this._reads.length > 0) {
3610
- return new Error("There are some read requests waitng on finished stream");
3611
- }
3612
- if (this._buffer.length > 0) {
3613
- return new Error("unrecognised content at end of stream");
3614
- }
3615
- };
3616
- }
3617
- });
3618
-
3619
- // ../../node_modules/pngjs/lib/filter-parse-sync.js
3620
- var require_filter_parse_sync = __commonJS({
3621
- "../../node_modules/pngjs/lib/filter-parse-sync.js"(exports) {
3622
- "use strict";
3623
- var SyncReader = require_sync_reader();
3624
- var Filter = require_filter_parse();
3625
- exports.process = function(inBuffer, bitmapInfo) {
3626
- let outBuffers = [];
3627
- let reader = new SyncReader(inBuffer);
3628
- let filter = new Filter(bitmapInfo, {
3629
- read: reader.read.bind(reader),
3630
- write: function(bufferPart) {
3631
- outBuffers.push(bufferPart);
3632
- },
3633
- complete: function() {
3634
- }
3635
- });
3636
- filter.start();
3637
- reader.process();
3638
- return Buffer.concat(outBuffers);
3639
- };
3640
- }
3641
- });
3642
-
3643
- // ../../node_modules/pngjs/lib/parser-sync.js
3644
- var require_parser_sync = __commonJS({
3645
- "../../node_modules/pngjs/lib/parser-sync.js"(exports, module) {
3646
- "use strict";
3647
- var hasSyncZlib = true;
3648
- var zlib = __require("zlib");
3649
- var inflateSync = require_sync_inflate();
3650
- if (!zlib.deflateSync) {
3651
- hasSyncZlib = false;
3652
- }
3653
- var SyncReader = require_sync_reader();
3654
- var FilterSync = require_filter_parse_sync();
3655
- var Parser = require_parser();
3656
- var bitmapper = require_bitmapper();
3657
- var formatNormaliser = require_format_normaliser();
3658
- module.exports = function(buffer, options) {
3659
- if (!hasSyncZlib) {
3660
- throw new Error(
3661
- "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
3662
- );
3663
- }
3664
- let err;
3665
- function handleError(_err_) {
3666
- err = _err_;
3667
- }
3668
- let metaData;
3669
- function handleMetaData(_metaData_) {
3670
- metaData = _metaData_;
3671
- }
3672
- function handleTransColor(transColor) {
3673
- metaData.transColor = transColor;
3674
- }
3675
- function handlePalette(palette) {
3676
- metaData.palette = palette;
3677
- }
3678
- function handleSimpleTransparency() {
3679
- metaData.alpha = true;
3680
- }
3681
- let gamma;
3682
- function handleGamma(_gamma_) {
3683
- gamma = _gamma_;
3684
- }
3685
- let inflateDataList = [];
3686
- function handleInflateData(inflatedData2) {
3687
- inflateDataList.push(inflatedData2);
3688
- }
3689
- let reader = new SyncReader(buffer);
3690
- let parser = new Parser(options, {
3691
- read: reader.read.bind(reader),
3692
- error: handleError,
3693
- metadata: handleMetaData,
3694
- gamma: handleGamma,
3695
- palette: handlePalette,
3696
- transColor: handleTransColor,
3697
- inflateData: handleInflateData,
3698
- simpleTransparency: handleSimpleTransparency
3699
- });
3700
- parser.start();
3701
- reader.process();
3702
- if (err) {
3703
- throw err;
3704
- }
3705
- let inflateData = Buffer.concat(inflateDataList);
3706
- inflateDataList.length = 0;
3707
- let inflatedData;
3708
- if (metaData.interlace) {
3709
- inflatedData = zlib.inflateSync(inflateData);
3710
- } else {
3711
- let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
3712
- let imageSize = rowSize * metaData.height;
3713
- inflatedData = inflateSync(inflateData, {
3714
- chunkSize: imageSize,
3715
- maxLength: imageSize
3716
- });
3717
- }
3718
- inflateData = null;
3719
- if (!inflatedData || !inflatedData.length) {
3720
- throw new Error("bad png - invalid inflate data response");
3721
- }
3722
- let unfilteredData = FilterSync.process(inflatedData, metaData);
3723
- inflateData = null;
3724
- let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
3725
- unfilteredData = null;
3726
- let normalisedBitmapData = formatNormaliser(bitmapData, metaData);
3727
- metaData.data = normalisedBitmapData;
3728
- metaData.gamma = gamma || 0;
3729
- return metaData;
3730
- };
3731
- }
3732
- });
3733
-
3734
- // ../../node_modules/pngjs/lib/packer-sync.js
3735
- var require_packer_sync = __commonJS({
3736
- "../../node_modules/pngjs/lib/packer-sync.js"(exports, module) {
3737
- "use strict";
3738
- var hasSyncZlib = true;
3739
- var zlib = __require("zlib");
3740
- if (!zlib.deflateSync) {
3741
- hasSyncZlib = false;
3742
- }
3743
- var constants = require_constants();
3744
- var Packer = require_packer();
3745
- module.exports = function(metaData, opt) {
3746
- if (!hasSyncZlib) {
3747
- throw new Error(
3748
- "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
3749
- );
3750
- }
3751
- let options = opt || {};
3752
- let packer = new Packer(options);
3753
- let chunks = [];
3754
- chunks.push(Buffer.from(constants.PNG_SIGNATURE));
3755
- chunks.push(packer.packIHDR(metaData.width, metaData.height));
3756
- if (metaData.gamma) {
3757
- chunks.push(packer.packGAMA(metaData.gamma));
3758
- }
3759
- let filteredData = packer.filterData(
3760
- metaData.data,
3761
- metaData.width,
3762
- metaData.height
3763
- );
3764
- let compressedData = zlib.deflateSync(
3765
- filteredData,
3766
- packer.getDeflateOptions()
3767
- );
3768
- filteredData = null;
3769
- if (!compressedData || !compressedData.length) {
3770
- throw new Error("bad png - invalid compressed data response");
3771
- }
3772
- chunks.push(packer.packIDAT(compressedData));
3773
- chunks.push(packer.packIEND());
3774
- return Buffer.concat(chunks);
3775
- };
3776
- }
3777
- });
3778
-
3779
- // ../../node_modules/pngjs/lib/png-sync.js
3780
- var require_png_sync = __commonJS({
3781
- "../../node_modules/pngjs/lib/png-sync.js"(exports) {
3782
- "use strict";
3783
- var parse = require_parser_sync();
3784
- var pack = require_packer_sync();
3785
- exports.read = function(buffer, options) {
3786
- return parse(buffer, options || {});
3787
- };
3788
- exports.write = function(png, options) {
3789
- return pack(png, options);
3790
- };
3791
- }
3792
- });
3793
-
3794
- // ../../node_modules/pngjs/lib/png.js
3795
- var require_png = __commonJS({
3796
- "../../node_modules/pngjs/lib/png.js"(exports) {
3797
- "use strict";
3798
- var util = __require("util");
3799
- var Stream = __require("stream");
3800
- var Parser = require_parser_async();
3801
- var Packer = require_packer_async();
3802
- var PNGSync = require_png_sync();
3803
- var PNG = exports.PNG = function(options) {
3804
- Stream.call(this);
3805
- options = options || {};
3806
- this.width = options.width | 0;
3807
- this.height = options.height | 0;
3808
- this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
3809
- if (options.fill && this.data) {
3810
- this.data.fill(0);
3811
- }
3812
- this.gamma = 0;
3813
- this.readable = this.writable = true;
3814
- this._parser = new Parser(options);
3815
- this._parser.on("error", this.emit.bind(this, "error"));
3816
- this._parser.on("close", this._handleClose.bind(this));
3817
- this._parser.on("metadata", this._metadata.bind(this));
3818
- this._parser.on("gamma", this._gamma.bind(this));
3819
- this._parser.on(
3820
- "parsed",
3821
- function(data) {
3822
- this.data = data;
3823
- this.emit("parsed", data);
3824
- }.bind(this)
3825
- );
3826
- this._packer = new Packer(options);
3827
- this._packer.on("data", this.emit.bind(this, "data"));
3828
- this._packer.on("end", this.emit.bind(this, "end"));
3829
- this._parser.on("close", this._handleClose.bind(this));
3830
- this._packer.on("error", this.emit.bind(this, "error"));
3831
- };
3832
- util.inherits(PNG, Stream);
3833
- PNG.sync = PNGSync;
3834
- PNG.prototype.pack = function() {
3835
- if (!this.data || !this.data.length) {
3836
- this.emit("error", "No data provided");
3837
- return this;
3838
- }
3839
- process.nextTick(
3840
- function() {
3841
- this._packer.pack(this.data, this.width, this.height, this.gamma);
3842
- }.bind(this)
3843
- );
3844
- return this;
3845
- };
3846
- PNG.prototype.parse = function(data, callback) {
3847
- if (callback) {
3848
- let onParsed, onError;
3849
- onParsed = function(parsedData) {
3850
- this.removeListener("error", onError);
3851
- this.data = parsedData;
3852
- callback(null, this);
3853
- }.bind(this);
3854
- onError = function(err) {
3855
- this.removeListener("parsed", onParsed);
3856
- callback(err, null);
3857
- }.bind(this);
3858
- this.once("parsed", onParsed);
3859
- this.once("error", onError);
3860
- }
3861
- this.end(data);
3862
- return this;
3863
- };
3864
- PNG.prototype.write = function(data) {
3865
- this._parser.write(data);
3866
- return true;
3867
- };
3868
- PNG.prototype.end = function(data) {
3869
- this._parser.end(data);
3870
- };
3871
- PNG.prototype._metadata = function(metadata) {
3872
- this.width = metadata.width;
3873
- this.height = metadata.height;
3874
- this.emit("metadata", metadata);
3875
- };
3876
- PNG.prototype._gamma = function(gamma) {
3877
- this.gamma = gamma;
3878
- };
3879
- PNG.prototype._handleClose = function() {
3880
- if (!this._parser.writable && !this._packer.readable) {
3881
- this.emit("close");
3882
- }
3883
- };
3884
- PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
3885
- srcX |= 0;
3886
- srcY |= 0;
3887
- width |= 0;
3888
- height |= 0;
3889
- deltaX |= 0;
3890
- deltaY |= 0;
3891
- if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
3892
- throw new Error("bitblt reading outside image");
3893
- }
3894
- if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
3895
- throw new Error("bitblt writing outside image");
3896
- }
3897
- for (let y = 0; y < height; y++) {
3898
- src.data.copy(
3899
- dst.data,
3900
- (deltaY + y) * dst.width + deltaX << 2,
3901
- (srcY + y) * src.width + srcX << 2,
3902
- (srcY + y) * src.width + srcX + width << 2
3903
- );
3904
- }
3905
- };
3906
- PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
3907
- PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
3908
- return this;
3909
- };
3910
- PNG.adjustGamma = function(src) {
3911
- if (src.gamma) {
3912
- for (let y = 0; y < src.height; y++) {
3913
- for (let x = 0; x < src.width; x++) {
3914
- let idx = src.width * y + x << 2;
3915
- for (let i = 0; i < 3; i++) {
3916
- let sample = src.data[idx + i] / 255;
3917
- sample = Math.pow(sample, 1 / 2.2 / src.gamma);
3918
- src.data[idx + i] = Math.round(sample * 255);
3919
- }
3920
- }
3921
- }
3922
- src.gamma = 0;
3923
- }
3924
- };
3925
- PNG.prototype.adjustGamma = function() {
3926
- PNG.adjustGamma(this);
3927
- };
3928
- }
3929
- });
3930
-
3931
- // ../../node_modules/qrcode/lib/renderer/utils.js
3932
- var require_utils2 = __commonJS({
3933
- "../../node_modules/qrcode/lib/renderer/utils.js"(exports) {
3934
- function hex2rgba(hex) {
3935
- if (typeof hex === "number") {
3936
- hex = hex.toString();
3937
- }
3938
- if (typeof hex !== "string") {
3939
- throw new Error("Color should be defined as hex string");
3940
- }
3941
- let hexCode = hex.slice().replace("#", "").split("");
3942
- if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
3943
- throw new Error("Invalid hex color: " + hex);
3944
- }
3945
- if (hexCode.length === 3 || hexCode.length === 4) {
3946
- hexCode = Array.prototype.concat.apply([], hexCode.map(function(c) {
3947
- return [c, c];
3948
- }));
3949
- }
3950
- if (hexCode.length === 6) hexCode.push("F", "F");
3951
- const hexValue = parseInt(hexCode.join(""), 16);
3952
- return {
3953
- r: hexValue >> 24 & 255,
3954
- g: hexValue >> 16 & 255,
3955
- b: hexValue >> 8 & 255,
3956
- a: hexValue & 255,
3957
- hex: "#" + hexCode.slice(0, 6).join("")
3958
- };
3959
- }
3960
- exports.getOptions = function getOptions(options) {
3961
- if (!options) options = {};
3962
- if (!options.color) options.color = {};
3963
- const margin = typeof options.margin === "undefined" || options.margin === null || options.margin < 0 ? 4 : options.margin;
3964
- const width = options.width && options.width >= 21 ? options.width : void 0;
3965
- const scale = options.scale || 4;
3966
- return {
3967
- width,
3968
- scale: width ? 4 : scale,
3969
- margin,
3970
- color: {
3971
- dark: hex2rgba(options.color.dark || "#000000ff"),
3972
- light: hex2rgba(options.color.light || "#ffffffff")
3973
- },
3974
- type: options.type,
3975
- rendererOpts: options.rendererOpts || {}
3976
- };
3977
- };
3978
- exports.getScale = function getScale(qrSize, opts) {
3979
- return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
3980
- };
3981
- exports.getImageWidth = function getImageWidth(qrSize, opts) {
3982
- const scale = exports.getScale(qrSize, opts);
3983
- return Math.floor((qrSize + opts.margin * 2) * scale);
3984
- };
3985
- exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
3986
- const size = qr.modules.size;
3987
- const data = qr.modules.data;
3988
- const scale = exports.getScale(size, opts);
3989
- const symbolSize = Math.floor((size + opts.margin * 2) * scale);
3990
- const scaledMargin = opts.margin * scale;
3991
- const palette = [opts.color.light, opts.color.dark];
3992
- for (let i = 0; i < symbolSize; i++) {
3993
- for (let j = 0; j < symbolSize; j++) {
3994
- let posDst = (i * symbolSize + j) * 4;
3995
- let pxColor = opts.color.light;
3996
- if (i >= scaledMargin && j >= scaledMargin && i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
3997
- const iSrc = Math.floor((i - scaledMargin) / scale);
3998
- const jSrc = Math.floor((j - scaledMargin) / scale);
3999
- pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
4000
- }
4001
- imgData[posDst++] = pxColor.r;
4002
- imgData[posDst++] = pxColor.g;
4003
- imgData[posDst++] = pxColor.b;
4004
- imgData[posDst] = pxColor.a;
4005
- }
4006
- }
4007
- };
4008
- }
4009
- });
4010
-
4011
- // ../../node_modules/qrcode/lib/renderer/png.js
4012
- var require_png2 = __commonJS({
4013
- "../../node_modules/qrcode/lib/renderer/png.js"(exports) {
4014
- var fs = __require("fs");
4015
- var PNG = require_png().PNG;
4016
- var Utils = require_utils2();
4017
- exports.render = function render(qrData, options) {
4018
- const opts = Utils.getOptions(options);
4019
- const pngOpts = opts.rendererOpts;
4020
- const size = Utils.getImageWidth(qrData.modules.size, opts);
4021
- pngOpts.width = size;
4022
- pngOpts.height = size;
4023
- const pngImage = new PNG(pngOpts);
4024
- Utils.qrToImageData(pngImage.data, qrData, opts);
4025
- return pngImage;
4026
- };
4027
- exports.renderToDataURL = function renderToDataURL(qrData, options, cb) {
4028
- if (typeof cb === "undefined") {
4029
- cb = options;
4030
- options = void 0;
4031
- }
4032
- exports.renderToBuffer(qrData, options, function(err, output) {
4033
- if (err) cb(err);
4034
- let url = "data:image/png;base64,";
4035
- url += output.toString("base64");
4036
- cb(null, url);
4037
- });
4038
- };
4039
- exports.renderToBuffer = function renderToBuffer(qrData, options, cb) {
4040
- if (typeof cb === "undefined") {
4041
- cb = options;
4042
- options = void 0;
4043
- }
4044
- const png = exports.render(qrData, options);
4045
- const buffer = [];
4046
- png.on("error", cb);
4047
- png.on("data", function(data) {
4048
- buffer.push(data);
4049
- });
4050
- png.on("end", function() {
4051
- cb(null, Buffer.concat(buffer));
4052
- });
4053
- png.pack();
4054
- };
4055
- exports.renderToFile = function renderToFile(path, qrData, options, cb) {
4056
- if (typeof cb === "undefined") {
4057
- cb = options;
4058
- options = void 0;
4059
- }
4060
- let called = false;
4061
- const done = (...args2) => {
4062
- if (called) return;
4063
- called = true;
4064
- cb.apply(null, args2);
4065
- };
4066
- const stream = fs.createWriteStream(path);
4067
- stream.on("error", done);
4068
- stream.on("close", done);
4069
- exports.renderToFileStream(stream, qrData, options);
4070
- };
4071
- exports.renderToFileStream = function renderToFileStream(stream, qrData, options) {
4072
- const png = exports.render(qrData, options);
4073
- png.pack().pipe(stream);
4074
- };
4075
- }
4076
- });
4077
-
4078
- // ../../node_modules/qrcode/lib/renderer/utf8.js
4079
- var require_utf8 = __commonJS({
4080
- "../../node_modules/qrcode/lib/renderer/utf8.js"(exports) {
4081
- var Utils = require_utils2();
4082
- var BLOCK_CHAR = {
4083
- WW: " ",
4084
- WB: "\u2584",
4085
- BB: "\u2588",
4086
- BW: "\u2580"
4087
- };
4088
- var INVERTED_BLOCK_CHAR = {
4089
- BB: " ",
4090
- BW: "\u2584",
4091
- WW: "\u2588",
4092
- WB: "\u2580"
4093
- };
4094
- function getBlockChar(top, bottom, blocks) {
4095
- if (top && bottom) return blocks.BB;
4096
- if (top && !bottom) return blocks.BW;
4097
- if (!top && bottom) return blocks.WB;
4098
- return blocks.WW;
4099
- }
4100
- exports.render = function(qrData, options, cb) {
4101
- const opts = Utils.getOptions(options);
4102
- let blocks = BLOCK_CHAR;
4103
- if (opts.color.dark.hex === "#ffffff" || opts.color.light.hex === "#000000") {
4104
- blocks = INVERTED_BLOCK_CHAR;
4105
- }
4106
- const size = qrData.modules.size;
4107
- const data = qrData.modules.data;
4108
- let output = "";
4109
- let hMargin = Array(size + opts.margin * 2 + 1).join(blocks.WW);
4110
- hMargin = Array(opts.margin / 2 + 1).join(hMargin + "\n");
4111
- const vMargin = Array(opts.margin + 1).join(blocks.WW);
4112
- output += hMargin;
4113
- for (let i = 0; i < size; i += 2) {
4114
- output += vMargin;
4115
- for (let j = 0; j < size; j++) {
4116
- const topModule = data[i * size + j];
4117
- const bottomModule = data[(i + 1) * size + j];
4118
- output += getBlockChar(topModule, bottomModule, blocks);
4119
- }
4120
- output += vMargin + "\n";
4121
- }
4122
- output += hMargin.slice(0, -1);
4123
- if (typeof cb === "function") {
4124
- cb(null, output);
4125
- }
4126
- return output;
4127
- };
4128
- exports.renderToFile = function renderToFile(path, qrData, options, cb) {
4129
- if (typeof cb === "undefined") {
4130
- cb = options;
4131
- options = void 0;
4132
- }
4133
- const fs = __require("fs");
4134
- const utf8 = exports.render(qrData, options);
4135
- fs.writeFile(path, utf8, cb);
4136
- };
4137
- }
4138
- });
4139
-
4140
- // ../../node_modules/qrcode/lib/renderer/terminal/terminal.js
4141
- var require_terminal = __commonJS({
4142
- "../../node_modules/qrcode/lib/renderer/terminal/terminal.js"(exports) {
4143
- exports.render = function(qrData, options, cb) {
4144
- const size = qrData.modules.size;
4145
- const data = qrData.modules.data;
4146
- const black = "\x1B[40m \x1B[0m";
4147
- const white = "\x1B[47m \x1B[0m";
4148
- let output = "";
4149
- const hMargin = Array(size + 3).join(white);
4150
- const vMargin = Array(2).join(white);
4151
- output += hMargin + "\n";
4152
- for (let i = 0; i < size; ++i) {
4153
- output += white;
4154
- for (let j = 0; j < size; j++) {
4155
- output += data[i * size + j] ? black : white;
4156
- }
4157
- output += vMargin + "\n";
4158
- }
4159
- output += hMargin + "\n";
4160
- if (typeof cb === "function") {
4161
- cb(null, output);
4162
- }
4163
- return output;
4164
- };
4165
- }
4166
- });
4167
-
4168
- // ../../node_modules/qrcode/lib/renderer/terminal/terminal-small.js
4169
- var require_terminal_small = __commonJS({
4170
- "../../node_modules/qrcode/lib/renderer/terminal/terminal-small.js"(exports) {
4171
- var backgroundWhite = "\x1B[47m";
4172
- var backgroundBlack = "\x1B[40m";
4173
- var foregroundWhite = "\x1B[37m";
4174
- var foregroundBlack = "\x1B[30m";
4175
- var reset = "\x1B[0m";
4176
- var lineSetupNormal = backgroundWhite + foregroundBlack;
4177
- var lineSetupInverse = backgroundBlack + foregroundWhite;
4178
- var createPalette = function(lineSetup, foregroundWhite2, foregroundBlack2) {
4179
- return {
4180
- // 1 ... white, 2 ... black, 0 ... transparent (default)
4181
- "00": reset + " " + lineSetup,
4182
- "01": reset + foregroundWhite2 + "\u2584" + lineSetup,
4183
- "02": reset + foregroundBlack2 + "\u2584" + lineSetup,
4184
- 10: reset + foregroundWhite2 + "\u2580" + lineSetup,
4185
- 11: " ",
4186
- 12: "\u2584",
4187
- 20: reset + foregroundBlack2 + "\u2580" + lineSetup,
4188
- 21: "\u2580",
4189
- 22: "\u2588"
4190
- };
4191
- };
4192
- var mkCodePixel = function(modules, size, x, y) {
4193
- const sizePlus = size + 1;
4194
- if (x >= sizePlus || y >= sizePlus || y < -1 || x < -1) return "0";
4195
- if (x >= size || y >= size || y < 0 || x < 0) return "1";
4196
- const idx = y * size + x;
4197
- return modules[idx] ? "2" : "1";
4198
- };
4199
- var mkCode = function(modules, size, x, y) {
4200
- return mkCodePixel(modules, size, x, y) + mkCodePixel(modules, size, x, y + 1);
4201
- };
4202
- exports.render = function(qrData, options, cb) {
4203
- const size = qrData.modules.size;
4204
- const data = qrData.modules.data;
4205
- const inverse = !!(options && options.inverse);
4206
- const lineSetup = options && options.inverse ? lineSetupInverse : lineSetupNormal;
4207
- const white = inverse ? foregroundBlack : foregroundWhite;
4208
- const black = inverse ? foregroundWhite : foregroundBlack;
4209
- const palette = createPalette(lineSetup, white, black);
4210
- const newLine = reset + "\n" + lineSetup;
4211
- let output = lineSetup;
4212
- for (let y = -1; y < size + 1; y += 2) {
4213
- for (let x = -1; x < size; x++) {
4214
- output += palette[mkCode(data, size, x, y)];
4215
- }
4216
- output += palette[mkCode(data, size, size, y)] + newLine;
4217
- }
4218
- output += reset;
4219
- if (typeof cb === "function") {
4220
- cb(null, output);
4221
- }
4222
- return output;
4223
- };
4224
- }
4225
- });
4226
-
4227
- // ../../node_modules/qrcode/lib/renderer/terminal.js
4228
- var require_terminal2 = __commonJS({
4229
- "../../node_modules/qrcode/lib/renderer/terminal.js"(exports) {
4230
- var big = require_terminal();
4231
- var small = require_terminal_small();
4232
- exports.render = function(qrData, options, cb) {
4233
- if (options && options.small) {
4234
- return small.render(qrData, options, cb);
4235
- }
4236
- return big.render(qrData, options, cb);
4237
- };
4238
- }
4239
- });
4240
-
4241
- // ../../node_modules/qrcode/lib/renderer/svg-tag.js
4242
- var require_svg_tag = __commonJS({
4243
- "../../node_modules/qrcode/lib/renderer/svg-tag.js"(exports) {
4244
- var Utils = require_utils2();
4245
- function getColorAttrib(color, attrib) {
4246
- const alpha = color.a / 255;
4247
- const str = attrib + '="' + color.hex + '"';
4248
- return alpha < 1 ? str + " " + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str;
4249
- }
4250
- function svgCmd(cmd, x, y) {
4251
- let str = cmd + x;
4252
- if (typeof y !== "undefined") str += " " + y;
4253
- return str;
4254
- }
4255
- function qrToPath(data, size, margin) {
4256
- let path = "";
4257
- let moveBy = 0;
4258
- let newRow = false;
4259
- let lineLength = 0;
4260
- for (let i = 0; i < data.length; i++) {
4261
- const col = Math.floor(i % size);
4262
- const row = Math.floor(i / size);
4263
- if (!col && !newRow) newRow = true;
4264
- if (data[i]) {
4265
- lineLength++;
4266
- if (!(i > 0 && col > 0 && data[i - 1])) {
4267
- path += newRow ? svgCmd("M", col + margin, 0.5 + row + margin) : svgCmd("m", moveBy, 0);
4268
- moveBy = 0;
4269
- newRow = false;
4270
- }
4271
- if (!(col + 1 < size && data[i + 1])) {
4272
- path += svgCmd("h", lineLength);
4273
- lineLength = 0;
4274
- }
4275
- } else {
4276
- moveBy++;
4277
- }
4278
- }
4279
- return path;
4280
- }
4281
- exports.render = function render(qrData, options, cb) {
4282
- const opts = Utils.getOptions(options);
4283
- const size = qrData.modules.size;
4284
- const data = qrData.modules.data;
4285
- const qrcodesize = size + opts.margin * 2;
4286
- const bg = !opts.color.light.a ? "" : "<path " + getColorAttrib(opts.color.light, "fill") + ' d="M0 0h' + qrcodesize + "v" + qrcodesize + 'H0z"/>';
4287
- const path = "<path " + getColorAttrib(opts.color.dark, "stroke") + ' d="' + qrToPath(data, size, opts.margin) + '"/>';
4288
- const viewBox = 'viewBox="0 0 ' + qrcodesize + " " + qrcodesize + '"';
4289
- const width = !opts.width ? "" : 'width="' + opts.width + '" height="' + opts.width + '" ';
4290
- const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + "</svg>\n";
4291
- if (typeof cb === "function") {
4292
- cb(null, svgTag);
4293
- }
4294
- return svgTag;
4295
- };
4296
- }
4297
- });
4298
-
4299
- // ../../node_modules/qrcode/lib/renderer/svg.js
4300
- var require_svg = __commonJS({
4301
- "../../node_modules/qrcode/lib/renderer/svg.js"(exports) {
4302
- var svgTagRenderer = require_svg_tag();
4303
- exports.render = svgTagRenderer.render;
4304
- exports.renderToFile = function renderToFile(path, qrData, options, cb) {
4305
- if (typeof cb === "undefined") {
4306
- cb = options;
4307
- options = void 0;
4308
- }
4309
- const fs = __require("fs");
4310
- const svgTag = exports.render(qrData, options);
4311
- const xmlStr = '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' + svgTag;
4312
- fs.writeFile(path, xmlStr, cb);
4313
- };
4314
- }
4315
- });
4316
-
4317
- // ../../node_modules/qrcode/lib/renderer/canvas.js
4318
- var require_canvas = __commonJS({
4319
- "../../node_modules/qrcode/lib/renderer/canvas.js"(exports) {
4320
- var Utils = require_utils2();
4321
- function clearCanvas(ctx, canvas, size) {
4322
- ctx.clearRect(0, 0, canvas.width, canvas.height);
4323
- if (!canvas.style) canvas.style = {};
4324
- canvas.height = size;
4325
- canvas.width = size;
4326
- canvas.style.height = size + "px";
4327
- canvas.style.width = size + "px";
4328
- }
4329
- function getCanvasElement() {
4330
- try {
4331
- return document.createElement("canvas");
4332
- } catch (e) {
4333
- throw new Error("You need to specify a canvas element");
4334
- }
4335
- }
4336
- exports.render = function render(qrData, canvas, options) {
4337
- let opts = options;
4338
- let canvasEl = canvas;
4339
- if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
4340
- opts = canvas;
4341
- canvas = void 0;
4342
- }
4343
- if (!canvas) {
4344
- canvasEl = getCanvasElement();
4345
- }
4346
- opts = Utils.getOptions(opts);
4347
- const size = Utils.getImageWidth(qrData.modules.size, opts);
4348
- const ctx = canvasEl.getContext("2d");
4349
- const image = ctx.createImageData(size, size);
4350
- Utils.qrToImageData(image.data, qrData, opts);
4351
- clearCanvas(ctx, canvasEl, size);
4352
- ctx.putImageData(image, 0, 0);
4353
- return canvasEl;
4354
- };
4355
- exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
4356
- let opts = options;
4357
- if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
4358
- opts = canvas;
4359
- canvas = void 0;
4360
- }
4361
- if (!opts) opts = {};
4362
- const canvasEl = exports.render(qrData, canvas, opts);
4363
- const type = opts.type || "image/png";
4364
- const rendererOpts = opts.rendererOpts || {};
4365
- return canvasEl.toDataURL(type, rendererOpts.quality);
4366
- };
4367
- }
4368
- });
4369
-
4370
- // ../../node_modules/qrcode/lib/browser.js
4371
- var require_browser = __commonJS({
4372
- "../../node_modules/qrcode/lib/browser.js"(exports) {
4373
- var canPromise = require_can_promise();
4374
- var QRCode2 = require_qrcode();
4375
- var CanvasRenderer = require_canvas();
4376
- var SvgRenderer = require_svg_tag();
4377
- function renderCanvas(renderFunc, canvas, text, opts, cb) {
4378
- const args2 = [].slice.call(arguments, 1);
4379
- const argsNum = args2.length;
4380
- const isLastArgCb = typeof args2[argsNum - 1] === "function";
4381
- if (!isLastArgCb && !canPromise()) {
4382
- throw new Error("Callback required as last argument");
4383
- }
4384
- if (isLastArgCb) {
4385
- if (argsNum < 2) {
4386
- throw new Error("Too few arguments provided");
4387
- }
4388
- if (argsNum === 2) {
4389
- cb = text;
4390
- text = canvas;
4391
- canvas = opts = void 0;
4392
- } else if (argsNum === 3) {
4393
- if (canvas.getContext && typeof cb === "undefined") {
4394
- cb = opts;
4395
- opts = void 0;
4396
- } else {
4397
- cb = opts;
4398
- opts = text;
4399
- text = canvas;
4400
- canvas = void 0;
4401
- }
4402
- }
4403
- } else {
4404
- if (argsNum < 1) {
4405
- throw new Error("Too few arguments provided");
4406
- }
4407
- if (argsNum === 1) {
4408
- text = canvas;
4409
- canvas = opts = void 0;
4410
- } else if (argsNum === 2 && !canvas.getContext) {
4411
- opts = text;
4412
- text = canvas;
4413
- canvas = void 0;
4414
- }
4415
- return new Promise(function(resolve, reject) {
4416
- try {
4417
- const data = QRCode2.create(text, opts);
4418
- resolve(renderFunc(data, canvas, opts));
4419
- } catch (e) {
4420
- reject(e);
4421
- }
4422
- });
4423
- }
4424
- try {
4425
- const data = QRCode2.create(text, opts);
4426
- cb(null, renderFunc(data, canvas, opts));
4427
- } catch (e) {
4428
- cb(e);
4429
- }
4430
- }
4431
- exports.create = QRCode2.create;
4432
- exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
4433
- exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
4434
- exports.toString = renderCanvas.bind(null, function(data, _, opts) {
4435
- return SvgRenderer.render(data, opts);
4436
- });
4437
- }
4438
- });
4439
-
4440
- // ../../node_modules/qrcode/lib/server.js
4441
- var require_server = __commonJS({
4442
- "../../node_modules/qrcode/lib/server.js"(exports) {
4443
- var canPromise = require_can_promise();
4444
- var QRCode2 = require_qrcode();
4445
- var PngRenderer = require_png2();
4446
- var Utf8Renderer = require_utf8();
4447
- var TerminalRenderer = require_terminal2();
4448
- var SvgRenderer = require_svg();
4449
- function checkParams(text, opts, cb) {
4450
- if (typeof text === "undefined") {
4451
- throw new Error("String required as first argument");
4452
- }
4453
- if (typeof cb === "undefined") {
4454
- cb = opts;
4455
- opts = {};
4456
- }
4457
- if (typeof cb !== "function") {
4458
- if (!canPromise()) {
4459
- throw new Error("Callback required as last argument");
4460
- } else {
4461
- opts = cb || {};
4462
- cb = null;
4463
- }
4464
- }
4465
- return {
4466
- opts,
4467
- cb
4468
- };
4469
- }
4470
- function getTypeFromFilename(path) {
4471
- return path.slice((path.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
4472
- }
4473
- function getRendererFromType(type) {
4474
- switch (type) {
4475
- case "svg":
4476
- return SvgRenderer;
4477
- case "txt":
4478
- case "utf8":
4479
- return Utf8Renderer;
4480
- case "png":
4481
- case "image/png":
4482
- default:
4483
- return PngRenderer;
4484
- }
4485
- }
4486
- function getStringRendererFromType(type) {
4487
- switch (type) {
4488
- case "svg":
4489
- return SvgRenderer;
4490
- case "terminal":
4491
- return TerminalRenderer;
4492
- case "utf8":
4493
- default:
4494
- return Utf8Renderer;
4495
- }
4496
- }
4497
- function render(renderFunc, text, params) {
4498
- if (!params.cb) {
4499
- return new Promise(function(resolve, reject) {
4500
- try {
4501
- const data = QRCode2.create(text, params.opts);
4502
- return renderFunc(data, params.opts, function(err, data2) {
4503
- return err ? reject(err) : resolve(data2);
4504
- });
4505
- } catch (e) {
4506
- reject(e);
4507
- }
4508
- });
4509
- }
4510
- try {
4511
- const data = QRCode2.create(text, params.opts);
4512
- return renderFunc(data, params.opts, params.cb);
4513
- } catch (e) {
4514
- params.cb(e);
4515
- }
4516
- }
4517
- exports.create = QRCode2.create;
4518
- exports.toCanvas = require_browser().toCanvas;
4519
- exports.toString = function toString(text, opts, cb) {
4520
- const params = checkParams(text, opts, cb);
4521
- const type = params.opts ? params.opts.type : void 0;
4522
- const renderer = getStringRendererFromType(type);
4523
- return render(renderer.render, text, params);
4524
- };
4525
- exports.toDataURL = function toDataURL(text, opts, cb) {
4526
- const params = checkParams(text, opts, cb);
4527
- const renderer = getRendererFromType(params.opts.type);
4528
- return render(renderer.renderToDataURL, text, params);
4529
- };
4530
- exports.toBuffer = function toBuffer(text, opts, cb) {
4531
- const params = checkParams(text, opts, cb);
4532
- const renderer = getRendererFromType(params.opts.type);
4533
- return render(renderer.renderToBuffer, text, params);
4534
- };
4535
- exports.toFile = function toFile(path, text, opts, cb) {
4536
- if (typeof path !== "string" || !(typeof text === "string" || typeof text === "object")) {
4537
- throw new Error("Invalid argument");
4538
- }
4539
- if (arguments.length < 3 && !canPromise()) {
4540
- throw new Error("Too few arguments provided");
4541
- }
4542
- const params = checkParams(text, opts, cb);
4543
- const type = params.opts.type || getTypeFromFilename(path);
4544
- const renderer = getRendererFromType(type);
4545
- const renderToFile = renderer.renderToFile.bind(null, path);
4546
- return render(renderToFile, text, params);
4547
- };
4548
- exports.toFileStream = function toFileStream(stream, text, opts) {
4549
- if (arguments.length < 2) {
4550
- throw new Error("Too few arguments provided");
4551
- }
4552
- const params = checkParams(text, opts, stream.emit.bind(stream, "error"));
4553
- const renderer = getRendererFromType("png");
4554
- const renderToFileStream = renderer.renderToFileStream.bind(null, stream);
4555
- render(renderToFileStream, text, params);
4556
- };
4557
- }
4558
- });
4559
-
4560
- // ../../node_modules/qrcode/lib/index.js
4561
- var require_lib = __commonJS({
4562
- "../../node_modules/qrcode/lib/index.js"(exports, module) {
4563
- module.exports = require_server();
4564
- }
4565
- });
4566
2
 
4567
3
  // src/bin.ts
4568
4
  import { spawn as spawnChild } from "node:child_process";
4569
5
  import { fileURLToPath } from "node:url";
4570
6
 
4571
7
  // src/index.ts
4572
- var import_qrcode = __toESM(require_lib(), 1);
4573
8
  import WebSocket from "ws";
9
+ import QRCode from "qrcode";
4574
10
 
4575
11
  // ../crypto/dist/crypto.js
4576
12
  var ALGORITHM = "AES-GCM";
@@ -5142,7 +578,7 @@ async function printShareLinkWithQr(label, url) {
5142
578
  console.log(` \x1B[4m\x1B[36m${url}\x1B[0m`);
5143
579
  console.log("");
5144
580
  try {
5145
- const qr = await import_qrcode.default.toString(url, {
581
+ const qr = await QRCode.toString(url, {
5146
582
  type: "terminal",
5147
583
  small: true,
5148
584
  errorCorrectionLevel: "L"