@mulmocast/deck 0.1.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/LICENSE +21 -0
- package/README.md +66 -0
- package/lib/blocks.d.ts +13 -0
- package/lib/blocks.js +251 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +8 -0
- package/lib/layouts/big_quote.d.ts +2 -0
- package/lib/layouts/big_quote.js +19 -0
- package/lib/layouts/columns.d.ts +2 -0
- package/lib/layouts/columns.js +53 -0
- package/lib/layouts/comparison.d.ts +2 -0
- package/lib/layouts/comparison.js +25 -0
- package/lib/layouts/funnel.d.ts +2 -0
- package/lib/layouts/funnel.js +25 -0
- package/lib/layouts/grid.d.ts +2 -0
- package/lib/layouts/grid.js +38 -0
- package/lib/layouts/index.d.ts +3 -0
- package/lib/layouts/index.js +46 -0
- package/lib/layouts/matrix.d.ts +2 -0
- package/lib/layouts/matrix.js +53 -0
- package/lib/layouts/split.d.ts +2 -0
- package/lib/layouts/split.js +51 -0
- package/lib/layouts/stats.d.ts +2 -0
- package/lib/layouts/stats.js +23 -0
- package/lib/layouts/table.d.ts +2 -0
- package/lib/layouts/table.js +10 -0
- package/lib/layouts/timeline.d.ts +2 -0
- package/lib/layouts/timeline.js +27 -0
- package/lib/layouts/title.d.ts +2 -0
- package/lib/layouts/title.js +19 -0
- package/lib/layouts/waterfall.d.ts +2 -0
- package/lib/layouts/waterfall.js +63 -0
- package/lib/render.d.ts +17 -0
- package/lib/render.js +101 -0
- package/lib/schema.d.ts +9309 -0
- package/lib/schema.js +434 -0
- package/lib/utils.d.ts +76 -0
- package/lib/utils.js +243 -0
- package/package.json +55 -0
package/lib/utils.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/** Escape HTML special characters */
|
|
2
|
+
export const escapeHtml = (s) => {
|
|
3
|
+
return String(s || "")
|
|
4
|
+
.replace(/&/g, "&")
|
|
5
|
+
.replace(/</g, "<")
|
|
6
|
+
.replace(/>/g, ">")
|
|
7
|
+
.replace(/"/g, """)
|
|
8
|
+
.replace(/'/g, "'");
|
|
9
|
+
};
|
|
10
|
+
/** Escape HTML and convert newlines to <br> */
|
|
11
|
+
export const nl2br = (s) => {
|
|
12
|
+
return escapeHtml(s).replace(/\n/g, "<br>");
|
|
13
|
+
};
|
|
14
|
+
/** Valid accent color keys for inline markup */
|
|
15
|
+
const inlineColorKeys = new Set(["primary", "accent", "success", "warning", "danger", "info", "highlight"]);
|
|
16
|
+
/**
|
|
17
|
+
* Render inline markup: escape HTML first, then parse **bold** and {color:text}.
|
|
18
|
+
* Also converts newlines to <br>.
|
|
19
|
+
* Safe: escapeHtml runs before any markup parsing, so XSS is impossible.
|
|
20
|
+
*/
|
|
21
|
+
export const renderInlineMarkup = (s) => {
|
|
22
|
+
let result = escapeHtml(s);
|
|
23
|
+
// **bold** → <strong>bold</strong>
|
|
24
|
+
result = result.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
|
|
25
|
+
// {color:text} → <span class="text-d-color">text</span>
|
|
26
|
+
result = result.replace(/\{([a-z]+):(.+?)\}/g, (_match, color, text) => {
|
|
27
|
+
if (inlineColorKeys.has(color)) {
|
|
28
|
+
return `<span class="text-${c(color)}">${text}</span>`;
|
|
29
|
+
}
|
|
30
|
+
return `{${color}:${text}}`;
|
|
31
|
+
});
|
|
32
|
+
// newlines to <br>
|
|
33
|
+
result = result.replace(/\n/g, "<br>");
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
/** Sanitize a value for safe use in CSS class names (alphanumeric + hyphens only) */
|
|
37
|
+
const sanitizeCssClass = (s) => {
|
|
38
|
+
return s.replace(/[^a-zA-Z0-9-]/g, "");
|
|
39
|
+
};
|
|
40
|
+
/** Sanitize a hex color value (hex digits only) */
|
|
41
|
+
export const sanitizeHex = (s) => {
|
|
42
|
+
return s.replace(/[^0-9A-Fa-f]/g, "");
|
|
43
|
+
};
|
|
44
|
+
/** Accent color key → Tailwind class segment: "primary" → "d-primary" */
|
|
45
|
+
export const c = (key) => {
|
|
46
|
+
return `d-${sanitizeCssClass(key)}`;
|
|
47
|
+
};
|
|
48
|
+
// ═══════════════════════════════════════════════════════════
|
|
49
|
+
// Shared micro-helpers for HTML generation
|
|
50
|
+
// ═══════════════════════════════════════════════════════════
|
|
51
|
+
/** Default accent color used when none is specified */
|
|
52
|
+
const DEFAULT_ACCENT = "primary";
|
|
53
|
+
/** Resolve accent color key with "primary" as fallback */
|
|
54
|
+
export const resolveAccent = (color) => color || DEFAULT_ACCENT;
|
|
55
|
+
/** Resolve item-level color with slide-level fallback then "primary" */
|
|
56
|
+
export const resolveItemColor = (itemColor, slideAccent) => itemColor || slideAccent || DEFAULT_ACCENT;
|
|
57
|
+
/** Render a horizontal accent bar (3px full-width). Pass extraClass for width/margin variants. */
|
|
58
|
+
export const accentBar = (colorKey, extraClass) => `<div class="h-[3px] bg-${c(colorKey)} shrink-0 ${extraClass || ""}"></div>`;
|
|
59
|
+
/** Render an optional block title (chart, mermaid, table) */
|
|
60
|
+
export const blockTitle = (title) => title ? `<p class="text-sm font-bold text-d-text font-body mb-2">${renderInlineMarkup(title)}</p>` : "";
|
|
61
|
+
/** Resolve change indicator color: "success" for positive (+), "danger" for negative */
|
|
62
|
+
export const resolveChangeColor = (change) => (/\+/.test(change) ? "success" : "danger");
|
|
63
|
+
/** Render the optional callout bar at the bottom of a slide, or empty string */
|
|
64
|
+
export const renderOptionalCallout = (callout) => {
|
|
65
|
+
if (!callout)
|
|
66
|
+
return "";
|
|
67
|
+
return `<div class="mt-auto pb-4">${renderCalloutBar(callout)}</div>`;
|
|
68
|
+
};
|
|
69
|
+
const colorKeyMap = {
|
|
70
|
+
bg: "bg",
|
|
71
|
+
bgCard: "card",
|
|
72
|
+
bgCardAlt: "alt",
|
|
73
|
+
text: "text",
|
|
74
|
+
textMuted: "muted",
|
|
75
|
+
textDim: "dim",
|
|
76
|
+
primary: "primary",
|
|
77
|
+
accent: "accent",
|
|
78
|
+
success: "success",
|
|
79
|
+
warning: "warning",
|
|
80
|
+
danger: "danger",
|
|
81
|
+
info: "info",
|
|
82
|
+
highlight: "highlight",
|
|
83
|
+
};
|
|
84
|
+
/** Build the Tailwind config JSON string for theme colors and fonts */
|
|
85
|
+
export const buildTailwindConfig = (theme) => {
|
|
86
|
+
const colorMap = {};
|
|
87
|
+
Object.entries(theme.colors).forEach(([k, v]) => {
|
|
88
|
+
const mapped = colorKeyMap[k];
|
|
89
|
+
if (mapped) {
|
|
90
|
+
colorMap[mapped] = `#${v}`;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return JSON.stringify({
|
|
94
|
+
theme: {
|
|
95
|
+
extend: {
|
|
96
|
+
colors: { d: colorMap },
|
|
97
|
+
fontFamily: {
|
|
98
|
+
title: [theme.fonts.title, "serif"],
|
|
99
|
+
body: [theme.fonts.body, "Arial", "sans-serif"],
|
|
100
|
+
mono: [theme.fonts.mono, "monospace"],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
/** Render a numbered circle badge */
|
|
107
|
+
export const numBadge = (num, colorKey) => {
|
|
108
|
+
return `<div class="w-10 h-10 rounded-full bg-${c(colorKey)} flex items-center justify-center shrink-0">
|
|
109
|
+
<span class="text-white font-bold text-sm">${num}</span>
|
|
110
|
+
</div>`;
|
|
111
|
+
};
|
|
112
|
+
/** Render an icon in a square container */
|
|
113
|
+
export const iconSquare = (icon, colorKey) => {
|
|
114
|
+
return `<div class="w-16 h-16 bg-d-alt flex items-center justify-center rounded">
|
|
115
|
+
<span class="text-2xl font-mono font-bold text-${c(colorKey)}">${escapeHtml(icon)}</span>
|
|
116
|
+
</div>`;
|
|
117
|
+
};
|
|
118
|
+
/** Render a card wrapper with accent top bar */
|
|
119
|
+
export const cardWrap = (accentColor, innerHtml, extraClass) => {
|
|
120
|
+
return `<div class="bg-d-card rounded-lg shadow-lg overflow-hidden flex flex-col min-h-0 ${sanitizeCssClass(extraClass || "")}">
|
|
121
|
+
${accentBar(accentColor)}
|
|
122
|
+
<div class="p-5 flex flex-col flex-1 min-h-0 overflow-hidden">
|
|
123
|
+
${innerHtml}
|
|
124
|
+
</div>
|
|
125
|
+
</div>`;
|
|
126
|
+
};
|
|
127
|
+
/** Render a callout bar at the bottom of a slide */
|
|
128
|
+
export const renderCalloutBar = (obj) => {
|
|
129
|
+
const color = obj.color || "warning";
|
|
130
|
+
const leftBar = obj.leftBar ? `<div class="w-1 bg-${c(color)} shrink-0"></div>` : "";
|
|
131
|
+
const align = obj.align === "center" ? "text-center" : "";
|
|
132
|
+
const inner = obj.label
|
|
133
|
+
? `<span class="font-bold text-${c(color)}">${renderInlineMarkup(obj.label)}:</span> <span class="text-d-muted">${renderInlineMarkup(obj.text)}</span>`
|
|
134
|
+
: `<span class="text-d-muted">${renderInlineMarkup(obj.text)}</span>`;
|
|
135
|
+
return `<div class="mx-12 bg-d-card rounded flex overflow-hidden ${align}">
|
|
136
|
+
${leftBar}
|
|
137
|
+
<div class="px-4 py-3 text-sm font-body flex-1">${inner}</div>
|
|
138
|
+
</div>`;
|
|
139
|
+
};
|
|
140
|
+
/** Render header text elements (stepLabel + title + subtitle) without wrapping div */
|
|
141
|
+
export const renderHeaderText = (data) => {
|
|
142
|
+
const accent = resolveAccent(data.accentColor);
|
|
143
|
+
const lines = [];
|
|
144
|
+
if (data.stepLabel) {
|
|
145
|
+
lines.push(`<p class="text-sm font-bold text-${c(accent)} font-body">${renderInlineMarkup(data.stepLabel)}</p>`);
|
|
146
|
+
}
|
|
147
|
+
lines.push(`<h2 class="text-[42px] leading-tight font-title font-bold text-d-text">${renderInlineMarkup(data.title)}</h2>`);
|
|
148
|
+
if (data.subtitle) {
|
|
149
|
+
lines.push(`<p class="text-[15px] text-d-dim mt-2 font-body">${renderInlineMarkup(data.subtitle)}</p>`);
|
|
150
|
+
}
|
|
151
|
+
return lines.join("\n");
|
|
152
|
+
};
|
|
153
|
+
/** Render the common slide header (accent bar + title + subtitle) */
|
|
154
|
+
export const slideHeader = (data) => {
|
|
155
|
+
const accent = resolveAccent(data.accentColor);
|
|
156
|
+
return [accentBar(accent), `<div class="px-12 pt-5 shrink-0">`, renderHeaderText(data), `</div>`].join("\n");
|
|
157
|
+
};
|
|
158
|
+
/** Render accent bar + vertically-centered wrapper with header text (used by stats, timeline) */
|
|
159
|
+
export const centeredSlideHeader = (data) => {
|
|
160
|
+
const accent = resolveAccent(data.accentColor);
|
|
161
|
+
return [accentBar(accent), `<div class="flex-1 flex flex-col justify-center px-12 min-h-0">`, renderHeaderText(data)].join("\n");
|
|
162
|
+
};
|
|
163
|
+
// ═══════════════════════════════════════════════════════════
|
|
164
|
+
// Counter-based ID generation (unique within a single slide)
|
|
165
|
+
// ═══════════════════════════════════════════════════════════
|
|
166
|
+
let slideIdCounter = 0;
|
|
167
|
+
/** Generate a unique ID with the given prefix (e.g. "chart-0", "mermaid-1") */
|
|
168
|
+
export const generateSlideId = (prefix) => `${prefix}-${slideIdCounter++}`;
|
|
169
|
+
/** Reset the ID counter (for testing) */
|
|
170
|
+
export const resetSlideIdCounter = () => {
|
|
171
|
+
slideIdCounter = 0;
|
|
172
|
+
};
|
|
173
|
+
// ═══════════════════════════════════════════════════════════
|
|
174
|
+
// Content block type detection
|
|
175
|
+
// ═══════════════════════════════════════════════════════════
|
|
176
|
+
/** Chart.js plugin CDN URLs keyed by chart type */
|
|
177
|
+
const CHART_PLUGIN_CDNS = {
|
|
178
|
+
sankey: "https://cdn.jsdelivr.net/npm/chartjs-chart-sankey",
|
|
179
|
+
treemap: "https://cdn.jsdelivr.net/npm/chartjs-chart-treemap@3",
|
|
180
|
+
};
|
|
181
|
+
/** Collect all content block arrays from a slide layout */
|
|
182
|
+
const collectContentArrays = (slide) => {
|
|
183
|
+
const arrays = [];
|
|
184
|
+
const pushIfPresent = (content) => {
|
|
185
|
+
if (content)
|
|
186
|
+
arrays.push(content);
|
|
187
|
+
};
|
|
188
|
+
switch (slide.layout) {
|
|
189
|
+
case "columns":
|
|
190
|
+
slide.columns.forEach((col) => pushIfPresent(col.content));
|
|
191
|
+
break;
|
|
192
|
+
case "comparison":
|
|
193
|
+
pushIfPresent(slide.left.content);
|
|
194
|
+
pushIfPresent(slide.right.content);
|
|
195
|
+
break;
|
|
196
|
+
case "grid":
|
|
197
|
+
slide.items.forEach((item) => pushIfPresent(item.content));
|
|
198
|
+
break;
|
|
199
|
+
case "split":
|
|
200
|
+
pushIfPresent(slide.left?.content);
|
|
201
|
+
pushIfPresent(slide.right?.content);
|
|
202
|
+
break;
|
|
203
|
+
case "matrix":
|
|
204
|
+
slide.cells.forEach((cell) => pushIfPresent(cell.content));
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
return arrays;
|
|
208
|
+
};
|
|
209
|
+
/** Collect chart type from a chart block */
|
|
210
|
+
const collectChartPlugin = (block, plugins) => {
|
|
211
|
+
if (block.type === "chart") {
|
|
212
|
+
const chartType = block.chartData?.type;
|
|
213
|
+
if (chartType && CHART_PLUGIN_CDNS[chartType]) {
|
|
214
|
+
plugins.add(CHART_PLUGIN_CDNS[chartType]);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
/** Detect whether chart or mermaid content blocks exist in a slide */
|
|
219
|
+
export const detectBlockTypes = (slide) => {
|
|
220
|
+
const arrays = collectContentArrays(slide);
|
|
221
|
+
let hasChart = false;
|
|
222
|
+
let hasMermaid = false;
|
|
223
|
+
const plugins = new Set();
|
|
224
|
+
arrays.forEach((blocks) => {
|
|
225
|
+
blocks.forEach((block) => {
|
|
226
|
+
if (block.type === "chart")
|
|
227
|
+
hasChart = true;
|
|
228
|
+
if (block.type === "mermaid")
|
|
229
|
+
hasMermaid = true;
|
|
230
|
+
collectChartPlugin(block, plugins);
|
|
231
|
+
if (block.type === "section" && block.content) {
|
|
232
|
+
block.content.forEach((inner) => {
|
|
233
|
+
if (inner.type === "chart")
|
|
234
|
+
hasChart = true;
|
|
235
|
+
if (inner.type === "mermaid")
|
|
236
|
+
hasMermaid = true;
|
|
237
|
+
collectChartPlugin(inner, plugins);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
return { hasChart, hasMermaid, chartPlugins: [...plugins] };
|
|
243
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mulmocast/deck",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MulmoCast deck DSL: JSON-described semantic slide layouts (stats, comparison, timeline, ...) rendered to Tailwind-based HTML",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"lint": "eslint src test",
|
|
11
|
+
"format": "prettier --write '{src,test}/**/*.ts'",
|
|
12
|
+
"test": "tsx --test ./test/test_*.ts",
|
|
13
|
+
"prepublishOnly": "yarn run build"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"zod": "^4.3.5"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@eslint/js": "^10.0.1",
|
|
23
|
+
"eslint": "^10.4.0",
|
|
24
|
+
"eslint-config-prettier": "^10.1.8",
|
|
25
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
26
|
+
"globals": "^17.6.0",
|
|
27
|
+
"prettier": "^3.8.3",
|
|
28
|
+
"tsx": "^4.22.3",
|
|
29
|
+
"typescript": "^6.0.3",
|
|
30
|
+
"typescript-eslint": "^8.59.4"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"mulmocast",
|
|
37
|
+
"deck",
|
|
38
|
+
"slide",
|
|
39
|
+
"dsl",
|
|
40
|
+
"tailwind",
|
|
41
|
+
"presentation"
|
|
42
|
+
],
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+ssh://git@github.com/receptron/mulmocast-deck.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/receptron/mulmocast-deck/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/receptron/mulmocast-deck#readme",
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=22.0.0"
|
|
54
|
+
}
|
|
55
|
+
}
|