@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.
- package/README.md +24 -22
- package/dist/client/200.html +5 -5
- package/dist/client/404.html +5 -5
- package/dist/client/_nuxt/{C2uur0MR.js → 7b-muJBz.js} +1 -1
- package/dist/client/_nuxt/{B3yRAOXz.js → CFDTW01f.js} +1 -1
- package/dist/client/_nuxt/{CO8u40Ut.js → LZrVsJnT.js} +1 -1
- package/dist/client/_nuxt/{BqAhYH0E.js → ZXwHJetA.js} +4 -4
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/f0a0fb88-29eb-404a-b0c9-7ad64c942608.json +1 -0
- package/dist/client/index.html +5 -5
- package/dist/module.d.mts +13 -25
- package/dist/module.d.ts +13 -25
- package/dist/module.json +1 -1
- package/dist/module.mjs +114 -17
- package/dist/runtime/composables/useScript.d.ts +4 -2
- package/dist/runtime/composables/useScript.mjs +13 -4
- 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 -6
- package/dist/runtime/registry/confetti.d.ts +9 -1
- package/dist/runtime/registry/confetti.mjs +8 -5
- package/dist/runtime/registry/facebook-pixel.d.ts +1 -1
- package/dist/runtime/registry/facebook-pixel.mjs +5 -8
- package/dist/runtime/registry/fathom-analytics.d.ts +1 -2
- package/dist/runtime/registry/fathom-analytics.mjs +4 -5
- package/dist/runtime/registry/hotjar.d.ts +2 -3
- package/dist/runtime/registry/hotjar.mjs +5 -8
- package/dist/runtime/registry/intercom.d.ts +1 -2
- package/dist/runtime/registry/intercom.mjs +4 -7
- package/dist/runtime/registry/npm.d.ts +12 -0
- package/dist/runtime/registry/npm.mjs +22 -0
- package/dist/runtime/registry/segment.d.ts +1 -2
- package/dist/runtime/registry/segment.mjs +6 -9
- package/dist/runtime/types.d.ts +31 -1
- package/package.json +7 -3
- package/dist/client/_nuxt/builds/meta/4e9eefe2-f4a5-46ff-889b-aa701f38d2cd.json +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { literal, number, object, optional,
|
|
2
|
-
import { useScript } from "#imports";
|
|
3
|
-
const IntercomOptions = object({
|
|
1
|
+
import { literal, number, object, optional, string, union } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
|
+
export const IntercomOptions = object({
|
|
4
4
|
app_id: string(),
|
|
5
5
|
api_base: optional(union([literal("https://api-iam.intercom.io"), literal("https://api-iam.eu.intercom.io"), literal("https://api-iam.au.intercom.io")])),
|
|
6
6
|
name: optional(string()),
|
|
@@ -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
|
};
|
|
@@ -24,9 +23,7 @@ export function useScriptIntercom(options, _scriptOptions) {
|
|
|
24
23
|
src: `https://widget.intercom.io/widget/${options?.app_id}`,
|
|
25
24
|
defer: true
|
|
26
25
|
}, {
|
|
27
|
-
trigger: "onNuxtReady",
|
|
28
26
|
...scriptOptions,
|
|
29
|
-
assetStrategy: "bundle",
|
|
30
27
|
use() {
|
|
31
28
|
return { Intercom: window.Intercom };
|
|
32
29
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Input } from 'valibot';
|
|
2
|
+
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
3
|
+
export declare const NpmOptions: import("valibot").ObjectSchema<{
|
|
4
|
+
packageName: import("valibot").StringSchema<string>;
|
|
5
|
+
file: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
6
|
+
version: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
7
|
+
}, undefined, {
|
|
8
|
+
packageName: string;
|
|
9
|
+
file?: string | undefined;
|
|
10
|
+
version?: string | undefined;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function useScriptNpm<T>(options: Input<typeof NpmOptions>, _scriptOptions?: NuxtUseScriptOptions<T>): any;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { object, optional, string } from "valibot";
|
|
2
|
+
import { withBase } from "ufo";
|
|
3
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
4
|
+
export const NpmOptions = object({
|
|
5
|
+
packageName: string(),
|
|
6
|
+
file: optional(string()),
|
|
7
|
+
version: optional(string())
|
|
8
|
+
});
|
|
9
|
+
export function useScriptNpm(options, _scriptOptions) {
|
|
10
|
+
const scriptOptions = _scriptOptions || {};
|
|
11
|
+
scriptOptions.beforeInit = () => {
|
|
12
|
+
validateScriptInputSchema(NpmOptions, options);
|
|
13
|
+
};
|
|
14
|
+
return useScript({
|
|
15
|
+
src: typeof options === "string" ? options : withBase(options.file || "", `https://unpkg.com/${options?.packageName}@${options.version}`)
|
|
16
|
+
}, {
|
|
17
|
+
...scriptOptions,
|
|
18
|
+
use() {
|
|
19
|
+
return new window.JSConfetti();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Input } from 'valibot';
|
|
2
2
|
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
3
|
-
declare const SegmentOptions: import("valibot").ObjectSchema<{
|
|
3
|
+
export declare const SegmentOptions: import("valibot").ObjectSchema<{
|
|
4
4
|
writeKey: import("valibot").StringSchema<string>;
|
|
5
5
|
analyticsKey: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
6
6
|
}, undefined, {
|
|
@@ -22,4 +22,3 @@ declare global {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
export declare function useScriptSegment<T extends SegmentApi>(options?: Input<typeof SegmentOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
|
|
25
|
-
export {};
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { object, optional,
|
|
2
|
-
import { useScript } from "#imports";
|
|
3
|
-
const SegmentOptions = object({
|
|
1
|
+
import { object, optional, string } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
|
+
export const SegmentOptions = object({
|
|
4
4
|
writeKey: string(),
|
|
5
5
|
analyticsKey: optional(string())
|
|
6
6
|
});
|
|
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;
|
|
@@ -34,9 +33,7 @@ export function useScriptSegment(options, _scriptOptions) {
|
|
|
34
33
|
"src": `https://cdn.segment.com/analytics.js/v1/${options?.writeKey}/analytics.min.js`,
|
|
35
34
|
"defer": true
|
|
36
35
|
}, {
|
|
37
|
-
trigger: "onNuxtReady",
|
|
38
36
|
...scriptOptions,
|
|
39
|
-
assetStrategy: "bundle",
|
|
40
37
|
use() {
|
|
41
38
|
return { analytics: window[analyticsKey] };
|
|
42
39
|
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
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
|
+
import type { Input, ObjectSchema } from 'valibot';
|
|
5
|
+
import type { CloudflareWebAnalyticsOptions } from '~/src/runtime/registry/cloudflare-web-analytics';
|
|
6
|
+
import type { FacebookPixelOptions } from '~/src/runtime/registry/facebook-pixel';
|
|
7
|
+
import type { FathomAnalyticsOptions } from '~/src/runtime/registry/fathom-analytics';
|
|
8
|
+
import type { HotjarOptions } from '~/src/runtime/registry/hotjar';
|
|
9
|
+
import type { SegmentOptions } from '~/src/runtime/registry/segment';
|
|
10
|
+
import type { IntercomOptions } from '~/src/runtime/registry/intercom';
|
|
4
11
|
export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
5
12
|
/**
|
|
6
13
|
* The trigger to load the script:
|
|
@@ -37,3 +44,26 @@ export interface ConsentPromiseOptions {
|
|
|
37
44
|
*/
|
|
38
45
|
loadOnNuxtReady?: boolean;
|
|
39
46
|
}
|
|
47
|
+
export interface NuxtAppScript {
|
|
48
|
+
key: string;
|
|
49
|
+
src: string;
|
|
50
|
+
$script: VueScriptInstance<any>;
|
|
51
|
+
events: {
|
|
52
|
+
type: string;
|
|
53
|
+
fn?: string | symbol;
|
|
54
|
+
args?: any;
|
|
55
|
+
status?: string;
|
|
56
|
+
trigger?: NuxtUseScriptOptions['trigger'];
|
|
57
|
+
at: number;
|
|
58
|
+
}[];
|
|
59
|
+
}
|
|
60
|
+
export type ScriptRegistryEntry<T extends ObjectSchema<any>> = Input<T> | [Input<T>, NuxtUseScriptOptions<T>];
|
|
61
|
+
export interface ScriptRegistry {
|
|
62
|
+
cloudflareWebAnalytics?: ScriptRegistryEntry<typeof CloudflareWebAnalyticsOptions>;
|
|
63
|
+
confetti?: ScriptRegistryEntry<typeof CloudflareWebAnalyticsOptions>;
|
|
64
|
+
facebookPixel?: ScriptRegistryEntry<typeof FacebookPixelOptions>;
|
|
65
|
+
fathomAnalytics?: ScriptRegistryEntry<typeof FathomAnalyticsOptions>;
|
|
66
|
+
hotjar?: ScriptRegistryEntry<typeof HotjarOptions>;
|
|
67
|
+
segment?: ScriptRegistryEntry<typeof SegmentOptions>;
|
|
68
|
+
intercom?: ScriptRegistryEntry<typeof IntercomOptions>;
|
|
69
|
+
}
|
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.6",
|
|
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",
|
|
@@ -53,7 +56,8 @@
|
|
|
53
56
|
"ufo": "^1.5.3",
|
|
54
57
|
"unplugin": "^1.10.0",
|
|
55
58
|
"unstorage": "^1.10.2",
|
|
56
|
-
"valibot": "^0.30.0"
|
|
59
|
+
"valibot": "^0.30.0",
|
|
60
|
+
"unimport": "^3.7.1"
|
|
57
61
|
},
|
|
58
62
|
"devDependencies": {
|
|
59
63
|
"@antfu/eslint-config": "2.8.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"4e9eefe2-f4a5-46ff-889b-aa701f38d2cd","timestamp":1711697722263,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|