@build-qube/papyra 0.0.3 → 0.1.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.
- package/README.md +102 -0
- package/dist/cache.d.ts +3 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js.map +1 -1
- package/dist/document.d.ts +135 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +237 -10
- package/dist/document.js.map +1 -1
- package/dist/encode.d.ts +49 -0
- package/dist/encode.d.ts.map +1 -0
- package/dist/encode.js +71 -0
- package/dist/encode.js.map +1 -0
- package/dist/encoded.d.ts +62 -0
- package/dist/encoded.d.ts.map +1 -0
- package/dist/encoded.js +56 -0
- package/dist/encoded.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/outline.d.ts +64 -0
- package/dist/outline.d.ts.map +1 -0
- package/dist/outline.js +67 -0
- package/dist/outline.js.map +1 -0
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +2 -0
- package/dist/runtime.js.map +1 -1
- package/dist/scheduler.d.ts +20 -2
- package/dist/scheduler.d.ts.map +1 -1
- package/dist/scheduler.js +15 -0
- package/dist/scheduler.js.map +1 -1
- package/dist/search.d.ts +50 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +151 -0
- package/dist/search.js.map +1 -0
- package/dist/text.d.ts +111 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +75 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# papyra
|
|
2
|
+
|
|
3
|
+
Fast PDF rendering for Node **and** the browser, from one Rust core. The engine
|
|
4
|
+
([hayro](https://github.com/LaurenzV/hayro)) is compiled in — there are no pdfium
|
|
5
|
+
binaries to ship and nothing to install alongside it.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @build-qube/papyra
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The native addon and the browser wasm build ship as optional dependencies; your
|
|
14
|
+
package manager picks the right one.
|
|
15
|
+
|
|
16
|
+
## Render a page
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { open, paintToCanvas } from '@build-qube/papyra';
|
|
20
|
+
|
|
21
|
+
const doc = await open(file); // Uint8Array | ArrayBuffer | Blob | File
|
|
22
|
+
const page = await doc.renderPage(0, { fitWidth: 1600 });
|
|
23
|
+
|
|
24
|
+
paintToCanvas(page, canvas);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`renderPage` never blocks the event loop. `page` is tightly packed RGBA8, so
|
|
28
|
+
`paintToCanvas` is a convenience rather than the only route — `toImageData`, the
|
|
29
|
+
encoders, or your own buffer handling all work from the same bytes.
|
|
30
|
+
|
|
31
|
+
## Thumbnails
|
|
32
|
+
|
|
33
|
+
`stream` yields pages as they finish, with concurrency bounded for you:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
for await (const { page, bitmap } of doc.stream({ fitWidth: 160 })) {
|
|
37
|
+
paint(page, bitmap);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Say what is urgent
|
|
42
|
+
|
|
43
|
+
papyra does not guess which page matters — a viewer knows what is on screen and the
|
|
44
|
+
library does not. Attach a priority and the queue honours it. **Lower runs first**,
|
|
45
|
+
and the default is the most urgent tier, so callers who do not care can ignore this
|
|
46
|
+
entirely.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
const doc = await open(file, { concurrency: 4 }); // viewers want a narrow pool
|
|
50
|
+
|
|
51
|
+
// Thumbnails yield to whatever is on screen.
|
|
52
|
+
for await (const t of doc.stream({ fitWidth: 160, priority: 2 })) { /* … */ }
|
|
53
|
+
|
|
54
|
+
// Reprioritise on scroll instead of cancelling and resubmitting.
|
|
55
|
+
const job = doc.render(12, { fitWidth: 1600, priority: 2 });
|
|
56
|
+
onScroll(() => job.setPriority(isVisible(12) ? 0 : 3));
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Requests for the same page at the same size coalesce into one render. Pending work
|
|
60
|
+
reorders freely; work already running is never interrupted.
|
|
61
|
+
|
|
62
|
+
## Export, text, and outlines
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const image = await doc.renderImage(0, { fitWidth: 2000 });
|
|
66
|
+
await writeFile('page-0.webp', (await image.toWebp()).bytes);
|
|
67
|
+
|
|
68
|
+
for await (const hit of doc.search('site plan')) {
|
|
69
|
+
highlight(hit.page, hit.rects);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const node of await doc.outline()) {
|
|
73
|
+
if (node.page !== null) goTo(node.page);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`renderImage` keeps the pixels in Rust and encodes on demand, so nothing but the
|
|
78
|
+
finished file crosses into JS.
|
|
79
|
+
|
|
80
|
+
## Two things that will bite you
|
|
81
|
+
|
|
82
|
+
**Size with `fitWidth`, not `dpi`.** Page areas vary by two orders of magnitude. At a
|
|
83
|
+
fixed 36 DPI, US Letter is a 216x279 thumbnail while a 42x30in drawing is a 1512x1080,
|
|
84
|
+
6.5 MB image. Sizing by output width keeps cost proportional to what you actually
|
|
85
|
+
display; renders above 100 MP are refused outright.
|
|
86
|
+
|
|
87
|
+
**The browser build needs cross-origin isolation.** It uses shared wasm memory, so
|
|
88
|
+
`SharedArrayBuffer` must be available. Serve your page with:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
Cross-Origin-Opener-Policy: same-origin
|
|
92
|
+
Cross-Origin-Embedder-Policy: require-corp
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## More
|
|
96
|
+
|
|
97
|
+
The [full API reference](https://buildqube.github.io/Papyra/docs) is generated from
|
|
98
|
+
these sources, so it never drifts from them. The
|
|
99
|
+
[project README](https://github.com/BuildQube/Papyra) covers architecture, benchmarks
|
|
100
|
+
against pdf.js, and the measurements behind these defaults.
|
|
101
|
+
|
|
102
|
+
MIT.
|
package/dist/cache.d.ts
CHANGED
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
export interface CacheStats {
|
|
16
16
|
/** Bytes currently held. */
|
|
17
17
|
bytes: number;
|
|
18
|
+
/** Pages currently held. */
|
|
18
19
|
entries: number;
|
|
20
|
+
/** Lookups served without rendering. */
|
|
19
21
|
hits: number;
|
|
22
|
+
/** Lookups that had to render. */
|
|
20
23
|
misses: number;
|
|
21
24
|
/** Entries dropped to stay under budget. */
|
|
22
25
|
evictions: number;
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,UAAU;IACzB,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,WAAW,CAAC,CAAC;;IAUxB,YAAY,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,EAG5D;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAW9B;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAc/B;IAcD,KAAK,IAAI,IAAI,CAGZ;IAED,IAAI,KAAK,IAAI,UAAU,CAQtB;CACF"}
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,UAAU;IACzB,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,WAAW,CAAC,CAAC;;IAUxB,YAAY,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,EAG5D;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAW9B;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAc/B;IAcD,KAAK,IAAI,IAAI,CAGZ;IAED,IAAI,KAAK,IAAI,UAAU,CAQtB;CACF"}
|
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAeH,MAAM,OAAO,WAAW;IACb,OAAO,CAAS;IAChB,OAAO,CAAuB;IACvC,wFAAwF;IAC/E,QAAQ,GAAG,IAAI,GAAG,EAAa,CAAC;IACzC,MAAM,GAAG,CAAC,CAAC;IACX,KAAK,GAAG,CAAC,CAAC;IACV,OAAO,GAAG,CAAC,CAAC;IACZ,UAAU,GAAG,CAAC,CAAC;IAEf,YAAY,WAAmB,EAAE,MAA4B;QAC3D,IAAI,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AI,IAAI,CAAC;QACpB,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,yDAAyD;YACzD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;YAC3C,IAAI,MAAM,CAAC,IAAI;gBAAE,OAAO;YACxB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9C,IAAI,KAAK,KAAK,SAAS;gBAAE,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC5D,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACnC,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,KAAK;QACP,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;YAC3B,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,SAAS,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAC;IACJ,CAAC;CACF"}
|
package/dist/document.d.ts
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
import { PdfDocument as NativeDocument } from '@build-qube/papyra-native';
|
|
2
2
|
import { type CacheStats } from './cache.js';
|
|
3
|
+
import { PageImage } from './encode.js';
|
|
4
|
+
import { type OutlineNode } from './outline.js';
|
|
3
5
|
import { type JobHandle } from './scheduler.js';
|
|
4
|
-
import
|
|
6
|
+
import { type SearchMatch } from './search.js';
|
|
7
|
+
import { type PageText } from './text.js';
|
|
8
|
+
import type { OpenOptions, PageSize, PdfSource, RenderedPage, RenderOptions, SearchOptions, StreamedPage, StreamOptions } from './types.js';
|
|
5
9
|
/** A queued render, plus whether it was served from cache without rendering at all. */
|
|
6
10
|
export interface RenderHandle extends JobHandle<RenderedPage> {
|
|
11
|
+
/**
|
|
12
|
+
* The page was already in the cache and nothing was queued.
|
|
13
|
+
*
|
|
14
|
+
* `promise` still resolves normally, so this only matters for instrumentation —
|
|
15
|
+
* a cache hit costs none of the ~93ms floor a real render does.
|
|
16
|
+
*/
|
|
7
17
|
readonly cached: boolean;
|
|
8
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* A queued export render. No `cached` flag: unlike {@link RenderHandle} the image path
|
|
21
|
+
* never comes from the cache, which is keyed by page and size with no format dimension.
|
|
22
|
+
*/
|
|
23
|
+
export type ImageHandle = JobHandle<PageImage>;
|
|
9
24
|
/** Open a PDF from bytes, an `ArrayBuffer`, a `Blob`, or a `File`. */
|
|
10
25
|
export declare function open(source: PdfSource, options?: OpenOptions): Promise<Document>;
|
|
26
|
+
/**
|
|
27
|
+
* An open PDF, and the queue and caches that serve it.
|
|
28
|
+
*
|
|
29
|
+
* Every page-level call goes through one shared scheduler, so a thumbnail sweep can
|
|
30
|
+
* never starve the page on screen — attach a {@link RenderOptions.priority} and the
|
|
31
|
+
* queue reorders around it. Construct via {@link open}, not `new`.
|
|
32
|
+
*/
|
|
11
33
|
export declare class Document {
|
|
12
34
|
#private;
|
|
13
35
|
/** @internal — construct via {@link open}. */
|
|
@@ -18,15 +40,73 @@ export declare class Document {
|
|
|
18
40
|
clearCache(): void;
|
|
19
41
|
/** Pages queued but not yet started, pages rendering, and the longest wait so far. */
|
|
20
42
|
get queued(): {
|
|
43
|
+
/** Submitted but not started. These are the ones priority can still reorder. */
|
|
21
44
|
pending: number;
|
|
45
|
+
/** Rendering now. Never preempted, so this is work you are committed to. */
|
|
22
46
|
running: number;
|
|
47
|
+
/**
|
|
48
|
+
* How long the longest-waiting pending job has sat there.
|
|
49
|
+
*
|
|
50
|
+
* The number to watch in a viewer: if it climbs, the pool is too wide for the
|
|
51
|
+
* work or a priority is wrong.
|
|
52
|
+
*/
|
|
23
53
|
oldestWaitMs: number;
|
|
24
54
|
};
|
|
55
|
+
/** How many pages the document has. Page indices are 0-based throughout. */
|
|
25
56
|
get pageCount(): number;
|
|
57
|
+
/**
|
|
58
|
+
* The document outline — bookmarks, the table of contents — as a tree.
|
|
59
|
+
*
|
|
60
|
+
* Resolves to an empty array when the document has no outline, which is the common
|
|
61
|
+
* case. The walk runs off the event loop and the result is memoised, so calling
|
|
62
|
+
* this on every render of a sidebar costs nothing after the first.
|
|
63
|
+
*
|
|
64
|
+
* Entries that point outside the document (a URL, another file) and containers that
|
|
65
|
+
* group children without a destination of their own both have a `dest` of `null`;
|
|
66
|
+
* they are kept because a viewer still lists them.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* for (const node of await doc.outline()) {
|
|
71
|
+
* if (node.page !== null) void doc.render(node.page, { fitWidth: 1600 });
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
outline(): Promise<OutlineNode[]>;
|
|
26
76
|
/** Page dimensions in PDF points (1/72 inch). */
|
|
27
77
|
pageSize(index: number): PageSize;
|
|
28
78
|
/** Render a single page. Never blocks the event loop. */
|
|
29
79
|
renderPage(index: number, options?: RenderOptions): Promise<RenderedPage>;
|
|
80
|
+
/**
|
|
81
|
+
* Render a page for export, keeping the pixels in Rust.
|
|
82
|
+
*
|
|
83
|
+
* The returned {@link PageImage} encodes on demand — `toWebp()`, `toPng()`,
|
|
84
|
+
* `toJpeg()`, `toDataUrl()` — and never hands the raw bitmap to JS. A 42x30in
|
|
85
|
+
* drawing at 150 DPI is 6.5 MB raw and a fraction of that encoded, so for anything
|
|
86
|
+
* leaving the process that buffer is pure overhead.
|
|
87
|
+
*
|
|
88
|
+
* Use `renderPage` when you want to paint to a canvas, and `encode()` when you want
|
|
89
|
+
* both the pixels and a file.
|
|
90
|
+
*
|
|
91
|
+
* Shares the scheduler with every other render, so priority and concurrency behave
|
|
92
|
+
* exactly as they do for `render`. **Not cached** — the cache is keyed by page and
|
|
93
|
+
* size with no format dimension, and it measures raw bytes.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* const img = await doc.renderImage(0, { fitWidth: 2000 });
|
|
98
|
+
* await writeFile('page-0.webp', (await img.toWebp()).bytes);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
renderImage(index: number, options?: RenderOptions): Promise<PageImage>;
|
|
102
|
+
/**
|
|
103
|
+
* As {@link renderImage}, but returns the handle so the job can be reprioritised,
|
|
104
|
+
* cancelled, or timed — the same relationship `render` has to `renderPage`.
|
|
105
|
+
*
|
|
106
|
+
* `timing` is where the export path becomes measurable: it separates queue wait from
|
|
107
|
+
* render time, which end-to-end timing around the promise cannot.
|
|
108
|
+
*/
|
|
109
|
+
imageHandle(index: number, options?: RenderOptions): ImageHandle;
|
|
30
110
|
/**
|
|
31
111
|
* Render a page, returning a handle you can reprioritise or drop.
|
|
32
112
|
*
|
|
@@ -73,6 +153,60 @@ export declare class Document {
|
|
|
73
153
|
* ```
|
|
74
154
|
*/
|
|
75
155
|
stream(options?: StreamOptions): AsyncGenerator<StreamedPage>;
|
|
156
|
+
/**
|
|
157
|
+
* Extract the text of one page.
|
|
158
|
+
*
|
|
159
|
+
* Scheduled like a render, but behind one by default: a search should not stall the
|
|
160
|
+
* page the user is looking at. Results are cached, so searching the same document
|
|
161
|
+
* repeatedly extracts each page once.
|
|
162
|
+
*
|
|
163
|
+
* Extraction is interpretation without rasterisation, which makes it roughly a
|
|
164
|
+
* hundredth the cost of rendering the same page — about 1ms for a dense page of a
|
|
165
|
+
* paper. It is cheap enough to do speculatively.
|
|
166
|
+
*/
|
|
167
|
+
pageText(index: number, options?: {
|
|
168
|
+
priority?: number;
|
|
169
|
+
signal?: AbortSignal;
|
|
170
|
+
}): Promise<PageText>;
|
|
171
|
+
/**
|
|
172
|
+
* Extract every page's text up front, so a later search is immediate.
|
|
173
|
+
*
|
|
174
|
+
* Worth calling on a long document: on native this fans out across rayon rather
|
|
175
|
+
* than the JS thread pool, which an addon cannot resize past four threads —
|
|
176
|
+
* measured 15ms for a 14-page paper against ~1ms per page one at a time.
|
|
177
|
+
*
|
|
178
|
+
* On wasm it walks the pages through the scheduler instead. The rayon batch is a
|
|
179
|
+
* native-only path for the same reason `renderPages` is: rayon's wasm workers are
|
|
180
|
+
* Web Workers the JS event loop has to create, and driving a batch from a blocked
|
|
181
|
+
* thread traps (`docs/spike-results.md`, "wasm parallel rendering is UNSTABLE").
|
|
182
|
+
*
|
|
183
|
+
* Idempotent, and never necessary — {@link search} extracts what it needs as it
|
|
184
|
+
* goes. This only trades a pause now for instant results later.
|
|
185
|
+
*/
|
|
186
|
+
indexText(options?: {
|
|
187
|
+
priority?: number;
|
|
188
|
+
}): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Find `query` in the document, yielding matches as each page is searched.
|
|
191
|
+
*
|
|
192
|
+
* Streaming rather than collected, because the first hit is usually the one the user
|
|
193
|
+
* wants and a long document should not make them wait for the last. Breaking out of
|
|
194
|
+
* the loop stops the search.
|
|
195
|
+
*
|
|
196
|
+
* `order` is the lever a viewer wants: searching outward from the current page finds
|
|
197
|
+
* the nearest hit first, which is almost never page 1.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* for await (const hit of doc.search('site plan', { order: outward(current) })) {
|
|
202
|
+
* show(hit.page, hit.rects);
|
|
203
|
+
* break;
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
search(query: string, options?: SearchOptions): AsyncGenerator<SearchMatch>;
|
|
208
|
+
/** Extracted page text held for reuse, and how often that has paid off. */
|
|
209
|
+
get textCache(): CacheStats;
|
|
76
210
|
/** How many pages this document will render at once. */
|
|
77
211
|
get concurrency(): number;
|
|
78
212
|
}
|
package/dist/document.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,IAAI,cAAc,EAE9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAOlE,OAAO,EAAoB,KAAK,SAAS,EAAa,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,KAAK,QAAQ,EAA6B,MAAM,WAAW,CAAC;AACrE,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,aAAa,EACd,MAAM,YAAY,CAAC;AA+BpB,uFAAuF;AACvF,MAAM,WAAW,YAAa,SAAQ,SAAS,CAAC,YAAY,CAAC;IAC3D;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;AAiB/C,sEAAsE;AACtE,wBAAsB,IAAI,CACxB,MAAM,EAAE,SAAS,EACjB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,QAAQ,CAAC,CAQnB;AAED;;;;;;GAMG;AACH,qBAAa,QAAQ;;IAanB,8CAA8C;IAC9C,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CAAC,CA2CvE;IAED;;;;;;;;;;OAUG;IACG,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GACxD,OAAO,CAAC,QAAQ,CAAC,CAgCnB;IAED;;;;;;;;;;;;;;OAcG;IACG,SAAS,CAAC,OAAO,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAOlE;IAiBD;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,CACX,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAAkB,GAC1B,cAAc,CAAC,WAAW,CAAC,CAmB7B;IAED,2EAA2E;IAC3E,IAAI,SAAS,IAAI,UAAU,CAE1B;IAED,wDAAwD;IACxD,IAAI,WAAW,IAAI,MAAM,CAExB;CACF"}
|
package/dist/document.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
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 } from './encode.js';
|
|
4
|
+
import { buildOutlineTree } from './outline.js';
|
|
3
5
|
import { currentRuntime, hardwareConcurrency, init, MAX_WASM_CONCURRENCY, } from './runtime.js';
|
|
4
6
|
import { DEFAULT_PRIORITY, Scheduler } from './scheduler.js';
|
|
7
|
+
import { searchPageText } from './search.js';
|
|
5
8
|
import { toBytes } from './source.js';
|
|
9
|
+
import { pageTextBytes, toPageText } from './text.js';
|
|
6
10
|
const DEFAULT_DPI = 72;
|
|
7
11
|
/**
|
|
8
12
|
* Refuse renders large enough to take down the tab.
|
|
@@ -12,6 +16,33 @@ const DEFAULT_DPI = 72;
|
|
|
12
16
|
const MAX_PIXELS = 100_000_000;
|
|
13
17
|
/** Default bytes of rendered pages to keep. Roughly eleven 2000px ARCH-E sheets. */
|
|
14
18
|
const DEFAULT_CACHE_BYTES = 128 * 1024 * 1024;
|
|
19
|
+
/**
|
|
20
|
+
* Default bytes of extracted text to keep.
|
|
21
|
+
*
|
|
22
|
+
* Text is three orders of magnitude smaller than the pixels of the same page — a
|
|
23
|
+
* dense page of a paper is ~80 KB against ~11 MB — so this holds hundreds of pages
|
|
24
|
+
* and a repeated search never re-extracts.
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_TEXT_CACHE_BYTES = 32 * 1024 * 1024;
|
|
27
|
+
/**
|
|
28
|
+
* Where text extraction sits in the queue by default.
|
|
29
|
+
*
|
|
30
|
+
* Behind rendering: a search that stalls the page the user is looking at is worse
|
|
31
|
+
* than one that takes another beat to fill in.
|
|
32
|
+
*/
|
|
33
|
+
const DEFAULT_TEXT_PRIORITY = 3;
|
|
34
|
+
/** Wire an `AbortSignal` to a queued job. Cancelling only drops work not yet started. */
|
|
35
|
+
function attachSignal(handle, signal) {
|
|
36
|
+
if (!signal)
|
|
37
|
+
return;
|
|
38
|
+
if (signal.aborted) {
|
|
39
|
+
handle.cancel('signal aborted');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
signal.addEventListener('abort', () => handle.cancel('signal aborted'), {
|
|
43
|
+
once: true,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
15
46
|
/** Open a PDF from bytes, an `ArrayBuffer`, a `Blob`, or a `File`. */
|
|
16
47
|
export async function open(source, options = {}) {
|
|
17
48
|
init();
|
|
@@ -21,11 +52,25 @@ export async function open(source, options = {}) {
|
|
|
21
52
|
: NativeDocument.loadWithPassword(bytes, options.password);
|
|
22
53
|
return new Document(inner, options);
|
|
23
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* An open PDF, and the queue and caches that serve it.
|
|
57
|
+
*
|
|
58
|
+
* Every page-level call goes through one shared scheduler, so a thumbnail sweep can
|
|
59
|
+
* never starve the page on screen — attach a {@link RenderOptions.priority} and the
|
|
60
|
+
* queue reorders around it. Construct via {@link open}, not `new`.
|
|
61
|
+
*/
|
|
24
62
|
export class Document {
|
|
25
63
|
#inner;
|
|
64
|
+
// One queue for every kind of job, `renderImage` included: priority and concurrency
|
|
65
|
+
// are the point of this library, and a bulk export must not starve the visible page.
|
|
26
66
|
#scheduler;
|
|
27
67
|
#limit;
|
|
28
68
|
#cache;
|
|
69
|
+
#text;
|
|
70
|
+
/** Memoised by {@link outline}; the outline cannot change under us. */
|
|
71
|
+
#outline;
|
|
72
|
+
/** Memoised by {@link indexText}. */
|
|
73
|
+
#indexed;
|
|
29
74
|
/** @internal — construct via {@link open}. */
|
|
30
75
|
constructor(inner, options = {}) {
|
|
31
76
|
this.#inner = inner;
|
|
@@ -34,6 +79,7 @@ export class Document {
|
|
|
34
79
|
yieldToUrgent: options.yieldToUrgent,
|
|
35
80
|
});
|
|
36
81
|
this.#cache = new RenderCache(options.cacheBytes ?? DEFAULT_CACHE_BYTES, (page) => page.data.byteLength);
|
|
82
|
+
this.#text = new RenderCache(options.textCacheBytes ?? DEFAULT_TEXT_CACHE_BYTES, pageTextBytes);
|
|
37
83
|
}
|
|
38
84
|
/** Rendered pages held for reuse, and how often that has paid off. */
|
|
39
85
|
get cache() {
|
|
@@ -51,9 +97,39 @@ export class Document {
|
|
|
51
97
|
oldestWaitMs: this.#scheduler.oldestWaitMs,
|
|
52
98
|
};
|
|
53
99
|
}
|
|
100
|
+
/** How many pages the document has. Page indices are 0-based throughout. */
|
|
54
101
|
get pageCount() {
|
|
55
102
|
return this.#inner.pageCount;
|
|
56
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* The document outline — bookmarks, the table of contents — as a tree.
|
|
106
|
+
*
|
|
107
|
+
* Resolves to an empty array when the document has no outline, which is the common
|
|
108
|
+
* case. The walk runs off the event loop and the result is memoised, so calling
|
|
109
|
+
* this on every render of a sidebar costs nothing after the first.
|
|
110
|
+
*
|
|
111
|
+
* Entries that point outside the document (a URL, another file) and containers that
|
|
112
|
+
* group children without a destination of their own both have a `dest` of `null`;
|
|
113
|
+
* they are kept because a viewer still lists them.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* for (const node of await doc.outline()) {
|
|
118
|
+
* if (node.page !== null) void doc.render(node.page, { fitWidth: 1600 });
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
async outline() {
|
|
123
|
+
this.#outline ??= this.#inner
|
|
124
|
+
.outline()
|
|
125
|
+
.then(buildOutlineTree)
|
|
126
|
+
// A failed walk must not be cached as a permanent empty outline.
|
|
127
|
+
.catch((e) => {
|
|
128
|
+
this.#outline = undefined;
|
|
129
|
+
throw e;
|
|
130
|
+
});
|
|
131
|
+
return this.#outline;
|
|
132
|
+
}
|
|
57
133
|
/** Page dimensions in PDF points (1/72 inch). */
|
|
58
134
|
pageSize(index) {
|
|
59
135
|
return this.#inner.pageSize(index);
|
|
@@ -62,6 +138,49 @@ export class Document {
|
|
|
62
138
|
async renderPage(index, options = {}) {
|
|
63
139
|
return this.render(index, options).promise;
|
|
64
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Render a page for export, keeping the pixels in Rust.
|
|
143
|
+
*
|
|
144
|
+
* The returned {@link PageImage} encodes on demand — `toWebp()`, `toPng()`,
|
|
145
|
+
* `toJpeg()`, `toDataUrl()` — and never hands the raw bitmap to JS. A 42x30in
|
|
146
|
+
* drawing at 150 DPI is 6.5 MB raw and a fraction of that encoded, so for anything
|
|
147
|
+
* leaving the process that buffer is pure overhead.
|
|
148
|
+
*
|
|
149
|
+
* Use `renderPage` when you want to paint to a canvas, and `encode()` when you want
|
|
150
|
+
* both the pixels and a file.
|
|
151
|
+
*
|
|
152
|
+
* Shares the scheduler with every other render, so priority and concurrency behave
|
|
153
|
+
* exactly as they do for `render`. **Not cached** — the cache is keyed by page and
|
|
154
|
+
* size with no format dimension, and it measures raw bytes.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const img = await doc.renderImage(0, { fitWidth: 2000 });
|
|
159
|
+
* await writeFile('page-0.webp', (await img.toWebp()).bytes);
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
async renderImage(index, options = {}) {
|
|
163
|
+
return this.imageHandle(index, options).promise;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* As {@link renderImage}, but returns the handle so the job can be reprioritised,
|
|
167
|
+
* cancelled, or timed — the same relationship `render` has to `renderPage`.
|
|
168
|
+
*
|
|
169
|
+
* `timing` is where the export path becomes measurable: it separates queue wait from
|
|
170
|
+
* render time, which end-to-end timing around the promise cannot.
|
|
171
|
+
*/
|
|
172
|
+
imageHandle(index, options = {}) {
|
|
173
|
+
const dpi = this.#resolveDpi(index, options);
|
|
174
|
+
// A distinct key space from `render`, so an image request never coalesces onto a
|
|
175
|
+
// pending raw render (different return type) or vice versa.
|
|
176
|
+
const handle = this.#scheduler.submit({
|
|
177
|
+
key: `image:${index}@${dpi.toFixed(4)}`,
|
|
178
|
+
priority: options.priority ?? DEFAULT_PRIORITY,
|
|
179
|
+
run: () => this.#inner.renderPageImageAsync(index, dpi, options.signal).then((img) => new PageImage(img)),
|
|
180
|
+
});
|
|
181
|
+
attachSignal(handle, options.signal);
|
|
182
|
+
return handle;
|
|
183
|
+
}
|
|
65
184
|
/**
|
|
66
185
|
* Render a page, returning a handle you can reprioritise or drop.
|
|
67
186
|
*
|
|
@@ -92,15 +211,7 @@ export class Document {
|
|
|
92
211
|
return page;
|
|
93
212
|
}),
|
|
94
213
|
});
|
|
95
|
-
|
|
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
|
-
}
|
|
214
|
+
attachSignal(handle, options.signal);
|
|
104
215
|
return liveHandle(handle);
|
|
105
216
|
}
|
|
106
217
|
/**
|
|
@@ -207,6 +318,122 @@ export class Document {
|
|
|
207
318
|
handles.clear();
|
|
208
319
|
}
|
|
209
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* Extract the text of one page.
|
|
323
|
+
*
|
|
324
|
+
* Scheduled like a render, but behind one by default: a search should not stall the
|
|
325
|
+
* page the user is looking at. Results are cached, so searching the same document
|
|
326
|
+
* repeatedly extracts each page once.
|
|
327
|
+
*
|
|
328
|
+
* Extraction is interpretation without rasterisation, which makes it roughly a
|
|
329
|
+
* hundredth the cost of rendering the same page — about 1ms for a dense page of a
|
|
330
|
+
* paper. It is cheap enough to do speculatively.
|
|
331
|
+
*/
|
|
332
|
+
async pageText(index, options = {}) {
|
|
333
|
+
const key = `text:${index}`;
|
|
334
|
+
const hit = this.#text.get(key);
|
|
335
|
+
if (hit)
|
|
336
|
+
return hit;
|
|
337
|
+
// One queue for renders and text both, so priority means something across them.
|
|
338
|
+
// Coalescing by key is what stops a search and a text selection extracting the
|
|
339
|
+
// same page twice.
|
|
340
|
+
const handle = this.#scheduler.submit({
|
|
341
|
+
key,
|
|
342
|
+
priority: options.priority ?? DEFAULT_TEXT_PRIORITY,
|
|
343
|
+
run: async () => {
|
|
344
|
+
const text = toPageText(index, await this.#inner.pageTextAsync(index));
|
|
345
|
+
this.#text.set(key, text);
|
|
346
|
+
return text;
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
const { signal } = options;
|
|
350
|
+
if (signal) {
|
|
351
|
+
if (signal.aborted)
|
|
352
|
+
handle.cancel('signal aborted');
|
|
353
|
+
else
|
|
354
|
+
signal.addEventListener('abort', () => handle.cancel('signal aborted'), {
|
|
355
|
+
once: true,
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
return handle.promise;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Extract every page's text up front, so a later search is immediate.
|
|
362
|
+
*
|
|
363
|
+
* Worth calling on a long document: on native this fans out across rayon rather
|
|
364
|
+
* than the JS thread pool, which an addon cannot resize past four threads —
|
|
365
|
+
* measured 15ms for a 14-page paper against ~1ms per page one at a time.
|
|
366
|
+
*
|
|
367
|
+
* On wasm it walks the pages through the scheduler instead. The rayon batch is a
|
|
368
|
+
* native-only path for the same reason `renderPages` is: rayon's wasm workers are
|
|
369
|
+
* Web Workers the JS event loop has to create, and driving a batch from a blocked
|
|
370
|
+
* thread traps (`docs/spike-results.md`, "wasm parallel rendering is UNSTABLE").
|
|
371
|
+
*
|
|
372
|
+
* Idempotent, and never necessary — {@link search} extracts what it needs as it
|
|
373
|
+
* goes. This only trades a pause now for instant results later.
|
|
374
|
+
*/
|
|
375
|
+
async indexText(options = {}) {
|
|
376
|
+
this.#indexed ??= this.#index(options).catch((e) => {
|
|
377
|
+
// A failed pass must not be remembered as a completed one.
|
|
378
|
+
this.#indexed = undefined;
|
|
379
|
+
throw e;
|
|
380
|
+
});
|
|
381
|
+
return this.#indexed;
|
|
382
|
+
}
|
|
383
|
+
async #index(options) {
|
|
384
|
+
if (currentRuntime() === 'native') {
|
|
385
|
+
const all = await this.#inner.pageTextsAsync(0, this.pageCount);
|
|
386
|
+
for (const [i, native] of all.entries()) {
|
|
387
|
+
this.#text.set(`text:${i}`, toPageText(i, native));
|
|
388
|
+
}
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
// The scheduler bounds how many run at once, so this stays within the four
|
|
392
|
+
// in-flight tasks napi-rs's browser glue allows.
|
|
393
|
+
await Promise.all(range(0, this.pageCount).map((i) => this.pageText(i, options)));
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Find `query` in the document, yielding matches as each page is searched.
|
|
397
|
+
*
|
|
398
|
+
* Streaming rather than collected, because the first hit is usually the one the user
|
|
399
|
+
* wants and a long document should not make them wait for the last. Breaking out of
|
|
400
|
+
* the loop stops the search.
|
|
401
|
+
*
|
|
402
|
+
* `order` is the lever a viewer wants: searching outward from the current page finds
|
|
403
|
+
* the nearest hit first, which is almost never page 1.
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* for await (const hit of doc.search('site plan', { order: outward(current) })) {
|
|
408
|
+
* show(hit.page, hit.rects);
|
|
409
|
+
* break;
|
|
410
|
+
* }
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
async *search(query, options = {}) {
|
|
414
|
+
if (query.trim() === '')
|
|
415
|
+
return;
|
|
416
|
+
const pages = options.order ?? range(0, this.pageCount);
|
|
417
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
418
|
+
let found = 0;
|
|
419
|
+
for (const page of pages) {
|
|
420
|
+
if (options.signal?.aborted)
|
|
421
|
+
return;
|
|
422
|
+
const text = await this.pageText(page, {
|
|
423
|
+
priority: options.priority ?? DEFAULT_TEXT_PRIORITY,
|
|
424
|
+
signal: options.signal,
|
|
425
|
+
});
|
|
426
|
+
for (const match of searchPageText(text, query, options)) {
|
|
427
|
+
yield match;
|
|
428
|
+
if (++found >= limit)
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/** Extracted page text held for reuse, and how often that has paid off. */
|
|
434
|
+
get textCache() {
|
|
435
|
+
return this.#text.stats;
|
|
436
|
+
}
|
|
210
437
|
/** How many pages this document will render at once. */
|
|
211
438
|
get concurrency() {
|
|
212
439
|
return this.#limit;
|
package/dist/document.js.map
CHANGED
|
@@ -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,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