export { r as readCookieFromString, s as serializeCookie } from './cookie-yB16ruKs.js'; import { BuildScriptOptions } from './script.js'; export { ScriptConfig } from './script.js'; import { C as CookieOptions } from './types-BAqJDAl9.js'; /** * Parse the `Sec-CH-Prefers-Color-Scheme` User-Agent Client Hint. When set, * this is the browser's current `prefers-color-scheme` value, so the server * can render the correct theme for first-time visitors who have no cookie. * * The hint is opt-in: the server must first respond with the * `Accept-CH: Sec-CH-Prefers-Color-Scheme` header on a prior request. Most * setups wire this via middleware — see `acceptClientHintsHeader()`. */ declare function readColorSchemeHint(headers: Headers | Record): 'light' | 'dark' | null; /** * Returns the value to send as `Accept-CH` to opt into the * `prefers-color-scheme` client hint on subsequent requests. */ declare function acceptClientHintsHeader(): string; interface GetThemeOptions { cookieName?: string; /** * A raw cookie header string (for custom servers / middleware). If omitted, * the Next.js `cookies()` API is used automatically. */ cookieHeader?: string; /** * Request headers (for custom servers / middleware). When provided, the * `Sec-CH-Prefers-Color-Scheme` client hint is read as a fallback when the * theme cookie is not set. */ headers?: Headers | Record; /** * Whitelist of acceptable theme names. When provided, a cookie value or * client hint that doesn't match (e.g. a stale value from a previous theme * configuration, or a hand-crafted cookie) is treated as missing. * * Without this, server components branching on `getTheme()` could render * with an attribute the runtime would later normalize away — a real * hydration mismatch source. */ themes?: TThemes; } /** * Read the persisted theme for a Next.js request (App Router). * * Two call shapes: * * 1. `getTheme()` / `getTheme(options)` — async. Reads from Next.js's * `cookies()` / `headers()` (or from `options.cookieHeader` if provided). * Use in Server Components and Route Handlers. * * 2. `getTheme(request)` / `getTheme(request, options)` — sync. Reads * directly from the `Request` object's cookie + headers without touching * `next/headers`. Use in middleware, edge functions, and any place where * you have a `Request` but no Next.js async context. * * @example Server component (async) * const theme = await getTheme(); * * @example Middleware (sync, from Request) * export function middleware(request: NextRequest) { * const theme = getTheme(request, { defaultTheme: 'dark' }); * // rewrite, set a header, redirect based on theme, etc. * } * * @example Custom server / explicit options (async) * const theme = await getTheme({ * cookieHeader: request.headers.get('cookie') ?? '', * headers: request.headers, * }); */ declare function getTheme(request: Request, options: GetThemeOptions & { themes: TThemes; }): TThemes[number] | 'system' | null; declare function getTheme(request: Request, options?: GetThemeOptions): string | null; declare function getTheme(options: GetThemeOptions & { themes: TThemes; }): Promise; declare function getTheme(options?: GetThemeOptions): Promise; interface SetThemeCookieOptions extends CookieOptions { cookieName?: string; } /** * Serialize a `Set-Cookie` header value for the theme cookie. Does not touch * response objects — the caller is responsible for attaching the header. Use * this in route handlers, server actions, and edge middleware when running in * hybrid/cookie storage mode. */ declare function setThemeCookie(theme: string, options?: SetThemeCookieOptions): string; /** * Write the theme cookie directly via the Next.js `cookies()` API. Only * callable in Server Actions and Route Handlers (not in Server Components). * No-op when `next/headers` is unavailable. */ declare function writeThemeCookie(theme: string, options?: SetThemeCookieOptions): Promise; /** * Build the inline anti-FOUC script as an HTML-safe string. Place this * inside the `` of your root layout — that is where it can run * synchronously before the browser paints any body pixels, eliminating * the dark → light → dark flicker that `useServerInsertedHTML` placement * inside `` allows. * * Recommended usage in Next.js App Router: * * ```tsx * // app/layout.tsx * import { getTheme, getThemeScript } from '@teispace/next-themes/server'; * * export default async function RootLayout({ children }) { * const initialTheme = await getTheme(); * const script = getThemeScript({ attribute: 'class', initialTheme }); * return ( * * *