pdf-parser.js 5.2.26 → 5.2.28

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 (221) hide show
  1. package/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
  2. package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
  3. package/dist/afm-widths.cjs +1 -1
  4. package/dist/afm-widths.js +1 -1
  5. package/dist/annotations.cjs +5 -3
  6. package/dist/annotations.d.cts +2 -2
  7. package/dist/annotations.d.ts +2 -2
  8. package/dist/annotations.js +5 -3
  9. package/dist/attachments.d.cts +2 -2
  10. package/dist/attachments.d.ts +2 -2
  11. package/dist/builtin-encoding.cjs +17 -6
  12. package/dist/builtin-encoding.js +17 -6
  13. package/dist/bytes/crc32.cjs +5 -3
  14. package/dist/bytes/crc32.js +5 -3
  15. package/dist/bytes/flate.cjs +0 -1
  16. package/dist/bytes/flate.js +0 -1
  17. package/dist/cff-bounds.cjs +73 -45
  18. package/dist/cff-bounds.js +73 -45
  19. package/dist/cff.cjs +13 -6
  20. package/dist/cff.js +13 -6
  21. package/dist/cmap-table.cjs +54 -26
  22. package/dist/cmap-table.js +54 -26
  23. package/dist/cmap.cjs +5 -3
  24. package/dist/cmap.js +5 -3
  25. package/dist/content-read.d.cts +1 -1
  26. package/dist/content-read.d.ts +1 -1
  27. package/dist/content-write.cjs +21 -14
  28. package/dist/content-write.d.cts +2 -2
  29. package/dist/content-write.d.ts +2 -2
  30. package/dist/content-write.js +21 -14
  31. package/dist/crypto/aes.cjs +76 -55
  32. package/dist/crypto/aes.js +76 -55
  33. package/dist/crypto/md5.cjs +345 -149
  34. package/dist/crypto/md5.js +345 -149
  35. package/dist/crypto/rc4.cjs +5 -4
  36. package/dist/crypto/rc4.js +5 -4
  37. package/dist/crypto/sha2.cjs +92 -43
  38. package/dist/crypto/sha2.js +92 -43
  39. package/dist/document.cjs +17 -11
  40. package/dist/document.d.cts +1 -1
  41. package/dist/document.d.ts +1 -1
  42. package/dist/document.js +17 -11
  43. package/dist/{embedded-font-Bnhh4juV.d.ts → embedded-font-ByD7ZiQS.d.ts} +1 -1
  44. package/dist/{embedded-font-CEf-zBCA.d.cts → embedded-font-DgVBedw6.d.cts} +1 -1
  45. package/dist/embedded-font-write.d.cts +2 -2
  46. package/dist/embedded-font-write.d.ts +2 -2
  47. package/dist/embedded-font.cjs +4 -2
  48. package/dist/embedded-font.d.cts +1 -1
  49. package/dist/embedded-font.d.ts +1 -1
  50. package/dist/embedded-font.js +4 -2
  51. package/dist/encoding.cjs +1 -1
  52. package/dist/encoding.js +1 -1
  53. package/dist/encrypt-write.cjs +25 -21
  54. package/dist/encrypt-write.d.cts +1 -1
  55. package/dist/encrypt-write.d.ts +1 -1
  56. package/dist/encrypt-write.js +25 -21
  57. package/dist/encrypt.cjs +43 -64
  58. package/dist/encrypt.d.cts +1 -1
  59. package/dist/encrypt.d.ts +1 -1
  60. package/dist/encrypt.js +43 -64
  61. package/dist/filters.cjs +46 -26
  62. package/dist/filters.d.cts +1 -1
  63. package/dist/filters.d.ts +1 -1
  64. package/dist/filters.js +46 -26
  65. package/dist/font-face.cjs +2 -1
  66. package/dist/font-face.js +2 -1
  67. package/dist/font-read.cjs +12 -6
  68. package/dist/font-read.d.cts +1 -1
  69. package/dist/font-read.d.ts +1 -1
  70. package/dist/font-read.js +12 -6
  71. package/dist/font-registry.d.cts +3 -3
  72. package/dist/font-registry.d.ts +3 -3
  73. package/dist/font-tables.cjs +55 -28
  74. package/dist/font-tables.js +55 -28
  75. package/dist/form.cjs +13 -8
  76. package/dist/form.d.cts +2 -2
  77. package/dist/form.d.ts +2 -2
  78. package/dist/form.js +13 -8
  79. package/dist/gdef-table.cjs +6 -3
  80. package/dist/gdef-table.js +6 -3
  81. package/dist/{glyf-contours-C0epBNqP.d.ts → glyf-contours-B1PsI9oA.d.ts} +1 -1
  82. package/dist/{glyf-contours-BRpvd0rt.d.cts → glyf-contours-NHBpgks-.d.cts} +1 -1
  83. package/dist/glyf-contours.cjs +3 -1
  84. package/dist/glyf-contours.d.cts +1 -1
  85. package/dist/glyf-contours.d.ts +1 -1
  86. package/dist/glyf-contours.js +3 -1
  87. package/dist/glyf.cjs +22 -11
  88. package/dist/glyf.js +22 -11
  89. package/dist/gpos-table.cjs +37 -19
  90. package/dist/gpos-table.js +37 -19
  91. package/dist/gsub-table.cjs +40 -25
  92. package/dist/gsub-table.js +40 -25
  93. package/dist/hmtx-table.cjs +5 -3
  94. package/dist/hmtx-table.js +5 -3
  95. package/dist/image/ccitt-encode.cjs +8 -5
  96. package/dist/image/ccitt-encode.js +8 -5
  97. package/dist/image/ccitt.cjs +801 -209
  98. package/dist/image/ccitt.js +801 -209
  99. package/dist/image/jbig2-arith.cjs +340 -306
  100. package/dist/image/jbig2-arith.js +340 -306
  101. package/dist/image/jbig2-bitmap.cjs +8 -5
  102. package/dist/image/jbig2-bitmap.js +8 -5
  103. package/dist/image/jbig2-generic.cjs +240 -69
  104. package/dist/image/jbig2-generic.js +240 -69
  105. package/dist/image/jbig2-text.cjs +4 -2
  106. package/dist/image/jbig2-text.js +4 -2
  107. package/dist/image/jbig2.cjs +69 -31
  108. package/dist/image/jbig2.js +69 -31
  109. package/dist/image/jp2-boxes.cjs +52 -27
  110. package/dist/image/jp2-boxes.js +52 -27
  111. package/dist/image/jpeg-info.cjs +29 -24
  112. package/dist/image/jpeg-info.js +29 -24
  113. package/dist/image/jpeg2000-codestream.cjs +61 -32
  114. package/dist/image/jpeg2000-codestream.js +61 -32
  115. package/dist/image/jpeg2000-dwt.cjs +2 -1
  116. package/dist/image/jpeg2000-dwt.js +2 -1
  117. package/dist/image/jpeg2000-t1.cjs +21 -11
  118. package/dist/image/jpeg2000-t1.js +21 -11
  119. package/dist/image/jpeg2000-t2.cjs +12 -5
  120. package/dist/image/jpeg2000-t2.js +12 -5
  121. package/dist/image/jpeg2000-tagtree.cjs +8 -4
  122. package/dist/image/jpeg2000-tagtree.js +8 -4
  123. package/dist/image/jpeg2000.cjs +11 -6
  124. package/dist/image/jpeg2000.js +11 -6
  125. package/dist/image/png-decode.cjs +62 -39
  126. package/dist/image/png-decode.d.cts +3 -2
  127. package/dist/image/png-decode.d.ts +3 -2
  128. package/dist/image/png-decode.js +62 -39
  129. package/dist/image/png-filter.cjs +23 -15
  130. package/dist/image/png-filter.js +23 -15
  131. package/dist/images-read.cjs +41 -36
  132. package/dist/images-read.d.cts +2 -2
  133. package/dist/images-read.d.ts +2 -2
  134. package/dist/images-read.js +41 -36
  135. package/dist/index.cjs +1 -1
  136. package/dist/index.d.cts +1 -1
  137. package/dist/index.d.ts +1 -1
  138. package/dist/index.js +1 -1
  139. package/dist/interpret.cjs +68 -40
  140. package/dist/interpret.d.cts +1 -1
  141. package/dist/interpret.d.ts +1 -1
  142. package/dist/interpret.js +68 -40
  143. package/dist/lexer.cjs +86 -51
  144. package/dist/lexer.js +86 -51
  145. package/dist/math-content-write.cjs +9 -5
  146. package/dist/math-content-write.js +9 -5
  147. package/dist/math-font-write.cjs +2 -1
  148. package/dist/math-font-write.d.cts +1 -1
  149. package/dist/math-font-write.d.ts +1 -1
  150. package/dist/math-font-write.js +2 -1
  151. package/dist/math-font.cjs +16 -7
  152. package/dist/math-font.js +16 -7
  153. package/dist/math-table.cjs +25 -13
  154. package/dist/math-table.js +25 -13
  155. package/dist/matrix.cjs +3 -2
  156. package/dist/matrix.js +3 -2
  157. package/dist/measure.cjs +1 -1
  158. package/dist/measure.js +1 -1
  159. package/dist/names.cjs +7 -7
  160. package/dist/names.d.cts +2 -2
  161. package/dist/names.d.ts +2 -2
  162. package/dist/names.js +7 -7
  163. package/dist/navigation.cjs +16 -12
  164. package/dist/navigation.d.cts +4 -4
  165. package/dist/navigation.d.ts +4 -4
  166. package/dist/navigation.js +16 -12
  167. package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.cts} +3 -3
  168. package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.ts} +3 -3
  169. package/dist/objects.d.cts +1 -1
  170. package/dist/objects.d.ts +1 -1
  171. package/dist/optional-content.d.cts +2 -2
  172. package/dist/optional-content.d.ts +2 -2
  173. package/dist/ot-layout-common.cjs +22 -15
  174. package/dist/ot-layout-common.js +22 -15
  175. package/dist/parse.cjs +7 -5
  176. package/dist/parse.d.cts +1 -1
  177. package/dist/parse.d.ts +1 -1
  178. package/dist/parse.js +7 -5
  179. package/dist/pdf-text.cjs +5 -2
  180. package/dist/pdf-text.js +5 -2
  181. package/dist/predictors.cjs +14 -9
  182. package/dist/predictors.d.cts +1 -1
  183. package/dist/predictors.d.ts +1 -1
  184. package/dist/predictors.js +14 -9
  185. package/dist/raster.cjs +30 -19
  186. package/dist/raster.d.cts +8 -8
  187. package/dist/raster.d.ts +8 -8
  188. package/dist/raster.js +30 -19
  189. package/dist/read.cjs +29 -16
  190. package/dist/read.js +29 -16
  191. package/dist/serialize.cjs +6 -2
  192. package/dist/serialize.d.cts +1 -1
  193. package/dist/serialize.d.ts +1 -1
  194. package/dist/serialize.js +6 -2
  195. package/dist/sfnt-subset.cjs +25 -13
  196. package/dist/sfnt-subset.d.cts +1 -1
  197. package/dist/sfnt-subset.d.ts +1 -1
  198. package/dist/sfnt-subset.js +25 -13
  199. package/dist/sfnt.cjs +20 -10
  200. package/dist/sfnt.js +20 -10
  201. package/dist/structure.d.cts +2 -2
  202. package/dist/structure.d.ts +2 -2
  203. package/dist/text-group.cjs +0 -1
  204. package/dist/text-group.js +0 -1
  205. package/dist/text-layout.d.cts +1 -1
  206. package/dist/text-layout.d.ts +1 -1
  207. package/dist/tounicode.cjs +4 -2
  208. package/dist/tounicode.d.cts +1 -1
  209. package/dist/tounicode.d.ts +1 -1
  210. package/dist/tounicode.js +4 -2
  211. package/dist/winansi.cjs +1 -1
  212. package/dist/winansi.js +1 -1
  213. package/dist/write.cjs +20 -12
  214. package/dist/write.d.cts +1 -1
  215. package/dist/write.d.ts +1 -1
  216. package/dist/write.js +20 -12
  217. package/dist/xref.cjs +5 -2
  218. package/dist/xref.d.cts +1 -1
  219. package/dist/xref.d.ts +1 -1
  220. package/dist/xref.js +5 -2
  221. package/package.json +1 -1
package/dist/matrix.js CHANGED
@@ -47,8 +47,9 @@ function scaleMatrix(sx, sy) {
47
47
  ];
48
48
  }
49
49
  const BEZIER_KAPPA = .5522847498;
50
+ const DEGREES_PER_HALF_TURN = 180;
50
51
  function rotationMatrix(degrees) {
51
- const radians = degrees * Math.PI / 180;
52
+ const radians = degrees * Math.PI / DEGREES_PER_HALF_TURN;
52
53
  const cos = Math.cos(radians);
53
54
  const sin = Math.sin(radians);
54
55
  return [
@@ -67,7 +68,7 @@ function matrixScaleY(m) {
67
68
  return Math.hypot(m[2], m[3]);
68
69
  }
69
70
  function matrixRotationDegrees(m) {
70
- return Math.atan2(m[1], m[0]) * 180 / Math.PI;
71
+ return Math.atan2(m[1], m[0]) * DEGREES_PER_HALF_TURN / Math.PI;
71
72
  }
72
73
  function rotatePointAboutCenter(point, center, degrees) {
73
74
  const relative = {
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-BYiX2L9D.cjs");
2
+ const require_afm_widths = require("./afm-widths-BHD2HZIL.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-blUDDjlI.js";
1
+ import { h as encodeForShow, t as STANDARD_METRICS } from "./afm-widths-B_IGbGky.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 };
@@ -6,6 +6,11 @@ const require_names = require("./names.cjs");
6
6
  function coordinateAt(arr, index) {
7
7
  return require_objects.asNumber(arr[index]);
8
8
  }
9
+ const DEST_XYZ_TOP_INDEX = 3;
10
+ const DEST_XYZ_ZOOM_INDEX = 4;
11
+ const DEST_FITR_BOTTOM_INDEX = 3;
12
+ const DEST_FITR_RIGHT_INDEX = 4;
13
+ const DEST_FITR_TOP_INDEX = 5;
9
14
  function parseDestination(value, resolver, pageIndex, sink) {
10
15
  const arr = require_objects.asArray(resolver.resolve(value));
11
16
  if (arr === void 0 || arr.length < 2) {
@@ -33,8 +38,8 @@ function parseDestination(value, resolver, pageIndex, sink) {
33
38
  kind: "xyz",
34
39
  ...optionalCoords(arr, [
35
40
  ["leftPt", 2],
36
- ["topPt", 3],
37
- ["zoom", 4]
41
+ ["topPt", DEST_XYZ_TOP_INDEX],
42
+ ["zoom", DEST_XYZ_ZOOM_INDEX]
38
43
  ])
39
44
  }
40
45
  };
@@ -62,9 +67,9 @@ function parseDestination(value, resolver, pageIndex, sink) {
62
67
  kind: "fitR",
63
68
  ...optionalCoords(arr, [
64
69
  ["leftPt", 2],
65
- ["bottomPt", 3],
66
- ["rightPt", 4],
67
- ["topPt", 5]
70
+ ["bottomPt", DEST_FITR_BOTTOM_INDEX],
71
+ ["rightPt", DEST_FITR_RIGHT_INDEX],
72
+ ["topPt", DEST_FITR_TOP_INDEX]
68
73
  ])
69
74
  }
70
75
  };
@@ -161,11 +166,10 @@ function readOutline(catalog, registry, resolver, sink) {
161
166
  const root = resolver.resolveDict(require_objects.dictGet(catalog, "Outlines"));
162
167
  const first = root === void 0 ? void 0 : resolver.resolveDict(require_objects.dictGet(root, "First"));
163
168
  if (first === void 0) return [];
164
- const items = [];
165
- walkOutlineSiblings(first, items, registry, resolver, sink, /* @__PURE__ */ new Set());
166
- return items;
169
+ return walkOutlineSiblings(first, registry, resolver, sink, /* @__PURE__ */ new Set());
167
170
  }
168
- function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
171
+ function walkOutlineSiblings(node, registry, resolver, sink, visited) {
172
+ const out = [];
169
173
  let current = node;
170
174
  while (current !== void 0) {
171
175
  if (visited.has(current)) {
@@ -174,13 +178,12 @@ function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
174
178
  severity: "warning",
175
179
  message: "the outline contains a cycle; stopping the sibling chain at the repeated item"
176
180
  });
177
- return;
181
+ return out;
178
182
  }
179
183
  visited.add(current);
180
184
  const titleObj = require_objects.dictGet(current, "Title");
181
- const children = [];
182
185
  const childFirst = resolver.resolveDict(require_objects.dictGet(current, "First"));
183
- if (childFirst !== void 0) walkOutlineSiblings(childFirst, children, registry, resolver, sink, visited);
186
+ const children = childFirst === void 0 ? [] : walkOutlineSiblings(childFirst, registry, resolver, sink, visited);
184
187
  const destination = internOutlineDestination(current, registry, resolver);
185
188
  out.push({
186
189
  title: titleObj?.kind === "string" ? require_pdf_text.decodePdfString(titleObj.bytes) : "",
@@ -189,6 +192,7 @@ function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
189
192
  });
190
193
  current = resolver.resolveDict(require_objects.dictGet(current, "Next"));
191
194
  }
195
+ return out;
192
196
  }
193
197
  function internOutlineDestination(node, registry, resolver) {
194
198
  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 };
@@ -5,6 +5,11 @@ import { walkNameTree } from "./names.js";
5
5
  function coordinateAt(arr, index) {
6
6
  return asNumber(arr[index]);
7
7
  }
8
+ const DEST_XYZ_TOP_INDEX = 3;
9
+ const DEST_XYZ_ZOOM_INDEX = 4;
10
+ const DEST_FITR_BOTTOM_INDEX = 3;
11
+ const DEST_FITR_RIGHT_INDEX = 4;
12
+ const DEST_FITR_TOP_INDEX = 5;
8
13
  function parseDestination(value, resolver, pageIndex, sink) {
9
14
  const arr = asArray(resolver.resolve(value));
10
15
  if (arr === void 0 || arr.length < 2) {
@@ -32,8 +37,8 @@ function parseDestination(value, resolver, pageIndex, sink) {
32
37
  kind: "xyz",
33
38
  ...optionalCoords(arr, [
34
39
  ["leftPt", 2],
35
- ["topPt", 3],
36
- ["zoom", 4]
40
+ ["topPt", DEST_XYZ_TOP_INDEX],
41
+ ["zoom", DEST_XYZ_ZOOM_INDEX]
37
42
  ])
38
43
  }
39
44
  };
@@ -61,9 +66,9 @@ function parseDestination(value, resolver, pageIndex, sink) {
61
66
  kind: "fitR",
62
67
  ...optionalCoords(arr, [
63
68
  ["leftPt", 2],
64
- ["bottomPt", 3],
65
- ["rightPt", 4],
66
- ["topPt", 5]
69
+ ["bottomPt", DEST_FITR_BOTTOM_INDEX],
70
+ ["rightPt", DEST_FITR_RIGHT_INDEX],
71
+ ["topPt", DEST_FITR_TOP_INDEX]
67
72
  ])
68
73
  }
69
74
  };
@@ -160,11 +165,10 @@ function readOutline(catalog, registry, resolver, sink) {
160
165
  const root = resolver.resolveDict(dictGet(catalog, "Outlines"));
161
166
  const first = root === void 0 ? void 0 : resolver.resolveDict(dictGet(root, "First"));
162
167
  if (first === void 0) return [];
163
- const items = [];
164
- walkOutlineSiblings(first, items, registry, resolver, sink, /* @__PURE__ */ new Set());
165
- return items;
168
+ return walkOutlineSiblings(first, registry, resolver, sink, /* @__PURE__ */ new Set());
166
169
  }
167
- function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
170
+ function walkOutlineSiblings(node, registry, resolver, sink, visited) {
171
+ const out = [];
168
172
  let current = node;
169
173
  while (current !== void 0) {
170
174
  if (visited.has(current)) {
@@ -173,13 +177,12 @@ function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
173
177
  severity: "warning",
174
178
  message: "the outline contains a cycle; stopping the sibling chain at the repeated item"
175
179
  });
176
- return;
180
+ return out;
177
181
  }
178
182
  visited.add(current);
179
183
  const titleObj = dictGet(current, "Title");
180
- const children = [];
181
184
  const childFirst = resolver.resolveDict(dictGet(current, "First"));
182
- if (childFirst !== void 0) walkOutlineSiblings(childFirst, children, registry, resolver, sink, visited);
185
+ const children = childFirst === void 0 ? [] : walkOutlineSiblings(childFirst, registry, resolver, sink, visited);
183
186
  const destination = internOutlineDestination(current, registry, resolver);
184
187
  out.push({
185
188
  title: titleObj?.kind === "string" ? decodePdfString(titleObj.bytes) : "",
@@ -188,6 +191,7 @@ function walkOutlineSiblings(node, out, registry, resolver, sink, visited) {
188
191
  });
189
192
  current = resolver.resolveDict(dictGet(current, "Next"));
190
193
  }
194
+ return out;
191
195
  }
192
196
  function internOutlineDestination(node, registry, resolver) {
193
197
  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,23 +12,21 @@ 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;
29
+ const RANGE_RECORD_VALUE_OFFSET = 4;
32
30
  function parseRangeRecords(bytes, recordsOffset, recordCount) {
33
31
  if (!require_sfnt.hasBytes(bytes, recordsOffset, recordCount * RANGE_RECORD_SIZE)) return;
34
32
  const ranges = [];
@@ -40,7 +38,7 @@ function parseRangeRecords(bytes, recordsOffset, recordCount) {
40
38
  ranges.push({
41
39
  startGlyphId,
42
40
  endGlyphId,
43
- value: require_sfnt.u16(bytes, recordOffset + 4)
41
+ value: require_sfnt.u16(bytes, recordOffset + RANGE_RECORD_VALUE_OFFSET)
44
42
  });
45
43
  }
46
44
  ranges.sort((a, b) => a.startGlyphId - b.startGlyphId);
@@ -56,7 +54,11 @@ function parseCoverage(bytes, coverageOffset) {
56
54
  const glyphArrayOffset = coverageOffset + COVERAGE_HEADER_SIZE;
57
55
  if (!require_sfnt.hasBytes(bytes, glyphArrayOffset, count * 2)) return;
58
56
  ranges = [];
59
- for (let i = 0; i < count; i++) pushGlyph(ranges, require_sfnt.u16(bytes, glyphArrayOffset + i * 2), i, 1);
57
+ for (let i = 0; i < count; i++) {
58
+ const placement = placeGlyph(ranges, require_sfnt.u16(bytes, glyphArrayOffset + i * 2), i, 1);
59
+ if (placement.extended !== void 0) ranges[ranges.length - 1] = placement.extended;
60
+ else ranges.push(placement.fresh);
61
+ }
60
62
  ranges.sort((a, b) => a.startGlyphId - b.startGlyphId);
61
63
  } else if (format === 2) ranges = parseRangeRecords(bytes, coverageOffset + COVERAGE_HEADER_SIZE, count);
62
64
  if (ranges === void 0) return;
@@ -72,6 +74,7 @@ function parseCoverage(bytes, coverageOffset) {
72
74
  };
73
75
  }
74
76
  const CLASS_DEF_FORMAT_1_HEADER_SIZE = 6;
77
+ const CLASS_DEF_FORMAT_1_GLYPH_COUNT_OFFSET = 4;
75
78
  const CLASS_DEF_FORMAT_2_HEADER_SIZE = 4;
76
79
  function parseClassDef(bytes, classDefOffset) {
77
80
  if (!require_sfnt.hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_2_HEADER_SIZE)) return;
@@ -80,11 +83,15 @@ function parseClassDef(bytes, classDefOffset) {
80
83
  if (format === 1) {
81
84
  if (!require_sfnt.hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_1_HEADER_SIZE)) return;
82
85
  const startGlyphId = require_sfnt.u16(bytes, classDefOffset + 2);
83
- const glyphCount = require_sfnt.u16(bytes, classDefOffset + 4);
86
+ const glyphCount = require_sfnt.u16(bytes, classDefOffset + CLASS_DEF_FORMAT_1_GLYPH_COUNT_OFFSET);
84
87
  const classArrayOffset = classDefOffset + CLASS_DEF_FORMAT_1_HEADER_SIZE;
85
88
  if (!require_sfnt.hasBytes(bytes, classArrayOffset, glyphCount * 2)) return;
86
89
  ranges = [];
87
- for (let i = 0; i < glyphCount; i++) pushGlyph(ranges, startGlyphId + i, require_sfnt.u16(bytes, classArrayOffset + i * 2), 0);
90
+ for (let i = 0; i < glyphCount; i++) {
91
+ const placement = placeGlyph(ranges, startGlyphId + i, require_sfnt.u16(bytes, classArrayOffset + i * 2), 0);
92
+ if (placement.extended !== void 0) ranges[ranges.length - 1] = placement.extended;
93
+ else ranges.push(placement.fresh);
94
+ }
88
95
  } else if (format === 2) ranges = parseRangeRecords(bytes, classDefOffset + CLASS_DEF_FORMAT_2_HEADER_SIZE, require_sfnt.u16(bytes, classDefOffset + 2));
89
96
  if (ranges === void 0) return;
90
97
  const resolved = ranges;
@@ -11,23 +11,21 @@ function findRange(ranges, glyphId) {
11
11
  else return range;
12
12
  }
13
13
  }
14
- function pushGlyph(ranges, glyphId, value, valueStep) {
14
+ function placeGlyph(ranges, glyphId, value, valueStep) {
15
15
  const previous = ranges[ranges.length - 1];
16
- if (previous !== void 0 && glyphId === previous.endGlyphId + 1 && value === previous.value + (previous.endGlyphId - previous.startGlyphId + 1) * valueStep) {
17
- ranges[ranges.length - 1] = {
18
- startGlyphId: previous.startGlyphId,
19
- endGlyphId: glyphId,
20
- value: previous.value
21
- };
22
- return;
23
- }
24
- ranges.push({
16
+ if (previous !== void 0 && glyphId === previous.endGlyphId + 1 && value === previous.value + (previous.endGlyphId - previous.startGlyphId + 1) * valueStep) return { extended: {
17
+ startGlyphId: previous.startGlyphId,
18
+ endGlyphId: glyphId,
19
+ value: previous.value
20
+ } };
21
+ return { fresh: {
25
22
  startGlyphId: glyphId,
26
23
  endGlyphId: glyphId,
27
24
  value
28
- });
25
+ } };
29
26
  }
30
27
  const RANGE_RECORD_SIZE = 6;
28
+ const RANGE_RECORD_VALUE_OFFSET = 4;
31
29
  function parseRangeRecords(bytes, recordsOffset, recordCount) {
32
30
  if (!hasBytes(bytes, recordsOffset, recordCount * RANGE_RECORD_SIZE)) return;
33
31
  const ranges = [];
@@ -39,7 +37,7 @@ function parseRangeRecords(bytes, recordsOffset, recordCount) {
39
37
  ranges.push({
40
38
  startGlyphId,
41
39
  endGlyphId,
42
- value: u16(bytes, recordOffset + 4)
40
+ value: u16(bytes, recordOffset + RANGE_RECORD_VALUE_OFFSET)
43
41
  });
44
42
  }
45
43
  ranges.sort((a, b) => a.startGlyphId - b.startGlyphId);
@@ -55,7 +53,11 @@ function parseCoverage(bytes, coverageOffset) {
55
53
  const glyphArrayOffset = coverageOffset + COVERAGE_HEADER_SIZE;
56
54
  if (!hasBytes(bytes, glyphArrayOffset, count * 2)) return;
57
55
  ranges = [];
58
- for (let i = 0; i < count; i++) pushGlyph(ranges, u16(bytes, glyphArrayOffset + i * 2), i, 1);
56
+ for (let i = 0; i < count; i++) {
57
+ const placement = placeGlyph(ranges, 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
+ }
59
61
  ranges.sort((a, b) => a.startGlyphId - b.startGlyphId);
60
62
  } else if (format === 2) ranges = parseRangeRecords(bytes, coverageOffset + COVERAGE_HEADER_SIZE, count);
61
63
  if (ranges === void 0) return;
@@ -71,6 +73,7 @@ function parseCoverage(bytes, coverageOffset) {
71
73
  };
72
74
  }
73
75
  const CLASS_DEF_FORMAT_1_HEADER_SIZE = 6;
76
+ const CLASS_DEF_FORMAT_1_GLYPH_COUNT_OFFSET = 4;
74
77
  const CLASS_DEF_FORMAT_2_HEADER_SIZE = 4;
75
78
  function parseClassDef(bytes, classDefOffset) {
76
79
  if (!hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_2_HEADER_SIZE)) return;
@@ -79,11 +82,15 @@ function parseClassDef(bytes, classDefOffset) {
79
82
  if (format === 1) {
80
83
  if (!hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_1_HEADER_SIZE)) return;
81
84
  const startGlyphId = u16(bytes, classDefOffset + 2);
82
- const glyphCount = u16(bytes, classDefOffset + 4);
85
+ const glyphCount = u16(bytes, classDefOffset + CLASS_DEF_FORMAT_1_GLYPH_COUNT_OFFSET);
83
86
  const classArrayOffset = classDefOffset + CLASS_DEF_FORMAT_1_HEADER_SIZE;
84
87
  if (!hasBytes(bytes, classArrayOffset, glyphCount * 2)) return;
85
88
  ranges = [];
86
- for (let i = 0; i < glyphCount; i++) pushGlyph(ranges, startGlyphId + i, u16(bytes, classArrayOffset + i * 2), 0);
89
+ for (let i = 0; i < glyphCount; i++) {
90
+ const placement = placeGlyph(ranges, startGlyphId + i, u16(bytes, classArrayOffset + i * 2), 0);
91
+ if (placement.extended !== void 0) ranges[ranges.length - 1] = placement.extended;
92
+ else ranges.push(placement.fresh);
93
+ }
87
94
  } else if (format === 2) ranges = parseRangeRecords(bytes, classDefOffset + CLASS_DEF_FORMAT_2_HEADER_SIZE, u16(bytes, classDefOffset + 2));
88
95
  if (ranges === void 0) return;
89
96
  const resolved = ranges;
package/dist/parse.cjs CHANGED
@@ -110,10 +110,12 @@ function parseDictOrStreamBody(reader, sink) {
110
110
  reader.reset(afterDictMark);
111
111
  return dict;
112
112
  }
113
+ const CARRIAGE_RETURN = 13;
114
+ const LINE_FEED = 10;
113
115
  function skipStreamDataStart(reader, sink) {
114
- if (reader.peek() === 13) {
116
+ if (reader.peek() === CARRIAGE_RETURN) {
115
117
  reader.next();
116
- if (reader.peek() === 10) reader.next();
118
+ if (reader.peek() === LINE_FEED) reader.next();
117
119
  else sink({
118
120
  code: "pdf/stream-bad-eol",
119
121
  severity: "warning",
@@ -121,7 +123,7 @@ function skipStreamDataStart(reader, sink) {
121
123
  });
122
124
  return;
123
125
  }
124
- if (reader.peek() === 10) {
126
+ if (reader.peek() === LINE_FEED) {
125
127
  reader.next();
126
128
  return;
127
129
  }
@@ -187,8 +189,8 @@ function findEndstreamOffset(reader, fromOffset) {
187
189
  }
188
190
  function trimTrailingStreamEol(reader, dataStart, endstreamOffset) {
189
191
  const precedingTwo = reader.slice(Math.max(dataStart, endstreamOffset - 2), endstreamOffset);
190
- if (precedingTwo.length >= 2 && precedingTwo[precedingTwo.length - 2] === 13 && precedingTwo[precedingTwo.length - 1] === 10) return endstreamOffset - 2;
191
- if (precedingTwo.length >= 1 && (precedingTwo[precedingTwo.length - 1] === 10 || precedingTwo[precedingTwo.length - 1] === 13)) return endstreamOffset - 1;
192
+ if (precedingTwo.length >= 2 && precedingTwo[precedingTwo.length - 2] === CARRIAGE_RETURN && precedingTwo[precedingTwo.length - 1] === LINE_FEED) return endstreamOffset - 2;
193
+ if (precedingTwo.length >= 1 && (precedingTwo[precedingTwo.length - 1] === LINE_FEED || precedingTwo[precedingTwo.length - 1] === CARRIAGE_RETURN)) return endstreamOffset - 1;
192
194
  return endstreamOffset;
193
195
  }
194
196
  function parseIndirectObject(reader, sink) {