@nuxt/scripts 0.3.3 → 0.3.5

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 (63) hide show
  1. package/dist/client/200.html +5 -5
  2. package/dist/client/404.html +5 -5
  3. package/dist/client/_nuxt/{B-3dzucQ.js → B-VcbH-p.js} +1 -1
  4. package/dist/client/_nuxt/{CmaBlQfy.js → Da7ySKCR.js} +1 -1
  5. package/dist/client/_nuxt/Duz6zLk8.js +31 -0
  6. package/dist/client/_nuxt/builds/latest.json +1 -1
  7. package/dist/client/_nuxt/builds/meta/ce1e7798-e27a-4397-9734-cd67ecbfb4ca.json +1 -0
  8. package/dist/client/_nuxt/{D-T6Aidr.js → enpXmyCL.js} +1 -1
  9. package/dist/client/index.html +5 -5
  10. package/dist/module.d.mts +2 -2
  11. package/dist/module.d.ts +2 -2
  12. package/dist/module.json +1 -1
  13. package/dist/module.mjs +67 -36
  14. package/dist/registry.d.mts +2 -2
  15. package/dist/registry.d.ts +2 -2
  16. package/dist/registry.mjs +16 -16
  17. package/dist/runtime/components/ScriptGoogleMaps.vue +264 -0
  18. package/dist/runtime/components/ScriptLemonSqueezyButton.vue +42 -0
  19. package/dist/runtime/components/ScriptLoadingIndicator.vue +15 -0
  20. package/dist/runtime/components/ScriptStripePricingTable.vue +47 -0
  21. package/dist/runtime/components/ScriptVimeoPlayer.vue +243 -0
  22. package/dist/runtime/components/ScriptYouTubePlayer.vue +160 -0
  23. package/dist/runtime/composables/useElementScriptTrigger.d.ts +3 -3
  24. package/dist/runtime/composables/useElementScriptTrigger.mjs +41 -5
  25. package/dist/runtime/composables/useScript.d.ts +1 -1
  26. package/dist/runtime/composables/useScript.mjs +7 -6
  27. package/dist/runtime/registry/cloudflare-web-analytics.mjs +2 -2
  28. package/dist/runtime/registry/fathom-analytics.d.ts +2 -2
  29. package/dist/runtime/registry/fathom-analytics.mjs +2 -2
  30. package/dist/runtime/registry/google-analytics.d.ts +4 -2
  31. package/dist/runtime/registry/google-analytics.mjs +13 -8
  32. package/dist/runtime/registry/google-maps.mjs +2 -2
  33. package/dist/runtime/registry/google-tag-manager.mjs +2 -2
  34. package/dist/runtime/registry/hotjar.mjs +4 -4
  35. package/dist/runtime/registry/intercom.mjs +3 -8
  36. package/dist/runtime/registry/lemon-squeezy.d.ts +1 -2
  37. package/dist/runtime/registry/lemon-squeezy.mjs +3 -6
  38. package/dist/runtime/registry/matomo-analytics.mjs +11 -10
  39. package/dist/runtime/registry/{facebook-pixel.d.ts → meta-pixel.d.ts} +7 -7
  40. package/dist/runtime/registry/{facebook-pixel.mjs → meta-pixel.mjs} +9 -7
  41. package/dist/runtime/registry/npm.mjs +2 -2
  42. package/dist/runtime/registry/plausible-analytics.mjs +2 -2
  43. package/dist/runtime/registry/segment.d.ts +22 -9
  44. package/dist/runtime/registry/segment.mjs +43 -21
  45. package/dist/runtime/registry/stripe.mjs +4 -4
  46. package/dist/runtime/registry/vimeo-player.d.ts +6 -6
  47. package/dist/runtime/registry/vimeo-player.mjs +30 -34
  48. package/dist/runtime/registry/x-pixel.mjs +17 -13
  49. package/dist/runtime/registry/youtube-player.d.ts +14 -0
  50. package/dist/runtime/registry/{youtube-iframe.mjs → youtube-player.mjs} +22 -20
  51. package/dist/runtime/types.d.ts +33 -16
  52. package/dist/runtime/types.mjs +2 -0
  53. package/dist/runtime/utils.d.ts +3 -2
  54. package/dist/runtime/utils.mjs +15 -13
  55. package/package.json +6 -6
  56. package/dist/client/_nuxt/CMNIl2hT.js +0 -31
  57. package/dist/client/_nuxt/builds/meta/8b865286-abcf-4201-a2af-ee13e4478155.json +0 -1
  58. package/dist/runtime/components/GoogleMaps.vue +0 -130
  59. package/dist/runtime/components/LemonSqueezyButton.vue +0 -28
  60. package/dist/runtime/components/StripePricingTableEmbed.vue +0 -33
  61. package/dist/runtime/components/VimeoEmbed.vue +0 -161
  62. package/dist/runtime/components/YouTubeEmbed.vue +0 -79
  63. package/dist/runtime/registry/youtube-iframe.d.ts +0 -15
@@ -7,15 +7,27 @@ export declare const SegmentOptions: import("valibot").ObjectSchema<{
7
7
  analyticsKey?: string | undefined;
8
8
  }>;
9
9
  export type SegmentInput = RegistryScriptInput<typeof SegmentOptions>;
10
- export interface SegmentApi {
11
- analytics: {
12
- track: (event: string, properties?: Record<string, any>) => void;
13
- page: (name?: string, properties?: Record<string, any>) => void;
14
- identify: (userId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
15
- group: (groupId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
16
- alias: (userId: string, previousId: string, options?: Record<string, any>) => void;
17
- reset: () => void;
18
- };
10
+ interface AnalyticsApi {
11
+ track: (event: string, properties?: Record<string, any>) => void;
12
+ page: (name?: string, properties?: Record<string, any>) => void;
13
+ identify: (userId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
14
+ group: (groupId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
15
+ alias: (userId: string, previousId: string, options?: Record<string, any>) => void;
16
+ reset: () => void;
17
+ /**
18
+ * @internal
19
+ */
20
+ methods: string[];
21
+ /**
22
+ * @internal
23
+ */
24
+ factory: (method: string) => (...args: any[]) => AnalyticsApi;
25
+ /**
26
+ * @internal
27
+ */
28
+ push: (args: any[]) => void;
29
+ }
30
+ export interface SegmentApi extends Pick<AnalyticsApi, 'track' | 'page' | 'identify' | 'group' | 'alias' | 'reset'> {
19
31
  }
20
32
  declare global {
21
33
  interface Window extends SegmentApi {
@@ -24,3 +36,4 @@ declare global {
24
36
  export declare function useScriptSegment<T extends SegmentApi>(_options?: SegmentInput): T & {
25
37
  $script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
26
38
  };
39
+ export {};
@@ -1,39 +1,61 @@
1
- import { registryScript } from "../utils.mjs";
1
+ import { useRegistryScript } from "../utils.mjs";
2
2
  import { SegmentScriptResolver } from "../../registry";
3
3
  import { object, optional, string } from "#nuxt-scripts-validator";
4
4
  export const SegmentOptions = object({
5
5
  writeKey: string(),
6
6
  analyticsKey: optional(string())
7
7
  });
8
+ const methods = ["track", "page", "identify", "group", "alias", "reset"];
8
9
  export function useScriptSegment(_options) {
9
- return registryScript("segment", (options) => {
10
- const analyticsKey = options?.analyticsKey || "analytics";
10
+ return useRegistryScript("segment", (options) => {
11
+ const k = options?.analyticsKey ?? "analytics";
11
12
  return {
12
13
  scriptInput: {
13
- "data-global-segment-analytics-key": analyticsKey,
14
+ "data-global-segment-analytics-key": k,
14
15
  "src": SegmentScriptResolver(options)
15
16
  },
17
+ clientInit: import.meta.server ? void 0 : () => {
18
+ window[k] = window[k] || [];
19
+ window[k].methods = methods;
20
+ window[k].factory = function(method) {
21
+ return function(...params) {
22
+ const args = Array.prototype.slice.call(params);
23
+ args.unshift(method);
24
+ window[k].push(args);
25
+ return window[k];
26
+ };
27
+ };
28
+ for (let i = 0; i < window[k].methods.length; i++) {
29
+ const key = window[k].methods[i];
30
+ window[k][key] = window[k].factory(key);
31
+ }
32
+ window[k].page();
33
+ },
16
34
  schema: import.meta.dev ? SegmentOptions : void 0,
17
35
  scriptOptions: {
18
- use() {
19
- return { analytics: window[analyticsKey] };
20
- },
21
- clientInit: import.meta.server ? void 0 : () => {
22
- window.analytics = window.analytics || [];
23
- window.analytics.methods = ["track", "page", "identify", "group", "alias", "reset"];
24
- window.analytics.factory = function(method) {
25
- return function(...params) {
26
- const args = Array.prototype.slice.call(params);
27
- args.unshift(method);
28
- window.analytics.push(args);
29
- return window.analytics;
36
+ stub: import.meta.server ? ({ fn }) => {
37
+ if (fn === "analytics") {
38
+ return {
39
+ track: () => {
40
+ },
41
+ page: () => {
42
+ },
43
+ identify: () => {
44
+ },
45
+ group: () => {
46
+ },
47
+ alias: () => {
48
+ },
49
+ reset: () => {
50
+ }
30
51
  };
31
- };
32
- for (let i = 0; i < window.analytics.methods.length; i++) {
33
- const key = window.analytics.methods[i];
34
- window.analytics[key] = window.analytics.factory(key);
35
52
  }
36
- window.analytics.page();
53
+ } : void 0,
54
+ use() {
55
+ return methods.reduce((acc, key) => {
56
+ acc[key] = window[k].factory(key);
57
+ return acc;
58
+ }, {});
37
59
  }
38
60
  }
39
61
  };
@@ -1,11 +1,11 @@
1
1
  import { withQuery } from "ufo";
2
- import { registryScript } from "../utils.mjs";
2
+ import { useRegistryScript } from "../utils.mjs";
3
3
  import { boolean, object, optional } from "#nuxt-scripts-validator";
4
4
  export const StripeOptions = object({
5
5
  advancedFraudSignals: optional(boolean())
6
6
  });
7
7
  export function useScriptStripe(_options) {
8
- return registryScript("stripe", (options) => ({
8
+ return useRegistryScript("stripe", (options) => ({
9
9
  scriptInput: {
10
10
  src: withQuery(
11
11
  `https://js.stripe.com/v3/`,
@@ -13,9 +13,9 @@ export function useScriptStripe(_options) {
13
13
  ),
14
14
  // opt-out of privacy defaults
15
15
  // @ts-expect-error TODO add types
16
- crossorigin: null,
16
+ crossorigin: false,
17
17
  // @ts-expect-error TODO add types
18
- referrerpolicy: null
18
+ referrerpolicy: false
19
19
  },
20
20
  schema: import.meta.dev ? StripeOptions : void 0,
21
21
  scriptOptions: {
@@ -1,13 +1,13 @@
1
- import type VimeoPlayer from 'vimeo__player';
1
+ import type ScriptVimeoPlayer from 'vimeo__player';
2
2
  import type { RegistryScriptInput } from '#nuxt-scripts';
3
3
  export interface VimeoPlayerApi {
4
- Player: VimeoPlayer;
4
+ Vimeo: {
5
+ Player: ScriptVimeoPlayer;
6
+ };
5
7
  }
6
- export declare const VimeoPlayerOptions: import("valibot").ObjectSchema<{}, undefined, {}>;
7
- export type VimeoPlayerInput = RegistryScriptInput<typeof VimeoPlayerOptions>;
8
+ export type VimeoPlayerInput = RegistryScriptInput;
8
9
  declare global {
9
- interface Window {
10
- Vimeo: VimeoPlayerApi;
10
+ interface Window extends VimeoPlayerApi {
11
11
  }
12
12
  }
13
13
  export declare function useScriptVimeoPlayer<T extends VimeoPlayerApi>(_options?: VimeoPlayerInput): T & {
@@ -1,45 +1,41 @@
1
- import { registryScript } from "../utils.mjs";
2
- import { object } from "#nuxt-scripts-validator";
1
+ import { watch } from "vue";
2
+ import { useRegistryScript } from "../utils.mjs";
3
3
  import { useHead } from "#imports";
4
- export const VimeoPlayerOptions = object({});
5
4
  export function useScriptVimeoPlayer(_options) {
6
- return registryScript("vimeoPlayer", () => ({
5
+ const instance = useRegistryScript("vimeoPlayer", () => ({
7
6
  scriptInput: {
8
7
  src: "https://player.vimeo.com/api/player.js"
9
8
  },
10
- schema: import.meta.dev ? VimeoPlayerOptions : void 0,
11
9
  scriptOptions: {
12
10
  use() {
13
- let Player;
14
- if (import.meta.client) {
15
- Player = function(...params) {
16
- return new window.Vimeo.Player(...params);
17
- };
18
- }
19
- return { Player };
11
+ return {
12
+ Vimeo: window.Vimeo
13
+ };
20
14
  }
21
- },
22
- beforeInit() {
23
- useHead({
24
- link: [
25
- {
26
- rel: "preconnect",
27
- href: "https://player.vimeo.com"
28
- },
29
- {
30
- rel: "preconnect",
31
- href: "https://i.vimeocdn.com"
32
- },
33
- {
34
- rel: "preconnect",
35
- href: "https://f.vimeocdn.com"
36
- },
37
- {
38
- rel: "preconnect",
39
- href: "https://fresnel.vimeocdn.com"
40
- }
41
- ]
42
- });
43
15
  }
44
16
  }), _options);
17
+ if (import.meta.client) {
18
+ const _ = watch(instance.$script.status, (status) => {
19
+ if (status === "loading") {
20
+ useHead({
21
+ link: [
22
+ {
23
+ rel: "preconnect",
24
+ href: "https://i.vimeocdn.com"
25
+ },
26
+ {
27
+ rel: "preconnect",
28
+ href: "https://f.vimeocdn.com"
29
+ },
30
+ {
31
+ rel: "preconnect",
32
+ href: "https://fresnel.vimeocdn.com"
33
+ }
34
+ ]
35
+ });
36
+ _();
37
+ }
38
+ });
39
+ }
40
+ return instance;
45
41
  }
@@ -1,28 +1,32 @@
1
- import { registryScript } from "../utils.mjs";
1
+ import { useRegistryScript } from "../utils.mjs";
2
2
  import { object, optional, string } from "#nuxt-scripts-validator";
3
3
  export const XPixelOptions = object({
4
4
  id: string(),
5
5
  version: optional(string())
6
6
  });
7
7
  export function useScriptXPixel(_options) {
8
- return registryScript("xPixel", (options) => ({
9
- scriptInput: {
10
- src: "https://static.ads-twitter.com/uwt.js"
11
- },
12
- schema: import.meta.dev ? XPixelOptions : void 0,
13
- scriptOptions: {
14
- use() {
15
- return { twq: window.twq };
8
+ return useRegistryScript("xPixel", (options) => {
9
+ return {
10
+ scriptInput: {
11
+ src: "https://static.ads-twitter.com/uwt.js",
12
+ // @ts-expect-error TODO fix upstream
13
+ crossorigin: false
16
14
  },
17
15
  clientInit: import.meta.server ? void 0 : () => {
18
- const s = window.twq = function(...params) {
19
- s.exe ? s.exe(s, ...params) : s.queue.push(params);
16
+ const s = window.twq = function() {
17
+ s.exe ? s.exe(s, arguments) : s.queue.push(arguments);
20
18
  };
21
19
  s.version = options?.version || "1.1";
22
20
  s.queue = [
23
21
  ["config", options?.id]
24
22
  ];
23
+ },
24
+ schema: import.meta.dev ? XPixelOptions : void 0,
25
+ scriptOptions: {
26
+ use() {
27
+ return { twq: window.twq };
28
+ }
25
29
  }
26
- }
27
- }), _options);
30
+ };
31
+ }, _options);
28
32
  }
@@ -0,0 +1,14 @@
1
+ /// <reference types="youtube" />
2
+ import type { RegistryScriptInput } from '#nuxt-scripts';
3
+ export interface YouTubePlayerApi {
4
+ YT: typeof YT;
5
+ }
6
+ declare global {
7
+ interface Window extends YouTubePlayerApi {
8
+ onYouTubeIframeAPIReady: () => void;
9
+ }
10
+ }
11
+ export type YouTubePlayerInput = RegistryScriptInput;
12
+ export declare function useScriptYouTubePlayer<T extends YouTubePlayerApi>(_options: YouTubePlayerInput): T & {
13
+ $script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
14
+ };
@@ -1,19 +1,15 @@
1
- import { registryScript } from "../utils.mjs";
2
- import { object } from "#nuxt-scripts-validator";
1
+ import { watch } from "vue";
2
+ import { useRegistryScript } from "../utils.mjs";
3
3
  import { useHead } from "#imports";
4
- export const YouTubeIframeOptions = object({
5
- // no options afaik
6
- });
7
- export function useScriptYouTubeIframe(_options) {
4
+ export function useScriptYouTubePlayer(_options) {
8
5
  let readyPromise = Promise.resolve();
9
- return registryScript("youtubeIframe", () => ({
6
+ const instance = useRegistryScript("youtubePlayer", () => ({
10
7
  scriptInput: {
11
8
  src: "https://www.youtube.com/iframe_api",
12
- // opt-out of privacy defaults
13
- // @ts-expect-error TODO add types
14
- crossorigin: null
9
+ // @ts-expect-error TODO fix types upstream
10
+ crossorigin: false
11
+ // crossorigin can't be set or it breaks
15
12
  },
16
- schema: import.meta.dev ? YouTubeIframeOptions : void 0,
17
13
  scriptOptions: {
18
14
  use() {
19
15
  return {
@@ -21,13 +17,17 @@ export function useScriptYouTubeIframe(_options) {
21
17
  return window.YT;
22
18
  })
23
19
  };
24
- },
25
- clientInit: import.meta.server ? void 0 : () => {
26
- readyPromise = new Promise((resolve) => {
27
- window.onYouTubeIframeAPIReady = resolve;
28
- });
29
- },
30
- beforeInit() {
20
+ }
21
+ },
22
+ clientInit: import.meta.server ? void 0 : () => {
23
+ readyPromise = new Promise((resolve) => {
24
+ window.onYouTubeIframeAPIReady = resolve;
25
+ });
26
+ }
27
+ }), _options);
28
+ if (import.meta.client) {
29
+ const _ = watch(instance.$script.status, (status) => {
30
+ if (status === "loading") {
31
31
  useHead({
32
32
  link: [
33
33
  {
@@ -48,7 +48,9 @@ export function useScriptYouTubeIframe(_options) {
48
48
  }
49
49
  ]
50
50
  });
51
+ _();
51
52
  }
52
- }
53
- }), _options);
53
+ });
54
+ }
55
+ return instance;
54
56
  }
@@ -5,7 +5,7 @@ import type { Input, ObjectSchema } from 'valibot';
5
5
  import type { Import } from 'unimport';
6
6
  import type { SegmentInput } from './registry/segment';
7
7
  import type { CloudflareWebAnalyticsInput } from './registry/cloudflare-web-analytics';
8
- import type { FacebookPixelInput } from './registry/facebook-pixel';
8
+ import type { MetaPixelInput } from './registry/meta-pixel';
9
9
  import type { FathomAnalyticsInput } from './registry/fathom-analytics';
10
10
  import type { HotjarInput } from './registry/hotjar';
11
11
  import type { IntercomInput } from './registry/intercom';
@@ -16,6 +16,10 @@ import type { MatomoAnalyticsInput } from './registry/matomo-analytics';
16
16
  import type { StripeInput } from './registry/stripe';
17
17
  import type { VimeoPlayerInput } from './registry/vimeo-player';
18
18
  import type { XPixelInput } from './registry/x-pixel';
19
+ import type { YouTubePlayerInput } from './registry/youtube-player';
20
+ import type { PlausibleAnalyticsInput } from './registry/plausible-analytics';
21
+ import type { NpmInput } from './registry/npm';
22
+ import type { LemonSqueezyInput } from './registry/lemon-squeezy';
19
23
  export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
20
24
  /**
21
25
  * The trigger to load the script:
@@ -32,6 +36,11 @@ export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'>
32
36
  * - `false` - Do not bundle the script. (default)
33
37
  */
34
38
  bundle?: boolean;
39
+ /**
40
+ * Skip any schema validation for the script input. This is useful for loading the script stubs for development without
41
+ * loading the actual script and not getting warnings.
42
+ */
43
+ skipValidation?: boolean;
35
44
  };
36
45
  export type NuxtUseScriptIntegrationOptions = Omit<NuxtUseScriptOptions, 'use'>;
37
46
  export type NuxtUseScriptInput = UseScriptInput;
@@ -64,23 +73,30 @@ export interface NuxtAppScript {
64
73
  at: number;
65
74
  }[];
66
75
  }
67
- export type ScriptRegistryEntry<T> = true | T | [T, NuxtUseScriptOptions<T>];
68
76
  export interface ScriptRegistry {
69
- cloudflareWebAnalytics?: ScriptRegistryEntry<CloudflareWebAnalyticsInput>;
70
- facebookPixel?: ScriptRegistryEntry<FacebookPixelInput>;
71
- fathomAnalytics?: ScriptRegistryEntry<FathomAnalyticsInput>;
72
- googleAnalytics?: ScriptRegistryEntry<GoogleAnalyticsInput>;
73
- googleMaps?: ScriptRegistryEntry<GoogleMapsInput>;
74
- googleTagManager?: ScriptRegistryEntry<GoogleTagManagerInput>;
75
- hotjar?: ScriptRegistryEntry<HotjarInput>;
76
- intercom?: ScriptRegistryEntry<IntercomInput>;
77
- matomoAnalytics?: ScriptRegistryEntry<MatomoAnalyticsInput>;
78
- segment?: ScriptRegistryEntry<SegmentInput>;
79
- stripe?: ScriptRegistryEntry<StripeInput>;
80
- vimeo?: ScriptRegistryEntry<VimeoPlayerInput>;
81
- xPixel?: ScriptRegistryEntry<XPixelInput>;
77
+ cloudflareWebAnalytics?: CloudflareWebAnalyticsInput;
78
+ metaPixel?: MetaPixelInput;
79
+ fathomAnalytics?: FathomAnalyticsInput;
80
+ plausibleAnalytics?: PlausibleAnalyticsInput;
81
+ googleAnalytics?: GoogleAnalyticsInput;
82
+ googleMaps?: GoogleMapsInput;
83
+ lemonSqueezy?: LemonSqueezyInput;
84
+ googleTagManager?: GoogleTagManagerInput;
85
+ hotjar?: HotjarInput;
86
+ intercom?: IntercomInput;
87
+ matomoAnalytics?: MatomoAnalyticsInput;
88
+ segment?: SegmentInput;
89
+ stripe?: StripeInput;
90
+ xPixel?: XPixelInput;
91
+ youtubePlayer?: YouTubePlayerInput;
92
+ vimeoPlayer?: VimeoPlayerInput;
93
+ [key: `${string}-npm`]: NpmInput;
82
94
  }
83
- export type RegistryScriptInput<T extends ObjectSchema<any>, Bundelable extends boolean = true> = Input<T> & {
95
+ export type NuxtConfigScriptRegistryEntry<T> = true | 'mock' | T | [T, NuxtUseScriptOptions<T>];
96
+ export type NuxtConfigScriptRegistry<T extends keyof ScriptRegistry = keyof ScriptRegistry> = Partial<Record<T, NuxtConfigScriptRegistryEntry<ScriptRegistry[T]>>>;
97
+ declare const emptyOptions: ObjectSchema<{}, undefined, {}>;
98
+ export type EmptyOptionsSchema = typeof emptyOptions;
99
+ export type RegistryScriptInput<T extends ObjectSchema<any> = EmptyOptionsSchema, Bundelable extends boolean = true> = Input<T> & {
84
100
  scriptInput?: UseScriptInput;
85
101
  scriptOptions?: Bundelable extends true ? Omit<NuxtUseScriptOptions, 'use'> : Omit<NuxtUseScriptOptions, 'bundle' | 'use'>;
86
102
  };
@@ -95,3 +111,4 @@ export type RegistryScripts = {
95
111
  dark: string;
96
112
  };
97
113
  }[];
114
+ export {};
@@ -0,0 +1,2 @@
1
+ import { object } from "valibot";
2
+ const emptyOptions = object({});
@@ -1,13 +1,14 @@
1
1
  import type { Input, ObjectSchema } from 'valibot';
2
2
  import type { UseScriptInput } from '@unhead/vue';
3
- import type { NuxtUseScriptOptions, RegistryScriptInput } from '#nuxt-scripts';
3
+ import type { EmptyOptionsSchema, NuxtUseScriptOptions, RegistryScriptInput, ScriptRegistry } from '#nuxt-scripts';
4
4
  type OptionsFn<O extends ObjectSchema<any>> = (options: Input<O>) => ({
5
5
  scriptInput?: UseScriptInput;
6
6
  scriptOptions?: NuxtUseScriptOptions;
7
7
  schema?: O;
8
8
  clientInit?: () => void;
9
9
  });
10
- export declare function registryScript<T extends Record<string | symbol, any>, O extends ObjectSchema<any>>(key: string, optionsFn: OptionsFn<O>, _userOptions?: RegistryScriptInput<O>): T & {
10
+ export declare function scriptRuntimeConfig<T extends keyof ScriptRegistry>(key: T): ScriptRegistry[T];
11
+ export declare function useRegistryScript<T extends Record<string | symbol, any>, O extends ObjectSchema<any> = EmptyOptionsSchema>(key: keyof ScriptRegistry | string, optionsFn: OptionsFn<O>, _userOptions?: RegistryScriptInput<O>): T & {
11
12
  $script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
12
13
  };
13
14
  export {};
@@ -1,30 +1,32 @@
1
1
  import { defu } from "defu";
2
2
  import { parse } from "#nuxt-scripts-validator";
3
- import { createError, useRuntimeConfig, useScript } from "#imports";
3
+ import { useRuntimeConfig, useScript } from "#imports";
4
4
  function validateScriptInputSchema(key, schema, options) {
5
5
  if (import.meta.dev) {
6
6
  try {
7
7
  parse(schema, options);
8
- } catch (e) {
9
- createError({
10
- cause: e,
11
- message: `Invalid script options for ${key}`
12
- });
8
+ } catch (_e) {
9
+ const e = _e;
10
+ console.error(e.issues.map((i) => `${key}.${i.path?.map((i2) => i2.key).join(",")}: ${i.message}`).join("\n"));
13
11
  }
14
12
  }
15
13
  }
16
- export function registryScript(key, optionsFn, _userOptions) {
17
- const runtimeConfig = useRuntimeConfig().public.scripts || {};
18
- const runtimeOptions = runtimeConfig[key];
19
- const userOptions = Object.assign(_userOptions || {}, runtimeOptions || {});
14
+ export function scriptRuntimeConfig(key) {
15
+ return (useRuntimeConfig().public.scripts || {})[key];
16
+ }
17
+ export function useRegistryScript(key, optionsFn, _userOptions) {
18
+ const scriptConfig = scriptRuntimeConfig(key);
19
+ const userOptions = Object.assign(_userOptions || {}, typeof scriptConfig === "object" ? scriptConfig : {});
20
20
  const options = optionsFn(userOptions);
21
21
  const scriptInput = defu(options.scriptInput, { key });
22
- const scriptOptions = Object.assign(_userOptions?.scriptOptions || {}, options.scriptOptions || {});
22
+ const scriptOptions = Object.assign(userOptions?.scriptOptions || {}, options.scriptOptions || {});
23
23
  const init = scriptOptions.beforeInit;
24
24
  scriptOptions.beforeInit = () => {
25
- import.meta.dev && options.schema && validateScriptInputSchema(key, options.schema, userOptions);
25
+ import.meta.dev && !scriptOptions.skipValidation && options.schema && validateScriptInputSchema(key, options.schema, userOptions);
26
26
  init?.();
27
- import.meta.client && options.clientInit?.();
27
+ if (import.meta.client) {
28
+ options.clientInit?.();
29
+ }
28
30
  };
29
31
  return useScript(scriptInput, scriptOptions);
30
32
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxt/scripts",
3
3
  "type": "module",
4
- "version": "0.3.3",
4
+ "version": "0.3.5",
5
5
  "description": "Load third-party scripts with better performance, privacy and DX in Nuxt Apps.",
6
6
  "author": {
7
7
  "website": "https://harlanzw.com",
@@ -43,11 +43,11 @@
43
43
  "@nuxt/devtools-kit": "^1.2.0",
44
44
  "@nuxt/devtools-ui-kit": "^1.2.0",
45
45
  "@nuxt/kit": "^3.11.2",
46
- "@types/google.maps": "^3.55.7",
46
+ "@types/google.maps": "^3.55.8",
47
47
  "@types/stripe-v3": "^3.1.33",
48
48
  "@types/vimeo__player": "^2.18.3",
49
49
  "@types/youtube": "^0.0.50",
50
- "@unhead/vue": "^1.9.8",
50
+ "@unhead/vue": "^1.9.9",
51
51
  "@vueuse/core": "^10.9.0",
52
52
  "consola": "^3.2.3",
53
53
  "defu": "^6.1.4",
@@ -75,14 +75,14 @@
75
75
  "@nuxt/devtools-ui-kit": "^1.2.0",
76
76
  "@nuxt/module-builder": "^0.6.0",
77
77
  "@nuxt/test-utils": "3.12.1",
78
- "@unhead/schema": "^1.9.8",
78
+ "@unhead/schema": "^1.9.9",
79
79
  "acorn-loose": "^8.4.0",
80
80
  "bumpp": "^9.4.1",
81
- "eslint": "9.1.1",
81
+ "eslint": "9.2.0",
82
82
  "nuxt": "^3.11.2",
83
83
  "playwright-core": "^1.43.1",
84
84
  "typescript": "^5.4.5",
85
- "vitest": "^1.5.3",
85
+ "vitest": "^1.6.0",
86
86
  "vue": "^3.4.26",
87
87
  "vue-router": "^4.3.2"
88
88
  },