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
@@ -1,130 +0,0 @@
1
- /**
2
- * Server-safe factory function that creates a Stoop instance.
3
- * Only includes APIs that work without React: css, globalCss, keyframes, getCssText, etc.
4
- * Does NOT include: styled, Provider, useTheme
5
- *
6
- * This is the entry point for Server Components in Next.js App Router.
7
- */
8
- import { createTheme as createThemeFactory } from "./api/create-theme";
9
- import { createCSSFunction } from "./api/css";
10
- import { createGlobalCSSFunction } from "./api/global-css";
11
- import { createKeyframesFunction } from "./api/keyframes";
12
- import { DEFAULT_THEME_MAP } from "./constants";
13
- import { compileCSS } from "./core/compiler";
14
- import { registerDefaultTheme, updateThemeVariables } from "./core/theme-manager";
15
- import { getCssText as getCssTextBase, registerTheme } from "./inject";
16
- import { getRootRegex, sanitizePrefix } from "./utils/string";
17
- import { generateCSSVariables } from "./utils/theme";
18
- import { validateTheme } from "./utils/theme-validation";
19
- /**
20
- * Creates a server-safe Stoop instance with the provided configuration.
21
- * Only includes APIs that work without React: css, globalCss, keyframes, getCssText, etc.
22
- *
23
- * @param config - Configuration object containing theme, media queries, utilities, and optional prefix/themeMap
24
- * @returns StoopServerInstance with server-safe API functions
25
- */
26
- export function createStoop(config) {
27
- const { media: configMedia, prefix = "stoop", theme, themeMap: userThemeMap, utils } = config;
28
- const sanitizedPrefix = sanitizePrefix(prefix);
29
- const validatedTheme = validateTheme(theme);
30
- const media = validatedTheme.media || configMedia;
31
- const mergedThemeMap = {
32
- ...DEFAULT_THEME_MAP,
33
- ...userThemeMap,
34
- };
35
- registerDefaultTheme(validatedTheme, sanitizedPrefix);
36
- registerTheme(validatedTheme, sanitizedPrefix);
37
- const css = createCSSFunction(validatedTheme, sanitizedPrefix, media, utils, mergedThemeMap);
38
- const createTheme = createThemeFactory(validatedTheme);
39
- const globalCss = createGlobalCSSFunction(validatedTheme, sanitizedPrefix, media, utils, mergedThemeMap);
40
- const keyframes = createKeyframesFunction(sanitizedPrefix, validatedTheme, mergedThemeMap);
41
- const themeObject = Object.freeze({ ...validatedTheme });
42
- /**
43
- * Pre-compiles CSS objects to warm the cache.
44
- * Useful for eliminating FOUC by pre-compiling common styles.
45
- *
46
- * @param styles - Array of CSS objects to pre-compile
47
- */
48
- function warmCache(styles) {
49
- for (const style of styles) {
50
- try {
51
- compileCSS(style, validatedTheme, sanitizedPrefix, media, utils, mergedThemeMap);
52
- }
53
- catch {
54
- // Skip invalid styles
55
- }
56
- }
57
- }
58
- /**
59
- * Preloads a theme by injecting its CSS variables before React renders.
60
- * Useful for preventing FOUC when loading a non-default theme from localStorage.
61
- *
62
- * @param theme - Theme to preload (can be theme name string or Theme object)
63
- */
64
- function preloadTheme(theme) {
65
- let themeToInject;
66
- if (typeof theme === "string") {
67
- if (config.themes && config.themes[theme]) {
68
- themeToInject = config.themes[theme];
69
- }
70
- else {
71
- if (typeof process !== "undefined" && process.env?.NODE_ENV !== "production") {
72
- // eslint-disable-next-line no-console
73
- console.warn(`[Stoop] Theme "${theme}" not found. Available themes: ${config.themes ? Object.keys(config.themes).join(", ") : "none"}`);
74
- }
75
- return;
76
- }
77
- }
78
- else {
79
- themeToInject = theme;
80
- }
81
- updateThemeVariables(themeToInject, sanitizedPrefix);
82
- }
83
- /**
84
- * Gets all injected CSS text for server-side rendering.
85
- * Always includes theme CSS variables.
86
- *
87
- * @param theme - Optional theme (name or object) to include vars for (defaults to default theme)
88
- * @returns CSS text string with theme variables and component styles
89
- */
90
- function getCssText(theme) {
91
- let themeToUse = validatedTheme;
92
- if (theme) {
93
- if (typeof theme === "string") {
94
- if (config.themes && config.themes[theme]) {
95
- themeToUse = config.themes[theme];
96
- }
97
- else if (typeof process !== "undefined" && process.env?.NODE_ENV !== "production") {
98
- // eslint-disable-next-line no-console
99
- console.warn(`[Stoop] Theme "${theme}" not found. Using default theme. Available: ${config.themes ? Object.keys(config.themes).join(", ") : "none"}`);
100
- }
101
- }
102
- else {
103
- themeToUse = theme;
104
- }
105
- }
106
- let result = "";
107
- const themeVars = generateCSSVariables(themeToUse, sanitizedPrefix);
108
- if (themeVars) {
109
- result += themeVars + "\n";
110
- }
111
- const baseCss = getCssTextBase();
112
- const rootRegex = getRootRegex(sanitizedPrefix);
113
- const cssWithoutThemeVars = baseCss.replace(rootRegex, "").trim();
114
- if (cssWithoutThemeVars) {
115
- result += (result ? "\n" : "") + cssWithoutThemeVars;
116
- }
117
- return result;
118
- }
119
- return {
120
- config: { ...config, prefix: sanitizedPrefix },
121
- createTheme,
122
- css,
123
- getCssText,
124
- globalCss,
125
- keyframes,
126
- preloadTheme,
127
- theme: themeObject,
128
- warmCache,
129
- };
130
- }
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Main entry point for Stoop CSS-in-JS library.
3
- * Exports the createStoop factory function and essential public types.
4
- */
5
- export { createStoop } from "./create-stoop";
6
- export type { CSS, StoopConfig, StoopInstance, StyledComponentProps, Theme, UtilityFunction, Variants, } from "./types";
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Main entry point for Stoop CSS-in-JS library.
3
- * Exports the createStoop factory function and essential public types.
4
- */
5
- export { createStoop } from "./create-stoop";
@@ -1,58 +0,0 @@
1
- /**
2
- * Browser-specific CSS injection.
3
- * Manages a single stylesheet element that gets updated with new CSS rules.
4
- * Handles theme variable injection, deduplication, and stylesheet lifecycle.
5
- */
6
- import type { Theme } from "../types";
7
- /**
8
- * Gets or creates the stylesheet element for CSS injection.
9
- * Reuses the SSR stylesheet if it exists to prevent FOUC.
10
- *
11
- * @param prefix - Optional prefix for stylesheet identification
12
- * @returns HTMLStyleElement
13
- * @throws Error if called in SSR context
14
- */
15
- export declare function getStylesheet(prefix?: string): HTMLStyleElement;
16
- /**
17
- * Injects theme CSS variables into the stylesheet.
18
- * Automatically ensures stylesheet exists before injection.
19
- *
20
- * @param cssVars - CSS variables string
21
- * @param theme - Theme object
22
- * @param prefix - Optional prefix for CSS variables
23
- */
24
- export declare function injectThemeVariables(cssVars: string, theme: Theme, prefix?: string): void;
25
- /**
26
- * Registers a theme for injection (browser-specific).
27
- * Automatically ensures stylesheet exists and injects theme variables.
28
- *
29
- * @param theme - Theme object to register
30
- * @param prefix - Optional prefix for CSS variables
31
- */
32
- export declare function registerTheme(theme: Theme, prefix?: string): void;
33
- /**
34
- * Updates the stylesheet with new CSS rules.
35
- *
36
- * @param css - CSS string to inject
37
- * @param ruleKey - Unique key for deduplication
38
- * @param prefix - Optional prefix for CSS rules
39
- */
40
- export declare function updateStylesheet(css: string, ruleKey: string, prefix?: string): void;
41
- /**
42
- * Injects CSS into the browser stylesheet with deduplication.
43
- *
44
- * @param css - CSS string to inject
45
- * @param ruleKey - Unique key for deduplication
46
- * @param prefix - Optional prefix for CSS rules
47
- */
48
- export declare function injectBrowserCSS(css: string, ruleKey: string, prefix?: string): void;
49
- /**
50
- * Gets the current stylesheet element.
51
- *
52
- * @returns HTMLStyleElement or null if not created
53
- */
54
- export declare function getStylesheetElement(): HTMLStyleElement | null;
55
- /**
56
- * Clears the stylesheet and all caches.
57
- */
58
- export declare function clearStylesheet(): void;
@@ -1,149 +0,0 @@
1
- /**
2
- * Browser-specific CSS injection.
3
- * Manages a single stylesheet element that gets updated with new CSS rules.
4
- * Handles theme variable injection, deduplication, and stylesheet lifecycle.
5
- */
6
- import { isBrowser } from "../utils/environment";
7
- import { getRootRegex, sanitizePrefix } from "../utils/string";
8
- import { generateCSSVariables } from "../utils/theme";
9
- import * as dedup from "./dedup";
10
- import * as ssr from "./ssr";
11
- let stylesheetElement = null;
12
- const lastInjectedThemes = new Map();
13
- const lastInjectedCSSVars = new Map();
14
- /**
15
- * Gets or creates the stylesheet element for CSS injection.
16
- * Reuses the SSR stylesheet if it exists to prevent FOUC.
17
- *
18
- * @param prefix - Optional prefix for stylesheet identification
19
- * @returns HTMLStyleElement
20
- * @throws Error if called in SSR context
21
- */
22
- export function getStylesheet(prefix = "stoop") {
23
- if (!isBrowser()) {
24
- throw new Error("Cannot access document in SSR context");
25
- }
26
- const sanitizedPrefix = sanitizePrefix(prefix);
27
- if (!stylesheetElement || !stylesheetElement.parentNode) {
28
- const ssrStylesheet = document.getElementById("stoop-ssr");
29
- if (ssrStylesheet) {
30
- stylesheetElement = ssrStylesheet;
31
- stylesheetElement.setAttribute("data-stoop", sanitizedPrefix || "stoop");
32
- }
33
- else {
34
- stylesheetElement = document.createElement("style");
35
- stylesheetElement.setAttribute("data-stoop", sanitizedPrefix || "stoop");
36
- document.head.appendChild(stylesheetElement);
37
- }
38
- }
39
- return stylesheetElement;
40
- }
41
- /**
42
- * Injects theme CSS variables into the stylesheet.
43
- * Automatically ensures stylesheet exists before injection.
44
- *
45
- * @param cssVars - CSS variables string
46
- * @param theme - Theme object
47
- * @param prefix - Optional prefix for CSS variables
48
- */
49
- export function injectThemeVariables(cssVars, theme, prefix = "stoop") {
50
- if (!cssVars) {
51
- return;
52
- }
53
- const sanitizedPrefix = sanitizePrefix(prefix);
54
- const key = `__theme_vars_${sanitizedPrefix}`;
55
- const lastCSSVars = lastInjectedCSSVars.get(key) ?? null;
56
- if (lastCSSVars === cssVars) {
57
- const lastTheme = lastInjectedThemes.get(key) ?? null;
58
- if (lastTheme !== theme) {
59
- lastInjectedThemes.set(key, theme);
60
- }
61
- return;
62
- }
63
- lastInjectedThemes.set(key, theme);
64
- lastInjectedCSSVars.set(key, cssVars);
65
- if (!isBrowser()) {
66
- ssr.addToSSRCache(cssVars);
67
- return;
68
- }
69
- const sheet = getStylesheet(sanitizedPrefix);
70
- const currentCSS = sheet.textContent || "";
71
- if (dedup.isInjectedRule(key)) {
72
- const rootRegex = getRootRegex(sanitizedPrefix);
73
- const withoutVars = currentCSS.replace(rootRegex, "").trim();
74
- sheet.textContent = cssVars + (withoutVars ? "\n" + withoutVars : "");
75
- dedup.markRuleAsInjected(key, cssVars);
76
- }
77
- else {
78
- sheet.textContent = cssVars + (currentCSS ? "\n" + currentCSS : "");
79
- dedup.markRuleAsInjected(key, cssVars);
80
- }
81
- }
82
- /**
83
- * Registers a theme for injection (browser-specific).
84
- * Automatically ensures stylesheet exists and injects theme variables.
85
- *
86
- * @param theme - Theme object to register
87
- * @param prefix - Optional prefix for CSS variables
88
- */
89
- export function registerTheme(theme, prefix = "stoop") {
90
- const sanitizedPrefix = sanitizePrefix(prefix);
91
- if (isBrowser()) {
92
- getStylesheet(sanitizedPrefix);
93
- const cssVars = generateCSSVariables(theme, sanitizedPrefix);
94
- injectThemeVariables(cssVars, theme, sanitizedPrefix);
95
- }
96
- }
97
- /**
98
- * Updates the stylesheet with new CSS rules.
99
- *
100
- * @param css - CSS string to inject
101
- * @param ruleKey - Unique key for deduplication
102
- * @param prefix - Optional prefix for CSS rules
103
- */
104
- export function updateStylesheet(css, ruleKey, prefix = "stoop") {
105
- if (!isBrowser()) {
106
- return;
107
- }
108
- const sanitizedPrefix = sanitizePrefix(prefix);
109
- if (dedup.isInjectedRule(ruleKey)) {
110
- return;
111
- }
112
- const sheet = getStylesheet(sanitizedPrefix);
113
- const currentCSS = sheet.textContent || "";
114
- sheet.textContent = currentCSS + (currentCSS ? "\n" : "") + css;
115
- dedup.markRuleAsInjected(ruleKey, css);
116
- }
117
- /**
118
- * Injects CSS into the browser stylesheet with deduplication.
119
- *
120
- * @param css - CSS string to inject
121
- * @param ruleKey - Unique key for deduplication
122
- * @param prefix - Optional prefix for CSS rules
123
- */
124
- export function injectBrowserCSS(css, ruleKey, prefix = "stoop") {
125
- if (dedup.isInjectedRule(ruleKey)) {
126
- return;
127
- }
128
- const sanitizedPrefix = sanitizePrefix(prefix);
129
- updateStylesheet(css, ruleKey, sanitizedPrefix);
130
- }
131
- /**
132
- * Gets the current stylesheet element.
133
- *
134
- * @returns HTMLStyleElement or null if not created
135
- */
136
- export function getStylesheetElement() {
137
- return stylesheetElement;
138
- }
139
- /**
140
- * Clears the stylesheet and all caches.
141
- */
142
- export function clearStylesheet() {
143
- if (stylesheetElement && stylesheetElement.parentNode) {
144
- stylesheetElement.parentNode.removeChild(stylesheetElement);
145
- }
146
- stylesheetElement = null;
147
- lastInjectedThemes.clear();
148
- lastInjectedCSSVars.clear();
149
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * CSS injection deduplication.
3
- * Tracks which CSS rules have been injected to prevent duplicates.
4
- * Used by both browser and SSR injection systems.
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
- * Gets all injected rules as a new Map.
22
- *
23
- * @returns Map of all injected rules
24
- */
25
- export declare function getAllInjectedRules(): Map<string, string>;
26
- /**
27
- * Clears all injected rule tracking.
28
- */
29
- export declare function clearInjectedRules(): void;
@@ -1,38 +0,0 @@
1
- /**
2
- * CSS injection deduplication.
3
- * Tracks which CSS rules have been injected to prevent duplicates.
4
- * Used by both browser and SSR injection systems.
5
- */
6
- const injectedRules = new Map();
7
- /**
8
- * Checks if a CSS rule has already been injected.
9
- *
10
- * @param key - Rule key to check
11
- * @returns True if rule is already injected
12
- */
13
- export function isInjectedRule(key) {
14
- return injectedRules.has(key);
15
- }
16
- /**
17
- * Marks a CSS rule as injected.
18
- *
19
- * @param key - Rule key
20
- * @param css - CSS string
21
- */
22
- export function markRuleAsInjected(key, css) {
23
- injectedRules.set(key, css);
24
- }
25
- /**
26
- * Gets all injected rules as a new Map.
27
- *
28
- * @returns Map of all injected rules
29
- */
30
- export function getAllInjectedRules() {
31
- return new Map(injectedRules);
32
- }
33
- /**
34
- * Clears all injected rule tracking.
35
- */
36
- export function clearInjectedRules() {
37
- injectedRules.clear();
38
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * CSS injection public API.
3
- * Composes browser, SSR, and deduplication modules into a unified interface.
4
- * Provides single stylesheet injection with automatic SSR support.
5
- */
6
- import type { Theme } from "../types";
7
- export { isInjectedRule } from "./dedup";
8
- /**
9
- * Injects CSS into the document with automatic SSR support.
10
- *
11
- * @param css - CSS string to inject
12
- * @param prefix - Optional prefix for CSS rules
13
- * @param ruleKey - Optional unique key for deduplication
14
- */
15
- export declare function injectCSS(css: string, prefix?: string, ruleKey?: string): void;
16
- /**
17
- * Injects theme CSS variables into the document.
18
- *
19
- * @param cssVars - CSS variables string
20
- * @param theme - Theme object
21
- * @param prefix - Optional prefix for CSS variables
22
- */
23
- export declare function injectThemeVariables(cssVars: string, theme: Theme, prefix?: string): void;
24
- /**
25
- * Registers a theme for injection.
26
- *
27
- * @param theme - Theme object to register
28
- * @param prefix - Optional prefix for CSS variables
29
- */
30
- export declare function registerTheme(theme: Theme, prefix?: string): void;
31
- /**
32
- * Gets all injected CSS text (browser or SSR).
33
- *
34
- * @returns CSS text string
35
- */
36
- export declare function getCssText(): string;
37
- /**
38
- * Clears all injected CSS and caches.
39
- */
40
- export declare function clearStylesheet(): void;
@@ -1,75 +0,0 @@
1
- /**
2
- * CSS injection public API.
3
- * Composes browser, SSR, and deduplication modules into a unified interface.
4
- * Provides single stylesheet injection with automatic SSR support.
5
- */
6
- import { clearStyleCache } from "../core/cache";
7
- import { isBrowser } from "../utils/environment";
8
- import * as browser from "./browser";
9
- import * as dedup from "./dedup";
10
- import * as ssr from "./ssr";
11
- export { isInjectedRule } from "./dedup";
12
- /**
13
- * Injects CSS into the document with automatic SSR support.
14
- *
15
- * @param css - CSS string to inject
16
- * @param prefix - Optional prefix for CSS rules
17
- * @param ruleKey - Optional unique key for deduplication
18
- */
19
- export function injectCSS(css, prefix = "stoop", ruleKey) {
20
- const key = ruleKey || css;
21
- if (!isBrowser()) {
22
- if (!dedup.isInjectedRule(key)) {
23
- dedup.markRuleAsInjected(key, css);
24
- }
25
- ssr.addToSSRCache(css);
26
- return;
27
- }
28
- browser.injectBrowserCSS(css, key, prefix);
29
- }
30
- /**
31
- * Injects theme CSS variables into the document.
32
- *
33
- * @param cssVars - CSS variables string
34
- * @param theme - Theme object
35
- * @param prefix - Optional prefix for CSS variables
36
- */
37
- export function injectThemeVariables(cssVars, theme, prefix = "stoop") {
38
- browser.injectThemeVariables(cssVars, theme, prefix);
39
- }
40
- /**
41
- * Registers a theme for injection.
42
- *
43
- * @param theme - Theme object to register
44
- * @param prefix - Optional prefix for CSS variables
45
- */
46
- export function registerTheme(theme, prefix = "stoop") {
47
- browser.registerTheme(theme, prefix);
48
- }
49
- /**
50
- * Gets all injected CSS text (browser or SSR).
51
- *
52
- * @returns CSS text string
53
- */
54
- export function getCssText() {
55
- if (isBrowser()) {
56
- const sheetElement = browser.getStylesheetElement();
57
- if (sheetElement && sheetElement.parentNode) {
58
- const sheetCSS = sheetElement.textContent || "";
59
- if (!sheetCSS && dedup.getAllInjectedRules().size > 0) {
60
- return ssr.getSSRCacheText();
61
- }
62
- return sheetCSS;
63
- }
64
- }
65
- return ssr.getSSRCacheText();
66
- }
67
- /**
68
- * Clears all injected CSS and caches.
69
- */
70
- export function clearStylesheet() {
71
- browser.clearStylesheet();
72
- dedup.clearInjectedRules();
73
- ssr.clearSSRCache();
74
- clearStyleCache();
75
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * SSR cache management for CSS injection.
3
- * Maintains a cache of CSS text for server-side rendering.
4
- */
5
- /**
6
- * Adds CSS to the SSR cache with FIFO eviction.
7
- *
8
- * @param css - CSS string to cache
9
- */
10
- export declare function addToSSRCache(css: string): void;
11
- /**
12
- * Gets all cached CSS text for SSR.
13
- *
14
- * @returns Joined CSS text string
15
- */
16
- export declare function getSSRCacheText(): string;
17
- /**
18
- * Clears the SSR cache.
19
- */
20
- export declare function clearSSRCache(): void;
21
- /**
22
- * Checks if CSS is already in the SSR cache.
23
- *
24
- * @param css - CSS string to check
25
- * @returns True if CSS is cached
26
- */
27
- export declare function isInSSRCache(css: string): boolean;
@@ -1,46 +0,0 @@
1
- /**
2
- * SSR cache management for CSS injection.
3
- * Maintains a cache of CSS text for server-side rendering.
4
- */
5
- import { MAX_CSS_CACHE_SIZE } from "../constants";
6
- const cssTextCache = new Map();
7
- /**
8
- * Adds CSS to the SSR cache with FIFO eviction.
9
- *
10
- * @param css - CSS string to cache
11
- */
12
- export function addToSSRCache(css) {
13
- if (cssTextCache.has(css)) {
14
- return;
15
- }
16
- if (cssTextCache.size >= MAX_CSS_CACHE_SIZE) {
17
- const firstKey = cssTextCache.keys().next().value;
18
- if (firstKey !== undefined) {
19
- cssTextCache.delete(firstKey);
20
- }
21
- }
22
- cssTextCache.set(css, true);
23
- }
24
- /**
25
- * Gets all cached CSS text for SSR.
26
- *
27
- * @returns Joined CSS text string
28
- */
29
- export function getSSRCacheText() {
30
- return Array.from(cssTextCache.keys()).join("\n");
31
- }
32
- /**
33
- * Clears the SSR cache.
34
- */
35
- export function clearSSRCache() {
36
- cssTextCache.clear();
37
- }
38
- /**
39
- * Checks if CSS is already in the SSR cache.
40
- *
41
- * @param css - CSS string to check
42
- * @returns True if CSS is cached
43
- */
44
- export function isInSSRCache(css) {
45
- return cssTextCache.has(css);
46
- }
package/dist/ssr.d.ts DELETED
@@ -1,21 +0,0 @@
1
- /**
2
- * Server-safe entry point for Stoop.
3
- * Exports only functions that work in Server Components.
4
- * NO React dependencies, NO "use client" directive.
5
- *
6
- * Use this entry point when importing Stoop in Next.js Server Components.
7
- *
8
- * @example
9
- * ```typescript
10
- * // In a Server Component (layout.tsx)
11
- * import { createStoop } from 'stoop/ssr';
12
- *
13
- * const { getCssText } = createStoop(config);
14
- * const cssText = getCssText();
15
- * ```
16
- */
17
- export { createStoop } from "./create-stoop-server";
18
- export type { StoopServerInstance } from "./create-stoop-server";
19
- export { getCssText, clearStylesheet } from "./inject";
20
- export { generateCSSVariables } from "./utils/theme";
21
- export type { Theme, CSS, StoopConfig, UtilityFunction, Variants } from "./types";
package/dist/ssr.js DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * Server-safe entry point for Stoop.
3
- * Exports only functions that work in Server Components.
4
- * NO React dependencies, NO "use client" directive.
5
- *
6
- * Use this entry point when importing Stoop in Next.js Server Components.
7
- *
8
- * @example
9
- * ```typescript
10
- * // In a Server Component (layout.tsx)
11
- * import { createStoop } from 'stoop/ssr';
12
- *
13
- * const { getCssText } = createStoop(config);
14
- * const cssText = getCssText();
15
- * ```
16
- */
17
- export { createStoop } from "./create-stoop-server";
18
- export { getCssText, clearStylesheet } from "./inject";
19
- export { generateCSSVariables } from "./utils/theme";
@@ -1,6 +0,0 @@
1
- /**
2
- * Checks if code is running in a browser environment.
3
- *
4
- * @returns True if running in browser, false if in SSR/Node environment
5
- */
6
- export declare function isBrowser(): boolean;
@@ -1,12 +0,0 @@
1
- /**
2
- * Checks if code is running in a browser environment.
3
- *
4
- * @returns True if running in browser, false if in SSR/Node environment
5
- */
6
- export function isBrowser() {
7
- return (typeof window !== "undefined" &&
8
- typeof document !== "undefined" &&
9
- typeof window.document === "object" &&
10
- // Ensure we're not in React Server Component or SSR context
11
- typeof window.requestAnimationFrame === "function");
12
- }