@8btc/mditor 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,26 @@
1
- import {Constants} from "../constants";
2
- import {addScript} from "../util/addScript";
3
- import {mermaidRenderAdapter} from "./adapterRender";
4
- import {genUUID} from "../util/function";
1
+ import { Constants } from "../constants";
2
+ import { addScript } from "../util/addScript";
3
+ import { mermaidRenderAdapter } from "./adapterRender";
4
+ import { genUUID } from "../util/function";
5
5
 
6
6
  declare const mermaid: {
7
- initialize(options: any): void,
8
- render(id: string, text: string): { svg: string }
7
+ initialize(options: any): void;
8
+ render(id: string, text: string): { svg: string };
9
9
  };
10
10
 
11
- export const mermaidRender = (element: (HTMLElement | Document) = document, cdn = Constants.CDN, theme: string) => {
11
+ export const mermaidRender = (
12
+ element: HTMLElement | Document = document,
13
+ cdn = Constants.CDN,
14
+ theme: string
15
+ ) => {
12
16
  const mermaidElements = mermaidRenderAdapter.getElements(element);
13
17
  if (mermaidElements.length === 0) {
14
18
  return;
15
19
  }
16
- addScript(`${cdn}/dist/js/mermaid/mermaid.min.js?v=11.11.0`, "vditorMermaidScript").then(() => {
20
+ addScript(
21
+ `${cdn}/dist/js/mermaid/mermaid.min.js?v=11.11.0`,
22
+ "vditorMermaidScript"
23
+ ).then(() => {
17
24
  const config: any = {
18
25
  securityLevel: "loose", // 升级后无 https://github.com/siyuan-note/siyuan/issues/3587,可使用该选项
19
26
  altFontFamily: "sans-serif",
@@ -21,19 +28,19 @@ export const mermaidRender = (element: (HTMLElement | Document) = document, cdn
21
28
  startOnLoad: false,
22
29
  flowchart: {
23
30
  htmlLabels: true,
24
- useMaxWidth: !0
31
+ useMaxWidth: !0,
25
32
  },
26
33
  sequence: {
27
34
  useMaxWidth: true,
28
35
  diagramMarginX: 8,
29
36
  diagramMarginY: 8,
30
37
  boxMargin: 8,
31
- showSequenceNumbers: true // Mermaid 时序图增加序号 https://github.com/siyuan-note/siyuan/pull/6992 https://mermaid.js.org/syntax/sequenceDiagram.html#sequencenumbers
38
+ showSequenceNumbers: true, // Mermaid 时序图增加序号 https://github.com/siyuan-note/siyuan/pull/6992 https://mermaid.js.org/syntax/sequenceDiagram.html#sequencenumbers
32
39
  },
33
40
  gantt: {
34
41
  leftPadding: 75,
35
- rightPadding: 20
36
- }
42
+ rightPadding: 20,
43
+ },
37
44
  };
38
45
  if (theme === "dark") {
39
46
  config.theme = "dark";
@@ -41,17 +48,24 @@ export const mermaidRender = (element: (HTMLElement | Document) = document, cdn
41
48
  mermaid.initialize(config);
42
49
  mermaidElements.forEach(async (item) => {
43
50
  const code = mermaidRenderAdapter.getCode(item);
44
- if (item.getAttribute("data-processed") === "true" || code.trim() === "") {
51
+ if (
52
+ item.getAttribute("data-processed") === "true" ||
53
+ code.trim() === ""
54
+ ) {
45
55
  return;
46
56
  }
47
- const id = "mermaid" + genUUID()
57
+ const id = "mermaid" + genUUID();
48
58
  try {
49
59
  const mermaidData = await mermaid.render(id, item.textContent);
50
60
  item.innerHTML = mermaidData.svg;
51
61
  } catch (e) {
52
62
  const errorElement = document.querySelector("#" + id);
53
- item.innerHTML = `${errorElement.outerHTML}<br>
54
- <div style="text-align: left"><small>${e.message.replace(/\n/, "<br>")}</small></div>`;
63
+ item.innerHTML = `
64
+ <div class="mermaid-error">
65
+ <div class="mermaid-error-icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-bug-icon lucide-bug"><path d="M12 20v-9"/><path d="M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z"/><path d="M14.12 3.88 16 2"/><path d="M21 21a4 4 0 0 0-3.81-4"/><path d="M21 5a4 4 0 0 1-3.55 3.97"/><path d="M22 13h-4"/><path d="M3 21a4 4 0 0 1 3.81-4"/><path d="M3 5a4 4 0 0 0 3.55 3.97"/><path d="M6 13H2"/><path d="m8 2 1.88 1.88"/><path d="M9 7.13V6a3 3 0 1 1 6 0v1.13"/></svg></div>
66
+ <div class="mermaid-error-title">图表加载失败</div>
67
+ <div class="mermaid-error-message">${e.message.replace(/\n/, "<br>")}</div>
68
+ </div>`;
55
69
  errorElement.parentElement.remove();
56
70
  }
57
71
  item.setAttribute("data-processed", "true");