Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-02-19 18:58:56 +06:00 committed by GitHub
parent af315fd25a
commit b49762fe03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 6 deletions

View File

@ -311,7 +311,8 @@ function hashCode (str: string): number {
* @public
*/
export function getColorNumberByText (str: string): number {
return hashCode(str)
const hash = hashCode(str)
return Math.abs(hash) % Math.min(darkPalette.length, whitePalette.length)
}
/**

View File

@ -16,6 +16,7 @@
import { tooltip } from '../tooltips'
import { AnySvelteComponent, emojiSP } from '../types'
import plugin from '../plugin'
import { fromCodePoint } from '../utils'
export let embedded = false
export let selected: string | undefined
@ -108,7 +109,7 @@
function getEmojis (startCode: number, endCode: number, postfix?: number[]): Array<string | undefined> {
return [...Array(endCode - startCode + 1).keys()].map((v) => {
const str = postfix ? String.fromCodePoint(v + startCode, ...postfix) : String.fromCodePoint(v + startCode)
const str = postfix ? fromCodePoint(v + startCode, ...postfix) : fromCodePoint(v + startCode)
if ([...str.matchAll(regex)].length > 0) return str
return undefined
})

View File

@ -14,13 +14,14 @@
-->
<script lang="ts">
import { IconSize } from '../types'
import { fromCodePoint } from '../utils'
export let icon: number
export let size: IconSize
let value: string = ''
$: try {
value = String.fromCodePoint(icon)
value = fromCodePoint(icon)
} catch (err) {}
</script>

View File

@ -245,6 +245,10 @@ export function formatKey (key: string): string[][] {
return result
}
export function fromCodePoint (...vals: number[]): string {
return String.fromCodePoint(...vals.map((p) => Math.abs(p) % 0x10ffff))
}
/**
* @public
*/

View File

@ -31,6 +31,7 @@
ModernEditbox,
TextArea,
closePopup,
fromCodePoint,
getPlatformColorDef,
showPopup,
themeStore
@ -421,7 +422,7 @@
{:else}
<EmojiPopup
embedded
selected={String.fromCodePoint(color ?? 0)}
selected={fromCodePoint(color ?? 0)}
on:close={(evt) => {
color = evt.detail.codePointAt(0)
icon = iconWithEmoji

View File

@ -14,7 +14,15 @@
-->
<script lang="ts">
import { Asset, Metadata } from '@hcengineering/platform'
import { Button, EmojiPopup, TabsControl, getPlatformColor, getPlatformColorDef, themeStore } from '@hcengineering/ui'
import {
Button,
EmojiPopup,
TabsControl,
fromCodePoint,
getPlatformColor,
getPlatformColorDef,
themeStore
} from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte'
import view from '../plugin'
import ColorsPopup from './ColorsPopup.svelte'
@ -75,7 +83,7 @@
{:else}
<EmojiPopup
embedded
selected={String.fromCodePoint(color ?? 0)}
selected={fromCodePoint(color ?? 0)}
on:close={(evt) => {
dispatch('close', { icon: iconWithEmoji, color: evt.detail.codePointAt(0) })
}}