react-tailwindcss-style 1.0.1

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.
Files changed (71) hide show
  1. package/.github/workflows/node.js.yml +28 -0
  2. package/.prettierrc +7 -0
  3. package/LICENSE +21 -0
  4. package/README.md +116 -0
  5. package/babel.config.js +12 -0
  6. package/cli.sh +1 -0
  7. package/color.js +10 -0
  8. package/corePlugins/alignContent.js +10 -0
  9. package/corePlugins/alignItems.js +9 -0
  10. package/corePlugins/alignSelf.js +10 -0
  11. package/corePlugins/backfaceVisibility.js +6 -0
  12. package/corePlugins/backgroundColor.js +4 -0
  13. package/corePlugins/borderColor.js +4 -0
  14. package/corePlugins/borderRadius.js +19 -0
  15. package/corePlugins/borderRadiusDir.js +11 -0
  16. package/corePlugins/borderStyle.js +7 -0
  17. package/corePlugins/borderWidth.js +13 -0
  18. package/corePlugins/borderWidthDir.js +8 -0
  19. package/corePlugins/bottom.js +4 -0
  20. package/corePlugins/boxShadow.js +4 -0
  21. package/corePlugins/direction.js +7 -0
  22. package/corePlugins/display.js +6 -0
  23. package/corePlugins/end.js +4 -0
  24. package/corePlugins/flex.js +4 -0
  25. package/corePlugins/flexDirection.js +8 -0
  26. package/corePlugins/flexGrow.js +4 -0
  27. package/corePlugins/flexShrink.js +4 -0
  28. package/corePlugins/flexWrap.js +7 -0
  29. package/corePlugins/fontFamily.js +4 -0
  30. package/corePlugins/fontPadding.js +6 -0
  31. package/corePlugins/fontSize.js +4 -0
  32. package/corePlugins/fontStyle.js +6 -0
  33. package/corePlugins/fontWeight.js +13 -0
  34. package/corePlugins/height.js +4 -0
  35. package/corePlugins/inset.js +7 -0
  36. package/corePlugins/insetDir.js +6 -0
  37. package/corePlugins/justifyContent.js +10 -0
  38. package/corePlugins/left.js +4 -0
  39. package/corePlugins/letterSpacing.js +4 -0
  40. package/corePlugins/lineHeight.js +4 -0
  41. package/corePlugins/margin.js +13 -0
  42. package/corePlugins/maxHeight.js +4 -0
  43. package/corePlugins/maxWidth.js +4 -0
  44. package/corePlugins/minHeight.js +4 -0
  45. package/corePlugins/minWidth.js +4 -0
  46. package/corePlugins/objectFit.js +8 -0
  47. package/corePlugins/opacity.js +4 -0
  48. package/corePlugins/overflow.js +7 -0
  49. package/corePlugins/padding.js +13 -0
  50. package/corePlugins/position.js +6 -0
  51. package/corePlugins/resize.js +9 -0
  52. package/corePlugins/right.js +4 -0
  53. package/corePlugins/start.js +4 -0
  54. package/corePlugins/textAlign.js +9 -0
  55. package/corePlugins/textColor.js +4 -0
  56. package/corePlugins/textDecoration.js +8 -0
  57. package/corePlugins/textShadow.js +4 -0
  58. package/corePlugins/textTransform.js +8 -0
  59. package/corePlugins/tint.js +4 -0
  60. package/corePlugins/top.js +4 -0
  61. package/corePlugins/verticalAlign.js +8 -0
  62. package/corePlugins/width.js +4 -0
  63. package/corePlugins/zIndex.js +4 -0
  64. package/index.d.ts +5327 -0
  65. package/index.js +15 -0
  66. package/package.json +38 -0
  67. package/stubs/defaultConfig.stub.js +583 -0
  68. package/stubs/simpleConfig.stub.js +5 -0
  69. package/tailwind.js +121 -0
  70. package/util/configHandler.js +11 -0
  71. package/util/generator.js +409 -0
package/tailwind.js ADDED
@@ -0,0 +1,121 @@
1
+ import {StyleSheet} from 'react-native';
2
+
3
+ import alignContent from './corePlugins/alignContent';
4
+ import alignItems from './corePlugins/alignItems';
5
+ import alignSelf from './corePlugins/alignSelf';
6
+ import backfaceVisibility from './corePlugins/backfaceVisibility';
7
+ import borderStyle from './corePlugins/borderStyle';
8
+ import direction from './corePlugins/direction';
9
+ import display from './corePlugins/display';
10
+ import flexDirection from './corePlugins/flexDirection';
11
+ import flexWrap from './corePlugins/flexWrap';
12
+ import fontPadding from './corePlugins/fontPadding';
13
+ import fontStyle from './corePlugins/fontStyle';
14
+ import fontWeight from './corePlugins/fontWeight';
15
+ import justifyContent from './corePlugins/justifyContent';
16
+ import objectFit from './corePlugins/objectFit';
17
+ import overflow from './corePlugins/overflow';
18
+ import position from './corePlugins/position';
19
+ import resize from './corePlugins/resize';
20
+ import textAlign from './corePlugins/textAlign';
21
+ import textDecoration from './corePlugins/textDecoration';
22
+ import textTransform from './corePlugins/textTransform';
23
+ import verticalAlign from './corePlugins/verticalAlign';
24
+ import backgroundColor from './corePlugins/backgroundColor';
25
+ import borderColor from './corePlugins/borderColor';
26
+ import borderRadius from './corePlugins/borderRadius';
27
+ import borderWidth from './corePlugins/borderWidth';
28
+ import flex from './corePlugins/flex';
29
+ import flexGrow from './corePlugins/flexGrow';
30
+ import flexShrink from './corePlugins/flexShrink';
31
+ import fontFamily from './corePlugins/fontFamily';
32
+ import fontSize from './corePlugins/fontSize';
33
+ import height from './corePlugins/height';
34
+ import inset from './corePlugins/inset';
35
+ import top from './corePlugins/top';
36
+ import bottom from './corePlugins/bottom';
37
+ import left from './corePlugins/left';
38
+ import right from './corePlugins/right';
39
+ import start from './corePlugins/start';
40
+ import end from './corePlugins/end';
41
+ import letterSpacing from './corePlugins/letterSpacing';
42
+ import lineHeight from './corePlugins/lineHeight';
43
+ import margin from './corePlugins/margin';
44
+ import maxHeight from './corePlugins/maxHeight';
45
+ import maxWidth from './corePlugins/maxWidth';
46
+ import minHeight from './corePlugins/minHeight';
47
+ import minWidth from './corePlugins/minWidth';
48
+ import opacity from './corePlugins/opacity';
49
+ import padding from './corePlugins/padding';
50
+ import textColor from './corePlugins/textColor';
51
+ import tint from './corePlugins/tint';
52
+ import width from './corePlugins/width';
53
+ import zIndex from './corePlugins/zIndex';
54
+ import boxShadow from './corePlugins/boxShadow';
55
+ import textShadow from './corePlugins/textShadow';
56
+ import insetDir from './corePlugins/insetDir';
57
+ import borderWidthDir from './corePlugins/borderWidthDir';
58
+ import borderRadiusDir from './corePlugins/borderRadiusDir';
59
+
60
+ let style = {};
61
+
62
+ Object.assign(style,
63
+ alignContent,
64
+ alignItems,
65
+ alignSelf,
66
+ backfaceVisibility,
67
+ borderStyle,
68
+ direction,
69
+ display,
70
+ flexDirection,
71
+ flexWrap,
72
+ fontPadding,
73
+ fontStyle,
74
+ fontWeight,
75
+ justifyContent,
76
+ objectFit,
77
+ overflow,
78
+ position,
79
+ resize,
80
+ textAlign,
81
+ textDecoration,
82
+ textTransform,
83
+ verticalAlign,
84
+ backgroundColor,
85
+ borderColor,
86
+ borderRadius,
87
+ borderWidth,
88
+ boxShadow,
89
+ flex,
90
+ flexGrow,
91
+ flexShrink,
92
+ fontFamily,
93
+ fontSize,
94
+ height,
95
+ inset,
96
+ top,
97
+ bottom,
98
+ left,
99
+ right,
100
+ start,
101
+ end,
102
+ letterSpacing,
103
+ lineHeight,
104
+ margin,
105
+ maxHeight,
106
+ maxWidth,
107
+ minHeight,
108
+ minWidth,
109
+ opacity,
110
+ padding,
111
+ textColor,
112
+ textShadow,
113
+ tint,
114
+ width,
115
+ zIndex,
116
+ borderRadiusDir,
117
+ borderWidthDir,
118
+ insetDir,
119
+ );
120
+
121
+ export default StyleSheet.create(style);
@@ -0,0 +1,11 @@
1
+ import resolveConfig from 'tailwindcss/resolveConfig';
2
+
3
+ let file = require('../stubs/simpleConfig.stub');
4
+
5
+ try {
6
+ file = require('../../../tailwind.config');
7
+ } catch (e) {}
8
+
9
+ const {theme} = resolveConfig(file);
10
+
11
+ export default theme;
@@ -0,0 +1,409 @@
1
+ export default {
2
+ generate(name, key, values, variation = []) {
3
+ let i = 0,
4
+ j = 0,
5
+ styles = {},
6
+ value = '',
7
+ styleName = '',
8
+ valueName = '',
9
+ keyName = '',
10
+ keys = '',
11
+ keyStyleName = '';
12
+
13
+ const styleValues = this.parseThemeValues(values),
14
+ valuesLength = styleValues.length,
15
+ variationLength = variation.length;
16
+
17
+ for (; i < valuesLength; ++i) {
18
+ value = this.getValue(styleValues[i]);
19
+ valueName = this.getValueName(styleValues[i]);
20
+ keyName = this.getKeyName(name, valueName);
21
+
22
+ styleName = this.translateKeys(keyName);
23
+
24
+ if (
25
+ this.guardAgainstCssNotSupportedInReactNative(
26
+ key,
27
+ this.translateValues(value)
28
+ )
29
+ ) {
30
+ styles[styleName] = this.guardedKeyHandler(key, value);
31
+
32
+ continue;
33
+ }
34
+
35
+ styles[styleName] = this.keyHandler(key, value);
36
+ }
37
+
38
+ if (variationLength) {
39
+ j = 0;
40
+ value = '';
41
+ styleName = '';
42
+ valueName = '';
43
+ keyName = '';
44
+ keyStyleName = '';
45
+
46
+ for (; j < variationLength; ++j) {
47
+ i = 0;
48
+ keyName = `${name}-${variation[j][0]}`;
49
+ keys = variation[j][1];
50
+
51
+ for (; i < valuesLength; ++i) {
52
+ value = this.getValue(styleValues[i]);
53
+ valueName = this.getValueName(styleValues[i]);
54
+ keyStyleName = this.getKeyName(keyName, valueName);
55
+
56
+ styleName = this.translateKeys(keyStyleName);
57
+
58
+ if (
59
+ this.guardAgainstCssNotSupportedInReactNative(
60
+ keys,
61
+ this.translateValues(value)
62
+ )
63
+ ) {
64
+ styles[styleName] = this.guardedKeyHandler(keys, value);
65
+
66
+ continue;
67
+ }
68
+
69
+ styles[styleName] = this.keyHandler(keys, value);
70
+ }
71
+ }
72
+ }
73
+
74
+ return styles;
75
+ },
76
+
77
+ generateShadows(name, key, values) {
78
+ let i = 0,
79
+ styles = {},
80
+ value = '',
81
+ styleName = '',
82
+ valueName = '',
83
+ keyName = '',
84
+ shadowValues = {};
85
+
86
+ const styleValues = this.parseThemeValues(values),
87
+ valuesLength = styleValues.length;
88
+
89
+ for (; i < valuesLength; ++i) {
90
+ value = this.getValue(styleValues[i]);
91
+ valueName = this.getValueName(styleValues[i]);
92
+ keyName = this.getKeyName(name, valueName);
93
+ shadowValues = this.getShadowValues(value);
94
+
95
+ styleName = this.translateKeys(keyName);
96
+ styles[styleName] = {};
97
+
98
+ styles[styleName][`${key}Color`] = shadowValues.color;
99
+ styles[styleName][`${key}Offset`] = shadowValues.offset;
100
+ styles[styleName][`${key}Radius`] = shadowValues.radius;
101
+
102
+ if (key === 'shadow') {
103
+ styles[styleName][`${key}Opacity`] = shadowValues.opacity;
104
+ styles[styleName]['elevation'] = shadowValues.elevation;
105
+ }
106
+ }
107
+
108
+ return styles;
109
+ },
110
+
111
+ generateColors(colors) {
112
+ let colorList = {},
113
+ color,
114
+ currentColor,
115
+ colorKey,
116
+ colorValue,
117
+ colorName,
118
+ currentColorKeys;
119
+
120
+ for (color in colors) {
121
+ colorName = color;
122
+
123
+ currentColor = colors[colorName];
124
+
125
+ if (typeof currentColor !== 'object') {
126
+ colorValue = this.translateValues(currentColor);
127
+
128
+ colorName = this.translateKeys(colorName);
129
+
130
+ colorList[colorName] = colorValue;
131
+ }
132
+
133
+ if (typeof currentColor === 'object') {
134
+ currentColorKeys = Object.getOwnPropertyNames(currentColor);
135
+
136
+ currentColorKeys.map(key => {
137
+ if (['dynamic', 'semantic'].includes(key)) {
138
+ colorValue = this.translateValues(currentColor);
139
+
140
+ colorName = this.translateKeys(colorName);
141
+
142
+ colorList[colorName] = colorValue;
143
+ } else {
144
+ colorValue = this.translateValues(currentColor[key]);
145
+
146
+ colorKey = this.translateKeys(`${colorName}-${key}`);
147
+
148
+ colorList[colorKey] = colorValue;
149
+ }
150
+ });
151
+ }
152
+ }
153
+
154
+ return colorList;
155
+ },
156
+
157
+ getValue(value) {
158
+ let valueToReturn = value;
159
+
160
+ if (typeof value === 'object') {
161
+ valueToReturn = value[1];
162
+ }
163
+
164
+ if (
165
+ typeof valueToReturn === 'object' &&
166
+ !valueToReturn.semantic &&
167
+ !valueToReturn.dynamic
168
+ ) {
169
+ valueToReturn = valueToReturn[0];
170
+ }
171
+
172
+ return valueToReturn;
173
+ },
174
+
175
+ getValueName(value) {
176
+ if (typeof value === 'object') {
177
+ return value[0];
178
+ }
179
+
180
+ return value;
181
+ },
182
+
183
+ getKeyName(name, valueName) {
184
+ let keyName = valueName,
185
+ prefix = name;
186
+
187
+ if (keyName.substring(0, 1) === '-') {
188
+ prefix = `-${name}`;
189
+ keyName = keyName.substring(1);
190
+ }
191
+
192
+ if (prefix !== '') {
193
+ keyName = `${prefix}-${keyName}`;
194
+ }
195
+
196
+ return keyName;
197
+ },
198
+
199
+ keyHandler(keys, value) {
200
+ let i = 0,
201
+ tempObject = {};
202
+ const keysLength = keys.length;
203
+
204
+ if (typeof keys === 'object') {
205
+ for (; i < keysLength; ++i) {
206
+ tempObject[keys[i]] = this.translateValues(value);
207
+ }
208
+
209
+ return tempObject;
210
+ }
211
+
212
+ tempObject[keys] = this.translateValues(value);
213
+
214
+ return tempObject;
215
+ },
216
+
217
+ guardAgainstCssNotSupportedInReactNative(property, value) {
218
+ if (property === 'zIndex' && typeof value !== 'number') {
219
+ return true;
220
+ }
221
+
222
+ if (property === 'fontWeight' && typeof value === 'number') {
223
+ return true;
224
+ }
225
+
226
+ if (property === 'letterSpacing') {
227
+ return true;
228
+ }
229
+
230
+ if (property === 'flex' && typeof value !== 'number') {
231
+ return true;
232
+ }
233
+
234
+ return false;
235
+ },
236
+
237
+ guardedKeyHandler(property, value) {
238
+ let tempObject = {},
239
+ translatedValue = 0;
240
+
241
+ if (property === 'zIndex' && typeof value !== 'number') {
242
+ tempObject[property] = 0;
243
+ }
244
+
245
+ if (property === 'fontWeight') {
246
+ tempObject[property] = `${value}`;
247
+ }
248
+
249
+ if (property === 'letterSpacing') {
250
+ if (value.search('em') !== -1) {
251
+ translatedValue = parseFloat(value.slice(0, -2)) * 16;
252
+ }
253
+
254
+ tempObject[property] = translatedValue;
255
+ }
256
+
257
+ if (property === 'flex' && typeof value !== 'number') {
258
+ const firstNumber = value.match(/^[0-9]+/);
259
+
260
+ translatedValue = this.translateValues(
261
+ firstNumber && firstNumber.length ? firstNumber[0] : 0
262
+ );
263
+
264
+ tempObject[property] = translatedValue;
265
+ }
266
+
267
+ return tempObject;
268
+ },
269
+
270
+ translateKeys(name, prefix = '') {
271
+ let translatedKey = name;
272
+
273
+ if (translatedKey.search('default') !== -1) {
274
+ translatedKey = `${prefix}${translatedKey.replace('-default', '')}`;
275
+ }
276
+
277
+ if (translatedKey.search(/\//) !== -1) {
278
+ translatedKey = `${prefix}${translatedKey.replace('/', '_')}`;
279
+ }
280
+
281
+ if (translatedKey.search(/^-[a-zA-Z]/) !== -1) {
282
+ translatedKey = `${prefix}${translatedKey.replace(
283
+ /^(-)[a-zA-Z]/g,
284
+ result => {
285
+ return result.replace('-', '_');
286
+ }
287
+ )}`;
288
+ }
289
+
290
+ if (translatedKey.search('-') !== -1) {
291
+ translatedKey = translatedKey.replace(/-([a-z])/g, result => {
292
+ return result[1].toUpperCase();
293
+ });
294
+ }
295
+
296
+ if (translatedKey.search(/^[a-zA-Z_]+-[0-9]/) !== -1) {
297
+ translatedKey = `${prefix}${translatedKey.replace('-', '')}`;
298
+ }
299
+
300
+ return translatedKey;
301
+ },
302
+
303
+ translateValues(content) {
304
+ let translatedValue = content;
305
+
306
+ if (translatedValue === 'transparent') {
307
+ return 'rgba(0,0,0,0)';
308
+ }
309
+
310
+ if (translatedValue === 'true') {
311
+ return true;
312
+ }
313
+
314
+ if (translatedValue === 'false') {
315
+ return false;
316
+ }
317
+
318
+ if (typeof translatedValue !== 'string') {
319
+ return translatedValue;
320
+ }
321
+
322
+ if (content.search(/^-?[0-9]*(\.[0-9]+)?px$/) !== -1) {
323
+ translatedValue = content.replace('px', '');
324
+
325
+ return parseInt(translatedValue);
326
+ }
327
+
328
+ if (content.search(/^-?[0-9]*(\.[0-9]+)?rem$/) !== -1) {
329
+ translatedValue = content.replace('rem', '');
330
+
331
+ translatedValue = parseFloat(translatedValue) * 16;
332
+
333
+ return Math.round(translatedValue);
334
+ }
335
+
336
+ if (content.search(/^-?[0-9]*(\.[0-9]+)?em$/) !== -1) {
337
+ translatedValue = content.replace('em', '');
338
+
339
+ translatedValue = parseFloat(translatedValue) * 16;
340
+
341
+ return Math.round(translatedValue);
342
+ }
343
+
344
+ if (content.search(/^-?[0-9]+$/) !== -1) {
345
+ return parseInt(translatedValue);
346
+ }
347
+
348
+ if (content.search(/-?\.[0-9]+$/) !== -1) {
349
+ return parseFloat(translatedValue);
350
+ }
351
+
352
+ return translatedValue;
353
+ },
354
+
355
+ getShadowValues(content) {
356
+ let results, color, elevation;
357
+
358
+ if (content === 'none' || content.search(/inset/) !== -1) {
359
+ return {
360
+ color: 'rgba(0, 0, 0, 0)',
361
+ offset: {width: 0, height: 0},
362
+ radius: 0,
363
+ opacity: 0,
364
+ elevation: 0,
365
+ };
366
+ }
367
+
368
+ results = content.match(
369
+ /^([0-9]+)p?x?\s([0-9]+)p?x?\s([0-9]+)p?x?\s(-?[0-9]+)?p?x?\s?(rgba?\(.+?\))?(#[a-zA-Z0-9]{3,8})?/
370
+ );
371
+
372
+ elevation = content.match(/,(?:\s+)?(-?[0-9]+)$/);
373
+
374
+ color = results[5];
375
+
376
+ elevation = elevation
377
+ ? this.translateValues(elevation[1])
378
+ : this.translateValues(results[3]) / 2;
379
+
380
+ if (typeof color === 'undefined') {
381
+ color = results[6];
382
+ }
383
+
384
+ return {
385
+ color: color,
386
+ offset: {
387
+ width: this.translateValues(results[1]),
388
+ height: this.translateValues(results[2]),
389
+ },
390
+ radius: this.translateValues(results[3]),
391
+ opacity: 1,
392
+ elevation: elevation,
393
+ };
394
+ },
395
+
396
+ parseThemeValues(values) {
397
+ if (typeof values === 'object' && !Array.isArray(values)) {
398
+ return this.toArray(values);
399
+ }
400
+
401
+ return values;
402
+ },
403
+
404
+ toArray(object) {
405
+ return Object.keys(object).map(value => {
406
+ return [value, object[value]];
407
+ });
408
+ },
409
+ };