@nuxt/scripts 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/client/200.html +7 -6
  2. package/dist/client/404.html +7 -6
  3. package/dist/client/_nuxt/BG_OyJVq.js +1 -0
  4. package/dist/client/_nuxt/{YkgnKQjM.js → BVIyUFBp.js} +3 -3
  5. package/dist/client/_nuxt/{C6qP6ksw.js → CV_REd8b.js} +1 -1
  6. package/dist/client/_nuxt/{D2oMNJSZ.js → D1ek2jBE.js} +1 -1
  7. package/dist/client/_nuxt/DnLUQrgA.js +1 -0
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/b5db882d-dfbd-4edf-87b5-38d1f0a456e3.json +1 -0
  10. package/dist/client/_nuxt/{BBafEUG8.js → vqIOxd68.js} +1 -1
  11. package/dist/client/index.html +7 -6
  12. package/dist/module.d.mts +13 -67
  13. package/dist/module.d.ts +13 -67
  14. package/dist/module.json +1 -1
  15. package/dist/module.mjs +185 -120
  16. package/dist/runtime/composables/useScript.mjs +3 -2
  17. package/dist/runtime/composables/validateScriptInputSchema.d.ts +2 -7
  18. package/dist/runtime/composables/validateScriptInputSchema.mjs +9 -7
  19. package/dist/runtime/registry/cloudflare-web-analytics.mjs +3 -7
  20. package/dist/runtime/registry/confetti.d.ts +9 -1
  21. package/dist/runtime/registry/confetti.mjs +8 -5
  22. package/dist/runtime/registry/facebook-pixel.d.ts +1 -1
  23. package/dist/runtime/registry/facebook-pixel.mjs +4 -7
  24. package/dist/runtime/registry/fathom-analytics.d.ts +1 -2
  25. package/dist/runtime/registry/fathom-analytics.mjs +4 -7
  26. package/dist/runtime/registry/hotjar.d.ts +4 -5
  27. package/dist/runtime/registry/hotjar.mjs +4 -6
  28. package/dist/runtime/registry/intercom.d.ts +5 -5
  29. package/dist/runtime/registry/intercom.mjs +4 -6
  30. package/dist/runtime/registry/npm.d.ts +12 -0
  31. package/dist/runtime/registry/npm.mjs +18 -0
  32. package/dist/runtime/registry/segment.d.ts +4 -5
  33. package/dist/runtime/registry/segment.mjs +3 -6
  34. package/dist/runtime/types.d.ts +32 -3
  35. package/package.json +5 -5
  36. package/dist/client/_nuxt/CkMwVfOK.js +0 -1
  37. package/dist/client/_nuxt/builds/meta/72c1a85e-b70c-4e27-93ec-d6316f40b143.json +0 -1
package/dist/module.mjs CHANGED
@@ -1,9 +1,9 @@
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
+ import { parseURL, parseQuery, joinURL, hasProtocol, withQuery, withBase } from 'ufo';
3
4
  import { existsSync } from 'node:fs';
4
5
  import { pathToFileURL } from 'node:url';
5
6
  import { createUnplugin } from 'unplugin';
6
- import { parseURL, parseQuery, joinURL, hasProtocol } from 'ufo';
7
7
  import MagicString from 'magic-string';
8
8
  import { walk } from 'estree-walker';
9
9
  import fsp from 'node:fs/promises';
@@ -81,42 +81,80 @@ function NuxtScriptAssetBundlerTransformer(options) {
81
81
  const s = new MagicString(code);
82
82
  walk(ast, {
83
83
  enter(_node) {
84
- if (_node.type === "CallExpression" && _node.callee.type === "Identifier" && _node.callee?.name === "useScript") {
84
+ if (_node.type === "CallExpression" && _node.callee.type === "Identifier" && _node.callee?.name.startsWith("useScript")) {
85
+ const fnName = _node.callee?.name;
85
86
  const node = _node;
86
87
  let scriptKey;
87
- let scriptNode;
88
- if (node.arguments[0].type === "Literal") {
89
- scriptNode = node.arguments[0];
90
- scriptKey = scriptNode.value;
91
- } else if (node.arguments[0].type === "ObjectExpression") {
92
- const srcProperty = node.arguments[0].properties.find(
93
- (p) => p.key?.name === "src" || p.key?.value === "src"
94
- );
95
- const keyProperty = node.arguments[0].properties.find(
96
- (p) => p.key?.name === "key" || p.key?.value === "key"
97
- );
98
- scriptKey = keyProperty?.value?.value || srcProperty?.value;
99
- scriptNode = srcProperty?.value;
88
+ let scriptSrcNode;
89
+ let src;
90
+ if (fnName === "useScript") {
91
+ if (node.arguments[0].type === "Literal") {
92
+ scriptSrcNode = node.arguments[0];
93
+ scriptKey = scriptSrcNode.value;
94
+ } else if (node.arguments[0].type === "ObjectExpression") {
95
+ const srcProperty = node.arguments[0].properties.find(
96
+ (p) => p.key?.name === "src" || p.key?.value === "src"
97
+ );
98
+ const keyProperty = node.arguments[0].properties.find(
99
+ (p) => p.key?.name === "key" || p.key?.value === "key"
100
+ );
101
+ scriptKey = keyProperty?.value?.value || srcProperty?.value;
102
+ scriptSrcNode = srcProperty?.value;
103
+ }
104
+ } else {
105
+ const registryNode = options.registry?.find((i) => i.name === fnName);
106
+ if (!registryNode) {
107
+ console.error(`[Nuxt Scripts] Integration ${fnName} not found in registry`);
108
+ return;
109
+ }
110
+ if (!registryNode.transform && !registryNode.src)
111
+ return;
112
+ const optionsNode = node.arguments[0];
113
+ if (optionsNode?.type === "ObjectExpression") {
114
+ const fnArg0 = {};
115
+ for (const prop of optionsNode.properties) {
116
+ if (prop.value.type === "Literal")
117
+ fnArg0[prop.key.name] = prop.value.value;
118
+ }
119
+ const srcProperty = node.arguments[0].properties.find(
120
+ (p) => p.key?.name === "src" || p.key?.value === "src"
121
+ );
122
+ if (srcProperty?.value?.value)
123
+ scriptSrcNode = srcProperty.value;
124
+ else
125
+ src = registryNode.src || registryNode.transform?.(fnArg0);
126
+ scriptKey = registryNode.key;
127
+ }
100
128
  }
101
- if (scriptNode) {
102
- const src = scriptNode.value;
129
+ if (scriptSrcNode || src) {
130
+ src = src || scriptSrcNode.value;
103
131
  if (src) {
104
- let hasAssetStrategy = false;
132
+ let canBundle = options.defaultBundle;
105
133
  if (node.arguments[1]?.type === "ObjectExpression") {
106
134
  const assetStrategyProperty = node.arguments[1]?.properties.find(
107
135
  (p) => p.key?.name === "assetStrategy" || p.key?.value === "assetStrategy"
108
136
  );
109
137
  if (assetStrategyProperty) {
110
- if (assetStrategyProperty?.value?.value !== "bundle")
138
+ if (assetStrategyProperty?.value?.value !== "bundle") {
139
+ canBundle = false;
111
140
  return;
112
- s.remove(assetStrategyProperty.start, assetStrategyProperty.end + 1);
113
- hasAssetStrategy = true;
141
+ }
142
+ if (node.arguments[1]?.properties.length === 1)
143
+ s.remove(node.arguments[1].start, node.arguments[1].end);
144
+ else
145
+ s.remove(assetStrategyProperty.start, assetStrategyProperty.end);
146
+ canBundle = true;
114
147
  }
115
148
  }
116
- hasAssetStrategy = hasAssetStrategy || options.overrides?.[scriptKey]?.assetStrategy === "bundle";
117
- if (hasAssetStrategy) {
149
+ canBundle = canBundle || options.overrides?.[scriptKey]?.assetStrategy === "bundle";
150
+ if (canBundle) {
118
151
  const newSrc = options.resolveScript(src);
119
- s.overwrite(scriptNode.start, scriptNode.end, `'${newSrc}'`);
152
+ if (scriptSrcNode) {
153
+ s.overwrite(scriptSrcNode.start, scriptSrcNode.end, `'${newSrc}'`);
154
+ } else {
155
+ const lastProperty = node.arguments[0].properties[node.arguments[0].properties.length - 1];
156
+ s.appendRight(lastProperty.end, `, src: '${newSrc}'`);
157
+ }
120
158
  }
121
159
  }
122
160
  }
@@ -234,7 +272,7 @@ function extendTypes(module, template) {
234
272
  const nuxt = useNuxt();
235
273
  const { resolve } = createResolver(import.meta.url);
236
274
  addTemplate({
237
- filename: `module/${module}.d.ts`,
275
+ filename: `modules/${module}.d.ts`,
238
276
  getContents: async () => {
239
277
  const typesPath = relative(resolve(nuxt.options.rootDir, nuxt.options.buildDir, "module"), resolve("runtime/types"));
240
278
  const s = await template({ typesPath });
@@ -259,6 +297,11 @@ const module = defineNuxtModule({
259
297
  }
260
298
  },
261
299
  defaults: {
300
+ defaultScriptOptions: {
301
+ assetStrategy: "bundle",
302
+ // Not supported on all scripts, only if the src is static, runtime fallback?
303
+ trigger: "onNuxtReady"
304
+ },
262
305
  enabled: true,
263
306
  debug: false
264
307
  },
@@ -271,99 +314,133 @@ const module = defineNuxtModule({
271
314
  }
272
315
  nuxt.options.alias["#nuxt-scripts"] = resolve("./runtime/types");
273
316
  nuxt.options.runtimeConfig["nuxt-scripts"] = { version };
317
+ nuxt.options.runtimeConfig.public["nuxt-scripts"] = { defaultScriptOptions: config.defaultScriptOptions };
274
318
  addImportsDir([
275
319
  resolve("./runtime/composables")
276
320
  ]);
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)});`);
321
+ nuxt.hooks.hook("modules:done", async () => {
322
+ const registry = [
323
+ {
324
+ name: "useScriptCloudflareTurnstile",
325
+ key: "cloudflareTurnstile",
326
+ from: resolve("./runtime/registry/cloudflare-turnstile")
327
+ },
328
+ {
329
+ name: "useScriptCloudflareWebAnalytics",
330
+ key: "cloudflareWebAnalytics",
331
+ from: resolve("./runtime/registry/cloudflare-web-analytics"),
332
+ src: "https://static.cloudflareinsights.com/beacon.min.js"
333
+ },
334
+ {
335
+ name: "useScriptConfetti",
336
+ key: "confetti",
337
+ from: resolve("./runtime/registry/confetti"),
338
+ src: "https://unpkg.com/js-confetti@latest/dist/js-confetti.browser.js"
339
+ },
340
+ {
341
+ name: "useScriptFacebookPixel",
342
+ key: "facebookPixel",
343
+ from: resolve("./runtime/registry/facebook-pixel"),
344
+ src: "https://connect.facebook.net/en_US/fbevents.js"
345
+ },
346
+ {
347
+ name: "useScriptFathomAnalytics",
348
+ key: "fathomAnalytics",
349
+ from: resolve("./runtime/registry/fathom-analytics"),
350
+ src: "https://cdn.usefathom.com/script.js"
351
+ },
352
+ {
353
+ name: "useScriptGoogleAnalytics",
354
+ key: "googleAnalytics",
355
+ from: resolve("./runtime/registry/google-analytics")
356
+ },
357
+ {
358
+ name: "useScriptGoogleTagManager",
359
+ key: "googleTagmanager",
360
+ from: resolve("./runtime/registry/google-tag-manager")
361
+ },
362
+ {
363
+ name: "useScriptHotjar",
364
+ from: resolve("./runtime/registry/hotjar"),
365
+ key: "hotjar",
366
+ transform(options) {
367
+ return withQuery(`https://static.hotjar.com/c/hotjar-${options?.id || ""}.js`, {
368
+ sv: options?.sv || "6"
369
+ });
370
+ }
371
+ },
372
+ {
373
+ name: "useScriptIntercom",
374
+ from: resolve("./runtime/registry/intercom"),
375
+ key: "intercom",
376
+ transform(options) {
377
+ return joinURL(`https://widget.intercom.io/widget`, options?.app_id || "");
378
+ }
379
+ },
380
+ {
381
+ name: "useScriptSegment",
382
+ from: resolve("./runtime/registry/segment"),
383
+ key: "segment",
384
+ transform(options) {
385
+ return joinURL("https://cdn.segment.com/analytics.js/v1", options?.writeKey || "", "analytics.min.js");
386
+ }
387
+ },
388
+ {
389
+ name: "useScriptNpm",
390
+ // key is based on package name
391
+ from: resolve("./runtime/registry/npm"),
392
+ transform(options) {
393
+ return withBase(options?.file || "", `https://unpkg.com/${options?.packageName || ""}@${options?.version || "latest"}`);
336
394
  }
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");
347
395
  }
396
+ ].map((i) => {
397
+ i.priority = -1;
398
+ return i;
348
399
  });
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'
400
+ addImports(registry);
401
+ await nuxt.hooks.callHook("scripts:registry", registry);
402
+ if (config.globals?.length || Object.keys(config.register || {}).length) {
403
+ const template = addTemplate({
404
+ filename: `modules/${name}.mjs`,
405
+ write: true,
406
+ getContents() {
407
+ const imports = ["useScript", "defineNuxtPlugin"];
408
+ const inits = [];
409
+ for (const [k, c] of Object.entries(config.register || {})) {
410
+ const importDefinition = registry.find((i) => i.name === `useScript${k.substring(0, 1).toUpperCase() + k.substring(1)}`);
411
+ if (importDefinition) {
412
+ imports.unshift(importDefinition.name);
413
+ inits.push(`${importDefinition.name}(${JSON.stringify(c)});`);
414
+ }
415
+ }
416
+ return `import { ${imports.join(", ")} } from '#imports'
355
417
  export default defineNuxtPlugin({
418
+ name: "${name}:init",
356
419
  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")}
420
+ ${(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")}
421
+ ${inits.join("\n ")}
358
422
  }
359
423
  })`;
424
+ }
425
+ });
426
+ addPlugin({
427
+ src: template.dst
428
+ });
429
+ }
430
+ const scriptMap = /* @__PURE__ */ new Map();
431
+ const { normalizeScriptData } = setupPublicAssetStrategy(config.assets);
432
+ addBuildPlugin(NuxtScriptAssetBundlerTransformer({
433
+ registry,
434
+ defaultBundle: config.defaultScriptOptions?.assetStrategy === "bundle",
435
+ resolveScript(src) {
436
+ if (scriptMap.has(src))
437
+ return scriptMap.get(src);
438
+ const url = normalizeScriptData(src);
439
+ scriptMap.set(src, url);
440
+ return url;
360
441
  }
361
- });
362
- addPlugin({
363
- src: template.dst,
364
- mode: "client"
365
- });
366
- }
442
+ }));
443
+ });
367
444
  extendTypes(name, async () => {
368
445
  return `
369
446
  declare module '#app' {
@@ -373,18 +450,6 @@ declare module '#app' {
373
450
  }
374
451
  `;
375
452
  });
376
- const scriptMap = /* @__PURE__ */ new Map();
377
- const { normalizeScriptData } = setupPublicAssetStrategy(config.assets);
378
- addBuildPlugin(NuxtScriptAssetBundlerTransformer({
379
- overrides: config.overrides,
380
- resolveScript(src) {
381
- if (scriptMap.has(src))
382
- return scriptMap.get(src);
383
- const url = normalizeScriptData(src);
384
- scriptMap.set(src, url);
385
- return url;
386
- }
387
- }));
388
453
  if (nuxt.options.dev)
389
454
  setupDevToolsUI(config, resolve);
390
455
  }
@@ -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,2 @@
1
- import { type Input, type ObjectSchema } 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 ObjectSchema<any>>(schema: T, options?: Input<T>): void;
1
+ import { type BaseSchema, type Input } from 'valibot';
2
+ export declare function validateScriptInputSchema<T extends BaseSchema<any>>(schema: T, options?: Input<T>): void;
@@ -1,12 +1,14 @@
1
1
  import { parse } from "valibot";
2
2
  import { createError } from "#imports";
3
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
- });
4
+ if (import.meta.dev) {
5
+ try {
6
+ parse(schema, options);
7
+ } catch (e) {
8
+ createError({
9
+ cause: e,
10
+ message: "Invalid script options"
11
+ });
12
+ }
11
13
  }
12
14
  }
@@ -18,18 +18,14 @@ export const CloudflareWebAnalyticsOptions = object({
18
18
  });
19
19
  export function useScriptCloudflareWebAnalytics(options, _scriptOptions) {
20
20
  const scriptOptions = _scriptOptions || {};
21
- if (import.meta.dev) {
22
- scriptOptions.beforeInit = () => {
23
- validateScriptInputSchema(CloudflareWebAnalyticsOptions, options);
24
- };
25
- }
21
+ scriptOptions.beforeInit = () => {
22
+ import.meta.dev && validateScriptInputSchema(CloudflareWebAnalyticsOptions, options);
23
+ };
26
24
  return useScript({
27
25
  "src": "https://static.cloudflareinsights.com/beacon.min.js",
28
26
  "data-cf-beacon": JSON.stringify(defu(options, { spa: true }))
29
27
  }, {
30
- trigger: "onNuxtReady",
31
28
  ...scriptOptions,
32
- assetStrategy: "bundle",
33
29
  use() {
34
30
  return { __cfBeacon: window.__cfBeacon, __cfRl: window.__cfRl };
35
31
  }
@@ -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,12 +1,12 @@
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) {
7
7
  const scriptOptions = _scriptOptions || {};
8
8
  scriptOptions.beforeInit = () => {
9
- validateScriptInputSchema(FacebookPixelOptions, options);
9
+ import.meta.dev && validateScriptInputSchema(FacebookPixelOptions, options);
10
10
  if (import.meta.client) {
11
11
  const fbq = window.fbq = function(...params) {
12
12
  fbq.callMethod ? fbq.callMethod(...params) : fbq.queue.push(params);
@@ -22,13 +22,10 @@ export function useScriptFacebookPixel(options, _scriptOptions) {
22
22
  }
23
23
  };
24
24
  return useScript({
25
- key: "facebook-pixel",
26
- src: "https://connect.facebook.net/en_US/fbevents.js",
27
- defer: true
25
+ key: "facebookPixel",
26
+ src: "https://connect.facebook.net/en_US/fbevents.js"
28
27
  }, {
29
- trigger: "onNuxtReady",
30
28
  ...scriptOptions,
31
- assetStrategy: "bundle",
32
29
  use() {
33
30
  return { fbq: window.fbq };
34
31
  }
@@ -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()),
@@ -11,14 +11,11 @@ const FathomAnalyticsOptions = object({
11
11
  });
12
12
  export function useScriptFathomAnalytics(options, _scriptOptions) {
13
13
  const scriptOptions = _scriptOptions || {};
14
- if (import.meta.dev) {
15
- scriptOptions.beforeInit = () => {
16
- validateScriptInputSchema(FathomAnalyticsOptions, options);
17
- };
18
- }
14
+ scriptOptions.beforeInit = () => {
15
+ import.meta.dev && validateScriptInputSchema(FathomAnalyticsOptions, options);
16
+ };
19
17
  return useScript({
20
18
  src: "https://cdn.usefathom.com/script.js",
21
- defer: true,
22
19
  ...options
23
20
  }, {
24
21
  ...scriptOptions,
@@ -1,5 +1,4 @@
1
- import { type Input } from 'valibot';
2
- import type { NuxtUseScriptOptions } from '#nuxt-scripts';
1
+ import type { NuxtUseScriptOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
3
2
  export interface HotjarApi {
4
3
  hj: ((event: 'identify', userId: string, attributes?: Record<string, any>) => void) & ((event: 'stateChange', path: string) => void) & ((event: 'event', eventName: string) => void) & ((event: string, arg?: string) => void) & ((...params: any[]) => void) & {
5
4
  q: any[];
@@ -13,12 +12,12 @@ declare global {
13
12
  };
14
13
  }
15
14
  }
16
- declare const HotjarOptions: import("valibot").ObjectSchema<{
15
+ export declare const HotjarOptions: import("valibot").ObjectSchema<{
17
16
  id: import("valibot").NumberSchema<number>;
18
17
  sv: import("valibot").OptionalSchema<import("valibot").NumberSchema<number>, undefined, number | undefined>;
19
18
  }, undefined, {
20
19
  id: number;
21
20
  sv?: number | undefined;
22
21
  }>;
23
- export declare function useScriptHotjar<T extends HotjarApi>(options?: Input<typeof HotjarOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
24
- export {};
22
+ export type HotjarInput = ScriptDynamicSrcInput<typeof HotjarOptions>;
23
+ export declare function useScriptHotjar<T extends HotjarApi>(options?: HotjarInput, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'assetStrategy' | 'beforeInit' | 'use'>): any;
@@ -1,13 +1,13 @@
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
  });
7
7
  export function useScriptHotjar(options, _scriptOptions) {
8
8
  const scriptOptions = _scriptOptions || {};
9
9
  scriptOptions.beforeInit = () => {
10
- validateScriptInputSchema(HotjarOptions, options);
10
+ import.meta.dev && validateScriptInputSchema(HotjarOptions, options);
11
11
  if (import.meta.client) {
12
12
  window._hjSettings = window._hjSettings || { hjid: options?.id, hjsv: options?.sv };
13
13
  window.hj = window.hj || function(...params) {
@@ -17,12 +17,10 @@ export function useScriptHotjar(options, _scriptOptions) {
17
17
  };
18
18
  return useScript({
19
19
  key: "hotjar",
20
- src: `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv}`,
21
- defer: true
20
+ // requires extra steps to bundle
21
+ src: options?.src || `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv}`
22
22
  }, {
23
- trigger: "onNuxtReady",
24
23
  ...scriptOptions,
25
- assetStrategy: "bundle",
26
24
  use() {
27
25
  return { hj: window.hj };
28
26
  }