Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-pdf/png-js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-pdf/png-js - npm Package Compare versions

Comparing version 2.3.1 to 3.0.0

166

lib/png-js.js
import fs from 'fs';
import zlib from 'zlib';
var PNG = /*#__PURE__*/function () {
PNG.decode = function decode(path, fn) {
class PNG {
static decode(path, fn) {
{
return fs.readFile(path, function (err, file) {
var png = new PNG(file);
return png.decode(function (pixels) {
return fn(pixels);
});
return fs.readFile(path, (err, file) => {
const png = new PNG(file);
return png.decode(pixels => fn(pixels));
});
}
};
PNG.load = function load(path) {
}
static load(path) {
{
var file = fs.readFileSync(path);
const file = fs.readFileSync(path);
return new PNG(file);
}
};
function PNG(data) {
var i;
}
constructor(data) {
let i;
this.data = data;

@@ -31,4 +29,4 @@ this.pos = 8; // Skip the default header

while (true) {
var chunkSize = this.readUInt32();
var section = '';
const chunkSize = this.readUInt32();
let section = '';
for (i = 0; i < 4; i++) {

@@ -128,31 +126,31 @@ section += String.fromCharCode(this.data[this.pos++]);

}
var _proto = PNG.prototype;
_proto.read = function read(bytes) {
var result = new Array(bytes);
for (var i = 0; i < bytes; i++) {
read(bytes) {
const result = new Array(bytes);
for (let i = 0; i < bytes; i++) {
result[i] = this.data[this.pos++];
}
return result;
};
_proto.readUInt32 = function readUInt32() {
var b1 = this.data[this.pos++] << 24;
var b2 = this.data[this.pos++] << 16;
var b3 = this.data[this.pos++] << 8;
var b4 = this.data[this.pos++];
}
readUInt32() {
const b1 = this.data[this.pos++] << 24;
const b2 = this.data[this.pos++] << 16;
const b3 = this.data[this.pos++] << 8;
const b4 = this.data[this.pos++];
return b1 | b2 | b3 | b4;
};
_proto.readUInt16 = function readUInt16() {
var b1 = this.data[this.pos++] << 8;
var b2 = this.data[this.pos++];
}
readUInt16() {
const b1 = this.data[this.pos++] << 8;
const b2 = this.data[this.pos++];
return b1 | b2;
};
_proto.decodePixels = function decodePixels(fn) {
var _this = this;
return zlib.inflate(this.imgData, function (err, data) {
}
decodePixels(fn) {
return zlib.inflate(this.imgData, (err, data) => {
if (err) throw err;
var pos = 0;
var width = _this.width,
height = _this.height;
var pixelBytes = _this.pixelBitlength / 8;
var pixels = Buffer.alloc(width * height * pixelBytes);
const {
width,
height
} = this;
var pixelBytes = this.pixelBitlength / 8;
const pixels = Buffer.alloc(width * height * pixelBytes);
function pass(x0, y0, dx, dy, singlePass) {

@@ -162,8 +160,8 @@ if (singlePass === void 0) {

}
var w = Math.ceil((width - x0) / dx);
var h = Math.ceil((height - y0) / dy);
var scanlineLength = pixelBytes * w;
var buffer = singlePass ? pixels : Buffer.alloc(scanlineLength * h);
var row = 0;
var c = 0;
const w = Math.ceil((width - x0) / dx);
const h = Math.ceil((height - y0) / dy);
const scanlineLength = pixelBytes * w;
const buffer = singlePass ? pixels : Buffer.alloc(scanlineLength * h);
let row = 0;
let c = 0;
while (row < h && pos < data.length) {

@@ -223,6 +221,6 @@ var byte;

}
var p = left + upper - upperLeft;
var pa = Math.abs(p - left);
var pb = Math.abs(p - upper);
var pc = Math.abs(p - upperLeft);
const p = left + upper - upperLeft;
const pa = Math.abs(p - left);
const pb = Math.abs(p - upper);
const pc = Math.abs(p - upperLeft);
if (pa <= pb && pa <= pc) {

@@ -239,9 +237,9 @@ paeth = left;

default:
throw new Error("Invalid filter algorithm: " + data[pos - 1]);
throw new Error(`Invalid filter algorithm: ${data[pos - 1]}`);
}
if (!singlePass) {
var pixelsPos = ((y0 + row * dy) * width + x0) * pixelBytes;
var bufferPos = row * scanlineLength;
let pixelsPos = ((y0 + row * dy) * width + x0) * pixelBytes;
let bufferPos = row * scanlineLength;
for (i = 0; i < w; i++) {
for (var j = 0; j < pixelBytes; j++) pixels[pixelsPos++] = buffer[bufferPos++];
for (let j = 0; j < pixelBytes; j++) pixels[pixelsPos++] = buffer[bufferPos++];
pixelsPos += (dx - 1) * pixelBytes;

@@ -253,3 +251,3 @@ }

}
if (_this.interlaceMethod === 1) {
if (this.interlaceMethod === 1) {
/*

@@ -277,11 +275,15 @@ 1 6 4 6 2 6 4 6

});
};
_proto.decodePalette = function decodePalette() {
var palette = this.palette;
var length = palette.length;
var transparency = this.transparency.indexed || [];
var ret = Buffer.alloc(transparency.length + length);
var pos = 0;
var c = 0;
for (var i = 0; i < length; i += 3) {
}
decodePalette() {
const {
palette
} = this;
const {
length
} = palette;
const transparency = this.transparency.indexed || [];
const ret = Buffer.alloc(transparency.length + length);
let pos = 0;
let c = 0;
for (let i = 0; i < length; i += 3) {
var left;

@@ -294,9 +296,11 @@ ret[pos++] = palette[i];

return ret;
};
_proto.copyToImageData = function copyToImageData(imageData, pixels) {
var j;
}
copyToImageData(imageData, pixels) {
let j;
var k;
var colors = this.colors;
var palette = null;
var alpha = this.hasAlphaChannel;
let {
colors
} = this;
let palette = null;
let alpha = this.hasAlphaChannel;
if (this.palette.length) {

@@ -307,10 +311,12 @@ palette = this._decodedPalette || (this._decodedPalette = this.decodePalette());

}
var data = imageData.data || imageData;
var length = data.length;
var input = palette || pixels;
var i = j = 0;
const data = imageData.data || imageData;
const {
length
} = data;
const input = palette || pixels;
let i = j = 0;
if (colors === 1) {
while (i < length) {
k = palette ? pixels[i / 4] * 4 : j;
var v = input[k++];
const v = input[k++];
data[i++] = v;

@@ -332,14 +338,12 @@ data[i++] = v;

}
};
_proto.decode = function decode(fn) {
var _this2 = this;
var ret = Buffer.alloc(this.width * this.height * 4);
return this.decodePixels(function (pixels) {
_this2.copyToImageData(ret, pixels);
}
decode(fn) {
const ret = Buffer.alloc(this.width * this.height * 4);
return this.decodePixels(pixels => {
this.copyToImageData(ret, pixels);
return fn(ret);
});
};
return PNG;
}();
}
}
export { PNG as default };
{
"name": "@react-pdf/png-js",
"description": "A PNG decoder in JS",
"version": "2.3.1",
"version": "3.0.0",
"license": "MIT",
"type": "module",
"main": "./lib/png-js.cjs",
"module": "./lib/png-js.js",
"main": "./lib/png-js.js",
"browser": {
"./lib/png-js.js": "./lib/png-js.browser.js",
"./lib/png-js.cjs": "./lib/png-js.browser.cjs"
"./lib/png-js.js": "./lib/png-js.browser.js"
},
"exports": {
".": {
"import": "./lib/png-js.js",
"require": "./lib/png-js.cjs",
"default": "./lib/png-js.js"
}
},
"repository": {

@@ -21,0 +12,0 @@ "type": "git",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc