@nuxt/scripts 0.1.4 → 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 +24 -22
- package/dist/client/200.html +5 -5
- package/dist/client/404.html +5 -5
- package/dist/client/_nuxt/{CO8u40Ut.js → BBafEUG8.js} +1 -1
- package/dist/client/_nuxt/{C2uur0MR.js → C6qP6ksw.js} +1 -1
- package/dist/client/_nuxt/{B3yRAOXz.js → D2oMNJSZ.js} +1 -1
- package/dist/client/_nuxt/{BqAhYH0E.js → YkgnKQjM.js} +4 -4
- 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 +39 -0
- package/dist/module.d.ts +39 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +105 -5
- package/dist/runtime/composables/useScript.d.ts +4 -2
- package/dist/runtime/composables/useScript.mjs +10 -2
- package/dist/runtime/composables/validateScriptInputSchema.d.ts +7 -0
- package/dist/runtime/composables/validateScriptInputSchema.mjs +12 -0
- package/dist/runtime/registry/cloudflare-web-analytics.d.ts +1 -2
- package/dist/runtime/registry/cloudflare-web-analytics.mjs +4 -4
- package/dist/runtime/registry/facebook-pixel.mjs +4 -5
- package/dist/runtime/registry/fathom-analytics.mjs +3 -4
- package/dist/runtime/registry/hotjar.mjs +3 -5
- package/dist/runtime/registry/intercom.mjs +3 -4
- package/dist/runtime/registry/segment.mjs +5 -6
- package/dist/runtime/types.d.ts +13 -1
- package/package.json +6 -2
- package/dist/client/_nuxt/builds/meta/4e9eefe2-f4a5-46ff-889b-aa701f38d2cd.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
|
|
|
@@ -23,7 +25,44 @@ type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
|
23
25
|
};
|
|
24
26
|
type NuxtUseScriptInput = UseScriptInput;
|
|
25
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
|
+
|
|
26
59
|
interface ModuleOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Register scripts globally.
|
|
62
|
+
*/
|
|
63
|
+
register?: {
|
|
64
|
+
cloudflareWebAnalytics?: Input<typeof CloudflareWebAnalyticsOptions>;
|
|
65
|
+
};
|
|
27
66
|
/**
|
|
28
67
|
* Register scripts that should be loaded globally on all pages.
|
|
29
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
|
|
|
@@ -23,7 +25,44 @@ type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
|
23
25
|
};
|
|
24
26
|
type NuxtUseScriptInput = UseScriptInput;
|
|
25
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
|
+
|
|
26
59
|
interface ModuleOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Register scripts globally.
|
|
62
|
+
*/
|
|
63
|
+
register?: {
|
|
64
|
+
cloudflareWebAnalytics?: Input<typeof CloudflareWebAnalyticsOptions>;
|
|
65
|
+
};
|
|
27
66
|
/**
|
|
28
67
|
* Register scripts that should be loaded globally on all pages.
|
|
29
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,7 +264,7 @@ 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;
|
|
@@ -253,9 +272,81 @@ const module = defineNuxtModule({
|
|
|
253
272
|
nuxt.options.alias["#nuxt-scripts"] = resolve("./runtime/types");
|
|
254
273
|
nuxt.options.runtimeConfig["nuxt-scripts"] = { version };
|
|
255
274
|
addImportsDir([
|
|
256
|
-
resolve("./runtime/composables")
|
|
257
|
-
resolve("./runtime/registry")
|
|
275
|
+
resolve("./runtime/composables")
|
|
258
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
|
+
}
|
|
259
350
|
if (config.globals?.length) {
|
|
260
351
|
const template = addTemplate({
|
|
261
352
|
filename: "modules/nuxt-scripts/plugin.client.mjs",
|
|
@@ -273,6 +364,15 @@ ${config.globals?.map((g) => !Array.isArray(g) ? ` useScript("${g.toString()}
|
|
|
273
364
|
mode: "client"
|
|
274
365
|
});
|
|
275
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
|
+
});
|
|
276
376
|
const scriptMap = /* @__PURE__ */ new Map();
|
|
277
377
|
const { normalizeScriptData } = setupPublicAssetStrategy(config.assets);
|
|
278
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
|
+
};
|
|
@@ -7,9 +7,17 @@ export function useScript(input, options) {
|
|
|
7
7
|
if (options.trigger === "onNuxtReady")
|
|
8
8
|
options.trigger = new Promise((resolve) => onNuxtReady(resolve));
|
|
9
9
|
const nuxtApp = useNuxtApp();
|
|
10
|
-
const id = input.key ||
|
|
11
|
-
if (
|
|
10
|
+
const id = input.key || input.src || hashCode(typeof input.innerHTML === "string" ? input.innerHTML : "");
|
|
11
|
+
if (!nuxtApp.scripts?.[id]) {
|
|
12
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
|
+
}
|
|
13
21
|
const instance = _useScript(input, options);
|
|
14
22
|
if (import.meta.dev && import.meta.client) {
|
|
15
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
|
+
}
|
|
@@ -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,
|
|
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,7 +20,7 @@ export function useScriptCloudflareWebAnalytics(options, _scriptOptions) {
|
|
|
20
20
|
const scriptOptions = _scriptOptions || {};
|
|
21
21
|
if (import.meta.dev) {
|
|
22
22
|
scriptOptions.beforeInit = () => {
|
|
23
|
-
|
|
23
|
+
validateScriptInputSchema(CloudflareWebAnalyticsOptions, options);
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
return useScript({
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { number, object,
|
|
2
|
-
import { useScript } from "#imports";
|
|
1
|
+
import { number, object, string, union } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
3
|
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
|
-
|
|
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
|
|
12
|
+
fbq.callMethod ? fbq.callMethod(...params) : fbq.queue.push(params);
|
|
14
13
|
};
|
|
15
14
|
if (!window._fbq)
|
|
16
15
|
window._fbq = fbq;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { boolean, literal, object, optional,
|
|
2
|
-
import { useScript } from "#imports";
|
|
1
|
+
import { boolean, literal, object, optional, string, union } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
3
|
const FathomAnalyticsOptions = object({
|
|
4
4
|
"site": string(),
|
|
5
5
|
// site is required
|
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { number, object, optional
|
|
2
|
-
import { useScript } from "#imports";
|
|
1
|
+
import { number, object, optional } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
3
|
const HotjarOptions = object({
|
|
4
4
|
id: number(),
|
|
5
5
|
sv: optional(number())
|
|
@@ -7,9 +7,7 @@ const HotjarOptions = object({
|
|
|
7
7
|
export function useScriptHotjar(options, _scriptOptions) {
|
|
8
8
|
const scriptOptions = _scriptOptions || {};
|
|
9
9
|
scriptOptions.beforeInit = () => {
|
|
10
|
-
|
|
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) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { literal, number, object, optional,
|
|
2
|
-
import { useScript } from "#imports";
|
|
1
|
+
import { literal, number, object, optional, string, union } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
3
|
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")])),
|
|
@@ -14,8 +14,7 @@ const IntercomOptions = object({
|
|
|
14
14
|
export function useScriptIntercom(options, _scriptOptions) {
|
|
15
15
|
const scriptOptions = _scriptOptions || {};
|
|
16
16
|
scriptOptions.beforeInit = () => {
|
|
17
|
-
|
|
18
|
-
parse(IntercomOptions, options);
|
|
17
|
+
validateScriptInputSchema(IntercomOptions, options);
|
|
19
18
|
if (import.meta.client)
|
|
20
19
|
window.intercomSettings = options;
|
|
21
20
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { object, optional,
|
|
2
|
-
import { useScript } from "#imports";
|
|
1
|
+
import { object, optional, string } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
3
|
const SegmentOptions = object({
|
|
4
4
|
writeKey: string(),
|
|
5
5
|
analyticsKey: optional(string())
|
|
@@ -7,14 +7,13 @@ const SegmentOptions = object({
|
|
|
7
7
|
export function useScriptSegment(options, _scriptOptions) {
|
|
8
8
|
const scriptOptions = _scriptOptions || {};
|
|
9
9
|
scriptOptions.beforeInit = () => {
|
|
10
|
-
|
|
11
|
-
parse(SegmentOptions, options);
|
|
10
|
+
validateScriptInputSchema(SegmentOptions, options);
|
|
12
11
|
if (import.meta.client) {
|
|
13
12
|
window.analytics = window.analytics || [];
|
|
14
13
|
window.analytics.methods = ["track", "page", "identify", "group", "alias", "reset"];
|
|
15
14
|
window.analytics.factory = function(method) {
|
|
16
|
-
return function() {
|
|
17
|
-
const args = Array.prototype.slice.call(
|
|
15
|
+
return function(...params) {
|
|
16
|
+
const args = Array.prototype.slice.call(params);
|
|
18
17
|
args.unshift(method);
|
|
19
18
|
window.analytics.push(args);
|
|
20
19
|
return window.analytics;
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UseScriptOptions } from '@unhead/schema';
|
|
2
|
-
import type { UseScriptInput } from '@unhead/vue';
|
|
2
|
+
import type { UseScriptInput, VueScriptInstance } from '@unhead/vue';
|
|
3
3
|
import type { ComputedRef, Ref } from 'vue';
|
|
4
4
|
export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
5
5
|
/**
|
|
@@ -37,3 +37,15 @@ export interface ConsentPromiseOptions {
|
|
|
37
37
|
*/
|
|
38
38
|
loadOnNuxtReady?: boolean;
|
|
39
39
|
}
|
|
40
|
+
export interface NuxtAppScript {
|
|
41
|
+
key: string;
|
|
42
|
+
src: string;
|
|
43
|
+
$script: VueScriptInstance<any>;
|
|
44
|
+
events: {
|
|
45
|
+
type: string;
|
|
46
|
+
fn?: string;
|
|
47
|
+
args?: any;
|
|
48
|
+
trigger?: string;
|
|
49
|
+
at: number;
|
|
50
|
+
}[];
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/scripts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"packageManager": "pnpm@8.15.5",
|
|
6
6
|
"description": "Next-gen Scripts for Nuxt",
|
|
7
7
|
"author": {
|
|
@@ -32,13 +32,16 @@
|
|
|
32
32
|
"build": {
|
|
33
33
|
"externals": [
|
|
34
34
|
"@unhead/vue",
|
|
35
|
-
"@unhead/schema"
|
|
35
|
+
"@unhead/schema",
|
|
36
|
+
"@unhead/vue",
|
|
37
|
+
"#nuxt-scripts"
|
|
36
38
|
]
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
41
|
"@nuxt/devtools-kit": "^1.1.5",
|
|
40
42
|
"@nuxt/devtools-ui-kit": "^1.1.5",
|
|
41
43
|
"@nuxt/kit": "^3.11.1",
|
|
44
|
+
"@unhead/vue": "^1.9.3",
|
|
42
45
|
"consola": "^3.2.3",
|
|
43
46
|
"defu": "^6.1.4",
|
|
44
47
|
"estree-walker": "^3.0.3",
|
|
@@ -68,6 +71,7 @@
|
|
|
68
71
|
"nuxt-scripts-devtools": "latest",
|
|
69
72
|
"playwright-core": "^1.42.1",
|
|
70
73
|
"typescript": "^5.4.3",
|
|
74
|
+
"unimport": "^3.7.1",
|
|
71
75
|
"vitest": "^1.4.0"
|
|
72
76
|
},
|
|
73
77
|
"resolutions": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"4e9eefe2-f4a5-46ff-889b-aa701f38d2cd","timestamp":1711697722263,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|