@hanzo/studio 0.0.0-stage → 0.1.1
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/LICENSE +29 -0
- package/NOTICE +68 -0
- package/lib/chat/store.d.ts +33 -0
- package/lib/chat/store.js +56 -0
- package/lib/chat/turn.d.ts +51 -0
- package/lib/chat/turn.js +274 -0
- package/lib/desk.d.ts +14 -0
- package/lib/desk.js +72 -0
- package/lib/gpu.d.ts +15 -0
- package/lib/gpu.js +41 -0
- package/lib/home.d.ts +6 -0
- package/lib/home.js +48 -0
- package/lib/host.d.ts +12 -0
- package/lib/host.js +18 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +11 -0
- package/lib/kinds/ad.d.ts +51 -0
- package/lib/kinds/ad.js +124 -0
- package/lib/kinds/document.d.ts +6 -0
- package/lib/kinds/document.js +271 -0
- package/lib/kinds/image.d.ts +47 -0
- package/lib/kinds/image.js +179 -0
- package/lib/kinds/index.d.ts +9 -0
- package/lib/kinds/index.js +12 -0
- package/lib/kinds/kind.d.ts +113 -0
- package/lib/kinds/kind.js +13 -0
- package/lib/kinds/mesh/index.d.ts +2 -0
- package/lib/kinds/mesh/index.js +76 -0
- package/lib/kinds/mesh/viewer.d.ts +7 -0
- package/lib/kinds/mesh/viewer.js +79 -0
- package/lib/kinds/poster/compose.d.ts +40 -0
- package/lib/kinds/poster/compose.js +289 -0
- package/lib/kinds/poster/index.d.ts +21 -0
- package/lib/kinds/poster/index.js +210 -0
- package/lib/kinds/sound.d.ts +6 -0
- package/lib/kinds/sound.js +100 -0
- package/lib/kinds/type/fonts.d.ts +30 -0
- package/lib/kinds/type/fonts.js +111 -0
- package/lib/kinds/type/index.d.ts +5 -0
- package/lib/kinds/type/index.js +117 -0
- package/lib/kinds/type/system.d.ts +164 -0
- package/lib/kinds/type/system.js +302 -0
- package/lib/kinds/video.d.ts +2 -0
- package/lib/kinds/video.js +81 -0
- package/lib/live.d.ts +44 -0
- package/lib/live.js +128 -0
- package/lib/made.d.ts +75 -0
- package/lib/made.js +36 -0
- package/lib/nav.d.ts +17 -0
- package/lib/nav.js +29 -0
- package/lib/pdf.d.ts +16 -0
- package/lib/pdf.js +53 -0
- package/lib/places.d.ts +6 -0
- package/lib/places.js +121 -0
- package/lib/raster.d.ts +7 -0
- package/lib/raster.js +53 -0
- package/lib/route.d.ts +33 -0
- package/lib/route.js +52 -0
- package/lib/starters.d.ts +31 -0
- package/lib/starters.js +62 -0
- package/lib/studio.d.ts +26 -0
- package/lib/studio.js +58 -0
- package/lib/talk.d.ts +3 -0
- package/lib/talk.js +369 -0
- package/lib/ui.d.ts +50 -0
- package/lib/ui.js +57 -0
- package/lib/use.d.ts +11 -0
- package/lib/use.js +35 -0
- package/lib/wire.d.ts +239 -0
- package/lib/wire.js +478 -0
- package/lib/zip.d.ts +9 -0
- package/lib/zip.js +60 -0
- package/package.json +75 -3
- package/README.md +0 -3
package/lib/gpu.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A render on the org's GPUs, start to finish: dispatch through the engine's
|
|
3
|
+
* one funnel, follow its work-log row until the engine's integrity gate says
|
|
4
|
+
* done (or failed), and read back what landed.
|
|
5
|
+
*
|
|
6
|
+
* The engine's word is the only verdict: `done` is the row its gate closed, a
|
|
7
|
+
* `failed` row carries the engine's reason, and a row still `queued` when the
|
|
8
|
+
* wait runs out is said to be still rendering, never called finished.
|
|
9
|
+
*/
|
|
10
|
+
import { dispatch, landed, Refusal, worklog } from './wire.js';
|
|
11
|
+
/** How long a render is followed, ms: a cold model load plus a video. */
|
|
12
|
+
const WAIT = 20 * 60_000;
|
|
13
|
+
const EVERY = 3_000;
|
|
14
|
+
export async function render(w, lane, body, doing, signal) {
|
|
15
|
+
doing('Sending to your GPU');
|
|
16
|
+
const sent = await dispatch(w, lane, body, signal);
|
|
17
|
+
const id = sent.prompt_id ?? sent.id;
|
|
18
|
+
if (!id)
|
|
19
|
+
throw new Refusal(502, 'The engine took the render but named no job.');
|
|
20
|
+
const until = Date.now() + WAIT;
|
|
21
|
+
let row;
|
|
22
|
+
for (;;) {
|
|
23
|
+
if (signal.aborted)
|
|
24
|
+
throw new DOMException('aborted', 'AbortError');
|
|
25
|
+
row = (await worklog(w, signal)).find((r) => r.prompt_id === id || r.id === id);
|
|
26
|
+
const status = row?.status ?? 'queued';
|
|
27
|
+
if (status === 'done')
|
|
28
|
+
break;
|
|
29
|
+
if (status === 'failed' || status === 'cancelled')
|
|
30
|
+
throw new Refusal(502, row?.error || `The render ${status}.`);
|
|
31
|
+
if (Date.now() > until)
|
|
32
|
+
throw new Refusal(504, 'Still rendering on your GPU; it will land in the library when it finishes.');
|
|
33
|
+
doing(status === 'running' ? 'Rendering on your GPU' : 'Waiting for a GPU');
|
|
34
|
+
await new Promise((r) => setTimeout(r, EVERY));
|
|
35
|
+
}
|
|
36
|
+
const paths = row?.outputs?.length ? row.outputs : row?.output ? [row.output] : [];
|
|
37
|
+
if (!paths.length)
|
|
38
|
+
throw new Refusal(502, 'The render finished with no file.');
|
|
39
|
+
doing('Reading the result');
|
|
40
|
+
return Promise.all(paths.map(async (path) => ({ path, blob: await landed(w, path) })));
|
|
41
|
+
}
|
package/lib/home.d.ts
ADDED
package/lib/home.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Under the composer while a conversation is empty: the category pills, the
|
|
4
|
+
* starters that can run right now, and the last conversations. A starter
|
|
5
|
+
* starts a conversation with its first message; one that starts from a
|
|
6
|
+
* picture puts its words in the composer and asks for the picture.
|
|
7
|
+
*/
|
|
8
|
+
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
9
|
+
import { ArrowRight } from '@hanzogui/lucide-icons-2';
|
|
10
|
+
import { useState } from 'react';
|
|
11
|
+
import { useHost } from './host.js';
|
|
12
|
+
import { kind } from './kinds/index.js';
|
|
13
|
+
import { stack, use } from './kinds/type/fonts.js';
|
|
14
|
+
import { PRESETS } from './kinds/type/system.js';
|
|
15
|
+
import { useChats, useWire } from './live.js';
|
|
16
|
+
import { path } from './route.js';
|
|
17
|
+
import { CATEGORIES, RUNTIME, STARTERS } from './starters.js';
|
|
18
|
+
import { Pill } from './ui.js';
|
|
19
|
+
import { useUrl } from './use.js';
|
|
20
|
+
export function Home({ available, onStart }) {
|
|
21
|
+
const [cat, setCat] = useState('all');
|
|
22
|
+
const runs = STARTERS.filter((s) => !kind(s.kind).needs(available));
|
|
23
|
+
const shown = runs.filter((s) => cat === 'all' || s.category === cat);
|
|
24
|
+
const cats = CATEGORIES.filter((c) => c.id === 'all' || runs.some((s) => s.category === c.id));
|
|
25
|
+
return (_jsxs(YStack, { "data-slot": "studio-home", width: "100%", maxW: 1080, mx: "auto", gap: "$4", pt: "$4", pb: "$6", px: "$1", children: [_jsx(XStack, { role: "toolbar", "aria-label": "Categories", gap: "$2", flexWrap: "wrap", justify: "center", children: cats.map((c) => (_jsx(Pill, { on: cat === c.id, onPress: () => setCat(c.id), children: c.label }, c.id))) }), _jsx(XStack, { role: "list", "aria-label": "Starters", flexWrap: "wrap", gap: 12, children: shown.map((s, i) => (_jsx(Card, { s: s, i: i, onPress: () => onStart(s) }, s.id))) }), _jsx(Recent, {})] }));
|
|
26
|
+
}
|
|
27
|
+
/** A starter's card: 4:5, its picture, or its title set in type; its words under it. */
|
|
28
|
+
function Card({ s, i, onPress }) {
|
|
29
|
+
const k = kind(s.kind);
|
|
30
|
+
const Icon = k.icon;
|
|
31
|
+
const look = PRESETS[i % PRESETS.length];
|
|
32
|
+
use(look.display);
|
|
33
|
+
return (_jsxs(YStack, { role: "listitem", width: "calc(50% - 6px)", $sm: { width: 'calc(25% - 9px)' }, gap: "$1.5", children: [_jsxs(YStack, { render: "button", "aria-label": `${s.title}: ${s.subtitle}`, onPress: onPress, position: "relative", width: "100%", rounded: 16, overflow: "hidden", cursor: "pointer", hoverStyle: { opacity: 0.92 }, focusVisibleStyle: { outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' }, style: { aspectRatio: '4 / 5' }, children: [s.thumb ? (_jsx("img", { src: s.thumb, alt: "", style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } })) : (_jsxs("div", { "aria-hidden": true, style: { position: 'absolute', inset: 0, background: look.colors.paper, color: look.colors.ink, padding: '14% 10%', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', textAlign: 'left' }, children: [_jsx("div", { style: { width: '28%', height: 4, background: look.colors.accent, marginBottom: 10 } }), _jsx("div", { style: { fontFamily: stack(look.display), fontWeight: look.weights.display, fontSize: 'clamp(18px, 2.4vw, 30px)', lineHeight: look.leading.display, letterSpacing: `${look.tracking.display}em` }, children: s.title })] })), _jsxs(XStack, { position: "absolute", t: 8, l: 8, r: 8, justify: "space-between", items: "center", children: [_jsx(XStack, { width: 26, height: 26, rounded: 99, bg: "rgba(0,0,0,0.55)", items: "center", justify: "center", children: _jsx(Icon, { size: 13 }) }), _jsx(XStack, { px: "$2", height: 22, rounded: 99, bg: "rgba(0,0,0,0.55)", items: "center", children: _jsx(SizableText, { size: "$1", color: "#fff", children: RUNTIME[s.kind] }) })] })] }), _jsx(SizableText, { size: "$2", fontWeight: "600", numberOfLines: 1, children: s.title }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, mt: -4, children: s.subtitle })] }));
|
|
34
|
+
}
|
|
35
|
+
const STATE = { making: 'Making', done: 'Done', failed: 'Failed' };
|
|
36
|
+
/** The last eight conversations, each with what it is doing now. */
|
|
37
|
+
function Recent() {
|
|
38
|
+
const host = useHost();
|
|
39
|
+
const wire = useWire(host);
|
|
40
|
+
const { rows } = useChats(wire);
|
|
41
|
+
if (!rows.length)
|
|
42
|
+
return null;
|
|
43
|
+
return (_jsxs(YStack, { gap: "$2", pt: "$2", children: [_jsxs(XStack, { items: "center", justify: "space-between", children: [_jsx(SizableText, { size: "$3", fontWeight: "600", children: "Recent" }), _jsxs(XStack, { render: "button", "aria-label": "Open the library", onPress: () => host.go(path({ kind: 'library' })), items: "center", gap: "$1", cursor: "pointer", px: "$2", height: 28, rounded: "$3", hoverStyle: { bg: '$hover' }, children: [_jsx(SizableText, { size: "$2", color: "$soft", children: "Library" }), _jsx(ArrowRight, { size: 13 })] })] }), _jsx(XStack, { role: "list", "aria-label": "Recent conversations", gap: "$2", overflowX: "auto", pb: "$1", children: rows.slice(0, 8).map((r) => (_jsxs(YStack, { role: "listitem", render: "button", "aria-label": `${r.title}, ${STATE[r.state]}`, onPress: () => host.go(path({ kind: 'chat', id: r.id })), width: 148, shrink: 0, gap: "$1", cursor: "pointer", children: [_jsx(Cover, { wire: wire, cover: r.cover }), _jsx(SizableText, { size: "$2", numberOfLines: 1, children: r.title }), _jsxs(XStack, { items: "center", gap: "$1.5", children: [_jsx(XStack, { width: 6, height: 6, rounded: 6, bg: r.state === 'making' ? '$blue10' : r.state === 'failed' ? '$red10' : '$green10' }), _jsx(SizableText, { size: "$1", color: "$soft", children: `${STATE[r.state]} · ${r.count} made` })] })] }, r.id))) })] }));
|
|
44
|
+
}
|
|
45
|
+
function Cover({ wire, cover }) {
|
|
46
|
+
const { src } = useUrl(wire, cover);
|
|
47
|
+
return src ? (_jsx("img", { src: src, alt: "", width: 148, height: 110, style: { borderRadius: 12, objectFit: 'cover', width: 148, height: 110 } })) : (_jsx(YStack, { width: 148, height: 110, rounded: 12, bg: "$hover" }));
|
|
48
|
+
}
|
package/lib/host.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host Studio is mounted under, for every pane: @hanzo/build's `Host`, the
|
|
3
|
+
* same value Dev takes, so hanzo.ai mounts both one way. It is also handed to
|
|
4
|
+
* @hanzo/build's own provider, which its side panel reads.
|
|
5
|
+
*/
|
|
6
|
+
import { type Host } from '@hanzo/build';
|
|
7
|
+
import { type ReactNode } from 'react';
|
|
8
|
+
export declare function StudioHost({ host, children }: {
|
|
9
|
+
host: Host;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
export declare function useHost(): Host;
|
package/lib/host.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The host Studio is mounted under, for every pane: @hanzo/build's `Host`, the
|
|
4
|
+
* same value Dev takes, so hanzo.ai mounts both one way. It is also handed to
|
|
5
|
+
* @hanzo/build's own provider, which its side panel reads.
|
|
6
|
+
*/
|
|
7
|
+
import { HostProvider } from '@hanzo/build';
|
|
8
|
+
import { createContext, useContext } from 'react';
|
|
9
|
+
const Ctx = createContext(null);
|
|
10
|
+
export function StudioHost({ host, children }) {
|
|
11
|
+
return (_jsx(HostProvider, { host: host, children: _jsx(Ctx.Provider, { value: host, children: children }) }));
|
|
12
|
+
}
|
|
13
|
+
export function useHost() {
|
|
14
|
+
const h = useContext(Ctx);
|
|
15
|
+
if (!h)
|
|
16
|
+
throw new Error('Studio was drawn without a host');
|
|
17
|
+
return h;
|
|
18
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hanzo/studio: Studio as a component.
|
|
3
|
+
*
|
|
4
|
+
* `Studio({host, rail})` under a gui root in a box with a height; `nav(host,
|
|
5
|
+
* go)` for a host that draws Studio's places in a rail of its own (the Hanzo
|
|
6
|
+
* app at hanzo.ai/studio). `host` is @hanzo/build's `Host`, the value Dev
|
|
7
|
+
* takes, and `host.path` is Studio's address under its mount (`route`).
|
|
8
|
+
*/
|
|
9
|
+
export { Studio } from './studio.tsx';
|
|
10
|
+
export { nav, NEW, type Group } from './nav.tsx';
|
|
11
|
+
export { path, route, type Route } from './route.ts';
|
|
12
|
+
export type { Host } from '@hanzo/build';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hanzo/studio: Studio as a component.
|
|
3
|
+
*
|
|
4
|
+
* `Studio({host, rail})` under a gui root in a box with a height; `nav(host,
|
|
5
|
+
* go)` for a host that draws Studio's places in a rail of its own (the Hanzo
|
|
6
|
+
* app at hanzo.ai/studio). `host` is @hanzo/build's `Host`, the value Dev
|
|
7
|
+
* takes, and `host.path` is Studio's address under its mount (`route`).
|
|
8
|
+
*/
|
|
9
|
+
export { Studio } from './studio.js';
|
|
10
|
+
export { nav, NEW } from './nav.js';
|
|
11
|
+
export { path, route } from './route.js';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type Kind } from './kind.ts';
|
|
2
|
+
export declare const UNITS: readonly [{
|
|
3
|
+
readonly id: 'feed';
|
|
4
|
+
readonly label: 'Feed 1:1';
|
|
5
|
+
readonly width: 1080;
|
|
6
|
+
readonly height: 1080;
|
|
7
|
+
readonly set: 'social';
|
|
8
|
+
}, {
|
|
9
|
+
readonly id: 'portrait';
|
|
10
|
+
readonly label: 'Feed 4:5';
|
|
11
|
+
readonly width: 1080;
|
|
12
|
+
readonly height: 1350;
|
|
13
|
+
readonly set: 'social';
|
|
14
|
+
}, {
|
|
15
|
+
readonly id: 'story';
|
|
16
|
+
readonly label: 'Story 9:16';
|
|
17
|
+
readonly width: 1080;
|
|
18
|
+
readonly height: 1920;
|
|
19
|
+
readonly set: 'social';
|
|
20
|
+
}, {
|
|
21
|
+
readonly id: 'link';
|
|
22
|
+
readonly label: 'Link 1.91:1';
|
|
23
|
+
readonly width: 1200;
|
|
24
|
+
readonly height: 628;
|
|
25
|
+
readonly set: 'social';
|
|
26
|
+
}, {
|
|
27
|
+
readonly id: 'rectangle';
|
|
28
|
+
readonly label: '300 × 250';
|
|
29
|
+
readonly width: 300;
|
|
30
|
+
readonly height: 250;
|
|
31
|
+
readonly set: 'banner';
|
|
32
|
+
}, {
|
|
33
|
+
readonly id: 'leaderboard';
|
|
34
|
+
readonly label: '728 × 90';
|
|
35
|
+
readonly width: 728;
|
|
36
|
+
readonly height: 90;
|
|
37
|
+
readonly set: 'banner';
|
|
38
|
+
}, {
|
|
39
|
+
readonly id: 'skyscraper';
|
|
40
|
+
readonly label: '160 × 600';
|
|
41
|
+
readonly width: 160;
|
|
42
|
+
readonly height: 600;
|
|
43
|
+
readonly set: 'banner';
|
|
44
|
+
}, {
|
|
45
|
+
readonly id: 'mobile';
|
|
46
|
+
readonly label: '320 × 50';
|
|
47
|
+
readonly width: 320;
|
|
48
|
+
readonly height: 50;
|
|
49
|
+
readonly set: 'banner';
|
|
50
|
+
}];
|
|
51
|
+
export declare const ad: Kind;
|
package/lib/kinds/ad.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Ads: one message at every size it runs at. The social set (1:1, 4:5, 9:16,
|
|
4
|
+
* 1.91:1) and the display banners (300x250, 728x90, 160x600, 320x50), each
|
|
5
|
+
* laid out for its shape by the poster composer, in the brand, from one
|
|
6
|
+
* picture and one set of words. A version keeps one PNG per size; the set
|
|
7
|
+
* downloads as a ZIP.
|
|
8
|
+
*/
|
|
9
|
+
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
10
|
+
import { Megaphone } from '@hanzogui/lucide-icons-2';
|
|
11
|
+
import { current, filename } from '../made.js';
|
|
12
|
+
import { pixels } from '../raster.js';
|
|
13
|
+
import { useUrl } from '../use.js';
|
|
14
|
+
import { read } from '../wire.js';
|
|
15
|
+
import { zip } from '../zip.js';
|
|
16
|
+
import { picture } from './image.js';
|
|
17
|
+
import { num, str } from './kind.js';
|
|
18
|
+
import { svg } from './poster/index.js';
|
|
19
|
+
import { PRESETS, settle } from './type/system.js';
|
|
20
|
+
export const UNITS = [
|
|
21
|
+
{ id: 'feed', label: 'Feed 1:1', width: 1080, height: 1080, set: 'social' },
|
|
22
|
+
{ id: 'portrait', label: 'Feed 4:5', width: 1080, height: 1350, set: 'social' },
|
|
23
|
+
{ id: 'story', label: 'Story 9:16', width: 1080, height: 1920, set: 'social' },
|
|
24
|
+
{ id: 'link', label: 'Link 1.91:1', width: 1200, height: 628, set: 'social' },
|
|
25
|
+
{ id: 'rectangle', label: '300 × 250', width: 300, height: 250, set: 'banner' },
|
|
26
|
+
{ id: 'leaderboard', label: '728 × 90', width: 728, height: 90, set: 'banner' },
|
|
27
|
+
{ id: 'skyscraper', label: '160 × 600', width: 160, height: 600, set: 'banner' },
|
|
28
|
+
{ id: 'mobile', label: '320 × 50', width: 320, height: 50, set: 'banner' },
|
|
29
|
+
];
|
|
30
|
+
const spec = (v) => ({
|
|
31
|
+
headline: str(v.headline, 'Untitled'),
|
|
32
|
+
subhead: str(v.subhead),
|
|
33
|
+
cta: str(v.cta, 'Learn more'),
|
|
34
|
+
picture: str(v.picture),
|
|
35
|
+
prompt: str(v.prompt),
|
|
36
|
+
sets: Array.isArray(v.sets) && v.sets.length ? v.sets.filter((s) => s === 'social' || s === 'banner') : ['social', 'banner'],
|
|
37
|
+
system: settle((v.system ?? {}), PRESETS[0]),
|
|
38
|
+
});
|
|
39
|
+
/** Every unit of the set, drawn and kept. */
|
|
40
|
+
async function draw(w, s) {
|
|
41
|
+
const files = [];
|
|
42
|
+
for (const u of UNITS.filter((x) => s.sets.includes(x.set))) {
|
|
43
|
+
w.doing(`Laying out ${u.label}`);
|
|
44
|
+
// Small units carry the headline alone: a subhead at 50px tall is noise.
|
|
45
|
+
const small = u.width * u.height < 200_000;
|
|
46
|
+
const text = await svg(w.wire, {
|
|
47
|
+
format: 'square',
|
|
48
|
+
layout: u.width / u.height > 1.5 ? 'split' : 'hero',
|
|
49
|
+
headline: s.headline,
|
|
50
|
+
subhead: small ? '' : s.subhead,
|
|
51
|
+
details: '',
|
|
52
|
+
cta: s.cta,
|
|
53
|
+
picture: s.picture,
|
|
54
|
+
prompt: s.prompt,
|
|
55
|
+
system: s.system,
|
|
56
|
+
size: { width: u.width, height: u.height },
|
|
57
|
+
});
|
|
58
|
+
files.push(await w.keep(`${u.id}-${u.width}x${u.height}.png`, await pixels(text, u.width, u.height), { width: u.width, height: u.height }));
|
|
59
|
+
}
|
|
60
|
+
return files;
|
|
61
|
+
}
|
|
62
|
+
export const ad = {
|
|
63
|
+
id: 'ad',
|
|
64
|
+
label: 'Ads',
|
|
65
|
+
blurb: 'One ad at every size: the social set and the display banners.',
|
|
66
|
+
icon: Megaphone,
|
|
67
|
+
tool: {
|
|
68
|
+
name: 'make_ad',
|
|
69
|
+
description: 'Make an ad set: one picture and one message laid out at every size it runs at (feed, portrait, story, link, and the 300x250, 728x90, 160x600 and 320x50 banners).',
|
|
70
|
+
parameters: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: {
|
|
73
|
+
title: { type: 'string', description: 'A short name for the tab.' },
|
|
74
|
+
headline: { type: 'string', description: 'Four to eight words.' },
|
|
75
|
+
subhead: { type: 'string', description: 'One supporting line.' },
|
|
76
|
+
cta: { type: 'string', description: 'One to three words: Shop now, Learn more, Book a table.' },
|
|
77
|
+
image_prompt: { type: 'string', description: 'The picture, with no words in it.' },
|
|
78
|
+
image_tab: { type: 'integer', description: 'A tab whose picture to use instead.' },
|
|
79
|
+
sets: { type: 'array', items: { type: 'string', enum: ['social', 'banner'] }, description: 'Both unless asked.' },
|
|
80
|
+
},
|
|
81
|
+
required: ['title', 'headline'],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
needs: () => null,
|
|
85
|
+
make: async (w, args) => {
|
|
86
|
+
const s = spec({ ...args, prompt: str(args.image_prompt), system: w.brand ?? PRESETS[0] });
|
|
87
|
+
let why = '';
|
|
88
|
+
const tab = num(args.image_tab, 0) ? w.find(num(args.image_tab, 0)) : null;
|
|
89
|
+
const f = tab ? current(tab).files.find((x) => x.mime.startsWith('image/')) : undefined;
|
|
90
|
+
if (f)
|
|
91
|
+
s.picture = f.key;
|
|
92
|
+
else if (s.prompt) {
|
|
93
|
+
try {
|
|
94
|
+
s.picture = (await picture(w, { prompt: s.prompt, aspect: '4:5', model: '' })).files[0]?.key ?? '';
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
why = e instanceof Error ? e.message : String(e);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const files = await draw(w, s);
|
|
101
|
+
return { title: str(args.title, s.headline), draft: { spec: s, files, note: why ? `Set in type alone: ${why}` : s.headline, by: 'Studio layout' } };
|
|
102
|
+
},
|
|
103
|
+
revise: async (w, made, change) => {
|
|
104
|
+
const s = spec({ ...current(made).spec, ...(change.patch ?? {}), system: w.brand ?? current(made).spec.system });
|
|
105
|
+
if (change.instruction)
|
|
106
|
+
s.headline = change.instruction.length < 60 ? change.instruction : s.headline;
|
|
107
|
+
return { spec: s, files: await draw(w, s), note: change.instruction ?? 'Edited', by: 'Studio layout' };
|
|
108
|
+
},
|
|
109
|
+
View: Set,
|
|
110
|
+
exports: [
|
|
111
|
+
{
|
|
112
|
+
label: 'All sizes (ZIP)',
|
|
113
|
+
run: async (w, m, v) => ({ name: filename(m.title, 'zip'), blob: await zip(await Promise.all(v.files.map(async (f) => ({ name: f.name, blob: await read(w, f.key) })))) }),
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
function Set({ version, wire, made }) {
|
|
118
|
+
return (_jsx(YStack, { flex: 1, minH: 0, overflow: "scroll", p: "$3", children: _jsx(XStack, { flexWrap: "wrap", gap: "$3", items: "flex-start", children: version.files.map((f) => (_jsx(Unit, { wire: wire, file: f, alt: `${made.title}, ${f.name}` }, f.key))) }) }));
|
|
119
|
+
}
|
|
120
|
+
function Unit({ wire, file, alt }) {
|
|
121
|
+
const { src } = useUrl(wire, file.key);
|
|
122
|
+
const scale = Math.min(1, 260 / (file.width ?? 260), 320 / (file.height ?? 320));
|
|
123
|
+
return (_jsxs(YStack, { gap: "$1", children: [src ? _jsx("img", { src: src, alt: alt, width: Math.round((file.width ?? 260) * scale), height: Math.round((file.height ?? 260) * scale), style: { borderRadius: 6, background: 'var(--hover)' } }) : null, _jsx(SizableText, { size: "$1", color: "$soft", children: file.name.replace(/\.png$/, '') })] }));
|
|
124
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Kind } from './kind.ts';
|
|
2
|
+
import { type TypeSystem } from './type/system.ts';
|
|
3
|
+
/** The brand as the engine's theme. */
|
|
4
|
+
export declare function theme(t: TypeSystem | null): Record<string, string>;
|
|
5
|
+
export declare const document_: Kind;
|
|
6
|
+
export declare const slides: Kind;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Documents and slides, written by the chat and drawn by the engine's
|
|
4
|
+
* renderers (PDF, Word, PowerPoint): one kind for prose (`doc`) and one for
|
|
5
|
+
* decks (`deck`), made the same way.
|
|
6
|
+
*
|
|
7
|
+
* 1. The writer answers the document as the engine's own IR, against the
|
|
8
|
+
* grammar the engine publishes (GET /v1/documents/schema), with picture
|
|
9
|
+
* blocks that say what to draw or which tab to take.
|
|
10
|
+
* 2. Each picture is drawn (the image lane) or taken from its tab and kept;
|
|
11
|
+
* the IR holds the stored key.
|
|
12
|
+
* 3. At render each key's picture goes inside the IR as a data: URL, the
|
|
13
|
+
* brand becomes the IR's `theme`, and the engine draws the files, which are
|
|
14
|
+
* kept here: a version's files never depend on the engine keeping them.
|
|
15
|
+
*/
|
|
16
|
+
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
17
|
+
import { FileText, Presentation } from '@hanzogui/lucide-icons-2';
|
|
18
|
+
import { useEffect, useState } from 'react';
|
|
19
|
+
import { current, filename } from '../made.js';
|
|
20
|
+
import { Act } from '../ui.js';
|
|
21
|
+
import { shrink } from '../raster.js';
|
|
22
|
+
import { documents, read, structured } from '../wire.js';
|
|
23
|
+
import { picture } from './image.js';
|
|
24
|
+
import { num, str } from './kind.js';
|
|
25
|
+
import { PRESETS } from './type/system.js';
|
|
26
|
+
/** The brand as the engine's theme. */
|
|
27
|
+
export function theme(t) {
|
|
28
|
+
const s = t ?? PRESETS[0];
|
|
29
|
+
return { ink: s.colors.ink, paper: s.colors.paper, accent: s.colors.accent, muted: s.colors.muted, display_font: s.display, text_font: s.text };
|
|
30
|
+
}
|
|
31
|
+
const BLOCK = {
|
|
32
|
+
type: 'object',
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
required: ['type', 'text', 'level', 'items', 'headers', 'rows', 'prompt', 'tab', 'caption'],
|
|
35
|
+
properties: {
|
|
36
|
+
type: { type: 'string', enum: ['title', 'h', 'p', 'ul', 'table', 'kv', 'hr', 'image'] },
|
|
37
|
+
text: { type: 'string' },
|
|
38
|
+
level: { type: 'integer' },
|
|
39
|
+
items: { type: 'array', items: { type: 'string' } },
|
|
40
|
+
headers: { type: 'array', items: { type: 'string' } },
|
|
41
|
+
rows: { type: 'array', items: { type: 'array', items: { type: 'string' } } },
|
|
42
|
+
prompt: { type: 'string', description: 'image: what to draw, with no words in it' },
|
|
43
|
+
tab: { type: 'integer', description: 'image: a tab whose picture to use, 0 for none' },
|
|
44
|
+
caption: { type: 'string' },
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
const SLIDE = {
|
|
48
|
+
type: 'object',
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
required: ['layout', 'title', 'subtitle', 'bullets', 'notes', 'prompt', 'tab', 'quote', 'labels', 'values'],
|
|
51
|
+
properties: {
|
|
52
|
+
layout: { type: 'string', enum: ['title', 'section', 'bullets', 'image', 'split', 'quote', 'chart', 'closing'] },
|
|
53
|
+
title: { type: 'string' },
|
|
54
|
+
subtitle: { type: 'string' },
|
|
55
|
+
bullets: { type: 'array', items: { type: 'string' } },
|
|
56
|
+
notes: { type: 'string' },
|
|
57
|
+
prompt: { type: 'string', description: 'image and split: what to draw, with no words in it' },
|
|
58
|
+
tab: { type: 'integer', description: 'image and split: a tab whose picture to use, 0 for none' },
|
|
59
|
+
quote: { type: 'string' },
|
|
60
|
+
labels: { type: 'array', items: { type: 'string' }, description: 'chart: the categories' },
|
|
61
|
+
values: { type: 'array', items: { type: 'number' }, description: 'chart: one value per label' },
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const schema = (a) => ({
|
|
65
|
+
type: 'object',
|
|
66
|
+
additionalProperties: false,
|
|
67
|
+
required: ['title', a === 'doc' ? 'blocks' : 'slides'],
|
|
68
|
+
properties: { title: { type: 'string' }, [a === 'doc' ? 'blocks' : 'slides']: { type: 'array', items: a === 'doc' ? BLOCK : SLIDE } },
|
|
69
|
+
});
|
|
70
|
+
const BRIEF = {
|
|
71
|
+
doc: `You write documents as JSON blocks: title {text, caption as the subtitle}, h {text, level 1-3}, p {text}, ul {items}, table {headers, rows}, kv {rows as [key, value] pairs}, hr, image {prompt or tab, caption}. Fill every field of every block; use "" , 0 and [] for fields a block does not use. Write the real content, complete and specific, in the person's language. Use an image block only where a picture helps (a cover, a product, a place), at most three.`,
|
|
72
|
+
deck: `You write slide decks as JSON slides. Layouts: title (title, subtitle), section (title), bullets (title, 3 to 5 bullets), image (title, prompt or tab), split (title, bullets, prompt or tab), quote (quote, subtitle as the attribution), chart (title, labels, values), closing (title, subtitle). Fill every field of every slide; use "", 0 and [] for fields a layout does not use. Speaker notes in notes. Ten slides or fewer unless asked. Pictures with no words in them.`,
|
|
73
|
+
};
|
|
74
|
+
/** Draw or take each picture a written IR asks for, and keep it: the IR then names stored keys. */
|
|
75
|
+
async function pictures(w, ir, arch) {
|
|
76
|
+
const list = (arch === 'doc' ? ir.blocks : ir.slides) ?? [];
|
|
77
|
+
let n = 0;
|
|
78
|
+
const out = [];
|
|
79
|
+
for (const b of list) {
|
|
80
|
+
const wants = arch === 'doc' ? b.type === 'image' : b.layout === 'image' || b.layout === 'split';
|
|
81
|
+
if (!wants || str(b.src)) {
|
|
82
|
+
out.push(b);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
n++;
|
|
86
|
+
const tab = num(b.tab, 0) ? w.find(num(b.tab, 0)) : null;
|
|
87
|
+
const f = tab ? current(tab).files.find((x) => x.mime.startsWith('image/')) : undefined;
|
|
88
|
+
if (f) {
|
|
89
|
+
out.push({ ...b, src: f.key });
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!str(b.prompt)) {
|
|
93
|
+
out.push({ ...b, src: '' });
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
w.doing(`Drawing picture ${n}`);
|
|
98
|
+
const got = await picture(w, { prompt: str(b.prompt), aspect: arch === 'deck' ? (b.layout === 'split' ? '4:5' : '16:9') : '3:2', model: '' });
|
|
99
|
+
out.push({ ...b, src: got.files[0]?.key ?? '' });
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
// A picture the lane cannot draw is left out, and said: the words still ship.
|
|
103
|
+
out.push({ ...b, src: '', missing: e instanceof Error ? e.message : String(e) });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return arch === 'doc' ? { ...ir, blocks: out } : { ...ir, slides: out };
|
|
107
|
+
}
|
|
108
|
+
const texts = (v) => (Array.isArray(v) ? v.map((x) => String(x ?? '')).filter((x) => x.trim()) : []);
|
|
109
|
+
/** A written block in the engine's own words (GET /v1/documents/schema): the block's tag is `t`. */
|
|
110
|
+
function block(b, src) {
|
|
111
|
+
switch (b.type) {
|
|
112
|
+
case 'title':
|
|
113
|
+
return { t: 'title', text: str(b.text), sub: str(b.caption) };
|
|
114
|
+
case 'h':
|
|
115
|
+
return { t: 'h', text: str(b.text), level: num(b.level, 2, 1, 3) };
|
|
116
|
+
case 'p':
|
|
117
|
+
return { t: 'p', text: str(b.text) };
|
|
118
|
+
case 'ul':
|
|
119
|
+
return { t: 'ul', items: texts(b.items) };
|
|
120
|
+
case 'table':
|
|
121
|
+
return { t: 'table', headers: texts(b.headers), rows: Array.isArray(b.rows) ? b.rows.map(texts) : [], align: [], foot: [] };
|
|
122
|
+
case 'kv':
|
|
123
|
+
return { t: 'kv', pairs: Array.isArray(b.rows) ? b.rows.map(texts).filter((r) => r.length >= 2).map((r) => [r[0], r.slice(1).join(' ')]) : [], cols: 1 };
|
|
124
|
+
case 'hr':
|
|
125
|
+
return { t: 'hr' };
|
|
126
|
+
case 'image':
|
|
127
|
+
return src ? { t: 'image', src, caption: str(b.caption) } : null;
|
|
128
|
+
default:
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** A written slide in the engine's own words. A picture slide with no picture falls back to words. */
|
|
133
|
+
function slide(b, src) {
|
|
134
|
+
const layout = str(b.layout, 'bullets');
|
|
135
|
+
const words = { title: str(b.title), subtitle: str(b.subtitle), bullets: texts(b.bullets), notes: str(b.notes) };
|
|
136
|
+
if ((layout === 'image' || layout === 'split') && !src)
|
|
137
|
+
return { layout: layout === 'split' ? 'bullets' : 'section', ...words };
|
|
138
|
+
if (layout === 'chart') {
|
|
139
|
+
const labels = texts(b.labels);
|
|
140
|
+
const values = Array.isArray(b.values) ? b.values.map((v) => num(v, 0)) : [];
|
|
141
|
+
return labels.length && labels.length === values.length ? { layout, ...words, chart: { labels, values } } : { layout: 'bullets', ...words };
|
|
142
|
+
}
|
|
143
|
+
return { layout, ...words, ...(src ? { image: src } : {}), ...(layout === 'quote' ? { quote: str(b.quote) } : {}) };
|
|
144
|
+
}
|
|
145
|
+
/** The IR the engine is handed: stored keys as read addresses, pictures that could not be had dropped, the brand as theme. */
|
|
146
|
+
async function wired(wire, ir, arch, brand) {
|
|
147
|
+
const list = (arch === 'doc' ? ir.blocks : ir.slides) ?? [];
|
|
148
|
+
const out = [];
|
|
149
|
+
for (const b of list) {
|
|
150
|
+
const key = str(b.src);
|
|
151
|
+
// The picture travels inside the IR: what is kept is this person's alone, and no address of it is handed out.
|
|
152
|
+
const src = key ? await shrink(await read(wire, key)).catch(() => '') : '';
|
|
153
|
+
const next = arch === 'doc' ? block(b, src) : slide(b, src);
|
|
154
|
+
if (next)
|
|
155
|
+
out.push(next);
|
|
156
|
+
}
|
|
157
|
+
return { ...(arch === 'doc' ? { blocks: out } : { slides: out }), title: ir.title, theme: theme(brand) };
|
|
158
|
+
}
|
|
159
|
+
/** Render on the engine and keep the files. */
|
|
160
|
+
async function render(w, ir, arch, brand) {
|
|
161
|
+
w.doing(arch === 'doc' ? 'Setting the document' : 'Building the slides');
|
|
162
|
+
const doc = await documents.create(w.wire, { kind: arch, ir: await wired(w.wire, ir, arch, brand), title: ir.title });
|
|
163
|
+
const formats = arch === 'doc' ? ['pdf', 'docx'] : ['pdf', 'pptx'];
|
|
164
|
+
const files = [];
|
|
165
|
+
for (const f of formats) {
|
|
166
|
+
w.doing(`Writing the ${f.toUpperCase()}`);
|
|
167
|
+
const blob = await documents.file(w.wire, doc.id, f);
|
|
168
|
+
files.push(await w.keep(filename(ir.title, f), blob));
|
|
169
|
+
}
|
|
170
|
+
return { id: doc.id, files };
|
|
171
|
+
}
|
|
172
|
+
function kind(arch) {
|
|
173
|
+
const id = arch === 'doc' ? 'document' : 'slides';
|
|
174
|
+
return {
|
|
175
|
+
id,
|
|
176
|
+
label: arch === 'doc' ? 'Document' : 'Slides',
|
|
177
|
+
blurb: arch === 'doc' ? 'Reports, proposals, letters, one-pagers, as PDF and Word.' : 'Decks with pictures and charts, as PowerPoint and PDF.',
|
|
178
|
+
icon: arch === 'doc' ? FileText : Presentation,
|
|
179
|
+
tool: {
|
|
180
|
+
name: arch === 'doc' ? 'make_document' : 'make_slides',
|
|
181
|
+
description: arch === 'doc'
|
|
182
|
+
? 'Write a document: a report, proposal, letter, memo, resume, invoice, one-pager, press release, contract. Rendered to PDF and Word in the brand.'
|
|
183
|
+
: 'Write a slide deck: a pitch, a business review, a project update, a talk, a lesson. Rendered to PowerPoint and PDF in the brand.',
|
|
184
|
+
parameters: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
properties: {
|
|
187
|
+
title: { type: 'string', description: 'The document\'s title.' },
|
|
188
|
+
brief: { type: 'string', description: 'Everything the person said it should contain, and who it is for.' },
|
|
189
|
+
},
|
|
190
|
+
required: ['title', 'brief'],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
needs: () => null,
|
|
194
|
+
make: async (w, args) => {
|
|
195
|
+
w.doing(arch === 'doc' ? 'Writing the document' : 'Writing the slides');
|
|
196
|
+
const brief = str(args.brief);
|
|
197
|
+
const written = await structured(w.wire, w.writer, BRIEF[arch], `Title: ${str(args.title)}\n${brief}`, schema(arch), w.signal);
|
|
198
|
+
const ir = await pictures(w, { ...written, title: str(written.title, str(args.title, 'Untitled')) }, arch);
|
|
199
|
+
const { id: engine, files } = await render(w, ir, arch, w.brand);
|
|
200
|
+
const missing = ((arch === 'doc' ? ir.blocks : ir.slides) ?? []).map((b) => str(b.missing)).filter(Boolean);
|
|
201
|
+
const note = missing.length ? `${brief.slice(0, 120)} (pictures left out: ${missing[0]})` : brief.slice(0, 160);
|
|
202
|
+
return { title: ir.title, draft: { spec: { ir, engine, brief }, files, note, by: w.writer } };
|
|
203
|
+
},
|
|
204
|
+
revise: async (w, made, change) => {
|
|
205
|
+
const now = current(made).spec;
|
|
206
|
+
let ir = change.patch?.ir ? change.patch.ir : now.ir;
|
|
207
|
+
if (change.instruction) {
|
|
208
|
+
w.doing('Revising');
|
|
209
|
+
const written = await structured(w.wire, w.writer, `${BRIEF[arch]}\nYou are revising: answer the whole document with the instruction applied, and keep everything it does not ask to change exactly as it is (keep each picture block's src).`, `Current: ${JSON.stringify(now.ir)}\nInstruction: ${change.instruction}`, schema(arch), w.signal);
|
|
210
|
+
ir = await pictures(w, written, arch);
|
|
211
|
+
}
|
|
212
|
+
const { id: engine, files } = await render(w, ir, arch, w.brand);
|
|
213
|
+
return { spec: { ir, engine, brief: now.brief }, files, note: change.instruction ?? 'Edited', by: change.instruction ? w.writer : 'edit' };
|
|
214
|
+
},
|
|
215
|
+
View: (p) => _jsx(Pages, { ...p, arch: arch }),
|
|
216
|
+
exports: (arch === 'doc' ? ['pdf', 'docx'] : ['pdf', 'pptx']).map((ext) => ({
|
|
217
|
+
label: ext === 'pdf' ? 'PDF' : ext === 'docx' ? 'Word (.docx)' : 'PowerPoint (.pptx)',
|
|
218
|
+
run: async (wire, m, v) => {
|
|
219
|
+
const f = v.files.find((x) => x.name.endsWith(`.${ext}`));
|
|
220
|
+
if (!f)
|
|
221
|
+
throw new Error(`This version has no ${ext.toUpperCase()}.`);
|
|
222
|
+
return { name: filename(m.title, ext), blob: await read(wire, f.key) };
|
|
223
|
+
},
|
|
224
|
+
})),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
export const document_ = kind('doc');
|
|
228
|
+
export const slides = kind('deck');
|
|
229
|
+
/** The PDF, in the browser's own viewer; the words beside it for an edit in place. */
|
|
230
|
+
function Pages({ made, version, wire, edit, busy, arch }) {
|
|
231
|
+
const pdf = version.files.find((f) => f.name.endsWith('.pdf'));
|
|
232
|
+
const [src, setSrc] = useState('');
|
|
233
|
+
const [error, setError] = useState('');
|
|
234
|
+
const [editing, setEditing] = useState(false);
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
if (!pdf)
|
|
237
|
+
return;
|
|
238
|
+
let live = true;
|
|
239
|
+
let made = '';
|
|
240
|
+
read(wire, pdf.key).then((b) => {
|
|
241
|
+
if (!live)
|
|
242
|
+
return;
|
|
243
|
+
made = URL.createObjectURL(new Blob([b], { type: 'application/pdf' }));
|
|
244
|
+
setSrc(made);
|
|
245
|
+
}, (e) => live && setError(e instanceof Error ? e.message : String(e)));
|
|
246
|
+
return () => {
|
|
247
|
+
live = false;
|
|
248
|
+
if (made)
|
|
249
|
+
URL.revokeObjectURL(made);
|
|
250
|
+
};
|
|
251
|
+
}, [wire, pdf?.key]);
|
|
252
|
+
const ir = version.spec.ir;
|
|
253
|
+
return (_jsxs(YStack, { flex: 1, minH: 0, children: [_jsxs(XStack, { gap: "$2", px: "$3", py: "$2", borderBottomWidth: 1, borderColor: "$borderColor", items: "center", children: [_jsx(SizableText, { size: "$1", color: "$soft", flex: 1, numberOfLines: 1, children: version.files.map((f) => f.name).join(' · ') }), ir ? (_jsx(Act, { label: editing ? 'Show the pages' : 'Edit the words', onPress: () => setEditing(!editing), on: editing, children: _jsx(SizableText, { size: "$2", children: editing ? 'Pages' : 'Edit words' }) })) : null] }), editing && ir ? (_jsx(Words, { ir: ir, arch: arch, busy: busy, onSave: (next) => edit({ ir: next }, 'Edited in place') })) : src ? (_jsx("iframe", { title: made.title, src: src, style: { flex: 1, width: '100%', border: 0, minHeight: 0 } })) : (_jsx(YStack, { flex: 1, items: "center", justify: "center", children: _jsx(SizableText, { color: "$soft", children: error || 'Opening…' }) }))] }));
|
|
254
|
+
}
|
|
255
|
+
/** Every line of words the IR carries, as fields. */
|
|
256
|
+
function Words({ ir, arch, busy, onSave }) {
|
|
257
|
+
const [draft, setDraft] = useState(ir);
|
|
258
|
+
const list = (arch === 'doc' ? draft.blocks : draft.slides) ?? [];
|
|
259
|
+
const put = (i, patch) => {
|
|
260
|
+
const next = list.map((b, j) => (j === i ? { ...b, ...patch } : b));
|
|
261
|
+
setDraft(arch === 'doc' ? { ...draft, blocks: next } : { ...draft, slides: next });
|
|
262
|
+
};
|
|
263
|
+
const box = { width: '100%', padding: 8, borderRadius: 8, border: '1px solid var(--borderColor)', background: 'transparent', color: 'inherit', font: 'inherit' };
|
|
264
|
+
return (_jsxs(YStack, { flex: 1, minH: 0, overflow: "scroll", p: "$3", gap: "$3", children: [_jsx("input", { "aria-label": "Title", value: draft.title, onChange: (e) => setDraft({ ...draft, title: e.currentTarget.value }), style: { ...box, fontWeight: 600 } }), list.map((b, i) => {
|
|
265
|
+
const fields = ['text', 'title', 'subtitle', 'quote', 'caption'].filter((k) => typeof b[k] === 'string' && b[k].length);
|
|
266
|
+
const lists = ['items', 'bullets'].filter((k) => Array.isArray(b[k]) && b[k].length);
|
|
267
|
+
if (!fields.length && !lists.length)
|
|
268
|
+
return null;
|
|
269
|
+
return (_jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: arch === 'doc' ? String(b.type) : `Slide ${i + 1} · ${String(b.layout)}` }), fields.map((k) => k === 'text' && b.type === 'p' ? (_jsx("textarea", { "aria-label": `${k} ${i + 1}`, rows: 4, value: b[k], onChange: (e) => put(i, { [k]: e.currentTarget.value }), style: box }, k)) : (_jsx("input", { "aria-label": `${k} ${i + 1}`, value: b[k], onChange: (e) => put(i, { [k]: e.currentTarget.value }), style: box }, k))), lists.map((k) => (_jsx("textarea", { "aria-label": `${k} ${i + 1}, one per line`, rows: Math.max(2, b[k].length), value: b[k].join('\n'), onChange: (e) => put(i, { [k]: e.currentTarget.value.split('\n') }), style: box }, k)))] }, i));
|
|
270
|
+
}), _jsx(XStack, { render: "button", "aria-label": "Save these words as a new version", disabled: busy, onPress: () => !busy && onSave(draft), height: 36, items: "center", justify: "center", rounded: "$3", bg: "$ink", cursor: "pointer", children: _jsx(SizableText, { size: "$2", color: "$background", children: busy ? 'Saving…' : 'Save version' }) })] }));
|
|
271
|
+
}
|