@stylexjs/stylex 0.2.0-beta.21 → 0.2.0-beta.22
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/README.md +80 -43
- package/lib/StyleXCSSTypes.js +1 -1
- package/lib/StyleXSheet.js +18 -19
- package/lib/StyleXTypes.d.ts +26 -51
- package/lib/StyleXTypes.js +1 -1
- package/lib/StyleXTypes.js.flow +16 -16
- package/lib/native/CSSCustomPropertyValue.js +1 -1
- package/lib/native/CSSLengthUnitValue.js +7 -7
- package/lib/native/CSSMediaQuery.js +4 -4
- package/lib/native/SpreadOptions.d.ts +1 -0
- package/lib/native/SpreadOptions.js.flow +1 -0
- package/lib/native/__tests__/__snapshots__/stylex-test.js.snap +16 -0
- package/lib/native/__tests__/parseTimeValue-test.js +3 -3
- package/lib/native/__tests__/stylex-css-var-test.js +60 -60
- package/lib/native/__tests__/stylex-test.js +306 -289
- package/lib/native/fixContentBox.js +7 -7
- package/lib/native/flattenStyle.js +1 -1
- package/lib/native/parseShadow.js +4 -4
- package/lib/native/parseTimeValue.js +4 -4
- package/lib/native/stylex.d.ts +15 -5
- package/lib/native/stylex.js +120 -89
- package/lib/native/stylex.js.flow +19 -5
- package/lib/stylex.d.ts +31 -22
- package/lib/stylex.js +81 -59
- package/lib/stylex.js.flow +32 -27
- package/package.json +2 -2
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.CSSMediaQuery = void 0;
|
|
7
7
|
var _cssMediaquery = _interopRequireDefault(require("css-mediaquery"));
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
const MQ_PREFIX =
|
|
9
|
+
const MQ_PREFIX = '@media';
|
|
10
10
|
class CSSMediaQuery {
|
|
11
11
|
static isMediaQueryString(inp) {
|
|
12
12
|
return inp.startsWith(MQ_PREFIX);
|
|
@@ -33,7 +33,7 @@ class CSSMediaQuery {
|
|
|
33
33
|
return result;
|
|
34
34
|
}
|
|
35
35
|
constructor(query, matchedStyle) {
|
|
36
|
-
this.query = query.replace(MQ_PREFIX,
|
|
36
|
+
this.query = query.replace(MQ_PREFIX, '');
|
|
37
37
|
this.matchedStyle = matchedStyle;
|
|
38
38
|
}
|
|
39
39
|
resolve(matchObject) {
|
|
@@ -45,8 +45,8 @@ class CSSMediaQuery {
|
|
|
45
45
|
const matches = _cssMediaquery.default.match(this.query, {
|
|
46
46
|
width,
|
|
47
47
|
height,
|
|
48
|
-
orientation: width > height ?
|
|
49
|
-
|
|
48
|
+
orientation: width > height ? 'landscape' : 'portrait',
|
|
49
|
+
'aspect-ratio': width / height,
|
|
50
50
|
direction: direction
|
|
51
51
|
});
|
|
52
52
|
return matches ? this.matchedStyle : {};
|
|
@@ -11,6 +11,7 @@ export type SpreadOptions = {
|
|
|
11
11
|
customProperties: {};
|
|
12
12
|
inheritedFontSize: null | undefined | number;
|
|
13
13
|
fontScale: number | void;
|
|
14
|
+
hover?: null | undefined | boolean;
|
|
14
15
|
passthroughProperties: Array<string>;
|
|
15
16
|
viewportHeight: number;
|
|
16
17
|
viewportWidth: number;
|
|
@@ -530,6 +530,22 @@ exports[`logical styles textAlign: start 1`] = `
|
|
|
530
530
|
}
|
|
531
531
|
`;
|
|
532
532
|
|
|
533
|
+
exports[`styles :hover syntax: hovered 1`] = `
|
|
534
|
+
{
|
|
535
|
+
"style": {
|
|
536
|
+
"backgroundColor": "blue",
|
|
537
|
+
},
|
|
538
|
+
}
|
|
539
|
+
`;
|
|
540
|
+
|
|
541
|
+
exports[`styles :hover syntax: not hovered 1`] = `
|
|
542
|
+
{
|
|
543
|
+
"style": {
|
|
544
|
+
"backgroundColor": "red",
|
|
545
|
+
},
|
|
546
|
+
}
|
|
547
|
+
`;
|
|
548
|
+
|
|
533
549
|
exports[`styles animation-delay 1`] = `
|
|
534
550
|
{
|
|
535
551
|
"style": {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _parseTimeValue = require("../parseTimeValue");
|
|
4
|
-
const WPT_TRANSITION_DELAY_TEST_CASES = [[
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
4
|
+
const WPT_TRANSITION_DELAY_TEST_CASES = [['10.2s', 10200], ['1s', 1000], ['0.1s', 100], ['0.01s', 10], ['0.001s', 1], ['0.009s', 9], ['0s', 0], ['.0s', 0], ['.3s', 300], ['-5s', -5000], ['10200ms', 10200], ['1000ms', 1000], ['100ms', 100], ['10ms', 10], ['9ms', 9], ['1ms', 1], ['0ms', 0], ['-500ms', -500], ['foobar', 0]];
|
|
5
|
+
describe('parseTimeValue', () => {
|
|
6
|
+
it('parses time values to milliseconds', () => {
|
|
7
7
|
for (const [timeValue, expectedMilliseconds] of WPT_TRANSITION_DELAY_TEST_CASES) {
|
|
8
8
|
expect((0, _parseTimeValue.parseTimeValue)(timeValue)).toEqual(expectedMilliseconds);
|
|
9
9
|
}
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
var _stylex = require("../stylex");
|
|
4
4
|
const mockOptions = {
|
|
5
5
|
customProperties: {
|
|
6
|
-
testVar:
|
|
7
|
-
testVar2:
|
|
8
|
-
boxShadowVar1:
|
|
6
|
+
testVar: 'red',
|
|
7
|
+
testVar2: 'blue',
|
|
8
|
+
boxShadowVar1: '5px 5px 5px black',
|
|
9
9
|
rawNumber: 10,
|
|
10
|
-
pixelNumber:
|
|
11
|
-
emNumber:
|
|
12
|
-
refToRawNumber:
|
|
13
|
-
refToPixelNumber:
|
|
14
|
-
refToRefToRawNumber:
|
|
10
|
+
pixelNumber: '10px',
|
|
11
|
+
emNumber: '10em',
|
|
12
|
+
refToRawNumber: 'var(--rawNumber)',
|
|
13
|
+
refToPixelNumber: 'var(--pixelNumber)',
|
|
14
|
+
refToRefToRawNumber: 'var(--refToRawNumber)'
|
|
15
15
|
},
|
|
16
16
|
viewportHeight: 600,
|
|
17
17
|
viewportWidth: 320
|
|
@@ -22,127 +22,127 @@ function resolveColorValue(colorValue) {
|
|
|
22
22
|
color: colorValue
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
return _stylex.stylex.
|
|
25
|
+
return _stylex.stylex.props(styles.root, mockOptions).style.color;
|
|
26
26
|
}
|
|
27
|
-
describe(
|
|
27
|
+
describe('stylex CSSCustomProperty value test', () => {
|
|
28
28
|
beforeEach(() => {
|
|
29
|
-
jest.spyOn(console,
|
|
29
|
+
jest.spyOn(console, 'warn');
|
|
30
30
|
console.warn.mockImplementation(() => {});
|
|
31
31
|
});
|
|
32
32
|
afterEach(() => {
|
|
33
33
|
console.warn.mockRestore();
|
|
34
34
|
});
|
|
35
|
-
test(
|
|
36
|
-
expect(resolveColorValue(
|
|
35
|
+
test('parses a basic variable correctly', () => {
|
|
36
|
+
expect(resolveColorValue('var(--testVar)')).toEqual('red');
|
|
37
37
|
});
|
|
38
|
-
test(
|
|
39
|
-
expect(resolveColorValue(
|
|
38
|
+
test('parses kebab case to camel case', () => {
|
|
39
|
+
expect(resolveColorValue('var(--test-var)')).toEqual('red');
|
|
40
40
|
});
|
|
41
|
-
test(
|
|
42
|
-
expect(resolveColorValue(
|
|
43
|
-
expect(resolveColorValue(
|
|
41
|
+
test('parses a variable with a default value', () => {
|
|
42
|
+
expect(resolveColorValue('var(--testVar, blue)')).toEqual('red');
|
|
43
|
+
expect(resolveColorValue('var(--notFound, blue)')).toEqual('blue');
|
|
44
44
|
});
|
|
45
|
-
test(
|
|
46
|
-
expect(resolveColorValue(
|
|
47
|
-
expect(resolveColorValue(
|
|
45
|
+
test('parses kebab case with a default value', () => {
|
|
46
|
+
expect(resolveColorValue('var(--test-var, blue)')).toEqual('red');
|
|
47
|
+
expect(resolveColorValue('var(--not-found, blue)')).toEqual('blue');
|
|
48
48
|
});
|
|
49
|
-
test(
|
|
49
|
+
test('parses a variable with a default value with spaces', () => {
|
|
50
50
|
const styles = _stylex.stylex.create({
|
|
51
51
|
root: {
|
|
52
|
-
boxShadow:
|
|
52
|
+
boxShadow: 'var(--boxShadowVar1, 0px 0px 0px black)'
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
|
-
expect(_stylex.stylex.
|
|
55
|
+
expect(_stylex.stylex.props(styles.root, mockOptions)).toMatchSnapshot();
|
|
56
56
|
});
|
|
57
|
-
test(
|
|
57
|
+
test('falls back to a default value with spaces', () => {
|
|
58
58
|
const styles = _stylex.stylex.create({
|
|
59
59
|
root: {
|
|
60
|
-
boxShadow:
|
|
60
|
+
boxShadow: 'var(--boxShadowVarNotFound, 0px 0px 0px black)'
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
|
-
expect(_stylex.stylex.
|
|
63
|
+
expect(_stylex.stylex.props(styles.root, mockOptions)).toMatchSnapshot();
|
|
64
64
|
});
|
|
65
|
-
test(
|
|
65
|
+
test('parses and falls back to default value containing a variable', () => {
|
|
66
66
|
const styles = _stylex.stylex.create({
|
|
67
67
|
root: {
|
|
68
|
-
color:
|
|
68
|
+
color: 'var(--colorNotFound, var(--testVar2))'
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
|
-
expect(_stylex.stylex.
|
|
71
|
+
expect(_stylex.stylex.props(styles.root, mockOptions)).toMatchSnapshot();
|
|
72
72
|
});
|
|
73
|
-
test(
|
|
73
|
+
test('parses and falls back to a default value containing spaces and embedded variables', () => {
|
|
74
74
|
const styles = _stylex.stylex.create({
|
|
75
75
|
root: {
|
|
76
|
-
boxShadow:
|
|
76
|
+
boxShadow: 'var(--boxShadowVarNotFound, 0px 0px 0px var(--testVar2))'
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
-
expect(_stylex.stylex.
|
|
79
|
+
expect(_stylex.stylex.props(styles.root, mockOptions)).toMatchSnapshot();
|
|
80
80
|
});
|
|
81
|
-
test(
|
|
82
|
-
expect(resolveColorValue(
|
|
83
|
-
expect(resolveColorValue(
|
|
84
|
-
expect(resolveColorValue(
|
|
85
|
-
expect(resolveColorValue(
|
|
81
|
+
test('does not parse malformed vars', () => {
|
|
82
|
+
expect(resolveColorValue('var(--testUnfinished')).toEqual('var(--testUnfinished');
|
|
83
|
+
expect(resolveColorValue('var(bad--input)')).toEqual('var(bad--input)');
|
|
84
|
+
expect(resolveColorValue('--testMulti')).toEqual('--testMulti');
|
|
85
|
+
expect(resolveColorValue('var ( --testMulti)')).toEqual('var ( --testMulti)');
|
|
86
86
|
});
|
|
87
|
-
test(
|
|
87
|
+
test('basic value lookup works', () => {
|
|
88
88
|
const styles = _stylex.stylex.create({
|
|
89
89
|
root: {
|
|
90
90
|
borderWidth: 10
|
|
91
91
|
},
|
|
92
92
|
withVars: {
|
|
93
|
-
borderWidth:
|
|
93
|
+
borderWidth: 'var(--rawNumber)'
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
|
-
const rootStyle = _stylex.stylex.
|
|
96
|
+
const rootStyle = _stylex.stylex.props(styles.root, mockOptions).style;
|
|
97
97
|
expect(rootStyle.borderWidth).toEqual(10);
|
|
98
|
-
expect(_stylex.stylex.
|
|
98
|
+
expect(_stylex.stylex.props(styles.withVars, mockOptions).style.borderWidth).toEqual(rootStyle.borderWidth);
|
|
99
99
|
});
|
|
100
|
-
test(
|
|
100
|
+
test('value lookup with pixel prop conversion', () => {
|
|
101
101
|
const styles = _stylex.stylex.create({
|
|
102
102
|
root: {
|
|
103
|
-
borderWidth:
|
|
103
|
+
borderWidth: '10px'
|
|
104
104
|
},
|
|
105
105
|
withVars: {
|
|
106
|
-
borderWidth:
|
|
106
|
+
borderWidth: 'var(--pixelNumber)'
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
|
-
const rootStyle = _stylex.stylex.
|
|
109
|
+
const rootStyle = _stylex.stylex.props(styles.root, mockOptions).style;
|
|
110
110
|
expect(rootStyle.borderWidth).toEqual(10);
|
|
111
|
-
expect(_stylex.stylex.
|
|
111
|
+
expect(_stylex.stylex.props(styles.withVars, mockOptions).style.borderWidth).toEqual(rootStyle.borderWidth);
|
|
112
112
|
});
|
|
113
|
-
test(
|
|
113
|
+
test('value lookup with em prop conversion', () => {
|
|
114
114
|
const styles = _stylex.stylex.create({
|
|
115
115
|
root: {
|
|
116
|
-
fontSize:
|
|
116
|
+
fontSize: '10em'
|
|
117
117
|
},
|
|
118
118
|
withVars: {
|
|
119
|
-
fontSize:
|
|
119
|
+
fontSize: 'var(--emNumber)'
|
|
120
120
|
}
|
|
121
121
|
});
|
|
122
|
-
const rootStyle = _stylex.stylex.
|
|
122
|
+
const rootStyle = _stylex.stylex.props(styles.root, mockOptions).style;
|
|
123
123
|
expect(rootStyle.fontSize).toEqual(160);
|
|
124
|
-
expect(_stylex.stylex.
|
|
124
|
+
expect(_stylex.stylex.props(styles.withVars, mockOptions).style.fontSize).toEqual(rootStyle.fontSize);
|
|
125
125
|
});
|
|
126
|
-
test(
|
|
126
|
+
test('prop lookup with ref', () => {
|
|
127
127
|
const styles = _stylex.stylex.create({
|
|
128
128
|
root: {
|
|
129
|
-
borderWidth:
|
|
129
|
+
borderWidth: 'var(--refToRawNumber)'
|
|
130
130
|
},
|
|
131
131
|
withVars: {
|
|
132
|
-
borderWidth:
|
|
132
|
+
borderWidth: 'var(--refToPixelNumber)'
|
|
133
133
|
}
|
|
134
134
|
});
|
|
135
|
-
const rootStyle = _stylex.stylex.
|
|
135
|
+
const rootStyle = _stylex.stylex.props(styles.root, mockOptions).style;
|
|
136
136
|
expect(rootStyle.borderWidth).toEqual(10);
|
|
137
|
-
expect(_stylex.stylex.
|
|
137
|
+
expect(_stylex.stylex.props(styles.withVars, mockOptions).style.borderWidth).toEqual(rootStyle.borderWidth);
|
|
138
138
|
});
|
|
139
|
-
test(
|
|
139
|
+
test('prop lookup with ref to ref', () => {
|
|
140
140
|
const styles = _stylex.stylex.create({
|
|
141
141
|
root: {
|
|
142
|
-
borderWidth:
|
|
142
|
+
borderWidth: 'var(--refToRefToRawNumber)'
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
|
-
const rootStyle = _stylex.stylex.
|
|
145
|
+
const rootStyle = _stylex.stylex.props(styles.root, mockOptions).style;
|
|
146
146
|
expect(rootStyle.borderWidth).toEqual(10);
|
|
147
147
|
});
|
|
148
148
|
});
|