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
|
|
|
|
|
|
|
const setRootColors = (theme: string) => {
|
2023-05-24 16:53:06 +00:00
|
|
|
document.documentElement.setAttribute('class', `${theme} ${getCurrentFontSize()}`)
|
|
|
|
themeOptions.set(
|
|
|
|
new ThemeOptions(getCurrentFontSize() === 'normal-font' ? 16 : 14, getCurrentTheme() === 'theme-dark')
|
|
|
|
)
|
2021-08-04 23:31:54 +00:00
|
|
|
}
|
|
|
|
const setRootFontSize = (fontsize: string) => {
|
2021-08-14 11:42:31 +00:00
|
|
|
document.documentElement.setAttribute('class', `${getCurrentTheme()} ${fontsize}`)
|
2023-05-24 16:53:06 +00:00
|
|
|
themeOptions.set(new ThemeOptions(fontsize === 'normal-font' ? 16 : 14, getCurrentTheme() === 'theme-dark'))
|
2021-08-04 23:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setContext('theme', {
|
2022-11-02 08:50:14 +00:00
|
|
|
currentTheme,
|
2021-08-04 23:31:54 +00:00
|
|
|
setTheme: (name: string) => {
|
|
|
|
localStorage.setItem('theme', name)
|
2023-05-24 16:53:06 +00:00
|
|
|
setRootColors(name)
|
2021-08-04 23:31:54 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
setContext('fontsize', {
|
2022-11-02 08:50:14 +00:00
|
|
|
currentFontSize,
|
2021-08-04 23:31:54 +00:00
|
|
|
setFontSize: (fontsize: string) => {
|
|
|
|
localStorage.setItem('fontsize', fontsize)
|
2023-05-24 16:53:06 +00:00
|
|
|
setRootFontSize(fontsize)
|
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,
|
2022-01-06 11:09:19 +00:00
|
|
|
setLanguage: (lang: string) => {
|
2022-02-23 16:10:11 +00:00
|
|
|
currentLanguage = lang
|
2022-01-06 11:09:19 +00:00
|
|
|
localStorage.setItem('lang', lang)
|
2022-02-23 16:10:11 +00:00
|
|
|
location.reload()
|
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(() => {
|
|
|
|
setRootColors(currentTheme)
|
|
|
|
setRootFontSize(currentFontSize)
|
2022-02-23 16:10:11 +00:00
|
|
|
setMetadata(platform.metadata.locale, currentLanguage)
|
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 />
|