'use strict';

var remarkMath = require('remark-math');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

function _interopNamespace(e) {
    if (e && e.__esModule) return e;
    var n = Object.create(null);
    if (e) {
        Object.keys(e).forEach(function (k) {
            if (k !== 'default') {
                var d = Object.getOwnPropertyDescriptor(e, k);
                Object.defineProperty(n, k, d.get ? d : {
                    enumerable: true,
                    get: function () {
                        return e[k];
                    }
                });
            }
        });
    }
    n['default'] = e;
    return Object.freeze(n);
}

var remarkMath__default = /*#__PURE__*/_interopDefaultLegacy(remarkMath);

function math({ katexOptions } = {}) {
    let katex;
    return {
        remark: (p) => p.use(remarkMath__default['default']),
        viewerEffect({ $el }) {
            const renderMath = async (selector, displayMode) => {
                const els = $el.querySelectorAll(selector);
                if (els.length === 0)
                    return;
                if (!katex) {
                    katex = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('katex')); });
                }
                els.forEach((el) => {
                    katex.render(el.innerText, el, {
                        ...katexOptions,
                        throwOnError: false,
                        displayMode,
                    });
                });
            };
            renderMath('.math.math-inline', false);
            renderMath('.math.math-display', true);
        },
    };
}

module.exports = math;
//# sourceMappingURL=index.cjs.js.map
