Latest repo

This commit is contained in:
Marc
2025-06-02 16:42:16 +00:00
parent 53ddf1a329
commit cde5fae175
27907 changed files with 3875388 additions and 1 deletions

21
node_modules/@react-pdf/png-js/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Devon Govett
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

50
node_modules/@react-pdf/png-js/README.md generated vendored Normal file
View File

@@ -0,0 +1,50 @@
<p align="center">
<img src="https://user-images.githubusercontent.com/5600341/27505816-c8bc37aa-587f-11e7-9a86-08a2d081a8b9.png" height="280px">
</p>
# @react-pdf/png-js
A PNG decoder in JS for the canvas element or Node.js.
## Acknowledges
This project is a fork of [png.js](https://github.com/foliojs/png.js) by @devongovett and continued under the scope of this project since it has react-pdf specific features. Any recongnition should go to him and the original project mantainers.
## About this fork
> Updated to 977b857a11676c1e720e79ed8d9178a005a9abd6
- Build node and browser specific bundles
- Uses rollup for build
## Browser Usage
Simply include png.js and zlib.js on your HTML page, create a canvas element, and call PNG.load to load an image.
<canvas></canvas>
<script src="zlib.js"></script>
<script src="png.js"></script>
<script>
var canvas = document.getElementsByTagName('canvas')[0];
PNG.load('some.png', canvas);
</script>
The source code for the browser version resides in `png.js` and also supports loading and displaying animated PNGs.
## Node.js Usage
Install the module using npm
sudo npm install png-js
Require the module and decode a PNG
var PNG = require('png-js');
PNG.decode('some.png', function(pixels) {
// pixels is a 1d array (in rgba order) of decoded pixel data
});
You can also call `PNG.load` if you want to load the PNG (but not decode the pixels) synchronously. If you already
have the PNG data in a buffer, simply use `new PNG(buffer)`. In both of these cases, you need to call `png.decode`
yourself which passes your callback the decoded pixels as a buffer. If you already have a buffer you want the pixels
copied to, call `copyToImageData` with your buffer and the decoded pixels as returned from `decodePixels`.

12600
node_modules/@react-pdf/png-js/lib/png-js.browser.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

339
node_modules/@react-pdf/png-js/lib/png-js.js generated vendored Normal file
View File

@@ -0,0 +1,339 @@
import fs from 'fs';
import zlib from 'zlib';
class PNG {
static decode(path, fn) {
{
return fs.readFile(path, (err, file) => {
const png = new PNG(file);
return png.decode(pixels => fn(pixels));
});
}
}
static load(path) {
{
const file = fs.readFileSync(path);
return new PNG(file);
}
}
constructor(data) {
let i;
this.data = data;
this.pos = 8; // Skip the default header
this.palette = [];
this.imgData = [];
this.transparency = {};
this.text = {};
while (true) {
const chunkSize = this.readUInt32();
let section = '';
for (i = 0; i < 4; i++) {
section += String.fromCharCode(this.data[this.pos++]);
}
switch (section) {
case 'IHDR':
// we can grab interesting values from here (like width, height, etc)
this.width = this.readUInt32();
this.height = this.readUInt32();
this.bits = this.data[this.pos++];
this.colorType = this.data[this.pos++];
this.compressionMethod = this.data[this.pos++];
this.filterMethod = this.data[this.pos++];
this.interlaceMethod = this.data[this.pos++];
break;
case 'PLTE':
this.palette = this.read(chunkSize);
break;
case 'IDAT':
for (i = 0; i < chunkSize; i++) {
this.imgData.push(this.data[this.pos++]);
}
break;
case 'tRNS':
// This chunk can only occur once and it must occur after the
// PLTE chunk and before the IDAT chunk.
this.transparency = {};
switch (this.colorType) {
case 3:
// Indexed color, RGB. Each byte in this chunk is an alpha for
// the palette index in the PLTE ("palette") chunk up until the
// last non-opaque entry. Set up an array, stretching over all
// palette entries which will be 0 (opaque) or 1 (transparent).
this.transparency.indexed = this.read(chunkSize);
var short = 255 - this.transparency.indexed.length;
if (short > 0) {
for (i = 0; i < short; i++) {
this.transparency.indexed.push(255);
}
}
break;
case 0:
// Greyscale. Corresponding to entries in the PLTE chunk.
// Grey is two bytes, range 0 .. (2 ^ bit-depth) - 1
this.transparency.grayscale = this.read(chunkSize)[0];
break;
case 2:
// True color with proper alpha channel.
this.transparency.rgb = this.read(chunkSize);
break;
}
break;
case 'tEXt':
var text = this.read(chunkSize);
var index = text.indexOf(0);
var key = String.fromCharCode.apply(String, text.slice(0, index));
this.text[key] = String.fromCharCode.apply(String, text.slice(index + 1));
break;
case 'IEND':
// we've got everything we need!
switch (this.colorType) {
case 0:
case 3:
case 4:
this.colors = 1;
break;
case 2:
case 6:
this.colors = 3;
break;
}
this.hasAlphaChannel = [4, 6].includes(this.colorType);
var colors = this.colors + (this.hasAlphaChannel ? 1 : 0);
this.pixelBitlength = this.bits * colors;
switch (this.colors) {
case 1:
this.colorSpace = 'DeviceGray';
break;
case 3:
this.colorSpace = 'DeviceRGB';
break;
}
this.imgData = Buffer.from(this.imgData);
return;
default:
// unknown (or unimportant) section, skip it
this.pos += chunkSize;
}
this.pos += 4; // Skip the CRC
if (this.pos > this.data.length) {
throw new Error('Incomplete or corrupt PNG file');
}
}
}
read(bytes) {
const result = new Array(bytes);
for (let i = 0; i < bytes; i++) {
result[i] = this.data[this.pos++];
}
return result;
}
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;
}
readUInt16() {
const b1 = this.data[this.pos++] << 8;
const b2 = this.data[this.pos++];
return b1 | b2;
}
decodePixels(fn) {
return zlib.inflate(this.imgData, (err, data) => {
if (err) throw err;
var pos = 0;
const {
width,
height
} = this;
var pixelBytes = this.pixelBitlength / 8;
const pixels = Buffer.alloc(width * height * pixelBytes);
function pass(x0, y0, dx, dy, singlePass) {
if (singlePass === void 0) {
singlePass = false;
}
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) {
var byte;
var col;
var i;
var left;
var upper;
switch (data[pos++]) {
case 0:
// None
for (i = 0; i < scanlineLength; i++) {
buffer[c++] = data[pos++];
}
break;
case 1:
// Sub
for (i = 0; i < scanlineLength; i++) {
byte = data[pos++];
left = i < pixelBytes ? 0 : buffer[c - pixelBytes];
buffer[c++] = (byte + left) % 256;
}
break;
case 2:
// Up
for (i = 0; i < scanlineLength; i++) {
byte = data[pos++];
col = (i - i % pixelBytes) / pixelBytes;
upper = row && buffer[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];
buffer[c++] = (upper + byte) % 256;
}
break;
case 3:
// Average
for (i = 0; i < scanlineLength; i++) {
byte = data[pos++];
col = (i - i % pixelBytes) / pixelBytes;
left = i < pixelBytes ? 0 : buffer[c - pixelBytes];
upper = row && buffer[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];
buffer[c++] = (byte + Math.floor((left + upper) / 2)) % 256;
}
break;
case 4:
// Paeth
for (i = 0; i < scanlineLength; i++) {
var paeth;
var upperLeft;
byte = data[pos++];
col = (i - i % pixelBytes) / pixelBytes;
left = i < pixelBytes ? 0 : buffer[c - pixelBytes];
if (row === 0) {
upper = upperLeft = 0;
} else {
upper = buffer[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];
upperLeft = col && buffer[(row - 1) * scanlineLength + (col - 1) * pixelBytes + i % pixelBytes];
}
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) {
paeth = left;
} else if (pb <= pc) {
paeth = upper;
} else {
paeth = upperLeft;
}
buffer[c++] = (byte + paeth) % 256;
}
break;
default:
throw new Error(`Invalid filter algorithm: ${data[pos - 1]}`);
}
if (!singlePass) {
let pixelsPos = ((y0 + row * dy) * width + x0) * pixelBytes;
let bufferPos = row * scanlineLength;
for (i = 0; i < w; i++) {
for (let j = 0; j < pixelBytes; j++) pixels[pixelsPos++] = buffer[bufferPos++];
pixelsPos += (dx - 1) * pixelBytes;
}
}
row++;
}
}
if (this.interlaceMethod === 1) {
/*
1 6 4 6 2 6 4 6
7 7 7 7 7 7 7 7
5 6 5 6 5 6 5 6
7 7 7 7 7 7 7 7
3 6 4 6 3 6 4 6
7 7 7 7 7 7 7 7
5 6 5 6 5 6 5 6
7 7 7 7 7 7 7 7
*/
pass(0, 0, 8, 8); // 1
pass(4, 0, 8, 8); // 2
pass(0, 4, 4, 8); // 3
pass(2, 0, 4, 4); // 4
pass(0, 2, 2, 4); // 5
pass(1, 0, 2, 2); // 6
pass(0, 1, 1, 2); // 7
} else {
pass(0, 0, 1, 1, true);
}
return fn(pixels);
});
}
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;
ret[pos++] = palette[i];
ret[pos++] = palette[i + 1];
ret[pos++] = palette[i + 2];
ret[pos++] = (left = transparency[c++]) != null ? left : 255;
}
return ret;
}
copyToImageData(imageData, pixels) {
let j;
var k;
let {
colors
} = this;
let palette = null;
let alpha = this.hasAlphaChannel;
if (this.palette.length) {
palette = this._decodedPalette || (this._decodedPalette = this.decodePalette());
colors = 4;
alpha = true;
}
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;
const v = input[k++];
data[i++] = v;
data[i++] = v;
data[i++] = v;
data[i++] = alpha ? input[k++] : 255;
j = k;
}
} else {
while (i < length) {
k = palette ? pixels[i / 4] * 4 : j;
data[i++] = input[k++];
data[i++] = input[k++];
data[i++] = input[k++];
data[i++] = alpha ? input[k++] : 255;
j = k;
}
}
}
decode(fn) {
const ret = Buffer.alloc(this.width * this.height * 4);
return this.decodePixels(pixels => {
this.copyToImageData(ret, pixels);
return fn(ret);
});
}
}
export { PNG as default };

31
node_modules/@react-pdf/png-js/package.json generated vendored Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "@react-pdf/png-js",
"description": "A PNG decoder in JS",
"version": "3.0.0",
"license": "MIT",
"type": "module",
"main": "./lib/png-js.js",
"browser": {
"./lib/png-js.js": "./lib/png-js.browser.js"
},
"repository": {
"type": "git",
"url": "https://github.com/diegomura/react-pdf.git",
"directory": "packages/png-js"
},
"author": {
"name": "Devon Govett",
"email": "devongovett@gmail.com",
"url": "http://badassjs.com/"
},
"scripts": {
"build": "rimraf ./lib && rollup -c",
"watch": "rimraf ./lib && rollup -c -w"
},
"files": [
"lib"
],
"dependencies": {
"browserify-zlib": "^0.2.0"
}
}