0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-03-06 23:02:06 +01:00

Remove colorToHex utility, inline colord call in codeeditor

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
silverwind 2026-02-19 06:14:27 +01:00
parent 6a127075fe
commit 21782d1259
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
3 changed files with 3 additions and 19 deletions

View File

@ -1,5 +1,5 @@
import {colord} from 'colord';
import {basename, extname, isObject, isDarkTheme} from '../utils.ts';
import {colorToHex} from '../utils/color.ts';
import {onInputDebounce} from '../utils/dom.ts';
import type MonacoNamespace from 'monaco-editor';
@ -94,7 +94,7 @@ function updateTheme(monaco: Monaco): void {
// https://github.com/microsoft/monaco-editor/issues/2427
// also, monaco can only parse 6-digit hex colors, so we convert the colors to that format
const styles = window.getComputedStyle(document.documentElement);
const getColor = (name: string) => colorToHex(styles.getPropertyValue(name).trim());
const getColor = (name: string) => colord(styles.getPropertyValue(name).trim()).alpha(1).toHex();
monaco.editor.defineTheme('gitea', {
base: isDarkTheme() ? 'vs-dark' : 'vs',

View File

@ -1,15 +1,4 @@
import {colorToHex, contrastColor} from './color.ts';
test('colorToHex', () => {
expect(colorToHex('#d73a4a')).toBe('#d73a4a');
expect(colorToHex('#ff0000')).toBe('#ff0000');
expect(colorToHex('#ffffff')).toBe('#ffffff');
expect(colorToHex('#000000')).toBe('#000000');
expect(colorToHex('rgb(255, 0, 0)')).toBe('#ff0000');
expect(colorToHex('rgba(255, 0, 0, 0.5)')).toBe('#ff0000');
expect(colorToHex('rgba(0, 0, 0, 0)')).toBe('#000000');
expect(colorToHex('#ff000080')).toBe('#ff0000');
});
import {contrastColor} from './color.ts';
test('contrastColor', () => {
expect(contrastColor('#d73a4a')).toBe('#fff');

View File

@ -16,11 +16,6 @@ function useLightText(backgroundColor: AnyColor): boolean {
* contrast ratio. */
// In the future, the APCA contrast function, or CSS `contrast-color` will be better.
// https://github.com/color-js/color.js/blob/eb7b53f7a13bb716ec8b28c7a56f052cd599acd9/src/contrast/APCA.js#L42
/** Converts any color to a 6-digit hex color */
export function colorToHex(color: AnyColor): string {
return colord(color).alpha(1).toHex();
}
export function contrastColor(backgroundColor: AnyColor): string {
return useLightText(backgroundColor) ? '#fff' : '#000';
}