unhead 1.5.4 → 1.6.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 +12 -42
- 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 +13 -43
- 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
|
}
|
|
@@ -336,37 +336,7 @@ function createHeadCore(options = {}) {
|
|
|
336
336
|
|
|
337
337
|
// @__NO_SIDE_EFFECTS__
|
|
338
338
|
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
|
-
});
|
|
339
|
+
return shared.defineHeadPlugin({});
|
|
370
340
|
}
|
|
371
341
|
|
|
372
342
|
const importRe = /@import/;
|
|
@@ -382,19 +352,19 @@ function CapoPlugin(options) {
|
|
|
382
352
|
const isScript = tag.tag === "script";
|
|
383
353
|
const isLink = tag.tag === "link";
|
|
384
354
|
if (isScript && isTruthy(tag.props.async)) {
|
|
385
|
-
tag.tagPriority =
|
|
355
|
+
tag.tagPriority = 30;
|
|
386
356
|
} else if (tag.tag === "style" && tag.innerHTML && importRe.test(tag.innerHTML)) {
|
|
387
|
-
tag.tagPriority =
|
|
357
|
+
tag.tagPriority = 40;
|
|
388
358
|
} 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 =
|
|
359
|
+
tag.tagPriority = 50;
|
|
390
360
|
} else if (isLink && tag.props.rel === "stylesheet" || tag.tag === "style") {
|
|
391
|
-
tag.tagPriority =
|
|
361
|
+
tag.tagPriority = 60;
|
|
392
362
|
} else if (isLink && ["preload", "modulepreload"].includes(tag.props.rel)) {
|
|
393
|
-
tag.tagPriority =
|
|
363
|
+
tag.tagPriority = 70;
|
|
394
364
|
} else if (isScript && isTruthy(tag.props.defer) && tag.props.src && !isTruthy(tag.props.async)) {
|
|
395
|
-
tag.tagPriority =
|
|
365
|
+
tag.tagPriority = 80;
|
|
396
366
|
} else if (isLink && ["prefetch", "dns-prefetch", "prerender"].includes(tag.props.rel)) {
|
|
397
|
-
tag.tagPriority =
|
|
367
|
+
tag.tagPriority = 90;
|
|
398
368
|
}
|
|
399
369
|
}
|
|
400
370
|
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
|
}
|
|
@@ -335,37 +335,7 @@ function createHeadCore(options = {}) {
|
|
|
335
335
|
|
|
336
336
|
// @__NO_SIDE_EFFECTS__
|
|
337
337
|
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
|
-
});
|
|
338
|
+
return defineHeadPlugin({});
|
|
369
339
|
}
|
|
370
340
|
|
|
371
341
|
const importRe = /@import/;
|
|
@@ -381,19 +351,19 @@ function CapoPlugin(options) {
|
|
|
381
351
|
const isScript = tag.tag === "script";
|
|
382
352
|
const isLink = tag.tag === "link";
|
|
383
353
|
if (isScript && isTruthy(tag.props.async)) {
|
|
384
|
-
tag.tagPriority =
|
|
354
|
+
tag.tagPriority = 30;
|
|
385
355
|
} else if (tag.tag === "style" && tag.innerHTML && importRe.test(tag.innerHTML)) {
|
|
386
|
-
tag.tagPriority =
|
|
356
|
+
tag.tagPriority = 40;
|
|
387
357
|
} 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 =
|
|
358
|
+
tag.tagPriority = 50;
|
|
389
359
|
} else if (isLink && tag.props.rel === "stylesheet" || tag.tag === "style") {
|
|
390
|
-
tag.tagPriority =
|
|
360
|
+
tag.tagPriority = 60;
|
|
391
361
|
} else if (isLink && ["preload", "modulepreload"].includes(tag.props.rel)) {
|
|
392
|
-
tag.tagPriority =
|
|
362
|
+
tag.tagPriority = 70;
|
|
393
363
|
} else if (isScript && isTruthy(tag.props.defer) && tag.props.src && !isTruthy(tag.props.async)) {
|
|
394
|
-
tag.tagPriority =
|
|
364
|
+
tag.tagPriority = 80;
|
|
395
365
|
} else if (isLink && ["prefetch", "dns-prefetch", "prerender"].includes(tag.props.rel)) {
|
|
396
|
-
tag.tagPriority =
|
|
366
|
+
tag.tagPriority = 90;
|
|
397
367
|
}
|
|
398
368
|
}
|
|
399
369
|
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.0",
|
|
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/dom": "1.
|
|
34
|
-
"@unhead/schema": "1.
|
|
35
|
-
"@unhead/shared": "1.
|
|
33
|
+
"@unhead/dom": "1.6.0",
|
|
34
|
+
"@unhead/schema": "1.6.0",
|
|
35
|
+
"@unhead/shared": "1.6.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "unbuild .",
|