-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
69 lines (67 loc) · 1.8 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
/**
* TailwindCSS Font Sizes
* Generates font sizes in ems
* @file index.js
*/
const plugin = require('tailwindcss/plugin')
const _ = require('lodash')
// const selectorParser = require('postcss-selector-parser')
/**
* getSizes
* Handles getting sizes in pixels
* @param {int} totalSizes
* @param {int} startingValue
* @return {object}
*/
const getSizes = (totalSizes = 900, startingValue = 0) => {
// The following generates an array of increasing values from the totalSizes above.
const sizeArray = Array.from(Array(startingValue + totalSizes + 1).keys())
const sliced = sizeArray.slice(startingValue, sizeArray.length)
// Traverse the array and generate sizes in pxs.
const sizes = sliced.map((i, x) =>
x > 0 ? { [`${x}px`]: `${x}px;` } : { [`${x}px`]: `${x};` }
)
// Merge the array of objects into a single one
const sizeObj = Object.assign.apply(Object, sizes)
// console.log('sizeObj', sizeObj)
return sizeObj
}
module.exports = plugin.withOptions(
function (options) {
return function ({ addUtilities, e, variants, theme }) {
// ...
}
},
function (options) {
// Widths
// Option defaults
// {
// total: 900,
// startingSize: 0,
// }
const widths = getSizes(
(options && options.width && options.width.total) || 900,
(options && options.width && options.width.startingSize) || 0
)
const heights = getSizes(
(options && options.height && options.height.total) || 900,
(options && options.height && options.height.startingSize) || 0
)
return {
theme: {
// fontSizes: {
extend: {
width: {
...widths,
},
height: {
...heights,
},
},
},
// variants: {
// fontSizes: [],
// },
}
}
)