@sentropic/diagram-canvas 0.2.4 → 0.3.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.
@@ -23,6 +23,14 @@
23
23
  * 22 px kicker and the 32 px title at their own size (cf. the frozen SVG:
24
24
  * kicker baseline `headerY + 16 + 22`, title `+ 32`, subtitle `+ 22`).
25
25
  */
26
+ /**
27
+ * Versioned card anatomy (DE-1). `"v1"` is the frozen `460 × 200` box every
28
+ * existing view keeps; `"v2"` is the compact `352 × 154` default new views
29
+ * pin. A view pins one anatomy; geometry is selected per box, never patched
30
+ * in place. The engine default stays `"v1"` so unpinned views do not move;
31
+ * `createView` pins `"v2"` for genuinely new views.
32
+ */
33
+ export type DiagramAnatomy = "v1" | "v2";
26
34
  /** Frozen card geometry, in card pixels (spec §5.3, Appendix A). */
27
35
  export declare const CARD_GEOMETRY: {
28
36
  readonly width: 460;
@@ -100,6 +108,102 @@ export declare const CARD_GEOMETRY: {
100
108
  readonly footer: 1;
101
109
  };
102
110
  };
111
+ /**
112
+ * Compact card geometry (`diagram-anatomy/v2`): `352 × 154` with padding
113
+ * `6`, header inset `12`, accent `6`, icon `52` / gap `4`. Type scale is
114
+ * unchanged (`22 / 32 / 24`). Unlisted leaves keep their v1 values. Title is
115
+ * one line first (owner addendum 8): over-long titles report `card-overflow`
116
+ * instead of growing the box. The folded header width is derived, not
117
+ * pinned: `352 − border 2 − padding 6 − toggle 66 − headerText 68 = 210`.
118
+ */
119
+ export declare const CARD_GEOMETRY_V2: {
120
+ readonly width: 352;
121
+ readonly height: 154;
122
+ readonly padding: 6;
123
+ readonly accentWidth: 6;
124
+ readonly headerInset: 12;
125
+ readonly iconSize: 52;
126
+ readonly iconTextGap: 4;
127
+ readonly foldedHeaderTextWidth: 210;
128
+ /** Title on one line first (addendum 8); v1 keeps two lines. */
129
+ readonly allocatedLines: {
130
+ readonly kicker: 1;
131
+ readonly title: 1;
132
+ readonly body: 2;
133
+ readonly footer: 1;
134
+ };
135
+ readonly borderWidth: 2;
136
+ readonly kicker: {
137
+ readonly size: 22;
138
+ readonly weight: 400;
139
+ readonly lineHeight: 1.3;
140
+ readonly letterSpacingEm: 0.04;
141
+ };
142
+ readonly title: {
143
+ readonly size: 32;
144
+ readonly weight: 700;
145
+ readonly lineHeight: 1.3;
146
+ };
147
+ /** Header row → body block. */
148
+ readonly gap: 6;
149
+ readonly body: {
150
+ readonly size: 24;
151
+ readonly weight: 400;
152
+ readonly lineHeight: 1.3;
153
+ };
154
+ /**
155
+ * Edge-label text (BF-6): 18px so one line plus margins fits the 32px
156
+ * gutter cap (22 + 2 × 4 = 30 ≤ 32). Mirrors the
157
+ * `diagramScene.edgeLabelFontSize` / `edgeLabelLineHeight` tokens;
158
+ * additive, frozen card sizes unchanged.
159
+ */
160
+ readonly edgeLabel: {
161
+ readonly size: 18;
162
+ readonly weight: 400;
163
+ readonly lineHeight: number;
164
+ };
165
+ /** Accent-bar left edge → first body glyph. */
166
+ readonly bodyInsetFromBar: 14;
167
+ readonly ruleHeight: 1;
168
+ readonly ruleMargin: 4;
169
+ readonly ruleInsetStart: 16;
170
+ readonly ruleInsetEnd: 10;
171
+ readonly footer: {
172
+ readonly size: 24;
173
+ readonly weight: 700;
174
+ readonly lineHeight: 1.3;
175
+ };
176
+ /** Footer text-box bottom → inner edge of the bottom border. */
177
+ readonly footerBottomInset: 9.25;
178
+ /**
179
+ * Title/kicker width reservation when the toggle slot is present
180
+ * (hrpn tints.css `header { padding-right: 66px }`: the 66 px the +/−
181
+ * control needs in the header's inline-end).
182
+ */
183
+ readonly toggleAllocation: 66;
184
+ /** The toggle slot box itself: the 32 px DS IconButton (sm) square. */
185
+ readonly toggleBoxSize: 32;
186
+ readonly toggleInset: 8;
187
+ };
188
+ /** Select the card geometry for a pinned anatomy (default `"v1"`). */
189
+ export declare function anatomyCardGeometry(anatomy: DiagramAnatomy | undefined): typeof CARD_GEOMETRY | typeof CARD_GEOMETRY_V2;
190
+ /**
191
+ * Additive per-entity pin carried alongside a governed `EntityPresentation`
192
+ * (structural, never persisted in the governed fragment): the pinned
193
+ * `diagram-anatomy/v1 | v2` for this box. Absent means `"v1"`.
194
+ */
195
+ export interface AnatomyPinned {
196
+ readonly anatomy?: DiagramAnatomy;
197
+ }
198
+ /**
199
+ * Additive alignment pin (DE-1 step 2), same carrying pattern as
200
+ * `AnatomyPinned`: structural, never persisted in the governed fragment.
201
+ * `"left"` keeps the frozen behaviour; `"center"` centres title and body
202
+ * on both axes. Absent means `"left"`.
203
+ */
204
+ export interface AlignPinned {
205
+ readonly align?: "left" | "center";
206
+ }
103
207
  /**
104
208
  * Edge label typography (DC-2a, tokens `diagramScene.edgeLabelFontSize` /
105
209
  * `diagramScene.edgeLabelLineHeight`): 18 px on a 22 px line box. One line
@@ -139,6 +243,16 @@ export interface CardPresentationInput {
139
243
  readonly categoryRef?: string;
140
244
  /** Neutral status prop: drawn as a dashed border, independent of tint. */
141
245
  readonly proposed?: boolean;
246
+ /**
247
+ * Pinned card anatomy (`diagram-anatomy/v1 | v2`). Absent means `"v1"`;
248
+ * a view pins `"v2"` for the compact box.
249
+ */
250
+ readonly anatomy?: DiagramAnatomy;
251
+ /**
252
+ * Additive alignment pin (DE-1 step 2, `AnatomyPinned` pattern):
253
+ * `"center"` centres title and body on both axes. Absent means `"left"`.
254
+ */
255
+ readonly align?: "left" | "center";
142
256
  }
143
257
  /** Resolved glyph path data (structural twin of the `diagram-icons`
144
258
  * registry record — no import so the barrel never resolves that graph). */
@@ -148,7 +262,7 @@ export interface DiagramGlyphPaths {
148
262
  readonly darkLine?: true;
149
263
  readonly text?: string;
150
264
  readonly severity?: "info";
151
- readonly reason?: "truncated";
265
+ readonly reason?: "truncated" | "fallback-v1";
152
266
  readonly hiddenLength?: number;
153
267
  }
154
268
  export interface DiagramCardToggle {
@@ -183,17 +297,31 @@ export interface DiagramCardProps {
183
297
  readonly proposed?: boolean;
184
298
  readonly toggle?: DiagramCardToggle;
185
299
  /**
186
- * Owner variant: `"center"` centres every text slot horizontally inside its
187
- * frozen allocation (same 460 × 200 box). Default `"left"`.
300
+ * Owner variant: `"center"` centres the kicker/title/footer text slots
301
+ * horizontally inside their frozen allocations (same 460 × 200 box). The
302
+ * body block is always centred — horizontally and vertically — inside
303
+ * the remaining body box. Default `"left"`.
188
304
  */
189
305
  readonly align?: "left" | "center";
190
306
  /**
191
- * Body rendering mode. `"leaf"` (default): left/top-aligned function/detail
192
- * lines at the body inset. `"subtitle"`: the collapsed-zone subtitle —
193
- * wrapped at the frozen 396 px measure and centred horizontally and
194
- * vertically inside the card body area (§6.2.1).
307
+ * Body rendering mode. `"leaf"` (default): function/detail lines at the
308
+ * body inset, centred horizontally and vertically inside the remaining
309
+ * body box. `"subtitle"`: the collapsed-zone subtitle — wrapped at the
310
+ * frozen 396 px measure and centred the same way inside the card body
311
+ * area (§6.2.1).
195
312
  */
196
313
  readonly bodyMode?: "leaf" | "subtitle";
314
+ /**
315
+ * Pinned card anatomy (`diagram-anatomy/v1 | v2`). Absent means `"v1"`;
316
+ * `"v2"` selects the compact `352 × 154` box.
317
+ */
318
+ readonly anatomy?: DiagramAnatomy;
319
+ /**
320
+ * Zone depth surface, set only for zone-collapsed cards (a folded zone
321
+ * keeps its depth background). Leaf cards never set it: their semantic
322
+ * tints are unchanged. Hosts paint the matching zone surface token.
323
+ */
324
+ readonly surface?: ZoneDepthSurface;
197
325
  }
198
326
  export type CardResolveResult = {
199
327
  readonly kind: "card";
@@ -205,6 +333,16 @@ export interface ProjectCardOptions {
205
333
  readonly entityId: string;
206
334
  readonly toggle?: DiagramCardToggle;
207
335
  readonly resolveGlyph?: (name: string) => DiagramGlyphPaths | undefined;
336
+ /**
337
+ * Fallback anatomy when the presentation pins none. Absent means `"v1"`;
338
+ * scene entry points for new views pass `"v2"`.
339
+ */
340
+ readonly anatomy?: DiagramAnatomy;
341
+ /**
342
+ * Fallback alignment when the presentation pins none. Absent means
343
+ * `"left"`; centred scenes pass `"center"`.
344
+ */
345
+ readonly align?: "left" | "center";
208
346
  }
209
347
  /**
210
348
  * Shared `EntityPresentation` → props projection (§4.2), consumed by both
@@ -308,7 +446,7 @@ export interface CardDiagnostic {
308
446
  */
309
447
  readonly text?: string;
310
448
  readonly severity?: "info";
311
- readonly reason?: "truncated";
449
+ readonly reason?: "truncated" | "fallback-v1";
312
450
  readonly hiddenLength?: number;
313
451
  }
314
452
  /** First content diagnostic, for reporting only; renderers retain every slot. */
@@ -341,6 +479,8 @@ export declare function headerSlotGeometry(opts: {
341
479
  readonly hasIcon: boolean;
342
480
  readonly kickerLines: number;
343
481
  readonly titleLines: number;
482
+ /** Icon floor for the block height; defaults to the v1 `70`. */
483
+ readonly iconSize?: number;
344
484
  }): HeaderSlotGeometry;
345
485
  /** Fixed-slot truncation shared by cards and zones (owner A14). */
346
486
  export declare function truncateSlot(text: string, role: "kicker" | "title" | "body" | "footer", width: number, budget: number, measure: CardLineMeasure, report: (diagnostic: {
@@ -390,12 +530,13 @@ export interface CardLayout {
390
530
  readonly headerBlockHeight: number;
391
531
  readonly bodyX: number;
392
532
  readonly bodyWidth: number;
393
- /** Body allocation: vertical centring reference in `subtitle` body mode (§6.2.1). */
533
+ /** Body allocation: vertical centring reference for every card body (leaf and `subtitle` alike). */
394
534
  readonly bodyArea: {
395
535
  readonly top: number;
396
536
  readonly bottom: number;
397
537
  };
398
538
  readonly body: readonly LaidOutLine[];
539
+ /** Bottom of the centred body block (`bodyBlockTop + lines * lineBoxHeight`). */
399
540
  readonly bodyBottom: number;
400
541
  /** Present only when `footer` is set: exactly one rule (§5.4, DH-04). */
401
542
  readonly ruleY?: number;
@@ -410,12 +551,16 @@ export interface CardLayout {
410
551
  readonly y: number;
411
552
  readonly size: number;
412
553
  };
554
+ /** Present when a `v2` compact card overflowed and fell back per box to frozen `v1` (`460 × 200`). */
555
+ readonly anatomyFallback?: "v1";
413
556
  readonly diagnostics: readonly CardDiagnostic[];
414
557
  }
415
558
  /**
416
559
  * Lay out fixed card slots with measured ellipses and a pinned footer.
417
560
  * Informational diagnostics retain the original text and hidden length.
418
561
  * Missing glyphs use the visible unknown icon (owner A2/A11).
562
+ * Compact `v2` cards default to `"center"` alignment and fall back per box
563
+ * to frozen `v1` (`460 × 200`) on overflow instead of dropping slots.
419
564
  */
420
565
  export declare function layoutCard(props: DiagramCardProps, measure: CardLineMeasure): CardLayout;
421
566
  /**
@@ -492,6 +637,90 @@ export declare const ZONE_GEOMETRY: {
492
637
  readonly footer: 1;
493
638
  };
494
639
  };
640
+ /**
641
+ * Compact zone geometry (`diagram-anatomy/v2`): the collapsed zone IS the
642
+ * compact card (`352 × 154`, collapsed subtitle measure `352 − 2 × 32`);
643
+ * expanded chrome follows the compact insets (header `12`, icon `52`,
644
+ * gap `4`). Unlisted leaves keep v1 values; type scale unchanged.
645
+ */
646
+ export declare const ZONE_GEOMETRY_V2: {
647
+ readonly headerInset: 12;
648
+ readonly iconSize: 52;
649
+ readonly iconTextGap: 4;
650
+ /**
651
+ * Expanded header text inset for v2: `12 + 52 + 4 + 86 = 154` so the
652
+ * inline-end toggle reserve stays `86 px` (matching v1) instead of
653
+ * growing to `110 px`.
654
+ */
655
+ readonly headerTextInset: 154;
656
+ readonly collapsedWidth: 352;
657
+ readonly collapsedHeight: 154;
658
+ readonly allocatedLines: {
659
+ readonly kicker: 1;
660
+ readonly title: 1;
661
+ readonly subtitle: 2;
662
+ readonly footer: 1;
663
+ };
664
+ readonly radius: 0;
665
+ readonly borderWidth: 1.5;
666
+ readonly kicker: {
667
+ readonly size: 22;
668
+ readonly weight: 400;
669
+ readonly lineHeight: 1.3;
670
+ readonly letterSpacingEm: 0.04;
671
+ };
672
+ readonly title: {
673
+ readonly size: 32;
674
+ readonly weight: 700;
675
+ readonly lineHeight: 1.3;
676
+ };
677
+ readonly subtitle: {
678
+ readonly size: 24;
679
+ readonly weight: 400;
680
+ readonly lineHeight: 1.3;
681
+ };
682
+ /** Rendered title → subtitle gap: alias of the card `gap` (§6.4). */
683
+ readonly subtitleGap: 6;
684
+ readonly headerRuleGap: 4;
685
+ readonly contentInsetTop: 16;
686
+ readonly contentInsetBottom: 16;
687
+ readonly contentInsetInline: 16;
688
+ readonly ruleHeight: 1;
689
+ readonly ruleMargin: 4;
690
+ readonly ruleInsetStart: 16;
691
+ readonly ruleInsetEnd: 10;
692
+ readonly footer: {
693
+ readonly size: 24;
694
+ readonly weight: 700;
695
+ readonly lineHeight: 1.3;
696
+ };
697
+ readonly footerBottomInset: 9.25;
698
+ readonly toggleAllocation: 66;
699
+ readonly toggleBoxSize: 32;
700
+ /**
701
+ * Expanded toggle top inset: the frozen SVG places every zone toggle at
702
+ * `y + 10` (flush under the frame's top edge), while the header band
703
+ * starts at `y + 16`.
704
+ */
705
+ readonly toggleTopInset: 8;
706
+ readonly toggleInset: 8;
707
+ readonly collapsedInset: 16;
708
+ readonly collapsedSubtitleMarginInline: 16;
709
+ };
710
+ /** Select the zone geometry for a pinned anatomy (default `"v1"`). */
711
+ export declare function anatomyZoneGeometry(anatomy: DiagramAnatomy | undefined): typeof ZONE_GEOMETRY | typeof ZONE_GEOMETRY_V2;
712
+ /**
713
+ * Owner addendum 1 — one engine rule for alternating zone backgrounds by
714
+ * nesting depth. Even depths (top level first) paint `surface1`, odd depths
715
+ * paint `surface2`; `startParity` is selectable per scene and flips which
716
+ * parity the top level takes. Depth normalises to a non-negative integer;
717
+ * card semantic tints are untouched (leaf cards never read this rule).
718
+ */
719
+ export type ZoneDepthSurface = "surface1" | "surface2";
720
+ /** Nesting depth of a zone: `0` is the top level. */
721
+ export declare function normalizeZoneDepth(depth: number | undefined): number;
722
+ /** Resolve the depth surface for a zone (default start parity `0`). */
723
+ export declare function zoneDepthSurface(depth: number | undefined, startParity?: 0 | 1): ZoneDepthSurface;
495
724
  /** Centred collapsed-subtitle measure (§6.2.1): 460 − 2 × (16 + 16). */
496
725
  export declare const COLLAPSED_SUBTITLE_MEASURE: number;
497
726
  export interface DiagramZoneToggle {
@@ -502,6 +731,11 @@ export interface DiagramZoneToggle {
502
731
  export interface DiagramZoneProps {
503
732
  readonly containerPadding?: number;
504
733
  readonly autoSize?: boolean;
734
+ /**
735
+ * Pinned zone anatomy (`diagram-anatomy/v1 | v2`). Absent means `"v1"`;
736
+ * `"v2"` selects the compact collapsed `352 × 154` box.
737
+ */
738
+ readonly anatomy?: DiagramAnatomy;
505
739
  readonly entityId: string;
506
740
  readonly kicker?: string;
507
741
  readonly title: string;
@@ -520,6 +754,23 @@ export interface DiagramZoneProps {
520
754
  readonly toggleLabel?: string;
521
755
  /** Owner variant: `"center"` centres every text slot, both states. */
522
756
  readonly align?: "left" | "center";
757
+ /**
758
+ * Nesting depth of the zone (owner addendum 1): `0` is the top level.
759
+ * The frame — and the folded card — paint the depth surface from the
760
+ * engine rule. Absent means `0`.
761
+ */
762
+ readonly depth?: number;
763
+ /**
764
+ * Opt-in informational diagnostic (owner addendum 1): when true, a leaf
765
+ * card on a same-colour zone surface reports `zone-surface-same`. Off by
766
+ * default — a fitting child renders with no diagnostics.
767
+ */
768
+ readonly reportSurfaceSame?: boolean;
769
+ /**
770
+ * Selectable start parity for the depth rule: `1` flips which parity the
771
+ * top level takes. Scene-global; absent means `0`.
772
+ */
773
+ readonly depthParityStart?: 0 | 1;
523
774
  /**
524
775
  * Occurrence box supplied by the host layout (§6.1: the component paints
525
776
  * around the box it is given). Collapsed, the box is the frozen
@@ -542,8 +793,11 @@ export interface ZoneDiagnostic {
542
793
  * `zone-overflow` / `zone-icon-unknown` are the zone's own; a descendant
543
794
  * card or nested zone keeps its own `card-overflow` / `card-icon-unknown`
544
795
  * code with its own `entityId` when `renderZoneSvg` aggregates them.
796
+ * `zone-surface-same` is informational and opt-in (owner addendum 1):
797
+ * a leaf card on a same-colour zone, reported only for explicitly
798
+ * composed children when the zone sets `reportSurfaceSame`.
545
799
  */
546
- readonly code: "zone-overflow" | "zone-icon-unknown" | "card-icon-missing" | "zone-grown" | "card-overflow" | "card-icon-unknown" | "card-grown";
800
+ readonly code: "zone-overflow" | "zone-icon-unknown" | "card-icon-missing" | "zone-grown" | "card-overflow" | "card-icon-unknown" | "card-grown" | "zone-surface-same";
547
801
  readonly slot: string;
548
802
  readonly entityId: string;
549
803
  readonly neededPx: number;
@@ -551,7 +805,7 @@ export interface ZoneDiagnostic {
551
805
  /** Original, unwrapped slot text retained with the diagnostic. */
552
806
  readonly text?: string;
553
807
  readonly severity?: "info";
554
- readonly reason?: "truncated";
808
+ readonly reason?: "truncated" | "fallback-v1";
555
809
  readonly hiddenLength?: number;
556
810
  }
557
811
  export interface ZoneChildSpec {
@@ -574,6 +828,14 @@ export interface ZoneLayout {
574
828
  readonly height: number;
575
829
  };
576
830
  readonly collapsed: boolean;
831
+ /**
832
+ * Owner addendum 1: resolved depth surface (`surface1` at even depths,
833
+ * top level first) and normalised depth. Present only when depth pins
834
+ * are threaded (absent means `surface1` / `0`); hosts paint the matching
835
+ * zone surface token on the frame and on the folded card.
836
+ */
837
+ readonly surface?: ZoneDepthSurface;
838
+ readonly depth?: number;
577
839
  /** Collapsed: the card layout of the folded card (same geometry source). */
578
840
  readonly card?: CardLayout;
579
841
  /** Expanded: header + rule + footer geometry inside the frame. */
@@ -632,6 +894,32 @@ export interface ZonePresentationInput {
632
894
  readonly categoryRef?: string;
633
895
  /** Neutral status prop: drawn as a dashed border, independent of tint. */
634
896
  readonly proposed?: boolean;
897
+ /**
898
+ * Pinned zone anatomy (`diagram-anatomy/v1 | v2`). Absent means `"v1"`.
899
+ */
900
+ readonly anatomy?: DiagramAnatomy;
901
+ /**
902
+ * Additive alignment pin (DE-1 step 2, `AnatomyPinned` pattern):
903
+ * `"center"` centres title and body on both axes. Absent means `"left"`.
904
+ */
905
+ readonly align?: "left" | "center";
906
+ /**
907
+ * Additive depth pins (owner addendum 1, `AnatomyPinned` pattern):
908
+ * nesting depth (`0` top) and selectable start parity. Absent means
909
+ * `0` / `0`; the scene stamps depth from the view groups.
910
+ */
911
+ readonly depth?: number;
912
+ readonly depthParityStart?: 0 | 1;
913
+ }
914
+ /**
915
+ * Additive depth pins (owner addendum 1), same carrying pattern as
916
+ * `AnatomyPinned`: structural, never persisted in the governed fragment.
917
+ * The scene stamps `depth` from the view groups; `depthParityStart`
918
+ * selects which parity the top level takes.
919
+ */
920
+ export interface DepthPinned {
921
+ readonly depth?: number;
922
+ readonly depthParityStart?: 0 | 1;
635
923
  }
636
924
  export type ZoneResolveResult = {
637
925
  readonly kind: "zone";
@@ -641,10 +929,21 @@ export type ZoneResolveResult = {
641
929
  };
642
930
  export interface ProjectZoneOptions {
643
931
  readonly containerPadding?: number;
932
+ /**
933
+ * Fallback anatomy when the presentation pins none. Absent means `"v1"`;
934
+ * scene entry points for new views pass `"v2"`.
935
+ */
936
+ readonly anatomy?: DiagramAnatomy;
644
937
  readonly entityId: string;
645
938
  readonly collapsed: boolean;
646
939
  readonly toggleLabel?: string;
647
940
  readonly align?: "left" | "center";
941
+ /**
942
+ * Fallback depth pins when the presentation pins none. Absent means
943
+ * `0` / `0`; the scene stamps them from the view groups.
944
+ */
945
+ readonly depth?: number;
946
+ readonly depthParityStart?: 0 | 1;
648
947
  readonly x?: number;
649
948
  readonly y?: number;
650
949
  readonly width?: number;