logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

appearance_tab.js (5741B)


  1. import BooleanSetting from '../helpers/boolean_setting.vue'
  2. import ChoiceSetting from '../helpers/choice_setting.vue'
  3. import IntegerSetting from '../helpers/integer_setting.vue'
  4. import FloatSetting from '../helpers/float_setting.vue'
  5. import UnitSetting, { defaultHorizontalUnits } from '../helpers/unit_setting.vue'
  6. import FontControl from 'src/components/font_control/font_control.vue'
  7. import { normalizeThemeData } from 'src/modules/interface'
  8. import {
  9. getThemes
  10. } from 'src/services/style_setter/style_setter.js'
  11. import { convertTheme2To3 } from 'src/services/theme_data/theme2_to_theme3.js'
  12. import { init } from 'src/services/theme_data/theme_data_3.service.js'
  13. import {
  14. getCssRules,
  15. getScopedVersion
  16. } from 'src/services/theme_data/css_utils.js'
  17. import SharedComputedObject from '../helpers/shared_computed_object.js'
  18. import ProfileSettingIndicator from '../helpers/profile_setting_indicator.vue'
  19. import { library } from '@fortawesome/fontawesome-svg-core'
  20. import {
  21. faGlobe
  22. } from '@fortawesome/free-solid-svg-icons'
  23. import Preview from './theme_tab/theme_preview.vue'
  24. library.add(
  25. faGlobe
  26. )
  27. const AppearanceTab = {
  28. data () {
  29. return {
  30. availableStyles: [],
  31. intersectionObserver: null,
  32. thirdColumnModeOptions: ['none', 'notifications', 'postform'].map(mode => ({
  33. key: mode,
  34. value: mode,
  35. label: this.$t(`settings.third_column_mode_${mode}`)
  36. })),
  37. forcedRoundnessOptions: ['disabled', 'sharp', 'nonsharp', 'round'].map((mode, i) => ({
  38. key: mode,
  39. value: i - 1,
  40. label: this.$t(`settings.style.themes3.hacks.forced_roundness_mode_${mode}`)
  41. })),
  42. underlayOverrideModes: ['none', 'opaque', 'transparent'].map((mode, i) => ({
  43. key: mode,
  44. value: mode,
  45. label: this.$t(`settings.style.themes3.hacks.underlay_override_mode_${mode}`)
  46. }))
  47. }
  48. },
  49. components: {
  50. BooleanSetting,
  51. ChoiceSetting,
  52. IntegerSetting,
  53. FloatSetting,
  54. UnitSetting,
  55. ProfileSettingIndicator,
  56. FontControl,
  57. Preview
  58. },
  59. mounted () {
  60. getThemes()
  61. .then((promises) => {
  62. return Promise.all(
  63. Object.entries(promises)
  64. .map(([k, v]) => v.then(res => [k, res]))
  65. )
  66. })
  67. .then(themes => themes.reduce((acc, [k, v]) => {
  68. if (v) {
  69. return [
  70. ...acc,
  71. {
  72. name: v.name || v[0],
  73. key: k,
  74. data: v
  75. }
  76. ]
  77. } else {
  78. return acc
  79. }
  80. }, []))
  81. .then((themesComplete) => {
  82. this.availableStyles = themesComplete
  83. })
  84. if (window.IntersectionObserver) {
  85. this.intersectionObserver = new IntersectionObserver((entries, observer) => {
  86. entries.forEach(({ target, isIntersecting }) => {
  87. if (!isIntersecting) return
  88. const theme = this.availableStyles.find(x => x.key === target.dataset.themeKey)
  89. this.$nextTick(() => {
  90. if (theme) theme.ready = true
  91. })
  92. observer.unobserve(target)
  93. })
  94. }, {
  95. root: this.$refs.themeList
  96. })
  97. }
  98. },
  99. updated () {
  100. this.$nextTick(() => {
  101. this.$refs.themeList.querySelectorAll('.theme-preview').forEach(node => {
  102. this.intersectionObserver.observe(node)
  103. })
  104. })
  105. },
  106. computed: {
  107. noIntersectionObserver () {
  108. return !window.IntersectionObserver
  109. },
  110. horizontalUnits () {
  111. return defaultHorizontalUnits
  112. },
  113. fontsOverride () {
  114. return this.$store.getters.mergedConfig.fontsOverride
  115. },
  116. columns () {
  117. const mode = this.$store.getters.mergedConfig.thirdColumnMode
  118. const notif = mode === 'none' ? [] : ['notifs']
  119. if (this.$store.getters.mergedConfig.sidebarRight || mode === 'postform') {
  120. return [...notif, 'content', 'sidebar']
  121. } else {
  122. return ['sidebar', 'content', ...notif]
  123. }
  124. },
  125. instanceSpecificPanelPresent () { return this.$store.state.instance.showInstanceSpecificPanel },
  126. instanceWallpaperUsed () {
  127. return this.$store.state.instance.background &&
  128. !this.$store.state.users.currentUser.background_image
  129. },
  130. instanceShoutboxPresent () { return this.$store.state.instance.shoutAvailable },
  131. language: {
  132. get: function () { return this.$store.getters.mergedConfig.interfaceLanguage },
  133. set: function (val) {
  134. this.$store.dispatch('setOption', { name: 'interfaceLanguage', value: val })
  135. }
  136. },
  137. isCustomThemeUsed () {
  138. const { theme } = this.mergedConfig
  139. return theme === 'custom' || theme === null
  140. },
  141. ...SharedComputedObject()
  142. },
  143. methods: {
  144. updateFont (key, value) {
  145. console.log(key, value)
  146. this.$store.dispatch('setOption', {
  147. name: 'theme3hacks',
  148. value: {
  149. ...this.mergedConfig.theme3hacks,
  150. fonts: {
  151. ...this.mergedConfig.theme3hacks.fonts,
  152. [key]: value
  153. }
  154. }
  155. })
  156. },
  157. isThemeActive (key) {
  158. const { theme } = this.mergedConfig
  159. return key === theme
  160. },
  161. setTheme (name) {
  162. this.$store.dispatch('setTheme', { themeName: name, saveData: true, recompile: true })
  163. },
  164. previewTheme (key, input) {
  165. const style = normalizeThemeData(input)
  166. const x = 2
  167. if (x === 1) return
  168. const theme2 = convertTheme2To3(style)
  169. const theme3 = init({
  170. inputRuleset: theme2,
  171. ultimateBackgroundColor: '#000000',
  172. liteMode: true,
  173. debug: true,
  174. onlyNormalState: true
  175. })
  176. return getScopedVersion(
  177. getCssRules(theme3.eager),
  178. '#theme-preview-' + key
  179. ).join('\n')
  180. }
  181. }
  182. }
  183. export default AppearanceTab