@nuxt/scripts 0.1.4 → 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 (37) hide show
  1. package/README.md +24 -22
  2. package/dist/client/200.html +5 -5
  3. package/dist/client/404.html +5 -5
  4. package/dist/client/_nuxt/{C2uur0MR.js → 7b-muJBz.js} +1 -1
  5. package/dist/client/_nuxt/{B3yRAOXz.js → CFDTW01f.js} +1 -1
  6. package/dist/client/_nuxt/{CO8u40Ut.js → LZrVsJnT.js} +1 -1
  7. package/dist/client/_nuxt/{BqAhYH0E.js → ZXwHJetA.js} +4 -4
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/f0a0fb88-29eb-404a-b0c9-7ad64c942608.json +1 -0
  10. package/dist/client/index.html +5 -5
  11. package/dist/module.d.mts +13 -25
  12. package/dist/module.d.ts +13 -25
  13. package/dist/module.json +1 -1
  14. package/dist/module.mjs +114 -17
  15. package/dist/runtime/composables/useScript.d.ts +4 -2
  16. package/dist/runtime/composables/useScript.mjs +13 -4
  17. package/dist/runtime/composables/validateScriptInputSchema.d.ts +7 -0
  18. package/dist/runtime/composables/validateScriptInputSchema.mjs +12 -0
  19. package/dist/runtime/registry/cloudflare-web-analytics.d.ts +1 -2
  20. package/dist/runtime/registry/cloudflare-web-analytics.mjs +4 -6
  21. package/dist/runtime/registry/confetti.d.ts +9 -1
  22. package/dist/runtime/registry/confetti.mjs +8 -5
  23. package/dist/runtime/registry/facebook-pixel.d.ts +1 -1
  24. package/dist/runtime/registry/facebook-pixel.mjs +5 -8
  25. package/dist/runtime/registry/fathom-analytics.d.ts +1 -2
  26. package/dist/runtime/registry/fathom-analytics.mjs +4 -5
  27. package/dist/runtime/registry/hotjar.d.ts +2 -3
  28. package/dist/runtime/registry/hotjar.mjs +5 -8
  29. package/dist/runtime/registry/intercom.d.ts +1 -2
  30. package/dist/runtime/registry/intercom.mjs +4 -7
  31. package/dist/runtime/registry/npm.d.ts +12 -0
  32. package/dist/runtime/registry/npm.mjs +22 -0
  33. package/dist/runtime/registry/segment.d.ts +1 -2
  34. package/dist/runtime/registry/segment.mjs +6 -9
  35. package/dist/runtime/types.d.ts +31 -1
  36. package/package.json +7 -3
  37. package/dist/client/_nuxt/builds/meta/4e9eefe2-f4a5-46ff-889b-aa701f38d2cd.json +0 -1
@@ -1 +1 @@
1
- {"id":"4e9eefe2-f4a5-46ff-889b-aa701f38d2cd","timestamp":1711697722263}
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/BqAhYH0E.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/CO8u40Ut.js">
233
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/B3yRAOXz.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/C2uur0MR.js">
236
- <script type="module" src="/__nuxt-scripts/_nuxt/BqAhYH0E.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,29 +1,16 @@
1
1
  import * as nuxt_schema from 'nuxt/schema';
2
- import { UseScriptOptions } from '@unhead/schema';
3
- import { UseScriptInput } from '@unhead/vue';
2
+ import { Import } from 'unimport';
3
+ import { ScriptRegistry, NuxtUseScriptOptions, NuxtUseScriptInput } from '#nuxt-scripts';
4
4
 
5
- type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
5
+ interface ModuleOptions {
6
6
  /**
7
- * The trigger to load the script:
8
- * - `onNuxtReady` - Load the script when Nuxt is ready.
9
- * - `manual` - Load the script manually by calling `$script.load()` or `$script.waitForLoad()`.
10
- * - `Promise` - Load the script when the promise resolves.
7
+ * Register scripts globally.
11
8
  */
12
- trigger?: UseScriptOptions<T>['trigger'] | 'onNuxtReady';
9
+ register?: ScriptRegistry;
13
10
  /**
14
- * Should the script be bundled as an asset and loaded from your server. This is useful for improving the
15
- * performance by avoiding the extra DNS lookup and reducing the number of requests. It also
16
- * improves privacy by not sharing the user's IP address with third-party servers.
11
+ * Default options for scripts.
17
12
  */
18
- assetStrategy?: 'bundle';
19
- /**
20
- * A hook to run when a script does not exist and will be initialized for the first time.
21
- */
22
- beforeInit?: () => void;
23
- };
24
- type NuxtUseScriptInput = UseScriptInput;
25
-
26
- interface ModuleOptions {
13
+ defaultScriptOptions?: NuxtUseScriptOptions;
27
14
  /**
28
15
  * Register scripts that should be loaded globally on all pages.
29
16
  */
@@ -41,7 +28,11 @@ interface ModuleOptions {
41
28
  * @default '/_scripts/'
42
29
  */
43
30
  prefix?: string;
44
- /** 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
+ */
45
36
  strategy?: 'public';
46
37
  };
47
38
  /**
@@ -61,10 +52,7 @@ interface ModuleHooks {
61
52
  /**
62
53
  * Transform a script before it's registered.
63
54
  */
64
- 'scripts:transform': (ctx: {
65
- script: string;
66
- options: any;
67
- }) => Promise<void>;
55
+ 'scripts:registry': (registry: Import[]) => Promise<void>;
68
56
  }
69
57
  declare const _default: nuxt_schema.NuxtModule<ModuleOptions>;
70
58
 
package/dist/module.d.ts CHANGED
@@ -1,29 +1,16 @@
1
1
  import * as nuxt_schema from 'nuxt/schema';
2
- import { UseScriptOptions } from '@unhead/schema';
3
- import { UseScriptInput } from '@unhead/vue';
2
+ import { Import } from 'unimport';
3
+ import { ScriptRegistry, NuxtUseScriptOptions, NuxtUseScriptInput } from '#nuxt-scripts';
4
4
 
5
- type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
5
+ interface ModuleOptions {
6
6
  /**
7
- * The trigger to load the script:
8
- * - `onNuxtReady` - Load the script when Nuxt is ready.
9
- * - `manual` - Load the script manually by calling `$script.load()` or `$script.waitForLoad()`.
10
- * - `Promise` - Load the script when the promise resolves.
7
+ * Register scripts globally.
11
8
  */
12
- trigger?: UseScriptOptions<T>['trigger'] | 'onNuxtReady';
9
+ register?: ScriptRegistry;
13
10
  /**
14
- * Should the script be bundled as an asset and loaded from your server. This is useful for improving the
15
- * performance by avoiding the extra DNS lookup and reducing the number of requests. It also
16
- * improves privacy by not sharing the user's IP address with third-party servers.
11
+ * Default options for scripts.
17
12
  */
18
- assetStrategy?: 'bundle';
19
- /**
20
- * A hook to run when a script does not exist and will be initialized for the first time.
21
- */
22
- beforeInit?: () => void;
23
- };
24
- type NuxtUseScriptInput = UseScriptInput;
25
-
26
- interface ModuleOptions {
13
+ defaultScriptOptions?: NuxtUseScriptOptions;
27
14
  /**
28
15
  * Register scripts that should be loaded globally on all pages.
29
16
  */
@@ -41,7 +28,11 @@ interface ModuleOptions {
41
28
  * @default '/_scripts/'
42
29
  */
43
30
  prefix?: string;
44
- /** 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
+ */
45
36
  strategy?: 'public';
46
37
  };
47
38
  /**
@@ -61,10 +52,7 @@ interface ModuleHooks {
61
52
  /**
62
53
  * Transform a script before it's registered.
63
54
  */
64
- 'scripts:transform': (ctx: {
65
- script: string;
66
- options: any;
67
- }) => Promise<void>;
55
+ 'scripts:registry': (registry: Import[]) => Promise<void>;
68
56
  }
69
57
  declare const _default: nuxt_schema.NuxtModule<ModuleOptions>;
70
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.4"
8
+ "version": "0.1.6"
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useNuxt, useLogger, addDevServerHandler, defineNuxtModule, createResolver, addImportsDir, addTemplate, 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';
@@ -11,7 +11,7 @@ import { lazyEventHandler, eventHandler, createError } from 'h3';
11
11
  import { fetch } from 'ofetch';
12
12
  import { colors } from 'consola/utils';
13
13
  import { defu } from 'defu';
14
- import { join } from 'pathe';
14
+ import { join, relative } from 'pathe';
15
15
  import { hash } from 'ohash';
16
16
  import { createStorage } from 'unstorage';
17
17
  import fsDriver from 'unstorage/drivers/fs-lite';
@@ -230,6 +230,25 @@ function setupPublicAssetStrategy(options = {}) {
230
230
  return { normalizeScriptData };
231
231
  }
232
232
 
233
+ function extendTypes(module, template) {
234
+ const nuxt = useNuxt();
235
+ const { resolve } = createResolver(import.meta.url);
236
+ addTemplate({
237
+ filename: `modules/${module}.d.ts`,
238
+ getContents: async () => {
239
+ const typesPath = relative(resolve(nuxt.options.rootDir, nuxt.options.buildDir, "module"), resolve("runtime/types"));
240
+ const s = await template({ typesPath });
241
+ return `// Generated by ${module}
242
+ ${s}
243
+ export {}
244
+ `;
245
+ }
246
+ });
247
+ nuxt.hooks.hook("prepare:types", ({ references }) => {
248
+ references.push({ path: resolve(nuxt.options.buildDir, `module/${module}.d.ts`) });
249
+ });
250
+ }
251
+
233
252
  const module = defineNuxtModule({
234
253
  meta: {
235
254
  name: "@nuxt/scripts",
@@ -240,39 +259,117 @@ const module = defineNuxtModule({
240
259
  }
241
260
  },
242
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
+ },
243
267
  enabled: true,
244
268
  debug: false
245
269
  },
246
270
  async setup(config, nuxt) {
247
271
  const { resolve } = createResolver(import.meta.url);
248
- const { version } = await readPackageJSON(resolve("../package.json"));
272
+ const { version, name } = await readPackageJSON(resolve("../package.json"));
249
273
  if (!config.enabled) {
250
274
  logger.debug("The module is disabled, skipping setup.");
251
275
  return;
252
276
  }
253
277
  nuxt.options.alias["#nuxt-scripts"] = resolve("./runtime/types");
254
278
  nuxt.options.runtimeConfig["nuxt-scripts"] = { version };
279
+ nuxt.options.runtimeConfig.public["nuxt-scripts"] = { defaultScriptOptions: config.defaultScriptOptions };
255
280
  addImportsDir([
256
- resolve("./runtime/composables"),
257
- resolve("./runtime/registry")
281
+ resolve("./runtime/composables")
258
282
  ]);
259
- if (config.globals?.length) {
260
- const template = addTemplate({
261
- filename: "modules/nuxt-scripts/plugin.client.mjs",
262
- getContents() {
263
- return `import { defineNuxtPlugin, useScript } from '#imports'
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")
328
+ }
329
+ ].map((i) => {
330
+ i.priority = -1;
331
+ return i;
332
+ });
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'
264
350
  export default defineNuxtPlugin({
351
+ name: "${name}:init",
265
352
  setup() {
266
- ${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 ")}
267
355
  }
268
356
  })`;
269
- }
270
- });
271
- addPlugin({
272
- src: template.dst,
273
- mode: "client"
274
- });
357
+ }
358
+ });
359
+ addPlugin({
360
+ src: template.dst
361
+ });
362
+ }
363
+ });
364
+ extendTypes(name, async () => {
365
+ return `
366
+ declare module '#app' {
367
+ interface NuxtApp {
368
+ ${nuxt.options.dev ? `_scripts: (import('#nuxt-scripts').NuxtAppScript)[]` : ""}
275
369
  }
370
+ }
371
+ `;
372
+ });
276
373
  const scriptMap = /* @__PURE__ */ new Map();
277
374
  const { normalizeScriptData } = setupPublicAssetStrategy(config.assets);
278
375
  addBuildPlugin(NuxtScriptAssetBundlerTransformer({
@@ -1,3 +1,5 @@
1
- import { type UseScriptInput } from '@unhead/vue';
1
+ import { type UseScriptInput, type VueScriptInstance } from '@unhead/vue';
2
2
  import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
- export declare function useScript<T>(input: UseScriptInput, options?: NuxtUseScriptOptions): any;
3
+ export declare function useScript<T>(input: UseScriptInput, options?: NuxtUseScriptOptions): T & {
4
+ $script: VueScriptInstance<T>;
5
+ };
@@ -1,15 +1,24 @@
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();
10
- const id = input.key || hashCode(input.src || (typeof input.innerHTML === "string" ? input.innerHTML : ""));
11
- if (import.meta.dev && !nuxtApp.scripts?.[id])
11
+ const id = input.key || input.src || hashCode(typeof input.innerHTML === "string" ? input.innerHTML : "");
12
+ if (!nuxtApp.scripts?.[id]) {
12
13
  options.beforeInit?.();
14
+ if (import.meta.client) {
15
+ performance?.mark?.("mark_feature_usage", {
16
+ detail: {
17
+ feature: `nuxt-scripts:${id}`
18
+ }
19
+ });
20
+ }
21
+ }
13
22
  const instance = _useScript(input, options);
14
23
  if (import.meta.dev && import.meta.client) {
15
24
  let syncScripts = function() {
@@ -0,0 +1,7 @@
1
+ import { type BaseSchema, type Input } from 'valibot';
2
+ /**
3
+ * injectScript
4
+ *
5
+ * Checks if a script with the 'key' value exists in head.
6
+ */
7
+ export declare function validateScriptInputSchema<T extends BaseSchema<any>>(schema: T, options?: Input<T>): void;
@@ -0,0 +1,12 @@
1
+ import { parse } from "valibot";
2
+ import { createError } from "#imports";
3
+ export function validateScriptInputSchema(schema, options) {
4
+ try {
5
+ parse(schema, options);
6
+ } catch (e) {
7
+ createError({
8
+ cause: e,
9
+ message: "Invalid script options"
10
+ });
11
+ }
12
+ }
@@ -12,7 +12,7 @@ declare global {
12
12
  interface Window extends CloudflareWebAnalyticsApi {
13
13
  }
14
14
  }
15
- declare const CloudflareWebAnalyticsOptions: import("valibot").ObjectSchema<{
15
+ export declare const CloudflareWebAnalyticsOptions: import("valibot").ObjectSchema<{
16
16
  /**
17
17
  * The Cloudflare Web Analytics token.
18
18
  *
@@ -31,4 +31,3 @@ declare const CloudflareWebAnalyticsOptions: import("valibot").ObjectSchema<{
31
31
  spa?: boolean | undefined;
32
32
  }>;
33
33
  export declare function useScriptCloudflareWebAnalytics<T extends CloudflareWebAnalyticsApi>(options?: Input<typeof CloudflareWebAnalyticsOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
34
- export {};
@@ -1,7 +1,7 @@
1
- import { boolean, minLength, object, optional, parse, string } from "valibot";
1
+ import { boolean, minLength, object, optional, string } from "valibot";
2
2
  import { defu } from "defu";
3
- import { useScript } from "#imports";
4
- const CloudflareWebAnalyticsOptions = object({
3
+ import { useScript, validateScriptInputSchema } from "#imports";
4
+ export const CloudflareWebAnalyticsOptions = object({
5
5
  /**
6
6
  * The Cloudflare Web Analytics token.
7
7
  *
@@ -20,16 +20,14 @@ export function useScriptCloudflareWebAnalytics(options, _scriptOptions) {
20
20
  const scriptOptions = _scriptOptions || {};
21
21
  if (import.meta.dev) {
22
22
  scriptOptions.beforeInit = () => {
23
- parse(CloudflareWebAnalyticsOptions, options);
23
+ validateScriptInputSchema(CloudflareWebAnalyticsOptions, options);
24
24
  };
25
25
  }
26
26
  return useScript({
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,16 +1,15 @@
1
- import { number, object, parse, string, union } from "valibot";
2
- import { useScript } from "#imports";
3
- const FacebookPixelOptions = object({
1
+ import { number, object, string, union } from "valibot";
2
+ import { useScript, validateScriptInputSchema } from "#imports";
3
+ export const FacebookPixelOptions = object({
4
4
  id: union([string(), number()])
5
5
  });
6
6
  export function useScriptFacebookPixel(options, _scriptOptions) {
7
7
  const scriptOptions = _scriptOptions || {};
8
8
  scriptOptions.beforeInit = () => {
9
- if (import.meta.dev)
10
- parse(FacebookPixelOptions, options);
9
+ validateScriptInputSchema(FacebookPixelOptions, options);
11
10
  if (import.meta.client) {
12
11
  const fbq = window.fbq = function(...params) {
13
- fbq.callMethod ? fbq.callMethod.apply(fbq, params) : fbq.queue.push(params);
12
+ fbq.callMethod ? fbq.callMethod(...params) : fbq.queue.push(params);
14
13
  };
15
14
  if (!window._fbq)
16
15
  window._fbq = fbq;
@@ -27,9 +26,7 @@ export function useScriptFacebookPixel(options, _scriptOptions) {
27
26
  src: "https://connect.facebook.net/en_US/fbevents.js",
28
27
  defer: true
29
28
  }, {
30
- trigger: "onNuxtReady",
31
29
  ...scriptOptions,
32
- assetStrategy: "bundle",
33
30
  use() {
34
31
  return { fbq: window.fbq };
35
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
- import { boolean, literal, object, optional, parse, string, union } from "valibot";
2
- import { useScript } from "#imports";
3
- const FathomAnalyticsOptions = object({
1
+ import { boolean, literal, object, optional, string, union } from "valibot";
2
+ import { useScript, validateScriptInputSchema } from "#imports";
3
+ export const FathomAnalyticsOptions = object({
4
4
  "site": string(),
5
5
  // site is required
6
6
  "src": optional(string()),
@@ -13,7 +13,7 @@ export function useScriptFathomAnalytics(options, _scriptOptions) {
13
13
  const scriptOptions = _scriptOptions || {};
14
14
  if (import.meta.dev) {
15
15
  scriptOptions.beforeInit = () => {
16
- parse(FathomAnalyticsOptions, options);
16
+ validateScriptInputSchema(FathomAnalyticsOptions, options);
17
17
  };
18
18
  }
19
19
  return useScript({
@@ -22,7 +22,6 @@ export function useScriptFathomAnalytics(options, _scriptOptions) {
22
22
  ...options
23
23
  }, {
24
24
  ...scriptOptions,
25
- assetStrategy: "bundle",
26
25
  use: () => window.fathom
27
26
  });
28
27
  }
@@ -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,15 +1,13 @@
1
- import { number, object, optional, parse } from "valibot";
2
- import { useScript } from "#imports";
3
- const HotjarOptions = object({
1
+ import { number, object, optional } from "valibot";
2
+ import { useScript, validateScriptInputSchema } from "#imports";
3
+ export const HotjarOptions = object({
4
4
  id: number(),
5
5
  sv: optional(number())
6
6
  });
7
7
  export function useScriptHotjar(options, _scriptOptions) {
8
8
  const scriptOptions = _scriptOptions || {};
9
9
  scriptOptions.beforeInit = () => {
10
- if (import.meta.dev) {
11
- parse(HotjarOptions, options);
12
- }
10
+ validateScriptInputSchema(HotjarOptions, options);
13
11
  if (import.meta.client) {
14
12
  window._hjSettings = window._hjSettings || { hjid: options?.id, hjsv: options?.sv };
15
13
  window.hj = window.hj || function(...params) {
@@ -19,12 +17,11 @@ export function useScriptHotjar(options, _scriptOptions) {
19
17
  };
20
18
  return useScript({
21
19
  key: "hotjar",
20
+ // requires extra steps to bundle
22
21
  src: `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv}`,
23
22
  defer: true
24
23
  }, {
25
- trigger: "onNuxtReady",
26
24
  ...scriptOptions,
27
- assetStrategy: "bundle",
28
25
  use() {
29
26
  return { hj: window.hj };
30
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 {};