pdf-parser.js 5.2.26 → 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 (95) hide show
  1. package/dist/annotations.d.cts +2 -2
  2. package/dist/annotations.d.ts +2 -2
  3. package/dist/attachments.d.cts +2 -2
  4. package/dist/attachments.d.ts +2 -2
  5. package/dist/cff-bounds.cjs +31 -21
  6. package/dist/cff-bounds.js +31 -21
  7. package/dist/content-read.d.cts +1 -1
  8. package/dist/content-read.d.ts +1 -1
  9. package/dist/content-write.cjs +18 -12
  10. package/dist/content-write.d.cts +2 -2
  11. package/dist/content-write.d.ts +2 -2
  12. package/dist/content-write.js +18 -12
  13. package/dist/document.cjs +17 -11
  14. package/dist/document.d.cts +1 -1
  15. package/dist/document.d.ts +1 -1
  16. package/dist/document.js +17 -11
  17. package/dist/{embedded-font-Bnhh4juV.d.ts → embedded-font-ByD7ZiQS.d.ts} +1 -1
  18. package/dist/{embedded-font-CEf-zBCA.d.cts → embedded-font-DgVBedw6.d.cts} +1 -1
  19. package/dist/embedded-font-write.d.cts +2 -2
  20. package/dist/embedded-font-write.d.ts +2 -2
  21. package/dist/embedded-font.d.cts +1 -1
  22. package/dist/embedded-font.d.ts +1 -1
  23. package/dist/encrypt-write.d.cts +1 -1
  24. package/dist/encrypt-write.d.ts +1 -1
  25. package/dist/encrypt.d.cts +1 -1
  26. package/dist/encrypt.d.ts +1 -1
  27. package/dist/filters.cjs +6 -6
  28. package/dist/filters.d.cts +1 -1
  29. package/dist/filters.d.ts +1 -1
  30. package/dist/filters.js +6 -6
  31. package/dist/font-read.d.cts +1 -1
  32. package/dist/font-read.d.ts +1 -1
  33. package/dist/font-registry.d.cts +3 -3
  34. package/dist/font-registry.d.ts +3 -3
  35. package/dist/form.cjs +13 -8
  36. package/dist/form.d.cts +2 -2
  37. package/dist/form.d.ts +2 -2
  38. package/dist/form.js +13 -8
  39. package/dist/{glyf-contours-C0epBNqP.d.ts → glyf-contours-B1PsI9oA.d.ts} +1 -1
  40. package/dist/{glyf-contours-BRpvd0rt.d.cts → glyf-contours-NHBpgks-.d.cts} +1 -1
  41. package/dist/glyf-contours.d.cts +1 -1
  42. package/dist/glyf-contours.d.ts +1 -1
  43. package/dist/gsub-table.cjs +12 -8
  44. package/dist/gsub-table.js +12 -8
  45. package/dist/image/jpeg2000-codestream.cjs +17 -8
  46. package/dist/image/jpeg2000-codestream.js +17 -8
  47. package/dist/images-read.d.cts +2 -2
  48. package/dist/images-read.d.ts +2 -2
  49. package/dist/index.d.cts +1 -1
  50. package/dist/index.d.ts +1 -1
  51. package/dist/interpret.cjs +29 -16
  52. package/dist/interpret.d.cts +1 -1
  53. package/dist/interpret.d.ts +1 -1
  54. package/dist/interpret.js +29 -16
  55. package/dist/math-font-write.d.cts +1 -1
  56. package/dist/math-font-write.d.ts +1 -1
  57. package/dist/names.cjs +7 -7
  58. package/dist/names.d.cts +2 -2
  59. package/dist/names.d.ts +2 -2
  60. package/dist/names.js +7 -7
  61. package/dist/navigation.cjs +6 -7
  62. package/dist/navigation.d.cts +4 -4
  63. package/dist/navigation.d.ts +4 -4
  64. package/dist/navigation.js +6 -7
  65. package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.cts} +3 -3
  66. package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.ts} +3 -3
  67. package/dist/objects.d.cts +1 -1
  68. package/dist/objects.d.ts +1 -1
  69. package/dist/optional-content.d.cts +2 -2
  70. package/dist/optional-content.d.ts +2 -2
  71. package/dist/ot-layout-common.cjs +18 -13
  72. package/dist/ot-layout-common.js +18 -13
  73. package/dist/parse.d.cts +1 -1
  74. package/dist/parse.d.ts +1 -1
  75. package/dist/predictors.d.cts +1 -1
  76. package/dist/predictors.d.ts +1 -1
  77. package/dist/raster.d.cts +8 -8
  78. package/dist/raster.d.ts +8 -8
  79. package/dist/read.cjs +12 -8
  80. package/dist/read.js +12 -8
  81. package/dist/serialize.d.cts +1 -1
  82. package/dist/serialize.d.ts +1 -1
  83. package/dist/sfnt-subset.d.cts +1 -1
  84. package/dist/sfnt-subset.d.ts +1 -1
  85. package/dist/structure.d.cts +2 -2
  86. package/dist/structure.d.ts +2 -2
  87. package/dist/text-layout.d.cts +1 -1
  88. package/dist/text-layout.d.ts +1 -1
  89. package/dist/tounicode.d.cts +1 -1
  90. package/dist/tounicode.d.ts +1 -1
  91. package/dist/write.d.cts +1 -1
  92. package/dist/write.d.ts +1 -1
  93. package/dist/xref.d.cts +1 -1
  94. package/dist/xref.d.ts +1 -1
  95. package/package.json +1 -1
@@ -274,17 +274,33 @@ function classifyShape(subpaths, paint, style) {
274
274
  if (subpaths.length !== 1 || subpath === void 0) return;
275
275
  return detectRect(subpath, paint) ?? detectEllipse(subpath, paint) ?? detectLine(subpath, paint, style);
276
276
  }
277
+ var MarkedContentStack = class {
278
+ #frames;
279
+ constructor(seed = []) {
280
+ this.#frames = [...seed];
281
+ }
282
+ open(frame) {
283
+ this.#frames.push(frame);
284
+ }
285
+ close() {
286
+ this.#frames.pop();
287
+ }
288
+ inScope(key) {
289
+ for (let i = this.#frames.length - 1; i >= 0; i--) {
290
+ const frame = this.#frames[i];
291
+ if (frame !== void 0 && key in frame) return frame[key];
292
+ }
293
+ }
294
+ };
277
295
  function interpretContentStream(bytes, resources, context) {
278
- const items = [];
279
- runContentStream(bytes, resources, {
296
+ return runContentStream(bytes, resources, {
280
297
  ctm: require_matrix.IDENTITY_MATRIX,
281
298
  fillColor: document_schema_js.COLOR_BLACK,
282
299
  strokeColor: document_schema_js.COLOR_BLACK,
283
300
  lineWidth: DEFAULT_LINE_WIDTH_PT,
284
301
  dashArray: [],
285
302
  ...initialTextParameters()
286
- }, context, items, 0, []);
287
- return items;
303
+ }, context, 0, new MarkedContentStack());
288
304
  }
289
305
  function lastPointOf(subpath) {
290
306
  const last = subpath.segments[subpath.segments.length - 1];
@@ -296,19 +312,15 @@ function lastPointOf(subpath) {
296
312
  y: last.yPt
297
313
  };
298
314
  }
299
- function runContentStream(bytes, resources, initialState, context, items, depth, markedContent) {
315
+ function runContentStream(bytes, resources, initialState, context, depth, markedContent) {
316
+ const items = [];
300
317
  const operations = require_content_read.readContentStream(bytes, context.sink);
301
318
  const gsStack = [];
302
319
  let gs = initialState;
303
320
  let text = defaultTextObjectState();
304
321
  let pathSubpaths = [];
305
322
  let currentSubpath;
306
- const inScope = (key) => {
307
- for (let i = markedContent.length - 1; i >= 0; i--) {
308
- const frame = markedContent[i];
309
- if (frame !== void 0 && key in frame) return frame[key];
310
- }
311
- };
323
+ const inScope = (key) => markedContent.inScope(key);
312
324
  const pushItem = (item) => {
313
325
  if (item.kind === "text") {
314
326
  const layer = item.layerName ?? inScope("layerName");
@@ -541,10 +553,10 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
541
553
  };
542
554
  const formLayer = ownLayer ?? inScope("layerName");
543
555
  const formMcid = require_objects.dictGet(xobj.dict, "StructParents") !== void 0 ? void 0 : inScope("mcid");
544
- runContentStream(decoded.bytes, formResources, formState, context, items, depth + 1, [{
556
+ for (const formItem of runContentStream(decoded.bytes, formResources, formState, context, depth + 1, new MarkedContentStack([{
545
557
  ...formLayer !== void 0 ? { layerName: formLayer } : {},
546
558
  ...formMcid !== void 0 ? { mcid: formMcid } : {}
547
- }]);
559
+ }]))) items.push(formItem);
548
560
  }
549
561
  };
550
562
  for (const token of operations) {
@@ -843,18 +855,19 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
843
855
  ...layerName !== void 0 ? { layerName } : {},
844
856
  ...markedContentScopeProps(props)
845
857
  };
846
- markedContent.push(depth === 0 ? scopeProps : {
858
+ markedContent.open(depth === 0 ? scopeProps : {
847
859
  ...scopeProps,
848
860
  mcid: void 0
849
861
  });
850
862
  break;
851
863
  }
852
864
  case "BMC":
853
- markedContent.push({});
865
+ markedContent.open({});
854
866
  break;
855
- case "EMC": markedContent.pop();
867
+ case "EMC": markedContent.close();
856
868
  }
857
869
  }
870
+ return items;
858
871
  }
859
872
  //#endregion
860
873
  exports.interpretContentStream = interpretContentStream;
@@ -1,6 +1,6 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
2
  import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
3
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
3
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
4
4
  import { Color, ContentStrokeStyle } from "document-schema.js";
5
5
  //#region src/interpret.d.ts
6
6
  interface ExtractedTextRun {
@@ -1,6 +1,6 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
2
  import { r as Matrix } from "./matrix-B7_SBKQ5.js";
3
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
3
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
4
4
  import { Color, ContentStrokeStyle } from "document-schema.js";
5
5
  //#region src/interpret.d.ts
6
6
  interface ExtractedTextRun {
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");
@@ -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 };
@@ -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 {
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,10 +1,10 @@
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;
@@ -12,7 +12,7 @@ interface DestinationRegistry {
12
12
  readonly entries: readonly LayoutDestination[];
13
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,10 +1,10 @@
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;
@@ -12,7 +12,7 @@ interface DestinationRegistry {
12
12
  readonly entries: readonly LayoutDestination[];
13
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;