@unhead/schema 1.3.9 → 1.4.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 +453 -0
- package/dist/index.d.mts +453 -0
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { MaybePromiseProps, MergeHead, BaseBodyAttributes, HtmlAttributes as HtmlAttributes$1, Meta as Meta$1, Stringable, Merge, Base as Base$1, DefinedValueOrEmptyObject, LinkBase, HttpEventAttributes, DataKeys, Style as Style$1, ScriptBase, Noscript as Noscript$1, BodyEvents, MetaFlatInput } from 'zhead';
|
|
2
|
+
export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInput, SpeculationRules } from 'zhead';
|
|
3
|
+
import { NestedHooks, Hookable } from 'hookable';
|
|
4
|
+
|
|
5
|
+
type HookResult = Promise<void> | void;
|
|
6
|
+
interface SSRHeadPayload {
|
|
7
|
+
headTags: string;
|
|
8
|
+
bodyTags: string;
|
|
9
|
+
bodyTagsOpen: string;
|
|
10
|
+
htmlAttrs: string;
|
|
11
|
+
bodyAttrs: string;
|
|
12
|
+
}
|
|
13
|
+
interface EntryResolveCtx<T> {
|
|
14
|
+
tags: HeadTag[];
|
|
15
|
+
entries: HeadEntry<T>[];
|
|
16
|
+
}
|
|
17
|
+
interface DomRenderTagContext {
|
|
18
|
+
id: string;
|
|
19
|
+
$el: Element;
|
|
20
|
+
shouldRender: boolean;
|
|
21
|
+
tag: HeadTag;
|
|
22
|
+
entry?: HeadEntry<any>;
|
|
23
|
+
markSideEffect: (key: string, fn: () => void) => void;
|
|
24
|
+
}
|
|
25
|
+
interface DomBeforeRenderCtx extends ShouldRenderContext {
|
|
26
|
+
tags: DomRenderTagContext[];
|
|
27
|
+
}
|
|
28
|
+
interface ShouldRenderContext {
|
|
29
|
+
shouldRender: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface SSRRenderContext {
|
|
32
|
+
tags: HeadTag[];
|
|
33
|
+
html: SSRHeadPayload;
|
|
34
|
+
}
|
|
35
|
+
interface HeadHooks {
|
|
36
|
+
'init': (ctx: Unhead<any>) => HookResult;
|
|
37
|
+
'entries:updated': (ctx: Unhead<any>) => HookResult;
|
|
38
|
+
'entries:resolve': (ctx: EntryResolveCtx<any>) => HookResult;
|
|
39
|
+
'tag:normalise': (ctx: {
|
|
40
|
+
tag: HeadTag;
|
|
41
|
+
entry: HeadEntry<any>;
|
|
42
|
+
resolvedOptions: CreateHeadOptions;
|
|
43
|
+
}) => HookResult;
|
|
44
|
+
'tags:beforeResolve': (ctx: {
|
|
45
|
+
tags: HeadTag[];
|
|
46
|
+
}) => HookResult;
|
|
47
|
+
'tags:resolve': (ctx: {
|
|
48
|
+
tags: HeadTag[];
|
|
49
|
+
}) => HookResult;
|
|
50
|
+
'dom:beforeRender': (ctx: ShouldRenderContext & {
|
|
51
|
+
tags: DomRenderTagContext[];
|
|
52
|
+
}) => HookResult;
|
|
53
|
+
'dom:renderTag': (ctx: DomRenderTagContext, document: Document, track: any) => HookResult;
|
|
54
|
+
'dom:rendered': (ctx: {
|
|
55
|
+
renders: DomRenderTagContext[];
|
|
56
|
+
}) => HookResult;
|
|
57
|
+
'ssr:beforeRender': (ctx: ShouldRenderContext) => HookResult;
|
|
58
|
+
'ssr:render': (ctx: {
|
|
59
|
+
tags: HeadTag[];
|
|
60
|
+
}) => HookResult;
|
|
61
|
+
'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Side effects are mapped with a key and their cleanup function.
|
|
66
|
+
*
|
|
67
|
+
* For example, `meta:data-h-4h46h465`: () => { document.querySelector('meta[data-h-4h46h465]').remove() }
|
|
68
|
+
*/
|
|
69
|
+
type SideEffectsRecord = Record<string, () => void>;
|
|
70
|
+
type RuntimeMode = 'server' | 'client';
|
|
71
|
+
interface HeadEntry<Input> {
|
|
72
|
+
/**
|
|
73
|
+
* User provided input for the entry.
|
|
74
|
+
*/
|
|
75
|
+
input: Input;
|
|
76
|
+
/**
|
|
77
|
+
* Optional resolved input which will be used if set.
|
|
78
|
+
*/
|
|
79
|
+
resolvedInput?: Input;
|
|
80
|
+
/**
|
|
81
|
+
* The mode that the entry should be used in.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
mode?: RuntimeMode;
|
|
86
|
+
/**
|
|
87
|
+
* Transformer function for the entry.
|
|
88
|
+
*
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
transform?: (input: Input) => Promise<Input> | Input;
|
|
92
|
+
/**
|
|
93
|
+
* Head entry index
|
|
94
|
+
*
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
_i: number;
|
|
98
|
+
/**
|
|
99
|
+
* Default tag position.
|
|
100
|
+
*
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
tagPosition?: TagPosition['tagPosition'];
|
|
104
|
+
/**
|
|
105
|
+
* Default tag priority.
|
|
106
|
+
*
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
tagPriority?: TagPriority['tagPriority'];
|
|
110
|
+
}
|
|
111
|
+
type HeadPluginOptions = Omit<CreateHeadOptions, 'plugins'> & {
|
|
112
|
+
mode?: RuntimeMode;
|
|
113
|
+
};
|
|
114
|
+
type HeadPlugin = HeadPluginOptions | ((head: Unhead) => HeadPluginOptions);
|
|
115
|
+
/**
|
|
116
|
+
* An active head entry provides an API to manipulate it.
|
|
117
|
+
*/
|
|
118
|
+
interface ActiveHeadEntry<Input> {
|
|
119
|
+
/**
|
|
120
|
+
* Updates the entry with new input.
|
|
121
|
+
*
|
|
122
|
+
* Will first clear any side effects for previous input.
|
|
123
|
+
*/
|
|
124
|
+
patch: (input: Input) => void;
|
|
125
|
+
/**
|
|
126
|
+
* Dispose the entry, removing it from the active head.
|
|
127
|
+
*
|
|
128
|
+
* Will queue side effects for removal.
|
|
129
|
+
*/
|
|
130
|
+
dispose: () => void;
|
|
131
|
+
}
|
|
132
|
+
interface CreateHeadOptions {
|
|
133
|
+
domDelayFn?: (fn: () => void) => void;
|
|
134
|
+
document?: Document;
|
|
135
|
+
plugins?: HeadPlugin[];
|
|
136
|
+
hooks?: NestedHooks<HeadHooks>;
|
|
137
|
+
}
|
|
138
|
+
interface HeadEntryOptions extends TagPosition, TagPriority {
|
|
139
|
+
mode?: RuntimeMode;
|
|
140
|
+
transform?: (input: unknown) => unknown;
|
|
141
|
+
}
|
|
142
|
+
interface Unhead<Input extends {} = Head> {
|
|
143
|
+
/**
|
|
144
|
+
* The active head entries.
|
|
145
|
+
*/
|
|
146
|
+
headEntries: () => HeadEntry<Input>[];
|
|
147
|
+
/**
|
|
148
|
+
* Create a new head entry.
|
|
149
|
+
*/
|
|
150
|
+
push: (entry: Input, options?: HeadEntryOptions) => ActiveHeadEntry<Input>;
|
|
151
|
+
/**
|
|
152
|
+
* Resolve tags from head entries.
|
|
153
|
+
*/
|
|
154
|
+
resolveTags: () => Promise<HeadTag[]>;
|
|
155
|
+
/**
|
|
156
|
+
* Exposed hooks for easier extension.
|
|
157
|
+
*/
|
|
158
|
+
hooks: Hookable<HeadHooks>;
|
|
159
|
+
/**
|
|
160
|
+
* Resolved options
|
|
161
|
+
*/
|
|
162
|
+
resolvedOptions: CreateHeadOptions;
|
|
163
|
+
/**
|
|
164
|
+
* Use a head plugin, loads the plugins hooks.
|
|
165
|
+
*/
|
|
166
|
+
use: (plugin: HeadPlugin) => void;
|
|
167
|
+
ssr: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
_dom?: DomState;
|
|
172
|
+
/**
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
_domUpdatePromise?: Promise<void>;
|
|
176
|
+
}
|
|
177
|
+
interface DomState {
|
|
178
|
+
pendingSideEffects: SideEffectsRecord;
|
|
179
|
+
sideEffects: SideEffectsRecord;
|
|
180
|
+
elMap: Record<string, Element>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface ResolvesDuplicates {
|
|
184
|
+
/**
|
|
185
|
+
* By default, tags which share the same unique key `name`, `property` are de-duped. To allow duplicates
|
|
186
|
+
* to be made you can provide a unique key for each entry.
|
|
187
|
+
*/
|
|
188
|
+
key?: string;
|
|
189
|
+
/**
|
|
190
|
+
* The strategy to use when a duplicate tag is encountered.
|
|
191
|
+
*
|
|
192
|
+
* - `replace` - Replace the existing tag with the new tag
|
|
193
|
+
* - `merge` - Merge the existing tag with the new tag
|
|
194
|
+
*
|
|
195
|
+
* @default 'replace' (some tags will default to 'merge', such as htmlAttr)
|
|
196
|
+
*/
|
|
197
|
+
tagDuplicateStrategy?: 'replace' | 'merge';
|
|
198
|
+
/**
|
|
199
|
+
* @deprecated Use `key` instead
|
|
200
|
+
*/
|
|
201
|
+
hid?: string;
|
|
202
|
+
/**
|
|
203
|
+
* @deprecated Use `key` instead
|
|
204
|
+
*/
|
|
205
|
+
vmid?: string;
|
|
206
|
+
}
|
|
207
|
+
type ValidTagPositions = 'head' | 'bodyClose' | 'bodyOpen';
|
|
208
|
+
interface TagPosition {
|
|
209
|
+
/**
|
|
210
|
+
* Specify where to render the tag.
|
|
211
|
+
*
|
|
212
|
+
* @default 'head'
|
|
213
|
+
*/
|
|
214
|
+
tagPosition?: ValidTagPositions;
|
|
215
|
+
}
|
|
216
|
+
type InnerContentVal = string | Record<string, any>;
|
|
217
|
+
interface InnerContent {
|
|
218
|
+
/**
|
|
219
|
+
* Text content of the tag.
|
|
220
|
+
*
|
|
221
|
+
* Warning: This is not safe for XSS. Do not use this with user input, use `textContent` instead.
|
|
222
|
+
*/
|
|
223
|
+
innerHTML?: InnerContentVal;
|
|
224
|
+
/**
|
|
225
|
+
* Sets the textContent of an element. Safer for XSS.
|
|
226
|
+
*/
|
|
227
|
+
textContent?: InnerContentVal;
|
|
228
|
+
/**
|
|
229
|
+
* Sets the textContent of an element.
|
|
230
|
+
*
|
|
231
|
+
* @deprecated Use `textContent` or `innerHTML`.
|
|
232
|
+
*/
|
|
233
|
+
children?: InnerContentVal;
|
|
234
|
+
}
|
|
235
|
+
interface TagPriority {
|
|
236
|
+
/**
|
|
237
|
+
* The priority for rendering the tag, without this all tags are rendered as they are registered
|
|
238
|
+
* (besides some special tags).
|
|
239
|
+
*
|
|
240
|
+
* The following special tags have default priorities:
|
|
241
|
+
* * -2 `<meta charset ...>`
|
|
242
|
+
* * -1 `<base>`
|
|
243
|
+
* * 0 `<meta http-equiv="content-security-policy" ...>`
|
|
244
|
+
*
|
|
245
|
+
* All other tags have a default priority of 10: `<meta>`, `<script>`, `<link>`, `<style>`, etc
|
|
246
|
+
*/
|
|
247
|
+
tagPriority?: number | 'critical' | 'high' | 'low' | `before:${string}` | `after:${string}`;
|
|
248
|
+
}
|
|
249
|
+
type TagUserProperties = TagPriority & TagPosition & MaybePromiseProps<InnerContent> & ResolvesDuplicates;
|
|
250
|
+
type TagKey = keyof Head;
|
|
251
|
+
type TemplateParams = {
|
|
252
|
+
separator?: string;
|
|
253
|
+
} & Record<string, null | string | Record<string, string>>;
|
|
254
|
+
interface HasTemplateParams {
|
|
255
|
+
templateParams?: TemplateParams;
|
|
256
|
+
}
|
|
257
|
+
interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTemplateParams {
|
|
258
|
+
tag: TagKey;
|
|
259
|
+
props: Record<string, string>;
|
|
260
|
+
innerHTML?: string;
|
|
261
|
+
textContent?: string;
|
|
262
|
+
/**
|
|
263
|
+
* Entry ID
|
|
264
|
+
* @internal
|
|
265
|
+
*/
|
|
266
|
+
_e?: number;
|
|
267
|
+
/**
|
|
268
|
+
* Position
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
_p?: number;
|
|
272
|
+
/**
|
|
273
|
+
* Dedupe key
|
|
274
|
+
* @internal
|
|
275
|
+
*/
|
|
276
|
+
_d?: string;
|
|
277
|
+
/**
|
|
278
|
+
* Hash code used to represent the tag.
|
|
279
|
+
* @internal
|
|
280
|
+
*/
|
|
281
|
+
_h?: string;
|
|
282
|
+
/**
|
|
283
|
+
* @internal
|
|
284
|
+
*/
|
|
285
|
+
_m?: RuntimeMode;
|
|
286
|
+
}
|
|
287
|
+
type HeadTagKeys = (keyof HeadTag)[];
|
|
288
|
+
|
|
289
|
+
type Never<T> = {
|
|
290
|
+
[P in keyof T]?: never;
|
|
291
|
+
};
|
|
292
|
+
type UserTagConfigWithoutInnerContent = TagPriority & TagPosition & ResolvesDuplicates & Never<InnerContent>;
|
|
293
|
+
type UserAttributesConfig = ResolvesDuplicates & TagPriority & Never<InnerContent & TagPosition>;
|
|
294
|
+
interface SchemaAugmentations extends MergeHead {
|
|
295
|
+
title: TagPriority;
|
|
296
|
+
titleTemplate: TagPriority;
|
|
297
|
+
base: UserAttributesConfig;
|
|
298
|
+
htmlAttrs: UserAttributesConfig;
|
|
299
|
+
bodyAttrs: UserAttributesConfig;
|
|
300
|
+
link: UserTagConfigWithoutInnerContent;
|
|
301
|
+
meta: UserTagConfigWithoutInnerContent;
|
|
302
|
+
style: TagUserProperties;
|
|
303
|
+
script: TagUserProperties;
|
|
304
|
+
noscript: TagUserProperties;
|
|
305
|
+
}
|
|
306
|
+
type MaybeArray<T> = T | T[];
|
|
307
|
+
type BaseBodyAttr = BaseBodyAttributes;
|
|
308
|
+
type BaseHtmlAttr = HtmlAttributes$1;
|
|
309
|
+
interface BodyAttr extends Omit<BaseBodyAttr, 'class'> {
|
|
310
|
+
/**
|
|
311
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
312
|
+
*
|
|
313
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
314
|
+
*/
|
|
315
|
+
class?: MaybeArray<string> | Record<string, boolean>;
|
|
316
|
+
}
|
|
317
|
+
interface HtmlAttr extends Omit<HtmlAttributes$1, 'class'> {
|
|
318
|
+
/**
|
|
319
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
320
|
+
*
|
|
321
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
322
|
+
*/
|
|
323
|
+
class?: MaybeArray<string> | Record<string, boolean>;
|
|
324
|
+
}
|
|
325
|
+
interface BaseMeta extends Omit<Meta$1, 'content'> {
|
|
326
|
+
/**
|
|
327
|
+
* This attribute contains the value for the http-equiv, name or property attribute, depending on which is used.
|
|
328
|
+
*
|
|
329
|
+
* You can provide an array of values to create multiple tags sharing the same name, property or http-equiv.
|
|
330
|
+
*
|
|
331
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#attr-content
|
|
332
|
+
*/
|
|
333
|
+
content?: MaybeArray<Stringable>;
|
|
334
|
+
}
|
|
335
|
+
type EntryAugmentation = undefined | Record<string, any>;
|
|
336
|
+
type MaybeFunctionEntries<T> = {
|
|
337
|
+
[key in keyof T]?: T[key] | ((e: Event) => void);
|
|
338
|
+
};
|
|
339
|
+
type TitleTemplateResolver = string | ((title?: string) => string | null);
|
|
340
|
+
type Title = MaybePromiseProps<string | ({
|
|
341
|
+
textContent: string;
|
|
342
|
+
} & SchemaAugmentations['title']) | null>;
|
|
343
|
+
type TitleTemplate = TitleTemplateResolver | null | ({
|
|
344
|
+
textContent: TitleTemplateResolver;
|
|
345
|
+
} & SchemaAugmentations['titleTemplate']);
|
|
346
|
+
type Base<E extends EntryAugmentation = {}> = Partial<Merge<SchemaAugmentations['base'], MaybePromiseProps<Base$1>>> & DefinedValueOrEmptyObject<E>;
|
|
347
|
+
type Link<E extends EntryAugmentation = {}> = MaybePromiseProps<LinkBase> & MaybeFunctionEntries<HttpEventAttributes> & DataKeys & SchemaAugmentations['link'] & DefinedValueOrEmptyObject<E>;
|
|
348
|
+
type Meta<E extends EntryAugmentation = {}> = MaybePromiseProps<BaseMeta> & DataKeys & SchemaAugmentations['meta'] & DefinedValueOrEmptyObject<E>;
|
|
349
|
+
type Style<E extends EntryAugmentation = {}> = MaybePromiseProps<Style$1> & DataKeys & SchemaAugmentations['style'] & DefinedValueOrEmptyObject<E>;
|
|
350
|
+
type Script<E extends EntryAugmentation = {}> = MaybePromiseProps<ScriptBase> & MaybeFunctionEntries<HttpEventAttributes> & DataKeys & SchemaAugmentations['script'] & DefinedValueOrEmptyObject<E>;
|
|
351
|
+
type Noscript<E extends EntryAugmentation = {}> = MaybePromiseProps<Noscript$1> & DataKeys & SchemaAugmentations['noscript'] & DefinedValueOrEmptyObject<E>;
|
|
352
|
+
type HtmlAttributes<E extends EntryAugmentation = {}> = MaybePromiseProps<HtmlAttr> & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
353
|
+
type BodyAttributes<E extends EntryAugmentation = {}> = MaybePromiseProps<BodyAttr> & MaybeFunctionEntries<BodyEvents> & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
354
|
+
interface HeadUtils {
|
|
355
|
+
/**
|
|
356
|
+
* Generate the title from a template.
|
|
357
|
+
*
|
|
358
|
+
* Should include a `%s` placeholder for the title, for example `%s - My Site`.
|
|
359
|
+
*/
|
|
360
|
+
titleTemplate?: TitleTemplate;
|
|
361
|
+
/**
|
|
362
|
+
* Variables used to substitute in the title and meta content.
|
|
363
|
+
*/
|
|
364
|
+
templateParams?: TemplateParams;
|
|
365
|
+
}
|
|
366
|
+
interface Head<E extends MergeHead = SchemaAugmentations> extends HeadUtils {
|
|
367
|
+
/**
|
|
368
|
+
* The `<title>` HTML element defines the document's title that is shown in a browser's title bar or a page's tab.
|
|
369
|
+
* It only contains text; tags within the element are ignored.
|
|
370
|
+
*
|
|
371
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
|
|
372
|
+
*/
|
|
373
|
+
title?: Title | Promise<Title>;
|
|
374
|
+
/**
|
|
375
|
+
* The `<base>` HTML element specifies the base URL to use for all relative URLs in a document.
|
|
376
|
+
* There can be only one <base> element in a document.
|
|
377
|
+
*
|
|
378
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
|
379
|
+
*/
|
|
380
|
+
base?: Base<E['base']>;
|
|
381
|
+
/**
|
|
382
|
+
* The `<link>` HTML element specifies relationships between the current document and an external resource.
|
|
383
|
+
* This element is most commonly used to link to stylesheets, but is also used to establish site icons
|
|
384
|
+
* (both "favicon" style icons and icons for the home screen and apps on mobile devices) among other things.
|
|
385
|
+
*
|
|
386
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as
|
|
387
|
+
*/
|
|
388
|
+
link?: Link<E['link']>[];
|
|
389
|
+
/**
|
|
390
|
+
* The `<meta>` element represents metadata that cannot be expressed in other HTML elements, like `<link>` or `<script>`.
|
|
391
|
+
*
|
|
392
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
|
|
393
|
+
*/
|
|
394
|
+
meta?: Meta<E['meta']>[];
|
|
395
|
+
/**
|
|
396
|
+
* The `<style>` HTML element contains style information for a document, or part of a document.
|
|
397
|
+
* It contains CSS, which is applied to the contents of the document containing the `<style>` element.
|
|
398
|
+
*
|
|
399
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
|
|
400
|
+
*/
|
|
401
|
+
style?: (Style<E['style']> | string)[];
|
|
402
|
+
/**
|
|
403
|
+
* The `<script>` HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code.
|
|
404
|
+
*
|
|
405
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
|
|
406
|
+
*/
|
|
407
|
+
script?: (Script<E['script']> | string)[];
|
|
408
|
+
/**
|
|
409
|
+
* The `<noscript>` HTML element defines a section of HTML to be inserted if a script type on the page is unsupported
|
|
410
|
+
* or if scripting is currently turned off in the browser.
|
|
411
|
+
*
|
|
412
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript
|
|
413
|
+
*/
|
|
414
|
+
noscript?: (Noscript<E['noscript']> | string)[];
|
|
415
|
+
/**
|
|
416
|
+
* Attributes for the `<html>` HTML element.
|
|
417
|
+
*
|
|
418
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html
|
|
419
|
+
*/
|
|
420
|
+
htmlAttrs?: HtmlAttributes<E['htmlAttrs']>;
|
|
421
|
+
/**
|
|
422
|
+
* Attributes for the `<body>` HTML element.
|
|
423
|
+
*
|
|
424
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body
|
|
425
|
+
*/
|
|
426
|
+
bodyAttrs?: BodyAttributes<E['bodyAttrs']>;
|
|
427
|
+
}
|
|
428
|
+
type UseSeoMetaInput = MetaFlatInput & {
|
|
429
|
+
title?: Title;
|
|
430
|
+
titleTemplate?: TitleTemplate;
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
type SafeBodyAttr = Pick<BodyAttr, 'id' | 'class'> & DataKeys;
|
|
434
|
+
type SafeHtmlAttr = Pick<HtmlAttr, 'id' | 'class' | 'lang' | 'dir'> & DataKeys;
|
|
435
|
+
type SafeMeta = Pick<Meta, 'id' | 'name' | 'property' | 'content'> & DataKeys;
|
|
436
|
+
type SafeLink = Pick<Link, 'color' | 'crossorigin' | 'fetchpriority' | 'href' | 'hreflang' | 'imagesizes' | 'imagesrcset' | 'integrity' | 'media' | 'referrerpolicy' | 'sizes' | 'id'> & {
|
|
437
|
+
rel?: Omit<Link['rel'], 'stylesheet' | 'canonical' | 'modulepreload' | 'prerender' | 'preload' | 'prefetch'>;
|
|
438
|
+
type?: 'audio/aac' | 'application/x-abiword' | 'application/x-freearc' | 'image/avif' | 'video/x-msvideo' | 'application/vnd.amazon.ebook' | 'application/octet-stream' | 'image/bmp' | 'application/x-bzip' | 'application/x-bzip2' | 'application/x-cdf' | 'application/x-csh' | 'text/csv' | 'application/msword' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/vnd.ms-fontobject' | 'application/epub+zip' | 'application/gzip' | 'image/gif' | 'image/vnd.microsoft.icon' | 'text/calendar' | 'application/java-archive' | 'image/jpeg' | 'application/json' | 'application/ld+json' | 'audio/midi' | 'audio/x-midi' | 'audio/mpeg' | 'video/mp4' | 'video/mpeg' | 'application/vnd.apple.installer+xml' | 'application/vnd.oasis.opendocument.presentation' | 'application/vnd.oasis.opendocument.spreadsheet' | 'application/vnd.oasis.opendocument.text' | 'audio/ogg' | 'video/ogg' | 'application/ogg' | 'audio/opus' | 'font/otf' | 'image/png' | 'application/pdf' | 'application/x-httpd-php' | 'application/vnd.ms-powerpoint' | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' | 'application/vnd.rar' | 'application/rtf' | 'application/x-sh' | 'image/svg+xml' | 'application/x-tar' | 'image/tiff' | 'video/mp2t' | 'font/ttf' | 'text/plain' | 'application/vnd.visio' | 'audio/wav' | 'audio/webm' | 'video/webm' | 'image/webp' | 'font/woff' | 'font/woff2' | 'application/xhtml+xml' | 'application/vnd.ms-excel' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'text/xml' | 'application/atom+xml' | 'application/xml' | 'application/vnd.mozilla.xul+xml' | 'application/zip' | 'video/3gpp' | 'audio/3gpp' | 'video/3gpp2' | 'audio/3gpp2' | (string & Record<never, never>);
|
|
439
|
+
} & DataKeys;
|
|
440
|
+
type SafeScript = Pick<Script, 'id' | 'textContent'> & {
|
|
441
|
+
type: 'application/json' | 'application/ld+json';
|
|
442
|
+
} & DataKeys;
|
|
443
|
+
type SafeNoscript = Pick<Noscript, 'id' | 'textContent'> & DataKeys;
|
|
444
|
+
interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParams'> {
|
|
445
|
+
meta?: SafeMeta[];
|
|
446
|
+
link?: SafeLink[];
|
|
447
|
+
noscript?: SafeNoscript[];
|
|
448
|
+
script?: SafeScript[];
|
|
449
|
+
htmlAttrs?: SafeHtmlAttr;
|
|
450
|
+
bodyAttrs?: SafeBodyAttr;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export type { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateHeadOptions, DomBeforeRenderCtx, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeFunctionEntries, Meta, Never, Noscript, 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
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { MaybePromiseProps, MergeHead, BaseBodyAttributes, HtmlAttributes as HtmlAttributes$1, Meta as Meta$1, Stringable, Merge, Base as Base$1, DefinedValueOrEmptyObject, LinkBase, HttpEventAttributes, DataKeys, Style as Style$1, ScriptBase, Noscript as Noscript$1, BodyEvents, MetaFlatInput } from 'zhead';
|
|
2
|
+
export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInput, SpeculationRules } from 'zhead';
|
|
3
|
+
import { NestedHooks, Hookable } from 'hookable';
|
|
4
|
+
|
|
5
|
+
type HookResult = Promise<void> | void;
|
|
6
|
+
interface SSRHeadPayload {
|
|
7
|
+
headTags: string;
|
|
8
|
+
bodyTags: string;
|
|
9
|
+
bodyTagsOpen: string;
|
|
10
|
+
htmlAttrs: string;
|
|
11
|
+
bodyAttrs: string;
|
|
12
|
+
}
|
|
13
|
+
interface EntryResolveCtx<T> {
|
|
14
|
+
tags: HeadTag[];
|
|
15
|
+
entries: HeadEntry<T>[];
|
|
16
|
+
}
|
|
17
|
+
interface DomRenderTagContext {
|
|
18
|
+
id: string;
|
|
19
|
+
$el: Element;
|
|
20
|
+
shouldRender: boolean;
|
|
21
|
+
tag: HeadTag;
|
|
22
|
+
entry?: HeadEntry<any>;
|
|
23
|
+
markSideEffect: (key: string, fn: () => void) => void;
|
|
24
|
+
}
|
|
25
|
+
interface DomBeforeRenderCtx extends ShouldRenderContext {
|
|
26
|
+
tags: DomRenderTagContext[];
|
|
27
|
+
}
|
|
28
|
+
interface ShouldRenderContext {
|
|
29
|
+
shouldRender: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface SSRRenderContext {
|
|
32
|
+
tags: HeadTag[];
|
|
33
|
+
html: SSRHeadPayload;
|
|
34
|
+
}
|
|
35
|
+
interface HeadHooks {
|
|
36
|
+
'init': (ctx: Unhead<any>) => HookResult;
|
|
37
|
+
'entries:updated': (ctx: Unhead<any>) => HookResult;
|
|
38
|
+
'entries:resolve': (ctx: EntryResolveCtx<any>) => HookResult;
|
|
39
|
+
'tag:normalise': (ctx: {
|
|
40
|
+
tag: HeadTag;
|
|
41
|
+
entry: HeadEntry<any>;
|
|
42
|
+
resolvedOptions: CreateHeadOptions;
|
|
43
|
+
}) => HookResult;
|
|
44
|
+
'tags:beforeResolve': (ctx: {
|
|
45
|
+
tags: HeadTag[];
|
|
46
|
+
}) => HookResult;
|
|
47
|
+
'tags:resolve': (ctx: {
|
|
48
|
+
tags: HeadTag[];
|
|
49
|
+
}) => HookResult;
|
|
50
|
+
'dom:beforeRender': (ctx: ShouldRenderContext & {
|
|
51
|
+
tags: DomRenderTagContext[];
|
|
52
|
+
}) => HookResult;
|
|
53
|
+
'dom:renderTag': (ctx: DomRenderTagContext, document: Document, track: any) => HookResult;
|
|
54
|
+
'dom:rendered': (ctx: {
|
|
55
|
+
renders: DomRenderTagContext[];
|
|
56
|
+
}) => HookResult;
|
|
57
|
+
'ssr:beforeRender': (ctx: ShouldRenderContext) => HookResult;
|
|
58
|
+
'ssr:render': (ctx: {
|
|
59
|
+
tags: HeadTag[];
|
|
60
|
+
}) => HookResult;
|
|
61
|
+
'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Side effects are mapped with a key and their cleanup function.
|
|
66
|
+
*
|
|
67
|
+
* For example, `meta:data-h-4h46h465`: () => { document.querySelector('meta[data-h-4h46h465]').remove() }
|
|
68
|
+
*/
|
|
69
|
+
type SideEffectsRecord = Record<string, () => void>;
|
|
70
|
+
type RuntimeMode = 'server' | 'client';
|
|
71
|
+
interface HeadEntry<Input> {
|
|
72
|
+
/**
|
|
73
|
+
* User provided input for the entry.
|
|
74
|
+
*/
|
|
75
|
+
input: Input;
|
|
76
|
+
/**
|
|
77
|
+
* Optional resolved input which will be used if set.
|
|
78
|
+
*/
|
|
79
|
+
resolvedInput?: Input;
|
|
80
|
+
/**
|
|
81
|
+
* The mode that the entry should be used in.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
mode?: RuntimeMode;
|
|
86
|
+
/**
|
|
87
|
+
* Transformer function for the entry.
|
|
88
|
+
*
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
transform?: (input: Input) => Promise<Input> | Input;
|
|
92
|
+
/**
|
|
93
|
+
* Head entry index
|
|
94
|
+
*
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
_i: number;
|
|
98
|
+
/**
|
|
99
|
+
* Default tag position.
|
|
100
|
+
*
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
tagPosition?: TagPosition['tagPosition'];
|
|
104
|
+
/**
|
|
105
|
+
* Default tag priority.
|
|
106
|
+
*
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
tagPriority?: TagPriority['tagPriority'];
|
|
110
|
+
}
|
|
111
|
+
type HeadPluginOptions = Omit<CreateHeadOptions, 'plugins'> & {
|
|
112
|
+
mode?: RuntimeMode;
|
|
113
|
+
};
|
|
114
|
+
type HeadPlugin = HeadPluginOptions | ((head: Unhead) => HeadPluginOptions);
|
|
115
|
+
/**
|
|
116
|
+
* An active head entry provides an API to manipulate it.
|
|
117
|
+
*/
|
|
118
|
+
interface ActiveHeadEntry<Input> {
|
|
119
|
+
/**
|
|
120
|
+
* Updates the entry with new input.
|
|
121
|
+
*
|
|
122
|
+
* Will first clear any side effects for previous input.
|
|
123
|
+
*/
|
|
124
|
+
patch: (input: Input) => void;
|
|
125
|
+
/**
|
|
126
|
+
* Dispose the entry, removing it from the active head.
|
|
127
|
+
*
|
|
128
|
+
* Will queue side effects for removal.
|
|
129
|
+
*/
|
|
130
|
+
dispose: () => void;
|
|
131
|
+
}
|
|
132
|
+
interface CreateHeadOptions {
|
|
133
|
+
domDelayFn?: (fn: () => void) => void;
|
|
134
|
+
document?: Document;
|
|
135
|
+
plugins?: HeadPlugin[];
|
|
136
|
+
hooks?: NestedHooks<HeadHooks>;
|
|
137
|
+
}
|
|
138
|
+
interface HeadEntryOptions extends TagPosition, TagPriority {
|
|
139
|
+
mode?: RuntimeMode;
|
|
140
|
+
transform?: (input: unknown) => unknown;
|
|
141
|
+
}
|
|
142
|
+
interface Unhead<Input extends {} = Head> {
|
|
143
|
+
/**
|
|
144
|
+
* The active head entries.
|
|
145
|
+
*/
|
|
146
|
+
headEntries: () => HeadEntry<Input>[];
|
|
147
|
+
/**
|
|
148
|
+
* Create a new head entry.
|
|
149
|
+
*/
|
|
150
|
+
push: (entry: Input, options?: HeadEntryOptions) => ActiveHeadEntry<Input>;
|
|
151
|
+
/**
|
|
152
|
+
* Resolve tags from head entries.
|
|
153
|
+
*/
|
|
154
|
+
resolveTags: () => Promise<HeadTag[]>;
|
|
155
|
+
/**
|
|
156
|
+
* Exposed hooks for easier extension.
|
|
157
|
+
*/
|
|
158
|
+
hooks: Hookable<HeadHooks>;
|
|
159
|
+
/**
|
|
160
|
+
* Resolved options
|
|
161
|
+
*/
|
|
162
|
+
resolvedOptions: CreateHeadOptions;
|
|
163
|
+
/**
|
|
164
|
+
* Use a head plugin, loads the plugins hooks.
|
|
165
|
+
*/
|
|
166
|
+
use: (plugin: HeadPlugin) => void;
|
|
167
|
+
ssr: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
_dom?: DomState;
|
|
172
|
+
/**
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
_domUpdatePromise?: Promise<void>;
|
|
176
|
+
}
|
|
177
|
+
interface DomState {
|
|
178
|
+
pendingSideEffects: SideEffectsRecord;
|
|
179
|
+
sideEffects: SideEffectsRecord;
|
|
180
|
+
elMap: Record<string, Element>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface ResolvesDuplicates {
|
|
184
|
+
/**
|
|
185
|
+
* By default, tags which share the same unique key `name`, `property` are de-duped. To allow duplicates
|
|
186
|
+
* to be made you can provide a unique key for each entry.
|
|
187
|
+
*/
|
|
188
|
+
key?: string;
|
|
189
|
+
/**
|
|
190
|
+
* The strategy to use when a duplicate tag is encountered.
|
|
191
|
+
*
|
|
192
|
+
* - `replace` - Replace the existing tag with the new tag
|
|
193
|
+
* - `merge` - Merge the existing tag with the new tag
|
|
194
|
+
*
|
|
195
|
+
* @default 'replace' (some tags will default to 'merge', such as htmlAttr)
|
|
196
|
+
*/
|
|
197
|
+
tagDuplicateStrategy?: 'replace' | 'merge';
|
|
198
|
+
/**
|
|
199
|
+
* @deprecated Use `key` instead
|
|
200
|
+
*/
|
|
201
|
+
hid?: string;
|
|
202
|
+
/**
|
|
203
|
+
* @deprecated Use `key` instead
|
|
204
|
+
*/
|
|
205
|
+
vmid?: string;
|
|
206
|
+
}
|
|
207
|
+
type ValidTagPositions = 'head' | 'bodyClose' | 'bodyOpen';
|
|
208
|
+
interface TagPosition {
|
|
209
|
+
/**
|
|
210
|
+
* Specify where to render the tag.
|
|
211
|
+
*
|
|
212
|
+
* @default 'head'
|
|
213
|
+
*/
|
|
214
|
+
tagPosition?: ValidTagPositions;
|
|
215
|
+
}
|
|
216
|
+
type InnerContentVal = string | Record<string, any>;
|
|
217
|
+
interface InnerContent {
|
|
218
|
+
/**
|
|
219
|
+
* Text content of the tag.
|
|
220
|
+
*
|
|
221
|
+
* Warning: This is not safe for XSS. Do not use this with user input, use `textContent` instead.
|
|
222
|
+
*/
|
|
223
|
+
innerHTML?: InnerContentVal;
|
|
224
|
+
/**
|
|
225
|
+
* Sets the textContent of an element. Safer for XSS.
|
|
226
|
+
*/
|
|
227
|
+
textContent?: InnerContentVal;
|
|
228
|
+
/**
|
|
229
|
+
* Sets the textContent of an element.
|
|
230
|
+
*
|
|
231
|
+
* @deprecated Use `textContent` or `innerHTML`.
|
|
232
|
+
*/
|
|
233
|
+
children?: InnerContentVal;
|
|
234
|
+
}
|
|
235
|
+
interface TagPriority {
|
|
236
|
+
/**
|
|
237
|
+
* The priority for rendering the tag, without this all tags are rendered as they are registered
|
|
238
|
+
* (besides some special tags).
|
|
239
|
+
*
|
|
240
|
+
* The following special tags have default priorities:
|
|
241
|
+
* * -2 `<meta charset ...>`
|
|
242
|
+
* * -1 `<base>`
|
|
243
|
+
* * 0 `<meta http-equiv="content-security-policy" ...>`
|
|
244
|
+
*
|
|
245
|
+
* All other tags have a default priority of 10: `<meta>`, `<script>`, `<link>`, `<style>`, etc
|
|
246
|
+
*/
|
|
247
|
+
tagPriority?: number | 'critical' | 'high' | 'low' | `before:${string}` | `after:${string}`;
|
|
248
|
+
}
|
|
249
|
+
type TagUserProperties = TagPriority & TagPosition & MaybePromiseProps<InnerContent> & ResolvesDuplicates;
|
|
250
|
+
type TagKey = keyof Head;
|
|
251
|
+
type TemplateParams = {
|
|
252
|
+
separator?: string;
|
|
253
|
+
} & Record<string, null | string | Record<string, string>>;
|
|
254
|
+
interface HasTemplateParams {
|
|
255
|
+
templateParams?: TemplateParams;
|
|
256
|
+
}
|
|
257
|
+
interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTemplateParams {
|
|
258
|
+
tag: TagKey;
|
|
259
|
+
props: Record<string, string>;
|
|
260
|
+
innerHTML?: string;
|
|
261
|
+
textContent?: string;
|
|
262
|
+
/**
|
|
263
|
+
* Entry ID
|
|
264
|
+
* @internal
|
|
265
|
+
*/
|
|
266
|
+
_e?: number;
|
|
267
|
+
/**
|
|
268
|
+
* Position
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
_p?: number;
|
|
272
|
+
/**
|
|
273
|
+
* Dedupe key
|
|
274
|
+
* @internal
|
|
275
|
+
*/
|
|
276
|
+
_d?: string;
|
|
277
|
+
/**
|
|
278
|
+
* Hash code used to represent the tag.
|
|
279
|
+
* @internal
|
|
280
|
+
*/
|
|
281
|
+
_h?: string;
|
|
282
|
+
/**
|
|
283
|
+
* @internal
|
|
284
|
+
*/
|
|
285
|
+
_m?: RuntimeMode;
|
|
286
|
+
}
|
|
287
|
+
type HeadTagKeys = (keyof HeadTag)[];
|
|
288
|
+
|
|
289
|
+
type Never<T> = {
|
|
290
|
+
[P in keyof T]?: never;
|
|
291
|
+
};
|
|
292
|
+
type UserTagConfigWithoutInnerContent = TagPriority & TagPosition & ResolvesDuplicates & Never<InnerContent>;
|
|
293
|
+
type UserAttributesConfig = ResolvesDuplicates & TagPriority & Never<InnerContent & TagPosition>;
|
|
294
|
+
interface SchemaAugmentations extends MergeHead {
|
|
295
|
+
title: TagPriority;
|
|
296
|
+
titleTemplate: TagPriority;
|
|
297
|
+
base: UserAttributesConfig;
|
|
298
|
+
htmlAttrs: UserAttributesConfig;
|
|
299
|
+
bodyAttrs: UserAttributesConfig;
|
|
300
|
+
link: UserTagConfigWithoutInnerContent;
|
|
301
|
+
meta: UserTagConfigWithoutInnerContent;
|
|
302
|
+
style: TagUserProperties;
|
|
303
|
+
script: TagUserProperties;
|
|
304
|
+
noscript: TagUserProperties;
|
|
305
|
+
}
|
|
306
|
+
type MaybeArray<T> = T | T[];
|
|
307
|
+
type BaseBodyAttr = BaseBodyAttributes;
|
|
308
|
+
type BaseHtmlAttr = HtmlAttributes$1;
|
|
309
|
+
interface BodyAttr extends Omit<BaseBodyAttr, 'class'> {
|
|
310
|
+
/**
|
|
311
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
312
|
+
*
|
|
313
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
314
|
+
*/
|
|
315
|
+
class?: MaybeArray<string> | Record<string, boolean>;
|
|
316
|
+
}
|
|
317
|
+
interface HtmlAttr extends Omit<HtmlAttributes$1, 'class'> {
|
|
318
|
+
/**
|
|
319
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
320
|
+
*
|
|
321
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
322
|
+
*/
|
|
323
|
+
class?: MaybeArray<string> | Record<string, boolean>;
|
|
324
|
+
}
|
|
325
|
+
interface BaseMeta extends Omit<Meta$1, 'content'> {
|
|
326
|
+
/**
|
|
327
|
+
* This attribute contains the value for the http-equiv, name or property attribute, depending on which is used.
|
|
328
|
+
*
|
|
329
|
+
* You can provide an array of values to create multiple tags sharing the same name, property or http-equiv.
|
|
330
|
+
*
|
|
331
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#attr-content
|
|
332
|
+
*/
|
|
333
|
+
content?: MaybeArray<Stringable>;
|
|
334
|
+
}
|
|
335
|
+
type EntryAugmentation = undefined | Record<string, any>;
|
|
336
|
+
type MaybeFunctionEntries<T> = {
|
|
337
|
+
[key in keyof T]?: T[key] | ((e: Event) => void);
|
|
338
|
+
};
|
|
339
|
+
type TitleTemplateResolver = string | ((title?: string) => string | null);
|
|
340
|
+
type Title = MaybePromiseProps<string | ({
|
|
341
|
+
textContent: string;
|
|
342
|
+
} & SchemaAugmentations['title']) | null>;
|
|
343
|
+
type TitleTemplate = TitleTemplateResolver | null | ({
|
|
344
|
+
textContent: TitleTemplateResolver;
|
|
345
|
+
} & SchemaAugmentations['titleTemplate']);
|
|
346
|
+
type Base<E extends EntryAugmentation = {}> = Partial<Merge<SchemaAugmentations['base'], MaybePromiseProps<Base$1>>> & DefinedValueOrEmptyObject<E>;
|
|
347
|
+
type Link<E extends EntryAugmentation = {}> = MaybePromiseProps<LinkBase> & MaybeFunctionEntries<HttpEventAttributes> & DataKeys & SchemaAugmentations['link'] & DefinedValueOrEmptyObject<E>;
|
|
348
|
+
type Meta<E extends EntryAugmentation = {}> = MaybePromiseProps<BaseMeta> & DataKeys & SchemaAugmentations['meta'] & DefinedValueOrEmptyObject<E>;
|
|
349
|
+
type Style<E extends EntryAugmentation = {}> = MaybePromiseProps<Style$1> & DataKeys & SchemaAugmentations['style'] & DefinedValueOrEmptyObject<E>;
|
|
350
|
+
type Script<E extends EntryAugmentation = {}> = MaybePromiseProps<ScriptBase> & MaybeFunctionEntries<HttpEventAttributes> & DataKeys & SchemaAugmentations['script'] & DefinedValueOrEmptyObject<E>;
|
|
351
|
+
type Noscript<E extends EntryAugmentation = {}> = MaybePromiseProps<Noscript$1> & DataKeys & SchemaAugmentations['noscript'] & DefinedValueOrEmptyObject<E>;
|
|
352
|
+
type HtmlAttributes<E extends EntryAugmentation = {}> = MaybePromiseProps<HtmlAttr> & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
353
|
+
type BodyAttributes<E extends EntryAugmentation = {}> = MaybePromiseProps<BodyAttr> & MaybeFunctionEntries<BodyEvents> & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
354
|
+
interface HeadUtils {
|
|
355
|
+
/**
|
|
356
|
+
* Generate the title from a template.
|
|
357
|
+
*
|
|
358
|
+
* Should include a `%s` placeholder for the title, for example `%s - My Site`.
|
|
359
|
+
*/
|
|
360
|
+
titleTemplate?: TitleTemplate;
|
|
361
|
+
/**
|
|
362
|
+
* Variables used to substitute in the title and meta content.
|
|
363
|
+
*/
|
|
364
|
+
templateParams?: TemplateParams;
|
|
365
|
+
}
|
|
366
|
+
interface Head<E extends MergeHead = SchemaAugmentations> extends HeadUtils {
|
|
367
|
+
/**
|
|
368
|
+
* The `<title>` HTML element defines the document's title that is shown in a browser's title bar or a page's tab.
|
|
369
|
+
* It only contains text; tags within the element are ignored.
|
|
370
|
+
*
|
|
371
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
|
|
372
|
+
*/
|
|
373
|
+
title?: Title | Promise<Title>;
|
|
374
|
+
/**
|
|
375
|
+
* The `<base>` HTML element specifies the base URL to use for all relative URLs in a document.
|
|
376
|
+
* There can be only one <base> element in a document.
|
|
377
|
+
*
|
|
378
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
|
379
|
+
*/
|
|
380
|
+
base?: Base<E['base']>;
|
|
381
|
+
/**
|
|
382
|
+
* The `<link>` HTML element specifies relationships between the current document and an external resource.
|
|
383
|
+
* This element is most commonly used to link to stylesheets, but is also used to establish site icons
|
|
384
|
+
* (both "favicon" style icons and icons for the home screen and apps on mobile devices) among other things.
|
|
385
|
+
*
|
|
386
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as
|
|
387
|
+
*/
|
|
388
|
+
link?: Link<E['link']>[];
|
|
389
|
+
/**
|
|
390
|
+
* The `<meta>` element represents metadata that cannot be expressed in other HTML elements, like `<link>` or `<script>`.
|
|
391
|
+
*
|
|
392
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
|
|
393
|
+
*/
|
|
394
|
+
meta?: Meta<E['meta']>[];
|
|
395
|
+
/**
|
|
396
|
+
* The `<style>` HTML element contains style information for a document, or part of a document.
|
|
397
|
+
* It contains CSS, which is applied to the contents of the document containing the `<style>` element.
|
|
398
|
+
*
|
|
399
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
|
|
400
|
+
*/
|
|
401
|
+
style?: (Style<E['style']> | string)[];
|
|
402
|
+
/**
|
|
403
|
+
* The `<script>` HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code.
|
|
404
|
+
*
|
|
405
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
|
|
406
|
+
*/
|
|
407
|
+
script?: (Script<E['script']> | string)[];
|
|
408
|
+
/**
|
|
409
|
+
* The `<noscript>` HTML element defines a section of HTML to be inserted if a script type on the page is unsupported
|
|
410
|
+
* or if scripting is currently turned off in the browser.
|
|
411
|
+
*
|
|
412
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript
|
|
413
|
+
*/
|
|
414
|
+
noscript?: (Noscript<E['noscript']> | string)[];
|
|
415
|
+
/**
|
|
416
|
+
* Attributes for the `<html>` HTML element.
|
|
417
|
+
*
|
|
418
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html
|
|
419
|
+
*/
|
|
420
|
+
htmlAttrs?: HtmlAttributes<E['htmlAttrs']>;
|
|
421
|
+
/**
|
|
422
|
+
* Attributes for the `<body>` HTML element.
|
|
423
|
+
*
|
|
424
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body
|
|
425
|
+
*/
|
|
426
|
+
bodyAttrs?: BodyAttributes<E['bodyAttrs']>;
|
|
427
|
+
}
|
|
428
|
+
type UseSeoMetaInput = MetaFlatInput & {
|
|
429
|
+
title?: Title;
|
|
430
|
+
titleTemplate?: TitleTemplate;
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
type SafeBodyAttr = Pick<BodyAttr, 'id' | 'class'> & DataKeys;
|
|
434
|
+
type SafeHtmlAttr = Pick<HtmlAttr, 'id' | 'class' | 'lang' | 'dir'> & DataKeys;
|
|
435
|
+
type SafeMeta = Pick<Meta, 'id' | 'name' | 'property' | 'content'> & DataKeys;
|
|
436
|
+
type SafeLink = Pick<Link, 'color' | 'crossorigin' | 'fetchpriority' | 'href' | 'hreflang' | 'imagesizes' | 'imagesrcset' | 'integrity' | 'media' | 'referrerpolicy' | 'sizes' | 'id'> & {
|
|
437
|
+
rel?: Omit<Link['rel'], 'stylesheet' | 'canonical' | 'modulepreload' | 'prerender' | 'preload' | 'prefetch'>;
|
|
438
|
+
type?: 'audio/aac' | 'application/x-abiword' | 'application/x-freearc' | 'image/avif' | 'video/x-msvideo' | 'application/vnd.amazon.ebook' | 'application/octet-stream' | 'image/bmp' | 'application/x-bzip' | 'application/x-bzip2' | 'application/x-cdf' | 'application/x-csh' | 'text/csv' | 'application/msword' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/vnd.ms-fontobject' | 'application/epub+zip' | 'application/gzip' | 'image/gif' | 'image/vnd.microsoft.icon' | 'text/calendar' | 'application/java-archive' | 'image/jpeg' | 'application/json' | 'application/ld+json' | 'audio/midi' | 'audio/x-midi' | 'audio/mpeg' | 'video/mp4' | 'video/mpeg' | 'application/vnd.apple.installer+xml' | 'application/vnd.oasis.opendocument.presentation' | 'application/vnd.oasis.opendocument.spreadsheet' | 'application/vnd.oasis.opendocument.text' | 'audio/ogg' | 'video/ogg' | 'application/ogg' | 'audio/opus' | 'font/otf' | 'image/png' | 'application/pdf' | 'application/x-httpd-php' | 'application/vnd.ms-powerpoint' | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' | 'application/vnd.rar' | 'application/rtf' | 'application/x-sh' | 'image/svg+xml' | 'application/x-tar' | 'image/tiff' | 'video/mp2t' | 'font/ttf' | 'text/plain' | 'application/vnd.visio' | 'audio/wav' | 'audio/webm' | 'video/webm' | 'image/webp' | 'font/woff' | 'font/woff2' | 'application/xhtml+xml' | 'application/vnd.ms-excel' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'text/xml' | 'application/atom+xml' | 'application/xml' | 'application/vnd.mozilla.xul+xml' | 'application/zip' | 'video/3gpp' | 'audio/3gpp' | 'video/3gpp2' | 'audio/3gpp2' | (string & Record<never, never>);
|
|
439
|
+
} & DataKeys;
|
|
440
|
+
type SafeScript = Pick<Script, 'id' | 'textContent'> & {
|
|
441
|
+
type: 'application/json' | 'application/ld+json';
|
|
442
|
+
} & DataKeys;
|
|
443
|
+
type SafeNoscript = Pick<Noscript, 'id' | 'textContent'> & DataKeys;
|
|
444
|
+
interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParams'> {
|
|
445
|
+
meta?: SafeMeta[];
|
|
446
|
+
link?: SafeLink[];
|
|
447
|
+
noscript?: SafeNoscript[];
|
|
448
|
+
script?: SafeScript[];
|
|
449
|
+
htmlAttrs?: SafeHtmlAttr;
|
|
450
|
+
bodyAttrs?: SafeBodyAttr;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export type { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateHeadOptions, DomBeforeRenderCtx, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeFunctionEntries, Meta, Never, Noscript, 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
|
@@ -450,4 +450,4 @@ interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParam
|
|
|
450
450
|
bodyAttrs?: SafeBodyAttr;
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
-
export { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateHeadOptions, DomBeforeRenderCtx, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeFunctionEntries, Meta, Never, Noscript, 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 };
|
|
453
|
+
export type { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateHeadOptions, DomBeforeRenderCtx, DomRenderTagContext, DomState, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadPluginOptions, HeadSafe, HeadTag, HeadTagKeys, HeadUtils, HookResult, HtmlAttr, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeFunctionEntries, Meta, Never, Noscript, 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 };
|