@stylexjs/stylex 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +18 -43
  2. package/lib/StyleXCSSTypes.d.ts +3 -1
  3. package/lib/StyleXCSSTypes.js.flow +4 -2
  4. package/lib/StyleXSheet.js +17 -3
  5. package/lib/StyleXTypes.d.ts +10 -4
  6. package/lib/StyleXTypes.js.flow +9 -6
  7. package/lib/stylex.d.ts +0 -7
  8. package/lib/stylex.js +1 -5
  9. package/lib/stylex.js.flow +0 -4
  10. package/package.json +2 -2
  11. package/lib/native/CSSCustomPropertyValue.d.ts +0 -26
  12. package/lib/native/CSSCustomPropertyValue.js +0 -27
  13. package/lib/native/CSSCustomPropertyValue.js.flow +0 -27
  14. package/lib/native/CSSLengthUnitValue.d.ts +0 -18
  15. package/lib/native/CSSLengthUnitValue.js +0 -73
  16. package/lib/native/CSSLengthUnitValue.js.flow +0 -21
  17. package/lib/native/CSSMediaQuery.d.ts +0 -25
  18. package/lib/native/CSSMediaQuery.js +0 -55
  19. package/lib/native/CSSMediaQuery.js.flow +0 -26
  20. package/lib/native/SpreadOptions.d.ts +0 -19
  21. package/lib/native/SpreadOptions.js +0 -1
  22. package/lib/native/SpreadOptions.js.flow +0 -19
  23. package/lib/native/__tests__/__snapshots__/stylex-css-var-test.js.snap +0 -48
  24. package/lib/native/__tests__/__snapshots__/stylex-test.js.snap +0 -1046
  25. package/lib/native/__tests__/parseTimeValue-test.js +0 -11
  26. package/lib/native/__tests__/stylex-css-var-test.js +0 -148
  27. package/lib/native/__tests__/stylex-test.js +0 -924
  28. package/lib/native/errorMsg.d.ts +0 -11
  29. package/lib/native/errorMsg.js +0 -13
  30. package/lib/native/errorMsg.js.flow +0 -12
  31. package/lib/native/fixContentBox.d.ts +0 -11
  32. package/lib/native/fixContentBox.js +0 -59
  33. package/lib/native/fixContentBox.js.flow +0 -11
  34. package/lib/native/flattenStyle.d.ts +0 -15
  35. package/lib/native/flattenStyle.js +0 -20
  36. package/lib/native/flattenStyle.js.flow +0 -20
  37. package/lib/native/parseShadow.d.ts +0 -18
  38. package/lib/native/parseShadow.js +0 -36
  39. package/lib/native/parseShadow.js.flow +0 -19
  40. package/lib/native/parseTimeValue.d.ts +0 -11
  41. package/lib/native/parseTimeValue.js +0 -18
  42. package/lib/native/parseTimeValue.js.flow +0 -12
  43. package/lib/native/stylex.d.ts +0 -50
  44. package/lib/native/stylex.js +0 -393
  45. package/lib/native/stylex.js.flow +0 -60
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- var _parseTimeValue = require("../parseTimeValue");
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
- for (const [timeValue, expectedMilliseconds] of WPT_TRANSITION_DELAY_TEST_CASES) {
8
- expect((0, _parseTimeValue.parseTimeValue)(timeValue)).toEqual(expectedMilliseconds);
9
- }
10
- });
11
- });
@@ -1,148 +0,0 @@
1
- "use strict";
2
-
3
- var _stylex = require("../stylex");
4
- const mockOptions = {
5
- customProperties: {
6
- testVar: 'red',
7
- testVar2: 'blue',
8
- boxShadowVar1: '5px 5px 5px black',
9
- rawNumber: 10,
10
- pixelNumber: '10px',
11
- emNumber: '10em',
12
- refToRawNumber: 'var(--rawNumber)',
13
- refToPixelNumber: 'var(--pixelNumber)',
14
- refToRefToRawNumber: 'var(--refToRawNumber)'
15
- },
16
- viewportHeight: 600,
17
- viewportWidth: 320
18
- };
19
- function resolveColorValue(colorValue) {
20
- const styles = _stylex.stylex.create({
21
- root: {
22
- color: colorValue
23
- }
24
- });
25
- return _stylex.stylex.props.call(mockOptions, styles.root).style.color;
26
- }
27
- describe('stylex CSSCustomProperty value test', () => {
28
- beforeEach(() => {
29
- jest.spyOn(console, 'warn');
30
- console.warn.mockImplementation(() => {});
31
- });
32
- afterEach(() => {
33
- console.warn.mockRestore();
34
- });
35
- test('parses a basic variable correctly', () => {
36
- expect(resolveColorValue('var(--testVar)')).toEqual('red');
37
- });
38
- test('parses kebab case to camel case', () => {
39
- expect(resolveColorValue('var(--test-var)')).toEqual('red');
40
- });
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
- });
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
- });
49
- test('parses a variable with a default value with spaces', () => {
50
- const styles = _stylex.stylex.create({
51
- root: {
52
- boxShadow: 'var(--boxShadowVar1, 0px 0px 0px black)'
53
- }
54
- });
55
- expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
56
- });
57
- test('falls back to a default value with spaces', () => {
58
- const styles = _stylex.stylex.create({
59
- root: {
60
- boxShadow: 'var(--boxShadowVarNotFound, 0px 0px 0px black)'
61
- }
62
- });
63
- expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
64
- });
65
- test('parses and falls back to default value containing a variable', () => {
66
- const styles = _stylex.stylex.create({
67
- root: {
68
- color: 'var(--colorNotFound, var(--testVar2))'
69
- }
70
- });
71
- expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
72
- });
73
- test('parses and falls back to a default value containing spaces and embedded variables', () => {
74
- const styles = _stylex.stylex.create({
75
- root: {
76
- boxShadow: 'var(--boxShadowVarNotFound, 0px 0px 0px var(--testVar2))'
77
- }
78
- });
79
- expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
80
- });
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
- });
87
- test('basic value lookup works', () => {
88
- const styles = _stylex.stylex.create({
89
- root: {
90
- borderWidth: 10
91
- },
92
- withVars: {
93
- borderWidth: 'var(--rawNumber)'
94
- }
95
- });
96
- const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
97
- expect(rootStyle.borderWidth).toEqual(10);
98
- expect(_stylex.stylex.props.call(mockOptions, styles.withVars).style.borderWidth).toEqual(rootStyle.borderWidth);
99
- });
100
- test('value lookup with pixel prop conversion', () => {
101
- const styles = _stylex.stylex.create({
102
- root: {
103
- borderWidth: '10px'
104
- },
105
- withVars: {
106
- borderWidth: 'var(--pixelNumber)'
107
- }
108
- });
109
- const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
110
- expect(rootStyle.borderWidth).toEqual(10);
111
- expect(_stylex.stylex.props.call(mockOptions, styles.withVars).style.borderWidth).toEqual(rootStyle.borderWidth);
112
- });
113
- test('value lookup with em prop conversion', () => {
114
- const styles = _stylex.stylex.create({
115
- root: {
116
- fontSize: '10em'
117
- },
118
- withVars: {
119
- fontSize: 'var(--emNumber)'
120
- }
121
- });
122
- const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
123
- expect(rootStyle.fontSize).toEqual(160);
124
- expect(_stylex.stylex.props.call(mockOptions, styles.withVars).style.fontSize).toEqual(rootStyle.fontSize);
125
- });
126
- test('prop lookup with ref', () => {
127
- const styles = _stylex.stylex.create({
128
- root: {
129
- borderWidth: 'var(--refToRawNumber)'
130
- },
131
- withVars: {
132
- borderWidth: 'var(--refToPixelNumber)'
133
- }
134
- });
135
- const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
136
- expect(rootStyle.borderWidth).toEqual(10);
137
- expect(_stylex.stylex.props.call(mockOptions, styles.withVars).style.borderWidth).toEqual(rootStyle.borderWidth);
138
- });
139
- test('prop lookup with ref to ref', () => {
140
- const styles = _stylex.stylex.create({
141
- root: {
142
- borderWidth: 'var(--refToRefToRawNumber)'
143
- }
144
- });
145
- const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
146
- expect(rootStyle.borderWidth).toEqual(10);
147
- });
148
- });