@metacensus/library-ui 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/pdf/PdfPage.js +8 -43
- package/dist/pdf/PdfPage.js.map +1 -1
- package/dist/pdf/PdfReader.d.ts +18 -0
- package/dist/pdf/PdfReader.js +286 -0
- package/dist/pdf/PdfReader.js.map +1 -0
- package/dist/pdf/index.d.ts +1 -0
- package/dist/pdf/index.js +1 -0
- package/dist/pdf/index.js.map +1 -1
- package/dist/pdf/page.d.ts +22 -3
- package/dist/pdf/page.js +58 -4
- package/dist/pdf/page.js.map +1 -1
- package/dist/pdf/queue.d.ts +3 -3
- package/dist/pdf/queue.js +24 -15
- package/dist/pdf/queue.js.map +1 -1
- package/dist/pdf/scroll.d.ts +13 -0
- package/dist/pdf/scroll.js +48 -0
- package/dist/pdf/scroll.js.map +1 -0
- package/dist/pdf/toolbar.d.ts +8 -0
- package/dist/pdf/toolbar.js +22 -0
- package/dist/pdf/toolbar.js.map +1 -0
- package/package.json +1 -1
- package/src/css/pdf.css +50 -0
package/README.md
CHANGED
|
@@ -65,6 +65,7 @@ In `.astro` files, pass `Header`'s `nav` and `actions` as named slots; JSX props
|
|
|
65
65
|
`@metacensus/library-ui/pdf` is a separate entry point, so the main one never loads pdf.js.
|
|
66
66
|
|
|
67
67
|
- `<PdfPage source={…} page={12} crop={anchor} label="…" marks={[…]} />` draws one page, cropped to an anchor's quads plus 30 pt or whole, with marks that stay on their glyphs at every width and DPR. Import `@metacensus/library-ui/pdf.css` beside `tokens.css`.
|
|
68
|
+
- `<PdfReader source={…} marks={[…]} target={{ mark: id }} jump={n} className="h-full" />` scrolls the whole document inside its frame, which sets its height: a toolbar, zoom from 50% to 400% of fit width, and the reader's place kept through zoom and resize. `target` scrolls on load, when it changes, and when `jump` does.
|
|
68
69
|
- A stored mark is a `PdfAnchor`, whose JSON Schema is `@metacensus/library-ui/pdf/anchor.schema.json`, and `quadFromRect` and `quadsFromFractions` convert user-space rects and fractions of the displayed page into its quads.
|
|
69
70
|
- Serve `dist/pdf-assets/` (the worker, wasm, cmaps, standard fonts and the ICC profiles for CMYK pages) from your own origin, copied again on each upgrade since pdf.js refuses a worker of another version, and name its URL once per page with `configurePdf({ assets: '/pdfjs/' })`. The page's CSP needs `script-src 'self' 'wasm-unsafe-eval'; worker-src 'self'`, and no `unsafe-eval`.
|
|
70
71
|
|
package/dist/pdf/PdfPage.js
CHANGED
|
@@ -2,20 +2,17 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { Button } from '../tools/Button.js';
|
|
4
4
|
import { cn } from '../tools/cn.js';
|
|
5
|
-
import {
|
|
6
|
-
import { open, typed } from './document.js';
|
|
5
|
+
import { open } from './document.js';
|
|
7
6
|
import { toView } from './marks.js';
|
|
8
|
-
import { PageView } from './page.js';
|
|
9
|
-
import { quadsOn
|
|
7
|
+
import { Failed, PageView, pageName, useAttempt, useDrawn, } from './page.js';
|
|
8
|
+
import { quadsOn } from './resolve.js';
|
|
10
9
|
/** One page of a PDF, cropped to a passage or whole, with marks on it. */
|
|
11
10
|
export function PdfPage({ source, page, crop, label, marks = [], current, onResolve, onMarkActivate, onPageClick, onError, className, }) {
|
|
12
11
|
const host = useRef(null);
|
|
13
12
|
const id = useId();
|
|
14
13
|
const [width, setWidth] = useState(0);
|
|
15
|
-
const [attempt, setAttempt] = useState(0);
|
|
16
14
|
const [loaded, setLoaded] = useState();
|
|
17
|
-
const
|
|
18
|
-
const [resolutions, setResolutions] = useState();
|
|
15
|
+
const { attempt, error, fail, retry } = useAttempt(onError);
|
|
19
16
|
const [expanded, setExpanded] = useState(false);
|
|
20
17
|
const toggled = useRef(false);
|
|
21
18
|
useEffect(() => {
|
|
@@ -47,37 +44,9 @@ export function PdfPage({ source, page, crop, label, marks = [], current, onReso
|
|
|
47
44
|
live = false;
|
|
48
45
|
lease.release();
|
|
49
46
|
setLoaded(undefined);
|
|
50
|
-
setResolutions(undefined);
|
|
51
47
|
};
|
|
52
48
|
}, [file, source.sha256, page, attempt]);
|
|
53
|
-
const
|
|
54
|
-
const failure = typed(error);
|
|
55
|
-
setError(failure);
|
|
56
|
-
onError?.(failure);
|
|
57
|
-
};
|
|
58
|
-
const anchors = JSON.stringify(marks.map(({ id, anchor }) => [id, anchor]));
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (!loaded)
|
|
61
|
-
return;
|
|
62
|
-
let live = true;
|
|
63
|
-
resolve(marks, loaded.document, loaded.sha256)
|
|
64
|
-
.then((resolutions) => live && setResolutions(resolutions))
|
|
65
|
-
.catch((error) => live && fail(error));
|
|
66
|
-
return () => {
|
|
67
|
-
live = false;
|
|
68
|
-
};
|
|
69
|
-
}, [loaded, anchors]);
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (resolutions)
|
|
72
|
-
onResolve?.(resolutions);
|
|
73
|
-
}, [JSON.stringify(resolutions)]);
|
|
74
|
-
const drawn = useMemo(() => {
|
|
75
|
-
const placed = new Map(resolutions?.map((r) => [r.id, r]));
|
|
76
|
-
return marks.flatMap((mark) => {
|
|
77
|
-
const { status, anchor = mark.anchor } = placed.get(mark.id) ?? {};
|
|
78
|
-
return status && status !== 'orphan' ? [{ ...mark, anchor }] : [];
|
|
79
|
-
});
|
|
80
|
-
}, [marks, resolutions]);
|
|
49
|
+
const drawn = useDrawn(marks, loaded, onResolve, fail);
|
|
81
50
|
const shown = crop && !expanded ? quadsOn(crop, page) : [];
|
|
82
51
|
const cropped = shown.length > 0;
|
|
83
52
|
const view = useMemo(() => (loaded && width > 0 ? fit(loaded.page, width, shown) : undefined), [loaded, width, JSON.stringify(shown)]);
|
|
@@ -89,13 +58,9 @@ export function PdfPage({ source, page, crop, label, marks = [], current, onReso
|
|
|
89
58
|
.current.querySelector('.mc-pdf-mark')
|
|
90
59
|
?.scrollIntoView({ block: 'nearest' });
|
|
91
60
|
}, [view]);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return (_jsx("div", { ref: host, className: cn('mc-pdf-page', className), "aria-busy": !loaded && !error, children: error ? (_jsx(Notice, { title: "This PDF could not be shown.", children: _jsx(Button, { variant: "secondary", onClick: () => {
|
|
96
|
-
setError(undefined);
|
|
97
|
-
setAttempt((n) => n + 1);
|
|
98
|
-
}, children: "Retry" }) })) : (_jsxs(_Fragment, { children: [_jsx("div", { id: id, children: _jsx(PageView, { view: view, cropped: cropped, name: cropped ? (label ?? `Page ${page}`) : `Page ${page}${printed}`, marks: drawn, current: current, onMarkActivate: onMarkActivate, onPageClick: onPageClick, onError: fail }) }), crop && (_jsx(Button, { variant: "text", "aria-expanded": expanded, "aria-controls": id, onClick: () => {
|
|
61
|
+
return (_jsx("div", { ref: host, className: cn('mc-pdf-page', className), "aria-busy": !loaded && !error, children: error ? (_jsx(Failed, { onRetry: retry })) : (_jsxs(_Fragment, { children: [_jsx("div", { id: id, children: _jsx(PageView, { view: view, cropped: cropped, name: cropped
|
|
62
|
+
? (label ?? `Page ${page}`)
|
|
63
|
+
: pageName(page, loaded?.printed), marks: drawn ?? [], current: current, onMarkActivate: onMarkActivate, onPageClick: onPageClick, onError: fail }) }), crop && (_jsx(Button, { variant: "text", "aria-expanded": expanded, "aria-controls": id, onClick: () => {
|
|
99
64
|
toggled.current = true;
|
|
100
65
|
setExpanded(!expanded);
|
|
101
66
|
}, children: "Whole page" }))] })) }));
|
package/dist/pdf/PdfPage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PdfPage.js","sourceRoot":"","sources":["../../src/pdf/PdfPage.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,C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AE,CAAC,GAAG,MAAM,CAAC,CAAA;IAChD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,CAAA;IAChD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,CAAA;IAChD,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACvD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IACnC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IACrC,OAAO;QACL,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;KACjB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ComponentProps } from 'react';
|
|
2
|
+
import type { PdfTarget } from './index.js';
|
|
3
|
+
import type { PdfPage } from './PdfPage.js';
|
|
4
|
+
type Props = Omit<ComponentProps<typeof PdfPage>, 'page' | 'crop' | 'label' | 'className'> & {
|
|
5
|
+
/** Scrolled to on load, when its page or mark changes, and when `jump` does. */
|
|
6
|
+
target?: PdfTarget;
|
|
7
|
+
jump?: number;
|
|
8
|
+
/** The page under the middle of the view. */
|
|
9
|
+
onPageChange?: (page: {
|
|
10
|
+
index: number;
|
|
11
|
+
label?: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
/** The frame, which sets the reader's height. */
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
/** A whole PDF that scrolls inside its frame, with marks on its pages. */
|
|
17
|
+
export declare function PdfReader({ source, marks, current, target, jump, onPageChange, onResolve, onMarkActivate, onPageClick, onError, className, }: Props): import("react").JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { cn } from '../tools/cn.js';
|
|
4
|
+
import { open } from './document.js';
|
|
5
|
+
import { toView } from './marks.js';
|
|
6
|
+
import { Failed, PageView, pageName, useAttempt, useDrawn } from './page.js';
|
|
7
|
+
import { watch } from './queue.js';
|
|
8
|
+
import { quadsOf } from './anchor.js';
|
|
9
|
+
import { quadsOn } from './resolve.js';
|
|
10
|
+
import { pageAt, placeOf, restore } from './scroll.js';
|
|
11
|
+
import { Toolbar, within } from './toolbar.js';
|
|
12
|
+
/** CSS px around and between pages. */
|
|
13
|
+
const gap = 8;
|
|
14
|
+
/** A whole PDF that scrolls inside its frame, with marks on its pages. */
|
|
15
|
+
export function PdfReader({ source, marks = [], current, target, jump, onPageChange, onResolve, onMarkActivate, onPageClick, onError, className, }) {
|
|
16
|
+
const [box, setBox] = useState(null);
|
|
17
|
+
const sheet = useRef(null);
|
|
18
|
+
const [width, setWidth] = useState(0);
|
|
19
|
+
const [loaded, setLoaded] = useState();
|
|
20
|
+
const { attempt, error, fail, retry } = useAttempt(onError);
|
|
21
|
+
const [fetched, setFetched] = useState({});
|
|
22
|
+
const [zoom, setZoom] = useState(1);
|
|
23
|
+
const [shown, setShown] = useState(1);
|
|
24
|
+
const [said, setSaid] = useState('');
|
|
25
|
+
const [goal, setGoal] = useState();
|
|
26
|
+
const reached = useRef();
|
|
27
|
+
const wanted = useRef();
|
|
28
|
+
const place = useRef();
|
|
29
|
+
// Where the view stood when `place` was last set; any scroll away is a person's.
|
|
30
|
+
const scrolledTo = useRef();
|
|
31
|
+
const failOpen = (error) => loaded?.live() && fail(error);
|
|
32
|
+
// Callers pass new objects each render, so effects key on their contents.
|
|
33
|
+
const file = 'url' in source ? source.url : source.data;
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const lease = open(source);
|
|
36
|
+
let live = true;
|
|
37
|
+
Promise.all([lease.document, lease.sha256])
|
|
38
|
+
.then(async ([document, sha256]) => {
|
|
39
|
+
const [first, labels] = await Promise.all([
|
|
40
|
+
document.getPage(1),
|
|
41
|
+
document.getPageLabels(),
|
|
42
|
+
]);
|
|
43
|
+
if (!live)
|
|
44
|
+
return;
|
|
45
|
+
setFetched({ 1: first });
|
|
46
|
+
setLoaded({ document, sha256, labels, live: () => live });
|
|
47
|
+
})
|
|
48
|
+
.catch((error) => live && fail(error));
|
|
49
|
+
return () => {
|
|
50
|
+
live = false;
|
|
51
|
+
lease.release();
|
|
52
|
+
place.current = undefined;
|
|
53
|
+
setLoaded(undefined);
|
|
54
|
+
setFetched({});
|
|
55
|
+
};
|
|
56
|
+
}, [file, source.sha256, attempt]);
|
|
57
|
+
// Page 1 comes with the document; the rest are fetched as they near the view.
|
|
58
|
+
const fetch = useMemo(() => {
|
|
59
|
+
if (!loaded)
|
|
60
|
+
return;
|
|
61
|
+
const asked = new Set([1]);
|
|
62
|
+
return (n) => {
|
|
63
|
+
if (asked.has(n))
|
|
64
|
+
return;
|
|
65
|
+
asked.add(n);
|
|
66
|
+
loaded.document
|
|
67
|
+
.getPage(n)
|
|
68
|
+
.then((page) => loaded.live() && setFetched((all) => ({ ...all, [n]: page })), failOpen);
|
|
69
|
+
};
|
|
70
|
+
}, [loaded]);
|
|
71
|
+
const drawn = useDrawn(marks, loaded, onResolve, fail);
|
|
72
|
+
const now = useRef({ zoom, scale: 0 });
|
|
73
|
+
// A pinch or ctrl+wheel in progress: the pages wear a transform until the
|
|
74
|
+
// zoom it ends at is drawn, so no rect is read while it is set.
|
|
75
|
+
const gesture = useRef();
|
|
76
|
+
// A new place supersedes a jump still waiting for its page.
|
|
77
|
+
const capture = (at) => {
|
|
78
|
+
if (!box || !now.current.scale)
|
|
79
|
+
return;
|
|
80
|
+
place.current = placeOf(box, now.current.scale, at);
|
|
81
|
+
scrolledTo.current = { top: box.scrollTop, left: box.scrollLeft };
|
|
82
|
+
reached.current = wanted.current;
|
|
83
|
+
};
|
|
84
|
+
// A scroll the reader did not make sets the place, even one whose event has
|
|
85
|
+
// yet to fire, so it is read here, before this render changes any size.
|
|
86
|
+
const follow = () => {
|
|
87
|
+
const to = scrolledTo.current;
|
|
88
|
+
if (!box || !to || gesture.current)
|
|
89
|
+
return;
|
|
90
|
+
if (Math.abs(box.scrollTop - to.top) > 1 ||
|
|
91
|
+
Math.abs(box.scrollLeft - to.left) > 1)
|
|
92
|
+
capture();
|
|
93
|
+
};
|
|
94
|
+
follow();
|
|
95
|
+
const first = fetched[1];
|
|
96
|
+
const base = useMemo(() => first?.getViewport({ scale: 1 }), [first]);
|
|
97
|
+
const scale = base && width ? (zoom * (width - 2 * gap)) / base.width : 0;
|
|
98
|
+
now.current = { zoom, scale };
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (!box)
|
|
101
|
+
return;
|
|
102
|
+
// Only the width sets the scale, so a scrollbar's coming or going is no
|
|
103
|
+
// reason to measure the place afresh.
|
|
104
|
+
let wide = 0;
|
|
105
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
106
|
+
const { width } = entry.contentRect;
|
|
107
|
+
if (width === wide)
|
|
108
|
+
return;
|
|
109
|
+
wide = width;
|
|
110
|
+
capture();
|
|
111
|
+
setWidth(width);
|
|
112
|
+
});
|
|
113
|
+
observer.observe(box);
|
|
114
|
+
return () => observer.disconnect();
|
|
115
|
+
}, [box]);
|
|
116
|
+
const go = (page, mark) => {
|
|
117
|
+
if (!loaded || !fetch)
|
|
118
|
+
return;
|
|
119
|
+
const n = Math.min(loaded.document.numPages, Math.max(1, page));
|
|
120
|
+
fetch(n);
|
|
121
|
+
wanted.current = { page: n, mark };
|
|
122
|
+
setGoal(wanted.current);
|
|
123
|
+
};
|
|
124
|
+
// A mark's page is known once the marks resolve.
|
|
125
|
+
const mark = target && 'mark' in target ? target.mark : undefined;
|
|
126
|
+
const to = target && 'page' in target
|
|
127
|
+
? target.page
|
|
128
|
+
: firstPage(drawn?.find(({ id }) => id === mark));
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (loaded && to)
|
|
131
|
+
go(to, mark);
|
|
132
|
+
}, [loaded, mark, to, jump]);
|
|
133
|
+
// Before paint, after every change of size: to a goal, once its mark's page
|
|
134
|
+
// is fetched, else back to the reader's place.
|
|
135
|
+
useLayoutEffect(() => {
|
|
136
|
+
if (!box || !scale || (gesture.current && !gesture.current.done))
|
|
137
|
+
return;
|
|
138
|
+
const page = goal && fetched[goal.page];
|
|
139
|
+
if (goal && goal !== reached.current && (page || !goal.mark)) {
|
|
140
|
+
reached.current = goal;
|
|
141
|
+
place.current = aim(box, goal, scale, drawn ?? [], page);
|
|
142
|
+
}
|
|
143
|
+
if (gesture.current) {
|
|
144
|
+
sheet.current.style.transform = '';
|
|
145
|
+
gesture.current = undefined;
|
|
146
|
+
}
|
|
147
|
+
if (place.current)
|
|
148
|
+
restore(box, place.current, scale);
|
|
149
|
+
place.current ??= placeOf(box, scale);
|
|
150
|
+
scrolledTo.current = { top: box.scrollTop, left: box.scrollLeft };
|
|
151
|
+
setShown(pageAt(box, box.clientHeight / 2));
|
|
152
|
+
}, [box, scale, fetched, goal]);
|
|
153
|
+
const scrolled = () => {
|
|
154
|
+
if (!box || !scale || gesture.current)
|
|
155
|
+
return;
|
|
156
|
+
follow();
|
|
157
|
+
setShown(pageAt(box, box.clientHeight / 2));
|
|
158
|
+
};
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (!loaded)
|
|
161
|
+
return;
|
|
162
|
+
onPageChange?.({ index: shown, label: loaded.labels?.[shown - 1] });
|
|
163
|
+
const settled = setTimeout(() => setSaid(`Page ${shown} of ${loaded.document.numPages}`), 500);
|
|
164
|
+
return () => clearTimeout(settled);
|
|
165
|
+
}, [shown, loaded]);
|
|
166
|
+
const zoomTo = (to) => {
|
|
167
|
+
capture();
|
|
168
|
+
setZoom(within(to));
|
|
169
|
+
};
|
|
170
|
+
// Pinch and ctrl+wheel scale the pages by a transform, from the view's top,
|
|
171
|
+
// then zoom once the gesture ends.
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (!box)
|
|
174
|
+
return;
|
|
175
|
+
let span = 0;
|
|
176
|
+
let idle;
|
|
177
|
+
const preview = (by, at) => {
|
|
178
|
+
if (gesture.current?.done)
|
|
179
|
+
return;
|
|
180
|
+
if (!gesture.current)
|
|
181
|
+
capture(at);
|
|
182
|
+
const { zoom } = now.current;
|
|
183
|
+
const ratio = within(zoom * by) / zoom;
|
|
184
|
+
gesture.current = { ratio, at };
|
|
185
|
+
const pages = sheet.current;
|
|
186
|
+
pages.style.transformOrigin = `${box.scrollLeft + at}px ${box.scrollTop}px`;
|
|
187
|
+
pages.style.transform = `scale(${ratio})`;
|
|
188
|
+
};
|
|
189
|
+
// The layout effect drawing the new zoom takes the transform off.
|
|
190
|
+
const commit = () => {
|
|
191
|
+
const { zoom } = now.current;
|
|
192
|
+
const to = within(zoom * gesture.current.ratio);
|
|
193
|
+
if (to === zoom) {
|
|
194
|
+
sheet.current.style.transform = '';
|
|
195
|
+
gesture.current = undefined;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
gesture.current.done = true;
|
|
199
|
+
setZoom(to);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const left = (x) => x - box.getBoundingClientRect().left;
|
|
203
|
+
const wheel = (event) => {
|
|
204
|
+
if (!event.ctrlKey || !sheet.current)
|
|
205
|
+
return;
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
preview((gesture.current?.ratio ?? 1) * Math.exp(-event.deltaY / 200), left(event.clientX));
|
|
208
|
+
clearTimeout(idle);
|
|
209
|
+
idle = setTimeout(commit, 200);
|
|
210
|
+
};
|
|
211
|
+
const touch = (event) => {
|
|
212
|
+
const [a, b] = [event.touches[0], event.touches[1]];
|
|
213
|
+
if (a && b && !event.touches[2] && sheet.current) {
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
const apart = Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY);
|
|
216
|
+
if (span)
|
|
217
|
+
preview(apart / span, left((a.clientX + b.clientX) / 2));
|
|
218
|
+
else
|
|
219
|
+
span = apart;
|
|
220
|
+
}
|
|
221
|
+
else if (span) {
|
|
222
|
+
span = 0;
|
|
223
|
+
commit();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const touches = ['touchstart', 'touchmove', 'touchend', 'touchcancel'];
|
|
227
|
+
box.addEventListener('wheel', wheel, { passive: false });
|
|
228
|
+
for (const type of touches)
|
|
229
|
+
box.addEventListener(type, touch, { passive: false });
|
|
230
|
+
return () => {
|
|
231
|
+
clearTimeout(idle);
|
|
232
|
+
box.removeEventListener('wheel', wheel);
|
|
233
|
+
for (const type of touches)
|
|
234
|
+
box.removeEventListener(type, touch);
|
|
235
|
+
};
|
|
236
|
+
}, [box]);
|
|
237
|
+
const pages = loaded?.document.numPages ?? 0;
|
|
238
|
+
return (_jsx("div", { className: cn('mc-pdf-reader', className), "aria-busy": !loaded && !error, children: error ? (_jsx(Failed, { onRetry: retry })) : (_jsxs(_Fragment, { children: [loaded && (_jsx(Toolbar, { page: shown, pages: pages, zoom: zoom, onPage: go, onZoom: zoomTo })), _jsx("div", { ref: setBox, className: "mc-pdf-scroll", role: "region", "aria-label": "Document", tabIndex: 0, onScroll: scrolled, children: box && base && scale > 0 && fetch && (_jsx("div", { ref: sheet, className: "mc-pdf-pages", style: { padding: gap, gap }, children: Array.from({ length: pages }, (_, i) => (_jsx(Slot, { page: i + 1, fetched: fetched[i + 1], base: base, scale: scale, fetch: fetch, root: box, name: pageName(i + 1, loaded.labels?.[i]), marks: drawn ?? [], current: current, onMarkActivate: onMarkActivate, onPageClick: onPageClick, onError: failOpen }, i))) })) }), _jsx("div", { className: "mc-pdf-said", "aria-live": "polite", children: said })] })) }));
|
|
239
|
+
}
|
|
240
|
+
const firstPage = (mark) => {
|
|
241
|
+
const pages = mark && quadsOf(mark.anchor).map(({ page }) => page);
|
|
242
|
+
return pages?.length ? Math.min(...pages) : undefined;
|
|
243
|
+
};
|
|
244
|
+
/** Where the view goes for `goal`: a mark's centre to the view's, once its
|
|
245
|
+
* page is fetched, else the page's top to the view's top. */
|
|
246
|
+
function aim(box, { page: n, mark: id }, scale, marks, page) {
|
|
247
|
+
const mark = marks.find((mark) => mark.id === id);
|
|
248
|
+
if (!mark || !page)
|
|
249
|
+
return { page: n, x: 0, y: 0, at: 0, scale };
|
|
250
|
+
const viewport = page.getViewport({ scale });
|
|
251
|
+
const points = quadsOn(mark.anchor, n).flatMap((quad) => toView(viewport, quad));
|
|
252
|
+
const middle = (values) => (Math.min(...values) + Math.max(...values)) / 2;
|
|
253
|
+
return {
|
|
254
|
+
page: n,
|
|
255
|
+
x: middle(points.map(([x]) => x)),
|
|
256
|
+
y: middle(points.map(([, y]) => y)) - box.clientHeight / 2,
|
|
257
|
+
at: box.clientWidth / 2,
|
|
258
|
+
scale,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/** One page: a placeholder at page 1's size until it nears the view, then the
|
|
262
|
+
* page itself. */
|
|
263
|
+
function Slot({ page, fetched, base, scale, fetch, root, ...shown }) {
|
|
264
|
+
const slot = useRef(null);
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
if (!fetched)
|
|
267
|
+
return watch(slot.current, (near) => near && fetch(page), root);
|
|
268
|
+
}, [fetched, fetch, root, page]);
|
|
269
|
+
const view = useMemo(() => {
|
|
270
|
+
if (!fetched)
|
|
271
|
+
return;
|
|
272
|
+
const viewport = fetched.getViewport({ scale });
|
|
273
|
+
return {
|
|
274
|
+
page: fetched,
|
|
275
|
+
viewport,
|
|
276
|
+
width: viewport.width,
|
|
277
|
+
height: viewport.height,
|
|
278
|
+
};
|
|
279
|
+
}, [fetched, scale]);
|
|
280
|
+
const size = view ?? {
|
|
281
|
+
width: base.width * scale,
|
|
282
|
+
height: base.height * scale,
|
|
283
|
+
};
|
|
284
|
+
return (_jsx("div", { ref: slot, className: "mc-pdf-slot", style: { width: size.width, height: size.height }, children: view && _jsx(PageView, { view: view, cropped: false, root: root, ...shown }) }));
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=PdfReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PdfReader.js","sourceRoot":"","sources":["../../src/pdf/PdfReader.tsx"],"names":[],"mappings":";AACA,OAAO,EAEL,SAAS,EACT,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEnC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAc,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAyB9C,uCAAuC;AACvC,MAAM,GAAG,GAAG,CAAC,CAAA;AAEb,0E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dist/pdf/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { PdfAnchor } from './anchor.js';
|
|
|
2
2
|
export { quadFromRect, quadsFromFractions, type PdfAnchor } from './anchor.js';
|
|
3
3
|
export { configurePdf } from './assets.js';
|
|
4
4
|
export { PdfPage } from './PdfPage.js';
|
|
5
|
+
export { PdfReader } from './PdfReader.js';
|
|
5
6
|
export type PdfSource = {
|
|
6
7
|
url: string;
|
|
7
8
|
sha256: string;
|
package/dist/pdf/index.js
CHANGED
package/dist/pdf/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAkB,MAAM,aAAa,CAAA;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAkB,MAAM,aAAa,CAAA;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/pdf/page.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PageViewport, PDFPageProxy } from 'pdfjs-dist';
|
|
2
|
-
import type { PdfMark, PdfPoint } from './index.js';
|
|
1
|
+
import type { PageViewport, PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
|
|
2
|
+
import type { PdfError, PdfMark, PdfPoint, PdfResolution } from './index.js';
|
|
3
3
|
/** What a page shows: `viewport` drawn into `width` by `height` CSS px. */
|
|
4
4
|
export type View = {
|
|
5
5
|
page: PDFPageProxy;
|
|
@@ -7,7 +7,24 @@ export type View = {
|
|
|
7
7
|
width: number;
|
|
8
8
|
height: number;
|
|
9
9
|
};
|
|
10
|
-
export declare
|
|
10
|
+
export declare const pageName: (page: number, printed?: string) => string;
|
|
11
|
+
export declare const Failed: ({ onRetry }: {
|
|
12
|
+
onRetry: () => void;
|
|
13
|
+
}) => import("react").JSX.Element;
|
|
14
|
+
/** The error that ended the latest attempt to load, and the retry that starts the next. */
|
|
15
|
+
export declare function useAttempt(onError?: (error: PdfError) => void): {
|
|
16
|
+
attempt: number;
|
|
17
|
+
error: PdfError | undefined;
|
|
18
|
+
fail: (error: unknown) => void;
|
|
19
|
+
retry: () => void;
|
|
20
|
+
};
|
|
21
|
+
/** The marks to draw on `loaded`, each told to `onResolve` and carrying its
|
|
22
|
+
* fresh anchor where reanchored; undefined until they resolve. */
|
|
23
|
+
export declare function useDrawn(marks: PdfMark[], loaded: {
|
|
24
|
+
document: PDFDocumentProxy;
|
|
25
|
+
sha256: string;
|
|
26
|
+
} | undefined, onResolve: ((resolutions: PdfResolution[]) => void) | undefined, onError: (error: unknown) => void): PdfMark[] | undefined;
|
|
27
|
+
export declare function PageView({ view, cropped, name, marks, current, onMarkActivate, onPageClick, onError, root, }: {
|
|
11
28
|
view?: View;
|
|
12
29
|
cropped: boolean;
|
|
13
30
|
name: string;
|
|
@@ -16,4 +33,6 @@ export declare function PageView({ view, cropped, name, marks, current, onMarkAc
|
|
|
16
33
|
onMarkActivate?: (id: string) => void;
|
|
17
34
|
onPageClick?: (point: PdfPoint) => void;
|
|
18
35
|
onError: (error: unknown) => void;
|
|
36
|
+
/** The box the page scrolls in; absent, the window. */
|
|
37
|
+
root?: Element;
|
|
19
38
|
}): import("react").JSX.Element;
|
package/dist/pdf/page.js
CHANGED
|
@@ -1,16 +1,70 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Button } from '../tools/Button.js';
|
|
4
|
+
import { Notice } from '../tools/Notice.js';
|
|
5
|
+
import { typed } from './document.js';
|
|
3
6
|
import { hit, Marks, place } from './marks.js';
|
|
4
7
|
import { enqueue, watch } from './queue.js';
|
|
8
|
+
import { resolve } from './resolve.js';
|
|
9
|
+
export const pageName = (page, printed) => printed && printed !== String(page)
|
|
10
|
+
? `Page ${page}, printed page ${printed}`
|
|
11
|
+
: `Page ${page}`;
|
|
12
|
+
export const Failed = ({ onRetry }) => (_jsx(Notice, { title: "This PDF could not be shown.", children: _jsx(Button, { variant: "secondary", onClick: onRetry, children: "Retry" }) }));
|
|
13
|
+
/** The error that ended the latest attempt to load, and the retry that starts the next. */
|
|
14
|
+
export function useAttempt(onError) {
|
|
15
|
+
const [attempt, setAttempt] = useState(0);
|
|
16
|
+
const [error, setError] = useState();
|
|
17
|
+
const fail = (error) => {
|
|
18
|
+
const failure = typed(error);
|
|
19
|
+
setError(failure);
|
|
20
|
+
onError?.(failure);
|
|
21
|
+
};
|
|
22
|
+
const retry = () => {
|
|
23
|
+
setError(undefined);
|
|
24
|
+
setAttempt((n) => n + 1);
|
|
25
|
+
};
|
|
26
|
+
return { attempt, error, fail, retry };
|
|
27
|
+
}
|
|
28
|
+
/** The marks to draw on `loaded`, each told to `onResolve` and carrying its
|
|
29
|
+
* fresh anchor where reanchored; undefined until they resolve. */
|
|
30
|
+
export function useDrawn(marks, loaded, onResolve, onError) {
|
|
31
|
+
const [resolved, setResolved] = useState();
|
|
32
|
+
const resolutions = loaded && resolved?.[0] === loaded ? resolved[1] : undefined;
|
|
33
|
+
const anchors = JSON.stringify(marks.map(({ id, anchor }) => [id, anchor]));
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!loaded)
|
|
36
|
+
return;
|
|
37
|
+
let live = true;
|
|
38
|
+
resolve(marks, loaded.document, loaded.sha256)
|
|
39
|
+
.then((resolutions) => live && setResolved([loaded, resolutions]))
|
|
40
|
+
.catch((error) => live && onError(error));
|
|
41
|
+
return () => {
|
|
42
|
+
live = false;
|
|
43
|
+
};
|
|
44
|
+
}, [loaded, anchors]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (resolutions)
|
|
47
|
+
onResolve?.(resolutions);
|
|
48
|
+
}, [JSON.stringify(resolutions)]);
|
|
49
|
+
return useMemo(() => {
|
|
50
|
+
if (!resolutions)
|
|
51
|
+
return;
|
|
52
|
+
const placed = new Map(resolutions.map((r) => [r.id, r]));
|
|
53
|
+
return marks.flatMap((mark) => {
|
|
54
|
+
const { status, anchor = mark.anchor } = placed.get(mark.id) ?? {};
|
|
55
|
+
return status && status !== 'orphan' ? [{ ...mark, anchor }] : [];
|
|
56
|
+
});
|
|
57
|
+
}, [marks, resolutions]);
|
|
58
|
+
}
|
|
5
59
|
/** The iOS limit on one canvas; past it a page renders softer. */
|
|
6
60
|
const maxPixels = 16_777_216;
|
|
7
|
-
export function PageView({ view, cropped, name, marks, current, onMarkActivate, onPageClick, onError, }) {
|
|
61
|
+
export function PageView({ view, cropped, name, marks, current, onMarkActivate, onPageClick, onError, root, }) {
|
|
8
62
|
const frame = useRef(null);
|
|
9
63
|
const canvas = useRef(null);
|
|
10
64
|
const text = useRef(null);
|
|
11
65
|
const [near, setNear] = useState(false);
|
|
12
66
|
const placed = useMemo(() => (view ? place(marks, view.page.pageNumber, view.viewport) : []), [marks, view]);
|
|
13
|
-
useEffect(() => watch(frame.current, setNear), []);
|
|
67
|
+
useEffect(() => watch(frame.current, setNear, root), [root]);
|
|
14
68
|
useEffect(() => {
|
|
15
69
|
if (!near || !view)
|
|
16
70
|
return;
|
|
@@ -18,8 +72,8 @@ export function PageView({ view, cropped, name, marks, current, onMarkActivate,
|
|
|
18
72
|
return enqueue(frame.current, (signal) => draw(view, canvas.current, layer, signal).catch((error) => {
|
|
19
73
|
if (!signal.aborted)
|
|
20
74
|
onError(error);
|
|
21
|
-
}));
|
|
22
|
-
}, [near, view, cropped]);
|
|
75
|
+
}), root);
|
|
76
|
+
}, [near, view, cropped, root]);
|
|
23
77
|
useEffect(() => {
|
|
24
78
|
if (near)
|
|
25
79
|
return;
|
package/dist/pdf/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/pdf/page.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAmB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/pdf/page.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAmB,MAAM,OAAO,CAAA;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAUtC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,OAAgB,EAAE,EAAE,CACzD,OAAO,IAAI,OAAO,KAAK,MAAM,CAAC,IAAI,CAAC;IACjC,CAAC,CAAC,QAAQ,IAAI,kBAAkB,OAAO,EAAE;IACzC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAA;AAEpB,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAE,OAAO,EAA2B,EAAE,EAAE,CAAC,CAC9D,KAAC,MAAM,IAAC,KAAK,EAAC,8BAA8B,YAC1C,KAAC,MAAM,IAAC,OAAO,EAAC,WAAW,EAAC,OAAO,EAAE,OAAO,sBAEnC,GACF,CACV,CA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C,iBAAiB,EAAE;gBAC3C,SAAS,EAAE,KAAK;gBAChB,QAAQ;aACT,CAAC,CAAA;YACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;YACtD,MAAM,KAAK,CAAC,MAAM,EAAE,CAAA;QACtB,CAAC;QACD,IAAI,MAAM,CAAC,OAAO;YAAE,OAAM;QAC1B,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;QAC3B,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QAC7B,MAAM,CAAC,UAAU,CAAC,IAAI,CAAE,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QAChD,IAAI,KAAK;YAAE,IAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IACzC,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,KAAK,GAAG,CAAC,CAAA;IAClB,CAAC;AACH,CAAC"}
|
package/dist/pdf/queue.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** Runs `draw` in its turn, nearest the viewport first. Returns its cancel. */
|
|
2
|
-
export declare function enqueue(element: Element, draw: (signal: AbortSignal) => Promise<void
|
|
3
|
-
/** Calls `set(true)` within one screen of
|
|
4
|
-
export declare function watch(element: Element, set: (near: boolean) => void): () => void;
|
|
2
|
+
export declare function enqueue(element: Element, draw: (signal: AbortSignal) => Promise<void>, root?: Element): () => void;
|
|
3
|
+
/** Calls `set(true)` within one screen of `root`, `set(false)` beyond three. */
|
|
4
|
+
export declare function watch(element: Element, set: (near: boolean) => void, root?: Element): () => void;
|
package/dist/pdf/queue.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// One render queue and one pair of observers per
|
|
1
|
+
// One render queue per window, and one pair of observers per scroll root,
|
|
2
|
+
// shared by every page.
|
|
2
3
|
const pending = new Set();
|
|
3
4
|
let running = 0;
|
|
4
5
|
/** Runs `draw` in its turn, nearest the viewport first. Returns its cancel. */
|
|
5
|
-
export function enqueue(element, draw) {
|
|
6
|
+
export function enqueue(element, draw, root) {
|
|
6
7
|
const aborted = new AbortController();
|
|
7
|
-
const job = { element, run: () => draw(aborted.signal) };
|
|
8
|
+
const job = { element, root, run: () => draw(aborted.signal) };
|
|
8
9
|
pending.add(job);
|
|
9
10
|
pump();
|
|
10
11
|
return () => {
|
|
@@ -14,7 +15,7 @@ export function enqueue(element, draw) {
|
|
|
14
15
|
}
|
|
15
16
|
function pump() {
|
|
16
17
|
while (running < 2 && pending.size) {
|
|
17
|
-
const job = [...pending].reduce((a, b) => distance(b
|
|
18
|
+
const job = [...pending].reduce((a, b) => distance(b) < distance(a) ? b : a);
|
|
18
19
|
pending.delete(job);
|
|
19
20
|
running++;
|
|
20
21
|
void job.run().finally(() => {
|
|
@@ -23,31 +24,39 @@ function pump() {
|
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
function distance(element) {
|
|
27
|
+
function distance({ element, root }) {
|
|
27
28
|
const { top, bottom } = element.getBoundingClientRect();
|
|
28
|
-
|
|
29
|
+
const view = root?.getBoundingClientRect() ?? { top: 0, bottom: innerHeight };
|
|
30
|
+
return Math.max(0, top - view.bottom, view.top - bottom);
|
|
29
31
|
}
|
|
30
32
|
const watched = new Map();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const observers = new WeakMap();
|
|
34
|
+
let listening = false;
|
|
35
|
+
/** Calls `set(true)` within one screen of `root`, `set(false)` beyond three. */
|
|
36
|
+
export function watch(element, set, root) {
|
|
37
|
+
if (!listening) {
|
|
38
|
+
listening = true;
|
|
36
39
|
// Released pages render again to print.
|
|
37
40
|
addEventListener('beforeprint', () => watched.forEach((set) => set(true)));
|
|
38
41
|
}
|
|
42
|
+
const key = root ?? document;
|
|
43
|
+
const pair = observers.get(key) ?? [
|
|
44
|
+
observer('100%', true, root),
|
|
45
|
+
observer('300%', false, root),
|
|
46
|
+
];
|
|
47
|
+
observers.set(key, pair);
|
|
39
48
|
watched.set(element, set);
|
|
40
|
-
|
|
49
|
+
pair.forEach((o) => o.observe(element));
|
|
41
50
|
return () => {
|
|
42
51
|
watched.delete(element);
|
|
43
|
-
|
|
52
|
+
pair.forEach((o) => o.unobserve(element));
|
|
44
53
|
};
|
|
45
54
|
}
|
|
46
|
-
function observer(margin, near) {
|
|
55
|
+
function observer(margin, near, root) {
|
|
47
56
|
return new IntersectionObserver((entries) => {
|
|
48
57
|
for (const { target, isIntersecting } of entries)
|
|
49
58
|
if (isIntersecting === near)
|
|
50
59
|
watched.get(target)?.(near);
|
|
51
|
-
}, { rootMargin: `${margin} 0px` });
|
|
60
|
+
}, { root, rootMargin: `${margin} 0px` });
|
|
52
61
|
}
|
|
53
62
|
//# sourceMappingURL=queue.js.map
|
package/dist/pdf/queue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/pdf/queue.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/pdf/queue.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wBAAwB;AAIxB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAO,CAAA;AAC9B,IAAI,OAAO,GAAG,CAAC,CAAA;AAEf,+EAA+E;AAC/E,MAAM,UAAU,OAAO,CACrB,OAAgB,EAChB,IAA4C,EAC5C,IAAc;IAEd,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAA;IACrC,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAA;IAC9D,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAChB,IAAI,EAAE,CAAA;IACN,OAA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AC5D,CAAC,EACD,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,EAAE,CACtC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The view's top `y` CSS px below page `page`'s top, and its point `at` px from
|
|
2
|
+
* the left `x` px right of that page's left, measured at `scale`. */
|
|
3
|
+
export type Place = {
|
|
4
|
+
page: number;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
at: number;
|
|
8
|
+
scale: number;
|
|
9
|
+
};
|
|
10
|
+
/** The 1-based page `y` px below the view's top: the last that starts above it. */
|
|
11
|
+
export declare function pageAt(box: Element, y: number): number;
|
|
12
|
+
export declare function placeOf(box: Element, scale: number, at?: number): Place;
|
|
13
|
+
export declare function restore(box: Element, place: Place, scale: number): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The reader's place, kept as a point on a page rather than a scroll offset, so
|
|
2
|
+
// it holds while pages above it change size.
|
|
3
|
+
const pages = (box) => box.firstElementChild.children;
|
|
4
|
+
/** A page's top left in the box's scrolled content. */
|
|
5
|
+
function corner(box, page) {
|
|
6
|
+
const view = box.getBoundingClientRect();
|
|
7
|
+
const { top, left } = pages(box)[page - 1].getBoundingClientRect();
|
|
8
|
+
return {
|
|
9
|
+
top: top - view.top - box.clientTop + box.scrollTop,
|
|
10
|
+
left: left - view.left - box.clientLeft + box.scrollLeft,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** The 1-based page `y` px below the view's top: the last that starts above it. */
|
|
14
|
+
export function pageAt(box, y) {
|
|
15
|
+
const at = box.scrollTop + y;
|
|
16
|
+
let [low, high] = [1, pages(box).length];
|
|
17
|
+
while (low < high) {
|
|
18
|
+
const mid = (low + high + 1) >> 1;
|
|
19
|
+
if (corner(box, mid).top <= at)
|
|
20
|
+
low = mid;
|
|
21
|
+
else
|
|
22
|
+
high = mid - 1;
|
|
23
|
+
}
|
|
24
|
+
return low;
|
|
25
|
+
}
|
|
26
|
+
export function placeOf(box, scale, at = box.clientWidth / 2) {
|
|
27
|
+
const page = pageAt(box, 0);
|
|
28
|
+
const { top, left } = corner(box, page);
|
|
29
|
+
return {
|
|
30
|
+
page,
|
|
31
|
+
x: box.scrollLeft + at - left,
|
|
32
|
+
y: box.scrollTop - top,
|
|
33
|
+
at,
|
|
34
|
+
scale,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// A scroll that moves nothing is skipped, since some touch browsers end a
|
|
38
|
+
// fling at any scroll a page makes.
|
|
39
|
+
export function restore(box, place, scale) {
|
|
40
|
+
const { top, left } = corner(box, place.page);
|
|
41
|
+
const ratio = scale / place.scale;
|
|
42
|
+
const x = clamp(left + place.x * ratio - place.at, box.scrollWidth - box.clientWidth);
|
|
43
|
+
const y = clamp(top + place.y * ratio, box.scrollHeight - box.clientHeight);
|
|
44
|
+
if (Math.abs(x - box.scrollLeft) >= 0.5 || Math.abs(y - box.scrollTop) >= 0.5)
|
|
45
|
+
box.scrollTo(x, y);
|
|
46
|
+
}
|
|
47
|
+
const clamp = (n, most) => Math.min(Math.max(0, most), Math.max(0, n));
|
|
48
|
+
//# sourceMappingURL=scroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../src/pdf/scroll.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,6CAA6C;AAY7C,MAAM,KAAK,GAAG,CAAC,GAAY,EAAE,EAAE,CAAC,GAAG,CAAC,iBAAkB,CAAC,QAAQ,CAAA;AAE/D,uDAAuD;AACvD,SAAS,MAAM,CAAC,GAAY,EAAE,IAAY;IACxC,MAAM,IAAI,GAAG,GAAG,CAAC,qBAAqB,EAAE,CAAA;IACxC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAE,CAAC,qBAAqB,EAAE,CAAA;IACnE,OAAO;QACL,GAAG,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AU,OAAO,CAAC,GAAY,EAAE,KAAY,EAAE,KAAa;IAC/D,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;IACjC,MAAM,CAAC,GAAG,KAAK,CACb,IAAI,GAAG,KAAK,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC,EAAE,EACjC,GAAG,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,CAClC,CAAA;IACD,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC,CAAA;IAC3E,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,GAAG;QAC3E,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACtB,CAAC;AAED,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,IAAY,EAAE,EAAE,CACxC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const within: (zoom: number) => number;
|
|
2
|
+
export declare function Toolbar({ page, pages, zoom, onPage, onZoom, }: {
|
|
3
|
+
page: number;
|
|
4
|
+
pages: number;
|
|
5
|
+
zoom: number;
|
|
6
|
+
onPage: (page: number) => void;
|
|
7
|
+
onZoom: (zoom: number) => void;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Button } from '../tools/Button.js';
|
|
4
|
+
import { Input } from '../tools/form.js';
|
|
5
|
+
/** Zoom, as a multiple of fit width. */
|
|
6
|
+
const zooms = [0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4];
|
|
7
|
+
export const within = (zoom) => Math.min(zooms.at(-1), Math.max(zooms[0], zoom));
|
|
8
|
+
export function Toolbar({ page, pages, zoom, onPage, onZoom, }) {
|
|
9
|
+
const [typed, setTyped] = useState();
|
|
10
|
+
const go = () => {
|
|
11
|
+
const asked = Math.round(Number(typed));
|
|
12
|
+
if (asked)
|
|
13
|
+
onPage(asked);
|
|
14
|
+
setTyped(undefined);
|
|
15
|
+
};
|
|
16
|
+
const button = (label, text, onClick) => (_jsx(Button, { variant: "secondary", "aria-label": label, onClick: onClick, children: text }));
|
|
17
|
+
return (_jsxs("div", { className: "mc-pdf-toolbar", children: [button('Previous page', '‹', () => onPage(page - 1)), button('Next page', '›', () => onPage(page + 1)), _jsxs("form", { onSubmit: (event) => {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
go();
|
|
20
|
+
}, children: [_jsx(Input, { "aria-label": "Page", inputMode: "numeric", value: typed ?? page, onChange: (event) => setTyped(event.target.value), onBlur: go }), ' ', "of ", pages] }), button('Zoom out', '−', () => onZoom([...zooms].reverse().find((z) => z < zoom - 0.001) ?? zooms[0])), _jsxs("output", { "aria-label": "Zoom", children: [Math.round(zoom * 100), "%"] }), button('Zoom in', '+', () => onZoom(zooms.find((z) => z > zoom + 0.001) ?? zooms.at(-1))), _jsx(Button, { variant: "secondary", onClick: () => onZoom(1), children: "Fit width" })] }));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=toolbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolbar.js","sourceRoot":"","sources":["../../src/pdf/toolbar.tsx"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56 @@
|
|
|
86
86
|
transform: translate(-100%, -100%);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/* The reader: a toolbar over a box that scrolls both ways, so the page
|
|
90
|
+
* around it never does. */
|
|
91
|
+
.mc-pdf-reader {
|
|
92
|
+
display: flex;
|
|
93
|
+
flex-direction: column;
|
|
94
|
+
min-width: 0;
|
|
95
|
+
min-height: 0;
|
|
96
|
+
overflow: hidden;
|
|
97
|
+
}
|
|
98
|
+
.mc-pdf-toolbar {
|
|
99
|
+
display: flex;
|
|
100
|
+
flex-wrap: wrap;
|
|
101
|
+
align-items: center;
|
|
102
|
+
gap: 0.5rem;
|
|
103
|
+
padding: 0.5rem;
|
|
104
|
+
border-bottom: 1px solid var(--mc-hairline);
|
|
105
|
+
}
|
|
106
|
+
.mc-pdf-toolbar .mc-control {
|
|
107
|
+
width: 4em;
|
|
108
|
+
}
|
|
109
|
+
.mc-pdf-scroll {
|
|
110
|
+
flex: 1;
|
|
111
|
+
min-height: 0;
|
|
112
|
+
overflow: auto;
|
|
113
|
+
overflow-anchor: none;
|
|
114
|
+
scrollbar-gutter: stable;
|
|
115
|
+
touch-action: pan-x pan-y;
|
|
116
|
+
background: var(--mc-surface);
|
|
117
|
+
}
|
|
118
|
+
.mc-pdf-pages {
|
|
119
|
+
display: flex;
|
|
120
|
+
flex-direction: column;
|
|
121
|
+
align-items: center;
|
|
122
|
+
box-sizing: border-box;
|
|
123
|
+
width: max-content;
|
|
124
|
+
min-width: 100%;
|
|
125
|
+
}
|
|
126
|
+
.mc-pdf-slot {
|
|
127
|
+
flex: none;
|
|
128
|
+
background: var(--mc-card);
|
|
129
|
+
}
|
|
130
|
+
.mc-pdf-said {
|
|
131
|
+
position: absolute;
|
|
132
|
+
width: 1px;
|
|
133
|
+
height: 1px;
|
|
134
|
+
overflow: hidden;
|
|
135
|
+
clip-path: inset(50%);
|
|
136
|
+
white-space: nowrap;
|
|
137
|
+
}
|
|
138
|
+
|
|
89
139
|
@media (forced-colors: active) {
|
|
90
140
|
.mc-pdf-shape,
|
|
91
141
|
.mc-pdf-fill .mc-pdf-shape {
|