Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed May 19, 2022
2 parents b746572 + 3e6df37 commit 9f588aa
Show file tree
Hide file tree
Showing 507 changed files with 5,098 additions and 3,778 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- stable
- 17
sudo: false
script:
- npm install
Expand Down
55 changes: 37 additions & 18 deletions components/bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const path = require('path');
/**
* The amount of space for each level of indentation
*/
const INDENT = ' ';
const INDENT = ' ';

/**
* The pattern to use when looking for explort commands to process
Expand All @@ -43,24 +43,36 @@ const EXPORT_PROCESS = ['let', 'const', 'var', 'function', 'class', 'namespace']
/**
* The relative path to the MathJax directory
*/
const mjPath = path.relative(process.cwd(), path.resolve(__dirname,'../../js'));
const mjPath = path.relative(process.cwd(), path.resolve(__dirname, '..', '..', 'js'));
const mjGlobal = path.join('..', mjPath, 'components', 'global.js');

/**
* Read the configuration for the component
*/
const config = JSON.parse(fs.readFileSync(process.argv[2] || 'build.json'));

function getType() {
const component = config.component || 'part';
if (component.match(/\/(svg|chtml|common)\/fonts\//)) return RegExp.$1 + '-font';
if (component.match(/\/(mathml|tex)\/.+\//)) return RegExp.$1 + '-extension';
if (component.match(/^(.+)\//)) return RegExp.$1;
return component;
}

/**
* Extract the configuration values
*/
const COMPONENT = path.basename(config.component || 'part'); // name of the component
const ID = config.id || config.component || 'part'; // the ID of the component
const TARGETS = config.targets || []; // the files to include in the component
const EXCLUDE = new Map((config.exclude || []).map(name => [name, true])); // files to exclude from the component
const EXCLUDESUBDIRS = config.excludeSubdirs === 'true'; // exclude subdirectories
const MATHJAX = config.js || config.mathjax || mjPath; // path to the compiled .js files
const EXCLUDESUBDIRS = config.excludeSubdirs === 'true'; // exclude subdirectories or not
const JS = config.js || config.mathjax || mjPath; // path to the compiled .js files
const LIB = config.lib || './lib'; // path to the lib directory to create
const COMPONENT = path.basename(config.component || 'part'); // name of the component
const GLOBAL = config.global || `../${MATHJAX}/components/global.js`; // the location of global.js
const SRC = config.ts || MATHJAX.replace(/js$/, 'ts'); // path to the .ts files
const TS = config.ts || JS.replace(/js$/, 'ts'); // path to the .ts files
const GLOBAL = config.global || mjGlobal; // path to the global.js file
const VERSION = config.version || mjGlobal.replace(/global/, 'version'); // path to the version.js file
const TYPE = config.type || getType(); // the module type

/**
* The list of files that need to be added to the lib directory
Expand Down Expand Up @@ -160,17 +172,15 @@ function processLines(file, objects) {
if (objects.length === 0) return [];
const dir = path.dirname(file).replace(/^\.$/, '');
const dots = dir.replace(/[^\/]+/g, '..') || '.';
const relative = path.join(dots, '..', MATHJAX, dir, path.basename(file)).replace(/\.ts$/, '.js');
const relative = path.join(dots, '..', JS, dir, path.basename(file)).replace(/\.ts$/, '.js');
const name = path.parse(file).name;
const lines = [
'"use strict";',
`Object.defineProperty(exports, '__esModule', {value: true});`
];
let source = (dir.replace(/\//g, '.') + '.' + name).replace(/^\./, '')
let source = ((dir.replace(/\//g, '.') + '.' + name).replace(/^\./, '')
+ (exists(path.resolve(JS, file.replace(/\.ts$/, ''))) ? '_ts' : ''))
.replace(/\.[^.]*/g, (x) => (x.substr(1).match(/[^a-zA-Z_]/) ? '[\'' + x.substr(1) + '\']' : x));
if (exists(path.resolve(MATHJAX, file.replace(/\.ts$/, '')))) {
source += '_ts';
}
for (const id of objects) {
lines.push(`exports.${id} = MathJax._.${source}.${id};`);
}
Expand Down Expand Up @@ -223,6 +233,7 @@ function processGlobal() {
console.info(' ' + COMPONENT + '.ts');
const lines = [
`import {combineWithMathJax} from '${GLOBAL}';`,
`import {VERSION} from '${VERSION}';`,
'',
];
const packages = [];
Expand All @@ -231,9 +242,17 @@ function processGlobal() {
const dir = path.dirname(PACKAGE[0]).split(path.sep)[0];
packages.push(processPackage(lines, INDENT, dir));
}
lines.push('', `combineWithMathJax({_: {`);
lines.push(INDENT + packages.join(',\n' + INDENT));
lines.push('}});');
const name = (ID.match(/[^a-zA-Z0-9_]/) ? `"${ID}"` : ID);
lines.push(
'',
'if (MathJax.loader) {',
INDENT + `MathJax.loader.checkVersion('${ID}', VERSION, '${TYPE}');`,
'}',
'',
`combineWithMathJax({_: {`,
INDENT + packages.join(',\n' + INDENT),
'}});'
);
fs.writeFileSync(path.join(LIB, COMPONENT + '.js'), lines.join('\n') + '\n');
}

Expand Down Expand Up @@ -273,11 +292,11 @@ function processPackage(lines, space, dir) {
if (path.dirname(PACKAGE[0]) === dir) {
const file = PACKAGE.shift();
const name = path.basename(file);
const relativefile = path.join('..', MATHJAX, dir, name).replace(/\.ts$/, '.js');
const relativefile = path.join('..', JS, dir, name).replace(/\.ts$/, '.js');
const component = 'module' + (++importCount);
lines.push(`import * as ${component} from '${relativefile}';`);
let property = name.replace(/\.ts$/, '');
if (property !== name && exists(path.resolve(MATHJAX, file.replace(/\.ts$/, '')))) {
if (property !== name && exists(path.resolve(JS, file.replace(/\.ts$/, '')))) {
property += '_ts';
}
if (property.match(/[^a-zA-Z0-9_]/)) {
Expand Down Expand Up @@ -324,5 +343,5 @@ function rmDir(dir) {
//
rmDir(LIB);
console.info("Processing:");
processList(SRC, '', TARGETS);
processList(TS, '', TARGETS);
processGlobal();
16 changes: 14 additions & 2 deletions components/bin/makeAll
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ const fs = require('fs');
const path = require('path');
const {execSync} = require('child_process');

const options = {
recursive: true
};

/**
* Get the directories to process
* Get the directories to process and check for options
*/
const dirs = process.argv.slice(2);

if (dirs[0] === '--no-subdirs') {
dirs.shift();
options.recursive = false;
}

if (dirs.length === 0) {
dirs.push('.');
}
Expand Down Expand Up @@ -74,7 +84,9 @@ function processList(dirs) {
*/
function processDir(dir, action) {
action(dir);
processSubdirs(dir, action);
if (options.recursive) {
processSubdirs(dir, action);
}
}

/**
Expand Down
30 changes: 20 additions & 10 deletions components/bin/pack
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function fileSize(file) {
/**
* Regular expressions for the components directory and the MathJax .js location
*/
const compRE = fileRegExp(path.join(path.dirname(__dirname), 'src'));
const compRE = fileRegExp(path.dirname(__dirname));
const rootRE = fileRegExp(path.join(path.dirname(path.dirname(__dirname)), 'js'));
const nodeRE = fileRegExp(path.join(path.dirname(path.dirname(__dirname)), 'node_modules'));

Expand Down Expand Up @@ -83,7 +83,7 @@ async function webpackLib(dir) {
//
// Get js directory from the webpack.config.js file
//
const jsdir = require(path.resolve(dir, 'webpack.config.js')).plugins[0].definitions.jsdir;
const jsdir = require(path.resolve(dir, 'webpack.config.js')).plugins[0].definitions.__JSDIR__;
const jsRE = fileRegExp(jsdir);
const libRE = fileRegExp(path.resolve(jsdir, '..', 'components'));

Expand All @@ -103,17 +103,27 @@ async function webpackLib(dir) {
.replace(/ \+ \d+ modules/, '')
.replace(dirRE, '.');
}
for (const module of modules.sort((a,b) => a.name < b.name ? -1 : 1)) {
const list = [];
for (const module of modules) {
if (module.moduleType.match(/javascript/)) {
const name = module.name
.replace(compRE, '[components]')
.replace(rootRE, '[mathjax]')
.replace(nodeRE, '[node]')
.replace(jsRE, '[js]')
.replace(libRE, '[lib]');
console.log(' ' + name + fileSize(module));
let name = module.name
.replace(compRE, '[components]')
.replace(rootRE, '[mathjax]')
.replace(nodeRE, '[node]')
.replace(jsRE, '[js]')
.replace(libRE, '[lib]');
if (name.charAt(0) !== '.' && name.charAt(0) !== '[') {
name = path.relative(dir, name);
}
list.push(' ' + name + fileSize(module));
}
}
console.log(
list
.filter(a => a.slice(2, 4) === './').sort()
.concat(list.filter(a => a.slice(2, 4) !== './').sort())
.join('\n')
);
} catch (err) {
console.error(err);
}
Expand Down
3 changes: 1 addition & 2 deletions components/src/a11y/complexity/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"targets": [
"a11y/complexity.ts",
"a11y/complexity",
"a11y/semantic-enrich.ts",
"a11y/sre.ts"
"a11y/semantic-enrich.ts"
]
}
2 changes: 1 addition & 1 deletion components/src/a11y/explorer/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"component": "a11y/explorer",
"targets": ["a11y/explorer.ts", "a11y/sre.ts", "a11y/explorer"]
"targets": ["a11y/explorer.ts", "a11y/explorer"]
}
1 change: 1 addition & 0 deletions components/src/a11y/explorer/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = PACKAGE(
[ // packages to link to
'components/src/ui/menu/lib',
'components/src/a11y/semantic-enrich/lib',
'components/src/a11y/sre/lib',
'components/src/input/mml/lib',
'components/src/core/lib'
],
Expand Down
2 changes: 1 addition & 1 deletion components/src/a11y/semantic-enrich/build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"component": "a11y/semantic-enrich",
"targets": ["a11y/semantic-enrich.ts", "a11y/sre.ts"]
"targets": ["a11y/semantic-enrich.ts"]
}

4 changes: 2 additions & 2 deletions components/src/a11y/semantic-enrich/semantic-enrich.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import './lib/semantic-enrich.js';

import {combineDefaults} from '../../../../js/components/global.js';
import {sreReady} from '../../../../js/a11y/sre.js';
import Sre from '../../../../js/a11y/sre.js';
import {EnrichHandler} from '../../../../js/a11y/semantic-enrich.js';
import {MathML} from '../../../../js/input/mathml.js';

if (MathJax.loader) {
combineDefaults(MathJax.config.loader, 'a11y/semantic-enrich', {checkReady: () => sreReady()});
combineDefaults(MathJax.config.loader, 'a11y/semantic-enrich', {checkReady: () => Sre.sreReady()});
}

if (MathJax.startup) {
Expand Down
3 changes: 2 additions & 1 deletion components/src/a11y/semantic-enrich/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = PACKAGE(
'../../../../js', // location of the MathJax js library
[ // packages to link to
'components/src/input/mml/lib',
'components/src/core/lib'
'components/src/core/lib',
'components/src/a11y/sre/lib'
],
__dirname // our directory
);
5 changes: 5 additions & 0 deletions components/src/a11y/sre/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"component": "a11y/sre",
"targets": ["a11y/sre.ts"]
}

9 changes: 9 additions & 0 deletions components/src/a11y/sre/sre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import './lib/sre.js';
import './sre_config.js';
import Sre from '../../../../js/a11y/sre.js';

if (MathJax.startup) {
((typeof window !== 'undefined') ? window : global).
SREfeature.custom = (loc) => Sre.preloadLocales(loc);
}

19 changes: 19 additions & 0 deletions components/src/a11y/sre/sre_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {combineDefaults} from '../../../../js/components/global.js';
import {Package} from '../../../../js/components/package.js';

// This sets up the correct link to the mathmaps files.
if (MathJax.startup) {

let path = Package.resolvePath('[sre]', false);

if (typeof window !== 'undefined') {
window.SREfeature = {json: path};
} else {
// In Node get the absolute path to the mathmaps directory.
try {
path = MathJax.config.loader.require.resolve(
path + '/base.json').replace(/\/base\.json$/, '');
} catch(_err) { }
global.SREfeature = {json: path};
}
}
12 changes: 12 additions & 0 deletions components/src/a11y/sre/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const PACKAGE = require('../../../webpack.common.js');

module.exports = PACKAGE(
'a11y/sre', // the package to build
'../../../../js', // location of the MathJax js library
[ // packages to link to
'components/src/input/mml/lib',
'components/src/core/lib',
'components/src/startup/lib'
],
__dirname // our directory
);
41 changes: 7 additions & 34 deletions components/src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

export const dependencies = {
'a11y/semantic-enrich': ['input/mml', '[sre]'],
'a11y/semantic-enrich': ['input/mml', 'a11y/sre'],
'a11y/complexity': ['a11y/semantic-enrich'],
'a11y/explorer': ['a11y/semantic-enrich', 'ui/menu'],
'[mml]/mml3': ['input/mml'],
Expand Down Expand Up @@ -58,41 +58,14 @@ export const dependencies = {
export const paths = {
tex: '[mathjax]/input/tex/extensions',
mml: '[mathjax]/input/mml/extensions',
sre: '[mathjax]/sre/' + (typeof window === 'undefined' ? 'sre-node' : 'sre_browser')
sre: '[mathjax]/sre/mathmaps'
};

const allPackages = [
'[tex]/action',
'[tex]/ams',
'[tex]/amscd',
'[tex]/bbox',
'[tex]/boldsymbol',
'[tex]/braket',
'[tex]/bussproofs',
'[tex]/cancel',
'[tex]/centernot',
'[tex]/color',
'[tex]/colortbl',
'[tex]/configmacros',
'[tex]/enclose',
'[tex]/extpfeil',
'[tex]/html',
'[tex]/mathtools',
'[tex]/mhchem',
'[tex]/newcommand',
'[tex]/noerrors',
'[tex]/noundefined',
'[tex]/physics',
'[tex]/require',
'[tex]/setoptions',
'[tex]/tagformat',
'[tex]/textcomp',
'[tex]/textmacros',
'[tex]/unicode',
'[tex]/verb',
'[tex]/cases',
'[tex]/empheq'
];
const allPackages = Array.from(Object.keys(dependencies))
.filter(name => name.substr(0,5) === '[tex]' &&
name !== '[tex]/autoload' &&
name !== '[tex]/colorv2' &&
name !== '[tex]/all-packages');

export const provides = {
'startup': ['loader'],
Expand Down
3 changes: 1 addition & 2 deletions components/src/input/asciimath/build.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"component": "inpu/asciimath",
"component": "input/asciimath",
"targets": ["input/asciimath.ts", "input/asciimath"],
"excludeSubdirs": "true"
}

2 changes: 1 addition & 1 deletion components/src/input/mml/build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"component": "inpu/mml",
"component": "input/mml",
"targets": [
"input/mathml.ts",
"input/mathml"
Expand Down
1 change: 1 addition & 0 deletions components/src/input/mml/extensions/mml3/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[mml]/mml3",
"component": "input/mml/extensions/mml3",
"targets": ["input/mathml/mml3"]
}
Loading

0 comments on commit 9f588aa

Please sign in to comment.