@formicoidea/labre-framework-edgy 0.23.0 → 0.23.1

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