stoop 0.1.0 → 0.2.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.
- package/LICENSE.md +21 -0
- package/README.md +142 -51
- package/dist/api/create-theme.d.ts +13 -0
- package/dist/api/css.d.ts +16 -0
- package/dist/api/global-css.d.ts +18 -0
- package/dist/api/keyframes.d.ts +16 -0
- package/dist/api/provider.d.ts +19 -0
- package/dist/api/styled.d.ts +41 -0
- package/dist/api/use-theme.d.ts +13 -0
- package/dist/constants.d.ts +21 -0
- package/dist/core/cache.d.ts +39 -0
- package/dist/core/compiler.d.ts +19 -0
- package/dist/core/theme-manager.d.ts +30 -0
- package/dist/core/variants.d.ts +15 -0
- package/dist/create-stoop.d.ts +12 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +13 -156
- package/dist/inject/browser.d.ts +59 -0
- package/dist/inject/dedup.d.ts +29 -0
- package/dist/inject/index.d.ts +41 -0
- package/dist/inject/ssr.d.ts +28 -0
- package/dist/types/index.d.ts +141 -0
- package/dist/types/react-polymorphic-types.d.ts +17 -0
- package/dist/utils/string.d.ts +102 -0
- package/dist/utils/theme-map.d.ts +25 -0
- package/dist/utils/theme-validation.d.ts +13 -0
- package/dist/utils/theme.d.ts +43 -0
- package/dist/utils/type-guards.d.ts +26 -0
- package/dist/utils/utilities.d.ts +14 -0
- package/package.json +63 -39
- package/dist/components/Badge/index.d.ts +0 -13
- package/dist/components/Badge/styles.d.ts +0 -3
- package/dist/components/Badge/types.d.ts +0 -13
- package/dist/components/Button/index.d.ts +0 -14
- package/dist/components/Button/styles.d.ts +0 -6
- package/dist/components/Button/types.d.ts +0 -22
- package/dist/components/Card/index.d.ts +0 -14
- package/dist/components/Card/styles.d.ts +0 -16
- package/dist/components/Card/types.d.ts +0 -18
- package/dist/components/Input/index.d.ts +0 -13
- package/dist/components/Input/styles.d.ts +0 -3
- package/dist/components/Input/types.d.ts +0 -8
- package/dist/components/Menu/index.d.ts +0 -13
- package/dist/components/Menu/styles.d.ts +0 -9
- package/dist/components/Menu/types.d.ts +0 -26
- package/dist/components/Modal/index.d.ts +0 -14
- package/dist/components/Modal/styles.d.ts +0 -14
- package/dist/components/Modal/types.d.ts +0 -18
- package/dist/components/Popover/index.d.ts +0 -13
- package/dist/components/Popover/styles.d.ts +0 -4
- package/dist/components/Popover/types.d.ts +0 -16
- package/dist/components/Provider/GlobalStyles.d.ts +0 -10
- package/dist/components/Provider/StoopProvider.d.ts +0 -41
- package/dist/components/Provider/index.d.ts +0 -2
- package/dist/components/Section/index.d.ts +0 -15
- package/dist/components/Section/styles.d.ts +0 -5
- package/dist/components/Section/types.d.ts +0 -20
- package/dist/components/Select/index.d.ts +0 -13
- package/dist/components/Select/styles.d.ts +0 -7
- package/dist/components/Select/types.d.ts +0 -30
- package/dist/components/Stack/index.d.ts +0 -16
- package/dist/components/Stack/styles.d.ts +0 -10
- package/dist/components/Stack/types.d.ts +0 -42
- package/dist/components/Tabs/index.d.ts +0 -13
- package/dist/components/Tabs/styles.d.ts +0 -8
- package/dist/components/Tabs/types.d.ts +0 -20
- package/dist/components/Text/index.d.ts +0 -14
- package/dist/components/Text/styles.d.ts +0 -4
- package/dist/components/Text/types.d.ts +0 -21
- package/dist/components/Textarea/index.d.ts +0 -15
- package/dist/components/Textarea/styles.d.ts +0 -3
- package/dist/components/Textarea/types.d.ts +0 -10
- package/dist/components/index.d.ts +0 -27
- package/dist/hooks/index.d.ts +0 -5
- package/dist/hooks/useBreakpoints.d.ts +0 -14
- package/dist/hooks/useEventListener.d.ts +0 -6
- package/dist/hooks/useFloating.d.ts +0 -18
- package/dist/hooks/useOutsideClick.d.ts +0 -6
- package/dist/hooks/usePortal.d.ts +0 -9
- package/dist/styles/compiler.d.ts +0 -25
- package/dist/styles/index.d.ts +0 -2
- package/dist/styles/theme.d.ts +0 -495
- package/dist/styles/types.d.ts +0 -66
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jackson Dolman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,88 +1,179 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Stoop
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CSS-in-JS library with type inference, theme creation, and variants support.
|
|
4
4
|
|
|
5
|
-
](https://www.npmjs.com/package/stoop)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
> **Warning: Not Production Ready**
|
|
9
|
+
> Stoop is currently in active development and is not recommended for production use. The API may change, and there may be bugs or missing features. Use at your own risk.
|
|
10
|
+
|
|
11
|
+
## About
|
|
12
|
+
|
|
13
|
+
Stoop is a CSS-in-JS library—a TypeScript-first approach to styling that provides type-safe CSS objects with full type inference. Similar to [Stitches](https://stitches.dev) and [Vanilla Extract](https://vanilla-extract.style), Stoop focuses on type safety and developer experience.
|
|
14
|
+
|
|
15
|
+
Stoop is a minimalist implementation of Stitches' high-level features. It provides a similar API for `styled`, `css`, and variants, but omits several Stitches features.
|
|
16
|
+
|
|
17
|
+
**What's missing compared to Stitches:**
|
|
18
|
+
- Compound variants
|
|
19
|
+
- Build-time CSS extraction (runtime-only)
|
|
20
|
+
- Advanced utility functions (basic support only)
|
|
21
|
+
- Additional Stitches APIs
|
|
22
|
+
|
|
23
|
+
If you need these features, consider [Vanilla Extract](https://vanilla-extract.style) or [styled-components](https://styled-components.com).
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- Type-safe theming with TypeScript inference
|
|
28
|
+
- CSS variables for theme tokens
|
|
29
|
+
- Variant system for component variations
|
|
30
|
+
- Utility functions for custom CSS transformations
|
|
31
|
+
- Multiple themes with `createTheme()`
|
|
32
|
+
- SSR support via `getCssText()`
|
|
33
|
+
- React 19+ required (Next.js Pages & App Router supported)
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
8
36
|
|
|
9
37
|
```sh
|
|
10
38
|
npm install stoop
|
|
11
39
|
# or
|
|
12
40
|
bun add stoop
|
|
41
|
+
# or
|
|
42
|
+
yarn add stoop
|
|
13
43
|
```
|
|
14
44
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
### Setup Provider
|
|
18
|
-
|
|
19
|
-
Wrap your app with the `StoopProvider`:
|
|
45
|
+
## Quick Start
|
|
20
46
|
|
|
21
47
|
```tsx
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
48
|
+
import { createStoop } from "stoop";
|
|
49
|
+
|
|
50
|
+
const { styled, css, createTheme, globalCss, keyframes, ThemeContext } = createStoop({
|
|
51
|
+
theme: {
|
|
52
|
+
colors: {
|
|
53
|
+
primary: "#0070f3",
|
|
54
|
+
background: "#ffffff",
|
|
55
|
+
text: "#000000",
|
|
56
|
+
},
|
|
57
|
+
space: {
|
|
58
|
+
small: "8px",
|
|
59
|
+
medium: "16px",
|
|
60
|
+
large: "24px",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const Button = styled("button", {
|
|
66
|
+
padding: "$medium",
|
|
67
|
+
backgroundColor: "$primary",
|
|
68
|
+
}, {
|
|
69
|
+
variant: {
|
|
70
|
+
primary: { backgroundColor: "$primary" },
|
|
71
|
+
secondary: { backgroundColor: "$secondary" },
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
<Button variant="primary">Click me</Button>
|
|
31
76
|
```
|
|
32
77
|
|
|
33
|
-
|
|
78
|
+
See [GUIDE.md](./docs/GUIDE.md) for complete setup instructions.
|
|
79
|
+
|
|
80
|
+
## Documentation
|
|
81
|
+
|
|
82
|
+
- **[GUIDE.md](./docs/GUIDE.md)** - Step-by-step setup and usage guide
|
|
83
|
+
- **[API.md](./docs/API.md)** - Complete API reference
|
|
84
|
+
- **[ARCHITECTURE.md](./docs/ARCHITECTURE.md)** - Internal implementation details
|
|
85
|
+
|
|
86
|
+
## API Overview
|
|
87
|
+
|
|
88
|
+
### `createStoop(config)`
|
|
89
|
+
|
|
90
|
+
Creates a Stoop instance. Returns: `styled`, `css`, `createTheme`, `globalCss`, `keyframes`, `getCssText`, `warmCache`, `ThemeContext`, `theme`, `config`.
|
|
91
|
+
|
|
92
|
+
See [API.md](./docs/API.md) for complete API documentation.
|
|
93
|
+
|
|
94
|
+
### Theme Tokens
|
|
95
|
+
|
|
96
|
+
Use `$` prefix for theme tokens. Shorthand `$token` searches all scales; explicit `$scale.token` specifies the scale.
|
|
34
97
|
|
|
35
98
|
```tsx
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<Stack gap="medium">
|
|
41
|
-
<Text as="h1">Welcome</Text>
|
|
42
|
-
<Button>Click me</Button>
|
|
43
|
-
</Stack>
|
|
44
|
-
);
|
|
99
|
+
{
|
|
100
|
+
color: "$primary", // Shorthand (preferred)
|
|
101
|
+
padding: "$medium", // Property-aware resolution
|
|
102
|
+
fontSize: "$fontSizes.small", // Explicit scale
|
|
45
103
|
}
|
|
46
104
|
```
|
|
47
105
|
|
|
48
|
-
|
|
106
|
+
Tokens resolve to CSS variables (`var(--colors-primary)`), enabling instant theme switching without recompiling CSS.
|
|
107
|
+
|
|
108
|
+
### Variants
|
|
109
|
+
|
|
110
|
+
Variants create component variations via props:
|
|
49
111
|
|
|
50
112
|
```tsx
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
113
|
+
const Button = styled("button", {}, {
|
|
114
|
+
variant: {
|
|
115
|
+
primary: { backgroundColor: "$primary" },
|
|
116
|
+
secondary: { backgroundColor: "$secondary" },
|
|
117
|
+
},
|
|
118
|
+
size: {
|
|
119
|
+
small: { padding: "$small" },
|
|
120
|
+
large: { padding: "$large" },
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
<Button variant="primary" size="small" />
|
|
62
125
|
```
|
|
63
126
|
|
|
64
|
-
##
|
|
127
|
+
## Migration from Stitches
|
|
128
|
+
|
|
129
|
+
Stoop provides a similar API for the features it implements. Key differences:
|
|
130
|
+
- CSS variables for theme tokens
|
|
131
|
+
- Simple theme system with `createTheme()`
|
|
132
|
+
- Full TypeScript inference
|
|
133
|
+
|
|
134
|
+
See [GUIDE.md](./docs/GUIDE.md) for migration examples.
|
|
135
|
+
|
|
136
|
+
## Related Projects
|
|
65
137
|
|
|
66
|
-
|
|
138
|
+
**CSS-in-JS Libraries:**
|
|
139
|
+
- [Stitches](https://stitches.dev) - Original library Stoop is based on (no longer maintained)
|
|
140
|
+
- [Stitches](https://stitches.dev) - CSS-in-JS library (original inspiration)
|
|
141
|
+
- [Vanilla Extract](https://vanilla-extract.style) - Zero-runtime CSS-in-JS
|
|
142
|
+
- [styled-components](https://styled-components.com) - CSS-in-JS library
|
|
143
|
+
- [Emotion](https://emotion.sh) - CSS-in-JS library
|
|
144
|
+
- [Goober](https://goober.rocks) - Lightweight CSS-in-JS library
|
|
145
|
+
- [JSS](https://cssinjs.org) - Framework-agnostic CSS-in-JS
|
|
146
|
+
- [Compiled](https://compiledcssinjs.com) - Compile-time CSS-in-JS
|
|
147
|
+
- [Stylex](https://stylexjs.com) - Facebook's build-time CSS-in-JS
|
|
148
|
+
- [Panda CSS](https://panda-css.com) - CSS-in-JS with build-time generation
|
|
149
|
+
- [Linaria](https://linaria.dev) - Zero-runtime CSS-in-JS
|
|
150
|
+
- [Treat](https://seek-oss.github.io/treat) - Themeable CSS-in-JS
|
|
151
|
+
|
|
152
|
+
**Variant Systems:**
|
|
153
|
+
- [CVA](https://cva.style) - Class Variance Authority for component variants
|
|
154
|
+
- [clsx](https://github.com/lukeed/clsx) - Tiny utility for constructing className strings
|
|
155
|
+
|
|
156
|
+
**Utility-First:**
|
|
157
|
+
- [Tailwind CSS](https://tailwindcss.com) - Utility-first CSS framework
|
|
158
|
+
- [UnoCSS](https://unocss.dev) - Instant atomic CSS engine
|
|
159
|
+
|
|
160
|
+
**Component Libraries:**
|
|
161
|
+
- [Radix UI](https://www.radix-ui.com) - Unstyled, accessible component primitives
|
|
162
|
+
- [Chakra UI](https://chakra-ui.com) - Component library built on Emotion
|
|
163
|
+
- [Mantine](https://mantine.dev) - React components library with Emotion
|
|
164
|
+
|
|
165
|
+
## Development
|
|
67
166
|
|
|
68
167
|
```sh
|
|
69
|
-
# Install dependencies
|
|
70
168
|
bun install
|
|
71
|
-
|
|
72
|
-
# Start development server
|
|
73
169
|
bun run dev
|
|
74
|
-
|
|
75
|
-
# Build the library
|
|
76
170
|
bun run build
|
|
77
|
-
|
|
78
|
-
# Lint and format
|
|
79
171
|
bun run lint
|
|
80
|
-
bun run prettier
|
|
81
172
|
```
|
|
82
173
|
|
|
83
174
|
## Contributing
|
|
84
175
|
|
|
85
|
-
|
|
176
|
+
Contributions welcome. See [ARCHITECTURE.md](./docs/ARCHITECTURE.md) for implementation details.
|
|
86
177
|
|
|
87
178
|
## License
|
|
88
179
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme extension API.
|
|
3
|
+
* Creates a function that deep merges theme overrides with a base theme.
|
|
4
|
+
*/
|
|
5
|
+
import type { Theme } from "../types";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a function that extends a base theme with overrides.
|
|
8
|
+
* The returned function deep merges theme overrides with the base theme.
|
|
9
|
+
*
|
|
10
|
+
* @param baseTheme - Base theme to extend
|
|
11
|
+
* @returns Function that accepts theme overrides and returns a merged theme
|
|
12
|
+
*/
|
|
13
|
+
export declare function createTheme(baseTheme: Theme): (themeOverrides: Partial<Theme>) => Theme;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS class generation API.
|
|
3
|
+
* Creates a function that compiles CSS objects into class names.
|
|
4
|
+
*/
|
|
5
|
+
import type { CSS, Theme, ThemeScale, UtilityFunction } from "../types";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a CSS function that compiles CSS objects into class names.
|
|
8
|
+
*
|
|
9
|
+
* @param defaultTheme - Default theme for token resolution
|
|
10
|
+
* @param prefix - Optional prefix for generated class names
|
|
11
|
+
* @param media - Optional media query breakpoints
|
|
12
|
+
* @param utils - Optional utility functions
|
|
13
|
+
* @param themeMap - Optional theme scale mappings
|
|
14
|
+
* @returns Function that accepts CSS objects and returns class names
|
|
15
|
+
*/
|
|
16
|
+
export declare function createCSSFunction(defaultTheme: Theme, prefix?: string, media?: Record<string, string>, utils?: Record<string, UtilityFunction>, themeMap?: Record<string, ThemeScale>): (styles: CSS) => string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global CSS injection API.
|
|
3
|
+
* Creates a function that injects global styles into the document.
|
|
4
|
+
* Supports media queries, nested selectors, and theme tokens.
|
|
5
|
+
*/
|
|
6
|
+
import type { CSS, Theme, ThemeScale, UtilityFunction } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a global CSS injection function.
|
|
9
|
+
* Injects styles directly into the document with deduplication support.
|
|
10
|
+
*
|
|
11
|
+
* @param defaultTheme - Default theme for token resolution
|
|
12
|
+
* @param prefix - Optional prefix for CSS rules
|
|
13
|
+
* @param media - Optional media query breakpoints
|
|
14
|
+
* @param utils - Optional utility functions
|
|
15
|
+
* @param themeMap - Optional theme scale mappings
|
|
16
|
+
* @returns Function that accepts CSS objects and returns a cleanup function
|
|
17
|
+
*/
|
|
18
|
+
export declare function createGlobalCSSFunction(defaultTheme: Theme, prefix?: string, media?: Record<string, string>, utils?: Record<string, UtilityFunction>, themeMap?: Record<string, ThemeScale>): (styles: CSS) => () => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS keyframes animation API.
|
|
3
|
+
* Creates a function that generates and injects @keyframes rules.
|
|
4
|
+
* Caches animations by content hash to prevent duplicates.
|
|
5
|
+
*/
|
|
6
|
+
import type { CSS, Theme, ThemeScale } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a keyframes animation function.
|
|
9
|
+
* Generates and injects @keyframes rules with caching to prevent duplicates.
|
|
10
|
+
*
|
|
11
|
+
* @param prefix - Optional prefix for animation names
|
|
12
|
+
* @param theme - Optional theme for token resolution
|
|
13
|
+
* @param themeMap - Optional theme scale mappings
|
|
14
|
+
* @returns Function that accepts keyframes objects and returns animation names
|
|
15
|
+
*/
|
|
16
|
+
export declare function createKeyframesFunction(prefix?: string, theme?: Theme, themeMap?: Record<string, ThemeScale>): (keyframes: Record<string, CSS>) => string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme Provider component.
|
|
3
|
+
* Manages theme state, localStorage persistence, and centralized theme variable updates.
|
|
4
|
+
*/
|
|
5
|
+
import { type ComponentType, type Context } from "react";
|
|
6
|
+
import type { ProviderProps, Theme, ThemeContextValue, ThemeManagementContextValue } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a Provider component for theme management.
|
|
9
|
+
*
|
|
10
|
+
* @param ThemeContext - Stoop's theme context for styled components
|
|
11
|
+
* @param themes - Map of theme names to theme objects
|
|
12
|
+
* @param defaultTheme - Default theme object
|
|
13
|
+
* @param prefix - Optional prefix for CSS variable scoping
|
|
14
|
+
* @returns Provider component and theme management context
|
|
15
|
+
*/
|
|
16
|
+
export declare function createProvider(ThemeContext: Context<ThemeContextValue | null>, themes: Record<string, Theme>, defaultTheme: Theme, prefix?: string): {
|
|
17
|
+
Provider: ComponentType<ProviderProps>;
|
|
18
|
+
ThemeManagementContext: Context<ThemeManagementContextValue | null>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Styled component API.
|
|
3
|
+
* Creates polymorphic styled components with variant support, theme awareness,
|
|
4
|
+
* and CSS prop merging. Supports component targeting via selector references.
|
|
5
|
+
*/
|
|
6
|
+
import { forwardRef, type Context } from "react";
|
|
7
|
+
import type { CSS, StyledComponentProps, StyledComponentRef, StylableElement, Theme, ThemeContextValue, ThemeScale, UtilityFunction, Variants } from "../types";
|
|
8
|
+
/**
|
|
9
|
+
* Creates a styled component reference for selector targeting.
|
|
10
|
+
*
|
|
11
|
+
* @param className - Class name to reference
|
|
12
|
+
* @returns StyledComponentRef for use in CSS selectors
|
|
13
|
+
*/
|
|
14
|
+
export declare function createStyledComponentRef(className: string): StyledComponentRef;
|
|
15
|
+
type CSSWithVariants = {
|
|
16
|
+
[K in keyof CSS]: CSS[K];
|
|
17
|
+
} & {
|
|
18
|
+
variants: Variants;
|
|
19
|
+
compoundVariants?: unknown[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Creates a styled component factory function.
|
|
23
|
+
* Supports polymorphic components, variants, theme awareness, and CSS prop merging.
|
|
24
|
+
*
|
|
25
|
+
* @param defaultTheme - Default theme for token resolution
|
|
26
|
+
* @param prefix - Optional prefix for generated class names
|
|
27
|
+
* @param media - Optional media query breakpoints
|
|
28
|
+
* @param utils - Optional utility functions
|
|
29
|
+
* @param themeMap - Optional theme scale mappings
|
|
30
|
+
* @param themeContext - React context for theme values (instance-specific)
|
|
31
|
+
* @returns Styled component factory function
|
|
32
|
+
*/
|
|
33
|
+
export declare function createStyledFunction(defaultTheme: Theme, prefix?: string, media?: Record<string, string>, utils?: Record<string, UtilityFunction>, themeMap?: Record<string, ThemeScale>, themeContext?: Context<ThemeContextValue | null>): {
|
|
34
|
+
<DefaultElement extends StylableElement, BaseStyles extends CSSWithVariants>(defaultElement: DefaultElement, baseStyles: BaseStyles): ReturnType<typeof forwardRef<unknown, StyledComponentProps<DefaultElement, BaseStyles["variants"]>>> & {
|
|
35
|
+
selector: StyledComponentRef;
|
|
36
|
+
};
|
|
37
|
+
<DefaultElement extends StylableElement, VariantsConfig extends Variants = {}>(defaultElement: DefaultElement, baseStyles?: CSS, variants?: VariantsConfig): ReturnType<typeof forwardRef<unknown, StyledComponentProps<DefaultElement, VariantsConfig>>> & {
|
|
38
|
+
selector: StyledComponentRef;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme management hook.
|
|
3
|
+
* Provides access to theme state and theme switching functions.
|
|
4
|
+
*/
|
|
5
|
+
import { type Context } from "react";
|
|
6
|
+
import type { ThemeManagementContextValue } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a useTheme hook for a specific theme management context.
|
|
9
|
+
*
|
|
10
|
+
* @param ThemeManagementContext - React context for theme management
|
|
11
|
+
* @returns Hook function that returns theme management context value
|
|
12
|
+
*/
|
|
13
|
+
export declare function createUseThemeHook(ThemeManagementContext: Context<ThemeManagementContextValue | null>): () => ThemeManagementContextValue;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared constants used throughout the library.
|
|
3
|
+
* Includes cache size limits, nesting depth limits, and fallback context.
|
|
4
|
+
*/
|
|
5
|
+
import type { CSS, ThemeContextValue, ThemeScale } from "./types";
|
|
6
|
+
export declare const EMPTY_CSS: CSS;
|
|
7
|
+
export declare const MAX_CSS_CACHE_SIZE = 10000;
|
|
8
|
+
export declare const MAX_CLASS_NAME_CACHE_SIZE = 5000;
|
|
9
|
+
export declare const MAX_CSS_NESTING_DEPTH = 10;
|
|
10
|
+
export declare const FALLBACK_CONTEXT: import("react").Context<ThemeContextValue>;
|
|
11
|
+
/**
|
|
12
|
+
* Approved theme scales - only these scales are allowed in theme objects.
|
|
13
|
+
*/
|
|
14
|
+
export declare const APPROVED_THEME_SCALES: ReadonlyArray<ThemeScale>;
|
|
15
|
+
/**
|
|
16
|
+
* Default themeMap mapping CSS properties to theme scales.
|
|
17
|
+
* Covers 150+ common CSS properties for zero-config experience.
|
|
18
|
+
* Missing properties gracefully fallback to pattern-based auto-detection.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_THEME_MAP: Record<string, ThemeScale>;
|
|
21
|
+
export declare const STOOP_COMPONENT_SYMBOL: unique symbol;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS compilation caching system.
|
|
3
|
+
* Tracks compiled CSS strings and class names to prevent duplicate work.
|
|
4
|
+
* Implements LRU (Least Recently Used) eviction when cache size limits are exceeded.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* LRU Cache implementation for class names and CSS strings.
|
|
8
|
+
* Automatically evicts least recently used entries when size limit is exceeded.
|
|
9
|
+
*/
|
|
10
|
+
declare class LRUCache<K, V> extends Map<K, V> {
|
|
11
|
+
private readonly maxSize;
|
|
12
|
+
constructor(maxSize: number);
|
|
13
|
+
get(key: K): V | undefined;
|
|
14
|
+
set(key: K, value: V): this;
|
|
15
|
+
}
|
|
16
|
+
export declare const classNameCache: LRUCache<string, string>;
|
|
17
|
+
export declare const cssStringCache: LRUCache<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if a CSS string is cached.
|
|
20
|
+
*
|
|
21
|
+
* @param css - CSS string to check
|
|
22
|
+
* @returns True if CSS is cached
|
|
23
|
+
*/
|
|
24
|
+
export declare function isCachedStyle(css: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Marks a CSS string as cached.
|
|
27
|
+
*
|
|
28
|
+
* @param css - CSS string to cache
|
|
29
|
+
*/
|
|
30
|
+
export declare function markStyleAsCached(css: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Limits cache size by evicting least recently used entries.
|
|
33
|
+
*/
|
|
34
|
+
export declare function limitCacheSize(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Clears all cached styles.
|
|
37
|
+
*/
|
|
38
|
+
export declare function clearStyleCache(): void;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
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 type { CSS, Theme, ThemeScale, UtilityFunction } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Compiles CSS objects into CSS strings and generates unique class names.
|
|
9
|
+
* Handles nested selectors, media queries, styled component targeting, and theme tokens.
|
|
10
|
+
*
|
|
11
|
+
* @param styles - CSS object to compile
|
|
12
|
+
* @param currentTheme - Theme for token resolution
|
|
13
|
+
* @param prefix - Optional prefix for generated class names
|
|
14
|
+
* @param media - Optional media query breakpoints
|
|
15
|
+
* @param utils - Optional utility functions
|
|
16
|
+
* @param themeMap - Optional theme scale mappings
|
|
17
|
+
* @returns Generated class name
|
|
18
|
+
*/
|
|
19
|
+
export declare function compileCSS(styles: CSS, currentTheme: Theme, prefix?: string, media?: Record<string, string>, utils?: Record<string, UtilityFunction>, themeMap?: Record<string, ThemeScale>): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 type { Theme } from "../types";
|
|
8
|
+
/**
|
|
9
|
+
* Registers the default theme for a given prefix.
|
|
10
|
+
* Called automatically by createStoop.
|
|
11
|
+
*
|
|
12
|
+
* @param theme - Default theme from createStoop
|
|
13
|
+
* @param prefix - Optional prefix for theme scoping
|
|
14
|
+
*/
|
|
15
|
+
export declare function registerDefaultTheme(theme: Theme, prefix?: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the default theme for a given prefix.
|
|
18
|
+
*
|
|
19
|
+
* @param prefix - Optional prefix for theme scoping
|
|
20
|
+
* @returns Default theme or null if not registered
|
|
21
|
+
*/
|
|
22
|
+
export declare function getDefaultTheme(prefix?: string): Theme | null;
|
|
23
|
+
/**
|
|
24
|
+
* Updates CSS custom properties when theme changes.
|
|
25
|
+
* Automatically merges the theme with the default theme to ensure all properties are present.
|
|
26
|
+
*
|
|
27
|
+
* @param theme - Theme object to generate CSS variables from
|
|
28
|
+
* @param prefix - Optional prefix for CSS variable names
|
|
29
|
+
*/
|
|
30
|
+
export declare function updateThemeVariables(theme: Theme, prefix?: string): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
import type { CSS, Variants, VariantProps } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Applies variant styles to base styles based on component props.
|
|
9
|
+
*
|
|
10
|
+
* @param variants - Variant configuration object
|
|
11
|
+
* @param props - Component props containing variant values
|
|
12
|
+
* @param baseStyles - Base styles to merge with variant styles
|
|
13
|
+
* @returns Merged CSS object
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyVariants(variants: Variants, props: VariantProps, baseStyles: CSS): CSS;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main factory function that creates a Stoop instance.
|
|
3
|
+
* Configures theme, media queries, utilities, and returns all API functions.
|
|
4
|
+
*/
|
|
5
|
+
import type { StoopConfig, StoopInstance } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Stoop instance with the provided configuration.
|
|
8
|
+
*
|
|
9
|
+
* @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.)
|
|
11
|
+
*/
|
|
12
|
+
export declare function createStoop(config: StoopConfig): StoopInstance;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
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";
|