-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
42 lines (36 loc) · 1.05 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
// @flow
import type { Interpolation, ScopedInsertableStyles } from '@emotion/types'
import hashString from '@emotion/hash'
import { handleInterpolation, labelPattern } from '@emotion/serialize'
let fakeRegisteredCache = {}
function css(
strings: Interpolation | string[],
...interpolations: Interpolation[]
): ScopedInsertableStyles {
let stringMode = true
let styles: string = ''
let identifierName = ''
if (strings == null || strings.raw === undefined) {
stringMode = false
styles += handleInterpolation(fakeRegisteredCache, strings)
} else {
styles += strings[0]
}
interpolations.forEach(function(interpolation, i) {
styles += handleInterpolation(fakeRegisteredCache, interpolation)
if (stringMode === true && strings[i + 1] !== undefined) {
styles += strings[i + 1]
}
}, this)
styles = styles.replace(labelPattern, (match, p1: string) => {
identifierName += `-${p1}`
return ''
})
let name = hashString(styles) + identifierName
return {
type: 1,
name,
styles
}
}
export default css