{"version":3,"file":"Asset.cjs","names":[],"sources":["../../src/Asset.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport { useHydrated } from './ClientOnly'\nimport type { RouterManagedTag } from '@tanstack/router-core'\n\nconst INLINE_CSS_HYDRATION_ATTR = 'data-tsr-inline-css'\n\ninterface ScriptAttrs {\n [key: string]: string | boolean | undefined\n src?: string\n suppressHydrationWarning?: boolean\n}\n\nconst noopScriptHandler = () => {}\n\nfunction setScriptAttrs(\n script: HTMLScriptElement,\n attrs: ScriptAttrs | undefined,\n) {\n if (!attrs) {\n return\n }\n\n for (const [key, value] of Object.entries(attrs)) {\n if (\n key !== 'suppressHydrationWarning' &&\n value !== undefined &&\n value !== false\n ) {\n script.setAttribute(key, typeof value === 'boolean' ? '' : String(value))\n }\n }\n}\n\nexport function Asset(\n asset: RouterManagedTag & {\n nonce?: string\n preventScriptHoist?: boolean\n },\n): React.ReactElement | null {\n const { attrs, children, nonce, preventScriptHoist } = asset\n\n switch (asset.tag) {\n case 'title':\n return (\n \n {children}\n \n )\n case 'meta':\n return \n case 'link':\n return (\n \n )\n case 'style':\n if (\n asset.inlineCss &&\n (process.env.TSS_INLINE_CSS_ENABLED === 'true' ||\n (process.env.TSS_INLINE_CSS_ENABLED === undefined && isServer))\n ) {\n return (\n \n {children}\n \n )\n }\n\n return (\n \n )\n case 'script':\n return (\n \n )\n default:\n return null\n }\n}\n\nfunction InlineCssStyle({\n attrs,\n children,\n nonce,\n}: {\n attrs?: Record\n children?: RouterManagedTag['children']\n nonce?: string\n}) {\n const isInlineCssPlaceholder = children === undefined\n const [hydratedInlineCss] = React.useState(() => {\n if (!isInlineCssPlaceholder || typeof document === 'undefined') {\n return undefined\n }\n\n return (\n document.querySelector(\n `style[${INLINE_CSS_HYDRATION_ATTR}]`,\n )?.textContent ?? undefined\n )\n })\n const html = isInlineCssPlaceholder\n ? (hydratedInlineCss ?? '')\n : (children ?? '')\n\n return (\n \n )\n}\n\nfunction Script({\n attrs,\n children,\n preventScriptHoist,\n}: {\n attrs?: ScriptAttrs\n children?: string\n preventScriptHoist?: boolean\n}) {\n const router = useRouter()\n const hydrated = useHydrated()\n const dataScript =\n typeof attrs?.type === 'string' &&\n attrs.type !== '' &&\n attrs.type !== 'text/javascript' &&\n attrs.type !== 'module'\n\n if (\n process.env.NODE_ENV !== 'production' &&\n attrs?.src &&\n typeof children === 'string' &&\n children.trim().length\n ) {\n console.warn(\n '[TanStack Router]