@nuxt/scripts 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -23
- package/dist/client/200.html +5 -5
- package/dist/client/404.html +5 -5
- package/dist/client/_nuxt/{DnntiO6I.js → BBafEUG8.js} +1 -1
- package/dist/client/_nuxt/{Bw1vr1xi.js → C6qP6ksw.js} +1 -1
- package/dist/client/_nuxt/{B7gLnlpM.js → D2oMNJSZ.js} +1 -1
- package/dist/client/_nuxt/{CXVVb7oJ.js → YkgnKQjM.js} +10 -10
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/72c1a85e-b70c-4e27-93ec-d6316f40b143.json +1 -0
- package/dist/client/index.html +5 -5
- package/dist/module.d.mts +43 -0
- package/dist/module.d.ts +43 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +107 -4
- package/dist/runtime/composables/useScript.d.ts +4 -2
- package/dist/runtime/composables/useScript.mjs +13 -1
- package/dist/runtime/composables/validateScriptInputSchema.d.ts +7 -0
- package/dist/runtime/composables/validateScriptInputSchema.mjs +12 -0
- package/dist/runtime/registry/cloudflare-turnstile.d.ts +1 -0
- package/dist/runtime/registry/cloudflare-turnstile.mjs +3 -0
- package/dist/runtime/registry/cloudflare-web-analytics.d.ts +33 -0
- package/dist/runtime/registry/cloudflare-web-analytics.mjs +37 -0
- package/dist/runtime/registry/confetti.d.ts +14 -0
- package/dist/runtime/registry/confetti.mjs +12 -0
- package/dist/runtime/registry/facebook-pixel.d.ts +42 -0
- package/dist/runtime/registry/facebook-pixel.mjs +36 -0
- package/dist/runtime/registry/fathom-analytics.d.ts +33 -0
- package/dist/runtime/registry/fathom-analytics.mjs +27 -0
- package/dist/runtime/registry/google-analytics.d.ts +1 -0
- package/dist/runtime/registry/google-analytics.mjs +3 -0
- package/dist/runtime/registry/google-tag-manager.d.ts +1 -0
- package/dist/runtime/registry/google-tag-manager.mjs +3 -0
- package/dist/runtime/registry/hotjar.d.ts +24 -0
- package/dist/runtime/registry/hotjar.mjs +30 -0
- package/dist/runtime/registry/intercom.d.ts +31 -0
- package/dist/runtime/registry/intercom.mjs +33 -0
- package/dist/runtime/registry/segment.d.ts +25 -0
- package/dist/runtime/registry/segment.mjs +43 -0
- package/dist/runtime/types.d.ts +17 -1
- package/package.json +15 -9
- package/dist/client/_nuxt/builds/meta/dfbad358-c258-488d-9323-84d07e1f8acf.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"72c1a85e-b70c-4e27-93ec-d6316f40b143","timestamp":1711777231401}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"72c1a85e-b70c-4e27-93ec-d6316f40b143","timestamp":1711777231401,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -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/
|
|
4
|
+
<link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/YkgnKQjM.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/
|
|
233
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/
|
|
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">
|
|
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/
|
|
236
|
-
<script type="module" src="/__nuxt-scripts/_nuxt/
|
|
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"}})();
|
|
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,4 +1,6 @@
|
|
|
1
1
|
import * as nuxt_schema from 'nuxt/schema';
|
|
2
|
+
import * as valibot from 'valibot';
|
|
3
|
+
import { Input } from 'valibot';
|
|
2
4
|
import { UseScriptOptions } from '@unhead/schema';
|
|
3
5
|
import { UseScriptInput } from '@unhead/vue';
|
|
4
6
|
|
|
@@ -16,10 +18,51 @@ type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
|
16
18
|
* improves privacy by not sharing the user's IP address with third-party servers.
|
|
17
19
|
*/
|
|
18
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;
|
|
19
25
|
};
|
|
20
26
|
type NuxtUseScriptInput = UseScriptInput;
|
|
21
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
|
+
}>;
|
|
58
|
+
|
|
22
59
|
interface ModuleOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Register scripts globally.
|
|
62
|
+
*/
|
|
63
|
+
register?: {
|
|
64
|
+
cloudflareWebAnalytics?: Input<typeof CloudflareWebAnalyticsOptions>;
|
|
65
|
+
};
|
|
23
66
|
/**
|
|
24
67
|
* Register scripts that should be loaded globally on all pages.
|
|
25
68
|
*/
|
package/dist/module.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as nuxt_schema from 'nuxt/schema';
|
|
2
|
+
import * as valibot from 'valibot';
|
|
3
|
+
import { Input } from 'valibot';
|
|
2
4
|
import { UseScriptOptions } from '@unhead/schema';
|
|
3
5
|
import { UseScriptInput } from '@unhead/vue';
|
|
4
6
|
|
|
@@ -16,10 +18,51 @@ type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
|
16
18
|
* improves privacy by not sharing the user's IP address with third-party servers.
|
|
17
19
|
*/
|
|
18
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;
|
|
19
25
|
};
|
|
20
26
|
type NuxtUseScriptInput = UseScriptInput;
|
|
21
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
|
+
}>;
|
|
58
|
+
|
|
22
59
|
interface ModuleOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Register scripts globally.
|
|
62
|
+
*/
|
|
63
|
+
register?: {
|
|
64
|
+
cloudflareWebAnalytics?: Input<typeof CloudflareWebAnalyticsOptions>;
|
|
65
|
+
};
|
|
23
66
|
/**
|
|
24
67
|
* Register scripts that should be loaded globally on all pages.
|
|
25
68
|
*/
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useNuxt, useLogger, addDevServerHandler,
|
|
1
|
+
import { useNuxt, useLogger, addDevServerHandler, createResolver, addTemplate, defineNuxtModule, addImportsDir, addImports, addPluginTemplate, 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: `module/${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",
|
|
@@ -245,14 +264,89 @@ const module = defineNuxtModule({
|
|
|
245
264
|
},
|
|
246
265
|
async setup(config, nuxt) {
|
|
247
266
|
const { resolve } = createResolver(import.meta.url);
|
|
248
|
-
const { version } = await readPackageJSON(resolve("../package.json"));
|
|
267
|
+
const { version, name } = await readPackageJSON(resolve("../package.json"));
|
|
249
268
|
if (!config.enabled) {
|
|
250
269
|
logger.debug("The module is disabled, skipping setup.");
|
|
251
270
|
return;
|
|
252
271
|
}
|
|
253
272
|
nuxt.options.alias["#nuxt-scripts"] = resolve("./runtime/types");
|
|
254
273
|
nuxt.options.runtimeConfig["nuxt-scripts"] = { version };
|
|
255
|
-
addImportsDir(
|
|
274
|
+
addImportsDir([
|
|
275
|
+
resolve("./runtime/composables")
|
|
276
|
+
]);
|
|
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");
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
256
350
|
if (config.globals?.length) {
|
|
257
351
|
const template = addTemplate({
|
|
258
352
|
filename: "modules/nuxt-scripts/plugin.client.mjs",
|
|
@@ -270,6 +364,15 @@ ${config.globals?.map((g) => !Array.isArray(g) ? ` useScript("${g.toString()}
|
|
|
270
364
|
mode: "client"
|
|
271
365
|
});
|
|
272
366
|
}
|
|
367
|
+
extendTypes(name, async () => {
|
|
368
|
+
return `
|
|
369
|
+
declare module '#app' {
|
|
370
|
+
interface NuxtApp {
|
|
371
|
+
${nuxt.options.dev ? `_scripts: (import('#nuxt-scripts').NuxtAppScript)[]` : ""}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
`;
|
|
375
|
+
});
|
|
273
376
|
const scriptMap = /* @__PURE__ */ new Map();
|
|
274
377
|
const { normalizeScriptData } = setupPublicAssetStrategy(config.assets);
|
|
275
378
|
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):
|
|
3
|
+
export declare function useScript<T>(input: UseScriptInput, options?: NuxtUseScriptOptions): T & {
|
|
4
|
+
$script: VueScriptInstance<T>;
|
|
5
|
+
};
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { useScript as _useScript, injectHead } from "@unhead/vue";
|
|
2
|
+
import { hashCode } from "@unhead/shared";
|
|
2
3
|
import { onNuxtReady, useNuxtApp } from "#imports";
|
|
3
4
|
export function useScript(input, options) {
|
|
4
5
|
input = typeof input === "string" ? { src: input } : input;
|
|
5
6
|
options = options || {};
|
|
6
7
|
if (options.trigger === "onNuxtReady")
|
|
7
|
-
options.trigger = onNuxtReady;
|
|
8
|
+
options.trigger = new Promise((resolve) => onNuxtReady(resolve));
|
|
8
9
|
const nuxtApp = useNuxtApp();
|
|
10
|
+
const id = input.key || input.src || hashCode(typeof input.innerHTML === "string" ? input.innerHTML : "");
|
|
11
|
+
if (!nuxtApp.scripts?.[id]) {
|
|
12
|
+
options.beforeInit?.();
|
|
13
|
+
if (import.meta.client) {
|
|
14
|
+
performance?.mark?.("mark_feature_usage", {
|
|
15
|
+
detail: {
|
|
16
|
+
feature: `nuxt-scripts:${id}`
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
9
21
|
const instance = _useScript(input, options);
|
|
10
22
|
if (import.meta.dev && import.meta.client) {
|
|
11
23
|
let syncScripts = function() {
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useScriptCloudflareTurnstile(): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Input } from 'valibot';
|
|
2
|
+
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
3
|
+
export interface CloudflareWebAnalyticsApi {
|
|
4
|
+
__cfBeacon: {
|
|
5
|
+
load: 'single';
|
|
6
|
+
spa: boolean;
|
|
7
|
+
token: string;
|
|
8
|
+
};
|
|
9
|
+
__cfRl?: unknown;
|
|
10
|
+
}
|
|
11
|
+
declare global {
|
|
12
|
+
interface Window extends CloudflareWebAnalyticsApi {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare const CloudflareWebAnalyticsOptions: import("valibot").ObjectSchema<{
|
|
16
|
+
/**
|
|
17
|
+
* The Cloudflare Web Analytics token.
|
|
18
|
+
*
|
|
19
|
+
* Required when used for the first time.
|
|
20
|
+
*/
|
|
21
|
+
token: import("valibot").StringSchema<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Cloudflare Web Analytics enables measuring SPAs automatically by overriding the History API’s pushState function
|
|
24
|
+
* and listening to the onpopstate. Hash-based router is not supported.
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
spa: import("valibot").OptionalSchema<import("valibot").BooleanSchema<boolean>, undefined, boolean | undefined>;
|
|
29
|
+
}, undefined, {
|
|
30
|
+
token: string;
|
|
31
|
+
spa?: boolean | undefined;
|
|
32
|
+
}>;
|
|
33
|
+
export declare function useScriptCloudflareWebAnalytics<T extends CloudflareWebAnalyticsApi>(options?: Input<typeof CloudflareWebAnalyticsOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { boolean, minLength, object, optional, string } from "valibot";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
4
|
+
export const CloudflareWebAnalyticsOptions = object({
|
|
5
|
+
/**
|
|
6
|
+
* The Cloudflare Web Analytics token.
|
|
7
|
+
*
|
|
8
|
+
* Required when used for the first time.
|
|
9
|
+
*/
|
|
10
|
+
token: string([minLength(33)]),
|
|
11
|
+
/**
|
|
12
|
+
* Cloudflare Web Analytics enables measuring SPAs automatically by overriding the History API’s pushState function
|
|
13
|
+
* and listening to the onpopstate. Hash-based router is not supported.
|
|
14
|
+
*
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
spa: optional(boolean())
|
|
18
|
+
});
|
|
19
|
+
export function useScriptCloudflareWebAnalytics(options, _scriptOptions) {
|
|
20
|
+
const scriptOptions = _scriptOptions || {};
|
|
21
|
+
if (import.meta.dev) {
|
|
22
|
+
scriptOptions.beforeInit = () => {
|
|
23
|
+
validateScriptInputSchema(CloudflareWebAnalyticsOptions, options);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return useScript({
|
|
27
|
+
"src": "https://static.cloudflareinsights.com/beacon.min.js",
|
|
28
|
+
"data-cf-beacon": JSON.stringify(defu(options, { spa: true }))
|
|
29
|
+
}, {
|
|
30
|
+
trigger: "onNuxtReady",
|
|
31
|
+
...scriptOptions,
|
|
32
|
+
assetStrategy: "bundle",
|
|
33
|
+
use() {
|
|
34
|
+
return { __cfBeacon: window.__cfBeacon, __cfRl: window.__cfRl };
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
2
|
+
export interface JSConfettiApi {
|
|
3
|
+
addConfetti: (options?: {
|
|
4
|
+
emojis: string[];
|
|
5
|
+
}) => void;
|
|
6
|
+
}
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
JSConfetti: {
|
|
10
|
+
new (): JSConfettiApi;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare function useScriptConfetti<T extends JSConfettiApi>(options?: NuxtUseScriptOptions<T>): any;
|
|
@@ -0,0 +1,12 @@
|
|
|
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"
|
|
5
|
+
}, {
|
|
6
|
+
...options,
|
|
7
|
+
assetStrategy: "bundle",
|
|
8
|
+
use() {
|
|
9
|
+
return new window.JSConfetti();
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Input } from 'valibot';
|
|
2
|
+
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
3
|
+
type StandardEvents = 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent';
|
|
4
|
+
interface EventObjectProperties {
|
|
5
|
+
content_category?: string;
|
|
6
|
+
content_ids?: string[];
|
|
7
|
+
content_name?: string;
|
|
8
|
+
content_type?: string;
|
|
9
|
+
contents: {
|
|
10
|
+
id: string;
|
|
11
|
+
quantity: number;
|
|
12
|
+
}[];
|
|
13
|
+
currency?: string;
|
|
14
|
+
delivery_category?: 'in_store' | 'curbside' | 'home_delivery';
|
|
15
|
+
num_items?: number;
|
|
16
|
+
predicted_ltv?: number;
|
|
17
|
+
search_string?: string;
|
|
18
|
+
status?: 'completed' | 'updated' | 'viewed' | 'added_to_cart' | 'removed_from_cart' | string;
|
|
19
|
+
value?: number;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}
|
|
22
|
+
type FbqFns = ((event: 'track', eventName: StandardEvents, data?: EventObjectProperties) => void) & ((event: 'trackCustom', eventName: string, data?: EventObjectProperties) => void) & ((event: 'init', id: number, data?: Record<string, any>) => void) & ((event: 'init', id: string) => void) & ((event: string, ...params: any[]) => void);
|
|
23
|
+
export interface FacebookPixelApi {
|
|
24
|
+
fbq: FbqFns & {
|
|
25
|
+
push: FbqFns;
|
|
26
|
+
loaded: boolean;
|
|
27
|
+
version: string;
|
|
28
|
+
queue: any[];
|
|
29
|
+
};
|
|
30
|
+
_fbq: FacebookPixelApi['fbq'];
|
|
31
|
+
}
|
|
32
|
+
declare global {
|
|
33
|
+
interface Window extends FacebookPixelApi {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
declare const FacebookPixelOptions: import("valibot").ObjectSchema<{
|
|
37
|
+
id: import("valibot").UnionSchema<(import("valibot").StringSchema<string> | import("valibot").NumberSchema<number>)[], string | number>;
|
|
38
|
+
}, undefined, {
|
|
39
|
+
id: string | number;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function useScriptFacebookPixel<T extends FacebookPixelApi>(options?: Input<typeof FacebookPixelOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { number, object, string, union } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
|
+
const FacebookPixelOptions = object({
|
|
4
|
+
id: union([string(), number()])
|
|
5
|
+
});
|
|
6
|
+
export function useScriptFacebookPixel(options, _scriptOptions) {
|
|
7
|
+
const scriptOptions = _scriptOptions || {};
|
|
8
|
+
scriptOptions.beforeInit = () => {
|
|
9
|
+
validateScriptInputSchema(FacebookPixelOptions, options);
|
|
10
|
+
if (import.meta.client) {
|
|
11
|
+
const fbq = window.fbq = function(...params) {
|
|
12
|
+
fbq.callMethod ? fbq.callMethod(...params) : fbq.queue.push(params);
|
|
13
|
+
};
|
|
14
|
+
if (!window._fbq)
|
|
15
|
+
window._fbq = fbq;
|
|
16
|
+
fbq.push = fbq;
|
|
17
|
+
fbq.loaded = true;
|
|
18
|
+
fbq.version = "2.0";
|
|
19
|
+
fbq.queue = [];
|
|
20
|
+
fbq("init", options?.id);
|
|
21
|
+
fbq("track", "PageView");
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return useScript({
|
|
25
|
+
key: "facebook-pixel",
|
|
26
|
+
src: "https://connect.facebook.net/en_US/fbevents.js",
|
|
27
|
+
defer: true
|
|
28
|
+
}, {
|
|
29
|
+
trigger: "onNuxtReady",
|
|
30
|
+
...scriptOptions,
|
|
31
|
+
assetStrategy: "bundle",
|
|
32
|
+
use() {
|
|
33
|
+
return { fbq: window.fbq };
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Input } from 'valibot';
|
|
2
|
+
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
3
|
+
declare const FathomAnalyticsOptions: import("valibot").ObjectSchema<{
|
|
4
|
+
site: import("valibot").StringSchema<string>;
|
|
5
|
+
src: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
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>;
|
|
7
|
+
'data-auto': import("valibot").OptionalSchema<import("valibot").BooleanSchema<boolean>, undefined, boolean | undefined>;
|
|
8
|
+
'data-canonical': import("valibot").OptionalSchema<import("valibot").BooleanSchema<boolean>, undefined, boolean | undefined>;
|
|
9
|
+
'data-honor-dnt': import("valibot").OptionalSchema<import("valibot").BooleanSchema<boolean>, undefined, boolean | undefined>;
|
|
10
|
+
}, undefined, {
|
|
11
|
+
site: string;
|
|
12
|
+
src?: string | undefined;
|
|
13
|
+
'data-spa'?: "auto" | "history" | "hash" | undefined;
|
|
14
|
+
'data-auto'?: boolean | undefined;
|
|
15
|
+
'data-canonical'?: boolean | undefined;
|
|
16
|
+
'data-honor-dnt'?: boolean | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
export interface FathomAnalyticsApi {
|
|
19
|
+
trackPageview: (ctx?: {
|
|
20
|
+
url: string;
|
|
21
|
+
referrer?: string;
|
|
22
|
+
}) => void;
|
|
23
|
+
trackEvent: (eventName: string, value: {
|
|
24
|
+
_value: number;
|
|
25
|
+
}) => void;
|
|
26
|
+
}
|
|
27
|
+
declare global {
|
|
28
|
+
interface Window {
|
|
29
|
+
fathom: FathomAnalyticsApi;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export declare function useScriptFathomAnalytics<T extends FathomAnalyticsApi>(options?: Input<typeof FathomAnalyticsOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { boolean, literal, object, optional, string, union } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
|
+
const FathomAnalyticsOptions = object({
|
|
4
|
+
"site": string(),
|
|
5
|
+
// site is required
|
|
6
|
+
"src": optional(string()),
|
|
7
|
+
"data-spa": optional(union([literal("auto"), literal("history"), literal("hash")])),
|
|
8
|
+
"data-auto": optional(boolean()),
|
|
9
|
+
"data-canonical": optional(boolean()),
|
|
10
|
+
"data-honor-dnt": optional(boolean())
|
|
11
|
+
});
|
|
12
|
+
export function useScriptFathomAnalytics(options, _scriptOptions) {
|
|
13
|
+
const scriptOptions = _scriptOptions || {};
|
|
14
|
+
if (import.meta.dev) {
|
|
15
|
+
scriptOptions.beforeInit = () => {
|
|
16
|
+
validateScriptInputSchema(FathomAnalyticsOptions, options);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return useScript({
|
|
20
|
+
src: "https://cdn.usefathom.com/script.js",
|
|
21
|
+
defer: true,
|
|
22
|
+
...options
|
|
23
|
+
}, {
|
|
24
|
+
...scriptOptions,
|
|
25
|
+
use: () => window.fathom
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useScriptGoogleAnalytics(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useScriptGoogleTagManager(): void;
|