Skip to content

Commit fecee0a

Browse files
authored
Merge pull request #1357 from mathjax/feature/draggable-dialogs
Make dialogs movable and sizable.
2 parents a634d43 + 946a580 commit fecee0a

File tree

23 files changed

+2095
-649
lines changed

23 files changed

+2095
-649
lines changed

components/mjs/core/config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"targets": [
55
"mathjax.ts",
66
"core", "util", "handlers",
7+
"ui/dialog/DraggableDialog.ts",
8+
"ui/dialog/InfoDialog.ts",
79
"adaptors/HTMLAdaptor.ts",
810
"adaptors/browserAdaptor.ts",
911
"components/global.ts"

testsuite/tests/util/StyleJson.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,20 @@ describe('StyleJsonSheet object', () => {
3636
expect(styles.cssText).toBe('');
3737
});
3838

39+
test('Compound style', () => {
40+
expect(new StyleJsonSheet({
41+
'@media (prefers-color-scheme: dark)': {
42+
'mjx-container': {
43+
'color': '#E0E0E0',
44+
},
45+
}
46+
}).cssText).toBe([
47+
'@media (prefers-color-scheme: dark) {',
48+
' mjx-container {',
49+
' color: #E0E0E0;',
50+
' }',
51+
'}'
52+
].join('\n'));
53+
});
54+
3955
});

ts/a11y/complexity/collapse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ export class Collapse {
599599
),
600600
},
601601
[
602-
factory.create('mtext', { mathcolor: 'blue', ...variant }, [
602+
factory.create('mtext', variant, [
603603
(factory.create('text') as TextNode).setText(marker),
604604
]),
605605
]

ts/a11y/explorer.ts

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export function ExplorerMathDocumentMixin<
321321
public static OPTIONS: OptionList = {
322322
...BaseDocument.OPTIONS,
323323
enableExplorer: hasWindow, // only activate in interactive contexts
324+
enableExplorerHelp: true, // help dialog is enabled
324325
renderActions: expandable({
325326
...BaseDocument.OPTIONS.renderActions,
326327
explorable: [STATE.EXPLORER]
@@ -426,77 +427,20 @@ export function ExplorerMathDocumentMixin<
426427
display: 'inline-flex',
427428
'align-items': 'center',
428429
},
429-
430-
'mjx-help-sizer': {
431-
position: 'fixed',
432-
width: '40%',
433-
'max-width': '30em',
434-
top: '3em',
435-
left: '50%',
436-
},
437-
'mjx-help-dialog': {
438-
position: 'absolute',
439-
width: '200%',
440-
left: '-100%',
441-
border: '3px outset',
442-
'border-radius': '15px',
443-
color: 'black',
444-
'background-color': '#DDDDDD',
445-
'z-index': '301',
446-
'text-align': 'right',
447-
'font-style': 'normal',
448-
'text-indent': 0,
449-
'text-transform': 'none',
450-
'line-height': 'normal',
451-
'letter-spacing': 'normal',
452-
'word-spacing': 'normal',
453-
'word-wrap': 'normal',
454-
float: 'none',
455-
'box-shadow': '0px 10px 20px #808080',
456-
outline: 'none',
457-
},
458-
'mjx-help-dialog > h1': {
459-
'font-size': '24px',
460-
'text-align': 'center',
461-
margin: '.5em 0',
462-
},
463-
'mjx-help-dialog > div': {
464-
margin: '0 1em',
465-
padding: '3px',
466-
overflow: 'auto',
467-
height: '20em',
468-
border: '2px inset black',
469-
'background-color': 'white',
470-
'text-align': 'left',
471-
},
472-
'mjx-help-dialog > input': {
473-
margin: '.5em 2em',
474-
},
475-
'mjx-help-dialog kbd': {
476-
display: 'inline-block',
477-
padding: '3px 5px',
478-
'font-size': '11px',
479-
'line-height': '10px',
480-
color: '#444d56',
481-
'vertical-align': 'middle',
482-
'background-color': '#fafbfc',
483-
border: 'solid 1.5px #c6cbd1',
484-
'border-bottom-color': '#959da5',
485-
'border-radius': '3px',
486-
'box-shadow': 'inset -.5px -1px 0 #959da5',
487-
},
488-
'mjx-help-dialog ul': {
489-
'list-style-type': 'none',
490-
},
491-
'mjx-help-dialog li': {
492-
'margin-bottom': '.5em',
493-
},
494-
'mjx-help-background': {
495-
position: 'fixed',
496-
top: 0,
497-
left: 0,
498-
right: 0,
499-
bottom: 0,
430+
'@media (prefers-color-scheme: dark) /* explorer */': {
431+
'mjx-help > svg': {
432+
stroke: '#E0E0E0',
433+
},
434+
'mjx-help > svg > circle': {
435+
fill: '#404040',
436+
},
437+
'mjx-help > svg > circle:nth-child(2)': {
438+
fill: 'rgba(132, 132, 255, .3)',
439+
},
440+
'mjx-help:hover > svg > circle:nth-child(2)': {
441+
stroke: '#AAAAAA',
442+
fill: '#404040',
443+
},
500444
},
501445
};
502446

@@ -565,7 +509,7 @@ export function ExplorerMathDocumentMixin<
565509
SVGNS
566510
),
567511
]);
568-
this.tmpFocus = this.adaptor.node('mjx-focus', {
512+
this.tmpFocus = adaptor.node('mjx-focus', {
569513
tabIndex: 0,
570514
style: {
571515
outline: 'none',

ts/a11y/explorer/Highlighter.ts

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,9 @@
2121
interface NamedColor {
2222
color: string;
2323
alpha?: number;
24+
type?: string;
2425
}
2526

26-
interface ChannelColor {
27-
red: number;
28-
green: number;
29-
blue: number;
30-
alpha?: number;
31-
}
32-
33-
const namedColors: { [key: string]: ChannelColor } = {
34-
red: { red: 255, green: 0, blue: 0 },
35-
green: { red: 0, green: 255, blue: 0 },
36-
blue: { red: 0, green: 0, blue: 255 },
37-
yellow: { red: 255, green: 255, blue: 0 },
38-
cyan: { red: 0, green: 255, blue: 255 },
39-
magenta: { red: 255, green: 0, blue: 255 },
40-
white: { red: 255, green: 255, blue: 255 },
41-
black: { red: 0, green: 0, blue: 0 },
42-
};
43-
4427
/**
4528
* Turns a named color into a channel color.
4629
*
@@ -49,30 +32,22 @@ const namedColors: { [key: string]: ChannelColor } = {
4932
* @returns {string} The channel color.
5033
*/
5134
function getColorString(color: NamedColor, deflt: NamedColor): string {
52-
const channel = namedColors[color.color] || namedColors[deflt.color];
53-
channel.alpha = color.alpha ?? deflt.alpha;
54-
return rgba(channel);
55-
}
56-
57-
/**
58-
* RGBa string version of the channel color.
59-
*
60-
* @param {ChannelColor} color The channel color.
61-
* @returns {string} The color in RGBa format.
62-
*/
63-
function rgba(color: ChannelColor): string {
64-
return `rgba(${color.red},${color.green},${color.blue},${color.alpha ?? 1})`;
35+
const type = deflt.type;
36+
const name = color.color ?? deflt.color;
37+
const opacity = color.alpha ?? deflt.alpha;
38+
const alpha = opacity === 1 ? 1 : `var(--mjx-${type}-alpha)`;
39+
return `rgba(var(--mjx-${type}-${name}), ${alpha})`;
6540
}
6641

6742
/**
6843
* The default background color if a none existing color is provided.
6944
*/
70-
const DEFAULT_BACKGROUND: NamedColor = { color: 'blue', alpha: 1 };
45+
const DEFAULT_BACKGROUND: NamedColor = { color: 'blue', alpha: 1, type: 'bg' };
7146

7247
/**
7348
* The default color if a none existing color is provided.
7449
*/
75-
const DEFAULT_FOREGROUND: NamedColor = { color: 'black', alpha: 1 };
50+
const DEFAULT_FOREGROUND: NamedColor = { color: 'black', alpha: 1, type: 'fg' };
7651

7752
export interface Highlighter {
7853
/**

0 commit comments

Comments
 (0)