import { CSSProperties, StyleDefinition, StyleOptions, Theme } from './types' let styleSheet: HTMLStyleElement | null = null; // Cache now stores the generated class name and its corresponding CSS rules. const cache = new Map(); // --- For SSR --- // A registry to hold unique CSS rules generated on the server for a single render pass. let ssrStyleRegistry: Set = new Set(); /** * Retrieves all unique CSS rules generated during a server-side render. * @returns A single string containing all CSS rules. */ export const getSsrStyles = (): string => { return Array.from(ssrStyleRegistry).join('\n'); }; /** * Clears the server-side style registry. Should be called before each server render. */ export const clearSsrStyles = (): void => { ssrStyleRegistry.clear(); }; // --- // Simple hash function to generate a unique ID from a string const hashCode = (str: string): string => { let hash = 0 for (let i = 0; i < str.length; i++) { const char = str.charCodeAt(i) hash = ((hash << 5) - hash) + char hash = hash & hash // Convert to 32bit integer } return Math.abs(hash).toString(36) } // Creates or reuses a single