@compiled/react 0.7.0 → 0.10.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 (265) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/dist/browser/class-names/index.d.ts +2 -2
  3. package/dist/browser/class-names/index.js.flow +45 -0
  4. package/dist/browser/class-names/index.js.map +1 -1
  5. package/dist/browser/css/index.d.ts +16 -3
  6. package/dist/browser/css/index.js +1 -13
  7. package/dist/browser/css/index.js.flow +35 -0
  8. package/dist/browser/css/index.js.map +1 -1
  9. package/dist/browser/index.d.ts +15 -23
  10. package/dist/browser/index.js +4 -0
  11. package/dist/browser/index.js.flow +15 -0
  12. package/dist/browser/index.js.map +1 -1
  13. package/dist/browser/jsx/jsx-dev-runtime.d.ts +2 -0
  14. package/dist/browser/jsx/jsx-dev-runtime.js +4 -0
  15. package/dist/browser/jsx/jsx-dev-runtime.js.map +1 -0
  16. package/dist/browser/jsx/jsx-local-namespace.d.ts +40 -0
  17. package/dist/browser/jsx/jsx-local-namespace.js +2 -0
  18. package/dist/browser/jsx/jsx-local-namespace.js.map +1 -0
  19. package/dist/browser/jsx/jsx-runtime.d.ts +2 -0
  20. package/dist/browser/jsx/jsx-runtime.js +4 -0
  21. package/dist/browser/jsx/jsx-runtime.js.map +1 -0
  22. package/dist/browser/keyframes/index.js.flow +54 -0
  23. package/dist/browser/runtime/ax.js.flow +27 -0
  24. package/dist/browser/runtime/css-custom-property.d.ts +1 -1
  25. package/dist/browser/runtime/css-custom-property.js.flow +19 -0
  26. package/dist/browser/runtime/css-custom-property.js.map +1 -1
  27. package/dist/browser/runtime/dev-warnings.d.ts +0 -1
  28. package/dist/browser/runtime/dev-warnings.js +1 -1
  29. package/dist/browser/runtime/dev-warnings.js.flow +7 -0
  30. package/dist/browser/runtime/dev-warnings.js.map +1 -1
  31. package/dist/browser/runtime/index.js.flow +10 -0
  32. package/dist/browser/runtime/is-node.js.flow +19 -0
  33. package/dist/browser/runtime/sheet.d.ts +1 -1
  34. package/dist/browser/runtime/sheet.js.flow +36 -0
  35. package/dist/browser/runtime/style-cache.d.ts +1 -1
  36. package/dist/browser/runtime/style-cache.js.flow +19 -0
  37. package/dist/browser/runtime/style-cache.js.map +1 -1
  38. package/dist/browser/runtime/style.d.ts +1 -1
  39. package/dist/browser/runtime/style.js +2 -2
  40. package/dist/browser/runtime/style.js.flow +17 -0
  41. package/dist/browser/runtime/style.js.map +1 -1
  42. package/dist/browser/runtime/types.js.flow +23 -0
  43. package/dist/browser/runtime.js.flow +7 -0
  44. package/dist/browser/styled/index.d.ts +6 -9
  45. package/dist/browser/styled/index.js.flow +69 -0
  46. package/dist/browser/styled/index.js.map +1 -1
  47. package/dist/browser/types.d.ts +6 -3
  48. package/dist/browser/types.js.flow +29 -0
  49. package/dist/browser/utils/error.js.flow +7 -0
  50. package/dist/cjs/class-names/index.d.ts +2 -2
  51. package/dist/cjs/class-names/index.js.flow +45 -0
  52. package/dist/cjs/class-names/index.js.map +1 -1
  53. package/dist/cjs/css/index.d.ts +16 -3
  54. package/dist/cjs/css/index.js +1 -13
  55. package/dist/cjs/css/index.js.flow +35 -0
  56. package/dist/cjs/css/index.js.map +1 -1
  57. package/dist/cjs/index.d.ts +15 -23
  58. package/dist/cjs/index.js +5 -1
  59. package/dist/cjs/index.js.flow +15 -0
  60. package/dist/cjs/index.js.map +1 -1
  61. package/dist/cjs/jsx/jsx-dev-runtime.d.ts +2 -0
  62. package/dist/cjs/jsx/jsx-dev-runtime.js +16 -0
  63. package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -0
  64. package/dist/cjs/jsx/jsx-local-namespace.d.ts +40 -0
  65. package/dist/cjs/jsx/jsx-local-namespace.js +3 -0
  66. package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -0
  67. package/dist/cjs/jsx/jsx-runtime.d.ts +2 -0
  68. package/dist/cjs/jsx/jsx-runtime.js +16 -0
  69. package/dist/cjs/jsx/jsx-runtime.js.map +1 -0
  70. package/dist/cjs/keyframes/index.js.flow +54 -0
  71. package/dist/cjs/runtime/ax.js.flow +27 -0
  72. package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
  73. package/dist/cjs/runtime/css-custom-property.js.flow +19 -0
  74. package/dist/cjs/runtime/css-custom-property.js.map +1 -1
  75. package/dist/cjs/runtime/dev-warnings.d.ts +0 -1
  76. package/dist/cjs/runtime/dev-warnings.js +2 -3
  77. package/dist/cjs/runtime/dev-warnings.js.flow +7 -0
  78. package/dist/cjs/runtime/dev-warnings.js.map +1 -1
  79. package/dist/cjs/runtime/index.js.flow +10 -0
  80. package/dist/cjs/runtime/is-node.js.flow +19 -0
  81. package/dist/cjs/runtime/sheet.d.ts +1 -1
  82. package/dist/cjs/runtime/sheet.js.flow +36 -0
  83. package/dist/cjs/runtime/style-cache.d.ts +1 -1
  84. package/dist/cjs/runtime/style-cache.js.flow +19 -0
  85. package/dist/cjs/runtime/style-cache.js.map +1 -1
  86. package/dist/cjs/runtime/style.d.ts +1 -1
  87. package/dist/cjs/runtime/style.js +2 -2
  88. package/dist/cjs/runtime/style.js.flow +17 -0
  89. package/dist/cjs/runtime/style.js.map +1 -1
  90. package/dist/cjs/runtime/types.js.flow +23 -0
  91. package/dist/cjs/runtime.js.flow +7 -0
  92. package/dist/cjs/styled/index.d.ts +6 -9
  93. package/dist/cjs/styled/index.js.flow +69 -0
  94. package/dist/cjs/styled/index.js.map +1 -1
  95. package/dist/cjs/types.d.ts +6 -3
  96. package/dist/cjs/types.js.flow +29 -0
  97. package/dist/cjs/utils/error.js.flow +7 -0
  98. package/dist/esm/class-names/index.d.ts +2 -2
  99. package/dist/esm/class-names/index.js.flow +45 -0
  100. package/dist/esm/class-names/index.js.map +1 -1
  101. package/dist/esm/css/index.d.ts +16 -3
  102. package/dist/esm/css/index.js +1 -13
  103. package/dist/esm/css/index.js.flow +35 -0
  104. package/dist/esm/css/index.js.map +1 -1
  105. package/dist/esm/index.d.ts +15 -23
  106. package/dist/esm/index.js +4 -0
  107. package/dist/esm/index.js.flow +15 -0
  108. package/dist/esm/index.js.map +1 -1
  109. package/dist/esm/jsx/jsx-dev-runtime.d.ts +2 -0
  110. package/dist/esm/jsx/jsx-dev-runtime.js +4 -0
  111. package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -0
  112. package/dist/esm/jsx/jsx-local-namespace.d.ts +40 -0
  113. package/dist/esm/jsx/jsx-local-namespace.js +2 -0
  114. package/dist/esm/jsx/jsx-local-namespace.js.map +1 -0
  115. package/dist/esm/jsx/jsx-runtime.d.ts +2 -0
  116. package/dist/esm/jsx/jsx-runtime.js +4 -0
  117. package/dist/esm/jsx/jsx-runtime.js.map +1 -0
  118. package/dist/esm/keyframes/index.js.flow +54 -0
  119. package/dist/esm/runtime/ax.js.flow +27 -0
  120. package/dist/esm/runtime/css-custom-property.d.ts +1 -1
  121. package/dist/esm/runtime/css-custom-property.js.flow +19 -0
  122. package/dist/esm/runtime/css-custom-property.js.map +1 -1
  123. package/dist/esm/runtime/dev-warnings.d.ts +0 -1
  124. package/dist/esm/runtime/dev-warnings.js +1 -1
  125. package/dist/esm/runtime/dev-warnings.js.flow +7 -0
  126. package/dist/esm/runtime/dev-warnings.js.map +1 -1
  127. package/dist/esm/runtime/index.js.flow +10 -0
  128. package/dist/esm/runtime/is-node.js.flow +19 -0
  129. package/dist/esm/runtime/sheet.d.ts +1 -1
  130. package/dist/esm/runtime/sheet.js.flow +36 -0
  131. package/dist/esm/runtime/style-cache.d.ts +1 -1
  132. package/dist/esm/runtime/style-cache.js.flow +19 -0
  133. package/dist/esm/runtime/style-cache.js.map +1 -1
  134. package/dist/esm/runtime/style.d.ts +1 -1
  135. package/dist/esm/runtime/style.js +2 -2
  136. package/dist/esm/runtime/style.js.flow +17 -0
  137. package/dist/esm/runtime/style.js.map +1 -1
  138. package/dist/esm/runtime/types.js.flow +23 -0
  139. package/dist/esm/runtime.js.flow +7 -0
  140. package/dist/esm/styled/index.d.ts +6 -9
  141. package/dist/esm/styled/index.js.flow +69 -0
  142. package/dist/esm/styled/index.js.map +1 -1
  143. package/dist/esm/types.d.ts +6 -3
  144. package/dist/esm/types.js.flow +29 -0
  145. package/dist/esm/utils/error.js.flow +7 -0
  146. package/jsx-dev-runtime/package.json +6 -0
  147. package/jsx-runtime/package.json +6 -0
  148. package/package.json +41 -15
  149. package/src/__tests__/browser.test.tsx +5 -5
  150. package/src/__tests__/jest-matcher.test.tsx +197 -0
  151. package/src/__tests__/server-side-hydrate.test.tsx +1 -0
  152. package/src/__tests__/ssr.test.tsx +2 -2
  153. package/src/class-names/__tests__/index.test.tsx +1 -1
  154. package/src/class-names/__tests__/types.test.js.flow +28 -0
  155. package/src/class-names/index.js.flow +45 -0
  156. package/src/class-names/index.tsx +3 -2
  157. package/src/css/__tests__/index.test.tsx +40 -0
  158. package/src/css/__tests__/types.test.js.flow +17 -0
  159. package/src/css/index.js.flow +35 -0
  160. package/src/css/index.tsx +27 -3
  161. package/src/index.js.flow +15 -0
  162. package/src/index.tsx +20 -26
  163. package/src/jsx/__tests__/index.test.tsx +1 -2
  164. package/src/jsx/__tests__/jsx-import-source-pragma.test.tsx +37 -0
  165. package/src/jsx/__tests__/jsx-pragma.test.tsx +39 -0
  166. package/src/jsx/jsx-dev-runtime.tsx +5 -0
  167. package/src/jsx/jsx-local-namespace.tsx +49 -0
  168. package/src/jsx/jsx-runtime.tsx +5 -0
  169. package/src/keyframes/__tests__/index.test.tsx +2 -1
  170. package/src/keyframes/__tests__/types.test.js.flow +31 -0
  171. package/src/keyframes/index.js.flow +54 -0
  172. package/src/runtime/__perf__/ax.test.ts +42 -0
  173. package/src/runtime/__perf__/cs.test.tsx +111 -0
  174. package/src/runtime/__perf__/sheet.test.ts +61 -0
  175. package/src/runtime/__perf__/utils/cs.tsx +60 -0
  176. package/src/runtime/__perf__/utils/sheet.tsx +151 -0
  177. package/src/runtime/__tests__/style-ssr.test.tsx +1 -0
  178. package/src/runtime/__tests__/style.test.tsx +92 -58
  179. package/src/runtime/ax.js.flow +27 -0
  180. package/src/runtime/css-custom-property.js.flow +19 -0
  181. package/src/runtime/css-custom-property.tsx +1 -1
  182. package/src/runtime/dev-warnings.js.flow +7 -0
  183. package/src/runtime/dev-warnings.tsx +1 -1
  184. package/src/runtime/index.js.flow +10 -0
  185. package/src/runtime/is-node.js.flow +19 -0
  186. package/src/runtime/sheet.js.flow +36 -0
  187. package/src/runtime/sheet.tsx +1 -1
  188. package/src/runtime/style-cache.js.flow +19 -0
  189. package/src/runtime/style-cache.tsx +2 -1
  190. package/src/runtime/style.js.flow +17 -0
  191. package/src/runtime/style.tsx +4 -3
  192. package/src/runtime/types.js.flow +23 -0
  193. package/src/runtime.js.flow +7 -0
  194. package/src/styled/__tests__/index.test.tsx +3 -3
  195. package/src/styled/__tests__/types.test.js.flow +30 -0
  196. package/src/styled/index.js.flow +69 -0
  197. package/src/styled/index.tsx +7 -10
  198. package/src/types.js.flow +29 -0
  199. package/src/types.tsx +7 -3
  200. package/src/utils/error.js.flow +7 -0
  201. package/dist/browser/codemods/codemods-helpers.d.ts +0 -60
  202. package/dist/browser/codemods/codemods-helpers.js +0 -201
  203. package/dist/browser/codemods/codemods-helpers.js.map +0 -1
  204. package/dist/browser/codemods/constants.d.ts +0 -3
  205. package/dist/browser/codemods/constants.js +0 -4
  206. package/dist/browser/codemods/constants.js.map +0 -1
  207. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  208. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
  209. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  210. package/dist/browser/codemods/emotion-to-compiled/index.d.ts +0 -1
  211. package/dist/browser/codemods/emotion-to-compiled/index.js +0 -2
  212. package/dist/browser/codemods/emotion-to-compiled/index.js.map +0 -1
  213. package/dist/browser/codemods/styled-components-to-compiled/index.d.ts +0 -1
  214. package/dist/browser/codemods/styled-components-to-compiled/index.js +0 -2
  215. package/dist/browser/codemods/styled-components-to-compiled/index.js.map +0 -1
  216. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  217. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
  218. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  219. package/dist/cjs/codemods/codemods-helpers.d.ts +0 -60
  220. package/dist/cjs/codemods/codemods-helpers.js +0 -217
  221. package/dist/cjs/codemods/codemods-helpers.js.map +0 -1
  222. package/dist/cjs/codemods/constants.d.ts +0 -3
  223. package/dist/cjs/codemods/constants.js +0 -7
  224. package/dist/cjs/codemods/constants.js.map +0 -1
  225. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  226. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -180
  227. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  228. package/dist/cjs/codemods/emotion-to-compiled/index.d.ts +0 -1
  229. package/dist/cjs/codemods/emotion-to-compiled/index.js +0 -9
  230. package/dist/cjs/codemods/emotion-to-compiled/index.js.map +0 -1
  231. package/dist/cjs/codemods/styled-components-to-compiled/index.d.ts +0 -1
  232. package/dist/cjs/codemods/styled-components-to-compiled/index.js +0 -9
  233. package/dist/cjs/codemods/styled-components-to-compiled/index.js.map +0 -1
  234. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  235. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -35
  236. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  237. package/dist/esm/codemods/codemods-helpers.d.ts +0 -60
  238. package/dist/esm/codemods/codemods-helpers.js +0 -201
  239. package/dist/esm/codemods/codemods-helpers.js.map +0 -1
  240. package/dist/esm/codemods/constants.d.ts +0 -3
  241. package/dist/esm/codemods/constants.js +0 -4
  242. package/dist/esm/codemods/constants.js.map +0 -1
  243. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  244. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
  245. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  246. package/dist/esm/codemods/emotion-to-compiled/index.d.ts +0 -1
  247. package/dist/esm/codemods/emotion-to-compiled/index.js +0 -2
  248. package/dist/esm/codemods/emotion-to-compiled/index.js.map +0 -1
  249. package/dist/esm/codemods/styled-components-to-compiled/index.d.ts +0 -1
  250. package/dist/esm/codemods/styled-components-to-compiled/index.js +0 -2
  251. package/dist/esm/codemods/styled-components-to-compiled/index.js.map +0 -1
  252. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  253. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
  254. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  255. package/src/codemods/README.md +0 -8
  256. package/src/codemods/codemods-helpers.tsx +0 -369
  257. package/src/codemods/constants.tsx +0 -3
  258. package/src/codemods/emotion-to-compiled/README.md +0 -71
  259. package/src/codemods/emotion-to-compiled/__tests__/emotion-to-compiled.test.tsx +0 -526
  260. package/src/codemods/emotion-to-compiled/emotion-to-compiled.tsx +0 -249
  261. package/src/codemods/emotion-to-compiled/index.tsx +0 -1
  262. package/src/codemods/styled-components-to-compiled/README.md +0 -37
  263. package/src/codemods/styled-components-to-compiled/__tests__/styled-components-to-compiled.test.tsx +0 -109
  264. package/src/codemods/styled-components-to-compiled/index.tsx +0 -1
  265. package/src/codemods/styled-components-to-compiled/styled-components-to-compiled.tsx +0 -45
package/src/css/index.tsx CHANGED
@@ -1,8 +1,10 @@
1
+ /* eslint-disable import/export */
2
+
3
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
1
4
  import { createSetupError } from '../utils/error';
2
- import type { CSSProps } from '../types';
3
5
 
4
6
  /**
5
- * Create styles that can be re-used between components.
7
+ * Create styles that can be re-used between components with a template literal.
6
8
  *
7
9
  * ```
8
10
  * css`color: red;`;
@@ -14,6 +16,28 @@ import type { CSSProps } from '../types';
14
16
  * @param css
15
17
  * @param values
16
18
  */
17
- export default function css(_css: TemplateStringsArray, ..._values:(string|number)[]): CSSProps {
19
+ export default function css<T = void>(
20
+ _css: TemplateStringsArray,
21
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
22
+ ): CSSProps;
23
+
24
+ /**
25
+ * Create styles that can be re-used between components with an object
26
+ *
27
+ * ```
28
+ * css({ color: 'red' });
29
+ * ```
30
+ *
31
+ * For more help, read the docs:
32
+ * https://compiledcssinjs.com/docs/api-css
33
+ *
34
+ * @param css
35
+ */
36
+ export default function css(_css: CSSProps): CSSProps;
37
+
38
+ export default function css<T = void>(
39
+ _css: TemplateStringsArray | CSSProps,
40
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
41
+ ): CSSProps {
18
42
  throw createSetupError();
19
43
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * THIS IS A MANUALLY CURATED FLOW FILE.
3
+ *
4
+ * Flowtype definitions for runtime
5
+ * Generated by Flowgen from a Typescript Definition
6
+ * Flowgen v1.15.0
7
+ * @flow
8
+ */
9
+ import type { CSSProps, CssFunction } from './types';
10
+ declare export { keyframes } from './keyframes';
11
+ declare export { styled } from './styled';
12
+ declare export { ClassNames } from './class-names';
13
+ declare export { default as css } from './css';
14
+ export type { CssFunction, CSSProps };
15
+ export type { CssObject } from './styled';
package/src/index.tsx CHANGED
@@ -1,35 +1,29 @@
1
+ import { createElement } from 'react';
2
+
3
+ import type { CompiledJSX } from './jsx/jsx-local-namespace';
4
+ import type { CssFunction, CSSProps } from './types';
5
+
1
6
  export { keyframes } from './keyframes';
2
7
  export { styled } from './styled';
3
8
  export { ClassNames } from './class-names';
4
9
  export { default as css } from './css';
5
10
 
6
- import { CssFunction } from './types';
11
+ // Pass through the (classic) jsx runtime.
12
+ // Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
13
+ export const jsx = createElement;
7
14
 
8
- declare module 'react' {
9
- // We must match the same type signature so the generic needs to stay.
10
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
- interface DOMAttributes<T> {
12
- css?: CssFunction | CssFunction[];
13
- }
14
- }
15
+ export type { CssFunction, CSSProps };
16
+ export type { CssObject } from './styled';
15
17
 
16
- declare global {
17
- namespace JSX {
18
- interface IntrinsicAttributes {
19
- /**
20
- * Tie styles to an element.
21
- * It is available when the `@compiled/react` module is in scope.
22
- *
23
- * ```
24
- * css={{ fontSize: 12 }} // Object CSS
25
- * css={`font-size: 12px;`} // Template literal CSS
26
- * css={[{ fontSize: 12 }, `font-size: 12px;`]} // Array CSS
27
- * ```
28
- *
29
- * For more help, read the docs:
30
- * https://compiledcssinjs.com/docs/api-css-prop
31
- */
32
- css?: CssFunction | CssFunction[];
33
- }
18
+ export namespace jsx {
19
+ export namespace JSX {
20
+ export type Element = CompiledJSX.Element;
21
+ export type ElementClass = CompiledJSX.ElementClass;
22
+ export type ElementAttributesProperty = CompiledJSX.ElementAttributesProperty;
23
+ export type ElementChildrenAttribute = CompiledJSX.ElementChildrenAttribute;
24
+ export type LibraryManagedAttributes<C, P> = CompiledJSX.LibraryManagedAttributes<C, P>;
25
+ export type IntrinsicAttributes = CompiledJSX.IntrinsicAttributes;
26
+ export type IntrinsicClassAttributes<T> = CompiledJSX.IntrinsicClassAttributes<T>;
27
+ export type IntrinsicElements = CompiledJSX.IntrinsicElements;
34
28
  }
35
29
  }
@@ -1,5 +1,4 @@
1
- import '@compiled/react';
2
- import React from 'react';
1
+ /** @jsxImportSource @compiled/react */
3
2
  import { render } from '@testing-library/react';
4
3
 
5
4
  describe('css prop', () => {
@@ -0,0 +1,37 @@
1
+ /** @jsxImportSource @compiled/react */
2
+ import { render } from '@testing-library/react';
3
+
4
+ describe('local jsx namespace', () => {
5
+ it('should create css from object literal', () => {
6
+ const { getByText } = render(<div css={{ fontSize: '15px' }}>hello world</div>);
7
+
8
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
9
+ });
10
+
11
+ it('should allow css prop when class name is a declared prop', () => {
12
+ function Component({ className, children }: { className?: string; children: string }) {
13
+ return <div className={className}>{children}</div>;
14
+ }
15
+
16
+ const { getByText } = render(<Component css={{ fontSize: '15px' }}>hello world</Component>);
17
+
18
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
19
+ });
20
+
21
+ it('should type error css prop when class name is not a declared prop', () => {
22
+ function Component({ children }: { children: string }) {
23
+ return <div>{children}</div>;
24
+ }
25
+
26
+ const { getByText } = render(
27
+ <Component
28
+ // CSS prop is not allowed when class name is not a declared prop
29
+ // @ts-expect-error
30
+ css={{ fontSize: '15px' }}>
31
+ hello world
32
+ </Component>
33
+ );
34
+
35
+ expect(getByText('hello world')).not.toHaveCompiledCss('font-size', '15px');
36
+ });
37
+ });
@@ -0,0 +1,39 @@
1
+ /** @jsxRuntime classic */
2
+ /** @jsx jsx */
3
+ import { jsx } from '@compiled/react';
4
+ import { render } from '@testing-library/react';
5
+
6
+ describe('local jsx namespace', () => {
7
+ it('should create css from object literal', () => {
8
+ const { getByText } = render(<div css={{ fontSize: '15px' }}>hello world</div>);
9
+
10
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
11
+ });
12
+
13
+ it('should allow css prop when class name is a declared prop', () => {
14
+ function Component({ className, children }: { className?: string; children: string }) {
15
+ return <div className={className}>{children}</div>;
16
+ }
17
+
18
+ const { getByText } = render(<Component css={{ fontSize: '15px' }}>hello world</Component>);
19
+
20
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
21
+ });
22
+
23
+ it('should type error css prop when class name is not a declared prop', () => {
24
+ function Component({ children }: { children: string }) {
25
+ return <div>{children}</div>;
26
+ }
27
+
28
+ const { getByText } = render(
29
+ <Component
30
+ // CSS prop is not allowed when class name is not a declared prop
31
+ // @ts-expect-error
32
+ css={{ fontSize: '15px' }}>
33
+ hello world
34
+ </Component>
35
+ );
36
+
37
+ expect(getByText('hello world')).not.toHaveCompiledCss('font-size', '15px');
38
+ });
39
+ });
@@ -0,0 +1,5 @@
1
+ export type { CompiledJSX as JSX } from './jsx-local-namespace';
2
+
3
+ // Pass through the (automatic) jsx dev runtime.
4
+ // Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
5
+ export * from 'react/jsx-dev-runtime';
@@ -0,0 +1,49 @@
1
+ import type { CssFunction } from '../types';
2
+
3
+ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps
4
+ ? string extends TProps['className' & keyof TProps]
5
+ ? {
6
+ /**
7
+ * Tie styles to an element.
8
+ *
9
+ * ```
10
+ * css={{ fontSize: 12 }} // Object CSS
11
+ * css={`font-size: 12px;`} // Template literal CSS
12
+ * css={[{ fontSize: 12 }, `font-size: 12px;`]} // Array CSS
13
+ * ```
14
+ *
15
+ * For more help, read the docs:
16
+ * https://compiledcssinjs.com/docs/api-css-prop
17
+ */
18
+ css?: CssFunction | CssFunction[];
19
+ }
20
+ : // eslint-disable-next-line @typescript-eslint/ban-types
21
+ {}
22
+ : // eslint-disable-next-line @typescript-eslint/ban-types
23
+ {};
24
+
25
+ // Unpack all here to avoid infinite self-referencing when defining our own JSX namespace
26
+ type ReactJSXElement = JSX.Element;
27
+ type ReactJSXElementClass = JSX.ElementClass;
28
+ type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty;
29
+ type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute;
30
+ type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>;
31
+ type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes;
32
+ type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>;
33
+ type ReactJSXIntrinsicElements = JSX.IntrinsicElements;
34
+
35
+ export namespace CompiledJSX {
36
+ export type Element = ReactJSXElement;
37
+ export type ElementClass = ReactJSXElementClass;
38
+ export type ElementAttributesProperty = ReactJSXElementAttributesProperty;
39
+ export type ElementChildrenAttribute = ReactJSXElementChildrenAttribute;
40
+ export type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
41
+ ReactJSXLibraryManagedAttributes<C, P>;
42
+ export type IntrinsicAttributes = ReactJSXIntrinsicAttributes;
43
+ export type IntrinsicClassAttributes<T> = ReactJSXIntrinsicClassAttributes<T>;
44
+ export type IntrinsicElements = {
45
+ [K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
46
+ css?: CssFunction | CssFunction[];
47
+ };
48
+ };
49
+ }
@@ -0,0 +1,5 @@
1
+ export type { CompiledJSX as JSX } from './jsx-local-namespace';
2
+
3
+ // Pass through the (automatic) jsx runtime.
4
+ // Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
5
+ export * from 'react/jsx-runtime';
@@ -1,7 +1,8 @@
1
+ /** @jsxImportSource @compiled/react */
1
2
  import { keyframes, styled } from '@compiled/react';
2
3
  import { render } from '@testing-library/react';
3
4
 
4
- import defaultFadeOut, { fadeOut as shadowedFadeOut, namedFadeOut } from '../__fixtures__';
5
+ import defaultFadeOut, { namedFadeOut, fadeOut as shadowedFadeOut } from '../__fixtures__';
5
6
 
6
7
  const getOpacity = (str: string | number) => str;
7
8
 
@@ -0,0 +1,31 @@
1
+ // @flow strict-local
2
+ import React from 'react';
3
+ import { css, ClassNames, styled, keyframes } from '@compiled/react';
4
+
5
+ // Tagged template expression
6
+ (): React$Element<'div'> => {
7
+ const fadeOut = keyframes`
8
+ from { opacity: 1; }
9
+ to { opacity: 0; }
10
+ `;
11
+ return <div css={{ animationName: fadeOut }}>hello world</div>;
12
+ };
13
+
14
+ // Object call expression
15
+ (): React$Element<'div'> => {
16
+ const fadeOut = keyframes({
17
+ from: {
18
+ opacity: 1,
19
+ },
20
+ to: {
21
+ opacity: 0,
22
+ },
23
+ });
24
+ return <div css={{ animationName: fadeOut }}>hello world</div>;
25
+ };
26
+
27
+ // String call expression
28
+ (): React$Element<'div'> => {
29
+ const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
30
+ return <div css={{ animationName: fadeOut }}>hello world</div>;
31
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.15.0
5
+ * @flow
6
+ */
7
+ import type { BasicTemplateInterpolations, CSSProps } from '../types';
8
+ export type KeyframeSteps = string | { [key: string]: CSSProps, ... };
9
+ /**
10
+ * Create keyframes using a tagged template expression:
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:
27
+ *
28
+ * 1. An object expression
29
+ *
30
+ * ```
31
+ * const fadeOut = keyframes({
32
+ * from: {
33
+ * opacity: 1,
34
+ * },
35
+ * to: {
36
+ * opacity: 0,
37
+ * },
38
+ * });
39
+ * ```
40
+ *
41
+ * 2. A string
42
+ *
43
+ * ```
44
+ * const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
45
+ * ```
46
+ *
47
+ * 3. A template literal
48
+ *
49
+ * ```
50
+ * const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
51
+ * ```
52
+ * @param _steps The waypoints along the animation sequence
53
+ */
54
+ declare export function keyframes(_steps: KeyframeSteps): string;
@@ -0,0 +1,42 @@
1
+ import { runBenchmark } from '@compiled/benchmark';
2
+
3
+ import { ax } from '../index';
4
+
5
+ describe('ax benchmark', () => {
6
+ it('completes with ax() string as the fastest', async () => {
7
+ const arr = [
8
+ '_19itglyw',
9
+ '_2rko1l7b',
10
+ '_ca0qftgi',
11
+ '_u5f319bv',
12
+ '_n3tdftgi',
13
+ '_19bv19bv',
14
+ '_bfhk1mzw',
15
+ '_syazu67f',
16
+ '_k48p1nn1',
17
+ '_ect41kw7',
18
+ '_1wybdlk8',
19
+ '_irr3mlcl',
20
+ '_1di6vctu',
21
+ undefined,
22
+ ];
23
+
24
+ // Remove undefined and join the strings
25
+ const str = arr.slice(0, -1).join(' ');
26
+
27
+ const benchmark = await runBenchmark('ax', [
28
+ {
29
+ name: 'ax() array',
30
+ fn: () => ax(arr),
31
+ },
32
+ {
33
+ name: 'ax() string',
34
+ fn: () => ax([str, undefined]),
35
+ },
36
+ ]);
37
+
38
+ expect(benchmark).toMatchObject({
39
+ fastest: ['ax() string'],
40
+ });
41
+ }, 30000);
42
+ });
@@ -0,0 +1,111 @@
1
+ import { runBenchmark } from '@compiled/benchmark';
2
+ import * as React from 'react';
3
+ import { renderToString } from 'react-dom/server';
4
+
5
+ import { CC, CS } from '../index';
6
+
7
+ import { StyleArr, StyleStr } from './utils/cs';
8
+
9
+ 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
+ ];
24
+
25
+ const stylesStr = stylesArr.join('');
26
+
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(' ');
44
+
45
+ const style = {
46
+ '--_16owtcm': 'rgb(227, 252, 239)',
47
+ '--_kmurgp': 'rgb(0, 102, 68)',
48
+ } as any;
49
+
50
+ const nonce = 'k0Mp1lEd';
51
+
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
+ );
64
+ },
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
+ );
77
+ },
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
+ );
90
+ },
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
+ );
103
+ },
104
+ },
105
+ ]);
106
+
107
+ expect(benchmark).toMatchObject({
108
+ fastest: expect.not.arrayContaining(['StyleStr', 'CS (n array elements)']),
109
+ });
110
+ }, 30000);
111
+ });
@@ -0,0 +1,61 @@
1
+ import { runBenchmark } from '@compiled/benchmark';
2
+
3
+ import insertRule from '../sheet';
4
+
5
+ import { createStyleSheet } from './utils/sheet';
6
+
7
+ global.document = {
8
+ // @ts-expect-error
9
+ createTextNode: () => {},
10
+ head: {
11
+ // @ts-expect-error
12
+ insertBefore: () => {},
13
+ },
14
+ // @ts-expect-error
15
+ createElement: () => ({
16
+ appendChild: () => {},
17
+ }),
18
+ };
19
+
20
+ describe('sheet benchmark', () => {
21
+ it('completes with insertRule as the fastest', async () => {
22
+ const rules = [
23
+ '._s7n4jp4b{vertical-align:top}',
24
+ '._1reo15vq{overflow-x:hidden}',
25
+ '._18m915vq{overflow-y:hidden}',
26
+ '._1bto1l2s{text-overflow:ellipsis}',
27
+ '._o5721q9c{white-space:nowrap}',
28
+ '._ca0qidpf{padding-top:0}',
29
+ '._u5f31y44{padding-right:4px}',
30
+ '._n3tdidpf{padding-bottom:0}',
31
+ '._19bv1y44{padding-left:4px}',
32
+ '._p12f12xx{max-width:100px}',
33
+ '._1bsb1osq{width:100%}',
34
+ ];
35
+
36
+ const benchmark = await runBenchmark('sheet', [
37
+ {
38
+ name: 'insertRule',
39
+ fn: () => {
40
+ for (const rule of rules) {
41
+ insertRule(rule, {});
42
+ }
43
+ },
44
+ },
45
+ {
46
+ name: 'createStyleSheet',
47
+ fn: () => {
48
+ const sheet = createStyleSheet({});
49
+
50
+ for (const rule of rules) {
51
+ sheet(rule);
52
+ }
53
+ },
54
+ },
55
+ ]);
56
+
57
+ expect(benchmark).toMatchObject({
58
+ fastest: expect.arrayContaining(['insertRule']),
59
+ });
60
+ }, 30000);
61
+ });
@@ -0,0 +1,60 @@
1
+ import React, { createContext, useContext } from 'react';
2
+
3
+ const Cache = createContext<Record<string, true> | null>(null);
4
+
5
+ export const useCache = (): Record<string, true> => {
6
+ return useContext(Cache) || {};
7
+ };
8
+
9
+ export type StyleStrProps = {
10
+ children: string;
11
+ nonce: string;
12
+ };
13
+
14
+ export function StyleStr({ children, nonce }: StyleStrProps): JSX.Element | null {
15
+ const inserted = useCache();
16
+
17
+ // The following code will not exist in the browser bundle.
18
+ const sheets = children.split('.');
19
+ let toInsert = '';
20
+
21
+ for (let i = 0; i < sheets.length; i++) {
22
+ const sheet = sheets[i];
23
+ if (inserted[sheet]) {
24
+ continue;
25
+ }
26
+ toInsert += sheet;
27
+ }
28
+
29
+ if (!toInsert) {
30
+ return null;
31
+ }
32
+
33
+ return <style nonce={nonce}>{toInsert}</style>;
34
+ }
35
+
36
+ export type StyleArrProps = {
37
+ children: string[];
38
+ nonce: string;
39
+ };
40
+
41
+ export function StyleArr({ children: sheets, nonce }: StyleArrProps): JSX.Element | null {
42
+ const inserted = useCache();
43
+
44
+ // The following code will not exist in the browser bundle.
45
+ let toInsert = '';
46
+
47
+ for (let i = 0; i < sheets.length; i++) {
48
+ const sheet = sheets[i];
49
+ if (inserted[sheet]) {
50
+ continue;
51
+ }
52
+ toInsert += sheet;
53
+ }
54
+
55
+ if (!toInsert) {
56
+ return null;
57
+ }
58
+
59
+ return <style nonce={nonce}>{toInsert}</style>;
60
+ }