This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

2
node_modules/image-size/dist/detector.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { imageType } from './types/index';
export declare function detector(input: Uint8Array): imageType | undefined;

30
node_modules/image-size/dist/detector.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.detector = void 0;
const index_1 = require("./types/index");
const keys = Object.keys(index_1.typeHandlers);
// This map helps avoid validating for every single image type
const firstBytes = {
0x38: 'psd',
0x42: 'bmp',
0x44: 'dds',
0x47: 'gif',
0x49: 'tiff',
0x4d: 'tiff',
0x52: 'webp',
0x69: 'icns',
0x89: 'png',
0xff: 'jpg',
};
function detector(input) {
const byte = input[0];
if (byte in firstBytes) {
const type = firstBytes[byte];
if (type && index_1.typeHandlers[type].validate(input)) {
return type;
}
}
const finder = (key) => index_1.typeHandlers[key].validate(input);
return keys.find(finder);
}
exports.detector = detector;

10
node_modules/image-size/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import type { imageType } from './types/index';
import type { ISizeCalculationResult } from './types/interface';
type CallbackFn = (e: Error | null, r?: ISizeCalculationResult) => void;
export default imageSize;
export declare function imageSize(input: Uint8Array | string): ISizeCalculationResult;
export declare function imageSize(input: string, callback: CallbackFn): void;
export declare const disableFS: (v: boolean) => void;
export declare const disableTypes: (types: imageType[]) => void;
export declare const setConcurrency: (c: number) => void;
export declare const types: string[];

129
node_modules/image-size/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,129 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.types = exports.setConcurrency = exports.disableTypes = exports.disableFS = exports.imageSize = void 0;
const fs = require("fs");
const path = require("path");
const queue_1 = require("queue");
const index_1 = require("./types/index");
const detector_1 = require("./detector");
// Maximum input size, with a default of 512 kilobytes.
// TO-DO: make this adaptive based on the initial signature of the image
const MaxInputSize = 512 * 1024;
// This queue is for async `fs` operations, to avoid reaching file-descriptor limits
const queue = new queue_1.default({ concurrency: 100, autostart: true });
const globalOptions = {
disabledFS: false,
disabledTypes: [],
};
/**
* Return size information based on an Uint8Array
*
* @param {Uint8Array} input
* @param {String} filepath
* @returns {Object}
*/
function lookup(input, filepath) {
// detect the file type.. don't rely on the extension
const type = (0, detector_1.detector)(input);
if (typeof type !== 'undefined') {
if (globalOptions.disabledTypes.indexOf(type) > -1) {
throw new TypeError('disabled file type: ' + type);
}
// find an appropriate handler for this file type
if (type in index_1.typeHandlers) {
const size = index_1.typeHandlers[type].calculate(input, filepath);
if (size !== undefined) {
size.type = size.type ?? type;
return size;
}
}
}
// throw up, if we don't understand the file
throw new TypeError('unsupported file type: ' + type + ' (file: ' + filepath + ')');
}
/**
* Reads a file into an Uint8Array.
* @param {String} filepath
* @returns {Promise<Uint8Array>}
*/
async function readFileAsync(filepath) {
const handle = await fs.promises.open(filepath, 'r');
try {
const { size } = await handle.stat();
if (size <= 0) {
throw new Error('Empty file');
}
const inputSize = Math.min(size, MaxInputSize);
const input = new Uint8Array(inputSize);
await handle.read(input, 0, inputSize, 0);
return input;
}
finally {
await handle.close();
}
}
/**
* Synchronously reads a file into an Uint8Array, blocking the nodejs process.
*
* @param {String} filepath
* @returns {Uint8Array}
*/
function readFileSync(filepath) {
// read from the file, synchronously
const descriptor = fs.openSync(filepath, 'r');
try {
const { size } = fs.fstatSync(descriptor);
if (size <= 0) {
throw new Error('Empty file');
}
const inputSize = Math.min(size, MaxInputSize);
const input = new Uint8Array(inputSize);
fs.readSync(descriptor, input, 0, inputSize, 0);
return input;
}
finally {
fs.closeSync(descriptor);
}
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
module.exports = exports = imageSize; // backwards compatibility
exports.default = imageSize;
/**
* @param {Uint8Array|string} input - Uint8Array or relative/absolute path of the image file
* @param {Function=} [callback] - optional function for async detection
*/
function imageSize(input, callback) {
// Handle Uint8Array input
if (input instanceof Uint8Array) {
return lookup(input);
}
// input should be a string at this point
if (typeof input !== 'string' || globalOptions.disabledFS) {
throw new TypeError('invalid invocation. input should be a Uint8Array');
}
// resolve the file path
const filepath = path.resolve(input);
if (typeof callback === 'function') {
queue.push(() => readFileAsync(filepath)
.then((input) => process.nextTick(callback, null, lookup(input, filepath)))
.catch(callback));
}
else {
const input = readFileSync(filepath);
return lookup(input, filepath);
}
}
exports.imageSize = imageSize;
const disableFS = (v) => {
globalOptions.disabledFS = v;
};
exports.disableFS = disableFS;
const disableTypes = (types) => {
globalOptions.disabledTypes = types;
};
exports.disableTypes = disableTypes;
const setConcurrency = (c) => {
queue.concurrency = c;
};
exports.setConcurrency = setConcurrency;
exports.types = Object.keys(index_1.typeHandlers);

2
node_modules/image-size/dist/types/bmp.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const BMP: IImage;

11
node_modules/image-size/dist/types/bmp.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BMP = void 0;
const utils_1 = require("./utils");
exports.BMP = {
validate: (input) => (0, utils_1.toUTF8String)(input, 0, 2) === 'BM',
calculate: (input) => ({
height: Math.abs((0, utils_1.readInt32LE)(input, 22)),
width: (0, utils_1.readUInt32LE)(input, 18),
}),
};

2
node_modules/image-size/dist/types/cur.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const CUR: IImage;

17
node_modules/image-size/dist/types/cur.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CUR = void 0;
const ico_1 = require("./ico");
const utils_1 = require("./utils");
const TYPE_CURSOR = 2;
exports.CUR = {
validate(input) {
const reserved = (0, utils_1.readUInt16LE)(input, 0);
const imageCount = (0, utils_1.readUInt16LE)(input, 4);
if (reserved !== 0 || imageCount === 0)
return false;
const imageType = (0, utils_1.readUInt16LE)(input, 2);
return imageType === TYPE_CURSOR;
},
calculate: (input) => ico_1.ICO.calculate(input),
};

2
node_modules/image-size/dist/types/dds.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const DDS: IImage;

11
node_modules/image-size/dist/types/dds.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DDS = void 0;
const utils_1 = require("./utils");
exports.DDS = {
validate: (input) => (0, utils_1.readUInt32LE)(input, 0) === 0x20534444,
calculate: (input) => ({
height: (0, utils_1.readUInt32LE)(input, 12),
width: (0, utils_1.readUInt32LE)(input, 16),
}),
};

2
node_modules/image-size/dist/types/gif.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const GIF: IImage;

12
node_modules/image-size/dist/types/gif.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GIF = void 0;
const utils_1 = require("./utils");
const gifRegexp = /^GIF8[79]a/;
exports.GIF = {
validate: (input) => gifRegexp.test((0, utils_1.toUTF8String)(input, 0, 6)),
calculate: (input) => ({
height: (0, utils_1.readUInt16LE)(input, 8),
width: (0, utils_1.readUInt16LE)(input, 6),
}),
};

2
node_modules/image-size/dist/types/heif.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const HEIF: IImage;

35
node_modules/image-size/dist/types/heif.js generated vendored Normal file
View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HEIF = void 0;
const utils_1 = require("./utils");
const brandMap = {
avif: 'avif',
mif1: 'heif',
msf1: 'heif', // hief-sequence
heic: 'heic',
heix: 'heic',
hevc: 'heic', // heic-sequence
hevx: 'heic', // heic-sequence
};
exports.HEIF = {
validate(buffer) {
const ftype = (0, utils_1.toUTF8String)(buffer, 4, 8);
const brand = (0, utils_1.toUTF8String)(buffer, 8, 12);
return 'ftyp' === ftype && brand in brandMap;
},
calculate(buffer) {
// Based on https://nokiatech.github.io/heif/technical.html
const metaBox = (0, utils_1.findBox)(buffer, 'meta', 0);
const iprpBox = metaBox && (0, utils_1.findBox)(buffer, 'iprp', metaBox.offset + 12);
const ipcoBox = iprpBox && (0, utils_1.findBox)(buffer, 'ipco', iprpBox.offset + 8);
const ispeBox = ipcoBox && (0, utils_1.findBox)(buffer, 'ispe', ipcoBox.offset + 8);
if (ispeBox) {
return {
height: (0, utils_1.readUInt32BE)(buffer, ispeBox.offset + 16),
width: (0, utils_1.readUInt32BE)(buffer, ispeBox.offset + 12),
type: (0, utils_1.toUTF8String)(buffer, 8, 12),
};
}
throw new TypeError('Invalid HEIF, no size found');
}
};

2
node_modules/image-size/dist/types/icns.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const ICNS: IImage;

101
node_modules/image-size/dist/types/icns.js generated vendored Normal file
View File

@@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ICNS = void 0;
const utils_1 = require("./utils");
/**
* ICNS Header
*
* | Offset | Size | Purpose |
* | 0 | 4 | Magic literal, must be "icns" (0x69, 0x63, 0x6e, 0x73) |
* | 4 | 4 | Length of file, in bytes, msb first. |
*
*/
const SIZE_HEADER = 4 + 4; // 8
const FILE_LENGTH_OFFSET = 4; // MSB => BIG ENDIAN
/**
* Image Entry
*
* | Offset | Size | Purpose |
* | 0 | 4 | Icon type, see OSType below. |
* | 4 | 4 | Length of data, in bytes (including type and length), msb first. |
* | 8 | n | Icon data |
*/
const ENTRY_LENGTH_OFFSET = 4; // MSB => BIG ENDIAN
const ICON_TYPE_SIZE = {
ICON: 32,
'ICN#': 32,
// m => 16 x 16
'icm#': 16,
icm4: 16,
icm8: 16,
// s => 16 x 16
'ics#': 16,
ics4: 16,
ics8: 16,
is32: 16,
s8mk: 16,
icp4: 16,
// l => 32 x 32
icl4: 32,
icl8: 32,
il32: 32,
l8mk: 32,
icp5: 32,
ic11: 32,
// h => 48 x 48
ich4: 48,
ich8: 48,
ih32: 48,
h8mk: 48,
// . => 64 x 64
icp6: 64,
ic12: 32,
// t => 128 x 128
it32: 128,
t8mk: 128,
ic07: 128,
// . => 256 x 256
ic08: 256,
ic13: 256,
// . => 512 x 512
ic09: 512,
ic14: 512,
// . => 1024 x 1024
ic10: 1024,
};
function readImageHeader(input, imageOffset) {
const imageLengthOffset = imageOffset + ENTRY_LENGTH_OFFSET;
return [
(0, utils_1.toUTF8String)(input, imageOffset, imageLengthOffset),
(0, utils_1.readUInt32BE)(input, imageLengthOffset),
];
}
function getImageSize(type) {
const size = ICON_TYPE_SIZE[type];
return { width: size, height: size, type };
}
exports.ICNS = {
validate: (input) => (0, utils_1.toUTF8String)(input, 0, 4) === 'icns',
calculate(input) {
const inputLength = input.length;
const fileLength = (0, utils_1.readUInt32BE)(input, FILE_LENGTH_OFFSET);
let imageOffset = SIZE_HEADER;
let imageHeader = readImageHeader(input, imageOffset);
let imageSize = getImageSize(imageHeader[0]);
imageOffset += imageHeader[1];
if (imageOffset === fileLength)
return imageSize;
const result = {
height: imageSize.height,
images: [imageSize],
width: imageSize.width,
};
while (imageOffset < fileLength && imageOffset < inputLength) {
imageHeader = readImageHeader(input, imageOffset);
imageSize = getImageSize(imageHeader[0]);
imageOffset += imageHeader[1];
result.images.push(imageSize);
}
return result;
},
};

2
node_modules/image-size/dist/types/ico.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const ICO: IImage;

68
node_modules/image-size/dist/types/ico.js generated vendored Normal file
View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ICO = void 0;
const utils_1 = require("./utils");
const TYPE_ICON = 1;
/**
* ICON Header
*
* | Offset | Size | Purpose |
* | 0 | 2 | Reserved. Must always be 0. |
* | 2 | 2 | Image type: 1 for icon (.ICO) image, 2 for cursor (.CUR) image. Other values are invalid. |
* | 4 | 2 | Number of images in the file. |
*
*/
const SIZE_HEADER = 2 + 2 + 2; // 6
/**
* Image Entry
*
* | Offset | Size | Purpose |
* | 0 | 1 | Image width in pixels. Can be any number between 0 and 255. Value 0 means width is 256 pixels. |
* | 1 | 1 | Image height in pixels. Can be any number between 0 and 255. Value 0 means height is 256 pixels. |
* | 2 | 1 | Number of colors in the color palette. Should be 0 if the image does not use a color palette. |
* | 3 | 1 | Reserved. Should be 0. |
* | 4 | 2 | ICO format: Color planes. Should be 0 or 1. |
* | | | CUR format: The horizontal coordinates of the hotspot in number of pixels from the left. |
* | 6 | 2 | ICO format: Bits per pixel. |
* | | | CUR format: The vertical coordinates of the hotspot in number of pixels from the top. |
* | 8 | 4 | The size of the image's data in bytes |
* | 12 | 4 | The offset of BMP or PNG data from the beginning of the ICO/CUR file |
*
*/
const SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; // 16
function getSizeFromOffset(input, offset) {
const value = input[offset];
return value === 0 ? 256 : value;
}
function getImageSize(input, imageIndex) {
const offset = SIZE_HEADER + imageIndex * SIZE_IMAGE_ENTRY;
return {
height: getSizeFromOffset(input, offset + 1),
width: getSizeFromOffset(input, offset),
};
}
exports.ICO = {
validate(input) {
const reserved = (0, utils_1.readUInt16LE)(input, 0);
const imageCount = (0, utils_1.readUInt16LE)(input, 4);
if (reserved !== 0 || imageCount === 0)
return false;
const imageType = (0, utils_1.readUInt16LE)(input, 2);
return imageType === TYPE_ICON;
},
calculate(input) {
const nbImages = (0, utils_1.readUInt16LE)(input, 4);
const imageSize = getImageSize(input, 0);
if (nbImages === 1)
return imageSize;
const imgs = [imageSize];
for (let imageIndex = 1; imageIndex < nbImages; imageIndex += 1) {
imgs.push(getImageSize(input, imageIndex));
}
return {
height: imageSize.height,
images: imgs,
width: imageSize.width,
};
},
};

21
node_modules/image-size/dist/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,21 @@
export declare const typeHandlers: {
bmp: import("./interface").IImage;
cur: import("./interface").IImage;
dds: import("./interface").IImage;
gif: import("./interface").IImage;
heif: import("./interface").IImage;
icns: import("./interface").IImage;
ico: import("./interface").IImage;
j2c: import("./interface").IImage;
jp2: import("./interface").IImage;
jpg: import("./interface").IImage;
ktx: import("./interface").IImage;
png: import("./interface").IImage;
pnm: import("./interface").IImage;
psd: import("./interface").IImage;
svg: import("./interface").IImage;
tga: import("./interface").IImage;
tiff: import("./interface").IImage;
webp: import("./interface").IImage;
};
export type imageType = keyof typeof typeHandlers;

42
node_modules/image-size/dist/types/index.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.typeHandlers = void 0;
// load all available handlers explicitly for browserify support
const bmp_1 = require("./bmp");
const cur_1 = require("./cur");
const dds_1 = require("./dds");
const gif_1 = require("./gif");
const heif_1 = require("./heif");
const icns_1 = require("./icns");
const ico_1 = require("./ico");
const j2c_1 = require("./j2c");
const jp2_1 = require("./jp2");
const jpg_1 = require("./jpg");
const ktx_1 = require("./ktx");
const png_1 = require("./png");
const pnm_1 = require("./pnm");
const psd_1 = require("./psd");
const svg_1 = require("./svg");
const tga_1 = require("./tga");
const tiff_1 = require("./tiff");
const webp_1 = require("./webp");
exports.typeHandlers = {
bmp: bmp_1.BMP,
cur: cur_1.CUR,
dds: dds_1.DDS,
gif: gif_1.GIF,
heif: heif_1.HEIF,
icns: icns_1.ICNS,
ico: ico_1.ICO,
j2c: j2c_1.J2C,
jp2: jp2_1.JP2,
jpg: jpg_1.JPG,
ktx: ktx_1.KTX,
png: png_1.PNG,
pnm: pnm_1.PNM,
psd: psd_1.PSD,
svg: svg_1.SVG,
tga: tga_1.TGA,
tiff: tiff_1.TIFF,
webp: webp_1.WEBP,
};

13
node_modules/image-size/dist/types/interface.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
export type ISize = {
width: number | undefined;
height: number | undefined;
orientation?: number;
type?: string;
};
export type ISizeCalculationResult = {
images?: ISize[];
} & ISize;
export type IImage = {
validate: (input: Uint8Array) => boolean;
calculate: (input: Uint8Array, filepath?: string) => ISizeCalculationResult;
};

2
node_modules/image-size/dist/types/interface.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

2
node_modules/image-size/dist/types/j2c.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const J2C: IImage;

12
node_modules/image-size/dist/types/j2c.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.J2C = void 0;
const utils_1 = require("./utils");
exports.J2C = {
// TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC
validate: (input) => (0, utils_1.toHexString)(input, 0, 4) === 'ff4fff51',
calculate: (input) => ({
height: (0, utils_1.readUInt32BE)(input, 12),
width: (0, utils_1.readUInt32BE)(input, 8),
}),
};

2
node_modules/image-size/dist/types/jp2.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const JP2: IImage;

25
node_modules/image-size/dist/types/jp2.js generated vendored Normal file
View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JP2 = void 0;
const utils_1 = require("./utils");
exports.JP2 = {
validate(input) {
if ((0, utils_1.readUInt32BE)(input, 4) !== 0x6a502020 || (0, utils_1.readUInt32BE)(input, 0) < 1)
return false;
const ftypBox = (0, utils_1.findBox)(input, 'ftyp', 0);
if (!ftypBox)
return false;
return (0, utils_1.readUInt32BE)(input, ftypBox.offset + 4) === 0x66747970;
},
calculate(input) {
const jp2hBox = (0, utils_1.findBox)(input, 'jp2h', 0);
const ihdrBox = jp2hBox && (0, utils_1.findBox)(input, 'ihdr', jp2hBox.offset + 8);
if (ihdrBox) {
return {
height: (0, utils_1.readUInt32BE)(input, ihdrBox.offset + 8),
width: (0, utils_1.readUInt32BE)(input, ihdrBox.offset + 12),
};
}
throw new TypeError('Unsupported JPEG 2000 format');
},
};

2
node_modules/image-size/dist/types/jpg.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const JPG: IImage;

123
node_modules/image-size/dist/types/jpg.js generated vendored Normal file
View File

@@ -0,0 +1,123 @@
"use strict";
// NOTE: we only support baseline and progressive JPGs here
// due to the structure of the loader class, we only get a buffer
// with a maximum size of 4096 bytes. so if the SOF marker is outside
// if this range we can't detect the file size correctly.
Object.defineProperty(exports, "__esModule", { value: true });
exports.JPG = void 0;
const utils_1 = require("./utils");
const EXIF_MARKER = '45786966';
const APP1_DATA_SIZE_BYTES = 2;
const EXIF_HEADER_BYTES = 6;
const TIFF_BYTE_ALIGN_BYTES = 2;
const BIG_ENDIAN_BYTE_ALIGN = '4d4d';
const LITTLE_ENDIAN_BYTE_ALIGN = '4949';
// Each entry is exactly 12 bytes
const IDF_ENTRY_BYTES = 12;
const NUM_DIRECTORY_ENTRIES_BYTES = 2;
function isEXIF(input) {
return (0, utils_1.toHexString)(input, 2, 6) === EXIF_MARKER;
}
function extractSize(input, index) {
return {
height: (0, utils_1.readUInt16BE)(input, index),
width: (0, utils_1.readUInt16BE)(input, index + 2),
};
}
function extractOrientation(exifBlock, isBigEndian) {
// TODO: assert that this contains 0x002A
// let STATIC_MOTOROLA_TIFF_HEADER_BYTES = 2
// let TIFF_IMAGE_FILE_DIRECTORY_BYTES = 4
// TODO: derive from TIFF_IMAGE_FILE_DIRECTORY_BYTES
const idfOffset = 8;
// IDF osset works from right after the header bytes
// (so the offset includes the tiff byte align)
const offset = EXIF_HEADER_BYTES + idfOffset;
const idfDirectoryEntries = (0, utils_1.readUInt)(exifBlock, 16, offset, isBigEndian);
for (let directoryEntryNumber = 0; directoryEntryNumber < idfDirectoryEntries; directoryEntryNumber++) {
const start = offset +
NUM_DIRECTORY_ENTRIES_BYTES +
directoryEntryNumber * IDF_ENTRY_BYTES;
const end = start + IDF_ENTRY_BYTES;
// Skip on corrupt EXIF blocks
if (start > exifBlock.length) {
return;
}
const block = exifBlock.slice(start, end);
const tagNumber = (0, utils_1.readUInt)(block, 16, 0, isBigEndian);
// 0x0112 (decimal: 274) is the `orientation` tag ID
if (tagNumber === 274) {
const dataFormat = (0, utils_1.readUInt)(block, 16, 2, isBigEndian);
if (dataFormat !== 3) {
return;
}
// unsinged int has 2 bytes per component
// if there would more than 4 bytes in total it's a pointer
const numberOfComponents = (0, utils_1.readUInt)(block, 32, 4, isBigEndian);
if (numberOfComponents !== 1) {
return;
}
return (0, utils_1.readUInt)(block, 16, 8, isBigEndian);
}
}
}
function validateExifBlock(input, index) {
// Skip APP1 Data Size
const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index);
// Consider byte alignment
const byteAlign = (0, utils_1.toHexString)(exifBlock, EXIF_HEADER_BYTES, EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES);
// Ignore Empty EXIF. Validate byte alignment
const isBigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN;
const isLittleEndian = byteAlign === LITTLE_ENDIAN_BYTE_ALIGN;
if (isBigEndian || isLittleEndian) {
return extractOrientation(exifBlock, isBigEndian);
}
}
function validateInput(input, index) {
// index should be within buffer limits
if (index > input.length) {
throw new TypeError('Corrupt JPG, exceeded buffer limits');
}
}
exports.JPG = {
validate: (input) => (0, utils_1.toHexString)(input, 0, 2) === 'ffd8',
calculate(input) {
// Skip 4 chars, they are for signature
input = input.slice(4);
let orientation;
let next;
while (input.length) {
// read length of the next block
const i = (0, utils_1.readUInt16BE)(input, 0);
// Every JPEG block must begin with a 0xFF
if (input[i] !== 0xff) {
input = input.slice(1);
continue;
}
if (isEXIF(input)) {
orientation = validateExifBlock(input, i);
}
// ensure correct format
validateInput(input, i);
// 0xFFC0 is baseline standard(SOF)
// 0xFFC1 is baseline optimized(SOF)
// 0xFFC2 is progressive(SOF2)
next = input[i + 1];
if (next === 0xc0 || next === 0xc1 || next === 0xc2) {
const size = extractSize(input, i + 5);
// TODO: is orientation=0 a valid answer here?
if (!orientation) {
return size;
}
return {
height: size.height,
orientation,
width: size.width,
};
}
// move to the next block
input = input.slice(i + 2);
}
throw new TypeError('Invalid JPG, no size found');
},
};

2
node_modules/image-size/dist/types/ktx.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const KTX: IImage;

19
node_modules/image-size/dist/types/ktx.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KTX = void 0;
const utils_1 = require("./utils");
exports.KTX = {
validate: (input) => {
const signature = (0, utils_1.toUTF8String)(input, 1, 7);
return ['KTX 11', 'KTX 20'].includes(signature);
},
calculate: (input) => {
const type = input[5] === 0x31 ? 'ktx' : 'ktx2';
const offset = type === 'ktx' ? 36 : 20;
return ({
height: (0, utils_1.readUInt32LE)(input, offset + 4),
width: (0, utils_1.readUInt32LE)(input, offset),
type,
});
},
};

2
node_modules/image-size/dist/types/png.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const PNG: IImage;

35
node_modules/image-size/dist/types/png.js generated vendored Normal file
View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PNG = void 0;
const utils_1 = require("./utils");
const pngSignature = 'PNG\r\n\x1a\n';
const pngImageHeaderChunkName = 'IHDR';
// Used to detect "fried" png's: http://www.jongware.com/pngdefry.html
const pngFriedChunkName = 'CgBI';
exports.PNG = {
validate(input) {
if (pngSignature === (0, utils_1.toUTF8String)(input, 1, 8)) {
let chunkName = (0, utils_1.toUTF8String)(input, 12, 16);
if (chunkName === pngFriedChunkName) {
chunkName = (0, utils_1.toUTF8String)(input, 28, 32);
}
if (chunkName !== pngImageHeaderChunkName) {
throw new TypeError('Invalid PNG');
}
return true;
}
return false;
},
calculate(input) {
if ((0, utils_1.toUTF8String)(input, 12, 16) === pngFriedChunkName) {
return {
height: (0, utils_1.readUInt32BE)(input, 36),
width: (0, utils_1.readUInt32BE)(input, 32),
};
}
return {
height: (0, utils_1.readUInt32BE)(input, 20),
width: (0, utils_1.readUInt32BE)(input, 16),
};
},
};

2
node_modules/image-size/dist/types/pnm.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const PNM: IImage;

72
node_modules/image-size/dist/types/pnm.js generated vendored Normal file
View File

@@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PNM = void 0;
const utils_1 = require("./utils");
const PNMTypes = {
P1: 'pbm/ascii',
P2: 'pgm/ascii',
P3: 'ppm/ascii',
P4: 'pbm',
P5: 'pgm',
P6: 'ppm',
P7: 'pam',
PF: 'pfm',
};
const handlers = {
default: (lines) => {
let dimensions = [];
while (lines.length > 0) {
const line = lines.shift();
if (line[0] === '#') {
continue;
}
dimensions = line.split(' ');
break;
}
if (dimensions.length === 2) {
return {
height: parseInt(dimensions[1], 10),
width: parseInt(dimensions[0], 10),
};
}
else {
throw new TypeError('Invalid PNM');
}
},
pam: (lines) => {
const size = {};
while (lines.length > 0) {
const line = lines.shift();
if (line.length > 16 || line.charCodeAt(0) > 128) {
continue;
}
const [key, value] = line.split(' ');
if (key && value) {
size[key.toLowerCase()] = parseInt(value, 10);
}
if (size.height && size.width) {
break;
}
}
if (size.height && size.width) {
return {
height: size.height,
width: size.width,
};
}
else {
throw new TypeError('Invalid PAM');
}
},
};
exports.PNM = {
validate: (input) => (0, utils_1.toUTF8String)(input, 0, 2) in PNMTypes,
calculate(input) {
const signature = (0, utils_1.toUTF8String)(input, 0, 2);
const type = PNMTypes[signature];
// TODO: this probably generates garbage. move to a stream based parser
const lines = (0, utils_1.toUTF8String)(input, 3).split(/[\r\n]+/);
const handler = handlers[type] || handlers.default;
return handler(lines);
},
};

2
node_modules/image-size/dist/types/psd.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const PSD: IImage;

11
node_modules/image-size/dist/types/psd.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PSD = void 0;
const utils_1 = require("./utils");
exports.PSD = {
validate: (input) => (0, utils_1.toUTF8String)(input, 0, 4) === '8BPS',
calculate: (input) => ({
height: (0, utils_1.readUInt32BE)(input, 14),
width: (0, utils_1.readUInt32BE)(input, 18),
}),
};

2
node_modules/image-size/dist/types/svg.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const SVG: IImage;

90
node_modules/image-size/dist/types/svg.js generated vendored Normal file
View File

@@ -0,0 +1,90 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SVG = void 0;
const utils_1 = require("./utils");
const svgReg = /<svg\s([^>"']|"[^"]*"|'[^']*')*>/;
const extractorRegExps = {
height: /\sheight=(['"])([^%]+?)\1/,
root: svgReg,
viewbox: /\sviewBox=(['"])(.+?)\1/i,
width: /\swidth=(['"])([^%]+?)\1/,
};
const INCH_CM = 2.54;
const units = {
in: 96,
cm: 96 / INCH_CM,
em: 16,
ex: 8,
m: (96 / INCH_CM) * 100,
mm: 96 / INCH_CM / 10,
pc: 96 / 72 / 12,
pt: 96 / 72,
px: 1,
};
const unitsReg = new RegExp(`^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join('|')})?$`);
function parseLength(len) {
const m = unitsReg.exec(len);
if (!m) {
return undefined;
}
return Math.round(Number(m[1]) * (units[m[2]] || 1));
}
function parseViewbox(viewbox) {
const bounds = viewbox.split(' ');
return {
height: parseLength(bounds[3]),
width: parseLength(bounds[2]),
};
}
function parseAttributes(root) {
const width = root.match(extractorRegExps.width);
const height = root.match(extractorRegExps.height);
const viewbox = root.match(extractorRegExps.viewbox);
return {
height: height && parseLength(height[2]),
viewbox: viewbox && parseViewbox(viewbox[2]),
width: width && parseLength(width[2]),
};
}
function calculateByDimensions(attrs) {
return {
height: attrs.height,
width: attrs.width,
};
}
function calculateByViewbox(attrs, viewbox) {
const ratio = viewbox.width / viewbox.height;
if (attrs.width) {
return {
height: Math.floor(attrs.width / ratio),
width: attrs.width,
};
}
if (attrs.height) {
return {
height: attrs.height,
width: Math.floor(attrs.height * ratio),
};
}
return {
height: viewbox.height,
width: viewbox.width,
};
}
exports.SVG = {
// Scan only the first kilo-byte to speed up the check on larger files
validate: (input) => svgReg.test((0, utils_1.toUTF8String)(input, 0, 1000)),
calculate(input) {
const root = (0, utils_1.toUTF8String)(input).match(extractorRegExps.root);
if (root) {
const attrs = parseAttributes(root[0]);
if (attrs.width && attrs.height) {
return calculateByDimensions(attrs);
}
if (attrs.viewbox) {
return calculateByViewbox(attrs, attrs.viewbox);
}
}
throw new TypeError('Invalid SVG');
},
};

2
node_modules/image-size/dist/types/tga.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const TGA: IImage;

15
node_modules/image-size/dist/types/tga.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TGA = void 0;
const utils_1 = require("./utils");
exports.TGA = {
validate(input) {
return (0, utils_1.readUInt16LE)(input, 0) === 0 && (0, utils_1.readUInt16LE)(input, 4) === 0;
},
calculate(input) {
return {
height: (0, utils_1.readUInt16LE)(input, 14),
width: (0, utils_1.readUInt16LE)(input, 12),
};
},
};

2
node_modules/image-size/dist/types/tiff.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const TIFF: IImage;

95
node_modules/image-size/dist/types/tiff.js generated vendored Normal file
View File

@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TIFF = void 0;
// based on http://www.compix.com/fileformattif.htm
// TO-DO: support big-endian as well
const fs = require("fs");
const utils_1 = require("./utils");
// Read IFD (image-file-directory) into a buffer
function readIFD(input, filepath, isBigEndian) {
const ifdOffset = (0, utils_1.readUInt)(input, 32, 4, isBigEndian);
// read only till the end of the file
let bufferSize = 1024;
const fileSize = fs.statSync(filepath).size;
if (ifdOffset + bufferSize > fileSize) {
bufferSize = fileSize - ifdOffset - 10;
}
// populate the buffer
const endBuffer = new Uint8Array(bufferSize);
const descriptor = fs.openSync(filepath, 'r');
fs.readSync(descriptor, endBuffer, 0, bufferSize, ifdOffset);
fs.closeSync(descriptor);
return endBuffer.slice(2);
}
// TIFF values seem to be messed up on Big-Endian, this helps
function readValue(input, isBigEndian) {
const low = (0, utils_1.readUInt)(input, 16, 8, isBigEndian);
const high = (0, utils_1.readUInt)(input, 16, 10, isBigEndian);
return (high << 16) + low;
}
// move to the next tag
function nextTag(input) {
if (input.length > 24) {
return input.slice(12);
}
}
// Extract IFD tags from TIFF metadata
function extractTags(input, isBigEndian) {
const tags = {};
let temp = input;
while (temp && temp.length) {
const code = (0, utils_1.readUInt)(temp, 16, 0, isBigEndian);
const type = (0, utils_1.readUInt)(temp, 16, 2, isBigEndian);
const length = (0, utils_1.readUInt)(temp, 32, 4, isBigEndian);
// 0 means end of IFD
if (code === 0) {
break;
}
else {
// 256 is width, 257 is height
// if (code === 256 || code === 257) {
if (length === 1 && (type === 3 || type === 4)) {
tags[code] = readValue(temp, isBigEndian);
}
// move to the next tag
temp = nextTag(temp);
}
}
return tags;
}
// Test if the TIFF is Big Endian or Little Endian
function determineEndianness(input) {
const signature = (0, utils_1.toUTF8String)(input, 0, 2);
if ('II' === signature) {
return 'LE';
}
else if ('MM' === signature) {
return 'BE';
}
}
const signatures = [
// '492049', // currently not supported
'49492a00', // Little endian
'4d4d002a', // Big Endian
// '4d4d002a', // BigTIFF > 4GB. currently not supported
];
exports.TIFF = {
validate: (input) => signatures.includes((0, utils_1.toHexString)(input, 0, 4)),
calculate(input, filepath) {
if (!filepath) {
throw new TypeError('Tiff doesn\'t support buffer');
}
// Determine BE/LE
const isBigEndian = determineEndianness(input) === 'BE';
// read the IFD
const ifdBuffer = readIFD(input, filepath, isBigEndian);
// extract the tags from the IFD
const tags = extractTags(ifdBuffer, isBigEndian);
const width = tags[256];
const height = tags[257];
if (!width || !height) {
throw new TypeError('Invalid Tiff. Missing tags');
}
return { height, width };
},
};

15
node_modules/image-size/dist/types/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
export declare const toUTF8String: (input: Uint8Array, start?: number, end?: number) => string;
export declare const toHexString: (input: Uint8Array, start?: number, end?: number) => string;
export declare const readInt16LE: (input: Uint8Array, offset?: number) => number;
export declare const readUInt16BE: (input: Uint8Array, offset?: number) => number;
export declare const readUInt16LE: (input: Uint8Array, offset?: number) => number;
export declare const readUInt24LE: (input: Uint8Array, offset?: number) => number;
export declare const readInt32LE: (input: Uint8Array, offset?: number) => number;
export declare const readUInt32BE: (input: Uint8Array, offset?: number) => number;
export declare const readUInt32LE: (input: Uint8Array, offset?: number) => number;
export declare function readUInt(input: Uint8Array, bits: 16 | 32, offset: number, isBigEndian: boolean): number;
export declare function findBox(buffer: Uint8Array, boxName: string, offset: number): {
name: string;
offset: number;
size: number;
} | undefined;

73
node_modules/image-size/dist/types/utils.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findBox = exports.readUInt = exports.readUInt32LE = exports.readUInt32BE = exports.readInt32LE = exports.readUInt24LE = exports.readUInt16LE = exports.readUInt16BE = exports.readInt16LE = exports.toHexString = exports.toUTF8String = void 0;
const decoder = new TextDecoder();
const toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end));
exports.toUTF8String = toUTF8String;
const toHexString = (input, start = 0, end = input.length) => input
.slice(start, end)
.reduce((memo, i) => memo + ('0' + i.toString(16)).slice(-2), '');
exports.toHexString = toHexString;
const readInt16LE = (input, offset = 0) => {
const val = input[offset] + input[offset + 1] * 2 ** 8;
return val | ((val & (2 ** 15)) * 0x1fffe);
};
exports.readInt16LE = readInt16LE;
const readUInt16BE = (input, offset = 0) => input[offset] * 2 ** 8 + input[offset + 1];
exports.readUInt16BE = readUInt16BE;
const readUInt16LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8;
exports.readUInt16LE = readUInt16LE;
const readUInt24LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8 + input[offset + 2] * 2 ** 16;
exports.readUInt24LE = readUInt24LE;
const readInt32LE = (input, offset = 0) => input[offset] +
input[offset + 1] * 2 ** 8 +
input[offset + 2] * 2 ** 16 +
(input[offset + 3] << 24);
exports.readInt32LE = readInt32LE;
const readUInt32BE = (input, offset = 0) => input[offset] * 2 ** 24 +
input[offset + 1] * 2 ** 16 +
input[offset + 2] * 2 ** 8 +
input[offset + 3];
exports.readUInt32BE = readUInt32BE;
const readUInt32LE = (input, offset = 0) => input[offset] +
input[offset + 1] * 2 ** 8 +
input[offset + 2] * 2 ** 16 +
input[offset + 3] * 2 ** 24;
exports.readUInt32LE = readUInt32LE;
// Abstract reading multi-byte unsigned integers
const methods = {
readUInt16BE: exports.readUInt16BE,
readUInt16LE: exports.readUInt16LE,
readUInt32BE: exports.readUInt32BE,
readUInt32LE: exports.readUInt32LE,
};
function readUInt(input, bits, offset, isBigEndian) {
offset = offset || 0;
const endian = isBigEndian ? 'BE' : 'LE';
const methodName = ('readUInt' + bits + endian);
return methods[methodName](input, offset);
}
exports.readUInt = readUInt;
function readBox(buffer, offset) {
if (buffer.length - offset < 4)
return;
const boxSize = (0, exports.readUInt32BE)(buffer, offset);
if (buffer.length - offset < boxSize)
return;
return {
name: (0, exports.toUTF8String)(buffer, 4 + offset, 8 + offset),
offset,
size: boxSize,
};
}
function findBox(buffer, boxName, offset) {
while (offset < buffer.length) {
const box = readBox(buffer, offset);
if (!box)
break;
if (box.name === boxName)
return box;
offset += box.size;
}
}
exports.findBox = findBox;

2
node_modules/image-size/dist/types/webp.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import type { IImage } from './interface';
export declare const WEBP: IImage;

60
node_modules/image-size/dist/types/webp.js generated vendored Normal file
View File

@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WEBP = void 0;
const utils_1 = require("./utils");
function calculateExtended(input) {
return {
height: 1 + (0, utils_1.readUInt24LE)(input, 7),
width: 1 + (0, utils_1.readUInt24LE)(input, 4),
};
}
function calculateLossless(input) {
return {
height: 1 +
(((input[4] & 0xf) << 10) | (input[3] << 2) | ((input[2] & 0xc0) >> 6)),
width: 1 + (((input[2] & 0x3f) << 8) | input[1]),
};
}
function calculateLossy(input) {
// `& 0x3fff` returns the last 14 bits
// TO-DO: include webp scaling in the calculations
return {
height: (0, utils_1.readInt16LE)(input, 8) & 0x3fff,
width: (0, utils_1.readInt16LE)(input, 6) & 0x3fff,
};
}
exports.WEBP = {
validate(input) {
const riffHeader = 'RIFF' === (0, utils_1.toUTF8String)(input, 0, 4);
const webpHeader = 'WEBP' === (0, utils_1.toUTF8String)(input, 8, 12);
const vp8Header = 'VP8' === (0, utils_1.toUTF8String)(input, 12, 15);
return riffHeader && webpHeader && vp8Header;
},
calculate(input) {
const chunkHeader = (0, utils_1.toUTF8String)(input, 12, 16);
input = input.slice(20, 30);
// Extended webp stream signature
if (chunkHeader === 'VP8X') {
const extendedHeader = input[0];
const validStart = (extendedHeader & 0xc0) === 0;
const validEnd = (extendedHeader & 0x01) === 0;
if (validStart && validEnd) {
return calculateExtended(input);
}
else {
// TODO: breaking change
throw new TypeError('Invalid WebP');
}
}
// Lossless webp stream signature
if (chunkHeader === 'VP8 ' && input[0] !== 0x2f) {
return calculateLossy(input);
}
// Lossy webp stream signature
const signature = (0, utils_1.toHexString)(input, 3, 6);
if (chunkHeader === 'VP8L' && signature !== '9d012a') {
return calculateLossless(input);
}
throw new TypeError('Invalid WebP');
},
};