This commit is contained in:
Vanessa 2023-02-23 14:30:17 +08:00
parent e91bb94cf7
commit 45302d5a28
2 changed files with 9 additions and 9 deletions

View file

@ -1,6 +1,6 @@
import {addScript} from "../util/addScript";
import {Constants} from "../../constants";
import {hasClosestByClassName} from "../util/hasClosest";
import {hasClosestByAttribute} from "../util/hasClosest";
declare const flowchart: {
parse(text: string): { drawSVG: (type: Element) => void };
@ -19,22 +19,22 @@ export const flowchartRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
}
addScript(`${cdn}/js/flowchart.js/flowchart.min.js?v=0.0.0`, "protyleFlowchartScript").then(() => {
if (flowchartElements[0].firstElementChild.clientWidth === 0) {
const tabElement = hasClosestByClassName(flowchartElements[0], "protyle", true);
if (!tabElement) {
const hideElement = hasClosestByAttribute(flowchartElements[0], "fold", "1");
if (!hideElement) {
return;
}
const observer = new MutationObserver(() => {
initFlowchart(flowchartElements);
observer.disconnect();
});
observer.observe(tabElement, {attributeFilter: ["class"]});
observer.observe(hideElement, {attributeFilter: ["fold"]});
} else {
initFlowchart(flowchartElements);
}
});
};
const initFlowchart = (flowchartElements:Element[]) => {
const initFlowchart = (flowchartElements: Element[]) => {
flowchartElements.forEach((item: HTMLElement) => {
if (item.getAttribute("data-render") === "true") {
return;

View file

@ -1,6 +1,6 @@
import {addScript} from "../util/addScript";
import {Constants} from "../../constants";
import {hasClosestByClassName} from "../util/hasClosest";
import {hasClosestByAttribute} from "../util/hasClosest";
declare const mermaid: {
initialize(options: any): void,
@ -45,15 +45,15 @@ export const mermaidRender = (element: Element, cdn = Constants.PROTYLE_CDN) =>
}
mermaid.initialize(config);
if (mermaidElements[0].firstElementChild.clientWidth === 0) {
const tabElement = hasClosestByClassName(mermaidElements[0], "protyle", true);
if (!tabElement) {
const hideElement = hasClosestByAttribute(mermaidElements[0], "fold", "1");
if (!hideElement) {
return;
}
const observer = new MutationObserver(() => {
initMermaid(mermaidElements);
observer.disconnect();
});
observer.observe(tabElement, {attributeFilter: ["class"]});
observer.observe(hideElement, {attributeFilter: ["fold"]});
} else {
initMermaid(mermaidElements);
}