@cssxjs/css-to-react-native 3.2.0-0 → 3.2.0-2

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.
@@ -0,0 +1,186 @@
1
+ import transformCss from '..'
2
+
3
+ it('transforms transition shorthand', () => {
4
+ expect(transformCss([['transition', 'opacity 300ms ease']])).toEqual({
5
+ transitionProperty: 'opacity',
6
+ transitionDuration: '300ms',
7
+ transitionTimingFunction: 'ease',
8
+ transitionDelay: '0s',
9
+ })
10
+ })
11
+
12
+ it('transforms transition with only property and duration', () => {
13
+ expect(transformCss([['transition', 'opacity 300ms']])).toEqual({
14
+ transitionProperty: 'opacity',
15
+ transitionDuration: '300ms',
16
+ transitionTimingFunction: 'ease',
17
+ transitionDelay: '0s',
18
+ })
19
+ })
20
+
21
+ it('transforms transition property names to camelCase', () => {
22
+ expect(transformCss([['transition', 'background-color 300ms']])).toEqual({
23
+ transitionProperty: 'backgroundColor',
24
+ transitionDuration: '300ms',
25
+ transitionTimingFunction: 'ease',
26
+ transitionDelay: '0s',
27
+ })
28
+ })
29
+
30
+ it('transforms multiple transition property names to camelCase', () => {
31
+ expect(
32
+ transformCss([
33
+ ['transition', 'background-color 300ms, border-radius 500ms ease-out'],
34
+ ])
35
+ ).toEqual({
36
+ transitionProperty: ['backgroundColor', 'borderRadius'],
37
+ transitionDuration: ['300ms', '500ms'],
38
+ transitionTimingFunction: ['ease', 'ease-out'],
39
+ transitionDelay: ['0s', '0s'],
40
+ })
41
+ })
42
+
43
+ it('transforms transition with delay', () => {
44
+ expect(transformCss([['transition', 'opacity 300ms ease 100ms']])).toEqual({
45
+ transitionProperty: 'opacity',
46
+ transitionDuration: '300ms',
47
+ transitionTimingFunction: 'ease',
48
+ transitionDelay: '100ms',
49
+ })
50
+ })
51
+
52
+ it('transforms transition with all property', () => {
53
+ expect(transformCss([['transition', 'all 200ms linear']])).toEqual({
54
+ transitionProperty: 'all',
55
+ transitionDuration: '200ms',
56
+ transitionTimingFunction: 'linear',
57
+ transitionDelay: '0s',
58
+ })
59
+ })
60
+
61
+ it('transforms multiple transitions', () => {
62
+ expect(
63
+ transformCss([
64
+ ['transition', 'opacity 300ms ease, transform 500ms ease-in'],
65
+ ])
66
+ ).toEqual({
67
+ transitionProperty: ['opacity', 'transform'],
68
+ transitionDuration: ['300ms', '500ms'],
69
+ transitionTimingFunction: ['ease', 'ease-in'],
70
+ transitionDelay: ['0s', '0s'],
71
+ })
72
+ })
73
+
74
+ it('transforms transition with cubic-bezier', () => {
75
+ expect(
76
+ transformCss([['transition', 'opacity 300ms cubic-bezier(0.4, 0, 0.2, 1)']])
77
+ ).toEqual({
78
+ transitionProperty: 'opacity',
79
+ transitionDuration: '300ms',
80
+ transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
81
+ transitionDelay: '0s',
82
+ })
83
+ })
84
+
85
+ it('transforms transition none', () => {
86
+ expect(transformCss([['transition', 'none']])).toEqual({
87
+ transitionProperty: 'none',
88
+ transitionDuration: '0s',
89
+ transitionTimingFunction: 'ease',
90
+ transitionDelay: '0s',
91
+ })
92
+ })
93
+
94
+ it('transforms transition-property', () => {
95
+ expect(transformCss([['transition-property', 'opacity']])).toEqual({
96
+ transitionProperty: 'opacity',
97
+ })
98
+ })
99
+
100
+ it('transforms transition-property with multiple values', () => {
101
+ expect(
102
+ transformCss([['transition-property', 'opacity, transform, width']])
103
+ ).toEqual({
104
+ transitionProperty: ['opacity', 'transform', 'width'],
105
+ })
106
+ })
107
+
108
+ it('transforms transition-property with camelCase conversion', () => {
109
+ expect(
110
+ transformCss([['transition-property', 'background-color, border-radius']])
111
+ ).toEqual({
112
+ transitionProperty: ['backgroundColor', 'borderRadius'],
113
+ })
114
+ })
115
+
116
+ it('transforms transition-duration', () => {
117
+ expect(transformCss([['transition-duration', '300ms']])).toEqual({
118
+ transitionDuration: '300ms',
119
+ })
120
+ })
121
+
122
+ it('transforms transition-duration with multiple values', () => {
123
+ expect(transformCss([['transition-duration', '300ms, 500ms, 1s']])).toEqual({
124
+ transitionDuration: ['300ms', '500ms', '1s'],
125
+ })
126
+ })
127
+
128
+ it('transforms transition-timing-function', () => {
129
+ expect(transformCss([['transition-timing-function', 'ease-in-out']])).toEqual(
130
+ {
131
+ transitionTimingFunction: 'ease-in-out',
132
+ }
133
+ )
134
+ })
135
+
136
+ it('transforms transition-timing-function with multiple values', () => {
137
+ expect(
138
+ transformCss([['transition-timing-function', 'ease, linear, ease-in-out']])
139
+ ).toEqual({
140
+ transitionTimingFunction: ['ease', 'linear', 'ease-in-out'],
141
+ })
142
+ })
143
+
144
+ it('transforms transition-timing-function with cubic-bezier', () => {
145
+ expect(
146
+ transformCss([
147
+ ['transition-timing-function', 'cubic-bezier(0.4, 0, 0.2, 1)'],
148
+ ])
149
+ ).toEqual({
150
+ transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
151
+ })
152
+ })
153
+
154
+ it('transforms transition-delay', () => {
155
+ expect(transformCss([['transition-delay', '100ms']])).toEqual({
156
+ transitionDelay: '100ms',
157
+ })
158
+ })
159
+
160
+ it('transforms transition-delay with multiple values', () => {
161
+ expect(transformCss([['transition-delay', '100ms, 200ms, 0s']])).toEqual({
162
+ transitionDelay: ['100ms', '200ms', '0s'],
163
+ })
164
+ })
165
+
166
+ it('transforms transition with seconds', () => {
167
+ expect(transformCss([['transition', 'opacity 1s linear 0.5s']])).toEqual({
168
+ transitionProperty: 'opacity',
169
+ transitionDuration: '1s',
170
+ transitionTimingFunction: 'linear',
171
+ transitionDelay: '0.5s',
172
+ })
173
+ })
174
+
175
+ it('transforms multiple transitions with different timing functions', () => {
176
+ expect(
177
+ transformCss([
178
+ ['transition', 'width 200ms ease-in, height 300ms ease-out 100ms'],
179
+ ])
180
+ ).toEqual({
181
+ transitionProperty: ['width', 'height'],
182
+ transitionDuration: ['200ms', '300ms'],
183
+ transitionTimingFunction: ['ease-in', 'ease-out'],
184
+ transitionDelay: ['0s', '100ms'],
185
+ })
186
+ })
@@ -117,10 +117,7 @@ lengthUnits.forEach(unit => {
117
117
  expect(
118
118
  transformCss([['box-shadow', `10px ${value} ${value} red`]])
119
119
  ).toEqual({
120
- shadowOffset: { width: 10, height: value },
121
- shadowRadius: value,
122
- shadowColor: 'red',
123
- shadowOpacity: 1,
120
+ boxShadow: `10px ${value} ${value} red`,
124
121
  })
125
122
  })
126
123
  })
@@ -0,0 +1,385 @@
1
+ import transformCss from '..'
2
+
3
+ // =============================================================================
4
+ // Transform functions with var()
5
+ // =============================================================================
6
+
7
+ describe('transform with var()', () => {
8
+ it('transforms translateX with var()', () => {
9
+ expect(transformCss([['transform', 'translateX(var(--x))']])).toEqual({
10
+ transform: [{ translateX: 'var(--x)' }],
11
+ })
12
+ })
13
+
14
+ it('transforms translateX with var() and fallback', () => {
15
+ expect(transformCss([['transform', 'translateX(var(--x, 10px))']])).toEqual({
16
+ transform: [{ translateX: 'var(--x, 10px)' }],
17
+ })
18
+ })
19
+
20
+ it('transforms multiple transform functions with var()', () => {
21
+ expect(
22
+ transformCss([
23
+ ['transform', 'translateX(var(--x, 10px)) translateY(var(--y, 20px))'],
24
+ ])
25
+ ).toEqual({
26
+ transform: [
27
+ { translateY: 'var(--y, 20px)' },
28
+ { translateX: 'var(--x, 10px)' },
29
+ ],
30
+ })
31
+ })
32
+
33
+ it('transforms rotate with var()', () => {
34
+ expect(transformCss([['transform', 'rotate(var(--angle, 45deg))']])).toEqual(
35
+ {
36
+ transform: [{ rotate: 'var(--angle, 45deg)' }],
37
+ }
38
+ )
39
+ })
40
+
41
+ it('transforms scale with var()', () => {
42
+ expect(transformCss([['transform', 'scale(var(--scale, 1.5))']])).toEqual({
43
+ transform: [{ scale: 'var(--scale, 1.5)' }],
44
+ })
45
+ })
46
+
47
+ it('transforms mixed concrete and var() values', () => {
48
+ expect(
49
+ transformCss([['transform', 'translateX(10px) rotate(var(--angle))']])
50
+ ).toEqual({
51
+ transform: [{ rotate: 'var(--angle)' }, { translateX: 10 }],
52
+ })
53
+ })
54
+
55
+ it('transforms translate with two var() args', () => {
56
+ expect(
57
+ transformCss([['transform', 'translate(var(--x, 10px), var(--y, 20px))']])
58
+ ).toEqual({
59
+ transform: [
60
+ { translateY: 'var(--y, 20px)' },
61
+ { translateX: 'var(--x, 10px)' },
62
+ ],
63
+ })
64
+ })
65
+
66
+ it('transforms scale with two var() args', () => {
67
+ expect(
68
+ transformCss([['transform', 'scale(var(--sx, 1), var(--sy, 2))']])
69
+ ).toEqual({
70
+ transform: [{ scaleY: 'var(--sy, 2)' }, { scaleX: 'var(--sx, 1)' }],
71
+ })
72
+ })
73
+
74
+ it('transforms skew with var()', () => {
75
+ expect(
76
+ transformCss([['transform', 'skew(var(--skew-x, 10deg), var(--skew-y, 5deg))']])
77
+ ).toEqual({
78
+ transform: [
79
+ { skewY: 'var(--skew-y, 5deg)' },
80
+ { skewX: 'var(--skew-x, 10deg)' },
81
+ ],
82
+ })
83
+ })
84
+ })
85
+
86
+ // =============================================================================
87
+ // Box-shadow with multiple var() values and comma-separated shadows
88
+ // =============================================================================
89
+
90
+ describe('box-shadow with complex var()', () => {
91
+ it('transforms box-shadow with var() for offset-x', () => {
92
+ expect(
93
+ transformCss([['box-shadow', 'var(--x) 10px 5px red']])
94
+ ).toEqual({
95
+ boxShadow: 'var(--x) 10px 5px red',
96
+ })
97
+ })
98
+
99
+ it('transforms box-shadow with var() for offset-y', () => {
100
+ expect(
101
+ transformCss([['box-shadow', '10px var(--y) 5px red']])
102
+ ).toEqual({
103
+ boxShadow: '10px var(--y) 5px red',
104
+ })
105
+ })
106
+
107
+ it('transforms box-shadow with var() for blur', () => {
108
+ expect(
109
+ transformCss([['box-shadow', '10px 20px var(--blur) red']])
110
+ ).toEqual({
111
+ boxShadow: '10px 20px var(--blur) red',
112
+ })
113
+ })
114
+
115
+ it('transforms box-shadow with multiple var() values', () => {
116
+ expect(
117
+ transformCss([['box-shadow', 'var(--x) var(--y) var(--blur) var(--color)']])
118
+ ).toEqual({
119
+ boxShadow: 'var(--x) var(--y) var(--blur) var(--color)',
120
+ })
121
+ })
122
+
123
+ it('transforms multiple box-shadows with var()', () => {
124
+ expect(
125
+ transformCss([
126
+ [
127
+ 'box-shadow',
128
+ 'var(--x) var(--y) var(--color, rgba(0, 0, 0, 0.2)), var(--x-2) var(--y-2) var(--color-2, rgba(0, 0, 0, 0.5))',
129
+ ],
130
+ ])
131
+ ).toEqual({
132
+ boxShadow:
133
+ 'var(--x) var(--y) var(--color, rgba(0, 0, 0, 0.2)), var(--x-2) var(--y-2) var(--color-2, rgba(0, 0, 0, 0.5))',
134
+ })
135
+ })
136
+
137
+ it('transforms multiple box-shadows with mixed concrete and var() values', () => {
138
+ expect(
139
+ transformCss([
140
+ ['box-shadow', '10px 20px red, var(--x-2) var(--y-2) blue'],
141
+ ])
142
+ ).toEqual({
143
+ boxShadow: '10px 20px red, var(--x-2) var(--y-2) blue',
144
+ })
145
+ })
146
+
147
+ it('transforms box-shadow with var() having rgba fallback', () => {
148
+ expect(
149
+ transformCss([
150
+ ['box-shadow', '10px 20px var(--blur, 5px) var(--color, rgba(0, 0, 0, 0.2))'],
151
+ ])
152
+ ).toEqual({
153
+ boxShadow: '10px 20px var(--blur, 5px) var(--color, rgba(0, 0, 0, 0.2))',
154
+ })
155
+ })
156
+ })
157
+
158
+ // =============================================================================
159
+ // Shorthand properties with multiple var() values
160
+ // =============================================================================
161
+
162
+ describe('shorthand properties with var()', () => {
163
+ it('transforms padding with multiple var() values', () => {
164
+ expect(
165
+ transformCss([
166
+ ['padding', 'var(--top) var(--right) var(--bottom) var(--left)'],
167
+ ])
168
+ ).toEqual({
169
+ paddingTop: 'var(--top)',
170
+ paddingRight: 'var(--right)',
171
+ paddingBottom: 'var(--bottom)',
172
+ paddingLeft: 'var(--left)',
173
+ })
174
+ })
175
+
176
+ it('transforms padding with var() and fallbacks', () => {
177
+ expect(
178
+ transformCss([
179
+ ['padding', 'var(--top, 10px) var(--right, 20px) var(--bottom, 10px) var(--left, 20px)'],
180
+ ])
181
+ ).toEqual({
182
+ paddingTop: 'var(--top, 10px)',
183
+ paddingRight: 'var(--right, 20px)',
184
+ paddingBottom: 'var(--bottom, 10px)',
185
+ paddingLeft: 'var(--left, 20px)',
186
+ })
187
+ })
188
+
189
+ it('transforms padding with two var() values', () => {
190
+ expect(
191
+ transformCss([['padding', 'var(--vertical) var(--horizontal)']])
192
+ ).toEqual({
193
+ paddingTop: 'var(--vertical)',
194
+ paddingRight: 'var(--horizontal)',
195
+ paddingBottom: 'var(--vertical)',
196
+ paddingLeft: 'var(--horizontal)',
197
+ })
198
+ })
199
+
200
+ it('transforms margin with multiple var() values', () => {
201
+ expect(
202
+ transformCss([
203
+ ['margin', 'var(--top) var(--right) var(--bottom) var(--left)'],
204
+ ])
205
+ ).toEqual({
206
+ marginTop: 'var(--top)',
207
+ marginRight: 'var(--right)',
208
+ marginBottom: 'var(--bottom)',
209
+ marginLeft: 'var(--left)',
210
+ })
211
+ })
212
+
213
+ it('transforms margin with mixed concrete and var() values', () => {
214
+ expect(
215
+ transformCss([['margin', '10px var(--horizontal) 20px']])
216
+ ).toEqual({
217
+ marginTop: 10,
218
+ marginRight: 'var(--horizontal)',
219
+ marginBottom: 20,
220
+ marginLeft: 'var(--horizontal)',
221
+ })
222
+ })
223
+
224
+ it('transforms border-radius with multiple var() values', () => {
225
+ expect(
226
+ transformCss([
227
+ ['border-radius', 'var(--tl) var(--tr) var(--br) var(--bl)'],
228
+ ])
229
+ ).toEqual({
230
+ borderTopLeftRadius: 'var(--tl)',
231
+ borderTopRightRadius: 'var(--tr)',
232
+ borderBottomRightRadius: 'var(--br)',
233
+ borderBottomLeftRadius: 'var(--bl)',
234
+ })
235
+ })
236
+
237
+ it('transforms border-width with multiple var() values', () => {
238
+ expect(
239
+ transformCss([
240
+ ['border-width', 'var(--top) var(--right) var(--bottom) var(--left)'],
241
+ ])
242
+ ).toEqual({
243
+ borderTopWidth: 'var(--top)',
244
+ borderRightWidth: 'var(--right)',
245
+ borderBottomWidth: 'var(--bottom)',
246
+ borderLeftWidth: 'var(--left)',
247
+ })
248
+ })
249
+ })
250
+
251
+ // =============================================================================
252
+ // Animation with var()
253
+ // =============================================================================
254
+
255
+ describe('animation with var()', () => {
256
+ it('transforms animation-duration with var()', () => {
257
+ expect(
258
+ transformCss([['animation-duration', 'var(--duration, 300ms)']])
259
+ ).toEqual({
260
+ animationDuration: 'var(--duration, 300ms)',
261
+ })
262
+ })
263
+
264
+ it('transforms animation-delay with var()', () => {
265
+ expect(
266
+ transformCss([['animation-delay', 'var(--delay, 100ms)']])
267
+ ).toEqual({
268
+ animationDelay: 'var(--delay, 100ms)',
269
+ })
270
+ })
271
+
272
+ it('transforms animation-name with var()', () => {
273
+ expect(transformCss([['animation-name', 'var(--animation)']])).toEqual({
274
+ animationName: 'var(--animation)',
275
+ })
276
+ })
277
+
278
+ it('transforms animation shorthand with var() for duration', () => {
279
+ expect(
280
+ transformCss([['animation', 'fadeIn var(--duration, 300ms) ease']])
281
+ ).toEqual({
282
+ animationName: 'fadeIn',
283
+ animationDuration: 'var(--duration, 300ms)',
284
+ animationTimingFunction: 'ease',
285
+ animationDelay: '0s',
286
+ animationIterationCount: 1,
287
+ animationDirection: 'normal',
288
+ animationFillMode: 'none',
289
+ animationPlayState: 'running',
290
+ })
291
+ })
292
+
293
+ it('transforms multiple animation values with var()', () => {
294
+ expect(
295
+ transformCss([
296
+ ['animation-duration', 'var(--dur1), var(--dur2)'],
297
+ ])
298
+ ).toEqual({
299
+ animationDuration: ['var(--dur1)', 'var(--dur2)'],
300
+ })
301
+ })
302
+ })
303
+
304
+ // =============================================================================
305
+ // Transition with var()
306
+ // =============================================================================
307
+
308
+ describe('transition with var()', () => {
309
+ it('transforms transition-duration with var()', () => {
310
+ expect(
311
+ transformCss([['transition-duration', 'var(--duration, 300ms)']])
312
+ ).toEqual({
313
+ transitionDuration: 'var(--duration, 300ms)',
314
+ })
315
+ })
316
+
317
+ it('transforms transition-delay with var()', () => {
318
+ expect(
319
+ transformCss([['transition-delay', 'var(--delay, 100ms)']])
320
+ ).toEqual({
321
+ transitionDelay: 'var(--delay, 100ms)',
322
+ })
323
+ })
324
+
325
+ it('transforms transition shorthand with var() for duration', () => {
326
+ expect(
327
+ transformCss([['transition', 'opacity var(--duration, 300ms) ease']])
328
+ ).toEqual({
329
+ transitionProperty: 'opacity',
330
+ transitionDuration: 'var(--duration, 300ms)',
331
+ transitionTimingFunction: 'ease',
332
+ transitionDelay: '0s',
333
+ })
334
+ })
335
+
336
+ it('transforms multiple transition values with var()', () => {
337
+ expect(
338
+ transformCss([['transition-duration', 'var(--dur1), var(--dur2)']])
339
+ ).toEqual({
340
+ transitionDuration: ['var(--dur1)', 'var(--dur2)'],
341
+ })
342
+ })
343
+
344
+ it('transforms transition with var() for delay', () => {
345
+ expect(
346
+ transformCss([['transition', 'opacity 300ms ease var(--delay)']])
347
+ ).toEqual({
348
+ transitionProperty: 'opacity',
349
+ transitionDuration: '300ms',
350
+ transitionTimingFunction: 'ease',
351
+ transitionDelay: 'var(--delay)',
352
+ })
353
+ })
354
+ })
355
+
356
+ // =============================================================================
357
+ // Edge cases with var() fallbacks containing commas
358
+ // =============================================================================
359
+
360
+ describe('var() with complex fallbacks', () => {
361
+ it('handles var() with rgba fallback containing commas', () => {
362
+ expect(
363
+ transformCss([['color', 'var(--color, rgba(100, 100, 100, 0.5))']])
364
+ ).toEqual({
365
+ color: 'var(--color, rgba(100, 100, 100, 0.5))',
366
+ })
367
+ })
368
+
369
+ it('handles var() with rgb fallback containing commas', () => {
370
+ expect(
371
+ transformCss([['color', 'var(--color, rgb(100, 100, 100))']])
372
+ ).toEqual({
373
+ color: 'var(--color, rgb(100, 100, 100))',
374
+ })
375
+ })
376
+
377
+ it('handles nested var() fallbacks', () => {
378
+ // This might not work but let's test it
379
+ expect(
380
+ transformCss([['color', 'var(--primary, var(--fallback, red))']])
381
+ ).toEqual({
382
+ color: 'var(--primary, var(--fallback, red))',
383
+ })
384
+ })
385
+ })