263 lines
7.1 KiB
JavaScript
263 lines
7.1 KiB
JavaScript
// node_modules/svelte/src/html-tree-validation.js
|
|
/**
|
|
* Map of elements that have certain elements that are not allowed inside them, in the sense that they will auto-close the parent/ancestor element.
|
|
* Theoretically one could take advantage of it but most of the time it will just result in confusing behavior and break when SSR'd.
|
|
* There are more elements that are invalid inside other elements, but they're not auto-closed and so don't break SSR and are therefore not listed here.
|
|
* @type {Record<string, { direct: string[]} | { descendant: string[]; reset_by?: string[] }>}
|
|
*/
|
|
var autoclosing_children = {
|
|
li: { direct: ["li"] },
|
|
dt: {
|
|
descendant: ["dt", "dd"],
|
|
reset_by: ["dl"]
|
|
},
|
|
dd: {
|
|
descendant: ["dt", "dd"],
|
|
reset_by: ["dl"]
|
|
},
|
|
p: { descendant: [
|
|
"address",
|
|
"article",
|
|
"aside",
|
|
"blockquote",
|
|
"div",
|
|
"dl",
|
|
"fieldset",
|
|
"footer",
|
|
"form",
|
|
"h1",
|
|
"h2",
|
|
"h3",
|
|
"h4",
|
|
"h5",
|
|
"h6",
|
|
"header",
|
|
"hgroup",
|
|
"hr",
|
|
"main",
|
|
"menu",
|
|
"nav",
|
|
"ol",
|
|
"p",
|
|
"pre",
|
|
"section",
|
|
"table",
|
|
"ul"
|
|
] },
|
|
rt: { descendant: ["rt", "rp"] },
|
|
rp: { descendant: ["rt", "rp"] },
|
|
optgroup: { descendant: ["optgroup"] },
|
|
option: { descendant: ["option", "optgroup"] },
|
|
thead: { direct: ["tbody", "tfoot"] },
|
|
tbody: { direct: ["tbody", "tfoot"] },
|
|
tfoot: { direct: ["tbody"] },
|
|
tr: { direct: ["tr", "tbody"] },
|
|
td: { direct: [
|
|
"td",
|
|
"th",
|
|
"tr"
|
|
] },
|
|
th: { direct: [
|
|
"td",
|
|
"th",
|
|
"tr"
|
|
] }
|
|
};
|
|
/**
|
|
* Returns true if the tag is either the last in the list of siblings and will be autoclosed,
|
|
* or not allowed inside the parent tag such that it will auto-close it. The latter results
|
|
* in the browser repairing the HTML, which will likely result in an error during hydration.
|
|
* @param {string} current
|
|
* @param {string} [next]
|
|
*/
|
|
function closing_tag_omitted(current, next) {
|
|
const disallowed = autoclosing_children[current];
|
|
if (disallowed) {
|
|
if (!next || ("direct" in disallowed ? disallowed.direct : disallowed.descendant).includes(next)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
/**
|
|
* Map of elements that have certain elements that are not allowed inside them, in the sense that the browser will somehow repair the HTML.
|
|
* There are more elements that are invalid inside other elements, but they're not repaired and so don't break SSR and are therefore not listed here.
|
|
* @type {Record<string, { direct: string[]} | { descendant: string[]; reset_by?: string[]; only?: string[] } | { only: string[] }>}
|
|
*/
|
|
var disallowed_children = {
|
|
...autoclosing_children,
|
|
form: { descendant: ["form"] },
|
|
a: { descendant: ["a"] },
|
|
button: { descendant: ["button"] },
|
|
h1: { descendant: [
|
|
"h1",
|
|
"h2",
|
|
"h3",
|
|
"h4",
|
|
"h5",
|
|
"h6"
|
|
] },
|
|
h2: { descendant: [
|
|
"h1",
|
|
"h2",
|
|
"h3",
|
|
"h4",
|
|
"h5",
|
|
"h6"
|
|
] },
|
|
h3: { descendant: [
|
|
"h1",
|
|
"h2",
|
|
"h3",
|
|
"h4",
|
|
"h5",
|
|
"h6"
|
|
] },
|
|
h4: { descendant: [
|
|
"h1",
|
|
"h2",
|
|
"h3",
|
|
"h4",
|
|
"h5",
|
|
"h6"
|
|
] },
|
|
h5: { descendant: [
|
|
"h1",
|
|
"h2",
|
|
"h3",
|
|
"h4",
|
|
"h5",
|
|
"h6"
|
|
] },
|
|
h6: { descendant: [
|
|
"h1",
|
|
"h2",
|
|
"h3",
|
|
"h4",
|
|
"h5",
|
|
"h6"
|
|
] },
|
|
tr: { only: [
|
|
"th",
|
|
"td",
|
|
"style",
|
|
"script",
|
|
"template"
|
|
] },
|
|
tbody: { only: [
|
|
"tr",
|
|
"style",
|
|
"script",
|
|
"template"
|
|
] },
|
|
thead: { only: [
|
|
"tr",
|
|
"style",
|
|
"script",
|
|
"template"
|
|
] },
|
|
tfoot: { only: [
|
|
"tr",
|
|
"style",
|
|
"script",
|
|
"template"
|
|
] },
|
|
colgroup: { only: ["col", "template"] },
|
|
table: { only: [
|
|
"caption",
|
|
"colgroup",
|
|
"tbody",
|
|
"thead",
|
|
"tfoot",
|
|
"style",
|
|
"script",
|
|
"template"
|
|
] },
|
|
head: { only: [
|
|
"base",
|
|
"basefont",
|
|
"bgsound",
|
|
"link",
|
|
"meta",
|
|
"title",
|
|
"noscript",
|
|
"noframes",
|
|
"style",
|
|
"script",
|
|
"template"
|
|
] },
|
|
html: { only: [
|
|
"head",
|
|
"body",
|
|
"frameset"
|
|
] },
|
|
frameset: { only: ["frame"] },
|
|
"#document": { only: ["html"] }
|
|
};
|
|
/**
|
|
* Returns an error message if the tag is not allowed inside the ancestor tag (which is grandparent and above) such that it will result
|
|
* in the browser repairing the HTML, which will likely result in an error during hydration.
|
|
* @param {string} child_tag
|
|
* @param {string[]} ancestors All nodes starting with the parent, up until the ancestor, which means two entries minimum
|
|
* @param {string} [child_loc]
|
|
* @param {string} [ancestor_loc]
|
|
* @returns {string | null}
|
|
*/
|
|
function is_tag_valid_with_ancestor(child_tag, ancestors, child_loc, ancestor_loc) {
|
|
if (child_tag.includes("-")) return null;
|
|
const ancestor_tag = ancestors[ancestors.length - 1];
|
|
const disallowed = disallowed_children[ancestor_tag];
|
|
if (!disallowed) return null;
|
|
if ("reset_by" in disallowed && disallowed.reset_by) for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
if (ancestors[i].includes("-")) return null;
|
|
if (disallowed.reset_by.includes(ancestors[i])) return null;
|
|
}
|
|
if ("descendant" in disallowed && disallowed.descendant.includes(child_tag)) return `${child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``} cannot be a descendant of ${ancestor_loc ? `\`<${ancestor_tag}>\` (${ancestor_loc})` : `\`<${ancestor_tag}>\``}`;
|
|
return null;
|
|
}
|
|
/**
|
|
* Returns an error message if the tag is not allowed inside the parent tag such that it will result
|
|
* in the browser repairing the HTML, which will likely result in an error during hydration.
|
|
* @param {string} child_tag
|
|
* @param {string} parent_tag
|
|
* @param {string} [child_loc]
|
|
* @param {string} [parent_loc]
|
|
* @returns {string | null}
|
|
*/
|
|
function is_tag_valid_with_parent(child_tag, parent_tag, child_loc, parent_loc) {
|
|
if (child_tag.includes("-") || parent_tag?.includes("-")) return null;
|
|
if (parent_tag === "template") return null;
|
|
const disallowed = disallowed_children[parent_tag];
|
|
const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``;
|
|
const parent = parent_loc ? `\`<${parent_tag}>\` (${parent_loc})` : `\`<${parent_tag}>\``;
|
|
if (disallowed) {
|
|
if ("direct" in disallowed && disallowed.direct.includes(child_tag)) return `${child} cannot be a direct child of ${parent}`;
|
|
if ("descendant" in disallowed && disallowed.descendant.includes(child_tag)) return `${child} cannot be a child of ${parent}`;
|
|
if ("only" in disallowed && disallowed.only) {
|
|
if (disallowed.only.includes(child_tag)) return null;
|
|
else return `${child} cannot be a child of ${parent}. \`<${parent_tag}>\` only allows these children: ${disallowed.only.map((d) => `\`<${d}>\``).join(", ")}`;
|
|
}
|
|
}
|
|
switch (child_tag) {
|
|
case "body":
|
|
case "caption":
|
|
case "col":
|
|
case "colgroup":
|
|
case "frameset":
|
|
case "frame":
|
|
case "head":
|
|
case "html": return `${child} cannot be a child of ${parent}`;
|
|
case "thead":
|
|
case "tbody":
|
|
case "tfoot": return `${child} must be the child of a \`<table>\`, not a ${parent}`;
|
|
case "td":
|
|
case "th": return `${child} must be the child of a \`<tr>\`, not a ${parent}`;
|
|
case "tr": return `\`<tr>\` must be the child of a \`<thead>\`, \`<tbody>\`, or \`<tfoot>\`, not a ${parent}`;
|
|
}
|
|
return null;
|
|
}
|
|
// node_modules/svelte/src/internal/server/hydration.js
|
|
var BLOCK_OPEN = `<!--[-->`;
|
|
var BLOCK_OPEN_ELSE = `<!--[!-->`;
|
|
var BLOCK_CLOSE = `<!--]-->`;
|
|
var EMPTY_COMMENT = `<!---->`;
|
|
export { closing_tag_omitted as a, EMPTY_COMMENT as i, BLOCK_OPEN as n, is_tag_valid_with_ancestor as o, BLOCK_OPEN_ELSE as r, is_tag_valid_with_parent as s, BLOCK_CLOSE as t };
|