File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 7
7
8
8
import getStyle from './getStyle'
9
9
10
- const getColor = ( rawProperty : string , element = document . body ) => {
10
+ const getColor = ( rawProperty : string , element ?: Element ) => {
11
11
const property = `--${ rawProperty } `
12
12
const style = getStyle ( property , element )
13
13
return style ? style : rawProperty
Original file line number Diff line number Diff line change 5
5
* --------------------------------------------------------------------------
6
6
*/
7
7
8
- const getStyle = ( property : string , element = document . body ) => {
9
- return window . getComputedStyle ( element , null ) . getPropertyValue ( property ) . replace ( / ^ \s / , '' )
8
+ const getStyle = ( property : string , element ?: Element ) => {
9
+ if ( typeof window === 'undefined' ) {
10
+ return
11
+ }
12
+
13
+ if ( typeof document === 'undefined' ) {
14
+ return
15
+ }
16
+
17
+ const _element = element ?? document . body
18
+
19
+ return window . getComputedStyle ( _element , null ) . getPropertyValue ( property ) . replace ( / ^ \s / , '' )
10
20
}
11
21
12
22
export default getStyle
You can’t perform that action at this time.
0 commit comments