@stylexjs/stylex 0.1.0-beta.3 → 0.1.0-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/stylex",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "A minimal runtime styling library for web.",
5
5
  "main": "lib/stylex.js",
6
6
  "types": "lib/stylex.d.ts",
@@ -19,5 +19,8 @@
19
19
  "devDependencies": {
20
20
  "benchmark": "^2.1.4"
21
21
  },
22
- "jest": {}
22
+ "jest": {},
23
+ "files": [
24
+ "lib/*"
25
+ ]
23
26
  }
package/.babelrc.js DELETED
@@ -1,40 +0,0 @@
1
- function makeHaste() {
2
- return {
3
- visitor: {
4
- ImportDeclaration(path) {
5
- if (path.get('source').isStringLiteral()) {
6
- const oldValue = path.get('source').node.value;
7
- path.get('source').node.value = oldValue.slice(
8
- oldValue.lastIndexOf('/') + 1
9
- );
10
- }
11
- },
12
- },
13
- };
14
- }
15
-
16
- const presets = process.env['HASTE']
17
- ? []
18
- : [
19
- [
20
- '@babel/preset-env',
21
- {
22
- exclude: ['@babel/plugin-transform-typeof-symbol'],
23
- targets: 'defaults',
24
- },
25
- ],
26
- '@babel/preset-flow',
27
- '@babel/preset-react',
28
- ];
29
-
30
- const plugins = process.env['HASTE']
31
- ? [makeHaste, '@babel/plugin-syntax-flow', '@babel/plugin-syntax-jsx']
32
- : [];
33
-
34
- module.exports = {
35
- assumptions: {
36
- iterableIsArray: true,
37
- },
38
- presets,
39
- plugins,
40
- };
@@ -1,101 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- */
9
-
10
- 'use strict';
11
-
12
- import { StyleXSheet } from '../src/StyleXSheet';
13
-
14
- const testOpts = {
15
- rootTheme: undefined,
16
- supportsVariables: true,
17
- };
18
-
19
- test('StyleXSheet.prototype.insert', () => {
20
- const sheet = new StyleXSheet(testOpts);
21
-
22
- expect(sheet.getRuleCount()).toBe(0);
23
- sheet.inject();
24
- expect(sheet.getRuleCount()).toBe(0);
25
-
26
- sheet.insert('.a {}', 0);
27
- expect(sheet.getRuleCount()).toBe(1);
28
-
29
- sheet.insert('.b {}', 0);
30
- expect(sheet.getRuleCount()).toBe(2);
31
-
32
- sheet.insert('.b {}', 0);
33
- expect(sheet.getRuleCount()).toBe(2);
34
- });
35
-
36
- test('StyleXSheet.prototype.insert respects priorities', () => {
37
- const sheet = new StyleXSheet(testOpts);
38
-
39
- sheet.insert('.last {}', 6);
40
- sheet.insert('.third {}', 3);
41
- sheet.insert('.first {}', 0);
42
- sheet.insert('.second {}', 1);
43
-
44
- expect(sheet.getCSS()).toMatchInlineSnapshot(`
45
- ".first {}
46
- .second {}
47
- .third {}
48
- .last {}"
49
- `);
50
- });
51
-
52
- test('StyleXSheet.prototype.insert respects priority floats', () => {
53
- const sheet = new StyleXSheet(testOpts);
54
-
55
- sheet.insert('.fourth {}', 6.8);
56
- sheet.insert('.third {}', 6.5);
57
- sheet.insert('.second {}', 6);
58
- sheet.insert('.first {}', 2);
59
-
60
- expect(sheet.getCSS()).toMatchInlineSnapshot(`
61
- ".first {}
62
- .second {}
63
- .third {}
64
- .fourth {}"
65
- `);
66
- });
67
-
68
- test('StyleXSheet.prototype.insert handles RTL rules with media queries', () => {
69
- const sheet = new StyleXSheet(testOpts);
70
-
71
- sheet.insert(
72
- '@media (min-width: 1000px) { .foo {} }',
73
- 0,
74
- '@media (min-width: 1000px) { .foo {} }'
75
- );
76
-
77
- expect(sheet.getCSS()).toMatchInlineSnapshot(`
78
- "@media (min-width: 1000px) {html:not([dir='rtl']) .foo {} }
79
- @media (min-width: 1000px) {html[dir='rtl'] .foo {} }"
80
- `);
81
- });
82
-
83
- test('inlines variables for older browsers', () => {
84
- const sheet = new StyleXSheet({
85
- rootDarkTheme: { foo: 'reallydark' },
86
- rootTheme: { foo: 'bar' },
87
- supportsVariables: false,
88
- });
89
-
90
- sheet.insert('.foo {color: var(--foo)}', 1);
91
-
92
- expect(sheet.getCSS()).toMatchInlineSnapshot(`
93
- ":root, .__fb-light-mode {
94
- --foo: bar;
95
- }
96
- .__fb-dark-mode:root, .__fb-dark-mode {
97
- --foo: reallydark;
98
- }
99
- .foo {color: bar}"
100
- `);
101
- });
@@ -1,202 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @noflow
8
- */
9
-
10
- 'use strict';
11
-
12
- import { styleSheet } from '../src/StyleXSheet';
13
- import stylex from '../src/stylex';
14
-
15
- // TODO: priorities need testing
16
- test('stylex.inject', () => {
17
- const prevCount = styleSheet.getRuleCount();
18
- stylex.inject('hey {}', 0);
19
- expect(styleSheet.getRuleCount()).toBeGreaterThan(prevCount);
20
- });
21
-
22
- describe('stylex', () => {
23
- test('basic resolve', () => {
24
- expect(stylex({ a: 'aaa', b: 'bbb' })).toBe('aaa bbb');
25
- });
26
-
27
- test('merge order', () => {
28
- expect(
29
- stylex([
30
- { a: 'a', ':hover': { aa: 'aa' } },
31
- { b: 'b' },
32
- { c: 'c', ':hover': { cc: 'cc' } },
33
- ])
34
- ).toBe('a aa b c cc');
35
- });
36
-
37
- test('with a top-level array of simple overridden classes', () => {
38
- expect(
39
- stylex([
40
- {
41
- backgroundColor: 'nu7423ey',
42
- },
43
- {
44
- backgroundColor: 'gh25dzvf',
45
- },
46
- ])
47
- ).toEqual('gh25dzvf');
48
- });
49
-
50
- test('with nested arrays and pseudoClasses overriding things', () => {
51
- expect(
52
- stylex([
53
- {
54
- backgroundColor: 'nu7423ey',
55
- },
56
- [
57
- {
58
- backgroundColor: 'abcdefg',
59
- ':hover': {
60
- backgroundColor: 'ksdfmwjs',
61
- },
62
- },
63
- ],
64
- {
65
- color: 'gofk2cf1',
66
- ':hover': {
67
- backgroundColor: 'rse6dlih',
68
- },
69
- },
70
- ])
71
- ).toEqual('abcdefg gofk2cf1 rse6dlih');
72
- });
73
-
74
- test('with just pseudoclasses', () => {
75
- expect(
76
- stylex(
77
- {
78
- ':hover': {
79
- backgroundColor: 'rse6dlih',
80
- },
81
- },
82
- {
83
- ':hover': {
84
- color: 'gofk2cf1',
85
- },
86
- }
87
- )
88
- ).toEqual('rse6dlih gofk2cf1');
89
- });
90
-
91
- test('with complicated set of arguments', () => {
92
- const styles = [
93
- {
94
- backgroundColor: 'nu7423ey',
95
- borderColor: 'tpe1esc0',
96
- borderStyle: 'gewhe1h2',
97
- borderWidth: 'gcovof34',
98
- boxSizing: 'bdao358l',
99
- display: 'rse6dlih',
100
- listStyle: 's5oniofx',
101
- marginTop: 'm8h3af8h',
102
- marginEnd: 'l7ghb35v',
103
- marginBottom: 'kjdc1dyq',
104
- marginStart: 'kmwttqpk',
105
- paddingTop: 'srn514ro',
106
- paddingEnd: 'oxkhqvkx',
107
- paddingBottom: 'rl78xhln',
108
- paddingStart: 'nch0832m',
109
- WebkitTapHighlightColor: 'qi72231t',
110
- textAlign: 'cr00lzj9',
111
- textDecoration: 'rn8ck1ys',
112
- whiteSpace: 'n3t5jt4f',
113
- wordWrap: 'gh25dzvf',
114
- zIndex: 'g4tp4svg',
115
- },
116
- false,
117
- false,
118
- false,
119
- false,
120
- [
121
- {
122
- cursor: 'fsf7x5fv',
123
- touchAction: 's3jn8y49',
124
- },
125
- false,
126
- {
127
- outline: 'icdlwmnq',
128
- },
129
- [
130
- {
131
- WebkitTapHighlightColor: 'oajrlxb2',
132
- cursor: 'nhd2j8a9',
133
- touchAction: 'f1sip0of',
134
- },
135
- false,
136
- false,
137
- {
138
- textDecoration: 'esuyzwwr',
139
- ':hover': {
140
- textDecoration: 'p8dawk7l',
141
- },
142
- },
143
- false,
144
- [
145
- {
146
- backgroundColor: 'g5ia77u1',
147
- border: 'e4t7hp5w',
148
- color: 'gmql0nx0',
149
- cursor: 'nhd2j8a9',
150
- display: 'q9uorilb',
151
- fontFamily: 'ihxqhq3m',
152
- fontSize: 'l94mrbxd',
153
- lineHeight: 'aenfhxwr',
154
- marginTop: 'kvgmc6g5',
155
- marginEnd: 'cxmmr5t8',
156
- marginBottom: 'oygrvhab',
157
- marginStart: 'hcukyx3x',
158
- paddingTop: 'jb3vyjys',
159
- paddingEnd: 'rz4wbd8a',
160
- paddingBottom: 'qt6c0cv9',
161
- paddingStart: 'a8nywdso',
162
- textAlign: 'i1ao9s8h',
163
- textDecoration: 'myohyog2',
164
- ':hover': {
165
- color: 'ksdfmwjs',
166
- textDecoration: 'gofk2cf1',
167
- },
168
- ':active': {
169
- transform: 'lsqurvkf',
170
- transition: 'bj9fd4vl',
171
- },
172
- },
173
- {
174
- display: 'a8c37x1j',
175
- width: 'k4urcfbm',
176
- },
177
- [
178
- {
179
- ':active': {
180
- transform: 'tm8avpzi',
181
- },
182
- },
183
- ],
184
- ],
185
- ],
186
- ],
187
- ];
188
-
189
- const value = stylex(styles);
190
- const repeat = stylex(styles);
191
-
192
- // Check the cached-derived result is correct
193
- expect(value).toEqual(repeat);
194
-
195
- expect(value.split(' ').sort().join(' ')).toEqual(
196
- 'g5ia77u1 tpe1esc0 gewhe1h2 gcovof34 bdao358l a8c37x1j s5oniofx kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso oajrlxb2 i1ao9s8h myohyog2 n3t5jt4f gh25dzvf g4tp4svg nhd2j8a9 f1sip0of icdlwmnq e4t7hp5w gmql0nx0 ihxqhq3m l94mrbxd aenfhxwr k4urcfbm gofk2cf1 ksdfmwjs tm8avpzi bj9fd4vl'
197
- .split(' ')
198
- .sort()
199
- .join(' ')
200
- );
201
- });
202
- });
package/benchmark.js DELETED
@@ -1,144 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- const stylex = require('./lib/stylex').default;
9
- const Benchmark = require('benchmark');
10
- const suite = new Benchmark.Suite();
11
- const test = (...args) => suite.add(...args);
12
-
13
- const basicStyleFixture1 = {
14
- backgroundColor: 'nu7423ey',
15
- };
16
-
17
- const basicStyleFixture2 = {
18
- backgroundColor: 'gh25dzvf',
19
- };
20
-
21
- const bigStyleFixture = {
22
- backgroundColor: 'nu7423ey',
23
- borderColor: 'tpe1esc0',
24
- borderStyle: 'gewhe1h2',
25
- borderWidth: 'gcovof34',
26
- boxSizing: 'bdao358l',
27
- display: 'rse6dlih',
28
- listStyle: 's5oniofx',
29
- marginTop: 'm8h3af8h',
30
- marginEnd: 'l7ghb35v',
31
- marginBottom: 'kjdc1dyq',
32
- marginStart: 'kmwttqpk',
33
- paddingTop: 'srn514ro',
34
- paddingEnd: 'oxkhqvkx',
35
- paddingBottom: 'rl78xhln',
36
- paddingStart: 'nch0832m',
37
- textAlign: 'cr00lzj9',
38
- textDecoration: 'rn8ck1ys',
39
- whiteSpace: 'n3t5jt4f',
40
- wordWrap: 'gh25dzvf',
41
- zIndex: 'g4tp4svg',
42
- };
43
-
44
- const bigStyleWithPseudosFixture = {
45
- backgroundColor: 'g5ia77u1',
46
- border: 'e4t7hp5w',
47
- color: 'gmql0nx0',
48
- cursor: 'nhd2j8a9',
49
- display: 'q9uorilb',
50
- fontFamily: 'ihxqhq3m',
51
- fontSize: 'l94mrbxd',
52
- lineHeight: 'aenfhxwr',
53
- marginTop: 'kvgmc6g5',
54
- marginEnd: 'cxmmr5t8',
55
- marginBottom: 'oygrvhab',
56
- marginStart: 'hcukyx3x',
57
- paddingTop: 'jb3vyjys',
58
- paddingEnd: 'rz4wbd8a',
59
- paddingBottom: 'qt6c0cv9',
60
- paddingStart: 'a8nywdso',
61
- textAlign: 'i1ao9s8h',
62
- textDecoration: 'myohyog2',
63
- ':hover': {
64
- color: 'ksdfmwjs',
65
- textDecoration: 'gofk2cf1',
66
- },
67
- ':active': {
68
- transform: 'lsqurvkf',
69
- transition: 'bj9fd4vl',
70
- },
71
- };
72
-
73
- test('stylex(): basic', () => {
74
- stylex(basicStyleFixture1);
75
- });
76
-
77
- test('stylex(): complex', () => {
78
- stylex(bigStyleFixture);
79
- });
80
-
81
- test('stylex(): basic merge (args)', () => {
82
- stylex(basicStyleFixture1, basicStyleFixture2);
83
- });
84
-
85
- test('stylex(): basic merge (array)', () => {
86
- stylex([basicStyleFixture1, basicStyleFixture2]);
87
- });
88
-
89
- const complexNestedStyleFixture = [
90
- bigStyleFixture,
91
- false,
92
- false,
93
- false,
94
- false,
95
- [
96
- {
97
- cursor: 'fsf7x5fv',
98
- touchAction: 's3jn8y49',
99
- },
100
- false,
101
- {
102
- outline: 'icdlwmnq',
103
- },
104
- [
105
- {
106
- cursor: 'nhd2j8a9',
107
- touchAction: 'f1sip0of',
108
- },
109
- false,
110
- false,
111
- {
112
- textDecoration: 'esuyzwwr',
113
- ':hover': {
114
- textDecoration: 'p8dawk7l',
115
- },
116
- },
117
- false,
118
- [
119
- bigStyleWithPseudosFixture,
120
- {
121
- display: 'a8c37x1j',
122
- width: 'k4urcfbm',
123
- },
124
- [
125
- {
126
- ':active': {
127
- transform: 'tm8avpzi',
128
- },
129
- },
130
- ],
131
- ],
132
- ],
133
- ],
134
- ];
135
-
136
- test('stylex(): complex merge (array)', () => {
137
- stylex([complexNestedStyleFixture]);
138
- });
139
-
140
- suite.on('cycle', (event) => {
141
- console.log(String(event.target));
142
- });
143
-
144
- suite.run();