unhead 2.0.0-alpha.9 → 2.0.0-beta.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/client.d.mts +4 -13
- package/dist/client.d.ts +4 -13
- package/dist/client.mjs +80 -63
- package/dist/index.d.mts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.mjs +8 -36
- package/dist/legacy.d.mts +10 -109
- package/dist/legacy.d.ts +10 -109
- package/dist/legacy.mjs +18 -279
- package/dist/plugins.d.mts +40 -16
- package/dist/plugins.d.ts +40 -16
- package/dist/plugins.mjs +82 -74
- package/dist/scripts.d.mts +8 -0
- package/dist/scripts.d.ts +8 -0
- package/dist/scripts.mjs +30 -0
- package/dist/server.d.mts +6 -8
- package/dist/server.d.ts +6 -8
- package/dist/server.mjs +60 -21
- package/dist/shared/unhead.BHfOzKG2.mjs +266 -0
- package/dist/shared/unhead.BPM0-cfG.mjs +44 -0
- package/dist/shared/unhead.Bc1vIJ23.d.ts +10 -0
- package/dist/shared/unhead.Bj0vvOrH.d.ts +68 -0
- package/dist/shared/unhead.CApf5sj3.mjs +148 -0
- package/dist/shared/unhead.CydFxwlU.mjs +162 -0
- package/dist/shared/unhead.DLPWlHGE.d.mts +68 -0
- package/dist/shared/unhead.DQc16pHI.mjs +196 -0
- package/dist/shared/unhead.DVcP39oW.d.mts +2303 -0
- package/dist/shared/unhead.DVcP39oW.d.ts +2303 -0
- package/dist/shared/unhead.DZbvapt-.mjs +70 -0
- package/dist/shared/unhead.DnNYlT4k.mjs +155 -0
- package/dist/shared/unhead.UCwgwV97.d.mts +10 -0
- package/dist/shared/unhead.kVuXtrDW.mjs +48 -0
- package/dist/shared/unhead.xsi8MZXD.mjs +177 -0
- package/dist/shared/unhead.yem5I2v_.mjs +38 -0
- package/dist/types.d.mts +265 -0
- package/dist/types.d.ts +265 -0
- package/dist/types.mjs +1 -0
- package/dist/utils.d.mts +34 -0
- package/dist/utils.d.ts +34 -0
- package/dist/utils.mjs +5 -0
- package/package.json +35 -21
- package/scripts.d.ts +1 -0
- package/types.d.ts +1 -0
- package/utils.d.ts +1 -0
- package/dist/client.cjs +0 -206
- package/dist/client.d.cts +0 -22
- package/dist/index.cjs +0 -42
- package/dist/index.d.cts +0 -9
- package/dist/legacy.cjs +0 -323
- package/dist/legacy.d.cts +0 -115
- package/dist/plugins.cjs +0 -96
- package/dist/plugins.d.cts +0 -41
- package/dist/server.cjs +0 -183
- package/dist/server.d.cts +0 -30
- package/dist/shared/unhead.9459P6Us.mjs +0 -216
- package/dist/shared/unhead.B1vp-BN3.cjs +0 -63
- package/dist/shared/unhead.BxRHFjqA.cjs +0 -104
- package/dist/shared/unhead.Bxnr6E-l.mjs +0 -65
- package/dist/shared/unhead.D--bHScR.d.cts +0 -11
- package/dist/shared/unhead.D--bHScR.d.mts +0 -11
- package/dist/shared/unhead.D--bHScR.d.ts +0 -11
- package/dist/shared/unhead.DGQq1RAN.cjs +0 -58
- package/dist/shared/unhead.DbMOoWpX.cjs +0 -222
- package/dist/shared/unhead.Dk9EcP_t.mjs +0 -60
- package/dist/shared/unhead.YfQbj2z7.mjs +0 -55
- package/dist/shared/unhead.aU5fNi04.mjs +0 -102
- package/dist/shared/unhead.nhdFb1MX.cjs +0 -68
package/dist/client.d.mts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { R as ResolvableHead, q as CreateClientHeadOptions, U as Unhead, G as RenderDomHeadOptions } from './shared/unhead.DVcP39oW.mjs';
|
|
2
|
+
import 'hookable';
|
|
3
3
|
|
|
4
|
-
declare function createHead<T
|
|
5
|
-
|
|
6
|
-
declare function DomPlugin(options: DomPluginOptions): _unhead_schema.HeadPluginInput;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Supports DOM event handlers (i.e `onload`) as functions.
|
|
10
|
-
*
|
|
11
|
-
* When SSR we need to strip out these values. On CSR we
|
|
12
|
-
*/
|
|
13
|
-
declare const ClientEventHandlerPlugin: _unhead_schema.HeadPluginInput;
|
|
4
|
+
declare function createHead<T = ResolvableHead>(options?: CreateClientHeadOptions): Unhead<T>;
|
|
14
5
|
|
|
15
6
|
/**
|
|
16
7
|
* Render the head tags to the DOM.
|
|
@@ -19,4 +10,4 @@ declare function renderDOMHead<T extends Unhead<any>>(head: T, options?: RenderD
|
|
|
19
10
|
|
|
20
11
|
declare function createDebouncedFn(callee: () => void, delayer: (fn: () => void) => void): () => void;
|
|
21
12
|
|
|
22
|
-
export {
|
|
13
|
+
export { createDebouncedFn, createHead, renderDOMHead };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { R as ResolvableHead, q as CreateClientHeadOptions, U as Unhead, G as RenderDomHeadOptions } from './shared/unhead.DVcP39oW.js';
|
|
2
|
+
import 'hookable';
|
|
3
3
|
|
|
4
|
-
declare function createHead<T
|
|
5
|
-
|
|
6
|
-
declare function DomPlugin(options: DomPluginOptions): _unhead_schema.HeadPluginInput;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Supports DOM event handlers (i.e `onload`) as functions.
|
|
10
|
-
*
|
|
11
|
-
* When SSR we need to strip out these values. On CSR we
|
|
12
|
-
*/
|
|
13
|
-
declare const ClientEventHandlerPlugin: _unhead_schema.HeadPluginInput;
|
|
4
|
+
declare function createHead<T = ResolvableHead>(options?: CreateClientHeadOptions): Unhead<T>;
|
|
14
5
|
|
|
15
6
|
/**
|
|
16
7
|
* Render the head tags to the DOM.
|
|
@@ -19,4 +10,4 @@ declare function renderDOMHead<T extends Unhead<any>>(head: T, options?: RenderD
|
|
|
19
10
|
|
|
20
11
|
declare function createDebouncedFn(callee: () => void, delayer: (fn: () => void) => void): () => void;
|
|
21
12
|
|
|
22
|
-
export {
|
|
13
|
+
export { createDebouncedFn, createHead, renderDOMHead };
|
package/dist/client.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { a as createUnhead } from './shared/unhead.CydFxwlU.mjs';
|
|
2
|
+
import { H as HasElementTags } from './shared/unhead.yem5I2v_.mjs';
|
|
3
|
+
import { h as hashTag, i as isMetaArrayDupeKey, a as normalizeProps, d as dedupeKey } from './shared/unhead.xsi8MZXD.mjs';
|
|
4
4
|
import 'hookable';
|
|
5
|
-
import './shared/unhead.
|
|
5
|
+
import './shared/unhead.DZbvapt-.mjs';
|
|
6
6
|
|
|
7
7
|
async function renderDOMHead(head, options = {}) {
|
|
8
8
|
const dom = options.document || head.resolvedOptions.document;
|
|
@@ -16,17 +16,30 @@ async function renderDOMHead(head, options = {}) {
|
|
|
16
16
|
return head._domUpdatePromise;
|
|
17
17
|
}
|
|
18
18
|
head._domUpdatePromise = new Promise(async (resolve) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const dupeKeyCounter = /* @__PURE__ */ new Map();
|
|
20
|
+
const resolveTagPromise = new Promise((resolve2) => {
|
|
21
|
+
head.resolveTags().then((tags2) => {
|
|
22
|
+
resolve2(
|
|
23
|
+
tags2.map((tag) => {
|
|
24
|
+
const count = dupeKeyCounter.get(tag._d) || 0;
|
|
25
|
+
const res = {
|
|
26
|
+
tag,
|
|
27
|
+
id: (count ? `${tag._d}:${count}` : tag._d) || hashTag(tag),
|
|
28
|
+
shouldRender: true
|
|
29
|
+
};
|
|
30
|
+
if (tag._d && isMetaArrayDupeKey(tag._d)) {
|
|
31
|
+
dupeKeyCounter.set(tag._d, count + 1);
|
|
32
|
+
}
|
|
33
|
+
return res;
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
24
38
|
let state = head._dom;
|
|
25
39
|
if (!state) {
|
|
26
40
|
state = {
|
|
27
|
-
elMap:
|
|
41
|
+
elMap: (/* @__PURE__ */ new Map()).set("htmlAttrs", dom.documentElement).set("bodyAttrs", dom.body)
|
|
28
42
|
};
|
|
29
|
-
const takenDedupeKeys = /* @__PURE__ */ new Set();
|
|
30
43
|
for (const key of ["body", "head"]) {
|
|
31
44
|
const children = dom[key]?.children;
|
|
32
45
|
for (const c of children) {
|
|
@@ -34,23 +47,25 @@ async function renderDOMHead(head, options = {}) {
|
|
|
34
47
|
if (!HasElementTags.has(tag)) {
|
|
35
48
|
continue;
|
|
36
49
|
}
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
props
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const next = normalizeProps({ tag, props: {} }, {
|
|
51
|
+
innerHTML: c.innerHTML,
|
|
52
|
+
...c.getAttributeNames().reduce((props, name) => {
|
|
53
|
+
props[name] = c.getAttribute(name);
|
|
54
|
+
return props;
|
|
55
|
+
}, {}) || {}
|
|
56
|
+
});
|
|
57
|
+
next.key = c.getAttribute("data-hid") || void 0;
|
|
58
|
+
next._d = dedupeKey(next) || hashTag(next);
|
|
59
|
+
if (state.elMap.has(next._d)) {
|
|
60
|
+
let count = 1;
|
|
61
|
+
let k = next._d;
|
|
62
|
+
while (state.elMap.has(k)) {
|
|
63
|
+
k = `${next._d}:${count++}`;
|
|
64
|
+
}
|
|
65
|
+
state.elMap.set(k, c);
|
|
66
|
+
} else {
|
|
67
|
+
state.elMap.set(next._d, c);
|
|
52
68
|
}
|
|
53
|
-
state.elMap[c.getAttribute("data-hid") || hashTag(t)] = c;
|
|
54
69
|
}
|
|
55
70
|
}
|
|
56
71
|
}
|
|
@@ -63,7 +78,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
63
78
|
}
|
|
64
79
|
function trackCtx({ id, $el, tag }) {
|
|
65
80
|
const isAttrTag = tag.tag.endsWith("Attrs");
|
|
66
|
-
state.elMap
|
|
81
|
+
state.elMap.set(id, $el);
|
|
67
82
|
if (!isAttrTag) {
|
|
68
83
|
if (tag.textContent && tag.textContent !== $el.textContent) {
|
|
69
84
|
$el.textContent = tag.textContent;
|
|
@@ -72,36 +87,36 @@ async function renderDOMHead(head, options = {}) {
|
|
|
72
87
|
$el.innerHTML = tag.innerHTML;
|
|
73
88
|
}
|
|
74
89
|
track(id, "el", () => {
|
|
75
|
-
|
|
76
|
-
|
|
90
|
+
$el?.remove();
|
|
91
|
+
state.elMap.delete(id);
|
|
77
92
|
});
|
|
78
93
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
94
|
+
for (const k in tag.props) {
|
|
95
|
+
if (!Object.hasOwn(tag.props, k))
|
|
96
|
+
continue;
|
|
97
|
+
const value = tag.props[k];
|
|
98
|
+
if (k.startsWith("on") && typeof value === "function") {
|
|
99
|
+
const dataset = $el?.dataset;
|
|
100
|
+
if (dataset && dataset[`${k}fired`]) {
|
|
101
|
+
const ek = k.slice(0, -5);
|
|
102
|
+
value.call($el, new Event(ek.substring(2)));
|
|
83
103
|
}
|
|
84
104
|
if ($el.getAttribute(`data-${k}`) !== "") {
|
|
85
105
|
(tag.tag === "bodyAttrs" ? dom.defaultView : $el).addEventListener(
|
|
86
106
|
// onload -> load
|
|
87
107
|
k.substring(2),
|
|
88
|
-
|
|
108
|
+
value.bind($el)
|
|
89
109
|
);
|
|
90
110
|
$el.setAttribute(`data-${k}`, "");
|
|
91
111
|
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
for (const k in tag.props) {
|
|
95
|
-
if (!Object.prototype.hasOwnProperty.call(tag.props, k)) {
|
|
96
112
|
continue;
|
|
97
113
|
}
|
|
98
|
-
const value = tag.props[k];
|
|
99
114
|
const ck = `attr:${k}`;
|
|
100
115
|
if (k === "class") {
|
|
101
116
|
if (!value) {
|
|
102
117
|
continue;
|
|
103
118
|
}
|
|
104
|
-
for (const c of value
|
|
119
|
+
for (const c of value) {
|
|
105
120
|
isAttrTag && track(id, `${ck}:${c}`, () => $el.classList.remove(c));
|
|
106
121
|
!$el.classList.contains(c) && $el.classList.add(c);
|
|
107
122
|
}
|
|
@@ -109,16 +124,13 @@ async function renderDOMHead(head, options = {}) {
|
|
|
109
124
|
if (!value) {
|
|
110
125
|
continue;
|
|
111
126
|
}
|
|
112
|
-
for (const
|
|
113
|
-
const propIndex = c.indexOf(":");
|
|
114
|
-
const k2 = c.substring(0, propIndex).trim();
|
|
115
|
-
const v = c.substring(propIndex + 1).trim();
|
|
127
|
+
for (const [k2, v] of value) {
|
|
116
128
|
track(id, `${ck}:${k2}`, () => {
|
|
117
129
|
$el.style.removeProperty(k2);
|
|
118
130
|
});
|
|
119
131
|
$el.style.setProperty(k2, v);
|
|
120
132
|
}
|
|
121
|
-
} else {
|
|
133
|
+
} else if (value !== false && value !== null) {
|
|
122
134
|
$el.getAttribute(k) !== value && $el.setAttribute(k, value === true ? "" : String(value));
|
|
123
135
|
isAttrTag && track(id, ck, () => $el.removeAttribute(k));
|
|
124
136
|
}
|
|
@@ -126,10 +138,11 @@ async function renderDOMHead(head, options = {}) {
|
|
|
126
138
|
}
|
|
127
139
|
const pending = [];
|
|
128
140
|
const frag = {
|
|
129
|
-
bodyClose:
|
|
130
|
-
bodyOpen:
|
|
131
|
-
head:
|
|
141
|
+
bodyClose: void 0,
|
|
142
|
+
bodyOpen: void 0,
|
|
143
|
+
head: void 0
|
|
132
144
|
};
|
|
145
|
+
const tags = await resolveTagPromise;
|
|
133
146
|
for (const ctx of tags) {
|
|
134
147
|
const { tag, shouldRender, id } = ctx;
|
|
135
148
|
if (!shouldRender)
|
|
@@ -138,7 +151,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
138
151
|
dom.title = tag.textContent;
|
|
139
152
|
continue;
|
|
140
153
|
}
|
|
141
|
-
ctx.$el = ctx.$el || state.elMap
|
|
154
|
+
ctx.$el = ctx.$el || state.elMap.get(id);
|
|
142
155
|
if (ctx.$el) {
|
|
143
156
|
trackCtx(ctx);
|
|
144
157
|
} else if (HasElementTags.has(tag.tag)) {
|
|
@@ -164,25 +177,29 @@ async function renderDOMHead(head, options = {}) {
|
|
|
164
177
|
await head.hooks.callHook("dom:rendered", { renders: tags });
|
|
165
178
|
resolve();
|
|
166
179
|
}).finally(() => {
|
|
167
|
-
head._domUpdatePromise =
|
|
180
|
+
head._domUpdatePromise = void 0;
|
|
168
181
|
head.dirty = false;
|
|
169
182
|
});
|
|
170
183
|
return head._domUpdatePromise;
|
|
171
184
|
}
|
|
172
185
|
|
|
173
186
|
function createHead(options = {}) {
|
|
174
|
-
|
|
175
|
-
document:
|
|
176
|
-
...options
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
187
|
+
const head = createUnhead({
|
|
188
|
+
document: typeof window !== "undefined" ? document : void 0,
|
|
189
|
+
...options
|
|
190
|
+
});
|
|
191
|
+
const initialPayload = head.resolvedOptions.document?.head.querySelector('script[id="unhead:payload"]')?.innerHTML || false;
|
|
192
|
+
if (initialPayload) {
|
|
193
|
+
head.push(JSON.parse(initialPayload));
|
|
194
|
+
}
|
|
195
|
+
const render = options.domOptions?.render || renderDOMHead;
|
|
196
|
+
head.use({
|
|
197
|
+
key: "client",
|
|
198
|
+
hooks: {
|
|
199
|
+
"entries:updated": render
|
|
200
|
+
}
|
|
185
201
|
});
|
|
202
|
+
return head;
|
|
186
203
|
}
|
|
187
204
|
|
|
188
205
|
function createDebouncedFn(callee, delayer) {
|
|
@@ -197,4 +214,4 @@ function createDebouncedFn(callee, delayer) {
|
|
|
197
214
|
};
|
|
198
215
|
}
|
|
199
216
|
|
|
200
|
-
export {
|
|
217
|
+
export { createDebouncedFn, createHead, renderDOMHead };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { H as HeadSafe } from './shared/unhead.DLPWlHGE.mjs';
|
|
2
|
+
import { U as Unhead, R as ResolvableHead, r as HeadEntryOptions, o as ActiveHeadEntry, a8 as UseSeoMetaInput, C as CreateHeadOptions } from './shared/unhead.DVcP39oW.mjs';
|
|
3
|
+
export { u as useScript } from './shared/unhead.UCwgwV97.mjs';
|
|
4
|
+
import 'hookable';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
|
|
6
|
+
declare function useHead<T extends Unhead<any>, I = ResolvableHead>(unhead: T, input?: ResolvableHead, options?: HeadEntryOptions): ActiveHeadEntry<I>;
|
|
7
|
+
declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
|
|
8
|
+
declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<UseSeoMetaInput>;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated use `useHead` instead. Advanced use cases should tree shake using import.meta.* if statements.
|
|
11
|
+
*/
|
|
12
|
+
declare function useServerHead<T extends Unhead<any>>(unhead: T, input?: Parameters<T['push']>[0], options?: Omit<HeadEntryOptions, 'mode'>): ReturnType<T['push']>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated use `useHeadSafe` instead. Advanced use cases should tree shake using import.meta.* if statements.
|
|
15
|
+
*/
|
|
16
|
+
declare function useServerHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: Omit<HeadEntryOptions, 'mode'>): ActiveHeadEntry<HeadSafe>;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated use `useSeoMeta` instead. Advanced use cases should tree shake using import.meta.* if statements.
|
|
19
|
+
*/
|
|
20
|
+
declare function useServerSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: Omit<HeadEntryOptions, 'mode'>): ActiveHeadEntry<UseSeoMetaInput>;
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use `createUnhead` instead
|
|
24
|
+
*/
|
|
25
|
+
declare function createHeadCore<T = ResolvableHead>(resolvedOptions?: CreateHeadOptions): Unhead<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a core instance of unhead. Does not provide a global ctx for composables to work
|
|
28
|
+
* and does not register DOM plugins.
|
|
29
|
+
*/
|
|
30
|
+
declare function createUnhead<T = ResolvableHead>(resolvedOptions?: CreateHeadOptions): Unhead<T>;
|
|
31
|
+
|
|
32
|
+
export { createHeadCore, createUnhead, useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { H as HeadSafe } from './shared/unhead.Bj0vvOrH.js';
|
|
2
|
+
import { U as Unhead, R as ResolvableHead, r as HeadEntryOptions, o as ActiveHeadEntry, a8 as UseSeoMetaInput, C as CreateHeadOptions } from './shared/unhead.DVcP39oW.js';
|
|
3
|
+
export { u as useScript } from './shared/unhead.Bc1vIJ23.js';
|
|
4
|
+
import 'hookable';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
|
|
6
|
+
declare function useHead<T extends Unhead<any>, I = ResolvableHead>(unhead: T, input?: ResolvableHead, options?: HeadEntryOptions): ActiveHeadEntry<I>;
|
|
7
|
+
declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
|
|
8
|
+
declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<UseSeoMetaInput>;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated use `useHead` instead. Advanced use cases should tree shake using import.meta.* if statements.
|
|
11
|
+
*/
|
|
12
|
+
declare function useServerHead<T extends Unhead<any>>(unhead: T, input?: Parameters<T['push']>[0], options?: Omit<HeadEntryOptions, 'mode'>): ReturnType<T['push']>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated use `useHeadSafe` instead. Advanced use cases should tree shake using import.meta.* if statements.
|
|
15
|
+
*/
|
|
16
|
+
declare function useServerHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: Omit<HeadEntryOptions, 'mode'>): ActiveHeadEntry<HeadSafe>;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated use `useSeoMeta` instead. Advanced use cases should tree shake using import.meta.* if statements.
|
|
19
|
+
*/
|
|
20
|
+
declare function useServerSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: Omit<HeadEntryOptions, 'mode'>): ActiveHeadEntry<UseSeoMetaInput>;
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use `createUnhead` instead
|
|
24
|
+
*/
|
|
25
|
+
declare function createHeadCore<T = ResolvableHead>(resolvedOptions?: CreateHeadOptions): Unhead<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a core instance of unhead. Does not provide a global ctx for composables to work
|
|
28
|
+
* and does not register DOM plugins.
|
|
29
|
+
*/
|
|
30
|
+
declare function createUnhead<T = ResolvableHead>(resolvedOptions?: CreateHeadOptions): Unhead<T>;
|
|
31
|
+
|
|
32
|
+
export { createHeadCore, createUnhead, useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };
|
package/dist/index.mjs
CHANGED
|
@@ -1,37 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export { c as createHeadCore } from './shared/unhead.
|
|
1
|
+
export { u as useHead, a as useHeadSafe, b as useSeoMeta, c as useServerHead, d as useServerHeadSafe, e as useServerSeoMeta } from './shared/unhead.BPM0-cfG.mjs';
|
|
2
|
+
export { c as createHeadCore, a as createUnhead } from './shared/unhead.CydFxwlU.mjs';
|
|
3
|
+
export { u as useScript } from './shared/unhead.BHfOzKG2.mjs';
|
|
4
|
+
import './shared/unhead.CApf5sj3.mjs';
|
|
5
|
+
import './shared/unhead.DQc16pHI.mjs';
|
|
6
|
+
import './shared/unhead.yem5I2v_.mjs';
|
|
3
7
|
import 'hookable';
|
|
4
|
-
import './shared/unhead.
|
|
5
|
-
|
|
6
|
-
function useHead(unhead, input, options = {}) {
|
|
7
|
-
return unhead.push(input, options);
|
|
8
|
-
}
|
|
9
|
-
function useHeadSafe(unhead, input, options) {
|
|
10
|
-
return useHead(unhead, input, {
|
|
11
|
-
...options,
|
|
12
|
-
// @ts-expect-error untyped
|
|
13
|
-
transform: whitelistSafeInput
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
function useSeoMeta(unhead, input, options) {
|
|
17
|
-
const { title, titleTemplate, ...meta } = input;
|
|
18
|
-
return useHead(unhead, {
|
|
19
|
-
title,
|
|
20
|
-
titleTemplate,
|
|
21
|
-
// we need to input the meta so the reactivity will be resolved
|
|
22
|
-
_flatMeta: meta
|
|
23
|
-
}, {
|
|
24
|
-
...options,
|
|
25
|
-
transform(t) {
|
|
26
|
-
const meta2 = unpackMeta({ ...t._flatMeta });
|
|
27
|
-
delete t._flatMeta;
|
|
28
|
-
return {
|
|
29
|
-
// @ts-expect-error runtime type
|
|
30
|
-
...t,
|
|
31
|
-
meta: meta2
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { useHead, useHeadSafe, useSeoMeta };
|
|
8
|
+
import './shared/unhead.xsi8MZXD.mjs';
|
|
9
|
+
import './shared/unhead.DZbvapt-.mjs';
|
package/dist/legacy.d.mts
CHANGED
|
@@ -1,115 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
type UseScriptResolvedInput = Omit<Script, 'src'> & {
|
|
9
|
-
src: string;
|
|
10
|
-
};
|
|
11
|
-
declare function resolveScriptKey(input: UseScriptResolvedInput): any;
|
|
12
|
-
type UseScriptStatus = 'awaitingLoad' | 'loading' | 'loaded' | 'error' | 'removed';
|
|
13
|
-
interface ScriptInstance<T extends BaseScriptApi> {
|
|
14
|
-
proxy: AsAsyncFunctionValues<T>;
|
|
15
|
-
instance?: T;
|
|
16
|
-
id: string;
|
|
17
|
-
status: UseScriptStatus;
|
|
18
|
-
entry?: ActiveHeadEntry<any>;
|
|
19
|
-
load: () => Promise<T>;
|
|
20
|
-
remove: () => boolean;
|
|
21
|
-
setupTriggerHandler: (trigger: UseScriptOptions['trigger']) => void;
|
|
22
|
-
onLoaded: (fn: (instance: T) => void | Promise<void>) => void;
|
|
23
|
-
onError: (fn: (err?: Error) => void | Promise<void>) => void;
|
|
24
|
-
/**
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
_triggerAbortController?: AbortController | null;
|
|
28
|
-
/**
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
_triggerAbortPromise?: Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
_triggerPromises?: Promise<void>[];
|
|
36
|
-
/**
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
_cbs: {
|
|
40
|
-
loaded: null | ((instance: T) => void | Promise<void>)[];
|
|
41
|
-
error: null | ((err?: Error) => void | Promise<void>)[];
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
interface UseScriptOptions<T extends BaseScriptApi = Record<string, any>> extends HeadEntryOptions {
|
|
45
|
-
/**
|
|
46
|
-
* Resolve the script instance from the window.
|
|
47
|
-
*/
|
|
48
|
-
use?: () => T | undefined | null;
|
|
49
|
-
/**
|
|
50
|
-
* Stub the script instance. Useful for SSR or testing.
|
|
51
|
-
*/
|
|
52
|
-
stub?: ((ctx: {
|
|
53
|
-
script: ScriptInstance<T>;
|
|
54
|
-
fn: string | symbol;
|
|
55
|
-
}) => any);
|
|
56
|
-
/**
|
|
57
|
-
* The trigger to load the script:
|
|
58
|
-
* - `undefined` | `client` - (Default) Load the script on the client when this js is loaded.
|
|
59
|
-
* - `manual` - Load the script manually by calling `$script.load()`, exists only on the client.
|
|
60
|
-
* - `Promise` - Load the script when the promise resolves, exists only on the client.
|
|
61
|
-
* - `Function` - Register a callback function to load the script, exists only on the client.
|
|
62
|
-
* - `server` - Have the script injected on the server.
|
|
63
|
-
*/
|
|
64
|
-
trigger?: 'client' | 'server' | 'manual' | Promise<boolean | void> | ((fn: any) => any) | null;
|
|
65
|
-
/**
|
|
66
|
-
* Context to run events with. This is useful in Vue to attach the current instance context before
|
|
67
|
-
* calling the event, allowing the event to be reactive.
|
|
68
|
-
*/
|
|
69
|
-
eventContext?: any;
|
|
70
|
-
/**
|
|
71
|
-
* Called before the script is initialized. Will not be triggered when the script is already loaded. This means
|
|
72
|
-
* this is guaranteed to be called only once, unless the script is removed and re-added.
|
|
73
|
-
*/
|
|
74
|
-
beforeInit?: () => void;
|
|
75
|
-
}
|
|
76
|
-
type BaseScriptApi = Record<symbol | string, any>;
|
|
77
|
-
type AsAsyncFunctionValues<T extends BaseScriptApi> = {
|
|
78
|
-
[key in keyof T]: T[key] extends any[] ? T[key] : T[key] extends (...args: infer A) => infer R ? (...args: A) => R extends Promise<any> ? R : Promise<R> : T[key] extends Record<any, any> ? AsAsyncFunctionValues<T[key]> : never;
|
|
79
|
-
};
|
|
80
|
-
type UseScriptContext<T extends Record<symbol | string, any>> = (Promise<T> & ScriptInstance<T>) & AsAsyncFunctionValues<T> & {
|
|
81
|
-
/**
|
|
82
|
-
* @deprecated Use top-level functions instead.
|
|
83
|
-
*/
|
|
84
|
-
$script: Promise<T> & ScriptInstance<T>;
|
|
85
|
-
};
|
|
86
|
-
type UseFunctionType<T, U> = T extends {
|
|
87
|
-
use: infer V;
|
|
88
|
-
} ? V extends (...args: any) => any ? ReturnType<V> : U : U;
|
|
89
|
-
/**
|
|
90
|
-
* Load third-party scripts with SSR support and a proxied API.
|
|
91
|
-
*
|
|
92
|
-
* @see https://unhead.unjs.io/usage/composables/use-script
|
|
93
|
-
*/
|
|
94
|
-
declare function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>>(_input: UseScriptInput, _options?: UseScriptOptions<T>): UseScriptContext<UseFunctionType<UseScriptOptions<T>, T>>;
|
|
1
|
+
import { createUnhead } from './index.mjs';
|
|
2
|
+
export { useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta } from './index.mjs';
|
|
3
|
+
import { U as Unhead, R as ResolvableHead, C as CreateHeadOptions } from './shared/unhead.DVcP39oW.mjs';
|
|
4
|
+
export { u as useScript } from './shared/unhead.UCwgwV97.mjs';
|
|
5
|
+
import './shared/unhead.DLPWlHGE.mjs';
|
|
6
|
+
import 'hookable';
|
|
95
7
|
|
|
96
8
|
declare const activeHead: {
|
|
97
9
|
value: Unhead<any> | null;
|
|
98
10
|
};
|
|
99
11
|
declare function getActiveHead(): Unhead<any> | null;
|
|
100
|
-
declare
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}[];
|
|
104
|
-
|
|
105
|
-
declare function createServerHead<T extends Record<string, any> = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
106
|
-
declare function createHead<T extends Record<string, any> = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
107
|
-
type UseHeadInput<T extends MergeHead> = Head<T>;
|
|
108
|
-
declare function useHead<T extends MergeHead>(input: UseHeadInput<T>, options?: HeadEntryOptions): ActiveHeadEntry<UseHeadInput<T>> | void;
|
|
109
|
-
declare function useHeadSafe(input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe> | void;
|
|
110
|
-
declare function useSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any> | void;
|
|
111
|
-
declare function useServerHead<T extends MergeHead>(input: UseHeadInput<T>, options?: HeadEntryOptions): ActiveHeadEntry<UseHeadInput<T>> | void;
|
|
112
|
-
declare function useServerHeadSafe<T extends HeadSafe>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
113
|
-
declare function useServerSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any> | void;
|
|
12
|
+
declare function createServerHead<T extends Record<string, any> = ResolvableHead>(options?: CreateHeadOptions): Unhead<T>;
|
|
13
|
+
declare function createHead<T extends Record<string, any> = ResolvableHead>(options?: CreateHeadOptions): Unhead<T>;
|
|
14
|
+
declare const createHeadCore: typeof createUnhead;
|
|
114
15
|
|
|
115
|
-
export {
|
|
16
|
+
export { activeHead, createHead, createHeadCore, createServerHead, createUnhead, getActiveHead };
|