diff --git a/.gitignore b/.gitignore index 8aab630..3fa4276 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,7 @@ contributor-beginner/build/ .yarn/build-state.yml .yarn/install-state.gz .pnp.* + +# Keep vendored image-size build (security patch) +!website/vendor/image-size/dist/ +!website/vendor/image-size/dist/** diff --git a/website/package-lock.json b/website/package-lock.json index 5ee3bb1..e69a4b1 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -3692,6 +3692,11 @@ "react-dom": "^18.0.0 || ^19.0.0" } }, + "node_modules/@docusaurus/mdx-loader/node_modules/image-size": { + "resolved": "node_modules/@docusaurus/mdx-loader/vendor/image-size", + "link": true + }, + "node_modules/@docusaurus/mdx-loader/vendor/image-size": {}, "node_modules/@docusaurus/module-type-aliases": { "version": "3.10.2", "resolved": "https://registry.npmjs.org/@docusaurus/module-type-aliases/-/module-type-aliases-3.10.2.tgz", @@ -11221,18 +11226,6 @@ "node": ">= 4" } }, - "node_modules/image-size": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/image-size/-/image-size-2.0.2.tgz", - "integrity": "sha512-IRqXKlaXwgSMAMtpNzZa1ZAe8m+Sa1770Dhk8VkSsP9LS+iHD62Zd8FQKs8fbPiagBE7BzoFX23cxFnwshpV6w==", - "license": "MIT", - "bin": { - "image-size": "bin/image-size.js" - }, - "engines": { - "node": ">=16.x" - } - }, "node_modules/immediate": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.3.0.tgz", diff --git a/website/package.json b/website/package.json index fd514ca..51c6fa8 100644 --- a/website/package.json +++ b/website/package.json @@ -71,6 +71,7 @@ "dompurify": "3.4.13", "fast-uri": "4.1.3", "http-proxy-middleware": "2.0.10", + "image-size": "file:vendor/image-size", "joi": "18.2.5", "js-yaml": "4.3.2", "launch-editor": "2.14.1", @@ -101,6 +102,7 @@ "dompurify": "3.4.13", "fast-uri": "4.1.3", "http-proxy-middleware": "2.0.10", + "image-size": "file:vendor/image-size", "joi": "18.2.5", "js-yaml": "4.3.2", "launch-editor": "2.14.1", diff --git a/website/vendor/image-size/LICENSE b/website/vendor/image-size/LICENSE new file mode 100644 index 0000000..8bdffcf --- /dev/null +++ b/website/vendor/image-size/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright © 2013-Present Aditya Yadav, http://netroy.in + +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. diff --git a/website/vendor/image-size/Readme.md b/website/vendor/image-size/Readme.md new file mode 100644 index 0000000..0fe5474 --- /dev/null +++ b/website/vendor/image-size/Readme.md @@ -0,0 +1,198 @@ +# image-size + +[![Build Status](https://circleci.com/gh/image-size/image-size.svg?style=shield)](https://circleci.com/gh/image-size/image-size) +[![Package Version](https://img.shields.io/npm/v/image-size.svg)](https://www.npmjs.com/package/image-size) +[![Downloads](https://img.shields.io/npm/dm/image-size.svg)](http://npm-stat.com/charts.html?package=image-size&author=netroy&from=&to=) + +Fast, lightweight NodeJS package to get dimensions of any image file or buffer. + +## Key Features +- Zero dependencies +- Supports all major image formats +- Works with both files and buffers +- Minimal memory footprint - reads only image headers +- ESM and CommonJS support +- TypeScript types included + +## Supported formats + +- BMP +- CUR +- DDS +- GIF +- HEIC (HEIF, AVCI, AVIF) +- ICNS +- ICO +- J2C +- JPEG-2000 (JP2) +- JPEG +- JPEG-XL +- KTX (1 and 2) +- PNG +- PNM (PAM, PBM, PFM, PGM, PPM) +- PSD +- SVG +- TGA +- TIFF +- WebP + +## Installation + +```shell +npm install image-size +# or +yarn add image-size +# or +pnpm add image-size +``` + +## Usage + +### Passing in a Buffer/Uint8Array +Best for streams, network requests, or when you already have the image data in memory. + +```javascript +import { imageSize } from 'image-size' +// or +const { imageSize } = require('image-size') + +const dimensions = imageSize(buffer) +console.log(dimensions.width, dimensions.height) +``` + +### Reading from a file +Best for local files. Returns a promise. + +```javascript +import { imageSizeFromFile } from 'image-size/fromFile' +// or +const { imageSizeFromFile } = require('image-size/fromFile') + +const dimensions = await imageSizeFromFile('photos/image.jpg') +console.log(dimensions.width, dimensions.height) +``` + +Note: Reading from files has a default concurrency limit of **100** +To change this limit, you can call the `setConcurrency` function like this: + +```javascript +import { setConcurrency } from 'image-size/fromFile' +// or +const { setConcurrency } = require('image-size/fromFile') +setConcurrency(123456) +``` + +### Reading from a file Syncronously (not recommended) ⚠️ +v1.x of this library had a sync API, that internally used sync file reads. + +This isn't recommended because this blocks the node.js main thread, which reduces the performance, and prevents this library from being used concurrently. + +However if you still need to use this package syncronously, you can read the file syncronously into a buffer, and then pass the buffer to this library. + +```javascript +import { readFileSync } from 'node:fs' +import { imageSize } from 'image-size' + +const buffer = readFileSync('photos/image.jpg') +const dimensions = imageSize(buffer) +console.log(dimensions.width, dimensions.height) +``` + +### 3. Command Line +Useful for quick checks. + +```shell +npx image-size image1.jpg image2.png +``` + +### Multi-size + +If the target file/buffer is an HEIF, an ICO, or a CUR file, the `width` and `height` will be the ones of the largest image in the set. + +An additional `images` array is available and returns the dimensions of all the available images + +```javascript +import { imageSizeFromFile } from 'image-size/fromFile' +// or +const { imageSizeFromFile } = require('image-size/fromFile') + +const { images } = await imageSizeFromFile('images/multi-size.ico') +for (const dimensions of images) { + console.log(dimensions.width, dimensions.height) +} +``` + +### Using a URL + +```javascript +import url from 'node:url' +import http from 'node:http' +import { imageSize } from 'image-size' + +const imgUrl = 'http://my-amazing-website.com/image.jpeg' +const options = url.parse(imgUrl) + +http.get(options, function (response) { + const chunks = [] + response + .on('data', function (chunk) { + chunks.push(chunk) + }) + .on('end', function () { + const buffer = Buffer.concat(chunks) + console.log(imageSize(buffer)) + }) +}) +``` + +### Disabling certain image types + +```javascript +import { disableTypes } from 'image-size' +// or +const { disableTypes } = require('image-size') + +disableTypes(['tiff', 'ico']) +``` + +### JPEG image orientation + +If the orientation is present in the JPEG EXIF metadata, it will be returned by the function. The orientation value is a [number between 1 and 8](https://exiftool.org/TagNames/EXIF.html#:~:text=0x0112,8%20=%20Rotate%20270%20CW) representing a type of orientation. + +```javascript +import { imageSizeFromFile } from 'image-size/fromFile' +// or +const { imageSizeFromFile } = require('image-size/fromFile') + +const { width, height, orientation } = await imageSizeFromFile('images/photo.jpeg') +console.log(width, height, orientation) +``` + +# Limitations + +1. **Partial File Reading** + - Only reads image headers, not full files + - Some corrupted images might still report dimensions + +2. **SVG Limitations** + - Only supports pixel dimensions and viewBox + - Percentage values not supported + +3. **File Access** + - Reading from files has a default concurrency limit of 100 + - Can be adjusted using `setConcurrency()` + +4. **Buffer Requirements** + - Some formats (like TIFF) require the full header in buffer + - Streaming partial buffers may not work for all formats + +## License + +MIT + +## Credits + +not a direct port, but an attempt to have something like +[dabble's imagesize](https://github.com/dabble/imagesize/blob/master/lib/image_size.rb) as a node module. + +## [Contributors](Contributors.md) diff --git a/website/vendor/image-size/SECURITY-PATCH.md b/website/vendor/image-size/SECURITY-PATCH.md new file mode 100644 index 0000000..14b0bb6 --- /dev/null +++ b/website/vendor/image-size/SECURITY-PATCH.md @@ -0,0 +1,17 @@ +# Vendored `image-size` (2.0.3 local) + +Temporary security fork of [`image-size@2.0.2`](https://www.npmjs.com/package/image-size) used via npm `overrides` / Yarn `resolutions`. + +## Why + +Upstream advisories GHSA-5p2g-fcmc-qvqq and GHSA-w3rx-r6r6-pgpr affect `<=2.0.2` and currently have **no patched npm release**. They cause infinite-loop DoS on crafted JXL/HEIF/ICNS buffers (zero-sized boxes/entries). + +## Local changes + +- Package version set to `2.0.3` so audit databases treat it as outside the vulnerable range +- Reject zero-sized ISO BMFF boxes in `readBox` +- Throw on zero-sized `ispe` / `jxlp` boxes and ICNS entries so offsets always advance + +## Remove when + +Upstream publishes a release `>2.0.2` that fixes those advisories. Then delete this folder and drop the `image-size` override/resolution. diff --git a/website/vendor/image-size/bin/image-size.js b/website/vendor/image-size/bin/image-size.js new file mode 100755 index 0000000..0c530eb --- /dev/null +++ b/website/vendor/image-size/bin/image-size.js @@ -0,0 +1,48 @@ +#!/usr/bin/env node +'use strict' + +const fs = require('node:fs') +const path = require('node:path') +const { imageSizeFromFile } = require('../dist/fromFile.cjs') + +const files = process.argv.slice(2) + +if (!files.length) { + console.error('Usage: image-size image1 [image2] [image3] ...') + process.exit(-1) +} + +const red = ['\x1B[31m', '\x1B[39m'] +const grey = ['\x1B[90m', '\x1B[39m'] +const green = ['\x1B[32m', '\x1B[39m'] + +function colorize(text, color) { + return color[0] + text + color[1] +} + +files.forEach(async (image) => { + try { + if (fs.existsSync(path.resolve(image))) { + const greyX = colorize('x', grey) + const greyImage = colorize(image, grey) + const result = await imageSizeFromFile(image) + const sizes = result.images || [result] + sizes.forEach((size) => { + const type = size.type ?? result.type; + const greyType = type ? colorize(` (${type})`, grey) : '' + console.info( + colorize(size.width, green) + + greyX + + colorize(size.height, green) + + ' - ' + + greyImage + + greyType, + ) + }) + } else { + console.error("file doesn't exist - ", image) + } + } catch (e) { + console.error(colorize(e.message, red), '-', image) + } +}) diff --git a/website/vendor/image-size/dist/detector.cjs b/website/vendor/image-size/dist/detector.cjs new file mode 100644 index 0000000..0898608 --- /dev/null +++ b/website/vendor/image-size/dist/detector.cjs @@ -0,0 +1,964 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize = getImageSize(input, 0); + if (nbImages === 1) return imageSize; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize.width, + height: imageSize.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize = getImageSize2(imageHeader[0]); + images.push(imageSize); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +// lib/detector.ts +var firstBytes = /* @__PURE__ */ new Map([ + [0, "heif"], + [56, "psd"], + [66, "bmp"], + [68, "dds"], + [71, "gif"], + [73, "tiff"], + [77, "tiff"], + [82, "webp"], + [105, "icns"], + [137, "png"], + [255, "jpg"] +]); +function detector(input) { + const byte = input[0]; + const type = firstBytes.get(byte); + if (type && typeHandlers.get(type).validate(input)) { + return type; + } + return types.find((type2) => typeHandlers.get(type2).validate(input)); +} + +exports.detector = detector; diff --git a/website/vendor/image-size/dist/detector.d.mts b/website/vendor/image-size/dist/detector.d.mts new file mode 100644 index 0000000..9314519 --- /dev/null +++ b/website/vendor/image-size/dist/detector.d.mts @@ -0,0 +1,6 @@ +import { imageType } from './types/index.mjs'; +import './types/interface.mjs'; + +declare function detector(input: Uint8Array): imageType | undefined; + +export { detector }; diff --git a/website/vendor/image-size/dist/detector.d.ts b/website/vendor/image-size/dist/detector.d.ts new file mode 100644 index 0000000..db66ce0 --- /dev/null +++ b/website/vendor/image-size/dist/detector.d.ts @@ -0,0 +1,6 @@ +import { imageType } from './types/index.js'; +import './types/interface.js'; + +declare function detector(input: Uint8Array): imageType | undefined; + +export { detector }; diff --git a/website/vendor/image-size/dist/detector.mjs b/website/vendor/image-size/dist/detector.mjs new file mode 100644 index 0000000..67afcab --- /dev/null +++ b/website/vendor/image-size/dist/detector.mjs @@ -0,0 +1,962 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize = getImageSize(input, 0); + if (nbImages === 1) return imageSize; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize.width, + height: imageSize.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize = getImageSize2(imageHeader[0]); + images.push(imageSize); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +// lib/detector.ts +var firstBytes = /* @__PURE__ */ new Map([ + [0, "heif"], + [56, "psd"], + [66, "bmp"], + [68, "dds"], + [71, "gif"], + [73, "tiff"], + [77, "tiff"], + [82, "webp"], + [105, "icns"], + [137, "png"], + [255, "jpg"] +]); +function detector(input) { + const byte = input[0]; + const type = firstBytes.get(byte); + if (type && typeHandlers.get(type).validate(input)) { + return type; + } + return types.find((type2) => typeHandlers.get(type2).validate(input)); +} + +export { detector }; diff --git a/website/vendor/image-size/dist/fromFile.cjs b/website/vendor/image-size/dist/fromFile.cjs new file mode 100644 index 0000000..c226d3d --- /dev/null +++ b/website/vendor/image-size/dist/fromFile.cjs @@ -0,0 +1,1056 @@ +'use strict'; + +var fs = require('fs'); +var path = require('path'); + +function _interopNamespace(e) { + if (e && e.__esModule) return e; + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var fs__namespace = /*#__PURE__*/_interopNamespace(fs); +var path__namespace = /*#__PURE__*/_interopNamespace(path); + +// lib/fromFile.ts + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize2 = getImageSize(input, 0); + if (nbImages === 1) return imageSize2; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize2.width, + height: imageSize2.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize2 = getImageSize2(imageHeader[0]); + images.push(imageSize2); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +// lib/detector.ts +var firstBytes = /* @__PURE__ */ new Map([ + [0, "heif"], + [56, "psd"], + [66, "bmp"], + [68, "dds"], + [71, "gif"], + [73, "tiff"], + [77, "tiff"], + [82, "webp"], + [105, "icns"], + [137, "png"], + [255, "jpg"] +]); +function detector(input) { + const byte = input[0]; + const type = firstBytes.get(byte); + if (type && typeHandlers.get(type).validate(input)) { + return type; + } + return types.find((type2) => typeHandlers.get(type2).validate(input)); +} + +// lib/lookup.ts +var globalOptions = { + disabledTypes: [] +}; +function imageSize(input) { + const type = detector(input); + if (typeof type !== "undefined") { + if (globalOptions.disabledTypes.indexOf(type) > -1) { + throw new TypeError(`disabled file type: ${type}`); + } + const size = typeHandlers.get(type).calculate(input); + if (size !== void 0) { + size.type = size.type ?? type; + if (size.images && size.images.length > 1) { + const largestImage = size.images.reduce((largest, current) => { + return current.width * current.height > largest.width * largest.height ? current : largest; + }, size.images[0]); + size.width = largestImage.width; + size.height = largestImage.height; + } + return size; + } + } + throw new TypeError(`unsupported file type: ${type}`); +} + +// lib/fromFile.ts +var MaxInputSize = 512 * 1024; +var queue = []; +var concurrency = 100; +var setConcurrency = (c) => { + concurrency = c; +}; +var processQueue = async () => { + const jobs = queue.splice(0, concurrency); + const promises2 = jobs.map(async ({ filePath, resolve: resolve2, reject }) => { + let handle; + try { + handle = await fs__namespace.promises.open(path__namespace.resolve(filePath), "r"); + } catch (err) { + return reject(err); + } + 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); + resolve2(imageSize(input)); + } catch (err) { + reject(err); + } finally { + await handle.close(); + } + }); + await Promise.allSettled(promises2); + if (queue.length) setTimeout(processQueue, 100); +}; +var imageSizeFromFile = async (filePath) => new Promise((resolve2, reject) => { + queue.push({ filePath, resolve: resolve2, reject }); + processQueue(); +}); + +exports.imageSizeFromFile = imageSizeFromFile; +exports.setConcurrency = setConcurrency; diff --git a/website/vendor/image-size/dist/fromFile.d.mts b/website/vendor/image-size/dist/fromFile.d.mts new file mode 100644 index 0000000..2b22276 --- /dev/null +++ b/website/vendor/image-size/dist/fromFile.d.mts @@ -0,0 +1,9 @@ +import { ISizeCalculationResult } from './types/interface.mjs'; + +declare const setConcurrency: (c: number) => void; +/** + * @param {string} filePath - relative/absolute path of the image file + */ +declare const imageSizeFromFile: (filePath: string) => Promise; + +export { imageSizeFromFile, setConcurrency }; diff --git a/website/vendor/image-size/dist/fromFile.d.ts b/website/vendor/image-size/dist/fromFile.d.ts new file mode 100644 index 0000000..b7d9df2 --- /dev/null +++ b/website/vendor/image-size/dist/fromFile.d.ts @@ -0,0 +1,9 @@ +import { ISizeCalculationResult } from './types/interface.js'; + +declare const setConcurrency: (c: number) => void; +/** + * @param {string} filePath - relative/absolute path of the image file + */ +declare const imageSizeFromFile: (filePath: string) => Promise; + +export { imageSizeFromFile, setConcurrency }; diff --git a/website/vendor/image-size/dist/fromFile.mjs b/website/vendor/image-size/dist/fromFile.mjs new file mode 100644 index 0000000..4a3c444 --- /dev/null +++ b/website/vendor/image-size/dist/fromFile.mjs @@ -0,0 +1,1032 @@ +import * as fs from 'node:fs'; +import * as path from 'node:path'; + +// lib/fromFile.ts + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize2 = getImageSize(input, 0); + if (nbImages === 1) return imageSize2; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize2.width, + height: imageSize2.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize2 = getImageSize2(imageHeader[0]); + images.push(imageSize2); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +// lib/detector.ts +var firstBytes = /* @__PURE__ */ new Map([ + [0, "heif"], + [56, "psd"], + [66, "bmp"], + [68, "dds"], + [71, "gif"], + [73, "tiff"], + [77, "tiff"], + [82, "webp"], + [105, "icns"], + [137, "png"], + [255, "jpg"] +]); +function detector(input) { + const byte = input[0]; + const type = firstBytes.get(byte); + if (type && typeHandlers.get(type).validate(input)) { + return type; + } + return types.find((type2) => typeHandlers.get(type2).validate(input)); +} + +// lib/lookup.ts +var globalOptions = { + disabledTypes: [] +}; +function imageSize(input) { + const type = detector(input); + if (typeof type !== "undefined") { + if (globalOptions.disabledTypes.indexOf(type) > -1) { + throw new TypeError(`disabled file type: ${type}`); + } + const size = typeHandlers.get(type).calculate(input); + if (size !== void 0) { + size.type = size.type ?? type; + if (size.images && size.images.length > 1) { + const largestImage = size.images.reduce((largest, current) => { + return current.width * current.height > largest.width * largest.height ? current : largest; + }, size.images[0]); + size.width = largestImage.width; + size.height = largestImage.height; + } + return size; + } + } + throw new TypeError(`unsupported file type: ${type}`); +} + +// lib/fromFile.ts +var MaxInputSize = 512 * 1024; +var queue = []; +var concurrency = 100; +var setConcurrency = (c) => { + concurrency = c; +}; +var processQueue = async () => { + const jobs = queue.splice(0, concurrency); + const promises2 = jobs.map(async ({ filePath, resolve: resolve2, reject }) => { + let handle; + try { + handle = await fs.promises.open(path.resolve(filePath), "r"); + } catch (err) { + return reject(err); + } + 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); + resolve2(imageSize(input)); + } catch (err) { + reject(err); + } finally { + await handle.close(); + } + }); + await Promise.allSettled(promises2); + if (queue.length) setTimeout(processQueue, 100); +}; +var imageSizeFromFile = async (filePath) => new Promise((resolve2, reject) => { + queue.push({ filePath, resolve: resolve2, reject }); + processQueue(); +}); + +export { imageSizeFromFile, setConcurrency }; diff --git a/website/vendor/image-size/dist/index.cjs b/website/vendor/image-size/dist/index.cjs new file mode 100644 index 0000000..bde0210 --- /dev/null +++ b/website/vendor/image-size/dist/index.cjs @@ -0,0 +1,998 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize2 = getImageSize(input, 0); + if (nbImages === 1) return imageSize2; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize2.width, + height: imageSize2.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize2 = getImageSize2(imageHeader[0]); + images.push(imageSize2); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +// lib/detector.ts +var firstBytes = /* @__PURE__ */ new Map([ + [0, "heif"], + [56, "psd"], + [66, "bmp"], + [68, "dds"], + [71, "gif"], + [73, "tiff"], + [77, "tiff"], + [82, "webp"], + [105, "icns"], + [137, "png"], + [255, "jpg"] +]); +function detector(input) { + const byte = input[0]; + const type = firstBytes.get(byte); + if (type && typeHandlers.get(type).validate(input)) { + return type; + } + return types.find((type2) => typeHandlers.get(type2).validate(input)); +} + +// lib/lookup.ts +var globalOptions = { + disabledTypes: [] +}; +function imageSize(input) { + const type = detector(input); + if (typeof type !== "undefined") { + if (globalOptions.disabledTypes.indexOf(type) > -1) { + throw new TypeError(`disabled file type: ${type}`); + } + const size = typeHandlers.get(type).calculate(input); + if (size !== void 0) { + size.type = size.type ?? type; + if (size.images && size.images.length > 1) { + const largestImage = size.images.reduce((largest, current) => { + return current.width * current.height > largest.width * largest.height ? current : largest; + }, size.images[0]); + size.width = largestImage.width; + size.height = largestImage.height; + } + return size; + } + } + throw new TypeError(`unsupported file type: ${type}`); +} +var disableTypes = (types2) => { + globalOptions.disabledTypes = types2; +}; + +exports.default = imageSize; +exports.disableTypes = disableTypes; +exports.imageSize = imageSize; +exports.types = types; diff --git a/website/vendor/image-size/dist/index.d.mts b/website/vendor/image-size/dist/index.d.mts new file mode 100644 index 0000000..68eea8e --- /dev/null +++ b/website/vendor/image-size/dist/index.d.mts @@ -0,0 +1,3 @@ +export { types } from './types/index.mjs'; +export { imageSize as default, disableTypes, imageSize } from './lookup.mjs'; +import './types/interface.mjs'; diff --git a/website/vendor/image-size/dist/index.d.ts b/website/vendor/image-size/dist/index.d.ts new file mode 100644 index 0000000..cf1e04b --- /dev/null +++ b/website/vendor/image-size/dist/index.d.ts @@ -0,0 +1,3 @@ +export { types } from './types/index.js'; +export { imageSize as default, disableTypes, imageSize } from './lookup.js'; +import './types/interface.js'; diff --git a/website/vendor/image-size/dist/index.mjs b/website/vendor/image-size/dist/index.mjs new file mode 100644 index 0000000..22c17af --- /dev/null +++ b/website/vendor/image-size/dist/index.mjs @@ -0,0 +1,991 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize2 = getImageSize(input, 0); + if (nbImages === 1) return imageSize2; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize2.width, + height: imageSize2.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize2 = getImageSize2(imageHeader[0]); + images.push(imageSize2); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +// lib/detector.ts +var firstBytes = /* @__PURE__ */ new Map([ + [0, "heif"], + [56, "psd"], + [66, "bmp"], + [68, "dds"], + [71, "gif"], + [73, "tiff"], + [77, "tiff"], + [82, "webp"], + [105, "icns"], + [137, "png"], + [255, "jpg"] +]); +function detector(input) { + const byte = input[0]; + const type = firstBytes.get(byte); + if (type && typeHandlers.get(type).validate(input)) { + return type; + } + return types.find((type2) => typeHandlers.get(type2).validate(input)); +} + +// lib/lookup.ts +var globalOptions = { + disabledTypes: [] +}; +function imageSize(input) { + const type = detector(input); + if (typeof type !== "undefined") { + if (globalOptions.disabledTypes.indexOf(type) > -1) { + throw new TypeError(`disabled file type: ${type}`); + } + const size = typeHandlers.get(type).calculate(input); + if (size !== void 0) { + size.type = size.type ?? type; + if (size.images && size.images.length > 1) { + const largestImage = size.images.reduce((largest, current) => { + return current.width * current.height > largest.width * largest.height ? current : largest; + }, size.images[0]); + size.width = largestImage.width; + size.height = largestImage.height; + } + return size; + } + } + throw new TypeError(`unsupported file type: ${type}`); +} +var disableTypes = (types2) => { + globalOptions.disabledTypes = types2; +}; + +export { imageSize as default, disableTypes, imageSize, types }; diff --git a/website/vendor/image-size/dist/lookup.cjs b/website/vendor/image-size/dist/lookup.cjs new file mode 100644 index 0000000..9731ad8 --- /dev/null +++ b/website/vendor/image-size/dist/lookup.cjs @@ -0,0 +1,994 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize2 = getImageSize(input, 0); + if (nbImages === 1) return imageSize2; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize2.width, + height: imageSize2.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize2 = getImageSize2(imageHeader[0]); + images.push(imageSize2); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +// lib/detector.ts +var firstBytes = /* @__PURE__ */ new Map([ + [0, "heif"], + [56, "psd"], + [66, "bmp"], + [68, "dds"], + [71, "gif"], + [73, "tiff"], + [77, "tiff"], + [82, "webp"], + [105, "icns"], + [137, "png"], + [255, "jpg"] +]); +function detector(input) { + const byte = input[0]; + const type = firstBytes.get(byte); + if (type && typeHandlers.get(type).validate(input)) { + return type; + } + return types.find((type2) => typeHandlers.get(type2).validate(input)); +} + +// lib/lookup.ts +var globalOptions = { + disabledTypes: [] +}; +function imageSize(input) { + const type = detector(input); + if (typeof type !== "undefined") { + if (globalOptions.disabledTypes.indexOf(type) > -1) { + throw new TypeError(`disabled file type: ${type}`); + } + const size = typeHandlers.get(type).calculate(input); + if (size !== void 0) { + size.type = size.type ?? type; + if (size.images && size.images.length > 1) { + const largestImage = size.images.reduce((largest, current) => { + return current.width * current.height > largest.width * largest.height ? current : largest; + }, size.images[0]); + size.width = largestImage.width; + size.height = largestImage.height; + } + return size; + } + } + throw new TypeError(`unsupported file type: ${type}`); +} +var disableTypes = (types2) => { + globalOptions.disabledTypes = types2; +}; + +exports.disableTypes = disableTypes; +exports.imageSize = imageSize; diff --git a/website/vendor/image-size/dist/lookup.d.mts b/website/vendor/image-size/dist/lookup.d.mts new file mode 100644 index 0000000..2c6b33d --- /dev/null +++ b/website/vendor/image-size/dist/lookup.d.mts @@ -0,0 +1,13 @@ +import { imageType } from './types/index.mjs'; +import { ISizeCalculationResult } from './types/interface.mjs'; + +/** + * Return size information based on an Uint8Array + * + * @param {Uint8Array} input + * @returns {ISizeCalculationResult} + */ +declare function imageSize(input: Uint8Array): ISizeCalculationResult; +declare const disableTypes: (types: imageType[]) => void; + +export { disableTypes, imageSize }; diff --git a/website/vendor/image-size/dist/lookup.d.ts b/website/vendor/image-size/dist/lookup.d.ts new file mode 100644 index 0000000..66f568f --- /dev/null +++ b/website/vendor/image-size/dist/lookup.d.ts @@ -0,0 +1,13 @@ +import { imageType } from './types/index.js'; +import { ISizeCalculationResult } from './types/interface.js'; + +/** + * Return size information based on an Uint8Array + * + * @param {Uint8Array} input + * @returns {ISizeCalculationResult} + */ +declare function imageSize(input: Uint8Array): ISizeCalculationResult; +declare const disableTypes: (types: imageType[]) => void; + +export { disableTypes, imageSize }; diff --git a/website/vendor/image-size/dist/lookup.mjs b/website/vendor/image-size/dist/lookup.mjs new file mode 100644 index 0000000..f787d1c --- /dev/null +++ b/website/vendor/image-size/dist/lookup.mjs @@ -0,0 +1,991 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize2 = getImageSize(input, 0); + if (nbImages === 1) return imageSize2; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize2.width, + height: imageSize2.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize2 = getImageSize2(imageHeader[0]); + images.push(imageSize2); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +// lib/detector.ts +var firstBytes = /* @__PURE__ */ new Map([ + [0, "heif"], + [56, "psd"], + [66, "bmp"], + [68, "dds"], + [71, "gif"], + [73, "tiff"], + [77, "tiff"], + [82, "webp"], + [105, "icns"], + [137, "png"], + [255, "jpg"] +]); +function detector(input) { + const byte = input[0]; + const type = firstBytes.get(byte); + if (type && typeHandlers.get(type).validate(input)) { + return type; + } + return types.find((type2) => typeHandlers.get(type2).validate(input)); +} + +// lib/lookup.ts +var globalOptions = { + disabledTypes: [] +}; +function imageSize(input) { + const type = detector(input); + if (typeof type !== "undefined") { + if (globalOptions.disabledTypes.indexOf(type) > -1) { + throw new TypeError(`disabled file type: ${type}`); + } + const size = typeHandlers.get(type).calculate(input); + if (size !== void 0) { + size.type = size.type ?? type; + if (size.images && size.images.length > 1) { + const largestImage = size.images.reduce((largest, current) => { + return current.width * current.height > largest.width * largest.height ? current : largest; + }, size.images[0]); + size.width = largestImage.width; + size.height = largestImage.height; + } + return size; + } + } + throw new TypeError(`unsupported file type: ${type}`); +} +var disableTypes = (types2) => { + globalOptions.disabledTypes = types2; +}; + +export { disableTypes, imageSize }; diff --git a/website/vendor/image-size/dist/types/bmp.cjs b/website/vendor/image-size/dist/types/bmp.cjs new file mode 100644 index 0000000..3fd9cfa --- /dev/null +++ b/website/vendor/image-size/dist/types/bmp.cjs @@ -0,0 +1,19 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +exports.BMP = BMP; diff --git a/website/vendor/image-size/dist/types/bmp.d.mts b/website/vendor/image-size/dist/types/bmp.d.mts new file mode 100644 index 0000000..a5f6324 --- /dev/null +++ b/website/vendor/image-size/dist/types/bmp.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const BMP: IImage; + +export { BMP }; diff --git a/website/vendor/image-size/dist/types/bmp.d.ts b/website/vendor/image-size/dist/types/bmp.d.ts new file mode 100644 index 0000000..27a2256 --- /dev/null +++ b/website/vendor/image-size/dist/types/bmp.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const BMP: IImage; + +export { BMP }; diff --git a/website/vendor/image-size/dist/types/bmp.mjs b/website/vendor/image-size/dist/types/bmp.mjs new file mode 100644 index 0000000..efc23bf --- /dev/null +++ b/website/vendor/image-size/dist/types/bmp.mjs @@ -0,0 +1,17 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +export { BMP }; diff --git a/website/vendor/image-size/dist/types/cur.cjs b/website/vendor/image-size/dist/types/cur.cjs new file mode 100644 index 0000000..9ddffcd --- /dev/null +++ b/website/vendor/image-size/dist/types/cur.cjs @@ -0,0 +1,60 @@ +'use strict'; + +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize = getImageSize(input, 0); + if (nbImages === 1) return imageSize; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize.width, + height: imageSize.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +exports.CUR = CUR; diff --git a/website/vendor/image-size/dist/types/cur.d.mts b/website/vendor/image-size/dist/types/cur.d.mts new file mode 100644 index 0000000..dc8c6dc --- /dev/null +++ b/website/vendor/image-size/dist/types/cur.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const CUR: IImage; + +export { CUR }; diff --git a/website/vendor/image-size/dist/types/cur.d.ts b/website/vendor/image-size/dist/types/cur.d.ts new file mode 100644 index 0000000..984ec17 --- /dev/null +++ b/website/vendor/image-size/dist/types/cur.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const CUR: IImage; + +export { CUR }; diff --git a/website/vendor/image-size/dist/types/cur.mjs b/website/vendor/image-size/dist/types/cur.mjs new file mode 100644 index 0000000..f84af76 --- /dev/null +++ b/website/vendor/image-size/dist/types/cur.mjs @@ -0,0 +1,58 @@ +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize = getImageSize(input, 0); + if (nbImages === 1) return imageSize; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize.width, + height: imageSize.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +export { CUR }; diff --git a/website/vendor/image-size/dist/types/dds.cjs b/website/vendor/image-size/dist/types/dds.cjs new file mode 100644 index 0000000..56e4a95 --- /dev/null +++ b/website/vendor/image-size/dist/types/dds.cjs @@ -0,0 +1,17 @@ +'use strict'; + +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +exports.DDS = DDS; diff --git a/website/vendor/image-size/dist/types/dds.d.mts b/website/vendor/image-size/dist/types/dds.d.mts new file mode 100644 index 0000000..a7af22d --- /dev/null +++ b/website/vendor/image-size/dist/types/dds.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const DDS: IImage; + +export { DDS }; diff --git a/website/vendor/image-size/dist/types/dds.d.ts b/website/vendor/image-size/dist/types/dds.d.ts new file mode 100644 index 0000000..84366ba --- /dev/null +++ b/website/vendor/image-size/dist/types/dds.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const DDS: IImage; + +export { DDS }; diff --git a/website/vendor/image-size/dist/types/dds.mjs b/website/vendor/image-size/dist/types/dds.mjs new file mode 100644 index 0000000..bdec684 --- /dev/null +++ b/website/vendor/image-size/dist/types/dds.mjs @@ -0,0 +1,15 @@ +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +export { DDS }; diff --git a/website/vendor/image-size/dist/types/gif.cjs b/website/vendor/image-size/dist/types/gif.cjs new file mode 100644 index 0000000..64fa0ba --- /dev/null +++ b/website/vendor/image-size/dist/types/gif.cjs @@ -0,0 +1,19 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +exports.GIF = GIF; diff --git a/website/vendor/image-size/dist/types/gif.d.mts b/website/vendor/image-size/dist/types/gif.d.mts new file mode 100644 index 0000000..3776009 --- /dev/null +++ b/website/vendor/image-size/dist/types/gif.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const GIF: IImage; + +export { GIF }; diff --git a/website/vendor/image-size/dist/types/gif.d.ts b/website/vendor/image-size/dist/types/gif.d.ts new file mode 100644 index 0000000..31a0476 --- /dev/null +++ b/website/vendor/image-size/dist/types/gif.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const GIF: IImage; + +export { GIF }; diff --git a/website/vendor/image-size/dist/types/gif.mjs b/website/vendor/image-size/dist/types/gif.mjs new file mode 100644 index 0000000..918dc2b --- /dev/null +++ b/website/vendor/image-size/dist/types/gif.mjs @@ -0,0 +1,17 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +export { GIF }; diff --git a/website/vendor/image-size/dist/types/heif.cjs b/website/vendor/image-size/dist/types/heif.cjs new file mode 100644 index 0000000..418ea88 --- /dev/null +++ b/website/vendor/image-size/dist/types/heif.cjs @@ -0,0 +1,92 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +function readBox(input, offset) { + if (input.length - offset < 8) return; + const boxSize = readUInt32BE(input, offset); + // Size 0 would not advance parsers that use offset+size (DoS). Treat as invalid. + if (boxSize === 0) return; + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + // Guard zero-sized ispe boxes (DoS: never-advancing offset) + if (!ispeBox.size) { + throw new TypeError("Invalid HEIF, zero-sized ispe box"); + } + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +exports.HEIF = HEIF; diff --git a/website/vendor/image-size/dist/types/heif.d.mts b/website/vendor/image-size/dist/types/heif.d.mts new file mode 100644 index 0000000..5a54612 --- /dev/null +++ b/website/vendor/image-size/dist/types/heif.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const HEIF: IImage; + +export { HEIF }; diff --git a/website/vendor/image-size/dist/types/heif.d.ts b/website/vendor/image-size/dist/types/heif.d.ts new file mode 100644 index 0000000..0a8cddd --- /dev/null +++ b/website/vendor/image-size/dist/types/heif.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const HEIF: IImage; + +export { HEIF }; diff --git a/website/vendor/image-size/dist/types/heif.mjs b/website/vendor/image-size/dist/types/heif.mjs new file mode 100644 index 0000000..76b75a6 --- /dev/null +++ b/website/vendor/image-size/dist/types/heif.mjs @@ -0,0 +1,90 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +function readBox(input, offset) { + if (input.length - offset < 8) return; + const boxSize = readUInt32BE(input, offset); + // Size 0 would not advance parsers that use offset+size (DoS). Treat as invalid. + if (boxSize === 0) return; + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + // Guard zero-sized ispe boxes (DoS: never-advancing offset) + if (!ispeBox.size) { + throw new TypeError("Invalid HEIF, zero-sized ispe box"); + } + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +export { HEIF }; diff --git a/website/vendor/image-size/dist/types/icns.cjs b/website/vendor/image-size/dist/types/icns.cjs new file mode 100644 index 0000000..e2628c5 --- /dev/null +++ b/website/vendor/image-size/dist/types/icns.cjs @@ -0,0 +1,95 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); + +// lib/types/icns.ts +var SIZE_HEADER = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const entryLength = imageHeader[1]; + // Guard zero-sized ICNS entries (DoS: never-advancing offset) + if (!entryLength) { + throw new TypeError("Invalid ICNS, zero-sized entry"); + } + const imageSize = getImageSize(imageHeader[0]); + images.push(imageSize); + imageOffset += entryLength; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +exports.ICNS = ICNS; diff --git a/website/vendor/image-size/dist/types/icns.d.mts b/website/vendor/image-size/dist/types/icns.d.mts new file mode 100644 index 0000000..e65df4d --- /dev/null +++ b/website/vendor/image-size/dist/types/icns.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const ICNS: IImage; + +export { ICNS }; diff --git a/website/vendor/image-size/dist/types/icns.d.ts b/website/vendor/image-size/dist/types/icns.d.ts new file mode 100644 index 0000000..33d371d --- /dev/null +++ b/website/vendor/image-size/dist/types/icns.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const ICNS: IImage; + +export { ICNS }; diff --git a/website/vendor/image-size/dist/types/icns.mjs b/website/vendor/image-size/dist/types/icns.mjs new file mode 100644 index 0000000..00a5680 --- /dev/null +++ b/website/vendor/image-size/dist/types/icns.mjs @@ -0,0 +1,93 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); + +// lib/types/icns.ts +var SIZE_HEADER = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const entryLength = imageHeader[1]; + // Guard zero-sized ICNS entries (DoS: never-advancing offset) + if (!entryLength) { + throw new TypeError("Invalid ICNS, zero-sized entry"); + } + const imageSize = getImageSize(imageHeader[0]); + images.push(imageSize); + imageOffset += entryLength; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +export { ICNS }; diff --git a/website/vendor/image-size/dist/types/ico.cjs b/website/vendor/image-size/dist/types/ico.cjs new file mode 100644 index 0000000..972dbd6 --- /dev/null +++ b/website/vendor/image-size/dist/types/ico.cjs @@ -0,0 +1,47 @@ +'use strict'; + +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize = getImageSize(input, 0); + if (nbImages === 1) return imageSize; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize.width, + height: imageSize.height, + images + }; + } +}; + +exports.ICO = ICO; diff --git a/website/vendor/image-size/dist/types/ico.d.mts b/website/vendor/image-size/dist/types/ico.d.mts new file mode 100644 index 0000000..a88d38f --- /dev/null +++ b/website/vendor/image-size/dist/types/ico.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const ICO: IImage; + +export { ICO }; diff --git a/website/vendor/image-size/dist/types/ico.d.ts b/website/vendor/image-size/dist/types/ico.d.ts new file mode 100644 index 0000000..8d9dfdb --- /dev/null +++ b/website/vendor/image-size/dist/types/ico.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const ICO: IImage; + +export { ICO }; diff --git a/website/vendor/image-size/dist/types/ico.mjs b/website/vendor/image-size/dist/types/ico.mjs new file mode 100644 index 0000000..a2a0a7e --- /dev/null +++ b/website/vendor/image-size/dist/types/ico.mjs @@ -0,0 +1,45 @@ +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize = getImageSize(input, 0); + if (nbImages === 1) return imageSize; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize.width, + height: imageSize.height, + images + }; + } +}; + +export { ICO }; diff --git a/website/vendor/image-size/dist/types/index.cjs b/website/vendor/image-size/dist/types/index.cjs new file mode 100644 index 0000000..6949cd1 --- /dev/null +++ b/website/vendor/image-size/dist/types/index.cjs @@ -0,0 +1,942 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize = getImageSize(input, 0); + if (nbImages === 1) return imageSize; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize.width, + height: imageSize.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize = getImageSize2(imageHeader[0]); + images.push(imageSize); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +exports.typeHandlers = typeHandlers; +exports.types = types; diff --git a/website/vendor/image-size/dist/types/index.d.mts b/website/vendor/image-size/dist/types/index.d.mts new file mode 100644 index 0000000..d4b3969 --- /dev/null +++ b/website/vendor/image-size/dist/types/index.d.mts @@ -0,0 +1,7 @@ +import { IImage } from './interface.mjs'; + +declare const typeHandlers: Map<"bmp" | "cur" | "dds" | "gif" | "heif" | "icns" | "ico" | "j2c" | "jp2" | "jpg" | "jxl" | "jxl-stream" | "ktx" | "png" | "pnm" | "psd" | "svg" | "tga" | "tiff" | "webp", IImage>; +declare const types: ("bmp" | "cur" | "dds" | "gif" | "heif" | "icns" | "ico" | "j2c" | "jp2" | "jpg" | "jxl" | "jxl-stream" | "ktx" | "png" | "pnm" | "psd" | "svg" | "tga" | "tiff" | "webp")[]; +type imageType = (typeof types)[number]; + +export { type imageType, typeHandlers, types }; diff --git a/website/vendor/image-size/dist/types/index.d.ts b/website/vendor/image-size/dist/types/index.d.ts new file mode 100644 index 0000000..7b44f38 --- /dev/null +++ b/website/vendor/image-size/dist/types/index.d.ts @@ -0,0 +1,7 @@ +import { IImage } from './interface.js'; + +declare const typeHandlers: Map<"bmp" | "cur" | "dds" | "gif" | "heif" | "icns" | "ico" | "j2c" | "jp2" | "jpg" | "jxl" | "jxl-stream" | "ktx" | "png" | "pnm" | "psd" | "svg" | "tga" | "tiff" | "webp", IImage>; +declare const types: ("bmp" | "cur" | "dds" | "gif" | "heif" | "icns" | "ico" | "j2c" | "jp2" | "jpg" | "jxl" | "jxl-stream" | "ktx" | "png" | "pnm" | "psd" | "svg" | "tga" | "tiff" | "webp")[]; +type imageType = (typeof types)[number]; + +export { type imageType, typeHandlers, types }; diff --git a/website/vendor/image-size/dist/types/index.mjs b/website/vendor/image-size/dist/types/index.mjs new file mode 100644 index 0000000..b026dda --- /dev/null +++ b/website/vendor/image-size/dist/types/index.mjs @@ -0,0 +1,939 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/bmp.ts +var BMP = { + validate: (input) => toUTF8String(input, 0, 2) === "BM", + calculate: (input) => ({ + height: Math.abs(readInt32LE(input, 22)), + width: readUInt32LE(input, 18) + }) +}; + +// lib/types/ico.ts +var TYPE_ICON = 1; +var SIZE_HEADER = 2 + 2 + 2; +var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; +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) + }; +} +var ICO = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_ICON; + }, + calculate(input) { + const nbImages = readUInt16LE(input, 4); + const imageSize = getImageSize(input, 0); + if (nbImages === 1) return imageSize; + const images = []; + for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) { + images.push(getImageSize(input, imageIndex)); + } + return { + width: imageSize.width, + height: imageSize.height, + images + }; + } +}; + +// lib/types/cur.ts +var TYPE_CURSOR = 2; +var CUR = { + validate(input) { + const reserved = readUInt16LE(input, 0); + const imageCount = readUInt16LE(input, 4); + if (reserved !== 0 || imageCount === 0) return false; + const imageType = readUInt16LE(input, 2); + return imageType === TYPE_CURSOR; + }, + calculate: (input) => ICO.calculate(input) +}; + +// lib/types/dds.ts +var DDS = { + validate: (input) => readUInt32LE(input, 0) === 542327876, + calculate: (input) => ({ + height: readUInt32LE(input, 12), + width: readUInt32LE(input, 16) + }) +}; + +// lib/types/gif.ts +var gifRegexp = /^GIF8[79]a/; +var GIF = { + validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)), + calculate: (input) => ({ + height: readUInt16LE(input, 8), + width: readUInt16LE(input, 6) + }) +}; + +// lib/types/heif.ts +var brandMap = { + avif: "avif", + mif1: "heif", + msf1: "heif", + // heif-sequence + heic: "heic", + heix: "heic", + hevc: "heic", + // heic-sequence + hevx: "heic" + // heic-sequence +}; +var HEIF = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "ftyp") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand in brandMap; + }, + calculate(input) { + const metaBox = findBox(input, "meta", 0); + const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12); + const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8); + if (!ipcoBox) { + throw new TypeError("Invalid HEIF, no ipco box found"); + } + const type = toUTF8String(input, 8, 12); + const images = []; + let currentOffset = ipcoBox.offset + 8; + while (currentOffset < ipcoBox.offset + ipcoBox.size) { + const ispeBox = findBox(input, "ispe", currentOffset); + if (!ispeBox) break; + const rawWidth = readUInt32BE(input, ispeBox.offset + 12); + const rawHeight = readUInt32BE(input, ispeBox.offset + 16); + const clapBox = findBox(input, "clap", currentOffset); + let width = rawWidth; + let height = rawHeight; + if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) { + const cropRight = readUInt32BE(input, clapBox.offset + 12); + width = rawWidth - cropRight; + } + images.push({ height, width }); + currentOffset = ispeBox.offset + ispeBox.size; + } + if (images.length === 0) { + throw new TypeError("Invalid HEIF, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + type, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/icns.ts +var SIZE_HEADER2 = 4 + 4; +var FILE_LENGTH_OFFSET = 4; +var ENTRY_LENGTH_OFFSET = 4; +var 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 [ + toUTF8String(input, imageOffset, imageLengthOffset), + readUInt32BE(input, imageLengthOffset) + ]; +} +function getImageSize2(type) { + const size = ICON_TYPE_SIZE[type]; + return { width: size, height: size, type }; +} +var ICNS = { + validate: (input) => toUTF8String(input, 0, 4) === "icns", + calculate(input) { + const inputLength = input.length; + const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET); + let imageOffset = SIZE_HEADER2; + const images = []; + while (imageOffset < fileLength && imageOffset < inputLength) { + const imageHeader = readImageHeader(input, imageOffset); + const imageSize = getImageSize2(imageHeader[0]); + images.push(imageSize); + imageOffset += imageHeader[1]; + } + if (images.length === 0) { + throw new TypeError("Invalid ICNS, no sizes found"); + } + return { + width: images[0].width, + height: images[0].height, + ...images.length > 1 ? { images } : {} + }; + } +}; + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +// lib/types/index.ts +var typeHandlers = /* @__PURE__ */ new Map([ + ["bmp", BMP], + ["cur", CUR], + ["dds", DDS], + ["gif", GIF], + ["heif", HEIF], + ["icns", ICNS], + ["ico", ICO], + ["j2c", J2C], + ["jp2", JP2], + ["jpg", JPG], + ["jxl", JXL], + ["jxl-stream", JXLStream], + ["ktx", KTX], + ["png", PNG], + ["pnm", PNM], + ["psd", PSD], + ["svg", SVG], + ["tga", TGA], + ["tiff", TIFF], + ["webp", WEBP] +]); +var types = Array.from(typeHandlers.keys()); + +export { typeHandlers, types }; diff --git a/website/vendor/image-size/dist/types/interface.cjs b/website/vendor/image-size/dist/types/interface.cjs new file mode 100644 index 0000000..eb109ab --- /dev/null +++ b/website/vendor/image-size/dist/types/interface.cjs @@ -0,0 +1,2 @@ +'use strict'; + diff --git a/website/vendor/image-size/dist/types/interface.d.mts b/website/vendor/image-size/dist/types/interface.d.mts new file mode 100644 index 0000000..751c166 --- /dev/null +++ b/website/vendor/image-size/dist/types/interface.d.mts @@ -0,0 +1,15 @@ +interface ISize { + width: number; + height: number; + orientation?: number; + type?: string; +} +type ISizeCalculationResult = { + images?: ISize[]; +} & ISize; +interface IImage { + validate: (input: Uint8Array) => boolean; + calculate: (input: Uint8Array) => ISizeCalculationResult; +} + +export type { IImage, ISize, ISizeCalculationResult }; diff --git a/website/vendor/image-size/dist/types/interface.d.ts b/website/vendor/image-size/dist/types/interface.d.ts new file mode 100644 index 0000000..751c166 --- /dev/null +++ b/website/vendor/image-size/dist/types/interface.d.ts @@ -0,0 +1,15 @@ +interface ISize { + width: number; + height: number; + orientation?: number; + type?: string; +} +type ISizeCalculationResult = { + images?: ISize[]; +} & ISize; +interface IImage { + validate: (input: Uint8Array) => boolean; + calculate: (input: Uint8Array) => ISizeCalculationResult; +} + +export type { IImage, ISize, ISizeCalculationResult }; diff --git a/website/vendor/image-size/dist/types/interface.mjs b/website/vendor/image-size/dist/types/interface.mjs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/website/vendor/image-size/dist/types/interface.mjs @@ -0,0 +1 @@ + diff --git a/website/vendor/image-size/dist/types/j2c.cjs b/website/vendor/image-size/dist/types/j2c.cjs new file mode 100644 index 0000000..7f0fc12 --- /dev/null +++ b/website/vendor/image-size/dist/types/j2c.cjs @@ -0,0 +1,18 @@ +'use strict'; + +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +exports.J2C = J2C; diff --git a/website/vendor/image-size/dist/types/j2c.d.mts b/website/vendor/image-size/dist/types/j2c.d.mts new file mode 100644 index 0000000..4550294 --- /dev/null +++ b/website/vendor/image-size/dist/types/j2c.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const J2C: IImage; + +export { J2C }; diff --git a/website/vendor/image-size/dist/types/j2c.d.ts b/website/vendor/image-size/dist/types/j2c.d.ts new file mode 100644 index 0000000..4a07241 --- /dev/null +++ b/website/vendor/image-size/dist/types/j2c.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const J2C: IImage; + +export { J2C }; diff --git a/website/vendor/image-size/dist/types/j2c.mjs b/website/vendor/image-size/dist/types/j2c.mjs new file mode 100644 index 0000000..74ebe7e --- /dev/null +++ b/website/vendor/image-size/dist/types/j2c.mjs @@ -0,0 +1,16 @@ +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); + +// lib/types/j2c.ts +var J2C = { + // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC + validate: (input) => readUInt32BE(input, 0) === 4283432785, + calculate: (input) => ({ + height: readUInt32BE(input, 12), + width: readUInt32BE(input, 8) + }) +}; + +export { J2C }; diff --git a/website/vendor/image-size/dist/types/jp2.cjs b/website/vendor/image-size/dist/types/jp2.cjs new file mode 100644 index 0000000..cdd7c88 --- /dev/null +++ b/website/vendor/image-size/dist/types/jp2.cjs @@ -0,0 +1,50 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +exports.JP2 = JP2; diff --git a/website/vendor/image-size/dist/types/jp2.d.mts b/website/vendor/image-size/dist/types/jp2.d.mts new file mode 100644 index 0000000..675d171 --- /dev/null +++ b/website/vendor/image-size/dist/types/jp2.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const JP2: IImage; + +export { JP2 }; diff --git a/website/vendor/image-size/dist/types/jp2.d.ts b/website/vendor/image-size/dist/types/jp2.d.ts new file mode 100644 index 0000000..1319476 --- /dev/null +++ b/website/vendor/image-size/dist/types/jp2.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const JP2: IImage; + +export { JP2 }; diff --git a/website/vendor/image-size/dist/types/jp2.mjs b/website/vendor/image-size/dist/types/jp2.mjs new file mode 100644 index 0000000..63a5376 --- /dev/null +++ b/website/vendor/image-size/dist/types/jp2.mjs @@ -0,0 +1,48 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +function readBox(input, offset) { + if (input.length - offset < 4) return; + const boxSize = readUInt32BE(input, offset); + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/jp2.ts +var JP2 = { + validate(input) { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "jP ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jp2 "; + }, + calculate(input) { + const jp2hBox = findBox(input, "jp2h", 0); + const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8); + if (ihdrBox) { + return { + height: readUInt32BE(input, ihdrBox.offset + 8), + width: readUInt32BE(input, ihdrBox.offset + 12) + }; + } + throw new TypeError("Unsupported JPEG 2000 format"); + } +}; + +export { JP2 }; diff --git a/website/vendor/image-size/dist/types/jpg.cjs b/website/vendor/image-size/dist/types/jpg.cjs new file mode 100644 index 0000000..664da4a --- /dev/null +++ b/website/vendor/image-size/dist/types/jpg.cjs @@ -0,0 +1,118 @@ +'use strict'; + +// lib/types/utils.ts +new TextDecoder(); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +exports.JPG = JPG; diff --git a/website/vendor/image-size/dist/types/jpg.d.mts b/website/vendor/image-size/dist/types/jpg.d.mts new file mode 100644 index 0000000..b64de42 --- /dev/null +++ b/website/vendor/image-size/dist/types/jpg.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const JPG: IImage; + +export { JPG }; diff --git a/website/vendor/image-size/dist/types/jpg.d.ts b/website/vendor/image-size/dist/types/jpg.d.ts new file mode 100644 index 0000000..a1945ea --- /dev/null +++ b/website/vendor/image-size/dist/types/jpg.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const JPG: IImage; + +export { JPG }; diff --git a/website/vendor/image-size/dist/types/jpg.mjs b/website/vendor/image-size/dist/types/jpg.mjs new file mode 100644 index 0000000..8fd6076 --- /dev/null +++ b/website/vendor/image-size/dist/types/jpg.mjs @@ -0,0 +1,116 @@ +// lib/types/utils.ts +new TextDecoder(); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} + +// lib/types/jpg.ts +var EXIF_MARKER = "45786966"; +var APP1_DATA_SIZE_BYTES = 2; +var EXIF_HEADER_BYTES = 6; +var TIFF_BYTE_ALIGN_BYTES = 2; +var BIG_ENDIAN_BYTE_ALIGN = "4d4d"; +var LITTLE_ENDIAN_BYTE_ALIGN = "4949"; +var IDF_ENTRY_BYTES = 12; +var NUM_DIRECTORY_ENTRIES_BYTES = 2; +function isEXIF(input) { + return toHexString(input, 2, 6) === EXIF_MARKER; +} +function extractSize(input, index) { + return { + height: readUInt16BE(input, index), + width: readUInt16BE(input, index + 2) + }; +} +function extractOrientation(exifBlock, isBigEndian) { + const idfOffset = 8; + const offset = EXIF_HEADER_BYTES + idfOffset; + const idfDirectoryEntries = 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; + if (start > exifBlock.length) { + return; + } + const block = exifBlock.slice(start, end); + const tagNumber = readUInt(block, 16, 0, isBigEndian); + if (tagNumber === 274) { + const dataFormat = readUInt(block, 16, 2, isBigEndian); + if (dataFormat !== 3) { + return; + } + const numberOfComponents = readUInt(block, 32, 4, isBigEndian); + if (numberOfComponents !== 1) { + return; + } + return readUInt(block, 16, 8, isBigEndian); + } + } +} +function validateExifBlock(input, index) { + const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index); + const byteAlign = toHexString( + exifBlock, + EXIF_HEADER_BYTES, + EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES + ); + 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) { + if (index > input.length) { + throw new TypeError("Corrupt JPG, exceeded buffer limits"); + } +} +var JPG = { + validate: (input) => toHexString(input, 0, 2) === "ffd8", + calculate(_input) { + let input = _input.slice(4); + let orientation; + let next; + while (input.length) { + const i = readUInt16BE(input, 0); + validateInput(input, i); + if (input[i] !== 255) { + input = input.slice(1); + continue; + } + if (isEXIF(input)) { + orientation = validateExifBlock(input, i); + } + next = input[i + 1]; + if (next === 192 || next === 193 || next === 194) { + const size = extractSize(input, i + 5); + if (!orientation) { + return size; + } + return { + height: size.height, + orientation, + width: size.width + }; + } + input = input.slice(i + 2); + } + throw new TypeError("Invalid JPG, no size found"); + } +}; + +export { JPG }; diff --git a/website/vendor/image-size/dist/types/jxl-stream.cjs b/website/vendor/image-size/dist/types/jxl-stream.cjs new file mode 100644 index 0000000..b31d558 --- /dev/null +++ b/website/vendor/image-size/dist/types/jxl-stream.cjs @@ -0,0 +1,80 @@ +'use strict'; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/utils.ts +new TextDecoder(); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +exports.JXLStream = JXLStream; diff --git a/website/vendor/image-size/dist/types/jxl-stream.d.mts b/website/vendor/image-size/dist/types/jxl-stream.d.mts new file mode 100644 index 0000000..50fb83f --- /dev/null +++ b/website/vendor/image-size/dist/types/jxl-stream.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const JXLStream: IImage; + +export { JXLStream }; diff --git a/website/vendor/image-size/dist/types/jxl-stream.d.ts b/website/vendor/image-size/dist/types/jxl-stream.d.ts new file mode 100644 index 0000000..f929490 --- /dev/null +++ b/website/vendor/image-size/dist/types/jxl-stream.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const JXLStream: IImage; + +export { JXLStream }; diff --git a/website/vendor/image-size/dist/types/jxl-stream.mjs b/website/vendor/image-size/dist/types/jxl-stream.mjs new file mode 100644 index 0000000..40ba918 --- /dev/null +++ b/website/vendor/image-size/dist/types/jxl-stream.mjs @@ -0,0 +1,78 @@ +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/utils.ts +new TextDecoder(); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +export { JXLStream }; diff --git a/website/vendor/image-size/dist/types/jxl.cjs b/website/vendor/image-size/dist/types/jxl.cjs new file mode 100644 index 0000000..a31827c --- /dev/null +++ b/website/vendor/image-size/dist/types/jxl.cjs @@ -0,0 +1,160 @@ +'use strict'; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +function readBox(input, offset) { + if (input.length - offset < 8) return; + const boxSize = readUInt32BE(input, offset); + // Size 0 would not advance parsers that use offset+size (DoS). Treat as invalid. + if (boxSize === 0) return; + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + if (!jxlpBox.size) { + throw new Error("Invalid JXL, zero-sized jxlp box"); + } + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +exports.JXL = JXL; diff --git a/website/vendor/image-size/dist/types/jxl.d.mts b/website/vendor/image-size/dist/types/jxl.d.mts new file mode 100644 index 0000000..c7527e6 --- /dev/null +++ b/website/vendor/image-size/dist/types/jxl.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const JXL: IImage; + +export { JXL }; diff --git a/website/vendor/image-size/dist/types/jxl.d.ts b/website/vendor/image-size/dist/types/jxl.d.ts new file mode 100644 index 0000000..a34dd98 --- /dev/null +++ b/website/vendor/image-size/dist/types/jxl.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const JXL: IImage; + +export { JXL }; diff --git a/website/vendor/image-size/dist/types/jxl.mjs b/website/vendor/image-size/dist/types/jxl.mjs new file mode 100644 index 0000000..8b6fa76 --- /dev/null +++ b/website/vendor/image-size/dist/types/jxl.mjs @@ -0,0 +1,158 @@ +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +function readBox(input, offset) { + if (input.length - offset < 8) return; + const boxSize = readUInt32BE(input, offset); + // Size 0 would not advance parsers that use offset+size (DoS). Treat as invalid. + if (boxSize === 0) return; + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +// lib/types/jxl-stream.ts +function calculateImageDimension(reader, isSmallImage) { + if (isSmallImage) { + return 8 * (1 + reader.getBits(5)); + } + const sizeClass = reader.getBits(2); + const extraBits = [9, 13, 18, 30][sizeClass]; + return 1 + reader.getBits(extraBits); +} +function calculateImageWidth(reader, isSmallImage, widthMode, height) { + if (isSmallImage && widthMode === 0) { + return 8 * (1 + reader.getBits(5)); + } + if (widthMode === 0) { + return calculateImageDimension(reader, false); + } + const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2]; + return Math.floor(height * aspectRatios[widthMode - 1]); +} +var JXLStream = { + validate: (input) => { + return toHexString(input, 0, 2) === "ff0a"; + }, + calculate(input) { + const reader = new BitReader(input, "little-endian"); + const isSmallImage = reader.getBits(1) === 1; + const height = calculateImageDimension(reader, isSmallImage); + const widthMode = reader.getBits(3); + const width = calculateImageWidth(reader, isSmallImage, widthMode, height); + return { width, height }; + } +}; + +// lib/types/jxl.ts +function extractCodestream(input) { + const jxlcBox = findBox(input, "jxlc", 0); + if (jxlcBox) { + return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size); + } + const partialStreams = extractPartialStreams(input); + if (partialStreams.length > 0) { + return concatenateCodestreams(partialStreams); + } + return void 0; +} +function extractPartialStreams(input) { + const partialStreams = []; + let offset = 0; + while (offset < input.length) { + const jxlpBox = findBox(input, "jxlp", offset); + if (!jxlpBox) break; + if (!jxlpBox.size) { + throw new Error("Invalid JXL, zero-sized jxlp box"); + } + partialStreams.push( + input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size) + ); + offset = jxlpBox.offset + jxlpBox.size; + } + return partialStreams; +} +function concatenateCodestreams(partialCodestreams) { + const totalLength = partialCodestreams.reduce( + (acc, curr) => acc + curr.length, + 0 + ); + const codestream = new Uint8Array(totalLength); + let position = 0; + for (const partial of partialCodestreams) { + codestream.set(partial, position); + position += partial.length; + } + return codestream; +} +var JXL = { + validate: (input) => { + const boxType = toUTF8String(input, 4, 8); + if (boxType !== "JXL ") return false; + const ftypBox = findBox(input, "ftyp", 0); + if (!ftypBox) return false; + const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12); + return brand === "jxl "; + }, + calculate(input) { + const codestream = extractCodestream(input); + if (codestream) return JXLStream.calculate(codestream); + throw new Error("No codestream found in JXL container"); + } +}; + +export { JXL }; diff --git a/website/vendor/image-size/dist/types/ktx.cjs b/website/vendor/image-size/dist/types/ktx.cjs new file mode 100644 index 0000000..01ba7e4 --- /dev/null +++ b/website/vendor/image-size/dist/types/ktx.cjs @@ -0,0 +1,26 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +exports.KTX = KTX; diff --git a/website/vendor/image-size/dist/types/ktx.d.mts b/website/vendor/image-size/dist/types/ktx.d.mts new file mode 100644 index 0000000..1b58b54 --- /dev/null +++ b/website/vendor/image-size/dist/types/ktx.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const KTX: IImage; + +export { KTX }; diff --git a/website/vendor/image-size/dist/types/ktx.d.ts b/website/vendor/image-size/dist/types/ktx.d.ts new file mode 100644 index 0000000..037e074 --- /dev/null +++ b/website/vendor/image-size/dist/types/ktx.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const KTX: IImage; + +export { KTX }; diff --git a/website/vendor/image-size/dist/types/ktx.mjs b/website/vendor/image-size/dist/types/ktx.mjs new file mode 100644 index 0000000..d2c103d --- /dev/null +++ b/website/vendor/image-size/dist/types/ktx.mjs @@ -0,0 +1,24 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); + +// lib/types/ktx.ts +var KTX = { + validate: (input) => { + const signature = toUTF8String(input, 1, 7); + return ["KTX 11", "KTX 20"].includes(signature); + }, + calculate: (input) => { + const type = input[5] === 49 ? "ktx" : "ktx2"; + const offset = type === "ktx" ? 36 : 20; + return { + height: readUInt32LE(input, offset + 4), + width: readUInt32LE(input, offset), + type + }; + } +}; + +export { KTX }; diff --git a/website/vendor/image-size/dist/types/png.cjs b/website/vendor/image-size/dist/types/png.cjs new file mode 100644 index 0000000..5f1cbe1 --- /dev/null +++ b/website/vendor/image-size/dist/types/png.cjs @@ -0,0 +1,41 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +exports.PNG = PNG; diff --git a/website/vendor/image-size/dist/types/png.d.mts b/website/vendor/image-size/dist/types/png.d.mts new file mode 100644 index 0000000..55d8d66 --- /dev/null +++ b/website/vendor/image-size/dist/types/png.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const PNG: IImage; + +export { PNG }; diff --git a/website/vendor/image-size/dist/types/png.d.ts b/website/vendor/image-size/dist/types/png.d.ts new file mode 100644 index 0000000..a43b49c --- /dev/null +++ b/website/vendor/image-size/dist/types/png.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const PNG: IImage; + +export { PNG }; diff --git a/website/vendor/image-size/dist/types/png.mjs b/website/vendor/image-size/dist/types/png.mjs new file mode 100644 index 0000000..d68ec18 --- /dev/null +++ b/website/vendor/image-size/dist/types/png.mjs @@ -0,0 +1,39 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); + +// lib/types/png.ts +var pngSignature = "PNG\r\n\n"; +var pngImageHeaderChunkName = "IHDR"; +var pngFriedChunkName = "CgBI"; +var PNG = { + validate(input) { + if (pngSignature === toUTF8String(input, 1, 8)) { + let chunkName = toUTF8String(input, 12, 16); + if (chunkName === pngFriedChunkName) { + chunkName = toUTF8String(input, 28, 32); + } + if (chunkName !== pngImageHeaderChunkName) { + throw new TypeError("Invalid PNG"); + } + return true; + } + return false; + }, + calculate(input) { + if (toUTF8String(input, 12, 16) === pngFriedChunkName) { + return { + height: readUInt32BE(input, 36), + width: readUInt32BE(input, 32) + }; + } + return { + height: readUInt32BE(input, 20), + width: readUInt32BE(input, 16) + }; + } +}; + +export { PNG }; diff --git a/website/vendor/image-size/dist/types/pnm.cjs b/website/vendor/image-size/dist/types/pnm.cjs new file mode 100644 index 0000000..7ec54bd --- /dev/null +++ b/website/vendor/image-size/dist/types/pnm.cjs @@ -0,0 +1,72 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +exports.PNM = PNM; diff --git a/website/vendor/image-size/dist/types/pnm.d.mts b/website/vendor/image-size/dist/types/pnm.d.mts new file mode 100644 index 0000000..79e53ab --- /dev/null +++ b/website/vendor/image-size/dist/types/pnm.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const PNM: IImage; + +export { PNM }; diff --git a/website/vendor/image-size/dist/types/pnm.d.ts b/website/vendor/image-size/dist/types/pnm.d.ts new file mode 100644 index 0000000..f36b23e --- /dev/null +++ b/website/vendor/image-size/dist/types/pnm.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const PNM: IImage; + +export { PNM }; diff --git a/website/vendor/image-size/dist/types/pnm.mjs b/website/vendor/image-size/dist/types/pnm.mjs new file mode 100644 index 0000000..0cc2857 --- /dev/null +++ b/website/vendor/image-size/dist/types/pnm.mjs @@ -0,0 +1,70 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); + +// lib/types/pnm.ts +var PNMTypes = { + P1: "pbm/ascii", + P2: "pgm/ascii", + P3: "ppm/ascii", + P4: "pbm", + P5: "pgm", + P6: "ppm", + P7: "pam", + PF: "pfm" +}; +var 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: Number.parseInt(dimensions[1], 10), + width: Number.parseInt(dimensions[0], 10) + }; + } + 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()] = Number.parseInt(value, 10); + } + if (size.height && size.width) { + break; + } + } + if (size.height && size.width) { + return { + height: size.height, + width: size.width + }; + } + throw new TypeError("Invalid PAM"); + } +}; +var PNM = { + validate: (input) => toUTF8String(input, 0, 2) in PNMTypes, + calculate(input) { + const signature = toUTF8String(input, 0, 2); + const type = PNMTypes[signature]; + const lines = toUTF8String(input, 3).split(/[\r\n]+/); + const handler = handlers[type] || handlers.default; + return handler(lines); + } +}; + +export { PNM }; diff --git a/website/vendor/image-size/dist/types/psd.cjs b/website/vendor/image-size/dist/types/psd.cjs new file mode 100644 index 0000000..fe979ca --- /dev/null +++ b/website/vendor/image-size/dist/types/psd.cjs @@ -0,0 +1,18 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +exports.PSD = PSD; diff --git a/website/vendor/image-size/dist/types/psd.d.mts b/website/vendor/image-size/dist/types/psd.d.mts new file mode 100644 index 0000000..159147a --- /dev/null +++ b/website/vendor/image-size/dist/types/psd.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const PSD: IImage; + +export { PSD }; diff --git a/website/vendor/image-size/dist/types/psd.d.ts b/website/vendor/image-size/dist/types/psd.d.ts new file mode 100644 index 0000000..47840e9 --- /dev/null +++ b/website/vendor/image-size/dist/types/psd.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const PSD: IImage; + +export { PSD }; diff --git a/website/vendor/image-size/dist/types/psd.mjs b/website/vendor/image-size/dist/types/psd.mjs new file mode 100644 index 0000000..a363926 --- /dev/null +++ b/website/vendor/image-size/dist/types/psd.mjs @@ -0,0 +1,16 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); + +// lib/types/psd.ts +var PSD = { + validate: (input) => toUTF8String(input, 0, 4) === "8BPS", + calculate: (input) => ({ + height: readUInt32BE(input, 14), + width: readUInt32BE(input, 18) + }) +}; + +export { PSD }; diff --git a/website/vendor/image-size/dist/types/svg.cjs b/website/vendor/image-size/dist/types/svg.cjs new file mode 100644 index 0000000..00e527a --- /dev/null +++ b/website/vendor/image-size/dist/types/svg.cjs @@ -0,0 +1,97 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +exports.SVG = SVG; diff --git a/website/vendor/image-size/dist/types/svg.d.mts b/website/vendor/image-size/dist/types/svg.d.mts new file mode 100644 index 0000000..cb1efcd --- /dev/null +++ b/website/vendor/image-size/dist/types/svg.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const SVG: IImage; + +export { SVG }; diff --git a/website/vendor/image-size/dist/types/svg.d.ts b/website/vendor/image-size/dist/types/svg.d.ts new file mode 100644 index 0000000..55d17c1 --- /dev/null +++ b/website/vendor/image-size/dist/types/svg.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const SVG: IImage; + +export { SVG }; diff --git a/website/vendor/image-size/dist/types/svg.mjs b/website/vendor/image-size/dist/types/svg.mjs new file mode 100644 index 0000000..85f9110 --- /dev/null +++ b/website/vendor/image-size/dist/types/svg.mjs @@ -0,0 +1,95 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); + +// lib/types/svg.ts +var svgReg = /"']|"[^"]*"|'[^']*')*>/; +var extractorRegExps = { + height: /\sheight=(['"])([^%]+?)\1/, + root: svgReg, + viewbox: /\sviewBox=(['"])(.+?)\1/i, + width: /\swidth=(['"])([^%]+?)\1/ +}; +var INCH_CM = 2.54; +var 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 +}; +var unitsReg = new RegExp( + `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$` +); +function parseLength(len) { + const m = unitsReg.exec(len); + if (!m) { + return void 0; + } + 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 + }; +} +var SVG = { + // Scan only the first kilo-byte to speed up the check on larger files + validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)), + calculate(input) { + const root = 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"); + } +}; + +export { SVG }; diff --git a/website/vendor/image-size/dist/types/tga.cjs b/website/vendor/image-size/dist/types/tga.cjs new file mode 100644 index 0000000..f7d6f38 --- /dev/null +++ b/website/vendor/image-size/dist/types/tga.cjs @@ -0,0 +1,21 @@ +'use strict'; + +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +exports.TGA = TGA; diff --git a/website/vendor/image-size/dist/types/tga.d.mts b/website/vendor/image-size/dist/types/tga.d.mts new file mode 100644 index 0000000..2be9992 --- /dev/null +++ b/website/vendor/image-size/dist/types/tga.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const TGA: IImage; + +export { TGA }; diff --git a/website/vendor/image-size/dist/types/tga.d.ts b/website/vendor/image-size/dist/types/tga.d.ts new file mode 100644 index 0000000..6ad7ba4 --- /dev/null +++ b/website/vendor/image-size/dist/types/tga.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const TGA: IImage; + +export { TGA }; diff --git a/website/vendor/image-size/dist/types/tga.mjs b/website/vendor/image-size/dist/types/tga.mjs new file mode 100644 index 0000000..1e75dd1 --- /dev/null +++ b/website/vendor/image-size/dist/types/tga.mjs @@ -0,0 +1,19 @@ +// lib/types/utils.ts +new TextDecoder(); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); + +// lib/types/tga.ts +var TGA = { + validate(input) { + return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0; + }, + calculate(input) { + return { + height: readUInt16LE(input, 14), + width: readUInt16LE(input, 12) + }; + } +}; + +export { TGA }; diff --git a/website/vendor/image-size/dist/types/tiff.cjs b/website/vendor/image-size/dist/types/tiff.cjs new file mode 100644 index 0000000..b3fe32b --- /dev/null +++ b/website/vendor/image-size/dist/types/tiff.cjs @@ -0,0 +1,142 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +exports.TIFF = TIFF; diff --git a/website/vendor/image-size/dist/types/tiff.d.mts b/website/vendor/image-size/dist/types/tiff.d.mts new file mode 100644 index 0000000..3c66667 --- /dev/null +++ b/website/vendor/image-size/dist/types/tiff.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const TIFF: IImage; + +export { TIFF }; diff --git a/website/vendor/image-size/dist/types/tiff.d.ts b/website/vendor/image-size/dist/types/tiff.d.ts new file mode 100644 index 0000000..2c93df2 --- /dev/null +++ b/website/vendor/image-size/dist/types/tiff.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const TIFF: IImage; + +export { TIFF }; diff --git a/website/vendor/image-size/dist/types/tiff.mjs b/website/vendor/image-size/dist/types/tiff.mjs new file mode 100644 index 0000000..293846c --- /dev/null +++ b/website/vendor/image-size/dist/types/tiff.mjs @@ -0,0 +1,140 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} + +// lib/types/tiff.ts +var CONSTANTS = { + TAG: { + WIDTH: 256, + HEIGHT: 257, + COMPRESSION: 259 + }, + TYPE: { + SHORT: 3, + LONG: 4, + LONG8: 16 + }, + ENTRY_SIZE: { + STANDARD: 12, + BIG: 20 + }, + COUNT_SIZE: { + STANDARD: 2, + BIG: 8 + } +}; +function readIFD(input, { isBigEndian, isBigTiff }) { + const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian); + const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD; + return input.slice(ifdOffset + entryCountSize); +} +function readTagValue(input, type, offset, isBigEndian) { + switch (type) { + case CONSTANTS.TYPE.SHORT: + return readUInt(input, 16, offset, isBigEndian); + case CONSTANTS.TYPE.LONG: + return readUInt(input, 32, offset, isBigEndian); + case CONSTANTS.TYPE.LONG8: { + const value = Number(readUInt64(input, offset, isBigEndian)); + if (value > Number.MAX_SAFE_INTEGER) { + throw new TypeError("Value too large"); + } + return value; + } + default: + return 0; + } +} +function nextTag(input, isBigTiff) { + const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD; + if (input.length > entrySize) { + return input.slice(entrySize); + } +} +function extractTags(input, { isBigEndian, isBigTiff }) { + const tags = {}; + let temp = input; + while (temp?.length) { + const code = readUInt(temp, 16, 0, isBigEndian); + const type = readUInt(temp, 16, 2, isBigEndian); + const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian); + if (code === 0) break; + if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) { + const valueOffset = isBigTiff ? 12 : 8; + tags[code] = readTagValue(temp, type, valueOffset, isBigEndian); + } + temp = nextTag(temp, isBigTiff); + } + return tags; +} +function determineFormat(input) { + const signature = toUTF8String(input, 0, 2); + const version = readUInt(input, 16, 2, signature === "MM"); + return { + isBigEndian: signature === "MM", + isBigTiff: version === 43 + }; +} +function validateBigTIFFHeader(input, isBigEndian) { + const byteSize = readUInt(input, 16, 4, isBigEndian); + const reserved = readUInt(input, 16, 6, isBigEndian); + if (byteSize !== 8 || reserved !== 0) { + throw new TypeError("Invalid BigTIFF header"); + } +} +var signatures = /* @__PURE__ */ new Set([ + "49492a00", + // Little Endian + "4d4d002a", + // Big Endian + "49492b00", + // BigTIFF Little Endian + "4d4d002b" + // BigTIFF Big Endian +]); +var TIFF = { + validate: (input) => { + const signature = toHexString(input, 0, 4); + return signatures.has(signature); + }, + calculate(input) { + const format = determineFormat(input); + if (format.isBigTiff) { + validateBigTIFFHeader(input, format.isBigEndian); + } + const ifdBuffer = readIFD(input, format); + const tags = extractTags(ifdBuffer, format); + const info = { + height: tags[CONSTANTS.TAG.HEIGHT], + width: tags[CONSTANTS.TAG.WIDTH], + type: format.isBigTiff ? "bigtiff" : "tiff" + }; + if (tags[CONSTANTS.TAG.COMPRESSION]) { + info.compression = tags[CONSTANTS.TAG.COMPRESSION]; + } + if (!info.width || !info.height) { + throw new TypeError("Invalid Tiff. Missing tags"); + } + return info; + } +}; + +export { TIFF }; diff --git a/website/vendor/image-size/dist/types/utils.cjs b/website/vendor/image-size/dist/types/utils.cjs new file mode 100644 index 0000000..33daf01 --- /dev/null +++ b/website/vendor/image-size/dist/types/utils.cjs @@ -0,0 +1,62 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 8) return; + const boxSize = readUInt32BE(input, offset); + // Size 0 would not advance parsers that use offset+size (DoS). Treat as invalid. + if (boxSize === 0) return; + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +exports.findBox = findBox; +exports.readInt16LE = readInt16LE; +exports.readInt32LE = readInt32LE; +exports.readUInt = readUInt; +exports.readUInt16BE = readUInt16BE; +exports.readUInt16LE = readUInt16LE; +exports.readUInt24LE = readUInt24LE; +exports.readUInt32BE = readUInt32BE; +exports.readUInt32LE = readUInt32LE; +exports.readUInt64 = readUInt64; +exports.toHexString = toHexString; +exports.toUTF8String = toUTF8String; diff --git a/website/vendor/image-size/dist/types/utils.d.mts b/website/vendor/image-size/dist/types/utils.d.mts new file mode 100644 index 0000000..421d4fd --- /dev/null +++ b/website/vendor/image-size/dist/types/utils.d.mts @@ -0,0 +1,18 @@ +declare const toUTF8String: (input: Uint8Array, start?: number, end?: number) => string; +declare const toHexString: (input: Uint8Array, start?: number, end?: number) => string; +declare const readInt16LE: (input: Uint8Array, offset?: number) => number; +declare const readUInt16BE: (input: Uint8Array, offset?: number) => number; +declare const readUInt16LE: (input: Uint8Array, offset?: number) => number; +declare const readUInt24LE: (input: Uint8Array, offset?: number) => number; +declare const readInt32LE: (input: Uint8Array, offset?: number) => number; +declare const readUInt32BE: (input: Uint8Array, offset?: number) => number; +declare const readUInt32LE: (input: Uint8Array, offset?: number) => number; +declare const readUInt64: (input: Uint8Array, offset: number, isBigEndian: boolean) => bigint; +declare function readUInt(input: Uint8Array, bits: 16 | 32, offset?: number, isBigEndian?: boolean): number; +declare function findBox(input: Uint8Array, boxName: string, currentOffset: number): { + name: string; + offset: number; + size: number; +} | undefined; + +export { findBox, readInt16LE, readInt32LE, readUInt, readUInt16BE, readUInt16LE, readUInt24LE, readUInt32BE, readUInt32LE, readUInt64, toHexString, toUTF8String }; diff --git a/website/vendor/image-size/dist/types/utils.d.ts b/website/vendor/image-size/dist/types/utils.d.ts new file mode 100644 index 0000000..421d4fd --- /dev/null +++ b/website/vendor/image-size/dist/types/utils.d.ts @@ -0,0 +1,18 @@ +declare const toUTF8String: (input: Uint8Array, start?: number, end?: number) => string; +declare const toHexString: (input: Uint8Array, start?: number, end?: number) => string; +declare const readInt16LE: (input: Uint8Array, offset?: number) => number; +declare const readUInt16BE: (input: Uint8Array, offset?: number) => number; +declare const readUInt16LE: (input: Uint8Array, offset?: number) => number; +declare const readUInt24LE: (input: Uint8Array, offset?: number) => number; +declare const readInt32LE: (input: Uint8Array, offset?: number) => number; +declare const readUInt32BE: (input: Uint8Array, offset?: number) => number; +declare const readUInt32LE: (input: Uint8Array, offset?: number) => number; +declare const readUInt64: (input: Uint8Array, offset: number, isBigEndian: boolean) => bigint; +declare function readUInt(input: Uint8Array, bits: 16 | 32, offset?: number, isBigEndian?: boolean): number; +declare function findBox(input: Uint8Array, boxName: string, currentOffset: number): { + name: string; + offset: number; + size: number; +} | undefined; + +export { findBox, readInt16LE, readInt32LE, readUInt, readUInt16BE, readUInt16LE, readUInt24LE, readUInt32BE, readUInt32LE, readUInt64, toHexString, toUTF8String }; diff --git a/website/vendor/image-size/dist/types/utils.mjs b/website/vendor/image-size/dist/types/utils.mjs new file mode 100644 index 0000000..06fb8a0 --- /dev/null +++ b/website/vendor/image-size/dist/types/utils.mjs @@ -0,0 +1,49 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false); +var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; +var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true); +var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false); +var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true); +var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian); +var methods = { + readUInt16BE, + readUInt16LE, + readUInt32BE, + readUInt32LE +}; +function readUInt(input, bits, offset = 0, isBigEndian = false) { + const endian = isBigEndian ? "BE" : "LE"; + const methodName = `readUInt${bits}${endian}`; + return methods[methodName](input, offset); +} +function readBox(input, offset) { + if (input.length - offset < 8) return; + const boxSize = readUInt32BE(input, offset); + // Size 0 would not advance parsers that use offset+size (DoS). Treat as invalid. + if (boxSize === 0) return; + if (input.length - offset < boxSize) return; + return { + name: toUTF8String(input, 4 + offset, 8 + offset), + offset, + size: boxSize + }; +} +function findBox(input, boxName, currentOffset) { + while (currentOffset < input.length) { + const box = readBox(input, currentOffset); + if (!box) break; + if (box.name === boxName) return box; + currentOffset += box.size > 0 ? box.size : 8; + } +} + +export { findBox, readInt16LE, readInt32LE, readUInt, readUInt16BE, readUInt16LE, readUInt24LE, readUInt32BE, readUInt32LE, readUInt64, toHexString, toUTF8String }; diff --git a/website/vendor/image-size/dist/types/webp.cjs b/website/vendor/image-size/dist/types/webp.cjs new file mode 100644 index 0000000..c3c549e --- /dev/null +++ b/website/vendor/image-size/dist/types/webp.cjs @@ -0,0 +1,63 @@ +'use strict'; + +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +exports.WEBP = WEBP; diff --git a/website/vendor/image-size/dist/types/webp.d.mts b/website/vendor/image-size/dist/types/webp.d.mts new file mode 100644 index 0000000..8a0ae8f --- /dev/null +++ b/website/vendor/image-size/dist/types/webp.d.mts @@ -0,0 +1,5 @@ +import { IImage } from './interface.mjs'; + +declare const WEBP: IImage; + +export { WEBP }; diff --git a/website/vendor/image-size/dist/types/webp.d.ts b/website/vendor/image-size/dist/types/webp.d.ts new file mode 100644 index 0000000..a8c166a --- /dev/null +++ b/website/vendor/image-size/dist/types/webp.d.ts @@ -0,0 +1,5 @@ +import { IImage } from './interface.js'; + +declare const WEBP: IImage; + +export { WEBP }; diff --git a/website/vendor/image-size/dist/types/webp.mjs b/website/vendor/image-size/dist/types/webp.mjs new file mode 100644 index 0000000..b96c375 --- /dev/null +++ b/website/vendor/image-size/dist/types/webp.mjs @@ -0,0 +1,61 @@ +// lib/types/utils.ts +var decoder = new TextDecoder(); +var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end)); +var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), ""); +var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset); +var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true); +var readUInt24LE = (input, offset = 0) => { + const view = getView(input, offset); + return view.getUint16(0, true) + (view.getUint8(2) << 16); +}; + +// lib/types/webp.ts +function calculateExtended(input) { + return { + height: 1 + readUInt24LE(input, 7), + width: 1 + readUInt24LE(input, 4) + }; +} +function calculateLossless(input) { + return { + height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6), + width: 1 + ((input[2] & 63) << 8 | input[1]) + }; +} +function calculateLossy(input) { + return { + height: readInt16LE(input, 8) & 16383, + width: readInt16LE(input, 6) & 16383 + }; +} +var WEBP = { + validate(input) { + const riffHeader = "RIFF" === toUTF8String(input, 0, 4); + const webpHeader = "WEBP" === toUTF8String(input, 8, 12); + const vp8Header = "VP8" === toUTF8String(input, 12, 15); + return riffHeader && webpHeader && vp8Header; + }, + calculate(_input) { + const chunkHeader = toUTF8String(_input, 12, 16); + const input = _input.slice(20, 30); + if (chunkHeader === "VP8X") { + const extendedHeader = input[0]; + const validStart = (extendedHeader & 192) === 0; + const validEnd = (extendedHeader & 1) === 0; + if (validStart && validEnd) { + return calculateExtended(input); + } + throw new TypeError("Invalid WebP"); + } + if (chunkHeader === "VP8 " && input[0] !== 47) { + return calculateLossy(input); + } + const signature = toHexString(input, 3, 6); + if (chunkHeader === "VP8L" && signature !== "9d012a") { + return calculateLossless(input); + } + throw new TypeError("Invalid WebP"); + } +}; + +export { WEBP }; diff --git a/website/vendor/image-size/dist/utils/bit-reader.cjs b/website/vendor/image-size/dist/utils/bit-reader.cjs new file mode 100644 index 0000000..d3c5429 --- /dev/null +++ b/website/vendor/image-size/dist/utils/bit-reader.cjs @@ -0,0 +1,43 @@ +'use strict'; + +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +exports.BitReader = BitReader; diff --git a/website/vendor/image-size/dist/utils/bit-reader.d.mts b/website/vendor/image-size/dist/utils/bit-reader.d.mts new file mode 100644 index 0000000..8c4a93d --- /dev/null +++ b/website/vendor/image-size/dist/utils/bit-reader.d.mts @@ -0,0 +1,12 @@ +/** This class helps read Uint8Array bit-by-bit */ +declare class BitReader { + private readonly input; + private readonly endianness; + private byteOffset; + private bitOffset; + constructor(input: Uint8Array, endianness: 'big-endian' | 'little-endian'); + /** Reads a specified number of bits, and move the offset */ + getBits(length?: number): number; +} + +export { BitReader }; diff --git a/website/vendor/image-size/dist/utils/bit-reader.d.ts b/website/vendor/image-size/dist/utils/bit-reader.d.ts new file mode 100644 index 0000000..8c4a93d --- /dev/null +++ b/website/vendor/image-size/dist/utils/bit-reader.d.ts @@ -0,0 +1,12 @@ +/** This class helps read Uint8Array bit-by-bit */ +declare class BitReader { + private readonly input; + private readonly endianness; + private byteOffset; + private bitOffset; + constructor(input: Uint8Array, endianness: 'big-endian' | 'little-endian'); + /** Reads a specified number of bits, and move the offset */ + getBits(length?: number): number; +} + +export { BitReader }; diff --git a/website/vendor/image-size/dist/utils/bit-reader.mjs b/website/vendor/image-size/dist/utils/bit-reader.mjs new file mode 100644 index 0000000..7d759cf --- /dev/null +++ b/website/vendor/image-size/dist/utils/bit-reader.mjs @@ -0,0 +1,41 @@ +// lib/utils/bit-reader.ts +var BitReader = class { + constructor(input, endianness) { + this.input = input; + this.endianness = endianness; + // Skip the first 16 bits (2 bytes) of signature + this.byteOffset = 2; + this.bitOffset = 0; + } + /** Reads a specified number of bits, and move the offset */ + getBits(length = 1) { + let result = 0; + let bitsRead = 0; + while (bitsRead < length) { + if (this.byteOffset >= this.input.length) { + throw new Error("Reached end of input"); + } + const currentByte = this.input[this.byteOffset]; + const bitsLeft = 8 - this.bitOffset; + const bitsToRead = Math.min(length - bitsRead, bitsLeft); + if (this.endianness === "little-endian") { + const mask = (1 << bitsToRead) - 1; + const bits = currentByte >> this.bitOffset & mask; + result |= bits << bitsRead; + } else { + const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead; + const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead; + result = result << bitsToRead | bits; + } + bitsRead += bitsToRead; + this.bitOffset += bitsToRead; + if (this.bitOffset === 8) { + this.byteOffset++; + this.bitOffset = 0; + } + } + return result; + } +}; + +export { BitReader }; diff --git a/website/vendor/image-size/package.json b/website/vendor/image-size/package.json new file mode 100644 index 0000000..7efa25d --- /dev/null +++ b/website/vendor/image-size/package.json @@ -0,0 +1,78 @@ +{ + "name": "image-size", + "version": "2.0.3", + "description": "get dimensions of any image file (local security patch: zero-size box/entry DoS guards)", + "main": "./dist/index.cjs", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.mjs" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs" + } + }, + "./fromFile": { + "import": { + "types": "./dist/fromFile.d.ts", + "default": "./dist/fromFile.mjs" + }, + "require": { + "types": "./dist/fromFile.d.ts", + "default": "./dist/fromFile.cjs" + } + }, + "./types/*": { + "import": { + "types": "./dist/types/*.d.ts", + "default": "./dist/types/*.mjs" + }, + "require": { + "types": "./dist/types/*.d.ts", + "default": "./dist/types/*.cjs" + } + } + }, + "files": [ + "dist", + "bin/image-size.js" + ], + "engines": { + "node": ">=16.x" + }, + "bin": "bin/image-size.js", + "keywords": [ + "image", + "size", + "dimensions", + "resolution", + "width", + "height", + "avif", + "bmp", + "cur", + "gif", + "heic", + "heif", + "icns", + "ico", + "jpeg", + "jxl", + "png", + "psd", + "svg", + "tga", + "tiff", + "webp" + ], + "repository": { + "type": "git", + "url": "git://github.com/image-size/image-size.git" + }, + "author": "netroy (http://netroy.in/)", + "license": "MIT" +} diff --git a/website/yarn.lock b/website/yarn.lock index 8d8a17f..528d0f5 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -2865,9 +2865,9 @@ integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA== "@tybys/wasm-util@^0.10.0": - version "0.10.3" - resolved "https://registry.yarnpkg.com/@tybys/wasm-util/-/wasm-util-0.10.3.tgz#015cba9e9dd47ce14d03d2a8c5d547bfb169665d" - integrity sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg== + version "0.10.4" + resolved "https://registry.yarnpkg.com/@tybys/wasm-util/-/wasm-util-0.10.4.tgz#3e85ecb266f9d1722250e89bc69528615720b154" + integrity sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A== dependencies: tslib "^2.4.0" @@ -6156,10 +6156,8 @@ ignore@^5.2.0, ignore@^5.2.4: resolved "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz" integrity sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g== -image-size@^2.0.2: - version "2.0.2" - resolved "https://registry.npmjs.org/image-size/-/image-size-2.0.2.tgz" - integrity sha512-IRqXKlaXwgSMAMtpNzZa1ZAe8m+Sa1770Dhk8VkSsP9LS+iHD62Zd8FQKs8fbPiagBE7BzoFX23cxFnwshpV6w== +image-size@^2.0.2, "image-size@file:vendor/image-size": + version "2.0.3" immediate@^3.2.3: version "3.3.0"