-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (40 loc) · 1.44 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
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var defaultBreakpoints = {
mobile: '480px',
tablet: '768px',
desktop: '1300px'
};
var defaultUnitIntervals = {
'px': 1,
'em': 0.01,
'rem': 0.1
};
var includeMedia = function includeMedia() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$breakpoints = _ref.breakpoints,
breakpoints = _ref$breakpoints === undefined ? defaultBreakpoints : _ref$breakpoints,
_ref$unitIntervals = _ref.unitIntervals,
unitIntervals = _ref$unitIntervals === undefined ? defaultUnitIntervals : _ref$unitIntervals;
return function (mediaExpression) {
if (!mediaExpression) {
return console.warn('must provide media expression for includeMedia');
}
var isMax = mediaExpression.charAt(0) === '<';
var minOrMax = isMax ? 'max-width' : 'min-width';
var mediaExpressionValue = breakpoints[mediaExpression.slice(1)] || mediaExpression;
var value = mediaExpressionValue.replace(/\D/g, '');
var unit = mediaExpressionValue.replace(/\S*[0-9]/g, '');
var unitInterval = unitIntervals[unit];
var newValue = isMax ? value - unitInterval : value;
if (isNaN(newValue)) {
return console.warn('must provide valid value');
}
return '@media only screen and (' + minOrMax + ': ' + newValue + unit + ')';
};
};
var im = includeMedia;
exports.im = im;
exports.default = includeMedia;