UNPKG

@nuxt/scripts

Version:

Load third-party scripts with better performance, privacy and DX in Nuxt Apps.

31 lines (30 loc) 830 B
import { useRegistryScript } from "../utils.js"; import { minLength, object, string, pipe } from "#nuxt-scripts-validator"; export const ClarityOptions = object({ /** * The Clarity token. */ id: pipe(string(), minLength(10)) }); export function useScriptClarity(_options) { return useRegistryScript( "clarity", (options) => ({ scriptInput: { src: `https://www.clarity.ms/tag/${options.id}` }, schema: import.meta.dev ? ClarityOptions : void 0, scriptOptions: { use() { return { clarity: window.clarity }; } }, clientInit: import.meta.server ? void 0 : () => { window.clarity = window.clarity || function(...params) { (window.clarity.q = window.clarity.q || []).push(params); }; } }), _options ); }