Files
to_docx/client/node_modules/.vite/deps/diagram-5BDNPKRD-IMF7AYPE.js
T
2026-05-12 08:59:02 +08:00

215 lines
5.7 KiB
JavaScript

import {
ImperativeState
} from "./chunk-VPVLR6E4.js";
import {
populateCommonDb
} from "./chunk-BEGFPAJS.js";
import {
parse
} from "./chunk-R5NQBCLB.js";
import "./chunk-JH6V2QOE.js";
import "./chunk-QLH66CIT.js";
import "./chunk-SHHXTPWA.js";
import "./chunk-JLNTX6TF.js";
import "./chunk-IELG6YWI.js";
import "./chunk-ZOQ3FUUK.js";
import "./chunk-TAVNOOKD.js";
import "./chunk-5D6MANWW.js";
import "./chunk-E3W5VJ2T.js";
import "./chunk-S4AGLBPD.js";
import "./chunk-K3ORWWMK.js";
import {
selectSvgElement
} from "./chunk-QBIGODNM.js";
import "./chunk-BQ2Z5GT2.js";
import {
cleanAndMerge
} from "./chunk-GUBXVVWZ.js";
import "./chunk-MOBZPS7F.js";
import {
clear,
configureSvgSize,
defaultConfig_default,
getAccDescription,
getAccTitle,
getConfig,
getDiagramTitle,
setAccDescription,
setAccTitle,
setDiagramTitle
} from "./chunk-6YWVU24R.js";
import "./chunk-5ZDVNSGT.js";
import {
__name,
log
} from "./chunk-XOKMXDAB.js";
import "./chunk-DBU5TJLK.js";
// node_modules/mermaid/dist/chunks/mermaid.core/diagram-5BDNPKRD.mjs
var state = new ImperativeState(() => ({
cnt: 1,
stack: [
{
id: 0,
level: -1,
name: "/",
children: []
}
]
}));
var clear2 = __name(() => {
state.reset();
clear();
}, "clear");
var getRoot = __name(() => {
return state.records.stack[0];
}, "getRoot");
var getCount = __name(() => state.records.cnt, "getCount");
var defaultConfig = defaultConfig_default.treeView;
var getConfig2 = __name(() => {
return cleanAndMerge(defaultConfig, getConfig().treeView);
}, "getConfig");
var addNode = __name((level, name) => {
while (level <= state.records.stack[state.records.stack.length - 1].level) {
state.records.stack.pop();
}
const node = {
id: state.records.cnt++,
level,
name,
children: []
};
state.records.stack[state.records.stack.length - 1].children.push(node);
state.records.stack.push(node);
}, "addNode");
var db = {
clear: clear2,
addNode,
getRoot,
getCount,
getConfig: getConfig2,
getAccTitle,
getAccDescription,
getDiagramTitle,
setAccDescription,
setAccTitle,
setDiagramTitle
};
var db_default = db;
var populate = __name((ast) => {
populateCommonDb(ast, db_default);
ast.nodes.map((node) => db_default.addNode(node.indent ? parseInt(node.indent) : 0, node.name));
}, "populate");
var parser = {
parse: __name(async (input) => {
const ast = await parse("treeView", input);
log.debug(ast);
populate(ast);
}, "parse")
};
var positionLabel = __name((x, y, node, domElem, config) => {
const label = domElem.append("text").text(node.name).attr("dominant-baseline", "middle").attr("class", "treeView-node-label");
const { height: labelHeight, width: labelWidth } = label.node().getBBox();
const height = labelHeight + config.paddingY * 2;
const width = labelWidth + config.paddingX * 2;
label.attr("x", x + config.paddingX);
label.attr("y", y + height / 2);
node.BBox = {
x,
y,
width,
height
};
}, "positionLabel");
var positionLine = __name((domElem, x1, y1, x2, y2, lineThickness) => {
return domElem.append("line").attr("x1", x1).attr("y1", y1).attr("x2", x2).attr("y2", y2).attr("stroke-width", lineThickness).attr("class", "treeView-node-line");
}, "positionLine");
var drawTree = __name((elem, root, config) => {
let totalHeight = 0;
let totalWidth = 0;
const drawNode = __name((elem2, node, config2, depth) => {
const indent = depth * (config2.rowIndent + config2.paddingX);
positionLabel(indent, totalHeight, node, elem2, config2);
const { height, width } = node.BBox;
positionLine(
elem2,
indent - config2.rowIndent,
totalHeight + height / 2,
indent,
totalHeight + height / 2,
config2.lineThickness
);
totalWidth = Math.max(totalWidth, indent + width);
totalHeight += height;
}, "drawNode");
const processNode = __name((node, depth = 0) => {
drawNode(elem, node, config, depth);
node.children.forEach((child) => {
processNode(child, depth + 1);
});
const { x, y, height } = node.BBox;
if (node.children.length) {
const { y: endY, height: endHeight } = node.children[node.children.length - 1].BBox;
positionLine(
elem,
x + config.paddingX,
y + height,
x + config.paddingX,
endY + endHeight / 2 + config.lineThickness / 2,
config.lineThickness
);
}
}, "processNode");
processNode(root);
return { totalHeight, totalWidth };
}, "drawTree");
var draw = __name((text, id, _ver, diagObj) => {
log.debug("Rendering treeView diagram\n" + text);
const db2 = diagObj.db;
const root = db2.getRoot();
const config = db2.getConfig();
const svg = selectSvgElement(id);
const treeElem = svg.append("g");
treeElem.attr("class", "tree-view");
const { totalHeight, totalWidth } = drawTree(treeElem, root, config);
svg.attr("viewBox", `-${config.lineThickness / 2} 0 ${totalWidth} ${totalHeight}`);
configureSvgSize(svg, totalHeight, totalWidth, config.useMaxWidth);
}, "draw");
var renderer = {
draw
};
var renderer_default = renderer;
var defaultTreeViewDiagramStyles = {
labelFontSize: "16px",
labelColor: "black",
lineColor: "black"
};
var styles = __name(({
treeView
}) => {
const { labelFontSize, labelColor, lineColor } = cleanAndMerge(
defaultTreeViewDiagramStyles,
treeView
);
return `
.treeView-node-label {
font-size: ${labelFontSize};
fill: ${labelColor};
}
.treeView-node-line {
stroke: ${lineColor};
}
`;
}, "styles");
var styles_default = styles;
var diagram = {
db: db_default,
renderer: renderer_default,
parser,
styles: styles_default
};
export {
diagram
};
//# sourceMappingURL=diagram-5BDNPKRD-IMF7AYPE.js.map