From 21782d1259e0e01ebd792c26e556e865084505e0 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 19 Feb 2026 06:14:27 +0100 Subject: [PATCH] Remove `colorToHex` utility, inline colord call in codeeditor Co-Authored-By: Claude Opus 4.6 --- web_src/js/features/codeeditor.ts | 4 ++-- web_src/js/utils/color.test.ts | 13 +------------ web_src/js/utils/color.ts | 5 ----- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/web_src/js/features/codeeditor.ts b/web_src/js/features/codeeditor.ts index c020a10951..b2aa9ea1c5 100644 --- a/web_src/js/features/codeeditor.ts +++ b/web_src/js/features/codeeditor.ts @@ -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', diff --git a/web_src/js/utils/color.test.ts b/web_src/js/utils/color.test.ts index a5adf61287..9e4fbcca64 100644 --- a/web_src/js/utils/color.test.ts +++ b/web_src/js/utils/color.test.ts @@ -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'); diff --git a/web_src/js/utils/color.ts b/web_src/js/utils/color.ts index e189096146..fcc7d80808 100644 --- a/web_src/js/utils/color.ts +++ b/web_src/js/utils/color.ts @@ -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'; }