stoop 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +48 -103
  2. package/dist/api/core-api.d.ts +34 -0
  3. package/dist/api/core-api.js +135 -0
  4. package/dist/api/global-css.d.ts +0 -11
  5. package/dist/api/global-css.js +42 -0
  6. package/dist/api/styled.d.ts +0 -1
  7. package/dist/api/styled.js +419 -0
  8. package/dist/api/theme-provider.d.ts +41 -0
  9. package/dist/api/theme-provider.js +223 -0
  10. package/dist/constants.d.ts +13 -4
  11. package/dist/constants.js +154 -0
  12. package/dist/core/cache.d.ts +5 -9
  13. package/dist/core/cache.js +68 -0
  14. package/dist/core/compiler.d.ts +11 -0
  15. package/dist/core/compiler.js +206 -0
  16. package/dist/core/theme-manager.d.ts +27 -4
  17. package/dist/core/theme-manager.js +107 -0
  18. package/dist/core/variants.js +38 -0
  19. package/dist/create-stoop-internal.d.ts +30 -0
  20. package/dist/create-stoop-internal.js +123 -0
  21. package/dist/create-stoop-ssr.d.ts +10 -0
  22. package/dist/create-stoop-ssr.js +26 -0
  23. package/dist/create-stoop.d.ts +32 -4
  24. package/dist/create-stoop.js +156 -0
  25. package/dist/inject.d.ts +113 -0
  26. package/dist/inject.js +308 -0
  27. package/dist/types/index.d.ts +157 -17
  28. package/dist/types/index.js +5 -0
  29. package/dist/types/react-polymorphic-types.d.ts +15 -8
  30. package/dist/utils/auto-preload.d.ts +45 -0
  31. package/dist/utils/auto-preload.js +167 -0
  32. package/dist/utils/helpers.d.ts +64 -0
  33. package/dist/utils/helpers.js +150 -0
  34. package/dist/utils/storage.d.ts +148 -0
  35. package/dist/utils/storage.js +396 -0
  36. package/dist/utils/{string.d.ts → theme-utils.d.ts} +36 -12
  37. package/dist/utils/theme-utils.js +353 -0
  38. package/dist/utils/theme.d.ts +17 -5
  39. package/dist/utils/theme.js +304 -0
  40. package/package.json +48 -24
  41. package/LICENSE.md +0 -21
  42. package/dist/api/create-theme.d.ts +0 -13
  43. package/dist/api/css.d.ts +0 -16
  44. package/dist/api/keyframes.d.ts +0 -16
  45. package/dist/api/provider.d.ts +0 -19
  46. package/dist/api/use-theme.d.ts +0 -13
  47. package/dist/index.d.ts +0 -6
  48. package/dist/index.js +0 -13
  49. package/dist/inject/browser.d.ts +0 -59
  50. package/dist/inject/dedup.d.ts +0 -29
  51. package/dist/inject/index.d.ts +0 -41
  52. package/dist/inject/ssr.d.ts +0 -28
  53. package/dist/utils/theme-map.d.ts +0 -25
  54. package/dist/utils/theme-validation.d.ts +0 -13
  55. package/dist/utils/type-guards.d.ts +0 -26
  56. package/dist/utils/utilities.d.ts +0 -14
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Variant application logic.
3
+ * Merges variant styles with base styles based on component props.
4
+ * Optimized to avoid unnecessary object spreads when no variants are applied.
5
+ */
6
+ /**
7
+ * Applies variant styles to base styles based on component props.
8
+ *
9
+ * @param variants - Variant configuration object
10
+ * @param props - Component props containing variant values
11
+ * @param baseStyles - Base styles to merge with variant styles
12
+ * @returns Merged CSS object
13
+ */
14
+ export function applyVariants(variants, props, baseStyles) {
15
+ let hasVariants = false;
16
+ const appliedVariantStyles = [];
17
+ for (const variantName in variants) {
18
+ const propValue = props[variantName];
19
+ if (propValue === undefined) {
20
+ continue;
21
+ }
22
+ const variantOptions = variants[variantName];
23
+ const key = propValue === true ? "true" : propValue === false ? "false" : String(propValue);
24
+ if (variantOptions[key]) {
25
+ appliedVariantStyles.push(variantOptions[key]);
26
+ hasVariants = true;
27
+ }
28
+ }
29
+ if (!hasVariants) {
30
+ return baseStyles;
31
+ }
32
+ // Merge all variant styles into a single object using spread for consistency
33
+ const mergedVariants = { ...appliedVariantStyles[0] };
34
+ for (let i = 1; i < appliedVariantStyles.length; i++) {
35
+ Object.assign(mergedVariants, appliedVariantStyles[i]);
36
+ }
37
+ return { ...baseStyles, ...mergedVariants };
38
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Internal implementation for creating Stoop instances.
3
+ * This file is used by the SSR entry point and does NOT import React types at module level.
4
+ * React types are only imported conditionally when creating client instances.
5
+ */
6
+ import type { CSS, StoopConfig, Theme, ThemeScale } from "./types";
7
+ import { createCSSFunction, createKeyframesFunction } from "./api/core-api";
8
+ import { createGlobalCSSFunction } from "./api/global-css";
9
+ /**
10
+ * Shared implementation for creating Stoop instances.
11
+ * Handles common setup logic for both client and server instances.
12
+ * Exported for use in SSR entry point.
13
+ */
14
+ export declare function createStoopBase(config: StoopConfig): {
15
+ config: StoopConfig;
16
+ createTheme: (overrides?: Partial<Theme>) => Theme;
17
+ css: ReturnType<typeof createCSSFunction>;
18
+ getCssText: (theme?: string | Theme) => string;
19
+ globalCss: ReturnType<typeof createGlobalCSSFunction>;
20
+ globalCssConfig: StoopConfig["globalCss"];
21
+ keyframes: ReturnType<typeof createKeyframesFunction>;
22
+ media: StoopConfig["media"];
23
+ mergedThemeMap: Record<string, ThemeScale>;
24
+ preloadTheme: (theme: string | Theme) => void;
25
+ sanitizedPrefix: string;
26
+ theme: Theme;
27
+ utils: StoopConfig["utils"];
28
+ validatedTheme: Theme;
29
+ warmCache: (styles: CSS[]) => void;
30
+ };
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Internal implementation for creating Stoop instances.
3
+ * This file is used by the SSR entry point and does NOT import React types at module level.
4
+ * React types are only imported conditionally when creating client instances.
5
+ */
6
+ import { createTheme as createThemeFactory, createCSSFunction, createKeyframesFunction, } from "./api/core-api";
7
+ import { createGlobalCSSFunction } from "./api/global-css";
8
+ // Note: React APIs (styled, Provider) are NOT imported here for SSR safety
9
+ import { DEFAULT_THEME_MAP } from "./constants";
10
+ import { compileCSS } from "./core/compiler";
11
+ import { mergeWithDefaultTheme, registerDefaultTheme, injectAllThemes } from "./core/theme-manager";
12
+ import { getCssText as getCssTextBase, removeThemeVariableBlocks } from "./inject";
13
+ import { validateTheme } from "./utils/helpers";
14
+ import { generateAllThemeVariables, generateCSSVariables } from "./utils/theme";
15
+ import { sanitizePrefix } from "./utils/theme-utils";
16
+ /**
17
+ * Shared implementation for creating Stoop instances.
18
+ * Handles common setup logic for both client and server instances.
19
+ * Exported for use in SSR entry point.
20
+ */
21
+ export function createStoopBase(config) {
22
+ const { globalCss: globalCssConfig, media: configMedia, prefix = "stoop", theme, themeMap: userThemeMap, utils, } = config;
23
+ const sanitizedPrefix = sanitizePrefix(prefix);
24
+ const validatedTheme = validateTheme(theme);
25
+ const media = validatedTheme.media || configMedia;
26
+ const mergedThemeMap = {
27
+ ...DEFAULT_THEME_MAP,
28
+ ...userThemeMap,
29
+ };
30
+ registerDefaultTheme(validatedTheme, sanitizedPrefix);
31
+ const css = createCSSFunction(validatedTheme, sanitizedPrefix, media, utils, mergedThemeMap);
32
+ const createTheme = createThemeFactory(validatedTheme);
33
+ const globalCss = createGlobalCSSFunction(validatedTheme, sanitizedPrefix, media, utils, mergedThemeMap);
34
+ const keyframes = createKeyframesFunction(sanitizedPrefix, validatedTheme, mergedThemeMap);
35
+ const themeObject = Object.freeze({ ...validatedTheme });
36
+ /**
37
+ * Pre-compiles CSS objects to warm the cache.
38
+ * Useful for eliminating FOUC by pre-compiling common styles.
39
+ *
40
+ * @param styles - Array of CSS objects to pre-compile
41
+ */
42
+ function warmCache(styles) {
43
+ for (const style of styles) {
44
+ try {
45
+ compileCSS(style, validatedTheme, sanitizedPrefix, media, utils, mergedThemeMap);
46
+ }
47
+ catch {
48
+ // Skip invalid styles
49
+ }
50
+ }
51
+ }
52
+ /**
53
+ * Preloads a theme by injecting its CSS variables before React renders.
54
+ * Useful for preventing FOUC when loading a non-default theme from localStorage.
55
+ * Uses injectAllThemes to ensure all themes are available.
56
+ *
57
+ * @param theme - Theme to preload (can be theme name string or Theme object)
58
+ */
59
+ function preloadTheme(theme) {
60
+ if (!config.themes || Object.keys(config.themes).length === 0) {
61
+ return;
62
+ }
63
+ // Always inject all themes for consistency and to prevent FOUC
64
+ injectAllThemes(config.themes, sanitizedPrefix);
65
+ }
66
+ /**
67
+ * Gets all injected CSS text for server-side rendering.
68
+ * Always includes all theme CSS variables using attribute selectors.
69
+ *
70
+ * @param theme - Deprecated parameter, kept for backward compatibility but ignored
71
+ * @returns CSS text string with theme variables and component styles
72
+ */
73
+ function getCssText(theme) {
74
+ let result = "";
75
+ // Always include all themes using attribute selectors for consistency
76
+ if (config.themes && Object.keys(config.themes).length > 0) {
77
+ // Merge all themes with default theme for consistency with client-side behavior
78
+ const mergedThemes = {};
79
+ for (const [themeName, theme] of Object.entries(config.themes)) {
80
+ mergedThemes[themeName] = mergeWithDefaultTheme(theme, sanitizedPrefix);
81
+ }
82
+ const allThemeVars = generateAllThemeVariables(mergedThemes, sanitizedPrefix, "data-theme");
83
+ if (allThemeVars) {
84
+ result += allThemeVars + "\n";
85
+ }
86
+ }
87
+ else {
88
+ // No themes configured, just use default theme
89
+ const themeVars = generateCSSVariables(validatedTheme, sanitizedPrefix);
90
+ if (themeVars) {
91
+ result += themeVars + "\n";
92
+ }
93
+ }
94
+ const baseCss = getCssTextBase();
95
+ // Remove any existing theme variable blocks (they're already included above)
96
+ const cleanedCss = removeThemeVariableBlocks(baseCss).trim();
97
+ if (cleanedCss) {
98
+ result += (result ? "\n" : "") + cleanedCss;
99
+ }
100
+ return result;
101
+ }
102
+ return {
103
+ config: { ...config, prefix: sanitizedPrefix },
104
+ createTheme,
105
+ css,
106
+ getCssText,
107
+ globalCss,
108
+ globalCssConfig,
109
+ keyframes,
110
+ media,
111
+ mergedThemeMap,
112
+ preloadTheme,
113
+ sanitizedPrefix,
114
+ theme: themeObject,
115
+ utils,
116
+ // Internal values for React API creation
117
+ validatedTheme,
118
+ warmCache,
119
+ };
120
+ }
121
+ // Export createStoopBase for use in SSR entry point
122
+ // Note: This file does NOT export createStoop() - that's in create-stoop.ts
123
+ // This separation allows SSR entry point to avoid bundling React code
@@ -0,0 +1,10 @@
1
+ /**
2
+ * SSR-safe entry point for Stoop.
3
+ * Exports only server-safe APIs that don't require React.
4
+ * Use this import in Server Components: import { createStoop } from "stoop/ssr"
5
+ *
6
+ * This file does NOT import React types or create React components.
7
+ */
8
+ import type { StoopConfig, StoopServerInstance } from "./types";
9
+ export type { CSS, Theme, StoopConfig, StoopServerInstance, UtilityFunction, ThemeScale, DefaultTheme, } from "./types";
10
+ export declare function createStoop(config: StoopConfig): StoopServerInstance;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * SSR-safe entry point for Stoop.
3
+ * Exports only server-safe APIs that don't require React.
4
+ * Use this import in Server Components: import { createStoop } from "stoop/ssr"
5
+ *
6
+ * This file does NOT import React types or create React components.
7
+ */
8
+ // Import createStoopBase from create-stoop-internal to avoid React type imports
9
+ // create-stoop-internal.ts is a copy of create-stoop.ts without React imports at module level
10
+ import { createStoopBase } from "./create-stoop-internal";
11
+ export function createStoop(config) {
12
+ const base = createStoopBase(config);
13
+ // Return only server-safe APIs (no React components)
14
+ // Ensure config.prefix is always a string (not undefined) for type compatibility
15
+ return {
16
+ config: { ...base.config, prefix: base.sanitizedPrefix },
17
+ createTheme: base.createTheme,
18
+ css: base.css,
19
+ getCssText: base.getCssText,
20
+ globalCss: base.globalCss,
21
+ keyframes: base.keyframes,
22
+ preloadTheme: base.preloadTheme,
23
+ theme: base.theme,
24
+ warmCache: base.warmCache,
25
+ };
26
+ }
@@ -1,12 +1,40 @@
1
1
  /**
2
- * Main factory function that creates a Stoop instance.
3
- * Configures theme, media queries, utilities, and returns all API functions.
2
+ * Factory function that creates a Stoop instance.
3
+ * Supports both client-side (with React APIs) and server-side (without React) usage.
4
+ * Automatically detects environment and includes appropriate APIs.
4
5
  */
5
- import type { StoopConfig, StoopInstance } from "./types";
6
+ import type { CSS, StoopConfig, StoopInstance, Theme, ThemeScale } from "./types";
7
+ import { createCSSFunction, createKeyframesFunction } from "./api/core-api";
8
+ import { createGlobalCSSFunction } from "./api/global-css";
9
+ /**
10
+ * Shared implementation for creating Stoop instances.
11
+ * Handles common setup logic for both client and server instances.
12
+ * Exported for use in SSR entry point.
13
+ */
14
+ export declare function createStoopBase(config: StoopConfig): {
15
+ config: StoopConfig;
16
+ createTheme: (overrides?: Partial<Theme>) => Theme;
17
+ css: ReturnType<typeof createCSSFunction>;
18
+ getCssText: (theme?: string | Theme) => string;
19
+ globalCss: ReturnType<typeof createGlobalCSSFunction>;
20
+ globalCssConfig: StoopConfig["globalCss"];
21
+ keyframes: ReturnType<typeof createKeyframesFunction>;
22
+ media: StoopConfig["media"];
23
+ mergedThemeMap: Record<string, ThemeScale>;
24
+ preloadTheme: (theme: string | Theme) => void;
25
+ sanitizedPrefix: string;
26
+ theme: Theme;
27
+ utils: StoopConfig["utils"];
28
+ validatedTheme: Theme;
29
+ warmCache: (styles: CSS[]) => void;
30
+ };
6
31
  /**
7
32
  * Creates a Stoop instance with the provided configuration.
33
+ * Includes all APIs: styled, Provider, useTheme, etc.
34
+ * In server contexts without React, React APIs will be undefined.
8
35
  *
9
36
  * @param config - Configuration object containing theme, media queries, utilities, and optional prefix/themeMap
10
- * @returns StoopInstance with all API functions (styled, css, globalCss, keyframes, createTheme, etc.)
37
+ * @returns StoopInstance with all API functions
11
38
  */
39
+ export type { CSS, Theme, StoopConfig, StoopInstance, UtilityFunction, ThemeScale, DefaultTheme, } from "./types";
12
40
  export declare function createStoop(config: StoopConfig): StoopInstance;
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Factory function that creates a Stoop instance.
3
+ * Supports both client-side (with React APIs) and server-side (without React) usage.
4
+ * Automatically detects environment and includes appropriate APIs.
5
+ */
6
+ import { createTheme as createThemeFactory, createCSSFunction, createKeyframesFunction, } from "./api/core-api";
7
+ import { createGlobalCSSFunction } from "./api/global-css";
8
+ import { createStyledFunction } from "./api/styled";
9
+ import { createProvider, createUseThemeHook } from "./api/theme-provider";
10
+ import { DEFAULT_THEME_MAP } from "./constants";
11
+ import { compileCSS } from "./core/compiler";
12
+ import { mergeWithDefaultTheme, registerDefaultTheme, injectAllThemes } from "./core/theme-manager";
13
+ import { getCssText as getCssTextBase, removeThemeVariableBlocks } from "./inject";
14
+ import { validateTheme } from "./utils/helpers";
15
+ import { generateAllThemeVariables, generateCSSVariables } from "./utils/theme";
16
+ import { sanitizePrefix } from "./utils/theme-utils";
17
+ /**
18
+ * Shared implementation for creating Stoop instances.
19
+ * Handles common setup logic for both client and server instances.
20
+ * Exported for use in SSR entry point.
21
+ */
22
+ export function createStoopBase(config) {
23
+ const { globalCss: globalCssConfig, media: configMedia, prefix = "stoop", theme, themeMap: userThemeMap, utils, } = config;
24
+ const sanitizedPrefix = sanitizePrefix(prefix);
25
+ const validatedTheme = validateTheme(theme);
26
+ const media = validatedTheme.media || configMedia;
27
+ const mergedThemeMap = {
28
+ ...DEFAULT_THEME_MAP,
29
+ ...userThemeMap,
30
+ };
31
+ registerDefaultTheme(validatedTheme, sanitizedPrefix);
32
+ const css = createCSSFunction(validatedTheme, sanitizedPrefix, media, utils, mergedThemeMap);
33
+ const createTheme = createThemeFactory(validatedTheme);
34
+ const globalCss = createGlobalCSSFunction(validatedTheme, sanitizedPrefix, media, utils, mergedThemeMap);
35
+ const keyframes = createKeyframesFunction(sanitizedPrefix, validatedTheme, mergedThemeMap);
36
+ const themeObject = Object.freeze({ ...validatedTheme });
37
+ /**
38
+ * Pre-compiles CSS objects to warm the cache.
39
+ * Useful for eliminating FOUC by pre-compiling common styles.
40
+ *
41
+ * @param styles - Array of CSS objects to pre-compile
42
+ */
43
+ function warmCache(styles) {
44
+ for (const style of styles) {
45
+ try {
46
+ compileCSS(style, validatedTheme, sanitizedPrefix, media, utils, mergedThemeMap);
47
+ }
48
+ catch {
49
+ // Skip invalid styles
50
+ }
51
+ }
52
+ }
53
+ /**
54
+ * Preloads a theme by injecting its CSS variables before React renders.
55
+ * Useful for preventing FOUC when loading a non-default theme from localStorage.
56
+ * Uses injectAllThemes to ensure all themes are available.
57
+ *
58
+ * @param theme - Theme to preload (can be theme name string or Theme object)
59
+ */
60
+ function preloadTheme(theme) {
61
+ if (!config.themes || Object.keys(config.themes).length === 0) {
62
+ return;
63
+ }
64
+ // Always inject all themes for consistency and to prevent FOUC
65
+ injectAllThemes(config.themes, sanitizedPrefix);
66
+ }
67
+ /**
68
+ * Gets all injected CSS text for server-side rendering.
69
+ * Always includes all theme CSS variables using attribute selectors.
70
+ *
71
+ * @param theme - Deprecated parameter, kept for backward compatibility but ignored
72
+ * @returns CSS text string with theme variables and component styles
73
+ */
74
+ function getCssText(theme) {
75
+ let result = "";
76
+ // Always include all themes using attribute selectors for consistency
77
+ if (config.themes && Object.keys(config.themes).length > 0) {
78
+ // Merge all themes with default theme for consistency with client-side behavior
79
+ const mergedThemes = {};
80
+ for (const [themeName, theme] of Object.entries(config.themes)) {
81
+ mergedThemes[themeName] = mergeWithDefaultTheme(theme, sanitizedPrefix);
82
+ }
83
+ const allThemeVars = generateAllThemeVariables(mergedThemes, sanitizedPrefix, "data-theme");
84
+ if (allThemeVars) {
85
+ result += allThemeVars + "\n";
86
+ }
87
+ }
88
+ else {
89
+ // No themes configured, just use default theme
90
+ const themeVars = generateCSSVariables(validatedTheme, sanitizedPrefix);
91
+ if (themeVars) {
92
+ result += themeVars + "\n";
93
+ }
94
+ }
95
+ const baseCss = getCssTextBase();
96
+ // Remove any existing theme variable blocks (they're already included above)
97
+ const cleanedCss = removeThemeVariableBlocks(baseCss).trim();
98
+ if (cleanedCss) {
99
+ result += (result ? "\n" : "") + cleanedCss;
100
+ }
101
+ return result;
102
+ }
103
+ return {
104
+ config: { ...config, prefix: sanitizedPrefix },
105
+ createTheme,
106
+ css,
107
+ getCssText,
108
+ globalCss,
109
+ globalCssConfig,
110
+ keyframes,
111
+ media,
112
+ mergedThemeMap,
113
+ preloadTheme,
114
+ sanitizedPrefix,
115
+ theme: themeObject,
116
+ utils,
117
+ // Internal values for React API creation
118
+ validatedTheme,
119
+ warmCache,
120
+ };
121
+ }
122
+ export function createStoop(config) {
123
+ const base = createStoopBase(config);
124
+ // Create full client instance (React APIs may be undefined in SSR contexts)
125
+ // Create Provider and useTheme if themes are configured
126
+ let Provider;
127
+ let useTheme;
128
+ let themeContext;
129
+ if (config.themes) {
130
+ const mergedThemesForProvider = {};
131
+ for (const [themeName, themeOverride] of Object.entries(config.themes)) {
132
+ mergedThemesForProvider[themeName] = base.createTheme(themeOverride);
133
+ }
134
+ const { Provider: ProviderComponent, ThemeContext, ThemeManagementContext, } = createProvider(mergedThemesForProvider, base.validatedTheme, base.sanitizedPrefix, base.globalCssConfig, base.globalCss);
135
+ themeContext = ThemeContext;
136
+ Provider = ProviderComponent;
137
+ useTheme = createUseThemeHook(ThemeManagementContext);
138
+ }
139
+ // Create styled function
140
+ const styled = createStyledFunction(base.validatedTheme, base.sanitizedPrefix, base.media, base.utils, base.mergedThemeMap, themeContext);
141
+ // Return instance with all APIs
142
+ return {
143
+ config: base.config,
144
+ createTheme: base.createTheme,
145
+ css: base.css,
146
+ getCssText: base.getCssText,
147
+ globalCss: base.globalCss,
148
+ keyframes: base.keyframes,
149
+ preloadTheme: base.preloadTheme,
150
+ Provider,
151
+ styled,
152
+ theme: base.theme,
153
+ useTheme,
154
+ warmCache: base.warmCache,
155
+ };
156
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * CSS injection implementation.
3
+ * Consolidates browser-specific and SSR-specific CSS injection logic.
4
+ * Handles stylesheet management, theme variable injection, deduplication, and SSR caching.
5
+ */
6
+ /**
7
+ * Checks if a CSS rule has already been injected.
8
+ *
9
+ * @param key - Rule key to check
10
+ * @returns True if rule is already injected
11
+ */
12
+ export declare function isInjectedRule(key: string): boolean;
13
+ /**
14
+ * Marks a CSS rule as injected.
15
+ *
16
+ * @param key - Rule key
17
+ * @param css - CSS string
18
+ */
19
+ export declare function markRuleAsInjected(key: string, css: string): void;
20
+ /**
21
+ * Adds CSS to the SSR cache with LRU eviction.
22
+ *
23
+ * @param css - CSS string to cache
24
+ */
25
+ export declare function addToSSRCache(css: string): void;
26
+ /**
27
+ * Gets all cached CSS text for SSR.
28
+ *
29
+ * @returns Joined CSS text string
30
+ */
31
+ export declare function getSSRCacheText(): string;
32
+ /**
33
+ * Clears the SSR cache.
34
+ */
35
+ export declare function clearSSRCache(): void;
36
+ /**
37
+ * Checks if CSS is already in the SSR cache.
38
+ *
39
+ * @param css - CSS string to check
40
+ * @returns True if CSS is cached
41
+ */
42
+ export declare function isInSSRCache(css: string): boolean;
43
+ /**
44
+ * Gets or creates the stylesheet element for CSS injection.
45
+ * Reuses the SSR stylesheet if it exists to prevent FOUC.
46
+ * Supports multiple Stoop instances with different prefixes.
47
+ *
48
+ * @param prefix - Optional prefix for stylesheet identification
49
+ * @returns HTMLStyleElement
50
+ * @throws Error if called in SSR context
51
+ */
52
+ export declare function getStylesheet(prefix?: string): HTMLStyleElement;
53
+ /**
54
+ * Removes all theme variable blocks (both :root and attribute selectors) from CSS.
55
+ *
56
+ * @param css - CSS string to clean
57
+ * @returns CSS string without theme variable blocks
58
+ */
59
+ export declare function removeThemeVariableBlocks(css: string): string;
60
+ /**
61
+ * Injects CSS variables for all themes using attribute selectors.
62
+ * This allows all themes to be available simultaneously, with theme switching
63
+ * handled by changing the data-theme attribute.
64
+ *
65
+ * @param allThemeVars - CSS string containing all theme CSS variables
66
+ * @param prefix - Optional prefix for CSS variables
67
+ */
68
+ export declare function injectAllThemeVariables(allThemeVars: string, prefix?: string): void;
69
+ /**
70
+ * Updates the stylesheet with new CSS rules.
71
+ *
72
+ * @param css - CSS string to inject
73
+ * @param ruleKey - Unique key for deduplication
74
+ * @param prefix - Optional prefix for CSS rules
75
+ */
76
+ export declare function updateStylesheet(css: string, ruleKey: string, prefix?: string): void;
77
+ /**
78
+ * Injects CSS into the browser stylesheet with deduplication.
79
+ *
80
+ * @param css - CSS string to inject
81
+ * @param ruleKey - Unique key for deduplication
82
+ * @param prefix - Optional prefix for CSS rules
83
+ */
84
+ export declare function injectBrowserCSS(css: string, ruleKey: string, prefix?: string): void;
85
+ /**
86
+ * Gets the current stylesheet element for a given prefix.
87
+ *
88
+ * @param prefix - Optional prefix for stylesheet identification
89
+ * @returns HTMLStyleElement or null if not created
90
+ */
91
+ export declare function getStylesheetElement(prefix?: string): HTMLStyleElement | null;
92
+ /**
93
+ * Gets all injected rules (for internal use).
94
+ */
95
+ export declare function getAllInjectedRules(): Map<string, string>;
96
+ /**
97
+ * Injects CSS into the document with automatic SSR support.
98
+ *
99
+ * @param css - CSS string to inject
100
+ * @param prefix - Optional prefix for CSS rules
101
+ * @param ruleKey - Optional unique key for deduplication
102
+ */
103
+ export declare function injectCSS(css: string, prefix?: string, ruleKey?: string): void;
104
+ /**
105
+ * Gets all injected CSS text (browser or SSR).
106
+ *
107
+ * @returns CSS text string
108
+ */
109
+ export declare function getCssText(prefix?: string): string;
110
+ /**
111
+ * Clears all injected CSS and caches.
112
+ */
113
+ export declare function clearStylesheet(): void;