@sentropic/diagram-core 0.4.0 → 0.5.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.
package/README.md CHANGED
@@ -374,3 +374,16 @@ if a compiler reads them. Remove the brand from `Ref<K>` and `check` reports 42
374
374
  and scenarios. Relation refinements resolve through `relationBaseType` and
375
375
  `relationSchema`, preserving inherited roles and constraints. See
376
376
  [the authoring contract and mapping examples](../../docs/DC2C_NUMBERED_FLOWS.md).
377
+
378
+ ## Diagram conventions (DE-2)
379
+
380
+ - **Arrow direction (`source` = initiator of the action):** directed relations
381
+ declare the initiator of the action as the `source` endpoint and the receiver
382
+ as the `target` endpoint. Scenes that declare initiator metadata (via
383
+ `relation.attributes.initiator` or caller-supplied initiator maps) can run the
384
+ opt-in `arrow-direction-convention` lint in `@sentropic/diagram-canvas`.
385
+ - **Zone tags (`kicker`):** bare opaque acronyms without a descriptive label
386
+ should be avoided; acronyms belong with their label (e.g. `"IAM — Identity &
387
+ Access Management"`). `@sentropic/diagram-canvas` provides the opt-in
388
+ non-blocking `zone-tag-opaque-acronym` lint with an allowlist for `DLR-315`
389
+ product kickers.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Closed connector presentation registries (DE-2): dash patterns, arrowhead
3
+ * kinds (ready for ArchiMate later), and link emphasis.
4
+ *
5
+ * Connectors are selected strictly by closed vocabulary words from the view /
6
+ * presentation layer — never by raw SVG geometry, dash-array strings, marker
7
+ * path data, or colour/width literals. Emphasis is a distinct colour + width
8
+ * axis and is NEVER a dash style (`dashed` continues to mean "proposed").
9
+ *
10
+ * Pure deeply-frozen data, zero runtime dependencies, zero DOM.
11
+ */
12
+ export declare const STROKE_STYLES: readonly ["solid", "dashed", "dotted"];
13
+ export type StrokeStyle = (typeof STROKE_STYLES)[number];
14
+ export interface DashPatternDescriptor {
15
+ readonly style: StrokeStyle;
16
+ /** Semantic meaning of the pattern (`dashed` already means "proposed"). */
17
+ readonly meaning: "default" | "proposed" | "dotted";
18
+ /** World-unit dash/gap fallback pattern when CSS tokens are absent. */
19
+ readonly dashArray: readonly number[];
20
+ /** Component token key under `diagramScene.*`, omitted for solid strokes. */
21
+ readonly tokenName?: "linkDashDashed" | "linkDashDotted";
22
+ }
23
+ export declare const ARROWHEAD_KINDS: readonly ["arrow", "none"];
24
+ export type ArrowheadKind = (typeof ARROWHEAD_KINDS)[number];
25
+ export type CanonicalArrowheadKind = "arrow" | "none";
26
+ export interface ArrowheadDescriptor {
27
+ readonly kind: ArrowheadKind;
28
+ /** Normalized visual head kind (`"arrow"` or `"none"` in `@4`; further heads reserved for N2). */
29
+ readonly canonicalKind: CanonicalArrowheadKind;
30
+ readonly shape: "triangle" | "none";
31
+ readonly fill: "stroke" | "none";
32
+ readonly outlined: false;
33
+ }
34
+ export declare const LINK_EMPHASIS_KINDS: readonly ["default", "emphasis"];
35
+ export type LinkEmphasis = (typeof LINK_EMPHASIS_KINDS)[number];
36
+ export interface LinkEmphasisDescriptor {
37
+ readonly emphasis: LinkEmphasis;
38
+ readonly strokeToken: "edgeStroke" | "linkEmphasisStroke";
39
+ readonly widthToken: "linkStrokeWidth" | "linkEmphasisStrokeWidth";
40
+ /** Emphasis is strictly a colour + width axis, never a dash style. */
41
+ readonly changesDash: false;
42
+ }
43
+ /**
44
+ * Word-addressed connector presentation for a relation occurrence.
45
+ * Every field is a closed registry word; raw geometry is refused.
46
+ */
47
+ export interface RelationPresentation {
48
+ readonly strokeStyle?: StrokeStyle;
49
+ readonly arrowhead?: ArrowheadKind;
50
+ readonly emphasis?: LinkEmphasis;
51
+ }
52
+ export declare const DASH_PATTERN_REGISTRY: Readonly<Record<StrokeStyle, DashPatternDescriptor>>;
53
+ export declare const ARROWHEAD_REGISTRY: Readonly<Record<ArrowheadKind, ArrowheadDescriptor>>;
54
+ export declare const LINK_EMPHASIS_REGISTRY: Readonly<Record<LinkEmphasis, LinkEmphasisDescriptor>>;
55
+ export declare function isStrokeStyle(value: unknown): value is StrokeStyle;
56
+ export declare function isArrowheadKind(value: unknown): value is ArrowheadKind;
57
+ export declare function isLinkEmphasis(value: unknown): value is LinkEmphasis;
58
+ export declare function resolveDashPattern(style: StrokeStyle | undefined): DashPatternDescriptor;
59
+ export declare function resolveDashPattern(style: string | undefined): DashPatternDescriptor | undefined;
60
+ export declare function resolveArrowhead(kind: ArrowheadKind | undefined): ArrowheadDescriptor;
61
+ export declare function resolveArrowhead(kind: string | undefined): ArrowheadDescriptor | undefined;
62
+ export declare function resolveLinkEmphasis(emphasis: LinkEmphasis | undefined): LinkEmphasisDescriptor;
63
+ export declare function resolveLinkEmphasis(emphasis: string | undefined): LinkEmphasisDescriptor | undefined;
64
+ //# sourceMappingURL=connector-registry.d.ts.map
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Closed connector presentation registries (DE-2): dash patterns, arrowhead
3
+ * kinds (ready for ArchiMate later), and link emphasis.
4
+ *
5
+ * Connectors are selected strictly by closed vocabulary words from the view /
6
+ * presentation layer — never by raw SVG geometry, dash-array strings, marker
7
+ * path data, or colour/width literals. Emphasis is a distinct colour + width
8
+ * axis and is NEVER a dash style (`dashed` continues to mean "proposed").
9
+ *
10
+ * Pure deeply-frozen data, zero runtime dependencies, zero DOM.
11
+ */
12
+ export const STROKE_STYLES = ["solid", "dashed", "dotted"];
13
+ export const ARROWHEAD_KINDS = ["arrow", "none"];
14
+ export const LINK_EMPHASIS_KINDS = ["default", "emphasis"];
15
+ function deepFreeze(value) {
16
+ if (value === null || typeof value !== "object" || Object.isFrozen(value))
17
+ return value;
18
+ for (const child of Object.values(value))
19
+ deepFreeze(child);
20
+ return Object.freeze(value);
21
+ }
22
+ export const DASH_PATTERN_REGISTRY = deepFreeze({
23
+ solid: {
24
+ style: "solid",
25
+ meaning: "default",
26
+ dashArray: [],
27
+ },
28
+ dashed: {
29
+ style: "dashed",
30
+ meaning: "proposed",
31
+ dashArray: [8, 6],
32
+ tokenName: "linkDashDashed",
33
+ },
34
+ dotted: {
35
+ style: "dotted",
36
+ meaning: "dotted",
37
+ dashArray: [2, 5],
38
+ tokenName: "linkDashDotted",
39
+ },
40
+ });
41
+ export const ARROWHEAD_REGISTRY = deepFreeze({
42
+ arrow: {
43
+ kind: "arrow",
44
+ canonicalKind: "arrow",
45
+ shape: "triangle",
46
+ fill: "stroke",
47
+ outlined: false,
48
+ },
49
+ none: {
50
+ kind: "none",
51
+ canonicalKind: "none",
52
+ shape: "none",
53
+ fill: "none",
54
+ outlined: false,
55
+ },
56
+ });
57
+ export const LINK_EMPHASIS_REGISTRY = deepFreeze({
58
+ default: {
59
+ emphasis: "default",
60
+ strokeToken: "edgeStroke",
61
+ widthToken: "linkStrokeWidth",
62
+ changesDash: false,
63
+ },
64
+ emphasis: {
65
+ emphasis: "emphasis",
66
+ strokeToken: "linkEmphasisStroke",
67
+ widthToken: "linkEmphasisStrokeWidth",
68
+ changesDash: false,
69
+ },
70
+ });
71
+ const STROKE_STYLE_SET = new Set(STROKE_STYLES);
72
+ const ARROWHEAD_KIND_SET = new Set(ARROWHEAD_KINDS);
73
+ const LINK_EMPHASIS_SET = new Set(LINK_EMPHASIS_KINDS);
74
+ export function isStrokeStyle(value) {
75
+ return typeof value === "string" && STROKE_STYLE_SET.has(value);
76
+ }
77
+ export function isArrowheadKind(value) {
78
+ return typeof value === "string" && ARROWHEAD_KIND_SET.has(value);
79
+ }
80
+ export function isLinkEmphasis(value) {
81
+ return typeof value === "string" && LINK_EMPHASIS_SET.has(value);
82
+ }
83
+ export function resolveDashPattern(style) {
84
+ if (style === undefined)
85
+ return DASH_PATTERN_REGISTRY.solid;
86
+ return isStrokeStyle(style) ? DASH_PATTERN_REGISTRY[style] : undefined;
87
+ }
88
+ export function resolveArrowhead(kind) {
89
+ if (kind === undefined)
90
+ return ARROWHEAD_REGISTRY.arrow;
91
+ return isArrowheadKind(kind) ? ARROWHEAD_REGISTRY[kind] : undefined;
92
+ }
93
+ export function resolveLinkEmphasis(emphasis) {
94
+ if (emphasis === undefined)
95
+ return LINK_EMPHASIS_REGISTRY.default;
96
+ return isLinkEmphasis(emphasis) ? LINK_EMPHASIS_REGISTRY[emphasis] : undefined;
97
+ }
98
+ //# sourceMappingURL=connector-registry.js.map
package/dist/fold.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { StrokeStyle } from "./connector-registry.js";
1
2
  import type { SemanticDocument } from "./document.js";
2
3
  import type { ProfileRegistry } from "./profile.js";
3
4
  import type { RelationOccurrence, ViewDocument } from "./view.js";
@@ -101,7 +102,7 @@ export interface ActiveSummary {
101
102
  interface SummaryCandidate {
102
103
  readonly occurrence: OccurrenceRef;
103
104
  readonly relation: RelationRef;
104
- readonly style: "solid" | "dashed";
105
+ readonly style: StrokeStyle;
105
106
  }
106
107
  export interface SummaryResolutionOptions {
107
108
  /** Evaluated filter exclusions feeding aggregate resolution (§4.4.6). */
@@ -110,7 +111,7 @@ export interface SummaryResolutionOptions {
110
111
  readonly registry: ProfileRegistry;
111
112
  }
112
113
  /** Binary candidate occurrences whose oriented endpoints lie in the two scopes. */
113
- export declare function summaryCandidates(view: ViewDocument, document: SemanticDocument, registry: ProfileRegistry, source: OccurrenceRef, target: OccurrenceRef, style: "solid" | "dashed"): SummaryCandidate[];
114
+ export declare function summaryCandidates(view: ViewDocument, document: SemanticDocument, registry: ProfileRegistry, source: OccurrenceRef, target: OccurrenceRef, style: StrokeStyle): SummaryCandidate[];
114
115
  export type SummaryCheck = "summary-constituents-mismatch" | "summary-duplicate-key" | "summary-occurrence-ambiguous" | "summary-active-key-conflict";
115
116
  export interface SummaryIssue {
116
117
  readonly id: string;
package/dist/fold.js CHANGED
@@ -205,6 +205,8 @@ export function projectRelationOccurrences(sourceView, document, collapsed) {
205
205
  ? {}
206
206
  : { waypoints: occurrence.waypoints.map((point) => ({ ...point })) }),
207
207
  ...(occurrence.strokeStyle === undefined ? {} : { strokeStyle: occurrence.strokeStyle }),
208
+ ...(occurrence.arrowhead === undefined ? {} : { arrowhead: occurrence.arrowhead }),
209
+ ...(occurrence.emphasis === undefined ? {} : { emphasis: occurrence.emphasis }),
208
210
  };
209
211
  continue;
210
212
  }
@@ -240,6 +242,8 @@ export function projectRelationOccurrences(sourceView, document, collapsed) {
240
242
  ? {}
241
243
  : { waypoints: occurrence.waypoints.map((point) => ({ ...point })) }),
242
244
  ...(occurrence.strokeStyle === undefined ? {} : { strokeStyle: occurrence.strokeStyle }),
245
+ ...(occurrence.arrowhead === undefined ? {} : { arrowhead: occurrence.arrowhead }),
246
+ ...(occurrence.emphasis === undefined ? {} : { emphasis: occurrence.emphasis }),
243
247
  };
244
248
  }
245
249
  return relationOccurrences;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * from "./bindings.js";
14
14
  export * from "./multiplicity.js";
15
15
  export * from "./archimate-cases.js";
16
16
  export * from "./profile-migrations.js";
17
+ export * from "./connector-registry.js";
17
18
  export * from "./presentation.js";
18
19
  export * from "./presentation-relations.js";
19
20
  export * from "./presentation-apply.js";
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ export * from "./bindings.js";
14
14
  export * from "./multiplicity.js";
15
15
  export * from "./archimate-cases.js";
16
16
  export * from "./profile-migrations.js";
17
+ export * from "./connector-registry.js";
17
18
  export * from "./presentation.js";
18
19
  export * from "./presentation-relations.js";
19
20
  export * from "./presentation-apply.js";
@@ -1,25 +1,90 @@
1
- /** Resolve document relation refinements and diagram-presentation@2 at the boundary of the frozen presentation adapter. */
1
+ /** Resolve document relation refinements, diagram-presentation@2 and DE-2 connector words at the boundary of the frozen presentation adapter. */
2
+ import { isArrowheadKind, isLinkEmphasis } from "./connector-registry.js";
3
+ import { diagnostic } from "./diagnostics.js";
2
4
  import { DIAGRAM_PRESENTATION_CONTRACT_PIN, isPresentationContractV2Pin, } from "./presentation.js";
3
5
  import { validateDiagramPresentation as validatePinnedPresentation } from "./presentation-validate.js";
4
6
  import { relationBaseType } from "./relation-types.js";
5
7
  function isRecord(value) {
6
8
  return typeof value === "object" && value !== null && !Array.isArray(value);
7
9
  }
8
- function normalizeV2View(view) {
10
+ function shapeInvalid(path) {
11
+ return diagnostic({
12
+ code: "occurrence-endpoint-mismatch",
13
+ severity: "error",
14
+ path,
15
+ message: "diagram presentation fails check presentation-shape-invalid",
16
+ refs: [],
17
+ details: { check: "presentation-shape-invalid" },
18
+ });
19
+ }
20
+ function normalizeViewForPinnedAdapter(view) {
9
21
  const diagram = view.presentation.diagram;
10
- if (!isRecord(diagram) || !isRecord(diagram["contractPin"]))
11
- return view;
12
- if (!isPresentationContractV2Pin(diagram["contractPin"]))
13
- return view;
22
+ const hasDiagram = isRecord(diagram);
23
+ const isV2 = hasDiagram &&
24
+ isRecord(diagram["contractPin"]) &&
25
+ isPresentationContractV2Pin(diagram["contractPin"]);
26
+ const isFrozenV1 = hasDiagram && !isV2;
27
+ const ALLOWED_RELATION_OCCURRENCE_KEYS = new Set([
28
+ "id",
29
+ "relation",
30
+ "endpoints",
31
+ "waypoints",
32
+ "strokeStyle",
33
+ "arrowhead",
34
+ "emphasis",
35
+ ]);
36
+ const connectorDiagnostics = [];
37
+ let relationOccurrencesChanged = false;
38
+ const normalizedRelations = {};
39
+ for (const key of Object.keys(view.relationOccurrences).sort()) {
40
+ const occurrence = view.relationOccurrences[key];
41
+ for (const field of Object.keys(occurrence).sort()) {
42
+ if (!ALLOWED_RELATION_OCCURRENCE_KEYS.has(field)) {
43
+ connectorDiagnostics.push(shapeInvalid(`relationOccurrences.${key}.${field}`));
44
+ }
45
+ }
46
+ const arrowhead = occurrence["arrowhead"];
47
+ if (arrowhead !== undefined && (isFrozenV1 || !isArrowheadKind(arrowhead))) {
48
+ connectorDiagnostics.push(shapeInvalid(`relationOccurrences.${key}.arrowhead`));
49
+ }
50
+ const emphasis = occurrence["emphasis"];
51
+ if (emphasis !== undefined && (isFrozenV1 || !isLinkEmphasis(emphasis))) {
52
+ connectorDiagnostics.push(shapeInvalid(`relationOccurrences.${key}.emphasis`));
53
+ }
54
+ // Frozen diagram-presentation@1 keeps its exact @1 strokeStyle check
55
+ // ("solid" | "dashed"); diagram-presentation@2 admits the DE-2 "dotted" word.
56
+ if (isV2 && occurrence["strokeStyle"] === "dotted") {
57
+ normalizedRelations[key] = { ...occurrence, strokeStyle: "dashed" };
58
+ relationOccurrencesChanged = true;
59
+ }
60
+ else {
61
+ normalizedRelations[key] = occurrence;
62
+ }
63
+ }
64
+ if (isFrozenV1 && isRecord(view.summaryLabels)) {
65
+ for (const id of Object.keys(view.summaryLabels).sort()) {
66
+ const summary = view.summaryLabels[id];
67
+ if (isRecord(summary) && summary["strokeStyle"] === "dotted") {
68
+ connectorDiagnostics.push(shapeInvalid(`summaryLabels.${id}.strokeStyle`));
69
+ }
70
+ }
71
+ }
72
+ let nextView = relationOccurrencesChanged
73
+ ? { ...view, relationOccurrences: normalizedRelations }
74
+ : view;
75
+ if (!isV2 || !isRecord(diagram)) {
76
+ return { view: nextView, connectorDiagnostics };
77
+ }
14
78
  const rawEntities = diagram["entities"];
15
79
  if (!isRecord(rawEntities)) {
16
- return {
17
- ...view,
80
+ nextView = {
81
+ ...nextView,
18
82
  presentation: {
19
- ...view.presentation,
83
+ ...nextView.presentation,
20
84
  diagram: { ...diagram, contractPin: { ...DIAGRAM_PRESENTATION_CONTRACT_PIN } },
21
85
  },
22
86
  };
87
+ return { view: nextView, connectorDiagnostics };
23
88
  }
24
89
  const entities = {};
25
90
  for (const [key, entry] of Object.entries(rawEntities)) {
@@ -34,10 +99,10 @@ function normalizeV2View(view) {
34
99
  }
35
100
  entities[key] = entry;
36
101
  }
37
- return {
38
- ...view,
102
+ nextView = {
103
+ ...nextView,
39
104
  presentation: {
40
- ...view.presentation,
105
+ ...nextView.presentation,
41
106
  diagram: {
42
107
  ...diagram,
43
108
  contractPin: { ...DIAGRAM_PRESENTATION_CONTRACT_PIN },
@@ -45,6 +110,7 @@ function normalizeV2View(view) {
45
110
  },
46
111
  },
47
112
  };
113
+ return { view: nextView, connectorDiagnostics };
48
114
  }
49
115
  export function validateDiagramPresentation(...args) {
50
116
  const [document, view, options] = args;
@@ -57,6 +123,8 @@ export function validateDiagramPresentation(...args) {
57
123
  changed = true;
58
124
  return [id, { ...relation, type }];
59
125
  }));
60
- return validatePinnedPresentation(changed ? { ...document, relations } : document, normalizeV2View(view), options);
126
+ const normalized = normalizeViewForPinnedAdapter(view);
127
+ const pinned = validatePinnedPresentation(changed ? { ...document, relations } : document, normalized.view, options);
128
+ return normalized.connectorDiagnostics.length === 0 ? pinned : [...normalized.connectorDiagnostics, ...pinned];
61
129
  }
62
130
  //# sourceMappingURL=presentation-relations.js.map
@@ -15,7 +15,8 @@ export interface PresentationPin {
15
15
  readonly version: string;
16
16
  readonly contentDigest: string;
17
17
  }
18
- export type StrokeStyle = "solid" | "dashed";
18
+ import type { StrokeStyle } from "./connector-registry.js";
19
+ export type { StrokeStyle };
19
20
  export type DiagramForm = "card" | "container" | "legend" | "legend-key";
20
21
  /** Text/header alignment governed by `diagram-presentation@2` (DE-1). */
21
22
  export type PresentationAlign = "left" | "center";
package/dist/validate.js CHANGED
@@ -24,6 +24,7 @@ import { hashContent } from "./hash.js";
24
24
  import { entityTypeOf, portTypeOf, qualifyAttributeSchema, relationTypeOf, roleOf, selectGroupingHierarchy, validateProfile, } from "./profile.js";
25
25
  import { parseRef, refKindOf, } from "./refs.js";
26
26
  import { createTypeResolver } from "./resolver.js";
27
+ import { isArrowheadKind, isLinkEmphasis, isStrokeStyle } from "./connector-registry.js";
27
28
  import { isPresentationContractProfileId } from "./presentation.js";
28
29
  import { validateDiagramPresentation } from "./presentation-relations.js";
29
30
  import { analyzeSummaries, classifyInternalRelations, collapsedOf, drawnTargetOf, hiddenByFold, parentOccurrenceOf, portRepresentativeOf, representativeOf, } from "./fold.js";
@@ -1879,6 +1880,60 @@ export function validateView(view, document, options, hidden) {
1879
1880
  for (const [index, waypoint] of (occurrence.waypoints ?? []).entries()) {
1880
1881
  diagnostics.push(...finiteNumbers([["x", waypoint.x], ["y", waypoint.y]], `${path}.waypoints[${index}]`));
1881
1882
  }
1883
+ if (view.presentation.diagram === undefined) {
1884
+ const allowedKeys = new Set([
1885
+ "id",
1886
+ "relation",
1887
+ "endpoints",
1888
+ "waypoints",
1889
+ "strokeStyle",
1890
+ "arrowhead",
1891
+ "emphasis",
1892
+ ]);
1893
+ const raw = occurrence;
1894
+ for (const field of Object.keys(raw).sort()) {
1895
+ if (!allowedKeys.has(field)) {
1896
+ diagnostics.push(diagnostic({
1897
+ code: "occurrence-endpoint-mismatch",
1898
+ severity: "error",
1899
+ path: `${path}.${field}`,
1900
+ message: `relation occurrence field ${field} is not part of the closed connector vocabulary`,
1901
+ refs: [occurrence.id],
1902
+ details: { check: "presentation-shape-invalid" },
1903
+ }));
1904
+ }
1905
+ }
1906
+ if (raw["strokeStyle"] !== undefined && !isStrokeStyle(raw["strokeStyle"])) {
1907
+ diagnostics.push(diagnostic({
1908
+ code: "occurrence-endpoint-mismatch",
1909
+ severity: "error",
1910
+ path: `${path}.strokeStyle`,
1911
+ message: `strokeStyle ${String(raw["strokeStyle"])} must be a closed dash-pattern word`,
1912
+ refs: [occurrence.id],
1913
+ details: { check: "presentation-shape-invalid" },
1914
+ }));
1915
+ }
1916
+ if (raw["arrowhead"] !== undefined && !isArrowheadKind(raw["arrowhead"])) {
1917
+ diagnostics.push(diagnostic({
1918
+ code: "occurrence-endpoint-mismatch",
1919
+ severity: "error",
1920
+ path: `${path}.arrowhead`,
1921
+ message: `arrowhead ${String(raw["arrowhead"])} must be a closed arrowhead word`,
1922
+ refs: [occurrence.id],
1923
+ details: { check: "presentation-shape-invalid" },
1924
+ }));
1925
+ }
1926
+ if (raw["emphasis"] !== undefined && !isLinkEmphasis(raw["emphasis"])) {
1927
+ diagnostics.push(diagnostic({
1928
+ code: "occurrence-endpoint-mismatch",
1929
+ severity: "error",
1930
+ path: `${path}.emphasis`,
1931
+ message: `emphasis ${String(raw["emphasis"])} must be a closed link-emphasis word`,
1932
+ refs: [occurrence.id],
1933
+ details: { check: "presentation-shape-invalid" },
1934
+ }));
1935
+ }
1936
+ }
1882
1937
  }
1883
1938
  // Drawn representatives of projected endpoints: their container capability
1884
1939
  // is reported once at the endpoint (`representative-not-container`), so the
@@ -1965,6 +2020,17 @@ export function validateView(view, document, options, hidden) {
1965
2020
  message: `record key ${id} is not the summary definition id ${definition.id}`,
1966
2021
  }));
1967
2022
  }
2023
+ const rawStyle = definition["strokeStyle"];
2024
+ if (rawStyle !== undefined && !isStrokeStyle(rawStyle)) {
2025
+ diagnostics.push(diagnostic({
2026
+ code: "occurrence-endpoint-mismatch",
2027
+ severity: "error",
2028
+ path: `summaryLabels.${id}.strokeStyle`,
2029
+ message: `strokeStyle ${String(rawStyle)} must be a closed dash-pattern word`,
2030
+ refs: [id],
2031
+ details: { check: "presentation-shape-invalid" },
2032
+ }));
2033
+ }
1968
2034
  }
1969
2035
  const analysis = analyzeSummaries(view, document, {
1970
2036
  registry: options.registry,
@@ -2026,6 +2092,25 @@ export function validateView(view, document, options, hidden) {
2026
2092
  details: { check: "presentation-shape-invalid" },
2027
2093
  }));
2028
2094
  }
2095
+ const entityAnatomy = view.presentation.entityAnatomy;
2096
+ if (entityAnatomy !== undefined && (entityAnatomy === null || typeof entityAnatomy !== "object" || Array.isArray(entityAnatomy))) {
2097
+ diagnostics.push(diagnostic({
2098
+ code: "occurrence-endpoint-mismatch",
2099
+ path: "presentation.entityAnatomy",
2100
+ message: "entity anatomy overrides must be keyed by occurrence",
2101
+ }));
2102
+ }
2103
+ else {
2104
+ for (const [id, anatomy] of Object.entries(entityAnatomy ?? {})) {
2105
+ if (Object.hasOwn(view.entityOccurrences, id) && (anatomy === "v1" || anatomy === "v2"))
2106
+ continue;
2107
+ diagnostics.push(diagnostic({
2108
+ code: "occurrence-endpoint-mismatch",
2109
+ path: `presentation.entityAnatomy.${id}`,
2110
+ message: "anatomy must be v1 or v2 and reference an entity occurrence",
2111
+ }));
2112
+ }
2113
+ }
2029
2114
  if (view.presentation.diagram !== undefined) {
2030
2115
  diagnostics.push(...validateDiagramPresentation(document, view, options));
2031
2116
  }
@@ -21,7 +21,7 @@ export interface ViewSchemaPin {
21
21
  readonly version: string;
22
22
  readonly contentDigest: string;
23
23
  }
24
- export type ViewSchemaVersion = "1" | "2" | "3";
24
+ export type ViewSchemaVersion = "1" | "2" | "3" | "4";
25
25
  export declare const DIAGRAM_VIEW_SCHEMA_ID: "diagram-view-schema";
26
26
  export declare const DIAGRAM_VIEW_SCHEMA_V1: Record<string, unknown>;
27
27
  export declare const DIAGRAM_VIEW_SCHEMA_V1_DIGEST: string;
@@ -46,6 +46,9 @@ export type ViewSchemaResolution = {
46
46
  export declare const DIAGRAM_VIEW_SCHEMA_V3: Record<string, unknown>;
47
47
  export declare const DIAGRAM_VIEW_SCHEMA_V3_DIGEST: string;
48
48
  export declare const DIAGRAM_VIEW_SCHEMA_V3_PIN: ViewSchemaPin;
49
+ export declare const DIAGRAM_VIEW_SCHEMA_V4: Record<string, unknown>;
50
+ export declare const DIAGRAM_VIEW_SCHEMA_V4_DIGEST: string;
51
+ export declare const DIAGRAM_VIEW_SCHEMA_V4_PIN: ViewSchemaPin;
49
52
  /**
50
53
  * Resolve a view schema by exact pin only. Never throws: every failure is a
51
54
  * typed refusal. No "latest", no fallback, no reverse migration.
@@ -87,6 +87,38 @@ export const DIAGRAM_VIEW_SCHEMA_V3_DIGEST = sha256Hex(canonicalBytes(PRIVATE_V3
87
87
  export const DIAGRAM_VIEW_SCHEMA_V3_PIN = deepFreezeValue({
88
88
  id: DIAGRAM_VIEW_SCHEMA_ID, version: "3", contentDigest: DIAGRAM_VIEW_SCHEMA_V3_DIGEST,
89
89
  });
90
+ /**
91
+ * Additive successor (DE-2): closed connector presentation registries
92
+ * (`strokeStyle: solid | dashed | dotted`, `arrowhead: arrow | none`,
93
+ * `emphasis: default | emphasis`) plus DE-1 `presentation.anatomy` and `diagram-presentation@2`
94
+ * (`align`). `@1/@2/@3` bytes and digests remain untouched; additional arrowheads are reserved for N2.
95
+ */
96
+ const PRIVATE_V4_SCHEMA = (() => {
97
+ const schema = deepCloneValue(PRIVATE_V3_SCHEMA);
98
+ schema["$id"] = "engram:diagram-view-schema/4";
99
+ const rootProps = schema["properties"];
100
+ const presentationProps = rootProps["presentation"]["properties"];
101
+ presentationProps["anatomy"] = { enum: ["v1", "v2"] };
102
+ presentationProps["entityAnatomy"] = { type: "object", additionalProperties: { enum: ["v1", "v2"] } };
103
+ const diagramProps = presentationProps["diagram"]["properties"];
104
+ const pinProps = diagramProps["contractPin"]["properties"];
105
+ pinProps["version"] = { enum: ["1", "2"] };
106
+ const entityProps = diagramProps["entities"]["additionalProperties"]["properties"];
107
+ entityProps["align"] = { enum: ["left", "center"] };
108
+ const relOccProps = rootProps["relationOccurrences"]["additionalProperties"]["properties"];
109
+ relOccProps["strokeStyle"] = { enum: ["solid", "dashed", "dotted"] };
110
+ relOccProps["arrowhead"] = { enum: ["arrow", "none"] };
111
+ relOccProps["emphasis"] = { enum: ["default", "emphasis"] };
112
+ const summaryProps = rootProps["summaryLabels"]["additionalProperties"]["properties"];
113
+ summaryProps["strokeStyle"] = { enum: ["solid", "dashed", "dotted"] };
114
+ return schema;
115
+ })();
116
+ deepFreezeValue(PRIVATE_V4_SCHEMA);
117
+ export const DIAGRAM_VIEW_SCHEMA_V4 = frozenCopy(PRIVATE_V4_SCHEMA);
118
+ export const DIAGRAM_VIEW_SCHEMA_V4_DIGEST = sha256Hex(canonicalBytes(PRIVATE_V4_SCHEMA));
119
+ export const DIAGRAM_VIEW_SCHEMA_V4_PIN = deepFreezeValue({
120
+ id: DIAGRAM_VIEW_SCHEMA_ID, version: "4", contentDigest: DIAGRAM_VIEW_SCHEMA_V4_DIGEST,
121
+ });
90
122
  const ALLOWED_PIN_KEYS = new Set(["id", "version", "contentDigest"]);
91
123
  /**
92
124
  * Exact-key shape gate, mirroring `isWellFormedPin` in
@@ -146,9 +178,15 @@ export function resolveViewSchema(pin) {
146
178
  return { ok: false, refusal: { code: "pin-malformed" } };
147
179
  if (id !== DIAGRAM_VIEW_SCHEMA_ID)
148
180
  return { ok: false, refusal: { code: "unknown-schema-id" } };
149
- if (version !== "1" && version !== "2" && version !== "3")
181
+ if (version !== "1" && version !== "2" && version !== "3" && version !== "4")
150
182
  return { ok: false, refusal: { code: "unknown-schema-version" } };
151
- const expected = version === "1" ? DIAGRAM_VIEW_SCHEMA_V1_DIGEST : version === "2" ? DIAGRAM_VIEW_SCHEMA_V2_DIGEST : DIAGRAM_VIEW_SCHEMA_V3_DIGEST;
183
+ const expected = version === "1"
184
+ ? DIAGRAM_VIEW_SCHEMA_V1_DIGEST
185
+ : version === "2"
186
+ ? DIAGRAM_VIEW_SCHEMA_V2_DIGEST
187
+ : version === "3"
188
+ ? DIAGRAM_VIEW_SCHEMA_V3_DIGEST
189
+ : DIAGRAM_VIEW_SCHEMA_V4_DIGEST;
152
190
  if (contentDigest !== expected)
153
191
  return { ok: false, refusal: { code: "schema-digest-mismatch" } };
154
192
  if (version === "1") {
@@ -158,6 +196,8 @@ export function resolveViewSchema(pin) {
158
196
  }
159
197
  if (version === "3")
160
198
  return { ok: true, version: "3", pin: frozenCopy(DIAGRAM_VIEW_SCHEMA_V3_PIN), schema: DIAGRAM_VIEW_SCHEMA_V3 };
199
+ if (version === "4")
200
+ return { ok: true, version: "4", pin: frozenCopy(DIAGRAM_VIEW_SCHEMA_V4_PIN), schema: DIAGRAM_VIEW_SCHEMA_V4 };
161
201
  if (DIAGRAM_VIEW_SCHEMA_V2 === undefined)
162
202
  return { ok: false, refusal: { code: "schema-bytes-unavailable" } };
163
203
  return { ok: true, version: "2", pin: frozenCopy(DIAGRAM_VIEW_SCHEMA_V2_PIN), schema: DIAGRAM_VIEW_SCHEMA_V2 };
package/dist/view.d.ts CHANGED
@@ -17,7 +17,8 @@
17
17
  * occurrence id is unique across the three (checked as `duplicate-id`).
18
18
  */
19
19
  import type { DocumentRef, EntityRef, OccurrenceRef, PortRef, RelationRef, ViewRef } from "./refs.js";
20
- import type { DiagramPresentation, StrokeStyle } from "./presentation.js";
20
+ import type { ArrowheadKind, LinkEmphasis, StrokeStyle } from "./connector-registry.js";
21
+ import type { DiagramPresentation } from "./presentation.js";
21
22
  export interface Point {
22
23
  readonly x: number;
23
24
  readonly y: number;
@@ -76,10 +77,20 @@ export interface RelationOccurrence {
76
77
  /** Persisted route hints. An empty/absent list means "the renderer routes it". */
77
78
  readonly waypoints?: readonly Point[];
78
79
  /**
79
- * The only stroke carrier (M3 §3.2.2/§3.5), default solid. Absent is distinct
80
- * from explicit solid and is preserved byte-for-byte.
80
+ * Dash-pattern registry word (`solid | dashed | dotted`; `dashed` means "proposed").
81
+ * Absent is distinct from explicit solid and is preserved byte-for-byte.
81
82
  */
82
83
  readonly strokeStyle?: StrokeStyle;
84
+ /**
85
+ * Arrowhead registry word (`arrow | none`, DE-2; further heads reserved for N2).
86
+ * Absent means default arrow and is preserved byte-for-byte.
87
+ */
88
+ readonly arrowhead?: ArrowheadKind;
89
+ /**
90
+ * Link emphasis word (`default | emphasis`, DE-2): distinct colour + width,
91
+ * never a dash style. Absent is preserved byte-for-byte.
92
+ */
93
+ readonly emphasis?: LinkEmphasis;
83
94
  }
84
95
  export type PortSide = "north" | "east" | "south" | "west";
85
96
  /**
@@ -130,8 +141,8 @@ export interface SummaryDefinition {
130
141
  readonly label: string;
131
142
  /** Sorted, distinct, non-empty semantic relation ids of the selected set. */
132
143
  readonly relationIds: readonly RelationRef[];
133
- /** Absent selects solid only. Solid and dashed never aggregate together. */
134
- readonly strokeStyle?: "solid" | "dashed";
144
+ /** Absent selects solid only. Distinct dash styles never aggregate together. */
145
+ readonly strokeStyle?: StrokeStyle;
135
146
  /**
136
147
  * Complete selected candidate occurrence set for the scope/style. Absent
137
148
  * means the scope/style must select at most one occurrence per relation
@@ -184,8 +195,10 @@ export interface PresentationState {
184
195
  };
185
196
  /** A theme id the host resolves. No colour, no token value is stored here. */
186
197
  readonly theme?: string;
187
- /** Pinned card/zone anatomy (`diagram-anatomy/v1 | v2`). New views default to `"v2"`. */
198
+ /** Pinned card/zone anatomy (`diagram-anatomy/v1 | v2`). Absent means legacy `"v1"`; `"v2"` is opt-in. */
188
199
  readonly anatomy?: DiagramAnatomyVersion;
200
+ /** Per-occurrence anatomy overrides for mixed full-size and compact scenes. */
201
+ readonly entityAnatomy?: Readonly<Record<string, DiagramAnatomyVersion>>;
189
202
  /** Typed presentation fragment (M3 §3.2.2). Absent means no presentation contract. */
190
203
  readonly diagram?: DiagramPresentation;
191
204
  }
package/dist/view.js CHANGED
@@ -29,7 +29,7 @@ export const VIEW_DOCUMENT_FIELDS = [
29
29
  "summaryLabels",
30
30
  "viewId",
31
31
  ];
32
- export const DEFAULT_PRESENTATION = { camera: { x: 0, y: 0, zoom: 1 }, anatomy: "v2" };
32
+ export const DEFAULT_PRESENTATION = { camera: { x: 0, y: 0, zoom: 1 } };
33
33
  export function createView(input) {
34
34
  return {
35
35
  viewId: input.viewId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentropic/diagram-core",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Typed semantic core for diagrams: versioned documents and profiles, views with occurrences, transactional commands with logical inverses. No runtime dependency, no DOM, no framework.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,6 +25,8 @@
25
25
  },
26
26
  "./schemas/diagram-view-schema-3.json": "./schemas/diagram-view-schema-3.json",
27
27
  "./schemas/diagram-view-schema-3.sha256": "./schemas/diagram-view-schema-3.sha256",
28
+ "./schemas/diagram-view-schema-4.json": "./schemas/diagram-view-schema-4.json",
29
+ "./schemas/diagram-view-schema-4.sha256": "./schemas/diagram-view-schema-4.sha256",
28
30
  "./schemas/ds-layout-hints-1.json": "./schemas/ds-layout-hints-1.json",
29
31
  "./schemas/ds-layout-hints-1.sha256": "./schemas/ds-layout-hints-1.sha256"
30
32
  },
@@ -0,0 +1 @@
1
+ {"$id":"engram:diagram-view-schema/4","$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":false,"properties":{"entityOccurrences":{"additionalProperties":{"additionalProperties":false,"properties":{"entity":{"type":"string"},"geometry":{"additionalProperties":false,"properties":{"height":{"type":"number"},"width":{"type":"number"},"x":{"type":"number"},"y":{"type":"number"}},"required":["x","y","width","height"],"type":"object"},"group":{"type":"string"},"id":{"type":"string"},"z":{"type":"number"}},"required":["id","entity","geometry"],"type":"object"},"type":"object"},"filters":{"items":{"anyOf":[{"additionalProperties":false,"properties":{"id":{"type":"string"},"kind":{"const":"entity-type"},"mode":{"enum":["include","exclude"]},"types":{"items":{"type":"string"},"type":"array"}},"required":["id","kind","types","mode"],"type":"object"},{"additionalProperties":false,"properties":{"id":{"type":"string"},"kind":{"const":"relation-type"},"mode":{"enum":["include","exclude"]},"types":{"items":{"type":"string"},"type":"array"}},"required":["id","kind","types","mode"],"type":"object"},{"additionalProperties":false,"properties":{"attribute":{"type":"string"},"id":{"type":"string"},"kind":{"const":"attribute-equals"},"mode":{"enum":["include","exclude"]},"value":{"type":"string"}},"required":["id","kind","attribute","value","mode"],"type":"object"}]},"type":"array"},"groups":{"additionalProperties":{"additionalProperties":false,"properties":{"collapsed":{"type":"boolean"},"id":{"type":"string"},"label":{"type":"string"},"occurrence":{"type":"string"}},"required":["id"],"type":"object"},"type":"object"},"portOccurrences":{"additionalProperties":{"additionalProperties":false,"properties":{"anchor":{"maximum":1,"minimum":0,"type":"number"},"id":{"type":"string"},"order":{"type":"number"},"ownerOccurrence":{"type":"string"},"port":{"type":"string"},"side":{"enum":["north","east","south","west"]}},"required":["id","port","ownerOccurrence","side","order","anchor"],"type":"object"},"type":"object"},"presentation":{"additionalProperties":false,"properties":{"anatomy":{"enum":["v1","v2"]},"camera":{"additionalProperties":false,"properties":{"x":{"type":"number"},"y":{"type":"number"},"zoom":{"type":"number"}},"required":["x","y","zoom"],"type":"object"},"diagram":{"additionalProperties":false,"properties":{"categoryTokens":{"items":{"additionalProperties":false,"properties":{"category":{"maxLength":40,"minLength":1,"pattern":"^[a-z][a-z0-9-]*$","type":"string"},"legendRef":{"minLength":1,"type":"string"},"token":{"maxLength":80,"minLength":1,"pattern":"^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)*$","type":"string"}},"required":["legendRef","category","token"],"type":"object"},"type":"array"},"contractPin":{"additionalProperties":false,"properties":{"contentDigest":{"pattern":"^[0-9a-f]{64}$","type":"string"},"id":{"const":"diagram-presentation"},"version":{"enum":["1","2"]}},"required":["id","version","contentDigest"],"type":"object"},"entities":{"additionalProperties":{"additionalProperties":false,"allOf":[{"if":{"properties":{"form":{"const":"legend-key"}},"required":["form"]},"then":{"properties":{"text":{"properties":{"title":{"maxLength":120,"type":"string"}},"type":"object"}}}}],"properties":{"align":{"enum":["left","center"]},"categoryRef":{"minLength":1,"type":"string"},"form":{"enum":["card","container","legend","legend-key"]},"icon":{"maxLength":40,"minLength":1,"pattern":"^[a-z][a-z0-9-]*$","type":"string"},"text":{"additionalProperties":false,"properties":{"body":{"maxLength":400,"type":"string"},"detail":{"maxLength":400,"type":"string"},"footer":{"maxLength":120,"type":"string"},"kicker":{"maxLength":80,"type":"string"},"subtitle":{"maxLength":600,"type":"string"},"title":{"maxLength":200,"type":"string"}},"type":"object"}},"required":["form","text"],"type":"object"},"type":"object"},"legends":{"additionalProperties":{"additionalProperties":false,"properties":{"order":{"items":{"minLength":1,"type":"string"},"type":"array","uniqueItems":true}},"required":["order"],"type":"object"},"type":"object"}},"required":["contractPin","entities","legends","categoryTokens"],"type":"object"},"entityAnatomy":{"additionalProperties":{"enum":["v1","v2"]},"type":"object"},"grid":{"additionalProperties":false,"properties":{"size":{"type":"number"},"snap":{"type":"boolean"}},"required":["size","snap"],"type":"object"},"theme":{"type":"string"}},"required":["camera"],"type":"object"},"relationOccurrences":{"additionalProperties":{"additionalProperties":false,"properties":{"arrowhead":{"enum":["arrow","none"]},"emphasis":{"enum":["default","emphasis"]},"endpoints":{"items":{"additionalProperties":false,"dependentRequired":{"chainProvenance":["semanticTarget"],"sourceOccurrence":["semanticTarget"]},"dependentSchemas":{"semanticTarget":{"oneOf":[{"properties":{"chainProvenance":false,"sourceOccurrence":true},"required":["sourceOccurrence"]},{"properties":{"chainProvenance":true,"sourceOccurrence":false},"required":["chainProvenance"]}]}},"properties":{"chainProvenance":{"additionalProperties":false,"properties":{"hops":{"items":{"type":"string"},"type":"array"},"members":{"items":{"type":"string"},"type":"array"},"predicateId":{"minLength":1,"type":"string"}},"required":["predicateId","hops"],"type":"object"},"occurrence":{"type":"string"},"role":{"type":"string"},"semanticTarget":{"type":"string"},"sourceOccurrence":{"type":"string"}},"required":["role","occurrence"],"type":"object"},"type":"array"},"id":{"type":"string"},"relation":{"type":"string"},"strokeStyle":{"enum":["solid","dashed","dotted"]},"waypoints":{"items":{"additionalProperties":false,"properties":{"x":{"type":"number"},"y":{"type":"number"}},"required":["x","y"],"type":"object"},"type":"array"}},"required":["id","relation","endpoints"],"type":"object"},"type":"object"},"revision":{"minimum":0,"type":"integer"},"semanticDocumentId":{"type":"string"},"summaryLabels":{"additionalProperties":{"additionalProperties":false,"properties":{"id":{"type":"string"},"label":{"type":"string"},"relationIds":{"items":{"type":"string"},"minItems":1,"type":"array"},"relationOccurrences":{"items":{"type":"string"},"type":"array"},"sourceOccurrence":{"type":"string"},"strokeStyle":{"enum":["solid","dashed","dotted"]},"targetOccurrence":{"type":"string"}},"required":["id","sourceOccurrence","targetOccurrence","label","relationIds"],"type":"object"},"type":"object"},"viewId":{"type":"string"}},"required":["viewId","semanticDocumentId","revision","entityOccurrences","relationOccurrences","portOccurrences","groups","filters","presentation"],"type":"object"}
@@ -0,0 +1 @@
1
+ fca61a87490d5ba7ed0f10c5144d6871e0087a68f2f19b1025c18dacfcdb8916