unhead 2.0.0-alpha.16 → 2.0.0-alpha.18
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/client.d.mts +2 -3
- package/dist/client.d.ts +2 -3
- package/dist/client.mjs +10 -9
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +8 -6
- package/dist/legacy.d.mts +4 -99
- package/dist/legacy.d.ts +4 -99
- package/dist/legacy.mjs +11 -235
- package/dist/plugins.d.mts +13 -10
- package/dist/plugins.d.ts +13 -10
- package/dist/plugins.mjs +8 -6
- package/dist/scripts.d.mts +8 -0
- package/dist/scripts.d.ts +8 -0
- package/dist/scripts.mjs +30 -0
- package/dist/server.d.mts +2 -3
- package/dist/server.d.ts +2 -3
- package/dist/server.mjs +8 -7
- package/dist/shared/{unhead.nHwoOBDy.mjs → unhead.9Qw6eOEM.mjs} +4 -4
- package/dist/shared/unhead.B-rJEnx9.d.mts +10 -0
- package/dist/shared/{unhead.C45sZTyS.d.mts → unhead.B_YMvzY6.d.mts} +110 -1
- package/dist/shared/{unhead.C45sZTyS.d.ts → unhead.B_YMvzY6.d.ts} +110 -1
- package/dist/shared/unhead.C2emW6l4.mjs +32 -0
- package/dist/shared/unhead.CG0hxuzW.mjs +265 -0
- package/dist/shared/unhead.Cd1JiNI3.d.mts +59 -0
- package/dist/shared/{unhead.Cixots_n.mjs → unhead.CnbCxOp9.mjs} +3 -3
- package/dist/shared/{unhead.oUj3qANc.mjs → unhead.DFwCX-QT.mjs} +5 -9
- package/dist/shared/{unhead.BX2ITVEM.mjs → unhead.DZbvapt-.mjs} +1 -38
- package/dist/shared/unhead.Da77tn0u.d.ts +59 -0
- package/dist/shared/unhead.DsucyNhv.d.ts +10 -0
- package/dist/shared/{unhead.dac5MmID.mjs → unhead.x5NJGkxU.mjs} +4 -3
- package/dist/shared/{unhead.CGUU1vXi.mjs → unhead.xsi8MZXD.mjs} +5 -5
- package/dist/shared/unhead.yem5I2v_.mjs +38 -0
- package/dist/shared/{unhead.cW6GzjRO.mjs → unhead.z5bPaiJg.mjs} +6 -2
- package/dist/types.d.mts +4 -62
- package/dist/types.d.ts +4 -62
- package/dist/utils.d.mts +3 -6
- package/dist/utils.d.ts +3 -6
- package/dist/utils.mjs +5 -4
- package/package.json +11 -3
- package/scripts.d.ts +1 -0
- package/dist/shared/unhead.BDJ47PJE.mjs +0 -21
package/dist/client.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { a as Head, b as CreateClientHeadOptions, U as Unhead, R as RenderDomHeadOptions } from './shared/unhead.C45sZTyS.mjs';
|
|
1
|
+
import { am as Head, n as CreateClientHeadOptions, p as Unhead, z as RenderDomHeadOptions } from './shared/unhead.B_YMvzY6.mjs';
|
|
3
2
|
import 'hookable';
|
|
4
3
|
|
|
5
|
-
declare function createHead<T = Head>(options?: CreateClientHeadOptions):
|
|
4
|
+
declare function createHead<T = Head>(options?: CreateClientHeadOptions): Unhead<T>;
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Render the head tags to the DOM.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { a as Head, b as CreateClientHeadOptions, U as Unhead, R as RenderDomHeadOptions } from './shared/unhead.C45sZTyS.js';
|
|
1
|
+
import { am as Head, n as CreateClientHeadOptions, p as Unhead, z as RenderDomHeadOptions } from './shared/unhead.B_YMvzY6.js';
|
|
3
2
|
import 'hookable';
|
|
4
3
|
|
|
5
|
-
declare function createHead<T = Head>(options?: CreateClientHeadOptions):
|
|
4
|
+
declare function createHead<T = Head>(options?: CreateClientHeadOptions): Unhead<T>;
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Render the head tags to the DOM.
|
package/dist/client.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { c as createHeadCore } from './shared/unhead.
|
|
2
|
-
import { H as HasElementTags } from './shared/unhead.
|
|
3
|
-
import { h as hashTag, i as isMetaArrayDupeKey, a as normalizeProps, d as dedupeKey } from './shared/unhead.
|
|
1
|
+
import { c as createHeadCore } from './shared/unhead.x5NJGkxU.mjs';
|
|
2
|
+
import { H as HasElementTags } from './shared/unhead.yem5I2v_.mjs';
|
|
3
|
+
import { h as hashTag, i as isMetaArrayDupeKey, a as normalizeProps, d as dedupeKey } from './shared/unhead.xsi8MZXD.mjs';
|
|
4
4
|
import 'hookable';
|
|
5
|
+
import './shared/unhead.DZbvapt-.mjs';
|
|
5
6
|
|
|
6
7
|
async function renderDOMHead(head, options = {}) {
|
|
7
8
|
const dom = options.document || head.resolvedOptions.document;
|
|
@@ -53,7 +54,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
53
54
|
return props;
|
|
54
55
|
}, {}) || {}
|
|
55
56
|
});
|
|
56
|
-
next.key = c.getAttribute("data-hid") ||
|
|
57
|
+
next.key = c.getAttribute("data-hid") || void 0;
|
|
57
58
|
next._d = dedupeKey(next) || hashTag(next);
|
|
58
59
|
if (state.elMap.has(next._d)) {
|
|
59
60
|
let count = 1;
|
|
@@ -137,9 +138,9 @@ async function renderDOMHead(head, options = {}) {
|
|
|
137
138
|
}
|
|
138
139
|
const pending = [];
|
|
139
140
|
const frag = {
|
|
140
|
-
bodyClose:
|
|
141
|
-
bodyOpen:
|
|
142
|
-
head:
|
|
141
|
+
bodyClose: void 0,
|
|
142
|
+
bodyOpen: void 0,
|
|
143
|
+
head: void 0
|
|
143
144
|
};
|
|
144
145
|
const tags = await resolveTagPromise;
|
|
145
146
|
for (const ctx of tags) {
|
|
@@ -176,7 +177,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
176
177
|
await head.hooks.callHook("dom:rendered", { renders: tags });
|
|
177
178
|
resolve();
|
|
178
179
|
}).finally(() => {
|
|
179
|
-
head._domUpdatePromise =
|
|
180
|
+
head._domUpdatePromise = void 0;
|
|
180
181
|
head.dirty = false;
|
|
181
182
|
});
|
|
182
183
|
return head._domUpdatePromise;
|
|
@@ -184,7 +185,7 @@ async function renderDOMHead(head, options = {}) {
|
|
|
184
185
|
|
|
185
186
|
function createHead(options = {}) {
|
|
186
187
|
const head = createHeadCore({
|
|
187
|
-
document: typeof window !== "undefined" ? document :
|
|
188
|
+
document: typeof window !== "undefined" ? document : void 0,
|
|
188
189
|
...options
|
|
189
190
|
});
|
|
190
191
|
const initialPayload = head.resolvedOptions.document?.head.querySelector('script[id="unhead:payload"]')?.innerHTML || false;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { H as HeadSafe } from './shared/unhead.Cd1JiNI3.mjs';
|
|
2
|
+
import { p as Unhead, o as HeadEntryOptions, l as ActiveHeadEntry, ao as UseSeoMetaInput, am as Head, C as CreateHeadOptions } from './shared/unhead.B_YMvzY6.mjs';
|
|
3
|
+
export { u as useScript } from './shared/unhead.B-rJEnx9.mjs';
|
|
3
4
|
import 'hookable';
|
|
4
5
|
|
|
5
|
-
declare function useHead<T extends Unhead<any>>(unhead: T, input
|
|
6
|
-
declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input
|
|
7
|
-
declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input
|
|
6
|
+
declare function useHead<T extends Unhead<any>>(unhead: T, input?: Parameters<T['push']>[0], options?: HeadEntryOptions): ReturnType<T['push']>;
|
|
7
|
+
declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
|
|
8
|
+
declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<UseSeoMetaInput>;
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Creates a core instance of unhead. Does not provide a global ctx for composables to work
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { H as HeadSafe } from './shared/unhead.Da77tn0u.js';
|
|
2
|
+
import { p as Unhead, o as HeadEntryOptions, l as ActiveHeadEntry, ao as UseSeoMetaInput, am as Head, C as CreateHeadOptions } from './shared/unhead.B_YMvzY6.js';
|
|
3
|
+
export { u as useScript } from './shared/unhead.DsucyNhv.js';
|
|
3
4
|
import 'hookable';
|
|
4
5
|
|
|
5
|
-
declare function useHead<T extends Unhead<any>>(unhead: T, input
|
|
6
|
-
declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input
|
|
7
|
-
declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input
|
|
6
|
+
declare function useHead<T extends Unhead<any>>(unhead: T, input?: Parameters<T['push']>[0], options?: HeadEntryOptions): ReturnType<T['push']>;
|
|
7
|
+
declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
|
|
8
|
+
declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<UseSeoMetaInput>;
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Creates a core instance of unhead. Does not provide a global ctx for composables to work
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export { u as useHead, a as useHeadSafe, b as useSeoMeta } from './shared/unhead.
|
|
2
|
-
export { c as createHeadCore } from './shared/unhead.
|
|
3
|
-
|
|
4
|
-
import './shared/unhead.
|
|
5
|
-
import './shared/unhead.
|
|
1
|
+
export { u as useHead, a as useHeadSafe, b as useSeoMeta } from './shared/unhead.C2emW6l4.mjs';
|
|
2
|
+
export { c as createHeadCore } from './shared/unhead.x5NJGkxU.mjs';
|
|
3
|
+
export { u as useScript } from './shared/unhead.CG0hxuzW.mjs';
|
|
4
|
+
import './shared/unhead.z5bPaiJg.mjs';
|
|
5
|
+
import './shared/unhead.DFwCX-QT.mjs';
|
|
6
|
+
import './shared/unhead.yem5I2v_.mjs';
|
|
6
7
|
import 'hookable';
|
|
7
|
-
import './shared/unhead.
|
|
8
|
+
import './shared/unhead.xsi8MZXD.mjs';
|
|
9
|
+
import './shared/unhead.DZbvapt-.mjs';
|
package/dist/legacy.d.mts
CHANGED
|
@@ -1,109 +1,14 @@
|
|
|
1
1
|
export { createHeadCore, useHead, useHeadSafe, useSeoMeta } from './index.mjs';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { p as Unhead, am as Head, C as CreateHeadOptions } from './shared/unhead.B_YMvzY6.mjs';
|
|
3
|
+
export { u as useScript } from './shared/unhead.B-rJEnx9.mjs';
|
|
4
|
+
import './shared/unhead.Cd1JiNI3.mjs';
|
|
4
5
|
import 'hookable';
|
|
5
6
|
|
|
6
|
-
type UseScriptInput = string | (Omit<Script, 'src'> & {
|
|
7
|
-
src: string;
|
|
8
|
-
});
|
|
9
|
-
type UseScriptResolvedInput = Omit<Script, 'src'> & {
|
|
10
|
-
src: string;
|
|
11
|
-
};
|
|
12
|
-
declare function resolveScriptKey(input: UseScriptResolvedInput): any;
|
|
13
|
-
type UseScriptStatus = 'awaitingLoad' | 'loading' | 'loaded' | 'error' | 'removed';
|
|
14
|
-
interface ScriptInstance<T extends BaseScriptApi> {
|
|
15
|
-
proxy: AsAsyncFunctionValues<T>;
|
|
16
|
-
instance?: T;
|
|
17
|
-
id: string;
|
|
18
|
-
status: UseScriptStatus;
|
|
19
|
-
entry?: ActiveHeadEntry<any>;
|
|
20
|
-
load: () => Promise<T>;
|
|
21
|
-
remove: () => boolean;
|
|
22
|
-
setupTriggerHandler: (trigger: UseScriptOptions['trigger']) => void;
|
|
23
|
-
onLoaded: (fn: (instance: T) => void | Promise<void>) => void;
|
|
24
|
-
onError: (fn: (err?: Error) => void | Promise<void>) => void;
|
|
25
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
_triggerAbortController?: AbortController | null;
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
_triggerAbortPromise?: Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
_triggerPromises?: Promise<void>[];
|
|
37
|
-
/**
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
_cbs: {
|
|
41
|
-
loaded: null | ((instance: T) => void | Promise<void>)[];
|
|
42
|
-
error: null | ((err?: Error) => void | Promise<void>)[];
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
interface UseScriptOptions<T extends BaseScriptApi = Record<string, any>> extends HeadEntryOptions {
|
|
46
|
-
/**
|
|
47
|
-
* Resolve the script instance from the window.
|
|
48
|
-
*/
|
|
49
|
-
use?: () => T | undefined | null;
|
|
50
|
-
/**
|
|
51
|
-
* Stub the script instance. Useful for SSR or testing.
|
|
52
|
-
*/
|
|
53
|
-
stub?: ((ctx: {
|
|
54
|
-
script: ScriptInstance<T>;
|
|
55
|
-
fn: string | symbol;
|
|
56
|
-
}) => any);
|
|
57
|
-
/**
|
|
58
|
-
* The trigger to load the script:
|
|
59
|
-
* - `undefined` | `client` - (Default) Load the script on the client when this js is loaded.
|
|
60
|
-
* - `manual` - Load the script manually by calling `$script.load()`, exists only on the client.
|
|
61
|
-
* - `Promise` - Load the script when the promise resolves, exists only on the client.
|
|
62
|
-
* - `Function` - Register a callback function to load the script, exists only on the client.
|
|
63
|
-
* - `server` - Have the script injected on the server.
|
|
64
|
-
*/
|
|
65
|
-
trigger?: 'client' | 'server' | 'manual' | Promise<boolean | void> | ((fn: any) => any) | null;
|
|
66
|
-
/**
|
|
67
|
-
* Context to run events with. This is useful in Vue to attach the current instance context before
|
|
68
|
-
* calling the event, allowing the event to be reactive.
|
|
69
|
-
*/
|
|
70
|
-
eventContext?: any;
|
|
71
|
-
/**
|
|
72
|
-
* Called before the script is initialized. Will not be triggered when the script is already loaded. This means
|
|
73
|
-
* this is guaranteed to be called only once, unless the script is removed and re-added.
|
|
74
|
-
*/
|
|
75
|
-
beforeInit?: () => void;
|
|
76
|
-
}
|
|
77
|
-
type BaseScriptApi = Record<symbol | string, any>;
|
|
78
|
-
type AsAsyncFunctionValues<T extends BaseScriptApi> = {
|
|
79
|
-
[key in keyof T]: T[key] extends any[] ? T[key] : T[key] extends (...args: infer A) => infer R ? (...args: A) => R extends Promise<any> ? R : Promise<R> : T[key] extends Record<any, any> ? AsAsyncFunctionValues<T[key]> : never;
|
|
80
|
-
};
|
|
81
|
-
type UseScriptContext<T extends Record<symbol | string, any>> = (Promise<T> & ScriptInstance<T>) & AsAsyncFunctionValues<T> & {
|
|
82
|
-
/**
|
|
83
|
-
* @deprecated Use top-level functions instead.
|
|
84
|
-
*/
|
|
85
|
-
$script: Promise<T> & ScriptInstance<T>;
|
|
86
|
-
};
|
|
87
|
-
type UseFunctionType<T, U> = T extends {
|
|
88
|
-
use: infer V;
|
|
89
|
-
} ? V extends (...args: any) => any ? ReturnType<V> : U : U;
|
|
90
|
-
/**
|
|
91
|
-
* Load third-party scripts with SSR support and a proxied API.
|
|
92
|
-
*
|
|
93
|
-
* @see https://unhead.unjs.io/usage/composables/use-script
|
|
94
|
-
*/
|
|
95
|
-
declare function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>>(_input: UseScriptInput, _options?: UseScriptOptions<T>): UseScriptContext<UseFunctionType<UseScriptOptions<T>, T>>;
|
|
96
|
-
|
|
97
7
|
declare const activeHead: {
|
|
98
8
|
value: Unhead<any> | null;
|
|
99
9
|
};
|
|
100
10
|
declare function getActiveHead(): Unhead<any> | null;
|
|
101
|
-
declare const unheadComposablesImports: {
|
|
102
|
-
from: string;
|
|
103
|
-
imports: string[];
|
|
104
|
-
}[];
|
|
105
|
-
declare const composableNames: string[];
|
|
106
11
|
declare function createServerHead<T extends Record<string, any> = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
107
12
|
declare function createHead<T extends Record<string, any> = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
108
13
|
|
|
109
|
-
export {
|
|
14
|
+
export { activeHead, createHead, createServerHead, getActiveHead };
|
package/dist/legacy.d.ts
CHANGED
|
@@ -1,109 +1,14 @@
|
|
|
1
1
|
export { createHeadCore, useHead, useHeadSafe, useSeoMeta } from './index.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { p as Unhead, am as Head, C as CreateHeadOptions } from './shared/unhead.B_YMvzY6.js';
|
|
3
|
+
export { u as useScript } from './shared/unhead.DsucyNhv.js';
|
|
4
|
+
import './shared/unhead.Da77tn0u.js';
|
|
4
5
|
import 'hookable';
|
|
5
6
|
|
|
6
|
-
type UseScriptInput = string | (Omit<Script, 'src'> & {
|
|
7
|
-
src: string;
|
|
8
|
-
});
|
|
9
|
-
type UseScriptResolvedInput = Omit<Script, 'src'> & {
|
|
10
|
-
src: string;
|
|
11
|
-
};
|
|
12
|
-
declare function resolveScriptKey(input: UseScriptResolvedInput): any;
|
|
13
|
-
type UseScriptStatus = 'awaitingLoad' | 'loading' | 'loaded' | 'error' | 'removed';
|
|
14
|
-
interface ScriptInstance<T extends BaseScriptApi> {
|
|
15
|
-
proxy: AsAsyncFunctionValues<T>;
|
|
16
|
-
instance?: T;
|
|
17
|
-
id: string;
|
|
18
|
-
status: UseScriptStatus;
|
|
19
|
-
entry?: ActiveHeadEntry<any>;
|
|
20
|
-
load: () => Promise<T>;
|
|
21
|
-
remove: () => boolean;
|
|
22
|
-
setupTriggerHandler: (trigger: UseScriptOptions['trigger']) => void;
|
|
23
|
-
onLoaded: (fn: (instance: T) => void | Promise<void>) => void;
|
|
24
|
-
onError: (fn: (err?: Error) => void | Promise<void>) => void;
|
|
25
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
_triggerAbortController?: AbortController | null;
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
_triggerAbortPromise?: Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
_triggerPromises?: Promise<void>[];
|
|
37
|
-
/**
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
_cbs: {
|
|
41
|
-
loaded: null | ((instance: T) => void | Promise<void>)[];
|
|
42
|
-
error: null | ((err?: Error) => void | Promise<void>)[];
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
interface UseScriptOptions<T extends BaseScriptApi = Record<string, any>> extends HeadEntryOptions {
|
|
46
|
-
/**
|
|
47
|
-
* Resolve the script instance from the window.
|
|
48
|
-
*/
|
|
49
|
-
use?: () => T | undefined | null;
|
|
50
|
-
/**
|
|
51
|
-
* Stub the script instance. Useful for SSR or testing.
|
|
52
|
-
*/
|
|
53
|
-
stub?: ((ctx: {
|
|
54
|
-
script: ScriptInstance<T>;
|
|
55
|
-
fn: string | symbol;
|
|
56
|
-
}) => any);
|
|
57
|
-
/**
|
|
58
|
-
* The trigger to load the script:
|
|
59
|
-
* - `undefined` | `client` - (Default) Load the script on the client when this js is loaded.
|
|
60
|
-
* - `manual` - Load the script manually by calling `$script.load()`, exists only on the client.
|
|
61
|
-
* - `Promise` - Load the script when the promise resolves, exists only on the client.
|
|
62
|
-
* - `Function` - Register a callback function to load the script, exists only on the client.
|
|
63
|
-
* - `server` - Have the script injected on the server.
|
|
64
|
-
*/
|
|
65
|
-
trigger?: 'client' | 'server' | 'manual' | Promise<boolean | void> | ((fn: any) => any) | null;
|
|
66
|
-
/**
|
|
67
|
-
* Context to run events with. This is useful in Vue to attach the current instance context before
|
|
68
|
-
* calling the event, allowing the event to be reactive.
|
|
69
|
-
*/
|
|
70
|
-
eventContext?: any;
|
|
71
|
-
/**
|
|
72
|
-
* Called before the script is initialized. Will not be triggered when the script is already loaded. This means
|
|
73
|
-
* this is guaranteed to be called only once, unless the script is removed and re-added.
|
|
74
|
-
*/
|
|
75
|
-
beforeInit?: () => void;
|
|
76
|
-
}
|
|
77
|
-
type BaseScriptApi = Record<symbol | string, any>;
|
|
78
|
-
type AsAsyncFunctionValues<T extends BaseScriptApi> = {
|
|
79
|
-
[key in keyof T]: T[key] extends any[] ? T[key] : T[key] extends (...args: infer A) => infer R ? (...args: A) => R extends Promise<any> ? R : Promise<R> : T[key] extends Record<any, any> ? AsAsyncFunctionValues<T[key]> : never;
|
|
80
|
-
};
|
|
81
|
-
type UseScriptContext<T extends Record<symbol | string, any>> = (Promise<T> & ScriptInstance<T>) & AsAsyncFunctionValues<T> & {
|
|
82
|
-
/**
|
|
83
|
-
* @deprecated Use top-level functions instead.
|
|
84
|
-
*/
|
|
85
|
-
$script: Promise<T> & ScriptInstance<T>;
|
|
86
|
-
};
|
|
87
|
-
type UseFunctionType<T, U> = T extends {
|
|
88
|
-
use: infer V;
|
|
89
|
-
} ? V extends (...args: any) => any ? ReturnType<V> : U : U;
|
|
90
|
-
/**
|
|
91
|
-
* Load third-party scripts with SSR support and a proxied API.
|
|
92
|
-
*
|
|
93
|
-
* @see https://unhead.unjs.io/usage/composables/use-script
|
|
94
|
-
*/
|
|
95
|
-
declare function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>>(_input: UseScriptInput, _options?: UseScriptOptions<T>): UseScriptContext<UseFunctionType<UseScriptOptions<T>, T>>;
|
|
96
|
-
|
|
97
7
|
declare const activeHead: {
|
|
98
8
|
value: Unhead<any> | null;
|
|
99
9
|
};
|
|
100
10
|
declare function getActiveHead(): Unhead<any> | null;
|
|
101
|
-
declare const unheadComposablesImports: {
|
|
102
|
-
from: string;
|
|
103
|
-
imports: string[];
|
|
104
|
-
}[];
|
|
105
|
-
declare const composableNames: string[];
|
|
106
11
|
declare function createServerHead<T extends Record<string, any> = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
107
12
|
declare function createHead<T extends Record<string, any> = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
108
13
|
|
|
109
|
-
export {
|
|
14
|
+
export { activeHead, createHead, createServerHead, getActiveHead };
|
package/dist/legacy.mjs
CHANGED
|
@@ -1,243 +1,19 @@
|
|
|
1
|
-
import { c as createHeadCore } from './shared/unhead.
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export { u as
|
|
1
|
+
import { c as createHeadCore } from './shared/unhead.x5NJGkxU.mjs';
|
|
2
|
+
import { D as DeprecationsPlugin, P as PromisesPlugin, T as TemplateParamsPlugin, A as AliasSortingPlugin } from './shared/unhead.9Qw6eOEM.mjs';
|
|
3
|
+
export { u as useHead, a as useHeadSafe, b as useSeoMeta } from './shared/unhead.C2emW6l4.mjs';
|
|
4
|
+
export { u as useScript } from './shared/unhead.CG0hxuzW.mjs';
|
|
5
5
|
import 'hookable';
|
|
6
|
-
import './shared/unhead.
|
|
7
|
-
import './shared/unhead.
|
|
8
|
-
import './shared/unhead.
|
|
9
|
-
import './shared/unhead.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return input.key || input.src || (typeof input.innerHTML === "string" ? input.innerHTML : "");
|
|
13
|
-
}
|
|
14
|
-
const ScriptProxyTarget = Symbol("ScriptProxyTarget");
|
|
15
|
-
function scriptProxy() {
|
|
16
|
-
}
|
|
17
|
-
function useScript(_input, _options) {
|
|
18
|
-
const input = typeof _input === "string" ? { src: _input } : _input;
|
|
19
|
-
const options = _options || {};
|
|
20
|
-
const head = options.head || getActiveHead();
|
|
21
|
-
if (!head)
|
|
22
|
-
throw new Error("Missing Unhead context.");
|
|
23
|
-
const id = resolveScriptKey(input);
|
|
24
|
-
const prevScript = head._scripts?.[id];
|
|
25
|
-
if (prevScript) {
|
|
26
|
-
prevScript.setupTriggerHandler(options.trigger);
|
|
27
|
-
return prevScript;
|
|
28
|
-
}
|
|
29
|
-
options.beforeInit?.();
|
|
30
|
-
const syncStatus = (s) => {
|
|
31
|
-
script.status = s;
|
|
32
|
-
head.hooks.callHook(`script:updated`, hookCtx);
|
|
33
|
-
};
|
|
34
|
-
ScriptNetworkEvents.forEach((fn) => {
|
|
35
|
-
const _fn = typeof input[fn] === "function" ? input[fn].bind(options.eventContext) : null;
|
|
36
|
-
input[fn] = (e) => {
|
|
37
|
-
syncStatus(fn === "onload" ? "loaded" : fn === "onerror" ? "error" : "loading");
|
|
38
|
-
_fn?.(e);
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
const _cbs = { loaded: [], error: [] };
|
|
42
|
-
const _registerCb = (key, cb) => {
|
|
43
|
-
if (_cbs[key]) {
|
|
44
|
-
const i = _cbs[key].push(cb);
|
|
45
|
-
return () => _cbs[key]?.splice(i - 1, 1);
|
|
46
|
-
}
|
|
47
|
-
cb(script.instance);
|
|
48
|
-
return () => {
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
const loadPromise = new Promise((resolve) => {
|
|
52
|
-
if (head.ssr)
|
|
53
|
-
return;
|
|
54
|
-
const emit = (api) => requestAnimationFrame(() => resolve(api));
|
|
55
|
-
const _ = head.hooks.hook("script:updated", ({ script: script2 }) => {
|
|
56
|
-
const status = script2.status;
|
|
57
|
-
if (script2.id === id && (status === "loaded" || status === "error")) {
|
|
58
|
-
if (status === "loaded") {
|
|
59
|
-
if (typeof options.use === "function") {
|
|
60
|
-
const api = options.use();
|
|
61
|
-
if (api) {
|
|
62
|
-
emit(api);
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
emit({});
|
|
66
|
-
}
|
|
67
|
-
} else if (status === "error") {
|
|
68
|
-
resolve(false);
|
|
69
|
-
}
|
|
70
|
-
_();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
const script = Object.assign(loadPromise, {
|
|
75
|
-
instance: !head.ssr && options?.use?.() || null,
|
|
76
|
-
proxy: null,
|
|
77
|
-
id,
|
|
78
|
-
status: "awaitingLoad",
|
|
79
|
-
remove() {
|
|
80
|
-
script._triggerAbortController?.abort();
|
|
81
|
-
script._triggerPromises = [];
|
|
82
|
-
if (script.entry) {
|
|
83
|
-
script.entry.dispose();
|
|
84
|
-
script.entry = undefined;
|
|
85
|
-
syncStatus("removed");
|
|
86
|
-
delete head._scripts?.[id];
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
},
|
|
91
|
-
load(cb) {
|
|
92
|
-
script._triggerAbortController?.abort();
|
|
93
|
-
script._triggerPromises = [];
|
|
94
|
-
if (!script.entry) {
|
|
95
|
-
syncStatus("loading");
|
|
96
|
-
const defaults = {
|
|
97
|
-
defer: true,
|
|
98
|
-
fetchpriority: "low"
|
|
99
|
-
};
|
|
100
|
-
if (input.src && (input.src.startsWith("http") || input.src.startsWith("//"))) {
|
|
101
|
-
defaults.crossorigin = "anonymous";
|
|
102
|
-
defaults.referrerpolicy = "no-referrer";
|
|
103
|
-
}
|
|
104
|
-
script.entry = head.push({
|
|
105
|
-
script: [{ ...defaults, ...input, key: `script.${id}` }]
|
|
106
|
-
}, options);
|
|
107
|
-
}
|
|
108
|
-
if (cb)
|
|
109
|
-
_registerCb("loaded", cb);
|
|
110
|
-
return loadPromise;
|
|
111
|
-
},
|
|
112
|
-
onLoaded(cb) {
|
|
113
|
-
return _registerCb("loaded", cb);
|
|
114
|
-
},
|
|
115
|
-
onError(cb) {
|
|
116
|
-
return _registerCb("error", cb);
|
|
117
|
-
},
|
|
118
|
-
setupTriggerHandler(trigger) {
|
|
119
|
-
if (script.status !== "awaitingLoad") {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if ((typeof trigger === "undefined" || trigger === "client") && !head.ssr || trigger === "server") {
|
|
123
|
-
script.load();
|
|
124
|
-
} else if (trigger instanceof Promise) {
|
|
125
|
-
if (head.ssr) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (!script._triggerAbortController) {
|
|
129
|
-
script._triggerAbortController = new AbortController();
|
|
130
|
-
script._triggerAbortPromise = new Promise((resolve) => {
|
|
131
|
-
script._triggerAbortController.signal.addEventListener("abort", () => {
|
|
132
|
-
script._triggerAbortController = null;
|
|
133
|
-
resolve();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
script._triggerPromises = script._triggerPromises || [];
|
|
138
|
-
const idx = script._triggerPromises.push(Promise.race([
|
|
139
|
-
trigger.then((v) => typeof v === "undefined" || v ? script.load : undefined),
|
|
140
|
-
script._triggerAbortPromise
|
|
141
|
-
]).catch(() => {
|
|
142
|
-
}).then((res2) => {
|
|
143
|
-
res2?.();
|
|
144
|
-
}).finally(() => {
|
|
145
|
-
script._triggerPromises?.splice(idx, 1);
|
|
146
|
-
}));
|
|
147
|
-
} else if (typeof trigger === "function") {
|
|
148
|
-
trigger(script.load);
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
_cbs
|
|
152
|
-
});
|
|
153
|
-
loadPromise.then((api) => {
|
|
154
|
-
if (api !== false) {
|
|
155
|
-
script.instance = api;
|
|
156
|
-
_cbs.loaded?.forEach((cb) => cb(api));
|
|
157
|
-
_cbs.loaded = null;
|
|
158
|
-
} else {
|
|
159
|
-
_cbs.error?.forEach((cb) => cb());
|
|
160
|
-
_cbs.error = null;
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
const hookCtx = { script };
|
|
164
|
-
script.setupTriggerHandler(options.trigger);
|
|
165
|
-
script.$script = script;
|
|
166
|
-
const proxyChain = (instance, accessor, accessors) => {
|
|
167
|
-
scriptProxy[ScriptProxyTarget] = true;
|
|
168
|
-
return new Proxy((!accessor ? instance : instance?.[accessor]) || scriptProxy, {
|
|
169
|
-
get(_, k, r) {
|
|
170
|
-
head.hooks.callHook("script:instance-fn", { script, fn: k, exists: k in _ });
|
|
171
|
-
if (!accessor) {
|
|
172
|
-
const stub = options.stub?.({ script, fn: k });
|
|
173
|
-
if (stub)
|
|
174
|
-
return stub;
|
|
175
|
-
}
|
|
176
|
-
if (_ && k in _ && typeof _[k] !== "undefined") {
|
|
177
|
-
return Reflect.get(_, k, r);
|
|
178
|
-
}
|
|
179
|
-
if (k === Symbol.iterator) {
|
|
180
|
-
return [][Symbol.iterator];
|
|
181
|
-
}
|
|
182
|
-
return proxyChain(accessor ? instance?.[accessor] : instance, k, accessors || [k]);
|
|
183
|
-
},
|
|
184
|
-
async apply(_, _this, args) {
|
|
185
|
-
if (head.ssr && _[ScriptProxyTarget])
|
|
186
|
-
return;
|
|
187
|
-
let instance2;
|
|
188
|
-
const access = (fn2) => {
|
|
189
|
-
instance2 = fn2 || instance2;
|
|
190
|
-
for (let i = 0; i < (accessors || []).length; i++) {
|
|
191
|
-
const k = (accessors || [])[i];
|
|
192
|
-
fn2 = fn2?.[k];
|
|
193
|
-
}
|
|
194
|
-
return fn2;
|
|
195
|
-
};
|
|
196
|
-
let fn = access(script.instance);
|
|
197
|
-
if (!fn) {
|
|
198
|
-
fn = await new Promise((resolve) => {
|
|
199
|
-
script.onLoaded((api) => {
|
|
200
|
-
resolve(access(api));
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
return typeof fn === "function" ? Reflect.apply(fn, instance2, args) : fn;
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
script.proxy = proxyChain(script.instance);
|
|
209
|
-
const res = new Proxy(script, {
|
|
210
|
-
get(_, k) {
|
|
211
|
-
const target = k in script || String(k)[0] === "_" ? script : script.proxy;
|
|
212
|
-
if (k === "then" || k === "catch") {
|
|
213
|
-
return script[k].bind(script);
|
|
214
|
-
}
|
|
215
|
-
return Reflect.get(target, k, target);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
head._scripts = Object.assign(head._scripts || {}, { [id]: res });
|
|
219
|
-
return res;
|
|
220
|
-
}
|
|
6
|
+
import './shared/unhead.xsi8MZXD.mjs';
|
|
7
|
+
import './shared/unhead.yem5I2v_.mjs';
|
|
8
|
+
import './shared/unhead.DZbvapt-.mjs';
|
|
9
|
+
import './shared/unhead.z5bPaiJg.mjs';
|
|
10
|
+
import './shared/unhead.DFwCX-QT.mjs';
|
|
11
|
+
import './shared/unhead.CnbCxOp9.mjs';
|
|
221
12
|
|
|
222
13
|
const activeHead = { value: null };
|
|
223
14
|
function getActiveHead() {
|
|
224
15
|
return activeHead?.value;
|
|
225
16
|
}
|
|
226
|
-
const unheadComposablesImports = [
|
|
227
|
-
{
|
|
228
|
-
from: "unhead",
|
|
229
|
-
imports: [
|
|
230
|
-
"useHead",
|
|
231
|
-
"useHeadSafe",
|
|
232
|
-
"useSeoMeta"
|
|
233
|
-
]
|
|
234
|
-
}
|
|
235
|
-
];
|
|
236
|
-
const composableNames = [
|
|
237
|
-
"useHead",
|
|
238
|
-
"useHeadSafe",
|
|
239
|
-
"useSeoMeta"
|
|
240
|
-
];
|
|
241
17
|
function createServerHead(options = {}) {
|
|
242
18
|
return activeHead.value = createHeadCore({
|
|
243
19
|
disableCapoSorting: true,
|
|
@@ -267,4 +43,4 @@ function createHead(options = {}) {
|
|
|
267
43
|
});
|
|
268
44
|
}
|
|
269
45
|
|
|
270
|
-
export { activeHead,
|
|
46
|
+
export { activeHead, createHead, createHeadCore, createServerHead, getActiveHead };
|
package/dist/plugins.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { j as HeadPluginInput } from './shared/unhead.B_YMvzY6.mjs';
|
|
2
|
+
import 'hookable';
|
|
2
3
|
|
|
3
|
-
declare const AliasSortingPlugin:
|
|
4
|
+
declare const AliasSortingPlugin: HeadPluginInput;
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* CanonicalPlugin resolves paths in tags that require a canonical host to be set.
|
|
@@ -22,11 +23,13 @@ declare const AliasSortingPlugin: unhead_types.HeadPluginInput;
|
|
|
22
23
|
declare function CanonicalPlugin(options: {
|
|
23
24
|
canonicalHost?: string;
|
|
24
25
|
customResolver?: (url: string) => string;
|
|
25
|
-
}):
|
|
26
|
+
}): HeadPluginInput;
|
|
26
27
|
|
|
27
|
-
declare
|
|
28
|
+
declare function defineHeadPlugin(plugin: HeadPluginInput): HeadPluginInput;
|
|
28
29
|
|
|
29
|
-
declare const
|
|
30
|
+
declare const DeprecationsPlugin: HeadPluginInput;
|
|
31
|
+
|
|
32
|
+
declare const FlatMetaPlugin: HeadPluginInput;
|
|
30
33
|
|
|
31
34
|
interface InferSeoMetaPluginOptions {
|
|
32
35
|
/**
|
|
@@ -48,12 +51,12 @@ interface InferSeoMetaPluginOptions {
|
|
|
48
51
|
*/
|
|
49
52
|
twitterCard?: false | 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
50
53
|
}
|
|
51
|
-
declare function InferSeoMetaPlugin(options?: InferSeoMetaPluginOptions):
|
|
54
|
+
declare function InferSeoMetaPlugin(options?: InferSeoMetaPluginOptions): HeadPluginInput;
|
|
52
55
|
|
|
53
|
-
declare const PromisesPlugin:
|
|
56
|
+
declare const PromisesPlugin: HeadPluginInput;
|
|
54
57
|
|
|
55
|
-
declare const SafeInputPlugin:
|
|
58
|
+
declare const SafeInputPlugin: HeadPluginInput;
|
|
56
59
|
|
|
57
|
-
declare const TemplateParamsPlugin:
|
|
60
|
+
declare const TemplateParamsPlugin: HeadPluginInput;
|
|
58
61
|
|
|
59
|
-
export { AliasSortingPlugin, CanonicalPlugin, DeprecationsPlugin, FlatMetaPlugin, InferSeoMetaPlugin, PromisesPlugin, SafeInputPlugin, TemplateParamsPlugin };
|
|
62
|
+
export { AliasSortingPlugin, CanonicalPlugin, DeprecationsPlugin, FlatMetaPlugin, InferSeoMetaPlugin, PromisesPlugin, SafeInputPlugin, TemplateParamsPlugin, defineHeadPlugin };
|