styled-components 6.4.0-prerelease.1 → 6.4.0-prerelease.11

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 (91) hide show
  1. package/README.md +225 -47
  2. package/dist/base.d.ts +2 -1
  3. package/dist/constants.d.ts +1 -0
  4. package/dist/constructors/createGlobalStyle.d.ts +10 -0
  5. package/dist/constructors/createTheme.d.ts +108 -0
  6. package/dist/constructors/css.d.ts +12 -0
  7. package/dist/constructors/keyframes.d.ts +11 -0
  8. package/dist/constructors/styled.d.ts +8 -0
  9. package/dist/hoc/withTheme.d.ts +1 -0
  10. package/dist/index.d.ts +1 -0
  11. package/dist/models/ComponentStyle.d.ts +7 -6
  12. package/dist/models/GlobalStyle.d.ts +13 -1
  13. package/dist/models/InlineStyle.d.ts +11 -0
  14. package/dist/models/StyleSheetManager.d.ts +12 -2
  15. package/dist/native/index.d.ts +18 -2
  16. package/dist/sheet/Sheet.d.ts +2 -0
  17. package/dist/styled-components.browser.cjs.js +5 -1
  18. package/dist/styled-components.browser.cjs.js.map +1 -1
  19. package/dist/styled-components.browser.esm.js +5 -1
  20. package/dist/styled-components.browser.esm.js.map +1 -1
  21. package/dist/styled-components.cjs.js +5 -1
  22. package/dist/styled-components.cjs.js.map +1 -1
  23. package/dist/styled-components.esm.js +5 -1
  24. package/dist/styled-components.esm.js.map +1 -1
  25. package/dist/styled-components.js +1046 -1086
  26. package/dist/styled-components.js.map +1 -1
  27. package/dist/styled-components.min.js +5 -1
  28. package/dist/styled-components.min.js.map +1 -1
  29. package/dist/utils/cssTagged.d.ts +2 -0
  30. package/dist/utils/escape.d.ts +0 -4
  31. package/dist/utils/hash.d.ts +1 -0
  32. package/dist/utils/hoist.d.ts +0 -4
  33. package/dist/utils/isStyledComponent.d.ts +1 -0
  34. package/dist/utils/joinStrings.d.ts +3 -0
  35. package/dist/utils/rscCache.d.ts +2 -0
  36. package/dist/utils/stylisPluginRSC.d.ts +3 -0
  37. package/native/dist/base.d.ts +2 -1
  38. package/native/dist/constants.d.ts +1 -0
  39. package/native/dist/constructors/createGlobalStyle.d.ts +10 -0
  40. package/native/dist/constructors/createTheme.d.ts +108 -0
  41. package/native/dist/constructors/css.d.ts +12 -0
  42. package/native/dist/constructors/keyframes.d.ts +11 -0
  43. package/native/dist/constructors/styled.d.ts +8 -0
  44. package/native/dist/dist/base.d.ts +2 -1
  45. package/native/dist/dist/constants.d.ts +1 -0
  46. package/native/dist/dist/constructors/createGlobalStyle.d.ts +10 -0
  47. package/native/dist/dist/constructors/createTheme.d.ts +108 -0
  48. package/native/dist/dist/constructors/css.d.ts +12 -0
  49. package/native/dist/dist/constructors/keyframes.d.ts +11 -0
  50. package/native/dist/dist/constructors/styled.d.ts +8 -0
  51. package/native/dist/dist/hoc/withTheme.d.ts +1 -0
  52. package/native/dist/dist/index.d.ts +1 -0
  53. package/native/dist/dist/models/ComponentStyle.d.ts +7 -6
  54. package/native/dist/dist/models/GlobalStyle.d.ts +13 -1
  55. package/native/dist/dist/models/InlineStyle.d.ts +11 -0
  56. package/native/dist/dist/models/StyleSheetManager.d.ts +12 -2
  57. package/native/dist/dist/native/index.d.ts +18 -2
  58. package/native/dist/dist/sheet/Sheet.d.ts +2 -0
  59. package/native/dist/dist/utils/cssTagged.d.ts +2 -0
  60. package/native/dist/dist/utils/escape.d.ts +0 -4
  61. package/native/dist/dist/utils/hash.d.ts +1 -0
  62. package/native/dist/dist/utils/hoist.d.ts +0 -4
  63. package/native/dist/dist/utils/isStyledComponent.d.ts +1 -0
  64. package/native/dist/dist/utils/joinStrings.d.ts +3 -0
  65. package/native/dist/dist/utils/rscCache.d.ts +2 -0
  66. package/native/dist/dist/utils/stylisPluginNthChildFix.d.ts +3 -0
  67. package/native/dist/dist/utils/stylisPluginRSC.d.ts +3 -0
  68. package/native/dist/hoc/withTheme.d.ts +1 -0
  69. package/native/dist/index.d.ts +1 -0
  70. package/native/dist/models/ComponentStyle.d.ts +7 -6
  71. package/native/dist/models/GlobalStyle.d.ts +13 -1
  72. package/native/dist/models/InlineStyle.d.ts +11 -0
  73. package/native/dist/models/StyleSheetManager.d.ts +12 -2
  74. package/native/dist/native/index.d.ts +18 -2
  75. package/native/dist/sheet/Sheet.d.ts +2 -0
  76. package/native/dist/sheet/Tag.d.ts +4 -4
  77. package/native/dist/styled-components.native.cjs.js +1 -1
  78. package/native/dist/styled-components.native.cjs.js.map +1 -1
  79. package/native/dist/styled-components.native.esm.js +1 -1
  80. package/native/dist/styled-components.native.esm.js.map +1 -1
  81. package/native/dist/utils/cssTagged.d.ts +2 -0
  82. package/native/dist/utils/escape.d.ts +0 -4
  83. package/native/dist/utils/hash.d.ts +1 -0
  84. package/native/dist/utils/hoist.d.ts +0 -4
  85. package/native/dist/utils/isStyledComponent.d.ts +1 -0
  86. package/native/dist/utils/joinStrings.d.ts +3 -0
  87. package/native/dist/utils/rscCache.d.ts +2 -0
  88. package/native/dist/utils/stylisPluginNthChildFix.d.ts +3 -0
  89. package/native/dist/utils/stylisPluginRSC.d.ts +3 -0
  90. package/native/package.json +7 -2
  91. package/package.json +17 -21
package/README.md CHANGED
@@ -7,7 +7,9 @@
7
7
  <br />
8
8
 
9
9
  <div align="center">
10
- <strong>Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅</strong>
10
+ <strong>Fast, expressive styling for React.</strong>
11
+ <br />
12
+ Server components, client components, streaming SSR, React Native—one API.
11
13
  <br />
12
14
  <br />
13
15
  <a href="https://www.npmjs.com/package/styled-components"><img src="https://img.shields.io/npm/dm/styled-components.svg" alt="npm downloads"></a>
@@ -16,19 +18,26 @@
16
18
 
17
19
  ---
18
20
 
19
- `styled-components` lets you write actual CSS in your JavaScript using tagged template literals. It removes the mapping between components and styles, making components the styling primitive.
21
+ styled-components is largely maintained by one person. Please help fund the project for consistent long-term support and updates: [Open Collective](https://opencollective.com/styled-components)
22
+
23
+ ---
20
24
 
21
- - Built-in TypeScript types (no `@types` package needed)
22
- - React Server Components (RSC) support via automatic runtime detection
23
- - React Native support
24
- - Compatible with React 16.8+, including React 19
25
+ Style React components with real CSS, scoped automatically and delivered only when needed. No class name juggling, no separate files, no build step required.
25
26
 
26
- ## Installation
27
+ - **Works everywhere React runs.** Server components, client components, streaming SSR, and React Native—same API, automatic runtime detection.
28
+ - **Full CSS, no compromises.** Media queries, pseudo-selectors, nesting, keyframes, global styles. If CSS supports it, so does styled-components.
29
+ - **TypeScript-first.** Built-in types ship with the package. Props flow through to your styles with full inference—no `@types` install, no manual generics.
30
+ - **<13kB gzipped.** Small enough to disappear in your bundle. No build plugin required.
31
+
32
+ ## Install
27
33
 
28
34
  ```sh
29
35
  npm install styled-components
30
36
  ```
31
37
 
38
+ <details>
39
+ <summary>pnpm / yarn</summary>
40
+
32
41
  ```sh
33
42
  pnpm add styled-components
34
43
  ```
@@ -37,55 +46,228 @@ pnpm add styled-components
37
46
  yarn add styled-components
38
47
  ```
39
48
 
40
- ## Example
49
+ </details>
41
50
 
42
- ```jsx
51
+ ## Quick examples
52
+
53
+ ### Dynamic props
54
+
55
+ Vary styles based on component props. Prefix transient props with `$` to keep them off the DOM.
56
+
57
+ ```tsx
43
58
  import styled from 'styled-components';
44
59
 
45
- const Title = styled.h1`
46
- font-size: 1.5em;
47
- text-align: center;
48
- color: palevioletred;
60
+ const Button = styled.button<{ $primary?: boolean }>`
61
+ background: ${props => (props.$primary ? 'palevioletred' : 'white')};
62
+ color: ${props => (props.$primary ? 'white' : 'palevioletred')};
63
+ font-size: 1em;
64
+ padding: 0.25em 1em;
65
+ border: 2px solid palevioletred;
66
+ border-radius: 3px;
67
+ `;
68
+
69
+ <Button>Normal</Button>
70
+ <Button $primary>Primary</Button>
71
+ ```
72
+
73
+ ### Extending styles
74
+
75
+ Build variants on top of existing styled components.
76
+
77
+ ```tsx
78
+ const TomatoButton = styled(Button)`
79
+ background: tomato;
80
+ color: white;
81
+ border-color: tomato;
49
82
  `;
83
+ ```
84
+
85
+ ### Polymorphic `as` prop
86
+
87
+ Swap the rendered element without changing styles.
88
+
89
+ ```tsx
90
+ // Renders a <a> tag with Button styles
91
+ <Button as="a" href="/home">Link Button</Button>
92
+ ```
93
+
94
+ ### Pseudos and nesting
95
+
96
+ Use `&` to reference the component's generated class name—works with pseudo-classes, pseudo-elements, and nested selectors.
97
+
98
+ ```tsx
99
+ const Input = styled.input`
100
+ border: 1px solid #ccc;
101
+ border-radius: 4px;
102
+ padding: 0.5em;
103
+
104
+ &:focus {
105
+ border-color: palevioletred;
106
+ outline: none;
107
+ }
108
+
109
+ &::placeholder {
110
+ color: #aaa;
111
+ }
112
+ `;
113
+ ```
114
+
115
+ ### Animations
116
+
117
+ Define `@keyframes` once, reference them across components. Names are scoped automatically.
118
+
119
+ ```tsx
120
+ import styled, { keyframes } from 'styled-components';
121
+
122
+ const rotate = keyframes`
123
+ from { transform: rotate(0deg); }
124
+ to { transform: rotate(360deg); }
125
+ `;
126
+
127
+ const Spinner = styled.div`
128
+ animation: ${rotate} 1s linear infinite;
129
+ width: 40px;
130
+ height: 40px;
131
+ border: 3px solid palevioletred;
132
+ border-top-color: transparent;
133
+ border-radius: 50%;
134
+ `;
135
+ ```
136
+
137
+ ### Theming
138
+
139
+ Share design tokens across your app via React context. Every styled component receives `props.theme`.
140
+
141
+ ```tsx
142
+ import styled, { ThemeProvider } from 'styled-components';
143
+
144
+ const theme = {
145
+ fg: 'palevioletred',
146
+ bg: 'white',
147
+ };
50
148
 
51
- const Wrapper = styled.section`
52
- padding: 4em;
53
- background: papayawhip;
149
+ const Card = styled.div`
150
+ background: ${props => props.theme.bg};
151
+ color: ${props => props.theme.fg};
152
+ padding: 2em;
54
153
  `;
55
154
 
56
- function MyUI() {
57
- return (
58
- <Wrapper>
59
- <Title>Hello World, this is my first styled component!</Title>
60
- </Wrapper>
61
- );
62
- }
155
+ <ThemeProvider theme={theme}>
156
+ <Card>Themed content</Card>
157
+ </ThemeProvider>
63
158
  ```
64
159
 
65
- Style objects are also supported:
160
+ ### RSC-compatible themes
66
161
 
67
- ```jsx
68
- const Button = styled.button({
69
- color: 'grey',
162
+ `createTheme` turns your tokens into CSS custom properties. Class name hashes stay stable across theme variants—no hydration mismatch when switching light/dark.
163
+
164
+ ```tsx
165
+ import styled, { createTheme, ThemeProvider } from 'styled-components';
166
+
167
+ const { theme, GlobalStyle: ThemeVars } = createTheme({
168
+ colors: {
169
+ fg: 'palevioletred',
170
+ bg: 'white',
171
+ },
172
+ space: {
173
+ md: '1rem',
174
+ },
70
175
  });
176
+
177
+ const Card = styled.div`
178
+ color: ${theme.colors.fg}; /* var(--sc-colors-fg, palevioletred) */
179
+ background: ${theme.colors.bg};
180
+ padding: ${theme.space.md};
181
+ `;
182
+
183
+ // Render <ThemeVars /> at the root to emit the CSS variable declarations
184
+ // Pass the theme to ThemeProvider for stable hashes
185
+ <ThemeProvider theme={theme}>
186
+ <ThemeVars />
187
+ <Card>Token-driven content</Card>
188
+ </ThemeProvider>
189
+ ```
190
+
191
+ ### Shared styles with `css`
192
+
193
+ Extract reusable style blocks to share across components or apply conditionally.
194
+
195
+ ```tsx
196
+ import styled, { css } from 'styled-components';
197
+
198
+ const truncate = css`
199
+ white-space: nowrap;
200
+ overflow: hidden;
201
+ text-overflow: ellipsis;
202
+ `;
203
+
204
+ const Label = styled.span`
205
+ ${truncate}
206
+ max-width: 200px;
207
+ `;
208
+ ```
209
+
210
+ ### Styling third-party components
211
+
212
+ Wrap any component that accepts a `className` prop.
213
+
214
+ ```tsx
215
+ import styled from 'styled-components';
216
+ import { Link } from 'react-router-dom';
217
+
218
+ const StyledLink = styled(Link)`
219
+ color: palevioletred;
220
+ text-decoration: none;
221
+
222
+ &:hover {
223
+ text-decoration: underline;
224
+ }
225
+ `;
71
226
  ```
72
227
 
73
- ## [Docs](https://www.styled-components.com/docs)
228
+ ### Global styles
229
+
230
+ Inject app-wide CSS like resets and font faces. Supports theming and dynamic updates.
231
+
232
+ ```tsx
233
+ import { createGlobalStyle } from 'styled-components';
74
234
 
75
- See the documentation at [styled-components.com/docs](https://www.styled-components.com/docs) for full usage information.
235
+ const GlobalStyle = createGlobalStyle`
236
+ body {
237
+ margin: 0;
238
+ font-family: system-ui, sans-serif;
239
+ }
240
+ `;
241
+
242
+ // Render <GlobalStyle /> at the root of your app
243
+ ```
76
244
 
77
- - [Getting started](https://www.styled-components.com/docs/basics)
78
- - [API Reference](https://styled-components.com/docs/api)
79
- - [Theming](https://www.styled-components.com/docs/advanced#theming)
80
- - [Server-side rendering](https://www.styled-components.com/docs/advanced#server-side-rendering)
81
- - [React Server Components](https://www.styled-components.com/docs/advanced#react-server-components)
82
- - [React Native](https://www.styled-components.com/docs/basics#react-native)
245
+ ### Attrs
83
246
 
84
- ## Contributing
247
+ Set default or static HTML attributes so consumers don't have to.
85
248
 
86
- See our [contributing and community guidelines](./CONTRIBUTING.md) and [Code of Conduct](./CODE_OF_CONDUCT.md).
249
+ ```tsx
250
+ const PasswordInput = styled.input.attrs({
251
+ type: 'password',
252
+ placeholder: 'Enter password',
253
+ })`
254
+ border: 1px solid #ccc;
255
+ padding: 0.5em;
256
+ `;
257
+ ```
87
258
 
88
- Check out [awesome-styled-components](https://github.com/styled-components/awesome-styled-components) for community libraries, projects, and examples.
259
+ ## Documentation
260
+
261
+ - [Getting started](https://styled-components.com/docs/basics)
262
+ - [API reference](https://styled-components.com/docs/api)
263
+ - [Server-side rendering](https://styled-components.com/docs/advanced#server-side-rendering)
264
+ - [React Server Components](https://styled-components.com/docs/advanced#react-server-components)
265
+ - [Theming](https://styled-components.com/docs/advanced#theming)
266
+ - [React Native](https://styled-components.com/docs/basics#react-native)
267
+
268
+ ## Community
269
+
270
+ [Contributing guidelines](./CONTRIBUTING.md) | [Code of Conduct](./CODE_OF_CONDUCT.md) | [awesome-styled-components](https://github.com/styled-components/awesome-styled-components)
89
271
 
90
272
  ## Contributors
91
273
 
@@ -95,7 +277,7 @@ This project exists thanks to all the people who contribute.
95
277
 
96
278
  ## Backers
97
279
 
98
- Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/styled-components#backer)]
280
+ Thank you to all our backers! [[Become a backer](https://opencollective.com/styled-components#backer)]
99
281
 
100
282
  <a href="https://opencollective.com/styled-components#backers" target="_blank"><img src="https://opencollective.com/styled-components/backers.svg?width=890"></a>
101
283
 
@@ -105,14 +287,10 @@ Support this project by becoming a sponsor. [[Become a sponsor](https://opencoll
105
287
 
106
288
  <a href="https://opencollective.com/styled-components#sponsors" target="_blank"><img src="https://opencollective.com/styled-components/sponsors.svg?width=890"></a>
107
289
 
108
- ## License
109
-
110
- Licensed under the MIT License, Copyright © 2016-present styled-components contributors.
111
-
112
- See [LICENSE](./LICENSE) for more information.
113
-
114
290
  ## Acknowledgements
115
291
 
116
- This project builds on a long line of earlier work by clever folks all around the world. We'd like to thank Charlie Somerville, Nik Graf, Sunil Pai, Michael Chan, Andrey Popp, Jed Watson & Andrey Sitnik who contributed ideas, code or inspiration.
292
+ This project builds on earlier work by Charlie Somerville, Nik Graf, Sunil Pai, Michael Chan, Andrey Popp, Jed Watson, and Andrey Sitnik. Special thanks to [@okonet](https://github.com/okonet) for the logo.
293
+
294
+ ## License
117
295
 
118
- Special thanks to [@okonet](https://github.com/okonet) for the fantastic logo.
296
+ Licensed under the MIT License, Copyright © 2016-present styled-components contributors. See [LICENSE](./LICENSE) for details.
package/dist/base.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { SC_VERSION } from './constants';
2
2
  import createGlobalStyle from './constructors/createGlobalStyle';
3
+ import createTheme from './constructors/createTheme';
3
4
  import css from './constructors/css';
4
5
  import keyframes from './constructors/keyframes';
5
6
  import withTheme from './hoc/withTheme';
@@ -9,4 +10,4 @@ import ThemeProvider, { ThemeConsumer, ThemeContext, useTheme } from './models/T
9
10
  import isStyledComponent from './utils/isStyledComponent';
10
11
  export * from './secretInternals';
11
12
  export { Attrs, DefaultTheme, Keyframes, ShouldForwardProp } from './types';
12
- export { IStyleSheetContext, IStyleSheetManager, IStylisContext, ServerStyleSheet, StyleSheetConsumer, StyleSheetContext, StyleSheetManager, ThemeConsumer, ThemeContext, ThemeProvider, createGlobalStyle, css, isStyledComponent, keyframes, useTheme, SC_VERSION as version, withTheme, };
13
+ export { IStyleSheetContext, IStyleSheetManager, IStylisContext, ServerStyleSheet, StyleSheetConsumer, StyleSheetContext, StyleSheetManager, ThemeConsumer, ThemeContext, ThemeProvider, createGlobalStyle, createTheme, css, isStyledComponent, keyframes, useTheme, SC_VERSION as version, withTheme, };
@@ -13,4 +13,5 @@ export declare const IS_BROWSER: boolean;
13
13
  */
14
14
  export declare const IS_RSC: boolean;
15
15
  export declare const DISABLE_SPEEDY: boolean;
16
+ export declare const KEYFRAMES_ID_PREFIX = "sc-keyframes-";
16
17
  export declare const STATIC_EXECUTION_CONTEXT: {};
@@ -1,3 +1,13 @@
1
1
  import React from 'react';
2
2
  import { ExecutionProps, Interpolation, Styles } from '../types';
3
+ /**
4
+ * Create a component that injects global CSS when mounted. Supports theming and dynamic props.
5
+ *
6
+ * ```tsx
7
+ * const GlobalStyle = createGlobalStyle`
8
+ * body { margin: 0; font-family: system-ui; }
9
+ * `;
10
+ * // Render <GlobalStyle /> at the root of your app
11
+ * ```
12
+ */
3
13
  export default function createGlobalStyle<Props extends object>(strings: Styles<Props>, ...interpolations: Array<Interpolation<Props>>): React.NamedExoticComponent<ExecutionProps & Props>;
@@ -0,0 +1,108 @@
1
+ import createGlobalStyle from './createGlobalStyle';
2
+ type ThemeLeaf = string | number;
3
+ /**
4
+ * Recursively maps a theme object so every leaf value becomes
5
+ * a `var(--sc-path, fallback)` CSS string.
6
+ */
7
+ type CSSVarTheme<T> = {
8
+ [K in keyof T]: T[K] extends ThemeLeaf ? string : CSSVarTheme<T[K]>;
9
+ };
10
+ /**
11
+ * The object returned by `createTheme`. Same shape as the input theme but
12
+ * every leaf is a CSS `var()` reference. Also carries a `GlobalStyle`
13
+ * component and the original `raw` theme object.
14
+ */
15
+ type ThemeContract<T> = CSSVarTheme<T> & {
16
+ /**
17
+ * A `createGlobalStyle` component that emits `:root` CSS custom properties
18
+ * from the current ThemeProvider context. Mount this once at the root of
19
+ * your app so RSC components can consume theme values via CSS variables.
20
+ */
21
+ GlobalStyle: ReturnType<typeof createGlobalStyle>;
22
+ /** The original theme object, for passing to `ThemeProvider`. */
23
+ raw: T;
24
+ /**
25
+ * Same shape as the theme but every leaf is the bare CSS custom property
26
+ * name (e.g. `"--sc-colors-primary"`). Useful for building dark mode
27
+ * overrides without hand-writing variable names.
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * const { vars } = createTheme({ colors: { bg: '#fff', text: '#000' } });
32
+ * vars.colors.bg // "--sc-colors-bg"
33
+ *
34
+ * const DarkMode = createGlobalStyle`
35
+ * .dark {
36
+ * ${vars.colors.bg}: #111;
37
+ * ${vars.colors.text}: #eee;
38
+ * }
39
+ * `;
40
+ * ```
41
+ */
42
+ vars: CSSVarTheme<T>;
43
+ /**
44
+ * Read the current resolved CSS variable values from the DOM and return
45
+ * an object with the same shape as the original theme. Each leaf is the
46
+ * computed value (e.g. `"#0070f3"`), not the `var()` reference.
47
+ *
48
+ * Optionally pass a target element to read scoped variables from
49
+ * (defaults to `document.documentElement`).
50
+ *
51
+ * Client-only — throws if called on the server.
52
+ */
53
+ resolve(el?: Element): T;
54
+ };
55
+ interface CreateThemeOptions {
56
+ /**
57
+ * Prefix for CSS variable names. Defaults to `"sc"`.
58
+ * Useful for isolation when multiple design systems or microfrontends
59
+ * coexist on the same page.
60
+ *
61
+ * @example
62
+ * createTheme(theme, { prefix: 'ds' })
63
+ * // → var(--ds-colors-primary, #0070f3)
64
+ */
65
+ prefix?: string;
66
+ /**
67
+ * CSS selector for the variable declarations. Defaults to `":root"`.
68
+ * Use `":host"` for web components / Shadow DOM, or a class selector
69
+ * for scoped theming.
70
+ *
71
+ * @example
72
+ * createTheme(theme, { selector: ':host' })
73
+ * // → :host { --sc-colors-primary: #0070f3; }
74
+ */
75
+ selector?: string;
76
+ }
77
+ /**
78
+ * Create a theme backed by CSS custom properties, bridging `ThemeProvider` and CSS variables.
79
+ *
80
+ * Returns an object with the same shape as the input theme, but every leaf value
81
+ * is a `var(--prefix-*, fallback)` CSS string. Use these in styled component
82
+ * templates — they work in both client and RSC contexts.
83
+ *
84
+ * Mount the returned `GlobalStyle` component inside your `ThemeProvider` to emit
85
+ * the CSS variables. When the theme changes (e.g. light → dark), the variables
86
+ * update automatically.
87
+ *
88
+ * @example
89
+ * ```tsx
90
+ * const theme = createTheme({
91
+ * colors: { primary: '#0070f3', text: '#111' },
92
+ * });
93
+ *
94
+ * // Root layout (client):
95
+ * <ThemeProvider theme={themes[preset]}>
96
+ * <theme.GlobalStyle />
97
+ * {children}
98
+ * </ThemeProvider>
99
+ *
100
+ * // Any RSC file:
101
+ * const Card = styled.div`
102
+ * color: ${theme.colors.primary};
103
+ * // → "var(--sc-colors-primary, #0070f3)"
104
+ * `;
105
+ * ```
106
+ */
107
+ export default function createTheme<T extends Record<string, any>>(defaultTheme: T, options?: CreateThemeOptions): ThemeContract<T>;
108
+ export {};
@@ -1,4 +1,16 @@
1
1
  import { Interpolation, RuleSet, Styles } from '../types';
2
+ /**
3
+ * Tag a CSS template literal for use in styled components, createGlobalStyle, or attrs.
4
+ * Enables interpolation type-checking and shared style blocks.
5
+ *
6
+ * ```tsx
7
+ * const truncate = css`
8
+ * white-space: nowrap;
9
+ * overflow: hidden;
10
+ * text-overflow: ellipsis;
11
+ * `;
12
+ * ```
13
+ */
2
14
  declare function css(styles: Styles<object>, ...interpolations: Interpolation<object>[]): RuleSet<object>;
3
15
  declare function css<Props extends object>(styles: Styles<NoInfer<Props>>, ...interpolations: Interpolation<NoInfer<Props>>[]): RuleSet<NoInfer<Props>>;
4
16
  export default css;
@@ -1,3 +1,14 @@
1
1
  import Keyframes from '../models/Keyframes';
2
2
  import { Interpolation, Styles } from '../types';
3
+ /**
4
+ * Define a CSS `@keyframes` animation with an automatically scoped name.
5
+ *
6
+ * ```tsx
7
+ * const rotate = keyframes`
8
+ * from { transform: rotate(0deg); }
9
+ * to { transform: rotate(360deg); }
10
+ * `;
11
+ * const Spinner = styled.div`animation: ${rotate} 1s linear infinite;`;
12
+ * ```
13
+ */
3
14
  export default function keyframes<Props extends object = {}>(strings: Styles<Props>, ...interpolations: Array<Interpolation<Props>>): Keyframes;
@@ -2,6 +2,14 @@ import * as React from 'react';
2
2
  import { BaseObject, KnownTarget, WebTarget } from '../types';
3
3
  import { SupportedHTMLElements } from '../utils/domElements';
4
4
  import { Styled as StyledInstance } from './constructWithOptions';
5
+ /**
6
+ * Create a styled component from an HTML element or React component.
7
+ *
8
+ * ```tsx
9
+ * const Button = styled.button`color: red;`;
10
+ * const Link = styled(RouterLink)`text-decoration: none;`;
11
+ * ```
12
+ */
5
13
  declare const baseStyled: <Target extends WebTarget, InjectedProps extends object = BaseObject>(tag: Target) => StyledInstance<"web", Target, Target extends KnownTarget ? React.ComponentPropsWithRef<Target> & InjectedProps : InjectedProps, BaseObject, never>;
6
14
  declare const styled: typeof baseStyled & { [E in SupportedHTMLElements]: StyledInstance<"web", E, React.JSX.IntrinsicElements[E]>; };
7
15
  export default styled;
@@ -2,5 +2,6 @@ import React from 'react';
2
2
  import { AnyComponent, ExecutionProps } from '../types';
3
3
  import { NonReactStatics } from '../utils/hoist';
4
4
  type WithThemeOuterProps<T extends AnyComponent> = Omit<React.ComponentPropsWithRef<T>, keyof ExecutionProps> & ExecutionProps;
5
+ /** Higher-order component that injects the current theme as a prop. Prefer `useTheme` in function components. */
5
6
  export default function withTheme<T extends AnyComponent>(Component: T): React.ForwardRefExoticComponent<React.PropsWithoutRef<WithThemeOuterProps<T>> & React.RefAttributes<any>> & NonReactStatics<T>;
6
7
  export {};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import styled, { LibraryStyled, Styled, StyledInstance } from './constructors/styled';
2
2
  export * from './base';
3
+ export { default as stylisPluginRSC } from './utils/stylisPluginRSC';
3
4
  export { CSSKeyframes, CSSObject, CSSProp, CSSProperties, CSSPseudos, DataAttributes, DefaultTheme, ExecutionContext, ExecutionProps, FastOmit, Interpolation, IStyledComponent, IStyledComponentFactory, IStyledStatics, PolymorphicComponent, PolymorphicComponentProps, RuleSet, Runtime, StyledObject, StyledOptions, StyleFunction, SupportedHTMLElements, WebTarget, } from './types';
4
5
  export { styled as default, LibraryStyled, Styled, styled, StyledInstance };
@@ -1,5 +1,10 @@
1
1
  import StyleSheet from '../sheet';
2
2
  import { ExecutionContext, RuleSet, Stringifier } from '../types';
3
+ /**
4
+ * Get all compiled CSS for a ComponentStyle's registered names.
5
+ * Returns null on any cache miss (caller falls back to getGroup).
6
+ */
7
+ export declare function getCompiledCSS(cs: ComponentStyle, styleSheet: StyleSheet): string | null;
3
8
  /**
4
9
  * ComponentStyle is all the CSS-specific stuff, not the React-specific stuff.
5
10
  */
@@ -7,12 +12,8 @@ export default class ComponentStyle {
7
12
  baseHash: number;
8
13
  baseStyle: ComponentStyle | null | undefined;
9
14
  componentId: string;
10
- isStatic: boolean;
11
15
  rules: RuleSet<any>;
12
- staticRulesId: string;
16
+ dynamicNameCache: Map<string, string> | undefined;
13
17
  constructor(rules: RuleSet<any>, componentId: string, baseStyle?: ComponentStyle | undefined);
14
- generateAndInjectStyles(executionContext: ExecutionContext, styleSheet: StyleSheet, stylis: Stringifier): {
15
- className: string;
16
- css: string;
17
- };
18
+ generateAndInjectStyles(executionContext: ExecutionContext, styleSheet: StyleSheet, stylis: Stringifier): string;
18
19
  }
@@ -1,11 +1,23 @@
1
1
  import StyleSheet from '../sheet';
2
2
  import { ExecutionContext, RuleSet, Stringifier } from '../types';
3
+ type InstanceEntry = {
4
+ name: string;
5
+ rules: string[];
6
+ };
3
7
  export default class GlobalStyle<Props extends object> {
4
8
  componentId: string;
5
9
  isStatic: boolean;
6
10
  rules: RuleSet<Props>;
11
+ /** @internal Per-instance rule cache for shared-group rebuild. */
12
+ instanceRules: Map<number, InstanceEntry>;
7
13
  constructor(rules: RuleSet<Props>, componentId: string);
8
- createStyles(instance: number, executionContext: ExecutionContext & Props, styleSheet: StyleSheet, stylis: Stringifier): void;
9
14
  removeStyles(instance: number, styleSheet: StyleSheet): void;
10
15
  renderStyles(instance: number, executionContext: ExecutionContext & Props, styleSheet: StyleSheet, stylis: Stringifier): void;
16
+ private computeRules;
17
+ /**
18
+ * Clear all CSS rules in the shared group and re-insert from surviving instances.
19
+ * Must run synchronously — no yielding between clear and re-insert.
20
+ */
21
+ private rebuildGroup;
11
22
  }
23
+ export {};
@@ -1,6 +1,17 @@
1
1
  import { IInlineStyleConstructor, StyleSheet } from '../types';
2
2
  export declare const RN_UNSUPPORTED_VALUES: string[];
3
+ /**
4
+ * Extract CSS declaration pairs from flat CSS text.
5
+ * Only handles `property: value;` — selectors, at-rules, and nesting
6
+ * are not supported (and not expected in the native inline style path).
7
+ */
8
+ export declare function parseCSSDeclarations(rawCss: string): [string, string][];
9
+ /** Clear the cached CSS-to-style-object mappings. Useful in tests or long-running RN apps with highly dynamic styles. */
3
10
  export declare const resetStyleCache: () => void;
11
+ /**
12
+ * Parse flat CSS into a style object via css-to-react-native, with caching.
13
+ */
14
+ export declare function cssToStyleObject(flatCSS: string, styleSheet: StyleSheet): any;
4
15
  /**
5
16
  * InlineStyle takes arbitrary CSS and generates a flat object
6
17
  */
@@ -8,12 +8,13 @@ export type IStyleSheetContext = {
8
8
  shouldForwardProp?: ShouldForwardProp<'web'> | undefined;
9
9
  styleSheet: StyleSheet;
10
10
  stylis: Stringifier;
11
+ /** Preserved for inheritance — inner SSMs that set namespace/vendorPrefixes
12
+ * but not stylisPlugins can still inherit the parent's plugins. */
13
+ stylisPlugins?: stylis.Middleware[] | undefined;
11
14
  };
12
15
  export declare const StyleSheetContext: React.Context<IStyleSheetContext>;
13
16
  export declare const StyleSheetConsumer: React.Consumer<IStyleSheetContext>;
14
17
  export type IStylisContext = Stringifier | void;
15
- export declare const StylisContext: React.Context<IStylisContext>;
16
- export declare const StylisConsumer: React.Consumer<IStylisContext>;
17
18
  export declare function useStyleSheetContext(): IStyleSheetContext;
18
19
  export type IStyleSheetManager = React.PropsWithChildren<{
19
20
  /**
@@ -49,6 +50,10 @@ export type IStyleSheetManager = React.PropsWithChildren<{
49
50
  *
50
51
  * Manually composing `styled.{element}.withConfig({shouldForwardProp})` will
51
52
  * override this default.
53
+ *
54
+ * When nested inside another `StyleSheetManager`, omitting this prop inherits
55
+ * the parent's function. Pass `undefined` explicitly or a passthrough function
56
+ * to disable inherited behavior for a subtree.
52
57
  */
53
58
  shouldForwardProp?: undefined | IStyleSheetContext['shouldForwardProp'];
54
59
  /**
@@ -56,6 +61,10 @@ export type IStyleSheetManager = React.PropsWithChildren<{
56
61
  * Check out [what's available on npm*](https://www.npmjs.com/search?q=keywords%3Astylis).
57
62
  *
58
63
  * \* The plugin(s) must be compatible with stylis v4 or above.
64
+ *
65
+ * When nested inside another `StyleSheetManager`, omitting this prop inherits
66
+ * the parent's plugins. Pass an empty array (`[]`) to explicitly disable
67
+ * inherited plugins for a subtree.
59
68
  */
60
69
  stylisPlugins?: undefined | stylis.Middleware[];
61
70
  /**
@@ -68,4 +77,5 @@ export type IStyleSheetManager = React.PropsWithChildren<{
68
77
  */
69
78
  target?: undefined | InsertionTarget;
70
79
  }>;
80
+ /** Configure style injection for descendant styled components (target element, stylis plugins, prop forwarding). */
71
81
  export declare function StyleSheetManager(props: IStyleSheetManager): React.JSX.Element;