pdf-parser.js 5.2.25 → 5.2.27

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.
Files changed (149) hide show
  1. package/dist/afm-widths.cjs +1 -1
  2. package/dist/afm-widths.js +1 -1
  3. package/dist/annotations.d.cts +2 -2
  4. package/dist/annotations.d.ts +2 -2
  5. package/dist/attachments.d.cts +2 -2
  6. package/dist/attachments.d.ts +2 -2
  7. package/dist/builtin-encoding.cjs +1 -1
  8. package/dist/builtin-encoding.d.cts +2 -2
  9. package/dist/builtin-encoding.d.ts +2 -2
  10. package/dist/builtin-encoding.js +1 -1
  11. package/dist/cff-bounds.cjs +31 -21
  12. package/dist/cff-bounds.d.cts +1 -1
  13. package/dist/cff-bounds.d.ts +1 -1
  14. package/dist/cff-bounds.js +31 -21
  15. package/dist/cff.d.cts +1 -1
  16. package/dist/cff.d.ts +1 -1
  17. package/dist/cmap-table.d.cts +1 -1
  18. package/dist/cmap-table.d.ts +1 -1
  19. package/dist/cmap.d.cts +1 -1
  20. package/dist/cmap.d.ts +1 -1
  21. package/dist/content-read.d.cts +1 -1
  22. package/dist/content-read.d.ts +1 -1
  23. package/dist/content-write.cjs +19 -13
  24. package/dist/content-write.d.cts +3 -3
  25. package/dist/content-write.d.ts +3 -3
  26. package/dist/content-write.js +19 -13
  27. package/dist/document.cjs +17 -11
  28. package/dist/document.d.cts +5 -5
  29. package/dist/document.d.ts +5 -5
  30. package/dist/document.js +17 -11
  31. package/dist/{embedded-font-BRhZfEN2.d.ts → embedded-font-ByD7ZiQS.d.ts} +4 -4
  32. package/dist/{embedded-font-DJUn9kMH.d.cts → embedded-font-DgVBedw6.d.cts} +4 -4
  33. package/dist/embedded-font-write.d.cts +2 -2
  34. package/dist/embedded-font-write.d.ts +2 -2
  35. package/dist/embedded-font.cjs +1 -1
  36. package/dist/embedded-font.d.cts +1 -1
  37. package/dist/embedded-font.d.ts +1 -1
  38. package/dist/embedded-font.js +1 -1
  39. package/dist/encoding.cjs +1 -1
  40. package/dist/encoding.js +1 -1
  41. package/dist/encrypt-write.d.cts +3 -3
  42. package/dist/encrypt-write.d.ts +3 -3
  43. package/dist/encrypt.d.cts +3 -3
  44. package/dist/encrypt.d.ts +3 -3
  45. package/dist/filters.cjs +6 -6
  46. package/dist/filters.d.cts +1 -1
  47. package/dist/filters.d.ts +1 -1
  48. package/dist/filters.js +6 -6
  49. package/dist/font-read.cjs +1 -1
  50. package/dist/font-read.d.cts +3 -3
  51. package/dist/font-read.d.ts +3 -3
  52. package/dist/font-read.js +1 -1
  53. package/dist/font-registry.d.cts +3 -3
  54. package/dist/font-registry.d.ts +3 -3
  55. package/dist/form.cjs +13 -8
  56. package/dist/form.d.cts +2 -2
  57. package/dist/form.d.ts +2 -2
  58. package/dist/form.js +13 -8
  59. package/dist/gdef-table.d.cts +3 -3
  60. package/dist/gdef-table.d.ts +3 -3
  61. package/dist/{glyf-vMGtP1pb.d.ts → glyf-Bv1katwK.d.ts} +4 -4
  62. package/dist/{glyf-nXC-IDRW.d.cts → glyf-DFyknMrW.d.cts} +4 -4
  63. package/dist/{glyf-contours-OSdG6Edr.d.ts → glyf-contours-B1PsI9oA.d.ts} +2 -2
  64. package/dist/{glyf-contours-zRQbj-Yp.d.cts → glyf-contours-NHBpgks-.d.cts} +2 -2
  65. package/dist/glyf-contours.d.cts +1 -1
  66. package/dist/glyf-contours.d.ts +1 -1
  67. package/dist/glyf.d.cts +1 -1
  68. package/dist/glyf.d.ts +1 -1
  69. package/dist/gsub-table.cjs +13 -9
  70. package/dist/gsub-table.js +13 -9
  71. package/dist/hmtx-table.d.cts +1 -1
  72. package/dist/hmtx-table.d.ts +1 -1
  73. package/dist/image/jbig2-generic.cjs +2 -2
  74. package/dist/image/jbig2-generic.js +2 -2
  75. package/dist/image/jpeg2000-codestream.cjs +17 -8
  76. package/dist/image/jpeg2000-codestream.js +17 -8
  77. package/dist/image/jpeg2000-tagtree.cjs +1 -1
  78. package/dist/image/jpeg2000-tagtree.js +1 -1
  79. package/dist/images-read.d.cts +2 -2
  80. package/dist/images-read.d.ts +2 -2
  81. package/dist/index.cjs +1 -1
  82. package/dist/index.d.cts +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.js +1 -1
  85. package/dist/interpret.cjs +31 -18
  86. package/dist/interpret.d.cts +5 -5
  87. package/dist/interpret.d.ts +5 -5
  88. package/dist/interpret.js +31 -18
  89. package/dist/math-content-write.cjs +3 -3
  90. package/dist/math-content-write.js +3 -3
  91. package/dist/math-font-write.d.cts +1 -1
  92. package/dist/math-font-write.d.ts +1 -1
  93. package/dist/math-font.d.cts +4 -4
  94. package/dist/math-font.d.ts +4 -4
  95. package/dist/measure.cjs +1 -1
  96. package/dist/measure.js +1 -1
  97. package/dist/names.cjs +7 -7
  98. package/dist/names.d.cts +2 -2
  99. package/dist/names.d.ts +2 -2
  100. package/dist/names.js +7 -7
  101. package/dist/navigation.cjs +6 -7
  102. package/dist/navigation.d.cts +5 -5
  103. package/dist/navigation.d.ts +5 -5
  104. package/dist/navigation.js +6 -7
  105. package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.cts} +3 -3
  106. package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.ts} +3 -3
  107. package/dist/objects.d.cts +1 -1
  108. package/dist/objects.d.ts +1 -1
  109. package/dist/optional-content.d.cts +2 -2
  110. package/dist/optional-content.d.ts +2 -2
  111. package/dist/ot-layout-common.cjs +18 -13
  112. package/dist/ot-layout-common.d.cts +2 -2
  113. package/dist/ot-layout-common.d.ts +2 -2
  114. package/dist/ot-layout-common.js +18 -13
  115. package/dist/parse.cjs +5 -0
  116. package/dist/parse.d.cts +3 -2
  117. package/dist/parse.d.ts +3 -2
  118. package/dist/parse.js +5 -1
  119. package/dist/predictors.d.cts +1 -1
  120. package/dist/predictors.d.ts +1 -1
  121. package/dist/raster.cjs +10 -40
  122. package/dist/raster.d.cts +11 -11
  123. package/dist/raster.d.ts +11 -11
  124. package/dist/raster.js +10 -40
  125. package/dist/read.cjs +12 -8
  126. package/dist/read.js +12 -8
  127. package/dist/serialize.d.cts +1 -1
  128. package/dist/serialize.d.ts +1 -1
  129. package/dist/sfnt-subset.d.cts +1 -1
  130. package/dist/sfnt-subset.d.ts +1 -1
  131. package/dist/structure.cjs +4 -4
  132. package/dist/structure.d.cts +2 -2
  133. package/dist/structure.d.ts +2 -2
  134. package/dist/structure.js +4 -4
  135. package/dist/text-layout.d.cts +1 -1
  136. package/dist/text-layout.d.ts +1 -1
  137. package/dist/tounicode.d.cts +1 -1
  138. package/dist/tounicode.d.ts +1 -1
  139. package/dist/winansi.cjs +1 -1
  140. package/dist/winansi.js +1 -1
  141. package/dist/write.cjs +4 -4
  142. package/dist/write.d.cts +1 -1
  143. package/dist/write.d.ts +1 -1
  144. package/dist/write.js +4 -4
  145. package/dist/xref.d.cts +1 -1
  146. package/dist/xref.d.ts +1 -1
  147. package/package.json +2 -2
  148. package/dist/{afm-widths-BTu0IDp2.cjs → afm-widths-BYiX2L9D.cjs} +1 -1
  149. package/dist/{afm-widths-De_QMWgC.js → afm-widths-blUDDjlI.js} +1 -1
package/dist/interpret.js CHANGED
@@ -273,17 +273,33 @@ function classifyShape(subpaths, paint, style) {
273
273
  if (subpaths.length !== 1 || subpath === void 0) return;
274
274
  return detectRect(subpath, paint) ?? detectEllipse(subpath, paint) ?? detectLine(subpath, paint, style);
275
275
  }
276
+ var MarkedContentStack = class {
277
+ #frames;
278
+ constructor(seed = []) {
279
+ this.#frames = [...seed];
280
+ }
281
+ open(frame) {
282
+ this.#frames.push(frame);
283
+ }
284
+ close() {
285
+ this.#frames.pop();
286
+ }
287
+ inScope(key) {
288
+ for (let i = this.#frames.length - 1; i >= 0; i--) {
289
+ const frame = this.#frames[i];
290
+ if (frame !== void 0 && key in frame) return frame[key];
291
+ }
292
+ }
293
+ };
276
294
  function interpretContentStream(bytes, resources, context) {
277
- const items = [];
278
- runContentStream(bytes, resources, {
295
+ return runContentStream(bytes, resources, {
279
296
  ctm: IDENTITY_MATRIX,
280
297
  fillColor: COLOR_BLACK,
281
298
  strokeColor: COLOR_BLACK,
282
299
  lineWidth: DEFAULT_LINE_WIDTH_PT,
283
300
  dashArray: [],
284
301
  ...initialTextParameters()
285
- }, context, items, 0, []);
286
- return items;
302
+ }, context, 0, new MarkedContentStack());
287
303
  }
288
304
  function lastPointOf(subpath) {
289
305
  const last = subpath.segments[subpath.segments.length - 1];
@@ -295,19 +311,15 @@ function lastPointOf(subpath) {
295
311
  y: last.yPt
296
312
  };
297
313
  }
298
- function runContentStream(bytes, resources, initialState, context, items, depth, markedContent) {
314
+ function runContentStream(bytes, resources, initialState, context, depth, markedContent) {
315
+ const items = [];
299
316
  const operations = readContentStream(bytes, context.sink);
300
317
  const gsStack = [];
301
318
  let gs = initialState;
302
319
  let text = defaultTextObjectState();
303
320
  let pathSubpaths = [];
304
321
  let currentSubpath;
305
- const inScope = (key) => {
306
- for (let i = markedContent.length - 1; i >= 0; i--) {
307
- const frame = markedContent[i];
308
- if (frame !== void 0 && key in frame) return frame[key];
309
- }
310
- };
322
+ const inScope = (key) => markedContent.inScope(key);
311
323
  const pushItem = (item) => {
312
324
  if (item.kind === "text") {
313
325
  const layer = item.layerName ?? inScope("layerName");
@@ -486,10 +498,10 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
486
498
  ...vertical ? { vertical: true } : {}
487
499
  });
488
500
  };
489
- const showText = (bytes) => {
501
+ const showText = (textBytes) => {
490
502
  showTextArray([{
491
503
  kind: "string",
492
- bytes,
504
+ bytes: textBytes,
493
505
  hex: false
494
506
  }]);
495
507
  };
@@ -540,10 +552,10 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
540
552
  };
541
553
  const formLayer = ownLayer ?? inScope("layerName");
542
554
  const formMcid = dictGet(xobj.dict, "StructParents") !== void 0 ? void 0 : inScope("mcid");
543
- runContentStream(decoded.bytes, formResources, formState, context, items, depth + 1, [{
555
+ for (const formItem of runContentStream(decoded.bytes, formResources, formState, context, depth + 1, new MarkedContentStack([{
544
556
  ...formLayer !== void 0 ? { layerName: formLayer } : {},
545
557
  ...formMcid !== void 0 ? { mcid: formMcid } : {}
546
- }]);
558
+ }]))) items.push(formItem);
547
559
  }
548
560
  };
549
561
  for (const token of operations) {
@@ -842,18 +854,19 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
842
854
  ...layerName !== void 0 ? { layerName } : {},
843
855
  ...markedContentScopeProps(props)
844
856
  };
845
- markedContent.push(depth === 0 ? scopeProps : {
857
+ markedContent.open(depth === 0 ? scopeProps : {
846
858
  ...scopeProps,
847
859
  mcid: void 0
848
860
  });
849
861
  break;
850
862
  }
851
863
  case "BMC":
852
- markedContent.push({});
864
+ markedContent.open({});
853
865
  break;
854
- case "EMC": markedContent.pop();
866
+ case "EMC": markedContent.close();
855
867
  }
856
868
  }
869
+ return items;
857
870
  }
858
871
  //#endregion
859
872
  export { interpretContentStream };
@@ -28,15 +28,15 @@ function encodeGlyphRunToCids(font, text) {
28
28
  return bytes;
29
29
  }
30
30
  function writeGlyphRun(writer, positioned, item, ctx) {
31
- const cidBytes = encodeGlyphRunToCids(ctx.font, item.text);
32
- if (cidBytes.length === 0) return;
31
+ const encodedCids = encodeGlyphRunToCids(ctx.font, item.text);
32
+ if (encodedCids.length === 0) return;
33
33
  const x = toPdfX(positioned, item.xPt);
34
34
  const y = toPdfY(positioned, item.yPt);
35
35
  writer.writeAscii("BT\n");
36
36
  writer.writeAscii(`/${ctx.resourceName} ${require_serialize.formatNumber(item.sizePt)} Tf\n`);
37
37
  writeRgbOperator(writer, item.color, "rg");
38
38
  writer.writeAscii(`1 0 0 1 ${require_serialize.formatNumber(x)} ${require_serialize.formatNumber(y)} Tm\n`);
39
- require_serialize.writeObject(writer, require_objects.pdfHexString(cidBytes));
39
+ require_serialize.writeObject(writer, require_objects.pdfHexString(encodedCids));
40
40
  writer.writeAscii(" Tj\n");
41
41
  writer.writeAscii("ET\n");
42
42
  }
@@ -27,15 +27,15 @@ function encodeGlyphRunToCids(font, text) {
27
27
  return bytes;
28
28
  }
29
29
  function writeGlyphRun(writer, positioned, item, ctx) {
30
- const cidBytes = encodeGlyphRunToCids(ctx.font, item.text);
31
- if (cidBytes.length === 0) return;
30
+ const encodedCids = encodeGlyphRunToCids(ctx.font, item.text);
31
+ if (encodedCids.length === 0) return;
32
32
  const x = toPdfX(positioned, item.xPt);
33
33
  const y = toPdfY(positioned, item.yPt);
34
34
  writer.writeAscii("BT\n");
35
35
  writer.writeAscii(`/${ctx.resourceName} ${formatNumber(item.sizePt)} Tf\n`);
36
36
  writeRgbOperator(writer, item.color, "rg");
37
37
  writer.writeAscii(`1 0 0 1 ${formatNumber(x)} ${formatNumber(y)} Tm\n`);
38
- writeObject(writer, pdfHexString(cidBytes));
38
+ writeObject(writer, pdfHexString(encodedCids));
39
39
  writer.writeAscii(" Tj\n");
40
40
  writer.writeAscii("ET\n");
41
41
  }
@@ -1,4 +1,4 @@
1
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
1
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
2
  import { MathFont } from "./math-font.cjs";
3
3
  //#region src/math-font-write.d.ts
4
4
  interface MathFontObjectRefs {
@@ -1,4 +1,4 @@
1
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
1
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
2
2
  import { MathFont } from "./math-font.js";
3
3
  //#region src/math-font-write.d.ts
4
4
  interface MathFontObjectRefs {
@@ -16,11 +16,11 @@ interface MathFont {
16
16
  readonly metrics: MathFontMetrics;
17
17
  readonly cffBytes: Uint8Array<ArrayBuffer>;
18
18
  readonly descriptor: MathFontDescriptorMetrics;
19
- glyphId(codePoint: number): number | undefined;
20
- glyphSpaceWidth(glyphId: number): number;
21
- glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
19
+ glyphId: (codePoint: number) => number | undefined;
20
+ glyphSpaceWidth: (glyphId: number) => number;
21
+ glyphInkBounds: (glyphId: number) => GlyphInkBounds | undefined;
22
22
  readonly minConnectorOverlap: number;
23
- stretchyConstruction(codePoint: number, axis: MathStretchAxis): MathGlyphConstruction | undefined;
23
+ stretchyConstruction: (codePoint: number, axis: MathStretchAxis) => MathGlyphConstruction | undefined;
24
24
  }
25
25
  interface LoadedMathFont {
26
26
  readonly font: MathFont;
@@ -16,11 +16,11 @@ interface MathFont {
16
16
  readonly metrics: MathFontMetrics;
17
17
  readonly cffBytes: Uint8Array<ArrayBuffer>;
18
18
  readonly descriptor: MathFontDescriptorMetrics;
19
- glyphId(codePoint: number): number | undefined;
20
- glyphSpaceWidth(glyphId: number): number;
21
- glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
19
+ glyphId: (codePoint: number) => number | undefined;
20
+ glyphSpaceWidth: (glyphId: number) => number;
21
+ glyphInkBounds: (glyphId: number) => GlyphInkBounds | undefined;
22
22
  readonly minConnectorOverlap: number;
23
- stretchyConstruction(codePoint: number, axis: MathStretchAxis): MathGlyphConstruction | undefined;
23
+ stretchyConstruction: (codePoint: number, axis: MathStretchAxis) => MathGlyphConstruction | undefined;
24
24
  }
25
25
  interface LoadedMathFont {
26
26
  readonly font: MathFont;
package/dist/measure.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
2
+ const require_afm_widths = require("./afm-widths-BYiX2L9D.cjs");
3
3
  const require_embedded_font = require("./embedded-font.cjs");
4
4
  const require_font_registry = require("./font-registry.cjs");
5
5
  //#region src/measure.ts
package/dist/measure.js CHANGED
@@ -1,4 +1,4 @@
1
- import { h as encodeForShow, t as STANDARD_METRICS } from "./afm-widths-De_QMWgC.js";
1
+ import { h as encodeForShow, t as STANDARD_METRICS } from "./afm-widths-blUDDjlI.js";
2
2
  import { encodeForShowEmbedded } from "./embedded-font.js";
3
3
  import { resolveFaceWithRegistry } from "./font-registry.js";
4
4
  //#region src/measure.ts
package/dist/names.cjs CHANGED
@@ -3,11 +3,9 @@ const require_objects = require("./objects.cjs");
3
3
  const require_pdf_text = require("./pdf-text.cjs");
4
4
  //#region src/names.ts
5
5
  function walkNameTree(root, resolver, sink) {
6
- const entries = [];
7
- collectNameTreeEntries(root, resolver, sink, entries, /* @__PURE__ */ new Set());
8
- return entries;
6
+ return collectNameTreeEntries(root, resolver, sink, /* @__PURE__ */ new Set());
9
7
  }
10
- function collectNameTreeEntries(node, resolver, sink, entries, visited) {
8
+ function collectNameTreeEntries(node, resolver, sink, visited) {
11
9
  const dict = require_objects.asDict(resolver.resolve(node));
12
10
  if (dict === void 0) {
13
11
  if (node !== void 0) sink({
@@ -15,7 +13,7 @@ function collectNameTreeEntries(node, resolver, sink, entries, visited) {
15
13
  severity: "warning",
16
14
  message: "a name tree node did not resolve to a dictionary; skipping it"
17
15
  });
18
- return;
16
+ return [];
19
17
  }
20
18
  if (visited.has(dict)) {
21
19
  sink({
@@ -23,9 +21,10 @@ function collectNameTreeEntries(node, resolver, sink, entries, visited) {
23
21
  severity: "warning",
24
22
  message: "the name tree contains a cycle; stopping descent at the repeated node"
25
23
  });
26
- return;
24
+ return [];
27
25
  }
28
26
  visited.add(dict);
27
+ const entries = [];
29
28
  const names = require_objects.asArray(require_objects.dictGet(dict, "Names"));
30
29
  if (names !== void 0) for (let i = 0; i + 1 < names.length; i += 2) {
31
30
  const key = names[i];
@@ -35,7 +34,8 @@ function collectNameTreeEntries(node, resolver, sink, entries, visited) {
35
34
  });
36
35
  }
37
36
  const kids = require_objects.asArray(require_objects.dictGet(dict, "Kids"));
38
- if (kids !== void 0) for (const kid of kids) collectNameTreeEntries(kid, resolver, sink, entries, visited);
37
+ if (kids !== void 0) for (const kid of kids) for (const entry of collectNameTreeEntries(kid, resolver, sink, visited)) entries.push(entry);
38
+ return entries;
39
39
  }
40
40
  //#endregion
41
41
  exports.walkNameTree = walkNameTree;
package/dist/names.d.cts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { r as PdfObject } from "./objects-B7HdMeWS.cjs";
2
+ import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
3
3
  import { PdfObjectResolver } from "./interpret.cjs";
4
4
  //#region src/names.d.ts
5
5
  interface NameTreeEntry {
6
6
  readonly name: string;
7
7
  readonly value: PdfObject;
8
8
  }
9
- declare function walkNameTree(root: PdfObject | undefined, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): NameTreeEntry[];
9
+ declare function walkNameTree(root: PdfObject | undefined, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): NameTreeEntry[];
10
10
  //#endregion
11
11
  export { NameTreeEntry, walkNameTree };
package/dist/names.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { r as PdfObject } from "./objects-B7HdMeWS.js";
2
+ import { r as PdfObject } from "./objects-e2RS3-yT.js";
3
3
  import { PdfObjectResolver } from "./interpret.js";
4
4
  //#region src/names.d.ts
5
5
  interface NameTreeEntry {
6
6
  readonly name: string;
7
7
  readonly value: PdfObject;
8
8
  }
9
- declare function walkNameTree(root: PdfObject | undefined, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): NameTreeEntry[];
9
+ declare function walkNameTree(root: PdfObject | undefined, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): NameTreeEntry[];
10
10
  //#endregion
11
11
  export { NameTreeEntry, walkNameTree };
package/dist/names.js CHANGED
@@ -2,11 +2,9 @@ import { asArray, asDict, dictGet } from "./objects.js";
2
2
  import { decodePdfString } from "./pdf-text.js";
3
3
  //#region src/names.ts
4
4
  function walkNameTree(root, resolver, sink) {
5
- const entries = [];
6
- collectNameTreeEntries(root, resolver, sink, entries, /* @__PURE__ */ new Set());
7
- return entries;
5
+ return collectNameTreeEntries(root, resolver, sink, /* @__PURE__ */ new Set());
8
6
  }
9
- function collectNameTreeEntries(node, resolver, sink, entries, visited) {
7
+ function collectNameTreeEntries(node, resolver, sink, visited) {
10
8
  const dict = asDict(resolver.resolve(node));
11
9
  if (dict === void 0) {
12
10
  if (node !== void 0) sink({
@@ -14,7 +12,7 @@ function collectNameTreeEntries(node, resolver, sink, entries, visited) {
14
12
  severity: "warning",
15
13
  message: "a name tree node did not resolve to a dictionary; skipping it"
16
14
  });
17
- return;
15
+ return [];
18
16
  }
19
17
  if (visited.has(dict)) {
20
18
  sink({
@@ -22,9 +20,10 @@ function collectNameTreeEntries(node, resolver, sink, entries, visited) {
22
20
  severity: "warning",
23
21
  message: "the name tree contains a cycle; stopping descent at the repeated node"
24
22
  });
25
- return;
23
+ return [];
26
24
  }
27
25
  visited.add(dict);
26
+ const entries = [];
28
27
  const names = asArray(dictGet(dict, "Names"));
29
28
  if (names !== void 0) for (let i = 0; i + 1 < names.length; i += 2) {
30
29
  const key = names[i];
@@ -34,7 +33,8 @@ function collectNameTreeEntries(node, resolver, sink, entries, visited) {
34
33
  });
35
34
  }
36
35
  const kids = asArray(dictGet(dict, "Kids"));
37
- if (kids !== void 0) for (const kid of kids) collectNameTreeEntries(kid, resolver, sink, entries, visited);
36
+ if (kids !== void 0) for (const kid of kids) for (const entry of collectNameTreeEntries(kid, resolver, sink, visited)) entries.push(entry);
37
+ return entries;
38
38
  }
39
39
  //#endregion
40
40
  export { walkNameTree };
@@ -161,11 +161,10 @@ function readOutline(catalog, registry, resolver, sink) {
161
161
  const root = resolver.resolveDict(require_objects.dictGet(catalog, "Outlines"));
162
162
  const first = root === void 0 ? void 0 : resolver.resolveDict(require_objects.dictGet(root, "First"));
163
163
  if (first === void 0) return [];
164
- const items = [];
165
- walkOutlineSiblings(first, items, registry, resolver, sink, /* @__PURE__ */ new Set());
166
- return items;
164
+ return walkOutlineSiblings(first, registry, resolver, sink, /* @__PURE__ */ new Set());
167
165
  }
168
- function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
166
+ function walkOutlineSiblings(node, registry, resolver, sink, visited) {
167
+ const out = [];
169
168
  let current = node;
170
169
  while (current !== void 0) {
171
170
  if (visited.has(current)) {
@@ -174,13 +173,12 @@ function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
174
173
  severity: "warning",
175
174
  message: "the outline contains a cycle; stopping the sibling chain at the repeated item"
176
175
  });
177
- return;
176
+ return out;
178
177
  }
179
178
  visited.add(current);
180
179
  const titleObj = require_objects.dictGet(current, "Title");
181
- const children = [];
182
180
  const childFirst = resolver.resolveDict(require_objects.dictGet(current, "First"));
183
- if (childFirst !== void 0) walkOutlineSiblings(childFirst, children, registry, resolver, sink, visited);
181
+ const children = childFirst === void 0 ? [] : walkOutlineSiblings(childFirst, registry, resolver, sink, visited);
184
182
  const destination = internOutlineDestination(current, registry, resolver);
185
183
  out.push({
186
184
  title: titleObj?.kind === "string" ? require_pdf_text.decodePdfString(titleObj.bytes) : "",
@@ -189,6 +187,7 @@ function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
189
187
  });
190
188
  current = resolver.resolveDict(require_objects.dictGet(current, "Next"));
191
189
  }
190
+ return out;
192
191
  }
193
192
  function internOutlineDestination(node, registry, resolver) {
194
193
  const dest = require_objects.dictGet(node, "Dest");
@@ -1,18 +1,18 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
3
3
  import { PdfObjectResolver } from "./interpret.cjs";
4
4
  import { LayoutDestination, LayoutDestinationTarget, LayoutOutlineItem } from "./layout.cjs";
5
5
  //#region src/navigation.d.ts
6
6
  type PageIndexLookup = (obj: PdfObject | undefined) => number | undefined;
7
- declare function parseDestination(value: PdfObject | undefined, resolver: PdfObjectResolver, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): {
7
+ declare function parseDestination(value: PdfObject | undefined, resolver: Readonly<PdfObjectResolver>, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): {
8
8
  pageIndex: number;
9
9
  target: LayoutDestinationTarget;
10
10
  } | undefined;
11
11
  interface DestinationRegistry {
12
12
  readonly entries: readonly LayoutDestination[];
13
- intern(obj: PdfObject | undefined): string | undefined;
13
+ intern: (obj: PdfObject | undefined) => string | undefined;
14
14
  }
15
- declare function createDestinationRegistry(catalog: PdfDict, resolver: PdfObjectResolver, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): DestinationRegistry;
16
- declare function readOutline(catalog: PdfDict, registry: DestinationRegistry, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutOutlineItem[];
15
+ declare function createDestinationRegistry(catalog: PdfDict, resolver: Readonly<PdfObjectResolver>, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): DestinationRegistry;
16
+ declare function readOutline(catalog: PdfDict, registry: DestinationRegistry, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): LayoutOutlineItem[];
17
17
  //#endregion
18
18
  export { DestinationRegistry, PageIndexLookup, createDestinationRegistry, parseDestination, readOutline };
@@ -1,18 +1,18 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
3
3
  import { PdfObjectResolver } from "./interpret.js";
4
4
  import { LayoutDestination, LayoutDestinationTarget, LayoutOutlineItem } from "./layout.js";
5
5
  //#region src/navigation.d.ts
6
6
  type PageIndexLookup = (obj: PdfObject | undefined) => number | undefined;
7
- declare function parseDestination(value: PdfObject | undefined, resolver: PdfObjectResolver, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): {
7
+ declare function parseDestination(value: PdfObject | undefined, resolver: Readonly<PdfObjectResolver>, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): {
8
8
  pageIndex: number;
9
9
  target: LayoutDestinationTarget;
10
10
  } | undefined;
11
11
  interface DestinationRegistry {
12
12
  readonly entries: readonly LayoutDestination[];
13
- intern(obj: PdfObject | undefined): string | undefined;
13
+ intern: (obj: PdfObject | undefined) => string | undefined;
14
14
  }
15
- declare function createDestinationRegistry(catalog: PdfDict, resolver: PdfObjectResolver, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): DestinationRegistry;
16
- declare function readOutline(catalog: PdfDict, registry: DestinationRegistry, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutOutlineItem[];
15
+ declare function createDestinationRegistry(catalog: PdfDict, resolver: Readonly<PdfObjectResolver>, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): DestinationRegistry;
16
+ declare function readOutline(catalog: PdfDict, registry: DestinationRegistry, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): LayoutOutlineItem[];
17
17
  //#endregion
18
18
  export { DestinationRegistry, PageIndexLookup, createDestinationRegistry, parseDestination, readOutline };
@@ -160,11 +160,10 @@ function readOutline(catalog, registry, resolver, sink) {
160
160
  const root = resolver.resolveDict(dictGet(catalog, "Outlines"));
161
161
  const first = root === void 0 ? void 0 : resolver.resolveDict(dictGet(root, "First"));
162
162
  if (first === void 0) return [];
163
- const items = [];
164
- walkOutlineSiblings(first, items, registry, resolver, sink, /* @__PURE__ */ new Set());
165
- return items;
163
+ return walkOutlineSiblings(first, registry, resolver, sink, /* @__PURE__ */ new Set());
166
164
  }
167
- function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
165
+ function walkOutlineSiblings(node, registry, resolver, sink, visited) {
166
+ const out = [];
168
167
  let current = node;
169
168
  while (current !== void 0) {
170
169
  if (visited.has(current)) {
@@ -173,13 +172,12 @@ function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
173
172
  severity: "warning",
174
173
  message: "the outline contains a cycle; stopping the sibling chain at the repeated item"
175
174
  });
176
- return;
175
+ return out;
177
176
  }
178
177
  visited.add(current);
179
178
  const titleObj = dictGet(current, "Title");
180
- const children = [];
181
179
  const childFirst = resolver.resolveDict(dictGet(current, "First"));
182
- if (childFirst !== void 0) walkOutlineSiblings(childFirst, children, registry, resolver, sink, visited);
180
+ const children = childFirst === void 0 ? [] : walkOutlineSiblings(childFirst, registry, resolver, sink, visited);
183
181
  const destination = internOutlineDestination(current, registry, resolver);
184
182
  out.push({
185
183
  title: titleObj?.kind === "string" ? decodePdfString(titleObj.bytes) : "",
@@ -188,6 +186,7 @@ function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
188
186
  });
189
187
  current = resolver.resolveDict(dictGet(current, "Next"));
190
188
  }
189
+ return out;
191
190
  }
192
191
  function internOutlineDestination(node, registry, resolver) {
193
192
  const dest = dictGet(node, "Dest");
@@ -16,7 +16,7 @@ type PdfObject = {
16
16
  hex: boolean;
17
17
  } | {
18
18
  kind: "array";
19
- items: PdfObject[];
19
+ items: readonly PdfObject[];
20
20
  } | {
21
21
  kind: "dict";
22
22
  entries: Map<string, PdfObject>;
@@ -44,7 +44,7 @@ declare function pdfNum(value: number): PdfObject;
44
44
  declare function pdfName(name: string): PdfObject;
45
45
  declare function pdfHexString(bytes: Uint8Array<ArrayBuffer>): PdfObject;
46
46
  declare function pdfLiteralString(bytes: Uint8Array<ArrayBuffer>): PdfObject;
47
- declare function pdfArray(items: PdfObject[]): PdfObject;
47
+ declare function pdfArray(items: readonly PdfObject[]): PdfObject;
48
48
  declare function pdfDict(entries: Record<string, PdfObject> | Map<string, PdfObject>): PdfDict;
49
49
  declare function pdfStream(dict: PdfDict, raw: Uint8Array<ArrayBuffer>): PdfObject;
50
50
  declare function pdfRef(num: number, gen: number): PdfObject;
@@ -52,7 +52,7 @@ declare function isName(obj: PdfObject | undefined, name: string): boolean;
52
52
  declare function asNumber(obj: PdfObject | undefined): number | undefined;
53
53
  declare function asName(obj: PdfObject | undefined): string | undefined;
54
54
  declare function asBool(obj: PdfObject | undefined): boolean | undefined;
55
- declare function asArray(obj: PdfObject | undefined): PdfObject[] | undefined;
55
+ declare function asArray(obj: PdfObject | undefined): readonly PdfObject[] | undefined;
56
56
  declare function asDict(obj: PdfObject | undefined): PdfDict | undefined;
57
57
  declare function dictGet(dict: PdfDict, key: string): PdfObject | undefined;
58
58
  //#endregion
@@ -16,7 +16,7 @@ type PdfObject = {
16
16
  hex: boolean;
17
17
  } | {
18
18
  kind: "array";
19
- items: PdfObject[];
19
+ items: readonly PdfObject[];
20
20
  } | {
21
21
  kind: "dict";
22
22
  entries: Map<string, PdfObject>;
@@ -44,7 +44,7 @@ declare function pdfNum(value: number): PdfObject;
44
44
  declare function pdfName(name: string): PdfObject;
45
45
  declare function pdfHexString(bytes: Uint8Array<ArrayBuffer>): PdfObject;
46
46
  declare function pdfLiteralString(bytes: Uint8Array<ArrayBuffer>): PdfObject;
47
- declare function pdfArray(items: PdfObject[]): PdfObject;
47
+ declare function pdfArray(items: readonly PdfObject[]): PdfObject;
48
48
  declare function pdfDict(entries: Record<string, PdfObject> | Map<string, PdfObject>): PdfDict;
49
49
  declare function pdfStream(dict: PdfDict, raw: Uint8Array<ArrayBuffer>): PdfObject;
50
50
  declare function pdfRef(num: number, gen: number): PdfObject;
@@ -52,7 +52,7 @@ declare function isName(obj: PdfObject | undefined, name: string): boolean;
52
52
  declare function asNumber(obj: PdfObject | undefined): number | undefined;
53
53
  declare function asName(obj: PdfObject | undefined): string | undefined;
54
54
  declare function asBool(obj: PdfObject | undefined): boolean | undefined;
55
- declare function asArray(obj: PdfObject | undefined): PdfObject[] | undefined;
55
+ declare function asArray(obj: PdfObject | undefined): readonly PdfObject[] | undefined;
56
56
  declare function asDict(obj: PdfObject | undefined): PdfDict | undefined;
57
57
  declare function dictGet(dict: PdfDict, key: string): PdfObject | undefined;
58
58
  //#endregion
@@ -1,2 +1,2 @@
1
- import { _ as pdfName, a as asArray, b as pdfRef, c as asName, d as isName, f as pdfArray, g as pdfLiteralString, h as pdfHexString, i as PdfStream, l as asNumber, m as pdfDict, n as PdfDict, o as asBool, p as pdfBool, r as PdfObject, s as asDict, t as PdfArray, u as dictGet, v as pdfNull, x as pdfStream, y as pdfNum } from "./objects-B7HdMeWS.cjs";
1
+ import { _ as pdfName, a as asArray, b as pdfRef, c as asName, d as isName, f as pdfArray, g as pdfLiteralString, h as pdfHexString, i as PdfStream, l as asNumber, m as pdfDict, n as PdfDict, o as asBool, p as pdfBool, r as PdfObject, s as asDict, t as PdfArray, u as dictGet, v as pdfNull, x as pdfStream, y as pdfNum } from "./objects-e2RS3-yT.cjs";
2
2
  export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asBool, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
package/dist/objects.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as pdfName, a as asArray, b as pdfRef, c as asName, d as isName, f as pdfArray, g as pdfLiteralString, h as pdfHexString, i as PdfStream, l as asNumber, m as pdfDict, n as PdfDict, o as asBool, p as pdfBool, r as PdfObject, s as asDict, t as PdfArray, u as dictGet, v as pdfNull, x as pdfStream, y as pdfNum } from "./objects-B7HdMeWS.js";
1
+ import { _ as pdfName, a as asArray, b as pdfRef, c as asName, d as isName, f as pdfArray, g as pdfLiteralString, h as pdfHexString, i as PdfStream, l as asNumber, m as pdfDict, n as PdfDict, o as asBool, p as pdfBool, r as PdfObject, s as asDict, t as PdfArray, u as dictGet, v as pdfNull, x as pdfStream, y as pdfNum } from "./objects-e2RS3-yT.js";
2
2
  export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asBool, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
3
3
  import { PdfObjectResolver } from "./interpret.cjs";
4
4
  import { LayoutLayer } from "./layout.cjs";
5
5
  //#region src/optional-content.d.ts
@@ -7,6 +7,6 @@ interface OptionalContentContext {
7
7
  readonly layers: readonly LayoutLayer[];
8
8
  readonly layerNameOf: (obj: PdfObject | undefined) => string | undefined;
9
9
  }
10
- declare function readOptionalContent(catalog: PdfDict, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): OptionalContentContext;
10
+ declare function readOptionalContent(catalog: PdfDict, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): OptionalContentContext;
11
11
  //#endregion
12
12
  export { OptionalContentContext, readOptionalContent };
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
3
3
  import { PdfObjectResolver } from "./interpret.js";
4
4
  import { LayoutLayer } from "./layout.js";
5
5
  //#region src/optional-content.d.ts
@@ -7,6 +7,6 @@ interface OptionalContentContext {
7
7
  readonly layers: readonly LayoutLayer[];
8
8
  readonly layerNameOf: (obj: PdfObject | undefined) => string | undefined;
9
9
  }
10
- declare function readOptionalContent(catalog: PdfDict, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): OptionalContentContext;
10
+ declare function readOptionalContent(catalog: PdfDict, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): OptionalContentContext;
11
11
  //#endregion
12
12
  export { OptionalContentContext, readOptionalContent };
@@ -12,21 +12,18 @@ function findRange(ranges, glyphId) {
12
12
  else return range;
13
13
  }
14
14
  }
15
- function pushGlyph(ranges, glyphId, value, valueStep) {
15
+ function placeGlyph(ranges, glyphId, value, valueStep) {
16
16
  const previous = ranges[ranges.length - 1];
17
- if (previous !== void 0 && glyphId === previous.endGlyphId + 1 && value === previous.value + (previous.endGlyphId - previous.startGlyphId + 1) * valueStep) {
18
- ranges[ranges.length - 1] = {
19
- startGlyphId: previous.startGlyphId,
20
- endGlyphId: glyphId,
21
- value: previous.value
22
- };
23
- return;
24
- }
25
- ranges.push({
17
+ if (previous !== void 0 && glyphId === previous.endGlyphId + 1 && value === previous.value + (previous.endGlyphId - previous.startGlyphId + 1) * valueStep) return { extended: {
18
+ startGlyphId: previous.startGlyphId,
19
+ endGlyphId: glyphId,
20
+ value: previous.value
21
+ } };
22
+ return { fresh: {
26
23
  startGlyphId: glyphId,
27
24
  endGlyphId: glyphId,
28
25
  value
29
- });
26
+ } };
30
27
  }
31
28
  const RANGE_RECORD_SIZE = 6;
32
29
  function parseRangeRecords(bytes, recordsOffset, recordCount) {
@@ -56,7 +53,11 @@ function parseCoverage(bytes, coverageOffset) {
56
53
  const glyphArrayOffset = coverageOffset + COVERAGE_HEADER_SIZE;
57
54
  if (!require_sfnt.hasBytes(bytes, glyphArrayOffset, count * 2)) return;
58
55
  ranges = [];
59
- for (let i = 0; i < count; i++) pushGlyph(ranges, require_sfnt.u16(bytes, glyphArrayOffset + i * 2), i, 1);
56
+ for (let i = 0; i < count; i++) {
57
+ const placement = placeGlyph(ranges, require_sfnt.u16(bytes, glyphArrayOffset + i * 2), i, 1);
58
+ if (placement.extended !== void 0) ranges[ranges.length - 1] = placement.extended;
59
+ else ranges.push(placement.fresh);
60
+ }
60
61
  ranges.sort((a, b) => a.startGlyphId - b.startGlyphId);
61
62
  } else if (format === 2) ranges = parseRangeRecords(bytes, coverageOffset + COVERAGE_HEADER_SIZE, count);
62
63
  if (ranges === void 0) return;
@@ -84,7 +85,11 @@ function parseClassDef(bytes, classDefOffset) {
84
85
  const classArrayOffset = classDefOffset + CLASS_DEF_FORMAT_1_HEADER_SIZE;
85
86
  if (!require_sfnt.hasBytes(bytes, classArrayOffset, glyphCount * 2)) return;
86
87
  ranges = [];
87
- for (let i = 0; i < glyphCount; i++) pushGlyph(ranges, startGlyphId + i, require_sfnt.u16(bytes, classArrayOffset + i * 2), 0);
88
+ for (let i = 0; i < glyphCount; i++) {
89
+ const placement = placeGlyph(ranges, startGlyphId + i, require_sfnt.u16(bytes, classArrayOffset + i * 2), 0);
90
+ if (placement.extended !== void 0) ranges[ranges.length - 1] = placement.extended;
91
+ else ranges.push(placement.fresh);
92
+ }
88
93
  } else if (format === 2) ranges = parseRangeRecords(bytes, classDefOffset + CLASS_DEF_FORMAT_2_HEADER_SIZE, require_sfnt.u16(bytes, classDefOffset + 2));
89
94
  if (ranges === void 0) return;
90
95
  const resolved = ranges;
@@ -1,7 +1,7 @@
1
1
  //#region src/ot-layout-common.d.ts
2
2
  interface CoverageTable {
3
- coverageIndex(glyphId: number): number | undefined;
4
- entries(): IterableIterator<readonly [number, number]>;
3
+ coverageIndex: (glyphId: number) => number | undefined;
4
+ entries: () => IterableIterator<readonly [number, number]>;
5
5
  }
6
6
  declare function parseCoverage(bytes: Uint8Array<ArrayBuffer>, coverageOffset: number): CoverageTable | undefined;
7
7
  type ClassDefTable = (glyphId: number) => number;
@@ -1,7 +1,7 @@
1
1
  //#region src/ot-layout-common.d.ts
2
2
  interface CoverageTable {
3
- coverageIndex(glyphId: number): number | undefined;
4
- entries(): IterableIterator<readonly [number, number]>;
3
+ coverageIndex: (glyphId: number) => number | undefined;
4
+ entries: () => IterableIterator<readonly [number, number]>;
5
5
  }
6
6
  declare function parseCoverage(bytes: Uint8Array<ArrayBuffer>, coverageOffset: number): CoverageTable | undefined;
7
7
  type ClassDefTable = (glyphId: number) => number;