"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
postscriptum.plugin('ps-mathjax', (processor, options) => {
    var _a;
    const SCRIPT_URL = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/startup.js";
    const { util } = postscriptum;
    const { io } = util;
    let config = {
        startup: {
            elements: [processor.source],
        },
        loader: {
            load: ["input/tex-full", "input/mml", "output/chtml"]
        },
        chtml: {}
    };
    if (options.config)
        config = io.mergeOptions({}, config, options.config);
    if ((_a = options.elements) === null || _a === void 0 ? void 0 : _a.length)
        config.startup.elements = options.elements;
    if (options.fontsUrl)
        config.chtml.fontURL = options.fontsUrl;
    processor.on('start', async function () {
        if (this.parentFragmentor)
            return;
        window.MathJax = config;
        await io.loadScript(options.scriptUrl || SCRIPT_URL);
        await window.MathJax.startup.promise;
    });
}, { scriptUrl: "", fontsUrl: "", elements: [], config: null });
