@formicoidea/labre-framework-bpmn 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 (41) hide show
  1. package/package.json +6 -15
  2. package/{dist/consts.js → src/consts.ts} +57 -48
  3. package/{dist/descriptor.js → src/descriptor.ts} +1 -1
  4. package/src/effects.ts +14 -0
  5. package/src/element-renderer.ts +93 -0
  6. package/src/element-view.ts +116 -0
  7. package/src/index.ts +1 -0
  8. package/src/node/node-renderer.ts +65 -0
  9. package/src/node/node-view.ts +34 -0
  10. package/src/templates/index.ts +156 -0
  11. package/src/toolbar/bpmn-menu.ts +224 -0
  12. package/{dist/toolbar/bpmn-senior-button.js → src/toolbar/bpmn-senior-button.ts} +102 -97
  13. package/src/toolbar/config.ts +74 -0
  14. package/{dist/toolbar/icons.js → src/toolbar/icons.ts} +43 -37
  15. package/{dist/toolbar/senior-tool.js → src/toolbar/senior-tool.ts} +11 -11
  16. package/src/view.ts +37 -0
  17. package/dist/consts.d.ts +0 -42
  18. package/dist/descriptor.d.ts +0 -7
  19. package/dist/effects.d.ts +0 -10
  20. package/dist/effects.js +0 -7
  21. package/dist/element-renderer.d.ts +0 -13
  22. package/dist/element-renderer.js +0 -58
  23. package/dist/element-view.d.ts +0 -22
  24. package/dist/element-view.js +0 -103
  25. package/dist/index.d.ts +0 -2
  26. package/dist/index.js +0 -2
  27. package/dist/node/node-renderer.d.ts +0 -16
  28. package/dist/node/node-renderer.js +0 -43
  29. package/dist/node/node-view.d.ts +0 -17
  30. package/dist/node/node-view.js +0 -28
  31. package/dist/templates/index.d.ts +0 -3
  32. package/dist/templates/index.js +0 -114
  33. package/dist/toolbar/bpmn-menu.d.ts +0 -27
  34. package/dist/toolbar/bpmn-menu.js +0 -179
  35. package/dist/toolbar/bpmn-senior-button.d.ts +0 -16
  36. package/dist/toolbar/config.d.ts +0 -14
  37. package/dist/toolbar/config.js +0 -55
  38. package/dist/toolbar/icons.d.ts +0 -16
  39. package/dist/toolbar/senior-tool.d.ts +0 -2
  40. package/dist/view.d.ts +0 -7
  41. package/dist/view.js +0 -34
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formicoidea/labre-framework-bpmn",
3
3
  "description": "Labre bpmn 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,48 +1,57 @@
1
- /**
2
- * Visual constants for the BPMN basics. Style "C" (hybrid): spec-accurate
3
- * shapes and line weights, with accent colour only on the event rings — the
4
- * task and gateway stay neutral. All of these are just the creation-time
5
- * defaults; every value is an editable shape property afterwards.
6
- */
7
- /** Accent stroke for the start event (thin green ring). */
8
- export const EVENT_START = '#43a06b';
9
- /** Accent stroke for the end event (thick red ring). */
10
- export const EVENT_END = '#cf5648';
11
- /** Neutral stroke for task / gateway (matches the EDGY base shapes). */
12
- export const NEUTRAL_STROKE = '#262626';
13
- /** Default fill for events / task / gateway. */
14
- export const NODE_FILL = '#ffffff';
15
- /** BPMN line weights: thin start ring, thick end ring, regular elsewhere. */
16
- export const START_WIDTH = 2;
17
- export const END_WIDTH = 4;
18
- export const NODE_STROKE_WIDTH = 2;
19
- /** Task corner radius (absolute px a lightly rounded rectangle). */
20
- export const TASK_RADIUS = 10;
21
- /** Inner-text font for the task label. */
22
- export const INNER_FONT_SIZE = 18;
23
- /** Default node sizes (model units) per kind. */
24
- export const NODE_SIZE = {
25
- startEvent: { w: 56, h: 56 },
26
- endEvent: { w: 56, h: 56 },
27
- task: { w: 120, h: 72 },
28
- gatewayExclusive: { w: 72, h: 72 },
29
- };
30
- /** Default inner text per kind (only the task carries a label). */
31
- export const NODE_LABEL = {
32
- startEvent: '',
33
- endEvent: '',
34
- task: 'Task',
35
- gatewayExclusive: '',
36
- };
37
- /** Pool (background container) defaults. */
38
- export const POOL_BAND_WIDTH = 28;
39
- export const POOL_FRAME_COLOR = '#262626';
40
- export const POOL_BAND_FILL = '#f4f4f5';
41
- export const POOL_FRAME_WIDTH = 1.5;
42
- export const POOL_NAME_FONT_SIZE = 15;
43
- export const POOL_NAME_COLOR = '#262626';
44
- export const POOL_FONT_FAMILY = 'Inter, sans-serif';
45
- /** Sequence-flow connector preset. */
46
- export const SEQUENCE_STROKE = '#262626';
47
- export const SEQUENCE_WIDTH = 2;
48
- //# sourceMappingURL=consts.js.map
1
+ import type { BpmnNodeKind } from '@formicoidea/labre-core/model';
2
+
3
+ /**
4
+ * Visual constants for the BPMN basics. Style "C" (hybrid): spec-accurate
5
+ * shapes and line weights, with accent colour only on the event rings — the
6
+ * task and gateway stay neutral. All of these are just the creation-time
7
+ * defaults; every value is an editable shape property afterwards.
8
+ */
9
+
10
+ /** Accent stroke for the start event (thin green ring). */
11
+ export const EVENT_START = '#43a06b';
12
+ /** Accent stroke for the end event (thick red ring). */
13
+ export const EVENT_END = '#cf5648';
14
+ /** Neutral stroke for task / gateway (matches the EDGY base shapes). */
15
+ export const NEUTRAL_STROKE = '#262626';
16
+ /** Default fill for events / task / gateway. */
17
+ export const NODE_FILL = '#ffffff';
18
+
19
+ /** BPMN line weights: thin start ring, thick end ring, regular elsewhere. */
20
+ export const START_WIDTH = 2;
21
+ export const END_WIDTH = 4;
22
+ export const NODE_STROKE_WIDTH = 2;
23
+
24
+ /** Task corner radius (absolute px — a lightly rounded rectangle). */
25
+ export const TASK_RADIUS = 10;
26
+
27
+ /** Inner-text font for the task label. */
28
+ export const INNER_FONT_SIZE = 18;
29
+
30
+ /** Default node sizes (model units) per kind. */
31
+ export const NODE_SIZE: Record<BpmnNodeKind, { w: number; h: number }> = {
32
+ startEvent: { w: 56, h: 56 },
33
+ endEvent: { w: 56, h: 56 },
34
+ task: { w: 120, h: 72 },
35
+ gatewayExclusive: { w: 72, h: 72 },
36
+ };
37
+
38
+ /** Default inner text per kind (only the task carries a label). */
39
+ export const NODE_LABEL: Record<BpmnNodeKind, string> = {
40
+ startEvent: '',
41
+ endEvent: '',
42
+ task: 'Task',
43
+ gatewayExclusive: '',
44
+ };
45
+
46
+ /** Pool (background container) defaults. */
47
+ export const POOL_BAND_WIDTH = 28;
48
+ export const POOL_FRAME_COLOR = '#262626';
49
+ export const POOL_BAND_FILL = '#f4f4f5';
50
+ export const POOL_FRAME_WIDTH = 1.5;
51
+ export const POOL_NAME_FONT_SIZE = 15;
52
+ export const POOL_NAME_COLOR = '#262626';
53
+ export const POOL_FONT_FAMILY = 'Inter, sans-serif';
54
+
55
+ /** Sequence-flow connector preset. */
56
+ export const SEQUENCE_STROKE = '#262626';
57
+ export const SEQUENCE_WIDTH = 2;
@@ -5,4 +5,4 @@ export const bpmnFramework = {
5
5
  flag: 'bpmn',
6
6
  telemetry: 'bpmn',
7
7
  viewExtension: BpmnViewExtension,
8
- };
8
+ } as const;
package/src/effects.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { EdgelessBpmnMenu } from './toolbar/bpmn-menu';
2
+ import { EdgelessBpmnSeniorButton } from './toolbar/bpmn-senior-button';
3
+
4
+ export function effects() {
5
+ customElements.define('edgeless-bpmn-menu', EdgelessBpmnMenu);
6
+ customElements.define('edgeless-bpmn-senior-button', EdgelessBpmnSeniorButton);
7
+ }
8
+
9
+ declare global {
10
+ interface HTMLElementTagNameMap {
11
+ 'edgeless-bpmn-menu': EdgelessBpmnMenu;
12
+ 'edgeless-bpmn-senior-button': EdgelessBpmnSeniorButton;
13
+ }
14
+ }
@@ -0,0 +1,93 @@
1
+ import {
2
+ type ElementRenderer,
3
+ ElementRendererExtension,
4
+ } from '@formicoidea/labre-core/blocks/surface';
5
+ import type { BpmnPoolElementModel } from '@formicoidea/labre-core/model';
6
+
7
+ import {
8
+ POOL_BAND_FILL,
9
+ POOL_BAND_WIDTH,
10
+ POOL_FONT_FAMILY,
11
+ POOL_FRAME_COLOR,
12
+ POOL_FRAME_WIDTH,
13
+ POOL_NAME_COLOR,
14
+ POOL_NAME_FONT_SIZE,
15
+ } from './consts';
16
+
17
+ /** Trace a rounded-rectangle path (no dependency on ctx.roundRect). */
18
+ function roundedRectPath(
19
+ ctx: CanvasRenderingContext2D,
20
+ x: number,
21
+ y: number,
22
+ w: number,
23
+ h: number,
24
+ r: number
25
+ ): void {
26
+ const rr = Math.min(r, w / 2, h / 2);
27
+ ctx.beginPath();
28
+ ctx.moveTo(x + rr, y);
29
+ ctx.lineTo(x + w - rr, y);
30
+ ctx.arcTo(x + w, y, x + w, y + rr, rr);
31
+ ctx.lineTo(x + w, y + h - rr);
32
+ ctx.arcTo(x + w, y + h, x + w - rr, y + h, rr);
33
+ ctx.lineTo(x + rr, y + h);
34
+ ctx.arcTo(x, y + h, x, y + h - rr, rr);
35
+ ctx.lineTo(x, y + rr);
36
+ ctx.arcTo(x, y, x + rr, y, rr);
37
+ ctx.closePath();
38
+ }
39
+
40
+ /**
41
+ * Canvas renderer for a BPMN pool: a rounded-rect frame with a vertical name
42
+ * band on the left (the participant name is drawn rotated, as in the spec).
43
+ * Drawn directly in element space; the band width and font are fixed so they
44
+ * stay legible at any pool size. Mirrors the other framework backgrounds.
45
+ */
46
+ export const bpmnPool: ElementRenderer<BpmnPoolElementModel> = (
47
+ model,
48
+ ctx,
49
+ matrix
50
+ ) => {
51
+ const [, , w, h] = model.deserializedXYWH;
52
+ const cx = w / 2;
53
+ const cy = h / 2;
54
+ ctx.setTransform(
55
+ matrix.translateSelf(cx, cy).rotateSelf(model.rotate).translateSelf(-cx, -cy)
56
+ );
57
+
58
+ const band = Math.min(POOL_BAND_WIDTH, w);
59
+ const inset = POOL_FRAME_WIDTH / 2;
60
+
61
+ // Name band (left), filled.
62
+ ctx.fillStyle = POOL_BAND_FILL;
63
+ ctx.fillRect(0, 0, band, h);
64
+
65
+ // Frame + band divider.
66
+ ctx.strokeStyle = POOL_FRAME_COLOR;
67
+ ctx.lineWidth = POOL_FRAME_WIDTH;
68
+ ctx.lineJoin = 'round';
69
+ roundedRectPath(ctx, inset, inset, w - POOL_FRAME_WIDTH, h - POOL_FRAME_WIDTH, 6);
70
+ ctx.stroke();
71
+ ctx.beginPath();
72
+ ctx.moveTo(band, 0);
73
+ ctx.lineTo(band, h);
74
+ ctx.stroke();
75
+
76
+ // Participant name, rotated to read up the band (skip when empty / too narrow).
77
+ if (model.name && band > 12) {
78
+ ctx.save();
79
+ ctx.translate(band / 2, h / 2);
80
+ ctx.rotate(-Math.PI / 2);
81
+ ctx.fillStyle = POOL_NAME_COLOR;
82
+ ctx.font = `600 ${POOL_NAME_FONT_SIZE}px ${POOL_FONT_FAMILY}`;
83
+ ctx.textAlign = 'center';
84
+ ctx.textBaseline = 'middle';
85
+ ctx.fillText(model.name, 0, 0);
86
+ ctx.restore();
87
+ }
88
+ };
89
+
90
+ export const BpmnPoolRendererExtension = ElementRendererExtension(
91
+ 'bpmnPool',
92
+ bpmnPool
93
+ );
@@ -0,0 +1,116 @@
1
+ import { EdgelessCRUDIdentifier } from '@formicoidea/labre-core/blocks/surface';
2
+ import type { BpmnPoolElementModel } from '@formicoidea/labre-core/model';
3
+ import type { PointerEventState } from '@formicoidea/labre-core/std';
4
+ import {
5
+ GfxElementModelView,
6
+ GfxViewInteractionExtension,
7
+ } from '@formicoidea/labre-core/std/gfx';
8
+
9
+ /**
10
+ * View for a BPMN pool. A double-click edits the participant name in place
11
+ * (single field — the whole pool is the hit target). Mirrors the inline label
12
+ * editor used by the EDGY / Wardley backgrounds.
13
+ */
14
+ export class BpmnPoolView extends GfxElementModelView<BpmnPoolElementModel> {
15
+ static override type: string = 'bpmnPool';
16
+
17
+ private _nameEditor: HTMLInputElement | null = null;
18
+
19
+ override onCreated(): void {
20
+ super.onCreated();
21
+ this.on('dblclick', e => this._onDblClick(e));
22
+ }
23
+
24
+ override onDestroyed(): void {
25
+ this._closeEditor();
26
+ super.onDestroyed();
27
+ }
28
+
29
+ private _onDblClick(e: PointerEventState): void {
30
+ if (this.model.isLocked()) return;
31
+ this._openEditor(e);
32
+ }
33
+
34
+ private _openEditor(e: PointerEventState): void {
35
+ this._closeEditor();
36
+
37
+ const input = document.createElement('input');
38
+ input.value = String(this.model.name ?? '');
39
+ Object.assign(input.style, {
40
+ position: 'fixed',
41
+ left: `${e.raw.clientX}px`,
42
+ top: `${e.raw.clientY}px`,
43
+ transform: 'translate(-50%, -50%)',
44
+ zIndex: '10000',
45
+ minWidth: '140px',
46
+ padding: '3px 8px',
47
+ font: '14px Inter, sans-serif',
48
+ color: 'var(--affine-text-primary-color, #1f2328)',
49
+ background: 'var(--affine-background-overlay-panel-color, #ffffff)',
50
+ border: '1px solid var(--affine-primary-color, #1e96eb)',
51
+ borderRadius: '6px',
52
+ boxShadow: 'var(--affine-shadow-2, 0 2px 8px rgba(0,0,0,0.18))',
53
+ outline: 'none',
54
+ });
55
+ document.body.append(input);
56
+ this._nameEditor = input;
57
+
58
+ // Mark "editing" so the global edgeless key handlers (delete, escape, …)
59
+ // don't act on the pool while the user types.
60
+ this.gfx.selection.set({ elements: [this.model.id], editing: true });
61
+
62
+ input.focus();
63
+ input.select();
64
+
65
+ const commit = () => {
66
+ if (this._nameEditor !== input) return;
67
+ const value = input.value;
68
+ this._closeEditor();
69
+ this.gfx.std.store.captureSync();
70
+ this.gfx.std
71
+ .get(EdgelessCRUDIdentifier)
72
+ .updateElement(this.model.id, { name: value });
73
+ };
74
+
75
+ input.addEventListener('keydown', ev => {
76
+ ev.stopPropagation();
77
+ if (ev.key === 'Enter') {
78
+ ev.preventDefault();
79
+ commit();
80
+ } else if (ev.key === 'Escape') {
81
+ ev.preventDefault();
82
+ this._closeEditor();
83
+ }
84
+ });
85
+ input.addEventListener('blur', commit);
86
+ }
87
+
88
+ private _closeEditor(): void {
89
+ if (!this._nameEditor) return;
90
+ const input = this._nameEditor;
91
+ this._nameEditor = null;
92
+ input.remove();
93
+ if (this.isConnected) {
94
+ this.gfx.selection.set({ elements: [this.model.id], editing: false });
95
+ }
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Resize gating: the resize handles are hidden unless `model.resizeEnabled` is
101
+ * true (toggled from the toolbar). Moving / selecting stays available.
102
+ */
103
+ export const BpmnPoolInteraction = GfxViewInteractionExtension<BpmnPoolView>(
104
+ BpmnPoolView.type,
105
+ {
106
+ handleResize({ model }) {
107
+ return {
108
+ beforeResize({ set }) {
109
+ if (!model.resizeEnabled) {
110
+ set({ allowedHandlers: [] });
111
+ }
112
+ },
113
+ };
114
+ },
115
+ }
116
+ );
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ import {
2
+ type ElementRenderer,
3
+ ElementRendererExtension,
4
+ } from '@formicoidea/labre-core/blocks/surface';
5
+ import { shape as shapeRenderer } from '@formicoidea/labre-core/gfx/shape';
6
+ import { type BpmnNodeElementModel, DefaultTheme } from '@formicoidea/labre-core/model';
7
+
8
+ /**
9
+ * Renderer for a BPMN flow-object node. The shape body (ellipse / rounded rect
10
+ * / diamond) is drawn by REUSING the native shape renderer — so stroke width,
11
+ * colors, inner text and theme behave exactly like a native shape. Only
12
+ * `gatewayExclusive` is decorated: an X drawn on top in the node's (editable)
13
+ * stroke color. Events and task are plain native shapes.
14
+ *
15
+ * Mirrors the EDGY node renderer.
16
+ */
17
+ export const bpmnNode: ElementRenderer<BpmnNodeElementModel> = (
18
+ model,
19
+ ctx,
20
+ matrix,
21
+ renderer,
22
+ rc,
23
+ bound
24
+ ) => {
25
+ const [, , w, h] = model.deserializedXYWH;
26
+ const cx = w / 2;
27
+ const cy = h / 2;
28
+
29
+ // Capture the element-local transform BEFORE the shape renderer mutates the
30
+ // matrix, so the glyph can be drawn in the same space afterwards.
31
+ const glyphMatrix = DOMMatrix.fromMatrix(matrix)
32
+ .translateSelf(cx, cy)
33
+ .rotateSelf(model.rotate)
34
+ .translateSelf(-cx, -cy);
35
+
36
+ // Native shape (fill / stroke / inner text / theme handled natively).
37
+ shapeRenderer(model, ctx, matrix, renderer, rc, bound);
38
+
39
+ if (model.kind !== 'gatewayExclusive') return;
40
+
41
+ const color = renderer.getColorValue(
42
+ model.strokeColor,
43
+ DefaultTheme.shapeStrokeColor,
44
+ true
45
+ );
46
+
47
+ // ── Exclusive-gateway X, centred and sized to the diamond ───────────
48
+ const r = Math.min(w, h) * 0.2;
49
+ ctx.setTransform(glyphMatrix);
50
+ ctx.translate(cx, cy);
51
+ ctx.strokeStyle = color;
52
+ ctx.lineWidth = Math.max(2, Math.min(w, h) * 0.06);
53
+ ctx.lineCap = 'round';
54
+ ctx.beginPath();
55
+ ctx.moveTo(-r, -r);
56
+ ctx.lineTo(r, r);
57
+ ctx.moveTo(-r, r);
58
+ ctx.lineTo(r, -r);
59
+ ctx.stroke();
60
+ };
61
+
62
+ export const BpmnNodeRendererExtension = ElementRendererExtension(
63
+ 'bpmnNode',
64
+ bpmnNode
65
+ );
@@ -0,0 +1,34 @@
1
+ import { mountShapeTextEditor } from '@formicoidea/labre-core/gfx/shape';
2
+ import {
3
+ type BpmnNodeElementModel,
4
+ ShapeElementModel,
5
+ } from '@formicoidea/labre-core/model';
6
+ import { GfxElementModelView } from '@formicoidea/labre-core/std/gfx';
7
+
8
+ /**
9
+ * View for a BPMN flow-object node. Registering it ensures `gfx.view.get(model)`
10
+ * returns a view (required so move / select / connector interactions work).
11
+ *
12
+ * BPMN nodes are native shapes, so we reuse the shape inner-text editor: a
13
+ * double-click mounts the editable text overlay (`mountShapeTextEditor`),
14
+ * exactly like a native shape (used to label the task).
15
+ *
16
+ * Mirrors {@link EdgyNodeView}.
17
+ */
18
+ export class BpmnNodeView extends GfxElementModelView<BpmnNodeElementModel> {
19
+ static override type: string = 'bpmnNode';
20
+
21
+ override onCreated(): void {
22
+ super.onCreated();
23
+ this.on('dblclick', () => {
24
+ const edgeless = this.std.view.getBlock(this.std.store.root!.id);
25
+ if (
26
+ edgeless &&
27
+ !this.model.isLocked() &&
28
+ this.model instanceof ShapeElementModel
29
+ ) {
30
+ mountShapeTextEditor(this.model, edgeless);
31
+ }
32
+ });
33
+ }
34
+ }
@@ -0,0 +1,156 @@
1
+ import {
2
+ makeTemplateSnapshot,
3
+ type SurfaceElementsJSON,
4
+ surfaceText,
5
+ type Template,
6
+ type TemplateCategory,
7
+ } from '@formicoidea/labre-core/gfx/template';
8
+ import {
9
+ ConnectorMode,
10
+ FontFamily,
11
+ PointStyle,
12
+ ShapeStyle,
13
+ StrokeStyle,
14
+ } from '@formicoidea/labre-core/model';
15
+
16
+ import {
17
+ END_WIDTH,
18
+ EVENT_END,
19
+ EVENT_START,
20
+ INNER_FONT_SIZE,
21
+ NEUTRAL_STROKE,
22
+ NODE_FILL,
23
+ NODE_SIZE,
24
+ NODE_STROKE_WIDTH,
25
+ SEQUENCE_STROKE,
26
+ SEQUENCE_WIDTH,
27
+ START_WIDTH,
28
+ TASK_RADIUS,
29
+ } from '../consts';
30
+
31
+ type NodeKind = 'startEvent' | 'endEvent' | 'task' | 'gatewayExclusive';
32
+
33
+ /** One BPMN flow-object node, as a surface-element JSON entry. */
34
+ function node(kind: NodeKind, x: number, y: number, text?: string) {
35
+ const { w, h } = NODE_SIZE[kind];
36
+ const base: Record<string, unknown> = {
37
+ type: 'bpmnNode',
38
+ kind,
39
+ filled: true,
40
+ fillColor: NODE_FILL,
41
+ shapeStyle: ShapeStyle.General,
42
+ roughness: 0,
43
+ xywh: `[${x},${y},${w},${h}]`,
44
+ };
45
+ if (kind === 'startEvent')
46
+ return { ...base, shapeType: 'ellipse', strokeColor: EVENT_START, strokeWidth: START_WIDTH };
47
+ if (kind === 'endEvent')
48
+ return { ...base, shapeType: 'ellipse', strokeColor: EVENT_END, strokeWidth: END_WIDTH };
49
+ if (kind === 'gatewayExclusive')
50
+ return { ...base, shapeType: 'diamond', strokeColor: NEUTRAL_STROKE, strokeWidth: NODE_STROKE_WIDTH };
51
+ return {
52
+ ...base,
53
+ shapeType: 'rect',
54
+ radius: TASK_RADIUS,
55
+ strokeColor: NEUTRAL_STROKE,
56
+ strokeWidth: NODE_STROKE_WIDTH,
57
+ text: surfaceText(text ?? 'Task'),
58
+ color: NEUTRAL_STROKE,
59
+ fontFamily: FontFamily.Inter,
60
+ fontSize: INNER_FONT_SIZE,
61
+ textAlign: 'center',
62
+ };
63
+ }
64
+
65
+ function pool(x: number, y: number, w: number, h: number, name = 'Pool') {
66
+ return { type: 'bpmnPool', name, xywh: `[${x},${y},${w},${h}]` };
67
+ }
68
+
69
+ /** A sequence-flow connector; ids are remapped on insert. */
70
+ function seq(source: string, target: string) {
71
+ return {
72
+ type: 'connector',
73
+ mode: ConnectorMode.Orthogonal,
74
+ stroke: SEQUENCE_STROKE,
75
+ strokeWidth: SEQUENCE_WIDTH,
76
+ strokeStyle: StrokeStyle.Solid,
77
+ frontEndpointStyle: PointStyle.None,
78
+ rearEndpointStyle: PointStyle.Triangle,
79
+ source: { id: source, position: [0.5, 0.5] },
80
+ target: { id: target, position: [0.5, 0.5] },
81
+ };
82
+ }
83
+
84
+ /** A standalone (free) sequence-flow arrow for the prefab card. */
85
+ function freeSeq(): Record<string, unknown> {
86
+ return {
87
+ type: 'connector',
88
+ mode: ConnectorMode.Orthogonal,
89
+ stroke: SEQUENCE_STROKE,
90
+ strokeWidth: SEQUENCE_WIDTH,
91
+ strokeStyle: StrokeStyle.Solid,
92
+ frontEndpointStyle: PointStyle.None,
93
+ rearEndpointStyle: PointStyle.Triangle,
94
+ source: { position: [0, 0] },
95
+ target: { position: [140, 0] },
96
+ };
97
+ }
98
+
99
+ const single = (el: Record<string, unknown>): SurfaceElementsJSON => ({ a: el });
100
+
101
+ const PREVIEW_ATTRS = 'width="100%" height="100%" viewBox="0 0 135 80" xmlns="http://www.w3.org/2000/svg"';
102
+
103
+ const previews = {
104
+ process: `<svg ${PREVIEW_ATTRS} fill="none"><circle cx="16" cy="40" r="8" stroke="#43a06b" stroke-width="2"/><rect x="34" y="31" width="26" height="18" rx="3" stroke="#262626" stroke-width="1.6"/><path d="M78 31 L88 40 L78 49 L68 40 Z" stroke="#262626" stroke-width="1.4"/><path d="M73 37 L83 43 M83 37 L73 43" stroke="#262626" stroke-width="1.2"/><circle cx="118" cy="40" r="8" stroke="#cf5648" stroke-width="3"/><path d="M24 40 H34 M60 40 H68 M88 40 H110" stroke="#262626" stroke-width="1.2"/></svg>`,
105
+ startEvent: `<svg ${PREVIEW_ATTRS} fill="none"><circle cx="67" cy="40" r="20" stroke="#43a06b" stroke-width="3"/></svg>`,
106
+ endEvent: `<svg ${PREVIEW_ATTRS} fill="none"><circle cx="67" cy="40" r="20" stroke="#cf5648" stroke-width="5"/></svg>`,
107
+ task: `<svg ${PREVIEW_ATTRS} fill="none"><rect x="34" y="24" width="66" height="32" rx="6" stroke="#262626" stroke-width="2.4"/></svg>`,
108
+ gateway: `<svg ${PREVIEW_ATTRS} fill="none"><path d="M67 16 L92 40 L67 64 L42 40 Z" stroke="#262626" stroke-width="2.4" stroke-linejoin="round"/><path d="M58 31 L76 49 M76 31 L58 49" stroke="#262626" stroke-width="2.2" stroke-linecap="round"/></svg>`,
109
+ sequence: `<svg ${PREVIEW_ATTRS} fill="none"><path d="M24 40 H96" stroke="#262626" stroke-width="2.4" stroke-linecap="round"/><path d="M94 33 L108 40 L94 47 Z" fill="#262626"/></svg>`,
110
+ pool: `<svg ${PREVIEW_ATTRS} fill="none"><rect x="14" y="20" width="107" height="40" rx="3" stroke="#262626" stroke-width="2"/><path d="M30 20 V60" stroke="#262626" stroke-width="1.8"/><rect x="14" y="20" width="16" height="40" fill="#f4f4f5"/><path d="M30 20 V60" stroke="#262626" stroke-width="1.8"/></svg>`,
111
+ };
112
+
113
+ /** The lean BPMN basics: a simple worked process + every prefab the menu makes. */
114
+ function bpmnTemplates(): Template[] {
115
+ const process: SurfaceElementsJSON = {
116
+ pool: pool(0, 0, 640, 200, 'Process'),
117
+ start: node('startEvent', 40, 72),
118
+ task1: node('task', 116, 64, 'Submit request'),
119
+ gw: node('gatewayExclusive', 272, 64),
120
+ task2: node('task', 376, 20, 'Fulfil'),
121
+ task3: node('task', 376, 124, 'Reject'),
122
+ end: node('endEvent', 556, 72),
123
+ c1: seq('start', 'task1'),
124
+ c2: seq('task1', 'gw'),
125
+ c3: seq('gw', 'task2'),
126
+ c4: seq('gw', 'task3'),
127
+ c5: seq('task2', 'end'),
128
+ c6: seq('task3', 'end'),
129
+ };
130
+
131
+ const t = (
132
+ name: string,
133
+ preview: string,
134
+ elements: SurfaceElementsJSON
135
+ ): Template => ({
136
+ name,
137
+ type: 'template',
138
+ preview,
139
+ content: makeTemplateSnapshot(elements, name),
140
+ });
141
+
142
+ return [
143
+ t('Simple process', previews.process, process),
144
+ t('Start event', previews.startEvent, single(node('startEvent', 0, 0))),
145
+ t('End event', previews.endEvent, single(node('endEvent', 0, 0))),
146
+ t('Task', previews.task, single(node('task', 0, 0))),
147
+ t('Exclusive gateway', previews.gateway, single(node('gatewayExclusive', 0, 0))),
148
+ t('Sequence flow', previews.sequence, single(freeSeq())),
149
+ t('Pool', previews.pool, single(pool(0, 0, 560, 200))),
150
+ ];
151
+ }
152
+
153
+ export const bpmnTemplateCategory: TemplateCategory = {
154
+ name: 'BPMN',
155
+ templates: bpmnTemplates(),
156
+ };