@sentropic/design-system-elements 0.2.0 → 0.3.2

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 (93) hide show
  1. package/LICENSE.THIRD-PARTY.md +44 -1
  2. package/README.md +81 -13
  3. package/catalog.json +401 -7
  4. package/dist/browser/chunks/{Modeler-BfAmwsmK.js → Modeler-D87tL_OJ.js} +4 -4
  5. package/dist/browser/chunks/Viewer-D9zjRrp2.js +4 -0
  6. package/dist/browser/chunks/bpmn-canvas-BevbP_6a.js +1 -0
  7. package/dist/browser/chunks/bpmn-mount-BhO_zb0S.js +2202 -0
  8. package/dist/browser/chunks/dist-DRauAwm2.js +6 -0
  9. package/dist/browser/chunks/{entropic-CM5BHERN.js → entropic-MwNVEq6w.js} +639 -0
  10. package/dist/browser/chunks/focus-renderer-BWm7DlQD.js +55 -0
  11. package/dist/browser/chunks/{forge-B8hrW4lA.js → forge-CzwO8Hbe.js} +639 -0
  12. package/dist/browser/chunks/layout-T3X333Za.js +1 -0
  13. package/dist/browser/elements.js +671 -6
  14. package/dist/browser/sri.json +52 -45
  15. package/dist/contracts/bar-chart.js +2 -2
  16. package/dist/contracts/decision-dossier.d.ts +4 -8
  17. package/dist/contracts/decision-dossier.js +8 -12
  18. package/dist/contracts/index.d.ts +1 -0
  19. package/dist/contracts/index.js +2 -0
  20. package/dist/contracts/time-series-chart.d.ts +49 -0
  21. package/dist/contracts/time-series-chart.js +37 -0
  22. package/dist/dossier/dossier-mount.js +845 -0
  23. package/dist/dossier/renderer/dossier.css +2 -0
  24. package/dist/element/bpmn-mount.d.ts +11 -0
  25. package/dist/element/bpmn-mount.js +56 -0
  26. package/dist/element/bpmn-types.d.ts +27 -0
  27. package/dist/element/bpmn-types.js +12 -0
  28. package/dist/element/bpmn.d.ts +10 -0
  29. package/dist/element/bpmn.js +39 -0
  30. package/dist/element/dom/dossier-mount.d.ts +25 -0
  31. package/dist/element/dom/dossier-review-mount.d.ts +25 -0
  32. package/dist/element/dom/dossier-review-state.svelte.d.ts +13 -0
  33. package/dist/element/dom/engines/bpmn-canvas.d.ts +11 -0
  34. package/dist/element/dom/engines/bpmn-canvas.js +11 -0
  35. package/dist/element/dom/engines/dossier-diagrams.d.ts +5 -0
  36. package/dist/element/dom/engines/dossier-evidence.d.ts +9 -0
  37. package/dist/element/dom/engines/dossier-styles.d.ts +21 -0
  38. package/dist/element/dom/engines/focus-renderer.d.ts +60 -0
  39. package/dist/element/dom/engines/focus-snapshot.d.ts +3 -0
  40. package/dist/element/dom/intents.d.ts +20 -0
  41. package/dist/element/markdown/minimal-markdown.d.ts +1 -2
  42. package/dist/element/markdown/minimal-markdown.js +19 -1
  43. package/dist/element/validator.d.ts +26 -0
  44. package/dist/element/validator.js +54 -0
  45. package/dist/focus-diagrams/diagram-layout.d.ts +140 -0
  46. package/dist/focus-diagrams/diagram-layout.js +190 -0
  47. package/dist/focus-diagrams/diagram-source.d.ts +11 -0
  48. package/dist/focus-diagrams/diagram-source.js +147 -0
  49. package/dist/focus-diagrams/dossier-views.d.ts +21 -0
  50. package/dist/focus-diagrams/dossier-views.js +57 -0
  51. package/dist/focus-diagrams/ecosystem.json +853 -0
  52. package/dist/focus-kit/index.html +13 -0
  53. package/dist/focus-kit/renderer/dossier.css +2 -0
  54. package/dist/focus-kit/renderer/dossier.js +845 -0
  55. package/dist/focus-kit-manifest.json +1 -0
  56. package/dist/focus-kit.d.ts +9 -0
  57. package/dist/focus-kit.js +30 -0
  58. package/dist/format-time-series-markdown.d.ts +5 -0
  59. package/dist/format-time-series-markdown.js +24 -0
  60. package/dist/generator/parity.js +6 -1
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.js +1 -0
  63. package/dist/ports/dossier-views.d.ts +3 -0
  64. package/dist/ports/dossier-views.js +3 -0
  65. package/dist/ports/focus.d.ts +0 -1
  66. package/dist/ports/types.d.ts +0 -1
  67. package/dist/shells/BarChart.html +8494 -0
  68. package/dist/shells/BarChart.js +8482 -0
  69. package/dist/shells/DecisionDossier.html +8502 -0
  70. package/dist/shells/DecisionDossier.js +8490 -0
  71. package/dist/shells/TimeSeriesChart.html +8475 -0
  72. package/dist/shells/TimeSeriesChart.js +8463 -0
  73. package/dist/shells/manifest.json +108 -0
  74. package/dist/structure/interpreter.d.ts +1 -1
  75. package/dist/structure/interpreter.js +14 -4
  76. package/dist/time-series.d.ts +13 -0
  77. package/dist/time-series.js +15 -0
  78. package/dist/validate/envelope.js +5 -1
  79. package/dist/validate/time-series.d.ts +5 -0
  80. package/dist/validate/time-series.js +28 -0
  81. package/fixtures/time-series-multi.json +46 -0
  82. package/fixtures/time-series-single.json +28 -0
  83. package/fixtures/time-series-thresholds.json +52 -0
  84. package/package.json +40 -6
  85. package/schemas/BarChart.v1.json +2 -2
  86. package/schemas/DecisionDossier.v1.json +155 -5
  87. package/schemas/TimeSeriesChart.v1.json +287 -0
  88. package/skill/SKILL.md +27 -0
  89. package/dist/browser/chunks/Viewer-eYLzc3fD.js +0 -4
  90. package/dist/browser/chunks/bpmn-canvas-DeAWdJFy.js +0 -2207
  91. package/dist/browser/chunks/dist-O6_2ByYB.js +0 -1
  92. package/dist/browser/chunks/focus-renderer-0elVToA2.js +0 -10
  93. package/dist/browser/chunks/layout-q0TR9-aY.js +0 -1
@@ -0,0 +1,140 @@
1
+ import { type SceneDocument, type SceneOccurrenceRef } from "@sentropic/diagram-canvas/diagramSceneModel";
2
+ export declare function dossierDiagramLayout(scene: SceneDocument): {
3
+ document: import("@sentropic/diagram-core").SemanticDocument;
4
+ registry: import("@sentropic/diagram-core").ProfileRegistry;
5
+ bindings: import("@sentropic/diagram-core").ExecutorProfileBindings;
6
+ presentation: import("@sentropic/diagram-core").DiagramPresentation & {
7
+ readonly entities: Readonly<Record<string, import("@sentropic/diagram-core").EntityPresentation & import("@sentropic/diagram-canvas/diagramCardModel").AnatomyPinned & import("@sentropic/diagram-canvas/diagramCardModel").AlignPinned & import("@sentropic/diagram-canvas/diagramCardModel").DepthPinned>>;
8
+ readonly relations?: Readonly<Record<string, import("@sentropic/diagram-core").RelationPresentation>>;
9
+ };
10
+ measureLines: ((request: import("@sentropic/diagram-canvas/diagramCardModel").CardMeasureRequest) => import("@sentropic/diagram-canvas/diagramCardModel").CardLineLayout) & {
11
+ readonly version?: string;
12
+ };
13
+ containers: import("@sentropic/diagram-core").OccurrenceRef[];
14
+ };
15
+ export declare function drawDossierDiagram(sectionId: string, title: string, layout: ReturnType<typeof dossierDiagramLayout>, collapsed: readonly SceneOccurrenceRef[]): {
16
+ diagnostics: (import("@sentropic/diagram-canvas/diagramCardModel").ZoneDiagnostic | import("@sentropic/diagram-canvas").LayoutWarning)[];
17
+ svg: string;
18
+ result: {
19
+ readonly status: "laid-out";
20
+ readonly view: import("@sentropic/diagram-core").ViewDocument;
21
+ readonly fit: import("@sentropic/diagram-canvas").LayoutFit;
22
+ readonly warnings: readonly import("@sentropic/diagram-canvas").LayoutWarning[];
23
+ readonly badgeBoxes?: Readonly<Record<string, import("@sentropic/diagram-canvas").Rect>>;
24
+ readonly arrowBoxes?: Readonly<Record<string, readonly import("@sentropic/diagram-canvas").FlowArrow[]>>;
25
+ readonly flowBundles?: readonly import("@sentropic/diagram-canvas").FlowBundle[];
26
+ readonly flowTargets?: Readonly<Record<string, import("@sentropic/diagram-canvas").FlowVisibleTarget>>;
27
+ readonly flowRepairPasses?: 0 | 1;
28
+ readonly measurements?: import("@sentropic/diagram-canvas").LayoutMeasurements;
29
+ readonly orientations?: Readonly<Record<string, import("@sentropic/diagram-canvas").LevelOrientation>>;
30
+ readonly channels?: readonly import("@sentropic/diagram-canvas").LayoutChannel[];
31
+ readonly routeSpacing?: import("@sentropic/diagram-canvas").RouteSpacingReport;
32
+ readonly labelBoxes?: Readonly<Record<string, {
33
+ readonly x: number;
34
+ readonly y: number;
35
+ readonly width: number;
36
+ readonly height: number;
37
+ }>>;
38
+ readonly edgeBundles?: Readonly<Record<string, {
39
+ readonly members: readonly string[];
40
+ readonly label: string;
41
+ readonly title: string;
42
+ readonly relations?: readonly string[];
43
+ chip?: ReturnType<typeof import("@sentropic/diagram-canvas").measureBundleLabel>;
44
+ }>>;
45
+ readonly linkLegend?: import("@sentropic/diagram-canvas").SceneLinkLegend;
46
+ readonly legendResolved?: boolean;
47
+ readonly composition?: import("@sentropic/diagram-canvas").LayoutCompositionReport;
48
+ readonly combGroups?: readonly import("@sentropic/diagram-canvas").LayoutCombGroup[];
49
+ };
50
+ scene: import("@sentropic/diagram-canvas/diagramSceneModel").SceneModel;
51
+ };
52
+ export declare function prepareDossierDiagram(sectionId: string, title: string, scene: SceneDocument): {
53
+ layout: {
54
+ document: import("@sentropic/diagram-core").SemanticDocument;
55
+ registry: import("@sentropic/diagram-core").ProfileRegistry;
56
+ bindings: import("@sentropic/diagram-core").ExecutorProfileBindings;
57
+ presentation: import("@sentropic/diagram-core").DiagramPresentation & {
58
+ readonly entities: Readonly<Record<string, import("@sentropic/diagram-core").EntityPresentation & import("@sentropic/diagram-canvas/diagramCardModel").AnatomyPinned & import("@sentropic/diagram-canvas/diagramCardModel").AlignPinned & import("@sentropic/diagram-canvas/diagramCardModel").DepthPinned>>;
59
+ readonly relations?: Readonly<Record<string, import("@sentropic/diagram-core").RelationPresentation>>;
60
+ };
61
+ measureLines: ((request: import("@sentropic/diagram-canvas/diagramCardModel").CardMeasureRequest) => import("@sentropic/diagram-canvas/diagramCardModel").CardLineLayout) & {
62
+ readonly version?: string;
63
+ };
64
+ containers: import("@sentropic/diagram-core").OccurrenceRef[];
65
+ };
66
+ expanded: {
67
+ diagnostics: (import("@sentropic/diagram-canvas/diagramCardModel").ZoneDiagnostic | import("@sentropic/diagram-canvas").LayoutWarning)[];
68
+ svg: string;
69
+ result: {
70
+ readonly status: "laid-out";
71
+ readonly view: import("@sentropic/diagram-core").ViewDocument;
72
+ readonly fit: import("@sentropic/diagram-canvas").LayoutFit;
73
+ readonly warnings: readonly import("@sentropic/diagram-canvas").LayoutWarning[];
74
+ readonly badgeBoxes?: Readonly<Record<string, import("@sentropic/diagram-canvas").Rect>>;
75
+ readonly arrowBoxes?: Readonly<Record<string, readonly import("@sentropic/diagram-canvas").FlowArrow[]>>;
76
+ readonly flowBundles?: readonly import("@sentropic/diagram-canvas").FlowBundle[];
77
+ readonly flowTargets?: Readonly<Record<string, import("@sentropic/diagram-canvas").FlowVisibleTarget>>;
78
+ readonly flowRepairPasses?: 0 | 1;
79
+ readonly measurements?: import("@sentropic/diagram-canvas").LayoutMeasurements;
80
+ readonly orientations?: Readonly<Record<string, import("@sentropic/diagram-canvas").LevelOrientation>>;
81
+ readonly channels?: readonly import("@sentropic/diagram-canvas").LayoutChannel[];
82
+ readonly routeSpacing?: import("@sentropic/diagram-canvas").RouteSpacingReport;
83
+ readonly labelBoxes?: Readonly<Record<string, {
84
+ readonly x: number;
85
+ readonly y: number;
86
+ readonly width: number;
87
+ readonly height: number;
88
+ }>>;
89
+ readonly edgeBundles?: Readonly<Record<string, {
90
+ readonly members: readonly string[];
91
+ readonly label: string;
92
+ readonly title: string;
93
+ readonly relations?: readonly string[];
94
+ chip?: ReturnType<typeof import("@sentropic/diagram-canvas").measureBundleLabel>;
95
+ }>>;
96
+ readonly linkLegend?: import("@sentropic/diagram-canvas").SceneLinkLegend;
97
+ readonly legendResolved?: boolean;
98
+ readonly composition?: import("@sentropic/diagram-canvas").LayoutCompositionReport;
99
+ readonly combGroups?: readonly import("@sentropic/diagram-canvas").LayoutCombGroup[];
100
+ };
101
+ scene: import("@sentropic/diagram-canvas/diagramSceneModel").SceneModel;
102
+ };
103
+ folded: {
104
+ diagnostics: (import("@sentropic/diagram-canvas/diagramCardModel").ZoneDiagnostic | import("@sentropic/diagram-canvas").LayoutWarning)[];
105
+ svg: string;
106
+ result: {
107
+ readonly status: "laid-out";
108
+ readonly view: import("@sentropic/diagram-core").ViewDocument;
109
+ readonly fit: import("@sentropic/diagram-canvas").LayoutFit;
110
+ readonly warnings: readonly import("@sentropic/diagram-canvas").LayoutWarning[];
111
+ readonly badgeBoxes?: Readonly<Record<string, import("@sentropic/diagram-canvas").Rect>>;
112
+ readonly arrowBoxes?: Readonly<Record<string, readonly import("@sentropic/diagram-canvas").FlowArrow[]>>;
113
+ readonly flowBundles?: readonly import("@sentropic/diagram-canvas").FlowBundle[];
114
+ readonly flowTargets?: Readonly<Record<string, import("@sentropic/diagram-canvas").FlowVisibleTarget>>;
115
+ readonly flowRepairPasses?: 0 | 1;
116
+ readonly measurements?: import("@sentropic/diagram-canvas").LayoutMeasurements;
117
+ readonly orientations?: Readonly<Record<string, import("@sentropic/diagram-canvas").LevelOrientation>>;
118
+ readonly channels?: readonly import("@sentropic/diagram-canvas").LayoutChannel[];
119
+ readonly routeSpacing?: import("@sentropic/diagram-canvas").RouteSpacingReport;
120
+ readonly labelBoxes?: Readonly<Record<string, {
121
+ readonly x: number;
122
+ readonly y: number;
123
+ readonly width: number;
124
+ readonly height: number;
125
+ }>>;
126
+ readonly edgeBundles?: Readonly<Record<string, {
127
+ readonly members: readonly string[];
128
+ readonly label: string;
129
+ readonly title: string;
130
+ readonly relations?: readonly string[];
131
+ chip?: ReturnType<typeof import("@sentropic/diagram-canvas").measureBundleLabel>;
132
+ }>>;
133
+ readonly linkLegend?: import("@sentropic/diagram-canvas").SceneLinkLegend;
134
+ readonly legendResolved?: boolean;
135
+ readonly composition?: import("@sentropic/diagram-canvas").LayoutCompositionReport;
136
+ readonly combGroups?: readonly import("@sentropic/diagram-canvas").LayoutCombGroup[];
137
+ };
138
+ scene: import("@sentropic/diagram-canvas/diagramSceneModel").SceneModel;
139
+ };
140
+ };
@@ -0,0 +1,190 @@
1
+ import { layoutCard, layoutZone, defaultCardMeasure, sceneCardMeasure } from "@sentropic/diagram-canvas/diagramCardModel";
2
+ import { layoutScene, } from "@sentropic/diagram-canvas/diagramSceneModel";
3
+ import { cardLineMeasurer, projectCardProps, projectZoneProps, renderSceneSvg } from "@sentropic/diagram-canvas/diagram-render";
4
+ import { DossierDiagramError } from "./diagram-source.js";
5
+ const measure = sceneCardMeasure(defaultCardMeasure);
6
+ const measureLines = cardLineMeasurer(measure);
7
+ const layoutFailures = new Set([
8
+ "label-unplaced",
9
+ "label-budget-exhausted",
10
+ "route-obstructed",
11
+ "route-spacing-conflict",
12
+ "channel-unresolved",
13
+ "channel-capacity-exceeded",
14
+ "docking-overflow",
15
+ ]);
16
+ const PRESENTATION_CONTRACT_PIN = {
17
+ id: "diagram-presentation",
18
+ version: "1",
19
+ contentDigest: "74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae",
20
+ };
21
+ // r7 creates fold groups only for types marked as containers. generic@1
22
+ // describes containment but omits that flag. Declare the foldable generic@1
23
+ // profile and its pinned legacy binding without importing diagram-core in the
24
+ // design-system layer.
25
+ const foldableGenericProfile = {
26
+ id: "generic@1",
27
+ name: "generic",
28
+ version: 1,
29
+ completeness: "complete",
30
+ entityTypes: [
31
+ {
32
+ id: "node",
33
+ label: "Node",
34
+ attributes: [
35
+ { name: "name", kind: "text", required: true, maxLength: 200 },
36
+ { name: "state", kind: "enum", values: ["draft", "active", "retired"] },
37
+ { name: "weight", kind: "quantity", units: ["unit"] },
38
+ { name: "duration", kind: "quantity", units: ["s", "min", "h"] },
39
+ { name: "createdAt", kind: "date" },
40
+ { name: "pinned", kind: "boolean" },
41
+ { name: "tags", kind: "collection", item: { kind: "text", maxLength: 40 }, maxItems: 8 },
42
+ { name: "owner", kind: "reference", refKind: "entity" },
43
+ ],
44
+ },
45
+ {
46
+ id: "container",
47
+ label: "Container",
48
+ container: true,
49
+ attributes: [
50
+ { name: "name", kind: "text", required: true, maxLength: 200 },
51
+ { name: "collapsed", kind: "boolean" },
52
+ ],
53
+ },
54
+ ],
55
+ portTypes: [
56
+ {
57
+ id: "port",
58
+ label: "Port",
59
+ directions: ["in", "out", "inout"],
60
+ attributes: [{ name: "label", kind: "text", maxLength: 80 }],
61
+ },
62
+ ],
63
+ relationTypes: [
64
+ {
65
+ id: "link",
66
+ label: "Link",
67
+ direction: "directed",
68
+ roles: [
69
+ { role: "source", cardinality: { min: 1, max: 1 }, targets: ["entity", "port"] },
70
+ { role: "target", cardinality: { min: 1, max: 1 }, targets: ["entity", "port"] },
71
+ ],
72
+ attributes: [
73
+ { name: "label", kind: "text", maxLength: 120 },
74
+ { name: "weight", kind: "quantity", units: ["unit"] },
75
+ ],
76
+ },
77
+ {
78
+ id: "contains",
79
+ label: "Contains",
80
+ direction: "directed",
81
+ roles: [
82
+ { role: "parent", cardinality: { min: 1, max: 1 }, targets: ["entity"], entityTypes: ["container"] },
83
+ { role: "child", cardinality: { min: 1, max: 1 }, targets: ["entity"] },
84
+ ],
85
+ hierarchy: {
86
+ id: "containment",
87
+ shape: "tree",
88
+ parentRole: "parent",
89
+ childRole: "child",
90
+ },
91
+ },
92
+ {
93
+ id: "association",
94
+ label: "Association",
95
+ direction: "undirected",
96
+ roles: [
97
+ { role: "member", cardinality: { min: 2, max: 8 }, targets: ["entity"] },
98
+ ],
99
+ attributes: [{ name: "label", kind: "text", maxLength: 120 }],
100
+ },
101
+ ],
102
+ constraints: [
103
+ { kind: "acyclic-hierarchy", hierarchyId: "containment" },
104
+ { kind: "unique-attribute", entityType: "container", attribute: "name" },
105
+ { kind: "max-entities-of-type", entityType: "container", max: 64 },
106
+ ],
107
+ limits: {
108
+ maxEntities: 100_000,
109
+ maxRelations: 500_000,
110
+ maxEndpointsPerRelation: 8,
111
+ },
112
+ notes: [
113
+ "Foldable generic@1 profile for Focus dossier diagrams.",
114
+ ],
115
+ };
116
+ const registry = {
117
+ get: (id) => (id === "generic@1" ? foldableGenericProfile : undefined),
118
+ has: (id) => id === "generic@1",
119
+ list: () => ["generic@1"],
120
+ };
121
+ const bindings = {
122
+ schemaVersion: "1",
123
+ rows: [{
124
+ profileId: "generic@1",
125
+ profilePin: {
126
+ id: "generic@1",
127
+ version: 1,
128
+ contentDigest: "a003981971bdf75b50f455f19d701130c81fd896aeb7f4b0f0f9fe49dd874b8a",
129
+ },
130
+ declarationAdapter: "legacy-constraints@1",
131
+ }],
132
+ };
133
+ const localIdOf = (ref) => ref.slice(ref.indexOf(":") + 1);
134
+ const occurrenceRef = (id) => `occurrence:${id}`;
135
+ export function dossierDiagramLayout(scene) {
136
+ const entities = Object.fromEntries(Object.values(scene.entities).map((entity) => [
137
+ occurrenceRef(`e.${localIdOf(entity.id)}`),
138
+ {
139
+ form: entity.type === "container" ? "container" : "card",
140
+ text: { title: entity.attributes.name?.kind === "text" ? entity.attributes.name.value : entity.id },
141
+ },
142
+ ]));
143
+ const containers = Object.entries(entities)
144
+ .filter(([, entity]) => entity.form === "container").map(([id]) => id);
145
+ const presentation = {
146
+ contractPin: PRESENTATION_CONTRACT_PIN, entities, legends: {}, categoryTokens: [],
147
+ };
148
+ return { document: scene, registry, bindings, presentation, measureLines, containers };
149
+ }
150
+ export function drawDossierDiagram(sectionId, title, layout, collapsed) {
151
+ const input = { ...layout, collapsed };
152
+ let drawing;
153
+ try {
154
+ // renderSceneSvg uses layoutScene and resolveScene for the drawing.
155
+ drawing = renderSceneSvg(input, { title, measure });
156
+ }
157
+ catch (error) {
158
+ const result = layoutScene(input);
159
+ if (result.status === "laid-out")
160
+ throw error;
161
+ throw new DossierDiagramError(sectionId, "diagram-layout-refused", "The DS engine refused the scene", [...result.refusals, ...result.diagnostics]);
162
+ }
163
+ const diagnostics = drawing.scene.nodes.flatMap((node) => {
164
+ const options = { entityId: node.entity };
165
+ const projected = node.kind === "zone"
166
+ ? projectZoneProps(node.presentation, {
167
+ ...options, collapsed: node.collapsed, width: node.rect.width, height: node.rect.height,
168
+ })
169
+ : projectCardProps(node.presentation, options);
170
+ if (projected.kind === "label")
171
+ return [];
172
+ const overflow = projected.kind === "zone"
173
+ ? layoutZone({ ...projected.props, autoSize: true }, measure).diagnostics
174
+ : layoutCard({ ...projected.props, height: node.rect.height, autoSize: true }, measure).diagnostics;
175
+ return [...overflow].filter((item) => item.code === "card-overflow" || item.code === "zone-overflow");
176
+ });
177
+ const warnings = drawing.result.warnings.filter(({ code }) => layoutFailures.has(code) || code.endsWith("-overflow"));
178
+ return { ...drawing, diagnostics: [...diagnostics, ...warnings] };
179
+ }
180
+ export function prepareDossierDiagram(sectionId, title, scene) {
181
+ const layout = dossierDiagramLayout(scene);
182
+ const expanded = drawDossierDiagram(sectionId, title, layout, []);
183
+ const folded = layout.containers.length === 0 ? expanded : drawDossierDiagram(sectionId, title, layout, layout.containers);
184
+ const diagnostics = folded === expanded ? expanded.diagnostics : [...expanded.diagnostics, ...folded.diagnostics];
185
+ if (diagnostics.length !== 0) {
186
+ throw new DossierDiagramError(sectionId, "diagram-layout-refused", `The DS engine reported ${diagnostics.map(({ code }) => code).join(", ")}`, diagnostics);
187
+ }
188
+ return { layout, expanded, folded };
189
+ }
190
+ //# sourceMappingURL=diagram-layout.js.map
@@ -0,0 +1,11 @@
1
+ import type { DiagramNode } from "@sentropic/focus";
2
+ import type { SceneDocument } from "@sentropic/diagram-canvas/diagramSceneModel";
3
+ export declare class DossierDiagramError extends Error {
4
+ readonly sectionId: string;
5
+ readonly code: "diagram-source-unsupported" | "diagram-layout-refused" | "diagram-views-invalid";
6
+ readonly diagnostics: readonly unknown[];
7
+ constructor(sectionId: string, code: "diagram-source-unsupported" | "diagram-layout-refused" | "diagram-views-invalid", message: string, diagnostics?: readonly unknown[]);
8
+ }
9
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
10
+ export declare function resolveDossierScene(section: DiagramNode): Record<string, unknown>;
11
+ export declare function readDossierScene(sectionId: string, scene: unknown): SceneDocument;
@@ -0,0 +1,147 @@
1
+ import ecosystem from "./ecosystem.json" with { type: "json" };
2
+ export class DossierDiagramError extends Error {
3
+ sectionId;
4
+ code;
5
+ diagnostics;
6
+ constructor(sectionId, code, message, diagnostics = []) {
7
+ super(`Diagram "${sectionId}": ${message}`);
8
+ this.sectionId = sectionId;
9
+ this.code = code;
10
+ this.diagnostics = diagnostics;
11
+ this.name = "DossierDiagramError";
12
+ }
13
+ }
14
+ export function isRecord(value) {
15
+ return value !== null && typeof value === "object" && !Array.isArray(value);
16
+ }
17
+ function closed(value, keys) {
18
+ return isRecord(value) && Object.keys(value).every((key) => keys.includes(key));
19
+ }
20
+ function isText(value) {
21
+ return closed(value, ["kind", "value"]) && value.kind === "text" && typeof value.value === "string";
22
+ }
23
+ /** The portable Focus profile, bounded independently of diagram-core's full vocabulary. */
24
+ function checkScene(scene, refuse) {
25
+ const fail = () => refuse("Unsupported diagram-core document: expected generic@1 nodes/containers, links and a containment tree without views, geometry or layout hints");
26
+ const { schemaVersion, documentId, revision, profileRefs, typeDefinitions, entities, relations, ports, resources, extensions } = scene;
27
+ if (!closed(scene, ["documentId", "schemaVersion", "revision", "profileRefs", "typeDefinitions", "entities", "relations", "ports", "resources", "extensions"]) ||
28
+ typeof documentId !== "string" || !documentId.startsWith("document:") ||
29
+ !closed(schemaVersion, ["major", "minor"]) || schemaVersion.major !== 1 || schemaVersion.minor !== 1 ||
30
+ typeof revision !== "number" || !Number.isInteger(revision) || revision < 0 ||
31
+ !Array.isArray(profileRefs) || profileRefs.length !== 1 || profileRefs[0] !== "generic@1" ||
32
+ !closed(typeDefinitions, []) || !closed(ports, []) || !closed(resources, []) ||
33
+ !Array.isArray(extensions) || extensions.length !== 0)
34
+ fail();
35
+ if (!isRecord(entities) || !isRecord(relations))
36
+ return fail();
37
+ const nodes = Object.entries(entities);
38
+ const edges = Object.entries(relations);
39
+ if (nodes.length === 0 || nodes.length > 80 || edges.length > 240)
40
+ fail();
41
+ const containers = new Set();
42
+ for (const [id, entity] of nodes) {
43
+ if (!id.startsWith("entity:") || !closed(entity, ["id", "profile", "type", "attributes"]) ||
44
+ entity.id !== id || entity.profile !== "generic@1" || (entity.type !== "node" && entity.type !== "container") ||
45
+ !closed(entity.attributes, ["name"]) || !isText(entity.attributes.name))
46
+ return fail();
47
+ if (entity.type === "container")
48
+ containers.add(id);
49
+ }
50
+ const parents = new Map();
51
+ for (const [id, relation] of edges) {
52
+ if (!id.startsWith("relation:") || !closed(relation, ["id", "profile", "type", "endpoints", "attributes"]) ||
53
+ relation.id !== id || relation.profile !== "generic@1" || (relation.type !== "link" && relation.type !== "contains") ||
54
+ !Array.isArray(relation.endpoints) || relation.endpoints.length !== 2 ||
55
+ !relation.endpoints.every((endpoint) => closed(endpoint, ["role", "target"])) ||
56
+ !closed(relation.attributes, relation.type === "link" ? ["label"] : []))
57
+ return fail();
58
+ const { endpoints, type, attributes } = relation;
59
+ const first = endpoints.find((endpoint) => endpoint.role === (type === "link" ? "source" : "parent"))?.target;
60
+ const second = endpoints.find((endpoint) => endpoint.role === (type === "link" ? "target" : "child"))?.target;
61
+ if (typeof first !== "string" || typeof second !== "string" || !Object.hasOwn(entities, first) || !Object.hasOwn(entities, second))
62
+ return fail();
63
+ if (type === "contains") {
64
+ if (!containers.has(first) || parents.has(second))
65
+ fail();
66
+ parents.set(second, first);
67
+ }
68
+ else if (attributes.label !== undefined && !isText(attributes.label))
69
+ fail();
70
+ }
71
+ for (const id of parents.keys()) {
72
+ const visited = new Set();
73
+ for (let current = id; current !== undefined; current = parents.get(current)) {
74
+ if (visited.has(current))
75
+ fail();
76
+ visited.add(current);
77
+ }
78
+ }
79
+ }
80
+ /** Accept the same declaration and labelled-edge grammar as the portable h2a builder. */
81
+ function parseFlowchart(source, id, refuse) {
82
+ const lines = source.trim().split(/\r?\n/).map((line) => line.trim()).filter((line) => line && !line.startsWith("%%"));
83
+ if (!/^flowchart (LR|TB|TD)$/.test(lines.shift() ?? "")) {
84
+ refuse("Unsupported diagram: use ecosystem:<scene> or the documented Mermaid flowchart profile");
85
+ }
86
+ const entities = {};
87
+ const relations = {};
88
+ let edgeCount = 0;
89
+ for (const line of lines) {
90
+ const node = /^([a-z][a-z0-9_-]*)\["([^"<>\n]+)"\]$/.exec(line);
91
+ const edge = /^([a-z][a-z0-9_-]*) -->\|([^|<>\n]+)\| ([a-z][a-z0-9_-]*)$/.exec(line);
92
+ if (node !== null) {
93
+ const entityId = `entity:${node[1]}`;
94
+ if (Object.hasOwn(entities, entityId))
95
+ refuse(`Duplicate diagram node: ${node[1]}`);
96
+ entities[entityId] = { id: entityId, profile: "generic@1", type: "node", attributes: { name: { kind: "text", value: node[2] } } };
97
+ }
98
+ else if (edge !== null) {
99
+ const relationId = `relation:${edgeCount++}`;
100
+ relations[relationId] = {
101
+ id: relationId, profile: "generic@1", type: "link",
102
+ endpoints: [{ role: "source", target: `entity:${edge[1]}` }, { role: "target", target: `entity:${edge[3]}` }],
103
+ attributes: { label: { kind: "text", value: edge[2] } },
104
+ };
105
+ }
106
+ else {
107
+ refuse(`Unsupported flowchart line: ${line}`);
108
+ }
109
+ }
110
+ if (Object.keys(entities).length === 0 || Object.keys(entities).length > 80 || edgeCount > 160) {
111
+ refuse("Diagram needs 1–80 nodes and at most 160 edges");
112
+ }
113
+ return {
114
+ documentId: `document:${id}`, schemaVersion: { major: 1, minor: 1 }, revision: 0,
115
+ profileRefs: ["generic@1"], typeDefinitions: {}, entities, relations, ports: {}, resources: {}, extensions: [],
116
+ };
117
+ }
118
+ export function resolveDossierScene(section) {
119
+ const refuse = (message) => { throw new DossierDiagramError(section.id, "diagram-source-unsupported", message); };
120
+ if (section.sourceRef !== undefined) {
121
+ return refuse(`Reference ${section.renderComponent} -> ${section.sourceRef} requires a host diagram resolver`);
122
+ }
123
+ let scene = section.scene;
124
+ if (scene === undefined) {
125
+ if (section.syntax !== "mermaid")
126
+ return refuse("Unsupported diagram syntax: use Mermaid flowcharts or ecosystem references");
127
+ if (section.source.startsWith("ecosystem:")) {
128
+ const name = section.source.slice("ecosystem:".length);
129
+ if (!Object.hasOwn(ecosystem.scenes, name))
130
+ return refuse(`Unknown ecosystem scene: ${name}`);
131
+ scene = ecosystem.scenes[name].document;
132
+ }
133
+ else {
134
+ scene = parseFlowchart(section.source, section.id, refuse);
135
+ }
136
+ }
137
+ checkScene(scene, refuse);
138
+ return scene;
139
+ }
140
+ export function readDossierScene(sectionId, scene) {
141
+ const refuse = (message) => { throw new DossierDiagramError(sectionId, "diagram-source-unsupported", message); };
142
+ if (!isRecord(scene))
143
+ return refuse("Expected a semantic scene object");
144
+ checkScene(scene, refuse);
145
+ return scene;
146
+ }
147
+ //# sourceMappingURL=diagram-source.js.map
@@ -0,0 +1,21 @@
1
+ import type { SceneDocument, SceneView } from "@sentropic/diagram-canvas/diagramSceneModel";
2
+ export interface DossierDiagramViews {
3
+ readonly scene: SceneDocument;
4
+ readonly views: {
5
+ readonly expanded: SceneView;
6
+ readonly folded: SceneView;
7
+ };
8
+ }
9
+ export interface DossierViews {
10
+ readonly contract: "focus-views/1";
11
+ readonly documentDigest: string;
12
+ readonly rendererDigest: string;
13
+ readonly diagrams: Readonly<Record<string, DossierDiagramViews>>;
14
+ }
15
+ /** Prepare the companion before writing an artifact. Encode it with Focus canonicalJson. */
16
+ export declare function buildDossierViews(input: unknown, kitManifest: unknown): DossierViews | undefined;
17
+ export declare function dossierManifestViews(manifest: unknown): Record<string, unknown> | undefined;
18
+ export declare function validateDossierViews(dossier: unknown, manifest: unknown, companion: unknown, sectionIds: ReadonlySet<string>): ReadonlyMap<string, {
19
+ readonly scene: unknown;
20
+ readonly views: Record<string, unknown>;
21
+ }>;
@@ -0,0 +1,57 @@
1
+ import { baseDigest, canonicalJson } from "@sentropic/focus/editing";
2
+ import { assertFocusDocument } from "@sentropic/focus/validate";
3
+ import { prepareDossierDiagram } from "./diagram-layout.js";
4
+ import { isRecord, resolveDossierScene } from "./diagram-source.js";
5
+ /** Prepare the companion before writing an artifact. Encode it with Focus canonicalJson. */
6
+ export function buildDossierViews(input, kitManifest) {
7
+ const dossier = assertFocusDocument(input);
8
+ const sections = dossier.sections.filter((section) => section.kind === "diagram");
9
+ if (sections.length === 0)
10
+ return undefined;
11
+ const diagrams = Object.fromEntries(sections.map((section) => {
12
+ const scene = JSON.parse(canonicalJson(resolveDossierScene(section)));
13
+ const { expanded, folded } = prepareDossierDiagram(section.id, section.alt, scene);
14
+ return [section.id, { scene, views: { expanded: expanded.result.view, folded: folded.result.view } }];
15
+ }));
16
+ return { contract: "focus-views/1", documentDigest: baseDigest(input), rendererDigest: baseDigest(kitManifest), diagrams };
17
+ }
18
+ export function dossierManifestViews(manifest) {
19
+ if (!isRecord(manifest) || manifest.contract !== "focus-dossier/1" || !Array.isArray(manifest.derived)) {
20
+ throw new Error("Invalid focus-dossier/1 manifest");
21
+ }
22
+ const entries = manifest.derived.filter((entry) => isRecord(entry) && entry.path === "views.json");
23
+ if (entries.length > 1)
24
+ throw new Error("Duplicate views.json manifest entry");
25
+ return entries[0];
26
+ }
27
+ export function validateDossierViews(dossier, manifest, companion, sectionIds) {
28
+ if (manifest === undefined && companion === undefined)
29
+ return new Map();
30
+ const entry = dossierManifestViews(manifest);
31
+ if (!isRecord(manifest) || !isRecord(manifest.document) || manifest.document.digest !== baseDigest(dossier)) {
32
+ throw new Error("Dossier document digest does not match the manifest");
33
+ }
34
+ if (companion === undefined && entry === undefined)
35
+ return new Map();
36
+ if (!isRecord(companion) || companion.contract !== "focus-views/1" || !isRecord(companion.diagrams) ||
37
+ Object.keys(companion).length !== 4)
38
+ throw new Error("Invalid focus-views/1 companion");
39
+ if (companion.documentDigest !== manifest.document.digest)
40
+ throw new Error("Views document digest does not match the manifest");
41
+ if (!isRecord(manifest.renderer) || typeof companion.rendererDigest !== "string" ||
42
+ !/^sha256:[0-9a-f]{64}$/.test(companion.rendererDigest) || companion.rendererDigest !== manifest.renderer.digest) {
43
+ throw new Error("Views renderer digest does not match the manifest");
44
+ }
45
+ if (entry?.mimeType !== "application/json" || entry.digest !== baseDigest(companion) ||
46
+ entry.bytes !== new TextEncoder().encode(canonicalJson(companion)).length) {
47
+ throw new Error("Views file digest or size does not match the manifest");
48
+ }
49
+ return new Map(Object.entries(companion.diagrams).map(([id, diagram]) => {
50
+ if (!sectionIds.has(id) || !isRecord(diagram) || !isRecord(diagram.scene) || !isRecord(diagram.views) ||
51
+ Object.keys(diagram).length !== 2 || Object.keys(diagram.views).length !== 2) {
52
+ throw new Error(`Invalid views companion entry for diagram "${id}"`);
53
+ }
54
+ return [id, { scene: diagram.scene, views: diagram.views }];
55
+ }));
56
+ }
57
+ //# sourceMappingURL=dossier-views.js.map