@unhead/ssr 1.9.16 → 1.10.0-beta.3

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 CHANGED
@@ -6,12 +6,17 @@ function encodeAttribute(value) {
6
6
  return String(value).replace(/"/g, """);
7
7
  }
8
8
  function propsToString(props) {
9
- const attrs = [];
10
- for (const [key, value] of Object.entries(props)) {
11
- if (value !== false && value !== null)
12
- attrs.push(value === true ? key : `${key}="${encodeAttribute(value)}"`);
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
+ }
13
18
  }
14
- return `${attrs.length > 0 ? " " : ""}${attrs.join(" ")}`;
19
+ return attrs;
15
20
  }
16
21
 
17
22
  function escapeHtml(str) {
@@ -37,28 +42,30 @@ function escapeHtml(str) {
37
42
  function tagToString(tag) {
38
43
  const attrs = propsToString(tag.props);
39
44
  const openTag = `<${tag.tag}${attrs}>`;
40
- if (!shared.TagsWithInnerContent.includes(tag.tag))
41
- return shared.SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
45
+ if (!shared.TagsWithInnerContent.has(tag.tag))
46
+ return shared.SelfClosingTags.has(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
42
47
  let content = String(tag.innerHTML || "");
43
48
  if (tag.textContent)
44
49
  content = escapeHtml(String(tag.textContent));
45
- return shared.SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
50
+ return shared.SelfClosingTags.has(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
46
51
  }
47
52
 
48
53
  function ssrRenderTags(tags, options) {
49
- const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: [], bodyClose: [], bodyOpen: [] } };
54
+ const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: "", bodyClose: "", bodyOpen: "" } };
55
+ const lineBreaks = !options?.omitLineBreaks ? "\n" : "";
50
56
  for (const tag of tags) {
51
57
  if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
52
- schema[tag.tag] = { ...schema[tag.tag], ...tag.props };
58
+ Object.assign(schema[tag.tag], tag.props);
53
59
  continue;
54
60
  }
55
- schema.tags[tag.tagPosition || "head"].push(tagToString(tag));
61
+ const s = tagToString(tag);
62
+ const tagPosition = tag.tagPosition || "head";
63
+ schema.tags[tagPosition] += schema.tags[tagPosition] ? `${lineBreaks}${s}` : s;
56
64
  }
57
- const lineBreaks = !options?.omitLineBreaks ? "\n" : "";
58
65
  return {
59
- headTags: schema.tags.head.join(lineBreaks),
60
- bodyTags: schema.tags.bodyClose.join(lineBreaks),
61
- bodyTagsOpen: schema.tags.bodyOpen.join(lineBreaks),
66
+ headTags: schema.tags.head,
67
+ bodyTags: schema.tags.bodyClose,
68
+ bodyTagsOpen: schema.tags.bodyOpen,
62
69
  htmlAttrs: propsToString(schema.htmlAttrs),
63
70
  bodyAttrs: propsToString(schema.bodyAttrs)
64
71
  };
package/dist/index.mjs CHANGED
@@ -4,12 +4,17 @@ function encodeAttribute(value) {
4
4
  return String(value).replace(/"/g, "&quot;");
5
5
  }
6
6
  function propsToString(props) {
7
- const attrs = [];
8
- for (const [key, value] of Object.entries(props)) {
9
- if (value !== false && value !== null)
10
- attrs.push(value === true ? key : `${key}="${encodeAttribute(value)}"`);
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
+ }
11
16
  }
12
- return `${attrs.length > 0 ? " " : ""}${attrs.join(" ")}`;
17
+ return attrs;
13
18
  }
14
19
 
15
20
  function escapeHtml(str) {
@@ -35,28 +40,30 @@ function escapeHtml(str) {
35
40
  function tagToString(tag) {
36
41
  const attrs = propsToString(tag.props);
37
42
  const openTag = `<${tag.tag}${attrs}>`;
38
- if (!TagsWithInnerContent.includes(tag.tag))
39
- return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
43
+ if (!TagsWithInnerContent.has(tag.tag))
44
+ return SelfClosingTags.has(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
40
45
  let content = String(tag.innerHTML || "");
41
46
  if (tag.textContent)
42
47
  content = escapeHtml(String(tag.textContent));
43
- return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
48
+ return SelfClosingTags.has(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
44
49
  }
45
50
 
46
51
  function ssrRenderTags(tags, options) {
47
- const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: [], bodyClose: [], bodyOpen: [] } };
52
+ const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: "", bodyClose: "", bodyOpen: "" } };
53
+ const lineBreaks = !options?.omitLineBreaks ? "\n" : "";
48
54
  for (const tag of tags) {
49
55
  if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
50
- schema[tag.tag] = { ...schema[tag.tag], ...tag.props };
56
+ Object.assign(schema[tag.tag], tag.props);
51
57
  continue;
52
58
  }
53
- schema.tags[tag.tagPosition || "head"].push(tagToString(tag));
59
+ const s = tagToString(tag);
60
+ const tagPosition = tag.tagPosition || "head";
61
+ schema.tags[tagPosition] += schema.tags[tagPosition] ? `${lineBreaks}${s}` : s;
54
62
  }
55
- const lineBreaks = !options?.omitLineBreaks ? "\n" : "";
56
63
  return {
57
- headTags: schema.tags.head.join(lineBreaks),
58
- bodyTags: schema.tags.bodyClose.join(lineBreaks),
59
- bodyTagsOpen: schema.tags.bodyOpen.join(lineBreaks),
64
+ headTags: schema.tags.head,
65
+ bodyTags: schema.tags.bodyClose,
66
+ bodyTagsOpen: schema.tags.bodyOpen,
60
67
  htmlAttrs: propsToString(schema.htmlAttrs),
61
68
  bodyAttrs: propsToString(schema.bodyAttrs)
62
69
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/ssr",
3
3
  "type": "module",
4
- "version": "1.9.16",
4
+ "version": "1.10.0-beta.3",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -29,8 +29,8 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@unhead/schema": "1.9.16",
33
- "@unhead/shared": "1.9.16"
32
+ "@unhead/schema": "1.10.0-beta.3",
33
+ "@unhead/shared": "1.10.0-beta.3"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "unbuild .",