mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-08 18:16:44 +02:00
Compare commits
10 Commits
@mermaid-j
...
6587-class
Author | SHA1 | Date | |
---|---|---|---|
![]() |
361c0076c8 | ||
![]() |
3840451fda | ||
![]() |
cfe9238882 | ||
![]() |
ad35a930c6 | ||
![]() |
a495eb03e2 | ||
![]() |
8f9ee39af7 | ||
![]() |
eb81bdd617 | ||
![]() |
faa03bb4b2 | ||
![]() |
fbf1085b57 | ||
![]() |
e2b7f7fc84 |
5
.changeset/old-eagles-agree.md
Normal file
5
.changeset/old-eagles-agree.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'mermaid': patch
|
||||
---
|
||||
|
||||
fix: Added support for styling class diagram elements based on stereotype annotations
|
9
.changeset/revert-marked-dependency.md
Normal file
9
.changeset/revert-marked-dependency.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
'mermaid': patch
|
||||
---
|
||||
|
||||
chore: revert marked dependency from ^15.0.7 to ^16.0.0
|
||||
|
||||
- Reverted marked package version to ^16.0.0 for better compatibility
|
||||
- This is a dependency update that maintains API compatibility
|
||||
- All tests pass with the updated version
|
@@ -1028,4 +1028,88 @@ class C13["With Città foreign language"]
|
||||
{ logLevel: 1, htmlLabels: true }
|
||||
);
|
||||
});
|
||||
it('should render a full class diagram using interface annotation', () => {
|
||||
imgSnapshotTest(
|
||||
`
|
||||
classDiagram
|
||||
Class01 <|-- AveryLongClass : Cool
|
||||
<<interface>> Class01
|
||||
Class03 "0" *-- "0..n" Class04
|
||||
Class05 "1" o-- "many" Class06
|
||||
Class07 .. Class08
|
||||
Class09 "many" --> "1" C2 : Where am i?
|
||||
Class09 "0" --* "1..n" C3
|
||||
Class09 --|> Class07
|
||||
Class07 : equals()
|
||||
Class07 : Object[] elementData
|
||||
Class01 : #size()
|
||||
Class01 : -int chimp
|
||||
Class01 : +int gorilla
|
||||
Class08 <--> C2: Cool label
|
||||
class Class10 {
|
||||
<<service>>
|
||||
int id
|
||||
size()
|
||||
}
|
||||
|
||||
`,
|
||||
{ logLevel: 1, htmlLabels: true }
|
||||
);
|
||||
});
|
||||
it('should render a full class diagram using abstract annotation', () => {
|
||||
imgSnapshotTest(
|
||||
`
|
||||
classDiagram
|
||||
Class01 <|-- AveryLongClass : Cool
|
||||
<<abstract>> Class01
|
||||
Class03 "0" *-- "0..n" Class04
|
||||
Class05 "1" o-- "many" Class06
|
||||
Class07 .. Class08
|
||||
Class09 "many" --> "1" C2 : Where am i?
|
||||
Class09 "0" --* "1..n" C3
|
||||
Class09 --|> Class07
|
||||
Class07 : equals()
|
||||
Class07 : Object[] elementData
|
||||
Class01 : #size()
|
||||
Class01 : -int chimp
|
||||
Class01 : +int gorilla
|
||||
Class08 <--> C2: Cool label
|
||||
class Class10 {
|
||||
<<service>>
|
||||
int id
|
||||
size()
|
||||
}
|
||||
|
||||
`,
|
||||
{ logLevel: 1, htmlLabels: true }
|
||||
);
|
||||
});
|
||||
it('should render a full class diagram using enumeration annotation', () => {
|
||||
imgSnapshotTest(
|
||||
`
|
||||
classDiagram
|
||||
Class01 <|-- AveryLongClass : Cool
|
||||
<<enumeration>> Class01
|
||||
Class03 "0" *-- "0..n" Class04
|
||||
Class05 "1" o-- "many" Class06
|
||||
Class07 .. Class08
|
||||
Class09 "many" --> "1" C2 : Where am i?
|
||||
Class09 "0" --* "1..n" C3
|
||||
Class09 --|> Class07
|
||||
Class07 : equals()
|
||||
Class07 : Object[] elementData
|
||||
Class01 : #size()
|
||||
Class01 : -int chimp
|
||||
Class01 : +int gorilla
|
||||
Class08 <--> C2: Cool label
|
||||
class Class10 {
|
||||
<<service>>
|
||||
int id
|
||||
size()
|
||||
}
|
||||
|
||||
`,
|
||||
{ logLevel: 1, htmlLabels: true }
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -82,7 +82,7 @@
|
||||
"katex": "^0.16.22",
|
||||
"khroma": "^2.1.0",
|
||||
"lodash-es": "^4.17.21",
|
||||
"marked": "^15.0.7",
|
||||
"marked": "^16.0.0",
|
||||
"roughjs": "^4.6.6",
|
||||
"stylis": "^4.3.6",
|
||||
"ts-dedent": "^2.2.0",
|
||||
|
@@ -36,15 +36,57 @@ export async function textHelper<T extends SVGGraphicsElement>(
|
||||
|
||||
annotationGroup = shapeSvg.insert('g').attr('class', 'annotation-group text');
|
||||
if (node.annotations.length > 0) {
|
||||
const annotation = node.annotations[0];
|
||||
await addText(annotationGroup, { text: `«${annotation}»` } as unknown as ClassMember, 0);
|
||||
|
||||
const annotation = node.annotations[0].toLowerCase();
|
||||
let isSupported = false;
|
||||
switch (annotation) {
|
||||
case 'interface':
|
||||
case 'abstract':
|
||||
case 'enumeration':
|
||||
isSupported = true;
|
||||
break;
|
||||
}
|
||||
if (!isSupported) {
|
||||
await addText(
|
||||
annotationGroup,
|
||||
{ text: `«${node.annotations[0]}»` } as unknown as ClassMember,
|
||||
0,
|
||||
[]
|
||||
);
|
||||
annotationGroup.style('opacity', '1');
|
||||
}
|
||||
const annotationGroupBBox = annotationGroup.node()!.getBBox();
|
||||
annotationGroupHeight = annotationGroupBBox.height;
|
||||
}
|
||||
|
||||
labelGroup = shapeSvg.insert('g').attr('class', 'label-group text');
|
||||
await addText(labelGroup, node, 0, ['font-weight: bolder']);
|
||||
|
||||
// Determine styling based on annotations
|
||||
let labelStyles = [''];
|
||||
let labelClass = '';
|
||||
if (node.annotations && node.annotations.length > 0) {
|
||||
const annotation = node.annotations[0].toLowerCase();
|
||||
switch (annotation) {
|
||||
case 'abstract':
|
||||
labelClass = 'abstract';
|
||||
labelStyles = [];
|
||||
break;
|
||||
case 'enumeration':
|
||||
labelClass = 'enumeration';
|
||||
labelStyles = [];
|
||||
break;
|
||||
case 'interface':
|
||||
labelClass = 'interface';
|
||||
labelStyles = [];
|
||||
break;
|
||||
default:
|
||||
labelClass = '';
|
||||
labelStyles = [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Apply the CSS class to the label group
|
||||
labelGroup.attr('class', `label-group text classTitle ${labelClass}`);
|
||||
|
||||
await addText(labelGroup, node, 0, labelStyles);
|
||||
const labelGroupBBox = labelGroup.node()!.getBBox();
|
||||
labelGroupHeight = labelGroupBBox.height;
|
||||
|
||||
@@ -71,7 +113,7 @@ export async function textHelper<T extends SVGGraphicsElement>(
|
||||
// Center annotation
|
||||
if (annotationGroup !== null) {
|
||||
const annotationGroupBBox = annotationGroup.node()!.getBBox();
|
||||
annotationGroup.attr('transform', `translate(${-annotationGroupBBox.width / 2})`);
|
||||
annotationGroup.attr('transform', `translate(${-annotationGroupBBox.width / 2}, 0)`);
|
||||
}
|
||||
|
||||
// Adjust label
|
||||
|
@@ -31,7 +31,7 @@ const getStyles = (options) =>
|
||||
}
|
||||
|
||||
.classTitle {
|
||||
font-weight: bolder;
|
||||
font-weight: normal;
|
||||
}
|
||||
.node rect,
|
||||
.node circle,
|
||||
@@ -148,6 +148,20 @@ g.classGroup line {
|
||||
stroke: ${options.lineColor} !important;
|
||||
stroke-width: 1;
|
||||
}
|
||||
|
||||
.classTitle.abstract {
|
||||
font-style: italic;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.classTitle.enumeration {
|
||||
text-decoration: underline;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.classTitle.interface {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.edgeTerminals {
|
||||
font-size: 11px;
|
||||
|
81
pnpm-lock.yaml
generated
81
pnpm-lock.yaml
generated
@@ -269,8 +269,8 @@ importers:
|
||||
specifier: ^4.17.21
|
||||
version: 4.17.21
|
||||
marked:
|
||||
specifier: ^15.0.7
|
||||
version: 15.0.12
|
||||
specifier: ^16.0.0
|
||||
version: 16.2.1
|
||||
roughjs:
|
||||
specifier: ^4.6.6
|
||||
version: 4.6.6(patch_hash=3543d47108cb41b68ec6a671c0e1f9d0cfe2ce524fea5b0992511ae84c3c6b64)
|
||||
@@ -7445,9 +7445,9 @@ packages:
|
||||
markdown-table@3.0.4:
|
||||
resolution: {integrity: sha512-wiYz4+JrLyb/DqW2hkFJxP7Vd7JuTDm77fvbM8VfEQdmSMqcImWeeRbHwZjBjIFki/VaMK2BhFi7oUUZeM5bqw==}
|
||||
|
||||
marked@15.0.12:
|
||||
resolution: {integrity: sha512-8dD6FusOQSrpv9Z1rdNMdlSgQOIP880DHqnohobOmYLElGEqAL/JvxvuxZO16r4HtjTlfPRDC1hbvxC9dPN2nA==}
|
||||
engines: {node: '>= 18'}
|
||||
marked@16.2.1:
|
||||
resolution: {integrity: sha512-r3UrXED9lMlHF97jJByry90cwrZBBvZmjG1L68oYfuPMW+uDTnuMbyJDymCWwbTE+f+3LhpNDKfpR3a3saFyjA==}
|
||||
engines: {node: '>= 20'}
|
||||
hasBin: true
|
||||
|
||||
marked@4.3.0:
|
||||
@@ -14430,14 +14430,6 @@ snapshots:
|
||||
optionalDependencies:
|
||||
vite: 6.1.1(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0)
|
||||
|
||||
'@unocss/astro@66.4.2(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))':
|
||||
dependencies:
|
||||
'@unocss/core': 66.4.2
|
||||
'@unocss/reset': 66.4.2
|
||||
'@unocss/vite': 66.4.2(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))
|
||||
optionalDependencies:
|
||||
vite: 6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0)
|
||||
|
||||
'@unocss/cli@66.4.2':
|
||||
dependencies:
|
||||
'@ampproject/remapping': 2.3.0
|
||||
@@ -14582,19 +14574,6 @@ snapshots:
|
||||
unplugin-utils: 0.2.4
|
||||
vite: 6.1.1(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0)
|
||||
|
||||
'@unocss/vite@66.4.2(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))':
|
||||
dependencies:
|
||||
'@ampproject/remapping': 2.3.0
|
||||
'@unocss/config': 66.4.2
|
||||
'@unocss/core': 66.4.2
|
||||
'@unocss/inspector': 66.4.2
|
||||
chokidar: 3.6.0
|
||||
magic-string: 0.30.17
|
||||
pathe: 2.0.3
|
||||
tinyglobby: 0.2.14
|
||||
unplugin-utils: 0.2.4
|
||||
vite: 6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0)
|
||||
|
||||
'@unrs/resolver-binding-android-arm-eabi@1.11.1':
|
||||
optional: true
|
||||
|
||||
@@ -14658,10 +14637,6 @@ snapshots:
|
||||
dependencies:
|
||||
vite-plugin-pwa: 1.0.0(vite@6.1.1(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))(workbox-build@7.1.1(@types/babel__core@7.20.5))(workbox-window@7.3.0)
|
||||
|
||||
'@vite-pwa/vitepress@1.0.0(vite-plugin-pwa@1.0.0(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))(workbox-build@7.1.1(@types/babel__core@7.20.5))(workbox-window@7.3.0))':
|
||||
dependencies:
|
||||
vite-plugin-pwa: 1.0.0(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))(workbox-build@7.1.1(@types/babel__core@7.20.5))(workbox-window@7.3.0)
|
||||
|
||||
'@vitejs/plugin-vue@5.2.1(vite@5.4.19(@types/node@22.13.5)(terser@5.39.0))(vue@3.5.13(typescript@5.7.3))':
|
||||
dependencies:
|
||||
vite: 5.4.19(@types/node@22.13.5)(terser@5.39.0)
|
||||
@@ -14673,12 +14648,6 @@ snapshots:
|
||||
vite: 6.1.1(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0)
|
||||
vue: 3.5.13(typescript@5.7.3)
|
||||
|
||||
'@vitejs/plugin-vue@6.0.0(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))(vue@3.5.13(typescript@5.7.3))':
|
||||
dependencies:
|
||||
'@rolldown/pluginutils': 1.0.0-beta.19
|
||||
vite: 6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0)
|
||||
vue: 3.5.13(typescript@5.7.3)
|
||||
|
||||
'@vitest/coverage-v8@3.0.6(vitest@3.0.6)':
|
||||
dependencies:
|
||||
'@ampproject/remapping': 2.3.0
|
||||
@@ -19176,7 +19145,7 @@ snapshots:
|
||||
|
||||
markdown-table@3.0.4: {}
|
||||
|
||||
marked@15.0.12: {}
|
||||
marked@16.2.1: {}
|
||||
|
||||
marked@4.3.0: {}
|
||||
|
||||
@@ -21843,33 +21812,6 @@ snapshots:
|
||||
- postcss
|
||||
- supports-color
|
||||
|
||||
unocss@66.4.2(postcss@8.5.6)(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0)):
|
||||
dependencies:
|
||||
'@unocss/astro': 66.4.2(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))
|
||||
'@unocss/cli': 66.4.2
|
||||
'@unocss/core': 66.4.2
|
||||
'@unocss/postcss': 66.4.2(postcss@8.5.6)
|
||||
'@unocss/preset-attributify': 66.4.2
|
||||
'@unocss/preset-icons': 66.4.2
|
||||
'@unocss/preset-mini': 66.4.2
|
||||
'@unocss/preset-tagify': 66.4.2
|
||||
'@unocss/preset-typography': 66.4.2
|
||||
'@unocss/preset-uno': 66.4.2
|
||||
'@unocss/preset-web-fonts': 66.4.2
|
||||
'@unocss/preset-wind': 66.4.2
|
||||
'@unocss/preset-wind3': 66.4.2
|
||||
'@unocss/preset-wind4': 66.4.2
|
||||
'@unocss/transformer-attributify-jsx': 66.4.2
|
||||
'@unocss/transformer-compile-class': 66.4.2
|
||||
'@unocss/transformer-directives': 66.4.2
|
||||
'@unocss/transformer-variant-group': 66.4.2
|
||||
'@unocss/vite': 66.4.2(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))
|
||||
optionalDependencies:
|
||||
vite: 6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0)
|
||||
transitivePeerDependencies:
|
||||
- postcss
|
||||
- supports-color
|
||||
|
||||
unpipe@1.0.0: {}
|
||||
|
||||
unplugin-utils@0.2.4:
|
||||
@@ -22024,17 +21966,6 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
vite-plugin-pwa@1.0.0(vite@6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0))(workbox-build@7.1.1(@types/babel__core@7.20.5))(workbox-window@7.3.0):
|
||||
dependencies:
|
||||
debug: 4.4.0
|
||||
pretty-bytes: 6.1.1
|
||||
tinyglobby: 0.2.12
|
||||
vite: 6.1.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.39.0)(tsx@4.19.3)(yaml@2.8.0)
|
||||
workbox-build: 7.1.1(@types/babel__core@7.20.5)
|
||||
workbox-window: 7.3.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
vite@5.4.19(@types/node@22.13.5)(terser@5.39.0):
|
||||
dependencies:
|
||||
esbuild: 0.21.5
|
||||
|
Reference in New Issue
Block a user