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