@unhead/vue 0.6.3 → 0.6.5
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/chunks/index.cjs +164 -0
- package/dist/chunks/index.mjs +161 -0
- package/dist/index.cjs +530 -16
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +526 -9
- package/package.json +4 -5
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,522 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { HasElementTags, getActiveHead, createHead as createHead$1, defineHeadPlugin, composableNames } from 'unhead';
|
|
4
|
-
export * from '@unhead/dom';
|
|
1
|
+
import { unref, isRef, version, getCurrentInstance, inject, nextTick, ref, watchEffect, watch, onBeforeUnmount } from 'vue';
|
|
2
|
+
import { createHooks } from 'hookable';
|
|
5
3
|
|
|
4
|
+
const ValidHeadTags = [
|
|
5
|
+
"title",
|
|
6
|
+
"titleTemplate",
|
|
7
|
+
"base",
|
|
8
|
+
"htmlAttrs",
|
|
9
|
+
"bodyAttrs",
|
|
10
|
+
"meta",
|
|
11
|
+
"link",
|
|
12
|
+
"style",
|
|
13
|
+
"script",
|
|
14
|
+
"noscript"
|
|
15
|
+
];
|
|
16
|
+
const TagConfigKeys = ["tagPosition", "tagPriority", "tagDuplicateStrategy"];
|
|
17
|
+
|
|
18
|
+
function normaliseTag(tagName, input) {
|
|
19
|
+
const tag = { tag: tagName, props: {} };
|
|
20
|
+
if (tagName === "title" || tagName === "titleTemplate") {
|
|
21
|
+
tag.children = input;
|
|
22
|
+
return tag;
|
|
23
|
+
}
|
|
24
|
+
tag.props = normaliseProps({ ...input });
|
|
25
|
+
["children", "innerHtml", "innerHTML"].forEach((key) => {
|
|
26
|
+
if (typeof tag.props[key] !== "undefined") {
|
|
27
|
+
tag.children = tag.props[key];
|
|
28
|
+
delete tag.props[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.keys(tag.props).filter((k) => TagConfigKeys.includes(k)).forEach((k) => {
|
|
32
|
+
tag[k] = tag.props[k];
|
|
33
|
+
delete tag.props[k];
|
|
34
|
+
});
|
|
35
|
+
if (typeof tag.props.class === "object" && !Array.isArray(tag.props.class)) {
|
|
36
|
+
tag.props.class = Object.keys(tag.props.class).filter((k) => tag.props.class[k]);
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(tag.props.class))
|
|
39
|
+
tag.props.class = tag.props.class.join(" ");
|
|
40
|
+
if (tag.props.content && Array.isArray(tag.props.content)) {
|
|
41
|
+
return tag.props.content.map((v, i) => {
|
|
42
|
+
const newTag = { ...tag, props: { ...tag.props } };
|
|
43
|
+
newTag.props.content = v;
|
|
44
|
+
newTag.key = `${tag.props.name || tag.props.property}:${i}`;
|
|
45
|
+
return newTag;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return tag;
|
|
49
|
+
}
|
|
50
|
+
function normaliseProps(props) {
|
|
51
|
+
for (const k in props) {
|
|
52
|
+
if (String(props[k]) === "true") {
|
|
53
|
+
props[k] = "";
|
|
54
|
+
} else if (String(props[k]) === "false") {
|
|
55
|
+
delete props[k];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return props;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const tagWeight = (tag) => {
|
|
62
|
+
if (typeof tag.tagPriority === "number")
|
|
63
|
+
return tag.tagPriority;
|
|
64
|
+
switch (tag.tag) {
|
|
65
|
+
case "base":
|
|
66
|
+
return -1;
|
|
67
|
+
case "title":
|
|
68
|
+
return 1;
|
|
69
|
+
case "meta":
|
|
70
|
+
if (tag.props.charset)
|
|
71
|
+
return -2;
|
|
72
|
+
if (tag.props["http-equiv"] === "content-security-policy")
|
|
73
|
+
return 0;
|
|
74
|
+
return 10;
|
|
75
|
+
default:
|
|
76
|
+
return 10;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const sortTags = (aTag, bTag) => {
|
|
80
|
+
return tagWeight(aTag) - tagWeight(bTag);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const UniqueTags = ["base", "title", "titleTemplate", "bodyAttrs", "htmlAttrs"];
|
|
84
|
+
const ArrayMetaProperties = [
|
|
85
|
+
"og:image",
|
|
86
|
+
"og:video",
|
|
87
|
+
"og:audio",
|
|
88
|
+
"og:locale:alternate",
|
|
89
|
+
"video:actor",
|
|
90
|
+
"video:director",
|
|
91
|
+
"video:writer",
|
|
92
|
+
"video:tag",
|
|
93
|
+
"article:author",
|
|
94
|
+
"article:tag",
|
|
95
|
+
"book:tag",
|
|
96
|
+
"book:author",
|
|
97
|
+
"music:album",
|
|
98
|
+
"music:musician"
|
|
99
|
+
];
|
|
100
|
+
function tagDedupeKey(tag) {
|
|
101
|
+
const { props, tag: tagName } = tag;
|
|
102
|
+
if (UniqueTags.includes(tagName))
|
|
103
|
+
return tagName;
|
|
104
|
+
if (tagName === "link" && props.rel === "canonical")
|
|
105
|
+
return "canonical";
|
|
106
|
+
if (props.charset)
|
|
107
|
+
return "charset";
|
|
108
|
+
const name = ["id"];
|
|
109
|
+
if (tagName === "meta")
|
|
110
|
+
name.push(...["name", "property", "http-equiv"]);
|
|
111
|
+
for (const n of name) {
|
|
112
|
+
if (typeof props[n] !== "undefined") {
|
|
113
|
+
const val = String(props[n]);
|
|
114
|
+
if (ArrayMetaProperties.findIndex((p) => val.startsWith(p)) !== -1)
|
|
115
|
+
return false;
|
|
116
|
+
return `${tagName}:${n}:${val}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const renderTitleTemplate = (template, title) => {
|
|
123
|
+
if (template == null)
|
|
124
|
+
return title || null;
|
|
125
|
+
if (typeof template === "function")
|
|
126
|
+
return template(title);
|
|
127
|
+
return template.replace("%s", title ?? "");
|
|
128
|
+
};
|
|
129
|
+
function resolveTitleTemplateFromTags(tags) {
|
|
130
|
+
const titleTemplateIdx = tags.findIndex((i) => i.tag === "titleTemplate");
|
|
131
|
+
const titleIdx = tags.findIndex((i) => i.tag === "title");
|
|
132
|
+
if (titleIdx !== -1 && titleTemplateIdx !== -1) {
|
|
133
|
+
const newTitle = renderTitleTemplate(
|
|
134
|
+
tags[titleTemplateIdx].children,
|
|
135
|
+
tags[titleIdx].children
|
|
136
|
+
);
|
|
137
|
+
if (newTitle !== null) {
|
|
138
|
+
tags[titleIdx].children = newTitle || tags[titleIdx].children;
|
|
139
|
+
} else {
|
|
140
|
+
delete tags[titleIdx];
|
|
141
|
+
}
|
|
142
|
+
} else if (titleTemplateIdx !== -1) {
|
|
143
|
+
const newTitle = renderTitleTemplate(
|
|
144
|
+
tags[titleTemplateIdx].children
|
|
145
|
+
);
|
|
146
|
+
if (newTitle !== null) {
|
|
147
|
+
tags[titleTemplateIdx].children = newTitle;
|
|
148
|
+
tags[titleTemplateIdx].tag = "title";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (titleTemplateIdx !== -1) {
|
|
152
|
+
delete tags[titleTemplateIdx];
|
|
153
|
+
}
|
|
154
|
+
return tags.filter(Boolean);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const DedupesTagsPlugin = (options) => {
|
|
158
|
+
options = options || {};
|
|
159
|
+
const dedupeKeys = options.dedupeKeys || ["hid", "vmid", "key"];
|
|
160
|
+
return defineHeadPlugin({
|
|
161
|
+
hooks: {
|
|
162
|
+
"tag:normalise": function({ tag }) {
|
|
163
|
+
dedupeKeys.forEach((key) => {
|
|
164
|
+
if (tag.props[key]) {
|
|
165
|
+
tag.key = tag.props[key];
|
|
166
|
+
delete tag.props[key];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
const dedupe = tag.key ? `${tag.tag}:${tag.key}` : tagDedupeKey(tag);
|
|
170
|
+
if (dedupe)
|
|
171
|
+
tag._d = dedupe;
|
|
172
|
+
},
|
|
173
|
+
"tags:resolve": function(ctx) {
|
|
174
|
+
const deduping = {};
|
|
175
|
+
ctx.tags.forEach((tag) => {
|
|
176
|
+
let dedupeKey = tag._d || tag._p;
|
|
177
|
+
const dupedTag = deduping[dedupeKey];
|
|
178
|
+
if (dupedTag) {
|
|
179
|
+
let strategy = tag?.tagDuplicateStrategy;
|
|
180
|
+
if (!strategy && (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs"))
|
|
181
|
+
strategy = "merge";
|
|
182
|
+
if (strategy === "merge") {
|
|
183
|
+
const oldProps = dupedTag.props;
|
|
184
|
+
["class", "style"].forEach((key) => {
|
|
185
|
+
if (tag.props[key] && oldProps[key]) {
|
|
186
|
+
if (key === "style" && !oldProps[key].endsWith(";"))
|
|
187
|
+
oldProps[key] += ";";
|
|
188
|
+
tag.props[key] = `${oldProps[key]} ${tag.props[key]}`;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
deduping[dedupeKey].props = {
|
|
192
|
+
...oldProps,
|
|
193
|
+
...tag.props
|
|
194
|
+
};
|
|
195
|
+
return;
|
|
196
|
+
} else if (tag._e === dupedTag._e) {
|
|
197
|
+
dedupeKey = tag._d = `${dedupeKey}:${tag._p}`;
|
|
198
|
+
}
|
|
199
|
+
const propCount = Object.keys(tag.props).length;
|
|
200
|
+
if ((propCount === 0 || propCount === 1 && typeof tag.props["data-h-key"] !== "undefined") && !tag.children) {
|
|
201
|
+
delete deduping[dedupeKey];
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
deduping[dedupeKey] = tag;
|
|
206
|
+
});
|
|
207
|
+
ctx.tags = Object.values(deduping);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const SortTagsPlugin = () => {
|
|
214
|
+
return defineHeadPlugin({
|
|
215
|
+
hooks: {
|
|
216
|
+
"tags:resolve": (ctx) => {
|
|
217
|
+
const tagIndexForKey = (key) => ctx.tags.find((tag) => tag._d === key)?._p;
|
|
218
|
+
for (const tag of ctx.tags) {
|
|
219
|
+
if (!tag.tagPriority || typeof tag.tagPriority === "number")
|
|
220
|
+
continue;
|
|
221
|
+
const modifiers = [{ prefix: "before:", offset: -1 }, { prefix: "after:", offset: 1 }];
|
|
222
|
+
for (const { prefix, offset } of modifiers) {
|
|
223
|
+
if (tag.tagPriority.startsWith(prefix)) {
|
|
224
|
+
const key = tag.tagPriority.replace(prefix, "");
|
|
225
|
+
const index = tagIndexForKey(key);
|
|
226
|
+
if (typeof index !== "undefined")
|
|
227
|
+
tag._p = index + offset;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
ctx.tags.sort((a, b) => a._p - b._p).sort(sortTags);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const TitleTemplatePlugin = () => {
|
|
238
|
+
return defineHeadPlugin({
|
|
239
|
+
hooks: {
|
|
240
|
+
"tags:resolve": (ctx) => {
|
|
241
|
+
ctx.tags = resolveTitleTemplateFromTags(ctx.tags);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const DeprecatedTagAttrPlugin = () => {
|
|
248
|
+
return defineHeadPlugin({
|
|
249
|
+
hooks: {
|
|
250
|
+
"tag:normalise": function({ tag }) {
|
|
251
|
+
if (typeof tag.props.body !== "undefined") {
|
|
252
|
+
tag.tagPosition = "bodyClose";
|
|
253
|
+
delete tag.props.body;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const IsBrowser$1 = typeof window !== "undefined";
|
|
261
|
+
|
|
262
|
+
const ProvideTagHashPlugin = () => {
|
|
263
|
+
return defineHeadPlugin({
|
|
264
|
+
hooks: {
|
|
265
|
+
"tag:normalise": (ctx) => {
|
|
266
|
+
const { tag, entry } = ctx;
|
|
267
|
+
const isDynamic = typeof tag.props._dynamic !== "undefined";
|
|
268
|
+
if (!HasElementTags.includes(tag.tag) || !tag.key)
|
|
269
|
+
return;
|
|
270
|
+
tag._hash = hashCode(JSON.stringify({ tag: tag.tag, key: tag.key }));
|
|
271
|
+
if (IsBrowser$1 || getActiveHead()?.resolvedOptions?.document)
|
|
272
|
+
return;
|
|
273
|
+
if (entry._m === "server" || isDynamic) {
|
|
274
|
+
tag.props[`data-h-${tag._hash}`] = "";
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
"tags:resolve": (ctx) => {
|
|
278
|
+
ctx.tags = ctx.tags.map((t) => {
|
|
279
|
+
delete t.props._dynamic;
|
|
280
|
+
return t;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const PatchDomOnEntryUpdatesPlugin = (options) => {
|
|
288
|
+
return defineHeadPlugin({
|
|
289
|
+
hooks: {
|
|
290
|
+
"entries:updated": function(head) {
|
|
291
|
+
if (typeof options?.document === "undefined" && typeof window === "undefined")
|
|
292
|
+
return;
|
|
293
|
+
let delayFn = options?.delayFn;
|
|
294
|
+
if (!delayFn && typeof requestAnimationFrame !== "undefined")
|
|
295
|
+
delayFn = requestAnimationFrame;
|
|
296
|
+
import('./chunks/index.mjs').then(({ debouncedRenderDOMHead }) => {
|
|
297
|
+
debouncedRenderDOMHead(head, { document: options?.document || window.document, delayFn });
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const EventHandlersPlugin = () => {
|
|
305
|
+
const stripEventHandlers = (mode, tag) => {
|
|
306
|
+
const props = {};
|
|
307
|
+
const eventHandlers = {};
|
|
308
|
+
Object.entries(tag.props).forEach(([key, value]) => {
|
|
309
|
+
if (key.startsWith("on") && typeof value === "function")
|
|
310
|
+
eventHandlers[key] = value;
|
|
311
|
+
else
|
|
312
|
+
props[key] = value;
|
|
313
|
+
});
|
|
314
|
+
let delayedSrc;
|
|
315
|
+
if (mode === "dom" && tag.tag === "script" && typeof props.src === "string" && typeof eventHandlers.onload !== "undefined") {
|
|
316
|
+
delayedSrc = props.src;
|
|
317
|
+
delete props.src;
|
|
318
|
+
}
|
|
319
|
+
return { props, eventHandlers, delayedSrc };
|
|
320
|
+
};
|
|
321
|
+
return defineHeadPlugin({
|
|
322
|
+
hooks: {
|
|
323
|
+
"ssr:render": function(ctx) {
|
|
324
|
+
ctx.tags = ctx.tags.map((tag) => {
|
|
325
|
+
tag.props = stripEventHandlers("ssr", tag).props;
|
|
326
|
+
return tag;
|
|
327
|
+
});
|
|
328
|
+
},
|
|
329
|
+
"dom:beforeRenderTag": function(ctx) {
|
|
330
|
+
const { props, eventHandlers, delayedSrc } = stripEventHandlers("dom", ctx.tag);
|
|
331
|
+
if (!Object.keys(eventHandlers).length)
|
|
332
|
+
return;
|
|
333
|
+
ctx.tag.props = props;
|
|
334
|
+
ctx.tag._eventHandlers = eventHandlers;
|
|
335
|
+
ctx.tag._delayedSrc = delayedSrc;
|
|
336
|
+
},
|
|
337
|
+
"dom:renderTag": function(ctx) {
|
|
338
|
+
const $el = ctx.$el;
|
|
339
|
+
if (!ctx.tag._eventHandlers || !$el)
|
|
340
|
+
return;
|
|
341
|
+
const $eventListenerTarget = ctx.tag.tag === "bodyAttrs" && typeof window !== "undefined" ? window : $el;
|
|
342
|
+
Object.entries(ctx.tag._eventHandlers).forEach(([k, value]) => {
|
|
343
|
+
const sdeKey = `${ctx.tag._d || ctx.tag._p}:${k}`;
|
|
344
|
+
const eventName = k.slice(2).toLowerCase();
|
|
345
|
+
const eventDedupeKey = `data-h-${eventName}`;
|
|
346
|
+
delete ctx.queuedSideEffects[sdeKey];
|
|
347
|
+
if ($el.hasAttribute(eventDedupeKey))
|
|
348
|
+
return;
|
|
349
|
+
const handler = value;
|
|
350
|
+
$el.setAttribute(eventDedupeKey, "");
|
|
351
|
+
$eventListenerTarget.addEventListener(eventName, handler);
|
|
352
|
+
ctx.entry._sde[sdeKey] = () => {
|
|
353
|
+
$eventListenerTarget.removeEventListener(eventName, handler);
|
|
354
|
+
$el.removeAttribute(eventDedupeKey);
|
|
355
|
+
};
|
|
356
|
+
});
|
|
357
|
+
if (ctx.tag._delayedSrc) {
|
|
358
|
+
$el.setAttribute("src", ctx.tag._delayedSrc);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
function asArray$1(value) {
|
|
366
|
+
return Array.isArray(value) ? value : [value];
|
|
367
|
+
}
|
|
368
|
+
function hashCode(s) {
|
|
369
|
+
let h = 9;
|
|
370
|
+
for (let i = 0; i < s.length; )
|
|
371
|
+
h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
|
|
372
|
+
return ((h ^ h >>> 9) + 65536).toString(16).substring(1, 8).toLowerCase();
|
|
373
|
+
}
|
|
374
|
+
const HasElementTags = [
|
|
375
|
+
"base",
|
|
376
|
+
"meta",
|
|
377
|
+
"link",
|
|
378
|
+
"style",
|
|
379
|
+
"script",
|
|
380
|
+
"noscript"
|
|
381
|
+
];
|
|
382
|
+
|
|
383
|
+
let activeHead;
|
|
384
|
+
const setActiveHead = (head) => activeHead = head;
|
|
385
|
+
const getActiveHead = () => activeHead;
|
|
386
|
+
|
|
387
|
+
const TagEntityBits = 10;
|
|
388
|
+
|
|
389
|
+
function normaliseEntryTags(e) {
|
|
390
|
+
return Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).map(
|
|
391
|
+
([k, value]) => asArray$1(value).map((props) => asArray$1(normaliseTag(k, props)))
|
|
392
|
+
).flat(3).map((t, i) => {
|
|
393
|
+
t._e = e._i;
|
|
394
|
+
t._p = (e._i << TagEntityBits) + i;
|
|
395
|
+
return t;
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function createHead$1(options = {}) {
|
|
400
|
+
let entries = [];
|
|
401
|
+
let _sde = {};
|
|
402
|
+
let _eid = 0;
|
|
403
|
+
const hooks = createHooks();
|
|
404
|
+
if (options?.hooks)
|
|
405
|
+
hooks.addHooks(options.hooks);
|
|
406
|
+
options.plugins = [
|
|
407
|
+
DeprecatedTagAttrPlugin(),
|
|
408
|
+
DedupesTagsPlugin(),
|
|
409
|
+
SortTagsPlugin(),
|
|
410
|
+
TitleTemplatePlugin(),
|
|
411
|
+
EventHandlersPlugin(),
|
|
412
|
+
ProvideTagHashPlugin(),
|
|
413
|
+
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn }),
|
|
414
|
+
...options?.plugins || []
|
|
415
|
+
];
|
|
416
|
+
options.plugins.forEach((p) => p.hooks && hooks.addHooks(p.hooks));
|
|
417
|
+
const triggerUpdateHook = () => hooks.callHook("entries:updated", head);
|
|
418
|
+
const head = {
|
|
419
|
+
resolvedOptions: options,
|
|
420
|
+
headEntries() {
|
|
421
|
+
return entries;
|
|
422
|
+
},
|
|
423
|
+
get hooks() {
|
|
424
|
+
return hooks;
|
|
425
|
+
},
|
|
426
|
+
push(input, options2) {
|
|
427
|
+
const activeEntry = {
|
|
428
|
+
_i: _eid++,
|
|
429
|
+
input,
|
|
430
|
+
_sde: {}
|
|
431
|
+
};
|
|
432
|
+
if (options2?.mode)
|
|
433
|
+
activeEntry._m = options2?.mode;
|
|
434
|
+
entries.push(activeEntry);
|
|
435
|
+
triggerUpdateHook();
|
|
436
|
+
const queueSideEffects = (e) => {
|
|
437
|
+
_sde = { ..._sde, ...e._sde || {} };
|
|
438
|
+
e._sde = {};
|
|
439
|
+
triggerUpdateHook();
|
|
440
|
+
};
|
|
441
|
+
return {
|
|
442
|
+
dispose() {
|
|
443
|
+
entries = entries.filter((e) => {
|
|
444
|
+
if (e._i !== activeEntry._i)
|
|
445
|
+
return true;
|
|
446
|
+
queueSideEffects(e);
|
|
447
|
+
return false;
|
|
448
|
+
});
|
|
449
|
+
},
|
|
450
|
+
patch(input2) {
|
|
451
|
+
entries = entries.map((e) => {
|
|
452
|
+
if (e._i === activeEntry._i) {
|
|
453
|
+
queueSideEffects(e);
|
|
454
|
+
activeEntry.input = e.input = input2;
|
|
455
|
+
activeEntry._i = e._i = _eid++;
|
|
456
|
+
}
|
|
457
|
+
return e;
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
},
|
|
462
|
+
async resolveTags() {
|
|
463
|
+
const resolveCtx = { tags: [], entries: [...entries] };
|
|
464
|
+
await hooks.callHook("entries:resolve", resolveCtx);
|
|
465
|
+
for (const entry of resolveCtx.entries) {
|
|
466
|
+
for (const tag of normaliseEntryTags(entry)) {
|
|
467
|
+
const tagCtx = { tag, entry };
|
|
468
|
+
await hooks.callHook("tag:normalise", tagCtx);
|
|
469
|
+
resolveCtx.tags.push(tagCtx.tag);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
await hooks.callHook("tags:resolve", resolveCtx);
|
|
473
|
+
return resolveCtx.tags;
|
|
474
|
+
},
|
|
475
|
+
_elMap: {},
|
|
476
|
+
_popSideEffectQueue() {
|
|
477
|
+
const sde = { ..._sde };
|
|
478
|
+
_sde = {};
|
|
479
|
+
return sde;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
head.hooks.callHook("init", head);
|
|
483
|
+
setActiveHead(head);
|
|
484
|
+
return head;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function defineHeadPlugin(plugin) {
|
|
488
|
+
return plugin;
|
|
489
|
+
}
|
|
490
|
+
const composableNames = [
|
|
491
|
+
"useHead",
|
|
492
|
+
"useTagTitle",
|
|
493
|
+
"useTagBase",
|
|
494
|
+
"useTagMeta",
|
|
495
|
+
"useTagMetaFlat",
|
|
496
|
+
"useTagLink",
|
|
497
|
+
"useTagScript",
|
|
498
|
+
"useTagStyle",
|
|
499
|
+
"useTagNoscript",
|
|
500
|
+
"useHtmlAttrs",
|
|
501
|
+
"useBodyAttrs",
|
|
502
|
+
"useTitleTemplate",
|
|
503
|
+
"useServerHead",
|
|
504
|
+
"useServerTagTitle",
|
|
505
|
+
"useServerTagBase",
|
|
506
|
+
"useServerTagMeta",
|
|
507
|
+
"useServerTagMetaFlat",
|
|
508
|
+
"useServerTagLink",
|
|
509
|
+
"useServerTagScript",
|
|
510
|
+
"useServerTagStyle",
|
|
511
|
+
"useServerTagNoscript",
|
|
512
|
+
"useServerHtmlAttrs",
|
|
513
|
+
"useServerBodyAttrs",
|
|
514
|
+
"useServerTitleTemplate"
|
|
515
|
+
];
|
|
516
|
+
|
|
517
|
+
function resolveUnref(r) {
|
|
518
|
+
return typeof r === "function" ? r() : unref(r);
|
|
519
|
+
}
|
|
6
520
|
function resolveUnrefHeadInput(ref, lastKey = "") {
|
|
7
521
|
const root = resolveUnref(ref);
|
|
8
522
|
if (!ref || !root)
|
|
@@ -10,14 +524,17 @@ function resolveUnrefHeadInput(ref, lastKey = "") {
|
|
|
10
524
|
if (Array.isArray(root))
|
|
11
525
|
return root.map((r) => resolveUnrefHeadInput(r, lastKey));
|
|
12
526
|
if (typeof root === "object") {
|
|
527
|
+
let dynamic = false;
|
|
13
528
|
const unrefdObj = Object.fromEntries(
|
|
14
|
-
Object.entries(root).map(([
|
|
15
|
-
if (
|
|
16
|
-
return [
|
|
17
|
-
|
|
529
|
+
Object.entries(root).map(([k, v]) => {
|
|
530
|
+
if (k === "titleTemplate" || k.startsWith("on"))
|
|
531
|
+
return [k, unref(v)];
|
|
532
|
+
if (typeof v === "function" || isRef(v))
|
|
533
|
+
dynamic = true;
|
|
534
|
+
return [k, resolveUnrefHeadInput(v, k)];
|
|
18
535
|
})
|
|
19
536
|
);
|
|
20
|
-
if (HasElementTags.includes(String(lastKey))
|
|
537
|
+
if (dynamic && HasElementTags.includes(String(lastKey)))
|
|
21
538
|
unrefdObj._dynamic = true;
|
|
22
539
|
return unrefdObj;
|
|
23
540
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.5",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,12 +33,11 @@
|
|
|
33
33
|
"vue": ">=2.7 || >=3"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unhead/
|
|
37
|
-
"
|
|
38
|
-
"@vueuse/shared": "latest",
|
|
39
|
-
"unhead": "0.6.3"
|
|
36
|
+
"@unhead/schema": "0.6.5",
|
|
37
|
+
"hookable": "^5.4.1"
|
|
40
38
|
},
|
|
41
39
|
"devDependencies": {
|
|
40
|
+
"unhead": "0.6.5",
|
|
42
41
|
"vue": "^3.2.45"
|
|
43
42
|
},
|
|
44
43
|
"scripts": {
|