/**
 * CSS Utilities for Ty Components
 * Handles dynamic CSS loading into Shadow DOM
 */
/** Cache of loaded CSSStyleSheet objects */
const styleCache = new Map();
/**
 * Ensure CSS is loaded into a shadow root
 * Uses CSSStyleSheet API for efficient style sharing
 *
 * @param shadowRoot - The shadow root to attach styles to
 * @param styleContent - Style content with CSS text and optional ID
 */
export function ensureStyles(shadowRoot, styleContent) {
    const { css, id } = styleContent;
    // Check cache first
    let sheet;
    if (id && styleCache.has(id)) {
        sheet = styleCache.get(id);
    }
    else {
        // Create new stylesheet
        sheet = new CSSStyleSheet();
        sheet.replaceSync(css);
        // Cache it if ID provided
        if (id) {
            styleCache.set(id, sheet);
        }
    }
    // Append to existing stylesheets instead of replacing
    const existing = shadowRoot.adoptedStyleSheets || [];
    shadowRoot.adoptedStyleSheets = [...existing, sheet];
}
/**
 * Build CSS class list from properties
 * Filters out falsy values
 *
 * @param classes - Array of class names or falsy values
 * @returns Space-separated class string
 */
export function buildClassList(...classes) {
    return classes.filter(Boolean).join(' ');
}
/**
 * Clear the style cache
 * Useful for testing or hot-reloading
 */
export function clearStyleCache() {
    styleCache.clear();
}
//# sourceMappingURL=styles.js.map