2021-08-04 23:31:54 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2022-09-21 08:08:25 +00:00
|
|
|
import platform, { loadPluginStrings, setMetadata } from '@hcengineering/platform'
|
2023-05-24 16:53:06 +00:00
|
|
|
import { onMount, setContext } from 'svelte'
|
|
|
|
import { ThemeOptions, getCurrentFontSize, getCurrentLanguage, getCurrentTheme, themeStore as themeOptions } from './'
|
2021-08-04 23:31:54 +00:00
|
|
|
|
|
|
|
const currentTheme = getCurrentTheme()
|
2023-05-24 16:53:06 +00:00
|
|
|
const currentFontSize = getCurrentFontSize()
|
|
|
|
let currentLanguage = getCurrentLanguage()
|
2021-08-04 23:31:54 +00:00
|
|
|
|
2023-06-22 04:55:57 +00:00
|
|
|
const setOptions = (currentFont: string, theme: string, language: string) => {
|
|
|
|
themeOptions.set(new ThemeOptions(currentFont === 'normal-font' ? 16 : 14, theme === 'theme-dark', language))
|
|
|
|
}
|
|
|
|
|
|
|
|
const setRootColors = (theme: string, set = true) => {
|
|
|
|
if (set) {
|
|
|
|
localStorage.setItem('theme', theme)
|
|
|
|
}
|
2023-05-24 16:53:06 +00:00
|
|
|
document.documentElement.setAttribute('class', `${theme} ${getCurrentFontSize()}`)
|
2023-06-22 04:55:57 +00:00
|
|
|
setOptions(getCurrentFontSize(), theme, getCurrentLanguage())
|
2021-08-04 23:31:54 +00:00
|
|
|
}
|
2023-06-22 04:55:57 +00:00
|
|
|
const setRootFontSize = (fontsize: string, set = true) => {
|
|
|
|
if (set) {
|
|
|
|
localStorage.setItem('fontsize', fontsize)
|
|
|
|
}
|
2021-08-14 11:42:31 +00:00
|
|
|
document.documentElement.setAttribute('class', `${getCurrentTheme()} ${fontsize}`)
|
2023-06-22 04:55:57 +00:00
|
|
|
setOptions(fontsize, getCurrentTheme(), getCurrentLanguage())
|
|
|
|
}
|
|
|
|
const setLanguage = async (language: string, set: boolean = true) => {
|
|
|
|
currentLanguage = language
|
|
|
|
if (set) {
|
|
|
|
localStorage.setItem('lang', language)
|
|
|
|
}
|
|
|
|
setMetadata(platform.metadata.locale, currentLanguage)
|
|
|
|
await loadPluginStrings(currentLanguage, set)
|
|
|
|
setOptions(getCurrentFontSize(), getCurrentTheme(), language)
|
2021-08-04 23:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setContext('theme', {
|
2022-11-02 08:50:14 +00:00
|
|
|
currentTheme,
|
2023-06-22 04:55:57 +00:00
|
|
|
setTheme: setRootColors
|
2021-08-04 23:31:54 +00:00
|
|
|
})
|
|
|
|
setContext('fontsize', {
|
2022-11-02 08:50:14 +00:00
|
|
|
currentFontSize,
|
2023-06-22 04:55:57 +00:00
|
|
|
setFontSize: setRootFontSize
|
2021-08-04 23:31:54 +00:00
|
|
|
})
|
2022-01-06 11:09:19 +00:00
|
|
|
setContext('lang', {
|
2022-11-02 08:50:14 +00:00
|
|
|
currentLanguage,
|
2023-06-22 04:55:57 +00:00
|
|
|
setLanguage
|
2022-01-06 11:09:19 +00:00
|
|
|
})
|
2021-08-04 23:31:54 +00:00
|
|
|
|
2022-05-20 19:40:24 +00:00
|
|
|
const setDocumentLanguage = (): void => {
|
|
|
|
document.documentElement.lang = currentLanguage
|
|
|
|
}
|
|
|
|
|
2021-08-04 23:31:54 +00:00
|
|
|
onMount(() => {
|
2023-06-22 04:55:57 +00:00
|
|
|
setRootColors(currentTheme, false)
|
|
|
|
setRootFontSize(currentFontSize, false)
|
|
|
|
setLanguage(currentLanguage, false)
|
2022-02-28 03:42:34 +00:00
|
|
|
loadPluginStrings(currentLanguage)
|
2022-05-20 19:40:24 +00:00
|
|
|
setDocumentLanguage()
|
2021-08-04 23:31:54 +00:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
<slot />
|