AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
feat(diagram): keep flowchart steps uniform and edges straight
tianma-ife7a933bd7f2b
diff --git a/apps/web/src/components/DiagramEditorPane.test.mjs b/apps/web/src/components/DiagramEditorPane.test.mjsindex 162e4a21..6e115576 100644--- a/apps/web/src/components/DiagramEditorPane.test.mjs+++ b/apps/web/src/components/DiagramEditorPane.test.mjs@@ -165,7 +165,9 @@ describe("diagram editor canvas surface", () => {expect(source).toContain('{ fill: "none" }');expect(source).toContain('if (kind !== "mind-map") edge.attr("line/fill", "none")');expect(source).toContain("FLOWCHART_EDGE_ROUTER");- expect(source).toContain('showTheme={document.kind !== "flowchart"}');+ expect(source).toContain("applyFlowchartEdgePorts(graph)");+ expect(source).toContain("flowchartEdgeIsStraight");+ expect(source).toContain('showTheme={document.kind === "mind-map"}');expect(toolbarSource).toContain("showTheme = true");expect(source).toContain("maxScale: policy.maxScale");expect(source).not.toContain("minScale: policy.minScale");@@ -175,6 +177,10 @@ describe("diagram editor canvas surface", () => {expect(source).toContain("bindDiagramScrollerFit(graph)");expect(source).toContain("applyDiagramScrollerFitOptions(");expect(source).toContain("diagramNodeBounds(graph)");+ expect(source).toContain("graph.scale().sx < policy.minScale");+ expect(source).toContain("readFlowchart(graph, document, container)");+ expect(source).toContain("scroller?.container.clientHeight");+ expect(source).toContain("graph.centerPoint(box.x + box.width / 2, box.y + viewportHeight / 2 - 48)");expect(source).toContain("graph.zoomToRect(bounds, { padding, maxScale: policy.maxScale })");expect(source).toContain("getDiagramLayoutViewport(document.kind)");expect(source).toContain("fitDiagramContent(graph, document, containerRef.current);");@@ -248,9 +254,9 @@ describe("diagram editor canvas surface", () => {expect(source).toContain("parent.addChild(node)");expect(source).toContain("updateSelectedEdgeLabel");expect(source).toContain('t("diagram.edgeText")');- expect(source).toContain("ARCHITECTURE_NODE_ICONS");- expect(source).toContain('{ tagName: "path", selector: "architectureIcon" }');- expect(source).toContain('shape === "external" ? "7 5"');+ expect(source).toContain("architectureNodeVisual");+ expect(source).toContain("architectureEdgeVisual");+ expect(source).toContain("resolveArchitectureSurface");expect(globalStyles).toContain('[data-diagram-kind="architecture"] .x6-port-body');});@@ -277,9 +283,9 @@ describe("diagram editor canvas surface", () => {expect(source).toContain('options.label ??');expect(source).toContain('resourceIcon: architectureResourceIcon(item)');expect(source).toContain('...(data?.resourceIcon ? { resourceIcon: data.resourceIcon } : {})');- expect(source).toContain('architectureNodeVisuals(node.shape, size, appearance, node.resourceIcon)');+ expect(source).toContain('architectureNodeVisual(node.shape, appearance, size, node.resourceIcon)');expect(source).toContain('inferArchitectureResourceIcon(node.label, t)');- expect(source).toContain('.render({}, null).props.iconNode');+ expect(source).not.toContain('.render({}, null).props.iconNode');expect(source).not.toContain('className="line-clamp-2"');});diff --git a/apps/web/src/components/DiagramEditorPane.tsx b/apps/web/src/components/DiagramEditorPane.tsxindex ab3fed28..d8d8c8a5 100644--- a/apps/web/src/components/DiagramEditorPane.tsx+++ b/apps/web/src/components/DiagramEditorPane.tsx@@ -83,7 +83,14 @@ import {resolveDiagramStructure,resolveDiagramTheme,serializeDiagramDocument,+ architectureEdgeVisual,+ architectureIconOffset,+ architectureNodeVisual,+ isArchitectureNodeShape,+ resolveArchitectureSurface,FLOWCHART_EDGE_ROUTER,+ flowchartEdgeIsStraight,+ flowchartEdgePorts,flowchartNodeVisual,resolveFlowchartSurface,type ArchitectureResourceIcon,@@ -316,11 +323,6 @@ const ARCHITECTURE_LIBRARY_CATEGORIES: Array<{const architectureResourceIcon = (item: ArchitectureLibraryItem) =>item.labelKey.slice("diagram.architectureResources.".length) as ArchitectureResourceIcon;-const ARCHITECTURE_RESOURCE_ICON_COMPONENTS = Object.fromEntries(- ARCHITECTURE_LIBRARY_CATEGORIES.flatMap((category) => category.items)- .map((item) => [architectureResourceIcon(item), item.icon]),-) as Record<ArchitectureResourceIcon, LucideIcon>;-const ARCHITECTURE_LIBRARY_ITEMS = ARCHITECTURE_LIBRARY_CATEGORIES.flatMap((category) => category.items);const inferArchitectureResourceIcon = (@@ -544,7 +546,9 @@ const diagramCanvasColor = (appearance: DiagramAppearance,) => (kind === "flowchart"? resolveFlowchartSurface(appearance).canvas- : resolveDiagramPalette(theme, appearance).canvas);+ : kind === "architecture"+ ? resolveArchitectureSurface(appearance).canvas+ : resolveDiagramPalette(theme, appearance).canvas);const applyDiagramSurface = (graph: Graph,@@ -755,9 +759,12 @@ const nodeEditorState = (const flowchartStyle = !mindRole && (data?.shape === "process" || data?.shape === "decision" || data?.shape === "terminator")? flowchartNodeVisual(data.shape, appearance, node.getSize()): null;+ const architectureStyle = !mindRole && !flowchartStyle && data?.shape && isArchitectureNodeShape(data.shape)+ ? architectureNodeVisual(data.shape, appearance, node.getSize(), data.resourceIcon)+ : null;const attrs = mindStyle? mindStyle.visual- : flowchartStyle ?? nodeAttrs(data?.shape ?? "process", theme, appearance, isRootTopic);+ : flowchartStyle ?? architectureStyle ?? nodeAttrs(data?.shape ?? "process", theme, appearance, isRootTopic);return {nodeId: node.id,originalValue: data?.label ?? "",@@ -769,7 +776,9 @@ const nodeEditorState = (height: Math.max(1, bottomRight.y - topLeft.y),fontSize: (mindRole ? attrs.label.fontSize : data?.shape === "topic" ? 14 : 13) * graph.scale().sx,color: String(attrs.label.fill),- background: String(attrs.body.fill === "transparent" ? resolveDiagramPalette(theme, appearance).canvas : attrs.body.fill),+ background: String(attrs.body.fill === "transparent"+ ? (architectureStyle ? resolveArchitectureSurface(appearance).canvas : resolveDiagramPalette(theme, appearance).canvas)+ : attrs.body.fill),borderColor: String(attrs.body.stroke),};};@@ -782,128 +791,20 @@ const nodeAttrs = () => {const palette = resolveDiagramPalette(theme, appearance);const isTerminator = shape === "terminator";- const isBoundary = shape === "boundary";- const architectureAccent = ARCHITECTURE_NODE_ACCENTS[shape];const isAccent = isRootTopic || isTerminator;- const architectureFill = appearance === "dark" ? palette.nodeFill : `${architectureAccent}12`;- const architectureRadius: Partial<Record<DiagramNodeShape, number>> = {- client: 6,- frontend: 12,- service: 8,- database: 24,- storage: 6,- queue: 18,- security: 16,- external: 28,- };return {body: {- fill: isBoundary ? "transparent" : architectureAccent ? architectureFill : isAccent ? palette.topicFill : palette.nodeFill,- stroke: isBoundary ? palette.nodeStroke : architectureAccent ?? (isAccent ? palette.topicStroke : palette.nodeStroke),- strokeWidth: isBoundary ? 1.5 : isAccent || architectureAccent ? 1.5 : 1,- strokeDasharray: isBoundary || shape === "external" ? "7 5" : undefined,- rx: isTerminator ? 24 : architectureRadius[shape] ?? 11,- ry: isTerminator ? 24 : architectureRadius[shape] ?? 11,+ fill: isAccent ? palette.topicFill : palette.nodeFill,+ stroke: isAccent ? palette.topicStroke : palette.nodeStroke,+ strokeWidth: isAccent ? 1.5 : 1,+ rx: isTerminator ? 24 : 11,+ ry: isTerminator ? 24 : 11,...(shape === "decision" ? { refPoints: "0,10 10,0 20,10 10,20" } : {}),},label: {fill: isAccent ? palette.topicText : palette.nodeText,- fontSize: shape === "topic" ? 14 : isBoundary ? 12 : 13,- fontWeight: isAccent || isBoundary || architectureAccent ? 650 : 500,- ...(isBoundary ? { refX: 18, refY: 22, textAnchor: "start", textVerticalAnchor: "middle" } : {}),- },- };-};--const ARCHITECTURE_NODE_ACCENTS: Partial<Record<DiagramNodeShape, string>> = {- client: "#0891B2",- frontend: "#2563EB",- service: "#16A06E",- database: "#7C3AED",- storage: "#D97706",- queue: "#EA580C",- security: "#E11D48",- external: "#64748B",-};--// Simple 24px pictograms are embedded in the X6 SVG so exports remain self-contained.-const ARCHITECTURE_NODE_ICONS: Partial<Record<DiagramNodeShape, string>> = {- client: "M3 4h18v13H3z M8 21h8 M12 17v4",- frontend: "M3 4h18v16H3z M3 9h18 M7 6.5h.01 M10 6.5h.01",- service: "M4 3h16v7H4z M4 14h16v7H4z M7 6.5h.01 M7 17.5h.01 M16 6.5h2 M16 17.5h2",- database: "M20 6c0 2.2-3.6 4-8 4S4 8.2 4 6s3.6-4 8-4 8 1.8 8 4Z M4 6v6c0 2.2 3.6 4 8 4s8-1.8 8-4V6 M4 12v6c0 2.2 3.6 4 8 4s8-1.8 8-4v-6",- storage: "M4 4h16l2 6v10H2V10z M2 10h20 M17 15h.01",- queue: "M5 6h14 M5 12h14 M5 18h14 M3 6h.01 M3 12h.01 M3 18h.01",- security: "M12 2 20 5v6c0 5.2-3.4 9.2-8 11-4.6-1.8-8-5.8-8-11V5z M9 12l2 2 4-5",- external: "M16 16h3a4 4 0 0 0 .6-8A7 7 0 0 0 6.3 6.4 4.5 4.5 0 0 0 7.5 16H10 M14 4h6v6 M20 4l-8 8",-};--const architectureNodeVisuals = (- shape: DiagramNodeShape,- size: { width: number; height: number },- appearance: DiagramAppearance,- resourceIcon?: ArchitectureResourceIcon,-) => {- const accent = ARCHITECTURE_NODE_ACCENTS[shape] ?? "#64748B";- const iconY = Math.round((size.height - 34) / 2);- const iconComponent = resourceIcon ? ARCHITECTURE_RESOURCE_ICON_COMPONENTS[resourceIcon] : undefined;- const iconNodes = iconComponent- ? (iconComponent as unknown as {- render: (props: Record<string, never>, ref: null) => {- props: { iconNode: Array<[string, Record<string, string>]> };- };- }).render({}, null).props.iconNode- : null;- const iconMarkup = iconNodes?.map(([tagName], index) => ({- tagName,- selector: `architectureIcon${index}`,- })) ?? [{ tagName: "path", selector: "architectureIcon" }];- const iconAttrs = iconNodes- ? Object.fromEntries(iconNodes.map(([, sourceAttrs], index) => {- const { key: _key, ...geometry } = sourceAttrs;- return [`architectureIcon${index}`, {- ...geometry,- transform: `translate(15 ${iconY + 5})`,- fill: "none",- stroke: accent,- strokeWidth: 1.8,- strokeLinecap: "round",- strokeLinejoin: "round",- pointerEvents: "none",- }];- }))- : {- architectureIcon: {- d: ARCHITECTURE_NODE_ICONS[shape],- transform: `translate(15 ${iconY + 5})`,- fill: "none",- stroke: accent,- strokeWidth: 1.8,- strokeLinecap: "round",- strokeLinejoin: "round",- pointerEvents: "none",- },- };- return {- markup: [- { tagName: "rect", selector: "body" },- { tagName: "rect", selector: "iconFrame" },- ...iconMarkup,- { tagName: "text", selector: "label" },- ],- attrs: {- iconFrame: {- x: 10,- y: iconY,- width: 34,- height: 34,- rx: shape === "database" ? 17 : shape === "security" ? 12 : 8,- ry: shape === "database" ? 17 : shape === "security" ? 12 : 8,- fill: appearance === "dark" ? `${accent}30` : `${accent}18`,- stroke: "none",- pointerEvents: "none",- },- ...iconAttrs,+ fontSize: shape === "topic" ? 14 : 13,+ fontWeight: isAccent ? 650 : 500,},};};@@ -924,7 +825,7 @@ const diagramNodePresentation = (const fontSize = 13;const lineHeight = 18;const text = Dom.breakText(node.label, { width: size.width - (kind === "architecture" ? 66 : 24), height: 10000 }, {- fontSize, 'font-size': fontSize, 'font-weight': kind === "architecture" || !node.parentId ? 650 : 500,+ fontSize, 'font-size': fontSize, 'font-weight': kind === "architecture" ? 600 : !node.parentId ? 650 : 500,lineHeight,});return { ...size, height: Math.max(size.height, text.split("\n").length * lineHeight + 16), text };@@ -942,7 +843,7 @@ const refreshNodeLabel = (node: Node, label: string, structure?: DiagramStructurnode.attr("label/text", label);return;}- const kind = shape === "topic" ? "mind-map" : ARCHITECTURE_NODE_ACCENTS[shape] ? "architecture" : "flowchart";+ const kind = shape === "topic" ? "mind-map" : isArchitectureNodeShape(shape) ? "architecture" : "flowchart";const graphNodes = kind === "mind-map" ? node.model?.getNodes() : undefined;const allNodes = graphNodes?.map((item) => ({id: item.id,@@ -954,6 +855,13 @@ const refreshNodeLabel = (node: Node, label: string, structure?: DiagramStructurnode.resize(presentation.width, presentation.height);}node.attr("label/text", presentation.text);+ if (kind === "architecture") {+ const iconY = architectureIconOffset(presentation.height);+ node.attr("iconFrame/y", iconY);+ for (const selector of Object.keys(node.getAttrs()).filter((name) => name.startsWith("architectureIcon"))) {+ node.attr(`${selector}/transform`, `translate(15 ${iconY + 5})`);+ }+ }};const flowPortGroup = (@@ -998,17 +906,20 @@ const nodeMetadata = (? resolveMindMapNodeStyle([node], node.id, palette, theme, appearance, size, structure): null;const flowchartStyle = kind === "flowchart" ? flowchartNodeVisual(node.shape, appearance, size) : null;+ const architectureStyle = kind === "architecture"+ ? architectureNodeVisual(node.shape, appearance, size, node.resourceIcon)+ : null;const visualAttrs = mindStyle? mindStyle.visual- : flowchartStyle ?? nodeAttrs(node.shape, theme, appearance, isRootTopic);+ : flowchartStyle ?? architectureStyle ?? nodeAttrs(node.shape, theme, appearance, isRootTopic);const hasPorts = isConnectableDiagram(kind) && node.shape !== "boundary";- const architectureVisuals = kind === "architecture" && node.shape !== "boundary"- ? architectureNodeVisuals(node.shape, size, appearance, node.resourceIcon)- : null;const flowchartSurface = kind === "flowchart" ? resolveFlowchartSurface(appearance) : null;+ const architectureSurface = kind === "architecture" ? resolveArchitectureSurface(appearance) : null;const portPalette = flowchartSurface? { ...palette, canvas: flowchartSurface.canvas, topicStroke: flowchartSurface.terminator.stroke }- : palette;+ : architectureSurface+ ? { ...palette, canvas: architectureSurface.canvas, topicStroke: architectureSurface.nodes.service.stroke }+ : palette;return {id: node.id,shape: isDecision ? "polygon" : "rect",@@ -1023,17 +934,16 @@ const nodeMetadata = (...(node.parentId ? { parentId: node.parentId } : {}),...(node.resourceIcon ? { resourceIcon: node.resourceIcon } : {}),} satisfies NodeData,- ...(architectureVisuals ? { markup: architectureVisuals.markup } : mindStyle ? { markup: mindMapTopicMarkup(structure, mindStyle.role) } : {}),+ ...(architectureStyle ? { markup: architectureStyle.markup } : mindStyle ? { markup: mindMapTopicMarkup(structure, mindStyle.role) } : {}),attrs: {body: visualAttrs.body,...(mindStyle ? { underline: mindStyle.visual.underline } : {}),label: {...visualAttrs.label,text: diagramNodePresentation(node, kind).text,- lineHeight: mindStyle?.visual.label.lineHeight ?? flowchartStyle?.label.lineHeight ?? 18,- ...(architectureVisuals ? { refX: 54, refY: "50%", textAnchor: "start", textVerticalAnchor: "middle" } : {}),+ lineHeight: mindStyle?.visual.label.lineHeight ?? flowchartStyle?.label.lineHeight ?? architectureStyle?.label.lineHeight ?? 18,},- ...(architectureVisuals?.attrs ?? {}),+ ...(architectureStyle?.attrs ?? {}),},...(hasPorts ? { ports: {groups: {@@ -1054,12 +964,14 @@ const diagramEdgeLabel = (appearance: DiagramAppearance = "light",) => {const flowchart = kind === "flowchart" ? resolveFlowchartSurface(appearance) : null;+ const architecture = kind === "architecture" ? resolveArchitectureSurface(appearance) : null;return {position: { distance: 0.5, offset: kind === "architecture" ? { x: 0, y: -16 } : 0 },attrs: {- label: { text, fill: flowchart?.process.text ?? palette.nodeText, fontSize: 12, lineHeight: 16, textWrap: { width: 140, height: 512 } },+ label: { text, fill: flowchart?.process.text ?? architecture?.nodes.service.text ?? palette.nodeText, fontSize: 12, lineHeight: 16, textWrap: { width: 140, height: 512 } },body: { ref: "label", refWidth: 1, refHeight: 1, refWidth2: 12, refHeight2: 8, refX: -6, refY: -4,- fill: flowchart?.canvas ?? palette.canvas, stroke: flowchart?.process.stroke ?? palette.nodeStroke, strokeWidth: 1, rx: 4, ry: 4 },+ fill: flowchart?.canvas ?? architecture?.canvas ?? palette.canvas,+ stroke: flowchart?.process.stroke ?? architecture?.nodes.service.stroke ?? palette.nodeStroke, strokeWidth: 1, rx: 4, ry: 4 },},};};@@ -1074,11 +986,10 @@ const edgeMetadata = (const edgeKind = edge.kind ?? (kind === "architecture" ? "dependency" : undefined);const mindEdge = kind === "mind-map" ? mindMapEdgeVisual("primary", palette) : null;const flowchartSurface = kind === "flowchart" ? resolveFlowchartSurface(appearance) : null;- const edgeStroke = edgeKind === "data"- ? "#7C3AED"- : edgeKind === "async"- ? "#EA580C"- : mindEdge?.stroke ?? flowchartSurface?.edge ?? palette.flowEdge;+ const architectureEdge = kind === "architecture"+ ? architectureEdgeVisual(edgeKind, appearance, edge.bidirectional)+ : null;+ const edgeStroke = architectureEdge?.stroke ?? mindEdge?.stroke ?? flowchartSurface?.edge ?? palette.flowEdge;return {id: edge.id,source: { cell: edge.source },@@ -1091,10 +1002,12 @@ const edgeMetadata = (attrs: {line: {stroke: edgeStroke,- strokeWidth: mindEdge ? 0.5 : 1.5,- strokeDasharray: edgeKind === "async" ? "7 5" : undefined,- sourceMarker: edge.bidirectional ? { name: "block", width: 8, height: 6 } : null,- targetMarker: kind === "mind-map" ? null : { name: "block", width: 8, height: 6 },+ strokeWidth: architectureEdge?.strokeWidth ?? (mindEdge ? 0.5 : 1.5),+ strokeDasharray: architectureEdge?.strokeDasharray,+ sourceMarker: architectureEdge+ ? architectureEdge.sourceMarker+ : edge.bidirectional ? { name: "block", width: 8, height: 6 } : null,+ targetMarker: kind === "mind-map" ? null : architectureEdge?.targetMarker ?? { name: "block", width: 8, height: 6 },...(mindEdge ? {fill: edgeStroke,strokeLinejoin: "round",@@ -1106,6 +1019,20 @@ const edgeMetadata = (};};+const applyFlowchartEdgePorts = (graph: Graph) => {+ for (const edge of graph.getEdges()) {+ const source = edge.getSourceNode();+ const target = edge.getTargetNode();+ if (!source || !target) continue;+ const sourceBox = { ...source.getPosition(), ...source.getSize() };+ const targetBox = { ...target.getPosition(), ...target.getSize() };+ const ports = flowchartEdgePorts(sourceBox, targetBox);+ edge.setSource({ cell: source.id, port: ports.source });+ edge.setTarget({ cell: target.id, port: ports.target });+ edge.setRouter(flowchartEdgeIsStraight(sourceBox, targetBox) ? { name: "normal" } : FLOWCHART_EDGE_ROUTER);+ }+};+const graphToDocument = (graph: Graph, kind: DiagramDocument["kind"], theme: DiagramTheme, structure?: DiagramStructure): DiagramDocument => ({schemaVersion: kind === "architecture" ? ARCHITECTURE_DIAGRAM_SCHEMA_VERSION : DIAGRAM_SCHEMA_VERSION,kind,@@ -1170,10 +1097,26 @@ const removeGraphSelection = (graph: Graph) => {};+const readFlowchart = (graph: Graph, document: DiagramDocument, container: HTMLElement | null) => {+ if (!document.nodes.length) return;+ const incoming = new Set(document.edges.map((edge) => edge.target));+ const start = document.nodes.find((node) => !incoming.has(node.id)) ?? document.nodes[0];+ const cell = graph.getCellById(start.id);+ if (!cell?.isNode()) return;+ graph.zoomTo(1);+ const box = cell.getBBox();+ const scroller = getDiagramScroller(graph);+ const viewportHeight = scroller?.container.clientHeight+ || container?.clientHeight+ || graph.container.clientHeight+ || 640;+ graph.centerPoint(box.x + box.width / 2, box.y + viewportHeight / 2 - 48);+};+const fitDiagramContent = (graph: Graph,document: DiagramDocument,- _container: HTMLElement | null,+ container: HTMLElement | null,padding = 32,viewport?: DiagramLayoutViewport,) => {@@ -1183,17 +1126,13 @@ const fitDiagramContent = (// Fit every node, including mind-map branches left of the root. Zooming to a// visible subset or to edge paths lets Scroller shrink the paper and clip.graph.zoomToRect(bounds, { padding, maxScale: policy.maxScale });-};--const readFlowchart = (graph: Graph, document: DiagramDocument, container: HTMLElement | null) => {- if (!container || !document.nodes.length) return;- const incoming = new Set(document.edges.map((edge) => edge.target));- const start = document.nodes.find((node) => !incoming.has(node.id)) ?? document.nodes[0];- const cell = graph.getCellById(start.id);- if (!cell?.isNode()) return;- graph.zoomTo(1);- const bounds = cell.getBBox();- graph.translate(container.clientWidth / 2 - bounds.center.x, 48 - bounds.y);+ if (+ document.kind === "flowchart"+ && policy.minScale != null+ && graph.scale().sx < policy.minScale+ ) {+ readFlowchart(graph, document, container);+ }};const applyMindMapHierarchy = (graph: Graph, theme: DiagramTheme, appearance: DiagramAppearance, structure?: DiagramStructure) => {@@ -1261,30 +1200,44 @@ const applyGraphPalette = (for (const node of graph.getNodes()) {const data = node.getData<NodeData>();const shape = data?.shape ?? "process";+ refreshNodeLabel(node, data?.label ?? "", structure);const flowchartStyle = kind === "flowchart" ? flowchartNodeVisual(shape, appearance, node.getSize()) : null;- const attrs = flowchartStyle ?? nodeAttrs(shape, theme, appearance, shape === "topic" && !data?.parentId);+ const architectureStyle = kind === "architecture"+ ? architectureNodeVisual(shape, appearance, node.getSize(), data?.resourceIcon)+ : null;+ const attrs = flowchartStyle+ ?? (architectureStyle ? { body: architectureStyle.body, label: architectureStyle.label } : null)+ ?? nodeAttrs(shape, theme, appearance, shape === "topic" && !data?.parentId);node.attr("body", attrs.body);- node.attr("label", attrs.label);- refreshNodeLabel(node, data?.label ?? "", structure);- if (kind === "architecture" && shape !== "boundary") {- const architectureVisuals = architectureNodeVisuals(shape, node.getSize(), appearance, data?.resourceIcon);- for (const [selector, selectorAttrs] of Object.entries(architectureVisuals.attrs)) {- node.attr(selector, selectorAttrs);+ node.attr("label", { ...attrs.label, text: node.attr("label/text") ?? data?.label ?? "" });+ if (architectureStyle) {+ for (const [selector, selectorAttrs] of Object.entries(architectureStyle.attrs)) {+ node.attr(selector, selectorAttrs as Record<string, string | number | undefined>);}}const flowchartSurface = kind === "flowchart" ? resolveFlowchartSurface(appearance) : null;+ const architectureSurface = kind === "architecture" ? resolveArchitectureSurface(appearance) : null;for (const port of node.getPorts()) {if (!port.id) continue;node.portProp(port.id, "attrs/circle", {- stroke: flowchartSurface?.terminator.stroke ?? palette.topicStroke,- fill: flowchartSurface?.canvas ?? palette.canvas,+ stroke: flowchartSurface?.terminator.stroke ?? architectureSurface?.nodes.service.stroke ?? palette.topicStroke,+ fill: flowchartSurface?.canvas ?? architectureSurface?.canvas ?? palette.canvas,});}}const flowchartSurface = kind === "flowchart" ? resolveFlowchartSurface(appearance) : null;for (const edge of graph.getEdges()) {const edgeKind = edge.getData<EdgeData>()?.kind;- edge.attr("line/stroke", edgeKind === "data" ? "#7C3AED" : edgeKind === "async" ? "#EA580C" : kind === "mind-map" ? palette.mindMapEdge : flowchartSurface?.edge ?? palette.flowEdge);+ const architectureEdge = kind === "architecture"+ ? architectureEdgeVisual(edgeKind, appearance, edge.getData<EdgeData>()?.bidirectional)+ : null;+ edge.attr("line/stroke", architectureEdge?.stroke ?? (kind === "mind-map" ? palette.mindMapEdge : flowchartSurface?.edge ?? palette.flowEdge));+ if (architectureEdge) {+ edge.attr("line/strokeWidth", architectureEdge.strokeWidth);+ edge.attr("line/strokeDasharray", architectureEdge.strokeDasharray);+ edge.attr("line/sourceMarker", architectureEdge.sourceMarker);+ edge.attr("line/targetMarker", architectureEdge.targetMarker);+ }if (kind !== "mind-map") edge.attr("line/fill", "none");if (edge.getLabels().length > 0) {edge.setLabels(edge.getLabels().map((label) => diagramEdgeLabel(String(label.attrs?.label?.text ?? ""), palette, kind, appearance)));@@ -1651,6 +1604,7 @@ export const DiagramEditorPane = ({}}graph.addEdges(document.edges.map((edge) => edgeMetadata(edge, document.kind, documentTheme, appearance)));+ if (document.kind === "flowchart") applyFlowchartEdgePorts(graph);applyGraphPalette(graph, documentTheme, document.kind, appearance, documentStructure);graph.on("scale", () => setZoomPercent(Math.round(graph.scale().sx * 100)));graph.cleanHistory();@@ -1662,7 +1616,6 @@ export const DiagramEditorPane = ({settleLoadedViewport();graph.once("render:done", settleLoadedViewport);requestAnimationFrame(settleLoadedViewport);- if (document.kind === "flowchart" && graph.scale().sx < 0.8) readFlowchart(graph, document, containerRef.current);const updateHistory = () => setHistoryState({ undo: graph.canUndo(), redo: graph.canRedo() });const markDirty = () => {@@ -1822,6 +1775,7 @@ export const DiagramEditorPane = ({target: { cell: currentCell.id, ...(currentPort ? { port: currentPort } : {}) },});graph.stopBatch("connect");+ if (document.kind === "flowchart") applyFlowchartEdgePorts(graph);return;}if (!currentPoint || !containerRef.current) {@@ -2314,6 +2268,7 @@ export const DiagramEditorPane = ({target: { cell: id, ...(oppositeFlowPort(pending.sourcePort) ? { port: oppositeFlowPort(pending.sourcePort) } : {}) },});graph.stopBatch("quick-create");+ applyFlowchartEdgePorts(graph);settleScroller();graph.cleanSelection();graph.select(node);@@ -2392,6 +2347,7 @@ export const DiagramEditorPane = ({node.resize(geometry.width, geometry.height);}}+ if (document.kind === "flowchart") applyFlowchartEdgePorts(graph);if (document.kind === "mind-map") applyMindMapHierarchy(graph, themeRef.current, appearanceRef.current, structureRef.current);graph.stopBatch("layout");ensureDiagramPaperContainsNodes(graph);@@ -2855,7 +2811,7 @@ export const DiagramEditorPane = ({onExport={exportDiagram}onRedo={() => runHistoryAction("redo")}onThemeChange={applyTheme}- showTheme={document.kind !== "flowchart"}+ showTheme={document.kind === "mind-map"}onStructureChange={document.kind === "mind-map" ? applyStructure : undefined}structure={structure}onUndo={() => runHistoryAction("undo")}diff --git a/apps/web/src/lib/diagram-layout.test.mjs b/apps/web/src/lib/diagram-layout.test.mjsindex 3f58824e..0415442a 100644--- a/apps/web/src/lib/diagram-layout.test.mjs+++ b/apps/web/src/lib/diagram-layout.test.mjs@@ -102,9 +102,9 @@ describe("diagram auto layout", () => {});test("uses compact flowchart nodes with aligned process and terminator centers", () => {- expect(compactFlowchartNodeSize("process")).toEqual({ width: 124, height: 42 });- expect(compactFlowchartNodeSize("terminator")).toEqual({ width: 116, height: 40 });- expect(compactFlowchartNodeSize("decision")).toEqual({ width: 140, height: 72 });+ expect(compactFlowchartNodeSize("process")).toEqual({ width: 176, height: 56 });+ expect(compactFlowchartNodeSize("terminator")).toEqual({ width: 140, height: 44 });+ expect(compactFlowchartNodeSize("decision")).toEqual({ width: 176, height: 80 });});test("balances a large mind map across both sides while keeping descendants with their branch", () => {@@ -209,4 +209,12 @@ describe("diagram auto layout", () => {}expect(result.viewport.minScale).toBe(0.64);});++ test("keeps flowchart viewports at reading size instead of shrinking the whole stack", () => {+ expect(getDiagramLayoutViewport("flowchart")).toEqual({+ anchor: "center",+ maxScale: 1,+ minScale: 0.85,+ });+ });});diff --git a/packages/shared/src/diagram-architecture-icons.ts b/packages/shared/src/diagram-architecture-icons.tsnew file mode 100644index 00000000..d1aff11c--- /dev/null+++ b/packages/shared/src/diagram-architecture-icons.ts@@ -0,0 +1,56 @@+// Frozen Lucide 24px geometry so Web, native X6 viewers, and SVG/PNG+// exports share the same pictograms without bundling React icons.+import type { ArchitectureResourceIcon } from "./diagram";++export type ArchitectureIconElement = {+ tagName: string;+ attrs: Record<string, string>;+};++export const ARCHITECTURE_RESOURCE_ICON_ELEMENTS: Record<ArchitectureResourceIcon, ArchitectureIconElement[]> = {+ client: [{ tagName: "path", attrs: { d: "M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8" } }, { tagName: "path", attrs: { d: "M10 19v-3.96 3.15" } }, { tagName: "path", attrs: { d: "M7 19h5" } }, { tagName: "rect", attrs: { width: "6", height: "10", x: "16", y: "12", rx: "2" } }],+ webApp: [{ tagName: "rect", attrs: { x: "2", y: "4", width: "20", height: "16", rx: "2" } }, { tagName: "path", attrs: { d: "M10 4v4" } }, { tagName: "path", attrs: { d: "M2 8h20" } }, { tagName: "path", attrs: { d: "M6 4v4" } }],+ mobileApp: [{ tagName: "rect", attrs: { width: "14", height: "20", x: "5", y: "2", rx: "2", ry: "2" } }, { tagName: "path", attrs: { d: "M12 18h.01" } }],+ website: [{ tagName: "path", attrs: { d: "M21.54 15H17a2 2 0 0 0-2 2v4.54" } }, { tagName: "path", attrs: { d: "M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17" } }, { tagName: "path", attrs: { d: "M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05" } }, { tagName: "circle", attrs: { cx: "12", cy: "12", r: "10" } }],+ apiClient: [{ tagName: "path", attrs: { d: "m18 16 4-4-4-4" } }, { tagName: "path", attrs: { d: "m6 8-4 4 4 4" } }, { tagName: "path", attrs: { d: "m14.5 4-5 16" } }],+ service: [{ tagName: "rect", attrs: { width: "20", height: "8", x: "2", y: "2", rx: "2", ry: "2" } }, { tagName: "rect", attrs: { width: "20", height: "8", x: "2", y: "14", rx: "2", ry: "2" } }, { tagName: "line", attrs: { x1: "6", x2: "6.01", y1: "6", y2: "6" } }, { tagName: "line", attrs: { x1: "6", x2: "6.01", y1: "18", y2: "18" } }],+ virtualMachine: [{ tagName: "path", attrs: { d: "M12 20v2" } }, { tagName: "path", attrs: { d: "M12 2v2" } }, { tagName: "path", attrs: { d: "M17 20v2" } }, { tagName: "path", attrs: { d: "M17 2v2" } }, { tagName: "path", attrs: { d: "M2 12h2" } }, { tagName: "path", attrs: { d: "M2 17h2" } }, { tagName: "path", attrs: { d: "M2 7h2" } }, { tagName: "path", attrs: { d: "M20 12h2" } }, { tagName: "path", attrs: { d: "M20 17h2" } }, { tagName: "path", attrs: { d: "M20 7h2" } }, { tagName: "path", attrs: { d: "M7 20v2" } }, { tagName: "path", attrs: { d: "M7 2v2" } }, { tagName: "rect", attrs: { x: "4", y: "4", width: "16", height: "16", rx: "2" } }, { tagName: "rect", attrs: { x: "8", y: "8", width: "8", height: "8", rx: "1" } }],+ container: [{ tagName: "path", attrs: { d: "M22 7.7c0-.6-.4-1.2-.8-1.5l-6.3-3.9a1.72 1.72 0 0 0-1.7 0l-10.3 6c-.5.2-.9.8-.9 1.4v6.6c0 .5.4 1.2.8 1.5l6.3 3.9a1.72 1.72 0 0 0 1.7 0l10.3-6c.5-.3.9-1 .9-1.5Z" } }, { tagName: "path", attrs: { d: "M10 21.9V14L2.1 9.1" } }, { tagName: "path", attrs: { d: "m10 14 11.9-6.9" } }, { tagName: "path", attrs: { d: "M14 19.8v-8.1" } }, { tagName: "path", attrs: { d: "M18 17.5V9.4" } }],+ kubernetes: [{ tagName: "path", attrs: { d: "M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2" } }, { tagName: "rect", attrs: { x: "14", y: "2", width: "8", height: "8", rx: "1" } }],+ serverless: [{ tagName: "rect", attrs: { width: "18", height: "18", x: "3", y: "3", rx: "2", ry: "2" } }, { tagName: "path", attrs: { d: "M9 17c2 0 2.8-1 2.8-2.8V10c0-2 1-3.3 3.2-3" } }, { tagName: "path", attrs: { d: "M9 11.2h5.7" } }],+ relationalDatabase: [{ tagName: "ellipse", attrs: { cx: "12", cy: "5", rx: "9", ry: "3" } }, { tagName: "path", attrs: { d: "M3 5V19A9 3 0 0 0 21 19V5" } }, { tagName: "path", attrs: { d: "M3 12A9 3 0 0 0 21 12" } }],+ noSqlDatabase: [{ tagName: "ellipse", attrs: { cx: "12", cy: "5", rx: "9", ry: "3" } }, { tagName: "path", attrs: { d: "M3 5V19A9 3 0 0 0 15 21.84" } }, { tagName: "path", attrs: { d: "M21 5V8" } }, { tagName: "path", attrs: { d: "M21 12L18 17H22L19 22" } }, { tagName: "path", attrs: { d: "M3 12A9 3 0 0 0 14.59 14.87" } }],+ cache: [{ tagName: "path", attrs: { d: "M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z" } }, { tagName: "path", attrs: { d: "M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12" } }, { tagName: "path", attrs: { d: "M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17" } }],+ dataWarehouse: [{ tagName: "path", attrs: { d: "M12 16v5" } }, { tagName: "path", attrs: { d: "M16 14.639V21" } }, { tagName: "path", attrs: { d: "M20 10.656V21" } }, { tagName: "path", attrs: { d: "m22 3-8.646 8.646a.5.5 0 0 1-.708 0L9.354 8.354a.5.5 0 0 0-.707 0L2 15" } }, { tagName: "path", attrs: { d: "M4 18.463V21" } }, { tagName: "path", attrs: { d: "M8 14.656V21" } }],+ searchEngine: [{ tagName: "path", attrs: { d: "m21 21-4.34-4.34" } }, { tagName: "circle", attrs: { cx: "11", cy: "11", r: "8" } }],+ objectStorage: [{ tagName: "path", attrs: { d: "M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z" } }],+ fileStorage: [{ tagName: "path", attrs: { d: "M11 21a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-8a1 1 0 0 1 1-1" } }, { tagName: "path", attrs: { d: "M16 16a1 1 0 0 1-1 1H9a1 1 0 0 1-1-1V8a1 1 0 0 1 1-1" } }, { tagName: "path", attrs: { d: "M21 6a2 2 0 0 0-.586-1.414l-2-2A2 2 0 0 0 17 2h-3a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1z" } }],+ blockStorage: [{ tagName: "path", attrs: { d: "M10 16h.01" } }, { tagName: "path", attrs: { d: "M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z" } }, { tagName: "path", attrs: { d: "M21.946 12.013H2.054" } }, { tagName: "path", attrs: { d: "M6 16h.01" } }],+ backup: [{ tagName: "circle", attrs: { cx: "15", cy: "19", r: "2" } }, { tagName: "path", attrs: { d: "M20.9 19.8A2 2 0 0 0 22 18V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2h5.1" } }, { tagName: "path", attrs: { d: "M15 11v-1" } }, { tagName: "path", attrs: { d: "M15 17v-2" } }],+ cdn: [{ tagName: "path", attrs: { d: "M12 13v8" } }, { tagName: "path", attrs: { d: "M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242" } }, { tagName: "path", attrs: { d: "m8 17 4-4 4 4" } }],+ messageQueue: [{ tagName: "path", attrs: { d: "M15 6a9 9 0 0 0-9 9V3" } }, { tagName: "circle", attrs: { cx: "18", cy: "6", r: "3" } }, { tagName: "circle", attrs: { cx: "6", cy: "18", r: "3" } }],+ eventBus: [{ tagName: "rect", attrs: { width: "8", height: "8", x: "3", y: "3", rx: "2" } }, { tagName: "path", attrs: { d: "M7 11v4a2 2 0 0 0 2 2h4" } }, { tagName: "rect", attrs: { width: "8", height: "8", x: "13", y: "13", rx: "2" } }],+ streamProcessing: [{ tagName: "path", attrs: { d: "M4.9 16.1C1 12.2 1 5.8 4.9 1.9" } }, { tagName: "path", attrs: { d: "M7.8 4.7a6.14 6.14 0 0 0-.8 7.5" } }, { tagName: "circle", attrs: { cx: "12", cy: "9", r: "2" } }, { tagName: "path", attrs: { d: "M16.2 4.8c2 2 2.26 5.11.8 7.47" } }, { tagName: "path", attrs: { d: "M19.1 1.9a9.96 9.96 0 0 1 0 14.1" } }, { tagName: "path", attrs: { d: "M9.5 18h5" } }, { tagName: "path", attrs: { d: "m8 22 4-11 4 11" } }],+ webhook: [{ tagName: "path", attrs: { d: "M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2" } }, { tagName: "path", attrs: { d: "m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06" } }, { tagName: "path", attrs: { d: "m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8" } }],+ serviceMesh: [{ tagName: "path", attrs: { d: "M8 5h13" } }, { tagName: "path", attrs: { d: "M13 12h8" } }, { tagName: "path", attrs: { d: "M13 19h8" } }, { tagName: "path", attrs: { d: "M3 10a2 2 0 0 0 2 2h3" } }, { tagName: "path", attrs: { d: "M3 5v12a2 2 0 0 0 2 2h3" } }],+ apiGateway: [{ tagName: "rect", attrs: { width: "20", height: "8", x: "2", y: "14", rx: "2" } }, { tagName: "path", attrs: { d: "M6.01 18H6" } }, { tagName: "path", attrs: { d: "M10.01 18H10" } }, { tagName: "path", attrs: { d: "M15 10v4" } }, { tagName: "path", attrs: { d: "M17.84 7.17a4 4 0 0 0-5.66 0" } }, { tagName: "path", attrs: { d: "M20.66 4.34a8 8 0 0 0-11.31 0" } }],+ loadBalancer: [{ tagName: "path", attrs: { d: "M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2" } }],+ dns: [{ tagName: "path", attrs: { d: "M21.54 15H17a2 2 0 0 0-2 2v4.54" } }, { tagName: "path", attrs: { d: "M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17" } }, { tagName: "path", attrs: { d: "M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05" } }, { tagName: "circle", attrs: { cx: "12", cy: "12", r: "10" } }],+ vpc: [{ tagName: "rect", attrs: { x: "16", y: "16", width: "6", height: "6", rx: "1" } }, { tagName: "rect", attrs: { x: "2", y: "16", width: "6", height: "6", rx: "1" } }, { tagName: "rect", attrs: { x: "9", y: "2", width: "6", height: "6", rx: "1" } }, { tagName: "path", attrs: { d: "M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3" } }, { tagName: "path", attrs: { d: "M12 12V8" } }],+ subnet: [{ tagName: "path", attrs: { d: "M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z" } }, { tagName: "path", attrs: { d: "M17 21v-2" } }, { tagName: "path", attrs: { d: "M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10" } }, { tagName: "path", attrs: { d: "M21 21v-2" } }, { tagName: "path", attrs: { d: "M3 5V3" } }, { tagName: "path", attrs: { d: "M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z" } }, { tagName: "path", attrs: { d: "M7 5V3" } }],+ vpn: [{ tagName: "path", attrs: { d: "m15 20 3-3h2a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h2l3 3z" } }, { tagName: "path", attrs: { d: "M6 8v1" } }, { tagName: "path", attrs: { d: "M10 8v1" } }, { tagName: "path", attrs: { d: "M14 8v1" } }, { tagName: "path", attrs: { d: "M18 8v1" } }],+ identity: [{ tagName: "path", attrs: { d: "M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z" } }, { tagName: "circle", attrs: { cx: "16.5", cy: "7.5", r: ".5", fill: "currentColor" } }],+ firewall: [{ tagName: "rect", attrs: { width: "18", height: "18", x: "3", y: "3", rx: "2" } }, { tagName: "path", attrs: { d: "M12 9v6" } }, { tagName: "path", attrs: { d: "M16 15v6" } }, { tagName: "path", attrs: { d: "M16 3v6" } }, { tagName: "path", attrs: { d: "M3 15h18" } }, { tagName: "path", attrs: { d: "M3 9h18" } }, { tagName: "path", attrs: { d: "M8 15v6" } }, { tagName: "path", attrs: { d: "M8 3v6" } }],+ waf: [{ tagName: "path", attrs: { d: "M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z" } }, { tagName: "path", attrs: { d: "m9 12 2 2 4-4" } }],+ secretManager: [{ tagName: "circle", attrs: { cx: "12", cy: "16", r: "1" } }, { tagName: "rect", attrs: { x: "3", y: "10", width: "18", height: "12", rx: "2" } }, { tagName: "path", attrs: { d: "M7 10V7a5 5 0 0 1 10 0v3" } }],+ certificate: [{ tagName: "path", attrs: { d: "M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z" } }, { tagName: "path", attrs: { d: "M8 12h.01" } }, { tagName: "path", attrs: { d: "M12 12h.01" } }, { tagName: "path", attrs: { d: "M16 12h.01" } }],+ systemBoundary: [{ tagName: "path", attrs: { d: "M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z" } }, { tagName: "path", attrs: { d: "m3.3 7 8.7 5 8.7-5" } }, { tagName: "path", attrs: { d: "M12 22V12" } }],+ monitoring: [{ tagName: "path", attrs: { d: "m12 14 4-4" } }, { tagName: "path", attrs: { d: "M3.34 19a10 10 0 1 1 17.32 0" } }],+ logging: [{ tagName: "path", attrs: { d: "M16 22h2a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v2.85" } }, { tagName: "path", attrs: { d: "M14 2v5a1 1 0 0 0 1 1h5" } }, { tagName: "path", attrs: { d: "M8 14v2.2l1.6 1" } }, { tagName: "circle", attrs: { cx: "8", cy: "16", r: "6" } }],+ metrics: [{ tagName: "path", attrs: { d: "M12 16v5" } }, { tagName: "path", attrs: { d: "M16 14.639V21" } }, { tagName: "path", attrs: { d: "M20 10.656V21" } }, { tagName: "path", attrs: { d: "m22 3-8.646 8.646a.5.5 0 0 1-.708 0L9.354 8.354a.5.5 0 0 0-.707 0L2 15" } }, { tagName: "path", attrs: { d: "M4 18.463V21" } }, { tagName: "path", attrs: { d: "M8 14.656V21" } }],+ tracing: [{ tagName: "path", attrs: { d: "M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2" } }],+ alerting: [{ tagName: "circle", attrs: { cx: "12", cy: "12", r: "10" } }, { tagName: "line", attrs: { x1: "12", x2: "12", y1: "8", y2: "12" } }, { tagName: "line", attrs: { x1: "12", x2: "12.01", y1: "16", y2: "16" } }],+ saas: [{ tagName: "path", attrs: { d: "m10.852 19.772-.383.924" } }, { tagName: "path", attrs: { d: "m13.148 14.228.383-.923" } }, { tagName: "path", attrs: { d: "M13.148 19.772a3 3 0 1 0-2.296-5.544l-.383-.923" } }, { tagName: "path", attrs: { d: "m13.53 20.696-.382-.924a3 3 0 1 1-2.296-5.544" } }, { tagName: "path", attrs: { d: "m14.772 15.852.923-.383" } }, { tagName: "path", attrs: { d: "m14.772 18.148.923.383" } }, { tagName: "path", attrs: { d: "M4.2 15.1a7 7 0 1 1 9.93-9.858A7 7 0 0 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.2" } }, { tagName: "path", attrs: { d: "m9.228 15.852-.923-.383" } }, { tagName: "path", attrs: { d: "m9.228 18.148-.923.383" } }],+ externalApi: [{ tagName: "path", attrs: { d: "M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2" } }, { tagName: "path", attrs: { d: "m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06" } }, { tagName: "path", attrs: { d: "m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8" } }],+ thirdPartyService: [{ tagName: "path", attrs: { d: "M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z" } }],+};\ No newline at end of filediff --git a/packages/shared/src/diagram-architecture-style.test.mjs b/packages/shared/src/diagram-architecture-style.test.mjsnew file mode 100644index 00000000..dc10ce48--- /dev/null+++ b/packages/shared/src/diagram-architecture-style.test.mjs@@ -0,0 +1,114 @@+import { describe, expect, test } from "bun:test";+import { ARCHITECTURE_RESOURCE_ICONS } from "./diagram.ts";+import { ARCHITECTURE_RESOURCE_ICON_ELEMENTS } from "./diagram-architecture-icons.ts";+import {+ ARCHITECTURE_COMPONENT_SHAPES,+ ARCHITECTURE_SURFACES,+ architectureEdgeVisual,+ architectureIconElements,+ architectureMermaidClassDefs,+ architectureNodeVisual,+ isArchitectureNodeShape,+ resolveArchitectureSurface,+} from "./diagram-architecture-style.ts";++const channel = (value) => {+ const normalized = value / 255;+ return normalized <= 0.04045 ? normalized / 12.92 : ((normalized + 0.055) / 1.055) ** 2.4;+};++const luminance = (hex) => {+ const channels = hex.match(/[a-f\d]{2}/gi).map((value) => channel(Number.parseInt(value, 16)));+ return channels[0] * 0.2126 + channels[1] * 0.7152 + channels[2] * 0.0722;+};++const contrast = (foreground, background) => {+ const values = [luminance(foreground), luminance(background)].sort((left, right) => right - left);+ return (values[0] + 0.05) / (values[1] + 0.05);+};++describe("architecture semantic paint", () => {+ test("keeps every component fill distinct in light and dark", () => {+ for (const appearance of ["light", "dark"]) {+ const fills = ARCHITECTURE_COMPONENT_SHAPES.map((shape) => resolveArchitectureSurface(appearance).nodes[shape].fill);+ expect(new Set(fills).size).toBe(ARCHITECTURE_COMPONENT_SHAPES.length);+ }+ });++ test("preserves hue on dark cards instead of sharing one fill", () => {+ const dark = resolveArchitectureSurface("dark");+ const light = resolveArchitectureSurface("light");+ for (const shape of ARCHITECTURE_COMPONENT_SHAPES) {+ expect(dark.nodes[shape].fill).not.toBe(dark.canvas);+ expect(dark.nodes[shape].fill).not.toBe(light.nodes[shape].fill);+ expect(dark.nodes[shape].fill).toHaveLength(7);+ expect(light.nodes[shape].fill).toHaveLength(7);+ }+ });++ test("keeps node labels readable on their fills", () => {+ for (const appearance of ["light", "dark"]) {+ const surface = ARCHITECTURE_SURFACES[appearance];+ for (const shape of ARCHITECTURE_COMPONENT_SHAPES) {+ expect(contrast(surface.nodes[shape].text, surface.nodes[shape].fill)).toBeGreaterThanOrEqual(4.5);+ }+ expect(contrast(surface.boundaryText, surface.canvas)).toBeGreaterThanOrEqual(4.5);+ }+ });++ test("uses capsules for databases, queues, and external systems", () => {+ const database = architectureNodeVisual("database", "light", { width: 150, height: 72 });+ const queue = architectureNodeVisual("queue", "light", { width: 156, height: 60 });+ const external = architectureNodeVisual("external", "light", { width: 156, height: 64 });+ const service = architectureNodeVisual("service", "light", { width: 156, height: 64 });+ expect(database.body.rx).toBe(36);+ expect(queue.body.rx).toBe(30);+ expect(external.body.rx).toBe(32);+ expect(external.body.strokeDasharray).toBe("7 5");+ expect(service.body.rx).toBe(8);+ expect(service.body.strokeDasharray).toBeUndefined();+ expect(database.label.fontFamily).toContain("Inter");+ });++ test("distinguishes request, data, async, and dependency edges", () => {+ const request = architectureEdgeVisual("request", "light");+ const data = architectureEdgeVisual("data", "light");+ const asyncEdge = architectureEdgeVisual("async", "light");+ const dependency = architectureEdgeVisual("dependency", "light");+ expect(request.stroke).not.toBe(data.stroke);+ expect(request.stroke).not.toBe(dependency.stroke);+ expect(asyncEdge.strokeDasharray).toBe("7 5");+ expect(dependency.strokeWidth).toBeLessThan(request.strokeWidth);+ expect(request.targetMarker).toEqual({ name: "block", width: 8, height: 6 });+ });+});++describe("architecture portable icons", () => {+ test("embeds an SVG path for every resource instead of a unicode glyph", () => {+ expect(Object.keys(ARCHITECTURE_RESOURCE_ICON_ELEMENTS).sort()).toEqual([...ARCHITECTURE_RESOURCE_ICONS].sort());+ for (const icon of ARCHITECTURE_RESOURCE_ICONS) {+ const elements = architectureIconElements(icon, "service");+ expect(elements.length).toBeGreaterThan(0);+ expect(elements.some((element) => element.tagName === "path" || element.tagName === "rect" || element.tagName === "circle" || element.tagName === "ellipse")).toBe(true);+ expect(JSON.stringify(elements)).not.toMatch(/[▣▤⬡ϟ☁]/);+ }+ const container = architectureIconElements("container", "service");+ const database = architectureIconElements("noSqlDatabase", "database");+ expect(container).not.toEqual(database);+ });++ test("falls back to the shape pictogram when a resource icon is missing", () => {+ const fromShape = architectureIconElements(undefined, "database");+ const relational = architectureIconElements("relationalDatabase", "database");+ expect(fromShape).toEqual(relational);+ expect(isArchitectureNodeShape("client")).toBe(true);+ expect(isArchitectureNodeShape("process")).toBe(false);+ });++ test("emits mermaid classDefs from the same light surface", () => {+ const defs = architectureMermaidClassDefs("light").join("\n");+ expect(defs).toContain(`fill:${ARCHITECTURE_SURFACES.light.nodes.database.fill}`);+ expect(defs).toContain("classDef archExternal");+ expect(defs).toContain("stroke-dasharray:6 4");+ });+});diff --git a/packages/shared/src/diagram-architecture-style.ts b/packages/shared/src/diagram-architecture-style.tsnew file mode 100644index 00000000..aa54b1b7--- /dev/null+++ b/packages/shared/src/diagram-architecture-style.ts@@ -0,0 +1,291 @@+import type { ArchitectureResourceIcon, DiagramEdgeKind, DiagramNodeShape } from "./diagram";+import {+ ARCHITECTURE_RESOURCE_ICON_ELEMENTS,+ type ArchitectureIconElement,+} from "./diagram-architecture-icons";++export type { ArchitectureIconElement };++export const ARCHITECTURE_LABEL_FONT =+ 'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';++export const ARCHITECTURE_ICON_SIZE = 24;+export const ARCHITECTURE_ICON_FRAME = 34;+export const ARCHITECTURE_ICON_INSET = 10;++export type ArchitectureAppearance = "light" | "dark";++export type ArchitectureComponentShape = Exclude<+ DiagramNodeShape,+ "topic" | "process" | "decision" | "terminator" | "boundary"+>;++export const ARCHITECTURE_COMPONENT_SHAPES: ArchitectureComponentShape[] = [+ "client", "frontend", "service", "database", "storage", "queue", "security", "external",+];++export const isArchitectureNodeShape = (shape: DiagramNodeShape) =>+ shape === "boundary" || ARCHITECTURE_COMPONENT_SHAPES.includes(shape as ArchitectureComponentShape);++export const ARCHITECTURE_ACCENTS: Record<ArchitectureComponentShape, string> = {+ client: "#0891B2",+ frontend: "#2563EB",+ service: "#16A06E",+ database: "#7C3AED",+ storage: "#D97706",+ queue: "#EA580C",+ security: "#E11D48",+ external: "#64748B",+};++const ARCHITECTURE_SHAPE_RESOURCE: Record<ArchitectureComponentShape, ArchitectureResourceIcon> = {+ client: "client",+ frontend: "webApp",+ service: "service",+ database: "relationalDatabase",+ storage: "objectStorage",+ queue: "messageQueue",+ security: "waf",+ external: "saas",+};++export type ArchitectureShapePaint = {+ fill: string;+ stroke: string;+ text: string;+ accent: string;+ iconFrame: string;+};++export type ArchitectureEdgePaint = {+ stroke: string;+ strokeWidth: number;+ strokeDasharray?: string;+ markerWidth: number;+ markerHeight: number;+};++export type ArchitectureSurface = {+ canvas: string;+ boundaryStroke: string;+ boundaryText: string;+ nodes: Record<ArchitectureComponentShape, ArchitectureShapePaint>;+ edges: Record<Exclude<DiagramEdgeKind, never>, ArchitectureEdgePaint>;+};++export const ARCHITECTURE_SURFACES: Record<ArchitectureAppearance, ArchitectureSurface> = {+ light: {+ canvas: "#F5F8F6",+ boundaryStroke: "#7B8F86",+ boundaryText: "#1C3D31",+ nodes: {+ client: { fill: "#C9E7EE", stroke: "#0A87A6", text: "#134F5D", accent: "#0891B2", iconFrame: "#A1D5E2" },+ frontend: { fill: "#CFDDFB", stroke: "#245DDA", text: "#203A76", accent: "#2563EB", iconFrame: "#ACC4F7" },+ service: { fill: "#CCEADF", stroke: "#169567", text: "#19563E", accent: "#16A06E", iconFrame: "#A6DBC8" },+ database: { fill: "#E2D4FB", stroke: "#7437DC", text: "#472877", accent: "#7C3AED", iconFrame: "#CDB4F8" },+ storage: { fill: "#F7E1C8", stroke: "#CA6F07", text: "#71430F", accent: "#D97706", iconFrame: "#F1CBA0" },+ queue: { fill: "#FADACA", stroke: "#DA530D", text: "#793512", accent: "#EA580C", iconFrame: "#F7C0A3" },+ security: { fill: "#F8CDD7", stroke: "#D11D44", text: "#751B2D", accent: "#E11D48", iconFrame: "#F4A9B9" },+ external: { fill: "#DDE0E5", stroke: "#5E6D82", text: "#3C424B", accent: "#64748B", iconFrame: "#C4CAD3" },+ },+ edges: {+ dependency: { stroke: "#64748B", strokeWidth: 1.2, markerWidth: 7, markerHeight: 5 },+ request: { stroke: "#0F8A5C", strokeWidth: 1.6, markerWidth: 8, markerHeight: 6 },+ data: { stroke: "#7C3AED", strokeWidth: 1.6, markerWidth: 8, markerHeight: 6 },+ async: { stroke: "#EA580C", strokeWidth: 1.5, strokeDasharray: "7 5", markerWidth: 8, markerHeight: 6 },+ },+ },+ dark: {+ canvas: "#101311",+ boundaryStroke: "#5B6F66",+ boundaryText: "#D7F4E8",+ nodes: {+ client: { fill: "#0E363E", stroke: "#3EA9C3", text: "#D3EBF1", accent: "#3EA9C3", iconFrame: "#0C4F5E" },+ frontend: { fill: "#16294E", stroke: "#5585EF", text: "#D8E3FB", accent: "#5585EF", iconFrame: "#1A397A" },+ service: { fill: "#123A2B", stroke: "#49B58E", text: "#D5EEE5", accent: "#49B58E", iconFrame: "#13573E" },+ database: { fill: "#2E1E4F", stroke: "#9965F1", text: "#E7DCFC", accent: "#9965F1", iconFrame: "#44267B" },+ storage: { fill: "#482F0E", stroke: "#E1953D", text: "#F8E7D2", accent: "#E1953D", iconFrame: "#70430C" },+ queue: { fill: "#4D2610", stroke: "#EF7D41", text: "#FBE1D3", accent: "#EF7D41", iconFrame: "#79340F" },+ security: { fill: "#4B1620", stroke: "#E84F70", text: "#FAD6DE", accent: "#E84F70", iconFrame: "#74182B" },+ external: { fill: "#282E33", stroke: "#8693A5", text: "#E3E6EA", accent: "#8693A5", iconFrame: "#38424C" },+ },+ edges: {+ dependency: { stroke: "#94A3B8", strokeWidth: 1.2, markerWidth: 7, markerHeight: 5 },+ request: { stroke: "#4DB58B", strokeWidth: 1.6, markerWidth: 8, markerHeight: 6 },+ data: { stroke: "#A78BFA", strokeWidth: 1.6, markerWidth: 8, markerHeight: 6 },+ async: { stroke: "#FB923C", strokeWidth: 1.5, strokeDasharray: "7 5", markerWidth: 8, markerHeight: 6 },+ },+ },+};++export const resolveArchitectureSurface = (appearance: ArchitectureAppearance = "light") =>+ ARCHITECTURE_SURFACES[appearance];++export const architectureShapePaint = (shape: DiagramNodeShape, appearance: ArchitectureAppearance) => {+ const surface = resolveArchitectureSurface(appearance);+ if (shape === "boundary") {+ return {+ fill: "transparent",+ stroke: surface.boundaryStroke,+ text: surface.boundaryText,+ accent: surface.boundaryStroke,+ iconFrame: "transparent",+ } satisfies ArchitectureShapePaint;+ }+ if (ARCHITECTURE_COMPONENT_SHAPES.includes(shape as ArchitectureComponentShape)) {+ return surface.nodes[shape as ArchitectureComponentShape];+ }+ return surface.nodes.service;+};++const architectureBodyRadius = (shape: DiagramNodeShape, height: number) => {+ if (shape === "database" || shape === "queue" || shape === "external") return Math.round(height / 2);+ if (shape === "security") return 16;+ if (shape === "frontend") return 10;+ if (shape === "service") return 8;+ if (shape === "client" || shape === "storage") return 6;+ return 11;+};++const architectureIconFrameRadius = (shape: DiagramNodeShape) => {+ if (shape === "database" || shape === "external") return 17;+ if (shape === "security") return 12;+ if (shape === "queue") return 10;+ return 8;+};++export const architectureIconOffset = (height: number) =>+ Math.round((height - ARCHITECTURE_ICON_FRAME) / 2);++export const architectureIconElements = (+ resourceIcon: ArchitectureResourceIcon | undefined,+ shape: DiagramNodeShape,+): ArchitectureIconElement[] => {+ const resolved = resourceIcon+ ?? (ARCHITECTURE_COMPONENT_SHAPES.includes(shape as ArchitectureComponentShape)+ ? ARCHITECTURE_SHAPE_RESOURCE[shape as ArchitectureComponentShape]+ : "service");+ return ARCHITECTURE_RESOURCE_ICON_ELEMENTS[resolved] ?? ARCHITECTURE_RESOURCE_ICON_ELEMENTS.service;+};++export const architectureNodeMarkup = (+ resourceIcon: ArchitectureResourceIcon | undefined,+ shape: DiagramNodeShape,+) => {+ if (shape === "boundary") {+ return [+ { tagName: "rect", selector: "body" },+ { tagName: "text", selector: "label" },+ ];+ }+ const icons = architectureIconElements(resourceIcon, shape);+ return [+ { tagName: "rect", selector: "body" },+ { tagName: "rect", selector: "iconFrame" },+ ...icons.map((icon, index) => ({ tagName: icon.tagName, selector: `architectureIcon${index}` })),+ { tagName: "text", selector: "label" },+ ];+};++export const architectureNodeVisual = (+ shape: DiagramNodeShape,+ appearance: ArchitectureAppearance,+ size: { width: number; height: number },+ resourceIcon?: ArchitectureResourceIcon,+) => {+ const paint = architectureShapePaint(shape, appearance);+ const boundary = shape === "boundary";+ const radius = architectureBodyRadius(shape, size.height);+ const iconY = architectureIconOffset(size.height);+ const icons = boundary ? [] : architectureIconElements(resourceIcon, shape);+ const iconAttrs = Object.fromEntries(icons.map((icon, index) => [`architectureIcon${index}`, {+ ...icon.attrs,+ transform: `translate(15 ${iconY + 5})`,+ fill: "none",+ stroke: paint.accent,+ strokeWidth: 2,+ strokeLinecap: "round",+ strokeLinejoin: "round",+ pointerEvents: "none",+ }]));+ return {+ markup: architectureNodeMarkup(resourceIcon, shape),+ body: {+ fill: paint.fill,+ stroke: paint.stroke,+ strokeWidth: 1.5,+ strokeDasharray: boundary || shape === "external" ? "7 5" : undefined,+ rx: radius,+ ry: radius,+ },+ label: {+ fill: paint.text,+ fontSize: boundary ? 12 : 13,+ fontWeight: boundary ? 650 : 600,+ fontFamily: ARCHITECTURE_LABEL_FONT,+ lineHeight: 18,+ ...(boundary+ ? { refX: 18, refY: 22, textAnchor: "start" as const, textVerticalAnchor: "middle" as const }+ : { refX: 54, refY: "50%", textAnchor: "start" as const, textVerticalAnchor: "middle" as const }),+ },+ attrs: boundary ? {} : {+ iconFrame: {+ x: ARCHITECTURE_ICON_INSET,+ y: iconY,+ width: ARCHITECTURE_ICON_FRAME,+ height: ARCHITECTURE_ICON_FRAME,+ rx: architectureIconFrameRadius(shape),+ ry: architectureIconFrameRadius(shape),+ fill: paint.iconFrame,+ stroke: "none",+ pointerEvents: "none",+ },+ ...iconAttrs,+ },+ };+};++export const architectureEdgeVisual = (+ kind: DiagramEdgeKind | undefined,+ appearance: ArchitectureAppearance,+ bidirectional = false,+) => {+ const paint = resolveArchitectureSurface(appearance).edges[kind ?? "dependency"];+ const marker = { name: "block" as const, width: paint.markerWidth, height: paint.markerHeight };+ return {+ stroke: paint.stroke,+ strokeWidth: paint.strokeWidth,+ strokeDasharray: paint.strokeDasharray,+ sourceMarker: bidirectional ? marker : null,+ targetMarker: marker,+ fill: "none" as const,+ };+};++const mermaidClassName: Record<ArchitectureComponentShape, string> = {+ client: "archClient",+ frontend: "archFrontend",+ service: "archService",+ database: "archDatabase",+ storage: "archStorage",+ queue: "archQueue",+ security: "archSecurity",+ external: "archExternal",+};++export const architectureMermaidClassName = (shape: DiagramNodeShape) =>+ mermaidClassName[shape as ArchitectureComponentShape];++export const architectureMermaidClassDefs = (appearance: ArchitectureAppearance = "light") => {+ const surface = resolveArchitectureSurface(appearance);+ return ARCHITECTURE_COMPONENT_SHAPES.map((shape) => {+ const paint = surface.nodes[shape];+ const dashed = shape === "external" ? ",stroke-dasharray:6 4" : "";+ return ` classDef ${mermaidClassName[shape]} fill:${paint.fill},stroke:${paint.stroke},color:${paint.text},stroke-width:1.5px${dashed}`;+ });+};++export const architectureMermaidBoundaryStyle = (appearance: ArchitectureAppearance = "light") => {+ const surface = resolveArchitectureSurface(appearance);+ return `fill:transparent,stroke:${surface.boundaryStroke},stroke-width:1.5px,stroke-dasharray:7 5`;+};diff --git a/packages/shared/src/diagram-flowchart-style.test.mjs b/packages/shared/src/diagram-flowchart-style.test.mjsindex cbd84221..300f919d 100644--- a/packages/shared/src/diagram-flowchart-style.test.mjs+++ b/packages/shared/src/diagram-flowchart-style.test.mjs@@ -1,7 +1,11 @@import { describe, expect, test } from "bun:test";import { flowchartNodePresentation } from "./diagram-node-presentation.ts";import {+ FLOWCHART_READABLE_MIN_SCALE,FLOWCHART_SURFACES,+ flowchartEdgeIsStraight,+ flowchartEdgePorts,+ flowchartFitsReadableViewport,flowchartNodeVisual,resolveFlowchartSurface,} from "./diagram-flowchart-style.ts";@@ -60,6 +64,42 @@ describe("flowchart node presentation", () => {const label = "Transformer 前向计算\n因果注意力+前馈网络以及更长的说明文字";const presentation = flowchartNodePresentation("process", label);expect(presentation.text.replaceAll("\n", "")).toBe(label.replaceAll("\n", ""));- expect(presentation.width).toBeLessThanOrEqual(240);+ expect(presentation.width).toBe(176);+ });++ test("keeps every process node the same width regardless of label length", () => {+ const short = flowchartNodePresentation("process", "短");+ const long = flowchartNodePresentation("process", "Transformer 前向计算\n因果注意力+前馈网络");+ expect(short.width).toBe(long.width);+ expect(short.width).toBe(176);+ });+});++describe("flowchart edge geometry", () => {+ const above = { x: 80, y: 40, width: 176, height: 56 };+ const below = { x: 80, y: 160, width: 176, height: 56 };++ test("routes a stacked pair through the top and bottom ports as a straight line", () => {+ expect(flowchartEdgePorts(above, below)).toEqual({ source: "bottom", target: "top" });+ expect(flowchartEdgeIsStraight(above, below)).toBe(true);+ });++ test("sends a returning loop around the left side", () => {+ const loop = { x: 80, y: 520, width: 176, height: 56 };+ expect(flowchartEdgePorts(loop, above)).toEqual({ source: "left", target: "left" });+ expect(flowchartEdgeIsStraight(loop, above)).toBe(false);+ });+});++describe("flowchart readable viewport", () => {+ const viewport = { width: 960, height: 720 };++ test("keeps compact flows inside the canvas", () => {+ expect(flowchartFitsReadableViewport({ width: 180, height: 280 }, viewport)).toBe(true);+ });++ test("refuses to shrink a tall flow below reading size", () => {+ expect(flowchartFitsReadableViewport({ width: 220, height: 1680 }, viewport)).toBe(false);+ expect(FLOWCHART_READABLE_MIN_SCALE).toBe(0.85);});});diff --git a/packages/shared/src/diagram-flowchart-style.ts b/packages/shared/src/diagram-flowchart-style.tsindex fc608497..e34bde80 100644--- a/packages/shared/src/diagram-flowchart-style.ts+++ b/packages/shared/src/diagram-flowchart-style.ts@@ -5,11 +5,63 @@ export const FLOWCHART_LABEL_FONT =export const FLOWCHART_EDGE_ROUTER = {name: "manhattan" as const,- args: { padding: 16, step: 10 },+ args: { padding: 8, step: 8, excludeEnds: true },+};++export type FlowchartPortName = "top" | "right" | "bottom" | "left";++export type FlowchartBox = { x: number; y: number; width: number; height: number };++export const flowchartEdgePorts = (+ source: FlowchartBox,+ target: FlowchartBox,+): { source: FlowchartPortName; target: FlowchartPortName } => {+ const sourceCenter = { x: source.x + source.width / 2, y: source.y + source.height / 2 };+ const targetCenter = { x: target.x + target.width / 2, y: target.y + target.height / 2 };+ const dx = targetCenter.x - sourceCenter.x;+ const dy = targetCenter.y - sourceCenter.y;+ if (dy < -source.height) return { source: "left", target: "left" };+ if (dx < -source.width) return { source: "top", target: "top" };+ if (Math.abs(dy) >= Math.abs(dx)) {+ return dy >= 0+ ? { source: "bottom", target: "top" }+ : { source: "top", target: "bottom" };+ }+ return dx >= 0+ ? { source: "right", target: "left" }+ : { source: "left", target: "right" };+};++export const flowchartEdgeIsStraight = (source: FlowchartBox, target: FlowchartBox) => {+ const dx = (target.x + target.width / 2) - (source.x + source.width / 2);+ const dy = (target.y + target.height / 2) - (source.y + source.height / 2);+ if (dy < -source.height || dx < -source.width) return false;+ return (Math.abs(dx) <= 1 && Math.abs(dy) > 8) || (Math.abs(dy) <= 1 && Math.abs(dx) > 8);};export const FLOWCHART_LAYOUT_SPACING = { rank: 56, node: 36 };+// Tall flows should stay at reading size. Shrinking the whole graph into the+// viewport makes 12-step notes unreadable; show the start and let the canvas scroll.+export const FLOWCHART_READABLE_MIN_SCALE = 0.85;++export const flowchartFitsReadableViewport = (+ bounds: { width: number; height: number },+ viewport: { width: number; height: number },+ padding = 32,+ minScale = FLOWCHART_READABLE_MIN_SCALE,+ maxScale = 1,+) => {+ const availableWidth = Math.max(viewport.width - padding * 2, 1);+ const availableHeight = Math.max(viewport.height - padding * 2, 1);+ const fitScale = Math.min(+ availableWidth / Math.max(bounds.width, 1),+ availableHeight / Math.max(bounds.height, 1),+ maxScale,+ );+ return fitScale + 1e-6 >= minScale;+};+export type FlowchartAppearance = "light" | "dark";export type FlowchartShapePaint = {diff --git a/packages/shared/src/diagram-layout.ts b/packages/shared/src/diagram-layout.tsindex 36bfed2d..a55eeb52 100644--- a/packages/shared/src/diagram-layout.ts+++ b/packages/shared/src/diagram-layout.ts@@ -1,7 +1,13 @@import { compactFlowchartNodeSize, flowchartNodePresentation } from "./diagram-node-presentation";export { compactFlowchartNodeSize, flowchartNodePresentation } from "./diagram-node-presentation";-import { FLOWCHART_LAYOUT_SPACING } from "./diagram-flowchart-style";-export { FLOWCHART_EDGE_ROUTER, FLOWCHART_LAYOUT_SPACING } from "./diagram-flowchart-style";+import { FLOWCHART_LAYOUT_SPACING, FLOWCHART_READABLE_MIN_SCALE } from "./diagram-flowchart-style";+export {+ FLOWCHART_EDGE_ROUTER,+ FLOWCHART_LAYOUT_SPACING,+ flowchartEdgeIsStraight,+ flowchartEdgePorts,+ flowchartFitsReadableViewport,+} from "./diagram-flowchart-style";import {MIND_MAP_HORIZONTAL_GAP,MIND_MAP_VERTICAL_GAP,@@ -536,7 +542,7 @@ const DIAGRAM_LAYOUT_STRATEGIES: Record<DiagramKind, DiagramLayoutStrategy> = {flowchart: {kind: "flowchart",layout: computeFlowchartLayout,- viewport: { anchor: "center", maxScale: 0.9 },+ viewport: { anchor: "center", maxScale: 1, minScale: FLOWCHART_READABLE_MIN_SCALE },},architecture: {kind: "architecture",@@ -557,7 +563,11 @@ export const computeDiagramLayoutResult = (const strategy = DIAGRAM_LAYOUT_STRATEGIES[document.kind];const layoutDocument: DiagramDocument = {...document,- nodes: document.nodes.map((node) => ({ ...node })),+ nodes: document.nodes.map((node) => {+ if (document.kind !== "flowchart") return { ...node };+ const size = flowchartNodePresentation(node.shape, node.label);+ return { ...node, width: size.width, height: size.height };+ }),edges: document.edges.map((edge) => ({ ...edge })),};const positions = strategy.layout(layoutDocument, options);diff --git a/packages/shared/src/diagram-node-presentation.ts b/packages/shared/src/diagram-node-presentation.tsindex 32721c14..2b257b72 100644--- a/packages/shared/src/diagram-node-presentation.ts+++ b/packages/shared/src/diagram-node-presentation.ts@@ -7,10 +7,10 @@ export const visualTextUnits = (label: string) => Array.from(label).reduce(export const compactFlowchartNodeSize = (shape: DiagramNodeShape) => (shape === "decision"- ? { width: 140, height: 72 }+ ? { width: 176, height: 80 }: shape === "terminator"- ? { width: 116, height: 40 }- : { width: 124, height: 42 }+ ? { width: 140, height: 44 }+ : { width: 176, height: 56 });const FLOWCHART_CHAR_WIDTH = 13;@@ -36,15 +36,8 @@ export const flowchartNodePresentation = (shape: DiagramNodeShape, label: stringconst base = compactFlowchartNodeSize(shape);const decision = shape === "decision";const terminator = shape === "terminator";- const units = Math.max(...label.split("\n").map(visualTextUnits), 0);const padX = terminator ? 36 : 28;- const width = Math.max(- base.width,- Math.min(- 240,- Math.ceil(decision ? units * FLOWCHART_CHAR_WIDTH / FLOWCHART_DECISION_TEXT_RATIO + 12 : units * FLOWCHART_CHAR_WIDTH + padX),- ),- );+ const width = base.width;const capacity = Math.max(4, (decision ? width * FLOWCHART_DECISION_TEXT_RATIO : width - padX) / FLOWCHART_CHAR_WIDTH);const lines = wrapFlowchartLabel(label, capacity);const textHeight = Math.max(lines.length, 1) * FLOWCHART_LINE_HEIGHT;diff --git a/packages/shared/src/diagram-reader.ts b/packages/shared/src/diagram-reader.tsindex 609131c8..65e8c9e4 100644--- a/packages/shared/src/diagram-reader.ts+++ b/packages/shared/src/diagram-reader.ts@@ -1,5 +1,6 @@import { attachDiagramScroll } from "./diagram-scroll";import type { DiagramDocument } from './diagram';+import { FLOWCHART_READABLE_MIN_SCALE } from "./diagram-flowchart-style";type ReaderGraph = {resize: (width: number, height: number) => unknown;@@ -34,7 +35,11 @@ export const attachDiagramReader = (toolbar.appendChild(button);return button;};- const fit = () => { graph.zoomToFit({ maxScale: 1.05, padding: 28 }); graph.centerContent(); };+ const fit = () => {+ graph.zoomToFit({ maxScale: 1, padding: 28 });+ if (diagram.kind === 'flowchart' && graph.scale().sx < FLOWCHART_READABLE_MIN_SCALE) read();+ else graph.centerContent();+ };const read = () => {const incoming = new Set(diagram.edges.map((edge) => edge.target));const start = diagram.nodes.find((node) => !incoming.has(node.id)) ?? diagram.nodes[0];@@ -67,7 +72,6 @@ export const attachDiagramReader = (graph.resize(width, height);if (first) {fit();- if (diagram.kind === 'flowchart' && graph.scale().sx < 0.8) read();} else graph.translate(previous.tx + dx, previous.ty + dy);update();},diff --git a/packages/shared/src/diagram-view.ts b/packages/shared/src/diagram-view.tsindex b80e266b..dc785b06 100644--- a/packages/shared/src/diagram-view.ts+++ b/packages/shared/src/diagram-view.ts@@ -1,11 +1,18 @@import { flowchartNodePresentation } from "./diagram-node-presentation";+import {+ architectureEdgeVisual,+ architectureNodeVisual,+ resolveArchitectureSurface,+} from "./diagram-architecture-style";import {FLOWCHART_EDGE_ROUTER,FLOWCHART_LABEL_FONT,+ flowchartEdgeIsStraight,+ flowchartEdgePorts,flowchartNodeVisual,resolveFlowchartSurface,} from "./diagram-flowchart-style";-import type { ArchitectureResourceIcon, DiagramDocument, DiagramNodeShape, DiagramTheme } from "./diagram";+import type { DiagramDocument, DiagramTheme } from "./diagram";import { buildDiagramPalette } from "./diagram-palette";import {MIND_MAP_CONNECTOR_NAME,@@ -32,50 +39,11 @@ export type DiagramPalette = {canvas: string;};-const BRAND_GREEN = "#16A06E";-export const resolvePortableDiagramPalette = (theme: DiagramTheme = "brand",appearance: DiagramAppearance = "light",) => buildDiagramPalette(theme, appearance);-const architectureAccent: Partial<Record<DiagramNodeShape, string>> = {- client: "#0891B2",- frontend: "#2563EB",- service: BRAND_GREEN,- database: "#7C3AED",- storage: "#D97706",- queue: "#EA580C",- security: "#E11D48",- external: "#64748B",-};--// Native X6 viewers do not bundle React icon components. These compact,-// monochrome glyphs preserve each resource's visual identity in that portable-// projection while the Web editor renders the matching Lucide pictogram.-const architectureResourceGlyphs: Record<ArchitectureResourceIcon, string> = {- client: "▣", webApp: "▤", mobileApp: "▯", website: "◎", apiClient: "</>",- service: "▤", virtualMachine: "⚙", container: "⬡", kubernetes: "⌘", serverless: "ƒ",- relationalDatabase: "◉", noSqlDatabase: "ϟ", cache: "▱", dataWarehouse: "▥", searchEngine: "⌕",- objectStorage: "☁", fileStorage: "▧", blockStorage: "▰", backup: "↶", cdn: "⇧",- messageQueue: "≡", eventBus: "⑂", streamProcessing: "≋", webhook: "⌁", serviceMesh: "⋮",- apiGateway: "⇄", loadBalancer: "↔", dns: "◎", vpc: "◇", subnet: "⊞", vpn: "⌁",- identity: "◆", firewall: "▦", waf: "✓", secretManager: "⌑", certificate: "◈", systemBoundary: "□",- monitoring: "◴", logging: "▤", metrics: "↗", tracing: "∿", alerting: "!",- saas: "☁", externalApi: "⌁", thirdPartyService: "ϟ",-};--const architectureShapeGlyphs: Partial<Record<DiagramNodeShape, string>> = {- client: "▣",- frontend: "▤",- service: "▥",- database: "◉",- storage: "▰",- queue: "≡",- security: "✓",- external: "☁",-};-/** Plain X6 metadata shared by native WebView viewers. */export const diagramDocumentToX6Cells = (document: DiagramDocument,@@ -83,6 +51,7 @@ export const diagramDocumentToX6Cells = () => {const palette = resolvePortableDiagramPalette(document.theme ?? "brand", appearance);const flowchartSurface = document.kind === "flowchart" ? resolveFlowchartSurface(appearance) : null;+ const architectureSurface = document.kind === "architecture" ? resolveArchitectureSurface(appearance) : null;const nodes = document.nodes.map((node) => {const mindMapRole = document.kind === "mind-map" ? mindMapNodeRole(document.nodes, node.id) : null;const presentation = document.kind === "flowchart"@@ -97,29 +66,27 @@ export const diagramDocumentToX6Cells = (const flowchartVisual = document.kind === "flowchart"? flowchartNodeVisual(node.shape, appearance, presentation): null;+ const architectureVisual = document.kind === "architecture"+ ? architectureNodeVisual(node.shape, appearance, presentation, node.resourceIcon)+ : null;const isRootTopic = node.shape === "topic" && !node.parentId;const isTerminator = node.shape === "terminator";const isBoundary = node.shape === "boundary";- const accent = architectureAccent[node.shape];const emphasized = isRootTopic || isTerminator;const fill = mindVisual? mindVisual.body.fill: flowchartVisual? flowchartVisual.body.fill- : isBoundary- ? "transparent"- : accent- ? (appearance === "dark" ? palette.nodeFill : `${accent}12`)- : emphasized ? palette.topicFill : palette.nodeFill;+ : architectureVisual+ ? architectureVisual.body.fill+ : emphasized ? palette.topicFill : palette.nodeFill;const stroke = mindVisual? mindVisual.body.stroke: flowchartVisual? flowchartVisual.body.stroke- : isBoundary ? palette.nodeStroke : accent ?? (emphasized ? palette.topicStroke : palette.nodeStroke);- const usesArchitectureIcon = document.kind === "architecture" && !isBoundary;- const iconGlyph = node.resourceIcon- ? architectureResourceGlyphs[node.resourceIcon]- : architectureShapeGlyphs[node.shape];+ : architectureVisual+ ? architectureVisual.body.stroke+ : emphasized ? palette.topicStroke : palette.nodeStroke;return {id: node.id,shape: node.shape === "decision" ? "polygon" : "rect",@@ -128,63 +95,41 @@ export const diagramDocumentToX6Cells = (width: presentation.width,height: presentation.height,zIndex: isBoundary ? 0 : 2,- ...(usesArchitectureIcon ? { markup: [- { tagName: "rect", selector: "body" },- { tagName: "rect", selector: "iconFrame" },- { tagName: "text", selector: "resourceIcon" },- { tagName: "text", selector: "label" },- ] } : mindMapRole ? { markup: mindMapTopicMarkup(document.structure, mindMapRole) } : {}),+ ...(architectureVisual ? { markup: architectureVisual.markup } : mindMapRole ? { markup: mindMapTopicMarkup(document.structure, mindMapRole) } : {}),attrs: {body: {fill,stroke,- strokeWidth: mindVisual?.body.strokeWidth ?? flowchartVisual?.body.strokeWidth ?? (isBoundary || emphasized || accent ? 1.5 : 1),- strokeDasharray: isBoundary || node.shape === "external" ? "7 5" : undefined,- ...(mindVisual?.body ?? flowchartVisual?.body ?? {- rx: isTerminator ? 24 : node.shape === "database" ? 24 : 11,- ry: isTerminator ? 24 : node.shape === "database" ? 24 : 11,+ strokeWidth: mindVisual?.body.strokeWidth ?? flowchartVisual?.body.strokeWidth ?? architectureVisual?.body.strokeWidth ?? 1,+ strokeDasharray: architectureVisual?.body.strokeDasharray ?? (isBoundary ? "7 5" : undefined),+ ...(mindVisual?.body ?? flowchartVisual?.body ?? architectureVisual?.body ?? {+ rx: isTerminator ? 24 : 11,+ ry: isTerminator ? 24 : 11,}),...(node.shape === "decision" ? { refPoints: "0,10 10,0 20,10 10,20" } : {}),},label: {text: presentation.text,- lineHeight: mindVisual?.label.lineHeight ?? flowchartVisual?.label.lineHeight ?? (mindMapRole === "root" ? 20 : 18),- fill: mindVisual?.label.fill ?? flowchartVisual?.label.fill ?? (emphasized ? palette.topicText : palette.nodeText),- fontSize: mindVisual?.label.fontSize ?? flowchartVisual?.label.fontSize ?? (node.shape === "topic" ? 14 : isBoundary ? 12 : 13),- fontWeight: mindVisual?.label.fontWeight ?? flowchartVisual?.label.fontWeight ?? (emphasized || isBoundary || accent ? 650 : 500),- fontFamily: mindVisual?.label.fontFamily ?? flowchartVisual?.label.fontFamily ?? FLOWCHART_LABEL_FONT,+ lineHeight: mindVisual?.label.lineHeight ?? flowchartVisual?.label.lineHeight ?? architectureVisual?.label.lineHeight ?? (mindMapRole === "root" ? 20 : 18),+ fill: mindVisual?.label.fill ?? flowchartVisual?.label.fill ?? architectureVisual?.label.fill ?? (emphasized ? palette.topicText : palette.nodeText),+ fontSize: mindVisual?.label.fontSize ?? flowchartVisual?.label.fontSize ?? architectureVisual?.label.fontSize ?? (node.shape === "topic" ? 14 : 13),+ fontWeight: mindVisual?.label.fontWeight ?? flowchartVisual?.label.fontWeight ?? architectureVisual?.label.fontWeight ?? (emphasized ? 650 : 500),+ fontFamily: mindVisual?.label.fontFamily ?? flowchartVisual?.label.fontFamily ?? architectureVisual?.label.fontFamily ?? FLOWCHART_LABEL_FONT,...(mindVisual ? {refX: mindVisual.label.refX,refY: mindVisual.label.refY,textAnchor: mindVisual.label.textAnchor,textVerticalAnchor: mindVisual.label.textVerticalAnchor,} : {}),- ...(isBoundary ? { refX: 18, refY: 22, textAnchor: "start", textVerticalAnchor: "middle" } : {}),- ...(usesArchitectureIcon ? { refX: 54, refY: "50%", textAnchor: "start", textVerticalAnchor: "middle" } : {}),+ ...(architectureVisual ? {+ refX: architectureVisual.label.refX,+ refY: architectureVisual.label.refY,+ textAnchor: architectureVisual.label.textAnchor,+ textVerticalAnchor: architectureVisual.label.textVerticalAnchor,+ } : {}),},...(mindVisual ? { underline: mindVisual.underline } : {}),- ...(usesArchitectureIcon ? {- iconFrame: {- x: 10,- y: Math.round((node.height - 34) / 2),- width: 34,- height: 34,- rx: node.shape === "database" ? 17 : node.shape === "security" ? 12 : 8,- ry: node.shape === "database" ? 17 : node.shape === "security" ? 12 : 8,- fill: appearance === "dark" ? `${accent}30` : `${accent}18`,- stroke: "none",- },- resourceIcon: {- text: iconGlyph,- x: 27,- y: node.height / 2,- fill: accent,- fontSize: iconGlyph === "</>" ? 10 : 17,- fontWeight: 700,- textAnchor: "middle",- textVerticalAnchor: "middle",- },- } : {}),+ ...(architectureVisual?.attrs ?? {}),},};});@@ -208,29 +153,43 @@ export const diagramDocumentToX6Cells = (const targetTerminal = targetNode && mindMapTargetRole? mindMapEdgeTerminal(targetNode, mindMapTargetRole, sides.target, document.structure): null;- const stroke = edgeKind === "data"- ? "#7C3AED"- : edgeKind === "async"- ? "#EA580C"- : mindEdge?.stroke ?? flowchartSurface?.edge ?? palette.flowEdge;+ const architectureEdge = document.kind === "architecture"+ ? architectureEdgeVisual(edgeKind, appearance, edge.bidirectional)+ : null;+ const stroke = architectureEdge?.stroke+ ?? mindEdge?.stroke+ ?? flowchartSurface?.edge+ ?? palette.flowEdge;+ const flowchartPorts = document.kind === "flowchart" && sourceNode && targetNode+ ? flowchartEdgePorts(sourceNode, targetNode)+ : null;+ const flowchartStraight = Boolean(flowchartPorts && sourceNode && targetNode && flowchartEdgeIsStraight(sourceNode, targetNode));return {id: edge.id,source: document.kind === "mind-map"? { cell: edge.source, ...(sourceTerminal ?? { anchor: { name: sides.source } }) }- : { cell: edge.source },+ : flowchartPorts+ ? { cell: edge.source, port: flowchartPorts.source }+ : { cell: edge.source },target: document.kind === "mind-map"? { cell: edge.target, ...(targetTerminal ?? { anchor: { name: sides.target } }) }- : { cell: edge.target },- router: document.kind === "flowchart" ? FLOWCHART_EDGE_ROUTER : undefined,+ : flowchartPorts+ ? { cell: edge.target, port: flowchartPorts.target }+ : { cell: edge.target },+ router: document.kind === "flowchart"+ ? (flowchartStraight ? { name: "normal" } : FLOWCHART_EDGE_ROUTER)+ : undefined,connector: document.kind === "mind-map"? { name: MIND_MAP_CONNECTOR_NAME, args: { sourceWidth: mindEdge?.sourceWidth, targetWidth: mindEdge?.targetWidth } }: { name: "rounded", args: { radius: 10 } },attrs: { line: {stroke,- strokeWidth: mindEdge ? 0.5 : 1.5,- strokeDasharray: edgeKind === "async" ? "7 5" : undefined,- sourceMarker: edge.bidirectional ? { name: "block", width: 8, height: 6 } : null,- targetMarker: document.kind === "mind-map" ? null : { name: "block", width: 8, height: 6 },+ strokeWidth: architectureEdge?.strokeWidth ?? (mindEdge ? 0.5 : 1.5),+ strokeDasharray: architectureEdge?.strokeDasharray,+ sourceMarker: architectureEdge+ ? architectureEdge.sourceMarker+ : edge.bidirectional ? { name: "block", width: 8, height: 6 } : null,+ targetMarker: document.kind === "mind-map" ? null : architectureEdge?.targetMarker ?? { name: "block", width: 8, height: 6 },...(mindEdge ? {fill: stroke,strokeLinejoin: "round",@@ -240,7 +199,7 @@ export const diagramDocumentToX6Cells = (labels: edge.label ? [{ attrs: {label: {text: edge.label,- fill: flowchartSurface?.process.text ?? palette.nodeText,+ fill: flowchartSurface?.process.text ?? architectureSurface?.nodes.service.text ?? palette.nodeText,fontSize: 12,lineHeight: 16,fontFamily: FLOWCHART_LABEL_FONT,@@ -248,12 +207,12 @@ export const diagramDocumentToX6Cells = (},body: {ref: "label", refWidth: 1, refHeight: 1, refWidth2: 12, refHeight2: 8, refX: -6, refY: -4,- fill: flowchartSurface?.canvas ?? palette.canvas,- stroke: flowchartSurface?.process.stroke ?? palette.nodeStroke,+ fill: flowchartSurface?.canvas ?? architectureSurface?.canvas ?? palette.canvas,+ stroke: flowchartSurface?.process.stroke ?? architectureSurface?.nodes.service.stroke ?? palette.nodeStroke,strokeWidth: 1, rx: 5, ry: 5,},} }] : undefined,};});- return { canvas: flowchartSurface?.canvas ?? palette.canvas, edges, nodes };+ return { canvas: flowchartSurface?.canvas ?? architectureSurface?.canvas ?? palette.canvas, edges, nodes };};diff --git a/packages/shared/src/diagram.test.mjs b/packages/shared/src/diagram.test.mjsindex 4517372f..7e0d367a 100644--- a/packages/shared/src/diagram.test.mjs+++ b/packages/shared/src/diagram.test.mjs@@ -145,9 +145,14 @@ describe("diagram document", () => {const projected = diagramDocumentToX6Cells(legacy, "light");const containerCell = projected.nodes.find((node) => node.id === "api");const databaseCell = projected.nodes.find((node) => node.id === "database");- expect(containerCell.attrs.resourceIcon.text).toBe("⬡");- expect(databaseCell.attrs.resourceIcon.text).toBe("ϟ");- expect(containerCell.attrs.resourceIcon.text).not.toBe(databaseCell.attrs.resourceIcon.text);+ expect(containerCell.attrs.architectureIcon0.d).toContain("M22 7.7");+ expect(databaseCell.markup.some((item) => item.selector === "architectureIcon0" && item.tagName === "ellipse")).toBe(true);+ expect(containerCell.attrs.body.fill).toHaveLength(7);+ expect(containerCell.attrs.body.fill).not.toBe(databaseCell.attrs.body.fill);+ const dark = diagramDocumentToX6Cells(legacy, "dark");+ expect(dark.nodes.find((node) => node.id === "api").attrs.body.fill).not.toBe(+ dark.nodes.find((node) => node.id === "database").attrs.body.fill,+ );});test("rejects malformed and dangling graph data", () => {@@ -177,8 +182,9 @@ test('native flowchart projection shares label sizing and obstacle routing withoconst projection = diagramDocumentToX6Cells(document, 'dark');expect(projection.nodes[1].height).toBeGreaterThan(document.nodes[1].height);expect(projection.nodes[1].attrs.label.text.replaceAll('\n', '')).toBe(document.nodes[1].label.replaceAll('\n', ''));- expect(projection.edges[0].router.name).toBe('manhattan');- expect(projection.edges[0].router.args.padding).toBe(16);+ expect(projection.edges[0].router.name).toBe('normal');+ expect(projection.edges[0].source.port).toBe('bottom');+ expect(projection.edges[0].target.port).toBe('top');expect(projection.edges[0].attrs.line.fill).toBe('none');expect(projection.nodes[0].attrs.body.fill).not.toBe('#16A06E');expect(projection.nodes[0].attrs.label.fontFamily).toContain('Inter');diff --git a/packages/shared/src/diagram.ts b/packages/shared/src/diagram.tsindex 89767424..039fa9c8 100644--- a/packages/shared/src/diagram.ts+++ b/packages/shared/src/diagram.ts@@ -1,4 +1,9 @@import { Base64 } from "js-base64";+import {+ architectureMermaidBoundaryStyle,+ architectureMermaidClassDefs,+ architectureMermaidClassName,+} from "./diagram-architecture-style";export const DIAGRAM_SCHEMA_VERSION = 1 as const;export const ARCHITECTURE_DIAGRAM_SCHEMA_VERSION = 2 as const;@@ -268,16 +273,6 @@ export const diagramDocumentToMermaid = (document: DiagramDocument) => {security: "hex",external: "cloud",};- const classNames: Partial<Record<DiagramNodeShape, string>> = {- client: "archClient",- frontend: "archFrontend",- service: "archService",- database: "archDatabase",- storage: "archStorage",- queue: "archQueue",- security: "archSecurity",- external: "archExternal",- };const rendered = new Set<string>();const renderNode = (node: DiagramNode, indent: string) => {if (rendered.has(node.id)) return;@@ -292,7 +287,7 @@ export const diagramDocumentToMermaid = (document: DiagramDocument) => {return;}lines.push(`${indent}${id}@{ shape: ${shapeNames[node.shape] ?? "rect"}, label: "${label}" }`);- const className = classNames[node.shape];+ const className = architectureMermaidClassName(node.shape);if (className) lines.push(`${indent}class ${id} ${className}`);};@@ -310,16 +305,9 @@ export const diagramDocumentToMermaid = (document: DiagramDocument) => {lines.push(` ${source} ${connector} ${target}`);}- lines.push(" classDef archClient fill:#ECFEFF,stroke:#0891B2,color:#0F172A,stroke-width:2px");- lines.push(" classDef archFrontend fill:#EFF6FF,stroke:#2563EB,color:#0F172A,stroke-width:2px");- lines.push(" classDef archService fill:#ECFDF5,stroke:#16A06E,color:#0F172A,stroke-width:2px");- lines.push(" classDef archDatabase fill:#F5F3FF,stroke:#7C3AED,color:#0F172A,stroke-width:2px");- lines.push(" classDef archStorage fill:#FFFBEB,stroke:#D97706,color:#0F172A,stroke-width:2px");- lines.push(" classDef archQueue fill:#FFF7ED,stroke:#EA580C,color:#0F172A,stroke-width:2px");- lines.push(" classDef archSecurity fill:#FFF1F2,stroke:#E11D48,color:#0F172A,stroke-width:2px");- lines.push(" classDef archExternal fill:#F8FAFC,stroke:#64748B,color:#0F172A,stroke-width:2px,stroke-dasharray:6 4");+ lines.push(...architectureMermaidClassDefs("light"));for (const boundary of document.nodes.filter((node) => node.shape === "boundary")) {- lines.push(` style ${nodeIds.get(boundary.id)} fill:transparent,stroke:#64748B,stroke-width:1.5px,stroke-dasharray:7 5`);+ lines.push(` style ${nodeIds.get(boundary.id)} ${architectureMermaidBoundaryStyle("light")}`);}return lines.join("\n");}@@ -419,9 +407,9 @@ export const createDefaultDiagramDocument = (kind: DiagramKind): DiagramDocumentschemaVersion: DIAGRAM_SCHEMA_VERSION,kind,nodes: [- { id: "flow-start", label: "开始", x: 86, y: 48, width: 116, height: 40, shape: "terminator" },- { id: "flow-process", label: "处理步骤", x: 82, y: 136, width: 124, height: 42, shape: "process" },- { id: "flow-end", label: "结束", x: 86, y: 226, width: 116, height: 40, shape: "terminator" },+ { id: "flow-start", label: "开始", x: 98, y: 48, width: 140, height: 44, shape: "terminator" },+ { id: "flow-process", label: "处理步骤", x: 80, y: 140, width: 176, height: 56, shape: "process" },+ { id: "flow-end", label: "结束", x: 98, y: 244, width: 140, height: 44, shape: "terminator" },],edges: [{ id: "flow-edge-1", source: "flow-start", target: "flow-process" },diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.tsindex 81b9450b..2c129a5b 100644--- a/packages/shared/src/index.ts+++ b/packages/shared/src/index.ts@@ -32,6 +32,7 @@ export * from "./deployment-metadata";export * from "./diagram";export * from "./diagram-palette";export * from "./diagram-flowchart-style";+export * from "./diagram-architecture-style";export * from "./diagram-mindmap-style";export * from "./diagram-view";export * from "./file-attachment";