@build-qube/papyra 0.0.4 → 0.2.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 (55) hide show
  1. package/README.md +129 -0
  2. package/dist/cache.d.ts +3 -0
  3. package/dist/cache.d.ts.map +1 -1
  4. package/dist/cache.js.map +1 -1
  5. package/dist/document.d.ts +251 -3
  6. package/dist/document.d.ts.map +1 -1
  7. package/dist/document.js +444 -16
  8. package/dist/document.js.map +1 -1
  9. package/dist/encode.d.ts +49 -0
  10. package/dist/encode.d.ts.map +1 -0
  11. package/dist/encode.js +71 -0
  12. package/dist/encode.js.map +1 -0
  13. package/dist/encoded.d.ts +91 -0
  14. package/dist/encoded.d.ts.map +1 -0
  15. package/dist/encoded.js +84 -0
  16. package/dist/encoded.js.map +1 -0
  17. package/dist/errors.d.ts +45 -0
  18. package/dist/errors.d.ts.map +1 -0
  19. package/dist/errors.js +69 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/fingerprint.d.ts +18 -0
  22. package/dist/fingerprint.d.ts.map +1 -0
  23. package/dist/fingerprint.js +48 -0
  24. package/dist/fingerprint.js.map +1 -0
  25. package/dist/index.d.ts +12 -2
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +5 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/links.d.ts +53 -0
  30. package/dist/links.d.ts.map +1 -0
  31. package/dist/links.js +26 -0
  32. package/dist/links.js.map +1 -0
  33. package/dist/outline.d.ts +72 -0
  34. package/dist/outline.d.ts.map +1 -0
  35. package/dist/outline.js +73 -0
  36. package/dist/outline.js.map +1 -0
  37. package/dist/runtime.d.ts +8 -0
  38. package/dist/runtime.d.ts.map +1 -1
  39. package/dist/runtime.js +2 -0
  40. package/dist/runtime.js.map +1 -1
  41. package/dist/scheduler.d.ts +20 -2
  42. package/dist/scheduler.d.ts.map +1 -1
  43. package/dist/scheduler.js +15 -0
  44. package/dist/scheduler.js.map +1 -1
  45. package/dist/search.d.ts +50 -0
  46. package/dist/search.d.ts.map +1 -0
  47. package/dist/search.js +151 -0
  48. package/dist/search.js.map +1 -0
  49. package/dist/text.d.ts +113 -0
  50. package/dist/text.d.ts.map +1 -0
  51. package/dist/text.js +84 -0
  52. package/dist/text.js.map +1 -0
  53. package/dist/types.d.ts +96 -0
  54. package/dist/types.d.ts.map +1 -1
  55. package/package.json +4 -3
package/dist/document.js CHANGED
@@ -1,8 +1,15 @@
1
- import { PdfDocument as NativeDocument } from '@build-qube/papyra-native';
1
+ import { PdfDocument as NativeDocument, } from '@build-qube/papyra-native';
2
2
  import { RenderCache } from './cache.js';
3
+ import { PageImage, svgPage } from './encode.js';
4
+ import { rethrowLoadError } from './errors.js';
5
+ import { fingerprint } from './fingerprint.js';
6
+ import { toPageLink } from './links.js';
7
+ import { buildOutlineTree } from './outline.js';
3
8
  import { currentRuntime, hardwareConcurrency, init, MAX_WASM_CONCURRENCY, } from './runtime.js';
4
9
  import { DEFAULT_PRIORITY, Scheduler } from './scheduler.js';
10
+ import { searchPageText } from './search.js';
5
11
  import { toBytes } from './source.js';
12
+ import { pageTextBytes, toPageText } from './text.js';
6
13
  const DEFAULT_DPI = 72;
7
14
  /**
8
15
  * Refuse renders large enough to take down the tab.
@@ -12,28 +19,126 @@ const DEFAULT_DPI = 72;
12
19
  const MAX_PIXELS = 100_000_000;
13
20
  /** Default bytes of rendered pages to keep. Roughly eleven 2000px ARCH-E sheets. */
14
21
  const DEFAULT_CACHE_BYTES = 128 * 1024 * 1024;
15
- /** Open a PDF from bytes, an `ArrayBuffer`, a `Blob`, or a `File`. */
22
+ /**
23
+ * Default bytes of extracted text to keep.
24
+ *
25
+ * Text is three orders of magnitude smaller than the pixels of the same page — a
26
+ * dense page of a paper is ~80 KB against ~11 MB — so this holds hundreds of pages
27
+ * and a repeated search never re-extracts.
28
+ */
29
+ const DEFAULT_TEXT_CACHE_BYTES = 32 * 1024 * 1024;
30
+ /**
31
+ * Bytes of page links to keep.
32
+ *
33
+ * Not an option, unlike the render and text budgets: links are two orders of
34
+ * magnitude smaller again — a page of a linked table of contents is a few hundred
35
+ * bytes — so 4 MB holds tens of thousands of them and there is nothing to tune.
36
+ */
37
+ const LINK_CACHE_BYTES = 4 * 1024 * 1024;
38
+ /** Rough bytes per cached link: two objects, a rect, and a short string. */
39
+ const LINK_BYTES = 96;
40
+ /**
41
+ * Where text extraction sits in the queue by default.
42
+ *
43
+ * Behind rendering: a search that stalls the page the user is looking at is worse
44
+ * than one that takes another beat to fill in.
45
+ */
46
+ const DEFAULT_TEXT_PRIORITY = 3;
47
+ /** napi omits absent strings rather than nulling them; normalise to one shape. */
48
+ function toMetadata(info) {
49
+ return {
50
+ title: info.title ?? null,
51
+ author: info.author ?? null,
52
+ subject: info.subject ?? null,
53
+ keywords: info.keywords ?? null,
54
+ creator: info.creator ?? null,
55
+ producer: info.producer ?? null,
56
+ created: info.created ?? null,
57
+ modified: info.modified ?? null,
58
+ };
59
+ }
60
+ /** Wire an `AbortSignal` to a queued job. Cancelling only drops work not yet started. */
61
+ function attachSignal(handle, signal) {
62
+ if (!signal)
63
+ return;
64
+ if (signal.aborted) {
65
+ handle.cancel('signal aborted');
66
+ return;
67
+ }
68
+ signal.addEventListener('abort', () => handle.cancel('signal aborted'), {
69
+ once: true,
70
+ });
71
+ }
72
+ /**
73
+ * Open a PDF from bytes, an `ArrayBuffer`, a `Blob`, or a `File`.
74
+ *
75
+ * Throws {@link PasswordRequiredError} when the document is encrypted and no
76
+ * {@link OpenOptions.password} was given, and {@link IncorrectPasswordError} when one
77
+ * was given and rejected. Both extend {@link PasswordError}, so a viewer that shows
78
+ * one dialog for both can catch the base.
79
+ */
16
80
  export async function open(source, options = {}) {
17
81
  init();
18
82
  const bytes = await toBytes(source);
19
- const inner = options.password === undefined
20
- ? NativeDocument.load(bytes)
21
- : NativeDocument.loadWithPassword(bytes, options.password);
22
- return new Document(inner, options);
83
+ try {
84
+ const inner = options.password === undefined
85
+ ? NativeDocument.load(bytes)
86
+ : NativeDocument.loadWithPassword(bytes, options.password);
87
+ return new Document(inner, fingerprint(bytes), options);
88
+ }
89
+ catch (e) {
90
+ rethrowLoadError(e);
91
+ }
23
92
  }
93
+ /**
94
+ * An open PDF, and the queue and caches that serve it.
95
+ *
96
+ * Every page-level call goes through one shared scheduler, so a thumbnail sweep can
97
+ * never starve the page on screen — attach a {@link RenderOptions.priority} and the
98
+ * queue reorders around it. Construct via {@link open}, not `new`.
99
+ */
24
100
  export class Document {
25
101
  #inner;
102
+ // One queue for every kind of job, `renderImage` included: priority and concurrency
103
+ // are the point of this library, and a bulk export must not starve the visible page.
26
104
  #scheduler;
27
105
  #limit;
28
106
  #cache;
107
+ #text;
108
+ #links;
109
+ /** In-flight link reads, so two callers on one page share a single task. */
110
+ #linksPending = new Map();
111
+ /** Memoised by {@link outline}; the outline cannot change under us. */
112
+ #outline;
113
+ /** Memoised by {@link pageLabels}. */
114
+ #labels;
115
+ /** Memoised by {@link metadata}. */
116
+ #metadata;
117
+ /** Memoised by {@link indexText}. */
118
+ #indexed;
119
+ /**
120
+ * A stable identifier for this document's bytes.
121
+ *
122
+ * Sixteen hex characters, for keying whatever you remember per document — the page
123
+ * it was left on, a zoom level, a set of highlights. Two `open` calls on the same
124
+ * file always agree.
125
+ *
126
+ * It is a hash of the file, **not** the PDF's own `/ID`: the engine exposes no
127
+ * trailer accessor, so that identifier is out of reach. The practical difference is
128
+ * that saving an incremental update changes this while `/ID` would have survived.
129
+ */
130
+ fingerprint;
29
131
  /** @internal — construct via {@link open}. */
30
- constructor(inner, options = {}) {
132
+ constructor(inner, fingerprintOfBytes, options = {}) {
31
133
  this.#inner = inner;
134
+ this.fingerprint = fingerprintOfBytes;
32
135
  this.#limit = Math.max(1, options.concurrency ?? defaultConcurrency());
33
136
  this.#scheduler = new Scheduler(this.#limit, {
34
137
  yieldToUrgent: options.yieldToUrgent,
35
138
  });
36
139
  this.#cache = new RenderCache(options.cacheBytes ?? DEFAULT_CACHE_BYTES, (page) => page.data.byteLength);
140
+ this.#text = new RenderCache(options.textCacheBytes ?? DEFAULT_TEXT_CACHE_BYTES, pageTextBytes);
141
+ this.#links = new RenderCache(LINK_CACHE_BYTES, (links) => links.length * LINK_BYTES);
37
142
  }
38
143
  /** Rendered pages held for reuse, and how often that has paid off. */
39
144
  get cache() {
@@ -51,9 +156,140 @@ export class Document {
51
156
  oldestWaitMs: this.#scheduler.oldestWaitMs,
52
157
  };
53
158
  }
159
+ /** How many pages the document has. Page indices are 0-based throughout. */
54
160
  get pageCount() {
55
161
  return this.#inner.pageCount;
56
162
  }
163
+ /**
164
+ * The PDF specification version the file declares, e.g. `'1.7'`.
165
+ *
166
+ * Deliberately not part of {@link Document.metadata}: that is what the producer
167
+ * chose to say about the document, while this is a structural property read from
168
+ * the file's header — and from the catalog, which overrides it for 1.4 and later,
169
+ * so an incrementally saved file reports the version it was last written as.
170
+ *
171
+ * `'1.0'` is worth treating with suspicion. Genuine PDF 1.0 files are close to
172
+ * extinct, and it is also what a file with an unreadable header reports.
173
+ */
174
+ get pdfVersion() {
175
+ return this.#inner.pdfVersion ?? null;
176
+ }
177
+ /**
178
+ * The document outline — bookmarks, the table of contents — as a tree.
179
+ *
180
+ * Resolves to an empty array when the document has no outline, which is the common
181
+ * case. The walk runs off the event loop and the result is memoised, so calling
182
+ * this on every render of a sidebar costs nothing after the first.
183
+ *
184
+ * Entries that point outside the document (a URL, another file) and containers that
185
+ * group children without a destination of their own both have a `dest` of `null`;
186
+ * they are kept because a viewer still lists them.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * for (const node of await doc.outline()) {
191
+ * if (node.page !== null) void doc.render(node.page, { fitWidth: 1600 });
192
+ * }
193
+ * ```
194
+ */
195
+ async outline() {
196
+ this.#outline ??= this.#inner
197
+ .outline()
198
+ .then(buildOutlineTree)
199
+ // A failed walk must not be cached as a permanent empty outline.
200
+ .catch((e) => {
201
+ this.#outline = undefined;
202
+ throw e;
203
+ });
204
+ return this.#outline;
205
+ }
206
+ /**
207
+ * What the document says about itself: title, author, dates, the tool that wrote it.
208
+ *
209
+ * Synchronous — the engine reads the information dictionary while loading, so this
210
+ * only decodes strings. Every field is independently `null`, and none of it is
211
+ * verified; `title` in particular is often a filename or missing entirely.
212
+ */
213
+ get metadata() {
214
+ this.#metadata ??= toMetadata(this.#inner.info());
215
+ return this.#metadata;
216
+ }
217
+ /**
218
+ * The label printed on each page, one entry per page.
219
+ *
220
+ * Resolves to an **empty array** when the document defines no page labels, which is
221
+ * the common case — that is the signal to number pages by index yourself. A
222
+ * document that defines labels but says nothing about a particular page gives that
223
+ * page an empty string, which is a different answer.
224
+ *
225
+ * Worth honouring wherever a page number is shown: a document with front matter
226
+ * numbers its first pages i, ii, iii, and a viewer that says "page 4 of 300" when
227
+ * the sheet reads "A101" is describing a document nobody else can see.
228
+ *
229
+ * The walk runs off the event loop and the result is memoised.
230
+ *
231
+ * @example
232
+ * ```ts
233
+ * const labels = await doc.pageLabels();
234
+ * const shown = labels[index] || String(index + 1);
235
+ * ```
236
+ */
237
+ async pageLabels() {
238
+ this.#labels ??= this.#inner.pageLabels().catch((e) => {
239
+ // A failed walk must not be cached as a permanent absence of labels.
240
+ this.#labels = undefined;
241
+ throw e;
242
+ });
243
+ return this.#labels;
244
+ }
245
+ /**
246
+ * The links on one page — where they are, and where they go.
247
+ *
248
+ * Rectangles are in the same 72-DPI top-left space as {@link Document.pageText} and
249
+ * {@link Document.pageSize}, so placing them over a render is one multiply; see
250
+ * {@link scaleRect}. Only links that resolve to something actionable are reported.
251
+ *
252
+ * Unlike text extraction this never interprets a content stream — it is an
253
+ * object-graph read, roughly a thousandth the cost of rendering the page — so it
254
+ * does **not** go through the priority queue. Making a link layer wait behind
255
+ * renders would add latency a viewer can feel, for work that costs nothing.
256
+ * Results are cached, and two calls for the same page share one read.
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * const scale = rendered.width / doc.pageSize(index).width;
261
+ * for (const link of await doc.links(index)) {
262
+ * const { x, y, width, height } = scaleRect(link.rect, scale);
263
+ * // ...position an anchor over the canvas
264
+ * }
265
+ * ```
266
+ */
267
+ async links(index) {
268
+ const key = `links:${index}`;
269
+ const hit = this.#links.get(key);
270
+ if (hit)
271
+ return hit;
272
+ const pending = this.#linksPending.get(index);
273
+ if (pending)
274
+ return pending;
275
+ const read = this.#inner
276
+ .pageLinks(index)
277
+ .then((native) => {
278
+ // `toPageLink` only returns null for a link with no resolvable target, which
279
+ // the bindings do not emit — the filter is here so a future one cannot leak
280
+ // a null into the array.
281
+ const links = native
282
+ .map(toPageLink)
283
+ .filter((link) => link !== null);
284
+ this.#links.set(key, links);
285
+ return links;
286
+ })
287
+ .finally(() => {
288
+ this.#linksPending.delete(index);
289
+ });
290
+ this.#linksPending.set(index, read);
291
+ return read;
292
+ }
57
293
  /** Page dimensions in PDF points (1/72 inch). */
58
294
  pageSize(index) {
59
295
  return this.#inner.pageSize(index);
@@ -62,6 +298,90 @@ export class Document {
62
298
  async renderPage(index, options = {}) {
63
299
  return this.render(index, options).promise;
64
300
  }
301
+ /**
302
+ * Render a page for export, keeping the pixels in Rust.
303
+ *
304
+ * The returned {@link PageImage} encodes on demand — `toWebp()`, `toPng()`,
305
+ * `toJpeg()`, `toDataUrl()` — and never hands the raw bitmap to JS. A 42x30in
306
+ * drawing at 150 DPI is 6.5 MB raw and a fraction of that encoded, so for anything
307
+ * leaving the process that buffer is pure overhead.
308
+ *
309
+ * Use `renderPage` when you want to paint to a canvas, and `encode()` when you want
310
+ * both the pixels and a file.
311
+ *
312
+ * Shares the scheduler with every other render, so priority and concurrency behave
313
+ * exactly as they do for `render`. **Not cached** — the cache is keyed by page and
314
+ * size with no format dimension, and it measures raw bytes.
315
+ *
316
+ * @example
317
+ * ```ts
318
+ * const img = await doc.renderImage(0, { fitWidth: 2000 });
319
+ * await writeFile('page-0.webp', (await img.toWebp()).bytes);
320
+ * ```
321
+ */
322
+ async renderImage(index, options = {}) {
323
+ return this.imageHandle(index, options).promise;
324
+ }
325
+ /**
326
+ * As {@link renderImage}, but returns the handle so the job can be reprioritised,
327
+ * cancelled, or timed — the same relationship `render` has to `renderPage`.
328
+ *
329
+ * `timing` is where the export path becomes measurable: it separates queue wait from
330
+ * render time, which end-to-end timing around the promise cannot.
331
+ */
332
+ imageHandle(index, options = {}) {
333
+ const dpi = this.#resolveDpi(index, options);
334
+ // A distinct key space from `render`, so an image request never coalesces onto a
335
+ // pending raw render (different return type) or vice versa.
336
+ const handle = this.#scheduler.submit({
337
+ key: `image:${index}@${dpi.toFixed(4)}`,
338
+ priority: options.priority ?? DEFAULT_PRIORITY,
339
+ run: () => this.#inner.renderPageImageAsync(index, dpi, options.signal).then((img) => new PageImage(img)),
340
+ });
341
+ attachSignal(handle, options.signal);
342
+ return handle;
343
+ }
344
+ /**
345
+ * Convert a page to SVG — vector output, not pixels.
346
+ *
347
+ * Paths stay paths and text stays glyph outlines, so the result scales to any size
348
+ * and can be edited downstream. That is the trade: an SVG of a dense drawing is
349
+ * larger than a WebP of the same page at screen size and slower for a browser to
350
+ * paint, but it is the only output that survives being scaled up.
351
+ *
352
+ * Conversion is content-stream interpretation without rasterisation — roughly the
353
+ * non-preemptible portion of a render — so it shares the scheduler with everything
354
+ * else and honours {@link SvgOptions.priority}. **Not cached**, for the same reason
355
+ * {@link renderImage} is not.
356
+ *
357
+ * @example
358
+ * ```ts
359
+ * const page = await doc.renderSvg(0, { background: 'transparent' });
360
+ * await writeFile('page-0.svg', page.markup);
361
+ * ```
362
+ */
363
+ async renderSvg(index, options = {}) {
364
+ return this.svgHandle(index, options).promise;
365
+ }
366
+ /**
367
+ * As {@link renderSvg}, but returns the handle so the job can be reprioritised,
368
+ * cancelled, or timed — the same relationship `imageHandle` has to `renderImage`.
369
+ */
370
+ svgHandle(index, options = {}) {
371
+ if (index < 0 || index >= this.pageCount) {
372
+ throw new RangeError(`papyra: page ${index} is out of range (0..${this.pageCount - 1})`);
373
+ }
374
+ const opaque = options.background !== 'transparent';
375
+ const handle = this.#scheduler.submit({
376
+ // The background is part of the key: the scheduler coalesces same-key requests,
377
+ // and an opaque and a transparent conversion of one page are different output.
378
+ key: `svg:${index}${opaque ? '' : ':transparent'}`,
379
+ priority: options.priority ?? DEFAULT_PRIORITY,
380
+ run: () => this.#inner.renderPageSvgAsync(index, opaque, options.signal).then(svgPage),
381
+ });
382
+ attachSignal(handle, options.signal);
383
+ return handle;
384
+ }
65
385
  /**
66
386
  * Render a page, returning a handle you can reprioritise or drop.
67
387
  *
@@ -92,15 +412,7 @@ export class Document {
92
412
  return page;
93
413
  }),
94
414
  });
95
- const { signal } = options;
96
- if (signal) {
97
- if (signal.aborted)
98
- handle.cancel('signal aborted');
99
- else
100
- signal.addEventListener('abort', () => handle.cancel('signal aborted'), {
101
- once: true,
102
- });
103
- }
415
+ attachSignal(handle, options.signal);
104
416
  return liveHandle(handle);
105
417
  }
106
418
  /**
@@ -207,6 +519,122 @@ export class Document {
207
519
  handles.clear();
208
520
  }
209
521
  }
522
+ /**
523
+ * Extract the text of one page.
524
+ *
525
+ * Scheduled like a render, but behind one by default: a search should not stall the
526
+ * page the user is looking at. Results are cached, so searching the same document
527
+ * repeatedly extracts each page once.
528
+ *
529
+ * Extraction is interpretation without rasterisation, which makes it roughly a
530
+ * hundredth the cost of rendering the same page — about 1ms for a dense page of a
531
+ * paper. It is cheap enough to do speculatively.
532
+ */
533
+ async pageText(index, options = {}) {
534
+ const key = `text:${index}`;
535
+ const hit = this.#text.get(key);
536
+ if (hit)
537
+ return hit;
538
+ // One queue for renders and text both, so priority means something across them.
539
+ // Coalescing by key is what stops a search and a text selection extracting the
540
+ // same page twice.
541
+ const handle = this.#scheduler.submit({
542
+ key,
543
+ priority: options.priority ?? DEFAULT_TEXT_PRIORITY,
544
+ run: async () => {
545
+ const text = toPageText(index, await this.#inner.pageTextAsync(index));
546
+ this.#text.set(key, text);
547
+ return text;
548
+ },
549
+ });
550
+ const { signal } = options;
551
+ if (signal) {
552
+ if (signal.aborted)
553
+ handle.cancel('signal aborted');
554
+ else
555
+ signal.addEventListener('abort', () => handle.cancel('signal aborted'), {
556
+ once: true,
557
+ });
558
+ }
559
+ return handle.promise;
560
+ }
561
+ /**
562
+ * Extract every page's text up front, so a later search is immediate.
563
+ *
564
+ * Worth calling on a long document: on native this fans out across rayon rather
565
+ * than the JS thread pool, which an addon cannot resize past four threads —
566
+ * measured 15ms for a 14-page paper against ~1ms per page one at a time.
567
+ *
568
+ * On wasm it walks the pages through the scheduler instead. The rayon batch is a
569
+ * native-only path for the same reason `renderPages` is: rayon's wasm workers are
570
+ * Web Workers the JS event loop has to create, and driving a batch from a blocked
571
+ * thread traps (`docs/spike-results.md`, "wasm parallel rendering is UNSTABLE").
572
+ *
573
+ * Idempotent, and never necessary — {@link search} extracts what it needs as it
574
+ * goes. This only trades a pause now for instant results later.
575
+ */
576
+ async indexText(options = {}) {
577
+ this.#indexed ??= this.#index(options).catch((e) => {
578
+ // A failed pass must not be remembered as a completed one.
579
+ this.#indexed = undefined;
580
+ throw e;
581
+ });
582
+ return this.#indexed;
583
+ }
584
+ async #index(options) {
585
+ if (currentRuntime() === 'native') {
586
+ const all = await this.#inner.pageTextsAsync(0, this.pageCount);
587
+ for (const [i, native] of all.entries()) {
588
+ this.#text.set(`text:${i}`, toPageText(i, native));
589
+ }
590
+ return;
591
+ }
592
+ // The scheduler bounds how many run at once, so this stays within the four
593
+ // in-flight tasks napi-rs's browser glue allows.
594
+ await Promise.all(range(0, this.pageCount).map((i) => this.pageText(i, options)));
595
+ }
596
+ /**
597
+ * Find `query` in the document, yielding matches as each page is searched.
598
+ *
599
+ * Streaming rather than collected, because the first hit is usually the one the user
600
+ * wants and a long document should not make them wait for the last. Breaking out of
601
+ * the loop stops the search.
602
+ *
603
+ * `order` is the lever a viewer wants: searching outward from the current page finds
604
+ * the nearest hit first, which is almost never page 1.
605
+ *
606
+ * @example
607
+ * ```ts
608
+ * for await (const hit of doc.search('site plan', { order: outward(current) })) {
609
+ * show(hit.page, hit.rects);
610
+ * break;
611
+ * }
612
+ * ```
613
+ */
614
+ async *search(query, options = {}) {
615
+ if (query.trim() === '')
616
+ return;
617
+ const pages = options.order ?? range(0, this.pageCount);
618
+ const limit = options.limit ?? Number.POSITIVE_INFINITY;
619
+ let found = 0;
620
+ for (const page of pages) {
621
+ if (options.signal?.aborted)
622
+ return;
623
+ const text = await this.pageText(page, {
624
+ priority: options.priority ?? DEFAULT_TEXT_PRIORITY,
625
+ signal: options.signal,
626
+ });
627
+ for (const match of searchPageText(text, query, options)) {
628
+ yield match;
629
+ if (++found >= limit)
630
+ return;
631
+ }
632
+ }
633
+ }
634
+ /** Extracted page text held for reuse, and how often that has paid off. */
635
+ get textCache() {
636
+ return this.#text.stats;
637
+ }
210
638
  /** How many pages this document will render at once. */
211
639
  get concurrency() {
212
640
  return this.#limit;
@@ -1 +1 @@
1
- {"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAmB,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,IAAI,EACJ,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAkB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAWtC,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;;GAIG;AACH,MAAM,UAAU,GAAG,WAAW,CAAC;AAE/B,oFAAoF;AACpF,MAAM,mBAAmB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAO9C,sEAAsE;AACtE,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,MAAiB,EACjB,OAAO,GAAgB,EAAE;IAEzB,IAAI,EAAE,CAAC;IACP,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CA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AM,CAAC,GAAG;QACf,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,MAAM;YACR,OAAO,MAAM,CAAC,MAAM,CAAC;QACvB,CAAC;QACD,WAAW,EAAE,CAAC,QAAgB,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC;QAC/D,MAAM,EAAE,CAAC,MAAe,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,kDAAkD;AAClD,SAAS,YAAY,CAAC,GAAW,EAAE,IAAkB;IACnD,OAAO;QACL,GAAG;QACH,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;QAC9B,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;QAC/B,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;QACrB,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;KACjB,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,KAAa,EAAE,GAAW;IACvC,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9C,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { type PageImage as NativePageImage } from '@build-qube/papyra-native';
2
+ import { type EncodedImage, type EncodeOptions } from './encoded.js';
3
+ import type { RenderedPage } from './types.js';
4
+ export type { EncodedFormat, EncodedImage, EncodeOptions, RasterFormat, SvgPage, } from './encoded.js';
5
+ export { encodedImage, mimeType, svgPage } from './encoded.js';
6
+ /**
7
+ * Encode a page you already hold — a cache hit, or one you have just painted.
8
+ *
9
+ * This copies the pixels back into Rust, because a `Uint8Array` points at the JS heap
10
+ * and cannot be held across the worker-thread boundary. When you do not also need the
11
+ * raw pixels, `doc.renderImage()` skips the round trip entirely.
12
+ */
13
+ export declare function encode(page: RenderedPage, options?: EncodeOptions): Promise<EncodedImage>;
14
+ /**
15
+ * A page held in Rust, encoded on demand.
16
+ *
17
+ * The pixels never cross into JS. A 42x30in drawing at 150 DPI is 6.5 MB raw and a
18
+ * fraction of that encoded, so for export the raw buffer is pure overhead. There is no
19
+ * accessor for it on purpose: use `renderPage` when you want pixels, this when you
20
+ * want a file.
21
+ */
22
+ export declare class PageImage {
23
+ #private;
24
+ constructor(inner: NativePageImage);
25
+ /** Output width in pixels. */
26
+ get width(): number;
27
+ /** Output height in pixels. */
28
+ get height(): number;
29
+ /** Size of the *raw* bitmap still held in Rust. Encoded output is much smaller. */
30
+ get byteLength(): number;
31
+ /** Encode to {@link EncodeOptions.format}, defaulting to WebP. */
32
+ encode(options?: EncodeOptions): Promise<EncodedImage>;
33
+ /** Lossless VP8L. The default, and ~3x smaller than PNG on page content. */
34
+ toWebp(options?: Omit<EncodeOptions, 'format' | 'quality'>): Promise<EncodedImage>;
35
+ /** Lossless PNG. Reach for it when the consumer cannot be trusted to read WebP. */
36
+ toPng(options?: Omit<EncodeOptions, 'format' | 'quality'>): Promise<EncodedImage>;
37
+ /**
38
+ * Lossy JPEG at `quality` (1-100, default 80).
39
+ *
40
+ * No alpha: transparent pixels composite onto white, matching how pages render.
41
+ */
42
+ toJpeg(quality?: number, options?: Omit<EncodeOptions, 'format'>): Promise<EncodedImage>;
43
+ /**
44
+ * Encode straight to a `data:` URL. Nothing but the finished string crosses the
45
+ * boundary — not the pixels, not the encoded bytes.
46
+ */
47
+ toDataUrl(options?: EncodeOptions): Promise<string>;
48
+ }
49
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,IAAI,eAAe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