Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions components/mjs/a11y/complexity/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"component": "a11y/complexity",
"targets": [
"a11y/complexity.ts",
"a11y/complexity",
"a11y/semantic-enrich.ts"
"a11y/complexity"
]
},
"webpack": {
Expand Down
6 changes: 5 additions & 1 deletion components/mjs/a11y/explorer/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"build": {
"component": "a11y/explorer",
"targets": ["a11y/explorer.ts", "a11y/explorer"]
"targets": [
"a11y/explorer.ts",
"a11y/explorer",
"a11y/aria/__locales__"
]
},
"copy": [
{
Expand Down
4 changes: 3 additions & 1 deletion components/mjs/a11y/semantic-enrich/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"build": {
"component": "a11y/semantic-enrich",
"targets": [
"a11y/semantic-enrich.ts"
"a11y/semantic-enrich.ts",
"a11y/semantic-enrich",
"a11y/speech/strings.ts"
]
},
"copy": {
Expand Down
5 changes: 4 additions & 1 deletion components/mjs/a11y/speech/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"build": {
"component": "a11y/speech",
"targets": ["a11y/speech.ts", "a11y/speech"],
"exclude": ["a11y/speech/SpeechMenu.ts"]
"exclude": [
"a11y/speech/SpeechMenu.ts",
"a11y/speech/strings.ts"
]
},
"copy": {
"to": "[bundle]/a11y/speech",
Expand Down
5 changes: 4 additions & 1 deletion components/mjs/adaptors/linkedom/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"build": {
"component": "adaptors/linkedom",
"targets": ["adaptors/linkedomAdaptor.ts"]
"targets": [
"adaptors/linkedomAdaptor.ts",
"adaptors/linkedom"
]
},
"copy": {
"to": "[bundle]/adaptors/linkedom",
Expand Down
3 changes: 2 additions & 1 deletion components/mjs/input/mml/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"component": "input/mml",
"targets": [
"input/mathml.ts",
"input/mathml"
"input/mathml",
"input/mathml/__locales__"
],
"excludeSubdirs": true
},
Expand Down
3 changes: 2 additions & 1 deletion components/mjs/input/tex/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"input/tex/noundefined",
"input/tex/require",
"input/tex/autoload",
"input/tex/configmacros"
"input/tex/configmacros",
"input/tex/__locales__"
],
"excludeSubdirs": true
},
Expand Down
4 changes: 3 additions & 1 deletion components/mjs/output/chtml/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"output/chtml.ts",
"output/chtml",
"output/common.ts",
"output/common"
"output/common",
"a11y/semantic-enrich/strings.ts",
"a11y/semantic-enrich/maction.ts"
]
},
"webpack": {
Expand Down
4 changes: 3 additions & 1 deletion components/mjs/output/svg/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"output/svg.ts",
"output/svg",
"output/common.ts",
"output/common"
"output/common",
"a11y/semantic-enrich/strings.ts",
"a11y/semantic-enrich/maction.ts"
]
},
"webpack": {
Expand Down
9 changes: 8 additions & 1 deletion components/mjs/ui/menu/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"build": {
"component": "ui/menu",
"targets": ["ui/menu", "a11y/speech/SpeechMenu.ts"],
"targets": [
"ui/menu",
"a11y/speech/SpeechMenu.ts",
"a11y/semantic-enrich/strings.ts",
"a11y/speech/strings.ts",
"ui/menu/__locales__",
"a11y/aria/__locales__"
],
"excludeSubdirs": true
},
"copy": [
Expand Down
95 changes: 42 additions & 53 deletions ts/a11y/complexity/collapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import {
} from '../../core/MmlTree/MmlNode.js';
import { PropertyList } from '../../core/Tree/Node.js';
import { ComplexityVisitor } from './visitor.js';
import { PROP, DATA } from './strings.js';
import { SEM } from '../semantic-enrich/strings.js';
import { SPEECH } from '../speech/strings.js';
import { MACTION } from '../semantic-enrich/maction.js';
import type { SemanticMap } from '../speech/StructureUtil.js';

/*==========================================================================*/
Expand Down Expand Up @@ -156,7 +160,7 @@ export class Collapse {
complexity = this.uncollapseChild(complexity, node, 1);
if (
complexity > (this.cutoff.fenced as number) &&
node.attributes.get('data-semantic-role') === 'leftright'
node.attributes.get(SEM.ROLE) === 'leftright'
) {
complexity = this.recordCollapse(
node,
Expand All @@ -180,8 +184,7 @@ export class Collapse {
complexity = this.complexity.visitNode(node, false);
const marker = this.marker.appl as { [name: string]: string };
const text =
marker[node.attributes.get('data-semantic-role') as string] ||
marker.value;
marker[node.attributes.get(SEM.ROLE) as string] || marker.value;
complexity = this.recordCollapse(node, complexity, text);
}
return complexity;
Expand All @@ -197,7 +200,7 @@ export class Collapse {
(node, complexity) => {
complexity = this.uncollapseChild(complexity, node, 0);
if (complexity > (this.cutoff.sqrt as number)) {
node.setProperty('collapse-variant', true);
node.setProperty(PROP.VARIANT, true);
complexity = this.recordCollapse(
node,
complexity,
Expand All @@ -212,7 +215,7 @@ export class Collapse {
(node, complexity) => {
complexity = this.uncollapseChild(complexity, node, 0, 2);
if (complexity > (this.cutoff.sqrt as number)) {
node.setProperty('collapse-variant', true);
node.setProperty(PROP.VARIANT, true);
complexity = this.recordCollapse(
node,
complexity,
Expand All @@ -232,7 +235,7 @@ export class Collapse {
if (this.splitAttribute(node, 'children').length === 1) {
const child = this.canUncollapse(node, 1);
if (child) {
const marker = child.getProperty('collapse-marker') as string;
const marker = child.getProperty(PROP.MARKER) as string;
this.unrecordCollapse(child);
complexity = this.recordCollapse(
node,
Expand Down Expand Up @@ -369,7 +372,7 @@ export class Collapse {
* @returns {number} The revised complexity
*/
public check(node: MmlNode, complexity: number): number {
const type = node.attributes.get('data-semantic-type') as string;
const type = node.attributes.get(SEM.TYPE) as string;
if (this.collapse.has(type)) {
return this.collapse.get(type).call(this, node, complexity);
}
Expand All @@ -392,7 +395,7 @@ export class Collapse {
complexity: number,
type: string
): number {
const role = node.attributes.get('data-semantic-role') as string;
const role = node.attributes.get(SEM.ROLE) as string;
const check = this.cutoff[type];
const cutoff =
typeof check === 'number' ? check : check[role] || check.value;
Expand All @@ -417,8 +420,8 @@ export class Collapse {
text: string
): number {
text = '\u25C2' + text + '\u25B8';
node.setProperty('collapse-marker', text);
node.setProperty('collapse-complexity', complexity);
node.setProperty(PROP.MARKER, text);
node.setProperty(PROP.COMPLEXITY, complexity);
return text.length * this.complexity.complexity.text;
}

Expand All @@ -428,11 +431,11 @@ export class Collapse {
* @param {MmlNode} node The node to uncollapse
*/
protected unrecordCollapse(node: MmlNode) {
const complexity = node.getProperty('collapse-complexity');
const complexity = node.getProperty(PROP.COMPLEXITY);
if (complexity != null) {
node.attributes.set('data-semantic-complexity', complexity);
node.removeProperty('collapse-complexity');
node.removeProperty('collapse-marker');
node.attributes.set(DATA.COMPLEXITY, complexity);
node.removeProperty(PROP.COMPLEXITY);
node.removeProperty(PROP.MARKER);
}
}

Expand All @@ -454,7 +457,7 @@ export class Collapse {
: node;
if (mml && mml.childNodes[n]) {
const child = mml.childNodes[n];
if (child.getProperty('collapse-marker')) {
if (child.getProperty(PROP.MARKER)) {
return child;
}
}
Expand All @@ -479,7 +482,7 @@ export class Collapse {
if (child) {
this.unrecordCollapse(child);
if (child.parent !== node) {
child.parent.attributes.set('data-semantic-complexity', undefined);
child.parent.attributes.set(DATA.COMPLEXITY, undefined);
}
complexity = this.complexity.visitNode(node, false) as number;
}
Expand All @@ -492,9 +495,7 @@ export class Collapse {
* @returns {string[]} Array of ids in the attribute split at commas
*/
protected splitAttribute(node: MmlNode, id: string): string[] {
return ((node.attributes.get('data-semantic-' + id) as string) || '').split(
/,/
);
return ((node.attributes.get(SEM.PREFIX + id) as string) || '').split(/,/);
}

/**
Expand Down Expand Up @@ -522,7 +523,7 @@ export class Collapse {
* @returns {MmlNode|null} The child node (or null if not found)
*/
protected findChild(node: MmlNode, id: string): MmlNode | null {
if (!node || node.attributes.get('data-semantic-id') === id) return node;
if (!node || node.attributes.get(SEM.ID) === id) return node;
if (!node.isToken) {
for (const mml of node.childNodes) {
const child = this.findChild(mml, id);
Expand Down Expand Up @@ -554,7 +555,7 @@ export class Collapse {
}
const nodes: MmlNode[] = [];
node.walkTree((child: MmlNode) => {
if (child.getProperty('collapse-marker')) {
if (child.getProperty(PROP.MARKER)) {
nodes.push(child);
}
});
Expand All @@ -573,9 +574,7 @@ export class Collapse {
public makeActions(root: MmlNode, nodes: MmlNode[], parts: SemanticMap) {
for (const node of nodes) {
const extra =
parts
.get(node.attributes.get('data-semantic-id') as string)
?.slice(1) ?? [];
parts.get(node.attributes.get(SEM.ID) as string)?.slice(1) ?? [];
this.makeAction(root, node, extra);
}
}
Expand All @@ -597,22 +596,20 @@ export class Collapse {
node = this.addMrow(node);
}
const factory = this.complexity.factory;
const marker = node.getProperty('collapse-marker') as string;
const marker = node.getProperty(PROP.MARKER) as string;
const parent = node.parent;
const def = { 'data-mjx-collapsed': true } as PropertyList;
if (node.getProperty('collapse-variant')) {
const def = { [MACTION.COLLAPSED]: true } as PropertyList;
if (node.getProperty(PROP.VARIANT)) {
def.mathvariant = '-tex-variant';
}
const maction = factory.create(
'maction',
{
actiontype: 'toggle',
selection: 2,
'data-collapsible': true,
[MACTION.COLLAPSIBLE]: true,
id: this.makeId(),
'data-semantic-complexity': node.attributes.get(
'data-semantic-complexity'
),
[DATA.COMPLEXITY]: node.attributes.get(DATA.COMPLEXITY),
},
[
factory.create('mtext', def, [
Expand All @@ -621,12 +618,9 @@ export class Collapse {
]
);
maction.inheritAttributesFrom(node);
node.attributes.set(
'data-semantic-complexity',
node.getProperty('collapse-complexity')
);
node.removeProperty('collapse-marker');
node.removeProperty('collapse-complexity');
node.attributes.set(DATA.COMPLEXITY, node.getProperty(PROP.COMPLEXITY));
node.removeProperty(PROP.MARKER);
node.removeProperty(PROP.COMPLEXITY);
parent.replaceChild(maction, node);
maction.appendChild(node);
this.makeActionGroup(root, maction, extra);
Expand All @@ -639,10 +633,10 @@ export class Collapse {
*/
public makeActionGroup(root: MmlNode, action: MmlNode, extra: string[]) {
if (!extra.length) return;
action.attributes.set('data-collapse-group', true);
action.attributes.set(MACTION.GROUP, true);
const nodes: MmlNode[] = [];
root.walkTree((node) => {
if (extra.includes(node.attributes.get('data-semantic-id') as string)) {
if (extra.includes(node.attributes.get(SEM.ID) as string)) {
nodes.push(node);
}
});
Expand All @@ -654,11 +648,9 @@ export class Collapse {
{
actiontype: 'toggle',
selection: 2,
'data-collapsible': true,
'data-collapse-id': action.attributes.get('id'),
'data-semantic-complexity': node.attributes.get(
'data-semantic-complexity'
),
[MACTION.COLLAPSIBLE]: true,
[MACTION.GROUPID]: action.attributes.get('id'),
[DATA.COMPLEXITY]: node.attributes.get(DATA.COMPLEXITY),
},
[factory.create('mtext')]
);
Expand Down Expand Up @@ -686,8 +678,8 @@ export class Collapse {
const attributes = node.attributes.getAllAttributes();
for (const name of Object.keys(attributes)) {
if (
name.substring(0, 14) === 'data-semantic-' ||
name.substring(0, 12) === 'data-speech-' ||
name.substring(0, 14) === SEM.PREFIX ||
name.substring(0, 12) === SPEECH.PREFIX ||
name.substring(0, 5) === 'aria-' ||
name === 'role'
) {
Expand All @@ -696,13 +688,10 @@ export class Collapse {
}
}

mrow.setProperty('collapse-marker', node.getProperty('collapse-marker'));
mrow.setProperty(
'collapse-complexity',
node.getProperty('collapse-complexity')
);
node.removeProperty('collapse-marker');
node.removeProperty('collapse-complexity');
mrow.setProperty(PROP.MARKER, node.getProperty(PROP.MARKER));
mrow.setProperty(PROP.COMPLEXITY, node.getProperty(PROP.COMPLEXITY));
node.removeProperty(PROP.MARKER);
node.removeProperty(PROP.COMPLEXITY);
return mrow;
}
}
Loading