Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function mergeWithDefaultThemeVariables (themeKey, overrides) {
let variables
if (themeKey) {
variables = getVariablesWithOverrides(themeKey, overrides)
} else { // fall back to defaults, but still apply overrides
const defaultOverrides = getRegistry().overrides
const defaultOverridesIsEmpty = isEmpty(defaultOverrides)
if (!defaultOverridesIsEmpty && !isEmpty(overrides)) {
variables = mergeDeep(defaultOverrides, overrides)
} else if (defaultOverridesIsEmpty) {
variables = overrides
} else {
variables = defaultOverrides
}
}
return getVariablesWithOverrides(getDefaultThemeKey(), variables)
}
return function (variables) {
let theme = {}
if (typeof componentThemeFunction === 'function') {
theme = componentThemeFunction(variables)
}
// so that the components for the themeKey can
// just specify overrides we merge them with defaults here
let defaultComponentTheme = {}
if (typeof componentThemeFunction[themeKey] === 'function') {
defaultComponentTheme = componentThemeFunction[themeKey](variables)
}
if (!isEmpty(defaultComponentTheme) && !isEmpty(theme)) {
theme = {...theme, ...defaultComponentTheme}
} else if (isEmpty(theme)) {
theme = defaultComponentTheme
}
return theme
}
}
function mergeWithDefaultThemeVariables (themeKey, overrides) {
let variables
if (themeKey) {
variables = getVariablesWithOverrides(themeKey, overrides)
} else { // fall back to defaults, but still apply overrides
const defaultOverrides = getRegistry().overrides
const defaultOverridesIsEmpty = isEmpty(defaultOverrides)
if (!defaultOverridesIsEmpty && !isEmpty(overrides)) {
variables = mergeDeep(defaultOverrides, overrides)
} else if (defaultOverridesIsEmpty) {
variables = overrides
} else {
variables = defaultOverrides
}
}
return getVariablesWithOverrides(getDefaultThemeKey(), variables)
}
if (typeof componentThemeFunction === 'function') {
theme = componentThemeFunction(variables)
}
// so that the components for the themeKey can
// just specify overrides we merge them with defaults here
let defaultComponentTheme = {}
if (typeof componentThemeFunction[themeKey] === 'function') {
defaultComponentTheme = componentThemeFunction[themeKey](variables)
}
if (!isEmpty(defaultComponentTheme) && !isEmpty(theme)) {
theme = {...theme, ...defaultComponentTheme}
} else if (isEmpty(theme)) {
theme = defaultComponentTheme
}
return theme
}
}
function getShorthandPropValue (componentName, componentTheme, propValue, propName) {
if (typeof propValue !== 'string' || isEmpty(componentTheme)) {
return
}
return propValue
.split(' ')
.map((shortHandValue) => {
if (shortHandValue === 'auto' || shortHandValue === '0') {
return shortHandValue
}
if (shortHandValue === 'none') {
return '0'
}
if (shortHandValue === 'circle') {
return '100%'
function applyVariablesToNodeStyle (domNode, variables, defaults, prefix) {
if (!domNode || isEmpty(variables)) {
return
}
clearCustomProperties(domNode, prefix)
const overrides = pickOverrides(defaults, variables)
if (overrides && !isEmpty(overrides)) {
setCustomProperties(domNode, formatVariableNames(overrides, prefix))
}
}
function getVariablesWithOverrides (themeKey, overrides) {
const theme = getRegisteredTheme(themeKey)
const variables = theme.variables || {}
const overridesIsEmpty = isEmpty(overrides)
if (!overridesIsEmpty && theme.immutable) {
warn(
false,
`[themeable] Theme, '${theme.key}', is immutable. Cannot apply overrides: ${JSON.stringify(overrides)}`
)
return variables
}
const variablesIsEmpty = isEmpty(variables)
if (!variablesIsEmpty && !overridesIsEmpty) return mergeDeep(variables, overrides)
if (variablesIsEmpty) return overrides || {}
return variables
}
function getVariablesWithOverrides (themeKey, overrides) {
const theme = getRegisteredTheme(themeKey)
const variables = theme.variables || {}
const overridesIsEmpty = isEmpty(overrides)
if (!overridesIsEmpty && theme.immutable) {
warn(
false,
`[themeable] Theme, '${theme.key}', is immutable. Cannot apply overrides: ${JSON.stringify(overrides)}`
)
return variables
}
const variablesIsEmpty = isEmpty(variables)
if (!variablesIsEmpty && !overridesIsEmpty) return mergeDeep(variables, overrides)
if (variablesIsEmpty) return overrides || {}
return variables
}
function applyVariablesToNodeStyle (domNode, variables, defaults, prefix) {
if (!domNode || isEmpty(variables)) {
return
}
clearCustomProperties(domNode, prefix)
const overrides = pickOverrides(defaults, variables)
if (overrides && !isEmpty(overrides)) {
setCustomProperties(domNode, formatVariableNames(overrides, prefix))
}
}