@sentropic/design-system-svelte 0.40.0 → 0.41.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 (34) hide show
  1. package/LICENSE.THIRD-PARTY.md +2 -1
  2. package/README.md +7 -0
  3. package/dist/DiagramCard.svelte +25 -36
  4. package/dist/DiagramCard.svelte.d.ts +4 -8
  5. package/dist/DiagramCard.svelte.d.ts.map +1 -1
  6. package/dist/DiagramCardHeader.svelte +11 -10
  7. package/dist/DiagramCardHeader.svelte.d.ts.map +1 -1
  8. package/dist/DiagramSceneFigure.svelte +399 -33
  9. package/dist/DiagramSceneFigure.svelte.d.ts +24 -4
  10. package/dist/DiagramSceneFigure.svelte.d.ts.map +1 -1
  11. package/dist/DiagramZone.svelte +21 -47
  12. package/dist/DiagramZone.svelte.d.ts +2 -4
  13. package/dist/DiagramZone.svelte.d.ts.map +1 -1
  14. package/dist/DiagramZoneHeader.svelte +2 -1
  15. package/dist/DiagramZoneHeader.svelte.d.ts.map +1 -1
  16. package/dist/diagram-icons/PROVENANCE.md +4 -0
  17. package/dist/diagram-icons/registry.d.ts.map +1 -1
  18. package/dist/diagram-icons/registry.js +2 -1
  19. package/dist/diagram-render/renderCardSvg.d.ts +5 -15
  20. package/dist/diagram-render/renderCardSvg.d.ts.map +1 -1
  21. package/dist/diagram-render/renderCardSvg.js +9 -15
  22. package/dist/diagram-render/renderZoneSvg.d.ts +2 -11
  23. package/dist/diagram-render/renderZoneSvg.d.ts.map +1 -1
  24. package/dist/diagram-render/renderZoneSvg.js +5 -10
  25. package/dist/diagramCardModel.d.ts +2 -611
  26. package/dist/diagramCardModel.d.ts.map +1 -1
  27. package/dist/diagramCardModel.js +2 -1164
  28. package/dist/diagramFontMeasure.d.ts +5 -0
  29. package/dist/diagramFontMeasure.d.ts.map +1 -0
  30. package/dist/diagramFontMeasure.js +41 -0
  31. package/dist/diagramRenderedBounds.d.ts +6 -0
  32. package/dist/diagramRenderedBounds.d.ts.map +1 -0
  33. package/dist/diagramRenderedBounds.js +51 -0
  34. package/package.json +8 -6
@@ -1,1164 +1,2 @@
1
- /**
2
- * DiagramCard shared model — geometry, projection and line layout (DC-1).
3
- *
4
- * Pure TypeScript, zero imports: the Svelte `DiagramCard` (barrel graph)
5
- * and the `diagram-render` pure renderer (subpath graph) both consume this
6
- * module, so it must live outside both subpath directories and import
7
- * nothing. Glyph path data arrives via props (resolved by the caller from
8
- * the `diagram-icons` subpath); this module never resolves a glyph name.
9
- *
10
- * One geometry source (§5.6): every number below is frozen by
11
- * spec/SPEC_EVOL_DS_DIAGRAM_CARDS.md §5.3/Appendix A and mirrors
12
- * - the `diagramCard` component tokens (`packages/tokens/src/component.ts`),
13
- * - `packages/diagram-canvas/src/layout/measure.ts`
14
- * (`FIXED_CARD_WIDTH 460`, `FIXED_CARD_HEIGHT 200`,
15
- * `TOGGLE_ALLOCATION 66`, `CONTENT_INSET 16`, `RULE_GAP 4`).
16
- * The token↔constant agreement test asserts the sources agree.
17
- *
18
- * Line boxes use the kit's 1/64 px grid (`floor(size * 1.3 * 64) / 64`,
19
- * cf. `frameHeaderContent`): with those boxes the frozen content sums
20
- * exactly — footer text-box bottom at `198 − 9.25`, rule gaps 4/4 — instead
21
- * of drifting by fractional pixels (DIF-04). Text baselines follow the
22
- * kit's glyph bounds: a 24 px role sits 22 px above its baseline, the
23
- * 22 px kicker and the 32 px title at their own size (cf. the frozen SVG:
24
- * kicker baseline `headerY + 16 + 22`, title `+ 32`, subtitle `+ 22`).
25
- */
26
- /** Frozen card geometry, in card pixels (spec §5.3, Appendix A). */
27
- export const CARD_GEOMETRY = {
28
- width: 460,
29
- height: 200,
30
- borderWidth: 2,
31
- accentWidth: 8,
32
- padding: 8,
33
- /** Card left edge → header icon left edge (accent 8 + padding 8). */
34
- headerInset: 16,
35
- iconSize: 70,
36
- iconTextGap: 6,
37
- kicker: { size: 22, weight: 400, lineHeight: 1.3, letterSpacingEm: 0.04 },
38
- title: { size: 32, weight: 700, lineHeight: 1.3 },
39
- /** Header row → body block. */
40
- gap: 6,
41
- body: { size: 24, weight: 400, lineHeight: 1.3 },
42
- /**
43
- * Edge-label text (BF-6): 18px so one line plus margins fits the 32px
44
- * gutter cap (22 + 2 × 4 = 30 ≤ 32). Mirrors the
45
- * `diagramScene.edgeLabelFontSize` / `edgeLabelLineHeight` tokens;
46
- * additive, frozen card sizes unchanged.
47
- */
48
- edgeLabel: { size: 18, weight: 400, lineHeight: 22 / 18 },
49
- /** Accent-bar left edge → first body glyph. */
50
- bodyInsetFromBar: 14,
51
- ruleHeight: 1,
52
- ruleMargin: 4,
53
- ruleInsetStart: 16,
54
- ruleInsetEnd: 10,
55
- footer: { size: 24, weight: 700, lineHeight: 1.3 },
56
- /** Footer text-box bottom → inner edge of the bottom border. */
57
- footerBottomInset: 9.25,
58
- /**
59
- * Title/kicker width reservation when the toggle slot is present
60
- * (hrpn tints.css `header { padding-right: 66px }`: the 66 px the +/−
61
- * control needs in the header's inline-end).
62
- */
63
- toggleAllocation: 66,
64
- /** The toggle slot box itself: the 32 px DS IconButton (sm) square. */
65
- toggleBoxSize: 32,
66
- /**
67
- * Header text width of a folded card (toggle present, icon present):
68
- * the owner-pinned 290 px — the hrpn folded-card title width
69
- * (356 − 66 = 290). Plain cards keep `contentRight − headerTextX`
70
- * (358 px with the icon).
71
- */
72
- foldedHeaderTextWidth: 290,
73
- /** Card allocations, frozen-box-derived (see module doc). */
74
- allocatedLines: { kicker: 1, title: 2, body: 2, footer: 1 },
75
- };
76
- /**
77
- * Edge label typography (DC-2a, tokens `diagramScene.edgeLabelFontSize` /
78
- * `diagramScene.edgeLabelLineHeight`): 18 px on a 22 px line box. One line
79
- * plus the engine's two 4 px label margins is 30 px, inside the 32 px sibling
80
- * gap cap; at the 0.45 readability floor it renders at 8.1 CSS px.
81
- */
82
- export const EDGE_LABEL_GEOMETRY = { size: 18, weight: 400, lineHeight: 22 };
83
- /** Line box height for a size at 1.3, on the 1/64 px grid. */
84
- export function lineBoxHeight(size) {
85
- return Math.floor(size * 1.3 * 64) / 64;
86
- }
87
- /**
88
- * Alphabetic baseline inside a line box starting at `top`, per the kit's
89
- * glyph bounds: 24 px roles (body/subtitle/footer) sit 22 px above the
90
- * baseline; the 22 px kicker and the 32 px title at their own size.
91
- */
92
- export function baselineOf(top, size) {
93
- return top + (size === 24 ? 22 : size);
94
- }
95
- /**
96
- * Shared `EntityPresentation` → props projection (§4.2), consumed by both
97
- * renderers. A missing presentation entry (or a non-card form, or no title)
98
- * resolves to `{ kind: "label" }`: the host renders a simple label node and
99
- * no card (L-R12). The glyph name maps through the injected resolver, which
100
- * the `diagram-render` subpath wires to the icon registry; a name with no
101
- * record yields no glyph and the layout raises `card-icon-unknown`.
102
- */
103
- export function projectCardProps(presentation, opts) {
104
- if (presentation === undefined || presentation.form !== "card")
105
- return { kind: "label" };
106
- const title = presentation.text.title ?? "";
107
- if (title === "")
108
- return { kind: "label" };
109
- const bodyLines = [];
110
- if (presentation.text.body !== undefined && presentation.text.body !== "") {
111
- bodyLines.push(presentation.text.body);
112
- }
113
- let detailCount = 0;
114
- if (presentation.text.detail !== undefined && presentation.text.detail !== "") {
115
- bodyLines.push(presentation.text.detail);
116
- detailCount = 1;
117
- }
118
- const icon = presentation.icon;
119
- return {
120
- kind: "card",
121
- props: {
122
- entityId: opts.entityId,
123
- ...(presentation.text.kicker === undefined || presentation.text.kicker === ""
124
- ? {}
125
- : { kicker: presentation.text.kicker }),
126
- title,
127
- body: bodyLines,
128
- ...(detailCount === 0 ? {} : { detailCount }),
129
- ...(presentation.text.footer === undefined || presentation.text.footer === ""
130
- ? {}
131
- : { footer: presentation.text.footer }),
132
- ...(icon === undefined ? {} : { icon }),
133
- ...(icon === undefined || opts.resolveGlyph === undefined
134
- ? {}
135
- : (() => {
136
- const glyph = opts.resolveGlyph(icon);
137
- return glyph === undefined ? {} : { iconGlyph: glyph };
138
- })()),
139
- ...(presentation.categoryRef === undefined ? {} : { tone: presentation.categoryRef }),
140
- ...(presentation.proposed === undefined ? {} : { proposed: presentation.proposed }),
141
- ...(opts.toggle === undefined ? {} : { toggle: opts.toggle }),
142
- },
143
- };
144
- }
145
- /**
146
- * Pinned per-character advances at 1 px (data, not code).
147
- *
148
- * Source: the pinned kit 'governance-font-metrics.js' (browser-measured
149
- * Inter 400 advances for body/kicker, Dossier Inter 700 advances for
150
- * title/footer — the same tables the reference layout wraps against).
151
- * The DS default measurer consumes them so static strings wrap exactly
152
- * where the reference wraps; production hosts inject their measured
153
- * LineMeasurer (Inter-stack advances) instead. Measurer version:
154
- * 'pinned-kit-1px'. Missing glyphs fall back to 0.7 em (the kit's
155
- * unknown-glyph advance).
156
- */
157
- const CARD_ADVANCES_TITLE = {
158
- "0": 0.67,
159
- "1": 0.43,
160
- "2": 0.63,
161
- "3": 0.65,
162
- "4": 0.68,
163
- "5": 0.62,
164
- "6": 0.65,
165
- "7": 0.58,
166
- "8": 0.65,
167
- "9": 0.65,
168
- "\n": 0.24,
169
- " ": 0.24,
170
- "\"": 0.55,
171
- "#": 0.65,
172
- "%": 1.02,
173
- "&": 0.67,
174
- "'": 0.34,
175
- "(": 0.38,
176
- ")": 0.38,
177
- "*": 0.56,
178
- "+": 0.68,
179
- ",": 0.33,
180
- "-": 0.47,
181
- ".": 0.33,
182
- "/": 0.39,
183
- ":": 0.33,
184
- ";": 0.34,
185
- "<": 0.68,
186
- "=": 0.68,
187
- ">": 0.68,
188
- "@": 1.02,
189
- "A": 0.75,
190
- "B": 0.66,
191
- "C": 0.74,
192
- "D": 0.72,
193
- "E": 0.61,
194
- "F": 0.59,
195
- "G": 0.75,
196
- "H": 0.75,
197
- "I": 0.28,
198
- "J": 0.58,
199
- "K": 0.72,
200
- "L": 0.57,
201
- "M": 0.93,
202
- "N": 0.76,
203
- "O": 0.77,
204
- "P": 0.65,
205
- "Q": 0.78,
206
- "R": 0.66,
207
- "S": 0.65,
208
- "T": 0.67,
209
- "U": 0.73,
210
- "V": 0.75,
211
- "W": 1.04,
212
- "X": 0.74,
213
- "Y": 0.73,
214
- "Z": 0.66,
215
- "[": 0.38,
216
- "\\": 0.39,
217
- "]": 0.38,
218
- "_": 0.48,
219
- "a": 0.58,
220
- "b": 0.63,
221
- "c": 0.59,
222
- "d": 0.63,
223
- "e": 0.6,
224
- "f": 0.4,
225
- "g": 0.63,
226
- "h": 0.62,
227
- "i": 0.27,
228
- "j": 0.27,
229
- "k": 0.58,
230
- "l": 0.27,
231
- "m": 0.91,
232
- "n": 0.62,
233
- "o": 0.61,
234
- "p": 0.63,
235
- "q": 0.63,
236
- "r": 0.41,
237
- "s": 0.56,
238
- "t": 0.37,
239
- "u": 0.62,
240
- "v": 0.6,
241
- "w": 0.85,
242
- "x": 0.58,
243
- "y": 0.6,
244
- "z": 0.57,
245
- "{": 0.47,
246
- "}": 0.47,
247
- "§": 0.57,
248
- "«": 0.66,
249
- "·": 0.33,
250
- "»": 0.66,
251
- "À": 0.75,
252
- "Ç": 0.74,
253
- "È": 0.61,
254
- "É": 0.61,
255
- "×": 0.68,
256
- "à": 0.58,
257
- "â": 0.58,
258
- "ç": 0.59,
259
- "è": 0.6,
260
- "é": 0.6,
261
- "ê": 0.6,
262
- "î": 0.27,
263
- "ô": 0.61,
264
- "ù": 0.62,
265
- "–": 0.5,
266
- "’": 0.31,
267
- "\u2026": 1,
268
- "→": 1,
269
- "↔": 1,
270
- "≠": 0.83203,
271
- "≥": 0.83203
272
- };
273
- const CARD_ADVANCES_BODY = {
274
- "0": 0.59961,
275
- "1": 0.59961,
276
- "2": 0.59961,
277
- "3": 0.59961,
278
- "4": 0.59961,
279
- "5": 0.59961,
280
- "6": 0.59961,
281
- "7": 0.59961,
282
- "8": 0.59961,
283
- "9": 0.59961,
284
- "\n": 0.2998,
285
- " ": 0.2998,
286
- "\"": 0.45996,
287
- "#": 0.59961,
288
- "%": 0.69922,
289
- "&": 0.67969,
290
- "'": 0.2998,
291
- "(": 0.2998,
292
- ")": 0.2998,
293
- "*": 0.59961,
294
- "+": 0.59961,
295
- ",": 0.2998,
296
- "-": 0.2998,
297
- ".": 0.2998,
298
- "/": 0.51953,
299
- ":": 0.2998,
300
- ";": 0.2998,
301
- "<": 0.59961,
302
- "=": 0.59961,
303
- ">": 0.59961,
304
- "@": 0.7998,
305
- "A": 0.55957,
306
- "B": 0.61914,
307
- "C": 0.61914,
308
- "D": 0.65918,
309
- "E": 0.55957,
310
- "F": 0.47949,
311
- "G": 0.65918,
312
- "H": 0.65918,
313
- "I": 0.25977,
314
- "J": 0.39941,
315
- "K": 0.61914,
316
- "L": 0.5,
317
- "M": 0.81934,
318
- "N": 0.65918,
319
- "O": 0.65918,
320
- "P": 0.55957,
321
- "Q": 0.65918,
322
- "R": 0.61914,
323
- "S": 0.61914,
324
- "T": 0.5,
325
- "U": 0.63965,
326
- "V": 0.55957,
327
- "W": 0.81934,
328
- "X": 0.53906,
329
- "Y": 0.55957,
330
- "Z": 0.53906,
331
- "[": 0.2998,
332
- "\\": 0.51953,
333
- "]": 0.2998,
334
- "_": 0.5,
335
- "a": 0.53906,
336
- "b": 0.53906,
337
- "c": 0.47949,
338
- "d": 0.53906,
339
- "e": 0.53906,
340
- "f": 0.2998,
341
- "g": 0.5,
342
- "h": 0.53906,
343
- "i": 0.23926,
344
- "j": 0.21973,
345
- "k": 0.5,
346
- "l": 0.23926,
347
- "m": 0.81934,
348
- "n": 0.53906,
349
- "o": 0.53906,
350
- "p": 0.53906,
351
- "q": 0.53906,
352
- "r": 0.31934,
353
- "s": 0.51953,
354
- "t": 0.31934,
355
- "u": 0.53906,
356
- "v": 0.43945,
357
- "w": 0.65918,
358
- "x": 0.43945,
359
- "y": 0.41992,
360
- "z": 0.41992,
361
- "{": 0.2998,
362
- "}": 0.2998,
363
- "§": 0.59961,
364
- "«": 0.39941,
365
- "·": 0.23926,
366
- "»": 0.39941,
367
- "À": 0.55957,
368
- "Ç": 0.61914,
369
- "È": 0.55957,
370
- "É": 0.55957,
371
- "×": 0.59961,
372
- "à": 0.53906,
373
- "â": 0.53906,
374
- "ç": 0.47949,
375
- "è": 0.53906,
376
- "é": 0.53906,
377
- "ê": 0.53906,
378
- "î": 0.23926,
379
- "ô": 0.53906,
380
- "ù": 0.53906,
381
- "–": 0.55566,
382
- "’": 0.22168,
383
- "\u2026": 1,
384
- "→": 1,
385
- "↔": 1,
386
- "≠": 0.83203,
387
- "≥": 0.83203
388
- };
389
- /**
390
- * Deterministic greedy wrapper over the pinned per-character advances.
391
- * Production hosts inject their measured ‘LineMeasurer’; tests and
392
- * static strings use this. It mirrors the frozen reference measurer
393
- * (`cardTextWidth`/`wrapText` of the pinned kit): every candidate line is
394
- * measured as a whole — `sum(advance × size) + 2` px safety — with the
395
- * unknown-glyph fallback at 0.7 em, and the kicker is uppercased and
396
- * tracked at 0.04 em before lookup (the kicker renders uppercase with
397
- * `letter-spacing: 0.04em`). Corpus fixtures wrap exactly where the
398
- * reference wraps; overflow fixtures overflow under every metric.
399
- */
400
- export function defaultCardMeasure(text, role, availableWidth) {
401
- const size = role === "kicker"
402
- ? CARD_GEOMETRY.kicker.size
403
- : role === "title"
404
- ? CARD_GEOMETRY.title.size
405
- : role === "footer"
406
- ? CARD_GEOMETRY.footer.size
407
- : CARD_GEOMETRY.body.size;
408
- const table = role === "title" || role === "footer" ? CARD_ADVANCES_TITLE : CARD_ADVANCES_BODY;
409
- const letterSpacing = role === "kicker" ? size * CARD_GEOMETRY.kicker.letterSpacingEm : 0;
410
- const measureString = (value) => {
411
- if (value.length === 0)
412
- return 0;
413
- const normalized = role === "kicker" ? value.toUpperCase() : value;
414
- let sum = 0;
415
- for (const char of normalized) {
416
- sum += (table[char] ?? 0.7) * size + letterSpacing;
417
- }
418
- return sum + 2;
419
- };
420
- const lines = [];
421
- let tooWide = false;
422
- for (const word of String(text).split(/\s+/).filter(Boolean)) {
423
- const candidate = lines.length === 0 ? word : `${lines[lines.length - 1]} ${word}`;
424
- if (lines.length > 0 && measureString(candidate) <= availableWidth) {
425
- lines[lines.length - 1] = candidate;
426
- }
427
- else {
428
- if (measureString(word) > availableWidth)
429
- tooWide = true;
430
- lines.push(word);
431
- }
432
- }
433
- return { lines, tooWide, lineWidths: lines.map(measureString) };
434
- }
435
- export const DEFAULT_CARD_MEASURER_VERSION = "pinned-kit-1px";
436
- /**
437
- * Bridge from the card measurer to the canvas `LineMeasurer` shape: a host
438
- * pairing `diagram-canvas` with these renderers passes `cardLineMeasurer()`
439
- * straight as the injected `LineMeasurer` — no adapter, no role cast.
440
- * Every canvas role maps onto the card role with the same font size
441
- * (subtitle, detail and legend-label measure as body), `width` is the
442
- * widest emitted line, `height` the line count at the role's line box, and
443
- * `overflow` reports a too-wide line or a line-count overflow.
444
- *
445
- * The edge label has its own size (`EDGE_LABEL_GEOMETRY`, 18 px on 22 px):
446
- * it is the body face scaled by 18/24. The injected measure only knows the
447
- * four card roles, so the label is wrapped as body text in a width scaled up
448
- * by 24/18 and its line widths are scaled back down — advances are linear in
449
- * the font size, so this is the 18 px measurement.
450
- */
451
- export function cardLineMeasurer(measure = defaultCardMeasure) {
452
- const measureLines = (request) => {
453
- const role = request.role === "kicker" || request.role === "title" || request.role === "footer"
454
- ? request.role
455
- : "body";
456
- if (request.role === "edge-label") {
457
- const scale = EDGE_LABEL_GEOMETRY.size / CARD_GEOMETRY.body.size;
458
- const label = measure(request.text, "body", request.availableWidth / scale, request.allocatedLines);
459
- return {
460
- lines: label.lines,
461
- width: label.lineWidths === undefined ? request.availableWidth : Math.max(0, ...label.lineWidths) * scale,
462
- height: label.lines.length * EDGE_LABEL_GEOMETRY.lineHeight,
463
- overflow: label.tooWide || label.lines.length > request.allocatedLines,
464
- };
465
- }
466
- const measured = measure(request.text, role, request.availableWidth, request.allocatedLines);
467
- const size = role === "kicker"
468
- ? CARD_GEOMETRY.kicker.size
469
- : role === "title"
470
- ? CARD_GEOMETRY.title.size
471
- : CARD_GEOMETRY.body.size;
472
- const widest = measured.lineWidths === undefined
473
- ? request.availableWidth
474
- : Math.max(0, ...measured.lineWidths);
475
- return {
476
- lines: measured.lines,
477
- width: widest,
478
- height: measured.lines.length * lineBoxHeight(size),
479
- overflow: measured.tooWide || measured.lines.length > request.allocatedLines,
480
- };
481
- };
482
- return Object.assign(measureLines, { version: DEFAULT_CARD_MEASURER_VERSION });
483
- }
484
- /**
485
- * Overflow = refusal (owner criterion, DC-1 review): the first overflow
486
- * diagnostic of a layout, or `undefined` when the content fits. Both
487
- * renderers (pure SVG and Svelte) refuse on exactly this predicate, so the
488
- * two contracts cannot diverge.
489
- */
490
- export function firstOverflowDiagnostic(diagnostics) {
491
- return diagnostics.find((diagnostic) => diagnostic.code === "card-overflow" || diagnostic.code === "zone-overflow");
492
- }
493
- export function headerSlotGeometry(opts) {
494
- const g = CARD_GEOMETRY;
495
- const kickerHeight = lineBoxHeight(g.kicker.size);
496
- const titleHeight = lineBoxHeight(g.title.size);
497
- const contentHeight = (opts.kickerLines > 0 ? kickerHeight : 0) + opts.titleLines * titleHeight;
498
- const blockHeight = opts.hasIcon ? Math.max(g.iconSize, contentHeight) : contentHeight;
499
- return {
500
- kickerHeight,
501
- titleHeight,
502
- contentHeight,
503
- blockHeight,
504
- textTopOffset: (blockHeight - contentHeight) / 2,
505
- iconTopOffset: opts.hasIcon ? (blockHeight - g.iconSize) / 2 : 0,
506
- };
507
- }
508
- /**
509
- * Lay out one card: wrap every slot against its frozen allocation, position
510
- * every line, pin the footer, emit diagnostics. Never truncates or clips
511
- * (DC-D4): the layout always describes the complete content inside the
512
- * fixed 460 × 200 box. Any overflow — a too-wide line, a line-count
513
- * overflow, or a combined header+body height that does not fit the space
514
- * above the pinned rule — raises `card-overflow` carrying the original slot
515
- * text, and both renderers refuse on it (overflow = refusal, owner
516
- * criterion): no normal card is emitted until the content fits. An icon
517
- * name with no glyph data raises `card-icon-unknown` and the slot collapses.
518
- */
519
- export function layoutCard(props, measure) {
520
- const g = CARD_GEOMETRY;
521
- const diagnostics = [];
522
- const align = props.align ?? "left";
523
- const bodyMode = props.bodyMode ?? "leaf";
524
- const contentTop = g.borderWidth + g.padding;
525
- const contentRight = g.width - g.borderWidth - g.padding;
526
- // The icon slot collapses when the glyph is missing (DIF-14): the header
527
- // text then starts at the content inset and no space is reserved.
528
- const hasIcon = props.icon !== undefined && props.iconGlyph !== undefined;
529
- const headerTextX = hasIcon ? g.headerInset + g.iconSize + g.iconTextGap : g.headerInset;
530
- const toggle = props.toggle !== undefined;
531
- // Toggle present: the header text keeps the owner-pinned folded width
532
- // (290 px with the icon — the hrpn folded-card title width 356 − 66);
533
- // the 66 px reservation covers the +/− control's inline-end room.
534
- const headerTextWidth = toggle
535
- ? hasIcon
536
- ? g.foldedHeaderTextWidth
537
- : contentRight - g.toggleAllocation - headerTextX
538
- : contentRight - headerTextX;
539
- const headerAnchor = align === "center" ? "middle" : "start";
540
- const headerLineX = align === "center" ? headerTextX + headerTextWidth / 2 : headerTextX;
541
- // Overflow diagnostic (Astra J4): a too-wide line reports horizontal dims
542
- // (neededPx = widest measured line, allocatedPx = availableWidth, so
543
- // neededPx > allocatedPx always); a line-count overflow reports line dims.
544
- // `text` carries the original slot string: overflow is refused, never
545
- // shortened, so the diagnostic preserves what the host must shorten.
546
- const pushOverflow = (slot, measured, lineHeight, allocatedLines, availableWidth, text) => {
547
- if (measured.tooWide) {
548
- const widest = measured.lineWidths === undefined ? availableWidth + 1 : Math.max(0, ...measured.lineWidths);
549
- diagnostics.push({
550
- code: "card-overflow",
551
- slot,
552
- entityId: props.entityId,
553
- neededPx: widest,
554
- allocatedPx: availableWidth,
555
- text,
556
- });
557
- }
558
- else {
559
- diagnostics.push({
560
- code: "card-overflow",
561
- slot,
562
- entityId: props.entityId,
563
- neededPx: measured.lines.length * lineHeight,
564
- allocatedPx: allocatedLines * lineHeight,
565
- text,
566
- });
567
- }
568
- };
569
- if (props.icon !== undefined && props.iconGlyph === undefined) {
570
- diagnostics.push({
571
- code: "card-icon-unknown",
572
- slot: "icon",
573
- entityId: props.entityId,
574
- neededPx: 1,
575
- allocatedPx: 0,
576
- });
577
- }
578
- const kickerResult = props.kicker === undefined
579
- ? undefined
580
- : measure(props.kicker, "kicker", headerTextWidth, g.allocatedLines.kicker);
581
- const kickerTexts = kickerResult === undefined ? [] : [...kickerResult.lines];
582
- const titleMeasured = measure(props.title, "title", headerTextWidth, g.allocatedLines.title);
583
- const titleTexts = [...titleMeasured.lines];
584
- // Optional slots (review pass 2, item 10): one shared derivation — the
585
- // 70 px icon floor applies only when the icon is present, and the text
586
- // band is centred in the block exactly like the Svelte header row.
587
- // Pass 3: the kicker/title line heights and the icon offset come from the
588
- // same derivation too — no header geometry is recomputed outside it.
589
- const headerGeo = headerSlotGeometry({
590
- hasIcon,
591
- kickerLines: kickerTexts.length,
592
- titleLines: titleTexts.length,
593
- });
594
- const kickerHeight = headerGeo.kickerHeight;
595
- const titleHeight = headerGeo.titleHeight;
596
- if (kickerResult !== undefined && (kickerTexts.length > g.allocatedLines.kicker || kickerResult.tooWide)) {
597
- pushOverflow("kicker", kickerResult, kickerHeight, g.allocatedLines.kicker, headerTextWidth, props.kicker ?? "");
598
- }
599
- if (titleTexts.length > g.allocatedLines.title || titleMeasured.tooWide) {
600
- pushOverflow("title", titleMeasured, titleHeight, g.allocatedLines.title, headerTextWidth, props.title);
601
- }
602
- const headerBlockHeight = headerGeo.blockHeight;
603
- const textTop = contentTop + headerGeo.textTopOffset;
604
- // Pass 3, item 11: the icon is centred in the header block exactly like
605
- // the Svelte header row (align-items: center), so both renderers place it
606
- // at contentTop + iconTopOffset.
607
- const iconBox = hasIcon
608
- ? { x: g.headerInset, y: contentTop + headerGeo.iconTopOffset, size: g.iconSize }
609
- : undefined;
610
- const bodyHeight = lineBoxHeight(g.body.size);
611
- const bodyY = contentTop + headerBlockHeight + g.gap;
612
- // bodyInsetFromBar measures accent-bar edge → first glyph (14). The accent
613
- // bar occupies the card's left edge, so the body x is the token value
614
- // itself — 2 px left of the header icon edge (16). In `subtitle` body mode
615
- // (collapsed zone, §6.2.1) the body is the centred subtitle: wrapped at the
616
- // frozen 396 px measure (width − 2 × (collapsedInset + marginInline)).
617
- const subtitleMode = bodyMode === "subtitle";
618
- const subtitleMeasure = g.width - 2 * (ZONE_GEOMETRY.collapsedInset + ZONE_GEOMETRY.collapsedSubtitleMarginInline);
619
- const bodyTextX = subtitleMode ? (g.width - subtitleMeasure) / 2 : g.bodyInsetFromBar;
620
- const bodyWidth = subtitleMode ? subtitleMeasure : contentRight - bodyTextX;
621
- const bodyAnchor = subtitleMode || align === "center" ? "middle" : "start";
622
- const bodyLineX = bodyAnchor === "middle" ? bodyTextX + bodyWidth / 2 : bodyTextX;
623
- const wrappedBody = [];
624
- const bodyLineWidths = [];
625
- let bodyTooWide = false;
626
- for (const line of props.body) {
627
- const measured = measure(line, "body", bodyWidth, g.allocatedLines.body);
628
- wrappedBody.push(...measured.lines);
629
- bodyLineWidths.push(...(measured.lineWidths ?? []));
630
- bodyTooWide = bodyTooWide || measured.tooWide;
631
- }
632
- const bodySlot = subtitleMode ? "collapsed-subtitle" : "body";
633
- const bodySourceText = props.body.join("\n");
634
- let bodyOverflowPushed = false;
635
- if (wrappedBody.length > g.allocatedLines.body || bodyTooWide) {
636
- pushOverflow(bodySlot, { lines: wrappedBody, tooWide: bodyTooWide, lineWidths: bodyLineWidths }, bodyHeight, g.allocatedLines.body, bodyWidth, bodySourceText);
637
- bodyOverflowPushed = true;
638
- }
639
- const footerHeight = lineBoxHeight(g.footer.size);
640
- const footerBottom = g.height - g.borderWidth - g.footerBottomInset;
641
- // Footer: wrapped as measured (never joined back), pinned bottom-up — the
642
- // last line's box bottom sits at footerBottom; the rule stays ruleMargin
643
- // above the footer block (§5.4). No footer: no rule (DH-04).
644
- let footerLines = [];
645
- let ruleY;
646
- if (props.footer !== undefined) {
647
- const footerWidth = subtitleMode ? contentRight - g.headerInset : bodyWidth;
648
- const footerMeasured = measure(props.footer, "footer", footerWidth, g.allocatedLines.footer);
649
- const footerTexts = [...footerMeasured.lines];
650
- if (footerTexts.length > g.allocatedLines.footer || footerMeasured.tooWide) {
651
- pushOverflow("footer", footerMeasured, footerHeight, g.allocatedLines.footer, footerWidth, props.footer ?? "");
652
- }
653
- const footerAnchor = align === "center" ? "middle" : "start";
654
- const footerLineX = footerAnchor === "middle" ? g.headerInset + footerWidth / 2 : g.headerInset;
655
- const footerBlockHeight = footerTexts.length * footerHeight;
656
- footerLines = footerTexts.map((text, index) => ({
657
- text,
658
- x: footerLineX,
659
- baseline: baselineOf(footerBottom - footerBlockHeight + index * footerHeight, g.footer.size),
660
- size: g.footer.size,
661
- weight: g.footer.weight,
662
- secondary: false,
663
- anchor: footerAnchor,
664
- }));
665
- ruleY = footerBottom - footerBlockHeight - g.ruleHeight - g.ruleMargin;
666
- }
667
- const bodyAreaBottom = ruleY === undefined ? g.height - g.borderWidth - g.padding : ruleY - g.ruleMargin;
668
- // Vertical overflow (second review, blocking): the combined header + body
669
- // height must fit the actual space above the pinned rule. The body starts
670
- // at bodyY (derived from the header block), and the rule is pinned to the
671
- // footer, so the body allocation is bodyAreaBottom − bodyY — a two-line
672
- // title already leaves less than one body line above the rule, and the
673
- // second body baseline would cross the footer baseline. Diagnosed here and
674
- // refused by both renderers (overflow = refusal), never silently overlapped.
675
- const bodyBlockHeight = wrappedBody.length * bodyHeight;
676
- const bodyAreaHeight = bodyAreaBottom - bodyY;
677
- if (!bodyOverflowPushed && wrappedBody.length > 0 && bodyBlockHeight > bodyAreaHeight) {
678
- diagnostics.push({
679
- code: "card-overflow",
680
- slot: bodySlot,
681
- entityId: props.entityId,
682
- neededPx: bodyBlockHeight,
683
- allocatedPx: bodyAreaHeight,
684
- text: bodySourceText,
685
- });
686
- }
687
- // Subtitle mode centres the line block vertically inside the body area
688
- // (§6.2.1); leaf lines stay top-aligned (§5.2).
689
- const bodyBlockTop = subtitleMode
690
- ? bodyY + Math.max(0, (bodyAreaBottom - bodyY - wrappedBody.length * bodyHeight) / 2)
691
- : bodyY;
692
- const detailStart = wrappedBody.length - (props.detailCount ?? 0);
693
- const body = wrappedBody.map((text, index) => ({
694
- text,
695
- x: bodyLineX,
696
- baseline: baselineOf(bodyBlockTop + index * bodyHeight, g.body.size),
697
- size: g.body.size,
698
- weight: g.body.weight,
699
- secondary: !subtitleMode && index >= detailStart && (props.detailCount ?? 0) > 0,
700
- anchor: bodyAnchor,
701
- }));
702
- const bodyBottom = bodyY + wrappedBody.length * bodyHeight;
703
- const kicker = kickerTexts.map((text, index) => ({
704
- text,
705
- x: headerLineX,
706
- baseline: baselineOf(textTop + index * kickerHeight, g.kicker.size),
707
- size: g.kicker.size,
708
- weight: g.kicker.weight,
709
- secondary: true,
710
- anchor: headerAnchor,
711
- }));
712
- // Pass 3, item 10: title placement follows the MEASURED kicker-line
713
- // presence — an empty or whitespace-only kicker measures zero lines and
714
- // reserves no line, exactly like the shared header derivation above.
715
- const titleTop = textTop + (kickerTexts.length > 0 ? kickerHeight : 0);
716
- const title = titleTexts.map((text, index) => ({
717
- text,
718
- x: headerLineX,
719
- baseline: baselineOf(titleTop + index * titleHeight, g.title.size),
720
- size: g.title.size,
721
- weight: g.title.weight,
722
- secondary: false,
723
- anchor: headerAnchor,
724
- }));
725
- // Toggle slot: top right of the content box with the card's own margins
726
- // (hrpn folded-card placement, y = content top = 10 at the frozen values).
727
- // The slot box is the 32 px IconButton; the 66 px text reservation is
728
- // carried by headerTextWidth above.
729
- const toggleBox = props.toggle === undefined
730
- ? undefined
731
- : {
732
- x: contentRight - g.toggleBoxSize,
733
- y: contentTop,
734
- size: g.toggleBoxSize,
735
- };
736
- return {
737
- box: { width: g.width, height: g.height },
738
- contentTop,
739
- contentRight,
740
- ...(iconBox === undefined ? {} : { iconBox }),
741
- headerTextX,
742
- headerTextWidth,
743
- kicker,
744
- title,
745
- headerBlockHeight,
746
- bodyX: bodyTextX,
747
- bodyWidth,
748
- bodyArea: { top: bodyY, bottom: bodyAreaBottom },
749
- body,
750
- bodyBottom,
751
- ...(ruleY === undefined ? {} : { ruleY }),
752
- ruleX1: g.ruleInsetStart,
753
- ruleX2: g.width - g.ruleInsetEnd,
754
- footerLines,
755
- footerBottom,
756
- ...(toggleBox === undefined ? {} : { toggleBox }),
757
- diagnostics,
758
- };
759
- }
760
- /* ------------------------------------------------------------------ *
761
- * DC-2 static half — the wrapping card `DiagramZone` (spec §6). *
762
- * Same module, same rules: zero imports, one geometry source. *
763
- * ------------------------------------------------------------------ */
764
- /**
765
- * Frozen zone geometry (spec §6.4). Mirrors the `diagramZone` component
766
- * tokens (`packages/tokens/src/component.ts`) and the `diagram-canvas`
767
- * `measure.ts` constants (`CONTENT_INSET 16`, `RULE_GAP 4`,
768
- * `SUBTITLE_TO_RULE_GAP 4`, `RULE_TO_FIRST_CHILD_GAP 16`,
769
- * `LAST_CHILD_TO_BOTTOM_GAP 16`, `TOGGLE_ALLOCATION 66`,
770
- * `FIXED_CARD_WIDTH 460`, `FIXED_CARD_HEIGHT 200`); the token↔constant
771
- * agreement test asserts the sources agree. Fields shared with the atomic
772
- * card alias `CARD_GEOMETRY` directly — one geometry source (§5.6).
773
- */
774
- export const ZONE_GEOMETRY = {
775
- radius: 0,
776
- borderWidth: 1.5,
777
- // Shared with the atomic card by construction (one geometry source §5.6):
778
- // every field below aliases CARD_GEOMETRY unless the zone frame differs.
779
- headerInset: CARD_GEOMETRY.headerInset,
780
- iconSize: CARD_GEOMETRY.iconSize,
781
- iconTextGap: CARD_GEOMETRY.iconTextGap,
782
- kicker: CARD_GEOMETRY.kicker,
783
- title: CARD_GEOMETRY.title,
784
- subtitle: CARD_GEOMETRY.body,
785
- /** Rendered title → subtitle gap: alias of the card `gap` (§6.4). */
786
- subtitleGap: CARD_GEOMETRY.gap,
787
- headerRuleGap: 4,
788
- contentInsetTop: 16,
789
- contentInsetBottom: 16,
790
- contentInsetInline: 16,
791
- ruleHeight: CARD_GEOMETRY.ruleHeight,
792
- ruleMargin: CARD_GEOMETRY.ruleMargin,
793
- ruleInsetStart: CARD_GEOMETRY.ruleInsetStart,
794
- ruleInsetEnd: CARD_GEOMETRY.ruleInsetEnd,
795
- footer: CARD_GEOMETRY.footer,
796
- footerBottomInset: CARD_GEOMETRY.footerBottomInset,
797
- toggleAllocation: CARD_GEOMETRY.toggleAllocation,
798
- toggleBoxSize: CARD_GEOMETRY.toggleBoxSize,
799
- /**
800
- * Expanded toggle top inset: the frozen SVG places every zone toggle at
801
- * `y + 10` (flush under the frame's top edge), while the header band
802
- * starts at `y + 16`.
803
- */
804
- toggleTopInset: 10,
805
- /**
806
- * Expanded header text inset from the frame's left edge: the kit wraps
807
- * kicker/title at `width − 178` (icon 16 + 70 + gap 6, toggle room, right
808
- * inset) — 314 px at the PEOPLE width 492.
809
- */
810
- headerTextInset: 178,
811
- collapsedWidth: CARD_GEOMETRY.width,
812
- collapsedHeight: CARD_GEOMETRY.height,
813
- collapsedInset: 16,
814
- collapsedSubtitleMarginInline: 16,
815
- allocatedLines: { kicker: 1, title: 2, subtitle: 2, footer: 1 },
816
- };
817
- /** Centred collapsed-subtitle measure (§6.2.1): 460 − 2 × (16 + 16). */
818
- export const COLLAPSED_SUBTITLE_MEASURE = ZONE_GEOMETRY.collapsedWidth -
819
- 2 * (ZONE_GEOMETRY.collapsedInset + ZONE_GEOMETRY.collapsedSubtitleMarginInline);
820
- /**
821
- * Collapsed-zone → atomic-card props mapping (§6.2 field table): the
822
- * subtitle becomes the centred body (`bodyMode: "subtitle"`), the footer
823
- * pins the rule, the toggle takes the top-right slot. Shared by
824
- * `layoutZone` and both renderers so the collapsed zone is the card.
825
- */
826
- export function zoneCollapsedCardProps(props) {
827
- return {
828
- entityId: props.entityId,
829
- ...(props.kicker === undefined ? {} : { kicker: props.kicker }),
830
- title: props.title,
831
- body: props.subtitle === undefined || props.subtitle === "" ? [] : [props.subtitle],
832
- ...(props.footer === undefined ? {} : { footer: props.footer }),
833
- ...(props.icon === undefined ? {} : { icon: props.icon }),
834
- ...(props.iconGlyph === undefined ? {} : { iconGlyph: props.iconGlyph }),
835
- ...(props.tone === undefined ? {} : { tone: props.tone }),
836
- ...(props.proposed === undefined ? {} : { proposed: props.proposed }),
837
- ...(props.toggleLabel === undefined
838
- ? {}
839
- : { toggle: { collapsed: true, label: props.toggleLabel } }),
840
- ...(props.align === undefined ? {} : { align: props.align }),
841
- bodyMode: "subtitle",
842
- };
843
- }
844
- /**
845
- * Layout height of one child spec (review pass 3, item 9): a card child is
846
- * the frozen 460 × 200; a zone child is laid out through `layoutZone` —
847
- * recursively, so an auto-sized child contributes its own computed header +
848
- * children + footer height, and an explicit or collapsed child its own box.
849
- * A parent never assumes a 200 px child.
850
- */
851
- function childLayoutHeight(child, measure) {
852
- if (child.kind === "card")
853
- return CARD_GEOMETRY.height;
854
- if (child.zone === undefined)
855
- return ZONE_GEOMETRY.collapsedHeight;
856
- return layoutZone(child.zone, measure, child.children ?? []).box.height;
857
- }
858
- /**
859
- * Lay out one zone. Collapsed, the zone IS the atomic card (§6.2): the
860
- * subtitle wraps at the frozen 396 px measure and centres in the card body
861
- * area (`bodyMode: "subtitle"`), the footer pins the rule, and the toggle
862
- * takes the top-right slot. Expanded, the frame carries the shared header
863
- * (icon 70 at the 16 px inset, text at x + 92), the subtitle under the
864
- * icon from the left inset, the header rule 4 px under the subtitle (or
865
- * the header block), and the content box 16 px under the rule.
866
- */
867
- export function layoutZone(props, measure, children = []) {
868
- const g = ZONE_GEOMETRY;
869
- const x = props.x ?? 0;
870
- const y = props.y ?? 0;
871
- const diagnostics = [];
872
- if (props.collapsed) {
873
- const card = layoutCard(zoneCollapsedCardProps(props), measure);
874
- for (const diagnostic of card.diagnostics) {
875
- diagnostics.push({
876
- code: diagnostic.code === "card-icon-unknown" ? "zone-icon-unknown" : "zone-overflow",
877
- slot: diagnostic.slot,
878
- entityId: diagnostic.entityId,
879
- neededPx: diagnostic.neededPx,
880
- allocatedPx: diagnostic.allocatedPx,
881
- ...(diagnostic.text === undefined ? {} : { text: diagnostic.text }),
882
- });
883
- }
884
- return {
885
- box: { x, y, width: g.collapsedWidth, height: g.collapsedHeight },
886
- collapsed: true,
887
- card,
888
- diagnostics,
889
- };
890
- }
891
- // Expanded frame.
892
- const width = props.width ?? g.collapsedWidth;
893
- const contentRight = x + width - g.contentInsetInline;
894
- const hasIcon = props.icon !== undefined && props.iconGlyph !== undefined;
895
- const headerTextX = hasIcon ? x + g.headerInset + g.iconSize + g.iconTextGap : x + g.headerInset;
896
- // Kit header rule: with the icon and the toggle room both present,
897
- // kicker/title wrap at `width − 178` (314 px at the PEOPLE width 492).
898
- // Without the icon the text starts at the 16 px inset; without the
899
- // toggle there is no inline-end reservation — the 178 applies only when
900
- // icon and toggle are both there.
901
- const rightHeaderReserve = props.toggleLabel === undefined
902
- ? g.headerInset
903
- : g.headerTextInset - (g.headerInset + g.iconSize + g.iconTextGap);
904
- const headerTextWidth = Math.max(0, x + width - headerTextX - rightHeaderReserve);
905
- const align = props.align ?? "left";
906
- const headerAnchor = align === "center" ? "middle" : "start";
907
- const headerLineX = align === "center" ? headerTextX + headerTextWidth / 2 : headerTextX;
908
- // Overflow diagnostic (Astra J4): a too-wide line reports horizontal dims
909
- // (neededPx = widest measured line > availableWidth = allocatedPx); a
910
- // line-count overflow reports line dims.
911
- const pushOverflow = (slot, measured, lineHeight, allocatedLines, availableWidth, text) => {
912
- if (measured.tooWide) {
913
- const widest = measured.lineWidths === undefined ? availableWidth + 1 : Math.max(0, ...measured.lineWidths);
914
- diagnostics.push({
915
- code: "zone-overflow",
916
- slot,
917
- entityId: props.entityId,
918
- neededPx: widest,
919
- allocatedPx: availableWidth,
920
- text,
921
- });
922
- }
923
- else {
924
- diagnostics.push({
925
- code: "zone-overflow",
926
- slot,
927
- entityId: props.entityId,
928
- neededPx: measured.lines.length * lineHeight,
929
- allocatedPx: allocatedLines * lineHeight,
930
- text,
931
- });
932
- }
933
- };
934
- if (props.icon !== undefined && props.iconGlyph === undefined) {
935
- diagnostics.push({
936
- code: "zone-icon-unknown",
937
- slot: "icon",
938
- entityId: props.entityId,
939
- neededPx: 1,
940
- allocatedPx: 0,
941
- });
942
- }
943
- // The kit stacks the 24 px subtitle at the raw 24 × 1.3 = 31.2 (not the
944
- // floored 1/64 grid) and ends its block 8 px under the last baseline.
945
- const subtitleLineHeight = g.subtitle.size * g.subtitle.lineHeight;
946
- const kickerResult = props.kicker === undefined
947
- ? undefined
948
- : measure(props.kicker, "kicker", headerTextWidth, g.allocatedLines.kicker);
949
- const kickerTexts = kickerResult === undefined ? [] : [...kickerResult.lines];
950
- const titleMeasured = measure(props.title, "title", headerTextWidth, g.allocatedLines.title);
951
- const titleTexts = [...titleMeasured.lines];
952
- // Optional slots (review pass 2, item 10): the same shared derivation as
953
- // the card — the 70 px icon floor applies only with the icon, and the
954
- // text band is centred in the block exactly like the Svelte header row
955
- // (align-items: center), so both renderers place it identically. Pass 3:
956
- // the kicker/title line heights come from the same derivation too.
957
- const headerGeo = headerSlotGeometry({
958
- hasIcon,
959
- kickerLines: kickerTexts.length,
960
- titleLines: titleTexts.length,
961
- });
962
- const kickerHeight = headerGeo.kickerHeight;
963
- const titleHeight = headerGeo.titleHeight;
964
- if (kickerResult !== undefined && (kickerTexts.length > g.allocatedLines.kicker || kickerResult.tooWide)) {
965
- pushOverflow("kicker", kickerResult, kickerHeight, g.allocatedLines.kicker, headerTextWidth, props.kicker ?? "");
966
- }
967
- if (titleTexts.length > g.allocatedLines.title || titleMeasured.tooWide) {
968
- pushOverflow("title", titleMeasured, titleHeight, g.allocatedLines.title, headerTextWidth, props.title);
969
- }
970
- const headerBlockHeight = headerGeo.blockHeight;
971
- const headerTop = y + g.headerInset;
972
- const textTop = headerTop + headerGeo.textTopOffset;
973
- const iconBox = hasIcon
974
- ? { x: x + g.headerInset, y: headerTop + headerGeo.iconTopOffset, size: g.iconSize }
975
- : undefined;
976
- const kicker = kickerTexts.map((text, index) => ({
977
- text,
978
- x: headerLineX,
979
- baseline: baselineOf(textTop + index * kickerHeight, g.kicker.size),
980
- size: g.kicker.size,
981
- weight: g.kicker.weight,
982
- secondary: true,
983
- anchor: headerAnchor,
984
- }));
985
- // Pass 3, item 10: title placement follows the MEASURED kicker-line
986
- // presence — an empty or whitespace-only kicker measures zero lines and
987
- // reserves no line, exactly like the shared header derivation above.
988
- const titleTop = textTop + (kickerTexts.length > 0 ? kickerHeight : 0);
989
- const title = titleTexts.map((text, index) => ({
990
- text,
991
- x: headerLineX,
992
- baseline: baselineOf(titleTop + index * titleHeight, g.title.size),
993
- size: g.title.size,
994
- weight: g.title.weight,
995
- secondary: false,
996
- anchor: headerAnchor,
997
- }));
998
- // Subtitle wraps under the icon from the left inset at x + 16 (§6.2).
999
- // Kit rule: min(width, 460) − 26, i.e. the same 16/10 insets as the
1000
- // header rule inside a box capped at the atomic card width.
1001
- const subtitleX = x + g.headerInset;
1002
- const subtitleWidth = Math.min(width, g.collapsedWidth) - g.ruleInsetStart - g.ruleInsetEnd;
1003
- const subtitleAnchor = align === "center" ? "middle" : "start";
1004
- const subtitleLineX = align === "center" ? subtitleX + subtitleWidth / 2 : subtitleX;
1005
- const subtitleMeasured = props.subtitle === undefined || props.subtitle === ""
1006
- ? { lines: [], tooWide: false }
1007
- : measure(props.subtitle, "body", subtitleWidth, g.allocatedLines.subtitle);
1008
- const subtitleTexts = [...subtitleMeasured.lines];
1009
- if (subtitleTexts.length > g.allocatedLines.subtitle || subtitleMeasured.tooWide) {
1010
- pushOverflow("subtitle", subtitleMeasured, subtitleLineHeight, g.allocatedLines.subtitle, subtitleWidth, props.subtitle ?? "");
1011
- }
1012
- const subtitleTop = headerTop + headerBlockHeight + g.subtitleGap;
1013
- const subtitle = subtitleTexts.map((text, index) => ({
1014
- text,
1015
- x: subtitleLineX,
1016
- baseline: baselineOf(subtitleTop + index * subtitleLineHeight, g.subtitle.size),
1017
- size: g.subtitle.size,
1018
- weight: g.subtitle.weight,
1019
- secondary: false,
1020
- anchor: subtitleAnchor,
1021
- }));
1022
- // Kit subtitle block bottom: 8 px descent under the last baseline.
1023
- const subtitleBottom = subtitleTexts.length === 0
1024
- ? subtitleTop
1025
- : subtitleTop + (subtitleTexts.length - 1) * subtitleLineHeight + 22 + 8;
1026
- // Header rule 4 px under the subtitle last line, or under the header
1027
- // block when there is no subtitle (§6.2, §6.4 headerRuleGap).
1028
- const ruleY = subtitleTexts.length > 0
1029
- ? subtitleBottom + g.headerRuleGap
1030
- : headerTop + headerBlockHeight + g.headerRuleGap;
1031
- const contentTop = ruleY + g.contentInsetTop;
1032
- // Footer, expanded state too (§6.1: folding never changes the footer):
1033
- // wrapped as measured, pinned bottom-up at the frame bottom like the
1034
- // card, with its own rule ruleMargin above the footer block. Measured
1035
- // before the default height so an auto-sized frame reserves the footer.
1036
- const footerHeight = lineBoxHeight(g.footer.size);
1037
- const footerX = x + g.contentInsetInline;
1038
- const footerWidth = x + width - g.contentInsetInline - footerX;
1039
- const footerMeasured = props.footer === undefined ? undefined : measure(props.footer, "footer", footerWidth, g.allocatedLines.footer);
1040
- const footerTexts = footerMeasured === undefined ? [] : [...footerMeasured.lines];
1041
- if (footerMeasured !== undefined && (footerTexts.length > g.allocatedLines.footer || footerMeasured.tooWide)) {
1042
- pushOverflow("footer", footerMeasured, footerHeight, g.allocatedLines.footer, footerWidth, props.footer ?? "");
1043
- }
1044
- const footerBlockHeight = footerTexts.length * footerHeight;
1045
- // Frame height (review pass 2, item 9; pass 3, item 9): the supplied box,
1046
- // or — when the host lets the zone size itself — the full vertical
1047
- // requirement: header + rule (contentTop) or children, whichever is
1048
- // lower, plus the bottom content inset and the footer reserve (footer
1049
- // block + rule + both rule gaps + bottom inset). Children contribute
1050
- // their own recursively computed layout height (never an assumed 200 px),
1051
- // so a nested auto-sized child is fully inside the frame. The old
1052
- // formula ignored the header, so a tall header silently overflowed an
1053
- // auto-sized 200 px frame.
1054
- const childrenBottom = children.reduce((bottom, child) => Math.max(bottom, child.y + childLayoutHeight(child, measure)), y);
1055
- const footerReserve = footerTexts.length === 0
1056
- ? 0
1057
- : footerBlockHeight + g.ruleHeight + 2 * g.ruleMargin + g.footerBottomInset;
1058
- const requiredHeight = Math.max(childrenBottom, contentTop) + g.contentInsetBottom - y + footerReserve;
1059
- const height = props.height ?? Math.max(g.collapsedHeight, requiredHeight);
1060
- // An explicitly undersized frame is refused (overflow = refusal): the
1061
- // header + content + footer requirement does not fit, diagnosed as a
1062
- // zone-overflow on the frame slot, and both renderers refuse on it.
1063
- if (props.height !== undefined && requiredHeight > props.height) {
1064
- diagnostics.push({
1065
- code: "zone-overflow",
1066
- slot: "frame",
1067
- entityId: props.entityId,
1068
- neededPx: requiredHeight,
1069
- allocatedPx: props.height,
1070
- text: props.title,
1071
- });
1072
- }
1073
- // Toggle slot: the frozen SVG places every expanded-zone toggle at
1074
- // y + 10 (the header band itself starts at y + 16).
1075
- const toggleBox = props.toggleLabel === undefined
1076
- ? undefined
1077
- : { x: contentRight - g.toggleBoxSize, y: y + g.toggleTopInset, size: g.toggleBoxSize };
1078
- const footerBottom = y + height - g.borderWidth - g.footerBottomInset;
1079
- let footer = [];
1080
- let footerRuleY;
1081
- if (footerMeasured !== undefined) {
1082
- const footerAnchor = align === "center" ? "middle" : "start";
1083
- const footerLineX = footerAnchor === "middle" ? footerX + footerWidth / 2 : footerX;
1084
- footer = footerTexts.map((text, index) => ({
1085
- text,
1086
- x: footerLineX,
1087
- baseline: baselineOf(footerBottom - footerBlockHeight + index * footerHeight, g.footer.size),
1088
- size: g.footer.size,
1089
- weight: g.footer.weight,
1090
- secondary: false,
1091
- anchor: footerAnchor,
1092
- }));
1093
- footerRuleY = footerBottom - footerBlockHeight - g.ruleHeight - g.ruleMargin;
1094
- }
1095
- return {
1096
- box: { x, y, width, height },
1097
- collapsed: false,
1098
- header: {
1099
- ...(iconBox === undefined ? {} : { iconBox }),
1100
- headerTextX,
1101
- headerTextWidth,
1102
- kicker,
1103
- title,
1104
- headerBlockHeight,
1105
- subtitle,
1106
- subtitleWidth,
1107
- subtitleBottom,
1108
- ruleY,
1109
- contentTop,
1110
- ...(toggleBox === undefined ? {} : { toggleBox }),
1111
- footer,
1112
- ...(footerRuleY === undefined ? {} : { footerRuleY }),
1113
- footerBottom,
1114
- },
1115
- diagnostics,
1116
- };
1117
- }
1118
- /**
1119
- * Shared `EntityPresentation` → zone props projection (§4.2/§6.1): container
1120
- * and legend forms resolve to a zone; a missing entry or no title resolves
1121
- * to `{ kind: "label" }` (L-R12).
1122
- */
1123
- export function projectZoneProps(presentation, opts) {
1124
- if (presentation === undefined ||
1125
- (presentation.form !== "container" && presentation.form !== "legend")) {
1126
- return { kind: "label" };
1127
- }
1128
- const title = presentation.text.title ?? "";
1129
- if (title === "")
1130
- return { kind: "label" };
1131
- const icon = presentation.icon;
1132
- return {
1133
- kind: "zone",
1134
- props: {
1135
- entityId: opts.entityId,
1136
- ...(presentation.text.kicker === undefined || presentation.text.kicker === ""
1137
- ? {}
1138
- : { kicker: presentation.text.kicker }),
1139
- title,
1140
- ...(presentation.text.subtitle === undefined || presentation.text.subtitle === ""
1141
- ? {}
1142
- : { subtitle: presentation.text.subtitle }),
1143
- ...(presentation.text.footer === undefined || presentation.text.footer === ""
1144
- ? {}
1145
- : { footer: presentation.text.footer }),
1146
- ...(icon === undefined ? {} : { icon }),
1147
- ...(icon === undefined || opts.resolveGlyph === undefined
1148
- ? {}
1149
- : (() => {
1150
- const glyph = opts.resolveGlyph(icon);
1151
- return glyph === undefined ? {} : { iconGlyph: glyph };
1152
- })()),
1153
- ...(presentation.categoryRef === undefined ? {} : { tone: presentation.categoryRef }),
1154
- ...(presentation.proposed === undefined ? {} : { proposed: presentation.proposed }),
1155
- collapsed: opts.collapsed,
1156
- ...(opts.toggleLabel === undefined ? {} : { toggleLabel: opts.toggleLabel }),
1157
- ...(opts.align === undefined ? {} : { align: opts.align }),
1158
- ...(opts.x === undefined ? {} : { x: opts.x }),
1159
- ...(opts.y === undefined ? {} : { y: opts.y }),
1160
- ...(opts.width === undefined ? {} : { width: opts.width }),
1161
- ...(opts.height === undefined ? {} : { height: opts.height }),
1162
- },
1163
- };
1164
- }
1
+ /** Framework-neutral card geometry shared with the Vue host and static renderers. */
2
+ export * from "@sentropic/diagram-canvas/diagramCardModel";