@stylexjs/stylex 0.2.0-beta.8 → 0.3.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 (52) hide show
  1. package/README.md +284 -0
  2. package/lib/StyleXCSSTypes.d.ts +1414 -0
  3. package/lib/StyleXCSSTypes.js +0 -9
  4. package/lib/StyleXCSSTypes.js.flow +1503 -0
  5. package/lib/StyleXSheet.d.ts +49 -0
  6. package/lib/StyleXSheet.js +7 -120
  7. package/lib/StyleXSheet.js.flow +49 -0
  8. package/lib/StyleXTypes.d.ts +212 -0
  9. package/lib/StyleXTypes.js +0 -9
  10. package/lib/StyleXTypes.js.flow +184 -0
  11. package/lib/native/CSSCustomPropertyValue.d.ts +26 -0
  12. package/lib/native/CSSCustomPropertyValue.js +27 -0
  13. package/lib/native/CSSCustomPropertyValue.js.flow +27 -0
  14. package/lib/native/CSSLengthUnitValue.d.ts +18 -0
  15. package/lib/native/CSSLengthUnitValue.js +73 -0
  16. package/lib/native/CSSLengthUnitValue.js.flow +21 -0
  17. package/lib/native/CSSMediaQuery.d.ts +25 -0
  18. package/lib/native/CSSMediaQuery.js +55 -0
  19. package/lib/native/CSSMediaQuery.js.flow +26 -0
  20. package/lib/native/SpreadOptions.d.ts +19 -0
  21. package/lib/native/SpreadOptions.js +1 -0
  22. package/lib/native/SpreadOptions.js.flow +19 -0
  23. package/lib/native/__tests__/__snapshots__/stylex-css-var-test.js.snap +48 -0
  24. package/lib/native/__tests__/__snapshots__/stylex-test.js.snap +1046 -0
  25. package/lib/native/__tests__/parseTimeValue-test.js +11 -0
  26. package/lib/native/__tests__/stylex-css-var-test.js +148 -0
  27. package/lib/native/__tests__/stylex-test.js +924 -0
  28. package/lib/native/errorMsg.d.ts +11 -0
  29. package/lib/native/errorMsg.js +13 -0
  30. package/lib/native/errorMsg.js.flow +12 -0
  31. package/lib/native/fixContentBox.d.ts +11 -0
  32. package/lib/native/fixContentBox.js +59 -0
  33. package/lib/native/fixContentBox.js.flow +11 -0
  34. package/lib/native/flattenStyle.d.ts +15 -0
  35. package/lib/native/flattenStyle.js +20 -0
  36. package/lib/native/flattenStyle.js.flow +20 -0
  37. package/lib/native/parseShadow.d.ts +18 -0
  38. package/lib/native/parseShadow.js +36 -0
  39. package/lib/native/parseShadow.js.flow +19 -0
  40. package/lib/native/parseTimeValue.d.ts +11 -0
  41. package/lib/native/parseTimeValue.js +18 -0
  42. package/lib/native/parseTimeValue.js.flow +12 -0
  43. package/lib/native/stylex.d.ts +50 -0
  44. package/lib/native/stylex.js +393 -0
  45. package/lib/native/stylex.js.flow +60 -0
  46. package/lib/stylex-inject.d.ts +15 -0
  47. package/lib/stylex-inject.js +0 -9
  48. package/lib/stylex-inject.js.flow +14 -0
  49. package/lib/stylex.d.ts +134 -59
  50. package/lib/stylex.js +123 -91
  51. package/lib/stylex.js.flow +151 -0
  52. package/package.json +8 -6
@@ -0,0 +1,924 @@
1
+ "use strict";
2
+
3
+ var _stylex = require("../stylex");
4
+ const mockOptions = {
5
+ customProperties: {},
6
+ hover: false,
7
+ viewportHeight: 600,
8
+ viewportWidth: 320
9
+ };
10
+ describe('styles', () => {
11
+ beforeEach(() => {
12
+ jest.spyOn(console, 'warn');
13
+ console.warn.mockImplementation(() => {});
14
+ });
15
+ afterEach(() => {
16
+ console.warn.mockRestore();
17
+ });
18
+ test('animation-delay', () => {
19
+ const styles = _stylex.stylex.create({
20
+ root: {
21
+ animationDelay: '0.3s'
22
+ }
23
+ });
24
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
25
+ });
26
+ test('animation-duration', () => {
27
+ const styles = _stylex.stylex.create({
28
+ root: {
29
+ animationDuration: '0.5s'
30
+ }
31
+ });
32
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
33
+ });
34
+ test('background-image', () => {
35
+ const styles = _stylex.stylex.create({
36
+ root: {
37
+ backgroundImage: 'url(https://placehold.it/300/300'
38
+ }
39
+ });
40
+ _stylex.stylex.props.call(mockOptions, styles.root);
41
+ expect(console.warn).toHaveBeenCalled();
42
+ });
43
+ test('border-style', () => {
44
+ const styles = _stylex.stylex.create({
45
+ root: {
46
+ borderStyle: 'none',
47
+ borderWidth: 10
48
+ },
49
+ override: {
50
+ borderStyle: 'solid'
51
+ }
52
+ });
53
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
54
+ expect(_stylex.stylex.props.call(mockOptions, styles.root, styles.override)).toMatchSnapshot();
55
+ });
56
+ test('box-shadow', () => {
57
+ const styles = _stylex.stylex.create({
58
+ root: {
59
+ boxShadow: '1px 2px 3px 4px red'
60
+ }
61
+ });
62
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
63
+ const styles2 = _stylex.stylex.create({
64
+ root: {
65
+ boxShadow: '1px 2px 3px 4px red, 2px 3px 4px 5px blue'
66
+ }
67
+ });
68
+ _stylex.stylex.props.call(mockOptions, styles2.root);
69
+ expect(console.warn).toHaveBeenCalledTimes(1);
70
+ const styles3 = _stylex.stylex.create({
71
+ root: {
72
+ boxShadow: 'inset 1px 2px 3px 4px red'
73
+ }
74
+ });
75
+ _stylex.stylex.props.call(mockOptions, styles3.root);
76
+ expect(console.warn).toHaveBeenCalledTimes(2);
77
+ });
78
+ test('box-sizing: content-box', () => {
79
+ const styles = _stylex.stylex.create({
80
+ width: {
81
+ boxSizing: 'content-box',
82
+ borderWidth: 2,
83
+ padding: 10,
84
+ width: 100,
85
+ overflow: 'hidden'
86
+ },
87
+ height: {
88
+ boxSizing: 'content-box',
89
+ borderWidth: 2,
90
+ padding: 10,
91
+ height: 50
92
+ },
93
+ maxWidth: {
94
+ boxSizing: 'content-box',
95
+ borderWidth: 2,
96
+ padding: 10,
97
+ maxWidth: 100
98
+ },
99
+ minWidth: {
100
+ boxSizing: 'content-box',
101
+ borderWidth: 2,
102
+ padding: 10,
103
+ minWidth: 100
104
+ },
105
+ maxHeight: {
106
+ boxSizing: 'content-box',
107
+ borderWidth: 2,
108
+ padding: 10,
109
+ maxHeight: 50
110
+ },
111
+ minHeight: {
112
+ boxSizing: 'content-box',
113
+ borderWidth: 2,
114
+ padding: 10,
115
+ minHeight: 50
116
+ },
117
+ units: {
118
+ boxSizing: 'content-box',
119
+ borderWidth: 2,
120
+ padding: '1rem',
121
+ width: '100px',
122
+ height: 50
123
+ },
124
+ allDifferent: {
125
+ boxSizing: 'content-box',
126
+ borderTopWidth: 1,
127
+ borderRightWidth: 2,
128
+ borderBottomWidth: 3,
129
+ borderLeftWidth: 4,
130
+ paddingTop: 10,
131
+ paddingRight: 20,
132
+ paddingBottom: 30,
133
+ paddingLeft: 40,
134
+ width: 100,
135
+ height: 100
136
+ },
137
+ auto: {
138
+ boxSizing: 'content-box',
139
+ borderWidth: 2,
140
+ padding: 10,
141
+ height: 50,
142
+ width: 'auto'
143
+ }
144
+ });
145
+ expect(_stylex.stylex.props.call(mockOptions, styles.width)).toMatchSnapshot('width');
146
+ expect(_stylex.stylex.props.call(mockOptions, styles.height)).toMatchSnapshot('height');
147
+ expect(_stylex.stylex.props.call(mockOptions, styles.maxWidth)).toMatchSnapshot('maxWidth');
148
+ expect(_stylex.stylex.props.call(mockOptions, styles.maxHeight)).toMatchSnapshot('maxHeight');
149
+ expect(_stylex.stylex.props.call(mockOptions, styles.minWidth)).toMatchSnapshot('minWidth');
150
+ expect(_stylex.stylex.props.call(mockOptions, styles.minHeight)).toMatchSnapshot('minHeight');
151
+ expect(_stylex.stylex.props.call(mockOptions, styles.units)).toMatchSnapshot('units');
152
+ expect(_stylex.stylex.props.call(mockOptions, styles.allDifferent)).toMatchSnapshot('allDifferent');
153
+ expect(_stylex.stylex.props.call(mockOptions, styles.auto)).toMatchSnapshot('auto');
154
+ });
155
+ test('direction', () => {
156
+ const styles = _stylex.stylex.create({
157
+ root: {
158
+ direction: 'ltr'
159
+ }
160
+ });
161
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
162
+ const styles2 = _stylex.stylex.create({
163
+ root: {
164
+ direction: 'rtl'
165
+ }
166
+ });
167
+ expect(_stylex.stylex.props.call(mockOptions, styles2.root)).toMatchSnapshot();
168
+ });
169
+ test('font-size', () => {
170
+ const styles = _stylex.stylex.create({
171
+ root: {
172
+ fontSize: '2.5rem'
173
+ }
174
+ });
175
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot('default');
176
+ expect(_stylex.stylex.props.call({
177
+ ...mockOptions,
178
+ fontScale: 2
179
+ }, styles.root)).toMatchSnapshot('fontScale:2');
180
+ });
181
+ test('font-variant', () => {
182
+ const styles = _stylex.stylex.create({
183
+ root: {
184
+ fontVariant: 'common-ligatures small-caps'
185
+ }
186
+ });
187
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
188
+ });
189
+ test('font-weight', () => {
190
+ const styles = _stylex.stylex.create({
191
+ root: {
192
+ fontWeight: 900
193
+ }
194
+ });
195
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
196
+ const styles2 = _stylex.stylex.create({
197
+ root: {
198
+ fontWeight: 'bold'
199
+ }
200
+ });
201
+ expect(_stylex.stylex.props.call(mockOptions, styles2.root)).toMatchSnapshot();
202
+ });
203
+ test('line-clamp', () => {
204
+ const styles = _stylex.stylex.create({
205
+ root: {
206
+ lineClamp: 3
207
+ }
208
+ });
209
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
210
+ });
211
+ test('line-height', () => {
212
+ const styles = _stylex.stylex.create({
213
+ numeric: {
214
+ lineHeight: 1.5
215
+ },
216
+ string: {
217
+ lineHeight: '1.5'
218
+ },
219
+ rem: {
220
+ lineHeight: '1.5rem'
221
+ },
222
+ px: {
223
+ lineHeight: '24px'
224
+ }
225
+ });
226
+ expect(_stylex.stylex.props.call(mockOptions, styles.numeric)).toMatchSnapshot('unitless number');
227
+ expect(_stylex.stylex.props.call(mockOptions, styles.string)).toMatchSnapshot('unitless string');
228
+ expect(_stylex.stylex.props.call(mockOptions, styles.rem)).toMatchSnapshot('rem');
229
+ expect(_stylex.stylex.props.call(mockOptions, styles.px)).toMatchSnapshot('px');
230
+ });
231
+ test('object-fit', () => {
232
+ const styles = _stylex.stylex.create({
233
+ contain: {
234
+ objectFit: 'contain'
235
+ },
236
+ cover: {
237
+ objectFit: 'cover'
238
+ },
239
+ fill: {
240
+ objectFit: 'fill'
241
+ },
242
+ scaleDown: {
243
+ objectFit: 'scale-down'
244
+ },
245
+ none: {
246
+ objectFit: 'none'
247
+ }
248
+ });
249
+ expect(_stylex.stylex.props.call(mockOptions, styles.contain)).toMatchSnapshot('contain');
250
+ expect(_stylex.stylex.props.call(mockOptions, styles.cover)).toMatchSnapshot('contain');
251
+ expect(_stylex.stylex.props.call(mockOptions, styles.fill)).toMatchSnapshot('fill');
252
+ expect(_stylex.stylex.props.call(mockOptions, styles.scaleDown)).toMatchSnapshot('scaleDown');
253
+ expect(_stylex.stylex.props.call(mockOptions, styles.none)).toMatchSnapshot('none');
254
+ });
255
+ test('pointer-events', () => {
256
+ const styles = _stylex.stylex.create({
257
+ root: {
258
+ pointerEvents: 'none'
259
+ }
260
+ });
261
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
262
+ });
263
+ test('position', () => {
264
+ const styles = _stylex.stylex.create({
265
+ static: {
266
+ position: 'static'
267
+ },
268
+ relative: {
269
+ position: 'relative'
270
+ },
271
+ absolute: {
272
+ position: 'absolute'
273
+ },
274
+ fixed: {
275
+ position: 'fixed'
276
+ },
277
+ sticky: {
278
+ position: 'sticky'
279
+ }
280
+ });
281
+ expect(_stylex.stylex.props.call(mockOptions, styles.static)).toMatchSnapshot('static');
282
+ expect(_stylex.stylex.props.call(mockOptions, styles.relative)).toMatchSnapshot('relative');
283
+ expect(_stylex.stylex.props.call(mockOptions, styles.absolute)).toMatchSnapshot('absolute');
284
+ expect(_stylex.stylex.props.call(mockOptions, styles.fixed)).toMatchSnapshot('fixed');
285
+ expect(_stylex.stylex.props.call(mockOptions, styles.sticky)).toMatchSnapshot('sticky');
286
+ expect(console.warn).toHaveBeenCalledTimes(3);
287
+ });
288
+ test('text-shadow', () => {
289
+ const styles = _stylex.stylex.create({
290
+ root: {
291
+ textShadow: '1px 2px 3px red'
292
+ }
293
+ });
294
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
295
+ const styles2 = _stylex.stylex.create({
296
+ root: {
297
+ textShadow: '1px 2px 3px red, 2px 3px 4px blue'
298
+ }
299
+ });
300
+ expect(_stylex.stylex.props.call(mockOptions, styles2.root)).toMatchSnapshot();
301
+ expect(console.warn).toHaveBeenCalledTimes(1);
302
+ });
303
+ test('transform', () => {
304
+ const styles = _stylex.stylex.create({
305
+ none: {
306
+ transform: 'none'
307
+ },
308
+ matrix: {
309
+ transform: 'matrix(0.1, 1, -0.3, 1, 0, 0)'
310
+ },
311
+ perspective: {
312
+ transform: 'perspective(10px)'
313
+ },
314
+ rotate: {
315
+ transform: 'rotate(10deg) rotateX(20deg) rotateY(30deg) rotateZ(40deg) rotate3d(0, 0.5, 1, 90deg)'
316
+ },
317
+ scale: {
318
+ transform: 'scale(1, 2) scaleX(1) scaleY(2) scaleZ(3) scale3d(1, 2, 3)'
319
+ },
320
+ skew: {
321
+ transform: 'skew(10deg, 15deg) skewX(20deg) skewY(30deg)'
322
+ },
323
+ translate: {
324
+ transform: 'translate(10px, 20px) translateX(11px) translateY(12px) translateZ(13px) translate3d(20px, 30px, 40px)'
325
+ },
326
+ mixed: {
327
+ transform: `
328
+ rotateX(1deg) rotateY(2deg) rotateZ(3deg) rotate3d(1deg, 2deg, 3deg)
329
+ scale(1) scaleX(2) scaleY(3) scaleZ(4) scale3d(1,2,3)
330
+ translateX(1px) translateY(1em) translateZ(1rem) translate3d(1px, 1em, 1rem)
331
+ `
332
+ }
333
+ });
334
+ expect(_stylex.stylex.props.call(mockOptions, styles.none)).toMatchSnapshot('none');
335
+ expect(_stylex.stylex.props.call(mockOptions, styles.matrix)).toMatchSnapshot('matrix');
336
+ expect(_stylex.stylex.props.call(mockOptions, styles.perspective)).toMatchSnapshot('perspective');
337
+ expect(_stylex.stylex.props.call(mockOptions, styles.rotate)).toMatchSnapshot('rotate');
338
+ expect(_stylex.stylex.props.call(mockOptions, styles.scale)).toMatchSnapshot('scale');
339
+ expect(_stylex.stylex.props.call(mockOptions, styles.skew)).toMatchSnapshot('skew');
340
+ expect(_stylex.stylex.props.call(mockOptions, styles.translate)).toMatchSnapshot('translate');
341
+ expect(_stylex.stylex.props.call(mockOptions, styles.rotate)).toMatchSnapshot('rotate');
342
+ expect(_stylex.stylex.props.call(mockOptions, styles.mixed)).toMatchSnapshot('mixed');
343
+ });
344
+ test('transition-delay', () => {
345
+ const styles = _stylex.stylex.create({
346
+ root: {
347
+ transitionDelay: '0.3s'
348
+ }
349
+ });
350
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
351
+ });
352
+ test('transition-duration', () => {
353
+ const styles = _stylex.stylex.create({
354
+ root: {
355
+ transitionDuration: '0.5s'
356
+ }
357
+ });
358
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
359
+ });
360
+ test('user-select', () => {
361
+ const styles = _stylex.stylex.create({
362
+ root: {
363
+ userSelect: 'none'
364
+ }
365
+ });
366
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
367
+ });
368
+ test('vertical-align', () => {
369
+ const styles = _stylex.stylex.create({
370
+ middle: {
371
+ verticalAlign: 'middle'
372
+ },
373
+ top: {
374
+ verticalAlign: 'top'
375
+ }
376
+ });
377
+ expect(_stylex.stylex.props.call(mockOptions, styles.middle)).toMatchSnapshot('middle');
378
+ expect(_stylex.stylex.props.call(mockOptions, styles.top)).toMatchSnapshot('top');
379
+ });
380
+ test(':hover syntax', () => {
381
+ const styles = _stylex.stylex.create({
382
+ root: {
383
+ backgroundColor: {
384
+ default: 'red',
385
+ ':hover': 'blue'
386
+ }
387
+ }
388
+ });
389
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot('not hovered');
390
+ const hoverOptions = {
391
+ ...mockOptions,
392
+ hover: true
393
+ };
394
+ expect(_stylex.stylex.props.call(hoverOptions, styles.root)).toMatchSnapshot('hovered');
395
+ });
396
+ });
397
+ describe('logical styles', () => {
398
+ test('blockSize', () => {
399
+ const styles = _stylex.stylex.create({
400
+ blockSize: {
401
+ blockSize: '100px'
402
+ },
403
+ maxBlockSize: {
404
+ maxBlockSize: '100px'
405
+ },
406
+ minBlockSize: {
407
+ minBlockSize: '100px'
408
+ }
409
+ });
410
+ expect(_stylex.stylex.props.call(mockOptions, styles.blockSize)).toMatchSnapshot('blockSize');
411
+ expect(_stylex.stylex.props.call(mockOptions, {
412
+ height: 200
413
+ }, styles.blockSize)).toMatchSnapshot('blockSize after height');
414
+ expect(_stylex.stylex.props.call(mockOptions, styles.maxBlockSize)).toMatchSnapshot('maxBlockSize');
415
+ expect(_stylex.stylex.props.call(mockOptions, {
416
+ maxHeight: 200
417
+ }, styles.maxBlockSize)).toMatchSnapshot('maxBlockSize after maxHeight');
418
+ expect(_stylex.stylex.props.call(mockOptions, styles.minBlockSize)).toMatchSnapshot('minBlockSize');
419
+ expect(_stylex.stylex.props.call(mockOptions, {
420
+ minHeight: 200
421
+ }, styles.minBlockSize)).toMatchSnapshot('minBlockSize after minHeight');
422
+ });
423
+ test('inlineSize', () => {
424
+ const styles = _stylex.stylex.create({
425
+ inlineSize: {
426
+ inlineSize: '100px'
427
+ },
428
+ maxInlineSize: {
429
+ maxInlineSize: '100px'
430
+ },
431
+ minInlineSize: {
432
+ minInlineSize: '100px'
433
+ }
434
+ });
435
+ expect(_stylex.stylex.props.call(mockOptions, styles.inlineSize)).toMatchSnapshot('inlineSize');
436
+ expect(_stylex.stylex.props.call(mockOptions, {
437
+ width: 200
438
+ }, styles.inlineSize)).toMatchSnapshot('inlineSize after width');
439
+ expect(_stylex.stylex.props.call(mockOptions, styles.maxInlineSize)).toMatchSnapshot('maxInlineSize');
440
+ expect(_stylex.stylex.props.call(mockOptions, {
441
+ maxWidth: 200
442
+ }, styles.maxInlineSize)).toMatchSnapshot('maxInlineSize after maxWidth');
443
+ expect(_stylex.stylex.props.call(mockOptions, styles.minInlineSize)).toMatchSnapshot('minInlineSize');
444
+ expect(_stylex.stylex.props.call(mockOptions, {
445
+ minWidth: 200
446
+ }, styles.minInlineSize)).toMatchSnapshot('minInlineSize after minWidth');
447
+ });
448
+ test('borderBlock', () => {
449
+ const styles = _stylex.stylex.create({
450
+ borderBlock: {
451
+ borderBlockColor: 'black',
452
+ borderBlockStyle: 'solid',
453
+ borderBlockWidth: 1
454
+ },
455
+ borderBlockEnd: {
456
+ borderBlockEndColor: 'red',
457
+ borderBlockEndStyle: 'dotted',
458
+ borderBlockEndWidth: 2
459
+ },
460
+ borderBlockStart: {
461
+ borderBlockStartColor: 'green',
462
+ borderBlockStartStyle: 'dashed',
463
+ borderBlockStartWidth: 3
464
+ }
465
+ });
466
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderBlock)).toMatchSnapshot('borderBlock');
467
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderBlockEnd)).toMatchSnapshot('borderBlockEnd');
468
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderBlockStart)).toMatchSnapshot('borderBlockStart');
469
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderBlockEnd, styles.borderBlock)).toMatchSnapshot('borderBlock after borderBlockEnd');
470
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderBlockStart, styles.borderBlock)).toMatchSnapshot('borderBlock after borderBlockStart');
471
+ });
472
+ test('borderInline', () => {
473
+ const styles = _stylex.stylex.create({
474
+ borderInline: {
475
+ borderInlineColor: 'black',
476
+ borderInlineStyle: 'solid',
477
+ borderInlineWidth: 1
478
+ },
479
+ borderInlineEnd: {
480
+ borderInlineEndColor: 'red',
481
+ borderInlineEndStyle: 'dotted',
482
+ borderInlineEndWidth: 2
483
+ },
484
+ borderInlineStart: {
485
+ borderInlineStartColor: 'green',
486
+ borderInlineStartStyle: 'dashed',
487
+ borderInlineStartWidth: 3
488
+ }
489
+ });
490
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderInline)).toMatchSnapshot('borderInline');
491
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderInlineEnd)).toMatchSnapshot('borderInlineEnd');
492
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderInlineStart)).toMatchSnapshot('borderInlineStart');
493
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderInlineEnd, styles.borderInline)).toMatchSnapshot('borderInline after borderInlineEnd');
494
+ expect(_stylex.stylex.props.call(mockOptions, styles.borderInlineStart, styles.borderInline)).toMatchSnapshot('borderInline after borderInlineStart');
495
+ });
496
+ test('borderRadius', () => {
497
+ const styles = _stylex.stylex.create({
498
+ startstart: {
499
+ borderStartStartRadius: 10
500
+ },
501
+ startend: {
502
+ borderStartEndRadius: 10
503
+ },
504
+ endstart: {
505
+ borderEndStartRadius: 10
506
+ },
507
+ endend: {
508
+ borderEndEndRadius: 10
509
+ }
510
+ });
511
+ expect(_stylex.stylex.props.call(mockOptions, styles.startstart)).toMatchSnapshot('startstart');
512
+ expect(_stylex.stylex.props.call(mockOptions, styles.startend)).toMatchSnapshot('startend');
513
+ expect(_stylex.stylex.props.call(mockOptions, styles.endstart)).toMatchSnapshot('endstart');
514
+ expect(_stylex.stylex.props.call(mockOptions, styles.endend)).toMatchSnapshot('endend');
515
+ });
516
+ test.skip('borderStyle', () => {
517
+ const styles = _stylex.stylex.create({
518
+ root: {}
519
+ });
520
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
521
+ });
522
+ test.skip('borderWidth', () => {
523
+ const styles = _stylex.stylex.create({
524
+ root: {}
525
+ });
526
+ expect(_stylex.stylex.props.call(mockOptions, styles.root)).toMatchSnapshot();
527
+ });
528
+ test('inset', () => {
529
+ const styles = _stylex.stylex.create({
530
+ inset: {
531
+ inset: 1
532
+ },
533
+ insetBlock: {
534
+ insetBlock: 2
535
+ },
536
+ insetBlockStart: {
537
+ insetBlockStart: 3
538
+ },
539
+ insetBlockEnd: {
540
+ insetBlockEnd: 4
541
+ },
542
+ insetInline: {
543
+ insetInline: 5
544
+ },
545
+ insetInlineStart: {
546
+ insetInlineStart: 6
547
+ },
548
+ insetInlineEnd: {
549
+ insetInlineEnd: 7
550
+ }
551
+ });
552
+ expect(_stylex.stylex.props.call(mockOptions, styles.inset)).toMatchSnapshot('inset');
553
+ expect(_stylex.stylex.props.call(mockOptions, styles.insetBlock)).toMatchSnapshot('insetBlock');
554
+ expect(_stylex.stylex.props.call(mockOptions, styles.insetBlockStart)).toMatchSnapshot('insetBlockStart');
555
+ expect(_stylex.stylex.props.call(mockOptions, styles.insetBlockEnd)).toMatchSnapshot('insetBlockEnd');
556
+ expect(_stylex.stylex.props.call(mockOptions, styles.insetInline)).toMatchSnapshot('insetInline');
557
+ expect(_stylex.stylex.props.call(mockOptions, styles.insetInlineStart)).toMatchSnapshot('insetInlineStart');
558
+ expect(_stylex.stylex.props.call(mockOptions, styles.insetInlineEnd)).toMatchSnapshot('insetInlineEnd');
559
+ expect(_stylex.stylex.props.call(mockOptions, {
560
+ left: 10,
561
+ right: 10,
562
+ bottom: 100,
563
+ top: 100
564
+ }, styles.insetBlockStart)).toMatchSnapshot('inset vs top');
565
+ expect(_stylex.stylex.props.call(mockOptions, {
566
+ bottom: 100,
567
+ top: 100
568
+ }, styles.insetBlockStart)).toMatchSnapshot('insetBlock vs top');
569
+ expect(_stylex.stylex.props.call(mockOptions, {
570
+ top: 100
571
+ }, styles.insetBlockStart)).toMatchSnapshot('insetBlockStart vs top');
572
+ expect(_stylex.stylex.props.call(mockOptions, {
573
+ bottom: 100
574
+ }, styles.insetBlockEnd)).toMatchSnapshot('insetBlockEnd vs bottom');
575
+ });
576
+ test('margin', () => {
577
+ const styles = _stylex.stylex.create({
578
+ marginBlock: {
579
+ marginBlock: 1
580
+ },
581
+ marginBlockStart: {
582
+ marginBlockStart: 2
583
+ },
584
+ marginBlockEnd: {
585
+ marginBlockEnd: 3
586
+ },
587
+ marginInline: {
588
+ marginInline: 1
589
+ },
590
+ marginInlineStart: {
591
+ marginInlineStart: 2
592
+ },
593
+ marginInlineEnd: {
594
+ marginInlineEnd: 3
595
+ }
596
+ });
597
+ expect(_stylex.stylex.props.call(mockOptions, styles.marginBlock)).toMatchSnapshot('marginBlock');
598
+ expect(_stylex.stylex.props.call(mockOptions, styles.marginBlockStart)).toMatchSnapshot('marginBlockStart');
599
+ expect(_stylex.stylex.props.call(mockOptions, styles.marginBlockEnd)).toMatchSnapshot('marginBlockEnd');
600
+ expect(_stylex.stylex.props.call(mockOptions, styles.marginInline)).toMatchSnapshot('marginInline');
601
+ expect(_stylex.stylex.props.call(mockOptions, styles.marginInlineStart)).toMatchSnapshot('marginInlineStart');
602
+ expect(_stylex.stylex.props.call(mockOptions, styles.marginInlineEnd)).toMatchSnapshot('marginInlineEnd');
603
+ });
604
+ test('padding', () => {
605
+ const styles = _stylex.stylex.create({
606
+ paddingBlock: {
607
+ paddingBlock: 1
608
+ },
609
+ paddingBlockStart: {
610
+ paddingBlockStart: 2
611
+ },
612
+ paddingBlockEnd: {
613
+ paddingBlockEnd: 3
614
+ },
615
+ paddingInline: {
616
+ paddingInline: 1
617
+ },
618
+ paddingInlineStart: {
619
+ paddingInlineStart: 2
620
+ },
621
+ paddingInlineEnd: {
622
+ paddingInlineEnd: 3
623
+ }
624
+ });
625
+ expect(_stylex.stylex.props.call(mockOptions, styles.paddingBlock)).toMatchSnapshot('paddingBlock');
626
+ expect(_stylex.stylex.props.call(mockOptions, styles.paddingBlockStart)).toMatchSnapshot('paddingBlockStart');
627
+ expect(_stylex.stylex.props.call(mockOptions, styles.paddingBlockEnd)).toMatchSnapshot('paddingBlockEnd');
628
+ expect(_stylex.stylex.props.call(mockOptions, styles.paddingInline)).toMatchSnapshot('paddingInline');
629
+ expect(_stylex.stylex.props.call(mockOptions, styles.paddingInlineStart)).toMatchSnapshot('paddingInlineStart');
630
+ expect(_stylex.stylex.props.call(mockOptions, styles.paddingInlineEnd)).toMatchSnapshot('paddingInlineEnd');
631
+ });
632
+ test('textAlign', () => {
633
+ const styles = _stylex.stylex.create({
634
+ start: {
635
+ textAlign: 'start'
636
+ },
637
+ end: {
638
+ textAlign: 'end'
639
+ }
640
+ });
641
+ expect(_stylex.stylex.props.call(mockOptions, styles.start)).toMatchSnapshot('start');
642
+ expect(_stylex.stylex.props.call(mockOptions, styles.end)).toMatchSnapshot('end');
643
+ });
644
+ });
645
+ describe('length units', () => {
646
+ const unitsToTest = ['em', 'px', 'rem', 'vh', 'vmax', 'vmin', 'vw'];
647
+ const value = 10;
648
+ for (const unitToTest of unitsToTest) {
649
+ test(`${value} "${unitToTest}" units are resolved to pixels`, () => {
650
+ const styles = _stylex.stylex.create({
651
+ underTest: {
652
+ width: `${value}${unitToTest}`
653
+ }
654
+ });
655
+ expect(_stylex.stylex.props.call(mockOptions, styles.underTest)).toMatchSnapshot();
656
+ });
657
+ }
658
+ test(`${value} "em" units based on inherited font-size`, () => {
659
+ const styles = _stylex.stylex.create({
660
+ underTest: {
661
+ width: `${value}em`
662
+ }
663
+ });
664
+ expect(_stylex.stylex.props.call({
665
+ ...mockOptions,
666
+ inheritedFontSize: 12
667
+ }, styles.underTest)).toMatchSnapshot();
668
+ });
669
+ });
670
+ describe('custom properties', () => {
671
+ beforeEach(() => {
672
+ jest.spyOn(console, 'error');
673
+ console.error.mockImplementation(() => {});
674
+ });
675
+ afterEach(() => {
676
+ console.error.mockRestore();
677
+ });
678
+ test('filters out the property and emits a warning when encountering a variable name which has not been provided', () => {
679
+ const {
680
+ underTest
681
+ } = _stylex.stylex.create({
682
+ underTest: {
683
+ width: 'var(--unprovided)'
684
+ }
685
+ });
686
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
687
+ expect(console.error).toHaveBeenCalledWith('stylex: Unrecognized custom property "--unprovided"');
688
+ });
689
+ test("resolves custom properties' values", () => {
690
+ const {
691
+ underTest
692
+ } = _stylex.stylex.create({
693
+ underTest: {
694
+ color: 'var(--slightly-darker-black)',
695
+ width: 'var(--the-best-width)'
696
+ }
697
+ });
698
+ expect(_stylex.stylex.props.call({
699
+ ...mockOptions,
700
+ customProperties: {
701
+ slightlyDarkerBlack: '#333',
702
+ theBestWidth: 42
703
+ }
704
+ }, underTest)).toMatchSnapshot();
705
+ });
706
+ });
707
+ expect.extend({
708
+ toMatchWindowDimensions(query, windowSize) {
709
+ const {
710
+ height,
711
+ width
712
+ } = windowSize;
713
+ const EXPECTED_MATCHED_VALUE = 500;
714
+ const {
715
+ underTest
716
+ } = _stylex.stylex.create({
717
+ underTest: {
718
+ [`@media ${query}`]: {
719
+ width: EXPECTED_MATCHED_VALUE
720
+ }
721
+ }
722
+ });
723
+ const props = _stylex.stylex.props.call({
724
+ viewportHeight: height,
725
+ viewportWidth: width
726
+ }, underTest);
727
+ const actualValue = props.style.width;
728
+ if (actualValue === EXPECTED_MATCHED_VALUE) {
729
+ return {
730
+ pass: true,
731
+ message: () => `expected media query ${query} not to match in a window of width ${width} and height ${height}`
732
+ };
733
+ } else {
734
+ return {
735
+ pass: false,
736
+ message: () => `expected media query ${query} to match in a window of width ${width} and height ${height}`
737
+ };
738
+ }
739
+ }
740
+ });
741
+ describe('media queries', () => {
742
+ test('matches a "min-width" query', () => {
743
+ expect('(min-width: 400px)').toMatchWindowDimensions({
744
+ width: 450,
745
+ height: 0
746
+ });
747
+ expect('(min-width: 400px)').not.toMatchWindowDimensions({
748
+ width: 350,
749
+ height: 0
750
+ });
751
+ });
752
+ test('matches a "max-width" query', () => {
753
+ expect('(max-width: 400px)').toMatchWindowDimensions({
754
+ width: 350,
755
+ height: 0
756
+ });
757
+ expect('(max-width: 400px)').not.toMatchWindowDimensions({
758
+ width: 450,
759
+ height: 0
760
+ });
761
+ });
762
+ test('matches a "min-height" query', () => {
763
+ expect('(min-height: 400px)').toMatchWindowDimensions({
764
+ width: 0,
765
+ height: 450
766
+ });
767
+ expect('(min-height: 400px)').not.toMatchWindowDimensions({
768
+ width: 0,
769
+ height: 350
770
+ });
771
+ });
772
+ test('matches a "max-height" query', () => {
773
+ expect('(max-height: 400px)').toMatchWindowDimensions({
774
+ width: 0,
775
+ height: 350
776
+ });
777
+ expect('(max-height: 400px)').not.toMatchWindowDimensions({
778
+ width: 0,
779
+ height: 450
780
+ });
781
+ });
782
+ });
783
+ describe('unsupported style properties', () => {
784
+ beforeEach(() => {
785
+ jest.spyOn(console, 'warn');
786
+ console.warn.mockImplementation(() => {});
787
+ });
788
+ afterEach(() => {
789
+ console.warn.mockRestore();
790
+ });
791
+ test('"filter"', () => {
792
+ const {
793
+ underTest
794
+ } = _stylex.stylex.create({
795
+ underTest: {
796
+ filter: 'blur(1px)'
797
+ }
798
+ });
799
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
800
+ expect(console.warn).toHaveBeenCalled();
801
+ });
802
+ test('"marginStart"', () => {
803
+ const {
804
+ underTest
805
+ } = _stylex.stylex.create({
806
+ underTest: {
807
+ marginStart: 10
808
+ }
809
+ });
810
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
811
+ expect(console.warn).toHaveBeenCalled();
812
+ });
813
+ test('"marginEnd"', () => {
814
+ const {
815
+ underTest
816
+ } = _stylex.stylex.create({
817
+ underTest: {
818
+ marginEnd: 10
819
+ }
820
+ });
821
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
822
+ expect(console.warn).toHaveBeenCalled();
823
+ });
824
+ test('"marginHorizontal"', () => {
825
+ const {
826
+ underTest
827
+ } = _stylex.stylex.create({
828
+ underTest: {
829
+ marginHorizontal: 10
830
+ }
831
+ });
832
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
833
+ expect(console.warn).toHaveBeenCalled();
834
+ });
835
+ test('"marginVertical"', () => {
836
+ const {
837
+ underTest
838
+ } = _stylex.stylex.create({
839
+ underTest: {
840
+ marginVertical: 10
841
+ }
842
+ });
843
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
844
+ expect(console.warn).toHaveBeenCalled();
845
+ });
846
+ test('"paddingHorizontal"', () => {
847
+ const {
848
+ underTest
849
+ } = _stylex.stylex.create({
850
+ underTest: {
851
+ paddingHorizontal: 10
852
+ }
853
+ });
854
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
855
+ expect(console.warn).toHaveBeenCalled();
856
+ });
857
+ test('"paddingVertical"', () => {
858
+ const {
859
+ underTest
860
+ } = _stylex.stylex.create({
861
+ underTest: {
862
+ paddingVertical: 10
863
+ }
864
+ });
865
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
866
+ expect(console.warn).toHaveBeenCalled();
867
+ });
868
+ test('"transitionProperty" passthrough', () => {
869
+ const {
870
+ underTest
871
+ } = _stylex.stylex.create({
872
+ underTest: {
873
+ transitionProperty: 'opacity'
874
+ }
875
+ });
876
+ expect(_stylex.stylex.props.call({
877
+ ...mockOptions,
878
+ passthroughProperties: ['transitionProperty']
879
+ }, underTest)).toMatchSnapshot();
880
+ expect(console.warn).not.toHaveBeenCalled();
881
+ });
882
+ });
883
+ describe('unsupported style values', () => {
884
+ beforeEach(() => {
885
+ jest.spyOn(console, 'warn');
886
+ console.warn.mockImplementation(() => {});
887
+ });
888
+ afterEach(() => {
889
+ console.warn.mockRestore();
890
+ });
891
+ test('calc', () => {
892
+ const {
893
+ underTest
894
+ } = _stylex.stylex.create({
895
+ underTest: {
896
+ width: 'calc(2 * 1rem)'
897
+ }
898
+ });
899
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
900
+ expect(console.warn).toHaveBeenCalled();
901
+ });
902
+ test('inherit', () => {
903
+ const {
904
+ underTest
905
+ } = _stylex.stylex.create({
906
+ underTest: {
907
+ fontSize: 'inherit'
908
+ }
909
+ });
910
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
911
+ expect(console.warn).toHaveBeenCalled();
912
+ });
913
+ test('initial', () => {
914
+ const {
915
+ underTest
916
+ } = _stylex.stylex.create({
917
+ underTest: {
918
+ fontSize: 'initial'
919
+ }
920
+ });
921
+ expect(_stylex.stylex.props.call(mockOptions, underTest)).toMatchSnapshot();
922
+ expect(console.warn).toHaveBeenCalled();
923
+ });
924
+ });