initial commit

This commit is contained in:
Zoe
2023-01-03 09:29:04 -06:00
commit 7851137d88
12889 changed files with 2557443 additions and 0 deletions

62
node_modules/@unhead/ssr/dist/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,62 @@
'use strict';
const SelfClosingTags = ["meta", "link", "base"];
const propsToString = (props) => {
const handledAttributes = [];
for (const [key, value] of Object.entries(props)) {
if (value === false || value == null)
continue;
let attribute = key;
if (value !== true)
attribute += `="${String(value).replace(/"/g, """)}"`;
handledAttributes.push(attribute);
}
return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
};
const tagToString = (tag) => {
const attrs = propsToString(tag.props);
const openTag = `<${tag.tag}${attrs}>`;
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${tag.children || ""}</${tag.tag}>`;
};
function ssrRenderTags(tags) {
const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: [], bodyClose: [], bodyOpen: [] } };
for (const tag of tags) {
if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
schema[tag.tag] = { ...schema[tag.tag], ...tag.props };
continue;
}
schema.tags[tag.tagPosition || "head"].push(tagToString(tag));
}
return {
headTags: schema.tags.head.join("\n"),
bodyTags: schema.tags.bodyClose.join("\n"),
bodyTagsOpen: schema.tags.bodyOpen.join("\n"),
htmlAttrs: propsToString(schema.htmlAttrs),
bodyAttrs: propsToString(schema.bodyAttrs)
};
}
async function renderSSRHead(head) {
const beforeRenderCtx = { shouldRender: true };
await head.hooks.callHook("ssr:beforeRender", beforeRenderCtx);
if (!beforeRenderCtx.shouldRender) {
return {
headTags: "",
bodyTags: "",
bodyTagsOpen: "",
htmlAttrs: "",
bodyAttrs: ""
};
}
const ctx = { tags: await head.resolveTags() };
await head.hooks.callHook("ssr:render", ctx);
const html = ssrRenderTags(ctx.tags);
const renderCtx = { tags: ctx.tags, html };
await head.hooks.callHook("ssr:rendered", renderCtx);
return renderCtx.html;
}
exports.renderSSRHead = renderSSRHead;

6
node_modules/@unhead/ssr/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import { Unhead, SSRHeadPayload } from '@unhead/schema';
export { SSRHeadPayload } from '@unhead/schema';
declare function renderSSRHead<T extends {}>(head: Unhead<T>): Promise<SSRHeadPayload>;
export { renderSSRHead };

60
node_modules/@unhead/ssr/dist/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,60 @@
const SelfClosingTags = ["meta", "link", "base"];
const propsToString = (props) => {
const handledAttributes = [];
for (const [key, value] of Object.entries(props)) {
if (value === false || value == null)
continue;
let attribute = key;
if (value !== true)
attribute += `="${String(value).replace(/"/g, "&quot;")}"`;
handledAttributes.push(attribute);
}
return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
};
const tagToString = (tag) => {
const attrs = propsToString(tag.props);
const openTag = `<${tag.tag}${attrs}>`;
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${tag.children || ""}</${tag.tag}>`;
};
function ssrRenderTags(tags) {
const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: [], bodyClose: [], bodyOpen: [] } };
for (const tag of tags) {
if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
schema[tag.tag] = { ...schema[tag.tag], ...tag.props };
continue;
}
schema.tags[tag.tagPosition || "head"].push(tagToString(tag));
}
return {
headTags: schema.tags.head.join("\n"),
bodyTags: schema.tags.bodyClose.join("\n"),
bodyTagsOpen: schema.tags.bodyOpen.join("\n"),
htmlAttrs: propsToString(schema.htmlAttrs),
bodyAttrs: propsToString(schema.bodyAttrs)
};
}
async function renderSSRHead(head) {
const beforeRenderCtx = { shouldRender: true };
await head.hooks.callHook("ssr:beforeRender", beforeRenderCtx);
if (!beforeRenderCtx.shouldRender) {
return {
headTags: "",
bodyTags: "",
bodyTagsOpen: "",
htmlAttrs: "",
bodyAttrs: ""
};
}
const ctx = { tags: await head.resolveTags() };
await head.hooks.callHook("ssr:render", ctx);
const html = ssrRenderTags(ctx.tags);
const renderCtx = { tags: ctx.tags, html };
await head.hooks.callHook("ssr:rendered", renderCtx);
return renderCtx.html;
}
export { renderSSRHead };