@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.
Files changed (86) hide show
  1. package/dist/{build-B0GJXy8I.js → build-BHFGY8eF.js} +1 -1
  2. package/dist/{check-CuDIWsPT.js → check-UEBmDfT_.js} +3 -3
  3. package/dist/cli/bin.js +10 -6
  4. package/dist/{config-CAZ7Z_va.js → config-B_pdNbYg.js} +1166 -591
  5. package/dist/{context-PWAh9qbf.js → context-BM9_-u9P.js} +1 -1
  6. package/dist/{dev-CYqppXDI.js → dev-DX3QMIRi.js} +1 -1
  7. package/dist/{diagram-CCaUUnRe.js → diagram-BK4jTZr4.js} +146 -146
  8. package/dist/diff-DayvbXfX.js +44 -0
  9. package/dist/{export-1JtO2OMC.js → export-BPsXj1i6.js} +3 -3
  10. package/dist/{import-CsrdBOZ8.js → import-71wlAsrd.js} +2 -2
  11. package/dist/index.d.ts +53 -2
  12. package/dist/index.js +457 -18
  13. package/dist/ops/index.d.ts +72 -17
  14. package/dist/ops/index.js +3 -3
  15. package/dist/{ops-B2y9BMpk.js → ops-BUo67DaP.js} +642 -124
  16. package/dist/{preview-DW3PM-JV.js → preview-D3m1-gUL.js} +1 -1
  17. package/dist/{sdk-BqU6mwD_.d.ts → sdk-CpDEGRIo.d.ts} +2 -0
  18. package/dist/vite/index.js +1 -1
  19. package/package.json +2 -2
  20. package/skills/doc-authoring/SKILL.md +9 -4
  21. package/skills/doc-authoring/references/pagination.md +1 -1
  22. package/skills/doc-authoring/references/tables-and-charts.md +18 -1
  23. package/src/app/components/browser/browser-ui.tsx +105 -0
  24. package/src/app/components/chart.tsx +239 -0
  25. package/src/app/components/command-palette.tsx +284 -0
  26. package/src/app/components/design-panel/design-panel.tsx +22 -20
  27. package/src/app/components/design-panel/design-provider.tsx +4 -2
  28. package/src/app/components/diagram.tsx +11 -1
  29. package/src/app/components/doc-assets.tsx +6 -5
  30. package/src/app/components/doc-search.tsx +12 -10
  31. package/src/app/components/doc-sidebar.tsx +24 -18
  32. package/src/app/components/flow-page.tsx +2 -0
  33. package/src/app/components/inspector/format-section.tsx +434 -0
  34. package/src/app/components/inspector/inspector.tsx +310 -89
  35. package/src/app/components/inspector/use-style-edits.ts +210 -0
  36. package/src/app/components/language-toggle.tsx +38 -0
  37. package/src/app/components/palette-items.ts +128 -0
  38. package/src/app/components/panel/edit-save-card.tsx +4 -2
  39. package/src/app/components/panel/fields.tsx +100 -9
  40. package/src/app/components/panel/save-card.tsx +18 -10
  41. package/src/app/components/sidebar/folder-item.tsx +10 -8
  42. package/src/app/components/sidebar/icon-picker.tsx +3 -1
  43. package/src/app/components/sidebar/sidebar.tsx +44 -13
  44. package/src/app/components/theme-toggle.tsx +5 -3
  45. package/src/app/components/ui/menu.tsx +5 -0
  46. package/src/app/lib/agent-bridge.ts +8 -2
  47. package/src/app/lib/chart.test.ts +108 -0
  48. package/src/app/lib/chart.ts +343 -0
  49. package/src/app/lib/doc-preview.tsx +0 -10
  50. package/src/app/lib/docs.ts +3 -0
  51. package/src/app/lib/docx/from-dom.ts +11 -11
  52. package/src/app/lib/docx/ooxml.test.ts +25 -9
  53. package/src/app/lib/docx/ooxml.ts +58 -37
  54. package/src/app/lib/export-docx.ts +13 -8
  55. package/src/app/lib/flow.ts +1 -1
  56. package/src/app/lib/i18n-ja/browser.ts +88 -0
  57. package/src/app/lib/i18n-ja/doc.ts +65 -0
  58. package/src/app/lib/i18n-ja/index.ts +5 -0
  59. package/src/app/lib/i18n-ja/panels.ts +151 -0
  60. package/src/app/lib/i18n-ko/browser.ts +87 -0
  61. package/src/app/lib/i18n-ko/doc.ts +65 -0
  62. package/src/app/lib/i18n-ko/index.ts +5 -0
  63. package/src/app/lib/i18n-ko/panels.ts +148 -0
  64. package/src/app/lib/i18n-zh-cn/browser.ts +84 -0
  65. package/src/app/lib/i18n-zh-cn/doc.ts +64 -0
  66. package/src/app/lib/i18n-zh-cn/index.ts +5 -0
  67. package/src/app/lib/i18n-zh-cn/panels.ts +143 -0
  68. package/src/app/lib/i18n-zh-tw/browser.ts +84 -0
  69. package/src/app/lib/i18n-zh-tw/doc.ts +64 -0
  70. package/src/app/lib/i18n-zh-tw/index.ts +5 -0
  71. package/src/app/lib/i18n-zh-tw/panels.ts +144 -0
  72. package/src/app/lib/i18n.test.ts +24 -0
  73. package/src/app/lib/i18n.tsx +109 -0
  74. package/src/app/lib/inspector/format.ts +156 -0
  75. package/src/app/lib/outline.ts +23 -0
  76. package/src/app/lib/page-range.test.ts +10 -1
  77. package/src/app/lib/page-range.ts +26 -0
  78. package/src/app/lib/sdk.ts +2 -0
  79. package/src/app/main.tsx +4 -1
  80. package/src/app/routes/assets.tsx +193 -132
  81. package/src/app/routes/doc.tsx +668 -310
  82. package/src/app/routes/home-shell.tsx +115 -88
  83. package/src/app/routes/home.tsx +200 -67
  84. package/src/app/routes/themes.tsx +42 -35
  85. package/src/app/styles.css +84 -5
  86. package/src/app/virtual.d.ts +1 -0
@@ -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 { describeSelection, type PageSelection, resolveSelection } from '../lib/page-range';
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
- const DOWNLOAD_FORMATS = [
70
- { format: 'pdf' as const, label: 'PDF', hint: 'True page size, print-ready', icon: FileText },
71
- { format: 'html' as const, label: 'HTML', hint: 'Self-contained, printable', icon: FileCode2 },
72
- { format: 'png' as const, label: 'PNG', hint: 'Pixels, 2x — for slides and chat', icon: Image },
73
- { format: 'svg' as const, label: 'SVG', hint: 'Vector, keeps text as text', icon: FileImage },
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
- format: 'docx' as const,
76
- label: 'Word (DOCX)',
77
- hint: 'Editable — Word lays out the pages',
78
- icon: FileType2,
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="Back to workspace">
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="Back to documents">
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 actualSize = () => {
430
+ const setZoom = (value: number) => {
370
431
  setZoomMode('auto');
371
- setManualScale(1);
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}”.</p>
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
- <div ref={rootRef} className="flex h-screen flex-col bg-background text-foreground">
438
- {/* Equal `1fr` rails put the title at the true centre of the bar rather
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
- <header className="grid h-12 flex-none grid-cols-[1fr_minmax(0,auto)_1fr] items-center gap-3 border-b border-border px-3">
445
- <div className="flex min-w-0 items-center">
446
- <HeaderBackLink />
447
- </div>
448
-
449
- <h1 className="truncate text-center font-medium text-sm">{doc.meta?.title ?? docId}</h1>
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
- <div className="flex items-center justify-end gap-3">
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
- <DocSearch scrollRef={scrollRef} pagesRef={pagesRef} onFoundPage={setCurrentPage} />
455
- </span>
456
-
457
- <div className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
458
- <IconButton label="Zoom out" onClick={() => zoom(-0.1)}>
459
- <Minus className="size-3.5" />
460
- </IconButton>
461
- <button
462
- type="button"
463
- onClick={actualSize}
464
- title="Actual size (100%)"
465
- className="w-11 rounded text-center font-mono text-[11px] tabular-nums transition-colors hover:bg-accent"
466
- >
467
- {Math.round(scale * 100)}%
468
- </button>
469
- <IconButton label="Zoom in" onClick={() => zoom(0.1)}>
470
- <Plus className="size-3.5" />
471
- </IconButton>
472
- <IconButton
473
- label="Fit width"
474
- onClick={() => fitTo('fit-width')}
475
- active={manualScale === null && zoomMode === 'fit-width'}
476
- >
477
- <MoveHorizontal className="size-3.5" />
478
- </IconButton>
479
- {/* Fit-width moves the page sideways to the edges, fit-page moves it
480
- up and down to them. Both used to be a square-ish glyph, and the
481
- fit-page one was the same square as fullscreen — three controls,
482
- two shapes, no way to tell which did what without clicking. */}
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="Fit page"
485
- onClick={() => fitTo('fit-page')}
486
- active={manualScale === null && zoomMode === 'fit-page'}
664
+ label={isFullscreen ? t('Exit fullscreen (F)') : t('Fullscreen (F)')}
665
+ onClick={toggleFullscreen}
487
666
  >
488
- <MoveVertical className="size-3.5" />
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
- <fieldset className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
496
- <legend className="sr-only">Page layout</legend>
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
- <IconButton
521
- label={isFullscreen ? 'Exit fullscreen (F)' : 'Fullscreen (F)'}
522
- onClick={toggleFullscreen}
523
- >
524
- {isFullscreen ? <Minimize className="size-4" /> : <Maximize className="size-4" />}
525
- </IconButton>
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
- {/* The document browser normally carries this. A viewer mounted with
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
- {!appConfig.build.showDocBrowser && <ThemeToggle />}
722
+ {!appConfig.build.showDocBrowser && <ThemeToggle />}
531
723
 
532
- {import.meta.env.DEV && (
533
- // Same two modes as open-slide: reading the document, or editing it
534
- // where it is printed. Leaving edit mode saves unsaved text first.
535
- <fieldset className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
536
- <legend className="sr-only">Mode</legend>
537
- <IconButton
538
- label="Preview"
539
- active={!editing}
540
- onClick={() => (leaveEditRef.current ? leaveEditRef.current() : setEditing(false))}
541
- >
542
- <Eye className="size-3.5" />
543
- </IconButton>
544
- <IconButton label="Edit" active={editing} onClick={() => setEditing(true)}>
545
- <Pencil className="size-3.5" />
546
- </IconButton>
547
- </fieldset>
548
- )}
549
- {import.meta.env.DEV && (
550
- <button
551
- type="button"
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
- <Palette className="size-3.5" />
563
- Design
564
- <kbd
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
- <PageChoice
599
- selection={selection}
600
- custom={customRange}
601
- currentPage={currentPage}
602
- total={pages.length}
603
- onSelection={setSelection}
604
- onCustom={setCustomRange}
605
- />
606
- {DOWNLOAD_FORMATS.map(({ format, label, hint, icon: Icon }) => (
607
- <MenuItem
608
- key={format}
609
- disabled={!chosenPages.valid}
610
- onClick={() => {
611
- close();
612
- void runDownload(format);
613
- }}
614
- >
615
- <Icon className="size-3.5 flex-none" />
616
- <span className="flex-1">
617
- {label}
618
- <span className="block text-[10px] text-muted-foreground">{hint}</span>
619
- </span>
620
- </MenuItem>
621
- ))}
622
- </>
623
- )}
624
- </Menu>
625
- </div>
626
- </header>
627
-
628
- <div className="flex min-h-0 flex-1">
629
- <DocSidebar
630
- docId={docId ?? ''}
631
- pages={pages}
632
- geometry={geometry}
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
- style={{
659
- gap: PAGE_GAP,
660
- padding: `${GUTTER}px ${GUTTER}px ${GUTTER * 1.5}px`,
661
- ...(viewMode === 'spread'
662
- ? { gridTemplateColumns: `repeat(2, ${geometry.width * scale}px)` }
663
- : viewMode === 'grid'
664
- ? { gridTemplateColumns: `repeat(auto-fill, ${geometry.width * scale}px)` }
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
- {pages.map((page, index) => (
669
- <PageFrame
670
- key={page.key}
671
- index={index}
672
- total={pages.length}
673
- geometry={geometry}
674
- scale={scale}
675
- design={doc.design}
676
- >
677
- {page.content}
678
- </PageFrame>
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
- {import.meta.env.DEV && docId && (
683
- <EditSaveCard
684
- textCount={textPending}
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
- onShownChange={setCardShown}
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
- </div>
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', hint: `${total}` },
745
- { kind: 'current' as const, label: 'This page', hint: `${currentPage}` },
746
- { kind: 'custom' as const, label: 'Custom', hint: '' },
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 chosen = describeSelection(
749
- selection.kind === 'custom' ? { kind: 'custom', text: custom } : selection,
750
- total,
751
- currentPage,
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
- <div className="border-border border-b px-1 pt-1 pb-2">
756
- <p className="px-1 pb-1 text-[10px] text-muted-foreground uppercase tracking-wide">Pages</p>
757
- <div className="flex gap-0.5">
758
- {options.map((option) => (
759
- <button
760
- key={option.kind}
761
- type="button"
762
- onClick={(event) => {
763
- event.stopPropagation();
764
- onSelection(
765
- option.kind === 'custom' ? { kind: 'custom', text: custom } : { kind: option.kind },
766
- );
767
- }}
768
- className={cn(
769
- 'flex-1 rounded px-2 py-1 text-[11px] transition-colors hover:bg-accent',
770
- selection.kind === option.kind && 'bg-accent text-foreground',
771
- )}
772
- >
773
- {option.label}
774
- {option.hint && (
775
- <span className="ml-1 font-mono text-[10px] text-muted-foreground">
776
- {option.hint}
777
- </span>
778
- )}
779
- </button>
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
- placeholder="e.g. 1-3, 5"
788
- aria-label="Pages to download"
789
- aria-invalid={!chosen.valid}
790
- className={cn(
791
- 'mt-1.5 w-full rounded border border-border bg-transparent px-2 py-1 text-[11px] outline-none placeholder:text-muted-foreground focus:border-foreground/40',
792
- !chosen.valid && custom !== '' && 'border-foreground/40',
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 className="px-1 pt-1.5 text-[10px] text-muted-foreground">
797
- {chosen.valid
798
- ? `${chosen.count} page${chosen.count === 1 ? '' : 's'} will be downloaded`
799
- : 'Type page numbers, like 1-3, 5'}
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
- </div>
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={`Page number, ${total} pages`}
850
- title="Go to page"
1054
+ aria-label={t('Page number, {total} pages', { total })}
1055
+ title={t('Go to page')}
851
1056
  inputMode="numeric"
852
- className="w-7 rounded bg-transparent text-right outline-none transition-colors hover:bg-accent focus:bg-accent focus:text-foreground"
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
  }