Merge branch 'feature/theming2' into shigusegubu

* feature/theming2:
  fixed keep checkboxes working when exporting
  unbreak user profiles
  fix preview input text using wrong string
  fix panel link color, fix broken user profiles
This commit is contained in:
Henry Jameson 2018-11-26 21:18:27 +03:00
commit 68df06f149
7 changed files with 65 additions and 19 deletions

View file

@ -407,6 +407,11 @@ main-router {
min-width: 1px; min-width: 1px;
align-self: stretch; align-self: stretch;
} }
a {
color: $fallback--link;
color: var(--panelLink, $fallback--link)
}
} }
.panel-heading.stub { .panel-heading.stub {
@ -417,6 +422,11 @@ main-router {
.panel-footer { .panel-footer {
border-radius: 0 0 $fallback--panelRadius $fallback--panelRadius; border-radius: 0 0 $fallback--panelRadius $fallback--panelRadius;
border-radius: 0 0 var(--panelRadius, $fallback--panelRadius) var(--panelRadius, $fallback--panelRadius); border-radius: 0 0 var(--panelRadius, $fallback--panelRadius) var(--panelRadius, $fallback--panelRadius);
a {
color: $fallback--link;
color: var(--panelLink, $fallback--link)
}
} }
.panel-body > p { .panel-body > p {

View file

@ -62,6 +62,7 @@ export default {
panelColorLocal: undefined, panelColorLocal: undefined,
panelTextColorLocal: undefined, panelTextColorLocal: undefined,
panelLinkColorLocal: undefined,
panelFaintColorLocal: undefined, panelFaintColorLocal: undefined,
panelOpacityLocal: undefined, panelOpacityLocal: undefined,
@ -155,6 +156,7 @@ export default {
panel: this.panelColorLocal, panel: this.panelColorLocal,
panelText: this.panelTextColorLocal, panelText: this.panelTextColorLocal,
panelLink: this.panelLinkColorLocal,
panelFaint: this.panelFaintColorLocal, panelFaint: this.panelFaintColorLocal,
input: this.inputColorLocal, input: this.inputColorLocal,
@ -230,6 +232,7 @@ export default {
const fgs = { const fgs = {
text: hex2rgb(colors.text), text: hex2rgb(colors.text),
panelText: hex2rgb(colors.panelText), panelText: hex2rgb(colors.panelText),
panelLink: hex2rgb(colors.panelLink),
btnText: hex2rgb(colors.btnText), btnText: hex2rgb(colors.btnText),
topBarText: hex2rgb(colors.topBarText), topBarText: hex2rgb(colors.topBarText),
inputText: hex2rgb(colors.inputText), inputText: hex2rgb(colors.inputText),
@ -268,6 +271,7 @@ export default {
tintText: getContrastRatio(alphaBlend(bgs.bg, 0.5, fgs.panelText), fgs.text), tintText: getContrastRatio(alphaBlend(bgs.bg, 0.5, fgs.panelText), fgs.text),
panelText: getContrastRatio(alphaBlend(bgs.panel, opacity.panel, fgs.panelText), fgs.panelText), panelText: getContrastRatio(alphaBlend(bgs.panel, opacity.panel, fgs.panelText), fgs.panelText),
panelLink: getContrastRatio(alphaBlend(bgs.panel, opacity.panel, fgs.panelLink), fgs.panelLink),
btnText: getContrastRatio(alphaBlend(bgs.btn, opacity.btn, fgs.btnText), fgs.btnText), btnText: getContrastRatio(alphaBlend(bgs.btn, opacity.btn, fgs.btnText), fgs.btnText),
@ -328,16 +332,34 @@ export default {
}, },
methods: { methods: {
exportCurrentTheme () { exportCurrentTheme () {
const stringified = JSON.stringify({ const saveEverything = !this.keepFonts && !this.keepShadows && !this.keepColors && !this.keepOpacity && !this.keepRoundness
// To separate from other random JSON files and possible future theme formats const theme = {
_pleroma_theme_version: 2,
theme: {
shadows: this.shadowsLocal, shadows: this.shadowsLocal,
fonts: this.fontsLocal, fonts: this.fontsLocal,
opacity: this.currentOpacity, opacity: this.currentOpacity,
colors: this.currentColors, colors: this.currentColors,
radii: this.currentRadii radii: this.currentRadii
} }
if (!this.keepFonts && !saveEverything) {
delete theme.fonts
}
if (!this.keepShadows && !saveEverything) {
delete theme.shadows
}
if (!this.keepOpacity && !saveEverything) {
delete theme.opacity
}
if (!this.keepColors && !saveEverything) {
delete theme.colors
}
if (!this.keepRoundness && !saveEverything) {
delete theme.radii
}
const stringified = JSON.stringify({
// To separate from other random JSON files and possible future theme formats
_pleroma_theme_version: 2, theme
}, null, 2) // Pretty-print and indent with 2 spaces }, null, 2) // Pretty-print and indent with 2 spaces
// Create an invisible link with a data url and simulate a click // Create an invisible link with a data url and simulate a click
@ -400,7 +422,9 @@ export default {
}, },
clearAll () { clearAll () {
this.normalizeLocalState(this.$store.state.config.customTheme) const state = this.$store.state.config.customTheme
const version = state.colors ? 2 : 'l1'
this.normalizeLocalState(this.$store.state.config.customTheme, version)
}, },
// Clears all the extra stuff when loading V1 theme // Clears all the extra stuff when loading V1 theme
@ -438,9 +462,13 @@ export default {
}, },
/** /**
* This applies stored theme data onto form. * This applies stored theme data onto form. Supports three versions of data:
* v2 (version = 2) - newer version of themes.
* v1 (version = 1) - older version of themes (import from file)
* v1l (version = l1) - older version of theme (load from local storage)
* v1 and v1l differ because of way themes were stored/exported.
* @param {Object} input - input data * @param {Object} input - input data
* @param {Number} version - version of data. 0 means try to guess based on data. * @param {Number} version - version of data. 0 means try to guess based on data. "l1" means v1, locastorage type
*/ */
normalizeLocalState (input, version = 0) { normalizeLocalState (input, version = 0) {
const colors = input.colors || input const colors = input.colors || input
@ -461,6 +489,8 @@ export default {
} }
} }
console.log(version)
// Stuff that differs between V1 and V2 // Stuff that differs between V1 and V2
if (version === 1) { if (version === 1) {
this.fgColorLocal = rgb2hex(colors.btn) this.fgColorLocal = rgb2hex(colors.btn)
@ -468,7 +498,7 @@ export default {
} }
const keys = new Set(version !== 1 ? Object.keys(colors) : []) const keys = new Set(version !== 1 ? Object.keys(colors) : [])
if (version === 1) { if (version === 1 || version === 'l1') {
// V1 ignores the rest // V1 ignores the rest
this.clearV1() this.clearV1()
keys keys
@ -479,6 +509,7 @@ export default {
.add('cGreen') .add('cGreen')
.add('cOrange') .add('cOrange')
} }
keys.forEach(key => { keys.forEach(key => {
this[key + 'ColorLocal'] = rgb2hex(colors[key]) this[key + 'ColorLocal'] = rgb2hex(colors[key])
}) })

View file

@ -97,7 +97,7 @@
<br> <br>
<br> <br>
<input :value="$t('settings.style.preview.error')" type="text"> <input :value="$t('settings.style.preview.input')" type="text">
<span class="alert error"> <span class="alert error">
{{$t('settings.style.preview.error')}} {{$t('settings.style.preview.error')}}
</span> </span>
@ -183,8 +183,10 @@
<h4>{{ $t('settings.style.advanced_colors.panel_header') }}</h4> <h4>{{ $t('settings.style.advanced_colors.panel_header') }}</h4>
<ColorInput name="panelColor" v-model="panelColorLocal" :fallback="fgColorLocal" :label="$t('settings.background')"/> <ColorInput name="panelColor" v-model="panelColorLocal" :fallback="fgColorLocal" :label="$t('settings.background')"/>
<OpacityInput name="panelOpacity" v-model="panelOpacityLocal" :fallback="previewTheme.opacity.panel || 1"/> <OpacityInput name="panelOpacity" v-model="panelOpacityLocal" :fallback="previewTheme.opacity.panel || 1"/>
<ColorInput name="panelTextColor" v-model="panelTextColorLocal" :fallback="previewTheme.colors.panelText" :label="$t('settings.links')"/> <ColorInput name="panelTextColor" v-model="panelTextColorLocal" :fallback="previewTheme.colors.panelText" :label="$t('settings.text')"/>
<ContrastRatio :contrast="previewContrast.panelText" large="1"/> <ContrastRatio :contrast="previewContrast.panelText" large="1"/>
<ColorInput name="panelLinkColor" v-model="panelLinkColorLocal" :fallback="previewTheme.colors.panelLink" :label="$t('settings.links')"/>
<ContrastRatio :contrast="previewContrast.panelLink" large="1"/>
</div> </div>
<div class="color-item"> <div class="color-item">
<h4>{{ $t('settings.style.advanced_colors.top_bar') }}</h4> <h4>{{ $t('settings.style.advanced_colors.top_bar') }}</h4>

View file

@ -12,7 +12,10 @@ export default {
}, },
computed: { computed: {
headingStyle () { headingStyle () {
const color = this.$store.state.config.customTheme.colors.bg const color = this.$store.state.config.customTheme.colors ?
this.$store.state.config.customTheme.colors.bg : // v2
this.$store.state.config.colors.bg // v1
if (color) { if (color) {
const rgb = (typeof color === 'string') ? hex2rgb(color) : color const rgb = (typeof color === 'string') ? hex2rgb(color) : color
const tintColor = `rgba(${Math.floor(rgb.r)}, ${Math.floor(rgb.g)}, ${Math.floor(rgb.b)}, .5)` const tintColor = `rgba(${Math.floor(rgb.r)}, ${Math.floor(rgb.g)}, ${Math.floor(rgb.b)}, .5)`

View file

@ -105,10 +105,9 @@
<span v-if="!hideUserStatsLocal">{{user.followers_count}}</span> <span v-if="!hideUserStatsLocal">{{user.followers_count}}</span>
</div> </div>
</div> </div>
</div>
<p v-if="!hideBio && user.description_html" class="profile-bio" v-html="user.description_html"></p> <p v-if="!hideBio && user.description_html" class="profile-bio" v-html="user.description_html"></p>
<p v-else-if="!hideBio" class="profile-bio">{{ user.description }}</p> <p v-else-if="!hideBio" class="profile-bio">{{ user.description }}</p>
</div> </div>
</div> </div>
</template> </template>

View file

@ -183,7 +183,7 @@
"keep_opacity": "Keep opacity", "keep_opacity": "Keep opacity",
"keep_roundness": "Keep roundness", "keep_roundness": "Keep roundness",
"keep_fonts": "Keep fonts", "keep_fonts": "Keep fonts",
"save_load_hint": "\"Keep\" options preserve currently set options when selecting or loading themes, it also stores said options when exporting a theme.", "save_load_hint": "\"Keep\" options preserve currently set options when selecting or loading themes, it also stores said options when exporting a theme. When all checkboxes unset, exporting theme will save everything.",
"reset": "Reset", "reset": "Reset",
"clear_all": "Clear all", "clear_all": "Clear all",
"clear_opacity": "Clear opacity" "clear_opacity": "Clear opacity"

View file

@ -172,6 +172,7 @@ const generateColors = (input) => {
colors.panel = col.panel || Object.assign({}, col.fg) colors.panel = col.panel || Object.assign({}, col.fg)
colors.panelText = col.panelText || getTextColor(colors.panel, colors.fgText) colors.panelText = col.panelText || getTextColor(colors.panel, colors.fgText)
colors.panelLink = col.panelLink || getTextColor(colors.panel, colors.fgLink)
colors.panelFaint = col.panelFaint || getTextColor(colors.panel, colors.faint) colors.panelFaint = col.panelFaint || getTextColor(colors.panel, colors.faint)
colors.topBar = col.topBar || Object.assign({}, col.fg) colors.topBar = col.topBar || Object.assign({}, col.fg)