@nuxt/scripts 0.1.5 → 0.1.6

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 (33) hide show
  1. package/dist/client/200.html +5 -5
  2. package/dist/client/404.html +5 -5
  3. package/dist/client/_nuxt/{C6qP6ksw.js → 7b-muJBz.js} +1 -1
  4. package/dist/client/_nuxt/{D2oMNJSZ.js → CFDTW01f.js} +1 -1
  5. package/dist/client/_nuxt/{BBafEUG8.js → LZrVsJnT.js} +1 -1
  6. package/dist/client/_nuxt/{YkgnKQjM.js → ZXwHJetA.js} +3 -3
  7. package/dist/client/_nuxt/builds/latest.json +1 -1
  8. package/dist/client/_nuxt/builds/meta/f0a0fb88-29eb-404a-b0c9-7ad64c942608.json +1 -0
  9. package/dist/client/index.html +5 -5
  10. package/dist/module.d.mts +13 -64
  11. package/dist/module.d.ts +13 -64
  12. package/dist/module.json +1 -1
  13. package/dist/module.mjs +83 -86
  14. package/dist/runtime/composables/useScript.mjs +3 -2
  15. package/dist/runtime/composables/validateScriptInputSchema.d.ts +2 -2
  16. package/dist/runtime/registry/cloudflare-web-analytics.mjs +0 -2
  17. package/dist/runtime/registry/confetti.d.ts +9 -1
  18. package/dist/runtime/registry/confetti.mjs +8 -5
  19. package/dist/runtime/registry/facebook-pixel.d.ts +1 -1
  20. package/dist/runtime/registry/facebook-pixel.mjs +1 -3
  21. package/dist/runtime/registry/fathom-analytics.d.ts +1 -2
  22. package/dist/runtime/registry/fathom-analytics.mjs +1 -1
  23. package/dist/runtime/registry/hotjar.d.ts +2 -3
  24. package/dist/runtime/registry/hotjar.mjs +2 -3
  25. package/dist/runtime/registry/intercom.d.ts +1 -2
  26. package/dist/runtime/registry/intercom.mjs +1 -3
  27. package/dist/runtime/registry/npm.d.ts +12 -0
  28. package/dist/runtime/registry/npm.mjs +22 -0
  29. package/dist/runtime/registry/segment.d.ts +1 -2
  30. package/dist/runtime/registry/segment.mjs +1 -3
  31. package/dist/runtime/types.d.ts +20 -2
  32. package/package.json +3 -3
  33. package/dist/client/_nuxt/builds/meta/72c1a85e-b70c-4e27-93ec-d6316f40b143.json +0 -1
@@ -1 +1 @@
1
- {"id":"72c1a85e-b70c-4e27-93ec-d6316f40b143","timestamp":1711777231401}
1
+ {"id":"f0a0fb88-29eb-404a-b0c9-7ad64c942608","timestamp":1711884560577}
@@ -0,0 +1 @@
1
+ {"id":"f0a0fb88-29eb-404a-b0c9-7ad64c942608","timestamp":1711884560577,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html><html><head><meta charset="utf-8">
2
2
  <meta name="viewport" content="width=device-width, initial-scale=1">
3
3
  <link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.D91GVkD7.css">
4
- <link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/YkgnKQjM.js">
4
+ <link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/ZXwHJetA.js">
5
5
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DXFkqnOI.js">
6
6
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/D6NljDpC.js">
7
7
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/CowR2XfX.js">
@@ -229,10 +229,10 @@
229
229
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DggdVF2v.js">
230
230
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/A1WiD9SJ.js">
231
231
  <link rel="prefetch" as="style" href="/__nuxt-scripts/_nuxt/error-404.ORekjfyJ.css">
232
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/BBafEUG8.js">
233
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/D2oMNJSZ.js">
232
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/LZrVsJnT.js">
233
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/CFDTW01f.js">
234
234
  <link rel="prefetch" as="style" href="/__nuxt-scripts/_nuxt/error-500.BIuFL0tW.css">
235
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/C6qP6ksw.js">
236
- <script type="module" src="/__nuxt-scripts/_nuxt/YkgnKQjM.js" crossorigin></script><script>"use strict";(()=>{const a=window,e=document.documentElement,c=window.localStorage,d=["dark","light"],n=c&&c.getItem&&c.getItem("nuxt-color-mode")||"system";let l=n==="system"?f():n;const i=e.getAttribute("data-color-mode-forced");i&&(l=i),r(l),a["__NUXT_COLOR_MODE__"]={preference:n,value:l,getColorScheme:f,addColorScheme:r,removeColorScheme:u};function r(o){const t=""+o+"",s="";e.classList?e.classList.add(t):e.className+=" "+t,s&&e.setAttribute("data-"+s,o)}function u(o){const t=""+o+"",s="";e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp(t,"g"),""),s&&e.removeAttribute("data-"+s)}function m(o){return a.matchMedia("(prefers-color-scheme"+o+")")}function f(){if(a.matchMedia&&m("").media!=="not all"){for(const o of d)if(m(":"+o).matches)return o}return"light"}})();
235
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/7b-muJBz.js">
236
+ <script type="module" src="/__nuxt-scripts/_nuxt/ZXwHJetA.js" crossorigin></script><script>"use strict";(()=>{const a=window,e=document.documentElement,c=window.localStorage,d=["dark","light"],n=c&&c.getItem&&c.getItem("nuxt-color-mode")||"system";let l=n==="system"?f():n;const i=e.getAttribute("data-color-mode-forced");i&&(l=i),r(l),a["__NUXT_COLOR_MODE__"]={preference:n,value:l,getColorScheme:f,addColorScheme:r,removeColorScheme:u};function r(o){const t=""+o+"",s="";e.classList?e.classList.add(t):e.className+=" "+t,s&&e.setAttribute("data-"+s,o)}function u(o){const t=""+o+"",s="";e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp(t,"g"),""),s&&e.removeAttribute("data-"+s)}function m(o){return a.matchMedia("(prefers-color-scheme"+o+")")}function f(){if(a.matchMedia&&m("").media!=="not all"){for(const o of d)if(m(":"+o).matches)return o}return"light"}})();
237
237
  </script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"_errors":1,"serverRendered":2,"data":3,"state":4,"once":5},{},false,{},{},["Set"]]</script>
238
238
  <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-scripts",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.d.mts CHANGED
@@ -1,68 +1,16 @@
1
1
  import * as nuxt_schema from 'nuxt/schema';
2
- import * as valibot from 'valibot';
3
- import { Input } from 'valibot';
4
- import { UseScriptOptions } from '@unhead/schema';
5
- import { UseScriptInput } from '@unhead/vue';
6
-
7
- type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
8
- /**
9
- * The trigger to load the script:
10
- * - `onNuxtReady` - Load the script when Nuxt is ready.
11
- * - `manual` - Load the script manually by calling `$script.load()` or `$script.waitForLoad()`.
12
- * - `Promise` - Load the script when the promise resolves.
13
- */
14
- trigger?: UseScriptOptions<T>['trigger'] | 'onNuxtReady';
15
- /**
16
- * Should the script be bundled as an asset and loaded from your server. This is useful for improving the
17
- * performance by avoiding the extra DNS lookup and reducing the number of requests. It also
18
- * improves privacy by not sharing the user's IP address with third-party servers.
19
- */
20
- assetStrategy?: 'bundle';
21
- /**
22
- * A hook to run when a script does not exist and will be initialized for the first time.
23
- */
24
- beforeInit?: () => void;
25
- };
26
- type NuxtUseScriptInput = UseScriptInput;
27
-
28
- interface CloudflareWebAnalyticsApi {
29
- __cfBeacon: {
30
- load: 'single';
31
- spa: boolean;
32
- token: string;
33
- };
34
- __cfRl?: unknown;
35
- }
36
- declare global {
37
- interface Window extends CloudflareWebAnalyticsApi {
38
- }
39
- }
40
- declare const CloudflareWebAnalyticsOptions: valibot.ObjectSchema<{
41
- /**
42
- * The Cloudflare Web Analytics token.
43
- *
44
- * Required when used for the first time.
45
- */
46
- token: valibot.StringSchema<string>;
47
- /**
48
- * Cloudflare Web Analytics enables measuring SPAs automatically by overriding the History API’s pushState function
49
- * and listening to the onpopstate. Hash-based router is not supported.
50
- *
51
- * @default true
52
- */
53
- spa: valibot.OptionalSchema<valibot.BooleanSchema<boolean>, undefined, boolean | undefined>;
54
- }, undefined, {
55
- token: string;
56
- spa?: boolean | undefined;
57
- }>;
2
+ import { Import } from 'unimport';
3
+ import { ScriptRegistry, NuxtUseScriptOptions, NuxtUseScriptInput } from '#nuxt-scripts';
58
4
 
59
5
  interface ModuleOptions {
60
6
  /**
61
7
  * Register scripts globally.
62
8
  */
63
- register?: {
64
- cloudflareWebAnalytics?: Input<typeof CloudflareWebAnalyticsOptions>;
65
- };
9
+ register?: ScriptRegistry;
10
+ /**
11
+ * Default options for scripts.
12
+ */
13
+ defaultScriptOptions?: NuxtUseScriptOptions;
66
14
  /**
67
15
  * Register scripts that should be loaded globally on all pages.
68
16
  */
@@ -80,7 +28,11 @@ interface ModuleOptions {
80
28
  * @default '/_scripts/'
81
29
  */
82
30
  prefix?: string;
83
- /** Currently scripts assets are exposed as public assets as part of the build. This will be configurable in future */
31
+ /**
32
+ * Scripts assets are exposed as public assets as part of the build.
33
+ *
34
+ * TODO Make configurable in future.
35
+ */
84
36
  strategy?: 'public';
85
37
  };
86
38
  /**
@@ -100,10 +52,7 @@ interface ModuleHooks {
100
52
  /**
101
53
  * Transform a script before it's registered.
102
54
  */
103
- 'scripts:transform': (ctx: {
104
- script: string;
105
- options: any;
106
- }) => Promise<void>;
55
+ 'scripts:registry': (registry: Import[]) => Promise<void>;
107
56
  }
108
57
  declare const _default: nuxt_schema.NuxtModule<ModuleOptions>;
109
58
 
package/dist/module.d.ts CHANGED
@@ -1,68 +1,16 @@
1
1
  import * as nuxt_schema from 'nuxt/schema';
2
- import * as valibot from 'valibot';
3
- import { Input } from 'valibot';
4
- import { UseScriptOptions } from '@unhead/schema';
5
- import { UseScriptInput } from '@unhead/vue';
6
-
7
- type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
8
- /**
9
- * The trigger to load the script:
10
- * - `onNuxtReady` - Load the script when Nuxt is ready.
11
- * - `manual` - Load the script manually by calling `$script.load()` or `$script.waitForLoad()`.
12
- * - `Promise` - Load the script when the promise resolves.
13
- */
14
- trigger?: UseScriptOptions<T>['trigger'] | 'onNuxtReady';
15
- /**
16
- * Should the script be bundled as an asset and loaded from your server. This is useful for improving the
17
- * performance by avoiding the extra DNS lookup and reducing the number of requests. It also
18
- * improves privacy by not sharing the user's IP address with third-party servers.
19
- */
20
- assetStrategy?: 'bundle';
21
- /**
22
- * A hook to run when a script does not exist and will be initialized for the first time.
23
- */
24
- beforeInit?: () => void;
25
- };
26
- type NuxtUseScriptInput = UseScriptInput;
27
-
28
- interface CloudflareWebAnalyticsApi {
29
- __cfBeacon: {
30
- load: 'single';
31
- spa: boolean;
32
- token: string;
33
- };
34
- __cfRl?: unknown;
35
- }
36
- declare global {
37
- interface Window extends CloudflareWebAnalyticsApi {
38
- }
39
- }
40
- declare const CloudflareWebAnalyticsOptions: valibot.ObjectSchema<{
41
- /**
42
- * The Cloudflare Web Analytics token.
43
- *
44
- * Required when used for the first time.
45
- */
46
- token: valibot.StringSchema<string>;
47
- /**
48
- * Cloudflare Web Analytics enables measuring SPAs automatically by overriding the History API’s pushState function
49
- * and listening to the onpopstate. Hash-based router is not supported.
50
- *
51
- * @default true
52
- */
53
- spa: valibot.OptionalSchema<valibot.BooleanSchema<boolean>, undefined, boolean | undefined>;
54
- }, undefined, {
55
- token: string;
56
- spa?: boolean | undefined;
57
- }>;
2
+ import { Import } from 'unimport';
3
+ import { ScriptRegistry, NuxtUseScriptOptions, NuxtUseScriptInput } from '#nuxt-scripts';
58
4
 
59
5
  interface ModuleOptions {
60
6
  /**
61
7
  * Register scripts globally.
62
8
  */
63
- register?: {
64
- cloudflareWebAnalytics?: Input<typeof CloudflareWebAnalyticsOptions>;
65
- };
9
+ register?: ScriptRegistry;
10
+ /**
11
+ * Default options for scripts.
12
+ */
13
+ defaultScriptOptions?: NuxtUseScriptOptions;
66
14
  /**
67
15
  * Register scripts that should be loaded globally on all pages.
68
16
  */
@@ -80,7 +28,11 @@ interface ModuleOptions {
80
28
  * @default '/_scripts/'
81
29
  */
82
30
  prefix?: string;
83
- /** Currently scripts assets are exposed as public assets as part of the build. This will be configurable in future */
31
+ /**
32
+ * Scripts assets are exposed as public assets as part of the build.
33
+ *
34
+ * TODO Make configurable in future.
35
+ */
84
36
  strategy?: 'public';
85
37
  };
86
38
  /**
@@ -100,10 +52,7 @@ interface ModuleHooks {
100
52
  /**
101
53
  * Transform a script before it's registered.
102
54
  */
103
- 'scripts:transform': (ctx: {
104
- script: string;
105
- options: any;
106
- }) => Promise<void>;
55
+ 'scripts:registry': (registry: Import[]) => Promise<void>;
107
56
  }
108
57
  declare const _default: nuxt_schema.NuxtModule<ModuleOptions>;
109
58
 
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.11.1",
6
6
  "bridge": false
7
7
  },
8
- "version": "0.1.5"
8
+ "version": "0.1.6"
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useNuxt, useLogger, addDevServerHandler, createResolver, addTemplate, defineNuxtModule, addImportsDir, addImports, addPluginTemplate, addPlugin, addBuildPlugin } from '@nuxt/kit';
1
+ import { useNuxt, useLogger, addDevServerHandler, createResolver, addTemplate, defineNuxtModule, addImportsDir, addImports, addPlugin, addBuildPlugin } from '@nuxt/kit';
2
2
  import { readPackageJSON } from 'pkg-types';
3
3
  import { existsSync } from 'node:fs';
4
4
  import { pathToFileURL } from 'node:url';
@@ -234,7 +234,7 @@ function extendTypes(module, template) {
234
234
  const nuxt = useNuxt();
235
235
  const { resolve } = createResolver(import.meta.url);
236
236
  addTemplate({
237
- filename: `module/${module}.d.ts`,
237
+ filename: `modules/${module}.d.ts`,
238
238
  getContents: async () => {
239
239
  const typesPath = relative(resolve(nuxt.options.rootDir, nuxt.options.buildDir, "module"), resolve("runtime/types"));
240
240
  const s = await template({ typesPath });
@@ -259,6 +259,11 @@ const module = defineNuxtModule({
259
259
  }
260
260
  },
261
261
  defaults: {
262
+ defaultScriptOptions: {
263
+ assetStrategy: "bundle",
264
+ // Not supported on all scripts, only if the src is static, runtime fallback?
265
+ trigger: "onNuxtReady"
266
+ },
262
267
  enabled: true,
263
268
  debug: false
264
269
  },
@@ -271,99 +276,91 @@ const module = defineNuxtModule({
271
276
  }
272
277
  nuxt.options.alias["#nuxt-scripts"] = resolve("./runtime/types");
273
278
  nuxt.options.runtimeConfig["nuxt-scripts"] = { version };
279
+ nuxt.options.runtimeConfig.public["nuxt-scripts"] = { defaultScriptOptions: config.defaultScriptOptions };
274
280
  addImportsDir([
275
281
  resolve("./runtime/composables")
276
282
  ]);
277
- const registry = [
278
- {
279
- name: "useScriptCloudflareTurnstile",
280
- from: resolve("./runtime/registry/cloudflare-turnstile")
281
- },
282
- {
283
- name: "useScriptCloudflareWebAnalytics",
284
- from: resolve("./runtime/registry/cloudflare-web-analytics")
285
- },
286
- {
287
- name: "useScriptConfetti",
288
- from: resolve("./runtime/registry/confetti")
289
- },
290
- {
291
- name: "useScriptFacebookPixel",
292
- from: resolve("./runtime/registry/facebook-pixel")
293
- },
294
- {
295
- name: "useScriptFathomAnalytics",
296
- from: resolve("./runtime/registry/fathom-analytics")
297
- },
298
- {
299
- name: "useScriptGoogleAnalytics",
300
- from: resolve("./runtime/registry/google-analytics")
301
- },
302
- {
303
- name: "useScriptGoogleTagManager",
304
- from: resolve("./runtime/registry/google-tag-manager")
305
- },
306
- {
307
- name: "useScriptHotjar",
308
- from: resolve("./runtime/registry/hotjar")
309
- },
310
- {
311
- name: "useScriptIntercom",
312
- from: resolve("./runtime/registry/intercom")
313
- },
314
- {
315
- name: "useScriptSegment",
316
- from: resolve("./runtime/registry/segment")
317
- }
318
- ].map((i) => {
319
- i.priority = -1;
320
- return i;
321
- });
322
- addImports(registry);
323
- const hasRegister = Object.keys(config.register || {}).length > 0;
324
- if (hasRegister) {
325
- addPluginTemplate({
326
- filename: "third-party.mjs",
327
- write: true,
328
- getContents() {
329
- const imports = ['import { defineNuxtPlugin } from "#imports";'];
330
- const inits = [];
331
- for (const [k, c] of Object.entries(config.register || {})) {
332
- const importPath = resolve(`./runtime/composables/${k}`);
333
- const exportName = k.substring(0, 1).toUpperCase() + k.substring(1);
334
- imports.unshift(`import { ${exportName} } from "${importPath}";`);
335
- inits.push(`${exportName}(${JSON.stringify(c)});`);
336
- }
337
- return [
338
- imports.join("\n"),
339
- "",
340
- "export default defineNuxtPlugin({",
341
- ' name: "nuxt-third-party",',
342
- " setup() {",
343
- inits.map((i) => ` ${i}`).join("\n"),
344
- " }",
345
- "})"
346
- ].join("\n");
283
+ nuxt.hooks.hook("modules:done", async () => {
284
+ const registry = [
285
+ {
286
+ name: "useScriptCloudflareTurnstile",
287
+ from: resolve("./runtime/registry/cloudflare-turnstile")
288
+ },
289
+ {
290
+ name: "useScriptCloudflareWebAnalytics",
291
+ from: resolve("./runtime/registry/cloudflare-web-analytics")
292
+ },
293
+ {
294
+ name: "useScriptConfetti",
295
+ from: resolve("./runtime/registry/confetti")
296
+ },
297
+ {
298
+ name: "useScriptFacebookPixel",
299
+ from: resolve("./runtime/registry/facebook-pixel")
300
+ },
301
+ {
302
+ name: "useScriptFathomAnalytics",
303
+ from: resolve("./runtime/registry/fathom-analytics")
304
+ },
305
+ {
306
+ name: "useScriptGoogleAnalytics",
307
+ from: resolve("./runtime/registry/google-analytics")
308
+ },
309
+ {
310
+ name: "useScriptGoogleTagManager",
311
+ from: resolve("./runtime/registry/google-tag-manager")
312
+ },
313
+ {
314
+ name: "useScriptHotjar",
315
+ from: resolve("./runtime/registry/hotjar")
316
+ },
317
+ {
318
+ name: "useScriptIntercom",
319
+ from: resolve("./runtime/registry/intercom")
320
+ },
321
+ {
322
+ name: "useScriptSegment",
323
+ from: resolve("./runtime/registry/segment")
324
+ },
325
+ {
326
+ name: "useScriptNpm",
327
+ from: resolve("./runtime/registry/npm")
347
328
  }
329
+ ].map((i) => {
330
+ i.priority = -1;
331
+ return i;
348
332
  });
349
- }
350
- if (config.globals?.length) {
351
- const template = addTemplate({
352
- filename: "modules/nuxt-scripts/plugin.client.mjs",
353
- getContents() {
354
- return `import { defineNuxtPlugin, useScript } from '#imports'
333
+ addImports(registry);
334
+ await nuxt.hooks.callHook("scripts:registry", registry);
335
+ if (config.globals?.length || Object.keys(config.register || {}).length) {
336
+ const template = addTemplate({
337
+ filename: `modules/${name}.mjs`,
338
+ write: true,
339
+ getContents() {
340
+ const imports = ["useScript", "defineNuxtPlugin"];
341
+ const inits = [];
342
+ for (const [k, c] of Object.entries(config.register || {})) {
343
+ const importDefinition = registry.find((i) => i.name === `useScript${k.substring(0, 1).toUpperCase() + k.substring(1)}`);
344
+ if (importDefinition) {
345
+ imports.unshift(importDefinition.name);
346
+ inits.push(`${importDefinition.name}(${JSON.stringify(c)});`);
347
+ }
348
+ }
349
+ return `import { ${imports.join(", ")} } from '#imports'
355
350
  export default defineNuxtPlugin({
351
+ name: "${name}:init",
356
352
  setup() {
357
- ${config.globals?.map((g) => !Array.isArray(g) ? ` useScript("${g.toString()}")` : g.length === 2 ? ` useScript(${JSON.stringify(g[0])}, ${JSON.stringify(g[1])} })` : ` useScript(${JSON.stringify(g[0])})`).join("\n")}
353
+ ${(config.globals || []).map((g) => !Array.isArray(g) ? ` useScript("${g.toString()}")` : g.length === 2 ? ` useScript(${JSON.stringify(g[0])}, ${JSON.stringify(g[1])} })` : ` useScript(${JSON.stringify(g[0])})`).join("\n")}
354
+ ${inits.join("\n ")}
358
355
  }
359
356
  })`;
360
- }
361
- });
362
- addPlugin({
363
- src: template.dst,
364
- mode: "client"
365
- });
366
- }
357
+ }
358
+ });
359
+ addPlugin({
360
+ src: template.dst
361
+ });
362
+ }
363
+ });
367
364
  extendTypes(name, async () => {
368
365
  return `
369
366
  declare module '#app' {
@@ -1,9 +1,10 @@
1
1
  import { useScript as _useScript, injectHead } from "@unhead/vue";
2
2
  import { hashCode } from "@unhead/shared";
3
- import { onNuxtReady, useNuxtApp } from "#imports";
3
+ import { defu } from "defu";
4
+ import { onNuxtReady, useNuxtApp, useRuntimeConfig } from "#imports";
4
5
  export function useScript(input, options) {
5
6
  input = typeof input === "string" ? { src: input } : input;
6
- options = options || {};
7
+ options = defu(options, useRuntimeConfig().public["nuxt-scripts"]?.defaultScriptOptions);
7
8
  if (options.trigger === "onNuxtReady")
8
9
  options.trigger = new Promise((resolve) => onNuxtReady(resolve));
9
10
  const nuxtApp = useNuxtApp();
@@ -1,7 +1,7 @@
1
- import { type Input, type ObjectSchema } from 'valibot';
1
+ import { type BaseSchema, type Input } from 'valibot';
2
2
  /**
3
3
  * injectScript
4
4
  *
5
5
  * Checks if a script with the 'key' value exists in head.
6
6
  */
7
- export declare function validateScriptInputSchema<T extends ObjectSchema<any>>(schema: T, options?: Input<T>): void;
7
+ export declare function validateScriptInputSchema<T extends BaseSchema<any>>(schema: T, options?: Input<T>): void;
@@ -27,9 +27,7 @@ export function useScriptCloudflareWebAnalytics(options, _scriptOptions) {
27
27
  "src": "https://static.cloudflareinsights.com/beacon.min.js",
28
28
  "data-cf-beacon": JSON.stringify(defu(options, { spa: true }))
29
29
  }, {
30
- trigger: "onNuxtReady",
31
30
  ...scriptOptions,
32
- assetStrategy: "bundle",
33
31
  use() {
34
32
  return { __cfBeacon: window.__cfBeacon, __cfRl: window.__cfRl };
35
33
  }
@@ -1,3 +1,4 @@
1
+ import { type Input } from 'valibot';
1
2
  import type { NuxtUseScriptOptions } from '#nuxt-scripts';
2
3
  export interface JSConfettiApi {
3
4
  addConfetti: (options?: {
@@ -11,4 +12,11 @@ declare global {
11
12
  };
12
13
  }
13
14
  }
14
- export declare function useScriptConfetti<T extends JSConfettiApi>(options?: NuxtUseScriptOptions<T>): any;
15
+ export declare const JSConfettiOptions: import("valibot").ObjectSchema<Pick<{
16
+ packageName: import("valibot").StringSchema<string>;
17
+ file: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
18
+ version: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
19
+ }, "version">, undefined, {
20
+ version?: string | undefined;
21
+ }>;
22
+ export declare function useScriptConfetti<T extends JSConfettiApi>(options: Input<typeof JSConfettiOptions>, _scriptOptions?: NuxtUseScriptOptions<T>): any;
@@ -1,10 +1,13 @@
1
- import { useScript } from "#imports";
2
- export function useScriptConfetti(options = {}) {
3
- return useScript({
4
- src: "https://cdn.jsdelivr.net/npm/js-confetti@latest/dist/js-confetti.browser.js"
1
+ import { pick } from "valibot";
2
+ import { NpmOptions, useScriptNpm } from "./npm.mjs";
3
+ export const JSConfettiOptions = pick(NpmOptions, ["version"]);
4
+ export function useScriptConfetti(options, _scriptOptions = {}) {
5
+ return useScriptNpm({
6
+ packageName: "js-confetti",
7
+ version: options.version,
8
+ file: "dist/js-confetti.browser.js"
5
9
  }, {
6
10
  ...options,
7
- assetStrategy: "bundle",
8
11
  use() {
9
12
  return new window.JSConfetti();
10
13
  }
@@ -33,7 +33,7 @@ declare global {
33
33
  interface Window extends FacebookPixelApi {
34
34
  }
35
35
  }
36
- declare const FacebookPixelOptions: import("valibot").ObjectSchema<{
36
+ export declare const FacebookPixelOptions: import("valibot").ObjectSchema<{
37
37
  id: import("valibot").UnionSchema<(import("valibot").StringSchema<string> | import("valibot").NumberSchema<number>)[], string | number>;
38
38
  }, undefined, {
39
39
  id: string | number;
@@ -1,6 +1,6 @@
1
1
  import { number, object, string, union } from "valibot";
2
2
  import { useScript, validateScriptInputSchema } from "#imports";
3
- const FacebookPixelOptions = object({
3
+ export const FacebookPixelOptions = object({
4
4
  id: union([string(), number()])
5
5
  });
6
6
  export function useScriptFacebookPixel(options, _scriptOptions) {
@@ -26,9 +26,7 @@ export function useScriptFacebookPixel(options, _scriptOptions) {
26
26
  src: "https://connect.facebook.net/en_US/fbevents.js",
27
27
  defer: true
28
28
  }, {
29
- trigger: "onNuxtReady",
30
29
  ...scriptOptions,
31
- assetStrategy: "bundle",
32
30
  use() {
33
31
  return { fbq: window.fbq };
34
32
  }
@@ -1,6 +1,6 @@
1
1
  import { type Input } from 'valibot';
2
2
  import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
- declare const FathomAnalyticsOptions: import("valibot").ObjectSchema<{
3
+ export declare const FathomAnalyticsOptions: import("valibot").ObjectSchema<{
4
4
  site: import("valibot").StringSchema<string>;
5
5
  src: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
6
6
  'data-spa': import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"auto", "auto"> | import("valibot").LiteralSchema<"history", "history"> | import("valibot").LiteralSchema<"hash", "hash">)[], "auto" | "history" | "hash">, undefined, "auto" | "history" | "hash" | undefined>;
@@ -30,4 +30,3 @@ declare global {
30
30
  }
31
31
  }
32
32
  export declare function useScriptFathomAnalytics<T extends FathomAnalyticsApi>(options?: Input<typeof FathomAnalyticsOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
33
- export {};
@@ -1,6 +1,6 @@
1
1
  import { boolean, literal, object, optional, string, union } from "valibot";
2
2
  import { useScript, validateScriptInputSchema } from "#imports";
3
- const FathomAnalyticsOptions = object({
3
+ export const FathomAnalyticsOptions = object({
4
4
  "site": string(),
5
5
  // site is required
6
6
  "src": optional(string()),
@@ -13,12 +13,11 @@ declare global {
13
13
  };
14
14
  }
15
15
  }
16
- declare const HotjarOptions: import("valibot").ObjectSchema<{
16
+ export declare const HotjarOptions: import("valibot").ObjectSchema<{
17
17
  id: import("valibot").NumberSchema<number>;
18
18
  sv: import("valibot").OptionalSchema<import("valibot").NumberSchema<number>, undefined, number | undefined>;
19
19
  }, undefined, {
20
20
  id: number;
21
21
  sv?: number | undefined;
22
22
  }>;
23
- export declare function useScriptHotjar<T extends HotjarApi>(options?: Input<typeof HotjarOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
24
- export {};
23
+ export declare function useScriptHotjar<T extends HotjarApi>(options?: Input<typeof HotjarOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'assetStrategy' | 'beforeInit' | 'use'>): any;
@@ -1,6 +1,6 @@
1
1
  import { number, object, optional } from "valibot";
2
2
  import { useScript, validateScriptInputSchema } from "#imports";
3
- const HotjarOptions = object({
3
+ export const HotjarOptions = object({
4
4
  id: number(),
5
5
  sv: optional(number())
6
6
  });
@@ -17,12 +17,11 @@ export function useScriptHotjar(options, _scriptOptions) {
17
17
  };
18
18
  return useScript({
19
19
  key: "hotjar",
20
+ // requires extra steps to bundle
20
21
  src: `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv}`,
21
22
  defer: true
22
23
  }, {
23
- trigger: "onNuxtReady",
24
24
  ...scriptOptions,
25
- assetStrategy: "bundle",
26
25
  use() {
27
26
  return { hj: window.hj };
28
27
  }
@@ -1,6 +1,6 @@
1
1
  import { type Input } from 'valibot';
2
2
  import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
- declare const IntercomOptions: import("valibot").ObjectSchema<{
3
+ export declare const IntercomOptions: import("valibot").ObjectSchema<{
4
4
  app_id: import("valibot").StringSchema<string>;
5
5
  api_base: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"https://api-iam.intercom.io", "https://api-iam.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.eu.intercom.io", "https://api-iam.eu.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.au.intercom.io", "https://api-iam.au.intercom.io">)[], "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io">, undefined, "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io" | undefined>;
6
6
  name: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
@@ -28,4 +28,3 @@ declare global {
28
28
  }
29
29
  }
30
30
  export declare function useScriptIntercom<T extends IntercomApi>(options?: Input<typeof IntercomOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
31
- export {};
@@ -1,6 +1,6 @@
1
1
  import { literal, number, object, optional, string, union } from "valibot";
2
2
  import { useScript, validateScriptInputSchema } from "#imports";
3
- const IntercomOptions = object({
3
+ export const IntercomOptions = object({
4
4
  app_id: string(),
5
5
  api_base: optional(union([literal("https://api-iam.intercom.io"), literal("https://api-iam.eu.intercom.io"), literal("https://api-iam.au.intercom.io")])),
6
6
  name: optional(string()),
@@ -23,9 +23,7 @@ export function useScriptIntercom(options, _scriptOptions) {
23
23
  src: `https://widget.intercom.io/widget/${options?.app_id}`,
24
24
  defer: true
25
25
  }, {
26
- trigger: "onNuxtReady",
27
26
  ...scriptOptions,
28
- assetStrategy: "bundle",
29
27
  use() {
30
28
  return { Intercom: window.Intercom };
31
29
  }