unhead 1.1.34 → 1.2.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 +36 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +36 -2
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,8 @@ function tagWeight(tag) {
|
|
|
25
25
|
weight = -2;
|
|
26
26
|
if (tag.props["http-equiv"] === "content-security-policy")
|
|
27
27
|
weight = 0;
|
|
28
|
+
} else if (tag.tag == "link" && tag.props.rel === "preconnect") {
|
|
29
|
+
weight = 2;
|
|
28
30
|
} else if (tag.tag in TAG_WEIGHTS) {
|
|
29
31
|
weight = TAG_WEIGHTS[tag.tag];
|
|
30
32
|
}
|
|
@@ -332,6 +334,38 @@ function TemplateParamsPlugin() {
|
|
|
332
334
|
});
|
|
333
335
|
}
|
|
334
336
|
|
|
337
|
+
const importRe = /@import/;
|
|
338
|
+
function CapoPlugin() {
|
|
339
|
+
return shared.defineHeadPlugin({
|
|
340
|
+
hooks: {
|
|
341
|
+
"tags:beforeResolve": function({ tags }) {
|
|
342
|
+
for (const tag of tags) {
|
|
343
|
+
if (tag.tagPriority)
|
|
344
|
+
continue;
|
|
345
|
+
const isTruthy = (val) => val === "";
|
|
346
|
+
const isScript = tag.tag === "script";
|
|
347
|
+
const isLink = tag.tag === "link";
|
|
348
|
+
if (isScript && isTruthy(tag.props.async)) {
|
|
349
|
+
tag.tagPriority = 3;
|
|
350
|
+
} else if (tag.tag === "style" && tag.innerHTML && importRe.test(tag.innerHTML)) {
|
|
351
|
+
tag.tagPriority = 4;
|
|
352
|
+
} else if (isScript && tag.props.src && !isTruthy(tag.props.defer) && !isTruthy(tag.props.async) && tag.props.type !== "module" && !tag.props.type?.endsWith("json")) {
|
|
353
|
+
tag.tagPriority = 5;
|
|
354
|
+
} else if (isLink && tag.props.rel === "stylesheet" || tag.tag === "style") {
|
|
355
|
+
tag.tagPriority = 6;
|
|
356
|
+
} else if (isLink && ["preload", "modulepreload"].includes(tag.props.rel)) {
|
|
357
|
+
tag.tagPriority = 7;
|
|
358
|
+
} else if (isScript && isTruthy(tag.props.defer) && tag.props.src && !isTruthy(tag.props.async)) {
|
|
359
|
+
tag.tagPriority = 8;
|
|
360
|
+
} else if (isLink && ["prefetch", "dns-prefetch", "prerender"].includes(tag.props.rel)) {
|
|
361
|
+
tag.tagPriority = 9;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
335
369
|
const IsBrowser = typeof window !== "undefined";
|
|
336
370
|
|
|
337
371
|
exports.activeHead = void 0;
|
|
@@ -1020,7 +1054,7 @@ function createHeadCore(options = {}) {
|
|
|
1020
1054
|
await hooks.callHook("entries:resolve", resolveCtx);
|
|
1021
1055
|
for (const entry of resolveCtx.entries) {
|
|
1022
1056
|
const resolved = entry.resolvedInput || entry.input;
|
|
1023
|
-
entry.resolvedInput = entry.transform ? entry.transform(resolved) : resolved;
|
|
1057
|
+
entry.resolvedInput = await (entry.transform ? entry.transform(resolved) : resolved);
|
|
1024
1058
|
if (entry.resolvedInput) {
|
|
1025
1059
|
for (const tag of await normaliseEntryTags(entry)) {
|
|
1026
1060
|
const tagCtx = { tag, entry, resolvedOptions: head.resolvedOptions };
|
|
@@ -1085,6 +1119,7 @@ const unheadComposablesImports = [
|
|
|
1085
1119
|
}
|
|
1086
1120
|
];
|
|
1087
1121
|
|
|
1122
|
+
exports.CapoPlugin = CapoPlugin;
|
|
1088
1123
|
exports.CorePlugins = CorePlugins;
|
|
1089
1124
|
exports.DOMPlugins = DOMPlugins;
|
|
1090
1125
|
exports.DedupesTagsPlugin = DedupesTagsPlugin;
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ declare function DedupesTagsPlugin(): _unhead_schema.HeadPlugin;
|
|
|
36
36
|
declare function processTemplateParams(s: string, p: TemplateParams): string;
|
|
37
37
|
declare function TemplateParamsPlugin(): _unhead_schema.HeadPlugin;
|
|
38
38
|
|
|
39
|
+
declare function CapoPlugin(): _unhead_schema.HeadPlugin;
|
|
40
|
+
|
|
39
41
|
declare function useHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
40
42
|
|
|
41
43
|
declare function useHeadSafe(input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe> | void;
|
|
@@ -186,4 +188,4 @@ declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promi
|
|
|
186
188
|
|
|
187
189
|
declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<string, string>>>): HeadSafe;
|
|
188
190
|
|
|
189
|
-
export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_ALIASES, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, UseSeoMetaInput, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
|
|
191
|
+
export { CapoPlugin, CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_ALIASES, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, UseSeoMetaInput, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
|
package/dist/index.mjs
CHANGED
|
@@ -23,6 +23,8 @@ function tagWeight(tag) {
|
|
|
23
23
|
weight = -2;
|
|
24
24
|
if (tag.props["http-equiv"] === "content-security-policy")
|
|
25
25
|
weight = 0;
|
|
26
|
+
} else if (tag.tag == "link" && tag.props.rel === "preconnect") {
|
|
27
|
+
weight = 2;
|
|
26
28
|
} else if (tag.tag in TAG_WEIGHTS) {
|
|
27
29
|
weight = TAG_WEIGHTS[tag.tag];
|
|
28
30
|
}
|
|
@@ -330,6 +332,38 @@ function TemplateParamsPlugin() {
|
|
|
330
332
|
});
|
|
331
333
|
}
|
|
332
334
|
|
|
335
|
+
const importRe = /@import/;
|
|
336
|
+
function CapoPlugin() {
|
|
337
|
+
return defineHeadPlugin({
|
|
338
|
+
hooks: {
|
|
339
|
+
"tags:beforeResolve": function({ tags }) {
|
|
340
|
+
for (const tag of tags) {
|
|
341
|
+
if (tag.tagPriority)
|
|
342
|
+
continue;
|
|
343
|
+
const isTruthy = (val) => val === "";
|
|
344
|
+
const isScript = tag.tag === "script";
|
|
345
|
+
const isLink = tag.tag === "link";
|
|
346
|
+
if (isScript && isTruthy(tag.props.async)) {
|
|
347
|
+
tag.tagPriority = 3;
|
|
348
|
+
} else if (tag.tag === "style" && tag.innerHTML && importRe.test(tag.innerHTML)) {
|
|
349
|
+
tag.tagPriority = 4;
|
|
350
|
+
} else if (isScript && tag.props.src && !isTruthy(tag.props.defer) && !isTruthy(tag.props.async) && tag.props.type !== "module" && !tag.props.type?.endsWith("json")) {
|
|
351
|
+
tag.tagPriority = 5;
|
|
352
|
+
} else if (isLink && tag.props.rel === "stylesheet" || tag.tag === "style") {
|
|
353
|
+
tag.tagPriority = 6;
|
|
354
|
+
} else if (isLink && ["preload", "modulepreload"].includes(tag.props.rel)) {
|
|
355
|
+
tag.tagPriority = 7;
|
|
356
|
+
} else if (isScript && isTruthy(tag.props.defer) && tag.props.src && !isTruthy(tag.props.async)) {
|
|
357
|
+
tag.tagPriority = 8;
|
|
358
|
+
} else if (isLink && ["prefetch", "dns-prefetch", "prerender"].includes(tag.props.rel)) {
|
|
359
|
+
tag.tagPriority = 9;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
|
|
333
367
|
const IsBrowser = typeof window !== "undefined";
|
|
334
368
|
|
|
335
369
|
let activeHead;
|
|
@@ -1018,7 +1052,7 @@ function createHeadCore(options = {}) {
|
|
|
1018
1052
|
await hooks.callHook("entries:resolve", resolveCtx);
|
|
1019
1053
|
for (const entry of resolveCtx.entries) {
|
|
1020
1054
|
const resolved = entry.resolvedInput || entry.input;
|
|
1021
|
-
entry.resolvedInput = entry.transform ? entry.transform(resolved) : resolved;
|
|
1055
|
+
entry.resolvedInput = await (entry.transform ? entry.transform(resolved) : resolved);
|
|
1022
1056
|
if (entry.resolvedInput) {
|
|
1023
1057
|
for (const tag of await normaliseEntryTags(entry)) {
|
|
1024
1058
|
const tagCtx = { tag, entry, resolvedOptions: head.resolvedOptions };
|
|
@@ -1083,4 +1117,4 @@ const unheadComposablesImports = [
|
|
|
1083
1117
|
}
|
|
1084
1118
|
];
|
|
1085
1119
|
|
|
1086
|
-
export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_ALIASES, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
|
|
1120
|
+
export { CapoPlugin, CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_ALIASES, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unhead",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"main": "dist/index.cjs",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"hookable": "^5.5.3",
|
|
33
|
-
"@unhead/dom": "1.1
|
|
34
|
-
"@unhead/schema": "1.1
|
|
35
|
-
"@unhead/shared": "1.1
|
|
33
|
+
"@unhead/dom": "1.2.1",
|
|
34
|
+
"@unhead/schema": "1.2.1",
|
|
35
|
+
"@unhead/shared": "1.2.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"packrup": "^0.1.0"
|