@unhead/dom 1.3.9 → 1.4.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 +7 -5
- package/dist/index.d.cts +31 -0
- package/dist/index.d.mts +31 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +8 -6
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
const shared = require('@unhead/shared');
|
|
4
4
|
|
|
5
|
-
function elementToTag($el) {
|
|
5
|
+
async function elementToTag($el) {
|
|
6
6
|
const tag = {
|
|
7
7
|
tag: $el.tagName.toLowerCase(),
|
|
8
|
-
props:
|
|
8
|
+
props: await shared.normaliseProps(
|
|
9
|
+
$el.getAttributeNames().reduce((props, name) => ({ ...props, [name]: $el.getAttribute(name) }), {})
|
|
10
|
+
),
|
|
9
11
|
innerHTML: $el.innerHTML
|
|
10
12
|
};
|
|
11
13
|
tag._d = shared.tagDedupeKey(tag);
|
|
@@ -32,7 +34,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
32
34
|
for (const key of ["body", "head"]) {
|
|
33
35
|
const children = dom?.[key]?.children;
|
|
34
36
|
for (const c of [...children].filter((c2) => shared.HasElementTags.includes(c2.tagName.toLowerCase())))
|
|
35
|
-
state.elMap[c.getAttribute("data-hid") || shared.hashTag(elementToTag(c))] = c;
|
|
37
|
+
state.elMap[c.getAttribute("data-hid") || shared.hashTag(await elementToTag(c))] = c;
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
state.pendingSideEffects = { ...state.sideEffects || {} };
|
|
@@ -55,7 +57,6 @@ async function renderDOMHead(head, options = {}) {
|
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
Object.entries(tag.props).forEach(([k, value]) => {
|
|
58
|
-
value = String(value);
|
|
59
60
|
const ck = `attr:${k}`;
|
|
60
61
|
if (k === "class") {
|
|
61
62
|
for (const c of (value || "").split(" ").filter(Boolean)) {
|
|
@@ -63,7 +64,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
63
64
|
!$el.classList.contains(c) && $el.classList.add(c);
|
|
64
65
|
}
|
|
65
66
|
} else {
|
|
66
|
-
$el.getAttribute(k) !== value && $el.setAttribute(k, value);
|
|
67
|
+
$el.getAttribute(k) !== value && $el.setAttribute(k, value === true ? "" : String(value));
|
|
67
68
|
isAttrTag && track(id, ck, () => $el.removeAttribute(k));
|
|
68
69
|
}
|
|
69
70
|
});
|
|
@@ -114,6 +115,7 @@ async function debouncedRenderDOMHead(head, options = {}) {
|
|
|
114
115
|
}));
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
// @__NO_SIDE_EFFECTS__
|
|
117
119
|
function DomPlugin(options) {
|
|
118
120
|
return shared.defineHeadPlugin((head) => {
|
|
119
121
|
const initialPayload = head.resolvedOptions.document?.head.querySelector('script[id="unhead:payload"]')?.innerHTML || false;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as _unhead_schema from '@unhead/schema';
|
|
2
|
+
import { Unhead } from '@unhead/schema';
|
|
3
|
+
|
|
4
|
+
interface RenderDomHeadOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Document to use for rendering. Allows stubbing for testing.
|
|
7
|
+
*/
|
|
8
|
+
document?: Document;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Render the head tags to the DOM.
|
|
12
|
+
*/
|
|
13
|
+
declare function renderDOMHead<T extends Unhead<any>>(head: T, options?: RenderDomHeadOptions): Promise<void>;
|
|
14
|
+
|
|
15
|
+
interface DomPluginOptions extends RenderDomHeadOptions {
|
|
16
|
+
delayFn?: (fn: () => void) => void;
|
|
17
|
+
}
|
|
18
|
+
declare function DomPlugin(options?: DomPluginOptions): _unhead_schema.HeadPlugin;
|
|
19
|
+
|
|
20
|
+
interface DebouncedRenderDomHeadOptions extends RenderDomHeadOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Specify a custom delay function for delaying the render.
|
|
23
|
+
*/
|
|
24
|
+
delayFn?: (fn: () => void) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Queue a debounced update of the DOM head.
|
|
28
|
+
*/
|
|
29
|
+
declare function debouncedRenderDOMHead<T extends Unhead<any>>(head: T, options?: DebouncedRenderDomHeadOptions): Promise<void>;
|
|
30
|
+
|
|
31
|
+
export { type DebouncedRenderDomHeadOptions, DomPlugin, type DomPluginOptions, type RenderDomHeadOptions, debouncedRenderDOMHead, renderDOMHead };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as _unhead_schema from '@unhead/schema';
|
|
2
|
+
import { Unhead } from '@unhead/schema';
|
|
3
|
+
|
|
4
|
+
interface RenderDomHeadOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Document to use for rendering. Allows stubbing for testing.
|
|
7
|
+
*/
|
|
8
|
+
document?: Document;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Render the head tags to the DOM.
|
|
12
|
+
*/
|
|
13
|
+
declare function renderDOMHead<T extends Unhead<any>>(head: T, options?: RenderDomHeadOptions): Promise<void>;
|
|
14
|
+
|
|
15
|
+
interface DomPluginOptions extends RenderDomHeadOptions {
|
|
16
|
+
delayFn?: (fn: () => void) => void;
|
|
17
|
+
}
|
|
18
|
+
declare function DomPlugin(options?: DomPluginOptions): _unhead_schema.HeadPlugin;
|
|
19
|
+
|
|
20
|
+
interface DebouncedRenderDomHeadOptions extends RenderDomHeadOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Specify a custom delay function for delaying the render.
|
|
23
|
+
*/
|
|
24
|
+
delayFn?: (fn: () => void) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Queue a debounced update of the DOM head.
|
|
28
|
+
*/
|
|
29
|
+
declare function debouncedRenderDOMHead<T extends Unhead<any>>(head: T, options?: DebouncedRenderDomHeadOptions): Promise<void>;
|
|
30
|
+
|
|
31
|
+
export { type DebouncedRenderDomHeadOptions, DomPlugin, type DomPluginOptions, type RenderDomHeadOptions, debouncedRenderDOMHead, renderDOMHead };
|
package/dist/index.d.ts
CHANGED
|
@@ -28,4 +28,4 @@ interface DebouncedRenderDomHeadOptions extends RenderDomHeadOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
declare function debouncedRenderDOMHead<T extends Unhead<any>>(head: T, options?: DebouncedRenderDomHeadOptions): Promise<void>;
|
|
30
30
|
|
|
31
|
-
export { DebouncedRenderDomHeadOptions, DomPlugin, DomPluginOptions, RenderDomHeadOptions, debouncedRenderDOMHead, renderDOMHead };
|
|
31
|
+
export { type DebouncedRenderDomHeadOptions, DomPlugin, type DomPluginOptions, type RenderDomHeadOptions, debouncedRenderDOMHead, renderDOMHead };
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { HasElementTags, hashTag, tagDedupeKey, defineHeadPlugin } from '@unhead/shared';
|
|
1
|
+
import { HasElementTags, hashTag, normaliseProps, tagDedupeKey, defineHeadPlugin } from '@unhead/shared';
|
|
2
2
|
|
|
3
|
-
function elementToTag($el) {
|
|
3
|
+
async function elementToTag($el) {
|
|
4
4
|
const tag = {
|
|
5
5
|
tag: $el.tagName.toLowerCase(),
|
|
6
|
-
props:
|
|
6
|
+
props: await normaliseProps(
|
|
7
|
+
$el.getAttributeNames().reduce((props, name) => ({ ...props, [name]: $el.getAttribute(name) }), {})
|
|
8
|
+
),
|
|
7
9
|
innerHTML: $el.innerHTML
|
|
8
10
|
};
|
|
9
11
|
tag._d = tagDedupeKey(tag);
|
|
@@ -30,7 +32,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
30
32
|
for (const key of ["body", "head"]) {
|
|
31
33
|
const children = dom?.[key]?.children;
|
|
32
34
|
for (const c of [...children].filter((c2) => HasElementTags.includes(c2.tagName.toLowerCase())))
|
|
33
|
-
state.elMap[c.getAttribute("data-hid") || hashTag(elementToTag(c))] = c;
|
|
35
|
+
state.elMap[c.getAttribute("data-hid") || hashTag(await elementToTag(c))] = c;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
state.pendingSideEffects = { ...state.sideEffects || {} };
|
|
@@ -53,7 +55,6 @@ async function renderDOMHead(head, options = {}) {
|
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
Object.entries(tag.props).forEach(([k, value]) => {
|
|
56
|
-
value = String(value);
|
|
57
58
|
const ck = `attr:${k}`;
|
|
58
59
|
if (k === "class") {
|
|
59
60
|
for (const c of (value || "").split(" ").filter(Boolean)) {
|
|
@@ -61,7 +62,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
61
62
|
!$el.classList.contains(c) && $el.classList.add(c);
|
|
62
63
|
}
|
|
63
64
|
} else {
|
|
64
|
-
$el.getAttribute(k) !== value && $el.setAttribute(k, value);
|
|
65
|
+
$el.getAttribute(k) !== value && $el.setAttribute(k, value === true ? "" : String(value));
|
|
65
66
|
isAttrTag && track(id, ck, () => $el.removeAttribute(k));
|
|
66
67
|
}
|
|
67
68
|
});
|
|
@@ -112,6 +113,7 @@ async function debouncedRenderDOMHead(head, options = {}) {
|
|
|
112
113
|
}));
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
// @__NO_SIDE_EFFECTS__
|
|
115
117
|
function DomPlugin(options) {
|
|
116
118
|
return defineHeadPlugin((head) => {
|
|
117
119
|
const initialPayload = head.resolvedOptions.document?.head.querySelector('script[id="unhead:payload"]')?.innerHTML || false;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/dom",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
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.
|
|
33
|
-
"@unhead/shared": "1.
|
|
32
|
+
"@unhead/schema": "1.4.0",
|
|
33
|
+
"@unhead/shared": "1.4.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "unbuild .",
|