@unhead/schema 1.11.15 → 2.0.0-alpha.1
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.d.cts +43 -123
- package/dist/index.d.mts +43 -123
- package/dist/index.d.ts +43 -123
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -5,8 +5,10 @@ export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInp
|
|
|
5
5
|
type Never<T> = {
|
|
6
6
|
[P in keyof T]?: never;
|
|
7
7
|
};
|
|
8
|
-
type
|
|
9
|
-
|
|
8
|
+
type MaybeFunction<T> = T | (() => T);
|
|
9
|
+
type Falsey = false | null | undefined;
|
|
10
|
+
type ResolvableValues<T> = {
|
|
11
|
+
[key in keyof T]?: MaybeFunction<T[key] | Falsey>;
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
type UserTagConfigWithoutInnerContent = TagPriority & TagPosition & ResolvesDuplicates & Never<InnerContent> & {
|
|
@@ -55,24 +57,24 @@ interface BaseMeta extends Omit<Meta$1, 'content'> {
|
|
|
55
57
|
content?: MaybeArray<Stringable> | null;
|
|
56
58
|
}
|
|
57
59
|
type EntryAugmentation = undefined | Record<string, any>;
|
|
58
|
-
type
|
|
60
|
+
type MaybeEventFnHandlers<T> = {
|
|
59
61
|
[key in keyof T]?: T[key] | ((e: Event) => void);
|
|
60
62
|
};
|
|
61
63
|
type TitleTemplateResolver = string | ((title?: string) => string | null);
|
|
62
|
-
type Title = string |
|
|
64
|
+
type Title = MaybeFunction<number | string | Falsey> | ResolvableValues<({
|
|
63
65
|
textContent: string;
|
|
64
|
-
} & SchemaAugmentations['title'])
|
|
66
|
+
} & SchemaAugmentations['title'])>;
|
|
65
67
|
type TitleTemplate = TitleTemplateResolver | null | ({
|
|
66
68
|
textContent: TitleTemplateResolver;
|
|
67
69
|
} & SchemaAugmentations['titleTemplate']);
|
|
68
|
-
type Base<E extends EntryAugmentation = Record<string, any>> = Partial<Merge<SchemaAugmentations['base'],
|
|
69
|
-
type Link<E extends EntryAugmentation = Record<string, any>> =
|
|
70
|
-
type Meta<E extends EntryAugmentation = Record<string, any>> =
|
|
71
|
-
type Style<E extends EntryAugmentation = Record<string, any>> =
|
|
72
|
-
type Script<E extends EntryAugmentation = Record<string, any>> =
|
|
73
|
-
type Noscript<E extends EntryAugmentation = Record<string, any>> =
|
|
74
|
-
type HtmlAttributes<E extends EntryAugmentation = Record<string, any>> =
|
|
75
|
-
type BodyAttributes<E extends EntryAugmentation = Record<string, any>> =
|
|
70
|
+
type Base<E extends EntryAugmentation = Record<string, any>> = Partial<Merge<SchemaAugmentations['base'], ResolvableValues<Base$1>>> & DefinedValueOrEmptyObject<E>;
|
|
71
|
+
type Link<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<LinkBase> & MaybeEventFnHandlers<HttpEventAttributes> & DataKeys & SchemaAugmentations['link'] & DefinedValueOrEmptyObject<E>;
|
|
72
|
+
type Meta<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<BaseMeta> & DataKeys & SchemaAugmentations['meta'] & DefinedValueOrEmptyObject<E>;
|
|
73
|
+
type Style<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<Style$1> & DataKeys & SchemaAugmentations['style'] & DefinedValueOrEmptyObject<E>;
|
|
74
|
+
type Script<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<ScriptBase> & MaybeEventFnHandlers<HttpEventAttributes> & DataKeys & SchemaAugmentations['script'] & DefinedValueOrEmptyObject<E>;
|
|
75
|
+
type Noscript<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<Noscript$1> & DataKeys & SchemaAugmentations['noscript'] & DefinedValueOrEmptyObject<E>;
|
|
76
|
+
type HtmlAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<HtmlAttr> & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
77
|
+
type BodyAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<BodyAttr> & MaybeEventFnHandlers<BodyEvents> & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
76
78
|
interface HeadUtils {
|
|
77
79
|
/**
|
|
78
80
|
* Generate the title from a template.
|
|
@@ -167,14 +169,6 @@ interface ResolvesDuplicates {
|
|
|
167
169
|
* @default 'replace' (some tags will default to 'merge', such as htmlAttr)
|
|
168
170
|
*/
|
|
169
171
|
tagDuplicateStrategy?: 'replace' | 'merge';
|
|
170
|
-
/**
|
|
171
|
-
* @deprecated Use `key` instead
|
|
172
|
-
*/
|
|
173
|
-
hid?: string;
|
|
174
|
-
/**
|
|
175
|
-
* @deprecated Use `key` instead
|
|
176
|
-
*/
|
|
177
|
-
vmid?: string;
|
|
178
172
|
}
|
|
179
173
|
type ValidTagPositions = 'head' | 'bodyClose' | 'bodyOpen';
|
|
180
174
|
interface TagPosition {
|
|
@@ -197,12 +191,6 @@ interface InnerContent {
|
|
|
197
191
|
* Sets the textContent of an element. Safer for XSS.
|
|
198
192
|
*/
|
|
199
193
|
textContent?: InnerContentVal;
|
|
200
|
-
/**
|
|
201
|
-
* Sets the textContent of an element.
|
|
202
|
-
*
|
|
203
|
-
* @deprecated Use `textContent` or `innerHTML`.
|
|
204
|
-
*/
|
|
205
|
-
children?: InnerContentVal;
|
|
206
194
|
}
|
|
207
195
|
interface TagPriority {
|
|
208
196
|
/**
|
|
@@ -218,7 +206,7 @@ interface TagPriority {
|
|
|
218
206
|
*/
|
|
219
207
|
tagPriority?: number | 'critical' | 'high' | 'low' | `before:${string}` | `after:${string}`;
|
|
220
208
|
}
|
|
221
|
-
type TagUserProperties =
|
|
209
|
+
type TagUserProperties = ResolvableValues<TagPriority & TagPosition & InnerContent & ResolvesDuplicates & ProcessesTemplateParams>;
|
|
222
210
|
type TagKey = keyof Head;
|
|
223
211
|
type TemplateParams = {
|
|
224
212
|
separator?: '|' | '-' | '·' | string;
|
|
@@ -262,7 +250,7 @@ interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTempl
|
|
|
262
250
|
/**
|
|
263
251
|
* @internal
|
|
264
252
|
*/
|
|
265
|
-
_eventHandlers?: Record<string, ((e: Event) =>
|
|
253
|
+
_eventHandlers?: Record<string, ((e: Event) => Record<string, any> | void)>;
|
|
266
254
|
}
|
|
267
255
|
type HeadTagKeys = (keyof HeadTag)[];
|
|
268
256
|
|
|
@@ -309,7 +297,7 @@ interface HeadHooks {
|
|
|
309
297
|
'tag:normalise': (ctx: {
|
|
310
298
|
tag: HeadTag;
|
|
311
299
|
entry: HeadEntry<any>;
|
|
312
|
-
resolvedOptions:
|
|
300
|
+
resolvedOptions: CreateClientHeadOptions;
|
|
313
301
|
}) => HookResult;
|
|
314
302
|
'tags:beforeResolve': (ctx: {
|
|
315
303
|
tags: HeadTag[];
|
|
@@ -330,14 +318,16 @@ interface HeadHooks {
|
|
|
330
318
|
tags: HeadTag[];
|
|
331
319
|
}) => HookResult;
|
|
332
320
|
'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface RenderDomHeadOptions {
|
|
324
|
+
/**
|
|
325
|
+
* Document to use for rendering. Allows stubbing for testing.
|
|
326
|
+
*/
|
|
327
|
+
document?: Document;
|
|
328
|
+
}
|
|
329
|
+
interface DomPluginOptions extends RenderDomHeadOptions {
|
|
330
|
+
delayFn?: (fn: () => void) => void;
|
|
341
331
|
}
|
|
342
332
|
|
|
343
333
|
/**
|
|
@@ -367,7 +357,7 @@ interface HeadEntry<Input> {
|
|
|
367
357
|
*
|
|
368
358
|
* @internal
|
|
369
359
|
*/
|
|
370
|
-
transform?: (input: Input) =>
|
|
360
|
+
transform?: (input: Input) => Input;
|
|
371
361
|
/**
|
|
372
362
|
* Head entry index
|
|
373
363
|
*
|
|
@@ -416,17 +406,28 @@ interface ActiveHeadEntry<Input> {
|
|
|
416
406
|
dispose: () => void;
|
|
417
407
|
}
|
|
418
408
|
interface CreateHeadOptions {
|
|
419
|
-
domDelayFn?: (fn: () => void) => void;
|
|
420
409
|
document?: Document;
|
|
421
410
|
plugins?: HeadPluginInput[];
|
|
422
411
|
hooks?: NestedHooks<HeadHooks>;
|
|
412
|
+
/**
|
|
413
|
+
* Disable the Capo.js tag sorting algorithm.
|
|
414
|
+
*
|
|
415
|
+
* This is added to make the v1 -> v2 migration easier allowing users to opt-out of the new sorting algorithm.
|
|
416
|
+
*/
|
|
417
|
+
disableCapoSorting?: boolean;
|
|
418
|
+
}
|
|
419
|
+
interface CreateClientHeadOptions extends CreateHeadOptions {
|
|
420
|
+
/**
|
|
421
|
+
* Options to pass to the DomPlugin.
|
|
422
|
+
*/
|
|
423
|
+
domOptions?: DomPluginOptions;
|
|
423
424
|
}
|
|
424
425
|
interface HeadEntryOptions extends TagPosition, TagPriority, ProcessesTemplateParams, ResolvesDuplicates {
|
|
425
426
|
mode?: RuntimeMode;
|
|
426
427
|
transform?: (input: unknown) => unknown;
|
|
427
428
|
head?: Unhead;
|
|
428
429
|
}
|
|
429
|
-
interface Unhead<Input extends
|
|
430
|
+
interface Unhead<Input extends Record<string, any> = Head> {
|
|
430
431
|
/**
|
|
431
432
|
* Registered plugins.
|
|
432
433
|
*/
|
|
@@ -514,85 +515,4 @@ interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParam
|
|
|
514
515
|
bodyAttrs?: SafeBodyAttr;
|
|
515
516
|
}
|
|
516
517
|
|
|
517
|
-
type
|
|
518
|
-
/**
|
|
519
|
-
* Either a string source for the script or full script properties.
|
|
520
|
-
*/
|
|
521
|
-
type UseScriptInput = string | (Omit<Script, 'src'> & {
|
|
522
|
-
src: string;
|
|
523
|
-
});
|
|
524
|
-
type UseScriptResolvedInput = Omit<Script, 'src'> & {
|
|
525
|
-
src: string;
|
|
526
|
-
};
|
|
527
|
-
type BaseScriptApi = Record<symbol | string, any>;
|
|
528
|
-
type AsAsyncFunctionValues<T extends BaseScriptApi> = {
|
|
529
|
-
[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;
|
|
530
|
-
};
|
|
531
|
-
interface ScriptInstance<T extends BaseScriptApi> {
|
|
532
|
-
proxy: AsAsyncFunctionValues<T>;
|
|
533
|
-
instance?: T;
|
|
534
|
-
id: string;
|
|
535
|
-
status: UseScriptStatus;
|
|
536
|
-
entry?: ActiveHeadEntry<any>;
|
|
537
|
-
load: () => Promise<T>;
|
|
538
|
-
remove: () => boolean;
|
|
539
|
-
setupTriggerHandler: (trigger: UseScriptOptions['trigger']) => void;
|
|
540
|
-
onLoaded: (fn: (instance: T) => void | Promise<void>) => void;
|
|
541
|
-
onError: (fn: (err?: Error) => void | Promise<void>) => void;
|
|
542
|
-
/**
|
|
543
|
-
* @internal
|
|
544
|
-
*/
|
|
545
|
-
_triggerAbortController?: AbortController | null;
|
|
546
|
-
/**
|
|
547
|
-
* @internal
|
|
548
|
-
*/
|
|
549
|
-
_triggerAbortPromise?: Promise<void>;
|
|
550
|
-
/**
|
|
551
|
-
* @internal
|
|
552
|
-
*/
|
|
553
|
-
_triggerPromises?: Promise<void>[];
|
|
554
|
-
/**
|
|
555
|
-
* @internal
|
|
556
|
-
*/
|
|
557
|
-
_cbs: {
|
|
558
|
-
loaded: null | ((instance: T) => void | Promise<void>)[];
|
|
559
|
-
error: null | ((err?: Error) => void | Promise<void>)[];
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
type UseFunctionType<T, U> = T extends {
|
|
563
|
-
use: infer V;
|
|
564
|
-
} ? V extends (...args: any) => any ? ReturnType<V> : U : U;
|
|
565
|
-
interface UseScriptOptions<T extends BaseScriptApi = {}, U = {}> extends HeadEntryOptions {
|
|
566
|
-
/**
|
|
567
|
-
* Resolve the script instance from the window.
|
|
568
|
-
*/
|
|
569
|
-
use?: () => T | undefined | null;
|
|
570
|
-
/**
|
|
571
|
-
* Stub the script instance. Useful for SSR or testing.
|
|
572
|
-
*/
|
|
573
|
-
stub?: ((ctx: {
|
|
574
|
-
script: ScriptInstance<T>;
|
|
575
|
-
fn: string | symbol;
|
|
576
|
-
}) => any);
|
|
577
|
-
/**
|
|
578
|
-
* The trigger to load the script:
|
|
579
|
-
* - `undefined` | `client` - (Default) Load the script on the client when this js is loaded.
|
|
580
|
-
* - `manual` - Load the script manually by calling `$script.load()`, exists only on the client.
|
|
581
|
-
* - `Promise` - Load the script when the promise resolves, exists only on the client.
|
|
582
|
-
* - `Function` - Register a callback function to load the script, exists only on the client.
|
|
583
|
-
* - `server` - Have the script injected on the server.
|
|
584
|
-
*/
|
|
585
|
-
trigger?: 'client' | 'server' | 'manual' | Promise<boolean | void> | ((fn: any) => any) | null;
|
|
586
|
-
/**
|
|
587
|
-
* Context to run events with. This is useful in Vue to attach the current instance context before
|
|
588
|
-
* calling the event, allowing the event to be reactive.
|
|
589
|
-
*/
|
|
590
|
-
eventContext?: any;
|
|
591
|
-
/**
|
|
592
|
-
* Called before the script is initialized. Will not be triggered when the script is already loaded. This means
|
|
593
|
-
* this is guaranteed to be called only once, unless the script is removed and re-added.
|
|
594
|
-
*/
|
|
595
|
-
beforeInit?: () => void;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
export type { ActiveHeadEntry, AsAsyncFunctionValues, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateHeadOptions, DomBeforeRenderCtx, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginInput, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeFunctionEntries, Meta, Noscript, ProcessesTemplateParams, RenderSSRHeadOptions, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript, SchemaAugmentations, Script, ScriptInstance, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseFunctionType, UseScriptInput, UseScriptOptions, UseScriptResolvedInput, UseScriptStatus, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
|
|
518
|
+
export type { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateClientHeadOptions, CreateHeadOptions, DomBeforeRenderCtx, DomPluginOptions, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginInput, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeEventFnHandlers, Meta, Noscript, ProcessesTemplateParams, RenderDomHeadOptions, RenderSSRHeadOptions, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript, SchemaAugmentations, Script, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
|
package/dist/index.d.mts
CHANGED
|
@@ -5,8 +5,10 @@ export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInp
|
|
|
5
5
|
type Never<T> = {
|
|
6
6
|
[P in keyof T]?: never;
|
|
7
7
|
};
|
|
8
|
-
type
|
|
9
|
-
|
|
8
|
+
type MaybeFunction<T> = T | (() => T);
|
|
9
|
+
type Falsey = false | null | undefined;
|
|
10
|
+
type ResolvableValues<T> = {
|
|
11
|
+
[key in keyof T]?: MaybeFunction<T[key] | Falsey>;
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
type UserTagConfigWithoutInnerContent = TagPriority & TagPosition & ResolvesDuplicates & Never<InnerContent> & {
|
|
@@ -55,24 +57,24 @@ interface BaseMeta extends Omit<Meta$1, 'content'> {
|
|
|
55
57
|
content?: MaybeArray<Stringable> | null;
|
|
56
58
|
}
|
|
57
59
|
type EntryAugmentation = undefined | Record<string, any>;
|
|
58
|
-
type
|
|
60
|
+
type MaybeEventFnHandlers<T> = {
|
|
59
61
|
[key in keyof T]?: T[key] | ((e: Event) => void);
|
|
60
62
|
};
|
|
61
63
|
type TitleTemplateResolver = string | ((title?: string) => string | null);
|
|
62
|
-
type Title = string |
|
|
64
|
+
type Title = MaybeFunction<number | string | Falsey> | ResolvableValues<({
|
|
63
65
|
textContent: string;
|
|
64
|
-
} & SchemaAugmentations['title'])
|
|
66
|
+
} & SchemaAugmentations['title'])>;
|
|
65
67
|
type TitleTemplate = TitleTemplateResolver | null | ({
|
|
66
68
|
textContent: TitleTemplateResolver;
|
|
67
69
|
} & SchemaAugmentations['titleTemplate']);
|
|
68
|
-
type Base<E extends EntryAugmentation = Record<string, any>> = Partial<Merge<SchemaAugmentations['base'],
|
|
69
|
-
type Link<E extends EntryAugmentation = Record<string, any>> =
|
|
70
|
-
type Meta<E extends EntryAugmentation = Record<string, any>> =
|
|
71
|
-
type Style<E extends EntryAugmentation = Record<string, any>> =
|
|
72
|
-
type Script<E extends EntryAugmentation = Record<string, any>> =
|
|
73
|
-
type Noscript<E extends EntryAugmentation = Record<string, any>> =
|
|
74
|
-
type HtmlAttributes<E extends EntryAugmentation = Record<string, any>> =
|
|
75
|
-
type BodyAttributes<E extends EntryAugmentation = Record<string, any>> =
|
|
70
|
+
type Base<E extends EntryAugmentation = Record<string, any>> = Partial<Merge<SchemaAugmentations['base'], ResolvableValues<Base$1>>> & DefinedValueOrEmptyObject<E>;
|
|
71
|
+
type Link<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<LinkBase> & MaybeEventFnHandlers<HttpEventAttributes> & DataKeys & SchemaAugmentations['link'] & DefinedValueOrEmptyObject<E>;
|
|
72
|
+
type Meta<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<BaseMeta> & DataKeys & SchemaAugmentations['meta'] & DefinedValueOrEmptyObject<E>;
|
|
73
|
+
type Style<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<Style$1> & DataKeys & SchemaAugmentations['style'] & DefinedValueOrEmptyObject<E>;
|
|
74
|
+
type Script<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<ScriptBase> & MaybeEventFnHandlers<HttpEventAttributes> & DataKeys & SchemaAugmentations['script'] & DefinedValueOrEmptyObject<E>;
|
|
75
|
+
type Noscript<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<Noscript$1> & DataKeys & SchemaAugmentations['noscript'] & DefinedValueOrEmptyObject<E>;
|
|
76
|
+
type HtmlAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<HtmlAttr> & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
77
|
+
type BodyAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<BodyAttr> & MaybeEventFnHandlers<BodyEvents> & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
76
78
|
interface HeadUtils {
|
|
77
79
|
/**
|
|
78
80
|
* Generate the title from a template.
|
|
@@ -167,14 +169,6 @@ interface ResolvesDuplicates {
|
|
|
167
169
|
* @default 'replace' (some tags will default to 'merge', such as htmlAttr)
|
|
168
170
|
*/
|
|
169
171
|
tagDuplicateStrategy?: 'replace' | 'merge';
|
|
170
|
-
/**
|
|
171
|
-
* @deprecated Use `key` instead
|
|
172
|
-
*/
|
|
173
|
-
hid?: string;
|
|
174
|
-
/**
|
|
175
|
-
* @deprecated Use `key` instead
|
|
176
|
-
*/
|
|
177
|
-
vmid?: string;
|
|
178
172
|
}
|
|
179
173
|
type ValidTagPositions = 'head' | 'bodyClose' | 'bodyOpen';
|
|
180
174
|
interface TagPosition {
|
|
@@ -197,12 +191,6 @@ interface InnerContent {
|
|
|
197
191
|
* Sets the textContent of an element. Safer for XSS.
|
|
198
192
|
*/
|
|
199
193
|
textContent?: InnerContentVal;
|
|
200
|
-
/**
|
|
201
|
-
* Sets the textContent of an element.
|
|
202
|
-
*
|
|
203
|
-
* @deprecated Use `textContent` or `innerHTML`.
|
|
204
|
-
*/
|
|
205
|
-
children?: InnerContentVal;
|
|
206
194
|
}
|
|
207
195
|
interface TagPriority {
|
|
208
196
|
/**
|
|
@@ -218,7 +206,7 @@ interface TagPriority {
|
|
|
218
206
|
*/
|
|
219
207
|
tagPriority?: number | 'critical' | 'high' | 'low' | `before:${string}` | `after:${string}`;
|
|
220
208
|
}
|
|
221
|
-
type TagUserProperties =
|
|
209
|
+
type TagUserProperties = ResolvableValues<TagPriority & TagPosition & InnerContent & ResolvesDuplicates & ProcessesTemplateParams>;
|
|
222
210
|
type TagKey = keyof Head;
|
|
223
211
|
type TemplateParams = {
|
|
224
212
|
separator?: '|' | '-' | '·' | string;
|
|
@@ -262,7 +250,7 @@ interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTempl
|
|
|
262
250
|
/**
|
|
263
251
|
* @internal
|
|
264
252
|
*/
|
|
265
|
-
_eventHandlers?: Record<string, ((e: Event) =>
|
|
253
|
+
_eventHandlers?: Record<string, ((e: Event) => Record<string, any> | void)>;
|
|
266
254
|
}
|
|
267
255
|
type HeadTagKeys = (keyof HeadTag)[];
|
|
268
256
|
|
|
@@ -309,7 +297,7 @@ interface HeadHooks {
|
|
|
309
297
|
'tag:normalise': (ctx: {
|
|
310
298
|
tag: HeadTag;
|
|
311
299
|
entry: HeadEntry<any>;
|
|
312
|
-
resolvedOptions:
|
|
300
|
+
resolvedOptions: CreateClientHeadOptions;
|
|
313
301
|
}) => HookResult;
|
|
314
302
|
'tags:beforeResolve': (ctx: {
|
|
315
303
|
tags: HeadTag[];
|
|
@@ -330,14 +318,16 @@ interface HeadHooks {
|
|
|
330
318
|
tags: HeadTag[];
|
|
331
319
|
}) => HookResult;
|
|
332
320
|
'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface RenderDomHeadOptions {
|
|
324
|
+
/**
|
|
325
|
+
* Document to use for rendering. Allows stubbing for testing.
|
|
326
|
+
*/
|
|
327
|
+
document?: Document;
|
|
328
|
+
}
|
|
329
|
+
interface DomPluginOptions extends RenderDomHeadOptions {
|
|
330
|
+
delayFn?: (fn: () => void) => void;
|
|
341
331
|
}
|
|
342
332
|
|
|
343
333
|
/**
|
|
@@ -367,7 +357,7 @@ interface HeadEntry<Input> {
|
|
|
367
357
|
*
|
|
368
358
|
* @internal
|
|
369
359
|
*/
|
|
370
|
-
transform?: (input: Input) =>
|
|
360
|
+
transform?: (input: Input) => Input;
|
|
371
361
|
/**
|
|
372
362
|
* Head entry index
|
|
373
363
|
*
|
|
@@ -416,17 +406,28 @@ interface ActiveHeadEntry<Input> {
|
|
|
416
406
|
dispose: () => void;
|
|
417
407
|
}
|
|
418
408
|
interface CreateHeadOptions {
|
|
419
|
-
domDelayFn?: (fn: () => void) => void;
|
|
420
409
|
document?: Document;
|
|
421
410
|
plugins?: HeadPluginInput[];
|
|
422
411
|
hooks?: NestedHooks<HeadHooks>;
|
|
412
|
+
/**
|
|
413
|
+
* Disable the Capo.js tag sorting algorithm.
|
|
414
|
+
*
|
|
415
|
+
* This is added to make the v1 -> v2 migration easier allowing users to opt-out of the new sorting algorithm.
|
|
416
|
+
*/
|
|
417
|
+
disableCapoSorting?: boolean;
|
|
418
|
+
}
|
|
419
|
+
interface CreateClientHeadOptions extends CreateHeadOptions {
|
|
420
|
+
/**
|
|
421
|
+
* Options to pass to the DomPlugin.
|
|
422
|
+
*/
|
|
423
|
+
domOptions?: DomPluginOptions;
|
|
423
424
|
}
|
|
424
425
|
interface HeadEntryOptions extends TagPosition, TagPriority, ProcessesTemplateParams, ResolvesDuplicates {
|
|
425
426
|
mode?: RuntimeMode;
|
|
426
427
|
transform?: (input: unknown) => unknown;
|
|
427
428
|
head?: Unhead;
|
|
428
429
|
}
|
|
429
|
-
interface Unhead<Input extends
|
|
430
|
+
interface Unhead<Input extends Record<string, any> = Head> {
|
|
430
431
|
/**
|
|
431
432
|
* Registered plugins.
|
|
432
433
|
*/
|
|
@@ -514,85 +515,4 @@ interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParam
|
|
|
514
515
|
bodyAttrs?: SafeBodyAttr;
|
|
515
516
|
}
|
|
516
517
|
|
|
517
|
-
type
|
|
518
|
-
/**
|
|
519
|
-
* Either a string source for the script or full script properties.
|
|
520
|
-
*/
|
|
521
|
-
type UseScriptInput = string | (Omit<Script, 'src'> & {
|
|
522
|
-
src: string;
|
|
523
|
-
});
|
|
524
|
-
type UseScriptResolvedInput = Omit<Script, 'src'> & {
|
|
525
|
-
src: string;
|
|
526
|
-
};
|
|
527
|
-
type BaseScriptApi = Record<symbol | string, any>;
|
|
528
|
-
type AsAsyncFunctionValues<T extends BaseScriptApi> = {
|
|
529
|
-
[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;
|
|
530
|
-
};
|
|
531
|
-
interface ScriptInstance<T extends BaseScriptApi> {
|
|
532
|
-
proxy: AsAsyncFunctionValues<T>;
|
|
533
|
-
instance?: T;
|
|
534
|
-
id: string;
|
|
535
|
-
status: UseScriptStatus;
|
|
536
|
-
entry?: ActiveHeadEntry<any>;
|
|
537
|
-
load: () => Promise<T>;
|
|
538
|
-
remove: () => boolean;
|
|
539
|
-
setupTriggerHandler: (trigger: UseScriptOptions['trigger']) => void;
|
|
540
|
-
onLoaded: (fn: (instance: T) => void | Promise<void>) => void;
|
|
541
|
-
onError: (fn: (err?: Error) => void | Promise<void>) => void;
|
|
542
|
-
/**
|
|
543
|
-
* @internal
|
|
544
|
-
*/
|
|
545
|
-
_triggerAbortController?: AbortController | null;
|
|
546
|
-
/**
|
|
547
|
-
* @internal
|
|
548
|
-
*/
|
|
549
|
-
_triggerAbortPromise?: Promise<void>;
|
|
550
|
-
/**
|
|
551
|
-
* @internal
|
|
552
|
-
*/
|
|
553
|
-
_triggerPromises?: Promise<void>[];
|
|
554
|
-
/**
|
|
555
|
-
* @internal
|
|
556
|
-
*/
|
|
557
|
-
_cbs: {
|
|
558
|
-
loaded: null | ((instance: T) => void | Promise<void>)[];
|
|
559
|
-
error: null | ((err?: Error) => void | Promise<void>)[];
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
type UseFunctionType<T, U> = T extends {
|
|
563
|
-
use: infer V;
|
|
564
|
-
} ? V extends (...args: any) => any ? ReturnType<V> : U : U;
|
|
565
|
-
interface UseScriptOptions<T extends BaseScriptApi = {}, U = {}> extends HeadEntryOptions {
|
|
566
|
-
/**
|
|
567
|
-
* Resolve the script instance from the window.
|
|
568
|
-
*/
|
|
569
|
-
use?: () => T | undefined | null;
|
|
570
|
-
/**
|
|
571
|
-
* Stub the script instance. Useful for SSR or testing.
|
|
572
|
-
*/
|
|
573
|
-
stub?: ((ctx: {
|
|
574
|
-
script: ScriptInstance<T>;
|
|
575
|
-
fn: string | symbol;
|
|
576
|
-
}) => any);
|
|
577
|
-
/**
|
|
578
|
-
* The trigger to load the script:
|
|
579
|
-
* - `undefined` | `client` - (Default) Load the script on the client when this js is loaded.
|
|
580
|
-
* - `manual` - Load the script manually by calling `$script.load()`, exists only on the client.
|
|
581
|
-
* - `Promise` - Load the script when the promise resolves, exists only on the client.
|
|
582
|
-
* - `Function` - Register a callback function to load the script, exists only on the client.
|
|
583
|
-
* - `server` - Have the script injected on the server.
|
|
584
|
-
*/
|
|
585
|
-
trigger?: 'client' | 'server' | 'manual' | Promise<boolean | void> | ((fn: any) => any) | null;
|
|
586
|
-
/**
|
|
587
|
-
* Context to run events with. This is useful in Vue to attach the current instance context before
|
|
588
|
-
* calling the event, allowing the event to be reactive.
|
|
589
|
-
*/
|
|
590
|
-
eventContext?: any;
|
|
591
|
-
/**
|
|
592
|
-
* Called before the script is initialized. Will not be triggered when the script is already loaded. This means
|
|
593
|
-
* this is guaranteed to be called only once, unless the script is removed and re-added.
|
|
594
|
-
*/
|
|
595
|
-
beforeInit?: () => void;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
export type { ActiveHeadEntry, AsAsyncFunctionValues, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateHeadOptions, DomBeforeRenderCtx, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginInput, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeFunctionEntries, Meta, Noscript, ProcessesTemplateParams, RenderSSRHeadOptions, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript, SchemaAugmentations, Script, ScriptInstance, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseFunctionType, UseScriptInput, UseScriptOptions, UseScriptResolvedInput, UseScriptStatus, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
|
|
518
|
+
export type { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateClientHeadOptions, CreateHeadOptions, DomBeforeRenderCtx, DomPluginOptions, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginInput, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeEventFnHandlers, Meta, Noscript, ProcessesTemplateParams, RenderDomHeadOptions, RenderSSRHeadOptions, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript, SchemaAugmentations, Script, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,10 @@ export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInp
|
|
|
5
5
|
type Never<T> = {
|
|
6
6
|
[P in keyof T]?: never;
|
|
7
7
|
};
|
|
8
|
-
type
|
|
9
|
-
|
|
8
|
+
type MaybeFunction<T> = T | (() => T);
|
|
9
|
+
type Falsey = false | null | undefined;
|
|
10
|
+
type ResolvableValues<T> = {
|
|
11
|
+
[key in keyof T]?: MaybeFunction<T[key] | Falsey>;
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
type UserTagConfigWithoutInnerContent = TagPriority & TagPosition & ResolvesDuplicates & Never<InnerContent> & {
|
|
@@ -55,24 +57,24 @@ interface BaseMeta extends Omit<Meta$1, 'content'> {
|
|
|
55
57
|
content?: MaybeArray<Stringable> | null;
|
|
56
58
|
}
|
|
57
59
|
type EntryAugmentation = undefined | Record<string, any>;
|
|
58
|
-
type
|
|
60
|
+
type MaybeEventFnHandlers<T> = {
|
|
59
61
|
[key in keyof T]?: T[key] | ((e: Event) => void);
|
|
60
62
|
};
|
|
61
63
|
type TitleTemplateResolver = string | ((title?: string) => string | null);
|
|
62
|
-
type Title = string |
|
|
64
|
+
type Title = MaybeFunction<number | string | Falsey> | ResolvableValues<({
|
|
63
65
|
textContent: string;
|
|
64
|
-
} & SchemaAugmentations['title'])
|
|
66
|
+
} & SchemaAugmentations['title'])>;
|
|
65
67
|
type TitleTemplate = TitleTemplateResolver | null | ({
|
|
66
68
|
textContent: TitleTemplateResolver;
|
|
67
69
|
} & SchemaAugmentations['titleTemplate']);
|
|
68
|
-
type Base<E extends EntryAugmentation = Record<string, any>> = Partial<Merge<SchemaAugmentations['base'],
|
|
69
|
-
type Link<E extends EntryAugmentation = Record<string, any>> =
|
|
70
|
-
type Meta<E extends EntryAugmentation = Record<string, any>> =
|
|
71
|
-
type Style<E extends EntryAugmentation = Record<string, any>> =
|
|
72
|
-
type Script<E extends EntryAugmentation = Record<string, any>> =
|
|
73
|
-
type Noscript<E extends EntryAugmentation = Record<string, any>> =
|
|
74
|
-
type HtmlAttributes<E extends EntryAugmentation = Record<string, any>> =
|
|
75
|
-
type BodyAttributes<E extends EntryAugmentation = Record<string, any>> =
|
|
70
|
+
type Base<E extends EntryAugmentation = Record<string, any>> = Partial<Merge<SchemaAugmentations['base'], ResolvableValues<Base$1>>> & DefinedValueOrEmptyObject<E>;
|
|
71
|
+
type Link<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<LinkBase> & MaybeEventFnHandlers<HttpEventAttributes> & DataKeys & SchemaAugmentations['link'] & DefinedValueOrEmptyObject<E>;
|
|
72
|
+
type Meta<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<BaseMeta> & DataKeys & SchemaAugmentations['meta'] & DefinedValueOrEmptyObject<E>;
|
|
73
|
+
type Style<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<Style$1> & DataKeys & SchemaAugmentations['style'] & DefinedValueOrEmptyObject<E>;
|
|
74
|
+
type Script<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<ScriptBase> & MaybeEventFnHandlers<HttpEventAttributes> & DataKeys & SchemaAugmentations['script'] & DefinedValueOrEmptyObject<E>;
|
|
75
|
+
type Noscript<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<Noscript$1> & DataKeys & SchemaAugmentations['noscript'] & DefinedValueOrEmptyObject<E>;
|
|
76
|
+
type HtmlAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<HtmlAttr> & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
77
|
+
type BodyAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableValues<BodyAttr> & MaybeEventFnHandlers<BodyEvents> & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
76
78
|
interface HeadUtils {
|
|
77
79
|
/**
|
|
78
80
|
* Generate the title from a template.
|
|
@@ -167,14 +169,6 @@ interface ResolvesDuplicates {
|
|
|
167
169
|
* @default 'replace' (some tags will default to 'merge', such as htmlAttr)
|
|
168
170
|
*/
|
|
169
171
|
tagDuplicateStrategy?: 'replace' | 'merge';
|
|
170
|
-
/**
|
|
171
|
-
* @deprecated Use `key` instead
|
|
172
|
-
*/
|
|
173
|
-
hid?: string;
|
|
174
|
-
/**
|
|
175
|
-
* @deprecated Use `key` instead
|
|
176
|
-
*/
|
|
177
|
-
vmid?: string;
|
|
178
172
|
}
|
|
179
173
|
type ValidTagPositions = 'head' | 'bodyClose' | 'bodyOpen';
|
|
180
174
|
interface TagPosition {
|
|
@@ -197,12 +191,6 @@ interface InnerContent {
|
|
|
197
191
|
* Sets the textContent of an element. Safer for XSS.
|
|
198
192
|
*/
|
|
199
193
|
textContent?: InnerContentVal;
|
|
200
|
-
/**
|
|
201
|
-
* Sets the textContent of an element.
|
|
202
|
-
*
|
|
203
|
-
* @deprecated Use `textContent` or `innerHTML`.
|
|
204
|
-
*/
|
|
205
|
-
children?: InnerContentVal;
|
|
206
194
|
}
|
|
207
195
|
interface TagPriority {
|
|
208
196
|
/**
|
|
@@ -218,7 +206,7 @@ interface TagPriority {
|
|
|
218
206
|
*/
|
|
219
207
|
tagPriority?: number | 'critical' | 'high' | 'low' | `before:${string}` | `after:${string}`;
|
|
220
208
|
}
|
|
221
|
-
type TagUserProperties =
|
|
209
|
+
type TagUserProperties = ResolvableValues<TagPriority & TagPosition & InnerContent & ResolvesDuplicates & ProcessesTemplateParams>;
|
|
222
210
|
type TagKey = keyof Head;
|
|
223
211
|
type TemplateParams = {
|
|
224
212
|
separator?: '|' | '-' | '·' | string;
|
|
@@ -262,7 +250,7 @@ interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTempl
|
|
|
262
250
|
/**
|
|
263
251
|
* @internal
|
|
264
252
|
*/
|
|
265
|
-
_eventHandlers?: Record<string, ((e: Event) =>
|
|
253
|
+
_eventHandlers?: Record<string, ((e: Event) => Record<string, any> | void)>;
|
|
266
254
|
}
|
|
267
255
|
type HeadTagKeys = (keyof HeadTag)[];
|
|
268
256
|
|
|
@@ -309,7 +297,7 @@ interface HeadHooks {
|
|
|
309
297
|
'tag:normalise': (ctx: {
|
|
310
298
|
tag: HeadTag;
|
|
311
299
|
entry: HeadEntry<any>;
|
|
312
|
-
resolvedOptions:
|
|
300
|
+
resolvedOptions: CreateClientHeadOptions;
|
|
313
301
|
}) => HookResult;
|
|
314
302
|
'tags:beforeResolve': (ctx: {
|
|
315
303
|
tags: HeadTag[];
|
|
@@ -330,14 +318,16 @@ interface HeadHooks {
|
|
|
330
318
|
tags: HeadTag[];
|
|
331
319
|
}) => HookResult;
|
|
332
320
|
'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface RenderDomHeadOptions {
|
|
324
|
+
/**
|
|
325
|
+
* Document to use for rendering. Allows stubbing for testing.
|
|
326
|
+
*/
|
|
327
|
+
document?: Document;
|
|
328
|
+
}
|
|
329
|
+
interface DomPluginOptions extends RenderDomHeadOptions {
|
|
330
|
+
delayFn?: (fn: () => void) => void;
|
|
341
331
|
}
|
|
342
332
|
|
|
343
333
|
/**
|
|
@@ -367,7 +357,7 @@ interface HeadEntry<Input> {
|
|
|
367
357
|
*
|
|
368
358
|
* @internal
|
|
369
359
|
*/
|
|
370
|
-
transform?: (input: Input) =>
|
|
360
|
+
transform?: (input: Input) => Input;
|
|
371
361
|
/**
|
|
372
362
|
* Head entry index
|
|
373
363
|
*
|
|
@@ -416,17 +406,28 @@ interface ActiveHeadEntry<Input> {
|
|
|
416
406
|
dispose: () => void;
|
|
417
407
|
}
|
|
418
408
|
interface CreateHeadOptions {
|
|
419
|
-
domDelayFn?: (fn: () => void) => void;
|
|
420
409
|
document?: Document;
|
|
421
410
|
plugins?: HeadPluginInput[];
|
|
422
411
|
hooks?: NestedHooks<HeadHooks>;
|
|
412
|
+
/**
|
|
413
|
+
* Disable the Capo.js tag sorting algorithm.
|
|
414
|
+
*
|
|
415
|
+
* This is added to make the v1 -> v2 migration easier allowing users to opt-out of the new sorting algorithm.
|
|
416
|
+
*/
|
|
417
|
+
disableCapoSorting?: boolean;
|
|
418
|
+
}
|
|
419
|
+
interface CreateClientHeadOptions extends CreateHeadOptions {
|
|
420
|
+
/**
|
|
421
|
+
* Options to pass to the DomPlugin.
|
|
422
|
+
*/
|
|
423
|
+
domOptions?: DomPluginOptions;
|
|
423
424
|
}
|
|
424
425
|
interface HeadEntryOptions extends TagPosition, TagPriority, ProcessesTemplateParams, ResolvesDuplicates {
|
|
425
426
|
mode?: RuntimeMode;
|
|
426
427
|
transform?: (input: unknown) => unknown;
|
|
427
428
|
head?: Unhead;
|
|
428
429
|
}
|
|
429
|
-
interface Unhead<Input extends
|
|
430
|
+
interface Unhead<Input extends Record<string, any> = Head> {
|
|
430
431
|
/**
|
|
431
432
|
* Registered plugins.
|
|
432
433
|
*/
|
|
@@ -514,85 +515,4 @@ interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParam
|
|
|
514
515
|
bodyAttrs?: SafeBodyAttr;
|
|
515
516
|
}
|
|
516
517
|
|
|
517
|
-
type
|
|
518
|
-
/**
|
|
519
|
-
* Either a string source for the script or full script properties.
|
|
520
|
-
*/
|
|
521
|
-
type UseScriptInput = string | (Omit<Script, 'src'> & {
|
|
522
|
-
src: string;
|
|
523
|
-
});
|
|
524
|
-
type UseScriptResolvedInput = Omit<Script, 'src'> & {
|
|
525
|
-
src: string;
|
|
526
|
-
};
|
|
527
|
-
type BaseScriptApi = Record<symbol | string, any>;
|
|
528
|
-
type AsAsyncFunctionValues<T extends BaseScriptApi> = {
|
|
529
|
-
[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;
|
|
530
|
-
};
|
|
531
|
-
interface ScriptInstance<T extends BaseScriptApi> {
|
|
532
|
-
proxy: AsAsyncFunctionValues<T>;
|
|
533
|
-
instance?: T;
|
|
534
|
-
id: string;
|
|
535
|
-
status: UseScriptStatus;
|
|
536
|
-
entry?: ActiveHeadEntry<any>;
|
|
537
|
-
load: () => Promise<T>;
|
|
538
|
-
remove: () => boolean;
|
|
539
|
-
setupTriggerHandler: (trigger: UseScriptOptions['trigger']) => void;
|
|
540
|
-
onLoaded: (fn: (instance: T) => void | Promise<void>) => void;
|
|
541
|
-
onError: (fn: (err?: Error) => void | Promise<void>) => void;
|
|
542
|
-
/**
|
|
543
|
-
* @internal
|
|
544
|
-
*/
|
|
545
|
-
_triggerAbortController?: AbortController | null;
|
|
546
|
-
/**
|
|
547
|
-
* @internal
|
|
548
|
-
*/
|
|
549
|
-
_triggerAbortPromise?: Promise<void>;
|
|
550
|
-
/**
|
|
551
|
-
* @internal
|
|
552
|
-
*/
|
|
553
|
-
_triggerPromises?: Promise<void>[];
|
|
554
|
-
/**
|
|
555
|
-
* @internal
|
|
556
|
-
*/
|
|
557
|
-
_cbs: {
|
|
558
|
-
loaded: null | ((instance: T) => void | Promise<void>)[];
|
|
559
|
-
error: null | ((err?: Error) => void | Promise<void>)[];
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
type UseFunctionType<T, U> = T extends {
|
|
563
|
-
use: infer V;
|
|
564
|
-
} ? V extends (...args: any) => any ? ReturnType<V> : U : U;
|
|
565
|
-
interface UseScriptOptions<T extends BaseScriptApi = {}, U = {}> extends HeadEntryOptions {
|
|
566
|
-
/**
|
|
567
|
-
* Resolve the script instance from the window.
|
|
568
|
-
*/
|
|
569
|
-
use?: () => T | undefined | null;
|
|
570
|
-
/**
|
|
571
|
-
* Stub the script instance. Useful for SSR or testing.
|
|
572
|
-
*/
|
|
573
|
-
stub?: ((ctx: {
|
|
574
|
-
script: ScriptInstance<T>;
|
|
575
|
-
fn: string | symbol;
|
|
576
|
-
}) => any);
|
|
577
|
-
/**
|
|
578
|
-
* The trigger to load the script:
|
|
579
|
-
* - `undefined` | `client` - (Default) Load the script on the client when this js is loaded.
|
|
580
|
-
* - `manual` - Load the script manually by calling `$script.load()`, exists only on the client.
|
|
581
|
-
* - `Promise` - Load the script when the promise resolves, exists only on the client.
|
|
582
|
-
* - `Function` - Register a callback function to load the script, exists only on the client.
|
|
583
|
-
* - `server` - Have the script injected on the server.
|
|
584
|
-
*/
|
|
585
|
-
trigger?: 'client' | 'server' | 'manual' | Promise<boolean | void> | ((fn: any) => any) | null;
|
|
586
|
-
/**
|
|
587
|
-
* Context to run events with. This is useful in Vue to attach the current instance context before
|
|
588
|
-
* calling the event, allowing the event to be reactive.
|
|
589
|
-
*/
|
|
590
|
-
eventContext?: any;
|
|
591
|
-
/**
|
|
592
|
-
* Called before the script is initialized. Will not be triggered when the script is already loaded. This means
|
|
593
|
-
* this is guaranteed to be called only once, unless the script is removed and re-added.
|
|
594
|
-
*/
|
|
595
|
-
beforeInit?: () => void;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
export type { ActiveHeadEntry, AsAsyncFunctionValues, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateHeadOptions, DomBeforeRenderCtx, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginInput, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeFunctionEntries, Meta, Noscript, ProcessesTemplateParams, RenderSSRHeadOptions, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript, SchemaAugmentations, Script, ScriptInstance, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseFunctionType, UseScriptInput, UseScriptOptions, UseScriptResolvedInput, UseScriptStatus, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
|
|
518
|
+
export type { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateClientHeadOptions, CreateHeadOptions, DomBeforeRenderCtx, DomPluginOptions, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginInput, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeEventFnHandlers, Meta, Noscript, ProcessesTemplateParams, RenderDomHeadOptions, RenderSSRHeadOptions, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript, SchemaAugmentations, Script, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
|