@open-document/core 0.9.1 → 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 (83) hide show
  1. package/dist/{build-B0GJXy8I.js → build-DJMLK50m.js} +1 -1
  2. package/dist/{check-CuDIWsPT.js → check-CUKuufBm.js} +3 -3
  3. package/dist/cli/bin.js +10 -6
  4. package/dist/{config-CAZ7Z_va.js → config-CvzpyAUA.js} +558 -546
  5. package/dist/{context-PWAh9qbf.js → context-B4ip7SoI.js} +1 -1
  6. package/dist/{dev-CYqppXDI.js → dev-dnH7DTlD.js} +1 -1
  7. package/dist/{diagram-CCaUUnRe.js → diagram-BK4jTZr4.js} +146 -146
  8. package/dist/diff-QTo0A5Rx.js +44 -0
  9. package/dist/{export-1JtO2OMC.js → export-BrRFrexj.js} +3 -3
  10. package/dist/{import-CsrdBOZ8.js → import-C14Vn9ER.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-DKidjLXP.js} +642 -124
  16. package/dist/{preview-DW3PM-JV.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 +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/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/flow.ts +1 -1
  54. package/src/app/lib/i18n-ja/browser.ts +88 -0
  55. package/src/app/lib/i18n-ja/doc.ts +65 -0
  56. package/src/app/lib/i18n-ja/index.ts +5 -0
  57. package/src/app/lib/i18n-ja/panels.ts +104 -0
  58. package/src/app/lib/i18n-ko/browser.ts +87 -0
  59. package/src/app/lib/i18n-ko/doc.ts +65 -0
  60. package/src/app/lib/i18n-ko/index.ts +5 -0
  61. package/src/app/lib/i18n-ko/panels.ts +102 -0
  62. package/src/app/lib/i18n-zh-cn/browser.ts +84 -0
  63. package/src/app/lib/i18n-zh-cn/doc.ts +64 -0
  64. package/src/app/lib/i18n-zh-cn/index.ts +5 -0
  65. package/src/app/lib/i18n-zh-cn/panels.ts +98 -0
  66. package/src/app/lib/i18n-zh-tw/browser.ts +84 -0
  67. package/src/app/lib/i18n-zh-tw/doc.ts +64 -0
  68. package/src/app/lib/i18n-zh-tw/index.ts +5 -0
  69. package/src/app/lib/i18n-zh-tw/panels.ts +99 -0
  70. package/src/app/lib/i18n.test.ts +24 -0
  71. package/src/app/lib/i18n.tsx +109 -0
  72. package/src/app/lib/outline.ts +23 -0
  73. package/src/app/lib/page-range.test.ts +10 -1
  74. package/src/app/lib/page-range.ts +26 -0
  75. package/src/app/lib/sdk.ts +2 -0
  76. package/src/app/main.tsx +4 -1
  77. package/src/app/routes/assets.tsx +193 -132
  78. package/src/app/routes/doc.tsx +666 -310
  79. package/src/app/routes/home-shell.tsx +115 -88
  80. package/src/app/routes/home.tsx +200 -67
  81. package/src/app/routes/themes.tsx +42 -35
  82. package/src/app/styles.css +84 -5
  83. package/src/app/virtual.d.ts +1 -0
@@ -0,0 +1,284 @@
1
+ import { CornerDownLeft, type LucideIcon, Search } from 'lucide-react';
2
+ import {
3
+ createContext,
4
+ type ReactNode,
5
+ useCallback,
6
+ useContext,
7
+ useEffect,
8
+ useId,
9
+ useMemo,
10
+ useRef,
11
+ useState,
12
+ } from 'react';
13
+ import { useT } from '../lib/i18n';
14
+ import { cn } from '../lib/utils';
15
+
16
+ export type PaletteItem = {
17
+ id: string;
18
+ group: string;
19
+ label: string;
20
+ /** Quiet text at the right of the row — a page number, a shortcut. */
21
+ hint?: string;
22
+ icon?: LucideIcon;
23
+ /** More words the query may match than the label shows. */
24
+ keywords?: string;
25
+ /** Ranks first whenever it matches — the one answer the query was typed to get. */
26
+ pinned?: boolean;
27
+ run: () => void;
28
+ };
29
+
30
+ type PaletteApi = { open: () => void };
31
+
32
+ const PaletteContext = createContext<PaletteApi>({ open: () => {} });
33
+
34
+ /** Opens the palette from anywhere below it — the sidebar's search field, a toolbar button. */
35
+ export function useCommandPalette(): PaletteApi {
36
+ return useContext(PaletteContext);
37
+ }
38
+
39
+ export const PALETTE_SHORTCUT =
40
+ typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌘K' : 'Ctrl K';
41
+
42
+ function matches(item: PaletteItem, words: string[]): number {
43
+ const label = item.label.toLowerCase();
44
+ const haystack = `${label} ${item.keywords?.toLowerCase() ?? ''} ${item.group.toLowerCase()}`;
45
+ if (!words.every((word) => haystack.includes(word))) return -1;
46
+ if (item.pinned) return 3;
47
+ // A label that starts with what was typed outranks one that merely contains it.
48
+ return label.startsWith(words[0] ?? '') ? 2 : label.includes(words[0] ?? '') ? 1 : 0;
49
+ }
50
+
51
+ /**
52
+ * ⌘K: one field that reaches every document, theme, folder and action without
53
+ * leaving the keyboard. Built here rather than pulled in — `core` ships to every
54
+ * user, and a dialog with a listbox is a page of code, not a dependency.
55
+ *
56
+ * `items` may be computed from the query (the viewer offers "Go to page 12"
57
+ * when 12 is typed), so it is a function of it.
58
+ */
59
+ export function CommandPaletteProvider({
60
+ items,
61
+ placeholder,
62
+ children,
63
+ }: {
64
+ items: (query: string) => PaletteItem[];
65
+ placeholder?: string;
66
+ children: ReactNode;
67
+ }) {
68
+ const t = useT();
69
+ const [open, setOpen] = useState(false);
70
+ const [query, setQuery] = useState('');
71
+ const [active, setActive] = useState(0);
72
+ const inputRef = useRef<HTMLInputElement>(null);
73
+ const returnRef = useRef<HTMLElement | null>(null);
74
+ const listId = useId();
75
+
76
+ const show = useCallback(() => {
77
+ returnRef.current = document.activeElement as HTMLElement | null;
78
+ setQuery('');
79
+ setActive(0);
80
+ setOpen(true);
81
+ }, []);
82
+
83
+ const hide = useCallback(() => {
84
+ setOpen(false);
85
+ // Focus goes back where it came from, so closing never strands the reader.
86
+ requestAnimationFrame(() => returnRef.current?.focus?.());
87
+ }, []);
88
+
89
+ useEffect(() => {
90
+ const onKeyDown = (event: KeyboardEvent) => {
91
+ if (event.key.toLowerCase() !== 'k' || !(event.metaKey || event.ctrlKey) || event.altKey) {
92
+ return;
93
+ }
94
+ // ⌘K inside text being edited on the page is "add a link", not search.
95
+ const target = event.target as HTMLElement | null;
96
+ if (target?.closest('[contenteditable="true"], [data-od-editing]')) return;
97
+ event.preventDefault();
98
+ if (open) hide();
99
+ else show();
100
+ };
101
+ window.addEventListener('keydown', onKeyDown);
102
+ return () => window.removeEventListener('keydown', onKeyDown);
103
+ }, [open, show, hide]);
104
+
105
+ useEffect(() => {
106
+ if (open) inputRef.current?.focus();
107
+ }, [open]);
108
+
109
+ const results = useMemo(() => {
110
+ if (!open) return [];
111
+ const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
112
+ const all = items(query.trim());
113
+ if (words.length === 0) return all;
114
+ return all
115
+ .map((item, order) => ({ item, order, score: matches(item, words) }))
116
+ .filter((entry) => entry.score >= 0)
117
+ .sort((a, b) => b.score - a.score || a.order - b.order)
118
+ .map((entry) => entry.item);
119
+ }, [open, query, items]);
120
+
121
+ useEffect(() => {
122
+ setActive((index) => Math.min(index, Math.max(0, results.length - 1)));
123
+ }, [results.length]);
124
+
125
+ useEffect(() => {
126
+ if (!open) return;
127
+ document.getElementById(`${listId}-${active}`)?.scrollIntoView({ block: 'nearest' });
128
+ }, [open, active, listId]);
129
+
130
+ const run = (item: PaletteItem | undefined) => {
131
+ if (!item) return;
132
+ setOpen(false);
133
+ item.run();
134
+ };
135
+
136
+ const groups: Array<{ name: string; entries: Array<{ item: PaletteItem; index: number }> }> = [];
137
+ results.forEach((item, index) => {
138
+ const last = groups[groups.length - 1];
139
+ if (last && last.name === item.group) last.entries.push({ item, index });
140
+ else groups.push({ name: item.group, entries: [{ item, index }] });
141
+ });
142
+
143
+ const api = useMemo(() => ({ open: show }), [show]);
144
+
145
+ return (
146
+ <PaletteContext.Provider value={api}>
147
+ {children}
148
+ {open && (
149
+ <div className="fixed inset-0 z-50 flex items-start justify-center px-4 pt-[14vh]">
150
+ <button
151
+ type="button"
152
+ aria-label={t('Close')}
153
+ tabIndex={-1}
154
+ onClick={hide}
155
+ className="od-fade-in absolute inset-0 bg-foreground/25 backdrop-blur-[2px]"
156
+ />
157
+ <div
158
+ role="dialog"
159
+ aria-modal="true"
160
+ aria-label={t('Command menu')}
161
+ className="od-fade-in relative flex max-h-[min(70vh,520px)] w-full max-w-[560px] flex-col overflow-hidden rounded-lg border border-border bg-background shadow-2xl"
162
+ >
163
+ <div className="flex items-center gap-2 border-border border-b px-3">
164
+ <Search className="size-4 flex-none text-muted-foreground" />
165
+ <input
166
+ ref={inputRef}
167
+ value={query}
168
+ onChange={(event) => {
169
+ setQuery(event.target.value);
170
+ setActive(0);
171
+ }}
172
+ onKeyDown={(event) => {
173
+ if (event.key === 'ArrowDown') {
174
+ event.preventDefault();
175
+ setActive((index) => (results.length ? (index + 1) % results.length : 0));
176
+ } else if (event.key === 'ArrowUp') {
177
+ event.preventDefault();
178
+ setActive((index) =>
179
+ results.length ? (index - 1 + results.length) % results.length : 0,
180
+ );
181
+ } else if (event.key === 'Enter') {
182
+ event.preventDefault();
183
+ run(results[active]);
184
+ } else if (event.key === 'Escape') {
185
+ event.preventDefault();
186
+ hide();
187
+ } else if (event.key === 'Tab') {
188
+ // The field is the dialog's only stop; Tab must not walk out of it.
189
+ event.preventDefault();
190
+ }
191
+ }}
192
+ role="combobox"
193
+ aria-expanded="true"
194
+ aria-controls={listId}
195
+ aria-activedescendant={results.length ? `${listId}-${active}` : undefined}
196
+ aria-autocomplete="list"
197
+ placeholder={placeholder ?? t('Search documents, sections and actions')}
198
+ className="h-12 min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"
199
+ />
200
+ </div>
201
+
202
+ <div
203
+ id={listId}
204
+ role="listbox"
205
+ aria-label={t('Results')}
206
+ className="overflow-y-auto p-1.5"
207
+ >
208
+ {results.length === 0 && (
209
+ <p className="px-3 py-8 text-center text-muted-foreground text-sm">
210
+ {t('Nothing matches “{query}”.', { query: query.trim() })}
211
+ </p>
212
+ )}
213
+ {groups.map((group) => (
214
+ // biome-ignore lint/a11y/useSemanticElements: a listbox's groups are role="group" by definition; a fieldset has no meaning inside one
215
+ <div key={group.name} role="group" aria-label={group.name}>
216
+ <p
217
+ aria-hidden
218
+ className="px-2.5 pt-2 pb-1 text-[10px] text-muted-foreground uppercase tracking-wide"
219
+ >
220
+ {group.name}
221
+ </p>
222
+ {group.entries.map(({ item, index }) => {
223
+ const Icon = item.icon;
224
+ const selected = index === active;
225
+ return (
226
+ // biome-ignore lint/a11y/useFocusableInteractive: options are reached with the arrow keys from the combobox, which keeps focus — the listbox pattern
227
+ <div
228
+ key={item.id}
229
+ id={`${listId}-${index}`}
230
+ role="option"
231
+ aria-selected={selected}
232
+ onMouseMove={() => setActive(index)}
233
+ onMouseDown={(event) => event.preventDefault()}
234
+ onClick={() => run(item)}
235
+ onKeyDown={() => {}}
236
+ className={cn(
237
+ 'flex h-9 cursor-pointer items-center gap-2.5 rounded-md px-2.5 text-sm',
238
+ selected ? 'bg-accent text-foreground' : 'text-foreground/90',
239
+ )}
240
+ >
241
+ {Icon && <Icon className="size-4 flex-none text-muted-foreground" />}
242
+ <span className="min-w-0 flex-1 truncate">{item.label}</span>
243
+ {item.hint && (
244
+ <span className="flex-none font-mono text-[11px] text-muted-foreground">
245
+ {item.hint}
246
+ </span>
247
+ )}
248
+ {selected && (
249
+ <CornerDownLeft className="size-3.5 flex-none text-muted-foreground" />
250
+ )}
251
+ </div>
252
+ );
253
+ })}
254
+ </div>
255
+ ))}
256
+ </div>
257
+
258
+ <div className="flex items-center justify-between border-border border-t px-3 py-2 text-[11px] text-muted-foreground">
259
+ <span>
260
+ <Kbd>esc</Kbd> {t('Close')}
261
+ </span>
262
+ <span className="flex items-center gap-3">
263
+ <span>
264
+ <Kbd>↑</Kbd> <Kbd>↓</Kbd> {t('Navigate')}
265
+ </span>
266
+ <span>
267
+ <Kbd>↵</Kbd> {t('Open')}
268
+ </span>
269
+ </span>
270
+ </div>
271
+ </div>
272
+ </div>
273
+ )}
274
+ </PaletteContext.Provider>
275
+ );
276
+ }
277
+
278
+ function Kbd({ children }: { children: ReactNode }) {
279
+ return (
280
+ <kbd className="rounded border border-border px-1 font-mono text-[10px] text-muted-foreground">
281
+ {children}
282
+ </kbd>
283
+ );
284
+ }
@@ -1,5 +1,6 @@
1
1
  import { Palette, RotateCcw, Shuffle, X } from 'lucide-react';
2
2
  import type { DesignSystem } from '../../lib/design';
3
+ import { useT } from '../../lib/i18n';
3
4
  import { ColorField, FontField, type FontPreset, Section, SliderField } from '../panel/fields';
4
5
  import { PanelBanner, PanelIconButton, PanelShell } from '../panel/panel-shell';
5
6
  import { useDesignPanelState } from './design-provider';
@@ -53,6 +54,7 @@ const TYPE_KEYS: Array<{
53
54
  export function DesignPanel({ onClose }: { onClose: () => void }) {
54
55
  const { loaded, exists, warning, draft, dirty, update, resetToDefaults, shuffle } =
55
56
  useDesignPanelState();
57
+ const t = useT();
56
58
 
57
59
  // The dock stays closed until there is a draft to show, rather than opening
58
60
  // on a spinner the reader has to wait out.
@@ -60,46 +62,46 @@ export function DesignPanel({ onClose }: { onClose: () => void }) {
60
62
 
61
63
  return (
62
64
  <PanelShell
63
- label="Design"
65
+ label={t('Design')}
64
66
  header={
65
67
  <>
66
68
  <Palette aria-hidden className="size-3.5 flex-none text-muted-foreground" />
67
- <span className="font-medium text-xs">Design</span>
69
+ <span className="font-medium text-xs">{t('Design')}</span>
68
70
  {!exists && (
69
71
  <span
70
- title="This document has no design const yet — saving writes one"
72
+ title={t('This document has no design const yet — saving writes one')}
71
73
  className="rounded border border-border bg-muted px-1.5 py-px font-mono text-[9.5px] text-muted-foreground uppercase tracking-wider"
72
74
  >
73
- Draft
75
+ {t('Draft')}
74
76
  </span>
75
77
  )}
76
78
  <span
77
79
  aria-hidden
78
- title={dirty ? 'Unsaved changes' : undefined}
80
+ title={dirty ? t('Unsaved changes') : undefined}
79
81
  className={`size-1.5 rounded-full bg-foreground transition-opacity duration-150 ${dirty ? 'opacity-100' : 'opacity-0'}`}
80
82
  />
81
83
  </>
82
84
  }
83
85
  actions={
84
86
  <>
85
- <PanelIconButton label="Shuffle preset" onClick={shuffle}>
87
+ <PanelIconButton label={t('Shuffle preset')} onClick={shuffle}>
86
88
  <Shuffle className="size-3.5" />
87
89
  </PanelIconButton>
88
- <PanelIconButton label="Reset to defaults" onClick={resetToDefaults}>
90
+ <PanelIconButton label={t('Reset to defaults')} onClick={resetToDefaults}>
89
91
  <RotateCcw className="size-3.5" />
90
92
  </PanelIconButton>
91
- <PanelIconButton label="Close design panel (D)" onClick={onClose}>
93
+ <PanelIconButton label={t('Close design panel (D)')} onClick={onClose}>
92
94
  <X className="size-3.5" />
93
95
  </PanelIconButton>
94
96
  </>
95
97
  }
96
98
  banner={warning ? <PanelBanner>{warning}</PanelBanner> : null}
97
99
  >
98
- <Section title="Palette">
100
+ <Section title={t('Palette')}>
99
101
  {PALETTE_KEYS.map(({ key, label }) => (
100
102
  <ColorField
101
103
  key={key}
102
- label={label}
104
+ label={t(label)}
103
105
  value={draft.palette[key]}
104
106
  onChange={(value) =>
105
107
  update((d) => {
@@ -110,13 +112,13 @@ export function DesignPanel({ onClose }: { onClose: () => void }) {
110
112
  ))}
111
113
  </Section>
112
114
 
113
- <Section title="Fonts">
115
+ <Section title={t('Fonts')}>
114
116
  {FONT_KEYS.map(({ key, label }) => (
115
117
  <FontField
116
118
  key={key}
117
- label={label}
119
+ label={t(label)}
118
120
  value={draft.fonts[key]}
119
- presets={FONT_PRESETS}
121
+ presets={FONT_PRESETS.map((preset) => ({ ...preset, label: t(preset.label) }))}
120
122
  onChange={(value) =>
121
123
  update((d) => {
122
124
  d.fonts[key] = value;
@@ -126,11 +128,11 @@ export function DesignPanel({ onClose }: { onClose: () => void }) {
126
128
  ))}
127
129
  </Section>
128
130
 
129
- <Section title="Type scale">
131
+ <Section title={t('Type scale')}>
130
132
  {TYPE_KEYS.map(({ key, label, min, max }) => (
131
133
  <SliderField
132
134
  key={key}
133
- label={label}
135
+ label={t(label)}
134
136
  value={draft.typeScale[key]}
135
137
  min={min}
136
138
  max={max}
@@ -144,14 +146,14 @@ export function DesignPanel({ onClose }: { onClose: () => void }) {
144
146
  ))}
145
147
  {draft.typeScale.body < 12 && (
146
148
  <p className="text-[11px] text-muted-foreground leading-relaxed">
147
- Body under 12px prints below 9pt — hard to read on paper.
149
+ {t('Body under 12px prints below 9pt — hard to read on paper.')}
148
150
  </p>
149
151
  )}
150
152
  </Section>
151
153
 
152
- <Section title="Page">
154
+ <Section title={t('Page')}>
153
155
  <SliderField
154
- label="Margin"
156
+ label={t('Margin')}
155
157
  value={draft.margin}
156
158
  min={32}
157
159
  max={140}
@@ -164,7 +166,7 @@ export function DesignPanel({ onClose }: { onClose: () => void }) {
164
166
  }
165
167
  />
166
168
  <SliderField
167
- label="Leading"
169
+ label={t('Leading')}
168
170
  value={draft.leading}
169
171
  min={1.2}
170
172
  max={2}
@@ -176,7 +178,7 @@ export function DesignPanel({ onClose }: { onClose: () => void }) {
176
178
  }
177
179
  />
178
180
  <SliderField
179
- label="Radius"
181
+ label={t('Radius')}
180
182
  value={draft.radius}
181
183
  min={0}
182
184
  max={24}
@@ -10,6 +10,7 @@ import {
10
10
  } from 'react';
11
11
  import { type DesignSystem, defaultDesign, designToCssVars } from '../../lib/design';
12
12
  import { shuffleDesign } from '../../lib/design-presets';
13
+ import { useT } from '../../lib/i18n';
13
14
  import { useHistory } from '../history-provider';
14
15
  import { useDesign as useDesignFetch } from './use-design';
15
16
 
@@ -49,6 +50,7 @@ export function DesignProvider({ docId, children }: { docId: string; children: R
49
50
  const [committing, setCommitting] = useState(false);
50
51
  const [error, setError] = useState<string | null>(null);
51
52
  const history = useHistory();
53
+ const t = useT();
52
54
  const draftRef = useRef<DesignSystem | null>(null);
53
55
  draftRef.current = draft;
54
56
 
@@ -89,10 +91,10 @@ export function DesignProvider({ docId, children }: { docId: string; children: R
89
91
  setCommitting(true);
90
92
  const result = await save(current);
91
93
  setCommitting(false);
92
- const error = result.ok ? null : (result.error ?? 'Failed to save');
94
+ const error = result.ok ? null : (result.error ?? t('Failed to save'));
93
95
  setError(error);
94
96
  return error ? { ok: false, error } : { ok: true };
95
- }, [save]);
97
+ }, [save, t]);
96
98
 
97
99
  const discard = useCallback(() => {
98
100
  if (design) setDraft(clone(design));
@@ -27,6 +27,16 @@ export type DiagramProps = {
27
27
  className?: string;
28
28
  };
29
29
 
30
+ /**
31
+ * The compiled SVG carries its natural size as `width`/`height`, which pins it
32
+ * there whatever box holds it — a `width` prop or a narrow column then only
33
+ * shrinks the box while the drawing runs past it. Without them the viewBox
34
+ * scales the drawing to the box, its height following the aspect ratio.
35
+ */
36
+ function fluid(svg: string): string {
37
+ return svg.replace(/^<svg([^>]*?) width="[^"]*" height="[^"]*"/, '<svg$1');
38
+ }
39
+
30
40
  /**
31
41
  * A diagram compiled from Mermaid-flavoured text at build time. The SVG is
32
42
  * inlined rather than referenced through `<img>` so it inherits the document's
@@ -55,7 +65,7 @@ export function Diagram({
55
65
  ...(caption ? undefined : style),
56
66
  }}
57
67
  // biome-ignore lint/security/noDangerouslySetInnerHtml: the SVG is produced by this package's own renderer at build time, never from document input at runtime
58
- dangerouslySetInnerHTML={{ __html: chart.svg }}
68
+ dangerouslySetInnerHTML={{ __html: fluid(chart.svg) }}
59
69
  />
60
70
  );
61
71
 
@@ -8,6 +8,7 @@ import {
8
8
  isPreviewable,
9
9
  listAssets,
10
10
  } from '../lib/assets';
11
+ import { useT } from '../lib/i18n';
11
12
  import { cn } from '../lib/utils';
12
13
 
13
14
  type Group = { scope: string; label: string; assets: Asset[] };
@@ -18,6 +19,7 @@ type Group = { scope: string; label: string; assets: Asset[] };
18
19
  * paste into the source.
19
20
  */
20
21
  export function DocAssets({ docId }: { docId: string }) {
22
+ const t = useT();
21
23
  const [groups, setGroups] = useState<Group[] | null>(null);
22
24
  const [selected, setSelected] = useState<Asset | null>(null);
23
25
  const [copied, setCopied] = useState(false);
@@ -63,8 +65,7 @@ export function DocAssets({ docId }: { docId: string }) {
63
65
  <div className="flex-1 overflow-y-auto px-3 pb-6">
64
66
  {empty && (
65
67
  <p className="px-1 py-2 text-muted-foreground text-xs leading-relaxed">
66
- No assets yet. Drop files into <code className="font-mono">docs/{docId}/assets/</code> or
67
- upload them from the Assets page.
68
+ {t('No assets yet. Add images from the Assets page.')}
68
69
  </p>
69
70
  )}
70
71
 
@@ -72,7 +73,7 @@ export function DocAssets({ docId }: { docId: string }) {
72
73
  group.assets.length === 0 ? null : (
73
74
  <section key={group.scope} className="mb-4">
74
75
  <h3 className="mb-1.5 px-1 text-[10px] text-muted-foreground uppercase tracking-wider">
75
- {group.label}
76
+ {t(group.label)}
76
77
  </h3>
77
78
  <div className="grid grid-cols-2 gap-1.5">
78
79
  {group.assets.map((asset) => (
@@ -109,7 +110,7 @@ export function DocAssets({ docId }: { docId: string }) {
109
110
  <p className="truncate font-medium text-[11px]">{selected.name}</p>
110
111
  <p className="mt-0.5 text-[10px] text-muted-foreground">
111
112
  {formatBytes(selected.size)}
112
- {selected.unused ? ' · unused' : ''}
113
+ {selected.unused ? t(' · unused') : ''}
113
114
  </p>
114
115
  <code className="mt-1.5 block truncate rounded bg-muted px-1.5 py-1 font-mono text-[10px]">
115
116
  {selected.importPath}
@@ -120,7 +121,7 @@ export function DocAssets({ docId }: { docId: string }) {
120
121
  className="mt-1.5 flex w-full items-center justify-center gap-1 rounded border border-border px-2 py-1 text-[11px] transition-colors hover:bg-accent"
121
122
  >
122
123
  {copied ? <Check className="size-3" /> : <Copy className="size-3" />}
123
- {copied ? 'Copied' : 'Copy import'}
124
+ {copied ? t('Copied') : t('Copy import')}
124
125
  </button>
125
126
  </div>
126
127
  )}
@@ -13,6 +13,7 @@
13
13
 
14
14
  import { ChevronDown, ChevronUp, Search, X } from 'lucide-react';
15
15
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
16
+ import { useT } from '../lib/i18n';
16
17
 
17
18
  const ALL = 'od-search';
18
19
  const ACTIVE = 'od-search-active';
@@ -76,6 +77,7 @@ export function DocSearch({
76
77
  pagesRef: React.RefObject<HTMLElement | null>;
77
78
  onFoundPage?: (page: number) => void;
78
79
  }) {
80
+ const t = useT();
79
81
  const [open, setOpen] = useState(false);
80
82
  const [query, setQuery] = useState('');
81
83
  const [hits, setHits] = useState<Hit[]>([]);
@@ -178,8 +180,8 @@ export function DocSearch({
178
180
  return (
179
181
  <button
180
182
  type="button"
181
- aria-label="Find in document"
182
- title="Find in document"
183
+ aria-label={t('Find in document')}
184
+ title={t('Find in document')}
183
185
  onClick={() => {
184
186
  setOpen(true);
185
187
  requestAnimationFrame(() => inputRef.current?.focus());
@@ -207,8 +209,8 @@ export function DocSearch({
207
209
  go(event.shiftKey ? -1 : 1);
208
210
  }
209
211
  }}
210
- placeholder="Find"
211
- aria-label="Find in document"
212
+ placeholder={t('Find')}
213
+ aria-label={t('Find in document')}
212
214
  className="w-28 bg-transparent text-xs outline-none placeholder:text-muted-foreground"
213
215
  />
214
216
  <span className="flex-none font-mono text-[11px] text-muted-foreground tabular-nums">
@@ -216,8 +218,8 @@ export function DocSearch({
216
218
  </span>
217
219
  <button
218
220
  type="button"
219
- aria-label="Previous match"
220
- title="Previous match (⇧⏎)"
221
+ aria-label={t('Previous match')}
222
+ title={`${t('Previous match')} (⇧⏎)`}
221
223
  onClick={() => go(-1)}
222
224
  disabled={hits.length === 0}
223
225
  className="flex size-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-40"
@@ -226,8 +228,8 @@ export function DocSearch({
226
228
  </button>
227
229
  <button
228
230
  type="button"
229
- aria-label="Next match"
230
- title="Next match (⏎)"
231
+ aria-label={t('Next match')}
232
+ title={`${t('Next match')} (⏎)`}
231
233
  onClick={() => go(1)}
232
234
  disabled={hits.length === 0}
233
235
  className="flex size-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-40"
@@ -236,8 +238,8 @@ export function DocSearch({
236
238
  </button>
237
239
  <button
238
240
  type="button"
239
- aria-label="Close search"
240
- title="Close search (Esc)"
241
+ aria-label={t('Close search')}
242
+ title={`${t('Close search')} (Esc)`}
241
243
  onClick={close}
242
244
  className="flex size-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
243
245
  >