@wiris/mathtype-viewer 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/dist/WIRISplugins.js +2 -7688
- package/dist/WIRISplugins.js.LICENSE.txt +1 -0
- package/dist/mathml.d.ts.map +1 -1
- package/package.json +4 -3
- package/project.json +10 -0
- package/src/mathml.ts +40 -0
- package/webpack.config.js +4 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! @license DOMPurify 2.4.7 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.4.7/LICENSE */
|
package/dist/mathml.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mathml.d.ts","sourceRoot":"","sources":["../src/mathml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"mathml.d.ts","sourceRoot":"","sources":["../src/mathml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAyD1C,wBAAsB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAgC3F"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wiris/mathtype-viewer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "webpack",
|
|
7
|
+
"build": "webpack --mode production",
|
|
8
|
+
"build-dev": "webpack --mode development",
|
|
8
9
|
"serve": "webpack serve",
|
|
9
10
|
"prepack": "yarn && npm run build"
|
|
10
11
|
},
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
"author": "Integrations",
|
|
16
17
|
"license": "ISC",
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@wiris/mathtype-html-integration-devkit": "1.
|
|
19
|
+
"@wiris/mathtype-html-integration-devkit": "1.15.0"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
22
|
"babel-loader": "^9.1.2",
|
package/project.json
CHANGED
|
@@ -13,6 +13,16 @@
|
|
|
13
13
|
"{options.outputPath}"
|
|
14
14
|
]
|
|
15
15
|
},
|
|
16
|
+
"build-dev": {
|
|
17
|
+
"executor": "nx:run-script",
|
|
18
|
+
"options": {
|
|
19
|
+
"script": "build-dev",
|
|
20
|
+
"outputPath": "packages/viewer/dist"
|
|
21
|
+
},
|
|
22
|
+
"outputs": [
|
|
23
|
+
"{options.outputPath}"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
16
26
|
"lint": {
|
|
17
27
|
"executor": "@nx/linter:eslint",
|
|
18
28
|
"options": {
|
package/src/mathml.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Properties } from "./properties";
|
|
2
2
|
import { showImage, createImage, mathml2accessible, processJsonResponse } from './services';
|
|
3
3
|
import { htmlEntitiesToXmlEntities, corruptMathML } from './utils';
|
|
4
|
+
import MathML from '@wiris/mathtype-html-integration-devkit/src/mathml';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Data obtained when rendering image. Data needed to set the formula image parameters.
|
|
@@ -12,6 +13,43 @@ interface FormulaData {
|
|
|
12
13
|
width: string,
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Look for safe MathML «math» formulas.
|
|
18
|
+
* @param {HTMLElement} root - Any DOM element that can contain MathML.
|
|
19
|
+
*/
|
|
20
|
+
function findSafeMathMLTextNodes(root: HTMLElement): Node[] {
|
|
21
|
+
const nodeIterator: NodeIterator = document.createNodeIterator(
|
|
22
|
+
root,
|
|
23
|
+
NodeFilter.SHOW_TEXT,
|
|
24
|
+
node => /«math(.*?)«\/math»/g.test(node.nodeValue || '') ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
|
|
25
|
+
);
|
|
26
|
+
const safeNodes : Node[] = [];
|
|
27
|
+
|
|
28
|
+
let currentNode: Node | null;
|
|
29
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
30
|
+
safeNodes.push(currentNode);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return safeNodes;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Parse the DOM looking for «math» formulas and replace them with the corresponding rendered images within the given element.
|
|
38
|
+
* @param {HTMLElement} root - Any DOM element that can contain MathML.
|
|
39
|
+
*/
|
|
40
|
+
function decodeSafeMathML(root: HTMLElement) {
|
|
41
|
+
const safeNodes = findSafeMathMLTextNodes(root);
|
|
42
|
+
|
|
43
|
+
for (const safeNode of safeNodes) {
|
|
44
|
+
const mathml = MathML.safeXmlDecode(safeNode.textContent);
|
|
45
|
+
// Insert mathml node.
|
|
46
|
+
const fragment = document.createRange().createContextualFragment(mathml);
|
|
47
|
+
|
|
48
|
+
safeNode.parentNode?.insertBefore(fragment, safeNode);
|
|
49
|
+
safeNode.parentNode?.removeChild(safeNode);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
15
53
|
/**
|
|
16
54
|
* Parse the DOM looking for <math> elements and replace them with the corresponding rendered images within the given element.
|
|
17
55
|
* @param {Properties} properties - Properties of the viewer.
|
|
@@ -23,6 +61,8 @@ export async function renderMathML(properties: Properties, root: HTMLElement): P
|
|
|
23
61
|
return;
|
|
24
62
|
}
|
|
25
63
|
|
|
64
|
+
decodeSafeMathML(root);
|
|
65
|
+
|
|
26
66
|
for(const mathElement of [...root.getElementsByTagName('math')]) {
|
|
27
67
|
const mml = htmlEntitiesToXmlEntities(mathElement.outerHTML);
|
|
28
68
|
|
package/webpack.config.js
CHANGED
|
@@ -3,8 +3,7 @@ const path = require('path');
|
|
|
3
3
|
module.exports = (config, context) => {
|
|
4
4
|
return {
|
|
5
5
|
entry: './src/app.ts',
|
|
6
|
-
mode: '
|
|
7
|
-
devtool: 'inline-source-map',
|
|
6
|
+
mode: 'none',
|
|
8
7
|
module: {
|
|
9
8
|
rules: [
|
|
10
9
|
{
|
|
@@ -35,5 +34,8 @@ module.exports = (config, context) => {
|
|
|
35
34
|
port: 8001,
|
|
36
35
|
open: true,
|
|
37
36
|
},
|
|
37
|
+
optimization: {
|
|
38
|
+
minimize: true, // enabling this reduces file size and readability
|
|
39
|
+
},
|
|
38
40
|
}
|
|
39
41
|
};
|