@nuxt/scripts 0.1.12 → 0.2.0
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 +10 -200
- package/dist/client/200.html +14 -14
- package/dist/client/404.html +14 -14
- package/dist/client/_nuxt/-hLHpAOl.js +1 -0
- package/dist/client/_nuxt/3Yx8WcR-.js +1 -0
- package/dist/client/_nuxt/BLO8rZtj.js +31 -0
- package/dist/client/_nuxt/{DggdVF2v.js → CQ1WWl9n.js} +1 -1
- package/dist/client/_nuxt/CudBhkk3.js +1 -0
- package/dist/client/_nuxt/{CW3w6uup.js → D6KmUh4-.js} +1 -1
- package/dist/client/_nuxt/{7fd6vGzb.js → DBeuZS66.js} +1 -1
- package/dist/client/_nuxt/DG73IEBO.js +1 -0
- package/dist/client/_nuxt/DX0ZGhB-.js +1 -0
- package/dist/client/_nuxt/{A1WiD9SJ.js → DaCkt_J7.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/69e9f83a-05c7-439f-bf82-0c2d6d83b961.json +1 -0
- package/dist/client/_nuxt/error-404.BRldFSII.css +1 -0
- package/dist/client/_nuxt/error-500.D8yw_IbC.css +1 -0
- package/dist/client/index.html +14 -14
- package/dist/module.d.mts +2 -6
- package/dist/module.d.ts +2 -6
- package/dist/module.json +6 -2
- package/dist/module.mjs +275 -131
- package/dist/runtime/components/GoogleMaps.vue +130 -0
- package/dist/runtime/components/LemonSqueezyButton.vue +28 -0
- package/dist/runtime/components/StripePricingTableEmbed.vue +33 -0
- package/dist/runtime/components/VimeoEmbed.vue +161 -0
- package/dist/runtime/components/YouTubeEmbed.vue +79 -0
- package/dist/runtime/composables/useElementScriptTrigger.d.ts +3 -0
- package/dist/runtime/composables/useElementScriptTrigger.mjs +9 -0
- package/dist/runtime/composables/useScript.d.ts +1 -1
- package/dist/runtime/composables/useScript.mjs +0 -1
- package/dist/runtime/registry/cloudflare-web-analytics.d.ts +9 -7
- package/dist/runtime/registry/cloudflare-web-analytics.mjs +16 -18
- package/dist/runtime/registry/confetti.d.ts +4 -4
- package/dist/runtime/registry/confetti.mjs +11 -8
- package/dist/runtime/registry/facebook-pixel.d.ts +4 -5
- package/dist/runtime/registry/facebook-pixel.mjs +15 -17
- package/dist/runtime/registry/fathom-analytics.d.ts +22 -14
- package/dist/runtime/registry/fathom-analytics.mjs +25 -20
- package/dist/runtime/registry/google-analytics.d.ts +19 -1
- package/dist/runtime/registry/google-analytics.mjs +30 -3
- package/dist/runtime/registry/google-maps.d.ts +21 -1
- package/dist/runtime/registry/google-maps.mjs +40 -3
- package/dist/runtime/registry/google-tag-manager.d.ts +19 -1
- package/dist/runtime/registry/google-tag-manager.mjs +29 -3
- package/dist/runtime/registry/hotjar.d.ts +3 -3
- package/dist/runtime/registry/hotjar.mjs +14 -18
- package/dist/runtime/registry/intercom.d.ts +3 -3
- package/dist/runtime/registry/intercom.mjs +19 -16
- package/dist/runtime/registry/lemon-squeezy.d.ts +66 -0
- package/dist/runtime/registry/lemon-squeezy.mjs +21 -0
- package/dist/runtime/registry/matomo-analytics.d.ts +22 -0
- package/dist/runtime/registry/matomo-analytics.mjs +33 -0
- package/dist/runtime/registry/npm.d.ts +5 -3
- package/dist/runtime/registry/npm.mjs +10 -11
- package/dist/runtime/registry/plausible-analytics.d.ts +20 -0
- package/dist/runtime/registry/plausible-analytics.mjs +35 -0
- package/dist/runtime/registry/segment.d.ts +3 -3
- package/dist/runtime/registry/segment.mjs +34 -34
- package/dist/runtime/registry/stripe.d.ts +16 -0
- package/dist/runtime/registry/stripe.mjs +27 -0
- package/dist/runtime/registry/vimeo-player.d.ts +13 -0
- package/dist/runtime/registry/vimeo-player.mjs +45 -0
- package/dist/runtime/registry/x-pixel.d.ts +39 -0
- package/dist/runtime/registry/x-pixel.mjs +28 -0
- package/dist/runtime/registry/youtube-iframe.d.ts +13 -0
- package/dist/runtime/registry/youtube-iframe.mjs +54 -0
- package/dist/runtime/types.d.ts +31 -15
- package/dist/runtime/utils.d.ts +11 -0
- package/dist/runtime/utils.mjs +30 -1
- package/package.json +34 -23
- package/dist/client/_nuxt/BG_OyJVq.js +0 -1
- package/dist/client/_nuxt/C3YqBJkQ.js +0 -1
- package/dist/client/_nuxt/CKtB_0Vj.js +0 -36
- package/dist/client/_nuxt/CrjQeCwm.js +0 -1
- package/dist/client/_nuxt/D75a3hZQ.js +0 -1
- package/dist/client/_nuxt/builds/meta/7bb27f9d-e4a9-494c-83a3-01bc2df7d17d.json +0 -1
- package/dist/client/_nuxt/error-404.ORekjfyJ.css +0 -1
- package/dist/client/_nuxt/error-500.BIuFL0tW.css +0 -1
- package/dist/client/_nuxt/yr0V4Txy.js +0 -1
- package/dist/runtime/composables/validateScriptInputSchema.d.ts +0 -2
- package/dist/runtime/composables/validateScriptInputSchema.mjs +0 -14
- package/dist/runtime/registry/cloudflare-turnstile.d.ts +0 -1
- package/dist/runtime/registry/cloudflare-turnstile.mjs +0 -4
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RegistryScriptInput } from '#nuxt-scripts';
|
|
2
|
+
export declare const PlausibleAnalyticsOptions: import("valibot").ObjectSchema<{
|
|
3
|
+
domain: import("valibot").StringSchema<string>;
|
|
4
|
+
extension: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").UnionSchema<(import("valibot").LiteralSchema<"hash", "hash"> | import("valibot").LiteralSchema<"outbound-links", "outbound-links"> | import("valibot").LiteralSchema<"file-downloads", "file-downloads"> | import("valibot").LiteralSchema<"tagged-events", "tagged-events"> | import("valibot").LiteralSchema<"revenue", "revenue"> | import("valibot").LiteralSchema<"pageview-props", "pageview-props"> | import("valibot").LiteralSchema<"compat", "compat"> | import("valibot").LiteralSchema<"local", "local"> | import("valibot").LiteralSchema<"manual", "manual">)[], "manual" | "hash" | "outbound-links" | "file-downloads" | "tagged-events" | "revenue" | "pageview-props" | "compat" | "local"> | import("valibot").ArraySchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"hash", "hash"> | import("valibot").LiteralSchema<"outbound-links", "outbound-links"> | import("valibot").LiteralSchema<"file-downloads", "file-downloads"> | import("valibot").LiteralSchema<"tagged-events", "tagged-events"> | import("valibot").LiteralSchema<"revenue", "revenue"> | import("valibot").LiteralSchema<"pageview-props", "pageview-props"> | import("valibot").LiteralSchema<"compat", "compat"> | import("valibot").LiteralSchema<"local", "local"> | import("valibot").LiteralSchema<"manual", "manual">)[], "manual" | "hash" | "outbound-links" | "file-downloads" | "tagged-events" | "revenue" | "pageview-props" | "compat" | "local">, ("manual" | "hash" | "outbound-links" | "file-downloads" | "tagged-events" | "revenue" | "pageview-props" | "compat" | "local")[]>)[], "manual" | "hash" | "outbound-links" | "file-downloads" | "tagged-events" | "revenue" | "pageview-props" | "compat" | "local" | ("manual" | "hash" | "outbound-links" | "file-downloads" | "tagged-events" | "revenue" | "pageview-props" | "compat" | "local")[]>, undefined, "manual" | "hash" | "outbound-links" | "file-downloads" | "tagged-events" | "revenue" | "pageview-props" | "compat" | "local" | ("manual" | "hash" | "outbound-links" | "file-downloads" | "tagged-events" | "revenue" | "pageview-props" | "compat" | "local")[] | undefined>;
|
|
5
|
+
}, undefined, {
|
|
6
|
+
domain: string;
|
|
7
|
+
extension?: "manual" | "hash" | "outbound-links" | "file-downloads" | "tagged-events" | "revenue" | "pageview-props" | "compat" | "local" | ("manual" | "hash" | "outbound-links" | "file-downloads" | "tagged-events" | "revenue" | "pageview-props" | "compat" | "local")[] | undefined;
|
|
8
|
+
}>;
|
|
9
|
+
export type PlausibleAnalyticsInput = RegistryScriptInput<typeof PlausibleAnalyticsOptions, false>;
|
|
10
|
+
export interface PlausibleAnalyticsApi {
|
|
11
|
+
plausible: ((event: '404', options: Record<string, any>) => void) & ((event: 'event', options: Record<string, any>) => void) & ((...params: any[]) => void) & {
|
|
12
|
+
q: any[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
declare global {
|
|
16
|
+
interface Window {
|
|
17
|
+
plausible: PlausibleAnalyticsApi;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export declare function useScriptPlausibleAnalytics<T extends PlausibleAnalyticsApi>(_options?: PlausibleAnalyticsInput): any;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { array, literal, object, optional, string, union } from "valibot";
|
|
2
|
+
import { registryScript } from "../utils.mjs";
|
|
3
|
+
import { PlausibleAnalyticsScriptResolver } from "../../registry";
|
|
4
|
+
const extensions = [
|
|
5
|
+
literal("hash"),
|
|
6
|
+
literal("outbound-links"),
|
|
7
|
+
literal("file-downloads"),
|
|
8
|
+
literal("tagged-events"),
|
|
9
|
+
literal("revenue"),
|
|
10
|
+
literal("pageview-props"),
|
|
11
|
+
literal("compat"),
|
|
12
|
+
literal("local"),
|
|
13
|
+
literal("manual")
|
|
14
|
+
];
|
|
15
|
+
export const PlausibleAnalyticsOptions = object({
|
|
16
|
+
domain: string(),
|
|
17
|
+
// required
|
|
18
|
+
extension: optional(union([union(extensions), array(union(extensions))]))
|
|
19
|
+
});
|
|
20
|
+
export function useScriptPlausibleAnalytics(_options) {
|
|
21
|
+
return registryScript("plausibleAnalytics", (options) => {
|
|
22
|
+
return {
|
|
23
|
+
scriptInput: {
|
|
24
|
+
"src": PlausibleAnalyticsScriptResolver(options),
|
|
25
|
+
"data-domain": options?.domain
|
|
26
|
+
},
|
|
27
|
+
schema: PlausibleAnalyticsOptions,
|
|
28
|
+
scriptOptions: {
|
|
29
|
+
use() {
|
|
30
|
+
return { plausible: window.plausible };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}, _options);
|
|
35
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RegistryScriptInput } from '#nuxt-scripts';
|
|
2
2
|
export declare const SegmentOptions: import("valibot").ObjectSchema<{
|
|
3
3
|
writeKey: import("valibot").StringSchema<string>;
|
|
4
4
|
analyticsKey: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
@@ -6,7 +6,7 @@ export declare const SegmentOptions: import("valibot").ObjectSchema<{
|
|
|
6
6
|
writeKey: string;
|
|
7
7
|
analyticsKey?: string | undefined;
|
|
8
8
|
}>;
|
|
9
|
-
export type SegmentInput =
|
|
9
|
+
export type SegmentInput = RegistryScriptInput<typeof SegmentOptions>;
|
|
10
10
|
export interface SegmentApi {
|
|
11
11
|
analytics: {
|
|
12
12
|
track: (event: string, properties?: Record<string, any>) => void;
|
|
@@ -21,4 +21,4 @@ declare global {
|
|
|
21
21
|
interface Window extends SegmentApi {
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
export declare function useScriptSegment<T extends SegmentApi>(
|
|
24
|
+
export declare function useScriptSegment<T extends SegmentApi>(_options?: SegmentInput): any;
|
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { object, optional, string } from "valibot";
|
|
2
|
-
import {
|
|
2
|
+
import { registryScript } from "../utils.mjs";
|
|
3
|
+
import { SegmentScriptResolver } from "../../registry";
|
|
3
4
|
export const SegmentOptions = object({
|
|
4
5
|
writeKey: string(),
|
|
5
6
|
analyticsKey: optional(string())
|
|
6
7
|
});
|
|
7
|
-
export function useScriptSegment(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
window
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
export function useScriptSegment(_options) {
|
|
9
|
+
return registryScript("segment", (options) => {
|
|
10
|
+
const analyticsKey = options?.analyticsKey || "analytics";
|
|
11
|
+
return {
|
|
12
|
+
scriptInput: {
|
|
13
|
+
"data-global-segment-analytics-key": analyticsKey,
|
|
14
|
+
"src": SegmentScriptResolver(options)
|
|
15
|
+
},
|
|
16
|
+
schema: SegmentOptions,
|
|
17
|
+
scriptOptions: {
|
|
18
|
+
use() {
|
|
19
|
+
return { analytics: window[analyticsKey] };
|
|
20
|
+
},
|
|
21
|
+
clientInit: import.meta.server ? void 0 : () => {
|
|
22
|
+
window.analytics = window.analytics || [];
|
|
23
|
+
window.analytics.methods = ["track", "page", "identify", "group", "alias", "reset"];
|
|
24
|
+
window.analytics.factory = function(method) {
|
|
25
|
+
return function(...params) {
|
|
26
|
+
const args = Array.prototype.slice.call(params);
|
|
27
|
+
args.unshift(method);
|
|
28
|
+
window.analytics.push(args);
|
|
29
|
+
return window.analytics;
|
|
30
|
+
};
|
|
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
|
+
}
|
|
36
|
+
window.analytics.page();
|
|
37
|
+
}
|
|
25
38
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_scriptOptions?.beforeInit?.();
|
|
29
|
-
};
|
|
30
|
-
const analyticsKey = options?.analyticsKey || "analytics";
|
|
31
|
-
return useScript({
|
|
32
|
-
"key": "segment",
|
|
33
|
-
"data-global-segment-analytics-key": analyticsKey,
|
|
34
|
-
"src": options?.src || `https://cdn.segment.com/analytics.js/v1/${options?.writeKey}/analytics.min.js`
|
|
35
|
-
}, {
|
|
36
|
-
...scriptOptions,
|
|
37
|
-
use() {
|
|
38
|
-
return { analytics: window[analyticsKey] };
|
|
39
|
-
}
|
|
40
|
-
});
|
|
39
|
+
};
|
|
40
|
+
}, _options);
|
|
41
41
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Stripe } from '@types/stripe-v3';
|
|
2
|
+
import type { RegistryScriptInput } from '#nuxt-scripts';
|
|
3
|
+
export declare const StripeOptions: import("valibot").ObjectSchema<{
|
|
4
|
+
advancedFraudSignals: import("valibot").OptionalSchema<import("valibot").BooleanSchema<boolean>, undefined, boolean | undefined>;
|
|
5
|
+
}, undefined, {
|
|
6
|
+
advancedFraudSignals?: boolean | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
export type StripeInput = RegistryScriptInput<typeof StripeOptions, false>;
|
|
9
|
+
export interface StripeApi {
|
|
10
|
+
Stripe: Stripe;
|
|
11
|
+
}
|
|
12
|
+
declare global {
|
|
13
|
+
interface Window extends StripeApi {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare function useScriptStripe<T extends StripeApi>(_options?: StripeInput): any;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { boolean, object, optional } from "valibot";
|
|
2
|
+
import { withQuery } from "ufo";
|
|
3
|
+
import { registryScript } from "../utils.mjs";
|
|
4
|
+
export const StripeOptions = object({
|
|
5
|
+
advancedFraudSignals: optional(boolean())
|
|
6
|
+
});
|
|
7
|
+
export function useScriptStripe(_options) {
|
|
8
|
+
return registryScript("stripe", (options) => ({
|
|
9
|
+
scriptInput: {
|
|
10
|
+
src: withQuery(
|
|
11
|
+
`https://js.stripe.com/v3/`,
|
|
12
|
+
typeof options?.advancedFraudSignals === "boolean" && !options?.advancedFraudSignals ? { advancedFraudSignals: false } : {}
|
|
13
|
+
),
|
|
14
|
+
// opt-out of privacy defaults
|
|
15
|
+
// @ts-expect-error TODO add types
|
|
16
|
+
crossorigin: null,
|
|
17
|
+
// @ts-expect-error TODO add types
|
|
18
|
+
referrerpolicy: null
|
|
19
|
+
},
|
|
20
|
+
schema: StripeOptions,
|
|
21
|
+
scriptOptions: {
|
|
22
|
+
use() {
|
|
23
|
+
return { Stripe: window.Stripe };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}), _options);
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type VimeoPlayer from 'vimeo__player';
|
|
2
|
+
import type { RegistryScriptInput } from '#nuxt-scripts';
|
|
3
|
+
export interface VimeoPlayerApi {
|
|
4
|
+
Player: VimeoPlayer;
|
|
5
|
+
}
|
|
6
|
+
export declare const VimeoPlayerOptions: import("valibot").ObjectSchema<{}, undefined, {}>;
|
|
7
|
+
export type VimeoPlayerInput = RegistryScriptInput<typeof VimeoPlayerOptions>;
|
|
8
|
+
declare global {
|
|
9
|
+
interface Window {
|
|
10
|
+
Vimeo: VimeoPlayerApi;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export declare function useScriptVimeoPlayer<T extends VimeoPlayerApi>(_options?: VimeoPlayerInput): any;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { object } from "valibot";
|
|
2
|
+
import { registryScript } from "../utils.mjs";
|
|
3
|
+
import { useHead } from "#imports";
|
|
4
|
+
export const VimeoPlayerOptions = object({});
|
|
5
|
+
export function useScriptVimeoPlayer(_options) {
|
|
6
|
+
return registryScript("vimeoPlayer", () => ({
|
|
7
|
+
scriptInput: {
|
|
8
|
+
src: "https://player.vimeo.com/api/player.js"
|
|
9
|
+
},
|
|
10
|
+
schema: VimeoPlayerOptions,
|
|
11
|
+
scriptOptions: {
|
|
12
|
+
use() {
|
|
13
|
+
let Player;
|
|
14
|
+
if (import.meta.client) {
|
|
15
|
+
Player = function(...params) {
|
|
16
|
+
return new window.Vimeo.Player(...params);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return { Player };
|
|
20
|
+
}
|
|
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
|
+
}
|
|
44
|
+
}), _options);
|
|
45
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RegistryScriptInput } from '#nuxt-scripts';
|
|
2
|
+
interface ContentProperties {
|
|
3
|
+
content_type?: string | null;
|
|
4
|
+
content_id?: string | number | null;
|
|
5
|
+
content_name?: string | null;
|
|
6
|
+
content_price?: string | number | null;
|
|
7
|
+
num_items?: string | number | null;
|
|
8
|
+
content_group_id?: string | number | null;
|
|
9
|
+
}
|
|
10
|
+
interface EventObjectProperties {
|
|
11
|
+
value?: string | number | null;
|
|
12
|
+
currency?: string | null;
|
|
13
|
+
conversion_id?: string | number | null;
|
|
14
|
+
email_address?: string | null;
|
|
15
|
+
phone_number?: string | null;
|
|
16
|
+
contents: ContentProperties[];
|
|
17
|
+
}
|
|
18
|
+
type TwqFns = ((event: 'event', eventId: string, data?: EventObjectProperties) => void) & ((event: 'config', id: string) => void) & ((event: string, ...params: any[]) => void);
|
|
19
|
+
export interface XPixelApi {
|
|
20
|
+
twq: TwqFns & {
|
|
21
|
+
loaded: boolean;
|
|
22
|
+
version: string;
|
|
23
|
+
queue: any[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
declare global {
|
|
27
|
+
interface Window extends XPixelApi {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export declare const XPixelOptions: import("valibot").ObjectSchema<{
|
|
31
|
+
id: import("valibot").StringSchema<string>;
|
|
32
|
+
version: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
33
|
+
}, undefined, {
|
|
34
|
+
id: string;
|
|
35
|
+
version?: string | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
export type XPixelInput = RegistryScriptInput<typeof XPixelOptions>;
|
|
38
|
+
export declare function useScriptXPixel<T extends XPixelApi>(_options?: XPixelInput): any;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { object, optional, string } from "valibot";
|
|
2
|
+
import { registryScript } from "../utils.mjs";
|
|
3
|
+
export const XPixelOptions = object({
|
|
4
|
+
id: string(),
|
|
5
|
+
version: optional(string())
|
|
6
|
+
});
|
|
7
|
+
export function useScriptXPixel(_options) {
|
|
8
|
+
return registryScript("xPixel", (options) => ({
|
|
9
|
+
scriptInput: {
|
|
10
|
+
src: "https://static.ads-twitter.com/uwt.js"
|
|
11
|
+
},
|
|
12
|
+
schema: XPixelOptions,
|
|
13
|
+
scriptOptions: {
|
|
14
|
+
use() {
|
|
15
|
+
return { twq: window.twq };
|
|
16
|
+
},
|
|
17
|
+
clientInit: import.meta.server ? void 0 : () => {
|
|
18
|
+
const s = window.twq = function(...params) {
|
|
19
|
+
s.exe ? s.exe(s, ...params) : s.queue.push(params);
|
|
20
|
+
};
|
|
21
|
+
s.version = options?.version || "1.1";
|
|
22
|
+
s.queue = [
|
|
23
|
+
["config", options?.id]
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}), _options);
|
|
28
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type YT from '@types/youtube';
|
|
2
|
+
import type { RegistryScriptInput } from '#nuxt-scripts';
|
|
3
|
+
export interface YouTubeIframeApi {
|
|
4
|
+
YT: typeof YT;
|
|
5
|
+
}
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window extends YouTubeIframeApi {
|
|
8
|
+
onYouTubeIframeAPIReady: () => void;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare const YouTubeIframeOptions: import("valibot").ObjectSchema<{}, undefined, {}>;
|
|
12
|
+
export type YouTubeIFrameInput = RegistryScriptInput<typeof YouTubeIframeOptions>;
|
|
13
|
+
export declare function useScriptYouTubeIframe<T extends YouTubeIframeApi>(_options: YouTubeIFrameInput): any;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { object } from "valibot";
|
|
2
|
+
import { registryScript } from "../utils.mjs";
|
|
3
|
+
import { useHead } from "#imports";
|
|
4
|
+
export const YouTubeIframeOptions = object({
|
|
5
|
+
// no options afaik
|
|
6
|
+
});
|
|
7
|
+
export function useScriptYouTubeIframe(_options) {
|
|
8
|
+
let readyPromise = Promise.resolve();
|
|
9
|
+
return registryScript("youtubeIframe", () => ({
|
|
10
|
+
scriptInput: {
|
|
11
|
+
src: "https://www.youtube.com/iframe_api",
|
|
12
|
+
// opt-out of privacy defaults
|
|
13
|
+
// @ts-expect-error TODO add types
|
|
14
|
+
crossorigin: null
|
|
15
|
+
},
|
|
16
|
+
schema: YouTubeIframeOptions,
|
|
17
|
+
scriptOptions: {
|
|
18
|
+
use() {
|
|
19
|
+
return {
|
|
20
|
+
YT: readyPromise.then(() => {
|
|
21
|
+
return window.YT;
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
clientInit: import.meta.server ? void 0 : () => {
|
|
26
|
+
readyPromise = new Promise((resolve) => {
|
|
27
|
+
window.onYouTubeIframeAPIReady = resolve;
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
beforeInit() {
|
|
31
|
+
useHead({
|
|
32
|
+
link: [
|
|
33
|
+
{
|
|
34
|
+
rel: "preconnect",
|
|
35
|
+
href: "https://www.youtube-nocookie.com"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
rel: "preconnect",
|
|
39
|
+
href: "https://www.google.com"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
rel: "preconnect",
|
|
43
|
+
href: "https://googleads.g.doubleclick.net"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
rel: "preconnect",
|
|
47
|
+
href: "https://static.doubleclick.net"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}), _options);
|
|
54
|
+
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -10,6 +10,13 @@ import type { FathomAnalyticsInput } from './registry/fathom-analytics';
|
|
|
10
10
|
import type { HotjarInput } from './registry/hotjar';
|
|
11
11
|
import type { IntercomInput } from './registry/intercom';
|
|
12
12
|
import type { ConfettiInput } from './registry/confetti';
|
|
13
|
+
import type { GoogleAnalyticsInput } from '~/src/runtime/registry/google-analytics';
|
|
14
|
+
import type { GoogleMapsInput } from '~/src/runtime/registry/google-maps';
|
|
15
|
+
import type { GoogleTagManagerInput } from '~/src/runtime/registry/google-tag-manager';
|
|
16
|
+
import type { MatomoAnalyticsInput } from '~/src/runtime/registry/matomo-analytics';
|
|
17
|
+
import type { StripeInput } from '~/src/runtime/registry/stripe';
|
|
18
|
+
import type { VimeoInput } from '~/src/runtime/registry/vimeo';
|
|
19
|
+
import type { XPixelInput } from '~/src/runtime/registry/x-pixel';
|
|
13
20
|
export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
14
21
|
/**
|
|
15
22
|
* The trigger to load the script:
|
|
@@ -22,14 +29,10 @@ export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'>
|
|
|
22
29
|
* Should the script be bundled as an asset and loaded from your server. This is useful for improving the
|
|
23
30
|
* performance by avoiding the extra DNS lookup and reducing the number of requests. It also
|
|
24
31
|
* improves privacy by not sharing the user's IP address with third-party servers.
|
|
25
|
-
* - `
|
|
26
|
-
* - `
|
|
32
|
+
* - `true` - Bundle the script as an asset.
|
|
33
|
+
* - `false` - Do not bundle the script. (default)
|
|
27
34
|
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* A hook to run when a script does not exist and will be initialized for the first time.
|
|
31
|
-
*/
|
|
32
|
-
beforeInit?: () => void;
|
|
35
|
+
bundle?: boolean;
|
|
33
36
|
};
|
|
34
37
|
export type NuxtUseScriptIntegrationOptions = Omit<NuxtUseScriptOptions, 'use'>;
|
|
35
38
|
export type NuxtUseScriptInput = UseScriptInput;
|
|
@@ -62,22 +65,35 @@ export interface NuxtAppScript {
|
|
|
62
65
|
at: number;
|
|
63
66
|
}[];
|
|
64
67
|
}
|
|
65
|
-
export type ScriptRegistryEntry<T> = T | [T, NuxtUseScriptOptions<T>];
|
|
68
|
+
export type ScriptRegistryEntry<T> = true | T | [T, NuxtUseScriptOptions<T>];
|
|
66
69
|
export interface ScriptRegistry {
|
|
67
70
|
cloudflareWebAnalytics?: ScriptRegistryEntry<CloudflareWebAnalyticsInput>;
|
|
68
71
|
confetti?: ScriptRegistryEntry<ConfettiInput>;
|
|
69
72
|
facebookPixel?: ScriptRegistryEntry<FacebookPixelInput>;
|
|
70
73
|
fathomAnalytics?: ScriptRegistryEntry<FathomAnalyticsInput>;
|
|
74
|
+
googleAnalytics?: ScriptRegistryEntry<GoogleAnalyticsInput>;
|
|
75
|
+
googleMaps?: ScriptRegistryEntry<GoogleMapsInput>;
|
|
76
|
+
googleTagManager?: ScriptRegistryEntry<GoogleTagManagerInput>;
|
|
71
77
|
hotjar?: ScriptRegistryEntry<HotjarInput>;
|
|
72
78
|
intercom?: ScriptRegistryEntry<IntercomInput>;
|
|
79
|
+
matomoAnalytics?: ScriptRegistryEntry<MatomoAnalyticsInput>;
|
|
73
80
|
segment?: ScriptRegistryEntry<SegmentInput>;
|
|
81
|
+
stripe?: ScriptRegistryEntry<StripeInput>;
|
|
82
|
+
vimeo?: ScriptRegistryEntry<VimeoInput>;
|
|
83
|
+
xPixel?: ScriptRegistryEntry<XPixelInput>;
|
|
74
84
|
}
|
|
75
|
-
export type
|
|
76
|
-
|
|
85
|
+
export type RegistryScriptInput<T extends ObjectSchema<any>, Bundelable extends boolean = true> = Input<T> & {
|
|
86
|
+
scriptInput?: UseScriptInput;
|
|
87
|
+
scriptOptions?: Bundelable extends true ? Omit<NuxtUseScriptOptions, 'use'> : Omit<NuxtUseScriptOptions, 'bundle' | 'use'>;
|
|
77
88
|
};
|
|
78
|
-
export type RegistryScripts =
|
|
89
|
+
export type RegistryScripts = {
|
|
90
|
+
import: Import;
|
|
91
|
+
scriptBundling?: false | ((options?: any) => string);
|
|
92
|
+
label?: string;
|
|
79
93
|
src?: string | false;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
category?: string;
|
|
95
|
+
logo?: string | {
|
|
96
|
+
light: string;
|
|
97
|
+
dark: string;
|
|
98
|
+
};
|
|
99
|
+
}[];
|
package/dist/runtime/utils.d.ts
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import type { Input, ObjectSchema } from 'valibot';
|
|
2
|
+
import type { UseScriptInput } from '@unhead/vue';
|
|
3
|
+
import type { NuxtUseScriptOptions, RegistryScriptInput } from '#nuxt-scripts';
|
|
1
4
|
export declare function mockFallbackScript(name: string, module: string): any;
|
|
5
|
+
type OptionsFn<O extends ObjectSchema<any>> = (options: Input<O>) => ({
|
|
6
|
+
scriptInput?: UseScriptInput;
|
|
7
|
+
scriptOptions?: NuxtUseScriptOptions;
|
|
8
|
+
schema?: O;
|
|
9
|
+
clientInit?: () => void;
|
|
10
|
+
});
|
|
11
|
+
export declare function registryScript<T extends Record<string | symbol, any>, O extends ObjectSchema<any>>(key: string, optionsFn: OptionsFn<O>, _userOptions?: RegistryScriptInput<O>): any;
|
|
12
|
+
export {};
|
package/dist/runtime/utils.mjs
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defu } from "defu";
|
|
2
|
+
import { parse } from "valibot";
|
|
3
|
+
import { createError, useRuntimeConfig, useScript } from "#imports";
|
|
2
4
|
export function mockFallbackScript(name, module) {
|
|
3
5
|
console.error(`${name} is provided by ${module}. Check your console to install it or run 'npx nuxi@latest module add ${module}'`);
|
|
4
6
|
return useScript("", { trigger: "manual" });
|
|
5
7
|
}
|
|
8
|
+
function validateScriptInputSchema(schema, options) {
|
|
9
|
+
if (import.meta.dev) {
|
|
10
|
+
try {
|
|
11
|
+
parse(schema, options);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
createError({
|
|
14
|
+
cause: e,
|
|
15
|
+
message: "Invalid script options"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function registryScript(key, optionsFn, _userOptions) {
|
|
21
|
+
const runtimeConfig = useRuntimeConfig().public.scripts || {};
|
|
22
|
+
const runtimeOptions = runtimeConfig[key];
|
|
23
|
+
const userOptions = Object.assign(_userOptions || {}, runtimeOptions || {});
|
|
24
|
+
const options = optionsFn(userOptions);
|
|
25
|
+
const scriptInput = defu({ key }, options.scriptInput);
|
|
26
|
+
const scriptOptions = Object.assign(_userOptions?.scriptOptions || {}, options.scriptOptions || {});
|
|
27
|
+
const init = scriptOptions.beforeInit;
|
|
28
|
+
scriptOptions.beforeInit = () => {
|
|
29
|
+
import.meta.dev && options.schema && validateScriptInputSchema(options.schema, userOptions);
|
|
30
|
+
init?.();
|
|
31
|
+
import.meta.client && options.clientInit?.();
|
|
32
|
+
};
|
|
33
|
+
return useScript(scriptInput, scriptOptions);
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/scripts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"
|
|
6
|
-
"description": "Next-gen Scripts for Nuxt",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"description": "Load third-party scripts with better performance, privacy and DX in Nuxt Apps.",
|
|
7
6
|
"author": {
|
|
8
7
|
"website": "https://harlanzw.com",
|
|
9
8
|
"name": "Harlan Wilton",
|
|
@@ -38,22 +37,29 @@
|
|
|
38
37
|
]
|
|
39
38
|
},
|
|
40
39
|
"dependencies": {
|
|
41
|
-
"@nuxt/devtools-kit": "^1.
|
|
42
|
-
"@nuxt/devtools-ui-kit": "^1.
|
|
43
|
-
"@nuxt/kit": "^3.11.
|
|
44
|
-
"@
|
|
40
|
+
"@nuxt/devtools-kit": "^1.2.0",
|
|
41
|
+
"@nuxt/devtools-ui-kit": "^1.2.0",
|
|
42
|
+
"@nuxt/kit": "^3.11.2",
|
|
43
|
+
"@types/google.maps": "^3.55.7",
|
|
44
|
+
"@types/stripe-v3": "^3.1.33",
|
|
45
|
+
"@types/vimeo__player": "^2.18.3",
|
|
46
|
+
"@types/youtube": "^0.0.50",
|
|
47
|
+
"@unhead/vue": "^1.9.7",
|
|
45
48
|
"consola": "^3.2.3",
|
|
46
49
|
"defu": "^6.1.4",
|
|
47
50
|
"estree-walker": "^3.0.3",
|
|
48
51
|
"h3": "^1.11.1",
|
|
49
|
-
"magic-string": "^0.30.
|
|
52
|
+
"magic-string": "^0.30.10",
|
|
53
|
+
"mlly": "^1.6.1",
|
|
50
54
|
"ofetch": "^1.3.4",
|
|
51
55
|
"ohash": "^1.1.3",
|
|
52
56
|
"pathe": "^1.1.2",
|
|
53
|
-
"pkg-types": "^1.0
|
|
54
|
-
"
|
|
57
|
+
"pkg-types": "^1.1.0",
|
|
58
|
+
"semver": "^7.6.0",
|
|
59
|
+
"shiki": "^1.3.0",
|
|
55
60
|
"sirv": "^2.0.4",
|
|
56
61
|
"std-env": "^3.7.0",
|
|
62
|
+
"third-party-capital": "^1.0.28",
|
|
57
63
|
"ufo": "^1.5.3",
|
|
58
64
|
"unimport": "^3.7.1",
|
|
59
65
|
"unplugin": "^1.10.1",
|
|
@@ -61,22 +67,27 @@
|
|
|
61
67
|
"valibot": "^0.30.0"
|
|
62
68
|
},
|
|
63
69
|
"devDependencies": {
|
|
64
|
-
"@antfu/eslint-config": "2.
|
|
65
|
-
"@nuxt/devtools-ui-kit": "^1.
|
|
66
|
-
"@nuxt/module-builder": "^0.
|
|
67
|
-
"@nuxt/test-utils": "3.12.
|
|
68
|
-
"@unhead/schema": "^1.9.
|
|
70
|
+
"@antfu/eslint-config": "2.15.0",
|
|
71
|
+
"@nuxt/devtools-ui-kit": "^1.2.0",
|
|
72
|
+
"@nuxt/module-builder": "^0.6.0",
|
|
73
|
+
"@nuxt/test-utils": "3.12.1",
|
|
74
|
+
"@unhead/schema": "^1.9.7",
|
|
69
75
|
"acorn-loose": "^8.4.0",
|
|
70
76
|
"bumpp": "^9.4.0",
|
|
71
|
-
"eslint": "
|
|
72
|
-
"nuxt": "^3.11.
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
+
"eslint": "9.1.1",
|
|
78
|
+
"nuxt": "^3.11.2",
|
|
79
|
+
"playwright-core": "^1.43.1",
|
|
80
|
+
"typescript": "^5.4.5",
|
|
81
|
+
"vitest": "^1.5.2",
|
|
82
|
+
"vue": "^3.4.25",
|
|
83
|
+
"vue-router": "^4.3.2"
|
|
77
84
|
},
|
|
78
85
|
"resolutions": {
|
|
79
|
-
"
|
|
86
|
+
"nuxt-scripts-devtools": "workspace:*",
|
|
87
|
+
"@nuxt/scripts": "workspace:*",
|
|
88
|
+
"nuxt": "^3.11.2",
|
|
89
|
+
"vue": "^3.4.25",
|
|
90
|
+
"vue-router": "^4.3.2"
|
|
80
91
|
},
|
|
81
92
|
"scripts": {
|
|
82
93
|
"build": "pnpm prepack",
|
|
@@ -86,7 +97,7 @@
|
|
|
86
97
|
"dev:ssl": "nuxi dev playground --https",
|
|
87
98
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
88
99
|
"typecheck": "pnpm dlx vue-tsc --noEmit",
|
|
89
|
-
"release": "pnpm build && bumpp && pnpm
|
|
100
|
+
"release": "pnpm build && bumpp && pnpm publish --no-git-checks",
|
|
90
101
|
"lint": "eslint .",
|
|
91
102
|
"lint:fix": "eslint . --fix",
|
|
92
103
|
"test": "true",
|