创高项目初始化
This commit is contained in:
101
client/node_modules/@unhead/ssr/dist/index.cjs
generated
vendored
Normal file
101
client/node_modules/@unhead/ssr/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
'use strict';
|
||||
|
||||
const shared = require('@unhead/shared');
|
||||
|
||||
function encodeAttribute(value) {
|
||||
return String(value).replace(/"/g, """);
|
||||
}
|
||||
function propsToString(props) {
|
||||
let attrs = "";
|
||||
for (const key in props) {
|
||||
if (!Object.prototype.hasOwnProperty.call(props, key)) {
|
||||
continue;
|
||||
}
|
||||
const value = props[key];
|
||||
if (value !== false && value !== null) {
|
||||
attrs += value === true ? ` ${key}` : ` ${key}="${encodeAttribute(value)}"`;
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
function ssrRenderTags(tags, options) {
|
||||
const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: "", bodyClose: "", bodyOpen: "" } };
|
||||
const lineBreaks = !options?.omitLineBreaks ? "\n" : "";
|
||||
for (const tag of tags) {
|
||||
if (Object.keys(tag.props).length === 0 && !tag.innerHTML && !tag.textContent) {
|
||||
continue;
|
||||
}
|
||||
if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
|
||||
Object.assign(schema[tag.tag], tag.props);
|
||||
continue;
|
||||
}
|
||||
const s = tagToString(tag);
|
||||
const tagPosition = tag.tagPosition || "head";
|
||||
schema.tags[tagPosition] += schema.tags[tagPosition] ? `${lineBreaks}${s}` : s;
|
||||
}
|
||||
return {
|
||||
headTags: schema.tags.head,
|
||||
bodyTags: schema.tags.bodyClose,
|
||||
bodyTagsOpen: schema.tags.bodyOpen,
|
||||
htmlAttrs: propsToString(schema.htmlAttrs),
|
||||
bodyAttrs: propsToString(schema.bodyAttrs)
|
||||
};
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
return str.replace(/[&<>"'/]/g, (char) => {
|
||||
switch (char) {
|
||||
case "&":
|
||||
return "&";
|
||||
case "<":
|
||||
return "<";
|
||||
case ">":
|
||||
return ">";
|
||||
case '"':
|
||||
return """;
|
||||
case "'":
|
||||
return "'";
|
||||
case "/":
|
||||
return "/";
|
||||
default:
|
||||
return char;
|
||||
}
|
||||
});
|
||||
}
|
||||
function tagToString(tag) {
|
||||
const attrs = propsToString(tag.props);
|
||||
const openTag = `<${tag.tag}${attrs}>`;
|
||||
if (!shared.TagsWithInnerContent.has(tag.tag))
|
||||
return shared.SelfClosingTags.has(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
||||
let content = String(tag.innerHTML || "");
|
||||
if (tag.textContent)
|
||||
content = escapeHtml(String(tag.textContent));
|
||||
return shared.SelfClosingTags.has(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
||||
}
|
||||
|
||||
async function renderSSRHead(head, options) {
|
||||
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, options);
|
||||
const renderCtx = { tags: ctx.tags, html };
|
||||
await head.hooks.callHook("ssr:rendered", renderCtx);
|
||||
return renderCtx.html;
|
||||
}
|
||||
|
||||
exports.escapeHtml = escapeHtml;
|
||||
exports.propsToString = propsToString;
|
||||
exports.renderSSRHead = renderSSRHead;
|
||||
exports.ssrRenderTags = ssrRenderTags;
|
||||
exports.tagToString = tagToString;
|
||||
19
client/node_modules/@unhead/ssr/dist/index.d.cts
generated
vendored
Normal file
19
client/node_modules/@unhead/ssr/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Unhead, RenderSSRHeadOptions, SSRHeadPayload, HeadTag } from '@unhead/schema';
|
||||
export { SSRHeadPayload } from '@unhead/schema';
|
||||
|
||||
declare function renderSSRHead<T extends {}>(head: Unhead<T>, options?: RenderSSRHeadOptions): Promise<SSRHeadPayload>;
|
||||
|
||||
declare function propsToString(props: Record<string, any>): string;
|
||||
|
||||
declare function ssrRenderTags<T extends HeadTag>(tags: T[], options?: RenderSSRHeadOptions): {
|
||||
headTags: string;
|
||||
bodyTags: string;
|
||||
bodyTagsOpen: string;
|
||||
htmlAttrs: string;
|
||||
bodyAttrs: string;
|
||||
};
|
||||
|
||||
declare function escapeHtml(str: string): string;
|
||||
declare function tagToString<T extends HeadTag>(tag: T): string;
|
||||
|
||||
export { escapeHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
||||
19
client/node_modules/@unhead/ssr/dist/index.d.mts
generated
vendored
Normal file
19
client/node_modules/@unhead/ssr/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Unhead, RenderSSRHeadOptions, SSRHeadPayload, HeadTag } from '@unhead/schema';
|
||||
export { SSRHeadPayload } from '@unhead/schema';
|
||||
|
||||
declare function renderSSRHead<T extends {}>(head: Unhead<T>, options?: RenderSSRHeadOptions): Promise<SSRHeadPayload>;
|
||||
|
||||
declare function propsToString(props: Record<string, any>): string;
|
||||
|
||||
declare function ssrRenderTags<T extends HeadTag>(tags: T[], options?: RenderSSRHeadOptions): {
|
||||
headTags: string;
|
||||
bodyTags: string;
|
||||
bodyTagsOpen: string;
|
||||
htmlAttrs: string;
|
||||
bodyAttrs: string;
|
||||
};
|
||||
|
||||
declare function escapeHtml(str: string): string;
|
||||
declare function tagToString<T extends HeadTag>(tag: T): string;
|
||||
|
||||
export { escapeHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
||||
19
client/node_modules/@unhead/ssr/dist/index.d.ts
generated
vendored
Normal file
19
client/node_modules/@unhead/ssr/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Unhead, RenderSSRHeadOptions, SSRHeadPayload, HeadTag } from '@unhead/schema';
|
||||
export { SSRHeadPayload } from '@unhead/schema';
|
||||
|
||||
declare function renderSSRHead<T extends {}>(head: Unhead<T>, options?: RenderSSRHeadOptions): Promise<SSRHeadPayload>;
|
||||
|
||||
declare function propsToString(props: Record<string, any>): string;
|
||||
|
||||
declare function ssrRenderTags<T extends HeadTag>(tags: T[], options?: RenderSSRHeadOptions): {
|
||||
headTags: string;
|
||||
bodyTags: string;
|
||||
bodyTagsOpen: string;
|
||||
htmlAttrs: string;
|
||||
bodyAttrs: string;
|
||||
};
|
||||
|
||||
declare function escapeHtml(str: string): string;
|
||||
declare function tagToString<T extends HeadTag>(tag: T): string;
|
||||
|
||||
export { escapeHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
||||
95
client/node_modules/@unhead/ssr/dist/index.mjs
generated
vendored
Normal file
95
client/node_modules/@unhead/ssr/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import { TagsWithInnerContent, SelfClosingTags } from '@unhead/shared';
|
||||
|
||||
function encodeAttribute(value) {
|
||||
return String(value).replace(/"/g, """);
|
||||
}
|
||||
function propsToString(props) {
|
||||
let attrs = "";
|
||||
for (const key in props) {
|
||||
if (!Object.prototype.hasOwnProperty.call(props, key)) {
|
||||
continue;
|
||||
}
|
||||
const value = props[key];
|
||||
if (value !== false && value !== null) {
|
||||
attrs += value === true ? ` ${key}` : ` ${key}="${encodeAttribute(value)}"`;
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
function ssrRenderTags(tags, options) {
|
||||
const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: "", bodyClose: "", bodyOpen: "" } };
|
||||
const lineBreaks = !options?.omitLineBreaks ? "\n" : "";
|
||||
for (const tag of tags) {
|
||||
if (Object.keys(tag.props).length === 0 && !tag.innerHTML && !tag.textContent) {
|
||||
continue;
|
||||
}
|
||||
if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
|
||||
Object.assign(schema[tag.tag], tag.props);
|
||||
continue;
|
||||
}
|
||||
const s = tagToString(tag);
|
||||
const tagPosition = tag.tagPosition || "head";
|
||||
schema.tags[tagPosition] += schema.tags[tagPosition] ? `${lineBreaks}${s}` : s;
|
||||
}
|
||||
return {
|
||||
headTags: schema.tags.head,
|
||||
bodyTags: schema.tags.bodyClose,
|
||||
bodyTagsOpen: schema.tags.bodyOpen,
|
||||
htmlAttrs: propsToString(schema.htmlAttrs),
|
||||
bodyAttrs: propsToString(schema.bodyAttrs)
|
||||
};
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
return str.replace(/[&<>"'/]/g, (char) => {
|
||||
switch (char) {
|
||||
case "&":
|
||||
return "&";
|
||||
case "<":
|
||||
return "<";
|
||||
case ">":
|
||||
return ">";
|
||||
case '"':
|
||||
return """;
|
||||
case "'":
|
||||
return "'";
|
||||
case "/":
|
||||
return "/";
|
||||
default:
|
||||
return char;
|
||||
}
|
||||
});
|
||||
}
|
||||
function tagToString(tag) {
|
||||
const attrs = propsToString(tag.props);
|
||||
const openTag = `<${tag.tag}${attrs}>`;
|
||||
if (!TagsWithInnerContent.has(tag.tag))
|
||||
return SelfClosingTags.has(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
||||
let content = String(tag.innerHTML || "");
|
||||
if (tag.textContent)
|
||||
content = escapeHtml(String(tag.textContent));
|
||||
return SelfClosingTags.has(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
||||
}
|
||||
|
||||
async function renderSSRHead(head, options) {
|
||||
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, options);
|
||||
const renderCtx = { tags: ctx.tags, html };
|
||||
await head.hooks.callHook("ssr:rendered", renderCtx);
|
||||
return renderCtx.html;
|
||||
}
|
||||
|
||||
export { escapeHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
||||
Reference in New Issue
Block a user