@unhead/vue 1.0.18 → 1.0.21
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 +49 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +50 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -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|
|
|
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 (
|
|
1007
|
+
if (ColonPrefixKeys.test(key)) {
|
|
973
1008
|
key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
|
|
974
1009
|
}
|
|
975
1010
|
return key;
|
|
@@ -988,17 +1023,27 @@ function changeKeyCasingDeep(input) {
|
|
|
988
1023
|
|
|
989
1024
|
function clientUseHead(input, options = {}) {
|
|
990
1025
|
const head = injectHead();
|
|
1026
|
+
const deactivated = vue.ref(false);
|
|
991
1027
|
const resolvedInput = vue.ref({});
|
|
992
1028
|
vue.watchEffect(() => {
|
|
993
1029
|
resolvedInput.value = resolveUnrefHeadInput(input);
|
|
994
1030
|
});
|
|
995
1031
|
const entry = head.push(resolvedInput.value, options);
|
|
996
|
-
vue.watch(resolvedInput, (e) =>
|
|
1032
|
+
vue.watch([resolvedInput, deactivated], ([e, disable]) => {
|
|
1033
|
+
if (!disable)
|
|
1034
|
+
entry.patch(e);
|
|
1035
|
+
});
|
|
997
1036
|
const vm = vue.getCurrentInstance();
|
|
998
1037
|
if (vm) {
|
|
999
1038
|
vue.onBeforeUnmount(() => {
|
|
1000
1039
|
entry.dispose();
|
|
1001
1040
|
});
|
|
1041
|
+
vue.onDeactivated(() => {
|
|
1042
|
+
deactivated.value = true;
|
|
1043
|
+
});
|
|
1044
|
+
vue.onActivated(() => {
|
|
1045
|
+
deactivated.value = false;
|
|
1046
|
+
});
|
|
1002
1047
|
}
|
|
1003
1048
|
return entry;
|
|
1004
1049
|
}
|
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.
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHooks } from 'hookable';
|
|
2
|
-
import { unref, isRef, version, getCurrentInstance, inject, nextTick, ref, watchEffect, watch, onBeforeUnmount } from 'vue';
|
|
2
|
+
import { unref, isRef, version, getCurrentInstance, inject, nextTick, ref, watchEffect, watch, onBeforeUnmount, onDeactivated, onActivated } from 'vue';
|
|
3
3
|
|
|
4
4
|
const TagsWithInnerContent = ["script", "style", "noscript"];
|
|
5
5
|
const HasElementTags$1 = [
|
|
@@ -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|
|
|
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 (
|
|
1005
|
+
if (ColonPrefixKeys.test(key)) {
|
|
971
1006
|
key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
|
|
972
1007
|
}
|
|
973
1008
|
return key;
|
|
@@ -986,17 +1021,27 @@ function changeKeyCasingDeep(input) {
|
|
|
986
1021
|
|
|
987
1022
|
function clientUseHead(input, options = {}) {
|
|
988
1023
|
const head = injectHead();
|
|
1024
|
+
const deactivated = ref(false);
|
|
989
1025
|
const resolvedInput = ref({});
|
|
990
1026
|
watchEffect(() => {
|
|
991
1027
|
resolvedInput.value = resolveUnrefHeadInput(input);
|
|
992
1028
|
});
|
|
993
1029
|
const entry = head.push(resolvedInput.value, options);
|
|
994
|
-
watch(resolvedInput, (e) =>
|
|
1030
|
+
watch([resolvedInput, deactivated], ([e, disable]) => {
|
|
1031
|
+
if (!disable)
|
|
1032
|
+
entry.patch(e);
|
|
1033
|
+
});
|
|
995
1034
|
const vm = getCurrentInstance();
|
|
996
1035
|
if (vm) {
|
|
997
1036
|
onBeforeUnmount(() => {
|
|
998
1037
|
entry.dispose();
|
|
999
1038
|
});
|
|
1039
|
+
onDeactivated(() => {
|
|
1040
|
+
deactivated.value = true;
|
|
1041
|
+
});
|
|
1042
|
+
onActivated(() => {
|
|
1043
|
+
deactivated.value = false;
|
|
1044
|
+
});
|
|
1000
1045
|
}
|
|
1001
1046
|
return entry;
|
|
1002
1047
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.21",
|
|
5
5
|
"packageManager": "pnpm@7.25.1",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"hookable": "^5.4.2",
|
|
37
|
-
"@unhead/schema": "1.0.
|
|
37
|
+
"@unhead/schema": "1.0.21"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"vue": "^3.2.45",
|
|
41
|
-
"unhead": "1.0.
|
|
41
|
+
"unhead": "1.0.21"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "unbuild .",
|