@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.
- package/dist/browser/class-names/index.d.ts +22 -16
- package/dist/browser/class-names/index.js +1 -27
- package/dist/browser/class-names/index.js.flow +2 -2
- package/dist/browser/class-names/index.js.map +1 -1
- package/dist/browser/css/index.d.ts +22 -19
- package/dist/browser/css/index.js +4 -3
- package/dist/browser/css/index.js.flow +1 -1
- package/dist/browser/css/index.js.map +1 -1
- package/dist/browser/index.d.ts +12 -22
- package/dist/browser/index.js +4 -0
- package/dist/browser/index.js.flow +5 -30
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/browser/jsx/jsx-dev-runtime.js +4 -0
- package/dist/browser/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/browser/jsx/jsx-local-namespace.d.ts +66 -0
- package/dist/browser/jsx/jsx-local-namespace.js +2 -0
- package/dist/browser/jsx/jsx-local-namespace.js.map +1 -0
- package/dist/browser/jsx/jsx-runtime.d.ts +2 -0
- package/dist/browser/jsx/jsx-runtime.js +4 -0
- package/dist/browser/jsx/jsx-runtime.js.map +1 -0
- package/dist/browser/keyframes/__fixtures__/index.js +1 -0
- package/dist/browser/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/browser/keyframes/index.d.ts +20 -24
- package/dist/browser/keyframes/index.js.flow +1 -1
- package/dist/browser/keyframes/index.js.map +1 -1
- package/dist/browser/runtime/ax.js.flow +1 -1
- package/dist/browser/runtime/cache.d.ts +12 -0
- package/dist/browser/runtime/cache.js +15 -0
- package/dist/browser/runtime/cache.js.flow +18 -0
- package/dist/browser/runtime/cache.js.map +1 -0
- package/dist/browser/runtime/css-custom-property.d.ts +1 -1
- package/dist/browser/runtime/css-custom-property.js.flow +2 -2
- package/dist/browser/runtime/css-custom-property.js.map +1 -1
- package/dist/browser/runtime/dev-warnings.js +10 -6
- package/dist/browser/runtime/dev-warnings.js.flow +1 -1
- package/dist/browser/runtime/dev-warnings.js.map +1 -1
- package/dist/browser/runtime/index.js.flow +1 -1
- package/dist/browser/runtime/is-node.js +1 -3
- package/dist/browser/runtime/is-node.js.flow +1 -1
- package/dist/browser/runtime/is-node.js.map +1 -1
- package/dist/browser/runtime/sheet.d.ts +1 -1
- package/dist/browser/runtime/sheet.js +5 -1
- package/dist/browser/runtime/sheet.js.flow +2 -2
- package/dist/browser/runtime/sheet.js.map +1 -1
- package/dist/browser/runtime/style-cache.js +4 -0
- package/dist/browser/runtime/style-cache.js.flow +1 -1
- package/dist/browser/runtime/style-cache.js.map +1 -1
- package/dist/browser/runtime/style.js +2 -2
- package/dist/browser/runtime/style.js.flow +1 -1
- package/dist/browser/runtime/style.js.map +1 -1
- package/dist/browser/runtime/types.js.flow +1 -1
- package/dist/browser/runtime.js.flow +1 -1
- package/dist/browser/styled/index.d.ts +35 -7
- package/dist/browser/styled/index.js +35 -7
- package/dist/browser/styled/index.js.flow +2 -2
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/browser/types.js.flow +1 -1
- package/dist/browser/utils/error.js.flow +1 -1
- package/dist/cjs/class-names/index.d.ts +22 -16
- package/dist/cjs/class-names/index.js +2 -28
- package/dist/cjs/class-names/index.js.flow +2 -2
- package/dist/cjs/class-names/index.js.map +1 -1
- package/dist/cjs/css/index.d.ts +22 -19
- package/dist/cjs/css/index.js +5 -4
- package/dist/cjs/css/index.js.flow +1 -1
- package/dist/cjs/css/index.js.map +1 -1
- package/dist/cjs/index.d.ts +12 -22
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.flow +5 -30
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/cjs/jsx/jsx-dev-runtime.js +16 -0
- package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/cjs/jsx/jsx-local-namespace.d.ts +66 -0
- package/dist/cjs/jsx/jsx-local-namespace.js +3 -0
- package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -0
- package/dist/cjs/jsx/jsx-runtime.d.ts +2 -0
- package/dist/cjs/jsx/jsx-runtime.js +16 -0
- package/dist/cjs/jsx/jsx-runtime.js.map +1 -0
- package/dist/cjs/keyframes/__fixtures__/index.js +2 -1
- package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/cjs/keyframes/index.d.ts +20 -24
- package/dist/cjs/keyframes/index.js +1 -1
- package/dist/cjs/keyframes/index.js.flow +1 -1
- package/dist/cjs/keyframes/index.js.map +1 -1
- package/dist/cjs/runtime/ax.js.flow +1 -1
- package/dist/cjs/runtime/cache.d.ts +12 -0
- package/dist/cjs/runtime/cache.js +19 -0
- package/dist/cjs/runtime/cache.js.flow +18 -0
- package/dist/cjs/runtime/cache.js.map +1 -0
- package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
- package/dist/cjs/runtime/css-custom-property.js.flow +2 -2
- package/dist/cjs/runtime/css-custom-property.js.map +1 -1
- package/dist/cjs/runtime/dev-warnings.js +10 -6
- package/dist/cjs/runtime/dev-warnings.js.flow +1 -1
- package/dist/cjs/runtime/dev-warnings.js.map +1 -1
- package/dist/cjs/runtime/index.js.flow +1 -1
- package/dist/cjs/runtime/is-node.js +1 -3
- package/dist/cjs/runtime/is-node.js.flow +1 -1
- package/dist/cjs/runtime/is-node.js.map +1 -1
- package/dist/cjs/runtime/sheet.d.ts +1 -1
- package/dist/cjs/runtime/sheet.js +6 -2
- package/dist/cjs/runtime/sheet.js.flow +2 -2
- package/dist/cjs/runtime/sheet.js.map +1 -1
- package/dist/cjs/runtime/style-cache.js +10 -6
- package/dist/cjs/runtime/style-cache.js.flow +1 -1
- package/dist/cjs/runtime/style-cache.js.map +1 -1
- package/dist/cjs/runtime/style.js +6 -6
- package/dist/cjs/runtime/style.js.flow +1 -1
- package/dist/cjs/runtime/style.js.map +1 -1
- package/dist/cjs/runtime/types.js.flow +1 -1
- package/dist/cjs/runtime.js.flow +1 -1
- package/dist/cjs/styled/index.d.ts +35 -7
- package/dist/cjs/styled/index.js +36 -8
- package/dist/cjs/styled/index.js.flow +2 -2
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/cjs/types.js.flow +1 -1
- package/dist/cjs/utils/error.js.flow +1 -1
- package/dist/esm/class-names/index.d.ts +22 -16
- package/dist/esm/class-names/index.js +1 -27
- package/dist/esm/class-names/index.js.flow +2 -2
- package/dist/esm/class-names/index.js.map +1 -1
- package/dist/esm/css/index.d.ts +22 -19
- package/dist/esm/css/index.js +4 -3
- package/dist/esm/css/index.js.flow +1 -1
- package/dist/esm/css/index.js.map +1 -1
- package/dist/esm/index.d.ts +12 -22
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.flow +5 -30
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/esm/jsx/jsx-dev-runtime.js +4 -0
- package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/esm/jsx/jsx-local-namespace.d.ts +66 -0
- package/dist/esm/jsx/jsx-local-namespace.js +2 -0
- package/dist/esm/jsx/jsx-local-namespace.js.map +1 -0
- package/dist/esm/jsx/jsx-runtime.d.ts +2 -0
- package/dist/esm/jsx/jsx-runtime.js +4 -0
- package/dist/esm/jsx/jsx-runtime.js.map +1 -0
- package/dist/esm/keyframes/__fixtures__/index.js +1 -0
- package/dist/esm/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/esm/keyframes/index.d.ts +20 -24
- package/dist/esm/keyframes/index.js.flow +1 -1
- package/dist/esm/keyframes/index.js.map +1 -1
- package/dist/esm/runtime/ax.js.flow +1 -1
- package/dist/esm/runtime/cache.d.ts +12 -0
- package/dist/esm/runtime/cache.js +15 -0
- package/dist/esm/runtime/cache.js.flow +18 -0
- package/dist/esm/runtime/cache.js.map +1 -0
- package/dist/esm/runtime/css-custom-property.d.ts +1 -1
- package/dist/esm/runtime/css-custom-property.js.flow +2 -2
- package/dist/esm/runtime/css-custom-property.js.map +1 -1
- package/dist/esm/runtime/dev-warnings.js +10 -6
- package/dist/esm/runtime/dev-warnings.js.flow +1 -1
- package/dist/esm/runtime/dev-warnings.js.map +1 -1
- package/dist/esm/runtime/index.js.flow +1 -1
- package/dist/esm/runtime/is-node.js +1 -3
- package/dist/esm/runtime/is-node.js.flow +1 -1
- package/dist/esm/runtime/is-node.js.map +1 -1
- package/dist/esm/runtime/sheet.d.ts +1 -1
- package/dist/esm/runtime/sheet.js +5 -1
- package/dist/esm/runtime/sheet.js.flow +2 -2
- package/dist/esm/runtime/sheet.js.map +1 -1
- package/dist/esm/runtime/style-cache.js +4 -0
- package/dist/esm/runtime/style-cache.js.flow +1 -1
- package/dist/esm/runtime/style-cache.js.map +1 -1
- package/dist/esm/runtime/style.js +2 -2
- package/dist/esm/runtime/style.js.flow +1 -1
- package/dist/esm/runtime/style.js.map +1 -1
- package/dist/esm/runtime/types.js.flow +1 -1
- package/dist/esm/runtime.js.flow +1 -1
- package/dist/esm/styled/index.d.ts +35 -7
- package/dist/esm/styled/index.js +35 -7
- package/dist/esm/styled/index.js.flow +2 -2
- package/dist/esm/styled/index.js.map +1 -1
- package/dist/esm/types.js.flow +1 -1
- package/dist/esm/utils/error.js.flow +1 -1
- package/jsx-dev-runtime/package.json +6 -0
- package/jsx-runtime/package.json +6 -0
- package/package.json +43 -14
- package/src/__tests__/browser.test.tsx +3 -8
- package/src/__tests__/display-names.test.tsx +1 -0
- package/src/__tests__/jest-matcher.test.tsx +199 -0
- package/src/__tests__/server-side-hydrate.test.tsx +1 -0
- package/src/__tests__/ssr.test.tsx +5 -3
- package/src/class-names/__tests__/index.test.tsx +2 -1
- package/src/class-names/index.js.flow +2 -2
- package/src/class-names/index.tsx +25 -14
- package/src/css/__tests__/index.test.tsx +10 -3
- package/src/css/index.js.flow +1 -1
- package/src/css/index.tsx +34 -24
- package/src/index.js.flow +5 -30
- package/src/index.tsx +18 -26
- package/src/jsx/__tests__/index.test.tsx +1 -2
- package/src/jsx/__tests__/jsx-import-source-pragma.test.tsx +37 -0
- package/src/jsx/__tests__/jsx-pragma.test.tsx +40 -0
- package/src/jsx/jsx-dev-runtime.tsx +5 -0
- package/src/jsx/jsx-local-namespace.tsx +75 -0
- package/src/jsx/jsx-runtime.tsx +5 -0
- package/src/keyframes/__fixtures__/index.tsx +1 -0
- package/src/keyframes/__tests__/index.test.tsx +20 -6
- package/src/keyframes/index.js.flow +1 -1
- package/src/keyframes/index.tsx +24 -28
- package/src/runtime/__perf__/ax.test.ts +42 -0
- package/src/runtime/__perf__/cs.test.tsx +111 -0
- package/src/runtime/__perf__/sheet.test.ts +61 -0
- package/src/runtime/__perf__/utils/cs.tsx +60 -0
- package/src/runtime/__perf__/utils/sheet.tsx +151 -0
- package/src/runtime/__tests__/style-ssr.test.tsx +5 -0
- package/src/runtime/__tests__/style.test.tsx +1 -5
- package/src/runtime/ax.js.flow +1 -1
- package/src/runtime/cache.js.flow +18 -0
- package/src/runtime/cache.tsx +14 -0
- package/src/runtime/css-custom-property.js.flow +2 -2
- package/src/runtime/css-custom-property.tsx +1 -1
- package/src/runtime/dev-warnings.js.flow +1 -1
- package/src/runtime/index.js.flow +1 -1
- package/src/runtime/is-node.js.flow +1 -1
- package/src/runtime/is-node.tsx +1 -2
- package/src/runtime/sheet.js.flow +2 -2
- package/src/runtime/sheet.tsx +8 -2
- package/src/runtime/style-cache.js.flow +1 -1
- package/src/runtime/style-cache.tsx +6 -0
- package/src/runtime/style.js.flow +1 -1
- package/src/runtime/style.tsx +4 -3
- package/src/runtime/types.js.flow +1 -1
- package/src/runtime.js.flow +1 -1
- package/src/styled/__tests__/index.test.tsx +4 -3
- package/src/styled/index.js.flow +2 -2
- package/src/styled/index.tsx +37 -8
- package/src/types.js.flow +1 -1
- package/src/utils/error.js.flow +1 -1
- 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,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
|
+
}
|
|
@@ -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
|
|
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
|
|
10
|
-
document.body.querySelectorAll('style'),
|
|
11
|
-
(style) => style.innerHTML
|
|
12
|
-
).join('\n');
|
|
11
|
+
const searchStr = `@keyframes ${name}`;
|
|
13
12
|
|
|
14
|
-
return
|
|
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', () => {
|
package/src/keyframes/index.tsx
CHANGED
|
@@ -4,28 +4,14 @@ import { createSetupError } from '../utils/error';
|
|
|
4
4
|
export type KeyframeSteps = string | Record<string, CSSProps>;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* ## Keyframes
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
28
|
+
* ### Style with template literals
|
|
41
29
|
*
|
|
30
|
+
* @example
|
|
42
31
|
* ```
|
|
43
|
-
* const fadeOut = keyframes
|
|
44
|
-
*
|
|
32
|
+
* const fadeOut = keyframes`
|
|
33
|
+
* from {
|
|
34
|
+
* opacity: 1;
|
|
35
|
+
* }
|
|
45
36
|
*
|
|
46
|
-
*
|
|
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(
|
|
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
|
+
}
|