reifyui 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -10
- package/dist/index.cjs +407 -172
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +128 -22
- package/dist/index.js +416 -172
- package/dist/index.js.map +1 -1
- package/dist/slides.cjs +737 -0
- package/dist/slides.cjs.map +1 -0
- package/dist/slides.d.ts +125 -0
- package/dist/slides.js +705 -0
- package/dist/slides.js.map +1 -0
- package/package.json +9 -2
- 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 +125 -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/dialog.css +145 -0
- package/styles/slides.css +38 -0
package/dist/slides.js
ADDED
|
@@ -0,0 +1,705 @@
|
|
|
1
|
+
// src/slides/SlideView.jsx
|
|
2
|
+
import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
3
|
+
|
|
4
|
+
// src/slides/elements.jsx
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
var ROLE_STYLE = {
|
|
8
|
+
title: { fontSize: 72, fontWeight: 800, lineHeight: 1.1, fontFamily: "var(--sl-head)" },
|
|
9
|
+
subtitle: { fontSize: 36, fontWeight: 500, lineHeight: 1.25, color: "var(--sl-mute)" },
|
|
10
|
+
body: { fontSize: 30, fontWeight: 400, lineHeight: 1.4 },
|
|
11
|
+
bullets: { fontSize: 30, fontWeight: 400, lineHeight: 1.5 },
|
|
12
|
+
caption: { fontSize: 22, fontWeight: 400, lineHeight: 1.3, color: "var(--sl-mute)" }
|
|
13
|
+
};
|
|
14
|
+
function runSpans(runs) {
|
|
15
|
+
return (runs || []).map((r, i) => {
|
|
16
|
+
const marks = new Set(r.marks || []);
|
|
17
|
+
let node = r.text;
|
|
18
|
+
const style = {};
|
|
19
|
+
if (marks.has("bold")) style.fontWeight = 700;
|
|
20
|
+
if (marks.has("italic")) style.fontStyle = "italic";
|
|
21
|
+
if (marks.has("underline")) style.textDecoration = "underline";
|
|
22
|
+
if (marks.has("code")) {
|
|
23
|
+
style.fontFamily = "var(--sl-mono, monospace)";
|
|
24
|
+
style.background = "rgba(0,0,0,.06)";
|
|
25
|
+
style.padding = "0 6px";
|
|
26
|
+
style.borderRadius = 4;
|
|
27
|
+
}
|
|
28
|
+
const link = (r.marks || []).find((m) => typeof m === "object" && m.link);
|
|
29
|
+
if (link) return /* @__PURE__ */ jsx("a", { href: link.link, style: { ...style, color: "var(--sl-brand)" }, children: node }, i);
|
|
30
|
+
return /* @__PURE__ */ jsx("span", { style, children: node }, i);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function TextEl({ el }) {
|
|
34
|
+
const role = el.content?.role || "body";
|
|
35
|
+
const base = ROLE_STYLE[role] || ROLE_STYLE.body;
|
|
36
|
+
const align = el.style?.align || (role === "title" || role === "subtitle" ? "left" : "left");
|
|
37
|
+
const runs = el.content?.runs || [];
|
|
38
|
+
const style = {
|
|
39
|
+
...base,
|
|
40
|
+
...el.style || {},
|
|
41
|
+
textAlign: align,
|
|
42
|
+
color: el.style?.color || base.color || "var(--sl-ink)",
|
|
43
|
+
width: "100%",
|
|
44
|
+
height: "100%",
|
|
45
|
+
display: "flex",
|
|
46
|
+
flexDirection: "column",
|
|
47
|
+
justifyContent: el.style?.valign === "center" ? "center" : "flex-start",
|
|
48
|
+
overflow: "visible"
|
|
49
|
+
};
|
|
50
|
+
if (role === "bullets") {
|
|
51
|
+
return /* @__PURE__ */ jsx("ul", { style: { ...style, margin: 0, paddingLeft: 40, display: "block" }, children: runs.map((r, i) => /* @__PURE__ */ jsx("li", { style: { marginBottom: 8 }, children: runSpans([r]) }, i)) });
|
|
52
|
+
}
|
|
53
|
+
return /* @__PURE__ */ jsx("div", { style, children: runSpans(runs) });
|
|
54
|
+
}
|
|
55
|
+
function ImageEl({ el, resolveSrc }) {
|
|
56
|
+
const src = resolveSrc ? resolveSrc(el.content?.src) : el.content?.src;
|
|
57
|
+
if (!src) return /* @__PURE__ */ jsx("div", { style: ph(), children: "image" });
|
|
58
|
+
return /* @__PURE__ */ jsx(
|
|
59
|
+
"img",
|
|
60
|
+
{
|
|
61
|
+
src,
|
|
62
|
+
alt: el.content?.alt || "",
|
|
63
|
+
style: {
|
|
64
|
+
width: "100%",
|
|
65
|
+
height: "100%",
|
|
66
|
+
objectFit: el.content?.fit || "cover",
|
|
67
|
+
borderRadius: el.style?.radius ?? 0,
|
|
68
|
+
display: "block"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
function ChartEl({ el }) {
|
|
74
|
+
const ref = useRef(null);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
let chart = null;
|
|
77
|
+
let dead = false;
|
|
78
|
+
(async () => {
|
|
79
|
+
try {
|
|
80
|
+
const echarts = (await import("echarts")).default || await import("echarts");
|
|
81
|
+
if (dead || !ref.current) return;
|
|
82
|
+
chart = echarts.init(ref.current, null, { renderer: "svg" });
|
|
83
|
+
if (el.content?.spec) chart.setOption(el.content.spec);
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
})();
|
|
87
|
+
return () => {
|
|
88
|
+
dead = true;
|
|
89
|
+
try {
|
|
90
|
+
chart && chart.dispose();
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}, [JSON.stringify(el.content?.spec)]);
|
|
95
|
+
return /* @__PURE__ */ jsx("div", { ref, style: { width: "100%", height: "100%" } });
|
|
96
|
+
}
|
|
97
|
+
function FlowchartEl({ el }) {
|
|
98
|
+
const [svg, setSvg] = useState("");
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
let dead = false;
|
|
101
|
+
(async () => {
|
|
102
|
+
const src = el.content?.mermaid;
|
|
103
|
+
if (!src) return;
|
|
104
|
+
try {
|
|
105
|
+
const mermaid = (await import("mermaid")).default || await import("mermaid");
|
|
106
|
+
mermaid.initialize({ startOnLoad: false, theme: "neutral" });
|
|
107
|
+
const id = "mmd_" + Math.random().toString(36).slice(2);
|
|
108
|
+
const { svg: svg2 } = await mermaid.render(id, src);
|
|
109
|
+
if (!dead) setSvg(svg2);
|
|
110
|
+
} catch {
|
|
111
|
+
if (!dead) setSvg("");
|
|
112
|
+
}
|
|
113
|
+
})();
|
|
114
|
+
return () => {
|
|
115
|
+
dead = true;
|
|
116
|
+
};
|
|
117
|
+
}, [el.content?.mermaid]);
|
|
118
|
+
return /* @__PURE__ */ jsx(
|
|
119
|
+
"div",
|
|
120
|
+
{
|
|
121
|
+
style: { width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center" },
|
|
122
|
+
dangerouslySetInnerHTML: { __html: svg || "" }
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
function ShapeEl({ el }) {
|
|
127
|
+
const kind = el.content?.kind || "rect";
|
|
128
|
+
const fill = el.style?.fill || "var(--sl-brand)";
|
|
129
|
+
const stroke = el.style?.stroke || "transparent";
|
|
130
|
+
const sw = el.style?.strokeWidth ?? 0;
|
|
131
|
+
if (kind === "line" || kind === "arrow") {
|
|
132
|
+
return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 100 100", preserveAspectRatio: "none", style: { width: "100%", height: "100%" }, children: [
|
|
133
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("marker", { id: "ah", markerWidth: "10", markerHeight: "10", refX: "7", refY: "3", orient: "auto", children: /* @__PURE__ */ jsx("path", { d: "M0,0 L7,3 L0,6 Z", fill: stroke !== "transparent" ? stroke : fill }) }) }),
|
|
134
|
+
/* @__PURE__ */ jsx(
|
|
135
|
+
"line",
|
|
136
|
+
{
|
|
137
|
+
x1: "2",
|
|
138
|
+
y1: "50",
|
|
139
|
+
x2: "98",
|
|
140
|
+
y2: "50",
|
|
141
|
+
stroke: stroke !== "transparent" ? stroke : fill,
|
|
142
|
+
strokeWidth: sw || 3,
|
|
143
|
+
markerEnd: kind === "arrow" ? "url(#ah)" : void 0
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
] });
|
|
147
|
+
}
|
|
148
|
+
const radius = kind === "ellipse" ? "50%" : el.style?.radius ?? 8;
|
|
149
|
+
return /* @__PURE__ */ jsx("div", { style: {
|
|
150
|
+
width: "100%",
|
|
151
|
+
height: "100%",
|
|
152
|
+
background: fill,
|
|
153
|
+
borderRadius: radius,
|
|
154
|
+
border: sw ? `${sw}px solid ${stroke}` : void 0
|
|
155
|
+
} });
|
|
156
|
+
}
|
|
157
|
+
function TableEl({ el }) {
|
|
158
|
+
const cols = el.content?.columns || [];
|
|
159
|
+
const rows = el.content?.rows || [];
|
|
160
|
+
return /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 24, color: "var(--sl-ink)" }, children: [
|
|
161
|
+
cols.length > 0 && /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: cols.map((c, i) => /* @__PURE__ */ jsx("th", { style: { textAlign: "left", padding: "10px 14px", borderBottom: "2px solid var(--sl-brand)", fontWeight: 700 }, children: c }, i)) }) }),
|
|
162
|
+
/* @__PURE__ */ jsx("tbody", { children: rows.map((r, i) => /* @__PURE__ */ jsx("tr", { children: (r || []).map((cell, j) => /* @__PURE__ */ jsx("td", { style: { padding: "10px 14px", borderBottom: "1px solid rgba(0,0,0,.08)" }, children: cell }, j)) }, i)) })
|
|
163
|
+
] });
|
|
164
|
+
}
|
|
165
|
+
function CodeEl({ el }) {
|
|
166
|
+
const ref = useRef(null);
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
let dead = false;
|
|
169
|
+
(async () => {
|
|
170
|
+
try {
|
|
171
|
+
const hljs = (await import("highlight.js/lib/common")).default;
|
|
172
|
+
if (dead || !ref.current) return;
|
|
173
|
+
ref.current.textContent = el.content?.source || "";
|
|
174
|
+
hljs.highlightElement(ref.current);
|
|
175
|
+
} catch {
|
|
176
|
+
if (ref.current) ref.current.textContent = el.content?.source || "";
|
|
177
|
+
}
|
|
178
|
+
})();
|
|
179
|
+
return () => {
|
|
180
|
+
dead = true;
|
|
181
|
+
};
|
|
182
|
+
}, [el.content?.source, el.content?.lang]);
|
|
183
|
+
return /* @__PURE__ */ jsx("pre", { style: {
|
|
184
|
+
width: "100%",
|
|
185
|
+
height: "100%",
|
|
186
|
+
margin: 0,
|
|
187
|
+
overflow: "auto",
|
|
188
|
+
borderRadius: 8,
|
|
189
|
+
fontSize: 22,
|
|
190
|
+
lineHeight: 1.5,
|
|
191
|
+
background: "#0B1020"
|
|
192
|
+
}, children: /* @__PURE__ */ jsx("code", { ref, className: `language-${el.content?.lang || "plaintext"}` }) });
|
|
193
|
+
}
|
|
194
|
+
function EmbedEl({ el }) {
|
|
195
|
+
return /* @__PURE__ */ jsx(
|
|
196
|
+
"div",
|
|
197
|
+
{
|
|
198
|
+
style: { width: "100%", height: "100%", overflow: "hidden" },
|
|
199
|
+
dangerouslySetInnerHTML: { __html: el.content?.html || "" }
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
function ph() {
|
|
204
|
+
return {
|
|
205
|
+
width: "100%",
|
|
206
|
+
height: "100%",
|
|
207
|
+
display: "flex",
|
|
208
|
+
alignItems: "center",
|
|
209
|
+
justifyContent: "center",
|
|
210
|
+
background: "var(--sl-surface)",
|
|
211
|
+
color: "var(--sl-mute)",
|
|
212
|
+
fontSize: 20,
|
|
213
|
+
borderRadius: 8
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
var RENDERERS = {
|
|
217
|
+
text: TextEl,
|
|
218
|
+
image: ImageEl,
|
|
219
|
+
chart: ChartEl,
|
|
220
|
+
flowchart: FlowchartEl,
|
|
221
|
+
shape: ShapeEl,
|
|
222
|
+
table: TableEl,
|
|
223
|
+
code: CodeEl,
|
|
224
|
+
embed: EmbedEl
|
|
225
|
+
};
|
|
226
|
+
function ElementView({ el, resolveSrc }) {
|
|
227
|
+
const R = RENDERERS[el.type];
|
|
228
|
+
if (!R) return /* @__PURE__ */ jsx("div", { style: ph(), children: el.type });
|
|
229
|
+
return /* @__PURE__ */ jsx(R, { el, resolveSrc });
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/slides/SlideView.jsx
|
|
233
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
234
|
+
var STAGE_W = 1920;
|
|
235
|
+
var STAGE_H = 1080;
|
|
236
|
+
function themeVars(theme) {
|
|
237
|
+
const p = theme && theme.palette || {};
|
|
238
|
+
const f = theme && theme.fonts || {};
|
|
239
|
+
return {
|
|
240
|
+
"--sl-bg": p.bg || "#FFFFFF",
|
|
241
|
+
"--sl-surface": p.surface || "#F7F8FB",
|
|
242
|
+
"--sl-ink": p.ink || "#111827",
|
|
243
|
+
"--sl-mute": p.mute || "#6B7280",
|
|
244
|
+
"--sl-brand": p.brand || "#4F46E5",
|
|
245
|
+
"--sl-accent": p.accent || "#06B6D4",
|
|
246
|
+
"--sl-head": f.head || "Inter, system-ui, sans-serif",
|
|
247
|
+
"--sl-body": f.body || "Inter, system-ui, sans-serif",
|
|
248
|
+
"--sl-mono": "ui-monospace, SFMono-Regular, Menlo, monospace"
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function background(bg, theme) {
|
|
252
|
+
if (!bg) return { background: "var(--sl-bg)" };
|
|
253
|
+
if (bg.color) return { background: bg.color };
|
|
254
|
+
if (bg.gradient) return { background: bg.gradient };
|
|
255
|
+
if (bg.image) return { backgroundImage: `url(${bg.image})`, backgroundSize: "cover", backgroundPosition: "center" };
|
|
256
|
+
return { background: "var(--sl-bg)" };
|
|
257
|
+
}
|
|
258
|
+
function SlideStage({ slide, theme, resolveSrc, selectedId, onSelectElement }) {
|
|
259
|
+
return /* @__PURE__ */ jsx2(
|
|
260
|
+
"div",
|
|
261
|
+
{
|
|
262
|
+
className: "sl-stage",
|
|
263
|
+
style: {
|
|
264
|
+
position: "relative",
|
|
265
|
+
width: STAGE_W,
|
|
266
|
+
height: STAGE_H,
|
|
267
|
+
overflow: "hidden",
|
|
268
|
+
fontFamily: "var(--sl-body)",
|
|
269
|
+
...themeVars(theme),
|
|
270
|
+
...background(slide?.background, theme)
|
|
271
|
+
},
|
|
272
|
+
children: (slide?.elements || []).map((el) => {
|
|
273
|
+
const fr = el.frame || {};
|
|
274
|
+
const sel = onSelectElement && el.id === selectedId;
|
|
275
|
+
return /* @__PURE__ */ jsx2(
|
|
276
|
+
"div",
|
|
277
|
+
{
|
|
278
|
+
className: "sl-el" + (sel ? " sl-el-selected" : ""),
|
|
279
|
+
onMouseDown: onSelectElement ? (e) => {
|
|
280
|
+
e.stopPropagation();
|
|
281
|
+
onSelectElement(el.id);
|
|
282
|
+
} : void 0,
|
|
283
|
+
style: {
|
|
284
|
+
position: "absolute",
|
|
285
|
+
left: fr.x || 0,
|
|
286
|
+
top: fr.y || 0,
|
|
287
|
+
width: fr.w ?? 400,
|
|
288
|
+
height: fr.h ?? 100,
|
|
289
|
+
transform: fr.rotation ? `rotate(${fr.rotation}deg)` : void 0,
|
|
290
|
+
cursor: onSelectElement ? "pointer" : "default"
|
|
291
|
+
},
|
|
292
|
+
children: /* @__PURE__ */ jsx2(ElementView, { el, resolveSrc })
|
|
293
|
+
},
|
|
294
|
+
el.id
|
|
295
|
+
);
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
function SlideView({ slide, theme, resolveSrc, selectedId, onSelectElement, onDeselect, bare }) {
|
|
301
|
+
const boxRef = useRef2(null);
|
|
302
|
+
const [scale, setScale] = useState2(1);
|
|
303
|
+
useEffect2(() => {
|
|
304
|
+
const el = boxRef.current;
|
|
305
|
+
if (!el) return void 0;
|
|
306
|
+
const fit = () => {
|
|
307
|
+
const r = el.getBoundingClientRect();
|
|
308
|
+
if (r.width && r.height) setScale(Math.min(r.width / STAGE_W, r.height / STAGE_H));
|
|
309
|
+
};
|
|
310
|
+
fit();
|
|
311
|
+
const ro = new ResizeObserver(fit);
|
|
312
|
+
ro.observe(el);
|
|
313
|
+
return () => ro.disconnect();
|
|
314
|
+
}, []);
|
|
315
|
+
return /* @__PURE__ */ jsx2(
|
|
316
|
+
"div",
|
|
317
|
+
{
|
|
318
|
+
ref: boxRef,
|
|
319
|
+
className: "sl-fit",
|
|
320
|
+
onMouseDown: onDeselect,
|
|
321
|
+
style: {
|
|
322
|
+
position: "relative",
|
|
323
|
+
width: "100%",
|
|
324
|
+
height: "100%",
|
|
325
|
+
display: "flex",
|
|
326
|
+
alignItems: "center",
|
|
327
|
+
justifyContent: "center"
|
|
328
|
+
},
|
|
329
|
+
children: /* @__PURE__ */ jsx2("div", { style: {
|
|
330
|
+
width: STAGE_W * scale,
|
|
331
|
+
height: STAGE_H * scale,
|
|
332
|
+
position: "relative",
|
|
333
|
+
boxShadow: bare ? "none" : "0 8px 40px -8px rgba(15,23,42,.25)",
|
|
334
|
+
borderRadius: bare ? 0 : 6 * scale,
|
|
335
|
+
overflow: "hidden",
|
|
336
|
+
flexShrink: 0
|
|
337
|
+
}, children: /* @__PURE__ */ jsx2("div", { style: { position: "absolute", top: 0, left: 0, transform: `scale(${scale})`, transformOrigin: "top left" }, children: /* @__PURE__ */ jsx2(
|
|
338
|
+
SlideStage,
|
|
339
|
+
{
|
|
340
|
+
slide,
|
|
341
|
+
theme,
|
|
342
|
+
resolveSrc,
|
|
343
|
+
selectedId,
|
|
344
|
+
onSelectElement
|
|
345
|
+
}
|
|
346
|
+
) }) })
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// src/slides/Editor.jsx
|
|
352
|
+
import { useCallback, useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
|
|
353
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
354
|
+
var STAGE_W2 = 1920;
|
|
355
|
+
var STAGE_H2 = 1080;
|
|
356
|
+
var MIN_SIZE = 24;
|
|
357
|
+
function hitTest(slide, x, y) {
|
|
358
|
+
const els = slide?.elements || [];
|
|
359
|
+
for (let i = els.length - 1; i >= 0; i--) {
|
|
360
|
+
const f = els[i].frame || {};
|
|
361
|
+
if (x >= (f.x || 0) && x <= (f.x || 0) + (f.w || 0) && y >= (f.y || 0) && y <= (f.y || 0) + (f.h || 0)) return els[i];
|
|
362
|
+
}
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
var HANDLES = [
|
|
366
|
+
{ k: "nw", cx: 0, cy: 0 },
|
|
367
|
+
{ k: "ne", cx: 1, cy: 0 },
|
|
368
|
+
{ k: "sw", cx: 0, cy: 1 },
|
|
369
|
+
{ k: "se", cx: 1, cy: 1 }
|
|
370
|
+
];
|
|
371
|
+
function resizeFrame(f0, k, dx, dy) {
|
|
372
|
+
let { x, y, w, h } = f0;
|
|
373
|
+
if (k.includes("e")) w = Math.max(MIN_SIZE, f0.w + dx);
|
|
374
|
+
if (k.includes("s")) h = Math.max(MIN_SIZE, f0.h + dy);
|
|
375
|
+
if (k.includes("w")) {
|
|
376
|
+
const nw = Math.max(MIN_SIZE, f0.w - dx);
|
|
377
|
+
x = f0.x + (f0.w - nw);
|
|
378
|
+
w = nw;
|
|
379
|
+
}
|
|
380
|
+
if (k.includes("n")) {
|
|
381
|
+
const nh = Math.max(MIN_SIZE, f0.h - dy);
|
|
382
|
+
y = f0.y + (f0.h - nh);
|
|
383
|
+
h = nh;
|
|
384
|
+
}
|
|
385
|
+
return { ...f0, x: Math.round(x), y: Math.round(y), w: Math.round(w), h: Math.round(h) };
|
|
386
|
+
}
|
|
387
|
+
function textOf(el) {
|
|
388
|
+
return (el.content?.runs || []).map((r) => r.text ?? "").join("\n");
|
|
389
|
+
}
|
|
390
|
+
function EditorCanvas({
|
|
391
|
+
slide,
|
|
392
|
+
theme,
|
|
393
|
+
resolveSrc,
|
|
394
|
+
selectedId,
|
|
395
|
+
onSelect,
|
|
396
|
+
onPatchElement,
|
|
397
|
+
// (elementId, patch, {transient}) => void
|
|
398
|
+
onDeleteElement,
|
|
399
|
+
// (elementId) => void
|
|
400
|
+
onDragState,
|
|
401
|
+
// (elementId|null, frame|null) live broadcast hook
|
|
402
|
+
peers = [],
|
|
403
|
+
// [{id,name,color,sel:{slideId,elId},drag:{elId,frame}}]
|
|
404
|
+
readOnly = false
|
|
405
|
+
}) {
|
|
406
|
+
const boxRef = useRef3(null);
|
|
407
|
+
const [scale, setScale] = useState3(1);
|
|
408
|
+
const [box, setBox] = useState3({ left: 0, top: 0 });
|
|
409
|
+
const gestureRef = useRef3(null);
|
|
410
|
+
const [liveFrame, setLiveFrame] = useState3(null);
|
|
411
|
+
const [editing, setEditing] = useState3(null);
|
|
412
|
+
useEffect3(() => {
|
|
413
|
+
const el = boxRef.current;
|
|
414
|
+
if (!el) return void 0;
|
|
415
|
+
const fit = () => {
|
|
416
|
+
const r = el.getBoundingClientRect();
|
|
417
|
+
if (r.width && r.height) {
|
|
418
|
+
const s = Math.min(r.width / STAGE_W2, r.height / STAGE_H2);
|
|
419
|
+
setScale(s);
|
|
420
|
+
setBox({ left: (r.width - STAGE_W2 * s) / 2, top: (r.height - STAGE_H2 * s) / 2 });
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
fit();
|
|
424
|
+
const ro = new ResizeObserver(fit);
|
|
425
|
+
ro.observe(el);
|
|
426
|
+
return () => ro.disconnect();
|
|
427
|
+
}, []);
|
|
428
|
+
const toStage = useCallback((e) => {
|
|
429
|
+
const r = boxRef.current.getBoundingClientRect();
|
|
430
|
+
return { x: (e.clientX - r.left - box.left) / scale, y: (e.clientY - r.top - box.top) / scale };
|
|
431
|
+
}, [scale, box]);
|
|
432
|
+
const selected = (slide?.elements || []).find((el) => el.id === selectedId) || null;
|
|
433
|
+
function beginGesture(mode, el, e, handle) {
|
|
434
|
+
if (readOnly) return;
|
|
435
|
+
const p = toStage(e);
|
|
436
|
+
gestureRef.current = { mode, handle, el, f0: { ...el.frame }, sx: p.x, sy: p.y, moved: false };
|
|
437
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
438
|
+
}
|
|
439
|
+
function onLayerPointerDown(e) {
|
|
440
|
+
if (editing) return;
|
|
441
|
+
const p = toStage(e);
|
|
442
|
+
const hit = hitTest(slide, p.x, p.y);
|
|
443
|
+
onSelect?.(hit ? hit.id : null);
|
|
444
|
+
if (hit) beginGesture("move", hit, e);
|
|
445
|
+
}
|
|
446
|
+
function onPointerMove(e) {
|
|
447
|
+
const g = gestureRef.current;
|
|
448
|
+
if (!g) return;
|
|
449
|
+
const p = toStage(e);
|
|
450
|
+
const dx = Math.round(p.x - g.sx);
|
|
451
|
+
const dy = Math.round(p.y - g.sy);
|
|
452
|
+
if (!g.moved && Math.abs(dx) < 3 && Math.abs(dy) < 3) return;
|
|
453
|
+
g.moved = true;
|
|
454
|
+
const f = g.mode === "move" ? {
|
|
455
|
+
...g.f0,
|
|
456
|
+
x: Math.max(-g.f0.w + 40, Math.min(STAGE_W2 - 40, g.f0.x + dx)),
|
|
457
|
+
y: Math.max(-g.f0.h + 40, Math.min(STAGE_H2 - 40, g.f0.y + dy))
|
|
458
|
+
} : resizeFrame(g.f0, g.handle, dx, dy);
|
|
459
|
+
setLiveFrame(f);
|
|
460
|
+
onDragState?.(g.el.id, f);
|
|
461
|
+
}
|
|
462
|
+
function onPointerUp() {
|
|
463
|
+
const g = gestureRef.current;
|
|
464
|
+
gestureRef.current = null;
|
|
465
|
+
onDragState?.(null, null);
|
|
466
|
+
if (g && g.moved && liveFrame) onPatchElement?.(g.el.id, { frame: liveFrame });
|
|
467
|
+
setLiveFrame(null);
|
|
468
|
+
}
|
|
469
|
+
function onDoubleClick(e) {
|
|
470
|
+
if (readOnly) return;
|
|
471
|
+
const p = toStage(e);
|
|
472
|
+
const hit = hitTest(slide, p.x, p.y);
|
|
473
|
+
if (hit && hit.type === "text") {
|
|
474
|
+
onSelect?.(hit.id);
|
|
475
|
+
setEditing({ elId: hit.id, value: textOf(hit) });
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
useEffect3(() => {
|
|
479
|
+
if (readOnly) return void 0;
|
|
480
|
+
const onKey = (e) => {
|
|
481
|
+
const t = e.target;
|
|
482
|
+
if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable)) return;
|
|
483
|
+
if (!selected) return;
|
|
484
|
+
if (e.key === "Backspace" || e.key === "Delete") {
|
|
485
|
+
e.preventDefault();
|
|
486
|
+
onDeleteElement?.(selected.id);
|
|
487
|
+
} else if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
|
|
488
|
+
e.preventDefault();
|
|
489
|
+
const step = e.shiftKey ? 24 : 4;
|
|
490
|
+
const f = { ...selected.frame };
|
|
491
|
+
if (e.key === "ArrowLeft") f.x -= step;
|
|
492
|
+
if (e.key === "ArrowRight") f.x += step;
|
|
493
|
+
if (e.key === "ArrowUp") f.y -= step;
|
|
494
|
+
if (e.key === "ArrowDown") f.y += step;
|
|
495
|
+
onPatchElement?.(selected.id, { frame: f });
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
window.addEventListener("keydown", onKey);
|
|
499
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
500
|
+
}, [selected, readOnly, onPatchElement, onDeleteElement]);
|
|
501
|
+
function commitText() {
|
|
502
|
+
if (!editing) return;
|
|
503
|
+
const el = (slide?.elements || []).find((x) => x.id === editing.elId);
|
|
504
|
+
if (el && editing.value !== textOf(el)) {
|
|
505
|
+
const runs = editing.value.split("\n").map((t) => ({ text: t }));
|
|
506
|
+
onPatchElement?.(el.id, { content: { ...el.content, runs } });
|
|
507
|
+
}
|
|
508
|
+
setEditing(null);
|
|
509
|
+
}
|
|
510
|
+
const displaySlide = liveFrame && gestureRef.current ? {
|
|
511
|
+
...slide,
|
|
512
|
+
elements: (slide.elements || []).map((el) => el.id === gestureRef.current.el.id ? { ...el, frame: liveFrame } : el)
|
|
513
|
+
} : slide;
|
|
514
|
+
const selFrame = liveFrame && gestureRef.current && selected && gestureRef.current.el.id === selected.id ? liveFrame : selected?.frame;
|
|
515
|
+
const editingEl = editing ? (slide?.elements || []).find((x) => x.id === editing.elId) : null;
|
|
516
|
+
return /* @__PURE__ */ jsxs2("div", { ref: boxRef, className: "sl-editor-fit", style: { position: "relative", width: "100%", height: "100%" }, children: [
|
|
517
|
+
/* @__PURE__ */ jsx3("div", { style: {
|
|
518
|
+
position: "absolute",
|
|
519
|
+
left: box.left,
|
|
520
|
+
top: box.top,
|
|
521
|
+
width: STAGE_W2 * scale,
|
|
522
|
+
height: STAGE_H2 * scale,
|
|
523
|
+
boxShadow: "0 8px 40px -8px rgba(15,23,42,.25)",
|
|
524
|
+
borderRadius: 6 * scale,
|
|
525
|
+
overflow: "hidden"
|
|
526
|
+
}, children: /* @__PURE__ */ jsx3("div", { style: { position: "absolute", top: 0, left: 0, transform: `scale(${scale})`, transformOrigin: "top left" }, children: /* @__PURE__ */ jsx3(SlideStage, { slide: displaySlide, theme, resolveSrc }) }) }),
|
|
527
|
+
/* @__PURE__ */ jsxs2(
|
|
528
|
+
"div",
|
|
529
|
+
{
|
|
530
|
+
className: "sl-editor-layer",
|
|
531
|
+
style: {
|
|
532
|
+
position: "absolute",
|
|
533
|
+
left: box.left,
|
|
534
|
+
top: box.top,
|
|
535
|
+
width: STAGE_W2 * scale,
|
|
536
|
+
height: STAGE_H2 * scale,
|
|
537
|
+
touchAction: "none"
|
|
538
|
+
},
|
|
539
|
+
onPointerDown: onLayerPointerDown,
|
|
540
|
+
onPointerMove,
|
|
541
|
+
onPointerUp,
|
|
542
|
+
onDoubleClick,
|
|
543
|
+
children: [
|
|
544
|
+
peers.map((p) => {
|
|
545
|
+
const targetId = p.drag?.elId || p.sel?.elId;
|
|
546
|
+
if (!targetId || p.sel?.slideId !== slide?.id) return null;
|
|
547
|
+
const el = (slide?.elements || []).find((x) => x.id === targetId);
|
|
548
|
+
const f = p.drag?.frame || el?.frame;
|
|
549
|
+
if (!f) return null;
|
|
550
|
+
return /* @__PURE__ */ jsx3("div", { className: "sl-peer-box", style: {
|
|
551
|
+
left: f.x * scale,
|
|
552
|
+
top: f.y * scale,
|
|
553
|
+
width: f.w * scale,
|
|
554
|
+
height: f.h * scale,
|
|
555
|
+
borderColor: p.color
|
|
556
|
+
}, children: /* @__PURE__ */ jsx3("span", { className: "sl-peer-tag", style: { background: p.color }, children: p.name }) }, p.id);
|
|
557
|
+
}),
|
|
558
|
+
selected && selFrame && !editing && /* @__PURE__ */ jsx3("div", { className: "sl-sel-box", style: {
|
|
559
|
+
left: selFrame.x * scale,
|
|
560
|
+
top: selFrame.y * scale,
|
|
561
|
+
width: selFrame.w * scale,
|
|
562
|
+
height: selFrame.h * scale
|
|
563
|
+
}, children: !readOnly && HANDLES.map((h) => /* @__PURE__ */ jsx3(
|
|
564
|
+
"span",
|
|
565
|
+
{
|
|
566
|
+
className: `sl-sel-handle sl-h-${h.k}`,
|
|
567
|
+
onPointerDown: (e) => {
|
|
568
|
+
e.stopPropagation();
|
|
569
|
+
beginGesture("resize", selected, e, h.k);
|
|
570
|
+
}
|
|
571
|
+
},
|
|
572
|
+
h.k
|
|
573
|
+
)) }),
|
|
574
|
+
editingEl && /* @__PURE__ */ jsx3(
|
|
575
|
+
"textarea",
|
|
576
|
+
{
|
|
577
|
+
className: "sl-text-edit",
|
|
578
|
+
autoFocus: true,
|
|
579
|
+
value: editing.value,
|
|
580
|
+
style: {
|
|
581
|
+
left: editingEl.frame.x * scale,
|
|
582
|
+
top: editingEl.frame.y * scale,
|
|
583
|
+
width: editingEl.frame.w * scale,
|
|
584
|
+
height: editingEl.frame.h * scale,
|
|
585
|
+
fontSize: (editingEl.style?.fontSize || { title: 72, subtitle: 36, body: 30, bullets: 30, caption: 22 }[editingEl.content?.role || "body"]) * scale,
|
|
586
|
+
fontFamily: "var(--sl-body, inherit)",
|
|
587
|
+
lineHeight: 1.25,
|
|
588
|
+
textAlign: editingEl.style?.align || "left"
|
|
589
|
+
},
|
|
590
|
+
onChange: (e) => setEditing((v) => ({ ...v, value: e.target.value })),
|
|
591
|
+
onBlur: commitText,
|
|
592
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
593
|
+
onKeyDown: (e) => {
|
|
594
|
+
e.stopPropagation();
|
|
595
|
+
if (e.key === "Escape") setEditing(null);
|
|
596
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) commitText();
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
)
|
|
600
|
+
]
|
|
601
|
+
}
|
|
602
|
+
)
|
|
603
|
+
] });
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// src/slides/Presentation.jsx
|
|
607
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef4, useState as useState4 } from "react";
|
|
608
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
609
|
+
function Presentation({ deck, resolveSrc, startIndex = 0, onExit }) {
|
|
610
|
+
const slides = deck?.slides || [];
|
|
611
|
+
const rootRef = useRef4(null);
|
|
612
|
+
const idleRef = useRef4(null);
|
|
613
|
+
const iRef = useRef4(Math.min(startIndex, Math.max(0, slides.length - 1)));
|
|
614
|
+
const [i, setI] = useState4(iRef.current);
|
|
615
|
+
const [awake, setAwake] = useState4(true);
|
|
616
|
+
const go = useCallback2((n) => {
|
|
617
|
+
const next = Math.max(0, Math.min(slides.length - 1, n));
|
|
618
|
+
iRef.current = next;
|
|
619
|
+
setI(next);
|
|
620
|
+
}, [slides.length]);
|
|
621
|
+
useEffect4(() => {
|
|
622
|
+
const el = rootRef.current;
|
|
623
|
+
el?.requestFullscreen?.().catch(() => {
|
|
624
|
+
});
|
|
625
|
+
const onFsChange = () => {
|
|
626
|
+
if (!document.fullscreenElement) onExit && onExit();
|
|
627
|
+
};
|
|
628
|
+
document.addEventListener("fullscreenchange", onFsChange);
|
|
629
|
+
return () => {
|
|
630
|
+
document.removeEventListener("fullscreenchange", onFsChange);
|
|
631
|
+
if (document.fullscreenElement) document.exitFullscreen?.().catch(() => {
|
|
632
|
+
});
|
|
633
|
+
};
|
|
634
|
+
}, []);
|
|
635
|
+
useEffect4(() => {
|
|
636
|
+
const onKey = (e) => {
|
|
637
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown" || e.key === " " || e.key === "PageDown") {
|
|
638
|
+
e.preventDefault();
|
|
639
|
+
go(iRef.current + 1);
|
|
640
|
+
} else if (e.key === "ArrowLeft" || e.key === "ArrowUp" || e.key === "PageUp") {
|
|
641
|
+
e.preventDefault();
|
|
642
|
+
go(iRef.current - 1);
|
|
643
|
+
} else if (e.key === "Home") go(0);
|
|
644
|
+
else if (e.key === "End") go(slides.length - 1);
|
|
645
|
+
else if (e.key === "Escape") onExit && onExit();
|
|
646
|
+
};
|
|
647
|
+
window.addEventListener("keydown", onKey);
|
|
648
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
649
|
+
}, [go, slides.length, onExit]);
|
|
650
|
+
const wake = useCallback2(() => {
|
|
651
|
+
setAwake(true);
|
|
652
|
+
window.clearTimeout(idleRef.current);
|
|
653
|
+
idleRef.current = window.setTimeout(() => setAwake(false), 2e3);
|
|
654
|
+
}, []);
|
|
655
|
+
useEffect4(() => {
|
|
656
|
+
wake();
|
|
657
|
+
return () => window.clearTimeout(idleRef.current);
|
|
658
|
+
}, [wake]);
|
|
659
|
+
return /* @__PURE__ */ jsxs3(
|
|
660
|
+
"div",
|
|
661
|
+
{
|
|
662
|
+
ref: rootRef,
|
|
663
|
+
className: "sl-present",
|
|
664
|
+
onMouseMove: wake,
|
|
665
|
+
onClick: () => go(iRef.current + 1),
|
|
666
|
+
style: {
|
|
667
|
+
position: "fixed",
|
|
668
|
+
inset: 0,
|
|
669
|
+
zIndex: 1e3,
|
|
670
|
+
background: "#000",
|
|
671
|
+
cursor: awake ? "default" : "none"
|
|
672
|
+
},
|
|
673
|
+
children: [
|
|
674
|
+
/* @__PURE__ */ jsx4(SlideView, { slide: slides[i], theme: deck?.theme, resolveSrc, bare: true }),
|
|
675
|
+
/* @__PURE__ */ jsxs3(
|
|
676
|
+
"div",
|
|
677
|
+
{
|
|
678
|
+
className: "sl-present-pill" + (awake ? " awake" : ""),
|
|
679
|
+
onClick: (e) => e.stopPropagation(),
|
|
680
|
+
children: [
|
|
681
|
+
/* @__PURE__ */ jsx4("button", { className: "sl-pp-btn", "aria-label": "Previous slide", onClick: () => go(i - 1), disabled: i === 0, children: /* @__PURE__ */ jsx4("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx4("path", { d: "M15 18l-6-6 6-6" }) }) }),
|
|
682
|
+
/* @__PURE__ */ jsxs3("span", { className: "sl-pp-count", children: [
|
|
683
|
+
i + 1,
|
|
684
|
+
" / ",
|
|
685
|
+
slides.length
|
|
686
|
+
] }),
|
|
687
|
+
/* @__PURE__ */ jsx4("button", { className: "sl-pp-btn", "aria-label": "Next slide", onClick: () => go(i + 1), disabled: i >= slides.length - 1, children: /* @__PURE__ */ jsx4("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx4("path", { d: "M9 18l6-6-6-6" }) }) }),
|
|
688
|
+
/* @__PURE__ */ jsx4("span", { className: "sl-pp-sep" }),
|
|
689
|
+
/* @__PURE__ */ jsx4("button", { className: "sl-pp-btn", "aria-label": "Exit presentation", onClick: onExit, children: /* @__PURE__ */ jsx4("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", children: /* @__PURE__ */ jsx4("path", { d: "M18 6L6 18M6 6l12 12" }) }) })
|
|
690
|
+
]
|
|
691
|
+
}
|
|
692
|
+
)
|
|
693
|
+
]
|
|
694
|
+
}
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
export {
|
|
698
|
+
EditorCanvas,
|
|
699
|
+
ElementView,
|
|
700
|
+
Presentation,
|
|
701
|
+
SlideStage,
|
|
702
|
+
SlideView,
|
|
703
|
+
themeVars
|
|
704
|
+
};
|
|
705
|
+
//# sourceMappingURL=slides.js.map
|