export { r as readCookieFromString, s as serializeCookie } from './cookie-DNTiDFmm.js';
import { THEME_SCRIPT_ATTRIBUTE, BuildScriptOptions } from './script.js';
export { ScriptConfig } from './script.js';
import { C as CookieOptions } from './types-BK2-7cKa.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<string, string>): '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<TThemes extends readonly string[] = readonly string[]> {
    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<string, string>;
    /**
     * 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<const TThemes extends readonly string[]>(request: Request, options: GetThemeOptions<TThemes> & {
    themes: TThemes;
}): TThemes[number] | 'system' | null;
declare function getTheme(request: Request, options?: GetThemeOptions): string | null;
declare function getTheme<const TThemes extends readonly string[]>(options: GetThemeOptions<TThemes> & {
    themes: TThemes;
}): Promise<TThemes[number] | 'system' | null>;
declare function getTheme(options?: GetThemeOptions): Promise<string | null>;
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<void>;
/**
 * Build the inline anti-FOUC script as an HTML-safe string, with the
 * configuration baked into the text.
 *
 * Because the text depends on the configuration, a hash-based CSP needs a
 * hash per configuration. Prefer {@link getThemeScriptProps}, whose script
 * text never changes and is covered by the single {@link getThemeScriptHash}.
 *
 * If you render the script yourself, pass `noScript` to the `ThemeProvider`
 * so it does not inject a second copy, and pass the same configuration to both
 * call sites (or use `createThemes()` so it lives in one place).
 */
declare function getThemeScript(options?: BuildScriptOptions): string;
interface ThemeScriptProps {
    [THEME_SCRIPT_ATTRIBUTE]: string;
    'data-cfasync': 'false';
    nonce?: string;
    suppressHydrationWarning: true;
    dangerouslySetInnerHTML: {
        __html: string;
    };
}
/**
 * Props for a `<script>` element that runs the anti-FOUC script. Spread them
 * onto a `<script>` in the `<head>` of your root layout — that placement runs
 * before the browser paints any body pixels — and pass `noScript` to the
 * provider so it does not inject a second copy:
 *
 * ```tsx
 * // app/layout.tsx
 * import { getTheme, getThemeScriptProps } from '@teispace/next-themes/server';
 *
 * export default async function RootLayout({ children }) {
 *   const initialTheme = await getTheme();
 *   return (
 *     <html lang="en" suppressHydrationWarning>
 *       <head>
 *         <script {...getThemeScriptProps({ attribute: 'class', initialTheme })} />
 *       </head>
 *       <body>
 *         <Providers initialTheme={initialTheme} noScript>{children}</Providers>
 *       </body>
 *     </html>
 *   );
 * }
 * ```
 *
 * The script text is the same for every configuration (the configuration
 * travels in a `data-` attribute), so under a hash-based CSP a single
 * `script-src` entry — {@link getThemeScriptHash} — allows it everywhere.
 * Under a nonce-based CSP pass `nonce` instead.
 */
declare function getThemeScriptProps(options?: BuildScriptOptions & {
    nonce?: string;
}): ThemeScriptProps;
/**
 * The CSP source expression (`'sha256-…'`) that allows the anti-FOUC script
 * the providers and {@link getThemeScriptProps} render. Add it to `script-src`
 * and the script runs under a hash-based policy with no nonce — which also
 * means pages can stay statically rendered.
 *
 * It does not cover {@link getThemeScript}, whose text varies with the
 * configuration.
 */
declare function getThemeScriptHash(): string;

export { BuildScriptOptions, CookieOptions, acceptClientHintsHeader, getTheme, getThemeScript, getThemeScriptHash, getThemeScriptProps, readColorSchemeHint, setThemeCookie, writeThemeCookie };
export type { GetThemeOptions, SetThemeCookieOptions, ThemeScriptProps };
