unhead 1.1.35 → 1.2.2

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 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,44 @@ function TemplateParamsPlugin() {
332
334
  });
333
335
  }
334
336
 
337
+ const importRe = /@import/;
338
+ function CapoPlugin(options) {
339
+ return shared.defineHeadPlugin({
340
+ hooks: {
341
+ "tags:beforeResolve": function({ tags }) {
342
+ for (const tag of tags) {
343
+ if (tag.tagPriority || tag.tagPosition && tag.tagPosition !== "head")
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
+ options?.track && tags.push({
365
+ tag: "htmlAttrs",
366
+ props: {
367
+ "data-capo": ""
368
+ }
369
+ });
370
+ }
371
+ }
372
+ });
373
+ }
374
+
335
375
  const IsBrowser = typeof window !== "undefined";
336
376
 
337
377
  exports.activeHead = void 0;
@@ -1085,6 +1125,7 @@ const unheadComposablesImports = [
1085
1125
  }
1086
1126
  ];
1087
1127
 
1128
+ exports.CapoPlugin = CapoPlugin;
1088
1129
  exports.CorePlugins = CorePlugins;
1089
1130
  exports.DOMPlugins = DOMPlugins;
1090
1131
  exports.DedupesTagsPlugin = DedupesTagsPlugin;
package/dist/index.d.ts CHANGED
@@ -36,6 +36,10 @@ 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(options: {
40
+ track?: boolean;
41
+ }): _unhead_schema.HeadPlugin;
42
+
39
43
  declare function useHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
40
44
 
41
45
  declare function useHeadSafe(input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe> | void;
@@ -186,4 +190,4 @@ declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promi
186
190
 
187
191
  declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<string, string>>>): HeadSafe;
188
192
 
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 };
193
+ 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,44 @@ function TemplateParamsPlugin() {
330
332
  });
331
333
  }
332
334
 
335
+ const importRe = /@import/;
336
+ function CapoPlugin(options) {
337
+ return defineHeadPlugin({
338
+ hooks: {
339
+ "tags:beforeResolve": function({ tags }) {
340
+ for (const tag of tags) {
341
+ if (tag.tagPriority || tag.tagPosition && tag.tagPosition !== "head")
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
+ options?.track && tags.push({
363
+ tag: "htmlAttrs",
364
+ props: {
365
+ "data-capo": ""
366
+ }
367
+ });
368
+ }
369
+ }
370
+ });
371
+ }
372
+
333
373
  const IsBrowser = typeof window !== "undefined";
334
374
 
335
375
  let activeHead;
@@ -1083,4 +1123,4 @@ const unheadComposablesImports = [
1083
1123
  }
1084
1124
  ];
1085
1125
 
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 };
1126
+ 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.35",
4
+ "version": "1.2.2",
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
- "require": "./dist/index.cjs",
22
- "import": "./dist/index.mjs"
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.35",
34
- "@unhead/schema": "1.1.35",
35
- "@unhead/shared": "1.1.35"
33
+ "@unhead/dom": "1.2.2",
34
+ "@unhead/schema": "1.2.2",
35
+ "@unhead/shared": "1.2.2"
36
36
  },
37
37
  "devDependencies": {
38
38
  "packrup": "^0.1.0"