@open-slide/core 2.0.0-beta.2 → 2.0.0-beta.5

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 (51) hide show
  1. package/README.md +1 -1
  2. package/dist/{build-Bzy-qlGc.js → build-Cu5_qRyE.js} +1 -1
  3. package/dist/cli/bin.js +3 -3
  4. package/dist/{config-nbSvY7z_.js → config-BQ6rD2iE.js} +226 -27
  5. package/dist/{config-DjWifhaA.d.ts → config-GMR1QUlM.d.ts} +1 -1
  6. package/dist/{dev-MXa5Tod4.js → dev-BK641O5e.js} +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +1 -1
  9. package/dist/locale/index.d.ts +1 -1
  10. package/dist/locale/index.js +1 -1
  11. package/dist/{preview-DEpQcKz3.js → preview-BuCI-RMW.js} +1 -1
  12. package/dist/{types-BWg-Dtbg.d.ts → types-BcbaKTNY.d.ts} +60 -0
  13. package/dist/vite/index.d.ts +1 -1
  14. package/dist/vite/index.js +1 -1
  15. package/dist/{zh-tw-DlKyeNX7.js → zh-tw-B51sMTg3.js} +267 -31
  16. package/package.json +5 -5
  17. package/src/app/components/asset-view.tsx +448 -0
  18. package/src/app/components/history-provider.tsx +68 -44
  19. package/src/app/components/icon-switcher-indicator.tsx +10 -0
  20. package/src/app/components/inspector/arrange-panel.tsx +449 -0
  21. package/src/app/components/inspector/inline-text-editor.tsx +170 -284
  22. package/src/app/components/inspector/inspect-overlay.tsx +642 -295
  23. package/src/app/components/inspector/inspector-panel.tsx +434 -427
  24. package/src/app/components/inspector/inspector-provider.tsx +564 -293
  25. package/src/app/components/inspector/save-bar.tsx +36 -0
  26. package/src/app/components/panel/editor-sidebar.tsx +50 -0
  27. package/src/app/components/panel/panel-fields.tsx +204 -16
  28. package/src/app/components/panel/panel-shell.tsx +3 -18
  29. package/src/app/components/style-panel/style-panel.tsx +4 -69
  30. package/src/app/lib/assets.ts +33 -0
  31. package/src/app/lib/inspector/geometry.test.ts +324 -0
  32. package/src/app/lib/inspector/geometry.ts +207 -0
  33. package/src/app/lib/inspector/text-edit-timeline.test.ts +121 -0
  34. package/src/app/lib/inspector/text-edit-timeline.ts +12 -0
  35. package/src/app/lib/inspector/text-selection.ts +117 -0
  36. package/src/app/lib/inspector/use-editor.ts +1 -1
  37. package/src/app/lib/inspector/use-visual-editor.ts +429 -0
  38. package/src/app/lib/inspector/visual-dom.ts +255 -0
  39. package/src/app/lib/keys.ts +9 -0
  40. package/src/app/lib/pptx/css.test.ts +33 -0
  41. package/src/app/lib/pptx/css.ts +12 -0
  42. package/src/app/lib/pptx/measure.ts +1 -19
  43. package/src/app/lib/use-document-title.test.ts +14 -0
  44. package/src/app/lib/use-document-title.ts +16 -0
  45. package/src/app/routes/presenter.tsx +2 -0
  46. package/src/app/routes/slide.tsx +36 -9
  47. package/src/locale/en.ts +70 -8
  48. package/src/locale/ja.ts +72 -7
  49. package/src/locale/types.ts +60 -0
  50. package/src/locale/zh-cn.ts +68 -8
  51. package/src/locale/zh-tw.ts +68 -8
@@ -1,6 +1,8 @@
1
+ import { useEffect } from 'react';
1
2
  import { useHistory } from '@/components/history-provider';
2
3
  import { SaveCard } from '@/components/panel/save-card';
3
4
  import { useDesignPanelState } from '@/components/style-panel/design-provider';
5
+ import { isTypingTarget } from '@/lib/keys';
4
6
  import { format, plural, useLocale } from '@/lib/use-locale';
5
7
  import { useInspector } from './inspector-provider';
6
8
 
@@ -26,6 +28,40 @@ export function SaveBar() {
26
28
  await Promise.all(tasks).catch(() => {});
27
29
  };
28
30
 
31
+ useEffect(() => {
32
+ if (!insp.active || committing) return;
33
+ const onKey = (event: KeyboardEvent) => {
34
+ if (!(event.metaKey || event.ctrlKey) || event.altKey) return;
35
+ if (isTypingTarget(event.target) && event.key.toLowerCase() !== 's') return;
36
+ if (document.querySelector('[data-visual-gesture]')) return;
37
+ if (
38
+ event.target instanceof Element &&
39
+ event.target.closest('[role="dialog"], [role="menu"], [role="listbox"]')
40
+ )
41
+ return;
42
+ const key = event.key.toLowerCase();
43
+ if (key === 'z' || (key === 'y' && event.ctrlKey)) {
44
+ event.preventDefault();
45
+ event.stopImmediatePropagation();
46
+ if (event.shiftKey || key === 'y') history.redo();
47
+ else history.undo();
48
+ } else if (key === 's') {
49
+ event.preventDefault();
50
+ event.stopImmediatePropagation();
51
+ if (
52
+ document.activeElement instanceof HTMLElement &&
53
+ !document.activeElement.isContentEditable
54
+ ) {
55
+ document.activeElement.blur();
56
+ }
57
+ void insp.commitEdits().catch(() => {});
58
+ if (design.dirty) void Promise.resolve(design.commit()).catch(() => {});
59
+ }
60
+ };
61
+ window.addEventListener('keydown', onKey, true);
62
+ return () => window.removeEventListener('keydown', onKey, true);
63
+ }, [insp.active, insp.commitEdits, committing, history, design.dirty, design.commit]);
64
+
29
65
  const onDiscard = () => {
30
66
  if (inspectorCount > 0) insp.cancelEdits();
31
67
  if (designCount > 0) design.discard();
@@ -0,0 +1,50 @@
1
+ import { useState } from 'react';
2
+ import { InspectorPanel } from '@/components/inspector/inspector-panel';
3
+ import { useInspector } from '@/components/inspector/inspector-provider';
4
+ import { useDesignPanelState } from '@/components/style-panel/design-provider';
5
+ import { DesignPanel } from '@/components/style-panel/style-panel';
6
+ import { PANEL_TRANSITION_MS, PANEL_W, usePanelMount } from './panel-shell';
7
+
8
+ export function EditorSidebar({
9
+ designOpen,
10
+ onCloseDesign,
11
+ }: {
12
+ designOpen: boolean;
13
+ onCloseDesign: () => void;
14
+ }) {
15
+ const { active, panelOpen } = useInspector();
16
+ const { loaded, draft } = useDesignPanelState();
17
+ const [preferredTab, setPreferredTab] = useState<'format' | 'arrange'>('format');
18
+ const mode = designOpen
19
+ ? loaded && draft
20
+ ? 'design'
21
+ : null
22
+ : active && panelOpen
23
+ ? 'format'
24
+ : null;
25
+ const [lastMode, setLastMode] = useState<'format' | 'design'>('format');
26
+ if (mode && mode !== lastMode) setLastMode(mode);
27
+ const open = mode !== null;
28
+ const { mounted, animVisible } = usePanelMount(open);
29
+
30
+ if (!mounted) return null;
31
+
32
+ return (
33
+ <div
34
+ data-editor-sidebar
35
+ inert={!open}
36
+ aria-hidden={!open}
37
+ className="flex h-full shrink-0 justify-end overflow-hidden bg-sidebar transition-[width] ease-swift motion-reduce:transition-none"
38
+ style={{
39
+ width: animVisible ? PANEL_W : 0,
40
+ transitionDuration: `${PANEL_TRANSITION_MS}ms`,
41
+ }}
42
+ >
43
+ {(mode ?? lastMode) === 'design' ? (
44
+ <DesignPanel onClose={onCloseDesign} />
45
+ ) : (
46
+ <InspectorPanel preferredTab={preferredTab} onTabChange={setPreferredTab} />
47
+ )}
48
+ </div>
49
+ );
50
+ }
@@ -1,17 +1,56 @@
1
+ import { ChevronRight, type LucideIcon, X } from 'lucide-react';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { Button } from '@/components/ui/button';
4
+ import { Input } from '@/components/ui/input';
1
5
  import { Label } from '@/components/ui/label';
6
+ import { useLocale } from '@/lib/use-locale';
7
+ import { cn } from '@/lib/utils';
2
8
 
3
- export function Section({ title, children }: { title: string; children: React.ReactNode }) {
9
+ export function Section({
10
+ title,
11
+ action,
12
+ children,
13
+ }: {
14
+ title: string;
15
+ action?: React.ReactNode;
16
+ children: React.ReactNode;
17
+ }) {
4
18
  return (
5
- <section className="px-3.5 py-3.5">
6
- <div className="mb-2.5 flex items-center gap-2">
19
+ <section className="px-3.5 py-4">
20
+ <div className="mb-2.5 flex items-center justify-between gap-2">
7
21
  <span className="eyebrow">{title}</span>
8
- <span aria-hidden className="h-px flex-1 bg-hairline" />
22
+ {action && <span className="-my-1 flex items-center">{action}</span>}
9
23
  </div>
10
24
  <div className="flex flex-col gap-2.5">{children}</div>
11
25
  </section>
12
26
  );
13
27
  }
14
28
 
29
+ export function CollapsibleSection({
30
+ title,
31
+ defaultOpen,
32
+ children,
33
+ }: {
34
+ title: string;
35
+ defaultOpen?: boolean;
36
+ children: React.ReactNode;
37
+ }) {
38
+ return (
39
+ <details className="group/section" open={defaultOpen}>
40
+ <summary className="flex cursor-pointer list-none items-center justify-between gap-2 px-3.5 py-4 outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/40 [&::-webkit-details-marker]:hidden">
41
+ <span className="eyebrow transition-colors group-hover/section:text-foreground">
42
+ {title}
43
+ </span>
44
+ <ChevronRight
45
+ aria-hidden
46
+ className="size-3 text-muted-foreground transition-transform duration-200 ease-swift group-open/section:rotate-90 motion-reduce:transition-none"
47
+ />
48
+ </summary>
49
+ <div className="-mt-1.5 flex flex-col gap-2.5 px-3.5 pb-4">{children}</div>
50
+ </details>
51
+ );
52
+ }
53
+
15
54
  export function Field({ label, children }: { label: string; children: React.ReactNode }) {
16
55
  return (
17
56
  <div className="grid grid-cols-[68px_1fr] items-center gap-3">
@@ -21,6 +60,59 @@ export function Field({ label, children }: { label: string; children: React.Reac
21
60
  );
22
61
  }
23
62
 
63
+ export function NumberShell({
64
+ icon: Icon,
65
+ prefix,
66
+ suffix,
67
+ label,
68
+ className,
69
+ children,
70
+ }: {
71
+ icon?: LucideIcon;
72
+ prefix?: string;
73
+ suffix?: string;
74
+ label?: string;
75
+ className?: string;
76
+ children: React.ReactNode;
77
+ }) {
78
+ return (
79
+ <div
80
+ title={label}
81
+ className={cn(
82
+ 'flex h-7 shrink-0 items-center rounded-[5px] border border-border bg-background pr-1.5 transition-colors focus-within:border-foreground/40 focus-within:ring-2 focus-within:ring-ring/30 has-[:disabled]:opacity-50',
83
+ (Icon || prefix) && 'pl-2',
84
+ className,
85
+ )}
86
+ >
87
+ {Icon && <Icon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />}
88
+ {prefix && (
89
+ <span aria-hidden className="shrink-0 font-mono text-[10px] text-muted-foreground">
90
+ {prefix}
91
+ </span>
92
+ )}
93
+ {children}
94
+ {suffix && (
95
+ <span className="font-mono text-[9.5px] uppercase tracking-[0.06em] text-muted-foreground/80">
96
+ {suffix}
97
+ </span>
98
+ )}
99
+ </div>
100
+ );
101
+ }
102
+
103
+ export function NumberInput({ className, ...props }: React.ComponentProps<'input'>) {
104
+ return (
105
+ <input
106
+ type="number"
107
+ className={cn(
108
+ 'nums h-full w-12 min-w-0 flex-1 bg-transparent px-2 text-right font-mono text-[11px] outline-none [appearance:textfield] disabled:cursor-not-allowed [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none',
109
+ className,
110
+ )}
111
+ {...props}
112
+ />
113
+ );
114
+ }
115
+
24
116
  export function NumberField({
25
117
  value,
26
118
  onChange,
@@ -28,6 +120,9 @@ export function NumberField({
28
120
  max,
29
121
  step = 1,
30
122
  suffix,
123
+ icon,
124
+ label,
125
+ className,
31
126
  }: {
32
127
  value: number;
33
128
  onChange: (n: number) => void;
@@ -35,26 +130,119 @@ export function NumberField({
35
130
  max?: number;
36
131
  step?: number;
37
132
  suffix?: string;
133
+ icon?: LucideIcon;
134
+ label?: string;
135
+ className?: string;
38
136
  }) {
137
+ const [draft, setDraft] = useState(String(value));
138
+ const focused = useRef(false);
139
+
140
+ useEffect(() => {
141
+ if (!focused.current) setDraft(String(value));
142
+ }, [value]);
143
+
39
144
  return (
40
- <div className="flex h-7 shrink-0 items-center rounded-[5px] border border-border bg-background pr-1.5 transition-colors focus-within:border-foreground/40 focus-within:ring-2 focus-within:ring-ring/30">
41
- <input
42
- type="number"
43
- value={value}
145
+ <NumberShell icon={icon} suffix={suffix} label={label} className={className}>
146
+ <NumberInput
147
+ aria-label={label}
148
+ value={draft}
149
+ onFocus={() => {
150
+ focused.current = true;
151
+ }}
152
+ onBlur={() => {
153
+ focused.current = false;
154
+ setDraft(String(value));
155
+ }}
44
156
  onChange={(e) => {
45
- const n = Number(e.target.value);
46
- if (Number.isFinite(n)) onChange(n);
157
+ const raw = e.target.value;
158
+ setDraft(raw);
159
+ const n = Number(raw);
160
+ if (!raw.trim() || !Number.isFinite(n)) return;
161
+ if (min !== undefined && n < min) return;
162
+ if (max !== undefined && n > max) return;
163
+ onChange(n);
47
164
  }}
48
165
  min={min}
49
166
  max={max}
50
167
  step={step}
51
- className="nums h-full w-12 bg-transparent px-2 text-right font-mono text-[11px] outline-none [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"
52
168
  />
53
- {suffix && (
54
- <span className="font-mono text-[9.5px] uppercase tracking-[0.06em] text-muted-foreground/80">
55
- {suffix}
56
- </span>
169
+ </NumberShell>
170
+ );
171
+ }
172
+
173
+ export function ColorField({
174
+ label,
175
+ value,
176
+ dim,
177
+ onChange,
178
+ onClear,
179
+ }: {
180
+ label: string;
181
+ value: string;
182
+ dim?: boolean;
183
+ onChange: (v: string) => void;
184
+ onClear?: () => void;
185
+ }) {
186
+ const [draft, setDraft] = useState(value);
187
+ const t = useLocale();
188
+ useEffect(() => setDraft(value), [value]);
189
+
190
+ return (
191
+ <Field label={label}>
192
+ <label className="relative inline-flex size-7 shrink-0 cursor-pointer items-center justify-center overflow-hidden rounded-[5px] border border-border bg-background transition-[border-color,scale] duration-150 hover:border-foreground/20 active:scale-[0.96] has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring/30">
193
+ <span
194
+ className={cn(
195
+ 'size-4 rounded-[3px]',
196
+ dim &&
197
+ 'bg-[repeating-conic-gradient(theme(colors.muted)_0_25%,transparent_0_50%)] bg-[length:8px_8px]',
198
+ )}
199
+ style={dim ? undefined : { backgroundColor: value }}
200
+ />
201
+ <input
202
+ type="color"
203
+ aria-label={label}
204
+ value={normalizeHex(value)}
205
+ onChange={(e) => onChange(e.target.value)}
206
+ className="absolute inset-0 cursor-pointer opacity-0"
207
+ />
208
+ </label>
209
+ <Input
210
+ type="text"
211
+ aria-label={label}
212
+ value={draft}
213
+ onChange={(e) => {
214
+ const v = e.target.value;
215
+ setDraft(v);
216
+ if (HEX6.test(v)) onChange(v);
217
+ }}
218
+ onBlur={() => {
219
+ if (!HEX6.test(draft)) setDraft(value);
220
+ }}
221
+ className="nums h-7 flex-1 px-2 font-mono text-[11px] uppercase"
222
+ spellCheck={false}
223
+ />
224
+ {onClear && (
225
+ <Button
226
+ variant="ghost"
227
+ size="icon-sm"
228
+ className="text-muted-foreground hover:text-foreground"
229
+ onClick={onClear}
230
+ aria-label={t.inspector.clearAria}
231
+ >
232
+ <X className="size-3.5" />
233
+ </Button>
57
234
  )}
58
- </div>
235
+ </Field>
59
236
  );
60
237
  }
238
+
239
+ const HEX6 = /^#[0-9a-fA-F]{6}$/;
240
+
241
+ function normalizeHex(value: string): string {
242
+ if (HEX6.test(value)) return value;
243
+ if (/^#[0-9a-fA-F]{3}$/.test(value)) {
244
+ const [, r, g, b] = value;
245
+ return `#${r}${r}${g}${g}${b}${b}`;
246
+ }
247
+ return '#000000';
248
+ }
@@ -35,7 +35,6 @@ export function usePanelMount(open: boolean): { mounted: boolean; animVisible: b
35
35
  }
36
36
 
37
37
  type PanelShellProps = {
38
- animVisible: boolean;
39
38
  uiAttr: 'inspector' | 'design';
40
39
  header: React.ReactNode;
41
40
  banner?: React.ReactNode;
@@ -43,24 +42,10 @@ type PanelShellProps = {
43
42
  children: React.ReactNode;
44
43
  };
45
44
 
46
- export function PanelShell({
47
- animVisible,
48
- uiAttr,
49
- header,
50
- banner,
51
- footer,
52
- children,
53
- }: PanelShellProps) {
45
+ export function PanelShell({ uiAttr, header, banner, footer, children }: PanelShellProps) {
54
46
  const dataAttrs = uiAttr === 'inspector' ? { 'data-inspector-ui': '' } : { 'data-design-ui': '' };
55
47
  return (
56
- <aside
57
- {...dataAttrs}
58
- className="flex h-full shrink-0 justify-end overflow-hidden bg-sidebar transition-[width] ease-swift motion-reduce:transition-none"
59
- style={{
60
- width: animVisible ? PANEL_W : 0,
61
- transitionDuration: `${PANEL_TRANSITION_MS}ms`,
62
- }}
63
- >
48
+ <aside {...dataAttrs} className="flex h-full shrink-0 bg-sidebar" style={{ width: PANEL_W }}>
64
49
  <div style={{ width: PANEL_W }} className="flex h-full shrink-0 flex-col">
65
50
  <header className="flex h-9 shrink-0 items-center justify-between gap-2 border-b border-hairline px-3">
66
51
  {header}
@@ -69,7 +54,7 @@ export function PanelShell({
69
54
  <ScrollArea className="min-h-0 flex-1">
70
55
  <div className="flex min-h-full flex-col">
71
56
  {children}
72
- {footer && <div className="mt-auto border-t border-hairline">{footer}</div>}
57
+ {footer && <div className="mt-auto">{footer}</div>}
73
58
  </div>
74
59
  </ScrollArea>
75
60
  </div>
@@ -1,13 +1,10 @@
1
1
  import { Palette, Shuffle, X } from 'lucide-react';
2
- import { useEffect, useState } from 'react';
3
- import { Field, NumberField, Section } from '@/components/panel/panel-fields';
4
- import { PanelShell, usePanelMount } from '@/components/panel/panel-shell';
2
+ import { ColorField, Field, NumberField, Section } from '@/components/panel/panel-fields';
3
+ import { PanelShell } from '@/components/panel/panel-shell';
5
4
  import { useLocale } from '@/lib/use-locale';
6
5
  import { cn } from '@/lib/utils';
7
6
  import { Button } from '../ui/button';
8
- import { Input } from '../ui/input';
9
7
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select';
10
- import { Separator } from '../ui/separator';
11
8
  import { Slider } from '../ui/slider';
12
9
  import { useDesignPanelState } from './design-provider';
13
10
 
@@ -24,25 +21,19 @@ const FONT_PRESETS: Array<{ label: string; value: string }> = [
24
21
  ];
25
22
 
26
23
  type DesignPanelProps = {
27
- open: boolean;
28
24
  onClose: () => void;
29
25
  };
30
26
 
31
- export function DesignPanel({ open, onClose }: DesignPanelProps) {
27
+ export function DesignPanel({ onClose }: DesignPanelProps) {
32
28
  const { draft, exists, warning, loaded, dirty, update, shuffle } = useDesignPanelState();
33
- // Gate the mount on data readiness so the first open still slides in
34
- // instead of popping fully expanded once loading finishes.
35
29
  const ready = loaded && draft != null;
36
- const { mounted, animVisible } = usePanelMount(open && ready);
37
30
  const t = useLocale();
38
31
 
39
32
  if (!ready) return null;
40
- if (!mounted) return null;
41
33
 
42
34
  return (
43
35
  <PanelShell
44
36
  uiAttr="design"
45
- animVisible={animVisible}
46
37
  header={
47
38
  <>
48
39
  <div className="flex min-w-0 items-center gap-2">
@@ -126,8 +117,6 @@ export function DesignPanel({ open, onClose }: DesignPanelProps) {
126
117
  />
127
118
  </Section>
128
119
 
129
- <Separator />
130
-
131
120
  <Section title={t.stylePanel.typographySection}>
132
121
  <FontField
133
122
  label={t.stylePanel.displayFontLabel}
@@ -175,8 +164,6 @@ export function DesignPanel({ open, onClose }: DesignPanelProps) {
175
164
  />
176
165
  </Section>
177
166
 
178
- <Separator />
179
-
180
167
  <Section title={t.stylePanel.shapeSection}>
181
168
  <SliderField
182
169
  label={t.stylePanel.radiusLabel}
@@ -222,47 +209,6 @@ export function DesignToggleButton({
222
209
  );
223
210
  }
224
211
 
225
- function ColorField({
226
- label,
227
- value,
228
- onChange,
229
- }: {
230
- label: string;
231
- value: string;
232
- onChange: (v: string) => void;
233
- }) {
234
- const [hexDraft, setHexDraft] = useState(value);
235
- useEffect(() => setHexDraft(value), [value]);
236
-
237
- return (
238
- <Field label={label}>
239
- <label className="relative inline-flex size-8 shrink-0 cursor-pointer items-center justify-center overflow-hidden rounded-md border bg-background shadow-xs transition-[border-color,scale] duration-150 hover:border-foreground/20 active:scale-[0.96] has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring/40">
240
- <span className="size-5 rounded-sm" style={{ backgroundColor: value }} />
241
- <input
242
- type="color"
243
- value={normalizeHex(value)}
244
- onChange={(e) => onChange(e.target.value)}
245
- className="absolute inset-0 cursor-pointer opacity-0"
246
- />
247
- </label>
248
- <Input
249
- type="text"
250
- value={hexDraft}
251
- onChange={(e) => {
252
- const v = e.target.value;
253
- setHexDraft(v);
254
- if (/^#[0-9a-fA-F]{6}$/.test(v)) onChange(v);
255
- }}
256
- onBlur={() => {
257
- if (!/^#[0-9a-fA-F]{6}$/.test(hexDraft)) setHexDraft(value);
258
- }}
259
- className="nums h-8 flex-1 font-mono text-[11px] uppercase"
260
- spellCheck={false}
261
- />
262
- </Field>
263
- );
264
- }
265
-
266
212
  function FontField({
267
213
  label,
268
214
  value,
@@ -286,7 +232,7 @@ function FontField({
286
232
  if (typeof v === 'string' && v !== '__custom__') onChange(v);
287
233
  }}
288
234
  >
289
- <SelectTrigger size="sm" className="h-8 flex-1 text-xs">
235
+ <SelectTrigger size="sm" className="flex-1 text-xs">
290
236
  <SelectValue />
291
237
  </SelectTrigger>
292
238
  <SelectContent>
@@ -344,14 +290,3 @@ function SliderField({
344
290
  </Field>
345
291
  );
346
292
  }
347
-
348
- function normalizeHex(value: string): string {
349
- if (/^#[0-9a-fA-F]{6}$/.test(value)) return value;
350
- if (/^#[0-9a-fA-F]{3}$/.test(value)) {
351
- const r = value[1];
352
- const g = value[2];
353
- const b = value[3];
354
- return `#${r}${r}${g}${g}${b}${b}`;
355
- }
356
- return '#000000';
357
- }
@@ -159,6 +159,39 @@ export async function fetchSvgAsFile(routeUrl: string, filename: string): Promis
159
159
  return new File([blob], filename, { type: 'image/svg+xml' });
160
160
  }
161
161
 
162
+ export type GoogleFontItem = {
163
+ family: string;
164
+ category: string;
165
+ // Weight keys from the Google Fonts catalog, e.g. ['400', '400i', '700'].
166
+ variants: string[];
167
+ };
168
+
169
+ export async function searchGoogleFonts(
170
+ query: string,
171
+ signal?: AbortSignal,
172
+ ): Promise<GoogleFontItem[]> {
173
+ const q = query.trim();
174
+ const params = new URLSearchParams();
175
+ if (q) params.set('q', q);
176
+ else params.set('limit', '30');
177
+ const res = await fetch(`/__gfonts/search?${params.toString()}`, { signal });
178
+ if (!res.ok) throw new Error(`gfonts ${res.status}`);
179
+ return (await res.json()) as GoogleFontItem[];
180
+ }
181
+
182
+ export async function fetchFontAsFile(
183
+ family: string,
184
+ variant: string,
185
+ filenameBase: string,
186
+ ): Promise<File> {
187
+ const params = new URLSearchParams({ family, variant });
188
+ const res = await fetch(`/__gfonts/download?${params.toString()}`);
189
+ if (!res.ok) throw new Error(`gfonts download ${res.status}`);
190
+ const ext = res.headers.get('x-font-ext') || 'ttf';
191
+ const blob = await res.blob();
192
+ return new File([blob], `${filenameBase}.${ext}`, { type: blob.type || 'font/ttf' });
193
+ }
194
+
162
195
  export type UseAssetsResult = {
163
196
  assets: AssetEntry[];
164
197
  loading: boolean;