styled-components 6.4.0-prerelease.2 → 6.4.0-prerelease.3
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/dist/base.d.ts +2 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constructors/createTheme.d.ts +89 -0
- package/dist/models/ComponentStyle.d.ts +1 -4
- package/dist/sheet/Sheet.d.ts +2 -0
- package/dist/styled-components.browser.cjs.js +1 -1
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.esm.js +1 -1
- package/dist/styled-components.browser.esm.js.map +1 -1
- package/dist/styled-components.cjs.js +1 -1
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.esm.js +1 -1
- package/dist/styled-components.esm.js.map +1 -1
- package/dist/styled-components.js +150 -17
- package/dist/styled-components.js.map +1 -1
- package/dist/styled-components.min.js +1 -1
- package/dist/styled-components.min.js.map +1 -1
- package/native/dist/base.d.ts +2 -1
- package/native/dist/constants.d.ts +1 -0
- package/native/dist/constructors/createTheme.d.ts +89 -0
- package/native/dist/dist/base.d.ts +2 -1
- package/native/dist/dist/constants.d.ts +1 -0
- package/native/dist/dist/constructors/createTheme.d.ts +89 -0
- package/native/dist/dist/models/ComponentStyle.d.ts +1 -4
- package/native/dist/dist/sheet/Sheet.d.ts +2 -0
- package/native/dist/models/ComponentStyle.d.ts +1 -4
- package/native/dist/sheet/Sheet.d.ts +2 -0
- package/native/dist/sheet/Tag.d.ts +4 -4
- package/native/dist/styled-components.native.cjs.js.map +1 -1
- package/native/dist/styled-components.native.esm.js.map +1 -1
- package/package.json +4 -3
package/native/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, };
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
* Read the current resolved CSS variable values from the DOM and return
|
|
26
|
+
* an object with the same shape as the original theme. Each leaf is the
|
|
27
|
+
* computed value (e.g. `"#0070f3"`), not the `var()` reference.
|
|
28
|
+
*
|
|
29
|
+
* Optionally pass a target element to read scoped variables from
|
|
30
|
+
* (defaults to `document.documentElement`).
|
|
31
|
+
*
|
|
32
|
+
* Client-only — throws if called on the server.
|
|
33
|
+
*/
|
|
34
|
+
resolve(el?: Element): T;
|
|
35
|
+
};
|
|
36
|
+
interface CreateThemeOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Prefix for CSS variable names. Defaults to `"sc"`.
|
|
39
|
+
* Useful for isolation when multiple design systems or microfrontends
|
|
40
|
+
* coexist on the same page.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* createTheme(theme, { prefix: 'ds' })
|
|
44
|
+
* // → var(--ds-colors-primary, #0070f3)
|
|
45
|
+
*/
|
|
46
|
+
prefix?: string;
|
|
47
|
+
/**
|
|
48
|
+
* CSS selector for the variable declarations. Defaults to `":root"`.
|
|
49
|
+
* Use `":host"` for web components / Shadow DOM, or a class selector
|
|
50
|
+
* for scoped theming.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* createTheme(theme, { selector: ':host' })
|
|
54
|
+
* // → :host { --sc-colors-primary: #0070f3; }
|
|
55
|
+
*/
|
|
56
|
+
selector?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a theme contract that bridges `ThemeProvider` and CSS custom properties.
|
|
60
|
+
*
|
|
61
|
+
* Returns an object with the same shape as the input theme, but every leaf value
|
|
62
|
+
* is a `var(--prefix-*, fallback)` CSS string. Use these in styled component
|
|
63
|
+
* templates — they work in both client and RSC contexts.
|
|
64
|
+
*
|
|
65
|
+
* Mount the returned `GlobalStyle` component inside your `ThemeProvider` to emit
|
|
66
|
+
* the CSS variables. When the theme changes (e.g. light → dark), the variables
|
|
67
|
+
* update automatically.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```tsx
|
|
71
|
+
* const theme = createTheme({
|
|
72
|
+
* colors: { primary: '#0070f3', text: '#111' },
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // Root layout (client):
|
|
76
|
+
* <ThemeProvider theme={themes[preset]}>
|
|
77
|
+
* <theme.GlobalStyle />
|
|
78
|
+
* {children}
|
|
79
|
+
* </ThemeProvider>
|
|
80
|
+
*
|
|
81
|
+
* // Any RSC file:
|
|
82
|
+
* const Card = styled.div`
|
|
83
|
+
* color: ${theme.colors.primary};
|
|
84
|
+
* // → "var(--sc-colors-primary, #0070f3)"
|
|
85
|
+
* `;
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export default function createTheme<T extends Record<string, any>>(defaultTheme: T, options?: CreateThemeOptions): ThemeContract<T>;
|
|
89
|
+
export {};
|
|
@@ -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, };
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
* Read the current resolved CSS variable values from the DOM and return
|
|
26
|
+
* an object with the same shape as the original theme. Each leaf is the
|
|
27
|
+
* computed value (e.g. `"#0070f3"`), not the `var()` reference.
|
|
28
|
+
*
|
|
29
|
+
* Optionally pass a target element to read scoped variables from
|
|
30
|
+
* (defaults to `document.documentElement`).
|
|
31
|
+
*
|
|
32
|
+
* Client-only — throws if called on the server.
|
|
33
|
+
*/
|
|
34
|
+
resolve(el?: Element): T;
|
|
35
|
+
};
|
|
36
|
+
interface CreateThemeOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Prefix for CSS variable names. Defaults to `"sc"`.
|
|
39
|
+
* Useful for isolation when multiple design systems or microfrontends
|
|
40
|
+
* coexist on the same page.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* createTheme(theme, { prefix: 'ds' })
|
|
44
|
+
* // → var(--ds-colors-primary, #0070f3)
|
|
45
|
+
*/
|
|
46
|
+
prefix?: string;
|
|
47
|
+
/**
|
|
48
|
+
* CSS selector for the variable declarations. Defaults to `":root"`.
|
|
49
|
+
* Use `":host"` for web components / Shadow DOM, or a class selector
|
|
50
|
+
* for scoped theming.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* createTheme(theme, { selector: ':host' })
|
|
54
|
+
* // → :host { --sc-colors-primary: #0070f3; }
|
|
55
|
+
*/
|
|
56
|
+
selector?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a theme contract that bridges `ThemeProvider` and CSS custom properties.
|
|
60
|
+
*
|
|
61
|
+
* Returns an object with the same shape as the input theme, but every leaf value
|
|
62
|
+
* is a `var(--prefix-*, fallback)` CSS string. Use these in styled component
|
|
63
|
+
* templates — they work in both client and RSC contexts.
|
|
64
|
+
*
|
|
65
|
+
* Mount the returned `GlobalStyle` component inside your `ThemeProvider` to emit
|
|
66
|
+
* the CSS variables. When the theme changes (e.g. light → dark), the variables
|
|
67
|
+
* update automatically.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```tsx
|
|
71
|
+
* const theme = createTheme({
|
|
72
|
+
* colors: { primary: '#0070f3', text: '#111' },
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // Root layout (client):
|
|
76
|
+
* <ThemeProvider theme={themes[preset]}>
|
|
77
|
+
* <theme.GlobalStyle />
|
|
78
|
+
* {children}
|
|
79
|
+
* </ThemeProvider>
|
|
80
|
+
*
|
|
81
|
+
* // Any RSC file:
|
|
82
|
+
* const Card = styled.div`
|
|
83
|
+
* color: ${theme.colors.primary};
|
|
84
|
+
* // → "var(--sc-colors-primary, #0070f3)"
|
|
85
|
+
* `;
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export default function createTheme<T extends Record<string, any>>(defaultTheme: T, options?: CreateThemeOptions): ThemeContract<T>;
|
|
89
|
+
export {};
|
|
@@ -11,8 +11,5 @@ export default class ComponentStyle {
|
|
|
11
11
|
rules: RuleSet<any>;
|
|
12
12
|
staticRulesId: string;
|
|
13
13
|
constructor(rules: RuleSet<any>, componentId: string, baseStyle?: ComponentStyle | undefined);
|
|
14
|
-
generateAndInjectStyles(executionContext: ExecutionContext, styleSheet: StyleSheet, stylis: Stringifier):
|
|
15
|
-
className: string;
|
|
16
|
-
css: string;
|
|
17
|
-
};
|
|
14
|
+
generateAndInjectStyles(executionContext: ExecutionContext, styleSheet: StyleSheet, stylis: Stringifier): string;
|
|
18
15
|
}
|
|
@@ -13,6 +13,8 @@ type NamesAllocationMap = Map<string, Set<string>>;
|
|
|
13
13
|
/** Contains the main stylesheet logic for stringification and caching */
|
|
14
14
|
export default class StyleSheet implements Sheet {
|
|
15
15
|
gs: GlobalStylesAllocationMap;
|
|
16
|
+
/** Keyframe component IDs for efficient RSC rendering (avoids scanning all names) */
|
|
17
|
+
keyframeIds: Set<string>;
|
|
16
18
|
names: NamesAllocationMap;
|
|
17
19
|
options: SheetOptions;
|
|
18
20
|
server: boolean;
|
|
@@ -11,8 +11,5 @@ export default class ComponentStyle {
|
|
|
11
11
|
rules: RuleSet<any>;
|
|
12
12
|
staticRulesId: string;
|
|
13
13
|
constructor(rules: RuleSet<any>, componentId: string, baseStyle?: ComponentStyle | undefined);
|
|
14
|
-
generateAndInjectStyles(executionContext: ExecutionContext, styleSheet: StyleSheet, stylis: Stringifier):
|
|
15
|
-
className: string;
|
|
16
|
-
css: string;
|
|
17
|
-
};
|
|
14
|
+
generateAndInjectStyles(executionContext: ExecutionContext, styleSheet: StyleSheet, stylis: Stringifier): string;
|
|
18
15
|
}
|
|
@@ -13,6 +13,8 @@ type NamesAllocationMap = Map<string, Set<string>>;
|
|
|
13
13
|
/** Contains the main stylesheet logic for stringification and caching */
|
|
14
14
|
export default class StyleSheet implements Sheet {
|
|
15
15
|
gs: GlobalStylesAllocationMap;
|
|
16
|
+
/** Keyframe component IDs for efficient RSC rendering (avoids scanning all names) */
|
|
17
|
+
keyframeIds: Set<string>;
|
|
16
18
|
names: NamesAllocationMap;
|
|
17
19
|
options: SheetOptions;
|
|
18
20
|
server: boolean;
|
|
@@ -2,21 +2,21 @@ import { InsertionTarget } from '../types';
|
|
|
2
2
|
import { SheetOptions } from './types';
|
|
3
3
|
/** Create a CSSStyleSheet-like tag depending on the environment */
|
|
4
4
|
export declare const makeTag: ({ isServer, useCSSOMInjection, target, nonce }: SheetOptions) => {
|
|
5
|
-
|
|
5
|
+
element: HTMLStyleElement;
|
|
6
|
+
sheet: CSSStyleSheet;
|
|
6
7
|
length: number;
|
|
7
8
|
insertRule(index: number, rule: string): boolean;
|
|
8
9
|
deleteRule(index: number): void;
|
|
9
10
|
getRule(index: number): string;
|
|
10
11
|
} | {
|
|
11
12
|
element: HTMLStyleElement;
|
|
12
|
-
|
|
13
|
+
nodes: NodeListOf<Node>;
|
|
13
14
|
length: number;
|
|
14
15
|
insertRule(index: number, rule: string): boolean;
|
|
15
16
|
deleteRule(index: number): void;
|
|
16
17
|
getRule(index: number): string;
|
|
17
18
|
} | {
|
|
18
|
-
|
|
19
|
-
nodes: NodeListOf<Node>;
|
|
19
|
+
rules: string[];
|
|
20
20
|
length: number;
|
|
21
21
|
insertRule(index: number, rule: string): boolean;
|
|
22
22
|
deleteRule(index: number): void;
|