-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
mediaQuery.ts
86 lines (65 loc) · 1.88 KB
/
mediaQuery.ts
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
import PropTypes from 'prop-types'
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number])
// media types
const types = {
all: PropTypes.bool,
grid: PropTypes.bool,
aural: PropTypes.bool,
braille: PropTypes.bool,
handheld: PropTypes.bool,
print: PropTypes.bool,
projection: PropTypes.bool,
screen: PropTypes.bool,
tty: PropTypes.bool,
tv: PropTypes.bool,
embossed: PropTypes.bool
}
// properties that match media queries
const matchers = {
orientation: PropTypes.oneOf(['portrait', 'landscape']),
scan: PropTypes.oneOf(['progressive', 'interlace']),
aspectRatio: PropTypes.string,
deviceAspectRatio: PropTypes.string,
height: stringOrNumber,
deviceHeight: stringOrNumber,
width: stringOrNumber,
deviceWidth: stringOrNumber,
color: PropTypes.bool,
colorIndex: PropTypes.bool,
monochrome: PropTypes.bool,
resolution: stringOrNumber,
type: Object.keys(types)
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { type, ...featureMatchers } = matchers
// media features
const features = {
minAspectRatio: PropTypes.string,
maxAspectRatio: PropTypes.string,
minDeviceAspectRatio: PropTypes.string,
maxDeviceAspectRatio: PropTypes.string,
minHeight: stringOrNumber,
maxHeight: stringOrNumber,
minDeviceHeight: stringOrNumber,
maxDeviceHeight: stringOrNumber,
minWidth: stringOrNumber,
maxWidth: stringOrNumber,
minDeviceWidth: stringOrNumber,
maxDeviceWidth: stringOrNumber,
minColor: PropTypes.number,
maxColor: PropTypes.number,
minColorIndex: PropTypes.number,
maxColorIndex: PropTypes.number,
minMonochrome: PropTypes.number,
maxMonochrome: PropTypes.number,
minResolution: stringOrNumber,
maxResolution: stringOrNumber,
...featureMatchers
}
const all = { ...types, ...features }
export default {
all: all,
types: types,
matchers: matchers,
features: features
}