@zerodeploy/cli 0.1.12 → 0.1.14
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.
- package/dist/cli.js +74 -4303
- package/package.json +2 -4
package/dist/cli.js
CHANGED
|
@@ -3560,4295 +3560,6 @@ var require_picomatch2 = __commonJS((exports, module) => {
|
|
|
3560
3560
|
module.exports = picomatch;
|
|
3561
3561
|
});
|
|
3562
3562
|
|
|
3563
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js
|
|
3564
|
-
var require_can_promise = __commonJS((exports, module) => {
|
|
3565
|
-
module.exports = function() {
|
|
3566
|
-
return typeof Promise === "function" && Promise.prototype && Promise.prototype.then;
|
|
3567
|
-
};
|
|
3568
|
-
});
|
|
3569
|
-
|
|
3570
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js
|
|
3571
|
-
var require_utils2 = __commonJS((exports) => {
|
|
3572
|
-
var toSJISFunction;
|
|
3573
|
-
var CODEWORDS_COUNT = [
|
|
3574
|
-
0,
|
|
3575
|
-
26,
|
|
3576
|
-
44,
|
|
3577
|
-
70,
|
|
3578
|
-
100,
|
|
3579
|
-
134,
|
|
3580
|
-
172,
|
|
3581
|
-
196,
|
|
3582
|
-
242,
|
|
3583
|
-
292,
|
|
3584
|
-
346,
|
|
3585
|
-
404,
|
|
3586
|
-
466,
|
|
3587
|
-
532,
|
|
3588
|
-
581,
|
|
3589
|
-
655,
|
|
3590
|
-
733,
|
|
3591
|
-
815,
|
|
3592
|
-
901,
|
|
3593
|
-
991,
|
|
3594
|
-
1085,
|
|
3595
|
-
1156,
|
|
3596
|
-
1258,
|
|
3597
|
-
1364,
|
|
3598
|
-
1474,
|
|
3599
|
-
1588,
|
|
3600
|
-
1706,
|
|
3601
|
-
1828,
|
|
3602
|
-
1921,
|
|
3603
|
-
2051,
|
|
3604
|
-
2185,
|
|
3605
|
-
2323,
|
|
3606
|
-
2465,
|
|
3607
|
-
2611,
|
|
3608
|
-
2761,
|
|
3609
|
-
2876,
|
|
3610
|
-
3034,
|
|
3611
|
-
3196,
|
|
3612
|
-
3362,
|
|
3613
|
-
3532,
|
|
3614
|
-
3706
|
|
3615
|
-
];
|
|
3616
|
-
exports.getSymbolSize = function getSymbolSize(version) {
|
|
3617
|
-
if (!version)
|
|
3618
|
-
throw new Error('"version" cannot be null or undefined');
|
|
3619
|
-
if (version < 1 || version > 40)
|
|
3620
|
-
throw new Error('"version" should be in range from 1 to 40');
|
|
3621
|
-
return version * 4 + 17;
|
|
3622
|
-
};
|
|
3623
|
-
exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
|
|
3624
|
-
return CODEWORDS_COUNT[version];
|
|
3625
|
-
};
|
|
3626
|
-
exports.getBCHDigit = function(data) {
|
|
3627
|
-
let digit = 0;
|
|
3628
|
-
while (data !== 0) {
|
|
3629
|
-
digit++;
|
|
3630
|
-
data >>>= 1;
|
|
3631
|
-
}
|
|
3632
|
-
return digit;
|
|
3633
|
-
};
|
|
3634
|
-
exports.setToSJISFunction = function setToSJISFunction(f) {
|
|
3635
|
-
if (typeof f !== "function") {
|
|
3636
|
-
throw new Error('"toSJISFunc" is not a valid function.');
|
|
3637
|
-
}
|
|
3638
|
-
toSJISFunction = f;
|
|
3639
|
-
};
|
|
3640
|
-
exports.isKanjiModeEnabled = function() {
|
|
3641
|
-
return typeof toSJISFunction !== "undefined";
|
|
3642
|
-
};
|
|
3643
|
-
exports.toSJIS = function toSJIS(kanji) {
|
|
3644
|
-
return toSJISFunction(kanji);
|
|
3645
|
-
};
|
|
3646
|
-
});
|
|
3647
|
-
|
|
3648
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js
|
|
3649
|
-
var require_error_correction_level = __commonJS((exports) => {
|
|
3650
|
-
exports.L = { bit: 1 };
|
|
3651
|
-
exports.M = { bit: 0 };
|
|
3652
|
-
exports.Q = { bit: 3 };
|
|
3653
|
-
exports.H = { bit: 2 };
|
|
3654
|
-
function fromString(string) {
|
|
3655
|
-
if (typeof string !== "string") {
|
|
3656
|
-
throw new Error("Param is not a string");
|
|
3657
|
-
}
|
|
3658
|
-
const lcStr = string.toLowerCase();
|
|
3659
|
-
switch (lcStr) {
|
|
3660
|
-
case "l":
|
|
3661
|
-
case "low":
|
|
3662
|
-
return exports.L;
|
|
3663
|
-
case "m":
|
|
3664
|
-
case "medium":
|
|
3665
|
-
return exports.M;
|
|
3666
|
-
case "q":
|
|
3667
|
-
case "quartile":
|
|
3668
|
-
return exports.Q;
|
|
3669
|
-
case "h":
|
|
3670
|
-
case "high":
|
|
3671
|
-
return exports.H;
|
|
3672
|
-
default:
|
|
3673
|
-
throw new Error("Unknown EC Level: " + string);
|
|
3674
|
-
}
|
|
3675
|
-
}
|
|
3676
|
-
exports.isValid = function isValid(level) {
|
|
3677
|
-
return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
|
|
3678
|
-
};
|
|
3679
|
-
exports.from = function from(value, defaultValue) {
|
|
3680
|
-
if (exports.isValid(value)) {
|
|
3681
|
-
return value;
|
|
3682
|
-
}
|
|
3683
|
-
try {
|
|
3684
|
-
return fromString(value);
|
|
3685
|
-
} catch (e) {
|
|
3686
|
-
return defaultValue;
|
|
3687
|
-
}
|
|
3688
|
-
};
|
|
3689
|
-
});
|
|
3690
|
-
|
|
3691
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js
|
|
3692
|
-
var require_bit_buffer = __commonJS((exports, module) => {
|
|
3693
|
-
function BitBuffer() {
|
|
3694
|
-
this.buffer = [];
|
|
3695
|
-
this.length = 0;
|
|
3696
|
-
}
|
|
3697
|
-
BitBuffer.prototype = {
|
|
3698
|
-
get: function(index) {
|
|
3699
|
-
const bufIndex = Math.floor(index / 8);
|
|
3700
|
-
return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
|
|
3701
|
-
},
|
|
3702
|
-
put: function(num, length) {
|
|
3703
|
-
for (let i2 = 0;i2 < length; i2++) {
|
|
3704
|
-
this.putBit((num >>> length - i2 - 1 & 1) === 1);
|
|
3705
|
-
}
|
|
3706
|
-
},
|
|
3707
|
-
getLengthInBits: function() {
|
|
3708
|
-
return this.length;
|
|
3709
|
-
},
|
|
3710
|
-
putBit: function(bit) {
|
|
3711
|
-
const bufIndex = Math.floor(this.length / 8);
|
|
3712
|
-
if (this.buffer.length <= bufIndex) {
|
|
3713
|
-
this.buffer.push(0);
|
|
3714
|
-
}
|
|
3715
|
-
if (bit) {
|
|
3716
|
-
this.buffer[bufIndex] |= 128 >>> this.length % 8;
|
|
3717
|
-
}
|
|
3718
|
-
this.length++;
|
|
3719
|
-
}
|
|
3720
|
-
};
|
|
3721
|
-
module.exports = BitBuffer;
|
|
3722
|
-
});
|
|
3723
|
-
|
|
3724
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js
|
|
3725
|
-
var require_bit_matrix = __commonJS((exports, module) => {
|
|
3726
|
-
function BitMatrix(size) {
|
|
3727
|
-
if (!size || size < 1) {
|
|
3728
|
-
throw new Error("BitMatrix size must be defined and greater than 0");
|
|
3729
|
-
}
|
|
3730
|
-
this.size = size;
|
|
3731
|
-
this.data = new Uint8Array(size * size);
|
|
3732
|
-
this.reservedBit = new Uint8Array(size * size);
|
|
3733
|
-
}
|
|
3734
|
-
BitMatrix.prototype.set = function(row, col, value, reserved) {
|
|
3735
|
-
const index = row * this.size + col;
|
|
3736
|
-
this.data[index] = value;
|
|
3737
|
-
if (reserved)
|
|
3738
|
-
this.reservedBit[index] = true;
|
|
3739
|
-
};
|
|
3740
|
-
BitMatrix.prototype.get = function(row, col) {
|
|
3741
|
-
return this.data[row * this.size + col];
|
|
3742
|
-
};
|
|
3743
|
-
BitMatrix.prototype.xor = function(row, col, value) {
|
|
3744
|
-
this.data[row * this.size + col] ^= value;
|
|
3745
|
-
};
|
|
3746
|
-
BitMatrix.prototype.isReserved = function(row, col) {
|
|
3747
|
-
return this.reservedBit[row * this.size + col];
|
|
3748
|
-
};
|
|
3749
|
-
module.exports = BitMatrix;
|
|
3750
|
-
});
|
|
3751
|
-
|
|
3752
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js
|
|
3753
|
-
var require_alignment_pattern = __commonJS((exports) => {
|
|
3754
|
-
var getSymbolSize = require_utils2().getSymbolSize;
|
|
3755
|
-
exports.getRowColCoords = function getRowColCoords(version) {
|
|
3756
|
-
if (version === 1)
|
|
3757
|
-
return [];
|
|
3758
|
-
const posCount = Math.floor(version / 7) + 2;
|
|
3759
|
-
const size = getSymbolSize(version);
|
|
3760
|
-
const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
|
|
3761
|
-
const positions = [size - 7];
|
|
3762
|
-
for (let i2 = 1;i2 < posCount - 1; i2++) {
|
|
3763
|
-
positions[i2] = positions[i2 - 1] - intervals;
|
|
3764
|
-
}
|
|
3765
|
-
positions.push(6);
|
|
3766
|
-
return positions.reverse();
|
|
3767
|
-
};
|
|
3768
|
-
exports.getPositions = function getPositions(version) {
|
|
3769
|
-
const coords = [];
|
|
3770
|
-
const pos = exports.getRowColCoords(version);
|
|
3771
|
-
const posLength = pos.length;
|
|
3772
|
-
for (let i2 = 0;i2 < posLength; i2++) {
|
|
3773
|
-
for (let j = 0;j < posLength; j++) {
|
|
3774
|
-
if (i2 === 0 && j === 0 || i2 === 0 && j === posLength - 1 || i2 === posLength - 1 && j === 0) {
|
|
3775
|
-
continue;
|
|
3776
|
-
}
|
|
3777
|
-
coords.push([pos[i2], pos[j]]);
|
|
3778
|
-
}
|
|
3779
|
-
}
|
|
3780
|
-
return coords;
|
|
3781
|
-
};
|
|
3782
|
-
});
|
|
3783
|
-
|
|
3784
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js
|
|
3785
|
-
var require_finder_pattern = __commonJS((exports) => {
|
|
3786
|
-
var getSymbolSize = require_utils2().getSymbolSize;
|
|
3787
|
-
var FINDER_PATTERN_SIZE = 7;
|
|
3788
|
-
exports.getPositions = function getPositions(version) {
|
|
3789
|
-
const size = getSymbolSize(version);
|
|
3790
|
-
return [
|
|
3791
|
-
[0, 0],
|
|
3792
|
-
[size - FINDER_PATTERN_SIZE, 0],
|
|
3793
|
-
[0, size - FINDER_PATTERN_SIZE]
|
|
3794
|
-
];
|
|
3795
|
-
};
|
|
3796
|
-
});
|
|
3797
|
-
|
|
3798
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js
|
|
3799
|
-
var require_mask_pattern = __commonJS((exports) => {
|
|
3800
|
-
exports.Patterns = {
|
|
3801
|
-
PATTERN000: 0,
|
|
3802
|
-
PATTERN001: 1,
|
|
3803
|
-
PATTERN010: 2,
|
|
3804
|
-
PATTERN011: 3,
|
|
3805
|
-
PATTERN100: 4,
|
|
3806
|
-
PATTERN101: 5,
|
|
3807
|
-
PATTERN110: 6,
|
|
3808
|
-
PATTERN111: 7
|
|
3809
|
-
};
|
|
3810
|
-
var PenaltyScores = {
|
|
3811
|
-
N1: 3,
|
|
3812
|
-
N2: 3,
|
|
3813
|
-
N3: 40,
|
|
3814
|
-
N4: 10
|
|
3815
|
-
};
|
|
3816
|
-
exports.isValid = function isValid(mask) {
|
|
3817
|
-
return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
|
|
3818
|
-
};
|
|
3819
|
-
exports.from = function from(value) {
|
|
3820
|
-
return exports.isValid(value) ? parseInt(value, 10) : undefined;
|
|
3821
|
-
};
|
|
3822
|
-
exports.getPenaltyN1 = function getPenaltyN1(data) {
|
|
3823
|
-
const size = data.size;
|
|
3824
|
-
let points = 0;
|
|
3825
|
-
let sameCountCol = 0;
|
|
3826
|
-
let sameCountRow = 0;
|
|
3827
|
-
let lastCol = null;
|
|
3828
|
-
let lastRow = null;
|
|
3829
|
-
for (let row = 0;row < size; row++) {
|
|
3830
|
-
sameCountCol = sameCountRow = 0;
|
|
3831
|
-
lastCol = lastRow = null;
|
|
3832
|
-
for (let col = 0;col < size; col++) {
|
|
3833
|
-
let module2 = data.get(row, col);
|
|
3834
|
-
if (module2 === lastCol) {
|
|
3835
|
-
sameCountCol++;
|
|
3836
|
-
} else {
|
|
3837
|
-
if (sameCountCol >= 5)
|
|
3838
|
-
points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
3839
|
-
lastCol = module2;
|
|
3840
|
-
sameCountCol = 1;
|
|
3841
|
-
}
|
|
3842
|
-
module2 = data.get(col, row);
|
|
3843
|
-
if (module2 === lastRow) {
|
|
3844
|
-
sameCountRow++;
|
|
3845
|
-
} else {
|
|
3846
|
-
if (sameCountRow >= 5)
|
|
3847
|
-
points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
3848
|
-
lastRow = module2;
|
|
3849
|
-
sameCountRow = 1;
|
|
3850
|
-
}
|
|
3851
|
-
}
|
|
3852
|
-
if (sameCountCol >= 5)
|
|
3853
|
-
points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
3854
|
-
if (sameCountRow >= 5)
|
|
3855
|
-
points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
3856
|
-
}
|
|
3857
|
-
return points;
|
|
3858
|
-
};
|
|
3859
|
-
exports.getPenaltyN2 = function getPenaltyN2(data) {
|
|
3860
|
-
const size = data.size;
|
|
3861
|
-
let points = 0;
|
|
3862
|
-
for (let row = 0;row < size - 1; row++) {
|
|
3863
|
-
for (let col = 0;col < size - 1; col++) {
|
|
3864
|
-
const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
|
|
3865
|
-
if (last === 4 || last === 0)
|
|
3866
|
-
points++;
|
|
3867
|
-
}
|
|
3868
|
-
}
|
|
3869
|
-
return points * PenaltyScores.N2;
|
|
3870
|
-
};
|
|
3871
|
-
exports.getPenaltyN3 = function getPenaltyN3(data) {
|
|
3872
|
-
const size = data.size;
|
|
3873
|
-
let points = 0;
|
|
3874
|
-
let bitsCol = 0;
|
|
3875
|
-
let bitsRow = 0;
|
|
3876
|
-
for (let row = 0;row < size; row++) {
|
|
3877
|
-
bitsCol = bitsRow = 0;
|
|
3878
|
-
for (let col = 0;col < size; col++) {
|
|
3879
|
-
bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
|
|
3880
|
-
if (col >= 10 && (bitsCol === 1488 || bitsCol === 93))
|
|
3881
|
-
points++;
|
|
3882
|
-
bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
|
|
3883
|
-
if (col >= 10 && (bitsRow === 1488 || bitsRow === 93))
|
|
3884
|
-
points++;
|
|
3885
|
-
}
|
|
3886
|
-
}
|
|
3887
|
-
return points * PenaltyScores.N3;
|
|
3888
|
-
};
|
|
3889
|
-
exports.getPenaltyN4 = function getPenaltyN4(data) {
|
|
3890
|
-
let darkCount = 0;
|
|
3891
|
-
const modulesCount = data.data.length;
|
|
3892
|
-
for (let i2 = 0;i2 < modulesCount; i2++)
|
|
3893
|
-
darkCount += data.data[i2];
|
|
3894
|
-
const k = Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10);
|
|
3895
|
-
return k * PenaltyScores.N4;
|
|
3896
|
-
};
|
|
3897
|
-
function getMaskAt(maskPattern, i2, j) {
|
|
3898
|
-
switch (maskPattern) {
|
|
3899
|
-
case exports.Patterns.PATTERN000:
|
|
3900
|
-
return (i2 + j) % 2 === 0;
|
|
3901
|
-
case exports.Patterns.PATTERN001:
|
|
3902
|
-
return i2 % 2 === 0;
|
|
3903
|
-
case exports.Patterns.PATTERN010:
|
|
3904
|
-
return j % 3 === 0;
|
|
3905
|
-
case exports.Patterns.PATTERN011:
|
|
3906
|
-
return (i2 + j) % 3 === 0;
|
|
3907
|
-
case exports.Patterns.PATTERN100:
|
|
3908
|
-
return (Math.floor(i2 / 2) + Math.floor(j / 3)) % 2 === 0;
|
|
3909
|
-
case exports.Patterns.PATTERN101:
|
|
3910
|
-
return i2 * j % 2 + i2 * j % 3 === 0;
|
|
3911
|
-
case exports.Patterns.PATTERN110:
|
|
3912
|
-
return (i2 * j % 2 + i2 * j % 3) % 2 === 0;
|
|
3913
|
-
case exports.Patterns.PATTERN111:
|
|
3914
|
-
return (i2 * j % 3 + (i2 + j) % 2) % 2 === 0;
|
|
3915
|
-
default:
|
|
3916
|
-
throw new Error("bad maskPattern:" + maskPattern);
|
|
3917
|
-
}
|
|
3918
|
-
}
|
|
3919
|
-
exports.applyMask = function applyMask(pattern, data) {
|
|
3920
|
-
const size = data.size;
|
|
3921
|
-
for (let col = 0;col < size; col++) {
|
|
3922
|
-
for (let row = 0;row < size; row++) {
|
|
3923
|
-
if (data.isReserved(row, col))
|
|
3924
|
-
continue;
|
|
3925
|
-
data.xor(row, col, getMaskAt(pattern, row, col));
|
|
3926
|
-
}
|
|
3927
|
-
}
|
|
3928
|
-
};
|
|
3929
|
-
exports.getBestMask = function getBestMask(data, setupFormatFunc) {
|
|
3930
|
-
const numPatterns = Object.keys(exports.Patterns).length;
|
|
3931
|
-
let bestPattern = 0;
|
|
3932
|
-
let lowerPenalty = Infinity;
|
|
3933
|
-
for (let p = 0;p < numPatterns; p++) {
|
|
3934
|
-
setupFormatFunc(p);
|
|
3935
|
-
exports.applyMask(p, data);
|
|
3936
|
-
const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
|
|
3937
|
-
exports.applyMask(p, data);
|
|
3938
|
-
if (penalty < lowerPenalty) {
|
|
3939
|
-
lowerPenalty = penalty;
|
|
3940
|
-
bestPattern = p;
|
|
3941
|
-
}
|
|
3942
|
-
}
|
|
3943
|
-
return bestPattern;
|
|
3944
|
-
};
|
|
3945
|
-
});
|
|
3946
|
-
|
|
3947
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js
|
|
3948
|
-
var require_error_correction_code = __commonJS((exports) => {
|
|
3949
|
-
var ECLevel = require_error_correction_level();
|
|
3950
|
-
var EC_BLOCKS_TABLE = [
|
|
3951
|
-
1,
|
|
3952
|
-
1,
|
|
3953
|
-
1,
|
|
3954
|
-
1,
|
|
3955
|
-
1,
|
|
3956
|
-
1,
|
|
3957
|
-
1,
|
|
3958
|
-
1,
|
|
3959
|
-
1,
|
|
3960
|
-
1,
|
|
3961
|
-
2,
|
|
3962
|
-
2,
|
|
3963
|
-
1,
|
|
3964
|
-
2,
|
|
3965
|
-
2,
|
|
3966
|
-
4,
|
|
3967
|
-
1,
|
|
3968
|
-
2,
|
|
3969
|
-
4,
|
|
3970
|
-
4,
|
|
3971
|
-
2,
|
|
3972
|
-
4,
|
|
3973
|
-
4,
|
|
3974
|
-
4,
|
|
3975
|
-
2,
|
|
3976
|
-
4,
|
|
3977
|
-
6,
|
|
3978
|
-
5,
|
|
3979
|
-
2,
|
|
3980
|
-
4,
|
|
3981
|
-
6,
|
|
3982
|
-
6,
|
|
3983
|
-
2,
|
|
3984
|
-
5,
|
|
3985
|
-
8,
|
|
3986
|
-
8,
|
|
3987
|
-
4,
|
|
3988
|
-
5,
|
|
3989
|
-
8,
|
|
3990
|
-
8,
|
|
3991
|
-
4,
|
|
3992
|
-
5,
|
|
3993
|
-
8,
|
|
3994
|
-
11,
|
|
3995
|
-
4,
|
|
3996
|
-
8,
|
|
3997
|
-
10,
|
|
3998
|
-
11,
|
|
3999
|
-
4,
|
|
4000
|
-
9,
|
|
4001
|
-
12,
|
|
4002
|
-
16,
|
|
4003
|
-
4,
|
|
4004
|
-
9,
|
|
4005
|
-
16,
|
|
4006
|
-
16,
|
|
4007
|
-
6,
|
|
4008
|
-
10,
|
|
4009
|
-
12,
|
|
4010
|
-
18,
|
|
4011
|
-
6,
|
|
4012
|
-
10,
|
|
4013
|
-
17,
|
|
4014
|
-
16,
|
|
4015
|
-
6,
|
|
4016
|
-
11,
|
|
4017
|
-
16,
|
|
4018
|
-
19,
|
|
4019
|
-
6,
|
|
4020
|
-
13,
|
|
4021
|
-
18,
|
|
4022
|
-
21,
|
|
4023
|
-
7,
|
|
4024
|
-
14,
|
|
4025
|
-
21,
|
|
4026
|
-
25,
|
|
4027
|
-
8,
|
|
4028
|
-
16,
|
|
4029
|
-
20,
|
|
4030
|
-
25,
|
|
4031
|
-
8,
|
|
4032
|
-
17,
|
|
4033
|
-
23,
|
|
4034
|
-
25,
|
|
4035
|
-
9,
|
|
4036
|
-
17,
|
|
4037
|
-
23,
|
|
4038
|
-
34,
|
|
4039
|
-
9,
|
|
4040
|
-
18,
|
|
4041
|
-
25,
|
|
4042
|
-
30,
|
|
4043
|
-
10,
|
|
4044
|
-
20,
|
|
4045
|
-
27,
|
|
4046
|
-
32,
|
|
4047
|
-
12,
|
|
4048
|
-
21,
|
|
4049
|
-
29,
|
|
4050
|
-
35,
|
|
4051
|
-
12,
|
|
4052
|
-
23,
|
|
4053
|
-
34,
|
|
4054
|
-
37,
|
|
4055
|
-
12,
|
|
4056
|
-
25,
|
|
4057
|
-
34,
|
|
4058
|
-
40,
|
|
4059
|
-
13,
|
|
4060
|
-
26,
|
|
4061
|
-
35,
|
|
4062
|
-
42,
|
|
4063
|
-
14,
|
|
4064
|
-
28,
|
|
4065
|
-
38,
|
|
4066
|
-
45,
|
|
4067
|
-
15,
|
|
4068
|
-
29,
|
|
4069
|
-
40,
|
|
4070
|
-
48,
|
|
4071
|
-
16,
|
|
4072
|
-
31,
|
|
4073
|
-
43,
|
|
4074
|
-
51,
|
|
4075
|
-
17,
|
|
4076
|
-
33,
|
|
4077
|
-
45,
|
|
4078
|
-
54,
|
|
4079
|
-
18,
|
|
4080
|
-
35,
|
|
4081
|
-
48,
|
|
4082
|
-
57,
|
|
4083
|
-
19,
|
|
4084
|
-
37,
|
|
4085
|
-
51,
|
|
4086
|
-
60,
|
|
4087
|
-
19,
|
|
4088
|
-
38,
|
|
4089
|
-
53,
|
|
4090
|
-
63,
|
|
4091
|
-
20,
|
|
4092
|
-
40,
|
|
4093
|
-
56,
|
|
4094
|
-
66,
|
|
4095
|
-
21,
|
|
4096
|
-
43,
|
|
4097
|
-
59,
|
|
4098
|
-
70,
|
|
4099
|
-
22,
|
|
4100
|
-
45,
|
|
4101
|
-
62,
|
|
4102
|
-
74,
|
|
4103
|
-
24,
|
|
4104
|
-
47,
|
|
4105
|
-
65,
|
|
4106
|
-
77,
|
|
4107
|
-
25,
|
|
4108
|
-
49,
|
|
4109
|
-
68,
|
|
4110
|
-
81
|
|
4111
|
-
];
|
|
4112
|
-
var EC_CODEWORDS_TABLE = [
|
|
4113
|
-
7,
|
|
4114
|
-
10,
|
|
4115
|
-
13,
|
|
4116
|
-
17,
|
|
4117
|
-
10,
|
|
4118
|
-
16,
|
|
4119
|
-
22,
|
|
4120
|
-
28,
|
|
4121
|
-
15,
|
|
4122
|
-
26,
|
|
4123
|
-
36,
|
|
4124
|
-
44,
|
|
4125
|
-
20,
|
|
4126
|
-
36,
|
|
4127
|
-
52,
|
|
4128
|
-
64,
|
|
4129
|
-
26,
|
|
4130
|
-
48,
|
|
4131
|
-
72,
|
|
4132
|
-
88,
|
|
4133
|
-
36,
|
|
4134
|
-
64,
|
|
4135
|
-
96,
|
|
4136
|
-
112,
|
|
4137
|
-
40,
|
|
4138
|
-
72,
|
|
4139
|
-
108,
|
|
4140
|
-
130,
|
|
4141
|
-
48,
|
|
4142
|
-
88,
|
|
4143
|
-
132,
|
|
4144
|
-
156,
|
|
4145
|
-
60,
|
|
4146
|
-
110,
|
|
4147
|
-
160,
|
|
4148
|
-
192,
|
|
4149
|
-
72,
|
|
4150
|
-
130,
|
|
4151
|
-
192,
|
|
4152
|
-
224,
|
|
4153
|
-
80,
|
|
4154
|
-
150,
|
|
4155
|
-
224,
|
|
4156
|
-
264,
|
|
4157
|
-
96,
|
|
4158
|
-
176,
|
|
4159
|
-
260,
|
|
4160
|
-
308,
|
|
4161
|
-
104,
|
|
4162
|
-
198,
|
|
4163
|
-
288,
|
|
4164
|
-
352,
|
|
4165
|
-
120,
|
|
4166
|
-
216,
|
|
4167
|
-
320,
|
|
4168
|
-
384,
|
|
4169
|
-
132,
|
|
4170
|
-
240,
|
|
4171
|
-
360,
|
|
4172
|
-
432,
|
|
4173
|
-
144,
|
|
4174
|
-
280,
|
|
4175
|
-
408,
|
|
4176
|
-
480,
|
|
4177
|
-
168,
|
|
4178
|
-
308,
|
|
4179
|
-
448,
|
|
4180
|
-
532,
|
|
4181
|
-
180,
|
|
4182
|
-
338,
|
|
4183
|
-
504,
|
|
4184
|
-
588,
|
|
4185
|
-
196,
|
|
4186
|
-
364,
|
|
4187
|
-
546,
|
|
4188
|
-
650,
|
|
4189
|
-
224,
|
|
4190
|
-
416,
|
|
4191
|
-
600,
|
|
4192
|
-
700,
|
|
4193
|
-
224,
|
|
4194
|
-
442,
|
|
4195
|
-
644,
|
|
4196
|
-
750,
|
|
4197
|
-
252,
|
|
4198
|
-
476,
|
|
4199
|
-
690,
|
|
4200
|
-
816,
|
|
4201
|
-
270,
|
|
4202
|
-
504,
|
|
4203
|
-
750,
|
|
4204
|
-
900,
|
|
4205
|
-
300,
|
|
4206
|
-
560,
|
|
4207
|
-
810,
|
|
4208
|
-
960,
|
|
4209
|
-
312,
|
|
4210
|
-
588,
|
|
4211
|
-
870,
|
|
4212
|
-
1050,
|
|
4213
|
-
336,
|
|
4214
|
-
644,
|
|
4215
|
-
952,
|
|
4216
|
-
1110,
|
|
4217
|
-
360,
|
|
4218
|
-
700,
|
|
4219
|
-
1020,
|
|
4220
|
-
1200,
|
|
4221
|
-
390,
|
|
4222
|
-
728,
|
|
4223
|
-
1050,
|
|
4224
|
-
1260,
|
|
4225
|
-
420,
|
|
4226
|
-
784,
|
|
4227
|
-
1140,
|
|
4228
|
-
1350,
|
|
4229
|
-
450,
|
|
4230
|
-
812,
|
|
4231
|
-
1200,
|
|
4232
|
-
1440,
|
|
4233
|
-
480,
|
|
4234
|
-
868,
|
|
4235
|
-
1290,
|
|
4236
|
-
1530,
|
|
4237
|
-
510,
|
|
4238
|
-
924,
|
|
4239
|
-
1350,
|
|
4240
|
-
1620,
|
|
4241
|
-
540,
|
|
4242
|
-
980,
|
|
4243
|
-
1440,
|
|
4244
|
-
1710,
|
|
4245
|
-
570,
|
|
4246
|
-
1036,
|
|
4247
|
-
1530,
|
|
4248
|
-
1800,
|
|
4249
|
-
570,
|
|
4250
|
-
1064,
|
|
4251
|
-
1590,
|
|
4252
|
-
1890,
|
|
4253
|
-
600,
|
|
4254
|
-
1120,
|
|
4255
|
-
1680,
|
|
4256
|
-
1980,
|
|
4257
|
-
630,
|
|
4258
|
-
1204,
|
|
4259
|
-
1770,
|
|
4260
|
-
2100,
|
|
4261
|
-
660,
|
|
4262
|
-
1260,
|
|
4263
|
-
1860,
|
|
4264
|
-
2220,
|
|
4265
|
-
720,
|
|
4266
|
-
1316,
|
|
4267
|
-
1950,
|
|
4268
|
-
2310,
|
|
4269
|
-
750,
|
|
4270
|
-
1372,
|
|
4271
|
-
2040,
|
|
4272
|
-
2430
|
|
4273
|
-
];
|
|
4274
|
-
exports.getBlocksCount = function getBlocksCount(version, errorCorrectionLevel) {
|
|
4275
|
-
switch (errorCorrectionLevel) {
|
|
4276
|
-
case ECLevel.L:
|
|
4277
|
-
return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
|
|
4278
|
-
case ECLevel.M:
|
|
4279
|
-
return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
|
|
4280
|
-
case ECLevel.Q:
|
|
4281
|
-
return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
|
|
4282
|
-
case ECLevel.H:
|
|
4283
|
-
return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
|
|
4284
|
-
default:
|
|
4285
|
-
return;
|
|
4286
|
-
}
|
|
4287
|
-
};
|
|
4288
|
-
exports.getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel) {
|
|
4289
|
-
switch (errorCorrectionLevel) {
|
|
4290
|
-
case ECLevel.L:
|
|
4291
|
-
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
|
|
4292
|
-
case ECLevel.M:
|
|
4293
|
-
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
|
|
4294
|
-
case ECLevel.Q:
|
|
4295
|
-
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
|
|
4296
|
-
case ECLevel.H:
|
|
4297
|
-
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
|
|
4298
|
-
default:
|
|
4299
|
-
return;
|
|
4300
|
-
}
|
|
4301
|
-
};
|
|
4302
|
-
});
|
|
4303
|
-
|
|
4304
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js
|
|
4305
|
-
var require_galois_field = __commonJS((exports) => {
|
|
4306
|
-
var EXP_TABLE = new Uint8Array(512);
|
|
4307
|
-
var LOG_TABLE = new Uint8Array(256);
|
|
4308
|
-
(function initTables() {
|
|
4309
|
-
let x2 = 1;
|
|
4310
|
-
for (let i2 = 0;i2 < 255; i2++) {
|
|
4311
|
-
EXP_TABLE[i2] = x2;
|
|
4312
|
-
LOG_TABLE[x2] = i2;
|
|
4313
|
-
x2 <<= 1;
|
|
4314
|
-
if (x2 & 256) {
|
|
4315
|
-
x2 ^= 285;
|
|
4316
|
-
}
|
|
4317
|
-
}
|
|
4318
|
-
for (let i2 = 255;i2 < 512; i2++) {
|
|
4319
|
-
EXP_TABLE[i2] = EXP_TABLE[i2 - 255];
|
|
4320
|
-
}
|
|
4321
|
-
})();
|
|
4322
|
-
exports.log = function log(n) {
|
|
4323
|
-
if (n < 1)
|
|
4324
|
-
throw new Error("log(" + n + ")");
|
|
4325
|
-
return LOG_TABLE[n];
|
|
4326
|
-
};
|
|
4327
|
-
exports.exp = function exp(n) {
|
|
4328
|
-
return EXP_TABLE[n];
|
|
4329
|
-
};
|
|
4330
|
-
exports.mul = function mul(x2, y) {
|
|
4331
|
-
if (x2 === 0 || y === 0)
|
|
4332
|
-
return 0;
|
|
4333
|
-
return EXP_TABLE[LOG_TABLE[x2] + LOG_TABLE[y]];
|
|
4334
|
-
};
|
|
4335
|
-
});
|
|
4336
|
-
|
|
4337
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js
|
|
4338
|
-
var require_polynomial = __commonJS((exports) => {
|
|
4339
|
-
var GF = require_galois_field();
|
|
4340
|
-
exports.mul = function mul(p1, p2) {
|
|
4341
|
-
const coeff = new Uint8Array(p1.length + p2.length - 1);
|
|
4342
|
-
for (let i2 = 0;i2 < p1.length; i2++) {
|
|
4343
|
-
for (let j = 0;j < p2.length; j++) {
|
|
4344
|
-
coeff[i2 + j] ^= GF.mul(p1[i2], p2[j]);
|
|
4345
|
-
}
|
|
4346
|
-
}
|
|
4347
|
-
return coeff;
|
|
4348
|
-
};
|
|
4349
|
-
exports.mod = function mod(divident, divisor) {
|
|
4350
|
-
let result = new Uint8Array(divident);
|
|
4351
|
-
while (result.length - divisor.length >= 0) {
|
|
4352
|
-
const coeff = result[0];
|
|
4353
|
-
for (let i2 = 0;i2 < divisor.length; i2++) {
|
|
4354
|
-
result[i2] ^= GF.mul(divisor[i2], coeff);
|
|
4355
|
-
}
|
|
4356
|
-
let offset = 0;
|
|
4357
|
-
while (offset < result.length && result[offset] === 0)
|
|
4358
|
-
offset++;
|
|
4359
|
-
result = result.slice(offset);
|
|
4360
|
-
}
|
|
4361
|
-
return result;
|
|
4362
|
-
};
|
|
4363
|
-
exports.generateECPolynomial = function generateECPolynomial(degree) {
|
|
4364
|
-
let poly = new Uint8Array([1]);
|
|
4365
|
-
for (let i2 = 0;i2 < degree; i2++) {
|
|
4366
|
-
poly = exports.mul(poly, new Uint8Array([1, GF.exp(i2)]));
|
|
4367
|
-
}
|
|
4368
|
-
return poly;
|
|
4369
|
-
};
|
|
4370
|
-
});
|
|
4371
|
-
|
|
4372
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js
|
|
4373
|
-
var require_reed_solomon_encoder = __commonJS((exports, module) => {
|
|
4374
|
-
var Polynomial = require_polynomial();
|
|
4375
|
-
function ReedSolomonEncoder(degree) {
|
|
4376
|
-
this.genPoly = undefined;
|
|
4377
|
-
this.degree = degree;
|
|
4378
|
-
if (this.degree)
|
|
4379
|
-
this.initialize(this.degree);
|
|
4380
|
-
}
|
|
4381
|
-
ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
|
|
4382
|
-
this.degree = degree;
|
|
4383
|
-
this.genPoly = Polynomial.generateECPolynomial(this.degree);
|
|
4384
|
-
};
|
|
4385
|
-
ReedSolomonEncoder.prototype.encode = function encode(data) {
|
|
4386
|
-
if (!this.genPoly) {
|
|
4387
|
-
throw new Error("Encoder not initialized");
|
|
4388
|
-
}
|
|
4389
|
-
const paddedData = new Uint8Array(data.length + this.degree);
|
|
4390
|
-
paddedData.set(data);
|
|
4391
|
-
const remainder = Polynomial.mod(paddedData, this.genPoly);
|
|
4392
|
-
const start = this.degree - remainder.length;
|
|
4393
|
-
if (start > 0) {
|
|
4394
|
-
const buff = new Uint8Array(this.degree);
|
|
4395
|
-
buff.set(remainder, start);
|
|
4396
|
-
return buff;
|
|
4397
|
-
}
|
|
4398
|
-
return remainder;
|
|
4399
|
-
};
|
|
4400
|
-
module.exports = ReedSolomonEncoder;
|
|
4401
|
-
});
|
|
4402
|
-
|
|
4403
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js
|
|
4404
|
-
var require_version_check = __commonJS((exports) => {
|
|
4405
|
-
exports.isValid = function isValid(version) {
|
|
4406
|
-
return !isNaN(version) && version >= 1 && version <= 40;
|
|
4407
|
-
};
|
|
4408
|
-
});
|
|
4409
|
-
|
|
4410
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js
|
|
4411
|
-
var require_regex = __commonJS((exports) => {
|
|
4412
|
-
var numeric = "[0-9]+";
|
|
4413
|
-
var alphanumeric = "[A-Z $%*+\\-./:]+";
|
|
4414
|
-
var kanji = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|" + "[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|" + "[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|" + "[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
|
|
4415
|
-
kanji = kanji.replace(/u/g, "\\u");
|
|
4416
|
-
var byte = "(?:(?![A-Z0-9 $%*+\\-./:]|" + kanji + `)(?:.|[\r
|
|
4417
|
-
]))+`;
|
|
4418
|
-
exports.KANJI = new RegExp(kanji, "g");
|
|
4419
|
-
exports.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g");
|
|
4420
|
-
exports.BYTE = new RegExp(byte, "g");
|
|
4421
|
-
exports.NUMERIC = new RegExp(numeric, "g");
|
|
4422
|
-
exports.ALPHANUMERIC = new RegExp(alphanumeric, "g");
|
|
4423
|
-
var TEST_KANJI = new RegExp("^" + kanji + "$");
|
|
4424
|
-
var TEST_NUMERIC = new RegExp("^" + numeric + "$");
|
|
4425
|
-
var TEST_ALPHANUMERIC = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
|
|
4426
|
-
exports.testKanji = function testKanji(str) {
|
|
4427
|
-
return TEST_KANJI.test(str);
|
|
4428
|
-
};
|
|
4429
|
-
exports.testNumeric = function testNumeric(str) {
|
|
4430
|
-
return TEST_NUMERIC.test(str);
|
|
4431
|
-
};
|
|
4432
|
-
exports.testAlphanumeric = function testAlphanumeric(str) {
|
|
4433
|
-
return TEST_ALPHANUMERIC.test(str);
|
|
4434
|
-
};
|
|
4435
|
-
});
|
|
4436
|
-
|
|
4437
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js
|
|
4438
|
-
var require_mode = __commonJS((exports) => {
|
|
4439
|
-
var VersionCheck = require_version_check();
|
|
4440
|
-
var Regex = require_regex();
|
|
4441
|
-
exports.NUMERIC = {
|
|
4442
|
-
id: "Numeric",
|
|
4443
|
-
bit: 1 << 0,
|
|
4444
|
-
ccBits: [10, 12, 14]
|
|
4445
|
-
};
|
|
4446
|
-
exports.ALPHANUMERIC = {
|
|
4447
|
-
id: "Alphanumeric",
|
|
4448
|
-
bit: 1 << 1,
|
|
4449
|
-
ccBits: [9, 11, 13]
|
|
4450
|
-
};
|
|
4451
|
-
exports.BYTE = {
|
|
4452
|
-
id: "Byte",
|
|
4453
|
-
bit: 1 << 2,
|
|
4454
|
-
ccBits: [8, 16, 16]
|
|
4455
|
-
};
|
|
4456
|
-
exports.KANJI = {
|
|
4457
|
-
id: "Kanji",
|
|
4458
|
-
bit: 1 << 3,
|
|
4459
|
-
ccBits: [8, 10, 12]
|
|
4460
|
-
};
|
|
4461
|
-
exports.MIXED = {
|
|
4462
|
-
bit: -1
|
|
4463
|
-
};
|
|
4464
|
-
exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
|
|
4465
|
-
if (!mode.ccBits)
|
|
4466
|
-
throw new Error("Invalid mode: " + mode);
|
|
4467
|
-
if (!VersionCheck.isValid(version)) {
|
|
4468
|
-
throw new Error("Invalid version: " + version);
|
|
4469
|
-
}
|
|
4470
|
-
if (version >= 1 && version < 10)
|
|
4471
|
-
return mode.ccBits[0];
|
|
4472
|
-
else if (version < 27)
|
|
4473
|
-
return mode.ccBits[1];
|
|
4474
|
-
return mode.ccBits[2];
|
|
4475
|
-
};
|
|
4476
|
-
exports.getBestModeForData = function getBestModeForData(dataStr) {
|
|
4477
|
-
if (Regex.testNumeric(dataStr))
|
|
4478
|
-
return exports.NUMERIC;
|
|
4479
|
-
else if (Regex.testAlphanumeric(dataStr))
|
|
4480
|
-
return exports.ALPHANUMERIC;
|
|
4481
|
-
else if (Regex.testKanji(dataStr))
|
|
4482
|
-
return exports.KANJI;
|
|
4483
|
-
else
|
|
4484
|
-
return exports.BYTE;
|
|
4485
|
-
};
|
|
4486
|
-
exports.toString = function toString(mode) {
|
|
4487
|
-
if (mode && mode.id)
|
|
4488
|
-
return mode.id;
|
|
4489
|
-
throw new Error("Invalid mode");
|
|
4490
|
-
};
|
|
4491
|
-
exports.isValid = function isValid(mode) {
|
|
4492
|
-
return mode && mode.bit && mode.ccBits;
|
|
4493
|
-
};
|
|
4494
|
-
function fromString(string) {
|
|
4495
|
-
if (typeof string !== "string") {
|
|
4496
|
-
throw new Error("Param is not a string");
|
|
4497
|
-
}
|
|
4498
|
-
const lcStr = string.toLowerCase();
|
|
4499
|
-
switch (lcStr) {
|
|
4500
|
-
case "numeric":
|
|
4501
|
-
return exports.NUMERIC;
|
|
4502
|
-
case "alphanumeric":
|
|
4503
|
-
return exports.ALPHANUMERIC;
|
|
4504
|
-
case "kanji":
|
|
4505
|
-
return exports.KANJI;
|
|
4506
|
-
case "byte":
|
|
4507
|
-
return exports.BYTE;
|
|
4508
|
-
default:
|
|
4509
|
-
throw new Error("Unknown mode: " + string);
|
|
4510
|
-
}
|
|
4511
|
-
}
|
|
4512
|
-
exports.from = function from(value, defaultValue) {
|
|
4513
|
-
if (exports.isValid(value)) {
|
|
4514
|
-
return value;
|
|
4515
|
-
}
|
|
4516
|
-
try {
|
|
4517
|
-
return fromString(value);
|
|
4518
|
-
} catch (e) {
|
|
4519
|
-
return defaultValue;
|
|
4520
|
-
}
|
|
4521
|
-
};
|
|
4522
|
-
});
|
|
4523
|
-
|
|
4524
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js
|
|
4525
|
-
var require_version = __commonJS((exports) => {
|
|
4526
|
-
var Utils = require_utils2();
|
|
4527
|
-
var ECCode = require_error_correction_code();
|
|
4528
|
-
var ECLevel = require_error_correction_level();
|
|
4529
|
-
var Mode = require_mode();
|
|
4530
|
-
var VersionCheck = require_version_check();
|
|
4531
|
-
var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
|
|
4532
|
-
var G18_BCH = Utils.getBCHDigit(G18);
|
|
4533
|
-
function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
|
|
4534
|
-
for (let currentVersion = 1;currentVersion <= 40; currentVersion++) {
|
|
4535
|
-
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
|
|
4536
|
-
return currentVersion;
|
|
4537
|
-
}
|
|
4538
|
-
}
|
|
4539
|
-
return;
|
|
4540
|
-
}
|
|
4541
|
-
function getReservedBitsCount(mode, version) {
|
|
4542
|
-
return Mode.getCharCountIndicator(mode, version) + 4;
|
|
4543
|
-
}
|
|
4544
|
-
function getTotalBitsFromDataArray(segments, version) {
|
|
4545
|
-
let totalBits = 0;
|
|
4546
|
-
segments.forEach(function(data) {
|
|
4547
|
-
const reservedBits = getReservedBitsCount(data.mode, version);
|
|
4548
|
-
totalBits += reservedBits + data.getBitsLength();
|
|
4549
|
-
});
|
|
4550
|
-
return totalBits;
|
|
4551
|
-
}
|
|
4552
|
-
function getBestVersionForMixedData(segments, errorCorrectionLevel) {
|
|
4553
|
-
for (let currentVersion = 1;currentVersion <= 40; currentVersion++) {
|
|
4554
|
-
const length = getTotalBitsFromDataArray(segments, currentVersion);
|
|
4555
|
-
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
|
|
4556
|
-
return currentVersion;
|
|
4557
|
-
}
|
|
4558
|
-
}
|
|
4559
|
-
return;
|
|
4560
|
-
}
|
|
4561
|
-
exports.from = function from(value, defaultValue) {
|
|
4562
|
-
if (VersionCheck.isValid(value)) {
|
|
4563
|
-
return parseInt(value, 10);
|
|
4564
|
-
}
|
|
4565
|
-
return defaultValue;
|
|
4566
|
-
};
|
|
4567
|
-
exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode) {
|
|
4568
|
-
if (!VersionCheck.isValid(version)) {
|
|
4569
|
-
throw new Error("Invalid QR Code version");
|
|
4570
|
-
}
|
|
4571
|
-
if (typeof mode === "undefined")
|
|
4572
|
-
mode = Mode.BYTE;
|
|
4573
|
-
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
4574
|
-
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
4575
|
-
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
4576
|
-
if (mode === Mode.MIXED)
|
|
4577
|
-
return dataTotalCodewordsBits;
|
|
4578
|
-
const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
|
|
4579
|
-
switch (mode) {
|
|
4580
|
-
case Mode.NUMERIC:
|
|
4581
|
-
return Math.floor(usableBits / 10 * 3);
|
|
4582
|
-
case Mode.ALPHANUMERIC:
|
|
4583
|
-
return Math.floor(usableBits / 11 * 2);
|
|
4584
|
-
case Mode.KANJI:
|
|
4585
|
-
return Math.floor(usableBits / 13);
|
|
4586
|
-
case Mode.BYTE:
|
|
4587
|
-
default:
|
|
4588
|
-
return Math.floor(usableBits / 8);
|
|
4589
|
-
}
|
|
4590
|
-
};
|
|
4591
|
-
exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel) {
|
|
4592
|
-
let seg;
|
|
4593
|
-
const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
|
|
4594
|
-
if (Array.isArray(data)) {
|
|
4595
|
-
if (data.length > 1) {
|
|
4596
|
-
return getBestVersionForMixedData(data, ecl);
|
|
4597
|
-
}
|
|
4598
|
-
if (data.length === 0) {
|
|
4599
|
-
return 1;
|
|
4600
|
-
}
|
|
4601
|
-
seg = data[0];
|
|
4602
|
-
} else {
|
|
4603
|
-
seg = data;
|
|
4604
|
-
}
|
|
4605
|
-
return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
|
|
4606
|
-
};
|
|
4607
|
-
exports.getEncodedBits = function getEncodedBits(version) {
|
|
4608
|
-
if (!VersionCheck.isValid(version) || version < 7) {
|
|
4609
|
-
throw new Error("Invalid QR Code version");
|
|
4610
|
-
}
|
|
4611
|
-
let d = version << 12;
|
|
4612
|
-
while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
|
|
4613
|
-
d ^= G18 << Utils.getBCHDigit(d) - G18_BCH;
|
|
4614
|
-
}
|
|
4615
|
-
return version << 12 | d;
|
|
4616
|
-
};
|
|
4617
|
-
});
|
|
4618
|
-
|
|
4619
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js
|
|
4620
|
-
var require_format_info = __commonJS((exports) => {
|
|
4621
|
-
var Utils = require_utils2();
|
|
4622
|
-
var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
|
|
4623
|
-
var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
|
|
4624
|
-
var G15_BCH = Utils.getBCHDigit(G15);
|
|
4625
|
-
exports.getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
|
|
4626
|
-
const data = errorCorrectionLevel.bit << 3 | mask;
|
|
4627
|
-
let d = data << 10;
|
|
4628
|
-
while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
|
|
4629
|
-
d ^= G15 << Utils.getBCHDigit(d) - G15_BCH;
|
|
4630
|
-
}
|
|
4631
|
-
return (data << 10 | d) ^ G15_MASK;
|
|
4632
|
-
};
|
|
4633
|
-
});
|
|
4634
|
-
|
|
4635
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js
|
|
4636
|
-
var require_numeric_data = __commonJS((exports, module) => {
|
|
4637
|
-
var Mode = require_mode();
|
|
4638
|
-
function NumericData(data) {
|
|
4639
|
-
this.mode = Mode.NUMERIC;
|
|
4640
|
-
this.data = data.toString();
|
|
4641
|
-
}
|
|
4642
|
-
NumericData.getBitsLength = function getBitsLength(length) {
|
|
4643
|
-
return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
|
|
4644
|
-
};
|
|
4645
|
-
NumericData.prototype.getLength = function getLength() {
|
|
4646
|
-
return this.data.length;
|
|
4647
|
-
};
|
|
4648
|
-
NumericData.prototype.getBitsLength = function getBitsLength() {
|
|
4649
|
-
return NumericData.getBitsLength(this.data.length);
|
|
4650
|
-
};
|
|
4651
|
-
NumericData.prototype.write = function write(bitBuffer) {
|
|
4652
|
-
let i2, group, value;
|
|
4653
|
-
for (i2 = 0;i2 + 3 <= this.data.length; i2 += 3) {
|
|
4654
|
-
group = this.data.substr(i2, 3);
|
|
4655
|
-
value = parseInt(group, 10);
|
|
4656
|
-
bitBuffer.put(value, 10);
|
|
4657
|
-
}
|
|
4658
|
-
const remainingNum = this.data.length - i2;
|
|
4659
|
-
if (remainingNum > 0) {
|
|
4660
|
-
group = this.data.substr(i2);
|
|
4661
|
-
value = parseInt(group, 10);
|
|
4662
|
-
bitBuffer.put(value, remainingNum * 3 + 1);
|
|
4663
|
-
}
|
|
4664
|
-
};
|
|
4665
|
-
module.exports = NumericData;
|
|
4666
|
-
});
|
|
4667
|
-
|
|
4668
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js
|
|
4669
|
-
var require_alphanumeric_data = __commonJS((exports, module) => {
|
|
4670
|
-
var Mode = require_mode();
|
|
4671
|
-
var ALPHA_NUM_CHARS = [
|
|
4672
|
-
"0",
|
|
4673
|
-
"1",
|
|
4674
|
-
"2",
|
|
4675
|
-
"3",
|
|
4676
|
-
"4",
|
|
4677
|
-
"5",
|
|
4678
|
-
"6",
|
|
4679
|
-
"7",
|
|
4680
|
-
"8",
|
|
4681
|
-
"9",
|
|
4682
|
-
"A",
|
|
4683
|
-
"B",
|
|
4684
|
-
"C",
|
|
4685
|
-
"D",
|
|
4686
|
-
"E",
|
|
4687
|
-
"F",
|
|
4688
|
-
"G",
|
|
4689
|
-
"H",
|
|
4690
|
-
"I",
|
|
4691
|
-
"J",
|
|
4692
|
-
"K",
|
|
4693
|
-
"L",
|
|
4694
|
-
"M",
|
|
4695
|
-
"N",
|
|
4696
|
-
"O",
|
|
4697
|
-
"P",
|
|
4698
|
-
"Q",
|
|
4699
|
-
"R",
|
|
4700
|
-
"S",
|
|
4701
|
-
"T",
|
|
4702
|
-
"U",
|
|
4703
|
-
"V",
|
|
4704
|
-
"W",
|
|
4705
|
-
"X",
|
|
4706
|
-
"Y",
|
|
4707
|
-
"Z",
|
|
4708
|
-
" ",
|
|
4709
|
-
"$",
|
|
4710
|
-
"%",
|
|
4711
|
-
"*",
|
|
4712
|
-
"+",
|
|
4713
|
-
"-",
|
|
4714
|
-
".",
|
|
4715
|
-
"/",
|
|
4716
|
-
":"
|
|
4717
|
-
];
|
|
4718
|
-
function AlphanumericData(data) {
|
|
4719
|
-
this.mode = Mode.ALPHANUMERIC;
|
|
4720
|
-
this.data = data;
|
|
4721
|
-
}
|
|
4722
|
-
AlphanumericData.getBitsLength = function getBitsLength(length) {
|
|
4723
|
-
return 11 * Math.floor(length / 2) + 6 * (length % 2);
|
|
4724
|
-
};
|
|
4725
|
-
AlphanumericData.prototype.getLength = function getLength() {
|
|
4726
|
-
return this.data.length;
|
|
4727
|
-
};
|
|
4728
|
-
AlphanumericData.prototype.getBitsLength = function getBitsLength() {
|
|
4729
|
-
return AlphanumericData.getBitsLength(this.data.length);
|
|
4730
|
-
};
|
|
4731
|
-
AlphanumericData.prototype.write = function write(bitBuffer) {
|
|
4732
|
-
let i2;
|
|
4733
|
-
for (i2 = 0;i2 + 2 <= this.data.length; i2 += 2) {
|
|
4734
|
-
let value = ALPHA_NUM_CHARS.indexOf(this.data[i2]) * 45;
|
|
4735
|
-
value += ALPHA_NUM_CHARS.indexOf(this.data[i2 + 1]);
|
|
4736
|
-
bitBuffer.put(value, 11);
|
|
4737
|
-
}
|
|
4738
|
-
if (this.data.length % 2) {
|
|
4739
|
-
bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i2]), 6);
|
|
4740
|
-
}
|
|
4741
|
-
};
|
|
4742
|
-
module.exports = AlphanumericData;
|
|
4743
|
-
});
|
|
4744
|
-
|
|
4745
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js
|
|
4746
|
-
var require_byte_data = __commonJS((exports, module) => {
|
|
4747
|
-
var Mode = require_mode();
|
|
4748
|
-
function ByteData(data) {
|
|
4749
|
-
this.mode = Mode.BYTE;
|
|
4750
|
-
if (typeof data === "string") {
|
|
4751
|
-
this.data = new TextEncoder().encode(data);
|
|
4752
|
-
} else {
|
|
4753
|
-
this.data = new Uint8Array(data);
|
|
4754
|
-
}
|
|
4755
|
-
}
|
|
4756
|
-
ByteData.getBitsLength = function getBitsLength(length) {
|
|
4757
|
-
return length * 8;
|
|
4758
|
-
};
|
|
4759
|
-
ByteData.prototype.getLength = function getLength() {
|
|
4760
|
-
return this.data.length;
|
|
4761
|
-
};
|
|
4762
|
-
ByteData.prototype.getBitsLength = function getBitsLength() {
|
|
4763
|
-
return ByteData.getBitsLength(this.data.length);
|
|
4764
|
-
};
|
|
4765
|
-
ByteData.prototype.write = function(bitBuffer) {
|
|
4766
|
-
for (let i2 = 0, l = this.data.length;i2 < l; i2++) {
|
|
4767
|
-
bitBuffer.put(this.data[i2], 8);
|
|
4768
|
-
}
|
|
4769
|
-
};
|
|
4770
|
-
module.exports = ByteData;
|
|
4771
|
-
});
|
|
4772
|
-
|
|
4773
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js
|
|
4774
|
-
var require_kanji_data = __commonJS((exports, module) => {
|
|
4775
|
-
var Mode = require_mode();
|
|
4776
|
-
var Utils = require_utils2();
|
|
4777
|
-
function KanjiData(data) {
|
|
4778
|
-
this.mode = Mode.KANJI;
|
|
4779
|
-
this.data = data;
|
|
4780
|
-
}
|
|
4781
|
-
KanjiData.getBitsLength = function getBitsLength(length) {
|
|
4782
|
-
return length * 13;
|
|
4783
|
-
};
|
|
4784
|
-
KanjiData.prototype.getLength = function getLength() {
|
|
4785
|
-
return this.data.length;
|
|
4786
|
-
};
|
|
4787
|
-
KanjiData.prototype.getBitsLength = function getBitsLength() {
|
|
4788
|
-
return KanjiData.getBitsLength(this.data.length);
|
|
4789
|
-
};
|
|
4790
|
-
KanjiData.prototype.write = function(bitBuffer) {
|
|
4791
|
-
let i2;
|
|
4792
|
-
for (i2 = 0;i2 < this.data.length; i2++) {
|
|
4793
|
-
let value = Utils.toSJIS(this.data[i2]);
|
|
4794
|
-
if (value >= 33088 && value <= 40956) {
|
|
4795
|
-
value -= 33088;
|
|
4796
|
-
} else if (value >= 57408 && value <= 60351) {
|
|
4797
|
-
value -= 49472;
|
|
4798
|
-
} else {
|
|
4799
|
-
throw new Error("Invalid SJIS character: " + this.data[i2] + `
|
|
4800
|
-
` + "Make sure your charset is UTF-8");
|
|
4801
|
-
}
|
|
4802
|
-
value = (value >>> 8 & 255) * 192 + (value & 255);
|
|
4803
|
-
bitBuffer.put(value, 13);
|
|
4804
|
-
}
|
|
4805
|
-
};
|
|
4806
|
-
module.exports = KanjiData;
|
|
4807
|
-
});
|
|
4808
|
-
|
|
4809
|
-
// ../../node_modules/.bun/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js
|
|
4810
|
-
var require_dijkstra = __commonJS((exports, module) => {
|
|
4811
|
-
var dijkstra = {
|
|
4812
|
-
single_source_shortest_paths: function(graph, s, d) {
|
|
4813
|
-
var predecessors = {};
|
|
4814
|
-
var costs = {};
|
|
4815
|
-
costs[s] = 0;
|
|
4816
|
-
var open2 = dijkstra.PriorityQueue.make();
|
|
4817
|
-
open2.push(s, 0);
|
|
4818
|
-
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;
|
|
4819
|
-
while (!open2.empty()) {
|
|
4820
|
-
closest = open2.pop();
|
|
4821
|
-
u = closest.value;
|
|
4822
|
-
cost_of_s_to_u = closest.cost;
|
|
4823
|
-
adjacent_nodes = graph[u] || {};
|
|
4824
|
-
for (v in adjacent_nodes) {
|
|
4825
|
-
if (adjacent_nodes.hasOwnProperty(v)) {
|
|
4826
|
-
cost_of_e = adjacent_nodes[v];
|
|
4827
|
-
cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
|
|
4828
|
-
cost_of_s_to_v = costs[v];
|
|
4829
|
-
first_visit = typeof costs[v] === "undefined";
|
|
4830
|
-
if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
|
|
4831
|
-
costs[v] = cost_of_s_to_u_plus_cost_of_e;
|
|
4832
|
-
open2.push(v, cost_of_s_to_u_plus_cost_of_e);
|
|
4833
|
-
predecessors[v] = u;
|
|
4834
|
-
}
|
|
4835
|
-
}
|
|
4836
|
-
}
|
|
4837
|
-
}
|
|
4838
|
-
if (typeof d !== "undefined" && typeof costs[d] === "undefined") {
|
|
4839
|
-
var msg = ["Could not find a path from ", s, " to ", d, "."].join("");
|
|
4840
|
-
throw new Error(msg);
|
|
4841
|
-
}
|
|
4842
|
-
return predecessors;
|
|
4843
|
-
},
|
|
4844
|
-
extract_shortest_path_from_predecessor_list: function(predecessors, d) {
|
|
4845
|
-
var nodes = [];
|
|
4846
|
-
var u = d;
|
|
4847
|
-
var predecessor;
|
|
4848
|
-
while (u) {
|
|
4849
|
-
nodes.push(u);
|
|
4850
|
-
predecessor = predecessors[u];
|
|
4851
|
-
u = predecessors[u];
|
|
4852
|
-
}
|
|
4853
|
-
nodes.reverse();
|
|
4854
|
-
return nodes;
|
|
4855
|
-
},
|
|
4856
|
-
find_path: function(graph, s, d) {
|
|
4857
|
-
var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
|
|
4858
|
-
return dijkstra.extract_shortest_path_from_predecessor_list(predecessors, d);
|
|
4859
|
-
},
|
|
4860
|
-
PriorityQueue: {
|
|
4861
|
-
make: function(opts) {
|
|
4862
|
-
var T = dijkstra.PriorityQueue, t = {}, key;
|
|
4863
|
-
opts = opts || {};
|
|
4864
|
-
for (key in T) {
|
|
4865
|
-
if (T.hasOwnProperty(key)) {
|
|
4866
|
-
t[key] = T[key];
|
|
4867
|
-
}
|
|
4868
|
-
}
|
|
4869
|
-
t.queue = [];
|
|
4870
|
-
t.sorter = opts.sorter || T.default_sorter;
|
|
4871
|
-
return t;
|
|
4872
|
-
},
|
|
4873
|
-
default_sorter: function(a, b) {
|
|
4874
|
-
return a.cost - b.cost;
|
|
4875
|
-
},
|
|
4876
|
-
push: function(value, cost) {
|
|
4877
|
-
var item = { value, cost };
|
|
4878
|
-
this.queue.push(item);
|
|
4879
|
-
this.queue.sort(this.sorter);
|
|
4880
|
-
},
|
|
4881
|
-
pop: function() {
|
|
4882
|
-
return this.queue.shift();
|
|
4883
|
-
},
|
|
4884
|
-
empty: function() {
|
|
4885
|
-
return this.queue.length === 0;
|
|
4886
|
-
}
|
|
4887
|
-
}
|
|
4888
|
-
};
|
|
4889
|
-
if (typeof module !== "undefined") {
|
|
4890
|
-
module.exports = dijkstra;
|
|
4891
|
-
}
|
|
4892
|
-
});
|
|
4893
|
-
|
|
4894
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js
|
|
4895
|
-
var require_segments = __commonJS((exports) => {
|
|
4896
|
-
var Mode = require_mode();
|
|
4897
|
-
var NumericData = require_numeric_data();
|
|
4898
|
-
var AlphanumericData = require_alphanumeric_data();
|
|
4899
|
-
var ByteData = require_byte_data();
|
|
4900
|
-
var KanjiData = require_kanji_data();
|
|
4901
|
-
var Regex = require_regex();
|
|
4902
|
-
var Utils = require_utils2();
|
|
4903
|
-
var dijkstra = require_dijkstra();
|
|
4904
|
-
function getStringByteLength(str) {
|
|
4905
|
-
return unescape(encodeURIComponent(str)).length;
|
|
4906
|
-
}
|
|
4907
|
-
function getSegments(regex, mode, str) {
|
|
4908
|
-
const segments = [];
|
|
4909
|
-
let result;
|
|
4910
|
-
while ((result = regex.exec(str)) !== null) {
|
|
4911
|
-
segments.push({
|
|
4912
|
-
data: result[0],
|
|
4913
|
-
index: result.index,
|
|
4914
|
-
mode,
|
|
4915
|
-
length: result[0].length
|
|
4916
|
-
});
|
|
4917
|
-
}
|
|
4918
|
-
return segments;
|
|
4919
|
-
}
|
|
4920
|
-
function getSegmentsFromString(dataStr) {
|
|
4921
|
-
const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
|
|
4922
|
-
const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
|
|
4923
|
-
let byteSegs;
|
|
4924
|
-
let kanjiSegs;
|
|
4925
|
-
if (Utils.isKanjiModeEnabled()) {
|
|
4926
|
-
byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
|
|
4927
|
-
kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
|
|
4928
|
-
} else {
|
|
4929
|
-
byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
|
|
4930
|
-
kanjiSegs = [];
|
|
4931
|
-
}
|
|
4932
|
-
const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
|
|
4933
|
-
return segs.sort(function(s1, s2) {
|
|
4934
|
-
return s1.index - s2.index;
|
|
4935
|
-
}).map(function(obj) {
|
|
4936
|
-
return {
|
|
4937
|
-
data: obj.data,
|
|
4938
|
-
mode: obj.mode,
|
|
4939
|
-
length: obj.length
|
|
4940
|
-
};
|
|
4941
|
-
});
|
|
4942
|
-
}
|
|
4943
|
-
function getSegmentBitsLength(length, mode) {
|
|
4944
|
-
switch (mode) {
|
|
4945
|
-
case Mode.NUMERIC:
|
|
4946
|
-
return NumericData.getBitsLength(length);
|
|
4947
|
-
case Mode.ALPHANUMERIC:
|
|
4948
|
-
return AlphanumericData.getBitsLength(length);
|
|
4949
|
-
case Mode.KANJI:
|
|
4950
|
-
return KanjiData.getBitsLength(length);
|
|
4951
|
-
case Mode.BYTE:
|
|
4952
|
-
return ByteData.getBitsLength(length);
|
|
4953
|
-
}
|
|
4954
|
-
}
|
|
4955
|
-
function mergeSegments(segs) {
|
|
4956
|
-
return segs.reduce(function(acc, curr) {
|
|
4957
|
-
const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
|
|
4958
|
-
if (prevSeg && prevSeg.mode === curr.mode) {
|
|
4959
|
-
acc[acc.length - 1].data += curr.data;
|
|
4960
|
-
return acc;
|
|
4961
|
-
}
|
|
4962
|
-
acc.push(curr);
|
|
4963
|
-
return acc;
|
|
4964
|
-
}, []);
|
|
4965
|
-
}
|
|
4966
|
-
function buildNodes(segs) {
|
|
4967
|
-
const nodes = [];
|
|
4968
|
-
for (let i2 = 0;i2 < segs.length; i2++) {
|
|
4969
|
-
const seg = segs[i2];
|
|
4970
|
-
switch (seg.mode) {
|
|
4971
|
-
case Mode.NUMERIC:
|
|
4972
|
-
nodes.push([
|
|
4973
|
-
seg,
|
|
4974
|
-
{ data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
|
|
4975
|
-
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
4976
|
-
]);
|
|
4977
|
-
break;
|
|
4978
|
-
case Mode.ALPHANUMERIC:
|
|
4979
|
-
nodes.push([
|
|
4980
|
-
seg,
|
|
4981
|
-
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
4982
|
-
]);
|
|
4983
|
-
break;
|
|
4984
|
-
case Mode.KANJI:
|
|
4985
|
-
nodes.push([
|
|
4986
|
-
seg,
|
|
4987
|
-
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
4988
|
-
]);
|
|
4989
|
-
break;
|
|
4990
|
-
case Mode.BYTE:
|
|
4991
|
-
nodes.push([
|
|
4992
|
-
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
4993
|
-
]);
|
|
4994
|
-
}
|
|
4995
|
-
}
|
|
4996
|
-
return nodes;
|
|
4997
|
-
}
|
|
4998
|
-
function buildGraph(nodes, version) {
|
|
4999
|
-
const table = {};
|
|
5000
|
-
const graph = { start: {} };
|
|
5001
|
-
let prevNodeIds = ["start"];
|
|
5002
|
-
for (let i2 = 0;i2 < nodes.length; i2++) {
|
|
5003
|
-
const nodeGroup = nodes[i2];
|
|
5004
|
-
const currentNodeIds = [];
|
|
5005
|
-
for (let j = 0;j < nodeGroup.length; j++) {
|
|
5006
|
-
const node = nodeGroup[j];
|
|
5007
|
-
const key = "" + i2 + j;
|
|
5008
|
-
currentNodeIds.push(key);
|
|
5009
|
-
table[key] = { node, lastCount: 0 };
|
|
5010
|
-
graph[key] = {};
|
|
5011
|
-
for (let n = 0;n < prevNodeIds.length; n++) {
|
|
5012
|
-
const prevNodeId = prevNodeIds[n];
|
|
5013
|
-
if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
|
|
5014
|
-
graph[prevNodeId][key] = getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
|
|
5015
|
-
table[prevNodeId].lastCount += node.length;
|
|
5016
|
-
} else {
|
|
5017
|
-
if (table[prevNodeId])
|
|
5018
|
-
table[prevNodeId].lastCount = node.length;
|
|
5019
|
-
graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + Mode.getCharCountIndicator(node.mode, version);
|
|
5020
|
-
}
|
|
5021
|
-
}
|
|
5022
|
-
}
|
|
5023
|
-
prevNodeIds = currentNodeIds;
|
|
5024
|
-
}
|
|
5025
|
-
for (let n = 0;n < prevNodeIds.length; n++) {
|
|
5026
|
-
graph[prevNodeIds[n]].end = 0;
|
|
5027
|
-
}
|
|
5028
|
-
return { map: graph, table };
|
|
5029
|
-
}
|
|
5030
|
-
function buildSingleSegment(data, modesHint) {
|
|
5031
|
-
let mode;
|
|
5032
|
-
const bestMode = Mode.getBestModeForData(data);
|
|
5033
|
-
mode = Mode.from(modesHint, bestMode);
|
|
5034
|
-
if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
|
|
5035
|
-
throw new Error('"' + data + '"' + " cannot be encoded with mode " + Mode.toString(mode) + `.
|
|
5036
|
-
Suggested mode is: ` + Mode.toString(bestMode));
|
|
5037
|
-
}
|
|
5038
|
-
if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
|
|
5039
|
-
mode = Mode.BYTE;
|
|
5040
|
-
}
|
|
5041
|
-
switch (mode) {
|
|
5042
|
-
case Mode.NUMERIC:
|
|
5043
|
-
return new NumericData(data);
|
|
5044
|
-
case Mode.ALPHANUMERIC:
|
|
5045
|
-
return new AlphanumericData(data);
|
|
5046
|
-
case Mode.KANJI:
|
|
5047
|
-
return new KanjiData(data);
|
|
5048
|
-
case Mode.BYTE:
|
|
5049
|
-
return new ByteData(data);
|
|
5050
|
-
}
|
|
5051
|
-
}
|
|
5052
|
-
exports.fromArray = function fromArray(array) {
|
|
5053
|
-
return array.reduce(function(acc, seg) {
|
|
5054
|
-
if (typeof seg === "string") {
|
|
5055
|
-
acc.push(buildSingleSegment(seg, null));
|
|
5056
|
-
} else if (seg.data) {
|
|
5057
|
-
acc.push(buildSingleSegment(seg.data, seg.mode));
|
|
5058
|
-
}
|
|
5059
|
-
return acc;
|
|
5060
|
-
}, []);
|
|
5061
|
-
};
|
|
5062
|
-
exports.fromString = function fromString(data, version) {
|
|
5063
|
-
const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
|
|
5064
|
-
const nodes = buildNodes(segs);
|
|
5065
|
-
const graph = buildGraph(nodes, version);
|
|
5066
|
-
const path3 = dijkstra.find_path(graph.map, "start", "end");
|
|
5067
|
-
const optimizedSegs = [];
|
|
5068
|
-
for (let i2 = 1;i2 < path3.length - 1; i2++) {
|
|
5069
|
-
optimizedSegs.push(graph.table[path3[i2]].node);
|
|
5070
|
-
}
|
|
5071
|
-
return exports.fromArray(mergeSegments(optimizedSegs));
|
|
5072
|
-
};
|
|
5073
|
-
exports.rawSplit = function rawSplit(data) {
|
|
5074
|
-
return exports.fromArray(getSegmentsFromString(data, Utils.isKanjiModeEnabled()));
|
|
5075
|
-
};
|
|
5076
|
-
});
|
|
5077
|
-
|
|
5078
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js
|
|
5079
|
-
var require_qrcode = __commonJS((exports) => {
|
|
5080
|
-
var Utils = require_utils2();
|
|
5081
|
-
var ECLevel = require_error_correction_level();
|
|
5082
|
-
var BitBuffer = require_bit_buffer();
|
|
5083
|
-
var BitMatrix = require_bit_matrix();
|
|
5084
|
-
var AlignmentPattern = require_alignment_pattern();
|
|
5085
|
-
var FinderPattern = require_finder_pattern();
|
|
5086
|
-
var MaskPattern = require_mask_pattern();
|
|
5087
|
-
var ECCode = require_error_correction_code();
|
|
5088
|
-
var ReedSolomonEncoder = require_reed_solomon_encoder();
|
|
5089
|
-
var Version = require_version();
|
|
5090
|
-
var FormatInfo = require_format_info();
|
|
5091
|
-
var Mode = require_mode();
|
|
5092
|
-
var Segments = require_segments();
|
|
5093
|
-
function setupFinderPattern(matrix, version) {
|
|
5094
|
-
const size = matrix.size;
|
|
5095
|
-
const pos = FinderPattern.getPositions(version);
|
|
5096
|
-
for (let i2 = 0;i2 < pos.length; i2++) {
|
|
5097
|
-
const row = pos[i2][0];
|
|
5098
|
-
const col = pos[i2][1];
|
|
5099
|
-
for (let r = -1;r <= 7; r++) {
|
|
5100
|
-
if (row + r <= -1 || size <= row + r)
|
|
5101
|
-
continue;
|
|
5102
|
-
for (let c = -1;c <= 7; c++) {
|
|
5103
|
-
if (col + c <= -1 || size <= col + c)
|
|
5104
|
-
continue;
|
|
5105
|
-
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) {
|
|
5106
|
-
matrix.set(row + r, col + c, true, true);
|
|
5107
|
-
} else {
|
|
5108
|
-
matrix.set(row + r, col + c, false, true);
|
|
5109
|
-
}
|
|
5110
|
-
}
|
|
5111
|
-
}
|
|
5112
|
-
}
|
|
5113
|
-
}
|
|
5114
|
-
function setupTimingPattern(matrix) {
|
|
5115
|
-
const size = matrix.size;
|
|
5116
|
-
for (let r = 8;r < size - 8; r++) {
|
|
5117
|
-
const value = r % 2 === 0;
|
|
5118
|
-
matrix.set(r, 6, value, true);
|
|
5119
|
-
matrix.set(6, r, value, true);
|
|
5120
|
-
}
|
|
5121
|
-
}
|
|
5122
|
-
function setupAlignmentPattern(matrix, version) {
|
|
5123
|
-
const pos = AlignmentPattern.getPositions(version);
|
|
5124
|
-
for (let i2 = 0;i2 < pos.length; i2++) {
|
|
5125
|
-
const row = pos[i2][0];
|
|
5126
|
-
const col = pos[i2][1];
|
|
5127
|
-
for (let r = -2;r <= 2; r++) {
|
|
5128
|
-
for (let c = -2;c <= 2; c++) {
|
|
5129
|
-
if (r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0) {
|
|
5130
|
-
matrix.set(row + r, col + c, true, true);
|
|
5131
|
-
} else {
|
|
5132
|
-
matrix.set(row + r, col + c, false, true);
|
|
5133
|
-
}
|
|
5134
|
-
}
|
|
5135
|
-
}
|
|
5136
|
-
}
|
|
5137
|
-
}
|
|
5138
|
-
function setupVersionInfo(matrix, version) {
|
|
5139
|
-
const size = matrix.size;
|
|
5140
|
-
const bits = Version.getEncodedBits(version);
|
|
5141
|
-
let row, col, mod;
|
|
5142
|
-
for (let i2 = 0;i2 < 18; i2++) {
|
|
5143
|
-
row = Math.floor(i2 / 3);
|
|
5144
|
-
col = i2 % 3 + size - 8 - 3;
|
|
5145
|
-
mod = (bits >> i2 & 1) === 1;
|
|
5146
|
-
matrix.set(row, col, mod, true);
|
|
5147
|
-
matrix.set(col, row, mod, true);
|
|
5148
|
-
}
|
|
5149
|
-
}
|
|
5150
|
-
function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
|
|
5151
|
-
const size = matrix.size;
|
|
5152
|
-
const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
|
|
5153
|
-
let i2, mod;
|
|
5154
|
-
for (i2 = 0;i2 < 15; i2++) {
|
|
5155
|
-
mod = (bits >> i2 & 1) === 1;
|
|
5156
|
-
if (i2 < 6) {
|
|
5157
|
-
matrix.set(i2, 8, mod, true);
|
|
5158
|
-
} else if (i2 < 8) {
|
|
5159
|
-
matrix.set(i2 + 1, 8, mod, true);
|
|
5160
|
-
} else {
|
|
5161
|
-
matrix.set(size - 15 + i2, 8, mod, true);
|
|
5162
|
-
}
|
|
5163
|
-
if (i2 < 8) {
|
|
5164
|
-
matrix.set(8, size - i2 - 1, mod, true);
|
|
5165
|
-
} else if (i2 < 9) {
|
|
5166
|
-
matrix.set(8, 15 - i2 - 1 + 1, mod, true);
|
|
5167
|
-
} else {
|
|
5168
|
-
matrix.set(8, 15 - i2 - 1, mod, true);
|
|
5169
|
-
}
|
|
5170
|
-
}
|
|
5171
|
-
matrix.set(size - 8, 8, 1, true);
|
|
5172
|
-
}
|
|
5173
|
-
function setupData(matrix, data) {
|
|
5174
|
-
const size = matrix.size;
|
|
5175
|
-
let inc = -1;
|
|
5176
|
-
let row = size - 1;
|
|
5177
|
-
let bitIndex = 7;
|
|
5178
|
-
let byteIndex = 0;
|
|
5179
|
-
for (let col = size - 1;col > 0; col -= 2) {
|
|
5180
|
-
if (col === 6)
|
|
5181
|
-
col--;
|
|
5182
|
-
while (true) {
|
|
5183
|
-
for (let c = 0;c < 2; c++) {
|
|
5184
|
-
if (!matrix.isReserved(row, col - c)) {
|
|
5185
|
-
let dark = false;
|
|
5186
|
-
if (byteIndex < data.length) {
|
|
5187
|
-
dark = (data[byteIndex] >>> bitIndex & 1) === 1;
|
|
5188
|
-
}
|
|
5189
|
-
matrix.set(row, col - c, dark);
|
|
5190
|
-
bitIndex--;
|
|
5191
|
-
if (bitIndex === -1) {
|
|
5192
|
-
byteIndex++;
|
|
5193
|
-
bitIndex = 7;
|
|
5194
|
-
}
|
|
5195
|
-
}
|
|
5196
|
-
}
|
|
5197
|
-
row += inc;
|
|
5198
|
-
if (row < 0 || size <= row) {
|
|
5199
|
-
row -= inc;
|
|
5200
|
-
inc = -inc;
|
|
5201
|
-
break;
|
|
5202
|
-
}
|
|
5203
|
-
}
|
|
5204
|
-
}
|
|
5205
|
-
}
|
|
5206
|
-
function createData(version, errorCorrectionLevel, segments) {
|
|
5207
|
-
const buffer = new BitBuffer;
|
|
5208
|
-
segments.forEach(function(data) {
|
|
5209
|
-
buffer.put(data.mode.bit, 4);
|
|
5210
|
-
buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
|
|
5211
|
-
data.write(buffer);
|
|
5212
|
-
});
|
|
5213
|
-
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
5214
|
-
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
5215
|
-
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
5216
|
-
if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
|
|
5217
|
-
buffer.put(0, 4);
|
|
5218
|
-
}
|
|
5219
|
-
while (buffer.getLengthInBits() % 8 !== 0) {
|
|
5220
|
-
buffer.putBit(0);
|
|
5221
|
-
}
|
|
5222
|
-
const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
|
|
5223
|
-
for (let i2 = 0;i2 < remainingByte; i2++) {
|
|
5224
|
-
buffer.put(i2 % 2 ? 17 : 236, 8);
|
|
5225
|
-
}
|
|
5226
|
-
return createCodewords(buffer, version, errorCorrectionLevel);
|
|
5227
|
-
}
|
|
5228
|
-
function createCodewords(bitBuffer, version, errorCorrectionLevel) {
|
|
5229
|
-
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
5230
|
-
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
5231
|
-
const dataTotalCodewords = totalCodewords - ecTotalCodewords;
|
|
5232
|
-
const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
|
|
5233
|
-
const blocksInGroup2 = totalCodewords % ecTotalBlocks;
|
|
5234
|
-
const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
|
|
5235
|
-
const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
|
|
5236
|
-
const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
|
|
5237
|
-
const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
|
|
5238
|
-
const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
|
|
5239
|
-
const rs = new ReedSolomonEncoder(ecCount);
|
|
5240
|
-
let offset = 0;
|
|
5241
|
-
const dcData = new Array(ecTotalBlocks);
|
|
5242
|
-
const ecData = new Array(ecTotalBlocks);
|
|
5243
|
-
let maxDataSize = 0;
|
|
5244
|
-
const buffer = new Uint8Array(bitBuffer.buffer);
|
|
5245
|
-
for (let b = 0;b < ecTotalBlocks; b++) {
|
|
5246
|
-
const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
|
|
5247
|
-
dcData[b] = buffer.slice(offset, offset + dataSize);
|
|
5248
|
-
ecData[b] = rs.encode(dcData[b]);
|
|
5249
|
-
offset += dataSize;
|
|
5250
|
-
maxDataSize = Math.max(maxDataSize, dataSize);
|
|
5251
|
-
}
|
|
5252
|
-
const data = new Uint8Array(totalCodewords);
|
|
5253
|
-
let index = 0;
|
|
5254
|
-
let i2, r;
|
|
5255
|
-
for (i2 = 0;i2 < maxDataSize; i2++) {
|
|
5256
|
-
for (r = 0;r < ecTotalBlocks; r++) {
|
|
5257
|
-
if (i2 < dcData[r].length) {
|
|
5258
|
-
data[index++] = dcData[r][i2];
|
|
5259
|
-
}
|
|
5260
|
-
}
|
|
5261
|
-
}
|
|
5262
|
-
for (i2 = 0;i2 < ecCount; i2++) {
|
|
5263
|
-
for (r = 0;r < ecTotalBlocks; r++) {
|
|
5264
|
-
data[index++] = ecData[r][i2];
|
|
5265
|
-
}
|
|
5266
|
-
}
|
|
5267
|
-
return data;
|
|
5268
|
-
}
|
|
5269
|
-
function createSymbol(data, version, errorCorrectionLevel, maskPattern) {
|
|
5270
|
-
let segments;
|
|
5271
|
-
if (Array.isArray(data)) {
|
|
5272
|
-
segments = Segments.fromArray(data);
|
|
5273
|
-
} else if (typeof data === "string") {
|
|
5274
|
-
let estimatedVersion = version;
|
|
5275
|
-
if (!estimatedVersion) {
|
|
5276
|
-
const rawSegments = Segments.rawSplit(data);
|
|
5277
|
-
estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
|
|
5278
|
-
}
|
|
5279
|
-
segments = Segments.fromString(data, estimatedVersion || 40);
|
|
5280
|
-
} else {
|
|
5281
|
-
throw new Error("Invalid data");
|
|
5282
|
-
}
|
|
5283
|
-
const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
|
|
5284
|
-
if (!bestVersion) {
|
|
5285
|
-
throw new Error("The amount of data is too big to be stored in a QR Code");
|
|
5286
|
-
}
|
|
5287
|
-
if (!version) {
|
|
5288
|
-
version = bestVersion;
|
|
5289
|
-
} else if (version < bestVersion) {
|
|
5290
|
-
throw new Error(`
|
|
5291
|
-
` + `The chosen QR Code version cannot contain this amount of data.
|
|
5292
|
-
` + "Minimum version required to store current data is: " + bestVersion + `.
|
|
5293
|
-
`);
|
|
5294
|
-
}
|
|
5295
|
-
const dataBits = createData(version, errorCorrectionLevel, segments);
|
|
5296
|
-
const moduleCount = Utils.getSymbolSize(version);
|
|
5297
|
-
const modules = new BitMatrix(moduleCount);
|
|
5298
|
-
setupFinderPattern(modules, version);
|
|
5299
|
-
setupTimingPattern(modules);
|
|
5300
|
-
setupAlignmentPattern(modules, version);
|
|
5301
|
-
setupFormatInfo(modules, errorCorrectionLevel, 0);
|
|
5302
|
-
if (version >= 7) {
|
|
5303
|
-
setupVersionInfo(modules, version);
|
|
5304
|
-
}
|
|
5305
|
-
setupData(modules, dataBits);
|
|
5306
|
-
if (isNaN(maskPattern)) {
|
|
5307
|
-
maskPattern = MaskPattern.getBestMask(modules, setupFormatInfo.bind(null, modules, errorCorrectionLevel));
|
|
5308
|
-
}
|
|
5309
|
-
MaskPattern.applyMask(maskPattern, modules);
|
|
5310
|
-
setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
|
|
5311
|
-
return {
|
|
5312
|
-
modules,
|
|
5313
|
-
version,
|
|
5314
|
-
errorCorrectionLevel,
|
|
5315
|
-
maskPattern,
|
|
5316
|
-
segments
|
|
5317
|
-
};
|
|
5318
|
-
}
|
|
5319
|
-
exports.create = function create(data, options) {
|
|
5320
|
-
if (typeof data === "undefined" || data === "") {
|
|
5321
|
-
throw new Error("No input text");
|
|
5322
|
-
}
|
|
5323
|
-
let errorCorrectionLevel = ECLevel.M;
|
|
5324
|
-
let version;
|
|
5325
|
-
let mask;
|
|
5326
|
-
if (typeof options !== "undefined") {
|
|
5327
|
-
errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
|
|
5328
|
-
version = Version.from(options.version);
|
|
5329
|
-
mask = MaskPattern.from(options.maskPattern);
|
|
5330
|
-
if (options.toSJISFunc) {
|
|
5331
|
-
Utils.setToSJISFunction(options.toSJISFunc);
|
|
5332
|
-
}
|
|
5333
|
-
}
|
|
5334
|
-
return createSymbol(data, version, errorCorrectionLevel, mask);
|
|
5335
|
-
};
|
|
5336
|
-
});
|
|
5337
|
-
|
|
5338
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js
|
|
5339
|
-
var require_chunkstream = __commonJS((exports, module) => {
|
|
5340
|
-
var util = __require("util");
|
|
5341
|
-
var Stream = __require("stream");
|
|
5342
|
-
var ChunkStream = module.exports = function() {
|
|
5343
|
-
Stream.call(this);
|
|
5344
|
-
this._buffers = [];
|
|
5345
|
-
this._buffered = 0;
|
|
5346
|
-
this._reads = [];
|
|
5347
|
-
this._paused = false;
|
|
5348
|
-
this._encoding = "utf8";
|
|
5349
|
-
this.writable = true;
|
|
5350
|
-
};
|
|
5351
|
-
util.inherits(ChunkStream, Stream);
|
|
5352
|
-
ChunkStream.prototype.read = function(length, callback) {
|
|
5353
|
-
this._reads.push({
|
|
5354
|
-
length: Math.abs(length),
|
|
5355
|
-
allowLess: length < 0,
|
|
5356
|
-
func: callback
|
|
5357
|
-
});
|
|
5358
|
-
process.nextTick(function() {
|
|
5359
|
-
this._process();
|
|
5360
|
-
if (this._paused && this._reads && this._reads.length > 0) {
|
|
5361
|
-
this._paused = false;
|
|
5362
|
-
this.emit("drain");
|
|
5363
|
-
}
|
|
5364
|
-
}.bind(this));
|
|
5365
|
-
};
|
|
5366
|
-
ChunkStream.prototype.write = function(data, encoding) {
|
|
5367
|
-
if (!this.writable) {
|
|
5368
|
-
this.emit("error", new Error("Stream not writable"));
|
|
5369
|
-
return false;
|
|
5370
|
-
}
|
|
5371
|
-
let dataBuffer;
|
|
5372
|
-
if (Buffer.isBuffer(data)) {
|
|
5373
|
-
dataBuffer = data;
|
|
5374
|
-
} else {
|
|
5375
|
-
dataBuffer = Buffer.from(data, encoding || this._encoding);
|
|
5376
|
-
}
|
|
5377
|
-
this._buffers.push(dataBuffer);
|
|
5378
|
-
this._buffered += dataBuffer.length;
|
|
5379
|
-
this._process();
|
|
5380
|
-
if (this._reads && this._reads.length === 0) {
|
|
5381
|
-
this._paused = true;
|
|
5382
|
-
}
|
|
5383
|
-
return this.writable && !this._paused;
|
|
5384
|
-
};
|
|
5385
|
-
ChunkStream.prototype.end = function(data, encoding) {
|
|
5386
|
-
if (data) {
|
|
5387
|
-
this.write(data, encoding);
|
|
5388
|
-
}
|
|
5389
|
-
this.writable = false;
|
|
5390
|
-
if (!this._buffers) {
|
|
5391
|
-
return;
|
|
5392
|
-
}
|
|
5393
|
-
if (this._buffers.length === 0) {
|
|
5394
|
-
this._end();
|
|
5395
|
-
} else {
|
|
5396
|
-
this._buffers.push(null);
|
|
5397
|
-
this._process();
|
|
5398
|
-
}
|
|
5399
|
-
};
|
|
5400
|
-
ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
|
|
5401
|
-
ChunkStream.prototype._end = function() {
|
|
5402
|
-
if (this._reads.length > 0) {
|
|
5403
|
-
this.emit("error", new Error("Unexpected end of input"));
|
|
5404
|
-
}
|
|
5405
|
-
this.destroy();
|
|
5406
|
-
};
|
|
5407
|
-
ChunkStream.prototype.destroy = function() {
|
|
5408
|
-
if (!this._buffers) {
|
|
5409
|
-
return;
|
|
5410
|
-
}
|
|
5411
|
-
this.writable = false;
|
|
5412
|
-
this._reads = null;
|
|
5413
|
-
this._buffers = null;
|
|
5414
|
-
this.emit("close");
|
|
5415
|
-
};
|
|
5416
|
-
ChunkStream.prototype._processReadAllowingLess = function(read) {
|
|
5417
|
-
this._reads.shift();
|
|
5418
|
-
let smallerBuf = this._buffers[0];
|
|
5419
|
-
if (smallerBuf.length > read.length) {
|
|
5420
|
-
this._buffered -= read.length;
|
|
5421
|
-
this._buffers[0] = smallerBuf.slice(read.length);
|
|
5422
|
-
read.func.call(this, smallerBuf.slice(0, read.length));
|
|
5423
|
-
} else {
|
|
5424
|
-
this._buffered -= smallerBuf.length;
|
|
5425
|
-
this._buffers.shift();
|
|
5426
|
-
read.func.call(this, smallerBuf);
|
|
5427
|
-
}
|
|
5428
|
-
};
|
|
5429
|
-
ChunkStream.prototype._processRead = function(read) {
|
|
5430
|
-
this._reads.shift();
|
|
5431
|
-
let pos = 0;
|
|
5432
|
-
let count = 0;
|
|
5433
|
-
let data = Buffer.alloc(read.length);
|
|
5434
|
-
while (pos < read.length) {
|
|
5435
|
-
let buf = this._buffers[count++];
|
|
5436
|
-
let len = Math.min(buf.length, read.length - pos);
|
|
5437
|
-
buf.copy(data, pos, 0, len);
|
|
5438
|
-
pos += len;
|
|
5439
|
-
if (len !== buf.length) {
|
|
5440
|
-
this._buffers[--count] = buf.slice(len);
|
|
5441
|
-
}
|
|
5442
|
-
}
|
|
5443
|
-
if (count > 0) {
|
|
5444
|
-
this._buffers.splice(0, count);
|
|
5445
|
-
}
|
|
5446
|
-
this._buffered -= read.length;
|
|
5447
|
-
read.func.call(this, data);
|
|
5448
|
-
};
|
|
5449
|
-
ChunkStream.prototype._process = function() {
|
|
5450
|
-
try {
|
|
5451
|
-
while (this._buffered > 0 && this._reads && this._reads.length > 0) {
|
|
5452
|
-
let read = this._reads[0];
|
|
5453
|
-
if (read.allowLess) {
|
|
5454
|
-
this._processReadAllowingLess(read);
|
|
5455
|
-
} else if (this._buffered >= read.length) {
|
|
5456
|
-
this._processRead(read);
|
|
5457
|
-
} else {
|
|
5458
|
-
break;
|
|
5459
|
-
}
|
|
5460
|
-
}
|
|
5461
|
-
if (this._buffers && !this.writable) {
|
|
5462
|
-
this._end();
|
|
5463
|
-
}
|
|
5464
|
-
} catch (ex) {
|
|
5465
|
-
this.emit("error", ex);
|
|
5466
|
-
}
|
|
5467
|
-
};
|
|
5468
|
-
});
|
|
5469
|
-
|
|
5470
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js
|
|
5471
|
-
var require_interlace = __commonJS((exports) => {
|
|
5472
|
-
var imagePasses = [
|
|
5473
|
-
{
|
|
5474
|
-
x: [0],
|
|
5475
|
-
y: [0]
|
|
5476
|
-
},
|
|
5477
|
-
{
|
|
5478
|
-
x: [4],
|
|
5479
|
-
y: [0]
|
|
5480
|
-
},
|
|
5481
|
-
{
|
|
5482
|
-
x: [0, 4],
|
|
5483
|
-
y: [4]
|
|
5484
|
-
},
|
|
5485
|
-
{
|
|
5486
|
-
x: [2, 6],
|
|
5487
|
-
y: [0, 4]
|
|
5488
|
-
},
|
|
5489
|
-
{
|
|
5490
|
-
x: [0, 2, 4, 6],
|
|
5491
|
-
y: [2, 6]
|
|
5492
|
-
},
|
|
5493
|
-
{
|
|
5494
|
-
x: [1, 3, 5, 7],
|
|
5495
|
-
y: [0, 2, 4, 6]
|
|
5496
|
-
},
|
|
5497
|
-
{
|
|
5498
|
-
x: [0, 1, 2, 3, 4, 5, 6, 7],
|
|
5499
|
-
y: [1, 3, 5, 7]
|
|
5500
|
-
}
|
|
5501
|
-
];
|
|
5502
|
-
exports.getImagePasses = function(width, height) {
|
|
5503
|
-
let images = [];
|
|
5504
|
-
let xLeftOver = width % 8;
|
|
5505
|
-
let yLeftOver = height % 8;
|
|
5506
|
-
let xRepeats = (width - xLeftOver) / 8;
|
|
5507
|
-
let yRepeats = (height - yLeftOver) / 8;
|
|
5508
|
-
for (let i2 = 0;i2 < imagePasses.length; i2++) {
|
|
5509
|
-
let pass = imagePasses[i2];
|
|
5510
|
-
let passWidth = xRepeats * pass.x.length;
|
|
5511
|
-
let passHeight = yRepeats * pass.y.length;
|
|
5512
|
-
for (let j = 0;j < pass.x.length; j++) {
|
|
5513
|
-
if (pass.x[j] < xLeftOver) {
|
|
5514
|
-
passWidth++;
|
|
5515
|
-
} else {
|
|
5516
|
-
break;
|
|
5517
|
-
}
|
|
5518
|
-
}
|
|
5519
|
-
for (let j = 0;j < pass.y.length; j++) {
|
|
5520
|
-
if (pass.y[j] < yLeftOver) {
|
|
5521
|
-
passHeight++;
|
|
5522
|
-
} else {
|
|
5523
|
-
break;
|
|
5524
|
-
}
|
|
5525
|
-
}
|
|
5526
|
-
if (passWidth > 0 && passHeight > 0) {
|
|
5527
|
-
images.push({ width: passWidth, height: passHeight, index: i2 });
|
|
5528
|
-
}
|
|
5529
|
-
}
|
|
5530
|
-
return images;
|
|
5531
|
-
};
|
|
5532
|
-
exports.getInterlaceIterator = function(width) {
|
|
5533
|
-
return function(x2, y, pass) {
|
|
5534
|
-
let outerXLeftOver = x2 % imagePasses[pass].x.length;
|
|
5535
|
-
let outerX = (x2 - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
|
|
5536
|
-
let outerYLeftOver = y % imagePasses[pass].y.length;
|
|
5537
|
-
let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
|
|
5538
|
-
return outerX * 4 + outerY * width * 4;
|
|
5539
|
-
};
|
|
5540
|
-
};
|
|
5541
|
-
});
|
|
5542
|
-
|
|
5543
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js
|
|
5544
|
-
var require_paeth_predictor = __commonJS((exports, module) => {
|
|
5545
|
-
module.exports = function paethPredictor(left, above, upLeft) {
|
|
5546
|
-
let paeth = left + above - upLeft;
|
|
5547
|
-
let pLeft = Math.abs(paeth - left);
|
|
5548
|
-
let pAbove = Math.abs(paeth - above);
|
|
5549
|
-
let pUpLeft = Math.abs(paeth - upLeft);
|
|
5550
|
-
if (pLeft <= pAbove && pLeft <= pUpLeft) {
|
|
5551
|
-
return left;
|
|
5552
|
-
}
|
|
5553
|
-
if (pAbove <= pUpLeft) {
|
|
5554
|
-
return above;
|
|
5555
|
-
}
|
|
5556
|
-
return upLeft;
|
|
5557
|
-
};
|
|
5558
|
-
});
|
|
5559
|
-
|
|
5560
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js
|
|
5561
|
-
var require_filter_parse = __commonJS((exports, module) => {
|
|
5562
|
-
var interlaceUtils = require_interlace();
|
|
5563
|
-
var paethPredictor = require_paeth_predictor();
|
|
5564
|
-
function getByteWidth(width, bpp, depth) {
|
|
5565
|
-
let byteWidth = width * bpp;
|
|
5566
|
-
if (depth !== 8) {
|
|
5567
|
-
byteWidth = Math.ceil(byteWidth / (8 / depth));
|
|
5568
|
-
}
|
|
5569
|
-
return byteWidth;
|
|
5570
|
-
}
|
|
5571
|
-
var Filter = module.exports = function(bitmapInfo, dependencies) {
|
|
5572
|
-
let width = bitmapInfo.width;
|
|
5573
|
-
let height = bitmapInfo.height;
|
|
5574
|
-
let interlace = bitmapInfo.interlace;
|
|
5575
|
-
let bpp = bitmapInfo.bpp;
|
|
5576
|
-
let depth = bitmapInfo.depth;
|
|
5577
|
-
this.read = dependencies.read;
|
|
5578
|
-
this.write = dependencies.write;
|
|
5579
|
-
this.complete = dependencies.complete;
|
|
5580
|
-
this._imageIndex = 0;
|
|
5581
|
-
this._images = [];
|
|
5582
|
-
if (interlace) {
|
|
5583
|
-
let passes = interlaceUtils.getImagePasses(width, height);
|
|
5584
|
-
for (let i2 = 0;i2 < passes.length; i2++) {
|
|
5585
|
-
this._images.push({
|
|
5586
|
-
byteWidth: getByteWidth(passes[i2].width, bpp, depth),
|
|
5587
|
-
height: passes[i2].height,
|
|
5588
|
-
lineIndex: 0
|
|
5589
|
-
});
|
|
5590
|
-
}
|
|
5591
|
-
} else {
|
|
5592
|
-
this._images.push({
|
|
5593
|
-
byteWidth: getByteWidth(width, bpp, depth),
|
|
5594
|
-
height,
|
|
5595
|
-
lineIndex: 0
|
|
5596
|
-
});
|
|
5597
|
-
}
|
|
5598
|
-
if (depth === 8) {
|
|
5599
|
-
this._xComparison = bpp;
|
|
5600
|
-
} else if (depth === 16) {
|
|
5601
|
-
this._xComparison = bpp * 2;
|
|
5602
|
-
} else {
|
|
5603
|
-
this._xComparison = 1;
|
|
5604
|
-
}
|
|
5605
|
-
};
|
|
5606
|
-
Filter.prototype.start = function() {
|
|
5607
|
-
this.read(this._images[this._imageIndex].byteWidth + 1, this._reverseFilterLine.bind(this));
|
|
5608
|
-
};
|
|
5609
|
-
Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
|
|
5610
|
-
let xComparison = this._xComparison;
|
|
5611
|
-
let xBiggerThan = xComparison - 1;
|
|
5612
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
5613
|
-
let rawByte = rawData[1 + x2];
|
|
5614
|
-
let f1Left = x2 > xBiggerThan ? unfilteredLine[x2 - xComparison] : 0;
|
|
5615
|
-
unfilteredLine[x2] = rawByte + f1Left;
|
|
5616
|
-
}
|
|
5617
|
-
};
|
|
5618
|
-
Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
|
|
5619
|
-
let lastLine = this._lastLine;
|
|
5620
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
5621
|
-
let rawByte = rawData[1 + x2];
|
|
5622
|
-
let f2Up = lastLine ? lastLine[x2] : 0;
|
|
5623
|
-
unfilteredLine[x2] = rawByte + f2Up;
|
|
5624
|
-
}
|
|
5625
|
-
};
|
|
5626
|
-
Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
|
|
5627
|
-
let xComparison = this._xComparison;
|
|
5628
|
-
let xBiggerThan = xComparison - 1;
|
|
5629
|
-
let lastLine = this._lastLine;
|
|
5630
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
5631
|
-
let rawByte = rawData[1 + x2];
|
|
5632
|
-
let f3Up = lastLine ? lastLine[x2] : 0;
|
|
5633
|
-
let f3Left = x2 > xBiggerThan ? unfilteredLine[x2 - xComparison] : 0;
|
|
5634
|
-
let f3Add = Math.floor((f3Left + f3Up) / 2);
|
|
5635
|
-
unfilteredLine[x2] = rawByte + f3Add;
|
|
5636
|
-
}
|
|
5637
|
-
};
|
|
5638
|
-
Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
|
|
5639
|
-
let xComparison = this._xComparison;
|
|
5640
|
-
let xBiggerThan = xComparison - 1;
|
|
5641
|
-
let lastLine = this._lastLine;
|
|
5642
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
5643
|
-
let rawByte = rawData[1 + x2];
|
|
5644
|
-
let f4Up = lastLine ? lastLine[x2] : 0;
|
|
5645
|
-
let f4Left = x2 > xBiggerThan ? unfilteredLine[x2 - xComparison] : 0;
|
|
5646
|
-
let f4UpLeft = x2 > xBiggerThan && lastLine ? lastLine[x2 - xComparison] : 0;
|
|
5647
|
-
let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
|
|
5648
|
-
unfilteredLine[x2] = rawByte + f4Add;
|
|
5649
|
-
}
|
|
5650
|
-
};
|
|
5651
|
-
Filter.prototype._reverseFilterLine = function(rawData) {
|
|
5652
|
-
let filter = rawData[0];
|
|
5653
|
-
let unfilteredLine;
|
|
5654
|
-
let currentImage = this._images[this._imageIndex];
|
|
5655
|
-
let byteWidth = currentImage.byteWidth;
|
|
5656
|
-
if (filter === 0) {
|
|
5657
|
-
unfilteredLine = rawData.slice(1, byteWidth + 1);
|
|
5658
|
-
} else {
|
|
5659
|
-
unfilteredLine = Buffer.alloc(byteWidth);
|
|
5660
|
-
switch (filter) {
|
|
5661
|
-
case 1:
|
|
5662
|
-
this._unFilterType1(rawData, unfilteredLine, byteWidth);
|
|
5663
|
-
break;
|
|
5664
|
-
case 2:
|
|
5665
|
-
this._unFilterType2(rawData, unfilteredLine, byteWidth);
|
|
5666
|
-
break;
|
|
5667
|
-
case 3:
|
|
5668
|
-
this._unFilterType3(rawData, unfilteredLine, byteWidth);
|
|
5669
|
-
break;
|
|
5670
|
-
case 4:
|
|
5671
|
-
this._unFilterType4(rawData, unfilteredLine, byteWidth);
|
|
5672
|
-
break;
|
|
5673
|
-
default:
|
|
5674
|
-
throw new Error("Unrecognised filter type - " + filter);
|
|
5675
|
-
}
|
|
5676
|
-
}
|
|
5677
|
-
this.write(unfilteredLine);
|
|
5678
|
-
currentImage.lineIndex++;
|
|
5679
|
-
if (currentImage.lineIndex >= currentImage.height) {
|
|
5680
|
-
this._lastLine = null;
|
|
5681
|
-
this._imageIndex++;
|
|
5682
|
-
currentImage = this._images[this._imageIndex];
|
|
5683
|
-
} else {
|
|
5684
|
-
this._lastLine = unfilteredLine;
|
|
5685
|
-
}
|
|
5686
|
-
if (currentImage) {
|
|
5687
|
-
this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
|
|
5688
|
-
} else {
|
|
5689
|
-
this._lastLine = null;
|
|
5690
|
-
this.complete();
|
|
5691
|
-
}
|
|
5692
|
-
};
|
|
5693
|
-
});
|
|
5694
|
-
|
|
5695
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-async.js
|
|
5696
|
-
var require_filter_parse_async = __commonJS((exports, module) => {
|
|
5697
|
-
var util = __require("util");
|
|
5698
|
-
var ChunkStream = require_chunkstream();
|
|
5699
|
-
var Filter = require_filter_parse();
|
|
5700
|
-
var FilterAsync = module.exports = function(bitmapInfo) {
|
|
5701
|
-
ChunkStream.call(this);
|
|
5702
|
-
let buffers = [];
|
|
5703
|
-
let that = this;
|
|
5704
|
-
this._filter = new Filter(bitmapInfo, {
|
|
5705
|
-
read: this.read.bind(this),
|
|
5706
|
-
write: function(buffer) {
|
|
5707
|
-
buffers.push(buffer);
|
|
5708
|
-
},
|
|
5709
|
-
complete: function() {
|
|
5710
|
-
that.emit("complete", Buffer.concat(buffers));
|
|
5711
|
-
}
|
|
5712
|
-
});
|
|
5713
|
-
this._filter.start();
|
|
5714
|
-
};
|
|
5715
|
-
util.inherits(FilterAsync, ChunkStream);
|
|
5716
|
-
});
|
|
5717
|
-
|
|
5718
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/constants.js
|
|
5719
|
-
var require_constants2 = __commonJS((exports, module) => {
|
|
5720
|
-
module.exports = {
|
|
5721
|
-
PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
|
|
5722
|
-
TYPE_IHDR: 1229472850,
|
|
5723
|
-
TYPE_IEND: 1229278788,
|
|
5724
|
-
TYPE_IDAT: 1229209940,
|
|
5725
|
-
TYPE_PLTE: 1347179589,
|
|
5726
|
-
TYPE_tRNS: 1951551059,
|
|
5727
|
-
TYPE_gAMA: 1732332865,
|
|
5728
|
-
COLORTYPE_GRAYSCALE: 0,
|
|
5729
|
-
COLORTYPE_PALETTE: 1,
|
|
5730
|
-
COLORTYPE_COLOR: 2,
|
|
5731
|
-
COLORTYPE_ALPHA: 4,
|
|
5732
|
-
COLORTYPE_PALETTE_COLOR: 3,
|
|
5733
|
-
COLORTYPE_COLOR_ALPHA: 6,
|
|
5734
|
-
COLORTYPE_TO_BPP_MAP: {
|
|
5735
|
-
0: 1,
|
|
5736
|
-
2: 3,
|
|
5737
|
-
3: 1,
|
|
5738
|
-
4: 2,
|
|
5739
|
-
6: 4
|
|
5740
|
-
},
|
|
5741
|
-
GAMMA_DIVISION: 1e5
|
|
5742
|
-
};
|
|
5743
|
-
});
|
|
5744
|
-
|
|
5745
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/crc.js
|
|
5746
|
-
var require_crc = __commonJS((exports, module) => {
|
|
5747
|
-
var crcTable = [];
|
|
5748
|
-
(function() {
|
|
5749
|
-
for (let i2 = 0;i2 < 256; i2++) {
|
|
5750
|
-
let currentCrc = i2;
|
|
5751
|
-
for (let j = 0;j < 8; j++) {
|
|
5752
|
-
if (currentCrc & 1) {
|
|
5753
|
-
currentCrc = 3988292384 ^ currentCrc >>> 1;
|
|
5754
|
-
} else {
|
|
5755
|
-
currentCrc = currentCrc >>> 1;
|
|
5756
|
-
}
|
|
5757
|
-
}
|
|
5758
|
-
crcTable[i2] = currentCrc;
|
|
5759
|
-
}
|
|
5760
|
-
})();
|
|
5761
|
-
var CrcCalculator = module.exports = function() {
|
|
5762
|
-
this._crc = -1;
|
|
5763
|
-
};
|
|
5764
|
-
CrcCalculator.prototype.write = function(data) {
|
|
5765
|
-
for (let i2 = 0;i2 < data.length; i2++) {
|
|
5766
|
-
this._crc = crcTable[(this._crc ^ data[i2]) & 255] ^ this._crc >>> 8;
|
|
5767
|
-
}
|
|
5768
|
-
return true;
|
|
5769
|
-
};
|
|
5770
|
-
CrcCalculator.prototype.crc32 = function() {
|
|
5771
|
-
return this._crc ^ -1;
|
|
5772
|
-
};
|
|
5773
|
-
CrcCalculator.crc32 = function(buf) {
|
|
5774
|
-
let crc2 = -1;
|
|
5775
|
-
for (let i2 = 0;i2 < buf.length; i2++) {
|
|
5776
|
-
crc2 = crcTable[(crc2 ^ buf[i2]) & 255] ^ crc2 >>> 8;
|
|
5777
|
-
}
|
|
5778
|
-
return crc2 ^ -1;
|
|
5779
|
-
};
|
|
5780
|
-
});
|
|
5781
|
-
|
|
5782
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/parser.js
|
|
5783
|
-
var require_parser = __commonJS((exports, module) => {
|
|
5784
|
-
var constants = require_constants2();
|
|
5785
|
-
var CrcCalculator = require_crc();
|
|
5786
|
-
var Parser = module.exports = function(options, dependencies) {
|
|
5787
|
-
this._options = options;
|
|
5788
|
-
options.checkCRC = options.checkCRC !== false;
|
|
5789
|
-
this._hasIHDR = false;
|
|
5790
|
-
this._hasIEND = false;
|
|
5791
|
-
this._emittedHeadersFinished = false;
|
|
5792
|
-
this._palette = [];
|
|
5793
|
-
this._colorType = 0;
|
|
5794
|
-
this._chunks = {};
|
|
5795
|
-
this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
|
|
5796
|
-
this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
|
|
5797
|
-
this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
|
|
5798
|
-
this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
|
|
5799
|
-
this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
|
|
5800
|
-
this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
|
|
5801
|
-
this.read = dependencies.read;
|
|
5802
|
-
this.error = dependencies.error;
|
|
5803
|
-
this.metadata = dependencies.metadata;
|
|
5804
|
-
this.gamma = dependencies.gamma;
|
|
5805
|
-
this.transColor = dependencies.transColor;
|
|
5806
|
-
this.palette = dependencies.palette;
|
|
5807
|
-
this.parsed = dependencies.parsed;
|
|
5808
|
-
this.inflateData = dependencies.inflateData;
|
|
5809
|
-
this.finished = dependencies.finished;
|
|
5810
|
-
this.simpleTransparency = dependencies.simpleTransparency;
|
|
5811
|
-
this.headersFinished = dependencies.headersFinished || function() {};
|
|
5812
|
-
};
|
|
5813
|
-
Parser.prototype.start = function() {
|
|
5814
|
-
this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
|
|
5815
|
-
};
|
|
5816
|
-
Parser.prototype._parseSignature = function(data) {
|
|
5817
|
-
let signature = constants.PNG_SIGNATURE;
|
|
5818
|
-
for (let i2 = 0;i2 < signature.length; i2++) {
|
|
5819
|
-
if (data[i2] !== signature[i2]) {
|
|
5820
|
-
this.error(new Error("Invalid file signature"));
|
|
5821
|
-
return;
|
|
5822
|
-
}
|
|
5823
|
-
}
|
|
5824
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
5825
|
-
};
|
|
5826
|
-
Parser.prototype._parseChunkBegin = function(data) {
|
|
5827
|
-
let length = data.readUInt32BE(0);
|
|
5828
|
-
let type = data.readUInt32BE(4);
|
|
5829
|
-
let name = "";
|
|
5830
|
-
for (let i2 = 4;i2 < 8; i2++) {
|
|
5831
|
-
name += String.fromCharCode(data[i2]);
|
|
5832
|
-
}
|
|
5833
|
-
let ancillary = Boolean(data[4] & 32);
|
|
5834
|
-
if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
|
|
5835
|
-
this.error(new Error("Expected IHDR on beggining"));
|
|
5836
|
-
return;
|
|
5837
|
-
}
|
|
5838
|
-
this._crc = new CrcCalculator;
|
|
5839
|
-
this._crc.write(Buffer.from(name));
|
|
5840
|
-
if (this._chunks[type]) {
|
|
5841
|
-
return this._chunks[type](length);
|
|
5842
|
-
}
|
|
5843
|
-
if (!ancillary) {
|
|
5844
|
-
this.error(new Error("Unsupported critical chunk type " + name));
|
|
5845
|
-
return;
|
|
5846
|
-
}
|
|
5847
|
-
this.read(length + 4, this._skipChunk.bind(this));
|
|
5848
|
-
};
|
|
5849
|
-
Parser.prototype._skipChunk = function() {
|
|
5850
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
5851
|
-
};
|
|
5852
|
-
Parser.prototype._handleChunkEnd = function() {
|
|
5853
|
-
this.read(4, this._parseChunkEnd.bind(this));
|
|
5854
|
-
};
|
|
5855
|
-
Parser.prototype._parseChunkEnd = function(data) {
|
|
5856
|
-
let fileCrc = data.readInt32BE(0);
|
|
5857
|
-
let calcCrc = this._crc.crc32();
|
|
5858
|
-
if (this._options.checkCRC && calcCrc !== fileCrc) {
|
|
5859
|
-
this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
|
|
5860
|
-
return;
|
|
5861
|
-
}
|
|
5862
|
-
if (!this._hasIEND) {
|
|
5863
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
5864
|
-
}
|
|
5865
|
-
};
|
|
5866
|
-
Parser.prototype._handleIHDR = function(length) {
|
|
5867
|
-
this.read(length, this._parseIHDR.bind(this));
|
|
5868
|
-
};
|
|
5869
|
-
Parser.prototype._parseIHDR = function(data) {
|
|
5870
|
-
this._crc.write(data);
|
|
5871
|
-
let width = data.readUInt32BE(0);
|
|
5872
|
-
let height = data.readUInt32BE(4);
|
|
5873
|
-
let depth = data[8];
|
|
5874
|
-
let colorType = data[9];
|
|
5875
|
-
let compr = data[10];
|
|
5876
|
-
let filter = data[11];
|
|
5877
|
-
let interlace = data[12];
|
|
5878
|
-
if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
|
|
5879
|
-
this.error(new Error("Unsupported bit depth " + depth));
|
|
5880
|
-
return;
|
|
5881
|
-
}
|
|
5882
|
-
if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
|
|
5883
|
-
this.error(new Error("Unsupported color type"));
|
|
5884
|
-
return;
|
|
5885
|
-
}
|
|
5886
|
-
if (compr !== 0) {
|
|
5887
|
-
this.error(new Error("Unsupported compression method"));
|
|
5888
|
-
return;
|
|
5889
|
-
}
|
|
5890
|
-
if (filter !== 0) {
|
|
5891
|
-
this.error(new Error("Unsupported filter method"));
|
|
5892
|
-
return;
|
|
5893
|
-
}
|
|
5894
|
-
if (interlace !== 0 && interlace !== 1) {
|
|
5895
|
-
this.error(new Error("Unsupported interlace method"));
|
|
5896
|
-
return;
|
|
5897
|
-
}
|
|
5898
|
-
this._colorType = colorType;
|
|
5899
|
-
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
|
|
5900
|
-
this._hasIHDR = true;
|
|
5901
|
-
this.metadata({
|
|
5902
|
-
width,
|
|
5903
|
-
height,
|
|
5904
|
-
depth,
|
|
5905
|
-
interlace: Boolean(interlace),
|
|
5906
|
-
palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
|
|
5907
|
-
color: Boolean(colorType & constants.COLORTYPE_COLOR),
|
|
5908
|
-
alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
|
|
5909
|
-
bpp,
|
|
5910
|
-
colorType
|
|
5911
|
-
});
|
|
5912
|
-
this._handleChunkEnd();
|
|
5913
|
-
};
|
|
5914
|
-
Parser.prototype._handlePLTE = function(length) {
|
|
5915
|
-
this.read(length, this._parsePLTE.bind(this));
|
|
5916
|
-
};
|
|
5917
|
-
Parser.prototype._parsePLTE = function(data) {
|
|
5918
|
-
this._crc.write(data);
|
|
5919
|
-
let entries = Math.floor(data.length / 3);
|
|
5920
|
-
for (let i2 = 0;i2 < entries; i2++) {
|
|
5921
|
-
this._palette.push([data[i2 * 3], data[i2 * 3 + 1], data[i2 * 3 + 2], 255]);
|
|
5922
|
-
}
|
|
5923
|
-
this.palette(this._palette);
|
|
5924
|
-
this._handleChunkEnd();
|
|
5925
|
-
};
|
|
5926
|
-
Parser.prototype._handleTRNS = function(length) {
|
|
5927
|
-
this.simpleTransparency();
|
|
5928
|
-
this.read(length, this._parseTRNS.bind(this));
|
|
5929
|
-
};
|
|
5930
|
-
Parser.prototype._parseTRNS = function(data) {
|
|
5931
|
-
this._crc.write(data);
|
|
5932
|
-
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
|
|
5933
|
-
if (this._palette.length === 0) {
|
|
5934
|
-
this.error(new Error("Transparency chunk must be after palette"));
|
|
5935
|
-
return;
|
|
5936
|
-
}
|
|
5937
|
-
if (data.length > this._palette.length) {
|
|
5938
|
-
this.error(new Error("More transparent colors than palette size"));
|
|
5939
|
-
return;
|
|
5940
|
-
}
|
|
5941
|
-
for (let i2 = 0;i2 < data.length; i2++) {
|
|
5942
|
-
this._palette[i2][3] = data[i2];
|
|
5943
|
-
}
|
|
5944
|
-
this.palette(this._palette);
|
|
5945
|
-
}
|
|
5946
|
-
if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
|
|
5947
|
-
this.transColor([data.readUInt16BE(0)]);
|
|
5948
|
-
}
|
|
5949
|
-
if (this._colorType === constants.COLORTYPE_COLOR) {
|
|
5950
|
-
this.transColor([
|
|
5951
|
-
data.readUInt16BE(0),
|
|
5952
|
-
data.readUInt16BE(2),
|
|
5953
|
-
data.readUInt16BE(4)
|
|
5954
|
-
]);
|
|
5955
|
-
}
|
|
5956
|
-
this._handleChunkEnd();
|
|
5957
|
-
};
|
|
5958
|
-
Parser.prototype._handleGAMA = function(length) {
|
|
5959
|
-
this.read(length, this._parseGAMA.bind(this));
|
|
5960
|
-
};
|
|
5961
|
-
Parser.prototype._parseGAMA = function(data) {
|
|
5962
|
-
this._crc.write(data);
|
|
5963
|
-
this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
|
|
5964
|
-
this._handleChunkEnd();
|
|
5965
|
-
};
|
|
5966
|
-
Parser.prototype._handleIDAT = function(length) {
|
|
5967
|
-
if (!this._emittedHeadersFinished) {
|
|
5968
|
-
this._emittedHeadersFinished = true;
|
|
5969
|
-
this.headersFinished();
|
|
5970
|
-
}
|
|
5971
|
-
this.read(-length, this._parseIDAT.bind(this, length));
|
|
5972
|
-
};
|
|
5973
|
-
Parser.prototype._parseIDAT = function(length, data) {
|
|
5974
|
-
this._crc.write(data);
|
|
5975
|
-
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
|
|
5976
|
-
throw new Error("Expected palette not found");
|
|
5977
|
-
}
|
|
5978
|
-
this.inflateData(data);
|
|
5979
|
-
let leftOverLength = length - data.length;
|
|
5980
|
-
if (leftOverLength > 0) {
|
|
5981
|
-
this._handleIDAT(leftOverLength);
|
|
5982
|
-
} else {
|
|
5983
|
-
this._handleChunkEnd();
|
|
5984
|
-
}
|
|
5985
|
-
};
|
|
5986
|
-
Parser.prototype._handleIEND = function(length) {
|
|
5987
|
-
this.read(length, this._parseIEND.bind(this));
|
|
5988
|
-
};
|
|
5989
|
-
Parser.prototype._parseIEND = function(data) {
|
|
5990
|
-
this._crc.write(data);
|
|
5991
|
-
this._hasIEND = true;
|
|
5992
|
-
this._handleChunkEnd();
|
|
5993
|
-
if (this.finished) {
|
|
5994
|
-
this.finished();
|
|
5995
|
-
}
|
|
5996
|
-
};
|
|
5997
|
-
});
|
|
5998
|
-
|
|
5999
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js
|
|
6000
|
-
var require_bitmapper = __commonJS((exports) => {
|
|
6001
|
-
var interlaceUtils = require_interlace();
|
|
6002
|
-
var pixelBppMapper = [
|
|
6003
|
-
function() {},
|
|
6004
|
-
function(pxData, data, pxPos, rawPos) {
|
|
6005
|
-
if (rawPos === data.length) {
|
|
6006
|
-
throw new Error("Ran out of data");
|
|
6007
|
-
}
|
|
6008
|
-
let pixel = data[rawPos];
|
|
6009
|
-
pxData[pxPos] = pixel;
|
|
6010
|
-
pxData[pxPos + 1] = pixel;
|
|
6011
|
-
pxData[pxPos + 2] = pixel;
|
|
6012
|
-
pxData[pxPos + 3] = 255;
|
|
6013
|
-
},
|
|
6014
|
-
function(pxData, data, pxPos, rawPos) {
|
|
6015
|
-
if (rawPos + 1 >= data.length) {
|
|
6016
|
-
throw new Error("Ran out of data");
|
|
6017
|
-
}
|
|
6018
|
-
let pixel = data[rawPos];
|
|
6019
|
-
pxData[pxPos] = pixel;
|
|
6020
|
-
pxData[pxPos + 1] = pixel;
|
|
6021
|
-
pxData[pxPos + 2] = pixel;
|
|
6022
|
-
pxData[pxPos + 3] = data[rawPos + 1];
|
|
6023
|
-
},
|
|
6024
|
-
function(pxData, data, pxPos, rawPos) {
|
|
6025
|
-
if (rawPos + 2 >= data.length) {
|
|
6026
|
-
throw new Error("Ran out of data");
|
|
6027
|
-
}
|
|
6028
|
-
pxData[pxPos] = data[rawPos];
|
|
6029
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
6030
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
6031
|
-
pxData[pxPos + 3] = 255;
|
|
6032
|
-
},
|
|
6033
|
-
function(pxData, data, pxPos, rawPos) {
|
|
6034
|
-
if (rawPos + 3 >= data.length) {
|
|
6035
|
-
throw new Error("Ran out of data");
|
|
6036
|
-
}
|
|
6037
|
-
pxData[pxPos] = data[rawPos];
|
|
6038
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
6039
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
6040
|
-
pxData[pxPos + 3] = data[rawPos + 3];
|
|
6041
|
-
}
|
|
6042
|
-
];
|
|
6043
|
-
var pixelBppCustomMapper = [
|
|
6044
|
-
function() {},
|
|
6045
|
-
function(pxData, pixelData, pxPos, maxBit) {
|
|
6046
|
-
let pixel = pixelData[0];
|
|
6047
|
-
pxData[pxPos] = pixel;
|
|
6048
|
-
pxData[pxPos + 1] = pixel;
|
|
6049
|
-
pxData[pxPos + 2] = pixel;
|
|
6050
|
-
pxData[pxPos + 3] = maxBit;
|
|
6051
|
-
},
|
|
6052
|
-
function(pxData, pixelData, pxPos) {
|
|
6053
|
-
let pixel = pixelData[0];
|
|
6054
|
-
pxData[pxPos] = pixel;
|
|
6055
|
-
pxData[pxPos + 1] = pixel;
|
|
6056
|
-
pxData[pxPos + 2] = pixel;
|
|
6057
|
-
pxData[pxPos + 3] = pixelData[1];
|
|
6058
|
-
},
|
|
6059
|
-
function(pxData, pixelData, pxPos, maxBit) {
|
|
6060
|
-
pxData[pxPos] = pixelData[0];
|
|
6061
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
6062
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
6063
|
-
pxData[pxPos + 3] = maxBit;
|
|
6064
|
-
},
|
|
6065
|
-
function(pxData, pixelData, pxPos) {
|
|
6066
|
-
pxData[pxPos] = pixelData[0];
|
|
6067
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
6068
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
6069
|
-
pxData[pxPos + 3] = pixelData[3];
|
|
6070
|
-
}
|
|
6071
|
-
];
|
|
6072
|
-
function bitRetriever(data, depth) {
|
|
6073
|
-
let leftOver = [];
|
|
6074
|
-
let i2 = 0;
|
|
6075
|
-
function split() {
|
|
6076
|
-
if (i2 === data.length) {
|
|
6077
|
-
throw new Error("Ran out of data");
|
|
6078
|
-
}
|
|
6079
|
-
let byte = data[i2];
|
|
6080
|
-
i2++;
|
|
6081
|
-
let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
|
|
6082
|
-
switch (depth) {
|
|
6083
|
-
default:
|
|
6084
|
-
throw new Error("unrecognised depth");
|
|
6085
|
-
case 16:
|
|
6086
|
-
byte2 = data[i2];
|
|
6087
|
-
i2++;
|
|
6088
|
-
leftOver.push((byte << 8) + byte2);
|
|
6089
|
-
break;
|
|
6090
|
-
case 4:
|
|
6091
|
-
byte2 = byte & 15;
|
|
6092
|
-
byte1 = byte >> 4;
|
|
6093
|
-
leftOver.push(byte1, byte2);
|
|
6094
|
-
break;
|
|
6095
|
-
case 2:
|
|
6096
|
-
byte4 = byte & 3;
|
|
6097
|
-
byte3 = byte >> 2 & 3;
|
|
6098
|
-
byte2 = byte >> 4 & 3;
|
|
6099
|
-
byte1 = byte >> 6 & 3;
|
|
6100
|
-
leftOver.push(byte1, byte2, byte3, byte4);
|
|
6101
|
-
break;
|
|
6102
|
-
case 1:
|
|
6103
|
-
byte8 = byte & 1;
|
|
6104
|
-
byte7 = byte >> 1 & 1;
|
|
6105
|
-
byte6 = byte >> 2 & 1;
|
|
6106
|
-
byte5 = byte >> 3 & 1;
|
|
6107
|
-
byte4 = byte >> 4 & 1;
|
|
6108
|
-
byte3 = byte >> 5 & 1;
|
|
6109
|
-
byte2 = byte >> 6 & 1;
|
|
6110
|
-
byte1 = byte >> 7 & 1;
|
|
6111
|
-
leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
|
|
6112
|
-
break;
|
|
6113
|
-
}
|
|
6114
|
-
}
|
|
6115
|
-
return {
|
|
6116
|
-
get: function(count) {
|
|
6117
|
-
while (leftOver.length < count) {
|
|
6118
|
-
split();
|
|
6119
|
-
}
|
|
6120
|
-
let returner = leftOver.slice(0, count);
|
|
6121
|
-
leftOver = leftOver.slice(count);
|
|
6122
|
-
return returner;
|
|
6123
|
-
},
|
|
6124
|
-
resetAfterLine: function() {
|
|
6125
|
-
leftOver.length = 0;
|
|
6126
|
-
},
|
|
6127
|
-
end: function() {
|
|
6128
|
-
if (i2 !== data.length) {
|
|
6129
|
-
throw new Error("extra data found");
|
|
6130
|
-
}
|
|
6131
|
-
}
|
|
6132
|
-
};
|
|
6133
|
-
}
|
|
6134
|
-
function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
|
|
6135
|
-
let imageWidth = image.width;
|
|
6136
|
-
let imageHeight = image.height;
|
|
6137
|
-
let imagePass = image.index;
|
|
6138
|
-
for (let y = 0;y < imageHeight; y++) {
|
|
6139
|
-
for (let x2 = 0;x2 < imageWidth; x2++) {
|
|
6140
|
-
let pxPos = getPxPos(x2, y, imagePass);
|
|
6141
|
-
pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
|
|
6142
|
-
rawPos += bpp;
|
|
6143
|
-
}
|
|
6144
|
-
}
|
|
6145
|
-
return rawPos;
|
|
6146
|
-
}
|
|
6147
|
-
function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
|
|
6148
|
-
let imageWidth = image.width;
|
|
6149
|
-
let imageHeight = image.height;
|
|
6150
|
-
let imagePass = image.index;
|
|
6151
|
-
for (let y = 0;y < imageHeight; y++) {
|
|
6152
|
-
for (let x2 = 0;x2 < imageWidth; x2++) {
|
|
6153
|
-
let pixelData = bits.get(bpp);
|
|
6154
|
-
let pxPos = getPxPos(x2, y, imagePass);
|
|
6155
|
-
pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
|
|
6156
|
-
}
|
|
6157
|
-
bits.resetAfterLine();
|
|
6158
|
-
}
|
|
6159
|
-
}
|
|
6160
|
-
exports.dataToBitMap = function(data, bitmapInfo) {
|
|
6161
|
-
let width = bitmapInfo.width;
|
|
6162
|
-
let height = bitmapInfo.height;
|
|
6163
|
-
let depth = bitmapInfo.depth;
|
|
6164
|
-
let bpp = bitmapInfo.bpp;
|
|
6165
|
-
let interlace = bitmapInfo.interlace;
|
|
6166
|
-
let bits;
|
|
6167
|
-
if (depth !== 8) {
|
|
6168
|
-
bits = bitRetriever(data, depth);
|
|
6169
|
-
}
|
|
6170
|
-
let pxData;
|
|
6171
|
-
if (depth <= 8) {
|
|
6172
|
-
pxData = Buffer.alloc(width * height * 4);
|
|
6173
|
-
} else {
|
|
6174
|
-
pxData = new Uint16Array(width * height * 4);
|
|
6175
|
-
}
|
|
6176
|
-
let maxBit = Math.pow(2, depth) - 1;
|
|
6177
|
-
let rawPos = 0;
|
|
6178
|
-
let images;
|
|
6179
|
-
let getPxPos;
|
|
6180
|
-
if (interlace) {
|
|
6181
|
-
images = interlaceUtils.getImagePasses(width, height);
|
|
6182
|
-
getPxPos = interlaceUtils.getInterlaceIterator(width, height);
|
|
6183
|
-
} else {
|
|
6184
|
-
let nonInterlacedPxPos = 0;
|
|
6185
|
-
getPxPos = function() {
|
|
6186
|
-
let returner = nonInterlacedPxPos;
|
|
6187
|
-
nonInterlacedPxPos += 4;
|
|
6188
|
-
return returner;
|
|
6189
|
-
};
|
|
6190
|
-
images = [{ width, height }];
|
|
6191
|
-
}
|
|
6192
|
-
for (let imageIndex = 0;imageIndex < images.length; imageIndex++) {
|
|
6193
|
-
if (depth === 8) {
|
|
6194
|
-
rawPos = mapImage8Bit(images[imageIndex], pxData, getPxPos, bpp, data, rawPos);
|
|
6195
|
-
} else {
|
|
6196
|
-
mapImageCustomBit(images[imageIndex], pxData, getPxPos, bpp, bits, maxBit);
|
|
6197
|
-
}
|
|
6198
|
-
}
|
|
6199
|
-
if (depth === 8) {
|
|
6200
|
-
if (rawPos !== data.length) {
|
|
6201
|
-
throw new Error("extra data found");
|
|
6202
|
-
}
|
|
6203
|
-
} else {
|
|
6204
|
-
bits.end();
|
|
6205
|
-
}
|
|
6206
|
-
return pxData;
|
|
6207
|
-
};
|
|
6208
|
-
});
|
|
6209
|
-
|
|
6210
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js
|
|
6211
|
-
var require_format_normaliser = __commonJS((exports, module) => {
|
|
6212
|
-
function dePalette(indata, outdata, width, height, palette) {
|
|
6213
|
-
let pxPos = 0;
|
|
6214
|
-
for (let y = 0;y < height; y++) {
|
|
6215
|
-
for (let x2 = 0;x2 < width; x2++) {
|
|
6216
|
-
let color = palette[indata[pxPos]];
|
|
6217
|
-
if (!color) {
|
|
6218
|
-
throw new Error("index " + indata[pxPos] + " not in palette");
|
|
6219
|
-
}
|
|
6220
|
-
for (let i2 = 0;i2 < 4; i2++) {
|
|
6221
|
-
outdata[pxPos + i2] = color[i2];
|
|
6222
|
-
}
|
|
6223
|
-
pxPos += 4;
|
|
6224
|
-
}
|
|
6225
|
-
}
|
|
6226
|
-
}
|
|
6227
|
-
function replaceTransparentColor(indata, outdata, width, height, transColor) {
|
|
6228
|
-
let pxPos = 0;
|
|
6229
|
-
for (let y = 0;y < height; y++) {
|
|
6230
|
-
for (let x2 = 0;x2 < width; x2++) {
|
|
6231
|
-
let makeTrans = false;
|
|
6232
|
-
if (transColor.length === 1) {
|
|
6233
|
-
if (transColor[0] === indata[pxPos]) {
|
|
6234
|
-
makeTrans = true;
|
|
6235
|
-
}
|
|
6236
|
-
} else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
|
|
6237
|
-
makeTrans = true;
|
|
6238
|
-
}
|
|
6239
|
-
if (makeTrans) {
|
|
6240
|
-
for (let i2 = 0;i2 < 4; i2++) {
|
|
6241
|
-
outdata[pxPos + i2] = 0;
|
|
6242
|
-
}
|
|
6243
|
-
}
|
|
6244
|
-
pxPos += 4;
|
|
6245
|
-
}
|
|
6246
|
-
}
|
|
6247
|
-
}
|
|
6248
|
-
function scaleDepth(indata, outdata, width, height, depth) {
|
|
6249
|
-
let maxOutSample = 255;
|
|
6250
|
-
let maxInSample = Math.pow(2, depth) - 1;
|
|
6251
|
-
let pxPos = 0;
|
|
6252
|
-
for (let y = 0;y < height; y++) {
|
|
6253
|
-
for (let x2 = 0;x2 < width; x2++) {
|
|
6254
|
-
for (let i2 = 0;i2 < 4; i2++) {
|
|
6255
|
-
outdata[pxPos + i2] = Math.floor(indata[pxPos + i2] * maxOutSample / maxInSample + 0.5);
|
|
6256
|
-
}
|
|
6257
|
-
pxPos += 4;
|
|
6258
|
-
}
|
|
6259
|
-
}
|
|
6260
|
-
}
|
|
6261
|
-
module.exports = function(indata, imageData) {
|
|
6262
|
-
let depth = imageData.depth;
|
|
6263
|
-
let width = imageData.width;
|
|
6264
|
-
let height = imageData.height;
|
|
6265
|
-
let colorType = imageData.colorType;
|
|
6266
|
-
let transColor = imageData.transColor;
|
|
6267
|
-
let palette = imageData.palette;
|
|
6268
|
-
let outdata = indata;
|
|
6269
|
-
if (colorType === 3) {
|
|
6270
|
-
dePalette(indata, outdata, width, height, palette);
|
|
6271
|
-
} else {
|
|
6272
|
-
if (transColor) {
|
|
6273
|
-
replaceTransparentColor(indata, outdata, width, height, transColor);
|
|
6274
|
-
}
|
|
6275
|
-
if (depth !== 8) {
|
|
6276
|
-
if (depth === 16) {
|
|
6277
|
-
outdata = Buffer.alloc(width * height * 4);
|
|
6278
|
-
}
|
|
6279
|
-
scaleDepth(indata, outdata, width, height, depth);
|
|
6280
|
-
}
|
|
6281
|
-
}
|
|
6282
|
-
return outdata;
|
|
6283
|
-
};
|
|
6284
|
-
});
|
|
6285
|
-
|
|
6286
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/parser-async.js
|
|
6287
|
-
var require_parser_async = __commonJS((exports, module) => {
|
|
6288
|
-
var util = __require("util");
|
|
6289
|
-
var zlib = __require("zlib");
|
|
6290
|
-
var ChunkStream = require_chunkstream();
|
|
6291
|
-
var FilterAsync = require_filter_parse_async();
|
|
6292
|
-
var Parser = require_parser();
|
|
6293
|
-
var bitmapper = require_bitmapper();
|
|
6294
|
-
var formatNormaliser = require_format_normaliser();
|
|
6295
|
-
var ParserAsync = module.exports = function(options) {
|
|
6296
|
-
ChunkStream.call(this);
|
|
6297
|
-
this._parser = new Parser(options, {
|
|
6298
|
-
read: this.read.bind(this),
|
|
6299
|
-
error: this._handleError.bind(this),
|
|
6300
|
-
metadata: this._handleMetaData.bind(this),
|
|
6301
|
-
gamma: this.emit.bind(this, "gamma"),
|
|
6302
|
-
palette: this._handlePalette.bind(this),
|
|
6303
|
-
transColor: this._handleTransColor.bind(this),
|
|
6304
|
-
finished: this._finished.bind(this),
|
|
6305
|
-
inflateData: this._inflateData.bind(this),
|
|
6306
|
-
simpleTransparency: this._simpleTransparency.bind(this),
|
|
6307
|
-
headersFinished: this._headersFinished.bind(this)
|
|
6308
|
-
});
|
|
6309
|
-
this._options = options;
|
|
6310
|
-
this.writable = true;
|
|
6311
|
-
this._parser.start();
|
|
6312
|
-
};
|
|
6313
|
-
util.inherits(ParserAsync, ChunkStream);
|
|
6314
|
-
ParserAsync.prototype._handleError = function(err) {
|
|
6315
|
-
this.emit("error", err);
|
|
6316
|
-
this.writable = false;
|
|
6317
|
-
this.destroy();
|
|
6318
|
-
if (this._inflate && this._inflate.destroy) {
|
|
6319
|
-
this._inflate.destroy();
|
|
6320
|
-
}
|
|
6321
|
-
if (this._filter) {
|
|
6322
|
-
this._filter.destroy();
|
|
6323
|
-
this._filter.on("error", function() {});
|
|
6324
|
-
}
|
|
6325
|
-
this.errord = true;
|
|
6326
|
-
};
|
|
6327
|
-
ParserAsync.prototype._inflateData = function(data) {
|
|
6328
|
-
if (!this._inflate) {
|
|
6329
|
-
if (this._bitmapInfo.interlace) {
|
|
6330
|
-
this._inflate = zlib.createInflate();
|
|
6331
|
-
this._inflate.on("error", this.emit.bind(this, "error"));
|
|
6332
|
-
this._filter.on("complete", this._complete.bind(this));
|
|
6333
|
-
this._inflate.pipe(this._filter);
|
|
6334
|
-
} else {
|
|
6335
|
-
let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
|
|
6336
|
-
let imageSize = rowSize * this._bitmapInfo.height;
|
|
6337
|
-
let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
|
|
6338
|
-
this._inflate = zlib.createInflate({ chunkSize });
|
|
6339
|
-
let leftToInflate = imageSize;
|
|
6340
|
-
let emitError = this.emit.bind(this, "error");
|
|
6341
|
-
this._inflate.on("error", function(err) {
|
|
6342
|
-
if (!leftToInflate) {
|
|
6343
|
-
return;
|
|
6344
|
-
}
|
|
6345
|
-
emitError(err);
|
|
6346
|
-
});
|
|
6347
|
-
this._filter.on("complete", this._complete.bind(this));
|
|
6348
|
-
let filterWrite = this._filter.write.bind(this._filter);
|
|
6349
|
-
this._inflate.on("data", function(chunk) {
|
|
6350
|
-
if (!leftToInflate) {
|
|
6351
|
-
return;
|
|
6352
|
-
}
|
|
6353
|
-
if (chunk.length > leftToInflate) {
|
|
6354
|
-
chunk = chunk.slice(0, leftToInflate);
|
|
6355
|
-
}
|
|
6356
|
-
leftToInflate -= chunk.length;
|
|
6357
|
-
filterWrite(chunk);
|
|
6358
|
-
});
|
|
6359
|
-
this._inflate.on("end", this._filter.end.bind(this._filter));
|
|
6360
|
-
}
|
|
6361
|
-
}
|
|
6362
|
-
this._inflate.write(data);
|
|
6363
|
-
};
|
|
6364
|
-
ParserAsync.prototype._handleMetaData = function(metaData) {
|
|
6365
|
-
this._metaData = metaData;
|
|
6366
|
-
this._bitmapInfo = Object.create(metaData);
|
|
6367
|
-
this._filter = new FilterAsync(this._bitmapInfo);
|
|
6368
|
-
};
|
|
6369
|
-
ParserAsync.prototype._handleTransColor = function(transColor) {
|
|
6370
|
-
this._bitmapInfo.transColor = transColor;
|
|
6371
|
-
};
|
|
6372
|
-
ParserAsync.prototype._handlePalette = function(palette) {
|
|
6373
|
-
this._bitmapInfo.palette = palette;
|
|
6374
|
-
};
|
|
6375
|
-
ParserAsync.prototype._simpleTransparency = function() {
|
|
6376
|
-
this._metaData.alpha = true;
|
|
6377
|
-
};
|
|
6378
|
-
ParserAsync.prototype._headersFinished = function() {
|
|
6379
|
-
this.emit("metadata", this._metaData);
|
|
6380
|
-
};
|
|
6381
|
-
ParserAsync.prototype._finished = function() {
|
|
6382
|
-
if (this.errord) {
|
|
6383
|
-
return;
|
|
6384
|
-
}
|
|
6385
|
-
if (!this._inflate) {
|
|
6386
|
-
this.emit("error", "No Inflate block");
|
|
6387
|
-
} else {
|
|
6388
|
-
this._inflate.end();
|
|
6389
|
-
}
|
|
6390
|
-
};
|
|
6391
|
-
ParserAsync.prototype._complete = function(filteredData) {
|
|
6392
|
-
if (this.errord) {
|
|
6393
|
-
return;
|
|
6394
|
-
}
|
|
6395
|
-
let normalisedBitmapData;
|
|
6396
|
-
try {
|
|
6397
|
-
let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
|
|
6398
|
-
normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo);
|
|
6399
|
-
bitmapData = null;
|
|
6400
|
-
} catch (ex) {
|
|
6401
|
-
this._handleError(ex);
|
|
6402
|
-
return;
|
|
6403
|
-
}
|
|
6404
|
-
this.emit("parsed", normalisedBitmapData);
|
|
6405
|
-
};
|
|
6406
|
-
});
|
|
6407
|
-
|
|
6408
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js
|
|
6409
|
-
var require_bitpacker = __commonJS((exports, module) => {
|
|
6410
|
-
var constants = require_constants2();
|
|
6411
|
-
module.exports = function(dataIn, width, height, options) {
|
|
6412
|
-
let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(options.colorType) !== -1;
|
|
6413
|
-
if (options.colorType === options.inputColorType) {
|
|
6414
|
-
let bigEndian = function() {
|
|
6415
|
-
let buffer = new ArrayBuffer(2);
|
|
6416
|
-
new DataView(buffer).setInt16(0, 256, true);
|
|
6417
|
-
return new Int16Array(buffer)[0] !== 256;
|
|
6418
|
-
}();
|
|
6419
|
-
if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
|
|
6420
|
-
return dataIn;
|
|
6421
|
-
}
|
|
6422
|
-
}
|
|
6423
|
-
let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
|
|
6424
|
-
let maxValue = 255;
|
|
6425
|
-
let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
|
|
6426
|
-
if (inBpp === 4 && !options.inputHasAlpha) {
|
|
6427
|
-
inBpp = 3;
|
|
6428
|
-
}
|
|
6429
|
-
let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
|
|
6430
|
-
if (options.bitDepth === 16) {
|
|
6431
|
-
maxValue = 65535;
|
|
6432
|
-
outBpp *= 2;
|
|
6433
|
-
}
|
|
6434
|
-
let outData = Buffer.alloc(width * height * outBpp);
|
|
6435
|
-
let inIndex = 0;
|
|
6436
|
-
let outIndex = 0;
|
|
6437
|
-
let bgColor = options.bgColor || {};
|
|
6438
|
-
if (bgColor.red === undefined) {
|
|
6439
|
-
bgColor.red = maxValue;
|
|
6440
|
-
}
|
|
6441
|
-
if (bgColor.green === undefined) {
|
|
6442
|
-
bgColor.green = maxValue;
|
|
6443
|
-
}
|
|
6444
|
-
if (bgColor.blue === undefined) {
|
|
6445
|
-
bgColor.blue = maxValue;
|
|
6446
|
-
}
|
|
6447
|
-
function getRGBA() {
|
|
6448
|
-
let red;
|
|
6449
|
-
let green;
|
|
6450
|
-
let blue;
|
|
6451
|
-
let alpha = maxValue;
|
|
6452
|
-
switch (options.inputColorType) {
|
|
6453
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
6454
|
-
alpha = data[inIndex + 3];
|
|
6455
|
-
red = data[inIndex];
|
|
6456
|
-
green = data[inIndex + 1];
|
|
6457
|
-
blue = data[inIndex + 2];
|
|
6458
|
-
break;
|
|
6459
|
-
case constants.COLORTYPE_COLOR:
|
|
6460
|
-
red = data[inIndex];
|
|
6461
|
-
green = data[inIndex + 1];
|
|
6462
|
-
blue = data[inIndex + 2];
|
|
6463
|
-
break;
|
|
6464
|
-
case constants.COLORTYPE_ALPHA:
|
|
6465
|
-
alpha = data[inIndex + 1];
|
|
6466
|
-
red = data[inIndex];
|
|
6467
|
-
green = red;
|
|
6468
|
-
blue = red;
|
|
6469
|
-
break;
|
|
6470
|
-
case constants.COLORTYPE_GRAYSCALE:
|
|
6471
|
-
red = data[inIndex];
|
|
6472
|
-
green = red;
|
|
6473
|
-
blue = red;
|
|
6474
|
-
break;
|
|
6475
|
-
default:
|
|
6476
|
-
throw new Error("input color type:" + options.inputColorType + " is not supported at present");
|
|
6477
|
-
}
|
|
6478
|
-
if (options.inputHasAlpha) {
|
|
6479
|
-
if (!outHasAlpha) {
|
|
6480
|
-
alpha /= maxValue;
|
|
6481
|
-
red = Math.min(Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0), maxValue);
|
|
6482
|
-
green = Math.min(Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0), maxValue);
|
|
6483
|
-
blue = Math.min(Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0), maxValue);
|
|
6484
|
-
}
|
|
6485
|
-
}
|
|
6486
|
-
return { red, green, blue, alpha };
|
|
6487
|
-
}
|
|
6488
|
-
for (let y = 0;y < height; y++) {
|
|
6489
|
-
for (let x2 = 0;x2 < width; x2++) {
|
|
6490
|
-
let rgba = getRGBA(data, inIndex);
|
|
6491
|
-
switch (options.colorType) {
|
|
6492
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
6493
|
-
case constants.COLORTYPE_COLOR:
|
|
6494
|
-
if (options.bitDepth === 8) {
|
|
6495
|
-
outData[outIndex] = rgba.red;
|
|
6496
|
-
outData[outIndex + 1] = rgba.green;
|
|
6497
|
-
outData[outIndex + 2] = rgba.blue;
|
|
6498
|
-
if (outHasAlpha) {
|
|
6499
|
-
outData[outIndex + 3] = rgba.alpha;
|
|
6500
|
-
}
|
|
6501
|
-
} else {
|
|
6502
|
-
outData.writeUInt16BE(rgba.red, outIndex);
|
|
6503
|
-
outData.writeUInt16BE(rgba.green, outIndex + 2);
|
|
6504
|
-
outData.writeUInt16BE(rgba.blue, outIndex + 4);
|
|
6505
|
-
if (outHasAlpha) {
|
|
6506
|
-
outData.writeUInt16BE(rgba.alpha, outIndex + 6);
|
|
6507
|
-
}
|
|
6508
|
-
}
|
|
6509
|
-
break;
|
|
6510
|
-
case constants.COLORTYPE_ALPHA:
|
|
6511
|
-
case constants.COLORTYPE_GRAYSCALE: {
|
|
6512
|
-
let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
|
|
6513
|
-
if (options.bitDepth === 8) {
|
|
6514
|
-
outData[outIndex] = grayscale;
|
|
6515
|
-
if (outHasAlpha) {
|
|
6516
|
-
outData[outIndex + 1] = rgba.alpha;
|
|
6517
|
-
}
|
|
6518
|
-
} else {
|
|
6519
|
-
outData.writeUInt16BE(grayscale, outIndex);
|
|
6520
|
-
if (outHasAlpha) {
|
|
6521
|
-
outData.writeUInt16BE(rgba.alpha, outIndex + 2);
|
|
6522
|
-
}
|
|
6523
|
-
}
|
|
6524
|
-
break;
|
|
6525
|
-
}
|
|
6526
|
-
default:
|
|
6527
|
-
throw new Error("unrecognised color Type " + options.colorType);
|
|
6528
|
-
}
|
|
6529
|
-
inIndex += inBpp;
|
|
6530
|
-
outIndex += outBpp;
|
|
6531
|
-
}
|
|
6532
|
-
}
|
|
6533
|
-
return outData;
|
|
6534
|
-
};
|
|
6535
|
-
});
|
|
6536
|
-
|
|
6537
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/filter-pack.js
|
|
6538
|
-
var require_filter_pack = __commonJS((exports, module) => {
|
|
6539
|
-
var paethPredictor = require_paeth_predictor();
|
|
6540
|
-
function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
6541
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
6542
|
-
rawData[rawPos + x2] = pxData[pxPos + x2];
|
|
6543
|
-
}
|
|
6544
|
-
}
|
|
6545
|
-
function filterSumNone(pxData, pxPos, byteWidth) {
|
|
6546
|
-
let sum = 0;
|
|
6547
|
-
let length = pxPos + byteWidth;
|
|
6548
|
-
for (let i2 = pxPos;i2 < length; i2++) {
|
|
6549
|
-
sum += Math.abs(pxData[i2]);
|
|
6550
|
-
}
|
|
6551
|
-
return sum;
|
|
6552
|
-
}
|
|
6553
|
-
function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
6554
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
6555
|
-
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
6556
|
-
let val = pxData[pxPos + x2] - left;
|
|
6557
|
-
rawData[rawPos + x2] = val;
|
|
6558
|
-
}
|
|
6559
|
-
}
|
|
6560
|
-
function filterSumSub(pxData, pxPos, byteWidth, bpp) {
|
|
6561
|
-
let sum = 0;
|
|
6562
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
6563
|
-
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
6564
|
-
let val = pxData[pxPos + x2] - left;
|
|
6565
|
-
sum += Math.abs(val);
|
|
6566
|
-
}
|
|
6567
|
-
return sum;
|
|
6568
|
-
}
|
|
6569
|
-
function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
6570
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
6571
|
-
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
6572
|
-
let val = pxData[pxPos + x2] - up;
|
|
6573
|
-
rawData[rawPos + x2] = val;
|
|
6574
|
-
}
|
|
6575
|
-
}
|
|
6576
|
-
function filterSumUp(pxData, pxPos, byteWidth) {
|
|
6577
|
-
let sum = 0;
|
|
6578
|
-
let length = pxPos + byteWidth;
|
|
6579
|
-
for (let x2 = pxPos;x2 < length; x2++) {
|
|
6580
|
-
let up = pxPos > 0 ? pxData[x2 - byteWidth] : 0;
|
|
6581
|
-
let val = pxData[x2] - up;
|
|
6582
|
-
sum += Math.abs(val);
|
|
6583
|
-
}
|
|
6584
|
-
return sum;
|
|
6585
|
-
}
|
|
6586
|
-
function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
6587
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
6588
|
-
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
6589
|
-
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
6590
|
-
let val = pxData[pxPos + x2] - (left + up >> 1);
|
|
6591
|
-
rawData[rawPos + x2] = val;
|
|
6592
|
-
}
|
|
6593
|
-
}
|
|
6594
|
-
function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
|
|
6595
|
-
let sum = 0;
|
|
6596
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
6597
|
-
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
6598
|
-
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
6599
|
-
let val = pxData[pxPos + x2] - (left + up >> 1);
|
|
6600
|
-
sum += Math.abs(val);
|
|
6601
|
-
}
|
|
6602
|
-
return sum;
|
|
6603
|
-
}
|
|
6604
|
-
function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
6605
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
6606
|
-
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
6607
|
-
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
6608
|
-
let upleft = pxPos > 0 && x2 >= bpp ? pxData[pxPos + x2 - (byteWidth + bpp)] : 0;
|
|
6609
|
-
let val = pxData[pxPos + x2] - paethPredictor(left, up, upleft);
|
|
6610
|
-
rawData[rawPos + x2] = val;
|
|
6611
|
-
}
|
|
6612
|
-
}
|
|
6613
|
-
function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
|
|
6614
|
-
let sum = 0;
|
|
6615
|
-
for (let x2 = 0;x2 < byteWidth; x2++) {
|
|
6616
|
-
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
6617
|
-
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
6618
|
-
let upleft = pxPos > 0 && x2 >= bpp ? pxData[pxPos + x2 - (byteWidth + bpp)] : 0;
|
|
6619
|
-
let val = pxData[pxPos + x2] - paethPredictor(left, up, upleft);
|
|
6620
|
-
sum += Math.abs(val);
|
|
6621
|
-
}
|
|
6622
|
-
return sum;
|
|
6623
|
-
}
|
|
6624
|
-
var filters = {
|
|
6625
|
-
0: filterNone,
|
|
6626
|
-
1: filterSub,
|
|
6627
|
-
2: filterUp,
|
|
6628
|
-
3: filterAvg,
|
|
6629
|
-
4: filterPaeth
|
|
6630
|
-
};
|
|
6631
|
-
var filterSums = {
|
|
6632
|
-
0: filterSumNone,
|
|
6633
|
-
1: filterSumSub,
|
|
6634
|
-
2: filterSumUp,
|
|
6635
|
-
3: filterSumAvg,
|
|
6636
|
-
4: filterSumPaeth
|
|
6637
|
-
};
|
|
6638
|
-
module.exports = function(pxData, width, height, options, bpp) {
|
|
6639
|
-
let filterTypes;
|
|
6640
|
-
if (!("filterType" in options) || options.filterType === -1) {
|
|
6641
|
-
filterTypes = [0, 1, 2, 3, 4];
|
|
6642
|
-
} else if (typeof options.filterType === "number") {
|
|
6643
|
-
filterTypes = [options.filterType];
|
|
6644
|
-
} else {
|
|
6645
|
-
throw new Error("unrecognised filter types");
|
|
6646
|
-
}
|
|
6647
|
-
if (options.bitDepth === 16) {
|
|
6648
|
-
bpp *= 2;
|
|
6649
|
-
}
|
|
6650
|
-
let byteWidth = width * bpp;
|
|
6651
|
-
let rawPos = 0;
|
|
6652
|
-
let pxPos = 0;
|
|
6653
|
-
let rawData = Buffer.alloc((byteWidth + 1) * height);
|
|
6654
|
-
let sel = filterTypes[0];
|
|
6655
|
-
for (let y = 0;y < height; y++) {
|
|
6656
|
-
if (filterTypes.length > 1) {
|
|
6657
|
-
let min = Infinity;
|
|
6658
|
-
for (let i2 = 0;i2 < filterTypes.length; i2++) {
|
|
6659
|
-
let sum = filterSums[filterTypes[i2]](pxData, pxPos, byteWidth, bpp);
|
|
6660
|
-
if (sum < min) {
|
|
6661
|
-
sel = filterTypes[i2];
|
|
6662
|
-
min = sum;
|
|
6663
|
-
}
|
|
6664
|
-
}
|
|
6665
|
-
}
|
|
6666
|
-
rawData[rawPos] = sel;
|
|
6667
|
-
rawPos++;
|
|
6668
|
-
filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
|
|
6669
|
-
rawPos += byteWidth;
|
|
6670
|
-
pxPos += byteWidth;
|
|
6671
|
-
}
|
|
6672
|
-
return rawData;
|
|
6673
|
-
};
|
|
6674
|
-
});
|
|
6675
|
-
|
|
6676
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/packer.js
|
|
6677
|
-
var require_packer = __commonJS((exports, module) => {
|
|
6678
|
-
var constants = require_constants2();
|
|
6679
|
-
var CrcStream = require_crc();
|
|
6680
|
-
var bitPacker = require_bitpacker();
|
|
6681
|
-
var filter = require_filter_pack();
|
|
6682
|
-
var zlib = __require("zlib");
|
|
6683
|
-
var Packer = module.exports = function(options) {
|
|
6684
|
-
this._options = options;
|
|
6685
|
-
options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
|
|
6686
|
-
options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
|
|
6687
|
-
options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
|
|
6688
|
-
options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
|
|
6689
|
-
options.deflateFactory = options.deflateFactory || zlib.createDeflate;
|
|
6690
|
-
options.bitDepth = options.bitDepth || 8;
|
|
6691
|
-
options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
6692
|
-
options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
6693
|
-
if ([
|
|
6694
|
-
constants.COLORTYPE_GRAYSCALE,
|
|
6695
|
-
constants.COLORTYPE_COLOR,
|
|
6696
|
-
constants.COLORTYPE_COLOR_ALPHA,
|
|
6697
|
-
constants.COLORTYPE_ALPHA
|
|
6698
|
-
].indexOf(options.colorType) === -1) {
|
|
6699
|
-
throw new Error("option color type:" + options.colorType + " is not supported at present");
|
|
6700
|
-
}
|
|
6701
|
-
if ([
|
|
6702
|
-
constants.COLORTYPE_GRAYSCALE,
|
|
6703
|
-
constants.COLORTYPE_COLOR,
|
|
6704
|
-
constants.COLORTYPE_COLOR_ALPHA,
|
|
6705
|
-
constants.COLORTYPE_ALPHA
|
|
6706
|
-
].indexOf(options.inputColorType) === -1) {
|
|
6707
|
-
throw new Error("option input color type:" + options.inputColorType + " is not supported at present");
|
|
6708
|
-
}
|
|
6709
|
-
if (options.bitDepth !== 8 && options.bitDepth !== 16) {
|
|
6710
|
-
throw new Error("option bit depth:" + options.bitDepth + " is not supported at present");
|
|
6711
|
-
}
|
|
6712
|
-
};
|
|
6713
|
-
Packer.prototype.getDeflateOptions = function() {
|
|
6714
|
-
return {
|
|
6715
|
-
chunkSize: this._options.deflateChunkSize,
|
|
6716
|
-
level: this._options.deflateLevel,
|
|
6717
|
-
strategy: this._options.deflateStrategy
|
|
6718
|
-
};
|
|
6719
|
-
};
|
|
6720
|
-
Packer.prototype.createDeflate = function() {
|
|
6721
|
-
return this._options.deflateFactory(this.getDeflateOptions());
|
|
6722
|
-
};
|
|
6723
|
-
Packer.prototype.filterData = function(data, width, height) {
|
|
6724
|
-
let packedData = bitPacker(data, width, height, this._options);
|
|
6725
|
-
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
|
|
6726
|
-
let filteredData = filter(packedData, width, height, this._options, bpp);
|
|
6727
|
-
return filteredData;
|
|
6728
|
-
};
|
|
6729
|
-
Packer.prototype._packChunk = function(type, data) {
|
|
6730
|
-
let len = data ? data.length : 0;
|
|
6731
|
-
let buf = Buffer.alloc(len + 12);
|
|
6732
|
-
buf.writeUInt32BE(len, 0);
|
|
6733
|
-
buf.writeUInt32BE(type, 4);
|
|
6734
|
-
if (data) {
|
|
6735
|
-
data.copy(buf, 8);
|
|
6736
|
-
}
|
|
6737
|
-
buf.writeInt32BE(CrcStream.crc32(buf.slice(4, buf.length - 4)), buf.length - 4);
|
|
6738
|
-
return buf;
|
|
6739
|
-
};
|
|
6740
|
-
Packer.prototype.packGAMA = function(gamma) {
|
|
6741
|
-
let buf = Buffer.alloc(4);
|
|
6742
|
-
buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
|
|
6743
|
-
return this._packChunk(constants.TYPE_gAMA, buf);
|
|
6744
|
-
};
|
|
6745
|
-
Packer.prototype.packIHDR = function(width, height) {
|
|
6746
|
-
let buf = Buffer.alloc(13);
|
|
6747
|
-
buf.writeUInt32BE(width, 0);
|
|
6748
|
-
buf.writeUInt32BE(height, 4);
|
|
6749
|
-
buf[8] = this._options.bitDepth;
|
|
6750
|
-
buf[9] = this._options.colorType;
|
|
6751
|
-
buf[10] = 0;
|
|
6752
|
-
buf[11] = 0;
|
|
6753
|
-
buf[12] = 0;
|
|
6754
|
-
return this._packChunk(constants.TYPE_IHDR, buf);
|
|
6755
|
-
};
|
|
6756
|
-
Packer.prototype.packIDAT = function(data) {
|
|
6757
|
-
return this._packChunk(constants.TYPE_IDAT, data);
|
|
6758
|
-
};
|
|
6759
|
-
Packer.prototype.packIEND = function() {
|
|
6760
|
-
return this._packChunk(constants.TYPE_IEND, null);
|
|
6761
|
-
};
|
|
6762
|
-
});
|
|
6763
|
-
|
|
6764
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js
|
|
6765
|
-
var require_packer_async = __commonJS((exports, module) => {
|
|
6766
|
-
var util = __require("util");
|
|
6767
|
-
var Stream = __require("stream");
|
|
6768
|
-
var constants = require_constants2();
|
|
6769
|
-
var Packer = require_packer();
|
|
6770
|
-
var PackerAsync = module.exports = function(opt) {
|
|
6771
|
-
Stream.call(this);
|
|
6772
|
-
let options = opt || {};
|
|
6773
|
-
this._packer = new Packer(options);
|
|
6774
|
-
this._deflate = this._packer.createDeflate();
|
|
6775
|
-
this.readable = true;
|
|
6776
|
-
};
|
|
6777
|
-
util.inherits(PackerAsync, Stream);
|
|
6778
|
-
PackerAsync.prototype.pack = function(data, width, height, gamma) {
|
|
6779
|
-
this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
|
|
6780
|
-
this.emit("data", this._packer.packIHDR(width, height));
|
|
6781
|
-
if (gamma) {
|
|
6782
|
-
this.emit("data", this._packer.packGAMA(gamma));
|
|
6783
|
-
}
|
|
6784
|
-
let filteredData = this._packer.filterData(data, width, height);
|
|
6785
|
-
this._deflate.on("error", this.emit.bind(this, "error"));
|
|
6786
|
-
this._deflate.on("data", function(compressedData) {
|
|
6787
|
-
this.emit("data", this._packer.packIDAT(compressedData));
|
|
6788
|
-
}.bind(this));
|
|
6789
|
-
this._deflate.on("end", function() {
|
|
6790
|
-
this.emit("data", this._packer.packIEND());
|
|
6791
|
-
this.emit("end");
|
|
6792
|
-
}.bind(this));
|
|
6793
|
-
this._deflate.end(filteredData);
|
|
6794
|
-
};
|
|
6795
|
-
});
|
|
6796
|
-
|
|
6797
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/sync-inflate.js
|
|
6798
|
-
var require_sync_inflate = __commonJS((exports, module) => {
|
|
6799
|
-
var assert = __require("assert").ok;
|
|
6800
|
-
var zlib = __require("zlib");
|
|
6801
|
-
var util = __require("util");
|
|
6802
|
-
var kMaxLength = __require("buffer").kMaxLength;
|
|
6803
|
-
function Inflate(opts) {
|
|
6804
|
-
if (!(this instanceof Inflate)) {
|
|
6805
|
-
return new Inflate(opts);
|
|
6806
|
-
}
|
|
6807
|
-
if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
|
|
6808
|
-
opts.chunkSize = zlib.Z_MIN_CHUNK;
|
|
6809
|
-
}
|
|
6810
|
-
zlib.Inflate.call(this, opts);
|
|
6811
|
-
this._offset = this._offset === undefined ? this._outOffset : this._offset;
|
|
6812
|
-
this._buffer = this._buffer || this._outBuffer;
|
|
6813
|
-
if (opts && opts.maxLength != null) {
|
|
6814
|
-
this._maxLength = opts.maxLength;
|
|
6815
|
-
}
|
|
6816
|
-
}
|
|
6817
|
-
function createInflate(opts) {
|
|
6818
|
-
return new Inflate(opts);
|
|
6819
|
-
}
|
|
6820
|
-
function _close(engine, callback) {
|
|
6821
|
-
if (callback) {
|
|
6822
|
-
process.nextTick(callback);
|
|
6823
|
-
}
|
|
6824
|
-
if (!engine._handle) {
|
|
6825
|
-
return;
|
|
6826
|
-
}
|
|
6827
|
-
engine._handle.close();
|
|
6828
|
-
engine._handle = null;
|
|
6829
|
-
}
|
|
6830
|
-
Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
|
|
6831
|
-
if (typeof asyncCb === "function") {
|
|
6832
|
-
return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
|
|
6833
|
-
}
|
|
6834
|
-
let self = this;
|
|
6835
|
-
let availInBefore = chunk && chunk.length;
|
|
6836
|
-
let availOutBefore = this._chunkSize - this._offset;
|
|
6837
|
-
let leftToInflate = this._maxLength;
|
|
6838
|
-
let inOff = 0;
|
|
6839
|
-
let buffers = [];
|
|
6840
|
-
let nread = 0;
|
|
6841
|
-
let error;
|
|
6842
|
-
this.on("error", function(err) {
|
|
6843
|
-
error = err;
|
|
6844
|
-
});
|
|
6845
|
-
function handleChunk(availInAfter, availOutAfter) {
|
|
6846
|
-
if (self._hadError) {
|
|
6847
|
-
return;
|
|
6848
|
-
}
|
|
6849
|
-
let have = availOutBefore - availOutAfter;
|
|
6850
|
-
assert(have >= 0, "have should not go down");
|
|
6851
|
-
if (have > 0) {
|
|
6852
|
-
let out = self._buffer.slice(self._offset, self._offset + have);
|
|
6853
|
-
self._offset += have;
|
|
6854
|
-
if (out.length > leftToInflate) {
|
|
6855
|
-
out = out.slice(0, leftToInflate);
|
|
6856
|
-
}
|
|
6857
|
-
buffers.push(out);
|
|
6858
|
-
nread += out.length;
|
|
6859
|
-
leftToInflate -= out.length;
|
|
6860
|
-
if (leftToInflate === 0) {
|
|
6861
|
-
return false;
|
|
6862
|
-
}
|
|
6863
|
-
}
|
|
6864
|
-
if (availOutAfter === 0 || self._offset >= self._chunkSize) {
|
|
6865
|
-
availOutBefore = self._chunkSize;
|
|
6866
|
-
self._offset = 0;
|
|
6867
|
-
self._buffer = Buffer.allocUnsafe(self._chunkSize);
|
|
6868
|
-
}
|
|
6869
|
-
if (availOutAfter === 0) {
|
|
6870
|
-
inOff += availInBefore - availInAfter;
|
|
6871
|
-
availInBefore = availInAfter;
|
|
6872
|
-
return true;
|
|
6873
|
-
}
|
|
6874
|
-
return false;
|
|
6875
|
-
}
|
|
6876
|
-
assert(this._handle, "zlib binding closed");
|
|
6877
|
-
let res;
|
|
6878
|
-
do {
|
|
6879
|
-
res = this._handle.writeSync(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, availOutBefore);
|
|
6880
|
-
res = res || this._writeState;
|
|
6881
|
-
} while (!this._hadError && handleChunk(res[0], res[1]));
|
|
6882
|
-
if (this._hadError) {
|
|
6883
|
-
throw error;
|
|
6884
|
-
}
|
|
6885
|
-
if (nread >= kMaxLength) {
|
|
6886
|
-
_close(this);
|
|
6887
|
-
throw new RangeError("Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes");
|
|
6888
|
-
}
|
|
6889
|
-
let buf = Buffer.concat(buffers, nread);
|
|
6890
|
-
_close(this);
|
|
6891
|
-
return buf;
|
|
6892
|
-
};
|
|
6893
|
-
util.inherits(Inflate, zlib.Inflate);
|
|
6894
|
-
function zlibBufferSync(engine, buffer) {
|
|
6895
|
-
if (typeof buffer === "string") {
|
|
6896
|
-
buffer = Buffer.from(buffer);
|
|
6897
|
-
}
|
|
6898
|
-
if (!(buffer instanceof Buffer)) {
|
|
6899
|
-
throw new TypeError("Not a string or buffer");
|
|
6900
|
-
}
|
|
6901
|
-
let flushFlag = engine._finishFlushFlag;
|
|
6902
|
-
if (flushFlag == null) {
|
|
6903
|
-
flushFlag = zlib.Z_FINISH;
|
|
6904
|
-
}
|
|
6905
|
-
return engine._processChunk(buffer, flushFlag);
|
|
6906
|
-
}
|
|
6907
|
-
function inflateSync(buffer, opts) {
|
|
6908
|
-
return zlibBufferSync(new Inflate(opts), buffer);
|
|
6909
|
-
}
|
|
6910
|
-
module.exports = exports = inflateSync;
|
|
6911
|
-
exports.Inflate = Inflate;
|
|
6912
|
-
exports.createInflate = createInflate;
|
|
6913
|
-
exports.inflateSync = inflateSync;
|
|
6914
|
-
});
|
|
6915
|
-
|
|
6916
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js
|
|
6917
|
-
var require_sync_reader = __commonJS((exports, module) => {
|
|
6918
|
-
var SyncReader = module.exports = function(buffer) {
|
|
6919
|
-
this._buffer = buffer;
|
|
6920
|
-
this._reads = [];
|
|
6921
|
-
};
|
|
6922
|
-
SyncReader.prototype.read = function(length, callback) {
|
|
6923
|
-
this._reads.push({
|
|
6924
|
-
length: Math.abs(length),
|
|
6925
|
-
allowLess: length < 0,
|
|
6926
|
-
func: callback
|
|
6927
|
-
});
|
|
6928
|
-
};
|
|
6929
|
-
SyncReader.prototype.process = function() {
|
|
6930
|
-
while (this._reads.length > 0 && this._buffer.length) {
|
|
6931
|
-
let read = this._reads[0];
|
|
6932
|
-
if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
|
|
6933
|
-
this._reads.shift();
|
|
6934
|
-
let buf = this._buffer;
|
|
6935
|
-
this._buffer = buf.slice(read.length);
|
|
6936
|
-
read.func.call(this, buf.slice(0, read.length));
|
|
6937
|
-
} else {
|
|
6938
|
-
break;
|
|
6939
|
-
}
|
|
6940
|
-
}
|
|
6941
|
-
if (this._reads.length > 0) {
|
|
6942
|
-
return new Error("There are some read requests waitng on finished stream");
|
|
6943
|
-
}
|
|
6944
|
-
if (this._buffer.length > 0) {
|
|
6945
|
-
return new Error("unrecognised content at end of stream");
|
|
6946
|
-
}
|
|
6947
|
-
};
|
|
6948
|
-
});
|
|
6949
|
-
|
|
6950
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-sync.js
|
|
6951
|
-
var require_filter_parse_sync = __commonJS((exports) => {
|
|
6952
|
-
var SyncReader = require_sync_reader();
|
|
6953
|
-
var Filter = require_filter_parse();
|
|
6954
|
-
exports.process = function(inBuffer, bitmapInfo) {
|
|
6955
|
-
let outBuffers = [];
|
|
6956
|
-
let reader = new SyncReader(inBuffer);
|
|
6957
|
-
let filter = new Filter(bitmapInfo, {
|
|
6958
|
-
read: reader.read.bind(reader),
|
|
6959
|
-
write: function(bufferPart) {
|
|
6960
|
-
outBuffers.push(bufferPart);
|
|
6961
|
-
},
|
|
6962
|
-
complete: function() {}
|
|
6963
|
-
});
|
|
6964
|
-
filter.start();
|
|
6965
|
-
reader.process();
|
|
6966
|
-
return Buffer.concat(outBuffers);
|
|
6967
|
-
};
|
|
6968
|
-
});
|
|
6969
|
-
|
|
6970
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/parser-sync.js
|
|
6971
|
-
var require_parser_sync = __commonJS((exports, module) => {
|
|
6972
|
-
var hasSyncZlib = true;
|
|
6973
|
-
var zlib = __require("zlib");
|
|
6974
|
-
var inflateSync = require_sync_inflate();
|
|
6975
|
-
if (!zlib.deflateSync) {
|
|
6976
|
-
hasSyncZlib = false;
|
|
6977
|
-
}
|
|
6978
|
-
var SyncReader = require_sync_reader();
|
|
6979
|
-
var FilterSync = require_filter_parse_sync();
|
|
6980
|
-
var Parser = require_parser();
|
|
6981
|
-
var bitmapper = require_bitmapper();
|
|
6982
|
-
var formatNormaliser = require_format_normaliser();
|
|
6983
|
-
module.exports = function(buffer, options) {
|
|
6984
|
-
if (!hasSyncZlib) {
|
|
6985
|
-
throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");
|
|
6986
|
-
}
|
|
6987
|
-
let err;
|
|
6988
|
-
function handleError(_err_) {
|
|
6989
|
-
err = _err_;
|
|
6990
|
-
}
|
|
6991
|
-
let metaData;
|
|
6992
|
-
function handleMetaData(_metaData_) {
|
|
6993
|
-
metaData = _metaData_;
|
|
6994
|
-
}
|
|
6995
|
-
function handleTransColor(transColor) {
|
|
6996
|
-
metaData.transColor = transColor;
|
|
6997
|
-
}
|
|
6998
|
-
function handlePalette(palette) {
|
|
6999
|
-
metaData.palette = palette;
|
|
7000
|
-
}
|
|
7001
|
-
function handleSimpleTransparency() {
|
|
7002
|
-
metaData.alpha = true;
|
|
7003
|
-
}
|
|
7004
|
-
let gamma;
|
|
7005
|
-
function handleGamma(_gamma_) {
|
|
7006
|
-
gamma = _gamma_;
|
|
7007
|
-
}
|
|
7008
|
-
let inflateDataList = [];
|
|
7009
|
-
function handleInflateData(inflatedData2) {
|
|
7010
|
-
inflateDataList.push(inflatedData2);
|
|
7011
|
-
}
|
|
7012
|
-
let reader = new SyncReader(buffer);
|
|
7013
|
-
let parser = new Parser(options, {
|
|
7014
|
-
read: reader.read.bind(reader),
|
|
7015
|
-
error: handleError,
|
|
7016
|
-
metadata: handleMetaData,
|
|
7017
|
-
gamma: handleGamma,
|
|
7018
|
-
palette: handlePalette,
|
|
7019
|
-
transColor: handleTransColor,
|
|
7020
|
-
inflateData: handleInflateData,
|
|
7021
|
-
simpleTransparency: handleSimpleTransparency
|
|
7022
|
-
});
|
|
7023
|
-
parser.start();
|
|
7024
|
-
reader.process();
|
|
7025
|
-
if (err) {
|
|
7026
|
-
throw err;
|
|
7027
|
-
}
|
|
7028
|
-
let inflateData = Buffer.concat(inflateDataList);
|
|
7029
|
-
inflateDataList.length = 0;
|
|
7030
|
-
let inflatedData;
|
|
7031
|
-
if (metaData.interlace) {
|
|
7032
|
-
inflatedData = zlib.inflateSync(inflateData);
|
|
7033
|
-
} else {
|
|
7034
|
-
let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
|
|
7035
|
-
let imageSize = rowSize * metaData.height;
|
|
7036
|
-
inflatedData = inflateSync(inflateData, {
|
|
7037
|
-
chunkSize: imageSize,
|
|
7038
|
-
maxLength: imageSize
|
|
7039
|
-
});
|
|
7040
|
-
}
|
|
7041
|
-
inflateData = null;
|
|
7042
|
-
if (!inflatedData || !inflatedData.length) {
|
|
7043
|
-
throw new Error("bad png - invalid inflate data response");
|
|
7044
|
-
}
|
|
7045
|
-
let unfilteredData = FilterSync.process(inflatedData, metaData);
|
|
7046
|
-
inflateData = null;
|
|
7047
|
-
let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
|
|
7048
|
-
unfilteredData = null;
|
|
7049
|
-
let normalisedBitmapData = formatNormaliser(bitmapData, metaData);
|
|
7050
|
-
metaData.data = normalisedBitmapData;
|
|
7051
|
-
metaData.gamma = gamma || 0;
|
|
7052
|
-
return metaData;
|
|
7053
|
-
};
|
|
7054
|
-
});
|
|
7055
|
-
|
|
7056
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/packer-sync.js
|
|
7057
|
-
var require_packer_sync = __commonJS((exports, module) => {
|
|
7058
|
-
var hasSyncZlib = true;
|
|
7059
|
-
var zlib = __require("zlib");
|
|
7060
|
-
if (!zlib.deflateSync) {
|
|
7061
|
-
hasSyncZlib = false;
|
|
7062
|
-
}
|
|
7063
|
-
var constants = require_constants2();
|
|
7064
|
-
var Packer = require_packer();
|
|
7065
|
-
module.exports = function(metaData, opt) {
|
|
7066
|
-
if (!hasSyncZlib) {
|
|
7067
|
-
throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");
|
|
7068
|
-
}
|
|
7069
|
-
let options = opt || {};
|
|
7070
|
-
let packer = new Packer(options);
|
|
7071
|
-
let chunks = [];
|
|
7072
|
-
chunks.push(Buffer.from(constants.PNG_SIGNATURE));
|
|
7073
|
-
chunks.push(packer.packIHDR(metaData.width, metaData.height));
|
|
7074
|
-
if (metaData.gamma) {
|
|
7075
|
-
chunks.push(packer.packGAMA(metaData.gamma));
|
|
7076
|
-
}
|
|
7077
|
-
let filteredData = packer.filterData(metaData.data, metaData.width, metaData.height);
|
|
7078
|
-
let compressedData = zlib.deflateSync(filteredData, packer.getDeflateOptions());
|
|
7079
|
-
filteredData = null;
|
|
7080
|
-
if (!compressedData || !compressedData.length) {
|
|
7081
|
-
throw new Error("bad png - invalid compressed data response");
|
|
7082
|
-
}
|
|
7083
|
-
chunks.push(packer.packIDAT(compressedData));
|
|
7084
|
-
chunks.push(packer.packIEND());
|
|
7085
|
-
return Buffer.concat(chunks);
|
|
7086
|
-
};
|
|
7087
|
-
});
|
|
7088
|
-
|
|
7089
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js
|
|
7090
|
-
var require_png_sync = __commonJS((exports) => {
|
|
7091
|
-
var parse = require_parser_sync();
|
|
7092
|
-
var pack = require_packer_sync();
|
|
7093
|
-
exports.read = function(buffer, options) {
|
|
7094
|
-
return parse(buffer, options || {});
|
|
7095
|
-
};
|
|
7096
|
-
exports.write = function(png, options) {
|
|
7097
|
-
return pack(png, options);
|
|
7098
|
-
};
|
|
7099
|
-
});
|
|
7100
|
-
|
|
7101
|
-
// ../../node_modules/.bun/pngjs@5.0.0/node_modules/pngjs/lib/png.js
|
|
7102
|
-
var require_png = __commonJS((exports) => {
|
|
7103
|
-
var util = __require("util");
|
|
7104
|
-
var Stream = __require("stream");
|
|
7105
|
-
var Parser = require_parser_async();
|
|
7106
|
-
var Packer = require_packer_async();
|
|
7107
|
-
var PNGSync = require_png_sync();
|
|
7108
|
-
var PNG = exports.PNG = function(options) {
|
|
7109
|
-
Stream.call(this);
|
|
7110
|
-
options = options || {};
|
|
7111
|
-
this.width = options.width | 0;
|
|
7112
|
-
this.height = options.height | 0;
|
|
7113
|
-
this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
|
|
7114
|
-
if (options.fill && this.data) {
|
|
7115
|
-
this.data.fill(0);
|
|
7116
|
-
}
|
|
7117
|
-
this.gamma = 0;
|
|
7118
|
-
this.readable = this.writable = true;
|
|
7119
|
-
this._parser = new Parser(options);
|
|
7120
|
-
this._parser.on("error", this.emit.bind(this, "error"));
|
|
7121
|
-
this._parser.on("close", this._handleClose.bind(this));
|
|
7122
|
-
this._parser.on("metadata", this._metadata.bind(this));
|
|
7123
|
-
this._parser.on("gamma", this._gamma.bind(this));
|
|
7124
|
-
this._parser.on("parsed", function(data) {
|
|
7125
|
-
this.data = data;
|
|
7126
|
-
this.emit("parsed", data);
|
|
7127
|
-
}.bind(this));
|
|
7128
|
-
this._packer = new Packer(options);
|
|
7129
|
-
this._packer.on("data", this.emit.bind(this, "data"));
|
|
7130
|
-
this._packer.on("end", this.emit.bind(this, "end"));
|
|
7131
|
-
this._parser.on("close", this._handleClose.bind(this));
|
|
7132
|
-
this._packer.on("error", this.emit.bind(this, "error"));
|
|
7133
|
-
};
|
|
7134
|
-
util.inherits(PNG, Stream);
|
|
7135
|
-
PNG.sync = PNGSync;
|
|
7136
|
-
PNG.prototype.pack = function() {
|
|
7137
|
-
if (!this.data || !this.data.length) {
|
|
7138
|
-
this.emit("error", "No data provided");
|
|
7139
|
-
return this;
|
|
7140
|
-
}
|
|
7141
|
-
process.nextTick(function() {
|
|
7142
|
-
this._packer.pack(this.data, this.width, this.height, this.gamma);
|
|
7143
|
-
}.bind(this));
|
|
7144
|
-
return this;
|
|
7145
|
-
};
|
|
7146
|
-
PNG.prototype.parse = function(data, callback) {
|
|
7147
|
-
if (callback) {
|
|
7148
|
-
let onParsed, onError;
|
|
7149
|
-
onParsed = function(parsedData) {
|
|
7150
|
-
this.removeListener("error", onError);
|
|
7151
|
-
this.data = parsedData;
|
|
7152
|
-
callback(null, this);
|
|
7153
|
-
}.bind(this);
|
|
7154
|
-
onError = function(err) {
|
|
7155
|
-
this.removeListener("parsed", onParsed);
|
|
7156
|
-
callback(err, null);
|
|
7157
|
-
}.bind(this);
|
|
7158
|
-
this.once("parsed", onParsed);
|
|
7159
|
-
this.once("error", onError);
|
|
7160
|
-
}
|
|
7161
|
-
this.end(data);
|
|
7162
|
-
return this;
|
|
7163
|
-
};
|
|
7164
|
-
PNG.prototype.write = function(data) {
|
|
7165
|
-
this._parser.write(data);
|
|
7166
|
-
return true;
|
|
7167
|
-
};
|
|
7168
|
-
PNG.prototype.end = function(data) {
|
|
7169
|
-
this._parser.end(data);
|
|
7170
|
-
};
|
|
7171
|
-
PNG.prototype._metadata = function(metadata) {
|
|
7172
|
-
this.width = metadata.width;
|
|
7173
|
-
this.height = metadata.height;
|
|
7174
|
-
this.emit("metadata", metadata);
|
|
7175
|
-
};
|
|
7176
|
-
PNG.prototype._gamma = function(gamma) {
|
|
7177
|
-
this.gamma = gamma;
|
|
7178
|
-
};
|
|
7179
|
-
PNG.prototype._handleClose = function() {
|
|
7180
|
-
if (!this._parser.writable && !this._packer.readable) {
|
|
7181
|
-
this.emit("close");
|
|
7182
|
-
}
|
|
7183
|
-
};
|
|
7184
|
-
PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
7185
|
-
srcX |= 0;
|
|
7186
|
-
srcY |= 0;
|
|
7187
|
-
width |= 0;
|
|
7188
|
-
height |= 0;
|
|
7189
|
-
deltaX |= 0;
|
|
7190
|
-
deltaY |= 0;
|
|
7191
|
-
if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
|
|
7192
|
-
throw new Error("bitblt reading outside image");
|
|
7193
|
-
}
|
|
7194
|
-
if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
|
|
7195
|
-
throw new Error("bitblt writing outside image");
|
|
7196
|
-
}
|
|
7197
|
-
for (let y = 0;y < height; y++) {
|
|
7198
|
-
src.data.copy(dst.data, (deltaY + y) * dst.width + deltaX << 2, (srcY + y) * src.width + srcX << 2, (srcY + y) * src.width + srcX + width << 2);
|
|
7199
|
-
}
|
|
7200
|
-
};
|
|
7201
|
-
PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
7202
|
-
PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
|
|
7203
|
-
return this;
|
|
7204
|
-
};
|
|
7205
|
-
PNG.adjustGamma = function(src) {
|
|
7206
|
-
if (src.gamma) {
|
|
7207
|
-
for (let y = 0;y < src.height; y++) {
|
|
7208
|
-
for (let x2 = 0;x2 < src.width; x2++) {
|
|
7209
|
-
let idx = src.width * y + x2 << 2;
|
|
7210
|
-
for (let i2 = 0;i2 < 3; i2++) {
|
|
7211
|
-
let sample = src.data[idx + i2] / 255;
|
|
7212
|
-
sample = Math.pow(sample, 1 / 2.2 / src.gamma);
|
|
7213
|
-
src.data[idx + i2] = Math.round(sample * 255);
|
|
7214
|
-
}
|
|
7215
|
-
}
|
|
7216
|
-
}
|
|
7217
|
-
src.gamma = 0;
|
|
7218
|
-
}
|
|
7219
|
-
};
|
|
7220
|
-
PNG.prototype.adjustGamma = function() {
|
|
7221
|
-
PNG.adjustGamma(this);
|
|
7222
|
-
};
|
|
7223
|
-
});
|
|
7224
|
-
|
|
7225
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js
|
|
7226
|
-
var require_utils3 = __commonJS((exports) => {
|
|
7227
|
-
function hex2rgba(hex) {
|
|
7228
|
-
if (typeof hex === "number") {
|
|
7229
|
-
hex = hex.toString();
|
|
7230
|
-
}
|
|
7231
|
-
if (typeof hex !== "string") {
|
|
7232
|
-
throw new Error("Color should be defined as hex string");
|
|
7233
|
-
}
|
|
7234
|
-
let hexCode = hex.slice().replace("#", "").split("");
|
|
7235
|
-
if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
|
|
7236
|
-
throw new Error("Invalid hex color: " + hex);
|
|
7237
|
-
}
|
|
7238
|
-
if (hexCode.length === 3 || hexCode.length === 4) {
|
|
7239
|
-
hexCode = Array.prototype.concat.apply([], hexCode.map(function(c) {
|
|
7240
|
-
return [c, c];
|
|
7241
|
-
}));
|
|
7242
|
-
}
|
|
7243
|
-
if (hexCode.length === 6)
|
|
7244
|
-
hexCode.push("F", "F");
|
|
7245
|
-
const hexValue = parseInt(hexCode.join(""), 16);
|
|
7246
|
-
return {
|
|
7247
|
-
r: hexValue >> 24 & 255,
|
|
7248
|
-
g: hexValue >> 16 & 255,
|
|
7249
|
-
b: hexValue >> 8 & 255,
|
|
7250
|
-
a: hexValue & 255,
|
|
7251
|
-
hex: "#" + hexCode.slice(0, 6).join("")
|
|
7252
|
-
};
|
|
7253
|
-
}
|
|
7254
|
-
exports.getOptions = function getOptions(options) {
|
|
7255
|
-
if (!options)
|
|
7256
|
-
options = {};
|
|
7257
|
-
if (!options.color)
|
|
7258
|
-
options.color = {};
|
|
7259
|
-
const margin = typeof options.margin === "undefined" || options.margin === null || options.margin < 0 ? 4 : options.margin;
|
|
7260
|
-
const width = options.width && options.width >= 21 ? options.width : undefined;
|
|
7261
|
-
const scale = options.scale || 4;
|
|
7262
|
-
return {
|
|
7263
|
-
width,
|
|
7264
|
-
scale: width ? 4 : scale,
|
|
7265
|
-
margin,
|
|
7266
|
-
color: {
|
|
7267
|
-
dark: hex2rgba(options.color.dark || "#000000ff"),
|
|
7268
|
-
light: hex2rgba(options.color.light || "#ffffffff")
|
|
7269
|
-
},
|
|
7270
|
-
type: options.type,
|
|
7271
|
-
rendererOpts: options.rendererOpts || {}
|
|
7272
|
-
};
|
|
7273
|
-
};
|
|
7274
|
-
exports.getScale = function getScale(qrSize, opts) {
|
|
7275
|
-
return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
|
|
7276
|
-
};
|
|
7277
|
-
exports.getImageWidth = function getImageWidth(qrSize, opts) {
|
|
7278
|
-
const scale = exports.getScale(qrSize, opts);
|
|
7279
|
-
return Math.floor((qrSize + opts.margin * 2) * scale);
|
|
7280
|
-
};
|
|
7281
|
-
exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
|
|
7282
|
-
const size = qr.modules.size;
|
|
7283
|
-
const data = qr.modules.data;
|
|
7284
|
-
const scale = exports.getScale(size, opts);
|
|
7285
|
-
const symbolSize = Math.floor((size + opts.margin * 2) * scale);
|
|
7286
|
-
const scaledMargin = opts.margin * scale;
|
|
7287
|
-
const palette = [opts.color.light, opts.color.dark];
|
|
7288
|
-
for (let i2 = 0;i2 < symbolSize; i2++) {
|
|
7289
|
-
for (let j = 0;j < symbolSize; j++) {
|
|
7290
|
-
let posDst = (i2 * symbolSize + j) * 4;
|
|
7291
|
-
let pxColor = opts.color.light;
|
|
7292
|
-
if (i2 >= scaledMargin && j >= scaledMargin && i2 < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
|
|
7293
|
-
const iSrc = Math.floor((i2 - scaledMargin) / scale);
|
|
7294
|
-
const jSrc = Math.floor((j - scaledMargin) / scale);
|
|
7295
|
-
pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
|
|
7296
|
-
}
|
|
7297
|
-
imgData[posDst++] = pxColor.r;
|
|
7298
|
-
imgData[posDst++] = pxColor.g;
|
|
7299
|
-
imgData[posDst++] = pxColor.b;
|
|
7300
|
-
imgData[posDst] = pxColor.a;
|
|
7301
|
-
}
|
|
7302
|
-
}
|
|
7303
|
-
};
|
|
7304
|
-
});
|
|
7305
|
-
|
|
7306
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/renderer/png.js
|
|
7307
|
-
var require_png2 = __commonJS((exports) => {
|
|
7308
|
-
var fs7 = __require("fs");
|
|
7309
|
-
var PNG = require_png().PNG;
|
|
7310
|
-
var Utils = require_utils3();
|
|
7311
|
-
exports.render = function render(qrData, options) {
|
|
7312
|
-
const opts = Utils.getOptions(options);
|
|
7313
|
-
const pngOpts = opts.rendererOpts;
|
|
7314
|
-
const size = Utils.getImageWidth(qrData.modules.size, opts);
|
|
7315
|
-
pngOpts.width = size;
|
|
7316
|
-
pngOpts.height = size;
|
|
7317
|
-
const pngImage = new PNG(pngOpts);
|
|
7318
|
-
Utils.qrToImageData(pngImage.data, qrData, opts);
|
|
7319
|
-
return pngImage;
|
|
7320
|
-
};
|
|
7321
|
-
exports.renderToDataURL = function renderToDataURL(qrData, options, cb) {
|
|
7322
|
-
if (typeof cb === "undefined") {
|
|
7323
|
-
cb = options;
|
|
7324
|
-
options = undefined;
|
|
7325
|
-
}
|
|
7326
|
-
exports.renderToBuffer(qrData, options, function(err, output) {
|
|
7327
|
-
if (err)
|
|
7328
|
-
cb(err);
|
|
7329
|
-
let url = "data:image/png;base64,";
|
|
7330
|
-
url += output.toString("base64");
|
|
7331
|
-
cb(null, url);
|
|
7332
|
-
});
|
|
7333
|
-
};
|
|
7334
|
-
exports.renderToBuffer = function renderToBuffer(qrData, options, cb) {
|
|
7335
|
-
if (typeof cb === "undefined") {
|
|
7336
|
-
cb = options;
|
|
7337
|
-
options = undefined;
|
|
7338
|
-
}
|
|
7339
|
-
const png = exports.render(qrData, options);
|
|
7340
|
-
const buffer = [];
|
|
7341
|
-
png.on("error", cb);
|
|
7342
|
-
png.on("data", function(data) {
|
|
7343
|
-
buffer.push(data);
|
|
7344
|
-
});
|
|
7345
|
-
png.on("end", function() {
|
|
7346
|
-
cb(null, Buffer.concat(buffer));
|
|
7347
|
-
});
|
|
7348
|
-
png.pack();
|
|
7349
|
-
};
|
|
7350
|
-
exports.renderToFile = function renderToFile(path3, qrData, options, cb) {
|
|
7351
|
-
if (typeof cb === "undefined") {
|
|
7352
|
-
cb = options;
|
|
7353
|
-
options = undefined;
|
|
7354
|
-
}
|
|
7355
|
-
let called = false;
|
|
7356
|
-
const done = (...args) => {
|
|
7357
|
-
if (called)
|
|
7358
|
-
return;
|
|
7359
|
-
called = true;
|
|
7360
|
-
cb.apply(null, args);
|
|
7361
|
-
};
|
|
7362
|
-
const stream = fs7.createWriteStream(path3);
|
|
7363
|
-
stream.on("error", done);
|
|
7364
|
-
stream.on("close", done);
|
|
7365
|
-
exports.renderToFileStream(stream, qrData, options);
|
|
7366
|
-
};
|
|
7367
|
-
exports.renderToFileStream = function renderToFileStream(stream, qrData, options) {
|
|
7368
|
-
const png = exports.render(qrData, options);
|
|
7369
|
-
png.pack().pipe(stream);
|
|
7370
|
-
};
|
|
7371
|
-
});
|
|
7372
|
-
|
|
7373
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utf8.js
|
|
7374
|
-
var require_utf8 = __commonJS((exports) => {
|
|
7375
|
-
var Utils = require_utils3();
|
|
7376
|
-
var BLOCK_CHAR = {
|
|
7377
|
-
WW: " ",
|
|
7378
|
-
WB: "▄",
|
|
7379
|
-
BB: "█",
|
|
7380
|
-
BW: "▀"
|
|
7381
|
-
};
|
|
7382
|
-
var INVERTED_BLOCK_CHAR = {
|
|
7383
|
-
BB: " ",
|
|
7384
|
-
BW: "▄",
|
|
7385
|
-
WW: "█",
|
|
7386
|
-
WB: "▀"
|
|
7387
|
-
};
|
|
7388
|
-
function getBlockChar(top, bottom, blocks) {
|
|
7389
|
-
if (top && bottom)
|
|
7390
|
-
return blocks.BB;
|
|
7391
|
-
if (top && !bottom)
|
|
7392
|
-
return blocks.BW;
|
|
7393
|
-
if (!top && bottom)
|
|
7394
|
-
return blocks.WB;
|
|
7395
|
-
return blocks.WW;
|
|
7396
|
-
}
|
|
7397
|
-
exports.render = function(qrData, options, cb) {
|
|
7398
|
-
const opts = Utils.getOptions(options);
|
|
7399
|
-
let blocks = BLOCK_CHAR;
|
|
7400
|
-
if (opts.color.dark.hex === "#ffffff" || opts.color.light.hex === "#000000") {
|
|
7401
|
-
blocks = INVERTED_BLOCK_CHAR;
|
|
7402
|
-
}
|
|
7403
|
-
const size = qrData.modules.size;
|
|
7404
|
-
const data = qrData.modules.data;
|
|
7405
|
-
let output = "";
|
|
7406
|
-
let hMargin = Array(size + opts.margin * 2 + 1).join(blocks.WW);
|
|
7407
|
-
hMargin = Array(opts.margin / 2 + 1).join(hMargin + `
|
|
7408
|
-
`);
|
|
7409
|
-
const vMargin = Array(opts.margin + 1).join(blocks.WW);
|
|
7410
|
-
output += hMargin;
|
|
7411
|
-
for (let i2 = 0;i2 < size; i2 += 2) {
|
|
7412
|
-
output += vMargin;
|
|
7413
|
-
for (let j = 0;j < size; j++) {
|
|
7414
|
-
const topModule = data[i2 * size + j];
|
|
7415
|
-
const bottomModule = data[(i2 + 1) * size + j];
|
|
7416
|
-
output += getBlockChar(topModule, bottomModule, blocks);
|
|
7417
|
-
}
|
|
7418
|
-
output += vMargin + `
|
|
7419
|
-
`;
|
|
7420
|
-
}
|
|
7421
|
-
output += hMargin.slice(0, -1);
|
|
7422
|
-
if (typeof cb === "function") {
|
|
7423
|
-
cb(null, output);
|
|
7424
|
-
}
|
|
7425
|
-
return output;
|
|
7426
|
-
};
|
|
7427
|
-
exports.renderToFile = function renderToFile(path3, qrData, options, cb) {
|
|
7428
|
-
if (typeof cb === "undefined") {
|
|
7429
|
-
cb = options;
|
|
7430
|
-
options = undefined;
|
|
7431
|
-
}
|
|
7432
|
-
const fs7 = __require("fs");
|
|
7433
|
-
const utf8 = exports.render(qrData, options);
|
|
7434
|
-
fs7.writeFile(path3, utf8, cb);
|
|
7435
|
-
};
|
|
7436
|
-
});
|
|
7437
|
-
|
|
7438
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal.js
|
|
7439
|
-
var require_terminal = __commonJS((exports) => {
|
|
7440
|
-
exports.render = function(qrData, options, cb) {
|
|
7441
|
-
const size = qrData.modules.size;
|
|
7442
|
-
const data = qrData.modules.data;
|
|
7443
|
-
const black = "\x1B[40m \x1B[0m";
|
|
7444
|
-
const white = "\x1B[47m \x1B[0m";
|
|
7445
|
-
let output = "";
|
|
7446
|
-
const hMargin = Array(size + 3).join(white);
|
|
7447
|
-
const vMargin = Array(2).join(white);
|
|
7448
|
-
output += hMargin + `
|
|
7449
|
-
`;
|
|
7450
|
-
for (let i2 = 0;i2 < size; ++i2) {
|
|
7451
|
-
output += white;
|
|
7452
|
-
for (let j = 0;j < size; j++) {
|
|
7453
|
-
output += data[i2 * size + j] ? black : white;
|
|
7454
|
-
}
|
|
7455
|
-
output += vMargin + `
|
|
7456
|
-
`;
|
|
7457
|
-
}
|
|
7458
|
-
output += hMargin + `
|
|
7459
|
-
`;
|
|
7460
|
-
if (typeof cb === "function") {
|
|
7461
|
-
cb(null, output);
|
|
7462
|
-
}
|
|
7463
|
-
return output;
|
|
7464
|
-
};
|
|
7465
|
-
});
|
|
7466
|
-
|
|
7467
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal-small.js
|
|
7468
|
-
var require_terminal_small = __commonJS((exports) => {
|
|
7469
|
-
var backgroundWhite = "\x1B[47m";
|
|
7470
|
-
var backgroundBlack = "\x1B[40m";
|
|
7471
|
-
var foregroundWhite = "\x1B[37m";
|
|
7472
|
-
var foregroundBlack = "\x1B[30m";
|
|
7473
|
-
var reset = "\x1B[0m";
|
|
7474
|
-
var lineSetupNormal = backgroundWhite + foregroundBlack;
|
|
7475
|
-
var lineSetupInverse = backgroundBlack + foregroundWhite;
|
|
7476
|
-
var createPalette = function(lineSetup, foregroundWhite2, foregroundBlack2) {
|
|
7477
|
-
return {
|
|
7478
|
-
"00": reset + " " + lineSetup,
|
|
7479
|
-
"01": reset + foregroundWhite2 + "▄" + lineSetup,
|
|
7480
|
-
"02": reset + foregroundBlack2 + "▄" + lineSetup,
|
|
7481
|
-
10: reset + foregroundWhite2 + "▀" + lineSetup,
|
|
7482
|
-
11: " ",
|
|
7483
|
-
12: "▄",
|
|
7484
|
-
20: reset + foregroundBlack2 + "▀" + lineSetup,
|
|
7485
|
-
21: "▀",
|
|
7486
|
-
22: "█"
|
|
7487
|
-
};
|
|
7488
|
-
};
|
|
7489
|
-
var mkCodePixel = function(modules, size, x2, y) {
|
|
7490
|
-
const sizePlus = size + 1;
|
|
7491
|
-
if (x2 >= sizePlus || y >= sizePlus || y < -1 || x2 < -1)
|
|
7492
|
-
return "0";
|
|
7493
|
-
if (x2 >= size || y >= size || y < 0 || x2 < 0)
|
|
7494
|
-
return "1";
|
|
7495
|
-
const idx = y * size + x2;
|
|
7496
|
-
return modules[idx] ? "2" : "1";
|
|
7497
|
-
};
|
|
7498
|
-
var mkCode = function(modules, size, x2, y) {
|
|
7499
|
-
return mkCodePixel(modules, size, x2, y) + mkCodePixel(modules, size, x2, y + 1);
|
|
7500
|
-
};
|
|
7501
|
-
exports.render = function(qrData, options, cb) {
|
|
7502
|
-
const size = qrData.modules.size;
|
|
7503
|
-
const data = qrData.modules.data;
|
|
7504
|
-
const inverse = !!(options && options.inverse);
|
|
7505
|
-
const lineSetup = options && options.inverse ? lineSetupInverse : lineSetupNormal;
|
|
7506
|
-
const white = inverse ? foregroundBlack : foregroundWhite;
|
|
7507
|
-
const black = inverse ? foregroundWhite : foregroundBlack;
|
|
7508
|
-
const palette = createPalette(lineSetup, white, black);
|
|
7509
|
-
const newLine = reset + `
|
|
7510
|
-
` + lineSetup;
|
|
7511
|
-
let output = lineSetup;
|
|
7512
|
-
for (let y = -1;y < size + 1; y += 2) {
|
|
7513
|
-
for (let x2 = -1;x2 < size; x2++) {
|
|
7514
|
-
output += palette[mkCode(data, size, x2, y)];
|
|
7515
|
-
}
|
|
7516
|
-
output += palette[mkCode(data, size, size, y)] + newLine;
|
|
7517
|
-
}
|
|
7518
|
-
output += reset;
|
|
7519
|
-
if (typeof cb === "function") {
|
|
7520
|
-
cb(null, output);
|
|
7521
|
-
}
|
|
7522
|
-
return output;
|
|
7523
|
-
};
|
|
7524
|
-
});
|
|
7525
|
-
|
|
7526
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal.js
|
|
7527
|
-
var require_terminal2 = __commonJS((exports) => {
|
|
7528
|
-
var big = require_terminal();
|
|
7529
|
-
var small = require_terminal_small();
|
|
7530
|
-
exports.render = function(qrData, options, cb) {
|
|
7531
|
-
if (options && options.small) {
|
|
7532
|
-
return small.render(qrData, options, cb);
|
|
7533
|
-
}
|
|
7534
|
-
return big.render(qrData, options, cb);
|
|
7535
|
-
};
|
|
7536
|
-
});
|
|
7537
|
-
|
|
7538
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js
|
|
7539
|
-
var require_svg_tag = __commonJS((exports) => {
|
|
7540
|
-
var Utils = require_utils3();
|
|
7541
|
-
function getColorAttrib(color, attrib) {
|
|
7542
|
-
const alpha = color.a / 255;
|
|
7543
|
-
const str = attrib + '="' + color.hex + '"';
|
|
7544
|
-
return alpha < 1 ? str + " " + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str;
|
|
7545
|
-
}
|
|
7546
|
-
function svgCmd(cmd, x2, y) {
|
|
7547
|
-
let str = cmd + x2;
|
|
7548
|
-
if (typeof y !== "undefined")
|
|
7549
|
-
str += " " + y;
|
|
7550
|
-
return str;
|
|
7551
|
-
}
|
|
7552
|
-
function qrToPath(data, size, margin) {
|
|
7553
|
-
let path3 = "";
|
|
7554
|
-
let moveBy = 0;
|
|
7555
|
-
let newRow = false;
|
|
7556
|
-
let lineLength = 0;
|
|
7557
|
-
for (let i2 = 0;i2 < data.length; i2++) {
|
|
7558
|
-
const col = Math.floor(i2 % size);
|
|
7559
|
-
const row = Math.floor(i2 / size);
|
|
7560
|
-
if (!col && !newRow)
|
|
7561
|
-
newRow = true;
|
|
7562
|
-
if (data[i2]) {
|
|
7563
|
-
lineLength++;
|
|
7564
|
-
if (!(i2 > 0 && col > 0 && data[i2 - 1])) {
|
|
7565
|
-
path3 += newRow ? svgCmd("M", col + margin, 0.5 + row + margin) : svgCmd("m", moveBy, 0);
|
|
7566
|
-
moveBy = 0;
|
|
7567
|
-
newRow = false;
|
|
7568
|
-
}
|
|
7569
|
-
if (!(col + 1 < size && data[i2 + 1])) {
|
|
7570
|
-
path3 += svgCmd("h", lineLength);
|
|
7571
|
-
lineLength = 0;
|
|
7572
|
-
}
|
|
7573
|
-
} else {
|
|
7574
|
-
moveBy++;
|
|
7575
|
-
}
|
|
7576
|
-
}
|
|
7577
|
-
return path3;
|
|
7578
|
-
}
|
|
7579
|
-
exports.render = function render(qrData, options, cb) {
|
|
7580
|
-
const opts = Utils.getOptions(options);
|
|
7581
|
-
const size = qrData.modules.size;
|
|
7582
|
-
const data = qrData.modules.data;
|
|
7583
|
-
const qrcodesize = size + opts.margin * 2;
|
|
7584
|
-
const bg = !opts.color.light.a ? "" : "<path " + getColorAttrib(opts.color.light, "fill") + ' d="M0 0h' + qrcodesize + "v" + qrcodesize + 'H0z"/>';
|
|
7585
|
-
const path3 = "<path " + getColorAttrib(opts.color.dark, "stroke") + ' d="' + qrToPath(data, size, opts.margin) + '"/>';
|
|
7586
|
-
const viewBox = 'viewBox="' + "0 0 " + qrcodesize + " " + qrcodesize + '"';
|
|
7587
|
-
const width = !opts.width ? "" : 'width="' + opts.width + '" height="' + opts.width + '" ';
|
|
7588
|
-
const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path3 + `</svg>
|
|
7589
|
-
`;
|
|
7590
|
-
if (typeof cb === "function") {
|
|
7591
|
-
cb(null, svgTag);
|
|
7592
|
-
}
|
|
7593
|
-
return svgTag;
|
|
7594
|
-
};
|
|
7595
|
-
});
|
|
7596
|
-
|
|
7597
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js
|
|
7598
|
-
var require_svg = __commonJS((exports) => {
|
|
7599
|
-
var svgTagRenderer = require_svg_tag();
|
|
7600
|
-
exports.render = svgTagRenderer.render;
|
|
7601
|
-
exports.renderToFile = function renderToFile(path3, qrData, options, cb) {
|
|
7602
|
-
if (typeof cb === "undefined") {
|
|
7603
|
-
cb = options;
|
|
7604
|
-
options = undefined;
|
|
7605
|
-
}
|
|
7606
|
-
const fs7 = __require("fs");
|
|
7607
|
-
const svgTag = exports.render(qrData, options);
|
|
7608
|
-
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;
|
|
7609
|
-
fs7.writeFile(path3, xmlStr, cb);
|
|
7610
|
-
};
|
|
7611
|
-
});
|
|
7612
|
-
|
|
7613
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js
|
|
7614
|
-
var require_canvas = __commonJS((exports) => {
|
|
7615
|
-
var Utils = require_utils3();
|
|
7616
|
-
function clearCanvas(ctx, canvas, size) {
|
|
7617
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
7618
|
-
if (!canvas.style)
|
|
7619
|
-
canvas.style = {};
|
|
7620
|
-
canvas.height = size;
|
|
7621
|
-
canvas.width = size;
|
|
7622
|
-
canvas.style.height = size + "px";
|
|
7623
|
-
canvas.style.width = size + "px";
|
|
7624
|
-
}
|
|
7625
|
-
function getCanvasElement() {
|
|
7626
|
-
try {
|
|
7627
|
-
return document.createElement("canvas");
|
|
7628
|
-
} catch (e) {
|
|
7629
|
-
throw new Error("You need to specify a canvas element");
|
|
7630
|
-
}
|
|
7631
|
-
}
|
|
7632
|
-
exports.render = function render(qrData, canvas, options) {
|
|
7633
|
-
let opts = options;
|
|
7634
|
-
let canvasEl = canvas;
|
|
7635
|
-
if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
|
|
7636
|
-
opts = canvas;
|
|
7637
|
-
canvas = undefined;
|
|
7638
|
-
}
|
|
7639
|
-
if (!canvas) {
|
|
7640
|
-
canvasEl = getCanvasElement();
|
|
7641
|
-
}
|
|
7642
|
-
opts = Utils.getOptions(opts);
|
|
7643
|
-
const size = Utils.getImageWidth(qrData.modules.size, opts);
|
|
7644
|
-
const ctx = canvasEl.getContext("2d");
|
|
7645
|
-
const image = ctx.createImageData(size, size);
|
|
7646
|
-
Utils.qrToImageData(image.data, qrData, opts);
|
|
7647
|
-
clearCanvas(ctx, canvasEl, size);
|
|
7648
|
-
ctx.putImageData(image, 0, 0);
|
|
7649
|
-
return canvasEl;
|
|
7650
|
-
};
|
|
7651
|
-
exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
|
|
7652
|
-
let opts = options;
|
|
7653
|
-
if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
|
|
7654
|
-
opts = canvas;
|
|
7655
|
-
canvas = undefined;
|
|
7656
|
-
}
|
|
7657
|
-
if (!opts)
|
|
7658
|
-
opts = {};
|
|
7659
|
-
const canvasEl = exports.render(qrData, canvas, opts);
|
|
7660
|
-
const type = opts.type || "image/png";
|
|
7661
|
-
const rendererOpts = opts.rendererOpts || {};
|
|
7662
|
-
return canvasEl.toDataURL(type, rendererOpts.quality);
|
|
7663
|
-
};
|
|
7664
|
-
});
|
|
7665
|
-
|
|
7666
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/browser.js
|
|
7667
|
-
var require_browser = __commonJS((exports) => {
|
|
7668
|
-
var canPromise = require_can_promise();
|
|
7669
|
-
var QRCode = require_qrcode();
|
|
7670
|
-
var CanvasRenderer = require_canvas();
|
|
7671
|
-
var SvgRenderer = require_svg_tag();
|
|
7672
|
-
function renderCanvas(renderFunc, canvas, text, opts, cb) {
|
|
7673
|
-
const args = [].slice.call(arguments, 1);
|
|
7674
|
-
const argsNum = args.length;
|
|
7675
|
-
const isLastArgCb = typeof args[argsNum - 1] === "function";
|
|
7676
|
-
if (!isLastArgCb && !canPromise()) {
|
|
7677
|
-
throw new Error("Callback required as last argument");
|
|
7678
|
-
}
|
|
7679
|
-
if (isLastArgCb) {
|
|
7680
|
-
if (argsNum < 2) {
|
|
7681
|
-
throw new Error("Too few arguments provided");
|
|
7682
|
-
}
|
|
7683
|
-
if (argsNum === 2) {
|
|
7684
|
-
cb = text;
|
|
7685
|
-
text = canvas;
|
|
7686
|
-
canvas = opts = undefined;
|
|
7687
|
-
} else if (argsNum === 3) {
|
|
7688
|
-
if (canvas.getContext && typeof cb === "undefined") {
|
|
7689
|
-
cb = opts;
|
|
7690
|
-
opts = undefined;
|
|
7691
|
-
} else {
|
|
7692
|
-
cb = opts;
|
|
7693
|
-
opts = text;
|
|
7694
|
-
text = canvas;
|
|
7695
|
-
canvas = undefined;
|
|
7696
|
-
}
|
|
7697
|
-
}
|
|
7698
|
-
} else {
|
|
7699
|
-
if (argsNum < 1) {
|
|
7700
|
-
throw new Error("Too few arguments provided");
|
|
7701
|
-
}
|
|
7702
|
-
if (argsNum === 1) {
|
|
7703
|
-
text = canvas;
|
|
7704
|
-
canvas = opts = undefined;
|
|
7705
|
-
} else if (argsNum === 2 && !canvas.getContext) {
|
|
7706
|
-
opts = text;
|
|
7707
|
-
text = canvas;
|
|
7708
|
-
canvas = undefined;
|
|
7709
|
-
}
|
|
7710
|
-
return new Promise(function(resolve4, reject) {
|
|
7711
|
-
try {
|
|
7712
|
-
const data = QRCode.create(text, opts);
|
|
7713
|
-
resolve4(renderFunc(data, canvas, opts));
|
|
7714
|
-
} catch (e) {
|
|
7715
|
-
reject(e);
|
|
7716
|
-
}
|
|
7717
|
-
});
|
|
7718
|
-
}
|
|
7719
|
-
try {
|
|
7720
|
-
const data = QRCode.create(text, opts);
|
|
7721
|
-
cb(null, renderFunc(data, canvas, opts));
|
|
7722
|
-
} catch (e) {
|
|
7723
|
-
cb(e);
|
|
7724
|
-
}
|
|
7725
|
-
}
|
|
7726
|
-
exports.create = QRCode.create;
|
|
7727
|
-
exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
|
|
7728
|
-
exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
|
|
7729
|
-
exports.toString = renderCanvas.bind(null, function(data, _, opts) {
|
|
7730
|
-
return SvgRenderer.render(data, opts);
|
|
7731
|
-
});
|
|
7732
|
-
});
|
|
7733
|
-
|
|
7734
|
-
// ../../node_modules/.bun/qrcode@1.5.4/node_modules/qrcode/lib/server.js
|
|
7735
|
-
var require_server = __commonJS((exports) => {
|
|
7736
|
-
var canPromise = require_can_promise();
|
|
7737
|
-
var QRCode = require_qrcode();
|
|
7738
|
-
var PngRenderer = require_png2();
|
|
7739
|
-
var Utf8Renderer = require_utf8();
|
|
7740
|
-
var TerminalRenderer = require_terminal2();
|
|
7741
|
-
var SvgRenderer = require_svg();
|
|
7742
|
-
function checkParams(text, opts, cb) {
|
|
7743
|
-
if (typeof text === "undefined") {
|
|
7744
|
-
throw new Error("String required as first argument");
|
|
7745
|
-
}
|
|
7746
|
-
if (typeof cb === "undefined") {
|
|
7747
|
-
cb = opts;
|
|
7748
|
-
opts = {};
|
|
7749
|
-
}
|
|
7750
|
-
if (typeof cb !== "function") {
|
|
7751
|
-
if (!canPromise()) {
|
|
7752
|
-
throw new Error("Callback required as last argument");
|
|
7753
|
-
} else {
|
|
7754
|
-
opts = cb || {};
|
|
7755
|
-
cb = null;
|
|
7756
|
-
}
|
|
7757
|
-
}
|
|
7758
|
-
return {
|
|
7759
|
-
opts,
|
|
7760
|
-
cb
|
|
7761
|
-
};
|
|
7762
|
-
}
|
|
7763
|
-
function getTypeFromFilename(path3) {
|
|
7764
|
-
return path3.slice((path3.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
|
|
7765
|
-
}
|
|
7766
|
-
function getRendererFromType(type) {
|
|
7767
|
-
switch (type) {
|
|
7768
|
-
case "svg":
|
|
7769
|
-
return SvgRenderer;
|
|
7770
|
-
case "txt":
|
|
7771
|
-
case "utf8":
|
|
7772
|
-
return Utf8Renderer;
|
|
7773
|
-
case "png":
|
|
7774
|
-
case "image/png":
|
|
7775
|
-
default:
|
|
7776
|
-
return PngRenderer;
|
|
7777
|
-
}
|
|
7778
|
-
}
|
|
7779
|
-
function getStringRendererFromType(type) {
|
|
7780
|
-
switch (type) {
|
|
7781
|
-
case "svg":
|
|
7782
|
-
return SvgRenderer;
|
|
7783
|
-
case "terminal":
|
|
7784
|
-
return TerminalRenderer;
|
|
7785
|
-
case "utf8":
|
|
7786
|
-
default:
|
|
7787
|
-
return Utf8Renderer;
|
|
7788
|
-
}
|
|
7789
|
-
}
|
|
7790
|
-
function render(renderFunc, text, params) {
|
|
7791
|
-
if (!params.cb) {
|
|
7792
|
-
return new Promise(function(resolve4, reject) {
|
|
7793
|
-
try {
|
|
7794
|
-
const data = QRCode.create(text, params.opts);
|
|
7795
|
-
return renderFunc(data, params.opts, function(err, data2) {
|
|
7796
|
-
return err ? reject(err) : resolve4(data2);
|
|
7797
|
-
});
|
|
7798
|
-
} catch (e) {
|
|
7799
|
-
reject(e);
|
|
7800
|
-
}
|
|
7801
|
-
});
|
|
7802
|
-
}
|
|
7803
|
-
try {
|
|
7804
|
-
const data = QRCode.create(text, params.opts);
|
|
7805
|
-
return renderFunc(data, params.opts, params.cb);
|
|
7806
|
-
} catch (e) {
|
|
7807
|
-
params.cb(e);
|
|
7808
|
-
}
|
|
7809
|
-
}
|
|
7810
|
-
exports.create = QRCode.create;
|
|
7811
|
-
exports.toCanvas = require_browser().toCanvas;
|
|
7812
|
-
exports.toString = function toString(text, opts, cb) {
|
|
7813
|
-
const params = checkParams(text, opts, cb);
|
|
7814
|
-
const type = params.opts ? params.opts.type : undefined;
|
|
7815
|
-
const renderer = getStringRendererFromType(type);
|
|
7816
|
-
return render(renderer.render, text, params);
|
|
7817
|
-
};
|
|
7818
|
-
exports.toDataURL = function toDataURL(text, opts, cb) {
|
|
7819
|
-
const params = checkParams(text, opts, cb);
|
|
7820
|
-
const renderer = getRendererFromType(params.opts.type);
|
|
7821
|
-
return render(renderer.renderToDataURL, text, params);
|
|
7822
|
-
};
|
|
7823
|
-
exports.toBuffer = function toBuffer(text, opts, cb) {
|
|
7824
|
-
const params = checkParams(text, opts, cb);
|
|
7825
|
-
const renderer = getRendererFromType(params.opts.type);
|
|
7826
|
-
return render(renderer.renderToBuffer, text, params);
|
|
7827
|
-
};
|
|
7828
|
-
exports.toFile = function toFile(path3, text, opts, cb) {
|
|
7829
|
-
if (typeof path3 !== "string" || !(typeof text === "string" || typeof text === "object")) {
|
|
7830
|
-
throw new Error("Invalid argument");
|
|
7831
|
-
}
|
|
7832
|
-
if (arguments.length < 3 && !canPromise()) {
|
|
7833
|
-
throw new Error("Too few arguments provided");
|
|
7834
|
-
}
|
|
7835
|
-
const params = checkParams(text, opts, cb);
|
|
7836
|
-
const type = params.opts.type || getTypeFromFilename(path3);
|
|
7837
|
-
const renderer = getRendererFromType(type);
|
|
7838
|
-
const renderToFile = renderer.renderToFile.bind(null, path3);
|
|
7839
|
-
return render(renderToFile, text, params);
|
|
7840
|
-
};
|
|
7841
|
-
exports.toFileStream = function toFileStream(stream, text, opts) {
|
|
7842
|
-
if (arguments.length < 2) {
|
|
7843
|
-
throw new Error("Too few arguments provided");
|
|
7844
|
-
}
|
|
7845
|
-
const params = checkParams(text, opts, stream.emit.bind(stream, "error"));
|
|
7846
|
-
const renderer = getRendererFromType("png");
|
|
7847
|
-
const renderToFileStream = renderer.renderToFileStream.bind(null, stream);
|
|
7848
|
-
render(renderToFileStream, text, params);
|
|
7849
|
-
};
|
|
7850
|
-
});
|
|
7851
|
-
|
|
7852
3563
|
// ../../node_modules/.bun/commander@14.0.2/node_modules/commander/esm.mjs
|
|
7853
3564
|
var import__ = __toESM(require_commander(), 1);
|
|
7854
3565
|
var {
|
|
@@ -9266,8 +4977,7 @@ var usageCommand = new Command2("usage").description("Show current usage and lim
|
|
|
9266
4977
|
}
|
|
9267
4978
|
console.log();
|
|
9268
4979
|
console.log("Account Usage:");
|
|
9269
|
-
console.log(formatUsageLine("
|
|
9270
|
-
console.log(formatUsageLine("Total Sites", data.usage.sites, data.limits.max_orgs * data.limits.max_sites_per_org));
|
|
4980
|
+
console.log(formatUsageLine("Total Sites", data.usage.sites, data.limits.max_sites_per_org));
|
|
9271
4981
|
console.log(formatUsageLine("Deployments (month)", data.usage.deployments_this_month, data.limits.max_deployments_per_month));
|
|
9272
4982
|
console.log();
|
|
9273
4983
|
console.log("Limits:");
|
|
@@ -11375,7 +7085,7 @@ var deployPromoteCommand = new Command2("promote").description("Promote a previe
|
|
|
11375
7085
|
});
|
|
11376
7086
|
|
|
11377
7087
|
// src/lib/version.ts
|
|
11378
|
-
var VERSION = "0.1.
|
|
7088
|
+
var VERSION = "0.1.14";
|
|
11379
7089
|
|
|
11380
7090
|
// src/commands/deploy/index.ts
|
|
11381
7091
|
function slugify(input) {
|
|
@@ -11833,6 +7543,7 @@ Error: Build failed`);
|
|
|
11833
7543
|
body: JSON.stringify({ preview: isPreview, mode: options.append ? "append" : "replace" })
|
|
11834
7544
|
}, {
|
|
11835
7545
|
maxRetries: 3,
|
|
7546
|
+
timeoutMs: 120000,
|
|
11836
7547
|
onRetry: (attempt, error, delayMs) => {
|
|
11837
7548
|
finalizeSpinner.update(`Finalizing... ${formatRetryMessage(attempt, 3, error)}, retrying in ${Math.round(delayMs / 1000)}s`);
|
|
11838
7549
|
}
|
|
@@ -11923,15 +7634,6 @@ Error: Build failed`);
|
|
|
11923
7634
|
}
|
|
11924
7635
|
console.log(`Preview: ${deployment.previewUrl}`);
|
|
11925
7636
|
}
|
|
11926
|
-
if (process.stdout.isTTY) {
|
|
11927
|
-
try {
|
|
11928
|
-
const QRCode = await Promise.resolve().then(() => __toESM(require_server(), 1));
|
|
11929
|
-
const qrUrl = isPreview ? deployment.previewUrl : deployment.url;
|
|
11930
|
-
const qr = await QRCode.toString(qrUrl, { type: "terminal", small: true });
|
|
11931
|
-
console.log("");
|
|
11932
|
-
console.log(qr);
|
|
11933
|
-
} catch {}
|
|
11934
|
-
}
|
|
11935
7637
|
if (options.githubOutput) {
|
|
11936
7638
|
const githubOutputFile = process.env.GITHUB_OUTPUT;
|
|
11937
7639
|
if (githubOutputFile) {
|
|
@@ -12117,8 +7819,77 @@ var deploymentsShowCommand = new Command2("show").description("View deployment d
|
|
|
12117
7819
|
}
|
|
12118
7820
|
});
|
|
12119
7821
|
|
|
7822
|
+
// src/commands/deployments/logs.ts
|
|
7823
|
+
function colorLevel(level) {
|
|
7824
|
+
switch (level) {
|
|
7825
|
+
case "error":
|
|
7826
|
+
return `\x1B[31m${level}\x1B[0m`;
|
|
7827
|
+
case "warn":
|
|
7828
|
+
return `\x1B[33m${level}\x1B[0m`;
|
|
7829
|
+
case "info":
|
|
7830
|
+
return `\x1B[36m${level}\x1B[0m`;
|
|
7831
|
+
default:
|
|
7832
|
+
return level;
|
|
7833
|
+
}
|
|
7834
|
+
}
|
|
7835
|
+
function formatTime(timestamp) {
|
|
7836
|
+
const d = new Date(timestamp);
|
|
7837
|
+
return d.toLocaleTimeString(undefined, { hour12: false, fractionalSecondDigits: 3 });
|
|
7838
|
+
}
|
|
7839
|
+
var deploymentsLogsCommand = new Command2("logs").description("View deployment finalize logs").argument("<id>", "Deployment ID (full or short)").option("--json", "Output as JSON").action(async (id, options) => {
|
|
7840
|
+
const token = loadToken();
|
|
7841
|
+
if (!token) {
|
|
7842
|
+
handleAuthError();
|
|
7843
|
+
}
|
|
7844
|
+
try {
|
|
7845
|
+
const client = getClient(token);
|
|
7846
|
+
const res = await client.deployments[":id"].logs.$get({
|
|
7847
|
+
param: { id }
|
|
7848
|
+
});
|
|
7849
|
+
if (!res.ok) {
|
|
7850
|
+
if (res.status === 404) {
|
|
7851
|
+
displayError({
|
|
7852
|
+
code: "not_found",
|
|
7853
|
+
message: `Deployment not found: ${id}`,
|
|
7854
|
+
hint: "Use the full deployment ID or at least 8 characters."
|
|
7855
|
+
});
|
|
7856
|
+
process.exit(ExitCode.NOT_FOUND);
|
|
7857
|
+
}
|
|
7858
|
+
await handleApiError(res);
|
|
7859
|
+
}
|
|
7860
|
+
const { data: entries } = await res.json();
|
|
7861
|
+
if (options.json) {
|
|
7862
|
+
console.log(JSON.stringify(entries, null, 2));
|
|
7863
|
+
return;
|
|
7864
|
+
}
|
|
7865
|
+
if (entries.length === 0) {
|
|
7866
|
+
console.log("No logs available for this deployment.");
|
|
7867
|
+
console.log("Logs are only available for deployments created after this feature was enabled.");
|
|
7868
|
+
return;
|
|
7869
|
+
}
|
|
7870
|
+
console.log("Deployment Logs");
|
|
7871
|
+
console.log("=".repeat(60));
|
|
7872
|
+
console.log();
|
|
7873
|
+
for (const entry of entries) {
|
|
7874
|
+
const time = formatTime(entry.timestamp);
|
|
7875
|
+
const level = colorLevel(entry.level);
|
|
7876
|
+
const phase = `\x1B[90m[${entry.phase}]\x1B[0m`;
|
|
7877
|
+
const duration = entry.duration_ms !== undefined ? ` \x1B[90m(${entry.duration_ms}ms)\x1B[0m` : "";
|
|
7878
|
+
console.log(`${time} ${level} ${phase} ${entry.message}${duration}`);
|
|
7879
|
+
if (entry.metadata && Object.keys(entry.metadata).length > 0) {
|
|
7880
|
+
const meta = Object.entries(entry.metadata).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
7881
|
+
console.log(` \x1B[90m${meta}\x1B[0m`);
|
|
7882
|
+
}
|
|
7883
|
+
}
|
|
7884
|
+
} catch (err) {
|
|
7885
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
7886
|
+
displayError({ code: "network_error", message: `Failed to get deployment logs: ${message}` });
|
|
7887
|
+
process.exit(ExitCode.NETWORK_ERROR);
|
|
7888
|
+
}
|
|
7889
|
+
});
|
|
7890
|
+
|
|
12120
7891
|
// src/commands/deployments/index.ts
|
|
12121
|
-
var deploymentsCommand = new Command2("deployments").description("Manage deployments").addCommand(deploymentsListCommand).addCommand(deploymentsShowCommand);
|
|
7892
|
+
var deploymentsCommand = new Command2("deployments").description("Manage deployments").addCommand(deploymentsListCommand).addCommand(deploymentsShowCommand).addCommand(deploymentsLogsCommand);
|
|
12122
7893
|
|
|
12123
7894
|
// src/commands/rollback.ts
|
|
12124
7895
|
var rollbackCommand = new Command2("rollback").description("Rollback a site to a previous deployment").argument("<site>", "Site slug").requiredOption("--org <org>", "Organization slug").option("--to <deploymentId>", "Deployment ID to rollback to (defaults to previous deployment)").action(async (site, options) => {
|
|
@@ -12842,7 +8613,7 @@ function createInspectCommand(rootProgram) {
|
|
|
12842
8613
|
}
|
|
12843
8614
|
|
|
12844
8615
|
// src/lib/version.ts
|
|
12845
|
-
var VERSION2 = "0.1.
|
|
8616
|
+
var VERSION2 = "0.1.14";
|
|
12846
8617
|
|
|
12847
8618
|
// src/lib/update-check.ts
|
|
12848
8619
|
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|