@compiled/react 0.10.2 → 0.11.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/dist/browser/class-names/index.d.ts +11 -5
- package/dist/browser/class-names/index.js.flow +29 -20
- package/dist/browser/class-names/index.js.map +1 -1
- package/dist/browser/css/index.d.ts +3 -3
- package/dist/browser/css/index.js.flow +24 -23
- package/dist/browser/css/index.js.map +1 -1
- package/dist/browser/index.d.ts +2 -3
- package/dist/browser/index.js.flow +4 -7
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/browser/jsx/jsx-local-namespace.d.ts +2 -2
- package/dist/browser/jsx/jsx-local-namespace.js.map +1 -1
- package/dist/browser/jsx/jsx-runtime.js.map +1 -1
- package/dist/browser/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/browser/keyframes/index.d.ts +1 -1
- package/dist/browser/keyframes/index.js.flow +25 -31
- package/dist/browser/keyframes/index.js.map +1 -1
- package/dist/browser/runtime/ax.js.flow +1 -1
- package/dist/browser/runtime/ax.js.map +1 -1
- package/dist/browser/runtime/cache.js.flow +1 -1
- package/dist/browser/runtime/cache.js.map +1 -1
- package/dist/browser/runtime/css-custom-property.js.flow +1 -1
- package/dist/browser/runtime/css-custom-property.js.map +1 -1
- package/dist/browser/runtime/dev-warnings.js.flow +1 -1
- package/dist/browser/runtime/dev-warnings.js.map +1 -1
- package/dist/browser/runtime/index.js.flow +1 -1
- package/dist/browser/runtime/index.js.map +1 -1
- package/dist/browser/runtime/{is-node.d.ts → is-server-environment.d.ts} +2 -2
- package/dist/browser/runtime/is-server-environment.js +31 -0
- package/dist/{cjs/runtime/is-node.js.flow → browser/runtime/is-server-environment.js.flow} +4 -4
- package/dist/browser/runtime/is-server-environment.js.map +1 -0
- package/dist/browser/runtime/sheet.js.flow +1 -1
- package/dist/browser/runtime/sheet.js.map +1 -1
- package/dist/browser/runtime/style-cache.js +1 -1
- package/dist/browser/runtime/style-cache.js.flow +1 -1
- package/dist/browser/runtime/style-cache.js.map +1 -1
- package/dist/browser/runtime/style.js +1 -1
- package/dist/browser/runtime/style.js.flow +1 -1
- package/dist/browser/runtime/style.js.map +1 -1
- package/dist/browser/runtime/types.js.flow +2 -2
- package/dist/browser/runtime/types.js.map +1 -1
- package/dist/browser/runtime.js.flow +1 -1
- package/dist/browser/runtime.js.map +1 -1
- package/dist/browser/styled/index.d.ts +10 -23
- package/dist/browser/styled/index.js.flow +45 -46
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/browser/types.d.ts +9 -5
- package/dist/browser/types.js.flow +13 -10
- package/dist/browser/types.js.map +1 -1
- package/dist/browser/utils/error.js.flow +1 -1
- package/dist/browser/utils/error.js.map +1 -1
- package/dist/cjs/class-names/index.d.ts +11 -5
- package/dist/cjs/class-names/index.js.flow +29 -20
- package/dist/cjs/class-names/index.js.map +1 -1
- package/dist/cjs/css/index.d.ts +3 -3
- package/dist/cjs/css/index.js.flow +24 -23
- package/dist/cjs/css/index.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -3
- package/dist/cjs/index.js.flow +4 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/jsx/jsx-dev-runtime.js +5 -1
- package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/cjs/jsx/jsx-local-namespace.d.ts +2 -2
- package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -1
- package/dist/cjs/jsx/jsx-runtime.js +5 -1
- package/dist/cjs/jsx/jsx-runtime.js.map +1 -1
- package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/cjs/keyframes/index.d.ts +1 -1
- package/dist/cjs/keyframes/index.js.flow +25 -31
- package/dist/cjs/keyframes/index.js.map +1 -1
- package/dist/cjs/runtime/ax.js.flow +1 -1
- package/dist/cjs/runtime/ax.js.map +1 -1
- package/dist/cjs/runtime/cache.js.flow +1 -1
- package/dist/cjs/runtime/cache.js.map +1 -1
- package/dist/cjs/runtime/css-custom-property.js.flow +1 -1
- package/dist/cjs/runtime/css-custom-property.js.map +1 -1
- package/dist/cjs/runtime/dev-warnings.js.flow +1 -1
- package/dist/cjs/runtime/dev-warnings.js.map +1 -1
- package/dist/cjs/runtime/index.js.flow +1 -1
- package/dist/cjs/runtime/index.js.map +1 -1
- package/dist/{esm/runtime/is-node.d.ts → cjs/runtime/is-server-environment.d.ts} +2 -2
- package/dist/cjs/runtime/is-server-environment.js +35 -0
- package/dist/{esm/runtime/is-node.js.flow → cjs/runtime/is-server-environment.js.flow} +4 -4
- package/dist/cjs/runtime/is-server-environment.js.map +1 -0
- package/dist/cjs/runtime/sheet.js.flow +1 -1
- package/dist/cjs/runtime/sheet.js.map +1 -1
- package/dist/cjs/runtime/style-cache.js +10 -6
- package/dist/cjs/runtime/style-cache.js.flow +1 -1
- package/dist/cjs/runtime/style-cache.js.map +1 -1
- package/dist/cjs/runtime/style.js +7 -3
- package/dist/cjs/runtime/style.js.flow +1 -1
- package/dist/cjs/runtime/style.js.map +1 -1
- package/dist/cjs/runtime/types.js.flow +2 -2
- package/dist/cjs/runtime/types.js.map +1 -1
- package/dist/cjs/runtime.js.flow +1 -1
- package/dist/cjs/runtime.js.map +1 -1
- package/dist/cjs/styled/index.d.ts +10 -23
- package/dist/cjs/styled/index.js.flow +45 -46
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/cjs/types.d.ts +9 -5
- package/dist/cjs/types.js.flow +13 -10
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/error.js.flow +1 -1
- package/dist/cjs/utils/error.js.map +1 -1
- package/dist/esm/class-names/index.d.ts +11 -5
- package/dist/esm/class-names/index.js.flow +29 -20
- package/dist/esm/class-names/index.js.map +1 -1
- package/dist/esm/css/index.d.ts +3 -3
- package/dist/esm/css/index.js.flow +24 -23
- package/dist/esm/css/index.js.map +1 -1
- package/dist/esm/index.d.ts +2 -3
- package/dist/esm/index.js.flow +4 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/esm/jsx/jsx-local-namespace.d.ts +2 -2
- package/dist/esm/jsx/jsx-local-namespace.js.map +1 -1
- package/dist/esm/jsx/jsx-runtime.js.map +1 -1
- package/dist/esm/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/esm/keyframes/index.d.ts +1 -1
- package/dist/esm/keyframes/index.js.flow +25 -31
- package/dist/esm/keyframes/index.js.map +1 -1
- package/dist/esm/runtime/ax.js.flow +1 -1
- package/dist/esm/runtime/ax.js.map +1 -1
- package/dist/esm/runtime/cache.js.flow +1 -1
- package/dist/esm/runtime/cache.js.map +1 -1
- package/dist/esm/runtime/css-custom-property.js.flow +1 -1
- package/dist/esm/runtime/css-custom-property.js.map +1 -1
- package/dist/esm/runtime/dev-warnings.js.flow +1 -1
- package/dist/esm/runtime/dev-warnings.js.map +1 -1
- package/dist/esm/runtime/index.js.flow +1 -1
- package/dist/esm/runtime/index.js.map +1 -1
- package/dist/{cjs/runtime/is-node.d.ts → esm/runtime/is-server-environment.d.ts} +2 -2
- package/dist/esm/runtime/is-server-environment.js +31 -0
- package/dist/{browser/runtime/is-node.js.flow → esm/runtime/is-server-environment.js.flow} +4 -4
- package/dist/esm/runtime/is-server-environment.js.map +1 -0
- package/dist/esm/runtime/sheet.js.flow +1 -1
- package/dist/esm/runtime/sheet.js.map +1 -1
- package/dist/esm/runtime/style-cache.js +5 -5
- package/dist/esm/runtime/style-cache.js.flow +1 -1
- package/dist/esm/runtime/style-cache.js.map +1 -1
- package/dist/esm/runtime/style.js +2 -2
- package/dist/esm/runtime/style.js.flow +1 -1
- package/dist/esm/runtime/style.js.map +1 -1
- package/dist/esm/runtime/types.js.flow +2 -2
- package/dist/esm/runtime/types.js.map +1 -1
- package/dist/esm/runtime.js.flow +1 -1
- package/dist/esm/runtime.js.map +1 -1
- package/dist/esm/styled/index.d.ts +10 -23
- package/dist/esm/styled/index.js.flow +45 -46
- package/dist/esm/styled/index.js.map +1 -1
- package/dist/esm/types.d.ts +9 -5
- package/dist/esm/types.js.flow +13 -10
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/error.js.flow +1 -1
- package/dist/esm/utils/error.js.map +1 -1
- package/package.json +14 -12
- package/src/__tests__/browser.test.tsx +4 -0
- package/src/__tests__/{display-names.test.tsx → display-names.test.ts} +0 -0
- package/src/__tests__/server-side-hydrate.test.tsx +2 -2
- package/src/class-names/__tests__/types.test.js.flow +10 -3
- package/src/class-names/index.js.flow +29 -20
- package/src/class-names/{index.tsx → index.ts} +15 -9
- package/src/css/__tests__/types.test.js.flow +25 -0
- package/src/css/index.js.flow +24 -23
- package/src/css/{index.tsx → index.ts} +9 -14
- package/src/index.js.flow +4 -7
- package/src/{index.tsx → index.ts} +3 -4
- package/src/jsx/{jsx-dev-runtime.tsx → jsx-dev-runtime.ts} +0 -0
- package/src/jsx/{jsx-local-namespace.tsx → jsx-local-namespace.ts} +2 -2
- package/src/jsx/{jsx-runtime.tsx → jsx-runtime.ts} +0 -0
- package/src/keyframes/__fixtures__/{index.tsx → index.ts} +0 -0
- package/src/keyframes/__tests__/index.test.tsx +4 -0
- package/src/keyframes/index.js.flow +25 -31
- package/src/keyframes/{index.tsx → index.ts} +1 -1
- package/src/runtime/__perf__/cs.test.tsx +137 -92
- package/src/runtime/__perf__/utils/cs.tsx +15 -15
- package/src/runtime/__perf__/utils/{sheet.tsx → sheet.ts} +0 -0
- package/src/runtime/__tests__/{ax.test.tsx → ax.test.ts} +0 -0
- package/src/runtime/__tests__/{css-custom-property.test.tsx → css-custom-property.test.ts} +0 -0
- package/src/runtime/__tests__/style.test.tsx +4 -0
- package/src/runtime/ax.js.flow +1 -1
- package/src/runtime/{ax.tsx → ax.ts} +0 -0
- package/src/runtime/cache.js.flow +1 -1
- package/src/runtime/{cache.tsx → cache.ts} +0 -0
- package/src/runtime/css-custom-property.js.flow +1 -1
- package/src/runtime/{css-custom-property.tsx → css-custom-property.ts} +0 -0
- package/src/runtime/dev-warnings.js.flow +1 -1
- package/src/runtime/{dev-warnings.tsx → dev-warnings.ts} +0 -0
- package/src/runtime/index.js.flow +1 -1
- package/src/runtime/{index.tsx → index.ts} +0 -0
- package/src/runtime/{is-node.js.flow → is-server-environment.js.flow} +4 -4
- package/src/runtime/is-server-environment.ts +29 -0
- package/src/runtime/sheet.js.flow +1 -1
- package/src/runtime/{sheet.tsx → sheet.ts} +0 -0
- package/src/runtime/style-cache.js.flow +1 -1
- package/src/runtime/style-cache.tsx +5 -5
- package/src/runtime/style.js.flow +1 -1
- package/src/runtime/style.tsx +2 -2
- package/src/runtime/types.js.flow +2 -2
- package/src/runtime/{types.tsx → types.ts} +0 -0
- package/src/runtime.js.flow +1 -1
- package/src/{runtime.tsx → runtime.ts} +0 -0
- package/src/styled/__tests__/index.test.tsx +1 -1
- package/src/styled/__tests__/types.test.js.flow +65 -11
- package/src/styled/index.js.flow +45 -46
- package/src/styled/index.ts +94 -0
- package/src/types.js.flow +13 -10
- package/src/types.ts +35 -0
- package/src/utils/error.js.flow +1 -1
- package/src/utils/{error.tsx → error.ts} +0 -0
- package/dist/browser/runtime/is-node.js +0 -16
- package/dist/browser/runtime/is-node.js.map +0 -1
- package/dist/cjs/runtime/is-node.js +0 -20
- package/dist/cjs/runtime/is-node.js.map +0 -1
- package/dist/esm/runtime/is-node.js +0 -16
- package/dist/esm/runtime/is-node.js.map +0 -1
- package/src/runtime/is-node.tsx +0 -15
- package/src/styled/index.tsx +0 -112
- package/src/types.tsx +0 -27
|
@@ -15,3 +15,28 @@ import { css } from '@compiled/react';
|
|
|
15
15
|
const styles = css({ color: 'red' });
|
|
16
16
|
return <div css={styles}>red text</div>;
|
|
17
17
|
};
|
|
18
|
+
|
|
19
|
+
// Object call with function call
|
|
20
|
+
(): React$Element<'div'> => {
|
|
21
|
+
const styles = css({
|
|
22
|
+
backgroundColor: token('elevation.surface', 'white'),
|
|
23
|
+
zIndex: layers.modal(),
|
|
24
|
+
});
|
|
25
|
+
return <div css={styles}>red text</div>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Media query selector
|
|
29
|
+
css({
|
|
30
|
+
/* Style only for Google Chrome */
|
|
31
|
+
'@media screen and (-webkit-min-device-pixel-ratio: 0)': {
|
|
32
|
+
wordBreak: 'break-word',
|
|
33
|
+
},
|
|
34
|
+
/* Style only for Safari */
|
|
35
|
+
'@media screen and (-webkit-transition)': {
|
|
36
|
+
wordBreak: 'break-word',
|
|
37
|
+
},
|
|
38
|
+
/* Style only for Mozilla Firefox */
|
|
39
|
+
'@-moz-document url-prefix()': {
|
|
40
|
+
overflowWrap: 'anywhere',
|
|
41
|
+
},
|
|
42
|
+
});
|
package/src/css/index.js.flow
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for index
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.17.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
7
|
+
import type { CSSProps, CssObject, CssFunction } from '../types';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* ## CSS
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* css
|
|
13
|
-
* ```
|
|
11
|
+
* Define styles that are statically typed and useable with other Compiled APIs.
|
|
12
|
+
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-css).
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
declare export default function css<T>(
|
|
21
|
-
_css: $ReadOnlyArray<string>,
|
|
22
|
-
..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
|
|
23
|
-
): CSSProps;
|
|
24
|
-
/**
|
|
25
|
-
* Create styles that can be re-used between components with an object
|
|
14
|
+
* ### Style with objects
|
|
15
|
+
* @example ```
|
|
16
|
+
* const redText = css({
|
|
17
|
+
* color: 'red',
|
|
18
|
+
* });
|
|
26
19
|
*
|
|
20
|
+
* <div css={redText} />
|
|
27
21
|
* ```
|
|
28
|
-
* css({ color: 'red' });
|
|
29
|
-
* ```
|
|
30
22
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
23
|
+
* ### Style with template literals
|
|
24
|
+
* @example ```
|
|
25
|
+
* const redText = css`
|
|
26
|
+
* color: red;
|
|
27
|
+
* `;
|
|
28
|
+
*
|
|
29
|
+
* <div css={redText} />
|
|
30
|
+
* ```
|
|
34
31
|
*/
|
|
35
|
-
declare export default function css(
|
|
32
|
+
declare export default function css<TProps>(
|
|
33
|
+
styles: $ReadOnlyArray<string>,
|
|
34
|
+
...interpolations: CssFunction<TProps>[]
|
|
35
|
+
): CSSProps<TProps>;
|
|
36
|
+
declare export default function css<T>(styles: CssObject<T> | CssObject<T>[]): CSSProps<T>;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
AnyKeyCssProps,
|
|
5
|
-
BasicTemplateInterpolations,
|
|
6
|
-
CSSProps,
|
|
7
|
-
FunctionInterpolation,
|
|
8
|
-
} from '../types';
|
|
3
|
+
import type { CSSProps, CssObject, CssFunction } from '../types';
|
|
9
4
|
import { createSetupError } from '../utils/error';
|
|
10
5
|
|
|
11
6
|
/**
|
|
@@ -36,16 +31,16 @@ import { createSetupError } from '../utils/error';
|
|
|
36
31
|
* <div css={redText} />
|
|
37
32
|
* ```
|
|
38
33
|
*/
|
|
39
|
-
export default function css<
|
|
34
|
+
export default function css<TProps = unknown>(
|
|
40
35
|
styles: TemplateStringsArray,
|
|
41
|
-
...interpolations:
|
|
42
|
-
): CSSProps
|
|
36
|
+
...interpolations: CssFunction<TProps>[]
|
|
37
|
+
): CSSProps<TProps>;
|
|
43
38
|
|
|
44
|
-
export default function css(styles:
|
|
39
|
+
export default function css<T = unknown>(styles: CssObject<T> | CssObject<T>[]): CSSProps<T>;
|
|
45
40
|
|
|
46
|
-
export default function css<T =
|
|
47
|
-
_styles: TemplateStringsArray |
|
|
48
|
-
..._interpolations:
|
|
49
|
-
): CSSProps {
|
|
41
|
+
export default function css<T = unknown>(
|
|
42
|
+
_styles: TemplateStringsArray | CssObject<T> | CssObject<T>[],
|
|
43
|
+
..._interpolations: CssFunction[]
|
|
44
|
+
): CSSProps<T> {
|
|
50
45
|
throw createSetupError();
|
|
51
46
|
}
|
package/src/index.js.flow
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Flowtype definitions for runtime
|
|
2
|
+
* Flowtype definitions for index
|
|
5
3
|
* Generated by Flowgen from a Typescript Definition
|
|
6
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.17.0
|
|
7
5
|
* @flow
|
|
8
6
|
*/
|
|
9
|
-
import type { CSSProps,
|
|
7
|
+
import type { CssFunction, CSSProps, CssType } from './types';
|
|
8
|
+
export type { CSSProps, CssFunction, CssType };
|
|
10
9
|
declare export { keyframes } from './keyframes';
|
|
11
10
|
declare export { styled } from './styled';
|
|
12
11
|
declare export { ClassNames } from './class-names';
|
|
13
12
|
declare export { default as css } from './css';
|
|
14
|
-
export type { CssFunction, CSSProps };
|
|
15
|
-
export type { CssObject } from './styled';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
|
|
3
3
|
import type { CompiledJSX } from './jsx/jsx-local-namespace';
|
|
4
|
-
import type { CssFunction, CSSProps } from './types';
|
|
4
|
+
import type { CssFunction, CSSProps, CssType } from './types';
|
|
5
|
+
|
|
6
|
+
export type { CSSProps, CssFunction, CssType };
|
|
5
7
|
|
|
6
8
|
export { keyframes } from './keyframes';
|
|
7
9
|
export { styled } from './styled';
|
|
@@ -12,9 +14,6 @@ export { default as css } from './css';
|
|
|
12
14
|
// Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
|
|
13
15
|
export const jsx = createElement;
|
|
14
16
|
|
|
15
|
-
export type { CssFunction, CSSProps };
|
|
16
|
-
export type { CssObject } from './styled';
|
|
17
|
-
|
|
18
17
|
export namespace jsx {
|
|
19
18
|
export namespace JSX {
|
|
20
19
|
export type Element = CompiledJSX.Element;
|
|
File without changes
|
|
@@ -41,7 +41,7 @@ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps
|
|
|
41
41
|
* />
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
css?: CssFunction | CssFunction[];
|
|
44
|
+
css?: CssFunction<void> | CssFunction<void>[];
|
|
45
45
|
}
|
|
46
46
|
: // eslint-disable-next-line @typescript-eslint/ban-types
|
|
47
47
|
{}
|
|
@@ -69,7 +69,7 @@ export namespace CompiledJSX {
|
|
|
69
69
|
export type IntrinsicClassAttributes<T> = ReactJSXIntrinsicClassAttributes<T>;
|
|
70
70
|
export type IntrinsicElements = {
|
|
71
71
|
[K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
|
|
72
|
-
css?: CssFunction | CssFunction[];
|
|
72
|
+
css?: CssFunction<void> | CssFunction<void>[];
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -16,6 +16,10 @@ const getKeyframe = (name: string) => {
|
|
|
16
16
|
.join('\n');
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
jest.mock('../../runtime/is-server-environment', () => ({
|
|
20
|
+
isServerEnvironment: () => false,
|
|
21
|
+
}));
|
|
22
|
+
|
|
19
23
|
describe('keyframes', () => {
|
|
20
24
|
beforeAll(() => {
|
|
21
25
|
process.env.CACHE = 'false';
|
|
@@ -1,33 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for index
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.17.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
import type { BasicTemplateInterpolations, CSSProps } from '../types';
|
|
8
|
-
export type KeyframeSteps = string | { [key: string]: CSSProps
|
|
8
|
+
export type KeyframeSteps = string | { [key: string]: CSSProps<void> };
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* ## Keyframes
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* from { opacity: 1; }
|
|
15
|
-
* to { opacity: 0; }
|
|
16
|
-
* `;
|
|
17
|
-
* ```
|
|
18
|
-
* @param _strings The input string values
|
|
19
|
-
* @param _interpolations The arguments used in the expression
|
|
20
|
-
*/
|
|
21
|
-
declare export function keyframes(
|
|
22
|
-
_strings: $ReadOnlyArray<string>,
|
|
23
|
-
..._interpolations: BasicTemplateInterpolations[]
|
|
24
|
-
): string;
|
|
25
|
-
/**
|
|
26
|
-
* Create keyframes using:
|
|
12
|
+
* Define keyframes to be used in a [CSS animation](https://developer.mozilla.org/en-US/docs/Web/CSS/animation).
|
|
13
|
+
* For further details [read the API documentation](https://compiledcssinjs.com/docs/api-keyframes).
|
|
27
14
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* ```
|
|
15
|
+
* ### Style with objects
|
|
16
|
+
* @example ```
|
|
31
17
|
* const fadeOut = keyframes({
|
|
32
18
|
* from: {
|
|
33
19
|
* opacity: 1,
|
|
@@ -36,19 +22,27 @@ declare export function keyframes(
|
|
|
36
22
|
* opacity: 0,
|
|
37
23
|
* },
|
|
38
24
|
* });
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* 2. A string
|
|
42
25
|
*
|
|
43
|
-
*
|
|
44
|
-
* const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
|
|
26
|
+
* <div css={{ animation: `${fadeOut} 2s` }} />
|
|
45
27
|
* ```
|
|
46
28
|
*
|
|
47
|
-
*
|
|
29
|
+
* ### Style with template literals
|
|
30
|
+
* @example ```
|
|
31
|
+
* const fadeOut = keyframes`
|
|
32
|
+
* from {
|
|
33
|
+
* opacity: 1;
|
|
34
|
+
* }
|
|
48
35
|
*
|
|
36
|
+
* to {
|
|
37
|
+
* opacity: 0;
|
|
38
|
+
* }
|
|
39
|
+
* `;
|
|
40
|
+
*
|
|
41
|
+
* <div css={{ animation: `${fadeOut} 2s` }} />
|
|
49
42
|
* ```
|
|
50
|
-
* const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
|
|
51
|
-
* ```
|
|
52
|
-
* @param _steps The waypoints along the animation sequence
|
|
53
43
|
*/
|
|
54
|
-
declare export function keyframes(
|
|
44
|
+
declare export function keyframes(steps: KeyframeSteps): string;
|
|
45
|
+
declare export function keyframes(
|
|
46
|
+
strings: $ReadOnlyArray<string>,
|
|
47
|
+
...interpolations: BasicTemplateInterpolations[]
|
|
48
|
+
): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BasicTemplateInterpolations, CSSProps } from '../types';
|
|
2
2
|
import { createSetupError } from '../utils/error';
|
|
3
3
|
|
|
4
|
-
export type KeyframeSteps = string | Record<string, CSSProps
|
|
4
|
+
export type KeyframeSteps = string | Record<string, CSSProps<void>>;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* ## Keyframes
|
|
@@ -1,111 +1,156 @@
|
|
|
1
1
|
import { runBenchmark } from '@compiled/benchmark';
|
|
2
|
+
import { JSDOM } from 'jsdom';
|
|
2
3
|
import * as React from 'react';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { render } from 'react-dom';
|
|
3
6
|
import { renderToString } from 'react-dom/server';
|
|
4
7
|
|
|
5
8
|
import { CC, CS } from '../index';
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
const MemoCS = memo(CS, () => true);
|
|
11
|
+
|
|
12
|
+
import { StyleBucketFromArray, StyleBucketFromString } from './utils/cs';
|
|
8
13
|
|
|
9
14
|
describe('CS benchmark', () => {
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
describe.each(['server', 'client'])('on the %s', (env) => {
|
|
16
|
+
const document = globalThis.document;
|
|
17
|
+
const window = globalThis.window;
|
|
18
|
+
|
|
19
|
+
beforeAll(() => {
|
|
20
|
+
if (env === 'server') {
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
delete globalThis.document;
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
delete globalThis.window;
|
|
25
|
+
} else {
|
|
26
|
+
const dom = new JSDOM('<div id="root"></div>');
|
|
27
|
+
globalThis.document = dom.window.document;
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
globalThis.window = dom.window;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterAll(() => {
|
|
34
|
+
globalThis.document = document;
|
|
35
|
+
globalThis.window = window;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const fastest =
|
|
39
|
+
env === 'server'
|
|
40
|
+
? ['StyleBucketFromArray', 'StyleBucketFromString']
|
|
41
|
+
: ['MemoCS (1 array element)', 'MemoCS (n array elements)'];
|
|
24
42
|
|
|
25
|
-
|
|
43
|
+
it(`completes with [${fastest.join(', ')}] as the fastest`, async () => {
|
|
44
|
+
const stylesArr = [
|
|
45
|
+
'._s7n4jp4b{vertical-align:top}',
|
|
46
|
+
'._1reo15vq{overflow-x:hidden}',
|
|
47
|
+
'._18m915vq{overflow-y:hidden}',
|
|
48
|
+
'._1bto1l2s{text-overflow:ellipsis}',
|
|
49
|
+
'._o5721q9c{white-space:nowrap}',
|
|
50
|
+
'._ca0qidpf{padding-top:0}',
|
|
51
|
+
'._u5f31y44{padding-right:4px}',
|
|
52
|
+
'._n3tdidpf{padding-bottom:0}',
|
|
53
|
+
'._19bv1y44{padding-left:4px}',
|
|
54
|
+
'._p12f12xx{max-width:100px}',
|
|
55
|
+
'._1bsb1osq{width:100%}',
|
|
56
|
+
];
|
|
26
57
|
|
|
27
|
-
|
|
28
|
-
'_bfhk1jys',
|
|
29
|
-
'_2rko1l7b',
|
|
30
|
-
'_vchhusvi',
|
|
31
|
-
'_syaz4rde',
|
|
32
|
-
'_1e0c1o8l',
|
|
33
|
-
'_1wyb1skh',
|
|
34
|
-
'_k48p1fw0',
|
|
35
|
-
'_vwz4kb7n',
|
|
36
|
-
'_p12f1osq',
|
|
37
|
-
'_ca0qyh40',
|
|
38
|
-
'_u5f3idpf',
|
|
39
|
-
'_n3td1l7b',
|
|
40
|
-
'_19bvidpf',
|
|
41
|
-
'_1p1dangw',
|
|
42
|
-
'_s7n41q9y',
|
|
43
|
-
].join(' ');
|
|
58
|
+
const stylesStr = stylesArr.join('');
|
|
44
59
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
'--_kmurgp': 'rgb(0, 102, 68)',
|
|
48
|
-
} as any;
|
|
60
|
+
const className = stylesArr.map((rule) => rule.slice(1, 10)).join(' ');
|
|
61
|
+
const nonce = 'k0Mp1lEd';
|
|
49
62
|
|
|
50
|
-
|
|
63
|
+
const renderJSX =
|
|
64
|
+
env === 'server'
|
|
65
|
+
? (jsx: (key: number) => JSX.Element) => {
|
|
66
|
+
renderToString(<>{Array.from({ length: 10 }).map((_, i) => jsx(i))}</>);
|
|
67
|
+
}
|
|
68
|
+
: (jsx: (key: number) => JSX.Element) => {
|
|
69
|
+
render(
|
|
70
|
+
<>{Array.from({ length: 10 }).map((_, i) => jsx(i))}</>,
|
|
71
|
+
globalThis.document.getElementById('root')
|
|
72
|
+
);
|
|
73
|
+
};
|
|
51
74
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
75
|
+
const tests = [
|
|
76
|
+
{
|
|
77
|
+
name: 'CS (1 array element)',
|
|
78
|
+
fn: () => {
|
|
79
|
+
renderJSX((key) => (
|
|
80
|
+
<CC key={`cs1-${key}`}>
|
|
81
|
+
<CS nonce={nonce}>{[stylesStr]}</CS>
|
|
82
|
+
<div className={className} />
|
|
83
|
+
</CC>
|
|
84
|
+
));
|
|
85
|
+
},
|
|
64
86
|
},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
</CC>
|
|
76
|
-
);
|
|
87
|
+
{
|
|
88
|
+
name: 'CS (n array elements)',
|
|
89
|
+
fn: () => {
|
|
90
|
+
renderJSX((key) => (
|
|
91
|
+
<CC key={`csn-${key}`}>
|
|
92
|
+
<CS nonce={nonce}>{stylesArr}</CS>
|
|
93
|
+
<div className={className} />
|
|
94
|
+
</CC>
|
|
95
|
+
));
|
|
96
|
+
},
|
|
77
97
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
</CC>
|
|
89
|
-
);
|
|
98
|
+
{
|
|
99
|
+
name: 'MemoCS (1 array element)',
|
|
100
|
+
fn: () => {
|
|
101
|
+
renderJSX((key) => (
|
|
102
|
+
<CC key={`memo-cs1-${key}`}>
|
|
103
|
+
<MemoCS nonce={nonce}>{[stylesStr]}</MemoCS>
|
|
104
|
+
<div className={className} />
|
|
105
|
+
</CC>
|
|
106
|
+
));
|
|
107
|
+
},
|
|
90
108
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
</CC>
|
|
102
|
-
);
|
|
109
|
+
{
|
|
110
|
+
name: 'MemoCS (n array elements)',
|
|
111
|
+
fn: () => {
|
|
112
|
+
renderJSX((key) => (
|
|
113
|
+
<CC key={`memo-csn-${key}`}>
|
|
114
|
+
<MemoCS nonce={nonce}>{stylesArr}</MemoCS>
|
|
115
|
+
<div className={className} />
|
|
116
|
+
</CC>
|
|
117
|
+
));
|
|
118
|
+
},
|
|
103
119
|
},
|
|
104
|
-
|
|
105
|
-
|
|
120
|
+
...(env === 'server'
|
|
121
|
+
? [
|
|
122
|
+
{
|
|
123
|
+
name: 'StyleBucketFromArray',
|
|
124
|
+
fn: () => {
|
|
125
|
+
renderJSX((key) => (
|
|
126
|
+
<CC key={`sbfa-${key}`}>
|
|
127
|
+
<StyleBucketFromArray nonce={nonce}>{stylesArr}</StyleBucketFromArray>
|
|
128
|
+
<div className={className} />
|
|
129
|
+
</CC>
|
|
130
|
+
));
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'StyleBucketFromString',
|
|
135
|
+
fn: () => {
|
|
136
|
+
renderJSX((key) => (
|
|
137
|
+
<CC key={`sbfs-${key}`}>
|
|
138
|
+
<StyleBucketFromString nonce={nonce}>{stylesStr}</StyleBucketFromString>
|
|
139
|
+
<div className={className} />
|
|
140
|
+
</CC>
|
|
141
|
+
));
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
]
|
|
145
|
+
: []),
|
|
146
|
+
];
|
|
106
147
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
148
|
+
const benchmark = await runBenchmark('CS', tests);
|
|
149
|
+
|
|
150
|
+
const slowest = tests.map((t) => t.name).filter((n) => !fastest.includes(n));
|
|
151
|
+
for (const name of slowest) {
|
|
152
|
+
expect(benchmark.fastest).not.toContain(name);
|
|
153
|
+
}
|
|
154
|
+
}, 60000);
|
|
155
|
+
});
|
|
111
156
|
});
|
|
@@ -2,20 +2,17 @@ import React, { createContext, useContext } from 'react';
|
|
|
2
2
|
|
|
3
3
|
const Cache = createContext<Record<string, true> | null>(null);
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type StyleStrProps = {
|
|
10
|
-
children: string;
|
|
5
|
+
export type StyleBucketFromArrayProps = {
|
|
6
|
+
children: string[];
|
|
11
7
|
nonce: string;
|
|
12
8
|
};
|
|
13
9
|
|
|
14
|
-
export function
|
|
15
|
-
|
|
10
|
+
export function StyleBucketFromArray({
|
|
11
|
+
children: sheets,
|
|
12
|
+
nonce,
|
|
13
|
+
}: StyleBucketFromArrayProps): JSX.Element | null {
|
|
14
|
+
const inserted = useContext(Cache) || {};
|
|
16
15
|
|
|
17
|
-
// The following code will not exist in the browser bundle.
|
|
18
|
-
const sheets = children.split('.');
|
|
19
16
|
let toInsert = '';
|
|
20
17
|
|
|
21
18
|
for (let i = 0; i < sheets.length; i++) {
|
|
@@ -33,15 +30,18 @@ export function StyleStr({ children, nonce }: StyleStrProps): JSX.Element | null
|
|
|
33
30
|
return <style nonce={nonce}>{toInsert}</style>;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
export type
|
|
37
|
-
children: string
|
|
33
|
+
export type StyleBucketFromStringProps = {
|
|
34
|
+
children: string;
|
|
38
35
|
nonce: string;
|
|
39
36
|
};
|
|
40
37
|
|
|
41
|
-
export function
|
|
42
|
-
|
|
38
|
+
export function StyleBucketFromString({
|
|
39
|
+
children,
|
|
40
|
+
nonce,
|
|
41
|
+
}: StyleBucketFromStringProps): JSX.Element | null {
|
|
42
|
+
const inserted = useContext(Cache) || {};
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
const sheets = children.split('.');
|
|
45
45
|
let toInsert = '';
|
|
46
46
|
|
|
47
47
|
for (let i = 0; i < sheets.length; i++) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -2,6 +2,10 @@ import { render } from '@testing-library/react';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import type { ComponentType } from 'react';
|
|
4
4
|
|
|
5
|
+
jest.mock('../is-server-environment', () => ({
|
|
6
|
+
isServerEnvironment: () => false,
|
|
7
|
+
}));
|
|
8
|
+
|
|
5
9
|
describe('<Style />', () => {
|
|
6
10
|
let consoleErrorSpy: jest.SpyInstance;
|
|
7
11
|
|
package/src/runtime/ax.js.flow
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|