@nuxt/scripts 0.3.0 → 0.3.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.
Files changed (66) hide show
  1. package/README.md +19 -10
  2. package/dist/client/200.html +5 -5
  3. package/dist/client/404.html +5 -5
  4. package/dist/client/_nuxt/{DIt5FBMJ.js → 5Hk8ESNW.js} +1 -1
  5. package/dist/client/_nuxt/BxcSmj5a.js +31 -0
  6. package/dist/client/_nuxt/{DOakR0z3.js → DeEC_XNp.js} +1 -1
  7. package/dist/client/_nuxt/{CovTDKFE.js → TwOttoDL.js} +1 -1
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/d293267d-837e-425a-bc4b-81773905567b.json +1 -0
  10. package/dist/client/index.html +5 -5
  11. package/dist/module.json +1 -1
  12. package/dist/module.mjs +1 -0
  13. package/dist/runtime/components/GoogleMaps.vue +1 -1
  14. package/dist/runtime/components/StripePricingTableEmbed.vue +1 -1
  15. package/dist/runtime/components/VimeoEmbed.vue +1 -1
  16. package/dist/runtime/components/YouTubeEmbed.vue +1 -1
  17. package/dist/runtime/composables/useConsentScriptTrigger.d.ts +13 -0
  18. package/dist/runtime/composables/{createConsentScriptTrigger.mjs → useConsentScriptTrigger.mjs} +11 -3
  19. package/dist/runtime/composables/useElementScriptTrigger.d.ts +15 -1
  20. package/dist/runtime/composables/useElementScriptTrigger.mjs +4 -2
  21. package/dist/runtime/composables/useScript.d.ts +1 -1
  22. package/dist/runtime/registry/cloudflare-web-analytics.d.ts +1 -1
  23. package/dist/runtime/registry/cloudflare-web-analytics.mjs +1 -1
  24. package/dist/runtime/registry/facebook-pixel.d.ts +1 -1
  25. package/dist/runtime/registry/facebook-pixel.mjs +2 -2
  26. package/dist/runtime/registry/fathom-analytics.d.ts +1 -1
  27. package/dist/runtime/registry/fathom-analytics.mjs +1 -1
  28. package/dist/runtime/registry/google-analytics.d.ts +1 -1
  29. package/dist/runtime/registry/google-analytics.mjs +2 -2
  30. package/dist/runtime/registry/google-maps.d.ts +9 -3
  31. package/dist/runtime/registry/google-maps.mjs +2 -2
  32. package/dist/runtime/registry/google-tag-manager.d.ts +1 -1
  33. package/dist/runtime/registry/google-tag-manager.mjs +2 -2
  34. package/dist/runtime/registry/hotjar.d.ts +1 -1
  35. package/dist/runtime/registry/hotjar.mjs +2 -2
  36. package/dist/runtime/registry/intercom.d.ts +3 -3
  37. package/dist/runtime/registry/intercom.mjs +2 -2
  38. package/dist/runtime/registry/lemon-squeezy.d.ts +1 -1
  39. package/dist/runtime/registry/lemon-squeezy.mjs +2 -2
  40. package/dist/runtime/registry/matomo-analytics.d.ts +1 -1
  41. package/dist/runtime/registry/matomo-analytics.mjs +2 -2
  42. package/dist/runtime/registry/npm.d.ts +1 -1
  43. package/dist/runtime/registry/npm.mjs +1 -1
  44. package/dist/runtime/registry/plausible-analytics.d.ts +1 -1
  45. package/dist/runtime/registry/plausible-analytics.mjs +2 -2
  46. package/dist/runtime/registry/segment.d.ts +1 -1
  47. package/dist/runtime/registry/segment.mjs +2 -2
  48. package/dist/runtime/registry/stripe.d.ts +3 -3
  49. package/dist/runtime/registry/stripe.mjs +2 -2
  50. package/dist/runtime/registry/vimeo-player.d.ts +1 -1
  51. package/dist/runtime/registry/vimeo-player.mjs +2 -2
  52. package/dist/runtime/registry/x-pixel.d.ts +1 -1
  53. package/dist/runtime/registry/x-pixel.mjs +2 -2
  54. package/dist/runtime/registry/youtube-iframe.d.ts +2 -2
  55. package/dist/runtime/registry/youtube-iframe.mjs +2 -2
  56. package/dist/runtime/types.d.ts +2 -2
  57. package/dist/runtime/utils.d.ts +1 -4
  58. package/dist/runtime/utils.mjs +4 -8
  59. package/dist/runtime/validation/mock.d.ts +36 -0
  60. package/dist/runtime/validation/mock.mjs +13 -0
  61. package/dist/runtime/validation/valibot.d.ts +1 -0
  62. package/dist/runtime/validation/valibot.mjs +1 -0
  63. package/package.json +1 -1
  64. package/dist/client/_nuxt/8T3kBMJO.js +0 -31
  65. package/dist/client/_nuxt/builds/meta/ccc94de9-89fa-400b-88f2-8fc2599e191f.json +0 -1
  66. package/dist/runtime/composables/createConsentScriptTrigger.d.ts +0 -6
@@ -36,6 +36,6 @@ export declare const XPixelOptions: import("valibot").ObjectSchema<{
36
36
  }>;
37
37
  export type XPixelInput = RegistryScriptInput<typeof XPixelOptions>;
38
38
  export declare function useScriptXPixel<T extends XPixelApi>(_options?: XPixelInput): T & {
39
- $script: import("@unhead/vue").VueScriptInstance<T> & Promise<T>;
39
+ $script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
40
40
  };
41
41
  export {};
@@ -1,5 +1,5 @@
1
- import { object, optional, string } from "valibot";
2
1
  import { registryScript } from "../utils.mjs";
2
+ import { object, optional, string } from "#nuxt-scripts-validator";
3
3
  export const XPixelOptions = object({
4
4
  id: string(),
5
5
  version: optional(string())
@@ -9,7 +9,7 @@ export function useScriptXPixel(_options) {
9
9
  scriptInput: {
10
10
  src: "https://static.ads-twitter.com/uwt.js"
11
11
  },
12
- schema: XPixelOptions,
12
+ schema: import.meta.dev ? XPixelOptions : void 0,
13
13
  scriptOptions: {
14
14
  use() {
15
15
  return { twq: window.twq };
@@ -1,4 +1,4 @@
1
- import type YT from '@types/youtube';
1
+ /// <reference types="youtube" />
2
2
  import type { RegistryScriptInput } from '#nuxt-scripts';
3
3
  export interface YouTubeIframeApi {
4
4
  YT: typeof YT;
@@ -11,5 +11,5 @@ declare global {
11
11
  export declare const YouTubeIframeOptions: import("valibot").ObjectSchema<{}, undefined, {}>;
12
12
  export type YouTubeIFrameInput = RegistryScriptInput<typeof YouTubeIframeOptions>;
13
13
  export declare function useScriptYouTubeIframe<T extends YouTubeIframeApi>(_options: YouTubeIFrameInput): T & {
14
- $script: import("@unhead/vue").VueScriptInstance<T> & Promise<T>;
14
+ $script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
15
15
  };
@@ -1,5 +1,5 @@
1
- import { object } from "valibot";
2
1
  import { registryScript } from "../utils.mjs";
2
+ import { object } from "#nuxt-scripts-validator";
3
3
  import { useHead } from "#imports";
4
4
  export const YouTubeIframeOptions = object({
5
5
  // no options afaik
@@ -13,7 +13,7 @@ export function useScriptYouTubeIframe(_options) {
13
13
  // @ts-expect-error TODO add types
14
14
  crossorigin: null
15
15
  },
16
- schema: YouTubeIframeOptions,
16
+ schema: import.meta.dev ? YouTubeIframeOptions : void 0,
17
17
  scriptOptions: {
18
18
  use() {
19
19
  return {
@@ -39,7 +39,7 @@ export interface TrackedPage {
39
39
  title?: string;
40
40
  path: string;
41
41
  }
42
- export interface ConsentPromiseOptions {
42
+ export interface ConsentScriptTriggerOptions {
43
43
  /**
44
44
  * An optional reactive (or promise) reference to the consent state. You can use this to accept the consent for scripts
45
45
  * instead of using the accept() method.
@@ -49,7 +49,7 @@ export interface ConsentPromiseOptions {
49
49
  * Should the script be loaded on the `requestIdleCallback` callback. This is useful for non-essential scripts that
50
50
  * have already been consented to be loaded.
51
51
  */
52
- loadOnNuxtReady?: boolean;
52
+ postConsentTrigger?: NuxtUseScriptOptions['trigger'];
53
53
  }
54
54
  export interface NuxtAppScript {
55
55
  key: string;
@@ -1,9 +1,6 @@
1
1
  import type { Input, ObjectSchema } from 'valibot';
2
2
  import type { UseScriptInput } from '@unhead/vue';
3
3
  import type { NuxtUseScriptOptions, RegistryScriptInput } from '#nuxt-scripts';
4
- export declare function mockFallbackScript(name: string, module: string): Record<string | symbol, any> & {
5
- $script: import("@unhead/vue").VueScriptInstance<Record<string | symbol, any>> & Promise<Record<string | symbol, any>>;
6
- };
7
4
  type OptionsFn<O extends ObjectSchema<any>> = (options: Input<O>) => ({
8
5
  scriptInput?: UseScriptInput;
9
6
  scriptOptions?: NuxtUseScriptOptions;
@@ -11,6 +8,6 @@ type OptionsFn<O extends ObjectSchema<any>> = (options: Input<O>) => ({
11
8
  clientInit?: () => void;
12
9
  });
13
10
  export declare function registryScript<T extends Record<string | symbol, any>, O extends ObjectSchema<any>>(key: string, optionsFn: OptionsFn<O>, _userOptions?: RegistryScriptInput<O>): T & {
14
- $script: import("@unhead/vue").VueScriptInstance<T> & Promise<T>;
11
+ $script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
15
12
  };
16
13
  export {};
@@ -1,18 +1,14 @@
1
1
  import { defu } from "defu";
2
- import { parse } from "valibot";
2
+ import { parse } from "#nuxt-scripts-validator";
3
3
  import { createError, useRuntimeConfig, useScript } from "#imports";
4
- export function mockFallbackScript(name, module) {
5
- console.error(`${name} is provided by ${module}. Check your console to install it or run 'npx nuxi@latest module add ${module}'`);
6
- return useScript("", { trigger: "manual" });
7
- }
8
- function validateScriptInputSchema(schema, options) {
4
+ function validateScriptInputSchema(key, schema, options) {
9
5
  if (import.meta.dev) {
10
6
  try {
11
7
  parse(schema, options);
12
8
  } catch (e) {
13
9
  createError({
14
10
  cause: e,
15
- message: "Invalid script options"
11
+ message: `Invalid script options for ${key}`
16
12
  });
17
13
  }
18
14
  }
@@ -26,7 +22,7 @@ export function registryScript(key, optionsFn, _userOptions) {
26
22
  const scriptOptions = Object.assign(_userOptions?.scriptOptions || {}, options.scriptOptions || {});
27
23
  const init = scriptOptions.beforeInit;
28
24
  scriptOptions.beforeInit = () => {
29
- import.meta.dev && options.schema && validateScriptInputSchema(options.schema, userOptions);
25
+ import.meta.dev && options.schema && validateScriptInputSchema(key, options.schema, userOptions);
30
26
  init?.();
31
27
  import.meta.client && options.clientInit?.();
32
28
  };
@@ -0,0 +1,36 @@
1
+ export declare const parse: (() => void) & {
2
+ __unenv__: boolean;
3
+ };
4
+ export declare const object: (() => void) & {
5
+ __unenv__: boolean;
6
+ };
7
+ export declare const array: (() => void) & {
8
+ __unenv__: boolean;
9
+ };
10
+ export declare const string: (() => void) & {
11
+ __unenv__: boolean;
12
+ };
13
+ export declare const number: (() => void) & {
14
+ __unenv__: boolean;
15
+ };
16
+ export declare const boolean: (() => void) & {
17
+ __unenv__: boolean;
18
+ };
19
+ export declare const optional: (() => void) & {
20
+ __unenv__: boolean;
21
+ };
22
+ export declare const literal: (() => void) & {
23
+ __unenv__: boolean;
24
+ };
25
+ export declare const union: (() => void) & {
26
+ __unenv__: boolean;
27
+ };
28
+ export declare const record: (() => void) & {
29
+ __unenv__: boolean;
30
+ };
31
+ export declare const any: (() => void) & {
32
+ __unenv__: boolean;
33
+ };
34
+ export declare const minLength: (() => void) & {
35
+ __unenv__: boolean;
36
+ };
@@ -0,0 +1,13 @@
1
+ import noop from "unenv/runtime/mock/noop";
2
+ export const parse = noop;
3
+ export const object = noop;
4
+ export const array = noop;
5
+ export const string = noop;
6
+ export const number = noop;
7
+ export const boolean = noop;
8
+ export const optional = noop;
9
+ export const literal = noop;
10
+ export const union = noop;
11
+ export const record = noop;
12
+ export const any = noop;
13
+ export const minLength = noop;
@@ -0,0 +1 @@
1
+ export * from 'valibot';
@@ -0,0 +1 @@
1
+ export * from "valibot";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxt/scripts",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
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",