@open-document/core 0.9.0 → 0.10.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 (88) hide show
  1. package/dist/{build-CFL7nhz0.js → build-DJMLK50m.js} +1 -1
  2. package/dist/{check-CL0-0eB8.js → check-CUKuufBm.js} +3 -3
  3. package/dist/cli/bin.js +10 -6
  4. package/dist/{config-4nz5NnxW.js → config-CvzpyAUA.js} +558 -546
  5. package/dist/{context-BH8C-dSW.js → context-B4ip7SoI.js} +1 -1
  6. package/dist/{dev-BCSUczXW.js → dev-dnH7DTlD.js} +1 -1
  7. package/dist/{diagram-xlVDekYk.js → diagram-BK4jTZr4.js} +231 -158
  8. package/dist/diff-QTo0A5Rx.js +44 -0
  9. package/dist/{export-CmVJdl9a.js → export-BrRFrexj.js} +3 -3
  10. package/dist/{import-E6vRo7xm.js → import-C14Vn9ER.js} +2 -2
  11. package/dist/index.d.ts +54 -3
  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-OZZVBgsM.js → ops-DKidjLXP.js} +642 -124
  16. package/dist/{preview-CwCrw-i3.js → preview-wKM4C6Uk.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 +13 -6
  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/inspector.tsx +75 -48
  34. package/src/app/components/language-toggle.tsx +38 -0
  35. package/src/app/components/palette-items.ts +128 -0
  36. package/src/app/components/panel/edit-save-card.tsx +4 -2
  37. package/src/app/components/panel/fields.tsx +5 -2
  38. package/src/app/components/panel/save-card.tsx +18 -10
  39. package/src/app/components/sidebar/folder-item.tsx +10 -8
  40. package/src/app/components/sidebar/icon-picker.tsx +3 -1
  41. package/src/app/components/sidebar/sidebar.tsx +44 -13
  42. package/src/app/components/theme-toggle.tsx +5 -3
  43. package/src/app/components/ui/menu.tsx +5 -0
  44. package/src/app/lib/agent-bridge.ts +8 -2
  45. package/src/app/lib/chart.test.ts +108 -0
  46. package/src/app/lib/chart.ts +343 -0
  47. package/src/app/lib/doc-preview.tsx +0 -10
  48. package/src/app/lib/docs.ts +3 -0
  49. package/src/app/lib/docx/from-dom.ts +11 -11
  50. package/src/app/lib/docx/ooxml.test.ts +25 -9
  51. package/src/app/lib/docx/ooxml.ts +58 -37
  52. package/src/app/lib/export-docx.ts +13 -8
  53. package/src/app/lib/export-dom.ts +4 -0
  54. package/src/app/lib/export-image.ts +2 -0
  55. package/src/app/lib/export-pdf.ts +6 -0
  56. package/src/app/lib/flow-measure.ts +3 -0
  57. package/src/app/lib/flow.ts +1 -1
  58. package/src/app/lib/i18n-ja/browser.ts +88 -0
  59. package/src/app/lib/i18n-ja/doc.ts +65 -0
  60. package/src/app/lib/i18n-ja/index.ts +5 -0
  61. package/src/app/lib/i18n-ja/panels.ts +104 -0
  62. package/src/app/lib/i18n-ko/browser.ts +87 -0
  63. package/src/app/lib/i18n-ko/doc.ts +65 -0
  64. package/src/app/lib/i18n-ko/index.ts +5 -0
  65. package/src/app/lib/i18n-ko/panels.ts +102 -0
  66. package/src/app/lib/i18n-zh-cn/browser.ts +84 -0
  67. package/src/app/lib/i18n-zh-cn/doc.ts +64 -0
  68. package/src/app/lib/i18n-zh-cn/index.ts +5 -0
  69. package/src/app/lib/i18n-zh-cn/panels.ts +98 -0
  70. package/src/app/lib/i18n-zh-tw/browser.ts +84 -0
  71. package/src/app/lib/i18n-zh-tw/doc.ts +64 -0
  72. package/src/app/lib/i18n-zh-tw/index.ts +5 -0
  73. package/src/app/lib/i18n-zh-tw/panels.ts +99 -0
  74. package/src/app/lib/i18n.test.ts +24 -0
  75. package/src/app/lib/i18n.tsx +109 -0
  76. package/src/app/lib/outline.ts +23 -0
  77. package/src/app/lib/page-range.test.ts +10 -1
  78. package/src/app/lib/page-range.ts +26 -0
  79. package/src/app/lib/sdk.ts +2 -0
  80. package/src/app/lib/svg-ids.ts +37 -0
  81. package/src/app/main.tsx +4 -1
  82. package/src/app/routes/assets.tsx +193 -132
  83. package/src/app/routes/doc.tsx +666 -310
  84. package/src/app/routes/home-shell.tsx +115 -88
  85. package/src/app/routes/home.tsx +200 -67
  86. package/src/app/routes/themes.tsx +42 -35
  87. package/src/app/styles.css +99 -0
  88. package/src/app/virtual.d.ts +1 -0
@@ -1,4 +1,5 @@
1
1
  import { type ReactNode, useEffect, useId, useState } from 'react';
2
+ import { useT } from '../../lib/i18n';
2
3
 
3
4
  export function Section({ title, children }: { title: string; children: ReactNode }) {
4
5
  return (
@@ -48,6 +49,7 @@ export function ColorField({
48
49
  value: string;
49
50
  onChange: (value: string) => void;
50
51
  }) {
52
+ const t = useT();
51
53
  const id = useId();
52
54
  const [draft, setDraft] = useState(value);
53
55
  useEffect(() => setDraft(value), [value]);
@@ -59,7 +61,7 @@ export function ColorField({
59
61
  <span className="size-5 rounded-sm border border-border" style={{ background: value }} />
60
62
  <input
61
63
  type="color"
62
- aria-label={`${label} swatch`}
64
+ aria-label={t('{label} swatch', { label })}
63
65
  value={HEX6.test(value) ? value : '#000000'}
64
66
  onChange={(e) => onChange(e.target.value)}
65
67
  className="absolute inset-0 cursor-pointer opacity-0"
@@ -223,6 +225,7 @@ export function FontField({
223
225
  presets: FontPreset[];
224
226
  onChange: (value: string) => void;
225
227
  }) {
228
+ const t = useT();
226
229
  const id = useId();
227
230
  const matched = presets.find((preset) => preset.value === value);
228
231
  return (
@@ -240,7 +243,7 @@ export function FontField({
240
243
  {preset.label}
241
244
  </option>
242
245
  ))}
243
- {!matched && <option value="__custom__">Custom (from source)</option>}
246
+ {!matched && <option value="__custom__">{t('Custom (from source)')}</option>}
244
247
  </select>
245
248
  </Field>
246
249
  );
@@ -1,5 +1,6 @@
1
1
  import { Check, Loader2, Redo2, Save, Undo2 } from 'lucide-react';
2
2
  import { useEffect, useState } from 'react';
3
+ import { useT } from '../../lib/i18n';
3
4
 
4
5
  const IS_APPLE = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform);
5
6
  const UNDO_KEYS = IS_APPLE ? '⌘Z' : 'Ctrl+Z';
@@ -34,6 +35,7 @@ export function SaveCard({
34
35
  onUndo: () => void;
35
36
  onRedo: () => void;
36
37
  }) {
38
+ const t = useT();
37
39
  const [justSaved, setJustSaved] = useState(false);
38
40
  useEffect(() => {
39
41
  if (!justSaved) return;
@@ -51,18 +53,20 @@ export function SaveCard({
51
53
  return (
52
54
  <div
53
55
  role="toolbar"
54
- aria-label="Unsaved changes"
56
+ aria-label={t('Unsaved changes')}
55
57
  className="od-card-in pointer-events-auto absolute bottom-4 left-1/2 z-40 flex h-10 -translate-x-1/2 items-center gap-1 rounded-lg border border-border bg-background py-1 pr-1 pl-1 text-xs shadow-md"
56
58
  >
57
59
  <HistoryButton
58
- label={`Undo (${UNDO_KEYS})`}
60
+ label={t('Undo')}
61
+ keys={UNDO_KEYS}
59
62
  disabled={committing || !canUndo}
60
63
  onClick={onUndo}
61
64
  >
62
65
  <Undo2 className="size-3.5" />
63
66
  </HistoryButton>
64
67
  <HistoryButton
65
- label={`Redo (${REDO_KEYS})`}
68
+ label={t('Redo')}
69
+ keys={REDO_KEYS}
66
70
  disabled={committing || !canRedo}
67
71
  onClick={onRedo}
68
72
  >
@@ -75,7 +79,7 @@ export function SaveCard({
75
79
  {justSaved ? (
76
80
  <>
77
81
  <Check className="size-3.5 flex-none" strokeWidth={2.5} />
78
- Saved
82
+ {t('Saved')}
79
83
  </>
80
84
  ) : error ? (
81
85
  <span className="max-w-72 truncate text-muted-foreground" title={error}>
@@ -85,7 +89,9 @@ export function SaveCard({
85
89
  <>
86
90
  <span aria-hidden className="size-1.5 flex-none rounded-full bg-foreground" />
87
91
  <span className="tabular-nums">
88
- {count} unsaved change{count === 1 ? '' : 's'}
92
+ {count === 1
93
+ ? t('{count} unsaved change', { count })
94
+ : t('{count} unsaved changes', { count })}
89
95
  </span>
90
96
  </>
91
97
  ) : null}
@@ -97,7 +103,7 @@ export function SaveCard({
97
103
  disabled={committing}
98
104
  className="h-8 rounded-md px-3 text-foreground/80 transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-foreground/60 focus-visible:outline-offset-1 disabled:opacity-50"
99
105
  >
100
- Discard
106
+ {t('Discard')}
101
107
  </button>
102
108
  )}
103
109
  {(dirty || committing) && (
@@ -105,7 +111,7 @@ export function SaveCard({
105
111
  type="button"
106
112
  onClick={() => void save()}
107
113
  disabled={committing}
108
- title={`Save (${SAVE_KEYS})`}
114
+ title={`${t('Save')} (${SAVE_KEYS})`}
109
115
  className="flex h-8 items-center gap-1.5 rounded-md bg-primary px-3 text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-2 focus-visible:outline-foreground/60 focus-visible:outline-offset-1 disabled:opacity-70"
110
116
  >
111
117
  {committing ? (
@@ -113,7 +119,7 @@ export function SaveCard({
113
119
  ) : (
114
120
  <Save className="size-3.5" />
115
121
  )}
116
- {committing ? 'Saving' : 'Save'}
122
+ {committing ? t('Saving') : t('Save')}
117
123
  </button>
118
124
  )}
119
125
  </div>
@@ -122,11 +128,13 @@ export function SaveCard({
122
128
 
123
129
  function HistoryButton({
124
130
  label,
131
+ keys,
125
132
  disabled,
126
133
  onClick,
127
134
  children,
128
135
  }: {
129
136
  label: string;
137
+ keys: string;
130
138
  disabled: boolean;
131
139
  onClick: () => void;
132
140
  children: React.ReactNode;
@@ -134,8 +142,8 @@ function HistoryButton({
134
142
  return (
135
143
  <button
136
144
  type="button"
137
- aria-label={label.replace(/ \(.*\)$/, '')}
138
- title={label}
145
+ aria-label={label}
146
+ title={`${label} (${keys})`}
139
147
  disabled={disabled}
140
148
  onClick={onClick}
141
149
  className="flex size-8 items-center justify-center rounded-md text-foreground/75 transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-foreground/60 focus-visible:outline-offset-1 disabled:text-foreground/30 disabled:hover:bg-transparent"
@@ -1,5 +1,6 @@
1
1
  import { FileText, Image, MoreHorizontal, Palette, PencilLine, Trash2 } from 'lucide-react';
2
2
  import { useEffect, useRef, useState } from 'react';
3
+ import { useT } from '../../lib/i18n';
3
4
  import type { Folder, FolderIcon } from '../../lib/sdk';
4
5
  import { cn } from '../../lib/utils';
5
6
  import { Menu, MenuItem, MenuSeparator } from '../ui/menu';
@@ -55,6 +56,7 @@ export function FolderItem({
55
56
  onSelect: () => void;
56
57
  onDropDoc: (docId: string) => void;
57
58
  }) {
59
+ const t = useT();
58
60
  const [renaming, setRenaming] = useState(false);
59
61
  const [draft, setDraft] = useState('');
60
62
  const [dragOver, setDragOver] = useState(false);
@@ -68,12 +70,12 @@ export function FolderItem({
68
70
  row.kind === 'folder'
69
71
  ? row.folder.name
70
72
  : row.kind === 'all'
71
- ? 'Documents'
73
+ ? t('Documents')
72
74
  : row.kind === 'themes'
73
- ? 'Themes'
75
+ ? t('Themes')
74
76
  : row.kind === 'assets'
75
- ? 'Assets'
76
- : 'Unfiled';
77
+ ? t('Assets')
78
+ : t('Unfiled');
77
79
 
78
80
  const acceptsDrop = row.kind === 'folder' || row.kind === 'draft';
79
81
 
@@ -114,7 +116,7 @@ export function FolderItem({
114
116
  trigger={(props) => (
115
117
  <button
116
118
  type="button"
117
- aria-label="Change icon"
119
+ aria-label={t('Change icon')}
118
120
  className="shrink-0 transition-transform hover:scale-110"
119
121
  {...props}
120
122
  >
@@ -171,7 +173,7 @@ export function FolderItem({
171
173
  trigger={(props) => (
172
174
  <button
173
175
  type="button"
174
- aria-label={`${row.folder.name} options`}
176
+ aria-label={t('{name} options', { name: row.folder.name })}
175
177
  className="flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-background hover:text-foreground aria-expanded:bg-background"
176
178
  {...props}
177
179
  >
@@ -189,7 +191,7 @@ export function FolderItem({
189
191
  }}
190
192
  >
191
193
  <PencilLine className="size-3.5" />
192
- Rename
194
+ {t('Rename')}
193
195
  </MenuItem>
194
196
  <MenuSeparator />
195
197
  <MenuItem
@@ -200,7 +202,7 @@ export function FolderItem({
200
202
  }}
201
203
  >
202
204
  <Trash2 className="size-3.5" />
203
- Delete folder
205
+ {t('Delete folder')}
204
206
  </MenuItem>
205
207
  </>
206
208
  )}
@@ -1,4 +1,5 @@
1
1
  import { useState } from 'react';
2
+ import { useT } from '../../lib/i18n';
2
3
  import type { FolderIcon } from '../../lib/sdk';
3
4
  import { cn } from '../../lib/utils';
4
5
 
@@ -40,6 +41,7 @@ export function IconPicker({
40
41
  value: FolderIcon;
41
42
  onChange: (icon: FolderIcon) => void;
42
43
  }) {
44
+ const t = useT();
43
45
  const [tab, setTab] = useState<'emoji' | 'color'>(value.type);
44
46
 
45
47
  return (
@@ -55,7 +57,7 @@ export function IconPicker({
55
57
  tab === next ? 'bg-background font-medium' : 'text-muted-foreground',
56
58
  )}
57
59
  >
58
- {next}
60
+ {t(next)}
59
61
  </button>
60
62
  ))}
61
63
  </div>
@@ -1,8 +1,11 @@
1
1
  import config from 'virtual:open-doc/config';
2
- import { Plus } from 'lucide-react';
2
+ import { Plus, Search } from 'lucide-react';
3
3
  import { useEffect, useRef, useState } from 'react';
4
+ import { useT } from '../../lib/i18n';
4
5
  import type { Folder, FolderIcon } from '../../lib/sdk';
5
6
  import { cn } from '../../lib/utils';
7
+ import { PALETTE_SHORTCUT, useCommandPalette } from '../command-palette';
8
+ import { LanguageToggle } from '../language-toggle';
6
9
  import { ThemeToggle } from '../theme-toggle';
7
10
  import { FolderIconChip, FolderItem } from './folder-item';
8
11
  import { IconPicker, PRESET_COLORS } from './icon-picker';
@@ -47,6 +50,7 @@ export function Sidebar({
47
50
  onDropToDraft,
48
51
  onReorder,
49
52
  }: Props) {
53
+ const t = useT();
50
54
  const [dragId, setDragId] = useState<string | null>(null);
51
55
  const [dropTarget, setDropTarget] = useState<{ id: string; before: boolean } | null>(null);
52
56
  const [creating, setCreating] = useState(false);
@@ -86,12 +90,13 @@ export function Sidebar({
86
90
  };
87
91
 
88
92
  return (
89
- <aside className="flex h-full w-[16.5rem] shrink-0 flex-col border-border border-r bg-background">
90
- <div className="flex items-center justify-between px-4 pt-4 pb-3">
93
+ <aside className="flex h-full w-[16.5rem] shrink-0 flex-col bg-background">
94
+ <div className="px-4 pt-4 pb-3">
91
95
  <h1 className="font-semibold text-base tracking-tight">open-doc</h1>
92
- <div className="-mr-1 flex items-center gap-0.5">
93
- <ThemeToggle />
94
- </div>
96
+ </div>
97
+
98
+ <div className="px-2 pb-2">
99
+ <SearchField />
95
100
  </div>
96
101
 
97
102
  <div className="px-2">
@@ -121,7 +126,9 @@ export function Sidebar({
121
126
  </div>
122
127
 
123
128
  <div className="mt-5 flex items-center gap-2 px-4 pb-1">
124
- <span className="text-[10px] text-muted-foreground uppercase tracking-wider">Folders</span>
129
+ <span className="text-[10px] text-muted-foreground uppercase tracking-wider">
130
+ {t('Folders')}
131
+ </span>
125
132
  <span className="h-px flex-1 bg-border" aria-hidden />
126
133
  </div>
127
134
 
@@ -218,7 +225,7 @@ export function Sidebar({
218
225
  setNewName('');
219
226
  }
220
227
  }}
221
- placeholder="Folder name"
228
+ placeholder={t('Folder name')}
222
229
  maxLength={40}
223
230
  className="min-w-0 flex-1 bg-transparent text-[13px] outline-none placeholder:text-muted-foreground/60"
224
231
  />
@@ -230,7 +237,7 @@ export function Sidebar({
230
237
  className="mt-1 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-[12px] text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
231
238
  >
232
239
  <Plus className="size-3.5" />
233
- New folder
240
+ {t('New folder')}
234
241
  </button>
235
242
  ))}
236
243
 
@@ -241,12 +248,36 @@ export function Sidebar({
241
248
  )}
242
249
  </div>
243
250
 
244
- <div className="border-border border-t px-4 py-3 text-[11px] text-muted-foreground">
245
- <div className="flex items-center justify-between">
246
- <span>v{config.version}</span>
247
- <span className="font-mono">{import.meta.env.DEV ? 'dev' : 'static'}</span>
251
+ <div className="flex items-center justify-between gap-2 px-4 py-3 text-[11px] text-muted-foreground">
252
+ <span>
253
+ v{config.version}
254
+ <span className="ml-2 font-mono">{import.meta.env.DEV ? 'dev' : 'static'}</span>
255
+ </span>
256
+ <div className="-mr-1.5 flex items-center gap-0.5">
257
+ <LanguageToggle />
258
+ <ThemeToggle />
248
259
  </div>
249
260
  </div>
250
261
  </aside>
251
262
  );
252
263
  }
264
+
265
+ /** Looks like a field, opens the palette — the same thing ⌘K does, for a pointer. */
266
+ function SearchField() {
267
+ const t = useT();
268
+ const palette = useCommandPalette();
269
+ return (
270
+ <button
271
+ type="button"
272
+ onClick={palette.open}
273
+ aria-keyshortcuts="Meta+K Control+K"
274
+ className="flex h-8 w-full items-center gap-2 rounded-md border border-border bg-background px-2.5 text-muted-foreground text-xs transition-colors hover:bg-accent hover:text-foreground"
275
+ >
276
+ <Search className="size-3.5" />
277
+ <span className="flex-1 text-left">{t('Search')}</span>
278
+ <kbd className="rounded border border-border px-1 font-mono text-[10px]">
279
+ {PALETTE_SHORTCUT}
280
+ </kbd>
281
+ </button>
282
+ );
283
+ }
@@ -1,6 +1,7 @@
1
1
  import { Monitor, Moon, Sun } from 'lucide-react';
2
2
  import { useTheme } from 'next-themes';
3
3
  import { useEffect, useState } from 'react';
4
+ import { useT } from '../lib/i18n';
4
5
  import { Menu, MenuItem } from './ui/menu';
5
6
 
6
7
  const OPTIONS = [
@@ -10,6 +11,7 @@ const OPTIONS = [
10
11
  ] as const;
11
12
 
12
13
  export function ThemeToggle() {
14
+ const t = useT();
13
15
  const { theme, setTheme } = useTheme();
14
16
  const [mounted, setMounted] = useState(false);
15
17
 
@@ -20,8 +22,8 @@ export function ThemeToggle() {
20
22
  trigger={(props) => (
21
23
  <button
22
24
  type="button"
23
- aria-label="Toggle theme"
24
- title="Theme"
25
+ aria-label={t('Toggle theme')}
26
+ title={t('Theme')}
25
27
  className="relative flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground aria-expanded:bg-accent"
26
28
  {...props}
27
29
  >
@@ -41,7 +43,7 @@ export function ThemeToggle() {
41
43
  }}
42
44
  >
43
45
  <Icon className="size-3.5" />
44
- {label}
46
+ {t(label)}
45
47
  </MenuItem>
46
48
  ))
47
49
  }
@@ -45,6 +45,11 @@ export function Menu({ trigger, children, placement = 'bottom-end', className }:
45
45
  let top = placement === 'right-start' ? a.top : a.bottom + gap;
46
46
  let left = placement === 'bottom-end' ? a.right - p.width : a.left;
47
47
  if (placement === 'right-start') left = a.right + gap;
48
+ // A trigger near the foot of the screen (the sidebar's footer) opens upward;
49
+ // clamping alone would slide the menu over the button that opened it.
50
+ if (placement !== 'right-start' && top + p.height > window.innerHeight - 8) {
51
+ top = a.top - gap - p.height;
52
+ }
48
53
  left = Math.max(8, Math.min(left, window.innerWidth - p.width - 8));
49
54
  top = Math.max(8, Math.min(top, window.innerHeight - p.height - 8));
50
55
  setCoords({ top, left });
@@ -2,7 +2,8 @@ import { useEffect, useRef } from 'react';
2
2
  import { diagnosePages, type LayoutFinding } from './diagnostics';
3
3
  import { buildDocDocx } from './export-docx';
4
4
  import { buildDocHtmlBundle } from './export-html';
5
- import { mountPrintCopy } from './export-pdf';
5
+ import { mountPrintCopy, type PrintCopy } from './export-pdf';
6
+ import { exposeOutline } from './outline';
6
7
  import type { DocModule, PageGeometry } from './sdk';
7
8
  import type { ExpandedPage } from './use-doc-pages';
8
9
 
@@ -66,7 +67,7 @@ export function useAgentBridge(input: BridgeInput): void {
66
67
 
67
68
  useEffect(() => {
68
69
  const g = globalThis as GlobalWithBridge;
69
- let held: { dispose: () => void } | null = null;
70
+ let held: PrintCopy | null = null;
70
71
 
71
72
  const status = (): BridgeStatus => {
72
73
  const { docId, doc, pages, geometry, measuring } = latest.current;
@@ -106,6 +107,11 @@ export function useAgentBridge(input: BridgeInput): void {
106
107
  const { docId, doc, pages } = latest.current;
107
108
  if (!doc || pages.length === 0) return { pageCount: 0 };
108
109
  held = await mountPrintCopy(doc, docId, pages);
110
+ // The copy is hidden from assistive tech while it sits offscreen, but
111
+ // the PDF's bookmarks and tags are built from that same tree. Nobody
112
+ // reads this tab, and the copy goes as soon as the PDF is written.
113
+ held.root.removeAttribute('aria-hidden');
114
+ exposeOutline(held.root);
109
115
  return { pageCount: pages.length };
110
116
  },
111
117
  releasePrint: release,
@@ -0,0 +1,108 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { formatChartValue, layoutChart, niceTicks, toNumber } from './chart';
3
+
4
+ const DATA = [
5
+ { month: 'Jan', cost: 120, budget: 100 },
6
+ { month: 'Feb', cost: 80, budget: 100 },
7
+ { month: 'Mar', cost: 150, budget: 120 },
8
+ ];
9
+
10
+ describe('niceTicks', () => {
11
+ it('steps by 1, 2 or 5 times a power of ten', () => {
12
+ expect(niceTicks(0, 150)).toEqual([0, 50, 100, 150]);
13
+ expect(niceTicks(0, 0.87)).toEqual([0, 0.2, 0.4, 0.6, 0.8, 1]);
14
+ expect(niceTicks(-30, 70)).toEqual([-40, -20, 0, 20, 40, 60, 80]);
15
+ });
16
+
17
+ it('opens a flat range so there is still an axis to draw', () => {
18
+ expect(niceTicks(0, 0)).toEqual([0, 1]);
19
+ expect(niceTicks(5, 5).length).toBeGreaterThan(1);
20
+ });
21
+ });
22
+
23
+ describe('values', () => {
24
+ it('reads CSV cells and typed numbers alike', () => {
25
+ expect(toNumber('1,204')).toBe(1204);
26
+ expect(toNumber(3.5)).toBe(3.5);
27
+ expect(toNumber('')).toBeNull();
28
+ expect(toNumber('n/a')).toBeNull();
29
+ });
30
+
31
+ it('formats like DataTable', () => {
32
+ expect(formatChartValue(0.123, 'percent')).toBe('12.3%');
33
+ expect(formatChartValue(1234.6, 'integer')).toBe((1235).toLocaleString());
34
+ expect(formatChartValue(7, (v) => `${v} ms`)).toBe('7 ms');
35
+ });
36
+ });
37
+
38
+ describe('layoutChart', () => {
39
+ const base = { data: DATA, x: 'month', width: 400, height: 200 } as const;
40
+
41
+ it('stands bars on zero and keeps them inside the plot', () => {
42
+ const chart = layoutChart({ ...base, type: 'bar', y: ['cost'] });
43
+ expect(chart.bars).toHaveLength(3);
44
+ const floor = chart.plot.y + chart.plot.height;
45
+ for (const bar of chart.bars) {
46
+ expect(bar.y).toBeGreaterThanOrEqual(chart.plot.y);
47
+ expect(bar.y + bar.height).toBeCloseTo(floor, 1);
48
+ }
49
+ // The tallest value draws the tallest bar.
50
+ const tallest = chart.bars.reduce((a, b) => (b.height > a.height ? b : a));
51
+ expect(tallest.value).toBe(150);
52
+ expect(chart.ticks[0]?.value).toBe(0);
53
+ });
54
+
55
+ it('groups series side by side, or stacks them', () => {
56
+ const grouped = layoutChart({ ...base, type: 'bar', y: ['cost', 'budget'] });
57
+ const [jan, janBudget] = grouped.bars;
58
+ expect(janBudget && jan && janBudget.x).toBeGreaterThan(jan?.x ?? 0);
59
+ expect(grouped.legend.map((item) => item.name)).toEqual(['cost', 'budget']);
60
+
61
+ const stacked = layoutChart({ ...base, type: 'bar', y: ['cost', 'budget'], stacked: true });
62
+ const [a, b] = stacked.bars;
63
+ expect(a?.x).toBe(b?.x);
64
+ expect(b && a && b.y + b.height).toBeCloseTo(a?.y ?? 0, 1);
65
+ // The axis has room for the stacked total, 270.
66
+ expect(stacked.ticks[stacked.ticks.length - 1]?.value).toBeGreaterThanOrEqual(270);
67
+ });
68
+
69
+ it('draws one line per series through the band centres', () => {
70
+ const chart = layoutChart({
71
+ ...base,
72
+ type: 'line',
73
+ y: ['cost', 'budget'],
74
+ labels: { cost: 'Cost', budget: 'Budget' },
75
+ });
76
+ expect(chart.lines).toHaveLength(2);
77
+ expect(chart.lines[0]?.points.map((p) => p.x)).toEqual(chart.categories.map((c) => c.x));
78
+ expect(chart.legend.map((item) => item.name)).toEqual(['Cost', 'Budget']);
79
+ });
80
+
81
+ it('thins category labels that would collide', () => {
82
+ const many = Array.from({ length: 40 }, (_, i) => ({ day: `Day ${i + 1}`, n: i }));
83
+ const chart = layoutChart({
84
+ type: 'bar',
85
+ data: many,
86
+ x: 'day',
87
+ y: ['n'],
88
+ width: 300,
89
+ height: 160,
90
+ });
91
+ expect(chart.categories.length).toBeLessThan(40);
92
+ const xs = chart.categories.map((c) => c.x);
93
+ for (let i = 1; i < xs.length; i++) expect((xs[i] ?? 0) - (xs[i - 1] ?? 0)).toBeGreaterThan(30);
94
+ });
95
+
96
+ it('cuts a pie into shares that add up to the whole', () => {
97
+ const chart = layoutChart({ ...base, type: 'pie', y: ['cost'], values: true });
98
+ expect(chart.slices).toHaveLength(3);
99
+ expect(chart.slices.reduce((sum, s) => sum + s.share, 0)).toBeCloseTo(1, 6);
100
+ expect(chart.legend[0]?.name).toContain('Jan');
101
+ expect(chart.values.map((v) => v.text)).toEqual(['34.3%', '22.9%', '42.9%']);
102
+ });
103
+
104
+ it('draws a single-slice pie as a full circle', () => {
105
+ const chart = layoutChart({ ...base, type: 'pie', data: [DATA[0] ?? {}], y: ['cost'] });
106
+ expect(chart.slices[0]?.path).toMatch(/ a.* a/);
107
+ });
108
+ });