@unhead/vue 1.0.17 → 1.0.20

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
@@ -160,7 +160,7 @@ async function renderDOMHead(head, options = {}) {
160
160
  // convert attributes to object
161
161
  props: $el.getAttributeNames().reduce((props, name) => ({ ...props, [name]: $el.getAttribute(name) }), {})
162
162
  });
163
- const matchIdx = queue.findIndex((ctx2) => ctx2 && (ctx2.tag._d === dedupeKey || $el.isEqualNode(ctx2.$el)));
163
+ const matchIdx = queue.findIndex((ctx2) => ctx2 && (ctx2.tag._d === dedupeKey || $el.isEqualNode?.(ctx2.$el)));
164
164
  if (matchIdx !== -1) {
165
165
  const ctx2 = queue[matchIdx];
166
166
  ctx2.$el = $el;
@@ -887,6 +887,7 @@ const MetaPackingSchema = {
887
887
  keyValueSeparator: ":"
888
888
  }
889
889
  },
890
+ // Pragma directives
890
891
  contentSecurityPolicy: {
891
892
  unpack: {
892
893
  keyValueSeparator: " ",
@@ -901,9 +902,15 @@ const MetaPackingSchema = {
901
902
  msapplicationTileImage: {
902
903
  keyValue: "msapplication-TileImage"
903
904
  },
905
+ /**
906
+ * Tile colour for windows
907
+ */
904
908
  msapplicationTileColor: {
905
909
  keyValue: "msapplication-TileColor"
906
910
  },
911
+ /**
912
+ * URL of a config for windows tile.
913
+ */
907
914
  msapplicationConfig: {
908
915
  keyValue: "msapplication-Config"
909
916
  },
@@ -927,7 +934,34 @@ function resolveMetaKeyType(key) {
927
934
  return PropertyPrefixKeys.test(key) ? "property" : MetaPackingSchema[key]?.metaKey || "name";
928
935
  }
929
936
 
937
+ const ArrayableInputs = ["Image", "Video", "Audio"];
930
938
  function unpackMeta(input) {
939
+ const extras = [];
940
+ ArrayableInputs.forEach((key) => {
941
+ const ogKey = `og:${key.toLowerCase()}`;
942
+ const inputKey = `og${key}`;
943
+ const val = input[inputKey];
944
+ if (typeof val === "object") {
945
+ (Array.isArray(val) ? val : [val]).forEach((entry) => {
946
+ if (!entry)
947
+ return;
948
+ const unpackedEntry = unpackToArray(entry, {
949
+ key: "property",
950
+ value: "content",
951
+ resolveKeyData({ key: key2 }) {
952
+ return fixKeyCase(`${ogKey}${key2 !== "url" ? `:${key2}` : ""}`);
953
+ },
954
+ resolveValueData({ value }) {
955
+ return typeof value === "number" ? value.toString() : value;
956
+ }
957
+ });
958
+ extras.push(
959
+ ...unpackedEntry.sort((a, b) => a.property === ogKey ? -1 : b.property === ogKey ? 1 : 0)
960
+ );
961
+ });
962
+ delete input[inputKey];
963
+ }
964
+ });
931
965
  const meta = unpackToArray(input, {
932
966
  key({ key }) {
933
967
  return resolveMetaKeyType(key);
@@ -963,13 +997,14 @@ function unpackMeta(input) {
963
997
  return typeof value === "number" ? value.toString() : value;
964
998
  }
965
999
  });
966
- return meta.filter((v) => typeof v.content === "undefined" || v.content !== "_null");
1000
+ return [...extras, ...meta].filter((v) => typeof v.content === "undefined" || v.content !== "_null");
967
1001
  }
968
1002
 
969
- const PropertyPrefixKeys = /^(og|twitter|fb)/;
1003
+ const PropertyPrefixKeys = /^(og|fb)/;
1004
+ const ColonPrefixKeys = /^(og|twitter|fb)/;
970
1005
  function fixKeyCase(key) {
971
1006
  key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
972
- if (PropertyPrefixKeys.test(key)) {
1007
+ if (ColonPrefixKeys.test(key)) {
973
1008
  key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
974
1009
  }
975
1010
  return key;
@@ -1029,6 +1064,20 @@ const useServerTagBase = (base) => useServerHead({ base });
1029
1064
  const useServerHtmlAttrs = (attrs) => useServerHead({ htmlAttrs: attrs });
1030
1065
  const useServerBodyAttrs = (attrs) => useHead({ bodyAttrs: attrs });
1031
1066
 
1067
+ const useSeoMeta = (input) => {
1068
+ const headInput = vue.ref({});
1069
+ vue.watchEffect(() => {
1070
+ const resolvedMeta = resolveUnrefHeadInput(input);
1071
+ const { title, titleTemplate, ...meta } = resolvedMeta;
1072
+ headInput.value = {
1073
+ title,
1074
+ titleTemplate,
1075
+ meta: unpackMeta(meta)
1076
+ };
1077
+ });
1078
+ return useHead(headInput);
1079
+ };
1080
+
1032
1081
  function useHead(input, options = {}) {
1033
1082
  const head = injectHead();
1034
1083
  if (head) {
@@ -1048,7 +1097,6 @@ const useTagMetaFlat = (meta) => {
1048
1097
  });
1049
1098
  return useHead({ meta: input });
1050
1099
  };
1051
- const useSeoMeta = useTagMetaFlat;
1052
1100
  const useTagLink = (link) => useHead({ link: asArray(link) });
1053
1101
  const useTagScript = (script) => useHead({ script: asArray(script) });
1054
1102
  const useTagStyle = (style) => useHead({ style: asArray(style) });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _unhead_schema from '@unhead/schema';
2
- import { Head, CreateHeadOptions, Unhead, Title as Title$1, TitleTemplate as TitleTemplate$1, EntryAugmentation, Base as Base$1, Link as Link$1, Meta as Meta$1, Style as Style$1, Script as Script$1, Noscript as Noscript$1, DataKeys, SchemaAugmentations, DefinedValueOrEmptyObject, MergeHead, BaseHtmlAttr, MaybeArray, BaseBodyAttr, HeadEntryOptions, MetaFlatInput, ActiveHeadEntry } from '@unhead/schema';
2
+ import { Head, CreateHeadOptions, Unhead, Title as Title$1, TitleTemplate as TitleTemplate$1, EntryAugmentation, Base as Base$1, Link as Link$1, Meta as Meta$1, Style as Style$1, Script as Script$1, Noscript as Noscript$1, DataKeys, SchemaAugmentations, DefinedValueOrEmptyObject, MaybeFunctionEntries, BodyEvents, MergeHead, BaseHtmlAttr, MaybeArray, BaseBodyAttr, HeadEntryOptions, MetaFlatInput, ActiveHeadEntry } from '@unhead/schema';
3
3
  export { ActiveHeadEntry, Head, HeadEntryOptions, HeadTag, MergeHead, Unhead } from '@unhead/schema';
4
4
  import { ComputedRef, Ref, Plugin } from 'vue';
5
5
 
@@ -44,7 +44,7 @@ type Style<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Style$1<E
44
44
  type Script<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Script$1<E>>;
45
45
  type Noscript<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Noscript$1<E>>;
46
46
  type HtmlAttributes<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<HtmlAttr & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>>>;
47
- type BodyAttributes<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<BodyAttr & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>>>;
47
+ type BodyAttributes<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<BodyAttr & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>> & MaybeFunctionEntries<BodyEvents>>;
48
48
  interface ReactiveHead<E extends MergeHead = MergeHead> {
49
49
  /**
50
50
  * The <title> HTML element defines the document's title that is shown in a browser's title bar or a page's tab.
@@ -142,12 +142,17 @@ declare const useServerTagBase: (base: ReactiveHead['base']) => void | _unhead_s
142
142
  declare const useServerHtmlAttrs: (attrs: ReactiveHead['htmlAttrs']) => void | _unhead_schema.ActiveHeadEntry<UseHeadInput<MergeHead>>;
143
143
  declare const useServerBodyAttrs: (attrs: ReactiveHead['bodyAttrs']) => void | _unhead_schema.ActiveHeadEntry<UseHeadInput<MergeHead>>;
144
144
 
145
+ type UseSeoMetaInput = MaybeComputedRefEntries<MetaFlatInput> & {
146
+ title?: ReactiveHead['title'];
147
+ titleTemplate?: ReactiveHead['titleTemplate'];
148
+ };
149
+ declare const useSeoMeta: (input: UseSeoMetaInput) => ActiveHeadEntry<any> | void;
150
+
145
151
  declare function useHead<T extends MergeHead>(input: UseHeadInput<T>, options?: HeadEntryOptions): ActiveHeadEntry<UseHeadInput<T>> | void;
146
152
  declare const useTagTitle: (title: ReactiveHead['title']) => void | ActiveHeadEntry<UseHeadInput<MergeHead>>;
147
153
  declare const useTitleTemplate: (titleTemplate: ReactiveHead['titleTemplate']) => void | ActiveHeadEntry<UseHeadInput<MergeHead>>;
148
154
  declare const useTagMeta: (meta: Arrayable<Meta>) => void | ActiveHeadEntry<UseHeadInput<MergeHead>>;
149
155
  declare const useTagMetaFlat: (meta: MaybeComputedRefEntries<MetaFlatInput>) => void | ActiveHeadEntry<UseHeadInput<MergeHead>>;
150
- declare const useSeoMeta: (meta: MaybeComputedRefEntries<MetaFlatInput>) => void | ActiveHeadEntry<UseHeadInput<MergeHead>>;
151
156
  declare const useTagLink: (link: Arrayable<Link>) => void | ActiveHeadEntry<UseHeadInput<MergeHead>>;
152
157
  declare const useTagScript: (script: Arrayable<Script>) => void | ActiveHeadEntry<UseHeadInput<MergeHead>>;
153
158
  declare const useTagStyle: (style: Arrayable<Style>) => void | ActiveHeadEntry<UseHeadInput<MergeHead>>;
@@ -160,4 +165,4 @@ declare const unheadVueComposablesImports: {
160
165
  '@unhead/vue': string[];
161
166
  };
162
167
 
163
- export { Arrayable, Base, BodyAttributes, HtmlAttributes, Link, MaybeComputedRef, MaybeComputedRefEntries, MaybeComputedRefOrPromise, MaybeReadonlyRef, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate, UseHeadInput, Vue2ProvideUnheadPlugin, VueHeadClient, VueHeadMixin, VueReactiveUseHeadPlugin, asArray, createHead, createHeadCore, headSymbol, injectHead, resolveUnrefHeadInput, unheadVueComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
168
+ export { Arrayable, Base, BodyAttributes, HtmlAttributes, Link, MaybeComputedRef, MaybeComputedRefEntries, MaybeComputedRefOrPromise, MaybeReadonlyRef, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate, UseHeadInput, UseSeoMetaInput, Vue2ProvideUnheadPlugin, VueHeadClient, VueHeadMixin, VueReactiveUseHeadPlugin, asArray, createHead, createHeadCore, headSymbol, injectHead, resolveUnrefHeadInput, unheadVueComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
package/dist/index.mjs CHANGED
@@ -158,7 +158,7 @@ async function renderDOMHead(head, options = {}) {
158
158
  // convert attributes to object
159
159
  props: $el.getAttributeNames().reduce((props, name) => ({ ...props, [name]: $el.getAttribute(name) }), {})
160
160
  });
161
- const matchIdx = queue.findIndex((ctx2) => ctx2 && (ctx2.tag._d === dedupeKey || $el.isEqualNode(ctx2.$el)));
161
+ const matchIdx = queue.findIndex((ctx2) => ctx2 && (ctx2.tag._d === dedupeKey || $el.isEqualNode?.(ctx2.$el)));
162
162
  if (matchIdx !== -1) {
163
163
  const ctx2 = queue[matchIdx];
164
164
  ctx2.$el = $el;
@@ -885,6 +885,7 @@ const MetaPackingSchema = {
885
885
  keyValueSeparator: ":"
886
886
  }
887
887
  },
888
+ // Pragma directives
888
889
  contentSecurityPolicy: {
889
890
  unpack: {
890
891
  keyValueSeparator: " ",
@@ -899,9 +900,15 @@ const MetaPackingSchema = {
899
900
  msapplicationTileImage: {
900
901
  keyValue: "msapplication-TileImage"
901
902
  },
903
+ /**
904
+ * Tile colour for windows
905
+ */
902
906
  msapplicationTileColor: {
903
907
  keyValue: "msapplication-TileColor"
904
908
  },
909
+ /**
910
+ * URL of a config for windows tile.
911
+ */
905
912
  msapplicationConfig: {
906
913
  keyValue: "msapplication-Config"
907
914
  },
@@ -925,7 +932,34 @@ function resolveMetaKeyType(key) {
925
932
  return PropertyPrefixKeys.test(key) ? "property" : MetaPackingSchema[key]?.metaKey || "name";
926
933
  }
927
934
 
935
+ const ArrayableInputs = ["Image", "Video", "Audio"];
928
936
  function unpackMeta(input) {
937
+ const extras = [];
938
+ ArrayableInputs.forEach((key) => {
939
+ const ogKey = `og:${key.toLowerCase()}`;
940
+ const inputKey = `og${key}`;
941
+ const val = input[inputKey];
942
+ if (typeof val === "object") {
943
+ (Array.isArray(val) ? val : [val]).forEach((entry) => {
944
+ if (!entry)
945
+ return;
946
+ const unpackedEntry = unpackToArray(entry, {
947
+ key: "property",
948
+ value: "content",
949
+ resolveKeyData({ key: key2 }) {
950
+ return fixKeyCase(`${ogKey}${key2 !== "url" ? `:${key2}` : ""}`);
951
+ },
952
+ resolveValueData({ value }) {
953
+ return typeof value === "number" ? value.toString() : value;
954
+ }
955
+ });
956
+ extras.push(
957
+ ...unpackedEntry.sort((a, b) => a.property === ogKey ? -1 : b.property === ogKey ? 1 : 0)
958
+ );
959
+ });
960
+ delete input[inputKey];
961
+ }
962
+ });
929
963
  const meta = unpackToArray(input, {
930
964
  key({ key }) {
931
965
  return resolveMetaKeyType(key);
@@ -961,13 +995,14 @@ function unpackMeta(input) {
961
995
  return typeof value === "number" ? value.toString() : value;
962
996
  }
963
997
  });
964
- return meta.filter((v) => typeof v.content === "undefined" || v.content !== "_null");
998
+ return [...extras, ...meta].filter((v) => typeof v.content === "undefined" || v.content !== "_null");
965
999
  }
966
1000
 
967
- const PropertyPrefixKeys = /^(og|twitter|fb)/;
1001
+ const PropertyPrefixKeys = /^(og|fb)/;
1002
+ const ColonPrefixKeys = /^(og|twitter|fb)/;
968
1003
  function fixKeyCase(key) {
969
1004
  key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
970
- if (PropertyPrefixKeys.test(key)) {
1005
+ if (ColonPrefixKeys.test(key)) {
971
1006
  key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
972
1007
  }
973
1008
  return key;
@@ -1027,6 +1062,20 @@ const useServerTagBase = (base) => useServerHead({ base });
1027
1062
  const useServerHtmlAttrs = (attrs) => useServerHead({ htmlAttrs: attrs });
1028
1063
  const useServerBodyAttrs = (attrs) => useHead({ bodyAttrs: attrs });
1029
1064
 
1065
+ const useSeoMeta = (input) => {
1066
+ const headInput = ref({});
1067
+ watchEffect(() => {
1068
+ const resolvedMeta = resolveUnrefHeadInput(input);
1069
+ const { title, titleTemplate, ...meta } = resolvedMeta;
1070
+ headInput.value = {
1071
+ title,
1072
+ titleTemplate,
1073
+ meta: unpackMeta(meta)
1074
+ };
1075
+ });
1076
+ return useHead(headInput);
1077
+ };
1078
+
1030
1079
  function useHead(input, options = {}) {
1031
1080
  const head = injectHead();
1032
1081
  if (head) {
@@ -1046,7 +1095,6 @@ const useTagMetaFlat = (meta) => {
1046
1095
  });
1047
1096
  return useHead({ meta: input });
1048
1097
  };
1049
- const useSeoMeta = useTagMetaFlat;
1050
1098
  const useTagLink = (link) => useHead({ link: asArray(link) });
1051
1099
  const useTagScript = (script) => useHead({ script: asArray(script) });
1052
1100
  const useTagStyle = (style) => useHead({ style: asArray(style) });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@unhead/vue",
3
3
  "type": "module",
4
- "version": "1.0.17",
5
- "packageManager": "pnpm@7.25.0",
4
+ "version": "1.0.20",
5
+ "packageManager": "pnpm@7.25.1",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -34,11 +34,11 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "hookable": "^5.4.2",
37
- "@unhead/schema": "1.0.17"
37
+ "@unhead/schema": "1.0.20"
38
38
  },
39
39
  "devDependencies": {
40
40
  "vue": "^3.2.45",
41
- "unhead": "1.0.17"
41
+ "unhead": "1.0.20"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "unbuild .",