-
Notifications
You must be signed in to change notification settings - Fork 185
Dark color improvement #3279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dark color improvement #3279
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| import { getColor, setColor } from '../utils/color'; | ||
| import { shouldSetValue } from '../utils/shouldSetValue'; | ||
| import type { BackgroundColorFormat } from 'roosterjs-content-model-types'; | ||
| import type { BackgroundColorFormat, TextColorFormat } from 'roosterjs-content-model-types'; | ||
| import type { FormatHandler } from '../FormatHandler'; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| export const backgroundColorFormatHandler: FormatHandler<BackgroundColorFormat> = { | ||
| export const backgroundColorFormatHandler: FormatHandler< | ||
| BackgroundColorFormat & TextColorFormat | ||
| > = { | ||
|
Comment on lines
+9
to
+11
|
||
| parse: (format, element, context, defaultStyle) => { | ||
| const backgroundColor = | ||
| getColor( | ||
|
|
@@ -34,7 +36,8 @@ export const backgroundColorFormatHandler: FormatHandler<BackgroundColorFormat> | |
| format.backgroundColor, | ||
| true /*isBackground*/, | ||
| !!context.isDarkMode, | ||
| context.darkColorHandler | ||
| context.darkColorHandler, | ||
| format.textColor | ||
| ); | ||
| } | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -84,12 +84,12 @@ export function getLightModeColor( | |||||
| ) { | ||||||
| if (DeprecatedColors.indexOf(color) > -1) { | ||||||
| return fallback; | ||||||
| } else if (darkColorHandler) { | ||||||
| } else { | ||||||
| const match = color.startsWith(VARIABLE_PREFIX) ? VARIABLE_REGEX.exec(color) : null; | ||||||
|
|
||||||
| if (match) { | ||||||
| color = match[2] || ''; | ||||||
| } else if (isDarkMode) { | ||||||
| } else if (isDarkMode && darkColorHandler) { | ||||||
| // If editor is in dark mode but the color is not in dark color format, it is possible the color was inserted from external code | ||||||
| // without any light color info. So we first try to see if there is a known dark color can match this color, and use its related | ||||||
| // light color as light mode color. Otherwise we need to drop this color to avoid show "white on white" content. | ||||||
|
|
@@ -126,20 +126,23 @@ export function retrieveElementColor( | |||||
| * @param isBackground True to set background color, false to set text color | ||||||
| * @param isDarkMode Whether element is in dark mode now | ||||||
| * @param darkColorHandler @optional The dark color handler object to help manager dark mode color | ||||||
| * @param comparingColor @optional When generating dark color for background color, we can provide text color as comparingColor to make sure the generated dark border color has enough contrast with text color in dark mode | ||||||
|
||||||
| * @param comparingColor @optional When generating dark color for background color, we can provide text color as comparingColor to make sure the generated dark border color has enough contrast with text color in dark mode | |
| * @param comparingColor @optional When generating dark color for a background, we can provide the text color as comparingColor to make sure the generated dark background color has enough contrast with the text color in dark mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transformColornow has a newdefaultTextColorparameter (used to propagate inherited text color for background contrast), but the exported function's documentation block above doesn't describe it. Please update the JSDoc to include this parameter and its effect on background color transformation.