pdf-parser.js 4.8.14 → 4.8.16

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.
@@ -3,7 +3,7 @@ const require_objects = require("./objects.cjs");
3
3
  const require_pdf_text = require("./pdf-text.cjs");
4
4
  const require_filters = require("./filters.cjs");
5
5
  const require_names = require("./names.cjs");
6
- const require_util_base64 = require("./util/base64.cjs");
6
+ let byte_codec = require("byte-codec");
7
7
  //#region src/attachments.ts
8
8
  function readAttachments(catalog, pages, resolver, sink) {
9
9
  const attachments = [];
@@ -52,7 +52,7 @@ function readFilespec(name, filespec, resolver, sink) {
52
52
  name,
53
53
  ...descObj?.kind === "string" ? { description: require_pdf_text.decodePdfString(descObj.bytes) } : {},
54
54
  ...subtype !== void 0 ? { mimeType: subtype } : {},
55
- base64: require_util_base64.bytesToBase64(decoded.bytes)
55
+ base64: (0, byte_codec.bytesToBase64)(decoded.bytes)
56
56
  };
57
57
  }
58
58
  sink({
@@ -2,7 +2,7 @@ import { asArray, asName, dictGet } from "./objects.js";
2
2
  import { decodePdfString } from "./pdf-text.js";
3
3
  import { decodeStream } from "./filters.js";
4
4
  import { walkNameTree } from "./names.js";
5
- import { bytesToBase64 } from "./util/base64.js";
5
+ import { bytesToBase64 } from "byte-codec";
6
6
  //#region src/attachments.ts
7
7
  function readAttachments(catalog, pages, resolver, sink) {
8
8
  const attachments = [];
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_util_base64 = require("./util/base64.cjs");
3
2
  const require_sfnt = require("./sfnt.cjs");
4
3
  const require_fonts = require("./fonts.cjs");
5
4
  const require_embedded_font = require("./embedded-font.cjs");
@@ -13,6 +12,7 @@ const require_assets_carlito_italic = require("./assets/carlito-italic.cjs");
13
12
  const require_assets_carlito_regular = require("./assets/carlito-regular.cjs");
14
13
  const require_font_substitutes = require("./font-substitutes.cjs");
15
14
  let fflate = require("fflate");
15
+ let byte_codec = require("byte-codec");
16
16
  //#region src/font-registry.ts
17
17
  function faceCacheKey(family, bold, italic) {
18
18
  return `${require_fonts.normalizeFamilyName(family)}|${bold ? 1 : 0}|${italic ? 1 : 0}`;
@@ -53,7 +53,7 @@ function loadVendoredFaceBytes(family, bold, italic) {
53
53
  const cached = vendoredFaceBytesCache.get(cacheKey);
54
54
  if (cached !== void 0) return cached;
55
55
  const deflatedBase64 = VENDORED_FACE_BASE64[family][faceKey];
56
- const inflated = (0, fflate.inflateSync)(require_util_base64.base64ToBytes(deflatedBase64));
56
+ const inflated = (0, fflate.inflateSync)((0, byte_codec.base64ToBytes)(deflatedBase64));
57
57
  const bytes = new Uint8Array(inflated.length);
58
58
  bytes.set(inflated);
59
59
  vendoredFaceBytesCache.set(cacheKey, bytes);
@@ -1,4 +1,3 @@
1
- import { base64ToBytes } from "./util/base64.js";
2
1
  import { parseSfnt } from "./sfnt.js";
3
2
  import { normalizeFamilyName, resolveStandardFont } from "./fonts.js";
4
3
  import { loadEmbeddedFace } from "./embedded-font.js";
@@ -12,6 +11,7 @@ import { CARLITO_ITALIC_FONT_DEFLATED_BASE64 } from "./assets/carlito-italic.js"
12
11
  import { CARLITO_REGULAR_FONT_DEFLATED_BASE64 } from "./assets/carlito-regular.js";
13
12
  import { resolveVendoredSubstituteFamily } from "./font-substitutes.js";
14
13
  import { inflateSync } from "fflate";
14
+ import { base64ToBytes } from "byte-codec";
15
15
  //#region src/font-registry.ts
16
16
  function faceCacheKey(family, bold, italic) {
17
17
  return `${normalizeFamilyName(family)}|${bold ? 1 : 0}|${italic ? 1 : 0}`;
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_util_base64 = require("./util/base64.cjs");
3
2
  const require_sfnt = require("./sfnt.cjs");
4
3
  const require_cmap_table = require("./cmap-table.cjs");
5
4
  const require_cff_bounds = require("./cff-bounds.cjs");
@@ -7,6 +6,7 @@ const require_hmtx_table = require("./hmtx-table.cjs");
7
6
  const require_assets_stix_two_math_font = require("./assets/stix-two-math-font.cjs");
8
7
  const require_math_stretch = require("./math-stretch.cjs");
9
8
  const require_math_table = require("./math-table.cjs");
9
+ let byte_codec = require("byte-codec");
10
10
  //#region src/math-font.ts
11
11
  function toPt(designUnits, unitsPerEm, sizePt) {
12
12
  return designUnits / unitsPerEm * sizePt;
@@ -116,7 +116,7 @@ function metricsAtSize(cmap, hmtx, math, inkBounds, unitsPerEm, ascentDesignUnit
116
116
  let cached;
117
117
  function loadMathFont() {
118
118
  if (cached !== void 0) return cached;
119
- const bytes = require_util_base64.base64ToBytes(require_assets_stix_two_math_font.STIX_TWO_MATH_FONT_BASE64);
119
+ const bytes = (0, byte_codec.base64ToBytes)(require_assets_stix_two_math_font.STIX_TWO_MATH_FONT_BASE64);
120
120
  const sfnt = require_sfnt.parseSfnt(bytes);
121
121
  if (sfnt === void 0) throw new Error("embedded math font is not a readable sfnt container");
122
122
  const headBytes = require_sfnt.sfntTableBytes(sfnt, "head");
package/dist/math-font.js CHANGED
@@ -1,4 +1,3 @@
1
- import { base64ToBytes } from "./util/base64.js";
2
1
  import { i16, parseSfnt, sfntTableBytes, u16 } from "./sfnt.js";
3
2
  import { buildCmapLookup } from "./cmap-table.js";
4
3
  import { parseCffGlyphBounds } from "./cff-bounds.js";
@@ -6,6 +5,7 @@ import { parseHmtx } from "./hmtx-table.js";
6
5
  import { STIX_TWO_MATH_FONT_BASE64 } from "./assets/stix-two-math-font.js";
7
6
  import { assembleStretchyGlyph, scaleMathStretchConstruction } from "./math-stretch.js";
8
7
  import { parseMathTable } from "./math-table.js";
8
+ import { base64ToBytes } from "byte-codec";
9
9
  //#region src/math-font.ts
10
10
  function toPt(designUnits, unitsPerEm, sizePt) {
11
11
  return designUnits / unitsPerEm * sizePt;
package/dist/read.cjs CHANGED
@@ -7,7 +7,6 @@ const require_serialize = require("./serialize.cjs");
7
7
  const require_matrix = require("./matrix.cjs");
8
8
  const require_annotations = require("./annotations.cjs");
9
9
  const require_filters = require("./filters.cjs");
10
- const require_util_base64 = require("./util/base64.cjs");
11
10
  const require_attachments = require("./attachments.cjs");
12
11
  const require_bytes_crc32 = require("./bytes/crc32.cjs");
13
12
  const require_form = require("./form.cjs");
@@ -22,6 +21,7 @@ const require_font_read = require("./font-read.cjs");
22
21
  const require_images_read = require("./images-read.cjs");
23
22
  const require_interpret = require("./interpret.cjs");
24
23
  const require_navigation = require("./navigation.cjs");
24
+ let byte_codec = require("byte-codec");
25
25
  //#region src/read.ts
26
26
  const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
27
27
  const HEADER_SEARCH_WINDOW = 1024;
@@ -501,13 +501,13 @@ function registerExtractedImage(format, bytes, widthPx, heightPx, images, origin
501
501
  const imageId = `img${require_bytes_crc32.crc32(bytes).toString(16)}`;
502
502
  if (!(imageId in images)) images[imageId] = {
503
503
  format,
504
- base64: require_util_base64.bytesToBase64(bytes),
504
+ base64: (0, byte_codec.bytesToBase64)(bytes),
505
505
  widthPx,
506
506
  heightPx,
507
507
  ...original !== void 0 ? { original: {
508
508
  filter: original.filter,
509
- base64: require_util_base64.bytesToBase64(original.bytes),
510
- ...original.globalsBytes !== void 0 ? { jbig2GlobalsBase64: require_util_base64.bytesToBase64(original.globalsBytes) } : {}
509
+ base64: (0, byte_codec.bytesToBase64)(original.bytes),
510
+ ...original.globalsBytes !== void 0 ? { jbig2GlobalsBase64: (0, byte_codec.bytesToBase64)(original.globalsBytes) } : {}
511
511
  } } : {}
512
512
  };
513
513
  return imageId;
package/dist/read.js CHANGED
@@ -6,7 +6,6 @@ import { serializeObjectToText } from "./serialize.js";
6
6
  import { applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, translationMatrix } from "./matrix.js";
7
7
  import { readPageAnnotations } from "./annotations.js";
8
8
  import { decodeStream } from "./filters.js";
9
- import { bytesToBase64 } from "./util/base64.js";
10
9
  import { readAttachments } from "./attachments.js";
11
10
  import { crc32 } from "./bytes/crc32.js";
12
11
  import { readAcroForm } from "./form.js";
@@ -21,6 +20,7 @@ import { createFontResolver } from "./font-read.js";
21
20
  import { readImageXObject } from "./images-read.js";
22
21
  import { interpretContentStream } from "./interpret.js";
23
22
  import { createDestinationRegistry, readOutline } from "./navigation.js";
23
+ import { bytesToBase64 } from "byte-codec";
24
24
  //#region src/read.ts
25
25
  const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
26
26
  const HEADER_SEARCH_WINDOW = 1024;
package/dist/write.cjs CHANGED
@@ -6,7 +6,6 @@ const require_bytes_writer = require("./bytes/writer.cjs");
6
6
  const require_serialize = require("./serialize.cjs");
7
7
  const require_bytes_reader = require("./bytes/reader.cjs");
8
8
  const require_bytes_flate = require("./bytes/flate.cjs");
9
- const require_util_base64 = require("./util/base64.cjs");
10
9
  const require_parse = require("./parse.cjs");
11
10
  const require_util_abort = require("./util/abort.cjs");
12
11
  const require_crypto_random = require("./crypto/random.cjs");
@@ -23,6 +22,7 @@ const require_math_font = require("./math-font.cjs");
23
22
  const require_math_font_write = require("./math-font-write.cjs");
24
23
  const require_measure = require("./measure.cjs");
25
24
  const require_sfnt_subset = require("./sfnt-subset.cjs");
25
+ let byte_codec = require("byte-codec");
26
26
  //#region src/write.ts
27
27
  const MATH_FONT_RESOURCE_NAME = "MF";
28
28
  const EMBEDDED_FONT_RESOURCE_PREFIX = "E";
@@ -204,7 +204,7 @@ function preparePngImage(bytes, compress) {
204
204
  }
205
205
  function preparePassthroughImage(asset, compress) {
206
206
  if (asset.original === void 0) throw new Error("preparePassthroughImage: asset carries no original stream");
207
- const png = preparePngImage(require_util_base64.base64ToBytes(asset.base64), compress);
207
+ const png = preparePngImage((0, byte_codec.base64ToBytes)(asset.base64), compress);
208
208
  const entries = /* @__PURE__ */ new Map([
209
209
  ["Type", require_objects.pdfName("XObject")],
210
210
  ["Subtype", require_objects.pdfName("Image")],
@@ -218,13 +218,13 @@ function preparePassthroughImage(asset, compress) {
218
218
  }
219
219
  return {
220
220
  dict: require_objects.pdfDict(entries),
221
- raw: require_util_base64.base64ToBytes(asset.original.base64),
221
+ raw: (0, byte_codec.base64ToBytes)(asset.original.base64),
222
222
  ...png.alpha !== void 0 ? { alpha: png.alpha } : {}
223
223
  };
224
224
  }
225
225
  function prepareImage(asset, compress) {
226
226
  if (asset.original !== void 0) return preparePassthroughImage(asset, compress);
227
- const bytes = require_util_base64.base64ToBytes(asset.base64);
227
+ const bytes = (0, byte_codec.base64ToBytes)(asset.base64);
228
228
  return asset.format === "jpeg" ? prepareJpegImage(bytes) : preparePngImage(bytes, compress);
229
229
  }
230
230
  function buildLinkAnnotDict(link) {
@@ -526,7 +526,7 @@ function writePdf(doc, options = {}) {
526
526
  if (attachment.mimeType !== void 0) fileEntries.push(["Subtype", require_objects.pdfName(attachment.mimeType)]);
527
527
  objects.push({
528
528
  num: alloc.fileNum,
529
- value: require_objects.pdfStream(require_objects.pdfDict(Object.fromEntries(fileEntries)), require_util_base64.base64ToBytes(attachment.base64))
529
+ value: require_objects.pdfStream(require_objects.pdfDict(Object.fromEntries(fileEntries)), (0, byte_codec.base64ToBytes)(attachment.base64))
530
530
  });
531
531
  const specEntries = [
532
532
  ["Type", require_objects.pdfName("Filespec")],
@@ -730,7 +730,7 @@ function writePdf(doc, options = {}) {
730
730
  });
731
731
  }
732
732
  if (alloc.globalsNum !== void 0 && alloc.globalsBase64 !== void 0) {
733
- const globalsRaw = require_util_base64.base64ToBytes(alloc.globalsBase64);
733
+ const globalsRaw = (0, byte_codec.base64ToBytes)(alloc.globalsBase64);
734
734
  alloc.prepared.dict.entries.set("DecodeParms", require_objects.pdfDict({ JBIG2Globals: require_objects.pdfRef(alloc.globalsNum, 0) }));
735
735
  objects.push({
736
736
  num: alloc.globalsNum,
package/dist/write.js CHANGED
@@ -5,12 +5,11 @@ import { ByteWriter, concatBytes } from "./bytes/writer.js";
5
5
  import { writeObject } from "./serialize.js";
6
6
  import { ByteReader } from "./bytes/reader.js";
7
7
  import { deflate } from "./bytes/flate.js";
8
- import { base64ToBytes } from "./util/base64.js";
9
8
  import { parseValue } from "./parse.js";
10
9
  import { throwIfAborted } from "./util/abort.js";
11
10
  import { randomBytes } from "./crypto/random.js";
12
11
  import { createStandardEncryptor, encryptIndirectObject } from "./encrypt-write.js";
13
- import { readJpegInfo } from "./image/jpeg-info.js";
12
+ import { readJpegInfo as readJpegInfo$1 } from "./image/jpeg-info.js";
14
13
  import { encodeCcittFax } from "./image/ccitt-encode.js";
15
14
  import { decodePng } from "./image/png-decode.js";
16
15
  import { collectEmbeddedGlyphs } from "./embedded-font.js";
@@ -22,6 +21,7 @@ import { loadMathFont } from "./math-font.js";
22
21
  import { buildMathFontObjects } from "./math-font-write.js";
23
22
  import { createFontMeasurer } from "./measure.js";
24
23
  import { subsetSfnt } from "./sfnt-subset.js";
24
+ import { base64ToBytes } from "byte-codec";
25
25
  //#region src/write.ts
26
26
  const MATH_FONT_RESOURCE_NAME = "MF";
27
27
  const EMBEDDED_FONT_RESOURCE_PREFIX = "E";
@@ -103,7 +103,7 @@ function buildFontObjects(standardName, descriptorRef) {
103
103
  };
104
104
  }
105
105
  function prepareJpegImage(bytes) {
106
- const info = readJpegInfo(bytes);
106
+ const info = readJpegInfo$1(bytes);
107
107
  const colorSpace = info.components === 1 ? "DeviceGray" : info.components === 4 ? "DeviceCMYK" : "DeviceRGB";
108
108
  const entries = /* @__PURE__ */ new Map([
109
109
  ["Type", pdfName("XObject")],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-parser.js",
3
- "version": "4.8.14",
3
+ "version": "4.8.16",
4
4
  "description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -72,7 +72,7 @@
72
72
  ],
73
73
  "license": "MIT",
74
74
  "dependencies": {
75
- "byte-codec": "1.6.0",
75
+ "byte-codec": "1.6.1",
76
76
  "document-schema.js": "7.11.4",
77
77
  "fflate": "0.8.3",
78
78
  "zod": "4.4.3"
@@ -1,48 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/util/base64.ts
3
- const TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4
- const DECODE = (() => {
5
- const map = (/* @__PURE__ */ new Uint8Array(256)).fill(255);
6
- for (let i = 0; i < 64; i = i + 1) map[TABLE.charCodeAt(i)] = i;
7
- return map;
8
- })();
9
- function bytesToBase64(bytes) {
10
- let out = "";
11
- const len = bytes.length;
12
- for (let i = 0; i < len; i = i + 3) {
13
- const b0 = bytes[i];
14
- const b1 = i + 1 < len ? bytes[i + 1] : 0;
15
- const b2 = i + 2 < len ? bytes[i + 2] : 0;
16
- out += TABLE.charAt(b0 >> 2);
17
- out += TABLE.charAt((b0 & 3) << 4 | b1 >> 4);
18
- out += i + 1 < len ? TABLE.charAt((b1 & 15) << 2 | b2 >> 6) : "=";
19
- out += i + 2 < len ? TABLE.charAt(b2 & 63) : "=";
20
- }
21
- return out;
22
- }
23
- function base64ToBytes(b64) {
24
- const clean = b64.replace(/[^A-Za-z0-9+/=]/g, "");
25
- const len = clean.length;
26
- const out = new Uint8Array(len * 3 / 4 | 0);
27
- let p = 0;
28
- for (let i = 0; i < len; i = i + 4) {
29
- const c0 = DECODE[clean.charCodeAt(i)];
30
- const c1 = DECODE[clean.charCodeAt(i + 1)];
31
- const c2 = clean.charCodeAt(i + 2);
32
- const c3 = clean.charCodeAt(i + 3);
33
- if (c0 === 255 || c1 === 255) throw new Error("invalid base64 input");
34
- out[p++] = c0 << 2 | c1 >> 4;
35
- if (c2 !== 61) {
36
- const d2 = DECODE[c2];
37
- out[p++] = (c1 & 15) << 4 | d2 >> 2;
38
- if (c3 !== 61) {
39
- const d3 = DECODE[c3];
40
- out[p++] = (d2 & 3) << 6 | d3;
41
- }
42
- }
43
- }
44
- return out.subarray(0, p);
45
- }
46
- //#endregion
47
- exports.base64ToBytes = base64ToBytes;
48
- exports.bytesToBase64 = bytesToBase64;
@@ -1,5 +0,0 @@
1
- //#region src/util/base64.d.ts
2
- declare function bytesToBase64(bytes: Uint8Array<ArrayBuffer>): string;
3
- declare function base64ToBytes(b64: string): Uint8Array<ArrayBuffer>;
4
- //#endregion
5
- export { base64ToBytes, bytesToBase64 };
@@ -1,5 +0,0 @@
1
- //#region src/util/base64.d.ts
2
- declare function bytesToBase64(bytes: Uint8Array<ArrayBuffer>): string;
3
- declare function base64ToBytes(b64: string): Uint8Array<ArrayBuffer>;
4
- //#endregion
5
- export { base64ToBytes, bytesToBase64 };
@@ -1,46 +0,0 @@
1
- //#region src/util/base64.ts
2
- const TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3
- const DECODE = (() => {
4
- const map = (/* @__PURE__ */ new Uint8Array(256)).fill(255);
5
- for (let i = 0; i < 64; i = i + 1) map[TABLE.charCodeAt(i)] = i;
6
- return map;
7
- })();
8
- function bytesToBase64(bytes) {
9
- let out = "";
10
- const len = bytes.length;
11
- for (let i = 0; i < len; i = i + 3) {
12
- const b0 = bytes[i];
13
- const b1 = i + 1 < len ? bytes[i + 1] : 0;
14
- const b2 = i + 2 < len ? bytes[i + 2] : 0;
15
- out += TABLE.charAt(b0 >> 2);
16
- out += TABLE.charAt((b0 & 3) << 4 | b1 >> 4);
17
- out += i + 1 < len ? TABLE.charAt((b1 & 15) << 2 | b2 >> 6) : "=";
18
- out += i + 2 < len ? TABLE.charAt(b2 & 63) : "=";
19
- }
20
- return out;
21
- }
22
- function base64ToBytes(b64) {
23
- const clean = b64.replace(/[^A-Za-z0-9+/=]/g, "");
24
- const len = clean.length;
25
- const out = new Uint8Array(len * 3 / 4 | 0);
26
- let p = 0;
27
- for (let i = 0; i < len; i = i + 4) {
28
- const c0 = DECODE[clean.charCodeAt(i)];
29
- const c1 = DECODE[clean.charCodeAt(i + 1)];
30
- const c2 = clean.charCodeAt(i + 2);
31
- const c3 = clean.charCodeAt(i + 3);
32
- if (c0 === 255 || c1 === 255) throw new Error("invalid base64 input");
33
- out[p++] = c0 << 2 | c1 >> 4;
34
- if (c2 !== 61) {
35
- const d2 = DECODE[c2];
36
- out[p++] = (c1 & 15) << 4 | d2 >> 2;
37
- if (c3 !== 61) {
38
- const d3 = DECODE[c3];
39
- out[p++] = (d2 & 3) << 6 | d3;
40
- }
41
- }
42
- }
43
- return out.subarray(0, p);
44
- }
45
- //#endregion
46
- export { base64ToBytes, bytesToBase64 };