Behaviour SwRS-MDOKFSTUDIO-DIAG-005
Mermaid colours follow the preview theme
When the page draws a Mermaid diagram, the extension SHALL take its colours from the preview theme variables, use a built-in fallback for any variable that is missing, empty or a CSS system colour keyword, and draw it again when the theme colours change.
Step 3 of path 1 in StRS-MDOKFSTUDIO-DIAG-001: from “The diagram is drawn as a picture” to “The diagram is redrawn in the new theme, labels kept”.
Scenarios 5
The situations the tests check; open one to read it.
nominalColours come from the theme variables
| Part of the picture | Source | Checked |
|---|---|---|
| Node fill | --studio-textCodeBlock-background | in the drawn picture (the node fill of the visual fixture) |
| Diagram background | transparent | in the drawn picture |
| Text and line colours | --studio-editor-foreground | as the value given to Mermaid |
| Border colour | --sphinx-preview-border | as the value given to Mermaid |
| Secondary and tertiary colours | --studio-textBlockQuote-background and --studio-editor-background | as the value given to Mermaid |
Givena dark preview theme that defines those variables
Whenthe page draws a Mermaid diagram
Theneach part takes its value from the variable in the table: the drawn node fill equals --studio-textCodeBlock-background and the picture background is transparent, and the other colours are the values given to Mermaid (the Mermaid base theme uses the secondary and tertiary colours only for clusters and for the derived edge-label background, which the visual fixture does not draw as such, and its nodes carry their own border)
nominalThe theme changes
Givena drawn Mermaid diagram on a dark preview
Whenthe data-sphinx-preview-theme-mode, data-sphinx-preview-theme, class or style attribute of the html element, or the class or style attribute of the body element, changes and the theme mode becomes white
Thenthe page checks every Mermaid diagram, draws again each one whose theme colours differ from those it was drawn with, and keeps its node labels
boundaryThe theme colours stay the same
Givena drawn Mermaid diagram
Whenan observed attribute changes and leaves the theme colours as they were
Thenthe diagram is not drawn again and keeps its picture
boundaryBuilt-in fallbacks
The built-in fallbacks are #f0f0f0, #1f1f1f, #808080 and #ffffff. The font is not a theme value; SwRS-MDOKFSTUDIO-DIAG-001 pins it.
| Variable state | Outcome |
|---|---|
| --studio-editor-foreground is not defined by the preview | The text and line colour is the fallback #1f1f1f |
| --studio-textCodeBlock-background has the value Canvas in any letter case (a CSS system colour keyword) | The node colour is the fallback #f0f0f0 instead of the keyword |
| A variable is empty | Its built-in fallback is used |
nominalEdge labels stay readable
| Theme | Outcome |
|---|---|
| Dark theme, a map whose edges carry labels | The picture holds as many edge labels as the source defines and each has a text contrast of at least 4.5:1 against its background |
| Fallback theme (a preview that gives no host colour variables), same map | The labels are kept and each has a contrast of at least 4.5:1 |
Implemented in 1
Tested by 3
Known limits (3)
- The redraw evidence covers dark, white and cream; the light mode relies on the same observer.
- The fallback colours are fixed colours of a light palette.
- Edge label readability is checked by the visual campaign only; no unit test.
Replaces
SwRS-MDOKFSTUDIO-DIAG-006Mermaid diagrams are drawn again when the theme changes superseded superseded by SwRS-MDOKFSTUDIO-DIAG-005 Markdown file
SwRS-MDOKFSTUDIO-DIAG-007Mermaid falls back to built-in colours superseded superseded by SwRS-MDOKFSTUDIO-DIAG-005 Markdown file
SwRS-MDOKFSTUDIO-DIAG-008Mermaid edge labels stay readable superseded superseded by SwRS-MDOKFSTUDIO-DIAG-005 Markdown file