fixed get(Layer|Opacity)Slot not working properly which broke Mojave theme
This commit is contained in:
parent
8de7eabd8f
commit
7354b6f706
3 changed files with 30 additions and 43 deletions
|
@ -246,7 +246,7 @@ export default {
|
||||||
if (!slotIsText) return acc
|
if (!slotIsText) return acc
|
||||||
const { layer, variant } = slotIsBaseText ? { layer: 'bg' } : value
|
const { layer, variant } = slotIsBaseText ? { layer: 'bg' } : value
|
||||||
const background = variant || layer
|
const background = variant || layer
|
||||||
const opacitySlot = getOpacitySlot(SLOT_INHERITANCE[background])
|
const opacitySlot = getOpacitySlot(background)
|
||||||
const textColors = [
|
const textColors = [
|
||||||
key,
|
key,
|
||||||
...(background === 'bg' ? ['cRed', 'cGreen', 'cBlue', 'cOrange'] : [])
|
...(background === 'bg' ? ['cRed', 'cGreen', 'cBlue', 'cOrange'] : [])
|
||||||
|
|
|
@ -392,16 +392,6 @@ export const colors2to3 = (colors) => {
|
||||||
...btnStates.reduce((stateAcc, state) => ({ ...stateAcc, ['btn' + state]: color }), {})
|
...btnStates.reduce((stateAcc, state) => ({ ...stateAcc, ['btn' + state]: color }), {})
|
||||||
}
|
}
|
||||||
case 'btnText':
|
case 'btnText':
|
||||||
console.log(
|
|
||||||
btnPositions
|
|
||||||
.map(position => btnStates.map(state => state + position))
|
|
||||||
.flat()
|
|
||||||
.reduce(
|
|
||||||
(statePositionAcc, statePosition) =>
|
|
||||||
({ ...statePositionAcc, ['btn' + statePosition + 'Text']: color })
|
|
||||||
, {}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
...btnPositions
|
...btnPositions
|
||||||
|
@ -414,7 +404,6 @@ export const colors2to3 = (colors) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
console.log('aaa', slotName, color, acc)
|
|
||||||
return { ...acc, [slotName]: color }
|
return { ...acc, [slotName]: color }
|
||||||
}
|
}
|
||||||
}, {})
|
}, {})
|
||||||
|
|
|
@ -591,38 +591,41 @@ export const topoSort = (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const expandSlotValue = (value) => {
|
||||||
|
if (typeof value === 'object') return value
|
||||||
|
return {
|
||||||
|
depends: value.startsWith('--') ? [value.substring(2)] : [],
|
||||||
|
default: value.startsWith('#') ? value : undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* retrieves opacity slot for given slot. This goes up the depenency graph
|
* retrieves opacity slot for given slot. This goes up the depenency graph
|
||||||
* to find which parent has opacity slot defined for it.
|
* to find which parent has opacity slot defined for it.
|
||||||
* TODO refactor this
|
* TODO refactor this
|
||||||
*/
|
*/
|
||||||
export const getOpacitySlot = (
|
export const getOpacitySlot = (
|
||||||
v,
|
k,
|
||||||
inheritance = SLOT_INHERITANCE,
|
inheritance = SLOT_INHERITANCE,
|
||||||
getDeps = getDependencies
|
getDeps = getDependencies
|
||||||
) => {
|
) => {
|
||||||
const value = typeof v === 'string'
|
const value = expandSlotValue(inheritance[k])
|
||||||
? {
|
|
||||||
depends: v.startsWith('--') ? [v.substring(2)] : []
|
|
||||||
}
|
|
||||||
: v
|
|
||||||
if (value.opacity === null) return
|
if (value.opacity === null) return
|
||||||
if (value.opacity) return v.opacity
|
if (value.opacity) return value.opacity
|
||||||
const findInheritedOpacity = (val) => {
|
const findInheritedOpacity = (key, visited = [k]) => {
|
||||||
const depSlot = val.depends[0]
|
const depSlot = getDeps(key, inheritance)[0]
|
||||||
if (depSlot === undefined) return
|
if (depSlot === undefined) return
|
||||||
const dependency = getDeps(depSlot, inheritance)[0]
|
const dependency = inheritance[depSlot]
|
||||||
if (dependency === undefined) return
|
if (dependency === undefined) return
|
||||||
if (dependency.opacity || dependency === null) {
|
if (dependency.opacity || dependency === null) {
|
||||||
return dependency.opacity
|
return dependency.opacity
|
||||||
} else if (dependency.depends) {
|
} else if (dependency.depends && visited.includes(depSlot)) {
|
||||||
return findInheritedOpacity(dependency)
|
return findInheritedOpacity(depSlot, [...visited, depSlot])
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value.depends) {
|
if (value.depends) {
|
||||||
return findInheritedOpacity(value)
|
return findInheritedOpacity(k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,33 +638,28 @@ export const getOpacitySlot = (
|
||||||
*/
|
*/
|
||||||
export const getLayerSlot = (
|
export const getLayerSlot = (
|
||||||
k,
|
k,
|
||||||
v,
|
|
||||||
inheritance = SLOT_INHERITANCE,
|
inheritance = SLOT_INHERITANCE,
|
||||||
getDeps = getDependencies
|
getDeps = getDependencies
|
||||||
) => {
|
) => {
|
||||||
const value = typeof v === 'string'
|
const value = expandSlotValue(inheritance[k])
|
||||||
? {
|
|
||||||
depends: v.startsWith('--') ? [v.substring(2)] : []
|
|
||||||
}
|
|
||||||
: v
|
|
||||||
if (LAYERS[k]) return k
|
if (LAYERS[k]) return k
|
||||||
if (value.layer === null) return
|
if (value.layer === null) return
|
||||||
if (value.layer) return v.layer
|
if (value.layer) return value.layer
|
||||||
const findInheritedLayer = (val) => {
|
const findInheritedLayer = (key, visited = [k]) => {
|
||||||
const depSlot = val.depends[0]
|
const depSlot = getDeps(key, inheritance)[0]
|
||||||
if (depSlot === undefined) return
|
if (depSlot === undefined) return
|
||||||
const dependency = getDeps(depSlot, inheritance)[0]
|
const dependency = inheritance[depSlot]
|
||||||
if (dependency === undefined) return
|
if (dependency === undefined) return
|
||||||
if (dependency.layer || dependency === null) {
|
if (dependency.layer || dependency === null) {
|
||||||
return dependency.layer
|
return dependency.layer
|
||||||
} else if (dependency.depends) {
|
} else if (dependency.depends) {
|
||||||
return findInheritedLayer(dependency)
|
return findInheritedLayer(dependency, [...visited, depSlot])
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value.depends) {
|
if (value.depends) {
|
||||||
return findInheritedLayer(value)
|
return findInheritedLayer(k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,7 +677,7 @@ export const SLOT_ORDERED = topoSort(
|
||||||
* with them
|
* with them
|
||||||
*/
|
*/
|
||||||
export const SLOTS_OPACITIES_DICT = Object.entries(SLOT_INHERITANCE).reduce((acc, [k, v]) => {
|
export const SLOTS_OPACITIES_DICT = Object.entries(SLOT_INHERITANCE).reduce((acc, [k, v]) => {
|
||||||
const opacity = getOpacitySlot(v, SLOT_INHERITANCE, getDependencies)
|
const opacity = getOpacitySlot(k, SLOT_INHERITANCE, getDependencies)
|
||||||
if (opacity) {
|
if (opacity) {
|
||||||
return { ...acc, [k]: opacity }
|
return { ...acc, [k]: opacity }
|
||||||
} else {
|
} else {
|
||||||
|
@ -692,7 +690,7 @@ export const SLOTS_OPACITIES_DICT = Object.entries(SLOT_INHERITANCE).reduce((acc
|
||||||
* color slots.
|
* color slots.
|
||||||
*/
|
*/
|
||||||
export const OPACITIES = Object.entries(SLOT_INHERITANCE).reduce((acc, [k, v]) => {
|
export const OPACITIES = Object.entries(SLOT_INHERITANCE).reduce((acc, [k, v]) => {
|
||||||
const opacity = getOpacitySlot(v, SLOT_INHERITANCE, getDependencies)
|
const opacity = getOpacitySlot(k, SLOT_INHERITANCE, getDependencies)
|
||||||
if (opacity) {
|
if (opacity) {
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
|
@ -738,9 +736,9 @@ export const getColors = (sourceColors, sourceOpacity, mod) => SLOT_ORDERED.redu
|
||||||
if (targetColor === 'transparent') {
|
if (targetColor === 'transparent') {
|
||||||
// We take only layers below current one
|
// We take only layers below current one
|
||||||
const layers = getLayers(
|
const layers = getLayers(
|
||||||
getLayerSlot(key, value),
|
getLayerSlot(key),
|
||||||
key,
|
key,
|
||||||
value.opacity || key,
|
getOpacitySlot(key) || key,
|
||||||
colors,
|
colors,
|
||||||
opacity
|
opacity
|
||||||
).slice(0, -1)
|
).slice(0, -1)
|
||||||
|
@ -781,7 +779,7 @@ export const getColors = (sourceColors, sourceOpacity, mod) => SLOT_ORDERED.redu
|
||||||
getLayers(
|
getLayers(
|
||||||
value.layer,
|
value.layer,
|
||||||
value.variant || value.layer,
|
value.variant || value.layer,
|
||||||
getOpacitySlot(SLOT_INHERITANCE[value.variant || value.layer]),
|
getOpacitySlot(value.variant || value.layer),
|
||||||
colors,
|
colors,
|
||||||
opacity
|
opacity
|
||||||
)
|
)
|
||||||
|
@ -813,7 +811,7 @@ export const getColors = (sourceColors, sourceOpacity, mod) => SLOT_ORDERED.redu
|
||||||
if (!outputColor) {
|
if (!outputColor) {
|
||||||
throw new Error('Couldn\'t generate color for ' + key)
|
throw new Error('Couldn\'t generate color for ' + key)
|
||||||
}
|
}
|
||||||
const opacitySlot = SLOTS_OPACITIES_DICT[key]
|
const opacitySlot = getOpacitySlot(key)
|
||||||
if (opacitySlot && outputColor.a === undefined) {
|
if (opacitySlot && outputColor.a === undefined) {
|
||||||
outputColor.a = sourceOpacity[opacitySlot] || OPACITIES[opacitySlot].defaultValue || 1
|
outputColor.a = sourceOpacity[opacitySlot] || OPACITIES[opacitySlot].defaultValue || 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue