@unhead/ssr 1.11.14 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +10 -95
- package/dist/index.d.cts +1 -19
- package/dist/index.d.mts +1 -19
- package/dist/index.d.ts +1 -19
- package/dist/index.mjs +1 -95
- package/package.json +4 -6
- package/README.md +0 -12
package/dist/index.cjs
CHANGED
|
@@ -1,101 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const server = require('unhead/server');
|
|
4
4
|
|
|
5
|
-
function encodeAttribute(value) {
|
|
6
|
-
return String(value).replace(/"/g, """);
|
|
7
|
-
}
|
|
8
|
-
function propsToString(props) {
|
|
9
|
-
let attrs = "";
|
|
10
|
-
for (const key in props) {
|
|
11
|
-
if (!Object.prototype.hasOwnProperty.call(props, key)) {
|
|
12
|
-
continue;
|
|
13
|
-
}
|
|
14
|
-
const value = props[key];
|
|
15
|
-
if (value !== false && value !== null) {
|
|
16
|
-
attrs += value === true ? ` ${key}` : ` ${key}="${encodeAttribute(value)}"`;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return attrs;
|
|
20
|
-
}
|
|
21
5
|
|
|
22
|
-
function ssrRenderTags(tags, options) {
|
|
23
|
-
const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: "", bodyClose: "", bodyOpen: "" } };
|
|
24
|
-
const lineBreaks = !options?.omitLineBreaks ? "\n" : "";
|
|
25
|
-
for (const tag of tags) {
|
|
26
|
-
if (Object.keys(tag.props).length === 0 && !tag.innerHTML && !tag.textContent) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
|
|
30
|
-
Object.assign(schema[tag.tag], tag.props);
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
const s = tagToString(tag);
|
|
34
|
-
const tagPosition = tag.tagPosition || "head";
|
|
35
|
-
schema.tags[tagPosition] += schema.tags[tagPosition] ? `${lineBreaks}${s}` : s;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
headTags: schema.tags.head,
|
|
39
|
-
bodyTags: schema.tags.bodyClose,
|
|
40
|
-
bodyTagsOpen: schema.tags.bodyOpen,
|
|
41
|
-
htmlAttrs: propsToString(schema.htmlAttrs),
|
|
42
|
-
bodyAttrs: propsToString(schema.bodyAttrs)
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
6
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return "<";
|
|
53
|
-
case ">":
|
|
54
|
-
return ">";
|
|
55
|
-
case '"':
|
|
56
|
-
return """;
|
|
57
|
-
case "'":
|
|
58
|
-
return "'";
|
|
59
|
-
case "/":
|
|
60
|
-
return "/";
|
|
61
|
-
default:
|
|
62
|
-
return char;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function tagToString(tag) {
|
|
67
|
-
const attrs = propsToString(tag.props);
|
|
68
|
-
const openTag = `<${tag.tag}${attrs}>`;
|
|
69
|
-
if (!shared.TagsWithInnerContent.has(tag.tag))
|
|
70
|
-
return shared.SelfClosingTags.has(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
|
71
|
-
let content = String(tag.innerHTML || "");
|
|
72
|
-
if (tag.textContent)
|
|
73
|
-
content = escapeHtml(String(tag.textContent));
|
|
74
|
-
return shared.SelfClosingTags.has(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
|
75
|
-
}
|
|
7
|
+
Object.prototype.hasOwnProperty.call(server, '__proto__') &&
|
|
8
|
+
!Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
|
|
9
|
+
Object.defineProperty(exports, '__proto__', {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
value: server['__proto__']
|
|
12
|
+
});
|
|
76
13
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (!beforeRenderCtx.shouldRender) {
|
|
81
|
-
return {
|
|
82
|
-
headTags: "",
|
|
83
|
-
bodyTags: "",
|
|
84
|
-
bodyTagsOpen: "",
|
|
85
|
-
htmlAttrs: "",
|
|
86
|
-
bodyAttrs: ""
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
const ctx = { tags: await head.resolveTags() };
|
|
90
|
-
await head.hooks.callHook("ssr:render", ctx);
|
|
91
|
-
const html = ssrRenderTags(ctx.tags, options);
|
|
92
|
-
const renderCtx = { tags: ctx.tags, html };
|
|
93
|
-
await head.hooks.callHook("ssr:rendered", renderCtx);
|
|
94
|
-
return renderCtx.html;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
exports.escapeHtml = escapeHtml;
|
|
98
|
-
exports.propsToString = propsToString;
|
|
99
|
-
exports.renderSSRHead = renderSSRHead;
|
|
100
|
-
exports.ssrRenderTags = ssrRenderTags;
|
|
101
|
-
exports.tagToString = tagToString;
|
|
14
|
+
Object.keys(server).forEach(function (k) {
|
|
15
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = server[k];
|
|
16
|
+
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { SSRHeadPayload } from '@unhead/schema';
|
|
3
|
-
|
|
4
|
-
declare function renderSSRHead<T extends {}>(head: Unhead<T>, options?: RenderSSRHeadOptions): Promise<SSRHeadPayload>;
|
|
5
|
-
|
|
6
|
-
declare function propsToString(props: Record<string, any>): string;
|
|
7
|
-
|
|
8
|
-
declare function ssrRenderTags<T extends HeadTag>(tags: T[], options?: RenderSSRHeadOptions): {
|
|
9
|
-
headTags: string;
|
|
10
|
-
bodyTags: string;
|
|
11
|
-
bodyTagsOpen: string;
|
|
12
|
-
htmlAttrs: string;
|
|
13
|
-
bodyAttrs: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
declare function escapeHtml(str: string): string;
|
|
17
|
-
declare function tagToString<T extends HeadTag>(tag: T): string;
|
|
18
|
-
|
|
19
|
-
export { escapeHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
|
1
|
+
export * from 'unhead/server';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { SSRHeadPayload } from '@unhead/schema';
|
|
3
|
-
|
|
4
|
-
declare function renderSSRHead<T extends {}>(head: Unhead<T>, options?: RenderSSRHeadOptions): Promise<SSRHeadPayload>;
|
|
5
|
-
|
|
6
|
-
declare function propsToString(props: Record<string, any>): string;
|
|
7
|
-
|
|
8
|
-
declare function ssrRenderTags<T extends HeadTag>(tags: T[], options?: RenderSSRHeadOptions): {
|
|
9
|
-
headTags: string;
|
|
10
|
-
bodyTags: string;
|
|
11
|
-
bodyTagsOpen: string;
|
|
12
|
-
htmlAttrs: string;
|
|
13
|
-
bodyAttrs: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
declare function escapeHtml(str: string): string;
|
|
17
|
-
declare function tagToString<T extends HeadTag>(tag: T): string;
|
|
18
|
-
|
|
19
|
-
export { escapeHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
|
1
|
+
export * from 'unhead/server';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { SSRHeadPayload } from '@unhead/schema';
|
|
3
|
-
|
|
4
|
-
declare function renderSSRHead<T extends {}>(head: Unhead<T>, options?: RenderSSRHeadOptions): Promise<SSRHeadPayload>;
|
|
5
|
-
|
|
6
|
-
declare function propsToString(props: Record<string, any>): string;
|
|
7
|
-
|
|
8
|
-
declare function ssrRenderTags<T extends HeadTag>(tags: T[], options?: RenderSSRHeadOptions): {
|
|
9
|
-
headTags: string;
|
|
10
|
-
bodyTags: string;
|
|
11
|
-
bodyTagsOpen: string;
|
|
12
|
-
htmlAttrs: string;
|
|
13
|
-
bodyAttrs: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
declare function escapeHtml(str: string): string;
|
|
17
|
-
declare function tagToString<T extends HeadTag>(tag: T): string;
|
|
18
|
-
|
|
19
|
-
export { escapeHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
|
1
|
+
export * from 'unhead/server';
|
package/dist/index.mjs
CHANGED
|
@@ -1,95 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function encodeAttribute(value) {
|
|
4
|
-
return String(value).replace(/"/g, """);
|
|
5
|
-
}
|
|
6
|
-
function propsToString(props) {
|
|
7
|
-
let attrs = "";
|
|
8
|
-
for (const key in props) {
|
|
9
|
-
if (!Object.prototype.hasOwnProperty.call(props, key)) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
const value = props[key];
|
|
13
|
-
if (value !== false && value !== null) {
|
|
14
|
-
attrs += value === true ? ` ${key}` : ` ${key}="${encodeAttribute(value)}"`;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return attrs;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function ssrRenderTags(tags, options) {
|
|
21
|
-
const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: "", bodyClose: "", bodyOpen: "" } };
|
|
22
|
-
const lineBreaks = !options?.omitLineBreaks ? "\n" : "";
|
|
23
|
-
for (const tag of tags) {
|
|
24
|
-
if (Object.keys(tag.props).length === 0 && !tag.innerHTML && !tag.textContent) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
|
|
28
|
-
Object.assign(schema[tag.tag], tag.props);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const s = tagToString(tag);
|
|
32
|
-
const tagPosition = tag.tagPosition || "head";
|
|
33
|
-
schema.tags[tagPosition] += schema.tags[tagPosition] ? `${lineBreaks}${s}` : s;
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
headTags: schema.tags.head,
|
|
37
|
-
bodyTags: schema.tags.bodyClose,
|
|
38
|
-
bodyTagsOpen: schema.tags.bodyOpen,
|
|
39
|
-
htmlAttrs: propsToString(schema.htmlAttrs),
|
|
40
|
-
bodyAttrs: propsToString(schema.bodyAttrs)
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function escapeHtml(str) {
|
|
45
|
-
return str.replace(/[&<>"'/]/g, (char) => {
|
|
46
|
-
switch (char) {
|
|
47
|
-
case "&":
|
|
48
|
-
return "&";
|
|
49
|
-
case "<":
|
|
50
|
-
return "<";
|
|
51
|
-
case ">":
|
|
52
|
-
return ">";
|
|
53
|
-
case '"':
|
|
54
|
-
return """;
|
|
55
|
-
case "'":
|
|
56
|
-
return "'";
|
|
57
|
-
case "/":
|
|
58
|
-
return "/";
|
|
59
|
-
default:
|
|
60
|
-
return char;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
function tagToString(tag) {
|
|
65
|
-
const attrs = propsToString(tag.props);
|
|
66
|
-
const openTag = `<${tag.tag}${attrs}>`;
|
|
67
|
-
if (!TagsWithInnerContent.has(tag.tag))
|
|
68
|
-
return SelfClosingTags.has(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
|
69
|
-
let content = String(tag.innerHTML || "");
|
|
70
|
-
if (tag.textContent)
|
|
71
|
-
content = escapeHtml(String(tag.textContent));
|
|
72
|
-
return SelfClosingTags.has(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function renderSSRHead(head, options) {
|
|
76
|
-
const beforeRenderCtx = { shouldRender: true };
|
|
77
|
-
await head.hooks.callHook("ssr:beforeRender", beforeRenderCtx);
|
|
78
|
-
if (!beforeRenderCtx.shouldRender) {
|
|
79
|
-
return {
|
|
80
|
-
headTags: "",
|
|
81
|
-
bodyTags: "",
|
|
82
|
-
bodyTagsOpen: "",
|
|
83
|
-
htmlAttrs: "",
|
|
84
|
-
bodyAttrs: ""
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
const ctx = { tags: await head.resolveTags() };
|
|
88
|
-
await head.hooks.callHook("ssr:render", ctx);
|
|
89
|
-
const html = ssrRenderTags(ctx.tags, options);
|
|
90
|
-
const renderCtx = { tags: ctx.tags, html };
|
|
91
|
-
await head.hooks.callHook("ssr:rendered", renderCtx);
|
|
92
|
-
return renderCtx.html;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export { escapeHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
|
1
|
+
export * from 'unhead/server';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/ssr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-alpha.0",
|
|
5
5
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -28,13 +28,11 @@
|
|
|
28
28
|
"files": [
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"@unhead/shared": "1.11.14"
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"unhead": "2.0.0-alpha.0"
|
|
34
33
|
},
|
|
35
34
|
"scripts": {
|
|
36
35
|
"build": "unbuild .",
|
|
37
|
-
"stub": "unbuild . --stub"
|
|
38
|
-
"export:sizes": "npx export-size . -r"
|
|
36
|
+
"stub": "unbuild . --stub"
|
|
39
37
|
}
|
|
40
38
|
}
|