stoop 0.3.0 → 0.4.1
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.
- package/README.md +125 -0
- package/dist/api/core-api.d.ts +34 -0
- package/dist/api/styled.d.ts +0 -1
- package/dist/api/theme-provider.d.ts +41 -0
- package/dist/constants.d.ts +11 -1
- package/dist/core/compiler.d.ts +11 -0
- package/dist/core/theme-manager.d.ts +34 -3
- package/dist/create-stoop-internal.d.ts +30 -0
- package/dist/create-stoop-ssr.d.ts +10 -0
- package/dist/create-stoop-ssr.js +16 -0
- package/dist/create-stoop.d.ts +32 -1
- package/dist/create-stoop.js +16 -147
- package/dist/inject.d.ts +113 -0
- package/dist/types/index.d.ts +147 -12
- package/dist/types/react-polymorphic-types.d.ts +13 -2
- package/dist/utils/auto-preload.d.ts +45 -0
- package/dist/utils/helpers.d.ts +64 -0
- package/dist/utils/storage.d.ts +148 -0
- package/dist/utils/{string.d.ts → theme-utils.d.ts} +20 -3
- package/dist/utils/theme.d.ts +14 -2
- package/package.json +44 -17
- package/dist/api/create-theme.d.ts +0 -13
- package/dist/api/create-theme.js +0 -43
- package/dist/api/css.d.ts +0 -16
- package/dist/api/css.js +0 -20
- package/dist/api/global-css.js +0 -89
- package/dist/api/keyframes.d.ts +0 -16
- package/dist/api/keyframes.js +0 -95
- package/dist/api/provider.d.ts +0 -19
- package/dist/api/provider.js +0 -109
- package/dist/api/styled.js +0 -170
- package/dist/api/use-theme.d.ts +0 -13
- package/dist/api/use-theme.js +0 -21
- package/dist/constants.js +0 -144
- package/dist/core/cache.js +0 -68
- package/dist/core/compiler.js +0 -198
- package/dist/core/theme-manager.js +0 -97
- package/dist/core/variants.js +0 -32
- package/dist/create-stoop-server.d.ts +0 -33
- package/dist/create-stoop-server.js +0 -130
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -5
- package/dist/inject/browser.d.ts +0 -58
- package/dist/inject/browser.js +0 -149
- package/dist/inject/dedup.d.ts +0 -29
- package/dist/inject/dedup.js +0 -38
- package/dist/inject/index.d.ts +0 -40
- package/dist/inject/index.js +0 -75
- package/dist/inject/ssr.d.ts +0 -27
- package/dist/inject/ssr.js +0 -46
- package/dist/ssr.d.ts +0 -21
- package/dist/ssr.js +0 -19
- package/dist/types/index.js +0 -5
- package/dist/utils/environment.d.ts +0 -6
- package/dist/utils/environment.js +0 -12
- package/dist/utils/string.js +0 -253
- package/dist/utils/theme-map.d.ts +0 -22
- package/dist/utils/theme-map.js +0 -97
- package/dist/utils/theme-validation.d.ts +0 -13
- package/dist/utils/theme-validation.js +0 -36
- package/dist/utils/theme.js +0 -279
- package/dist/utils/type-guards.d.ts +0 -26
- package/dist/utils/type-guards.js +0 -38
- package/dist/utils/utilities.d.ts +0 -14
- package/dist/utils/utilities.js +0 -43
package/dist/core/compiler.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CSS compilation engine.
|
|
3
|
-
* Converts CSS objects to CSS strings and generates unique class names.
|
|
4
|
-
* Handles nested selectors, media queries, styled component targeting, and theme tokens.
|
|
5
|
-
*/
|
|
6
|
-
import { MAX_CSS_NESTING_DEPTH, STOOP_COMPONENT_SYMBOL } from "../constants";
|
|
7
|
-
import { injectCSS } from "../inject";
|
|
8
|
-
import { escapeCSSValue, hash, sanitizeCSSPropertyName, sanitizeCSSSelector, sanitizeMediaQuery, sanitizePrefix, } from "../utils/string";
|
|
9
|
-
import { replaceThemeTokensWithVars } from "../utils/theme";
|
|
10
|
-
import { isValidCSSObject } from "../utils/type-guards";
|
|
11
|
-
import { applyUtilities } from "../utils/utilities";
|
|
12
|
-
import { classNameCache, cssStringCache } from "./cache";
|
|
13
|
-
/**
|
|
14
|
-
* Checks if a key/value pair represents a styled component reference.
|
|
15
|
-
*
|
|
16
|
-
* @param key - Property key to check
|
|
17
|
-
* @param value - Property value to check
|
|
18
|
-
* @returns True if key/value represents a styled component reference
|
|
19
|
-
*/
|
|
20
|
-
function isStyledComponentKey(key, value) {
|
|
21
|
-
if (typeof key === "symbol" && key === STOOP_COMPONENT_SYMBOL) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
if (typeof value === "object" && value !== null && STOOP_COMPONENT_SYMBOL in value) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
if (typeof key === "string" && key.startsWith("__STOOP_COMPONENT_")) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Extracts the class name from a styled component reference.
|
|
34
|
-
*
|
|
35
|
-
* @param key - Property key
|
|
36
|
-
* @param value - Property value
|
|
37
|
-
* @returns Extracted class name or empty string
|
|
38
|
-
*/
|
|
39
|
-
function getClassNameFromKeyOrValue(key, value) {
|
|
40
|
-
if (typeof value === "object" &&
|
|
41
|
-
value !== null &&
|
|
42
|
-
"__stoopClassName" in value &&
|
|
43
|
-
typeof value.__stoopClassName === "string") {
|
|
44
|
-
return value.__stoopClassName;
|
|
45
|
-
}
|
|
46
|
-
if (typeof key === "string" && key.startsWith("__STOOP_COMPONENT_")) {
|
|
47
|
-
return key.replace("__STOOP_COMPONENT_", "");
|
|
48
|
-
}
|
|
49
|
-
return "";
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Converts a CSS object to a CSS string with proper nesting and selectors.
|
|
53
|
-
* Handles pseudo-selectors, media queries, combinators, and styled component targeting.
|
|
54
|
-
*
|
|
55
|
-
* @param obj - CSS object to convert
|
|
56
|
-
* @param selector - Current selector context
|
|
57
|
-
* @param depth - Current nesting depth
|
|
58
|
-
* @param media - Media query breakpoints
|
|
59
|
-
* @returns CSS string
|
|
60
|
-
*/
|
|
61
|
-
function cssObjectToString(obj, selector = "", depth = 0, media) {
|
|
62
|
-
if (!obj || typeof obj !== "object") {
|
|
63
|
-
return "";
|
|
64
|
-
}
|
|
65
|
-
if (depth > MAX_CSS_NESTING_DEPTH) {
|
|
66
|
-
return "";
|
|
67
|
-
}
|
|
68
|
-
const cssProperties = [];
|
|
69
|
-
const nestedRulesList = [];
|
|
70
|
-
const keys = Object.keys(obj).sort();
|
|
71
|
-
for (const key of keys) {
|
|
72
|
-
const value = obj[key];
|
|
73
|
-
if (isStyledComponentKey(key, value)) {
|
|
74
|
-
const componentClassName = getClassNameFromKeyOrValue(key, value);
|
|
75
|
-
if (!componentClassName) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
const sanitizedClassName = sanitizeCSSSelector(componentClassName);
|
|
79
|
-
if (!sanitizedClassName) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
const componentSelector = selector
|
|
83
|
-
? `${selector} .${sanitizedClassName}`
|
|
84
|
-
: `.${sanitizedClassName}`;
|
|
85
|
-
const nestedCss = isValidCSSObject(value)
|
|
86
|
-
? cssObjectToString(value, componentSelector, depth + 1, media)
|
|
87
|
-
: "";
|
|
88
|
-
if (nestedCss) {
|
|
89
|
-
nestedRulesList.push(nestedCss);
|
|
90
|
-
}
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if (isValidCSSObject(value)) {
|
|
94
|
-
if (media && key in media) {
|
|
95
|
-
const mediaQuery = sanitizeMediaQuery(media[key]);
|
|
96
|
-
if (mediaQuery) {
|
|
97
|
-
const nestedCss = cssObjectToString(value, selector, depth + 1, media);
|
|
98
|
-
if (nestedCss) {
|
|
99
|
-
nestedRulesList.push(`${mediaQuery} { ${nestedCss} }`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else if (key.startsWith("@")) {
|
|
104
|
-
const sanitizedKey = sanitizeCSSSelector(key);
|
|
105
|
-
if (sanitizedKey) {
|
|
106
|
-
const nestedCss = cssObjectToString(value, selector, depth + 1, media);
|
|
107
|
-
if (nestedCss) {
|
|
108
|
-
nestedRulesList.push(`${sanitizedKey} { ${nestedCss} }`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
else if (key.includes("&")) {
|
|
113
|
-
const sanitizedKey = sanitizeCSSSelector(key);
|
|
114
|
-
if (sanitizedKey) {
|
|
115
|
-
const parts = sanitizedKey.split("&");
|
|
116
|
-
const nestedSelector = parts.join(selector);
|
|
117
|
-
const nestedCss = cssObjectToString(value, nestedSelector, depth + 1, media);
|
|
118
|
-
if (nestedCss) {
|
|
119
|
-
nestedRulesList.push(nestedCss);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else if (key.startsWith(":")) {
|
|
124
|
-
const sanitizedKey = sanitizeCSSSelector(key);
|
|
125
|
-
if (sanitizedKey) {
|
|
126
|
-
const nestedSelector = `${selector}${sanitizedKey}`;
|
|
127
|
-
const nestedCss = cssObjectToString(value, nestedSelector, depth + 1, media);
|
|
128
|
-
if (nestedCss) {
|
|
129
|
-
nestedRulesList.push(nestedCss);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else if (key.includes(" ") || key.includes(">") || key.includes("+") || key.includes("~")) {
|
|
134
|
-
const sanitizedKey = sanitizeCSSSelector(key);
|
|
135
|
-
if (sanitizedKey) {
|
|
136
|
-
const startsWithCombinator = /^[\s>+~]/.test(sanitizedKey.trim());
|
|
137
|
-
const nestedSelector = startsWithCombinator
|
|
138
|
-
? `${selector}${sanitizedKey}`
|
|
139
|
-
: `${selector} ${sanitizedKey}`;
|
|
140
|
-
const nestedCss = cssObjectToString(value, nestedSelector, depth + 1, media);
|
|
141
|
-
if (nestedCss) {
|
|
142
|
-
nestedRulesList.push(nestedCss);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
const sanitizedKey = sanitizeCSSSelector(key);
|
|
148
|
-
if (sanitizedKey) {
|
|
149
|
-
const nestedSelector = selector ? `${selector} ${sanitizedKey}` : sanitizedKey;
|
|
150
|
-
const nestedCss = cssObjectToString(value, nestedSelector, depth + 1, media);
|
|
151
|
-
if (nestedCss) {
|
|
152
|
-
nestedRulesList.push(nestedCss);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else if (value !== undefined) {
|
|
158
|
-
const property = sanitizeCSSPropertyName(key);
|
|
159
|
-
if (property && (typeof value === "string" || typeof value === "number")) {
|
|
160
|
-
const escapedValue = escapeCSSValue(value);
|
|
161
|
-
cssProperties.push(`${property}: ${escapedValue};`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
const rule = cssProperties.length > 0 ? `${selector} { ${cssProperties.join(" ")} }` : "";
|
|
166
|
-
return rule + nestedRulesList.join("");
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Compiles CSS objects into CSS strings and generates unique class names.
|
|
170
|
-
* Handles nested selectors, media queries, styled component targeting, and theme tokens.
|
|
171
|
-
*
|
|
172
|
-
* @param styles - CSS object to compile
|
|
173
|
-
* @param currentTheme - Theme for token resolution
|
|
174
|
-
* @param prefix - Optional prefix for generated class names
|
|
175
|
-
* @param media - Optional media query breakpoints
|
|
176
|
-
* @param utils - Optional utility functions
|
|
177
|
-
* @param themeMap - Optional theme scale mappings
|
|
178
|
-
* @returns Generated class name
|
|
179
|
-
*/
|
|
180
|
-
export function compileCSS(styles, currentTheme, prefix = "stoop", media, utils, themeMap) {
|
|
181
|
-
const sanitizedPrefix = sanitizePrefix(prefix);
|
|
182
|
-
const stylesWithUtils = applyUtilities(styles, utils);
|
|
183
|
-
const themedStyles = replaceThemeTokensWithVars(stylesWithUtils, currentTheme, themeMap);
|
|
184
|
-
const cssString = cssObjectToString(themedStyles, "", 0, media);
|
|
185
|
-
const stylesHash = hash(cssString);
|
|
186
|
-
const className = sanitizedPrefix ? `${sanitizedPrefix}-${stylesHash}` : `css-${stylesHash}`;
|
|
187
|
-
const cacheKey = `${sanitizedPrefix}:${className}`;
|
|
188
|
-
const cachedCSS = cssStringCache.get(cacheKey);
|
|
189
|
-
if (cachedCSS) {
|
|
190
|
-
injectCSS(cachedCSS, sanitizedPrefix, cacheKey);
|
|
191
|
-
return className;
|
|
192
|
-
}
|
|
193
|
-
const fullCSS = cssObjectToString(themedStyles, `.${className}`, 0, media);
|
|
194
|
-
cssStringCache.set(cacheKey, fullCSS);
|
|
195
|
-
classNameCache.set(cacheKey, className);
|
|
196
|
-
injectCSS(fullCSS, sanitizedPrefix, cacheKey);
|
|
197
|
-
return className;
|
|
198
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Theme variable management.
|
|
3
|
-
* Updates CSS custom properties when theme changes.
|
|
4
|
-
* Ensures CSS variables are injected and kept in sync with theme updates.
|
|
5
|
-
* Automatically merges themes with the default theme when applied.
|
|
6
|
-
*/
|
|
7
|
-
import { injectThemeVariables } from "../inject";
|
|
8
|
-
import { isBrowser } from "../utils/environment";
|
|
9
|
-
import { generateCSSVariables, themesAreEqual } from "../utils/theme";
|
|
10
|
-
const defaultThemes = new Map();
|
|
11
|
-
const mergedThemeCache = new WeakMap();
|
|
12
|
-
/**
|
|
13
|
-
* Registers the default theme for a given prefix.
|
|
14
|
-
* Called automatically by createStoop.
|
|
15
|
-
*
|
|
16
|
-
* @param theme - Default theme from createStoop
|
|
17
|
-
* @param prefix - Optional prefix for theme scoping
|
|
18
|
-
*/
|
|
19
|
-
export function registerDefaultTheme(theme, prefix = "stoop") {
|
|
20
|
-
const sanitizedPrefix = prefix || "";
|
|
21
|
-
defaultThemes.set(sanitizedPrefix, theme);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Gets the default theme for a given prefix.
|
|
25
|
-
*
|
|
26
|
-
* @param prefix - Optional prefix for theme scoping
|
|
27
|
-
* @returns Default theme or null if not registered
|
|
28
|
-
*/
|
|
29
|
-
function getDefaultTheme(prefix = "stoop") {
|
|
30
|
-
const sanitizedPrefix = prefix || "";
|
|
31
|
-
return defaultThemes.get(sanitizedPrefix) || null;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Merges a theme with the default theme if it's not already the default theme.
|
|
35
|
-
* This ensures all themes extend the default theme, keeping all original properties.
|
|
36
|
-
* Uses caching to avoid repeated merging of the same theme objects.
|
|
37
|
-
*
|
|
38
|
-
* @param theme - Theme to merge
|
|
39
|
-
* @param prefix - Optional prefix for theme scoping
|
|
40
|
-
* @returns Merged theme (or original if it's the default theme)
|
|
41
|
-
*/
|
|
42
|
-
function mergeWithDefaultTheme(theme, prefix = "stoop") {
|
|
43
|
-
const defaultTheme = getDefaultTheme(prefix);
|
|
44
|
-
if (!defaultTheme) {
|
|
45
|
-
return theme;
|
|
46
|
-
}
|
|
47
|
-
if (themesAreEqual(theme, defaultTheme)) {
|
|
48
|
-
return theme;
|
|
49
|
-
}
|
|
50
|
-
let prefixCache = mergedThemeCache.get(theme);
|
|
51
|
-
if (!prefixCache) {
|
|
52
|
-
prefixCache = new Map();
|
|
53
|
-
mergedThemeCache.set(theme, prefixCache);
|
|
54
|
-
}
|
|
55
|
-
const cached = prefixCache.get(prefix);
|
|
56
|
-
if (cached) {
|
|
57
|
-
return cached;
|
|
58
|
-
}
|
|
59
|
-
const merged = { ...defaultTheme };
|
|
60
|
-
const allThemeKeys = Object.keys(theme);
|
|
61
|
-
for (const key of allThemeKeys) {
|
|
62
|
-
if (key === "media") {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const themeValue = theme[key];
|
|
66
|
-
const defaultValue = defaultTheme[key];
|
|
67
|
-
if (themeValue &&
|
|
68
|
-
typeof themeValue === "object" &&
|
|
69
|
-
!Array.isArray(themeValue) &&
|
|
70
|
-
defaultValue &&
|
|
71
|
-
typeof defaultValue === "object" &&
|
|
72
|
-
!Array.isArray(defaultValue)) {
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
-
merged[key] = { ...defaultValue, ...themeValue };
|
|
75
|
-
}
|
|
76
|
-
else if (themeValue !== undefined) {
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
-
merged[key] = themeValue;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
prefixCache.set(prefix, merged);
|
|
82
|
-
return merged;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Updates CSS custom properties when theme changes.
|
|
86
|
-
*
|
|
87
|
-
* @param theme - Theme object to generate CSS variables from
|
|
88
|
-
* @param prefix - Optional prefix for CSS variable names
|
|
89
|
-
*/
|
|
90
|
-
export function updateThemeVariables(theme, prefix = "stoop") {
|
|
91
|
-
if (!isBrowser()) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const mergedTheme = mergeWithDefaultTheme(theme, prefix);
|
|
95
|
-
const cssVars = generateCSSVariables(mergedTheme, prefix);
|
|
96
|
-
injectThemeVariables(cssVars, mergedTheme, prefix);
|
|
97
|
-
}
|
package/dist/core/variants.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
return hasVariants
|
|
30
|
-
? { ...baseStyles, ...appliedVariantStyles.reduce((acc, style) => ({ ...acc, ...style }), {}) }
|
|
31
|
-
: baseStyles;
|
|
32
|
-
}
|
|
@@ -1,33 +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 type { CSS, StoopConfig, Theme } from "./types";
|
|
9
|
-
/**
|
|
10
|
-
* Server-safe Stoop instance interface.
|
|
11
|
-
* Only includes APIs that work without React dependencies.
|
|
12
|
-
*/
|
|
13
|
-
export interface StoopServerInstance {
|
|
14
|
-
config: StoopConfig & {
|
|
15
|
-
prefix: string;
|
|
16
|
-
};
|
|
17
|
-
createTheme: (themeOverride: Partial<Theme>) => Theme;
|
|
18
|
-
css: (styles: CSS) => string;
|
|
19
|
-
getCssText: (theme?: string | Theme) => string;
|
|
20
|
-
globalCss: (...args: CSS[]) => () => void;
|
|
21
|
-
keyframes: (definition: Record<string, CSS>) => string;
|
|
22
|
-
preloadTheme: (theme: string | Theme) => void;
|
|
23
|
-
theme: Theme;
|
|
24
|
-
warmCache: (styles: CSS[]) => void;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Creates a server-safe Stoop instance with the provided configuration.
|
|
28
|
-
* Only includes APIs that work without React: css, globalCss, keyframes, getCssText, etc.
|
|
29
|
-
*
|
|
30
|
-
* @param config - Configuration object containing theme, media queries, utilities, and optional prefix/themeMap
|
|
31
|
-
* @returns StoopServerInstance with server-safe API functions
|
|
32
|
-
*/
|
|
33
|
-
export declare function createStoop(config: StoopConfig): StoopServerInstance;
|
|
@@ -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
package/dist/inject/browser.d.ts
DELETED
|
@@ -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;
|