@unhead/dom 1.8.10 → 1.8.12
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 +26 -14
- package/dist/index.mjs +26 -14
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2,17 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const shared = require('@unhead/shared');
|
|
4
4
|
|
|
5
|
-
async function elementToTag($el) {
|
|
6
|
-
const tag = {
|
|
7
|
-
tag: $el.tagName.toLowerCase(),
|
|
8
|
-
props: await shared.normaliseProps(
|
|
9
|
-
$el.getAttributeNames().reduce((props, name) => ({ ...props, [name]: $el.getAttribute(name) }), {})
|
|
10
|
-
),
|
|
11
|
-
innerHTML: $el.innerHTML
|
|
12
|
-
};
|
|
13
|
-
tag._d = shared.tagDedupeKey(tag);
|
|
14
|
-
return tag;
|
|
15
|
-
}
|
|
16
5
|
async function renderDOMHead(head, options = {}) {
|
|
17
6
|
const dom = options.document || head.resolvedOptions.document;
|
|
18
7
|
if (!dom)
|
|
@@ -33,8 +22,23 @@ async function renderDOMHead(head, options = {}) {
|
|
|
33
22
|
};
|
|
34
23
|
for (const key of ["body", "head"]) {
|
|
35
24
|
const children = dom?.[key]?.children;
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
const tags2 = [];
|
|
26
|
+
for (const c of [...children].filter((c2) => shared.HasElementTags.includes(c2.tagName.toLowerCase()))) {
|
|
27
|
+
const t = {
|
|
28
|
+
tag: c.tagName.toLowerCase(),
|
|
29
|
+
props: await shared.normaliseProps(
|
|
30
|
+
c.getAttributeNames().reduce((props, name) => ({ ...props, [name]: c.getAttribute(name) }), {})
|
|
31
|
+
),
|
|
32
|
+
innerHTML: c.innerHTML
|
|
33
|
+
};
|
|
34
|
+
let i = 1;
|
|
35
|
+
let d = shared.tagDedupeKey(t);
|
|
36
|
+
while (d && tags2.find((t2) => t2._d === d))
|
|
37
|
+
d = `${d}:${i++}`;
|
|
38
|
+
t._d = d || void 0;
|
|
39
|
+
tags2.push(t);
|
|
40
|
+
state.elMap[c.getAttribute("data-hid") || shared.hashTag(t)] = c;
|
|
41
|
+
}
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
state.pendingSideEffects = { ...state.sideEffects || {} };
|
|
@@ -52,7 +56,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
52
56
|
tag[k] && tag[k] !== $el[k] && ($el[k] = tag[k]);
|
|
53
57
|
});
|
|
54
58
|
track(id, "el", () => {
|
|
55
|
-
state.elMap[id]
|
|
59
|
+
state.elMap[id]?.remove();
|
|
56
60
|
delete state.elMap[id];
|
|
57
61
|
});
|
|
58
62
|
}
|
|
@@ -63,6 +67,14 @@ async function renderDOMHead(head, options = {}) {
|
|
|
63
67
|
isAttrTag && track(id, `${ck}:${c}`, () => $el.classList.remove(c));
|
|
64
68
|
!$el.classList.contains(c) && $el.classList.add(c);
|
|
65
69
|
}
|
|
70
|
+
} else if (k === "style") {
|
|
71
|
+
for (const c of (value || "").split(";").filter(Boolean)) {
|
|
72
|
+
const [k2, v] = c.split(":").map((s) => s.trim());
|
|
73
|
+
track(id, `${ck}:${c}:${k2}`, () => {
|
|
74
|
+
$el.style.removeProperty(k2);
|
|
75
|
+
});
|
|
76
|
+
$el.style.setProperty(k2, v);
|
|
77
|
+
}
|
|
66
78
|
} else {
|
|
67
79
|
$el.getAttribute(k) !== value && $el.setAttribute(k, value === true ? "" : String(value));
|
|
68
80
|
isAttrTag && track(id, ck, () => $el.removeAttribute(k));
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { HasElementTags, hashTag, normaliseProps, tagDedupeKey, defineHeadPlugin } from '@unhead/shared';
|
|
2
2
|
|
|
3
|
-
async function elementToTag($el) {
|
|
4
|
-
const tag = {
|
|
5
|
-
tag: $el.tagName.toLowerCase(),
|
|
6
|
-
props: await normaliseProps(
|
|
7
|
-
$el.getAttributeNames().reduce((props, name) => ({ ...props, [name]: $el.getAttribute(name) }), {})
|
|
8
|
-
),
|
|
9
|
-
innerHTML: $el.innerHTML
|
|
10
|
-
};
|
|
11
|
-
tag._d = tagDedupeKey(tag);
|
|
12
|
-
return tag;
|
|
13
|
-
}
|
|
14
3
|
async function renderDOMHead(head, options = {}) {
|
|
15
4
|
const dom = options.document || head.resolvedOptions.document;
|
|
16
5
|
if (!dom)
|
|
@@ -31,8 +20,23 @@ async function renderDOMHead(head, options = {}) {
|
|
|
31
20
|
};
|
|
32
21
|
for (const key of ["body", "head"]) {
|
|
33
22
|
const children = dom?.[key]?.children;
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
const tags2 = [];
|
|
24
|
+
for (const c of [...children].filter((c2) => HasElementTags.includes(c2.tagName.toLowerCase()))) {
|
|
25
|
+
const t = {
|
|
26
|
+
tag: c.tagName.toLowerCase(),
|
|
27
|
+
props: await normaliseProps(
|
|
28
|
+
c.getAttributeNames().reduce((props, name) => ({ ...props, [name]: c.getAttribute(name) }), {})
|
|
29
|
+
),
|
|
30
|
+
innerHTML: c.innerHTML
|
|
31
|
+
};
|
|
32
|
+
let i = 1;
|
|
33
|
+
let d = tagDedupeKey(t);
|
|
34
|
+
while (d && tags2.find((t2) => t2._d === d))
|
|
35
|
+
d = `${d}:${i++}`;
|
|
36
|
+
t._d = d || void 0;
|
|
37
|
+
tags2.push(t);
|
|
38
|
+
state.elMap[c.getAttribute("data-hid") || hashTag(t)] = c;
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
state.pendingSideEffects = { ...state.sideEffects || {} };
|
|
@@ -50,7 +54,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
50
54
|
tag[k] && tag[k] !== $el[k] && ($el[k] = tag[k]);
|
|
51
55
|
});
|
|
52
56
|
track(id, "el", () => {
|
|
53
|
-
state.elMap[id]
|
|
57
|
+
state.elMap[id]?.remove();
|
|
54
58
|
delete state.elMap[id];
|
|
55
59
|
});
|
|
56
60
|
}
|
|
@@ -61,6 +65,14 @@ async function renderDOMHead(head, options = {}) {
|
|
|
61
65
|
isAttrTag && track(id, `${ck}:${c}`, () => $el.classList.remove(c));
|
|
62
66
|
!$el.classList.contains(c) && $el.classList.add(c);
|
|
63
67
|
}
|
|
68
|
+
} else if (k === "style") {
|
|
69
|
+
for (const c of (value || "").split(";").filter(Boolean)) {
|
|
70
|
+
const [k2, v] = c.split(":").map((s) => s.trim());
|
|
71
|
+
track(id, `${ck}:${c}:${k2}`, () => {
|
|
72
|
+
$el.style.removeProperty(k2);
|
|
73
|
+
});
|
|
74
|
+
$el.style.setProperty(k2, v);
|
|
75
|
+
}
|
|
64
76
|
} else {
|
|
65
77
|
$el.getAttribute(k) !== value && $el.setAttribute(k, value === true ? "" : String(value));
|
|
66
78
|
isAttrTag && track(id, ck, () => $el.removeAttribute(k));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/dom",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.8.
|
|
4
|
+
"version": "1.8.12",
|
|
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.8.
|
|
33
|
-
"@unhead/shared": "1.8.
|
|
32
|
+
"@unhead/schema": "1.8.12",
|
|
33
|
+
"@unhead/shared": "1.8.12"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "unbuild .",
|