2024-05-22 19:54:19 +03:00
|
|
|
import BooleanSetting from '../helpers/boolean_setting.vue'
|
|
|
|
|
import ChoiceSetting from '../helpers/choice_setting.vue'
|
|
|
|
|
import IntegerSetting from '../helpers/integer_setting.vue'
|
|
|
|
|
import FloatSetting from '../helpers/float_setting.vue'
|
2024-06-13 02:22:47 +03:00
|
|
|
import UnitSetting, { defaultHorizontalUnits } from '../helpers/unit_setting.vue'
|
2024-05-22 19:54:19 +03:00
|
|
|
|
2024-06-27 00:59:24 +03:00
|
|
|
import FontControl from 'src/components/font_control/font_control.vue'
|
|
|
|
|
|
2024-07-17 17:19:57 +03:00
|
|
|
import { normalizeThemeData } from 'src/modules/interface'
|
|
|
|
|
|
|
|
|
|
import {
|
2024-10-01 00:42:33 +03:00
|
|
|
getThemeResources
|
2024-07-17 17:19:57 +03:00
|
|
|
} from 'src/services/style_setter/style_setter.js'
|
|
|
|
|
import { convertTheme2To3 } from 'src/services/theme_data/theme2_to_theme3.js'
|
|
|
|
|
import { init } from 'src/services/theme_data/theme_data_3.service.js'
|
|
|
|
|
import {
|
|
|
|
|
getCssRules,
|
|
|
|
|
getScopedVersion
|
|
|
|
|
} from 'src/services/theme_data/css_utils.js'
|
|
|
|
|
|
2024-05-22 19:54:19 +03:00
|
|
|
import SharedComputedObject from '../helpers/shared_computed_object.js'
|
|
|
|
|
import ProfileSettingIndicator from '../helpers/profile_setting_indicator.vue'
|
|
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
|
|
|
import {
|
|
|
|
|
faGlobe
|
|
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
2024-07-25 19:48:14 +03:00
|
|
|
import Preview from './theme_tab/theme_preview.vue'
|
2024-07-17 17:19:57 +03:00
|
|
|
|
2024-05-22 19:54:19 +03:00
|
|
|
library.add(
|
|
|
|
|
faGlobe
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const AppearanceTab = {
|
|
|
|
|
data () {
|
2024-06-13 02:22:47 +03:00
|
|
|
return {
|
2024-07-17 17:19:57 +03:00
|
|
|
availableStyles: [],
|
2024-10-01 00:42:33 +03:00
|
|
|
availablePalettes: [],
|
|
|
|
|
palettesKeys: [
|
|
|
|
|
'background',
|
|
|
|
|
'foreground',
|
|
|
|
|
'link',
|
|
|
|
|
'text',
|
|
|
|
|
'cRed',
|
|
|
|
|
'cBlue',
|
|
|
|
|
'cGreen',
|
|
|
|
|
'cOrange'
|
|
|
|
|
],
|
2024-07-17 19:58:04 +03:00
|
|
|
intersectionObserver: null,
|
2024-06-13 02:22:47 +03:00
|
|
|
thirdColumnModeOptions: ['none', 'notifications', 'postform'].map(mode => ({
|
|
|
|
|
key: mode,
|
|
|
|
|
value: mode,
|
|
|
|
|
label: this.$t(`settings.third_column_mode_${mode}`)
|
2024-06-21 22:46:01 +03:00
|
|
|
})),
|
|
|
|
|
forcedRoundnessOptions: ['disabled', 'sharp', 'nonsharp', 'round'].map((mode, i) => ({
|
|
|
|
|
key: mode,
|
|
|
|
|
value: i - 1,
|
2024-07-16 21:01:20 +03:00
|
|
|
label: this.$t(`settings.style.themes3.hacks.forced_roundness_mode_${mode}`)
|
2024-07-10 22:49:56 +03:00
|
|
|
})),
|
|
|
|
|
underlayOverrideModes: ['none', 'opaque', 'transparent'].map((mode, i) => ({
|
|
|
|
|
key: mode,
|
|
|
|
|
value: mode,
|
2024-07-16 21:01:20 +03:00
|
|
|
label: this.$t(`settings.style.themes3.hacks.underlay_override_mode_${mode}`)
|
2024-06-13 02:22:47 +03:00
|
|
|
}))
|
|
|
|
|
}
|
2024-05-22 19:54:19 +03:00
|
|
|
},
|
|
|
|
|
components: {
|
|
|
|
|
BooleanSetting,
|
|
|
|
|
ChoiceSetting,
|
|
|
|
|
IntegerSetting,
|
|
|
|
|
FloatSetting,
|
|
|
|
|
UnitSetting,
|
2024-06-27 00:59:24 +03:00
|
|
|
ProfileSettingIndicator,
|
2024-07-17 17:19:57 +03:00
|
|
|
FontControl,
|
|
|
|
|
Preview
|
|
|
|
|
},
|
2024-07-17 19:58:04 +03:00
|
|
|
mounted () {
|
2024-10-01 00:42:33 +03:00
|
|
|
getThemeResources('/static/styles.json')
|
|
|
|
|
.then((themes) => {
|
|
|
|
|
this.availableStyles = Object
|
|
|
|
|
.entries(themes)
|
|
|
|
|
.map(([key, data]) => ({ key, data, name: data.name || data[0], version: 'v2' }))
|
2024-07-17 17:19:57 +03:00
|
|
|
})
|
2024-10-01 00:42:33 +03:00
|
|
|
|
|
|
|
|
getThemeResources('/static/palettes/index.json')
|
|
|
|
|
.then((palettes) => {
|
|
|
|
|
const result = {}
|
|
|
|
|
console.log(palettes)
|
|
|
|
|
Object.entries(palettes).forEach(([k, v]) => {
|
|
|
|
|
if (Array.isArray(v)) {
|
|
|
|
|
const [
|
|
|
|
|
name,
|
|
|
|
|
background,
|
|
|
|
|
foreground,
|
|
|
|
|
text,
|
|
|
|
|
link,
|
|
|
|
|
cRed = '#FF0000',
|
|
|
|
|
cBlue = '#0000FF',
|
|
|
|
|
cGreen = '#00FF00',
|
|
|
|
|
cOrange = '#E3FF00'
|
|
|
|
|
] = v
|
|
|
|
|
result[k] = { name, background, foreground, text, link, cRed, cBlue, cGreen, cOrange }
|
|
|
|
|
} else {
|
|
|
|
|
result[k] = v
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.availablePalettes = result
|
2024-07-17 19:58:04 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (window.IntersectionObserver) {
|
|
|
|
|
this.intersectionObserver = new IntersectionObserver((entries, observer) => {
|
|
|
|
|
entries.forEach(({ target, isIntersecting }) => {
|
|
|
|
|
if (!isIntersecting) return
|
|
|
|
|
const theme = this.availableStyles.find(x => x.key === target.dataset.themeKey)
|
|
|
|
|
this.$nextTick(() => {
|
2024-07-17 22:10:11 +03:00
|
|
|
if (theme) theme.ready = true
|
2024-07-17 19:58:04 +03:00
|
|
|
})
|
|
|
|
|
observer.unobserve(target)
|
|
|
|
|
})
|
|
|
|
|
}, {
|
|
|
|
|
root: this.$refs.themeList
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
updated () {
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.$refs.themeList.querySelectorAll('.theme-preview').forEach(node => {
|
|
|
|
|
this.intersectionObserver.observe(node)
|
2024-07-17 17:19:57 +03:00
|
|
|
})
|
2024-07-17 19:58:04 +03:00
|
|
|
})
|
2024-05-22 19:54:19 +03:00
|
|
|
},
|
|
|
|
|
computed: {
|
2024-07-17 19:58:04 +03:00
|
|
|
noIntersectionObserver () {
|
|
|
|
|
return !window.IntersectionObserver
|
|
|
|
|
},
|
2024-06-13 02:22:47 +03:00
|
|
|
horizontalUnits () {
|
|
|
|
|
return defaultHorizontalUnits
|
|
|
|
|
},
|
2024-06-27 00:59:24 +03:00
|
|
|
fontsOverride () {
|
|
|
|
|
return this.$store.getters.mergedConfig.fontsOverride
|
|
|
|
|
},
|
2024-06-13 02:22:47 +03:00
|
|
|
columns () {
|
|
|
|
|
const mode = this.$store.getters.mergedConfig.thirdColumnMode
|
|
|
|
|
|
|
|
|
|
const notif = mode === 'none' ? [] : ['notifs']
|
|
|
|
|
|
|
|
|
|
if (this.$store.getters.mergedConfig.sidebarRight || mode === 'postform') {
|
|
|
|
|
return [...notif, 'content', 'sidebar']
|
|
|
|
|
} else {
|
|
|
|
|
return ['sidebar', 'content', ...notif]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
instanceSpecificPanelPresent () { return this.$store.state.instance.showInstanceSpecificPanel },
|
2024-05-22 19:54:19 +03:00
|
|
|
instanceWallpaperUsed () {
|
|
|
|
|
return this.$store.state.instance.background &&
|
|
|
|
|
!this.$store.state.users.currentUser.background_image
|
|
|
|
|
},
|
2024-06-13 02:22:47 +03:00
|
|
|
instanceShoutboxPresent () { return this.$store.state.instance.shoutAvailable },
|
|
|
|
|
language: {
|
|
|
|
|
get: function () { return this.$store.getters.mergedConfig.interfaceLanguage },
|
|
|
|
|
set: function (val) {
|
|
|
|
|
this.$store.dispatch('setOption', { name: 'interfaceLanguage', value: val })
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-07-17 22:10:11 +03:00
|
|
|
isCustomThemeUsed () {
|
|
|
|
|
const { theme } = this.mergedConfig
|
|
|
|
|
return theme === 'custom' || theme === null
|
|
|
|
|
},
|
2024-05-22 19:54:19 +03:00
|
|
|
...SharedComputedObject()
|
2024-07-17 17:19:57 +03:00
|
|
|
},
|
|
|
|
|
methods: {
|
2024-07-21 23:27:11 +03:00
|
|
|
updateFont (key, value) {
|
|
|
|
|
console.log(key, value)
|
|
|
|
|
this.$store.dispatch('setOption', {
|
|
|
|
|
name: 'theme3hacks',
|
|
|
|
|
value: {
|
|
|
|
|
...this.mergedConfig.theme3hacks,
|
|
|
|
|
fonts: {
|
|
|
|
|
...this.mergedConfig.theme3hacks.fonts,
|
|
|
|
|
[key]: value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2024-07-17 22:10:11 +03:00
|
|
|
isThemeActive (key) {
|
|
|
|
|
const { theme } = this.mergedConfig
|
|
|
|
|
return key === theme
|
|
|
|
|
},
|
|
|
|
|
setTheme (name) {
|
|
|
|
|
this.$store.dispatch('setTheme', { themeName: name, saveData: true, recompile: true })
|
2024-07-17 19:58:04 +03:00
|
|
|
},
|
2024-10-01 00:42:33 +03:00
|
|
|
setPalette (name) {
|
|
|
|
|
this.$store.dispatch('setPalette', { paletteData: name })
|
|
|
|
|
},
|
2024-07-17 19:58:04 +03:00
|
|
|
previewTheme (key, input) {
|
2024-10-01 00:42:33 +03:00
|
|
|
let theme3
|
|
|
|
|
if (input) {
|
|
|
|
|
const style = normalizeThemeData(input)
|
|
|
|
|
const theme2 = convertTheme2To3(style)
|
|
|
|
|
theme3 = init({
|
|
|
|
|
inputRuleset: theme2,
|
|
|
|
|
ultimateBackgroundColor: '#000000',
|
|
|
|
|
liteMode: true,
|
|
|
|
|
debug: true,
|
|
|
|
|
onlyNormalState: true
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
theme3 = init({
|
|
|
|
|
inputRuleset: [],
|
|
|
|
|
ultimateBackgroundColor: '#000000',
|
|
|
|
|
liteMode: true,
|
|
|
|
|
debug: true,
|
|
|
|
|
onlyNormalState: true
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-07-17 17:19:57 +03:00
|
|
|
|
|
|
|
|
return getScopedVersion(
|
|
|
|
|
getCssRules(theme3.eager),
|
2024-07-17 19:58:04 +03:00
|
|
|
'#theme-preview-' + key
|
2024-07-17 17:19:57 +03:00
|
|
|
).join('\n')
|
|
|
|
|
}
|
2024-05-22 19:54:19 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default AppearanceTab
|