@hanzo/studio 0.1.8 → 0.1.12
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.
- package/lib/app/director.d.ts +134 -0
- package/lib/app/director.js +1196 -0
- package/lib/app/flow-run.d.ts +34 -0
- package/lib/app/flow-run.js +77 -0
- package/lib/app/flow.d.ts +58 -0
- package/lib/app/flow.js +1213 -0
- package/lib/app/sections.d.ts +5 -0
- package/lib/app/sections.js +26 -0
- package/lib/attach.d.ts +2 -0
- package/lib/attach.js +7 -0
- package/lib/chat/turn.js +19 -11
- package/lib/desk.d.ts +1 -1
- package/lib/desk.js +370 -14
- package/lib/download.d.ts +2 -0
- package/lib/download.js +11 -0
- package/lib/gpu.d.ts +13 -1
- package/lib/gpu.js +39 -16
- package/lib/handoff.d.ts +2 -0
- package/lib/handoff.js +2 -0
- package/lib/home.d.ts +3 -1
- package/lib/home.js +98 -9
- package/lib/index.d.ts +7 -0
- package/lib/index.js +6 -0
- package/lib/kinds/app.d.ts +40 -0
- package/lib/kinds/app.js +907 -0
- package/lib/kinds/document.js +256 -19
- package/lib/kinds/image.d.ts +3 -0
- package/lib/kinds/image.js +82 -10
- package/lib/kinds/index.js +2 -1
- package/lib/kinds/sound.js +109 -10
- package/lib/kinds/video.js +146 -17
- package/lib/live.d.ts +11 -0
- package/lib/live.js +10 -0
- package/lib/made.d.ts +2 -1
- package/lib/made.js +1 -0
- package/lib/pdf.js +1 -1
- package/lib/places.d.ts +0 -3
- package/lib/places.js +185 -41
- package/lib/route.d.ts +18 -0
- package/lib/route.js +23 -0
- package/lib/starters.d.ts +21 -0
- package/lib/starters.js +33 -2
- package/lib/studio.js +1 -1
- package/lib/talk.js +149 -46
- package/lib/ui.d.ts +18 -4
- package/lib/ui.js +50 -22
- package/lib/wire.d.ts +19 -6
- package/lib/wire.js +36 -3
- package/package.json +1 -1
package/lib/starters.d.ts
CHANGED
|
@@ -29,3 +29,24 @@ export interface Starter {
|
|
|
29
29
|
/** Roughly how long one takes, for the card's corner. */
|
|
30
30
|
export declare const RUNTIME: Record<KindId, string>;
|
|
31
31
|
export declare const STARTERS: readonly Starter[];
|
|
32
|
+
/**
|
|
33
|
+
* A starter as another surface offers it (the Hanzo Library's Make something
|
|
34
|
+
* new): `kind` as the Library files what it makes, `preview` its picture or '',
|
|
35
|
+
* and `search` the query that starts it on any of Studio's addresses.
|
|
36
|
+
*/
|
|
37
|
+
export interface Offer {
|
|
38
|
+
id: string;
|
|
39
|
+
title: string;
|
|
40
|
+
subtitle: string;
|
|
41
|
+
kind: string;
|
|
42
|
+
preview: string;
|
|
43
|
+
search: string;
|
|
44
|
+
}
|
|
45
|
+
export declare const starters: readonly Offer[];
|
|
46
|
+
export declare const queue: (s: Starter) => void;
|
|
47
|
+
/**
|
|
48
|
+
* The starter a conversation starts from: one handed from Explore, else the one
|
|
49
|
+
* the page's query names, which is then taken out of the address so a reload
|
|
50
|
+
* does not start it again.
|
|
51
|
+
*/
|
|
52
|
+
export declare function take(): Starter | null;
|
package/lib/starters.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { starter, starting } from './route.js';
|
|
2
|
+
import { LIBRARY } from './wire.js';
|
|
1
3
|
export const CATEGORIES = [
|
|
2
4
|
{ id: 'all', label: 'All' },
|
|
3
5
|
{ id: 'image', label: 'Image' },
|
|
@@ -20,10 +22,11 @@ export const RUNTIME = {
|
|
|
20
22
|
slides: '~60s',
|
|
21
23
|
type: '~15s',
|
|
22
24
|
mesh: '~2m',
|
|
23
|
-
video: '~
|
|
25
|
+
video: '~15s',
|
|
24
26
|
ad: '~45s',
|
|
25
27
|
voice: '~5s',
|
|
26
|
-
music: '~
|
|
28
|
+
music: '~15s',
|
|
29
|
+
app: '~15s',
|
|
27
30
|
};
|
|
28
31
|
export const STARTERS = [
|
|
29
32
|
{ id: 'poster-jazz', kind: 'poster', category: 'poster', title: 'Jazz night poster', subtitle: 'A3, full bleed', prompt: 'A poster for a jazz night this Friday at 9pm at The Blue Room, 14 Canal Street. Smoky, warm, late-night. Free entry before 10.' },
|
|
@@ -56,7 +59,35 @@ export const STARTERS = [
|
|
|
56
59
|
{ id: 'voice-intro', kind: 'voice', category: 'audio', title: 'Podcast intro', subtitle: 'Voiceover', prompt: 'A warm 15 second podcast intro voiceover for "Small Hours", a show about people who work nights.' },
|
|
57
60
|
{ id: 'voice-ad', kind: 'voice', category: 'audio', title: 'Radio spot', subtitle: '30 second read', prompt: 'A 30 second radio ad read for Greenline Bikes summer sale, upbeat and friendly.' },
|
|
58
61
|
{ id: 'music-lofi', kind: 'music', category: 'audio', title: 'Lo-fi bed', subtitle: 'Instrumental', prompt: 'A 60 second lo-fi hip hop instrumental bed, mellow keys, vinyl crackle, 80 bpm.' },
|
|
62
|
+
{ id: 'app-music-studio', kind: 'app', category: 'audio', title: 'Music player & visualizer app', subtitle: 'From your audio or synth', prompt: 'Build a full-blown interactive music app with a real-time frequency visualizer, waveform scrubber, 3-band mastering EQ, tempo control, and live synth pads.' },
|
|
63
|
+
{ id: 'app-music-upload', kind: 'app', category: 'audio', title: 'Music app from your track', subtitle: 'Upload MP3 / WAV', prompt: 'Build a custom interactive music player, visualizer, and stem deck app around this music track.', picture: true },
|
|
59
64
|
{ id: 'fashion-ghost', kind: 'image', category: 'fashion', title: 'CAD to ghost mannequin', subtitle: 'From a flat drawing', prompt: 'Turn this garment drawing into a photorealistic ghost-mannequin product photo on white, true to its colours, print and proportions.', picture: true },
|
|
60
65
|
{ id: 'fashion-product', kind: 'image', category: 'fashion', title: 'Product photo', subtitle: 'From a flat lay', prompt: 'Turn this flat lay into a clean e-commerce product photo on a light grey background with a soft shadow.', picture: true },
|
|
61
66
|
{ id: 'fashion-swap', kind: 'image', category: 'fashion', title: 'Outfit swap', subtitle: 'Keep the model', prompt: 'Dress the person in this photo in a camel wool overcoat and a cream turtleneck. Keep their face, pose, light and background exactly.', picture: true },
|
|
62
67
|
];
|
|
68
|
+
export const starters = STARTERS.map((s) => ({ id: s.id, title: s.title, subtitle: s.subtitle, kind: LIBRARY[s.kind], preview: s.thumb ?? '', search: starting(s.id) }));
|
|
69
|
+
/** A starter handed from Explore to the conversation it starts. */
|
|
70
|
+
let queued = null;
|
|
71
|
+
export const queue = (s) => {
|
|
72
|
+
queued = s;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* The starter a conversation starts from: one handed from Explore, else the one
|
|
76
|
+
* the page's query names, which is then taken out of the address so a reload
|
|
77
|
+
* does not start it again.
|
|
78
|
+
*/
|
|
79
|
+
export function take() {
|
|
80
|
+
const s = queued ?? named();
|
|
81
|
+
queued = null;
|
|
82
|
+
return s;
|
|
83
|
+
}
|
|
84
|
+
function named() {
|
|
85
|
+
if (typeof window === 'undefined')
|
|
86
|
+
return null;
|
|
87
|
+
const { pathname, search, hash } = window.location;
|
|
88
|
+
const n = starter(search);
|
|
89
|
+
if (!n)
|
|
90
|
+
return null;
|
|
91
|
+
window.history.replaceState(window.history.state, '', `${pathname}${n.search}${hash}`);
|
|
92
|
+
return STARTERS.find((s) => s.id === n.id) ?? null;
|
|
93
|
+
}
|
package/lib/studio.js
CHANGED
|
@@ -46,7 +46,7 @@ function Rail() {
|
|
|
46
46
|
email: host.person.email,
|
|
47
47
|
onSignOut: host.signOut,
|
|
48
48
|
}
|
|
49
|
-
: { name: 'Sign in', onPress: () => host.signIn?.() }, collapsed: collapsed, onCollapse: setCollapsed, open: drawer, onOpenChange: setDrawer, label: "
|
|
49
|
+
: { name: 'Sign in', onPress: () => host.signIn?.() }, collapsed: collapsed, onCollapse: setCollapsed, open: drawer, onOpenChange: setDrawer, label: "Design" }));
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Studio. `rail={false}` leaves the left column to the host, which lists
|
package/lib/talk.js
CHANGED
|
@@ -9,14 +9,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
9
9
|
* A new conversation has no id in the address until its first message is sent;
|
|
10
10
|
* then the address names it, and the conversation in hand is the one shown.
|
|
11
11
|
*/
|
|
12
|
+
import { RING } from './ui.js';
|
|
12
13
|
import { Gutter, Panel, PanelToggle, Reply, SideProvider, useDeck, useKey, usePanel, useSplit } from '@hanzo/build';
|
|
13
14
|
import { SizableText, useMedia, XStack, YStack } from '@hanzo/gui';
|
|
14
|
-
import { Check, ChevronDown,
|
|
15
|
-
import { DropdownMenu } from '@hanzo/ui';
|
|
15
|
+
import { Check, ChevronDown, Clapperboard, FileText, Image as ImageIcon, LoaderCircle, Music, Palette, SlidersHorizontal, Sparkles, X } from '@hanzogui/lucide-icons-2';
|
|
16
|
+
import { DropdownMenu, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@hanzo/ui';
|
|
16
17
|
import { Chat as Thread, Failure } from '@hanzo/ui/chat';
|
|
17
18
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
18
19
|
import { edit as editInPlace, turn } from './chat/turn.js';
|
|
19
20
|
import { keep, listed, open } from './chat/store.js';
|
|
21
|
+
import { uploadFailure } from './attach.js';
|
|
20
22
|
import { Desk } from './desk.js';
|
|
21
23
|
import { Home } from './home.js';
|
|
22
24
|
import { useHost } from './host.js';
|
|
@@ -26,8 +28,8 @@ import { lit } from './kinds/kind.js';
|
|
|
26
28
|
import { PRESETS } from './kinds/type/system.js';
|
|
27
29
|
import { BRAIN, touch, useAvailable, useLibrary, useWire, WRITER } from './live.js';
|
|
28
30
|
import { blank, current } from './made.js';
|
|
29
|
-
import { take } from './places.js';
|
|
30
31
|
import { path } from './route.js';
|
|
32
|
+
import { take } from './starters.js';
|
|
31
33
|
import { useUrl } from './use.js';
|
|
32
34
|
import { put } from './wire.js';
|
|
33
35
|
/** The conversations open in this page, by id: an address change does not drop the one in hand. */
|
|
@@ -37,10 +39,16 @@ const pane = {
|
|
|
37
39
|
bg: 'var(--pane-fill, var(--sheet-1))',
|
|
38
40
|
rounded: 'var(--pane-round, var(--radius-xl))',
|
|
39
41
|
borderWidth: 1,
|
|
40
|
-
borderColor: 'var(--pane-edge, var(--
|
|
42
|
+
borderColor: 'var(--pane-edge, var(--border))',
|
|
41
43
|
boxShadow: 'var(--shadow-sheet-2)',
|
|
42
44
|
};
|
|
43
45
|
const gap = 'var(--pane-gap, var(--space-2))';
|
|
46
|
+
const REFINEMENT_CHIPS = [
|
|
47
|
+
{ id: 'mono', label: 'Minimal monochrome', snippet: 'minimal monochrome palette, clean negative space' },
|
|
48
|
+
{ id: 'editorial', label: 'Editorial poster', snippet: 'editorial poster composition, crisp typographic hierarchy' },
|
|
49
|
+
{ id: 'contrast', label: 'High contrast', snippet: 'high-contrast lighting, deep shadows, sharp detail' },
|
|
50
|
+
{ id: 'wide', label: '16:9 widescreen', snippet: '16:9 widescreen framing', aspect: '16:9' },
|
|
51
|
+
];
|
|
44
52
|
export function Talk({ id }) {
|
|
45
53
|
const host = useHost();
|
|
46
54
|
const wire = useWire(host);
|
|
@@ -74,7 +82,7 @@ export function Talk({ id }) {
|
|
|
74
82
|
};
|
|
75
83
|
}, [id, wire]);
|
|
76
84
|
if (failed) {
|
|
77
|
-
return (_jsxs(YStack, { flex: 1, items: "center", justify: "center", gap: "$3", p: "$5", children: [_jsx(SizableText, { color: "$soft", children: failed }), _jsx(XStack, { render: "button",
|
|
85
|
+
return (_jsxs(YStack, { flex: 1, items: "center", justify: "center", gap: "$3", p: "$5", children: [_jsx(SizableText, { color: "$soft", children: failed }), _jsx(XStack, { render: _jsx("button", { type: "button" }), onClick: () => host.go(''), px: "$3", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 34, height: 34 }, items: "center", rounded: "$3", borderWidth: 1, borderColor: "var(--border-strong)", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$2", color: "$ink", children: "Start a new one" }) })] }));
|
|
78
86
|
}
|
|
79
87
|
if (!chat) {
|
|
80
88
|
return (_jsx(YStack, { flex: 1, items: "center", justify: "center", children: _jsx(SizableText, { color: "$soft", children: "Opening\u2026" }) }));
|
|
@@ -85,10 +93,14 @@ function Conversation({ start, host, wire, available }) {
|
|
|
85
93
|
const [chat, setChat] = useState(start);
|
|
86
94
|
const latest = useRef(chat);
|
|
87
95
|
const [draft, setDraft] = useState('');
|
|
96
|
+
const [activeStarter, setActiveStarter] = useState(null);
|
|
97
|
+
const [appliedChips, setAppliedChips] = useState([]);
|
|
88
98
|
const [attached, setAttached] = useState([]);
|
|
89
99
|
const [uploading, setUploading] = useState(0);
|
|
100
|
+
const [uploadError, setUploadError] = useState('');
|
|
90
101
|
const [picked, setPicked] = useState(null);
|
|
91
102
|
const [options, setOptions] = useState({ model: 'auto', aspect: '', count: 1 });
|
|
103
|
+
const [openMenu, setOpenMenu] = useState(null);
|
|
92
104
|
const [working, setWorking] = useState(null);
|
|
93
105
|
const [editing, setEditing] = useState({});
|
|
94
106
|
const [editFailed, setEditFailed] = useState({});
|
|
@@ -146,12 +158,19 @@ function Conversation({ start, host, wire, available }) {
|
|
|
146
158
|
setWorking(ctl);
|
|
147
159
|
const files = attached;
|
|
148
160
|
setDraft('');
|
|
161
|
+
setAppliedChips([]);
|
|
149
162
|
setAttached([]);
|
|
163
|
+
setUploadError('');
|
|
150
164
|
// The address names the conversation from its first message on.
|
|
151
165
|
if (!latest.current.turns.length)
|
|
152
166
|
host.go(path({ kind: 'chat', id: latest.current.id }), { replace: true });
|
|
167
|
+
const defaultPrompt = files.some((f) => f.mime.startsWith('audio/'))
|
|
168
|
+
? 'Build a full-blown interactive music player and visualizer app around this audio track.'
|
|
169
|
+
: files.some((f) => f.mime.startsWith('video/'))
|
|
170
|
+
? 'Here is a video clip.'
|
|
171
|
+
: 'Here is an attached file.';
|
|
153
172
|
const asked = {
|
|
154
|
-
text: words ||
|
|
173
|
+
text: words || defaultPrompt,
|
|
155
174
|
attached: files,
|
|
156
175
|
kind: (how.kind ?? picked) || undefined,
|
|
157
176
|
options: { model: options.model === 'auto' ? undefined : options.model, aspect: options.aspect || undefined, count: options.count > 1 ? options.count : undefined },
|
|
@@ -174,7 +193,7 @@ function Conversation({ start, host, wire, available }) {
|
|
|
174
193
|
setWorking(null);
|
|
175
194
|
}
|
|
176
195
|
};
|
|
177
|
-
// A starter chosen in Explore
|
|
196
|
+
// A starter chosen in Explore, or named in the address, fills the composer for this conversation.
|
|
178
197
|
useEffect(() => {
|
|
179
198
|
const s = take();
|
|
180
199
|
if (s)
|
|
@@ -183,41 +202,102 @@ function Conversation({ start, host, wire, available }) {
|
|
|
183
202
|
}, []);
|
|
184
203
|
const begin = (s) => {
|
|
185
204
|
setPicked(s.kind);
|
|
205
|
+
setActiveStarter(s);
|
|
206
|
+
setAppliedChips([]);
|
|
207
|
+
// Fill the composer, but never overwrite words someone typed (another starter's text is fine to replace).
|
|
208
|
+
setDraft((prev) => (prev.trim() && prev !== activeStarter?.prompt ? prev : s.prompt));
|
|
186
209
|
if (s.picture && !attached.length) {
|
|
187
|
-
setDraft(s.prompt);
|
|
188
210
|
attach();
|
|
211
|
+
}
|
|
212
|
+
// Words are in the composer: put the cursor there so the person can edit and send.
|
|
213
|
+
if (typeof window !== 'undefined') {
|
|
214
|
+
window.requestAnimationFrame(() => document.querySelector('[data-slot="composer"] textarea')?.focus());
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const toggleRefinementChip = (chip) => {
|
|
218
|
+
const isOn = appliedChips.includes(chip.id);
|
|
219
|
+
if (isOn) {
|
|
220
|
+
setAppliedChips((prev) => prev.filter((id) => id !== chip.id));
|
|
221
|
+
setDraft((prev) => prev
|
|
222
|
+
.replace(new RegExp(`(?:,\\s*|\\s+)?${chip.snippet.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'i'), '')
|
|
223
|
+
.replace(/^,\s*/, '')
|
|
224
|
+
.trim());
|
|
225
|
+
if (chip.aspect && options.aspect === chip.aspect) {
|
|
226
|
+
setOptions((o) => ({ ...o, aspect: '' }));
|
|
227
|
+
}
|
|
189
228
|
return;
|
|
190
229
|
}
|
|
191
|
-
|
|
230
|
+
setAppliedChips((prev) => [...prev, chip.id]);
|
|
231
|
+
setDraft((prev) => {
|
|
232
|
+
const clean = prev.trim();
|
|
233
|
+
if (!clean)
|
|
234
|
+
return chip.snippet.charAt(0).toUpperCase() + chip.snippet.slice(1);
|
|
235
|
+
return clean.toLowerCase().includes(chip.snippet.toLowerCase()) ? clean : `${clean.replace(/[.,;]+$/, '')}, ${chip.snippet}`;
|
|
236
|
+
});
|
|
237
|
+
if (chip.aspect) {
|
|
238
|
+
setOptions((o) => ({ ...o, aspect: chip.aspect }));
|
|
239
|
+
}
|
|
192
240
|
};
|
|
193
|
-
const
|
|
241
|
+
const attachWith = (accept, promptText, kindId) => {
|
|
194
242
|
const input = document.createElement('input');
|
|
195
243
|
input.type = 'file';
|
|
196
|
-
input.accept = 'image
|
|
244
|
+
input.accept = accept || 'image/*,audio/*,video/*,.mp3,.wav,.flac,.m4a,.ogg,.aac,.mp4,.webm,.mov,.pdf,.docx,.pptx,.xlsx,.csv,.json,.txt,.md,*/*';
|
|
197
245
|
input.multiple = true;
|
|
198
|
-
input.onchange = () =>
|
|
246
|
+
input.onchange = () => {
|
|
247
|
+
const files = Array.from(input.files ?? []);
|
|
248
|
+
if (!files.length)
|
|
249
|
+
return;
|
|
250
|
+
if (kindId)
|
|
251
|
+
setPicked(kindId);
|
|
252
|
+
if (promptText && !draft.trim())
|
|
253
|
+
setDraft(promptText);
|
|
254
|
+
void upload(files);
|
|
255
|
+
};
|
|
199
256
|
input.click();
|
|
200
257
|
};
|
|
258
|
+
const attach = () => attachWith();
|
|
259
|
+
const inferMime = (f) => {
|
|
260
|
+
if (f.type)
|
|
261
|
+
return f.type;
|
|
262
|
+
const ext = f.name.split('.').pop()?.toLowerCase() ?? '';
|
|
263
|
+
if (['mp3', 'wav', 'flac', 'm4a', 'ogg', 'aac', 'opus'].includes(ext))
|
|
264
|
+
return `audio/${ext === 'mp3' ? 'mpeg' : ext}`;
|
|
265
|
+
if (['mp4', 'webm', 'mov', 'm4v'].includes(ext))
|
|
266
|
+
return `video/${ext === 'mov' ? 'quicktime' : ext}`;
|
|
267
|
+
if (['png', 'jpg', 'jpeg', 'webp', 'gif', 'svg', 'avif'].includes(ext))
|
|
268
|
+
return `image/${ext === 'jpg' ? 'jpeg' : ext}`;
|
|
269
|
+
if (ext === 'pdf')
|
|
270
|
+
return 'application/pdf';
|
|
271
|
+
return 'application/octet-stream';
|
|
272
|
+
};
|
|
201
273
|
const upload = async (files) => {
|
|
202
|
-
const
|
|
203
|
-
if (!
|
|
274
|
+
const batch = files.slice(0, 6);
|
|
275
|
+
if (!batch.length)
|
|
204
276
|
return;
|
|
205
|
-
|
|
206
|
-
|
|
277
|
+
setUploadError('');
|
|
278
|
+
setUploading((n) => n + batch.length);
|
|
279
|
+
const failedNames = [];
|
|
280
|
+
let lastReason = '';
|
|
281
|
+
for (const f of batch) {
|
|
207
282
|
try {
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
const
|
|
211
|
-
|
|
283
|
+
const mime = inferMime(f);
|
|
284
|
+
const folder = mime.startsWith('audio/') ? 'music' : mime.startsWith('video/') ? 'video' : mime.startsWith('image/') ? 'image' : 'document';
|
|
285
|
+
const name = f.name.replace(/[^\w.-]+/g, '-').slice(-80) || 'upload.bin';
|
|
286
|
+
const blob = f.type === mime ? f : new Blob([f], { type: mime });
|
|
287
|
+
const key = await put(wire, `files/${folder}/${latest.current.id}/attached/${Date.now().toString(36)}/${name}`, blob);
|
|
288
|
+
const bmp = mime.startsWith('image/') ? await createImageBitmap(f).catch(() => null) : null;
|
|
289
|
+
setAttached((a) => [...a, { key, mime, name, width: bmp?.width, height: bmp?.height }]);
|
|
212
290
|
bmp?.close();
|
|
213
291
|
}
|
|
214
|
-
catch {
|
|
215
|
-
|
|
292
|
+
catch (e) {
|
|
293
|
+
failedNames.push(f.name || 'file');
|
|
294
|
+
lastReason = e instanceof Error ? e.message : String(e);
|
|
216
295
|
}
|
|
217
296
|
finally {
|
|
218
297
|
setUploading((n) => n - 1);
|
|
219
298
|
}
|
|
220
299
|
}
|
|
300
|
+
setUploadError(uploadFailure(failedNames, lastReason));
|
|
221
301
|
};
|
|
222
302
|
const pick = (m, at) => changed({ ...latest.current, made: latest.current.made.map((x) => (x.id === m.id ? { ...x, at } : x)) });
|
|
223
303
|
const editOne = async (m, patch, note) => {
|
|
@@ -249,7 +329,7 @@ function Conversation({ start, host, wire, available }) {
|
|
|
249
329
|
label: m.title,
|
|
250
330
|
icon: _jsx(Icon, { size: 14 }),
|
|
251
331
|
bleed: true,
|
|
252
|
-
render: () => (_jsx(Desk, { made: chat.made.find((x) => x.id === m.id) ?? m, wire: wire, others: chat.made.filter((x) => x.id !== m.id), onPick: (at) => pick(m, at), onEdit: (patch, note) => void editOne(m, patch, note), busy: Boolean(editing[m.id]), failed: editFailed[m.id] })),
|
|
332
|
+
render: () => (_jsx(Desk, { made: chat.made.find((x) => x.id === m.id) ?? m, wire: wire, others: chat.made.filter((x) => x.id !== m.id), onPick: (at) => pick(m, at), onEdit: (patch, note) => void editOne(m, patch, note), busy: Boolean(editing[m.id]), failed: editFailed[m.id] }, m.id)),
|
|
253
333
|
};
|
|
254
334
|
}),
|
|
255
335
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -277,19 +357,19 @@ function Conversation({ start, host, wire, available }) {
|
|
|
277
357
|
void send(q.text);
|
|
278
358
|
};
|
|
279
359
|
const kindItems = [
|
|
280
|
-
{ key: 'auto', label: 'Auto', description: '
|
|
360
|
+
{ key: 'auto', label: 'Auto', description: 'Design picks from what you ask', selected: picked === null, onSelect: () => setPicked(null) },
|
|
281
361
|
...ALL.map((k) => {
|
|
282
362
|
const why = k.needs(available);
|
|
283
|
-
return { key: k.id, label: k.label, description: why ? 'Needs a GPU' : k.blurb, disabled: Boolean(why), onSelect: () => setPicked(k.id) };
|
|
363
|
+
return { key: k.id, label: k.label, description: why ? 'Needs a GPU' : k.blurb, selected: picked === k.id, disabled: Boolean(why), onSelect: () => setPicked(k.id) };
|
|
284
364
|
}),
|
|
285
365
|
];
|
|
286
366
|
const brandName = brandOf(chat);
|
|
287
367
|
const brandItems = [
|
|
288
368
|
{ type: 'label', key: 'h', label: 'Draw in' },
|
|
289
|
-
{ key: 'none', label: 'Hanzo (default)', onSelect: () => changed({ ...latest.current, brand: undefined }) },
|
|
369
|
+
{ key: 'none', label: 'Hanzo (default)', selected: !chat.brand, onSelect: () => changed({ ...latest.current, brand: undefined }) },
|
|
290
370
|
...chat.made
|
|
291
371
|
.filter((m) => m.kind === 'type')
|
|
292
|
-
.map((m) => ({ key: m.id, label: m.title, description: 'From this conversation', onSelect: () => changed({ ...latest.current, brand: m.id }) })),
|
|
372
|
+
.map((m) => ({ key: m.id, label: m.title, description: 'From this conversation', selected: chat.brand === m.id, onSelect: () => changed({ ...latest.current, brand: m.id }) })),
|
|
293
373
|
{ type: 'separator', key: 's' },
|
|
294
374
|
...PRESETS.map((p) => ({
|
|
295
375
|
key: `preset-${p.name}`,
|
|
@@ -307,18 +387,30 @@ function Conversation({ start, host, wire, available }) {
|
|
|
307
387
|
const zen = lit(available.fleet, 'image.zen');
|
|
308
388
|
const optionItems = [
|
|
309
389
|
{ type: 'label', key: 'm', label: 'Image model' },
|
|
310
|
-
{ key: 'auto', label:
|
|
311
|
-
...(zen ? [{ key: ZEN, label:
|
|
312
|
-
...MODELS.map((m) => ({ key: m.id, label:
|
|
390
|
+
{ key: 'auto', label: 'Auto', description: zen ? 'Zen Image on your GPU' : MODELS[0].label, selected: options.model === 'auto', onSelect: () => setOptions({ ...options, model: 'auto' }) },
|
|
391
|
+
...(zen ? [{ key: ZEN, label: 'Zen Image', description: 'On your GPU', selected: options.model === ZEN, onSelect: () => setOptions({ ...options, model: ZEN }) }] : []),
|
|
392
|
+
...MODELS.map((m) => ({ key: m.id, label: m.label, selected: options.model === m.id, onSelect: () => setOptions({ ...options, model: m.id }) })),
|
|
313
393
|
{ type: 'separator', key: 's' },
|
|
314
394
|
{ type: 'label', key: 'a', label: 'Aspect' },
|
|
315
|
-
...['', '1:1', '4:5', '9:16', '16:9', '3:2'].map((a) => ({ key: `a${a}`, label:
|
|
395
|
+
...['', '1:1', '4:5', '9:16', '16:9', '3:2'].map((a) => ({ key: `a${a}`, label: a || 'As asked', selected: options.aspect === a, onSelect: () => setOptions({ ...options, aspect: a }) })),
|
|
316
396
|
{ type: 'separator', key: 's2' },
|
|
317
397
|
{ type: 'label', key: 'c', label: 'How many' },
|
|
318
|
-
...[1, 2, 4].map((n) => ({ key: `c${n}`, label:
|
|
398
|
+
...[1, 2, 4].map((n) => ({ key: `c${n}`, label: String(n), selected: options.count === n, onSelect: () => setOptions({ ...options, count: n }) })),
|
|
319
399
|
];
|
|
320
|
-
const
|
|
321
|
-
const
|
|
400
|
+
const formatValue = picked ? kind(picked).label : 'Auto';
|
|
401
|
+
const activeModelLabel = options.model === 'auto'
|
|
402
|
+
? null
|
|
403
|
+
: options.model === ZEN
|
|
404
|
+
? 'Zen Image'
|
|
405
|
+
: (MODELS.find((m) => m.id === options.model)?.label ?? options.model);
|
|
406
|
+
const optionParts = [activeModelLabel, options.aspect || null, options.count > 1 ? `${options.count}×` : null].filter(Boolean);
|
|
407
|
+
const optionsValue = optionParts.length ? optionParts.join(' · ') : 'Auto';
|
|
408
|
+
const tools = (_jsx(TooltipProvider, { delay: 200, children: _jsxs(XStack, { items: "center", gap: "$2", flexWrap: "wrap", maxW: "100%", children: [_jsxs(Tooltip, { placement: "top", offset: 6, open: openMenu === 'format' ? false : undefined, children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(XStack, { items: "center", children: _jsx(DropdownMenu, { onOpenChange: (o) => setOpenMenu(o ? 'format' : null), trigger: _jsx(Pillish, { label: "Format", icon: _jsx(Sparkles, { size: 12, color: "$soft" }), value: formatValue, open: openMenu === 'format' }), items: kindItems }) }) }), _jsx(TooltipContent, { children: _jsx(SizableText, { size: "$1", color: "$ink", children: "Output format \u2014 Auto picks from what you ask" }) })] }), _jsxs(Tooltip, { placement: "top", offset: 6, open: openMenu === 'brand' ? false : undefined, children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(XStack, { items: "center", children: _jsx(DropdownMenu, { onOpenChange: (o) => setOpenMenu(o ? 'brand' : null), trigger: _jsx(Pillish, { label: "Brand", icon: _jsx(Palette, { size: 12, color: "$soft" }), value: brandName, open: openMenu === 'brand' }), items: brandItems }) }) }), _jsx(TooltipContent, { children: _jsx(SizableText, { size: "$1", color: "$ink", children: "Brand & type system used for typography and palette" }) })] }), _jsxs(Tooltip, { placement: "top", offset: 6, open: openMenu === 'options' ? false : undefined, children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(XStack, { items: "center", children: _jsx(DropdownMenu, { onOpenChange: (o) => setOpenMenu(o ? 'options' : null), trigger: _jsx(Pillish, { label: "Options", "aria-label": `Options: ${optionsValue} (image model, aspect ratio, count)`, icon: _jsx(SlidersHorizontal, { size: 12, color: "$soft" }), value: optionsValue, open: openMenu === 'options' }), items: optionItems }) }) }), _jsx(TooltipContent, { children: _jsx(SizableText, { size: "$1", color: "$ink", children: "Image model, aspect ratio, and variant count" }) })] })] }) }));
|
|
409
|
+
const showRefinementChips = Boolean(activeStarter || draft.trim().length > 0);
|
|
410
|
+
const head = attached.length || uploading || uploadError || showRefinementChips ? (_jsxs(YStack, { gap: "$2", width: "100%", minW: 0, children: [uploadError ? (_jsxs(XStack, { role: "alert", items: "center", justify: "space-between", gap: "$2", px: "$2.5", py: "$1.5", rounded: "$3", bg: "var(--state-error-bg)", borderWidth: 1, borderColor: "var(--state-error)", children: [_jsx(SizableText, { size: "$1", color: "var(--state-error)", flex: 1, minW: 0, children: uploadError }), _jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Dismiss upload error", onClick: () => setUploadError(''), width: 20, height: 20, rounded: 99, items: "center", justify: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, shrink: 0, children: _jsx(X, { size: 11, color: "var(--state-error)" }) })] })) : null, attached.length || uploading ? (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", "data-slot": "attached", children: [attached.map((f) => (_jsxs(XStack, { position: "relative", children: [_jsx(Thumb, { wire: wire, file: f }), _jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": `Remove ${f.name}`, onClick: () => setAttached((a) => a.filter((x) => x.key !== f.key)), position: "absolute", t: -6, r: -6, width: 22, height: 22, "$max-sm": { minW: 44, minH: 44, t: -14, r: -14 }, rounded: 99, bg: "$background", borderWidth: 1, borderColor: "var(--border-strong)", items: "center", justify: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(X, { size: 11, color: "$ink" }) })] }, f.key))), uploading ? (_jsx(XStack, { width: 56, height: 56, rounded: "$3", bg: "$hover", items: "center", justify: "center", children: _jsx(LoaderCircle, { size: 16 }) })) : null] })) : null, showRefinementChips ? (_jsxs(XStack, { role: "group", "aria-label": "Prompt refinements", gap: "$1.5", width: "100%", minW: 0, overflowX: "auto", flexWrap: "nowrap", items: "center", style: { scrollbarWidth: 'none' }, children: [activeStarter && empty ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", height: 26, rounded: 999, borderWidth: 1, borderColor: "var(--border)", bg: "var(--surface-card)", shrink: 0, children: [_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: activeStarter.title }), _jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Clear starter selection", onClick: () => setActiveStarter(null), width: 18, height: 18, "$max-sm": { minW: 44, minH: 44 }, rounded: 99, items: "center", justify: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(X, { size: 10, color: "$soft" }) })] })) : null, REFINEMENT_CHIPS.map((chip) => {
|
|
411
|
+
const on = appliedChips.includes(chip.id);
|
|
412
|
+
return (_jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-pressed": on, onClick: () => toggleRefinementChip(chip), items: "center", gap: "$1", px: "$2.5", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, rounded: 999, borderWidth: 1, borderColor: on ? '$ink' : 'var(--border-strong)', bg: on ? '$ink' : 'transparent', cursor: "pointer", hoverStyle: { bg: on ? '$ink' : '$hover' }, focusVisibleStyle: RING, shrink: 0, children: _jsx(SizableText, { size: "$1", fontWeight: on ? '500' : '400', color: on ? '$background' : '$soft', whiteSpace: "nowrap", children: chip.label }) }, chip.id));
|
|
413
|
+
})] })) : null] })) : undefined;
|
|
322
414
|
const composer = {
|
|
323
415
|
value: draft,
|
|
324
416
|
onChange: setDraft,
|
|
@@ -330,27 +422,33 @@ function Conversation({ start, host, wire, available }) {
|
|
|
330
422
|
label: 'What should we create?',
|
|
331
423
|
head,
|
|
332
424
|
plus: { upload: attach },
|
|
333
|
-
//
|
|
425
|
+
// Format, Brand, and image options align with the composer's inner text left edge.
|
|
334
426
|
pills: tools,
|
|
335
427
|
column: true,
|
|
336
428
|
narrow: !wide,
|
|
337
|
-
|
|
338
|
-
|
|
429
|
+
maxW: 720,
|
|
430
|
+
pb: empty ? '$6' : '$3',
|
|
339
431
|
};
|
|
340
432
|
const deskPane = (sheet) => (_jsx(Panel, { side: deck, kinds: tabs, onHide: () => setDesk(false), sheet: sheet, label: "What this conversation made" }));
|
|
341
|
-
return (_jsxs(XStack, { "data-slot": "studio-split", flex: 1, minH: 0, minW: 0, width: "100%", children: [_jsxs(YStack, { "data-slot": "studio-talk", ref: split.main, style: split.mainStyle, ...pane, flex: 1, minH: 0, minW: 0, width: "100%",
|
|
433
|
+
return (_jsxs(XStack, { "data-slot": "studio-split", flex: 1, minH: 0, minW: 0, width: "100%", children: [_jsxs(YStack, { "data-slot": "studio-talk", ref: split.main, style: split.mainStyle, ...pane, flex: 1, minH: 0, minW: 0, width: "100%", overflowY: empty ? 'auto' : 'hidden', overflowX: "hidden", children: [_jsxs(XStack, { px: "$4", pt: "$3", pb: "$2", gap: "$2", items: "center", minH: 44, shrink: 0, children: [empty ? (_jsx(SizableText, { size: "$3", fontWeight: "500", color: "$soft", numberOfLines: 1, flex: 1, minW: 0, children: "Design" })) : (_jsx(SizableText, { render: "h1", size: "$4", fontWeight: "600", color: "$ink", numberOfLines: 1, flex: 1, minW: 0, children: chat.title })), chat.made.length ? _jsx(PanelToggle, { open: desk, onToggle: () => setDesk(!desk) }) : null] }), _jsx(Thread, { messages: messages, streaming: busy, send: (text) => void send(text), stop: working ? () => working.abort() : undefined, body: body, center: true, onFiles: (files) => void upload(files), empty: _jsxs(YStack, { "data-slot": "studio-opening", width: "100%", maxW: 1040, mx: "auto", items: "center", px: "$3", $md: { px: '$4' }, pt: "$3", pb: "$5", gap: "$4", minW: 0, children: [_jsx(Opening, {}), _jsx(Home, { available: available, onStart: begin, onUpload: attachWith })] }), composer: composer })] }), desk && chat.made.length && !wide ? deskPane(true) : null, desk && chat.made.length && wide ? (_jsxs(YStack, { "data-slot": "studio-desk", ref: split.aside, ...pane, ml: gap, position: "relative", shrink: 0, minH: 0, style: split.asideStyle, children: [split.grip ? (_jsx(Gutter, { ...split.grip, label: "Resize the tabs", inset: pane.borderWidth })) : null, _jsx(SideProvider, { value: split.side, children: deskPane(false) })] })) : null] }));
|
|
342
434
|
}
|
|
343
435
|
function brandOf(chat) {
|
|
344
436
|
const m = chat.brand ? chat.made.find((x) => x.id === chat.brand) : null;
|
|
345
437
|
return m ? m.title : 'Hanzo';
|
|
346
438
|
}
|
|
347
439
|
function Opening() {
|
|
348
|
-
return (_jsxs(YStack, { items: "center", width: "100%", pt: "$
|
|
440
|
+
return (_jsxs(YStack, { items: "center", width: "100%", pt: "$2", pb: "$1", px: "$3", gap: "$2", children: [_jsx(SizableText, { render: "h1", size: "$7", fontWeight: "600", color: "$ink", text: "center", letterSpacing: -0.6, children: "What should we create?" }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", maxW: 520, lineHeight: 20, children: "Visuals, images, posters, presentations, documents, ads, 3D, video, music & interactive apps. Upload any file \u2014 everything opens in a tab." })] }));
|
|
349
441
|
}
|
|
350
|
-
/** A composer
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
442
|
+
/** A composer picker aligned to the composer's inner text left edge (11px composer-foot + 1px border + 4px px = 16px). */
|
|
443
|
+
function Pillish({ label, icon, value, open = false, ...trigger }) {
|
|
444
|
+
const compact = !useMedia().sm;
|
|
445
|
+
const { onPress: triggerOnPress, onClick: triggerOnClick, ...rest } = trigger;
|
|
446
|
+
return (_jsx(XStack, { ...rest, render: _jsx("button", { type: "button" }), onClick: (e) => {
|
|
447
|
+
if (triggerOnClick)
|
|
448
|
+
triggerOnClick(e);
|
|
449
|
+
else
|
|
450
|
+
triggerOnPress?.(e);
|
|
451
|
+
}, "aria-label": rest['aria-label'] ?? `${label}: ${value}`, "aria-expanded": open, items: "center", minH: compact ? 44 : 38, "$max-sm": { minH: 44 }, px: compact ? '$2' : 4, py: compact ? 0 : 4, rounded: "$3", borderWidth: 1, borderColor: open ? 'var(--border-strong)' : 'transparent', bg: open ? '$hover' : 'transparent', cursor: "pointer", hoverStyle: { bg: '$hover', borderColor: 'var(--border-strong)' }, focusVisibleStyle: RING, shrink: 0, children: compact ? (_jsxs(XStack, { items: "center", gap: "$1", minW: 0, children: [icon, _jsx(SizableText, { size: "$1", lineHeight: 14, color: "$hint", numberOfLines: 1, children: label }), _jsx(SizableText, { size: "$2", lineHeight: 16, fontWeight: "500", color: "$ink", numberOfLines: 1, maxW: 84, children: value }), _jsx(ChevronDown, { size: 11, color: "$soft" })] })) : (_jsxs(YStack, { items: "flex-start", gap: 1, minW: 0, children: [_jsx(SizableText, { size: "$1", lineHeight: 14, color: "$hint", numberOfLines: 1, children: label }), _jsxs(XStack, { items: "center", gap: "$1", minW: 0, children: [icon, _jsx(SizableText, { size: "$2", lineHeight: 18, fontWeight: "500", color: "$ink", numberOfLines: 1, maxW: 116, children: value }), _jsx(ChevronDown, { size: 11, color: "$soft" })] })] })) }));
|
|
354
452
|
}
|
|
355
453
|
/** What a turn made, as a chip that opens its tab. */
|
|
356
454
|
function Chip({ made, wire, n, onPress }) {
|
|
@@ -358,9 +456,14 @@ function Chip({ made, wire, n, onPress }) {
|
|
|
358
456
|
const Icon = k.icon;
|
|
359
457
|
const pic = current(made).files.find((f) => f.mime.startsWith('image/'));
|
|
360
458
|
const { src } = useUrl(wire, pic?.key);
|
|
361
|
-
return (_jsxs(XStack, { render: "button", "aria-label": `Open tab ${n}: ${made.title}`,
|
|
459
|
+
return (_jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": `Open tab ${n}: ${made.title}`, onClick: onPress, items: "center", gap: "$2", p: "$1.5", pr: "$3", minH: 44, "$max-sm": { minH: 44 }, rounded: "$4", borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--surface-card)", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, maxW: 280, children: [src ? (_jsx("img", { src: src, alt: "", width: 40, height: 40, style: { borderRadius: 8, objectFit: 'cover' } })) : (_jsx(XStack, { width: 40, height: 40, rounded: "$3", bg: "$hover", items: "center", justify: "center", "$platform-web": { color: 'var(--foreground)' }, children: _jsx(Icon, { size: 16 }) })), _jsxs(YStack, { minW: 0, children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: made.title }), _jsx(SizableText, { size: "$1", color: "$soft", children: `Tab ${n} · ${k.label} · v${made.at + 1}` })] }), _jsx(Check, { size: 13, color: "$ink" })] }));
|
|
362
460
|
}
|
|
363
461
|
function Thumb({ wire, file }) {
|
|
364
|
-
const
|
|
365
|
-
|
|
462
|
+
const isImage = file.mime.startsWith('image/');
|
|
463
|
+
const { src } = useUrl(wire, isImage ? file.key : undefined);
|
|
464
|
+
if (isImage && src) {
|
|
465
|
+
return _jsx("img", { src: src, alt: file.name, width: 56, height: 56, style: { borderRadius: 8, objectFit: 'cover' } });
|
|
466
|
+
}
|
|
467
|
+
const Icon = file.mime.startsWith('audio/') ? Music : file.mime.startsWith('video/') ? Clapperboard : isImage ? ImageIcon : FileText;
|
|
468
|
+
return (_jsxs(XStack, { height: 56, px: "$2.5", gap: "$2", rounded: "$3", bg: "var(--surface-card)", borderWidth: 1, borderColor: "var(--border)", items: "center", justify: "center", maxW: 180, children: [_jsx(Icon, { size: 16, color: "$ink" }), _jsx(SizableText, { size: "$1", color: "$ink", numberOfLines: 2, children: file.name })] }));
|
|
366
469
|
}
|
package/lib/ui.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
+
/** The focus ring every Studio control draws: one definition. */
|
|
3
|
+
export declare const RING: {
|
|
4
|
+
readonly outlineWidth: 2;
|
|
5
|
+
readonly outlineStyle: 'solid';
|
|
6
|
+
readonly outlineColor: 'var(--ring)';
|
|
7
|
+
};
|
|
8
|
+
/** The same ring drawn inside the edge, for a control that fills its clipped parent. */
|
|
9
|
+
export declare const RING_INSET: {
|
|
10
|
+
readonly outlineWidth: 2;
|
|
11
|
+
readonly outlineStyle: 'solid';
|
|
12
|
+
readonly outlineColor: 'var(--ring)';
|
|
13
|
+
readonly outlineOffset: -2;
|
|
14
|
+
};
|
|
2
15
|
export interface Option {
|
|
3
16
|
value: string;
|
|
4
17
|
label?: string;
|
|
@@ -32,19 +45,20 @@ export declare function Row({ label, children }: {
|
|
|
32
45
|
children: ReactNode;
|
|
33
46
|
}): import("react").JSX.Element;
|
|
34
47
|
/** A pill that is on or off: a category, a filter. */
|
|
35
|
-
export declare function Pill({ on, onPress, children, label }: {
|
|
48
|
+
export declare function Pill({ on, onPress, children, label, count, }: {
|
|
36
49
|
on: boolean;
|
|
37
50
|
onPress: () => void;
|
|
38
51
|
children: ReactNode;
|
|
39
52
|
label?: string;
|
|
53
|
+
count?: number;
|
|
40
54
|
}): import("react").JSX.Element;
|
|
41
55
|
/** A small press with an icon and a word: the tab bar's controls. */
|
|
42
|
-
export declare function Act({ onPress, children, label, on, disabled }: {
|
|
56
|
+
export declare function Act({ onPress, children, label, on, disabled, }: {
|
|
43
57
|
onPress: () => void;
|
|
44
58
|
children: ReactNode;
|
|
45
59
|
label: string;
|
|
46
60
|
on?: boolean;
|
|
47
61
|
disabled?: boolean;
|
|
48
62
|
}): import("react").JSX.Element;
|
|
49
|
-
/**
|
|
50
|
-
export declare function
|
|
63
|
+
/** Whether the user has asked the OS for reduced motion. */
|
|
64
|
+
export declare function reducedMotion(): boolean;
|
package/lib/ui.js
CHANGED
|
@@ -6,19 +6,44 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
* or @hanzo/build's.
|
|
7
7
|
*/
|
|
8
8
|
import { SizableText, styled, XStack, YStack } from '@hanzo/gui';
|
|
9
|
+
/** The focus ring every Studio control draws: one definition. */
|
|
10
|
+
export const RING = { outlineWidth: 2, outlineStyle: 'solid', outlineColor: 'var(--ring)' };
|
|
11
|
+
/** The same ring drawn inside the edge, for a control that fills its clipped parent. */
|
|
12
|
+
export const RING_INSET = { ...RING, outlineOffset: -2 };
|
|
9
13
|
const field = {
|
|
10
14
|
size: '$2',
|
|
11
15
|
minW: 0,
|
|
12
16
|
rounded: '$3',
|
|
13
17
|
borderWidth: 1,
|
|
14
|
-
borderColor: '
|
|
15
|
-
bg: '
|
|
18
|
+
borderColor: 'var(--border-strong)',
|
|
19
|
+
bg: 'var(--background)',
|
|
16
20
|
color: '$ink',
|
|
17
|
-
focusVisibleStyle:
|
|
21
|
+
focusVisibleStyle: RING,
|
|
18
22
|
};
|
|
19
|
-
const Select = styled(SizableText, {
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
const Select = styled(SizableText, {
|
|
24
|
+
name: 'StudioChoice',
|
|
25
|
+
render: 'select',
|
|
26
|
+
minH: 44,
|
|
27
|
+
$md: { minH: 32, height: 32 },
|
|
28
|
+
px: '$2',
|
|
29
|
+
cursor: 'pointer',
|
|
30
|
+
...field,
|
|
31
|
+
});
|
|
32
|
+
const Line = styled(SizableText, {
|
|
33
|
+
name: 'StudioLine',
|
|
34
|
+
render: 'input',
|
|
35
|
+
minH: 44,
|
|
36
|
+
$md: { minH: 32, height: 32 },
|
|
37
|
+
px: '$2.5',
|
|
38
|
+
...field,
|
|
39
|
+
});
|
|
40
|
+
const Lines = styled(SizableText, {
|
|
41
|
+
name: 'StudioLines',
|
|
42
|
+
render: 'textarea',
|
|
43
|
+
p: '$2.5',
|
|
44
|
+
minH: 76,
|
|
45
|
+
...field,
|
|
46
|
+
});
|
|
22
47
|
export function Choice({ value, options, onChange, label }) {
|
|
23
48
|
const all = value === '' || options.some((o) => o.value === value) ? options : [{ value }, ...options];
|
|
24
49
|
return (_jsx(Select, { ...{ value }, onChange: (e) => onChange(e.currentTarget.value), "aria-label": label, children: all.map((o) => (_jsx("option", { value: o.value, children: o.label ?? o.value }, o.value))) }));
|
|
@@ -30,28 +55,31 @@ export function TextN({ value, onChange, label, rows = 3 }) {
|
|
|
30
55
|
return _jsx(Lines, { ...{ value, rows }, onChange: (e) => onChange(e.currentTarget.value), "aria-label": label });
|
|
31
56
|
}
|
|
32
57
|
export function Color({ value, onChange, label }) {
|
|
33
|
-
return (_jsx("input", { type: "color", value: value, "aria-label": label, onChange: (e) => onChange(e.currentTarget.value), style: {
|
|
58
|
+
return (_jsx("input", { type: "color", value: value, "aria-label": label, onChange: (e) => onChange(e.currentTarget.value), style: {
|
|
59
|
+
width: 40,
|
|
60
|
+
height: 40,
|
|
61
|
+
padding: 2,
|
|
62
|
+
border: '1px solid var(--border-strong)',
|
|
63
|
+
borderRadius: 8,
|
|
64
|
+
background: 'var(--background)',
|
|
65
|
+
cursor: 'pointer',
|
|
66
|
+
} }));
|
|
34
67
|
}
|
|
35
68
|
/** A label above a control. */
|
|
36
69
|
export function Row({ label, children }) {
|
|
37
70
|
return (_jsxs(YStack, { gap: "$1", minW: 0, children: [_jsx(SizableText, { size: "$1", color: "$soft", children: label }), children] }));
|
|
38
71
|
}
|
|
39
72
|
/** A pill that is on or off: a category, a filter. */
|
|
40
|
-
export function Pill({ on, onPress, children, label }) {
|
|
41
|
-
return (
|
|
73
|
+
export function Pill({ on, onPress, children, label, count, }) {
|
|
74
|
+
return (_jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-pressed": on, "aria-label": label, onClick: onPress, items: "center", justify: "center", gap: "$1.5", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 32, height: 32 }, px: "$3", rounded: 999, borderWidth: 1, borderColor: on ? '$ink' : 'var(--border-strong)', bg: on ? '$ink' : 'transparent', cursor: "pointer", hoverStyle: { bg: on ? '$ink' : '$hover', borderColor: on ? '$ink' : 'var(--border-strong)' }, focusVisibleStyle: RING, shrink: 0, children: [_jsx(SizableText, { size: "$2", fontWeight: on ? '600' : '500', color: on ? '$background' : '$ink', whiteSpace: "nowrap", children: children }), count !== undefined ? (_jsx(SizableText, { "aria-hidden": true, size: "$1", fontFamily: "$mono", color: on ? '$background' : '$soft', opacity: on ? 0.72 : 0.85, whiteSpace: "nowrap", children: count })) : null] }));
|
|
42
75
|
}
|
|
43
76
|
/** A small press with an icon and a word: the tab bar's controls. */
|
|
44
|
-
export function Act({ onPress, children, label, on = false, disabled = false }) {
|
|
45
|
-
return (_jsx(XStack, { render: "button",
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
export function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
a.download = name;
|
|
53
|
-
document.body.appendChild(a);
|
|
54
|
-
a.click();
|
|
55
|
-
a.remove();
|
|
56
|
-
setTimeout(() => URL.revokeObjectURL(url), 10_000);
|
|
77
|
+
export function Act({ onPress, children, label, on = false, disabled = false, }) {
|
|
78
|
+
return (_jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": label, "aria-pressed": on || undefined, disabled: disabled, onClick: disabled ? undefined : onPress, items: "center", justify: "center", gap: "$1.5", minH: 44, minW: 44, "$max-sm": { minH: 44, minW: 44 }, $md: { minH: 30, minW: 30, height: 30 }, px: "$2.5", rounded: "$3", borderWidth: 1, borderColor: on ? 'var(--border-strong)' : 'transparent', bg: on ? '$hover' : 'transparent', opacity: disabled ? 0.4 : 1, cursor: disabled ? 'default' : 'pointer', hoverStyle: disabled ? undefined : { bg: '$hover', borderColor: 'var(--border-strong)' }, focusVisibleStyle: RING, shrink: 0, children: children }));
|
|
79
|
+
}
|
|
80
|
+
/** Whether the user has asked the OS for reduced motion. */
|
|
81
|
+
export function reducedMotion() {
|
|
82
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
83
|
+
return false;
|
|
84
|
+
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
57
85
|
}
|