-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathindex.js
91 lines (88 loc) · 2.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { regExpToken, tokens } from '../tokenTypes'
import boxShadow from './boxShadow'
import flex from './flex'
import font from './font'
import fontFamily from './fontFamily'
import textShadow from './textShadow'
import textDecoration from './textDecoration'
import textDecorationLine from './textDecorationLine'
import transform from './transform'
import { directionFactory, anyOrderFactory, shadowOffsetFactory } from './util'
const {
IDENT,
WORD,
COLOR,
LENGTH,
UNSUPPORTED_LENGTH_UNIT,
PERCENT,
AUTO,
} = tokens
const background = tokenStream => ({
$merge: { backgroundColor: tokenStream.expect(COLOR) },
})
const border = anyOrderFactory({
borderWidth: {
tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
default: 1,
},
borderColor: {
tokens: [COLOR],
default: 'black',
},
borderStyle: {
tokens: [regExpToken(/^(solid|dashed|dotted)$/)],
default: 'solid',
},
})
const borderColor = directionFactory({
types: [WORD],
prefix: 'border',
suffix: 'Color',
})
const borderRadius = directionFactory({
directions: ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'],
prefix: 'border',
suffix: 'Radius',
})
const borderWidth = directionFactory({ prefix: 'border', suffix: 'Width' })
const margin = directionFactory({
types: [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO],
prefix: 'margin',
})
const padding = directionFactory({ prefix: 'padding' })
const flexFlow = anyOrderFactory({
flexWrap: {
tokens: [regExpToken(/(nowrap|wrap|wrap-reverse)/)],
default: 'nowrap',
},
flexDirection: {
tokens: [regExpToken(/(row|row-reverse|column|column-reverse)/)],
default: 'row',
},
})
const fontVariant = tokenStream => [tokenStream.expect(IDENT)]
const fontWeight = tokenStream => tokenStream.expect(WORD) // Also match numbers as strings
const shadowOffset = shadowOffsetFactory()
const textShadowOffset = shadowOffsetFactory()
export default {
background,
border,
borderColor,
borderRadius,
borderWidth,
boxShadow,
flex,
flexFlow,
font,
fontFamily,
fontVariant,
fontWeight,
margin,
padding,
shadowOffset,
textShadow,
textShadowOffset,
textDecoration,
textDecorationLine,
transform,
}