@nuxt/scripts 1.0.0-beta.1 → 1.0.0-beta.13
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 +6 -0
- package/dist/client/200.html +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/48AF9EJD.js +1 -0
- package/dist/client/_nuxt/Bk6ed9rg.js +1 -0
- package/dist/client/_nuxt/C4Cj8gBr.js +162 -0
- package/dist/client/_nuxt/{DTDyDxvR.js → DP0kj6Xn.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/0e95b1cc-8751-4000-8cb4-a6ef270b636f.json +1 -0
- package/dist/client/_nuxt/entry.D45OuV0w.css +1 -0
- package/dist/client/_nuxt/error-404.B57D-jUQ.css +1 -0
- package/dist/client/_nuxt/error-500.DTHUW7BI.css +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.d.mts +87 -2
- package/dist/module.d.ts +176 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +710 -273
- package/dist/registry.d.ts +6 -0
- package/dist/registry.mjs +42 -19
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.d.vue.ts +1 -1
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue +6 -6
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue.d.ts +1 -1
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsAdvancedMarkerElement.vue +6 -6
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsCircle.vue +7 -7
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsHeatmapLayer.vue +6 -6
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsInfoWindow.vue +12 -12
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarker.vue +6 -6
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.d.vue.ts +1 -1
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue +6 -6
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue.d.ts +1 -1
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPinElement.vue +5 -5
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPolygon.vue +7 -7
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPolyline.vue +7 -7
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsRectangle.vue +7 -7
- package/dist/runtime/components/ScriptCrisp.vue +1 -1
- package/dist/runtime/components/ScriptGoogleAdsense.vue +1 -1
- package/dist/runtime/components/ScriptInstagramEmbed.d.vue.ts +53 -0
- package/dist/runtime/components/ScriptInstagramEmbed.vue +38 -0
- package/dist/runtime/components/ScriptInstagramEmbed.vue.d.ts +53 -0
- package/dist/runtime/components/ScriptIntercom.vue +4 -3
- package/dist/runtime/components/ScriptLoadingIndicator.d.vue.ts +1 -1
- package/dist/runtime/components/ScriptLoadingIndicator.vue.d.ts +1 -1
- package/dist/runtime/components/ScriptPayPalButtons.d.vue.ts +2 -2
- package/dist/runtime/components/ScriptPayPalButtons.vue +13 -11
- package/dist/runtime/components/ScriptPayPalButtons.vue.d.ts +2 -2
- package/dist/runtime/components/ScriptPayPalMarks.d.vue.ts +2 -2
- package/dist/runtime/components/ScriptPayPalMarks.vue +10 -8
- package/dist/runtime/components/ScriptPayPalMarks.vue.d.ts +2 -2
- package/dist/runtime/components/ScriptPayPalMessages.d.vue.ts +2 -2
- package/dist/runtime/components/ScriptPayPalMessages.vue +11 -9
- package/dist/runtime/components/ScriptPayPalMessages.vue.d.ts +2 -2
- package/dist/runtime/components/ScriptStripePricingTable.vue +2 -2
- package/dist/runtime/components/ScriptVimeoPlayer.vue +1 -1
- package/dist/runtime/components/ScriptXEmbed.d.vue.ts +82 -0
- package/dist/runtime/components/ScriptXEmbed.vue +76 -0
- package/dist/runtime/components/ScriptXEmbed.vue.d.ts +82 -0
- package/dist/runtime/components/ScriptYouTubePlayer.vue +7 -4
- package/dist/runtime/composables/useScript.js +32 -6
- package/dist/runtime/composables/useScriptEventPage.js +2 -2
- package/dist/runtime/composables/useScriptTriggerConsent.js +1 -1
- package/dist/runtime/composables/useScriptTriggerElement.js +1 -1
- package/dist/runtime/composables/useScriptTriggerIdleTimeout.js +1 -1
- package/dist/runtime/composables/useScriptTriggerServiceWorker.d.ts +7 -0
- package/dist/runtime/composables/useScriptTriggerServiceWorker.js +39 -0
- package/dist/runtime/registry/clarity.js +21 -25
- package/dist/runtime/registry/cloudflare-web-analytics.js +1 -1
- package/dist/runtime/registry/crisp.js +1 -1
- package/dist/runtime/registry/databuddy-analytics.js +1 -1
- package/dist/runtime/registry/fathom-analytics.js +1 -1
- package/dist/runtime/registry/google-adsense.js +1 -1
- package/dist/runtime/registry/google-analytics.js +2 -2
- package/dist/runtime/registry/google-maps.d.ts +1 -1
- package/dist/runtime/registry/google-maps.js +1 -1
- package/dist/runtime/registry/google-recaptcha.js +2 -2
- package/dist/runtime/registry/google-sign-in.js +1 -1
- package/dist/runtime/registry/google-tag-manager.d.ts +1 -1
- package/dist/runtime/registry/google-tag-manager.js +2 -2
- package/dist/runtime/registry/hotjar.js +1 -1
- package/dist/runtime/registry/instagram-embed.d.ts +23 -0
- package/dist/runtime/registry/instagram-embed.js +22 -0
- package/dist/runtime/registry/intercom.js +1 -1
- package/dist/runtime/registry/lemon-squeezy.d.ts +0 -1
- package/dist/runtime/registry/matomo-analytics.js +2 -2
- package/dist/runtime/registry/meta-pixel.js +1 -1
- package/dist/runtime/registry/npm.js +1 -1
- package/dist/runtime/registry/paypal.d.ts +1 -1
- package/dist/runtime/registry/paypal.js +2 -2
- package/dist/runtime/registry/plausible-analytics.js +15 -9
- package/dist/runtime/registry/posthog.d.ts +3 -2
- package/dist/runtime/registry/posthog.js +8 -12
- package/dist/runtime/registry/reddit-pixel.js +1 -1
- package/dist/runtime/registry/rybbit-analytics.js +5 -3
- package/dist/runtime/registry/segment.js +1 -1
- package/dist/runtime/registry/snapchat-pixel.js +1 -1
- package/dist/runtime/registry/stripe.d.ts +1 -1
- package/dist/runtime/registry/stripe.js +1 -1
- package/dist/runtime/registry/tiktok-pixel.d.ts +1 -0
- package/dist/runtime/registry/tiktok-pixel.js +2 -1
- package/dist/runtime/registry/umami-analytics.js +1 -1
- package/dist/runtime/registry/vimeo-player.d.ts +2 -2
- package/dist/runtime/registry/vimeo-player.js +1 -1
- package/dist/runtime/registry/x-embed.d.ts +77 -0
- package/dist/runtime/registry/x-embed.js +41 -0
- package/dist/runtime/registry/x-pixel.js +1 -1
- package/dist/runtime/registry/youtube-player.d.ts +7 -7
- package/dist/runtime/registry/youtube-player.js +1 -1
- package/dist/runtime/server/google-static-maps-proxy.js +1 -1
- package/dist/runtime/server/instagram-embed-asset.d.ts +2 -0
- package/dist/runtime/server/instagram-embed-asset.js +42 -0
- package/dist/runtime/server/instagram-embed-image.d.ts +2 -0
- package/dist/runtime/server/instagram-embed-image.js +54 -0
- package/dist/runtime/server/instagram-embed.d.ts +2 -0
- package/dist/runtime/server/instagram-embed.js +91 -0
- package/dist/runtime/server/proxy-handler.d.ts +6 -0
- package/dist/runtime/server/proxy-handler.js +264 -0
- package/dist/runtime/server/utils/privacy.d.ts +141 -0
- package/dist/runtime/server/utils/privacy.js +324 -0
- package/dist/runtime/server/x-embed-image.d.ts +2 -0
- package/dist/runtime/server/x-embed-image.js +53 -0
- package/dist/runtime/server/x-embed.d.ts +49 -0
- package/dist/runtime/server/x-embed.js +31 -0
- package/dist/runtime/types.d.ts +51 -22
- package/dist/runtime/utils/pure.d.ts +9 -0
- package/dist/runtime/utils/pure.js +0 -0
- package/dist/runtime/utils.d.ts +3 -3
- package/dist/runtime/utils.js +3 -2
- package/dist/shared/scripts.DLRgvHQg.mjs +288 -0
- package/dist/stats.d.mts +39 -0
- package/dist/stats.d.ts +39 -0
- package/dist/stats.mjs +711 -0
- package/dist/types.d.mts +1 -1
- package/package.json +48 -41
- package/dist/client/_nuxt/Bdf7Qtwg.js +0 -1
- package/dist/client/_nuxt/CoyZWCgl.js +0 -162
- package/dist/client/_nuxt/Ds1k3yKJ.js +0 -1
- package/dist/client/_nuxt/builds/meta/62574f80-71d4-4f9e-8b96-145c85230d99.json +0 -1
- package/dist/client/_nuxt/entry.BjfcJo5q.css +0 -1
- package/dist/client/_nuxt/error-404.D45Vtjcx.css +0 -1
- package/dist/client/_nuxt/error-500.BOm1rWQf.css +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { useAsyncData } from "nuxt/app";
|
|
3
|
+
import { computed } from "vue";
|
|
4
|
+
import { formatCount, formatTweetDate, proxyXImageUrl } from "../registry/x-embed";
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
tweetId: { type: String, required: true },
|
|
7
|
+
apiEndpoint: { type: String, required: false, default: "/api/_scripts/x-embed" },
|
|
8
|
+
imageProxyEndpoint: { type: String, required: false, default: "/api/_scripts/x-embed-image" },
|
|
9
|
+
rootAttrs: { type: Object, required: false }
|
|
10
|
+
});
|
|
11
|
+
const cacheKey = computed(() => `x-embed-${props.tweetId}`);
|
|
12
|
+
const { data: tweet, status, error } = useAsyncData(
|
|
13
|
+
cacheKey,
|
|
14
|
+
() => $fetch(`${props.apiEndpoint}?id=${props.tweetId}`)
|
|
15
|
+
);
|
|
16
|
+
const slotProps = computed(() => {
|
|
17
|
+
if (!tweet.value)
|
|
18
|
+
return null;
|
|
19
|
+
const t = tweet.value;
|
|
20
|
+
return {
|
|
21
|
+
// Raw data
|
|
22
|
+
tweet: t,
|
|
23
|
+
// User info
|
|
24
|
+
userName: t.user.name,
|
|
25
|
+
userHandle: t.user.screen_name,
|
|
26
|
+
userAvatar: proxyXImageUrl(t.user.profile_image_url_https, props.imageProxyEndpoint),
|
|
27
|
+
userAvatarOriginal: t.user.profile_image_url_https,
|
|
28
|
+
isVerified: t.user.verified || t.user.is_blue_verified,
|
|
29
|
+
// Tweet content
|
|
30
|
+
text: t.text,
|
|
31
|
+
// Formatted values
|
|
32
|
+
datetime: formatTweetDate(t.created_at),
|
|
33
|
+
createdAt: new Date(t.created_at),
|
|
34
|
+
likes: t.favorite_count,
|
|
35
|
+
likesFormatted: formatCount(t.favorite_count),
|
|
36
|
+
replies: t.conversation_count,
|
|
37
|
+
repliesFormatted: formatCount(t.conversation_count),
|
|
38
|
+
// Media
|
|
39
|
+
photos: t.photos?.map((p) => ({
|
|
40
|
+
...p,
|
|
41
|
+
proxiedUrl: proxyXImageUrl(p.url, props.imageProxyEndpoint)
|
|
42
|
+
})),
|
|
43
|
+
video: t.video ? {
|
|
44
|
+
...t.video,
|
|
45
|
+
posterProxied: proxyXImageUrl(t.video.poster, props.imageProxyEndpoint)
|
|
46
|
+
} : null,
|
|
47
|
+
// Links
|
|
48
|
+
tweetUrl: `https://x.com/${t.user.screen_name}/status/${t.id_str}`,
|
|
49
|
+
userUrl: `https://x.com/${t.user.screen_name}`,
|
|
50
|
+
// Quoted tweet
|
|
51
|
+
quotedTweet: t.quoted_tweet,
|
|
52
|
+
// Reply context
|
|
53
|
+
isReply: !!t.parent,
|
|
54
|
+
replyToUser: t.parent?.user.screen_name,
|
|
55
|
+
// Helpers
|
|
56
|
+
proxyImage: (url) => proxyXImageUrl(url, props.imageProxyEndpoint)
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
defineExpose({
|
|
60
|
+
tweet,
|
|
61
|
+
status,
|
|
62
|
+
error
|
|
63
|
+
});
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<div v-bind="rootAttrs">
|
|
68
|
+
<slot v-if="status === 'pending'" name="loading">
|
|
69
|
+
<div>Loading tweet...</div>
|
|
70
|
+
</slot>
|
|
71
|
+
<slot v-else-if="status === 'error'" name="error" :error="error">
|
|
72
|
+
<div>Failed to load tweet</div>
|
|
73
|
+
</slot>
|
|
74
|
+
<slot v-else-if="slotProps" v-bind="slotProps" />
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'vue';
|
|
2
|
+
import type { XEmbedTweetData } from '../registry/x-embed.js';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
/**
|
|
5
|
+
* The tweet ID to embed
|
|
6
|
+
*/
|
|
7
|
+
tweetId: string;
|
|
8
|
+
/**
|
|
9
|
+
* Custom API endpoint for fetching tweet data
|
|
10
|
+
* @default '/_scripts/x-embed'
|
|
11
|
+
*/
|
|
12
|
+
apiEndpoint?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Custom image proxy endpoint
|
|
15
|
+
* @default '/_scripts/x-embed-image'
|
|
16
|
+
*/
|
|
17
|
+
imageProxyEndpoint?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Root element attributes
|
|
20
|
+
*/
|
|
21
|
+
rootAttrs?: HTMLAttributes;
|
|
22
|
+
};
|
|
23
|
+
declare var __VLS_1: {}, __VLS_3: {
|
|
24
|
+
error: import("nuxt/app").NuxtError<unknown> | undefined;
|
|
25
|
+
}, __VLS_5: {
|
|
26
|
+
tweet: XEmbedTweetData;
|
|
27
|
+
userName: string;
|
|
28
|
+
userHandle: string;
|
|
29
|
+
userAvatar: string;
|
|
30
|
+
userAvatarOriginal: string;
|
|
31
|
+
isVerified: boolean | undefined;
|
|
32
|
+
text: string;
|
|
33
|
+
datetime: string;
|
|
34
|
+
createdAt: Date;
|
|
35
|
+
likes: number;
|
|
36
|
+
likesFormatted: string;
|
|
37
|
+
replies: number;
|
|
38
|
+
repliesFormatted: string;
|
|
39
|
+
photos: {
|
|
40
|
+
proxiedUrl: string;
|
|
41
|
+
url: string;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
}[] | undefined;
|
|
45
|
+
video: {
|
|
46
|
+
posterProxied: string;
|
|
47
|
+
poster: string;
|
|
48
|
+
variants: Array<{
|
|
49
|
+
type: string;
|
|
50
|
+
src: string;
|
|
51
|
+
}>;
|
|
52
|
+
} | null;
|
|
53
|
+
tweetUrl: string;
|
|
54
|
+
userUrl: string;
|
|
55
|
+
quotedTweet: XEmbedTweetData | undefined;
|
|
56
|
+
isReply: boolean;
|
|
57
|
+
replyToUser: string | undefined;
|
|
58
|
+
proxyImage: (url: string) => string;
|
|
59
|
+
};
|
|
60
|
+
type __VLS_Slots = {} & {
|
|
61
|
+
loading?: (props: typeof __VLS_1) => any;
|
|
62
|
+
} & {
|
|
63
|
+
error?: (props: typeof __VLS_3) => any;
|
|
64
|
+
} & {
|
|
65
|
+
default?: (props: typeof __VLS_5) => any;
|
|
66
|
+
};
|
|
67
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
68
|
+
tweet: import("vue").Ref<XEmbedTweetData | undefined, XEmbedTweetData | undefined>;
|
|
69
|
+
status: import("vue").Ref<import("nuxt/app").AsyncDataRequestStatus, import("nuxt/app").AsyncDataRequestStatus>;
|
|
70
|
+
error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | undefined, import("nuxt/app").NuxtError<unknown> | undefined>;
|
|
71
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
72
|
+
apiEndpoint: string;
|
|
73
|
+
imageProxyEndpoint: string;
|
|
74
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
75
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
76
|
+
declare const _default: typeof __VLS_export;
|
|
77
|
+
export default _default;
|
|
78
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
79
|
+
new (): {
|
|
80
|
+
$slots: S;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
3
2
|
import { defu } from "defu";
|
|
4
3
|
import { useHead } from "nuxt/app";
|
|
4
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
5
5
|
import { useScriptTriggerElement } from "../composables/useScriptTriggerElement";
|
|
6
6
|
import { useScriptYouTubePlayer } from "../registry/youtube-player";
|
|
7
7
|
import ScriptAriaLoadingIndicator from "./ScriptAriaLoadingIndicator.vue";
|
|
@@ -70,9 +70,11 @@ onMounted(() => {
|
|
|
70
70
|
onLoaded(async (instance) => {
|
|
71
71
|
if (!isTriggered.value && trigger instanceof Promise) {
|
|
72
72
|
const triggered = await trigger;
|
|
73
|
-
if (!triggered)
|
|
73
|
+
if (!triggered)
|
|
74
|
+
return;
|
|
74
75
|
}
|
|
75
|
-
if (!youtubeEl.value)
|
|
76
|
+
if (!youtubeEl.value)
|
|
77
|
+
return;
|
|
76
78
|
const YouTube = instance.YT instanceof Promise ? await instance.YT : instance.YT;
|
|
77
79
|
await new Promise((resolve) => {
|
|
78
80
|
if (typeof YT.Player === "undefined")
|
|
@@ -80,7 +82,8 @@ onMounted(() => {
|
|
|
80
82
|
else
|
|
81
83
|
resolve();
|
|
82
84
|
});
|
|
83
|
-
if (!youtubeEl.value)
|
|
85
|
+
if (!youtubeEl.value)
|
|
86
|
+
return;
|
|
84
87
|
player.value = new YT.Player(youtubeEl.value, {
|
|
85
88
|
host: !props.cookies ? "https://www.youtube-nocookie.com" : "https://www.youtube.com",
|
|
86
89
|
videoId: props.videoId,
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveTrigger } from "#build/nuxt-scripts-trigger-resolver";
|
|
2
2
|
import { useScript as _useScript } from "@unhead/vue/scripts";
|
|
3
|
-
import {
|
|
4
|
-
import { onNuxtReady, useNuxtApp, useRuntimeConfig
|
|
3
|
+
import { defu } from "defu";
|
|
4
|
+
import { injectHead, onNuxtReady, useHead, useNuxtApp, useRuntimeConfig } from "nuxt/app";
|
|
5
|
+
import { ref } from "vue";
|
|
5
6
|
import { logger } from "../logger.js";
|
|
6
|
-
|
|
7
|
+
function ensureScripts(nuxtApp) {
|
|
8
|
+
if (!nuxtApp.$scripts) {
|
|
9
|
+
nuxtApp.$scripts = {};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
7
12
|
function useNuxtScriptRuntimeConfig() {
|
|
8
13
|
return useRuntimeConfig().public["nuxt-scripts"];
|
|
9
14
|
}
|
|
@@ -13,6 +18,27 @@ export function resolveScriptKey(input) {
|
|
|
13
18
|
export function useScript(input, options) {
|
|
14
19
|
input = typeof input === "string" ? { src: input } : input;
|
|
15
20
|
options = defu(options, useNuxtScriptRuntimeConfig()?.defaultScriptOptions);
|
|
21
|
+
if (options.partytown) {
|
|
22
|
+
const src = input.src;
|
|
23
|
+
if (!src) {
|
|
24
|
+
throw new Error("useScript with partytown requires a src");
|
|
25
|
+
}
|
|
26
|
+
useHead({
|
|
27
|
+
script: [{ src, type: "text/partytown" }]
|
|
28
|
+
});
|
|
29
|
+
const nuxtApp2 = useNuxtApp();
|
|
30
|
+
ensureScripts(nuxtApp2);
|
|
31
|
+
const status = ref("loaded");
|
|
32
|
+
const stub = {
|
|
33
|
+
id: src,
|
|
34
|
+
status,
|
|
35
|
+
load: () => Promise.resolve({}),
|
|
36
|
+
remove: () => false,
|
|
37
|
+
entry: void 0
|
|
38
|
+
};
|
|
39
|
+
nuxtApp2.$scripts[src] = stub;
|
|
40
|
+
return stub;
|
|
41
|
+
}
|
|
16
42
|
if (import.meta.dev && options.bundle === "unsupported") {
|
|
17
43
|
console.warn("[Nuxt Scripts] Bundling is not supported for dynamic script sources. Static URLs are required for bundling.");
|
|
18
44
|
options.bundle = false;
|
|
@@ -23,13 +49,13 @@ export function useScript(input, options) {
|
|
|
23
49
|
options.trigger = resolved;
|
|
24
50
|
}
|
|
25
51
|
}
|
|
26
|
-
const id = String(resolveScriptKey(input));
|
|
27
52
|
const nuxtApp = useNuxtApp();
|
|
53
|
+
const id = String(resolveScriptKey(input));
|
|
28
54
|
options.head = options.head || injectHead();
|
|
29
55
|
if (!options.head) {
|
|
30
56
|
throw new Error("useScript() has been called without Nuxt context.");
|
|
31
57
|
}
|
|
32
|
-
nuxtApp
|
|
58
|
+
ensureScripts(nuxtApp);
|
|
33
59
|
const exists = !!nuxtApp.$scripts?.[id];
|
|
34
60
|
const err = options._validate?.();
|
|
35
61
|
if (import.meta.dev && import.meta.client && err) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useNuxtApp, useRoute
|
|
2
|
-
import {
|
|
1
|
+
import { injectHead, useNuxtApp, useRoute } from "nuxt/app";
|
|
2
|
+
import { onScopeDispose, ref } from "vue";
|
|
3
3
|
export function useScriptEventPage(onChange) {
|
|
4
4
|
const nuxt = useNuxtApp();
|
|
5
5
|
const route = useRoute();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { onNuxtReady, requestIdleCallback, tryUseNuxtApp } from "nuxt/app";
|
|
1
2
|
import { isRef, ref, toValue, watch } from "vue";
|
|
2
|
-
import { tryUseNuxtApp, onNuxtReady, requestIdleCallback } from "nuxt/app";
|
|
3
3
|
export function useScriptTriggerConsent(options) {
|
|
4
4
|
if (import.meta.server)
|
|
5
5
|
return new Promise(() => {
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
useEventListener,
|
|
3
3
|
useIntersectionObserver
|
|
4
4
|
} from "@vueuse/core";
|
|
5
|
-
import {
|
|
5
|
+
import { tryOnMounted, tryOnScopeDispose } from "@vueuse/shared";
|
|
6
6
|
import { watch } from "vue";
|
|
7
7
|
function useElementVisibilityPromise(element) {
|
|
8
8
|
let observer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { tryOnScopeDispose } from "@vueuse/shared";
|
|
2
1
|
import { useTimeoutFn } from "@vueuse/core";
|
|
2
|
+
import { tryOnScopeDispose } from "@vueuse/shared";
|
|
3
3
|
import { onNuxtReady } from "nuxt/app";
|
|
4
4
|
export function useScriptTriggerIdleTimeout(options) {
|
|
5
5
|
if (import.meta.server) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a trigger that loads a script after the service worker is controlling the page.
|
|
3
|
+
* Falls back to immediate loading if service workers are not supported or after timeout.
|
|
4
|
+
*/
|
|
5
|
+
export declare function useScriptTriggerServiceWorker(options?: {
|
|
6
|
+
timeout?: number;
|
|
7
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { tryOnScopeDispose } from "@vueuse/shared";
|
|
2
|
+
export function useScriptTriggerServiceWorker(options) {
|
|
3
|
+
if (import.meta.server)
|
|
4
|
+
return new Promise(() => {
|
|
5
|
+
});
|
|
6
|
+
const timeout = options?.timeout ?? 3e3;
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
if (!("serviceWorker" in navigator)) {
|
|
9
|
+
resolve(true);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let resolved = false;
|
|
13
|
+
const done = () => {
|
|
14
|
+
if (resolved)
|
|
15
|
+
return;
|
|
16
|
+
resolved = true;
|
|
17
|
+
resolve(true);
|
|
18
|
+
};
|
|
19
|
+
if (navigator.serviceWorker.controller) {
|
|
20
|
+
done();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const onControllerChange = () => {
|
|
24
|
+
navigator.serviceWorker.removeEventListener("controllerchange", onControllerChange);
|
|
25
|
+
done();
|
|
26
|
+
};
|
|
27
|
+
navigator.serviceWorker.addEventListener("controllerchange", onControllerChange);
|
|
28
|
+
const timer = setTimeout(() => {
|
|
29
|
+
navigator.serviceWorker.removeEventListener("controllerchange", onControllerChange);
|
|
30
|
+
console.warn("[nuxt-scripts] Service worker not controlling after timeout, loading scripts anyway");
|
|
31
|
+
done();
|
|
32
|
+
}, timeout);
|
|
33
|
+
tryOnScopeDispose(() => {
|
|
34
|
+
navigator.serviceWorker.removeEventListener("controllerchange", onControllerChange);
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
resolve(false);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { minLength, object, pipe, string } from "#nuxt-scripts-validator";
|
|
1
2
|
import { useRegistryScript } from "../utils.js";
|
|
2
|
-
import { minLength, object, string, pipe } from "#nuxt-scripts-validator";
|
|
3
3
|
export const ClarityOptions = object({
|
|
4
4
|
/**
|
|
5
5
|
* The Clarity token.
|
|
@@ -7,30 +7,26 @@ export const ClarityOptions = object({
|
|
|
7
7
|
id: pipe(string(), minLength(10))
|
|
8
8
|
});
|
|
9
9
|
export function useScriptClarity(_options) {
|
|
10
|
-
return useRegistryScript(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
clarity
|
|
22
|
-
|
|
23
|
-
return clarity.apply(this, params);
|
|
24
|
-
}, window.clarity)
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
clientInit: import.meta.server ? void 0 : () => {
|
|
29
|
-
window.clarity = window.clarity || function(...params) {
|
|
30
|
-
(window.clarity.q = window.clarity.q || []).push(params);
|
|
10
|
+
return useRegistryScript("clarity", (options) => ({
|
|
11
|
+
scriptInput: {
|
|
12
|
+
src: `https://www.clarity.ms/tag/${options.id}`
|
|
13
|
+
},
|
|
14
|
+
schema: import.meta.dev ? ClarityOptions : void 0,
|
|
15
|
+
scriptOptions: {
|
|
16
|
+
use() {
|
|
17
|
+
return {
|
|
18
|
+
// @ts-expect-error untyped
|
|
19
|
+
clarity: Object.assign(function(...params) {
|
|
20
|
+
const clarity = window.clarity;
|
|
21
|
+
return clarity.apply(this, params);
|
|
22
|
+
}, window.clarity)
|
|
31
23
|
};
|
|
32
24
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
},
|
|
26
|
+
clientInit: import.meta.server ? void 0 : () => {
|
|
27
|
+
window.clarity = window.clarity || function(...params) {
|
|
28
|
+
(window.clarity.q = window.clarity.q || []).push(params);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}), _options);
|
|
36
32
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRegistryScript } from "../utils.js";
|
|
2
1
|
import { boolean, minLength, object, optional, pipe, string } from "#nuxt-scripts-validator";
|
|
2
|
+
import { useRegistryScript } from "../utils.js";
|
|
3
3
|
export const CloudflareWebAnalyticsOptions = object({
|
|
4
4
|
/**
|
|
5
5
|
* The Cloudflare Web Analytics token.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { boolean, number, object, optional, string } from "#nuxt-scripts-validator";
|
|
1
2
|
import { useRegistryScript } from "../utils.js";
|
|
2
|
-
import { object, optional, string, boolean, number } from "#nuxt-scripts-validator";
|
|
3
3
|
export const DatabuddyAnalyticsOptions = object({
|
|
4
4
|
// Required
|
|
5
5
|
clientId: string(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRegistryScript } from "../utils.js";
|
|
2
1
|
import { boolean, literal, object, optional, string, union } from "#nuxt-scripts-validator";
|
|
2
|
+
import { useRegistryScript } from "../utils.js";
|
|
3
3
|
export const FathomAnalyticsOptions = object({
|
|
4
4
|
/**
|
|
5
5
|
* The Fathom Analytics site ID.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { boolean, object, optional, string } from "#nuxt-scripts-validator";
|
|
1
2
|
import { useHead } from "nuxt/app";
|
|
2
3
|
import { useRegistryScript } from "../utils.js";
|
|
3
|
-
import { object, string, optional, boolean } from "#nuxt-scripts-validator";
|
|
4
4
|
export const GoogleAdsenseOptions = object({
|
|
5
5
|
/**
|
|
6
6
|
* The Google Adsense ID.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { object, optional, string } from "#nuxt-scripts-validator";
|
|
2
2
|
import { useRegistryScript } from "#nuxt-scripts/utils";
|
|
3
|
-
import {
|
|
3
|
+
import { withQuery } from "ufo";
|
|
4
4
|
export const GoogleAnalyticsOptions = object({
|
|
5
5
|
id: optional(string()),
|
|
6
6
|
// The GA4 measurement ID (format: G-XXXXXXXX)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { array, literal, object, optional, string, union } from "#nuxt-scripts-validator";
|
|
1
2
|
import { withQuery } from "ufo";
|
|
2
3
|
import { useRegistryScript } from "../utils.js";
|
|
3
|
-
import { array, literal, object, optional, string, union } from "#nuxt-scripts-validator";
|
|
4
4
|
export const GoogleMapsOptions = object({
|
|
5
5
|
apiKey: string(),
|
|
6
6
|
libraries: optional(array(string())),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { boolean, object, optional, string } from "#nuxt-scripts-validator";
|
|
2
2
|
import { useRegistryScript } from "#nuxt-scripts/utils";
|
|
3
|
-
import {
|
|
3
|
+
import { withQuery } from "ufo";
|
|
4
4
|
export const GoogleRecaptchaOptions = object({
|
|
5
5
|
siteKey: string(),
|
|
6
6
|
// Use enterprise.js instead of api.js
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { array, boolean, literal, object, optional, string, union } from "#nuxt-scripts-validator";
|
|
1
2
|
import { useRegistryScript } from "#nuxt-scripts/utils";
|
|
2
|
-
import { object, string, optional, boolean, array, union, literal } from "#nuxt-scripts-validator";
|
|
3
3
|
export const GoogleSignInOptions = object({
|
|
4
4
|
clientId: string(),
|
|
5
5
|
// Auto-select credentials if only one is available
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GTag } from './google-analytics.js';
|
|
2
1
|
import type { NuxtUseScriptOptions, RegistryScriptInput, UseFunctionType, UseScriptContext } from '#nuxt-scripts/types';
|
|
2
|
+
import type { GTag } from './google-analytics.js';
|
|
3
3
|
/**
|
|
4
4
|
* Improved DataLayer type that better reflects GTM's capabilities
|
|
5
5
|
* Can contain either gtag event parameters or custom data objects
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { boolean, literal, number, object, optional, record, string, union } from "#nuxt-scripts-validator";
|
|
2
2
|
import { useRegistryScript } from "#nuxt-scripts/utils";
|
|
3
|
-
import {
|
|
3
|
+
import { withQuery } from "ufo";
|
|
4
4
|
export const GoogleTagManagerOptions = object({
|
|
5
5
|
/** GTM container ID (format: GTM-XXXXXX) */
|
|
6
6
|
id: string(),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RegistryScriptInput } from '#nuxt-scripts/types';
|
|
2
|
+
export declare const InstagramEmbedOptions: import("valibot").ObjectSchema<{
|
|
3
|
+
/**
|
|
4
|
+
* The Instagram post URL to embed
|
|
5
|
+
* e.g., https://www.instagram.com/p/ABC123/
|
|
6
|
+
*/
|
|
7
|
+
readonly postUrl: import("valibot").StringSchema<undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to include captions in the embed
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
readonly captions: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Custom API endpoint for fetching embed HTML
|
|
15
|
+
* @default '/api/_scripts/instagram-embed'
|
|
16
|
+
*/
|
|
17
|
+
readonly apiEndpoint: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
18
|
+
}, undefined>;
|
|
19
|
+
export type InstagramEmbedInput = RegistryScriptInput<typeof InstagramEmbedOptions, false, false, false>;
|
|
20
|
+
/**
|
|
21
|
+
* Extract the post shortcode from an Instagram URL
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractInstagramShortcode(url: string): string | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { boolean, object, optional, string } from "#nuxt-scripts-validator";
|
|
2
|
+
export const InstagramEmbedOptions = object({
|
|
3
|
+
/**
|
|
4
|
+
* The Instagram post URL to embed
|
|
5
|
+
* e.g., https://www.instagram.com/p/ABC123/
|
|
6
|
+
*/
|
|
7
|
+
postUrl: string(),
|
|
8
|
+
/**
|
|
9
|
+
* Whether to include captions in the embed
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
captions: optional(boolean()),
|
|
13
|
+
/**
|
|
14
|
+
* Custom API endpoint for fetching embed HTML
|
|
15
|
+
* @default '/api/_scripts/instagram-embed'
|
|
16
|
+
*/
|
|
17
|
+
apiEndpoint: optional(string())
|
|
18
|
+
});
|
|
19
|
+
export function extractInstagramShortcode(url) {
|
|
20
|
+
const match = url.match(/instagram\.com\/(?:p|reel|tv)\/([^/?]+)/);
|
|
21
|
+
return match?.[1];
|
|
22
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { literal, number, object, optional, string, union } from "#nuxt-scripts-validator";
|
|
1
2
|
import { joinURL } from "ufo";
|
|
2
3
|
import { useRegistryScript } from "../utils.js";
|
|
3
|
-
import { literal, number, object, optional, string, union } from "#nuxt-scripts-validator";
|
|
4
4
|
export const IntercomOptions = object({
|
|
5
5
|
app_id: string(),
|
|
6
6
|
api_base: optional(union([literal("https://api-iam.intercom.io"), literal("https://api-iam.eu.intercom.io"), literal("https://api-iam.au.intercom.io")])),
|
|
@@ -21,7 +21,6 @@ export type LemonSqueezyEventPayload = {
|
|
|
21
21
|
export interface LemonSqueezyApi {
|
|
22
22
|
/**
|
|
23
23
|
* Initialises Lemon.js on your page.
|
|
24
|
-
* @param options - An object with a single property, eventHandler, which is a function that will be called when Lemon.js emits an event.
|
|
25
24
|
*/
|
|
26
25
|
Setup: (options: {
|
|
27
26
|
eventHandler: (event: LemonSqueezyEventPayload) => void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { boolean, number, object, optional, string, union } from "#nuxt-scripts-validator";
|
|
1
2
|
import { withBase, withHttps, withoutProtocol, withoutTrailingSlash } from "ufo";
|
|
2
|
-
import { useRegistryScript } from "../utils.js";
|
|
3
3
|
import { useScriptEventPage } from "../composables/useScriptEventPage.js";
|
|
4
|
-
import { boolean, object, optional, string, number, union } from "#nuxt-scripts-validator";
|
|
5
4
|
import { logger } from "../logger.js";
|
|
5
|
+
import { useRegistryScript } from "../utils.js";
|
|
6
6
|
export const MatomoAnalyticsOptions = object({
|
|
7
7
|
matomoUrl: optional(string()),
|
|
8
8
|
siteId: optional(union([string(), number()])),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { literal, object, optional, string, union } from "#nuxt-scripts-validator";
|
|
1
2
|
import { withBase } from "ufo";
|
|
2
3
|
import { useRegistryScript } from "../utils.js";
|
|
3
|
-
import { object, optional, string, union, literal } from "#nuxt-scripts-validator";
|
|
4
4
|
const PROVIDERS = ["jsdelivr", "cdnjs", "unpkg"];
|
|
5
5
|
const providerValidator = union(PROVIDERS.map((provider) => literal(provider)));
|
|
6
6
|
export const NpmOptions = object({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { array, boolean, object, optional, string, union } from "#nuxt-scripts-validator";
|
|
1
2
|
import { withQuery } from "ufo";
|
|
2
3
|
import { useRegistryScript } from "../utils.js";
|
|
3
|
-
import { object, string, optional, array, union, boolean } from "#nuxt-scripts-validator";
|
|
4
4
|
export const PayPalOptions = object({
|
|
5
5
|
clientId: string(),
|
|
6
6
|
buyerCountry: optional(string()),
|
|
@@ -27,7 +27,7 @@ export const PayPalOptions = object({
|
|
|
27
27
|
});
|
|
28
28
|
export function useScriptPayPal(_options) {
|
|
29
29
|
return useRegistryScript("paypal", (options) => {
|
|
30
|
-
let dataMerchantId
|
|
30
|
+
let dataMerchantId;
|
|
31
31
|
if (Array.isArray(options?.merchantId) && options?.merchantId.length > 1) {
|
|
32
32
|
dataMerchantId = JSON.stringify(options.merchantId);
|
|
33
33
|
options.merchantId = "*";
|