@vercel/speed-insights 2.0.0-canary.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +1 -1
- package/dist/next/index.mjs.map +1 -1
- package/dist/nuxt/runtime/index.js +1 -1
- package/dist/nuxt/runtime/index.js.map +1 -1
- package/dist/nuxt/runtime/index.mjs +1 -1
- package/dist/nuxt/runtime/index.mjs.map +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +1 -1
- package/dist/react/index.mjs.map +1 -1
- package/dist/remix/index.js +1 -1
- package/dist/remix/index.js.map +1 -1
- package/dist/remix/index.mjs +1 -1
- package/dist/remix/index.mjs.map +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/dist/sveltekit/index.js.map +1 -1
- package/dist/sveltekit/index.mjs +1 -1
- package/dist/sveltekit/index.mjs.map +1 -1
- package/dist/vue/index.js +1 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +1 -1
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generic.ts","../src/queue.ts","../package.json","../src/utils.ts"],"sourcesContent":["import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0-canary.1\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,WAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;;;ACPE,WAAQ;AACR,cAAW;;;ACKN,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;AAEO,SAAS,aACd,UACA,YACe;AACf,MAAI,CAAC,YAAY,CAAC,YAAY;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AACb,MAAI;AACF,UAAM,UAAU,OAAO,QAAQ,UAAU;AAEzC,eAAW,CAAC,KAAK,KAAK,KAAK,SA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D,GAAG;AAAA,IAC3D;AAAA,EACF;AAEA,WAAS,KAAK,YAAY,MAAM;AAEhC,SAAO;AAAA,IACL,UAAU,CAAC,UAA+B;AACxC,aAAO,QAAQ,QAAQ,SAAS;AAAA,IAClC;AAAA,EACF;AACF;AAKA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/generic.ts","../src/queue.ts","../package.json","../src/utils.ts"],"sourcesContent":["import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,WAAO,MAAM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IAAI,GAAG;AACb;;;AHrIA,SAAS,oBACP,QAAkC,CAAC,GACnC,YAGO;AAvBT;AAyBE,MAAI,CAAC,UAAU,KAAK,MAAM,UAAU,KAAM,QAAO;AAEjD,YAAU;AAEV,QAAM,EAAE,YAAY,KAAK,QAAQ,IAAI,UAAU,OAAO,UAAU;AAEhE,MAAI,SAAS,KAAK,cAAc,gBAAgB,GAAG,IAAI,EAAG,QAAO;AAEjE,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AAEA,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAGf,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,WAAO,QAAQ,GAAG,IAAI;AAAA,EACxB;AAEA,SAAO,UAAU,MAAY;AAC3B,YAAQ;AAAA,MACN,sDAAsD,GAAG;AAAA,IAC3D;AAAA,EACF;AAEA,WAAS,KAAK,YAAY,MAAM;AAEhC,SAAO;AAAA,IACL,UAAU,CAAC,UAA+B;AACxC,aAAO,QAAQ,QAAQ,SAAS;AAAA,IAClC;AAAA,EACF;AACF;AAKA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queue.ts","../package.json","../src/utils.ts","../src/generic.ts"],"sourcesContent":["export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0-canary.1\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n"],"mappings":";AAAO,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,WAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;;;ACPE,WAAQ;AACR,cAAW;;;ACKN,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;AAEO,SAAS,aACd,UACA,YACe;AACf,MAAI,CAAC,YAAY,CAAC,YAAY;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AACb,MAAI;AACF,UAAM,UAAU,OAAO,QAAQ,UAAU;AAEzC,eAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,UAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,cAAM,UAAU,kBAAkB,KAAK;AACvC,YAAI,QAAQ,KAA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+B;AACxC,aAAO,QAAQ,QAAQ,SAAS;AAAA,IAClC;AAAA,EACF;AACF;AAKA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/queue.ts","../package.json","../src/utils.ts","../src/generic.ts"],"sourcesContent":["export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n"],"mappings":";AAAO,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,WAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;;;ACPE,WAAQ;AACR,cAAW;;;ACKN,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AAC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QAAQ,IAAI,UAAU,OAAO,UAAU;AAEhE,MAAI,SAAS,KAAK,cAAc,gBAAgB,GAAG,IAAI,EAAG,QAAO;AAEjE,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AAEA,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAGf,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,WAAO,QAAQ,GAAG,IAAI;AAAA,EACxB;AAEA,SAAO,UAAU,MAAY;AAC3B,YAAQ;AAAA,MACN,sDAAsD,GAAG;AAAA,IAC3D;AAAA,EACF;AAEA,WAAS,KAAK,YAAY,MAAM;AAEhC,SAAO;AAAA,IACL,UAAU,CAAC,UAA+B;AACxC,aAAO,QAAQ,QAAQ,SAAS;AAAA,IAClC;AAAA,EACF;AACF;AAKA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":[]}
|
package/dist/next/index.js
CHANGED
package/dist/next/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../src/queue.ts","../../package.json","../../src/utils.ts","../../src/generic.ts","../../src/react/utils.ts","../../src/nextjs/utils.ts"],"sourcesContent":["'use client';\n\nimport React, { Suspense } from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { getBasePath, getConfigString, useRoute } from './utils';\n\ntype Props = Omit<SpeedInsightsProps, 'route'>;\n\nfunction SpeedInsightsComponent(props: Props): React.ReactElement {\n const route = useRoute();\n\n return (\n <SpeedInsightsScript\n route={route}\n {...props}\n framework=\"next\"\n basePath={getBasePath()}\n configString={getConfigString()}\n />\n );\n}\n\nexport function SpeedInsights(props: Props): null {\n // Because of incompatible types between ReactNode in React 19 and React 18 we return null (which is also what we render)\n return (\n <Suspense fallback={null}>\n <SpeedInsightsComponent {...props} />\n </Suspense>\n ) as never;\n}\n","'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { computeRoute, injectSpeedInsights } from '../generic';\nimport type { SpeedInsightsProps } from '../types';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function SpeedInsights(\n props: SpeedInsightsProps & {\n framework?: string;\n basePath?: string;\n configString?: string; // Internal only, passed from framework wrappers\n },\n): JSX.Element | null {\n useEffect(() => {\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n }, [props.beforeSend]);\n\n const setScriptRoute = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n if (!setScriptRoute.current) {\n const script = injectSpeedInsights(\n {\n framework: props.framework ?? 'react',\n basePath: props.basePath ?? getBasePath(),\n ...props,\n },\n props.configString ?? getConfigString(),\n );\n if (script) {\n setScriptRoute.current = script.setRoute;\n }\n }\n }, [props]);\n useEffect(() => {\n if (setScriptRoute.current && props.route) {\n setScriptRoute.current(props.route);\n }\n }, [props.route]);\n\n return null;\n}\n\nexport { computeRoute };\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0-canary.1\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n","'use client';\nimport { useParams, usePathname, useSearchParams } from 'next/navigation.js';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const searchParams = useSearchParams() || new URLSearchParams();\n const path = usePathname();\n // Until we have route parameters, we don't compute the route\n if (!params) {\n return null;\n }\n // in Next.js@13, useParams() could return an empty object for pages router, and we default to searchParams.\n const finalParams = Object.keys(params).length\n ? params\n : Object.fromEntries(searchParams.entries());\n return computeRoute(path, finalParams);\n};\n\n// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uBAAAA;AAAA;AAAA;AAEA,IAAAC,gBAAgC;;;ACAhC,mBAAkC;;;ACF3B,IAAM,YAAY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MACJ,WAAU;AAAA,MACV,UAAUC,aAAY;AAAA,MACtB,cAAcC,iBAAgB;AAAA;AAAA,EAChC;AAEJ;AAEO,SAASC,eAAc,OAAoB;AAEhD,SACE,8BAAAH,QAAA,cAAC,0BAAS,UAAU,QAClB,8BAAAA,QAAA,cAAC,0BAAwB,GAAG,OAAO,CACrC;AAEJ;","names":["SpeedInsights","import_react","getBasePath","getConfigString","React","getBasePath","getConfigString","SpeedInsights"]}
|
|
1
|
+
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../src/queue.ts","../../package.json","../../src/utils.ts","../../src/generic.ts","../../src/react/utils.ts","../../src/nextjs/utils.ts"],"sourcesContent":["'use client';\n\nimport React, { Suspense } from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { getBasePath, getConfigString, useRoute } from './utils';\n\ntype Props = Omit<SpeedInsightsProps, 'route'>;\n\nfunction SpeedInsightsComponent(props: Props): React.ReactElement {\n const route = useRoute();\n\n return (\n <SpeedInsightsScript\n route={route}\n {...props}\n framework=\"next\"\n basePath={getBasePath()}\n configString={getConfigString()}\n />\n );\n}\n\nexport function SpeedInsights(props: Props): null {\n // Because of incompatible types between ReactNode in React 19 and React 18 we return null (which is also what we render)\n return (\n <Suspense fallback={null}>\n <SpeedInsightsComponent {...props} />\n </Suspense>\n ) as never;\n}\n","'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { computeRoute, injectSpeedInsights } from '../generic';\nimport type { SpeedInsightsProps } from '../types';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function SpeedInsights(\n props: SpeedInsightsProps & {\n framework?: string;\n basePath?: string;\n configString?: string; // Internal only, passed from framework wrappers\n },\n): JSX.Element | null {\n useEffect(() => {\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n }, [props.beforeSend]);\n\n const setScriptRoute = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n if (!setScriptRoute.current) {\n const script = injectSpeedInsights(\n {\n framework: props.framework ?? 'react',\n basePath: props.basePath ?? getBasePath(),\n ...props,\n },\n props.configString ?? getConfigString(),\n );\n if (script) {\n setScriptRoute.current = script.setRoute;\n }\n }\n }, [props]);\n useEffect(() => {\n if (setScriptRoute.current && props.route) {\n setScriptRoute.current(props.route);\n }\n }, [props.route]);\n\n return null;\n}\n\nexport { computeRoute };\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n","'use client';\nimport { useParams, usePathname, useSearchParams } from 'next/navigation.js';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const searchParams = useSearchParams() || new URLSearchParams();\n const path = usePathname();\n // Until we have route parameters, we don't compute the route\n if (!params) {\n return null;\n }\n // in Next.js@13, useParams() could return an empty object for pages router, and we default to searchParams.\n const finalParams = Object.keys(params).length\n ? params\n : Object.fromEntries(searchParams.entries());\n return computeRoute(path, finalParams);\n};\n\n// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uBAAAA;AAAA;AAAA;AAEA,IAAAC,gBAAgC;;;ACAhC,mBAAkC;;;ACF3B,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,WAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;;;ACPE,WAAQ;AACR,cAAW;;;ACKN,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO;A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WAAW,MAAM,OAAO;AACzC,qBAAe,QAAQ,MAAM,KAAK;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,MAAM,KAAK,CAAC;AAEhB,SAAO;AACT;;;AM1CA,wBAAwD;AAGjD,IAAM,WAAW,MAAqB;AAC3C,QAAM,aAAS,6BAAU;AACzB,QAAM,mBAAe,mCAAgB,KAAK,IAAI,gBAAgB;AAC9D,QAAM,WAAO,+BAAY;AAEzB,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,OAAO,KAAK,MAAM,EAAE,SACpC,SACA,OAAO,YAAY,aAAa,QAAQ,CAAC;AAC7C,SAAO,aAAa,MAAM,WAAW;AACvC;AAMO,SAASC,eAAkC;AAChD,MAAI,OAAO,YAAY,eAAe,OAAO,QAAQ,QAAQ,aAAa;AACxE,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,IAAI;AACrB;AAEO,SAASC,mBAAsC;AACpD,MAAI,OAAO,YAAY,eAAe,OAAO,QAAQ,QAAQ,aAAa;AACxE,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,IAAI;AACrB;;;AP1BA,SAAS,uBAAuB,OAAkC;AAChE,QAAM,QAAQ,SAAS;AAEvB,SACE,8BAAAC,QAAA;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACC,GAAG;AAAA,MACJ,WAAU;AAAA,MACV,UAAUC,aAAY;AAAA,MACtB,cAAcC,iBAAgB;AAAA;AAAA,EAChC;AAEJ;AAEO,SAASC,eAAc,OAAoB;AAEhD,SACE,8BAAAH,QAAA,cAAC,0BAAS,UAAU,QAClB,8BAAAA,QAAA,cAAC,0BAAwB,GAAG,OAAO,CACrC;AAEJ;","names":["SpeedInsights","import_react","getBasePath","getConfigString","React","getBasePath","getConfigString","SpeedInsights"]}
|
package/dist/next/index.mjs
CHANGED
package/dist/next/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../src/queue.ts","../../package.json","../../src/utils.ts","../../src/generic.ts","../../src/react/utils.ts","../../src/nextjs/utils.ts"],"sourcesContent":["'use client';\n\nimport React, { Suspense } from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { getBasePath, getConfigString, useRoute } from './utils';\n\ntype Props = Omit<SpeedInsightsProps, 'route'>;\n\nfunction SpeedInsightsComponent(props: Props): React.ReactElement {\n const route = useRoute();\n\n return (\n <SpeedInsightsScript\n route={route}\n {...props}\n framework=\"next\"\n basePath={getBasePath()}\n configString={getConfigString()}\n />\n );\n}\n\nexport function SpeedInsights(props: Props): null {\n // Because of incompatible types between ReactNode in React 19 and React 18 we return null (which is also what we render)\n return (\n <Suspense fallback={null}>\n <SpeedInsightsComponent {...props} />\n </Suspense>\n ) as never;\n}\n","'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { computeRoute, injectSpeedInsights } from '../generic';\nimport type { SpeedInsightsProps } from '../types';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function SpeedInsights(\n props: SpeedInsightsProps & {\n framework?: string;\n basePath?: string;\n configString?: string; // Internal only, passed from framework wrappers\n },\n): JSX.Element | null {\n useEffect(() => {\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n }, [props.beforeSend]);\n\n const setScriptRoute = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n if (!setScriptRoute.current) {\n const script = injectSpeedInsights(\n {\n framework: props.framework ?? 'react',\n basePath: props.basePath ?? getBasePath(),\n ...props,\n },\n props.configString ?? getConfigString(),\n );\n if (script) {\n setScriptRoute.current = script.setRoute;\n }\n }\n }, [props]);\n useEffect(() => {\n if (setScriptRoute.current && props.route) {\n setScriptRoute.current(props.route);\n }\n }, [props.route]);\n\n return null;\n}\n\nexport { computeRoute };\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0-canary.1\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n","'use client';\nimport { useParams, usePathname, useSearchParams } from 'next/navigation.js';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const searchParams = useSearchParams() || new URLSearchParams();\n const path = usePathname();\n // Until we have route parameters, we don't compute the route\n if (!params) {\n return null;\n }\n // in Next.js@13, useParams() could return an empty object for pages router, and we default to searchParams.\n const finalParams = Object.keys(params).length\n ? params\n : Object.fromEntries(searchParams.entries());\n return computeRoute(path, finalParams);\n};\n\n// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n"],"mappings":";;;AAEA,OAAO,SAAS,gBAAgB;;;ACAhC,SAAS,WAAW,cAAc;;;ACF3B,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,WAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;;;ACPE,WAAQ;AACR,cAAW;;;ACKN,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;AAEO,SAAS,aACd,UACA,YACe;AACf,MAAI,CAAC,YAAY,CAAC,YAAY;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AACb,MAAI;AACF,UAAM,UAAU,OAAO,QAAQ,UAAU;AAEzC,eAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,UAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,cAAM,UAAU,kBAAkB,KAAK;AACvC,YAAI,QAAQ,KAAK,MAAM,GAAG;AACxB,mBAAS,OAAO,Q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YAAY,aAAa,QAAQ,CAAC;AAC7C,SAAO,aAAa,MAAM,WAAW;AACvC;AAMO,SAASA,eAAkC;AAChD,MAAI,OAAO,YAAY,eAAe,OAAO,QAAQ,QAAQ,aAAa;AACxE,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,IAAI;AACrB;AAEO,SAASC,mBAAsC;AACpD,MAAI,OAAO,YAAY,eAAe,OAAO,QAAQ,QAAQ,aAAa;AACxE,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,IAAI;AACrB;;;AP1BA,SAAS,uBAAuB,OAAkC;AAChE,QAAM,QAAQ,SAAS;AAEvB,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACC,GAAG;AAAA,MACJ,WAAU;AAAA,MACV,UAAUC,aAAY;AAAA,MACtB,cAAcC,iBAAgB;AAAA;AAAA,EAChC;AAEJ;AAEO,SAASC,eAAc,OAAoB;AAEhD,SACE,oCAAC,YAAS,UAAU,QAClB,oCAAC,0BAAwB,GAAG,OAAO,CACrC;AAEJ;","names":["getBasePath","getConfigString","getBasePath","getConfigString","SpeedInsights"]}
|
|
1
|
+
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../src/queue.ts","../../package.json","../../src/utils.ts","../../src/generic.ts","../../src/react/utils.ts","../../src/nextjs/utils.ts"],"sourcesContent":["'use client';\n\nimport React, { Suspense } from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { getBasePath, getConfigString, useRoute } from './utils';\n\ntype Props = Omit<SpeedInsightsProps, 'route'>;\n\nfunction SpeedInsightsComponent(props: Props): React.ReactElement {\n const route = useRoute();\n\n return (\n <SpeedInsightsScript\n route={route}\n {...props}\n framework=\"next\"\n basePath={getBasePath()}\n configString={getConfigString()}\n />\n );\n}\n\nexport function SpeedInsights(props: Props): null {\n // Because of incompatible types between ReactNode in React 19 and React 18 we return null (which is also what we render)\n return (\n <Suspense fallback={null}>\n <SpeedInsightsComponent {...props} />\n </Suspense>\n ) as never;\n}\n","'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { computeRoute, injectSpeedInsights } from '../generic';\nimport type { SpeedInsightsProps } from '../types';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function SpeedInsights(\n props: SpeedInsightsProps & {\n framework?: string;\n basePath?: string;\n configString?: string; // Internal only, passed from framework wrappers\n },\n): JSX.Element | null {\n useEffect(() => {\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n }, [props.beforeSend]);\n\n const setScriptRoute = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n if (!setScriptRoute.current) {\n const script = injectSpeedInsights(\n {\n framework: props.framework ?? 'react',\n basePath: props.basePath ?? getBasePath(),\n ...props,\n },\n props.configString ?? getConfigString(),\n );\n if (script) {\n setScriptRoute.current = script.setRoute;\n }\n }\n }, [props]);\n useEffect(() => {\n if (setScriptRoute.current && props.route) {\n setScriptRoute.current(props.route);\n }\n }, [props.route]);\n\n return null;\n}\n\nexport { computeRoute };\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n","'use client';\nimport { useParams, usePathname, useSearchParams } from 'next/navigation.js';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const searchParams = useSearchParams() || new URLSearchParams();\n const path = usePathname();\n // Until we have route parameters, we don't compute the route\n if (!params) {\n return null;\n }\n // in Next.js@13, useParams() could return an empty object for pages router, and we default to searchParams.\n const finalParams = Object.keys(params).length\n ? params\n : Object.fromEntries(searchParams.entries());\n return computeRoute(path, finalParams);\n};\n\n// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n"],"mappings":";;;AAEA,OAAO,SAAS,gBAAgB;;;ACAhC,SAAS,WAAW,cAAc;;;ACF3B,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,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A;AAAA,EAChC;AAEJ;AAEO,SAASC,eAAc,OAAoB;AAEhD,SACE,oCAAC,YAAS,UAAU,QAClB,oCAAC,0BAAwB,GAAG,OAAO,CACrC;AAEJ;","names":["getBasePath","getConfigString","getBasePath","getConfigString","SpeedInsights"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/nuxt/runtime/index.ts","../../../src/queue.ts","../../../package.json","../../../src/utils.ts","../../../src/generic.ts","../../../src/vue/create-component.ts","../../../src/vue/utils.ts","../../../src/nuxt/runtime/utils.ts"],"sourcesContent":["import { useRoute, useRouter } from 'nuxt/app';\nimport {\n type BeforeSendMiddleware,\n injectSpeedInsights as inject,\n} from '../../generic';\nimport type { SpeedInsightsProps } from '../../types';\nimport { computeRoute, isBrowser } from '../../utils';\nimport { createComponent } from '../../vue/create-component';\nimport { getBasePath, getConfigString } from './utils';\n\nexport const SpeedInsights = createComponent('nuxt');\nexport type { SpeedInsightsProps, BeforeSendMiddleware };\n\n// Export the injectSpeedInsights script with automatic tracking on page changes\nfunction injectSpeedInsights(\n props: Omit<SpeedInsightsProps, 'framework'> = {},\n): void {\n if (isBrowser()) {\n const router = useRouter();\n const route = useRoute();\n\n const speedInsights = inject(\n {\n ...props,\n route: computeRoute(route.path, route.params),\n framework: 'nuxt',\n basePath: getBasePath(),\n },\n getConfigString(),\n );\n // On navigation to a new page\n router.afterEach((to) => {\n speedInsights?.setRoute(computeRoute(to.path, to.params));\n });\n }\n}\n\nexport { injectSpeedInsights };\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0-canary.1\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","import { defineComponent, watch } from 'vue';\n// for barebone vue project, vite will issue a warning since 'vue-router' import can't be resolved,\nimport { useRoute } from 'vue-router';\nimport { injectSpeedInsights, type SpeedInsightsProps } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function createComponent(\n framework = 'vue',\n): ReturnType<typeof defineComponent> {\n return defineComponent({\n props: [\n 'dsn',\n 'sampleRate',\n 'beforeSend',\n 'debug',\n 'scriptSrc',\n 'endpoint',\n ],\n setup(props: Omit<SpeedInsightsProps, 'framework'>) {\n const route = useRoute();\n const configure = injectSpeedInsights(\n {\n ...Object.fromEntries(\n // trim out undefined values to avoid overriding config values\n Object.entries(props).filter(([_, v]) => v !== undefined),\n ),\n framework,\n basePath: getBasePath(),\n },\n getConfigString(),\n );\n if (route && configure) {\n const changeRoute = (): void => {\n configure.setRoute(computeRoute(route.path, route.params));\n };\n\n changeRoute();\n watch(route, changeRoute);\n }\n },\n // Vue component must have a render function, or a template.\n render() {\n return null;\n },\n });\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,6BAAAA;AAAA;AAAA;AAAA,iBAAoC;;;ACA7B,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,WAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;;;ACPE,WAAQ;AACR,cAAW;;;ACKN,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;AAEO,SAAS,aACd,UACA,YACe;AACf,MAAI,CAAC,YAAY,CAAC,YAAY;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AACb,MAAI;AACF,UAAM,UAAU,OAAO,QAAQ,UAAU;AAEzC,eAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,UAAI,CAAC,MAAM,QAAQ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,EAER;AACF;;;APZO,IAAM,gBAAgB,gBAAgB,MAAM;AAInD,SAASG,qBACP,QAA+C,CAAC,GAC1C;AACN,MAAI,UAAU,GAAG;AACf,UAAM,aAAS,sBAAU;AACzB,UAAM,YAAQ,qBAAS;AAEvB,UAAM,gBAAgB;AAAA,MACpB;AAAA,QACE,GAAG;AAAA,QACH,OAAO,aAAa,MAAM,MAAM,MAAM,MAAM;AAAA,QAC5C,WAAW;AAAA,QACX,UAAUC,aAAY;AAAA,MACxB;AAAA,MACAC,iBAAgB;AAAA,IAClB;AAEA,WAAO,UAAU,CAAC,OAAO;AACvB,qDAAe,SAAS,aAAa,GAAG,MAAM,GAAG,MAAM;AAAA,IACzD,CAAC;AAAA,EACH;AACF;","names":["injectSpeedInsights","import_meta","getBasePath","getConfigString","injectSpeedInsights","getBasePath","getConfigString"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/nuxt/runtime/index.ts","../../../src/queue.ts","../../../package.json","../../../src/utils.ts","../../../src/generic.ts","../../../src/vue/create-component.ts","../../../src/vue/utils.ts","../../../src/nuxt/runtime/utils.ts"],"sourcesContent":["import { useRoute, useRouter } from 'nuxt/app';\nimport {\n type BeforeSendMiddleware,\n injectSpeedInsights as inject,\n} from '../../generic';\nimport type { SpeedInsightsProps } from '../../types';\nimport { computeRoute, isBrowser } from '../../utils';\nimport { createComponent } from '../../vue/create-component';\nimport { getBasePath, getConfigString } from './utils';\n\nexport const SpeedInsights = createComponent('nuxt');\nexport type { SpeedInsightsProps, BeforeSendMiddleware };\n\n// Export the injectSpeedInsights script with automatic tracking on page changes\nfunction injectSpeedInsights(\n props: Omit<SpeedInsightsProps, 'framework'> = {},\n): void {\n if (isBrowser()) {\n const router = useRouter();\n const route = useRoute();\n\n const speedInsights = inject(\n {\n ...props,\n route: computeRoute(route.path, route.params),\n framework: 'nuxt',\n basePath: getBasePath(),\n },\n getConfigString(),\n );\n // On navigation to a new page\n router.afterEach((to) => {\n speedInsights?.setRoute(computeRoute(to.path, to.params));\n });\n }\n}\n\nexport { injectSpeedInsights };\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n window.siq = window.siq || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","import { defineComponent, watch } from 'vue';\n// for barebone vue project, vite will issue a warning since 'vue-router' import can't be resolved,\nimport { useRoute } from 'vue-router';\nimport { injectSpeedInsights, type SpeedInsightsProps } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function createComponent(\n framework = 'vue',\n): ReturnType<typeof defineComponent> {\n return defineComponent({\n props: [\n 'dsn',\n 'sampleRate',\n 'beforeSend',\n 'debug',\n 'scriptSrc',\n 'endpoint',\n ],\n setup(props: Omit<SpeedInsightsProps, 'framework'>) {\n const route = useRoute();\n const configure = injectSpeedInsights(\n {\n ...Object.fromEntries(\n // trim out undefined values to avoid overriding config values\n Object.entries(props).filter(([_, v]) => v !== undefined),\n ),\n framework,\n basePath: getBasePath(),\n },\n getConfigString(),\n );\n if (route && configure) {\n const changeRoute = (): void => {\n configure.setRoute(computeRoute(route.path, route.params));\n };\n\n changeRoute();\n watch(route, changeRoute);\n }\n },\n // Vue component must have a render function, or a template.\n render() {\n return null;\n },\n });\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,6BAAAA;AAAA;AAAA;AAAA,iBAAoC;;;ACA7B,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,WAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;;;ACPE,WAAQ;AACR,cAAW;;;ACKN,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,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AEA,oBAAY;AACZ,8BAAM,OAAO,WAAW;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA,IAEA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;;;AE9CA,IAAAC,eAAA;AAIO,SAASC,eAAkC;AAChD,MAAI;AACF,WAAOD,aAAY,IAAI;AAAA,EAGzB,QAAQ;AAAA,EAER;AACF;AAEO,SAASE,mBAAsC;AACpD,MAAI;AACF,WAAOF,aAAY,IAAI;AAAA,EAGzB,QAAQ;AAAA,EAER;AACF;;;APZO,IAAM,gBAAgB,gBAAgB,MAAM;AAInD,SAASG,qBACP,QAA+C,CAAC,GAC1C;AACN,MAAI,UAAU,GAAG;AACf,UAAM,aAAS,sBAAU;AACzB,UAAM,YAAQ,qBAAS;AAEvB,UAAM,gBAAgB;AAAA,MACpB;AAAA,QACE,GAAG;AAAA,QACH,OAAO,aAAa,MAAM,MAAM,MAAM,MAAM;AAAA,QAC5C,WAAW;AAAA,QACX,UAAUC,aAAY;AAAA,MACxB;AAAA,MACAC,iBAAgB;AAAA,IAClB;AAEA,WAAO,UAAU,CAAC,OAAO;AACvB,qDAAe,SAAS,aAAa,GAAG,MAAM,GAAG,MAAM;AAAA,IACzD,CAAC;AAAA,EACH;AACF;","names":["injectSpeedInsights","import_meta","getBasePath","getConfigString","injectSpeedInsights","getBasePath","getConfigString"]}
|