UNPKG

vitepress-markmap-preview

Version:

Markmap preview for vitepress

1,085 lines (1,080 loc) 42.7 kB
import H from "fs"; import K from "path"; /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */ function en(n) { return typeof n > "u" || n === null; } function mn(n) { return typeof n == "object" && n !== null; } function gn(n) { return Array.isArray(n) ? n : en(n) ? [] : [n]; } function xn(n, i) { var e, o, r, c; if (i) for (c = Object.keys(i), e = 0, o = c.length; e < o; e += 1) r = c[e], n[r] = i[r]; return n; } function An(n, i) { var e = "", o; for (o = 0; o < i; o += 1) e += n; return e; } function vn(n) { return n === 0 && Number.NEGATIVE_INFINITY === 1 / n; } var bn = en, wn = mn, yn = gn, Cn = An, kn = vn, Tn = xn, w = { isNothing: bn, isObject: wn, toArray: yn, repeat: Cn, isNegativeZero: kn, extend: Tn }; function rn(n, i) { var e = "", o = n.reason || "(unknown reason)"; return n.mark ? (n.mark.name && (e += 'in "' + n.mark.name + '" '), e += "(" + (n.mark.line + 1) + ":" + (n.mark.column + 1) + ")", !i && n.mark.snippet && (e += ` ` + n.mark.snippet), o + " " + e) : o; } function L(n, i) { Error.call(this), this.name = "YAMLException", this.reason = n, this.mark = i, this.message = rn(this, !1), Error.captureStackTrace ? Error.captureStackTrace(this, this.constructor) : this.stack = new Error().stack || ""; } L.prototype = Object.create(Error.prototype); L.prototype.constructor = L; L.prototype.toString = function(i) { return this.name + ": " + rn(this, i); }; var T = L; function Y(n, i, e, o, r) { var c = "", l = "", u = Math.floor(r / 2) - 1; return o - i > u && (c = " ... ", i = o - u + c.length), e - o > u && (l = " ...", e = o + u - l.length), { str: c + n.slice(i, e).replace(/\t/g, "→") + l, pos: o - i + c.length // relative position }; } function R(n, i) { return w.repeat(" ", i - n.length) + n; } function _n(n, i) { if (i = Object.create(i || null), !n.buffer) return null; i.maxLength || (i.maxLength = 79), typeof i.indent != "number" && (i.indent = 1), typeof i.linesBefore != "number" && (i.linesBefore = 3), typeof i.linesAfter != "number" && (i.linesAfter = 2); for (var e = /\r?\n|\r|\0/g, o = [0], r = [], c, l = -1; c = e.exec(n.buffer); ) r.push(c.index), o.push(c.index + c[0].length), n.position <= c.index && l < 0 && (l = o.length - 2); l < 0 && (l = o.length - 1); var u = "", f, h, s = Math.min(n.line + i.linesAfter, r.length).toString().length, t = i.maxLength - (i.indent + s + 3); for (f = 1; f <= i.linesBefore && !(l - f < 0); f++) h = Y( n.buffer, o[l - f], r[l - f], n.position - (o[l] - o[l - f]), t ), u = w.repeat(" ", i.indent) + R((n.line - f + 1).toString(), s) + " | " + h.str + ` ` + u; for (h = Y(n.buffer, o[l], r[l], n.position, t), u += w.repeat(" ", i.indent) + R((n.line + 1).toString(), s) + " | " + h.str + ` `, u += w.repeat("-", i.indent + s + 3 + h.pos) + `^ `, f = 1; f <= i.linesAfter && !(l + f >= r.length); f++) h = Y( n.buffer, o[l + f], r[l + f], n.position - (o[l] - o[l + f]), t ), u += w.repeat(" ", i.indent) + R((n.line + f + 1).toString(), s) + " | " + h.str + ` `; return u.replace(/\n$/, ""); } var Sn = _n, Fn = [ "kind", "multi", "resolve", "construct", "instanceOf", "predicate", "represent", "representName", "defaultStyle", "styleAliases" ], In = [ "scalar", "sequence", "mapping" ]; function On(n) { var i = {}; return n !== null && Object.keys(n).forEach(function(e) { n[e].forEach(function(o) { i[String(o)] = e; }); }), i; } function En(n, i) { if (i = i || {}, Object.keys(i).forEach(function(e) { if (Fn.indexOf(e) === -1) throw new T('Unknown option "' + e + '" is met in definition of "' + n + '" YAML type.'); }), this.options = i, this.tag = n, this.kind = i.kind || null, this.resolve = i.resolve || function() { return !0; }, this.construct = i.construct || function(e) { return e; }, this.instanceOf = i.instanceOf || null, this.predicate = i.predicate || null, this.represent = i.represent || null, this.representName = i.representName || null, this.defaultStyle = i.defaultStyle || null, this.multi = i.multi || !1, this.styleAliases = On(i.styleAliases || null), In.indexOf(this.kind) === -1) throw new T('Unknown kind "' + this.kind + '" is specified for "' + n + '" YAML type.'); } var b = En; function W(n, i) { var e = []; return n[i].forEach(function(o) { var r = e.length; e.forEach(function(c, l) { c.tag === o.tag && c.kind === o.kind && c.multi === o.multi && (r = l); }), e[r] = o; }), e; } function Nn() { var n = { scalar: {}, sequence: {}, mapping: {}, fallback: {}, multi: { scalar: [], sequence: [], mapping: [], fallback: [] } }, i, e; function o(r) { r.multi ? (n.multi[r.kind].push(r), n.multi.fallback.push(r)) : n[r.kind][r.tag] = n.fallback[r.tag] = r; } for (i = 0, e = arguments.length; i < e; i += 1) arguments[i].forEach(o); return n; } function U(n) { return this.extend(n); } U.prototype.extend = function(i) { var e = [], o = []; if (i instanceof b) o.push(i); else if (Array.isArray(i)) o = o.concat(i); else if (i && (Array.isArray(i.implicit) || Array.isArray(i.explicit))) i.implicit && (e = e.concat(i.implicit)), i.explicit && (o = o.concat(i.explicit)); else throw new T("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })"); e.forEach(function(c) { if (!(c instanceof b)) throw new T("Specified list of YAML types (or a single Type object) contains a non-Type object."); if (c.loadKind && c.loadKind !== "scalar") throw new T("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported."); if (c.multi) throw new T("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit."); }), o.forEach(function(c) { if (!(c instanceof b)) throw new T("Specified list of YAML types (or a single Type object) contains a non-Type object."); }); var r = Object.create(U.prototype); return r.implicit = (this.implicit || []).concat(e), r.explicit = (this.explicit || []).concat(o), r.compiledImplicit = W(r, "implicit"), r.compiledExplicit = W(r, "explicit"), r.compiledTypeMap = Nn(r.compiledImplicit, r.compiledExplicit), r; }; var Ln = U, Mn = new b("tag:yaml.org,2002:str", { kind: "scalar", construct: function(n) { return n !== null ? n : ""; } }), Dn = new b("tag:yaml.org,2002:seq", { kind: "sequence", construct: function(n) { return n !== null ? n : []; } }), Pn = new b("tag:yaml.org,2002:map", { kind: "mapping", construct: function(n) { return n !== null ? n : {}; } }), jn = new Ln({ explicit: [ Mn, Dn, Pn ] }); function Yn(n) { if (n === null) return !0; var i = n.length; return i === 1 && n === "~" || i === 4 && (n === "null" || n === "Null" || n === "NULL"); } function Rn() { return null; } function Bn(n) { return n === null; } var Un = new b("tag:yaml.org,2002:null", { kind: "scalar", resolve: Yn, construct: Rn, predicate: Bn, represent: { canonical: function() { return "~"; }, lowercase: function() { return "null"; }, uppercase: function() { return "NULL"; }, camelcase: function() { return "Null"; }, empty: function() { return ""; } }, defaultStyle: "lowercase" }); function $n(n) { if (n === null) return !1; var i = n.length; return i === 4 && (n === "true" || n === "True" || n === "TRUE") || i === 5 && (n === "false" || n === "False" || n === "FALSE"); } function qn(n) { return n === "true" || n === "True" || n === "TRUE"; } function Gn(n) { return Object.prototype.toString.call(n) === "[object Boolean]"; } var Hn = new b("tag:yaml.org,2002:bool", { kind: "scalar", resolve: $n, construct: qn, predicate: Gn, represent: { lowercase: function(n) { return n ? "true" : "false"; }, uppercase: function(n) { return n ? "TRUE" : "FALSE"; }, camelcase: function(n) { return n ? "True" : "False"; } }, defaultStyle: "lowercase" }); function Kn(n) { return 48 <= n && n <= 57 || 65 <= n && n <= 70 || 97 <= n && n <= 102; } function Wn(n) { return 48 <= n && n <= 55; } function Zn(n) { return 48 <= n && n <= 57; } function Vn(n) { if (n === null) return !1; var i = n.length, e = 0, o = !1, r; if (!i) return !1; if (r = n[e], (r === "-" || r === "+") && (r = n[++e]), r === "0") { if (e + 1 === i) return !0; if (r = n[++e], r === "b") { for (e++; e < i; e++) if (r = n[e], r !== "_") { if (r !== "0" && r !== "1") return !1; o = !0; } return o && r !== "_"; } if (r === "x") { for (e++; e < i; e++) if (r = n[e], r !== "_") { if (!Kn(n.charCodeAt(e))) return !1; o = !0; } return o && r !== "_"; } if (r === "o") { for (e++; e < i; e++) if (r = n[e], r !== "_") { if (!Wn(n.charCodeAt(e))) return !1; o = !0; } return o && r !== "_"; } } if (r === "_") return !1; for (; e < i; e++) if (r = n[e], r !== "_") { if (!Zn(n.charCodeAt(e))) return !1; o = !0; } return !(!o || r === "_"); } function zn(n) { var i = n, e = 1, o; if (i.indexOf("_") !== -1 && (i = i.replace(/_/g, "")), o = i[0], (o === "-" || o === "+") && (o === "-" && (e = -1), i = i.slice(1), o = i[0]), i === "0") return 0; if (o === "0") { if (i[1] === "b") return e * parseInt(i.slice(2), 2); if (i[1] === "x") return e * parseInt(i.slice(2), 16); if (i[1] === "o") return e * parseInt(i.slice(2), 8); } return e * parseInt(i, 10); } function Xn(n) { return Object.prototype.toString.call(n) === "[object Number]" && n % 1 === 0 && !w.isNegativeZero(n); } var Jn = new b("tag:yaml.org,2002:int", { kind: "scalar", resolve: Vn, construct: zn, predicate: Xn, represent: { binary: function(n) { return n >= 0 ? "0b" + n.toString(2) : "-0b" + n.toString(2).slice(1); }, octal: function(n) { return n >= 0 ? "0o" + n.toString(8) : "-0o" + n.toString(8).slice(1); }, decimal: function(n) { return n.toString(10); }, /* eslint-disable max-len */ hexadecimal: function(n) { return n >= 0 ? "0x" + n.toString(16).toUpperCase() : "-0x" + n.toString(16).toUpperCase().slice(1); } }, defaultStyle: "decimal", styleAliases: { binary: [2, "bin"], octal: [8, "oct"], decimal: [10, "dec"], hexadecimal: [16, "hex"] } }), Qn = new RegExp( // 2.5e4, 2.5 and integers "^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$" ); function ni(n) { return !(n === null || !Qn.test(n) || // Quick hack to not allow integers end with `_` // Probably should update regexp & check speed n[n.length - 1] === "_"); } function ii(n) { var i, e; return i = n.replace(/_/g, "").toLowerCase(), e = i[0] === "-" ? -1 : 1, "+-".indexOf(i[0]) >= 0 && (i = i.slice(1)), i === ".inf" ? e === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY : i === ".nan" ? NaN : e * parseFloat(i, 10); } var ei = /^[-+]?[0-9]+e/; function ri(n, i) { var e; if (isNaN(n)) switch (i) { case "lowercase": return ".nan"; case "uppercase": return ".NAN"; case "camelcase": return ".NaN"; } else if (Number.POSITIVE_INFINITY === n) switch (i) { case "lowercase": return ".inf"; case "uppercase": return ".INF"; case "camelcase": return ".Inf"; } else if (Number.NEGATIVE_INFINITY === n) switch (i) { case "lowercase": return "-.inf"; case "uppercase": return "-.INF"; case "camelcase": return "-.Inf"; } else if (w.isNegativeZero(n)) return "-0.0"; return e = n.toString(10), ei.test(e) ? e.replace("e", ".e") : e; } function oi(n) { return Object.prototype.toString.call(n) === "[object Number]" && (n % 1 !== 0 || w.isNegativeZero(n)); } var li = new b("tag:yaml.org,2002:float", { kind: "scalar", resolve: ni, construct: ii, predicate: oi, represent: ri, defaultStyle: "lowercase" }), ci = jn.extend({ implicit: [ Un, Hn, Jn, li ] }), ui = ci, on = new RegExp( "^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$" ), ln = new RegExp( "^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$" ); function fi(n) { return n === null ? !1 : on.exec(n) !== null || ln.exec(n) !== null; } function ti(n) { var i, e, o, r, c, l, u, f = 0, h = null, s, t, m; if (i = on.exec(n), i === null && (i = ln.exec(n)), i === null) throw new Error("Date resolve error"); if (e = +i[1], o = +i[2] - 1, r = +i[3], !i[4]) return new Date(Date.UTC(e, o, r)); if (c = +i[4], l = +i[5], u = +i[6], i[7]) { for (f = i[7].slice(0, 3); f.length < 3; ) f += "0"; f = +f; } return i[9] && (s = +i[10], t = +(i[11] || 0), h = (s * 60 + t) * 6e4, i[9] === "-" && (h = -h)), m = new Date(Date.UTC(e, o, r, c, l, u, f)), h && m.setTime(m.getTime() - h), m; } function ai(n) { return n.toISOString(); } var pi = new b("tag:yaml.org,2002:timestamp", { kind: "scalar", resolve: fi, construct: ti, instanceOf: Date, represent: ai }); function hi(n) { return n === "<<" || n === null; } var si = new b("tag:yaml.org,2002:merge", { kind: "scalar", resolve: hi }), $ = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/= \r`; function di(n) { if (n === null) return !1; var i, e, o = 0, r = n.length, c = $; for (e = 0; e < r; e++) if (i = c.indexOf(n.charAt(e)), !(i > 64)) { if (i < 0) return !1; o += 6; } return o % 8 === 0; } function mi(n) { var i, e, o = n.replace(/[\r\n=]/g, ""), r = o.length, c = $, l = 0, u = []; for (i = 0; i < r; i++) i % 4 === 0 && i && (u.push(l >> 16 & 255), u.push(l >> 8 & 255), u.push(l & 255)), l = l << 6 | c.indexOf(o.charAt(i)); return e = r % 4 * 6, e === 0 ? (u.push(l >> 16 & 255), u.push(l >> 8 & 255), u.push(l & 255)) : e === 18 ? (u.push(l >> 10 & 255), u.push(l >> 2 & 255)) : e === 12 && u.push(l >> 4 & 255), new Uint8Array(u); } function gi(n) { var i = "", e = 0, o, r, c = n.length, l = $; for (o = 0; o < c; o++) o % 3 === 0 && o && (i += l[e >> 18 & 63], i += l[e >> 12 & 63], i += l[e >> 6 & 63], i += l[e & 63]), e = (e << 8) + n[o]; return r = c % 3, r === 0 ? (i += l[e >> 18 & 63], i += l[e >> 12 & 63], i += l[e >> 6 & 63], i += l[e & 63]) : r === 2 ? (i += l[e >> 10 & 63], i += l[e >> 4 & 63], i += l[e << 2 & 63], i += l[64]) : r === 1 && (i += l[e >> 2 & 63], i += l[e << 4 & 63], i += l[64], i += l[64]), i; } function xi(n) { return Object.prototype.toString.call(n) === "[object Uint8Array]"; } var Ai = new b("tag:yaml.org,2002:binary", { kind: "scalar", resolve: di, construct: mi, predicate: xi, represent: gi }), vi = Object.prototype.hasOwnProperty, bi = Object.prototype.toString; function wi(n) { if (n === null) return !0; var i = [], e, o, r, c, l, u = n; for (e = 0, o = u.length; e < o; e += 1) { if (r = u[e], l = !1, bi.call(r) !== "[object Object]") return !1; for (c in r) if (vi.call(r, c)) if (!l) l = !0; else return !1; if (!l) return !1; if (i.indexOf(c) === -1) i.push(c); else return !1; } return !0; } function yi(n) { return n !== null ? n : []; } var Ci = new b("tag:yaml.org,2002:omap", { kind: "sequence", resolve: wi, construct: yi }), ki = Object.prototype.toString; function Ti(n) { if (n === null) return !0; var i, e, o, r, c, l = n; for (c = new Array(l.length), i = 0, e = l.length; i < e; i += 1) { if (o = l[i], ki.call(o) !== "[object Object]" || (r = Object.keys(o), r.length !== 1)) return !1; c[i] = [r[0], o[r[0]]]; } return !0; } function _i(n) { if (n === null) return []; var i, e, o, r, c, l = n; for (c = new Array(l.length), i = 0, e = l.length; i < e; i += 1) o = l[i], r = Object.keys(o), c[i] = [r[0], o[r[0]]]; return c; } var Si = new b("tag:yaml.org,2002:pairs", { kind: "sequence", resolve: Ti, construct: _i }), Fi = Object.prototype.hasOwnProperty; function Ii(n) { if (n === null) return !0; var i, e = n; for (i in e) if (Fi.call(e, i) && e[i] !== null) return !1; return !0; } function Oi(n) { return n !== null ? n : {}; } var Ei = new b("tag:yaml.org,2002:set", { kind: "mapping", resolve: Ii, construct: Oi }), Ni = ui.extend({ implicit: [ pi, si ], explicit: [ Ai, Ci, Si, Ei ] }), S = Object.prototype.hasOwnProperty, M = 1, cn = 2, un = 3, D = 4, B = 1, Li = 2, Z = 3, Mi = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/, Di = /[\x85\u2028\u2029]/, Pi = /[,\[\]\{\}]/, fn = /^(?:!|!!|![a-z\-]+!)$/i, tn = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i; function V(n) { return Object.prototype.toString.call(n); } function k(n) { return n === 10 || n === 13; } function F(n) { return n === 9 || n === 32; } function y(n) { return n === 9 || n === 32 || n === 10 || n === 13; } function O(n) { return n === 44 || n === 91 || n === 93 || n === 123 || n === 125; } function ji(n) { var i; return 48 <= n && n <= 57 ? n - 48 : (i = n | 32, 97 <= i && i <= 102 ? i - 97 + 10 : -1); } function Yi(n) { return n === 120 ? 2 : n === 117 ? 4 : n === 85 ? 8 : 0; } function Ri(n) { return 48 <= n && n <= 57 ? n - 48 : -1; } function z(n) { return n === 48 ? "\0" : n === 97 ? "\x07" : n === 98 ? "\b" : n === 116 || n === 9 ? " " : n === 110 ? ` ` : n === 118 ? "\v" : n === 102 ? "\f" : n === 114 ? "\r" : n === 101 ? "\x1B" : n === 32 ? " " : n === 34 ? '"' : n === 47 ? "/" : n === 92 ? "\\" : n === 78 ? "…" : n === 95 ? " " : n === 76 ? "\u2028" : n === 80 ? "\u2029" : ""; } function Bi(n) { return n <= 65535 ? String.fromCharCode(n) : String.fromCharCode( (n - 65536 >> 10) + 55296, (n - 65536 & 1023) + 56320 ); } var an = new Array(256), pn = new Array(256); for (var I = 0; I < 256; I++) an[I] = z(I) ? 1 : 0, pn[I] = z(I); function Ui(n, i) { this.input = n, this.filename = i.filename || null, this.schema = i.schema || Ni, this.onWarning = i.onWarning || null, this.legacy = i.legacy || !1, this.json = i.json || !1, this.listener = i.listener || null, this.implicitTypes = this.schema.compiledImplicit, this.typeMap = this.schema.compiledTypeMap, this.length = n.length, this.position = 0, this.line = 0, this.lineStart = 0, this.lineIndent = 0, this.firstTabInLine = -1, this.documents = []; } function hn(n, i) { var e = { name: n.filename, buffer: n.input.slice(0, -1), // omit trailing \0 position: n.position, line: n.line, column: n.position - n.lineStart }; return e.snippet = Sn(e), new T(i, e); } function a(n, i) { throw hn(n, i); } function P(n, i) { n.onWarning && n.onWarning.call(null, hn(n, i)); } var X = { YAML: function(i, e, o) { var r, c, l; i.version !== null && a(i, "duplication of %YAML directive"), o.length !== 1 && a(i, "YAML directive accepts exactly one argument"), r = /^([0-9]+)\.([0-9]+)$/.exec(o[0]), r === null && a(i, "ill-formed argument of the YAML directive"), c = parseInt(r[1], 10), l = parseInt(r[2], 10), c !== 1 && a(i, "unacceptable YAML version of the document"), i.version = o[0], i.checkLineBreaks = l < 2, l !== 1 && l !== 2 && P(i, "unsupported YAML version of the document"); }, TAG: function(i, e, o) { var r, c; o.length !== 2 && a(i, "TAG directive accepts exactly two arguments"), r = o[0], c = o[1], fn.test(r) || a(i, "ill-formed tag handle (first argument) of the TAG directive"), S.call(i.tagMap, r) && a(i, 'there is a previously declared suffix for "' + r + '" tag handle'), tn.test(c) || a(i, "ill-formed tag prefix (second argument) of the TAG directive"); try { c = decodeURIComponent(c); } catch { a(i, "tag prefix is malformed: " + c); } i.tagMap[r] = c; } }; function _(n, i, e, o) { var r, c, l, u; if (i < e) { if (u = n.input.slice(i, e), o) for (r = 0, c = u.length; r < c; r += 1) l = u.charCodeAt(r), l === 9 || 32 <= l && l <= 1114111 || a(n, "expected valid JSON character"); else Mi.test(u) && a(n, "the stream contains non-printable characters"); n.result += u; } } function J(n, i, e, o) { var r, c, l, u; for (w.isObject(e) || a(n, "cannot merge mappings; the provided source object is unacceptable"), r = Object.keys(e), l = 0, u = r.length; l < u; l += 1) c = r[l], S.call(i, c) || (i[c] = e[c], o[c] = !0); } function E(n, i, e, o, r, c, l, u, f) { var h, s; if (Array.isArray(r)) for (r = Array.prototype.slice.call(r), h = 0, s = r.length; h < s; h += 1) Array.isArray(r[h]) && a(n, "nested arrays are not supported inside keys"), typeof r == "object" && V(r[h]) === "[object Object]" && (r[h] = "[object Object]"); if (typeof r == "object" && V(r) === "[object Object]" && (r = "[object Object]"), r = String(r), i === null && (i = {}), o === "tag:yaml.org,2002:merge") if (Array.isArray(c)) for (h = 0, s = c.length; h < s; h += 1) J(n, i, c[h], e); else J(n, i, c, e); else !n.json && !S.call(e, r) && S.call(i, r) && (n.line = l || n.line, n.lineStart = u || n.lineStart, n.position = f || n.position, a(n, "duplicated mapping key")), r === "__proto__" ? Object.defineProperty(i, r, { configurable: !0, enumerable: !0, writable: !0, value: c }) : i[r] = c, delete e[r]; return i; } function q(n) { var i; i = n.input.charCodeAt(n.position), i === 10 ? n.position++ : i === 13 ? (n.position++, n.input.charCodeAt(n.position) === 10 && n.position++) : a(n, "a line break is expected"), n.line += 1, n.lineStart = n.position, n.firstTabInLine = -1; } function v(n, i, e) { for (var o = 0, r = n.input.charCodeAt(n.position); r !== 0; ) { for (; F(r); ) r === 9 && n.firstTabInLine === -1 && (n.firstTabInLine = n.position), r = n.input.charCodeAt(++n.position); if (i && r === 35) do r = n.input.charCodeAt(++n.position); while (r !== 10 && r !== 13 && r !== 0); if (k(r)) for (q(n), r = n.input.charCodeAt(n.position), o++, n.lineIndent = 0; r === 32; ) n.lineIndent++, r = n.input.charCodeAt(++n.position); else break; } return e !== -1 && o !== 0 && n.lineIndent < e && P(n, "deficient indentation"), o; } function j(n) { var i = n.position, e; return e = n.input.charCodeAt(i), !!((e === 45 || e === 46) && e === n.input.charCodeAt(i + 1) && e === n.input.charCodeAt(i + 2) && (i += 3, e = n.input.charCodeAt(i), e === 0 || y(e))); } function G(n, i) { i === 1 ? n.result += " " : i > 1 && (n.result += w.repeat(` `, i - 1)); } function $i(n, i, e) { var o, r, c, l, u, f, h, s, t = n.kind, m = n.result, p; if (p = n.input.charCodeAt(n.position), y(p) || O(p) || p === 35 || p === 38 || p === 42 || p === 33 || p === 124 || p === 62 || p === 39 || p === 34 || p === 37 || p === 64 || p === 96 || (p === 63 || p === 45) && (r = n.input.charCodeAt(n.position + 1), y(r) || e && O(r))) return !1; for (n.kind = "scalar", n.result = "", c = l = n.position, u = !1; p !== 0; ) { if (p === 58) { if (r = n.input.charCodeAt(n.position + 1), y(r) || e && O(r)) break; } else if (p === 35) { if (o = n.input.charCodeAt(n.position - 1), y(o)) break; } else { if (n.position === n.lineStart && j(n) || e && O(p)) break; if (k(p)) if (f = n.line, h = n.lineStart, s = n.lineIndent, v(n, !1, -1), n.lineIndent >= i) { u = !0, p = n.input.charCodeAt(n.position); continue; } else { n.position = l, n.line = f, n.lineStart = h, n.lineIndent = s; break; } } u && (_(n, c, l, !1), G(n, n.line - f), c = l = n.position, u = !1), F(p) || (l = n.position + 1), p = n.input.charCodeAt(++n.position); } return _(n, c, l, !1), n.result ? !0 : (n.kind = t, n.result = m, !1); } function qi(n, i) { var e, o, r; if (e = n.input.charCodeAt(n.position), e !== 39) return !1; for (n.kind = "scalar", n.result = "", n.position++, o = r = n.position; (e = n.input.charCodeAt(n.position)) !== 0; ) if (e === 39) if (_(n, o, n.position, !0), e = n.input.charCodeAt(++n.position), e === 39) o = n.position, n.position++, r = n.position; else return !0; else k(e) ? (_(n, o, r, !0), G(n, v(n, !1, i)), o = r = n.position) : n.position === n.lineStart && j(n) ? a(n, "unexpected end of the document within a single quoted scalar") : (n.position++, r = n.position); a(n, "unexpected end of the stream within a single quoted scalar"); } function Gi(n, i) { var e, o, r, c, l, u; if (u = n.input.charCodeAt(n.position), u !== 34) return !1; for (n.kind = "scalar", n.result = "", n.position++, e = o = n.position; (u = n.input.charCodeAt(n.position)) !== 0; ) { if (u === 34) return _(n, e, n.position, !0), n.position++, !0; if (u === 92) { if (_(n, e, n.position, !0), u = n.input.charCodeAt(++n.position), k(u)) v(n, !1, i); else if (u < 256 && an[u]) n.result += pn[u], n.position++; else if ((l = Yi(u)) > 0) { for (r = l, c = 0; r > 0; r--) u = n.input.charCodeAt(++n.position), (l = ji(u)) >= 0 ? c = (c << 4) + l : a(n, "expected hexadecimal character"); n.result += Bi(c), n.position++; } else a(n, "unknown escape sequence"); e = o = n.position; } else k(u) ? (_(n, e, o, !0), G(n, v(n, !1, i)), e = o = n.position) : n.position === n.lineStart && j(n) ? a(n, "unexpected end of the document within a double quoted scalar") : (n.position++, o = n.position); } a(n, "unexpected end of the stream within a double quoted scalar"); } function Hi(n, i) { var e = !0, o, r, c, l = n.tag, u, f = n.anchor, h, s, t, m, p, g = /* @__PURE__ */ Object.create(null), A, x, C, d; if (d = n.input.charCodeAt(n.position), d === 91) s = 93, p = !1, u = []; else if (d === 123) s = 125, p = !0, u = {}; else return !1; for (n.anchor !== null && (n.anchorMap[n.anchor] = u), d = n.input.charCodeAt(++n.position); d !== 0; ) { if (v(n, !0, i), d = n.input.charCodeAt(n.position), d === s) return n.position++, n.tag = l, n.anchor = f, n.kind = p ? "mapping" : "sequence", n.result = u, !0; e ? d === 44 && a(n, "expected the node content, but found ','") : a(n, "missed comma between flow collection entries"), x = A = C = null, t = m = !1, d === 63 && (h = n.input.charCodeAt(n.position + 1), y(h) && (t = m = !0, n.position++, v(n, !0, i))), o = n.line, r = n.lineStart, c = n.position, N(n, i, M, !1, !0), x = n.tag, A = n.result, v(n, !0, i), d = n.input.charCodeAt(n.position), (m || n.line === o) && d === 58 && (t = !0, d = n.input.charCodeAt(++n.position), v(n, !0, i), N(n, i, M, !1, !0), C = n.result), p ? E(n, u, g, x, A, C, o, r, c) : t ? u.push(E(n, null, g, x, A, C, o, r, c)) : u.push(A), v(n, !0, i), d = n.input.charCodeAt(n.position), d === 44 ? (e = !0, d = n.input.charCodeAt(++n.position)) : e = !1; } a(n, "unexpected end of the stream within a flow collection"); } function Ki(n, i) { var e, o, r = B, c = !1, l = !1, u = i, f = 0, h = !1, s, t; if (t = n.input.charCodeAt(n.position), t === 124) o = !1; else if (t === 62) o = !0; else return !1; for (n.kind = "scalar", n.result = ""; t !== 0; ) if (t = n.input.charCodeAt(++n.position), t === 43 || t === 45) B === r ? r = t === 43 ? Z : Li : a(n, "repeat of a chomping mode identifier"); else if ((s = Ri(t)) >= 0) s === 0 ? a(n, "bad explicit indentation width of a block scalar; it cannot be less than one") : l ? a(n, "repeat of an indentation width identifier") : (u = i + s - 1, l = !0); else break; if (F(t)) { do t = n.input.charCodeAt(++n.position); while (F(t)); if (t === 35) do t = n.input.charCodeAt(++n.position); while (!k(t) && t !== 0); } for (; t !== 0; ) { for (q(n), n.lineIndent = 0, t = n.input.charCodeAt(n.position); (!l || n.lineIndent < u) && t === 32; ) n.lineIndent++, t = n.input.charCodeAt(++n.position); if (!l && n.lineIndent > u && (u = n.lineIndent), k(t)) { f++; continue; } if (n.lineIndent < u) { r === Z ? n.result += w.repeat(` `, c ? 1 + f : f) : r === B && c && (n.result += ` `); break; } for (o ? F(t) ? (h = !0, n.result += w.repeat(` `, c ? 1 + f : f)) : h ? (h = !1, n.result += w.repeat(` `, f + 1)) : f === 0 ? c && (n.result += " ") : n.result += w.repeat(` `, f) : n.result += w.repeat(` `, c ? 1 + f : f), c = !0, l = !0, f = 0, e = n.position; !k(t) && t !== 0; ) t = n.input.charCodeAt(++n.position); _(n, e, n.position, !1); } return !0; } function Q(n, i) { var e, o = n.tag, r = n.anchor, c = [], l, u = !1, f; if (n.firstTabInLine !== -1) return !1; for (n.anchor !== null && (n.anchorMap[n.anchor] = c), f = n.input.charCodeAt(n.position); f !== 0 && (n.firstTabInLine !== -1 && (n.position = n.firstTabInLine, a(n, "tab characters must not be used in indentation")), !(f !== 45 || (l = n.input.charCodeAt(n.position + 1), !y(l)))); ) { if (u = !0, n.position++, v(n, !0, -1) && n.lineIndent <= i) { c.push(null), f = n.input.charCodeAt(n.position); continue; } if (e = n.line, N(n, i, un, !1, !0), c.push(n.result), v(n, !0, -1), f = n.input.charCodeAt(n.position), (n.line === e || n.lineIndent > i) && f !== 0) a(n, "bad indentation of a sequence entry"); else if (n.lineIndent < i) break; } return u ? (n.tag = o, n.anchor = r, n.kind = "sequence", n.result = c, !0) : !1; } function Wi(n, i, e) { var o, r, c, l, u, f, h = n.tag, s = n.anchor, t = {}, m = /* @__PURE__ */ Object.create(null), p = null, g = null, A = null, x = !1, C = !1, d; if (n.firstTabInLine !== -1) return !1; for (n.anchor !== null && (n.anchorMap[n.anchor] = t), d = n.input.charCodeAt(n.position); d !== 0; ) { if (!x && n.firstTabInLine !== -1 && (n.position = n.firstTabInLine, a(n, "tab characters must not be used in indentation")), o = n.input.charCodeAt(n.position + 1), c = n.line, (d === 63 || d === 58) && y(o)) d === 63 ? (x && (E(n, t, m, p, g, null, l, u, f), p = g = A = null), C = !0, x = !0, r = !0) : x ? (x = !1, r = !0) : a(n, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"), n.position += 1, d = o; else { if (l = n.line, u = n.lineStart, f = n.position, !N(n, e, cn, !1, !0)) break; if (n.line === c) { for (d = n.input.charCodeAt(n.position); F(d); ) d = n.input.charCodeAt(++n.position); if (d === 58) d = n.input.charCodeAt(++n.position), y(d) || a(n, "a whitespace character is expected after the key-value separator within a block mapping"), x && (E(n, t, m, p, g, null, l, u, f), p = g = A = null), C = !0, x = !1, r = !1, p = n.tag, g = n.result; else if (C) a(n, "can not read an implicit mapping pair; a colon is missed"); else return n.tag = h, n.anchor = s, !0; } else if (C) a(n, "can not read a block mapping entry; a multiline key may not be an implicit key"); else return n.tag = h, n.anchor = s, !0; } if ((n.line === c || n.lineIndent > i) && (x && (l = n.line, u = n.lineStart, f = n.position), N(n, i, D, !0, r) && (x ? g = n.result : A = n.result), x || (E(n, t, m, p, g, A, l, u, f), p = g = A = null), v(n, !0, -1), d = n.input.charCodeAt(n.position)), (n.line === c || n.lineIndent > i) && d !== 0) a(n, "bad indentation of a mapping entry"); else if (n.lineIndent < i) break; } return x && E(n, t, m, p, g, null, l, u, f), C && (n.tag = h, n.anchor = s, n.kind = "mapping", n.result = t), C; } function Zi(n) { var i, e = !1, o = !1, r, c, l; if (l = n.input.charCodeAt(n.position), l !== 33) return !1; if (n.tag !== null && a(n, "duplication of a tag property"), l = n.input.charCodeAt(++n.position), l === 60 ? (e = !0, l = n.input.charCodeAt(++n.position)) : l === 33 ? (o = !0, r = "!!", l = n.input.charCodeAt(++n.position)) : r = "!", i = n.position, e) { do l = n.input.charCodeAt(++n.position); while (l !== 0 && l !== 62); n.position < n.length ? (c = n.input.slice(i, n.position), l = n.input.charCodeAt(++n.position)) : a(n, "unexpected end of the stream within a verbatim tag"); } else { for (; l !== 0 && !y(l); ) l === 33 && (o ? a(n, "tag suffix cannot contain exclamation marks") : (r = n.input.slice(i - 1, n.position + 1), fn.test(r) || a(n, "named tag handle cannot contain such characters"), o = !0, i = n.position + 1)), l = n.input.charCodeAt(++n.position); c = n.input.slice(i, n.position), Pi.test(c) && a(n, "tag suffix cannot contain flow indicator characters"); } c && !tn.test(c) && a(n, "tag name cannot contain such characters: " + c); try { c = decodeURIComponent(c); } catch { a(n, "tag name is malformed: " + c); } return e ? n.tag = c : S.call(n.tagMap, r) ? n.tag = n.tagMap[r] + c : r === "!" ? n.tag = "!" + c : r === "!!" ? n.tag = "tag:yaml.org,2002:" + c : a(n, 'undeclared tag handle "' + r + '"'), !0; } function Vi(n) { var i, e; if (e = n.input.charCodeAt(n.position), e !== 38) return !1; for (n.anchor !== null && a(n, "duplication of an anchor property"), e = n.input.charCodeAt(++n.position), i = n.position; e !== 0 && !y(e) && !O(e); ) e = n.input.charCodeAt(++n.position); return n.position === i && a(n, "name of an anchor node must contain at least one character"), n.anchor = n.input.slice(i, n.position), !0; } function zi(n) { var i, e, o; if (o = n.input.charCodeAt(n.position), o !== 42) return !1; for (o = n.input.charCodeAt(++n.position), i = n.position; o !== 0 && !y(o) && !O(o); ) o = n.input.charCodeAt(++n.position); return n.position === i && a(n, "name of an alias node must contain at least one character"), e = n.input.slice(i, n.position), S.call(n.anchorMap, e) || a(n, 'unidentified alias "' + e + '"'), n.result = n.anchorMap[e], v(n, !0, -1), !0; } function N(n, i, e, o, r) { var c, l, u, f = 1, h = !1, s = !1, t, m, p, g, A, x; if (n.listener !== null && n.listener("open", n), n.tag = null, n.anchor = null, n.kind = null, n.result = null, c = l = u = D === e || un === e, o && v(n, !0, -1) && (h = !0, n.lineIndent > i ? f = 1 : n.lineIndent === i ? f = 0 : n.lineIndent < i && (f = -1)), f === 1) for (; Zi(n) || Vi(n); ) v(n, !0, -1) ? (h = !0, u = c, n.lineIndent > i ? f = 1 : n.lineIndent === i ? f = 0 : n.lineIndent < i && (f = -1)) : u = !1; if (u && (u = h || r), (f === 1 || D === e) && (M === e || cn === e ? A = i : A = i + 1, x = n.position - n.lineStart, f === 1 ? u && (Q(n, x) || Wi(n, x, A)) || Hi(n, A) ? s = !0 : (l && Ki(n, A) || qi(n, A) || Gi(n, A) ? s = !0 : zi(n) ? (s = !0, (n.tag !== null || n.anchor !== null) && a(n, "alias node should not have any properties")) : $i(n, A, M === e) && (s = !0, n.tag === null && (n.tag = "?")), n.anchor !== null && (n.anchorMap[n.anchor] = n.result)) : f === 0 && (s = u && Q(n, x))), n.tag === null) n.anchor !== null && (n.anchorMap[n.anchor] = n.result); else if (n.tag === "?") { for (n.result !== null && n.kind !== "scalar" && a(n, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + n.kind + '"'), t = 0, m = n.implicitTypes.length; t < m; t += 1) if (g = n.implicitTypes[t], g.resolve(n.result)) { n.result = g.construct(n.result), n.tag = g.tag, n.anchor !== null && (n.anchorMap[n.anchor] = n.result); break; } } else if (n.tag !== "!") { if (S.call(n.typeMap[n.kind || "fallback"], n.tag)) g = n.typeMap[n.kind || "fallback"][n.tag]; else for (g = null, p = n.typeMap.multi[n.kind || "fallback"], t = 0, m = p.length; t < m; t += 1) if (n.tag.slice(0, p[t].tag.length) === p[t].tag) { g = p[t]; break; } g || a(n, "unknown tag !<" + n.tag + ">"), n.result !== null && g.kind !== n.kind && a(n, "unacceptable node kind for !<" + n.tag + '> tag; it should be "' + g.kind + '", not "' + n.kind + '"'), g.resolve(n.result, n.tag) ? (n.result = g.construct(n.result, n.tag), n.anchor !== null && (n.anchorMap[n.anchor] = n.result)) : a(n, "cannot resolve a node with !<" + n.tag + "> explicit tag"); } return n.listener !== null && n.listener("close", n), n.tag !== null || n.anchor !== null || s; } function Xi(n) { var i = n.position, e, o, r, c = !1, l; for (n.version = null, n.checkLineBreaks = n.legacy, n.tagMap = /* @__PURE__ */ Object.create(null), n.anchorMap = /* @__PURE__ */ Object.create(null); (l = n.input.charCodeAt(n.position)) !== 0 && (v(n, !0, -1), l = n.input.charCodeAt(n.position), !(n.lineIndent > 0 || l !== 37)); ) { for (c = !0, l = n.input.charCodeAt(++n.position), e = n.position; l !== 0 && !y(l); ) l = n.input.charCodeAt(++n.position); for (o = n.input.slice(e, n.position), r = [], o.length < 1 && a(n, "directive name must not be less than one character in length"); l !== 0; ) { for (; F(l); ) l = n.input.charCodeAt(++n.position); if (l === 35) { do l = n.input.charCodeAt(++n.position); while (l !== 0 && !k(l)); break; } if (k(l)) break; for (e = n.position; l !== 0 && !y(l); ) l = n.input.charCodeAt(++n.position); r.push(n.input.slice(e, n.position)); } l !== 0 && q(n), S.call(X, o) ? X[o](n, o, r) : P(n, 'unknown document directive "' + o + '"'); } if (v(n, !0, -1), n.lineIndent === 0 && n.input.charCodeAt(n.position) === 45 && n.input.charCodeAt(n.position + 1) === 45 && n.input.charCodeAt(n.position + 2) === 45 ? (n.position += 3, v(n, !0, -1)) : c && a(n, "directives end mark is expected"), N(n, n.lineIndent - 1, D, !1, !0), v(n, !0, -1), n.checkLineBreaks && Di.test(n.input.slice(i, n.position)) && P(n, "non-ASCII line breaks are interpreted as content"), n.documents.push(n.result), n.position === n.lineStart && j(n)) { n.input.charCodeAt(n.position) === 46 && (n.position += 3, v(n, !0, -1)); return; } if (n.position < n.length - 1) a(n, "end of the stream or a document separator is expected"); else return; } function Ji(n, i) { n = String(n), i = i || {}, n.length !== 0 && (n.charCodeAt(n.length - 1) !== 10 && n.charCodeAt(n.length - 1) !== 13 && (n += ` `), n.charCodeAt(0) === 65279 && (n = n.slice(1))); var e = new Ui(n, i), o = n.indexOf("\0"); for (o !== -1 && (e.position = o, a(e, "null byte is not allowed in input")), e.input += "\0"; e.input.charCodeAt(e.position) === 32; ) e.lineIndent += 1, e.position += 1; for (; e.position < e.length - 1; ) Xi(e); return e.documents; } function Qi(n, i) { var e = Ji(n, i); if (e.length !== 0) { if (e.length === 1) return e[0]; throw new T("expected a single document in the stream, but found more"); } } var ne = Qi, ie = { load: ne }, ee = ie.load; function sn(n) { const i = { showToolbar: !0, markmap: {} }, e = n.match(/^---\s*([\s\S]*?)\s*---/); if (!e) return i; const o = e[1]; try { const r = ee(o); r && typeof r == "object" && (typeof r.showToolbar == "boolean" && (i.showToolbar = r.showToolbar), r.markmap && typeof r.markmap == "object" && (i.markmap = r.markmap)); } catch (r) { console.warn("解析 frontmatter 失败:", r); } return i; } function dn(n) { return n.replace(/^---\s*[\s\S]*?---\s*/, ""); } function re(n, i) { const e = n.renderer.rules.fence; n.renderer.rules.fence = (o, r, c, l, u) => { const f = o[r]; if ((f.info.trim() || "text") === "markmap") { const s = sn(f.content), t = s.showToolbar ?? i.showToolbar !== !1, m = dn(f.content), p = JSON.stringify(s.markmap || {}); return ` <ClientOnly> <MarkmapRoot markdown="${encodeURIComponent(m)}" showToolbar="${t ? 1 : 0}" config="${encodeURIComponent(p)}" /> </ClientOnly> `; } return e(o, r, c, l, u); }; } const oe = /<PreviewMarkmapPath\s*(.*?)\s*\/>/g, le = /<PreviewMarkmapPath\s*(.*?)><\/PreviewMarkmapPath>/g; function ce(n) { const i = /path=['"](.*?)['"]/.exec(n); return i ? i[1] : ""; } const ue = /(<\/?[A-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*(?:\s[^>]*?)?\/?>)/gs; function fe(n) { return n.replace(ue, "`$1`"); } function nn(n, i, e) { try { const o = /\bshowToolbar\b/i.test(n) || e.showToolbar, r = ce(n); let c = "", l = ""; if (i && i.path ? l = K.dirname(i.path) : process.cwd && (l = process.cwd()), r) { const m = K.resolve(l, r); try { c = H.readFileSync(m, "utf-8"); } catch (p) { console.error(`无法读取文件: ${m}`, p), c = `# 文件读取失败 无法加载: ${r}`; } } else if (i && i.path) try { c = H.readFileSync(i.path, "utf-8"); } catch (m) { console.error(`无法读取当前MD文件: ${i.path}`, m), c = `# 文件读取失败 无法加载: 当前文档`; } else c = `# 文件读取失败 未指定 path,且无法获取当前文档路径`; const u = sn(c), f = u.showToolbar ?? o, h = dn(c), s = fe(h), t = JSON.stringify(u.markmap || {}); return ` <ClientOnly> <MarkmapRoot markdown="${encodeURIComponent(s)}" showToolbar="${f ? 1 : 0}" config="${encodeURIComponent(t)}" /> </ClientOnly> `; } catch (o) { return console.error("处理ReviewMarkmap组件时出错:", o), '<div class="markmap-error">加载思维导图失败</div>'; } } function te(n, i) { const e = n.render; n.render = function(o, r) { let c = e.call(this, o, r); return c = c.replace(oe, (l, u) => nn(u, r, i)), c = c.replace(le, (l, u) => nn(u, r, i)), c; }; } const ae = { showToolbar: !1 }; function se(n, i = ae) { re(n, i), te(n, i); } export { se as vitepressMarkmapPreview };