pdf-codec 3.3.0 → 3.4.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/README.md CHANGED
@@ -214,7 +214,7 @@ The package is layered from generic primitives outward to the codec itself:
214
214
  - **Embedded text faces**: `embedded-font.ts` (parses one TrueType-outline face's metrics and `GPOS` pair kerning, and `encodeForShowEmbedded` — the single code path both measurement and text-showing go through so encoding and measuring cannot disagree). Every geometry field is converted into PDF's 1000-units-per-em glyph space. `embedded-font-write.ts` builds the `/Type0`/`/CIDFontType2`/`/FontDescriptor`/`/FontFile2`/ToUnicode group, with `/CIDToGIDMap /Identity` written explicitly and `/Length1` set to the **uncompressed** subset length. Its subset tag is a CRC32 over the face's PostScript name and glyph-ID list, so identical input yields byte-identical output.
215
215
  - **ToUnicode CMaps**: `tounicode.ts`, shared by both embedded-font writers — a character code → Unicode code point mapping written as a bfchar CMap (9.10.3), with supplementary-plane code points encoded as UTF-16BE surrogate pairs and entries emitted in blocks of at most 100.
216
216
  - **CFF reading**: `cff.ts` (shared `INDEX`/`DICT` container structures), `cff-bounds.ts` (a Type 2 charstring interpreter computing each glyph's tight ink bounding box by tracking the current point through every path operator and solving each cubic's real extrema from the roots of its derivative — a path walker, not a rasteriser; verified against the vendored STIX Two Math font's whole 5,543-glyph repertoire, matching fontTools' `BoundsPen` to within 0.01 design units). `cff-probe.ts` reads a bare CFF program's header/Name INDEX/Top DICT to detect the `ROS` operator defining a CID-keyed font — the guard a future source-embedded-font phase needs before it can trust CID == GID against an arbitrary caller-supplied font.
217
- - **Read**: `lexer.ts`/`parse.ts` (byte tokenizer and tokens → `PdfObject`), `filters.ts`/`predictors.ts` (Flate/LZW/ASCII85/ASCIIHex/RunLength/CCITTFax, TIFF/PNG predictors), `xref.ts`/`document.ts` (classic and cross-reference-stream resolution, object streams, `/Prev` chains, linear-scan recovery, the page tree with attribute inheritance), `encrypt.ts` (standard security handler: `/Encrypt` parsing, empty-user-password key derivation and `/U` verification, per-object keys, transparent string/stream decryption), `content-read.ts`/`interpret.ts` (content-stream tokenizer and graphics/text state machine, form-XObject recursion, general vector-path tracking), `cmap.ts`/`font-style.ts`/`font-read.ts` (`/ToUnicode` CMaps, font-dictionary resolution), `images-read.ts` (Image XObjects → PNG/JPEG bytes), `names.ts` (the document-level name-tree walker: one flattening pass for every `/Names` tenant), `navigation.ts` (named destinations from `/Dests` and `/Names` `/Dests`, reader-minted entries for direct destination arrays, and the `/Outlines` bookmark tree), `attachments.ts` (embedded files from the name tree, `/FileAttachment` filespecs, and `/AF`), `optional-content.ts` (`/OCProperties` groups and default-configuration visibility, plus the `/OC`-to-name resolution `interpret.ts` stamps onto span items), `annotations.ts` (sticky notes, FreeText, the `/QuadPoints` markup family, and residue for the opaque kinds), `form.ts` (the AcroForm field tree), `xmp.ts` (a bounded Dublin Core extractor for the `/Metadata` packet), `pdf-text.ts` (PDF string/date scalar decoding), `read.ts` (`readPdf`, assembling all of the above into a `LayoutDocument`).
217
+ - **Read**: `lexer.ts`/`parse.ts` (byte tokenizer and tokens → `PdfObject`), `filters.ts`/`predictors.ts` (Flate/LZW/ASCII85/ASCIIHex/RunLength/CCITTFax, TIFF/PNG predictors), `xref.ts`/`document.ts` (classic and cross-reference-stream resolution, object streams, `/Prev` chains, linear-scan recovery, the page tree with attribute inheritance), `encrypt.ts` (standard security handler: `/Encrypt` parsing, empty-user-password key derivation and `/U` verification, per-object keys, transparent string/stream decryption), `content-read.ts`/`interpret.ts` (content-stream tokenizer and graphics/text state machine, form-XObject recursion, general vector-path tracking), `cmap.ts`/`font-style.ts`/`font-read.ts` (`/ToUnicode` CMaps, font-dictionary resolution), `images-read.ts` (Image XObjects → PNG/JPEG bytes), `names.ts` (the document-level name-tree walker: one flattening pass for every `/Names` tenant), `navigation.ts` (named destinations from `/Dests` and `/Names` `/Dests`, reader-minted entries for direct destination arrays, and the `/Outlines` bookmark tree), `attachments.ts` (embedded files from the name tree, `/FileAttachment` filespecs, and `/AF`), `optional-content.ts` (`/OCProperties` groups and default-configuration visibility, plus the `/OC`-to-name resolution `interpret.ts` stamps onto span items), `annotations.ts` (sticky notes, FreeText, the `/QuadPoints` markup family, and residue for the opaque kinds), `form.ts` (the AcroForm field tree), `structure.ts` (the tagged-PDF `/StructTreeRoot` element tree with `/RoleMap` resolution and `/ClassMap` attribute merging, plus the `/ParentTree` walk that resolves each `(page, MCID)` pair to the owning element `read.ts` stamps onto an item), `xmp.ts` (a bounded Dublin Core extractor for the `/Metadata` packet), `pdf-text.ts` (PDF string/date scalar decoding), `read.ts` (`readPdf`, assembling all of the above into a `LayoutDocument`).
218
218
  - `codec.ts` — `pdfCodec`, a `z.codec()` pair over `readPdf`/`writePdf`, plus a standalone local copy of the `%PDF-` header check.
219
219
  - **`src/test-support/`** — hand-built PDF fixtures (`pdf.ts`) built by literal byte/string concatenation and deliberately importing NOTHING from this package's own writer (a fixture built by `writePdf` would let a writer bug hide from the corresponding reader test). `encrypted-pdfs.ts` applies the same principle: real PDFs encrypted by [qpdf](https://qpdf.sourceforge.io/), embedded as base64, so a bug in key derivation cannot cancel out between write and read halves. `fonts.ts` holds the real vendored Carlito and Caladea faces as raw sfnt bytes, and asserts values read out of the `.ttf` files by a standalone script with a bare `DataView`, not by this package's own parsers — external cross-checks rather than a parser's output compared against itself.
220
220
 
package/dist/codec.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { LayoutFormField, LayoutOutlineItem } from "./layout.cjs";
1
+ import { LayoutFormField, LayoutOutlineItem, LayoutStructureElement } from "./layout.cjs";
2
2
  import { z } from "zod";
3
3
  //#region src/codec.d.ts
4
4
  declare const PdfBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
@@ -46,6 +46,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
46
46
  layer: z.ZodOptional<z.ZodString>;
47
47
  actualText: z.ZodOptional<z.ZodString>;
48
48
  alt: z.ZodOptional<z.ZodString>;
49
+ structure: z.ZodOptional<z.ZodString>;
49
50
  sourcePath: z.ZodOptional<z.ZodString>;
50
51
  }, z.core.$strip>, z.ZodObject<{
51
52
  kind: z.ZodLiteral<"image">;
@@ -56,6 +57,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
56
57
  heightPt: z.ZodNumber;
57
58
  rotationDeg: z.ZodOptional<z.ZodNumber>;
58
59
  layer: z.ZodOptional<z.ZodString>;
60
+ structure: z.ZodOptional<z.ZodString>;
59
61
  sourcePath: z.ZodOptional<z.ZodString>;
60
62
  }, z.core.$strip>, z.ZodObject<{
61
63
  kind: z.ZodLiteral<"rect">;
@@ -77,6 +79,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
77
79
  widthPt: z.ZodNumber;
78
80
  }, z.core.$strip>>;
79
81
  layer: z.ZodOptional<z.ZodString>;
82
+ structure: z.ZodOptional<z.ZodString>;
80
83
  sourcePath: z.ZodOptional<z.ZodString>;
81
84
  }, z.core.$strip>, z.ZodObject<{
82
85
  kind: z.ZodLiteral<"line">;
@@ -97,6 +100,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
97
100
  double: "double";
98
101
  }>>;
99
102
  layer: z.ZodOptional<z.ZodString>;
103
+ structure: z.ZodOptional<z.ZodString>;
100
104
  sourcePath: z.ZodOptional<z.ZodString>;
101
105
  }, z.core.$strip>, z.ZodObject<{
102
106
  kind: z.ZodLiteral<"ellipse">;
@@ -118,6 +122,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
118
122
  widthPt: z.ZodNumber;
119
123
  }, z.core.$strip>>;
120
124
  layer: z.ZodOptional<z.ZodString>;
125
+ structure: z.ZodOptional<z.ZodString>;
121
126
  sourcePath: z.ZodOptional<z.ZodString>;
122
127
  }, z.core.$strip>, z.ZodObject<{
123
128
  kind: z.ZodLiteral<"path">;
@@ -163,6 +168,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
163
168
  double: "double";
164
169
  }>>;
165
170
  layer: z.ZodOptional<z.ZodString>;
171
+ structure: z.ZodOptional<z.ZodString>;
166
172
  sourcePath: z.ZodOptional<z.ZodString>;
167
173
  }, z.core.$strip>, z.ZodObject<{
168
174
  kind: z.ZodLiteral<"link">;
@@ -265,6 +271,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
265
271
  name: z.ZodString;
266
272
  visible: z.ZodBoolean;
267
273
  }, z.core.$strip>>>;
274
+ structure: z.ZodOptional<z.ZodArray<z.ZodType<LayoutStructureElement, LayoutStructureElement, z.core.$ZodTypeInternals<LayoutStructureElement, LayoutStructureElement>>>>;
268
275
  form: z.ZodOptional<z.ZodArray<z.ZodType<LayoutFormField, LayoutFormField, z.core.$ZodTypeInternals<LayoutFormField, LayoutFormField>>>>;
269
276
  source: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
270
277
  format: z.ZodEnum<{
package/dist/codec.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LayoutFormField, LayoutOutlineItem } from "./layout.js";
1
+ import { LayoutFormField, LayoutOutlineItem, LayoutStructureElement } from "./layout.js";
2
2
  import { z } from "zod";
3
3
  //#region src/codec.d.ts
4
4
  declare const PdfBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
@@ -46,6 +46,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
46
46
  layer: z.ZodOptional<z.ZodString>;
47
47
  actualText: z.ZodOptional<z.ZodString>;
48
48
  alt: z.ZodOptional<z.ZodString>;
49
+ structure: z.ZodOptional<z.ZodString>;
49
50
  sourcePath: z.ZodOptional<z.ZodString>;
50
51
  }, z.core.$strip>, z.ZodObject<{
51
52
  kind: z.ZodLiteral<"image">;
@@ -56,6 +57,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
56
57
  heightPt: z.ZodNumber;
57
58
  rotationDeg: z.ZodOptional<z.ZodNumber>;
58
59
  layer: z.ZodOptional<z.ZodString>;
60
+ structure: z.ZodOptional<z.ZodString>;
59
61
  sourcePath: z.ZodOptional<z.ZodString>;
60
62
  }, z.core.$strip>, z.ZodObject<{
61
63
  kind: z.ZodLiteral<"rect">;
@@ -77,6 +79,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
77
79
  widthPt: z.ZodNumber;
78
80
  }, z.core.$strip>>;
79
81
  layer: z.ZodOptional<z.ZodString>;
82
+ structure: z.ZodOptional<z.ZodString>;
80
83
  sourcePath: z.ZodOptional<z.ZodString>;
81
84
  }, z.core.$strip>, z.ZodObject<{
82
85
  kind: z.ZodLiteral<"line">;
@@ -97,6 +100,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
97
100
  double: "double";
98
101
  }>>;
99
102
  layer: z.ZodOptional<z.ZodString>;
103
+ structure: z.ZodOptional<z.ZodString>;
100
104
  sourcePath: z.ZodOptional<z.ZodString>;
101
105
  }, z.core.$strip>, z.ZodObject<{
102
106
  kind: z.ZodLiteral<"ellipse">;
@@ -118,6 +122,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
118
122
  widthPt: z.ZodNumber;
119
123
  }, z.core.$strip>>;
120
124
  layer: z.ZodOptional<z.ZodString>;
125
+ structure: z.ZodOptional<z.ZodString>;
121
126
  sourcePath: z.ZodOptional<z.ZodString>;
122
127
  }, z.core.$strip>, z.ZodObject<{
123
128
  kind: z.ZodLiteral<"path">;
@@ -163,6 +168,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
163
168
  double: "double";
164
169
  }>>;
165
170
  layer: z.ZodOptional<z.ZodString>;
171
+ structure: z.ZodOptional<z.ZodString>;
166
172
  sourcePath: z.ZodOptional<z.ZodString>;
167
173
  }, z.core.$strip>, z.ZodObject<{
168
174
  kind: z.ZodLiteral<"link">;
@@ -265,6 +271,7 @@ declare const pdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Arr
265
271
  name: z.ZodString;
266
272
  visible: z.ZodBoolean;
267
273
  }, z.core.$strip>>>;
274
+ structure: z.ZodOptional<z.ZodArray<z.ZodType<LayoutStructureElement, LayoutStructureElement, z.core.$ZodTypeInternals<LayoutStructureElement, LayoutStructureElement>>>>;
268
275
  form: z.ZodOptional<z.ZodArray<z.ZodType<LayoutFormField, LayoutFormField, z.core.$ZodTypeInternals<LayoutFormField, LayoutFormField>>>>;
269
276
  source: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
270
277
  format: z.ZodEnum<{
package/dist/index.cjs CHANGED
@@ -46,6 +46,7 @@ exports.LayoutPageSchema = require_layout.LayoutPageSchema;
46
46
  exports.LayoutPathSchema = require_layout.LayoutPathSchema;
47
47
  exports.LayoutPathSegmentSchema = require_layout.LayoutPathSegmentSchema;
48
48
  exports.LayoutRectSchema = require_layout.LayoutRectSchema;
49
+ exports.LayoutStructureElementSchema = require_layout.LayoutStructureElementSchema;
49
50
  exports.LayoutSubpathSchema = require_layout.LayoutSubpathSchema;
50
51
  exports.LayoutTextSchema = require_layout.LayoutTextSchema;
51
52
  exports.NOOP_DIAGNOSTIC_SINK = require_diagnostics.NOOP_DIAGNOSTIC_SINK;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-DyDq56Ph.cjs";
2
2
  import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.cjs";
3
- import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.cjs";
3
+ import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.cjs";
4
4
  import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
5
5
  import { PdfBytesSchema, pdfCodec } from "./codec.cjs";
6
6
  import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-BU6Jgcof.cjs";
@@ -24,4 +24,4 @@ import { LoadedMathFont, MathFont, MathFontDescriptorMetrics, loadMathFont } fro
24
24
  import { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer } from "./measure.cjs";
25
25
  import { FontRegistryOptions, FontSubstitution, MathAssembledGlyphs, MathBox, MathColor, MathFontMetrics, MathGlyphMetrics, MathGlyphPlacement, MathGlyphRun, MathLayoutItem, MathRule, MathStretchAxis, MathStretchGlyph, MathStretchResult, MathStroke, Point, PositionedFormula, ProvidedFont, StyledFragment, StyledRun, TextMeasurer, UnderlineMetrics, WrapOptions, WrappedLine } from "document-schema.js";
26
26
  export * from "byte-codec";
27
- export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
27
+ export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-DyDq56Ph.js";
2
2
  import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
3
- import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.js";
3
+ import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.js";
4
4
  import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
5
5
  import { PdfBytesSchema, pdfCodec } from "./codec.js";
6
6
  import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-fREdbxnr.js";
@@ -24,4 +24,4 @@ import { LoadedMathFont, MathFont, MathFontDescriptorMetrics, loadMathFont } fro
24
24
  import { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer } from "./measure.js";
25
25
  import { FontRegistryOptions, FontSubstitution, MathAssembledGlyphs, MathBox, MathColor, MathFontMetrics, MathGlyphMetrics, MathGlyphPlacement, MathGlyphRun, MathLayoutItem, MathRule, MathStretchAxis, MathStretchGlyph, MathStretchResult, MathStroke, Point, PositionedFormula, ProvidedFont, StyledFragment, StyledRun, TextMeasurer, UnderlineMetrics, WrapOptions, WrappedLine } from "document-schema.js";
26
26
  export * from "byte-codec";
27
- export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
27
+ export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { decodeCcittFax } from "./image/ccitt.js";
3
3
  import { Jbig2ParseError, Jbig2UnsupportedError } from "./image/jbig2-errors.js";
4
4
  import { decodeJbig2Embedded } from "./image/jbig2.js";
5
5
  import { filterScanlines, unfilterScanlines } from "./image/png-filter.js";
6
- import { LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema } from "./layout.js";
6
+ import { LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutStructureElementSchema, LayoutSubpathSchema, LayoutTextSchema } from "./layout.js";
7
7
  import { NOOP_DIAGNOSTIC_SINK, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
8
8
  import { resolveStandardFont } from "./fonts.js";
9
9
  import { Jpeg2000ParseError, Jpeg2000UnsupportedError } from "./image/jpeg2000-errors.js";
@@ -18,4 +18,4 @@ import { writePdf } from "./write.js";
18
18
  import { PdfBytesSchema, pdfCodec } from "./codec.js";
19
19
  import { FontFaceParseError, readFontFace } from "./font-face.js";
20
20
  export * from "byte-codec";
21
- export { DEFAULT_VERTICAL_METRIC_POLICY, FontFaceParseError, Jbig2ParseError, Jbig2UnsupportedError, Jpeg2000ParseError, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, STANDARD_METRICS, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
21
+ export { DEFAULT_VERTICAL_METRIC_POLICY, FontFaceParseError, Jbig2ParseError, Jbig2UnsupportedError, Jpeg2000ParseError, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutStructureElementSchema, LayoutSubpathSchema, LayoutTextSchema, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, STANDARD_METRICS, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
@@ -43,13 +43,15 @@ function markedContentProperties(operand, resources, resolver) {
43
43
  return properties === void 0 ? void 0 : resolver.resolveDict(require_objects.dictGet(properties, operand.name));
44
44
  }
45
45
  }
46
- function markedContentStrings(props) {
46
+ function markedContentScopeProps(props) {
47
47
  if (props === void 0) return {};
48
48
  const actualTextObj = require_objects.dictGet(props, "ActualText");
49
49
  const altObj = require_objects.dictGet(props, "Alt");
50
+ const mcid = require_objects.asNumber(require_objects.dictGet(props, "MCID"));
50
51
  return {
51
52
  ...actualTextObj?.kind === "string" ? { actualText: require_pdf_text.decodePdfString(actualTextObj.bytes) } : {},
52
- ...altObj?.kind === "string" ? { alt: require_pdf_text.decodePdfString(altObj.bytes) } : {}
53
+ ...altObj?.kind === "string" ? { alt: require_pdf_text.decodePdfString(altObj.bytes) } : {},
54
+ ...mcid !== void 0 && mcid >= 0 ? { mcid } : {}
53
55
  };
54
56
  }
55
57
  function grayColor(value) {
@@ -292,8 +294,8 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
292
294
  let currentSubpath;
293
295
  const inScope = (key) => {
294
296
  for (let i = markedContent.length - 1; i >= 0; i--) {
295
- const value = markedContent[i]?.[key];
296
- if (value !== void 0) return value;
297
+ const frame = markedContent[i];
298
+ if (frame !== void 0 && key in frame) return frame[key];
297
299
  }
298
300
  };
299
301
  const pushItem = (item) => {
@@ -301,18 +303,25 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
301
303
  const layer = item.layerName ?? inScope("layerName");
302
304
  const actualText = inScope("actualText");
303
305
  const alt = inScope("alt");
306
+ const mcid = inScope("mcid");
304
307
  items.push({
305
308
  ...item,
306
309
  ...layer !== void 0 ? { layerName: layer } : {},
307
310
  ...actualText !== void 0 ? { actualText } : {},
308
- ...alt !== void 0 ? { alt } : {}
311
+ ...alt !== void 0 ? { alt } : {},
312
+ ...mcid !== void 0 ? { mcid } : {}
309
313
  });
310
314
  return;
311
315
  }
312
316
  const layer = item.layerName ?? inScope("layerName");
313
- items.push(layer === void 0 ? item : {
317
+ const layerStamped = layer === void 0 ? item : {
314
318
  ...item,
315
319
  layerName: layer
320
+ };
321
+ const mcid = inScope("mcid");
322
+ items.push(mcid === void 0 ? layerStamped : {
323
+ ...layerStamped,
324
+ mcid
316
325
  });
317
326
  };
318
327
  const finalizeCurrentSubpath = () => {
@@ -500,7 +509,11 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
500
509
  ctm: require_matrix.multiplyMatrices(formMatrix, gs.ctm)
501
510
  };
502
511
  const formLayer = ownLayer ?? inScope("layerName");
503
- runContentStream(decoded.bytes, formResources, formState, context, items, depth + 1, [formLayer !== void 0 ? { layerName: formLayer } : {}]);
512
+ const formMcid = require_objects.dictGet(xobj.dict, "StructParents") !== void 0 ? void 0 : inScope("mcid");
513
+ runContentStream(decoded.bytes, formResources, formState, context, items, depth + 1, [{
514
+ ...formLayer !== void 0 ? { layerName: formLayer } : {},
515
+ ...formMcid !== void 0 ? { mcid: formMcid } : {}
516
+ }]);
504
517
  }
505
518
  };
506
519
  for (const token of operations) {
@@ -765,9 +778,13 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
765
778
  case "BDC": {
766
779
  const props = markedContentProperties(operands[1], resources, context.resolver);
767
780
  const layerName = context.layerNameOf?.(props === void 0 ? void 0 : require_objects.dictGet(props, "OC"));
768
- markedContent.push({
781
+ const scopeProps = {
769
782
  ...layerName !== void 0 ? { layerName } : {},
770
- ...markedContentStrings(props)
783
+ ...markedContentScopeProps(props)
784
+ };
785
+ markedContent.push(depth === 0 ? scopeProps : {
786
+ ...scopeProps,
787
+ mcid: void 0
771
788
  });
772
789
  break;
773
790
  }
@@ -15,6 +15,7 @@ interface ExtractedTextRun {
15
15
  readonly layerName?: string;
16
16
  readonly actualText?: string;
17
17
  readonly alt?: string;
18
+ readonly mcid?: number;
18
19
  }
19
20
  interface ExtractedPaint {
20
21
  readonly fill: Color | undefined;
@@ -23,6 +24,7 @@ interface ExtractedPaint {
23
24
  readonly widthPt: number;
24
25
  } | undefined;
25
26
  readonly layerName?: string;
27
+ readonly mcid?: number;
26
28
  }
27
29
  interface ExtractedRect extends ExtractedPaint {
28
30
  readonly kind: 'rect';
@@ -47,6 +49,7 @@ interface ExtractedLine {
47
49
  readonly color: Color;
48
50
  readonly widthPt: number;
49
51
  readonly layerName?: string;
52
+ readonly mcid?: number;
50
53
  }
51
54
  type ExtractedPathSegment = {
52
55
  readonly kind: 'line';
@@ -78,6 +81,7 @@ interface ExtractedImage {
78
81
  readonly resources: PdfDict;
79
82
  readonly matrix: Matrix;
80
83
  readonly layerName?: string;
84
+ readonly mcid?: number;
81
85
  }
82
86
  interface ExtractedInlineImage {
83
87
  readonly kind: 'inlineImage';
@@ -85,6 +89,7 @@ interface ExtractedInlineImage {
85
89
  readonly data: Uint8Array<ArrayBuffer>;
86
90
  readonly matrix: Matrix;
87
91
  readonly layerName?: string;
92
+ readonly mcid?: number;
88
93
  }
89
94
  type ExtractedItem = ExtractedTextRun | ExtractedRect | ExtractedEllipse | ExtractedLine | ExtractedPath | ExtractedImage | ExtractedInlineImage;
90
95
  interface GlyphAdvance {
@@ -15,6 +15,7 @@ interface ExtractedTextRun {
15
15
  readonly layerName?: string;
16
16
  readonly actualText?: string;
17
17
  readonly alt?: string;
18
+ readonly mcid?: number;
18
19
  }
19
20
  interface ExtractedPaint {
20
21
  readonly fill: Color | undefined;
@@ -23,6 +24,7 @@ interface ExtractedPaint {
23
24
  readonly widthPt: number;
24
25
  } | undefined;
25
26
  readonly layerName?: string;
27
+ readonly mcid?: number;
26
28
  }
27
29
  interface ExtractedRect extends ExtractedPaint {
28
30
  readonly kind: 'rect';
@@ -47,6 +49,7 @@ interface ExtractedLine {
47
49
  readonly color: Color;
48
50
  readonly widthPt: number;
49
51
  readonly layerName?: string;
52
+ readonly mcid?: number;
50
53
  }
51
54
  type ExtractedPathSegment = {
52
55
  readonly kind: 'line';
@@ -78,6 +81,7 @@ interface ExtractedImage {
78
81
  readonly resources: PdfDict;
79
82
  readonly matrix: Matrix;
80
83
  readonly layerName?: string;
84
+ readonly mcid?: number;
81
85
  }
82
86
  interface ExtractedInlineImage {
83
87
  readonly kind: 'inlineImage';
@@ -85,6 +89,7 @@ interface ExtractedInlineImage {
85
89
  readonly data: Uint8Array<ArrayBuffer>;
86
90
  readonly matrix: Matrix;
87
91
  readonly layerName?: string;
92
+ readonly mcid?: number;
88
93
  }
89
94
  type ExtractedItem = ExtractedTextRun | ExtractedRect | ExtractedEllipse | ExtractedLine | ExtractedPath | ExtractedImage | ExtractedInlineImage;
90
95
  interface GlyphAdvance {
package/dist/interpret.js CHANGED
@@ -42,13 +42,15 @@ function markedContentProperties(operand, resources, resolver) {
42
42
  return properties === void 0 ? void 0 : resolver.resolveDict(dictGet(properties, operand.name));
43
43
  }
44
44
  }
45
- function markedContentStrings(props) {
45
+ function markedContentScopeProps(props) {
46
46
  if (props === void 0) return {};
47
47
  const actualTextObj = dictGet(props, "ActualText");
48
48
  const altObj = dictGet(props, "Alt");
49
+ const mcid = asNumber(dictGet(props, "MCID"));
49
50
  return {
50
51
  ...actualTextObj?.kind === "string" ? { actualText: decodePdfString(actualTextObj.bytes) } : {},
51
- ...altObj?.kind === "string" ? { alt: decodePdfString(altObj.bytes) } : {}
52
+ ...altObj?.kind === "string" ? { alt: decodePdfString(altObj.bytes) } : {},
53
+ ...mcid !== void 0 && mcid >= 0 ? { mcid } : {}
52
54
  };
53
55
  }
54
56
  function grayColor(value) {
@@ -291,8 +293,8 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
291
293
  let currentSubpath;
292
294
  const inScope = (key) => {
293
295
  for (let i = markedContent.length - 1; i >= 0; i--) {
294
- const value = markedContent[i]?.[key];
295
- if (value !== void 0) return value;
296
+ const frame = markedContent[i];
297
+ if (frame !== void 0 && key in frame) return frame[key];
296
298
  }
297
299
  };
298
300
  const pushItem = (item) => {
@@ -300,18 +302,25 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
300
302
  const layer = item.layerName ?? inScope("layerName");
301
303
  const actualText = inScope("actualText");
302
304
  const alt = inScope("alt");
305
+ const mcid = inScope("mcid");
303
306
  items.push({
304
307
  ...item,
305
308
  ...layer !== void 0 ? { layerName: layer } : {},
306
309
  ...actualText !== void 0 ? { actualText } : {},
307
- ...alt !== void 0 ? { alt } : {}
310
+ ...alt !== void 0 ? { alt } : {},
311
+ ...mcid !== void 0 ? { mcid } : {}
308
312
  });
309
313
  return;
310
314
  }
311
315
  const layer = item.layerName ?? inScope("layerName");
312
- items.push(layer === void 0 ? item : {
316
+ const layerStamped = layer === void 0 ? item : {
313
317
  ...item,
314
318
  layerName: layer
319
+ };
320
+ const mcid = inScope("mcid");
321
+ items.push(mcid === void 0 ? layerStamped : {
322
+ ...layerStamped,
323
+ mcid
315
324
  });
316
325
  };
317
326
  const finalizeCurrentSubpath = () => {
@@ -499,7 +508,11 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
499
508
  ctm: multiplyMatrices(formMatrix, gs.ctm)
500
509
  };
501
510
  const formLayer = ownLayer ?? inScope("layerName");
502
- runContentStream(decoded.bytes, formResources, formState, context, items, depth + 1, [formLayer !== void 0 ? { layerName: formLayer } : {}]);
511
+ const formMcid = dictGet(xobj.dict, "StructParents") !== void 0 ? void 0 : inScope("mcid");
512
+ runContentStream(decoded.bytes, formResources, formState, context, items, depth + 1, [{
513
+ ...formLayer !== void 0 ? { layerName: formLayer } : {},
514
+ ...formMcid !== void 0 ? { mcid: formMcid } : {}
515
+ }]);
503
516
  }
504
517
  };
505
518
  for (const token of operations) {
@@ -764,9 +777,13 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
764
777
  case "BDC": {
765
778
  const props = markedContentProperties(operands[1], resources, context.resolver);
766
779
  const layerName = context.layerNameOf?.(props === void 0 ? void 0 : dictGet(props, "OC"));
767
- markedContent.push({
780
+ const scopeProps = {
768
781
  ...layerName !== void 0 ? { layerName } : {},
769
- ...markedContentStrings(props)
782
+ ...markedContentScopeProps(props)
783
+ };
784
+ markedContent.push(depth === 0 ? scopeProps : {
785
+ ...scopeProps,
786
+ mcid: void 0
770
787
  });
771
788
  break;
772
789
  }
package/dist/layout.cjs CHANGED
@@ -17,6 +17,7 @@ const LayoutTextSchema = zod.z.object({
17
17
  layer: zod.z.string().optional(),
18
18
  actualText: zod.z.string().optional(),
19
19
  alt: zod.z.string().optional(),
20
+ structure: zod.z.string().optional(),
20
21
  sourcePath: zod.z.string().optional()
21
22
  });
22
23
  const LayoutImageSchema = zod.z.object({
@@ -28,6 +29,7 @@ const LayoutImageSchema = zod.z.object({
28
29
  heightPt: zod.z.number().positive(),
29
30
  rotationDeg: zod.z.number().optional(),
30
31
  layer: zod.z.string().optional(),
32
+ structure: zod.z.string().optional(),
31
33
  sourcePath: zod.z.string().optional()
32
34
  });
33
35
  const LayoutRectSchema = zod.z.object({
@@ -42,6 +44,7 @@ const LayoutRectSchema = zod.z.object({
42
44
  widthPt: zod.z.number().positive()
43
45
  }).optional(),
44
46
  layer: zod.z.string().optional(),
47
+ structure: zod.z.string().optional(),
45
48
  sourcePath: zod.z.string().optional()
46
49
  });
47
50
  const LayoutLineSchema = zod.z.object({
@@ -54,6 +57,7 @@ const LayoutLineSchema = zod.z.object({
54
57
  widthPt: zod.z.number().positive(),
55
58
  style: document_schema_js.ContentStrokeStyleSchema.optional(),
56
59
  layer: zod.z.string().optional(),
60
+ structure: zod.z.string().optional(),
57
61
  sourcePath: zod.z.string().optional()
58
62
  });
59
63
  const LayoutEllipseSchema = zod.z.object({
@@ -68,6 +72,7 @@ const LayoutEllipseSchema = zod.z.object({
68
72
  widthPt: zod.z.number().positive()
69
73
  }).optional(),
70
74
  layer: zod.z.string().optional(),
75
+ structure: zod.z.string().optional(),
71
76
  sourcePath: zod.z.string().optional()
72
77
  });
73
78
  const LayoutPathSegmentSchema = zod.z.discriminatedUnion("kind", [zod.z.object({
@@ -100,6 +105,7 @@ const LayoutPathSchema = zod.z.object({
100
105
  }).optional(),
101
106
  style: document_schema_js.ContentStrokeStyleSchema.optional(),
102
107
  layer: zod.z.string().optional(),
108
+ structure: zod.z.string().optional(),
103
109
  sourcePath: zod.z.string().optional()
104
110
  });
105
111
  const LayoutLinkSchema = zod.z.object({
@@ -238,6 +244,15 @@ const LayoutLayerSchema = zod.z.object({
238
244
  name: zod.z.string(),
239
245
  visible: zod.z.boolean()
240
246
  });
247
+ const LayoutStructureElementSchema = zod.z.lazy(() => zod.z.object({
248
+ id: zod.z.string(),
249
+ type: zod.z.string(),
250
+ title: zod.z.string().optional(),
251
+ language: zod.z.string().optional(),
252
+ alt: zod.z.string().optional(),
253
+ actualText: zod.z.string().optional(),
254
+ children: zod.z.array(LayoutStructureElementSchema)
255
+ }));
241
256
  const LayoutDocumentSchema = zod.z.object({
242
257
  formatVersion: zod.z.literal(1),
243
258
  metadata: document_schema_js.LayoutMetadataSchema,
@@ -247,6 +262,7 @@ const LayoutDocumentSchema = zod.z.object({
247
262
  outline: zod.z.array(LayoutOutlineItemSchema).optional(),
248
263
  attachments: zod.z.array(LayoutAttachmentSchema).optional(),
249
264
  layers: zod.z.array(LayoutLayerSchema).optional(),
265
+ structure: zod.z.array(LayoutStructureElementSchema).optional(),
250
266
  form: zod.z.array(LayoutFormFieldSchema).optional(),
251
267
  source: zod.z.record(zod.z.string(), document_schema_js.SourceResidueSchema).optional()
252
268
  });
@@ -273,5 +289,6 @@ exports.LayoutPageSchema = LayoutPageSchema;
273
289
  exports.LayoutPathSchema = LayoutPathSchema;
274
290
  exports.LayoutPathSegmentSchema = LayoutPathSegmentSchema;
275
291
  exports.LayoutRectSchema = LayoutRectSchema;
292
+ exports.LayoutStructureElementSchema = LayoutStructureElementSchema;
276
293
  exports.LayoutSubpathSchema = LayoutSubpathSchema;
277
294
  exports.LayoutTextSchema = LayoutTextSchema;