import dedent from "ts-dedent"; import { l as log } from "./commonDb-573409be.js"; import { d as detectType, i as isDetailedError, u as utils, r as registerLazyLoadedDiagrams, l as loadRegisteredDiagrams } from "./utils-d622194a.js"; import { m as mermaidAPI } from "./mermaidAPI-3ae0f2f0.js"; import "dompurify"; import "dayjs"; import "khroma"; import "@braintree/sanitize-url"; import "d3"; import "lodash-es/memoize.js"; import "stylis"; import "lodash-es/isEmpty.js"; const handleError = (error, errors, parseError) => { log.warn(error); if (isDetailedError(error)) { if (parseError) { parseError(error.str, error.hash); } errors.push({ ...error, message: error.str, error }); } else { if (parseError) { parseError(error); } if (error instanceof Error) { errors.push({ str: error.message, message: error.message, hash: error.name, error }); } } }; const run = async function(options = { querySelector: ".mermaid" }) { try { await runThrowsErrors(options); } catch (e) { if (isDetailedError(e)) { log.error(e.str); } if (mermaid.parseError) { mermaid.parseError(e); } if (!options.suppressErrors) { log.error("Use the suppressErrors option to suppress these errors"); throw e; } } }; const runThrowsErrors = async function({ postRenderCallback, querySelector, nodes } = { querySelector: ".mermaid" }) { const conf = mermaidAPI.getConfig(); log.debug(`${!postRenderCallback ? "No " : ""}Callback function found`); let nodesToProcess; if (nodes) { nodesToProcess = nodes; } else if (querySelector) { nodesToProcess = document.querySelectorAll(querySelector); } else { throw new Error("Nodes and querySelector are both undefined"); } log.debug(`Found ${nodesToProcess.length} diagrams`); if ((conf == null ? void 0 : conf.startOnLoad) !== void 0) { log.debug("Start On Load: " + (conf == null ? void 0 : conf.startOnLoad)); mermaidAPI.updateSiteConfig({ startOnLoad: conf == null ? void 0 : conf.startOnLoad }); } const idGenerator = new utils.initIdGenerator(conf.deterministicIds, conf.deterministicIDSeed); let txt; const errors = []; for (const element of Array.from(nodesToProcess)) { log.info("Rendering diagram: " + element.id); /*! Check if previously processed */ if (element.getAttribute("data-processed")) { continue; } element.setAttribute("data-processed", "true"); const id = `mermaid-${idGenerator.next()}`; txt = element.innerHTML; txt = dedent(utils.entityDecode(txt)).trim().replace(//gi, "
"); const init2 = utils.detectInit(txt); if (init2) { log.debug("Detected early reinit: ", init2); } try { const { svg, bindFunctions } = await render(id, txt, element); element.innerHTML = svg; if (postRenderCallback) { await postRenderCallback(id); } if (bindFunctions) { bindFunctions(element); } } catch (error) { handleError(error, errors, mermaid.parseError); } } if (errors.length > 0) { throw errors[0]; } }; const initialize = function(config) { mermaidAPI.initialize(config); }; const init = async function(config, nodes, callback) { log.warn("mermaid.init is deprecated. Please use run instead."); if (config) { initialize(config); } const runOptions = { postRenderCallback: callback, querySelector: ".mermaid" }; if (typeof nodes === "string") { runOptions.querySelector = nodes; } else if (nodes) { if (nodes instanceof HTMLElement) { runOptions.nodes = [nodes]; } else { runOptions.nodes = nodes; } } await run(runOptions); }; const registerExternalDiagrams = async (diagrams, { lazyLoad = true } = {}) => { registerLazyLoadedDiagrams(...diagrams); if (lazyLoad === false) { await loadRegisteredDiagrams(); } }; const contentLoaded = function() { if (mermaid.startOnLoad) { const { startOnLoad } = mermaidAPI.getConfig(); if (startOnLoad) { mermaid.run().catch((err) => log.error("Mermaid failed to initialize", err)); } } }; if (typeof document !== "undefined") { /*! * Wait for document loaded before starting the execution */ window.addEventListener("load", contentLoaded, false); } const setParseErrorHandler = function(parseErrorHandler) { mermaid.parseError = parseErrorHandler; }; const executionQueue = []; let executionQueueRunning = false; const executeQueue = async () => { if (executionQueueRunning) { return; } executionQueueRunning = true; while (executionQueue.length > 0) { const f = executionQueue.shift(); if (f) { try { await f(); } catch (e) { log.error("Error executing queue", e); } } } executionQueueRunning = false; }; const parse = async (text, parseOptions) => { return new Promise((resolve, reject) => { const performCall = () => new Promise((res, rej) => { mermaidAPI.parse(text, parseOptions).then( (r) => { res(r); resolve(r); }, (e) => { var _a; log.error("Error parsing", e); (_a = mermaid.parseError) == null ? void 0 : _a.call(mermaid, e); rej(e); reject(e); } ); }); executionQueue.push(performCall); executeQueue().catch(reject); }); }; const render = (id, text, container) => { return new Promise((resolve, reject) => { const performCall = () => new Promise((res, rej) => { mermaidAPI.render(id, text, container).then( (r) => { res(r); resolve(r); }, (e) => { var _a; log.error("Error parsing", e); (_a = mermaid.parseError) == null ? void 0 : _a.call(mermaid, e); rej(e); reject(e); } ); }); executionQueue.push(performCall); executeQueue().catch(reject); }); }; const mermaid = { startOnLoad: true, mermaidAPI, parse, render, init, run, registerExternalDiagrams, initialize, parseError: void 0, contentLoaded, setParseErrorHandler, detectType }; export { mermaid as default }; //# sourceMappingURL=mermaid.core.mjs.map