@dr2rai/raid-canvas 0.1.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/LICENSE +201 -0
- package/NOTICE +2 -0
- package/dist/RaiBridge.d.ts +54 -0
- package/dist/RaiBridge.d.ts.map +1 -0
- package/dist/RaiBridge.js +408 -0
- package/dist/RaiBridge.js.map +1 -0
- package/dist/X6Shapes.d.ts +134 -0
- package/dist/X6Shapes.d.ts.map +1 -0
- package/dist/X6Shapes.js +536 -0
- package/dist/X6Shapes.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +162 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +32 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
- package/src/RaiBridge.ts +485 -0
- package/src/X6Shapes.ts +575 -0
- package/src/index.ts +39 -0
- package/src/styles/aoaim-theme.css +205 -0
- package/src/types.ts +208 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file RaiBridge.ts
|
|
3
|
+
* @description Bidirectional synchronization bridge between the SVG `aim-*` ontological
|
|
4
|
+
* contract and AntV X6 Graph models.
|
|
5
|
+
*
|
|
6
|
+
* Capabilities:
|
|
7
|
+
* - Hydrate: Ingests an SVG containing `aim-*` semantic attributes and inflates an interactive
|
|
8
|
+
* AntV X6 graph with orthogonal ports and Manhattan-routed edges.
|
|
9
|
+
* - Serialize: Extracts updated coordinates, node dimensions, and user-dragged bend points from
|
|
10
|
+
* the X6 graph, serializing them back into the SVG document while preserving semantic fidelity.
|
|
11
|
+
*/
|
|
12
|
+
import { Graph } from '@antv/x6';
|
|
13
|
+
import { type RaidMetamodel, type SvgBendPoint, type HydrationOptions, type SerializationOptions } from './types.js';
|
|
14
|
+
export declare class RaiBridge {
|
|
15
|
+
/**
|
|
16
|
+
* Hydrates an AntV X6 graph from an SVG source string or DOM Element.
|
|
17
|
+
*
|
|
18
|
+
* @param svgSource Raw SVG markup string or SVGSVGElement DOM node.
|
|
19
|
+
* @param graph The AntV X6 Graph instance to populate.
|
|
20
|
+
* @param options Hydration options.
|
|
21
|
+
* @returns The extracted RaidMetamodel representation.
|
|
22
|
+
*/
|
|
23
|
+
hydrateFromSvg(svgSource: string | Element, graph: Graph, options?: HydrationOptions): RaidMetamodel;
|
|
24
|
+
/**
|
|
25
|
+
* Serializes current X6 graph layout (positions, bounds, bend points) back into an SVG document.
|
|
26
|
+
*
|
|
27
|
+
* @param graph The AntV X6 Graph instance.
|
|
28
|
+
* @param baseSvg Optional base SVG string to update in-place.
|
|
29
|
+
* @param options Serialization options.
|
|
30
|
+
* @returns The updated SVG markup string adhering to the aim-* contract.
|
|
31
|
+
*/
|
|
32
|
+
serializeToSvg(graph: Graph, baseSvg?: string, options?: SerializationOptions): string;
|
|
33
|
+
/**
|
|
34
|
+
* Extracts a pure RaidMetamodel from an active AntV X6 Graph.
|
|
35
|
+
*/
|
|
36
|
+
metamodelFromGraph(graph: Graph): RaidMetamodel;
|
|
37
|
+
/**
|
|
38
|
+
* Parses semicolon-separated bend points: "100,50; 200,50; 200,150"
|
|
39
|
+
*/
|
|
40
|
+
parseBendPoints(bendsStr: string): SvgBendPoint[];
|
|
41
|
+
/**
|
|
42
|
+
* Formats bend points into the canonical aim-bends format: "x1,y1; x2,y2"
|
|
43
|
+
*/
|
|
44
|
+
formatBendPoints(points: readonly SvgBendPoint[]): string;
|
|
45
|
+
private resolveSvgElement;
|
|
46
|
+
private extractMetamodel;
|
|
47
|
+
private extractBounds;
|
|
48
|
+
private updateExistingSvg;
|
|
49
|
+
private generateFreshSvg;
|
|
50
|
+
private normalizeKind;
|
|
51
|
+
private normalizeEdgeKind;
|
|
52
|
+
private kindFromShape;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=RaiBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RaiBridge.d.ts","sourceRoot":"","sources":["../src/RaiBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,YAAY,EAEjB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EAC1B,MAAM,YAAY,CAAC;AAGpB,qBAAa,SAAS;IACpB;;;;;;;OAOG;IACI,cAAc,CACnB,SAAS,EAAE,MAAM,GAAG,OAAO,EAC3B,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE,gBAAqB,GAC7B,aAAa,CAuBf;IAED;;;;;;;OAOG;IACI,cAAc,CACnB,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,GAAE,oBAAyB,GACjC,MAAM,CAQR;IAED;;OAEG;IACI,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAuErD;IAED;;OAEG;IACI,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE,CAevD;IAED;;OAEG;IACI,gBAAgB,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,MAAM,CAE/D;IAMD,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,gBAAgB;IA8ExB,OAAO,CAAC,aAAa;IA8CrB,OAAO,CAAC,iBAAiB;IA0CzB,OAAO,CAAC,gBAAgB;IA8ExB,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,aAAa;CAQtB"}
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file RaiBridge.ts
|
|
3
|
+
* @description Bidirectional synchronization bridge between the SVG `aim-*` ontological
|
|
4
|
+
* contract and AntV X6 Graph models.
|
|
5
|
+
*
|
|
6
|
+
* Capabilities:
|
|
7
|
+
* - Hydrate: Ingests an SVG containing `aim-*` semantic attributes and inflates an interactive
|
|
8
|
+
* AntV X6 graph with orthogonal ports and Manhattan-routed edges.
|
|
9
|
+
* - Serialize: Extracts updated coordinates, node dimensions, and user-dragged bend points from
|
|
10
|
+
* the X6 graph, serializing them back into the SVG document while preserving semantic fidelity.
|
|
11
|
+
*/
|
|
12
|
+
import { AimSvgContract, } from './types.js';
|
|
13
|
+
import { createAimNode, createAimEdge, configureAimGraph, CascaisPalette } from './X6Shapes.js';
|
|
14
|
+
export class RaiBridge {
|
|
15
|
+
/**
|
|
16
|
+
* Hydrates an AntV X6 graph from an SVG source string or DOM Element.
|
|
17
|
+
*
|
|
18
|
+
* @param svgSource Raw SVG markup string or SVGSVGElement DOM node.
|
|
19
|
+
* @param graph The AntV X6 Graph instance to populate.
|
|
20
|
+
* @param options Hydration options.
|
|
21
|
+
* @returns The extracted RaidMetamodel representation.
|
|
22
|
+
*/
|
|
23
|
+
hydrateFromSvg(svgSource, graph, options = {}) {
|
|
24
|
+
configureAimGraph(graph);
|
|
25
|
+
if (options.clearGraph !== false) {
|
|
26
|
+
graph.clearCells();
|
|
27
|
+
}
|
|
28
|
+
const doc = this.resolveSvgElement(svgSource);
|
|
29
|
+
const metamodel = this.extractMetamodel(doc, options);
|
|
30
|
+
// 1. Add all nodes to graph
|
|
31
|
+
for (const nodeData of metamodel.nodes) {
|
|
32
|
+
const nodeMeta = createAimNode(nodeData);
|
|
33
|
+
graph.addNode(nodeMeta);
|
|
34
|
+
}
|
|
35
|
+
// 2. Add all edges to graph
|
|
36
|
+
for (const edgeData of metamodel.edges) {
|
|
37
|
+
const edgeMeta = createAimEdge(edgeData);
|
|
38
|
+
graph.addEdge(edgeMeta);
|
|
39
|
+
}
|
|
40
|
+
return metamodel;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Serializes current X6 graph layout (positions, bounds, bend points) back into an SVG document.
|
|
44
|
+
*
|
|
45
|
+
* @param graph The AntV X6 Graph instance.
|
|
46
|
+
* @param baseSvg Optional base SVG string to update in-place.
|
|
47
|
+
* @param options Serialization options.
|
|
48
|
+
* @returns The updated SVG markup string adhering to the aim-* contract.
|
|
49
|
+
*/
|
|
50
|
+
serializeToSvg(graph, baseSvg, options = {}) {
|
|
51
|
+
const metamodel = this.metamodelFromGraph(graph);
|
|
52
|
+
if (baseSvg) {
|
|
53
|
+
return this.updateExistingSvg(baseSvg, metamodel, options);
|
|
54
|
+
}
|
|
55
|
+
return this.generateFreshSvg(metamodel, options);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extracts a pure RaidMetamodel from an active AntV X6 Graph.
|
|
59
|
+
*/
|
|
60
|
+
metamodelFromGraph(graph) {
|
|
61
|
+
const nodes = [];
|
|
62
|
+
const edges = [];
|
|
63
|
+
// Extract nodes
|
|
64
|
+
const x6Nodes = graph.getNodes();
|
|
65
|
+
for (const node of x6Nodes) {
|
|
66
|
+
const pos = node.getPosition();
|
|
67
|
+
const size = node.getSize();
|
|
68
|
+
const customData = (node.getData() ?? {});
|
|
69
|
+
const id = node.id;
|
|
70
|
+
const kind = (customData.kind ?? this.kindFromShape(node.shape));
|
|
71
|
+
const displayName = customData.displayName ?? node.getAttrByPath('label/text') ?? id;
|
|
72
|
+
const nodeData = {
|
|
73
|
+
id,
|
|
74
|
+
kind,
|
|
75
|
+
displayName,
|
|
76
|
+
...(customData.stereotype !== undefined ? { stereotype: customData.stereotype } : {}),
|
|
77
|
+
...(customData.namespace !== undefined ? { namespace: customData.namespace } : {}),
|
|
78
|
+
...(customData.attributes !== undefined ? { attributes: customData.attributes } : {}),
|
|
79
|
+
...(customData.methods !== undefined ? { methods: customData.methods } : {}),
|
|
80
|
+
bounds: {
|
|
81
|
+
x: pos.x,
|
|
82
|
+
y: pos.y,
|
|
83
|
+
width: size.width,
|
|
84
|
+
height: size.height,
|
|
85
|
+
},
|
|
86
|
+
...(customData.properties !== undefined ? { properties: customData.properties } : {}),
|
|
87
|
+
};
|
|
88
|
+
nodes.push(nodeData);
|
|
89
|
+
}
|
|
90
|
+
// Extract edges
|
|
91
|
+
const x6Edges = graph.getEdges();
|
|
92
|
+
for (const edge of x6Edges) {
|
|
93
|
+
const source = edge.getSourceCell();
|
|
94
|
+
const target = edge.getTargetCell();
|
|
95
|
+
if (!source || !target)
|
|
96
|
+
continue;
|
|
97
|
+
const vertices = edge.getVertices();
|
|
98
|
+
const bendPoints = vertices.map((v) => ({ x: v.x, y: v.y }));
|
|
99
|
+
const customData = (edge.getData() ?? {});
|
|
100
|
+
const sourcePort = edge.getSourcePortId();
|
|
101
|
+
const targetPort = edge.getTargetPortId();
|
|
102
|
+
const label = edge.getLabels()?.[0]?.attrs?.['text']?.['text'] ?? customData.label;
|
|
103
|
+
const edgeData = {
|
|
104
|
+
id: edge.id,
|
|
105
|
+
kind: customData.kind ?? 'association',
|
|
106
|
+
sourceId: source.id,
|
|
107
|
+
targetId: target.id,
|
|
108
|
+
...(sourcePort !== undefined ? { sourcePort } : {}),
|
|
109
|
+
...(targetPort !== undefined ? { targetPort } : {}),
|
|
110
|
+
...(label !== undefined ? { label } : {}),
|
|
111
|
+
...(customData.stereotype !== undefined ? { stereotype: customData.stereotype } : {}),
|
|
112
|
+
bendPoints,
|
|
113
|
+
};
|
|
114
|
+
edges.push(edgeData);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
diagramId: 'RaidDiagram',
|
|
118
|
+
archetype: 'InteractiveCanvas',
|
|
119
|
+
nodes,
|
|
120
|
+
edges,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Parses semicolon-separated bend points: "100,50; 200,50; 200,150"
|
|
125
|
+
*/
|
|
126
|
+
parseBendPoints(bendsStr) {
|
|
127
|
+
if (!bendsStr || bendsStr.trim().length === 0) {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
return bendsStr
|
|
131
|
+
.split(';')
|
|
132
|
+
.map((part) => part.trim())
|
|
133
|
+
.filter((part) => part.length > 0)
|
|
134
|
+
.map((part) => {
|
|
135
|
+
const [xStr, yStr] = part.split(',');
|
|
136
|
+
const x = parseFloat(xStr?.trim() ?? '0');
|
|
137
|
+
const y = parseFloat(yStr?.trim() ?? '0');
|
|
138
|
+
return { x: Number.isNaN(x) ? 0 : x, y: Number.isNaN(y) ? 0 : y };
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Formats bend points into the canonical aim-bends format: "x1,y1; x2,y2"
|
|
143
|
+
*/
|
|
144
|
+
formatBendPoints(points) {
|
|
145
|
+
return points.map((p) => `${Math.round(p.x)},${Math.round(p.y)}`).join('; ');
|
|
146
|
+
}
|
|
147
|
+
// --------------------------------------------------------------------------
|
|
148
|
+
// Private Helper Implementation
|
|
149
|
+
// --------------------------------------------------------------------------
|
|
150
|
+
resolveSvgElement(source) {
|
|
151
|
+
if (typeof source !== 'string') {
|
|
152
|
+
return source;
|
|
153
|
+
}
|
|
154
|
+
if (typeof DOMParser !== 'undefined') {
|
|
155
|
+
const parser = new DOMParser();
|
|
156
|
+
const parsed = parser.parseFromString(source, 'image/svg+xml');
|
|
157
|
+
const root = parsed.documentElement;
|
|
158
|
+
if (root.tagName.toLowerCase() === 'parsererror') {
|
|
159
|
+
throw new Error('Failed to parse SVG: XML Parser Error');
|
|
160
|
+
}
|
|
161
|
+
return root;
|
|
162
|
+
}
|
|
163
|
+
throw new Error('DOMParser unavailable in current execution environment');
|
|
164
|
+
}
|
|
165
|
+
extractMetamodel(svgRoot, options) {
|
|
166
|
+
const nodes = [];
|
|
167
|
+
const edges = [];
|
|
168
|
+
// 1. Locate all node elements
|
|
169
|
+
const nodeElements = Array.from(svgRoot.querySelectorAll(AimSvgContract.SELECTOR_NODE));
|
|
170
|
+
for (const el of nodeElements) {
|
|
171
|
+
const id = el.getAttribute(AimSvgContract.ATTR_ID) ??
|
|
172
|
+
el.getAttribute('data-node') ??
|
|
173
|
+
el.getAttribute('data-element-id') ??
|
|
174
|
+
el.getAttribute('id');
|
|
175
|
+
if (!id)
|
|
176
|
+
continue;
|
|
177
|
+
const rawKind = el.getAttribute(AimSvgContract.ATTR_KIND) ?? 'act';
|
|
178
|
+
const kind = this.normalizeKind(rawKind);
|
|
179
|
+
const displayName = el.getAttribute(AimSvgContract.ATTR_DISPLAY_NAME) ??
|
|
180
|
+
el.querySelector('text')?.textContent?.trim() ??
|
|
181
|
+
id;
|
|
182
|
+
const stereotype = el.getAttribute(AimSvgContract.ATTR_STEREOTYPE) ?? undefined;
|
|
183
|
+
const bounds = this.extractBounds(el, options.defaultNodeSize);
|
|
184
|
+
nodes.push({
|
|
185
|
+
id,
|
|
186
|
+
kind,
|
|
187
|
+
displayName,
|
|
188
|
+
...(stereotype !== undefined ? { stereotype } : {}),
|
|
189
|
+
bounds,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
// 2. Locate all edge elements
|
|
193
|
+
const edgeElements = Array.from(svgRoot.querySelectorAll(AimSvgContract.SELECTOR_EDGE));
|
|
194
|
+
for (const el of edgeElements) {
|
|
195
|
+
const id = el.getAttribute(AimSvgContract.ATTR_ID) ?? el.getAttribute('id') ?? `edge-${edges.length + 1}`;
|
|
196
|
+
const sourceId = el.getAttribute(AimSvgContract.ATTR_SOURCE);
|
|
197
|
+
const targetId = el.getAttribute(AimSvgContract.ATTR_TARGET);
|
|
198
|
+
if (!sourceId || !targetId)
|
|
199
|
+
continue;
|
|
200
|
+
const rawEdgeKind = el.getAttribute(AimSvgContract.ATTR_EDGE_KIND) ?? 'association';
|
|
201
|
+
const kind = this.normalizeEdgeKind(rawEdgeKind);
|
|
202
|
+
const bendsAttr = el.getAttribute(AimSvgContract.ATTR_BENDS) ?? '';
|
|
203
|
+
const bendPoints = this.parseBendPoints(bendsAttr);
|
|
204
|
+
const sourcePort = el.getAttribute(AimSvgContract.ATTR_SOURCE_PORT) ?? undefined;
|
|
205
|
+
const targetPort = el.getAttribute(AimSvgContract.ATTR_TARGET_PORT) ?? undefined;
|
|
206
|
+
edges.push({
|
|
207
|
+
id,
|
|
208
|
+
kind,
|
|
209
|
+
sourceId,
|
|
210
|
+
targetId,
|
|
211
|
+
...(sourcePort !== undefined ? { sourcePort } : {}),
|
|
212
|
+
...(targetPort !== undefined ? { targetPort } : {}),
|
|
213
|
+
bendPoints,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
diagramId: svgRoot.getAttribute('id') ?? 'ImportedDiagram',
|
|
218
|
+
archetype: svgRoot.getAttribute('aim-archetype') ?? 'AOAIMDiagram',
|
|
219
|
+
nodes,
|
|
220
|
+
edges,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
extractBounds(el, defaultSize = { width: 140, height: 60 }) {
|
|
224
|
+
let x = 0;
|
|
225
|
+
let y = 0;
|
|
226
|
+
let width = defaultSize.width;
|
|
227
|
+
let height = defaultSize.height;
|
|
228
|
+
// Check transform matrix or translate
|
|
229
|
+
const transform = el.getAttribute('transform');
|
|
230
|
+
if (transform) {
|
|
231
|
+
const match = /translate\(\s*([-\d.]+)[,\s]+([-\d.]+)\s*\)/.exec(transform);
|
|
232
|
+
if (match && match[1] && match[2]) {
|
|
233
|
+
x = parseFloat(match[1]);
|
|
234
|
+
y = parseFloat(match[2]);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// Check direct geometry attributes (rect, ellipse, circle)
|
|
238
|
+
const rect = el.querySelector('rect') ?? (el.tagName.toLowerCase() === 'rect' ? el : null);
|
|
239
|
+
if (rect) {
|
|
240
|
+
if (!transform && rect.getAttribute('x'))
|
|
241
|
+
x = parseFloat(rect.getAttribute('x'));
|
|
242
|
+
if (!transform && rect.getAttribute('y'))
|
|
243
|
+
y = parseFloat(rect.getAttribute('y'));
|
|
244
|
+
if (rect.getAttribute('width'))
|
|
245
|
+
width = parseFloat(rect.getAttribute('width'));
|
|
246
|
+
if (rect.getAttribute('height'))
|
|
247
|
+
height = parseFloat(rect.getAttribute('height'));
|
|
248
|
+
}
|
|
249
|
+
const ellipse = el.querySelector('ellipse') ?? (el.tagName.toLowerCase() === 'ellipse' ? el : null);
|
|
250
|
+
if (ellipse) {
|
|
251
|
+
const rx = parseFloat(ellipse.getAttribute('rx') ?? `${width / 2}`);
|
|
252
|
+
const ry = parseFloat(ellipse.getAttribute('ry') ?? `${height / 2}`);
|
|
253
|
+
width = rx * 2;
|
|
254
|
+
height = ry * 2;
|
|
255
|
+
if (!transform) {
|
|
256
|
+
const cx = parseFloat(ellipse.getAttribute('cx') ?? '0');
|
|
257
|
+
const cy = parseFloat(ellipse.getAttribute('cy') ?? '0');
|
|
258
|
+
x = cx - rx;
|
|
259
|
+
y = cy - ry;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return { x, y, width, height };
|
|
263
|
+
}
|
|
264
|
+
updateExistingSvg(baseSvg, model, _options) {
|
|
265
|
+
if (typeof DOMParser === 'undefined' || typeof XMLSerializer === 'undefined') {
|
|
266
|
+
return this.generateFreshSvg(model, _options);
|
|
267
|
+
}
|
|
268
|
+
const parser = new DOMParser();
|
|
269
|
+
const doc = parser.parseFromString(baseSvg, 'image/svg+xml');
|
|
270
|
+
// Update node positions and transforms
|
|
271
|
+
for (const node of model.nodes) {
|
|
272
|
+
const el = doc.querySelector(`[${AimSvgContract.ATTR_ID}="${node.id}"], [id="${node.id}"]`);
|
|
273
|
+
if (el) {
|
|
274
|
+
el.setAttribute('transform', `translate(${node.bounds.x}, ${node.bounds.y})`);
|
|
275
|
+
el.setAttribute(AimSvgContract.ATTR_NODE, 'true');
|
|
276
|
+
el.setAttribute(AimSvgContract.ATTR_KIND, node.kind);
|
|
277
|
+
const rect = el.querySelector('rect');
|
|
278
|
+
if (rect) {
|
|
279
|
+
rect.setAttribute('width', `${node.bounds.width}`);
|
|
280
|
+
rect.setAttribute('height', `${node.bounds.height}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
// Update edge bend points and aim-bends attributes
|
|
285
|
+
for (const edge of model.edges) {
|
|
286
|
+
const el = doc.querySelector(`[${AimSvgContract.ATTR_ID}="${edge.id}"], [id="${edge.id}"]`);
|
|
287
|
+
if (el) {
|
|
288
|
+
const bendsString = this.formatBendPoints(edge.bendPoints);
|
|
289
|
+
el.setAttribute(AimSvgContract.ATTR_BENDS, bendsString);
|
|
290
|
+
el.setAttribute(AimSvgContract.ATTR_EDGE, 'true');
|
|
291
|
+
el.setAttribute(AimSvgContract.ATTR_EDGE_KIND, edge.kind);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return new XMLSerializer().serializeToString(doc);
|
|
295
|
+
}
|
|
296
|
+
generateFreshSvg(model, options) {
|
|
297
|
+
const width = Math.max(800, ...model.nodes.map((n) => n.bounds.x + n.bounds.width + 100));
|
|
298
|
+
const height = Math.max(600, ...model.nodes.map((n) => n.bounds.y + n.bounds.height + 100));
|
|
299
|
+
let svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" id="${model.diagramId}" aim-archetype="${model.archetype}">\n`;
|
|
300
|
+
// Definitions & Markers
|
|
301
|
+
svg += ` <defs>\n`;
|
|
302
|
+
svg += ` <marker id="arrow-classic" viewBox="0 0 10 10" refX="10" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">\n`;
|
|
303
|
+
svg += ` <path d="M 0 0 L 10 5 L 0 10 z" fill="${CascaisPalette.WarmGraphite}" />\n`;
|
|
304
|
+
svg += ` </marker>\n`;
|
|
305
|
+
svg += ` <marker id="arrow-hollow" viewBox="0 0 12 12" refX="12" refY="6" markerWidth="9" markerHeight="9" orient="auto-start-reverse">\n`;
|
|
306
|
+
svg += ` <polygon points="0 0, 12 6, 0 12" fill="${CascaisPalette.ChalkWhite}" stroke="${CascaisPalette.WarmGraphite}" stroke-width="1.5" />\n`;
|
|
307
|
+
svg += ` </marker>\n`;
|
|
308
|
+
if (options.embedStyles !== false) {
|
|
309
|
+
svg += ` <style>\n`;
|
|
310
|
+
svg += ` .aim-node { cursor: pointer; transition: filter 0.15s ease; }\n`;
|
|
311
|
+
svg += ` .aim-node:hover { filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1)); }\n`;
|
|
312
|
+
svg += ` .aim-edge { fill: none; stroke: ${CascaisPalette.WarmGraphite}; stroke-width: 1.5; }\n`;
|
|
313
|
+
svg += ` text { font-family: Inter, system-ui, sans-serif; }\n`;
|
|
314
|
+
svg += ` </style>\n`;
|
|
315
|
+
}
|
|
316
|
+
svg += ` </defs>\n\n`;
|
|
317
|
+
// Render Edges
|
|
318
|
+
svg += ` <!-- Edges -->\n`;
|
|
319
|
+
svg += ` <g class="aim-edges-layer">\n`;
|
|
320
|
+
for (const edge of model.edges) {
|
|
321
|
+
const bendsFormatted = this.formatBendPoints(edge.bendPoints);
|
|
322
|
+
const strokeDash = edge.kind === 'dependency' ? ' stroke-dasharray="5,5"' : '';
|
|
323
|
+
const markerEnd = edge.kind === 'generalization' ? ' marker-end="url(#arrow-hollow)"' : ' marker-end="url(#arrow-classic)"';
|
|
324
|
+
// Path data construction
|
|
325
|
+
let pathD = '';
|
|
326
|
+
if (edge.bendPoints.length > 0) {
|
|
327
|
+
const first = edge.bendPoints[0];
|
|
328
|
+
pathD = `M ${first.x} ${first.y} ` + edge.bendPoints.slice(1).map((p) => `L ${p.x} ${p.y}`).join(' ');
|
|
329
|
+
}
|
|
330
|
+
svg += ` <g ${AimSvgContract.ATTR_EDGE}="true" ${AimSvgContract.ATTR_ID}="${edge.id}" ${AimSvgContract.ATTR_EDGE_KIND}="${edge.kind}" ${AimSvgContract.ATTR_SOURCE}="${edge.sourceId}" ${AimSvgContract.ATTR_TARGET}="${edge.targetId}" ${AimSvgContract.ATTR_BENDS}="${bendsFormatted}">\n`;
|
|
331
|
+
if (pathD) {
|
|
332
|
+
svg += ` <path d="${pathD}" class="aim-edge"${strokeDash}${markerEnd} />\n`;
|
|
333
|
+
}
|
|
334
|
+
if (edge.label) {
|
|
335
|
+
const midPoint = edge.bendPoints[Math.floor(edge.bendPoints.length / 2)] ?? { x: 50, y: 50 };
|
|
336
|
+
svg += ` <text x="${midPoint.x}" y="${midPoint.y - 8}" font-size="11" fill="${CascaisPalette.TextSecondary}" text-anchor="middle">${edge.label}</text>\n`;
|
|
337
|
+
}
|
|
338
|
+
svg += ` </g>\n`;
|
|
339
|
+
}
|
|
340
|
+
svg += ` </g>\n\n`;
|
|
341
|
+
// Render Nodes
|
|
342
|
+
svg += ` <!-- Nodes -->\n`;
|
|
343
|
+
svg += ` <g class="aim-nodes-layer">\n`;
|
|
344
|
+
for (const node of model.nodes) {
|
|
345
|
+
svg += ` <g ${AimSvgContract.ATTR_NODE}="true" ${AimSvgContract.ATTR_ID}="${node.id}" ${AimSvgContract.ATTR_KIND}="${node.kind}" ${AimSvgContract.ATTR_DISPLAY_NAME}="${node.displayName}" transform="translate(${node.bounds.x}, ${node.bounds.y})">\n`;
|
|
346
|
+
if (node.kind === 'uc') {
|
|
347
|
+
const rx = node.bounds.width / 2;
|
|
348
|
+
const ry = node.bounds.height / 2;
|
|
349
|
+
svg += ` <ellipse cx="${rx}" cy="${ry}" rx="${rx}" ry="${ry}" fill="${CascaisPalette.ChalkWhite}" stroke="${CascaisPalette.NetGold}" stroke-width="2" />\n`;
|
|
350
|
+
svg += ` <text x="${rx}" y="${ry}" font-size="13" font-weight="bold" fill="${CascaisPalette.TextPrimary}" text-anchor="middle" dominant-baseline="central">${node.displayName}</text>\n`;
|
|
351
|
+
}
|
|
352
|
+
else if (node.kind === 'act') {
|
|
353
|
+
svg += ` <rect width="${node.bounds.width}" height="${node.bounds.height}" rx="12" ry="12" fill="${CascaisPalette.CanvasCream}" stroke="${CascaisPalette.HeraldicGreen}" stroke-width="2" />\n`;
|
|
354
|
+
svg += ` <text x="${node.bounds.width / 2}" y="${node.bounds.height / 2}" font-size="13" font-weight="600" fill="${CascaisPalette.TextPrimary}" text-anchor="middle" dominant-baseline="central">${node.displayName}</text>\n`;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
svg += ` <rect width="${node.bounds.width}" height="${node.bounds.height}" fill="${CascaisPalette.ChalkWhite}" stroke="${CascaisPalette.WarmGraphite}" stroke-width="1.5" />\n`;
|
|
358
|
+
svg += ` <text x="${node.bounds.width / 2}" y="${node.bounds.height / 2}" font-size="12" fill="${CascaisPalette.TextPrimary}" text-anchor="middle" dominant-baseline="central">${node.displayName}</text>\n`;
|
|
359
|
+
}
|
|
360
|
+
svg += ` </g>\n`;
|
|
361
|
+
}
|
|
362
|
+
svg += ` </g>\n`;
|
|
363
|
+
svg += `</svg>\n`;
|
|
364
|
+
return svg;
|
|
365
|
+
}
|
|
366
|
+
normalizeKind(kind) {
|
|
367
|
+
const lower = kind.toLowerCase();
|
|
368
|
+
if (lower === 'uc' || lower === 'usecase')
|
|
369
|
+
return 'uc';
|
|
370
|
+
if (lower === 'act' || lower === 'activity')
|
|
371
|
+
return 'act';
|
|
372
|
+
if (lower === 'cls' || lower === 'class')
|
|
373
|
+
return 'cls';
|
|
374
|
+
if (lower === 'obj' || lower === 'object')
|
|
375
|
+
return 'obj';
|
|
376
|
+
if (lower === 'per' || lower === 'person' || lower === 'actor')
|
|
377
|
+
return 'per';
|
|
378
|
+
return 'act';
|
|
379
|
+
}
|
|
380
|
+
normalizeEdgeKind(kind) {
|
|
381
|
+
const lower = kind.toLowerCase();
|
|
382
|
+
if (lower.includes('depend'))
|
|
383
|
+
return 'dependency';
|
|
384
|
+
if (lower.includes('general') || lower.includes('inher'))
|
|
385
|
+
return 'generalization';
|
|
386
|
+
if (lower.includes('realiz'))
|
|
387
|
+
return 'realization';
|
|
388
|
+
if (lower.includes('aggreg'))
|
|
389
|
+
return 'aggregation';
|
|
390
|
+
if (lower.includes('compos'))
|
|
391
|
+
return 'composition';
|
|
392
|
+
return 'association';
|
|
393
|
+
}
|
|
394
|
+
kindFromShape(shape) {
|
|
395
|
+
if (shape.includes('uc'))
|
|
396
|
+
return 'uc';
|
|
397
|
+
if (shape.includes('act'))
|
|
398
|
+
return 'act';
|
|
399
|
+
if (shape.includes('cls'))
|
|
400
|
+
return 'cls';
|
|
401
|
+
if (shape.includes('obj'))
|
|
402
|
+
return 'obj';
|
|
403
|
+
if (shape.includes('per'))
|
|
404
|
+
return 'per';
|
|
405
|
+
return 'act';
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
//# sourceMappingURL=RaiBridge.js.map
|