@unhead/vue 1.6.2 → 1.7.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.
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ const vue = require('vue');
4
+ const injectHead = require('./shared/vue.77729ad4.cjs');
5
+ require('unhead');
6
+ require('@unhead/shared');
7
+
8
+ function addVNodeToHeadObj(node, obj) {
9
+ const nodeType = !injectHead.Vue3 ? node.tag : node.type;
10
+ const type = nodeType === "html" ? "htmlAttrs" : nodeType === "body" ? "bodyAttrs" : nodeType;
11
+ if (typeof type !== "string" || !(type in obj))
12
+ return;
13
+ const nodeData = !injectHead.Vue3 ? node.data : node;
14
+ const props = (!injectHead.Vue3 ? nodeData.attrs : node.props) || {};
15
+ if (!injectHead.Vue3) {
16
+ if (nodeData.staticClass)
17
+ props.class = nodeData.staticClass;
18
+ if (nodeData.staticStyle)
19
+ props.style = Object.entries(nodeData.staticStyle).map(([key, value]) => `${key}:${value}`).join(";");
20
+ }
21
+ if (node.children) {
22
+ const childrenAttr = !injectHead.Vue3 ? "text" : "children";
23
+ props.children = Array.isArray(node.children) ? node.children[0][childrenAttr] : node[childrenAttr];
24
+ }
25
+ if (Array.isArray(obj[type]))
26
+ obj[type].push(props);
27
+ else if (type === "title")
28
+ obj.title = props.children;
29
+ else
30
+ obj[type] = props;
31
+ }
32
+ function vnodesToHeadObj(nodes) {
33
+ const obj = {
34
+ title: void 0,
35
+ htmlAttrs: void 0,
36
+ bodyAttrs: void 0,
37
+ base: void 0,
38
+ meta: [],
39
+ link: [],
40
+ style: [],
41
+ script: [],
42
+ noscript: []
43
+ };
44
+ for (const node of nodes) {
45
+ if (typeof node.type === "symbol" && Array.isArray(node.children)) {
46
+ for (const childNode of node.children)
47
+ addVNodeToHeadObj(childNode, obj);
48
+ } else {
49
+ addVNodeToHeadObj(node, obj);
50
+ }
51
+ }
52
+ return obj;
53
+ }
54
+ const Head = /* @__PURE__ */ vue.defineComponent({
55
+ // eslint-disable-next-line vue/no-reserved-component-names
56
+ name: "Head",
57
+ setup(_, { slots }) {
58
+ const head = injectHead.injectHead();
59
+ const obj = vue.ref({});
60
+ const entry = head.push(obj);
61
+ vue.onBeforeUnmount(() => {
62
+ entry.dispose();
63
+ });
64
+ return () => {
65
+ vue.watchEffect(() => {
66
+ if (!slots.default)
67
+ return;
68
+ entry.patch(vnodesToHeadObj(slots.default()));
69
+ });
70
+ return null;
71
+ };
72
+ }
73
+ });
74
+
75
+ exports.Head = Head;
@@ -0,0 +1,5 @@
1
+ import { DefineComponent } from 'vue';
2
+
3
+ declare const Head: DefineComponent;
4
+
5
+ export { Head };
@@ -0,0 +1,5 @@
1
+ import { DefineComponent } from 'vue';
2
+
3
+ declare const Head: DefineComponent;
4
+
5
+ export { Head };
@@ -0,0 +1,5 @@
1
+ import { DefineComponent } from 'vue';
2
+
3
+ declare const Head: DefineComponent;
4
+
5
+ export { Head };
@@ -0,0 +1,73 @@
1
+ import { defineComponent, ref, onBeforeUnmount, watchEffect } from 'vue';
2
+ import { i as injectHead, V as Vue3 } from './shared/vue.cf295fb1.mjs';
3
+ import 'unhead';
4
+ import '@unhead/shared';
5
+
6
+ function addVNodeToHeadObj(node, obj) {
7
+ const nodeType = !Vue3 ? node.tag : node.type;
8
+ const type = nodeType === "html" ? "htmlAttrs" : nodeType === "body" ? "bodyAttrs" : nodeType;
9
+ if (typeof type !== "string" || !(type in obj))
10
+ return;
11
+ const nodeData = !Vue3 ? node.data : node;
12
+ const props = (!Vue3 ? nodeData.attrs : node.props) || {};
13
+ if (!Vue3) {
14
+ if (nodeData.staticClass)
15
+ props.class = nodeData.staticClass;
16
+ if (nodeData.staticStyle)
17
+ props.style = Object.entries(nodeData.staticStyle).map(([key, value]) => `${key}:${value}`).join(";");
18
+ }
19
+ if (node.children) {
20
+ const childrenAttr = !Vue3 ? "text" : "children";
21
+ props.children = Array.isArray(node.children) ? node.children[0][childrenAttr] : node[childrenAttr];
22
+ }
23
+ if (Array.isArray(obj[type]))
24
+ obj[type].push(props);
25
+ else if (type === "title")
26
+ obj.title = props.children;
27
+ else
28
+ obj[type] = props;
29
+ }
30
+ function vnodesToHeadObj(nodes) {
31
+ const obj = {
32
+ title: void 0,
33
+ htmlAttrs: void 0,
34
+ bodyAttrs: void 0,
35
+ base: void 0,
36
+ meta: [],
37
+ link: [],
38
+ style: [],
39
+ script: [],
40
+ noscript: []
41
+ };
42
+ for (const node of nodes) {
43
+ if (typeof node.type === "symbol" && Array.isArray(node.children)) {
44
+ for (const childNode of node.children)
45
+ addVNodeToHeadObj(childNode, obj);
46
+ } else {
47
+ addVNodeToHeadObj(node, obj);
48
+ }
49
+ }
50
+ return obj;
51
+ }
52
+ const Head = /* @__PURE__ */ defineComponent({
53
+ // eslint-disable-next-line vue/no-reserved-component-names
54
+ name: "Head",
55
+ setup(_, { slots }) {
56
+ const head = injectHead();
57
+ const obj = ref({});
58
+ const entry = head.push(obj);
59
+ onBeforeUnmount(() => {
60
+ entry.dispose();
61
+ });
62
+ return () => {
63
+ watchEffect(() => {
64
+ if (!slots.default)
65
+ return;
66
+ entry.patch(vnodesToHeadObj(slots.default()));
67
+ });
68
+ return null;
69
+ };
70
+ }
71
+ });
72
+
73
+ export { Head };
package/dist/index.cjs CHANGED
@@ -1,14 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const unhead = require('unhead');
4
- const useHead = require('./shared/vue.9cf7ea21.cjs');
4
+ const injectHead = require('./shared/vue.77729ad4.cjs');
5
5
  const vue = require('vue');
6
+ const useHead = require('./shared/vue.af935fad.cjs');
6
7
  const shared = require('@unhead/shared');
7
8
 
8
9
  const VueHeadMixin = {
9
10
  created() {
10
11
  let source = false;
11
- if (useHead.Vue3) {
12
+ if (injectHead.Vue3) {
12
13
  const instance = vue.getCurrentInstance();
13
14
  if (!instance)
14
15
  return;
@@ -39,7 +40,7 @@ const Vue2ProvideUnheadPlugin = function(_Vue, head) {
39
40
  origProvideResult = origProvide || {};
40
41
  return {
41
42
  ...origProvideResult,
42
- [useHead.headSymbol]: head
43
+ [injectHead.headSymbol]: head
43
44
  };
44
45
  };
45
46
  }
@@ -60,7 +61,7 @@ function useHeadSafe(input, options = {}) {
60
61
  function useSeoMeta(input, options) {
61
62
  const headInput = vue.ref({});
62
63
  vue.watchEffect(() => {
63
- const resolvedMeta = useHead.resolveUnrefHeadInput(input);
64
+ const resolvedMeta = injectHead.resolveUnrefHeadInput(input);
64
65
  const { title, titleTemplate, ...meta } = resolvedMeta;
65
66
  headInput.value = {
66
67
  title,
@@ -72,7 +73,7 @@ function useSeoMeta(input, options) {
72
73
  }
73
74
 
74
75
  function useServerHead(input, options = {}) {
75
- const head = options.head || useHead.injectHead();
76
+ const head = options.head || injectHead.injectHead();
76
77
  delete options.head;
77
78
  if (head)
78
79
  return head.push(input, { ...options, mode: "server" });
@@ -89,11 +90,11 @@ function useServerSeoMeta(input, options) {
89
90
  exports.CapoPlugin = unhead.CapoPlugin;
90
91
  exports.HashHydrationPlugin = unhead.HashHydrationPlugin;
91
92
  exports.createHeadCore = unhead.createHeadCore;
92
- exports.createHead = useHead.createHead;
93
- exports.createServerHead = useHead.createServerHead;
94
- exports.injectHead = useHead.injectHead;
95
- exports.resolveUnrefHeadInput = useHead.resolveUnrefHeadInput;
96
- exports.setHeadInjectionHandler = useHead.setHeadInjectionHandler;
93
+ exports.createHead = injectHead.createHead;
94
+ exports.createServerHead = injectHead.createServerHead;
95
+ exports.injectHead = injectHead.injectHead;
96
+ exports.resolveUnrefHeadInput = injectHead.resolveUnrefHeadInput;
97
+ exports.setHeadInjectionHandler = injectHead.setHeadInjectionHandler;
97
98
  exports.useHead = useHead.useHead;
98
99
  exports.Vue2ProvideUnheadPlugin = Vue2ProvideUnheadPlugin;
99
100
  exports.VueHeadMixin = VueHeadMixin;
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  export { CapoPlugin, HashHydrationPlugin, createHeadCore } from 'unhead';
2
- import { V as Vue3, u as useHead, h as headSymbol, r as resolveUnrefHeadInput, i as injectHead } from './shared/vue.b1b42453.mjs';
3
- export { c as createHead, a as createServerHead, s as setHeadInjectionHandler } from './shared/vue.b1b42453.mjs';
2
+ import { V as Vue3, h as headSymbol, r as resolveUnrefHeadInput, i as injectHead } from './shared/vue.cf295fb1.mjs';
3
+ export { c as createHead, a as createServerHead, s as setHeadInjectionHandler } from './shared/vue.cf295fb1.mjs';
4
4
  import { getCurrentInstance, ref, watchEffect } from 'vue';
5
+ import { u as useHead } from './shared/vue.f36acd1f.mjs';
5
6
  import { composableNames, whitelistSafeInput, unpackMeta } from '@unhead/shared';
6
7
 
7
8
  const VueHeadMixin = {
package/dist/polyfill.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const useHead = require('./shared/vue.9cf7ea21.cjs');
3
+ const useHead = require('./shared/vue.af935fad.cjs');
4
4
  require('vue');
5
+ require('./shared/vue.77729ad4.cjs');
5
6
  require('unhead');
6
7
  require('@unhead/shared');
7
8
 
@@ -32,6 +32,9 @@ type VueHeadClientPollyFill<T extends MergeHead> = VueHeadClient<T> & {
32
32
  */
33
33
  unhead: VueHeadClient<T>;
34
34
  };
35
+ /**
36
+ * @deprecated Will be removed in v2.
37
+ */
35
38
  declare function polyfillAsVueUseHead<T extends MergeHead>(head: VueHeadClient<T>): VueHeadClientPollyFill<T>;
36
39
 
37
40
  export { type VueHeadClientPollyFill, polyfillAsVueUseHead };
@@ -32,6 +32,9 @@ type VueHeadClientPollyFill<T extends MergeHead> = VueHeadClient<T> & {
32
32
  */
33
33
  unhead: VueHeadClient<T>;
34
34
  };
35
+ /**
36
+ * @deprecated Will be removed in v2.
37
+ */
35
38
  declare function polyfillAsVueUseHead<T extends MergeHead>(head: VueHeadClient<T>): VueHeadClientPollyFill<T>;
36
39
 
37
40
  export { type VueHeadClientPollyFill, polyfillAsVueUseHead };
@@ -32,6 +32,9 @@ type VueHeadClientPollyFill<T extends MergeHead> = VueHeadClient<T> & {
32
32
  */
33
33
  unhead: VueHeadClient<T>;
34
34
  };
35
+ /**
36
+ * @deprecated Will be removed in v2.
37
+ */
35
38
  declare function polyfillAsVueUseHead<T extends MergeHead>(head: VueHeadClient<T>): VueHeadClientPollyFill<T>;
36
39
 
37
40
  export { type VueHeadClientPollyFill, polyfillAsVueUseHead };
package/dist/polyfill.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { u as useHead } from './shared/vue.b1b42453.mjs';
1
+ import { u as useHead } from './shared/vue.f36acd1f.mjs';
2
2
  import 'vue';
3
+ import './shared/vue.cf295fb1.mjs';
3
4
  import 'unhead';
4
5
  import '@unhead/shared';
5
6
 
@@ -80,39 +80,6 @@ function injectHead() {
80
80
  return head || unhead.getActiveHead();
81
81
  }
82
82
 
83
- function useHead(input, options = {}) {
84
- const head = options.head || injectHead();
85
- if (head) {
86
- if (!head.ssr)
87
- return clientUseHead(head, input, options);
88
- return head.push(input, options);
89
- }
90
- }
91
- function clientUseHead(head, input, options = {}) {
92
- const deactivated = vue.ref(false);
93
- const resolvedInput = vue.ref({});
94
- vue.watchEffect(() => {
95
- resolvedInput.value = deactivated.value ? {} : resolveUnrefHeadInput(input);
96
- });
97
- const entry = head.push(resolvedInput.value, options);
98
- vue.watch(resolvedInput, (e) => {
99
- entry.patch(e);
100
- });
101
- const vm = vue.getCurrentInstance();
102
- if (vm) {
103
- vue.onBeforeUnmount(() => {
104
- entry.dispose();
105
- });
106
- vue.onDeactivated(() => {
107
- deactivated.value = true;
108
- });
109
- vue.onActivated(() => {
110
- deactivated.value = false;
111
- });
112
- }
113
- return entry;
114
- }
115
-
116
83
  exports.Vue3 = Vue3;
117
84
  exports.createHead = createHead;
118
85
  exports.createServerHead = createServerHead;
@@ -120,4 +87,3 @@ exports.headSymbol = headSymbol;
120
87
  exports.injectHead = injectHead;
121
88
  exports.resolveUnrefHeadInput = resolveUnrefHeadInput;
122
89
  exports.setHeadInjectionHandler = setHeadInjectionHandler;
123
- exports.useHead = useHead;
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ const vue = require('vue');
4
+ const injectHead = require('./vue.77729ad4.cjs');
5
+
6
+ function useHead(input, options = {}) {
7
+ const head = options.head || injectHead.injectHead();
8
+ if (head) {
9
+ if (!head.ssr)
10
+ return clientUseHead(head, input, options);
11
+ return head.push(input, options);
12
+ }
13
+ }
14
+ function clientUseHead(head, input, options = {}) {
15
+ const deactivated = vue.ref(false);
16
+ const resolvedInput = vue.ref({});
17
+ vue.watchEffect(() => {
18
+ resolvedInput.value = deactivated.value ? {} : injectHead.resolveUnrefHeadInput(input);
19
+ });
20
+ const entry = head.push(resolvedInput.value, options);
21
+ vue.watch(resolvedInput, (e) => {
22
+ entry.patch(e);
23
+ });
24
+ const vm = vue.getCurrentInstance();
25
+ if (vm) {
26
+ vue.onBeforeUnmount(() => {
27
+ entry.dispose();
28
+ });
29
+ vue.onDeactivated(() => {
30
+ deactivated.value = true;
31
+ });
32
+ vue.onActivated(() => {
33
+ deactivated.value = false;
34
+ });
35
+ }
36
+ return entry;
37
+ }
38
+
39
+ exports.useHead = useHead;
@@ -1,4 +1,4 @@
1
- import { version, unref, nextTick, inject, ref, watchEffect, watch, getCurrentInstance, onBeforeUnmount, onDeactivated, onActivated } from 'vue';
1
+ import { version, unref, nextTick, inject } from 'vue';
2
2
  import { createServerHead as createServerHead$1, createHead as createHead$1, getActiveHead } from 'unhead';
3
3
  import { defineHeadPlugin } from '@unhead/shared';
4
4
 
@@ -78,37 +78,4 @@ function injectHead() {
78
78
  return head || getActiveHead();
79
79
  }
80
80
 
81
- function useHead(input, options = {}) {
82
- const head = options.head || injectHead();
83
- if (head) {
84
- if (!head.ssr)
85
- return clientUseHead(head, input, options);
86
- return head.push(input, options);
87
- }
88
- }
89
- function clientUseHead(head, input, options = {}) {
90
- const deactivated = ref(false);
91
- const resolvedInput = ref({});
92
- watchEffect(() => {
93
- resolvedInput.value = deactivated.value ? {} : resolveUnrefHeadInput(input);
94
- });
95
- const entry = head.push(resolvedInput.value, options);
96
- watch(resolvedInput, (e) => {
97
- entry.patch(e);
98
- });
99
- const vm = getCurrentInstance();
100
- if (vm) {
101
- onBeforeUnmount(() => {
102
- entry.dispose();
103
- });
104
- onDeactivated(() => {
105
- deactivated.value = true;
106
- });
107
- onActivated(() => {
108
- deactivated.value = false;
109
- });
110
- }
111
- return entry;
112
- }
113
-
114
- export { Vue3 as V, createServerHead as a, createHead as c, headSymbol as h, injectHead as i, resolveUnrefHeadInput as r, setHeadInjectionHandler as s, useHead as u };
81
+ export { Vue3 as V, createServerHead as a, createHead as c, headSymbol as h, injectHead as i, resolveUnrefHeadInput as r, setHeadInjectionHandler as s };
@@ -0,0 +1,37 @@
1
+ import { ref, watchEffect, watch, getCurrentInstance, onBeforeUnmount, onDeactivated, onActivated } from 'vue';
2
+ import { i as injectHead, r as resolveUnrefHeadInput } from './vue.cf295fb1.mjs';
3
+
4
+ function useHead(input, options = {}) {
5
+ const head = options.head || injectHead();
6
+ if (head) {
7
+ if (!head.ssr)
8
+ return clientUseHead(head, input, options);
9
+ return head.push(input, options);
10
+ }
11
+ }
12
+ function clientUseHead(head, input, options = {}) {
13
+ const deactivated = ref(false);
14
+ const resolvedInput = ref({});
15
+ watchEffect(() => {
16
+ resolvedInput.value = deactivated.value ? {} : resolveUnrefHeadInput(input);
17
+ });
18
+ const entry = head.push(resolvedInput.value, options);
19
+ watch(resolvedInput, (e) => {
20
+ entry.patch(e);
21
+ });
22
+ const vm = getCurrentInstance();
23
+ if (vm) {
24
+ onBeforeUnmount(() => {
25
+ entry.dispose();
26
+ });
27
+ onDeactivated(() => {
28
+ deactivated.value = true;
29
+ });
30
+ onActivated(() => {
31
+ deactivated.value = false;
32
+ });
33
+ }
34
+ return entry;
35
+ }
36
+
37
+ export { useHead as u };
package/dist/vue2.cjs CHANGED
@@ -1,50 +1,49 @@
1
1
  'use strict';
2
2
 
3
3
  const vue = require('vue');
4
- const useHead = require('./shared/vue.9cf7ea21.cjs');
4
+ const injectHead = require('./shared/vue.77729ad4.cjs');
5
+ const useHead = require('./shared/vue.af935fad.cjs');
5
6
  require('unhead');
6
7
  require('@unhead/shared');
7
8
 
8
- const HeadOptions = {
9
- created() {
10
- let source = false;
11
- if (useHead.Vue3) {
12
- const instance = vue.getCurrentInstance();
13
- if (!instance)
14
- return;
15
- const options = instance.type;
16
- if (!options || !("head" in options))
17
- return;
18
- source = typeof options.head === "function" ? () => options.head.call(instance.proxy) : options.head;
19
- } else {
20
- const head = this.$options.head;
21
- if (head) {
22
- source = typeof head === "function" ? () => head.call(this) : head;
9
+ const UnheadPlugin = function(_Vue) {
10
+ _Vue.mixin({
11
+ created() {
12
+ let source = false;
13
+ if (injectHead.Vue3) {
14
+ const instance = vue.getCurrentInstance();
15
+ if (!instance)
16
+ return;
17
+ const options = instance.type;
18
+ if (!options || !("head" in options))
19
+ return;
20
+ source = typeof options.head === "function" ? () => options.head.call(instance.proxy) : options.head;
21
+ } else {
22
+ const head = this.$options.head;
23
+ if (head) {
24
+ source = typeof head === "function" ? () => head.call(this) : head;
25
+ }
23
26
  }
24
- }
25
- source && useHead.useHead(source);
26
- }
27
- };
28
- function UnheadPlugin(head) {
29
- return {
30
- ...HeadOptions,
27
+ source && useHead.useHead(source);
28
+ },
31
29
  beforeCreate() {
32
30
  const options = this.$options;
33
- const origProvide = options.provide;
34
- options.provide = function() {
35
- let origProvideResult;
36
- if (typeof origProvide === "function")
37
- origProvideResult = origProvide.call(this);
38
- else
39
- origProvideResult = origProvide || {};
40
- return {
41
- ...origProvideResult,
42
- [useHead.headSymbol]: head
31
+ if (options.unhead) {
32
+ const origProvide = options.provide;
33
+ options.provide = function() {
34
+ let origProvideResult;
35
+ if (typeof origProvide === "function")
36
+ origProvideResult = origProvide.call(this);
37
+ else
38
+ origProvideResult = origProvide || {};
39
+ return {
40
+ ...origProvideResult,
41
+ [injectHead.headSymbol]: options.unhead
42
+ };
43
43
  };
44
- };
44
+ }
45
45
  }
46
- };
47
- }
46
+ });
47
+ };
48
48
 
49
- exports.HeadOptions = HeadOptions;
50
49
  exports.UnheadPlugin = UnheadPlugin;
package/dist/vue2.d.cts CHANGED
@@ -1,13 +1,5 @@
1
- import { V as VueHeadClient } from './shared/vue.8eef6ffc.cjs';
2
- import '@unhead/schema';
3
- import 'vue';
1
+ import { Plugin } from 'vue';
4
2
 
5
- declare const HeadOptions: {
6
- created(): void;
7
- };
8
- declare function UnheadPlugin(head: VueHeadClient<any>): {
9
- beforeCreate(): void;
10
- created(): void;
11
- };
3
+ declare const UnheadPlugin: Plugin;
12
4
 
13
- export { HeadOptions, UnheadPlugin };
5
+ export { UnheadPlugin };
package/dist/vue2.d.mts CHANGED
@@ -1,13 +1,5 @@
1
- import { V as VueHeadClient } from './shared/vue.8eef6ffc.mjs';
2
- import '@unhead/schema';
3
- import 'vue';
1
+ import { Plugin } from 'vue';
4
2
 
5
- declare const HeadOptions: {
6
- created(): void;
7
- };
8
- declare function UnheadPlugin(head: VueHeadClient<any>): {
9
- beforeCreate(): void;
10
- created(): void;
11
- };
3
+ declare const UnheadPlugin: Plugin;
12
4
 
13
- export { HeadOptions, UnheadPlugin };
5
+ export { UnheadPlugin };
package/dist/vue2.d.ts CHANGED
@@ -1,13 +1,5 @@
1
- import { V as VueHeadClient } from './shared/vue.8eef6ffc.js';
2
- import '@unhead/schema';
3
- import 'vue';
1
+ import { Plugin } from 'vue';
4
2
 
5
- declare const HeadOptions: {
6
- created(): void;
7
- };
8
- declare function UnheadPlugin(head: VueHeadClient<any>): {
9
- beforeCreate(): void;
10
- created(): void;
11
- };
3
+ declare const UnheadPlugin: Plugin;
12
4
 
13
- export { HeadOptions, UnheadPlugin };
5
+ export { UnheadPlugin };
package/dist/vue2.mjs CHANGED
@@ -1,47 +1,47 @@
1
1
  import { getCurrentInstance } from 'vue';
2
- import { V as Vue3, u as useHead, h as headSymbol } from './shared/vue.b1b42453.mjs';
2
+ import { V as Vue3, h as headSymbol } from './shared/vue.cf295fb1.mjs';
3
+ import { u as useHead } from './shared/vue.f36acd1f.mjs';
3
4
  import 'unhead';
4
5
  import '@unhead/shared';
5
6
 
6
- const HeadOptions = {
7
- created() {
8
- let source = false;
9
- if (Vue3) {
10
- const instance = getCurrentInstance();
11
- if (!instance)
12
- return;
13
- const options = instance.type;
14
- if (!options || !("head" in options))
15
- return;
16
- source = typeof options.head === "function" ? () => options.head.call(instance.proxy) : options.head;
17
- } else {
18
- const head = this.$options.head;
19
- if (head) {
20
- source = typeof head === "function" ? () => head.call(this) : head;
7
+ const UnheadPlugin = function(_Vue) {
8
+ _Vue.mixin({
9
+ created() {
10
+ let source = false;
11
+ if (Vue3) {
12
+ const instance = getCurrentInstance();
13
+ if (!instance)
14
+ return;
15
+ const options = instance.type;
16
+ if (!options || !("head" in options))
17
+ return;
18
+ source = typeof options.head === "function" ? () => options.head.call(instance.proxy) : options.head;
19
+ } else {
20
+ const head = this.$options.head;
21
+ if (head) {
22
+ source = typeof head === "function" ? () => head.call(this) : head;
23
+ }
21
24
  }
22
- }
23
- source && useHead(source);
24
- }
25
- };
26
- function UnheadPlugin(head) {
27
- return {
28
- ...HeadOptions,
25
+ source && useHead(source);
26
+ },
29
27
  beforeCreate() {
30
28
  const options = this.$options;
31
- const origProvide = options.provide;
32
- options.provide = function() {
33
- let origProvideResult;
34
- if (typeof origProvide === "function")
35
- origProvideResult = origProvide.call(this);
36
- else
37
- origProvideResult = origProvide || {};
38
- return {
39
- ...origProvideResult,
40
- [headSymbol]: head
29
+ if (options.unhead) {
30
+ const origProvide = options.provide;
31
+ options.provide = function() {
32
+ let origProvideResult;
33
+ if (typeof origProvide === "function")
34
+ origProvideResult = origProvide.call(this);
35
+ else
36
+ origProvideResult = origProvide || {};
37
+ return {
38
+ ...origProvideResult,
39
+ [headSymbol]: options.unhead
40
+ };
41
41
  };
42
- };
42
+ }
43
43
  }
44
- };
45
- }
44
+ });
45
+ };
46
46
 
47
- export { HeadOptions, UnheadPlugin };
47
+ export { UnheadPlugin };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/vue",
3
3
  "type": "module",
4
- "version": "1.6.2",
4
+ "version": "1.7.0",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -30,6 +30,11 @@
30
30
  "types": "./dist/vue2.d.ts",
31
31
  "import": "./dist/vue2.mjs",
32
32
  "require": "./dist/vue2.cjs"
33
+ },
34
+ "./components": {
35
+ "types": "./dist/components.d.ts",
36
+ "import": "./dist/components.mjs",
37
+ "require": "./dist/components.cjs"
33
38
  }
34
39
  },
35
40
  "main": "dist/index.cjs",
@@ -43,9 +48,9 @@
43
48
  },
44
49
  "dependencies": {
45
50
  "hookable": "^5.5.3",
46
- "@unhead/schema": "1.6.2",
47
- "@unhead/shared": "1.6.2",
48
- "unhead": "1.6.2"
51
+ "@unhead/schema": "1.7.0",
52
+ "@unhead/shared": "1.7.0",
53
+ "unhead": "1.7.0"
49
54
  },
50
55
  "devDependencies": {
51
56
  "vue": "^3.3.4"