@grethel-labs/excaliplant 0.8.0 → 0.9.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
@@ -7,7 +7,7 @@
7
7
  [![node](https://img.shields.io/node/v/@grethel-labs/excaliplant.svg)](https://nodejs.org)
8
8
  [![license](https://img.shields.io/npm/l/@grethel-labs/excaliplant.svg)](./LICENSE)
9
9
 
10
- > PlantUML → ELK layout → Excalidraw renderer with a plugin-based parser.  ·  **v0.8.0**  ·  194 tests  ·  MIT
10
+ > PlantUML → ELK layout → Excalidraw renderer with a plugin-based parser.  ·  **v0.9.0**  ·  194 tests  ·  MIT
11
11
 
12
12
  `@grethel-labs/excaliplant` takes PlantUML source, runs it through a plugin-based
13
13
  parser, lays it out with [ELK](https://github.com/kieler/elkjs), and
@@ -330,6 +330,16 @@ excaliplant
330
330
  │ │ │ ├── graph_context.mjs
331
331
  │ │ │ ├── graph_parser.mjs
332
332
  │ │ │ └── graph_runtime.mjs
333
+ │ │ ├── use-case
334
+ │ │ │ ├── plugins
335
+ │ │ │ ├── assets.mjs
336
+ │ │ │ ├── docs.mjs
337
+ │ │ │ ├── layout.mjs
338
+ │ │ │ ├── module.mjs
339
+ │ │ │ ├── parser.mjs
340
+ │ │ │ ├── render.mjs
341
+ │ │ │ ├── security.mjs
342
+ │ │ │ └── tests.mjs
333
343
  │ │ └── index.mjs
334
344
  │ ├── general
335
345
  │ │ ├── layout
@@ -379,7 +389,8 @@ excaliplant
379
389
  │ ├── security.test.mjs
380
390
  │ ├── self_introspection.test.mjs
381
391
  │ ├── sequence_components.test.mjs
382
- │ └── style.test.mjs
392
+ │ ├── style.test.mjs
393
+ │ └── usecase_components.test.mjs
383
394
  ├── AGENTS.md
384
395
  ├── CHANGELOG.md
385
396
  ├── CLAUDE.md
@@ -392,7 +403,6 @@ excaliplant
392
403
  ├── index.mjs
393
404
  ├── lifecycle-test.svg
394
405
  ├── package.json
395
- ├── prompt-deployment-diagram.md
396
406
  ├── style.example.json
397
407
  ├── style.example.yaml
398
408
  └── tsconfig.json
@@ -601,6 +611,58 @@ generated by the same command from JSDoc.
601
611
 
602
612
 
603
613
 
614
+ ### diagrams/use-case/assets
615
+
616
+
617
+
618
+ ### diagrams/use-case/docs
619
+
620
+
621
+
622
+ ### diagrams/use-case/layout
623
+
624
+
625
+
626
+ ### diagrams/use-case/module
627
+
628
+
629
+
630
+ ### diagrams/use-case/parser
631
+
632
+
633
+
634
+ ### diagrams/use-case/plugins/actors
635
+
636
+
637
+
638
+ ### diagrams/use-case/plugins/containers
639
+
640
+
641
+
642
+ ### diagrams/use-case/plugins/notes
643
+
644
+
645
+
646
+ ### diagrams/use-case/plugins/relationships
647
+
648
+
649
+
650
+ ### diagrams/use-case/plugins/usecases
651
+
652
+
653
+
654
+ ### diagrams/use-case/render
655
+
656
+
657
+
658
+ ### diagrams/use-case/security
659
+
660
+
661
+
662
+ ### diagrams/use-case/tests
663
+
664
+
665
+
604
666
  ### layout
605
667
 
606
668
  Layout chooses positions for every shape and routes every edge.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grethel-labs/excaliplant",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "PlantUML → ELK layout → Excalidraw renderer with a plugin-based parser.",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
@@ -91,11 +91,27 @@ export {
91
91
  } from "./deployment/render.mjs";
92
92
  export { DeploymentDiagramSecurity, deploymentDiagramSecurity } from "./deployment/security.mjs";
93
93
  export { DeploymentDiagramTests, deploymentDiagramTests } from "./deployment/tests.mjs";
94
+ export { UseCaseDiagramModule, useCaseDiagramModule } from "./use-case/module.mjs";
95
+ export { UseCaseDiagramAssets, useCaseDiagramAssets } from "./use-case/assets.mjs";
96
+ export { UseCaseDiagramDocs, useCaseDiagramDocs } from "./use-case/docs.mjs";
97
+ export { UseCaseDiagramLayout, useCaseDiagramLayout } from "./use-case/layout.mjs";
98
+ export {
99
+ UseCaseDiagramParser,
100
+ DEFAULT_USE_CASE_PLUGINS,
101
+ createUseCaseParseContext,
102
+ detectUseCaseDiagram,
103
+ prepareUseCaseLines,
104
+ useCaseDiagramParser,
105
+ } from "./use-case/parser.mjs";
106
+ export { UseCaseDiagramRenderer, useCaseDiagramRenderer } from "./use-case/render.mjs";
107
+ export { UseCaseDiagramSecurity, useCaseDiagramSecurity } from "./use-case/security.mjs";
108
+ export { UseCaseDiagramTests, useCaseDiagramTests } from "./use-case/tests.mjs";
94
109
 
95
110
  import { sequenceDiagramModule } from "./sequence/module.mjs";
96
111
  import { classDiagramModule } from "./class/module.mjs";
97
112
  import { componentDiagramModule } from "./component/module.mjs";
98
113
  import { deploymentDiagramModule } from "./deployment/module.mjs";
114
+ import { useCaseDiagramModule } from "./use-case/module.mjs";
99
115
 
100
116
  /** @public */
101
117
  export const BUILTIN_DIAGRAM_MODULES = Object.freeze([
@@ -103,4 +119,5 @@ export const BUILTIN_DIAGRAM_MODULES = Object.freeze([
103
119
  classDiagramModule,
104
120
  componentDiagramModule,
105
121
  deploymentDiagramModule,
122
+ useCaseDiagramModule,
106
123
  ]);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Use-case diagram asset manifest.
3
+ * @module diagrams/use-case/assets
4
+ */
5
+
6
+ import { BaseModuleAssets } from "../base/assets.mjs";
7
+
8
+ /** @public */
9
+ export class UseCaseDiagramAssets extends BaseModuleAssets {
10
+ constructor() {
11
+ super({});
12
+ }
13
+ }
14
+
15
+ /** @public */
16
+ export const useCaseDiagramAssets = new UseCaseDiagramAssets();
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Use-case diagram documentation manifest.
3
+ * @module diagrams/use-case/docs
4
+ */
5
+
6
+ import { BaseModuleDocs } from "../base/docs.mjs";
7
+
8
+ /** @public */
9
+ export class UseCaseDiagramDocs extends BaseModuleDocs {
10
+ constructor() {
11
+ super({
12
+ examples: [],
13
+ generatedPages: [],
14
+ knownGaps: [],
15
+ });
16
+ }
17
+ }
18
+
19
+ /** @public */
20
+ export const useCaseDiagramDocs = new UseCaseDiagramDocs();
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Use-case diagram layout contract.
3
+ * @module diagrams/use-case/layout
4
+ */
5
+
6
+ import { BaseModuleLayout } from "../base/layout.mjs";
7
+
8
+ /** @public */
9
+ export class UseCaseDiagramLayout extends BaseModuleLayout {
10
+ constructor() {
11
+ super({
12
+ layoutStrategy: "elk",
13
+ });
14
+ }
15
+ }
16
+
17
+ /** @public */
18
+ export const useCaseDiagramLayout = new UseCaseDiagramLayout();
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Built-in use-case diagram module.
3
+ * @module diagrams/use-case/module
4
+ */
5
+
6
+ import { GraphModuleBase } from "../base/module.mjs";
7
+ import { useCaseDiagramParser } from "./parser.mjs";
8
+ import { useCaseDiagramLayout } from "./layout.mjs";
9
+ import { useCaseDiagramRenderer } from "./render.mjs";
10
+ import { useCaseDiagramSecurity } from "./security.mjs";
11
+ import { useCaseDiagramAssets } from "./assets.mjs";
12
+ import { useCaseDiagramDocs } from "./docs.mjs";
13
+ import { useCaseDiagramTests } from "./tests.mjs";
14
+
15
+ /** @public */
16
+ export class UseCaseDiagramModule extends GraphModuleBase {
17
+ constructor() {
18
+ super({
19
+ kind: "use-case",
20
+ artifactRoot: "src/diagrams/use-case",
21
+ ownedArtifacts: {
22
+ parser: [
23
+ "src/diagrams/use-case/parser.mjs",
24
+ "src/diagrams/use-case/plugins/actors.mjs",
25
+ "src/diagrams/use-case/plugins/usecases.mjs",
26
+ "src/diagrams/use-case/plugins/relationships.mjs",
27
+ "src/diagrams/use-case/plugins/containers.mjs",
28
+ "src/diagrams/use-case/plugins/notes.mjs",
29
+ "src/diagrams/shared/graph_parser.mjs",
30
+ "src/diagrams/shared/graph_plugins/connections.mjs",
31
+ "src/diagrams/shared/graph_plugins/filters.mjs",
32
+ "src/diagrams/shared/graph_plugins/preamble.mjs",
33
+ ],
34
+ model: ["src/diagrams/shared/graph_context.mjs", "src/general/model/diagram.mjs"],
35
+ style: [],
36
+ layout: ["src/diagrams/use-case/layout.mjs"],
37
+ render: ["src/diagrams/use-case/render.mjs"],
38
+ security: ["src/diagrams/use-case/security.mjs"],
39
+ assets: ["src/diagrams/use-case/assets.mjs"],
40
+ docs: ["src/diagrams/use-case/docs.mjs"],
41
+ tests: ["src/diagrams/use-case/tests.mjs", "tests/usecase_components.test.mjs"],
42
+ },
43
+ genericFallback: true,
44
+ startDirectives: ["@startuml", "@startusecase"],
45
+ parser: useCaseDiagramParser,
46
+ layout: useCaseDiagramLayout,
47
+ renderer: useCaseDiagramRenderer,
48
+ security: useCaseDiagramSecurity,
49
+ assets: useCaseDiagramAssets,
50
+ docs: useCaseDiagramDocs,
51
+ tests: useCaseDiagramTests,
52
+ });
53
+ }
54
+ }
55
+
56
+ /** @public */
57
+ export const useCaseDiagramModule = new UseCaseDiagramModule();
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Use-case diagram parser contract.
3
+ * @module diagrams/use-case/parser
4
+ */
5
+
6
+ import { BaseModuleParser } from "../base/parser.mjs";
7
+ import { createComponentContext } from "../shared/graph_context.mjs";
8
+ import { actorPlugin } from "./plugins/actors.mjs";
9
+ import { usecasePlugin } from "./plugins/usecases.mjs";
10
+ import { useCaseRelationshipPlugin } from "./plugins/relationships.mjs";
11
+ import { useCaseContainerPlugin } from "./plugins/containers.mjs";
12
+ import { useCaseNotePlugin } from "./plugins/notes.mjs";
13
+ import { connectionPlugin } from "../shared/graph_plugins/connections.mjs";
14
+ import { createTitlePlugin } from "../shared/common_plugins/title.mjs";
15
+ import { collectBlockLines, unescapeLabel } from "../../util/plantuml_utils.mjs";
16
+
17
+ /**
18
+ * `title …` line for use-case diagrams.
19
+ * @type {import("../../util/parser_engine.mjs").Plugin}
20
+ */
21
+ const useCaseTitlePlugin = createTitlePlugin("use-case.title");
22
+
23
+ /**
24
+ * Closing `}` for any open container.
25
+ * @type {import("../../util/parser_engine.mjs").Plugin}
26
+ */
27
+ const useCaseCloseBracePlugin = {
28
+ name: "use-case.close",
29
+ tryLine(line, ctx) {
30
+ if (line !== "}") return false;
31
+ ctx.closeContainer();
32
+ return true;
33
+ },
34
+ };
35
+
36
+ /**
37
+ * Skinparam plugin for use-case diagrams.
38
+ * @type {import("../../util/parser_engine.mjs").Plugin}
39
+ */
40
+ const useCaseSkinparamPlugin = {
41
+ name: "use-case.skinparam",
42
+ tryLine(line) {
43
+ return /^skinparam\b/i.test(line);
44
+ },
45
+ tryStart(line) {
46
+ if (!/^skinparam\b.*\{$/i.test(line)) return null;
47
+ return {
48
+ onLine() {},
49
+ tryEnd(blockLine) {
50
+ return blockLine === "}";
51
+ },
52
+ };
53
+ },
54
+ };
55
+
56
+ /**
57
+ * Direction hints for use-case diagrams.
58
+ * @type {import("../../util/parser_engine.mjs").Plugin}
59
+ */
60
+ const useCaseDirectionPlugin = {
61
+ name: "use-case.direction",
62
+ tryLine(line, ctx) {
63
+ const m = line.match(/^(left\s+to\s+right|top\s+to\s+bottom)\s+direction$/i);
64
+ if (!m) return false;
65
+ ctx.diagram.layoutDirection = /^left/i.test(m[1]) ? "RIGHT" : "DOWN";
66
+ return true;
67
+ },
68
+ };
69
+
70
+ /**
71
+ * Presentation commands for use-case diagrams.
72
+ * @type {import("../../util/parser_engine.mjs").Plugin}
73
+ */
74
+ const useCasePresentationPlugin = {
75
+ name: "use-case.presentation",
76
+ tryLine(line, ctx) {
77
+ const caption = line.match(/^caption\s+(.+)$/i);
78
+ if (caption) {
79
+ ctx.diagram.caption = unescapeLabel(caption[1].trim());
80
+ return true;
81
+ }
82
+ const header = line.match(/^header\s+(.+)$/i);
83
+ if (header) {
84
+ ctx.diagram.header = unescapeLabel(header[1].trim());
85
+ return true;
86
+ }
87
+ const footer = line.match(/^footer\s+(.+)$/i);
88
+ if (footer) {
89
+ ctx.diagram.footer = unescapeLabel(footer[1].trim());
90
+ return true;
91
+ }
92
+ const mainframe = line.match(/^mainframe\s+(.+)$/i);
93
+ if (mainframe) {
94
+ ctx.diagram.mainframe = unescapeLabel(mainframe[1].trim());
95
+ return true;
96
+ }
97
+ return /^allowmixing\b/i.test(line);
98
+ },
99
+ tryStart(line) {
100
+ if (!/^legend\b/i.test(line)) return null;
101
+ return collectBlockLines(/^end\s+legend$/i, (lines, ctx) => {
102
+ ctx.diagram.legend = lines.join("\n");
103
+ });
104
+ },
105
+ };
106
+
107
+ /**
108
+ * Filter plugin for use-case diagrams.
109
+ * @type {import("../../util/parser_engine.mjs").Plugin}
110
+ */
111
+ const useCaseFilterPlugin = {
112
+ name: "use-case.filter",
113
+ tryLine(line) {
114
+ return /^(?:hide|show)\s+\w+/i.test(line);
115
+ },
116
+ tryStart(line) {
117
+ const m = line.match(/^remove\s*\{/i);
118
+ if (!m) return null;
119
+ return {
120
+ onLine() {},
121
+ tryEnd(blockLine) {
122
+ return blockLine === "}";
123
+ },
124
+ };
125
+ },
126
+ };
127
+
128
+ /**
129
+ * Detects if source is a use-case diagram.
130
+ * @param {string} source - PlantUML source
131
+ * @returns {boolean}
132
+ */
133
+ export function detectUseCaseDiagram(source) {
134
+ const trimmed = source.trim();
135
+ if (/^@startusecase\b/m.test(trimmed)) return true;
136
+ if (!/^@startuml\b/m.test(trimmed)) return false;
137
+
138
+ // Check for use-case specific patterns
139
+ const useCasePatterns = [
140
+ /\(:[^)]+\)/, // (Use case) notation
141
+ /:actor:/i, // :Actor: notation
142
+ /\bactor\b/i, // actor keyword
143
+ /\busecase\b/i, // usecase keyword
144
+ /\(First usecase\)/i, // Common use-case example
145
+ /\bactorStyle\b/i, // actorStyle skinparam
146
+ ];
147
+
148
+ return useCasePatterns.some((pattern) => pattern.test(trimmed));
149
+ }
150
+
151
+ /** @public */
152
+ export const DEFAULT_USE_CASE_PLUGINS = Object.freeze([
153
+ useCaseTitlePlugin,
154
+ useCaseSkinparamPlugin,
155
+ useCaseDirectionPlugin,
156
+ useCasePresentationPlugin,
157
+ useCaseCloseBracePlugin,
158
+ useCaseFilterPlugin,
159
+ actorPlugin,
160
+ usecasePlugin,
161
+ useCaseContainerPlugin,
162
+ useCaseNotePlugin,
163
+ useCaseRelationshipPlugin,
164
+ connectionPlugin,
165
+ ]);
166
+
167
+ /**
168
+ * Create a parse context for use-case diagrams.
169
+ * @returns {object}
170
+ */
171
+ export function createUseCaseParseContext() {
172
+ return createComponentContext();
173
+ }
174
+
175
+ /**
176
+ * Prepare lines for parsing (normalize, strip comments, etc.).
177
+ * @param {string[]} lines
178
+ * @returns {string[]}
179
+ */
180
+ export function prepareUseCaseLines(lines) {
181
+ return lines;
182
+ }
183
+
184
+ /** @public */
185
+ export class UseCaseDiagramParser extends BaseModuleParser {
186
+ constructor() {
187
+ super({
188
+ plugins: DEFAULT_USE_CASE_PLUGINS,
189
+ createParseContext: createUseCaseParseContext,
190
+ prepareLines: prepareUseCaseLines,
191
+ detect: detectUseCaseDiagram,
192
+ });
193
+ }
194
+ }
195
+
196
+ /** @public */
197
+ export const useCaseDiagramParser = new UseCaseDiagramParser();
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Actor plugin for use-case diagrams.
3
+ * @module diagrams/use-case/plugins/actors
4
+ */
5
+
6
+ import { stripComment, slug } from "../../../util/plantuml_utils.mjs";
7
+
8
+ /**
9
+ * Parse actor declaration with colon notation :Actor Name:.
10
+ * @param {string} line
11
+ * @returns {{type: string, id: string, title: string}|null}
12
+ */
13
+ function parseColonActor(line) {
14
+ // Match :Actor Name: or :Actor Name: as Alias
15
+ const match = line.match(/^:([^:]+):(?:\s+as\s+(\w+))?$/);
16
+ if (!match) return null;
17
+
18
+ const name = match[1].trim();
19
+ const alias = match[2] || slug(name);
20
+
21
+ return {
22
+ type: "actor",
23
+ id: alias,
24
+ title: name,
25
+ };
26
+ }
27
+
28
+ /**
29
+ * Parse actor keyword declaration.
30
+ * @param {string} line
31
+ * @returns {{type: string, id: string, title: string}|null}
32
+ */
33
+ function parseKeywordActor(line) {
34
+ // Match: actor "Name" as Alias or actor :Name: as Alias
35
+ const match = line.match(/^actor\s+(?::([^:]+):|"([^"]+)"|(\w+))(?:\s+as\s+(\w+))?$/i);
36
+ if (!match) return null;
37
+
38
+ const name = (match[1] || match[2] || match[3]).trim();
39
+ const alias = match[4] || slug(name);
40
+
41
+ return {
42
+ type: "actor",
43
+ id: alias,
44
+ title: name,
45
+ };
46
+ }
47
+
48
+ /**
49
+ * Parse actorStyle directive.
50
+ * @param {string} line
51
+ * @returns {{type: string, style: string}|null}
52
+ */
53
+ function parseActorStyle(line) {
54
+ const match = line.match(/^skinparam\s+actorStyle\s+(\w+)$/i);
55
+ if (!match) return null;
56
+
57
+ return {
58
+ type: "actorStyle",
59
+ style: match[1].toLowerCase(), // awesome, hollow, default
60
+ };
61
+ }
62
+
63
+ /** @public */
64
+ export const actorPlugin = {
65
+ name: "use-case.actor",
66
+
67
+ /**
68
+ * Try to parse an actor line.
69
+ * @param {string} line
70
+ * @param {ReturnType<import("../../shared/graph_context.mjs").createComponentContext>} ctx
71
+ * @returns {boolean}
72
+ */
73
+ tryLine(line, ctx) {
74
+ const cleanLine = stripComment(line).trim();
75
+ if (!cleanLine) return false;
76
+
77
+ // Try actorStyle first
78
+ const style = parseActorStyle(cleanLine);
79
+ if (style) {
80
+ // Store actor style in diagram metadata if needed
81
+ return true;
82
+ }
83
+
84
+ // Try colon notation :Actor:
85
+ const colonActor = parseColonActor(cleanLine);
86
+ if (colonActor) {
87
+ ctx.addBox({
88
+ id: colonActor.id,
89
+ title: colonActor.title,
90
+ shape: "actor",
91
+ });
92
+ return true;
93
+ }
94
+
95
+ // Try keyword actor
96
+ const keywordActor = parseKeywordActor(cleanLine);
97
+ if (keywordActor) {
98
+ ctx.addBox({
99
+ id: keywordActor.id,
100
+ title: keywordActor.title,
101
+ shape: "actor",
102
+ });
103
+ return true;
104
+ }
105
+
106
+ return false;
107
+ },
108
+ };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Container plugin for use-case diagrams (packages, rectangles).
3
+ * @module diagrams/use-case/plugins/containers
4
+ */
5
+
6
+ import { stripComment } from "../../../util/plantuml_utils.mjs";
7
+
8
+ /**
9
+ * Parse container start.
10
+ * @param {string} line
11
+ * @returns {{type: string, name: string, id: string}|null}
12
+ */
13
+ function parseContainerStart(line) {
14
+ // Match: package "Name" { or rectangle "Name" {
15
+ const match = line.match(/^(package|rectangle)\s+(?:"([^"]+)"|(\w+))\s*\{\s*$/i);
16
+ if (!match) return null;
17
+
18
+ const name = match[2] || match[3];
19
+ const type = match[1].toLowerCase();
20
+
21
+ return {
22
+ type,
23
+ name,
24
+ id: name.toLowerCase().replace(/\s+/g, "_"),
25
+ };
26
+ }
27
+
28
+ /** @public */
29
+ export const useCaseContainerPlugin = {
30
+ name: "use-case.containers",
31
+
32
+ /**
33
+ * Try to parse container start.
34
+ * @param {string} line
35
+ * @param {ReturnType<import("../../shared/graph_context.mjs").createComponentContext>} ctx
36
+ * @returns {{onLine: () => boolean, tryEnd: (endLine: string) => boolean}|null}
37
+ */
38
+ tryStart(line, ctx) {
39
+ const cleanLine = stripComment(line).trim();
40
+ if (!cleanLine) return null;
41
+
42
+ const container = parseContainerStart(cleanLine);
43
+ if (container) {
44
+ ctx.openContainer({
45
+ id: container.id,
46
+ title: container.name,
47
+ kind: container.type,
48
+ });
49
+ return {
50
+ onLine: () => true,
51
+ tryEnd: (endLine) => {
52
+ if (endLine.trim() === "}") {
53
+ ctx.closeContainer();
54
+ return true;
55
+ }
56
+ return false;
57
+ },
58
+ };
59
+ }
60
+
61
+ return null;
62
+ },
63
+ };
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Note plugin for use-case diagrams.
3
+ * @module diagrams/use-case/plugins/notes
4
+ */
5
+
6
+ import { stripComment } from "../../../util/plantuml_utils.mjs";
7
+
8
+ /**
9
+ * Parse note declaration.
10
+ * @param {string} line
11
+ * @returns {{type: "anchored", position: string, target: string}|{type: "floating", text: string, id: string}|null}
12
+ */
13
+ function parseNote(line) {
14
+ // Match: note right of Actor
15
+ // Match: note "Text" as N1
16
+ const anchoredMatch = line.match(/^note\s+(right|left|top|bottom)\s+of\s+(\w+)\s*$/i);
17
+ if (anchoredMatch) {
18
+ return {
19
+ type: "anchored",
20
+ position: anchoredMatch[1].toLowerCase(),
21
+ target: anchoredMatch[2],
22
+ };
23
+ }
24
+
25
+ const floatingMatch = line.match(/^note\s+"([^"]+)"\s+as\s+(\w+)\s*$/i);
26
+ if (floatingMatch) {
27
+ return {
28
+ type: "floating",
29
+ text: floatingMatch[1],
30
+ id: floatingMatch[2],
31
+ };
32
+ }
33
+
34
+ return null;
35
+ }
36
+
37
+ /** @public */
38
+ export const useCaseNotePlugin = {
39
+ name: "use-case.notes",
40
+
41
+ /**
42
+ * Try to parse a note line.
43
+ * @param {string} line
44
+ * @param {ReturnType<import("../../shared/graph_context.mjs").createComponentContext>} ctx
45
+ * @returns {boolean}
46
+ */
47
+ tryLine(line, ctx) {
48
+ const cleanLine = stripComment(line).trim();
49
+ if (!cleanLine) return false;
50
+
51
+ const note = parseNote(cleanLine);
52
+ if (note) {
53
+ if (note.type === "anchored") {
54
+ ctx.queueNote({
55
+ targetId: note.target,
56
+ text: "",
57
+ side: note.position,
58
+ });
59
+ } else {
60
+ ctx.addBox({
61
+ id: note.id,
62
+ title: note.text,
63
+ shape: "note",
64
+ });
65
+ }
66
+ return true;
67
+ }
68
+
69
+ return false;
70
+ },
71
+ };
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Relationship plugin for use-case diagrams.
3
+ * @module diagrams/use-case/plugins/relationships
4
+ */
5
+
6
+ import { stripComment } from "../../../util/plantuml_utils.mjs";
7
+
8
+ /**
9
+ * Parse use-case relationship.
10
+ * Supports: -->, ..>, <|--, :> (include), .> (extend)
11
+ * @param {string} line
12
+ * @returns {{from: string, to: string, type: string, label: string, dashed: boolean}|null}
13
+ */
14
+ function parseRelationship(line) {
15
+ // Match: Actor --> Usecase : label
16
+ // Match: Usecase ..> Usecase2 : include
17
+ // Match: Usecase <|-- Usecase2 (generalization)
18
+ // Match: Actor -- Usecase (simple association)
19
+
20
+ const patterns = [
21
+ // Include: ..> or .>
22
+ {
23
+ regex: /^(\w+)\s*\.\.?>\s*(\w+)\s*(?::\s*(.+))?$/,
24
+ type: "include",
25
+ dashed: true,
26
+ },
27
+ // Extend: <|-- or <--
28
+ {
29
+ regex: /^(\w+)\s*<\|?--\s*(\w+)\s*(?::\s*(.+))?$/,
30
+ type: "extend",
31
+ dashed: false,
32
+ },
33
+ // Generalization: --|> or -->
34
+ {
35
+ regex: /^(\w+)\s*--\|?>\s*(\w+)\s*(?::\s*(.+))?$/,
36
+ type: "generalization",
37
+ dashed: false,
38
+ },
39
+ // Association: --> or --
40
+ {
41
+ regex: /^(\w+)\s*--+>\s*(\w+)\s*(?::\s*(.+))?$/,
42
+ type: "association",
43
+ dashed: false,
44
+ },
45
+ // Simple association without arrowhead: --
46
+ {
47
+ regex: /^(\w+)\s*--\s*(\w+)\s*(?::\s*(.+))?$/,
48
+ type: "association",
49
+ dashed: false,
50
+ },
51
+ ];
52
+
53
+ for (const pattern of patterns) {
54
+ const match = line.match(pattern.regex);
55
+ if (match) {
56
+ return {
57
+ from: match[1],
58
+ to: match[2],
59
+ type: pattern.type,
60
+ label: match[3]?.trim() || "",
61
+ dashed: pattern.dashed,
62
+ };
63
+ }
64
+ }
65
+
66
+ return null;
67
+ }
68
+
69
+ /** @public */
70
+ export const useCaseRelationshipPlugin = {
71
+ name: "use-case.relationships",
72
+
73
+ /**
74
+ * Try to parse a relationship line.
75
+ * @param {string} line
76
+ * @param {ReturnType<import("../../shared/graph_context.mjs").createComponentContext>} ctx
77
+ * @returns {boolean}
78
+ */
79
+ tryLine(line, ctx) {
80
+ const cleanLine = stripComment(line).trim();
81
+ if (!cleanLine) return false;
82
+
83
+ const relationship = parseRelationship(cleanLine);
84
+ if (relationship) {
85
+ ctx.queueConnection({
86
+ fromId: relationship.from,
87
+ toId: relationship.to,
88
+ label: relationship.label,
89
+ dashed: relationship.dashed,
90
+ directed: true,
91
+ });
92
+ return true;
93
+ }
94
+
95
+ return false;
96
+ },
97
+ };
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Usecase plugin for use-case diagrams.
3
+ * @module diagrams/use-case/plugins/usecases
4
+ */
5
+
6
+ import { stripComment, slug } from "../../../util/plantuml_utils.mjs";
7
+
8
+ /**
9
+ * Parse usecase with parentheses notation (Use Case Name).
10
+ * @param {string} line
11
+ * @returns {{type: string, id: string, title: string}|null}
12
+ */
13
+ function parseParenthesisUsecase(line) {
14
+ // Match (Use Case Name) or (Use Case Name) as Alias
15
+ const match = line.match(/^\(([^)]+)\)(?:\s+as\s+(\w+))?$/);
16
+ if (!match) return null;
17
+
18
+ const name = match[1].trim();
19
+ const alias = match[2] || slug(name);
20
+
21
+ return {
22
+ type: "usecase",
23
+ id: alias,
24
+ title: name,
25
+ };
26
+ }
27
+
28
+ /**
29
+ * Parse usecase keyword declaration.
30
+ * @param {string} line
31
+ * @returns {{type: string, id: string, title: string}|null}
32
+ */
33
+ function parseKeywordUsecase(line) {
34
+ // Match: usecase "Name" as Alias or usecase (Name) as Alias
35
+ const match = line.match(/^usecase\s+(?:\(([^)]+)\)|"([^"]+)"|(\w+))(?:\s+as\s+(\w+))?$/i);
36
+ if (!match) return null;
37
+
38
+ const name = (match[1] || match[2] || match[3]).trim();
39
+ const alias = match[4] || slug(name);
40
+
41
+ return {
42
+ type: "usecase",
43
+ id: alias,
44
+ title: name,
45
+ };
46
+ }
47
+
48
+ /** @public */
49
+ export const usecasePlugin = {
50
+ name: "use-case.usecase",
51
+
52
+ /**
53
+ * Try to parse a usecase line.
54
+ * @param {string} line
55
+ * @param {ReturnType<import("../../shared/graph_context.mjs").createComponentContext>} ctx
56
+ * @returns {boolean}
57
+ */
58
+ tryLine(line, ctx) {
59
+ const cleanLine = stripComment(line).trim();
60
+ if (!cleanLine) return false;
61
+
62
+ // Try parenthesis notation (Use Case)
63
+ const parenUsecase = parseParenthesisUsecase(cleanLine);
64
+ if (parenUsecase) {
65
+ ctx.addBox({
66
+ id: parenUsecase.id,
67
+ title: parenUsecase.title,
68
+ shape: "usecase",
69
+ });
70
+ return true;
71
+ }
72
+
73
+ // Try keyword usecase
74
+ const keywordUsecase = parseKeywordUsecase(cleanLine);
75
+ if (keywordUsecase) {
76
+ ctx.addBox({
77
+ id: keywordUsecase.id,
78
+ title: keywordUsecase.title,
79
+ shape: "usecase",
80
+ });
81
+ return true;
82
+ }
83
+
84
+ return false;
85
+ },
86
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Use-case diagram renderer contract.
3
+ * @module diagrams/use-case/render
4
+ */
5
+
6
+ import { BaseModuleRenderer } from "../base/renderer.mjs";
7
+
8
+ /** @public */
9
+ export class UseCaseDiagramRenderer extends BaseModuleRenderer {
10
+ constructor() {
11
+ super({
12
+ renderers: {},
13
+ });
14
+ }
15
+ }
16
+
17
+ /** @public */
18
+ export const useCaseDiagramRenderer = new UseCaseDiagramRenderer();
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Use-case diagram security profile.
3
+ * @module diagrams/use-case/security
4
+ */
5
+
6
+ import { BaseModuleSecurity } from "../base/security.mjs";
7
+
8
+ /** @public */
9
+ export class UseCaseDiagramSecurity extends BaseModuleSecurity {
10
+ constructor() {
11
+ super({});
12
+ }
13
+ }
14
+
15
+ /** @public */
16
+ export const useCaseDiagramSecurity = new UseCaseDiagramSecurity();
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Use-case diagram test manifest.
3
+ * @module diagrams/use-case/tests
4
+ */
5
+
6
+ import { BaseModuleTests } from "../base/tests.mjs";
7
+
8
+ /** @public */
9
+ export class UseCaseDiagramTests extends BaseModuleTests {
10
+ constructor() {
11
+ super({
12
+ unit: [],
13
+ integration: [],
14
+ security: [],
15
+ });
16
+ }
17
+ }
18
+
19
+ /** @public */
20
+ export const useCaseDiagramTests = new UseCaseDiagramTests();