@unhead/schema 1.8.0-beta.0 → 1.8.0-beta.2

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 CHANGED
@@ -1,5 +1,5 @@
1
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';
2
+ export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInput, ScriptBase, SpeculationRules } from 'zhead';
3
3
  import { NestedHooks, Hookable } from 'hookable';
4
4
 
5
5
  type HookResult = Promise<void> | void;
@@ -10,6 +10,25 @@ interface SSRHeadPayload {
10
10
  htmlAttrs: string;
11
11
  bodyAttrs: string;
12
12
  }
13
+ type UseScriptStatus = 'awaitingLoad' | 'loading' | 'loaded' | 'error';
14
+ interface ScriptInstance<T> {
15
+ loaded: boolean;
16
+ status: UseScriptStatus;
17
+ load: () => Promise<T>;
18
+ waitForUse: () => Promise<T>;
19
+ }
20
+ interface UseScriptOptions<T> extends Omit<HeadEntryOptions, 'transform'> {
21
+ use?: () => T | undefined | null;
22
+ stub?: ((ctx: {
23
+ script: ScriptInstance<T>;
24
+ fn: string | symbol;
25
+ }) => any);
26
+ transform?: (script: Script) => Script;
27
+ trigger?: 'idle' | 'manual' | Promise<void>;
28
+ }
29
+ type UseScriptInput = Omit<Script, 'src'> & {
30
+ src: string;
31
+ };
13
32
  interface EntryResolveCtx<T> {
14
33
  tags: HeadTag[];
15
34
  entries: HeadEntry<T>[];
@@ -60,6 +79,18 @@ interface HeadHooks {
60
79
  tags: HeadTag[];
61
80
  }) => HookResult;
62
81
  'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
82
+ 'script:transform': (ctx: {
83
+ script: Script;
84
+ }) => HookResult;
85
+ 'script:loaded': (ctx: {
86
+ script: ScriptInstance<any>;
87
+ }) => HookResult;
88
+ 'script:error': (ctx: {
89
+ script: ScriptInstance<any>;
90
+ }) => HookResult;
91
+ 'script:loading': (ctx: {
92
+ script: ScriptInstance<any>;
93
+ }) => HookResult;
63
94
  }
64
95
 
65
96
  /**
@@ -182,6 +213,10 @@ interface Unhead<Input extends {} = Head> {
182
213
  * @internal
183
214
  */
184
215
  dirty: boolean;
216
+ /**
217
+ * @internal
218
+ */
219
+ _scripts?: Record<string, any>;
185
220
  }
186
221
  interface DomState {
187
222
  pendingSideEffects: SideEffectsRecord;
@@ -296,6 +331,10 @@ interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTempl
296
331
  * @internal
297
332
  */
298
333
  _m?: RuntimeMode;
334
+ /**
335
+ * @internal
336
+ */
337
+ _eventHandlers?: Record<string, ((e: Event) => {})>;
299
338
  }
300
339
  type HeadTagKeys = (keyof HeadTag)[];
301
340
 
@@ -465,4 +504,4 @@ interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParam
465
504
  bodyAttrs?: SafeBodyAttr;
466
505
  }
467
506
 
468
- 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, ProcessesTemplateParams, 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 };
507
+ 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, ProcessesTemplateParams, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript, SchemaAugmentations, Script, ScriptInstance, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseScriptInput, UseScriptOptions, UseScriptStatus, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
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';
2
+ export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInput, ScriptBase, SpeculationRules } from 'zhead';
3
3
  import { NestedHooks, Hookable } from 'hookable';
4
4
 
5
5
  type HookResult = Promise<void> | void;
@@ -10,6 +10,25 @@ interface SSRHeadPayload {
10
10
  htmlAttrs: string;
11
11
  bodyAttrs: string;
12
12
  }
13
+ type UseScriptStatus = 'awaitingLoad' | 'loading' | 'loaded' | 'error';
14
+ interface ScriptInstance<T> {
15
+ loaded: boolean;
16
+ status: UseScriptStatus;
17
+ load: () => Promise<T>;
18
+ waitForUse: () => Promise<T>;
19
+ }
20
+ interface UseScriptOptions<T> extends Omit<HeadEntryOptions, 'transform'> {
21
+ use?: () => T | undefined | null;
22
+ stub?: ((ctx: {
23
+ script: ScriptInstance<T>;
24
+ fn: string | symbol;
25
+ }) => any);
26
+ transform?: (script: Script) => Script;
27
+ trigger?: 'idle' | 'manual' | Promise<void>;
28
+ }
29
+ type UseScriptInput = Omit<Script, 'src'> & {
30
+ src: string;
31
+ };
13
32
  interface EntryResolveCtx<T> {
14
33
  tags: HeadTag[];
15
34
  entries: HeadEntry<T>[];
@@ -60,6 +79,18 @@ interface HeadHooks {
60
79
  tags: HeadTag[];
61
80
  }) => HookResult;
62
81
  'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
82
+ 'script:transform': (ctx: {
83
+ script: Script;
84
+ }) => HookResult;
85
+ 'script:loaded': (ctx: {
86
+ script: ScriptInstance<any>;
87
+ }) => HookResult;
88
+ 'script:error': (ctx: {
89
+ script: ScriptInstance<any>;
90
+ }) => HookResult;
91
+ 'script:loading': (ctx: {
92
+ script: ScriptInstance<any>;
93
+ }) => HookResult;
63
94
  }
64
95
 
65
96
  /**
@@ -182,6 +213,10 @@ interface Unhead<Input extends {} = Head> {
182
213
  * @internal
183
214
  */
184
215
  dirty: boolean;
216
+ /**
217
+ * @internal
218
+ */
219
+ _scripts?: Record<string, any>;
185
220
  }
186
221
  interface DomState {
187
222
  pendingSideEffects: SideEffectsRecord;
@@ -296,6 +331,10 @@ interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTempl
296
331
  * @internal
297
332
  */
298
333
  _m?: RuntimeMode;
334
+ /**
335
+ * @internal
336
+ */
337
+ _eventHandlers?: Record<string, ((e: Event) => {})>;
299
338
  }
300
339
  type HeadTagKeys = (keyof HeadTag)[];
301
340
 
@@ -465,4 +504,4 @@ interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParam
465
504
  bodyAttrs?: SafeBodyAttr;
466
505
  }
467
506
 
468
- 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, ProcessesTemplateParams, 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 };
507
+ 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, ProcessesTemplateParams, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript, SchemaAugmentations, Script, ScriptInstance, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseScriptInput, UseScriptOptions, UseScriptStatus, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
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';
2
+ export { BodyEvents, DataKeys, DefinedValueOrEmptyObject, MergeHead, MetaFlatInput, ScriptBase, SpeculationRules } from 'zhead';
3
3
  import { NestedHooks, Hookable } from 'hookable';
4
4
 
5
5
  type HookResult = Promise<void> | void;
@@ -10,6 +10,25 @@ interface SSRHeadPayload {
10
10
  htmlAttrs: string;
11
11
  bodyAttrs: string;
12
12
  }
13
+ type UseScriptStatus = 'awaitingLoad' | 'loading' | 'loaded' | 'error';
14
+ interface ScriptInstance<T> {
15
+ loaded: boolean;
16
+ status: UseScriptStatus;
17
+ load: () => Promise<T>;
18
+ waitForUse: () => Promise<T>;
19
+ }
20
+ interface UseScriptOptions<T> extends Omit<HeadEntryOptions, 'transform'> {
21
+ use?: () => T | undefined | null;
22
+ stub?: ((ctx: {
23
+ script: ScriptInstance<T>;
24
+ fn: string | symbol;
25
+ }) => any);
26
+ transform?: (script: Script) => Script;
27
+ trigger?: 'idle' | 'manual' | Promise<void>;
28
+ }
29
+ type UseScriptInput = Omit<Script, 'src'> & {
30
+ src: string;
31
+ };
13
32
  interface EntryResolveCtx<T> {
14
33
  tags: HeadTag[];
15
34
  entries: HeadEntry<T>[];
@@ -60,6 +79,18 @@ interface HeadHooks {
60
79
  tags: HeadTag[];
61
80
  }) => HookResult;
62
81
  'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
82
+ 'script:transform': (ctx: {
83
+ script: Script;
84
+ }) => HookResult;
85
+ 'script:loaded': (ctx: {
86
+ script: ScriptInstance<any>;
87
+ }) => HookResult;
88
+ 'script:error': (ctx: {
89
+ script: ScriptInstance<any>;
90
+ }) => HookResult;
91
+ 'script:loading': (ctx: {
92
+ script: ScriptInstance<any>;
93
+ }) => HookResult;
63
94
  }
64
95
 
65
96
  /**
@@ -182,6 +213,10 @@ interface Unhead<Input extends {} = Head> {
182
213
  * @internal
183
214
  */
184
215
  dirty: boolean;
216
+ /**
217
+ * @internal
218
+ */
219
+ _scripts?: Record<string, any>;
185
220
  }
186
221
  interface DomState {
187
222
  pendingSideEffects: SideEffectsRecord;
@@ -296,6 +331,10 @@ interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTempl
296
331
  * @internal
297
332
  */
298
333
  _m?: RuntimeMode;
334
+ /**
335
+ * @internal
336
+ */
337
+ _eventHandlers?: Record<string, ((e: Event) => {})>;
299
338
  }
300
339
  type HeadTagKeys = (keyof HeadTag)[];
301
340
 
@@ -465,4 +504,4 @@ interface HeadSafe extends Pick<Head, 'title' | 'titleTemplate' | 'templateParam
465
504
  bodyAttrs?: SafeBodyAttr;
466
505
  }
467
506
 
468
- 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, ProcessesTemplateParams, 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 };
507
+ 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, ProcessesTemplateParams, ResolvesDuplicates, RuntimeMode, SSRHeadPayload, SSRRenderContext, SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript, SchemaAugmentations, Script, ScriptInstance, ShouldRenderContext, SideEffectsRecord, Style, TagKey, TagPosition, TagPriority, TagUserProperties, TemplateParams, Title, TitleTemplate, Unhead, UseScriptInput, UseScriptOptions, UseScriptStatus, 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.8.0-beta.0",
4
+ "version": "1.8.0-beta.2",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",