-
Notifications
You must be signed in to change notification settings - Fork 232
Add color handling for dark mode #1369
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
Open
dpvc
wants to merge
4
commits into
feature/draggable-dialogs
Choose a base branch
from
feature/dark-mode
base: feature/draggable-dialogs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -73,13 +73,6 @@ export abstract class AbstractRegion<T> implements Region<T> { | |||||
| */ | ||||||
| protected static className: string; | ||||||
|
|
||||||
| /** | ||||||
| * True if the style has already been added to the document. | ||||||
| * | ||||||
| * @type {boolean} | ||||||
| */ | ||||||
| protected static styleAdded: boolean = false; | ||||||
|
|
||||||
| /** | ||||||
| * The CSS style that needs to be added for this type of region. | ||||||
| * | ||||||
|
|
@@ -117,20 +110,27 @@ export abstract class AbstractRegion<T> implements Region<T> { | |||||
| this.AddStyles(); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @returns {string} The stylesheet ID | ||||||
| */ | ||||||
| public static get sheetId(): string { | ||||||
| return 'MJX-' + this.name + '-styles'; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @override | ||||||
| */ | ||||||
| public AddStyles() { | ||||||
| if (this.CLASS.styleAdded) { | ||||||
| const id = this.CLASS.sheetId; | ||||||
| if ( | ||||||
| !this.CLASS.style || | ||||||
| this.document.adaptor.head().querySelector('#' + id) | ||||||
| ) { | ||||||
| return; | ||||||
| } | ||||||
| // TODO: should that be added to document.documentStyleSheet()? | ||||||
| const node = this.document.adaptor.node('style'); | ||||||
| const node = this.document.adaptor.node('style', { id }); | ||||||
| node.innerHTML = this.CLASS.style.cssText; | ||||||
| this.document.adaptor | ||||||
| .head(this.document.adaptor.document) | ||||||
| .appendChild(node); | ||||||
| this.CLASS.styleAdded = true; | ||||||
| this.document.adaptor.head().appendChild(node); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -177,7 +177,7 @@ export abstract class AbstractRegion<T> implements Region<T> { | |||||
| */ | ||||||
| public Hide() { | ||||||
| if (!this.div) return; | ||||||
| this.div.parentNode.removeChild(this.div); | ||||||
| this.div.remove(); | ||||||
| this.div = null; | ||||||
| this.inner = null; | ||||||
| } | ||||||
|
|
@@ -335,6 +335,13 @@ export class ToolTip extends StringRegion { | |||||
| 'border-radius': 'inherit', | ||||||
| padding: '0 2px', | ||||||
| }, | ||||||
| '@media (prefers-color-scheme: dark)': { | ||||||
| ['.' + ToolTip.className]: { | ||||||
| 'background-color': '#222025', | ||||||
| 'box-shadow': '0px 5px 20px #000', | ||||||
| border: '1px solid #7C7C7C', | ||||||
| }, | ||||||
| }, | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -348,6 +355,43 @@ export class LiveRegion extends StringRegion { | |||||
| * @override | ||||||
| */ | ||||||
| protected static style: StyleJsonSheet = new StyleJsonSheet({ | ||||||
| ':root': { | ||||||
| '--mjx-fg-red': '255, 0, 0', | ||||||
| '--mjx-fg-green': '0, 255, 0', | ||||||
| '--mjx-fg-blue': '0, 0, 255', | ||||||
| '--mjx-fg-yellow': '255, 255, 0', | ||||||
| '--mjx-fg-cyan': '0, 255, 255', | ||||||
| '--mjx-fg-magenta': '255, 0, 255', | ||||||
| '--mjx-fg-white': '255, 255, 255', | ||||||
| '--mjx-fg-black': '0, 0, 0', | ||||||
| '--mjx-bg-red': '255, 0, 0', | ||||||
| '--mjx-bg-green': '0, 255, 0', | ||||||
| '--mjx-bg-blue': '0, 0, 255', | ||||||
| '--mjx-bg-yellow': '255, 255, 0', | ||||||
| '--mjx-bg-cyan': '0, 255, 255', | ||||||
| '--mjx-bg-magenta': '255, 0, 255', | ||||||
| '--mjx-bg-white': '255, 255, 255', | ||||||
| '--mjx-bg-black': '0, 0, 0', | ||||||
| '--mjx-live-bg-color': 'white', | ||||||
| '--mjx-live-shadow-color': '#888', | ||||||
| '--mjx-live-border-color': '#CCCCCC', | ||||||
| '--mjx-bg-alpha': 0.2, | ||||||
| '--mjx-fg-alpha': 1, | ||||||
| }, | ||||||
| '@media (prefers-color-scheme: dark)': { | ||||||
| ':root': { | ||||||
| '--mjx-bg-blue': '132, 132, 255', | ||||||
| '--mjx-bg-white': '0, 0, 0', | ||||||
| '--mjx-bg-black': '255, 255, 255', | ||||||
| '--mjx-fg-white': '0, 0, 0', | ||||||
| '--mjx-fg-black': '255, 255, 255', | ||||||
| '--mjx-live-bg-color': '#222025', | ||||||
| '--mjx-live-shadow-color': 'black', | ||||||
| '--mjx-live-border-color': '#7C7C7C', | ||||||
| '--mjx-bg-alpha': 0.3, | ||||||
| '--mjx-fg-alpha': 1, | ||||||
| }, | ||||||
| }, | ||||||
| ['.' + LiveRegion.className]: { | ||||||
| position: 'absolute', | ||||||
| top: 0, | ||||||
|
|
@@ -360,20 +404,41 @@ export class LiveRegion extends StringRegion { | |||||
| left: 0, | ||||||
| right: 0, | ||||||
| margin: '0 auto', | ||||||
| 'background-color': 'white', | ||||||
| 'box-shadow': '0px 5px 20px #888', | ||||||
| border: '2px solid #CCCCCC', | ||||||
| 'background-color': 'var(--mjx-live-bg-color)', | ||||||
| 'box-shadow': '0px 5px 20px var(--mjx-live-shadow-color)', | ||||||
| border: '2px solid var(--mjx-live-border-color)', | ||||||
| }, | ||||||
| ['.' + LiveRegion.className + '_Show']: { | ||||||
| display: 'block', | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
| /** | ||||||
| * @param {string} type The type of alpha to set (fg or bg) | ||||||
| * @param {number} alpha The alpha value to use for the background | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * @param {Document} document The document whose CSS styles are to be adjusted | ||||||
| */ | ||||||
| public static setAlpha(type: string, alpha: number, document: Document) { | ||||||
| const style = document.head.querySelector( | ||||||
| '#' + this.sheetId | ||||||
| ) as HTMLStyleElement; | ||||||
| if (style) { | ||||||
| const name = `--mjx-${type}-alpha`; | ||||||
| (style.sheet.cssRules[0] as any).style.setProperty(name, alpha); | ||||||
| (style.sheet.cssRules[1] as any).cssRules[0].style.setProperty( | ||||||
| name, | ||||||
| alpha ** 0.7071 | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Region class that enables auto voicing of content via SSML markup. | ||||||
| */ | ||||||
| export class SpeechRegion extends LiveRegion { | ||||||
| protected static style: StyleJsonSheet = null; | ||||||
|
|
||||||
| /** | ||||||
| * Flag to activate auto voicing. | ||||||
| */ | ||||||
|
|
@@ -583,6 +648,13 @@ export class HoverRegion extends AbstractRegion<HTMLElement> { | |||||
| ['.' + HoverRegion.className + ' > div']: { | ||||||
| overflow: 'hidden', | ||||||
| }, | ||||||
| '@media (prefers-color-scheme: dark)': { | ||||||
| ['.' + HoverRegion.className]: { | ||||||
| 'background-color': '#222025', | ||||||
| 'box-shadow': '0px 5px 20px #000', | ||||||
| border: '1px solid #7C7C7C', | ||||||
| }, | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The issue here is that the we fix the background color of the circle i. I.e., when changing the highlighting color to something else, it stays blue. This is not an issue related to the darkmode but it has just never occurred to me.
We could solve this by making the
infoIconpart of theRegionPoolso it would have access to the highlighter for updating.