styled-components 6.0.0-beta.5 → 6.0.0-beta.7
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 -2
- package/dist/constructors/constructWithOptions.d.ts +2 -2
- package/dist/constructors/styled.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/models/StyleSheetManager.d.ts +38 -13
- package/dist/native/index.d.ts +27 -27
- package/dist/styled-components-macro.cjs.js +2 -7
- package/dist/styled-components-macro.cjs.js.map +1 -1
- package/dist/styled-components.browser.cjs.js +36 -40
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.esm.js +17 -16
- package/dist/styled-components.browser.esm.js.map +1 -1
- package/dist/styled-components.cjs.js +35 -39
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.esm.js +17 -16
- package/dist/styled-components.esm.js.map +1 -1
- package/dist/styled-components.js +33 -131
- 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/dist/test/utils.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +15 -5
- package/dist/utils/stylis.d.ts +3 -3
- package/native/dist/base.d.ts +2 -2
- package/native/dist/constructors/constructWithOptions.d.ts +2 -2
- package/native/dist/constructors/styled.d.ts +1 -1
- package/native/dist/index.d.ts +2 -2
- package/native/dist/models/StyleSheetManager.d.ts +38 -13
- package/native/dist/native/index.d.ts +27 -27
- package/native/dist/styled-components.native.cjs.js +24 -25
- package/native/dist/styled-components.native.cjs.js.map +1 -1
- package/native/dist/styled-components.native.esm.js +13 -9
- package/native/dist/styled-components.native.esm.js.map +1 -1
- package/native/dist/test/utils.d.ts +1 -1
- package/native/dist/types.d.ts +15 -5
- package/native/dist/utils/stylis.d.ts +3 -3
- package/package.json +32 -33
package/dist/base.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import keyframes from './constructors/keyframes';
|
|
|
5
5
|
import withTheme from './hoc/withTheme';
|
|
6
6
|
import useTheme from './hooks/useTheme';
|
|
7
7
|
import ServerStyleSheet from './models/ServerStyleSheet';
|
|
8
|
-
import
|
|
8
|
+
import { IStyleSheetContext, IStyleSheetManager, IStylisContext, StyleSheetConsumer, StyleSheetContext, StyleSheetManager } from './models/StyleSheetManager';
|
|
9
9
|
import ThemeProvider, { ThemeConsumer, ThemeContext } from './models/ThemeProvider';
|
|
10
10
|
import isStyledComponent from './utils/isStyledComponent';
|
|
11
11
|
declare global {
|
|
@@ -15,4 +15,4 @@ declare global {
|
|
|
15
15
|
}
|
|
16
16
|
export * from './secretInternals';
|
|
17
17
|
export { AttrsArg as Attrs, DefaultTheme, ShouldForwardProp } from './types';
|
|
18
|
-
export { createGlobalStyle, css, isStyledComponent, keyframes, ServerStyleSheet, StyleSheetConsumer, StyleSheetContext, StyleSheetManager, ThemeConsumer, ThemeContext, ThemeProvider, useTheme, SC_VERSION as version, withTheme, };
|
|
18
|
+
export { createGlobalStyle, css, isStyledComponent, IStyleSheetManager, IStyleSheetContext, IStylisContext, keyframes, ServerStyleSheet, StyleSheetConsumer, StyleSheetContext, StyleSheetManager, ThemeConsumer, ThemeContext, ThemeProvider, useTheme, SC_VERSION as version, withTheme, };
|
|
@@ -13,10 +13,10 @@ declare type OptionalIntersection<A, B> = {
|
|
|
13
13
|
* with the passed attr type to capture any intended overrides.
|
|
14
14
|
*/
|
|
15
15
|
declare type MarkPropsSatisfiedByAttrs<T extends Attrs, Props extends object> = T extends (...args: any) => infer P ? Omit<Props, keyof P> & OptionalIntersection<Props, P> : Omit<Props, keyof T> & Partial<T>;
|
|
16
|
-
export interface Styled<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object = Target extends KnownTarget ? R extends 'web' ?
|
|
16
|
+
export interface Styled<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object = Target extends KnownTarget ? React.ComponentPropsWithRef<Target> : R extends 'web' ? JSX.IntrinsicElements['div'] : object, OuterStatics extends object = object> {
|
|
17
17
|
<Props extends object = object, Statics extends object = object>(initialStyles: Styles<OuterProps & Props>, ...interpolations: Interpolation<OuterProps & Props>[]): IStyledComponent<R, Target, OuterProps & Props> & OuterStatics & Statics;
|
|
18
18
|
attrs: <T extends Attrs>(attrs: AttrsArg<T extends (...args: any) => infer P ? OuterProps & P : OuterProps & T>) => Styled<R, Target, MarkPropsSatisfiedByAttrs<T, OuterProps>, OuterStatics>;
|
|
19
19
|
withConfig: (config: StyledOptions<R, OuterProps>) => Styled<R, Target, OuterProps, OuterStatics>;
|
|
20
20
|
}
|
|
21
|
-
export default function constructWithOptions<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object = Target extends KnownTarget ? R extends 'web' ?
|
|
21
|
+
export default function constructWithOptions<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object = Target extends KnownTarget ? React.ComponentPropsWithRef<Target> : R extends 'web' ? JSX.IntrinsicElements['div'] : object, OuterStatics extends object = object>(componentConstructor: IStyledComponentFactory<R, Target, OuterProps, OuterStatics>, tag: Target, options?: StyledOptions<R, OuterProps>): Styled<R, Target, OuterProps, OuterStatics>;
|
|
22
22
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WebTarget } from '../types';
|
|
3
3
|
import { Styled } from './constructWithOptions';
|
|
4
|
-
declare const styled: (<Target extends WebTarget>(tag: Target) => Styled<"web", Target,
|
|
4
|
+
declare const styled: (<Target extends WebTarget>(tag: Target) => Styled<"web", Target, Target extends import("../types").KnownTarget ? import("react").ComponentPropsWithRef<Target> : import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, object>) & {
|
|
5
5
|
a: Styled<"web", "a", import("react").DetailedHTMLProps<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, object>;
|
|
6
6
|
abbr: Styled<"web", "abbr", import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, object>;
|
|
7
7
|
address: Styled<"web", "address", import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, object>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import styled from './constructors/styled';
|
|
2
2
|
export * from './base';
|
|
3
|
-
export { CSSProp, IStyledComponent, IStyledComponentFactory, IStyledStatics, StyledOptions, WebTarget, } from './types';
|
|
4
|
-
export { styled as default };
|
|
3
|
+
export { CSSProp, DefaultTheme, ExecutionContext, ExecutionProps, IStyledComponent, IStyledComponentFactory, IStyledStatics, PolymorphicComponent, PolymorphicComponentProps, Runtime, StyledObject, StyledOptions, WebTarget, } from './types';
|
|
4
|
+
export { styled, styled as default };
|
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import StyleSheet from '../sheet';
|
|
3
3
|
import { Stringifier } from '../types';
|
|
4
|
-
declare type
|
|
5
|
-
|
|
4
|
+
export declare type IStyleSheetContext = StyleSheet | void;
|
|
5
|
+
export declare const StyleSheetContext: React.Context<IStyleSheetContext>;
|
|
6
|
+
export declare const StyleSheetConsumer: React.Consumer<IStyleSheetContext>;
|
|
7
|
+
export declare type IStylisContext = Stringifier | void;
|
|
8
|
+
export declare const StylisContext: React.Context<IStylisContext>;
|
|
9
|
+
export declare const StylisConsumer: React.Consumer<IStylisContext>;
|
|
10
|
+
export declare const mainSheet: StyleSheet;
|
|
11
|
+
export declare const mainStylis: Stringifier;
|
|
12
|
+
export declare function useStyleSheet(): StyleSheet;
|
|
13
|
+
export declare function useStylis(): Stringifier;
|
|
14
|
+
export declare type IStyleSheetManager = React.PropsWithChildren<{
|
|
15
|
+
/**
|
|
16
|
+
* If desired, you can pass this prop to disable "speedy" insertion mode, which
|
|
17
|
+
* uses the browser [CSSOM APIs](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet).
|
|
18
|
+
* When disabled, rules are inserted as simple text into style blocks.
|
|
19
|
+
*/
|
|
6
20
|
disableCSSOMInjection?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If you are working exclusively with modern browsers, vendor prefixes can often be omitted
|
|
23
|
+
* to reduce the weight of CSS on the page.
|
|
24
|
+
*/
|
|
7
25
|
disableVendorPrefixes?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Provide an optional selector to be prepended to all generated style rules.
|
|
28
|
+
*/
|
|
29
|
+
namespace?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Create and provide your own `StyleSheet` if necessary for advanced SSR scenarios.
|
|
32
|
+
*/
|
|
8
33
|
sheet?: StyleSheet;
|
|
34
|
+
/**
|
|
35
|
+
* An array of plugins to be run by stylis (style processor) during compilation.
|
|
36
|
+
* Check out [what's available on npm*](https://www.npmjs.com/search?q=keywords%3Astylis).
|
|
37
|
+
*
|
|
38
|
+
* \* The plugin(s) must be compatible with stylis v4 or above.
|
|
39
|
+
*/
|
|
9
40
|
stylisPlugins?: stylis.Middleware[];
|
|
41
|
+
/**
|
|
42
|
+
* Provide an alternate DOM node to host generated styles; useful for iframes.
|
|
43
|
+
*/
|
|
10
44
|
target?: HTMLElement;
|
|
11
|
-
}
|
|
12
|
-
export declare
|
|
13
|
-
export declare const StyleSheetConsumer: React.Consumer<void | StyleSheet>;
|
|
14
|
-
export declare const StylisContext: React.Context<void | Stringifier>;
|
|
15
|
-
export declare const StylisConsumer: React.Consumer<void | Stringifier>;
|
|
16
|
-
export declare const mainSheet: StyleSheet;
|
|
17
|
-
export declare const mainStylis: Stringifier;
|
|
18
|
-
export declare function useStyleSheet(): StyleSheet;
|
|
19
|
-
export declare function useStylis(): Stringifier;
|
|
20
|
-
export default function StyleSheetManager(props: Props): JSX.Element;
|
|
21
|
-
export {};
|
|
45
|
+
}>;
|
|
46
|
+
export declare function StyleSheetManager(props: IStyleSheetManager): JSX.Element;
|
package/dist/native/index.d.ts
CHANGED
|
@@ -6,32 +6,32 @@ import useTheme from '../hooks/useTheme';
|
|
|
6
6
|
import ThemeProvider, { ThemeConsumer, ThemeContext } from '../models/ThemeProvider';
|
|
7
7
|
import { NativeTarget } from '../types';
|
|
8
8
|
import isStyledComponent from '../utils/isStyledComponent';
|
|
9
|
-
declare const styled: (<Target extends NativeTarget>(tag: Target) => Styled<"native", Target, Target extends import("../types").KnownTarget ?
|
|
10
|
-
ActivityIndicator: Styled<"native", typeof import("react-native").ActivityIndicator,
|
|
11
|
-
Button: Styled<"native", typeof import("react-native").Button,
|
|
12
|
-
DatePickerIOS: Styled<"native", typeof import("react-native").DatePickerIOS,
|
|
13
|
-
DrawerLayoutAndroid: Styled<"native", typeof import("react-native").DrawerLayoutAndroid,
|
|
14
|
-
FlatList: Styled<"native", typeof import("react-native").FlatList,
|
|
15
|
-
Image: Styled<"native", typeof import("react-native").Image,
|
|
16
|
-
ImageBackground: Styled<"native", typeof import("react-native").ImageBackground,
|
|
17
|
-
KeyboardAvoidingView: Styled<"native", typeof import("react-native").KeyboardAvoidingView,
|
|
18
|
-
Modal: Styled<"native", typeof import("react-native").Modal,
|
|
19
|
-
Pressable: Styled<"native", import("react").ForwardRefExoticComponent<import("react-native").PressableProps & import("react").RefAttributes<import("react-native").View>>,
|
|
20
|
-
ProgressBarAndroid: Styled<"native", typeof import("react-native").ProgressBarAndroid,
|
|
21
|
-
ProgressViewIOS: Styled<"native", typeof import("react-native").ProgressViewIOS,
|
|
22
|
-
RefreshControl: Styled<"native", typeof import("react-native").RefreshControl,
|
|
23
|
-
SafeAreaView: Styled<"native", typeof import("react-native").SafeAreaView,
|
|
24
|
-
ScrollView: Styled<"native", typeof import("react-native").ScrollView,
|
|
25
|
-
SectionList: Styled<"native", typeof import("react-native").SectionList,
|
|
26
|
-
Slider: Styled<"native", typeof import("react-native").Slider,
|
|
27
|
-
Switch: Styled<"native", typeof import("react-native").Switch,
|
|
28
|
-
Text: Styled<"native", typeof import("react-native").Text,
|
|
29
|
-
TextInput: Styled<"native", typeof import("react-native").TextInput,
|
|
30
|
-
TouchableHighlight: Styled<"native", typeof import("react-native").TouchableHighlight,
|
|
31
|
-
TouchableOpacity: Styled<"native", typeof import("react-native").TouchableOpacity,
|
|
32
|
-
View: Styled<"native", typeof import("react-native").View,
|
|
33
|
-
VirtualizedList: Styled<"native", typeof import("react-native").VirtualizedList,
|
|
9
|
+
declare const styled: (<Target extends NativeTarget>(tag: Target) => Styled<"native", Target, Target extends import("../types").KnownTarget ? React.ComponentPropsWithRef<Target> : object, object>) & {
|
|
10
|
+
ActivityIndicator: Styled<"native", typeof import("react-native").ActivityIndicator, import("react-native").ActivityIndicatorProps & React.RefAttributes<import("react-native").ActivityIndicator>, object>;
|
|
11
|
+
Button: Styled<"native", typeof import("react-native").Button, import("react-native").ButtonProps & React.RefAttributes<import("react-native").Button>, object>;
|
|
12
|
+
DatePickerIOS: Styled<"native", typeof import("react-native").DatePickerIOS, import("react-native").DatePickerIOSProps & React.RefAttributes<import("react-native").DatePickerIOS>, object>;
|
|
13
|
+
DrawerLayoutAndroid: Styled<"native", typeof import("react-native").DrawerLayoutAndroid, import("react-native").DrawerLayoutAndroidProps & React.RefAttributes<import("react-native").DrawerLayoutAndroid>, object>;
|
|
14
|
+
FlatList: Styled<"native", typeof import("react-native").FlatList, import("react-native").FlatListProps<unknown> & React.RefAttributes<import("react-native").FlatList<unknown>>, object>;
|
|
15
|
+
Image: Styled<"native", typeof import("react-native").Image, import("react-native").ImageProps & React.RefAttributes<import("react-native").Image>, object>;
|
|
16
|
+
ImageBackground: Styled<"native", typeof import("react-native").ImageBackground, import("react-native").ImageBackgroundProps & React.RefAttributes<import("react-native").ImageBackground>, object>;
|
|
17
|
+
KeyboardAvoidingView: Styled<"native", typeof import("react-native").KeyboardAvoidingView, import("react-native").KeyboardAvoidingViewProps & React.RefAttributes<import("react-native").KeyboardAvoidingView>, object>;
|
|
18
|
+
Modal: Styled<"native", typeof import("react-native").Modal, import("react-native").ModalBaseProps & import("react-native").ModalPropsIOS & import("react-native").ModalPropsAndroid & import("react-native").ViewProps & React.RefAttributes<import("react-native").Modal>, object>;
|
|
19
|
+
Pressable: Styled<"native", import("react").ForwardRefExoticComponent<import("react-native").PressableProps & import("react").RefAttributes<import("react-native").View>>, import("react-native").PressableProps & import("react").RefAttributes<import("react-native").View>, object>;
|
|
20
|
+
ProgressBarAndroid: Styled<"native", typeof import("react-native").ProgressBarAndroid, import("react-native").ProgressBarAndroidProps & React.RefAttributes<import("react-native").ProgressBarAndroid>, object>;
|
|
21
|
+
ProgressViewIOS: Styled<"native", typeof import("react-native").ProgressViewIOS, import("react-native").ProgressViewIOSProps & React.RefAttributes<import("react-native").ProgressViewIOS>, object>;
|
|
22
|
+
RefreshControl: Styled<"native", typeof import("react-native").RefreshControl, import("react-native").RefreshControlProps & React.RefAttributes<import("react-native").RefreshControl>, object>;
|
|
23
|
+
SafeAreaView: Styled<"native", typeof import("react-native").SafeAreaView, import("react-native").ViewProps & React.RefAttributes<import("react-native").SafeAreaView>, object>;
|
|
24
|
+
ScrollView: Styled<"native", typeof import("react-native").ScrollView, import("react-native").ScrollViewProps & React.RefAttributes<import("react-native").ScrollView>, object>;
|
|
25
|
+
SectionList: Styled<"native", typeof import("react-native").SectionList, import("react-native").SectionListProps<unknown, unknown> & React.RefAttributes<import("react-native").SectionList<unknown, unknown>>, object>;
|
|
26
|
+
Slider: Styled<"native", typeof import("react-native").Slider, import("react-native").SliderProps & React.RefAttributes<import("react-native").Slider>, object>;
|
|
27
|
+
Switch: Styled<"native", typeof import("react-native").Switch, import("react-native").SwitchProps & React.RefAttributes<import("react-native").Switch>, object>;
|
|
28
|
+
Text: Styled<"native", typeof import("react-native").Text, import("react-native").TextProps & React.RefAttributes<import("react-native").Text>, object>;
|
|
29
|
+
TextInput: Styled<"native", typeof import("react-native").TextInput, import("react-native").TextInputProps & React.RefAttributes<import("react-native").TextInput>, object>;
|
|
30
|
+
TouchableHighlight: Styled<"native", typeof import("react-native").TouchableHighlight, import("react-native").TouchableHighlightProps & React.RefAttributes<import("react-native").TouchableHighlight>, object>;
|
|
31
|
+
TouchableOpacity: Styled<"native", typeof import("react-native").TouchableOpacity, import("react-native").TouchableOpacityProps & React.RefAttributes<import("react-native").TouchableOpacity>, object>;
|
|
32
|
+
View: Styled<"native", typeof import("react-native").View, import("react-native").ViewProps & React.RefAttributes<import("react-native").View>, object>;
|
|
33
|
+
VirtualizedList: Styled<"native", typeof import("react-native").VirtualizedList, import("react-native").VirtualizedListProps<unknown> & React.RefAttributes<import("react-native").VirtualizedList<unknown>>, object>;
|
|
34
34
|
};
|
|
35
|
-
export { IStyledComponent, IStyledComponentFactory, IStyledStatics, NativeTarget, StyledOptions, } from '../types';
|
|
35
|
+
export { DefaultTheme, ExecutionContext, ExecutionProps, IStyledComponent, IStyledComponentFactory, IStyledStatics, NativeTarget, PolymorphicComponent, PolymorphicComponentProps, Runtime, StyledObject, StyledOptions, } from '../types';
|
|
36
36
|
export { css, isStyledComponent, ThemeProvider, ThemeConsumer, ThemeContext, withTheme, useTheme };
|
|
37
|
-
export default
|
|
37
|
+
export { styled, styled as default };
|
|
@@ -8,11 +8,6 @@ var traverse = require('@babel/traverse');
|
|
|
8
8
|
var babelPluginMacros = require('babel-plugin-macros');
|
|
9
9
|
var babelPlugin = require('babel-plugin-styled-components');
|
|
10
10
|
|
|
11
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
-
|
|
13
|
-
var traverse__default = /*#__PURE__*/_interopDefaultLegacy(traverse);
|
|
14
|
-
var babelPlugin__default = /*#__PURE__*/_interopDefaultLegacy(babelPlugin);
|
|
15
|
-
|
|
16
11
|
function styledComponentsMacro(_a) {
|
|
17
12
|
var references = _a.references, state = _a.state, t = _a.babel.types, _b = _a.config, _c = _b === void 0 ? {} : _b, _d = _c.importModuleName, importModuleName = _d === void 0 ? 'styled-components' : _d, config = tslib.__rest(_c, ["importModuleName"]);
|
|
18
13
|
var program = state.file.path;
|
|
@@ -38,11 +33,11 @@ function styledComponentsMacro(_a) {
|
|
|
38
33
|
});
|
|
39
34
|
// SECOND STEP : apply babel-plugin-styled-components to the file
|
|
40
35
|
var stateWithOpts = tslib.__assign(tslib.__assign({}, state), { opts: tslib.__assign(tslib.__assign({}, config), { topLevelImportPaths: (config.topLevelImportPaths || []).concat(importModuleName) }), customImportName: customImportName });
|
|
41
|
-
|
|
36
|
+
traverse(program.parent, babelPlugin({ types: t }).visitor, undefined, stateWithOpts);
|
|
42
37
|
}
|
|
43
38
|
var index = babelPluginMacros.createMacro(styledComponentsMacro, {
|
|
44
39
|
configName: 'styledComponents',
|
|
45
40
|
});
|
|
46
41
|
|
|
47
|
-
exports
|
|
42
|
+
exports.default = index;
|
|
48
43
|
//# sourceMappingURL=styled-components-macro.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled-components-macro.cjs.js","sources":["../src/macro/index.ts"],"sourcesContent":["import { types } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport traverse from '@babel/traverse';\nimport { createMacro, MacroParams } from 'babel-plugin-macros';\nimport babelPlugin from 'babel-plugin-styled-components';\n\nfunction styledComponentsMacro({\n references,\n state,\n babel: { types: t },\n config: { importModuleName = 'styled-components', ...config } = {},\n}: MacroParams) {\n const program = state.file.path;\n\n // FIRST STEP : replace `styled-components/macro` by `styled-components\n // references looks like this\n // { default: [path, path], css: [path], ... }\n let customImportName;\n Object.keys(references).forEach(refName => {\n // generate new identifier\n let id: types.Identifier;\n if (refName === 'default') {\n id = addDefault(program, importModuleName, { nameHint: 'styled' });\n customImportName = id;\n } else {\n id = addNamed(program, refName, importModuleName, { nameHint: refName });\n }\n\n // update references with the new identifiers\n references[refName].forEach(referencePath => {\n // eslint-disable-next-line no-param-reassign\n (referencePath.node as types.Identifier).name = id.name;\n });\n });\n\n // SECOND STEP : apply babel-plugin-styled-components to the file\n const stateWithOpts = {\n ...state,\n opts: {\n ...config,\n topLevelImportPaths: (config.topLevelImportPaths || []).concat(importModuleName),\n },\n customImportName,\n };\n traverse(program.parent, babelPlugin({ types: t }).visitor, undefined, stateWithOpts);\n}\n\nexport default createMacro(styledComponentsMacro, {\n configName: 'styledComponents',\n});\n"],"names":["__rest","addDefault","addNamed","__assign","
|
|
1
|
+
{"version":3,"file":"styled-components-macro.cjs.js","sources":["../src/macro/index.ts"],"sourcesContent":["import { types } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport traverse from '@babel/traverse';\nimport { createMacro, MacroParams } from 'babel-plugin-macros';\nimport babelPlugin from 'babel-plugin-styled-components';\n\nfunction styledComponentsMacro({\n references,\n state,\n babel: { types: t },\n config: { importModuleName = 'styled-components', ...config } = {},\n}: MacroParams) {\n const program = state.file.path;\n\n // FIRST STEP : replace `styled-components/macro` by `styled-components\n // references looks like this\n // { default: [path, path], css: [path], ... }\n let customImportName;\n Object.keys(references).forEach(refName => {\n // generate new identifier\n let id: types.Identifier;\n if (refName === 'default') {\n id = addDefault(program, importModuleName, { nameHint: 'styled' });\n customImportName = id;\n } else {\n id = addNamed(program, refName, importModuleName, { nameHint: refName });\n }\n\n // update references with the new identifiers\n references[refName].forEach(referencePath => {\n // eslint-disable-next-line no-param-reassign\n (referencePath.node as types.Identifier).name = id.name;\n });\n });\n\n // SECOND STEP : apply babel-plugin-styled-components to the file\n const stateWithOpts = {\n ...state,\n opts: {\n ...config,\n topLevelImportPaths: (config.topLevelImportPaths || []).concat(importModuleName),\n },\n customImportName,\n };\n traverse(program.parent, babelPlugin({ types: t }).visitor, undefined, stateWithOpts);\n}\n\nexport default createMacro(styledComponentsMacro, {\n configName: 'styledComponents',\n});\n"],"names":["__rest","addDefault","addNamed","__assign","createMacro"],"mappings":";;;;;;;;;;AAMA,SAAS,qBAAqB,CAAC,EAKjB,EAAA;IAJZ,IAAA,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,KAAK,GAAA,EAAA,CAAA,KAAA,EACW,CAAC,GAAA,EAAA,CAAA,KAAA,CAAA,KAAA,EACjB,EAAA,GAAA,EAAA,CAAA,MAAkE,EAAlE,EAAA,GAAA,EAAA,KAAA,KAAA,CAAA,GAAgE,EAAE,GAAA,EAAA,EAAxD,EAAsC,GAAA,EAAA,CAAA,gBAAA,EAAtC,gBAAgB,GAAA,EAAA,KAAA,KAAA,CAAA,GAAG,mBAAmB,GAAA,EAAA,EAAK,MAAM,GAAnDA,YAAA,CAAA,EAAA,EAAA,CAAA,kBAAA,CAAqD,CAAK,CAAA;AAElE,IAAA,IAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;;;;AAKhC,IAAA,IAAI,gBAAgB,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAA,OAAO,EAAA;;AAErC,QAAA,IAAI,EAAoB,CAAC;QACzB,IAAI,OAAO,KAAK,SAAS,EAAE;AACzB,YAAA,EAAE,GAAGC,8BAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YACnE,gBAAgB,GAAG,EAAE,CAAC;AACvB,SAAA;AAAM,aAAA;AACL,YAAA,EAAE,GAAGC,4BAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;AAC1E,SAAA;;AAGD,QAAA,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAA,aAAa,EAAA;;YAEtC,aAAa,CAAC,IAAyB,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;AAC1D,SAAC,CAAC,CAAC;AACL,KAAC,CAAC,CAAC;;IAGH,IAAM,aAAa,GACdC,cAAA,CAAAA,cAAA,CAAA,EAAA,EAAA,KAAK,CACR,EAAA,EAAA,IAAI,EACCA,cAAA,CAAAA,cAAA,CAAA,EAAA,EAAA,MAAM,CACT,EAAA,EAAA,mBAAmB,EAAE,CAAC,MAAM,CAAC,mBAAmB,IAAI,EAAE,EAAE,MAAM,CAAC,gBAAgB,CAAC,EAElF,CAAA,EAAA,gBAAgB,EAAA,gBAAA,EAAA,CACjB,CAAC;IACF,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AACxF,CAAC;AAED,YAAeC,6BAAW,CAAC,qBAAqB,EAAE;AAChD,IAAA,UAAU,EAAE,kBAAkB;AAC/B,CAAA,CAAC;;;;"}
|
|
@@ -8,17 +8,11 @@ var shallowequal = require('shallowequal');
|
|
|
8
8
|
var stylis = require('stylis');
|
|
9
9
|
var unitless = require('@emotion/unitless');
|
|
10
10
|
|
|
11
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
-
|
|
13
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
14
|
-
var shallowequal__default = /*#__PURE__*/_interopDefaultLegacy(shallowequal);
|
|
15
|
-
var unitless__default = /*#__PURE__*/_interopDefaultLegacy(unitless);
|
|
16
|
-
|
|
17
11
|
var SC_ATTR = (typeof process !== 'undefined' && (process.env.REACT_APP_SC_ATTR || process.env.SC_ATTR)) ||
|
|
18
12
|
'data-styled';
|
|
19
13
|
var SC_ATTR_ACTIVE = 'active';
|
|
20
14
|
var SC_ATTR_VERSION = 'data-styled-version';
|
|
21
|
-
var SC_VERSION = "6.0.0-beta.
|
|
15
|
+
var SC_VERSION = "6.0.0-beta.7";
|
|
22
16
|
var SPLITTER = '/*!sc*/\n';
|
|
23
17
|
var IS_BROWSER = typeof window !== 'undefined' && 'HTMLElement' in window;
|
|
24
18
|
var DISABLE_SPEEDY = Boolean(typeof SC_DISABLE_SPEEDY === 'boolean'
|
|
@@ -1026,7 +1020,11 @@ function createStylisInstance(_a) {
|
|
|
1026
1020
|
props[0] = props[0].replace(_selectorRegexp, selfReferenceReplacer);
|
|
1027
1021
|
}
|
|
1028
1022
|
};
|
|
1029
|
-
var stringifyRules = function (css, selector,
|
|
1023
|
+
var stringifyRules = function (css, selector,
|
|
1024
|
+
/**
|
|
1025
|
+
* This "prefix" referes to a _selector_ prefix.
|
|
1026
|
+
*/
|
|
1027
|
+
prefix, componentId) {
|
|
1030
1028
|
if (selector === void 0) { selector = ''; }
|
|
1031
1029
|
if (prefix === void 0) { prefix = ''; }
|
|
1032
1030
|
if (componentId === void 0) { componentId = '&'; }
|
|
@@ -1039,11 +1037,16 @@ function createStylisInstance(_a) {
|
|
|
1039
1037
|
_selectorRegexp = new RegExp("\\".concat(_selector, "\\b"), 'g');
|
|
1040
1038
|
_consecutiveSelfRefRegExp = new RegExp("(\\".concat(_selector, "\\b){2,}"));
|
|
1041
1039
|
var middlewares = plugins.slice();
|
|
1040
|
+
/**
|
|
1041
|
+
* Enables automatic vendor-prefixing for styles.
|
|
1042
|
+
*/
|
|
1042
1043
|
if (options.prefix || options.prefix === undefined) {
|
|
1043
1044
|
middlewares.unshift(stylis.prefixer);
|
|
1044
1045
|
}
|
|
1045
1046
|
middlewares.push(selfReferenceReplacementPlugin, stylis.stringify);
|
|
1046
|
-
return serialize(stylis.compile(
|
|
1047
|
+
return serialize(stylis.compile(options.namespace || prefix || selector
|
|
1048
|
+
? "".concat(options.namespace ? options.namespace + ' ' : '').concat(prefix, " ").concat(selector, " { ").concat(flatCSS, " }")
|
|
1049
|
+
: flatCSS), stylis.middleware(middlewares));
|
|
1047
1050
|
};
|
|
1048
1051
|
stringifyRules.hash = plugins.length
|
|
1049
1052
|
? plugins
|
|
@@ -1058,9 +1061,9 @@ function createStylisInstance(_a) {
|
|
|
1058
1061
|
return stringifyRules;
|
|
1059
1062
|
}
|
|
1060
1063
|
|
|
1061
|
-
var StyleSheetContext =
|
|
1064
|
+
var StyleSheetContext = React.createContext(undefined);
|
|
1062
1065
|
var StyleSheetConsumer = StyleSheetContext.Consumer;
|
|
1063
|
-
var StylisContext =
|
|
1066
|
+
var StylisContext = React.createContext(undefined);
|
|
1064
1067
|
StylisContext.Consumer;
|
|
1065
1068
|
var mainSheet = new StyleSheet();
|
|
1066
1069
|
var mainStylis = createStylisInstance();
|
|
@@ -1089,17 +1092,17 @@ function StyleSheetManager(props) {
|
|
|
1089
1092
|
}, [props.disableCSSOMInjection, props.sheet, props.target]);
|
|
1090
1093
|
var stylis = React.useMemo(function () {
|
|
1091
1094
|
return createStylisInstance({
|
|
1092
|
-
options: { prefix: !props.disableVendorPrefixes },
|
|
1095
|
+
options: { namespace: props.namespace, prefix: !props.disableVendorPrefixes },
|
|
1093
1096
|
plugins: plugins,
|
|
1094
1097
|
});
|
|
1095
|
-
}, [props.disableVendorPrefixes, plugins]);
|
|
1098
|
+
}, [props.disableVendorPrefixes, props.namespace, plugins]);
|
|
1096
1099
|
React.useEffect(function () {
|
|
1097
|
-
if (!
|
|
1100
|
+
if (!shallowequal(plugins, props.stylisPlugins))
|
|
1098
1101
|
setPlugins(props.stylisPlugins);
|
|
1099
1102
|
}, [props.stylisPlugins]);
|
|
1100
|
-
return (
|
|
1101
|
-
|
|
1102
|
-
?
|
|
1103
|
+
return (React.createElement(StyleSheetContext.Provider, { value: styleSheet },
|
|
1104
|
+
React.createElement(StylisContext.Provider, { value: stylis }, process.env.NODE_ENV !== 'production'
|
|
1105
|
+
? React.Children.only(props.children)
|
|
1103
1106
|
: props.children)));
|
|
1104
1107
|
}
|
|
1105
1108
|
|
|
@@ -1133,7 +1136,7 @@ function addUnitIfNeeded(name, value) {
|
|
|
1133
1136
|
if (value == null || typeof value === 'boolean' || value === '') {
|
|
1134
1137
|
return '';
|
|
1135
1138
|
}
|
|
1136
|
-
if (typeof value === 'number' && value !== 0 && !(name in
|
|
1139
|
+
if (typeof value === 'number' && value !== 0 && !(name in unitless)) {
|
|
1137
1140
|
return "".concat(value, "px"); // Presumes implicit 'px' suffix for unitless numbers
|
|
1138
1141
|
}
|
|
1139
1142
|
return String(value).trim();
|
|
@@ -1340,7 +1343,7 @@ var ComponentStyle = /** @class */ (function () {
|
|
|
1340
1343
|
return ComponentStyle;
|
|
1341
1344
|
}());
|
|
1342
1345
|
|
|
1343
|
-
var ThemeContext =
|
|
1346
|
+
var ThemeContext = React.createContext(undefined);
|
|
1344
1347
|
var ThemeConsumer = ThemeContext.Consumer;
|
|
1345
1348
|
function mergeTheme(theme, outerTheme) {
|
|
1346
1349
|
if (!theme) {
|
|
@@ -1369,7 +1372,7 @@ function ThemeProvider(props) {
|
|
|
1369
1372
|
if (!props.children) {
|
|
1370
1373
|
return null;
|
|
1371
1374
|
}
|
|
1372
|
-
return
|
|
1375
|
+
return React.createElement(ThemeContext.Provider, { value: themeContext }, props.children);
|
|
1373
1376
|
}
|
|
1374
1377
|
|
|
1375
1378
|
var identifiers = {};
|
|
@@ -1491,7 +1494,7 @@ function createStyledComponent(target, options, rules) {
|
|
|
1491
1494
|
* forwardRef creates a new interim component, which we'll take advantage of
|
|
1492
1495
|
* instead of extending ParentComponent to create _another_ interim class
|
|
1493
1496
|
*/
|
|
1494
|
-
var WrappedStyledComponent =
|
|
1497
|
+
var WrappedStyledComponent = React.forwardRef(forwardRef);
|
|
1495
1498
|
WrappedStyledComponent.attrs = finalAttrs;
|
|
1496
1499
|
WrappedStyledComponent.componentStyle = componentStyle;
|
|
1497
1500
|
WrappedStyledComponent.displayName = displayName;
|
|
@@ -1504,13 +1507,6 @@ function createStyledComponent(target, options, rules) {
|
|
|
1504
1507
|
WrappedStyledComponent.styledComponentId = styledComponentId;
|
|
1505
1508
|
// fold the underlying StyledComponent target up since we folded the styles
|
|
1506
1509
|
WrappedStyledComponent.target = isTargetStyledComp ? styledComponentTarget.target : target;
|
|
1507
|
-
WrappedStyledComponent.withComponent = function withComponent(tag) {
|
|
1508
|
-
var previousComponentId = options.componentId, optionsToCopy = tslib.__rest(options, ["componentId"]);
|
|
1509
|
-
var newComponentId = previousComponentId &&
|
|
1510
|
-
"".concat(previousComponentId, "-").concat(isTag(tag) ? tag : escape(getComponentName(tag)));
|
|
1511
|
-
var newOptions = tslib.__assign(tslib.__assign({}, optionsToCopy), { attrs: finalAttrs, componentId: newComponentId });
|
|
1512
|
-
return createStyledComponent(tag, newOptions, rules);
|
|
1513
|
-
};
|
|
1514
1510
|
Object.defineProperty(WrappedStyledComponent, 'defaultProps', {
|
|
1515
1511
|
get: function () {
|
|
1516
1512
|
return this._foldedDefaultProps;
|
|
@@ -1537,7 +1533,6 @@ function createStyledComponent(target, options, rules) {
|
|
|
1537
1533
|
shouldForwardProp: true,
|
|
1538
1534
|
styledComponentId: true,
|
|
1539
1535
|
target: true,
|
|
1540
|
-
withComponent: true,
|
|
1541
1536
|
});
|
|
1542
1537
|
}
|
|
1543
1538
|
return WrappedStyledComponent;
|
|
@@ -1660,10 +1655,10 @@ function createGlobalStyle(strings) {
|
|
|
1660
1655
|
var GlobalStyleComponent = function (props) {
|
|
1661
1656
|
var styleSheet = useStyleSheet();
|
|
1662
1657
|
var stylis = useStylis();
|
|
1663
|
-
var theme =
|
|
1664
|
-
var instanceRef =
|
|
1658
|
+
var theme = React.useContext(ThemeContext);
|
|
1659
|
+
var instanceRef = React.useRef(styleSheet.allocateGSInstance(styledComponentId));
|
|
1665
1660
|
var instance = instanceRef.current;
|
|
1666
|
-
if (process.env.NODE_ENV !== 'production' &&
|
|
1661
|
+
if (process.env.NODE_ENV !== 'production' && React.Children.count(props.children)) {
|
|
1667
1662
|
// eslint-disable-next-line no-console
|
|
1668
1663
|
console.warn("The global style component ".concat(styledComponentId, " was given child JSX. createGlobalStyle does not render children."));
|
|
1669
1664
|
}
|
|
@@ -1678,7 +1673,7 @@ function createGlobalStyle(strings) {
|
|
|
1678
1673
|
{
|
|
1679
1674
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
1680
1675
|
// @ts-expect-error still using React 17 types for the time being
|
|
1681
|
-
(
|
|
1676
|
+
(React.useInsertionEffect || React.useLayoutEffect)(function () {
|
|
1682
1677
|
if (!styleSheet.server) {
|
|
1683
1678
|
renderStyles(instance, props, styleSheet, theme, stylis);
|
|
1684
1679
|
return function () { return globalStyle.removeStyles(instance, styleSheet); };
|
|
@@ -1696,7 +1691,7 @@ function createGlobalStyle(strings) {
|
|
|
1696
1691
|
globalStyle.renderStyles(instance, context, styleSheet, stylis);
|
|
1697
1692
|
}
|
|
1698
1693
|
}
|
|
1699
|
-
return
|
|
1694
|
+
return React.memo(GlobalStyleComponent);
|
|
1700
1695
|
}
|
|
1701
1696
|
|
|
1702
1697
|
function keyframes(strings) {
|
|
@@ -1717,14 +1712,14 @@ function keyframes(strings) {
|
|
|
1717
1712
|
}
|
|
1718
1713
|
|
|
1719
1714
|
function withTheme(Component) {
|
|
1720
|
-
var WithTheme =
|
|
1721
|
-
var theme =
|
|
1715
|
+
var WithTheme = React.forwardRef(function (props, ref) {
|
|
1716
|
+
var theme = React.useContext(ThemeContext);
|
|
1722
1717
|
var themeProp = determineTheme(props, theme, Component.defaultProps);
|
|
1723
1718
|
if (process.env.NODE_ENV !== 'production' && themeProp === undefined) {
|
|
1724
1719
|
// eslint-disable-next-line no-console
|
|
1725
1720
|
console.warn("[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps in component class \"".concat(getComponentName(Component), "\""));
|
|
1726
1721
|
}
|
|
1727
|
-
return
|
|
1722
|
+
return React.createElement(Component, tslib.__assign({}, props, { theme: themeProp, ref: ref }));
|
|
1728
1723
|
});
|
|
1729
1724
|
WithTheme.displayName = "WithTheme(".concat(getComponentName(Component), ")");
|
|
1730
1725
|
return hoistNonReactStatics(WithTheme, Component);
|
|
@@ -1769,7 +1764,7 @@ var ServerStyleSheet = /** @class */ (function () {
|
|
|
1769
1764
|
props.nonce = nonce;
|
|
1770
1765
|
}
|
|
1771
1766
|
// v4 returned an array for this fn, so we'll do the same for v5 for backward compat
|
|
1772
|
-
return [
|
|
1767
|
+
return [React.createElement("style", tslib.__assign({}, props, { key: "sc-0-0" }))];
|
|
1773
1768
|
};
|
|
1774
1769
|
this.seal = function () {
|
|
1775
1770
|
_this.sealed = true;
|
|
@@ -1781,7 +1776,7 @@ var ServerStyleSheet = /** @class */ (function () {
|
|
|
1781
1776
|
if (this.sealed) {
|
|
1782
1777
|
throw throwStyledComponentsError(2);
|
|
1783
1778
|
}
|
|
1784
|
-
return
|
|
1779
|
+
return React.createElement(StyleSheetManager, { sheet: this.instance }, children);
|
|
1785
1780
|
};
|
|
1786
1781
|
// eslint-disable-next-line consistent-return
|
|
1787
1782
|
// @ts-expect-error alternate return types are not possible due to code transformation
|
|
@@ -1834,9 +1829,10 @@ exports.ThemeProvider = ThemeProvider;
|
|
|
1834
1829
|
exports.__PRIVATE__ = __PRIVATE__;
|
|
1835
1830
|
exports.createGlobalStyle = createGlobalStyle;
|
|
1836
1831
|
exports.css = css;
|
|
1837
|
-
exports
|
|
1832
|
+
exports.default = styled;
|
|
1838
1833
|
exports.isStyledComponent = isStyledComponent;
|
|
1839
1834
|
exports.keyframes = keyframes;
|
|
1835
|
+
exports.styled = styled;
|
|
1840
1836
|
exports.useTheme = useTheme;
|
|
1841
1837
|
exports.version = SC_VERSION;
|
|
1842
1838
|
exports.withTheme = withTheme;
|