@kibitzo/chess-book-reader 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -2
- package/dist/Library.d.ts +11 -0
- package/dist/Library.js +74 -0
- package/dist/PageView.d.ts +35 -0
- package/dist/PageView.js +80 -0
- package/dist/ReadApp.d.ts +9 -0
- package/dist/ReadApp.js +122 -0
- package/dist/Reader.d.ts +8 -0
- package/dist/Reader.js +117 -0
- package/dist/ReaderBar.d.ts +30 -0
- package/dist/ReaderBar.js +36 -0
- package/dist/SideGrip.d.ts +12 -0
- package/dist/SideGrip.js +66 -0
- package/dist/find.d.ts +51 -0
- package/dist/find.js +278 -0
- package/dist/host.d.ts +90 -0
- package/dist/host.js +66 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/pdf.d.ts +46 -0
- package/dist/pdf.js +130 -0
- package/dist/reader.css +1084 -0
- package/dist/store.d.ts +63 -0
- package/dist/store.js +103 -0
- package/dist/useDiagrams.d.ts +18 -0
- package/dist/useDiagrams.js +146 -0
- package/dist/usePages.d.ts +18 -0
- package/dist/usePages.js +148 -0
- package/package.json +52 -4
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kibitzo/chess-book-reader
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A chess-book reader for the browser, in React: open a PDF, every diagram in it is found and read
|
|
4
|
+
([@scoriiu/fenshot](https://www.npmjs.com/package/@scoriiu/fenshot)), and a click puts the position on a board
|
|
5
|
+
beside the page. The book is read in the browser and kept on the device (IndexedDB); nothing is uploaded.
|
|
6
|
+
|
|
7
|
+
It runs [fenshot.com/read](https://fenshot.com/read/) and [kibitzo.com/read](https://kibitzo.com/read): the
|
|
8
|
+
reader is this package, the board beside the page is each site's own.
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
import { BookReader, englishWords, type ReaderHost } from "@kibitzo/chess-book-reader";
|
|
12
|
+
import "@kibitzo/chess-book-reader/reader.css";
|
|
13
|
+
|
|
14
|
+
const host: ReaderHost = {
|
|
15
|
+
recognizer: createRecognizer({ modelUrl, wasmPaths }), // from @scoriiu/fenshot
|
|
16
|
+
pdf: { workerSrc: "/pdfjs/pdf.worker.min.mjs", assets: "/pdfjs/" }, // pdfjs-dist's worker, wasm/, cmaps/, standard_fonts/, iccs/
|
|
17
|
+
t: englishWords,
|
|
18
|
+
BoardPanel: MyBoard, // ({ picked: { page, diagram }, onClose }) => your board
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
<BookReader host={host} />;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The look follows the `--fsr-*` CSS variables (colours), `--fsr-inset` and `--fsr-z` (where an open book sits),
|
|
25
|
+
and `--fsr-sheet-left` (the board's sheet on narrow screens).
|
|
26
|
+
|
|
27
|
+
MIT.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Book } from "./store";
|
|
2
|
+
export declare function Library({ books, counts, busy, error, onFile, onOpen, onRename, onRemove }: {
|
|
3
|
+
books: Book[];
|
|
4
|
+
counts: Map<string, number>;
|
|
5
|
+
busy: boolean;
|
|
6
|
+
error: string | null;
|
|
7
|
+
onFile(file: File): void;
|
|
8
|
+
onOpen(book: Book): void;
|
|
9
|
+
onRename(book: Book, name: string): void;
|
|
10
|
+
onRemove(book: Book): void;
|
|
11
|
+
}): import("react").JSX.Element;
|
package/dist/Library.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useReaderHost, useT } from "./host";
|
|
4
|
+
import { fileNameOf, sizeText } from "./store";
|
|
5
|
+
/**
|
|
6
|
+
* The reader's first screen: the door for a new book, the books kept on this device as a list, the one opened last
|
|
7
|
+
* first (each row: the first page, the name, how many diagrams, how far the reader got, when he last opened it,
|
|
8
|
+
* and the way back in), and what the reader does.
|
|
9
|
+
*/
|
|
10
|
+
const COVER_ICON = "M5 4.5A1.5 1.5 0 0 1 6.5 3H19v15H6.5A1.5 1.5 0 0 0 5 19.5zM5 19.5A1.5 1.5 0 0 0 6.5 21H19";
|
|
11
|
+
/** When a book was last opened, in the page's language: "today", "yesterday", "3 Dec", "3 Dec 2025". */
|
|
12
|
+
function openedOn(at) {
|
|
13
|
+
const lang = document.documentElement.lang || "en";
|
|
14
|
+
const day = (t) => { const d = new Date(t); return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime(); };
|
|
15
|
+
const ago = Math.round((day(Date.now()) - day(at)) / 86400000);
|
|
16
|
+
if (ago <= 1) {
|
|
17
|
+
const words = new Intl.RelativeTimeFormat(lang, { numeric: "auto" }).format(-ago, "day");
|
|
18
|
+
return words.charAt(0).toLocaleUpperCase(lang) + words.slice(1);
|
|
19
|
+
}
|
|
20
|
+
const sameYear = new Date(at).getFullYear() === new Date().getFullYear();
|
|
21
|
+
return new Intl.DateTimeFormat(lang, { day: "numeric", month: "short", ...(sameYear ? {} : { year: "numeric" }) }).format(at);
|
|
22
|
+
}
|
|
23
|
+
/** Rename and Remove, behind one button: a row shows one action, the one most wanted. */
|
|
24
|
+
function RowMenu({ onRename, onRemove }) {
|
|
25
|
+
const t = useT();
|
|
26
|
+
const [open, setOpen] = useState(false);
|
|
27
|
+
const holder = useRef(null);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!open)
|
|
30
|
+
return;
|
|
31
|
+
const away = (e) => { if (!holder.current?.contains(e.target))
|
|
32
|
+
setOpen(false); };
|
|
33
|
+
const key = (e) => { if (e.key === "Escape")
|
|
34
|
+
setOpen(false); };
|
|
35
|
+
window.addEventListener("pointerdown", away);
|
|
36
|
+
window.addEventListener("keydown", key);
|
|
37
|
+
return () => { window.removeEventListener("pointerdown", away); window.removeEventListener("keydown", key); };
|
|
38
|
+
}, [open]);
|
|
39
|
+
const pick = (run) => () => { setOpen(false); run(); };
|
|
40
|
+
return (_jsxs("div", { className: "lib-menu", ref: holder, children: [_jsx("button", { type: "button", className: "rd-icon", onClick: () => setOpen(!open), "aria-expanded": open, "aria-label": t("readMore"), title: t("readMore"), "data-testid": "read-book-menu", children: _jsxs("svg", { viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: [_jsx("circle", { cx: "5", cy: "12", r: "1.7" }), _jsx("circle", { cx: "12", cy: "12", r: "1.7" }), _jsx("circle", { cx: "19", cy: "12", r: "1.7" })] }) }), open && (_jsxs("ul", { className: "lib-menu-list", role: "menu", children: [_jsx("li", { children: _jsx("button", { type: "button", role: "menuitem", onClick: pick(onRename), "data-testid": "read-rename", children: t("readRename") }) }), _jsx("li", { children: _jsx("button", { type: "button", role: "menuitem", className: "lib-danger", onClick: pick(onRemove), "data-testid": "read-remove", children: t("readRemove") }) })] }))] }));
|
|
41
|
+
}
|
|
42
|
+
function BookRow({ book, diagrams, onOpen, onRename, onRemove }) {
|
|
43
|
+
const t = useT();
|
|
44
|
+
const [naming, setNaming] = useState(false);
|
|
45
|
+
const [name, setName] = useState(book.name);
|
|
46
|
+
const share = book.pages > 1 ? Math.round(((book.page - 1) / (book.pages - 1)) * 100) : 0;
|
|
47
|
+
const save = () => {
|
|
48
|
+
const next = name.trim();
|
|
49
|
+
if (next && next !== book.name)
|
|
50
|
+
onRename(next);
|
|
51
|
+
else
|
|
52
|
+
setName(book.name);
|
|
53
|
+
setNaming(false);
|
|
54
|
+
};
|
|
55
|
+
return (_jsxs("li", { className: "lib-row", "data-testid": "read-book", children: [_jsx("button", { type: "button", className: "lib-cover", onClick: onOpen, "aria-label": book.name, tabIndex: -1, children: book.cover ? _jsx("img", { src: book.cover, alt: "" }) : _jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: _jsx("path", { d: COVER_ICON }) }) }), _jsxs("div", { className: "lib-about", children: [naming ? (_jsx("form", { className: "lib-rename", onSubmit: (e) => { e.preventDefault(); save(); }, children: _jsx("input", { autoFocus: true, value: name, maxLength: 120, onChange: (e) => setName(e.target.value), onBlur: save, onKeyDown: (e) => { if (e.key === "Escape") {
|
|
56
|
+
setName(book.name);
|
|
57
|
+
setNaming(false);
|
|
58
|
+
} }, "aria-label": t("readRename"), "data-testid": "read-rename-input" }) })) : (_jsx("button", { type: "button", className: "lib-name", onClick: onOpen, title: book.renamed ? fileNameOf(book) : book.name, children: book.name })), _jsxs("p", { className: "lib-meta", children: [diagrams > 0 && _jsxs(_Fragment, { children: [_jsx("b", { children: t("readDiagramsShort", { n: diagrams }) }), _jsx("span", { "aria-hidden": true, children: " \u00B7 " })] }), t("readPageOf", { page: book.page, pages: book.pages }), _jsxs("span", { className: "lib-size", children: [_jsx("span", { "aria-hidden": true, children: " \u00B7 " }), sizeText(book.size)] }), _jsxs("span", { className: "lib-when-inline", "aria-hidden": true, children: [" \u00B7 ", openedOn(book.opened)] })] }), _jsx("div", { className: "lib-progress", role: "progressbar", "aria-valuenow": share, "aria-valuemin": 0, "aria-valuemax": 100, children: _jsx("span", { style: { width: `${share}%` } }) })] }), _jsx("time", { className: "lib-when", dateTime: new Date(book.opened).toISOString(), title: new Date(book.opened).toLocaleString(), "data-testid": "read-book-when", children: openedOn(book.opened) }), _jsx("button", { type: "button", className: "rd-btn rd-btn-primary rd-btn-quiet lib-open", onClick: onOpen, "data-testid": "read-continue", children: book.page > 1 ? t("readOpenAt", { page: book.page }) : t("readOpen") }), _jsx(RowMenu, { onRename: () => { setName(book.name); setNaming(true); }, onRemove: () => { if (window.confirm(t("readRemoveAsk")))
|
|
59
|
+
onRemove(); } })] }));
|
|
60
|
+
}
|
|
61
|
+
export function Library({ books, counts, busy, error, onFile, onOpen, onRename, onRemove }) {
|
|
62
|
+
const t = useT();
|
|
63
|
+
const { emptyLibrary } = useReaderHost();
|
|
64
|
+
const input = useRef(null);
|
|
65
|
+
const [over, setOver] = useState(false);
|
|
66
|
+
const points = [
|
|
67
|
+
{ title: "readWhy1", sub: "readWhy1Sub", icon: "M4 6h16M4 12h10M4 18h6M17 15l2 2 3-4" },
|
|
68
|
+
{ title: "readWhy2", sub: "readWhy2Sub", icon: "M5 3h14v14H5zM5 10h14M12 3v14M8 21h8" },
|
|
69
|
+
{ title: "readWhy3", sub: "readWhy3Sub", icon: "M12 3l7 3v5c0 4.5-3 8-7 10-4-2-7-5.5-7-10V6zM9 12l2 2 4-4" },
|
|
70
|
+
];
|
|
71
|
+
return (_jsxs("main", { className: "lib", children: [_jsxs("div", { className: `rd-drop lib-drop ${over ? "rd-drop-active" : ""} ${busy ? "rd-drop-busy" : ""}`, onDragOver: (e) => { e.preventDefault(); setOver(true); }, onDragLeave: () => setOver(false), onDrop: (e) => { e.preventDefault(); setOver(false); const f = e.dataTransfer.files[0]; if (f)
|
|
72
|
+
onFile(f); }, onClick: () => input.current?.click(), "data-testid": "read-drop", children: [busy ? (_jsxs("div", { className: "rd-status", children: [_jsx("div", { className: "rd-spinner" }), t("readOpening")] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "rd-drop-title", children: books.length ? t("readAddBook") : t("readDropTitle") }), _jsxs("button", { type: "button", className: "rd-btn rd-btn-primary lib-choose", onClick: (e) => { e.stopPropagation(); input.current?.click(); }, "data-testid": "read-choose", children: [_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: [_jsx("path", { d: "M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8z" }), _jsx("path", { d: "M14 3v5h5M12 18v-6M9 15l3-3 3 3" })] }), t("readChoose")] }), _jsx("div", { className: "rd-drop-sub", children: t("readDropSub") }), _jsx("div", { className: "rd-drop-hint", children: t("readPrivate") }), error && _jsx("div", { className: "rd-error", children: error })] })), _jsx("input", { ref: input, type: "file", accept: "application/pdf,.pdf", hidden: true, onChange: (e) => { const f = e.target.files?.[0]; if (f)
|
|
73
|
+
onFile(f); e.target.value = ""; } })] }), books.length === 0 && emptyLibrary, books.length > 0 && (_jsxs("section", { className: "lib-section", children: [_jsxs("div", { className: "lib-head", children: [_jsx("h2", { children: t("readShelf") }), _jsx("span", { children: books.length === 1 ? t("readShelfOne") : t("readShelfCount", { n: books.length }) })] }), _jsx("ul", { className: "lib-list", children: books.map((b) => _jsx(BookRow, { book: b, diagrams: counts.get(b.id) ?? 0, onOpen: () => onOpen(b), onRename: (name) => onRename(b, name), onRemove: () => onRemove(b) }, b.id)) })] })), _jsx("ul", { className: "lib-points", children: points.map((point) => (_jsxs("li", { children: [_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: _jsx("path", { d: point.icon }) }), _jsx("p", { className: "lib-point-title", children: t(point.title) }), _jsx("p", { className: "lib-point-sub", children: t(point.sub) })] }, point.title))) })] }));
|
|
74
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Doc } from "./pdf";
|
|
2
|
+
import type { Diagram } from "./store";
|
|
3
|
+
/** A point of a page, in fractions of its width and height. */
|
|
4
|
+
export type Point = {
|
|
5
|
+
page: number;
|
|
6
|
+
fx: number;
|
|
7
|
+
fy: number;
|
|
8
|
+
};
|
|
9
|
+
/** A box on a page, in the same fractions. */
|
|
10
|
+
export type Box = {
|
|
11
|
+
x0: number;
|
|
12
|
+
y0: number;
|
|
13
|
+
x1: number;
|
|
14
|
+
y1: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* One page of the book: its picture when it is near the screen (`live`), the diagrams found on it as buttons, the
|
|
18
|
+
* reader's double-click (or two quick taps) told as a point of the page, and the box he draws around a diagram
|
|
19
|
+
* that was not found (while `selecting`, or with Shift held).
|
|
20
|
+
*/
|
|
21
|
+
export declare const PageView: import("react").NamedExoticComponent<{
|
|
22
|
+
doc: Doc;
|
|
23
|
+
n: number;
|
|
24
|
+
width: number;
|
|
25
|
+
ratio0: number;
|
|
26
|
+
live: boolean;
|
|
27
|
+
found: Diagram[] | undefined;
|
|
28
|
+
picked: Diagram | null;
|
|
29
|
+
busy: Point | null;
|
|
30
|
+
selecting: boolean;
|
|
31
|
+
onPoint(p: Point): void;
|
|
32
|
+
onDiagram(n: number, d: Diagram): void;
|
|
33
|
+
onBox(n: number, box: Box): void;
|
|
34
|
+
holder(n: number, el: HTMLDivElement | null): void;
|
|
35
|
+
}>;
|
package/dist/PageView.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { drawPage, ratioOf } from "./pdf";
|
|
4
|
+
/** A box smaller than this on screen was a slip of the hand, not a diagram. */
|
|
5
|
+
const BOX_MIN = 28;
|
|
6
|
+
/**
|
|
7
|
+
* One page of the book: its picture when it is near the screen (`live`), the diagrams found on it as buttons, the
|
|
8
|
+
* reader's double-click (or two quick taps) told as a point of the page, and the box he draws around a diagram
|
|
9
|
+
* that was not found (while `selecting`, or with Shift held).
|
|
10
|
+
*/
|
|
11
|
+
export const PageView = memo(function PageView({ doc, n, width, ratio0, live, found, picked, busy, selecting, onPoint, onDiagram, onBox, holder }) {
|
|
12
|
+
const [drawn, setDrawn] = useState(null);
|
|
13
|
+
const canvas = useRef(null);
|
|
14
|
+
const [ratio, setRatio] = useState(ratio0);
|
|
15
|
+
const tap = useRef(null);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!live)
|
|
18
|
+
return;
|
|
19
|
+
let gone = false;
|
|
20
|
+
void ratioOf(doc, n).then((r) => { if (!gone)
|
|
21
|
+
setRatio(r); });
|
|
22
|
+
return () => { gone = true; };
|
|
23
|
+
}, [doc, n, live]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const el = canvas.current;
|
|
26
|
+
if (!live || !el || width < 50)
|
|
27
|
+
return;
|
|
28
|
+
let task = null, gone = false;
|
|
29
|
+
const px = Math.min(2400, Math.round(width * Math.min(2, window.devicePixelRatio || 1)));
|
|
30
|
+
void drawPage(doc, n, px, el).then((t) => { t.promise.catch(() => { }); if (gone)
|
|
31
|
+
t.cancel();
|
|
32
|
+
else
|
|
33
|
+
task = t; });
|
|
34
|
+
return () => { gone = true; task?.cancel(); };
|
|
35
|
+
}, [doc, n, live, width]);
|
|
36
|
+
const point = (clientX, clientY, el) => {
|
|
37
|
+
const r = el.getBoundingClientRect();
|
|
38
|
+
return { page: n, fx: (clientX - r.left) / r.width, fy: (clientY - r.top) / r.height };
|
|
39
|
+
};
|
|
40
|
+
/** A phone has no double-click: two taps close in time and place are one. */
|
|
41
|
+
const tapped = (e) => {
|
|
42
|
+
if (e.pointerType !== "touch" || selecting)
|
|
43
|
+
return;
|
|
44
|
+
const now = performance.now(), was = tap.current;
|
|
45
|
+
if (was && now - was.at < 340 && Math.hypot(e.clientX - was.x, e.clientY - was.y) < 32) {
|
|
46
|
+
tap.current = null;
|
|
47
|
+
onPoint(point(e.clientX, e.clientY, e.currentTarget));
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
tap.current = { at: now, x: e.clientX, y: e.clientY };
|
|
51
|
+
};
|
|
52
|
+
/** A box drawn from where the pointer went down to where it is let go. */
|
|
53
|
+
const draw = (down) => {
|
|
54
|
+
if (down.button > 0 || !(selecting || down.shiftKey))
|
|
55
|
+
return;
|
|
56
|
+
const el = down.currentTarget, from = point(down.clientX, down.clientY, el);
|
|
57
|
+
down.preventDefault();
|
|
58
|
+
el.setPointerCapture(down.pointerId);
|
|
59
|
+
const boxTo = (e) => {
|
|
60
|
+
const to = point(e.clientX, e.clientY, el), hold = (v) => Math.min(1, Math.max(0, v));
|
|
61
|
+
return { x0: hold(Math.min(from.fx, to.fx)), y0: hold(Math.min(from.fy, to.fy)), x1: hold(Math.max(from.fx, to.fx)), y1: hold(Math.max(from.fy, to.fy)) };
|
|
62
|
+
};
|
|
63
|
+
const move = (e) => setDrawn(boxTo(e));
|
|
64
|
+
const end = (e) => {
|
|
65
|
+
el.removeEventListener("pointermove", move);
|
|
66
|
+
el.removeEventListener("pointerup", end);
|
|
67
|
+
el.removeEventListener("pointercancel", end);
|
|
68
|
+
setDrawn(null);
|
|
69
|
+
const b = boxTo(e), r = el.getBoundingClientRect();
|
|
70
|
+
if (e.type === "pointerup" && (b.x1 - b.x0) * r.width >= BOX_MIN && (b.y1 - b.y0) * r.height >= BOX_MIN)
|
|
71
|
+
onBox(n, b);
|
|
72
|
+
};
|
|
73
|
+
el.addEventListener("pointermove", move);
|
|
74
|
+
el.addEventListener("pointerup", end);
|
|
75
|
+
el.addEventListener("pointercancel", end);
|
|
76
|
+
};
|
|
77
|
+
const box = (d) => ({ left: `${d.x0 * 100}%`, top: `${d.y0 * 100}%`, width: `${(d.x1 - d.x0) * 100}%`, height: `${(d.y1 - d.y0) * 100}%` });
|
|
78
|
+
return (_jsxs("div", { className: "rd-page", ref: (el) => holder(n, el), "data-page": n, style: { width, height: Math.round(width * ratio) }, onDoubleClick: (e) => { if (!selecting)
|
|
79
|
+
onPoint(point(e.clientX, e.clientY, e.currentTarget)); }, onPointerUp: tapped, onPointerDown: draw, children: [live && _jsx("canvas", { ref: canvas }), (found ?? []).map((d, i) => (_jsx("button", { type: "button", className: `rd-diagram ${picked === d ? "on" : ""}`, style: box(d), "aria-label": `Diagram ${i + 1}`, "data-testid": "read-diagram", onClick: (e) => { e.stopPropagation(); onDiagram(n, d); }, onDoubleClick: (e) => e.stopPropagation() }, i))), picked && !(found ?? []).includes(picked) && _jsx("span", { className: "rd-diagram on", style: box(picked) }), drawn && _jsx("span", { className: "rd-marquee", style: box(drawn) }), busy?.page === n && _jsx("span", { className: "rd-busy", style: { left: `${busy.fx * 100}%`, top: `${busy.fy * 100}%` } }), _jsx("span", { className: "rd-page-no", children: n })] }));
|
|
80
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReaderHost } from "./host";
|
|
2
|
+
/**
|
|
3
|
+
* A chess book read in the browser (founder 2026-12-05): the library, or a book open; a PDF dropped anywhere on
|
|
4
|
+
* the page opens it. The address keeps the open book (#<id>), so a reload stays in it. The site around it is the
|
|
5
|
+
* host's (ReaderHost): fenshot.com/read and kibitzo.com/read are this same reader.
|
|
6
|
+
*/
|
|
7
|
+
export declare function BookReader({ host }: {
|
|
8
|
+
host: ReaderHost;
|
|
9
|
+
}): import("react").JSX.Element;
|
package/dist/ReadApp.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { ReaderHostProvider, useReaderHost, useT, useTrack } from "./host";
|
|
4
|
+
import { Library } from "./Library";
|
|
5
|
+
import { addBook, diagramCounts, fileOf, listBooks, removeBook, saveBook, takeIncoming } from "./store";
|
|
6
|
+
import { configurePdf, coverOf, openPdf } from "./pdf";
|
|
7
|
+
import { Reader } from "./Reader";
|
|
8
|
+
/**
|
|
9
|
+
* A chess book read in the browser (founder 2026-12-05): the library, or a book open; a PDF dropped anywhere on
|
|
10
|
+
* the page opens it. The address keeps the open book (#<id>), so a reload stays in it. The site around it is the
|
|
11
|
+
* host's (ReaderHost): fenshot.com/read and kibitzo.com/read are this same reader.
|
|
12
|
+
*/
|
|
13
|
+
export function BookReader({ host }) {
|
|
14
|
+
configurePdf(host.pdf);
|
|
15
|
+
return _jsx(ReaderHostProvider, { value: host, children: _jsx(ReadApp, {}) });
|
|
16
|
+
}
|
|
17
|
+
function ReadApp() {
|
|
18
|
+
const t = useT();
|
|
19
|
+
const count = useTrack();
|
|
20
|
+
const { header } = useReaderHost();
|
|
21
|
+
const [books, setBooks] = useState([]);
|
|
22
|
+
const [open, setOpen] = useState(null);
|
|
23
|
+
const [busy, setBusy] = useState(false);
|
|
24
|
+
const [error, setError] = useState(null);
|
|
25
|
+
const [counts, setCounts] = useState(new Map());
|
|
26
|
+
const refresh = useCallback(() => {
|
|
27
|
+
void diagramCounts().then(setCounts).catch(() => setCounts(new Map()));
|
|
28
|
+
return listBooks().then(setBooks).catch(() => setBooks([]));
|
|
29
|
+
}, []);
|
|
30
|
+
const openBook = useCallback(async (book) => {
|
|
31
|
+
setBusy(true);
|
|
32
|
+
setError(null);
|
|
33
|
+
try {
|
|
34
|
+
const file = await fileOf(book.id);
|
|
35
|
+
if (!file)
|
|
36
|
+
throw new Error("gone");
|
|
37
|
+
const doc = await openPdf(file);
|
|
38
|
+
const now = { ...book, pages: doc.numPages, page: Math.min(book.page, doc.numPages), opened: Date.now() };
|
|
39
|
+
await saveBook(now);
|
|
40
|
+
history.replaceState(null, "", `#${encodeURIComponent(book.id)}`);
|
|
41
|
+
setOpen({ book: now, doc });
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
setError(t("readCantOpen"));
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
setBusy(false);
|
|
48
|
+
}
|
|
49
|
+
}, [t]);
|
|
50
|
+
const openFile = useCallback(async (file) => {
|
|
51
|
+
if (file.type !== "application/pdf" && !/\.pdf$/i.test(file.name)) {
|
|
52
|
+
setError(t("readNotPdf"));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
setBusy(true);
|
|
56
|
+
setError(null);
|
|
57
|
+
try {
|
|
58
|
+
const doc = await openPdf(file);
|
|
59
|
+
const book = await addBook(file, doc.numPages, { cover: await coverOf(doc) });
|
|
60
|
+
count("read-open", { pages: doc.numPages });
|
|
61
|
+
history.replaceState(null, "", `#${encodeURIComponent(book.id)}`);
|
|
62
|
+
setOpen({ book: { ...book, opened: Date.now() }, doc });
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
setError(t("readCantOpen"));
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
setBusy(false);
|
|
69
|
+
}
|
|
70
|
+
}, [t]);
|
|
71
|
+
// Once, on arrival: the library, and the book the address names.
|
|
72
|
+
const arrived = useRef(false);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (arrived.current)
|
|
75
|
+
return;
|
|
76
|
+
arrived.current = true;
|
|
77
|
+
void listBooks().then(async (all) => {
|
|
78
|
+
setBooks(all);
|
|
79
|
+
void diagramCounts().then(setCounts).catch(() => { });
|
|
80
|
+
const id = decodeURIComponent(location.hash.slice(1));
|
|
81
|
+
if (id === "incoming") {
|
|
82
|
+
const file = await takeIncoming();
|
|
83
|
+
if (file)
|
|
84
|
+
return void openFile(file);
|
|
85
|
+
}
|
|
86
|
+
const book = id ? all.find((b) => b.id === id) : undefined;
|
|
87
|
+
if (book)
|
|
88
|
+
void openBook(book);
|
|
89
|
+
}).catch(() => setBooks([]));
|
|
90
|
+
}, [openBook, openFile]);
|
|
91
|
+
// A PDF dropped anywhere on the page, in the library or over a book.
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
const over = (e) => { if (e.dataTransfer?.types.includes("Files"))
|
|
94
|
+
e.preventDefault(); };
|
|
95
|
+
const drop = (e) => { const f = e.dataTransfer?.files[0]; if (f) {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
void openFile(f);
|
|
98
|
+
} };
|
|
99
|
+
window.addEventListener("dragover", over);
|
|
100
|
+
window.addEventListener("drop", drop);
|
|
101
|
+
return () => { window.removeEventListener("dragover", over); window.removeEventListener("drop", drop); };
|
|
102
|
+
}, [openFile]);
|
|
103
|
+
const toLibrary = useCallback(() => {
|
|
104
|
+
void open?.doc.loadingTask.destroy();
|
|
105
|
+
history.replaceState(null, "", location.pathname + location.search);
|
|
106
|
+
setOpen(null);
|
|
107
|
+
void refresh();
|
|
108
|
+
}, [open, refresh]);
|
|
109
|
+
const progress = useCallback((page) => {
|
|
110
|
+
setOpen((now) => {
|
|
111
|
+
if (!now || now.book.page === page)
|
|
112
|
+
return now;
|
|
113
|
+
const book = { ...now.book, page, opened: Date.now() };
|
|
114
|
+
void saveBook(book);
|
|
115
|
+
return { ...now, book };
|
|
116
|
+
});
|
|
117
|
+
}, []);
|
|
118
|
+
useEffect(() => { document.body.classList.toggle("reading", open !== null); }, [open]);
|
|
119
|
+
if (open)
|
|
120
|
+
return _jsx(Reader, { book: open.book, doc: open.doc, onLibrary: toLibrary, onProgress: progress }, open.book.id);
|
|
121
|
+
return (_jsxs("div", { className: "fsr-library", children: [header, _jsx(Library, { books: books, counts: counts, busy: busy, error: error, onFile: (f) => void openFile(f), onOpen: (b) => void openBook(b), onRename: (b, name) => void saveBook({ ...b, name, renamed: true }).then(refresh), onRemove: (b) => void removeBook(b.id).then(refresh) })] }));
|
|
122
|
+
}
|
package/dist/Reader.d.ts
ADDED
package/dist/Reader.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useReaderHost, useT, useTrack } from "./host";
|
|
4
|
+
import { PageView } from "./PageView";
|
|
5
|
+
import { ReaderBar } from "./ReaderBar";
|
|
6
|
+
import { SideGrip, storedSide } from "./SideGrip";
|
|
7
|
+
import { same, useDiagrams } from "./useDiagrams";
|
|
8
|
+
import { usePages } from "./usePages";
|
|
9
|
+
/**
|
|
10
|
+
* A book open: its pages in one column (usePages), every diagram of it found in the background (useDiagrams), and
|
|
11
|
+
* a board beside the pages for the diagram the reader opened: with a click on it, with the bar's "next diagram",
|
|
12
|
+
* or with a double-click where the search found none.
|
|
13
|
+
*/
|
|
14
|
+
const EMPTY = "8/8/8/8/8/8/8/8";
|
|
15
|
+
/** The diagram to go to from where the reader is: from the open one, else from the page he is reading. */
|
|
16
|
+
function stepFrom(all, index, page, step) {
|
|
17
|
+
// Round the book: before the first is the last, after the last the first.
|
|
18
|
+
if (index >= 0)
|
|
19
|
+
return all[(index + step + all.length) % all.length];
|
|
20
|
+
if (step > 0)
|
|
21
|
+
return all.find((s) => s.page >= page) ?? all[0];
|
|
22
|
+
const before = all.filter((s) => s.page <= page);
|
|
23
|
+
return before.filter((s) => s.page < page).at(-1) ?? before.at(-1) ?? all.at(-1);
|
|
24
|
+
}
|
|
25
|
+
export function Reader({ book, doc, onLibrary, onProgress }) {
|
|
26
|
+
const t = useT();
|
|
27
|
+
const count = useTrack();
|
|
28
|
+
const { BoardPanel } = useReaderHost();
|
|
29
|
+
const view = usePages(doc, book.page);
|
|
30
|
+
const { page, goToDiagram } = view;
|
|
31
|
+
const { found, all, searched, readPoint, readIn } = useDiagrams(doc, book.id, page, view.pane);
|
|
32
|
+
/** The reader is drawing a box around a diagram that was not found. */
|
|
33
|
+
const [selecting, setSelecting] = useState(false);
|
|
34
|
+
const [sideW, setSideW] = useState(storedSide);
|
|
35
|
+
const [picked, setPicked] = useState(null);
|
|
36
|
+
const [busy, setBusy] = useState(null);
|
|
37
|
+
/** A diagram that could not be read, and where: the reader may set it up by hand. */
|
|
38
|
+
const [unread, setUnread] = useState(null);
|
|
39
|
+
useEffect(() => { const id = setTimeout(() => onProgress(page), 500); return () => clearTimeout(id); }, [page, onProgress]);
|
|
40
|
+
useEffect(() => { if (!unread)
|
|
41
|
+
return; const id = setTimeout(() => setUnread(null), 7000); return () => clearTimeout(id); }, [unread]);
|
|
42
|
+
const open = useCallback((n, diagram) => {
|
|
43
|
+
setPicked({ page: n, diagram });
|
|
44
|
+
count("read-pick", { sure: diagram.min >= 0.7 });
|
|
45
|
+
}, []);
|
|
46
|
+
// Read through a ref: a page is not drawn again each time another page's diagrams are found.
|
|
47
|
+
const foundNow = useRef(found);
|
|
48
|
+
foundNow.current = found;
|
|
49
|
+
const onPoint = useCallback((p) => {
|
|
50
|
+
const known = (foundNow.current.get(p.page) ?? []).find((d) => p.fx >= d.x0 && p.fx <= d.x1 && p.fy >= d.y0 && p.fy <= d.y1);
|
|
51
|
+
if (known)
|
|
52
|
+
return open(p.page, known);
|
|
53
|
+
setBusy(p);
|
|
54
|
+
void readPoint(p).then((diagram) => {
|
|
55
|
+
if (diagram)
|
|
56
|
+
open(p.page, diagram);
|
|
57
|
+
else {
|
|
58
|
+
setUnread(p);
|
|
59
|
+
count("read-nodiagram");
|
|
60
|
+
}
|
|
61
|
+
}).catch(() => setUnread(p)).finally(() => setBusy(null));
|
|
62
|
+
}, [open, readPoint]);
|
|
63
|
+
const onBox = useCallback((n, box) => {
|
|
64
|
+
const middle = { page: n, fx: (box.x0 + box.x1) / 2, fy: (box.y0 + box.y1) / 2 };
|
|
65
|
+
setSelecting(false);
|
|
66
|
+
setBusy(middle);
|
|
67
|
+
void readIn(n, box).then((diagram) => {
|
|
68
|
+
if (diagram)
|
|
69
|
+
open(n, diagram);
|
|
70
|
+
else
|
|
71
|
+
setUnread(middle);
|
|
72
|
+
count("read-select", { read: diagram !== null });
|
|
73
|
+
}).catch(() => setUnread(middle)).finally(() => setBusy(null));
|
|
74
|
+
}, [open, readIn]);
|
|
75
|
+
const byHand = () => {
|
|
76
|
+
if (!unread)
|
|
77
|
+
return;
|
|
78
|
+
setPicked({ page: unread.page, byHand: true, diagram: { x0: unread.fx, y0: unread.fy, x1: unread.fx, y1: unread.fy, placement: EMPTY, flipped: false, min: 1, mean: 1 } });
|
|
79
|
+
setUnread(null);
|
|
80
|
+
count("read-byhand");
|
|
81
|
+
};
|
|
82
|
+
const index = picked && !picked.byHand ? all.findIndex((s) => s.page === picked.page && same(s.diagram, picked.diagram)) : -1;
|
|
83
|
+
const step = useCallback((by) => {
|
|
84
|
+
const to = stepFrom(all, index, page, by);
|
|
85
|
+
if (!to)
|
|
86
|
+
return;
|
|
87
|
+
goToDiagram(to.page, to.diagram);
|
|
88
|
+
setPicked({ page: to.page, diagram: to.diagram });
|
|
89
|
+
count("read-step");
|
|
90
|
+
}, [all, index, page, goToDiagram]);
|
|
91
|
+
const { zoomBy } = view;
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
const key = (e) => {
|
|
94
|
+
if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey || e.target instanceof HTMLInputElement)
|
|
95
|
+
return;
|
|
96
|
+
if (e.key === "Escape") {
|
|
97
|
+
if (selecting)
|
|
98
|
+
setSelecting(false);
|
|
99
|
+
else
|
|
100
|
+
setPicked(null);
|
|
101
|
+
}
|
|
102
|
+
else if (e.key === "+" || e.key === "=")
|
|
103
|
+
zoomBy(1);
|
|
104
|
+
else if (e.key === "-")
|
|
105
|
+
zoomBy(-1);
|
|
106
|
+
else if (e.key === "0")
|
|
107
|
+
zoomBy(0);
|
|
108
|
+
else if (e.key === "ArrowRight")
|
|
109
|
+
step(1);
|
|
110
|
+
else if (e.key === "ArrowLeft")
|
|
111
|
+
step(-1);
|
|
112
|
+
};
|
|
113
|
+
window.addEventListener("keydown", key);
|
|
114
|
+
return () => window.removeEventListener("keydown", key);
|
|
115
|
+
}, [zoomBy, step, selecting]);
|
|
116
|
+
return (_jsxs("div", { className: `rd ${picked ? "rd-has-board" : ""}`, style: { "--rd-side": `${sideW}px` }, "data-testid": "reader", children: [_jsx(ReaderBar, { doc: doc, name: book.name, page: page, onLibrary: onLibrary, onPage: view.goTo, nav: { total: all.length, index, searched, pages: view.pages, onStep: step }, select: { on: selecting, toggle: () => setSelecting(!selecting) }, zoom: { percent: view.zoom, by: zoomBy, canOut: view.canZoomOut, canIn: view.canZoomIn } }), _jsxs("div", { className: "rd-body", children: [_jsx("div", { className: `rd-pages ${selecting ? "rd-selecting" : ""}`, ref: view.pane, tabIndex: 0, "data-testid": "read-pages", children: view.laidOut && Array.from({ length: view.pages }, (_, i) => i + 1).map((n) => (_jsx(PageView, { doc: doc, n: n, width: view.width, ratio0: view.ratio0, live: view.near.has(n), found: found.get(n), picked: picked?.page === n && !picked.byHand ? picked.diagram : null, busy: busy?.page === n ? busy : null, selecting: selecting, onPoint: onPoint, onDiagram: open, onBox: onBox, holder: view.holder }, n))) }), _jsx(SideGrip, { width: sideW, label: t("readResize"), onWidth: setSideW }), picked ? (_jsx("aside", { className: "rd-side", "data-testid": "read-board-panel", children: _jsx(BoardPanel, { picked: picked, onClose: () => setPicked(null) }) })) : (_jsxs("aside", { className: "rd-side rd-side-empty", children: [_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: [_jsx("rect", { x: "3.5", y: "3.5", width: "17", height: "17", rx: "2" }), _jsx("path", { d: "M3.5 12h17M12 3.5v17" })] }), _jsx("p", { className: "rd-hint", children: t("readHint") }), _jsx("p", { className: "rd-hint-sub", children: t("readHintSub") })] }))] }), selecting && _jsx("div", { className: "rd-toast", role: "status", "data-testid": "read-select-hint", children: _jsx("span", { children: t("readSelectHint") }) }), unread && (_jsxs("div", { className: "rd-toast", role: "status", "data-testid": "read-toast", children: [_jsx("span", { children: t("readNoDiagram") }), _jsx("button", { type: "button", className: "rd-btn rd-btn-quiet", onClick: byHand, "data-testid": "read-byhand", children: t("readByHand") })] }))] }));
|
|
117
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Doc } from "./pdf";
|
|
2
|
+
export interface DiagramNavProps {
|
|
3
|
+
/** How many diagrams were found so far, and which of them is open (0-based, -1 for none). */
|
|
4
|
+
total: number;
|
|
5
|
+
index: number;
|
|
6
|
+
/** Pages searched, of the book's pages: the count is still growing while they differ. */
|
|
7
|
+
searched: number;
|
|
8
|
+
pages: number;
|
|
9
|
+
onStep(step: -1 | 1): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function ReaderBar({ doc, name, page, nav, select, zoom, onLibrary, onPage }: {
|
|
12
|
+
doc: Doc;
|
|
13
|
+
name: string;
|
|
14
|
+
page: number;
|
|
15
|
+
nav: DiagramNavProps;
|
|
16
|
+
/** The reader draws a box around a diagram that was not found. */
|
|
17
|
+
select: {
|
|
18
|
+
on: boolean;
|
|
19
|
+
toggle(): void;
|
|
20
|
+
};
|
|
21
|
+
/** The size of the pages in percent; a step of 0 is back to 100%. */
|
|
22
|
+
zoom: {
|
|
23
|
+
percent: number;
|
|
24
|
+
by(step: number): void;
|
|
25
|
+
canOut: boolean;
|
|
26
|
+
canIn: boolean;
|
|
27
|
+
};
|
|
28
|
+
onLibrary(): void;
|
|
29
|
+
onPage(n: number): void;
|
|
30
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useT } from "./host";
|
|
4
|
+
import { chaptersOf } from "./pdf";
|
|
5
|
+
/**
|
|
6
|
+
* The bar over an open book: back to the library, the book's name, its contents, its diagrams (how many, which
|
|
7
|
+
* one is open, the one before and the next), the page, and the size of the pages.
|
|
8
|
+
*/
|
|
9
|
+
const Icon = ({ d, width = 2 }) => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: width, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: _jsx("path", { d: d }) }));
|
|
10
|
+
function Contents({ doc, onPage }) {
|
|
11
|
+
const t = useT();
|
|
12
|
+
const [chapters, setChapters] = useState([]);
|
|
13
|
+
const [open, setOpen] = useState(false);
|
|
14
|
+
useEffect(() => { void chaptersOf(doc).then(setChapters); }, [doc]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!open)
|
|
17
|
+
return;
|
|
18
|
+
const key = (e) => { if (e.key === "Escape")
|
|
19
|
+
setOpen(false); };
|
|
20
|
+
window.addEventListener("keydown", key);
|
|
21
|
+
return () => window.removeEventListener("keydown", key);
|
|
22
|
+
}, [open]);
|
|
23
|
+
if (!chapters.length)
|
|
24
|
+
return null;
|
|
25
|
+
return (_jsxs("div", { className: "rd-contents", children: [_jsxs("button", { type: "button", className: "rd-chip", onClick: () => setOpen(!open), "aria-expanded": open, "aria-label": t("readContents"), "data-testid": "read-contents-open", children: [_jsx(Icon, { d: "M8 6h12M8 12h12M8 18h12M4 6h.01M4 12h.01M4 18h.01" }), _jsx("span", { children: t("readContents") })] }), open && (_jsx("ul", { className: "rd-contents-list", "data-testid": "read-contents", children: chapters.map((c, i) => (_jsx("li", { children: _jsxs("button", { type: "button", style: { paddingInlineStart: 12 + c.depth * 14 }, onClick: () => { onPage(c.page); setOpen(false); }, children: [_jsx("span", { children: c.title }), _jsx("span", { className: "rd-contents-page", children: c.page })] }) }, i))) }))] }));
|
|
26
|
+
}
|
|
27
|
+
function DiagramNav({ total, index, searched, pages, onStep }) {
|
|
28
|
+
const t = useT();
|
|
29
|
+
const finding = searched < pages;
|
|
30
|
+
const about = finding ? t("readFinding", { done: searched, pages }) : t("readDiagrams", { n: total });
|
|
31
|
+
return (_jsxs("div", { className: `rd-nav ${finding ? "finding" : ""}`, title: about, "data-testid": "read-nav", children: [_jsx("button", { type: "button", className: "rd-icon", onClick: () => onStep(-1), disabled: !total, "aria-label": t("readDiagramPrev"), "data-testid": "read-nav-prev", children: _jsx(Icon, { d: "M15 6l-6 6 6 6" }) }), _jsxs("span", { className: "rd-nav-count", style: { minWidth: `calc(${String(total).length * 2 + 3.4}ch + 21px)` }, "aria-label": about, "data-testid": "read-nav-count", children: [_jsxs("svg", { viewBox: "0 0 24 24", "aria-hidden": true, children: [_jsx("rect", { x: "3.5", y: "3.5", width: "17", height: "17", rx: "2.5", fill: "none", stroke: "currentColor", strokeWidth: "1.8" }), _jsx("path", { d: "M3.5 3.5h8.5v8.5H3.5zM12 12h8.5v8.5H12z", fill: "currentColor", opacity: "0.55" })] }), index >= 0 ? _jsxs(_Fragment, { children: [_jsx("b", { children: index + 1 }), _jsxs("i", { children: ["/ ", total] })] }) : _jsx("b", { children: total })] }), _jsx("button", { type: "button", className: "rd-icon", onClick: () => onStep(1), disabled: !total, "aria-label": t("readDiagramNext"), "data-testid": "read-nav-next", children: _jsx(Icon, { d: "M9 6l6 6-6 6" }) }), finding && _jsx("span", { className: "rd-nav-progress", "aria-hidden": true, children: _jsx("span", { style: { width: `${(searched / pages) * 100}%` } }) })] }));
|
|
32
|
+
}
|
|
33
|
+
export function ReaderBar({ doc, name, page, nav, select, zoom, onLibrary, onPage }) {
|
|
34
|
+
const t = useT();
|
|
35
|
+
return (_jsxs("header", { className: "rd-bar", children: [_jsxs("button", { type: "button", className: "rd-back", onClick: onLibrary, "data-testid": "read-library", children: [_jsx(Icon, { d: "M15 6l-6 6 6 6" }), _jsx("span", { children: t("readLibrary") })] }), _jsx("span", { className: "rd-title", title: name, children: name }), _jsx(Contents, { doc: doc, onPage: onPage }), _jsx(DiagramNav, { ...nav }), _jsxs("button", { type: "button", className: `rd-chip rd-select ${select.on ? "on" : ""}`, onClick: select.toggle, "aria-pressed": select.on, title: t("readSelectTitle"), "data-testid": "read-select", children: [_jsx(Icon, { d: "M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3M12 9v6M9 12h6" }), _jsx("span", { children: select.on ? t("readCancel") : t("readSelect") })] }), _jsxs("label", { className: "rd-pagebox", title: t("readGoToPage"), children: [_jsx("input", { type: "number", min: 1, max: doc.numPages, value: page, "aria-label": t("readGoToPage"), onChange: (e) => onPage(Number(e.target.value)), "data-testid": "read-page" }), _jsxs("span", { children: ["/ ", doc.numPages] })] }), _jsxs("div", { className: "rd-zoom", children: [_jsx("button", { type: "button", className: "rd-icon", onClick: () => zoom.by(-1), disabled: !zoom.canOut, "aria-label": t("readZoomOut"), title: t("readZoomOut"), "data-testid": "read-zoom-out", children: _jsx(Icon, { d: "M5 12h14", width: 2.2 }) }), _jsxs("button", { type: "button", className: "rd-zoom-now", onClick: () => zoom.by(0), disabled: zoom.percent === 100, title: t("readZoomReset"), "aria-label": t("readZoomReset"), "data-testid": "read-zoom", children: [zoom.percent, "%"] }), _jsx("button", { type: "button", className: "rd-icon", onClick: () => zoom.by(1), disabled: !zoom.canIn, "aria-label": t("readZoomIn"), title: t("readZoomIn"), "data-testid": "read-zoom-in", children: _jsx(Icon, { d: "M12 5v14M5 12h14", width: 2.2 }) })] })] }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The edge between the book and the board: drag it to give the board more room or less, press the arrow keys for
|
|
3
|
+
* small steps, double-click for the width it came with. The width is kept on this device. While the edge is
|
|
4
|
+
* dragged only a CSS variable on the reader changes (no render); the reader learns the new width when it is let go.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SIDE_DEFAULT = 480;
|
|
7
|
+
export declare function storedSide(): number;
|
|
8
|
+
export declare function SideGrip({ width, label, onWidth }: {
|
|
9
|
+
width: number;
|
|
10
|
+
label: string;
|
|
11
|
+
onWidth(width: number): void;
|
|
12
|
+
}): import("react").JSX.Element;
|