@formicoidea/labre-framework-edgy 0.23.1 → 0.23.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 (48) hide show
  1. package/package.json +6 -15
  2. package/{dist/consts.js → src/consts.ts} +50 -46
  3. package/{dist/descriptor.js → src/descriptor.ts} +1 -1
  4. package/src/effects.ts +14 -0
  5. package/src/element-renderer.ts +208 -0
  6. package/src/element-view.ts +145 -0
  7. package/src/index.ts +1 -0
  8. package/src/label-layout.ts +105 -0
  9. package/{dist/node/consts.js → src/node/consts.ts} +56 -49
  10. package/src/node/node-renderer.ts +64 -0
  11. package/{dist/node/node-view.js → src/node/node-view.ts} +33 -27
  12. package/src/templates/index.ts +254 -0
  13. package/src/toolbar/config.ts +96 -0
  14. package/src/toolbar/edgy-menu.ts +242 -0
  15. package/{dist/toolbar/edgy-senior-button.js → src/toolbar/edgy-senior-button.ts} +102 -97
  16. package/{dist/toolbar/icons.js → src/toolbar/icons.ts} +25 -20
  17. package/src/toolbar/node-config.ts +202 -0
  18. package/{dist/toolbar/senior-tool.js → src/toolbar/senior-tool.ts} +11 -11
  19. package/src/view.ts +39 -0
  20. package/dist/consts.d.ts +0 -47
  21. package/dist/descriptor.d.ts +0 -7
  22. package/dist/effects.d.ts +0 -10
  23. package/dist/effects.js +0 -7
  24. package/dist/element-renderer.d.ts +0 -17
  25. package/dist/element-renderer.js +0 -177
  26. package/dist/element-view.d.ts +0 -19
  27. package/dist/element-view.js +0 -123
  28. package/dist/index.d.ts +0 -2
  29. package/dist/index.js +0 -2
  30. package/dist/label-layout.d.ts +0 -46
  31. package/dist/label-layout.js +0 -69
  32. package/dist/node/consts.d.ts +0 -34
  33. package/dist/node/node-renderer.d.ts +0 -14
  34. package/dist/node/node-renderer.js +0 -40
  35. package/dist/node/node-view.d.ts +0 -16
  36. package/dist/templates/index.d.ts +0 -3
  37. package/dist/templates/index.js +0 -210
  38. package/dist/toolbar/config.d.ts +0 -20
  39. package/dist/toolbar/config.js +0 -71
  40. package/dist/toolbar/edgy-menu.d.ts +0 -31
  41. package/dist/toolbar/edgy-menu.js +0 -195
  42. package/dist/toolbar/edgy-senior-button.d.ts +0 -16
  43. package/dist/toolbar/icons.d.ts +0 -13
  44. package/dist/toolbar/node-config.d.ts +0 -2
  45. package/dist/toolbar/node-config.js +0 -162
  46. package/dist/toolbar/senior-tool.d.ts +0 -2
  47. package/dist/view.d.ts +0 -7
  48. package/dist/view.js +0 -36
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formicoidea/labre-framework-edgy",
3
3
  "description": "Labre edgy framework for @formicoidea/labre-core.",
4
- "version": "0.23.1",
4
+ "version": "0.23.2",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "author": "lajola",
@@ -10,24 +10,15 @@
10
10
  ],
11
11
  "license": "MPL-2.0",
12
12
  "exports": {
13
- ".": {
14
- "types": "./dist/index.d.ts",
15
- "import": "./dist/index.js"
16
- },
17
- "./view": {
18
- "types": "./dist/view.d.ts",
19
- "import": "./dist/view.js"
20
- },
21
- "./descriptor": {
22
- "types": "./dist/descriptor.d.ts",
23
- "import": "./dist/descriptor.js"
24
- }
13
+ ".": "./src/index.ts",
14
+ "./view": "./src/view.ts",
15
+ "./descriptor": "./src/descriptor.ts"
25
16
  },
26
17
  "files": [
27
- "dist"
18
+ "src"
28
19
  ],
29
20
  "dependencies": {
30
- "@formicoidea/labre-core": "0.23.1",
21
+ "@formicoidea/labre-core": "0.23.2",
31
22
  "lit": "^3.2.0"
32
23
  }
33
24
  }
@@ -1,46 +1,50 @@
1
- /**
2
- * Visual constants for the EDGY "Enterprise Design Facets" diagram.
3
- *
4
- * The whole diagram is authored in a FIXED reference coordinate space
5
- * (`REF_W × REF_H`, matching the validated mockup) and the renderer scales it
6
- * uniformly to the element bounds — so the three circles always stay circular
7
- * and the pictos/labels keep their relative proportions at any size.
8
- */
9
- /** Reference design size (the validated mockup canvas). */
10
- export const REF_W = 680;
11
- export const REF_H = 400;
12
- /** Circle geometry in reference coords. */
13
- export const VENN = {
14
- cx: REF_W / 2,
15
- cy: 176,
16
- /** Circle radius. */
17
- R: 95,
18
- /** Distance of each circle centre from the diagram centre. */
19
- r0: 56,
20
- };
21
- /** Saturated facet + intersection colours (faithful to the official icons). */
22
- export const COLORS = {
23
- identity: '#00ea4e',
24
- architecture: '#034cee',
25
- experience: '#ff0056',
26
- organisation: '#00caf4',
27
- brand: '#ffa500',
28
- product: '#cf00ff',
29
- center: '#ffffff',
30
- separator: '#ffffff',
31
- picto: '#ffffff',
32
- };
33
- /** Fixed picto line width + label font. */
34
- export const PICTO_STROKE = 2.4;
35
- export const LABEL_FONT_SIZE = 15;
36
- export const FONT_FAMILY = 'Inter, sans-serif';
37
- /**
38
- * Uniform fit of the reference design into an element of size `w × h`: the
39
- * scale factor plus the centering offsets (letterboxed). Shared by the renderer
40
- * (to draw) and the view (to map clicks back into reference coords).
41
- */
42
- export function refScale(w, h) {
43
- const s = Math.min(w / REF_W, h / REF_H);
44
- return { s, ox: (w - REF_W * s) / 2, oy: (h - REF_H * s) / 2 };
45
- }
46
- //# sourceMappingURL=consts.js.map
1
+ /**
2
+ * Visual constants for the EDGY "Enterprise Design Facets" diagram.
3
+ *
4
+ * The whole diagram is authored in a FIXED reference coordinate space
5
+ * (`REF_W × REF_H`, matching the validated mockup) and the renderer scales it
6
+ * uniformly to the element bounds — so the three circles always stay circular
7
+ * and the pictos/labels keep their relative proportions at any size.
8
+ */
9
+
10
+ /** Reference design size (the validated mockup canvas). */
11
+ export const REF_W = 680;
12
+ export const REF_H = 400;
13
+
14
+ /** Circle geometry in reference coords. */
15
+ export const VENN = {
16
+ cx: REF_W / 2,
17
+ cy: 176,
18
+ /** Circle radius. */
19
+ R: 95,
20
+ /** Distance of each circle centre from the diagram centre. */
21
+ r0: 56,
22
+ } as const;
23
+
24
+ /** Saturated facet + intersection colours (faithful to the official icons). */
25
+ export const COLORS = {
26
+ identity: '#00ea4e',
27
+ architecture: '#034cee',
28
+ experience: '#ff0056',
29
+ organisation: '#00caf4',
30
+ brand: '#ffa500',
31
+ product: '#cf00ff',
32
+ center: '#ffffff',
33
+ separator: '#ffffff',
34
+ picto: '#ffffff',
35
+ } as const;
36
+
37
+ /** Fixed picto line width + label font. */
38
+ export const PICTO_STROKE = 2.4;
39
+ export const LABEL_FONT_SIZE = 15;
40
+ export const FONT_FAMILY = 'Inter, sans-serif';
41
+
42
+ /**
43
+ * Uniform fit of the reference design into an element of size `w × h`: the
44
+ * scale factor plus the centering offsets (letterboxed). Shared by the renderer
45
+ * (to draw) and the view (to map clicks back into reference coords).
46
+ */
47
+ export function refScale(w: number, h: number) {
48
+ const s = Math.min(w / REF_W, h / REF_H);
49
+ return { s, ox: (w - REF_W * s) / 2, oy: (h - REF_H * s) / 2 };
50
+ }
@@ -5,4 +5,4 @@ export const edgyFramework = {
5
5
  flag: 'edgy',
6
6
  telemetry: 'edgy',
7
7
  viewExtension: EdgyViewExtension,
8
- };
8
+ } as const;
package/src/effects.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { EdgelessEdgyMenu } from './toolbar/edgy-menu';
2
+ import { EdgelessEdgySeniorButton } from './toolbar/edgy-senior-button';
3
+
4
+ export function effects() {
5
+ customElements.define('edgeless-edgy-menu', EdgelessEdgyMenu);
6
+ customElements.define('edgeless-edgy-senior-button', EdgelessEdgySeniorButton);
7
+ }
8
+
9
+ declare global {
10
+ interface HTMLElementTagNameMap {
11
+ 'edgeless-edgy-menu': EdgelessEdgyMenu;
12
+ 'edgeless-edgy-senior-button': EdgelessEdgySeniorButton;
13
+ }
14
+ }
@@ -0,0 +1,208 @@
1
+ import {
2
+ type ElementRenderer,
3
+ ElementRendererExtension,
4
+ } from '@formicoidea/labre-core/blocks/surface';
5
+ import type { EdgyFacetsElementModel } from '@formicoidea/labre-core/model';
6
+
7
+ import {
8
+ COLORS,
9
+ FONT_FAMILY,
10
+ LABEL_FONT_SIZE,
11
+ PICTO_STROKE,
12
+ REF_H,
13
+ REF_W,
14
+ refScale,
15
+ VENN,
16
+ } from './consts';
17
+ import { CIRCLE_A, CIRCLE_B, CIRCLE_C, facetLabelAnchors } from './label-layout';
18
+
19
+ type Pt = { x: number; y: number };
20
+
21
+ /**
22
+ * Canvas renderer for the EDGY Enterprise Design Facets diagram — reproduces the
23
+ * validated mockup: three overlapping circles (Identity / Architecture /
24
+ * Experience), the three pairwise intersection regions (Organisation / Brand /
25
+ * Product) painted by clip-intersection, the white centre, the six white
26
+ * pictograms and the three facet labels placed outside the circles.
27
+ *
28
+ * The whole diagram is drawn in the fixed reference space and scaled uniformly
29
+ * to the element bounds so the circles never distort.
30
+ */
31
+ export const edgy: ElementRenderer<EdgyFacetsElementModel> = (
32
+ model,
33
+ ctx,
34
+ matrix
35
+ ) => {
36
+ const [, , w, h] = model.deserializedXYWH;
37
+ const cx = w / 2;
38
+ const cy = h / 2;
39
+ ctx.setTransform(
40
+ matrix.translateSelf(cx, cy).rotateSelf(model.rotate).translateSelf(-cx, -cy)
41
+ );
42
+
43
+ // Uniform fit of the reference design, centered (letterboxed).
44
+ const { s, ox, oy } = refScale(w, h);
45
+ ctx.translate(ox, oy);
46
+ ctx.scale(s, s);
47
+
48
+ const A = CIRCLE_A;
49
+ const B = CIRCLE_B;
50
+ const C = CIRCLE_C;
51
+ const R = VENN.R;
52
+
53
+ const disc = (c: Pt, color: string) => {
54
+ ctx.beginPath();
55
+ ctx.arc(c.x, c.y, R, 0, Math.PI * 2);
56
+ ctx.fillStyle = color;
57
+ ctx.fill();
58
+ };
59
+ // Paint the region common to every circle in `cs` (clip-intersection).
60
+ const inter = (cs: Pt[], color: string) => {
61
+ ctx.save();
62
+ for (const c of cs) {
63
+ ctx.beginPath();
64
+ ctx.arc(c.x, c.y, R, 0, Math.PI * 2);
65
+ ctx.clip();
66
+ }
67
+ ctx.fillStyle = color;
68
+ ctx.fillRect(0, 0, REF_W, REF_H);
69
+ ctx.restore();
70
+ };
71
+
72
+ // ── Facets + intersections ──────────────────────────────────────────
73
+ disc(A, COLORS.identity);
74
+ disc(B, COLORS.architecture);
75
+ disc(C, COLORS.experience);
76
+ inter([A, B], COLORS.organisation);
77
+ inter([A, C], COLORS.brand);
78
+ inter([B, C], COLORS.product);
79
+ inter([A, B, C], COLORS.center);
80
+
81
+ // White separating outlines.
82
+ ctx.strokeStyle = COLORS.separator;
83
+ ctx.lineWidth = 2.5;
84
+ for (const c of [A, B, C]) {
85
+ ctx.beginPath();
86
+ ctx.arc(c.x, c.y, R, 0, Math.PI * 2);
87
+ ctx.stroke();
88
+ }
89
+
90
+ // ── White pictos ────────────────────────────────────────────────────
91
+ const pictoSetup = () => {
92
+ ctx.strokeStyle = COLORS.picto;
93
+ ctx.fillStyle = COLORS.picto;
94
+ ctx.lineWidth = PICTO_STROKE;
95
+ ctx.lineJoin = 'round';
96
+ ctx.lineCap = 'round';
97
+ };
98
+ const lens = (x: number, y: number) => {
99
+ pictoSetup();
100
+ ctx.beginPath();
101
+ ctx.arc(x, y, 10, 0, Math.PI * 2);
102
+ ctx.stroke();
103
+ ctx.beginPath();
104
+ ctx.moveTo(x + 7, y + 7);
105
+ ctx.lineTo(x + 15, y + 15);
106
+ ctx.stroke();
107
+ };
108
+ const house = (x: number, y: number) => {
109
+ pictoSetup();
110
+ ctx.beginPath();
111
+ ctx.moveTo(x - 11, y + 9);
112
+ ctx.lineTo(x - 11, y - 2);
113
+ ctx.lineTo(x, y - 11);
114
+ ctx.lineTo(x + 11, y - 2);
115
+ ctx.lineTo(x + 11, y + 9);
116
+ ctx.closePath();
117
+ ctx.stroke();
118
+ };
119
+ const heart = (x: number, y: number) => {
120
+ pictoSetup();
121
+ ctx.beginPath();
122
+ ctx.moveTo(x, y + 11);
123
+ ctx.bezierCurveTo(x - 14, y - 1, x - 9, y - 12, x, y - 4);
124
+ ctx.bezierCurveTo(x + 9, y - 12, x + 14, y - 1, x, y + 11);
125
+ ctx.closePath();
126
+ ctx.stroke();
127
+ };
128
+ const network = (x: number, y: number) => {
129
+ pictoSetup();
130
+ ctx.beginPath();
131
+ ctx.moveTo(x, y - 9);
132
+ ctx.lineTo(x - 9, y + 7);
133
+ ctx.lineTo(x + 9, y + 7);
134
+ ctx.closePath();
135
+ ctx.stroke();
136
+ for (const [px, py] of [
137
+ [x, y - 9],
138
+ [x - 9, y + 7],
139
+ [x + 9, y + 7],
140
+ ]) {
141
+ ctx.beginPath();
142
+ ctx.arc(px, py, 2.6, 0, Math.PI * 2);
143
+ ctx.fill();
144
+ }
145
+ };
146
+ const sun = (x: number, y: number) => {
147
+ pictoSetup();
148
+ ctx.beginPath();
149
+ ctx.arc(x, y, 6, 0, Math.PI * 2);
150
+ ctx.stroke();
151
+ for (let i = 0; i < 8; i++) {
152
+ const a = (i * Math.PI) / 4;
153
+ ctx.beginPath();
154
+ ctx.moveTo(x + Math.cos(a) * 9, y + Math.sin(a) * 9);
155
+ ctx.lineTo(x + Math.cos(a) * 12, y + Math.sin(a) * 12);
156
+ ctx.stroke();
157
+ }
158
+ };
159
+ const cube = (x: number, y: number) => {
160
+ pictoSetup();
161
+ const p = [
162
+ [x, y - 11],
163
+ [x + 10, y - 5],
164
+ [x + 10, y + 6],
165
+ [x, y + 12],
166
+ [x - 10, y + 6],
167
+ [x - 10, y - 5],
168
+ ];
169
+ ctx.beginPath();
170
+ p.forEach(([qx, qy], i) => (i ? ctx.lineTo(qx, qy) : ctx.moveTo(qx, qy)));
171
+ ctx.closePath();
172
+ ctx.stroke();
173
+ ctx.beginPath();
174
+ ctx.moveTo(x - 10, y - 5);
175
+ ctx.lineTo(x, y + 1);
176
+ ctx.lineTo(x + 10, y - 5);
177
+ ctx.moveTo(x, y + 1);
178
+ ctx.lineTo(x, y + 12);
179
+ ctx.stroke();
180
+ };
181
+
182
+ // Single-facet zone pictos.
183
+ lens(A.x - 30, A.y - 22);
184
+ house(B.x + 30, B.y - 22);
185
+ heart(C.x, C.y + 36);
186
+ // Intersection pictos at the validated sweet spots.
187
+ network(VENN.cx, 114);
188
+ sun(VENN.cx - 58, 206);
189
+ cube(VENN.cx + 58, 206);
190
+
191
+ // ── Labels (outside the circles) ────────────────────────────────────
192
+ if (model.showLabels) {
193
+ ctx.font = `500 ${LABEL_FONT_SIZE}px ${FONT_FAMILY}`;
194
+ ctx.textBaseline = 'middle';
195
+ const colorByField: Record<string, string> = {
196
+ identityLabel: COLORS.identity,
197
+ architectureLabel: COLORS.architecture,
198
+ experienceLabel: COLORS.experience,
199
+ };
200
+ for (const { field, text, x, y, align } of facetLabelAnchors(model)) {
201
+ ctx.fillStyle = colorByField[field];
202
+ ctx.textAlign = align;
203
+ ctx.fillText(text, x, y);
204
+ }
205
+ }
206
+ };
207
+
208
+ export const EdgyFacetsRendererExtension = ElementRendererExtension('edgy', edgy);
@@ -0,0 +1,145 @@
1
+ import { EdgelessCRUDIdentifier } from '@formicoidea/labre-core/blocks/surface';
2
+ import type { EdgyFacetsElementModel } from '@formicoidea/labre-core/model';
3
+ import { rotatePoint } from '@formicoidea/labre-core/global/gfx';
4
+ import type { PointerEventState } from '@formicoidea/labre-core/std';
5
+ import {
6
+ GfxElementModelView,
7
+ GfxViewInteractionExtension,
8
+ } from '@formicoidea/labre-core/std/gfx';
9
+
10
+ import { refScale } from './consts';
11
+ import {
12
+ type EdgyLabelField,
13
+ getEdgyLabelHits,
14
+ hitTestEdgyLabel,
15
+ } from './label-layout';
16
+
17
+ export class EdgyView extends GfxElementModelView<EdgyFacetsElementModel> {
18
+ static override type: string = 'edgy';
19
+
20
+ /** The in-place `<input>` used to edit a label, or null when idle. */
21
+ private _labelEditor: HTMLInputElement | null = null;
22
+
23
+ override onCreated(): void {
24
+ super.onCreated();
25
+ this.on('dblclick', e => this._onDblClick(e));
26
+ }
27
+
28
+ override onDestroyed(): void {
29
+ this._closeLabelEditor();
30
+ super.onDestroyed();
31
+ }
32
+
33
+ /** Double-click on a label → edit its text in place. */
34
+ private _onDblClick(e: PointerEventState): void {
35
+ if (this.model.isLocked()) return;
36
+
37
+ const [mx, my] = this.gfx.viewport.toModelCoord(e.x, e.y);
38
+ const [bx, by, w, h] = this.model.deserializedXYWH;
39
+
40
+ // Convert the model-space point into element-local coordinates, undoing the
41
+ // element rotation around its center.
42
+ let lx = mx - bx;
43
+ let ly = my - by;
44
+ const rot = this.model.rotate ?? 0;
45
+ if (rot) {
46
+ const center: [number, number] = [bx + w / 2, by + h / 2];
47
+ const [ux, uy] = rotatePoint([mx, my], center, -rot);
48
+ lx = ux - bx;
49
+ ly = uy - by;
50
+ }
51
+
52
+ // Map element-local coords into the fixed reference space the labels live in.
53
+ const { s, ox, oy } = refScale(w, h);
54
+ const rx = (lx - ox) / s;
55
+ const ry = (ly - oy) / s;
56
+
57
+ const hit = hitTestEdgyLabel(getEdgyLabelHits(this.model), rx, ry);
58
+ if (!hit) return;
59
+
60
+ this._openLabelEditor(hit.field, e);
61
+ }
62
+
63
+ private _openLabelEditor(field: EdgyLabelField, e: PointerEventState): void {
64
+ this._closeLabelEditor();
65
+
66
+ const input = document.createElement('input');
67
+ input.value = String(this.model[field] ?? '');
68
+ Object.assign(input.style, {
69
+ position: 'fixed',
70
+ left: `${e.raw.clientX}px`,
71
+ top: `${e.raw.clientY}px`,
72
+ transform: 'translate(-50%, -50%)',
73
+ zIndex: '10000',
74
+ minWidth: '140px',
75
+ padding: '3px 8px',
76
+ font: '14px Inter, sans-serif',
77
+ color: 'var(--affine-text-primary-color, #1f2328)',
78
+ background: 'var(--affine-background-overlay-panel-color, #ffffff)',
79
+ border: '1px solid var(--affine-primary-color, #1e96eb)',
80
+ borderRadius: '6px',
81
+ boxShadow: 'var(--affine-shadow-2, 0 2px 8px rgba(0,0,0,0.18))',
82
+ outline: 'none',
83
+ });
84
+ document.body.append(input);
85
+ this._labelEditor = input;
86
+
87
+ // Mark the element as "editing" so the global edgeless key handlers
88
+ // (delete, escape, etc.) don't act on it while the user types.
89
+ this.gfx.selection.set({ elements: [this.model.id], editing: true });
90
+
91
+ input.focus();
92
+ input.select();
93
+
94
+ const commit = () => {
95
+ if (this._labelEditor !== input) return;
96
+ const value = input.value;
97
+ this._closeLabelEditor();
98
+ this.gfx.std.store.captureSync();
99
+ this.gfx.std
100
+ .get(EdgelessCRUDIdentifier)
101
+ .updateElement(this.model.id, { [field]: value });
102
+ };
103
+
104
+ input.addEventListener('keydown', ev => {
105
+ ev.stopPropagation();
106
+ if (ev.key === 'Enter') {
107
+ ev.preventDefault();
108
+ commit();
109
+ } else if (ev.key === 'Escape') {
110
+ ev.preventDefault();
111
+ this._closeLabelEditor();
112
+ }
113
+ });
114
+ input.addEventListener('blur', commit);
115
+ }
116
+
117
+ private _closeLabelEditor(): void {
118
+ if (!this._labelEditor) return;
119
+ const input = this._labelEditor;
120
+ this._labelEditor = null;
121
+ input.remove();
122
+ if (this.isConnected) {
123
+ this.gfx.selection.set({ elements: [this.model.id], editing: false });
124
+ }
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Resize gating: the resize handles are hidden unless `model.resizeEnabled` is
130
+ * true (toggled from the toolbar). Moving/selecting stays available throughout.
131
+ */
132
+ export const EdgyInteraction = GfxViewInteractionExtension<EdgyView>(
133
+ EdgyView.type,
134
+ {
135
+ handleResize({ model }) {
136
+ return {
137
+ beforeResize({ set }) {
138
+ if (!model.resizeEnabled) {
139
+ set({ allowedHandlers: [] });
140
+ }
141
+ },
142
+ };
143
+ },
144
+ }
145
+ );
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,105 @@
1
+ import type { EdgyFacetsElementModel } from '@formicoidea/labre-core/model';
2
+
3
+ import { LABEL_FONT_SIZE, VENN } from './consts';
4
+
5
+ /** The three circle centres in reference coords. */
6
+ export const CIRCLE_A = { x: VENN.cx - 0.866 * VENN.r0, y: VENN.cy - 0.5 * VENN.r0 }; // Identity
7
+ export const CIRCLE_B = { x: VENN.cx + 0.866 * VENN.r0, y: VENN.cy - 0.5 * VENN.r0 }; // Architecture
8
+ export const CIRCLE_C = { x: VENN.cx, y: VENN.cy + VENN.r0 }; // Experience
9
+
10
+ /** The editable label fields of the facets diagram. */
11
+ export type EdgyLabelField =
12
+ | 'identityLabel'
13
+ | 'architectureLabel'
14
+ | 'experienceLabel';
15
+
16
+ export interface EdgyLabelAnchor {
17
+ field: EdgyLabelField;
18
+ text: string;
19
+ x: number;
20
+ y: number;
21
+ align: 'start' | 'end' | 'center';
22
+ }
23
+
24
+ /**
25
+ * The three facet name anchors in reference coords, positioned fully outside
26
+ * their circle (validated mockup). Shared by the renderer (to draw them) and
27
+ * the label-layout hit testing (to edit them).
28
+ */
29
+ export function facetLabelAnchors(
30
+ model: EdgyFacetsElementModel
31
+ ): EdgyLabelAnchor[] {
32
+ return [
33
+ {
34
+ field: 'identityLabel',
35
+ text: model.identityLabel,
36
+ x: CIRCLE_A.x - VENN.R - 10,
37
+ y: CIRCLE_A.y - 28,
38
+ align: 'end',
39
+ },
40
+ {
41
+ field: 'architectureLabel',
42
+ text: model.architectureLabel,
43
+ x: CIRCLE_B.x + VENN.R + 10,
44
+ y: CIRCLE_B.y - 28,
45
+ align: 'start',
46
+ },
47
+ {
48
+ field: 'experienceLabel',
49
+ text: model.experienceLabel,
50
+ x: CIRCLE_C.x,
51
+ y: CIRCLE_C.y + VENN.R + 22,
52
+ align: 'center',
53
+ },
54
+ ];
55
+ }
56
+
57
+ /** A label's hit box in reference coords (axis-aligned, padded). */
58
+ export interface EdgyLabelHit {
59
+ field: EdgyLabelField;
60
+ minX: number;
61
+ minY: number;
62
+ maxX: number;
63
+ maxY: number;
64
+ }
65
+
66
+ const approxTextWidth = (text: string, fontSize: number) =>
67
+ Math.max(fontSize, text.length * fontSize * 0.6);
68
+
69
+ /**
70
+ * Clickable boxes of every facet label, in reference coords. Derived from the
71
+ * SAME anchors the renderer uses so they track the drawn text. Boxes are padded
72
+ * so double-clicking is forgiving. Hidden when `showLabels` is false.
73
+ */
74
+ export function getEdgyLabelHits(model: EdgyFacetsElementModel): EdgyLabelHit[] {
75
+ if (!model.showLabels) return [];
76
+
77
+ const pad = 6;
78
+ const fs = LABEL_FONT_SIZE;
79
+ return facetLabelAnchors(model).map(({ field, text, x, y, align }) => {
80
+ const tw = approxTextWidth(text, fs);
81
+ const minX = align === 'end' ? x - tw : align === 'center' ? x - tw / 2 : x;
82
+ const maxX = align === 'end' ? x : align === 'center' ? x + tw / 2 : x + tw;
83
+ return {
84
+ field,
85
+ minX: minX - pad,
86
+ maxX: maxX + pad,
87
+ minY: y - fs / 2 - pad,
88
+ maxY: y + fs / 2 + pad,
89
+ };
90
+ });
91
+ }
92
+
93
+ /** First label whose (padded) box contains the reference-space point, or null. */
94
+ export function hitTestEdgyLabel(
95
+ hits: EdgyLabelHit[],
96
+ rx: number,
97
+ ry: number
98
+ ): EdgyLabelHit | null {
99
+ for (const hit of hits) {
100
+ if (rx >= hit.minX && rx <= hit.maxX && ry >= hit.minY && ry <= hit.maxY) {
101
+ return hit;
102
+ }
103
+ }
104
+ return null;
105
+ }