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