-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstants.ts
More file actions
144 lines (130 loc) · 3.28 KB
/
Copy pathconstants.ts
File metadata and controls
144 lines (130 loc) · 3.28 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { CSSPropertySet } from './cssPropertySet'
/*
* Setup valid CSS attributes object
*/
type CSSPropertyKey = keyof CSSPropertySet
type ValidCSSPropertyMap = { [key in CSSPropertyKey]: boolean }
export const SHORTHANDS = {
borderLeftRadius: ['borderTopLeftRadius', 'borderBottomLeftRadius'],
borderRightRadius: ['borderTopRightRadius', 'borderBottomRightRadius'],
borderBottomRadius: ['borderBottomLeftRadius', 'borderBottomRightRadius'],
borderTopRadius: ['borderTopRightRadius', 'borderTopLeftRadius'],
}
export const validCSSAttr: ValidCSSPropertyMap =
process.env.RENDER_TARGET === 'node'
? require('./validCSSAttribute.node').default
: require('./validCSSAttribute.dom').default
// conversions
export const CAMEL_TO_SNAKE = {}
export const SNAKE_TO_CAMEL = {}
for (const camelKey in validCSSAttr) {
let snakeKey = ''
if (camelKey.indexOf('webkit') === 0) {
snakeKey += '-'
}
for (const letter of camelKey) {
if (letter.toUpperCase() === letter) {
snakeKey += `-${letter.toLowerCase()}`
} else {
snakeKey += letter
}
}
CAMEL_TO_SNAKE[camelKey] = snakeKey
SNAKE_TO_CAMEL[snakeKey] = camelKey
}
// css attribute key abbreviations
const existing = new Set()
export const cssAttributeAbbreviations = {}
export const cssAbbreviationToAttribute = {} // inverse
for (const key in validCSSAttr) {
let found = ''
if (key.length < 4) {
found = `${key}-`
} else {
let i = 1
while (true) {
const abbrevs = getAbbrevs(key)
found = abbrevs.slice(0, i).join('')
if (i > abbrevs.length) {
found += `${i}`
}
found += '-'
if (!existing.has(found)) break
i++
}
}
existing.add(found)
cssAbbreviationToAttribute[found] = key
cssAttributeAbbreviations[key] = found
}
function getAbbrevs(key: string) {
let options = [key[0]]
const uppercases = key.match(/[A-Z]/g)
if (uppercases) options = [...options, ...uppercases]
return options
}
// various helpful constants
export const UNDEFINED = 'undefined'
// TODO this could be dynamic
// not the best tradeoff here for understanding where you can pass in colors
export const COLOR_KEYS = new Set<string>([
'color',
'background',
'backgroundColor',
'borderColor',
'borderBottomColor',
'borderTopColor',
'borderLeftColor',
'borderRightColor',
'textDecorationColor',
])
export const TRANSFORM_KEYS_MAP = {
x: 'translateX',
y: 'translateY',
z: 'translateZ',
dropShadow: 'drop-shadow',
}
export const COMMA_JOINED = new Set(['boxShadow', 'transition'])
export const FALSE_VALUES = {
background: 'transparent',
backgroundColor: 'transparent',
borderColor: 'transparent',
}
export const BORDER_KEY = new Set([
'border',
'borderLeft',
'borderRight',
'borderBottom',
'borderTop',
])
export const unitlessNumberProperties = new Set<string>([
'animationIterationCount',
'borderImageOutset',
'borderImageSlice',
'borderImageWidth',
'columnCount',
'flex',
'flexGrow',
'flexPositive',
'flexShrink',
'flexOrder',
'gridRow',
'gridColumn',
'fontWeight',
'lineClamp',
'opacity',
'order',
'orphans',
'tabSize',
'widows',
'zIndex',
'zoom',
'fillOpacity',
'floodOpacity',
'stopOpacity',
'strokeDasharray',
'strokeDashoffset',
'strokeMiterlimit',
'strokeOpacity',
'strokeWidth',
])