@embedpdf/models 2.11.1 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/geometry.d.ts +11 -0
- package/dist/image-metadata.d.ts +33 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -1
- package/dist/pdf.d.ts +13 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -322,6 +322,10 @@ function buildUserToDeviceMatrix(rect, rotation, outW, outH) {
|
|
|
322
322
|
return { a: 0, b: sy90, c: -sx90, d: 0, e: sx90 * (B + H), f: -sy90 * L };
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
|
+
function fitSizeWithin(size, bounds) {
|
|
326
|
+
const scale = Math.min(bounds.width / size.width, bounds.height / size.height, 1);
|
|
327
|
+
return { width: size.width * scale, height: size.height * scale };
|
|
328
|
+
}
|
|
325
329
|
class NoopLogger {
|
|
326
330
|
/** {@inheritDoc Logger.isEnabled} */
|
|
327
331
|
isEnabled() {
|
|
@@ -2248,6 +2252,53 @@ class TaskSequence {
|
|
|
2248
2252
|
});
|
|
2249
2253
|
}
|
|
2250
2254
|
}
|
|
2255
|
+
function getImageMetadata(buffer) {
|
|
2256
|
+
if (buffer.byteLength < 4) return null;
|
|
2257
|
+
const bytes = new Uint8Array(buffer);
|
|
2258
|
+
if (bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71) {
|
|
2259
|
+
return parsePng(buffer);
|
|
2260
|
+
}
|
|
2261
|
+
if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) {
|
|
2262
|
+
return parseJpeg(buffer);
|
|
2263
|
+
}
|
|
2264
|
+
if (bytes[0] === 37 && bytes[1] === 80 && bytes[2] === 68 && bytes[3] === 70) {
|
|
2265
|
+
return { mimeType: "application/pdf" };
|
|
2266
|
+
}
|
|
2267
|
+
return null;
|
|
2268
|
+
}
|
|
2269
|
+
function parsePng(buffer) {
|
|
2270
|
+
if (buffer.byteLength < 24) return null;
|
|
2271
|
+
const view = new DataView(buffer);
|
|
2272
|
+
const width = view.getUint32(16);
|
|
2273
|
+
const height = view.getUint32(20);
|
|
2274
|
+
if (width === 0 || height === 0) return null;
|
|
2275
|
+
return { mimeType: "image/png", width, height };
|
|
2276
|
+
}
|
|
2277
|
+
function parseJpeg(buffer) {
|
|
2278
|
+
const bytes = new Uint8Array(buffer);
|
|
2279
|
+
let offset = 2;
|
|
2280
|
+
while (offset + 4 < bytes.byteLength) {
|
|
2281
|
+
if (bytes[offset] !== 255) return null;
|
|
2282
|
+
const marker = bytes[offset + 1];
|
|
2283
|
+
if (marker >= 192 && marker <= 195) {
|
|
2284
|
+
if (offset + 9 > bytes.byteLength) return null;
|
|
2285
|
+
const view = new DataView(buffer, offset + 5);
|
|
2286
|
+
const height = view.getUint16(0);
|
|
2287
|
+
const width = view.getUint16(2);
|
|
2288
|
+
if (width === 0 || height === 0) return null;
|
|
2289
|
+
return { mimeType: "image/jpeg", width, height };
|
|
2290
|
+
}
|
|
2291
|
+
if (marker === 216 || marker === 217) {
|
|
2292
|
+
offset += 2;
|
|
2293
|
+
} else if (marker === 255) {
|
|
2294
|
+
offset += 1;
|
|
2295
|
+
} else {
|
|
2296
|
+
const segLen = bytes[offset + 2] << 8 | bytes[offset + 3];
|
|
2297
|
+
offset += 2 + segLen;
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
return null;
|
|
2301
|
+
}
|
|
2251
2302
|
function ignore() {
|
|
2252
2303
|
}
|
|
2253
2304
|
export {
|
|
@@ -2341,9 +2392,11 @@ export {
|
|
|
2341
2392
|
expandRect,
|
|
2342
2393
|
extractPdfColor,
|
|
2343
2394
|
extractWebOpacity,
|
|
2395
|
+
fitSizeWithin,
|
|
2344
2396
|
flagsToNames,
|
|
2345
2397
|
getBlendModeInfo,
|
|
2346
2398
|
getContrastStrokeColor,
|
|
2399
|
+
getImageMetadata,
|
|
2347
2400
|
getRectCenter,
|
|
2348
2401
|
getStandardFontDescriptor,
|
|
2349
2402
|
getTextAlignmentInfo,
|