@unhead/vue 2.0.0-alpha.3 → 2.0.0-alpha.31

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.
Files changed (57) hide show
  1. package/dist/client.d.mts +5 -4
  2. package/dist/client.d.ts +5 -4
  3. package/dist/client.mjs +9 -12
  4. package/dist/components.mjs +8 -6
  5. package/dist/index.d.mts +34 -17
  6. package/dist/index.d.ts +34 -17
  7. package/dist/index.mjs +13 -7
  8. package/dist/legacy.d.mts +27 -45
  9. package/dist/legacy.d.ts +27 -45
  10. package/dist/legacy.mjs +36 -93
  11. package/dist/plugins.d.mts +1 -0
  12. package/dist/plugins.d.ts +1 -0
  13. package/dist/plugins.mjs +1 -0
  14. package/dist/scripts.d.mts +32 -0
  15. package/dist/scripts.d.ts +32 -0
  16. package/dist/scripts.mjs +7 -0
  17. package/dist/server.d.mts +5 -4
  18. package/dist/server.d.ts +5 -4
  19. package/dist/server.mjs +7 -9
  20. package/dist/shared/vue.A6QPXQyg.d.ts +63 -0
  21. package/dist/shared/vue.BYLJNEcq.mjs +83 -0
  22. package/dist/shared/vue.C1egIkvG.d.mts +134 -0
  23. package/dist/shared/vue.C1egIkvG.d.ts +134 -0
  24. package/dist/shared/vue.Ds_C3mXu.d.mts +63 -0
  25. package/dist/shared/vue.N9zWjxoK.mjs +7 -0
  26. package/dist/shared/vue.cHBs6zvy.mjs +70 -0
  27. package/dist/shared/{vue.CNiRntV8.mjs → vue.nvpYXC6D.mjs} +1 -1
  28. package/dist/types.d.mts +14 -140
  29. package/dist/types.d.ts +14 -140
  30. package/dist/utils.d.mts +11 -0
  31. package/dist/utils.d.ts +11 -0
  32. package/dist/utils.mjs +10 -0
  33. package/package.json +34 -18
  34. package/plugins.d.ts +1 -0
  35. package/types.d.ts +1 -1
  36. package/utils.d.ts +1 -0
  37. package/dist/client.cjs +0 -36
  38. package/dist/client.d.cts +0 -8
  39. package/dist/components.cjs +0 -65
  40. package/dist/components.d.cts +0 -5
  41. package/dist/index.cjs +0 -26
  42. package/dist/index.d.cts +0 -28
  43. package/dist/legacy.cjs +0 -186
  44. package/dist/legacy.d.cts +0 -52
  45. package/dist/server.cjs +0 -33
  46. package/dist/server.d.cts +0 -8
  47. package/dist/shared/vue.51u-UkLG.mjs +0 -13
  48. package/dist/shared/vue.BF-HCrO8.d.cts +0 -3
  49. package/dist/shared/vue.BF-HCrO8.d.mts +0 -3
  50. package/dist/shared/vue.BF-HCrO8.d.ts +0 -3
  51. package/dist/shared/vue.Btxz9wTa.cjs +0 -126
  52. package/dist/shared/vue.D2UzSD_b.mjs +0 -115
  53. package/dist/shared/vue.DFf1FJKf.cjs +0 -20
  54. package/dist/shared/vue.DnywREVF.d.cts +0 -5
  55. package/dist/shared/vue.rzkVHzqg.cjs +0 -15
  56. package/dist/types.cjs +0 -2
  57. package/dist/types.d.cts +0 -142
@@ -1,5 +0,0 @@
1
- import { DefineComponent } from 'vue';
2
-
3
- declare const Head: DefineComponent;
4
-
5
- export { Head };
package/dist/index.cjs DELETED
@@ -1,26 +0,0 @@
1
- 'use strict';
2
-
3
- const shared = require('@unhead/shared');
4
- const unhead = require('unhead');
5
- const composables = require('./shared/vue.Btxz9wTa.cjs');
6
- const VueHeadMixin = require('./shared/vue.DFf1FJKf.cjs');
7
- require('vue');
8
-
9
- const unheadVueComposablesImports = {
10
- "@unhead/vue": ["injectHead", ...shared.composableNames]
11
- };
12
-
13
- const CapoPlugin = () => shared.defineHeadPlugin({});
14
-
15
- exports.createHeadCore = unhead.createHeadCore;
16
- exports.injectHead = composables.injectHead;
17
- exports.resolveUnrefHeadInput = composables.resolveUnrefHeadInput;
18
- exports.useHead = composables.useHead;
19
- exports.useHeadSafe = composables.useHeadSafe;
20
- exports.useSeoMeta = composables.useSeoMeta;
21
- exports.useServerHead = composables.useServerHead;
22
- exports.useServerHeadSafe = composables.useServerHeadSafe;
23
- exports.useServerSeoMeta = composables.useServerSeoMeta;
24
- exports.VueHeadMixin = VueHeadMixin.VueHeadMixin;
25
- exports.CapoPlugin = CapoPlugin;
26
- exports.unheadVueComposablesImports = unheadVueComposablesImports;
package/dist/index.d.cts DELETED
@@ -1,28 +0,0 @@
1
- import * as _unhead_schema from '@unhead/schema';
2
- import { MergeHead, ActiveHeadEntry } from '@unhead/schema';
3
- export { ActiveHeadEntry, Head, HeadEntryOptions, HeadTag, MergeHead, Unhead } from '@unhead/schema';
4
- export { createHeadCore } from 'unhead';
5
- export { r as resolveUnrefHeadInput } from './shared/vue.BF-HCrO8.cjs';
6
- import { VueHeadClient, UseHeadInput, UseHeadOptions, UseHeadSafeInput, UseSeoMetaInput } from './types.cjs';
7
- export { Base, BodyAttr, BodyAttributes, HeadSafe, HtmlAttr, HtmlAttributes, Link, MaybeComputedRef, MaybeComputedRefEntries, MaybeComputedRefEntriesOnly, MaybeComputedRefOrFalsy, MaybeComputedRefOrPromise, MaybeReadonlyRef, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate } from './types.cjs';
8
- export { V as VueHeadMixin } from './shared/vue.DnywREVF.cjs';
9
- import 'vue';
10
-
11
- declare const unheadVueComposablesImports: {
12
- '@unhead/vue': string[];
13
- };
14
-
15
- declare function injectHead(): VueHeadClient<MergeHead>;
16
- declare function useHead<T extends MergeHead>(input: UseHeadInput<T>, options?: UseHeadOptions): ActiveHeadEntry<UseHeadInput<T>>;
17
- declare function useHeadSafe(input: UseHeadSafeInput, options?: UseHeadOptions): ActiveHeadEntry<any>;
18
- declare function useSeoMeta(input: UseSeoMetaInput, options?: UseHeadOptions): ActiveHeadEntry<any>;
19
- declare function useServerHead<T extends MergeHead>(input: UseHeadInput<T>, options?: UseHeadOptions): ActiveHeadEntry<any>;
20
- declare function useServerHeadSafe(input: UseHeadSafeInput, options?: UseHeadOptions): ActiveHeadEntry<any>;
21
- declare function useServerSeoMeta(input: UseSeoMetaInput, options?: UseHeadOptions): ActiveHeadEntry<UseSeoMetaInput>;
22
-
23
- /**
24
- * @deprecated TODO remove
25
- */
26
- declare const CapoPlugin: () => _unhead_schema.HeadPluginInput;
27
-
28
- export { CapoPlugin, UseHeadInput, UseHeadOptions, UseHeadSafeInput, UseSeoMetaInput, VueHeadClient, injectHead, unheadVueComposablesImports, useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };
package/dist/legacy.cjs DELETED
@@ -1,186 +0,0 @@
1
- 'use strict';
2
-
3
- const shared = require('@unhead/shared');
4
- const unhead = require('unhead');
5
- const plugins = require('unhead/plugins');
6
- const vue = require('vue');
7
- const client = require('./client.cjs');
8
- const composables = require('./shared/vue.Btxz9wTa.cjs');
9
- const server = require('./server.cjs');
10
- const legacy = require('unhead/legacy');
11
- require('unhead/client');
12
- require('./shared/vue.rzkVHzqg.cjs');
13
- require('./shared/vue.DFf1FJKf.cjs');
14
- require('unhead/server');
15
-
16
- function registerVueScopeHandlers(script, scope) {
17
- if (!scope) {
18
- return;
19
- }
20
- const _registerCb = (key, cb) => {
21
- if (!script._cbs[key]) {
22
- cb(script.instance);
23
- return () => {
24
- };
25
- }
26
- let i = script._cbs[key].push(cb);
27
- const destroy = () => {
28
- if (i) {
29
- script._cbs[key]?.splice(i - 1, 1);
30
- i = null;
31
- }
32
- };
33
- vue.onScopeDispose(destroy);
34
- return destroy;
35
- };
36
- script.onLoaded = (cb) => _registerCb("loaded", cb);
37
- script.onError = (cb) => _registerCb("error", cb);
38
- vue.onScopeDispose(() => {
39
- script._triggerAbortController?.abort();
40
- });
41
- }
42
- function useScript(_input, _options) {
43
- const input = typeof _input === "string" ? { src: _input } : _input;
44
- const options = _options || {};
45
- const head = options?.head || injectHead();
46
- options.head = head;
47
- const scope = vue.getCurrentInstance();
48
- options.eventContext = scope;
49
- if (scope && typeof options.trigger === "undefined") {
50
- options.trigger = vue.onMounted;
51
- } else if (vue.isRef(options.trigger)) {
52
- const refTrigger = options.trigger;
53
- let off;
54
- options.trigger = new Promise((resolve) => {
55
- off = vue.watch(refTrigger, (val) => {
56
- if (val) {
57
- resolve(true);
58
- }
59
- }, {
60
- immediate: true
61
- });
62
- vue.onScopeDispose(() => resolve(false), true);
63
- }).then((val) => {
64
- off?.();
65
- return val;
66
- });
67
- }
68
- head._scriptStatusWatcher = head._scriptStatusWatcher || head.hooks.hook("script:updated", ({ script: s }) => {
69
- s._statusRef.value = s.status;
70
- });
71
- const script = legacy.useScript(input, options);
72
- script._statusRef = script._statusRef || vue.ref(script.status);
73
- registerVueScopeHandlers(script, scope);
74
- return new Proxy(script, {
75
- get(_, key, a) {
76
- return Reflect.get(_, key === "status" ? "_statusRef" : key, a);
77
- }
78
- });
79
- }
80
-
81
- const CapoPlugin = () => shared.defineHeadPlugin({});
82
- function createHead(options = {}) {
83
- return client.createHead({
84
- disableCapoSorting: true,
85
- ...options,
86
- plugins: [
87
- plugins.DeprecationsPlugin,
88
- plugins.PromisesPlugin,
89
- ...options.plugins || []
90
- ]
91
- });
92
- }
93
- function createServerHead(options = {}) {
94
- return server.createHead({
95
- disableCapoSorting: true,
96
- ...options,
97
- plugins: [
98
- plugins.DeprecationsPlugin,
99
- plugins.PromisesPlugin,
100
- ...options.plugins || []
101
- ]
102
- });
103
- }
104
- function setHeadInjectionHandler(handler) {
105
- }
106
- function injectHead() {
107
- return vue.inject(composables.headSymbol);
108
- }
109
- function useHead(input, options = {}) {
110
- const head = options.head || injectHead();
111
- if (head) {
112
- return head.ssr ? head.push(input, options) : clientUseHead(head, input, options);
113
- }
114
- }
115
- function clientUseHead(head, input, options = {}) {
116
- const deactivated = vue.ref(false);
117
- const resolvedInput = vue.ref({});
118
- vue.watchEffect(() => {
119
- resolvedInput.value = deactivated.value ? {} : composables.resolveUnrefHeadInput(input);
120
- });
121
- const entry = head.push(resolvedInput.value, options);
122
- vue.watch(resolvedInput, (e) => {
123
- entry.patch(e);
124
- });
125
- const vm = vue.getCurrentInstance();
126
- if (vm) {
127
- vue.onBeforeUnmount(() => {
128
- entry.dispose();
129
- });
130
- vue.onDeactivated(() => {
131
- deactivated.value = true;
132
- });
133
- vue.onActivated(() => {
134
- deactivated.value = false;
135
- });
136
- }
137
- return entry;
138
- }
139
- function useHeadSafe(input, options = {}) {
140
- return useHead(input, { ...options, transform: shared.whitelistSafeInput });
141
- }
142
- function useSeoMeta(input, options) {
143
- const { title, titleTemplate, ...meta } = input;
144
- return useHead({
145
- title,
146
- titleTemplate,
147
- // @ts-expect-error runtime type
148
- _flatMeta: meta
149
- }, {
150
- ...options,
151
- transform(t) {
152
- const meta2 = shared.unpackMeta({ ...t._flatMeta });
153
- delete t._flatMeta;
154
- return {
155
- // @ts-expect-error runtime type
156
- ...t,
157
- meta: meta2
158
- };
159
- }
160
- });
161
- }
162
- function useServerHead(input, options = {}) {
163
- return useHead(input, { ...options, mode: "server" });
164
- }
165
- function useServerHeadSafe(input, options = {}) {
166
- return useHeadSafe(input, { ...options, mode: "server" });
167
- }
168
- function useServerSeoMeta(input, options) {
169
- return useSeoMeta(input, { ...options, mode: "server" });
170
- }
171
-
172
- exports.createHeadCore = unhead.createHeadCore;
173
- exports.resolveUnrefHeadInput = composables.resolveUnrefHeadInput;
174
- exports.resolveScriptKey = legacy.resolveScriptKey;
175
- exports.CapoPlugin = CapoPlugin;
176
- exports.createHead = createHead;
177
- exports.createServerHead = createServerHead;
178
- exports.injectHead = injectHead;
179
- exports.setHeadInjectionHandler = setHeadInjectionHandler;
180
- exports.useHead = useHead;
181
- exports.useHeadSafe = useHeadSafe;
182
- exports.useScript = useScript;
183
- exports.useSeoMeta = useSeoMeta;
184
- exports.useServerHead = useServerHead;
185
- exports.useServerHeadSafe = useServerHeadSafe;
186
- exports.useServerSeoMeta = useServerSeoMeta;
package/dist/legacy.d.cts DELETED
@@ -1,52 +0,0 @@
1
- import * as _unhead_schema from '@unhead/schema';
2
- import { ScriptBase, DataKeys, SchemaAugmentations, HeadEntryOptions, MergeHead, CreateClientHeadOptions, ActiveHeadEntry } from '@unhead/schema';
3
- import { VueHeadClient, UseHeadInput, UseHeadOptions as UseHeadOptions$1, UseHeadSafeInput, UseSeoMetaInput } from './types.cjs';
4
- export { createHeadCore } from 'unhead';
5
- export { r as resolveUnrefHeadInput } from './shared/vue.BF-HCrO8.cjs';
6
- import { MaybeComputedRefEntriesOnly, UseHeadOptions } from '@unhead/vue';
7
- import { ScriptInstance, UseScriptStatus, UseScriptOptions as UseScriptOptions$1, UseFunctionType } from 'unhead/legacy';
8
- export { UseFunctionType, resolveScriptKey } from 'unhead/legacy';
9
- import { Ref } from 'vue';
10
-
11
- interface VueScriptInstance<T extends Record<symbol | string, any>> extends Omit<ScriptInstance<T>, 'status'> {
12
- status: Ref<UseScriptStatus>;
13
- }
14
- type UseScriptInput = string | (MaybeComputedRefEntriesOnly<Omit<ScriptBase & DataKeys & SchemaAugmentations['script'], 'src'>> & {
15
- src: string;
16
- });
17
- interface UseScriptOptions<T extends Record<symbol | string, any> = Record<string, any>> extends Omit<HeadEntryOptions, 'head'>, Pick<UseScriptOptions$1<T>, 'use' | 'eventContext' | 'beforeInit'> {
18
- /**
19
- * The trigger to load the script:
20
- * - `undefined` | `client` - (Default) Load the script on the client when this js is loaded.
21
- * - `manual` - Load the script manually by calling `$script.load()`, exists only on the client.
22
- * - `Promise` - Load the script when the promise resolves, exists only on the client.
23
- * - `Function` - Register a callback function to load the script, exists only on the client.
24
- * - `server` - Have the script injected on the server.
25
- * - `ref` - Load the script when the ref is true.
26
- */
27
- trigger?: UseScriptOptions$1['trigger'] | Ref<boolean>;
28
- /**
29
- * The Unhead instance to use.
30
- */
31
- head?: UseHeadOptions['head'];
32
- }
33
- type UseScriptContext<T extends Record<symbol | string, any>> = Promise<T> & VueScriptInstance<T>;
34
- type UseScriptReturn<T extends Record<symbol | string, any>> = UseScriptContext<UseFunctionType<UseScriptOptions<T>, T>>;
35
- declare function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>>(_input: UseScriptInput, _options?: UseScriptOptions<T>): UseScriptReturn<T>;
36
-
37
- declare const CapoPlugin: () => _unhead_schema.HeadPluginInput;
38
- declare function createHead<T extends MergeHead>(options?: CreateClientHeadOptions): VueHeadClient<T>;
39
- declare function createServerHead<T extends MergeHead>(options?: CreateClientHeadOptions): VueHeadClient<T>;
40
- /**
41
- * @deprecated Please switch to non-legacy version
42
- */
43
- declare function setHeadInjectionHandler(handler: () => VueHeadClient<any> | undefined): void;
44
- declare function injectHead(): VueHeadClient<any> | undefined;
45
- declare function useHead<T extends MergeHead>(input: UseHeadInput<T>, options?: UseHeadOptions$1): ActiveHeadEntry<UseHeadInput<T>> | void;
46
- declare function useHeadSafe(input: UseHeadSafeInput, options?: UseHeadOptions$1): ActiveHeadEntry<UseHeadSafeInput> | void;
47
- declare function useSeoMeta(input: UseSeoMetaInput, options?: UseHeadOptions$1): ActiveHeadEntry<any> | void;
48
- declare function useServerHead<T extends MergeHead>(input: UseHeadInput<T>, options?: UseHeadOptions$1): ActiveHeadEntry<any> | void;
49
- declare function useServerHeadSafe(input: UseHeadSafeInput, options?: UseHeadOptions$1): ActiveHeadEntry<any> | void;
50
- declare function useServerSeoMeta(input: UseSeoMetaInput, options?: UseHeadOptions$1): ActiveHeadEntry<any> | void;
51
-
52
- export { CapoPlugin, type UseScriptContext, type UseScriptInput, type UseScriptOptions, type UseScriptReturn, type VueScriptInstance, createHead, createServerHead, injectHead, setHeadInjectionHandler, useHead, useHeadSafe, useScript, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };
package/dist/server.cjs DELETED
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- const server = require('unhead/server');
4
- const composables = require('./shared/vue.Btxz9wTa.cjs');
5
- const VueReactivityPlugin = require('./shared/vue.rzkVHzqg.cjs');
6
- const VueHeadMixin = require('./shared/vue.DFf1FJKf.cjs');
7
- require('@unhead/shared');
8
- require('vue');
9
-
10
- function createHead(options = {}) {
11
- const head = server.createHead({
12
- ...options,
13
- plugins: [
14
- ...options.plugins || [],
15
- VueReactivityPlugin.VueReactivityPlugin
16
- ]
17
- });
18
- head.install = composables.vueInstall(head);
19
- return head;
20
- }
21
-
22
- exports.VueHeadMixin = VueHeadMixin.VueHeadMixin;
23
- exports.createHead = createHead;
24
- Object.prototype.hasOwnProperty.call(server, '__proto__') &&
25
- !Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
26
- Object.defineProperty(exports, '__proto__', {
27
- enumerable: true,
28
- value: server['__proto__']
29
- });
30
-
31
- Object.keys(server).forEach(function (k) {
32
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = server[k];
33
- });
package/dist/server.d.cts DELETED
@@ -1,8 +0,0 @@
1
- import { MergeHead, CreateHeadOptions } from '@unhead/schema';
2
- import { VueHeadClient } from '@unhead/vue';
3
- export { V as VueHeadMixin } from './shared/vue.DnywREVF.cjs';
4
- export * from 'unhead/server';
5
-
6
- declare function createHead<T extends MergeHead>(options?: Omit<CreateHeadOptions, 'domDelayFn' | 'document'>): VueHeadClient<T>;
7
-
8
- export { createHead };
@@ -1,13 +0,0 @@
1
- import { defineHeadPlugin } from '@unhead/shared';
2
- import { r as resolveUnrefHeadInput } from './vue.D2UzSD_b.mjs';
3
-
4
- const VueReactivityPlugin = defineHeadPlugin({
5
- hooks: {
6
- "entries:resolve": (ctx) => {
7
- for (const entry of ctx.entries)
8
- entry.resolvedInput = resolveUnrefHeadInput(entry.input);
9
- }
10
- }
11
- });
12
-
13
- export { VueReactivityPlugin as V };
@@ -1,3 +0,0 @@
1
- declare function resolveUnrefHeadInput(ref: any): any;
2
-
3
- export { resolveUnrefHeadInput as r };
@@ -1,3 +0,0 @@
1
- declare function resolveUnrefHeadInput(ref: any): any;
2
-
3
- export { resolveUnrefHeadInput as r };
@@ -1,3 +0,0 @@
1
- declare function resolveUnrefHeadInput(ref: any): any;
2
-
3
- export { resolveUnrefHeadInput as r };
@@ -1,126 +0,0 @@
1
- 'use strict';
2
-
3
- const shared = require('@unhead/shared');
4
- const vue = require('vue');
5
-
6
- function resolveUnref(r) {
7
- return typeof r === "function" ? r() : vue.unref(r);
8
- }
9
- function resolveUnrefHeadInput(ref) {
10
- if (ref instanceof Promise || ref instanceof Date || ref instanceof RegExp)
11
- return ref;
12
- const root = resolveUnref(ref);
13
- if (!ref || !root)
14
- return root;
15
- if (Array.isArray(root))
16
- return root.map((r) => resolveUnrefHeadInput(r));
17
- if (typeof root === "object") {
18
- const resolved = {};
19
- for (const k in root) {
20
- if (!Object.prototype.hasOwnProperty.call(root, k)) {
21
- continue;
22
- }
23
- if (k === "titleTemplate" || k[0] === "o" && k[1] === "n") {
24
- resolved[k] = vue.unref(root[k]);
25
- continue;
26
- }
27
- resolved[k] = resolveUnrefHeadInput(root[k]);
28
- }
29
- return resolved;
30
- }
31
- return root;
32
- }
33
-
34
- const headSymbol = "usehead";
35
- function vueInstall(head) {
36
- const plugin = {
37
- install(app) {
38
- app.config.globalProperties.$unhead = head;
39
- app.config.globalProperties.$head = head;
40
- app.provide(headSymbol, head);
41
- }
42
- };
43
- return plugin.install;
44
- }
45
-
46
- function injectHead() {
47
- if (vue.hasInjectionContext()) {
48
- const instance = vue.inject(headSymbol);
49
- if (!instance) {
50
- throw new Error("useHead() was called without provide context, ensure you call it through the setup() function.");
51
- }
52
- return instance;
53
- }
54
- throw new Error("useHead() was called without provide context, ensure you call it through the setup() function.");
55
- }
56
- function useHead(input, options = {}) {
57
- const head = options.head || injectHead();
58
- return head.ssr ? head.push(input, options) : clientUseHead(head, input, options);
59
- }
60
- function clientUseHead(head, input, options = {}) {
61
- const deactivated = vue.ref(false);
62
- const resolvedInput = vue.ref({});
63
- vue.watchEffect(() => {
64
- resolvedInput.value = deactivated.value ? {} : resolveUnrefHeadInput(input);
65
- });
66
- const entry = head.push(resolvedInput.value, options);
67
- vue.watch(resolvedInput, (e) => {
68
- entry.patch(e);
69
- });
70
- const vm = vue.getCurrentInstance();
71
- if (vm) {
72
- vue.onBeforeUnmount(() => {
73
- entry.dispose();
74
- });
75
- vue.onDeactivated(() => {
76
- deactivated.value = true;
77
- });
78
- vue.onActivated(() => {
79
- deactivated.value = false;
80
- });
81
- }
82
- return entry;
83
- }
84
- function useHeadSafe(input, options = {}) {
85
- return useHead(input, { ...options, transform: shared.whitelistSafeInput });
86
- }
87
- function useSeoMeta(input, options) {
88
- const { title, titleTemplate, ...meta } = input;
89
- return useHead({
90
- title,
91
- titleTemplate,
92
- // @ts-expect-error runtime type
93
- _flatMeta: meta
94
- }, {
95
- ...options,
96
- transform(t) {
97
- const meta2 = shared.unpackMeta({ ...t._flatMeta });
98
- delete t._flatMeta;
99
- return {
100
- // @ts-expect-error runtime type
101
- ...t,
102
- meta: meta2
103
- };
104
- }
105
- });
106
- }
107
- function useServerHead(input, options = {}) {
108
- return useHead(input, { ...options, mode: "server" });
109
- }
110
- function useServerHeadSafe(input, options = {}) {
111
- return useHeadSafe(input, { ...options, mode: "server" });
112
- }
113
- function useServerSeoMeta(input, options) {
114
- return useSeoMeta(input, { ...options, mode: "server" });
115
- }
116
-
117
- exports.headSymbol = headSymbol;
118
- exports.injectHead = injectHead;
119
- exports.resolveUnrefHeadInput = resolveUnrefHeadInput;
120
- exports.useHead = useHead;
121
- exports.useHeadSafe = useHeadSafe;
122
- exports.useSeoMeta = useSeoMeta;
123
- exports.useServerHead = useServerHead;
124
- exports.useServerHeadSafe = useServerHeadSafe;
125
- exports.useServerSeoMeta = useServerSeoMeta;
126
- exports.vueInstall = vueInstall;
@@ -1,115 +0,0 @@
1
- import { whitelistSafeInput, unpackMeta } from '@unhead/shared';
2
- import { unref, hasInjectionContext, inject, ref, watchEffect, watch, getCurrentInstance, onBeforeUnmount, onDeactivated, onActivated } from 'vue';
3
-
4
- function resolveUnref(r) {
5
- return typeof r === "function" ? r() : unref(r);
6
- }
7
- function resolveUnrefHeadInput(ref) {
8
- if (ref instanceof Promise || ref instanceof Date || ref instanceof RegExp)
9
- return ref;
10
- const root = resolveUnref(ref);
11
- if (!ref || !root)
12
- return root;
13
- if (Array.isArray(root))
14
- return root.map((r) => resolveUnrefHeadInput(r));
15
- if (typeof root === "object") {
16
- const resolved = {};
17
- for (const k in root) {
18
- if (!Object.prototype.hasOwnProperty.call(root, k)) {
19
- continue;
20
- }
21
- if (k === "titleTemplate" || k[0] === "o" && k[1] === "n") {
22
- resolved[k] = unref(root[k]);
23
- continue;
24
- }
25
- resolved[k] = resolveUnrefHeadInput(root[k]);
26
- }
27
- return resolved;
28
- }
29
- return root;
30
- }
31
-
32
- const headSymbol = "usehead";
33
- function vueInstall(head) {
34
- const plugin = {
35
- install(app) {
36
- app.config.globalProperties.$unhead = head;
37
- app.config.globalProperties.$head = head;
38
- app.provide(headSymbol, head);
39
- }
40
- };
41
- return plugin.install;
42
- }
43
-
44
- function injectHead() {
45
- if (hasInjectionContext()) {
46
- const instance = inject(headSymbol);
47
- if (!instance) {
48
- throw new Error("useHead() was called without provide context, ensure you call it through the setup() function.");
49
- }
50
- return instance;
51
- }
52
- throw new Error("useHead() was called without provide context, ensure you call it through the setup() function.");
53
- }
54
- function useHead(input, options = {}) {
55
- const head = options.head || injectHead();
56
- return head.ssr ? head.push(input, options) : clientUseHead(head, input, options);
57
- }
58
- function clientUseHead(head, input, options = {}) {
59
- const deactivated = ref(false);
60
- const resolvedInput = ref({});
61
- watchEffect(() => {
62
- resolvedInput.value = deactivated.value ? {} : resolveUnrefHeadInput(input);
63
- });
64
- const entry = head.push(resolvedInput.value, options);
65
- watch(resolvedInput, (e) => {
66
- entry.patch(e);
67
- });
68
- const vm = getCurrentInstance();
69
- if (vm) {
70
- onBeforeUnmount(() => {
71
- entry.dispose();
72
- });
73
- onDeactivated(() => {
74
- deactivated.value = true;
75
- });
76
- onActivated(() => {
77
- deactivated.value = false;
78
- });
79
- }
80
- return entry;
81
- }
82
- function useHeadSafe(input, options = {}) {
83
- return useHead(input, { ...options, transform: whitelistSafeInput });
84
- }
85
- function useSeoMeta(input, options) {
86
- const { title, titleTemplate, ...meta } = input;
87
- return useHead({
88
- title,
89
- titleTemplate,
90
- // @ts-expect-error runtime type
91
- _flatMeta: meta
92
- }, {
93
- ...options,
94
- transform(t) {
95
- const meta2 = unpackMeta({ ...t._flatMeta });
96
- delete t._flatMeta;
97
- return {
98
- // @ts-expect-error runtime type
99
- ...t,
100
- meta: meta2
101
- };
102
- }
103
- });
104
- }
105
- function useServerHead(input, options = {}) {
106
- return useHead(input, { ...options, mode: "server" });
107
- }
108
- function useServerHeadSafe(input, options = {}) {
109
- return useHeadSafe(input, { ...options, mode: "server" });
110
- }
111
- function useServerSeoMeta(input, options) {
112
- return useSeoMeta(input, { ...options, mode: "server" });
113
- }
114
-
115
- export { useHeadSafe as a, useSeoMeta as b, useServerHead as c, useServerHeadSafe as d, useServerSeoMeta as e, headSymbol as h, injectHead as i, resolveUnrefHeadInput as r, useHead as u, vueInstall as v };
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- const vue = require('vue');
4
- const composables = require('./vue.Btxz9wTa.cjs');
5
-
6
- const VueHeadMixin = {
7
- created() {
8
- let source = false;
9
- const instance = vue.getCurrentInstance();
10
- if (!instance)
11
- return;
12
- const options = instance.type;
13
- if (!options || !("head" in options))
14
- return;
15
- source = typeof options.head === "function" ? () => options.head.call(instance.proxy) : options.head;
16
- source && composables.useHead(source);
17
- }
18
- };
19
-
20
- exports.VueHeadMixin = VueHeadMixin;
@@ -1,5 +0,0 @@
1
- declare const VueHeadMixin: {
2
- created(): void;
3
- };
4
-
5
- export { VueHeadMixin as V };
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- const shared = require('@unhead/shared');
4
- const composables = require('./vue.Btxz9wTa.cjs');
5
-
6
- const VueReactivityPlugin = shared.defineHeadPlugin({
7
- hooks: {
8
- "entries:resolve": (ctx) => {
9
- for (const entry of ctx.entries)
10
- entry.resolvedInput = composables.resolveUnrefHeadInput(entry.input);
11
- }
12
- }
13
- });
14
-
15
- exports.VueReactivityPlugin = VueReactivityPlugin;
package/dist/types.cjs DELETED
@@ -1,2 +0,0 @@
1
- 'use strict';
2
-