stoop 0.3.0 → 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 (69) hide show
  1. package/README.md +125 -0
  2. package/dist/api/core-api.d.ts +34 -0
  3. package/dist/api/{keyframes.js → core-api.js} +45 -5
  4. package/dist/api/global-css.js +11 -58
  5. package/dist/api/styled.d.ts +0 -1
  6. package/dist/api/styled.js +265 -16
  7. package/dist/api/theme-provider.d.ts +41 -0
  8. package/dist/api/theme-provider.js +223 -0
  9. package/dist/constants.d.ts +11 -1
  10. package/dist/constants.js +11 -1
  11. package/dist/core/compiler.d.ts +11 -0
  12. package/dist/core/compiler.js +15 -7
  13. package/dist/core/theme-manager.d.ts +34 -3
  14. package/dist/core/theme-manager.js +55 -45
  15. package/dist/core/variants.js +9 -3
  16. package/dist/create-stoop-internal.d.ts +30 -0
  17. package/dist/create-stoop-internal.js +123 -0
  18. package/dist/create-stoop-ssr.d.ts +10 -0
  19. package/dist/create-stoop-ssr.js +26 -0
  20. package/dist/create-stoop.d.ts +32 -1
  21. package/dist/create-stoop.js +78 -69
  22. package/dist/inject.d.ts +113 -0
  23. package/dist/inject.js +308 -0
  24. package/dist/types/index.d.ts +147 -12
  25. package/dist/types/react-polymorphic-types.d.ts +13 -2
  26. package/dist/utils/auto-preload.d.ts +45 -0
  27. package/dist/utils/auto-preload.js +167 -0
  28. package/dist/utils/helpers.d.ts +64 -0
  29. package/dist/utils/helpers.js +150 -0
  30. package/dist/utils/storage.d.ts +148 -0
  31. package/dist/utils/storage.js +396 -0
  32. package/dist/utils/{string.d.ts → theme-utils.d.ts} +20 -3
  33. package/dist/utils/{string.js → theme-utils.js} +109 -9
  34. package/dist/utils/theme.d.ts +14 -2
  35. package/dist/utils/theme.js +41 -16
  36. package/package.json +48 -23
  37. package/dist/api/create-theme.d.ts +0 -13
  38. package/dist/api/create-theme.js +0 -43
  39. package/dist/api/css.d.ts +0 -16
  40. package/dist/api/css.js +0 -20
  41. package/dist/api/keyframes.d.ts +0 -16
  42. package/dist/api/provider.d.ts +0 -19
  43. package/dist/api/provider.js +0 -109
  44. package/dist/api/use-theme.d.ts +0 -13
  45. package/dist/api/use-theme.js +0 -21
  46. package/dist/create-stoop-server.d.ts +0 -33
  47. package/dist/create-stoop-server.js +0 -130
  48. package/dist/index.d.ts +0 -6
  49. package/dist/index.js +0 -5
  50. package/dist/inject/browser.d.ts +0 -58
  51. package/dist/inject/browser.js +0 -149
  52. package/dist/inject/dedup.d.ts +0 -29
  53. package/dist/inject/dedup.js +0 -38
  54. package/dist/inject/index.d.ts +0 -40
  55. package/dist/inject/index.js +0 -75
  56. package/dist/inject/ssr.d.ts +0 -27
  57. package/dist/inject/ssr.js +0 -46
  58. package/dist/ssr.d.ts +0 -21
  59. package/dist/ssr.js +0 -19
  60. package/dist/utils/environment.d.ts +0 -6
  61. package/dist/utils/environment.js +0 -12
  62. package/dist/utils/theme-map.d.ts +0 -22
  63. package/dist/utils/theme-map.js +0 -97
  64. package/dist/utils/theme-validation.d.ts +0 -13
  65. package/dist/utils/theme-validation.js +0 -36
  66. package/dist/utils/type-guards.d.ts +0 -26
  67. package/dist/utils/type-guards.js +0 -38
  68. package/dist/utils/utilities.d.ts +0 -14
  69. package/dist/utils/utilities.js +0 -43
package/dist/inject.js ADDED
@@ -0,0 +1,308 @@
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
+ import { MAX_CSS_CACHE_SIZE } from "./constants";
7
+ import { LRUCache, clearStyleCache } from "./core/cache";
8
+ import { isBrowser } from "./utils/helpers";
9
+ import { getRootRegex, sanitizePrefix } from "./utils/theme-utils";
10
+ // ============================================================================
11
+ // Internal Deduplication
12
+ // ============================================================================
13
+ const injectedRules = new Map();
14
+ /**
15
+ * Checks if a CSS rule has already been injected.
16
+ *
17
+ * @param key - Rule key to check
18
+ * @returns True if rule is already injected
19
+ */
20
+ export function isInjectedRule(key) {
21
+ return injectedRules.has(key);
22
+ }
23
+ /**
24
+ * Marks a CSS rule as injected.
25
+ *
26
+ * @param key - Rule key
27
+ * @param css - CSS string
28
+ */
29
+ export function markRuleAsInjected(key, css) {
30
+ injectedRules.set(key, css);
31
+ }
32
+ // ============================================================================
33
+ // SSR Cache Management
34
+ // ============================================================================
35
+ // Use LRUCache for reliable FIFO eviction (Map iteration order not guaranteed)
36
+ const cssTextCache = new LRUCache(MAX_CSS_CACHE_SIZE);
37
+ /**
38
+ * Adds CSS to the SSR cache with LRU eviction.
39
+ *
40
+ * @param css - CSS string to cache
41
+ */
42
+ export function addToSSRCache(css) {
43
+ if (!cssTextCache.has(css)) {
44
+ cssTextCache.set(css, true);
45
+ }
46
+ }
47
+ /**
48
+ * Gets all cached CSS text for SSR.
49
+ *
50
+ * @returns Joined CSS text string
51
+ */
52
+ export function getSSRCacheText() {
53
+ return Array.from(cssTextCache.keys()).join("\n");
54
+ }
55
+ /**
56
+ * Clears the SSR cache.
57
+ */
58
+ export function clearSSRCache() {
59
+ cssTextCache.clear();
60
+ }
61
+ /**
62
+ * Checks if CSS is already in the SSR cache.
63
+ *
64
+ * @param css - CSS string to check
65
+ * @returns True if CSS is cached
66
+ */
67
+ export function isInSSRCache(css) {
68
+ return cssTextCache.has(css);
69
+ }
70
+ // ============================================================================
71
+ // Browser-Specific Injection
72
+ // ============================================================================
73
+ // Map of prefix -> stylesheet element to support multiple Stoop instances
74
+ const stylesheetElements = new Map();
75
+ const lastInjectedThemes = new Map();
76
+ const lastInjectedCSSVars = new Map();
77
+ /**
78
+ * Gets or creates the stylesheet element for CSS injection.
79
+ * Reuses the SSR stylesheet if it exists to prevent FOUC.
80
+ * Supports multiple Stoop instances with different prefixes.
81
+ *
82
+ * @param prefix - Optional prefix for stylesheet identification
83
+ * @returns HTMLStyleElement
84
+ * @throws Error if called in SSR context
85
+ */
86
+ export function getStylesheet(prefix = "stoop") {
87
+ if (!isBrowser()) {
88
+ throw new Error("Cannot access document in SSR context");
89
+ }
90
+ const sanitizedPrefix = sanitizePrefix(prefix);
91
+ let stylesheetElement = stylesheetElements.get(sanitizedPrefix);
92
+ if (!stylesheetElement || !stylesheetElement.parentNode) {
93
+ // Check if SSR stylesheet exists and matches this prefix
94
+ const ssrStylesheet = document.getElementById("stoop-ssr");
95
+ if (ssrStylesheet) {
96
+ const existingPrefix = ssrStylesheet.getAttribute("data-stoop");
97
+ // Only reuse if prefix matches or no prefix set yet
98
+ if (!existingPrefix || existingPrefix === sanitizedPrefix) {
99
+ stylesheetElement = ssrStylesheet;
100
+ stylesheetElement.setAttribute("data-stoop", sanitizedPrefix);
101
+ stylesheetElements.set(sanitizedPrefix, stylesheetElement);
102
+ return stylesheetElement;
103
+ }
104
+ }
105
+ // Create new stylesheet for this prefix
106
+ stylesheetElement = document.createElement("style");
107
+ stylesheetElement.setAttribute("data-stoop", sanitizedPrefix);
108
+ stylesheetElement.setAttribute("id", `stoop-${sanitizedPrefix}`);
109
+ document.head.appendChild(stylesheetElement);
110
+ stylesheetElements.set(sanitizedPrefix, stylesheetElement);
111
+ }
112
+ return stylesheetElement;
113
+ }
114
+ /**
115
+ * Removes all theme variable blocks (both :root and attribute selectors) from CSS.
116
+ *
117
+ * @param css - CSS string to clean
118
+ * @returns CSS string without theme variable blocks
119
+ */
120
+ export function removeThemeVariableBlocks(css) {
121
+ let result = css;
122
+ // Remove :root blocks using regex
123
+ const rootRegex = getRootRegex("");
124
+ result = result.replace(rootRegex, "").trim();
125
+ // Remove attribute selector blocks manually (handles nested braces)
126
+ let startIndex = result.indexOf("[data-theme=");
127
+ while (startIndex !== -1) {
128
+ const openBrace = result.indexOf("{", startIndex);
129
+ if (openBrace === -1) {
130
+ break;
131
+ }
132
+ let braceCount = 1;
133
+ let closeBrace = openBrace + 1;
134
+ while (closeBrace < result.length && braceCount > 0) {
135
+ if (result[closeBrace] === "{") {
136
+ braceCount++;
137
+ }
138
+ else if (result[closeBrace] === "}") {
139
+ braceCount--;
140
+ }
141
+ closeBrace++;
142
+ }
143
+ if (braceCount === 0) {
144
+ const before = result.substring(0, startIndex).trim();
145
+ const after = result.substring(closeBrace).trim();
146
+ result = (before + "\n" + after).trim();
147
+ }
148
+ else {
149
+ break;
150
+ }
151
+ startIndex = result.indexOf("[data-theme=");
152
+ }
153
+ return result.trim();
154
+ }
155
+ /**
156
+ * Injects CSS variables for all themes using attribute selectors.
157
+ * This allows all themes to be available simultaneously, with theme switching
158
+ * handled by changing the data-theme attribute.
159
+ *
160
+ * @param allThemeVars - CSS string containing all theme CSS variables
161
+ * @param prefix - Optional prefix for CSS variables
162
+ */
163
+ export function injectAllThemeVariables(allThemeVars, prefix = "stoop") {
164
+ if (!allThemeVars) {
165
+ return;
166
+ }
167
+ const sanitizedPrefix = sanitizePrefix(prefix);
168
+ const key = `__all_theme_vars_${sanitizedPrefix}`;
169
+ const lastCSSVars = lastInjectedCSSVars.get(key) ?? null;
170
+ // Only skip if CSS vars string is exactly the same
171
+ if (lastCSSVars === allThemeVars) {
172
+ return;
173
+ }
174
+ lastInjectedCSSVars.set(key, allThemeVars);
175
+ if (!isBrowser()) {
176
+ addToSSRCache(allThemeVars);
177
+ return;
178
+ }
179
+ const sheet = getStylesheet(sanitizedPrefix);
180
+ const currentCSS = sheet.textContent || "";
181
+ // Check if theme variable blocks exist
182
+ const hasThemeBlocks = currentCSS.includes(":root") || currentCSS.includes("[data-theme=");
183
+ if (isInjectedRule(key) || hasThemeBlocks) {
184
+ // Remove all existing theme variable blocks
185
+ const withoutVars = removeThemeVariableBlocks(currentCSS);
186
+ // Update stylesheet synchronously - prepend all theme vars, then append rest
187
+ sheet.textContent = allThemeVars + (withoutVars ? "\n\n" + withoutVars : "");
188
+ markRuleAsInjected(key, allThemeVars);
189
+ }
190
+ else {
191
+ // First injection - no existing theme blocks
192
+ sheet.textContent = allThemeVars + (currentCSS ? "\n\n" + currentCSS : "");
193
+ markRuleAsInjected(key, allThemeVars);
194
+ }
195
+ }
196
+ /**
197
+ * Updates the stylesheet with new CSS rules.
198
+ *
199
+ * @param css - CSS string to inject
200
+ * @param ruleKey - Unique key for deduplication
201
+ * @param prefix - Optional prefix for CSS rules
202
+ */
203
+ export function updateStylesheet(css, ruleKey, prefix = "stoop") {
204
+ if (!isBrowser()) {
205
+ return;
206
+ }
207
+ const sanitizedPrefix = sanitizePrefix(prefix);
208
+ if (isInjectedRule(ruleKey)) {
209
+ return;
210
+ }
211
+ const sheet = getStylesheet(sanitizedPrefix);
212
+ const currentCSS = sheet.textContent || "";
213
+ sheet.textContent = currentCSS + (currentCSS ? "\n" : "") + css;
214
+ markRuleAsInjected(ruleKey, css);
215
+ }
216
+ /**
217
+ * Injects CSS into the browser stylesheet with deduplication.
218
+ *
219
+ * @param css - CSS string to inject
220
+ * @param ruleKey - Unique key for deduplication
221
+ * @param prefix - Optional prefix for CSS rules
222
+ */
223
+ export function injectBrowserCSS(css, ruleKey, prefix = "stoop") {
224
+ if (isInjectedRule(ruleKey)) {
225
+ return;
226
+ }
227
+ const sanitizedPrefix = sanitizePrefix(prefix);
228
+ updateStylesheet(css, ruleKey, sanitizedPrefix);
229
+ }
230
+ /**
231
+ * Gets the current stylesheet element for a given prefix.
232
+ *
233
+ * @param prefix - Optional prefix for stylesheet identification
234
+ * @returns HTMLStyleElement or null if not created
235
+ */
236
+ export function getStylesheetElement(prefix = "stoop") {
237
+ const sanitizedPrefix = sanitizePrefix(prefix);
238
+ return stylesheetElements.get(sanitizedPrefix) || null;
239
+ }
240
+ /**
241
+ * Clears the stylesheet and all caches (internal).
242
+ */
243
+ function clearStylesheetInternal() {
244
+ // Remove all stylesheet elements
245
+ for (const [, element] of stylesheetElements.entries()) {
246
+ if (element && element.parentNode) {
247
+ element.parentNode.removeChild(element);
248
+ }
249
+ }
250
+ stylesheetElements.clear();
251
+ lastInjectedThemes.clear();
252
+ lastInjectedCSSVars.clear();
253
+ injectedRules.clear();
254
+ }
255
+ /**
256
+ * Gets all injected rules (for internal use).
257
+ */
258
+ export function getAllInjectedRules() {
259
+ return new Map(injectedRules);
260
+ }
261
+ // ============================================================================
262
+ // Public API Functions
263
+ // ============================================================================
264
+ /**
265
+ * Injects CSS into the document with automatic SSR support.
266
+ *
267
+ * @param css - CSS string to inject
268
+ * @param prefix - Optional prefix for CSS rules
269
+ * @param ruleKey - Optional unique key for deduplication
270
+ */
271
+ export function injectCSS(css, prefix = "stoop", ruleKey) {
272
+ const key = ruleKey || css;
273
+ if (!isBrowser()) {
274
+ if (!isInjectedRule(key)) {
275
+ markRuleAsInjected(key, css);
276
+ }
277
+ addToSSRCache(css);
278
+ return;
279
+ }
280
+ injectBrowserCSS(css, key, prefix);
281
+ }
282
+ /**
283
+ * Gets all injected CSS text (browser or SSR).
284
+ *
285
+ * @returns CSS text string
286
+ */
287
+ export function getCssText(prefix = "stoop") {
288
+ if (isBrowser()) {
289
+ const sanitizedPrefix = sanitizePrefix(prefix);
290
+ const sheetElement = getStylesheetElement(sanitizedPrefix);
291
+ if (sheetElement && sheetElement.parentNode) {
292
+ const sheetCSS = sheetElement.textContent || "";
293
+ if (!sheetCSS && getAllInjectedRules().size > 0) {
294
+ return getSSRCacheText();
295
+ }
296
+ return sheetCSS;
297
+ }
298
+ }
299
+ return getSSRCacheText();
300
+ }
301
+ /**
302
+ * Clears all injected CSS and caches.
303
+ */
304
+ export function clearStylesheet() {
305
+ clearStylesheetInternal();
306
+ clearSSRCache();
307
+ clearStyleCache();
308
+ }
@@ -4,11 +4,6 @@
4
4
  */
5
5
  import type { ComponentType, ElementType, JSX, ReactNode } from "react";
6
6
  import type { PolymorphicPropsWithRef } from "react-polymorphic-types";
7
- import type { createTheme } from "../api/create-theme";
8
- import type { createCSSFunction } from "../api/css";
9
- import type { createGlobalCSSFunction } from "../api/global-css";
10
- import type { createKeyframesFunction } from "../api/keyframes";
11
- import type { createStyledFunction } from "../api/styled";
12
7
  export type CSSPropertyValue = string | number;
13
8
  export interface StyledComponentRef {
14
9
  readonly __stoopClassName: string;
@@ -70,10 +65,12 @@ export interface StoopConfig {
70
65
  utils?: Record<string, UtilityFunction>;
71
66
  prefix?: string;
72
67
  themeMap?: Record<string, ThemeScale>;
68
+ globalCss?: CSS;
73
69
  }
74
70
  export type VariantKeys<T extends Variants> = keyof T;
71
+ type ExtractVariantKeys<T> = T extends Record<infer K, CSS> ? K extends string | number | boolean ? K : T extends Record<string, CSS> ? string : never : T extends Record<string, CSS> ? keyof T : never;
75
72
  export type VariantPropsFromConfig<T extends Variants> = {
76
- [K in VariantKeys<T>]?: keyof T[K] | boolean | number;
73
+ [K in VariantKeys<T>]?: ExtractVariantKeys<T[K]>;
77
74
  };
78
75
  type StyledOwnProps<VariantsConfig extends Variants> = StyledBaseProps & (VariantsConfig extends Record<string, never> ? {} : VariantPropsFromConfig<VariantsConfig>);
79
76
  export type StyledComponentProps<DefaultElement extends ElementType, VariantsConfig extends Variants = {}> = PolymorphicPropsWithRef<StyledOwnProps<VariantsConfig>, DefaultElement>;
@@ -88,6 +85,119 @@ export interface ThemeManagementContextValue {
88
85
  toggleTheme: () => void;
89
86
  availableThemes: readonly string[];
90
87
  }
88
+ /**
89
+ * Server-side Stoop instance.
90
+ * Only includes APIs that work without React dependencies.
91
+ */
92
+ export interface StoopServerInstance {
93
+ config: StoopConfig & {
94
+ prefix: string;
95
+ };
96
+ createTheme: (themeOverride: Partial<Theme>) => Theme;
97
+ css: (styles: CSS) => string;
98
+ getCssText: (theme?: string | Theme) => string;
99
+ globalCss: (...args: CSS[]) => () => void;
100
+ keyframes: (definition: Record<string, CSS>) => string;
101
+ preloadTheme: (theme: string | Theme) => void;
102
+ theme: Theme;
103
+ warmCache: (styles: CSS[]) => void;
104
+ }
105
+ /**
106
+ * Theme detection options for automatic theme selection.
107
+ */
108
+ export interface ThemeDetectionOptions {
109
+ /** localStorage key to check for stored theme preference */
110
+ localStorage?: string;
111
+ /** Cookie name to check for stored theme preference */
112
+ cookie?: string;
113
+ /** Whether to check system color scheme preference */
114
+ systemPreference?: boolean;
115
+ /** Default theme name to fall back to */
116
+ default?: string;
117
+ /** Available themes map for validation */
118
+ themes?: Record<string, Theme>;
119
+ }
120
+ /**
121
+ * Result of theme detection.
122
+ */
123
+ export interface ThemeDetectionResult {
124
+ /** Detected theme name */
125
+ theme: string;
126
+ /** Source of the theme detection */
127
+ source: "cookie" | "localStorage" | "system" | "default";
128
+ /** Confidence level (0-1) of the detection */
129
+ confidence: number;
130
+ }
131
+ /**
132
+ * Storage type enumeration.
133
+ */
134
+ export type StorageType = "localStorage" | "cookie";
135
+ /**
136
+ * Options for storage operations.
137
+ */
138
+ export interface StorageOptions {
139
+ /** Storage type */
140
+ type?: StorageType;
141
+ /** Cookie max age in seconds (only for cookies) */
142
+ maxAge?: number;
143
+ /** Cookie path (only for cookies) */
144
+ path?: string;
145
+ /** Whether to use secure cookies (only for cookies) */
146
+ secure?: boolean;
147
+ }
148
+ /**
149
+ * Storage result with metadata.
150
+ */
151
+ export interface StorageResult<T = string> {
152
+ /** The stored value */
153
+ value: T;
154
+ /** Whether the operation succeeded */
155
+ success: boolean;
156
+ /** Error message if operation failed */
157
+ error?: string;
158
+ /** Source of the value */
159
+ source?: StorageType;
160
+ }
161
+ /**
162
+ * Options for auto-preloading.
163
+ */
164
+ export interface AutoPreloadOptions {
165
+ /** Theme detection options */
166
+ themeDetection?: ThemeDetectionOptions;
167
+ /** Common styles to warm the cache with */
168
+ commonStyles?: CSS[];
169
+ /** Whether to enable automatic theme preloading */
170
+ enableThemePreload?: boolean;
171
+ /** Whether to enable automatic cache warming */
172
+ enableCacheWarm?: boolean;
173
+ /** Whether to run in SSR context (limits available APIs) */
174
+ ssr?: boolean;
175
+ }
176
+ /**
177
+ * Result of auto-preloading operations.
178
+ */
179
+ export interface AutoPreloadResult {
180
+ /** Detected theme information */
181
+ themeDetection: ThemeDetectionResult;
182
+ /** Whether cache was warmed */
183
+ cacheWarmed: boolean;
184
+ /** Whether theme was preloaded */
185
+ themePreloaded: boolean;
186
+ /** Any errors that occurred */
187
+ errors: string[];
188
+ }
189
+ /**
190
+ * Styled component type - the return type of styled()
191
+ */
192
+ export type StyledComponent<DefaultElement extends ElementType, VariantsConfig extends Variants = {}> = ComponentType<StyledComponentProps<DefaultElement, VariantsConfig>> & {
193
+ selector: StyledComponentRef;
194
+ };
195
+ /**
196
+ * Styled function type - the main styled() function signature
197
+ */
198
+ export interface StyledFunction {
199
+ <DefaultElement extends StylableElement, VariantsConfig extends Variants = {}>(defaultElement: DefaultElement, baseStyles?: CSS, variants?: VariantsConfig): StyledComponent<DefaultElement, VariantsConfig>;
200
+ }
91
201
  export interface GetCssTextOptions {
92
202
  theme?: Theme;
93
203
  includeThemeVars?: boolean;
@@ -96,24 +206,49 @@ export interface ProviderProps {
96
206
  children: ReactNode;
97
207
  defaultTheme?: string;
98
208
  storageKey?: string;
209
+ cookieKey?: string;
99
210
  attribute?: string;
100
211
  }
212
+ /**
213
+ * CSS function type
214
+ */
215
+ export interface CSSFunction {
216
+ (styles: CSS): string;
217
+ }
218
+ /**
219
+ * Global CSS function type
220
+ */
221
+ export interface GlobalCSSFunction {
222
+ (styles: CSS): () => void;
223
+ }
224
+ /**
225
+ * Keyframes function type
226
+ */
227
+ export interface KeyframesFunction {
228
+ (keyframes: Record<string, CSS>): string;
229
+ }
230
+ /**
231
+ * Create theme function type
232
+ */
233
+ export interface CreateThemeFunction {
234
+ (theme: Partial<DefaultTheme>): DefaultTheme;
235
+ }
101
236
  /**
102
237
  * Stoop instance.
103
238
  * Includes all APIs: styled, Provider, useTheme, css, globalCss, keyframes, etc.
104
239
  */
105
240
  export interface StoopInstance {
106
- styled: ReturnType<typeof createStyledFunction>;
107
- css: ReturnType<typeof createCSSFunction>;
108
- createTheme: ReturnType<typeof createTheme>;
109
- globalCss: ReturnType<typeof createGlobalCSSFunction>;
110
- keyframes: ReturnType<typeof createKeyframesFunction>;
241
+ styled: StyledFunction;
242
+ css: CSSFunction;
243
+ createTheme: CreateThemeFunction;
244
+ globalCss: GlobalCSSFunction;
245
+ keyframes: KeyframesFunction;
111
246
  theme: DefaultTheme;
112
247
  /**
113
248
  * Gets all generated CSS text for server-side rendering.
114
249
  * Always includes theme CSS variables.
115
250
  *
116
- * @param theme - Optional theme (name or object) to include vars for (defaults to default theme)
251
+ * @param theme - Deprecated parameter, kept for backward compatibility but ignored
117
252
  * @returns CSS text string with theme variables and component styles
118
253
  */
119
254
  getCssText: (theme?: string | Theme) => string;
@@ -1,13 +1,24 @@
1
1
  /**
2
2
  * Type declaration for react-polymorphic-types to work around package.json exports issue.
3
+ * Properly extends native element props while preserving custom variant props.
3
4
  */
4
5
 
5
6
  declare module "react-polymorphic-types" {
6
7
  import type { ElementType, ComponentPropsWithRef, ComponentPropsWithoutRef } from "react";
7
8
 
9
+ /**
10
+ * Polymorphic props with ref support.
11
+ * Extends native element props while preserving custom props (like variants).
12
+ * Variant props take precedence over native props with the same name.
13
+ */
8
14
  export type PolymorphicPropsWithRef<OwnProps, DefaultElement extends ElementType> = OwnProps &
9
- ComponentPropsWithRef<DefaultElement>;
15
+ Omit<ComponentPropsWithRef<DefaultElement>, keyof OwnProps>;
10
16
 
17
+ /**
18
+ * Polymorphic props without ref support.
19
+ * Extends native element props while preserving custom props (like variants).
20
+ * Variant props take precedence over native props with the same name.
21
+ */
11
22
  export type PolymorphicPropsWithoutRef<OwnProps, DefaultElement extends ElementType> = OwnProps &
12
- ComponentPropsWithoutRef<DefaultElement>;
23
+ Omit<ComponentPropsWithoutRef<DefaultElement>, keyof OwnProps>;
13
24
  }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Auto-preloading utilities for cache warming and theme preloading.
3
+ * Helps eliminate FOUC (Flash of Unstyled Content) by pre-compiling styles and preloading themes.
4
+ */
5
+ import type { CSS, Theme, ThemeDetectionOptions, ThemeDetectionResult, AutoPreloadOptions, AutoPreloadResult } from "../types";
6
+ /**
7
+ * Common UI component styles that are frequently used.
8
+ * These represent typical design system patterns.
9
+ */
10
+ export declare const COMMON_UI_STYLES: CSS[];
11
+ /**
12
+ * Automatically warms the cache with common styles.
13
+ *
14
+ * @param warmCacheFn - The warmCache function from Stoop instance
15
+ * @param styles - Styles to warm (defaults to COMMON_UI_STYLES)
16
+ * @returns Promise that resolves when warming is complete
17
+ */
18
+ export declare function autoWarmCache(warmCacheFn: (styles: CSS[]) => void, styles?: CSS[]): Promise<void>;
19
+ /**
20
+ * Automatically preloads a detected theme.
21
+ *
22
+ * @param preloadThemeFn - The preloadTheme function from Stoop instance
23
+ * @param options - Theme detection options
24
+ * @param ssr - Whether running in SSR context
25
+ * @returns Promise that resolves when preloading is complete
26
+ */
27
+ export declare function autoPreloadTheme(preloadThemeFn: (theme: string | Theme) => void, options?: ThemeDetectionOptions, ssr?: boolean): Promise<ThemeDetectionResult>;
28
+ /**
29
+ * Performs automatic preloading operations based on configuration.
30
+ *
31
+ * @param warmCacheFn - The warmCache function from Stoop instance
32
+ * @param preloadThemeFn - The preloadTheme function from Stoop instance
33
+ * @param options - Auto-preload options
34
+ * @returns Promise that resolves with preload results
35
+ */
36
+ export declare function autoPreload(warmCacheFn: (styles: CSS[]) => void, preloadThemeFn: (theme: string | Theme) => void, options?: AutoPreloadOptions): Promise<AutoPreloadResult>;
37
+ /**
38
+ * Creates an auto-preloader with pre-configured options.
39
+ *
40
+ * @param warmCacheFn - The warmCache function from Stoop instance
41
+ * @param preloadThemeFn - The preloadTheme function from Stoop instance
42
+ * @param defaultOptions - Default auto-preload options
43
+ * @returns Auto-preloader function
44
+ */
45
+ export declare function createAutoPreloader(warmCacheFn: (styles: CSS[]) => void, preloadThemeFn: (theme: string | Theme) => void, defaultOptions?: AutoPreloadOptions): (options?: Partial<AutoPreloadOptions>) => Promise<AutoPreloadResult>;