@laminapdf/viewer 0.2.0-alpha.3 → 0.2.0-alpha.5
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 -8
- package/dist/client.d.ts +75 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +192 -32
- package/dist/client.js.map +1 -1
- package/dist/find/controller.d.ts +73 -0
- package/dist/find/controller.d.ts.map +1 -0
- package/dist/find/controller.js +227 -0
- package/dist/find/controller.js.map +1 -0
- package/dist/find/fold.d.ts +23 -0
- package/dist/find/fold.d.ts.map +1 -0
- package/dist/find/fold.js +99 -0
- package/dist/find/fold.js.map +1 -0
- package/dist/find/page.d.ts +44 -0
- package/dist/find/page.d.ts.map +1 -0
- package/dist/find/page.js +173 -0
- package/dist/find/page.js.map +1 -0
- package/dist/first-draw.d.ts +10 -0
- package/dist/first-draw.d.ts.map +1 -0
- package/dist/first-draw.js +33 -0
- package/dist/first-draw.js.map +1 -0
- package/dist/history/history.d.ts +65 -0
- package/dist/history/history.d.ts.map +1 -0
- package/dist/history/history.js +135 -0
- package/dist/history/history.js.map +1 -0
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/layers/box.d.ts +10 -0
- package/dist/layers/box.d.ts.map +1 -0
- package/dist/layers/box.js +19 -0
- package/dist/layers/box.js.map +1 -0
- package/dist/layers/copy.d.ts +26 -0
- package/dist/layers/copy.d.ts.map +1 -0
- package/dist/layers/copy.js +150 -0
- package/dist/layers/copy.js.map +1 -0
- package/dist/layers/highlight-layer.d.ts +31 -0
- package/dist/layers/highlight-layer.d.ts.map +1 -0
- package/dist/layers/highlight-layer.js +95 -0
- package/dist/layers/highlight-layer.js.map +1 -0
- package/dist/layers/link-layer.d.ts +68 -0
- package/dist/layers/link-layer.d.ts.map +1 -0
- package/dist/layers/link-layer.js +279 -0
- package/dist/layers/link-layer.js.map +1 -0
- package/dist/layers/link-url.d.ts +19 -0
- package/dist/layers/link-url.d.ts.map +1 -0
- package/dist/layers/link-url.js +47 -0
- package/dist/layers/link-url.js.map +1 -0
- package/dist/layers/spans.d.ts +36 -0
- package/dist/layers/spans.d.ts.map +1 -0
- package/dist/layers/spans.js +103 -0
- package/dist/layers/spans.js.map +1 -0
- package/dist/layers/structure-layer.d.ts +15 -0
- package/dist/layers/structure-layer.d.ts.map +1 -0
- package/dist/layers/structure-layer.js +155 -0
- package/dist/layers/structure-layer.js.map +1 -0
- package/dist/layers/text-layer.d.ts +70 -0
- package/dist/layers/text-layer.d.ts.map +1 -0
- package/dist/layers/text-layer.js +576 -0
- package/dist/layers/text-layer.js.map +1 -0
- package/dist/layout/range.d.ts +3 -0
- package/dist/layout/range.d.ts.map +1 -0
- package/dist/layout/range.js +5 -0
- package/dist/layout/range.js.map +1 -0
- package/dist/network/watch.d.ts +30 -0
- package/dist/network/watch.d.ts.map +1 -0
- package/dist/network/watch.js +181 -0
- package/dist/network/watch.js.map +1 -0
- package/dist/protocol.d.ts +193 -6
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +16 -4
- package/dist/protocol.js.map +1 -1
- package/dist/render/tiles.d.ts +43 -3
- package/dist/render/tiles.d.ts.map +1 -1
- package/dist/render/tiles.js +62 -10
- package/dist/render/tiles.js.map +1 -1
- package/dist/source/http-range.d.ts +59 -0
- package/dist/source/http-range.d.ts.map +1 -0
- package/dist/source/http-range.js +284 -0
- package/dist/source/http-range.js.map +1 -0
- package/dist/source/opfs.d.ts +35 -0
- package/dist/source/opfs.d.ts.map +1 -0
- package/dist/source/opfs.js +178 -0
- package/dist/source/opfs.js.map +1 -0
- package/dist/thumbnails/strip.d.ts +37 -0
- package/dist/thumbnails/strip.d.ts.map +1 -0
- package/dist/thumbnails/strip.js +324 -0
- package/dist/thumbnails/strip.js.map +1 -0
- package/dist/view/budgets.d.ts +29 -0
- package/dist/view/budgets.d.ts.map +1 -0
- package/dist/view/budgets.js +63 -0
- package/dist/view/budgets.js.map +1 -0
- package/dist/view/touch.d.ts +71 -0
- package/dist/view/touch.d.ts.map +1 -0
- package/dist/view/touch.js +220 -0
- package/dist/view/touch.js.map +1 -0
- package/dist/view/user-select.d.ts +3 -0
- package/dist/view/user-select.d.ts.map +1 -0
- package/dist/view/user-select.js +10 -0
- package/dist/view/user-select.js.map +1 -0
- package/dist/view/viewer.d.ts +102 -1
- package/dist/view/viewer.d.ts.map +1 -1
- package/dist/view/viewer.js +660 -95
- package/dist/view/viewer.js.map +1 -1
- package/dist/worker/document.d.ts +53 -1
- package/dist/worker/document.d.ts.map +1 -1
- package/dist/worker/document.js +222 -24
- package/dist/worker/document.js.map +1 -1
- package/dist/worker/entry.d.ts +1 -1
- package/dist/worker/entry.d.ts.map +1 -1
- package/dist/worker/entry.js +2 -0
- package/dist/worker/entry.js.map +1 -1
- package/dist/worker/find.d.ts +7 -0
- package/dist/worker/find.d.ts.map +1 -0
- package/dist/worker/find.js +46 -0
- package/dist/worker/find.js.map +1 -0
- package/dist/worker/methods.d.ts.map +1 -1
- package/dist/worker/methods.js +49 -4
- package/dist/worker/methods.js.map +1 -1
- package/dist/worker/navigation.d.ts +10 -0
- package/dist/worker/navigation.d.ts.map +1 -0
- package/dist/worker/navigation.js +34 -0
- package/dist/worker/navigation.js.map +1 -0
- package/dist/worker/network.d.ts +4 -0
- package/dist/worker/network.d.ts.map +1 -0
- package/dist/worker/network.js +24 -0
- package/dist/worker/network.js.map +1 -0
- package/dist/worker/print.d.ts +14 -0
- package/dist/worker/print.d.ts.map +1 -0
- package/dist/worker/print.js +49 -0
- package/dist/worker/print.js.map +1 -0
- package/dist/worker/recent-pages.d.ts +14 -0
- package/dist/worker/recent-pages.d.ts.map +1 -0
- package/dist/worker/recent-pages.js +53 -0
- package/dist/worker/recent-pages.js.map +1 -0
- package/dist/worker/render.d.ts +5 -2
- package/dist/worker/render.d.ts.map +1 -1
- package/dist/worker/render.js +16 -6
- package/dist/worker/render.js.map +1 -1
- package/dist/worker/text.d.ts +25 -0
- package/dist/worker/text.d.ts.map +1 -0
- package/dist/worker/text.js +82 -0
- package/dist/worker/text.js.map +1 -0
- package/dist/zoom/destination.d.ts +18 -0
- package/dist/zoom/destination.d.ts.map +1 -0
- package/dist/zoom/destination.js +56 -0
- package/dist/zoom/destination.js.map +1 -0
- package/package.json +6 -5
package/dist/worker/entry.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// The viewer's document worker: `@laminapdf/sdk/worker`'s server with the viewer's methods
|
|
2
2
|
// added, so it speaks the same protocol (handshake, queue, cancellation, errors, crash reports).
|
|
3
3
|
// Started by ViewerClient (`new Worker(new URL("./worker/entry.js", import.meta.url))`).
|
|
4
|
+
// The network log comes first: its wrappers must be in place before any other module runs.
|
|
5
|
+
import "./network.js";
|
|
4
6
|
import { serve } from "@laminapdf/sdk/worker/server";
|
|
5
7
|
import { viewerMethods } from "./methods.js";
|
|
6
8
|
serve({ methods: viewerMethods });
|
package/dist/worker/entry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../src/worker/entry.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,iGAAiG;AACjG,yFAAyF;AACzF,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../src/worker/entry.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,iGAAiG;AACjG,yFAAyF;AACzF,2FAA2F;AAC3F,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FindOptions } from "../find/fold.js";
|
|
2
|
+
import type { FindPageResult } from "../protocol.js";
|
|
3
|
+
/** The matches of `query` on each of `pages`, in that order. */
|
|
4
|
+
export declare function find(query: string, options: FindOptions, pages: readonly number[], signal: AbortSignal): Promise<FindPageResult[]>;
|
|
5
|
+
/** Forgets every page's searchable text: the document closed. */
|
|
6
|
+
export declare function forgetSearch(): void;
|
|
7
|
+
//# sourceMappingURL=find.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../src/worker/find.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAoBrD,gEAAgE;AAChE,wBAAsB,IAAI,CACxB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,cAAc,EAAE,CAAC,CAkB3B;AAED,iEAAiE;AACjE,wBAAgB,YAAY,IAAI,IAAI,CAEnC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Find in the document Web Worker: a call searches a few pages and returns each page's matches as
|
|
2
|
+
// quads in page space. The viewer's find controller asks for the next pages only once a call
|
|
3
|
+
// returns, at `background` priority, so renders run between calls and a new query simply stops
|
|
4
|
+
// asking. Each page's searchable text stays in a cache of its own (32 MB at most), so typing a
|
|
5
|
+
// longer query searches pages already read without reading their text again; a page's glyphs are
|
|
6
|
+
// read again only where it has matches.
|
|
7
|
+
import { matchRanges, quadsOfMatches, searchText, snippetOf } from "../find/page.js";
|
|
8
|
+
import { RecentPages } from "./recent-pages.js";
|
|
9
|
+
import { pageGlyphs } from "./text.js";
|
|
10
|
+
/** The cache's budget, in bytes of UTF-16 text and glyph maps. */
|
|
11
|
+
const SEARCH_CACHE_BYTES = 32 * 1024 * 1024;
|
|
12
|
+
const bytesOf = (s) => s.text.length * 2 + s.lo.byteLength + s.hi.byteLength + s.runOf.byteLength;
|
|
13
|
+
const cache = new RecentPages(SEARCH_CACHE_BYTES, bytesOf);
|
|
14
|
+
/** Page `index`'s searchable text, cached by document and page. */
|
|
15
|
+
async function searchable(index, signal) {
|
|
16
|
+
const hit = cache.get(index);
|
|
17
|
+
if (hit !== undefined)
|
|
18
|
+
return hit;
|
|
19
|
+
const search = searchText(await pageGlyphs(index, signal, false));
|
|
20
|
+
cache.set(index, search);
|
|
21
|
+
return search;
|
|
22
|
+
}
|
|
23
|
+
/** The matches of `query` on each of `pages`, in that order. */
|
|
24
|
+
export async function find(query, options, pages, signal) {
|
|
25
|
+
const out = [];
|
|
26
|
+
for (const page of pages) {
|
|
27
|
+
signal.throwIfAborted();
|
|
28
|
+
const search = await searchable(page, signal);
|
|
29
|
+
const empty = search.text.trim() === "";
|
|
30
|
+
// Most pages have no match: the glyphs are read again only for a page that has one.
|
|
31
|
+
const { folded, ranges } = matchRanges(search, query, options);
|
|
32
|
+
const quads = ranges.length === 0 ? [] : quadsOfMatches(await pageGlyphs(page, signal, false), search, folded, ranges);
|
|
33
|
+
out.push({
|
|
34
|
+
page,
|
|
35
|
+
matches: quads.map((q) => [...q]),
|
|
36
|
+
snippets: ranges.map((r) => snippetOf(search, folded, r)),
|
|
37
|
+
...(empty ? { noText: true } : {}),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
/** Forgets every page's searchable text: the document closed. */
|
|
43
|
+
export function forgetSearch() {
|
|
44
|
+
cache.clear();
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=find.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../src/worker/find.ts"],"names":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Root":"","sources":["../../src/worker/methods.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAmBpE,2EAA2E;AAC3E,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAsDnE,CAAC"}
|
package/dist/worker/methods.js
CHANGED
|
@@ -1,19 +1,64 @@
|
|
|
1
1
|
// The viewer's methods on the document worker: the extension `entry.ts` serves, and test
|
|
2
2
|
// workers too, which add their own hooks on top so none ships.
|
|
3
|
-
import { closeDocument, current, initBackend, openDocument, workerMemory } from "./document.js";
|
|
3
|
+
import { closeDocument, current, currentDocument, initBackend, openDocument, textModel, workerMemory, } from "./document.js";
|
|
4
|
+
import { find, forgetSearch } from "./find.js";
|
|
5
|
+
import { forgetLinks, namedDestination, outline, pageLinks } from "./navigation.js";
|
|
6
|
+
import { networkLog } from "./network.js";
|
|
7
|
+
import { fileBytes, printPage, replyBytes } from "./print.js";
|
|
4
8
|
import { render, reply } from "./render.js";
|
|
9
|
+
import { forgetText, pageText, readingOrder, reflow, replyText, structure } from "./text.js";
|
|
5
10
|
/** The viewer's worker methods, by name (see `Methods` in protocol.ts). */
|
|
6
11
|
export const viewerMethods = {
|
|
7
12
|
initBackend: { run: ([init]) => initBackend(init) },
|
|
8
13
|
openDocument: {
|
|
9
|
-
run: ([source, options], { signal }) => openDocument(source, options, signal),
|
|
14
|
+
run: ([source, options, ticket], { signal }) => openDocument(source, options, signal, ticket),
|
|
15
|
+
},
|
|
16
|
+
currentDocument: { run: () => currentDocument() },
|
|
17
|
+
closeDocument: {
|
|
18
|
+
run: () => {
|
|
19
|
+
forgetText();
|
|
20
|
+
forgetSearch();
|
|
21
|
+
forgetLinks();
|
|
22
|
+
return closeDocument();
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
pageInfo: {
|
|
26
|
+
run: ([index], { signal }) => {
|
|
27
|
+
const { model } = current();
|
|
28
|
+
return model.ensure(() => model.pageInfo(index), { signal });
|
|
29
|
+
},
|
|
10
30
|
},
|
|
11
|
-
closeDocument: { run: () => closeDocument() },
|
|
12
|
-
pageInfo: { run: ([index]) => current().model.pageInfo(index) },
|
|
13
31
|
render: {
|
|
14
32
|
run: ([request, id], { signal }) => render(request, id, signal),
|
|
15
33
|
reply: (tile) => reply(tile),
|
|
16
34
|
},
|
|
17
35
|
memory: { run: () => workerMemory() },
|
|
36
|
+
networkLog: { run: () => networkLog() },
|
|
37
|
+
pageText: {
|
|
38
|
+
run: ([index], { signal }) => pageText(index, signal),
|
|
39
|
+
reply: (text) => replyText(text),
|
|
40
|
+
},
|
|
41
|
+
structure: { run: (_params, { signal }) => structure(signal) },
|
|
42
|
+
reflow: { run: (_params, { signal }) => reflow(signal) },
|
|
43
|
+
readingOrder: { run: ([index], { signal }) => readingOrder(index, signal) },
|
|
44
|
+
find: {
|
|
45
|
+
run: ([query, options, pages], { signal }) => find(query, options, pages, signal),
|
|
46
|
+
},
|
|
47
|
+
outline: { run: (_params, { signal }) => outline(signal) },
|
|
48
|
+
namedDestination: { run: ([name], { signal }) => namedDestination(name, signal) },
|
|
49
|
+
pageLinks: { run: ([index], { signal }) => pageLinks(index, signal) },
|
|
50
|
+
properties: {
|
|
51
|
+
run: async (_params, { signal }) => {
|
|
52
|
+
const model = await textModel(signal);
|
|
53
|
+
return model.ensure(() => model.properties(), { signal });
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
printPage: {
|
|
57
|
+
run: ([index, options], { signal }) => printPage(index, options, signal),
|
|
58
|
+
},
|
|
59
|
+
fileBytes: {
|
|
60
|
+
run: (_params, { signal }) => fileBytes(signal),
|
|
61
|
+
reply: (bytes) => replyBytes(bytes),
|
|
62
|
+
},
|
|
18
63
|
};
|
|
19
64
|
//# sourceMappingURL=methods.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../src/worker/methods.ts"],"names":[],"m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MAAM,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC;QAC/C,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAmB,CAAC;KAClD;CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OutlineNode, PageLink, Target } from "@laminapdf/sdk";
|
|
2
|
+
/** The outline's top-level items, each with its children; empty without one. */
|
|
3
|
+
export declare function outline(signal: AbortSignal): Promise<OutlineNode[]>;
|
|
4
|
+
/** Where the named destination `name` goes, or `undefined` when the document has no such name. */
|
|
5
|
+
export declare function namedDestination(name: string, signal: AbortSignal): Promise<Target | undefined>;
|
|
6
|
+
/** Page `index`'s links, in annotation order (cached). */
|
|
7
|
+
export declare function pageLinks(index: number, signal: AbortSignal): Promise<readonly PageLink[]>;
|
|
8
|
+
/** Forgets every page's links: the document closed. */
|
|
9
|
+
export declare function forgetLinks(): void;
|
|
10
|
+
//# sourceMappingURL=navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/worker/navigation.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAOpE,gFAAgF;AAChF,wBAAsB,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAGzE;AAED,kGAAkG;AAClG,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAGrG;AAED,0DAA0D;AAC1D,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,QAAQ,EAAE,CAAC,CAOhG;AAED,uDAAuD;AACvD,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Moving through the open document: its outline, named destinations and each page's links, read
|
|
2
|
+
// by Lamina PDF in the worker (the extract module, which the text layer loads too), each target a
|
|
3
|
+
// page and a view in page space. The outline is read when a reader first asks for it, since it can
|
|
4
|
+
// hold thousands of items. The last pages' links are kept, since a page scrolled back into view
|
|
5
|
+
// asks again.
|
|
6
|
+
import { textModel } from "./document.js";
|
|
7
|
+
import { CACHED_PAGES, RecentPages } from "./recent-pages.js";
|
|
8
|
+
/** The last pages' links. */
|
|
9
|
+
const links = new RecentPages(CACHED_PAGES);
|
|
10
|
+
/** The outline's top-level items, each with its children; empty without one. */
|
|
11
|
+
export async function outline(signal) {
|
|
12
|
+
const model = await textModel(signal);
|
|
13
|
+
return model.ensure(() => model.outline(), { signal });
|
|
14
|
+
}
|
|
15
|
+
/** Where the named destination `name` goes, or `undefined` when the document has no such name. */
|
|
16
|
+
export async function namedDestination(name, signal) {
|
|
17
|
+
const model = await textModel(signal);
|
|
18
|
+
return model.ensure(() => model.namedDestination(name), { signal });
|
|
19
|
+
}
|
|
20
|
+
/** Page `index`'s links, in annotation order (cached). */
|
|
21
|
+
export async function pageLinks(index, signal) {
|
|
22
|
+
const cached = links.get(index);
|
|
23
|
+
if (cached !== undefined)
|
|
24
|
+
return cached;
|
|
25
|
+
const model = await textModel(signal);
|
|
26
|
+
const read = await model.ensure(() => model.pageLinks(index), { signal });
|
|
27
|
+
links.set(index, read);
|
|
28
|
+
return read;
|
|
29
|
+
}
|
|
30
|
+
/** Forgets every page's links: the document closed. */
|
|
31
|
+
export function forgetLinks() {
|
|
32
|
+
links.clear();
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../src/worker/navigation.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,kGAAkG;AAClG,mGAAmG;AACnG,gGAAgG;AAChG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AAuD;AACvD,MAAM,UAAU,WAAW;IACzB,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/worker/network.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAkC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAmBvF,8EAA8E;AAC9E,wBAAgB,UAAU,IAAI,gBAAgB,CAE7C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The document worker's network log (ADR 0011, R13). Imported first by entry.ts, so the wrappers
|
|
2
|
+
// are in place before any other module of the worker can capture an unwrapped `fetch`. Every
|
|
3
|
+
// request and every blocked request is kept (the page asks for them all with `networkLog`, so
|
|
4
|
+
// nothing sent before the page listened is lost) and posted as it happens (`network` and
|
|
5
|
+
// `csp-violation` events). Each event carries its index in the log, so the page can merge the two
|
|
6
|
+
// without counting a request twice.
|
|
7
|
+
import { emit } from "@laminapdf/sdk/worker/server";
|
|
8
|
+
import { watchNetwork } from "../network/watch.js";
|
|
9
|
+
const worker = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
10
|
+
const requests = [];
|
|
11
|
+
const violations = [];
|
|
12
|
+
watchNetwork(globalThis, {
|
|
13
|
+
request(record) {
|
|
14
|
+
emit("network", { worker, index: requests.push(record) - 1, record });
|
|
15
|
+
},
|
|
16
|
+
violation(violation) {
|
|
17
|
+
emit("csp-violation", { worker, index: violations.push(violation) - 1, violation });
|
|
18
|
+
},
|
|
19
|
+
}, "worker");
|
|
20
|
+
/** Everything the worker has requested, and had blocked, since it started. */
|
|
21
|
+
export function networkLog() {
|
|
22
|
+
return { worker, requests: [...requests], violations: [...violations] };
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/worker/network.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,6FAA6F;AAC7F,8FAA8F;AAC9F,yFAAyF;AACzF,kGAAkG;AAClG,oCAAoC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,MAAM,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AACvF,MAAM,QAAQ,GAAoB,EAAE,CAAC;AACrC,MAAM,UAAU,GAAsB,EAAE,CAAC;AAEzC,YAAY,CACV,UAAU,EACV;IACE,OAAO,CAAC,MAAM;QACZ,IAAI,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,SAAS,CAAC,SAAS;QACjB,IAAI,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IACtF,CAAC;CACF,EACD,QAAQ,CACT,CAAC;AAEF,8EAA8E;AAC9E,MAAM,UAAU,UAAU;IACxB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PrintedPage, PrintOptions } from "../protocol.js";
|
|
2
|
+
/**
|
|
3
|
+
* Page `index` drawn for printing at `options.dpi` (lowered when the page would pass
|
|
4
|
+
* MAX_PRINT_PIXELS; `dpi` says what it was drawn at), as a PNG.
|
|
5
|
+
*/
|
|
6
|
+
export declare function printPage(index: number, options: PrintOptions, signal: AbortSignal): Promise<PrintedPage>;
|
|
7
|
+
/**
|
|
8
|
+
* Every byte of the open file as it was opened: a remote file's from its block cache and its
|
|
9
|
+
* host, unchanged. A local file's bytes stay where the page has them.
|
|
10
|
+
*/
|
|
11
|
+
export declare function fileBytes(signal: AbortSignal): Promise<Uint8Array>;
|
|
12
|
+
/** One caller's answer: its own copy of the bytes, transferred. */
|
|
13
|
+
export declare function replyBytes(bytes: Uint8Array): [Uint8Array, Transferable[]];
|
|
14
|
+
//# sourceMappingURL=print.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.d.ts","sourceRoot":"","sources":["../../src/worker/print.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAOhE;;;GAGG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAmB/G;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAIlE;AAED,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC,UAAU,EAAE,YAAY,EAAE,CAAC,CAG1E"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Printing in the document worker (R09): a page drawn at print resolution with the print
|
|
2
|
+
// intent (annotations as their print flags say), encoded as PNG here, so the page that prints
|
|
3
|
+
// it only ever holds one small file per page, never its pixels. One page per call, so the
|
|
4
|
+
// pixels of the page before are released before the next is drawn.
|
|
5
|
+
import { readAll } from "../source.js";
|
|
6
|
+
import { current, filling } from "./document.js";
|
|
7
|
+
/** The most pixels one printed page holds: about 16 million, a 300 dpi page of 11 × 17 inches. */
|
|
8
|
+
const MAX_PRINT_PIXELS = 16_000_000;
|
|
9
|
+
/**
|
|
10
|
+
* Page `index` drawn for printing at `options.dpi` (lowered when the page would pass
|
|
11
|
+
* MAX_PRINT_PIXELS; `dpi` says what it was drawn at), as a PNG.
|
|
12
|
+
*/
|
|
13
|
+
export async function printPage(index, options, signal) {
|
|
14
|
+
const doc = current();
|
|
15
|
+
const page = doc.render.page(index);
|
|
16
|
+
const wanted = options.dpi / 72;
|
|
17
|
+
const area = page.width * page.height;
|
|
18
|
+
const scale = Math.min(wanted, Math.sqrt(MAX_PRINT_PIXELS / Math.max(1, area)));
|
|
19
|
+
const request = {
|
|
20
|
+
page: index,
|
|
21
|
+
scale,
|
|
22
|
+
flags: { annotations: options.annotations, formWidgets: options.annotations, print: true, grayscale: false },
|
|
23
|
+
};
|
|
24
|
+
const tile = await filling(doc.remote, () => doc.render.render(request, { signal }), signal);
|
|
25
|
+
signal.throwIfAborted();
|
|
26
|
+
const canvas = new OffscreenCanvas(tile.width, tile.height);
|
|
27
|
+
const context = canvas.getContext("2d");
|
|
28
|
+
if (context === null)
|
|
29
|
+
throw new Error("no 2D context for printing");
|
|
30
|
+
context.putImageData(new ImageData(tile.pixels, tile.width, tile.height), 0, 0);
|
|
31
|
+
const image = await canvas.convertToBlob({ type: "image/png" });
|
|
32
|
+
return { image, width: page.width, height: page.height, dpi: Math.round(scale * 72) };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Every byte of the open file as it was opened: a remote file's from its block cache and its
|
|
36
|
+
* host, unchanged. A local file's bytes stay where the page has them.
|
|
37
|
+
*/
|
|
38
|
+
export function fileBytes(signal) {
|
|
39
|
+
const { remote } = current();
|
|
40
|
+
if (remote === undefined)
|
|
41
|
+
return Promise.reject(new Error("the open file isn't remote: read it where it was opened"));
|
|
42
|
+
return remote.whole === undefined ? readAll(remote, signal) : Promise.resolve(remote.whole);
|
|
43
|
+
}
|
|
44
|
+
/** One caller's answer: its own copy of the bytes, transferred. */
|
|
45
|
+
export function replyBytes(bytes) {
|
|
46
|
+
const copy = bytes.slice();
|
|
47
|
+
return [copy, [copy.buffer]];
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=print.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.js","sourceRoot":"","sources":["../../src/worker/print.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,8FAA8F;AAC9F,0FAA0F;AAC1F,mEAAmE;AAInE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAEjD,kGAAkG;AAClG,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAa,EAAE,OAAqB,EAAE,MAAmB;IACvF,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IACtB,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;IACtC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAChF,MAAM,OAAO,GAAkB;QAC7B,IAAI,EAAE,KAAK;QACX,KAAK;QACL,KAAK,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;KAC7G,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG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,CAAC;AAC9F,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** How many pages' text and links stay cached (a screenful of pages and the margin, at most zoom). */
|
|
2
|
+
export declare const CACHED_PAGES = 24;
|
|
3
|
+
/** A cache of the pages read last, of the open document and those before it. */
|
|
4
|
+
export declare class RecentPages<T> {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(budget: number, weigh?: (value: T) => number);
|
|
7
|
+
/** Page `index` of the open document, now the newest; `undefined` when it isn't kept. */
|
|
8
|
+
get(index: number): T | undefined;
|
|
9
|
+
/** Keeps `value` for page `index` of the open document, letting the oldest go over the budget. */
|
|
10
|
+
set(index: number, value: T): void;
|
|
11
|
+
/** Forgets every page: the document closed. */
|
|
12
|
+
clear(): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=recent-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recent-pages.d.ts","sourceRoot":"","sources":["../../src/worker/recent-pages.ts"],"names":[],"mappings":"AAOA,sGAAsG;AACtG,eAAO,MAAM,YAAY,KAAK,CAAC;AAE/B,gFAAgF;AAChF,qBAAa,WAAW,CAAC,CAAC;;IAMxB,YAAY,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAgB,EAGhE;IAED,yFAAyF;IACzF,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAQhC;IAED,kGAAkG;IAClG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAYjC;IAED,+CAA+C;IAC/C,KAAK,IAAI,IAAI,CAGZ;CAKF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// What the document Web Worker keeps of the pages it read last: a page's text, its searchable
|
|
2
|
+
// text, its links. Entries are keyed by document and page, so another document never reads one's
|
|
3
|
+
// pages; reading one makes it the newest, and the oldest go first once the entries weigh more than
|
|
4
|
+
// the budget (a count of pages, unless `weigh` gives each its size).
|
|
5
|
+
import { current } from "./document.js";
|
|
6
|
+
/** How many pages' text and links stay cached (a screenful of pages and the margin, at most zoom). */
|
|
7
|
+
export const CACHED_PAGES = 24;
|
|
8
|
+
/** A cache of the pages read last, of the open document and those before it. */
|
|
9
|
+
export class RecentPages {
|
|
10
|
+
#entries = new Map();
|
|
11
|
+
#budget;
|
|
12
|
+
#weigh;
|
|
13
|
+
#weight = 0;
|
|
14
|
+
constructor(budget, weigh = () => 1) {
|
|
15
|
+
this.#budget = budget;
|
|
16
|
+
this.#weigh = weigh;
|
|
17
|
+
}
|
|
18
|
+
/** Page `index` of the open document, now the newest; `undefined` when it isn't kept. */
|
|
19
|
+
get(index) {
|
|
20
|
+
const key = this.#key(index);
|
|
21
|
+
const value = this.#entries.get(key);
|
|
22
|
+
if (value !== undefined) {
|
|
23
|
+
this.#entries.delete(key);
|
|
24
|
+
this.#entries.set(key, value);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
/** Keeps `value` for page `index` of the open document, letting the oldest go over the budget. */
|
|
29
|
+
set(index, value) {
|
|
30
|
+
const key = this.#key(index);
|
|
31
|
+
const old = this.#entries.get(key);
|
|
32
|
+
if (old !== undefined)
|
|
33
|
+
this.#weight -= this.#weigh(old);
|
|
34
|
+
this.#entries.delete(key);
|
|
35
|
+
this.#entries.set(key, value);
|
|
36
|
+
this.#weight += this.#weigh(value);
|
|
37
|
+
for (const [oldest, kept] of this.#entries) {
|
|
38
|
+
if (this.#weight <= this.#budget)
|
|
39
|
+
break;
|
|
40
|
+
this.#entries.delete(oldest);
|
|
41
|
+
this.#weight -= this.#weigh(kept);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Forgets every page: the document closed. */
|
|
45
|
+
clear() {
|
|
46
|
+
this.#entries.clear();
|
|
47
|
+
this.#weight = 0;
|
|
48
|
+
}
|
|
49
|
+
#key(index) {
|
|
50
|
+
return `${current().id}:${index}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=recent-pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recent-pages.js","sourceRoot":"","sources":["../../src/worker/recent-pages.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,iGAAiG;AACjG,mGAAmG;AACnG,qEAAqE;AAErE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,sGAAsG;AACtG,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAE/B,gFAAgF;AAChF,MAAM,OAAO,WAAW;IACb,QAAQ,GAAG,IAAI,GAAG,EAAa,CAAC;IAChC,OAAO,CAAS;IAChB,MAAM,CAAuB;IACtC,OAAO,GAAG,CAAC,CAAC;IAEZ,YAAY,MAAc,EAAE,KAAK,GAAyB,GAAG,EAAE,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,yFAAyF;IACzF,GAAG,CAAC,KAAa;QACf,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,kGAAkG;IAClG,GAAG,CAAC,KAAa,EAAE,KAAQ;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,GAAG,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnC,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC3C,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;gBAAE,MAAM;YACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC7B,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,+CAA+C;IAC/C,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,KAAa;QAChB,OAAO,GAAG,OAAO,EAAE,CAAC,EAAE,IAAI,KAAK,EAAE,CAAC;IACpC,CAAC;CACF"}
|
package/dist/worker/render.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { RenderedTile, RenderRequest } from "@laminapdf/render";
|
|
2
2
|
import { type RenderedBitmap } from "../protocol.js";
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Renders `request` on document `id` (a render queued for a document since replaced is
|
|
5
|
+
* `disposed`). A remote document's render fetches the bytes it meets missing and draws again.
|
|
6
|
+
*/
|
|
7
|
+
export declare function render(request: RenderRequest, id: number, signal: AbortSignal): Promise<RenderedTile>;
|
|
5
8
|
/** One caller's bitmap of `tile`. */
|
|
6
9
|
export declare function reply(tile: RenderedTile): Promise<[RenderedBitmap, Transferable[]]>;
|
|
7
10
|
//# sourceMappingURL=render.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/worker/render.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,KAAK,cAAc,EAAa,MAAM,gBAAgB,CAAC;AAGhE
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/worker/render.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,KAAK,cAAc,EAAa,MAAM,gBAAgB,CAAC;AAGhE;;;GAGG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAarG;AAED,qCAAqC;AACrC,wBAAsB,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,cAAc,EAAE,YAAY,EAAE,CAAC,CAAC,CAKzF"}
|
package/dist/worker/render.js
CHANGED
|
@@ -3,14 +3,24 @@
|
|
|
3
3
|
// coalesced render is drawn once; each caller gets its own bitmap of the same pixels.
|
|
4
4
|
import { emit } from "@laminapdf/sdk/worker/server";
|
|
5
5
|
import { renderKey } from "../protocol.js";
|
|
6
|
-
import { current } from "./document.js";
|
|
7
|
-
/**
|
|
6
|
+
import { current, filling, warmExtract } from "./document.js";
|
|
7
|
+
/**
|
|
8
|
+
* Renders `request` on document `id` (a render queued for a document since replaced is
|
|
9
|
+
* `disposed`). A remote document's render fetches the bytes it meets missing and draws again.
|
|
10
|
+
*/
|
|
8
11
|
export function render(request, id, signal) {
|
|
9
12
|
const doc = current(id);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const key = renderKey(request, id);
|
|
14
|
+
const draw = () => {
|
|
15
|
+
// The client starts its timers now (not while the render waits or fetches), and a
|
|
16
|
+
// performance test can see what the worker is busy with.
|
|
17
|
+
emit("render-start", { page: request.page, scale: request.scale, key });
|
|
18
|
+
return doc.render.render(request, { signal });
|
|
19
|
+
};
|
|
20
|
+
const tile = filling(doc.remote, draw, signal, () => emit("render-fetching", { key }));
|
|
21
|
+
// A page is on screen: the text layer's module may load now without delaying it.
|
|
22
|
+
void tile.then(warmExtract, () => undefined);
|
|
23
|
+
return tile;
|
|
14
24
|
}
|
|
15
25
|
/** One caller's bitmap of `tile`. */
|
|
16
26
|
export async function reply(tile) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/worker/render.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,yFAAyF;AACzF,sFAAsF;AAGtF,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAuB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/worker/render.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,yFAAyF;AACzF,sFAAsF;AAGtF,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAuB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACh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AC/C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Reflow } from "@laminapdf/sdk";
|
|
2
|
+
import type { PageGlyphs } from "../find/page.js";
|
|
3
|
+
import type { PageTextData, ReadingBlock, StructureData } from "../protocol.js";
|
|
4
|
+
/** Page `index`'s text runs and glyph quads (cached; `signal` stops a read of pending data). */
|
|
5
|
+
export declare function pageText(index: number, signal: AbortSignal): Promise<PageTextData>;
|
|
6
|
+
/**
|
|
7
|
+
* Page `index`'s runs, quads and glyph text, from the cache or read now. `keep: false` (find)
|
|
8
|
+
* reads a page without caching it, so a search through every page never pushes out the text of
|
|
9
|
+
* the pages in view.
|
|
10
|
+
*/
|
|
11
|
+
export declare function pageGlyphs(index: number, signal: AbortSignal, keep?: boolean): Promise<PageGlyphs>;
|
|
12
|
+
/** One caller's answer: its own copy of the quads, transferred. */
|
|
13
|
+
export declare function replyText(data: PageTextData): [PageTextData, Transferable[]];
|
|
14
|
+
/** Whether the document says it is tagged, and its structure tree when it has one. */
|
|
15
|
+
export declare function structure(signal: AbortSignal): Promise<StructureData>;
|
|
16
|
+
/** The open document for reader mode (`doc.reflow()`): blocks in the structure tree's order, or why not. */
|
|
17
|
+
export declare function reflow(signal: AbortSignal): Promise<Reflow>;
|
|
18
|
+
/**
|
|
19
|
+
* Page `index`'s blocks in reading order (cached). Running headers and footers stay in, as
|
|
20
|
+
* blocks of their own: a selection that takes them in copies them.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readingOrder(index: number, signal: AbortSignal): Promise<ReadingBlock[]>;
|
|
23
|
+
/** Forgets every page's text: the document closed. */
|
|
24
|
+
export declare function forgetText(): void;
|
|
25
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/worker/text.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAe,MAAM,gBAAgB,CAAC;AAO7F,gGAAgG;AAChG,wBAAsB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAGxF;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,UAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBrG;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,CAAC,CAG5E;AAED,sFAAsF;AACtF,wBAAsB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAK3E;AAED,4GAA4G;AAC5G,wBAAsB,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAGjE;AAKD;;;GAGG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAW9F;AAED,sDAAsD;AACtD,wBAAgB,UAAU,IAAI,IAAI,CAGjC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// A page's text for the text layer, read by Lamina PDF in the worker (ADR 0004's two-parsers rule:
|
|
2
|
+
// text geometry comes from Lamina PDF, never from the renderer). Runs cross as small records and
|
|
3
|
+
// every glyph's quad in one Float32Array, which each caller gets its own copy of to transfer, so a
|
|
4
|
+
// page of thousands of glyphs is three objects, not thousands. The last pages read are kept, since
|
|
5
|
+
// a page scrolled back into view asks again.
|
|
6
|
+
import { textModel } from "./document.js";
|
|
7
|
+
import { CACHED_PAGES, RecentPages } from "./recent-pages.js";
|
|
8
|
+
/** The last pages' text. Each keeps its glyphs' text too, for find; only the runs and quads reach the page. */
|
|
9
|
+
const cache = new RecentPages(CACHED_PAGES);
|
|
10
|
+
/** Page `index`'s text runs and glyph quads (cached; `signal` stops a read of pending data). */
|
|
11
|
+
export async function pageText(index, signal) {
|
|
12
|
+
const { runs, quads } = await pageGlyphs(index, signal);
|
|
13
|
+
return { runs, quads };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Page `index`'s runs, quads and glyph text, from the cache or read now. `keep: false` (find)
|
|
17
|
+
* reads a page without caching it, so a search through every page never pushes out the text of
|
|
18
|
+
* the pages in view.
|
|
19
|
+
*/
|
|
20
|
+
export async function pageGlyphs(index, signal, keep = true) {
|
|
21
|
+
const cached = cache.get(index);
|
|
22
|
+
if (cached !== undefined)
|
|
23
|
+
return cached;
|
|
24
|
+
signal.throwIfAborted();
|
|
25
|
+
const model = await textModel(signal);
|
|
26
|
+
const text = await model.ensure(() => model.page(index).text(), { signal });
|
|
27
|
+
const runs = text.runs.map((run) => ({
|
|
28
|
+
text: run.text,
|
|
29
|
+
size: run.size,
|
|
30
|
+
vertical: run.vertical,
|
|
31
|
+
actualText: run.actualText,
|
|
32
|
+
invisible: run.invisible,
|
|
33
|
+
glyphRange: run.glyphRange,
|
|
34
|
+
...(run.mcid === undefined ? {} : { mcid: run.mcid }),
|
|
35
|
+
}));
|
|
36
|
+
// The arrays are this worker's own (the SDK copied them out of WebAssembly memory).
|
|
37
|
+
const { quads, glyphText, glyphOffsets } = text.buffers;
|
|
38
|
+
const data = { runs, quads, glyphText, glyphOffsets };
|
|
39
|
+
if (!keep)
|
|
40
|
+
return data;
|
|
41
|
+
cache.set(index, data);
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
/** One caller's answer: its own copy of the quads, transferred. */
|
|
45
|
+
export function replyText(data) {
|
|
46
|
+
const copy = { ...data, quads: data.quads.slice() };
|
|
47
|
+
return [copy, [copy.quads.buffer]];
|
|
48
|
+
}
|
|
49
|
+
/** Whether the document says it is tagged, and its structure tree when it has one. */
|
|
50
|
+
export async function structure(signal) {
|
|
51
|
+
const model = await textModel(signal);
|
|
52
|
+
const tagged = await model.ensure(() => model.isTagged, { signal });
|
|
53
|
+
const tree = await model.ensure(() => model.structureTree(), { signal });
|
|
54
|
+
return tree === undefined ? { tagged } : { tagged, tree };
|
|
55
|
+
}
|
|
56
|
+
/** The open document for reader mode (`doc.reflow()`): blocks in the structure tree's order, or why not. */
|
|
57
|
+
export async function reflow(signal) {
|
|
58
|
+
const model = await textModel(signal);
|
|
59
|
+
return model.ensure(() => model.reflow(), { signal });
|
|
60
|
+
}
|
|
61
|
+
/** The reading-order blocks of the last pages a selection reached. */
|
|
62
|
+
const blocks = new RecentPages(CACHED_PAGES);
|
|
63
|
+
/**
|
|
64
|
+
* Page `index`'s blocks in reading order (cached). Running headers and footers stay in, as
|
|
65
|
+
* blocks of their own: a selection that takes them in copies them.
|
|
66
|
+
*/
|
|
67
|
+
export async function readingOrder(index, signal) {
|
|
68
|
+
const cached = blocks.get(index);
|
|
69
|
+
if (cached !== undefined)
|
|
70
|
+
return cached;
|
|
71
|
+
const model = await textModel(signal);
|
|
72
|
+
const extraction = await model.ensure(() => model.extract({ format: "json", pages: [index], drop: { furniture: false } }), { signal });
|
|
73
|
+
const found = extraction.blocks.map((b) => ({ bbox: b.bbox, type: b.type }));
|
|
74
|
+
blocks.set(index, found);
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
77
|
+
/** Forgets every page's text: the document closed. */
|
|
78
|
+
export function forgetText() {
|
|
79
|
+
cache.clear();
|
|
80
|
+
blocks.clear();
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/worker/text.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,iGAAiG;AACjG,mGAAmG;AACnG,mGAAmG;AACnG,6CAA6C;AAK7C,OAAO,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