better fallback for transparent colors
This commit is contained in:
parent
8536f3cc32
commit
552d13a060
1 changed files with 58 additions and 7 deletions
|
@ -35,8 +35,8 @@ export const DEFAULT_OPACITY = {
|
||||||
export const SLOT_INHERITANCE = {
|
export const SLOT_INHERITANCE = {
|
||||||
bg: {
|
bg: {
|
||||||
depends: [],
|
depends: [],
|
||||||
priority: 1,
|
opacity: 'bg',
|
||||||
opacity: 'bg'
|
priority: 1
|
||||||
},
|
},
|
||||||
fg: {
|
fg: {
|
||||||
depends: [],
|
depends: [],
|
||||||
|
@ -272,6 +272,9 @@ export const SLOT_INHERITANCE = {
|
||||||
variant: 'btnPressed',
|
variant: 'btnPressed',
|
||||||
textColor: true
|
textColor: true
|
||||||
},
|
},
|
||||||
|
btnPressedPanel: {
|
||||||
|
depends: ['btnPressed']
|
||||||
|
},
|
||||||
btnPressedPanelText: {
|
btnPressedPanelText: {
|
||||||
depends: ['btnPanelText'],
|
depends: ['btnPanelText'],
|
||||||
layer: 'btnPanel',
|
layer: 'btnPanel',
|
||||||
|
@ -490,8 +493,13 @@ export const getOpacitySlot = (
|
||||||
inheritance = SLOT_INHERITANCE,
|
inheritance = SLOT_INHERITANCE,
|
||||||
getDeps = getDependencies
|
getDeps = getDependencies
|
||||||
) => {
|
) => {
|
||||||
if (v.opacity === null) return
|
const value = typeof v === 'string'
|
||||||
if (v.opacity) return v.opacity
|
? {
|
||||||
|
depends: v.startsWith('--') ? [v.substring(2)] : []
|
||||||
|
}
|
||||||
|
: v
|
||||||
|
if (value.opacity === null) return
|
||||||
|
if (value.opacity) return v.opacity
|
||||||
const findInheritedOpacity = (val) => {
|
const findInheritedOpacity = (val) => {
|
||||||
const depSlot = val.depends[0]
|
const depSlot = val.depends[0]
|
||||||
if (depSlot === undefined) return
|
if (depSlot === undefined) return
|
||||||
|
@ -505,8 +513,40 @@ export const getOpacitySlot = (
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (v.depends) {
|
if (value.depends) {
|
||||||
return findInheritedOpacity(v)
|
return findInheritedOpacity(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getLayerSlot = (
|
||||||
|
k,
|
||||||
|
v,
|
||||||
|
inheritance = SLOT_INHERITANCE,
|
||||||
|
getDeps = getDependencies
|
||||||
|
) => {
|
||||||
|
const value = typeof v === 'string'
|
||||||
|
? {
|
||||||
|
depends: v.startsWith('--') ? [v.substring(2)] : []
|
||||||
|
}
|
||||||
|
: v
|
||||||
|
if (LAYERS[k]) return k
|
||||||
|
if (value.layer === null) return
|
||||||
|
if (value.layer) return v.layer
|
||||||
|
const findInheritedLayer = (val) => {
|
||||||
|
const depSlot = val.depends[0]
|
||||||
|
if (depSlot === undefined) return
|
||||||
|
const dependency = getDeps(depSlot, inheritance)[0]
|
||||||
|
if (dependency === undefined) return
|
||||||
|
if (dependency.layer || dependency === null) {
|
||||||
|
return dependency.layer
|
||||||
|
} else if (dependency.depends) {
|
||||||
|
return findInheritedLayer(dependency)
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (value.depends) {
|
||||||
|
return findInheritedLayer(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,9 +590,20 @@ export const getColors = (sourceColors, sourceOpacity, mod) => SLOT_ORDERED.redu
|
||||||
// Color is defined in source color
|
// Color is defined in source color
|
||||||
let targetColor = sourceColor
|
let targetColor = sourceColor
|
||||||
if (targetColor === 'transparent') {
|
if (targetColor === 'transparent') {
|
||||||
|
// We take only layers below current one
|
||||||
|
const layers = getLayers(
|
||||||
|
getLayerSlot(key, value),
|
||||||
|
key,
|
||||||
|
value.opacity || key,
|
||||||
|
colors,
|
||||||
|
opacity
|
||||||
|
).slice(0, -1)
|
||||||
targetColor = {
|
targetColor = {
|
||||||
// TODO: try to use alpha-blended background here
|
// TODO: try to use alpha-blended background here
|
||||||
...convert('#FF00FF').rgb,
|
...alphaBlendLayers(
|
||||||
|
convert('#FF00FF').rgb,
|
||||||
|
layers
|
||||||
|
),
|
||||||
a: 0
|
a: 0
|
||||||
}
|
}
|
||||||
} else if (typeof sourceColor === 'string' && sourceColor.startsWith('--')) {
|
} else if (typeof sourceColor === 'string' && sourceColor.startsWith('--')) {
|
||||||
|
|
Loading…
Reference in a new issue