@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.
Files changed (219) hide show
  1. package/dist/browser/class-names/index.d.ts +11 -5
  2. package/dist/browser/class-names/index.js.flow +29 -20
  3. package/dist/browser/class-names/index.js.map +1 -1
  4. package/dist/browser/css/index.d.ts +3 -3
  5. package/dist/browser/css/index.js.flow +24 -23
  6. package/dist/browser/css/index.js.map +1 -1
  7. package/dist/browser/index.d.ts +2 -3
  8. package/dist/browser/index.js.flow +4 -7
  9. package/dist/browser/index.js.map +1 -1
  10. package/dist/browser/jsx/jsx-dev-runtime.js.map +1 -1
  11. package/dist/browser/jsx/jsx-local-namespace.d.ts +2 -2
  12. package/dist/browser/jsx/jsx-local-namespace.js.map +1 -1
  13. package/dist/browser/jsx/jsx-runtime.js.map +1 -1
  14. package/dist/browser/keyframes/__fixtures__/index.js.map +1 -1
  15. package/dist/browser/keyframes/index.d.ts +1 -1
  16. package/dist/browser/keyframes/index.js.flow +25 -31
  17. package/dist/browser/keyframes/index.js.map +1 -1
  18. package/dist/browser/runtime/ax.js.flow +1 -1
  19. package/dist/browser/runtime/ax.js.map +1 -1
  20. package/dist/browser/runtime/cache.js.flow +1 -1
  21. package/dist/browser/runtime/cache.js.map +1 -1
  22. package/dist/browser/runtime/css-custom-property.js.flow +1 -1
  23. package/dist/browser/runtime/css-custom-property.js.map +1 -1
  24. package/dist/browser/runtime/dev-warnings.js.flow +1 -1
  25. package/dist/browser/runtime/dev-warnings.js.map +1 -1
  26. package/dist/browser/runtime/index.js.flow +1 -1
  27. package/dist/browser/runtime/index.js.map +1 -1
  28. package/dist/browser/runtime/{is-node.d.ts → is-server-environment.d.ts} +2 -2
  29. package/dist/browser/runtime/is-server-environment.js +31 -0
  30. package/dist/{cjs/runtime/is-node.js.flow → browser/runtime/is-server-environment.js.flow} +4 -4
  31. package/dist/browser/runtime/is-server-environment.js.map +1 -0
  32. package/dist/browser/runtime/sheet.js.flow +1 -1
  33. package/dist/browser/runtime/sheet.js.map +1 -1
  34. package/dist/browser/runtime/style-cache.js +1 -1
  35. package/dist/browser/runtime/style-cache.js.flow +1 -1
  36. package/dist/browser/runtime/style-cache.js.map +1 -1
  37. package/dist/browser/runtime/style.js +1 -1
  38. package/dist/browser/runtime/style.js.flow +1 -1
  39. package/dist/browser/runtime/style.js.map +1 -1
  40. package/dist/browser/runtime/types.js.flow +2 -2
  41. package/dist/browser/runtime/types.js.map +1 -1
  42. package/dist/browser/runtime.js.flow +1 -1
  43. package/dist/browser/runtime.js.map +1 -1
  44. package/dist/browser/styled/index.d.ts +10 -23
  45. package/dist/browser/styled/index.js.flow +45 -46
  46. package/dist/browser/styled/index.js.map +1 -1
  47. package/dist/browser/types.d.ts +9 -5
  48. package/dist/browser/types.js.flow +13 -10
  49. package/dist/browser/types.js.map +1 -1
  50. package/dist/browser/utils/error.js.flow +1 -1
  51. package/dist/browser/utils/error.js.map +1 -1
  52. package/dist/cjs/class-names/index.d.ts +11 -5
  53. package/dist/cjs/class-names/index.js.flow +29 -20
  54. package/dist/cjs/class-names/index.js.map +1 -1
  55. package/dist/cjs/css/index.d.ts +3 -3
  56. package/dist/cjs/css/index.js.flow +24 -23
  57. package/dist/cjs/css/index.js.map +1 -1
  58. package/dist/cjs/index.d.ts +2 -3
  59. package/dist/cjs/index.js.flow +4 -7
  60. package/dist/cjs/index.js.map +1 -1
  61. package/dist/cjs/jsx/jsx-dev-runtime.js +5 -1
  62. package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -1
  63. package/dist/cjs/jsx/jsx-local-namespace.d.ts +2 -2
  64. package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -1
  65. package/dist/cjs/jsx/jsx-runtime.js +5 -1
  66. package/dist/cjs/jsx/jsx-runtime.js.map +1 -1
  67. package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -1
  68. package/dist/cjs/keyframes/index.d.ts +1 -1
  69. package/dist/cjs/keyframes/index.js.flow +25 -31
  70. package/dist/cjs/keyframes/index.js.map +1 -1
  71. package/dist/cjs/runtime/ax.js.flow +1 -1
  72. package/dist/cjs/runtime/ax.js.map +1 -1
  73. package/dist/cjs/runtime/cache.js.flow +1 -1
  74. package/dist/cjs/runtime/cache.js.map +1 -1
  75. package/dist/cjs/runtime/css-custom-property.js.flow +1 -1
  76. package/dist/cjs/runtime/css-custom-property.js.map +1 -1
  77. package/dist/cjs/runtime/dev-warnings.js.flow +1 -1
  78. package/dist/cjs/runtime/dev-warnings.js.map +1 -1
  79. package/dist/cjs/runtime/index.js.flow +1 -1
  80. package/dist/cjs/runtime/index.js.map +1 -1
  81. package/dist/{esm/runtime/is-node.d.ts → cjs/runtime/is-server-environment.d.ts} +2 -2
  82. package/dist/cjs/runtime/is-server-environment.js +35 -0
  83. package/dist/{esm/runtime/is-node.js.flow → cjs/runtime/is-server-environment.js.flow} +4 -4
  84. package/dist/cjs/runtime/is-server-environment.js.map +1 -0
  85. package/dist/cjs/runtime/sheet.js.flow +1 -1
  86. package/dist/cjs/runtime/sheet.js.map +1 -1
  87. package/dist/cjs/runtime/style-cache.js +10 -6
  88. package/dist/cjs/runtime/style-cache.js.flow +1 -1
  89. package/dist/cjs/runtime/style-cache.js.map +1 -1
  90. package/dist/cjs/runtime/style.js +7 -3
  91. package/dist/cjs/runtime/style.js.flow +1 -1
  92. package/dist/cjs/runtime/style.js.map +1 -1
  93. package/dist/cjs/runtime/types.js.flow +2 -2
  94. package/dist/cjs/runtime/types.js.map +1 -1
  95. package/dist/cjs/runtime.js.flow +1 -1
  96. package/dist/cjs/runtime.js.map +1 -1
  97. package/dist/cjs/styled/index.d.ts +10 -23
  98. package/dist/cjs/styled/index.js.flow +45 -46
  99. package/dist/cjs/styled/index.js.map +1 -1
  100. package/dist/cjs/types.d.ts +9 -5
  101. package/dist/cjs/types.js.flow +13 -10
  102. package/dist/cjs/types.js.map +1 -1
  103. package/dist/cjs/utils/error.js.flow +1 -1
  104. package/dist/cjs/utils/error.js.map +1 -1
  105. package/dist/esm/class-names/index.d.ts +11 -5
  106. package/dist/esm/class-names/index.js.flow +29 -20
  107. package/dist/esm/class-names/index.js.map +1 -1
  108. package/dist/esm/css/index.d.ts +3 -3
  109. package/dist/esm/css/index.js.flow +24 -23
  110. package/dist/esm/css/index.js.map +1 -1
  111. package/dist/esm/index.d.ts +2 -3
  112. package/dist/esm/index.js.flow +4 -7
  113. package/dist/esm/index.js.map +1 -1
  114. package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -1
  115. package/dist/esm/jsx/jsx-local-namespace.d.ts +2 -2
  116. package/dist/esm/jsx/jsx-local-namespace.js.map +1 -1
  117. package/dist/esm/jsx/jsx-runtime.js.map +1 -1
  118. package/dist/esm/keyframes/__fixtures__/index.js.map +1 -1
  119. package/dist/esm/keyframes/index.d.ts +1 -1
  120. package/dist/esm/keyframes/index.js.flow +25 -31
  121. package/dist/esm/keyframes/index.js.map +1 -1
  122. package/dist/esm/runtime/ax.js.flow +1 -1
  123. package/dist/esm/runtime/ax.js.map +1 -1
  124. package/dist/esm/runtime/cache.js.flow +1 -1
  125. package/dist/esm/runtime/cache.js.map +1 -1
  126. package/dist/esm/runtime/css-custom-property.js.flow +1 -1
  127. package/dist/esm/runtime/css-custom-property.js.map +1 -1
  128. package/dist/esm/runtime/dev-warnings.js.flow +1 -1
  129. package/dist/esm/runtime/dev-warnings.js.map +1 -1
  130. package/dist/esm/runtime/index.js.flow +1 -1
  131. package/dist/esm/runtime/index.js.map +1 -1
  132. package/dist/{cjs/runtime/is-node.d.ts → esm/runtime/is-server-environment.d.ts} +2 -2
  133. package/dist/esm/runtime/is-server-environment.js +31 -0
  134. package/dist/{browser/runtime/is-node.js.flow → esm/runtime/is-server-environment.js.flow} +4 -4
  135. package/dist/esm/runtime/is-server-environment.js.map +1 -0
  136. package/dist/esm/runtime/sheet.js.flow +1 -1
  137. package/dist/esm/runtime/sheet.js.map +1 -1
  138. package/dist/esm/runtime/style-cache.js +5 -5
  139. package/dist/esm/runtime/style-cache.js.flow +1 -1
  140. package/dist/esm/runtime/style-cache.js.map +1 -1
  141. package/dist/esm/runtime/style.js +2 -2
  142. package/dist/esm/runtime/style.js.flow +1 -1
  143. package/dist/esm/runtime/style.js.map +1 -1
  144. package/dist/esm/runtime/types.js.flow +2 -2
  145. package/dist/esm/runtime/types.js.map +1 -1
  146. package/dist/esm/runtime.js.flow +1 -1
  147. package/dist/esm/runtime.js.map +1 -1
  148. package/dist/esm/styled/index.d.ts +10 -23
  149. package/dist/esm/styled/index.js.flow +45 -46
  150. package/dist/esm/styled/index.js.map +1 -1
  151. package/dist/esm/types.d.ts +9 -5
  152. package/dist/esm/types.js.flow +13 -10
  153. package/dist/esm/types.js.map +1 -1
  154. package/dist/esm/utils/error.js.flow +1 -1
  155. package/dist/esm/utils/error.js.map +1 -1
  156. package/package.json +14 -12
  157. package/src/__tests__/browser.test.tsx +4 -0
  158. package/src/__tests__/{display-names.test.tsx → display-names.test.ts} +0 -0
  159. package/src/__tests__/server-side-hydrate.test.tsx +2 -2
  160. package/src/class-names/__tests__/types.test.js.flow +10 -3
  161. package/src/class-names/index.js.flow +29 -20
  162. package/src/class-names/{index.tsx → index.ts} +15 -9
  163. package/src/css/__tests__/types.test.js.flow +25 -0
  164. package/src/css/index.js.flow +24 -23
  165. package/src/css/{index.tsx → index.ts} +9 -14
  166. package/src/index.js.flow +4 -7
  167. package/src/{index.tsx → index.ts} +3 -4
  168. package/src/jsx/{jsx-dev-runtime.tsx → jsx-dev-runtime.ts} +0 -0
  169. package/src/jsx/{jsx-local-namespace.tsx → jsx-local-namespace.ts} +2 -2
  170. package/src/jsx/{jsx-runtime.tsx → jsx-runtime.ts} +0 -0
  171. package/src/keyframes/__fixtures__/{index.tsx → index.ts} +0 -0
  172. package/src/keyframes/__tests__/index.test.tsx +4 -0
  173. package/src/keyframes/index.js.flow +25 -31
  174. package/src/keyframes/{index.tsx → index.ts} +1 -1
  175. package/src/runtime/__perf__/cs.test.tsx +137 -92
  176. package/src/runtime/__perf__/utils/cs.tsx +15 -15
  177. package/src/runtime/__perf__/utils/{sheet.tsx → sheet.ts} +0 -0
  178. package/src/runtime/__tests__/{ax.test.tsx → ax.test.ts} +0 -0
  179. package/src/runtime/__tests__/{css-custom-property.test.tsx → css-custom-property.test.ts} +0 -0
  180. package/src/runtime/__tests__/style.test.tsx +4 -0
  181. package/src/runtime/ax.js.flow +1 -1
  182. package/src/runtime/{ax.tsx → ax.ts} +0 -0
  183. package/src/runtime/cache.js.flow +1 -1
  184. package/src/runtime/{cache.tsx → cache.ts} +0 -0
  185. package/src/runtime/css-custom-property.js.flow +1 -1
  186. package/src/runtime/{css-custom-property.tsx → css-custom-property.ts} +0 -0
  187. package/src/runtime/dev-warnings.js.flow +1 -1
  188. package/src/runtime/{dev-warnings.tsx → dev-warnings.ts} +0 -0
  189. package/src/runtime/index.js.flow +1 -1
  190. package/src/runtime/{index.tsx → index.ts} +0 -0
  191. package/src/runtime/{is-node.js.flow → is-server-environment.js.flow} +4 -4
  192. package/src/runtime/is-server-environment.ts +29 -0
  193. package/src/runtime/sheet.js.flow +1 -1
  194. package/src/runtime/{sheet.tsx → sheet.ts} +0 -0
  195. package/src/runtime/style-cache.js.flow +1 -1
  196. package/src/runtime/style-cache.tsx +5 -5
  197. package/src/runtime/style.js.flow +1 -1
  198. package/src/runtime/style.tsx +2 -2
  199. package/src/runtime/types.js.flow +2 -2
  200. package/src/runtime/{types.tsx → types.ts} +0 -0
  201. package/src/runtime.js.flow +1 -1
  202. package/src/{runtime.tsx → runtime.ts} +0 -0
  203. package/src/styled/__tests__/index.test.tsx +1 -1
  204. package/src/styled/__tests__/types.test.js.flow +65 -11
  205. package/src/styled/index.js.flow +45 -46
  206. package/src/styled/index.ts +94 -0
  207. package/src/types.js.flow +13 -10
  208. package/src/types.ts +35 -0
  209. package/src/utils/error.js.flow +1 -1
  210. package/src/utils/{error.tsx → error.ts} +0 -0
  211. package/dist/browser/runtime/is-node.js +0 -16
  212. package/dist/browser/runtime/is-node.js.map +0 -1
  213. package/dist/cjs/runtime/is-node.js +0 -20
  214. package/dist/cjs/runtime/is-node.js.map +0 -1
  215. package/dist/esm/runtime/is-node.js +0 -16
  216. package/dist/esm/runtime/is-node.js.map +0 -1
  217. package/src/runtime/is-node.tsx +0 -15
  218. package/src/styled/index.tsx +0 -112
  219. 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
+ });
@@ -1,35 +1,36 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.15.0
4
+ * Flowgen v1.17.0
5
5
  * @flow
6
6
  */
7
- import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
7
+ import type { CSSProps, CssObject, CssFunction } from '../types';
8
8
  /**
9
- * Create styles that can be re-used between components with a template literal.
9
+ * ## CSS
10
10
  *
11
- * ```
12
- * css`color: red;`;
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
- * For more help, read the docs:
16
- * https://compiledcssinjs.com/docs/api-css
17
- * @param css
18
- * @param values
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
- * For more help, read the docs:
32
- * https://compiledcssinjs.com/docs/api-css
33
- * @param css
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(_css: CSSProps): CSSProps;
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<T = void>(
34
+ export default function css<TProps = unknown>(
40
35
  styles: TemplateStringsArray,
41
- ...interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
42
- ): CSSProps;
36
+ ...interpolations: CssFunction<TProps>[]
37
+ ): CSSProps<TProps>;
43
38
 
44
- export default function css(styles: AnyKeyCssProps<void> | CSSProps): CSSProps;
39
+ export default function css<T = unknown>(styles: CssObject<T> | CssObject<T>[]): CSSProps<T>;
45
40
 
46
- export default function css<T = void>(
47
- _styles: TemplateStringsArray | CSSProps,
48
- ..._interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
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
- * THIS IS A MANUALLY CURATED FLOW FILE.
3
- *
4
- * Flowtype definitions for runtime
2
+ * Flowtype definitions for index
5
3
  * Generated by Flowgen from a Typescript Definition
6
- * Flowgen v1.15.0
4
+ * Flowgen v1.17.0
7
5
  * @flow
8
6
  */
9
- import type { CSSProps, CssFunction } from './types';
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;
@@ -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
@@ -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.15.0
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
- * Create keyframes using a tagged template expression:
10
+ * ## Keyframes
11
11
  *
12
- * ```
13
- * const fadeOut = keyframes`
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
- * 1. An object expression
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
- * 3. A template literal
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(_steps: KeyframeSteps): string;
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
- import { StyleArr, StyleStr } from './utils/cs';
10
+ const MemoCS = memo(CS, () => true);
11
+
12
+ import { StyleBucketFromArray, StyleBucketFromString } from './utils/cs';
8
13
 
9
14
  describe('CS benchmark', () => {
10
- it('completes with CS (1 array element) or StyleArr as the fastest', async () => {
11
- const stylesArr = [
12
- '._s7n4jp4b{vertical-align:top}',
13
- '._1reo15vq{overflow-x:hidden}',
14
- '._18m915vq{overflow-y:hidden}',
15
- '._1bto1l2s{text-overflow:ellipsis}',
16
- '._o5721q9c{white-space:nowrap}',
17
- '._ca0qidpf{padding-top:0}',
18
- '._u5f31y44{padding-right:4px}',
19
- '._n3tdidpf{padding-bottom:0}',
20
- '._19bv1y44{padding-left:4px}',
21
- '._p12f12xx{max-width:100px}',
22
- '._1bsb1osq{width:100%}',
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
- const stylesStr = stylesArr.join('');
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
- const className = [
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
- const style = {
46
- '--_16owtcm': 'rgb(227, 252, 239)',
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
- const nonce = 'k0Mp1lEd';
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
- const benchmark = await runBenchmark('CS', [
53
- {
54
- name: 'CS (1 array element)',
55
- fn: () => {
56
- renderToString(
57
- <CC>
58
- <CS nonce={nonce}>{[stylesStr]}</CS>
59
- <span className={className} style={style}>
60
- hello world
61
- </span>
62
- </CC>
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
- name: 'CS (n array elements)',
68
- fn: () => {
69
- renderToString(
70
- <CC>
71
- <CS nonce={nonce}>{stylesArr}</CS>
72
- <span className={className} style={style}>
73
- hello world
74
- </span>
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
- name: 'StyleArr',
81
- fn: () => {
82
- renderToString(
83
- <CC>
84
- <StyleArr nonce={nonce}>{stylesArr}</StyleArr>
85
- <span className={className} style={style}>
86
- hello world
87
- </span>
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
- name: 'StyleStr',
94
- fn: () => {
95
- renderToString(
96
- <CC>
97
- <StyleStr nonce={nonce}>{stylesStr}</StyleStr>
98
- <span className={className} style={style}>
99
- hello world
100
- </span>
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
- expect(benchmark).toMatchObject({
108
- fastest: expect.not.arrayContaining(['StyleStr', 'CS (n array elements)']),
109
- });
110
- }, 30000);
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 const useCache = (): Record<string, true> => {
6
- return useContext(Cache) || {};
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 StyleStr({ children, nonce }: StyleStrProps): JSX.Element | null {
15
- const inserted = useCache();
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 StyleArrProps = {
37
- children: string[];
33
+ export type StyleBucketFromStringProps = {
34
+ children: string;
38
35
  nonce: string;
39
36
  };
40
37
 
41
- export function StyleArr({ children: sheets, nonce }: StyleArrProps): JSX.Element | null {
42
- const inserted = useCache();
38
+ export function StyleBucketFromString({
39
+ children,
40
+ nonce,
41
+ }: StyleBucketFromStringProps): JSX.Element | null {
42
+ const inserted = useContext(Cache) || {};
43
43
 
44
- // The following code will not exist in the browser bundle.
44
+ const sheets = children.split('.');
45
45
  let toInsert = '';
46
46
 
47
47
  for (let i = 0; i < sheets.length; i++) {
@@ -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
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for ax
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.15.0
4
+ * Flowgen v1.17.0
5
5
  * @flow
6
6
  */
7
7
  /**
File without changes
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for cache
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.15.0
4
+ * Flowgen v1.17.0
5
5
  * @flow
6
6
  */
7
7
  /**
File without changes
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for css-custom-property
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.15.0
4
+ * Flowgen v1.17.0
5
5
  * @flow
6
6
  */
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for dev-warnings
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.15.0
4
+ * Flowgen v1.17.0
5
5
  * @flow
6
6
  */
7
7
  declare export var analyzeCssInDev: (sheet: string) => void;