update
Some checks failed
Deploy / deploy (build, debian, 22, /root/OJDeploy/data/clientnext) (push) Has been cancelled
Deploy / deploy (build:staging, school, 8822, /root/OJ/data/dist) (push) Has been cancelled

This commit is contained in:
2026-05-07 06:54:51 -06:00
parent 5aa852acbc
commit 92cd3cd15e
2 changed files with 68 additions and 49 deletions

View File

@@ -72,19 +72,19 @@ export function useMermaidConverter() {
// 添加样式定义来区分不同类型的节点 // 添加样式定义来区分不同类型的节点
mermaid += "\n" mermaid += "\n"
mermaid += mermaid +=
" classDef startNode fill:#dcfce7,stroke:#16a34a,stroke-width:2.5px,color:#0f172a\n" " classDef startNode fill:#e2ebe4,stroke:#527557,stroke-width:2px,color:#1e2a35\n"
mermaid += mermaid +=
" classDef endNode fill:#fee2e2,stroke:#dc2626,stroke-width:2.5px,color:#0f172a\n" " classDef endNode fill:#ebe2e2,stroke:#755252,stroke-width:2px,color:#1e2a35\n"
mermaid += mermaid +=
" classDef input fill:#dbeafe,stroke:#2563eb,stroke-width:2.5px,color:#0f172a\n" " classDef input fill:#e2e6eb,stroke:#526075,stroke-width:2px,color:#1e2a35\n"
mermaid += mermaid +=
" classDef output fill:#ede9fe,stroke:#7c3aed,stroke-width:2.5px,color:#0f172a\n" " classDef output fill:#e8e2eb,stroke:#665275,stroke-width:2px,color:#1e2a35\n"
mermaid += mermaid +=
" classDef process fill:#f0f9ff,stroke:#0284c7,stroke-width:2.5px,color:#0f172a\n" " classDef process fill:#e2e9eb,stroke:#526b75,stroke-width:2px,color:#1e2a35\n"
mermaid += mermaid +=
" classDef decision fill:#fef3c7,stroke:#d97706,stroke-width:2.5px,color:#0f172a\n" " classDef decision fill:#ebe7e2,stroke:#75695a,stroke-width:2px,color:#1e2a35\n"
mermaid += mermaid +=
" classDef loop fill:#fae8ff,stroke:#c026d3,stroke-width:2.5px,color:#0f172a\n" " classDef loop fill:#e7e2eb,stroke:#63527a,stroke-width:2px,color:#1e2a35\n"
mermaid += "\n" mermaid += "\n"
// 为节点应用样式 // 为节点应用样式

View File

@@ -1,19 +1,19 @@
import { getRandomId } from "utils/functions" import { getRandomId } from "utils/functions"
const mermaidThemeVariables = { const mermaidThemeVariables = {
primaryColor: "#e0f2fe", primaryColor: "#e4e8eb",
primaryTextColor: "#0f172a", primaryTextColor: "#1e2a35",
primaryBorderColor: "#0284c7", primaryBorderColor: "#6b8096",
lineColor: "#64748b", lineColor: "#7a8a96",
secondaryColor: "#f5f3ff", secondaryColor: "#e8e4eb",
tertiaryColor: "#ecfdf5", tertiaryColor: "#e4ebe6",
background: "#ffffff", background: "#ffffff",
mainBkg: "#f8fafc", mainBkg: "#f5f5f4",
secondBkg: "#eef2ff", secondBkg: "#f0f0ef",
tertiaryBkg: "#f0fdfa", tertiaryBkg: "#f0f2f0",
nodeBorder: "#2563eb", nodeBorder: "#6b8096",
clusterBkg: "#f8fafc", clusterBkg: "#f5f5f4",
clusterBorder: "#cbd5e1", clusterBorder: "#c8cdd2",
edgeLabelBackground: "#ffffff", edgeLabelBackground: "#ffffff",
fontFamily: fontFamily:
'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif', 'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
@@ -43,8 +43,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node ellipse, .oj-mermaid-flowchart g.node ellipse,
.oj-mermaid-flowchart g.node circle, .oj-mermaid-flowchart g.node circle,
.oj-mermaid-flowchart g.node path { .oj-mermaid-flowchart g.node path {
stroke-width: 2.5px !important; stroke-width: 2px !important;
filter: drop-shadow(0 6px 12px rgba(15, 23, 42, 0.12)); filter: drop-shadow(0 3px 6px rgba(15, 23, 42, 0.07));
} }
.oj-mermaid-flowchart g.node.startNode rect, .oj-mermaid-flowchart g.node.startNode rect,
@@ -57,8 +57,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.startEnd ellipse, .oj-mermaid-flowchart g.node.startEnd ellipse,
.oj-mermaid-flowchart g.node.startEnd circle, .oj-mermaid-flowchart g.node.startEnd circle,
.oj-mermaid-flowchart g.node.startEnd path { .oj-mermaid-flowchart g.node.startEnd path {
fill: #dcfce7 !important; fill: #e2ebe4 !important;
stroke: #16a34a !important; stroke: #527557 !important;
} }
.oj-mermaid-flowchart g.node.endNode rect, .oj-mermaid-flowchart g.node.endNode rect,
@@ -66,8 +66,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.endNode ellipse, .oj-mermaid-flowchart g.node.endNode ellipse,
.oj-mermaid-flowchart g.node.endNode circle, .oj-mermaid-flowchart g.node.endNode circle,
.oj-mermaid-flowchart g.node.endNode path { .oj-mermaid-flowchart g.node.endNode path {
fill: #fee2e2 !important; fill: #ebe2e2 !important;
stroke: #dc2626 !important; stroke: #755252 !important;
} }
.oj-mermaid-flowchart g.node.input rect, .oj-mermaid-flowchart g.node.input rect,
@@ -75,8 +75,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.input ellipse, .oj-mermaid-flowchart g.node.input ellipse,
.oj-mermaid-flowchart g.node.input circle, .oj-mermaid-flowchart g.node.input circle,
.oj-mermaid-flowchart g.node.input path { .oj-mermaid-flowchart g.node.input path {
fill: #dbeafe !important; fill: #e2e6eb !important;
stroke: #2563eb !important; stroke: #526075 !important;
} }
.oj-mermaid-flowchart g.node.output rect, .oj-mermaid-flowchart g.node.output rect,
@@ -84,8 +84,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.output ellipse, .oj-mermaid-flowchart g.node.output ellipse,
.oj-mermaid-flowchart g.node.output circle, .oj-mermaid-flowchart g.node.output circle,
.oj-mermaid-flowchart g.node.output path { .oj-mermaid-flowchart g.node.output path {
fill: #ede9fe !important; fill: #e8e2eb !important;
stroke: #7c3aed !important; stroke: #665275 !important;
} }
.oj-mermaid-flowchart g.node.process rect, .oj-mermaid-flowchart g.node.process rect,
@@ -93,8 +93,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.process ellipse, .oj-mermaid-flowchart g.node.process ellipse,
.oj-mermaid-flowchart g.node.process circle, .oj-mermaid-flowchart g.node.process circle,
.oj-mermaid-flowchart g.node.process path { .oj-mermaid-flowchart g.node.process path {
fill: #f0f9ff !important; fill: #e2e9eb !important;
stroke: #0284c7 !important; stroke: #526b75 !important;
} }
.oj-mermaid-flowchart g.node.decision rect, .oj-mermaid-flowchart g.node.decision rect,
@@ -102,8 +102,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.decision ellipse, .oj-mermaid-flowchart g.node.decision ellipse,
.oj-mermaid-flowchart g.node.decision circle, .oj-mermaid-flowchart g.node.decision circle,
.oj-mermaid-flowchart g.node.decision path { .oj-mermaid-flowchart g.node.decision path {
fill: #fef3c7 !important; fill: #ebe7e2 !important;
stroke: #d97706 !important; stroke: #75695a !important;
} }
.oj-mermaid-flowchart g.node.loop rect, .oj-mermaid-flowchart g.node.loop rect,
@@ -111,8 +111,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.loop ellipse, .oj-mermaid-flowchart g.node.loop ellipse,
.oj-mermaid-flowchart g.node.loop circle, .oj-mermaid-flowchart g.node.loop circle,
.oj-mermaid-flowchart g.node.loop path { .oj-mermaid-flowchart g.node.loop path {
fill: #fae8ff !important; fill: #e7e2eb !important;
stroke: #c026d3 !important; stroke: #63527a !important;
} }
.oj-mermaid-flowchart g.node.oj-node-palette-0 rect, .oj-mermaid-flowchart g.node.oj-node-palette-0 rect,
@@ -120,8 +120,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.oj-node-palette-0 ellipse, .oj-mermaid-flowchart g.node.oj-node-palette-0 ellipse,
.oj-mermaid-flowchart g.node.oj-node-palette-0 circle, .oj-mermaid-flowchart g.node.oj-node-palette-0 circle,
.oj-mermaid-flowchart g.node.oj-node-palette-0 path { .oj-mermaid-flowchart g.node.oj-node-palette-0 path {
fill: #dbeafe !important; fill: #e2e6eb !important;
stroke: #2563eb !important; stroke: #526075 !important;
} }
.oj-mermaid-flowchart g.node.oj-node-palette-1 rect, .oj-mermaid-flowchart g.node.oj-node-palette-1 rect,
@@ -129,8 +129,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.oj-node-palette-1 ellipse, .oj-mermaid-flowchart g.node.oj-node-palette-1 ellipse,
.oj-mermaid-flowchart g.node.oj-node-palette-1 circle, .oj-mermaid-flowchart g.node.oj-node-palette-1 circle,
.oj-mermaid-flowchart g.node.oj-node-palette-1 path { .oj-mermaid-flowchart g.node.oj-node-palette-1 path {
fill: #ccfbf1 !important; fill: #e2ebe6 !important;
stroke: #0d9488 !important; stroke: #527563 !important;
} }
.oj-mermaid-flowchart g.node.oj-node-palette-2 rect, .oj-mermaid-flowchart g.node.oj-node-palette-2 rect,
@@ -138,8 +138,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.oj-node-palette-2 ellipse, .oj-mermaid-flowchart g.node.oj-node-palette-2 ellipse,
.oj-mermaid-flowchart g.node.oj-node-palette-2 circle, .oj-mermaid-flowchart g.node.oj-node-palette-2 circle,
.oj-mermaid-flowchart g.node.oj-node-palette-2 path { .oj-mermaid-flowchart g.node.oj-node-palette-2 path {
fill: #ede9fe !important; fill: #e8e2eb !important;
stroke: #7c3aed !important; stroke: #665275 !important;
} }
.oj-mermaid-flowchart g.node.oj-node-palette-3 rect, .oj-mermaid-flowchart g.node.oj-node-palette-3 rect,
@@ -147,8 +147,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.oj-node-palette-3 ellipse, .oj-mermaid-flowchart g.node.oj-node-palette-3 ellipse,
.oj-mermaid-flowchart g.node.oj-node-palette-3 circle, .oj-mermaid-flowchart g.node.oj-node-palette-3 circle,
.oj-mermaid-flowchart g.node.oj-node-palette-3 path { .oj-mermaid-flowchart g.node.oj-node-palette-3 path {
fill: #ffe4e6 !important; fill: #ebe2e6 !important;
stroke: #e11d48 !important; stroke: #75606a !important;
} }
.oj-mermaid-flowchart g.node.oj-node-palette-4 rect, .oj-mermaid-flowchart g.node.oj-node-palette-4 rect,
@@ -156,8 +156,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.oj-node-palette-4 ellipse, .oj-mermaid-flowchart g.node.oj-node-palette-4 ellipse,
.oj-mermaid-flowchart g.node.oj-node-palette-4 circle, .oj-mermaid-flowchart g.node.oj-node-palette-4 circle,
.oj-mermaid-flowchart g.node.oj-node-palette-4 path { .oj-mermaid-flowchart g.node.oj-node-palette-4 path {
fill: #fef3c7 !important; fill: #ebe7e2 !important;
stroke: #d97706 !important; stroke: #75695a !important;
} }
.oj-mermaid-flowchart g.node.oj-node-palette-5 rect, .oj-mermaid-flowchart g.node.oj-node-palette-5 rect,
@@ -165,8 +165,8 @@ const mermaidDisplayStyle = `
.oj-mermaid-flowchart g.node.oj-node-palette-5 ellipse, .oj-mermaid-flowchart g.node.oj-node-palette-5 ellipse,
.oj-mermaid-flowchart g.node.oj-node-palette-5 circle, .oj-mermaid-flowchart g.node.oj-node-palette-5 circle,
.oj-mermaid-flowchart g.node.oj-node-palette-5 path { .oj-mermaid-flowchart g.node.oj-node-palette-5 path {
fill: #dcfce7 !important; fill: #e4ebe2 !important;
stroke: #16a34a !important; stroke: #5a7552 !important;
} }
.oj-mermaid-flowchart g.node .label, .oj-mermaid-flowchart g.node .label,
@@ -206,6 +206,15 @@ const mermaidDisplayStyle = `
const svgNamespace = "http://www.w3.org/2000/svg" const svgNamespace = "http://www.w3.org/2000/svg"
function getNodeLabel(node: SVGGElement): string {
const el =
node.querySelector(".nodeLabel p") ||
node.querySelector(".nodeLabel") ||
node.querySelector(".label span") ||
node.querySelector(".label")
return el?.textContent?.trim() ?? ""
}
function applyFlowchartDisplayStyle(container: HTMLElement) { function applyFlowchartDisplayStyle(container: HTMLElement) {
container.classList.add("oj-mermaid-surface") container.classList.add("oj-mermaid-surface")
@@ -215,12 +224,22 @@ function applyFlowchartDisplayStyle(container: HTMLElement) {
svg.classList.add("oj-mermaid-flowchart") svg.classList.add("oj-mermaid-flowchart")
const nodes = Array.from(svg.querySelectorAll<SVGGElement>("g.node")) const nodes = Array.from(svg.querySelectorAll<SVGGElement>("g.node"))
nodes.forEach((node, index) => {
// Assign palette indices by label so same label → same color, different labels → different colors
const labelPaletteMap = new Map<string, number>()
let paletteCounter = 0
nodes.forEach((node) => {
const hasSemanticClass = semanticNodeClasses.some((className) => const hasSemanticClass = semanticNodeClasses.some((className) =>
node.classList.contains(className), node.classList.contains(className),
) )
if (!hasSemanticClass) { if (!hasSemanticClass) {
node.classList.add(`oj-node-palette-${index % 6}`) const label = getNodeLabel(node)
if (!labelPaletteMap.has(label)) {
labelPaletteMap.set(label, paletteCounter % 6)
paletteCounter++
}
node.classList.add(`oj-node-palette-${labelPaletteMap.get(label)}`)
} }
}) })