pdf-codec 3.0.12 → 3.1.1

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/README.md CHANGED
@@ -185,6 +185,14 @@ import { readJpegInfo } from 'pdf-codec/image/jpeg-info';
185
185
 
186
186
  This works via package.json's `"./*"` wildcard export, resolving any `pdf-codec/<path>` subpath to the correspondingly-named file under `dist/` — both ESM `import` and CJS `require` resolve the same way.
187
187
 
188
+ One subpath is a declared entry point in its own right: **`pdf-codec/read`** (an explicit `exports` entry onto `src/read.ts`, the read pipeline's own module). A consumer that only ever reads PDFs and imports the root barrel statically reaches `write.ts`'s module-scope imports — `math-font.ts` (the vendored STIX Two Math font) and `font-registry.ts` (the four Carlito/Caladea faces), together ~2.9 MB of font binaries it can never execute, which on Cloudflare Workers' free plan (3 MB gzipped for an entire Worker) is most of the budget. The read entry's module graph provably excludes them:
189
+
190
+ ```ts
191
+ import { readPdf } from 'pdf-codec/read';
192
+ ```
193
+
194
+ `src/read-graph.test.ts` walks the entry's static import graph and fails the build if `write.ts`, `math-font.ts`, `font-registry.ts`, or any asset module becomes reachable (type-only imports are exempt — they erase at compile time — so a read-side module can keep typing against the root barrel's types while its runtime graph stays narrow). The entry carries `readPdf` and the read pipeline's own helpers (`normalizeRotation`, `pageRotationTransform`, `decodePdfString`, `parsePdfDate`); the other read-adjacent surfaces it does not itself own stay deep-importable through the wildcard and are asset-free the same way — the diagnostics vocabulary (`pdf-codec/diagnostics`), the `LayoutDocument` item family (`pdf-codec/layout`), and standard-14 resolution/AFM metrics (`pdf-codec/fonts`, `pdf-codec/afm-widths`).
195
+
188
196
  ## Architecture
189
197
 
190
198
  The package is layered from generic primitives outward to the codec itself:
package/dist/codec.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_layout = require("./layout.cjs");
3
- const require_write = require("./write.cjs");
4
3
  const require_read = require("./read.cjs");
4
+ const require_write = require("./write.cjs");
5
5
  let zod = require("zod");
6
6
  //#region src/codec.ts
7
7
  const PDF_HEADER = [
package/dist/codec.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LayoutDocumentSchema } from "./layout.js";
2
- import { writePdf } from "./write.js";
3
2
  import { readPdf } from "./read.js";
3
+ import { writePdf } from "./write.js";
4
4
  import { z } from "zod";
5
5
  //#region src/codec.ts
6
6
  const PDF_HEADER = [
package/dist/index.cjs CHANGED
@@ -10,12 +10,12 @@ const require_fonts = require("./fonts.cjs");
10
10
  const require_image_jpeg2000_errors = require("./image/jpeg2000-errors.cjs");
11
11
  const require_image_jp2_boxes = require("./image/jp2-boxes.cjs");
12
12
  const require_image_jpeg2000 = require("./image/jpeg2000.cjs");
13
+ const require_read = require("./read.cjs");
13
14
  const require_font_registry = require("./font-registry.cjs");
14
15
  const require_math_stretch = require("./math-stretch.cjs");
15
16
  const require_math_font = require("./math-font.cjs");
16
17
  const require_measure = require("./measure.cjs");
17
18
  const require_write = require("./write.cjs");
18
- const require_read = require("./read.cjs");
19
19
  const require_codec = require("./codec.cjs");
20
20
  const require_font_face = require("./font-face.cjs");
21
21
  exports.DEFAULT_VERTICAL_METRIC_POLICY = require_measure.DEFAULT_VERTICAL_METRIC_POLICY;
package/dist/index.js CHANGED
@@ -9,12 +9,12 @@ import { resolveStandardFont } from "./fonts.js";
9
9
  import { Jpeg2000ParseError, Jpeg2000UnsupportedError } from "./image/jpeg2000-errors.js";
10
10
  import { looksLikeBareCodestream, parseJp2Container } from "./image/jp2-boxes.js";
11
11
  import { decodeJpeg2000, readJpeg2000Metadata } from "./image/jpeg2000.js";
12
+ import { readPdf } from "./read.js";
12
13
  import { createFontRegistry, resolveFaceWithRegistry } from "./font-registry.js";
13
14
  import { assembleStretchyGlyph, scaleMathStretchConstruction } from "./math-stretch.js";
14
15
  import { loadMathFont } from "./math-font.js";
15
16
  import { DEFAULT_VERTICAL_METRIC_POLICY, createFontMeasurer, createStandardFontMeasurer } from "./measure.js";
16
17
  import { writePdf } from "./write.js";
17
- import { readPdf } from "./read.js";
18
18
  import { PdfBytesSchema, pdfCodec } from "./codec.js";
19
19
  import { FontFaceParseError, readFontFace } from "./font-face.js";
20
20
  export * from "byte-codec";
@@ -0,0 +1,5 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/notes-annotation-author.ts
3
+ const NOTES_ANNOTATION_AUTHOR = "documents.js:notes";
4
+ //#endregion
5
+ exports.NOTES_ANNOTATION_AUTHOR = NOTES_ANNOTATION_AUTHOR;
@@ -0,0 +1,4 @@
1
+ //#region src/notes-annotation-author.d.ts
2
+ declare const NOTES_ANNOTATION_AUTHOR = "documents.js:notes";
3
+ //#endregion
4
+ export { NOTES_ANNOTATION_AUTHOR };
@@ -0,0 +1,4 @@
1
+ //#region src/notes-annotation-author.d.ts
2
+ declare const NOTES_ANNOTATION_AUTHOR = "documents.js:notes";
3
+ //#endregion
4
+ export { NOTES_ANNOTATION_AUTHOR };
@@ -0,0 +1,4 @@
1
+ //#region src/notes-annotation-author.ts
2
+ const NOTES_ANNOTATION_AUTHOR = "documents.js:notes";
3
+ //#endregion
4
+ export { NOTES_ANNOTATION_AUTHOR };
package/dist/read.cjs CHANGED
@@ -12,7 +12,7 @@ const require_font_read = require("./font-read.cjs");
12
12
  const require_images_read = require("./images-read.cjs");
13
13
  const require_matrix = require("./matrix.cjs");
14
14
  const require_interpret = require("./interpret.cjs");
15
- require("./write.cjs");
15
+ require("./notes-annotation-author.cjs");
16
16
  //#region src/read.ts
17
17
  const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
18
18
  const HEADER_SEARCH_WINDOW = 1024;
package/dist/read.js CHANGED
@@ -11,7 +11,7 @@ import { createFontResolver } from "./font-read.js";
11
11
  import { readImageXObject } from "./images-read.js";
12
12
  import { applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, translationMatrix } from "./matrix.js";
13
13
  import { interpretContentStream } from "./interpret.js";
14
- import "./write.js";
14
+ import "./notes-annotation-author.js";
15
15
  //#region src/read.ts
16
16
  const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
17
17
  const HEADER_SEARCH_WINDOW = 1024;
package/dist/write.cjs CHANGED
@@ -6,6 +6,7 @@ const require_objects = require("./objects.cjs");
6
6
  const require_bytes_flate = require("./bytes/flate.cjs");
7
7
  const require_util_abort = require("./util/abort.cjs");
8
8
  const require_image_jpeg_info = require("./image/jpeg-info.cjs");
9
+ const require_notes_annotation_author = require("./notes-annotation-author.cjs");
9
10
  const require_image_png_decode = require("./image/png-decode.cjs");
10
11
  const require_embedded_font = require("./embedded-font.cjs");
11
12
  const require_serialize = require("./serialize.cjs");
@@ -181,7 +182,6 @@ function isLinkItem(item) {
181
182
  return item.kind === "link";
182
183
  }
183
184
  const NOTES_ANNOTATION_HIDDEN_FLAG = 2;
184
- const NOTES_ANNOTATION_AUTHOR = "documents.js:notes";
185
185
  function buildNotesAnnotDict(notes) {
186
186
  return require_objects.pdfDict({
187
187
  Type: require_objects.pdfName("Annot"),
@@ -193,7 +193,7 @@ function buildNotesAnnotDict(notes) {
193
193
  0
194
194
  ].map((n) => require_objects.pdfNum(n))),
195
195
  Contents: textToPdfString(notes),
196
- T: textToPdfString(NOTES_ANNOTATION_AUTHOR),
196
+ T: textToPdfString(require_notes_annotation_author.NOTES_ANNOTATION_AUTHOR),
197
197
  F: require_objects.pdfNum(NOTES_ANNOTATION_HIDDEN_FLAG)
198
198
  });
199
199
  }
@@ -487,5 +487,4 @@ function writePdf(doc, options = {}) {
487
487
  return writer.toBytes();
488
488
  }
489
489
  //#endregion
490
- exports.NOTES_ANNOTATION_AUTHOR = NOTES_ANNOTATION_AUTHOR;
491
490
  exports.writePdf = writePdf;
package/dist/write.d.cts CHANGED
@@ -16,7 +16,6 @@ interface WritePdfOptions {
16
16
  readonly fonts?: FontRegistry;
17
17
  readonly formulas?: readonly PositionedFormula[];
18
18
  }
19
- declare const NOTES_ANNOTATION_AUTHOR = "documents.js:notes";
20
19
  declare function writePdf(doc: LayoutDocument, options?: WritePdfOptions): Uint8Array<ArrayBuffer>;
21
20
  //#endregion
22
- export { NOTES_ANNOTATION_AUTHOR, WritePdfOptions, writePdf };
21
+ export { WritePdfOptions, writePdf };
package/dist/write.d.ts CHANGED
@@ -16,7 +16,6 @@ interface WritePdfOptions {
16
16
  readonly fonts?: FontRegistry;
17
17
  readonly formulas?: readonly PositionedFormula[];
18
18
  }
19
- declare const NOTES_ANNOTATION_AUTHOR = "documents.js:notes";
20
19
  declare function writePdf(doc: LayoutDocument, options?: WritePdfOptions): Uint8Array<ArrayBuffer>;
21
20
  //#endregion
22
- export { NOTES_ANNOTATION_AUTHOR, WritePdfOptions, writePdf };
21
+ export { WritePdfOptions, writePdf };
package/dist/write.js CHANGED
@@ -5,6 +5,7 @@ import { pdfArray, pdfDict, pdfHexString, pdfName, pdfNum, pdfRef, pdfStream } f
5
5
  import { deflate } from "./bytes/flate.js";
6
6
  import { throwIfAborted } from "./util/abort.js";
7
7
  import { readJpegInfo } from "./image/jpeg-info.js";
8
+ import { NOTES_ANNOTATION_AUTHOR } from "./notes-annotation-author.js";
8
9
  import { decodePng } from "./image/png-decode.js";
9
10
  import { collectEmbeddedGlyphs } from "./embedded-font.js";
10
11
  import { writeObject } from "./serialize.js";
@@ -180,7 +181,6 @@ function isLinkItem(item) {
180
181
  return item.kind === "link";
181
182
  }
182
183
  const NOTES_ANNOTATION_HIDDEN_FLAG = 2;
183
- const NOTES_ANNOTATION_AUTHOR = "documents.js:notes";
184
184
  function buildNotesAnnotDict(notes) {
185
185
  return pdfDict({
186
186
  Type: pdfName("Annot"),
@@ -486,4 +486,4 @@ function writePdf(doc, options = {}) {
486
486
  return writer.toBytes();
487
487
  }
488
488
  //#endregion
489
- export { NOTES_ANNOTATION_AUTHOR, writePdf };
489
+ export { writePdf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-codec",
3
- "version": "3.0.12",
3
+ "version": "3.1.1",
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": {
@@ -21,6 +21,14 @@
21
21
  "import": "./dist/index.js",
22
22
  "require": "./dist/index.cjs"
23
23
  },
24
+ "./read": {
25
+ "types": {
26
+ "import": "./dist/read.d.ts",
27
+ "require": "./dist/read.d.cts"
28
+ },
29
+ "import": "./dist/read.js",
30
+ "require": "./dist/read.cjs"
31
+ },
24
32
  "./*": {
25
33
  "types": {
26
34
  "import": "./dist/*.d.ts",
@@ -33,6 +41,13 @@
33
41
  "main": "./dist/index.cjs",
34
42
  "module": "./dist/index.js",
35
43
  "types": "./dist/index.d.ts",
44
+ "typesVersions": {
45
+ "*": {
46
+ "read": [
47
+ "./dist/read.d.ts"
48
+ ]
49
+ }
50
+ },
36
51
  "files": [
37
52
  "dist"
38
53
  ],
@@ -83,7 +98,7 @@
83
98
  "packageManager": "pnpm@11.6.0",
84
99
  "dependencies": {
85
100
  "byte-codec": "^1.1.13",
86
- "document-schema.js": "^4.3.7",
101
+ "document-schema.js": "^4.5.0",
87
102
  "fflate": "^0.8.3",
88
103
  "zod": "^4.4.3"
89
104
  },