velite
Version:
Turns Markdown / MDX, YAML, JSON, or other files into app's data layer with type-safe schema.
1,641 lines (1,605 loc) • 178 kB
JavaScript
import { createRequire } from 'module';
import { zwitch, convert, asciiAlphanumeric, asciiAlpha, markdownLineEndingOrSpace, unicodeWhitespace, unicodePunctuation, zod_exports, svg, asciiControl, ok, VFile, find, stringify, stringify2, custom, stringType, isRelativePath, processAsset, getImageMetadata, fromMarkdown, remarkCopyLinkedFiles, rehypeCopyLinkedFiles, toHast, visit, raw, html, htmlVoidElements, toString, combineExtensions, splice, resolveAll, classifyCharacter, normalizeIdentifier, blankLine, factorySpace, markdownLineEnding, markdownSpace, esm_default, visitParents, EXIT } from './chunk-CA5YBCFK.js';
export { VeliteFile, assets, build, defineCollection, defineConfig, defineLoader, defineSchema, getImageMetadata, isRelativePath, logger, processAsset, rehypeCopyLinkedFiles, remarkCopyLinkedFiles, zod_exports as z } from './chunk-CA5YBCFK.js';
import { __commonJS, __toESM } from './chunk-ZWVIC74Y.js';
import { readFile } from 'fs/promises';
import { join, relative } from 'path';
createRequire(import.meta.url);
// node_modules/.pnpm/extend@3.0.2/node_modules/extend/index.js
var require_extend = __commonJS({
"node_modules/.pnpm/extend@3.0.2/node_modules/extend/index.js"(exports, module) {
var hasOwn = Object.prototype.hasOwnProperty;
var toStr = Object.prototype.toString;
var defineProperty = Object.defineProperty;
var gOPD = Object.getOwnPropertyDescriptor;
var isArray = function isArray2(arr) {
if (typeof Array.isArray === "function") {
return Array.isArray(arr);
}
return toStr.call(arr) === "[object Array]";
};
var isPlainObject2 = function isPlainObject3(obj) {
if (!obj || toStr.call(obj) !== "[object Object]") {
return false;
}
var hasOwnConstructor = hasOwn.call(obj, "constructor");
var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, "isPrototypeOf");
if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
return false;
}
var key2;
for (key2 in obj) {
}
return typeof key2 === "undefined" || hasOwn.call(obj, key2);
};
var setProperty = function setProperty2(target, options) {
if (defineProperty && options.name === "__proto__") {
defineProperty(target, options.name, {
enumerable: true,
configurable: true,
value: options.newValue,
writable: true
});
} else {
target[options.name] = options.newValue;
}
};
var getProperty = function getProperty2(obj, name) {
if (name === "__proto__") {
if (!hasOwn.call(obj, name)) {
return void 0;
} else if (gOPD) {
return gOPD(obj, name).value;
}
}
return obj[name];
};
module.exports = function extend2() {
var options, name, src, copy, copyIsArray, clone;
var target = arguments[0];
var i = 1;
var length = arguments.length;
var deep = false;
if (typeof target === "boolean") {
deep = target;
target = arguments[1] || {};
i = 2;
}
if (target == null || typeof target !== "object" && typeof target !== "function") {
target = {};
}
for (; i < length; ++i) {
options = arguments[i];
if (options != null) {
for (name in options) {
src = getProperty(target, name);
copy = getProperty(options, name);
if (target !== copy) {
if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray(copy)))) {
if (copyIsArray) {
copyIsArray = false;
clone = src && isArray(src) ? src : [];
} else {
clone = src && isPlainObject2(src) ? src : {};
}
setProperty(target, { name, newValue: extend2(deep, clone, copy) });
} else if (typeof copy !== "undefined") {
setProperty(target, { name, newValue: copy });
}
}
}
}
}
return target;
};
}
});
// src/schemas/excerpt.ts
var excerpt = ({ length = 260 } = {}) => custom((i) => i === void 0 || typeof i === "string").transform(async (value, { meta, addIssue }) => {
value = value ?? meta.plain;
if (value == null || value.length === 0) {
addIssue({ code: "custom", message: "The content is empty" });
return "";
}
return value.slice(0, length);
});
// src/schemas/file.ts
var file = ({ allowNonRelativePath = true } = {}) => stringType().transform(async (value, { meta, addIssue }) => {
try {
if (allowNonRelativePath && !isRelativePath(value)) return value;
const { output } = meta.config;
return await processAsset(value, meta.path, output.name, output.base);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
addIssue({ fatal: true, code: "custom", message });
return null;
}
});
var image = ({ absoluteRoot } = {}) => stringType().transform(async (value, { meta, addIssue }) => {
try {
if (absoluteRoot && /^\//.test(value)) {
const buffer = await readFile(join(absoluteRoot, value));
const metadata2 = await getImageMetadata(buffer);
if (metadata2 == null) throw new Error(`Failed to get image metadata: ${value}`);
return { src: value, ...metadata2 };
}
const { output } = meta.config;
return await processAsset(value, meta.path, output.name, output.base, true);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
addIssue({ fatal: true, code: "custom", message });
return null;
}
});
// src/schemas/isodate.ts
var isodate = () => stringType().refine((value) => !isNaN(Date.parse(value)), "Invalid date string").transform((value) => new Date(value).toISOString());
// node_modules/.pnpm/rehype-raw@7.0.0/node_modules/rehype-raw/lib/index.js
function rehypeRaw(options) {
return function(tree, file2) {
const result = (
/** @type {Root} */
raw(tree, { ...options, file: file2 })
);
return result;
};
}
// node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/core.js
var defaultSubsetRegex = /["&'<>`]/g;
var surrogatePairsRegex = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
var controlCharactersRegex = (
// eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
);
var regexEscapeRegex = /[|\\{}()[\]^$+*?.]/g;
var subsetToRegexCache = /* @__PURE__ */ new WeakMap();
function core(value, options) {
value = value.replace(
options.subset ? charactersToExpressionCached(options.subset) : defaultSubsetRegex,
basic
);
if (options.subset || options.escapeOnly) {
return value;
}
return value.replace(surrogatePairsRegex, surrogate).replace(controlCharactersRegex, basic);
function surrogate(pair, index, all3) {
return options.format(
(pair.charCodeAt(0) - 55296) * 1024 + pair.charCodeAt(1) - 56320 + 65536,
all3.charCodeAt(index + 2),
options
);
}
function basic(character, index, all3) {
return options.format(
character.charCodeAt(0),
all3.charCodeAt(index + 1),
options
);
}
}
function charactersToExpressionCached(subset) {
let cached = subsetToRegexCache.get(subset);
if (!cached) {
cached = charactersToExpression(subset);
subsetToRegexCache.set(subset, cached);
}
return cached;
}
function charactersToExpression(subset) {
const groups = [];
let index = -1;
while (++index < subset.length) {
groups.push(subset[index].replace(regexEscapeRegex, "\\$&"));
}
return new RegExp("(?:" + groups.join("|") + ")", "g");
}
// node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/util/to-hexadecimal.js
var hexadecimalRegex = /[\dA-Fa-f]/;
function toHexadecimal(code3, next, omit) {
const value = "&#x" + code3.toString(16).toUpperCase();
return omit && next && !hexadecimalRegex.test(String.fromCharCode(next)) ? value : value + ";";
}
// node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/util/to-decimal.js
var decimalRegex = /\d/;
function toDecimal(code3, next, omit) {
const value = "&#" + String(code3);
return omit && next && !decimalRegex.test(String.fromCharCode(next)) ? value : value + ";";
}
// node_modules/.pnpm/character-entities-legacy@3.0.0/node_modules/character-entities-legacy/index.js
var characterEntitiesLegacy = [
"AElig",
"AMP",
"Aacute",
"Acirc",
"Agrave",
"Aring",
"Atilde",
"Auml",
"COPY",
"Ccedil",
"ETH",
"Eacute",
"Ecirc",
"Egrave",
"Euml",
"GT",
"Iacute",
"Icirc",
"Igrave",
"Iuml",
"LT",
"Ntilde",
"Oacute",
"Ocirc",
"Ograve",
"Oslash",
"Otilde",
"Ouml",
"QUOT",
"REG",
"THORN",
"Uacute",
"Ucirc",
"Ugrave",
"Uuml",
"Yacute",
"aacute",
"acirc",
"acute",
"aelig",
"agrave",
"amp",
"aring",
"atilde",
"auml",
"brvbar",
"ccedil",
"cedil",
"cent",
"copy",
"curren",
"deg",
"divide",
"eacute",
"ecirc",
"egrave",
"eth",
"euml",
"frac12",
"frac14",
"frac34",
"gt",
"iacute",
"icirc",
"iexcl",
"igrave",
"iquest",
"iuml",
"laquo",
"lt",
"macr",
"micro",
"middot",
"nbsp",
"not",
"ntilde",
"oacute",
"ocirc",
"ograve",
"ordf",
"ordm",
"oslash",
"otilde",
"ouml",
"para",
"plusmn",
"pound",
"quot",
"raquo",
"reg",
"sect",
"shy",
"sup1",
"sup2",
"sup3",
"szlig",
"thorn",
"times",
"uacute",
"ucirc",
"ugrave",
"uml",
"uuml",
"yacute",
"yen",
"yuml"
];
// node_modules/.pnpm/character-entities-html4@2.1.0/node_modules/character-entities-html4/index.js
var characterEntitiesHtml4 = {
nbsp: "\xA0",
iexcl: "\xA1",
cent: "\xA2",
pound: "\xA3",
curren: "\xA4",
yen: "\xA5",
brvbar: "\xA6",
sect: "\xA7",
uml: "\xA8",
copy: "\xA9",
ordf: "\xAA",
laquo: "\xAB",
not: "\xAC",
shy: "\xAD",
reg: "\xAE",
macr: "\xAF",
deg: "\xB0",
plusmn: "\xB1",
sup2: "\xB2",
sup3: "\xB3",
acute: "\xB4",
micro: "\xB5",
para: "\xB6",
middot: "\xB7",
cedil: "\xB8",
sup1: "\xB9",
ordm: "\xBA",
raquo: "\xBB",
frac14: "\xBC",
frac12: "\xBD",
frac34: "\xBE",
iquest: "\xBF",
Agrave: "\xC0",
Aacute: "\xC1",
Acirc: "\xC2",
Atilde: "\xC3",
Auml: "\xC4",
Aring: "\xC5",
AElig: "\xC6",
Ccedil: "\xC7",
Egrave: "\xC8",
Eacute: "\xC9",
Ecirc: "\xCA",
Euml: "\xCB",
Igrave: "\xCC",
Iacute: "\xCD",
Icirc: "\xCE",
Iuml: "\xCF",
ETH: "\xD0",
Ntilde: "\xD1",
Ograve: "\xD2",
Oacute: "\xD3",
Ocirc: "\xD4",
Otilde: "\xD5",
Ouml: "\xD6",
times: "\xD7",
Oslash: "\xD8",
Ugrave: "\xD9",
Uacute: "\xDA",
Ucirc: "\xDB",
Uuml: "\xDC",
Yacute: "\xDD",
THORN: "\xDE",
szlig: "\xDF",
agrave: "\xE0",
aacute: "\xE1",
acirc: "\xE2",
atilde: "\xE3",
auml: "\xE4",
aring: "\xE5",
aelig: "\xE6",
ccedil: "\xE7",
egrave: "\xE8",
eacute: "\xE9",
ecirc: "\xEA",
euml: "\xEB",
igrave: "\xEC",
iacute: "\xED",
icirc: "\xEE",
iuml: "\xEF",
eth: "\xF0",
ntilde: "\xF1",
ograve: "\xF2",
oacute: "\xF3",
ocirc: "\xF4",
otilde: "\xF5",
ouml: "\xF6",
divide: "\xF7",
oslash: "\xF8",
ugrave: "\xF9",
uacute: "\xFA",
ucirc: "\xFB",
uuml: "\xFC",
yacute: "\xFD",
thorn: "\xFE",
yuml: "\xFF",
fnof: "\u0192",
Alpha: "\u0391",
Beta: "\u0392",
Gamma: "\u0393",
Delta: "\u0394",
Epsilon: "\u0395",
Zeta: "\u0396",
Eta: "\u0397",
Theta: "\u0398",
Iota: "\u0399",
Kappa: "\u039A",
Lambda: "\u039B",
Mu: "\u039C",
Nu: "\u039D",
Xi: "\u039E",
Omicron: "\u039F",
Pi: "\u03A0",
Rho: "\u03A1",
Sigma: "\u03A3",
Tau: "\u03A4",
Upsilon: "\u03A5",
Phi: "\u03A6",
Chi: "\u03A7",
Psi: "\u03A8",
Omega: "\u03A9",
alpha: "\u03B1",
beta: "\u03B2",
gamma: "\u03B3",
delta: "\u03B4",
epsilon: "\u03B5",
zeta: "\u03B6",
eta: "\u03B7",
theta: "\u03B8",
iota: "\u03B9",
kappa: "\u03BA",
lambda: "\u03BB",
mu: "\u03BC",
nu: "\u03BD",
xi: "\u03BE",
omicron: "\u03BF",
pi: "\u03C0",
rho: "\u03C1",
sigmaf: "\u03C2",
sigma: "\u03C3",
tau: "\u03C4",
upsilon: "\u03C5",
phi: "\u03C6",
chi: "\u03C7",
psi: "\u03C8",
omega: "\u03C9",
thetasym: "\u03D1",
upsih: "\u03D2",
piv: "\u03D6",
bull: "\u2022",
hellip: "\u2026",
prime: "\u2032",
Prime: "\u2033",
oline: "\u203E",
frasl: "\u2044",
weierp: "\u2118",
image: "\u2111",
real: "\u211C",
trade: "\u2122",
alefsym: "\u2135",
larr: "\u2190",
uarr: "\u2191",
rarr: "\u2192",
darr: "\u2193",
harr: "\u2194",
crarr: "\u21B5",
lArr: "\u21D0",
uArr: "\u21D1",
rArr: "\u21D2",
dArr: "\u21D3",
hArr: "\u21D4",
forall: "\u2200",
part: "\u2202",
exist: "\u2203",
empty: "\u2205",
nabla: "\u2207",
isin: "\u2208",
notin: "\u2209",
ni: "\u220B",
prod: "\u220F",
sum: "\u2211",
minus: "\u2212",
lowast: "\u2217",
radic: "\u221A",
prop: "\u221D",
infin: "\u221E",
ang: "\u2220",
and: "\u2227",
or: "\u2228",
cap: "\u2229",
cup: "\u222A",
int: "\u222B",
there4: "\u2234",
sim: "\u223C",
cong: "\u2245",
asymp: "\u2248",
ne: "\u2260",
equiv: "\u2261",
le: "\u2264",
ge: "\u2265",
sub: "\u2282",
sup: "\u2283",
nsub: "\u2284",
sube: "\u2286",
supe: "\u2287",
oplus: "\u2295",
otimes: "\u2297",
perp: "\u22A5",
sdot: "\u22C5",
lceil: "\u2308",
rceil: "\u2309",
lfloor: "\u230A",
rfloor: "\u230B",
lang: "\u2329",
rang: "\u232A",
loz: "\u25CA",
spades: "\u2660",
clubs: "\u2663",
hearts: "\u2665",
diams: "\u2666",
quot: '"',
amp: "&",
lt: "<",
gt: ">",
OElig: "\u0152",
oelig: "\u0153",
Scaron: "\u0160",
scaron: "\u0161",
Yuml: "\u0178",
circ: "\u02C6",
tilde: "\u02DC",
ensp: "\u2002",
emsp: "\u2003",
thinsp: "\u2009",
zwnj: "\u200C",
zwj: "\u200D",
lrm: "\u200E",
rlm: "\u200F",
ndash: "\u2013",
mdash: "\u2014",
lsquo: "\u2018",
rsquo: "\u2019",
sbquo: "\u201A",
ldquo: "\u201C",
rdquo: "\u201D",
bdquo: "\u201E",
dagger: "\u2020",
Dagger: "\u2021",
permil: "\u2030",
lsaquo: "\u2039",
rsaquo: "\u203A",
euro: "\u20AC"
};
// node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/constant/dangerous.js
var dangerous = [
"cent",
"copy",
"divide",
"gt",
"lt",
"not",
"para",
"times"
];
// node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/util/to-named.js
var own = {}.hasOwnProperty;
var characters = {};
var key;
for (key in characterEntitiesHtml4) {
if (own.call(characterEntitiesHtml4, key)) {
characters[characterEntitiesHtml4[key]] = key;
}
}
var notAlphanumericRegex = /[^\dA-Za-z]/;
function toNamed(code3, next, omit, attribute) {
const character = String.fromCharCode(code3);
if (own.call(characters, character)) {
const name = characters[character];
const value = "&" + name;
if (omit && characterEntitiesLegacy.includes(name) && !dangerous.includes(name) && (!attribute || next && next !== 61 && notAlphanumericRegex.test(String.fromCharCode(next)))) {
return value;
}
return value + ";";
}
return "";
}
// node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/util/format-smart.js
function formatSmart(code3, next, options) {
let numeric = toHexadecimal(code3, next, options.omitOptionalSemicolons);
let named;
if (options.useNamedReferences || options.useShortestReferences) {
named = toNamed(
code3,
next,
options.omitOptionalSemicolons,
options.attribute
);
}
if ((options.useShortestReferences || !named) && options.useShortestReferences) {
const decimal = toDecimal(code3, next, options.omitOptionalSemicolons);
if (decimal.length < numeric.length) {
numeric = decimal;
}
}
return named && (!options.useShortestReferences || named.length < numeric.length) ? named : numeric;
}
// node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/index.js
function stringifyEntities(value, options) {
return core(value, Object.assign({ format: formatSmart }, options));
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/handle/comment.js
var htmlCommentRegex = /^>|^->|<!--|-->|--!>|<!-$/g;
var bogusCommentEntitySubset = [">"];
var commentEntitySubset = ["<", ">"];
function comment(node, _1, _2, state) {
return state.settings.bogusComments ? "<?" + stringifyEntities(
node.value,
Object.assign({}, state.settings.characterReferences, {
subset: bogusCommentEntitySubset
})
) + ">" : "<!--" + node.value.replace(htmlCommentRegex, encode) + "-->";
function encode($0) {
return stringifyEntities(
$0,
Object.assign({}, state.settings.characterReferences, {
subset: commentEntitySubset
})
);
}
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/handle/doctype.js
function doctype(_1, _2, _3, state) {
return "<!" + (state.settings.upperDoctype ? "DOCTYPE" : "doctype") + (state.settings.tightDoctype ? "" : " ") + "html>";
}
// node_modules/.pnpm/ccount@2.0.1/node_modules/ccount/index.js
function ccount(value, character) {
const source = String(value);
if (typeof character !== "string") {
throw new TypeError("Expected character");
}
let count = 0;
let index = source.indexOf(character);
while (index !== -1) {
count++;
index = source.indexOf(character, index + character.length);
}
return count;
}
// node_modules/.pnpm/hast-util-whitespace@3.0.0/node_modules/hast-util-whitespace/lib/index.js
var re = /[ \t\n\f\r]/g;
function whitespace(thing) {
return typeof thing === "object" ? thing.type === "text" ? empty(thing.value) : false : empty(thing);
}
function empty(value) {
return value.replace(re, "") === "";
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/omission/util/siblings.js
var siblingAfter = siblings(1);
var siblingBefore = siblings(-1);
var emptyChildren = [];
function siblings(increment) {
return sibling;
function sibling(parent, index, includeWhitespace) {
const siblings2 = parent ? parent.children : emptyChildren;
let offset = (index || 0) + increment;
let next = siblings2[offset];
if (!includeWhitespace) {
while (next && whitespace(next)) {
offset += increment;
next = siblings2[offset];
}
}
return next;
}
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/omission/omission.js
var own2 = {}.hasOwnProperty;
function omission(handlers) {
return omit;
function omit(node, index, parent) {
return own2.call(handlers, node.tagName) && handlers[node.tagName](node, index, parent);
}
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/omission/closing.js
var closing = omission({
body,
caption: headOrColgroupOrCaption,
colgroup: headOrColgroupOrCaption,
dd,
dt,
head: headOrColgroupOrCaption,
html: html2,
li,
optgroup,
option,
p,
rp: rubyElement,
rt: rubyElement,
tbody,
td: cells,
tfoot,
th: cells,
thead,
tr
});
function headOrColgroupOrCaption(_, index, parent) {
const next = siblingAfter(parent, index, true);
return !next || next.type !== "comment" && !(next.type === "text" && whitespace(next.value.charAt(0)));
}
function html2(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type !== "comment";
}
function body(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type !== "comment";
}
function p(_, index, parent) {
const next = siblingAfter(parent, index);
return next ? next.type === "element" && (next.tagName === "address" || next.tagName === "article" || next.tagName === "aside" || next.tagName === "blockquote" || next.tagName === "details" || next.tagName === "div" || next.tagName === "dl" || next.tagName === "fieldset" || next.tagName === "figcaption" || next.tagName === "figure" || next.tagName === "footer" || next.tagName === "form" || next.tagName === "h1" || next.tagName === "h2" || next.tagName === "h3" || next.tagName === "h4" || next.tagName === "h5" || next.tagName === "h6" || next.tagName === "header" || next.tagName === "hgroup" || next.tagName === "hr" || next.tagName === "main" || next.tagName === "menu" || next.tagName === "nav" || next.tagName === "ol" || next.tagName === "p" || next.tagName === "pre" || next.tagName === "section" || next.tagName === "table" || next.tagName === "ul") : !parent || // Confusing parent.
!(parent.type === "element" && (parent.tagName === "a" || parent.tagName === "audio" || parent.tagName === "del" || parent.tagName === "ins" || parent.tagName === "map" || parent.tagName === "noscript" || parent.tagName === "video"));
}
function li(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type === "element" && next.tagName === "li";
}
function dt(_, index, parent) {
const next = siblingAfter(parent, index);
return Boolean(
next && next.type === "element" && (next.tagName === "dt" || next.tagName === "dd")
);
}
function dd(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type === "element" && (next.tagName === "dt" || next.tagName === "dd");
}
function rubyElement(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type === "element" && (next.tagName === "rp" || next.tagName === "rt");
}
function optgroup(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type === "element" && next.tagName === "optgroup";
}
function option(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type === "element" && (next.tagName === "option" || next.tagName === "optgroup");
}
function thead(_, index, parent) {
const next = siblingAfter(parent, index);
return Boolean(
next && next.type === "element" && (next.tagName === "tbody" || next.tagName === "tfoot")
);
}
function tbody(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type === "element" && (next.tagName === "tbody" || next.tagName === "tfoot");
}
function tfoot(_, index, parent) {
return !siblingAfter(parent, index);
}
function tr(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type === "element" && next.tagName === "tr";
}
function cells(_, index, parent) {
const next = siblingAfter(parent, index);
return !next || next.type === "element" && (next.tagName === "td" || next.tagName === "th");
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/omission/opening.js
var opening = omission({
body: body2,
colgroup,
head,
html: html3,
tbody: tbody2
});
function html3(node) {
const head2 = siblingAfter(node, -1);
return !head2 || head2.type !== "comment";
}
function head(node) {
const seen = /* @__PURE__ */ new Set();
for (const child2 of node.children) {
if (child2.type === "element" && (child2.tagName === "base" || child2.tagName === "title")) {
if (seen.has(child2.tagName)) return false;
seen.add(child2.tagName);
}
}
const child = node.children[0];
return !child || child.type === "element";
}
function body2(node) {
const head2 = siblingAfter(node, -1, true);
return !head2 || head2.type !== "comment" && !(head2.type === "text" && whitespace(head2.value.charAt(0))) && !(head2.type === "element" && (head2.tagName === "meta" || head2.tagName === "link" || head2.tagName === "script" || head2.tagName === "style" || head2.tagName === "template"));
}
function colgroup(node, index, parent) {
const previous2 = siblingBefore(parent, index);
const head2 = siblingAfter(node, -1, true);
if (parent && previous2 && previous2.type === "element" && previous2.tagName === "colgroup" && closing(previous2, parent.children.indexOf(previous2), parent)) {
return false;
}
return Boolean(head2 && head2.type === "element" && head2.tagName === "col");
}
function tbody2(node, index, parent) {
const previous2 = siblingBefore(parent, index);
const head2 = siblingAfter(node, -1);
if (parent && previous2 && previous2.type === "element" && (previous2.tagName === "thead" || previous2.tagName === "tbody") && closing(previous2, parent.children.indexOf(previous2), parent)) {
return false;
}
return Boolean(head2 && head2.type === "element" && head2.tagName === "tr");
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/handle/element.js
var constants = {
// See: <https://html.spec.whatwg.org/#attribute-name-state>.
name: [
[" \n\f\r &/=>".split(""), " \n\f\r \"&'/=>`".split("")],
[`\0
\f\r "&'/<=>`.split(""), "\0 \n\f\r \"&'/<=>`".split("")]
],
// See: <https://html.spec.whatwg.org/#attribute-value-(unquoted)-state>.
unquoted: [
[" \n\f\r &>".split(""), "\0 \n\f\r \"&'<=>`".split("")],
["\0 \n\f\r \"&'<=>`".split(""), "\0 \n\f\r \"&'<=>`".split("")]
],
// See: <https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state>.
single: [
["&'".split(""), "\"&'`".split("")],
["\0&'".split(""), "\0\"&'`".split("")]
],
// See: <https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state>.
double: [
['"&'.split(""), "\"&'`".split("")],
['\0"&'.split(""), "\0\"&'`".split("")]
]
};
function element(node, index, parent, state) {
const schema = state.schema;
const omit = schema.space === "svg" ? false : state.settings.omitOptionalTags;
let selfClosing = schema.space === "svg" ? state.settings.closeEmptyElements : state.settings.voids.includes(node.tagName.toLowerCase());
const parts = [];
let last;
if (schema.space === "html" && node.tagName === "svg") {
state.schema = svg;
}
const attributes = serializeAttributes(state, node.properties);
const content = state.all(
schema.space === "html" && node.tagName === "template" ? node.content : node
);
state.schema = schema;
if (content) selfClosing = false;
if (attributes || !omit || !opening(node, index, parent)) {
parts.push("<", node.tagName, attributes ? " " + attributes : "");
if (selfClosing && (schema.space === "svg" || state.settings.closeSelfClosing)) {
last = attributes.charAt(attributes.length - 1);
if (!state.settings.tightSelfClosing || last === "/" || last && last !== '"' && last !== "'") {
parts.push(" ");
}
parts.push("/");
}
parts.push(">");
}
parts.push(content);
if (!selfClosing && (!omit || !closing(node, index, parent))) {
parts.push("</" + node.tagName + ">");
}
return parts.join("");
}
function serializeAttributes(state, properties) {
const values = [];
let index = -1;
let key2;
if (properties) {
for (key2 in properties) {
if (properties[key2] !== null && properties[key2] !== void 0) {
const value = serializeAttribute(state, key2, properties[key2]);
if (value) values.push(value);
}
}
}
while (++index < values.length) {
const last = state.settings.tightAttributes ? values[index].charAt(values[index].length - 1) : void 0;
if (index !== values.length - 1 && last !== '"' && last !== "'") {
values[index] += " ";
}
}
return values.join("");
}
function serializeAttribute(state, key2, value) {
const info = find(state.schema, key2);
const x = state.settings.allowParseErrors && state.schema.space === "html" ? 0 : 1;
const y = state.settings.allowDangerousCharacters ? 0 : 1;
let quote = state.quote;
let result;
if (info.overloadedBoolean && (value === info.attribute || value === "")) {
value = true;
} else if ((info.boolean || info.overloadedBoolean) && (typeof value !== "string" || value === info.attribute || value === "")) {
value = Boolean(value);
}
if (value === null || value === void 0 || value === false || typeof value === "number" && Number.isNaN(value)) {
return "";
}
const name = stringifyEntities(
info.attribute,
Object.assign({}, state.settings.characterReferences, {
// Always encode without parse errors in non-HTML.
subset: constants.name[x][y]
})
);
if (value === true) return name;
value = Array.isArray(value) ? (info.commaSeparated ? stringify : stringify2)(value, {
padLeft: !state.settings.tightCommaSeparatedLists
}) : String(value);
if (state.settings.collapseEmptyAttributes && !value) return name;
if (state.settings.preferUnquoted) {
result = stringifyEntities(
value,
Object.assign({}, state.settings.characterReferences, {
attribute: true,
subset: constants.unquoted[x][y]
})
);
}
if (result !== value) {
if (state.settings.quoteSmart && ccount(value, quote) > ccount(value, state.alternative)) {
quote = state.alternative;
}
result = quote + stringifyEntities(
value,
Object.assign({}, state.settings.characterReferences, {
// Always encode without parse errors in non-HTML.
subset: (quote === "'" ? constants.single : constants.double)[x][y],
attribute: true
})
) + quote;
}
return name + (result ? "=" + result : result);
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/handle/text.js
var textEntitySubset = ["<", "&"];
function text(node, _, parent, state) {
return parent && parent.type === "element" && (parent.tagName === "script" || parent.tagName === "style") ? node.value : stringifyEntities(
node.value,
Object.assign({}, state.settings.characterReferences, {
subset: textEntitySubset
})
);
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/handle/raw.js
function raw2(node, index, parent, state) {
return state.settings.allowDangerousHtml ? node.value : text(node, index, parent, state);
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/handle/root.js
function root(node, _1, _2, state) {
return state.all(node);
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/handle/index.js
var handle = zwitch("type", {
invalid,
unknown,
handlers: { comment, doctype, element, raw: raw2, root, text }
});
function invalid(node) {
throw new Error("Expected node, not `" + node + "`");
}
function unknown(node_) {
const node = (
/** @type {Nodes} */
node_
);
throw new Error("Cannot compile unknown node `" + node.type + "`");
}
// node_modules/.pnpm/hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/index.js
var emptyOptions = {};
var emptyCharacterReferences = {};
var emptyChildren2 = [];
function toHtml(tree, options) {
const options_ = options || emptyOptions;
const quote = options_.quote || '"';
const alternative = quote === '"' ? "'" : '"';
if (quote !== '"' && quote !== "'") {
throw new Error("Invalid quote `" + quote + "`, expected `'` or `\"`");
}
const state = {
one,
all,
settings: {
omitOptionalTags: options_.omitOptionalTags || false,
allowParseErrors: options_.allowParseErrors || false,
allowDangerousCharacters: options_.allowDangerousCharacters || false,
quoteSmart: options_.quoteSmart || false,
preferUnquoted: options_.preferUnquoted || false,
tightAttributes: options_.tightAttributes || false,
upperDoctype: options_.upperDoctype || false,
tightDoctype: options_.tightDoctype || false,
bogusComments: options_.bogusComments || false,
tightCommaSeparatedLists: options_.tightCommaSeparatedLists || false,
tightSelfClosing: options_.tightSelfClosing || false,
collapseEmptyAttributes: options_.collapseEmptyAttributes || false,
allowDangerousHtml: options_.allowDangerousHtml || false,
voids: options_.voids || htmlVoidElements,
characterReferences: options_.characterReferences || emptyCharacterReferences,
closeSelfClosing: options_.closeSelfClosing || false,
closeEmptyElements: options_.closeEmptyElements || false
},
schema: options_.space === "svg" ? svg : html,
quote,
alternative
};
return state.one(
Array.isArray(tree) ? { type: "root", children: tree } : tree,
void 0,
void 0
);
}
function one(node, index, parent) {
return handle(node, index, parent, this);
}
function all(parent) {
const results = [];
const children = parent && parent.children || emptyChildren2;
let index = -1;
while (++index < children.length) {
results[index] = this.one(children[index], index, parent);
}
return results.join("");
}
// node_modules/.pnpm/rehype-stringify@10.0.1/node_modules/rehype-stringify/lib/index.js
function rehypeStringify(options) {
const self = this;
const settings = { ...self.data("settings"), ...options };
self.compiler = compiler;
function compiler(tree) {
return toHtml(tree, settings);
}
}
// node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
function escapeStringRegexp(string) {
if (typeof string !== "string") {
throw new TypeError("Expected a string");
}
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
}
// node_modules/.pnpm/mdast-util-find-and-replace@3.0.2/node_modules/mdast-util-find-and-replace/lib/index.js
function findAndReplace(tree, list2, options) {
const settings = options || {};
const ignored = convert(settings.ignore || []);
const pairs = toPairs(list2);
let pairIndex = -1;
while (++pairIndex < pairs.length) {
visitParents(tree, "text", visitor);
}
function visitor(node, parents) {
let index = -1;
let grandparent;
while (++index < parents.length) {
const parent = parents[index];
const siblings2 = grandparent ? grandparent.children : void 0;
if (ignored(
parent,
siblings2 ? siblings2.indexOf(parent) : void 0,
grandparent
)) {
return;
}
grandparent = parent;
}
if (grandparent) {
return handler(node, parents);
}
}
function handler(node, parents) {
const parent = parents[parents.length - 1];
const find2 = pairs[pairIndex][0];
const replace2 = pairs[pairIndex][1];
let start = 0;
const siblings2 = parent.children;
const index = siblings2.indexOf(node);
let change = false;
let nodes = [];
find2.lastIndex = 0;
let match = find2.exec(node.value);
while (match) {
const position = match.index;
const matchObject = {
index: match.index,
input: match.input,
stack: [...parents, node]
};
let value = replace2(...match, matchObject);
if (typeof value === "string") {
value = value.length > 0 ? { type: "text", value } : void 0;
}
if (value === false) {
find2.lastIndex = position + 1;
} else {
if (start !== position) {
nodes.push({
type: "text",
value: node.value.slice(start, position)
});
}
if (Array.isArray(value)) {
nodes.push(...value);
} else if (value) {
nodes.push(value);
}
start = position + match[0].length;
change = true;
}
if (!find2.global) {
break;
}
match = find2.exec(node.value);
}
if (change) {
if (start < node.value.length) {
nodes.push({ type: "text", value: node.value.slice(start) });
}
parent.children.splice(index, 1, ...nodes);
} else {
nodes = [node];
}
return index + nodes.length;
}
}
function toPairs(tupleOrList) {
const result = [];
if (!Array.isArray(tupleOrList)) {
throw new TypeError("Expected find and replace tuple or list of tuples");
}
const list2 = !tupleOrList[0] || Array.isArray(tupleOrList[0]) ? tupleOrList : [tupleOrList];
let index = -1;
while (++index < list2.length) {
const tuple = list2[index];
result.push([toExpression(tuple[0]), toFunction(tuple[1])]);
}
return result;
}
function toExpression(find2) {
return typeof find2 === "string" ? new RegExp(escapeStringRegexp(find2), "g") : find2;
}
function toFunction(replace2) {
return typeof replace2 === "function" ? replace2 : function() {
return replace2;
};
}
// node_modules/.pnpm/mdast-util-gfm-autolink-literal@2.0.1/node_modules/mdast-util-gfm-autolink-literal/lib/index.js
var inConstruct = "phrasing";
var notInConstruct = ["autolink", "link", "image", "label"];
function gfmAutolinkLiteralFromMarkdown() {
return {
transforms: [transformGfmAutolinkLiterals],
enter: {
literalAutolink: enterLiteralAutolink,
literalAutolinkEmail: enterLiteralAutolinkValue,
literalAutolinkHttp: enterLiteralAutolinkValue,
literalAutolinkWww: enterLiteralAutolinkValue
},
exit: {
literalAutolink: exitLiteralAutolink,
literalAutolinkEmail: exitLiteralAutolinkEmail,
literalAutolinkHttp: exitLiteralAutolinkHttp,
literalAutolinkWww: exitLiteralAutolinkWww
}
};
}
function gfmAutolinkLiteralToMarkdown() {
return {
unsafe: [
{
character: "@",
before: "[+\\-.\\w]",
after: "[\\-.\\w]",
inConstruct,
notInConstruct
},
{
character: ".",
before: "[Ww]",
after: "[\\-.\\w]",
inConstruct,
notInConstruct
},
{
character: ":",
before: "[ps]",
after: "\\/",
inConstruct,
notInConstruct
}
]
};
}
function enterLiteralAutolink(token) {
this.enter({ type: "link", title: null, url: "", children: [] }, token);
}
function enterLiteralAutolinkValue(token) {
this.config.enter.autolinkProtocol.call(this, token);
}
function exitLiteralAutolinkHttp(token) {
this.config.exit.autolinkProtocol.call(this, token);
}
function exitLiteralAutolinkWww(token) {
this.config.exit.data.call(this, token);
const node = this.stack[this.stack.length - 1];
ok(node.type === "link");
node.url = "http://" + this.sliceSerialize(token);
}
function exitLiteralAutolinkEmail(token) {
this.config.exit.autolinkEmail.call(this, token);
}
function exitLiteralAutolink(token) {
this.exit(token);
}
function transformGfmAutolinkLiterals(tree) {
findAndReplace(
tree,
[
[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)", "gu"), findEmail]
],
{ ignore: ["link", "linkReference"] }
);
}
function findUrl(_, protocol, domain2, path3, match) {
let prefix = "";
if (!previous(match)) {
return false;
}
if (/^w/i.test(protocol)) {
domain2 = protocol + domain2;
protocol = "";
prefix = "http://";
}
if (!isCorrectDomain(domain2)) {
return false;
}
const parts = splitUrl(domain2 + path3);
if (!parts[0]) return false;
const result = {
type: "link",
title: null,
url: prefix + protocol + parts[0],
children: [{ type: "text", value: protocol + parts[0] }]
};
if (parts[1]) {
return [result, { type: "text", value: parts[1] }];
}
return result;
}
function findEmail(_, atext, label, match) {
if (
// Not an expected previous character.
!previous(match, true) || // Label ends in not allowed character.
/[-\d_]$/.test(label)
) {
return false;
}
return {
type: "link",
title: null,
url: "mailto:" + atext + "@" + label,
children: [{ type: "text", value: atext + "@" + label }]
};
}
function isCorrectDomain(domain2) {
const parts = domain2.split(".");
if (parts.length < 2 || parts[parts.length - 1] && (/_/.test(parts[parts.length - 1]) || !/[a-zA-Z\d]/.test(parts[parts.length - 1])) || parts[parts.length - 2] && (/_/.test(parts[parts.length - 2]) || !/[a-zA-Z\d]/.test(parts[parts.length - 2]))) {
return false;
}
return true;
}
function splitUrl(url) {
const trailExec = /[!"&'),.:;<>?\]}]+$/.exec(url);
if (!trailExec) {
return [url, void 0];
}
url = url.slice(0, trailExec.index);
let trail2 = trailExec[0];
let closingParenIndex = trail2.indexOf(")");
const openingParens = ccount(url, "(");
let closingParens = ccount(url, ")");
while (closingParenIndex !== -1 && openingParens > closingParens) {
url += trail2.slice(0, closingParenIndex + 1);
trail2 = trail2.slice(closingParenIndex + 1);
closingParenIndex = trail2.indexOf(")");
closingParens++;
}
return [url, trail2];
}
function previous(match, email) {
const code3 = match.input.charCodeAt(match.index - 1);
return (match.index === 0 || unicodeWhitespace(code3) || unicodePunctuation(code3)) && // If it’s an email, the previous character should not be a slash.
(!email || code3 !== 47);
}
// node_modules/.pnpm/mdast-util-gfm-footnote@2.1.0/node_modules/mdast-util-gfm-footnote/lib/index.js
footnoteReference.peek = footnoteReferencePeek;
function enterFootnoteCallString() {
this.buffer();
}
function enterFootnoteCall(token) {
this.enter({ type: "footnoteReference", identifier: "", label: "" }, token);
}
function enterFootnoteDefinitionLabelString() {
this.buffer();
}
function enterFootnoteDefinition(token) {
this.enter(
{ type: "footnoteDefinition", identifier: "", label: "", children: [] },
token
);
}
function exitFootnoteCallString(token) {
const label = this.resume();
const node = this.stack[this.stack.length - 1];
ok(node.type === "footnoteReference");
node.identifier = normalizeIdentifier(
this.sliceSerialize(token)
).toLowerCase();
node.label = label;
}
function exitFootnoteCall(token) {
this.exit(token);
}
function exitFootnoteDefinitionLabelString(token) {
const label = this.resume();
const node = this.stack[this.stack.length - 1];
ok(node.type === "footnoteDefinition");
node.identifier = normalizeIdentifier(
this.sliceSerialize(token)
).toLowerCase();
node.label = label;
}
function exitFootnoteDefinition(token) {
this.exit(token);
}
function footnoteReferencePeek() {
return "[";
}
function footnoteReference(node, _, state, info) {
const tracker = state.createTracker(info);
let value = tracker.move("[^");
const exit2 = state.enter("footnoteReference");
const subexit = state.enter("reference");
value += tracker.move(
state.safe(state.associationId(node), { after: "]", before: value })
);
subexit();
exit2();
value += tracker.move("]");
return value;
}
function gfmFootnoteFromMarkdown() {
return {
enter: {
gfmFootnoteCallString: enterFootnoteCallString,
gfmFootnoteCall: enterFootnoteCall,
gfmFootnoteDefinitionLabelString: enterFootnoteDefinitionLabelString,
gfmFootnoteDefinition: enterFootnoteDefinition
},
exit: {
gfmFootnoteCallString: exitFootnoteCallString,
gfmFootnoteCall: exitFootnoteCall,
gfmFootnoteDefinitionLabelString: exitFootnoteDefinitionLabelString,
gfmFootnoteDefinition: exitFootnoteDefinition
}
};
}
function gfmFootnoteToMarkdown(options) {
let firstLineBlank = false;
if (options && options.firstLineBlank) {
firstLineBlank = true;
}
return {
handlers: { footnoteDefinition, footnoteReference },
// This is on by default already.
unsafe: [{ character: "[", inConstruct: ["label", "phrasing", "reference"] }]
};
function footnoteDefinition(node, _, state, info) {
const tracker = state.createTracker(info);
let value = tracker.move("[^");
const exit2 = state.enter("footnoteDefinition");
const subexit = state.enter("label");
value += tracker.move(
state.safe(state.associationId(node), { before: value, after: "]" })
);
subexit();
value += tracker.move("]:");
if (node.children && node.children.length > 0) {
tracker.shift(4);
value += tracker.move(
(firstLineBlank ? "\n" : " ") + state.indentLines(
state.containerFlow(node, tracker.current()),
firstLineBlank ? mapAll : mapExceptFirst
)
);
}
exit2();
return value;
}
}
function mapExceptFirst(line, index, blank) {
return index === 0 ? line : mapAll(line, index, blank);
}
function mapAll(line, index, blank) {
return (blank ? "" : " ") + line;
}
// node_modules/.pnpm/mdast-util-gfm-strikethrough@2.0.0/node_modules/mdast-util-gfm-strikethrough/lib/index.js
var constructsWithoutStrikethrough = [
"autolink",
"destinationLiteral",
"destinationRaw",
"reference",
"titleQuote",
"titleApostrophe"
];
handleDelete.peek = peekDelete;
function gfmStrikethroughFromMarkdown() {
return {
canContainEols: ["delete"],
enter: { strikethrough: enterStrikethrough },
exit: { strikethrough: exitStrikethrough }
};
}
function gfmStrikethroughToMarkdown() {
return {
unsafe: [
{
character: "~",
inConstruct: "phrasing",
notInConstruct: constructsWithoutStrikethrough
}
],
handlers: { delete: handleDelete }
};
}
function enterStrikethrough(token) {
this.enter({ type: "delete", children: [] }, token);
}
function exitStrikethrough(token) {
this.exit(token);
}
function handleDelete(node, _, state, info) {
const tracker = state.createTracker(info);
const exit2 = state.enter("strikethrough");
let value = tracker.move("~~");
value += state.containerPhrasing(node, {
...tracker.current(),
before: value,
after: "~"
});
value += tracker.move("~~");
exit2();
return value;
}
function peekDelete() {
return "~";
}
// node_modules/.pnpm/markdown-table@3.0.4/node_modules/markdown-table/index.js
function defaultStringLength(value) {
return value.length;
}
function markdownTable(table, options) {
const settings = options || {};
const align = (settings.align || []).concat();
const stringLength = settings.stringLength || defaultStringLength;
const alignments = [];
const cellMatrix = [];
const sizeMatrix = [];
const longestCellByColumn = [];
let mostCellsPerRow = 0;
let rowIndex = -1;
while (++rowIndex < table.length) {
const row2 = [];
const sizes2 = [];
let columnIndex2 = -1;
if (table[rowIndex].length > mostCellsPerRow) {
mostCellsPerRow = table[rowIndex].length;
}
while (++columnIndex2 < table[rowIndex].length) {
const cell = serialize(table[rowIndex][columnIndex2]);
if (settings.alignDelimiters !== false) {
const size = stringLength(cell);
sizes2[columnIndex2] = size;
if (longestCellByColumn[columnIndex2] === void 0 || size > longestCellByColumn[columnIndex2]) {
longestCellByColumn[columnIndex2] = size;
}
}
row2.push(cell);
}
cellMatrix[rowIndex] = row2;
sizeMatrix[rowIndex] = sizes2;
}
let columnIndex = -1;
if (typeof align === "object" && "length" in align) {
while (++columnIndex < mostCellsPerRow) {
alignments[columnIndex] = toAlignment(align[columnIndex]);
}
} else {
const code3 = toAlignment(align);
while (++columnIndex < mostCellsPerRow) {
alignments[columnIndex] = code3;
}
}
columnIndex = -1;
const row = [];
const sizes = [];
while (++columnIndex < mostCellsPerRow) {
const code3 = alignments[columnIndex];
let before = "";
let after = "";
if (code3 === 99) {
before = ":";
after = ":";
} else if (code3 === 108) {
before = ":";
} else if (code3 === 114) {
after = ":";
}
let size = settings.alignDelimiters === false ? 1 : Math.max(
1,
longestCellByColumn[columnIndex] - before.length - after.length
);
const cell = before + "-".repeat(size) + after;
if (settings.alignDelimiters !== false) {
size = before.length + size + after.length;
if (size > longestCellByColumn[columnIndex]) {
longestCellByColumn[columnIndex] = size;
}
sizes[columnIndex] = size;
}
row[columnIndex] = cell;
}
cellMatrix.splice(1, 0, row);
sizeMatrix.splice(1, 0, sizes);
rowIndex = -1;
const lines = [];
while (++rowIndex < cellMatrix.length) {
const row2 = cellMatrix[rowIndex];
const sizes2 = sizeMatrix[rowIndex];
columnIndex = -1;
const line = [];
while (++columnIndex < mostCellsPerRow) {
const cell = row2[columnIndex] || "";
let before = "";
let after = "";
if (settings.alignDelimiters !== false) {
const size = longestCellByColumn[columnIndex] - (sizes2[columnIndex] || 0);
const code3 = alignments[columnIndex];
if (code3 === 114) {
before = " ".repeat(size);
} else if (code3 === 99) {
if (size % 2) {
before = " ".repeat(size / 2 + 0.5);
after = " ".repeat(size / 2 - 0.5);
} else {
before = " ".repeat(size / 2);
after = before;
}
} else {
after = " ".repeat(size);
}
}
if (settings.delimiterStart !== false && !columnIndex) {
line.push("|");
}
if (settings.padding !== false && // Don’t add the opening space if we’re not aligning and the cell is
// empty: there will be a closing space.
!(settings.alignDelimiters === false && cell === "") && (settings.delimiterStart !== false || columnIndex)) {
line.push(" ");
}
if (settings.alignDelimiters !== false) {
line.push(before);
}
line.push(cell);
if (settings.alignDelimiters !== false) {
line.push(after);
}
if (settings.padding !== false) {
line.push(" ");
}
if (settings.delimiterEnd !== false || columnIndex !== mostCellsPerRow - 1) {
line.push("|");
}
}
lines.push(
settings.delimiterEnd === false ? line.join("").replace(/ +