@unhead/schema 1.0.22 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +74 -24
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MaybePromiseProps,
|
|
2
|
-
export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInput, SpeculationRules
|
|
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 } from 'zhead';
|
|
2
|
+
export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInput, SpeculationRules } from 'zhead';
|
|
3
3
|
import { NestedHooks, Hookable } from 'hookable';
|
|
4
4
|
|
|
5
5
|
interface ResolvesDuplicates {
|
|
@@ -43,19 +43,19 @@ interface InnerContent {
|
|
|
43
43
|
/**
|
|
44
44
|
* Text content of the tag.
|
|
45
45
|
*
|
|
46
|
-
*
|
|
46
|
+
* Warning: This is not safe for XSS. Do not use this with user input, use `textContent` instead.
|
|
47
47
|
*/
|
|
48
48
|
innerHTML?: InnerContentVal;
|
|
49
49
|
/**
|
|
50
|
-
* Sets the textContent of an element.
|
|
50
|
+
* Sets the textContent of an element. Safer for XSS.
|
|
51
51
|
*/
|
|
52
|
-
|
|
52
|
+
textContent?: InnerContentVal;
|
|
53
53
|
/**
|
|
54
|
-
* Sets the textContent of an element.
|
|
54
|
+
* Sets the textContent of an element.
|
|
55
55
|
*
|
|
56
|
-
*
|
|
56
|
+
* @deprecated Use `textContent` or `innerHTML`.
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
children?: InnerContentVal;
|
|
59
59
|
}
|
|
60
60
|
interface TagPriority {
|
|
61
61
|
/**
|
|
@@ -72,7 +72,14 @@ interface TagPriority {
|
|
|
72
72
|
tagPriority?: number | 'critical' | 'high' | 'low' | `before:${string}` | `after:${string}`;
|
|
73
73
|
}
|
|
74
74
|
type TagUserProperties = TagPriority & TagPosition & MaybePromiseProps<InnerContent> & ResolvesDuplicates;
|
|
75
|
-
|
|
75
|
+
type TagKey = keyof Head;
|
|
76
|
+
type TemplateParams = {
|
|
77
|
+
separator?: string;
|
|
78
|
+
} & Record<string, string | Record<string, string>>;
|
|
79
|
+
interface HasTemplateParams {
|
|
80
|
+
templateParams?: TemplateParams;
|
|
81
|
+
}
|
|
82
|
+
interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTemplateParams {
|
|
76
83
|
/**
|
|
77
84
|
* Entry ID
|
|
78
85
|
*/
|
|
@@ -85,8 +92,15 @@ interface TagInternalProperties {
|
|
|
85
92
|
* Dedupe key
|
|
86
93
|
*/
|
|
87
94
|
_d?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Hash code used to represent the tag.
|
|
97
|
+
*/
|
|
98
|
+
_h?: string;
|
|
99
|
+
tag: TagKey;
|
|
100
|
+
props: Record<string, string>;
|
|
101
|
+
innerHTML?: string;
|
|
102
|
+
textContent?: string;
|
|
88
103
|
}
|
|
89
|
-
type HeadTag = HeadTag$1 & TagUserProperties & TagInternalProperties;
|
|
90
104
|
type HeadTagKeys = (keyof HeadTag)[];
|
|
91
105
|
|
|
92
106
|
type Never<T> = {
|
|
@@ -147,7 +161,19 @@ type Script<E extends EntryAugmentation = {}> = MaybePromiseProps<ScriptBase> &
|
|
|
147
161
|
type Noscript<E extends EntryAugmentation = {}> = MaybePromiseProps<Noscript$1> & DataKeys & SchemaAugmentations['noscript'] & DefinedValueOrEmptyObject<E>;
|
|
148
162
|
type HtmlAttributes<E extends EntryAugmentation = {}> = MaybePromiseProps<HtmlAttr> & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
149
163
|
type BodyAttributes<E extends EntryAugmentation = {}> = MaybePromiseProps<BodyAttr> & MaybeFunctionEntries<BodyEvents> & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>;
|
|
150
|
-
interface
|
|
164
|
+
interface HeadUtils {
|
|
165
|
+
/**
|
|
166
|
+
* Generate the title from a template.
|
|
167
|
+
*
|
|
168
|
+
* Should include a `%s` placeholder for the title, for example `%s - My Site`.
|
|
169
|
+
*/
|
|
170
|
+
titleTemplate?: TitleTemplate;
|
|
171
|
+
/**
|
|
172
|
+
* Variables used to substitute in the title and meta content.
|
|
173
|
+
*/
|
|
174
|
+
templateParams?: TemplateParams;
|
|
175
|
+
}
|
|
176
|
+
interface Head<E extends MergeHead = SchemaAugmentations> extends HeadUtils {
|
|
151
177
|
/**
|
|
152
178
|
* The <title> HTML element defines the document's title that is shown in a browser's title bar or a page's tab.
|
|
153
179
|
* It only contains text; tags within the element are ignored.
|
|
@@ -155,12 +181,6 @@ interface Head<E extends MergeHead = SchemaAugmentations> {
|
|
|
155
181
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
|
|
156
182
|
*/
|
|
157
183
|
title?: Title | Promise<Title>;
|
|
158
|
-
/**
|
|
159
|
-
* Generate the title from a template.
|
|
160
|
-
*
|
|
161
|
-
* Should include a `%s` placeholder for the title, for example `%s - My Site`.
|
|
162
|
-
*/
|
|
163
|
-
titleTemplate?: TitleTemplate;
|
|
164
184
|
/**
|
|
165
185
|
* The <base> HTML element specifies the base URL to use for all relative URLs in a document.
|
|
166
186
|
* There can be only one <base> element in a document.
|
|
@@ -188,20 +208,20 @@ interface Head<E extends MergeHead = SchemaAugmentations> {
|
|
|
188
208
|
*
|
|
189
209
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
|
|
190
210
|
*/
|
|
191
|
-
style?: Style<E['style']>[];
|
|
211
|
+
style?: (Style<E['style']> | string)[];
|
|
192
212
|
/**
|
|
193
213
|
* The <script> HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code.
|
|
194
214
|
*
|
|
195
215
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
|
|
196
216
|
*/
|
|
197
|
-
script?: Script<E['script']>[];
|
|
217
|
+
script?: (Script<E['script']> | string)[];
|
|
198
218
|
/**
|
|
199
219
|
* The <noscript> HTML element defines a section of HTML to be inserted if a script type on the page is unsupported
|
|
200
220
|
* or if scripting is currently turned off in the browser.
|
|
201
221
|
*
|
|
202
222
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript
|
|
203
223
|
*/
|
|
204
|
-
noscript?: Noscript<E['noscript']>[];
|
|
224
|
+
noscript?: (Noscript<E['noscript']> | string)[];
|
|
205
225
|
/**
|
|
206
226
|
* Attributes for the <html> HTML element.
|
|
207
227
|
*
|
|
@@ -216,6 +236,26 @@ interface Head<E extends MergeHead = SchemaAugmentations> {
|
|
|
216
236
|
bodyAttrs?: BodyAttributes<E['bodyAttrs']>;
|
|
217
237
|
}
|
|
218
238
|
|
|
239
|
+
type SafeBodyAttr = Pick<BodyAttr, 'id' | 'class'> & DataKeys;
|
|
240
|
+
type SafeHtmlAttr = Pick<HtmlAttr, 'id' | 'class' | 'lang' | 'dir'> & DataKeys;
|
|
241
|
+
type SafeMeta = Pick<Meta, 'id' | 'name' | 'property' | 'content'> & DataKeys;
|
|
242
|
+
type SafeLink = Pick<Link, 'color' | 'crossorigin' | 'fetchpriority' | 'href' | 'hreflang' | 'imagesizes' | 'imagesrcset' | 'integrity' | 'media' | 'referrerpolicy' | 'sizes' | 'id'> & {
|
|
243
|
+
rel?: Omit<Link['rel'], 'stylesheet' | 'canonical' | 'modulepreload' | 'prerender' | 'preload' | 'prefetch'>;
|
|
244
|
+
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>);
|
|
245
|
+
} & DataKeys;
|
|
246
|
+
type SafeScript = Pick<Script, 'id' | 'textContent'> & {
|
|
247
|
+
type: 'application/json' | 'application/ld+json';
|
|
248
|
+
} & DataKeys;
|
|
249
|
+
type SafeNoscript = Pick<Noscript, 'id' | 'textContent'> & DataKeys;
|
|
250
|
+
interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParams'> {
|
|
251
|
+
meta?: SafeMeta[];
|
|
252
|
+
link?: SafeLink[];
|
|
253
|
+
noscript?: SafeNoscript[];
|
|
254
|
+
script?: SafeScript[];
|
|
255
|
+
htmlAttrs?: SafeHtmlAttr;
|
|
256
|
+
bodyAttrs?: SafeBodyAttr;
|
|
257
|
+
}
|
|
258
|
+
|
|
219
259
|
type HookResult = Promise<void> | void;
|
|
220
260
|
interface SSRHeadPayload {
|
|
221
261
|
headTags: string;
|
|
@@ -229,12 +269,12 @@ interface EntryResolveCtx<T> {
|
|
|
229
269
|
entries: HeadEntry<T>[];
|
|
230
270
|
}
|
|
231
271
|
interface DomRenderTagContext {
|
|
272
|
+
renderId: string;
|
|
232
273
|
$el?: Element | null;
|
|
233
274
|
shouldRender: boolean;
|
|
234
|
-
renderId: string;
|
|
235
275
|
tag: HeadTag;
|
|
236
276
|
entry?: HeadEntry<any>;
|
|
237
|
-
|
|
277
|
+
markSideEffect: (key: string, fn: () => void) => void;
|
|
238
278
|
}
|
|
239
279
|
interface BeforeRenderContext {
|
|
240
280
|
shouldRender: boolean;
|
|
@@ -250,6 +290,7 @@ interface HeadHooks {
|
|
|
250
290
|
'tag:normalise': (ctx: {
|
|
251
291
|
tag: HeadTag;
|
|
252
292
|
entry: HeadEntry<any>;
|
|
293
|
+
resolvedOptions: CreateHeadOptions;
|
|
253
294
|
}) => HookResult;
|
|
254
295
|
'tags:resolve': (ctx: {
|
|
255
296
|
tags: HeadTag[];
|
|
@@ -267,7 +308,7 @@ interface HeadHooks {
|
|
|
267
308
|
/**
|
|
268
309
|
* Side effects are mapped with a key and their cleanup function.
|
|
269
310
|
*
|
|
270
|
-
* For example `meta:data-h-4h46h465`: () => { document.querySelector('meta[data-h-4h46h465]').remove() }
|
|
311
|
+
* For example, `meta:data-h-4h46h465`: () => { document.querySelector('meta[data-h-4h46h465]').remove() }
|
|
271
312
|
*/
|
|
272
313
|
type SideEffectsRecord = Record<string, () => void>;
|
|
273
314
|
type RuntimeMode = 'server' | 'client' | 'all';
|
|
@@ -286,6 +327,12 @@ interface HeadEntry<Input> {
|
|
|
286
327
|
* @internal
|
|
287
328
|
*/
|
|
288
329
|
_m?: RuntimeMode;
|
|
330
|
+
/**
|
|
331
|
+
* Transformer function for the entry.
|
|
332
|
+
*
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
335
|
+
_t?: (input: Input) => Input;
|
|
289
336
|
/**
|
|
290
337
|
* Head entry index
|
|
291
338
|
*
|
|
@@ -322,9 +369,11 @@ interface CreateHeadOptions {
|
|
|
322
369
|
document?: Document;
|
|
323
370
|
plugins?: HeadPlugin[];
|
|
324
371
|
hooks?: NestedHooks<HeadHooks>;
|
|
372
|
+
experimentalHashHydration?: boolean;
|
|
325
373
|
}
|
|
326
374
|
interface HeadEntryOptions {
|
|
327
375
|
mode?: RuntimeMode;
|
|
376
|
+
transform?: (input: unknown) => unknown;
|
|
328
377
|
}
|
|
329
378
|
interface Unhead<Input extends {} = Head> {
|
|
330
379
|
/**
|
|
@@ -359,6 +408,7 @@ interface Unhead<Input extends {} = Head> {
|
|
|
359
408
|
* @internal
|
|
360
409
|
*/
|
|
361
410
|
_elMap: Record<string, Element>;
|
|
411
|
+
_hash?: string | false;
|
|
362
412
|
}
|
|
363
413
|
|
|
364
|
-
export { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BeforeRenderContext, BodyAttributes, CreateHeadOptions, DomRenderTagContext, EntryAugmentation, EntryResolveCtx, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadTag, HeadTagKeys, HookResult, HtmlAttributes, InnerContent, InnerContentVal, Link, MaybeArray, MaybeFunctionEntries, Meta, Never, Noscript, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SchemaAugmentations, Script, SideEffectsRecord, Style,
|
|
414
|
+
export { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BeforeRenderContext, BodyAttr, BodyAttributes, CreateHeadOptions, DomRenderTagContext, EntryAugmentation, EntryResolveCtx, HasTemplateParams, Head, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, 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, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/schema",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
5
|
-
"packageManager": "pnpm@7.
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"packageManager": "pnpm@7.27.1",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"hookable": "^5.4.2",
|
|
39
|
-
"zhead": "^2.0.
|
|
39
|
+
"zhead": "^2.0.4"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "unbuild .",
|