@formicoidea/labre-ddd-shared 0.34.2 → 0.35.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.
@@ -1,3 +1,4 @@
1
+ import { TextFitMode } from '@formicoidea/labre-core/model';
1
2
  import type { BlockStdScope } from '@formicoidea/labre-core/std';
2
3
  import { type GfxController } from '@formicoidea/labre-core/std/gfx';
3
4
  /**
@@ -17,6 +18,47 @@ type Surface = NonNullable<GfxController['surface']>;
17
18
  export declare function placeDddElement(std: BlockStdScope, build: (surface: Surface, cx: number, cy: number) => string): void;
18
19
  /** Group several element ids; returns the group id (or the first id on failure). */
19
20
  export declare function groupIds(std: BlockStdScope, ids: string[]): string;
21
+ export interface ShapeOpts {
22
+ shapeType?: 'rect' | 'ellipse' | 'diamond';
23
+ fill: string;
24
+ /**
25
+ * Semantic role (`<framework>:<role>`) stamped on the shape, so a validation
26
+ * rule can recognise it. `undefined` writes NOTHING — no `role` key is
27
+ * persisted and the artefact stays a neutral drawing, which is what every
28
+ * caller that does not pass one keeps getting and what every DDD artefact
29
+ * created before this parameter existed already is.
30
+ */
31
+ role?: string;
32
+ stroke?: string;
33
+ strokeWidth?: number;
34
+ radius?: number;
35
+ /**
36
+ * Shape-owned centred label. The text belongs to the shape itself (edited
37
+ * by double-click, moves/resizes with it) with the given text-fit mode —
38
+ * `contained` mimics a physical post-it.
39
+ */
40
+ label?: {
41
+ text: string;
42
+ color: string;
43
+ fontFamily: string;
44
+ fontSize: number;
45
+ fit: TextFitMode;
46
+ };
47
+ }
48
+ /**
49
+ * The props a DDD shape is CREATED with, as a record — the write of
50
+ * {@link addShape}, minus the write.
51
+ *
52
+ * Split out for the Core Domain morph, and for the reason C4's `presets.ts`
53
+ * gives: a kind's appearance is written by the preset of the kind it was created
54
+ * as and nothing else ever rewrites it, so a morph that restated the table would
55
+ * agree with the palette the day it was written and drift on the first restyle.
56
+ * Derived, they cannot — a morphed dot and one freshly placed are the same
57
+ * element.
58
+ */
59
+ export declare function dddShapeProps(x: number, y: number, w: number, h: number, opts: ShapeOpts): Record<string, unknown> & {
60
+ type: string;
61
+ };
20
62
  /**
21
63
  * A post-it: faux-shadow rect + coloured face whose label is the face's OWN
22
64
  * shape text in `contained` fit mode — like a real post-it, the box size is
@@ -43,6 +85,14 @@ export declare function addSticky(surface: Surface, std: BlockStdScope, cx: numb
43
85
  * long context name may spill out rather than deform the map).
44
86
  */
45
87
  export declare function addBubble(surface: Surface, cx: number, cy: number, label: string, role?: string): string;
88
+ /**
89
+ * What a Core Domain DOT is, as shape options — read by the creation site below
90
+ * and by the morph, so the two can never disagree about what a platform
91
+ * sub-domain looks like. See {@link dddShapeProps}.
92
+ */
93
+ export declare function dotShapeOpts(fill: string, role?: string): ShapeOpts;
94
+ /** What a Team Topologies MARKER square is, the same way. */
95
+ export declare function markerShapeOpts(fill: string, role?: string): ShapeOpts;
46
96
  /** A Core Domain dot (sub-domain / bounded context); optional label to its right. */
47
97
  export declare function addDot(surface: Surface, std: BlockStdScope, cx: number, cy: number, fill: string, label?: string,
48
98
  /** Stamped on the ELLIPSE, never on the group: the dot is the artefact. */
@@ -29,9 +29,20 @@ export function groupIds(std, ids) {
29
29
  const [, result] = std.command.exec(createGroupCommand, { elements: ids });
30
30
  return result.groupId || ids[0];
31
31
  }
32
- function addShape(surface, x, y, w, h, opts) {
32
+ /**
33
+ * The props a DDD shape is CREATED with, as a record — the write of
34
+ * {@link addShape}, minus the write.
35
+ *
36
+ * Split out for the Core Domain morph, and for the reason C4's `presets.ts`
37
+ * gives: a kind's appearance is written by the preset of the kind it was created
38
+ * as and nothing else ever rewrites it, so a morph that restated the table would
39
+ * agree with the palette the day it was written and drift on the first restyle.
40
+ * Derived, they cannot — a morphed dot and one freshly placed are the same
41
+ * element.
42
+ */
43
+ export function dddShapeProps(x, y, w, h, opts) {
33
44
  const { shapeType = 'rect', fill, stroke = NO_STROKE, strokeWidth = 0, radius = 0, label, role, } = opts;
34
- return surface.addElement({
45
+ return {
35
46
  type: 'shape',
36
47
  // `undefined` writes nothing: a neutral artefact keeps no `role` key.
37
48
  role,
@@ -54,7 +65,10 @@ function addShape(surface, x, y, w, h, opts) {
54
65
  textFitMode: label.fit,
55
66
  }
56
67
  : {}),
57
- });
68
+ };
69
+ }
70
+ function addShape(surface, x, y, w, h, opts) {
71
+ return surface.addElement(dddShapeProps(x, y, w, h, opts));
58
72
  }
59
73
  function addText(surface, x, y, w, text, color, fontFamily, fontSize, textAlign = 'center', bold = false) {
60
74
  return surface.addElement({
@@ -121,18 +135,38 @@ export function addBubble(surface, cx, cy, label, role) {
121
135
  },
122
136
  });
123
137
  }
138
+ /** The ink every Core Domain artefact is outlined with. */
139
+ const ARTEFACT_STROKE = '#1f2328';
140
+ /**
141
+ * What a Core Domain DOT is, as shape options — read by the creation site below
142
+ * and by the morph, so the two can never disagree about what a platform
143
+ * sub-domain looks like. See {@link dddShapeProps}.
144
+ */
145
+ export function dotShapeOpts(fill, role) {
146
+ return {
147
+ shapeType: 'ellipse',
148
+ fill,
149
+ stroke: ARTEFACT_STROKE,
150
+ strokeWidth: 1.5,
151
+ role,
152
+ };
153
+ }
154
+ /** What a Team Topologies MARKER square is, the same way. */
155
+ export function markerShapeOpts(fill, role) {
156
+ return {
157
+ fill,
158
+ stroke: ARTEFACT_STROKE,
159
+ strokeWidth: 1.5,
160
+ radius: 4,
161
+ role,
162
+ };
163
+ }
124
164
  /** A Core Domain dot (sub-domain / bounded context); optional label to its right. */
125
165
  export function addDot(surface, std, cx, cy, fill, label,
126
166
  /** Stamped on the ELLIPSE, never on the group: the dot is the artefact. */
127
167
  role) {
128
168
  const d = DOT_SIZE;
129
- const dot = addShape(surface, cx - d / 2, cy - d / 2, d, d, {
130
- shapeType: 'ellipse',
131
- fill,
132
- stroke: '#1f2328',
133
- strokeWidth: 1.5,
134
- role,
135
- });
169
+ const dot = addShape(surface, cx - d / 2, cy - d / 2, d, d, dotShapeOpts(fill, role));
136
170
  if (!label)
137
171
  return dot;
138
172
  const lbl = addText(surface, cx + d / 2 + 6, cy - LABEL_FONT_SIZE / 2, 170, label, LABEL_COLOR, LABEL_FONT, LABEL_FONT_SIZE, 'left');
@@ -169,13 +203,7 @@ export function addConnector(surface, x1, y1, x2, y2, opts = {}) {
169
203
  export function addMarker(surface, std, cx, cy, opts) {
170
204
  const { fill, letter, label, role } = opts;
171
205
  const s = MARKER_SIZE;
172
- const box = addShape(surface, cx - s / 2, cy - s / 2, s, s, {
173
- fill,
174
- stroke: '#1f2328',
175
- strokeWidth: 1.5,
176
- radius: 4,
177
- role,
178
- });
206
+ const box = addShape(surface, cx - s / 2, cy - s / 2, s, s, markerShapeOpts(fill, role));
179
207
  const glyph = addText(surface, cx - s / 2, cy - 9, s, letter, '#1f2328', LABEL_FONT, 15);
180
208
  const ids = [box, glyph];
181
209
  if (label) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formicoidea/labre-ddd-shared",
3
3
  "description": "Labre ddd-shared — shared building blocks for @formicoidea/labre-core frameworks.",
4
- "version": "0.34.2",
4
+ "version": "0.35.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "author": "lajola",
@@ -19,7 +19,7 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@formicoidea/labre-core": "0.34.2",
22
+ "@formicoidea/labre-core": "0.35.0",
23
23
  "lit": "^3.2.0"
24
24
  }
25
25
  }