@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.
- package/README.md +175 -0
- package/dist/cli/init.js +1 -0
- package/dist/cli/kraftwerk.js +3 -0
- package/dist/cli/presentations.d.ts +2 -0
- package/dist/cli/presentations.js +261 -0
- package/dist/client/routes.d.ts +18 -0
- package/dist/client/routes.js +18 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +10 -2
- package/dist/core/boards.d.ts +14 -1
- package/dist/core/boards.js +34 -1
- package/dist/core/chat/context.js +11 -2
- package/dist/core/git.js +3 -1
- package/dist/core/presentations/browser.d.ts +43 -0
- package/dist/core/presentations/browser.js +53 -0
- package/dist/core/presentations/builtin.d.ts +3 -0
- package/dist/core/presentations/builtin.js +142 -0
- package/dist/core/presentations/chart.d.ts +34 -0
- package/dist/core/presentations/chart.js +159 -0
- package/dist/core/presentations/deck.d.ts +63 -0
- package/dist/core/presentations/deck.js +198 -0
- package/dist/core/presentations/export.d.ts +21 -0
- package/dist/core/presentations/export.js +75 -0
- package/dist/core/presentations/html.d.ts +135 -0
- package/dist/core/presentations/html.js +389 -0
- package/dist/core/presentations/index.d.ts +252 -0
- package/dist/core/presentations/index.js +753 -0
- package/dist/core/presentations/layout.d.ts +47 -0
- package/dist/core/presentations/layout.js +147 -0
- package/dist/core/presentations/markdown.d.ts +49 -0
- package/dist/core/presentations/markdown.js +158 -0
- package/dist/core/presentations/merge.d.ts +26 -0
- package/dist/core/presentations/merge.js +28 -0
- package/dist/core/presentations/presence.d.ts +31 -0
- package/dist/core/presentations/presence.js +131 -0
- package/dist/core/presentations/render.d.ts +33 -0
- package/dist/core/presentations/render.js +318 -0
- package/dist/core/presentations/slots.d.ts +33 -0
- package/dist/core/presentations/slots.js +114 -0
- package/dist/core/presentations/template.d.ts +253 -0
- package/dist/core/presentations/template.js +141 -0
- package/dist/core/presentations/versions.d.ts +30 -0
- package/dist/core/presentations/versions.js +75 -0
- package/dist/core/refs.d.ts +1 -1
- package/dist/core/refs.js +9 -1
- package/dist/core/search.d.ts +10 -0
- package/dist/core/search.js +6 -0
- package/dist/core/settings.d.ts +2 -0
- package/dist/core/settings.js +12 -1
- package/dist/core/trash.d.ts +1 -1
- package/dist/server/api/index.d.ts +62 -1
- package/dist/server/api/index.js +2 -0
- package/dist/server/api/presentations.d.ts +66 -0
- package/dist/server/api/presentations.js +185 -0
- package/dist/server/api/socket.js +24 -1
- package/dist/server/api/workspace.d.ts +5 -0
- package/dist/server/api/workspace.js +2 -0
- package/package.json +6 -2
- package/schema/kraftwerk.schema.json +18 -0
- package/web/dist/assets/{dist-DvkrCSGL.js → dist-5-ibIscm.js} +1 -1
- package/web/dist/assets/{dist-Bie1ebP9.js → dist-5lgY5B-M.js} +1 -1
- package/web/dist/assets/{dist-BuwdjX6z.js → dist-BJaPgnhj.js} +1 -1
- package/web/dist/assets/{dist-C_rJjRj7.js → dist-Bar1_NBq.js} +1 -1
- package/web/dist/assets/{dist-DtUB2Uu2.js → dist-BxCxboU8.js} +1 -1
- package/web/dist/assets/dist-CDitSY16.js +1 -0
- package/web/dist/assets/{dist-C16bXf8c.js → dist-CRXT8IL6.js} +1 -1
- package/web/dist/assets/{dist-CH73jsgO.js → dist-CXRjiHpl.js} +1 -1
- package/web/dist/assets/{dist-BBFUIftm.js → dist-CpnB7MfK.js} +1 -1
- package/web/dist/assets/{dist-C0ve4Tka.js → dist-D1VK1YdB.js} +1 -1
- package/web/dist/assets/{dist-CDUZdAAS.js → dist-D52LvyO8.js} +1 -1
- package/web/dist/assets/{editor-3z92i0tV.js → editor-HCNTXWWs.js} +3 -3
- package/web/dist/assets/index-Dnlu16AL.css +2 -0
- package/web/dist/assets/index-kwWnQOhD.js +473 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/dist-DYICNp09.js +0 -1
- package/web/dist/assets/index-DRhNELK_.js +0 -232
- package/web/dist/assets/index-unGEux3Y.css +0 -2
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { parse, stringify } from "yaml";
|
|
2
|
+
import { NOTES_SLOT, joinSlots, slotsOf, trimBlank } from "./slots.js";
|
|
3
|
+
export { DEFAULT_SLOT, NOTES_SLOT, joinSlots, slotsOf } from "./slots.js";
|
|
4
|
+
/**
|
|
5
|
+
* deck.md: the whole presentation in one Markdown file, Slidev-style.
|
|
6
|
+
*
|
|
7
|
+
* --- headmatter: the deck (title, template, size) and the
|
|
8
|
+
* title: Why NodeHive first slide's own keys (layout, notes, background)
|
|
9
|
+
* template: default
|
|
10
|
+
* layout: title
|
|
11
|
+
* ---
|
|
12
|
+
* # Why NodeHive slide 1 — content before the first ::slot:: marker is
|
|
13
|
+
* ::subtitle:: the default content: a leading heading fills the
|
|
14
|
+
* Review · Nov 2026 layout's title slot, the rest its body slot
|
|
15
|
+
* ::notes:: ::notes:: are the speaker notes
|
|
16
|
+
* Open with the timeline.
|
|
17
|
+
*
|
|
18
|
+
* --- a `---` line starts the next slide; an optional YAML
|
|
19
|
+
* layout: two-column block right after it (closed by another `---`) is
|
|
20
|
+
* --- the slide's keys
|
|
21
|
+
* # Faster editing
|
|
22
|
+
* ::left::
|
|
23
|
+
* - One API for every channel
|
|
24
|
+
* ::right::
|
|
25
|
+
* 
|
|
26
|
+
*
|
|
27
|
+
* The parser is tolerant: a fence (```) hides separators and markers inside
|
|
28
|
+
* it, a `---` with no YAML after it is just a separator, and anything that
|
|
29
|
+
* is not a mapping stays content. `serializeDeck` writes the normalised
|
|
30
|
+
* form back; the editor and the CLI both go through it, agents may edit
|
|
31
|
+
* the file directly.
|
|
32
|
+
*/
|
|
33
|
+
/** Headmatter keys the deck reads itself; every other non-slide key stays in `meta` (author, date, …). */
|
|
34
|
+
export const DECK_KEYS = ["title", "template", "size", "css", "numbers"];
|
|
35
|
+
export const SLIDE_KEYS = ["layout", "notes", "background", "transition"];
|
|
36
|
+
const SEP_RE = /^---[ \t]*$/;
|
|
37
|
+
const FENCE_RE = /^(`{3,}|~{3,})/;
|
|
38
|
+
const KEY_RE = /^[A-Za-z_][\w-]*\s*:/;
|
|
39
|
+
export function parseDeck(raw) {
|
|
40
|
+
const lines = raw.replace(/\r\n?/g, "\n").split("\n");
|
|
41
|
+
let i = 0;
|
|
42
|
+
let head = {};
|
|
43
|
+
// Headmatter: a leading `---` block.
|
|
44
|
+
if (lines.length && SEP_RE.test(lines[0])) {
|
|
45
|
+
const end = lines.findIndex((l, idx) => idx > 0 && SEP_RE.test(l));
|
|
46
|
+
if (end > 0) {
|
|
47
|
+
head = mapping(lines.slice(1, end).join("\n"));
|
|
48
|
+
i = end + 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const doc = { title: str(head.title) || "", template: str(head.template) || "default", meta: {}, slides: [] };
|
|
52
|
+
if (head.size === "4:3" || head.size === "16:9")
|
|
53
|
+
doc.size = head.size;
|
|
54
|
+
if (typeof head.css === "string" && head.css.trim())
|
|
55
|
+
doc.css = head.css;
|
|
56
|
+
if (head.numbers === false)
|
|
57
|
+
doc.numbers = false;
|
|
58
|
+
for (const [k, v] of Object.entries(head))
|
|
59
|
+
if (!DECK_KEYS.includes(k) && !FIRST_SLIDE_KEYS.includes(k))
|
|
60
|
+
doc.meta[k] = v;
|
|
61
|
+
// Split the rest into slide chunks at top-level `---` lines (not inside fences).
|
|
62
|
+
const chunks = [{ attrs: pickSlideKeys(head), body: [] }];
|
|
63
|
+
let fence = null;
|
|
64
|
+
for (; i < lines.length; i++) {
|
|
65
|
+
const line = lines[i];
|
|
66
|
+
const f = FENCE_RE.exec(line);
|
|
67
|
+
if (f) {
|
|
68
|
+
if (!fence)
|
|
69
|
+
fence = f[1];
|
|
70
|
+
else if (line.startsWith(fence))
|
|
71
|
+
fence = null;
|
|
72
|
+
chunks[chunks.length - 1].body.push(line);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!fence && SEP_RE.test(line)) {
|
|
76
|
+
// A YAML block directly after the separator?
|
|
77
|
+
const close = lines.findIndex((l, idx) => idx > i && SEP_RE.test(l));
|
|
78
|
+
const between = close > i ? lines.slice(i + 1, close) : [];
|
|
79
|
+
const isYaml = between.length > 0 && between.every((l) => l.trim() !== "") && KEY_RE.test(between[0]) && tryMapping(between.join("\n")) != null;
|
|
80
|
+
if (isYaml) {
|
|
81
|
+
chunks.push({ attrs: mapping(between.join("\n")), body: [] });
|
|
82
|
+
i = close;
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
chunks.push({ attrs: {}, body: [] });
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
chunks[chunks.length - 1].body.push(line);
|
|
89
|
+
}
|
|
90
|
+
// An empty first chunk before the first separator (a deck that starts with `---` after the headmatter) is not a slide.
|
|
91
|
+
if (chunks.length > 1 && chunks[0].body.join("").trim() === "" && Object.keys(chunks[0].attrs).length === 0)
|
|
92
|
+
chunks.shift();
|
|
93
|
+
doc.slides = chunks.map((c) => slideOf(c.attrs, c.body.join("\n")));
|
|
94
|
+
return doc;
|
|
95
|
+
}
|
|
96
|
+
function slideOf(attrs, body) {
|
|
97
|
+
const slide = { extra: {}, content: trimBlank(body) };
|
|
98
|
+
if (typeof attrs.layout === "string" && attrs.layout.trim())
|
|
99
|
+
slide.layout = attrs.layout.trim();
|
|
100
|
+
if (typeof attrs.notes === "string" && attrs.notes.trim())
|
|
101
|
+
slide.notes = attrs.notes.trim();
|
|
102
|
+
if (typeof attrs.background === "string" && attrs.background.trim())
|
|
103
|
+
slide.background = attrs.background.trim();
|
|
104
|
+
if (typeof attrs.transition === "string" && attrs.transition.trim())
|
|
105
|
+
slide.transition = attrs.transition.trim();
|
|
106
|
+
for (const [k, v] of Object.entries(attrs))
|
|
107
|
+
if (!SLIDE_KEYS.includes(k))
|
|
108
|
+
slide.extra[k] = v;
|
|
109
|
+
// ::notes:: in the content wins over the key and is lifted out of the content.
|
|
110
|
+
const slots = slotsOf(slide.content);
|
|
111
|
+
if (slots[NOTES_SLOT] !== undefined) {
|
|
112
|
+
if (slots[NOTES_SLOT].trim())
|
|
113
|
+
slide.notes = slots[NOTES_SLOT].trim();
|
|
114
|
+
delete slots[NOTES_SLOT];
|
|
115
|
+
slide.content = joinSlots(slots);
|
|
116
|
+
}
|
|
117
|
+
return slide;
|
|
118
|
+
}
|
|
119
|
+
/** A deck in its file form: headmatter, then slides separated by `---` lines with their YAML blocks. */
|
|
120
|
+
export function serializeDeck(doc) {
|
|
121
|
+
const head = { title: doc.title || "Untitled", template: doc.template || "default" };
|
|
122
|
+
if (doc.size)
|
|
123
|
+
head.size = doc.size;
|
|
124
|
+
if (doc.numbers === false)
|
|
125
|
+
head.numbers = false;
|
|
126
|
+
if (doc.css?.trim())
|
|
127
|
+
head.css = doc.css.replace(/\s+$/, "") + "\n";
|
|
128
|
+
Object.assign(head, doc.meta);
|
|
129
|
+
const slides = doc.slides.length ? doc.slides : [{ extra: {}, content: "" }];
|
|
130
|
+
Object.assign(head, slideAttrs(slides[0]));
|
|
131
|
+
let out = `---\n${stringify(head)}---\n`;
|
|
132
|
+
out += slideBody(slides[0]);
|
|
133
|
+
for (const s of slides.slice(1)) {
|
|
134
|
+
const attrs = slideAttrs(s);
|
|
135
|
+
out += `\n---\n`;
|
|
136
|
+
if (Object.keys(attrs).length)
|
|
137
|
+
out += `${stringify(attrs)}---\n`;
|
|
138
|
+
out += slideBody(s);
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
function slideAttrs(s) {
|
|
143
|
+
const attrs = {};
|
|
144
|
+
if (s.layout)
|
|
145
|
+
attrs.layout = s.layout;
|
|
146
|
+
if (s.background)
|
|
147
|
+
attrs.background = s.background;
|
|
148
|
+
if (s.transition)
|
|
149
|
+
attrs.transition = s.transition;
|
|
150
|
+
Object.assign(attrs, s.extra);
|
|
151
|
+
return attrs;
|
|
152
|
+
}
|
|
153
|
+
function slideBody(s) {
|
|
154
|
+
const content = trimBlank(s.content);
|
|
155
|
+
const notes = s.notes?.trim() ? `::notes::\n${s.notes.trim()}` : "";
|
|
156
|
+
const body = [content, notes].filter(Boolean).join("\n\n");
|
|
157
|
+
return body ? `${body}\n` : "";
|
|
158
|
+
}
|
|
159
|
+
/** A new deck's file: a title slide and one content slide, so the editor opens with something to show. */
|
|
160
|
+
export function starterDeck(title, template) {
|
|
161
|
+
return {
|
|
162
|
+
title,
|
|
163
|
+
template,
|
|
164
|
+
meta: {},
|
|
165
|
+
slides: [
|
|
166
|
+
{ layout: "title", extra: {}, content: `# ${title}\n\n::subtitle::\n${new Date().toISOString().slice(0, 10)}` },
|
|
167
|
+
{ layout: "content", extra: {}, content: "# First point\n\n- What this deck is about\n- Why it matters\n- What we decide" },
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** The first slide's keys live in the headmatter: the slide keys and its `slots:` changes. */
|
|
172
|
+
/** The first slide's keys live in the headmatter too: id (comments point at it), hidden, number, slots. */
|
|
173
|
+
const FIRST_SLIDE_KEYS = [...SLIDE_KEYS, "slots", "id", "hidden", "number"];
|
|
174
|
+
function pickSlideKeys(head) {
|
|
175
|
+
const out = {};
|
|
176
|
+
for (const k of FIRST_SLIDE_KEYS)
|
|
177
|
+
if (head[k] !== undefined)
|
|
178
|
+
out[k] = head[k];
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
const str = (v) => (typeof v === "string" ? v.trim() : v == null ? "" : String(v));
|
|
182
|
+
function mapping(text) {
|
|
183
|
+
const data = text.trim() ? parse(text) : {};
|
|
184
|
+
if (data == null)
|
|
185
|
+
return {};
|
|
186
|
+
if (typeof data !== "object" || Array.isArray(data))
|
|
187
|
+
throw new Error("frontmatter must be a mapping");
|
|
188
|
+
return data;
|
|
189
|
+
}
|
|
190
|
+
function tryMapping(text) {
|
|
191
|
+
try {
|
|
192
|
+
const data = parse(text);
|
|
193
|
+
return data != null && typeof data === "object" && !Array.isArray(data) ? data : null;
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type PresentationData } from "@office-kit/pptx";
|
|
2
|
+
/**
|
|
3
|
+
* Exports of a rendered deck. The PowerPoint model is the one source: the
|
|
4
|
+
* PPTX is the model saved, a slide image is the model drawn by
|
|
5
|
+
* pptx-preview (resvg, no browser), and the PDF is those drawings, one
|
|
6
|
+
* page per slide, written by the small PDF writer below — so the file the
|
|
7
|
+
* client gets, the preview in the editor and what an agent looks at are the
|
|
8
|
+
* same picture.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PPTX_MIME = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
11
|
+
export declare const toPptx: (pres: PresentationData) => Promise<Uint8Array>;
|
|
12
|
+
/** One slide as PNG, `width` pixels wide (16:9 → width × width·9/16). */
|
|
13
|
+
export declare function slidePng(pres: PresentationData, index: number, width?: number): Uint8Array;
|
|
14
|
+
/** Every slide as PNG. */
|
|
15
|
+
export declare const slidePngs: (pres: PresentationData, width?: number) => Uint8Array[];
|
|
16
|
+
/**
|
|
17
|
+
* The deck as PDF: each slide rasterised at `width` pixels and placed on a
|
|
18
|
+
* page of the canvas size in points. Images are raw RGB under FlateDecode —
|
|
19
|
+
* the only encoding every PDF reader supports without a library here.
|
|
20
|
+
*/
|
|
21
|
+
export declare function toPdf(pres: PresentationData, size?: "16:9" | "4:3", width?: number): Uint8Array;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { deflateSync } from "node:zlib";
|
|
2
|
+
import { getSlides, savePresentation } from "@office-kit/pptx";
|
|
3
|
+
import { renderSlideToImage, renderSlideToRgba } from "@office-kit/pptx-preview/node";
|
|
4
|
+
import { CANVAS } from "./template.js";
|
|
5
|
+
/**
|
|
6
|
+
* Exports of a rendered deck. The PowerPoint model is the one source: the
|
|
7
|
+
* PPTX is the model saved, a slide image is the model drawn by
|
|
8
|
+
* pptx-preview (resvg, no browser), and the PDF is those drawings, one
|
|
9
|
+
* page per slide, written by the small PDF writer below — so the file the
|
|
10
|
+
* client gets, the preview in the editor and what an agent looks at are the
|
|
11
|
+
* same picture.
|
|
12
|
+
*/
|
|
13
|
+
export const PPTX_MIME = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
14
|
+
export const toPptx = (pres) => savePresentation(pres);
|
|
15
|
+
/** One slide as PNG, `width` pixels wide (16:9 → width × width·9/16). */
|
|
16
|
+
export function slidePng(pres, index, width = 1280) {
|
|
17
|
+
const slide = getSlides(pres)[index];
|
|
18
|
+
if (!slide)
|
|
19
|
+
throw new Error(`no slide ${index + 1}`);
|
|
20
|
+
return renderSlideToImage(pres, slide, { width });
|
|
21
|
+
}
|
|
22
|
+
/** Every slide as PNG. */
|
|
23
|
+
export const slidePngs = (pres, width = 1280) => getSlides(pres).map((_, i) => slidePng(pres, i, width));
|
|
24
|
+
/**
|
|
25
|
+
* The deck as PDF: each slide rasterised at `width` pixels and placed on a
|
|
26
|
+
* page of the canvas size in points. Images are raw RGB under FlateDecode —
|
|
27
|
+
* the only encoding every PDF reader supports without a library here.
|
|
28
|
+
*/
|
|
29
|
+
export function toPdf(pres, size = "16:9", width = 1600) {
|
|
30
|
+
const canvas = CANVAS[size];
|
|
31
|
+
const pageW = canvas.w * 72;
|
|
32
|
+
const pageH = canvas.h * 72;
|
|
33
|
+
const pages = getSlides(pres).map((slide) => {
|
|
34
|
+
const { image } = renderSlideToRgba(pres, slide, { width });
|
|
35
|
+
const rgb = Buffer.alloc(image.width * image.height * 3);
|
|
36
|
+
for (let i = 0, j = 0; i < image.data.length; i += 4, j += 3) {
|
|
37
|
+
rgb[j] = image.data[i];
|
|
38
|
+
rgb[j + 1] = image.data[i + 1];
|
|
39
|
+
rgb[j + 2] = image.data[i + 2];
|
|
40
|
+
}
|
|
41
|
+
return { w: image.width, h: image.height, data: deflateSync(rgb) };
|
|
42
|
+
});
|
|
43
|
+
return writePdf(pages, pageW, pageH);
|
|
44
|
+
}
|
|
45
|
+
function writePdf(images, pageW, pageH) {
|
|
46
|
+
const objects = [];
|
|
47
|
+
const add = (body) => {
|
|
48
|
+
objects.push(Buffer.isBuffer(body) ? body : Buffer.from(body, "latin1"));
|
|
49
|
+
return objects.length;
|
|
50
|
+
};
|
|
51
|
+
// 1 catalog, 2 pages; then per slide: image, content, page.
|
|
52
|
+
const catalog = add("<< /Type /Catalog /Pages 2 0 R >>");
|
|
53
|
+
const pagesIdx = add(""); // placeholder, filled once the page ids are known
|
|
54
|
+
const pageIds = [];
|
|
55
|
+
for (const img of images) {
|
|
56
|
+
const imgId = add(Buffer.concat([Buffer.from(`<< /Type /XObject /Subtype /Image /Width ${img.w} /Height ${img.h} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /FlateDecode /Length ${img.data.length} >>\nstream\n`, "latin1"), img.data, Buffer.from("\nendstream", "latin1")]));
|
|
57
|
+
const content = `q ${pageW.toFixed(2)} 0 0 ${pageH.toFixed(2)} 0 0 cm /Im0 Do Q`;
|
|
58
|
+
const contentId = add(`<< /Length ${content.length} >>\nstream\n${content}\nendstream`);
|
|
59
|
+
const pageId = add(`<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${pageW.toFixed(2)} ${pageH.toFixed(2)}] /Resources << /XObject << /Im0 ${imgId} 0 R >> >> /Contents ${contentId} 0 R >>`);
|
|
60
|
+
pageIds.push(pageId);
|
|
61
|
+
}
|
|
62
|
+
objects[pagesIdx - 1] = Buffer.from(`<< /Type /Pages /Kids [${pageIds.map((id) => `${id} 0 R`).join(" ")}] /Count ${pageIds.length} >>`, "latin1");
|
|
63
|
+
const parts = [Buffer.from("%PDF-1.4\n%\xE2\xE3\xCF\xD3\n", "latin1")];
|
|
64
|
+
const offsets = [];
|
|
65
|
+
let length = parts[0].length;
|
|
66
|
+
objects.forEach((body, i) => {
|
|
67
|
+
offsets.push(length);
|
|
68
|
+
const chunk = Buffer.concat([Buffer.from(`${i + 1} 0 obj\n`, "latin1"), body, Buffer.from("\nendobj\n", "latin1")]);
|
|
69
|
+
parts.push(chunk);
|
|
70
|
+
length += chunk.length;
|
|
71
|
+
});
|
|
72
|
+
const xref = [`xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`, ...offsets.map((o) => `${String(o).padStart(10, "0")} 00000 n \n`)].join("");
|
|
73
|
+
parts.push(Buffer.from(`${xref}trailer\n<< /Size ${objects.length + 1} /Root ${catalog} 0 R >>\nstartxref\n${length}\n%%EOF\n`, "latin1"));
|
|
74
|
+
return new Uint8Array(Buffer.concat(parts));
|
|
75
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { SlideDef } from "./deck.js";
|
|
2
|
+
import type { LayoutDef, SlotDef, Snippet } from "./template.js";
|
|
3
|
+
/**
|
|
4
|
+
* The slides as HTML: what the editor shows (and edits in place), what
|
|
5
|
+
* present mode and the thumbnails show, what PDF and PNG are printed
|
|
6
|
+
* from and what `render --html` writes. One model per slide (`slideView`):
|
|
7
|
+
* the layout's slots with the slide's own changes, each slot's HTML, its
|
|
8
|
+
* box in stage pixels (1600 wide, 160 per inch) and its look; the theme
|
|
9
|
+
* styles it with plain CSS (`stageCss`). Pure — the web bundles it; the
|
|
10
|
+
* caller says where pictures live (`asset`).
|
|
11
|
+
*/
|
|
12
|
+
/** The template as the HTML renderer needs it: no files, no schema. */
|
|
13
|
+
export interface StageTemplate {
|
|
14
|
+
slug: string;
|
|
15
|
+
name: string;
|
|
16
|
+
size: "16:9" | "4:3";
|
|
17
|
+
fonts: {
|
|
18
|
+
heading: string;
|
|
19
|
+
body: string;
|
|
20
|
+
};
|
|
21
|
+
colors: Record<string, string>;
|
|
22
|
+
layouts: Record<string, LayoutDef>;
|
|
23
|
+
default?: string;
|
|
24
|
+
/** Theme CSS; relative URLs already point where the caller serves the template's files. */
|
|
25
|
+
css: string;
|
|
26
|
+
snippets: Snippet[];
|
|
27
|
+
}
|
|
28
|
+
export interface SlotView {
|
|
29
|
+
name: string;
|
|
30
|
+
kind: SlotDef["kind"];
|
|
31
|
+
/** Box in inches (as in the files). */
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
w: number;
|
|
35
|
+
h: number;
|
|
36
|
+
size?: number;
|
|
37
|
+
bold?: boolean;
|
|
38
|
+
italic?: boolean;
|
|
39
|
+
color?: string;
|
|
40
|
+
font?: string;
|
|
41
|
+
align?: "left" | "center" | "right";
|
|
42
|
+
valign?: "top" | "middle" | "bottom";
|
|
43
|
+
fill?: string;
|
|
44
|
+
class?: string;
|
|
45
|
+
underline?: boolean;
|
|
46
|
+
strike?: boolean;
|
|
47
|
+
rotate?: number;
|
|
48
|
+
radius?: number;
|
|
49
|
+
border?: number;
|
|
50
|
+
borderColor?: string;
|
|
51
|
+
shadow?: boolean;
|
|
52
|
+
opacity?: number;
|
|
53
|
+
z?: number;
|
|
54
|
+
fit?: "contain" | "cover";
|
|
55
|
+
required?: boolean;
|
|
56
|
+
placeholder?: string;
|
|
57
|
+
/** A slot of the slide's own (not the layout's). */
|
|
58
|
+
own?: boolean;
|
|
59
|
+
/** The slide changes the layout's slot. */
|
|
60
|
+
changed?: boolean;
|
|
61
|
+
/** The slot's markdown, undefined when nothing fills it. */
|
|
62
|
+
md?: string;
|
|
63
|
+
/** What it shows. For `embed`, empty: see `embed`. */
|
|
64
|
+
html: string;
|
|
65
|
+
embed?: {
|
|
66
|
+
src?: string;
|
|
67
|
+
srcdoc?: string;
|
|
68
|
+
};
|
|
69
|
+
/** Why it could not be drawn (a broken chart block). */
|
|
70
|
+
error?: string;
|
|
71
|
+
}
|
|
72
|
+
/** How a slide comes in when presented: fade (the default), slide in from the right, zoom in, or cut (none). */
|
|
73
|
+
export declare const TRANSITIONS: readonly ["fade", "slide", "zoom", "none"];
|
|
74
|
+
export type Transition = (typeof TRANSITIONS)[number];
|
|
75
|
+
export declare const transitionOf: (value: string | undefined) => Transition;
|
|
76
|
+
export interface SlideView {
|
|
77
|
+
layout: string;
|
|
78
|
+
transition: Transition;
|
|
79
|
+
/** A color, or `url(...) center / cover` for a picture. */
|
|
80
|
+
background: string;
|
|
81
|
+
/** Left out of present mode and the exports. */
|
|
82
|
+
hidden: boolean;
|
|
83
|
+
/** Carries its slide number (the theme draws it, usually not on title and section slides): off with the deck's `numbers: false` or the slide's `number: false`. */
|
|
84
|
+
numbered: boolean;
|
|
85
|
+
shapes: {
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
w: number;
|
|
89
|
+
h: number;
|
|
90
|
+
fill: string;
|
|
91
|
+
}[];
|
|
92
|
+
slots: SlotView[];
|
|
93
|
+
problems: string[];
|
|
94
|
+
/** The stage in px. */
|
|
95
|
+
width: number;
|
|
96
|
+
height: number;
|
|
97
|
+
}
|
|
98
|
+
export interface RenderOpts {
|
|
99
|
+
/** Where a slide's picture (`assets/arch.png`) is fetched from. */
|
|
100
|
+
asset: (src: string) => string;
|
|
101
|
+
/** The deck's `numbers`: false leaves every slide without its number. */
|
|
102
|
+
numbers?: boolean;
|
|
103
|
+
}
|
|
104
|
+
export declare const stageHeight: (size: "16:9" | "4:3") => number;
|
|
105
|
+
/** A slot's font size in points as stage px. */
|
|
106
|
+
export declare const ptToPx: (pt: number) => number;
|
|
107
|
+
/** Every slot of a slide with its content and look; problems name what the slide asks for and the layout cannot give. */
|
|
108
|
+
export declare function slideView(slide: SlideDef, t: StageTemplate, opts: RenderOpts): SlideView;
|
|
109
|
+
/** A slot's own CSS: its box in stage px and how its text looks. */
|
|
110
|
+
export declare function slotStyle(s: Pick<SlotView, "x" | "y" | "w" | "h" | "size" | "bold" | "italic" | "color" | "font" | "align" | "fill" | "underline" | "strike" | "rotate" | "radius" | "border" | "borderColor" | "shadow" | "opacity" | "z">, t: StageTemplate): Record<string, string>;
|
|
111
|
+
/**
|
|
112
|
+
* The CSS of a deck's slides: the base (boxes, type, lists, tables), the
|
|
113
|
+
* template's colors and fonts as variables, the theme scoped to
|
|
114
|
+
* `.deck-theme-<slug>`, then the deck's own CSS scoped to its slides.
|
|
115
|
+
*/
|
|
116
|
+
export declare function stageCss(t: StageTemplate, deckCss?: string): string;
|
|
117
|
+
/** What every slide gets, whatever the theme; `:where()` keeps it weaker than any theme rule. */
|
|
118
|
+
export declare const BASE_CSS = "\n.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; }\n.deck-slide :where(*, *::before, *::after) { box-sizing: border-box; }\n.deck-slide .deck-slot { position: absolute; display: flex; flex-direction: column; min-width: 0; padding: 8px 16px; overflow-wrap: break-word; }\n.deck-slide .deck-slot[data-valign=\"middle\"] { justify-content: center; }\n.deck-slide .deck-slot[data-valign=\"bottom\"] { justify-content: flex-end; }\n.deck-slide .deck-content { min-height: 0; outline: none; }\n.deck-slide .deck-shape { position: absolute; }\n.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; }\n.deck-slide :where(p, ul, ol, blockquote, figure, table, pre, dl) { margin: 0; }\n.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; }\n.deck-slide :where(ul, ol) { padding-left: 1.15em; }\n.deck-slide :where(ul) { list-style: disc; }\n.deck-slide :where(ol) { list-style: decimal; }\n.deck-slide :where(ul ul) { list-style: circle; }\n.deck-slide :where(li + li) { margin-top: 0.25em; }\n.deck-slide :where(li)::marker { color: var(--c-accent); }\n.deck-slide :where(strong, b) { font-weight: 700; }\n.deck-slide :where(em, i) { font-style: italic; }\n.deck-slide :where(a) { color: var(--c-accent); text-decoration: underline; text-underline-offset: 0.12em; }\n.deck-slide :where(code) { font-family: ui-monospace, \"SF Mono\", Menlo, Consolas, monospace; font-size: 0.9em; color: var(--c-accent); }\n.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; }\n.deck-slide :where(pre code) { color: inherit; font-size: 1em; }\n.deck-slide :where(blockquote) { border-left: 4px solid var(--c-accent); padding-left: 0.8em; color: var(--c-muted); }\n.deck-slide :where(img, svg, video) { max-width: 100%; }\n.deck-slide :where(table) { border-collapse: collapse; width: 100%; font-size: 0.95em; }\n.deck-slide :where(th, td) { padding: 0.45em 0.65em; border-bottom: 1px solid var(--c-line); text-align: left; vertical-align: top; }\n.deck-slide :where(th) { font-weight: 700; border-bottom: 2px solid var(--c-text); }\n.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; }\n.deck-slide .kind-image img { width: 100%; height: 100%; object-fit: contain; display: block; }\n.deck-slide .kind-image[data-fit=\"cover\"] img { object-fit: cover; }\n.deck-slide .kind-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }\n.deck-slide .kind-embed iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }\n.deck-slide .kind-image, .deck-slide .kind-chart, .deck-slide .kind-embed { padding: 0; }\n.deck-slide .deck-error { color: #B91C1C; font-size: 0.6em; font-family: ui-monospace, Menlo, monospace; }\n";
|
|
119
|
+
/** One slide as an HTML string (the export's, the print's and the CLI's form of what the editor shows). */
|
|
120
|
+
export declare function slideHtml(v: SlideView, t: StageTemplate, extraClass?: string, number?: {
|
|
121
|
+
n: number;
|
|
122
|
+
of: number;
|
|
123
|
+
}): string;
|
|
124
|
+
/**
|
|
125
|
+
* The deck as one HTML file: every slide, the theme, arrows and space to
|
|
126
|
+
* step through, F for full screen, P to print (a PDF, one slide a page).
|
|
127
|
+
* The caller inlines the pictures and fonts (`asset` returning data URLs,
|
|
128
|
+
* the theme's URLs rewritten) so the file stands alone.
|
|
129
|
+
*/
|
|
130
|
+
export declare function standaloneHtml(deck: {
|
|
131
|
+
title: string;
|
|
132
|
+
slides: SlideDef[];
|
|
133
|
+
css?: string;
|
|
134
|
+
numbers?: false;
|
|
135
|
+
}, t: StageTemplate, opts: RenderOpts): string;
|