forked from AkkomaGang/akkoma-fe
support for "transparent" color keyword
This commit is contained in:
parent
6e11924c27
commit
332d31dc02
5 changed files with 78 additions and 44 deletions
|
@ -25,6 +25,14 @@ const v1OnlyNames = [
|
||||||
'cOrange'
|
'cOrange'
|
||||||
].map(_ => _ + 'ColorLocal')
|
].map(_ => _ + 'ColorLocal')
|
||||||
|
|
||||||
|
const colorConvert = (color) => {
|
||||||
|
if (color === 'transparent') {
|
||||||
|
return color
|
||||||
|
} else {
|
||||||
|
return hex2rgb(color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
@ -228,36 +236,36 @@ export default {
|
||||||
|
|
||||||
// fgsfds :DDDD
|
// fgsfds :DDDD
|
||||||
const fgs = {
|
const fgs = {
|
||||||
text: hex2rgb(colors.text),
|
text: colorConvert(colors.text),
|
||||||
panelText: hex2rgb(colors.panelText),
|
panelText: colorConvert(colors.panelText),
|
||||||
panelLink: hex2rgb(colors.panelLink),
|
panelLink: colorConvert(colors.panelLink),
|
||||||
btnText: hex2rgb(colors.btnText),
|
btnText: colorConvert(colors.btnText),
|
||||||
topBarText: hex2rgb(colors.topBarText),
|
topBarText: colorConvert(colors.topBarText),
|
||||||
inputText: hex2rgb(colors.inputText),
|
inputText: colorConvert(colors.inputText),
|
||||||
|
|
||||||
link: hex2rgb(colors.link),
|
link: colorConvert(colors.link),
|
||||||
topBarLink: hex2rgb(colors.topBarLink),
|
topBarLink: colorConvert(colors.topBarLink),
|
||||||
|
|
||||||
red: hex2rgb(colors.cRed),
|
red: colorConvert(colors.cRed),
|
||||||
green: hex2rgb(colors.cGreen),
|
green: colorConvert(colors.cGreen),
|
||||||
blue: hex2rgb(colors.cBlue),
|
blue: colorConvert(colors.cBlue),
|
||||||
orange: hex2rgb(colors.cOrange)
|
orange: colorConvert(colors.cOrange)
|
||||||
}
|
}
|
||||||
|
|
||||||
const bgs = {
|
const bgs = {
|
||||||
bg: hex2rgb(colors.bg),
|
bg: colorConvert(colors.bg),
|
||||||
underlay: hex2rgb(colors.underlay),
|
underlay: colorConvert(colors.underlay),
|
||||||
btn: hex2rgb(colors.btn),
|
btn: colorConvert(colors.btn),
|
||||||
panel: hex2rgb(colors.panel),
|
panel: colorConvert(colors.panel),
|
||||||
topBar: hex2rgb(colors.topBar),
|
topBar: colorConvert(colors.topBar),
|
||||||
input: hex2rgb(colors.input),
|
input: colorConvert(colors.input),
|
||||||
alertError: hex2rgb(colors.alertError),
|
alertError: colorConvert(colors.alertError),
|
||||||
alertWarning: hex2rgb(colors.alertWarning),
|
alertWarning: colorConvert(colors.alertWarning),
|
||||||
badgeNotification: hex2rgb(colors.badgeNotification)
|
badgeNotification: colorConvert(colors.badgeNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
const bg = [bgs.bg, opacity.bg]
|
const bg = [bgs.bg, opacity.bg]
|
||||||
const underlay = [bgs.underlay, opacity.underlay]
|
const underlay = [bgs.underlay || colorConvert('#000000'), opacity.underlay]
|
||||||
|
|
||||||
const panel = [underlay, bg]
|
const panel = [underlay, bg]
|
||||||
|
|
||||||
|
@ -443,7 +451,7 @@ export default {
|
||||||
*/
|
*/
|
||||||
normalizeLocalState (originalInput, version = 0) {
|
normalizeLocalState (originalInput, version = 0) {
|
||||||
let input
|
let input
|
||||||
if (typeof originalInput.v3compat !== undefined) {
|
if (typeof originalInput.v3compat !== 'undefined') {
|
||||||
version = 3
|
version = 3
|
||||||
input = merge(originalInput, originalInput.v3compat)
|
input = merge(originalInput, originalInput.v3compat)
|
||||||
} else {
|
} else {
|
||||||
|
@ -574,7 +582,7 @@ export default {
|
||||||
this.previewColors = generateColors({
|
this.previewColors = generateColors({
|
||||||
v3compat: this.currentCompat,
|
v3compat: this.currentCompat,
|
||||||
opacity: this.currentOpacity,
|
opacity: this.currentOpacity,
|
||||||
colors: this.currentColors,
|
colors: this.currentColors
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e)
|
console.warn(e)
|
||||||
|
|
|
@ -7,7 +7,8 @@ const rgb2hex = (r, g, b) => {
|
||||||
if (r === null || typeof r === 'undefined') {
|
if (r === null || typeof r === 'undefined') {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
if (r[0] === '#') {
|
// TODO: clean up this mess
|
||||||
|
if (r[0] === '#' || r === 'transparent') {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
if (typeof r === 'object') {
|
if (typeof r === 'object') {
|
||||||
|
|
|
@ -170,23 +170,32 @@ export const generateCompat = (input) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const generateColors = (input) => {
|
const generateColors = (themeData) => {
|
||||||
const colors = {}
|
const colors = {}
|
||||||
const opacity = Object.assign({
|
const rawOpacity = Object.assign({
|
||||||
alert: 0.5,
|
alert: 0.5,
|
||||||
input: 0.5,
|
input: 0.5,
|
||||||
faint: 0.5,
|
faint: 0.5,
|
||||||
underlay: 0.15
|
underlay: 0.15
|
||||||
}, Object.entries(input.opacity || {}).reduce((acc, [k, v]) => {
|
}, Object.entries(themeData.opacity || {}).reduce((acc, [k, v]) => {
|
||||||
if (typeof v !== 'undefined') {
|
if (typeof v !== 'undefined') {
|
||||||
acc[k] = v
|
acc[k] = v
|
||||||
}
|
}
|
||||||
return acc
|
return acc
|
||||||
}, {}))
|
}, {}))
|
||||||
|
|
||||||
const inputColors = input.colors || input
|
const inputColors = themeData.colors || themeData
|
||||||
|
|
||||||
const compat = input.v3compat || {}
|
const transparentsOpacity = Object.entries(inputColors).reduce((acc, [k, v]) => {
|
||||||
|
if (v === 'transparent') {
|
||||||
|
acc[k] = 0
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
const opacity = { ...rawOpacity, ...transparentsOpacity }
|
||||||
|
|
||||||
|
const compat = themeData.v3compat || {}
|
||||||
const compatColors = Object.entries(compat.colors || {}).reduce((acc, [key, value]) => {
|
const compatColors = Object.entries(compat.colors || {}).reduce((acc, [key, value]) => {
|
||||||
const newVal = value === null ? undefined : value
|
const newVal = value === null ? undefined : value
|
||||||
return { ...acc, [key]: newVal }
|
return { ...acc, [key]: newVal }
|
||||||
|
@ -196,15 +205,22 @@ const generateColors = (input) => {
|
||||||
if (typeof v === 'object') {
|
if (typeof v === 'object') {
|
||||||
acc[k] = v
|
acc[k] = v
|
||||||
} else {
|
} else {
|
||||||
acc[k] = hex2rgb(v)
|
let value = v
|
||||||
|
if (v === 'transparent') {
|
||||||
|
value = '#FF00FF'
|
||||||
|
}
|
||||||
|
acc[k] = hex2rgb(value)
|
||||||
}
|
}
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
|
|
||||||
const isLightOnDark = convert(col.bg).hsl.l < convert(col.text).hsl.l
|
colors.bg = col.bg
|
||||||
|
colors.underlay = col.underlay || hex2rgb('#000000')
|
||||||
|
colors.text = col.text
|
||||||
|
|
||||||
|
const isLightOnDark = convert(colors.bg).hsl.l < convert(colors.text).hsl.l
|
||||||
const mod = isLightOnDark ? 1 : -1
|
const mod = isLightOnDark ? 1 : -1
|
||||||
|
|
||||||
colors.text = col.text
|
|
||||||
colors.lightText = brightness(20 * mod, colors.text).rgb
|
colors.lightText = brightness(20 * mod, colors.text).rgb
|
||||||
|
|
||||||
colors.accent = col.accent || col.link
|
colors.accent = col.accent || col.link
|
||||||
|
@ -212,17 +228,15 @@ const generateColors = (input) => {
|
||||||
|
|
||||||
colors.faint = col.faint || Object.assign({}, col.text)
|
colors.faint = col.faint || Object.assign({}, col.text)
|
||||||
|
|
||||||
colors.bg = col.bg
|
|
||||||
colors.lightBg = col.lightBg || brightness(5 * mod, colors.bg).rgb
|
colors.lightBg = col.lightBg || brightness(5 * mod, colors.bg).rgb
|
||||||
|
|
||||||
const underlay = [col.underlay, opacity.underlay]
|
const underlay = [colors.underlay, opacity.underlay]
|
||||||
const fg = [col.fg, opacity.fg]
|
const fg = [col.fg, opacity.fg]
|
||||||
const bg = [col.bg, opacity.bg]
|
const bg = [col.bg, opacity.bg]
|
||||||
|
|
||||||
colors.fg = col.fg
|
colors.fg = col.fg
|
||||||
colors.fgText = col.fgText || getTextColor(alphaBlendLayers(colors.text, [underlay, bg, fg]), colors.text)
|
colors.fgText = col.fgText || getTextColor(alphaBlendLayers(colors.text, [underlay, bg, fg]), colors.text)
|
||||||
colors.fgLink = col.fgLink || getTextColor(alphaBlendLayers(colors.link, [underlay, bg, fg]), colors.link, true)
|
colors.fgLink = col.fgLink || getTextColor(alphaBlendLayers(colors.link, [underlay, bg, fg]), colors.link, true)
|
||||||
colors.underlay = col.underlay || hex2rgb('#000000')
|
|
||||||
|
|
||||||
colors.border = col.border || brightness(2 * mod, colors.fg).rgb
|
colors.border = col.border || brightness(2 * mod, colors.fg).rgb
|
||||||
|
|
||||||
|
@ -231,8 +245,8 @@ const generateColors = (input) => {
|
||||||
colors.btnText = col.btnText || getTextColor(alphaBlendLayers(colors.fgText, [underlay, bg, fg, btn]), colors.fgText)
|
colors.btnText = col.btnText || getTextColor(alphaBlendLayers(colors.fgText, [underlay, bg, fg, btn]), colors.fgText)
|
||||||
|
|
||||||
colors.input = col.input || Object.assign({}, col.fg)
|
colors.input = col.input || Object.assign({}, col.fg)
|
||||||
const inputCol = [colors.input, opacity.input]
|
const input = [colors.input, opacity.input]
|
||||||
colors.inputText = col.inputText || getTextColor(alphaBlendLayers(colors.lightText, [underlay, bg, fg, inputCol]), colors.lightText)
|
colors.inputText = col.inputText || getTextColor(alphaBlendLayers(colors.lightText, [underlay, bg, fg, input]), colors.lightText)
|
||||||
|
|
||||||
colors.panel = col.panel || Object.assign({}, col.fg)
|
colors.panel = col.panel || Object.assign({}, col.fg)
|
||||||
const panel = [colors.panel, opacity.panel]
|
const panel = [colors.panel, opacity.panel]
|
||||||
|
@ -256,12 +270,14 @@ const generateColors = (input) => {
|
||||||
colors.cOrange = col.cOrange || hex2rgb('#E3FF00')
|
colors.cOrange = col.cOrange || hex2rgb('#E3FF00')
|
||||||
|
|
||||||
colors.alertError = col.alertError || Object.assign({}, colors.cRed)
|
colors.alertError = col.alertError || Object.assign({}, colors.cRed)
|
||||||
colors.alertErrorText = getTextColor(alphaBlend(colors.alertError, opacity.alert, colors.bg), colors.text)
|
const alertError = [colors.alertError, opacity.alert]
|
||||||
colors.alertErrorPanelText = getTextColor(alphaBlend(colors.alertError, opacity.alert, colors.panel), colors.panelText)
|
colors.alertErrorText = getTextColor(alphaBlendLayers(colors.text, [underlay, bg, alertError]), colors.text)
|
||||||
|
colors.alertErrorPanelText = getTextColor(alphaBlendLayers(colors.panelText, [underlay, bg, panel, panel, alertError]), colors.panelText)
|
||||||
|
|
||||||
colors.alertWarning = col.alertWarning || Object.assign({}, colors.cOrange)
|
colors.alertWarning = col.alertWarning || Object.assign({}, colors.cOrange)
|
||||||
colors.alertWarningText = getTextColor(alphaBlend(colors.alertWarning, opacity.alert, colors.bg), colors.text)
|
const alertWarning = [colors.alertWarning, opacity.alert]
|
||||||
colors.alertWarningPanelText = getTextColor(alphaBlend(colors.alertWarning, opacity.alert, colors.panel), colors.panelText)
|
colors.alertWarningText = getTextColor(alphaBlendLayers(colors.text, [underlay, bg, alertWarning]), colors.text)
|
||||||
|
colors.alertWarningPanelText = getTextColor(alphaBlendLayers(colors.panelText, [underlay, bg, panel, panel, alertWarning]), colors.panelText)
|
||||||
|
|
||||||
colors.badgeNotification = col.badgeNotification || Object.assign({}, colors.cRed)
|
colors.badgeNotification = col.badgeNotification || Object.assign({}, colors.cRed)
|
||||||
colors.badgeNotificationText = contrastRatio(colors.badgeNotification).rgb
|
colors.badgeNotificationText = contrastRatio(colors.badgeNotification).rgb
|
||||||
|
|
|
@ -107,8 +107,12 @@
|
||||||
},
|
},
|
||||||
"fonts": {},
|
"fonts": {},
|
||||||
"opacity": {
|
"opacity": {
|
||||||
"input": "1",
|
"input": "1"
|
||||||
"panel": "0"
|
},
|
||||||
|
"v3compat": {
|
||||||
|
"colors": {
|
||||||
|
"panel": "transparent"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"colors": {
|
"colors": {
|
||||||
"bg": "#31363b",
|
"bg": "#31363b",
|
||||||
|
|
|
@ -109,6 +109,11 @@
|
||||||
"opacity": {
|
"opacity": {
|
||||||
"input": "1"
|
"input": "1"
|
||||||
},
|
},
|
||||||
|
"v3compat": {
|
||||||
|
"colors": {
|
||||||
|
"panel": "transparent"
|
||||||
|
}
|
||||||
|
},
|
||||||
"colors": {
|
"colors": {
|
||||||
"bg": "#eff0f1",
|
"bg": "#eff0f1",
|
||||||
"text": "#232627",
|
"text": "#232627",
|
||||||
|
|
Loading…
Reference in a new issue