@dannote/figma-use 0.6.2 → 0.6.3
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/CHANGELOG.md +14 -0
- package/SKILL.md +22 -0
- package/dist/cli/index.js +2110 -3
- package/package.json +4 -1
package/dist/cli/index.js
CHANGED
|
@@ -24370,6 +24370,2112 @@ ${oldContent.split(`
|
|
|
24370
24370
|
});
|
|
24371
24371
|
});
|
|
24372
24372
|
|
|
24373
|
+
// node_modules/pngjs/lib/chunkstream.js
|
|
24374
|
+
var require_chunkstream = __commonJS((exports, module) => {
|
|
24375
|
+
var util = __require("util");
|
|
24376
|
+
var Stream = __require("stream");
|
|
24377
|
+
var ChunkStream = module.exports = function() {
|
|
24378
|
+
Stream.call(this);
|
|
24379
|
+
this._buffers = [];
|
|
24380
|
+
this._buffered = 0;
|
|
24381
|
+
this._reads = [];
|
|
24382
|
+
this._paused = false;
|
|
24383
|
+
this._encoding = "utf8";
|
|
24384
|
+
this.writable = true;
|
|
24385
|
+
};
|
|
24386
|
+
util.inherits(ChunkStream, Stream);
|
|
24387
|
+
ChunkStream.prototype.read = function(length, callback) {
|
|
24388
|
+
this._reads.push({
|
|
24389
|
+
length: Math.abs(length),
|
|
24390
|
+
allowLess: length < 0,
|
|
24391
|
+
func: callback
|
|
24392
|
+
});
|
|
24393
|
+
process.nextTick(function() {
|
|
24394
|
+
this._process();
|
|
24395
|
+
if (this._paused && this._reads && this._reads.length > 0) {
|
|
24396
|
+
this._paused = false;
|
|
24397
|
+
this.emit("drain");
|
|
24398
|
+
}
|
|
24399
|
+
}.bind(this));
|
|
24400
|
+
};
|
|
24401
|
+
ChunkStream.prototype.write = function(data, encoding) {
|
|
24402
|
+
if (!this.writable) {
|
|
24403
|
+
this.emit("error", new Error("Stream not writable"));
|
|
24404
|
+
return false;
|
|
24405
|
+
}
|
|
24406
|
+
let dataBuffer;
|
|
24407
|
+
if (Buffer.isBuffer(data)) {
|
|
24408
|
+
dataBuffer = data;
|
|
24409
|
+
} else {
|
|
24410
|
+
dataBuffer = Buffer.from(data, encoding || this._encoding);
|
|
24411
|
+
}
|
|
24412
|
+
this._buffers.push(dataBuffer);
|
|
24413
|
+
this._buffered += dataBuffer.length;
|
|
24414
|
+
this._process();
|
|
24415
|
+
if (this._reads && this._reads.length === 0) {
|
|
24416
|
+
this._paused = true;
|
|
24417
|
+
}
|
|
24418
|
+
return this.writable && !this._paused;
|
|
24419
|
+
};
|
|
24420
|
+
ChunkStream.prototype.end = function(data, encoding) {
|
|
24421
|
+
if (data) {
|
|
24422
|
+
this.write(data, encoding);
|
|
24423
|
+
}
|
|
24424
|
+
this.writable = false;
|
|
24425
|
+
if (!this._buffers) {
|
|
24426
|
+
return;
|
|
24427
|
+
}
|
|
24428
|
+
if (this._buffers.length === 0) {
|
|
24429
|
+
this._end();
|
|
24430
|
+
} else {
|
|
24431
|
+
this._buffers.push(null);
|
|
24432
|
+
this._process();
|
|
24433
|
+
}
|
|
24434
|
+
};
|
|
24435
|
+
ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
|
|
24436
|
+
ChunkStream.prototype._end = function() {
|
|
24437
|
+
if (this._reads.length > 0) {
|
|
24438
|
+
this.emit("error", new Error("Unexpected end of input"));
|
|
24439
|
+
}
|
|
24440
|
+
this.destroy();
|
|
24441
|
+
};
|
|
24442
|
+
ChunkStream.prototype.destroy = function() {
|
|
24443
|
+
if (!this._buffers) {
|
|
24444
|
+
return;
|
|
24445
|
+
}
|
|
24446
|
+
this.writable = false;
|
|
24447
|
+
this._reads = null;
|
|
24448
|
+
this._buffers = null;
|
|
24449
|
+
this.emit("close");
|
|
24450
|
+
};
|
|
24451
|
+
ChunkStream.prototype._processReadAllowingLess = function(read) {
|
|
24452
|
+
this._reads.shift();
|
|
24453
|
+
let smallerBuf = this._buffers[0];
|
|
24454
|
+
if (smallerBuf.length > read.length) {
|
|
24455
|
+
this._buffered -= read.length;
|
|
24456
|
+
this._buffers[0] = smallerBuf.slice(read.length);
|
|
24457
|
+
read.func.call(this, smallerBuf.slice(0, read.length));
|
|
24458
|
+
} else {
|
|
24459
|
+
this._buffered -= smallerBuf.length;
|
|
24460
|
+
this._buffers.shift();
|
|
24461
|
+
read.func.call(this, smallerBuf);
|
|
24462
|
+
}
|
|
24463
|
+
};
|
|
24464
|
+
ChunkStream.prototype._processRead = function(read) {
|
|
24465
|
+
this._reads.shift();
|
|
24466
|
+
let pos = 0;
|
|
24467
|
+
let count = 0;
|
|
24468
|
+
let data = Buffer.alloc(read.length);
|
|
24469
|
+
while (pos < read.length) {
|
|
24470
|
+
let buf = this._buffers[count++];
|
|
24471
|
+
let len = Math.min(buf.length, read.length - pos);
|
|
24472
|
+
buf.copy(data, pos, 0, len);
|
|
24473
|
+
pos += len;
|
|
24474
|
+
if (len !== buf.length) {
|
|
24475
|
+
this._buffers[--count] = buf.slice(len);
|
|
24476
|
+
}
|
|
24477
|
+
}
|
|
24478
|
+
if (count > 0) {
|
|
24479
|
+
this._buffers.splice(0, count);
|
|
24480
|
+
}
|
|
24481
|
+
this._buffered -= read.length;
|
|
24482
|
+
read.func.call(this, data);
|
|
24483
|
+
};
|
|
24484
|
+
ChunkStream.prototype._process = function() {
|
|
24485
|
+
try {
|
|
24486
|
+
while (this._buffered > 0 && this._reads && this._reads.length > 0) {
|
|
24487
|
+
let read = this._reads[0];
|
|
24488
|
+
if (read.allowLess) {
|
|
24489
|
+
this._processReadAllowingLess(read);
|
|
24490
|
+
} else if (this._buffered >= read.length) {
|
|
24491
|
+
this._processRead(read);
|
|
24492
|
+
} else {
|
|
24493
|
+
break;
|
|
24494
|
+
}
|
|
24495
|
+
}
|
|
24496
|
+
if (this._buffers && !this.writable) {
|
|
24497
|
+
this._end();
|
|
24498
|
+
}
|
|
24499
|
+
} catch (ex) {
|
|
24500
|
+
this.emit("error", ex);
|
|
24501
|
+
}
|
|
24502
|
+
};
|
|
24503
|
+
});
|
|
24504
|
+
|
|
24505
|
+
// node_modules/pngjs/lib/interlace.js
|
|
24506
|
+
var require_interlace = __commonJS((exports) => {
|
|
24507
|
+
var imagePasses = [
|
|
24508
|
+
{
|
|
24509
|
+
x: [0],
|
|
24510
|
+
y: [0]
|
|
24511
|
+
},
|
|
24512
|
+
{
|
|
24513
|
+
x: [4],
|
|
24514
|
+
y: [0]
|
|
24515
|
+
},
|
|
24516
|
+
{
|
|
24517
|
+
x: [0, 4],
|
|
24518
|
+
y: [4]
|
|
24519
|
+
},
|
|
24520
|
+
{
|
|
24521
|
+
x: [2, 6],
|
|
24522
|
+
y: [0, 4]
|
|
24523
|
+
},
|
|
24524
|
+
{
|
|
24525
|
+
x: [0, 2, 4, 6],
|
|
24526
|
+
y: [2, 6]
|
|
24527
|
+
},
|
|
24528
|
+
{
|
|
24529
|
+
x: [1, 3, 5, 7],
|
|
24530
|
+
y: [0, 2, 4, 6]
|
|
24531
|
+
},
|
|
24532
|
+
{
|
|
24533
|
+
x: [0, 1, 2, 3, 4, 5, 6, 7],
|
|
24534
|
+
y: [1, 3, 5, 7]
|
|
24535
|
+
}
|
|
24536
|
+
];
|
|
24537
|
+
exports.getImagePasses = function(width, height) {
|
|
24538
|
+
let images = [];
|
|
24539
|
+
let xLeftOver = width % 8;
|
|
24540
|
+
let yLeftOver = height % 8;
|
|
24541
|
+
let xRepeats = (width - xLeftOver) / 8;
|
|
24542
|
+
let yRepeats = (height - yLeftOver) / 8;
|
|
24543
|
+
for (let i3 = 0;i3 < imagePasses.length; i3++) {
|
|
24544
|
+
let pass = imagePasses[i3];
|
|
24545
|
+
let passWidth = xRepeats * pass.x.length;
|
|
24546
|
+
let passHeight = yRepeats * pass.y.length;
|
|
24547
|
+
for (let j = 0;j < pass.x.length; j++) {
|
|
24548
|
+
if (pass.x[j] < xLeftOver) {
|
|
24549
|
+
passWidth++;
|
|
24550
|
+
} else {
|
|
24551
|
+
break;
|
|
24552
|
+
}
|
|
24553
|
+
}
|
|
24554
|
+
for (let j = 0;j < pass.y.length; j++) {
|
|
24555
|
+
if (pass.y[j] < yLeftOver) {
|
|
24556
|
+
passHeight++;
|
|
24557
|
+
} else {
|
|
24558
|
+
break;
|
|
24559
|
+
}
|
|
24560
|
+
}
|
|
24561
|
+
if (passWidth > 0 && passHeight > 0) {
|
|
24562
|
+
images.push({ width: passWidth, height: passHeight, index: i3 });
|
|
24563
|
+
}
|
|
24564
|
+
}
|
|
24565
|
+
return images;
|
|
24566
|
+
};
|
|
24567
|
+
exports.getInterlaceIterator = function(width) {
|
|
24568
|
+
return function(x3, y5, pass) {
|
|
24569
|
+
let outerXLeftOver = x3 % imagePasses[pass].x.length;
|
|
24570
|
+
let outerX = (x3 - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
|
|
24571
|
+
let outerYLeftOver = y5 % imagePasses[pass].y.length;
|
|
24572
|
+
let outerY = (y5 - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
|
|
24573
|
+
return outerX * 4 + outerY * width * 4;
|
|
24574
|
+
};
|
|
24575
|
+
};
|
|
24576
|
+
});
|
|
24577
|
+
|
|
24578
|
+
// node_modules/pngjs/lib/paeth-predictor.js
|
|
24579
|
+
var require_paeth_predictor = __commonJS((exports, module) => {
|
|
24580
|
+
module.exports = function paethPredictor(left, above, upLeft) {
|
|
24581
|
+
let paeth = left + above - upLeft;
|
|
24582
|
+
let pLeft = Math.abs(paeth - left);
|
|
24583
|
+
let pAbove = Math.abs(paeth - above);
|
|
24584
|
+
let pUpLeft = Math.abs(paeth - upLeft);
|
|
24585
|
+
if (pLeft <= pAbove && pLeft <= pUpLeft) {
|
|
24586
|
+
return left;
|
|
24587
|
+
}
|
|
24588
|
+
if (pAbove <= pUpLeft) {
|
|
24589
|
+
return above;
|
|
24590
|
+
}
|
|
24591
|
+
return upLeft;
|
|
24592
|
+
};
|
|
24593
|
+
});
|
|
24594
|
+
|
|
24595
|
+
// node_modules/pngjs/lib/filter-parse.js
|
|
24596
|
+
var require_filter_parse = __commonJS((exports, module) => {
|
|
24597
|
+
var interlaceUtils = require_interlace();
|
|
24598
|
+
var paethPredictor = require_paeth_predictor();
|
|
24599
|
+
function getByteWidth(width, bpp, depth) {
|
|
24600
|
+
let byteWidth = width * bpp;
|
|
24601
|
+
if (depth !== 8) {
|
|
24602
|
+
byteWidth = Math.ceil(byteWidth / (8 / depth));
|
|
24603
|
+
}
|
|
24604
|
+
return byteWidth;
|
|
24605
|
+
}
|
|
24606
|
+
var Filter = module.exports = function(bitmapInfo, dependencies) {
|
|
24607
|
+
let width = bitmapInfo.width;
|
|
24608
|
+
let height = bitmapInfo.height;
|
|
24609
|
+
let interlace = bitmapInfo.interlace;
|
|
24610
|
+
let bpp = bitmapInfo.bpp;
|
|
24611
|
+
let depth = bitmapInfo.depth;
|
|
24612
|
+
this.read = dependencies.read;
|
|
24613
|
+
this.write = dependencies.write;
|
|
24614
|
+
this.complete = dependencies.complete;
|
|
24615
|
+
this._imageIndex = 0;
|
|
24616
|
+
this._images = [];
|
|
24617
|
+
if (interlace) {
|
|
24618
|
+
let passes = interlaceUtils.getImagePasses(width, height);
|
|
24619
|
+
for (let i3 = 0;i3 < passes.length; i3++) {
|
|
24620
|
+
this._images.push({
|
|
24621
|
+
byteWidth: getByteWidth(passes[i3].width, bpp, depth),
|
|
24622
|
+
height: passes[i3].height,
|
|
24623
|
+
lineIndex: 0
|
|
24624
|
+
});
|
|
24625
|
+
}
|
|
24626
|
+
} else {
|
|
24627
|
+
this._images.push({
|
|
24628
|
+
byteWidth: getByteWidth(width, bpp, depth),
|
|
24629
|
+
height,
|
|
24630
|
+
lineIndex: 0
|
|
24631
|
+
});
|
|
24632
|
+
}
|
|
24633
|
+
if (depth === 8) {
|
|
24634
|
+
this._xComparison = bpp;
|
|
24635
|
+
} else if (depth === 16) {
|
|
24636
|
+
this._xComparison = bpp * 2;
|
|
24637
|
+
} else {
|
|
24638
|
+
this._xComparison = 1;
|
|
24639
|
+
}
|
|
24640
|
+
};
|
|
24641
|
+
Filter.prototype.start = function() {
|
|
24642
|
+
this.read(this._images[this._imageIndex].byteWidth + 1, this._reverseFilterLine.bind(this));
|
|
24643
|
+
};
|
|
24644
|
+
Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
|
|
24645
|
+
let xComparison = this._xComparison;
|
|
24646
|
+
let xBiggerThan = xComparison - 1;
|
|
24647
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
24648
|
+
let rawByte = rawData[1 + x3];
|
|
24649
|
+
let f1Left = x3 > xBiggerThan ? unfilteredLine[x3 - xComparison] : 0;
|
|
24650
|
+
unfilteredLine[x3] = rawByte + f1Left;
|
|
24651
|
+
}
|
|
24652
|
+
};
|
|
24653
|
+
Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
|
|
24654
|
+
let lastLine = this._lastLine;
|
|
24655
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
24656
|
+
let rawByte = rawData[1 + x3];
|
|
24657
|
+
let f2Up = lastLine ? lastLine[x3] : 0;
|
|
24658
|
+
unfilteredLine[x3] = rawByte + f2Up;
|
|
24659
|
+
}
|
|
24660
|
+
};
|
|
24661
|
+
Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
|
|
24662
|
+
let xComparison = this._xComparison;
|
|
24663
|
+
let xBiggerThan = xComparison - 1;
|
|
24664
|
+
let lastLine = this._lastLine;
|
|
24665
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
24666
|
+
let rawByte = rawData[1 + x3];
|
|
24667
|
+
let f3Up = lastLine ? lastLine[x3] : 0;
|
|
24668
|
+
let f3Left = x3 > xBiggerThan ? unfilteredLine[x3 - xComparison] : 0;
|
|
24669
|
+
let f3Add = Math.floor((f3Left + f3Up) / 2);
|
|
24670
|
+
unfilteredLine[x3] = rawByte + f3Add;
|
|
24671
|
+
}
|
|
24672
|
+
};
|
|
24673
|
+
Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
|
|
24674
|
+
let xComparison = this._xComparison;
|
|
24675
|
+
let xBiggerThan = xComparison - 1;
|
|
24676
|
+
let lastLine = this._lastLine;
|
|
24677
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
24678
|
+
let rawByte = rawData[1 + x3];
|
|
24679
|
+
let f4Up = lastLine ? lastLine[x3] : 0;
|
|
24680
|
+
let f4Left = x3 > xBiggerThan ? unfilteredLine[x3 - xComparison] : 0;
|
|
24681
|
+
let f4UpLeft = x3 > xBiggerThan && lastLine ? lastLine[x3 - xComparison] : 0;
|
|
24682
|
+
let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
|
|
24683
|
+
unfilteredLine[x3] = rawByte + f4Add;
|
|
24684
|
+
}
|
|
24685
|
+
};
|
|
24686
|
+
Filter.prototype._reverseFilterLine = function(rawData) {
|
|
24687
|
+
let filter = rawData[0];
|
|
24688
|
+
let unfilteredLine;
|
|
24689
|
+
let currentImage = this._images[this._imageIndex];
|
|
24690
|
+
let byteWidth = currentImage.byteWidth;
|
|
24691
|
+
if (filter === 0) {
|
|
24692
|
+
unfilteredLine = rawData.slice(1, byteWidth + 1);
|
|
24693
|
+
} else {
|
|
24694
|
+
unfilteredLine = Buffer.alloc(byteWidth);
|
|
24695
|
+
switch (filter) {
|
|
24696
|
+
case 1:
|
|
24697
|
+
this._unFilterType1(rawData, unfilteredLine, byteWidth);
|
|
24698
|
+
break;
|
|
24699
|
+
case 2:
|
|
24700
|
+
this._unFilterType2(rawData, unfilteredLine, byteWidth);
|
|
24701
|
+
break;
|
|
24702
|
+
case 3:
|
|
24703
|
+
this._unFilterType3(rawData, unfilteredLine, byteWidth);
|
|
24704
|
+
break;
|
|
24705
|
+
case 4:
|
|
24706
|
+
this._unFilterType4(rawData, unfilteredLine, byteWidth);
|
|
24707
|
+
break;
|
|
24708
|
+
default:
|
|
24709
|
+
throw new Error("Unrecognised filter type - " + filter);
|
|
24710
|
+
}
|
|
24711
|
+
}
|
|
24712
|
+
this.write(unfilteredLine);
|
|
24713
|
+
currentImage.lineIndex++;
|
|
24714
|
+
if (currentImage.lineIndex >= currentImage.height) {
|
|
24715
|
+
this._lastLine = null;
|
|
24716
|
+
this._imageIndex++;
|
|
24717
|
+
currentImage = this._images[this._imageIndex];
|
|
24718
|
+
} else {
|
|
24719
|
+
this._lastLine = unfilteredLine;
|
|
24720
|
+
}
|
|
24721
|
+
if (currentImage) {
|
|
24722
|
+
this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
|
|
24723
|
+
} else {
|
|
24724
|
+
this._lastLine = null;
|
|
24725
|
+
this.complete();
|
|
24726
|
+
}
|
|
24727
|
+
};
|
|
24728
|
+
});
|
|
24729
|
+
|
|
24730
|
+
// node_modules/pngjs/lib/filter-parse-async.js
|
|
24731
|
+
var require_filter_parse_async = __commonJS((exports, module) => {
|
|
24732
|
+
var util = __require("util");
|
|
24733
|
+
var ChunkStream = require_chunkstream();
|
|
24734
|
+
var Filter = require_filter_parse();
|
|
24735
|
+
var FilterAsync = module.exports = function(bitmapInfo) {
|
|
24736
|
+
ChunkStream.call(this);
|
|
24737
|
+
let buffers = [];
|
|
24738
|
+
let that = this;
|
|
24739
|
+
this._filter = new Filter(bitmapInfo, {
|
|
24740
|
+
read: this.read.bind(this),
|
|
24741
|
+
write: function(buffer) {
|
|
24742
|
+
buffers.push(buffer);
|
|
24743
|
+
},
|
|
24744
|
+
complete: function() {
|
|
24745
|
+
that.emit("complete", Buffer.concat(buffers));
|
|
24746
|
+
}
|
|
24747
|
+
});
|
|
24748
|
+
this._filter.start();
|
|
24749
|
+
};
|
|
24750
|
+
util.inherits(FilterAsync, ChunkStream);
|
|
24751
|
+
});
|
|
24752
|
+
|
|
24753
|
+
// node_modules/pngjs/lib/constants.js
|
|
24754
|
+
var require_constants = __commonJS((exports, module) => {
|
|
24755
|
+
module.exports = {
|
|
24756
|
+
PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
|
|
24757
|
+
TYPE_IHDR: 1229472850,
|
|
24758
|
+
TYPE_IEND: 1229278788,
|
|
24759
|
+
TYPE_IDAT: 1229209940,
|
|
24760
|
+
TYPE_PLTE: 1347179589,
|
|
24761
|
+
TYPE_tRNS: 1951551059,
|
|
24762
|
+
TYPE_gAMA: 1732332865,
|
|
24763
|
+
COLORTYPE_GRAYSCALE: 0,
|
|
24764
|
+
COLORTYPE_PALETTE: 1,
|
|
24765
|
+
COLORTYPE_COLOR: 2,
|
|
24766
|
+
COLORTYPE_ALPHA: 4,
|
|
24767
|
+
COLORTYPE_PALETTE_COLOR: 3,
|
|
24768
|
+
COLORTYPE_COLOR_ALPHA: 6,
|
|
24769
|
+
COLORTYPE_TO_BPP_MAP: {
|
|
24770
|
+
0: 1,
|
|
24771
|
+
2: 3,
|
|
24772
|
+
3: 1,
|
|
24773
|
+
4: 2,
|
|
24774
|
+
6: 4
|
|
24775
|
+
},
|
|
24776
|
+
GAMMA_DIVISION: 1e5
|
|
24777
|
+
};
|
|
24778
|
+
});
|
|
24779
|
+
|
|
24780
|
+
// node_modules/pngjs/lib/crc.js
|
|
24781
|
+
var require_crc = __commonJS((exports, module) => {
|
|
24782
|
+
var crcTable = [];
|
|
24783
|
+
(function() {
|
|
24784
|
+
for (let i3 = 0;i3 < 256; i3++) {
|
|
24785
|
+
let currentCrc = i3;
|
|
24786
|
+
for (let j = 0;j < 8; j++) {
|
|
24787
|
+
if (currentCrc & 1) {
|
|
24788
|
+
currentCrc = 3988292384 ^ currentCrc >>> 1;
|
|
24789
|
+
} else {
|
|
24790
|
+
currentCrc = currentCrc >>> 1;
|
|
24791
|
+
}
|
|
24792
|
+
}
|
|
24793
|
+
crcTable[i3] = currentCrc;
|
|
24794
|
+
}
|
|
24795
|
+
})();
|
|
24796
|
+
var CrcCalculator = module.exports = function() {
|
|
24797
|
+
this._crc = -1;
|
|
24798
|
+
};
|
|
24799
|
+
CrcCalculator.prototype.write = function(data) {
|
|
24800
|
+
for (let i3 = 0;i3 < data.length; i3++) {
|
|
24801
|
+
this._crc = crcTable[(this._crc ^ data[i3]) & 255] ^ this._crc >>> 8;
|
|
24802
|
+
}
|
|
24803
|
+
return true;
|
|
24804
|
+
};
|
|
24805
|
+
CrcCalculator.prototype.crc32 = function() {
|
|
24806
|
+
return this._crc ^ -1;
|
|
24807
|
+
};
|
|
24808
|
+
CrcCalculator.crc32 = function(buf) {
|
|
24809
|
+
let crc = -1;
|
|
24810
|
+
for (let i3 = 0;i3 < buf.length; i3++) {
|
|
24811
|
+
crc = crcTable[(crc ^ buf[i3]) & 255] ^ crc >>> 8;
|
|
24812
|
+
}
|
|
24813
|
+
return crc ^ -1;
|
|
24814
|
+
};
|
|
24815
|
+
});
|
|
24816
|
+
|
|
24817
|
+
// node_modules/pngjs/lib/parser.js
|
|
24818
|
+
var require_parser = __commonJS((exports, module) => {
|
|
24819
|
+
var constants = require_constants();
|
|
24820
|
+
var CrcCalculator = require_crc();
|
|
24821
|
+
var Parser = module.exports = function(options, dependencies) {
|
|
24822
|
+
this._options = options;
|
|
24823
|
+
options.checkCRC = options.checkCRC !== false;
|
|
24824
|
+
this._hasIHDR = false;
|
|
24825
|
+
this._hasIEND = false;
|
|
24826
|
+
this._emittedHeadersFinished = false;
|
|
24827
|
+
this._palette = [];
|
|
24828
|
+
this._colorType = 0;
|
|
24829
|
+
this._chunks = {};
|
|
24830
|
+
this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
|
|
24831
|
+
this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
|
|
24832
|
+
this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
|
|
24833
|
+
this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
|
|
24834
|
+
this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
|
|
24835
|
+
this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
|
|
24836
|
+
this.read = dependencies.read;
|
|
24837
|
+
this.error = dependencies.error;
|
|
24838
|
+
this.metadata = dependencies.metadata;
|
|
24839
|
+
this.gamma = dependencies.gamma;
|
|
24840
|
+
this.transColor = dependencies.transColor;
|
|
24841
|
+
this.palette = dependencies.palette;
|
|
24842
|
+
this.parsed = dependencies.parsed;
|
|
24843
|
+
this.inflateData = dependencies.inflateData;
|
|
24844
|
+
this.finished = dependencies.finished;
|
|
24845
|
+
this.simpleTransparency = dependencies.simpleTransparency;
|
|
24846
|
+
this.headersFinished = dependencies.headersFinished || function() {};
|
|
24847
|
+
};
|
|
24848
|
+
Parser.prototype.start = function() {
|
|
24849
|
+
this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
|
|
24850
|
+
};
|
|
24851
|
+
Parser.prototype._parseSignature = function(data) {
|
|
24852
|
+
let signature = constants.PNG_SIGNATURE;
|
|
24853
|
+
for (let i3 = 0;i3 < signature.length; i3++) {
|
|
24854
|
+
if (data[i3] !== signature[i3]) {
|
|
24855
|
+
this.error(new Error("Invalid file signature"));
|
|
24856
|
+
return;
|
|
24857
|
+
}
|
|
24858
|
+
}
|
|
24859
|
+
this.read(8, this._parseChunkBegin.bind(this));
|
|
24860
|
+
};
|
|
24861
|
+
Parser.prototype._parseChunkBegin = function(data) {
|
|
24862
|
+
let length = data.readUInt32BE(0);
|
|
24863
|
+
let type = data.readUInt32BE(4);
|
|
24864
|
+
let name = "";
|
|
24865
|
+
for (let i3 = 4;i3 < 8; i3++) {
|
|
24866
|
+
name += String.fromCharCode(data[i3]);
|
|
24867
|
+
}
|
|
24868
|
+
let ancillary = Boolean(data[4] & 32);
|
|
24869
|
+
if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
|
|
24870
|
+
this.error(new Error("Expected IHDR on beggining"));
|
|
24871
|
+
return;
|
|
24872
|
+
}
|
|
24873
|
+
this._crc = new CrcCalculator;
|
|
24874
|
+
this._crc.write(Buffer.from(name));
|
|
24875
|
+
if (this._chunks[type]) {
|
|
24876
|
+
return this._chunks[type](length);
|
|
24877
|
+
}
|
|
24878
|
+
if (!ancillary) {
|
|
24879
|
+
this.error(new Error("Unsupported critical chunk type " + name));
|
|
24880
|
+
return;
|
|
24881
|
+
}
|
|
24882
|
+
this.read(length + 4, this._skipChunk.bind(this));
|
|
24883
|
+
};
|
|
24884
|
+
Parser.prototype._skipChunk = function() {
|
|
24885
|
+
this.read(8, this._parseChunkBegin.bind(this));
|
|
24886
|
+
};
|
|
24887
|
+
Parser.prototype._handleChunkEnd = function() {
|
|
24888
|
+
this.read(4, this._parseChunkEnd.bind(this));
|
|
24889
|
+
};
|
|
24890
|
+
Parser.prototype._parseChunkEnd = function(data) {
|
|
24891
|
+
let fileCrc = data.readInt32BE(0);
|
|
24892
|
+
let calcCrc = this._crc.crc32();
|
|
24893
|
+
if (this._options.checkCRC && calcCrc !== fileCrc) {
|
|
24894
|
+
this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
|
|
24895
|
+
return;
|
|
24896
|
+
}
|
|
24897
|
+
if (!this._hasIEND) {
|
|
24898
|
+
this.read(8, this._parseChunkBegin.bind(this));
|
|
24899
|
+
}
|
|
24900
|
+
};
|
|
24901
|
+
Parser.prototype._handleIHDR = function(length) {
|
|
24902
|
+
this.read(length, this._parseIHDR.bind(this));
|
|
24903
|
+
};
|
|
24904
|
+
Parser.prototype._parseIHDR = function(data) {
|
|
24905
|
+
this._crc.write(data);
|
|
24906
|
+
let width = data.readUInt32BE(0);
|
|
24907
|
+
let height = data.readUInt32BE(4);
|
|
24908
|
+
let depth = data[8];
|
|
24909
|
+
let colorType = data[9];
|
|
24910
|
+
let compr = data[10];
|
|
24911
|
+
let filter = data[11];
|
|
24912
|
+
let interlace = data[12];
|
|
24913
|
+
if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
|
|
24914
|
+
this.error(new Error("Unsupported bit depth " + depth));
|
|
24915
|
+
return;
|
|
24916
|
+
}
|
|
24917
|
+
if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
|
|
24918
|
+
this.error(new Error("Unsupported color type"));
|
|
24919
|
+
return;
|
|
24920
|
+
}
|
|
24921
|
+
if (compr !== 0) {
|
|
24922
|
+
this.error(new Error("Unsupported compression method"));
|
|
24923
|
+
return;
|
|
24924
|
+
}
|
|
24925
|
+
if (filter !== 0) {
|
|
24926
|
+
this.error(new Error("Unsupported filter method"));
|
|
24927
|
+
return;
|
|
24928
|
+
}
|
|
24929
|
+
if (interlace !== 0 && interlace !== 1) {
|
|
24930
|
+
this.error(new Error("Unsupported interlace method"));
|
|
24931
|
+
return;
|
|
24932
|
+
}
|
|
24933
|
+
this._colorType = colorType;
|
|
24934
|
+
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
|
|
24935
|
+
this._hasIHDR = true;
|
|
24936
|
+
this.metadata({
|
|
24937
|
+
width,
|
|
24938
|
+
height,
|
|
24939
|
+
depth,
|
|
24940
|
+
interlace: Boolean(interlace),
|
|
24941
|
+
palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
|
|
24942
|
+
color: Boolean(colorType & constants.COLORTYPE_COLOR),
|
|
24943
|
+
alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
|
|
24944
|
+
bpp,
|
|
24945
|
+
colorType
|
|
24946
|
+
});
|
|
24947
|
+
this._handleChunkEnd();
|
|
24948
|
+
};
|
|
24949
|
+
Parser.prototype._handlePLTE = function(length) {
|
|
24950
|
+
this.read(length, this._parsePLTE.bind(this));
|
|
24951
|
+
};
|
|
24952
|
+
Parser.prototype._parsePLTE = function(data) {
|
|
24953
|
+
this._crc.write(data);
|
|
24954
|
+
let entries = Math.floor(data.length / 3);
|
|
24955
|
+
for (let i3 = 0;i3 < entries; i3++) {
|
|
24956
|
+
this._palette.push([data[i3 * 3], data[i3 * 3 + 1], data[i3 * 3 + 2], 255]);
|
|
24957
|
+
}
|
|
24958
|
+
this.palette(this._palette);
|
|
24959
|
+
this._handleChunkEnd();
|
|
24960
|
+
};
|
|
24961
|
+
Parser.prototype._handleTRNS = function(length) {
|
|
24962
|
+
this.simpleTransparency();
|
|
24963
|
+
this.read(length, this._parseTRNS.bind(this));
|
|
24964
|
+
};
|
|
24965
|
+
Parser.prototype._parseTRNS = function(data) {
|
|
24966
|
+
this._crc.write(data);
|
|
24967
|
+
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
|
|
24968
|
+
if (this._palette.length === 0) {
|
|
24969
|
+
this.error(new Error("Transparency chunk must be after palette"));
|
|
24970
|
+
return;
|
|
24971
|
+
}
|
|
24972
|
+
if (data.length > this._palette.length) {
|
|
24973
|
+
this.error(new Error("More transparent colors than palette size"));
|
|
24974
|
+
return;
|
|
24975
|
+
}
|
|
24976
|
+
for (let i3 = 0;i3 < data.length; i3++) {
|
|
24977
|
+
this._palette[i3][3] = data[i3];
|
|
24978
|
+
}
|
|
24979
|
+
this.palette(this._palette);
|
|
24980
|
+
}
|
|
24981
|
+
if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
|
|
24982
|
+
this.transColor([data.readUInt16BE(0)]);
|
|
24983
|
+
}
|
|
24984
|
+
if (this._colorType === constants.COLORTYPE_COLOR) {
|
|
24985
|
+
this.transColor([
|
|
24986
|
+
data.readUInt16BE(0),
|
|
24987
|
+
data.readUInt16BE(2),
|
|
24988
|
+
data.readUInt16BE(4)
|
|
24989
|
+
]);
|
|
24990
|
+
}
|
|
24991
|
+
this._handleChunkEnd();
|
|
24992
|
+
};
|
|
24993
|
+
Parser.prototype._handleGAMA = function(length) {
|
|
24994
|
+
this.read(length, this._parseGAMA.bind(this));
|
|
24995
|
+
};
|
|
24996
|
+
Parser.prototype._parseGAMA = function(data) {
|
|
24997
|
+
this._crc.write(data);
|
|
24998
|
+
this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
|
|
24999
|
+
this._handleChunkEnd();
|
|
25000
|
+
};
|
|
25001
|
+
Parser.prototype._handleIDAT = function(length) {
|
|
25002
|
+
if (!this._emittedHeadersFinished) {
|
|
25003
|
+
this._emittedHeadersFinished = true;
|
|
25004
|
+
this.headersFinished();
|
|
25005
|
+
}
|
|
25006
|
+
this.read(-length, this._parseIDAT.bind(this, length));
|
|
25007
|
+
};
|
|
25008
|
+
Parser.prototype._parseIDAT = function(length, data) {
|
|
25009
|
+
this._crc.write(data);
|
|
25010
|
+
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
|
|
25011
|
+
throw new Error("Expected palette not found");
|
|
25012
|
+
}
|
|
25013
|
+
this.inflateData(data);
|
|
25014
|
+
let leftOverLength = length - data.length;
|
|
25015
|
+
if (leftOverLength > 0) {
|
|
25016
|
+
this._handleIDAT(leftOverLength);
|
|
25017
|
+
} else {
|
|
25018
|
+
this._handleChunkEnd();
|
|
25019
|
+
}
|
|
25020
|
+
};
|
|
25021
|
+
Parser.prototype._handleIEND = function(length) {
|
|
25022
|
+
this.read(length, this._parseIEND.bind(this));
|
|
25023
|
+
};
|
|
25024
|
+
Parser.prototype._parseIEND = function(data) {
|
|
25025
|
+
this._crc.write(data);
|
|
25026
|
+
this._hasIEND = true;
|
|
25027
|
+
this._handleChunkEnd();
|
|
25028
|
+
if (this.finished) {
|
|
25029
|
+
this.finished();
|
|
25030
|
+
}
|
|
25031
|
+
};
|
|
25032
|
+
});
|
|
25033
|
+
|
|
25034
|
+
// node_modules/pngjs/lib/bitmapper.js
|
|
25035
|
+
var require_bitmapper = __commonJS((exports) => {
|
|
25036
|
+
var interlaceUtils = require_interlace();
|
|
25037
|
+
var pixelBppMapper = [
|
|
25038
|
+
function() {},
|
|
25039
|
+
function(pxData, data, pxPos, rawPos) {
|
|
25040
|
+
if (rawPos === data.length) {
|
|
25041
|
+
throw new Error("Ran out of data");
|
|
25042
|
+
}
|
|
25043
|
+
let pixel = data[rawPos];
|
|
25044
|
+
pxData[pxPos] = pixel;
|
|
25045
|
+
pxData[pxPos + 1] = pixel;
|
|
25046
|
+
pxData[pxPos + 2] = pixel;
|
|
25047
|
+
pxData[pxPos + 3] = 255;
|
|
25048
|
+
},
|
|
25049
|
+
function(pxData, data, pxPos, rawPos) {
|
|
25050
|
+
if (rawPos + 1 >= data.length) {
|
|
25051
|
+
throw new Error("Ran out of data");
|
|
25052
|
+
}
|
|
25053
|
+
let pixel = data[rawPos];
|
|
25054
|
+
pxData[pxPos] = pixel;
|
|
25055
|
+
pxData[pxPos + 1] = pixel;
|
|
25056
|
+
pxData[pxPos + 2] = pixel;
|
|
25057
|
+
pxData[pxPos + 3] = data[rawPos + 1];
|
|
25058
|
+
},
|
|
25059
|
+
function(pxData, data, pxPos, rawPos) {
|
|
25060
|
+
if (rawPos + 2 >= data.length) {
|
|
25061
|
+
throw new Error("Ran out of data");
|
|
25062
|
+
}
|
|
25063
|
+
pxData[pxPos] = data[rawPos];
|
|
25064
|
+
pxData[pxPos + 1] = data[rawPos + 1];
|
|
25065
|
+
pxData[pxPos + 2] = data[rawPos + 2];
|
|
25066
|
+
pxData[pxPos + 3] = 255;
|
|
25067
|
+
},
|
|
25068
|
+
function(pxData, data, pxPos, rawPos) {
|
|
25069
|
+
if (rawPos + 3 >= data.length) {
|
|
25070
|
+
throw new Error("Ran out of data");
|
|
25071
|
+
}
|
|
25072
|
+
pxData[pxPos] = data[rawPos];
|
|
25073
|
+
pxData[pxPos + 1] = data[rawPos + 1];
|
|
25074
|
+
pxData[pxPos + 2] = data[rawPos + 2];
|
|
25075
|
+
pxData[pxPos + 3] = data[rawPos + 3];
|
|
25076
|
+
}
|
|
25077
|
+
];
|
|
25078
|
+
var pixelBppCustomMapper = [
|
|
25079
|
+
function() {},
|
|
25080
|
+
function(pxData, pixelData, pxPos, maxBit) {
|
|
25081
|
+
let pixel = pixelData[0];
|
|
25082
|
+
pxData[pxPos] = pixel;
|
|
25083
|
+
pxData[pxPos + 1] = pixel;
|
|
25084
|
+
pxData[pxPos + 2] = pixel;
|
|
25085
|
+
pxData[pxPos + 3] = maxBit;
|
|
25086
|
+
},
|
|
25087
|
+
function(pxData, pixelData, pxPos) {
|
|
25088
|
+
let pixel = pixelData[0];
|
|
25089
|
+
pxData[pxPos] = pixel;
|
|
25090
|
+
pxData[pxPos + 1] = pixel;
|
|
25091
|
+
pxData[pxPos + 2] = pixel;
|
|
25092
|
+
pxData[pxPos + 3] = pixelData[1];
|
|
25093
|
+
},
|
|
25094
|
+
function(pxData, pixelData, pxPos, maxBit) {
|
|
25095
|
+
pxData[pxPos] = pixelData[0];
|
|
25096
|
+
pxData[pxPos + 1] = pixelData[1];
|
|
25097
|
+
pxData[pxPos + 2] = pixelData[2];
|
|
25098
|
+
pxData[pxPos + 3] = maxBit;
|
|
25099
|
+
},
|
|
25100
|
+
function(pxData, pixelData, pxPos) {
|
|
25101
|
+
pxData[pxPos] = pixelData[0];
|
|
25102
|
+
pxData[pxPos + 1] = pixelData[1];
|
|
25103
|
+
pxData[pxPos + 2] = pixelData[2];
|
|
25104
|
+
pxData[pxPos + 3] = pixelData[3];
|
|
25105
|
+
}
|
|
25106
|
+
];
|
|
25107
|
+
function bitRetriever(data, depth) {
|
|
25108
|
+
let leftOver = [];
|
|
25109
|
+
let i3 = 0;
|
|
25110
|
+
function split() {
|
|
25111
|
+
if (i3 === data.length) {
|
|
25112
|
+
throw new Error("Ran out of data");
|
|
25113
|
+
}
|
|
25114
|
+
let byte = data[i3];
|
|
25115
|
+
i3++;
|
|
25116
|
+
let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
|
|
25117
|
+
switch (depth) {
|
|
25118
|
+
default:
|
|
25119
|
+
throw new Error("unrecognised depth");
|
|
25120
|
+
case 16:
|
|
25121
|
+
byte2 = data[i3];
|
|
25122
|
+
i3++;
|
|
25123
|
+
leftOver.push((byte << 8) + byte2);
|
|
25124
|
+
break;
|
|
25125
|
+
case 4:
|
|
25126
|
+
byte2 = byte & 15;
|
|
25127
|
+
byte1 = byte >> 4;
|
|
25128
|
+
leftOver.push(byte1, byte2);
|
|
25129
|
+
break;
|
|
25130
|
+
case 2:
|
|
25131
|
+
byte4 = byte & 3;
|
|
25132
|
+
byte3 = byte >> 2 & 3;
|
|
25133
|
+
byte2 = byte >> 4 & 3;
|
|
25134
|
+
byte1 = byte >> 6 & 3;
|
|
25135
|
+
leftOver.push(byte1, byte2, byte3, byte4);
|
|
25136
|
+
break;
|
|
25137
|
+
case 1:
|
|
25138
|
+
byte8 = byte & 1;
|
|
25139
|
+
byte7 = byte >> 1 & 1;
|
|
25140
|
+
byte6 = byte >> 2 & 1;
|
|
25141
|
+
byte5 = byte >> 3 & 1;
|
|
25142
|
+
byte4 = byte >> 4 & 1;
|
|
25143
|
+
byte3 = byte >> 5 & 1;
|
|
25144
|
+
byte2 = byte >> 6 & 1;
|
|
25145
|
+
byte1 = byte >> 7 & 1;
|
|
25146
|
+
leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
|
|
25147
|
+
break;
|
|
25148
|
+
}
|
|
25149
|
+
}
|
|
25150
|
+
return {
|
|
25151
|
+
get: function(count) {
|
|
25152
|
+
while (leftOver.length < count) {
|
|
25153
|
+
split();
|
|
25154
|
+
}
|
|
25155
|
+
let returner = leftOver.slice(0, count);
|
|
25156
|
+
leftOver = leftOver.slice(count);
|
|
25157
|
+
return returner;
|
|
25158
|
+
},
|
|
25159
|
+
resetAfterLine: function() {
|
|
25160
|
+
leftOver.length = 0;
|
|
25161
|
+
},
|
|
25162
|
+
end: function() {
|
|
25163
|
+
if (i3 !== data.length) {
|
|
25164
|
+
throw new Error("extra data found");
|
|
25165
|
+
}
|
|
25166
|
+
}
|
|
25167
|
+
};
|
|
25168
|
+
}
|
|
25169
|
+
function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
|
|
25170
|
+
let imageWidth = image.width;
|
|
25171
|
+
let imageHeight = image.height;
|
|
25172
|
+
let imagePass = image.index;
|
|
25173
|
+
for (let y5 = 0;y5 < imageHeight; y5++) {
|
|
25174
|
+
for (let x3 = 0;x3 < imageWidth; x3++) {
|
|
25175
|
+
let pxPos = getPxPos(x3, y5, imagePass);
|
|
25176
|
+
pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
|
|
25177
|
+
rawPos += bpp;
|
|
25178
|
+
}
|
|
25179
|
+
}
|
|
25180
|
+
return rawPos;
|
|
25181
|
+
}
|
|
25182
|
+
function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
|
|
25183
|
+
let imageWidth = image.width;
|
|
25184
|
+
let imageHeight = image.height;
|
|
25185
|
+
let imagePass = image.index;
|
|
25186
|
+
for (let y5 = 0;y5 < imageHeight; y5++) {
|
|
25187
|
+
for (let x3 = 0;x3 < imageWidth; x3++) {
|
|
25188
|
+
let pixelData = bits.get(bpp);
|
|
25189
|
+
let pxPos = getPxPos(x3, y5, imagePass);
|
|
25190
|
+
pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
|
|
25191
|
+
}
|
|
25192
|
+
bits.resetAfterLine();
|
|
25193
|
+
}
|
|
25194
|
+
}
|
|
25195
|
+
exports.dataToBitMap = function(data, bitmapInfo) {
|
|
25196
|
+
let width = bitmapInfo.width;
|
|
25197
|
+
let height = bitmapInfo.height;
|
|
25198
|
+
let depth = bitmapInfo.depth;
|
|
25199
|
+
let bpp = bitmapInfo.bpp;
|
|
25200
|
+
let interlace = bitmapInfo.interlace;
|
|
25201
|
+
let bits;
|
|
25202
|
+
if (depth !== 8) {
|
|
25203
|
+
bits = bitRetriever(data, depth);
|
|
25204
|
+
}
|
|
25205
|
+
let pxData;
|
|
25206
|
+
if (depth <= 8) {
|
|
25207
|
+
pxData = Buffer.alloc(width * height * 4);
|
|
25208
|
+
} else {
|
|
25209
|
+
pxData = new Uint16Array(width * height * 4);
|
|
25210
|
+
}
|
|
25211
|
+
let maxBit = Math.pow(2, depth) - 1;
|
|
25212
|
+
let rawPos = 0;
|
|
25213
|
+
let images;
|
|
25214
|
+
let getPxPos;
|
|
25215
|
+
if (interlace) {
|
|
25216
|
+
images = interlaceUtils.getImagePasses(width, height);
|
|
25217
|
+
getPxPos = interlaceUtils.getInterlaceIterator(width, height);
|
|
25218
|
+
} else {
|
|
25219
|
+
let nonInterlacedPxPos = 0;
|
|
25220
|
+
getPxPos = function() {
|
|
25221
|
+
let returner = nonInterlacedPxPos;
|
|
25222
|
+
nonInterlacedPxPos += 4;
|
|
25223
|
+
return returner;
|
|
25224
|
+
};
|
|
25225
|
+
images = [{ width, height }];
|
|
25226
|
+
}
|
|
25227
|
+
for (let imageIndex = 0;imageIndex < images.length; imageIndex++) {
|
|
25228
|
+
if (depth === 8) {
|
|
25229
|
+
rawPos = mapImage8Bit(images[imageIndex], pxData, getPxPos, bpp, data, rawPos);
|
|
25230
|
+
} else {
|
|
25231
|
+
mapImageCustomBit(images[imageIndex], pxData, getPxPos, bpp, bits, maxBit);
|
|
25232
|
+
}
|
|
25233
|
+
}
|
|
25234
|
+
if (depth === 8) {
|
|
25235
|
+
if (rawPos !== data.length) {
|
|
25236
|
+
throw new Error("extra data found");
|
|
25237
|
+
}
|
|
25238
|
+
} else {
|
|
25239
|
+
bits.end();
|
|
25240
|
+
}
|
|
25241
|
+
return pxData;
|
|
25242
|
+
};
|
|
25243
|
+
});
|
|
25244
|
+
|
|
25245
|
+
// node_modules/pngjs/lib/format-normaliser.js
|
|
25246
|
+
var require_format_normaliser = __commonJS((exports, module) => {
|
|
25247
|
+
function dePalette(indata, outdata, width, height, palette) {
|
|
25248
|
+
let pxPos = 0;
|
|
25249
|
+
for (let y5 = 0;y5 < height; y5++) {
|
|
25250
|
+
for (let x3 = 0;x3 < width; x3++) {
|
|
25251
|
+
let color = palette[indata[pxPos]];
|
|
25252
|
+
if (!color) {
|
|
25253
|
+
throw new Error("index " + indata[pxPos] + " not in palette");
|
|
25254
|
+
}
|
|
25255
|
+
for (let i3 = 0;i3 < 4; i3++) {
|
|
25256
|
+
outdata[pxPos + i3] = color[i3];
|
|
25257
|
+
}
|
|
25258
|
+
pxPos += 4;
|
|
25259
|
+
}
|
|
25260
|
+
}
|
|
25261
|
+
}
|
|
25262
|
+
function replaceTransparentColor(indata, outdata, width, height, transColor) {
|
|
25263
|
+
let pxPos = 0;
|
|
25264
|
+
for (let y5 = 0;y5 < height; y5++) {
|
|
25265
|
+
for (let x3 = 0;x3 < width; x3++) {
|
|
25266
|
+
let makeTrans = false;
|
|
25267
|
+
if (transColor.length === 1) {
|
|
25268
|
+
if (transColor[0] === indata[pxPos]) {
|
|
25269
|
+
makeTrans = true;
|
|
25270
|
+
}
|
|
25271
|
+
} else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
|
|
25272
|
+
makeTrans = true;
|
|
25273
|
+
}
|
|
25274
|
+
if (makeTrans) {
|
|
25275
|
+
for (let i3 = 0;i3 < 4; i3++) {
|
|
25276
|
+
outdata[pxPos + i3] = 0;
|
|
25277
|
+
}
|
|
25278
|
+
}
|
|
25279
|
+
pxPos += 4;
|
|
25280
|
+
}
|
|
25281
|
+
}
|
|
25282
|
+
}
|
|
25283
|
+
function scaleDepth(indata, outdata, width, height, depth) {
|
|
25284
|
+
let maxOutSample = 255;
|
|
25285
|
+
let maxInSample = Math.pow(2, depth) - 1;
|
|
25286
|
+
let pxPos = 0;
|
|
25287
|
+
for (let y5 = 0;y5 < height; y5++) {
|
|
25288
|
+
for (let x3 = 0;x3 < width; x3++) {
|
|
25289
|
+
for (let i3 = 0;i3 < 4; i3++) {
|
|
25290
|
+
outdata[pxPos + i3] = Math.floor(indata[pxPos + i3] * maxOutSample / maxInSample + 0.5);
|
|
25291
|
+
}
|
|
25292
|
+
pxPos += 4;
|
|
25293
|
+
}
|
|
25294
|
+
}
|
|
25295
|
+
}
|
|
25296
|
+
module.exports = function(indata, imageData, skipRescale = false) {
|
|
25297
|
+
let depth = imageData.depth;
|
|
25298
|
+
let width = imageData.width;
|
|
25299
|
+
let height = imageData.height;
|
|
25300
|
+
let colorType = imageData.colorType;
|
|
25301
|
+
let transColor = imageData.transColor;
|
|
25302
|
+
let palette = imageData.palette;
|
|
25303
|
+
let outdata = indata;
|
|
25304
|
+
if (colorType === 3) {
|
|
25305
|
+
dePalette(indata, outdata, width, height, palette);
|
|
25306
|
+
} else {
|
|
25307
|
+
if (transColor) {
|
|
25308
|
+
replaceTransparentColor(indata, outdata, width, height, transColor);
|
|
25309
|
+
}
|
|
25310
|
+
if (depth !== 8 && !skipRescale) {
|
|
25311
|
+
if (depth === 16) {
|
|
25312
|
+
outdata = Buffer.alloc(width * height * 4);
|
|
25313
|
+
}
|
|
25314
|
+
scaleDepth(indata, outdata, width, height, depth);
|
|
25315
|
+
}
|
|
25316
|
+
}
|
|
25317
|
+
return outdata;
|
|
25318
|
+
};
|
|
25319
|
+
});
|
|
25320
|
+
|
|
25321
|
+
// node_modules/pngjs/lib/parser-async.js
|
|
25322
|
+
var require_parser_async = __commonJS((exports, module) => {
|
|
25323
|
+
var util = __require("util");
|
|
25324
|
+
var zlib = __require("zlib");
|
|
25325
|
+
var ChunkStream = require_chunkstream();
|
|
25326
|
+
var FilterAsync = require_filter_parse_async();
|
|
25327
|
+
var Parser = require_parser();
|
|
25328
|
+
var bitmapper = require_bitmapper();
|
|
25329
|
+
var formatNormaliser = require_format_normaliser();
|
|
25330
|
+
var ParserAsync = module.exports = function(options) {
|
|
25331
|
+
ChunkStream.call(this);
|
|
25332
|
+
this._parser = new Parser(options, {
|
|
25333
|
+
read: this.read.bind(this),
|
|
25334
|
+
error: this._handleError.bind(this),
|
|
25335
|
+
metadata: this._handleMetaData.bind(this),
|
|
25336
|
+
gamma: this.emit.bind(this, "gamma"),
|
|
25337
|
+
palette: this._handlePalette.bind(this),
|
|
25338
|
+
transColor: this._handleTransColor.bind(this),
|
|
25339
|
+
finished: this._finished.bind(this),
|
|
25340
|
+
inflateData: this._inflateData.bind(this),
|
|
25341
|
+
simpleTransparency: this._simpleTransparency.bind(this),
|
|
25342
|
+
headersFinished: this._headersFinished.bind(this)
|
|
25343
|
+
});
|
|
25344
|
+
this._options = options;
|
|
25345
|
+
this.writable = true;
|
|
25346
|
+
this._parser.start();
|
|
25347
|
+
};
|
|
25348
|
+
util.inherits(ParserAsync, ChunkStream);
|
|
25349
|
+
ParserAsync.prototype._handleError = function(err) {
|
|
25350
|
+
this.emit("error", err);
|
|
25351
|
+
this.writable = false;
|
|
25352
|
+
this.destroy();
|
|
25353
|
+
if (this._inflate && this._inflate.destroy) {
|
|
25354
|
+
this._inflate.destroy();
|
|
25355
|
+
}
|
|
25356
|
+
if (this._filter) {
|
|
25357
|
+
this._filter.destroy();
|
|
25358
|
+
this._filter.on("error", function() {});
|
|
25359
|
+
}
|
|
25360
|
+
this.errord = true;
|
|
25361
|
+
};
|
|
25362
|
+
ParserAsync.prototype._inflateData = function(data) {
|
|
25363
|
+
if (!this._inflate) {
|
|
25364
|
+
if (this._bitmapInfo.interlace) {
|
|
25365
|
+
this._inflate = zlib.createInflate();
|
|
25366
|
+
this._inflate.on("error", this.emit.bind(this, "error"));
|
|
25367
|
+
this._filter.on("complete", this._complete.bind(this));
|
|
25368
|
+
this._inflate.pipe(this._filter);
|
|
25369
|
+
} else {
|
|
25370
|
+
let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
|
|
25371
|
+
let imageSize = rowSize * this._bitmapInfo.height;
|
|
25372
|
+
let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
|
|
25373
|
+
this._inflate = zlib.createInflate({ chunkSize });
|
|
25374
|
+
let leftToInflate = imageSize;
|
|
25375
|
+
let emitError = this.emit.bind(this, "error");
|
|
25376
|
+
this._inflate.on("error", function(err) {
|
|
25377
|
+
if (!leftToInflate) {
|
|
25378
|
+
return;
|
|
25379
|
+
}
|
|
25380
|
+
emitError(err);
|
|
25381
|
+
});
|
|
25382
|
+
this._filter.on("complete", this._complete.bind(this));
|
|
25383
|
+
let filterWrite = this._filter.write.bind(this._filter);
|
|
25384
|
+
this._inflate.on("data", function(chunk) {
|
|
25385
|
+
if (!leftToInflate) {
|
|
25386
|
+
return;
|
|
25387
|
+
}
|
|
25388
|
+
if (chunk.length > leftToInflate) {
|
|
25389
|
+
chunk = chunk.slice(0, leftToInflate);
|
|
25390
|
+
}
|
|
25391
|
+
leftToInflate -= chunk.length;
|
|
25392
|
+
filterWrite(chunk);
|
|
25393
|
+
});
|
|
25394
|
+
this._inflate.on("end", this._filter.end.bind(this._filter));
|
|
25395
|
+
}
|
|
25396
|
+
}
|
|
25397
|
+
this._inflate.write(data);
|
|
25398
|
+
};
|
|
25399
|
+
ParserAsync.prototype._handleMetaData = function(metaData) {
|
|
25400
|
+
this._metaData = metaData;
|
|
25401
|
+
this._bitmapInfo = Object.create(metaData);
|
|
25402
|
+
this._filter = new FilterAsync(this._bitmapInfo);
|
|
25403
|
+
};
|
|
25404
|
+
ParserAsync.prototype._handleTransColor = function(transColor) {
|
|
25405
|
+
this._bitmapInfo.transColor = transColor;
|
|
25406
|
+
};
|
|
25407
|
+
ParserAsync.prototype._handlePalette = function(palette) {
|
|
25408
|
+
this._bitmapInfo.palette = palette;
|
|
25409
|
+
};
|
|
25410
|
+
ParserAsync.prototype._simpleTransparency = function() {
|
|
25411
|
+
this._metaData.alpha = true;
|
|
25412
|
+
};
|
|
25413
|
+
ParserAsync.prototype._headersFinished = function() {
|
|
25414
|
+
this.emit("metadata", this._metaData);
|
|
25415
|
+
};
|
|
25416
|
+
ParserAsync.prototype._finished = function() {
|
|
25417
|
+
if (this.errord) {
|
|
25418
|
+
return;
|
|
25419
|
+
}
|
|
25420
|
+
if (!this._inflate) {
|
|
25421
|
+
this.emit("error", "No Inflate block");
|
|
25422
|
+
} else {
|
|
25423
|
+
this._inflate.end();
|
|
25424
|
+
}
|
|
25425
|
+
};
|
|
25426
|
+
ParserAsync.prototype._complete = function(filteredData) {
|
|
25427
|
+
if (this.errord) {
|
|
25428
|
+
return;
|
|
25429
|
+
}
|
|
25430
|
+
let normalisedBitmapData;
|
|
25431
|
+
try {
|
|
25432
|
+
let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
|
|
25433
|
+
normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo, this._options.skipRescale);
|
|
25434
|
+
bitmapData = null;
|
|
25435
|
+
} catch (ex) {
|
|
25436
|
+
this._handleError(ex);
|
|
25437
|
+
return;
|
|
25438
|
+
}
|
|
25439
|
+
this.emit("parsed", normalisedBitmapData);
|
|
25440
|
+
};
|
|
25441
|
+
});
|
|
25442
|
+
|
|
25443
|
+
// node_modules/pngjs/lib/bitpacker.js
|
|
25444
|
+
var require_bitpacker = __commonJS((exports, module) => {
|
|
25445
|
+
var constants = require_constants();
|
|
25446
|
+
module.exports = function(dataIn, width, height, options) {
|
|
25447
|
+
let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(options.colorType) !== -1;
|
|
25448
|
+
if (options.colorType === options.inputColorType) {
|
|
25449
|
+
let bigEndian = function() {
|
|
25450
|
+
let buffer = new ArrayBuffer(2);
|
|
25451
|
+
new DataView(buffer).setInt16(0, 256, true);
|
|
25452
|
+
return new Int16Array(buffer)[0] !== 256;
|
|
25453
|
+
}();
|
|
25454
|
+
if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
|
|
25455
|
+
return dataIn;
|
|
25456
|
+
}
|
|
25457
|
+
}
|
|
25458
|
+
let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
|
|
25459
|
+
let maxValue = 255;
|
|
25460
|
+
let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
|
|
25461
|
+
if (inBpp === 4 && !options.inputHasAlpha) {
|
|
25462
|
+
inBpp = 3;
|
|
25463
|
+
}
|
|
25464
|
+
let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
|
|
25465
|
+
if (options.bitDepth === 16) {
|
|
25466
|
+
maxValue = 65535;
|
|
25467
|
+
outBpp *= 2;
|
|
25468
|
+
}
|
|
25469
|
+
let outData = Buffer.alloc(width * height * outBpp);
|
|
25470
|
+
let inIndex = 0;
|
|
25471
|
+
let outIndex = 0;
|
|
25472
|
+
let bgColor = options.bgColor || {};
|
|
25473
|
+
if (bgColor.red === undefined) {
|
|
25474
|
+
bgColor.red = maxValue;
|
|
25475
|
+
}
|
|
25476
|
+
if (bgColor.green === undefined) {
|
|
25477
|
+
bgColor.green = maxValue;
|
|
25478
|
+
}
|
|
25479
|
+
if (bgColor.blue === undefined) {
|
|
25480
|
+
bgColor.blue = maxValue;
|
|
25481
|
+
}
|
|
25482
|
+
function getRGBA() {
|
|
25483
|
+
let red;
|
|
25484
|
+
let green;
|
|
25485
|
+
let blue;
|
|
25486
|
+
let alpha = maxValue;
|
|
25487
|
+
switch (options.inputColorType) {
|
|
25488
|
+
case constants.COLORTYPE_COLOR_ALPHA:
|
|
25489
|
+
alpha = data[inIndex + 3];
|
|
25490
|
+
red = data[inIndex];
|
|
25491
|
+
green = data[inIndex + 1];
|
|
25492
|
+
blue = data[inIndex + 2];
|
|
25493
|
+
break;
|
|
25494
|
+
case constants.COLORTYPE_COLOR:
|
|
25495
|
+
red = data[inIndex];
|
|
25496
|
+
green = data[inIndex + 1];
|
|
25497
|
+
blue = data[inIndex + 2];
|
|
25498
|
+
break;
|
|
25499
|
+
case constants.COLORTYPE_ALPHA:
|
|
25500
|
+
alpha = data[inIndex + 1];
|
|
25501
|
+
red = data[inIndex];
|
|
25502
|
+
green = red;
|
|
25503
|
+
blue = red;
|
|
25504
|
+
break;
|
|
25505
|
+
case constants.COLORTYPE_GRAYSCALE:
|
|
25506
|
+
red = data[inIndex];
|
|
25507
|
+
green = red;
|
|
25508
|
+
blue = red;
|
|
25509
|
+
break;
|
|
25510
|
+
default:
|
|
25511
|
+
throw new Error("input color type:" + options.inputColorType + " is not supported at present");
|
|
25512
|
+
}
|
|
25513
|
+
if (options.inputHasAlpha) {
|
|
25514
|
+
if (!outHasAlpha) {
|
|
25515
|
+
alpha /= maxValue;
|
|
25516
|
+
red = Math.min(Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0), maxValue);
|
|
25517
|
+
green = Math.min(Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0), maxValue);
|
|
25518
|
+
blue = Math.min(Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0), maxValue);
|
|
25519
|
+
}
|
|
25520
|
+
}
|
|
25521
|
+
return { red, green, blue, alpha };
|
|
25522
|
+
}
|
|
25523
|
+
for (let y5 = 0;y5 < height; y5++) {
|
|
25524
|
+
for (let x3 = 0;x3 < width; x3++) {
|
|
25525
|
+
let rgba = getRGBA(data, inIndex);
|
|
25526
|
+
switch (options.colorType) {
|
|
25527
|
+
case constants.COLORTYPE_COLOR_ALPHA:
|
|
25528
|
+
case constants.COLORTYPE_COLOR:
|
|
25529
|
+
if (options.bitDepth === 8) {
|
|
25530
|
+
outData[outIndex] = rgba.red;
|
|
25531
|
+
outData[outIndex + 1] = rgba.green;
|
|
25532
|
+
outData[outIndex + 2] = rgba.blue;
|
|
25533
|
+
if (outHasAlpha) {
|
|
25534
|
+
outData[outIndex + 3] = rgba.alpha;
|
|
25535
|
+
}
|
|
25536
|
+
} else {
|
|
25537
|
+
outData.writeUInt16BE(rgba.red, outIndex);
|
|
25538
|
+
outData.writeUInt16BE(rgba.green, outIndex + 2);
|
|
25539
|
+
outData.writeUInt16BE(rgba.blue, outIndex + 4);
|
|
25540
|
+
if (outHasAlpha) {
|
|
25541
|
+
outData.writeUInt16BE(rgba.alpha, outIndex + 6);
|
|
25542
|
+
}
|
|
25543
|
+
}
|
|
25544
|
+
break;
|
|
25545
|
+
case constants.COLORTYPE_ALPHA:
|
|
25546
|
+
case constants.COLORTYPE_GRAYSCALE: {
|
|
25547
|
+
let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
|
|
25548
|
+
if (options.bitDepth === 8) {
|
|
25549
|
+
outData[outIndex] = grayscale;
|
|
25550
|
+
if (outHasAlpha) {
|
|
25551
|
+
outData[outIndex + 1] = rgba.alpha;
|
|
25552
|
+
}
|
|
25553
|
+
} else {
|
|
25554
|
+
outData.writeUInt16BE(grayscale, outIndex);
|
|
25555
|
+
if (outHasAlpha) {
|
|
25556
|
+
outData.writeUInt16BE(rgba.alpha, outIndex + 2);
|
|
25557
|
+
}
|
|
25558
|
+
}
|
|
25559
|
+
break;
|
|
25560
|
+
}
|
|
25561
|
+
default:
|
|
25562
|
+
throw new Error("unrecognised color Type " + options.colorType);
|
|
25563
|
+
}
|
|
25564
|
+
inIndex += inBpp;
|
|
25565
|
+
outIndex += outBpp;
|
|
25566
|
+
}
|
|
25567
|
+
}
|
|
25568
|
+
return outData;
|
|
25569
|
+
};
|
|
25570
|
+
});
|
|
25571
|
+
|
|
25572
|
+
// node_modules/pngjs/lib/filter-pack.js
|
|
25573
|
+
var require_filter_pack = __commonJS((exports, module) => {
|
|
25574
|
+
var paethPredictor = require_paeth_predictor();
|
|
25575
|
+
function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
25576
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
25577
|
+
rawData[rawPos + x3] = pxData[pxPos + x3];
|
|
25578
|
+
}
|
|
25579
|
+
}
|
|
25580
|
+
function filterSumNone(pxData, pxPos, byteWidth) {
|
|
25581
|
+
let sum = 0;
|
|
25582
|
+
let length = pxPos + byteWidth;
|
|
25583
|
+
for (let i3 = pxPos;i3 < length; i3++) {
|
|
25584
|
+
sum += Math.abs(pxData[i3]);
|
|
25585
|
+
}
|
|
25586
|
+
return sum;
|
|
25587
|
+
}
|
|
25588
|
+
function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
25589
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
25590
|
+
let left = x3 >= bpp ? pxData[pxPos + x3 - bpp] : 0;
|
|
25591
|
+
let val = pxData[pxPos + x3] - left;
|
|
25592
|
+
rawData[rawPos + x3] = val;
|
|
25593
|
+
}
|
|
25594
|
+
}
|
|
25595
|
+
function filterSumSub(pxData, pxPos, byteWidth, bpp) {
|
|
25596
|
+
let sum = 0;
|
|
25597
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
25598
|
+
let left = x3 >= bpp ? pxData[pxPos + x3 - bpp] : 0;
|
|
25599
|
+
let val = pxData[pxPos + x3] - left;
|
|
25600
|
+
sum += Math.abs(val);
|
|
25601
|
+
}
|
|
25602
|
+
return sum;
|
|
25603
|
+
}
|
|
25604
|
+
function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
25605
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
25606
|
+
let up = pxPos > 0 ? pxData[pxPos + x3 - byteWidth] : 0;
|
|
25607
|
+
let val = pxData[pxPos + x3] - up;
|
|
25608
|
+
rawData[rawPos + x3] = val;
|
|
25609
|
+
}
|
|
25610
|
+
}
|
|
25611
|
+
function filterSumUp(pxData, pxPos, byteWidth) {
|
|
25612
|
+
let sum = 0;
|
|
25613
|
+
let length = pxPos + byteWidth;
|
|
25614
|
+
for (let x3 = pxPos;x3 < length; x3++) {
|
|
25615
|
+
let up = pxPos > 0 ? pxData[x3 - byteWidth] : 0;
|
|
25616
|
+
let val = pxData[x3] - up;
|
|
25617
|
+
sum += Math.abs(val);
|
|
25618
|
+
}
|
|
25619
|
+
return sum;
|
|
25620
|
+
}
|
|
25621
|
+
function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
25622
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
25623
|
+
let left = x3 >= bpp ? pxData[pxPos + x3 - bpp] : 0;
|
|
25624
|
+
let up = pxPos > 0 ? pxData[pxPos + x3 - byteWidth] : 0;
|
|
25625
|
+
let val = pxData[pxPos + x3] - (left + up >> 1);
|
|
25626
|
+
rawData[rawPos + x3] = val;
|
|
25627
|
+
}
|
|
25628
|
+
}
|
|
25629
|
+
function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
|
|
25630
|
+
let sum = 0;
|
|
25631
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
25632
|
+
let left = x3 >= bpp ? pxData[pxPos + x3 - bpp] : 0;
|
|
25633
|
+
let up = pxPos > 0 ? pxData[pxPos + x3 - byteWidth] : 0;
|
|
25634
|
+
let val = pxData[pxPos + x3] - (left + up >> 1);
|
|
25635
|
+
sum += Math.abs(val);
|
|
25636
|
+
}
|
|
25637
|
+
return sum;
|
|
25638
|
+
}
|
|
25639
|
+
function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
25640
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
25641
|
+
let left = x3 >= bpp ? pxData[pxPos + x3 - bpp] : 0;
|
|
25642
|
+
let up = pxPos > 0 ? pxData[pxPos + x3 - byteWidth] : 0;
|
|
25643
|
+
let upleft = pxPos > 0 && x3 >= bpp ? pxData[pxPos + x3 - (byteWidth + bpp)] : 0;
|
|
25644
|
+
let val = pxData[pxPos + x3] - paethPredictor(left, up, upleft);
|
|
25645
|
+
rawData[rawPos + x3] = val;
|
|
25646
|
+
}
|
|
25647
|
+
}
|
|
25648
|
+
function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
|
|
25649
|
+
let sum = 0;
|
|
25650
|
+
for (let x3 = 0;x3 < byteWidth; x3++) {
|
|
25651
|
+
let left = x3 >= bpp ? pxData[pxPos + x3 - bpp] : 0;
|
|
25652
|
+
let up = pxPos > 0 ? pxData[pxPos + x3 - byteWidth] : 0;
|
|
25653
|
+
let upleft = pxPos > 0 && x3 >= bpp ? pxData[pxPos + x3 - (byteWidth + bpp)] : 0;
|
|
25654
|
+
let val = pxData[pxPos + x3] - paethPredictor(left, up, upleft);
|
|
25655
|
+
sum += Math.abs(val);
|
|
25656
|
+
}
|
|
25657
|
+
return sum;
|
|
25658
|
+
}
|
|
25659
|
+
var filters = {
|
|
25660
|
+
0: filterNone,
|
|
25661
|
+
1: filterSub,
|
|
25662
|
+
2: filterUp,
|
|
25663
|
+
3: filterAvg,
|
|
25664
|
+
4: filterPaeth
|
|
25665
|
+
};
|
|
25666
|
+
var filterSums = {
|
|
25667
|
+
0: filterSumNone,
|
|
25668
|
+
1: filterSumSub,
|
|
25669
|
+
2: filterSumUp,
|
|
25670
|
+
3: filterSumAvg,
|
|
25671
|
+
4: filterSumPaeth
|
|
25672
|
+
};
|
|
25673
|
+
module.exports = function(pxData, width, height, options, bpp) {
|
|
25674
|
+
let filterTypes;
|
|
25675
|
+
if (!("filterType" in options) || options.filterType === -1) {
|
|
25676
|
+
filterTypes = [0, 1, 2, 3, 4];
|
|
25677
|
+
} else if (typeof options.filterType === "number") {
|
|
25678
|
+
filterTypes = [options.filterType];
|
|
25679
|
+
} else {
|
|
25680
|
+
throw new Error("unrecognised filter types");
|
|
25681
|
+
}
|
|
25682
|
+
if (options.bitDepth === 16) {
|
|
25683
|
+
bpp *= 2;
|
|
25684
|
+
}
|
|
25685
|
+
let byteWidth = width * bpp;
|
|
25686
|
+
let rawPos = 0;
|
|
25687
|
+
let pxPos = 0;
|
|
25688
|
+
let rawData = Buffer.alloc((byteWidth + 1) * height);
|
|
25689
|
+
let sel = filterTypes[0];
|
|
25690
|
+
for (let y5 = 0;y5 < height; y5++) {
|
|
25691
|
+
if (filterTypes.length > 1) {
|
|
25692
|
+
let min = Infinity;
|
|
25693
|
+
for (let i3 = 0;i3 < filterTypes.length; i3++) {
|
|
25694
|
+
let sum = filterSums[filterTypes[i3]](pxData, pxPos, byteWidth, bpp);
|
|
25695
|
+
if (sum < min) {
|
|
25696
|
+
sel = filterTypes[i3];
|
|
25697
|
+
min = sum;
|
|
25698
|
+
}
|
|
25699
|
+
}
|
|
25700
|
+
}
|
|
25701
|
+
rawData[rawPos] = sel;
|
|
25702
|
+
rawPos++;
|
|
25703
|
+
filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
|
|
25704
|
+
rawPos += byteWidth;
|
|
25705
|
+
pxPos += byteWidth;
|
|
25706
|
+
}
|
|
25707
|
+
return rawData;
|
|
25708
|
+
};
|
|
25709
|
+
});
|
|
25710
|
+
|
|
25711
|
+
// node_modules/pngjs/lib/packer.js
|
|
25712
|
+
var require_packer = __commonJS((exports, module) => {
|
|
25713
|
+
var constants = require_constants();
|
|
25714
|
+
var CrcStream = require_crc();
|
|
25715
|
+
var bitPacker = require_bitpacker();
|
|
25716
|
+
var filter = require_filter_pack();
|
|
25717
|
+
var zlib = __require("zlib");
|
|
25718
|
+
var Packer = module.exports = function(options) {
|
|
25719
|
+
this._options = options;
|
|
25720
|
+
options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
|
|
25721
|
+
options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
|
|
25722
|
+
options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
|
|
25723
|
+
options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
|
|
25724
|
+
options.deflateFactory = options.deflateFactory || zlib.createDeflate;
|
|
25725
|
+
options.bitDepth = options.bitDepth || 8;
|
|
25726
|
+
options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
25727
|
+
options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
25728
|
+
if ([
|
|
25729
|
+
constants.COLORTYPE_GRAYSCALE,
|
|
25730
|
+
constants.COLORTYPE_COLOR,
|
|
25731
|
+
constants.COLORTYPE_COLOR_ALPHA,
|
|
25732
|
+
constants.COLORTYPE_ALPHA
|
|
25733
|
+
].indexOf(options.colorType) === -1) {
|
|
25734
|
+
throw new Error("option color type:" + options.colorType + " is not supported at present");
|
|
25735
|
+
}
|
|
25736
|
+
if ([
|
|
25737
|
+
constants.COLORTYPE_GRAYSCALE,
|
|
25738
|
+
constants.COLORTYPE_COLOR,
|
|
25739
|
+
constants.COLORTYPE_COLOR_ALPHA,
|
|
25740
|
+
constants.COLORTYPE_ALPHA
|
|
25741
|
+
].indexOf(options.inputColorType) === -1) {
|
|
25742
|
+
throw new Error("option input color type:" + options.inputColorType + " is not supported at present");
|
|
25743
|
+
}
|
|
25744
|
+
if (options.bitDepth !== 8 && options.bitDepth !== 16) {
|
|
25745
|
+
throw new Error("option bit depth:" + options.bitDepth + " is not supported at present");
|
|
25746
|
+
}
|
|
25747
|
+
};
|
|
25748
|
+
Packer.prototype.getDeflateOptions = function() {
|
|
25749
|
+
return {
|
|
25750
|
+
chunkSize: this._options.deflateChunkSize,
|
|
25751
|
+
level: this._options.deflateLevel,
|
|
25752
|
+
strategy: this._options.deflateStrategy
|
|
25753
|
+
};
|
|
25754
|
+
};
|
|
25755
|
+
Packer.prototype.createDeflate = function() {
|
|
25756
|
+
return this._options.deflateFactory(this.getDeflateOptions());
|
|
25757
|
+
};
|
|
25758
|
+
Packer.prototype.filterData = function(data, width, height) {
|
|
25759
|
+
let packedData = bitPacker(data, width, height, this._options);
|
|
25760
|
+
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
|
|
25761
|
+
let filteredData = filter(packedData, width, height, this._options, bpp);
|
|
25762
|
+
return filteredData;
|
|
25763
|
+
};
|
|
25764
|
+
Packer.prototype._packChunk = function(type, data) {
|
|
25765
|
+
let len = data ? data.length : 0;
|
|
25766
|
+
let buf = Buffer.alloc(len + 12);
|
|
25767
|
+
buf.writeUInt32BE(len, 0);
|
|
25768
|
+
buf.writeUInt32BE(type, 4);
|
|
25769
|
+
if (data) {
|
|
25770
|
+
data.copy(buf, 8);
|
|
25771
|
+
}
|
|
25772
|
+
buf.writeInt32BE(CrcStream.crc32(buf.slice(4, buf.length - 4)), buf.length - 4);
|
|
25773
|
+
return buf;
|
|
25774
|
+
};
|
|
25775
|
+
Packer.prototype.packGAMA = function(gamma4) {
|
|
25776
|
+
let buf = Buffer.alloc(4);
|
|
25777
|
+
buf.writeUInt32BE(Math.floor(gamma4 * constants.GAMMA_DIVISION), 0);
|
|
25778
|
+
return this._packChunk(constants.TYPE_gAMA, buf);
|
|
25779
|
+
};
|
|
25780
|
+
Packer.prototype.packIHDR = function(width, height) {
|
|
25781
|
+
let buf = Buffer.alloc(13);
|
|
25782
|
+
buf.writeUInt32BE(width, 0);
|
|
25783
|
+
buf.writeUInt32BE(height, 4);
|
|
25784
|
+
buf[8] = this._options.bitDepth;
|
|
25785
|
+
buf[9] = this._options.colorType;
|
|
25786
|
+
buf[10] = 0;
|
|
25787
|
+
buf[11] = 0;
|
|
25788
|
+
buf[12] = 0;
|
|
25789
|
+
return this._packChunk(constants.TYPE_IHDR, buf);
|
|
25790
|
+
};
|
|
25791
|
+
Packer.prototype.packIDAT = function(data) {
|
|
25792
|
+
return this._packChunk(constants.TYPE_IDAT, data);
|
|
25793
|
+
};
|
|
25794
|
+
Packer.prototype.packIEND = function() {
|
|
25795
|
+
return this._packChunk(constants.TYPE_IEND, null);
|
|
25796
|
+
};
|
|
25797
|
+
});
|
|
25798
|
+
|
|
25799
|
+
// node_modules/pngjs/lib/packer-async.js
|
|
25800
|
+
var require_packer_async = __commonJS((exports, module) => {
|
|
25801
|
+
var util = __require("util");
|
|
25802
|
+
var Stream = __require("stream");
|
|
25803
|
+
var constants = require_constants();
|
|
25804
|
+
var Packer = require_packer();
|
|
25805
|
+
var PackerAsync = module.exports = function(opt) {
|
|
25806
|
+
Stream.call(this);
|
|
25807
|
+
let options = opt || {};
|
|
25808
|
+
this._packer = new Packer(options);
|
|
25809
|
+
this._deflate = this._packer.createDeflate();
|
|
25810
|
+
this.readable = true;
|
|
25811
|
+
};
|
|
25812
|
+
util.inherits(PackerAsync, Stream);
|
|
25813
|
+
PackerAsync.prototype.pack = function(data, width, height, gamma4) {
|
|
25814
|
+
this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
|
|
25815
|
+
this.emit("data", this._packer.packIHDR(width, height));
|
|
25816
|
+
if (gamma4) {
|
|
25817
|
+
this.emit("data", this._packer.packGAMA(gamma4));
|
|
25818
|
+
}
|
|
25819
|
+
let filteredData = this._packer.filterData(data, width, height);
|
|
25820
|
+
this._deflate.on("error", this.emit.bind(this, "error"));
|
|
25821
|
+
this._deflate.on("data", function(compressedData) {
|
|
25822
|
+
this.emit("data", this._packer.packIDAT(compressedData));
|
|
25823
|
+
}.bind(this));
|
|
25824
|
+
this._deflate.on("end", function() {
|
|
25825
|
+
this.emit("data", this._packer.packIEND());
|
|
25826
|
+
this.emit("end");
|
|
25827
|
+
}.bind(this));
|
|
25828
|
+
this._deflate.end(filteredData);
|
|
25829
|
+
};
|
|
25830
|
+
});
|
|
25831
|
+
|
|
25832
|
+
// node_modules/pngjs/lib/sync-inflate.js
|
|
25833
|
+
var require_sync_inflate = __commonJS((exports, module) => {
|
|
25834
|
+
var assert = __require("assert").ok;
|
|
25835
|
+
var zlib = __require("zlib");
|
|
25836
|
+
var util = __require("util");
|
|
25837
|
+
var kMaxLength = __require("buffer").kMaxLength;
|
|
25838
|
+
function Inflate(opts) {
|
|
25839
|
+
if (!(this instanceof Inflate)) {
|
|
25840
|
+
return new Inflate(opts);
|
|
25841
|
+
}
|
|
25842
|
+
if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
|
|
25843
|
+
opts.chunkSize = zlib.Z_MIN_CHUNK;
|
|
25844
|
+
}
|
|
25845
|
+
zlib.Inflate.call(this, opts);
|
|
25846
|
+
this._offset = this._offset === undefined ? this._outOffset : this._offset;
|
|
25847
|
+
this._buffer = this._buffer || this._outBuffer;
|
|
25848
|
+
if (opts && opts.maxLength != null) {
|
|
25849
|
+
this._maxLength = opts.maxLength;
|
|
25850
|
+
}
|
|
25851
|
+
}
|
|
25852
|
+
function createInflate(opts) {
|
|
25853
|
+
return new Inflate(opts);
|
|
25854
|
+
}
|
|
25855
|
+
function _close(engine, callback) {
|
|
25856
|
+
if (callback) {
|
|
25857
|
+
process.nextTick(callback);
|
|
25858
|
+
}
|
|
25859
|
+
if (!engine._handle) {
|
|
25860
|
+
return;
|
|
25861
|
+
}
|
|
25862
|
+
engine._handle.close();
|
|
25863
|
+
engine._handle = null;
|
|
25864
|
+
}
|
|
25865
|
+
Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
|
|
25866
|
+
if (typeof asyncCb === "function") {
|
|
25867
|
+
return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
|
|
25868
|
+
}
|
|
25869
|
+
let self = this;
|
|
25870
|
+
let availInBefore = chunk && chunk.length;
|
|
25871
|
+
let availOutBefore = this._chunkSize - this._offset;
|
|
25872
|
+
let leftToInflate = this._maxLength;
|
|
25873
|
+
let inOff = 0;
|
|
25874
|
+
let buffers = [];
|
|
25875
|
+
let nread = 0;
|
|
25876
|
+
let error;
|
|
25877
|
+
this.on("error", function(err) {
|
|
25878
|
+
error = err;
|
|
25879
|
+
});
|
|
25880
|
+
function handleChunk(availInAfter, availOutAfter) {
|
|
25881
|
+
if (self._hadError) {
|
|
25882
|
+
return;
|
|
25883
|
+
}
|
|
25884
|
+
let have = availOutBefore - availOutAfter;
|
|
25885
|
+
assert(have >= 0, "have should not go down");
|
|
25886
|
+
if (have > 0) {
|
|
25887
|
+
let out = self._buffer.slice(self._offset, self._offset + have);
|
|
25888
|
+
self._offset += have;
|
|
25889
|
+
if (out.length > leftToInflate) {
|
|
25890
|
+
out = out.slice(0, leftToInflate);
|
|
25891
|
+
}
|
|
25892
|
+
buffers.push(out);
|
|
25893
|
+
nread += out.length;
|
|
25894
|
+
leftToInflate -= out.length;
|
|
25895
|
+
if (leftToInflate === 0) {
|
|
25896
|
+
return false;
|
|
25897
|
+
}
|
|
25898
|
+
}
|
|
25899
|
+
if (availOutAfter === 0 || self._offset >= self._chunkSize) {
|
|
25900
|
+
availOutBefore = self._chunkSize;
|
|
25901
|
+
self._offset = 0;
|
|
25902
|
+
self._buffer = Buffer.allocUnsafe(self._chunkSize);
|
|
25903
|
+
}
|
|
25904
|
+
if (availOutAfter === 0) {
|
|
25905
|
+
inOff += availInBefore - availInAfter;
|
|
25906
|
+
availInBefore = availInAfter;
|
|
25907
|
+
return true;
|
|
25908
|
+
}
|
|
25909
|
+
return false;
|
|
25910
|
+
}
|
|
25911
|
+
assert(this._handle, "zlib binding closed");
|
|
25912
|
+
let res;
|
|
25913
|
+
do {
|
|
25914
|
+
res = this._handle.writeSync(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, availOutBefore);
|
|
25915
|
+
res = res || this._writeState;
|
|
25916
|
+
} while (!this._hadError && handleChunk(res[0], res[1]));
|
|
25917
|
+
if (this._hadError) {
|
|
25918
|
+
throw error;
|
|
25919
|
+
}
|
|
25920
|
+
if (nread >= kMaxLength) {
|
|
25921
|
+
_close(this);
|
|
25922
|
+
throw new RangeError("Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes");
|
|
25923
|
+
}
|
|
25924
|
+
let buf = Buffer.concat(buffers, nread);
|
|
25925
|
+
_close(this);
|
|
25926
|
+
return buf;
|
|
25927
|
+
};
|
|
25928
|
+
util.inherits(Inflate, zlib.Inflate);
|
|
25929
|
+
function zlibBufferSync(engine, buffer) {
|
|
25930
|
+
if (typeof buffer === "string") {
|
|
25931
|
+
buffer = Buffer.from(buffer);
|
|
25932
|
+
}
|
|
25933
|
+
if (!(buffer instanceof Buffer)) {
|
|
25934
|
+
throw new TypeError("Not a string or buffer");
|
|
25935
|
+
}
|
|
25936
|
+
let flushFlag = engine._finishFlushFlag;
|
|
25937
|
+
if (flushFlag == null) {
|
|
25938
|
+
flushFlag = zlib.Z_FINISH;
|
|
25939
|
+
}
|
|
25940
|
+
return engine._processChunk(buffer, flushFlag);
|
|
25941
|
+
}
|
|
25942
|
+
function inflateSync(buffer, opts) {
|
|
25943
|
+
return zlibBufferSync(new Inflate(opts), buffer);
|
|
25944
|
+
}
|
|
25945
|
+
module.exports = exports = inflateSync;
|
|
25946
|
+
exports.Inflate = Inflate;
|
|
25947
|
+
exports.createInflate = createInflate;
|
|
25948
|
+
exports.inflateSync = inflateSync;
|
|
25949
|
+
});
|
|
25950
|
+
|
|
25951
|
+
// node_modules/pngjs/lib/sync-reader.js
|
|
25952
|
+
var require_sync_reader = __commonJS((exports, module) => {
|
|
25953
|
+
var SyncReader = module.exports = function(buffer) {
|
|
25954
|
+
this._buffer = buffer;
|
|
25955
|
+
this._reads = [];
|
|
25956
|
+
};
|
|
25957
|
+
SyncReader.prototype.read = function(length, callback) {
|
|
25958
|
+
this._reads.push({
|
|
25959
|
+
length: Math.abs(length),
|
|
25960
|
+
allowLess: length < 0,
|
|
25961
|
+
func: callback
|
|
25962
|
+
});
|
|
25963
|
+
};
|
|
25964
|
+
SyncReader.prototype.process = function() {
|
|
25965
|
+
while (this._reads.length > 0 && this._buffer.length) {
|
|
25966
|
+
let read = this._reads[0];
|
|
25967
|
+
if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
|
|
25968
|
+
this._reads.shift();
|
|
25969
|
+
let buf = this._buffer;
|
|
25970
|
+
this._buffer = buf.slice(read.length);
|
|
25971
|
+
read.func.call(this, buf.slice(0, read.length));
|
|
25972
|
+
} else {
|
|
25973
|
+
break;
|
|
25974
|
+
}
|
|
25975
|
+
}
|
|
25976
|
+
if (this._reads.length > 0) {
|
|
25977
|
+
throw new Error("There are some read requests waitng on finished stream");
|
|
25978
|
+
}
|
|
25979
|
+
if (this._buffer.length > 0) {
|
|
25980
|
+
throw new Error("unrecognised content at end of stream");
|
|
25981
|
+
}
|
|
25982
|
+
};
|
|
25983
|
+
});
|
|
25984
|
+
|
|
25985
|
+
// node_modules/pngjs/lib/filter-parse-sync.js
|
|
25986
|
+
var require_filter_parse_sync = __commonJS((exports) => {
|
|
25987
|
+
var SyncReader = require_sync_reader();
|
|
25988
|
+
var Filter = require_filter_parse();
|
|
25989
|
+
exports.process = function(inBuffer, bitmapInfo) {
|
|
25990
|
+
let outBuffers = [];
|
|
25991
|
+
let reader = new SyncReader(inBuffer);
|
|
25992
|
+
let filter = new Filter(bitmapInfo, {
|
|
25993
|
+
read: reader.read.bind(reader),
|
|
25994
|
+
write: function(bufferPart) {
|
|
25995
|
+
outBuffers.push(bufferPart);
|
|
25996
|
+
},
|
|
25997
|
+
complete: function() {}
|
|
25998
|
+
});
|
|
25999
|
+
filter.start();
|
|
26000
|
+
reader.process();
|
|
26001
|
+
return Buffer.concat(outBuffers);
|
|
26002
|
+
};
|
|
26003
|
+
});
|
|
26004
|
+
|
|
26005
|
+
// node_modules/pngjs/lib/parser-sync.js
|
|
26006
|
+
var require_parser_sync = __commonJS((exports, module) => {
|
|
26007
|
+
var hasSyncZlib = true;
|
|
26008
|
+
var zlib = __require("zlib");
|
|
26009
|
+
var inflateSync = require_sync_inflate();
|
|
26010
|
+
if (!zlib.deflateSync) {
|
|
26011
|
+
hasSyncZlib = false;
|
|
26012
|
+
}
|
|
26013
|
+
var SyncReader = require_sync_reader();
|
|
26014
|
+
var FilterSync = require_filter_parse_sync();
|
|
26015
|
+
var Parser = require_parser();
|
|
26016
|
+
var bitmapper = require_bitmapper();
|
|
26017
|
+
var formatNormaliser = require_format_normaliser();
|
|
26018
|
+
module.exports = function(buffer, options) {
|
|
26019
|
+
if (!hasSyncZlib) {
|
|
26020
|
+
throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");
|
|
26021
|
+
}
|
|
26022
|
+
let err;
|
|
26023
|
+
function handleError2(_err_) {
|
|
26024
|
+
err = _err_;
|
|
26025
|
+
}
|
|
26026
|
+
let metaData;
|
|
26027
|
+
function handleMetaData(_metaData_) {
|
|
26028
|
+
metaData = _metaData_;
|
|
26029
|
+
}
|
|
26030
|
+
function handleTransColor(transColor) {
|
|
26031
|
+
metaData.transColor = transColor;
|
|
26032
|
+
}
|
|
26033
|
+
function handlePalette(palette) {
|
|
26034
|
+
metaData.palette = palette;
|
|
26035
|
+
}
|
|
26036
|
+
function handleSimpleTransparency() {
|
|
26037
|
+
metaData.alpha = true;
|
|
26038
|
+
}
|
|
26039
|
+
let gamma4;
|
|
26040
|
+
function handleGamma(_gamma_) {
|
|
26041
|
+
gamma4 = _gamma_;
|
|
26042
|
+
}
|
|
26043
|
+
let inflateDataList = [];
|
|
26044
|
+
function handleInflateData(inflatedData2) {
|
|
26045
|
+
inflateDataList.push(inflatedData2);
|
|
26046
|
+
}
|
|
26047
|
+
let reader = new SyncReader(buffer);
|
|
26048
|
+
let parser = new Parser(options, {
|
|
26049
|
+
read: reader.read.bind(reader),
|
|
26050
|
+
error: handleError2,
|
|
26051
|
+
metadata: handleMetaData,
|
|
26052
|
+
gamma: handleGamma,
|
|
26053
|
+
palette: handlePalette,
|
|
26054
|
+
transColor: handleTransColor,
|
|
26055
|
+
inflateData: handleInflateData,
|
|
26056
|
+
simpleTransparency: handleSimpleTransparency
|
|
26057
|
+
});
|
|
26058
|
+
parser.start();
|
|
26059
|
+
reader.process();
|
|
26060
|
+
if (err) {
|
|
26061
|
+
throw err;
|
|
26062
|
+
}
|
|
26063
|
+
let inflateData = Buffer.concat(inflateDataList);
|
|
26064
|
+
inflateDataList.length = 0;
|
|
26065
|
+
let inflatedData;
|
|
26066
|
+
if (metaData.interlace) {
|
|
26067
|
+
inflatedData = zlib.inflateSync(inflateData);
|
|
26068
|
+
} else {
|
|
26069
|
+
let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
|
|
26070
|
+
let imageSize = rowSize * metaData.height;
|
|
26071
|
+
inflatedData = inflateSync(inflateData, {
|
|
26072
|
+
chunkSize: imageSize,
|
|
26073
|
+
maxLength: imageSize
|
|
26074
|
+
});
|
|
26075
|
+
}
|
|
26076
|
+
inflateData = null;
|
|
26077
|
+
if (!inflatedData || !inflatedData.length) {
|
|
26078
|
+
throw new Error("bad png - invalid inflate data response");
|
|
26079
|
+
}
|
|
26080
|
+
let unfilteredData = FilterSync.process(inflatedData, metaData);
|
|
26081
|
+
inflateData = null;
|
|
26082
|
+
let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
|
|
26083
|
+
unfilteredData = null;
|
|
26084
|
+
let normalisedBitmapData = formatNormaliser(bitmapData, metaData, options.skipRescale);
|
|
26085
|
+
metaData.data = normalisedBitmapData;
|
|
26086
|
+
metaData.gamma = gamma4 || 0;
|
|
26087
|
+
return metaData;
|
|
26088
|
+
};
|
|
26089
|
+
});
|
|
26090
|
+
|
|
26091
|
+
// node_modules/pngjs/lib/packer-sync.js
|
|
26092
|
+
var require_packer_sync = __commonJS((exports, module) => {
|
|
26093
|
+
var hasSyncZlib = true;
|
|
26094
|
+
var zlib = __require("zlib");
|
|
26095
|
+
if (!zlib.deflateSync) {
|
|
26096
|
+
hasSyncZlib = false;
|
|
26097
|
+
}
|
|
26098
|
+
var constants = require_constants();
|
|
26099
|
+
var Packer = require_packer();
|
|
26100
|
+
module.exports = function(metaData, opt) {
|
|
26101
|
+
if (!hasSyncZlib) {
|
|
26102
|
+
throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");
|
|
26103
|
+
}
|
|
26104
|
+
let options = opt || {};
|
|
26105
|
+
let packer = new Packer(options);
|
|
26106
|
+
let chunks = [];
|
|
26107
|
+
chunks.push(Buffer.from(constants.PNG_SIGNATURE));
|
|
26108
|
+
chunks.push(packer.packIHDR(metaData.width, metaData.height));
|
|
26109
|
+
if (metaData.gamma) {
|
|
26110
|
+
chunks.push(packer.packGAMA(metaData.gamma));
|
|
26111
|
+
}
|
|
26112
|
+
let filteredData = packer.filterData(metaData.data, metaData.width, metaData.height);
|
|
26113
|
+
let compressedData = zlib.deflateSync(filteredData, packer.getDeflateOptions());
|
|
26114
|
+
filteredData = null;
|
|
26115
|
+
if (!compressedData || !compressedData.length) {
|
|
26116
|
+
throw new Error("bad png - invalid compressed data response");
|
|
26117
|
+
}
|
|
26118
|
+
chunks.push(packer.packIDAT(compressedData));
|
|
26119
|
+
chunks.push(packer.packIEND());
|
|
26120
|
+
return Buffer.concat(chunks);
|
|
26121
|
+
};
|
|
26122
|
+
});
|
|
26123
|
+
|
|
26124
|
+
// node_modules/pngjs/lib/png-sync.js
|
|
26125
|
+
var require_png_sync = __commonJS((exports) => {
|
|
26126
|
+
var parse2 = require_parser_sync();
|
|
26127
|
+
var pack = require_packer_sync();
|
|
26128
|
+
exports.read = function(buffer, options) {
|
|
26129
|
+
return parse2(buffer, options || {});
|
|
26130
|
+
};
|
|
26131
|
+
exports.write = function(png, options) {
|
|
26132
|
+
return pack(png, options);
|
|
26133
|
+
};
|
|
26134
|
+
});
|
|
26135
|
+
|
|
26136
|
+
// node_modules/pngjs/lib/png.js
|
|
26137
|
+
var require_png = __commonJS((exports) => {
|
|
26138
|
+
var util = __require("util");
|
|
26139
|
+
var Stream = __require("stream");
|
|
26140
|
+
var Parser = require_parser_async();
|
|
26141
|
+
var Packer = require_packer_async();
|
|
26142
|
+
var PNGSync = require_png_sync();
|
|
26143
|
+
var PNG = exports.PNG = function(options) {
|
|
26144
|
+
Stream.call(this);
|
|
26145
|
+
options = options || {};
|
|
26146
|
+
this.width = options.width | 0;
|
|
26147
|
+
this.height = options.height | 0;
|
|
26148
|
+
this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
|
|
26149
|
+
if (options.fill && this.data) {
|
|
26150
|
+
this.data.fill(0);
|
|
26151
|
+
}
|
|
26152
|
+
this.gamma = 0;
|
|
26153
|
+
this.readable = this.writable = true;
|
|
26154
|
+
this._parser = new Parser(options);
|
|
26155
|
+
this._parser.on("error", this.emit.bind(this, "error"));
|
|
26156
|
+
this._parser.on("close", this._handleClose.bind(this));
|
|
26157
|
+
this._parser.on("metadata", this._metadata.bind(this));
|
|
26158
|
+
this._parser.on("gamma", this._gamma.bind(this));
|
|
26159
|
+
this._parser.on("parsed", function(data) {
|
|
26160
|
+
this.data = data;
|
|
26161
|
+
this.emit("parsed", data);
|
|
26162
|
+
}.bind(this));
|
|
26163
|
+
this._packer = new Packer(options);
|
|
26164
|
+
this._packer.on("data", this.emit.bind(this, "data"));
|
|
26165
|
+
this._packer.on("end", this.emit.bind(this, "end"));
|
|
26166
|
+
this._parser.on("close", this._handleClose.bind(this));
|
|
26167
|
+
this._packer.on("error", this.emit.bind(this, "error"));
|
|
26168
|
+
};
|
|
26169
|
+
util.inherits(PNG, Stream);
|
|
26170
|
+
PNG.sync = PNGSync;
|
|
26171
|
+
PNG.prototype.pack = function() {
|
|
26172
|
+
if (!this.data || !this.data.length) {
|
|
26173
|
+
this.emit("error", "No data provided");
|
|
26174
|
+
return this;
|
|
26175
|
+
}
|
|
26176
|
+
process.nextTick(function() {
|
|
26177
|
+
this._packer.pack(this.data, this.width, this.height, this.gamma);
|
|
26178
|
+
}.bind(this));
|
|
26179
|
+
return this;
|
|
26180
|
+
};
|
|
26181
|
+
PNG.prototype.parse = function(data, callback) {
|
|
26182
|
+
if (callback) {
|
|
26183
|
+
let onParsed, onError;
|
|
26184
|
+
onParsed = function(parsedData) {
|
|
26185
|
+
this.removeListener("error", onError);
|
|
26186
|
+
this.data = parsedData;
|
|
26187
|
+
callback(null, this);
|
|
26188
|
+
}.bind(this);
|
|
26189
|
+
onError = function(err) {
|
|
26190
|
+
this.removeListener("parsed", onParsed);
|
|
26191
|
+
callback(err, null);
|
|
26192
|
+
}.bind(this);
|
|
26193
|
+
this.once("parsed", onParsed);
|
|
26194
|
+
this.once("error", onError);
|
|
26195
|
+
}
|
|
26196
|
+
this.end(data);
|
|
26197
|
+
return this;
|
|
26198
|
+
};
|
|
26199
|
+
PNG.prototype.write = function(data) {
|
|
26200
|
+
this._parser.write(data);
|
|
26201
|
+
return true;
|
|
26202
|
+
};
|
|
26203
|
+
PNG.prototype.end = function(data) {
|
|
26204
|
+
this._parser.end(data);
|
|
26205
|
+
};
|
|
26206
|
+
PNG.prototype._metadata = function(metadata) {
|
|
26207
|
+
this.width = metadata.width;
|
|
26208
|
+
this.height = metadata.height;
|
|
26209
|
+
this.emit("metadata", metadata);
|
|
26210
|
+
};
|
|
26211
|
+
PNG.prototype._gamma = function(gamma4) {
|
|
26212
|
+
this.gamma = gamma4;
|
|
26213
|
+
};
|
|
26214
|
+
PNG.prototype._handleClose = function() {
|
|
26215
|
+
if (!this._parser.writable && !this._packer.readable) {
|
|
26216
|
+
this.emit("close");
|
|
26217
|
+
}
|
|
26218
|
+
};
|
|
26219
|
+
PNG.bitblt = function(src3, dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
26220
|
+
srcX |= 0;
|
|
26221
|
+
srcY |= 0;
|
|
26222
|
+
width |= 0;
|
|
26223
|
+
height |= 0;
|
|
26224
|
+
deltaX |= 0;
|
|
26225
|
+
deltaY |= 0;
|
|
26226
|
+
if (srcX > src3.width || srcY > src3.height || srcX + width > src3.width || srcY + height > src3.height) {
|
|
26227
|
+
throw new Error("bitblt reading outside image");
|
|
26228
|
+
}
|
|
26229
|
+
if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
|
|
26230
|
+
throw new Error("bitblt writing outside image");
|
|
26231
|
+
}
|
|
26232
|
+
for (let y5 = 0;y5 < height; y5++) {
|
|
26233
|
+
src3.data.copy(dst.data, (deltaY + y5) * dst.width + deltaX << 2, (srcY + y5) * src3.width + srcX << 2, (srcY + y5) * src3.width + srcX + width << 2);
|
|
26234
|
+
}
|
|
26235
|
+
};
|
|
26236
|
+
PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
26237
|
+
PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
|
|
26238
|
+
return this;
|
|
26239
|
+
};
|
|
26240
|
+
PNG.adjustGamma = function(src3) {
|
|
26241
|
+
if (src3.gamma) {
|
|
26242
|
+
for (let y5 = 0;y5 < src3.height; y5++) {
|
|
26243
|
+
for (let x3 = 0;x3 < src3.width; x3++) {
|
|
26244
|
+
let idx = src3.width * y5 + x3 << 2;
|
|
26245
|
+
for (let i3 = 0;i3 < 3; i3++) {
|
|
26246
|
+
let sample = src3.data[idx + i3] / 255;
|
|
26247
|
+
sample = Math.pow(sample, 1 / 2.2 / src3.gamma);
|
|
26248
|
+
src3.data[idx + i3] = Math.round(sample * 255);
|
|
26249
|
+
}
|
|
26250
|
+
}
|
|
26251
|
+
}
|
|
26252
|
+
src3.gamma = 0;
|
|
26253
|
+
}
|
|
26254
|
+
};
|
|
26255
|
+
PNG.prototype.adjustGamma = function() {
|
|
26256
|
+
PNG.adjustGamma(this);
|
|
26257
|
+
};
|
|
26258
|
+
});
|
|
26259
|
+
|
|
26260
|
+
// node_modules/pixelmatch/index.js
|
|
26261
|
+
function pixelmatch(img1, img2, output, width, height, options = {}) {
|
|
26262
|
+
const {
|
|
26263
|
+
threshold = 0.1,
|
|
26264
|
+
alpha = 0.1,
|
|
26265
|
+
aaColor = [255, 255, 0],
|
|
26266
|
+
diffColor = [255, 0, 0],
|
|
26267
|
+
includeAA,
|
|
26268
|
+
diffColorAlt,
|
|
26269
|
+
diffMask
|
|
26270
|
+
} = options;
|
|
26271
|
+
if (!isPixelData(img1) || !isPixelData(img2) || output && !isPixelData(output))
|
|
26272
|
+
throw new Error("Image data: Uint8Array, Uint8ClampedArray or Buffer expected.");
|
|
26273
|
+
if (img1.length !== img2.length || output && output.length !== img1.length)
|
|
26274
|
+
throw new Error("Image sizes do not match.");
|
|
26275
|
+
if (img1.length !== width * height * 4)
|
|
26276
|
+
throw new Error("Image data size does not match width/height.");
|
|
26277
|
+
const len = width * height;
|
|
26278
|
+
const a32 = new Uint32Array(img1.buffer, img1.byteOffset, len);
|
|
26279
|
+
const b32 = new Uint32Array(img2.buffer, img2.byteOffset, len);
|
|
26280
|
+
let identical = true;
|
|
26281
|
+
for (let i3 = 0;i3 < len; i3++) {
|
|
26282
|
+
if (a32[i3] !== b32[i3]) {
|
|
26283
|
+
identical = false;
|
|
26284
|
+
break;
|
|
26285
|
+
}
|
|
26286
|
+
}
|
|
26287
|
+
if (identical) {
|
|
26288
|
+
if (output && !diffMask) {
|
|
26289
|
+
for (let i3 = 0;i3 < len; i3++)
|
|
26290
|
+
drawGrayPixel(img1, 4 * i3, alpha, output);
|
|
26291
|
+
}
|
|
26292
|
+
return 0;
|
|
26293
|
+
}
|
|
26294
|
+
const maxDelta = 35215 * threshold * threshold;
|
|
26295
|
+
const [aaR, aaG, aaB] = aaColor;
|
|
26296
|
+
const [diffR, diffG, diffB] = diffColor;
|
|
26297
|
+
const [altR, altG, altB] = diffColorAlt || diffColor;
|
|
26298
|
+
let diff = 0;
|
|
26299
|
+
for (let y5 = 0;y5 < height; y5++) {
|
|
26300
|
+
for (let x3 = 0;x3 < width; x3++) {
|
|
26301
|
+
const i3 = y5 * width + x3;
|
|
26302
|
+
const pos = i3 * 4;
|
|
26303
|
+
const delta = a32[i3] === b32[i3] ? 0 : colorDelta(img1, img2, pos, pos, false);
|
|
26304
|
+
if (Math.abs(delta) > maxDelta) {
|
|
26305
|
+
const isAA = antialiased(img1, x3, y5, width, height, a32, b32) || antialiased(img2, x3, y5, width, height, b32, a32);
|
|
26306
|
+
if (!includeAA && isAA) {
|
|
26307
|
+
if (output && !diffMask)
|
|
26308
|
+
drawPixel(output, pos, aaR, aaG, aaB);
|
|
26309
|
+
} else {
|
|
26310
|
+
if (output) {
|
|
26311
|
+
if (delta < 0) {
|
|
26312
|
+
drawPixel(output, pos, altR, altG, altB);
|
|
26313
|
+
} else {
|
|
26314
|
+
drawPixel(output, pos, diffR, diffG, diffB);
|
|
26315
|
+
}
|
|
26316
|
+
}
|
|
26317
|
+
diff++;
|
|
26318
|
+
}
|
|
26319
|
+
} else if (output && !diffMask) {
|
|
26320
|
+
drawGrayPixel(img1, pos, alpha, output);
|
|
26321
|
+
}
|
|
26322
|
+
}
|
|
26323
|
+
}
|
|
26324
|
+
return diff;
|
|
26325
|
+
}
|
|
26326
|
+
function isPixelData(arr) {
|
|
26327
|
+
return ArrayBuffer.isView(arr) && arr.BYTES_PER_ELEMENT === 1;
|
|
26328
|
+
}
|
|
26329
|
+
function antialiased(img, x1, y1, width, height, a32, b32) {
|
|
26330
|
+
const x0 = Math.max(x1 - 1, 0);
|
|
26331
|
+
const y0 = Math.max(y1 - 1, 0);
|
|
26332
|
+
const x22 = Math.min(x1 + 1, width - 1);
|
|
26333
|
+
const y22 = Math.min(y1 + 1, height - 1);
|
|
26334
|
+
const pos = y1 * width + x1;
|
|
26335
|
+
let zeroes = x1 === x0 || x1 === x22 || y1 === y0 || y1 === y22 ? 1 : 0;
|
|
26336
|
+
let min = 0;
|
|
26337
|
+
let max = 0;
|
|
26338
|
+
let minX = 0;
|
|
26339
|
+
let minY = 0;
|
|
26340
|
+
let maxX = 0;
|
|
26341
|
+
let maxY = 0;
|
|
26342
|
+
for (let x3 = x0;x3 <= x22; x3++) {
|
|
26343
|
+
for (let y5 = y0;y5 <= y22; y5++) {
|
|
26344
|
+
if (x3 === x1 && y5 === y1)
|
|
26345
|
+
continue;
|
|
26346
|
+
const delta = colorDelta(img, img, pos * 4, (y5 * width + x3) * 4, true);
|
|
26347
|
+
if (delta === 0) {
|
|
26348
|
+
zeroes++;
|
|
26349
|
+
if (zeroes > 2)
|
|
26350
|
+
return false;
|
|
26351
|
+
} else if (delta < min) {
|
|
26352
|
+
min = delta;
|
|
26353
|
+
minX = x3;
|
|
26354
|
+
minY = y5;
|
|
26355
|
+
} else if (delta > max) {
|
|
26356
|
+
max = delta;
|
|
26357
|
+
maxX = x3;
|
|
26358
|
+
maxY = y5;
|
|
26359
|
+
}
|
|
26360
|
+
}
|
|
26361
|
+
}
|
|
26362
|
+
if (min === 0 || max === 0)
|
|
26363
|
+
return false;
|
|
26364
|
+
return hasManySiblings(a32, minX, minY, width, height) && hasManySiblings(b32, minX, minY, width, height) || hasManySiblings(a32, maxX, maxY, width, height) && hasManySiblings(b32, maxX, maxY, width, height);
|
|
26365
|
+
}
|
|
26366
|
+
function hasManySiblings(img, x1, y1, width, height) {
|
|
26367
|
+
const x0 = Math.max(x1 - 1, 0);
|
|
26368
|
+
const y0 = Math.max(y1 - 1, 0);
|
|
26369
|
+
const x22 = Math.min(x1 + 1, width - 1);
|
|
26370
|
+
const y22 = Math.min(y1 + 1, height - 1);
|
|
26371
|
+
const val = img[y1 * width + x1];
|
|
26372
|
+
let zeroes = x1 === x0 || x1 === x22 || y1 === y0 || y1 === y22 ? 1 : 0;
|
|
26373
|
+
for (let x3 = x0;x3 <= x22; x3++) {
|
|
26374
|
+
for (let y5 = y0;y5 <= y22; y5++) {
|
|
26375
|
+
if (x3 === x1 && y5 === y1)
|
|
26376
|
+
continue;
|
|
26377
|
+
zeroes += +(val === img[y5 * width + x3]);
|
|
26378
|
+
if (zeroes > 2)
|
|
26379
|
+
return true;
|
|
26380
|
+
}
|
|
26381
|
+
}
|
|
26382
|
+
return false;
|
|
26383
|
+
}
|
|
26384
|
+
function colorDelta(img1, img2, k6, m3, yOnly) {
|
|
26385
|
+
const r1 = img1[k6];
|
|
26386
|
+
const g1 = img1[k6 + 1];
|
|
26387
|
+
const b1 = img1[k6 + 2];
|
|
26388
|
+
const a1 = img1[k6 + 3];
|
|
26389
|
+
const r22 = img2[m3];
|
|
26390
|
+
const g22 = img2[m3 + 1];
|
|
26391
|
+
const b22 = img2[m3 + 2];
|
|
26392
|
+
const a22 = img2[m3 + 3];
|
|
26393
|
+
let dr = r1 - r22;
|
|
26394
|
+
let dg = g1 - g22;
|
|
26395
|
+
let db = b1 - b22;
|
|
26396
|
+
const da = a1 - a22;
|
|
26397
|
+
if (!dr && !dg && !db && !da)
|
|
26398
|
+
return 0;
|
|
26399
|
+
if (a1 < 255 || a22 < 255) {
|
|
26400
|
+
const rb = 48 + 159 * (k6 % 2);
|
|
26401
|
+
const gb = 48 + 159 * ((k6 / 1.618033988749895 | 0) % 2);
|
|
26402
|
+
const bb = 48 + 159 * ((k6 / 2.618033988749895 | 0) % 2);
|
|
26403
|
+
dr = (r1 * a1 - r22 * a22 - rb * da) / 255;
|
|
26404
|
+
dg = (g1 * a1 - g22 * a22 - gb * da) / 255;
|
|
26405
|
+
db = (b1 * a1 - b22 * a22 - bb * da) / 255;
|
|
26406
|
+
}
|
|
26407
|
+
const y5 = dr * 0.29889531 + dg * 0.58662247 + db * 0.11448223;
|
|
26408
|
+
if (yOnly)
|
|
26409
|
+
return y5;
|
|
26410
|
+
const i3 = dr * 0.59597799 - dg * 0.2741761 - db * 0.32180189;
|
|
26411
|
+
const q3 = dr * 0.21147017 - dg * 0.52261711 + db * 0.31114694;
|
|
26412
|
+
const delta = 0.5053 * y5 * y5 + 0.299 * i3 * i3 + 0.1957 * q3 * q3;
|
|
26413
|
+
return y5 > 0 ? -delta : delta;
|
|
26414
|
+
}
|
|
26415
|
+
function drawPixel(output, pos, r5, g5, b3) {
|
|
26416
|
+
output[pos + 0] = r5;
|
|
26417
|
+
output[pos + 1] = g5;
|
|
26418
|
+
output[pos + 2] = b3;
|
|
26419
|
+
output[pos + 3] = 255;
|
|
26420
|
+
}
|
|
26421
|
+
function drawGrayPixel(img, i3, alpha, output) {
|
|
26422
|
+
const val = 255 + (img[i3] * 0.29889531 + img[i3 + 1] * 0.58662247 + img[i3 + 2] * 0.11448223 - 255) * alpha * img[i3 + 3] / 255;
|
|
26423
|
+
drawPixel(output, i3, val, val, val);
|
|
26424
|
+
}
|
|
26425
|
+
|
|
26426
|
+
// packages/cli/src/commands/diff/visual.ts
|
|
26427
|
+
var exports_visual = {};
|
|
26428
|
+
__export(exports_visual, {
|
|
26429
|
+
default: () => visual_default
|
|
26430
|
+
});
|
|
26431
|
+
var import_pngjs, visual_default;
|
|
26432
|
+
var init_visual = __esm(() => {
|
|
26433
|
+
init_dist2();
|
|
26434
|
+
init_client();
|
|
26435
|
+
init_format();
|
|
26436
|
+
import_pngjs = __toESM(require_png(), 1);
|
|
26437
|
+
visual_default = defineCommand({
|
|
26438
|
+
meta: { description: "Create visual diff between two nodes as PNG" },
|
|
26439
|
+
args: {
|
|
26440
|
+
from: { type: "string", description: "Source node ID", required: true },
|
|
26441
|
+
to: { type: "string", description: "Target node ID", required: true },
|
|
26442
|
+
output: { type: "string", description: "Output file path", required: true },
|
|
26443
|
+
scale: { type: "string", description: "Export scale (default: 1)" },
|
|
26444
|
+
threshold: { type: "string", description: "Color threshold 0-1 (default: 0.1)" }
|
|
26445
|
+
},
|
|
26446
|
+
async run({ args }) {
|
|
26447
|
+
try {
|
|
26448
|
+
const scale = args.scale ? Number(args.scale) : 1;
|
|
26449
|
+
const threshold = args.threshold ? Number(args.threshold) : 0.1;
|
|
26450
|
+
const [fromResult, toResult] = await Promise.all([
|
|
26451
|
+
sendCommand("export-node", { id: args.from, format: "PNG", scale }),
|
|
26452
|
+
sendCommand("export-node", { id: args.to, format: "PNG", scale })
|
|
26453
|
+
]);
|
|
26454
|
+
if (!fromResult?.data || !toResult?.data) {
|
|
26455
|
+
console.error(fail("Could not export nodes"));
|
|
26456
|
+
process.exit(1);
|
|
26457
|
+
}
|
|
26458
|
+
const fromPng = import_pngjs.PNG.sync.read(Buffer.from(fromResult.data, "base64"));
|
|
26459
|
+
const toPng = import_pngjs.PNG.sync.read(Buffer.from(toResult.data, "base64"));
|
|
26460
|
+
if (fromPng.width !== toPng.width || fromPng.height !== toPng.height) {
|
|
26461
|
+
console.error(fail(`Size mismatch: ${fromPng.width}\xD7${fromPng.height} vs ${toPng.width}\xD7${toPng.height}`));
|
|
26462
|
+
process.exit(1);
|
|
26463
|
+
}
|
|
26464
|
+
const { width, height } = fromPng;
|
|
26465
|
+
const diff = new import_pngjs.PNG({ width, height });
|
|
26466
|
+
const diffPixels = pixelmatch(fromPng.data, toPng.data, diff.data, width, height, { threshold });
|
|
26467
|
+
const totalPixels = width * height;
|
|
26468
|
+
const diffPercent = (diffPixels / totalPixels * 100).toFixed(2);
|
|
26469
|
+
await Bun.write(args.output, import_pngjs.PNG.sync.write(diff));
|
|
26470
|
+
console.log(`${diffPixels} pixels differ (${diffPercent}%)`);
|
|
26471
|
+
console.log(`Saved to ${args.output}`);
|
|
26472
|
+
} catch (e6) {
|
|
26473
|
+
handleError(e6);
|
|
26474
|
+
}
|
|
26475
|
+
}
|
|
26476
|
+
});
|
|
26477
|
+
});
|
|
26478
|
+
|
|
24373
26479
|
// packages/cli/src/index.ts
|
|
24374
26480
|
init_dist2();
|
|
24375
26481
|
|
|
@@ -30510,7 +32616,8 @@ var diff_default = defineCommand({
|
|
|
30510
32616
|
subCommands: {
|
|
30511
32617
|
apply: () => Promise.resolve().then(() => (init_apply2(), exports_apply)).then((m3) => m3.default),
|
|
30512
32618
|
show: () => Promise.resolve().then(() => (init_show(), exports_show)).then((m3) => m3.default),
|
|
30513
|
-
create: () => Promise.resolve().then(() => (init_create2(), exports_create)).then((m3) => m3.default)
|
|
32619
|
+
create: () => Promise.resolve().then(() => (init_create2(), exports_create)).then((m3) => m3.default),
|
|
32620
|
+
visual: () => Promise.resolve().then(() => (init_visual(), exports_visual)).then((m3) => m3.default)
|
|
30514
32621
|
}
|
|
30515
32622
|
});
|
|
30516
32623
|
// packages/cli/src/commands/node/index.ts
|
|
@@ -31659,7 +33766,7 @@ var rotation_default = defineCommand({
|
|
|
31659
33766
|
meta: { description: "Set rotation angle" },
|
|
31660
33767
|
args: {
|
|
31661
33768
|
id: { type: "positional", description: "Node ID", required: true },
|
|
31662
|
-
angle: { type: "
|
|
33769
|
+
angle: { type: "string", description: "Angle in degrees", required: true },
|
|
31663
33770
|
json: { type: "boolean", description: "Output as JSON" }
|
|
31664
33771
|
},
|
|
31665
33772
|
async run({ args }) {
|
|
@@ -33357,7 +35464,7 @@ var font_default2 = defineCommand({
|
|
|
33357
35464
|
}
|
|
33358
35465
|
});
|
|
33359
35466
|
// package.json
|
|
33360
|
-
var version = "0.6.
|
|
35467
|
+
var version = "0.6.3";
|
|
33361
35468
|
|
|
33362
35469
|
// packages/cli/src/index.ts
|
|
33363
35470
|
var main = defineCommand({
|