Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kits/slides/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
"build": "vite build",
"test": "node --test src/lib/*.test.mjs"
},
"dependencies": {
"echarts": "^5.5.1",
Expand Down
19 changes: 19 additions & 0 deletions kits/slides/app/src/lib/deckContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// What an element carries, read the way the deck view draws it, so an export cannot leave out what the deck
// shows. The deck model (plugin/skills/slide-design/deck_model.py) is the schema and reifyui's slide elements
// are the renderer: a flowchart's Mermaid source is content.mermaid and a code block's text is content.source.
//
// PowerPoint export used to read content.code / content.text for a flowchart and content.runs for a code
// block. No deck has those, so every diagram and every code block was left out of the .pptx, and nothing
// said so.

/** The Mermaid source of a flowchart element, or '' when it has none. */
export function flowchartSource(el) {
const src = el?.content?.mermaid;
return typeof src === 'string' ? src.trim() && src : '';
}

/** A code element's text as one run (its line breaks kept), or [] when it has none. */
export function codeRuns(el) {
const src = el?.content?.source;
return typeof src === 'string' && src.trim() ? [{ text: src }] : [];
}
30 changes: 30 additions & 0 deletions kits/slides/app/src/lib/deckContent.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { codeRuns, flowchartSource } from './deckContent.js';

// The shapes the agent writes, from the deck model: these are what the deck view draws.
const flow = { type: 'flowchart', content: { mermaid: 'flowchart LR\n A["Introduced"] --> B["Committee"]' } };
const code = { type: 'code', content: { lang: 'python', source: 'def add(a, b):\n return a + b\n' } };

test('a flowchart is exported from its Mermaid source', () => {
assert.equal(flowchartSource(flow), flow.content.mermaid);
});

test('a code block is exported from its source, line breaks and all', () => {
assert.deepEqual(codeRuns(code), [{ text: code.content.source }]);
});

test('fields the deck view does not draw are not exported either', () => {
// the old readers' fields: a deck carrying only these shows nothing on the slide
assert.equal(flowchartSource({ type: 'flowchart', content: { code: 'flowchart LR\n A --> B' } }), '');
assert.deepEqual(codeRuns({ type: 'code', content: { runs: [{ text: 'x = 1' }] } }), []);
});

test('an element with nothing to show gives nothing, so the export can say it left it out', () => {
for (const el of [{}, { content: null }, { content: { mermaid: ' ' } }, { content: { mermaid: 42 } }]) {
assert.equal(flowchartSource(el), '');
}
for (const el of [{}, { content: {} }, { content: { source: '\n' } }]) {
assert.deepEqual(codeRuns(el), []);
}
});
9 changes: 6 additions & 3 deletions kits/slides/app/src/lib/exportPptx.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// pptxgenjs is imported by this module ONLY, so it lands in its own chunk and costs nothing until
// someone actually exports.
import { ROLE_STYLE } from 'reifyui/slides'; // one source of truth — never re-declare it here
import { codeRuns, flowchartSource } from './deckContent.js';

const PX_IN = 13.333 / 1920;
const inch = (v) => +((v || 0) * PX_IN).toFixed(4);
Expand Down Expand Up @@ -139,7 +140,7 @@ async function addChart(slide, el, notes) {
}

async function addFlowchart(slide, el, notes) {
const src = (el.content || {}).code || (el.content || {}).text;
const src = flowchartSource(el);
if (!src) return false;
const mermaid = (await import('mermaid')).default;
// htmlLabels:false matters — with it on, mermaid emits <foreignObject>, the one shape that
Expand Down Expand Up @@ -236,7 +237,7 @@ export async function downloadPptx(deck, resolveSrc, onProgress) {
} else if (el.type === 'chart') {
await addChart(slide, el, notes);
} else if (el.type === 'flowchart') {
await addFlowchart(slide, el, notes);
if (!(await addFlowchart(slide, el, notes))) notes.dropped.push(`a diagram on slide ${i + 1} with no Mermaid source`);
} else if (el.type === 'embed') {
const html = el.content?.html || '';
if (/<svg/i.test(html)) {
Expand All @@ -250,10 +251,12 @@ export async function downloadPptx(deck, resolveSrc, onProgress) {
notes.dropped.push('an embedded block that is not an image');
}
} else if (el.type === 'code') {
const props = textProps({ ...el, content: { ...el.content, role: 'body' } }, theme);
const props = textProps({ ...el, content: { ...el.content, runs: codeRuns(el), role: 'body' } }, theme);
if (props.length) {
slide.addText(props.map((p) => ({ ...p, options: { ...p.options, fontFace: 'Consolas' } })),
{ ...frameOf(el), valign: 'top', margin: 0, inset: 0, isTextBox: true, fit: 'none' });
} else {
notes.dropped.push(`a code block on slide ${i + 1} with no text`);
}
}
} catch (e) {
Expand Down
Loading