@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,5 +1,6 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import type { DesignSystem } from '../lib/design';
3
+ import { useT } from '../lib/i18n';
3
4
  import type { OutlineEntry } from '../lib/outline';
4
5
  import type { PageGeometry } from '../lib/sdk';
5
6
  import type { ExpandedPage } from '../lib/use-doc-pages';
@@ -7,7 +8,7 @@ import { cn } from '../lib/utils';
7
8
  import { DocAssets } from './doc-assets';
8
9
  import { PageFrame } from './page-frame';
9
10
 
10
- const THUMB_WIDTH = 116;
11
+ const THUMB_WIDTH = 150;
11
12
 
12
13
  type Tab = 'pages' | 'outline' | 'assets';
13
14
 
@@ -34,6 +35,7 @@ export function DocSidebar({
34
35
  onSelectPage,
35
36
  onSelectEntry,
36
37
  }: Props) {
38
+ const t = useT();
37
39
  const [tab, setTab] = useState<Tab>('pages');
38
40
  const railRef = useRef<HTMLDivElement>(null);
39
41
  // The assets panel talks to the dev API, so it has nothing to show in a
@@ -57,7 +59,7 @@ export function DocSidebar({
57
59
  }, [currentPage, tab]);
58
60
 
59
61
  return (
60
- <aside className="hidden w-56 flex-none flex-col border-border border-r bg-background md:flex">
62
+ <aside className="hidden w-56 flex-none flex-col bg-background md:flex">
61
63
  <div className="flex flex-none gap-1 p-2">
62
64
  {tabs.map((value) => (
63
65
  <button
@@ -65,13 +67,13 @@ export function DocSidebar({
65
67
  type="button"
66
68
  onClick={() => setTab(value)}
67
69
  className={cn(
68
- 'flex-1 rounded-md px-2 py-1 text-[11px] capitalize transition-colors',
70
+ 'flex-1 truncate whitespace-nowrap rounded-md px-2 py-1 text-[11px] capitalize transition-colors',
69
71
  tab === value
70
72
  ? 'bg-accent font-medium text-foreground'
71
73
  : 'text-muted-foreground hover:bg-accent/60',
72
74
  )}
73
75
  >
74
- {value}
76
+ {t(value)}
75
77
  </button>
76
78
  ))}
77
79
  </div>
@@ -79,8 +81,8 @@ export function DocSidebar({
79
81
  {tab === 'assets' ? (
80
82
  <DocAssets docId={docId} />
81
83
  ) : tab === 'pages' ? (
82
- <div ref={railRef} className="flex-1 overflow-y-auto px-3 pb-6">
83
- <div className="flex flex-col items-center gap-3">
84
+ <div ref={railRef} className="flex-1 overflow-y-auto px-2 pb-6">
85
+ <div className="flex flex-col gap-1">
84
86
  {pages.map((entry, index) => {
85
87
  const page = index + 1;
86
88
  return (
@@ -89,14 +91,27 @@ export function DocSidebar({
89
91
  type="button"
90
92
  data-thumb-page={page}
91
93
  onClick={() => onSelectPage(page)}
92
- className="flex flex-col items-center gap-1"
94
+ aria-label={t('Page {page}', { page })}
95
+ aria-current={page === currentPage ? 'page' : undefined}
96
+ className={cn(
97
+ 'group flex w-full items-start gap-2 rounded-md p-1.5 transition-colors',
98
+ page === currentPage ? 'bg-accent' : 'hover:bg-accent/60',
99
+ )}
93
100
  >
101
+ <span
102
+ className={cn(
103
+ 'w-5 flex-none pt-0.5 text-right font-mono text-[10px] tabular-nums',
104
+ page === currentPage ? 'text-foreground' : 'text-muted-foreground',
105
+ )}
106
+ >
107
+ {String(page).padStart(2, '0')}
108
+ </span>
94
109
  <div
95
110
  className={cn(
96
111
  'overflow-hidden rounded-sm ring-1 transition-shadow',
97
112
  page === currentPage
98
113
  ? 'ring-2 ring-foreground'
99
- : 'ring-border hover:ring-foreground/40',
114
+ : 'ring-border group-hover:ring-foreground/40',
100
115
  )}
101
116
  style={{
102
117
  width: THUMB_WIDTH,
@@ -114,14 +129,6 @@ export function DocSidebar({
114
129
  {entry.content}
115
130
  </PageFrame>
116
131
  </div>
117
- <span
118
- className={cn(
119
- 'font-mono text-[10px] tabular-nums',
120
- page === currentPage ? 'text-foreground' : 'text-muted-foreground',
121
- )}
122
- >
123
- {page}
124
- </span>
125
132
  </button>
126
133
  );
127
134
  })}
@@ -131,8 +138,7 @@ export function DocSidebar({
131
138
  <nav className="flex-1 overflow-y-auto px-2 pb-6">
132
139
  {entries.length === 0 ? (
133
140
  <p className="px-2 py-1 text-muted-foreground text-xs leading-relaxed">
134
- No headings yet. Add an <code className="font-mono">h1</code>/
135
- <code className="font-mono">h2</code> to a page and it shows up here.
141
+ {t('No headings yet.')}
136
142
  </p>
137
143
  ) : (
138
144
  entries.map((entry) => (
@@ -51,10 +51,12 @@ export function FlowPage({
51
51
  blocks?: ReactNode[];
52
52
  notes?: ExtractedNote[];
53
53
  }) {
54
+ const Header = section.header;
54
55
  const Footer = section.footer;
55
56
  const source = blocks ?? section.blocks;
56
57
  return (
57
58
  <div style={flowShellStyle(design, section.padding)}>
59
+ {Header && <Header />}
58
60
  <div style={{ flex: 1, minHeight: 0 }}>
59
61
  {blockIndices.map((index) => (
60
62
  <FlowBlock key={index}>{source[index]}</FlowBlock>
@@ -0,0 +1,434 @@
1
+ import {
2
+ AlignCenter,
3
+ AlignJustify,
4
+ AlignLeft,
5
+ AlignRight,
6
+ Bold,
7
+ CaseSensitive,
8
+ ChevronDown,
9
+ Italic,
10
+ Link2,
11
+ Lock,
12
+ type LucideIcon,
13
+ MoveHorizontal,
14
+ MoveVertical,
15
+ Type,
16
+ } from 'lucide-react';
17
+ import type { ReactNode } from 'react';
18
+ import { type Translate, useT } from '../../lib/i18n';
19
+ import {
20
+ isValidStyleValue,
21
+ PROP_TOKENS,
22
+ rgbToHex,
23
+ type StyleChanges,
24
+ type StyleInfo,
25
+ type StyleOrigin,
26
+ type StyleProp,
27
+ type StyleValue,
28
+ TOKENS,
29
+ tokenOf,
30
+ tokenValue,
31
+ } from '../../lib/inspector/format';
32
+ import { ColorField, NumberField, Section } from '../panel/fields';
33
+
34
+ /** What a key reads as right now: an unsaved change first, then the source, else inherited. */
35
+ type Current = { origin: StyleOrigin | null; pending: boolean };
36
+
37
+ function currentOf(prop: StyleProp, info: StyleInfo | null, pending: StyleChanges): Current {
38
+ if (prop in pending) {
39
+ const value = pending[prop];
40
+ if (value === null || value === undefined) return { origin: null, pending: true };
41
+ const token = typeof value === 'string' ? tokenOf(value) : null;
42
+ return {
43
+ origin: token ? { kind: 'token', token } : { kind: 'literal', value },
44
+ pending: true,
45
+ };
46
+ }
47
+ return { origin: info?.props?.[prop] ?? null, pending: false };
48
+ }
49
+
50
+ /** Where a value comes from, for a tooltip: a shared style object, or code the panel only shows. */
51
+ function originNote(t: Translate, current: Current): string | undefined {
52
+ const origin = current.origin;
53
+ if (current.pending || !origin) return undefined;
54
+ const from = origin.from ? t('from {name}', { name: origin.from }) : null;
55
+ const code = origin.kind === 'code' ? t('set in code: {code}', { code: origin.code }) : null;
56
+ return [code, from].filter(Boolean).join(' · ') || undefined;
57
+ }
58
+
59
+ // One frame for a composite control, so a number and its token chip read as
60
+ // one field, as they are one value.
61
+ const BOX_CLASS =
62
+ 'flex h-8 min-w-0 items-center rounded border border-border transition-colors focus-within:border-foreground/40';
63
+
64
+ const SELECT_CLASS =
65
+ 'h-8 min-w-0 flex-1 cursor-pointer appearance-none bg-transparent pr-6 text-xs outline-none';
66
+
67
+ const SEGMENT_CLASS =
68
+ 'flex h-8 min-w-8 flex-1 items-center justify-center rounded-[3px] text-foreground/70 transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-foreground/60 aria-pressed:bg-accent aria-pressed:text-foreground';
69
+
70
+ // Named with the number, as one string: "Light" alone is already the theme's.
71
+ const WEIGHTS: Array<[number, string]> = [
72
+ [300, 'Light 300'],
73
+ [400, 'Regular 400'],
74
+ [500, 'Medium 500'],
75
+ [600, 'Semibold 600'],
76
+ [700, 'Bold 700'],
77
+ [800, 'Extrabold 800'],
78
+ ];
79
+
80
+ const ALIGNS: Array<[string, string, LucideIcon]> = [
81
+ ['left', 'Align left', AlignLeft],
82
+ ['center', 'Align center', AlignCenter],
83
+ ['right', 'Align right', AlignRight],
84
+ ['justify', 'Justify', AlignJustify],
85
+ ];
86
+
87
+ type Choice = 'inherit' | `token:${string}` | 'custom';
88
+
89
+ function choiceOf(prop: StyleProp, current: Current): Choice {
90
+ const origin = current.origin;
91
+ if (origin === null || (origin.from && !current.pending)) return 'inherit';
92
+ const group = PROP_TOKENS[prop];
93
+ if (origin.kind === 'token' && group && TOKENS[group].some((t) => t.token === origin.token)) {
94
+ return `token:${origin.token}`;
95
+ }
96
+ return 'custom';
97
+ }
98
+
99
+ /**
100
+ * The value's source as a choice — inherited, one of the document's tokens,
101
+ * or this element's own. The chip names it, so a field linked to the design
102
+ * panel says so without being opened; the native select under it does the
103
+ * choosing, and the keyboard and screen reader with it.
104
+ */
105
+ function TokenChip({
106
+ label,
107
+ prop,
108
+ current,
109
+ compact = false,
110
+ onPick,
111
+ }: {
112
+ label: string;
113
+ prop: StyleProp;
114
+ current: Current;
115
+ /**
116
+ * Only an icon, for a field too narrow for a token name; `linked` keeps the
117
+ * name while a token is chosen, since that is the one worth reading.
118
+ */
119
+ compact?: boolean | 'linked';
120
+ onPick: (value: 'inherit' | string) => void;
121
+ }) {
122
+ const t = useT();
123
+ const group = PROP_TOKENS[prop];
124
+ const tokens = group ? TOKENS[group] : [];
125
+ const choice = choiceOf(prop, current);
126
+ const origin = current.origin;
127
+ const linked = choice.startsWith('token:');
128
+ const inheritLabel =
129
+ origin?.from && !current.pending ? t('From {name}', { name: origin.from }) : t('Inherited');
130
+ const shown =
131
+ choice === 'inherit'
132
+ ? origin?.from && !current.pending
133
+ ? origin.from
134
+ : t('Inherited')
135
+ : choice === 'custom'
136
+ ? origin?.kind === 'code'
137
+ ? t('Code')
138
+ : t('Custom')
139
+ : t(tokens.find((entry) => `token:${entry.token}` === choice)?.label ?? 'Custom');
140
+ return (
141
+ <span
142
+ title={originNote(t, current) ?? (linked ? `--od-${choice.slice(6)}` : undefined)}
143
+ className={`relative mr-1 flex h-6 flex-none items-center gap-0.5 rounded px-1.5 text-[11px] transition-colors hover:bg-accent has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-foreground/60 ${
144
+ linked ? 'bg-accent text-accent-foreground' : 'text-muted-foreground'
145
+ }`}
146
+ >
147
+ {compact === true || (compact === 'linked' && !linked) ? (
148
+ <Link2 aria-hidden className="size-3.5" />
149
+ ) : (
150
+ <span className="max-w-20 truncate">{shown}</span>
151
+ )}
152
+ <ChevronDown aria-hidden className="size-3 opacity-60" />
153
+ <select
154
+ aria-label={t('{label} token', { label })}
155
+ value={choice}
156
+ onChange={(e) => {
157
+ const next = e.target.value;
158
+ if (next === 'inherit') onPick('inherit');
159
+ else if (next.startsWith('token:')) onPick(tokenValue(next.slice(6)));
160
+ }}
161
+ className="absolute inset-0 cursor-pointer opacity-0"
162
+ >
163
+ <option value="inherit">{inheritLabel}</option>
164
+ {tokens.map((entry) => (
165
+ <option key={entry.token} value={`token:${entry.token}`}>
166
+ {t(entry.label)}
167
+ </option>
168
+ ))}
169
+ {choice === 'custom' && <option value="custom">{t('Custom')}</option>}
170
+ </select>
171
+ </span>
172
+ );
173
+ }
174
+
175
+ function Segments({ label, children }: { label: string; children: ReactNode }) {
176
+ return (
177
+ <fieldset
178
+ aria-label={label}
179
+ className="m-0 flex h-9 min-w-0 items-center gap-0.5 rounded border border-border p-0.5"
180
+ >
181
+ {children}
182
+ </fieldset>
183
+ );
184
+ }
185
+
186
+ export type FormatSectionProps = {
187
+ anchor: HTMLElement;
188
+ /** `null` while the source is still being read. */
189
+ info: StyleInfo | null;
190
+ pending: StyleChanges;
191
+ onChange: (prop: StyleProp, value: StyleValue | undefined, shown: StyleOrigin | null) => void;
192
+ };
193
+
194
+ /**
195
+ * Typography and colour for the selected element, written into its `style` in
196
+ * source. Values are read from the rendered element, so what the fields show
197
+ * is what is printed; whether a value is a design token, a shared style
198
+ * object's, or code comes from the source.
199
+ */
200
+ export function FormatSection({ anchor, info, pending, onChange }: FormatSectionProps) {
201
+ const t = useT();
202
+ const editable = info?.editable === true;
203
+ const cs = getComputedStyle(anchor);
204
+ const current = (prop: StyleProp) => currentOf(prop, info, pending);
205
+ const set = (prop: StyleProp, value: StyleValue | undefined) => {
206
+ if (value !== undefined && !isValidStyleValue(prop, value)) return;
207
+ onChange(prop, value, info?.props?.[prop] ?? null);
208
+ };
209
+ // Off in source when the element writes the key itself; otherwise only the
210
+ // unsaved change is taken back, since an inherited key is not this element's.
211
+ const clear = (prop: StyleProp) => {
212
+ const origin = info?.props?.[prop];
213
+ set(prop, origin && !origin.from ? null : undefined);
214
+ };
215
+ const pick = (prop: StyleProp) => (value: 'inherit' | string) =>
216
+ value === 'inherit' ? clear(prop) : set(prop, value);
217
+
218
+ const fontSize = Number.parseFloat(cs.fontSize) || 0;
219
+ const weight = Number.parseInt(cs.fontWeight, 10) || 400;
220
+ const italic = cs.fontStyle === 'italic';
221
+ const align = cs.textAlign === 'start' ? 'left' : cs.textAlign === 'end' ? 'right' : cs.textAlign;
222
+ const lineHeight =
223
+ cs.lineHeight === 'normal' || fontSize === 0
224
+ ? 1.2
225
+ : Number((Number.parseFloat(cs.lineHeight) / fontSize).toFixed(2));
226
+ const tracking = cs.letterSpacing === 'normal' ? 0 : Number.parseFloat(cs.letterSpacing) || 0;
227
+ const color = rgbToHex(cs.color) ?? '';
228
+ const background = rgbToHex(cs.backgroundColor) ?? '';
229
+
230
+ // A refused element keeps its fields, read-only: they still say what the
231
+ // element is set to, and the lock says why they do not move.
232
+ const locked = info !== null && !editable ? t(info.reason) : null;
233
+ const lock = locked ? (
234
+ <span role="img" aria-label={locked} title={locked} className="flex text-muted-foreground">
235
+ <Lock className="size-3.5" />
236
+ </span>
237
+ ) : undefined;
238
+
239
+ const font = current('fontFamily');
240
+ const fontChoice = choiceOf('fontFamily', font);
241
+
242
+ return (
243
+ <fieldset
244
+ disabled={!editable}
245
+ className={`m-0 min-w-0 border-0 p-0 transition-opacity ${locked ? 'opacity-50' : ''}`}
246
+ >
247
+ <Section title={t('Typography')} action={lock}>
248
+ <label className={`${BOX_CLASS} relative`} title={originNote(t, font)}>
249
+ <Type aria-hidden className="ml-2 size-3.5 flex-none text-muted-foreground" />
250
+ <select
251
+ aria-label={t('Font')}
252
+ value={fontChoice}
253
+ onChange={(e) => pick('fontFamily')(e.target.value)}
254
+ className={`${SELECT_CLASS} pl-2`}
255
+ >
256
+ <option value="inherit">
257
+ {font.origin?.from && !font.pending
258
+ ? t('From {name}', { name: font.origin.from })
259
+ : t('Inherited font')}
260
+ </option>
261
+ {TOKENS.font.map((entry) => (
262
+ <option key={entry.token} value={`token:${entry.token}`}>
263
+ {t('{name} font', { name: t(entry.label) })}
264
+ </option>
265
+ ))}
266
+ {fontChoice === 'custom' && <option value="custom">{t('Custom font')}</option>}
267
+ </select>
268
+ <ChevronDown
269
+ aria-hidden
270
+ className="pointer-events-none absolute right-2 size-3.5 text-muted-foreground"
271
+ />
272
+ </label>
273
+
274
+ <div className={BOX_CLASS} title={originNote(t, current('fontSize'))}>
275
+ <NumberField
276
+ bare
277
+ label={t('Size in pixels')}
278
+ prefix={<CaseSensitive className="size-4" />}
279
+ value={Number(fontSize.toFixed(1))}
280
+ min={4}
281
+ max={400}
282
+ step={0.5}
283
+ suffix="px"
284
+ onChange={(value) => set('fontSize', `${value}px`)}
285
+ />
286
+ <TokenChip
287
+ label={t('Size')}
288
+ prop="fontSize"
289
+ current={current('fontSize')}
290
+ onPick={pick('fontSize')}
291
+ />
292
+ </div>
293
+
294
+ <div className="flex min-w-0 gap-2">
295
+ <label
296
+ className={`${BOX_CLASS} relative flex-1`}
297
+ title={originNote(t, current('fontWeight'))}
298
+ >
299
+ <select
300
+ aria-label={t('Weight')}
301
+ value={weight}
302
+ onChange={(e) => set('fontWeight', Number(e.target.value))}
303
+ className={`${SELECT_CLASS} pl-2`}
304
+ >
305
+ {WEIGHTS.some(([value]) => value === weight) ? null : (
306
+ <option value={weight}>{weight}</option>
307
+ )}
308
+ {WEIGHTS.map(([value, label]) => (
309
+ <option key={value} value={value}>
310
+ {t(label)}
311
+ </option>
312
+ ))}
313
+ </select>
314
+ <ChevronDown
315
+ aria-hidden
316
+ className="pointer-events-none absolute right-2 size-3.5 text-muted-foreground"
317
+ />
318
+ </label>
319
+ <Segments label={t('Emphasis')}>
320
+ <button
321
+ type="button"
322
+ aria-label={t('Bold')}
323
+ title={t('Bold')}
324
+ aria-pressed={weight >= 600}
325
+ onClick={() => set('fontWeight', weight >= 600 ? 400 : 700)}
326
+ className={SEGMENT_CLASS}
327
+ >
328
+ <Bold className="size-3.5" />
329
+ </button>
330
+ <button
331
+ type="button"
332
+ aria-label={t('Italic')}
333
+ title={t('Italic')}
334
+ aria-pressed={italic}
335
+ onClick={() => set('fontStyle', italic ? 'normal' : 'italic')}
336
+ className={SEGMENT_CLASS}
337
+ >
338
+ <Italic className="size-3.5" />
339
+ </button>
340
+ </Segments>
341
+ </div>
342
+
343
+ <Segments label={t('Alignment')}>
344
+ {ALIGNS.map(([value, label, Icon]) => (
345
+ <button
346
+ key={value}
347
+ type="button"
348
+ aria-label={t(label)}
349
+ title={t(label)}
350
+ aria-pressed={align === value}
351
+ onClick={() => set('textAlign', value)}
352
+ className={SEGMENT_CLASS}
353
+ >
354
+ <Icon className="size-3.5" />
355
+ </button>
356
+ ))}
357
+ </Segments>
358
+
359
+ <div className="grid grid-cols-2 gap-2">
360
+ <div
361
+ className={BOX_CLASS}
362
+ title={originNote(t, current('lineHeight')) ?? t('Line height')}
363
+ >
364
+ <NumberField
365
+ bare
366
+ label={t('Line height')}
367
+ prefix={<MoveVertical className="size-3.5" />}
368
+ value={lineHeight}
369
+ min={0.5}
370
+ max={4}
371
+ step={0.05}
372
+ onChange={(value) => set('lineHeight', value)}
373
+ />
374
+ <TokenChip
375
+ compact
376
+ label={t('Line height')}
377
+ prop="lineHeight"
378
+ current={current('lineHeight')}
379
+ onPick={pick('lineHeight')}
380
+ />
381
+ </div>
382
+ <div
383
+ className={BOX_CLASS}
384
+ title={originNote(t, current('letterSpacing')) ?? t('Letter spacing')}
385
+ >
386
+ <NumberField
387
+ bare
388
+ label={t('Letter spacing in pixels')}
389
+ prefix={<MoveHorizontal className="size-3.5" />}
390
+ value={Number(tracking.toFixed(2))}
391
+ min={-20}
392
+ max={50}
393
+ step={0.1}
394
+ suffix="px"
395
+ onChange={(value) => set('letterSpacing', `${value}px`)}
396
+ />
397
+ </div>
398
+ </div>
399
+ </Section>
400
+
401
+ <Section title={t('Color')} action={lock}>
402
+ <ColorField
403
+ label={t('Text')}
404
+ value={color}
405
+ onChange={(value) => set('color', value)}
406
+ trailing={
407
+ <TokenChip
408
+ compact="linked"
409
+ label={t('Text color')}
410
+ prop="color"
411
+ current={current('color')}
412
+ onPick={pick('color')}
413
+ />
414
+ }
415
+ />
416
+ <ColorField
417
+ label={t('Fill')}
418
+ value={background}
419
+ placeholder={t('None')}
420
+ onChange={(value) => set('background', value)}
421
+ trailing={
422
+ <TokenChip
423
+ compact="linked"
424
+ label={t('Fill')}
425
+ prop="background"
426
+ current={current('background')}
427
+ onPick={pick('background')}
428
+ />
429
+ }
430
+ />
431
+ </Section>
432
+ </fieldset>
433
+ );
434
+ }