diff --git a/package.json b/package.json index b41b03c..b17812c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@coreui/utils", - "version": "2.0.1", + "version": "2.0.2", "description": "CoreUI Utilities", "keywords": [ "coreui", diff --git a/src/getColor.ts b/src/getColor.ts index 7184627..7120e3f 100644 --- a/src/getColor.ts +++ b/src/getColor.ts @@ -7,7 +7,7 @@ import getStyle from './getStyle' -const getColor = (rawProperty: string, element = document.body) => { +const getColor = (rawProperty: string, element?: Element) => { const property = `--${rawProperty}` const style = getStyle(property, element) return style ? style : rawProperty diff --git a/src/getStyle.ts b/src/getStyle.ts index ea97950..2431a8c 100644 --- a/src/getStyle.ts +++ b/src/getStyle.ts @@ -5,8 +5,18 @@ * -------------------------------------------------------------------------- */ -const getStyle = (property: string, element = document.body) => { - return window.getComputedStyle(element, null).getPropertyValue(property).replace(/^\s/, '') +const getStyle = (property: string, element?: Element) => { + if (typeof window === 'undefined') { + return + } + + if (typeof document === 'undefined') { + return + } + + const _element = element ?? document.body + + return window.getComputedStyle(_element, null).getPropertyValue(property).replace(/^\s/, '') } export default getStyle