@dversum/mcp-server 2.9.0 → 2.11.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 (51) hide show
  1. package/dist/src/client.d.ts +11 -0
  2. package/dist/src/client.d.ts.map +1 -1
  3. package/dist/src/client.js +51 -0
  4. package/dist/src/client.js.map +1 -1
  5. package/dist/src/index.d.ts.map +1 -1
  6. package/dist/src/index.js +19 -7
  7. package/dist/src/index.js.map +1 -1
  8. package/dist/src/tools/whiteboard-compose.d.ts +4 -0
  9. package/dist/src/tools/whiteboard-compose.d.ts.map +1 -0
  10. package/dist/src/tools/whiteboard-compose.js +359 -0
  11. package/dist/src/tools/whiteboard-compose.js.map +1 -0
  12. package/dist/src/tools/whiteboards.d.ts.map +1 -1
  13. package/dist/src/tools/whiteboards.js +150 -7
  14. package/dist/src/tools/whiteboards.js.map +1 -1
  15. package/dist/src/whiteboard/elements.d.ts +171 -0
  16. package/dist/src/whiteboard/elements.d.ts.map +1 -0
  17. package/dist/src/whiteboard/elements.js +121 -0
  18. package/dist/src/whiteboard/elements.js.map +1 -0
  19. package/dist/src/whiteboard/link.d.ts +22 -0
  20. package/dist/src/whiteboard/link.d.ts.map +1 -0
  21. package/dist/src/whiteboard/link.js +56 -0
  22. package/dist/src/whiteboard/link.js.map +1 -0
  23. package/dist/src/whiteboard/measure.d.ts +26 -0
  24. package/dist/src/whiteboard/measure.d.ts.map +1 -0
  25. package/dist/src/whiteboard/measure.js +64 -0
  26. package/dist/src/whiteboard/measure.js.map +1 -0
  27. package/dist/src/whiteboard/sections.d.ts +329 -0
  28. package/dist/src/whiteboard/sections.d.ts.map +1 -0
  29. package/dist/src/whiteboard/sections.js +757 -0
  30. package/dist/src/whiteboard/sections.js.map +1 -0
  31. package/dist/src/whiteboard/sections.spec.d.ts +2 -0
  32. package/dist/src/whiteboard/sections.spec.d.ts.map +1 -0
  33. package/dist/src/whiteboard/sections.spec.js +518 -0
  34. package/dist/src/whiteboard/sections.spec.js.map +1 -0
  35. package/dist/src/whiteboard/stock.d.ts +39 -0
  36. package/dist/src/whiteboard/stock.d.ts.map +1 -0
  37. package/dist/src/whiteboard/stock.js +91 -0
  38. package/dist/src/whiteboard/stock.js.map +1 -0
  39. package/dist/src/whiteboard/stock.spec.d.ts +2 -0
  40. package/dist/src/whiteboard/stock.spec.d.ts.map +1 -0
  41. package/dist/src/whiteboard/stock.spec.js +69 -0
  42. package/dist/src/whiteboard/stock.spec.js.map +1 -0
  43. package/dist/src/whiteboard/styles.d.ts +65 -0
  44. package/dist/src/whiteboard/styles.d.ts.map +1 -0
  45. package/dist/src/whiteboard/styles.js +63 -0
  46. package/dist/src/whiteboard/styles.js.map +1 -0
  47. package/dist/src/whiteboard/tokens.d.ts +114 -0
  48. package/dist/src/whiteboard/tokens.d.ts.map +1 -0
  49. package/dist/src/whiteboard/tokens.js +105 -0
  50. package/dist/src/whiteboard/tokens.js.map +1 -0
  51. package/package.json +5 -3
@@ -0,0 +1,757 @@
1
+ /**
2
+ * Composed whiteboard sections.
3
+ *
4
+ * A board built element by element reads as a scatter of boxes. A board
5
+ * built as a stack of sections reads as a page, because the sections share
6
+ * a content column, a spacing rhythm and a type hierarchy.
7
+ *
8
+ * Every function here is pure: it takes a position and some content, and
9
+ * returns positioned elements plus the exact height it consumed. The
10
+ * caller never computes a coordinate, and `composeBoard` never has to
11
+ * guess where the next section starts.
12
+ */
13
+ import { TYPE_SCALE, SPACE, GUTTER, RADIUS, STROKE, COLOR, SHADOW, SURFACE, CARD_PADDING, } from './tokens.js';
14
+ import { rect, ellipse, text, hrule, connector, icon, image, round, } from './elements.js';
15
+ import { textBlockHeight, textWidth } from './measure.js';
16
+ import { safeLinkHref } from './link.js';
17
+ import { resolveStyle, gapFor, DEFAULT_STYLE } from './styles.js';
18
+ // ---- Layout constants ---------------------------------------------------
19
+ /** Space from the canvas origin to the content column. */
20
+ export const CANVAS_MARGIN = SPACE.xxl;
21
+ /** Content column width. Callers may override for a narrower board. */
22
+ export const DEFAULT_COLUMN = 1200;
23
+ /**
24
+ * Hard cap on any run of body copy. At body size an average character is
25
+ * about 7 units wide, so 560 is roughly 80 characters. Body text running
26
+ * the full column is unreadable and is a large part of why wide boards
27
+ * look wrong, so every section clamps to this rather than filling.
28
+ */
29
+ export const MEASURE = 560;
30
+ /** Icon size inside a feature card. */
31
+ const CARD_ICON = 32;
32
+ /**
33
+ * How tall a hero stands in page layout.
34
+ *
35
+ * A landing page opens with one screen that holds a single idea. A hero
36
+ * that is only as tall as its own text reads as the first paragraph of a
37
+ * document instead, which is exactly what this board looked like. Roughly
38
+ * a laptop viewport at the default column width.
39
+ */
40
+ export const HERO_HEIGHT = 720;
41
+ /** Space under a section heading, before the thing it introduces. */
42
+ const HEADING_GAP = SPACE.xl;
43
+ // ---- Shared helpers -----------------------------------------------------
44
+ function lineHeightOf(role) {
45
+ return Math.ceil(TYPE_SCALE[role].size * TYPE_SCALE[role].lineHeight);
46
+ }
47
+ /** A text element sized to exactly the height its content will occupy. */
48
+ function block(id, x, y, width, content, role, opts) {
49
+ const family = opts.family ?? 'sans';
50
+ const weight = opts.weight ?? TYPE_SCALE[role].weight;
51
+ const height = textBlockHeight(content, width, role, family, weight);
52
+ return {
53
+ el: text(id, x, y, width, height, content, {
54
+ fontSize: TYPE_SCALE[role].size,
55
+ lineHeight: TYPE_SCALE[role].lineHeight,
56
+ color: opts.color,
57
+ fontWeight: weight,
58
+ fontFamily: family,
59
+ align: opts.align ?? 'left',
60
+ ...(opts.italic !== undefined ? { italic: opts.italic } : {}),
61
+ ...(opts.opacity !== undefined ? { opacity: opts.opacity } : {}),
62
+ }),
63
+ height,
64
+ };
65
+ }
66
+ /**
67
+ * The chart data union repeats the chart type as a discriminator. A caller
68
+ * that omits it gets a blank chart with no error, so fill it in rather
69
+ * than making every caller remember.
70
+ */
71
+ function withChartType(data, chartType) {
72
+ if (!data || typeof data !== 'object' || Array.isArray(data))
73
+ return data;
74
+ const obj = data;
75
+ return obj.type === undefined ? { ...obj, type: chartType } : obj;
76
+ }
77
+ function placeholderElements(id, x, y, w, h, brief) {
78
+ const glyph = 32;
79
+ const inner = Math.min(w - CARD_PADDING * 2, MEASURE);
80
+ const innerX = x + round((w - inner) / 2);
81
+ const briefH = textBlockHeight(brief, inner, 'body');
82
+ const stack = glyph + SPACE.md + briefH;
83
+ const top = y + round((h - stack) / 2);
84
+ return [
85
+ rect(id('slot'), x, y, w, h, { fill: COLOR.surfaceMuted, cornerRadius: RADIUS.md }),
86
+ icon(id('slot-icon'), x + round((w - glyph) / 2), top, glyph, { iconName: 'Image', color: COLOR.inkMuted }),
87
+ block(id('slot-brief'), innerX, top + glyph + SPACE.md, inner, brief, 'body', {
88
+ color: COLOR.inkMuted, align: 'center',
89
+ }).el,
90
+ ];
91
+ }
92
+ function visualElement(id, x, y, w, h, visual) {
93
+ if (visual.kind === 'placeholder') {
94
+ // Callers that want a placeholder go through visualElements, which can
95
+ // return the several elements a slot needs. Reaching here means the
96
+ // caller only handles one, so fall back to the frame alone.
97
+ return rect(id, x, y, w, h, { fill: COLOR.surfaceMuted, cornerRadius: RADIUS.md });
98
+ }
99
+ if (visual.kind === 'image') {
100
+ return image(id, x, y, w, h, { src: visual.src, ...(visual.alt !== undefined ? { alt: visual.alt } : {}) });
101
+ }
102
+ return {
103
+ id, type: 'chart', x: round(x), y: round(y), width: round(w), height: round(h),
104
+ rotation: 0, locked: false, opacity: 1, zIndex: 0,
105
+ chartType: visual.chartType,
106
+ ...(visual.title !== undefined ? { title: visual.title } : {}),
107
+ ...(visual.subtitle !== undefined ? { subtitle: visual.subtitle } : {}),
108
+ data: withChartType(visual.data, visual.chartType),
109
+ style: { accent: COLOR.accent, ...(visual.style ?? {}) },
110
+ };
111
+ }
112
+ /**
113
+ * An optional heading above a group of things.
114
+ *
115
+ * A landing page names its sections. A bare grid of cards with no line
116
+ * telling you what you are looking at is the clearest way a page reads as
117
+ * a document, and it was missing from every section here.
118
+ */
119
+ function headingBlock(env, title, intro, y) {
120
+ if (!title && !intro)
121
+ return { elements: [], height: 0 };
122
+ const st = env.style;
123
+ const align = st.centerHeadings ? 'center' : 'left';
124
+ const width = st.centerHeadings ? Math.min(env.width, MEASURE + SPACE.xxl * 2) : env.width;
125
+ const x = st.centerHeadings ? env.x + round((env.width - width) / 2) : env.x;
126
+ const elements = [];
127
+ let cursor = y;
128
+ if (title) {
129
+ const t = block(env.id('section-title'), x, cursor, width, title, 'headline', {
130
+ color: COLOR.ink, family: st.display, align,
131
+ });
132
+ elements.push(t.el);
133
+ cursor += t.height;
134
+ }
135
+ if (intro) {
136
+ if (title)
137
+ cursor += SPACE.md;
138
+ const introW = Math.min(width, MEASURE);
139
+ const introX = st.centerHeadings ? env.x + round((env.width - introW) / 2) : env.x;
140
+ const i = block(env.id('section-intro'), introX, cursor, introW, intro, 'body', {
141
+ color: COLOR.inkMuted, family: st.body, align,
142
+ });
143
+ elements.push(i.el);
144
+ cursor += i.height;
145
+ }
146
+ return { elements, height: cursor - y + HEADING_GAP };
147
+ }
148
+ /** One visual, however many elements that takes. */
149
+ function visualElements(env, key, x, y, w, h, visual) {
150
+ if (visual.kind === 'placeholder') {
151
+ return placeholderElements((sfx) => env.id(`${key}-${sfx}`), x, y, w, h, visual.brief);
152
+ }
153
+ return [visualElement(env.id(key), x, y, w, h, visual)];
154
+ }
155
+ /**
156
+ * The only section allowed display type, which is what makes the top of a
157
+ * board read as the top. An accent rule stands in for the all-caps eyebrow
158
+ * label that marks a page as generated.
159
+ */
160
+ export function hero(env, c) {
161
+ const st = env.style;
162
+ const els = [];
163
+ const hasVisual = !!c.visual;
164
+ const centred = st.heroAlign === 'center' && !hasVisual;
165
+ const textW = hasVisual
166
+ ? round((env.width - GUTTER) / 2)
167
+ : centred ? env.width : Math.min(env.width, 820);
168
+ const align = centred ? 'center' : 'left';
169
+ // In page layout the hero claims a screen and its content sits in the
170
+ // middle of it. Measure first at a throwaway origin, then place.
171
+ const minHeight = env.layout === 'page' ? HERO_HEIGHT : 0;
172
+ const measured = heroContentHeight(env, c, textW, centred);
173
+ const height = Math.max(measured, minHeight);
174
+ let y = env.y + round(Math.max(0, height - measured) / 2);
175
+ // The mark above the headline is the loudest single tell that two boards
176
+ // came from the same template, so each style answers it differently and
177
+ // one style declines to have one at all.
178
+ if (st.heroMark === 'accent-rule') {
179
+ const rx = centred ? env.x + round((env.width - 64) / 2) : env.x;
180
+ els.push(hrule(env.id('rule'), rx, y, 64, { stroke: COLOR.accent, strokeWidth: STROKE.strong }));
181
+ y += STROKE.strong + SPACE.lg;
182
+ }
183
+ else if (st.heroMark === 'hairline') {
184
+ els.push(hrule(env.id('rule'), env.x, y, env.width, { stroke: COLOR.border, strokeWidth: STROKE.hairline }));
185
+ y += STROKE.hairline + SPACE.md;
186
+ }
187
+ const head = block(env.id('headline'), env.x, y, textW, c.headline, st.heroRole, {
188
+ color: COLOR.ink, family: st.display, align,
189
+ });
190
+ els.push(head.el);
191
+ y += head.height;
192
+ if (c.subline) {
193
+ y += SPACE.md;
194
+ const subW = centred ? Math.min(env.width, MEASURE + SPACE.xxl) : Math.min(textW, MEASURE);
195
+ const subX = centred ? env.x + round((env.width - subW) / 2) : env.x;
196
+ const sub = block(env.id('subline'), subX, y, subW, c.subline, 'title', {
197
+ color: COLOR.inkMuted, weight: 'normal', family: st.body, align,
198
+ });
199
+ els.push(sub.el);
200
+ y += sub.height;
201
+ }
202
+ if (c.cta) {
203
+ y += SPACE.lg;
204
+ const btnH = 48;
205
+ const btnW = round(textWidth(c.cta.label, TYPE_SCALE.body.size, 'bold') + SPACE.lg * 2);
206
+ const btnX = centred ? env.x + round((env.width - btnW) / 2) : env.x;
207
+ const href = safeLinkHref(c.cta.href) ?? undefined;
208
+ els.push(rect(env.id('cta'), btnX, y, btnW, btnH, {
209
+ fill: COLOR.ink, cornerRadius: RADIUS.pill, ...(href ? { link: href } : {}),
210
+ }));
211
+ els.push(text(env.id('cta-label'), btnX, y + round((btnH - lineHeightOf('body')) / 2), btnW, lineHeightOf('body'), c.cta.label, {
212
+ fontSize: TYPE_SCALE.body.size, lineHeight: TYPE_SCALE.body.lineHeight,
213
+ color: COLOR.surface, fontWeight: 'bold', align: 'center', fontFamily: st.body,
214
+ ...(href ? { link: href } : {}),
215
+ }));
216
+ y += btnH;
217
+ }
218
+ if (c.visual) {
219
+ const vw = env.width - textW - GUTTER;
220
+ // The visual matches the hero, not the text, so the two halves of the
221
+ // first screen balance instead of a tall column beside a short box.
222
+ const vh = Math.max(measured, Math.min(height, 520));
223
+ const vy = env.y + round(Math.max(0, height - vh) / 2);
224
+ els.push(...visualElements(env, 'visual', env.x + textW + GUTTER, vy, vw, vh, c.visual));
225
+ }
226
+ return { elements: els, height };
227
+ }
228
+ /** Height of the hero's text stack, before any screen-filling. */
229
+ function heroContentHeight(env, c, textW, centred) {
230
+ const st = env.style;
231
+ let h = 0;
232
+ if (st.heroMark === 'accent-rule')
233
+ h += STROKE.strong + SPACE.lg;
234
+ else if (st.heroMark === 'hairline')
235
+ h += STROKE.hairline + SPACE.md;
236
+ h += textBlockHeight(c.headline, textW, st.heroRole, st.display);
237
+ if (c.subline) {
238
+ const subW = centred ? Math.min(env.width, MEASURE + SPACE.xxl) : Math.min(textW, MEASURE);
239
+ h += SPACE.md + textBlockHeight(c.subline, subW, 'title', st.body, 'normal');
240
+ }
241
+ if (c.cta)
242
+ h += SPACE.lg + 48;
243
+ return h;
244
+ }
245
+ /**
246
+ * Card heights are equalised to the tallest, so the row bottoms align. A
247
+ * grid whose cards each stop at their own text is the single most common
248
+ * reason a composed board looks ragged.
249
+ */
250
+ export function featureGrid(env, c) {
251
+ const st = env.style;
252
+ const items = c.items;
253
+ const cols = c.columns ?? (items.length <= 2 ? 2 : items.length === 4 ? 4 : 3);
254
+ const cardW = round((env.width - GUTTER * (cols - 1)) / cols);
255
+ const pad = st.cards === 'divided' ? 0 : CARD_PADDING;
256
+ const inner = cardW - pad * 2;
257
+ const lead = st.cards === 'divided' ? SPACE.md : 0;
258
+ const contentHeights = items.map((it) => lead + CARD_ICON + SPACE.md
259
+ + textBlockHeight(it.title, inner, 'title', st.display)
260
+ + SPACE.sm
261
+ + textBlockHeight(it.body, inner, 'body', st.body));
262
+ const cardH = Math.max(...contentHeights) + pad * 2;
263
+ const heading = headingBlock(env, c.title, c.intro, env.y);
264
+ const gridTop = env.y + heading.height;
265
+ const els = [...heading.elements];
266
+ items.forEach((it, i) => {
267
+ const col = i % cols;
268
+ const row = Math.floor(i / cols);
269
+ const cx = env.x + col * (cardW + GUTTER);
270
+ const cy = gridTop + row * (cardH + GUTTER);
271
+ // raised: a white card lifted off the ground.
272
+ // flat: a muted panel, no shadow, no lift.
273
+ // divided: no panel at all, a hairline doing the separating.
274
+ if (st.cards === 'raised') {
275
+ els.push(rect(env.id(`card-${i}`), cx, cy, cardW, cardH, {
276
+ fill: SURFACE.card.fill, cornerRadius: SURFACE.card.cornerRadius, shadow: { ...SHADOW.soft },
277
+ }));
278
+ }
279
+ else if (st.cards === 'flat') {
280
+ els.push(rect(env.id(`card-${i}`), cx, cy, cardW, cardH, {
281
+ fill: COLOR.surfaceMuted, cornerRadius: RADIUS.sm,
282
+ }));
283
+ }
284
+ else {
285
+ els.push(hrule(env.id(`rule-${i}`), cx, cy, cardW, { stroke: COLOR.border, strokeWidth: STROKE.hairline }));
286
+ }
287
+ const pad = st.cards === 'divided' ? 0 : CARD_PADDING;
288
+ els.push(icon(env.id(`icon-${i}`), cx + pad, cy + pad + (st.cards === 'divided' ? SPACE.md : 0), CARD_ICON, {
289
+ iconName: it.icon, color: COLOR.accentStrong,
290
+ }));
291
+ let ty = cy + pad + (st.cards === 'divided' ? SPACE.md : 0) + CARD_ICON + SPACE.md;
292
+ const title = block(env.id(`title-${i}`), cx + pad, ty, inner, it.title, 'title', {
293
+ color: COLOR.ink, family: st.display,
294
+ });
295
+ els.push(title.el);
296
+ ty += title.height + SPACE.sm;
297
+ els.push(block(env.id(`body-${i}`), cx + pad, ty, inner, it.body, 'body', {
298
+ color: COLOR.inkMuted, family: st.body,
299
+ }).el);
300
+ });
301
+ const rows = Math.ceil(items.length / cols);
302
+ return { elements: els, height: heading.height + rows * cardH + (rows - 1) * GUTTER };
303
+ }
304
+ /**
305
+ * Plain text on an ink panel rather than KPI chart elements: a band needs
306
+ * one shared baseline across every figure, and the chart element brings
307
+ * its own card chrome that would fight the panel.
308
+ */
309
+ export function statBand(env, c) {
310
+ const st = env.style;
311
+ const bare = st.statBand === 'bare';
312
+ const onDark = st.statBand === 'ink';
313
+ const pad = bare ? SPACE.md : SPACE.xl;
314
+ const n = c.stats.length;
315
+ const cellW = round((env.width - (bare ? 0 : CARD_PADDING * 2)) / n);
316
+ const valueH = lineHeightOf('headline');
317
+ const deltaH = c.stats.some((s) => s.delta) ? lineHeightOf('caption') + SPACE.xs : 0;
318
+ const labelH = lineHeightOf('caption');
319
+ const height = pad * 2 + valueH + deltaH + SPACE.sm + labelH;
320
+ // A number does not need a panel to be loud. Two styles give it one
321
+ // anyway, in opposite colours; one lets it sit on the page under a rule.
322
+ // A dark or accent band reaching both edges of the window is the single
323
+ // clearest "this is a page" signal available here. Bare figures stay in
324
+ // the column: a rule that runs off the screen is just a stray line.
325
+ const bleeds = !bare && env.style.bleedBands;
326
+ const panelX = bleeds ? env.bleedX : env.x;
327
+ const panelW = bleeds ? env.bleedWidth : env.width;
328
+ const els = bare
329
+ ? [hrule(env.id('rule'), env.x, env.y, env.width, { stroke: COLOR.border, strokeWidth: STROKE.hairline })]
330
+ : [rect(env.id('panel'), panelX, env.y, panelW, height, {
331
+ fill: onDark ? SURFACE.ink.fill : COLOR.accent, cornerRadius: bleeds ? 0 : RADIUS.lg,
332
+ })];
333
+ const valueColor = onDark ? COLOR.surface : COLOR.ink;
334
+ const labelColor = onDark ? COLOR.surfaceMuted : COLOR.ink;
335
+ const labelOpacity = onDark ? 0.65 : bare ? 1 : 0.7;
336
+ c.stats.forEach((s, i) => {
337
+ const cx = env.x + (bare ? 0 : CARD_PADDING) + i * cellW;
338
+ let cy = env.y + pad;
339
+ els.push(text(env.id(`value-${i}`), cx, cy, cellW, valueH, s.value, {
340
+ fontSize: TYPE_SCALE.headline.size, lineHeight: TYPE_SCALE.headline.lineHeight,
341
+ color: valueColor, fontWeight: 'bold', align: bare ? 'left' : 'center',
342
+ fontFamily: st.display,
343
+ }));
344
+ cy += valueH;
345
+ if (s.delta) {
346
+ cy += SPACE.xs;
347
+ els.push(text(env.id(`delta-${i}`), cx, cy, cellW, lineHeightOf('caption'), s.delta.text, {
348
+ fontSize: TYPE_SCALE.caption.size,
349
+ lineHeight: TYPE_SCALE.caption.lineHeight,
350
+ color: onDark || bare ? (s.delta.tone === 'down' ? COLOR.danger : COLOR.success) : COLOR.ink,
351
+ fontWeight: 'bold', align: bare ? 'left' : 'center',
352
+ }));
353
+ cy += lineHeightOf('caption');
354
+ }
355
+ cy += SPACE.sm;
356
+ // Off-white at reduced opacity, because inkMuted is unreadable on ink.
357
+ els.push(text(env.id(`label-${i}`), cx, cy, cellW, labelH, s.label, {
358
+ fontSize: TYPE_SCALE.caption.size, lineHeight: TYPE_SCALE.caption.lineHeight,
359
+ color: bare ? COLOR.inkMuted : labelColor, align: bare ? 'left' : 'center',
360
+ opacity: labelOpacity, fontFamily: st.body,
361
+ }));
362
+ });
363
+ return { elements: els, height, bleeds };
364
+ }
365
+ export function split(env, c) {
366
+ const half = round((env.width - GUTTER) / 2);
367
+ const textW = Math.min(half, MEASURE);
368
+ const textLeft = (c.side ?? 'left') === 'left';
369
+ const textX = textLeft ? env.x : env.x + half + GUTTER;
370
+ const visualX = textLeft ? env.x + half + GUTTER : env.x;
371
+ const els = [];
372
+ let y = env.y;
373
+ const title = block(env.id('title'), textX, y, textW, c.title, 'headline', { color: COLOR.ink, family: env.style.display });
374
+ els.push(title.el);
375
+ y += title.height + SPACE.md;
376
+ const body = block(env.id('body'), textX, y, textW, c.body, 'body', { color: COLOR.inkMuted, family: env.style.body });
377
+ els.push(body.el);
378
+ y += body.height;
379
+ const textHeight = y - env.y;
380
+ const visualH = Math.max(textHeight, 320);
381
+ els.push(...visualElements(env, 'visual', visualX, env.y, half, visualH, c.visual));
382
+ return { elements: els, height: Math.max(textHeight, visualH) };
383
+ }
384
+ /**
385
+ * The one section where numbered markers are honest, because the content
386
+ * genuinely is a sequence. Connectors draw the actual progression rather
387
+ * than leaving the reader to infer it from left-to-right order.
388
+ */
389
+ export function steps(env, c) {
390
+ const n = c.steps.length;
391
+ const dot = 48;
392
+ const colW = round((env.width - GUTTER * (n - 1)) / n);
393
+ const heading = headingBlock(env, c.title, c.intro, env.y);
394
+ const top = env.y + heading.height;
395
+ const els = [...heading.elements];
396
+ const dotIds = [];
397
+ let maxBelow = 0;
398
+ c.steps.forEach((s, i) => {
399
+ const cx = env.x + i * (colW + GUTTER);
400
+ const dotId = env.id(`dot-${i}`);
401
+ dotIds.push(dotId);
402
+ els.push(ellipse(dotId, cx + (colW - dot) / 2, top, dot, dot, {
403
+ fill: COLOR.accent,
404
+ text: String(i + 1),
405
+ fontSize: TYPE_SCALE.title.size,
406
+ fontColor: COLOR.ink,
407
+ fontWeight: 'bold',
408
+ }));
409
+ let ty = top + dot + SPACE.md;
410
+ const title = block(env.id(`title-${i}`), cx, ty, colW, s.title, 'title', { color: COLOR.ink, align: 'center', family: env.style.display });
411
+ els.push(title.el);
412
+ ty += title.height;
413
+ if (s.body) {
414
+ ty += SPACE.sm;
415
+ const body = block(env.id(`body-${i}`), cx, ty, colW, s.body, 'body', { color: COLOR.inkMuted, align: 'center' });
416
+ els.push(body.el);
417
+ ty += body.height;
418
+ }
419
+ maxBelow = Math.max(maxBelow, ty - (top + dot));
420
+ });
421
+ for (let i = 1; i < dotIds.length; i++) {
422
+ els.push(connector(env.id(`link-${i}`), dotIds[i - 1], dotIds[i], {
423
+ stroke: COLOR.border, strokeWidth: STROKE.regular,
424
+ }));
425
+ }
426
+ return { elements: els, height: heading.height + dot + maxBelow };
427
+ }
428
+ /** Structurally the quietest section and typographically the loudest. */
429
+ export function quote(env, c) {
430
+ const pad = SPACE.xl;
431
+ const inner = Math.min(env.width - pad * 2, 760);
432
+ const innerX = env.x + round((env.width - inner) / 2);
433
+ const quoteFamily = env.style.display === 'serif' ? 'sans' : 'serif';
434
+ const quoteH = textBlockHeight(c.quote, inner, 'headline', quoteFamily);
435
+ const attrH = c.attribution ? lineHeightOf('caption') + SPACE.md : 0;
436
+ const height = pad * 2 + quoteH + attrH;
437
+ const els = [
438
+ rect(env.id('panel'), env.x, env.y, env.width, height, {
439
+ fill: SURFACE.muted.fill, cornerRadius: RADIUS.lg,
440
+ }),
441
+ block(env.id('quote'), innerX, env.y + pad, inner, c.quote, 'headline', {
442
+ color: COLOR.ink, align: 'center', family: quoteFamily,
443
+ }).el,
444
+ ];
445
+ if (c.attribution) {
446
+ els.push(text(env.id('attribution'), innerX, env.y + pad + quoteH + SPACE.md, inner, lineHeightOf('caption'), c.attribution, {
447
+ fontSize: TYPE_SCALE.caption.size, lineHeight: TYPE_SCALE.caption.lineHeight, color: COLOR.inkMuted, align: 'center',
448
+ }));
449
+ }
450
+ return { elements: els, height };
451
+ }
452
+ export function chartPanel(env, c) {
453
+ const inner = env.width - CARD_PADDING * 2;
454
+ const chartH = c.chartHeight ?? 320;
455
+ const titleH = textBlockHeight(c.title, inner, 'title');
456
+ const capH = c.caption ? textBlockHeight(c.caption, inner, 'caption') + SPACE.sm : 0;
457
+ const height = CARD_PADDING * 2 + titleH + SPACE.md + chartH + capH;
458
+ const els = [
459
+ rect(env.id('panel'), env.x, env.y, env.width, height, {
460
+ fill: SURFACE.card.fill, cornerRadius: SURFACE.card.cornerRadius, shadow: { ...SHADOW.soft },
461
+ }),
462
+ ];
463
+ let y = env.y + CARD_PADDING;
464
+ els.push(block(env.id('title'), env.x + CARD_PADDING, y, inner, c.title, 'title', { color: COLOR.ink, family: env.style.display }).el);
465
+ y += titleH + SPACE.md;
466
+ els.push(visualElement(env.id('chart'), env.x + CARD_PADDING, y, inner, chartH, c.chart));
467
+ y += chartH;
468
+ if (c.caption) {
469
+ y += SPACE.sm;
470
+ els.push(block(env.id('caption'), env.x + CARD_PADDING, y, inner, c.caption, 'caption', { color: COLOR.inkMuted }).el);
471
+ }
472
+ return { elements: els, height };
473
+ }
474
+ /**
475
+ * The button label carries no arrow glyph. An appended arrow is one of the
476
+ * clearest tells of a generated page, and on a static board it also
477
+ * promises an interaction that does not exist.
478
+ */
479
+ export function ctaBand(env, c) {
480
+ const pad = SPACE.xl;
481
+ const btnH = 48;
482
+ const btnW = round(textWidth(c.buttonLabel, TYPE_SCALE.body.size, 'bold') + SPACE.lg * 2);
483
+ const textW = env.width - pad * 2 - btnW - GUTTER;
484
+ const headH = textBlockHeight(c.headline, textW, 'headline');
485
+ const noteH = c.note ? textBlockHeight(c.note, textW, 'caption') + SPACE.sm : 0;
486
+ const stack = headH + noteH;
487
+ const height = pad * 2 + Math.max(stack, btnH);
488
+ const bleeds = env.style.bleedBands;
489
+ const els = [
490
+ rect(env.id('panel'), bleeds ? env.bleedX : env.x, env.y, bleeds ? env.bleedWidth : env.width, height, {
491
+ fill: SURFACE.accent.fill, cornerRadius: bleeds ? 0 : RADIUS.lg,
492
+ }),
493
+ ];
494
+ let y = env.y + pad + round(Math.max(0, btnH - stack) / 2);
495
+ els.push(block(env.id('headline'), env.x + pad, y, textW, c.headline, 'headline', { color: COLOR.ink, family: env.style.display }).el);
496
+ y += headH;
497
+ if (c.note) {
498
+ y += SPACE.sm;
499
+ els.push(block(env.id('note'), env.x + pad, y, textW, c.note, 'caption', { color: COLOR.ink, opacity: 0.7 }).el);
500
+ }
501
+ const btnX = env.x + env.width - pad - btnW;
502
+ const btnY = env.y + round((height - btnH) / 2);
503
+ // Both the shape and its label carry the link, so the whole button is
504
+ // clickable rather than just the few pixels of text in the middle.
505
+ const href = safeLinkHref(c.href) ?? undefined;
506
+ els.push(rect(env.id('button'), btnX, btnY, btnW, btnH, {
507
+ fill: COLOR.ink, cornerRadius: RADIUS.pill, ...(href ? { link: href } : {}),
508
+ }));
509
+ els.push(text(env.id('button-label'), btnX, btnY + round((btnH - lineHeightOf('body')) / 2), btnW, lineHeightOf('body'), c.buttonLabel, {
510
+ fontSize: TYPE_SCALE.body.size, lineHeight: TYPE_SCALE.body.lineHeight, color: COLOR.surface, fontWeight: 'bold', align: 'center',
511
+ ...(href ? { link: href } : {}),
512
+ }));
513
+ return { elements: els, height, bleeds };
514
+ }
515
+ /**
516
+ * The first column is the row label and carries the longest strings, so it
517
+ * gets half again the width of the rest. Equal columns look tidy in the
518
+ * abstract and wrap badly in practice.
519
+ */
520
+ export function comparisonTable(env, c) {
521
+ const cols = c.columns.length;
522
+ const cellHeight = 44;
523
+ const units = 1.5 + (cols - 1);
524
+ const unit = env.width / units;
525
+ const cellWidths = [round(unit * 1.5), ...Array(cols - 1).fill(round(unit))];
526
+ const rowCount = c.rows.length + 1;
527
+ const height = rowCount * cellHeight;
528
+ return {
529
+ elements: [{
530
+ id: env.id('table'),
531
+ type: 'table',
532
+ x: round(env.x), y: round(env.y), width: round(env.width), height: round(height),
533
+ rotation: 0, locked: false, opacity: 1, zIndex: 0,
534
+ rows: rowCount,
535
+ cols,
536
+ cells: [c.columns, ...c.rows],
537
+ cellWidths,
538
+ cellHeight,
539
+ headerBg: COLOR.surfaceMuted,
540
+ cellBg: COLOR.surface,
541
+ borderColor: COLOR.border,
542
+ fontSize: TYPE_SCALE.body.size,
543
+ textColor: COLOR.ink,
544
+ }],
545
+ height,
546
+ };
547
+ }
548
+ export function timeline(env, c) {
549
+ const n = c.events.length;
550
+ const marker = 14;
551
+ const colW = round(env.width / n);
552
+ const labelW = colW - SPACE.md;
553
+ const dateH = lineHeightOf('caption');
554
+ const els = [];
555
+ const railY = env.y + dateH + SPACE.sm + marker / 2;
556
+ els.push(hrule(env.id('rail'), env.x, railY, env.width, {
557
+ stroke: COLOR.border, strokeWidth: STROKE.regular,
558
+ }));
559
+ let maxBelow = 0;
560
+ c.events.forEach((e, i) => {
561
+ const centre = env.x + colW * i + colW / 2;
562
+ const lx = round(centre - labelW / 2);
563
+ els.push(block(env.id(`date-${i}`), lx, env.y, labelW, e.date, 'caption', {
564
+ color: COLOR.inkMuted, align: 'center',
565
+ }).el);
566
+ els.push(ellipse(env.id(`marker-${i}`), round(centre - marker / 2), round(railY - marker / 2), marker, marker, {
567
+ fill: COLOR.accentStrong,
568
+ }));
569
+ let ty = railY + marker / 2 + SPACE.md;
570
+ const title = block(env.id(`title-${i}`), lx, ty, labelW, e.title, 'body', {
571
+ color: COLOR.ink, align: 'center', weight: 'bold',
572
+ });
573
+ els.push(title.el);
574
+ ty += title.height;
575
+ if (e.body) {
576
+ ty += SPACE.xs;
577
+ const body = block(env.id(`body-${i}`), lx, ty, labelW, e.body, 'caption', {
578
+ color: COLOR.inkMuted, align: 'center',
579
+ });
580
+ els.push(body.el);
581
+ ty += body.height;
582
+ }
583
+ maxBelow = Math.max(maxBelow, ty - railY);
584
+ });
585
+ return { elements: els, height: dateH + SPACE.sm + marker / 2 + maxBelow };
586
+ }
587
+ export function logoRow(env, c) {
588
+ const size = 64;
589
+ const n = c.items.length;
590
+ const colW = round(env.width / n);
591
+ const els = [];
592
+ let y = env.y;
593
+ if (c.label) {
594
+ const label = block(env.id('label'), env.x, y, env.width, c.label, 'caption', {
595
+ color: COLOR.inkMuted, align: 'center',
596
+ });
597
+ els.push(label.el);
598
+ y += label.height + SPACE.md;
599
+ }
600
+ c.items.forEach((it, i) => {
601
+ const ix = round(env.x + colW * i + (colW - size) / 2);
602
+ if (it.kind === 'icon') {
603
+ els.push(icon(env.id(`item-${i}`), ix, y, size, { iconName: it.iconName, color: COLOR.inkMuted }));
604
+ }
605
+ else {
606
+ els.push(image(env.id(`item-${i}`), ix, y, size, size, {
607
+ src: it.src, ...(it.alt !== undefined ? { alt: it.alt } : {}),
608
+ }));
609
+ }
610
+ });
611
+ return { elements: els, height: y - env.y + size };
612
+ }
613
+ /**
614
+ * Items are positioned separately rather than joined with middle dots. A
615
+ * dot-joined meta string is a generated-page tell, and separate elements
616
+ * also stay legible when the board is exported at a smaller scale.
617
+ */
618
+ export function footerMeta(env, c) {
619
+ const n = c.items.length;
620
+ const colW = round(env.width / n);
621
+ const capH = lineHeightOf('caption');
622
+ const els = [
623
+ hrule(env.id('divider'), env.x, env.y, env.width, {
624
+ stroke: COLOR.border, strokeWidth: STROKE.hairline,
625
+ }),
626
+ ];
627
+ c.items.forEach((item, i) => {
628
+ els.push(text(env.id(`item-${i}`), env.x + colW * i, env.y + STROKE.hairline + SPACE.md, colW, capH, item, {
629
+ fontSize: TYPE_SCALE.caption.size,
630
+ lineHeight: TYPE_SCALE.caption.lineHeight,
631
+ color: COLOR.inkMuted,
632
+ align: i === 0 ? 'left' : i === n - 1 ? 'right' : 'center',
633
+ }));
634
+ });
635
+ return { elements: els, height: STROKE.hairline + SPACE.md + capH };
636
+ }
637
+ /**
638
+ * A full-width picture with an optional caption. Wide and short on
639
+ * purpose: a full-column image at its natural aspect ratio would dwarf
640
+ * every section around it.
641
+ */
642
+ export function imageBand(env, c) {
643
+ const bandH = c.height ?? round(env.width / 3);
644
+ const els = visualElements(env, 'visual', env.x, env.y, env.width, bandH, c.visual);
645
+ let height = bandH;
646
+ if (c.caption) {
647
+ const capH = textBlockHeight(c.caption, env.width, 'caption');
648
+ els.push(block(env.id('caption'), env.x, env.y + bandH + SPACE.sm, env.width, c.caption, 'caption', {
649
+ color: COLOR.inkMuted, align: 'center',
650
+ }).el);
651
+ height += SPACE.sm + capH;
652
+ }
653
+ return { elements: els, height };
654
+ }
655
+ export const SECTION_TYPES = [
656
+ 'hero', 'featureGrid', 'statBand', 'split', 'steps', 'quote',
657
+ 'chartPanel', 'ctaBand', 'comparisonTable', 'timeline', 'logoRow', 'footerMeta', 'imageBand',
658
+ ];
659
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
660
+ const RENDERERS = {
661
+ hero, featureGrid, statBand, split, steps, quote,
662
+ chartPanel, ctaBand, comparisonTable, timeline, logoRow, footerMeta, imageBand,
663
+ };
664
+ /**
665
+ * A screen-shaped page for slide layout. 16:9 against the default column,
666
+ * so a board reads like a deck rather than a scroll.
667
+ */
668
+ export const SLIDE_HEIGHT = Math.round(DEFAULT_COLUMN * 9 / 16);
669
+ /**
670
+ * Stack sections down one content column.
671
+ *
672
+ * Each section reports the height it consumed, so the next one starts a
673
+ * fixed gap below it. That is the whole reason sections never overlap and
674
+ * the rhythm of the page stays even regardless of how much text a caller
675
+ * supplies.
676
+ */
677
+ export function composeBoard(specs, opts = {}) {
678
+ const width = opts.columnWidth ?? DEFAULT_COLUMN;
679
+ const margin = opts.margin ?? CANVAS_MARGIN;
680
+ const style = resolveStyle(opts.style ?? DEFAULT_STYLE);
681
+ const gap = gapFor(style);
682
+ const layout = opts.layout ?? 'page';
683
+ const elements = [];
684
+ const bleedIds = new Set();
685
+ let y = margin;
686
+ specs.forEach((spec, index) => {
687
+ const render = RENDERERS[spec.type];
688
+ if (!render)
689
+ throw new Error(`Unknown section type: ${spec.type}`);
690
+ const env = {
691
+ x: margin,
692
+ y,
693
+ width,
694
+ id: (suffix) => `s${index}-${spec.type}-${suffix}`,
695
+ style,
696
+ index: index + 1,
697
+ layout,
698
+ bleedX: 0,
699
+ bleedWidth: width + margin * 2,
700
+ };
701
+ const out = render(env, spec.content);
702
+ for (const el of out.elements) {
703
+ el.zIndex = elements.length;
704
+ if (out.bleeds)
705
+ bleedIds.add(el.id);
706
+ elements.push(el);
707
+ }
708
+ y += out.height + gap;
709
+ });
710
+ // The trailing gap after the last section is not part of the content.
711
+ const height = specs.length ? y - gap - margin : 0;
712
+ return {
713
+ elements,
714
+ layerOrder: elements.map((el) => el.id),
715
+ bleedIds: [...bleedIds],
716
+ height: round(height),
717
+ width,
718
+ };
719
+ }
720
+ /**
721
+ * Break the same section list into screen-sized pages.
722
+ *
723
+ * This is the other way to read a board: instead of one long column you
724
+ * scroll, a stack of pages you step through, each one filling a screen.
725
+ * Sections are packed greedily and never split, because half a feature
726
+ * grid at a page break is worse than an uneven page.
727
+ */
728
+ export function composeSlides(specs, opts = {}) {
729
+ const asSlides = { ...opts, layout: 'slides' };
730
+ const margin = opts.margin ?? CANVAS_MARGIN;
731
+ const slideHeight = opts.slideHeight ?? SLIDE_HEIGHT;
732
+ const usable = slideHeight - margin * 2;
733
+ const gap = gapFor(resolveStyle(opts.style ?? DEFAULT_STYLE));
734
+ // Measure once, at the position each section will actually occupy later.
735
+ const groups = [];
736
+ let current = [];
737
+ let used = 0;
738
+ for (const spec of specs) {
739
+ const probe = composeBoard([spec], { ...asSlides, margin });
740
+ const h = probe.height;
741
+ const needed = current.length ? used + gap + h : h;
742
+ if (current.length && needed > usable) {
743
+ groups.push(current);
744
+ current = [spec];
745
+ used = h;
746
+ }
747
+ else {
748
+ current.push(spec);
749
+ used = needed;
750
+ }
751
+ }
752
+ if (current.length)
753
+ groups.push(current);
754
+ return groups.map((group) => composeBoard(group, { ...asSlides, margin }));
755
+ }
756
+ export { BOARD_STYLES, BOARD_STYLE_IDS, DEFAULT_STYLE, resolveStyle } from './styles.js';
757
+ //# sourceMappingURL=sections.js.map