@netnodeag/kraftwerk 0.82.0 → 0.83.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.
Files changed (77) hide show
  1. package/README.md +175 -0
  2. package/dist/cli/init.js +1 -0
  3. package/dist/cli/kraftwerk.js +3 -0
  4. package/dist/cli/presentations.d.ts +2 -0
  5. package/dist/cli/presentations.js +261 -0
  6. package/dist/client/routes.d.ts +18 -0
  7. package/dist/client/routes.js +18 -0
  8. package/dist/config.d.ts +16 -0
  9. package/dist/config.js +10 -2
  10. package/dist/core/boards.d.ts +14 -1
  11. package/dist/core/boards.js +34 -1
  12. package/dist/core/chat/context.js +11 -2
  13. package/dist/core/git.js +3 -1
  14. package/dist/core/presentations/browser.d.ts +43 -0
  15. package/dist/core/presentations/browser.js +53 -0
  16. package/dist/core/presentations/builtin.d.ts +3 -0
  17. package/dist/core/presentations/builtin.js +142 -0
  18. package/dist/core/presentations/chart.d.ts +34 -0
  19. package/dist/core/presentations/chart.js +159 -0
  20. package/dist/core/presentations/deck.d.ts +63 -0
  21. package/dist/core/presentations/deck.js +198 -0
  22. package/dist/core/presentations/export.d.ts +21 -0
  23. package/dist/core/presentations/export.js +75 -0
  24. package/dist/core/presentations/html.d.ts +135 -0
  25. package/dist/core/presentations/html.js +389 -0
  26. package/dist/core/presentations/index.d.ts +252 -0
  27. package/dist/core/presentations/index.js +753 -0
  28. package/dist/core/presentations/layout.d.ts +47 -0
  29. package/dist/core/presentations/layout.js +147 -0
  30. package/dist/core/presentations/markdown.d.ts +49 -0
  31. package/dist/core/presentations/markdown.js +158 -0
  32. package/dist/core/presentations/merge.d.ts +26 -0
  33. package/dist/core/presentations/merge.js +28 -0
  34. package/dist/core/presentations/presence.d.ts +31 -0
  35. package/dist/core/presentations/presence.js +131 -0
  36. package/dist/core/presentations/render.d.ts +33 -0
  37. package/dist/core/presentations/render.js +318 -0
  38. package/dist/core/presentations/slots.d.ts +33 -0
  39. package/dist/core/presentations/slots.js +114 -0
  40. package/dist/core/presentations/template.d.ts +253 -0
  41. package/dist/core/presentations/template.js +141 -0
  42. package/dist/core/presentations/versions.d.ts +30 -0
  43. package/dist/core/presentations/versions.js +75 -0
  44. package/dist/core/refs.d.ts +1 -1
  45. package/dist/core/refs.js +9 -1
  46. package/dist/core/search.d.ts +10 -0
  47. package/dist/core/search.js +6 -0
  48. package/dist/core/settings.d.ts +2 -0
  49. package/dist/core/settings.js +12 -1
  50. package/dist/core/trash.d.ts +1 -1
  51. package/dist/server/api/index.d.ts +62 -1
  52. package/dist/server/api/index.js +2 -0
  53. package/dist/server/api/presentations.d.ts +66 -0
  54. package/dist/server/api/presentations.js +185 -0
  55. package/dist/server/api/socket.js +24 -1
  56. package/dist/server/api/workspace.d.ts +5 -0
  57. package/dist/server/api/workspace.js +2 -0
  58. package/package.json +6 -2
  59. package/schema/kraftwerk.schema.json +18 -0
  60. package/web/dist/assets/{dist-DvkrCSGL.js → dist-5-ibIscm.js} +1 -1
  61. package/web/dist/assets/{dist-Bie1ebP9.js → dist-5lgY5B-M.js} +1 -1
  62. package/web/dist/assets/{dist-BuwdjX6z.js → dist-BJaPgnhj.js} +1 -1
  63. package/web/dist/assets/{dist-C_rJjRj7.js → dist-Bar1_NBq.js} +1 -1
  64. package/web/dist/assets/{dist-DtUB2Uu2.js → dist-BxCxboU8.js} +1 -1
  65. package/web/dist/assets/dist-CDitSY16.js +1 -0
  66. package/web/dist/assets/{dist-C16bXf8c.js → dist-CRXT8IL6.js} +1 -1
  67. package/web/dist/assets/{dist-CH73jsgO.js → dist-CXRjiHpl.js} +1 -1
  68. package/web/dist/assets/{dist-BBFUIftm.js → dist-CpnB7MfK.js} +1 -1
  69. package/web/dist/assets/{dist-C0ve4Tka.js → dist-D1VK1YdB.js} +1 -1
  70. package/web/dist/assets/{dist-CDUZdAAS.js → dist-D52LvyO8.js} +1 -1
  71. package/web/dist/assets/{editor-3z92i0tV.js → editor-HCNTXWWs.js} +3 -3
  72. package/web/dist/assets/index-Dnlu16AL.css +2 -0
  73. package/web/dist/assets/index-kwWnQOhD.js +473 -0
  74. package/web/dist/index.html +2 -2
  75. package/web/dist/assets/dist-DYICNp09.js +0 -1
  76. package/web/dist/assets/index-DRhNELK_.js +0 -232
  77. package/web/dist/assets/index-unGEux3Y.css +0 -2
@@ -0,0 +1,389 @@
1
+ import { Marked } from "marked";
2
+ import { chartPalette, chartSvg, parseChart } from "./chart.js";
3
+ import { defaultSlotOf, layoutFor, PPI, resolveColor, slideSlots, STAGE_W } from "./layout.js";
4
+ import { DEFAULT_SLOT, getSlot, slotsOf, splitDefault } from "./slots.js";
5
+ /** How a slide comes in when presented: fade (the default), slide in from the right, zoom in, or cut (none). */
6
+ export const TRANSITIONS = ["fade", "slide", "zoom", "none"];
7
+ export const transitionOf = (value) => (TRANSITIONS.includes(value ?? "") ? value : "fade");
8
+ const esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
9
+ /**
10
+ * A picture a slot's own HTML names (`src="assets/shot.png"`, `url(assets/bg.jpg)`)
11
+ * through the caller's `asset()`, the same way a markdown image goes — so hand-written
12
+ * HTML shows its pictures in the editor, the thumbnails and the exports alike.
13
+ * Absolute URLs, data URLs and anything already resolved stay as they are.
14
+ */
15
+ const htmlAssets = (html, asset) => html.replace(/(?<![\w-])(src=["']|url\(["']?)((?!https?:|data:|blob:|#|\/)[^"')\s]+)/g, (m, lead, rel) => lead + asset(rel));
16
+ export const stageHeight = (size) => (size === "4:3" ? 1200 : 900);
17
+ /** A slot's font size in points as stage px. */
18
+ export const ptToPx = (pt) => Math.round((pt / 72) * PPI * 100) / 100;
19
+ function markedFor(t, opts, slotPx) {
20
+ const m = new Marked({ gfm: true, breaks: false });
21
+ m.use({
22
+ renderer: {
23
+ code(token) {
24
+ if ((token.lang ?? "").trim().toLowerCase() === "chart") {
25
+ try {
26
+ const { w, h, size } = slotPx();
27
+ return chartSvg(parseChart(token.text), w, h, look(t, size));
28
+ }
29
+ catch (err) {
30
+ return `<p class="deck-error">chart: ${esc(err.message)}</p>`;
31
+ }
32
+ }
33
+ return `<pre><code>${esc(token.text)}</code></pre>`;
34
+ },
35
+ image(token) {
36
+ return `<img src="${esc(opts.asset(token.href))}" data-src="${esc(token.href)}" alt="${esc(token.text ?? "")}"${token.title ? ` title="${esc(token.title)}"` : ""}>`;
37
+ },
38
+ },
39
+ });
40
+ return m;
41
+ }
42
+ const look = (t, sizePt) => ({
43
+ palette: chartPalette(t.colors.accent),
44
+ text: t.colors.text ?? "#161310",
45
+ muted: t.colors.muted ?? "#6F6D67",
46
+ line: t.colors.line ?? "#E1E0D9",
47
+ fontSize: ptToPx(sizePt),
48
+ });
49
+ /** Every slot of a slide with its content and look; problems name what the slide asks for and the layout cannot give. */
50
+ export function slideView(slide, t, opts) {
51
+ const width = STAGE_W;
52
+ const height = stageHeight(t.size);
53
+ const problems = [];
54
+ const found = layoutFor(t, slide.layout) ?? layoutFor(t, undefined);
55
+ const hidden = slide.extra?.hidden === true;
56
+ const numbered = opts.numbers !== false && slide.extra?.number !== false;
57
+ const transition = transitionOf(slide.transition);
58
+ if (slide.transition && transitionOf(slide.transition) !== slide.transition)
59
+ problems.push(`transition "${slide.transition}" is not one of ${TRANSITIONS.join(", ")}; fading`);
60
+ if (!found)
61
+ return { layout: "", transition, background: t.colors.background ?? "#fff", hidden, numbered, shapes: [], slots: [], problems: ["the template has no layouts"], width, height };
62
+ if (slide.layout && found.name !== slide.layout)
63
+ problems.push(`unknown layout "${slide.layout}", using "${found.name}"`);
64
+ const own = slideSlots(found.layout, slide.extra?.slots);
65
+ problems.push(...own.problems);
66
+ const dflt = defaultSlotOf(found.layout);
67
+ const named = slotsOf(slide.content);
68
+ for (const name of Object.keys(named))
69
+ if (name !== DEFAULT_SLOT && !own.slots[name])
70
+ problems.push(`layout has no slot "${name}"`);
71
+ if (!dflt && splitDefault(named[DEFAULT_SLOT]).rest)
72
+ problems.push("unmarked content has no slot to go to");
73
+ const color = (v, fallback) => resolveColor(t, v) ?? fallback;
74
+ // A picture as background: a path or URL (assets/hero.jpg), drawn to cover the slide.
75
+ const bg = slide.background?.trim();
76
+ const background = bg && /\.(png|jpe?g|gif|webp|svg|avif)(\?.*)?$/i.test(bg) ? `url("${opts.asset(bg)}") center / cover no-repeat` : color(bg ?? found.layout.background ?? "background", "#FFFFFF");
77
+ const shapes = (found.layout.shapes ?? []).map((s) => ({ x: s.x, y: s.y, w: s.w, h: s.h, fill: color(s.fill ?? s.color ?? "accent", "#000000") }));
78
+ const slots = Object.entries(own.slots).map(([name, def]) => {
79
+ const md = getSlot(slide.content, name, dflt);
80
+ const d = def;
81
+ const view = {
82
+ name,
83
+ kind: d.kind,
84
+ x: d.x,
85
+ y: d.y,
86
+ w: d.w,
87
+ h: d.h,
88
+ ...(d.size ? { size: d.size } : {}),
89
+ ...(d.bold ? { bold: true } : {}),
90
+ ...(d.italic ? { italic: true } : {}),
91
+ ...(d.color ? { color: d.color } : {}),
92
+ ...(d.font ? { font: d.font } : {}),
93
+ ...(d.align ? { align: d.align } : {}),
94
+ ...(d.valign ? { valign: d.valign } : {}),
95
+ ...(d.fill ? { fill: d.fill } : {}),
96
+ ...(d.class ? { class: d.class } : {}),
97
+ ...(d.underline ? { underline: true } : {}),
98
+ ...(d.strike ? { strike: true } : {}),
99
+ ...(typeof d.rotate === "number" && d.rotate ? { rotate: d.rotate } : {}),
100
+ ...(typeof d.radius === "number" ? { radius: d.radius } : {}),
101
+ ...(typeof d.border === "number" ? { border: d.border } : {}),
102
+ ...(d.borderColor ? { borderColor: d.borderColor } : {}),
103
+ ...(d.shadow ? { shadow: true } : {}),
104
+ ...(typeof d.opacity === "number" && d.opacity < 1 ? { opacity: d.opacity } : {}),
105
+ ...(typeof d.z === "number" ? { z: d.z } : {}),
106
+ ...(d.fit ? { fit: d.fit } : {}),
107
+ ...(d.required ? { required: true } : {}),
108
+ ...(d.placeholder ? { placeholder: d.placeholder } : {}),
109
+ ...(d.own ? { own: true } : {}),
110
+ ...(d.changed ? { changed: true } : {}),
111
+ ...(md !== undefined ? { md } : {}),
112
+ html: "",
113
+ };
114
+ if (md === undefined || md.trim() === "")
115
+ return view;
116
+ const px = { w: d.w * PPI - 32, h: d.h * PPI - 16, size: d.size ?? 14 };
117
+ const m = markedFor(t, opts, () => px);
118
+ try {
119
+ switch (d.kind) {
120
+ case "text":
121
+ view.html = m.parseInline(md.replace(/\s*\n\s*/g, " "), { async: false });
122
+ break;
123
+ case "image": {
124
+ const img = /!\[([^\]]*)\]\(([^)\s]+)(?:\s+"[^"]*")?\)/.exec(md);
125
+ const src = img ? img[2] : md.trim();
126
+ view.html = `<img src="${esc(opts.asset(src))}" data-src="${esc(src)}" alt="${esc(img?.[1] ?? "")}">`;
127
+ break;
128
+ }
129
+ case "chart":
130
+ view.html = chartSvg(parseChart(md), px.w, px.h, look(t, px.size));
131
+ break;
132
+ case "html":
133
+ view.html = htmlAssets(md, opts.asset);
134
+ break;
135
+ case "embed": {
136
+ const v = md.trim();
137
+ view.embed = /^https?:\/\/\S+$/i.test(v) ? { src: v } : { srcdoc: v };
138
+ break;
139
+ }
140
+ default:
141
+ view.html = htmlAssets(m.parse(md, { async: false }), opts.asset);
142
+ }
143
+ }
144
+ catch (err) {
145
+ view.error = err.message;
146
+ view.html = `<p class="deck-error">${esc(view.error)}</p>`;
147
+ }
148
+ return view;
149
+ });
150
+ return { layout: found.name, transition, background, hidden, numbered, shapes, slots, problems, width, height };
151
+ }
152
+ /** A slot's own CSS: its box in stage px and how its text looks. */
153
+ export function slotStyle(s, t) {
154
+ const st = {
155
+ left: `${px(s.x)}px`,
156
+ top: `${px(s.y)}px`,
157
+ width: `${px(s.w)}px`,
158
+ height: `${px(s.h)}px`,
159
+ };
160
+ if (s.size)
161
+ st["font-size"] = `${ptToPx(s.size)}px`;
162
+ if (s.bold)
163
+ st["font-weight"] = "700";
164
+ if (s.italic)
165
+ st["font-style"] = "italic";
166
+ if (s.color)
167
+ st.color = resolveColor(t, s.color) ?? s.color;
168
+ if (s.font)
169
+ st["font-family"] = s.font === "heading" ? "var(--font-heading)" : s.font === "body" ? "var(--font-body)" : `"${s.font}", var(--font-body)`;
170
+ if (s.align)
171
+ st["text-align"] = s.align;
172
+ if (s.fill)
173
+ st.background = resolveColor(t, s.fill) ?? s.fill;
174
+ const deco = [s.underline && "underline", s.strike && "line-through"].filter(Boolean).join(" ");
175
+ if (deco)
176
+ st["text-decoration"] = deco;
177
+ if (s.rotate)
178
+ st.transform = `rotate(${s.rotate}deg)`;
179
+ if (s.radius)
180
+ st["border-radius"] = `${ptToPx(s.radius)}px`;
181
+ if (s.border)
182
+ st.border = `${ptToPx(s.border)}px solid ${resolveColor(t, s.borderColor ?? "text") ?? s.borderColor ?? "currentColor"}`;
183
+ if (s.shadow)
184
+ st["box-shadow"] = "0 10px 30px rgb(0 0 0 / 0.18)";
185
+ if (typeof s.opacity === "number" && s.opacity < 1)
186
+ st.opacity = String(s.opacity);
187
+ if (typeof s.z === "number")
188
+ st["z-index"] = String(Math.round(s.z));
189
+ if (s.radius || s.border)
190
+ st.overflow = "hidden";
191
+ return st;
192
+ }
193
+ /** Inches as stage px, two decimals. */
194
+ const px = (inches) => Math.round(inches * PPI * 100) / 100;
195
+ const fontStack = (f) => `${/^[\w -]+$/.test(f) && !/^(system-ui|sans-serif|serif|monospace)$/.test(f) ? `"${f}"` : f}, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif`;
196
+ /** Rules that must not sit inside a nested rule: fonts, imports, keyframes, properties. */
197
+ const HOIST = /^@(font-face|import|charset|keyframes|-webkit-keyframes|property|namespace|layer\s*[\w.,\s]*;)/i;
198
+ /** Split CSS into its top-level statements (a rule with its block, or an at-rule ending in `;`). */
199
+ function topLevel(css) {
200
+ const out = [];
201
+ let depth = 0;
202
+ let start = 0;
203
+ let quote = null;
204
+ const clean = css.replace(/\/\*[\s\S]*?\*\//g, "");
205
+ for (let i = 0; i < clean.length; i++) {
206
+ const ch = clean[i];
207
+ if (quote) {
208
+ if (ch === "\\")
209
+ i++;
210
+ else if (ch === quote)
211
+ quote = null;
212
+ continue;
213
+ }
214
+ if (ch === '"' || ch === "'")
215
+ quote = ch;
216
+ else if (ch === "{")
217
+ depth++;
218
+ else if (ch === "}") {
219
+ depth--;
220
+ if (depth === 0) {
221
+ out.push(clean.slice(start, i + 1).trim());
222
+ start = i + 1;
223
+ }
224
+ }
225
+ else if (ch === ";" && depth === 0) {
226
+ out.push(clean.slice(start, i + 1).trim());
227
+ start = i + 1;
228
+ }
229
+ }
230
+ const rest = clean.slice(start).trim();
231
+ if (rest)
232
+ out.push(rest);
233
+ return out.filter(Boolean);
234
+ }
235
+ /** `:root`, `html` and `body` in selectors mean the slide once nested. */
236
+ const rescope = (rule) => rule.replace(/(^|[{};])([^{};@]*)(?=\{)/g, (_m, lead, prelude) => lead + prelude.replace(/(^|[\s,>+~(])(:root|html|body)(?=$|[\s,.:#[>+~)])/g, "$1&"));
237
+ /**
238
+ * The CSS of a deck's slides: the base (boxes, type, lists, tables), the
239
+ * template's colors and fonts as variables, the theme scoped to
240
+ * `.deck-theme-<slug>`, then the deck's own CSS scoped to its slides.
241
+ */
242
+ export function stageCss(t, deckCss = "") {
243
+ const scope = `.deck-theme-${t.slug}`;
244
+ const vars = Object.entries(t.colors)
245
+ .map(([k, v]) => `--c-${k}: ${v};`)
246
+ .join(" ");
247
+ const hoisted = [];
248
+ const nest = (css) => topLevel(css)
249
+ .filter((st) => {
250
+ if (HOIST.test(st)) {
251
+ hoisted.push(st);
252
+ return false;
253
+ }
254
+ return true;
255
+ })
256
+ .map(rescope)
257
+ .join("\n");
258
+ const theme = nest(t.css);
259
+ const deck = nest(deckCss);
260
+ return [
261
+ ...hoisted,
262
+ BASE_CSS,
263
+ `${scope} { ${vars} --font-heading: ${fontStack(t.fonts.heading)}; --font-body: ${fontStack(t.fonts.body)}; }`,
264
+ theme.trim() ? `${scope} {\n${theme}\n}` : "",
265
+ deck.trim() ? `${scope}.deck-slide {\n${deck}\n}` : "",
266
+ ]
267
+ .filter(Boolean)
268
+ .join("\n");
269
+ }
270
+ /** What every slide gets, whatever the theme; `:where()` keeps it weaker than any theme rule. */
271
+ export const BASE_CSS = `
272
+ .deck-slide { position: relative; overflow: hidden; isolation: isolate; color: var(--c-text); font-family: var(--font-body); font-size: 28px; line-height: 1.3; text-align: left; letter-spacing: normal; -webkit-font-smoothing: antialiased; }
273
+ .deck-slide :where(*, *::before, *::after) { box-sizing: border-box; }
274
+ .deck-slide .deck-slot { position: absolute; display: flex; flex-direction: column; min-width: 0; padding: 8px 16px; overflow-wrap: break-word; }
275
+ .deck-slide .deck-slot[data-valign="middle"] { justify-content: center; }
276
+ .deck-slide .deck-slot[data-valign="bottom"] { justify-content: flex-end; }
277
+ .deck-slide .deck-content { min-height: 0; outline: none; }
278
+ .deck-slide .deck-shape { position: absolute; }
279
+ .deck-slide :where(h1, h2, h3, h4, h5, h6) { font-family: var(--font-heading); font-weight: 700; line-height: 1.1; letter-spacing: -0.015em; margin: 0; font-size: 1.15em; }
280
+ .deck-slide :where(p, ul, ol, blockquote, figure, table, pre, dl) { margin: 0; }
281
+ .deck-slide :where(p, ul, ol, table, pre, blockquote, figure, div, h1, h2, h3, h4) + :where(p, ul, ol, table, pre, blockquote, figure, h1, h2, h3, h4) { margin-top: 0.5em; }
282
+ .deck-slide :where(ul, ol) { padding-left: 1.15em; }
283
+ .deck-slide :where(ul) { list-style: disc; }
284
+ .deck-slide :where(ol) { list-style: decimal; }
285
+ .deck-slide :where(ul ul) { list-style: circle; }
286
+ .deck-slide :where(li + li) { margin-top: 0.25em; }
287
+ .deck-slide :where(li)::marker { color: var(--c-accent); }
288
+ .deck-slide :where(strong, b) { font-weight: 700; }
289
+ .deck-slide :where(em, i) { font-style: italic; }
290
+ .deck-slide :where(a) { color: var(--c-accent); text-decoration: underline; text-underline-offset: 0.12em; }
291
+ .deck-slide :where(code) { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.9em; color: var(--c-accent); }
292
+ .deck-slide :where(pre) { font-size: 0.7em; line-height: 1.4; background: var(--c-surface); border: 1px solid var(--c-line); padding: 0.6em 0.8em; border-radius: 0.3em; white-space: pre-wrap; }
293
+ .deck-slide :where(pre code) { color: inherit; font-size: 1em; }
294
+ .deck-slide :where(blockquote) { border-left: 4px solid var(--c-accent); padding-left: 0.8em; color: var(--c-muted); }
295
+ .deck-slide :where(img, svg, video) { max-width: 100%; }
296
+ .deck-slide :where(table) { border-collapse: collapse; width: 100%; font-size: 0.95em; }
297
+ .deck-slide :where(th, td) { padding: 0.45em 0.65em; border-bottom: 1px solid var(--c-line); text-align: left; vertical-align: top; }
298
+ .deck-slide :where(th) { font-weight: 700; border-bottom: 2px solid var(--c-text); }
299
+ .deck-slide .kind-image .deck-content, .deck-slide .kind-chart .deck-content, .deck-slide .kind-embed .deck-content { flex: 1; display: flex; align-items: center; justify-content: center; }
300
+ .deck-slide .kind-image img { width: 100%; height: 100%; object-fit: contain; display: block; }
301
+ .deck-slide .kind-image[data-fit="cover"] img { object-fit: cover; }
302
+ .deck-slide .kind-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
303
+ .deck-slide .kind-embed iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
304
+ .deck-slide .kind-image, .deck-slide .kind-chart, .deck-slide .kind-embed { padding: 0; }
305
+ .deck-slide .deck-error { color: #B91C1C; font-size: 0.6em; font-family: ui-monospace, Menlo, monospace; }
306
+ `;
307
+ const attrs = (o) => Object.entries(o).map(([k, v]) => `${k}: ${v}`).join("; ");
308
+ /** One slide as an HTML string (the export's, the print's and the CLI's form of what the editor shows). */
309
+ export function slideHtml(v, t, extraClass = "", number) {
310
+ const shapes = v.shapes.map((s) => `<div class="deck-shape" style="left:${s.x * PPI}px;top:${s.y * PPI}px;width:${s.w * PPI}px;height:${s.h * PPI}px;background:${s.fill}"></div>`).join("");
311
+ const slots = v.slots
312
+ .filter((s) => s.html || s.embed)
313
+ .map((s) => {
314
+ const inner = s.embed ? `<iframe ${s.embed.src ? `src="${esc(s.embed.src)}"` : `srcdoc="${esc(s.embed.srcdoc ?? "")}"`} sandbox="allow-scripts allow-popups allow-forms" loading="lazy"></iframe>` : s.html;
315
+ return `<div class="deck-slot kind-${s.kind} slot-${s.name}${s.class ? ` ${esc(s.class)}` : ""}" data-slot="${s.name}"${s.valign ? ` data-valign="${s.valign}"` : ""}${s.fit ? ` data-fit="${s.fit}"` : ""} style="${attrs(slotStyle(s, t))}"><div class="deck-content">${inner}</div></div>`;
316
+ })
317
+ .join("");
318
+ return `<section class="deck-slide deck-theme-${t.slug} layout-${v.layout}${extraClass ? ` ${extraClass}` : ""}"${number && v.numbered ? ` data-n="${number.n}" data-nn="${String(number.n).padStart(2, "0")}" data-of="${number.of}"` : ""} data-transition="${v.transition}" style="width:${v.width}px;height:${v.height}px;background:${v.background}">${shapes}${slots}</section>`;
319
+ }
320
+ /**
321
+ * The deck as one HTML file: every slide, the theme, arrows and space to
322
+ * step through, F for full screen, P to print (a PDF, one slide a page).
323
+ * The caller inlines the pictures and fonts (`asset` returning data URLs,
324
+ * the theme's URLs rewritten) so the file stands alone.
325
+ */
326
+ export function standaloneHtml(deck, t, opts) {
327
+ // Hidden slides stay in the file, not in the deck shown.
328
+ const views = deck.slides.map((s) => slideView(s, t, { ...opts, ...(deck.numbers === false ? { numbers: false } : {}) })).filter((v) => !v.hidden);
329
+ const h = stageHeight(t.size);
330
+ return `<!doctype html>
331
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
332
+ <title>${esc(deck.title)}</title>
333
+ <style>
334
+ ${stageCss(t, deck.css ?? "")}
335
+ html, body { margin: 0; height: 100%; background: #111; }
336
+ .deck-viewport { position: fixed; inset: 0; display: grid; place-items: center; overflow: hidden; }
337
+ .deck-viewport .deck-slide { position: absolute; left: 50%; top: 50%; transform-origin: 0 0; display: none; }
338
+ .deck-viewport .deck-slide.is-current { display: block; }
339
+ .deck-viewport .deck-slide.is-current[data-transition="fade"] { animation: deck-in-fade 300ms ease-out; }
340
+ .deck-viewport .deck-slide.is-current[data-transition="slide"] { animation: deck-in-slide 420ms cubic-bezier(.2,.7,.2,1); }
341
+ .deck-viewport .deck-slide.is-current[data-transition="zoom"] { animation: deck-in-zoom 380ms cubic-bezier(.2,.7,.2,1); }
342
+ @keyframes deck-in-fade { from { opacity: 0; } }
343
+ @keyframes deck-in-slide { from { opacity: 0; translate: 8% 0; } }
344
+ @keyframes deck-in-zoom { from { opacity: 0; scale: .92; } }
345
+ @media (prefers-reduced-motion: reduce) { .deck-viewport .deck-slide.is-current { animation: none !important; } }
346
+ .deck-counter { position: fixed; right: 16px; bottom: 10px; font: 12px system-ui, sans-serif; color: #999; }
347
+ @page { size: ${STAGE_W}px ${h}px; margin: 0; }
348
+ @media print {
349
+ html, body { height: auto; background: none; }
350
+ .deck-viewport { position: static; display: block; }
351
+ .deck-viewport .deck-slide { position: relative; left: 0; top: 0; display: block !important; transform: none !important; break-after: page; }
352
+ .deck-counter { display: none; }
353
+ }
354
+ </style></head>
355
+ <body>
356
+ <main class="deck-viewport">
357
+ ${views.map((v, i) => slideHtml(v, t, i === 0 ? "is-current" : "", { n: i + 1, of: views.length })).join("\n")}
358
+ </main>
359
+ <div class="deck-counter"></div>
360
+ <script>
361
+ (() => {
362
+ const slides = [...document.querySelectorAll(".deck-slide")];
363
+ let i = Math.max(0, Math.min(slides.length - 1, (parseInt(location.hash.slice(1), 10) || 1) - 1));
364
+ const fit = () => {
365
+ const s = Math.min(innerWidth / ${STAGE_W}, innerHeight / ${h});
366
+ for (const el of slides) el.style.transform = "scale(" + s + ") translate(-50%, -50%)";
367
+ };
368
+ const show = (n) => {
369
+ i = Math.max(0, Math.min(slides.length - 1, n));
370
+ slides.forEach((el, k) => el.classList.toggle("is-current", k === i));
371
+ document.querySelector(".deck-counter").textContent = (i + 1) + " / " + slides.length;
372
+ history.replaceState(null, "", "#" + (i + 1));
373
+ };
374
+ addEventListener("resize", fit);
375
+ addEventListener("keydown", (e) => {
376
+ if (["ArrowRight", " ", "PageDown", "Enter"].includes(e.key)) { e.preventDefault(); show(i + 1); }
377
+ else if (["ArrowLeft", "PageUp", "Backspace"].includes(e.key)) { e.preventDefault(); show(i - 1); }
378
+ else if (e.key === "Home") show(0);
379
+ else if (e.key === "End") show(slides.length - 1);
380
+ else if (e.key === "f" || e.key === "F") document.documentElement.requestFullscreen?.();
381
+ else if (e.key === "p" || e.key === "P") print();
382
+ });
383
+ addEventListener("click", (e) => { if (!e.target.closest("a, iframe")) show(e.clientX > innerWidth / 3 ? i + 1 : i - 1); });
384
+ fit(); show(i);
385
+ })();
386
+ </script>
387
+ </body></html>
388
+ `;
389
+ }
@@ -0,0 +1,252 @@
1
+ import { type ResolvedWorkspace } from "../../config.js";
2
+ import { type DeckDoc, type SlideDef } from "./deck.js";
3
+ import { type DeckVersion } from "./versions.js";
4
+ import { type RenderWarning, type Rendered } from "./render.js";
5
+ import { type StageTemplate } from "./html.js";
6
+ import type { Readable } from "node:stream";
7
+ import { type SlotKind, type Template, type TemplateSummary } from "./template.js";
8
+ export { parseDeck, serializeDeck, type DeckDoc, type SlideDef } from "./deck.js";
9
+ export { slotsOf, joinSlots, getSlot, setSlot, DEFAULT_SLOT } from "./slots.js";
10
+ export { parseMarkdown, type Block, type Run } from "./markdown.js";
11
+ export { renderDeck, type RenderWarning } from "./render.js";
12
+ export { DEFAULT_TEMPLATE, parseTemplate, defaultTemplateYaml, CANVAS, type Template, type TemplateSummary, type LayoutDef, type SlotDef } from "./template.js";
13
+ export { PPTX_MIME, toPdf, toPptx } from "./export.js";
14
+ export { slideView, stageCss, slideHtml, standaloneHtml, type StageTemplate, type SlideView, type SlotView } from "./html.js";
15
+ /**
16
+ * Presentations: slide decks as folders, one per deck — deck.md (the
17
+ * slides, Slidev-style markdown), assets/ (pictures), exports/ (what
18
+ * `render` wrote). A project's decks live in projects/<p>/presentations/,
19
+ * the workspace's under the presentations root; templates under
20
+ * <root>/templates/<slug>/template.yml (+ theme.css, fonts, pictures).
21
+ * Slides are HTML (html.ts): the editor, present mode, the thumbnails, the
22
+ * HTML file and — through a headless browser (browser.ts) — the PNGs and
23
+ * the PDF are all the same render. The PowerPoint file is a native model
24
+ * of the same slots (render.ts), its HTML pieces drawn as pictures.
25
+ * Agents write deck.md and look at `render --png`.
26
+ */
27
+ export declare const DECK_FILE = "deck.md";
28
+ export declare const ASSETS_DIR = "assets";
29
+ export declare const EXPORTS_DIR = "exports";
30
+ export declare const COMMENTS_FILE = "comments.json";
31
+ export interface PresentationRef {
32
+ project?: string;
33
+ name: string;
34
+ }
35
+ export interface PresentationSummary extends PresentationRef {
36
+ title: string;
37
+ template: string;
38
+ slides: number;
39
+ path: string;
40
+ updatedAt?: string;
41
+ /** Set when deck.md cannot be parsed; the editor shows the raw file. */
42
+ error?: string;
43
+ }
44
+ export interface LayoutInfo {
45
+ name: string;
46
+ description?: string;
47
+ /** The slot the unmarked content after the heading goes to. */
48
+ default?: string;
49
+ /** Position and size in inches on the canvas, for the editor's inline fields. */
50
+ slots: SlotInfo[];
51
+ }
52
+ export interface SlotInfo {
53
+ name: string;
54
+ kind: SlotKind;
55
+ x: number;
56
+ y: number;
57
+ w: number;
58
+ h: number;
59
+ /** Text look, as the layout sets it (the editor's toolbar starts from these). */
60
+ size?: number;
61
+ bold?: boolean;
62
+ italic?: boolean;
63
+ align?: "left" | "center" | "right";
64
+ valign?: "top" | "middle" | "bottom";
65
+ color?: string;
66
+ required?: boolean;
67
+ placeholder?: string;
68
+ }
69
+ export interface PresentationDetail extends PresentationSummary {
70
+ deck: DeckDoc;
71
+ /** deck.md as it is on disk. */
72
+ source: string;
73
+ warnings: RenderWarning[];
74
+ /** The deck's template with its layouts, for the editor's picker. */
75
+ layouts: LayoutInfo[];
76
+ /** The canvas in inches (the slot positions' frame). */
77
+ canvas: {
78
+ w: number;
79
+ h: number;
80
+ };
81
+ /** The template's named colors as #RRGGBB, for the editor's swatches. */
82
+ colors: Record<string, string>;
83
+ /** The template as the HTML renderer needs it; `{{base}}` in its CSS stands for the API's base URL. */
84
+ theme: StageTemplate;
85
+ /** Every usable template the same way, for the design picker's previews. */
86
+ themes: StageTemplate[];
87
+ templates: TemplateSummary[];
88
+ /** Files under assets/, relative to the deck folder. */
89
+ assets: string[];
90
+ /** What exports/ holds. */
91
+ exports: string[];
92
+ /** Comments on slides and boxes, oldest first (comments.json in the folder). */
93
+ comments: DeckComment[];
94
+ }
95
+ export interface DeckComment {
96
+ id: string;
97
+ /** The slide's id (`id:` in its YAML head, given when the first comment lands), and its number when listed. */
98
+ slide: string;
99
+ n?: number;
100
+ /** The box it is about, when it is about one. */
101
+ slot?: string;
102
+ author: string;
103
+ text: string;
104
+ at: string;
105
+ resolved?: boolean;
106
+ replies: {
107
+ author: string;
108
+ text: string;
109
+ at: string;
110
+ }[];
111
+ }
112
+ export interface PresentationsView {
113
+ enabled: boolean;
114
+ root?: string;
115
+ presentations: PresentationSummary[];
116
+ error?: string;
117
+ }
118
+ export declare function openPresentations(): Promise<{
119
+ project?: ResolvedWorkspace;
120
+ root?: string;
121
+ off?: boolean;
122
+ error?: string;
123
+ }>;
124
+ /** Make sure the workspace presentations root exists; runs when the feature is switched on. */
125
+ export declare function ensurePresentationsRoot(): Promise<void>;
126
+ export declare function safeDeckSlug(slug: string): string;
127
+ /** The folder a deck lives in: inside its project (projects must be on) or under the workspace root. */
128
+ export declare function deckDir(ref: PresentationRef): Promise<string>;
129
+ /** The folder of a deck that exists (its deck.md is there); throws "no presentation …" otherwise. */
130
+ export declare function existingDeckDir(ref: PresentationRef): Promise<string>;
131
+ /** "<project>/<name>" or "<name>". */
132
+ export declare const deckKey: (ref: PresentationRef) => string;
133
+ export declare function parseDeckRef(text: string): PresentationRef;
134
+ export declare function listTemplates(): Promise<TemplateSummary[]>;
135
+ /** A template with its theme CSS whose relative URLs (fonts, pictures) point where `fileUrl` says. */
136
+ export declare function stageTemplateOf(t: Template, fileUrl: (rel: string) => string): StageTemplate;
137
+ export declare const mimeOf: (file: string) => string;
138
+ /** A file of a workspace template (its fonts, its logo); the built-in one has none. */
139
+ export declare function templateFile(slug: string, rel: string): Promise<{
140
+ path: string;
141
+ mime: string;
142
+ } | null>;
143
+ /** A file of a deck (its pictures under assets/); deck.md and exports are reached otherwise. */
144
+ export declare function deckFile(ref: PresentationRef, rel: string): Promise<{
145
+ path: string;
146
+ mime: string;
147
+ } | null>;
148
+ /** Write the built-in template as a workspace template to edit. */
149
+ export declare function initTemplate(slug: string): Promise<string>;
150
+ /** The decks of a project, or the workspace decks when no project is given. */
151
+ export declare function listDecks(project?: string): Promise<PresentationsView>;
152
+ /** Every deck of the workspace: the workspace ones first, then each project's. */
153
+ export declare function listAllDecks(): Promise<PresentationSummary[]>;
154
+ /** A comment on slide `n` (1-based), on one of its boxes when `slot` is given. The slide gets an id the first time. */
155
+ export declare function addComment(ref: PresentationRef, input: {
156
+ slide: number;
157
+ slot?: string;
158
+ text: string;
159
+ author: string;
160
+ }): Promise<DeckComment>;
161
+ /** Resolve or reopen a comment, or answer it. */
162
+ export declare function updateComment(ref: PresentationRef, id: string, input: {
163
+ resolved?: boolean;
164
+ reply?: string;
165
+ author: string;
166
+ }): Promise<DeckComment>;
167
+ export declare function deleteComment(ref: PresentationRef, id: string): Promise<void>;
168
+ /** The deck's earlier versions, newest first. */
169
+ export declare function deckVersions(ref: PresentationRef): Promise<DeckVersion[]>;
170
+ export declare function deckVersion(ref: PresentationRef, id: string): Promise<{
171
+ id: string;
172
+ at: string;
173
+ source: string;
174
+ deck: DeckDoc;
175
+ }>;
176
+ export declare function listComments(ref: PresentationRef): Promise<DeckComment[]>;
177
+ export declare function getDeck(ref: PresentationRef): Promise<PresentationDetail | null>;
178
+ /** A deck by "<project>/<name>" or "<name>". */
179
+ export declare function findDeck(reference: string): Promise<PresentationSummary | null>;
180
+ interface RenderEntry extends Rendered {
181
+ stamp: string;
182
+ deck: DeckDoc;
183
+ template: Template;
184
+ }
185
+ /** The deck rendered into its PowerPoint model, cached until deck.md, an asset or the template changes. */
186
+ export declare function render(ref: PresentationRef): Promise<RenderEntry>;
187
+ /** One slide as PNG (1-based `n`). */
188
+ export declare function deckSlidePng(ref: PresentationRef, n: number, width?: number, hide?: string): Promise<Uint8Array>;
189
+ export type ExportFormat = "pptx" | "pdf" | "png" | "html";
190
+ export interface ExportResult {
191
+ /** Files written, absolute. */
192
+ files: string[];
193
+ warnings: RenderWarning[];
194
+ }
195
+ /** The deck as one self-contained HTML file: pictures and the theme's fonts inlined. */
196
+ export declare function deckHtml(ref: PresentationRef): Promise<{
197
+ html: string;
198
+ deck: DeckDoc;
199
+ template: Template;
200
+ stage: StageTemplate;
201
+ }>;
202
+ /** Write the deck's PPTX, PDF, slide PNGs or HTML into exports/ (or `outDir`). */
203
+ export declare function exportDeck(ref: PresentationRef, format: ExportFormat, opts?: {
204
+ outDir?: string;
205
+ width?: number;
206
+ }): Promise<ExportResult>;
207
+ /** The bytes of an export for a download, without writing exports/. */
208
+ export declare function exportBytes(ref: PresentationRef, format: "pptx" | "pdf" | "html"): Promise<{
209
+ bytes: Uint8Array;
210
+ mime: string;
211
+ filename: string;
212
+ }>;
213
+ export declare function createDeck(input: {
214
+ project?: string;
215
+ title: string;
216
+ slug?: string;
217
+ template?: string;
218
+ source?: string;
219
+ }): Promise<PresentationDetail>;
220
+ /** A save made over a deck.md that changed since the caller read it (an agent, another window). */
221
+ export declare class StaleDeckError extends Error {
222
+ readonly current: string;
223
+ constructor(current: string);
224
+ }
225
+ export interface SaveDeckInput {
226
+ /** The `updatedAt` the caller's copy was read at; a newer file refuses the save (StaleDeckError). */
227
+ base?: string;
228
+ /** The whole deck.md; wins over the structured fields. */
229
+ source?: string;
230
+ title?: string;
231
+ template?: string;
232
+ size?: "16:9" | "4:3" | null;
233
+ /** false turns the slide numbers off for the deck, true (or null) back on. */
234
+ numbers?: boolean | null;
235
+ /** Replace the slides (the editor sends them all). */
236
+ slides?: SlideDef[];
237
+ }
238
+ export declare function saveDeck(ref: PresentationRef, input: SaveDeckInput): Promise<PresentationDetail>;
239
+ /** Save an uploaded picture into the deck's assets/ (png, jpg, gif; 25 MB). Returns the path a slide references: `assets/<name>`. */
240
+ export declare function saveAsset(ref: PresentationRef, name: string, body: Readable): Promise<{
241
+ path: string;
242
+ size: number;
243
+ }>;
244
+ /** Move the deck folder, assets and exports included, to the trash. */
245
+ export declare function deleteDeck(ref: PresentationRef): Promise<void>;
246
+ declare const cliScope: (ref: PresentationRef) => string;
247
+ /**
248
+ * The "## Presentations" block of a project chat (its decks) or the
249
+ * workspace's: what exists, the file format in short, and the CLI.
250
+ */
251
+ export declare function presentationsContext(project: string | undefined): Promise<string>;
252
+ export { cliScope as presentationCliScope };