@laminapdf/viewer 0.2.0-alpha.3 → 0.2.0-alpha.4
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 +71 -5
- package/dist/client.d.ts +48 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +89 -29
- 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/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -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/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/spans.d.ts +42 -0
- package/dist/layers/spans.d.ts.map +1 -0
- package/dist/layers/spans.js +121 -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 +152 -0
- package/dist/layers/structure-layer.js.map +1 -0
- package/dist/layers/text-layer.d.ts +53 -0
- package/dist/layers/text-layer.d.ts.map +1 -0
- package/dist/layers/text-layer.js +292 -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 +115 -2
- package/dist/protocol.d.ts.map +1 -1
- 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/thumbnails/strip.d.ts +37 -0
- package/dist/thumbnails/strip.d.ts.map +1 -0
- package/dist/thumbnails/strip.js +313 -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/viewer.d.ts +42 -1
- package/dist/view/viewer.d.ts.map +1 -1
- package/dist/view/viewer.js +425 -68
- package/dist/view/viewer.js.map +1 -1
- package/dist/worker/document.d.ts +30 -0
- package/dist/worker/document.d.ts.map +1 -1
- package/dist/worker/document.js +176 -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 +59 -0
- package/dist/worker/find.js.map +1 -0
- package/dist/worker/methods.d.ts.map +1 -1
- package/dist/worker/methods.js +28 -2
- package/dist/worker/methods.js.map +1 -1
- package/dist/worker/navigation.d.ts +6 -0
- package/dist/worker/navigation.d.ts.map +1 -0
- package/dist/worker/navigation.js +16 -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/render.d.ts +5 -2
- package/dist/worker/render.d.ts.map +1 -1
- package/dist/worker/render.js +13 -6
- package/dist/worker/render.js.map +1 -1
- package/dist/worker/text.d.ts +17 -0
- package/dist/worker/text.d.ts.map +1 -0
- package/dist/worker/text.js +75 -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 +5 -5
package/dist/protocol.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type CloneableWasmSource, type RenderLimits, type RenderRequest } from "@laminapdf/render";
|
|
2
|
-
import type { Limits, PageInfo } from "@laminapdf/sdk";
|
|
2
|
+
import type { Limits, OutlineNode, PageInfo, StructureNode, Target } from "@laminapdf/sdk";
|
|
3
|
+
import type { FindOptions } from "./find/fold.js";
|
|
4
|
+
import type { FindSnippet } from "./find/page.js";
|
|
3
5
|
/** Which engine draws the pages (ADR 0004: PDFium by default, hayro the CI oracle). */
|
|
4
6
|
export type BackendName = "pdfium" | "hayro";
|
|
5
7
|
/** What the worker loads a backend from. */
|
|
@@ -8,8 +10,15 @@ export interface BackendInit {
|
|
|
8
10
|
/** The engine's `.wasm`: required for PDFium (its URL from your bundler); hayro finds its own. */
|
|
9
11
|
readonly wasm?: CloneableWasmSource;
|
|
10
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* A remote file the worker fetches itself, with HTTP Range requests (`HttpRangeByteSource`): its
|
|
15
|
+
* bytes never pass through the page.
|
|
16
|
+
*/
|
|
17
|
+
export interface RemoteSource {
|
|
18
|
+
readonly url: string;
|
|
19
|
+
}
|
|
11
20
|
/** What a document is opened from: sent to the worker, which reads it there. */
|
|
12
|
-
export type SourceInit = Blob | ArrayBuffer | Uint8Array;
|
|
21
|
+
export type SourceInit = Blob | ArrayBuffer | Uint8Array | RemoteSource;
|
|
13
22
|
/** `open`'s options. The password crosses to the worker once and is kept only there. */
|
|
14
23
|
export interface ViewerOpenOptions {
|
|
15
24
|
readonly password?: string;
|
|
@@ -31,6 +40,8 @@ export interface OpenedDocument {
|
|
|
31
40
|
readonly name: BackendName;
|
|
32
41
|
readonly version: string;
|
|
33
42
|
};
|
|
43
|
+
/** The title in the file's metadata, for the window's title; absent when the file has none. */
|
|
44
|
+
readonly title?: string;
|
|
34
45
|
}
|
|
35
46
|
/** A rendered tile on the page: an ImageBitmap transferred from the worker. Close it when done. */
|
|
36
47
|
export interface RenderedBitmap {
|
|
@@ -75,6 +86,108 @@ export interface Methods {
|
|
|
75
86
|
params: [];
|
|
76
87
|
result: WorkerMemory;
|
|
77
88
|
};
|
|
89
|
+
pageText: {
|
|
90
|
+
params: [index: number];
|
|
91
|
+
result: PageTextData;
|
|
92
|
+
};
|
|
93
|
+
structure: {
|
|
94
|
+
params: [];
|
|
95
|
+
result: StructureData;
|
|
96
|
+
};
|
|
97
|
+
networkLog: {
|
|
98
|
+
params: [];
|
|
99
|
+
result: WorkerNetworkLog;
|
|
100
|
+
};
|
|
101
|
+
outline: {
|
|
102
|
+
params: [];
|
|
103
|
+
result: OutlineNode[];
|
|
104
|
+
};
|
|
105
|
+
namedDestination: {
|
|
106
|
+
params: [name: string];
|
|
107
|
+
result: Target | undefined;
|
|
108
|
+
};
|
|
109
|
+
find: {
|
|
110
|
+
params: [query: string, options: FindOptions, pages: readonly number[]];
|
|
111
|
+
result: FindPageResult[];
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** One page's find results: each match as its quads (8 numbers per run it touches), in page space. */
|
|
115
|
+
export interface FindPageResult {
|
|
116
|
+
readonly page: number;
|
|
117
|
+
readonly matches: readonly (readonly number[])[];
|
|
118
|
+
/** Each match in its line, in the same order. */
|
|
119
|
+
readonly snippets: readonly FindSnippet[];
|
|
120
|
+
/** The page has no text to search (a scan without an OCR layer). */
|
|
121
|
+
readonly noText?: true;
|
|
122
|
+
}
|
|
123
|
+
/** One text run of a page: glyphs of one font, size and direction on one baseline, in logical order. */
|
|
124
|
+
export interface TextRunData {
|
|
125
|
+
/** Its text in logical order (document text; an `/ActualText` replacement when `actualText`). */
|
|
126
|
+
readonly text: string;
|
|
127
|
+
/** Font size in points, the text matrix applied. */
|
|
128
|
+
readonly size: number;
|
|
129
|
+
/** Vertical writing. */
|
|
130
|
+
readonly vertical: boolean;
|
|
131
|
+
/** The text replaces its glyphs (`/ActualText`). */
|
|
132
|
+
readonly actualText: boolean;
|
|
133
|
+
/** Drawn invisibly (`Tr` 3 or 7: an OCR layer, hidden text); selectable all the same. */
|
|
134
|
+
readonly invisible: boolean;
|
|
135
|
+
/** Its glyphs: `[start, end)` into `quads` (8 numbers each), as the SDK's `PageTextRun.glyphRange`. */
|
|
136
|
+
readonly glyphRange: readonly [number, number];
|
|
137
|
+
/** The marked-content ID it is in, which links it to the structure tree. */
|
|
138
|
+
readonly mcid?: number;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A page's text: its runs, and every glyph's quad as 8 numbers (bottom-left, bottom-right,
|
|
142
|
+
* top-right, top-left, each `x, y`) in page space (ADR 0027: points from the displayed page's
|
|
143
|
+
* top-left, y down).
|
|
144
|
+
*/
|
|
145
|
+
export interface PageTextData {
|
|
146
|
+
readonly runs: readonly TextRunData[];
|
|
147
|
+
readonly quads: Float32Array;
|
|
148
|
+
}
|
|
149
|
+
/** Whether the document says it is tagged, and its structure tree when it has one. */
|
|
150
|
+
export interface StructureData {
|
|
151
|
+
readonly tagged: boolean;
|
|
152
|
+
readonly tree?: readonly StructureNode[];
|
|
153
|
+
}
|
|
154
|
+
/** Which JavaScript context made a request: the page, or the document worker. */
|
|
155
|
+
export type NetworkSource = "page" | "worker";
|
|
156
|
+
/** One network request a context made, as `watchNetwork` reports it. */
|
|
157
|
+
export interface NetworkRecord {
|
|
158
|
+
readonly url: string;
|
|
159
|
+
readonly method: string;
|
|
160
|
+
/**
|
|
161
|
+
* What made it: `fetch`, `xmlhttprequest`, `websocket` and `beacon` for wrapped calls, else the
|
|
162
|
+
* Resource Timing `initiatorType` (`script`, `link`, `css`, `img`, `navigation` …).
|
|
163
|
+
*/
|
|
164
|
+
readonly initiator: string;
|
|
165
|
+
/** Bytes received, when known (0 otherwise). */
|
|
166
|
+
readonly bytes: number;
|
|
167
|
+
/** The call failed or was refused (a CORS refusal, a network error, a beacon not queued). */
|
|
168
|
+
readonly failed: boolean;
|
|
169
|
+
readonly source: NetworkSource;
|
|
170
|
+
/** `Date.now()` when it was reported. */
|
|
171
|
+
readonly at: number;
|
|
172
|
+
}
|
|
173
|
+
/** A request the Content Security Policy blocked: nothing was sent. */
|
|
174
|
+
export interface PolicyViolation {
|
|
175
|
+
readonly directive: string;
|
|
176
|
+
readonly blockedUri: string;
|
|
177
|
+
readonly source: NetworkSource;
|
|
178
|
+
readonly at: number;
|
|
179
|
+
}
|
|
180
|
+
/** The document worker's network log: every request and blocked request since it started. */
|
|
181
|
+
export interface WorkerNetworkLog {
|
|
182
|
+
/** Different for each worker the client starts, so a restarted worker's records stay apart. */
|
|
183
|
+
readonly worker: string;
|
|
184
|
+
readonly requests: readonly NetworkRecord[];
|
|
185
|
+
readonly violations: readonly PolicyViolation[];
|
|
186
|
+
}
|
|
187
|
+
/** How much of a remote file the worker has read: the `progress` event. */
|
|
188
|
+
export interface LoadProgress {
|
|
189
|
+
readonly loaded: number;
|
|
190
|
+
readonly total: number;
|
|
78
191
|
}
|
|
79
192
|
/** A viewer method's name. */
|
|
80
193
|
export type MethodName = keyof Methods;
|
package/dist/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/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CAKpE,CAAC;AAEH,yFAAyF;AACzF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAG5D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAWpE"}
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,wFAAwF;AACxF,iGAAiG;AACjG,8FAA8F;AAC9F,kBAAkB;AAElB,OAAO,EAA4B,OAAO,EAAyC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,wFAAwF;AACxF,iGAAiG;AACjG,8FAA8F;AAC9F,kBAAkB;AAElB,OAAO,EAA4B,OAAO,EAAyC,MAAM,mBAAmB,CAAC;AAqL7G,mEAAmE;AACnE,MAAM,CAAC,MAAM,QAAQ,GAAsD,MAAM,CAAC,MAAM,CAAC;IACvF,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,UAAU,EAAE,CAAC;CACd,CAAC,CAAC;AAQH,kEAAkE;AAClE,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAc,CAAC;IAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAW,EAAE,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,OAAsB,EAAE,EAAU;IAC1D,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACvE,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,EAAE;QACF,IAAI;QACJ,KAAK;QACL,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;QACrE,QAAQ;QACR,OAAO,CAAC,KAAK,CAAC;QACd,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU;KAChD,CAAC,CAAC;AACL,CAAC"}
|
package/dist/render/tiles.d.ts
CHANGED
|
@@ -1,17 +1,57 @@
|
|
|
1
1
|
import type { PixelRect } from "@laminapdf/render";
|
|
2
|
+
/**
|
|
3
|
+
* The most device pixels a page's backdrop canvas holds: well below Safari's 16.7 MP per canvas,
|
|
4
|
+
* and small enough that the mounted pages share the pool. A page larger than this at the full
|
|
5
|
+
* pixel ratio keeps its backdrop at a lower one and gets a detail canvas over the part in view.
|
|
6
|
+
*/
|
|
7
|
+
export declare const BACKDROP_MAX_PIXELS: number;
|
|
8
|
+
/**
|
|
9
|
+
* Device px per CSS px of the backdrop of a page `css` CSS px in size: `dpr`, or less so that the
|
|
10
|
+
* whole page fits `maxPixels` ({@link BACKDROP_MAX_PIXELS} by default; less on touch devices).
|
|
11
|
+
*/
|
|
12
|
+
export declare function backdropRatio(dpr: number, css: {
|
|
13
|
+
readonly width: number;
|
|
14
|
+
readonly height: number;
|
|
15
|
+
}, maxPixels?: number): number;
|
|
16
|
+
/** The smallest rectangle covering every one of `rects`; undefined when there are none. */
|
|
17
|
+
export declare function bounds(rects: readonly PixelRect[]): PixelRect | undefined;
|
|
18
|
+
/** Whether `outer` contains all of `inner`. */
|
|
19
|
+
export declare function contains(outer: PixelRect, inner: PixelRect): boolean;
|
|
2
20
|
/** The render scale (output px per pt) of the low-resolution pass for a page `widthPt` wide. */
|
|
3
21
|
export declare function lowScale(sharpScale: number, widthPt: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* The sharp scale (device px per pt) of a page `css` CSS px in size at layout scale `layoutScale`:
|
|
24
|
+
* `layoutScale × dpr`, unless the canvas pool could only `fit` fewer pixels than `wanted`, the page
|
|
25
|
+
* in whole pixels at that scale (`pagePixels`); then lowered to what fits. The canvas is then
|
|
26
|
+
* `pagePixels` at this scale, which never exceeds `fitted` on either side.
|
|
27
|
+
*
|
|
28
|
+
* `wanted` is in whole pixels, as the pool fits them: comparing `fitted` with the fractional CSS
|
|
29
|
+
* size instead takes the pool's rounding (79.33 px to 79) for a cap, which lowers the scale a
|
|
30
|
+
* hair below the full one and sends every page asking for a detail canvas it doesn't need.
|
|
31
|
+
*/
|
|
32
|
+
export declare function sharpScale(layoutScale: number, dpr: number, css: {
|
|
33
|
+
readonly width: number;
|
|
34
|
+
readonly height: number;
|
|
35
|
+
}, fitted: {
|
|
36
|
+
readonly width: number;
|
|
37
|
+
readonly height: number;
|
|
38
|
+
}, wanted: {
|
|
39
|
+
readonly width: number;
|
|
40
|
+
readonly height: number;
|
|
41
|
+
}): number;
|
|
4
42
|
/**
|
|
5
43
|
* The tiles (device px, in the page's pixel space at the sharp scale) covering `visible`, the
|
|
6
|
-
* part of the page in view in CSS px (x, y from the page's top-left), clamped to the
|
|
44
|
+
* part of the page in view in CSS px (x, y from the page's top-left), clamped to `page`: the
|
|
45
|
+
* whole page in device px, as the renderer sizes it (`pagePixels` of `@laminapdf/render`), so no
|
|
46
|
+
* tile reaches past it. `ratio` is device px per CSS px.
|
|
7
47
|
*/
|
|
8
48
|
export declare function tilesFor(visible: {
|
|
9
49
|
readonly x: number;
|
|
10
50
|
readonly y: number;
|
|
11
51
|
readonly width: number;
|
|
12
52
|
readonly height: number;
|
|
13
|
-
},
|
|
53
|
+
}, page: {
|
|
14
54
|
readonly width: number;
|
|
15
55
|
readonly height: number;
|
|
16
|
-
},
|
|
56
|
+
}, ratio: number): PixelRect[];
|
|
17
57
|
//# sourceMappingURL=tiles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiles.d.ts","sourceRoot":"","sources":["../../src/render/tiles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAOnD,gGAAgG;AAChG,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED
|
|
1
|
+
{"version":3,"file":"tiles.d.ts","sourceRoot":"","sources":["../../src/render/tiles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAOnD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAkB,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACxD,SAAS,SAAsB,GAC9B,MAAM,CAGR;AAED,2FAA2F;AAC3F,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,GAAG,SAAS,CAWzE;AAED,+CAA+C;AAC/C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAOpE;AAED,gGAAgG;AAChG,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACxD,MAAM,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC3D,MAAM,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1D,MAAM,CAGR;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACpG,IAAI,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACzD,KAAK,EAAE,MAAM,GACZ,SAAS,EAAE,CAcb"}
|
package/dist/render/tiles.js
CHANGED
|
@@ -2,26 +2,78 @@
|
|
|
2
2
|
const TILE_CSS = 512;
|
|
3
3
|
/** The low-resolution pass: at most this many device px wide, and at most half the sharp scale. */
|
|
4
4
|
const LOW_MAX_WIDTH = 256;
|
|
5
|
+
/**
|
|
6
|
+
* The most device pixels a page's backdrop canvas holds: well below Safari's 16.7 MP per canvas,
|
|
7
|
+
* and small enough that the mounted pages share the pool. A page larger than this at the full
|
|
8
|
+
* pixel ratio keeps its backdrop at a lower one and gets a detail canvas over the part in view.
|
|
9
|
+
*/
|
|
10
|
+
export const BACKDROP_MAX_PIXELS = 8 * 1024 * 1024;
|
|
11
|
+
/**
|
|
12
|
+
* Device px per CSS px of the backdrop of a page `css` CSS px in size: `dpr`, or less so that the
|
|
13
|
+
* whole page fits `maxPixels` ({@link BACKDROP_MAX_PIXELS} by default; less on touch devices).
|
|
14
|
+
*/
|
|
15
|
+
export function backdropRatio(dpr, css, maxPixels = BACKDROP_MAX_PIXELS) {
|
|
16
|
+
const pixels = css.width * dpr * css.height * dpr;
|
|
17
|
+
return pixels <= maxPixels ? dpr : dpr * Math.sqrt(maxPixels / pixels);
|
|
18
|
+
}
|
|
19
|
+
/** The smallest rectangle covering every one of `rects`; undefined when there are none. */
|
|
20
|
+
export function bounds(rects) {
|
|
21
|
+
const [first] = rects;
|
|
22
|
+
if (first === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
let [x0, y0, x1, y1] = [first.x, first.y, first.x + first.width, first.y + first.height];
|
|
25
|
+
for (const r of rects) {
|
|
26
|
+
x0 = Math.min(x0, r.x);
|
|
27
|
+
y0 = Math.min(y0, r.y);
|
|
28
|
+
x1 = Math.max(x1, r.x + r.width);
|
|
29
|
+
y1 = Math.max(y1, r.y + r.height);
|
|
30
|
+
}
|
|
31
|
+
return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
|
|
32
|
+
}
|
|
33
|
+
/** Whether `outer` contains all of `inner`. */
|
|
34
|
+
export function contains(outer, inner) {
|
|
35
|
+
return (inner.x >= outer.x &&
|
|
36
|
+
inner.y >= outer.y &&
|
|
37
|
+
inner.x + inner.width <= outer.x + outer.width &&
|
|
38
|
+
inner.y + inner.height <= outer.y + outer.height);
|
|
39
|
+
}
|
|
5
40
|
/** The render scale (output px per pt) of the low-resolution pass for a page `widthPt` wide. */
|
|
6
41
|
export function lowScale(sharpScale, widthPt) {
|
|
7
42
|
return Math.min(sharpScale * 0.5, LOW_MAX_WIDTH / Math.max(1, widthPt));
|
|
8
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* The sharp scale (device px per pt) of a page `css` CSS px in size at layout scale `layoutScale`:
|
|
46
|
+
* `layoutScale × dpr`, unless the canvas pool could only `fit` fewer pixels than `wanted`, the page
|
|
47
|
+
* in whole pixels at that scale (`pagePixels`); then lowered to what fits. The canvas is then
|
|
48
|
+
* `pagePixels` at this scale, which never exceeds `fitted` on either side.
|
|
49
|
+
*
|
|
50
|
+
* `wanted` is in whole pixels, as the pool fits them: comparing `fitted` with the fractional CSS
|
|
51
|
+
* size instead takes the pool's rounding (79.33 px to 79) for a cap, which lowers the scale a
|
|
52
|
+
* hair below the full one and sends every page asking for a detail canvas it doesn't need.
|
|
53
|
+
*/
|
|
54
|
+
export function sharpScale(layoutScale, dpr, css, fitted, wanted) {
|
|
55
|
+
if (fitted.width >= wanted.width && fitted.height >= wanted.height)
|
|
56
|
+
return layoutScale * dpr;
|
|
57
|
+
return layoutScale * Math.min(dpr, fitted.width / css.width, fitted.height / css.height);
|
|
58
|
+
}
|
|
9
59
|
/**
|
|
10
60
|
* The tiles (device px, in the page's pixel space at the sharp scale) covering `visible`, the
|
|
11
|
-
* part of the page in view in CSS px (x, y from the page's top-left), clamped to the
|
|
61
|
+
* part of the page in view in CSS px (x, y from the page's top-left), clamped to `page`: the
|
|
62
|
+
* whole page in device px, as the renderer sizes it (`pagePixels` of `@laminapdf/render`), so no
|
|
63
|
+
* tile reaches past it. `ratio` is device px per CSS px.
|
|
12
64
|
*/
|
|
13
|
-
export function tilesFor(visible,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const side = Math.max(1, Math.round(TILE_CSS *
|
|
17
|
-
const x0 = Math.max(0, Math.floor((visible.x *
|
|
18
|
-
const y0 = Math.max(0, Math.floor((visible.y *
|
|
19
|
-
const x1 = Math.min(
|
|
20
|
-
const y1 = Math.min(
|
|
65
|
+
export function tilesFor(visible, page, ratio) {
|
|
66
|
+
if (visible.width <= 0 || visible.height <= 0)
|
|
67
|
+
return [];
|
|
68
|
+
const side = Math.max(1, Math.round(TILE_CSS * ratio));
|
|
69
|
+
const x0 = Math.max(0, Math.floor((visible.x * ratio) / side) * side);
|
|
70
|
+
const y0 = Math.max(0, Math.floor((visible.y * ratio) / side) * side);
|
|
71
|
+
const x1 = Math.min(page.width, Math.ceil(((visible.x + visible.width) * ratio) / side) * side);
|
|
72
|
+
const y1 = Math.min(page.height, Math.ceil(((visible.y + visible.height) * ratio) / side) * side);
|
|
21
73
|
const tiles = [];
|
|
22
74
|
for (let y = y0; y < y1; y += side) {
|
|
23
75
|
for (let x = x0; x < x1; x += side) {
|
|
24
|
-
tiles.push({ x, y, width: Math.min(side,
|
|
76
|
+
tiles.push({ x, y, width: Math.min(side, page.width - x), height: Math.min(side, page.height - y) });
|
|
25
77
|
}
|
|
26
78
|
}
|
|
27
79
|
return tiles;
|
package/dist/render/tiles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiles.js","sourceRoot":"","sources":["../../src/render/tiles.ts"],"names":[],"mappings":"AAKA,+EAA+E;AAC/E,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,mGAAmG;AACnG,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,
|
|
1
|
+
{"version":3,"file":"tiles.js","sourceRoot":"","sources":["../../src/render/tiles.ts"],"names":[],"mappings":"AAKA,+EAA+E;AAC/E,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,mGAAmG;AACnG,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,GAAW,EACX,GAAwD,EACxD,SAAS,GAAG,mBAAmB;IAE/B,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;IAClD,OAAO,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC;AACzE,CAAC;AAED,2FA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
+
import { type RangeSource } from "@laminapdf/sdk";
|
|
3
|
+
/** Options for {@link HttpRangeByteSource.open}. */
|
|
4
|
+
export interface HttpRangeByteSourceOptions {
|
|
5
|
+
/** Requests are aligned to blocks of this many bytes (default 65 536). */
|
|
6
|
+
readonly blockSize?: number;
|
|
7
|
+
/** Whole blocks fetched after each range asked for (default 1). */
|
|
8
|
+
readonly readahead?: number;
|
|
9
|
+
/** The most bytes the cache keeps; the least recently used blocks go first (default 64 MiB). */
|
|
10
|
+
readonly cacheBytes?: number;
|
|
11
|
+
/**
|
|
12
|
+
* The largest file downloaded whole when the server ignores `Range` (default 256 MiB); above
|
|
13
|
+
* it the open fails with `source-budget-exceeded`.
|
|
14
|
+
*/
|
|
15
|
+
readonly maxWholeBytes?: number;
|
|
16
|
+
/** Skip the browser's HTTP cache (default true). */
|
|
17
|
+
readonly noStore?: boolean;
|
|
18
|
+
/** Called after each fetch with the bytes received so far and the file's size. */
|
|
19
|
+
readonly onProgress?: (progress: {
|
|
20
|
+
readonly loaded: number;
|
|
21
|
+
readonly total: number;
|
|
22
|
+
}) => void;
|
|
23
|
+
/** Aborts the probe. */
|
|
24
|
+
readonly signal?: AbortSignal;
|
|
25
|
+
/** The `fetch` to use (default: the global one). */
|
|
26
|
+
readonly fetch?: typeof fetch;
|
|
27
|
+
}
|
|
28
|
+
/** A remote file as a `RangeSource` (for Lamina PDF) and a `RenderSource` (for the render backend). */
|
|
29
|
+
export declare class HttpRangeByteSource implements RangeSource, RenderSource {
|
|
30
|
+
#private;
|
|
31
|
+
readonly size: number;
|
|
32
|
+
readonly blockSize: number;
|
|
33
|
+
private constructor();
|
|
34
|
+
/**
|
|
35
|
+
* Probes `url` (its last 64 KiB: the size, and the part a reader reads first) and returns the
|
|
36
|
+
* source. A server that ignores `Range` sends the whole file, which is kept.
|
|
37
|
+
*
|
|
38
|
+
* @throws LaminaPdfError `fetch-failed` (`data.reason` `network` covers a refused CORS check,
|
|
39
|
+
* which the browser doesn't tell apart from being offline), `source-changed`,
|
|
40
|
+
* `source-budget-exceeded`, or the signal's reason.
|
|
41
|
+
*/
|
|
42
|
+
static open(url: string, options?: HttpRangeByteSourceOptions): Promise<HttpRangeByteSource>;
|
|
43
|
+
/** The whole file, when the server sent it whole (then every read is answered from it). */
|
|
44
|
+
get whole(): Uint8Array | undefined;
|
|
45
|
+
/** Bytes received from the network so far (the probe's included), re-fetches of evicted blocks too. */
|
|
46
|
+
get loaded(): number;
|
|
47
|
+
/** The `length` bytes at `offset` if every block is cached, else undefined (`RenderSource`). */
|
|
48
|
+
readSync(offset: number, length: number): Uint8Array | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Fetches the blocks `ranges` touch (and the readahead after each) that aren't cached: the
|
|
51
|
+
* ranges of a render backend's `data-pending`.
|
|
52
|
+
*/
|
|
53
|
+
fill(ranges: readonly ByteRange[], signal?: AbortSignal): Promise<void>;
|
|
54
|
+
/** `RangeSource.read`: fills, then reads from the cache. */
|
|
55
|
+
read(offset: number, length: number, options?: {
|
|
56
|
+
readonly signal?: AbortSignal;
|
|
57
|
+
}): Promise<Uint8Array>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=http-range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-range.d.ts","sourceRoot":"","sources":["../../src/source/http-range.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAqD,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIrG,oDAAoD;AACpD,MAAM,WAAW,0BAA0B;IACzC,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,gGAAgG;IAChG,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ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