rule-sheet.js
1.02 KB
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
// @flow
// https://github.com/thysultan/stylis.js/tree/master/plugins/rule-sheet
// inlined to avoid umd wrapper and peerDep warnings/installing stylis
// since we use stylis after closure compiler
import type { StylisPlugin } from './types'
const delimiter = '/*|*/'
const needle = delimiter + '}'
function toSheet(block) {
if (block) {
current.push(block + '}')
}
}
let ruleSheet: StylisPlugin = (
context,
content,
selectors,
parents,
line,
column,
length,
at,
depth
) => {
switch (context) {
case -1: {
current = []
break
}
case 2:
if (at === 0) return content + delimiter
break
// at-rule
case 3:
switch (at) {
// @font-face, @page
case 102:
case 112: {
current.push(selectors[0] + content)
return ''
}
default: {
return content + delimiter
}
}
case -2: {
content.split(needle).forEach(toSheet)
return current
}
}
}
let current
export default ruleSheet