1
- import { SPACE , COMMA , LENGTH , NUMBER , ANGLE } from '../tokenTypes'
1
+ import { SPACE , COMMA , LENGTH , NUMBER , ANGLE , PERCENT } from '../tokenTypes'
2
2
3
- const oneOfType = tokenType => functionStream => {
4
- const value = functionStream . expect ( tokenType )
3
+ const oneOfTypes = tokenTypes => functionStream => {
4
+ const value = functionStream . expect ( ... tokenTypes )
5
5
functionStream . expectEmpty ( )
6
6
return value
7
7
}
8
8
9
- const singleNumber = oneOfType ( NUMBER )
10
- const singleLength = oneOfType ( LENGTH )
11
- const singleAngle = oneOfType ( ANGLE )
12
- const xyTransformFactory = tokenType => (
9
+ const singleNumber = oneOfTypes ( [ NUMBER ] )
10
+ const singleLengthOrPercent = oneOfTypes ( [ LENGTH , PERCENT ] )
11
+ const singleAngle = oneOfTypes ( [ ANGLE ] )
12
+ const xyTransformFactory = tokenTypes => (
13
13
key ,
14
14
valueIfOmitted
15
15
) => functionStream => {
16
- const x = functionStream . expect ( tokenType )
16
+ const x = functionStream . expect ( ... tokenTypes )
17
17
18
18
let y
19
19
if ( functionStream . hasTokens ( ) ) {
20
20
functionStream . expect ( COMMA )
21
- y = functionStream . expect ( tokenType )
21
+ y = functionStream . expect ( ... tokenTypes )
22
22
} else if ( valueIfOmitted !== undefined ) {
23
23
y = valueIfOmitted
24
24
} else {
@@ -31,18 +31,18 @@ const xyTransformFactory = tokenType => (
31
31
32
32
return [ { [ `${ key } Y` ] : y } , { [ `${ key } X` ] : x } ]
33
33
}
34
- const xyNumber = xyTransformFactory ( NUMBER )
35
- const xyLength = xyTransformFactory ( LENGTH )
36
- const xyAngle = xyTransformFactory ( ANGLE )
34
+ const xyNumber = xyTransformFactory ( [ NUMBER ] )
35
+ const xyLengthOrPercent = xyTransformFactory ( [ LENGTH , PERCENT ] )
36
+ const xyAngle = xyTransformFactory ( [ ANGLE ] )
37
37
38
38
const partTransforms = {
39
39
perspective : singleNumber ,
40
40
scale : xyNumber ( 'scale' ) ,
41
41
scaleX : singleNumber ,
42
42
scaleY : singleNumber ,
43
- translate : xyLength ( 'translate' , 0 ) ,
44
- translateX : singleLength ,
45
- translateY : singleLength ,
43
+ translate : xyLengthOrPercent ( 'translate' , 0 ) ,
44
+ translateX : singleLengthOrPercent ,
45
+ translateY : singleLengthOrPercent ,
46
46
rotate : singleAngle ,
47
47
rotateX : singleAngle ,
48
48
rotateY : singleAngle ,
0 commit comments