@ni-c/imap-mcp 0.2.0 → 0.4.0

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 (67) hide show
  1. package/README.md +142 -35
  2. package/dist/analyze.d.ts +54 -6
  3. package/dist/analyze.js +295 -27
  4. package/dist/analyze.js.map +1 -1
  5. package/dist/attachments.d.ts +36 -0
  6. package/dist/attachments.js +21 -3
  7. package/dist/attachments.js.map +1 -1
  8. package/dist/audit.d.ts +7 -0
  9. package/dist/audit.js +11 -3
  10. package/dist/audit.js.map +1 -1
  11. package/dist/config.d.ts +32 -0
  12. package/dist/config.js +65 -6
  13. package/dist/config.js.map +1 -1
  14. package/dist/errors.js.map +1 -1
  15. package/dist/extract/child.d.ts +1 -0
  16. package/dist/extract/child.js +83 -0
  17. package/dist/extract/child.js.map +1 -0
  18. package/dist/extract/index.d.ts +41 -0
  19. package/dist/extract/index.js +183 -0
  20. package/dist/extract/index.js.map +1 -0
  21. package/dist/extract/ooxml.d.ts +35 -0
  22. package/dist/extract/ooxml.js +627 -0
  23. package/dist/extract/ooxml.js.map +1 -0
  24. package/dist/extract/pdf.d.ts +62 -0
  25. package/dist/extract/pdf.js +539 -0
  26. package/dist/extract/pdf.js.map +1 -0
  27. package/dist/extract/types.d.ts +56 -0
  28. package/dist/extract/types.js +13 -0
  29. package/dist/extract/types.js.map +1 -0
  30. package/dist/imap.js.map +1 -1
  31. package/dist/index.js +32 -5
  32. package/dist/index.js.map +1 -1
  33. package/dist/output-schema.d.ts +63 -0
  34. package/dist/output-schema.js +87 -0
  35. package/dist/output-schema.js.map +1 -0
  36. package/dist/resources.d.ts +1 -1
  37. package/dist/resources.js +5 -2
  38. package/dist/resources.js.map +1 -1
  39. package/dist/result.d.ts +39 -6
  40. package/dist/result.js +142 -29
  41. package/dist/result.js.map +1 -1
  42. package/dist/schema.d.ts +13 -1
  43. package/dist/schema.js +20 -2
  44. package/dist/schema.js.map +1 -1
  45. package/dist/server.d.ts +1 -1
  46. package/dist/server.js +30 -5
  47. package/dist/server.js.map +1 -1
  48. package/dist/tools/annotations.d.ts +32 -0
  49. package/dist/tools/annotations.js +33 -0
  50. package/dist/tools/annotations.js.map +1 -0
  51. package/dist/tools/catalogue.d.ts +2 -2
  52. package/dist/tools/read.d.ts +1 -1
  53. package/dist/tools/read.js +743 -87
  54. package/dist/tools/read.js.map +1 -1
  55. package/dist/tools/write.d.ts +3 -3
  56. package/dist/tools/write.js +174 -39
  57. package/dist/tools/write.js.map +1 -1
  58. package/package.json +17 -11
  59. package/dist/approval.d.ts +0 -45
  60. package/dist/approval.js +0 -69
  61. package/dist/approval.js.map +0 -1
  62. package/dist/confirm.d.ts +0 -59
  63. package/dist/confirm.js +0 -92
  64. package/dist/confirm.js.map +0 -1
  65. package/dist/tool-filter.d.ts +0 -45
  66. package/dist/tool-filter.js +0 -171
  67. package/dist/tool-filter.js.map +0 -1
@@ -0,0 +1,62 @@
1
+ import type { ExtractResponse } from './types.js';
2
+ /**
3
+ * How far one compressed stream may expand, and how far all of them may
4
+ * together, before the document is refused without a parser seeing it.
5
+ *
6
+ * This is the memory guard for PDFs, and it has to live here because nothing
7
+ * else bounds it. PDF.js inflates a stream into memory in full, and that memory
8
+ * is a typed array — external to the V8 heap, so no heap limit applies to it.
9
+ * Measured: a 3.4 MB file whose one content stream inflates to 1 GB took the
10
+ * process to 2.1 GB of resident memory within a second, and the extraction
11
+ * timeout only decides when that stops growing, not how far it gets. Deflate
12
+ * reaches roughly 1000:1 on repetitive input, so the 10 MB the size limit
13
+ * admits by default could stand for 10 GB.
14
+ *
15
+ * Every honest document is far below both numbers: a content stream is tens of
16
+ * kilobytes to a few megabytes, an embedded font a few hundred kilobytes.
17
+ */
18
+ export declare const MAX_STREAM_BYTES: number;
19
+ export declare const MAX_TOTAL_STREAM_BYTES: number;
20
+ /**
21
+ * Reads the text layer of a PDF.
22
+ *
23
+ * The API surface used here is deliberately five calls wide — `getDocument`,
24
+ * `getPage`, `getTextContent`, `view`, `destroy` — and it must stay that way.
25
+ * `getJSActions` surfaces the document's own JavaScript, `getAttachments`
26
+ * returns embedded files (a PDF can carry an executable past `sniffContent`,
27
+ * which only ever looks at the outer `%PDF`), and `getAnnotations` carries
28
+ * actions and URIs. None of them is needed to read text, and each is a door.
29
+ *
30
+ * Nothing here reaches the network, and that is worth stating because it is one
31
+ * careless line away from being false. unpdf only sets `standardFontDataUrl`
32
+ * and `cMapUrl` when it can resolve `pdfjs-dist`, which is not a dependency of
33
+ * this package, so both stay unset; the document is passed as bytes, never as a
34
+ * URL, so pdf.js never constructs its network stream. **Do not "fix" a missing
35
+ * font or CMap by pointing either option at a CDN.** It is the most-suggested
36
+ * workaround on the internet, and it would hand this server its first outbound
37
+ * HTTP client — the one property SECURITY.md is built on. The cost of leaving
38
+ * them unset is known and accepted: a PDF whose text needs a predefined CJK
39
+ * CMap does not extract.
40
+ */
41
+ export declare function extractPdf(bytes: Uint8Array, maxChars: number): Promise<ExtractResponse>;
42
+ /**
43
+ * Whether the document's compressed streams expand past the limits above.
44
+ *
45
+ * One forward pass over the file, finding every `stream … endstream` and
46
+ * decoding the ones whose filter can grow: Flate, LZW and RunLength, each
47
+ * optionally behind an ASCIIHex or ASCII85 wrapper. The decoders stop the
48
+ * moment they cross the remaining budget, so the work this costs is bounded by
49
+ * the budget plus one stream, whatever the file holds — and a decoder that
50
+ * hits a corrupt byte counts what it produced up to there, which is also what
51
+ * pdf.js would have got.
52
+ *
53
+ * The data is delimited the way pdf.js delimits it: by `/Length` where the
54
+ * number is direct or a resolvable reference and actually lands on
55
+ * `endstream`, and by the first `endstream` otherwise. Using only the keyword
56
+ * would let a sender end the scan early by writing the word inside their own
57
+ * compressed bytes.
58
+ *
59
+ * Image codecs — DCT, JPX, JBIG2, CCITT — are not decoded here, because text
60
+ * extraction never decodes them either.
61
+ */
62
+ export declare function expandsTooFar(bytes: Uint8Array): Promise<boolean>;
@@ -0,0 +1,539 @@
1
+ import { createInflate } from 'node:zlib';
2
+ /**
3
+ * Pages read at most, however many the document claims.
4
+ *
5
+ * A mail attachment that needs more than this is not a document anyone is going
6
+ * to read in a chat window, and the page loop is the one part of extraction
7
+ * whose cost scales with something the sender chose.
8
+ */
9
+ const MAX_PAGES = 100;
10
+ /** Below this many points, text is not there for a reader. */
11
+ const TINY_FONT_POINTS = 2;
12
+ /**
13
+ * How far one compressed stream may expand, and how far all of them may
14
+ * together, before the document is refused without a parser seeing it.
15
+ *
16
+ * This is the memory guard for PDFs, and it has to live here because nothing
17
+ * else bounds it. PDF.js inflates a stream into memory in full, and that memory
18
+ * is a typed array — external to the V8 heap, so no heap limit applies to it.
19
+ * Measured: a 3.4 MB file whose one content stream inflates to 1 GB took the
20
+ * process to 2.1 GB of resident memory within a second, and the extraction
21
+ * timeout only decides when that stops growing, not how far it gets. Deflate
22
+ * reaches roughly 1000:1 on repetitive input, so the 10 MB the size limit
23
+ * admits by default could stand for 10 GB.
24
+ *
25
+ * Every honest document is far below both numbers: a content stream is tens of
26
+ * kilobytes to a few megabytes, an embedded font a few hundred kilobytes.
27
+ */
28
+ export const MAX_STREAM_BYTES = 32 * 1024 * 1024;
29
+ export const MAX_TOTAL_STREAM_BYTES = 128 * 1024 * 1024;
30
+ /**
31
+ * pdf.js options, every one of them load-bearing.
32
+ *
33
+ * `isEvalSupported` reads like a performance knob and is not one: it gates
34
+ * pdf.js's construction of `Function` objects for font and PostScript-calculator
35
+ * programs taken from the document. That is the primitive that turned a parser
36
+ * bug into remote code execution in CVE-2024-4367. Text extraction never needs
37
+ * it.
38
+ *
39
+ * `useSystemFonts` overrides unpdf's own default of `true`. Nothing about
40
+ * reading text needs the host's font configuration consulted on behalf of a
41
+ * stranger's file.
42
+ *
43
+ * `verbosity` silences pdf.js's own logging. This matters more here than it
44
+ * looks: the server's transport is stdio JSON-RPC, and a stray `console.log`
45
+ * reaching the parent's stdout corrupts the framing and hangs the session. The
46
+ * child process is also started with its stdout discarded, because one guard
47
+ * is not a guard.
48
+ */
49
+ const PDFJS_OPTIONS = {
50
+ isEvalSupported: false,
51
+ enableXfa: false,
52
+ useSystemFonts: false,
53
+ disableFontFace: true,
54
+ verbosity: 0,
55
+ };
56
+ /**
57
+ * Reads the text layer of a PDF.
58
+ *
59
+ * The API surface used here is deliberately five calls wide — `getDocument`,
60
+ * `getPage`, `getTextContent`, `view`, `destroy` — and it must stay that way.
61
+ * `getJSActions` surfaces the document's own JavaScript, `getAttachments`
62
+ * returns embedded files (a PDF can carry an executable past `sniffContent`,
63
+ * which only ever looks at the outer `%PDF`), and `getAnnotations` carries
64
+ * actions and URIs. None of them is needed to read text, and each is a door.
65
+ *
66
+ * Nothing here reaches the network, and that is worth stating because it is one
67
+ * careless line away from being false. unpdf only sets `standardFontDataUrl`
68
+ * and `cMapUrl` when it can resolve `pdfjs-dist`, which is not a dependency of
69
+ * this package, so both stay unset; the document is passed as bytes, never as a
70
+ * URL, so pdf.js never constructs its network stream. **Do not "fix" a missing
71
+ * font or CMap by pointing either option at a CDN.** It is the most-suggested
72
+ * workaround on the internet, and it would hand this server its first outbound
73
+ * HTTP client — the one property SECURITY.md is built on. The cost of leaving
74
+ * them unset is known and accepted: a PDF whose text needs a predefined CJK
75
+ * CMap does not extract.
76
+ */
77
+ export async function extractPdf(bytes, maxChars) {
78
+ // Before the parser, not inside it: by the time pdf.js has inflated a stream
79
+ // the memory is spent, and there is no option that makes it stop earlier.
80
+ if (await expandsTooFar(bytes))
81
+ return { ok: false, reason: 'too-large' };
82
+ const { getDocumentProxy } = await import('unpdf');
83
+ let pdf;
84
+ try {
85
+ // Normalised, not passed through. A Node `Buffer` is a `Uint8Array`, so it
86
+ // satisfies the signature — but it is a view into a shared allocation pool
87
+ // at a non-zero `byteOffset`, and pdf.js reaches for the underlying
88
+ // `ArrayBuffer`. Handed a Buffer it reads the pool instead of the document
89
+ // and reports a corrupt file, which is a bug that looks exactly like a bad
90
+ // attachment. `set` on a fresh array is the copy that ends it.
91
+ const owned = new Uint8Array(bytes.byteLength);
92
+ owned.set(bytes);
93
+ pdf = await getDocumentProxy(owned, PDFJS_OPTIONS);
94
+ }
95
+ catch (error) {
96
+ return { ok: false, reason: reasonFor(error) };
97
+ }
98
+ try {
99
+ const declared = pdf.numPages;
100
+ const pageCount = Math.min(declared, MAX_PAGES);
101
+ const parts = [];
102
+ let length = 0;
103
+ // Set only by the character cap. It used to be initialised from
104
+ // `declared > pageCount`, and since the loop below ran only while it was
105
+ // false, a document with more than a hundred pages was never read at all
106
+ // and came back as "no text layer" — the diagnosis for a scan, on a long
107
+ // contract. The page count the walk stopped short of is reported
108
+ // separately, as `declaredUnitCount`.
109
+ let clipped = false;
110
+ let hiddenRuns = 0;
111
+ let totalRuns = 0;
112
+ // Sequentially, not `Promise.all` over the page count — which is what
113
+ // unpdf's own `extractText` does. That form allocates an array as long as
114
+ // the document claims to be and holds every page's text content live at
115
+ // once, both sized by a number the sender wrote.
116
+ for (let page = 1; page <= pageCount; page += 1) {
117
+ const proxy = await pdf.getPage(page);
118
+ const box = proxy.view;
119
+ const content = await proxy.getTextContent();
120
+ const line = [];
121
+ for (const item of content.items) {
122
+ if (!('str' in item))
123
+ continue;
124
+ totalRuns += 1;
125
+ if (isHidden(item, box))
126
+ hiddenRuns += 1;
127
+ line.push(item.str);
128
+ if (item.hasEOL)
129
+ line.push('\n');
130
+ }
131
+ const text = line.join('');
132
+ if (length + text.length >= maxChars) {
133
+ parts.push(text.slice(0, maxChars - length));
134
+ clipped = true;
135
+ break;
136
+ }
137
+ parts.push(text, '\n');
138
+ length += text.length + 1;
139
+ }
140
+ const text = parts.join('');
141
+ // Trimmed, because an image-only PDF still yields the page separators this
142
+ // loop writes. `text !== ''` would call a scanned invoice a text document.
143
+ if (text.trim() === '')
144
+ return { ok: false, reason: 'no-text-layer' };
145
+ return {
146
+ ok: true,
147
+ text,
148
+ unitLabel: 'pages',
149
+ unitCount: pageCount,
150
+ ...(declared > pageCount ? { declaredUnitCount: declared } : {}),
151
+ clipped,
152
+ hiddenRuns,
153
+ totalRuns,
154
+ };
155
+ }
156
+ catch (error) {
157
+ return { ok: false, reason: reasonFor(error) };
158
+ }
159
+ finally {
160
+ // Releases the parsing state. The process is about to exit anyway, but a
161
+ // document that fails on page 3 of 100 should not hold its object graph
162
+ // while the remaining pages are abandoned. `destroy` is on the loading
163
+ // task, not on the document proxy — the proxy only has `cleanup`, which
164
+ // keeps the transport alive.
165
+ await pdf.loadingTask.destroy().catch(() => undefined);
166
+ }
167
+ }
168
+ /**
169
+ * Whether a text run is drawn where a reader will not find it.
170
+ *
171
+ * A signal, never a filter — the same position this server takes on suspicious
172
+ * mail. Two of the four ways to hide text in a PDF are visible from here (off
173
+ * the page, and set microscopically small) and two are not: fill colour is not
174
+ * exposed by the text-content API at all, and text render mode 3 is exactly how
175
+ * every OCR'd scan stores the text layer over its own image, so treating it as
176
+ * hidden would reject the main thing this feature exists to read.
177
+ *
178
+ * So the count goes into a note, the text goes to the model either way, and the
179
+ * result header says plainly that some of what follows is text a person opening
180
+ * the document would not see.
181
+ *
182
+ * "Off the page" is measured against the page's own box, not against the
183
+ * origin: a MediaBox need not start at 0,0, and text past the right or top
184
+ * edge is as invisible as text past the left one.
185
+ */
186
+ function isHidden(item, box) {
187
+ const t = item.transform;
188
+ if (Array.isArray(t) && t.length >= 6) {
189
+ const x = Number(t[4]);
190
+ const y = Number(t[5]);
191
+ const [x0, y0, x1, y1] = box;
192
+ // Measured against pdf.js 6: a run placed *entirely* off the page produces
193
+ // no text item at all, so this catches the half that hangs over an edge
194
+ // and the other half never arrives — which is the better outcome and not
195
+ // one to undo.
196
+ if (Number.isFinite(x) &&
197
+ Number.isFinite(y) &&
198
+ (x < (x0 ?? 0) ||
199
+ y < (y0 ?? 0) ||
200
+ x > (x1 ?? Infinity) ||
201
+ y > (y1 ?? Infinity))) {
202
+ return true;
203
+ }
204
+ }
205
+ const size = item.height ?? 0;
206
+ return size > 0 && size < TINY_FONT_POINTS;
207
+ }
208
+ /**
209
+ * Maps a pdf.js rejection to a reason code.
210
+ *
211
+ * On the name, never the message. The message is a pdf.js implementation
212
+ * detail that changes between releases, and it quotes the document.
213
+ */
214
+ function reasonFor(error) {
215
+ const name = error?.name;
216
+ return name === 'PasswordException' ? 'encrypted' : 'corrupt';
217
+ }
218
+ /* ------------------------------------------------------------ pre-scan -- */
219
+ /**
220
+ * Whether the document's compressed streams expand past the limits above.
221
+ *
222
+ * One forward pass over the file, finding every `stream … endstream` and
223
+ * decoding the ones whose filter can grow: Flate, LZW and RunLength, each
224
+ * optionally behind an ASCIIHex or ASCII85 wrapper. The decoders stop the
225
+ * moment they cross the remaining budget, so the work this costs is bounded by
226
+ * the budget plus one stream, whatever the file holds — and a decoder that
227
+ * hits a corrupt byte counts what it produced up to there, which is also what
228
+ * pdf.js would have got.
229
+ *
230
+ * The data is delimited the way pdf.js delimits it: by `/Length` where the
231
+ * number is direct or a resolvable reference and actually lands on
232
+ * `endstream`, and by the first `endstream` otherwise. Using only the keyword
233
+ * would let a sender end the scan early by writing the word inside their own
234
+ * compressed bytes.
235
+ *
236
+ * Image codecs — DCT, JPX, JBIG2, CCITT — are not decoded here, because text
237
+ * extraction never decodes them either.
238
+ */
239
+ export async function expandsTooFar(bytes) {
240
+ const data = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
241
+ // latin1 keeps a one-to-one mapping between string index and byte offset.
242
+ const text = data.toString('latin1');
243
+ let total = 0;
244
+ let cursor = 0;
245
+ for (;;) {
246
+ const at = text.indexOf('stream', cursor);
247
+ if (at < 0)
248
+ return false;
249
+ cursor = at + 6;
250
+ // A keyword, not the tail of `endstream` or part of a name.
251
+ const before = at === 0 ? ' ' : text[at - 1];
252
+ if (!/[\s>]/.test(before))
253
+ continue;
254
+ let start = at + 6;
255
+ if (text[start] === '\r')
256
+ start += 1;
257
+ if (text[start] === '\n')
258
+ start += 1;
259
+ const objAt = text.lastIndexOf('obj', at);
260
+ const dict = text.slice(Math.max(objAt, cursor - 6 - 4096, 0), at);
261
+ const end = streamEnd(text, dict, start);
262
+ if (end < 0)
263
+ return false;
264
+ cursor = end + 9;
265
+ const filters = filtersOf(dict);
266
+ if (!filters.some((name) => EXPANDING.has(name)))
267
+ continue;
268
+ const limit = Math.min(MAX_STREAM_BYTES, MAX_TOTAL_STREAM_BYTES - total);
269
+ const size = await expansionOf(data.subarray(start, end), filters, /\/EarlyChange\s+0\b/.test(dict) ? 0 : 1, limit);
270
+ if (size > limit)
271
+ return true;
272
+ total += size;
273
+ }
274
+ }
275
+ const EXPANDING = new Set([
276
+ 'FlateDecode',
277
+ 'Fl',
278
+ 'LZWDecode',
279
+ 'LZW',
280
+ 'RunLengthDecode',
281
+ 'RL',
282
+ ]);
283
+ /** Where the stream's data ends: by a trustworthy `/Length`, else by keyword. */
284
+ function streamEnd(text, dict, start) {
285
+ const length = /\/Length\s+(\d+)(?:\s+(\d+)\s+R)?/.exec(dict);
286
+ if (length !== null) {
287
+ let declared;
288
+ if (length[2] === undefined) {
289
+ declared = Number(length[1]);
290
+ }
291
+ else {
292
+ const object = new RegExp(`(?:^|\\s)${length[1]}\\s+${length[2]}\\s+obj\\s*(\\d+)`).exec(text);
293
+ if (object !== null)
294
+ declared = Number(object[1]);
295
+ }
296
+ if (declared !== undefined && Number.isSafeInteger(declared)) {
297
+ let after = start + declared;
298
+ if (text[after] === '\r')
299
+ after += 1;
300
+ if (text[after] === '\n')
301
+ after += 1;
302
+ if (text.startsWith('endstream', after))
303
+ return start + declared;
304
+ }
305
+ }
306
+ return text.indexOf('endstream', start);
307
+ }
308
+ /** The `/Filter` names of a stream dictionary, in application order. */
309
+ function filtersOf(dict) {
310
+ const match = /\/Filter\s*(?:\[([^\]]*)\]|\/([A-Za-z0-9]+))/.exec(dict);
311
+ if (match === null)
312
+ return [];
313
+ if (match[2] !== undefined)
314
+ return [match[2]];
315
+ return [...match[1].matchAll(/\/([A-Za-z0-9]+)/g)].map((name) => name[1]);
316
+ }
317
+ /**
318
+ * Bytes the filter chain produces, or any number past `limit` once it does.
319
+ *
320
+ * Flate is materialised, because a second filter may follow it; LZW and
321
+ * RunLength only count, and end the chain, because nothing honest stacks
322
+ * another expanding filter behind them.
323
+ */
324
+ async function expansionOf(raw, filters, earlyChange, limit) {
325
+ let current = raw;
326
+ for (const filter of filters) {
327
+ switch (filter) {
328
+ case 'ASCIIHexDecode':
329
+ case 'AHx':
330
+ current = hexDecode(current);
331
+ break;
332
+ case 'ASCII85Decode':
333
+ case 'A85':
334
+ current = ascii85Decode(current);
335
+ break;
336
+ case 'FlateDecode':
337
+ case 'Fl': {
338
+ const inflated = await inflate(current, limit);
339
+ if (inflated === undefined)
340
+ return limit + 1;
341
+ current = inflated;
342
+ break;
343
+ }
344
+ case 'LZWDecode':
345
+ case 'LZW':
346
+ return lzwLength(current, earlyChange, limit);
347
+ case 'RunLengthDecode':
348
+ case 'RL':
349
+ return runLengthLength(current, limit);
350
+ default:
351
+ // An image codec, or something unknown: the chain stops producing
352
+ // anything text extraction would read.
353
+ return current === raw ? 0 : current.length;
354
+ }
355
+ }
356
+ return current === raw ? 0 : current.length;
357
+ }
358
+ /** Inflates up to `limit` bytes; `undefined` once the output would pass it. */
359
+ function inflate(data, limit) {
360
+ return new Promise((resolve) => {
361
+ const chunks = [];
362
+ let produced = 0;
363
+ let settled = false;
364
+ const stream = createInflate();
365
+ const finish = (value) => {
366
+ if (settled)
367
+ return;
368
+ settled = true;
369
+ stream.destroy();
370
+ resolve(value);
371
+ };
372
+ stream.on('data', (chunk) => {
373
+ if (settled)
374
+ return;
375
+ produced += chunk.length;
376
+ if (produced > limit) {
377
+ finish(undefined);
378
+ return;
379
+ }
380
+ chunks.push(chunk);
381
+ });
382
+ // A corrupt stream yields what it decoded before the bad byte, which is
383
+ // also what pdf.js gets from it. The listener stays attached after
384
+ // settling so a late error has somewhere to go.
385
+ stream.on('error', () => finish(Buffer.concat(chunks)));
386
+ stream.on('end', () => finish(Buffer.concat(chunks)));
387
+ stream.end(data);
388
+ });
389
+ }
390
+ /**
391
+ * Output length of a PDF LZW stream, without building a single string.
392
+ *
393
+ * Every dictionary entry is one byte longer than the entry it extends, so the
394
+ * length of any code is known from lengths alone — which is all the question
395
+ * needs. Codes are 9 to 12 bits, MSB first; 256 clears, 257 ends; the width
396
+ * grows one code early under the default `EarlyChange`.
397
+ */
398
+ function lzwLength(data, earlyChange, limit) {
399
+ let produced = 0;
400
+ let bits = 0;
401
+ let held = 0;
402
+ let pos = 0;
403
+ let width = 9;
404
+ let lengths = [];
405
+ let previous = 0;
406
+ let hasPrevious = false;
407
+ while (produced <= limit) {
408
+ while (held < width && pos < data.length) {
409
+ bits = (bits << 8) | data[pos];
410
+ pos += 1;
411
+ held += 8;
412
+ }
413
+ if (held < width)
414
+ break;
415
+ const code = (bits >>> (held - width)) & ((1 << width) - 1);
416
+ held -= width;
417
+ bits &= (1 << held) - 1;
418
+ if (code === 256) {
419
+ lengths = [];
420
+ width = 9;
421
+ hasPrevious = false;
422
+ continue;
423
+ }
424
+ if (code === 257)
425
+ break;
426
+ let length;
427
+ if (code < 256)
428
+ length = 1;
429
+ else if (code - 258 < lengths.length)
430
+ length = lengths[code - 258];
431
+ else if (code - 258 === lengths.length && hasPrevious)
432
+ length = previous + 1;
433
+ else
434
+ break;
435
+ produced += length;
436
+ if (hasPrevious)
437
+ lengths.push(previous + 1);
438
+ previous = length;
439
+ hasPrevious = true;
440
+ if (width < 12 && 258 + lengths.length + earlyChange >= 1 << width)
441
+ width += 1;
442
+ }
443
+ return produced;
444
+ }
445
+ /** Output length of a RunLength stream. */
446
+ function runLengthLength(data, limit) {
447
+ let produced = 0;
448
+ let i = 0;
449
+ while (i < data.length && produced <= limit) {
450
+ const marker = data[i];
451
+ i += 1;
452
+ if (marker === 128)
453
+ break;
454
+ if (marker < 128) {
455
+ produced += marker + 1;
456
+ i += marker + 1;
457
+ }
458
+ else {
459
+ produced += 257 - marker;
460
+ i += 1;
461
+ }
462
+ }
463
+ return produced;
464
+ }
465
+ function hexDecode(data) {
466
+ const out = new Uint8Array(Math.ceil(data.length / 2));
467
+ let n = 0;
468
+ let pending = -1;
469
+ for (const byte of data) {
470
+ if (byte === 0x3e)
471
+ break; // '>'
472
+ const digit = byte >= 0x30 && byte <= 0x39
473
+ ? byte - 0x30
474
+ : byte >= 0x41 && byte <= 0x46
475
+ ? byte - 0x37
476
+ : byte >= 0x61 && byte <= 0x66
477
+ ? byte - 0x57
478
+ : -1;
479
+ if (digit < 0)
480
+ continue;
481
+ if (pending < 0) {
482
+ pending = digit;
483
+ }
484
+ else {
485
+ out[n] = pending * 16 + digit;
486
+ n += 1;
487
+ pending = -1;
488
+ }
489
+ }
490
+ if (pending >= 0) {
491
+ out[n] = pending * 16;
492
+ n += 1;
493
+ }
494
+ return out.subarray(0, n);
495
+ }
496
+ function ascii85Decode(data) {
497
+ const out = new Uint8Array(Math.ceil(data.length / 5) * 4 + 4);
498
+ let n = 0;
499
+ const group = [];
500
+ let i = 0;
501
+ if (data[0] === 0x3c && data[1] === 0x7e)
502
+ i = 2; // '<~'
503
+ const flush = (count) => {
504
+ while (group.length < 5)
505
+ group.push(84);
506
+ let value = 0;
507
+ for (const digit of group)
508
+ value = value * 85 + digit;
509
+ const bytes = [
510
+ value >>> 24,
511
+ (value >>> 16) & 255,
512
+ (value >>> 8) & 255,
513
+ value & 255,
514
+ ];
515
+ for (let k = 0; k < count - 1; k += 1) {
516
+ out[n] = bytes[k];
517
+ n += 1;
518
+ }
519
+ group.length = 0;
520
+ };
521
+ for (; i < data.length; i += 1) {
522
+ const byte = data[i];
523
+ if (byte === 0x7e)
524
+ break; // '~' of '~>'
525
+ if (byte === 0x7a && group.length === 0) {
526
+ n += 4; // 'z' is four zero bytes
527
+ continue;
528
+ }
529
+ if (byte < 0x21 || byte > 0x75)
530
+ continue;
531
+ group.push(byte - 0x21);
532
+ if (group.length === 5)
533
+ flush(5);
534
+ }
535
+ if (group.length > 1)
536
+ flush(group.length);
537
+ return out.subarray(0, n);
538
+ }
539
+ //# sourceMappingURL=pdf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