pdf-parser.js 3.0.7 → 4.5.1

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 (240) hide show
  1. package/README.md +105 -54
  2. package/dist/{afm-widths-Dxucrg7D.js → afm-widths-BTu0IDp2.cjs} +1517 -4
  3. package/dist/{afm-widths-DyDq56Ph.d.cts → afm-widths-CneRyu5l.d.cts} +1 -1
  4. package/dist/{afm-widths-DyDq56Ph.d.ts → afm-widths-CneRyu5l.d.ts} +1 -1
  5. package/dist/{afm-widths-BoeTOK2r.cjs → afm-widths-De_QMWgC.js} +1416 -51
  6. package/dist/afm-widths.cjs +1 -1
  7. package/dist/afm-widths.d.cts +1 -1
  8. package/dist/afm-widths.d.ts +1 -1
  9. package/dist/afm-widths.js +1 -1
  10. package/dist/annotations.cjs +104 -0
  11. package/dist/annotations.d.cts +9 -0
  12. package/dist/annotations.d.ts +9 -0
  13. package/dist/annotations.js +103 -0
  14. package/dist/attachments.cjs +65 -0
  15. package/dist/attachments.d.cts +8 -0
  16. package/dist/attachments.d.ts +8 -0
  17. package/dist/attachments.js +64 -0
  18. package/dist/builtin-encoding.cjs +221 -0
  19. package/dist/builtin-encoding.d.cts +8 -0
  20. package/dist/builtin-encoding.d.ts +8 -0
  21. package/dist/builtin-encoding.js +220 -0
  22. package/dist/bytes/flate.cjs +1 -1
  23. package/dist/bytes/flate.js +1 -1
  24. package/dist/cff.cjs +14 -0
  25. package/dist/cff.d.cts +4 -1
  26. package/dist/cff.d.ts +4 -1
  27. package/dist/cff.js +12 -1
  28. package/dist/cmap-table.cjs +76 -13
  29. package/dist/cmap-table.d.cts +9 -1
  30. package/dist/cmap-table.d.ts +9 -1
  31. package/dist/cmap-table.js +77 -15
  32. package/dist/codec.cjs +1 -1
  33. package/dist/codec.d.cts +134 -0
  34. package/dist/codec.d.ts +134 -0
  35. package/dist/codec.js +1 -1
  36. package/dist/content-read.cjs +1 -1
  37. package/dist/content-read.d.cts +3 -3
  38. package/dist/content-read.d.ts +3 -3
  39. package/dist/content-read.js +1 -1
  40. package/dist/content-write.cjs +32 -10
  41. package/dist/content-write.d.cts +12 -5
  42. package/dist/content-write.d.ts +12 -5
  43. package/dist/content-write.js +32 -10
  44. package/dist/crypto/random.cjs +9 -0
  45. package/dist/crypto/random.d.cts +4 -0
  46. package/dist/crypto/random.d.ts +4 -0
  47. package/dist/crypto/random.js +8 -0
  48. package/dist/diagnostics.d.cts +1 -1
  49. package/dist/diagnostics.d.ts +1 -1
  50. package/dist/document.cjs +12 -3
  51. package/dist/document.d.cts +3 -1
  52. package/dist/document.d.ts +3 -1
  53. package/dist/document.js +12 -3
  54. package/dist/{embedded-font-fREdbxnr.d.ts → embedded-font-B4p9a3O3.d.ts} +3 -1
  55. package/dist/{embedded-font-BU6Jgcof.d.cts → embedded-font-oc65VGlr.d.cts} +3 -1
  56. package/dist/embedded-font-write.cjs +1 -1
  57. package/dist/embedded-font-write.d.cts +3 -3
  58. package/dist/embedded-font-write.d.ts +3 -3
  59. package/dist/embedded-font-write.js +1 -1
  60. package/dist/embedded-font.cjs +46 -15
  61. package/dist/embedded-font.d.cts +1 -1
  62. package/dist/embedded-font.d.ts +1 -1
  63. package/dist/embedded-font.js +46 -15
  64. package/dist/encoding.cjs +10 -1
  65. package/dist/encoding.d.cts +10 -1
  66. package/dist/encoding.d.ts +10 -1
  67. package/dist/encoding.js +2 -2
  68. package/dist/encrypt-write.cjs +234 -0
  69. package/dist/encrypt-write.d.cts +31 -0
  70. package/dist/encrypt-write.d.ts +31 -0
  71. package/dist/encrypt-write.js +231 -0
  72. package/dist/encrypt.cjs +51 -21
  73. package/dist/encrypt.d.cts +19 -3
  74. package/dist/encrypt.d.ts +19 -3
  75. package/dist/encrypt.js +36 -22
  76. package/dist/filters.cjs +18 -14
  77. package/dist/filters.d.cts +1 -1
  78. package/dist/filters.d.ts +1 -1
  79. package/dist/filters.js +18 -14
  80. package/dist/font-read.cjs +68 -13
  81. package/dist/font-read.d.cts +1 -1
  82. package/dist/font-read.d.ts +1 -1
  83. package/dist/font-read.js +69 -14
  84. package/dist/font-registry.cjs +1 -1
  85. package/dist/font-registry.d.cts +4 -4
  86. package/dist/font-registry.d.ts +4 -4
  87. package/dist/font-registry.js +1 -1
  88. package/dist/font-substitutes.d.cts +1 -1
  89. package/dist/font-substitutes.d.ts +1 -1
  90. package/dist/font-tables.cjs +31 -0
  91. package/dist/font-tables.d.cts +3 -1
  92. package/dist/font-tables.d.ts +3 -1
  93. package/dist/font-tables.js +31 -2
  94. package/dist/fonts.d.cts +2 -2
  95. package/dist/fonts.d.ts +2 -2
  96. package/dist/form.cjs +138 -0
  97. package/dist/form.d.cts +9 -0
  98. package/dist/form.d.ts +9 -0
  99. package/dist/form.js +137 -0
  100. package/dist/gsub-table-BRTQ8EUW.d.ts +10 -0
  101. package/dist/gsub-table-URczLd85.d.cts +10 -0
  102. package/dist/gsub-table.cjs +225 -0
  103. package/dist/gsub-table.d.cts +2 -0
  104. package/dist/gsub-table.d.ts +2 -0
  105. package/dist/gsub-table.js +224 -0
  106. package/dist/image/ccitt-encode.cjs +119 -0
  107. package/dist/image/ccitt-encode.d.cts +9 -0
  108. package/dist/image/ccitt-encode.d.ts +9 -0
  109. package/dist/image/ccitt-encode.js +118 -0
  110. package/dist/image/ccitt.cjs +3 -0
  111. package/dist/image/ccitt.d.cts +4 -1
  112. package/dist/image/ccitt.d.ts +4 -1
  113. package/dist/image/ccitt.js +1 -1
  114. package/dist/image/jbig2-bitmap.d.cts +1 -1
  115. package/dist/image/jbig2-bitmap.d.ts +1 -1
  116. package/dist/image/jbig2.cjs +3 -1
  117. package/dist/image/jbig2.js +3 -1
  118. package/dist/image/jp2-boxes.d.cts +1 -1
  119. package/dist/image/jp2-boxes.d.ts +1 -1
  120. package/dist/image/jpeg2000-codestream.d.cts +3 -3
  121. package/dist/image/jpeg2000-codestream.d.ts +3 -3
  122. package/dist/image/jpeg2000-t1.d.cts +1 -1
  123. package/dist/image/jpeg2000-t1.d.ts +1 -1
  124. package/dist/image/jpeg2000.cjs +1 -0
  125. package/dist/image/jpeg2000.d.cts +3 -0
  126. package/dist/image/jpeg2000.d.ts +3 -0
  127. package/dist/image/jpeg2000.js +1 -0
  128. package/dist/image/png-decode.cjs +1 -1
  129. package/dist/image/png-decode.js +1 -1
  130. package/dist/image/png-filter.d.cts +1 -1
  131. package/dist/image/png-filter.d.ts +1 -1
  132. package/dist/images-read.cjs +18 -12
  133. package/dist/images-read.d.cts +2 -2
  134. package/dist/images-read.d.ts +2 -2
  135. package/dist/images-read.js +15 -9
  136. package/dist/index.cjs +17 -4
  137. package/dist/index.d.cts +7 -6
  138. package/dist/index.d.ts +7 -6
  139. package/dist/index.js +6 -5
  140. package/dist/interpret.cjs +178 -56
  141. package/dist/interpret.d.cts +27 -12
  142. package/dist/interpret.d.ts +27 -12
  143. package/dist/interpret.js +178 -56
  144. package/dist/layout.cjs +149 -2
  145. package/dist/layout.d.cts +394 -1
  146. package/dist/layout.d.ts +394 -1
  147. package/dist/layout.js +140 -4
  148. package/dist/lexer.d.cts +9 -9
  149. package/dist/lexer.d.ts +9 -9
  150. package/dist/math-content-write.cjs +1 -1
  151. package/dist/math-content-write.js +1 -1
  152. package/dist/math-font-write.cjs +1 -1
  153. package/dist/math-font-write.d.cts +1 -1
  154. package/dist/math-font-write.d.ts +1 -1
  155. package/dist/math-font-write.js +1 -1
  156. package/dist/math-font.cjs +2 -2
  157. package/dist/math-font.d.cts +1 -1
  158. package/dist/math-font.d.ts +1 -1
  159. package/dist/math-font.js +2 -2
  160. package/dist/{math-stretch-a_rHNRvc.d.ts → math-stretch-BbC2o4Br.d.ts} +1 -1
  161. package/dist/{math-stretch-E26z6byT.d.cts → math-stretch-C2JanDAz.d.cts} +1 -1
  162. package/dist/math-stretch.d.cts +1 -1
  163. package/dist/math-stretch.d.ts +1 -1
  164. package/dist/measure.cjs +1 -1
  165. package/dist/measure.d.cts +1 -1
  166. package/dist/measure.d.ts +1 -1
  167. package/dist/measure.js +1 -1
  168. package/dist/names.cjs +41 -0
  169. package/dist/names.d.cts +11 -0
  170. package/dist/names.d.ts +11 -0
  171. package/dist/names.js +40 -0
  172. package/dist/navigation.cjs +210 -0
  173. package/dist/navigation.d.cts +18 -0
  174. package/dist/navigation.d.ts +18 -0
  175. package/dist/navigation.js +207 -0
  176. package/dist/notes-annotation-author.cjs +5 -0
  177. package/dist/notes-annotation-author.d.cts +4 -0
  178. package/dist/notes-annotation-author.d.ts +4 -0
  179. package/dist/notes-annotation-author.js +4 -0
  180. package/dist/objects-B7HdMeWS.d.cts +59 -0
  181. package/dist/objects-B7HdMeWS.d.ts +59 -0
  182. package/dist/objects.d.cts +1 -58
  183. package/dist/objects.d.ts +1 -58
  184. package/dist/optional-content.cjs +63 -0
  185. package/dist/optional-content.d.cts +12 -0
  186. package/dist/optional-content.d.ts +12 -0
  187. package/dist/optional-content.js +62 -0
  188. package/dist/parse.cjs +1 -1
  189. package/dist/parse.d.cts +2 -2
  190. package/dist/parse.d.ts +2 -2
  191. package/dist/parse.js +1 -1
  192. package/dist/pdf-text.cjs +21 -0
  193. package/dist/pdf-text.d.cts +5 -0
  194. package/dist/pdf-text.d.ts +5 -0
  195. package/dist/pdf-text.js +19 -0
  196. package/dist/predictors.d.cts +1 -1
  197. package/dist/predictors.d.ts +1 -1
  198. package/dist/read.cjs +287 -72
  199. package/dist/read.d.cts +2 -4
  200. package/dist/read.d.ts +2 -4
  201. package/dist/read.js +284 -67
  202. package/dist/serialize.cjs +5 -1
  203. package/dist/serialize.d.cts +3 -2
  204. package/dist/serialize.d.ts +3 -2
  205. package/dist/serialize.js +5 -2
  206. package/dist/sfnt-subset.cjs +10 -3
  207. package/dist/sfnt-subset.d.cts +1 -1
  208. package/dist/sfnt-subset.d.ts +1 -1
  209. package/dist/sfnt-subset.js +10 -3
  210. package/dist/structure.cjs +184 -0
  211. package/dist/structure.d.cts +12 -0
  212. package/dist/structure.d.ts +12 -0
  213. package/dist/structure.js +183 -0
  214. package/dist/tounicode.cjs +8 -3
  215. package/dist/tounicode.d.cts +2 -2
  216. package/dist/tounicode.d.ts +2 -2
  217. package/dist/tounicode.js +8 -3
  218. package/dist/util/base64.cjs +4 -4
  219. package/dist/util/base64.js +4 -4
  220. package/dist/winansi.cjs +1 -1
  221. package/dist/winansi.d.cts +1 -1
  222. package/dist/winansi.d.ts +1 -1
  223. package/dist/winansi.js +1 -1
  224. package/dist/write.cjs +464 -21
  225. package/dist/write.d.cts +4 -3
  226. package/dist/write.d.ts +4 -3
  227. package/dist/write.js +464 -20
  228. package/dist/xmp.cjs +46 -0
  229. package/dist/xmp.d.cts +14 -0
  230. package/dist/xmp.d.ts +14 -0
  231. package/dist/xmp.js +45 -0
  232. package/dist/xref.cjs +2 -2
  233. package/dist/xref.d.cts +3 -3
  234. package/dist/xref.d.ts +3 -3
  235. package/dist/xref.js +2 -2
  236. package/package.json +46 -31
  237. package/dist/image/png-encode.cjs +0 -64
  238. package/dist/image/png-encode.d.cts +0 -8
  239. package/dist/image/png-encode.d.ts +0 -8
  240. package/dist/image/png-encode.js +0 -63
@@ -0,0 +1,119 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_image_ccitt = require("./ccitt.cjs");
3
+ //#region src/image/ccitt-encode.ts
4
+ function buildRunCodes(table) {
5
+ const map = /* @__PURE__ */ new Map();
6
+ for (const [bits, run] of table) map.set(run, bits);
7
+ for (const [bits, run] of require_image_ccitt.EXTENDED_MAKEUP) if (!map.has(run)) map.set(run, bits);
8
+ return map;
9
+ }
10
+ const WHITE_RUN_CODES = buildRunCodes(require_image_ccitt.WHITE_TERMINATING_AND_MAKEUP);
11
+ const BLACK_RUN_CODES = buildRunCodes(require_image_ccitt.BLACK_TERMINATING_AND_MAKEUP);
12
+ const PASS_MODE = "0001";
13
+ const HORIZONTAL_MODE = "001";
14
+ const VERTICAL_MODES = /* @__PURE__ */ new Map([
15
+ [0, "1"],
16
+ [1, "011"],
17
+ [-1, "010"],
18
+ [2, "000011"],
19
+ [-2, "000010"],
20
+ [3, "0000011"],
21
+ [-3, "0000010"]
22
+ ]);
23
+ const LARGEST_MAKEUP_RUN = 2560;
24
+ const MAKEUP_GRANULARITY = 64;
25
+ var BitWriter = class {
26
+ bytes = [];
27
+ current = 0;
28
+ used = 0;
29
+ get byteLength() {
30
+ return this.bytes.length;
31
+ }
32
+ writeBits(bits) {
33
+ for (const char of bits) {
34
+ this.current = this.current << 1 | (char === "1" ? 1 : 0);
35
+ this.used++;
36
+ if (this.used === 8) {
37
+ this.bytes.push(this.current);
38
+ this.current = 0;
39
+ this.used = 0;
40
+ }
41
+ }
42
+ }
43
+ finish() {
44
+ if (this.used > 0) this.bytes.push(this.current << 8 - this.used);
45
+ return new Uint8Array(this.bytes);
46
+ }
47
+ };
48
+ function writeRun(writer, run, white) {
49
+ const codes = white ? WHITE_RUN_CODES : BLACK_RUN_CODES;
50
+ let remaining = run;
51
+ while (remaining >= MAKEUP_GRANULARITY) {
52
+ const makeup = Math.min(remaining - remaining % MAKEUP_GRANULARITY, LARGEST_MAKEUP_RUN);
53
+ writer.writeBits(codes.get(makeup));
54
+ remaining -= makeup;
55
+ }
56
+ writer.writeBits(codes.get(remaining));
57
+ }
58
+ function changingElements(bitmap, rowByteOffset, columns) {
59
+ const changes = [];
60
+ let previous = 1;
61
+ for (let x = 0; x < columns; x++) {
62
+ const pixel = (bitmap[rowByteOffset + (x >> 3)] ?? 0) >> 7 - (x & 7) & 1;
63
+ if (pixel !== previous) {
64
+ changes.push(x);
65
+ previous = pixel;
66
+ }
67
+ }
68
+ return changes;
69
+ }
70
+ function encodeCcittFax(bitmap, options) {
71
+ const { columns, rows, maxBytes } = options;
72
+ if (columns <= 0 || rows <= 0) return /* @__PURE__ */ new Uint8Array(0);
73
+ const rowBytes = columns + 7 >> 3;
74
+ const writer = new BitWriter();
75
+ let reference = [];
76
+ for (let y = 0; y < rows; y++) {
77
+ const offset = y * rowBytes;
78
+ const current = changingElements(bitmap, offset, columns);
79
+ let ci = 0;
80
+ let ri = 0;
81
+ const cur = (i) => current[i] ?? columns;
82
+ const ref = (i) => reference[i] ?? columns;
83
+ let a0 = -1;
84
+ let white = true;
85
+ while (a0 < columns) {
86
+ if (maxBytes !== void 0 && writer.byteLength > maxBytes) return;
87
+ const a1 = cur(ci);
88
+ const a2 = cur(ci + 1);
89
+ while (ri < reference.length && ref(ri) <= a0) ri++;
90
+ let b1Index = ri;
91
+ if (b1Index % 2 !== (white ? 0 : 1)) b1Index++;
92
+ const b1 = ref(b1Index);
93
+ const b2 = ref(b1Index + 1);
94
+ if (b2 < a1) {
95
+ writer.writeBits(PASS_MODE);
96
+ a0 = b2;
97
+ } else {
98
+ const delta = a1 - b1;
99
+ const vertical = VERTICAL_MODES.get(delta);
100
+ if (vertical !== void 0) {
101
+ writer.writeBits(vertical);
102
+ a0 = a1;
103
+ ci++;
104
+ } else {
105
+ writer.writeBits(HORIZONTAL_MODE);
106
+ writeRun(writer, a1 - Math.max(a0, 0), white);
107
+ writeRun(writer, a2 - a1, !white);
108
+ a0 = a2;
109
+ ci += 2;
110
+ }
111
+ }
112
+ if (a0 < columns) white = ((bitmap[offset + (a0 >> 3)] ?? 0) >> 7 - (a0 & 7) & 1) === 1;
113
+ }
114
+ reference = current;
115
+ }
116
+ return writer.finish();
117
+ }
118
+ //#endregion
119
+ exports.encodeCcittFax = encodeCcittFax;
@@ -0,0 +1,9 @@
1
+ //#region src/image/ccitt-encode.d.ts
2
+ interface EncodeCcittFaxOptions {
3
+ readonly columns: number;
4
+ readonly rows: number;
5
+ readonly maxBytes?: number;
6
+ }
7
+ declare function encodeCcittFax(bitmap: Uint8Array, options: EncodeCcittFaxOptions): Uint8Array<ArrayBuffer> | undefined;
8
+ //#endregion
9
+ export { EncodeCcittFaxOptions, encodeCcittFax };
@@ -0,0 +1,9 @@
1
+ //#region src/image/ccitt-encode.d.ts
2
+ interface EncodeCcittFaxOptions {
3
+ readonly columns: number;
4
+ readonly rows: number;
5
+ readonly maxBytes?: number;
6
+ }
7
+ declare function encodeCcittFax(bitmap: Uint8Array, options: EncodeCcittFaxOptions): Uint8Array<ArrayBuffer> | undefined;
8
+ //#endregion
9
+ export { EncodeCcittFaxOptions, encodeCcittFax };
@@ -0,0 +1,118 @@
1
+ import { BLACK_TERMINATING_AND_MAKEUP, EXTENDED_MAKEUP, WHITE_TERMINATING_AND_MAKEUP } from "./ccitt.js";
2
+ //#region src/image/ccitt-encode.ts
3
+ function buildRunCodes(table) {
4
+ const map = /* @__PURE__ */ new Map();
5
+ for (const [bits, run] of table) map.set(run, bits);
6
+ for (const [bits, run] of EXTENDED_MAKEUP) if (!map.has(run)) map.set(run, bits);
7
+ return map;
8
+ }
9
+ const WHITE_RUN_CODES = buildRunCodes(WHITE_TERMINATING_AND_MAKEUP);
10
+ const BLACK_RUN_CODES = buildRunCodes(BLACK_TERMINATING_AND_MAKEUP);
11
+ const PASS_MODE = "0001";
12
+ const HORIZONTAL_MODE = "001";
13
+ const VERTICAL_MODES = /* @__PURE__ */ new Map([
14
+ [0, "1"],
15
+ [1, "011"],
16
+ [-1, "010"],
17
+ [2, "000011"],
18
+ [-2, "000010"],
19
+ [3, "0000011"],
20
+ [-3, "0000010"]
21
+ ]);
22
+ const LARGEST_MAKEUP_RUN = 2560;
23
+ const MAKEUP_GRANULARITY = 64;
24
+ var BitWriter = class {
25
+ bytes = [];
26
+ current = 0;
27
+ used = 0;
28
+ get byteLength() {
29
+ return this.bytes.length;
30
+ }
31
+ writeBits(bits) {
32
+ for (const char of bits) {
33
+ this.current = this.current << 1 | (char === "1" ? 1 : 0);
34
+ this.used++;
35
+ if (this.used === 8) {
36
+ this.bytes.push(this.current);
37
+ this.current = 0;
38
+ this.used = 0;
39
+ }
40
+ }
41
+ }
42
+ finish() {
43
+ if (this.used > 0) this.bytes.push(this.current << 8 - this.used);
44
+ return new Uint8Array(this.bytes);
45
+ }
46
+ };
47
+ function writeRun(writer, run, white) {
48
+ const codes = white ? WHITE_RUN_CODES : BLACK_RUN_CODES;
49
+ let remaining = run;
50
+ while (remaining >= MAKEUP_GRANULARITY) {
51
+ const makeup = Math.min(remaining - remaining % MAKEUP_GRANULARITY, LARGEST_MAKEUP_RUN);
52
+ writer.writeBits(codes.get(makeup));
53
+ remaining -= makeup;
54
+ }
55
+ writer.writeBits(codes.get(remaining));
56
+ }
57
+ function changingElements(bitmap, rowByteOffset, columns) {
58
+ const changes = [];
59
+ let previous = 1;
60
+ for (let x = 0; x < columns; x++) {
61
+ const pixel = (bitmap[rowByteOffset + (x >> 3)] ?? 0) >> 7 - (x & 7) & 1;
62
+ if (pixel !== previous) {
63
+ changes.push(x);
64
+ previous = pixel;
65
+ }
66
+ }
67
+ return changes;
68
+ }
69
+ function encodeCcittFax(bitmap, options) {
70
+ const { columns, rows, maxBytes } = options;
71
+ if (columns <= 0 || rows <= 0) return /* @__PURE__ */ new Uint8Array(0);
72
+ const rowBytes = columns + 7 >> 3;
73
+ const writer = new BitWriter();
74
+ let reference = [];
75
+ for (let y = 0; y < rows; y++) {
76
+ const offset = y * rowBytes;
77
+ const current = changingElements(bitmap, offset, columns);
78
+ let ci = 0;
79
+ let ri = 0;
80
+ const cur = (i) => current[i] ?? columns;
81
+ const ref = (i) => reference[i] ?? columns;
82
+ let a0 = -1;
83
+ let white = true;
84
+ while (a0 < columns) {
85
+ if (maxBytes !== void 0 && writer.byteLength > maxBytes) return;
86
+ const a1 = cur(ci);
87
+ const a2 = cur(ci + 1);
88
+ while (ri < reference.length && ref(ri) <= a0) ri++;
89
+ let b1Index = ri;
90
+ if (b1Index % 2 !== (white ? 0 : 1)) b1Index++;
91
+ const b1 = ref(b1Index);
92
+ const b2 = ref(b1Index + 1);
93
+ if (b2 < a1) {
94
+ writer.writeBits(PASS_MODE);
95
+ a0 = b2;
96
+ } else {
97
+ const delta = a1 - b1;
98
+ const vertical = VERTICAL_MODES.get(delta);
99
+ if (vertical !== void 0) {
100
+ writer.writeBits(vertical);
101
+ a0 = a1;
102
+ ci++;
103
+ } else {
104
+ writer.writeBits(HORIZONTAL_MODE);
105
+ writeRun(writer, a1 - Math.max(a0, 0), white);
106
+ writeRun(writer, a2 - a1, !white);
107
+ a0 = a2;
108
+ ci += 2;
109
+ }
110
+ }
111
+ if (a0 < columns) white = ((bitmap[offset + (a0 >> 3)] ?? 0) >> 7 - (a0 & 7) & 1) === 1;
112
+ }
113
+ reference = current;
114
+ }
115
+ return writer.finish();
116
+ }
117
+ //#endregion
118
+ export { encodeCcittFax };
@@ -485,4 +485,7 @@ function decodeCcittFax(data, options = {}) {
485
485
  };
486
486
  }
487
487
  //#endregion
488
+ exports.BLACK_TERMINATING_AND_MAKEUP = BLACK_TERMINATING_AND_MAKEUP;
489
+ exports.EXTENDED_MAKEUP = EXTENDED_MAKEUP;
490
+ exports.WHITE_TERMINATING_AND_MAKEUP = WHITE_TERMINATING_AND_MAKEUP;
488
491
  exports.decodeCcittFax = decodeCcittFax;
@@ -1,4 +1,7 @@
1
1
  //#region src/image/ccitt.d.ts
2
+ declare const WHITE_TERMINATING_AND_MAKEUP: readonly (readonly [string, number])[];
3
+ declare const BLACK_TERMINATING_AND_MAKEUP: readonly (readonly [string, number])[];
4
+ declare const EXTENDED_MAKEUP: readonly (readonly [string, number])[];
2
5
  interface CcittFaxOptions {
3
6
  readonly k?: number;
4
7
  readonly columns?: number;
@@ -14,4 +17,4 @@ interface CcittFaxImage {
14
17
  }
15
18
  declare function decodeCcittFax(data: Uint8Array<ArrayBuffer>, options?: CcittFaxOptions): CcittFaxImage;
16
19
  //#endregion
17
- export { CcittFaxImage, CcittFaxOptions, decodeCcittFax };
20
+ export { BLACK_TERMINATING_AND_MAKEUP, CcittFaxImage, CcittFaxOptions, EXTENDED_MAKEUP, WHITE_TERMINATING_AND_MAKEUP, decodeCcittFax };
@@ -1,4 +1,7 @@
1
1
  //#region src/image/ccitt.d.ts
2
+ declare const WHITE_TERMINATING_AND_MAKEUP: readonly (readonly [string, number])[];
3
+ declare const BLACK_TERMINATING_AND_MAKEUP: readonly (readonly [string, number])[];
4
+ declare const EXTENDED_MAKEUP: readonly (readonly [string, number])[];
2
5
  interface CcittFaxOptions {
3
6
  readonly k?: number;
4
7
  readonly columns?: number;
@@ -14,4 +17,4 @@ interface CcittFaxImage {
14
17
  }
15
18
  declare function decodeCcittFax(data: Uint8Array<ArrayBuffer>, options?: CcittFaxOptions): CcittFaxImage;
16
19
  //#endregion
17
- export { CcittFaxImage, CcittFaxOptions, decodeCcittFax };
20
+ export { BLACK_TERMINATING_AND_MAKEUP, CcittFaxImage, CcittFaxOptions, EXTENDED_MAKEUP, WHITE_TERMINATING_AND_MAKEUP, decodeCcittFax };
@@ -484,4 +484,4 @@ function decodeCcittFax(data, options = {}) {
484
484
  };
485
485
  }
486
486
  //#endregion
487
- export { decodeCcittFax };
487
+ export { BLACK_TERMINATING_AND_MAKEUP, EXTENDED_MAKEUP, WHITE_TERMINATING_AND_MAKEUP, decodeCcittFax };
@@ -11,7 +11,7 @@ declare class Jbig2BitmapTooLargeError extends Jbig2ParseError {
11
11
  }
12
12
  declare function createBitmap(width: number, height: number, fill?: number): Jbig2Bitmap;
13
13
  declare function getPixel(bitmap: Jbig2Bitmap, x: number, y: number): number;
14
- type Jbig2CombinationOperator = 'or' | 'and' | 'xor' | 'xnor' | 'replace';
14
+ type Jbig2CombinationOperator = "or" | "and" | "xor" | "xnor" | "replace";
15
15
  declare function combinationOperatorFromCode(code: number): Jbig2CombinationOperator | undefined;
16
16
  declare function combineBitmap(destination: Jbig2Bitmap, source: Jbig2Bitmap, x: number, y: number, operator: Jbig2CombinationOperator): void;
17
17
  declare function packBitmapRows(bitmap: Jbig2Bitmap, width: number, height: number): Uint8Array<ArrayBuffer>;
@@ -11,7 +11,7 @@ declare class Jbig2BitmapTooLargeError extends Jbig2ParseError {
11
11
  }
12
12
  declare function createBitmap(width: number, height: number, fill?: number): Jbig2Bitmap;
13
13
  declare function getPixel(bitmap: Jbig2Bitmap, x: number, y: number): number;
14
- type Jbig2CombinationOperator = 'or' | 'and' | 'xor' | 'xnor' | 'replace';
14
+ type Jbig2CombinationOperator = "or" | "and" | "xor" | "xnor" | "replace";
15
15
  declare function combinationOperatorFromCode(code: number): Jbig2CombinationOperator | undefined;
16
16
  declare function combineBitmap(destination: Jbig2Bitmap, source: Jbig2Bitmap, x: number, y: number, operator: Jbig2CombinationOperator): void;
17
17
  declare function packBitmapRows(bitmap: Jbig2Bitmap, width: number, height: number): Uint8Array<ArrayBuffer>;
@@ -206,7 +206,9 @@ var Jbig2Decoder = class {
206
206
  columns: region.width,
207
207
  rows: region.height,
208
208
  blackIs1: true,
209
- onWarning: (message) => this.warn(message)
209
+ onWarning: (message) => {
210
+ this.warn(message);
211
+ }
210
212
  });
211
213
  this.compose(region, require_image_jbig2_bitmap.unpackBitmapRows(fax.bytes, region.width, region.height));
212
214
  return;
@@ -205,7 +205,9 @@ var Jbig2Decoder = class {
205
205
  columns: region.width,
206
206
  rows: region.height,
207
207
  blackIs1: true,
208
- onWarning: (message) => this.warn(message)
208
+ onWarning: (message) => {
209
+ this.warn(message);
210
+ }
209
211
  });
210
212
  this.compose(region, unpackBitmapRows(fax.bytes, region.width, region.height));
211
213
  return;
@@ -1,5 +1,5 @@
1
1
  //#region src/image/jp2-boxes.d.ts
2
- type Jp2ColourSpace = 'greyscale' | 'srgb' | 'sycc' | 'cmyk' | 'e-srgb' | 'rommrgb' | 'cielab';
2
+ type Jp2ColourSpace = "greyscale" | "srgb" | "sycc" | "cmyk" | "e-srgb" | "rommrgb" | "cielab";
3
3
  interface Jp2ImageHeader {
4
4
  readonly width: number;
5
5
  readonly height: number;
@@ -1,5 +1,5 @@
1
1
  //#region src/image/jp2-boxes.d.ts
2
- type Jp2ColourSpace = 'greyscale' | 'srgb' | 'sycc' | 'cmyk' | 'e-srgb' | 'rommrgb' | 'cielab';
2
+ type Jp2ColourSpace = "greyscale" | "srgb" | "sycc" | "cmyk" | "e-srgb" | "rommrgb" | "cielab";
3
3
  interface Jp2ImageHeader {
4
4
  readonly width: number;
5
5
  readonly height: number;
@@ -1,7 +1,7 @@
1
1
  //#region src/image/jpeg2000-codestream.d.ts
2
- type Jpeg2000ProgressionOrder = 'LRCP' | 'RLCP' | 'RPCL' | 'PCRL' | 'CPRL';
3
- type Jpeg2000Transform = 'reversible-5-3' | 'irreversible-9-7';
4
- type Jpeg2000QuantizationStyle = 'none' | 'derived' | 'expounded';
2
+ type Jpeg2000ProgressionOrder = "LRCP" | "RLCP" | "RPCL" | "PCRL" | "CPRL";
3
+ type Jpeg2000Transform = "reversible-5-3" | "irreversible-9-7";
4
+ type Jpeg2000QuantizationStyle = "none" | "derived" | "expounded";
5
5
  interface Jpeg2000ComponentSize {
6
6
  readonly signed: boolean;
7
7
  readonly bitDepth: number;
@@ -1,7 +1,7 @@
1
1
  //#region src/image/jpeg2000-codestream.d.ts
2
- type Jpeg2000ProgressionOrder = 'LRCP' | 'RLCP' | 'RPCL' | 'PCRL' | 'CPRL';
3
- type Jpeg2000Transform = 'reversible-5-3' | 'irreversible-9-7';
4
- type Jpeg2000QuantizationStyle = 'none' | 'derived' | 'expounded';
2
+ type Jpeg2000ProgressionOrder = "LRCP" | "RLCP" | "RPCL" | "PCRL" | "CPRL";
3
+ type Jpeg2000Transform = "reversible-5-3" | "irreversible-9-7";
4
+ type Jpeg2000QuantizationStyle = "none" | "derived" | "expounded";
5
5
  interface Jpeg2000ComponentSize {
6
6
  readonly signed: boolean;
7
7
  readonly bitDepth: number;
@@ -1,5 +1,5 @@
1
1
  //#region src/image/jpeg2000-t1.d.ts
2
- type Jpeg2000SubbandType = 'LL' | 'HL' | 'LH' | 'HH';
2
+ type Jpeg2000SubbandType = "LL" | "HL" | "LH" | "HH";
3
3
  interface Jpeg2000CodeBlockDecodeOptions {
4
4
  readonly width: number;
5
5
  readonly height: number;
@@ -1,5 +1,5 @@
1
1
  //#region src/image/jpeg2000-t1.d.ts
2
- type Jpeg2000SubbandType = 'LL' | 'HL' | 'LH' | 'HH';
2
+ type Jpeg2000SubbandType = "LL" | "HL" | "LH" | "HH";
3
3
  interface Jpeg2000CodeBlockDecodeOptions {
4
4
  readonly width: number;
5
5
  readonly height: number;
@@ -260,6 +260,7 @@ function decodeJpeg2000(data, options = {}) {
260
260
  const siz = codestream.siz;
261
261
  const width = siz.xsiz - siz.xosiz;
262
262
  const height = siz.ysiz - siz.yosiz;
263
+ if (options.maxWidth !== void 0 && width > options.maxWidth || options.maxHeight !== void 0 && height > options.maxHeight || options.maxPixels !== void 0 && width * height > options.maxPixels) throw new Error(`cannot decode a ${String(width)}x${String(height)} JPEG 2000 canvas; this exceeds the caller's configured size bound`);
263
264
  const componentCount = siz.components.length;
264
265
  const first = siz.components[0];
265
266
  if (first === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("the codestream declares no components");
@@ -38,6 +38,9 @@ interface Jpeg2000Metadata {
38
38
  }
39
39
  interface Jpeg2000DecodeOptions {
40
40
  readonly onWarning?: (message: string) => void;
41
+ readonly maxWidth?: number;
42
+ readonly maxHeight?: number;
43
+ readonly maxPixels?: number;
41
44
  }
42
45
  interface Jpeg2000Image {
43
46
  readonly width: number;
@@ -38,6 +38,9 @@ interface Jpeg2000Metadata {
38
38
  }
39
39
  interface Jpeg2000DecodeOptions {
40
40
  readonly onWarning?: (message: string) => void;
41
+ readonly maxWidth?: number;
42
+ readonly maxHeight?: number;
43
+ readonly maxPixels?: number;
41
44
  }
42
45
  interface Jpeg2000Image {
43
46
  readonly width: number;
@@ -259,6 +259,7 @@ function decodeJpeg2000(data, options = {}) {
259
259
  const siz = codestream.siz;
260
260
  const width = siz.xsiz - siz.xosiz;
261
261
  const height = siz.ysiz - siz.yosiz;
262
+ if (options.maxWidth !== void 0 && width > options.maxWidth || options.maxHeight !== void 0 && height > options.maxHeight || options.maxPixels !== void 0 && width * height > options.maxPixels) throw new Error(`cannot decode a ${String(width)}x${String(height)} JPEG 2000 canvas; this exceeds the caller's configured size bound`);
262
263
  const componentCount = siz.components.length;
263
264
  const first = siz.components[0];
264
265
  if (first === void 0) throw new Jpeg2000ParseError("the codestream declares no components");
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_bytes_crc32 = require("../bytes/crc32.cjs");
3
2
  const require_bytes_writer = require("../bytes/writer.cjs");
4
3
  const require_bytes_flate = require("../bytes/flate.cjs");
5
4
  const require_image_png_filter = require("./png-filter.cjs");
5
+ const require_bytes_crc32 = require("../bytes/crc32.cjs");
6
6
  //#region src/image/png-decode.ts
7
7
  const PNG_SIGNATURE = [
8
8
  137,
@@ -1,7 +1,7 @@
1
- import { crc32 } from "../bytes/crc32.js";
2
1
  import { concatBytes } from "../bytes/writer.js";
3
2
  import { inflateTolerant } from "../bytes/flate.js";
4
3
  import { unfilterScanlines } from "./png-filter.js";
4
+ import { crc32 } from "../bytes/crc32.js";
5
5
  //#region src/image/png-decode.ts
6
6
  const PNG_SIGNATURE = [
7
7
  137,
@@ -1,6 +1,6 @@
1
1
  //#region src/image/png-filter.d.ts
2
2
  type PngFilterType = 0 | 1 | 2 | 3 | 4;
3
3
  declare function unfilterScanlines(data: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number): Uint8Array<ArrayBuffer>;
4
- declare function filterScanlines(raw: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number, strategy?: 'none' | 'adaptive'): Uint8Array<ArrayBuffer>;
4
+ declare function filterScanlines(raw: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number, strategy?: "none" | "adaptive"): Uint8Array<ArrayBuffer>;
5
5
  //#endregion
6
6
  export { PngFilterType, filterScanlines, unfilterScanlines };
@@ -1,6 +1,6 @@
1
1
  //#region src/image/png-filter.d.ts
2
2
  type PngFilterType = 0 | 1 | 2 | 3 | 4;
3
3
  declare function unfilterScanlines(data: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number): Uint8Array<ArrayBuffer>;
4
- declare function filterScanlines(raw: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number, strategy?: 'none' | 'adaptive'): Uint8Array<ArrayBuffer>;
4
+ declare function filterScanlines(raw: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number, strategy?: "none" | "adaptive"): Uint8Array<ArrayBuffer>;
5
5
  //#endregion
6
6
  export { PngFilterType, filterScanlines, unfilterScanlines };
@@ -1,9 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_objects = require("./objects.cjs");
3
3
  const require_filters = require("./filters.cjs");
4
- const require_image_png_encode = require("./image/png-encode.cjs");
5
- const require_image_jpeg_info = require("./image/jpeg-info.cjs");
6
4
  const require_image_jpeg2000 = require("./image/jpeg2000.cjs");
5
+ let byte_codec = require("byte-codec");
7
6
  //#region src/images-read.ts
8
7
  function componentsOf(cs) {
9
8
  if (cs.kind === "gray") return 1;
@@ -185,11 +184,18 @@ function jpeg2000ChannelKind(image, dict, resolver, sink) {
185
184
  function readJpeg2000Image(dict, raw, resolver, sink) {
186
185
  let image;
187
186
  try {
188
- image = require_image_jpeg2000.decodeJpeg2000(raw, { onWarning: (message) => sink({
189
- code: "image/jpx-degraded",
190
- severity: "warning",
191
- message
192
- }) });
187
+ image = require_image_jpeg2000.decodeJpeg2000(raw, {
188
+ onWarning: (message) => {
189
+ sink({
190
+ code: "image/jpx-degraded",
191
+ severity: "warning",
192
+ message
193
+ });
194
+ },
195
+ maxWidth: byte_codec.PNG_MAX_DIMENSION,
196
+ maxHeight: byte_codec.PNG_MAX_DIMENSION,
197
+ maxPixels: byte_codec.PNG_MAX_PIXELS
198
+ });
193
199
  } catch (error) {
194
200
  sink({
195
201
  code: "image/jpx-undecodable",
@@ -241,7 +247,7 @@ function readJpeg2000Image(dict, raw, resolver, sink) {
241
247
  } : rawImage;
242
248
  return {
243
249
  format: "png",
244
- bytes: require_image_png_encode.encodePng(withAlpha),
250
+ bytes: (0, byte_codec.encodePng)(withAlpha),
245
251
  widthPx: image.width,
246
252
  heightPx: image.height
247
253
  };
@@ -259,7 +265,7 @@ function readImageXObject(dict, raw, resolver, sink) {
259
265
  if (decoded.remainingFilter === "DCTDecode") {
260
266
  let info;
261
267
  try {
262
- info = require_image_jpeg_info.readJpegInfo(decoded.bytes);
268
+ info = (0, byte_codec.readJpegInfo)(decoded.bytes);
263
269
  } catch {
264
270
  sink({
265
271
  code: "image/undecodable",
@@ -279,11 +285,11 @@ function readImageXObject(dict, raw, resolver, sink) {
279
285
  if (decoded.remainingFilter !== void 0) return;
280
286
  const width = require_objects.asNumber(require_objects.dictGet(dict, "Width") ?? require_objects.dictGet(dict, "W"));
281
287
  const height = require_objects.asNumber(require_objects.dictGet(dict, "Height") ?? require_objects.dictGet(dict, "H"));
282
- if (width === void 0 || height === void 0 || width <= 0 || height <= 0) {
288
+ if (width === void 0 || height === void 0 || !Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0 || width > byte_codec.PNG_MAX_DIMENSION || height > byte_codec.PNG_MAX_DIMENSION || width * height > byte_codec.PNG_MAX_PIXELS) {
283
289
  sink({
284
290
  code: "image/undecodable",
285
291
  severity: "warning",
286
- message: "image XObject is missing a valid /Width or /Height; skipping"
292
+ message: "image XObject has an invalid, out-of-range, or unusably large /Width or /Height; skipping"
287
293
  });
288
294
  return;
289
295
  }
@@ -315,7 +321,7 @@ function readImageXObject(dict, raw, resolver, sink) {
315
321
  } : rawImage;
316
322
  return {
317
323
  format: "png",
318
- bytes: require_image_png_encode.encodePng(withAlpha),
324
+ bytes: (0, byte_codec.encodePng)(withAlpha),
319
325
  widthPx: width,
320
326
  heightPx: height
321
327
  };
@@ -1,9 +1,9 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { PdfDict } from "./objects.cjs";
2
+ import { n as PdfDict } from "./objects-B7HdMeWS.cjs";
3
3
  import { PdfObjectResolver } from "./interpret.cjs";
4
4
  //#region src/images-read.d.ts
5
5
  interface ExtractedPdfImage {
6
- readonly format: 'png' | 'jpeg';
6
+ readonly format: "png" | "jpeg";
7
7
  readonly bytes: Uint8Array<ArrayBuffer>;
8
8
  readonly widthPx: number;
9
9
  readonly heightPx: number;
@@ -1,9 +1,9 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { PdfDict } from "./objects.js";
2
+ import { n as PdfDict } from "./objects-B7HdMeWS.js";
3
3
  import { PdfObjectResolver } from "./interpret.js";
4
4
  //#region src/images-read.d.ts
5
5
  interface ExtractedPdfImage {
6
- readonly format: 'png' | 'jpeg';
6
+ readonly format: "png" | "jpeg";
7
7
  readonly bytes: Uint8Array<ArrayBuffer>;
8
8
  readonly widthPx: number;
9
9
  readonly heightPx: number;
@@ -1,8 +1,7 @@
1
1
  import { asArray, asBool, asName, asNumber, dictGet } from "./objects.js";
2
2
  import { decodeStream } from "./filters.js";
3
- import { encodePng } from "./image/png-encode.js";
4
- import { readJpegInfo } from "./image/jpeg-info.js";
5
3
  import { decodeJpeg2000 } from "./image/jpeg2000.js";
4
+ import { PNG_MAX_DIMENSION, PNG_MAX_PIXELS, encodePng, readJpegInfo } from "byte-codec";
6
5
  //#region src/images-read.ts
7
6
  function componentsOf(cs) {
8
7
  if (cs.kind === "gray") return 1;
@@ -184,11 +183,18 @@ function jpeg2000ChannelKind(image, dict, resolver, sink) {
184
183
  function readJpeg2000Image(dict, raw, resolver, sink) {
185
184
  let image;
186
185
  try {
187
- image = decodeJpeg2000(raw, { onWarning: (message) => sink({
188
- code: "image/jpx-degraded",
189
- severity: "warning",
190
- message
191
- }) });
186
+ image = decodeJpeg2000(raw, {
187
+ onWarning: (message) => {
188
+ sink({
189
+ code: "image/jpx-degraded",
190
+ severity: "warning",
191
+ message
192
+ });
193
+ },
194
+ maxWidth: PNG_MAX_DIMENSION,
195
+ maxHeight: PNG_MAX_DIMENSION,
196
+ maxPixels: PNG_MAX_PIXELS
197
+ });
192
198
  } catch (error) {
193
199
  sink({
194
200
  code: "image/jpx-undecodable",
@@ -278,11 +284,11 @@ function readImageXObject(dict, raw, resolver, sink) {
278
284
  if (decoded.remainingFilter !== void 0) return;
279
285
  const width = asNumber(dictGet(dict, "Width") ?? dictGet(dict, "W"));
280
286
  const height = asNumber(dictGet(dict, "Height") ?? dictGet(dict, "H"));
281
- if (width === void 0 || height === void 0 || width <= 0 || height <= 0) {
287
+ if (width === void 0 || height === void 0 || !Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0 || width > PNG_MAX_DIMENSION || height > PNG_MAX_DIMENSION || width * height > PNG_MAX_PIXELS) {
282
288
  sink({
283
289
  code: "image/undecodable",
284
290
  severity: "warning",
285
- message: "image XObject is missing a valid /Width or /Height; skipping"
291
+ message: "image XObject has an invalid, out-of-range, or unusably large /Width or /Height; skipping"
286
292
  });
287
293
  return;
288
294
  }