@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.
Files changed (63) hide show
  1. package/dist/client/200.html +5 -5
  2. package/dist/client/404.html +5 -5
  3. package/dist/client/_nuxt/{B-3dzucQ.js → B-VcbH-p.js} +1 -1
  4. package/dist/client/_nuxt/{CmaBlQfy.js → Da7ySKCR.js} +1 -1
  5. package/dist/client/_nuxt/Duz6zLk8.js +31 -0
  6. package/dist/client/_nuxt/builds/latest.json +1 -1
  7. package/dist/client/_nuxt/builds/meta/ce1e7798-e27a-4397-9734-cd67ecbfb4ca.json +1 -0
  8. package/dist/client/_nuxt/{D-T6Aidr.js → enpXmyCL.js} +1 -1
  9. package/dist/client/index.html +5 -5
  10. package/dist/module.d.mts +2 -2
  11. package/dist/module.d.ts +2 -2
  12. package/dist/module.json +1 -1
  13. package/dist/module.mjs +67 -36
  14. package/dist/registry.d.mts +2 -2
  15. package/dist/registry.d.ts +2 -2
  16. package/dist/registry.mjs +16 -16
  17. package/dist/runtime/components/ScriptGoogleMaps.vue +264 -0
  18. package/dist/runtime/components/ScriptLemonSqueezyButton.vue +42 -0
  19. package/dist/runtime/components/ScriptLoadingIndicator.vue +15 -0
  20. package/dist/runtime/components/ScriptStripePricingTable.vue +47 -0
  21. package/dist/runtime/components/ScriptVimeoPlayer.vue +243 -0
  22. package/dist/runtime/components/ScriptYouTubePlayer.vue +160 -0
  23. package/dist/runtime/composables/useElementScriptTrigger.d.ts +3 -3
  24. package/dist/runtime/composables/useElementScriptTrigger.mjs +41 -5
  25. package/dist/runtime/composables/useScript.d.ts +1 -1
  26. package/dist/runtime/composables/useScript.mjs +7 -6
  27. package/dist/runtime/registry/cloudflare-web-analytics.mjs +2 -2
  28. package/dist/runtime/registry/fathom-analytics.d.ts +2 -2
  29. package/dist/runtime/registry/fathom-analytics.mjs +2 -2
  30. package/dist/runtime/registry/google-analytics.d.ts +4 -2
  31. package/dist/runtime/registry/google-analytics.mjs +13 -8
  32. package/dist/runtime/registry/google-maps.mjs +2 -2
  33. package/dist/runtime/registry/google-tag-manager.mjs +2 -2
  34. package/dist/runtime/registry/hotjar.mjs +4 -4
  35. package/dist/runtime/registry/intercom.mjs +3 -8
  36. package/dist/runtime/registry/lemon-squeezy.d.ts +1 -2
  37. package/dist/runtime/registry/lemon-squeezy.mjs +3 -6
  38. package/dist/runtime/registry/matomo-analytics.mjs +11 -10
  39. package/dist/runtime/registry/{facebook-pixel.d.ts → meta-pixel.d.ts} +7 -7
  40. package/dist/runtime/registry/{facebook-pixel.mjs → meta-pixel.mjs} +9 -7
  41. package/dist/runtime/registry/npm.mjs +2 -2
  42. package/dist/runtime/registry/plausible-analytics.mjs +2 -2
  43. package/dist/runtime/registry/segment.d.ts +22 -9
  44. package/dist/runtime/registry/segment.mjs +43 -21
  45. package/dist/runtime/registry/stripe.mjs +4 -4
  46. package/dist/runtime/registry/vimeo-player.d.ts +6 -6
  47. package/dist/runtime/registry/vimeo-player.mjs +30 -34
  48. package/dist/runtime/registry/x-pixel.mjs +17 -13
  49. package/dist/runtime/registry/youtube-player.d.ts +14 -0
  50. package/dist/runtime/registry/{youtube-iframe.mjs → youtube-player.mjs} +22 -20
  51. package/dist/runtime/types.d.ts +33 -16
  52. package/dist/runtime/types.mjs +2 -0
  53. package/dist/runtime/utils.d.ts +3 -2
  54. package/dist/runtime/utils.mjs +15 -13
  55. package/package.json +6 -6
  56. package/dist/client/_nuxt/CMNIl2hT.js +0 -31
  57. package/dist/client/_nuxt/builds/meta/8b865286-abcf-4201-a2af-ee13e4478155.json +0 -1
  58. package/dist/runtime/components/GoogleMaps.vue +0 -130
  59. package/dist/runtime/components/LemonSqueezyButton.vue +0 -28
  60. package/dist/runtime/components/StripePricingTableEmbed.vue +0 -33
  61. package/dist/runtime/components/VimeoEmbed.vue +0 -161
  62. package/dist/runtime/components/YouTubeEmbed.vue +0 -79
  63. package/dist/runtime/registry/youtube-iframe.d.ts +0 -15
@@ -0,0 +1,160 @@
1
+ <script setup lang="ts">
2
+ /// <reference types="youtube" />
3
+ import { type HTMLAttributes, type ImgHTMLAttributes, type Ref, computed, onMounted, ref, watch } from 'vue'
4
+ import { defu } from 'defu'
5
+ import type { ElementScriptTrigger } from '../composables/useElementScriptTrigger'
6
+ import { useElementScriptTrigger, useHead, useScriptYouTubePlayer } from '#imports'
7
+
8
+ const props = withDefaults(defineProps<{
9
+ placeholderAttrs?: ImgHTMLAttributes
10
+ rootAttrs?: HTMLAttributes
11
+ aboveTheFold?: boolean
12
+ trigger?: ElementScriptTrigger
13
+ videoId: string
14
+ playerVars?: YT.PlayerVars
15
+ width?: number
16
+ height?: number
17
+ }>(), {
18
+ trigger: 'mousedown',
19
+ // @ts-expect-error untyped
20
+ playerVars: { autoplay: 0, playsinline: 1 },
21
+ width: 640,
22
+ height: 480,
23
+ })
24
+
25
+ const emits = defineEmits<{
26
+ 'ready': [e: YT.PlayerEvent]
27
+ 'state-change': [e: YT.OnStateChangeEvent, target: YT.Player]
28
+ 'playback-quality-change': [e: YT.OnPlaybackQualityChangeEvent, target: YT.Player]
29
+ 'playback-rate-change': [e: YT.OnPlaybackRateChangeEvent, target: YT.Player]
30
+ 'error': [e: YT.OnErrorEvent, target: YT.Player]
31
+ }>()
32
+ const events: (keyof YT.Events)[] = [
33
+ 'onReady',
34
+ 'onStateChange',
35
+ 'onPlaybackQualityChange',
36
+ 'onPlaybackRateChange',
37
+ 'onError',
38
+ 'onApiChange',
39
+ ]
40
+ const rootEl = ref()
41
+ const youtubeEl = ref()
42
+ const ready = ref(false)
43
+ const trigger = useElementScriptTrigger({ trigger: props.trigger, el: rootEl })
44
+ const { $script } = useScriptYouTubePlayer({
45
+ scriptOptions: {
46
+ trigger,
47
+ },
48
+ })
49
+
50
+ const player: Ref<YT.Player | undefined> = ref()
51
+ let clickTriggered = false
52
+ if (props.trigger === 'mousedown') {
53
+ trigger.then(() => {
54
+ clickTriggered = true
55
+ })
56
+ }
57
+ onMounted(() => {
58
+ $script.then(async (instance) => {
59
+ const YouTube: typeof YT & { ready: (fn: () => void) => void } = await instance.YT
60
+ await new Promise<void>((resolve) => {
61
+ if (typeof YT.Player === 'undefined')
62
+ YouTube.ready(resolve)
63
+ else
64
+ resolve()
65
+ })
66
+ player.value = new YT.Player(youtubeEl.value, {
67
+ ...props,
68
+ events: Object.fromEntries(events.map(event => [event, (e: any) => {
69
+ const emitEventName = event.replace(/([A-Z])/g, '-$1').replace('on-', '').toLowerCase()
70
+ // @ts-expect-error untyped
71
+ emits(emitEventName, e)
72
+ if (event === 'onReady') {
73
+ ready.value = true
74
+ if (clickTriggered) {
75
+ player.value?.playVideo()
76
+ clickTriggered = false
77
+ }
78
+ watch(() => props.videoId, () => {
79
+ player.value?.loadVideoById(props.videoId)
80
+ })
81
+ }
82
+ }])),
83
+ })
84
+ })
85
+ })
86
+
87
+ defineExpose({
88
+ player,
89
+ })
90
+
91
+ const rootAttrs = computed(() => {
92
+ return defu(props.rootAttrs, {
93
+ 'aria-busy': $script.status.value === 'loading',
94
+ 'aria-label': $script.status.value === 'awaitingLoad'
95
+ ? 'YouTube Player - Placeholder'
96
+ : $script.status.value === 'loading'
97
+ ? 'YouTube Player - Loading'
98
+ : 'YouTube Player - Loaded',
99
+ 'aria-live': 'polite',
100
+ 'role': 'application',
101
+ 'style': {
102
+ cursor: 'pointer',
103
+ position: 'relative',
104
+ backgroundColor: 'black',
105
+ maxWidth: '100%',
106
+ width: `${props.width}px`,
107
+ height: `'auto'`,
108
+ aspectRatio: `${props.width}/${props.height}`,
109
+ },
110
+ }) as HTMLAttributes
111
+ })
112
+
113
+ const placeholder = computed(() => `https://i.ytimg.com/vi_webp/${props.videoId}/sddefault.webp`)
114
+
115
+ if (import.meta.server) {
116
+ // dns-prefetch https://i.vimeocdn.com
117
+ useHead({
118
+ link: [
119
+ {
120
+ rel: props.aboveTheFold ? 'preconnect' : 'dns-prefetch',
121
+ href: 'https://i.ytimg.com',
122
+ },
123
+ props.aboveTheFold
124
+ // we can preload the placeholder image
125
+ ? {
126
+ rel: 'preload',
127
+ as: 'image',
128
+ href: placeholder.value,
129
+ }
130
+ : {},
131
+ ],
132
+ })
133
+ }
134
+
135
+ const placeholderAttrs = computed(() => {
136
+ return defu(props.placeholderAttrs, {
137
+ src: placeholder.value,
138
+ alt: '',
139
+ loading: props.aboveTheFold ? 'eager' : 'lazy',
140
+ style: {
141
+ width: '100%',
142
+ objectFit: 'contain',
143
+ height: '100%',
144
+ },
145
+ } satisfies ImgHTMLAttributes)
146
+ })
147
+ </script>
148
+
149
+ <template>
150
+ <div ref="rootEl" v-bind="rootAttrs">
151
+ <div ref="youtubeEl" style="width: 100%; height: 100%; position: absolute; top: 0; left: 0;" />
152
+ <slot v-if="!ready" :placeholder="placeholder" name="placeholder">
153
+ <img v-bind="placeholderAttrs">
154
+ </slot>
155
+ <slot v-if="$script.status.value === 'loading'" name="loading">
156
+ <ScriptLoadingIndicator />
157
+ </slot>
158
+ <slot v-if="$script.status.value === 'awaitingLoad'" name="awaitingLoad" />
159
+ </div>
160
+ </template>
@@ -1,5 +1,5 @@
1
- import type { Ref } from 'vue';
2
- export type ElementScriptTrigger = 'visible' | 'mouseover' | false;
1
+ import type { MaybeComputedElementRef, MaybeElement } from '@vueuse/core';
2
+ export type ElementScriptTrigger = 'immediate' | 'visible' | keyof GlobalEventHandlersEventMap | (keyof GlobalEventHandlersEventMap)[] | false;
3
3
  export interface ElementScriptTriggerOptions {
4
4
  /**
5
5
  * The event to trigger the script load.
@@ -9,7 +9,7 @@ export interface ElementScriptTriggerOptions {
9
9
  * The element to watch for the trigger event.
10
10
  * @default document.body
11
11
  */
12
- el?: HTMLElement | Ref<HTMLElement | undefined> | null;
12
+ el?: MaybeComputedElementRef<MaybeElement>;
13
13
  }
14
14
  /**
15
15
  * Create a trigger for an element to load a script based on specific element events.
@@ -1,11 +1,47 @@
1
- import { useElementHover, useElementVisibility, watchOnce } from "@vueuse/core";
2
- import { ref } from "vue";
1
+ import {
2
+ useEventListener,
3
+ useIntersectionObserver
4
+ } from "@vueuse/core";
5
+ function useElementVisibilityPromise(element) {
6
+ let observer;
7
+ return new Promise((resolve) => {
8
+ observer = useIntersectionObserver(
9
+ element,
10
+ (intersectionObserverEntries) => {
11
+ for (const entry of intersectionObserverEntries) {
12
+ if (entry.isIntersecting)
13
+ resolve();
14
+ }
15
+ },
16
+ {
17
+ rootMargin: "30px 0px 0px 0px",
18
+ threshold: 0
19
+ }
20
+ );
21
+ }).finally(() => {
22
+ observer.stop();
23
+ });
24
+ }
3
25
  export function useElementScriptTrigger(options) {
4
26
  const { el, trigger } = options;
5
27
  if (import.meta.server || !el)
6
28
  return new Promise(() => {
7
29
  });
8
- const $el = typeof el !== "undefined" ? el : document.body;
9
- const activeRef = trigger ? trigger === "mouseover" ? useElementHover($el) : useElementVisibility($el) : ref(false);
10
- return trigger ? new Promise((resolve) => watchOnce([activeRef], () => resolve())) : Promise.resolve();
30
+ if (el && options.trigger === "visible")
31
+ return useElementVisibilityPromise(el);
32
+ if (trigger !== "immediate") {
33
+ return new Promise((resolve) => {
34
+ const _ = useEventListener(
35
+ typeof el !== "undefined" ? el : document.body,
36
+ // @ts-expect-error untyped
37
+ trigger,
38
+ () => {
39
+ resolve();
40
+ _();
41
+ },
42
+ { once: true, passive: true }
43
+ );
44
+ });
45
+ }
46
+ return Promise.resolve();
11
47
  }
@@ -1,4 +1,4 @@
1
- import { type UseScriptInput, type VueScriptInstance } from '@unhead/vue';
1
+ import type { UseScriptInput, VueScriptInstance } from '@unhead/vue';
2
2
  import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
3
  export declare function useScript<T extends Record<string | symbol, any>>(input: UseScriptInput, options?: NuxtUseScriptOptions): T & {
4
4
  $script: Promise<T> & VueScriptInstance<T>;
@@ -1,16 +1,18 @@
1
- import { useScript as _useScript, injectHead } from "@unhead/vue";
2
1
  import { hashCode } from "@unhead/shared";
3
2
  import { defu } from "defu";
4
- import { onNuxtReady, useNuxtApp, useRuntimeConfig } from "#imports";
3
+ import { useScript as _useScript, injectHead, onNuxtReady, useNuxtApp, useRuntimeConfig } from "#imports";
4
+ function useNuxtScriptRuntimeConfig() {
5
+ return useRuntimeConfig().public["nuxt-scripts"];
6
+ }
5
7
  export function useScript(input, options) {
6
8
  input = typeof input === "string" ? { src: input } : input;
7
- options = defu(options, useRuntimeConfig().public["nuxt-scripts"]?.defaultScriptOptions);
9
+ options = defu(options, useNuxtScriptRuntimeConfig()?.defaultScriptOptions);
8
10
  if (options.trigger === "onNuxtReady")
9
11
  options.trigger = onNuxtReady;
10
12
  const nuxtApp = useNuxtApp();
11
13
  const id = input.key || input.src || hashCode(typeof input.innerHTML === "string" ? input.innerHTML : "");
12
- if (!nuxtApp.scripts?.[id]) {
13
- if (import.meta.client) {
14
+ if (import.meta.client) {
15
+ if (!nuxtApp._scripts?.[id]) {
14
16
  performance?.mark?.("mark_feature_usage", {
15
17
  detail: {
16
18
  feature: `nuxt-scripts:${id}`
@@ -50,7 +52,6 @@ export function useScript(input, options) {
50
52
  payload.events.push({
51
53
  type: "fn-call",
52
54
  fn: ctx.fn,
53
- args: ctx.args,
54
55
  at: Date.now()
55
56
  });
56
57
  syncScripts();
@@ -1,5 +1,5 @@
1
1
  import { defu } from "defu";
2
- import { registryScript } from "../utils.mjs";
2
+ import { useRegistryScript } from "../utils.mjs";
3
3
  import { boolean, minLength, object, optional, string } from "#nuxt-scripts-validator";
4
4
  export const CloudflareWebAnalyticsOptions = object({
5
5
  /**
@@ -15,7 +15,7 @@ export const CloudflareWebAnalyticsOptions = object({
15
15
  spa: optional(boolean())
16
16
  });
17
17
  export function useScriptCloudflareWebAnalytics(_options) {
18
- return registryScript("cloudflareWebAnalytics", (options) => ({
18
+ return useRegistryScript("cloudflareWebAnalytics", (options) => ({
19
19
  scriptInput: {
20
20
  "src": "https://static.cloudflareinsights.com/beacon.min.js",
21
21
  "data-cf-beacon": JSON.stringify(defu(options, { spa: true }))
@@ -7,7 +7,7 @@ export declare const FathomAnalyticsOptions: import("valibot").ObjectSchema<{
7
7
  /**
8
8
  * The Fathom Analytics tracking mode.
9
9
  */
10
- spa: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"hash", "hash"> | import("valibot").LiteralSchema<"auto", "auto"> | import("valibot").LiteralSchema<"history", "history">)[], "auto" | "hash" | "history">, undefined, "auto" | "hash" | "history" | undefined>;
10
+ spa: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"auto", "auto"> | import("valibot").LiteralSchema<"history", "history"> | import("valibot").LiteralSchema<"hash", "hash">)[], "auto" | "history" | "hash">, undefined, "auto" | "history" | "hash" | undefined>;
11
11
  /**
12
12
  * Automatically track page views.
13
13
  */
@@ -23,7 +23,7 @@ export declare const FathomAnalyticsOptions: import("valibot").ObjectSchema<{
23
23
  }, undefined, {
24
24
  site: string;
25
25
  auto?: boolean | undefined;
26
- spa?: "auto" | "hash" | "history" | undefined;
26
+ spa?: "auto" | "history" | "hash" | undefined;
27
27
  canonical?: boolean | undefined;
28
28
  honorDnt?: boolean | undefined;
29
29
  }>;
@@ -1,4 +1,4 @@
1
- import { registryScript } from "../utils.mjs";
1
+ import { useRegistryScript } from "../utils.mjs";
2
2
  import { boolean, literal, object, optional, string, union } from "#nuxt-scripts-validator";
3
3
  export const FathomAnalyticsOptions = object({
4
4
  /**
@@ -23,7 +23,7 @@ export const FathomAnalyticsOptions = object({
23
23
  honorDnt: optional(boolean())
24
24
  });
25
25
  export function useScriptFathomAnalytics(_options) {
26
- return registryScript("fathomAnalytics", (options) => ({
26
+ return useRegistryScript("fathomAnalytics", (options) => ({
27
27
  scriptInput: {
28
28
  src: "https://cdn.usefathom.com/script.js",
29
29
  // can't be bundled
@@ -1,6 +1,9 @@
1
1
  import type { GoogleAnalyticsApi } from 'third-party-capital';
2
2
  import type { RegistryScriptInput } from '#nuxt-scripts';
3
- declare const GoogleAnalyticsOptions: import("valibot").ObjectSchema<{
3
+ export declare const GoogleAnalyticsOptions: import("valibot").ObjectSchema<{
4
+ /**
5
+ * The Google Analytics ID.
6
+ */
4
7
  id: import("valibot").StringSchema<string>;
5
8
  }, undefined, {
6
9
  id: string;
@@ -18,4 +21,3 @@ declare global {
18
21
  export declare function useScriptGoogleAnalytics<T extends GoogleAnalyticsApi>(_options?: GoogleAnalyticsInput): T & {
19
22
  $script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
20
23
  };
21
- export {};
@@ -1,11 +1,14 @@
1
- import { registryScript } from "../utils.mjs";
1
+ import { useRegistryScript } from "../utils.mjs";
2
2
  import { GoogleAnalyticsScriptResolver } from "../../registry";
3
3
  import { object, string } from "#nuxt-scripts-validator";
4
- const GoogleAnalyticsOptions = object({
4
+ export const GoogleAnalyticsOptions = object({
5
+ /**
6
+ * The Google Analytics ID.
7
+ */
5
8
  id: string()
6
9
  });
7
10
  export function useScriptGoogleAnalytics(_options) {
8
- return registryScript("googleAnalytics", (options) => ({
11
+ return useRegistryScript("googleAnalytics", (options) => ({
9
12
  scriptInput: {
10
13
  src: GoogleAnalyticsScriptResolver(options)
11
14
  },
@@ -20,12 +23,14 @@ export function useScriptGoogleAnalytics(_options) {
20
23
  }
21
24
  },
22
25
  clientInit: import.meta.server ? void 0 : () => {
23
- window.dataLayer = window.dataLayer || [];
24
- window.gtag = function gtag(...p) {
25
- window.dataLayer.push(p);
26
+ const w = window;
27
+ w.dataLayer = w.dataLayer || [];
28
+ const gtag = function() {
29
+ w.dataLayer.push(arguments);
26
30
  };
27
- window.gtag("js", /* @__PURE__ */ new Date());
28
- window.gtag("config", options?.id);
31
+ gtag("js", /* @__PURE__ */ new Date());
32
+ gtag("config", "G-TR58L0EF8P");
33
+ w.gtag = gtag;
29
34
  }
30
35
  }), _options);
31
36
  }
@@ -1,5 +1,5 @@
1
1
  import { withQuery } from "ufo";
2
- import { registryScript } from "../utils.mjs";
2
+ import { useRegistryScript } from "../utils.mjs";
3
3
  import { array, literal, object, optional, string, union } from "#nuxt-scripts-validator";
4
4
  export const GoogleMapsOptions = object({
5
5
  apiKey: string(),
@@ -8,7 +8,7 @@ export const GoogleMapsOptions = object({
8
8
  });
9
9
  export function useScriptGoogleMaps(_options) {
10
10
  let readyPromise = Promise.resolve();
11
- return registryScript("googleMaps", (options) => {
11
+ return useRegistryScript("googleMaps", (options) => {
12
12
  const libraries = options?.libraries || ["places"];
13
13
  return {
14
14
  scriptInput: {
@@ -1,11 +1,11 @@
1
1
  import { withQuery } from "ufo";
2
- import { registryScript } from "../utils.mjs";
2
+ import { useRegistryScript } from "../utils.mjs";
3
3
  import { object, string } from "#nuxt-scripts-validator";
4
4
  const GoogleTagManagerOptions = object({
5
5
  id: string()
6
6
  });
7
7
  export function useScriptGoogleTagManager(options) {
8
- return registryScript("googleTagManager", (options2) => ({
8
+ return useRegistryScript("googleTagManager", (options2) => ({
9
9
  scriptInput: {
10
10
  async: true,
11
11
  src: withQuery("https://www.googletagmanager.com/gtm.js", {
@@ -1,13 +1,13 @@
1
- import { registryScript } from "../utils.mjs";
1
+ import { useRegistryScript } from "../utils.mjs";
2
2
  import { number, object, optional } from "#nuxt-scripts-validator";
3
3
  export const HotjarOptions = object({
4
4
  id: number(),
5
5
  sv: optional(number())
6
6
  });
7
7
  export function useScriptHotjar(_options) {
8
- return registryScript("hotjar", (options) => ({
8
+ return useRegistryScript("hotjar", (options) => ({
9
9
  scriptInput: {
10
- src: `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv}`
10
+ src: `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv || 6}`
11
11
  },
12
12
  schema: import.meta.dev ? HotjarOptions : void 0,
13
13
  scriptOptions: {
@@ -16,7 +16,7 @@ export function useScriptHotjar(_options) {
16
16
  }
17
17
  },
18
18
  clientInit: import.meta.server ? void 0 : () => {
19
- window._hjSettings = window._hjSettings || { hjid: options?.id, hjsv: options?.sv };
19
+ window._hjSettings = window._hjSettings || { hjid: options?.id, hjsv: options?.sv || 6 };
20
20
  window.hj = window.hj || function(...params) {
21
21
  (window.hj.q = window.hj.q || []).push(params);
22
22
  };
@@ -1,5 +1,5 @@
1
1
  import { joinURL } from "ufo";
2
- import { registryScript } from "../utils.mjs";
2
+ import { useRegistryScript } from "../utils.mjs";
3
3
  import { literal, number, object, optional, string, union } from "#nuxt-scripts-validator";
4
4
  export const IntercomOptions = object({
5
5
  app_id: string(),
@@ -13,14 +13,9 @@ export const IntercomOptions = object({
13
13
  vertical_padding: optional(number())
14
14
  });
15
15
  export function useScriptIntercom(_options) {
16
- return registryScript("intercom", (options) => ({
16
+ return useRegistryScript("intercom", (options) => ({
17
17
  scriptInput: {
18
- src: joinURL(`https://widget.intercom.io/widget`, options?.app_id || ""),
19
- // append the data attr's
20
- ...Object.entries(options).filter(([key]) => key.startsWith("data-")).reduce((acc, [key, value]) => {
21
- acc[key] = value;
22
- return acc;
23
- })
18
+ src: joinURL(`https://widget.intercom.io/widget`, options?.app_id || "")
24
19
  },
25
20
  schema: import.meta.dev ? IntercomOptions : void 0,
26
21
  scriptOptions: {
@@ -1,6 +1,5 @@
1
1
  import type { RegistryScriptInput } from '#nuxt-scripts';
2
- export declare const LemonSqueezyOptions: import("valibot").ObjectSchema<{}, undefined, {}>;
3
- export type LemonSqueezyInput = RegistryScriptInput<typeof LemonSqueezyOptions>;
2
+ export type LemonSqueezyInput = RegistryScriptInput;
4
3
  export interface LemonSqueezyApi {
5
4
  /**
6
5
  * Initialises Lemon.js on your page.
@@ -1,14 +1,11 @@
1
- import { registryScript } from "../utils.mjs";
2
- import { object } from "#nuxt-scripts-validator";
3
- export const LemonSqueezyOptions = object({});
1
+ import { useRegistryScript } from "../utils.mjs";
4
2
  export function useScriptLemonSqueezy(_options) {
5
- return registryScript("lemonSqueezy", () => ({
3
+ return useRegistryScript("lemonSqueezy", () => ({
6
4
  scriptInput: {
7
5
  src: "https://assets.lemonsqueezy.com/lemon.js",
8
6
  // @ts-expect-error untyped
9
- crossorigin: null
7
+ crossorigin: false
10
8
  },
11
- schema: import.meta.dev ? LemonSqueezyOptions : void 0,
12
9
  scriptOptions: {
13
10
  use() {
14
11
  if (typeof window.createLemonSqueezy === "undefined")
@@ -1,4 +1,5 @@
1
- import { registryScript } from "../utils.mjs";
1
+ import { withBase, withHttps } from "ufo";
2
+ import { useRegistryScript } from "../utils.mjs";
2
3
  import { boolean, object, optional, string } from "#nuxt-scripts-validator";
3
4
  export const MatomoAnalyticsOptions = object({
4
5
  matomoUrl: string(),
@@ -8,9 +9,9 @@ export const MatomoAnalyticsOptions = object({
8
9
  enableLinkTracking: optional(boolean())
9
10
  });
10
11
  export function useScriptMatomoAnalytics(_options) {
11
- return registryScript("matomoAnalytics", (options) => ({
12
+ return useRegistryScript("matomoAnalytics", (options) => ({
12
13
  scriptInput: {
13
- src: `https://${options?.matomoUrl}/matomo.js`
14
+ src: withBase(`/matomo.js`, withHttps(options?.matomoUrl))
14
15
  },
15
16
  schema: import.meta.dev ? MatomoAnalyticsOptions : void 0,
16
17
  scriptOptions: {
@@ -20,14 +21,14 @@ export function useScriptMatomoAnalytics(_options) {
20
21
  // allow _paq to be accessed on the server
21
22
  stub: import.meta.client ? void 0 : ({ fn }) => {
22
23
  return fn === "_paq" ? [] : void 0;
23
- },
24
- clientInit: import.meta.server ? void 0 : () => {
25
- const _paq = window._paq = window._paq || [];
26
- options?.trackPageView !== false && _paq.push(["trackPageView"]);
27
- options?.enableLinkTracking !== false && _paq.push(["enableLinkTracking"]);
28
- _paq.push(["setTrackerUrl", `//${options?.matomoUrl}/matomo.php`]);
29
- _paq.push(["setSiteId", options?.siteId]);
30
24
  }
25
+ },
26
+ clientInit: import.meta.server ? void 0 : () => {
27
+ const _paq = window._paq = window._paq || [];
28
+ options?.trackPageView !== false && _paq.push(["trackPageView"]);
29
+ options?.enableLinkTracking !== false && _paq.push(["enableLinkTracking"]);
30
+ _paq.push(["setTrackerUrl", withBase(`/matomo.php`, withHttps(options?.matomoUrl))]);
31
+ _paq.push(["setSiteId", options?.siteId || "1"]);
31
32
  }
32
33
  }), _options);
33
34
  }
@@ -19,26 +19,26 @@ interface EventObjectProperties {
19
19
  [key: string]: any;
20
20
  }
21
21
  type FbqFns = ((event: 'track', eventName: StandardEvents, data?: EventObjectProperties) => void) & ((event: 'trackCustom', eventName: string, data?: EventObjectProperties) => void) & ((event: 'init', id: number, data?: Record<string, any>) => void) & ((event: 'init', id: string) => void) & ((event: string, ...params: any[]) => void);
22
- export interface FacebookPixelApi {
22
+ export interface MetaPixelApi {
23
23
  fbq: FbqFns & {
24
24
  push: FbqFns;
25
25
  loaded: boolean;
26
26
  version: string;
27
27
  queue: any[];
28
28
  };
29
- _fbq: FacebookPixelApi['fbq'];
29
+ _fbq: MetaPixelApi['fbq'];
30
30
  }
31
31
  declare global {
32
- interface Window extends FacebookPixelApi {
32
+ interface Window extends MetaPixelApi {
33
33
  }
34
34
  }
35
- export declare const FacebookPixelOptions: import("valibot").ObjectSchema<{
36
- id: import("valibot").UnionSchema<(import("valibot").NumberSchema<number> | import("valibot").StringSchema<string>)[], string | number>;
35
+ export declare const MetaPixelOptions: import("valibot").ObjectSchema<{
36
+ id: import("valibot").UnionSchema<(import("valibot").StringSchema<string> | import("valibot").NumberSchema<number>)[], string | number>;
37
37
  }, undefined, {
38
38
  id: string | number;
39
39
  }>;
40
- export type FacebookPixelInput = RegistryScriptInput<typeof FacebookPixelOptions>;
41
- export declare function useScriptFacebookPixel<T extends FacebookPixelApi>(_options?: FacebookPixelInput): T & {
40
+ export type MetaPixelInput = RegistryScriptInput<typeof MetaPixelOptions>;
41
+ export declare function useScriptMetaPixel<T extends MetaPixelApi>(_options?: MetaPixelInput): T & {
42
42
  $script: Promise<T> & import("@unhead/vue").VueScriptInstance<T>;
43
43
  };
44
44
  export {};
@@ -1,15 +1,17 @@
1
- import { registryScript } from "../utils.mjs";
2
- import { FacebookPixelScriptResolver } from "../../registry";
1
+ import { useRegistryScript } from "../utils.mjs";
2
+ import { MetaPixelScriptResolver } from "../../registry";
3
3
  import { number, object, string, union } from "#nuxt-scripts-validator";
4
- export const FacebookPixelOptions = object({
4
+ export const MetaPixelOptions = object({
5
5
  id: union([string(), number()])
6
6
  });
7
- export function useScriptFacebookPixel(_options) {
8
- return registryScript("facebookPixel", (options) => ({
7
+ export function useScriptMetaPixel(_options) {
8
+ return useRegistryScript("metaPixel", (options) => ({
9
9
  scriptInput: {
10
- src: FacebookPixelScriptResolver()
10
+ src: MetaPixelScriptResolver(),
11
+ // @ts-expect-error TODO fix upstream
12
+ crossorigin: false
11
13
  },
12
- schema: import.meta.dev ? FacebookPixelOptions : void 0,
14
+ schema: import.meta.dev ? MetaPixelOptions : void 0,
13
15
  scriptOptions: {
14
16
  use() {
15
17
  return { fbq: window.fbq };
@@ -1,5 +1,5 @@
1
1
  import { withBase } from "ufo";
2
- import { registryScript } from "../utils.mjs";
2
+ import { useRegistryScript } from "../utils.mjs";
3
3
  import { object, optional, string } from "#nuxt-scripts-validator";
4
4
  export const NpmOptions = object({
5
5
  packageName: string(),
@@ -8,7 +8,7 @@ export const NpmOptions = object({
8
8
  type: optional(string())
9
9
  });
10
10
  export function useScriptNpm(_options) {
11
- return registryScript(`${_options.packageName}-npm`, (options) => ({
11
+ return useRegistryScript(`${_options.packageName}-npm`, (options) => ({
12
12
  scriptInput: {
13
13
  src: withBase(options.file || "", `https://unpkg.com/${options?.packageName}@${options.version || "latest"}`)
14
14
  },
@@ -1,4 +1,4 @@
1
- import { registryScript } from "../utils.mjs";
1
+ import { useRegistryScript } from "../utils.mjs";
2
2
  import { PlausibleAnalyticsScriptResolver } from "../../registry";
3
3
  import { array, literal, object, optional, string, union } from "#nuxt-scripts-validator";
4
4
  const extensions = [
@@ -18,7 +18,7 @@ export const PlausibleAnalyticsOptions = object({
18
18
  extension: optional(union([union(extensions), array(union(extensions))]))
19
19
  });
20
20
  export function useScriptPlausibleAnalytics(_options) {
21
- return registryScript("plausibleAnalytics", (options) => {
21
+ return useRegistryScript("plausibleAnalytics", (options) => {
22
22
  return {
23
23
  scriptInput: {
24
24
  "src": PlausibleAnalyticsScriptResolver(options),