refactor(mermaid): move mermaid config to service

This commit is contained in:
Elian Doran
2025-03-22 15:02:04 +02:00
parent 1463411ad1
commit 7c9a7c9ff6
4 changed files with 22 additions and 23 deletions

View File

@@ -1,7 +1,26 @@
import type { MermaidConfig } from "mermaid";
import type { Mermaid } from "mermaid"; import type { Mermaid } from "mermaid";
let elkLoaded = false; let elkLoaded = false;
export function getMermaidConfig(): MermaidConfig {
const documentStyle = window.getComputedStyle(document.documentElement);
const mermaidTheme = documentStyle.getPropertyValue("--mermaid-theme") as "default";
return {
theme: mermaidTheme.trim() as "default",
securityLevel: "antiscript",
flowchart: { useMaxWidth: false },
sequence: { useMaxWidth: false },
gantt: { useMaxWidth: false },
class: { useMaxWidth: false },
state: { useMaxWidth: false },
pie: { useMaxWidth: true },
journey: { useMaxWidth: false },
gitGraph: { useMaxWidth: false }
};
}
/** /**
* Determines whether the ELK extension of Mermaid.js needs to be loaded (which is a relatively large library), based on the * Determines whether the ELK extension of Mermaid.js needs to be loaded (which is a relatively large library), based on the
* front-matter of the diagram and loads the library if needed. * front-matter of the diagram and loads the library if needed.

View File

@@ -16,7 +16,7 @@ import toast from "../../services/toast.js";
import { normalizeMimeTypeForCKEditor } from "../../services/mime_type_definitions.js"; import { normalizeMimeTypeForCKEditor } from "../../services/mime_type_definitions.js";
import { buildConfig, buildToolbarConfig } from "./ckeditor/config.js"; import { buildConfig, buildToolbarConfig } from "./ckeditor/config.js";
import type FNote from "../../entities/fnote.js"; import type FNote from "../../entities/fnote.js";
import { getMermaidConfig } from "./mermaid.js"; import { getMermaidConfig } from "../../services/mermaid.js";
const ENABLE_INSPECTOR = false; const ENABLE_INSPECTOR = false;

View File

@@ -1,5 +1,4 @@
import type { MermaidConfig } from "mermaid"; import { getMermaidConfig, loadElkIfNeeded, postprocessMermaidSvg } from "../../services/mermaid.js";
import { loadElkIfNeeded, postprocessMermaidSvg } from "../../services/mermaid.js";
import AbstractSvgSplitTypeWidget from "./abstract_svg_split_type_widget.js"; import AbstractSvgSplitTypeWidget from "./abstract_svg_split_type_widget.js";
let idCounter = 1; let idCounter = 1;
@@ -34,22 +33,3 @@ export class MermaidTypeWidget extends AbstractSvgSplitTypeWidget {
} }
} }
export function getMermaidConfig(): MermaidConfig {
const documentStyle = window.getComputedStyle(document.documentElement);
const mermaidTheme = documentStyle.getPropertyValue("--mermaid-theme") as "default";
return {
theme: mermaidTheme.trim() as "default",
securityLevel: "antiscript",
flowchart: { useMaxWidth: false },
sequence: { useMaxWidth: false },
gantt: { useMaxWidth: false },
class: { useMaxWidth: false },
state: { useMaxWidth: false },
pie: { useMaxWidth: true },
journey: { useMaxWidth: false },
gitGraph: { useMaxWidth: false }
};
}

View File

@@ -4,7 +4,7 @@ import { applySyntaxHighlight } from "../../services/syntax_highlight.js";
import type FNote from "../../entities/fnote.js"; import type FNote from "../../entities/fnote.js";
import type { EventData } from "../../components/app_context.js"; import type { EventData } from "../../components/app_context.js";
import { getLocaleById } from "../../services/i18n.js"; import { getLocaleById } from "../../services/i18n.js";
import { getMermaidConfig } from "./mermaid.js"; import { getMermaidConfig } from "../../services/mermaid.js";
const TPL = ` const TPL = `
<div class="note-detail-readonly-text note-detail-printable"> <div class="note-detail-readonly-text note-detail-printable">