@nuxt/scripts 0.3.3 → 0.3.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/dist/client/200.html +5 -5
- package/dist/client/404.html +5 -5
- package/dist/client/_nuxt/{B-3dzucQ.js → B-VcbH-p.js} +1 -1
- package/dist/client/_nuxt/{CmaBlQfy.js → Da7ySKCR.js} +1 -1
- package/dist/client/_nuxt/Duz6zLk8.js +31 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/ce1e7798-e27a-4397-9734-cd67ecbfb4ca.json +1 -0
- package/dist/client/_nuxt/{D-T6Aidr.js → enpXmyCL.js} +1 -1
- package/dist/client/index.html +5 -5
- package/dist/module.d.mts +2 -2
- package/dist/module.d.ts +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +67 -36
- package/dist/registry.d.mts +2 -2
- package/dist/registry.d.ts +2 -2
- package/dist/registry.mjs +16 -16
- package/dist/runtime/components/ScriptGoogleMaps.vue +264 -0
- package/dist/runtime/components/ScriptLemonSqueezyButton.vue +42 -0
- package/dist/runtime/components/ScriptLoadingIndicator.vue +15 -0
- package/dist/runtime/components/ScriptStripePricingTable.vue +47 -0
- package/dist/runtime/components/ScriptVimeoPlayer.vue +243 -0
- package/dist/runtime/components/ScriptYouTubePlayer.vue +160 -0
- package/dist/runtime/composables/useElementScriptTrigger.d.ts +3 -3
- package/dist/runtime/composables/useElementScriptTrigger.mjs +41 -5
- package/dist/runtime/composables/useScript.d.ts +1 -1
- package/dist/runtime/composables/useScript.mjs +7 -6
- package/dist/runtime/registry/cloudflare-web-analytics.mjs +2 -2
- package/dist/runtime/registry/fathom-analytics.d.ts +2 -2
- package/dist/runtime/registry/fathom-analytics.mjs +2 -2
- package/dist/runtime/registry/google-analytics.d.ts +4 -2
- package/dist/runtime/registry/google-analytics.mjs +13 -8
- package/dist/runtime/registry/google-maps.mjs +2 -2
- package/dist/runtime/registry/google-tag-manager.mjs +2 -2
- package/dist/runtime/registry/hotjar.mjs +4 -4
- package/dist/runtime/registry/intercom.mjs +3 -8
- package/dist/runtime/registry/lemon-squeezy.d.ts +1 -2
- package/dist/runtime/registry/lemon-squeezy.mjs +3 -6
- package/dist/runtime/registry/matomo-analytics.mjs +11 -10
- package/dist/runtime/registry/{facebook-pixel.d.ts → meta-pixel.d.ts} +7 -7
- package/dist/runtime/registry/{facebook-pixel.mjs → meta-pixel.mjs} +9 -7
- package/dist/runtime/registry/npm.mjs +2 -2
- package/dist/runtime/registry/plausible-analytics.mjs +2 -2
- package/dist/runtime/registry/segment.d.ts +22 -9
- package/dist/runtime/registry/segment.mjs +43 -21
- package/dist/runtime/registry/stripe.mjs +4 -4
- package/dist/runtime/registry/vimeo-player.d.ts +6 -6
- package/dist/runtime/registry/vimeo-player.mjs +30 -34
- package/dist/runtime/registry/x-pixel.mjs +17 -13
- package/dist/runtime/registry/youtube-player.d.ts +14 -0
- package/dist/runtime/registry/{youtube-iframe.mjs → youtube-player.mjs} +22 -20
- package/dist/runtime/types.d.ts +33 -16
- package/dist/runtime/types.mjs +2 -0
- package/dist/runtime/utils.d.ts +3 -2
- package/dist/runtime/utils.mjs +15 -13
- package/package.json +6 -6
- package/dist/client/_nuxt/CMNIl2hT.js +0 -31
- package/dist/client/_nuxt/builds/meta/8b865286-abcf-4201-a2af-ee13e4478155.json +0 -1
- package/dist/runtime/components/GoogleMaps.vue +0 -130
- package/dist/runtime/components/LemonSqueezyButton.vue +0 -28
- package/dist/runtime/components/StripePricingTableEmbed.vue +0 -33
- package/dist/runtime/components/VimeoEmbed.vue +0 -161
- package/dist/runtime/components/YouTubeEmbed.vue +0 -79
- package/dist/runtime/registry/youtube-iframe.d.ts +0 -15
|
@@ -7,15 +7,27 @@ export declare const SegmentOptions: import("valibot").ObjectSchema<{
|
|
|
7
7
|
analyticsKey?: string | undefined;
|
|
8
8
|
}>;
|
|
9
9
|
export type SegmentInput = RegistryScriptInput<typeof SegmentOptions>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
interface AnalyticsApi {
|
|
11
|
+
track: (event: string, properties?: Record<string, any>) => void;
|
|
12
|
+
page: (name?: string, properties?: Record<string, any>) => void;
|
|
13
|
+
identify: (userId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
|
|
14
|
+
group: (groupId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
|
|
15
|
+
alias: (userId: string, previousId: string, options?: Record<string, any>) => void;
|
|
16
|
+
reset: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
methods: string[];
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
factory: (method: string) => (...args: any[]) => AnalyticsApi;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
push: (args: any[]) => void;
|
|
29
|
+
}
|
|
30
|
+
export interface SegmentApi extends Pick<AnalyticsApi, 'track' | 'page' | 'identify' | 'group' | 'alias' | 'reset'> {
|
|
19
31
|
}
|
|
20
32
|
declare global {
|
|
21
33
|
interface Window extends SegmentApi {
|
|
@@ -24,3 +36,4 @@ declare global {
|
|
|
24
36
|
export declare function useScriptSegment<T extends SegmentApi>(_options?: SegmentInput): T & {
|
|
25
37
|
$script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
|
|
26
38
|
};
|
|
39
|
+
export {};
|
|
@@ -1,39 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRegistryScript } from "../utils.mjs";
|
|
2
2
|
import { SegmentScriptResolver } from "../../registry";
|
|
3
3
|
import { object, optional, string } from "#nuxt-scripts-validator";
|
|
4
4
|
export const SegmentOptions = object({
|
|
5
5
|
writeKey: string(),
|
|
6
6
|
analyticsKey: optional(string())
|
|
7
7
|
});
|
|
8
|
+
const methods = ["track", "page", "identify", "group", "alias", "reset"];
|
|
8
9
|
export function useScriptSegment(_options) {
|
|
9
|
-
return
|
|
10
|
-
const
|
|
10
|
+
return useRegistryScript("segment", (options) => {
|
|
11
|
+
const k = options?.analyticsKey ?? "analytics";
|
|
11
12
|
return {
|
|
12
13
|
scriptInput: {
|
|
13
|
-
"data-global-segment-analytics-key":
|
|
14
|
+
"data-global-segment-analytics-key": k,
|
|
14
15
|
"src": SegmentScriptResolver(options)
|
|
15
16
|
},
|
|
17
|
+
clientInit: import.meta.server ? void 0 : () => {
|
|
18
|
+
window[k] = window[k] || [];
|
|
19
|
+
window[k].methods = methods;
|
|
20
|
+
window[k].factory = function(method) {
|
|
21
|
+
return function(...params) {
|
|
22
|
+
const args = Array.prototype.slice.call(params);
|
|
23
|
+
args.unshift(method);
|
|
24
|
+
window[k].push(args);
|
|
25
|
+
return window[k];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
for (let i = 0; i < window[k].methods.length; i++) {
|
|
29
|
+
const key = window[k].methods[i];
|
|
30
|
+
window[k][key] = window[k].factory(key);
|
|
31
|
+
}
|
|
32
|
+
window[k].page();
|
|
33
|
+
},
|
|
16
34
|
schema: import.meta.dev ? SegmentOptions : void 0,
|
|
17
35
|
scriptOptions: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
stub: import.meta.server ? ({ fn }) => {
|
|
37
|
+
if (fn === "analytics") {
|
|
38
|
+
return {
|
|
39
|
+
track: () => {
|
|
40
|
+
},
|
|
41
|
+
page: () => {
|
|
42
|
+
},
|
|
43
|
+
identify: () => {
|
|
44
|
+
},
|
|
45
|
+
group: () => {
|
|
46
|
+
},
|
|
47
|
+
alias: () => {
|
|
48
|
+
},
|
|
49
|
+
reset: () => {
|
|
50
|
+
}
|
|
30
51
|
};
|
|
31
|
-
};
|
|
32
|
-
for (let i = 0; i < window.analytics.methods.length; i++) {
|
|
33
|
-
const key = window.analytics.methods[i];
|
|
34
|
-
window.analytics[key] = window.analytics.factory(key);
|
|
35
52
|
}
|
|
36
|
-
|
|
53
|
+
} : void 0,
|
|
54
|
+
use() {
|
|
55
|
+
return methods.reduce((acc, key) => {
|
|
56
|
+
acc[key] = window[k].factory(key);
|
|
57
|
+
return acc;
|
|
58
|
+
}, {});
|
|
37
59
|
}
|
|
38
60
|
}
|
|
39
61
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { withQuery } from "ufo";
|
|
2
|
-
import {
|
|
2
|
+
import { useRegistryScript } from "../utils.mjs";
|
|
3
3
|
import { boolean, object, optional } from "#nuxt-scripts-validator";
|
|
4
4
|
export const StripeOptions = object({
|
|
5
5
|
advancedFraudSignals: optional(boolean())
|
|
6
6
|
});
|
|
7
7
|
export function useScriptStripe(_options) {
|
|
8
|
-
return
|
|
8
|
+
return useRegistryScript("stripe", (options) => ({
|
|
9
9
|
scriptInput: {
|
|
10
10
|
src: withQuery(
|
|
11
11
|
`https://js.stripe.com/v3/`,
|
|
@@ -13,9 +13,9 @@ export function useScriptStripe(_options) {
|
|
|
13
13
|
),
|
|
14
14
|
// opt-out of privacy defaults
|
|
15
15
|
// @ts-expect-error TODO add types
|
|
16
|
-
crossorigin:
|
|
16
|
+
crossorigin: false,
|
|
17
17
|
// @ts-expect-error TODO add types
|
|
18
|
-
referrerpolicy:
|
|
18
|
+
referrerpolicy: false
|
|
19
19
|
},
|
|
20
20
|
schema: import.meta.dev ? StripeOptions : void 0,
|
|
21
21
|
scriptOptions: {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type ScriptVimeoPlayer from 'vimeo__player';
|
|
2
2
|
import type { RegistryScriptInput } from '#nuxt-scripts';
|
|
3
3
|
export interface VimeoPlayerApi {
|
|
4
|
-
|
|
4
|
+
Vimeo: {
|
|
5
|
+
Player: ScriptVimeoPlayer;
|
|
6
|
+
};
|
|
5
7
|
}
|
|
6
|
-
export
|
|
7
|
-
export type VimeoPlayerInput = RegistryScriptInput<typeof VimeoPlayerOptions>;
|
|
8
|
+
export type VimeoPlayerInput = RegistryScriptInput;
|
|
8
9
|
declare global {
|
|
9
|
-
interface Window {
|
|
10
|
-
Vimeo: VimeoPlayerApi;
|
|
10
|
+
interface Window extends VimeoPlayerApi {
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
export declare function useScriptVimeoPlayer<T extends VimeoPlayerApi>(_options?: VimeoPlayerInput): T & {
|
|
@@ -1,45 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { watch } from "vue";
|
|
2
|
+
import { useRegistryScript } from "../utils.mjs";
|
|
3
3
|
import { useHead } from "#imports";
|
|
4
|
-
export const VimeoPlayerOptions = object({});
|
|
5
4
|
export function useScriptVimeoPlayer(_options) {
|
|
6
|
-
|
|
5
|
+
const instance = useRegistryScript("vimeoPlayer", () => ({
|
|
7
6
|
scriptInput: {
|
|
8
7
|
src: "https://player.vimeo.com/api/player.js"
|
|
9
8
|
},
|
|
10
|
-
schema: import.meta.dev ? VimeoPlayerOptions : void 0,
|
|
11
9
|
scriptOptions: {
|
|
12
10
|
use() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return new window.Vimeo.Player(...params);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return { Player };
|
|
11
|
+
return {
|
|
12
|
+
Vimeo: window.Vimeo
|
|
13
|
+
};
|
|
20
14
|
}
|
|
21
|
-
},
|
|
22
|
-
beforeInit() {
|
|
23
|
-
useHead({
|
|
24
|
-
link: [
|
|
25
|
-
{
|
|
26
|
-
rel: "preconnect",
|
|
27
|
-
href: "https://player.vimeo.com"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
rel: "preconnect",
|
|
31
|
-
href: "https://i.vimeocdn.com"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
rel: "preconnect",
|
|
35
|
-
href: "https://f.vimeocdn.com"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
rel: "preconnect",
|
|
39
|
-
href: "https://fresnel.vimeocdn.com"
|
|
40
|
-
}
|
|
41
|
-
]
|
|
42
|
-
});
|
|
43
15
|
}
|
|
44
16
|
}), _options);
|
|
17
|
+
if (import.meta.client) {
|
|
18
|
+
const _ = watch(instance.$script.status, (status) => {
|
|
19
|
+
if (status === "loading") {
|
|
20
|
+
useHead({
|
|
21
|
+
link: [
|
|
22
|
+
{
|
|
23
|
+
rel: "preconnect",
|
|
24
|
+
href: "https://i.vimeocdn.com"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
rel: "preconnect",
|
|
28
|
+
href: "https://f.vimeocdn.com"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
rel: "preconnect",
|
|
32
|
+
href: "https://fresnel.vimeocdn.com"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
_();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return instance;
|
|
45
41
|
}
|
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRegistryScript } from "../utils.mjs";
|
|
2
2
|
import { object, optional, string } from "#nuxt-scripts-validator";
|
|
3
3
|
export const XPixelOptions = object({
|
|
4
4
|
id: string(),
|
|
5
5
|
version: optional(string())
|
|
6
6
|
});
|
|
7
7
|
export function useScriptXPixel(_options) {
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
use() {
|
|
15
|
-
return { twq: window.twq };
|
|
8
|
+
return useRegistryScript("xPixel", (options) => {
|
|
9
|
+
return {
|
|
10
|
+
scriptInput: {
|
|
11
|
+
src: "https://static.ads-twitter.com/uwt.js",
|
|
12
|
+
// @ts-expect-error TODO fix upstream
|
|
13
|
+
crossorigin: false
|
|
16
14
|
},
|
|
17
15
|
clientInit: import.meta.server ? void 0 : () => {
|
|
18
|
-
const s = window.twq = function(
|
|
19
|
-
s.exe ? s.exe(s,
|
|
16
|
+
const s = window.twq = function() {
|
|
17
|
+
s.exe ? s.exe(s, arguments) : s.queue.push(arguments);
|
|
20
18
|
};
|
|
21
19
|
s.version = options?.version || "1.1";
|
|
22
20
|
s.queue = [
|
|
23
21
|
["config", options?.id]
|
|
24
22
|
];
|
|
23
|
+
},
|
|
24
|
+
schema: import.meta.dev ? XPixelOptions : void 0,
|
|
25
|
+
scriptOptions: {
|
|
26
|
+
use() {
|
|
27
|
+
return { twq: window.twq };
|
|
28
|
+
}
|
|
25
29
|
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
30
|
+
};
|
|
31
|
+
}, _options);
|
|
28
32
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="youtube" />
|
|
2
|
+
import type { RegistryScriptInput } from '#nuxt-scripts';
|
|
3
|
+
export interface YouTubePlayerApi {
|
|
4
|
+
YT: typeof YT;
|
|
5
|
+
}
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window extends YouTubePlayerApi {
|
|
8
|
+
onYouTubeIframeAPIReady: () => void;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export type YouTubePlayerInput = RegistryScriptInput;
|
|
12
|
+
export declare function useScriptYouTubePlayer<T extends YouTubePlayerApi>(_options: YouTubePlayerInput): T & {
|
|
13
|
+
$script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
|
|
14
|
+
};
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { watch } from "vue";
|
|
2
|
+
import { useRegistryScript } from "../utils.mjs";
|
|
3
3
|
import { useHead } from "#imports";
|
|
4
|
-
export
|
|
5
|
-
// no options afaik
|
|
6
|
-
});
|
|
7
|
-
export function useScriptYouTubeIframe(_options) {
|
|
4
|
+
export function useScriptYouTubePlayer(_options) {
|
|
8
5
|
let readyPromise = Promise.resolve();
|
|
9
|
-
|
|
6
|
+
const instance = useRegistryScript("youtubePlayer", () => ({
|
|
10
7
|
scriptInput: {
|
|
11
8
|
src: "https://www.youtube.com/iframe_api",
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
crossorigin
|
|
9
|
+
// @ts-expect-error TODO fix types upstream
|
|
10
|
+
crossorigin: false
|
|
11
|
+
// crossorigin can't be set or it breaks
|
|
15
12
|
},
|
|
16
|
-
schema: import.meta.dev ? YouTubeIframeOptions : void 0,
|
|
17
13
|
scriptOptions: {
|
|
18
14
|
use() {
|
|
19
15
|
return {
|
|
@@ -21,13 +17,17 @@ export function useScriptYouTubeIframe(_options) {
|
|
|
21
17
|
return window.YT;
|
|
22
18
|
})
|
|
23
19
|
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
clientInit: import.meta.server ? void 0 : () => {
|
|
23
|
+
readyPromise = new Promise((resolve) => {
|
|
24
|
+
window.onYouTubeIframeAPIReady = resolve;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}), _options);
|
|
28
|
+
if (import.meta.client) {
|
|
29
|
+
const _ = watch(instance.$script.status, (status) => {
|
|
30
|
+
if (status === "loading") {
|
|
31
31
|
useHead({
|
|
32
32
|
link: [
|
|
33
33
|
{
|
|
@@ -48,7 +48,9 @@ export function useScriptYouTubeIframe(_options) {
|
|
|
48
48
|
}
|
|
49
49
|
]
|
|
50
50
|
});
|
|
51
|
+
_();
|
|
51
52
|
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return instance;
|
|
54
56
|
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Input, ObjectSchema } from 'valibot';
|
|
|
5
5
|
import type { Import } from 'unimport';
|
|
6
6
|
import type { SegmentInput } from './registry/segment';
|
|
7
7
|
import type { CloudflareWebAnalyticsInput } from './registry/cloudflare-web-analytics';
|
|
8
|
-
import type {
|
|
8
|
+
import type { MetaPixelInput } from './registry/meta-pixel';
|
|
9
9
|
import type { FathomAnalyticsInput } from './registry/fathom-analytics';
|
|
10
10
|
import type { HotjarInput } from './registry/hotjar';
|
|
11
11
|
import type { IntercomInput } from './registry/intercom';
|
|
@@ -16,6 +16,10 @@ import type { MatomoAnalyticsInput } from './registry/matomo-analytics';
|
|
|
16
16
|
import type { StripeInput } from './registry/stripe';
|
|
17
17
|
import type { VimeoPlayerInput } from './registry/vimeo-player';
|
|
18
18
|
import type { XPixelInput } from './registry/x-pixel';
|
|
19
|
+
import type { YouTubePlayerInput } from './registry/youtube-player';
|
|
20
|
+
import type { PlausibleAnalyticsInput } from './registry/plausible-analytics';
|
|
21
|
+
import type { NpmInput } from './registry/npm';
|
|
22
|
+
import type { LemonSqueezyInput } from './registry/lemon-squeezy';
|
|
19
23
|
export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
20
24
|
/**
|
|
21
25
|
* The trigger to load the script:
|
|
@@ -32,6 +36,11 @@ export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'>
|
|
|
32
36
|
* - `false` - Do not bundle the script. (default)
|
|
33
37
|
*/
|
|
34
38
|
bundle?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Skip any schema validation for the script input. This is useful for loading the script stubs for development without
|
|
41
|
+
* loading the actual script and not getting warnings.
|
|
42
|
+
*/
|
|
43
|
+
skipValidation?: boolean;
|
|
35
44
|
};
|
|
36
45
|
export type NuxtUseScriptIntegrationOptions = Omit<NuxtUseScriptOptions, 'use'>;
|
|
37
46
|
export type NuxtUseScriptInput = UseScriptInput;
|
|
@@ -64,23 +73,30 @@ export interface NuxtAppScript {
|
|
|
64
73
|
at: number;
|
|
65
74
|
}[];
|
|
66
75
|
}
|
|
67
|
-
export type ScriptRegistryEntry<T> = true | T | [T, NuxtUseScriptOptions<T>];
|
|
68
76
|
export interface ScriptRegistry {
|
|
69
|
-
cloudflareWebAnalytics?:
|
|
70
|
-
|
|
71
|
-
fathomAnalytics?:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
cloudflareWebAnalytics?: CloudflareWebAnalyticsInput;
|
|
78
|
+
metaPixel?: MetaPixelInput;
|
|
79
|
+
fathomAnalytics?: FathomAnalyticsInput;
|
|
80
|
+
plausibleAnalytics?: PlausibleAnalyticsInput;
|
|
81
|
+
googleAnalytics?: GoogleAnalyticsInput;
|
|
82
|
+
googleMaps?: GoogleMapsInput;
|
|
83
|
+
lemonSqueezy?: LemonSqueezyInput;
|
|
84
|
+
googleTagManager?: GoogleTagManagerInput;
|
|
85
|
+
hotjar?: HotjarInput;
|
|
86
|
+
intercom?: IntercomInput;
|
|
87
|
+
matomoAnalytics?: MatomoAnalyticsInput;
|
|
88
|
+
segment?: SegmentInput;
|
|
89
|
+
stripe?: StripeInput;
|
|
90
|
+
xPixel?: XPixelInput;
|
|
91
|
+
youtubePlayer?: YouTubePlayerInput;
|
|
92
|
+
vimeoPlayer?: VimeoPlayerInput;
|
|
93
|
+
[key: `${string}-npm`]: NpmInput;
|
|
82
94
|
}
|
|
83
|
-
export type
|
|
95
|
+
export type NuxtConfigScriptRegistryEntry<T> = true | 'mock' | T | [T, NuxtUseScriptOptions<T>];
|
|
96
|
+
export type NuxtConfigScriptRegistry<T extends keyof ScriptRegistry = keyof ScriptRegistry> = Partial<Record<T, NuxtConfigScriptRegistryEntry<ScriptRegistry[T]>>>;
|
|
97
|
+
declare const emptyOptions: ObjectSchema<{}, undefined, {}>;
|
|
98
|
+
export type EmptyOptionsSchema = typeof emptyOptions;
|
|
99
|
+
export type RegistryScriptInput<T extends ObjectSchema<any> = EmptyOptionsSchema, Bundelable extends boolean = true> = Input<T> & {
|
|
84
100
|
scriptInput?: UseScriptInput;
|
|
85
101
|
scriptOptions?: Bundelable extends true ? Omit<NuxtUseScriptOptions, 'use'> : Omit<NuxtUseScriptOptions, 'bundle' | 'use'>;
|
|
86
102
|
};
|
|
@@ -95,3 +111,4 @@ export type RegistryScripts = {
|
|
|
95
111
|
dark: string;
|
|
96
112
|
};
|
|
97
113
|
}[];
|
|
114
|
+
export {};
|
package/dist/runtime/types.mjs
CHANGED
package/dist/runtime/utils.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Input, ObjectSchema } from 'valibot';
|
|
2
2
|
import type { UseScriptInput } from '@unhead/vue';
|
|
3
|
-
import type { NuxtUseScriptOptions, RegistryScriptInput } from '#nuxt-scripts';
|
|
3
|
+
import type { EmptyOptionsSchema, NuxtUseScriptOptions, RegistryScriptInput, ScriptRegistry } from '#nuxt-scripts';
|
|
4
4
|
type OptionsFn<O extends ObjectSchema<any>> = (options: Input<O>) => ({
|
|
5
5
|
scriptInput?: UseScriptInput;
|
|
6
6
|
scriptOptions?: NuxtUseScriptOptions;
|
|
7
7
|
schema?: O;
|
|
8
8
|
clientInit?: () => void;
|
|
9
9
|
});
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function scriptRuntimeConfig<T extends keyof ScriptRegistry>(key: T): ScriptRegistry[T];
|
|
11
|
+
export declare function useRegistryScript<T extends Record<string | symbol, any>, O extends ObjectSchema<any> = EmptyOptionsSchema>(key: keyof ScriptRegistry | string, optionsFn: OptionsFn<O>, _userOptions?: RegistryScriptInput<O>): T & {
|
|
11
12
|
$script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
|
|
12
13
|
};
|
|
13
14
|
export {};
|
package/dist/runtime/utils.mjs
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
2
|
import { parse } from "#nuxt-scripts-validator";
|
|
3
|
-
import {
|
|
3
|
+
import { useRuntimeConfig, useScript } from "#imports";
|
|
4
4
|
function validateScriptInputSchema(key, schema, options) {
|
|
5
5
|
if (import.meta.dev) {
|
|
6
6
|
try {
|
|
7
7
|
parse(schema, options);
|
|
8
|
-
} catch (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
message: `Invalid script options for ${key}`
|
|
12
|
-
});
|
|
8
|
+
} catch (_e) {
|
|
9
|
+
const e = _e;
|
|
10
|
+
console.error(e.issues.map((i) => `${key}.${i.path?.map((i2) => i2.key).join(",")}: ${i.message}`).join("\n"));
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
|
-
export function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
export function scriptRuntimeConfig(key) {
|
|
15
|
+
return (useRuntimeConfig().public.scripts || {})[key];
|
|
16
|
+
}
|
|
17
|
+
export function useRegistryScript(key, optionsFn, _userOptions) {
|
|
18
|
+
const scriptConfig = scriptRuntimeConfig(key);
|
|
19
|
+
const userOptions = Object.assign(_userOptions || {}, typeof scriptConfig === "object" ? scriptConfig : {});
|
|
20
20
|
const options = optionsFn(userOptions);
|
|
21
21
|
const scriptInput = defu(options.scriptInput, { key });
|
|
22
|
-
const scriptOptions = Object.assign(
|
|
22
|
+
const scriptOptions = Object.assign(userOptions?.scriptOptions || {}, options.scriptOptions || {});
|
|
23
23
|
const init = scriptOptions.beforeInit;
|
|
24
24
|
scriptOptions.beforeInit = () => {
|
|
25
|
-
import.meta.dev && options.schema && validateScriptInputSchema(key, options.schema, userOptions);
|
|
25
|
+
import.meta.dev && !scriptOptions.skipValidation && options.schema && validateScriptInputSchema(key, options.schema, userOptions);
|
|
26
26
|
init?.();
|
|
27
|
-
import.meta.client
|
|
27
|
+
if (import.meta.client) {
|
|
28
|
+
options.clientInit?.();
|
|
29
|
+
}
|
|
28
30
|
};
|
|
29
31
|
return useScript(scriptInput, scriptOptions);
|
|
30
32
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/scripts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.5",
|
|
5
5
|
"description": "Load third-party scripts with better performance, privacy and DX in Nuxt Apps.",
|
|
6
6
|
"author": {
|
|
7
7
|
"website": "https://harlanzw.com",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"@nuxt/devtools-kit": "^1.2.0",
|
|
44
44
|
"@nuxt/devtools-ui-kit": "^1.2.0",
|
|
45
45
|
"@nuxt/kit": "^3.11.2",
|
|
46
|
-
"@types/google.maps": "^3.55.
|
|
46
|
+
"@types/google.maps": "^3.55.8",
|
|
47
47
|
"@types/stripe-v3": "^3.1.33",
|
|
48
48
|
"@types/vimeo__player": "^2.18.3",
|
|
49
49
|
"@types/youtube": "^0.0.50",
|
|
50
|
-
"@unhead/vue": "^1.9.
|
|
50
|
+
"@unhead/vue": "^1.9.9",
|
|
51
51
|
"@vueuse/core": "^10.9.0",
|
|
52
52
|
"consola": "^3.2.3",
|
|
53
53
|
"defu": "^6.1.4",
|
|
@@ -75,14 +75,14 @@
|
|
|
75
75
|
"@nuxt/devtools-ui-kit": "^1.2.0",
|
|
76
76
|
"@nuxt/module-builder": "^0.6.0",
|
|
77
77
|
"@nuxt/test-utils": "3.12.1",
|
|
78
|
-
"@unhead/schema": "^1.9.
|
|
78
|
+
"@unhead/schema": "^1.9.9",
|
|
79
79
|
"acorn-loose": "^8.4.0",
|
|
80
80
|
"bumpp": "^9.4.1",
|
|
81
|
-
"eslint": "9.
|
|
81
|
+
"eslint": "9.2.0",
|
|
82
82
|
"nuxt": "^3.11.2",
|
|
83
83
|
"playwright-core": "^1.43.1",
|
|
84
84
|
"typescript": "^5.4.5",
|
|
85
|
-
"vitest": "^1.
|
|
85
|
+
"vitest": "^1.6.0",
|
|
86
86
|
"vue": "^3.4.26",
|
|
87
87
|
"vue-router": "^4.3.2"
|
|
88
88
|
},
|