reifyui 0.3.0 → 0.4.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/README.md +59 -10
- package/dist/index.d.ts +93 -22
- package/dist/slides.cjs +737 -0
- package/dist/slides.cjs.map +1 -0
- package/dist/slides.d.ts +128 -0
- package/dist/slides.js +705 -0
- package/dist/slides.js.map +1 -0
- package/package.json +10 -3
- package/src/auth/AuthForm.jsx +187 -0
- package/src/auth/GoogleButton.jsx +80 -0
- package/src/auth/client.js +177 -0
- package/src/components/ChatMessages.jsx +194 -0
- package/src/components/CodeBlock.jsx +120 -0
- package/src/components/Composer.jsx +75 -0
- package/src/components/Dialog.jsx +312 -0
- package/src/components/TaskList.jsx +193 -0
- package/src/components/ToolSteps.jsx +84 -0
- package/src/components/icons.jsx +33 -0
- package/src/components/resizable.jsx +84 -0
- package/src/components/toolMeta.js +91 -0
- package/src/index.d.ts +234 -0
- package/src/index.js +35 -0
- package/src/sheet/SheetGrid.jsx +633 -0
- package/src/slides/Editor.jsx +246 -0
- package/src/slides/Presentation.jsx +79 -0
- package/src/slides/SlideView.jsx +97 -0
- package/src/slides/elements.jsx +178 -0
- package/src/slides/index.d.ts +128 -0
- package/src/slides/index.js +10 -0
- package/src/state/blocks.js +37 -0
- package/src/state/conversationStore.js +55 -0
- package/src/stream/responses.js +122 -0
- package/styles/slides.css +38 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// EditorCanvas — direct manipulation over the deck renderer: a real slides
|
|
2
|
+
// editor. One transparent interaction layer above the scaled SlideStage owns
|
|
3
|
+
// ALL pointer behavior (hit-test → select, click-drag moves immediately like
|
|
4
|
+
// Google Slides, corner handles resize, double-click edits text inline,
|
|
5
|
+
// Delete removes, arrows nudge). It never mutates the deck itself — every
|
|
6
|
+
// commit flows up as a typed patch (onPatchElement/onDeleteElement), so the
|
|
7
|
+
// host owns undo/autosave/collab broadcast. Peer decorations (selection
|
|
8
|
+
// outlines, live drag) render from the `peers` prop.
|
|
9
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
|
+
import { SlideStage } from './SlideView.jsx';
|
|
11
|
+
|
|
12
|
+
const STAGE_W = 1920;
|
|
13
|
+
const STAGE_H = 1080;
|
|
14
|
+
const MIN_SIZE = 24;
|
|
15
|
+
|
|
16
|
+
// Topmost element whose frame contains the stage-space point (z = list order).
|
|
17
|
+
// Rotation is ignored for hit-testing (rare, and the frame box stays close).
|
|
18
|
+
function hitTest(slide, x, y) {
|
|
19
|
+
const els = slide?.elements || [];
|
|
20
|
+
for (let i = els.length - 1; i >= 0; i--) {
|
|
21
|
+
const f = els[i].frame || {};
|
|
22
|
+
if (x >= (f.x || 0) && x <= (f.x || 0) + (f.w || 0)
|
|
23
|
+
&& y >= (f.y || 0) && y <= (f.y || 0) + (f.h || 0)) return els[i];
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const HANDLES = [
|
|
29
|
+
{ k: 'nw', cx: 0, cy: 0 }, { k: 'ne', cx: 1, cy: 0 },
|
|
30
|
+
{ k: 'sw', cx: 0, cy: 1 }, { k: 'se', cx: 1, cy: 1 },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function resizeFrame(f0, k, dx, dy) {
|
|
34
|
+
let { x, y, w, h } = f0;
|
|
35
|
+
if (k.includes('e')) w = Math.max(MIN_SIZE, f0.w + dx);
|
|
36
|
+
if (k.includes('s')) h = Math.max(MIN_SIZE, f0.h + dy);
|
|
37
|
+
if (k.includes('w')) { const nw = Math.max(MIN_SIZE, f0.w - dx); x = f0.x + (f0.w - nw); w = nw; }
|
|
38
|
+
if (k.includes('n')) { const nh = Math.max(MIN_SIZE, f0.h - dy); y = f0.y + (f0.h - nh); h = nh; }
|
|
39
|
+
return { ...f0, x: Math.round(x), y: Math.round(y), w: Math.round(w), h: Math.round(h) };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function textOf(el) {
|
|
43
|
+
return (el.content?.runs || []).map((r) => r.text ?? '').join('\n');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function EditorCanvas({
|
|
47
|
+
slide, theme, resolveSrc,
|
|
48
|
+
selectedId, onSelect,
|
|
49
|
+
onPatchElement, // (elementId, patch, {transient}) => void
|
|
50
|
+
onDeleteElement, // (elementId) => void
|
|
51
|
+
onDragState, // (elementId|null, frame|null) live broadcast hook
|
|
52
|
+
peers = [], // [{id,name,color,sel:{slideId,elId},drag:{elId,frame}}]
|
|
53
|
+
readOnly = false,
|
|
54
|
+
}) {
|
|
55
|
+
const boxRef = useRef(null);
|
|
56
|
+
const [scale, setScale] = useState(1);
|
|
57
|
+
const [box, setBox] = useState({ left: 0, top: 0 });
|
|
58
|
+
const gestureRef = useRef(null); // {mode:'move'|'resize', handle, el, f0, sx, sy, moved}
|
|
59
|
+
const [liveFrame, setLiveFrame] = useState(null); // frame during an active gesture
|
|
60
|
+
const [editing, setEditing] = useState(null); // {elId, value}
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const el = boxRef.current;
|
|
64
|
+
if (!el) return undefined;
|
|
65
|
+
const fit = () => {
|
|
66
|
+
const r = el.getBoundingClientRect();
|
|
67
|
+
if (r.width && r.height) {
|
|
68
|
+
const s = Math.min(r.width / STAGE_W, r.height / STAGE_H);
|
|
69
|
+
setScale(s);
|
|
70
|
+
setBox({ left: (r.width - STAGE_W * s) / 2, top: (r.height - STAGE_H * s) / 2 });
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
fit();
|
|
74
|
+
const ro = new ResizeObserver(fit);
|
|
75
|
+
ro.observe(el);
|
|
76
|
+
return () => ro.disconnect();
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
79
|
+
const toStage = useCallback((e) => {
|
|
80
|
+
const r = boxRef.current.getBoundingClientRect();
|
|
81
|
+
return { x: (e.clientX - r.left - box.left) / scale, y: (e.clientY - r.top - box.top) / scale };
|
|
82
|
+
}, [scale, box]);
|
|
83
|
+
|
|
84
|
+
const selected = (slide?.elements || []).find((el) => el.id === selectedId) || null;
|
|
85
|
+
|
|
86
|
+
function beginGesture(mode, el, e, handle) {
|
|
87
|
+
if (readOnly) return;
|
|
88
|
+
const p = toStage(e);
|
|
89
|
+
gestureRef.current = { mode, handle, el, f0: { ...el.frame }, sx: p.x, sy: p.y, moved: false };
|
|
90
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function onLayerPointerDown(e) {
|
|
94
|
+
if (editing) return; // let the textarea own the pointer
|
|
95
|
+
const p = toStage(e);
|
|
96
|
+
const hit = hitTest(slide, p.x, p.y);
|
|
97
|
+
onSelect?.(hit ? hit.id : null);
|
|
98
|
+
if (hit) beginGesture('move', hit, e);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function onPointerMove(e) {
|
|
102
|
+
const g = gestureRef.current;
|
|
103
|
+
if (!g) return;
|
|
104
|
+
const p = toStage(e);
|
|
105
|
+
const dx = Math.round(p.x - g.sx);
|
|
106
|
+
const dy = Math.round(p.y - g.sy);
|
|
107
|
+
if (!g.moved && Math.abs(dx) < 3 && Math.abs(dy) < 3) return; // click, not drag
|
|
108
|
+
g.moved = true;
|
|
109
|
+
const f = g.mode === 'move'
|
|
110
|
+
? { ...g.f0,
|
|
111
|
+
x: Math.max(-g.f0.w + 40, Math.min(STAGE_W - 40, g.f0.x + dx)),
|
|
112
|
+
y: Math.max(-g.f0.h + 40, Math.min(STAGE_H - 40, g.f0.y + dy)) }
|
|
113
|
+
: resizeFrame(g.f0, g.handle, dx, dy);
|
|
114
|
+
setLiveFrame(f);
|
|
115
|
+
onDragState?.(g.el.id, f);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function onPointerUp() {
|
|
119
|
+
const g = gestureRef.current;
|
|
120
|
+
gestureRef.current = null;
|
|
121
|
+
onDragState?.(null, null);
|
|
122
|
+
if (g && g.moved && liveFrame) onPatchElement?.(g.el.id, { frame: liveFrame });
|
|
123
|
+
setLiveFrame(null);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function onDoubleClick(e) {
|
|
127
|
+
if (readOnly) return;
|
|
128
|
+
const p = toStage(e);
|
|
129
|
+
const hit = hitTest(slide, p.x, p.y);
|
|
130
|
+
if (hit && hit.type === 'text') {
|
|
131
|
+
onSelect?.(hit.id);
|
|
132
|
+
setEditing({ elId: hit.id, value: textOf(hit) });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Delete + nudge on the selected element (never while typing in the editor
|
|
137
|
+
// overlay — it stops propagation itself).
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (readOnly) return undefined;
|
|
140
|
+
const onKey = (e) => {
|
|
141
|
+
const t = e.target;
|
|
142
|
+
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return;
|
|
143
|
+
if (!selected) return;
|
|
144
|
+
if (e.key === 'Backspace' || e.key === 'Delete') { e.preventDefault(); onDeleteElement?.(selected.id); }
|
|
145
|
+
else if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(e.key)) {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
const step = e.shiftKey ? 24 : 4;
|
|
148
|
+
const f = { ...selected.frame };
|
|
149
|
+
if (e.key === 'ArrowLeft') f.x -= step;
|
|
150
|
+
if (e.key === 'ArrowRight') f.x += step;
|
|
151
|
+
if (e.key === 'ArrowUp') f.y -= step;
|
|
152
|
+
if (e.key === 'ArrowDown') f.y += step;
|
|
153
|
+
onPatchElement?.(selected.id, { frame: f });
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
window.addEventListener('keydown', onKey);
|
|
157
|
+
return () => window.removeEventListener('keydown', onKey);
|
|
158
|
+
}, [selected, readOnly, onPatchElement, onDeleteElement]);
|
|
159
|
+
|
|
160
|
+
function commitText() {
|
|
161
|
+
if (!editing) return;
|
|
162
|
+
const el = (slide?.elements || []).find((x) => x.id === editing.elId);
|
|
163
|
+
if (el && editing.value !== textOf(el)) {
|
|
164
|
+
const runs = editing.value.split('\n').map((t) => ({ text: t }));
|
|
165
|
+
onPatchElement?.(el.id, { content: { ...el.content, runs } });
|
|
166
|
+
}
|
|
167
|
+
setEditing(null);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Render-time frame override for the element being dragged/resized.
|
|
171
|
+
const displaySlide = liveFrame && gestureRef.current
|
|
172
|
+
? { ...slide,
|
|
173
|
+
elements: (slide.elements || []).map((el) => (el.id === gestureRef.current.el.id ? { ...el, frame: liveFrame } : el)) }
|
|
174
|
+
: slide;
|
|
175
|
+
|
|
176
|
+
const selFrame = liveFrame && gestureRef.current && selected && gestureRef.current.el.id === selected.id
|
|
177
|
+
? liveFrame : selected?.frame;
|
|
178
|
+
|
|
179
|
+
const editingEl = editing ? (slide?.elements || []).find((x) => x.id === editing.elId) : null;
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<div ref={boxRef} className="sl-editor-fit" style={{ position: 'relative', width: '100%', height: '100%' }}>
|
|
183
|
+
<div style={{ position: 'absolute', left: box.left, top: box.top,
|
|
184
|
+
width: STAGE_W * scale, height: STAGE_H * scale,
|
|
185
|
+
boxShadow: '0 8px 40px -8px rgba(15,23,42,.25)', borderRadius: 6 * scale, overflow: 'hidden' }}>
|
|
186
|
+
<div style={{ position: 'absolute', top: 0, left: 0, transform: `scale(${scale})`, transformOrigin: 'top left' }}>
|
|
187
|
+
<SlideStage slide={displaySlide} theme={theme} resolveSrc={resolveSrc} />
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
|
|
191
|
+
{/* interaction + decoration layer (stage coordinates * scale) */}
|
|
192
|
+
<div className="sl-editor-layer"
|
|
193
|
+
style={{ position: 'absolute', left: box.left, top: box.top,
|
|
194
|
+
width: STAGE_W * scale, height: STAGE_H * scale, touchAction: 'none' }}
|
|
195
|
+
onPointerDown={onLayerPointerDown} onPointerMove={onPointerMove}
|
|
196
|
+
onPointerUp={onPointerUp} onDoubleClick={onDoubleClick}>
|
|
197
|
+
|
|
198
|
+
{/* peer selections + live peer drags */}
|
|
199
|
+
{peers.map((p) => {
|
|
200
|
+
const targetId = p.drag?.elId || p.sel?.elId;
|
|
201
|
+
if (!targetId || p.sel?.slideId !== slide?.id) return null;
|
|
202
|
+
const el = (slide?.elements || []).find((x) => x.id === targetId);
|
|
203
|
+
const f = p.drag?.frame || el?.frame;
|
|
204
|
+
if (!f) return null;
|
|
205
|
+
return (
|
|
206
|
+
<div key={p.id} className="sl-peer-box" style={{
|
|
207
|
+
left: f.x * scale, top: f.y * scale, width: f.w * scale, height: f.h * scale,
|
|
208
|
+
borderColor: p.color }}>
|
|
209
|
+
<span className="sl-peer-tag" style={{ background: p.color }}>{p.name}</span>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
})}
|
|
213
|
+
|
|
214
|
+
{/* own selection + handles */}
|
|
215
|
+
{selected && selFrame && !editing && (
|
|
216
|
+
<div className="sl-sel-box" style={{ left: selFrame.x * scale, top: selFrame.y * scale,
|
|
217
|
+
width: selFrame.w * scale, height: selFrame.h * scale }}>
|
|
218
|
+
{!readOnly && HANDLES.map((h) => (
|
|
219
|
+
<span key={h.k} className={`sl-sel-handle sl-h-${h.k}`}
|
|
220
|
+
onPointerDown={(e) => { e.stopPropagation(); beginGesture('resize', selected, e, h.k); }} />
|
|
221
|
+
))}
|
|
222
|
+
</div>
|
|
223
|
+
)}
|
|
224
|
+
|
|
225
|
+
{/* inline text editor */}
|
|
226
|
+
{editingEl && (
|
|
227
|
+
<textarea className="sl-text-edit" autoFocus value={editing.value}
|
|
228
|
+
style={{ left: editingEl.frame.x * scale, top: editingEl.frame.y * scale,
|
|
229
|
+
width: editingEl.frame.w * scale, height: editingEl.frame.h * scale,
|
|
230
|
+
fontSize: (editingEl.style?.fontSize
|
|
231
|
+
|| { title: 72, subtitle: 36, body: 30, bullets: 30, caption: 22 }[editingEl.content?.role || 'body']) * scale,
|
|
232
|
+
fontFamily: 'var(--sl-body, inherit)', lineHeight: 1.25,
|
|
233
|
+
textAlign: editingEl.style?.align || 'left' }}
|
|
234
|
+
onChange={(e) => setEditing((v) => ({ ...v, value: e.target.value }))}
|
|
235
|
+
onBlur={commitText}
|
|
236
|
+
onPointerDown={(e) => e.stopPropagation()}
|
|
237
|
+
onKeyDown={(e) => {
|
|
238
|
+
e.stopPropagation();
|
|
239
|
+
if (e.key === 'Escape') setEditing(null);
|
|
240
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) commitText();
|
|
241
|
+
}} />
|
|
242
|
+
)}
|
|
243
|
+
</div>
|
|
244
|
+
</div>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Presentation — fullscreen deck playback, modeled on how people actually
|
|
2
|
+
// present (Google Slides): entering triggers REAL browser fullscreen, the
|
|
3
|
+
// slide fills the screen edge-to-edge on black, everything is keyboard-driven
|
|
4
|
+
// (←/→/Space/PgUp/PgDn/Home/End, Esc exits), click advances, and the only
|
|
5
|
+
// chrome is a floating control pill that appears on mouse move and fades away
|
|
6
|
+
// with the cursor after a moment of stillness.
|
|
7
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
8
|
+
import { SlideView } from './SlideView.jsx';
|
|
9
|
+
|
|
10
|
+
export function Presentation({ deck, resolveSrc, startIndex = 0, onExit }) {
|
|
11
|
+
const slides = deck?.slides || [];
|
|
12
|
+
const rootRef = useRef(null);
|
|
13
|
+
const idleRef = useRef(null);
|
|
14
|
+
const iRef = useRef(Math.min(startIndex, Math.max(0, slides.length - 1)));
|
|
15
|
+
const [i, setI] = useState(iRef.current);
|
|
16
|
+
const [awake, setAwake] = useState(true);
|
|
17
|
+
|
|
18
|
+
const go = useCallback((n) => {
|
|
19
|
+
const next = Math.max(0, Math.min(slides.length - 1, n));
|
|
20
|
+
iRef.current = next;
|
|
21
|
+
setI(next);
|
|
22
|
+
}, [slides.length]);
|
|
23
|
+
|
|
24
|
+
// Real fullscreen on enter; leaving fullscreen (Esc) exits the show.
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const el = rootRef.current;
|
|
27
|
+
el?.requestFullscreen?.().catch(() => {});
|
|
28
|
+
const onFsChange = () => { if (!document.fullscreenElement) onExit && onExit(); };
|
|
29
|
+
document.addEventListener('fullscreenchange', onFsChange);
|
|
30
|
+
return () => {
|
|
31
|
+
document.removeEventListener('fullscreenchange', onFsChange);
|
|
32
|
+
if (document.fullscreenElement) document.exitFullscreen?.().catch(() => {});
|
|
33
|
+
};
|
|
34
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const onKey = (e) => {
|
|
39
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown' || e.key === ' ' || e.key === 'PageDown') { e.preventDefault(); go(iRef.current + 1); }
|
|
40
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp' || e.key === 'PageUp') { e.preventDefault(); go(iRef.current - 1); }
|
|
41
|
+
else if (e.key === 'Home') go(0);
|
|
42
|
+
else if (e.key === 'End') go(slides.length - 1);
|
|
43
|
+
else if (e.key === 'Escape') onExit && onExit(); // also fires via fullscreenchange
|
|
44
|
+
};
|
|
45
|
+
window.addEventListener('keydown', onKey);
|
|
46
|
+
return () => window.removeEventListener('keydown', onKey);
|
|
47
|
+
}, [go, slides.length, onExit]);
|
|
48
|
+
|
|
49
|
+
// Wake the chrome on movement; let it sleep (with the cursor) after 2s still.
|
|
50
|
+
const wake = useCallback(() => {
|
|
51
|
+
setAwake(true);
|
|
52
|
+
window.clearTimeout(idleRef.current);
|
|
53
|
+
idleRef.current = window.setTimeout(() => setAwake(false), 2000);
|
|
54
|
+
}, []);
|
|
55
|
+
useEffect(() => { wake(); return () => window.clearTimeout(idleRef.current); }, [wake]);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div ref={rootRef} className="sl-present" onMouseMove={wake}
|
|
59
|
+
onClick={() => go(iRef.current + 1)}
|
|
60
|
+
style={{ position: 'fixed', inset: 0, zIndex: 1000, background: '#000',
|
|
61
|
+
cursor: awake ? 'default' : 'none' }}>
|
|
62
|
+
<SlideView slide={slides[i]} theme={deck?.theme} resolveSrc={resolveSrc} bare />
|
|
63
|
+
<div className={'sl-present-pill' + (awake ? ' awake' : '')}
|
|
64
|
+
onClick={(e) => e.stopPropagation()}>
|
|
65
|
+
<button className="sl-pp-btn" aria-label="Previous slide" onClick={() => go(i - 1)} disabled={i === 0}>
|
|
66
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 18l-6-6 6-6"/></svg>
|
|
67
|
+
</button>
|
|
68
|
+
<span className="sl-pp-count">{i + 1} / {slides.length}</span>
|
|
69
|
+
<button className="sl-pp-btn" aria-label="Next slide" onClick={() => go(i + 1)} disabled={i >= slides.length - 1}>
|
|
70
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="M9 18l6-6-6-6"/></svg>
|
|
71
|
+
</button>
|
|
72
|
+
<span className="sl-pp-sep" />
|
|
73
|
+
<button className="sl-pp-btn" aria-label="Exit presentation" onClick={onExit}>
|
|
74
|
+
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round"><path d="M18 6L6 18M6 6l12 12"/></svg>
|
|
75
|
+
</button>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// SlideView — render ONE slide from the deck JSON onto the fixed 1920×1080
|
|
2
|
+
// stage, then scale that stage to fit the container (the convergent pattern
|
|
3
|
+
// from OpenDesign / frontend-slides). Theme tokens become CSS vars so every
|
|
4
|
+
// element reads them; elements are absolutely positioned by their `frame`.
|
|
5
|
+
// The SAME component renders the editor canvas, the thumbnails, and the
|
|
6
|
+
// presentation view — one renderer, four surfaces.
|
|
7
|
+
import { useEffect, useRef, useState } from 'react';
|
|
8
|
+
import { ElementView } from './elements.jsx';
|
|
9
|
+
|
|
10
|
+
const STAGE_W = 1920;
|
|
11
|
+
const STAGE_H = 1080;
|
|
12
|
+
|
|
13
|
+
/** deck.theme → CSS custom properties consumed by the element renderers. */
|
|
14
|
+
export function themeVars(theme) {
|
|
15
|
+
const p = (theme && theme.palette) || {};
|
|
16
|
+
const f = (theme && theme.fonts) || {};
|
|
17
|
+
return {
|
|
18
|
+
'--sl-bg': p.bg || '#FFFFFF',
|
|
19
|
+
'--sl-surface': p.surface || '#F7F8FB',
|
|
20
|
+
'--sl-ink': p.ink || '#111827',
|
|
21
|
+
'--sl-mute': p.mute || '#6B7280',
|
|
22
|
+
'--sl-brand': p.brand || '#4F46E5',
|
|
23
|
+
'--sl-accent': p.accent || '#06B6D4',
|
|
24
|
+
'--sl-head': f.head || 'Inter, system-ui, sans-serif',
|
|
25
|
+
'--sl-body': f.body || 'Inter, system-ui, sans-serif',
|
|
26
|
+
'--sl-mono': 'ui-monospace, SFMono-Regular, Menlo, monospace',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function background(bg, theme) {
|
|
31
|
+
if (!bg) return { background: 'var(--sl-bg)' };
|
|
32
|
+
if (bg.color) return { background: bg.color };
|
|
33
|
+
if (bg.gradient) return { background: bg.gradient };
|
|
34
|
+
if (bg.image) return { backgroundImage: `url(${bg.image})`, backgroundSize: 'cover', backgroundPosition: 'center' };
|
|
35
|
+
return { background: 'var(--sl-bg)' };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The un-scaled 1920×1080 stage. Used directly for export/screenshot; wrapped
|
|
39
|
+
* by SlideView for on-screen scaling. */
|
|
40
|
+
export function SlideStage({ slide, theme, resolveSrc, selectedId, onSelectElement }) {
|
|
41
|
+
return (
|
|
42
|
+
<div className="sl-stage"
|
|
43
|
+
style={{ position: 'relative', width: STAGE_W, height: STAGE_H, overflow: 'hidden',
|
|
44
|
+
fontFamily: 'var(--sl-body)', ...themeVars(theme), ...background(slide?.background, theme) }}>
|
|
45
|
+
{(slide?.elements || []).map((el) => {
|
|
46
|
+
const fr = el.frame || {};
|
|
47
|
+
const sel = onSelectElement && el.id === selectedId;
|
|
48
|
+
return (
|
|
49
|
+
<div key={el.id}
|
|
50
|
+
className={'sl-el' + (sel ? ' sl-el-selected' : '')}
|
|
51
|
+
onMouseDown={onSelectElement ? (e) => { e.stopPropagation(); onSelectElement(el.id); } : undefined}
|
|
52
|
+
style={{ position: 'absolute',
|
|
53
|
+
left: fr.x || 0, top: fr.y || 0,
|
|
54
|
+
width: fr.w ?? 400, height: fr.h ?? 100,
|
|
55
|
+
transform: fr.rotation ? `rotate(${fr.rotation}deg)` : undefined,
|
|
56
|
+
cursor: onSelectElement ? 'pointer' : 'default' }}>
|
|
57
|
+
<ElementView el={el} resolveSrc={resolveSrc} />
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
})}
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Scales the fixed stage to fill its parent while preserving 16:9. */
|
|
66
|
+
export function SlideView({ slide, theme, resolveSrc, selectedId, onSelectElement, onDeselect, bare }) {
|
|
67
|
+
const boxRef = useRef(null);
|
|
68
|
+
const [scale, setScale] = useState(1);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const el = boxRef.current;
|
|
71
|
+
if (!el) return undefined;
|
|
72
|
+
const fit = () => {
|
|
73
|
+
const r = el.getBoundingClientRect();
|
|
74
|
+
if (r.width && r.height) setScale(Math.min(r.width / STAGE_W, r.height / STAGE_H));
|
|
75
|
+
};
|
|
76
|
+
fit();
|
|
77
|
+
const ro = new ResizeObserver(fit);
|
|
78
|
+
ro.observe(el);
|
|
79
|
+
return () => ro.disconnect();
|
|
80
|
+
}, []);
|
|
81
|
+
return (
|
|
82
|
+
<div ref={boxRef} className="sl-fit"
|
|
83
|
+
onMouseDown={onDeselect}
|
|
84
|
+
style={{ position: 'relative', width: '100%', height: '100%',
|
|
85
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
86
|
+
<div style={{ width: STAGE_W * scale, height: STAGE_H * scale, position: 'relative',
|
|
87
|
+
boxShadow: bare ? 'none' : '0 8px 40px -8px rgba(15,23,42,.25)',
|
|
88
|
+
borderRadius: bare ? 0 : 6 * scale, overflow: 'hidden',
|
|
89
|
+
flexShrink: 0 }}>
|
|
90
|
+
<div style={{ position: 'absolute', top: 0, left: 0, transform: `scale(${scale})`, transformOrigin: 'top left' }}>
|
|
91
|
+
<SlideStage slide={slide} theme={theme} resolveSrc={resolveSrc}
|
|
92
|
+
selectedId={selectedId} onSelectElement={onSelectElement} />
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Element renderers — one per element type in the deck model
|
|
2
|
+
// (docs/slides-architecture.md). Each renders the element's `content` inside a
|
|
3
|
+
// frame that SlideView has already absolutely-positioned + sized on the fixed
|
|
4
|
+
// 1920×1080 stage, so these components fill 100% of their box and never worry
|
|
5
|
+
// about placement. Charts (ECharts) and flowcharts (Mermaid) load lazily and
|
|
6
|
+
// render to SVG so they stay crisp in the canvas, thumbnails, and PDF.
|
|
7
|
+
import { useEffect, useRef, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
// Rich-text runs → spans with marks. role drives default sizing (the stage is
|
|
10
|
+
// 1920 wide, so these px sizes read correctly once the stage is scaled).
|
|
11
|
+
const ROLE_STYLE = {
|
|
12
|
+
title: { fontSize: 72, fontWeight: 800, lineHeight: 1.1, fontFamily: 'var(--sl-head)' },
|
|
13
|
+
subtitle: { fontSize: 36, fontWeight: 500, lineHeight: 1.25, color: 'var(--sl-mute)' },
|
|
14
|
+
body: { fontSize: 30, fontWeight: 400, lineHeight: 1.4 },
|
|
15
|
+
bullets: { fontSize: 30, fontWeight: 400, lineHeight: 1.5 },
|
|
16
|
+
caption: { fontSize: 22, fontWeight: 400, lineHeight: 1.3, color: 'var(--sl-mute)' },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function runSpans(runs) {
|
|
20
|
+
return (runs || []).map((r, i) => {
|
|
21
|
+
const marks = new Set(r.marks || []);
|
|
22
|
+
let node = r.text;
|
|
23
|
+
const style = {};
|
|
24
|
+
if (marks.has('bold')) style.fontWeight = 700;
|
|
25
|
+
if (marks.has('italic')) style.fontStyle = 'italic';
|
|
26
|
+
if (marks.has('underline')) style.textDecoration = 'underline';
|
|
27
|
+
if (marks.has('code')) { style.fontFamily = 'var(--sl-mono, monospace)'; style.background = 'rgba(0,0,0,.06)'; style.padding = '0 6px'; style.borderRadius = 4; }
|
|
28
|
+
const link = (r.marks || []).find((m) => typeof m === 'object' && m.link);
|
|
29
|
+
if (link) return <a key={i} href={link.link} style={{ ...style, color: 'var(--sl-brand)' }}>{node}</a>;
|
|
30
|
+
return <span key={i} style={style}>{node}</span>;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function TextEl({ el }) {
|
|
35
|
+
const role = el.content?.role || 'body';
|
|
36
|
+
const base = ROLE_STYLE[role] || ROLE_STYLE.body;
|
|
37
|
+
const align = el.style?.align || (role === 'title' || role === 'subtitle' ? 'left' : 'left');
|
|
38
|
+
const runs = el.content?.runs || [];
|
|
39
|
+
const style = { ...base, ...(el.style || {}), textAlign: align, color: el.style?.color || base.color || 'var(--sl-ink)',
|
|
40
|
+
width: '100%', height: '100%', display: 'flex', flexDirection: 'column',
|
|
41
|
+
justifyContent: el.style?.valign === 'center' ? 'center' : 'flex-start', overflow: 'visible' };
|
|
42
|
+
if (role === 'bullets') {
|
|
43
|
+
return (
|
|
44
|
+
<ul style={{ ...style, margin: 0, paddingLeft: 40, display: 'block' }}>
|
|
45
|
+
{runs.map((r, i) => <li key={i} style={{ marginBottom: 8 }}>{runSpans([r])}</li>)}
|
|
46
|
+
</ul>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return <div style={style}>{runSpans(runs)}</div>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function ImageEl({ el, resolveSrc }) {
|
|
53
|
+
const src = resolveSrc ? resolveSrc(el.content?.src) : el.content?.src;
|
|
54
|
+
if (!src) return <div style={ph()}>image</div>;
|
|
55
|
+
return <img src={src} alt={el.content?.alt || ''}
|
|
56
|
+
style={{ width: '100%', height: '100%', objectFit: el.content?.fit || 'cover',
|
|
57
|
+
borderRadius: el.style?.radius ?? 0, display: 'block' }} />;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function ChartEl({ el }) {
|
|
61
|
+
const ref = useRef(null);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
let chart = null; let dead = false;
|
|
64
|
+
(async () => {
|
|
65
|
+
try {
|
|
66
|
+
const echarts = (await import('echarts')).default || (await import('echarts'));
|
|
67
|
+
if (dead || !ref.current) return;
|
|
68
|
+
chart = echarts.init(ref.current, null, { renderer: 'svg' });
|
|
69
|
+
if (el.content?.spec) chart.setOption(el.content.spec);
|
|
70
|
+
} catch { /* echarts missing — leave the box */ }
|
|
71
|
+
})();
|
|
72
|
+
return () => { dead = true; try { chart && chart.dispose(); } catch {} };
|
|
73
|
+
}, [JSON.stringify(el.content?.spec)]);
|
|
74
|
+
return <div ref={ref} style={{ width: '100%', height: '100%' }} />;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function FlowchartEl({ el }) {
|
|
78
|
+
const [svg, setSvg] = useState('');
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
let dead = false;
|
|
81
|
+
(async () => {
|
|
82
|
+
const src = el.content?.mermaid;
|
|
83
|
+
if (!src) return;
|
|
84
|
+
try {
|
|
85
|
+
const mermaid = (await import('mermaid')).default || (await import('mermaid'));
|
|
86
|
+
mermaid.initialize({ startOnLoad: false, theme: 'neutral' });
|
|
87
|
+
const id = 'mmd_' + Math.random().toString(36).slice(2);
|
|
88
|
+
const { svg } = await mermaid.render(id, src);
|
|
89
|
+
if (!dead) setSvg(svg);
|
|
90
|
+
} catch { if (!dead) setSvg(''); }
|
|
91
|
+
})();
|
|
92
|
+
return () => { dead = true; };
|
|
93
|
+
}, [el.content?.mermaid]);
|
|
94
|
+
return <div style={{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }}
|
|
95
|
+
dangerouslySetInnerHTML={{ __html: svg || '' }} />;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function ShapeEl({ el }) {
|
|
99
|
+
const kind = el.content?.kind || 'rect';
|
|
100
|
+
const fill = el.style?.fill || 'var(--sl-brand)';
|
|
101
|
+
const stroke = el.style?.stroke || 'transparent';
|
|
102
|
+
const sw = el.style?.strokeWidth ?? 0;
|
|
103
|
+
if (kind === 'line' || kind === 'arrow') {
|
|
104
|
+
return (
|
|
105
|
+
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ width: '100%', height: '100%' }}>
|
|
106
|
+
<defs><marker id="ah" markerWidth="10" markerHeight="10" refX="7" refY="3" orient="auto">
|
|
107
|
+
<path d="M0,0 L7,3 L0,6 Z" fill={stroke !== 'transparent' ? stroke : fill} /></marker></defs>
|
|
108
|
+
<line x1="2" y1="50" x2="98" y2="50" stroke={stroke !== 'transparent' ? stroke : fill}
|
|
109
|
+
strokeWidth={sw || 3} markerEnd={kind === 'arrow' ? 'url(#ah)' : undefined} />
|
|
110
|
+
</svg>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
const radius = kind === 'ellipse' ? '50%' : (el.style?.radius ?? 8);
|
|
114
|
+
return <div style={{ width: '100%', height: '100%', background: fill, borderRadius: radius,
|
|
115
|
+
border: sw ? `${sw}px solid ${stroke}` : undefined }} />;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function TableEl({ el }) {
|
|
119
|
+
const cols = el.content?.columns || [];
|
|
120
|
+
const rows = el.content?.rows || [];
|
|
121
|
+
return (
|
|
122
|
+
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 24, color: 'var(--sl-ink)' }}>
|
|
123
|
+
{cols.length > 0 && (
|
|
124
|
+
<thead><tr>{cols.map((c, i) => (
|
|
125
|
+
<th key={i} style={{ textAlign: 'left', padding: '10px 14px', borderBottom: '2px solid var(--sl-brand)', fontWeight: 700 }}>{c}</th>
|
|
126
|
+
))}</tr></thead>
|
|
127
|
+
)}
|
|
128
|
+
<tbody>{rows.map((r, i) => (
|
|
129
|
+
<tr key={i}>{(r || []).map((cell, j) => (
|
|
130
|
+
<td key={j} style={{ padding: '10px 14px', borderBottom: '1px solid rgba(0,0,0,.08)' }}>{cell}</td>
|
|
131
|
+
))}</tr>
|
|
132
|
+
))}</tbody>
|
|
133
|
+
</table>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function CodeEl({ el }) {
|
|
138
|
+
const ref = useRef(null);
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
let dead = false;
|
|
141
|
+
(async () => {
|
|
142
|
+
try {
|
|
143
|
+
const hljs = (await import('highlight.js/lib/common')).default;
|
|
144
|
+
if (dead || !ref.current) return;
|
|
145
|
+
ref.current.textContent = el.content?.source || '';
|
|
146
|
+
hljs.highlightElement(ref.current);
|
|
147
|
+
} catch { if (ref.current) ref.current.textContent = el.content?.source || ''; }
|
|
148
|
+
})();
|
|
149
|
+
return () => { dead = true; };
|
|
150
|
+
}, [el.content?.source, el.content?.lang]);
|
|
151
|
+
return (
|
|
152
|
+
<pre style={{ width: '100%', height: '100%', margin: 0, overflow: 'auto', borderRadius: 8,
|
|
153
|
+
fontSize: 22, lineHeight: 1.5, background: '#0B1020' }}>
|
|
154
|
+
<code ref={ref} className={`language-${el.content?.lang || 'plaintext'}`} />
|
|
155
|
+
</pre>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function EmbedEl({ el }) {
|
|
160
|
+
return <div style={{ width: '100%', height: '100%', overflow: 'hidden' }}
|
|
161
|
+
dangerouslySetInnerHTML={{ __html: el.content?.html || '' }} />;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function ph() {
|
|
165
|
+
return { width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
166
|
+
background: 'var(--sl-surface)', color: 'var(--sl-mute)', fontSize: 20, borderRadius: 8 };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const RENDERERS = {
|
|
170
|
+
text: TextEl, image: ImageEl, chart: ChartEl, flowchart: FlowchartEl,
|
|
171
|
+
shape: ShapeEl, table: TableEl, code: CodeEl, embed: EmbedEl,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export function ElementView({ el, resolveSrc }) {
|
|
175
|
+
const R = RENDERERS[el.type];
|
|
176
|
+
if (!R) return <div style={ph()}>{el.type}</div>;
|
|
177
|
+
return <R el={el} resolveSrc={resolveSrc} />;
|
|
178
|
+
}
|