@unhead/schema 1.9.5 → 1.9.7

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
@@ -73,6 +73,7 @@ interface HeadHooks {
73
73
  script: ScriptInstance<any>;
74
74
  fn: string | symbol;
75
75
  args: any;
76
+ exists: boolean;
76
77
  }) => HookResult;
77
78
  }
78
79
 
@@ -516,14 +517,13 @@ type UseScriptInput = string | (Omit<Script, 'src'> & {
516
517
  type UseScriptResolvedInput = Omit<Script, 'src'> & {
517
518
  src: string;
518
519
  };
519
- type ScriptInstance<T> = {
520
+ interface ScriptInstance<T> {
520
521
  id: string;
521
522
  status: UseScriptStatus;
522
- loadPromise: Promise<T>;
523
523
  entry?: ActiveHeadEntry<any>;
524
524
  load: () => Promise<T>;
525
525
  remove: () => boolean;
526
- } & Promise<T>;
526
+ }
527
527
  interface UseScriptOptions<T> extends HeadEntryOptions {
528
528
  /**
529
529
  * Resolve the script instance from the window.
@@ -533,7 +533,7 @@ interface UseScriptOptions<T> extends HeadEntryOptions {
533
533
  * Stub the script instance. Useful for SSR or testing.
534
534
  */
535
535
  stub?: ((ctx: {
536
- script: ScriptInstance<T>;
536
+ script: Promise<T> & ScriptInstance<T>;
537
537
  fn: string | symbol;
538
538
  }) => any);
539
539
  /**
@@ -550,6 +550,11 @@ interface UseScriptOptions<T> extends HeadEntryOptions {
550
550
  * calling the event, allowing the event to be reactive.
551
551
  */
552
552
  eventContext?: any;
553
+ /**
554
+ * Called before the script is initialized. Will not be triggered when the script is already loaded. This means
555
+ * this is guaranteed to be called only once, unless the script is removed and re-added.
556
+ */
557
+ beforeInit?: () => void;
553
558
  }
554
559
 
555
560
  export type { ActiveHeadEntry, 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, Never, 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, UseScriptInput, UseScriptOptions, UseScriptResolvedInput, UseScriptStatus, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
package/dist/index.d.mts CHANGED
@@ -73,6 +73,7 @@ interface HeadHooks {
73
73
  script: ScriptInstance<any>;
74
74
  fn: string | symbol;
75
75
  args: any;
76
+ exists: boolean;
76
77
  }) => HookResult;
77
78
  }
78
79
 
@@ -516,14 +517,13 @@ type UseScriptInput = string | (Omit<Script, 'src'> & {
516
517
  type UseScriptResolvedInput = Omit<Script, 'src'> & {
517
518
  src: string;
518
519
  };
519
- type ScriptInstance<T> = {
520
+ interface ScriptInstance<T> {
520
521
  id: string;
521
522
  status: UseScriptStatus;
522
- loadPromise: Promise<T>;
523
523
  entry?: ActiveHeadEntry<any>;
524
524
  load: () => Promise<T>;
525
525
  remove: () => boolean;
526
- } & Promise<T>;
526
+ }
527
527
  interface UseScriptOptions<T> extends HeadEntryOptions {
528
528
  /**
529
529
  * Resolve the script instance from the window.
@@ -533,7 +533,7 @@ interface UseScriptOptions<T> extends HeadEntryOptions {
533
533
  * Stub the script instance. Useful for SSR or testing.
534
534
  */
535
535
  stub?: ((ctx: {
536
- script: ScriptInstance<T>;
536
+ script: Promise<T> & ScriptInstance<T>;
537
537
  fn: string | symbol;
538
538
  }) => any);
539
539
  /**
@@ -550,6 +550,11 @@ interface UseScriptOptions<T> extends HeadEntryOptions {
550
550
  * calling the event, allowing the event to be reactive.
551
551
  */
552
552
  eventContext?: any;
553
+ /**
554
+ * Called before the script is initialized. Will not be triggered when the script is already loaded. This means
555
+ * this is guaranteed to be called only once, unless the script is removed and re-added.
556
+ */
557
+ beforeInit?: () => void;
553
558
  }
554
559
 
555
560
  export type { ActiveHeadEntry, 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, Never, 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, UseScriptInput, UseScriptOptions, UseScriptResolvedInput, UseScriptStatus, UseSeoMetaInput, UserAttributesConfig, UserTagConfigWithoutInnerContent, ValidTagPositions };
package/dist/index.d.ts CHANGED
@@ -73,6 +73,7 @@ interface HeadHooks {
73
73
  script: ScriptInstance<any>;
74
74
  fn: string | symbol;
75
75
  args: any;
76
+ exists: boolean;
76
77
  }) => HookResult;
77
78
  }
78
79
 
@@ -516,14 +517,13 @@ type UseScriptInput = string | (Omit<Script, 'src'> & {
516
517
  type UseScriptResolvedInput = Omit<Script, 'src'> & {
517
518
  src: string;
518
519
  };
519
- type ScriptInstance<T> = {
520
+ interface ScriptInstance<T> {
520
521
  id: string;
521
522
  status: UseScriptStatus;
522
- loadPromise: Promise<T>;
523
523
  entry?: ActiveHeadEntry<any>;
524
524
  load: () => Promise<T>;
525
525
  remove: () => boolean;
526
- } & Promise<T>;
526
+ }
527
527
  interface UseScriptOptions<T> extends HeadEntryOptions {
528
528
  /**
529
529
  * Resolve the script instance from the window.
@@ -533,7 +533,7 @@ interface UseScriptOptions<T> extends HeadEntryOptions {
533
533
  * Stub the script instance. Useful for SSR or testing.
534
534
  */
535
535
  stub?: ((ctx: {
536
- script: ScriptInstance<T>;
536
+ script: Promise<T> & ScriptInstance<T>;
537
537
  fn: string | symbol;
538
538
  }) => any);
539
539
  /**
@@ -550,6 +550,11 @@ interface UseScriptOptions<T> extends HeadEntryOptions {
550
550
  * calling the event, allowing the event to be reactive.
551
551
  */
552
552
  eventContext?: any;
553
+ /**
554
+ * Called before the script is initialized. Will not be triggered when the script is already loaded. This means
555
+ * this is guaranteed to be called only once, unless the script is removed and re-added.
556
+ */
557
+ beforeInit?: () => void;
553
558
  }
554
559
 
555
560
  export type { ActiveHeadEntry, 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, Never, 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, UseScriptInput, UseScriptOptions, UseScriptResolvedInput, 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.9.5",
4
+ "version": "1.9.7",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",