@compiled/react 0.9.1 → 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.
- package/CHANGELOG.md +47 -0
- package/dist/browser/class-names/index.d.ts +1 -1
- package/dist/browser/class-names/index.js.flow +1 -1
- package/dist/browser/class-names/index.js.map +1 -1
- package/dist/browser/css/index.js +1 -0
- 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 +4 -29
- 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 +40 -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/runtime/css-custom-property.d.ts +1 -1
- package/dist/browser/runtime/css-custom-property.js.flow +1 -1
- package/dist/browser/runtime/css-custom-property.js.map +1 -1
- package/dist/browser/runtime/sheet.d.ts +1 -1
- package/dist/browser/runtime/sheet.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.map +1 -1
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/cjs/class-names/index.d.ts +1 -1
- package/dist/cjs/class-names/index.js.flow +1 -1
- package/dist/cjs/class-names/index.js.map +1 -1
- package/dist/cjs/css/index.js +1 -0
- 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 +4 -29
- 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 +40 -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/runtime/css-custom-property.d.ts +1 -1
- package/dist/cjs/runtime/css-custom-property.js.flow +1 -1
- package/dist/cjs/runtime/css-custom-property.js.map +1 -1
- package/dist/cjs/runtime/sheet.d.ts +1 -1
- package/dist/cjs/runtime/sheet.js.flow +1 -1
- package/dist/cjs/runtime/style-cache.js.map +1 -1
- package/dist/cjs/runtime/style.js +2 -2
- package/dist/cjs/runtime/style.js.map +1 -1
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/esm/class-names/index.d.ts +1 -1
- package/dist/esm/class-names/index.js.flow +1 -1
- package/dist/esm/class-names/index.js.map +1 -1
- package/dist/esm/css/index.js +1 -0
- 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 +4 -29
- 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 +40 -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/runtime/css-custom-property.d.ts +1 -1
- package/dist/esm/runtime/css-custom-property.js.flow +1 -1
- package/dist/esm/runtime/css-custom-property.js.map +1 -1
- package/dist/esm/runtime/sheet.d.ts +1 -1
- package/dist/esm/runtime/sheet.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.map +1 -1
- package/dist/esm/styled/index.js.map +1 -1
- package/jsx-dev-runtime/package.json +6 -0
- package/jsx-runtime/package.json +6 -0
- package/package.json +40 -12
- package/src/__tests__/browser.test.tsx +5 -5
- package/src/__tests__/jest-matcher.test.tsx +197 -0
- package/src/__tests__/server-side-hydrate.test.tsx +1 -0
- package/src/__tests__/ssr.test.tsx +2 -2
- package/src/class-names/__tests__/index.test.tsx +1 -1
- package/src/class-names/index.js.flow +1 -1
- package/src/class-names/index.tsx +2 -1
- package/src/css/__tests__/index.test.tsx +2 -3
- package/src/css/index.tsx +3 -1
- package/src/index.js.flow +4 -29
- 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 +39 -0
- package/src/jsx/jsx-dev-runtime.tsx +5 -0
- package/src/jsx/jsx-local-namespace.tsx +49 -0
- package/src/jsx/jsx-runtime.tsx +5 -0
- package/src/keyframes/__tests__/index.test.tsx +2 -1
- 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 +1 -0
- package/src/runtime/__tests__/style.test.tsx +1 -1
- package/src/runtime/css-custom-property.js.flow +1 -1
- package/src/runtime/css-custom-property.tsx +1 -1
- package/src/runtime/sheet.js.flow +1 -1
- package/src/runtime/sheet.tsx +1 -1
- package/src/runtime/style-cache.tsx +1 -0
- package/src/runtime/style.tsx +4 -3
- package/src/styled/__tests__/index.test.tsx +3 -3
- package/src/styled/index.tsx +2 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ordered style buckets using their short psuedo name.
|
|
3
|
+
* If changes are needed make sure that it aligns with the definition in `sort-at-rule-pseudos.tsx`.
|
|
4
|
+
*/
|
|
5
|
+
export const styleBucketOrdering: string[] = [
|
|
6
|
+
// catch-all
|
|
7
|
+
'',
|
|
8
|
+
// link
|
|
9
|
+
'l',
|
|
10
|
+
// visited
|
|
11
|
+
'v',
|
|
12
|
+
// focus-within
|
|
13
|
+
'w',
|
|
14
|
+
// focus
|
|
15
|
+
'f',
|
|
16
|
+
// focus-visible
|
|
17
|
+
'i',
|
|
18
|
+
// hover
|
|
19
|
+
'h',
|
|
20
|
+
// active
|
|
21
|
+
'a',
|
|
22
|
+
// at-rules
|
|
23
|
+
'm',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Holds all style buckets in memory that have been added to the head.
|
|
28
|
+
*/
|
|
29
|
+
const styleBucketsInHead: Record<string, HTMLStyleElement> = {};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Maps the long pseudo name to the short pseudo name.
|
|
33
|
+
* Pseudos that match here will be ordered,
|
|
34
|
+
* everythin else will make their way to the catch all style bucket.
|
|
35
|
+
* We reduce the pseduo name to save bundlesize.
|
|
36
|
+
* Thankfully there aren't any overlaps, see: https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes.
|
|
37
|
+
*/
|
|
38
|
+
const pseudosMap: Record<string, string> = {
|
|
39
|
+
// link
|
|
40
|
+
k: 'l',
|
|
41
|
+
// visited
|
|
42
|
+
ited: 'v',
|
|
43
|
+
// focus-within
|
|
44
|
+
'us-within': 'w',
|
|
45
|
+
// focus
|
|
46
|
+
us: 'f',
|
|
47
|
+
// focus-visible
|
|
48
|
+
'us-visible': 'i',
|
|
49
|
+
// hover
|
|
50
|
+
er: 'h',
|
|
51
|
+
// active
|
|
52
|
+
ive: 'a',
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type StyleBucketOptions = {
|
|
56
|
+
nonce?: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Lazily adds a `<style>` bucket to the `<head>`.
|
|
61
|
+
* This will ensure that the style buckets are ordered.
|
|
62
|
+
*
|
|
63
|
+
* @param bucketName Bucket to insert in the head.
|
|
64
|
+
* @param opts
|
|
65
|
+
*/
|
|
66
|
+
function lazyAddStyleBucketToHead(
|
|
67
|
+
bucketName: string,
|
|
68
|
+
{ nonce }: StyleBucketOptions
|
|
69
|
+
): HTMLStyleElement {
|
|
70
|
+
if (!styleBucketsInHead[bucketName]) {
|
|
71
|
+
let currentBucketIndex = styleBucketOrdering.indexOf(bucketName) + 1;
|
|
72
|
+
let nextBucketFromCache = null;
|
|
73
|
+
|
|
74
|
+
for (; currentBucketIndex < styleBucketOrdering.length; currentBucketIndex++) {
|
|
75
|
+
// Find the next bucket which we will add our new style bucket before.
|
|
76
|
+
const nextBucket = styleBucketsInHead[styleBucketOrdering[currentBucketIndex]];
|
|
77
|
+
if (nextBucket) {
|
|
78
|
+
nextBucketFromCache = nextBucket;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const tag = document.createElement('style');
|
|
84
|
+
nonce && tag.setAttribute('nonce', nonce);
|
|
85
|
+
tag.appendChild(document.createTextNode(''));
|
|
86
|
+
styleBucketsInHead[bucketName] = tag;
|
|
87
|
+
document.head.insertBefore(tag, nextBucketFromCache);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return styleBucketsInHead[bucketName]!;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Gets the bucket depending on the sheet.
|
|
95
|
+
* This function makes assumptions as to the form of the input class name.
|
|
96
|
+
*
|
|
97
|
+
* Input:
|
|
98
|
+
*
|
|
99
|
+
* ```
|
|
100
|
+
* "._a1234567:hover{ color: red; }"
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* Output:
|
|
104
|
+
*
|
|
105
|
+
* ```
|
|
106
|
+
* "h"
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @param sheet styles for which we are getting the bucket
|
|
110
|
+
*/
|
|
111
|
+
const getStyleBucketName = (sheet: string): string => {
|
|
112
|
+
// We are grouping all the at-rules like @media, @supports etc under `m` bucket.
|
|
113
|
+
if (sheet.charCodeAt(0) === 64 /* "@" */) {
|
|
114
|
+
return 'm';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* We assume that classname will always be 9 character long,
|
|
119
|
+
* using this the 10th character could be a pseudo declaration.
|
|
120
|
+
*/
|
|
121
|
+
if (sheet.charCodeAt(10) === 58 /* ":" */) {
|
|
122
|
+
// We send through a subset of the string instead of the full pseudo name.
|
|
123
|
+
// For example `"focus-visible"` name would instead of `"us-visible"`.
|
|
124
|
+
// Return a mapped pseudo else the default catch all bucket.
|
|
125
|
+
return pseudosMap[sheet.slice(14, sheet.indexOf('{'))] || '';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Return default catch all bucket
|
|
129
|
+
return '';
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type CreateStyleSheetOptions = StyleBucketOptions;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Returns a style sheet object that is used to move styles to the head of the application during runtime.
|
|
136
|
+
*
|
|
137
|
+
* @param opts StyleSheetOpts
|
|
138
|
+
*/
|
|
139
|
+
export function createStyleSheet(opts: CreateStyleSheetOptions) {
|
|
140
|
+
return (css: string): void => {
|
|
141
|
+
const bucketName = getStyleBucketName(css);
|
|
142
|
+
const style = lazyAddStyleBucketToHead(bucketName, opts);
|
|
143
|
+
|
|
144
|
+
if (process.env.NODE_ENV === 'production') {
|
|
145
|
+
const sheet = style.sheet as CSSStyleSheet;
|
|
146
|
+
sheet.insertRule(css, sheet.cssRules.length);
|
|
147
|
+
} else {
|
|
148
|
+
style.appendChild(document.createTextNode(css));
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Flowgen v1.15.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
7
|
+
import type { Bucket, StyleSheetOpts } from './types';
|
|
8
8
|
/**
|
|
9
9
|
* Ordered style buckets using their short psuedo name.
|
|
10
10
|
* If changes are needed make sure that it aligns with the definition in `sort-at-rule-pseudos.tsx`.
|
package/src/runtime/sheet.tsx
CHANGED
package/src/runtime/style.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { analyzeCssInDev } from './dev-warnings';
|
|
4
|
-
import type { StyleSheetOpts, Bucket } from './types';
|
|
5
|
-
import { useCache } from './style-cache';
|
|
6
4
|
import { isNodeEnvironment } from './is-node';
|
|
5
|
+
import insertRule, { getStyleBucketName, styleBucketOrdering } from './sheet';
|
|
6
|
+
import { useCache } from './style-cache';
|
|
7
|
+
import type { Bucket, StyleSheetOpts } from './types';
|
|
7
8
|
|
|
8
9
|
interface StyleProps extends StyleSheetOpts {
|
|
9
10
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
1
|
+
/** @jsxImportSource @compiled/react */
|
|
3
2
|
import { styled } from '@compiled/react';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
4
|
|
|
5
5
|
const em = (str: string | number) => str;
|
|
6
6
|
|
|
@@ -139,7 +139,7 @@ describe('styled component', () => {
|
|
|
139
139
|
expect(StyledDiv.displayName).toEqual(undefined);
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
it('should have a display name', () => {
|
|
143
143
|
process.env.NODE_ENV = 'development';
|
|
144
144
|
|
|
145
145
|
const StyledDiv = styled.div`
|
package/src/styled/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ComponentType } from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
|
|
4
|
+
import { createSetupError } from '../utils/error';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Typing for the CSS object.
|