@stylexjs/stylex 0.2.0-beta.21 → 0.2.0-beta.23

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.
@@ -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 = "@media";
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 ? "landscape" : "portrait",
49
- "aspect-ratio": width / height,
48
+ orientation: width > height ? 'landscape' : 'portrait',
49
+ 'aspect-ratio': width / height,
50
50
  direction: direction
51
51
  });
52
52
  return matches ? this.matchedStyle : {};
@@ -7,12 +7,13 @@
7
7
  *
8
8
  */
9
9
 
10
- export type SpreadOptions = {
10
+ export type SpreadOptions = Readonly<{
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;
17
18
  writingDirection: 'ltr' | 'rtl';
18
- };
19
+ }>;
@@ -7,12 +7,13 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- export type SpreadOptions = {|
10
+ export type SpreadOptions = $ReadOnly<{
11
11
  customProperties: {},
12
12
  inheritedFontSize: ?number,
13
13
  fontScale: number | void,
14
+ hover?: ?boolean,
14
15
  passthroughProperties: Array<string>,
15
16
  viewportHeight: number,
16
17
  viewportWidth: number,
17
18
  writingDirection: 'ltr' | 'rtl',
18
- |};
19
+ }>;
@@ -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 = [["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", () => {
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: "red",
7
- testVar2: "blue",
8
- boxShadowVar1: "5px 5px 5px black",
6
+ testVar: 'red',
7
+ testVar2: 'blue',
8
+ boxShadowVar1: '5px 5px 5px black',
9
9
  rawNumber: 10,
10
- pixelNumber: "10px",
11
- emNumber: "10em",
12
- refToRawNumber: "var(--rawNumber)",
13
- refToPixelNumber: "var(--pixelNumber)",
14
- refToRefToRawNumber: "var(--refToRawNumber)"
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.spread(styles.root, mockOptions).style.color;
25
+ return _stylex.stylex.props.call(mockOptions, styles.root).style.color;
26
26
  }
27
- describe("stylex CSSCustomProperty value test", () => {
27
+ describe('stylex CSSCustomProperty value test', () => {
28
28
  beforeEach(() => {
29
- jest.spyOn(console, "warn");
29
+ jest.spyOn(console, 'warn');
30
30
  console.warn.mockImplementation(() => {});
31
31
  });
32
32
  afterEach(() => {
33
33
  console.warn.mockRestore();
34
34
  });
35
- test("parses a basic variable correctly", () => {
36
- expect(resolveColorValue("var(--testVar)")).toEqual("red");
35
+ test('parses a basic variable correctly', () => {
36
+ expect(resolveColorValue('var(--testVar)')).toEqual('red');
37
37
  });
38
- test("parses kebab case to camel case", () => {
39
- expect(resolveColorValue("var(--test-var)")).toEqual("red");
38
+ test('parses kebab case to camel case', () => {
39
+ expect(resolveColorValue('var(--test-var)')).toEqual('red');
40
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");
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("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");
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("parses a variable with a default value with spaces", () => {
49
+ test('parses a variable with a default value with spaces', () => {
50
50
  const styles = _stylex.stylex.create({
51
51
  root: {
52
- boxShadow: "var(--boxShadowVar1, 0px 0px 0px black)"
52
+ boxShadow: 'var(--boxShadowVar1, 0px 0px 0px black)'
53
53
  }
54
54
  });
55
- expect(_stylex.stylex.spread(styles.root, mockOptions)).toMatchSnapshot();
55
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
56
56
  });
57
- test("falls back to a default value with spaces", () => {
57
+ test('falls back to a default value with spaces', () => {
58
58
  const styles = _stylex.stylex.create({
59
59
  root: {
60
- boxShadow: "var(--boxShadowVarNotFound, 0px 0px 0px black)"
60
+ boxShadow: 'var(--boxShadowVarNotFound, 0px 0px 0px black)'
61
61
  }
62
62
  });
63
- expect(_stylex.stylex.spread(styles.root, mockOptions)).toMatchSnapshot();
63
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
64
64
  });
65
- test("parses and falls back to default value containing a variable", () => {
65
+ test('parses and falls back to default value containing a variable', () => {
66
66
  const styles = _stylex.stylex.create({
67
67
  root: {
68
- color: "var(--colorNotFound, var(--testVar2))"
68
+ color: 'var(--colorNotFound, var(--testVar2))'
69
69
  }
70
70
  });
71
- expect(_stylex.stylex.spread(styles.root, mockOptions)).toMatchSnapshot();
71
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
72
72
  });
73
- test("parses and falls back to a default value containing spaces and embedded variables", () => {
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: "var(--boxShadowVarNotFound, 0px 0px 0px var(--testVar2))"
76
+ boxShadow: 'var(--boxShadowVarNotFound, 0px 0px 0px var(--testVar2))'
77
77
  }
78
78
  });
79
- expect(_stylex.stylex.spread(styles.root, mockOptions)).toMatchSnapshot();
79
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
80
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)");
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("basic value lookup works", () => {
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: "var(--rawNumber)"
93
+ borderWidth: 'var(--rawNumber)'
94
94
  }
95
95
  });
96
- const rootStyle = _stylex.stylex.spread(styles.root, mockOptions).style;
96
+ const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
97
97
  expect(rootStyle.borderWidth).toEqual(10);
98
- expect(_stylex.stylex.spread(styles.withVars, mockOptions).style.borderWidth).toEqual(rootStyle.borderWidth);
98
+ expect(_stylex.stylex.props.call(mockOptions, styles.withVars).style.borderWidth).toEqual(rootStyle.borderWidth);
99
99
  });
100
- test("value lookup with pixel prop conversion", () => {
100
+ test('value lookup with pixel prop conversion', () => {
101
101
  const styles = _stylex.stylex.create({
102
102
  root: {
103
- borderWidth: "10px"
103
+ borderWidth: '10px'
104
104
  },
105
105
  withVars: {
106
- borderWidth: "var(--pixelNumber)"
106
+ borderWidth: 'var(--pixelNumber)'
107
107
  }
108
108
  });
109
- const rootStyle = _stylex.stylex.spread(styles.root, mockOptions).style;
109
+ const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
110
110
  expect(rootStyle.borderWidth).toEqual(10);
111
- expect(_stylex.stylex.spread(styles.withVars, mockOptions).style.borderWidth).toEqual(rootStyle.borderWidth);
111
+ expect(_stylex.stylex.props.call(mockOptions, styles.withVars).style.borderWidth).toEqual(rootStyle.borderWidth);
112
112
  });
113
- test("value lookup with em prop conversion", () => {
113
+ test('value lookup with em prop conversion', () => {
114
114
  const styles = _stylex.stylex.create({
115
115
  root: {
116
- fontSize: "10em"
116
+ fontSize: '10em'
117
117
  },
118
118
  withVars: {
119
- fontSize: "var(--emNumber)"
119
+ fontSize: 'var(--emNumber)'
120
120
  }
121
121
  });
122
- const rootStyle = _stylex.stylex.spread(styles.root, mockOptions).style;
122
+ const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
123
123
  expect(rootStyle.fontSize).toEqual(160);
124
- expect(_stylex.stylex.spread(styles.withVars, mockOptions).style.fontSize).toEqual(rootStyle.fontSize);
124
+ expect(_stylex.stylex.props.call(mockOptions, styles.withVars).style.fontSize).toEqual(rootStyle.fontSize);
125
125
  });
126
- test("prop lookup with ref", () => {
126
+ test('prop lookup with ref', () => {
127
127
  const styles = _stylex.stylex.create({
128
128
  root: {
129
- borderWidth: "var(--refToRawNumber)"
129
+ borderWidth: 'var(--refToRawNumber)'
130
130
  },
131
131
  withVars: {
132
- borderWidth: "var(--refToPixelNumber)"
132
+ borderWidth: 'var(--refToPixelNumber)'
133
133
  }
134
134
  });
135
- const rootStyle = _stylex.stylex.spread(styles.root, mockOptions).style;
135
+ const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
136
136
  expect(rootStyle.borderWidth).toEqual(10);
137
- expect(_stylex.stylex.spread(styles.withVars, mockOptions).style.borderWidth).toEqual(rootStyle.borderWidth);
137
+ expect(_stylex.stylex.props.call(mockOptions, styles.withVars).style.borderWidth).toEqual(rootStyle.borderWidth);
138
138
  });
139
- test("prop lookup with ref to ref", () => {
139
+ test('prop lookup with ref to ref', () => {
140
140
  const styles = _stylex.stylex.create({
141
141
  root: {
142
- borderWidth: "var(--refToRefToRawNumber)"
142
+ borderWidth: 'var(--refToRefToRawNumber)'
143
143
  }
144
144
  });
145
- const rootStyle = _stylex.stylex.spread(styles.root, mockOptions).style;
145
+ const rootStyle = _stylex.stylex.props.call(mockOptions, styles.root).style;
146
146
  expect(rootStyle.borderWidth).toEqual(10);
147
147
  });
148
148
  });