* fix: improve Mermaid diagram implementation (#1213) This commit addresses multiple issues with Mermaid diagram rendering and adds significant improvements to the user experience. - Fix `<br/>` tags rendering as literal text instead of line breaks - Fix flash of raw mermaid code before diagram renders - Fix Gantt chart rendering issues in dark mode - Fix diagrams briefly showing during theme switch re-render - Fix expand modal showing diagram left-aligned before centering - Add fullscreen expand modal with pan/zoom functionality - Add toolbar with zoom controls (zoom in/out, reset, fit to screen) - Add keyboard support (Escape to close modal) - Add per-diagram transparent background via `%%transparent%%` directive - Add comprehensive configuration options: - `look`: classic or handDrawn (sketch style) - `lightTheme`/`darkTheme`: theme selection per mode - `lightThemeVariables`/`darkThemeVariables`: custom theme colors - `securityLevel`, `htmlLabels`, `maxTextSize`, `maxEdges` - `fontSize`, `fontFamily`, `curve`, `logLevel` - Switch from ESM to UMD bundle for faster initial load (~1s vs 2s+) - Lazy-load panzoom library only when expand modal is opened - Pre-render alternate theme during idle time for instant theme switching - Cache rendered diagrams to avoid re-rendering on theme toggle - Move all inline CSS to article.scss using SCSS nesting - Extract helper functions for better maintainability - Use data attributes and event delegation for cleaner handlers - Reduce mermaid.html from 411 to 177 lines (57% reduction) - Add comprehensive mermaid-diagrams example post with all diagram types - Document all configuration options in hugo.yaml * refactor: extract mermaid inline JS to TypeScript module Move ~155 lines of inline JavaScript from mermaid.html partial into assets/ts/mermaid.ts. The partial shrinks from 179 to 36 lines and now only contains modal HTML markup and Hugo Pipes build/import logic. - Deduplicate initWithTheme() and renderOffscreen() helpers - Enable minification via Hugo Pipes js.Build in production - Remove user-configurable mermaid version from params.toml --------- Co-authored-by: delize <4028612+delize@users.noreply.github.com>
433 lines
8.5 KiB
SCSS
433 lines
8.5 KiB
SCSS
/* Default article style */
|
|
.article-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: var(--section-separation);
|
|
|
|
article {
|
|
display: flex;
|
|
flex-direction: column;
|
|
background-color: var(--card-background);
|
|
box-shadow: var(--shadow-l1);
|
|
border-radius: var(--card-border-radius);
|
|
overflow: hidden;
|
|
|
|
transition: box-shadow 0.3s ease;
|
|
|
|
&:hover {
|
|
box-shadow: var(--shadow-l2);
|
|
}
|
|
|
|
.article-image {
|
|
img {
|
|
width: 100%;
|
|
height: 150px;
|
|
object-fit: cover;
|
|
|
|
@include respond(md) {
|
|
height: 200px;
|
|
}
|
|
|
|
@include respond(xl) {
|
|
height: 250px;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
.article-details {
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
padding: var(--card-padding);
|
|
gap: 15px;
|
|
}
|
|
|
|
.article-title {
|
|
font-family: var(--article-font-family);
|
|
font-weight: 600;
|
|
margin: 0;
|
|
color: var(--card-text-color-main);
|
|
font-size: 2.2rem;
|
|
|
|
@include respond(xl) {
|
|
font-size: 2.4rem;
|
|
}
|
|
|
|
a {
|
|
color: var(--card-text-color-main);
|
|
|
|
&:hover {
|
|
color: var(--card-text-color-main);
|
|
}
|
|
}
|
|
}
|
|
|
|
.article-subtitle {
|
|
font-weight: normal;
|
|
color: var(--card-text-color-secondary);
|
|
line-height: 1.5;
|
|
margin: 0;
|
|
font-size: 1.75rem;
|
|
@include respond(xl) {
|
|
font-size: 2rem;
|
|
}
|
|
}
|
|
|
|
.article-title-wrapper {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 8px;
|
|
}
|
|
|
|
.article-time,
|
|
.article-translations {
|
|
display: flex;
|
|
color: var(--card-text-color-tertiary);
|
|
gap: 15px;
|
|
|
|
svg {
|
|
vertical-align: middle;
|
|
width: 20px;
|
|
height: 20px;
|
|
stroke-width: 1.33;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
time,
|
|
a {
|
|
font-size: 1.4rem;
|
|
color: var(--card-text-color-tertiary);
|
|
}
|
|
|
|
& > div {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 15px;
|
|
}
|
|
}
|
|
|
|
.article-time {
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.article-translations {
|
|
& > div {
|
|
flex-wrap: wrap;
|
|
}
|
|
}
|
|
|
|
.article-category,
|
|
.article-tags {
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-wrap: wrap;
|
|
|
|
a {
|
|
color: var(--accent-color-text);
|
|
background-color: var(--accent-color);
|
|
padding: 8px 16px;
|
|
border-radius: var(--tag-border-radius);
|
|
display: inline-block;
|
|
font-size: 1.4rem;
|
|
transition: background-color 0.5s ease;
|
|
|
|
&:hover {
|
|
color: var(--accent-color-text);
|
|
background-color: var(--accent-color-darker);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Compact style article list */
|
|
.article-list--compact {
|
|
border-radius: var(--card-border-radius);
|
|
box-shadow: var(--shadow-l1);
|
|
background-color: var(--card-background);
|
|
--image-size: 50px;
|
|
|
|
@include respond(md) {
|
|
--image-size: 60px;
|
|
}
|
|
|
|
article {
|
|
& > a {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: var(--small-card-padding);
|
|
gap: 15px;
|
|
}
|
|
|
|
&:not(:last-of-type) {
|
|
border-bottom: 1.5px solid var(--card-separator-color);
|
|
}
|
|
|
|
.article-details {
|
|
flex-grow: 1;
|
|
padding: 0;
|
|
min-height: var(--image-size);
|
|
gap: 10px;
|
|
}
|
|
|
|
.article-title {
|
|
margin: 0;
|
|
font-size: 1.6rem;
|
|
|
|
@include respond(md) {
|
|
font-size: 1.8rem;
|
|
}
|
|
}
|
|
|
|
.article-image {
|
|
img {
|
|
width: var(--image-size);
|
|
height: var(--image-size);
|
|
object-fit: cover;
|
|
}
|
|
}
|
|
|
|
.article-time {
|
|
font-size: 1.4rem;
|
|
}
|
|
|
|
.article-preview {
|
|
font-size: 1.4rem;
|
|
color: var(--card-text-color-tertiary);
|
|
line-height: 1.5;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Tile style article list */
|
|
.article-list--tile {
|
|
article {
|
|
border-radius: var(--card-border-radius);
|
|
overflow: hidden;
|
|
position: relative;
|
|
height: 350px;
|
|
width: 250px;
|
|
box-shadow: var(--shadow-l1);
|
|
transition: box-shadow 0.3s ease;
|
|
background-color: var(--card-background);
|
|
|
|
&:hover {
|
|
box-shadow: var(--shadow-l2);
|
|
}
|
|
|
|
&.has-image {
|
|
.article-details {
|
|
background-color: rgba(#000, 0.25);
|
|
}
|
|
|
|
.article-title {
|
|
color: #fff;
|
|
}
|
|
}
|
|
|
|
.article-image {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
|
|
img {
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
}
|
|
}
|
|
|
|
.article-details {
|
|
border-radius: var(--card-border-radius);
|
|
position: relative;
|
|
height: 100%;
|
|
width: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: flex-end;
|
|
z-index: 2;
|
|
padding: 15px;
|
|
|
|
@include respond(sm) {
|
|
padding: 20px;
|
|
}
|
|
}
|
|
|
|
.article-title {
|
|
font-size: 2rem;
|
|
font-weight: 500;
|
|
color: var(--card-text-color-main);
|
|
|
|
@include respond(sm) {
|
|
font-size: 2.2rem;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
.mermaid:not([data-processed]) {
|
|
background: var(--card-background);
|
|
min-height: 150px;
|
|
border-radius: 8px;
|
|
position: relative;
|
|
overflow: hidden;
|
|
font-size: 0 !important;
|
|
line-height: 0;
|
|
color: transparent;
|
|
|
|
&::after {
|
|
visibility: visible;
|
|
content: "";
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
width: 28px;
|
|
height: 28px;
|
|
margin: -14px 0 0 -14px;
|
|
border: 3px solid var(--card-background);
|
|
border-top-color: var(--accent-color, #3273dc);
|
|
border-radius: 50%;
|
|
animation: mermaid-spinner 0.8s linear infinite;
|
|
}
|
|
}
|
|
|
|
@keyframes mermaid-spinner {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
|
|
// Mermaid diagram wrapper with expand toolbar
|
|
.mermaid-wrapper {
|
|
position: relative;
|
|
margin: 1rem 0;
|
|
|
|
.mermaid {
|
|
display: flex;
|
|
justify-content: center;
|
|
|
|
svg {
|
|
display: block;
|
|
max-width: 100%;
|
|
height: auto;
|
|
}
|
|
}
|
|
}
|
|
|
|
.mermaid-toolbar {
|
|
position: absolute;
|
|
top: 0.75rem;
|
|
right: 0.75rem;
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
z-index: 10;
|
|
|
|
button {
|
|
padding: 0.5rem 1rem;
|
|
background: rgba(255, 255, 255, 0.95);
|
|
border: 2px solid #333;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
font-size: 1rem;
|
|
font-weight: 600;
|
|
color: #333;
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
|
transition: all 0.2s;
|
|
|
|
&:hover {
|
|
background: #333;
|
|
color: #fff;
|
|
transform: scale(1.05);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Mermaid fullscreen modal
|
|
.mermaid-modal {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100vw;
|
|
height: 100vh;
|
|
background: rgba(0, 0, 0, 0.95);
|
|
z-index: 9999;
|
|
|
|
&.active {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
}
|
|
|
|
.mermaid-modal-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 0.75rem 1rem;
|
|
background: rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.mermaid-modal-controls {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.mermaid-modal-controls button,
|
|
.mermaid-modal-close {
|
|
padding: 0.5rem 1rem;
|
|
background: #fff;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 0.9rem;
|
|
|
|
&:hover {
|
|
background: #ddd;
|
|
}
|
|
}
|
|
|
|
.mermaid-modal-body {
|
|
flex: 1;
|
|
overflow: hidden;
|
|
position: relative;
|
|
}
|
|
|
|
.mermaid-modal-content {
|
|
position: absolute;
|
|
top: 1rem;
|
|
left: 1rem;
|
|
right: 1rem;
|
|
bottom: 1rem;
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
background: #fff;
|
|
|
|
[data-scheme="dark"] & {
|
|
background: #1e1e1e;
|
|
}
|
|
}
|
|
|
|
.mermaid-panzoom-container {
|
|
display: inline-block;
|
|
transform-origin: 0 0;
|
|
visibility: hidden;
|
|
|
|
&.ready {
|
|
visibility: visible;
|
|
}
|
|
|
|
svg {
|
|
display: block;
|
|
}
|
|
}
|
|
|
|
// Off-screen container for pre-rendering alternate theme
|
|
.mermaid-offscreen {
|
|
position: absolute;
|
|
left: -9999px;
|
|
visibility: hidden;
|
|
width: 800px;
|
|
}
|