@open-document/core 0.9.1 → 0.11.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/dist/{build-B0GJXy8I.js → build-BHFGY8eF.js} +1 -1
- package/dist/{check-CuDIWsPT.js → check-UEBmDfT_.js} +3 -3
- package/dist/cli/bin.js +10 -6
- package/dist/{config-CAZ7Z_va.js → config-B_pdNbYg.js} +1166 -591
- package/dist/{context-PWAh9qbf.js → context-BM9_-u9P.js} +1 -1
- package/dist/{dev-CYqppXDI.js → dev-DX3QMIRi.js} +1 -1
- package/dist/{diagram-CCaUUnRe.js → diagram-BK4jTZr4.js} +146 -146
- package/dist/diff-DayvbXfX.js +44 -0
- package/dist/{export-1JtO2OMC.js → export-BPsXj1i6.js} +3 -3
- package/dist/{import-CsrdBOZ8.js → import-71wlAsrd.js} +2 -2
- package/dist/index.d.ts +53 -2
- package/dist/index.js +457 -18
- package/dist/ops/index.d.ts +72 -17
- package/dist/ops/index.js +3 -3
- package/dist/{ops-B2y9BMpk.js → ops-BUo67DaP.js} +642 -124
- package/dist/{preview-DW3PM-JV.js → preview-D3m1-gUL.js} +1 -1
- package/dist/{sdk-BqU6mwD_.d.ts → sdk-CpDEGRIo.d.ts} +2 -0
- package/dist/vite/index.js +1 -1
- package/package.json +2 -2
- package/skills/doc-authoring/SKILL.md +9 -4
- package/skills/doc-authoring/references/pagination.md +1 -1
- package/skills/doc-authoring/references/tables-and-charts.md +18 -1
- package/src/app/components/browser/browser-ui.tsx +105 -0
- package/src/app/components/chart.tsx +239 -0
- package/src/app/components/command-palette.tsx +284 -0
- package/src/app/components/design-panel/design-panel.tsx +22 -20
- package/src/app/components/design-panel/design-provider.tsx +4 -2
- package/src/app/components/diagram.tsx +11 -1
- package/src/app/components/doc-assets.tsx +6 -5
- package/src/app/components/doc-search.tsx +12 -10
- package/src/app/components/doc-sidebar.tsx +24 -18
- package/src/app/components/flow-page.tsx +2 -0
- package/src/app/components/inspector/format-section.tsx +434 -0
- package/src/app/components/inspector/inspector.tsx +310 -89
- package/src/app/components/inspector/use-style-edits.ts +210 -0
- package/src/app/components/language-toggle.tsx +38 -0
- package/src/app/components/palette-items.ts +128 -0
- package/src/app/components/panel/edit-save-card.tsx +4 -2
- package/src/app/components/panel/fields.tsx +100 -9
- package/src/app/components/panel/save-card.tsx +18 -10
- package/src/app/components/sidebar/folder-item.tsx +10 -8
- package/src/app/components/sidebar/icon-picker.tsx +3 -1
- package/src/app/components/sidebar/sidebar.tsx +44 -13
- package/src/app/components/theme-toggle.tsx +5 -3
- package/src/app/components/ui/menu.tsx +5 -0
- package/src/app/lib/agent-bridge.ts +8 -2
- package/src/app/lib/chart.test.ts +108 -0
- package/src/app/lib/chart.ts +343 -0
- package/src/app/lib/doc-preview.tsx +0 -10
- package/src/app/lib/docs.ts +3 -0
- package/src/app/lib/docx/from-dom.ts +11 -11
- package/src/app/lib/docx/ooxml.test.ts +25 -9
- package/src/app/lib/docx/ooxml.ts +58 -37
- package/src/app/lib/export-docx.ts +13 -8
- package/src/app/lib/flow.ts +1 -1
- package/src/app/lib/i18n-ja/browser.ts +88 -0
- package/src/app/lib/i18n-ja/doc.ts +65 -0
- package/src/app/lib/i18n-ja/index.ts +5 -0
- package/src/app/lib/i18n-ja/panels.ts +151 -0
- package/src/app/lib/i18n-ko/browser.ts +87 -0
- package/src/app/lib/i18n-ko/doc.ts +65 -0
- package/src/app/lib/i18n-ko/index.ts +5 -0
- package/src/app/lib/i18n-ko/panels.ts +148 -0
- package/src/app/lib/i18n-zh-cn/browser.ts +84 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +64 -0
- package/src/app/lib/i18n-zh-cn/index.ts +5 -0
- package/src/app/lib/i18n-zh-cn/panels.ts +143 -0
- package/src/app/lib/i18n-zh-tw/browser.ts +84 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +64 -0
- package/src/app/lib/i18n-zh-tw/index.ts +5 -0
- package/src/app/lib/i18n-zh-tw/panels.ts +144 -0
- package/src/app/lib/i18n.test.ts +24 -0
- package/src/app/lib/i18n.tsx +109 -0
- package/src/app/lib/inspector/format.ts +156 -0
- package/src/app/lib/outline.ts +23 -0
- package/src/app/lib/page-range.test.ts +10 -1
- package/src/app/lib/page-range.ts +26 -0
- package/src/app/lib/sdk.ts +2 -0
- package/src/app/main.tsx +4 -1
- package/src/app/routes/assets.tsx +193 -132
- package/src/app/routes/doc.tsx +668 -310
- package/src/app/routes/home-shell.tsx +115 -88
- package/src/app/routes/home.tsx +200 -67
- package/src/app/routes/themes.tsx +42 -35
- package/src/app/styles.css +84 -5
- package/src/app/virtual.d.ts +1 -0
package/src/app/routes/doc.tsx
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import appConfig from 'virtual:open-doc/config';
|
|
2
2
|
import {
|
|
3
|
+
ArrowDownToLine,
|
|
3
4
|
ArrowLeft,
|
|
4
5
|
BookOpen,
|
|
5
6
|
Check,
|
|
7
|
+
ChevronDown,
|
|
6
8
|
Download,
|
|
7
9
|
Eye,
|
|
8
10
|
FileCode2,
|
|
9
11
|
FileImage,
|
|
10
12
|
FileText,
|
|
11
13
|
FileType2,
|
|
14
|
+
Hash,
|
|
12
15
|
Image,
|
|
13
16
|
LayoutGrid,
|
|
17
|
+
Link2,
|
|
14
18
|
Loader2,
|
|
15
19
|
Maximize,
|
|
16
20
|
Minimize,
|
|
@@ -19,12 +23,13 @@ import {
|
|
|
19
23
|
MoveVertical,
|
|
20
24
|
Palette,
|
|
21
25
|
Pencil,
|
|
22
|
-
Percent,
|
|
23
26
|
Plus,
|
|
24
27
|
Rows3,
|
|
25
28
|
} from 'lucide-react';
|
|
29
|
+
import { useTheme } from 'next-themes';
|
|
26
30
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
27
|
-
import { Link, useParams } from 'react-router-dom';
|
|
31
|
+
import { Link, useNavigate, useParams } from 'react-router-dom';
|
|
32
|
+
import { CommandPaletteProvider, type PaletteItem } from '../components/command-palette';
|
|
28
33
|
import { DesignPanel } from '../components/design-panel/design-panel';
|
|
29
34
|
import { DesignProvider } from '../components/design-panel/design-provider';
|
|
30
35
|
import { DocSearch } from '../components/doc-search';
|
|
@@ -32,6 +37,7 @@ import { DocSidebar } from '../components/doc-sidebar';
|
|
|
32
37
|
import { HistoryProvider } from '../components/history-provider';
|
|
33
38
|
import { Inspector, type InspectorControls } from '../components/inspector/inspector';
|
|
34
39
|
import { PageFrame } from '../components/page-frame';
|
|
40
|
+
import { browserItems } from '../components/palette-items';
|
|
35
41
|
import { EditSaveCard } from '../components/panel/edit-save-card';
|
|
36
42
|
import { ThemeToggle } from '../components/theme-toggle';
|
|
37
43
|
import { Menu, MenuItem } from '../components/ui/menu';
|
|
@@ -40,8 +46,14 @@ import { exportDocAsDocx } from '../lib/export-docx';
|
|
|
40
46
|
import { exportDocAsHtml } from '../lib/export-html';
|
|
41
47
|
import { exportDocAsImages } from '../lib/export-image';
|
|
42
48
|
import { exportDocAsPdf } from '../lib/export-pdf';
|
|
49
|
+
import { useLocale, useT } from '../lib/i18n';
|
|
43
50
|
import { type OutlineEntry, useDocOutline } from '../lib/outline';
|
|
44
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
describeSelection,
|
|
53
|
+
formatPages,
|
|
54
|
+
type PageSelection,
|
|
55
|
+
resolveSelection,
|
|
56
|
+
} from '../lib/page-range';
|
|
45
57
|
import { nextFrame, waitForFonts } from '../lib/print-ready';
|
|
46
58
|
import { scanDocument } from '../lib/scan';
|
|
47
59
|
import { resolvePageGeometry } from '../lib/sdk';
|
|
@@ -66,16 +78,61 @@ const DOWNLOAD_LABEL: Record<DownloadFormat, string> = {
|
|
|
66
78
|
docx: 'Word',
|
|
67
79
|
};
|
|
68
80
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Grouped by what the file is for rather than listed by type: the reader is
|
|
83
|
+
* choosing between "send it", "edit it" and "drop it in a slide", and the
|
|
84
|
+
* extension on the right says what lands in their downloads folder.
|
|
85
|
+
*/
|
|
86
|
+
const DOWNLOAD_GROUPS = [
|
|
87
|
+
{
|
|
88
|
+
label: 'Print & share',
|
|
89
|
+
formats: [
|
|
90
|
+
{
|
|
91
|
+
format: 'pdf' as const,
|
|
92
|
+
label: 'PDF',
|
|
93
|
+
hint: 'True page size, print-ready',
|
|
94
|
+
ext: '.pdf',
|
|
95
|
+
icon: FileText,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
format: 'html' as const,
|
|
99
|
+
label: 'HTML',
|
|
100
|
+
hint: 'One self-contained file',
|
|
101
|
+
ext: '.html',
|
|
102
|
+
icon: FileCode2,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
label: 'Edit',
|
|
108
|
+
formats: [
|
|
109
|
+
{
|
|
110
|
+
format: 'docx' as const,
|
|
111
|
+
label: 'Word',
|
|
112
|
+
hint: 'Editable; Word lays out the pages',
|
|
113
|
+
ext: '.docx',
|
|
114
|
+
icon: FileType2,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
74
118
|
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
119
|
+
label: 'Images',
|
|
120
|
+
formats: [
|
|
121
|
+
{
|
|
122
|
+
format: 'png' as const,
|
|
123
|
+
label: 'PNG',
|
|
124
|
+
hint: 'Pixels at 2×, for slides and chat',
|
|
125
|
+
ext: '.png',
|
|
126
|
+
icon: Image,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
format: 'svg' as const,
|
|
130
|
+
label: 'SVG',
|
|
131
|
+
hint: 'Vector, text stays text',
|
|
132
|
+
ext: '.svg',
|
|
133
|
+
icon: FileImage,
|
|
134
|
+
},
|
|
135
|
+
],
|
|
79
136
|
},
|
|
80
137
|
];
|
|
81
138
|
|
|
@@ -99,16 +156,17 @@ const BACK_CLASS =
|
|
|
99
156
|
* host that mounts the viewer this way is providing its own way back.
|
|
100
157
|
*/
|
|
101
158
|
const HeaderBackLink = () => {
|
|
159
|
+
const t = useT();
|
|
102
160
|
if (appConfig.home !== undefined) {
|
|
103
161
|
return (
|
|
104
|
-
<a href={appConfig.home} className={BACK_CLASS} aria-label=
|
|
162
|
+
<a href={appConfig.home} className={BACK_CLASS} aria-label={t('Back to workspace')}>
|
|
105
163
|
<ArrowLeft className="size-4" />
|
|
106
164
|
</a>
|
|
107
165
|
);
|
|
108
166
|
}
|
|
109
167
|
if (!appConfig.build.showDocBrowser) return null;
|
|
110
168
|
return (
|
|
111
|
-
<Link to="/" className={BACK_CLASS} aria-label=
|
|
169
|
+
<Link to="/" className={BACK_CLASS} aria-label={t('Back to documents')}>
|
|
112
170
|
<ArrowLeft className="size-4" />
|
|
113
171
|
</Link>
|
|
114
172
|
);
|
|
@@ -129,6 +187,8 @@ export function Doc() {
|
|
|
129
187
|
const { docId } = useParams<{ docId: string }>();
|
|
130
188
|
const state = useDocModule(docId);
|
|
131
189
|
const doc = state.doc;
|
|
190
|
+
const t = useT();
|
|
191
|
+
const { setLocale } = useLocale();
|
|
132
192
|
|
|
133
193
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
134
194
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
@@ -144,6 +204,7 @@ export function Doc() {
|
|
|
144
204
|
const [selection, setSelection] = useState<PageSelection>({ kind: 'all' });
|
|
145
205
|
const [customRange, setCustomRange] = useState('');
|
|
146
206
|
const [designOpen, setDesignOpen] = useState(false);
|
|
207
|
+
const closeDesign = useCallback(() => setDesignOpen(false), []);
|
|
147
208
|
const [editing, setEditingState] = useState(readEditing);
|
|
148
209
|
// The dev server reloads every open viewer when a document is added or
|
|
149
210
|
// removed anywhere in the workspace. Edit mode is per tab and survives that.
|
|
@@ -366,9 +427,9 @@ export function Doc() {
|
|
|
366
427
|
setZoomMode(mode);
|
|
367
428
|
};
|
|
368
429
|
|
|
369
|
-
const
|
|
430
|
+
const setZoom = (value: number) => {
|
|
370
431
|
setZoomMode('auto');
|
|
371
|
-
setManualScale(
|
|
432
|
+
setManualScale(Math.min(MAX_SCALE, Math.max(MIN_SCALE, Number(value.toFixed(2)))));
|
|
372
433
|
};
|
|
373
434
|
|
|
374
435
|
const toggleFullscreen = useCallback(() => {
|
|
@@ -379,6 +440,114 @@ export function Doc() {
|
|
|
379
440
|
void rootRef.current?.requestFullscreen?.().catch(() => {});
|
|
380
441
|
}, []);
|
|
381
442
|
|
|
443
|
+
const navigate = useNavigate();
|
|
444
|
+
const { setTheme } = useTheme();
|
|
445
|
+
const paletteItems = (query: string): PaletteItem[] => {
|
|
446
|
+
const items: PaletteItem[] = [];
|
|
447
|
+
const wanted = Number(query.replace(/^(p|page)\.?\s*/i, ''));
|
|
448
|
+
if (Number.isInteger(wanted) && wanted >= 1 && wanted <= pages.length) {
|
|
449
|
+
items.push({
|
|
450
|
+
id: 'page',
|
|
451
|
+
group: t('This document'),
|
|
452
|
+
label: t('Go to page {page}', { page: wanted }),
|
|
453
|
+
keywords: query,
|
|
454
|
+
pinned: true,
|
|
455
|
+
icon: ArrowDownToLine,
|
|
456
|
+
run: () => scrollToPage(wanted),
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
for (const entry of outline) {
|
|
460
|
+
items.push({
|
|
461
|
+
id: `section:${entry.id}`,
|
|
462
|
+
group: t('Sections'),
|
|
463
|
+
label: entry.text,
|
|
464
|
+
hint: t('p. {page}', { page: entry.page }),
|
|
465
|
+
icon: Hash,
|
|
466
|
+
run: () => scrollToEntry(entry),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
for (const group of DOWNLOAD_GROUPS) {
|
|
470
|
+
for (const { format, label, icon } of group.formats) {
|
|
471
|
+
items.push({
|
|
472
|
+
id: `download:${format}`,
|
|
473
|
+
group: t('Actions'),
|
|
474
|
+
label: t('Download as {format}', { format: t(label) }),
|
|
475
|
+
keywords: `export ${format}`,
|
|
476
|
+
icon,
|
|
477
|
+
run: () => void runDownload(format),
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
items.push(
|
|
482
|
+
{
|
|
483
|
+
id: 'layout:continuous',
|
|
484
|
+
group: t('Actions'),
|
|
485
|
+
label: t('Continuous layout'),
|
|
486
|
+
keywords: 'view pages',
|
|
487
|
+
icon: Rows3,
|
|
488
|
+
run: () => setViewMode('continuous'),
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
id: 'layout:spread',
|
|
492
|
+
group: t('Actions'),
|
|
493
|
+
label: t('Two-up layout'),
|
|
494
|
+
keywords: 'view spread pages',
|
|
495
|
+
icon: BookOpen,
|
|
496
|
+
run: () => setViewMode('spread'),
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
id: 'layout:grid',
|
|
500
|
+
group: t('Actions'),
|
|
501
|
+
label: t('Grid layout'),
|
|
502
|
+
keywords: 'view overview pages',
|
|
503
|
+
icon: LayoutGrid,
|
|
504
|
+
run: () => setViewMode('grid'),
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
id: 'fullscreen',
|
|
508
|
+
group: t('Actions'),
|
|
509
|
+
label: t('Fullscreen'),
|
|
510
|
+
hint: 'F',
|
|
511
|
+
icon: Maximize,
|
|
512
|
+
run: toggleFullscreen,
|
|
513
|
+
},
|
|
514
|
+
);
|
|
515
|
+
if (import.meta.env.DEV) {
|
|
516
|
+
items.push(
|
|
517
|
+
editing
|
|
518
|
+
? {
|
|
519
|
+
id: 'mode:preview',
|
|
520
|
+
group: t('Actions'),
|
|
521
|
+
label: t('Leave edit mode'),
|
|
522
|
+
keywords: 'preview read',
|
|
523
|
+
icon: Eye,
|
|
524
|
+
run: () => (leaveEditRef.current ? leaveEditRef.current() : setEditing(false)),
|
|
525
|
+
}
|
|
526
|
+
: {
|
|
527
|
+
id: 'mode:edit',
|
|
528
|
+
group: t('Actions'),
|
|
529
|
+
label: t('Edit on the page'),
|
|
530
|
+
keywords: 'edit mode text',
|
|
531
|
+
icon: Pencil,
|
|
532
|
+
run: () => setEditing(true),
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
id: 'design',
|
|
536
|
+
group: t('Actions'),
|
|
537
|
+
label: designOpen ? t('Close the design panel') : t('Open the design panel'),
|
|
538
|
+
hint: 'D',
|
|
539
|
+
keywords: 'design colours fonts',
|
|
540
|
+
icon: Palette,
|
|
541
|
+
run: () => setDesignOpen((open) => !open),
|
|
542
|
+
},
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
return [
|
|
546
|
+
...items,
|
|
547
|
+
...browserItems({ navigate, manifest: null, setTheme, setLocale, exclude: docId, t }),
|
|
548
|
+
];
|
|
549
|
+
};
|
|
550
|
+
|
|
382
551
|
useEffect(() => {
|
|
383
552
|
const onChange = () => setIsFullscreen(Boolean(document.fullscreenElement));
|
|
384
553
|
document.addEventListener('fullscreenchange', onChange);
|
|
@@ -418,7 +587,7 @@ export function Doc() {
|
|
|
418
587
|
if (state.status === 'error') {
|
|
419
588
|
return (
|
|
420
589
|
<Centered>
|
|
421
|
-
<p className="font-medium text-sm">Could not load “{docId}
|
|
590
|
+
<p className="font-medium text-sm">{t('Could not load “{id}”.', { id: docId ?? '' })}</p>
|
|
422
591
|
<p className="mt-1 text-muted-foreground text-xs">{state.error.message}</p>
|
|
423
592
|
<BackLink />
|
|
424
593
|
</Centered>
|
|
@@ -434,278 +603,274 @@ export function Doc() {
|
|
|
434
603
|
}
|
|
435
604
|
|
|
436
605
|
const view = (
|
|
437
|
-
<
|
|
438
|
-
{
|
|
606
|
+
<CommandPaletteProvider
|
|
607
|
+
items={paletteItems}
|
|
608
|
+
placeholder={t('Search sections, pages, actions and documents')}
|
|
609
|
+
>
|
|
610
|
+
<div ref={rootRef} className="flex h-screen flex-col bg-background text-foreground">
|
|
611
|
+
{/* Equal `1fr` rails put the title at the true centre of the bar rather
|
|
439
612
|
than the centre of what is left over, which is where a flex row would
|
|
440
613
|
drop it — the control cluster is many times wider than the back link.
|
|
441
614
|
The control rail keeps its automatic minimum — no `min-w-0` — so when
|
|
442
615
|
it outgrows its share the title truncates and slides instead of being
|
|
443
616
|
overlapped by it. */}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
<
|
|
617
|
+
{/* Three rails by job: where you are (back, title), how you are looking
|
|
618
|
+
(page, zoom, layout, fullscreen), and what you do to the document
|
|
619
|
+
(search, edit, design, download). The middle rail is `auto` between
|
|
620
|
+
two equal `1fr` rails, so it sits at the true centre of the bar while
|
|
621
|
+
the title truncates before anything is overlapped. */}
|
|
622
|
+
<header className="grid h-12 flex-none grid-cols-[1fr_auto_1fr] items-center gap-3 border-b border-border px-3">
|
|
623
|
+
<div className="flex min-w-0 items-center gap-1">
|
|
624
|
+
<HeaderBackLink />
|
|
625
|
+
<h1 className="truncate font-medium text-sm">{doc.meta?.title ?? docId}</h1>
|
|
626
|
+
</div>
|
|
450
627
|
|
|
451
|
-
|
|
452
|
-
<span className="hidden items-center gap-1.5 sm:flex">
|
|
628
|
+
<div className="hidden items-center gap-2 sm:flex">
|
|
453
629
|
<PageJump page={currentPage} total={pages.length} onJump={scrollToPage} />
|
|
454
|
-
<
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
630
|
+
<Divider />
|
|
631
|
+
<ZoomControl
|
|
632
|
+
scale={scale}
|
|
633
|
+
fit={manualScale === null ? zoomMode : null}
|
|
634
|
+
onStep={zoom}
|
|
635
|
+
onSet={setZoom}
|
|
636
|
+
onFit={fitTo}
|
|
637
|
+
/>
|
|
638
|
+
<Divider />
|
|
639
|
+
<fieldset className="flex items-center gap-0.5">
|
|
640
|
+
<legend className="sr-only">{t('Page layout')}</legend>
|
|
641
|
+
<IconButton
|
|
642
|
+
label={t('Continuous')}
|
|
643
|
+
active={viewMode === 'continuous'}
|
|
644
|
+
onClick={() => setViewMode('continuous')}
|
|
645
|
+
>
|
|
646
|
+
<Rows3 className="size-3.5" />
|
|
647
|
+
</IconButton>
|
|
648
|
+
<IconButton
|
|
649
|
+
label={t('Two-up')}
|
|
650
|
+
active={viewMode === 'spread'}
|
|
651
|
+
onClick={() => setViewMode('spread')}
|
|
652
|
+
>
|
|
653
|
+
<BookOpen className="size-3.5" />
|
|
654
|
+
</IconButton>
|
|
655
|
+
<IconButton
|
|
656
|
+
label={t('Grid')}
|
|
657
|
+
active={viewMode === 'grid'}
|
|
658
|
+
onClick={() => setViewMode('grid')}
|
|
659
|
+
>
|
|
660
|
+
<LayoutGrid className="size-3.5" />
|
|
661
|
+
</IconButton>
|
|
662
|
+
</fieldset>
|
|
483
663
|
<IconButton
|
|
484
|
-
label=
|
|
485
|
-
onClick={
|
|
486
|
-
active={manualScale === null && zoomMode === 'fit-page'}
|
|
664
|
+
label={isFullscreen ? t('Exit fullscreen (F)') : t('Fullscreen (F)')}
|
|
665
|
+
onClick={toggleFullscreen}
|
|
487
666
|
>
|
|
488
|
-
<
|
|
489
|
-
</IconButton>
|
|
490
|
-
<IconButton label="Actual size (100%)" onClick={actualSize}>
|
|
491
|
-
<Percent className="size-3.5" />
|
|
667
|
+
{isFullscreen ? <Minimize className="size-3.5" /> : <Maximize className="size-3.5" />}
|
|
492
668
|
</IconButton>
|
|
493
669
|
</div>
|
|
494
670
|
|
|
495
|
-
<
|
|
496
|
-
<
|
|
497
|
-
<IconButton
|
|
498
|
-
label="Continuous"
|
|
499
|
-
active={viewMode === 'continuous'}
|
|
500
|
-
onClick={() => setViewMode('continuous')}
|
|
501
|
-
>
|
|
502
|
-
<Rows3 className="size-3.5" />
|
|
503
|
-
</IconButton>
|
|
504
|
-
<IconButton
|
|
505
|
-
label="Two-up"
|
|
506
|
-
active={viewMode === 'spread'}
|
|
507
|
-
onClick={() => setViewMode('spread')}
|
|
508
|
-
>
|
|
509
|
-
<BookOpen className="size-3.5" />
|
|
510
|
-
</IconButton>
|
|
511
|
-
<IconButton
|
|
512
|
-
label="Grid"
|
|
513
|
-
active={viewMode === 'grid'}
|
|
514
|
-
onClick={() => setViewMode('grid')}
|
|
515
|
-
>
|
|
516
|
-
<LayoutGrid className="size-3.5" />
|
|
517
|
-
</IconButton>
|
|
518
|
-
</fieldset>
|
|
671
|
+
<div className="flex items-center justify-end gap-2">
|
|
672
|
+
<DocSearch scrollRef={scrollRef} pagesRef={pagesRef} onFoundPage={setCurrentPage} />
|
|
519
673
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
674
|
+
{import.meta.env.DEV && (
|
|
675
|
+
// Same two modes as open-slide: reading the document, or editing it
|
|
676
|
+
// where it is printed. Leaving edit mode saves unsaved text first.
|
|
677
|
+
<fieldset className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
|
|
678
|
+
<legend className="sr-only">{t('Mode')}</legend>
|
|
679
|
+
<IconButton
|
|
680
|
+
label={t('Preview')}
|
|
681
|
+
active={!editing}
|
|
682
|
+
onClick={() =>
|
|
683
|
+
leaveEditRef.current ? leaveEditRef.current() : setEditing(false)
|
|
684
|
+
}
|
|
685
|
+
>
|
|
686
|
+
<Eye className="size-3.5" />
|
|
687
|
+
</IconButton>
|
|
688
|
+
<IconButton label={t('Edit')} active={editing} onClick={() => setEditing(true)}>
|
|
689
|
+
<Pencil className="size-3.5" />
|
|
690
|
+
</IconButton>
|
|
691
|
+
</fieldset>
|
|
692
|
+
)}
|
|
693
|
+
{import.meta.env.DEV && (
|
|
694
|
+
<button
|
|
695
|
+
type="button"
|
|
696
|
+
aria-pressed={designOpen}
|
|
697
|
+
aria-label={t('Design')}
|
|
698
|
+
aria-keyshortcuts="D"
|
|
699
|
+
title={t('Design tokens (D)')}
|
|
700
|
+
onClick={() => setDesignOpen((open) => !open)}
|
|
701
|
+
className={cn(
|
|
702
|
+
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
703
|
+
designOpen && 'bg-accent',
|
|
704
|
+
)}
|
|
705
|
+
>
|
|
706
|
+
<Palette className="size-3.5" />
|
|
707
|
+
{t('Design')}
|
|
708
|
+
<kbd
|
|
709
|
+
aria-hidden
|
|
710
|
+
className="hidden rounded-sm bg-foreground/10 px-1 font-mono text-[9.5px] text-muted-foreground md:inline"
|
|
711
|
+
>
|
|
712
|
+
D
|
|
713
|
+
</kbd>
|
|
714
|
+
</button>
|
|
715
|
+
)}
|
|
526
716
|
|
|
527
|
-
|
|
717
|
+
<CopyLink />
|
|
718
|
+
|
|
719
|
+
{/* The document browser normally carries this. A viewer mounted with
|
|
528
720
|
`showDocBrowser: false` never shows that shell, and without it a
|
|
529
721
|
reader has no way to change the theme at all. */}
|
|
530
|
-
|
|
722
|
+
{!appConfig.build.showDocBrowser && <ThemeToggle />}
|
|
531
723
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
aria-pressed={designOpen}
|
|
553
|
-
aria-label="Design"
|
|
554
|
-
aria-keyshortcuts="D"
|
|
555
|
-
title="Design tokens (D)"
|
|
556
|
-
onClick={() => setDesignOpen((open) => !open)}
|
|
557
|
-
className={cn(
|
|
558
|
-
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
559
|
-
designOpen && 'bg-accent',
|
|
724
|
+
<Menu
|
|
725
|
+
className="w-[300px] p-1.5"
|
|
726
|
+
trigger={(props) => (
|
|
727
|
+
<button
|
|
728
|
+
type="button"
|
|
729
|
+
disabled={download !== null}
|
|
730
|
+
className="flex items-center gap-1.5 rounded-md bg-primary px-2.5 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-70 aria-expanded:opacity-90"
|
|
731
|
+
{...props}
|
|
732
|
+
>
|
|
733
|
+
{download ? (
|
|
734
|
+
<Loader2 className="size-3.5 animate-spin" />
|
|
735
|
+
) : downloaded ? (
|
|
736
|
+
<Check className="size-3.5" />
|
|
737
|
+
) : (
|
|
738
|
+
<Download className="size-3.5" />
|
|
739
|
+
)}
|
|
740
|
+
{download
|
|
741
|
+
? `${t(DOWNLOAD_LABEL[download.format])} ${Math.round(download.percent)}%`
|
|
742
|
+
: t('Download')}
|
|
743
|
+
</button>
|
|
560
744
|
)}
|
|
561
745
|
>
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
aria-hidden
|
|
566
|
-
className="hidden rounded-sm bg-foreground/10 px-1 font-mono text-[9.5px] text-muted-foreground md:inline"
|
|
567
|
-
>
|
|
568
|
-
D
|
|
569
|
-
</kbd>
|
|
570
|
-
</button>
|
|
571
|
-
)}
|
|
572
|
-
<Menu
|
|
573
|
-
trigger={(props) => (
|
|
574
|
-
<button
|
|
575
|
-
type="button"
|
|
576
|
-
disabled={download !== null}
|
|
577
|
-
className="flex items-center gap-1.5 rounded-md bg-primary px-2.5 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-70 aria-expanded:opacity-90"
|
|
578
|
-
{...props}
|
|
579
|
-
>
|
|
580
|
-
{download ? (
|
|
581
|
-
<Loader2 className="size-3.5 animate-spin" />
|
|
582
|
-
) : downloaded ? (
|
|
583
|
-
<Check className="size-3.5" />
|
|
584
|
-
) : (
|
|
585
|
-
<Download className="size-3.5" />
|
|
586
|
-
)}
|
|
587
|
-
{download
|
|
588
|
-
? `${DOWNLOAD_LABEL[download.format]} ${Math.round(download.percent)}%`
|
|
589
|
-
: 'Download'}
|
|
590
|
-
</button>
|
|
591
|
-
)}
|
|
592
|
-
>
|
|
593
|
-
{(close) => (
|
|
594
|
-
<>
|
|
595
|
-
{/* Which pages, before which format. A reader who picks PDF and
|
|
746
|
+
{(close) => (
|
|
747
|
+
<>
|
|
748
|
+
{/* Which pages, before which format. A reader who picks PDF and
|
|
596
749
|
then discovers they exported forty pages has already waited
|
|
597
750
|
for all forty. */}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
design={doc.design}
|
|
634
|
-
currentPage={currentPage}
|
|
635
|
-
entries={outline}
|
|
636
|
-
activeId={activeOutlineId}
|
|
637
|
-
onSelectPage={scrollToPage}
|
|
638
|
-
onSelectEntry={scrollToEntry}
|
|
639
|
-
/>
|
|
640
|
-
<div className="relative flex min-w-0 flex-1">
|
|
641
|
-
<div
|
|
642
|
-
ref={scrollRef}
|
|
643
|
-
data-od-viewer
|
|
644
|
-
className="relative min-w-0 flex-1 overflow-auto bg-canvas"
|
|
645
|
-
>
|
|
646
|
-
<div
|
|
647
|
-
ref={pagesRef}
|
|
648
|
-
data-od-view={viewMode}
|
|
649
|
-
className={cn(
|
|
650
|
-
viewMode === 'continuous' && 'flex flex-col items-center',
|
|
651
|
-
// Facing pages as a bound document is read: page 1 alone on
|
|
652
|
-
// the right, then 2–3, 4–5.
|
|
653
|
-
viewMode === 'spread' && 'grid justify-center [&>:first-child]:col-start-2',
|
|
654
|
-
// A contact sheet: columns that line up, the last row starting
|
|
655
|
-
// under the first sheet rather than centred in the gap.
|
|
656
|
-
viewMode === 'grid' && 'grid content-start justify-center',
|
|
751
|
+
<PageChoice
|
|
752
|
+
selection={selection}
|
|
753
|
+
custom={customRange}
|
|
754
|
+
currentPage={currentPage}
|
|
755
|
+
total={pages.length}
|
|
756
|
+
onSelection={setSelection}
|
|
757
|
+
onCustom={setCustomRange}
|
|
758
|
+
/>
|
|
759
|
+
{DOWNLOAD_GROUPS.map((group) => (
|
|
760
|
+
<fieldset key={group.label}>
|
|
761
|
+
<legend className={MENU_LABEL}>{t(group.label)}</legend>
|
|
762
|
+
{group.formats.map(({ format, label, hint, ext, icon: Icon }) => (
|
|
763
|
+
<MenuItem
|
|
764
|
+
key={format}
|
|
765
|
+
disabled={!chosenPages.valid}
|
|
766
|
+
onClick={() => {
|
|
767
|
+
close();
|
|
768
|
+
void runDownload(format);
|
|
769
|
+
}}
|
|
770
|
+
>
|
|
771
|
+
<Icon className="size-4 flex-none text-muted-foreground" />
|
|
772
|
+
<span className="min-w-0 flex-1">
|
|
773
|
+
<span className="block font-medium">{t(label)}</span>
|
|
774
|
+
<span className="block truncate text-[10.5px] text-muted-foreground">
|
|
775
|
+
{t(hint)}
|
|
776
|
+
</span>
|
|
777
|
+
</span>
|
|
778
|
+
<span className="flex-none font-mono text-[10px] text-muted-foreground">
|
|
779
|
+
{ext}
|
|
780
|
+
</span>
|
|
781
|
+
</MenuItem>
|
|
782
|
+
))}
|
|
783
|
+
</fieldset>
|
|
784
|
+
))}
|
|
785
|
+
</>
|
|
657
786
|
)}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
787
|
+
</Menu>
|
|
788
|
+
</div>
|
|
789
|
+
</header>
|
|
790
|
+
|
|
791
|
+
<div className="flex min-h-0 flex-1">
|
|
792
|
+
<DocSidebar
|
|
793
|
+
docId={docId ?? ''}
|
|
794
|
+
pages={pages}
|
|
795
|
+
geometry={geometry}
|
|
796
|
+
design={doc.design}
|
|
797
|
+
currentPage={currentPage}
|
|
798
|
+
entries={outline}
|
|
799
|
+
activeId={activeOutlineId}
|
|
800
|
+
onSelectPage={scrollToPage}
|
|
801
|
+
onSelectEntry={scrollToEntry}
|
|
802
|
+
/>
|
|
803
|
+
<div className="relative flex min-w-0 flex-1">
|
|
804
|
+
<div
|
|
805
|
+
ref={scrollRef}
|
|
806
|
+
data-od-viewer
|
|
807
|
+
className="relative min-w-0 flex-1 overflow-auto bg-canvas md:my-2 md:mr-2 md:rounded-xl md:border md:border-border"
|
|
667
808
|
>
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
809
|
+
<div
|
|
810
|
+
ref={pagesRef}
|
|
811
|
+
data-od-view={viewMode}
|
|
812
|
+
className={cn(
|
|
813
|
+
viewMode === 'continuous' && 'flex flex-col items-center',
|
|
814
|
+
// Facing pages as a bound document is read: page 1 alone on
|
|
815
|
+
// the right, then 2–3, 4–5.
|
|
816
|
+
viewMode === 'spread' && 'grid justify-center [&>:first-child]:col-start-2',
|
|
817
|
+
// A contact sheet: columns that line up, the last row starting
|
|
818
|
+
// under the first sheet rather than centred in the gap.
|
|
819
|
+
viewMode === 'grid' && 'grid content-start justify-center',
|
|
820
|
+
)}
|
|
821
|
+
style={{
|
|
822
|
+
gap: PAGE_GAP,
|
|
823
|
+
padding: `${GUTTER}px ${GUTTER}px ${GUTTER * 1.5}px`,
|
|
824
|
+
...(viewMode === 'spread'
|
|
825
|
+
? { gridTemplateColumns: `repeat(2, ${geometry.width * scale}px)` }
|
|
826
|
+
: viewMode === 'grid'
|
|
827
|
+
? { gridTemplateColumns: `repeat(auto-fill, ${geometry.width * scale}px)` }
|
|
828
|
+
: {}),
|
|
829
|
+
}}
|
|
830
|
+
>
|
|
831
|
+
{pages.map((page, index) => (
|
|
832
|
+
<PageFrame
|
|
833
|
+
key={page.key}
|
|
834
|
+
index={index}
|
|
835
|
+
total={pages.length}
|
|
836
|
+
geometry={geometry}
|
|
837
|
+
scale={scale}
|
|
838
|
+
design={doc.design}
|
|
839
|
+
>
|
|
840
|
+
{page.content}
|
|
841
|
+
</PageFrame>
|
|
842
|
+
))}
|
|
843
|
+
</div>
|
|
680
844
|
</div>
|
|
845
|
+
{import.meta.env.DEV && docId && (
|
|
846
|
+
<EditSaveCard
|
|
847
|
+
textCount={textPending}
|
|
848
|
+
controlsRef={editControlsRef}
|
|
849
|
+
onShownChange={setCardShown}
|
|
850
|
+
/>
|
|
851
|
+
)}
|
|
681
852
|
</div>
|
|
682
|
-
{
|
|
683
|
-
|
|
684
|
-
|
|
853
|
+
{editing && docId && (
|
|
854
|
+
// Keyed by document: a selection, or an editor carried across a
|
|
855
|
+
// reload by source location, must never follow into another
|
|
856
|
+
// document where the same line:column is something else entirely.
|
|
857
|
+
<Inspector
|
|
858
|
+
key={docId}
|
|
859
|
+
docId={docId}
|
|
860
|
+
containerRef={scrollRef}
|
|
861
|
+
panelHidden={designOpen}
|
|
862
|
+
onPick={closeDesign}
|
|
863
|
+
quiet={cardShown}
|
|
864
|
+
onExit={() => setEditing(false)}
|
|
865
|
+
exitRef={leaveEditRef}
|
|
685
866
|
controlsRef={editControlsRef}
|
|
686
|
-
|
|
867
|
+
onPendingChange={setTextPending}
|
|
687
868
|
/>
|
|
688
869
|
)}
|
|
870
|
+
{designOpen && <DesignPanel onClose={() => setDesignOpen(false)} />}
|
|
689
871
|
</div>
|
|
690
|
-
{editing && docId && (
|
|
691
|
-
// Keyed by document: a selection, or an editor carried across a
|
|
692
|
-
// reload by source location, must never follow into another
|
|
693
|
-
// document where the same line:column is something else entirely.
|
|
694
|
-
<Inspector
|
|
695
|
-
key={docId}
|
|
696
|
-
docId={docId}
|
|
697
|
-
containerRef={scrollRef}
|
|
698
|
-
panelHidden={designOpen}
|
|
699
|
-
quiet={cardShown}
|
|
700
|
-
onExit={() => setEditing(false)}
|
|
701
|
-
exitRef={leaveEditRef}
|
|
702
|
-
controlsRef={editControlsRef}
|
|
703
|
-
onPendingChange={setTextPending}
|
|
704
|
-
/>
|
|
705
|
-
)}
|
|
706
|
-
{designOpen && <DesignPanel onClose={() => setDesignOpen(false)} />}
|
|
707
872
|
</div>
|
|
708
|
-
</
|
|
873
|
+
</CommandPaletteProvider>
|
|
709
874
|
);
|
|
710
875
|
|
|
711
876
|
// The design panel writes back to source through the dev server, so it only
|
|
@@ -725,6 +890,8 @@ export function Doc() {
|
|
|
725
890
|
* 自訂欄位只在被選中時出現。三個選項配一個永遠佔著位置的空欄位,會讓人以為那是
|
|
726
891
|
* 必填的。
|
|
727
892
|
*/
|
|
893
|
+
const MENU_LABEL = 'px-2 pt-2 pb-1 text-[10px] text-muted-foreground uppercase tracking-wide';
|
|
894
|
+
|
|
728
895
|
function PageChoice({
|
|
729
896
|
selection,
|
|
730
897
|
custom,
|
|
@@ -740,65 +907,100 @@ function PageChoice({
|
|
|
740
907
|
onSelection: (selection: PageSelection) => void;
|
|
741
908
|
onCustom: (text: string) => void;
|
|
742
909
|
}) {
|
|
910
|
+
const t = useT();
|
|
911
|
+
const rangeRef = useRef<HTMLInputElement>(null);
|
|
743
912
|
const options = [
|
|
744
|
-
{ kind: 'all' as const, label: 'All',
|
|
745
|
-
{ kind: 'current' as const, label: 'This page',
|
|
746
|
-
{ kind: 'custom' as const, label: '
|
|
913
|
+
{ kind: 'all' as const, label: t('All'), count: total },
|
|
914
|
+
{ kind: 'current' as const, label: t('This page'), count: currentPage },
|
|
915
|
+
{ kind: 'custom' as const, label: t('Range'), count: null },
|
|
747
916
|
];
|
|
748
|
-
const
|
|
749
|
-
selection.kind === 'custom' ? { kind: 'custom', text: custom } : selection
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
917
|
+
const current =
|
|
918
|
+
selection.kind === 'custom' ? { kind: 'custom' as const, text: custom } : selection;
|
|
919
|
+
const pages = resolveSelection(current, total, currentPage);
|
|
920
|
+
|
|
921
|
+
// Choosing a range is choosing to type one.
|
|
922
|
+
useEffect(() => {
|
|
923
|
+
if (selection.kind === 'custom') rangeRef.current?.focus();
|
|
924
|
+
}, [selection.kind]);
|
|
925
|
+
|
|
926
|
+
const summary =
|
|
927
|
+
pages === null
|
|
928
|
+
? selection.kind === 'custom' && custom.trim() !== ''
|
|
929
|
+
? t('No such pages — this document has {total}', { total })
|
|
930
|
+
: t('Type pages, like 1-3, 6')
|
|
931
|
+
: selection.kind === 'all'
|
|
932
|
+
? total === 1
|
|
933
|
+
? t('All 1 page')
|
|
934
|
+
: t('All {count} pages', { count: total })
|
|
935
|
+
: pages.length === 1
|
|
936
|
+
? t('Page {pages} · 1 page', { pages: formatPages(pages) })
|
|
937
|
+
: t('Pages {pages} · {count} pages', {
|
|
938
|
+
pages: formatPages(pages),
|
|
939
|
+
count: pages.length,
|
|
940
|
+
});
|
|
753
941
|
|
|
754
942
|
return (
|
|
755
|
-
<
|
|
756
|
-
<
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
943
|
+
<fieldset className="border-border border-b pb-2">
|
|
944
|
+
<legend className={MENU_LABEL}>{t('Pages')}</legend>
|
|
945
|
+
{/* One row of equal segments; labels never wrap, so a two-word option
|
|
946
|
+
doesn't stand taller than its neighbours. */}
|
|
947
|
+
<div
|
|
948
|
+
role="radiogroup"
|
|
949
|
+
aria-label={t('Pages to download')}
|
|
950
|
+
className="mx-1 grid grid-cols-3 gap-0.5 rounded-md bg-muted p-0.5"
|
|
951
|
+
>
|
|
952
|
+
{options.map((option) => {
|
|
953
|
+
const active = selection.kind === option.kind;
|
|
954
|
+
return (
|
|
955
|
+
<button
|
|
956
|
+
key={option.kind}
|
|
957
|
+
type="button"
|
|
958
|
+
aria-pressed={active}
|
|
959
|
+
onClick={(event) => {
|
|
960
|
+
event.stopPropagation();
|
|
961
|
+
onSelection(
|
|
962
|
+
option.kind === 'custom'
|
|
963
|
+
? { kind: 'custom', text: custom }
|
|
964
|
+
: { kind: option.kind },
|
|
965
|
+
);
|
|
966
|
+
}}
|
|
967
|
+
className={cn(
|
|
968
|
+
'flex h-7 items-center justify-center gap-1 whitespace-nowrap rounded px-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground',
|
|
969
|
+
active && 'bg-background text-foreground shadow-sm',
|
|
970
|
+
)}
|
|
971
|
+
>
|
|
972
|
+
{option.label}
|
|
973
|
+
{option.count !== null && (
|
|
974
|
+
<span className="font-mono text-[10px] text-muted-foreground tabular-nums">
|
|
975
|
+
{option.count}
|
|
976
|
+
</span>
|
|
977
|
+
)}
|
|
978
|
+
</button>
|
|
979
|
+
);
|
|
980
|
+
})}
|
|
781
981
|
</div>
|
|
782
982
|
{selection.kind === 'custom' && (
|
|
783
983
|
<input
|
|
984
|
+
ref={rangeRef}
|
|
784
985
|
value={custom}
|
|
785
986
|
onChange={(event) => onCustom(event.target.value)}
|
|
786
987
|
onClick={(event) => event.stopPropagation()}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
aria-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
)}
|
|
988
|
+
onKeyDown={(event) => event.stopPropagation()}
|
|
989
|
+
placeholder="1-3, 6"
|
|
990
|
+
aria-label={t('Page range')}
|
|
991
|
+
aria-invalid={pages === null && custom.trim() !== ''}
|
|
992
|
+
aria-describedby="od-download-pages"
|
|
993
|
+
className="mx-1 mt-1.5 h-7 w-[calc(100%-0.5rem)] rounded border border-border bg-background px-2 font-mono text-[11px] outline-none placeholder:text-muted-foreground focus-visible:border-foreground focus-visible:ring-2 focus-visible:ring-primary/30 aria-invalid:border-foreground/60"
|
|
794
994
|
/>
|
|
795
995
|
)}
|
|
796
|
-
<p
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
996
|
+
<p
|
|
997
|
+
id="od-download-pages"
|
|
998
|
+
aria-live="polite"
|
|
999
|
+
className="px-2 pt-1.5 text-[10.5px] text-muted-foreground"
|
|
1000
|
+
>
|
|
1001
|
+
{summary}
|
|
800
1002
|
</p>
|
|
801
|
-
</
|
|
1003
|
+
</fieldset>
|
|
802
1004
|
);
|
|
803
1005
|
}
|
|
804
1006
|
|
|
@@ -817,6 +1019,7 @@ function PageJump({
|
|
|
817
1019
|
total: number;
|
|
818
1020
|
onJump: (page: number) => void;
|
|
819
1021
|
}) {
|
|
1022
|
+
const t = useT();
|
|
820
1023
|
const [draft, setDraft] = useState<string | null>(null);
|
|
821
1024
|
|
|
822
1025
|
const commit = (raw: string) => {
|
|
@@ -828,6 +1031,8 @@ function PageJump({
|
|
|
828
1031
|
|
|
829
1032
|
return (
|
|
830
1033
|
<span className="flex items-center whitespace-nowrap font-mono text-muted-foreground text-xs tabular-nums">
|
|
1034
|
+
{/* A bordered field, not bare digits: a number that looks like a label
|
|
1035
|
+
reads as one, and nobody thinks to type into it. */}
|
|
831
1036
|
<input
|
|
832
1037
|
value={draft ?? String(page)}
|
|
833
1038
|
onChange={(event) => setDraft(event.target.value)}
|
|
@@ -846,10 +1051,11 @@ function PageJump({
|
|
|
846
1051
|
event.currentTarget.blur();
|
|
847
1052
|
}
|
|
848
1053
|
}}
|
|
849
|
-
aria-label={
|
|
850
|
-
title=
|
|
1054
|
+
aria-label={t('Page number, {total} pages', { total })}
|
|
1055
|
+
title={t('Go to page')}
|
|
851
1056
|
inputMode="numeric"
|
|
852
|
-
className=
|
|
1057
|
+
className={FIELD_CLASS}
|
|
1058
|
+
style={{ width: `${Math.max(2, String(total).length) + 2}ch` }}
|
|
853
1059
|
/>
|
|
854
1060
|
<span className="px-1">/</span>
|
|
855
1061
|
<span>{total}</span>
|
|
@@ -857,6 +1063,157 @@ function PageJump({
|
|
|
857
1063
|
);
|
|
858
1064
|
}
|
|
859
1065
|
|
|
1066
|
+
const FIELD_CLASS =
|
|
1067
|
+
'h-6 rounded border border-border bg-background px-1 text-center text-foreground outline-none transition-colors hover:border-muted-foreground/50 focus-visible:border-foreground focus-visible:ring-2 focus-visible:ring-primary/30';
|
|
1068
|
+
|
|
1069
|
+
function Divider() {
|
|
1070
|
+
return <span aria-hidden className="mx-0.5 h-4 w-px bg-border" />;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
const ZOOM_PRESETS = [50, 75, 100, 125, 150, 200];
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* The zoom as a field you can type into, with the fits and common sizes one
|
|
1077
|
+
* menu away. It replaces a read-only percentage beside three icon buttons —
|
|
1078
|
+
* fit width, fit page, and actual size — the last of which did exactly what
|
|
1079
|
+
* clicking the percentage already did.
|
|
1080
|
+
*/
|
|
1081
|
+
function ZoomControl({
|
|
1082
|
+
scale,
|
|
1083
|
+
fit,
|
|
1084
|
+
onStep,
|
|
1085
|
+
onSet,
|
|
1086
|
+
onFit,
|
|
1087
|
+
}: {
|
|
1088
|
+
scale: number;
|
|
1089
|
+
/** The fit in force, or null once the reader has set a size by hand. */
|
|
1090
|
+
fit: 'auto' | 'fit-width' | 'fit-page' | null;
|
|
1091
|
+
onStep: (delta: number) => void;
|
|
1092
|
+
onSet: (scale: number) => void;
|
|
1093
|
+
onFit: (mode: 'fit-width' | 'fit-page') => void;
|
|
1094
|
+
}) {
|
|
1095
|
+
const t = useT();
|
|
1096
|
+
const [draft, setDraft] = useState<string | null>(null);
|
|
1097
|
+
const percent = Math.round(scale * 100);
|
|
1098
|
+
|
|
1099
|
+
const commit = (raw: string) => {
|
|
1100
|
+
setDraft(null);
|
|
1101
|
+
const digits = raw.replace(/[0-9]/g, (d) => String(d.charCodeAt(0) - 0xff10));
|
|
1102
|
+
const wanted = Number.parseFloat(digits.replace(/[%\s]/g, ''));
|
|
1103
|
+
if (Number.isFinite(wanted) && wanted > 0) onSet(wanted / 100);
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
return (
|
|
1107
|
+
<div className="flex items-center gap-0.5">
|
|
1108
|
+
<IconButton label={t('Zoom out')} onClick={() => onStep(-0.1)}>
|
|
1109
|
+
<Minus className="size-3.5" />
|
|
1110
|
+
</IconButton>
|
|
1111
|
+
<input
|
|
1112
|
+
value={draft ?? `${percent}%`}
|
|
1113
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
1114
|
+
onFocus={(event) => {
|
|
1115
|
+
setDraft(String(percent));
|
|
1116
|
+
requestAnimationFrame(() => event.target.select());
|
|
1117
|
+
}}
|
|
1118
|
+
onBlur={(event) => commit(event.target.value)}
|
|
1119
|
+
onKeyDown={(event) => {
|
|
1120
|
+
if (event.key === 'Enter') {
|
|
1121
|
+
event.preventDefault();
|
|
1122
|
+
event.currentTarget.blur();
|
|
1123
|
+
}
|
|
1124
|
+
if (event.key === 'Escape') {
|
|
1125
|
+
setDraft(null);
|
|
1126
|
+
event.currentTarget.blur();
|
|
1127
|
+
}
|
|
1128
|
+
}}
|
|
1129
|
+
aria-label={t('Zoom level, percent')}
|
|
1130
|
+
title={t('Type a zoom level')}
|
|
1131
|
+
inputMode="decimal"
|
|
1132
|
+
className={cn(FIELD_CLASS, 'w-[6ch] font-mono text-xs tabular-nums')}
|
|
1133
|
+
/>
|
|
1134
|
+
<IconButton label={t('Zoom in')} onClick={() => onStep(0.1)}>
|
|
1135
|
+
<Plus className="size-3.5" />
|
|
1136
|
+
</IconButton>
|
|
1137
|
+
<Menu
|
|
1138
|
+
placement="bottom-start"
|
|
1139
|
+
trigger={(props) => (
|
|
1140
|
+
<button
|
|
1141
|
+
type="button"
|
|
1142
|
+
aria-label={t('Zoom options')}
|
|
1143
|
+
title={t('Zoom options')}
|
|
1144
|
+
className="flex h-6 w-5 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground aria-expanded:bg-accent aria-expanded:text-foreground"
|
|
1145
|
+
{...props}
|
|
1146
|
+
>
|
|
1147
|
+
<ChevronDown className="size-3.5" />
|
|
1148
|
+
</button>
|
|
1149
|
+
)}
|
|
1150
|
+
>
|
|
1151
|
+
{(close) => (
|
|
1152
|
+
<>
|
|
1153
|
+
<MenuItem
|
|
1154
|
+
active={fit === 'fit-width'}
|
|
1155
|
+
onClick={() => {
|
|
1156
|
+
onFit('fit-width');
|
|
1157
|
+
close();
|
|
1158
|
+
}}
|
|
1159
|
+
>
|
|
1160
|
+
<MoveHorizontal className="size-3.5" />
|
|
1161
|
+
{t('Fit width')}
|
|
1162
|
+
</MenuItem>
|
|
1163
|
+
<MenuItem
|
|
1164
|
+
active={fit === 'fit-page'}
|
|
1165
|
+
onClick={() => {
|
|
1166
|
+
onFit('fit-page');
|
|
1167
|
+
close();
|
|
1168
|
+
}}
|
|
1169
|
+
>
|
|
1170
|
+
<MoveVertical className="size-3.5" />
|
|
1171
|
+
{t('Fit page')}
|
|
1172
|
+
</MenuItem>
|
|
1173
|
+
<div aria-hidden className="my-1 h-px bg-border" />
|
|
1174
|
+
{ZOOM_PRESETS.map((value) => (
|
|
1175
|
+
<MenuItem
|
|
1176
|
+
key={value}
|
|
1177
|
+
active={fit === null && percent === value}
|
|
1178
|
+
onClick={() => {
|
|
1179
|
+
onSet(value / 100);
|
|
1180
|
+
close();
|
|
1181
|
+
}}
|
|
1182
|
+
>
|
|
1183
|
+
<span className="w-3.5" />
|
|
1184
|
+
{value === 100 ? t('Actual size (100%)') : `${value}%`}
|
|
1185
|
+
</MenuItem>
|
|
1186
|
+
))}
|
|
1187
|
+
</>
|
|
1188
|
+
)}
|
|
1189
|
+
</Menu>
|
|
1190
|
+
</div>
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/** The page as it is — document, and the reader's place in it — on the clipboard. */
|
|
1195
|
+
function CopyLink() {
|
|
1196
|
+
const t = useT();
|
|
1197
|
+
const [copied, setCopied] = useState(false);
|
|
1198
|
+
return (
|
|
1199
|
+
<button
|
|
1200
|
+
type="button"
|
|
1201
|
+
aria-label={copied ? t('Link copied') : t('Copy link')}
|
|
1202
|
+
title={t('Copy link')}
|
|
1203
|
+
onClick={async () => {
|
|
1204
|
+
try {
|
|
1205
|
+
await navigator.clipboard.writeText(window.location.href);
|
|
1206
|
+
setCopied(true);
|
|
1207
|
+
setTimeout(() => setCopied(false), 1500);
|
|
1208
|
+
} catch {}
|
|
1209
|
+
}}
|
|
1210
|
+
className="flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
|
1211
|
+
>
|
|
1212
|
+
{copied ? <Check className="size-4" /> : <Link2 className="size-4" />}
|
|
1213
|
+
</button>
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
860
1217
|
function IconButton({
|
|
861
1218
|
label,
|
|
862
1219
|
onClick,
|
|
@@ -894,14 +1251,15 @@ function Centered({ children }: { children: React.ReactNode }) {
|
|
|
894
1251
|
}
|
|
895
1252
|
|
|
896
1253
|
function BackLink() {
|
|
1254
|
+
const t = useT();
|
|
897
1255
|
const className = 'mt-4 inline-block text-muted-foreground text-xs underline';
|
|
898
1256
|
return appConfig.home === undefined ? (
|
|
899
1257
|
<Link to="/" className={className}>
|
|
900
|
-
Back to documents
|
|
1258
|
+
{t('Back to documents')}
|
|
901
1259
|
</Link>
|
|
902
1260
|
) : (
|
|
903
1261
|
<a href={appConfig.home} className={className}>
|
|
904
|
-
Back to workspace
|
|
1262
|
+
{t('Back to workspace')}
|
|
905
1263
|
</a>
|
|
906
1264
|
);
|
|
907
1265
|
}
|