/** * Server-safe utilities for Next.js integration. * These functions can be used in Server Components without adding "use client". */ import { collectStyles, getRegisteredCss } from 'typestyles/server'; import { getRouteCss, type GetRouteCssOptions } from '@typestyles/build-runner'; export { getRegisteredCss, getRouteCss, type GetRouteCssOptions }; /** * Collect styles from a React component and return them as a string. * Useful for server components or when you need more control. * * @example * ```tsx * // app/styles.ts * import { collectStylesFromComponent } from '@typestyles/next/server'; * import { YourApp } from './YourApp'; * * export async function getStyles() { * return collectStylesFromComponent(); * } * ``` */ export async function collectStylesFromComponent(component: React.ReactElement): Promise { const { renderToString } = await import('react-dom/server'); const { css } = collectStyles(() => renderToString(component)); return css; } /** * Collect CSS by rendering a React element on the server (alias for {@link collectStylesFromComponent}). * Use when you need styles for a specific subtree; inject the returned string in `` / layout as needed. * * Next.js `metadata` / `generateMetadata` does not support injecting arbitrary `