@unhead/schema 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.d.ts +191 -174
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -2,6 +2,184 @@ import { MaybePromiseProps, MergeHead, BaseBodyAttributes, HtmlAttributes as Htm
2
2
  export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInput, SpeculationRules } from 'zhead';
3
3
  import { NestedHooks, Hookable } from 'hookable';
4
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
+
5
183
  interface ResolvesDuplicates {
6
184
  /**
7
185
  * By default, tags which share the same unique key `name`, `property` are de-duped. To allow duplicates
@@ -77,26 +255,34 @@ interface HasTemplateParams {
77
255
  templateParams?: TemplateParams;
78
256
  }
79
257
  interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTemplateParams {
258
+ tag: TagKey;
259
+ props: Record<string, string>;
260
+ innerHTML?: string;
261
+ textContent?: string;
80
262
  /**
81
263
  * Entry ID
264
+ * @internal
82
265
  */
83
266
  _e?: number;
84
267
  /**
85
268
  * Position
269
+ * @internal
86
270
  */
87
271
  _p?: number;
88
272
  /**
89
273
  * Dedupe key
274
+ * @internal
90
275
  */
91
276
  _d?: string;
92
277
  /**
93
278
  * Hash code used to represent the tag.
279
+ * @internal
94
280
  */
95
281
  _h?: string;
96
- tag: TagKey;
97
- props: Record<string, string>;
98
- innerHTML?: string;
99
- textContent?: string;
282
+ /**
283
+ * @internal
284
+ */
285
+ _m?: RuntimeMode;
100
286
  }
101
287
  type HeadTagKeys = (keyof HeadTag)[];
102
288
 
@@ -264,173 +450,4 @@ interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParam
264
450
  bodyAttrs?: SafeBodyAttr;
265
451
  }
266
452
 
267
- type HookResult = Promise<void> | void;
268
- interface SSRHeadPayload {
269
- headTags: string;
270
- bodyTags: string;
271
- bodyTagsOpen: string;
272
- htmlAttrs: string;
273
- bodyAttrs: string;
274
- }
275
- interface EntryResolveCtx<T> {
276
- tags: HeadTag[];
277
- entries: HeadEntry<T>[];
278
- }
279
- interface DomRenderTagContext {
280
- id: string;
281
- $el: Element;
282
- shouldRender: boolean;
283
- tag: HeadTag;
284
- entry?: HeadEntry<any>;
285
- markSideEffect: (key: string, fn: () => void) => void;
286
- }
287
- interface DomBeforeRenderCtx extends ShouldRenderContext {
288
- tags: DomRenderTagContext[];
289
- }
290
- interface ShouldRenderContext {
291
- shouldRender: boolean;
292
- }
293
- interface SSRRenderContext {
294
- tags: HeadTag[];
295
- html: SSRHeadPayload;
296
- }
297
- interface HeadHooks {
298
- 'init': (ctx: Unhead<any>) => HookResult;
299
- 'entries:updated': (ctx: Unhead<any>) => HookResult;
300
- 'entries:resolve': (ctx: EntryResolveCtx<any>) => HookResult;
301
- 'tag:normalise': (ctx: {
302
- tag: HeadTag;
303
- entry: HeadEntry<any>;
304
- resolvedOptions: CreateHeadOptions;
305
- }) => HookResult;
306
- 'tags:beforeResolve': (ctx: {
307
- tags: HeadTag[];
308
- }) => HookResult;
309
- 'tags:resolve': (ctx: {
310
- tags: HeadTag[];
311
- }) => HookResult;
312
- 'dom:beforeRender': (ctx: ShouldRenderContext & {
313
- tags: DomRenderTagContext[];
314
- }) => HookResult;
315
- 'dom:renderTag': (ctx: DomRenderTagContext, document: Document, track: any) => HookResult;
316
- 'dom:rendered': (ctx: {
317
- renders: DomRenderTagContext[];
318
- }) => HookResult;
319
- 'ssr:beforeRender': (ctx: ShouldRenderContext) => HookResult;
320
- 'ssr:render': (ctx: {
321
- tags: HeadTag[];
322
- }) => HookResult;
323
- 'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
324
- }
325
-
326
- /**
327
- * Side effects are mapped with a key and their cleanup function.
328
- *
329
- * For example, `meta:data-h-4h46h465`: () => { document.querySelector('meta[data-h-4h46h465]').remove() }
330
- */
331
- type SideEffectsRecord = Record<string, () => void>;
332
- type RuntimeMode = 'server' | 'client' | 'all';
333
- interface HeadEntry<Input> {
334
- /**
335
- * User provided input for the entry.
336
- */
337
- input: Input;
338
- /**
339
- * Optional resolved input which will be used if set.
340
- */
341
- resolvedInput?: Input;
342
- /**
343
- * The mode that the entry should be used in.
344
- *
345
- * @internal
346
- */
347
- mode?: RuntimeMode;
348
- /**
349
- * Transformer function for the entry.
350
- *
351
- * @internal
352
- */
353
- transform?: (input: Input) => Promise<Input> | Input;
354
- /**
355
- * Head entry index
356
- *
357
- * @internal
358
- */
359
- _i: number;
360
- /**
361
- * Default tag position.
362
- *
363
- * @internal
364
- */
365
- tagPosition?: TagPosition['tagPosition'];
366
- /**
367
- * Default tag priority.
368
- *
369
- * @internal
370
- */
371
- tagPriority?: TagPriority['tagPriority'];
372
- }
373
- type HeadPlugin = Omit<CreateHeadOptions, 'plugins'>;
374
- /**
375
- * An active head entry provides an API to manipulate it.
376
- */
377
- interface ActiveHeadEntry<Input> {
378
- /**
379
- * Updates the entry with new input.
380
- *
381
- * Will first clear any side effects for previous input.
382
- */
383
- patch: (input: Input) => void;
384
- /**
385
- * Dispose the entry, removing it from the active head.
386
- *
387
- * Will queue side effects for removal.
388
- */
389
- dispose: () => void;
390
- }
391
- interface CreateHeadOptions {
392
- domDelayFn?: (fn: () => void) => void;
393
- document?: Document;
394
- plugins?: HeadPlugin[];
395
- hooks?: NestedHooks<HeadHooks>;
396
- }
397
- interface HeadEntryOptions extends TagPosition, TagPriority {
398
- mode?: RuntimeMode;
399
- transform?: (input: unknown) => unknown;
400
- }
401
- interface Unhead<Input extends {} = Head> {
402
- /**
403
- * The active head entries.
404
- */
405
- headEntries: () => HeadEntry<Input>[];
406
- /**
407
- * Create a new head entry.
408
- */
409
- push: (entry: Input, options?: HeadEntryOptions) => ActiveHeadEntry<Input>;
410
- /**
411
- * Resolve tags from head entries.
412
- */
413
- resolveTags: () => Promise<HeadTag[]>;
414
- /**
415
- * Exposed hooks for easier extension.
416
- */
417
- hooks: Hookable<HeadHooks>;
418
- /**
419
- * Resolved options
420
- */
421
- resolvedOptions: CreateHeadOptions;
422
- /**
423
- * Use a head plugin, loads the plugins hooks.
424
- */
425
- use: (plugin: HeadPlugin) => void;
426
- ssr: boolean;
427
- _dom?: DomState;
428
- _domUpdatePromise?: Promise<void>;
429
- }
430
- interface DomState {
431
- pendingSideEffects: SideEffectsRecord;
432
- sideEffects: SideEffectsRecord;
433
- elMap: Record<string, Element>;
434
- }
435
-
436
- export { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BaseMeta, BodyAttr, BodyAttributes, CreateHeadOptions, DomBeforeRenderCtx, DomRenderTagContext, DomState, 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, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/schema",
3
3
  "type": "module",
4
- "version": "1.3.3",
4
+ "version": "1.3.4",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",