unhead 1.5.5 → 1.6.1
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 +17 -43
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +18 -44
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -75,13 +75,13 @@ const PayloadPlugin = shared.defineHeadPlugin({
|
|
|
75
75
|
mode: "server",
|
|
76
76
|
hooks: {
|
|
77
77
|
"tags:resolve": function(ctx) {
|
|
78
|
-
const
|
|
78
|
+
const payload = {};
|
|
79
79
|
ctx.tags.filter((tag) => ["titleTemplate", "templateParams", "title"].includes(tag.tag) && tag._m === "server").forEach((tag) => {
|
|
80
|
-
|
|
80
|
+
payload[tag.tag] = tag.tag.startsWith("title") ? tag.textContent : tag.props;
|
|
81
81
|
});
|
|
82
|
-
Object.keys(
|
|
82
|
+
Object.keys(payload).length && ctx.tags.push({
|
|
83
83
|
tag: "script",
|
|
84
|
-
innerHTML: JSON.stringify(
|
|
84
|
+
innerHTML: JSON.stringify(payload),
|
|
85
85
|
props: { id: "unhead:payload", type: "application/json" }
|
|
86
86
|
});
|
|
87
87
|
}
|
|
@@ -267,10 +267,14 @@ function createHeadCore(options = {}) {
|
|
|
267
267
|
TitleTemplatePlugin,
|
|
268
268
|
...options?.plugins || []
|
|
269
269
|
];
|
|
270
|
-
const updated = () =>
|
|
270
|
+
const updated = () => {
|
|
271
|
+
head.dirty = true;
|
|
272
|
+
hooks.callHook("entries:updated", head);
|
|
273
|
+
};
|
|
271
274
|
let entryCount = 0;
|
|
272
275
|
let entries = [];
|
|
273
276
|
const head = {
|
|
277
|
+
dirty: false,
|
|
274
278
|
resolvedOptions: options,
|
|
275
279
|
hooks,
|
|
276
280
|
headEntries() {
|
|
@@ -336,37 +340,7 @@ function createHeadCore(options = {}) {
|
|
|
336
340
|
|
|
337
341
|
// @__NO_SIDE_EFFECTS__
|
|
338
342
|
function HashHydrationPlugin() {
|
|
339
|
-
|
|
340
|
-
let dirty = false;
|
|
341
|
-
let head;
|
|
342
|
-
return shared.defineHeadPlugin({
|
|
343
|
-
hooks: {
|
|
344
|
-
"init": function(_head) {
|
|
345
|
-
head = _head;
|
|
346
|
-
if (!head.ssr)
|
|
347
|
-
prevHash = head.resolvedOptions.document?.head.querySelector('meta[name="unhead:ssr"]')?.getAttribute("content") || false;
|
|
348
|
-
if (!prevHash)
|
|
349
|
-
dirty = true;
|
|
350
|
-
},
|
|
351
|
-
"tags:resolve": function({ tags }) {
|
|
352
|
-
const nonServerTags = tags.filter((tag) => tag._m !== "server");
|
|
353
|
-
const hash = !nonServerTags.length ? false : shared.hashCode(
|
|
354
|
-
nonServerTags.map((tag) => shared.hashTag(tag)).join("")
|
|
355
|
-
);
|
|
356
|
-
if (prevHash !== hash && prevHash !== false)
|
|
357
|
-
dirty = true;
|
|
358
|
-
else
|
|
359
|
-
prevHash = hash;
|
|
360
|
-
},
|
|
361
|
-
"dom:beforeRender": function(ctx) {
|
|
362
|
-
ctx.shouldRender = dirty;
|
|
363
|
-
dirty = false;
|
|
364
|
-
},
|
|
365
|
-
"ssr:render": function({ tags }) {
|
|
366
|
-
prevHash && tags.push({ tag: "meta", props: { name: "unhead:ssr", content: String(prevHash) } });
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
});
|
|
343
|
+
return shared.defineHeadPlugin({});
|
|
370
344
|
}
|
|
371
345
|
|
|
372
346
|
const importRe = /@import/;
|
|
@@ -382,19 +356,19 @@ function CapoPlugin(options) {
|
|
|
382
356
|
const isScript = tag.tag === "script";
|
|
383
357
|
const isLink = tag.tag === "link";
|
|
384
358
|
if (isScript && isTruthy(tag.props.async)) {
|
|
385
|
-
tag.tagPriority =
|
|
359
|
+
tag.tagPriority = 30;
|
|
386
360
|
} else if (tag.tag === "style" && tag.innerHTML && importRe.test(tag.innerHTML)) {
|
|
387
|
-
tag.tagPriority =
|
|
361
|
+
tag.tagPriority = 40;
|
|
388
362
|
} else if (isScript && tag.props.src && !isTruthy(tag.props.defer) && !isTruthy(tag.props.async) && tag.props.type !== "module" && !tag.props.type?.endsWith("json")) {
|
|
389
|
-
tag.tagPriority =
|
|
363
|
+
tag.tagPriority = 50;
|
|
390
364
|
} else if (isLink && tag.props.rel === "stylesheet" || tag.tag === "style") {
|
|
391
|
-
tag.tagPriority =
|
|
365
|
+
tag.tagPriority = 60;
|
|
392
366
|
} else if (isLink && ["preload", "modulepreload"].includes(tag.props.rel)) {
|
|
393
|
-
tag.tagPriority =
|
|
367
|
+
tag.tagPriority = 70;
|
|
394
368
|
} else if (isScript && isTruthy(tag.props.defer) && tag.props.src && !isTruthy(tag.props.async)) {
|
|
395
|
-
tag.tagPriority =
|
|
369
|
+
tag.tagPriority = 80;
|
|
396
370
|
} else if (isLink && ["prefetch", "dns-prefetch", "prerender"].includes(tag.props.rel)) {
|
|
397
|
-
tag.tagPriority =
|
|
371
|
+
tag.tagPriority = 90;
|
|
398
372
|
}
|
|
399
373
|
}
|
|
400
374
|
options?.track && tags.push({
|
package/dist/index.d.cts
CHANGED
|
@@ -12,6 +12,9 @@ declare function createServerHead<T extends {} = Head>(options?: CreateHeadOptio
|
|
|
12
12
|
*/
|
|
13
13
|
declare function createHeadCore<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Hash hydration is no longer supported. Please remove this plugin.
|
|
17
|
+
*/
|
|
15
18
|
declare function HashHydrationPlugin(): _unhead_schema.HeadPlugin;
|
|
16
19
|
|
|
17
20
|
declare function CapoPlugin(options: {
|
package/dist/index.d.mts
CHANGED
|
@@ -12,6 +12,9 @@ declare function createServerHead<T extends {} = Head>(options?: CreateHeadOptio
|
|
|
12
12
|
*/
|
|
13
13
|
declare function createHeadCore<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Hash hydration is no longer supported. Please remove this plugin.
|
|
17
|
+
*/
|
|
15
18
|
declare function HashHydrationPlugin(): _unhead_schema.HeadPlugin;
|
|
16
19
|
|
|
17
20
|
declare function CapoPlugin(options: {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,9 @@ declare function createServerHead<T extends {} = Head>(options?: CreateHeadOptio
|
|
|
12
12
|
*/
|
|
13
13
|
declare function createHeadCore<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Hash hydration is no longer supported. Please remove this plugin.
|
|
17
|
+
*/
|
|
15
18
|
declare function HashHydrationPlugin(): _unhead_schema.HeadPlugin;
|
|
16
19
|
|
|
17
20
|
declare function CapoPlugin(options: {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHooks } from 'hookable';
|
|
2
2
|
import { DomPlugin } from '@unhead/dom';
|
|
3
|
-
import { defineHeadPlugin, tagDedupeKey, tagWeight, HasElementTags, hashCode, SortModifiers, processTemplateParams, resolveTitleTemplate, IsBrowser, normaliseEntryTags,
|
|
3
|
+
import { defineHeadPlugin, tagDedupeKey, tagWeight, HasElementTags, hashCode, SortModifiers, processTemplateParams, resolveTitleTemplate, IsBrowser, normaliseEntryTags, composableNames, whitelistSafeInput, unpackMeta } from '@unhead/shared';
|
|
4
4
|
export { composableNames } from '@unhead/shared';
|
|
5
5
|
|
|
6
6
|
const UsesMergeStrategy = ["templateParams", "htmlAttrs", "bodyAttrs"];
|
|
@@ -74,13 +74,13 @@ const PayloadPlugin = defineHeadPlugin({
|
|
|
74
74
|
mode: "server",
|
|
75
75
|
hooks: {
|
|
76
76
|
"tags:resolve": function(ctx) {
|
|
77
|
-
const
|
|
77
|
+
const payload = {};
|
|
78
78
|
ctx.tags.filter((tag) => ["titleTemplate", "templateParams", "title"].includes(tag.tag) && tag._m === "server").forEach((tag) => {
|
|
79
|
-
|
|
79
|
+
payload[tag.tag] = tag.tag.startsWith("title") ? tag.textContent : tag.props;
|
|
80
80
|
});
|
|
81
|
-
Object.keys(
|
|
81
|
+
Object.keys(payload).length && ctx.tags.push({
|
|
82
82
|
tag: "script",
|
|
83
|
-
innerHTML: JSON.stringify(
|
|
83
|
+
innerHTML: JSON.stringify(payload),
|
|
84
84
|
props: { id: "unhead:payload", type: "application/json" }
|
|
85
85
|
});
|
|
86
86
|
}
|
|
@@ -266,10 +266,14 @@ function createHeadCore(options = {}) {
|
|
|
266
266
|
TitleTemplatePlugin,
|
|
267
267
|
...options?.plugins || []
|
|
268
268
|
];
|
|
269
|
-
const updated = () =>
|
|
269
|
+
const updated = () => {
|
|
270
|
+
head.dirty = true;
|
|
271
|
+
hooks.callHook("entries:updated", head);
|
|
272
|
+
};
|
|
270
273
|
let entryCount = 0;
|
|
271
274
|
let entries = [];
|
|
272
275
|
const head = {
|
|
276
|
+
dirty: false,
|
|
273
277
|
resolvedOptions: options,
|
|
274
278
|
hooks,
|
|
275
279
|
headEntries() {
|
|
@@ -335,37 +339,7 @@ function createHeadCore(options = {}) {
|
|
|
335
339
|
|
|
336
340
|
// @__NO_SIDE_EFFECTS__
|
|
337
341
|
function HashHydrationPlugin() {
|
|
338
|
-
|
|
339
|
-
let dirty = false;
|
|
340
|
-
let head;
|
|
341
|
-
return defineHeadPlugin({
|
|
342
|
-
hooks: {
|
|
343
|
-
"init": function(_head) {
|
|
344
|
-
head = _head;
|
|
345
|
-
if (!head.ssr)
|
|
346
|
-
prevHash = head.resolvedOptions.document?.head.querySelector('meta[name="unhead:ssr"]')?.getAttribute("content") || false;
|
|
347
|
-
if (!prevHash)
|
|
348
|
-
dirty = true;
|
|
349
|
-
},
|
|
350
|
-
"tags:resolve": function({ tags }) {
|
|
351
|
-
const nonServerTags = tags.filter((tag) => tag._m !== "server");
|
|
352
|
-
const hash = !nonServerTags.length ? false : hashCode(
|
|
353
|
-
nonServerTags.map((tag) => hashTag(tag)).join("")
|
|
354
|
-
);
|
|
355
|
-
if (prevHash !== hash && prevHash !== false)
|
|
356
|
-
dirty = true;
|
|
357
|
-
else
|
|
358
|
-
prevHash = hash;
|
|
359
|
-
},
|
|
360
|
-
"dom:beforeRender": function(ctx) {
|
|
361
|
-
ctx.shouldRender = dirty;
|
|
362
|
-
dirty = false;
|
|
363
|
-
},
|
|
364
|
-
"ssr:render": function({ tags }) {
|
|
365
|
-
prevHash && tags.push({ tag: "meta", props: { name: "unhead:ssr", content: String(prevHash) } });
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
});
|
|
342
|
+
return defineHeadPlugin({});
|
|
369
343
|
}
|
|
370
344
|
|
|
371
345
|
const importRe = /@import/;
|
|
@@ -381,19 +355,19 @@ function CapoPlugin(options) {
|
|
|
381
355
|
const isScript = tag.tag === "script";
|
|
382
356
|
const isLink = tag.tag === "link";
|
|
383
357
|
if (isScript && isTruthy(tag.props.async)) {
|
|
384
|
-
tag.tagPriority =
|
|
358
|
+
tag.tagPriority = 30;
|
|
385
359
|
} else if (tag.tag === "style" && tag.innerHTML && importRe.test(tag.innerHTML)) {
|
|
386
|
-
tag.tagPriority =
|
|
360
|
+
tag.tagPriority = 40;
|
|
387
361
|
} else if (isScript && tag.props.src && !isTruthy(tag.props.defer) && !isTruthy(tag.props.async) && tag.props.type !== "module" && !tag.props.type?.endsWith("json")) {
|
|
388
|
-
tag.tagPriority =
|
|
362
|
+
tag.tagPriority = 50;
|
|
389
363
|
} else if (isLink && tag.props.rel === "stylesheet" || tag.tag === "style") {
|
|
390
|
-
tag.tagPriority =
|
|
364
|
+
tag.tagPriority = 60;
|
|
391
365
|
} else if (isLink && ["preload", "modulepreload"].includes(tag.props.rel)) {
|
|
392
|
-
tag.tagPriority =
|
|
366
|
+
tag.tagPriority = 70;
|
|
393
367
|
} else if (isScript && isTruthy(tag.props.defer) && tag.props.src && !isTruthy(tag.props.async)) {
|
|
394
|
-
tag.tagPriority =
|
|
368
|
+
tag.tagPriority = 80;
|
|
395
369
|
} else if (isLink && ["prefetch", "dns-prefetch", "prerender"].includes(tag.props.rel)) {
|
|
396
|
-
tag.tagPriority =
|
|
370
|
+
tag.tagPriority = 90;
|
|
397
371
|
}
|
|
398
372
|
}
|
|
399
373
|
options?.track && tags.push({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unhead",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.6.1",
|
|
5
5
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"hookable": "^5.5.3",
|
|
33
|
-
"@unhead/
|
|
34
|
-
"@unhead/
|
|
35
|
-
"@unhead/
|
|
33
|
+
"@unhead/schema": "1.6.1",
|
|
34
|
+
"@unhead/dom": "1.6.1",
|
|
35
|
+
"@unhead/shared": "1.6.1"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "unbuild .",
|