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
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/text-group.ts
3
2
  const DEFAULT_BASELINE_TOLERANCE_EM = 2 / 3;
4
3
  const DEFAULT_WORD_GAP_EM = 1 / 8;
5
4
  const DEFAULT_COLUMN_GAP_EM = 1;
@@ -1,4 +1,3 @@
1
- //#region src/text-group.ts
2
1
  const DEFAULT_BASELINE_TOLERANCE_EM = 2 / 3;
3
2
  const DEFAULT_WORD_GAP_EM = 1 / 8;
4
3
  const DEFAULT_COLUMN_GAP_EM = 1;
@@ -1,6 +1,6 @@
1
1
  import { Color, LayoutFont, StyledRun, TextMeasurer, WrapOptions, WrappedLine } from "document-schema.js";
2
2
  //#region src/text-layout.d.ts
3
3
  declare function wrapRunsToWidth(runs: readonly StyledRun[], measurer: TextMeasurer, maxWidthPt: number, options?: WrapOptions): WrappedLine[];
4
- declare function wrapTextToWidth(text: string, font: LayoutFont, sizePt: number, color: Color, measurer: TextMeasurer, maxWidthPt: number): string[];
4
+ declare function wrapTextToWidth(text: string, font: Readonly<LayoutFont>, sizePt: number, color: Readonly<Color>, measurer: TextMeasurer, maxWidthPt: number): string[];
5
5
  //#endregion
6
6
  export { wrapRunsToWidth, wrapTextToWidth };
@@ -1,6 +1,6 @@
1
1
  import { Color, LayoutFont, StyledRun, TextMeasurer, WrapOptions, WrappedLine } from "document-schema.js";
2
2
  //#region src/text-layout.d.ts
3
3
  declare function wrapRunsToWidth(runs: readonly StyledRun[], measurer: TextMeasurer, maxWidthPt: number, options?: WrapOptions): WrappedLine[];
4
- declare function wrapTextToWidth(text: string, font: LayoutFont, sizePt: number, color: Color, measurer: TextMeasurer, maxWidthPt: number): string[];
4
+ declare function wrapTextToWidth(text: string, font: Readonly<LayoutFont>, sizePt: number, color: Readonly<Color>, measurer: TextMeasurer, maxWidthPt: number): string[];
5
5
  //#endregion
6
6
  export { wrapRunsToWidth, wrapTextToWidth };
@@ -2,10 +2,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_objects = require("./objects.cjs");
3
3
  //#region src/tounicode.ts
4
4
  const MAX_BFCHAR_ENTRIES_PER_BLOCK = 100;
5
+ const HEX_RADIX = 16;
6
+ const UTF16_HEX_DIGIT_WIDTH = 4;
5
7
  function codePointToUtf16BEHex(codePoint) {
6
8
  const text = String.fromCodePoint(codePoint);
7
9
  let hex = "";
8
- for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(16).padStart(4, "0");
10
+ for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(HEX_RADIX).padStart(UTF16_HEX_DIGIT_WIDTH, "0");
9
11
  return hex;
10
12
  }
11
13
  function sequenceToUtf16BEHex(codePoints) {
@@ -29,7 +31,7 @@ function buildToUnicodeCMap(codeToSequence) {
29
31
  for (let start = 0; start < entries.length; start += MAX_BFCHAR_ENTRIES_PER_BLOCK) {
30
32
  const block = entries.slice(start, start + MAX_BFCHAR_ENTRIES_PER_BLOCK);
31
33
  lines.push(`${block.length} beginbfchar`);
32
- for (const [code, sequence] of block) lines.push(`<${code.toString(16).padStart(4, "0")}> <${sequenceToUtf16BEHex(sequence)}>`);
34
+ for (const [code, sequence] of block) lines.push(`<${code.toString(HEX_RADIX).padStart(UTF16_HEX_DIGIT_WIDTH, "0")}> <${sequenceToUtf16BEHex(sequence)}>`);
33
35
  lines.push("endbfchar");
34
36
  }
35
37
  lines.push("endcmap", "CMapName currentdict /CMap defineresource pop", "end", "end");
@@ -1,4 +1,4 @@
1
- import { r as PdfObject } from "./objects-B7HdMeWS.cjs";
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
2
  //#region src/tounicode.d.ts
3
3
  declare function buildToUnicodeCMap(codeToSequence: ReadonlyMap<number, readonly number[]>): PdfObject;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { r as PdfObject } from "./objects-B7HdMeWS.js";
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.js";
2
2
  //#region src/tounicode.d.ts
3
3
  declare function buildToUnicodeCMap(codeToSequence: ReadonlyMap<number, readonly number[]>): PdfObject;
4
4
  //#endregion
package/dist/tounicode.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { pdfDict, pdfStream } from "./objects.js";
2
2
  //#region src/tounicode.ts
3
3
  const MAX_BFCHAR_ENTRIES_PER_BLOCK = 100;
4
+ const HEX_RADIX = 16;
5
+ const UTF16_HEX_DIGIT_WIDTH = 4;
4
6
  function codePointToUtf16BEHex(codePoint) {
5
7
  const text = String.fromCodePoint(codePoint);
6
8
  let hex = "";
7
- for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(16).padStart(4, "0");
9
+ for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(HEX_RADIX).padStart(UTF16_HEX_DIGIT_WIDTH, "0");
8
10
  return hex;
9
11
  }
10
12
  function sequenceToUtf16BEHex(codePoints) {
@@ -28,7 +30,7 @@ function buildToUnicodeCMap(codeToSequence) {
28
30
  for (let start = 0; start < entries.length; start += MAX_BFCHAR_ENTRIES_PER_BLOCK) {
29
31
  const block = entries.slice(start, start + MAX_BFCHAR_ENTRIES_PER_BLOCK);
30
32
  lines.push(`${block.length} beginbfchar`);
31
- for (const [code, sequence] of block) lines.push(`<${code.toString(16).padStart(4, "0")}> <${sequenceToUtf16BEHex(sequence)}>`);
33
+ for (const [code, sequence] of block) lines.push(`<${code.toString(HEX_RADIX).padStart(UTF16_HEX_DIGIT_WIDTH, "0")}> <${sequenceToUtf16BEHex(sequence)}>`);
32
34
  lines.push("endbfchar");
33
35
  }
34
36
  lines.push("endcmap", "CMapName currentdict /CMap defineresource pop", "end", "end");
package/dist/winansi.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
  exports.encodeForShow = require_afm_widths.encodeForShow;
4
4
  exports.sanitizeToWinAnsi = require_afm_widths.sanitizeToWinAnsi;
5
5
  exports.winAnsiCodeToUnicode = require_afm_widths.winAnsiCodeToUnicode;
package/dist/winansi.js CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as winAnsiCodeToUnicode, g as sanitizeToWinAnsi, h as encodeForShow } from "./afm-widths-blUDDjlI.js";
1
+ import { _ as winAnsiCodeToUnicode, g as sanitizeToWinAnsi, h as encodeForShow } from "./afm-widths-B_IGbGky.js";
2
2
  export { encodeForShow, sanitizeToWinAnsi, winAnsiCodeToUnicode };
package/dist/write.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_notes_annotation_author = require("./notes-annotation-author.cjs");
4
4
  const require_objects = require("./objects.cjs");
5
5
  const require_bytes_writer = require("./bytes/writer.cjs");
@@ -36,6 +36,11 @@ const FLAG_NONSYMBOLIC = 32;
36
36
  const FLAG_ITALIC = 64;
37
37
  const FLAG_FORCE_BOLD = 262144;
38
38
  const FILE_ID_BYTES = 16;
39
+ const BITS_PER_BYTE = 8;
40
+ const BYTE_SHIFT = Math.log2(BITS_PER_BYTE);
41
+ const BYTE_MASK = 255;
42
+ const PACKED_BIT_MSB_MASK = 128;
43
+ const BIT_INDEX_MASK = 7;
39
44
  function textToPdfString(text) {
40
45
  const bytes = new Uint8Array(2 + text.length * 2);
41
46
  bytes[0] = 254;
@@ -43,8 +48,8 @@ function textToPdfString(text) {
43
48
  let offset = 2;
44
49
  for (const unit of text.split("")) {
45
50
  const code = unit.charCodeAt(0);
46
- bytes[offset] = code >> 8 & 255;
47
- bytes[offset + 1] = code & 255;
51
+ bytes[offset] = code >> BITS_PER_BYTE & BYTE_MASK;
52
+ bytes[offset + 1] = code & BYTE_MASK;
48
53
  offset += 2;
49
54
  }
50
55
  return require_objects.pdfHexString(bytes);
@@ -108,9 +113,10 @@ function buildFontObjects(standardName, descriptorRef) {
108
113
  function codePointsOf(texts) {
109
114
  return new Set(texts.flatMap((text) => [...text].map((character) => character.codePointAt(0))));
110
115
  }
116
+ const JPEG_COMPONENTS_CMYK = 4;
111
117
  function prepareJpegImage(bytes) {
112
118
  const info = require_image_jpeg_info.readJpegInfo(bytes);
113
- const colorSpace = info.components === 1 ? "DeviceGray" : info.components === 4 ? "DeviceCMYK" : "DeviceRGB";
119
+ const colorSpace = info.components === 1 ? "DeviceGray" : info.components === JPEG_COMPONENTS_CMYK ? "DeviceCMYK" : "DeviceRGB";
114
120
  const entries = /* @__PURE__ */ new Map([
115
121
  ["Type", require_objects.pdfName("XObject")],
116
122
  ["Subtype", require_objects.pdfName("Image")],
@@ -120,7 +126,7 @@ function prepareJpegImage(bytes) {
120
126
  ["BitsPerComponent", require_objects.pdfNum(info.precision)],
121
127
  ["Filter", require_objects.pdfName("DCTDecode")]
122
128
  ]);
123
- if (info.components === 4 && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", require_objects.pdfArray([
129
+ if (info.components === JPEG_COMPONENTS_CMYK && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", require_objects.pdfArray([
124
130
  1,
125
131
  0,
126
132
  1,
@@ -142,22 +148,22 @@ function pngImageDict(width, height, colorSpace, compress) {
142
148
  ["Width", require_objects.pdfNum(width)],
143
149
  ["Height", require_objects.pdfNum(height)],
144
150
  ["ColorSpace", require_objects.pdfName(colorSpace)],
145
- ["BitsPerComponent", require_objects.pdfNum(8)]
151
+ ["BitsPerComponent", require_objects.pdfNum(BITS_PER_BYTE)]
146
152
  ]);
147
153
  if (compress) entries.set("Filter", require_objects.pdfName("FlateDecode"));
148
154
  return require_objects.pdfDict(entries);
149
155
  }
150
156
  function packBilevel(raw) {
151
- const rowBytes = raw.width + 7 >> 3;
157
+ const rowBytes = raw.width + BIT_INDEX_MASK >> BYTE_SHIFT;
152
158
  const packed = new Uint8Array(rowBytes * raw.height);
153
159
  const view = new DataView(packed.buffer);
154
160
  for (let index = 0; index < raw.data.length; index++) {
155
161
  const sample = raw.data[index];
156
- if (sample !== 0 && sample !== 255) return;
157
- if (sample === 255) {
162
+ if (sample !== 0 && sample !== BYTE_MASK) return;
163
+ if (sample === BYTE_MASK) {
158
164
  const x = index % raw.width;
159
- const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> 3);
160
- view.setUint8(byteIndex, view.getUint8(byteIndex) | 128 >> (x & 7));
165
+ const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> BYTE_SHIFT);
166
+ view.setUint8(byteIndex, view.getUint8(byteIndex) | PACKED_BIT_MSB_MASK >> (x & BIT_INDEX_MASK));
161
167
  }
162
168
  }
163
169
  return packed;
@@ -323,8 +329,10 @@ function buildNotesAnnotDict(notes) {
323
329
  F: require_objects.pdfNum(NOTES_ANNOTATION_HIDDEN_FLAG)
324
330
  });
325
331
  }
332
+ const XREF_OFFSET_DIGITS = 10;
333
+ const XREF_GENERATION_DIGITS = 5;
326
334
  function xrefEntry(offset, generation, inUse) {
327
- return `${offset.toString().padStart(10, "0")} ${generation.toString().padStart(5, "0")} ${inUse ? "n" : "f"} \n`;
335
+ return `${offset.toString().padStart(XREF_OFFSET_DIGITS, "0")} ${generation.toString().padStart(XREF_GENERATION_DIGITS, "0")} ${inUse ? "n" : "f"} \n`;
328
336
  }
329
337
  function parseResidueRow(residue) {
330
338
  const reader = new require_bytes_reader.ByteReader(new TextEncoder().encode(residue.xml));
package/dist/write.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LayoutDocument } from "./layout.cjs";
2
- import { r as EmbeddedFaceSubstitution } from "./embedded-font-CEf-zBCA.cjs";
2
+ import { r as EmbeddedFaceSubstitution } from "./embedded-font-DgVBedw6.cjs";
3
3
  import { WinAnsiSubstitution } from "./winansi.cjs";
4
4
  import { PdfEncryptionOptions } from "./encrypt-write.cjs";
5
5
  import { FontRegistry } from "./font-registry.cjs";
package/dist/write.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LayoutDocument } from "./layout.js";
2
- import { r as EmbeddedFaceSubstitution } from "./embedded-font-Bnhh4juV.js";
2
+ import { r as EmbeddedFaceSubstitution } from "./embedded-font-ByD7ZiQS.js";
3
3
  import { WinAnsiSubstitution } from "./winansi.js";
4
4
  import { PdfEncryptionOptions } from "./encrypt-write.js";
5
5
  import { FontRegistry } from "./font-registry.js";
package/dist/write.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-blUDDjlI.js";
1
+ import { n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-B_IGbGky.js";
2
2
  import { NOTES_ANNOTATION_AUTHOR } from "./notes-annotation-author.js";
3
3
  import { pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream } from "./objects.js";
4
4
  import { ByteWriter, concatBytes } from "./bytes/writer.js";
@@ -35,6 +35,11 @@ const FLAG_NONSYMBOLIC = 32;
35
35
  const FLAG_ITALIC = 64;
36
36
  const FLAG_FORCE_BOLD = 262144;
37
37
  const FILE_ID_BYTES = 16;
38
+ const BITS_PER_BYTE = 8;
39
+ const BYTE_SHIFT = Math.log2(BITS_PER_BYTE);
40
+ const BYTE_MASK = 255;
41
+ const PACKED_BIT_MSB_MASK = 128;
42
+ const BIT_INDEX_MASK = 7;
38
43
  function textToPdfString(text) {
39
44
  const bytes = new Uint8Array(2 + text.length * 2);
40
45
  bytes[0] = 254;
@@ -42,8 +47,8 @@ function textToPdfString(text) {
42
47
  let offset = 2;
43
48
  for (const unit of text.split("")) {
44
49
  const code = unit.charCodeAt(0);
45
- bytes[offset] = code >> 8 & 255;
46
- bytes[offset + 1] = code & 255;
50
+ bytes[offset] = code >> BITS_PER_BYTE & BYTE_MASK;
51
+ bytes[offset + 1] = code & BYTE_MASK;
47
52
  offset += 2;
48
53
  }
49
54
  return pdfHexString(bytes);
@@ -107,9 +112,10 @@ function buildFontObjects(standardName, descriptorRef) {
107
112
  function codePointsOf(texts) {
108
113
  return new Set(texts.flatMap((text) => [...text].map((character) => character.codePointAt(0))));
109
114
  }
115
+ const JPEG_COMPONENTS_CMYK = 4;
110
116
  function prepareJpegImage(bytes) {
111
117
  const info = readJpegInfo$1(bytes);
112
- const colorSpace = info.components === 1 ? "DeviceGray" : info.components === 4 ? "DeviceCMYK" : "DeviceRGB";
118
+ const colorSpace = info.components === 1 ? "DeviceGray" : info.components === JPEG_COMPONENTS_CMYK ? "DeviceCMYK" : "DeviceRGB";
113
119
  const entries = /* @__PURE__ */ new Map([
114
120
  ["Type", pdfName("XObject")],
115
121
  ["Subtype", pdfName("Image")],
@@ -119,7 +125,7 @@ function prepareJpegImage(bytes) {
119
125
  ["BitsPerComponent", pdfNum(info.precision)],
120
126
  ["Filter", pdfName("DCTDecode")]
121
127
  ]);
122
- if (info.components === 4 && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", pdfArray([
128
+ if (info.components === JPEG_COMPONENTS_CMYK && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", pdfArray([
123
129
  1,
124
130
  0,
125
131
  1,
@@ -141,22 +147,22 @@ function pngImageDict(width, height, colorSpace, compress) {
141
147
  ["Width", pdfNum(width)],
142
148
  ["Height", pdfNum(height)],
143
149
  ["ColorSpace", pdfName(colorSpace)],
144
- ["BitsPerComponent", pdfNum(8)]
150
+ ["BitsPerComponent", pdfNum(BITS_PER_BYTE)]
145
151
  ]);
146
152
  if (compress) entries.set("Filter", pdfName("FlateDecode"));
147
153
  return pdfDict(entries);
148
154
  }
149
155
  function packBilevel(raw) {
150
- const rowBytes = raw.width + 7 >> 3;
156
+ const rowBytes = raw.width + BIT_INDEX_MASK >> BYTE_SHIFT;
151
157
  const packed = new Uint8Array(rowBytes * raw.height);
152
158
  const view = new DataView(packed.buffer);
153
159
  for (let index = 0; index < raw.data.length; index++) {
154
160
  const sample = raw.data[index];
155
- if (sample !== 0 && sample !== 255) return;
156
- if (sample === 255) {
161
+ if (sample !== 0 && sample !== BYTE_MASK) return;
162
+ if (sample === BYTE_MASK) {
157
163
  const x = index % raw.width;
158
- const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> 3);
159
- view.setUint8(byteIndex, view.getUint8(byteIndex) | 128 >> (x & 7));
164
+ const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> BYTE_SHIFT);
165
+ view.setUint8(byteIndex, view.getUint8(byteIndex) | PACKED_BIT_MSB_MASK >> (x & BIT_INDEX_MASK));
160
166
  }
161
167
  }
162
168
  return packed;
@@ -322,8 +328,10 @@ function buildNotesAnnotDict(notes) {
322
328
  F: pdfNum(NOTES_ANNOTATION_HIDDEN_FLAG)
323
329
  });
324
330
  }
331
+ const XREF_OFFSET_DIGITS = 10;
332
+ const XREF_GENERATION_DIGITS = 5;
325
333
  function xrefEntry(offset, generation, inUse) {
326
- return `${offset.toString().padStart(10, "0")} ${generation.toString().padStart(5, "0")} ${inUse ? "n" : "f"} \n`;
334
+ return `${offset.toString().padStart(XREF_OFFSET_DIGITS, "0")} ${generation.toString().padStart(XREF_GENERATION_DIGITS, "0")} ${inUse ? "n" : "f"} \n`;
327
335
  }
328
336
  function parseResidueRow(residue) {
329
337
  const reader = new ByteReader(new TextEncoder().encode(residue.xml));
package/dist/xref.cjs CHANGED
@@ -220,9 +220,10 @@ function readXrefStreamSection(dict, raw, sink) {
220
220
  prevOffset: require_objects.asNumber(require_objects.dictGet(dict, "Prev"))
221
221
  };
222
222
  }
223
+ const BYTE_RADIX = 256;
223
224
  function readBigEndian(bytes, offset, width) {
224
225
  let value = 0;
225
- for (let i = 0; i < width; i++) value = value * 256 + (bytes[offset + i] ?? 0);
226
+ for (let i = 0; i < width; i++) value = value * BYTE_RADIX + (bytes[offset + i] ?? 0);
226
227
  return value;
227
228
  }
228
229
  function isBoundaryByte(byte) {
@@ -238,8 +239,10 @@ function findAllKeywordPositions(bytes, needle) {
238
239
  }
239
240
  return positions;
240
241
  }
242
+ const ASCII_DIGIT_ZERO = 48;
243
+ const ASCII_DIGIT_NINE = 57;
241
244
  function isDigitByte(byte) {
242
- return byte !== void 0 && byte >= 48 && byte <= 57;
245
+ return byte !== void 0 && byte >= ASCII_DIGIT_ZERO && byte <= ASCII_DIGIT_NINE;
243
246
  }
244
247
  function scanBackWhile(bytes, end, predicate) {
245
248
  let i = end;
package/dist/xref.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { n as PdfDict } from "./objects-B7HdMeWS.cjs";
2
+ import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
3
3
  //#region src/xref.d.ts
4
4
  interface XrefOffsetEntry {
5
5
  readonly type: "offset";
package/dist/xref.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { n as PdfDict } from "./objects-B7HdMeWS.js";
2
+ import { n as PdfDict } from "./objects-e2RS3-yT.js";
3
3
  //#region src/xref.d.ts
4
4
  interface XrefOffsetEntry {
5
5
  readonly type: "offset";
package/dist/xref.js CHANGED
@@ -219,9 +219,10 @@ function readXrefStreamSection(dict, raw, sink) {
219
219
  prevOffset: asNumber(dictGet(dict, "Prev"))
220
220
  };
221
221
  }
222
+ const BYTE_RADIX = 256;
222
223
  function readBigEndian(bytes, offset, width) {
223
224
  let value = 0;
224
- for (let i = 0; i < width; i++) value = value * 256 + (bytes[offset + i] ?? 0);
225
+ for (let i = 0; i < width; i++) value = value * BYTE_RADIX + (bytes[offset + i] ?? 0);
225
226
  return value;
226
227
  }
227
228
  function isBoundaryByte(byte) {
@@ -237,8 +238,10 @@ function findAllKeywordPositions(bytes, needle) {
237
238
  }
238
239
  return positions;
239
240
  }
241
+ const ASCII_DIGIT_ZERO = 48;
242
+ const ASCII_DIGIT_NINE = 57;
240
243
  function isDigitByte(byte) {
241
- return byte !== void 0 && byte >= 48 && byte <= 57;
244
+ return byte !== void 0 && byte >= ASCII_DIGIT_ZERO && byte <= ASCII_DIGIT_NINE;
242
245
  }
243
246
  function scanBackWhile(bytes, end, predicate) {
244
247
  let i = end;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-parser.js",
3
- "version": "5.2.26",
3
+ "version": "5.2.28",
4
4
  "description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {