@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
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// The viewer's memory on touch devices (UI/UX plan §5.4): iOS Safari caps one canvas at about
|
|
2
|
+
// 16.7 MP and all of a tab's canvases at 224–384 MB, and kills the tab past that; pdf.js caps a
|
|
3
|
+
// mobile canvas at 5 MP. On a coarse pointer every canvas holds at most 5 MP, and the pools and the
|
|
4
|
+
// bitmap cache together stay under the lowest of those totals unless the browser reports 4 GB of
|
|
5
|
+
// memory or more (`navigator.deviceMemory`). Desktop keeps the defaults.
|
|
6
|
+
import { DEFAULT_CACHE_BYTES } from "../canvas/cache.js";
|
|
7
|
+
import { BACKDROP_MAX_PIXELS } from "../render/tiles.js";
|
|
8
|
+
const MP = 1024 * 1024;
|
|
9
|
+
const MB = 1024 * 1024;
|
|
10
|
+
/** One canvas on a touch device: pdf.js's mobile cap. */
|
|
11
|
+
const TOUCH_CANVAS = 5 * MP;
|
|
12
|
+
/** The desktop budgets: the viewer's defaults before touch devices had their own. */
|
|
13
|
+
export const DESKTOP_BUDGETS = {
|
|
14
|
+
backdropMaxPixels: BACKDROP_MAX_PIXELS,
|
|
15
|
+
canvasMaxPixels: Number.POSITIVE_INFINITY,
|
|
16
|
+
pool: { max: 12, maxPixels: 40 * MP },
|
|
17
|
+
detailPool: { max: 3, maxPixels: 24 * MP },
|
|
18
|
+
cacheBytes: DEFAULT_CACHE_BYTES,
|
|
19
|
+
};
|
|
20
|
+
const TOUCH = { backdropMaxPixels: TOUCH_CANVAS, canvasMaxPixels: TOUCH_CANVAS };
|
|
21
|
+
/** The decoded bytes `budgets` allow at most: 4 a pixel across both pools, and the bitmap cache. */
|
|
22
|
+
export function budgetBytes(budgets) {
|
|
23
|
+
return 4 * ((budgets.pool.maxPixels ?? 0) + (budgets.detailPool.maxPixels ?? 0)) + budgets.cacheBytes;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The budgets for a device. On a coarse pointer the canvases and cache total at most 4 bytes per
|
|
27
|
+
* pixel × (pool + detail pool) + cache: 184 MB when the memory is unknown (iOS Safari reports none),
|
|
28
|
+
* 116 MB at 2 GB or less, 304 MB at 4 GB or more.
|
|
29
|
+
*/
|
|
30
|
+
export function viewerBudgets(hints) {
|
|
31
|
+
if (!hints.coarse)
|
|
32
|
+
return DESKTOP_BUDGETS;
|
|
33
|
+
const memory = hints.memoryGb;
|
|
34
|
+
if (memory !== undefined && memory <= 2) {
|
|
35
|
+
return {
|
|
36
|
+
...TOUCH,
|
|
37
|
+
pool: { max: 6, maxPixels: 12 * MP },
|
|
38
|
+
detailPool: { max: 1, maxPixels: 5 * MP },
|
|
39
|
+
cacheBytes: 48 * MB,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (memory !== undefined && memory >= 4) {
|
|
43
|
+
return {
|
|
44
|
+
...TOUCH,
|
|
45
|
+
pool: { max: 10, maxPixels: 32 * MP },
|
|
46
|
+
detailPool: { max: 2, maxPixels: 12 * MP },
|
|
47
|
+
cacheBytes: 128 * MB,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...TOUCH,
|
|
52
|
+
pool: { max: 8, maxPixels: 20 * MP },
|
|
53
|
+
detailPool: { max: 2, maxPixels: 10 * MP },
|
|
54
|
+
cacheBytes: 64 * MB,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** This device's hints: a coarse main pointer, and `navigator.deviceMemory` (Chromium only). */
|
|
58
|
+
export function deviceHints() {
|
|
59
|
+
const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches;
|
|
60
|
+
const memory = globalThis.navigator?.deviceMemory;
|
|
61
|
+
return { coarse, memoryGb: typeof memory === "number" ? memory : undefined };
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=budgets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budgets.js","sourceRoot":"","sources":["../../src/view/budgets.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,gGAAgG;AAChG,oGAAoG;AACpG,iGAAiG;AACjG,yEAAyE;AAEzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAmBzD,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACvB,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACvB,yDAAyD;AACzD,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,CAAC;AAE5B,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAkB;IAC5C,iBAAiB,EAAE,mBAAmB;IACtC,eAAe,EAAE,MAAM,CAAC,iBAAiB;IACzC,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,EAAE;IACrC,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,EAAE;IAC1C,UAAU,EAAE,mBAAmB;CAChC,CAAC;AAEF,MAAM,KAAK,GAAG,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAW,CAAC;AAE1F,oGAAoG;AACpG,MAAM,UAAU,WAAW,CAAC,OAAsB;IAChD,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;AACxG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aA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C9F,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** A position in viewport CSS px, or a time-stamped one. */
|
|
2
|
+
interface At {
|
|
3
|
+
readonly x: number;
|
|
4
|
+
readonly y: number;
|
|
5
|
+
}
|
|
6
|
+
interface Sample extends At {
|
|
7
|
+
/** ms */
|
|
8
|
+
readonly t: number;
|
|
9
|
+
}
|
|
10
|
+
/** How far a finger moves (CSS px) before a touch is a pan rather than a tap or a long press. */
|
|
11
|
+
export declare const SLOP = 10;
|
|
12
|
+
/** A finger held still this long (ms) is a long press, left to the browser's text selection. */
|
|
13
|
+
export declare const LONG_PRESS_MS = 500;
|
|
14
|
+
/** The most time (ms) from the first tap's lift to the second's touch, and the distance (CSS px) between them. */
|
|
15
|
+
export declare const DOUBLE_TAP: {
|
|
16
|
+
readonly ms: 300;
|
|
17
|
+
readonly distance: 24;
|
|
18
|
+
};
|
|
19
|
+
/** Whether tap `b` is the second tap of a double tap whose first was `a`. */
|
|
20
|
+
export declare function isDoubleTap(a: Sample, b: Sample): boolean;
|
|
21
|
+
/** The speed (CSS px per ms) a pan ends with: its movement over the last {@link VELOCITY_WINDOW} ms. */
|
|
22
|
+
export declare function releaseVelocity(samples: readonly Sample[]): At;
|
|
23
|
+
/**
|
|
24
|
+
* One frame of momentum `dt` ms long at speed `v`: how far it moves and its speed after, or
|
|
25
|
+
* undefined once it has slowed to a stop. The distance is the speed's integral over the frame.
|
|
26
|
+
*/
|
|
27
|
+
export declare function momentumStep(v: At, dt: number): {
|
|
28
|
+
readonly move: At;
|
|
29
|
+
readonly v: At;
|
|
30
|
+
} | undefined;
|
|
31
|
+
/** The zoom percentage of a pinch that started at `percent` with the fingers `from` apart and is `to` apart now. */
|
|
32
|
+
export declare function pinchPercent(percent: number, from: number, to: number): number;
|
|
33
|
+
/** What the gestures change: the viewer, seen through the calls they need. */
|
|
34
|
+
export interface TouchHost<Point> {
|
|
35
|
+
/** The zoom percentage now. */
|
|
36
|
+
percent(): number;
|
|
37
|
+
/** Whether the zoom is the page width now, so a double tap zooms in rather than back to it. */
|
|
38
|
+
fitsWidth(): boolean;
|
|
39
|
+
/** Zooms to `percent`, or to the page width, keeping viewport position `at` where it is. */
|
|
40
|
+
zoom(to: number | "fit-width", at: At): void;
|
|
41
|
+
/** The document point at viewport position `at`, and where a document point is now. */
|
|
42
|
+
pointAt(at: At): Point | undefined;
|
|
43
|
+
positionOf(point: Point): At | undefined;
|
|
44
|
+
scrollBy(dx: number, dy: number): void;
|
|
45
|
+
/** A pointer event's position in viewport CSS px. */
|
|
46
|
+
local(e: {
|
|
47
|
+
readonly clientX: number;
|
|
48
|
+
readonly clientY: number;
|
|
49
|
+
}): At;
|
|
50
|
+
frame(callback: (now: number) => void): number;
|
|
51
|
+
cancelFrame(id: number): void;
|
|
52
|
+
/** Keeps a pointer's events on the viewer while it is down, even if the canvas under it is recycled. */
|
|
53
|
+
capture(pointerId: number): void;
|
|
54
|
+
}
|
|
55
|
+
/** The touch gestures over one viewer; feed it the root's pointer events. */
|
|
56
|
+
export declare class TouchGestures<Point> {
|
|
57
|
+
#private;
|
|
58
|
+
constructor(host: TouchHost<Point>);
|
|
59
|
+
/** A pointer went down. A third finger joins nothing: the pinch keeps its first two. */
|
|
60
|
+
down(e: PointerEvent): void;
|
|
61
|
+
/** Whether two fingers are pinching now: Safari's own gesture events then leave the zoom alone. */
|
|
62
|
+
pinching(): boolean;
|
|
63
|
+
move(e: PointerEvent): void;
|
|
64
|
+
up(e: PointerEvent): void;
|
|
65
|
+
/** Stops what is running (momentum, a long-press timer); the viewer calls it on destroy. */
|
|
66
|
+
stop(): void;
|
|
67
|
+
/** Stops a flick's momentum: another input (a wheel, a key, a jump to a page) takes over. */
|
|
68
|
+
stopMomentum(): void;
|
|
69
|
+
}
|
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// browser neither scrolls nor zooms the page under a finger, and these do instead. One finger pans,
|
|
3
|
+
// with momentum after a flick; two fingers pinch, keeping the document point under them where it
|
|
4
|
+
// started; a double tap zooms in, or back to the page width. A finger held still passes through, so
|
|
5
|
+
// a long press still selects text. A pen pans like a finger until a mode draws with it; the mouse is
|
|
6
|
+
// left to the browser.
|
|
7
|
+
/** How far a finger moves (CSS px) before a touch is a pan rather than a tap or a long press. */
|
|
8
|
+
export const SLOP = 10;
|
|
9
|
+
/** A finger held still this long (ms) is a long press, left to the browser's text selection. */
|
|
10
|
+
export const LONG_PRESS_MS = 500;
|
|
11
|
+
/** The most time (ms) from the first tap's lift to the second's touch, and the distance (CSS px) between them. */
|
|
12
|
+
export const DOUBLE_TAP = { ms: 300, distance: 24 };
|
|
13
|
+
/** How long a tap may last (ms). */
|
|
14
|
+
const TAP_MS = 250;
|
|
15
|
+
/** Momentum's time constant (ms): the speed falls to about a third each this long, as on iOS. */
|
|
16
|
+
const MOMENTUM_MS = 325;
|
|
17
|
+
/** Momentum stops below this speed (CSS px per ms). */
|
|
18
|
+
const MOMENTUM_STOP = 0.02;
|
|
19
|
+
/** The last stretch of a pan (ms) whose movement sets the flick's speed. */
|
|
20
|
+
const VELOCITY_WINDOW = 100;
|
|
21
|
+
/** Whether tap `b` is the second tap of a double tap whose first was `a`. */
|
|
22
|
+
export function isDoubleTap(a, b) {
|
|
23
|
+
return b.t - a.t <= DOUBLE_TAP.ms && Math.hypot(b.x - a.x, b.y - a.y) <= DOUBLE_TAP.distance;
|
|
24
|
+
}
|
|
25
|
+
/** The speed (CSS px per ms) a pan ends with: its movement over the last {@link VELOCITY_WINDOW} ms. */
|
|
26
|
+
export function releaseVelocity(samples) {
|
|
27
|
+
const last = samples.at(-1);
|
|
28
|
+
if (last === undefined)
|
|
29
|
+
return { x: 0, y: 0 };
|
|
30
|
+
const first = samples.find((s) => last.t - s.t <= VELOCITY_WINDOW) ?? last;
|
|
31
|
+
const dt = last.t - first.t;
|
|
32
|
+
return dt <= 0 ? { x: 0, y: 0 } : { x: (last.x - first.x) / dt, y: (last.y - first.y) / dt };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* One frame of momentum `dt` ms long at speed `v`: how far it moves and its speed after, or
|
|
36
|
+
* undefined once it has slowed to a stop. The distance is the speed's integral over the frame.
|
|
37
|
+
*/
|
|
38
|
+
export function momentumStep(v, dt) {
|
|
39
|
+
if (Math.hypot(v.x, v.y) < MOMENTUM_STOP)
|
|
40
|
+
return undefined;
|
|
41
|
+
const decay = Math.exp(-dt / MOMENTUM_MS);
|
|
42
|
+
const travelled = MOMENTUM_MS * (1 - decay);
|
|
43
|
+
return { move: { x: v.x * travelled, y: v.y * travelled }, v: { x: v.x * decay, y: v.y * decay } };
|
|
44
|
+
}
|
|
45
|
+
/** The zoom percentage of a pinch that started at `percent` with the fingers `from` apart and is `to` apart now. */
|
|
46
|
+
export function pinchPercent(percent, from, to) {
|
|
47
|
+
return from <= 0 ? percent : percent * (to / from);
|
|
48
|
+
}
|
|
49
|
+
/** Whether the gestures take this pointer: fingers and pens, not the mouse. */
|
|
50
|
+
const TAKEN = new Set(["touch", "pen"]);
|
|
51
|
+
/** The touch gestures over one viewer; feed it the root's pointer events. */
|
|
52
|
+
export class TouchGestures {
|
|
53
|
+
#host;
|
|
54
|
+
#fingers = new Map();
|
|
55
|
+
/** The kind of pointer down now: a pen's gesture ignores a palm resting beside it, and the other way round. */
|
|
56
|
+
#kind;
|
|
57
|
+
#gesture;
|
|
58
|
+
#lastTap;
|
|
59
|
+
#longPress;
|
|
60
|
+
#momentum;
|
|
61
|
+
constructor(host) {
|
|
62
|
+
this.#host = host;
|
|
63
|
+
}
|
|
64
|
+
/** A pointer went down. A third finger joins nothing: the pinch keeps its first two. */
|
|
65
|
+
down(e) {
|
|
66
|
+
if (!TAKEN.has(e.pointerType))
|
|
67
|
+
return;
|
|
68
|
+
if (this.#fingers.size > 0 && e.pointerType !== this.#kind)
|
|
69
|
+
return;
|
|
70
|
+
this.#kind = e.pointerType;
|
|
71
|
+
this.stopMomentum();
|
|
72
|
+
const at = this.#host.local(e);
|
|
73
|
+
this.#fingers.set(e.pointerId, at);
|
|
74
|
+
this.#host.capture(e.pointerId);
|
|
75
|
+
if (this.#fingers.size === 2)
|
|
76
|
+
this.#startPinch();
|
|
77
|
+
else if (this.#fingers.size === 1)
|
|
78
|
+
this.#startPending(at, e.timeStamp);
|
|
79
|
+
}
|
|
80
|
+
/** Whether two fingers are pinching now: Safari's own gesture events then leave the zoom alone. */
|
|
81
|
+
pinching() {
|
|
82
|
+
return this.#gesture?.kind === "pinch";
|
|
83
|
+
}
|
|
84
|
+
move(e) {
|
|
85
|
+
if (!this.#fingers.has(e.pointerId))
|
|
86
|
+
return;
|
|
87
|
+
const at = this.#host.local(e);
|
|
88
|
+
this.#fingers.set(e.pointerId, at);
|
|
89
|
+
const g = this.#gesture;
|
|
90
|
+
if (g === undefined || g.kind === "passthrough")
|
|
91
|
+
return;
|
|
92
|
+
if (g.kind === "pinch") {
|
|
93
|
+
this.#pinch(g);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (g.kind === "pending") {
|
|
97
|
+
if (Math.hypot(at.x - g.start.x, at.y - g.start.y) < SLOP)
|
|
98
|
+
return;
|
|
99
|
+
clearTimeout(this.#longPress);
|
|
100
|
+
this.#gesture = { kind: "pan", last: g.start, samples: [g.start] };
|
|
101
|
+
}
|
|
102
|
+
const pan = this.#gesture;
|
|
103
|
+
if (pan?.kind !== "pan")
|
|
104
|
+
return;
|
|
105
|
+
this.#host.scrollBy(pan.last.x - at.x, pan.last.y - at.y);
|
|
106
|
+
pan.last = at;
|
|
107
|
+
pan.samples.push({ ...at, t: e.timeStamp });
|
|
108
|
+
// Only the last stretch sets a flick's speed, so older samples go.
|
|
109
|
+
const since = pan.samples.findIndex((s) => e.timeStamp - s.t <= VELOCITY_WINDOW);
|
|
110
|
+
if (since > 0)
|
|
111
|
+
pan.samples.splice(0, since);
|
|
112
|
+
}
|
|
113
|
+
up(e) {
|
|
114
|
+
if (!this.#fingers.delete(e.pointerId))
|
|
115
|
+
return;
|
|
116
|
+
clearTimeout(this.#longPress);
|
|
117
|
+
const g = this.#gesture;
|
|
118
|
+
if (g?.kind === "pinch") {
|
|
119
|
+
// Two fingers left pinch afresh from where they are; one left pans on from where it is, so the
|
|
120
|
+
// page never jumps.
|
|
121
|
+
const left = [...this.#fingers.values()];
|
|
122
|
+
if (left.length >= 2)
|
|
123
|
+
this.#startPinch();
|
|
124
|
+
else
|
|
125
|
+
this.#gesture = left[0] === undefined ? undefined : { kind: "pan", last: left[0], samples: [] };
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (this.#fingers.size > 0)
|
|
129
|
+
return;
|
|
130
|
+
this.#gesture = undefined;
|
|
131
|
+
// A cancelled or lost pointer ends the gesture without a flick or a tap.
|
|
132
|
+
if (e.type !== "pointerup")
|
|
133
|
+
return;
|
|
134
|
+
if (g?.kind === "pan")
|
|
135
|
+
this.#fling(releaseVelocity(g.samples));
|
|
136
|
+
else if (g?.kind === "pending" && e.timeStamp - g.start.t <= TAP_MS)
|
|
137
|
+
this.#tap(g.start, e.timeStamp);
|
|
138
|
+
}
|
|
139
|
+
/** Stops what is running (momentum, a long-press timer); the viewer calls it on destroy. */
|
|
140
|
+
stop() {
|
|
141
|
+
this.stopMomentum();
|
|
142
|
+
clearTimeout(this.#longPress);
|
|
143
|
+
this.#fingers.clear();
|
|
144
|
+
this.#gesture = undefined;
|
|
145
|
+
this.#kind = undefined;
|
|
146
|
+
}
|
|
147
|
+
#startPending(at, t) {
|
|
148
|
+
const start = { ...at, t };
|
|
149
|
+
this.#gesture = { kind: "pending", start };
|
|
150
|
+
clearTimeout(this.#longPress);
|
|
151
|
+
this.#longPress = setTimeout(() => {
|
|
152
|
+
if (this.#gesture?.kind === "pending")
|
|
153
|
+
this.#gesture = { kind: "passthrough" };
|
|
154
|
+
}, LONG_PRESS_MS);
|
|
155
|
+
}
|
|
156
|
+
#startPinch() {
|
|
157
|
+
clearTimeout(this.#longPress);
|
|
158
|
+
const s = this.#spread();
|
|
159
|
+
if (s === undefined)
|
|
160
|
+
return;
|
|
161
|
+
this.#gesture = {
|
|
162
|
+
kind: "pinch",
|
|
163
|
+
percent: this.#host.percent(),
|
|
164
|
+
distance: s.distance,
|
|
165
|
+
point: this.#host.pointAt(s.mid),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
#pinch(g) {
|
|
169
|
+
const s = this.#spread();
|
|
170
|
+
if (s === undefined)
|
|
171
|
+
return;
|
|
172
|
+
this.#host.zoom(pinchPercent(g.percent, g.distance, s.distance), s.mid);
|
|
173
|
+
// The zoom kept the midpoint's own point still; the fingers may also have moved together, so
|
|
174
|
+
// the point that started under them is scrolled back under them.
|
|
175
|
+
const now = g.point === undefined ? undefined : this.#host.positionOf(g.point);
|
|
176
|
+
if (now !== undefined)
|
|
177
|
+
this.#host.scrollBy(now.x - s.mid.x, now.y - s.mid.y);
|
|
178
|
+
}
|
|
179
|
+
#spread() {
|
|
180
|
+
const [a, b] = [...this.#fingers.values()];
|
|
181
|
+
if (a === undefined || b === undefined)
|
|
182
|
+
return undefined;
|
|
183
|
+
return { distance: Math.hypot(a.x - b.x, a.y - b.y), mid: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 } };
|
|
184
|
+
}
|
|
185
|
+
/** A tap that touched at `tap` and lifted at `lifted` (ms). */
|
|
186
|
+
#tap(tap, lifted) {
|
|
187
|
+
const first = this.#lastTap;
|
|
188
|
+
if (first !== undefined && isDoubleTap(first, tap)) {
|
|
189
|
+
this.#lastTap = undefined;
|
|
190
|
+
this.#host.zoom(this.#host.fitsWidth() ? this.#host.percent() * 2 : "fit-width", tap);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
// The window to the second tap runs from this one's lift.
|
|
194
|
+
this.#lastTap = { ...tap, t: lifted };
|
|
195
|
+
}
|
|
196
|
+
#fling(v) {
|
|
197
|
+
let speed = { x: -v.x, y: -v.y };
|
|
198
|
+
let before;
|
|
199
|
+
const step = (now) => {
|
|
200
|
+
const dt = before === undefined ? 16 : now - before;
|
|
201
|
+
before = now;
|
|
202
|
+
const next = momentumStep(speed, dt);
|
|
203
|
+
if (next === undefined) {
|
|
204
|
+
this.#momentum = undefined;
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
this.#host.scrollBy(next.move.x, next.move.y);
|
|
208
|
+
speed = next.v;
|
|
209
|
+
this.#momentum = this.#host.frame(step);
|
|
210
|
+
};
|
|
211
|
+
this.#momentum = this.#host.frame(step);
|
|
212
|
+
}
|
|
213
|
+
/** Stops a flick's momentum: another input (a wheel, a key, a jump to a page) takes over. */
|
|
214
|
+
stopMomentum() {
|
|
215
|
+
if (this.#momentum !== undefined)
|
|
216
|
+
this.#host.cancelFrame(this.#momentum);
|
|
217
|
+
this.#momentum = undefined;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=touch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touch.js","sourceRoot":"","sources":["../../src/view/touch.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,oGAAoG;AACpG,iGAAiG;AACjG,oGAAoG;AACpG,qGAAqG;AACrG,uBAAuB;AAYvB,iGAAiG;AACjG,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;AACvB,gGAAgG;AAChG,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AACjC,kHAAkH;AAClH,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAW,CAAC;AAC7D,oCAAoC;AACpC,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,iGAAiG;AACjG,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,uDAAuD;AACvD,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,4EAA4E;AAC5E,MAAM,e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CAAC,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,6FAA6F;IAC7F,YAAY;QACV,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-select.d.ts","sourceRoot":"","sources":["../../src/view/user-select.ts"],"names":[],"mappings":"AAKA,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Which parts of the viewer a selection may take in: only the text layer's spans. Each element
|
|
2
|
+
// that holds nothing to select sets `none` on itself; no ancestor of the spans may, since Firefox
|
|
3
|
+
// stops a mouse drag from selecting under a `user-select: none` ancestor once a text field on
|
|
4
|
+
// the page has had the focus (docs/bugs/firefox-selection-after-a-field).
|
|
5
|
+
/** Sets `element`'s `user-select`, with WebKit's prefix (Safari before 26 reads only that). */
|
|
6
|
+
export function setUserSelect(element, value) {
|
|
7
|
+
element.style.setProperty("user-select", value);
|
|
8
|
+
element.style.setProperty("-webkit-user-select", value);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=user-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-select.js","sourceRoot":"","sources":["../../src/view/user-select.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,kGAAkG;AAClG,8FAA8F;AAC9F,0EAA0E;AAE1E,+FAA+F;AAC/F,MAAM,UAAU,aAAa,CAAC,OAAoB,EAAE,KAAsB;IACxE,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAChD,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/view/viewer.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import { type PageAppearance } from "@laminapdf/render";
|
|
2
|
+
import type { Target } from "@laminapdf/sdk";
|
|
1
3
|
import { type CanvasPoolOptions } from "../canvas/pool.js";
|
|
2
4
|
import type { ViewerClient } from "../client.js";
|
|
5
|
+
import { FindController } from "../find/controller.js";
|
|
6
|
+
import { NavigationHistory, type NavigationHistoryOptions } from "../history/history.js";
|
|
7
|
+
import type { CopyMode } from "../layers/copy.js";
|
|
8
|
+
import { type LinkLayerOptions } from "../layers/link-layer.js";
|
|
9
|
+
import { type TextLayerOptions, type TextSelection } from "../layers/text-layer.js";
|
|
3
10
|
import { type Rotation } from "../layout/page-layout.js";
|
|
4
11
|
import { type OpenedDocument } from "../protocol.js";
|
|
5
12
|
import { type DocumentPoint, type Point, type Zoom } from "../zoom/zoom.js";
|
|
13
|
+
import { type DeviceHints } from "./budgets.js";
|
|
6
14
|
/** Where a mounted page's pixels are. */
|
|
7
15
|
export type PageRenderState = "placeholder" | "low" | "sharp" | "error";
|
|
8
16
|
/** What the view shows: for `useSyncExternalStore` and the toolbar. */
|
|
@@ -14,6 +22,8 @@ export interface ViewState {
|
|
|
14
22
|
/** The zoom as a percentage (100 is actual size), whatever the mode. */
|
|
15
23
|
readonly percent: number;
|
|
16
24
|
readonly rotation: Rotation;
|
|
25
|
+
/** How the pages' colours are drawn (`"original"`: their own). */
|
|
26
|
+
readonly appearance: PageAppearance;
|
|
17
27
|
readonly scrollTop: number;
|
|
18
28
|
/** The pages any part of which is in the viewport. */
|
|
19
29
|
readonly visibleRange: {
|
|
@@ -28,6 +38,8 @@ export interface RenderStats {
|
|
|
28
38
|
readonly canvases: number;
|
|
29
39
|
readonly peakCanvases: number;
|
|
30
40
|
readonly maxCanvases: number;
|
|
41
|
+
/** Detail canvases in use now: one per page in view whose backdrop is below the full pixel ratio. */
|
|
42
|
+
readonly detailCanvases: number;
|
|
31
43
|
/**
|
|
32
44
|
* Draws onto a page whose shell was out of the DOM at the moment of drawing, counted at the
|
|
33
45
|
* draw itself: always 0 (the guarantee that a cancelled render never paints).
|
|
@@ -51,10 +63,18 @@ export interface ViewerEventMap {
|
|
|
51
63
|
readonly percent: number;
|
|
52
64
|
};
|
|
53
65
|
renderstats: RenderStats;
|
|
66
|
+
/** The text selection changed: `undefined` when it left the viewer (UI/UX plan §5.3). */
|
|
67
|
+
selectionchange: {
|
|
68
|
+
readonly selection: TextSelection | undefined;
|
|
69
|
+
};
|
|
54
70
|
}
|
|
55
71
|
/** A layer that later todos mount into each page (text, annotations, highlights, …). */
|
|
56
72
|
export interface PageLayer {
|
|
57
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Its slot: `text`, `annot` and `highlight` exist on every page; another name gets a new one on top.
|
|
75
|
+
* Every slot but `text` lets the pointer through, so the text stays selectable under it. An element a
|
|
76
|
+
* layer wants clicked, such as a link, sets `pointer-events: auto` on itself.
|
|
77
|
+
*/
|
|
58
78
|
readonly name: string;
|
|
59
79
|
/** Page `page` was mounted: `element` is the layer's slot in its shell. */
|
|
60
80
|
onMount?(page: number, element: HTMLElement): void;
|
|
@@ -73,15 +93,56 @@ export interface CreateViewerOptions {
|
|
|
73
93
|
readonly margin?: number;
|
|
74
94
|
/** CSS px between pages (default 16). */
|
|
75
95
|
readonly gap?: number;
|
|
96
|
+
/**
|
|
97
|
+
* The page canvases (backdrops): default 12 canvases and 40 MP in all, less on a touch device
|
|
98
|
+
* (view/budgets.ts), as are the next three.
|
|
99
|
+
*/
|
|
76
100
|
readonly pool?: CanvasPoolOptions;
|
|
101
|
+
/** The detail canvases over the part in view: default 3 canvases and 24 MP in all. */
|
|
102
|
+
readonly detailPool?: CanvasPoolOptions;
|
|
77
103
|
/** The bitmap cache's budget in bytes (default 256 MB). */
|
|
78
104
|
readonly cacheBytes?: number;
|
|
105
|
+
/** The most device pixels one page canvas holds (default 8 MP; 5 MP on a touch device). */
|
|
106
|
+
readonly backdropMaxPixels?: number;
|
|
107
|
+
/** The most device pixels any one canvas holds, a detail canvas too (default no cap; 5 MP on a touch device). */
|
|
108
|
+
readonly canvasMaxPixels?: number;
|
|
109
|
+
/** The device the budgets are chosen for; detected (a coarse pointer, `navigator.deviceMemory`) when left out. */
|
|
110
|
+
readonly device?: DeviceHints;
|
|
79
111
|
/** How long a zoom gesture must pause before the sharp re-render, in ms (default 150). */
|
|
80
112
|
readonly settleMs?: number;
|
|
81
113
|
/** The device pixel ratio (default `globalThis.devicePixelRatio`). */
|
|
82
114
|
readonly dpr?: () => number;
|
|
83
115
|
/** The initial zoom (default `fit-width`). */
|
|
84
116
|
readonly zoom?: Zoom;
|
|
117
|
+
/**
|
|
118
|
+
* The text layer: selectable, copyable text over every page, and a tagged document's structure
|
|
119
|
+
* for screen readers (default on; `false` leaves it out, an object sets its options).
|
|
120
|
+
*/
|
|
121
|
+
readonly text?: boolean | TextLayerOptions;
|
|
122
|
+
/**
|
|
123
|
+
* The link layer: an anchor over each link, internal ones going there as history jumps (default
|
|
124
|
+
* on; `false` leaves it out, an object sets its options).
|
|
125
|
+
*/
|
|
126
|
+
readonly links?: boolean | LinkLayerOptions;
|
|
127
|
+
/** The back and forward history's options. */
|
|
128
|
+
readonly history?: NavigationHistoryOptions;
|
|
129
|
+
/** What assistive technology hears of each page, and where focus goes after a jump. */
|
|
130
|
+
readonly pages?: PageRegionOptions;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Each page shell is a region that assistive technology names ("Page iv, 4 of 120") and can land
|
|
134
|
+
* on: the viewer has no strings of its own, so the app gives the words.
|
|
135
|
+
*/
|
|
136
|
+
export interface PageRegionOptions {
|
|
137
|
+
/** A page's name, from its index and the page count (default "Page 4 of 120"). */
|
|
138
|
+
readonly name?: (index: number, count: number) => string;
|
|
139
|
+
/** What a page is called as a kind of region (default "page"). */
|
|
140
|
+
readonly roleDescription?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Whether a history jump (a link, the outline, a thumbnail, go to page) moves focus to the page
|
|
143
|
+
* it lands on, once that page is mounted (default false).
|
|
144
|
+
*/
|
|
145
|
+
readonly focusOnJump?: boolean;
|
|
85
146
|
}
|
|
86
147
|
/**
|
|
87
148
|
* The viewer: a scroll container over one document's pages. Make one with {@link createViewer},
|
|
@@ -89,6 +150,13 @@ export interface CreateViewerOptions {
|
|
|
89
150
|
*/
|
|
90
151
|
export declare class Viewer {
|
|
91
152
|
#private;
|
|
153
|
+
/** Find in this viewer's document: query, options, matches, next and previous. */
|
|
154
|
+
readonly find: FindController;
|
|
155
|
+
/**
|
|
156
|
+
* Back and forward through the places jumped from and to: links, `jumpToPage`,
|
|
157
|
+
* `jumpToDestination` and find's matches record a jump; scrolling doesn't.
|
|
158
|
+
*/
|
|
159
|
+
readonly history: NavigationHistory;
|
|
92
160
|
constructor(options: CreateViewerOptions);
|
|
93
161
|
/** The scroll container (append it, or use {@link mount}). */
|
|
94
162
|
get element(): HTMLDivElement;
|
|
@@ -102,12 +170,38 @@ export declare class Viewer {
|
|
|
102
170
|
subscribe(listener: () => void): () => void;
|
|
103
171
|
/** Listens for `event`; returns a function that stops listening. */
|
|
104
172
|
on<E extends keyof ViewerEventMap>(event: E, listener: (data: ViewerEventMap[E]) => void): () => void;
|
|
173
|
+
/**
|
|
174
|
+
* Copies the text selection to the clipboard: by paragraph in reading order, or exact, as laid
|
|
175
|
+
* out. Call it in a user gesture (a click, a key). Resolves false when nothing is selected or
|
|
176
|
+
* the clipboard refused.
|
|
177
|
+
*/
|
|
178
|
+
copySelection(mode?: CopyMode): Promise<boolean>;
|
|
179
|
+
/** Whether a plain drag selects a rectangle, as an Alt/Option-drag does (column selection). */
|
|
180
|
+
get columnSelect(): boolean;
|
|
181
|
+
/** Turns column selection by plain drag on or off; Alt/Option-drag selects a rectangle either way. */
|
|
182
|
+
set columnSelect(on: boolean);
|
|
183
|
+
/**
|
|
184
|
+
* Keeps `pages` mounted wherever the view scrolls, until the next call replaces them: the pages
|
|
185
|
+
* a text selection touches, so scrolling never takes the selection away. A pinned page out of
|
|
186
|
+
* view keeps its shell and its text; its canvas goes back to the pool like any other.
|
|
187
|
+
*/
|
|
188
|
+
keepMounted(pages: Iterable<number>): void;
|
|
105
189
|
/** Adds a layer to every page, mounted now and later; returns a function that removes it. */
|
|
106
190
|
addLayer(layer: PageLayer): () => void;
|
|
107
191
|
/** Scrolls page `index` to the top of the viewport (or its centre). */
|
|
108
192
|
goToPage(index: number, options?: {
|
|
109
193
|
readonly anchor?: "top" | "center";
|
|
110
194
|
}): void;
|
|
195
|
+
/**
|
|
196
|
+
* Goes to `target` (an outline item's, a named destination's or a link's, from
|
|
197
|
+
* `ViewerClient.outline` or `namedDestination`): its zoom if it sets one, then its point at the
|
|
198
|
+
* viewport's top-left, or its page's top when it names no point (ISO 32000-2 §12.3.2.2).
|
|
199
|
+
*/
|
|
200
|
+
goToDestination(target: Target): void;
|
|
201
|
+
/** {@link goToPage} as a history jump: Back returns to where the view was. */
|
|
202
|
+
jumpToPage(index: number): void;
|
|
203
|
+
/** {@link goToDestination} as a history jump: Back returns to where the view was. */
|
|
204
|
+
jumpToDestination(target: Target): void;
|
|
111
205
|
/**
|
|
112
206
|
* Sets the zoom (a mode, or a percentage clamped to 10–800 %), keeping the document point at
|
|
113
207
|
* `anchor` (viewport CSS px; default its centre) where it is.
|
|
@@ -121,6 +215,13 @@ export declare class Viewer {
|
|
|
121
215
|
* @throws RangeError when `delta` isn't a multiple of 90.
|
|
122
216
|
*/
|
|
123
217
|
rotate(delta: number): void;
|
|
218
|
+
/**
|
|
219
|
+
* Draws the pages in `appearance` (Sepia, Dark, High contrast or their own colours), keeping the
|
|
220
|
+
* scroll position: pages in view paint again, a quick pass then sharp tiles, and none of their
|
|
221
|
+
* old pixels is kept; other pages give their canvas back and paint when they come into view.
|
|
222
|
+
* The thumbnails follow.
|
|
223
|
+
*/
|
|
224
|
+
setAppearance(appearance: PageAppearance): void;
|
|
124
225
|
/** The document point at viewport position (`x`, `y`) in CSS px. */
|
|
125
226
|
pointAt(x: number, y: number): DocumentPoint | undefined;
|
|
126
227
|
/** Where `point` is now, in viewport CSS px. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewer.d.ts","sourceRoot":"","sources":["../../src/view/viewer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"viewer.d.ts","sourceRoot":"","sources":["../../src/view/viewer.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,cAAc,EAA8B,MAAM,mBAAmB,CAAC;AACpF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAc,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAqB,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC5G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAa,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,EAAyC,KAAK,QAAQ,EAAW,MAAM,0BAA0B,CAAC;AAEzG,OAAO,EAGL,KAAK,cAAc,EAIpB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,KAAK,EAKV,KAAK,IAAI,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,WAAW,EAA8B,MAAM,cAAc,CAAC;AAI5E,yCAAyC;AACzC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