@compiled/react 0.9.0 → 0.10.2

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 (234) hide show
  1. package/dist/browser/class-names/index.d.ts +22 -16
  2. package/dist/browser/class-names/index.js +1 -27
  3. package/dist/browser/class-names/index.js.flow +2 -2
  4. package/dist/browser/class-names/index.js.map +1 -1
  5. package/dist/browser/css/index.d.ts +22 -19
  6. package/dist/browser/css/index.js +4 -3
  7. package/dist/browser/css/index.js.flow +1 -1
  8. package/dist/browser/css/index.js.map +1 -1
  9. package/dist/browser/index.d.ts +12 -22
  10. package/dist/browser/index.js +4 -0
  11. package/dist/browser/index.js.flow +5 -30
  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 +66 -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/__fixtures__/index.js +1 -0
  23. package/dist/browser/keyframes/__fixtures__/index.js.map +1 -1
  24. package/dist/browser/keyframes/index.d.ts +20 -24
  25. package/dist/browser/keyframes/index.js.flow +1 -1
  26. package/dist/browser/keyframes/index.js.map +1 -1
  27. package/dist/browser/runtime/ax.js.flow +1 -1
  28. package/dist/browser/runtime/cache.d.ts +12 -0
  29. package/dist/browser/runtime/cache.js +15 -0
  30. package/dist/browser/runtime/cache.js.flow +18 -0
  31. package/dist/browser/runtime/cache.js.map +1 -0
  32. package/dist/browser/runtime/css-custom-property.d.ts +1 -1
  33. package/dist/browser/runtime/css-custom-property.js.flow +2 -2
  34. package/dist/browser/runtime/css-custom-property.js.map +1 -1
  35. package/dist/browser/runtime/dev-warnings.js +10 -6
  36. package/dist/browser/runtime/dev-warnings.js.flow +1 -1
  37. package/dist/browser/runtime/dev-warnings.js.map +1 -1
  38. package/dist/browser/runtime/index.js.flow +1 -1
  39. package/dist/browser/runtime/is-node.js +1 -3
  40. package/dist/browser/runtime/is-node.js.flow +1 -1
  41. package/dist/browser/runtime/is-node.js.map +1 -1
  42. package/dist/browser/runtime/sheet.d.ts +1 -1
  43. package/dist/browser/runtime/sheet.js +5 -1
  44. package/dist/browser/runtime/sheet.js.flow +2 -2
  45. package/dist/browser/runtime/sheet.js.map +1 -1
  46. package/dist/browser/runtime/style-cache.js +4 -0
  47. package/dist/browser/runtime/style-cache.js.flow +1 -1
  48. package/dist/browser/runtime/style-cache.js.map +1 -1
  49. package/dist/browser/runtime/style.js +2 -2
  50. package/dist/browser/runtime/style.js.flow +1 -1
  51. package/dist/browser/runtime/style.js.map +1 -1
  52. package/dist/browser/runtime/types.js.flow +1 -1
  53. package/dist/browser/runtime.js.flow +1 -1
  54. package/dist/browser/styled/index.d.ts +35 -7
  55. package/dist/browser/styled/index.js +35 -7
  56. package/dist/browser/styled/index.js.flow +2 -2
  57. package/dist/browser/styled/index.js.map +1 -1
  58. package/dist/browser/types.js.flow +1 -1
  59. package/dist/browser/utils/error.js.flow +1 -1
  60. package/dist/cjs/class-names/index.d.ts +22 -16
  61. package/dist/cjs/class-names/index.js +2 -28
  62. package/dist/cjs/class-names/index.js.flow +2 -2
  63. package/dist/cjs/class-names/index.js.map +1 -1
  64. package/dist/cjs/css/index.d.ts +22 -19
  65. package/dist/cjs/css/index.js +5 -4
  66. package/dist/cjs/css/index.js.flow +1 -1
  67. package/dist/cjs/css/index.js.map +1 -1
  68. package/dist/cjs/index.d.ts +12 -22
  69. package/dist/cjs/index.js +5 -1
  70. package/dist/cjs/index.js.flow +5 -30
  71. package/dist/cjs/index.js.map +1 -1
  72. package/dist/cjs/jsx/jsx-dev-runtime.d.ts +2 -0
  73. package/dist/cjs/jsx/jsx-dev-runtime.js +16 -0
  74. package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -0
  75. package/dist/cjs/jsx/jsx-local-namespace.d.ts +66 -0
  76. package/dist/cjs/jsx/jsx-local-namespace.js +3 -0
  77. package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -0
  78. package/dist/cjs/jsx/jsx-runtime.d.ts +2 -0
  79. package/dist/cjs/jsx/jsx-runtime.js +16 -0
  80. package/dist/cjs/jsx/jsx-runtime.js.map +1 -0
  81. package/dist/cjs/keyframes/__fixtures__/index.js +2 -1
  82. package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -1
  83. package/dist/cjs/keyframes/index.d.ts +20 -24
  84. package/dist/cjs/keyframes/index.js +1 -1
  85. package/dist/cjs/keyframes/index.js.flow +1 -1
  86. package/dist/cjs/keyframes/index.js.map +1 -1
  87. package/dist/cjs/runtime/ax.js.flow +1 -1
  88. package/dist/cjs/runtime/cache.d.ts +12 -0
  89. package/dist/cjs/runtime/cache.js +19 -0
  90. package/dist/cjs/runtime/cache.js.flow +18 -0
  91. package/dist/cjs/runtime/cache.js.map +1 -0
  92. package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
  93. package/dist/cjs/runtime/css-custom-property.js.flow +2 -2
  94. package/dist/cjs/runtime/css-custom-property.js.map +1 -1
  95. package/dist/cjs/runtime/dev-warnings.js +10 -6
  96. package/dist/cjs/runtime/dev-warnings.js.flow +1 -1
  97. package/dist/cjs/runtime/dev-warnings.js.map +1 -1
  98. package/dist/cjs/runtime/index.js.flow +1 -1
  99. package/dist/cjs/runtime/is-node.js +1 -3
  100. package/dist/cjs/runtime/is-node.js.flow +1 -1
  101. package/dist/cjs/runtime/is-node.js.map +1 -1
  102. package/dist/cjs/runtime/sheet.d.ts +1 -1
  103. package/dist/cjs/runtime/sheet.js +6 -2
  104. package/dist/cjs/runtime/sheet.js.flow +2 -2
  105. package/dist/cjs/runtime/sheet.js.map +1 -1
  106. package/dist/cjs/runtime/style-cache.js +10 -6
  107. package/dist/cjs/runtime/style-cache.js.flow +1 -1
  108. package/dist/cjs/runtime/style-cache.js.map +1 -1
  109. package/dist/cjs/runtime/style.js +6 -6
  110. package/dist/cjs/runtime/style.js.flow +1 -1
  111. package/dist/cjs/runtime/style.js.map +1 -1
  112. package/dist/cjs/runtime/types.js.flow +1 -1
  113. package/dist/cjs/runtime.js.flow +1 -1
  114. package/dist/cjs/styled/index.d.ts +35 -7
  115. package/dist/cjs/styled/index.js +36 -8
  116. package/dist/cjs/styled/index.js.flow +2 -2
  117. package/dist/cjs/styled/index.js.map +1 -1
  118. package/dist/cjs/types.js.flow +1 -1
  119. package/dist/cjs/utils/error.js.flow +1 -1
  120. package/dist/esm/class-names/index.d.ts +22 -16
  121. package/dist/esm/class-names/index.js +1 -27
  122. package/dist/esm/class-names/index.js.flow +2 -2
  123. package/dist/esm/class-names/index.js.map +1 -1
  124. package/dist/esm/css/index.d.ts +22 -19
  125. package/dist/esm/css/index.js +4 -3
  126. package/dist/esm/css/index.js.flow +1 -1
  127. package/dist/esm/css/index.js.map +1 -1
  128. package/dist/esm/index.d.ts +12 -22
  129. package/dist/esm/index.js +4 -0
  130. package/dist/esm/index.js.flow +5 -30
  131. package/dist/esm/index.js.map +1 -1
  132. package/dist/esm/jsx/jsx-dev-runtime.d.ts +2 -0
  133. package/dist/esm/jsx/jsx-dev-runtime.js +4 -0
  134. package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -0
  135. package/dist/esm/jsx/jsx-local-namespace.d.ts +66 -0
  136. package/dist/esm/jsx/jsx-local-namespace.js +2 -0
  137. package/dist/esm/jsx/jsx-local-namespace.js.map +1 -0
  138. package/dist/esm/jsx/jsx-runtime.d.ts +2 -0
  139. package/dist/esm/jsx/jsx-runtime.js +4 -0
  140. package/dist/esm/jsx/jsx-runtime.js.map +1 -0
  141. package/dist/esm/keyframes/__fixtures__/index.js +1 -0
  142. package/dist/esm/keyframes/__fixtures__/index.js.map +1 -1
  143. package/dist/esm/keyframes/index.d.ts +20 -24
  144. package/dist/esm/keyframes/index.js.flow +1 -1
  145. package/dist/esm/keyframes/index.js.map +1 -1
  146. package/dist/esm/runtime/ax.js.flow +1 -1
  147. package/dist/esm/runtime/cache.d.ts +12 -0
  148. package/dist/esm/runtime/cache.js +15 -0
  149. package/dist/esm/runtime/cache.js.flow +18 -0
  150. package/dist/esm/runtime/cache.js.map +1 -0
  151. package/dist/esm/runtime/css-custom-property.d.ts +1 -1
  152. package/dist/esm/runtime/css-custom-property.js.flow +2 -2
  153. package/dist/esm/runtime/css-custom-property.js.map +1 -1
  154. package/dist/esm/runtime/dev-warnings.js +10 -6
  155. package/dist/esm/runtime/dev-warnings.js.flow +1 -1
  156. package/dist/esm/runtime/dev-warnings.js.map +1 -1
  157. package/dist/esm/runtime/index.js.flow +1 -1
  158. package/dist/esm/runtime/is-node.js +1 -3
  159. package/dist/esm/runtime/is-node.js.flow +1 -1
  160. package/dist/esm/runtime/is-node.js.map +1 -1
  161. package/dist/esm/runtime/sheet.d.ts +1 -1
  162. package/dist/esm/runtime/sheet.js +5 -1
  163. package/dist/esm/runtime/sheet.js.flow +2 -2
  164. package/dist/esm/runtime/sheet.js.map +1 -1
  165. package/dist/esm/runtime/style-cache.js +4 -0
  166. package/dist/esm/runtime/style-cache.js.flow +1 -1
  167. package/dist/esm/runtime/style-cache.js.map +1 -1
  168. package/dist/esm/runtime/style.js +2 -2
  169. package/dist/esm/runtime/style.js.flow +1 -1
  170. package/dist/esm/runtime/style.js.map +1 -1
  171. package/dist/esm/runtime/types.js.flow +1 -1
  172. package/dist/esm/runtime.js.flow +1 -1
  173. package/dist/esm/styled/index.d.ts +35 -7
  174. package/dist/esm/styled/index.js +35 -7
  175. package/dist/esm/styled/index.js.flow +2 -2
  176. package/dist/esm/styled/index.js.map +1 -1
  177. package/dist/esm/types.js.flow +1 -1
  178. package/dist/esm/utils/error.js.flow +1 -1
  179. package/jsx-dev-runtime/package.json +6 -0
  180. package/jsx-runtime/package.json +6 -0
  181. package/package.json +43 -14
  182. package/src/__tests__/browser.test.tsx +3 -8
  183. package/src/__tests__/display-names.test.tsx +1 -0
  184. package/src/__tests__/jest-matcher.test.tsx +199 -0
  185. package/src/__tests__/server-side-hydrate.test.tsx +1 -0
  186. package/src/__tests__/ssr.test.tsx +5 -3
  187. package/src/class-names/__tests__/index.test.tsx +2 -1
  188. package/src/class-names/index.js.flow +2 -2
  189. package/src/class-names/index.tsx +25 -14
  190. package/src/css/__tests__/index.test.tsx +10 -3
  191. package/src/css/index.js.flow +1 -1
  192. package/src/css/index.tsx +34 -24
  193. package/src/index.js.flow +5 -30
  194. package/src/index.tsx +18 -26
  195. package/src/jsx/__tests__/index.test.tsx +1 -2
  196. package/src/jsx/__tests__/jsx-import-source-pragma.test.tsx +37 -0
  197. package/src/jsx/__tests__/jsx-pragma.test.tsx +40 -0
  198. package/src/jsx/jsx-dev-runtime.tsx +5 -0
  199. package/src/jsx/jsx-local-namespace.tsx +75 -0
  200. package/src/jsx/jsx-runtime.tsx +5 -0
  201. package/src/keyframes/__fixtures__/index.tsx +1 -0
  202. package/src/keyframes/__tests__/index.test.tsx +20 -6
  203. package/src/keyframes/index.js.flow +1 -1
  204. package/src/keyframes/index.tsx +24 -28
  205. package/src/runtime/__perf__/ax.test.ts +42 -0
  206. package/src/runtime/__perf__/cs.test.tsx +111 -0
  207. package/src/runtime/__perf__/sheet.test.ts +61 -0
  208. package/src/runtime/__perf__/utils/cs.tsx +60 -0
  209. package/src/runtime/__perf__/utils/sheet.tsx +151 -0
  210. package/src/runtime/__tests__/style-ssr.test.tsx +5 -0
  211. package/src/runtime/__tests__/style.test.tsx +1 -5
  212. package/src/runtime/ax.js.flow +1 -1
  213. package/src/runtime/cache.js.flow +18 -0
  214. package/src/runtime/cache.tsx +14 -0
  215. package/src/runtime/css-custom-property.js.flow +2 -2
  216. package/src/runtime/css-custom-property.tsx +1 -1
  217. package/src/runtime/dev-warnings.js.flow +1 -1
  218. package/src/runtime/index.js.flow +1 -1
  219. package/src/runtime/is-node.js.flow +1 -1
  220. package/src/runtime/is-node.tsx +1 -2
  221. package/src/runtime/sheet.js.flow +2 -2
  222. package/src/runtime/sheet.tsx +8 -2
  223. package/src/runtime/style-cache.js.flow +1 -1
  224. package/src/runtime/style-cache.tsx +6 -0
  225. package/src/runtime/style.js.flow +1 -1
  226. package/src/runtime/style.tsx +4 -3
  227. package/src/runtime/types.js.flow +1 -1
  228. package/src/runtime.js.flow +1 -1
  229. package/src/styled/__tests__/index.test.tsx +4 -3
  230. package/src/styled/index.js.flow +2 -2
  231. package/src/styled/index.tsx +37 -8
  232. package/src/types.js.flow +1 -1
  233. package/src/utils/error.js.flow +1 -1
  234. package/CHANGELOG.md +0 -74
@@ -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,40 @@
1
+ /** @jsxRuntime classic */
2
+ /** @jsx jsx */
3
+ // eslint-disable-next-line import/no-extraneous-dependencies
4
+ import { jsx } from '@compiled/react';
5
+ import { render } from '@testing-library/react';
6
+
7
+ describe('local jsx namespace', () => {
8
+ it('should create css from object literal', () => {
9
+ const { getByText } = render(<div css={{ fontSize: '15px' }}>hello world</div>);
10
+
11
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
12
+ });
13
+
14
+ it('should allow css prop when class name is a declared prop', () => {
15
+ function Component({ className, children }: { className?: string; children: string }) {
16
+ return <div className={className}>{children}</div>;
17
+ }
18
+
19
+ const { getByText } = render(<Component css={{ fontSize: '15px' }}>hello world</Component>);
20
+
21
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
22
+ });
23
+
24
+ it('should type error css prop when class name is not a declared prop', () => {
25
+ function Component({ children }: { children: string }) {
26
+ return <div>{children}</div>;
27
+ }
28
+
29
+ const { getByText } = render(
30
+ <Component
31
+ // CSS prop is not allowed when class name is not a declared prop
32
+ // @ts-expect-error
33
+ css={{ fontSize: '15px' }}>
34
+ hello world
35
+ </Component>
36
+ );
37
+
38
+ expect(getByText('hello world')).not.toHaveCompiledCss('font-size', '15px');
39
+ });
40
+ });
@@ -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,75 @@
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
+ * ## CSS prop
8
+ *
9
+ * Style a JSX element.
10
+ * For further details [read the API documentation](https://compiledcssinjs.com/docs/api-css-prop).
11
+ *
12
+ * ### Style with objects
13
+ *
14
+ * @example
15
+ * ```
16
+ * import { css } from '@compiled/react';
17
+ *
18
+ * <div css={css({ fontSize: 12 })} />
19
+ * ```
20
+ *
21
+ * ### Style with template literals
22
+ *
23
+ * @example
24
+ * ```
25
+ * import { css } from '@compiled/react';
26
+ *
27
+ * <div css={css`color: red;`} />
28
+ * ```
29
+ *
30
+ * ### Compose styles with arrays
31
+ *
32
+ * @example
33
+ * ```
34
+ * import { css } from '@compiled/react';
35
+ *
36
+ * <div
37
+ * css={[
38
+ * css({ fontSize: 12 }),
39
+ * css`color: red;`,
40
+ * ]}
41
+ * />
42
+ * ```
43
+ */
44
+ css?: CssFunction | CssFunction[];
45
+ }
46
+ : // eslint-disable-next-line @typescript-eslint/ban-types
47
+ {}
48
+ : // eslint-disable-next-line @typescript-eslint/ban-types
49
+ {};
50
+
51
+ // Unpack all here to avoid infinite self-referencing when defining our own JSX namespace
52
+ type ReactJSXElement = JSX.Element;
53
+ type ReactJSXElementClass = JSX.ElementClass;
54
+ type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty;
55
+ type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute;
56
+ type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>;
57
+ type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes;
58
+ type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>;
59
+ type ReactJSXIntrinsicElements = JSX.IntrinsicElements;
60
+
61
+ export namespace CompiledJSX {
62
+ export type Element = ReactJSXElement;
63
+ export type ElementClass = ReactJSXElementClass;
64
+ export type ElementAttributesProperty = ReactJSXElementAttributesProperty;
65
+ export type ElementChildrenAttribute = ReactJSXElementChildrenAttribute;
66
+ export type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
67
+ ReactJSXLibraryManagedAttributes<C, P>;
68
+ export type IntrinsicAttributes = ReactJSXIntrinsicAttributes;
69
+ export type IntrinsicClassAttributes<T> = ReactJSXIntrinsicClassAttributes<T>;
70
+ export type IntrinsicElements = {
71
+ [K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
72
+ css?: CssFunction | CssFunction[];
73
+ };
74
+ };
75
+ }
@@ -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,3 +1,4 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
1
2
  import { keyframes } from '@compiled/react';
2
3
 
3
4
  export const fadeOut = keyframes({
@@ -1,20 +1,34 @@
1
+ /** @jsxImportSource @compiled/react */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
1
3
  import { keyframes, styled } from '@compiled/react';
2
4
  import { render } from '@testing-library/react';
3
5
 
4
- import defaultFadeOut, { fadeOut as shadowedFadeOut, namedFadeOut } from '../__fixtures__';
6
+ import defaultFadeOut, { namedFadeOut, fadeOut as shadowedFadeOut } from '../__fixtures__';
5
7
 
6
8
  const getOpacity = (str: string | number) => str;
7
9
 
8
10
  const getKeyframe = (name: string) => {
9
- const styles = Array.from(
10
- document.body.querySelectorAll('style'),
11
- (style) => style.innerHTML
12
- ).join('\n');
11
+ const searchStr = `@keyframes ${name}`;
13
12
 
14
- return styles.substring(styles.indexOf(`@keyframes ${name}`));
13
+ return Array.from(document.head.querySelectorAll('style'), (style) => style.innerHTML)
14
+ .filter((style) => style.indexOf(searchStr) >= 0)
15
+ .map((style) => style.substring(style.indexOf(searchStr)))
16
+ .join('\n');
15
17
  };
16
18
 
17
19
  describe('keyframes', () => {
20
+ beforeAll(() => {
21
+ process.env.CACHE = 'false';
22
+ });
23
+
24
+ afterAll(() => {
25
+ delete process.env.CACHE;
26
+ });
27
+
28
+ afterEach(() => {
29
+ document.head.innerHTML = '';
30
+ });
31
+
18
32
  describe('referenced through a css prop', () => {
19
33
  describe('render an animation', () => {
20
34
  it('given an object call expression argument', () => {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.14.1
4
+ * Flowgen v1.15.0
5
5
  * @flow
6
6
  */
7
7
  import type { BasicTemplateInterpolations, CSSProps } from '../types';
@@ -4,28 +4,14 @@ import { createSetupError } from '../utils/error';
4
4
  export type KeyframeSteps = string | Record<string, CSSProps>;
5
5
 
6
6
  /**
7
- * Create keyframes using a tagged template expression:
7
+ * ## Keyframes
8
8
  *
9
- * ```
10
- * const fadeOut = keyframes`
11
- * from { opacity: 1; }
12
- * to { opacity: 0; }
13
- * `;
14
- * ```
15
- *
16
- * @param _strings The input string values
17
- * @param _interpolations The arguments used in the expression
18
- */
19
- export function keyframes(
20
- _strings: TemplateStringsArray,
21
- ..._interpolations: BasicTemplateInterpolations[]
22
- ): string;
23
-
24
- /**
25
- * Create keyframes using:
9
+ * Define keyframes to be used in a [CSS animation](https://developer.mozilla.org/en-US/docs/Web/CSS/animation).
10
+ * For further details [read the API documentation](https://compiledcssinjs.com/docs/api-keyframes).
26
11
  *
27
- * 1. An object expression
12
+ * ### Style with objects
28
13
  *
14
+ * @example
29
15
  * ```
30
16
  * const fadeOut = keyframes({
31
17
  * from: {
@@ -35,23 +21,33 @@ export function keyframes(
35
21
  * opacity: 0,
36
22
  * },
37
23
  * });
24
+ *
25
+ * <div css={{ animation: `${fadeOut} 2s` }} />
38
26
  * ```
39
27
  *
40
- * 2. A string
28
+ * ### Style with template literals
41
29
  *
30
+ * @example
42
31
  * ```
43
- * const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
44
- * ```
32
+ * const fadeOut = keyframes`
33
+ * from {
34
+ * opacity: 1;
35
+ * }
45
36
  *
46
- * 3. A template literal
37
+ * to {
38
+ * opacity: 0;
39
+ * }
40
+ * `;
47
41
  *
42
+ * <div css={{ animation: `${fadeOut} 2s` }} />
48
43
  * ```
49
- * const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
50
- * ```
51
- *
52
- * @param _steps The waypoints along the animation sequence
53
44
  */
54
- export function keyframes(_steps: KeyframeSteps): string;
45
+ export function keyframes(steps: KeyframeSteps): string;
46
+
47
+ export function keyframes(
48
+ strings: TemplateStringsArray,
49
+ ...interpolations: BasicTemplateInterpolations[]
50
+ ): string;
55
51
 
56
52
  export function keyframes(
57
53
  _stringsOrSteps: TemplateStringsArray | KeyframeSteps,
@@ -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
+ }