fix price and modular

This commit is contained in:
2026-02-01 17:38:39 +03:30
parent 55f34aa15d
commit 164542d3e2
801 changed files with 16129 additions and 14478 deletions
+85 -4
View File
@@ -105,6 +105,89 @@ const GIF = {
})
};
const HEIC = {
validate: (input) => {
const ftypBox = findBox$1(input, "ftyp");
if (!ftypBox) return false;
const majorBrand = toUTF8String(
input,
ftypBox.offset + 8,
ftypBox.offset + 12
);
return ["heic", "heix", "hevc", "hevx", "mif1", "msf1"].includes(
majorBrand
);
},
calculate: (input) => {
const metaBox = findBox$1(input, "meta");
if (!metaBox) throw new TypeError("heic: meta box not found");
const iprpBox = findBox$1(
input,
"iprp",
metaBox.offset + 12,
metaBox.offset + metaBox.size
);
if (!iprpBox) throw new TypeError("heic: iprp box not found");
const ipcoBox = findBox$1(
input,
"ipco",
iprpBox.offset + 8,
iprpBox.offset + iprpBox.size
);
if (!ipcoBox) throw new TypeError("heic: ipco box not found");
const dimensions = findAllBoxes(
input,
"ispe",
ipcoBox.offset + 8,
ipcoBox.offset + ipcoBox.size
).map((box) => ({
width: readUInt32BE(input, box.offset + 12),
height: readUInt32BE(input, box.offset + 16)
}));
if (dimensions.length === 0)
throw new TypeError("heic: ispe box not found");
let largestDimension = dimensions[0];
for (let i = 1; i < dimensions.length; i++) {
const curr = dimensions[i];
if (curr.width * curr.height > largestDimension.width * largestDimension.height) {
largestDimension = curr;
}
}
return largestDimension;
}
};
function findBox$1(input, type, startOffset = 0, endOffset = input.length) {
let offset = startOffset;
while (offset < endOffset) {
const size = readUInt32BE(input, offset);
const boxType = toUTF8String(input, offset + 4, offset + 8);
if (boxType === type) {
return { offset, size };
}
if (size <= 0 || offset + size > endOffset) {
break;
}
offset += size;
}
return void 0;
}
function findAllBoxes(input, type, startOffset = 0, endOffset = input.length) {
let offset = startOffset;
const boxes = [];
while (offset < endOffset) {
const size = readUInt32BE(input, offset);
const boxType = toUTF8String(input, offset + 4, offset + 8);
if (boxType === type) {
boxes.push({ offset, size });
}
if (size <= 0 || offset + size > endOffset) {
break;
}
offset += size;
}
return boxes;
}
const SIZE_HEADER = 4 + 4;
const FILE_LENGTH_OFFSET = 4;
const ENTRY_LENGTH_OFFSET = 4;
@@ -199,12 +282,9 @@ const J2C = {
const BoxTypes = {
ftyp: "66747970",
ihdr: "69686472",
jp2h: "6a703268",
jp__: "6a502020",
rreq: "72726571",
xml_: "786d6c20"
};
rreq: "72726571"};
const calculateRREQLength = (box) => {
const unit = box[0];
let offset = 1 + 2 * unit;
@@ -727,6 +807,7 @@ const typeHandlers = {
cur: CUR,
dds: DDS,
gif: GIF,
heic: HEIC,
icns: ICNS,
ico: ICO,
j2c: J2C,
+12 -12
View File
@@ -1,6 +1,6 @@
{
"name": "image-meta",
"version": "0.2.1",
"version": "0.2.2",
"description": "Detect image type and size using pure javascript",
"repository": "unjs/image-meta",
"license": "MIT",
@@ -31,16 +31,16 @@
"test:types": "tsc --noEmit --skipLibCheck"
},
"devDependencies": {
"@types/node": "^20.14.9",
"@vitest/coverage-v8": "^1.6.0",
"changelogen": "^0.5.5",
"eslint": "^9.6.0",
"eslint-config-unjs": "^0.3.2",
"jiti": "^1.21.6",
"prettier": "^3.3.2",
"typescript": "^5.5.3",
"unbuild": "^2.0.0",
"vitest": "^1.6.0"
"@types/node": "^24.7.0",
"@vitest/coverage-v8": "^3.2.4",
"changelogen": "^0.6.2",
"eslint": "^9.37.0",
"eslint-config-unjs": "^0.5.0",
"jiti": "^2.6.1",
"prettier": "^3.6.2",
"typescript": "^5.9.3",
"unbuild": "^3.6.1",
"vitest": "^3.2.4"
},
"packageManager": "pnpm@9.4.0"
"packageManager": "pnpm@10.18.1"
}