From e65380aaf59fb6f172cf17dbb75b7061988a7277 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Wed, 26 Feb 2025 00:45:33 +0100 Subject: [PATCH] ui: use less saturated and modern colors when drawing highlights (#453) --- .../src/app/reader/components/annotator/Annotator.tsx | 6 ++++-- apps/readest-app/src/services/constants.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/readest-app/src/app/reader/components/annotator/Annotator.tsx b/apps/readest-app/src/app/reader/components/annotator/Annotator.tsx index 605362ab..ec285ac0 100644 --- a/apps/readest-app/src/app/reader/components/annotator/Annotator.tsx +++ b/apps/readest-app/src/app/reader/components/annotator/Annotator.tsx @@ -24,6 +24,7 @@ import { useFoliateEvents } from '../../hooks/useFoliateEvents'; import { useNotesSync } from '../../hooks/useNotesSync'; import { getPopupPosition, getPosition, Position, TextSelection } from '@/utils/sel'; import { eventDispatcher } from '@/utils/event'; +import { HIGHLIGHT_COLOR_HEX } from '@/services/constants'; import AnnotationPopup from './AnnotationPopup'; import WiktionaryPopup from './WiktionaryPopup'; import WikipediaPopup from './WikipediaPopup'; @@ -176,14 +177,15 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => { const detail = (event as CustomEvent).detail; const { draw, annotation, doc, range } = detail; const { style, color } = annotation as BookNote; + const hexColor = color ? HIGHLIGHT_COLOR_HEX[color] : color; if (style === 'highlight') { - draw(Overlayer.highlight, { color }); + draw(Overlayer.highlight, { color: hexColor }); } else if (['underline', 'squiggly'].includes(style as string)) { const { defaultView } = doc; const node = range.startContainer; const el = node.nodeType === 1 ? node : node.parentElement; const { writingMode } = defaultView.getComputedStyle(el); - draw(Overlayer[style as keyof typeof Overlayer], { writingMode, color }); + draw(Overlayer[style as keyof typeof Overlayer], { writingMode, color: hexColor }); } }; diff --git a/apps/readest-app/src/services/constants.ts b/apps/readest-app/src/services/constants.ts index a4a65849..71ccef3b 100644 --- a/apps/readest-app/src/services/constants.ts +++ b/apps/readest-app/src/services/constants.ts @@ -3,6 +3,7 @@ import { BookLayout, BookSearchConfig, BookStyle, + HighlightColor, TTSConfig, ViewConfig, ViewSettings, @@ -406,3 +407,11 @@ export const DEFAULT_STORAGE_QUOTA: UserStorageQuota = { export const DOUBLE_CLICK_INTERVAL_THRESHOLD_MS = 250; export const DISABLE_DOUBLE_CLICK_ON_MOBILE = true; export const LONG_HOLD_THRESHOLD = 500; + +export const HIGHLIGHT_COLOR_HEX: Record = { + red: '#f87171', // red-400 + yellow: '#facc15', // yellow-400 + green: '#4ade80', // green-400 + blue: '#60a5fa', // blue-400 + violet: '#a78bfa', // violet-400 +};