-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
417 lines (409 loc) · 7.57 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
import {Dimensions} from 'react-native';
const {width, height} = Dimensions.get('window');
let ratio = width / 375;
const styles = {
winh: height,
winw: width,
h100: {
height: '100%',
},
w100: {
width: '100%',
},
uWrap: {
flexWrap: 'wrap', //自动换行
},
uNoWrap: {
flexWrap: 'nowrap', //截断
},
//主轴的排列方向
udr: {
//主轴为水平方向,起点在左端
flexDirection: 'row',
},
udrr: {
//主轴为水平方向,起点在右端
flexDirection: 'row-reverse',
},
udc: {
//主轴为垂直方向,起点在上沿
flexDirection: 'column',
},
udcr: {
//主轴为垂直方向,起点在下沿
flexDirection: 'column-reverse',
},
//主轴的排列方向 end
uf1: {
flex: 1,
},
//次轴排序
uas: {
//居前
alignItems: 'flex-start',
},
uac: {
//居中
alignItems: 'center',
},
uae: {
//居后
alignItems: 'flex-end',
},
ual: {
alignItems: 'baseline',
},
uacs: {
alignContent: 'flex-start'
},
uacc: {
alignContent: 'center'
},
uacb: {
alignContent: 'space-between'
},
uaca: {
alignContent: 'space-around'
},
//主轴排序
ujs: {
//居前
justifyContent: 'flex-start',
},
ujc: {
//居中
justifyContent: 'center',
},
uje: {
//居后
justifyContent: 'flex-end',
},
uja: {
//平均分布
justifyContent: 'space-around',
},
ujb: {
//两端
justifyContent: 'space-between',
},
//自身次轴对齐 alignSelf enum('auto', 'flex-start', 'flex-end', 'center', 'stretch')
uSelfAuto: {alignSelf: 'auto'},
uSelfStart: {alignSelf: 'flex-start'},
uSelfEnd: {alignSelf: 'flex-end'},
uSelfCenter: {alignSelf: 'center'},
uSelfStretch: {alignSelf: 'stretch'},
upa: {
//绝对定位
position: 'absolute',
},
upr: {
position: 'relative',
},
uof: {
//超出隐藏
overflow: 'hidden',
},
//文字水平居中 enum('auto', 'left', 'right', 'center')
utxc: {
textAlign: 'center',
},
//水平居右
utxr: {
textAlign: 'right',
},
utxl: {
textAlign: 'left',
},
//文字垂直居顶
utxvt: {
textAlignVertical: 'top',
},
//文字垂直居中
utxvc: {
textAlignVertical: 'center',
},
//文本横线-底部
utxdu: {
textDecorationLine: 'underline',
},
//文本横线-中间
utxdt: {
textDecorationLine: 'line-through',
},
//文本横线-中间和底部
utxdut: {
textDecorationLine: 'underline line-through',
},
//盒子
uf: num => {
return {flex: num};
},
//高度
h: c => {
return {height: c * ratio};
},
h_: c => {
return {height: c};
},
//最小高度
minh: c => {
return {minHeight: c * ratio};
},
//最大高度
maxh: c => {
return {maxHeight: c * ratio};
},
maxh_: c => {
return {maxHeight: c};
},
//宽度百分比
wRatio: number => {
return {width: number + '%'};
},
//高度百分比
hRatio: number => {
return {height: number + '%'};
},
//宽度
w: c => {
return {width: c * ratio};
},
//宽度
w_: c => {
return {width: c};
},
//宽高一样
size: c => {
return {height: c * ratio, width: c * ratio}
},
//最小宽度
minw: c => {
return {minWidth: c * ratio};
},
//最大宽度
maxw: c => {
return {maxWidth: c * ratio};
},
//内边距
pt: c => {
return {paddingTop: c * ratio};
},
pt_: c => {
return {paddingTop: c};
},
pr: c => {
return {paddingRight: c * ratio};
},
pl: c => {
return {paddingLeft: c * ratio};
},
pb: c => {
return {paddingBottom: c * ratio};
},
pb_: c => {
return {paddingBottom: c};
},
ptb: c => {
return {paddingTop: c * ratio, paddingBottom: c * ratio};
},
ptb_: c => {
return {paddingTop: c, paddingBottom: c};
},
plr: c => {
return {paddingRight: c * ratio, paddingLeft: c * ratio};
},
plr_: c => {
return {paddingRight: c, paddingLeft: c};
},
pa: c => {
return {padding: c * ratio};
},
bt: number => {
return {borderTopWidth: number};
},
bb: number => {
return {borderBottomWidth: number};
},
bl: number => {
return {borderLeftWidth: number};
},
br: number => {
return {borderRightWidth: number};
},
blr: number => {
return {borderLeftWidth: number, borderRightWidth: number};
},
btb: number => {
return {borderTopWidth: number, borderBottomWidth: number};
},
ba: number => {
return {borderWidth: number * ratio};
},
ba_: number => {
return {borderWidth: number};
},
mt: c => {
return {marginTop: c * ratio};
},
mt_: c => {
return {marginTop: c};
},
mb: c => {
return {marginBottom: c * ratio};
},
ml: c => {
return {marginLeft: c * ratio};
},
ml_: c => {
return {marginLeft: c};
},
mr: c => {
return {marginRight: c * ratio};
},
mr_: c => {
return {marginRight: c};
},
mlr: c => {
return {marginLeft: c * ratio, marginRight: c * ratio};
},
mtb: c => {
return {marginTop: c * ratio, marginBottom: c * ratio};
},
ma: c => {
return {margin: c * ratio};
},
radiusA: c => {
return {borderRadius: c * ratio};
},
radiusA_: c => {
return {borderRadius: c};
},
radiusTL: c => {
return {
borderTopLeftRadius: c * ratio,
};
},
radiusTR: c => {
return {borderTopRightRadius: c * ratio};
},
radiusBL: c => {
return {borderBottomLeftRadius: c * ratio};
},
radiusBR: c => {
return {borderBottomRightRadius: c * ratio};
},
shadowColor: c => {
return {shadowColor: c};
},
shadowOffset: (w, h) => {
return {shadowOffset: {width: w * ratio, height: h * ratio}};
},
shadowOpacity: c => {
return {shadowOpacity: c};
},
shadowRadius: c => {
return {shadowRadius: c};
},
elevation: c => {
return {elevation: c};
},
//位置
top: c => {
return {top: c * ratio};
},
top_: c => {
return {top: c};
},
bottom: c => {
return {bottom: c * ratio};
},
bottom_: c => {
return {bottom: c};
},
left: c => {
return {left: c * ratio};
},
left_: c => {
return {left: c};
},
right: c => {
return {right: c * ratio};
},
right_: c => {
return {right: c};
},
/*字体大小*/
fSize: c => {
return {fontSize: c * ratio};
},
/*字体样式 italic:字体倾斜 normal:正常*/
fStyle: c => {
return {fontStyle: c};
},
/*字体加粗*/
fWeight: c => {
return {fontWeight: c, fontFamily: 'System'};
},
/*字体*/
fFamily: c => {
return {fontFamily: c};
},
/*字体颜色*/
color: c => {
return {color: c};
},
/*背景色*/
bgColor: c => {
return {backgroundColor: c};
},
/*边框色*/
bdColor: c => {
return {borderColor: c};
},
/*左边框色*/
blColor: c => {
return {borderLeftColor: c};
},
/*右边框色*/
brColor: c => {
return {borderRightColor: c};
},
/*上边框色*/
btColor: c => {
return {borderTopColor: c};
},
/*下边框色*/
bbColor: c => {
return {borderBottomColor: c};
},
bdStyle: c => {
return {borderStyle: c}
},
/*透明度*/
opacity: c => {
return {opacity: c};
},
zIndex: c => {
return {zIndex: c};
},
lh: c => {
return {lineHeight: c};
},
tf: c => {
return {transform: [{skewX: c + 'deg'}, {skewY: c + 'deg'}]};
},
calc: c => {
return c * ratio;
}
};
function setSize(size) {
if (typeof size !== 'number') {
throw new TypeError('size must be a number')
}
if (size === 0) {
throw new RangeError('size cannot be 0')
}
ratio = width / size
}
export {setSize}
export default styles;