@nuxt/scripts 0.13.2 → 1.0.0-beta.2

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 (98) hide show
  1. package/README.md +15 -0
  2. package/dist/client/200.html +1 -1
  3. package/dist/client/404.html +1 -1
  4. package/dist/client/_nuxt/B66N9HCo.js +1 -0
  5. package/dist/client/_nuxt/B8XOar-X.js +162 -0
  6. package/dist/client/_nuxt/{Bje-0OHL.js → DfLgoB--.js} +1 -1
  7. package/dist/client/_nuxt/DvH517bE.js +1 -0
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/133a46c5-a5c1-4a63-87d1-037947a5bcdb.json +1 -0
  10. package/dist/client/_nuxt/entry.D45OuV0w.css +1 -0
  11. package/dist/client/_nuxt/error-404.B57D-jUQ.css +1 -0
  12. package/dist/client/_nuxt/error-500.DTHUW7BI.css +1 -0
  13. package/dist/client/index.html +1 -1
  14. package/dist/module.d.mts +106 -4
  15. package/dist/module.json +1 -1
  16. package/dist/module.mjs +705 -173
  17. package/dist/registry.mjs +63 -0
  18. package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.d.vue.ts +29 -1
  19. package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue +35 -10
  20. package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue.d.ts +29 -1
  21. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.d.vue.ts +20 -8
  22. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue +2 -2
  23. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue.d.ts +20 -8
  24. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPinElement.vue +7 -1
  25. package/dist/runtime/components/ScriptCrisp.d.vue.ts +1 -1
  26. package/dist/runtime/components/ScriptCrisp.vue.d.ts +1 -1
  27. package/dist/runtime/components/ScriptInstagramEmbed.d.vue.ts +53 -0
  28. package/dist/runtime/components/ScriptInstagramEmbed.vue +38 -0
  29. package/dist/runtime/components/ScriptInstagramEmbed.vue.d.ts +53 -0
  30. package/dist/runtime/components/ScriptIntercom.d.vue.ts +1 -1
  31. package/dist/runtime/components/ScriptIntercom.vue.d.ts +1 -1
  32. package/dist/runtime/components/ScriptVimeoPlayer.d.vue.ts +2 -2
  33. package/dist/runtime/components/ScriptVimeoPlayer.vue.d.ts +2 -2
  34. package/dist/runtime/components/ScriptXEmbed.d.vue.ts +82 -0
  35. package/dist/runtime/components/ScriptXEmbed.vue +76 -0
  36. package/dist/runtime/components/ScriptXEmbed.vue.d.ts +82 -0
  37. package/dist/runtime/components/ScriptYouTubePlayer.d.vue.ts +12 -1
  38. package/dist/runtime/components/ScriptYouTubePlayer.vue +41 -16
  39. package/dist/runtime/components/ScriptYouTubePlayer.vue.d.ts +12 -1
  40. package/dist/runtime/composables/useScript.js +34 -3
  41. package/dist/runtime/composables/useScriptTriggerServiceWorker.d.ts +7 -0
  42. package/dist/runtime/composables/useScriptTriggerServiceWorker.js +39 -0
  43. package/dist/runtime/npm-script-stub.d.ts +20 -0
  44. package/dist/runtime/npm-script-stub.js +73 -0
  45. package/dist/runtime/plugins/sw-register.client.d.ts +2 -0
  46. package/dist/runtime/plugins/sw-register.client.js +12 -0
  47. package/dist/runtime/registry/google-recaptcha.d.ts +27 -0
  48. package/dist/runtime/registry/google-recaptcha.js +45 -0
  49. package/dist/runtime/registry/google-sign-in.d.ts +84 -0
  50. package/dist/runtime/registry/google-sign-in.js +50 -0
  51. package/dist/runtime/registry/google-tag-manager.d.ts +3 -1
  52. package/dist/runtime/registry/google-tag-manager.js +15 -5
  53. package/dist/runtime/registry/instagram-embed.d.ts +23 -0
  54. package/dist/runtime/registry/instagram-embed.js +22 -0
  55. package/dist/runtime/registry/lemon-squeezy.d.ts +0 -1
  56. package/dist/runtime/registry/matomo-analytics.js +1 -1
  57. package/dist/runtime/registry/plausible-analytics.js +8 -6
  58. package/dist/runtime/registry/posthog.d.ts +26 -0
  59. package/dist/runtime/registry/posthog.js +92 -0
  60. package/dist/runtime/registry/rybbit-analytics.js +38 -8
  61. package/dist/runtime/registry/tiktok-pixel.d.ts +44 -0
  62. package/dist/runtime/registry/tiktok-pixel.js +44 -0
  63. package/dist/runtime/registry/x-embed.d.ts +77 -0
  64. package/dist/runtime/registry/x-embed.js +41 -0
  65. package/dist/runtime/server/google-static-maps-proxy.d.ts +2 -0
  66. package/dist/runtime/server/google-static-maps-proxy.js +54 -0
  67. package/dist/runtime/server/instagram-embed-asset.d.ts +2 -0
  68. package/dist/runtime/server/instagram-embed-asset.js +42 -0
  69. package/dist/runtime/server/instagram-embed-image.d.ts +2 -0
  70. package/dist/runtime/server/instagram-embed-image.js +54 -0
  71. package/dist/runtime/server/instagram-embed.d.ts +2 -0
  72. package/dist/runtime/server/instagram-embed.js +91 -0
  73. package/dist/runtime/server/proxy-handler.d.ts +6 -0
  74. package/dist/runtime/server/proxy-handler.js +230 -0
  75. package/dist/runtime/server/sw-handler.d.ts +2 -0
  76. package/dist/runtime/server/sw-handler.js +25 -0
  77. package/dist/runtime/server/utils/privacy.d.ts +97 -0
  78. package/dist/runtime/server/utils/privacy.js +268 -0
  79. package/dist/runtime/server/x-embed-image.d.ts +2 -0
  80. package/dist/runtime/server/x-embed-image.js +53 -0
  81. package/dist/runtime/server/x-embed.d.ts +49 -0
  82. package/dist/runtime/server/x-embed.js +31 -0
  83. package/dist/runtime/sw/proxy-sw.template.d.ts +1 -0
  84. package/dist/runtime/sw/proxy-sw.template.js +54 -0
  85. package/dist/runtime/types.d.ts +42 -1
  86. package/dist/runtime/utils/pure.d.ts +13 -0
  87. package/dist/runtime/utils/pure.js +67 -0
  88. package/dist/runtime/utils.d.ts +3 -2
  89. package/dist/runtime/utils.js +11 -1
  90. package/dist/types.d.mts +1 -1
  91. package/package.json +39 -32
  92. package/dist/client/_nuxt/DMut0W-e.js +0 -162
  93. package/dist/client/_nuxt/builds/meta/5e0206fe-a683-423c-8d59-2596d0b16fee.json +0 -1
  94. package/dist/client/_nuxt/entry.BjfcJo5q.css +0 -1
  95. package/dist/client/_nuxt/error-404.B0ZhSNwd.css +0 -1
  96. package/dist/client/_nuxt/error-500.D4MdgPaC.css +0 -1
  97. package/dist/client/_nuxt/iNmKC7TZ.js +0 -1
  98. package/dist/client/_nuxt/rttsH3SL.js +0 -1
@@ -0,0 +1,20 @@
1
+ import type { Ref } from 'vue';
2
+ import type { NuxtUseScriptOptions } from './types.js';
3
+ export interface NpmScriptStubOptions {
4
+ key: string;
5
+ use?: () => any;
6
+ clientInit?: () => void | Promise<any>;
7
+ trigger?: NuxtUseScriptOptions['trigger'];
8
+ }
9
+ export interface NpmScriptStub<T = any> {
10
+ status: Ref<'awaitingLoad' | 'loading' | 'loaded' | 'error'>;
11
+ load: () => Promise<void>;
12
+ onLoaded: (callback: (api: T) => void) => void;
13
+ proxy: T;
14
+ $script?: any;
15
+ }
16
+ /**
17
+ * Creates a script stub for NPM-only packages (no external script tag)
18
+ * Manages lifecycle and status without relying on script tag loading
19
+ */
20
+ export declare function createNpmScriptStub<T = any>(options: NpmScriptStubOptions): NpmScriptStub<T>;
@@ -0,0 +1,73 @@
1
+ import { ref } from "vue";
2
+ import { logger } from "./logger.js";
3
+ export function createNpmScriptStub(options) {
4
+ const status = ref("awaitingLoad");
5
+ const loadedCallbacks = [];
6
+ let initPromise = null;
7
+ let hasInitialized = false;
8
+ const proxy = options.use?.() || {};
9
+ const stub = {
10
+ status,
11
+ proxy,
12
+ async load() {
13
+ if (hasInitialized || status.value !== "awaitingLoad")
14
+ return;
15
+ hasInitialized = true;
16
+ status.value = "loading";
17
+ try {
18
+ if (options.clientInit) {
19
+ console.log(`[NpmScriptStub] Initializing ${options.key}...`);
20
+ initPromise = Promise.resolve(options.clientInit());
21
+ await initPromise;
22
+ console.log(`[NpmScriptStub] ${options.key} initialized successfully`);
23
+ }
24
+ status.value = "loaded";
25
+ loadedCallbacks.forEach((cb) => {
26
+ try {
27
+ cb(proxy);
28
+ } catch (error) {
29
+ logger.error(`[NpmScriptStub] Error in onLoaded callback for ${options.key}:`, error);
30
+ }
31
+ });
32
+ } catch (error) {
33
+ logger.error(`[NpmScriptStub] Failed to initialize ${options.key}:`, error);
34
+ status.value = "error";
35
+ }
36
+ },
37
+ onLoaded(callback) {
38
+ if (status.value === "loaded") {
39
+ callback(proxy);
40
+ } else {
41
+ loadedCallbacks.push(callback);
42
+ }
43
+ },
44
+ // Mock $script for compatibility with useScript API
45
+ get $script() {
46
+ return {
47
+ status: status.value,
48
+ load: stub.load
49
+ };
50
+ }
51
+ };
52
+ if (options.trigger) {
53
+ if (typeof options.trigger === "function") {
54
+ const res = options.trigger(() => stub.load());
55
+ if (res && typeof res === "object" && "then" in res)
56
+ res.then(() => stub.load());
57
+ } else if (options.trigger === "manual") {
58
+ } else if (options.trigger === "onNuxtReady") {
59
+ import("nuxt/app").then(({ onNuxtReady }) => {
60
+ onNuxtReady(() => stub.load());
61
+ });
62
+ } else if (options.trigger === "client") {
63
+ if (import.meta.client) {
64
+ stub.load();
65
+ }
66
+ }
67
+ } else {
68
+ if (import.meta.client) {
69
+ stub.load();
70
+ }
71
+ }
72
+ return stub;
73
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { defineNuxtPlugin } from "nuxt/app";
2
+ export default defineNuxtPlugin({
3
+ name: "nuxt-scripts:sw-register",
4
+ enforce: "pre",
5
+ async setup() {
6
+ if (!("serviceWorker" in navigator))
7
+ return;
8
+ await navigator.serviceWorker.register(SW_PATH, { scope: "/" }).catch((err) => {
9
+ console.warn("[nuxt-scripts] Service worker registration failed:", err);
10
+ });
11
+ }
12
+ });
@@ -0,0 +1,27 @@
1
+ import type { RegistryScriptInput } from '#nuxt-scripts/types';
2
+ export declare const GoogleRecaptchaOptions: import("valibot").ObjectSchema<{
3
+ readonly siteKey: import("valibot").StringSchema<undefined>;
4
+ readonly enterprise: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
5
+ readonly recaptchaNet: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
6
+ readonly hl: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
7
+ }, undefined>;
8
+ export type GoogleRecaptchaInput = RegistryScriptInput<typeof GoogleRecaptchaOptions>;
9
+ export interface GoogleRecaptchaApi {
10
+ grecaptcha: {
11
+ ready: (callback: () => void) => void;
12
+ execute: (siteKey: string, options: {
13
+ action: string;
14
+ }) => Promise<string>;
15
+ enterprise?: {
16
+ ready: (callback: () => void) => void;
17
+ execute: (siteKey: string, options: {
18
+ action: string;
19
+ }) => Promise<string>;
20
+ };
21
+ };
22
+ }
23
+ declare global {
24
+ interface Window extends GoogleRecaptchaApi {
25
+ }
26
+ }
27
+ export declare function useScriptGoogleRecaptcha<T extends GoogleRecaptchaApi>(_options?: GoogleRecaptchaInput): import("#nuxt-scripts/types").UseScriptContext<T>;
@@ -0,0 +1,45 @@
1
+ import { withQuery } from "ufo";
2
+ import { useRegistryScript } from "#nuxt-scripts/utils";
3
+ import { object, string, optional, boolean } from "#nuxt-scripts-validator";
4
+ export const GoogleRecaptchaOptions = object({
5
+ siteKey: string(),
6
+ // Use enterprise.js instead of api.js
7
+ enterprise: optional(boolean()),
8
+ // Use recaptcha.net (works in China)
9
+ recaptchaNet: optional(boolean()),
10
+ // Language code
11
+ hl: optional(string())
12
+ });
13
+ export function useScriptGoogleRecaptcha(_options) {
14
+ return useRegistryScript(_options?.key || "googleRecaptcha", (options) => {
15
+ const baseUrl = options?.recaptchaNet ? "https://www.recaptcha.net/recaptcha" : "https://www.google.com/recaptcha";
16
+ const scriptPath = options?.enterprise ? "enterprise.js" : "api.js";
17
+ return {
18
+ scriptInput: {
19
+ src: withQuery(`${baseUrl}/${scriptPath}`, {
20
+ render: options?.siteKey,
21
+ hl: options?.hl
22
+ }),
23
+ crossorigin: false
24
+ },
25
+ schema: import.meta.dev ? GoogleRecaptchaOptions : void 0,
26
+ scriptOptions: {
27
+ use() {
28
+ return { grecaptcha: window.grecaptcha };
29
+ }
30
+ },
31
+ clientInit: import.meta.server ? void 0 : () => {
32
+ const w = window;
33
+ w.grecaptcha = w.grecaptcha || {};
34
+ const readyFn = function(cb) {
35
+ (w.___grecaptcha_cfg = w.___grecaptcha_cfg || {}).fns = (w.___grecaptcha_cfg.fns || []).concat([cb]);
36
+ };
37
+ w.grecaptcha.ready = w.grecaptcha.ready || readyFn;
38
+ if (options?.enterprise) {
39
+ w.grecaptcha.enterprise = w.grecaptcha.enterprise || {};
40
+ w.grecaptcha.enterprise.ready = w.grecaptcha.enterprise.ready || readyFn;
41
+ }
42
+ }
43
+ };
44
+ }, _options);
45
+ }
@@ -0,0 +1,84 @@
1
+ import type { RegistryScriptInput } from '#nuxt-scripts/types';
2
+ export interface CredentialResponse {
3
+ credential: string;
4
+ select_by: 'auto' | 'user' | 'user_1tap' | 'user_2tap' | 'btn' | 'btn_confirm' | 'btn_add_session' | 'btn_confirm_add_session';
5
+ clientId?: string;
6
+ }
7
+ export interface IdConfiguration {
8
+ client_id: string;
9
+ auto_select?: boolean;
10
+ callback?: (response: CredentialResponse) => void;
11
+ login_uri?: string;
12
+ native_callback?: (response: CredentialResponse) => void;
13
+ cancel_on_tap_outside?: boolean;
14
+ prompt_parent_id?: string;
15
+ nonce?: string;
16
+ context?: 'signin' | 'signup' | 'use';
17
+ state_cookie_domain?: string;
18
+ ux_mode?: 'popup' | 'redirect';
19
+ allowed_parent_origin?: string | string[];
20
+ intermediate_iframe_close_callback?: () => void;
21
+ itp_support?: boolean;
22
+ login_hint?: string;
23
+ hd?: string;
24
+ use_fedcm_for_prompt?: boolean;
25
+ }
26
+ export interface GsiButtonConfiguration {
27
+ type?: 'standard' | 'icon';
28
+ theme?: 'outline' | 'filled_blue' | 'filled_black';
29
+ size?: 'large' | 'medium' | 'small';
30
+ text?: 'signin_with' | 'signup_with' | 'continue_with' | 'signin';
31
+ shape?: 'rectangular' | 'pill' | 'circle' | 'square';
32
+ logo_alignment?: 'left' | 'center';
33
+ width?: string | number;
34
+ locale?: string;
35
+ click_listener?: () => void;
36
+ use_fedcm?: boolean;
37
+ }
38
+ export type MomentType = 'display' | 'skipped' | 'dismissed';
39
+ export interface MomentNotification {
40
+ isDisplayMoment: () => boolean;
41
+ isDisplayed: () => boolean;
42
+ isNotDisplayed: () => boolean;
43
+ getNotDisplayedReason: () => 'browser_not_supported' | 'invalid_client' | 'missing_client_id' | 'opt_out_or_no_session' | 'secure_http_required' | 'suppressed_by_user' | 'unregistered_origin' | 'unknown_reason';
44
+ isSkippedMoment: () => boolean;
45
+ getSkippedReason: () => 'auto_cancel' | 'user_cancel' | 'tap_outside' | 'issuing_failed';
46
+ isDismissedMoment: () => boolean;
47
+ getDismissedReason: () => 'credential_returned' | 'cancel_called' | 'flow_restarted';
48
+ getMomentType: () => MomentType;
49
+ }
50
+ export interface RevocationResponse {
51
+ successful: boolean;
52
+ error?: string;
53
+ }
54
+ declare namespace google {
55
+ namespace accounts {
56
+ namespace id {
57
+ function initialize(config: IdConfiguration): void;
58
+ function prompt(momentListener?: (notification: MomentNotification) => void): void;
59
+ function renderButton(parent: HTMLElement, options: GsiButtonConfiguration): void;
60
+ function disableAutoSelect(): void;
61
+ function cancel(): void;
62
+ function revoke(hint: string, callback: (response: RevocationResponse) => void): void;
63
+ }
64
+ }
65
+ }
66
+ type AccountsNamespace = typeof google.accounts;
67
+ export interface GoogleSignInApi {
68
+ accounts: AccountsNamespace;
69
+ }
70
+ export declare const GoogleSignInOptions: import("valibot").ObjectSchema<{
71
+ readonly clientId: import("valibot").StringSchema<undefined>;
72
+ readonly autoSelect: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
73
+ readonly context: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"signin", undefined>, import("valibot").LiteralSchema<"signup", undefined>, import("valibot").LiteralSchema<"use", undefined>], undefined>, undefined>;
74
+ readonly useFedcmForPrompt: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
75
+ readonly cancelOnTapOutside: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
76
+ readonly uxMode: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"popup", undefined>, import("valibot").LiteralSchema<"redirect", undefined>], undefined>, undefined>;
77
+ readonly loginUri: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
78
+ readonly itpSupport: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
79
+ readonly allowedParentOrigin: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").StringSchema<undefined>, import("valibot").ArraySchema<import("valibot").StringSchema<undefined>, undefined>], undefined>, undefined>;
80
+ readonly hd: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
81
+ }, undefined>;
82
+ export type GoogleSignInInput = RegistryScriptInput<typeof GoogleSignInOptions>;
83
+ export declare function useScriptGoogleSignIn<T extends GoogleSignInApi>(_options?: GoogleSignInInput): import("#nuxt-scripts/types").UseScriptContext<T>;
84
+ export {};
@@ -0,0 +1,50 @@
1
+ import { useRegistryScript } from "#nuxt-scripts/utils";
2
+ import { object, string, optional, boolean, array, union, literal } from "#nuxt-scripts-validator";
3
+ export const GoogleSignInOptions = object({
4
+ clientId: string(),
5
+ // Auto-select credentials if only one is available
6
+ autoSelect: optional(boolean()),
7
+ // Context for One Tap (signin, signup, or use)
8
+ context: optional(union([literal("signin"), literal("signup"), literal("use")])),
9
+ // FedCM API support (Privacy Sandbox) - mandatory from August 2025
10
+ useFedcmForPrompt: optional(boolean()),
11
+ // Cancel One Tap if user clicks outside
12
+ cancelOnTapOutside: optional(boolean()),
13
+ // UX mode: popup or redirect
14
+ uxMode: optional(union([literal("popup"), literal("redirect")])),
15
+ // Login URI for redirect flow
16
+ loginUri: optional(string()),
17
+ // ITP (Intelligent Tracking Prevention) support
18
+ itpSupport: optional(boolean()),
19
+ // Allowed parent origins for iframe embedding
20
+ allowedParentOrigin: optional(union([string(), array(string())])),
21
+ // Hosted domain - restrict to specific Google Workspace domain
22
+ hd: optional(string())
23
+ });
24
+ export function useScriptGoogleSignIn(_options) {
25
+ return useRegistryScript(_options?.key || "googleSignIn", () => {
26
+ return {
27
+ scriptInput: {
28
+ src: "https://accounts.google.com/gsi/client",
29
+ // Performance best practice: async + defer to prevent render blocking
30
+ defer: true,
31
+ // Google's script doesn't support CORS
32
+ crossorigin: false
33
+ },
34
+ schema: import.meta.dev ? GoogleSignInOptions : void 0,
35
+ scriptOptions: {
36
+ use() {
37
+ return {
38
+ accounts: window.google?.accounts
39
+ };
40
+ }
41
+ },
42
+ clientInit: import.meta.server ? void 0 : () => {
43
+ const w = window;
44
+ w.google = w.google || {};
45
+ w.google.accounts = w.google.accounts || {};
46
+ w.google.accounts.id = w.google.accounts.id || {};
47
+ }
48
+ };
49
+ }, _options);
50
+ }
@@ -11,7 +11,7 @@ export type DataLayer = Array<DataLayerItem>;
11
11
  */
12
12
  export interface DataLayerPush {
13
13
  (...args: Parameters<GTag>): void;
14
- (obj: Record<string, unknown>): void;
14
+ (obj: Record<string, unknown> | any[]): void;
15
15
  }
16
16
  /**
17
17
  * Improved DataLayer API type with more precise methods
@@ -89,6 +89,8 @@ export declare const GoogleTagManagerOptions: import("valibot").ObjectSchema<{
89
89
  readonly envName: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
90
90
  /** Referrer policy for analytics requests */
91
91
  readonly authReferrerPolicy: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
92
+ /** Default consent settings for GTM */
93
+ readonly defaultConsent: import("valibot").OptionalSchema<import("valibot").RecordSchema<import("valibot").StringSchema<undefined>, import("valibot").UnionSchema<[import("valibot").StringSchema<undefined>, import("valibot").NumberSchema<undefined>], undefined>, undefined>, undefined>;
92
94
  }, undefined>;
93
95
  export type GoogleTagManagerInput = RegistryScriptInput<typeof GoogleTagManagerOptions>;
94
96
  /**
@@ -1,6 +1,6 @@
1
1
  import { withQuery } from "ufo";
2
2
  import { useRegistryScript } from "#nuxt-scripts/utils";
3
- import { object, string, optional, boolean, union, literal } from "#nuxt-scripts-validator";
3
+ import { object, string, optional, boolean, union, literal, record, number } from "#nuxt-scripts-validator";
4
4
  export const GoogleTagManagerOptions = object({
5
5
  /** GTM container ID (format: GTM-XXXXXX) */
6
6
  id: string(),
@@ -21,10 +21,12 @@ export const GoogleTagManagerOptions = object({
21
21
  /** Environment name for environment-specific container */
22
22
  envName: optional(string()),
23
23
  /** Referrer policy for analytics requests */
24
- authReferrerPolicy: optional(string())
24
+ authReferrerPolicy: optional(string()),
25
+ /** Default consent settings for GTM */
26
+ defaultConsent: optional(record(string(), union([string(), number()])))
25
27
  });
26
28
  export function useScriptGoogleTagManager(options) {
27
- return useRegistryScript(
29
+ const instance = useRegistryScript(
28
30
  options?.key || "googleTagManager",
29
31
  (opts) => {
30
32
  const dataLayerName = opts?.l ?? opts?.dataLayer ?? "dataLayer";
@@ -54,11 +56,13 @@ export function useScriptGoogleTagManager(options) {
54
56
  },
55
57
  clientInit: import.meta.server ? void 0 : () => {
56
58
  window[dataLayerName] = window[dataLayerName] || [];
57
- function gtag() {
58
- window[dataLayerName].push(arguments);
59
+ function gtag(...args) {
60
+ window[dataLayerName].push(args);
59
61
  }
60
62
  window.gtag = gtag;
61
63
  options?.onBeforeGtmStart?.(gtag);
64
+ if (opts.defaultConsent)
65
+ gtag("consent", "default", opts.defaultConsent);
62
66
  window[dataLayerName].push({
63
67
  "gtm.start": (/* @__PURE__ */ new Date()).getTime(),
64
68
  "event": "gtm.js"
@@ -68,4 +72,10 @@ export function useScriptGoogleTagManager(options) {
68
72
  },
69
73
  options
70
74
  );
75
+ if (import.meta.client && options?.onBeforeGtmStart) {
76
+ const gtag = window.gtag;
77
+ if (gtag)
78
+ options.onBeforeGtmStart(gtag);
79
+ }
80
+ return instance;
71
81
  }
@@ -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
+ }
@@ -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;
@@ -46,7 +46,7 @@ export function useScriptMatomoAnalytics(_options) {
46
46
  _paq.push(["disableCookies"]);
47
47
  }
48
48
  if (options?.trackerUrl || options?.matomoUrl) {
49
- _paq.push(["setTrackerUrl", options?.trackerUrl ? withHttps(options.trackerUrl) : withBase(`/matomo.php`, withHttps(options?.matomoUrl || ""))]);
49
+ _paq.push(["setTrackerUrl", options?.trackerUrl ?? withBase(`/matomo.php`, options?.matomoUrl || "")]);
50
50
  } else if (normalizedCloudId) {
51
51
  _paq.push(["setTrackerUrl", withBase(`/matomo.php`, withHttps(normalizedCloudId))]);
52
52
  }
@@ -74,13 +74,15 @@ export function useScriptPlausibleAnalytics(_options) {
74
74
  use() {
75
75
  return { plausible: window.plausible };
76
76
  },
77
- clientInit() {
78
- window.plausible = window.plausible || function() {
79
- (plausible.q = plausible.q || []).push(arguments);
80
- }, plausible.init = plausible.init || function(i) {
81
- plausible.o = i || {};
77
+ clientInit: import.meta.server ? void 0 : () => {
78
+ const w = window;
79
+ w.plausible = w.plausible || function(...args) {
80
+ (w.plausible.q = w.plausible.q || []).push(args);
82
81
  };
83
- window.plausible.init(initOptions);
82
+ w.plausible.init = w.plausible.init || function(i) {
83
+ w.plausible.o = i || {};
84
+ };
85
+ w.plausible.init(initOptions);
84
86
  }
85
87
  }
86
88
  };
@@ -0,0 +1,26 @@
1
+ import type { PostHog } from 'posthog-js';
2
+ import type { RegistryScriptInput } from '#nuxt-scripts/types';
3
+ export declare const PostHogOptions: import("valibot").ObjectSchema<{
4
+ readonly apiKey: import("valibot").StringSchema<undefined>;
5
+ readonly region: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"us", undefined>, import("valibot").LiteralSchema<"eu", undefined>], undefined>, undefined>;
6
+ readonly autocapture: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
7
+ readonly capturePageview: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
8
+ readonly capturePageleave: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
9
+ readonly disableSessionRecording: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
10
+ readonly config: import("valibot").OptionalSchema<import("valibot").RecordSchema<import("valibot").StringSchema<undefined>, import("valibot").AnySchema, undefined>, undefined>;
11
+ }, undefined>;
12
+ export type PostHogInput = RegistryScriptInput<typeof PostHogOptions, false, true>;
13
+ export interface PostHogApi {
14
+ posthog: PostHog;
15
+ }
16
+ declare global {
17
+ interface Window {
18
+ posthog?: PostHog;
19
+ __posthogInitPromise?: Promise<PostHog | undefined>;
20
+ _posthogQueue?: {
21
+ prop: string | symbol;
22
+ args: any[];
23
+ }[];
24
+ }
25
+ }
26
+ export declare function useScriptPostHog<T extends PostHogApi>(_options?: PostHogInput): import("#nuxt-scripts/types").UseScriptContext<T>;
@@ -0,0 +1,92 @@
1
+ import { any, record, string, object, optional, boolean, union, literal } from "#nuxt-scripts-validator";
2
+ import { useRegistryScript } from "../utils.js";
3
+ import { logger } from "../logger.js";
4
+ export const PostHogOptions = object({
5
+ apiKey: string(),
6
+ region: optional(union([literal("us"), literal("eu")])),
7
+ autocapture: optional(boolean()),
8
+ capturePageview: optional(boolean()),
9
+ capturePageleave: optional(boolean()),
10
+ disableSessionRecording: optional(boolean()),
11
+ config: optional(record(string(), any()))
12
+ });
13
+ export function useScriptPostHog(_options) {
14
+ return useRegistryScript("posthog", (options) => {
15
+ return {
16
+ scriptMode: "npm",
17
+ // Use NPM mode - no external script tag
18
+ schema: import.meta.dev ? PostHogOptions : void 0,
19
+ scriptOptions: {
20
+ use() {
21
+ if (import.meta.server)
22
+ return { posthog: {} };
23
+ if (window.posthog)
24
+ return { posthog: window.posthog };
25
+ const posthog = new Proxy({}, {
26
+ get(_, prop) {
27
+ if (window.posthog)
28
+ return window.posthog[prop];
29
+ if (prop === "then")
30
+ return void 0;
31
+ return (...args) => {
32
+ if (window.posthog)
33
+ return window.posthog[prop](...args);
34
+ window._posthogQueue = window._posthogQueue || [];
35
+ window._posthogQueue.push({ prop, args });
36
+ };
37
+ }
38
+ });
39
+ return { posthog };
40
+ }
41
+ },
42
+ clientInit: import.meta.server ? void 0 : async () => {
43
+ if (window.__posthogInitPromise || window.posthog)
44
+ return;
45
+ if (!options?.apiKey) {
46
+ logger.warn("PostHog apiKey is required");
47
+ return;
48
+ }
49
+ const region = options?.region || "us";
50
+ const apiHost = region === "eu" ? "https://eu.i.posthog.com" : "https://us.i.posthog.com";
51
+ console.log("[PostHog] Starting dynamic import of posthog-js...");
52
+ window.__posthogInitPromise = import("posthog-js").then(({ default: posthog }) => {
53
+ console.log("[PostHog] posthog-js imported successfully");
54
+ const config = {
55
+ api_host: apiHost,
56
+ ...options?.config
57
+ };
58
+ if (typeof options?.autocapture === "boolean")
59
+ config.autocapture = options.autocapture;
60
+ if (typeof options?.capturePageview === "boolean")
61
+ config.capture_pageview = options.capturePageview;
62
+ if (typeof options?.capturePageleave === "boolean")
63
+ config.capture_pageleave = options.capturePageleave;
64
+ if (typeof options?.disableSessionRecording === "boolean")
65
+ config.disable_session_recording = options.disableSessionRecording;
66
+ console.log("[PostHog] Calling posthog.init with apiKey:", options.apiKey, "config:", config);
67
+ const instance = posthog.init(options.apiKey, config);
68
+ if (!instance) {
69
+ logger.error("PostHog init returned undefined - initialization failed");
70
+ delete window._posthogQueue;
71
+ return void 0;
72
+ }
73
+ console.log("[PostHog] posthog.init succeeded, instance:", instance);
74
+ window.posthog = instance;
75
+ if (window._posthogQueue && window._posthogQueue.length > 0) {
76
+ console.log("[PostHog] Flushing", window._posthogQueue.length, "queued calls");
77
+ window._posthogQueue.forEach((q) => window.posthog[q.prop]?.(...q.args));
78
+ delete window._posthogQueue;
79
+ }
80
+ console.log("[PostHog] Initialization complete!");
81
+ return window.posthog;
82
+ }).catch((e) => {
83
+ logger.error("Failed to load posthog-js:", e);
84
+ console.error("[PostHog] Import/init error:", e);
85
+ delete window._posthogQueue;
86
+ return void 0;
87
+ });
88
+ return window.__posthogInitPromise;
89
+ }
90
+ };
91
+ }, _options);
92
+ }
@@ -15,7 +15,39 @@ export const RybbitAnalyticsOptions = object({
15
15
  debounce: optional(number()),
16
16
  apiKey: optional(string())
17
17
  });
18
+ const RYBBIT_QUEUE_KEY = Symbol.for("nuxt-scripts.rybbit-queue");
19
+ function getRybbitState() {
20
+ if (!import.meta.client) return;
21
+ const g = globalThis;
22
+ if (!g[RYBBIT_QUEUE_KEY]) {
23
+ g[RYBBIT_QUEUE_KEY] = { queue: [], flushed: false };
24
+ }
25
+ return g[RYBBIT_QUEUE_KEY];
26
+ }
18
27
  export function useScriptRybbitAnalytics(_options) {
28
+ const isRybbitReady = () => import.meta.client && typeof window !== "undefined" && window.rybbit && typeof window.rybbit.event === "function";
29
+ const flushQueue = () => {
30
+ const state = getRybbitState();
31
+ if (!state || state.flushed || !isRybbitReady()) return;
32
+ state.flushed = true;
33
+ while (state.queue.length > 0) {
34
+ const [method, ...args] = state.queue.shift();
35
+ const fn = window.rybbit[method];
36
+ if (typeof fn === "function") {
37
+ fn.apply(window.rybbit, args);
38
+ }
39
+ }
40
+ };
41
+ const callOrQueue = (method, ...args) => {
42
+ if (isRybbitReady()) {
43
+ const fn = window.rybbit[method];
44
+ if (typeof fn === "function") {
45
+ fn.apply(window.rybbit, args);
46
+ }
47
+ } else {
48
+ getRybbitState()?.queue.push([method, ...args]);
49
+ }
50
+ };
19
51
  return useRegistryScript("rybbitAnalytics", (options) => {
20
52
  return {
21
53
  scriptInput: {
@@ -36,15 +68,13 @@ export function useScriptRybbitAnalytics(_options) {
36
68
  schema: import.meta.dev ? RybbitAnalyticsOptions : void 0,
37
69
  scriptOptions: {
38
70
  use() {
39
- if (typeof window.rybbit === "undefined") {
40
- return null;
41
- }
71
+ flushQueue();
42
72
  return {
43
- pageview: window.rybbit.pageview,
44
- event: window.rybbit.event,
45
- identify: window.rybbit.identify,
46
- clearUserId: window.rybbit.clearUserId,
47
- getUserId: window.rybbit.getUserId,
73
+ pageview: () => callOrQueue("pageview"),
74
+ event: (name, properties) => callOrQueue("event", name, properties),
75
+ identify: (userId) => callOrQueue("identify", userId),
76
+ clearUserId: () => callOrQueue("clearUserId"),
77
+ getUserId: () => window.rybbit?.getUserId?.() ?? null,
48
78
  rybbit: window.rybbit
49
79
  };
50
80
  }