Files
huly-platform/packages/theme/src/index.ts
Anton AlexeyevandGitHub ab0ee7388d Emoji improvements (#9730)
* Add Noto Color emojis

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>

* Fix custom emojis in the new chat

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>

* Rollback unnecessary changes

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>

* Fix return type

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>

* Load emoji function in the top level component

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>

* Fix detection of messages with emojis only

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>

* Fix formatting

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>

* Move parseEmojisFunction to the plugin

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>

---------

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>
2025-09-09 12:34:38 +07:00

95 lines
2.8 KiB
TypeScript

//
// Copyright © 2020 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.
//
import { Analytics } from '@hcengineering/analytics'
import '@hcengineering/platform-rig/profiles/ui/svelte'
import { derived, writable } from 'svelte/store'
import { ThemeVariant, type ThemeVariantType } from './variants'
export { default as Theme } from './Theme.svelte'
export { default as InvertedTheme } from './InvertedTheme.svelte'
export { ThemeVariant, type ThemeVariantType } from './variants'
/**
* @public
*/
export const setDefaultLanguage = (language: string): void => {
if (localStorage.getItem('lang') === null) {
localStorage.setItem('lang', language)
}
}
function getDefaultProps (prop: string, value: string): string {
localStorage.setItem(prop, value)
return value
}
/**
* @public
*/
export const isSystemThemeDark = (): boolean => window.matchMedia('(prefers-color-scheme: dark)').matches
/**
* @public
*/
export const isThemeDark = (theme: string): boolean =>
theme === 'theme-dark' || (theme === 'theme-system' && isSystemThemeDark())
/**
* @public
*/
export const getCurrentTheme = (): string => localStorage.getItem('theme') ?? getDefaultProps('theme', 'theme-system')
/**
* @public
*/
export const getCurrentFontSize = (): string =>
localStorage.getItem('fontsize') ?? getDefaultProps('fontsize', 'normal-font')
/**
* @public
*/
export const getCurrentLanguage = (): string => {
const lang = localStorage.getItem('lang') ?? getDefaultProps('lang', 'en')
Analytics.setTag('language', lang)
return lang
}
/**
* @public
*/
export const getCurrentEmoji = (): string => localStorage.getItem('emoji') ?? getDefaultProps('emoji', 'emoji-system')
export class ThemeOptions {
readonly variant: ThemeVariantType
constructor (
readonly fontSize: number,
readonly dark: boolean,
readonly language: string,
readonly emoji: string
) {
this.variant = dark ? ThemeVariant.Dark : ThemeVariant.Light
}
}
export const themeStore = writable<ThemeOptions>()
export function initThemeStore (): void {
themeStore.set(
new ThemeOptions(
getCurrentFontSize() === 'normal-font' ? 16 : 14,
isThemeDark(getCurrentTheme()),
getCurrentLanguage(),
getCurrentEmoji()
)
)
}
export const languageStore = derived(themeStore, ($theme) => $theme?.language ?? '')