All files / src/meridian-mermaid theme.ts

100% Statements 181/181
84.61% Branches 11/13
81.81% Functions 9/11
100% Lines 181/181

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 1821x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Meridian diagram renderer — in-house theme and SVG polish for bundled Mermaid.js.
 * Part of app-visual-studio; no third-party diagram renderer dependency.
 */
 
export type MeridianMermaidCssVars = {
  background: string
  foreground: string
  link: string
  border: string
  muted: string
}
 
/** Fallback palette when VS Code CSS variables are unavailable. */
export const MERIDIAN_MERMAID_FALLBACK: MeridianMermaidCssVars = {
  background: "#1e1e1e",
  foreground: "#cccccc",
  link: "#38bdf8",
  border: "#475569",
  muted: "#94a3b8",
}
 
/** Role colors aligned with generate-architecture-diagram skill classDef palette. */
export const MERIDIAN_DIAGRAM_ROLE_COLORS = {
  module: { fill: "#0f766e", stroke: "#2dd4bf", text: "#ecfeff" },
  store: { fill: "#065f46", stroke: "#34d399", text: "#ecfdf5" },
  workflow: { fill: "#5b21b6", stroke: "#c4b5fd", text: "#f5f3ff" },
  person: { fill: "#1d4ed8", stroke: "#93c5fd", text: "#eff6ff" },
  ui: { fill: "#334155", stroke: "#94a3b8", text: "#f8fafc" },
} as const
 
export type MeridianMermaidInitConfig = {
  theme: "base"
  themeVariables: Record<string, string>
  flowchart: { useMaxWidth: boolean; htmlLabels: boolean; curve: string; padding: number }
  er: { useMaxWidth: boolean; fontSize: number }
  sequence: { useMaxWidth: boolean; mirrorActors: boolean }
  securityLevel: "loose"
}
 
export function buildMeridianMermaidInitConfig(
  css: MeridianMermaidCssVars = MERIDIAN_MERMAID_FALLBACK,
): MeridianMermaidInitConfig {
  const { background, foreground, link, border, muted } = css
  const { module, store, workflow, ui } = MERIDIAN_DIAGRAM_ROLE_COLORS
 
  return {
    theme: "base",
    themeVariables: {
      darkMode: "true",
      background,
      primaryColor: module.fill,
      primaryTextColor: module.text,
      primaryBorderColor: module.stroke,
      secondaryColor: ui.fill,
      secondaryTextColor: ui.text,
      secondaryBorderColor: ui.stroke,
      tertiaryColor: workflow.fill,
      tertiaryTextColor: workflow.text,
      tertiaryBorderColor: workflow.stroke,
      lineColor: muted,
      textColor: foreground,
      mainBkg: module.fill,
      nodeBorder: module.stroke,
      clusterBkg: "rgba(148,163,184,0.06)",
      clusterBorder: border,
      titleColor: foreground,
      edgeLabelBackground: background,
      fontFamily: "var(--vscode-font-family)",
      noteBkgColor: store.fill,
      noteTextColor: store.text,
      noteBorderColor: store.stroke,
      actorBkg: ui.fill,
      actorBorder: ui.stroke,
      actorTextColor: ui.text,
      signalColor: muted,
      labelBoxBkgColor: background,
      labelBoxBorderColor: border,
      labelTextColor: foreground,
      relationColor: link,
    },
    flowchart: {
      useMaxWidth: false,
      htmlLabels: true,
      curve: "basis",
      padding: 16,
    },
    er: {
      useMaxWidth: false,
      fontSize: 13,
    },
    sequence: {
      useMaxWidth: false,
      mirrorActors: false,
    },
    securityLevel: "loose",
  }
}
 
/** JS helpers injected into the architecture diagram webview. */
export function meridianMermaidThemeScriptBody(): string {
  const roles = MERIDIAN_DIAGRAM_ROLE_COLORS
  const fallbacks = MERIDIAN_MERMAID_FALLBACK
  return `
    const MERIDIAN_ROLE_COLORS = ${JSON.stringify(roles)};
    const MERIDIAN_THEME_FALLBACKS = ${JSON.stringify(fallbacks)};
 
    function readCssVar(name, fallback) {
      const value = getComputedStyle(document.body).getPropertyValue(name).trim();
      return value || fallback;
    }
 
    function meridianMermaidTheme() {
      const css = {
        background: readCssVar("--vscode-editor-background", MERIDIAN_THEME_FALLBACKS.background),
        foreground: readCssVar("--vscode-foreground", MERIDIAN_THEME_FALLBACKS.foreground),
        link: readCssVar("--vscode-textLink-foreground", MERIDIAN_THEME_FALLBACKS.link),
        border: readCssVar("--vscode-panel-border", MERIDIAN_THEME_FALLBACKS.border),
        muted: readCssVar("--vscode-descriptionForeground", MERIDIAN_THEME_FALLBACKS.muted),
      };
      const module = MERIDIAN_ROLE_COLORS.module;
      const store = MERIDIAN_ROLE_COLORS.store;
      const workflow = MERIDIAN_ROLE_COLORS.workflow;
      const ui = MERIDIAN_ROLE_COLORS.ui;
      return {
        theme: "base",
        themeVariables: {
          darkMode: "true",
          background: css.background,
          primaryColor: module.fill,
          primaryTextColor: module.text,
          primaryBorderColor: module.stroke,
          secondaryColor: ui.fill,
          secondaryTextColor: ui.text,
          secondaryBorderColor: ui.stroke,
          tertiaryColor: workflow.fill,
          tertiaryTextColor: workflow.text,
          tertiaryBorderColor: workflow.stroke,
          lineColor: css.muted,
          textColor: css.foreground,
          mainBkg: module.fill,
          nodeBorder: module.stroke,
          clusterBkg: "rgba(148,163,184,0.06)",
          clusterBorder: css.border,
          titleColor: css.foreground,
          edgeLabelBackground: css.background,
          fontFamily: "var(--vscode-font-family)",
          noteBkgColor: store.fill,
          noteTextColor: store.text,
          noteBorderColor: store.stroke,
          actorBkg: ui.fill,
          actorBorder: ui.stroke,
          actorTextColor: ui.text,
          signalColor: css.muted,
          labelBoxBkgColor: css.background,
          labelBoxBorderColor: css.border,
          labelTextColor: css.foreground,
          relationColor: css.link,
        },
        flowchart: { useMaxWidth: false, htmlLabels: true, curve: "basis", padding: 16 },
        er: { useMaxWidth: false, fontSize: 13 },
        sequence: { useMaxWidth: false, mirrorActors: false },
        securityLevel: "loose",
      };
    }
 
    function polishMeridianSvg(svg) {
      let out = (svg || "").trim();
      if (!out) return out;
      if (!/class="[^"]*meridian-diagram/.test(out)) {
        out = out.replace(/<svg\\b/, '<svg class="meridian-diagram"');
      }
      out = out.replace(/\\sstyle="max-width:\\s*100%;?"/gi, "");
      out = out.replace(/\\smax-width="[^"]*"/gi, "");
      if (!/role="img"/.test(out)) {
        out = out.replace(/<svg\\b/, '<svg role="img"');
      }
      return out;
    }
  `
}