@wiris/mathtype-viewer 8.9.1 → 8.10.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 +1 -4
- package/babel.config.js +3 -2
- package/dist/WIRISplugins.js +1 -1
- package/dist/WIRISplugins.js.LICENSE.txt +1 -1
- package/dist/app.d.ts +1 -1
- package/dist/app.d.ts.map +1 -1
- package/dist/latex.d.ts +1 -1
- package/dist/latex.d.ts.map +1 -1
- package/dist/mathml.d.ts +1 -0
- package/dist/mathml.d.ts.map +1 -1
- package/dist/properties.d.ts +18 -17
- package/dist/properties.d.ts.map +1 -1
- package/dist/services.d.ts +1 -1
- package/dist/services.d.ts.map +1 -1
- package/docs/spec.md +25 -25
- package/index.html +19 -21
- package/jest.config.js +4 -0
- package/package.json +7 -2
- package/project.json +4 -12
- package/src/app.ts +11 -12
- package/src/latex.ts +19 -24
- package/src/mathml.spec.ts +189 -0
- package/src/mathml.ts +90 -43
- package/src/properties.ts +116 -89
- package/src/retro.ts +49 -44
- package/src/services.ts +65 -48
- package/tsconfig.json +26 -22
- package/typings/module-name.d.ts +1 -1
- package/webpack.config.js +10 -10
- package/dist/utils.d.ts +0 -3
- package/dist/utils.d.ts.map +0 -1
- package/src/utils.ts +0 -45
package/src/services.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Parser from
|
|
2
|
-
import { Properties } from
|
|
1
|
+
import Parser from "@wiris/mathtype-html-integration-devkit/src/parser";
|
|
2
|
+
import { Properties } from "./properties";
|
|
3
3
|
|
|
4
4
|
enum MethodType {
|
|
5
5
|
Post = "POST",
|
|
@@ -28,12 +28,12 @@ export async function processJsonResponse(response: Promise<Response>): Promise<
|
|
|
28
28
|
try {
|
|
29
29
|
const { status, result } = await (await response).json();
|
|
30
30
|
|
|
31
|
-
if (status !==
|
|
32
|
-
throw new StatusError(
|
|
31
|
+
if (status !== "ok") {
|
|
32
|
+
throw new StatusError("Service responded with a non-ok status");
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
return result;
|
|
36
|
-
} catch(e) {
|
|
36
|
+
} catch (e) {
|
|
37
37
|
// TODO manage network and status non-ok errors
|
|
38
38
|
throw e;
|
|
39
39
|
}
|
|
@@ -47,19 +47,26 @@ export async function processJsonResponse(response: Promise<Response>): Promise<
|
|
|
47
47
|
* @param {string} extension - Extension to add to the end of the serviceName (including the dot if necessary).
|
|
48
48
|
* @returns {Promise<Response>} The request response.
|
|
49
49
|
*/
|
|
50
|
-
export async function callService(
|
|
50
|
+
export async function callService(
|
|
51
|
+
query: object,
|
|
52
|
+
serviceName: string,
|
|
53
|
+
method: MethodType,
|
|
54
|
+
serverURL: string,
|
|
55
|
+
extension: string,
|
|
56
|
+
): Promise<any> {
|
|
51
57
|
try {
|
|
52
58
|
const url = new URL(serviceName + extension, serverURL);
|
|
53
59
|
|
|
54
|
-
|
|
60
|
+
// Getting the configuration is asynchronous since we make some requests.
|
|
61
|
+
const properties = await Properties.getInstance();
|
|
55
62
|
const headers = {
|
|
56
|
-
|
|
57
|
-
...properties.config.backendConfig.wiriscustomheaders
|
|
58
|
-
}
|
|
63
|
+
"Content-type": "application/x-www-form-urlencoded; charset=utf-8",
|
|
64
|
+
...properties.config.backendConfig.wiriscustomheaders,
|
|
65
|
+
};
|
|
59
66
|
|
|
60
67
|
const init: RequestInit = {
|
|
61
68
|
method,
|
|
62
|
-
headers
|
|
69
|
+
headers,
|
|
63
70
|
};
|
|
64
71
|
|
|
65
72
|
if (method === MethodType.Get) {
|
|
@@ -69,11 +76,11 @@ export async function callService(query: object, serviceName: string, method: Me
|
|
|
69
76
|
}
|
|
70
77
|
} else {
|
|
71
78
|
// Add the query as the body of the request
|
|
72
|
-
init.body = new URLSearchParams({...query});
|
|
79
|
+
init.body = new URLSearchParams({ ...query });
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
return fetch(url.toString(), init);
|
|
76
|
-
} catch(e) {
|
|
83
|
+
} catch (e) {
|
|
77
84
|
// TODO manage network and status non-ok errors
|
|
78
85
|
throw e;
|
|
79
86
|
}
|
|
@@ -87,18 +94,18 @@ export async function callService(query: object, serviceName: string, method: Me
|
|
|
87
94
|
* @param {string} extension - Extension to add to the end of the serviceName (including the dot if necessary).
|
|
88
95
|
* @returns {Promise<Response>} The mathml2accessible service response.
|
|
89
96
|
*/
|
|
90
|
-
export async function mathml2accessible(mml: string, lang: string, url: string, extension: string)
|
|
97
|
+
export async function mathml2accessible(mml: string, lang: string, url: string, extension: string): Promise<any> {
|
|
91
98
|
// Set the needed params to retrieve the alt text.
|
|
92
99
|
const params = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
+
service: "mathml2accessible",
|
|
101
|
+
mml: mml,
|
|
102
|
+
metrics: "true",
|
|
103
|
+
centerbaseline: "false",
|
|
104
|
+
lang: lang,
|
|
105
|
+
ignoreStyles: "true",
|
|
106
|
+
};
|
|
100
107
|
|
|
101
|
-
const response = callService(params,
|
|
108
|
+
const response = callService(params, "service", MethodType.Post, url, extension);
|
|
102
109
|
return processJsonResponse(response);
|
|
103
110
|
}
|
|
104
111
|
|
|
@@ -112,18 +119,18 @@ export async function mathml2accessible(mml: string, lang: string, url: string,
|
|
|
112
119
|
*/
|
|
113
120
|
export async function showImage(mml: string, lang: string, url: string, extension: string): Promise<any> {
|
|
114
121
|
const params = {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
122
|
+
mml: mml,
|
|
123
|
+
metrics: "true",
|
|
124
|
+
centerbaseline: "false",
|
|
125
|
+
lang: lang,
|
|
126
|
+
};
|
|
120
127
|
|
|
121
128
|
// Try to obtain the image via GET
|
|
122
129
|
const getParams = Parser.createShowImageSrcData(params, params.lang);
|
|
123
|
-
const getResponse = callService(getParams,
|
|
130
|
+
const getResponse = callService(getParams, "showimage", MethodType.Get, url, extension);
|
|
124
131
|
try {
|
|
125
132
|
return await processJsonResponse(getResponse);
|
|
126
|
-
} catch(e) {
|
|
133
|
+
} catch (e) {
|
|
127
134
|
if (e instanceof StatusError) {
|
|
128
135
|
// Formula was not in cache; proceed with calling showimage via POST
|
|
129
136
|
} else {
|
|
@@ -132,10 +139,9 @@ export async function showImage(mml: string, lang: string, url: string, extensio
|
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
// If GET request fails, it means that the formula was not in cache. Proceed with POST:
|
|
135
|
-
const response = callService(params,
|
|
142
|
+
const response = callService(params, "showimage", MethodType.Post, url, extension);
|
|
136
143
|
return processJsonResponse(response);
|
|
137
|
-
|
|
138
|
-
};
|
|
144
|
+
}
|
|
139
145
|
|
|
140
146
|
/**
|
|
141
147
|
* Calls the createImage service with the given MathML and returns the received Response object.
|
|
@@ -147,16 +153,16 @@ export async function showImage(mml: string, lang: string, url: string, extensio
|
|
|
147
153
|
*/
|
|
148
154
|
export async function createImage(mml: string, lang: string, url: string, extension: string): Promise<any> {
|
|
149
155
|
const params = {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
156
|
+
mml: mml,
|
|
157
|
+
metrics: "true",
|
|
158
|
+
centerbaseline: "false",
|
|
159
|
+
lang: lang,
|
|
160
|
+
};
|
|
155
161
|
|
|
156
|
-
// POST request to
|
|
157
|
-
const response = callService(params,
|
|
162
|
+
// POST request to retrieve the corresponding image.
|
|
163
|
+
const response = callService(params, "showimage", MethodType.Post, url, extension);
|
|
158
164
|
return processJsonResponse(response);
|
|
159
|
-
|
|
165
|
+
}
|
|
160
166
|
|
|
161
167
|
/**
|
|
162
168
|
* Calls the latex2mathml service with the given LaTeX and returns the received Response object.
|
|
@@ -167,11 +173,11 @@ export async function createImage(mml: string, lang: string, url: string, extens
|
|
|
167
173
|
*/
|
|
168
174
|
export async function latexToMathml(latex: string, url: string, extension: string): Promise<any> {
|
|
169
175
|
const params = {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
176
|
+
service: "latex2mathml",
|
|
177
|
+
latex: latex,
|
|
178
|
+
};
|
|
173
179
|
|
|
174
|
-
const response = callService(params,
|
|
180
|
+
const response = callService(params, "service", MethodType.Post, url, extension);
|
|
175
181
|
return processJsonResponse(response);
|
|
176
182
|
}
|
|
177
183
|
|
|
@@ -181,11 +187,22 @@ export async function latexToMathml(latex: string, url: string, extension: strin
|
|
|
181
187
|
* @param {string} extension - Extension to add to the end of the serviceName (including the dot if necessary).
|
|
182
188
|
* @returns {Promise<Response>} The configurationjson service response.
|
|
183
189
|
*/
|
|
184
|
-
export async function configurationJson(
|
|
190
|
+
export async function configurationJson(
|
|
191
|
+
variablekeys: string[],
|
|
192
|
+
url: string,
|
|
193
|
+
extension: string,
|
|
194
|
+
check: boolean,
|
|
195
|
+
): Promise<any> {
|
|
185
196
|
const params = {
|
|
186
|
-
|
|
187
|
-
}
|
|
197
|
+
variablekeys: variablekeys.join(","),
|
|
198
|
+
};
|
|
188
199
|
|
|
189
|
-
const response = callService(params,
|
|
200
|
+
const response = await callService(params, "configurationjson", MethodType.Get, url, extension);
|
|
201
|
+
|
|
202
|
+
// Provide a warning to alert the users that the console error is an expected outcome,
|
|
203
|
+
// since this request only aims to be a check and does not expect to retrieve any data.
|
|
204
|
+
if (check && !response.ok) {
|
|
205
|
+
console.warn("Fetching the url: " + response.url + ", is expected to fail and handled. Don't panic!");
|
|
206
|
+
}
|
|
190
207
|
return processJsonResponse(response);
|
|
191
208
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
+
"strict": true,
|
|
3
4
|
/* Basic Options */
|
|
4
|
-
"target": "ES5"
|
|
5
|
-
"module": "commonjs"
|
|
5
|
+
"target": "ES5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
|
|
6
|
+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
|
6
7
|
"lib": [
|
|
7
8
|
"dom",
|
|
8
9
|
"es6",
|
|
@@ -10,28 +11,28 @@
|
|
|
10
11
|
"scripthost",
|
|
11
12
|
"es2017",
|
|
12
13
|
"es5",
|
|
13
|
-
"es2015"
|
|
14
|
-
]
|
|
14
|
+
"es2015"
|
|
15
|
+
] /* Specify library files to be included in the compilation. */,
|
|
15
16
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
16
17
|
// "checkJs": true, /* Report errors in .js files. */
|
|
17
18
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
18
|
-
"declaration": true
|
|
19
|
-
"declarationMap": true
|
|
20
|
-
"sourceMap": true
|
|
19
|
+
"declaration": true /* Generates corresponding '.d.ts' file. */,
|
|
20
|
+
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
|
|
21
|
+
"sourceMap": true /* Generates corresponding '.map' file. */,
|
|
21
22
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
22
|
-
"outDir": "./dist"
|
|
23
|
-
"rootDir": "./src"
|
|
23
|
+
"outDir": "./dist" /* Redirect output structure to the directory. */,
|
|
24
|
+
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
|
24
25
|
// "composite": true, /* Enable project compilation */es
|
|
25
|
-
"removeComments": true
|
|
26
|
+
"removeComments": true /* Do not emit comments to output. */,
|
|
26
27
|
// "noEmit": true, /* Do not emit outputs. */
|
|
27
28
|
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
28
|
-
"downlevelIteration": true
|
|
29
|
+
"downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
|
|
29
30
|
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
30
31
|
"noEmitOnError": true,
|
|
31
32
|
|
|
32
33
|
/* Strict Type-Checking Options */
|
|
33
34
|
// "strict": true, /* Enable all strict type-checking options. */
|
|
34
|
-
"noImplicitAny": false
|
|
35
|
+
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
|
|
35
36
|
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
36
37
|
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
37
38
|
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
@@ -40,24 +41,25 @@
|
|
|
40
41
|
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
41
42
|
|
|
42
43
|
/* Additional Checks */
|
|
43
|
-
"noUnusedLocals": false
|
|
44
|
-
"noUnusedParameters": false
|
|
45
|
-
"noImplicitReturns": true
|
|
44
|
+
"noUnusedLocals": false /* Report errors on unused locals. */,
|
|
45
|
+
"noUnusedParameters": false /* Report errors on unused parameters. */,
|
|
46
|
+
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
|
46
47
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
47
48
|
|
|
48
49
|
/* Module Resolution Options */
|
|
49
|
-
"moduleResolution": "node"
|
|
50
|
+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
|
|
50
51
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
51
52
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
52
53
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
53
54
|
"typeRoots": [
|
|
54
55
|
"./typings",
|
|
55
56
|
"../node_modules/@types",
|
|
57
|
+
"../../node_modules/@types",
|
|
56
58
|
"./dist"
|
|
57
|
-
]
|
|
59
|
+
] /* List of folders to include type definitions from. */,
|
|
58
60
|
// "types": [], /* Type declaration files to be included in compilation. */
|
|
59
61
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
60
|
-
"esModuleInterop": true
|
|
62
|
+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
|
61
63
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
62
64
|
|
|
63
65
|
/* Source Map Options */
|
|
@@ -67,12 +69,14 @@
|
|
|
67
69
|
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
68
70
|
|
|
69
71
|
/* Experimental Options */
|
|
70
|
-
"experimentalDecorators": true
|
|
72
|
+
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
|
|
71
73
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
72
|
-
"resolveJsonModule": true
|
|
74
|
+
"resolveJsonModule": true,
|
|
75
|
+
"types": ["jest"]
|
|
73
76
|
},
|
|
74
77
|
"exclude": [
|
|
75
78
|
"node_modules", // would be the default
|
|
76
|
-
"./dist"
|
|
79
|
+
"./dist",
|
|
80
|
+
"**/*.spec.ts"
|
|
77
81
|
]
|
|
78
|
-
}
|
|
82
|
+
}
|
package/typings/module-name.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
declare module "Parser";
|
|
2
|
-
declare module
|
|
2
|
+
declare module "@wiris/mathtype-html-integration-devkit/src/parser";
|
package/webpack.config.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
const path = require(
|
|
1
|
+
const path = require("path");
|
|
2
2
|
|
|
3
3
|
module.exports = (config, context) => {
|
|
4
4
|
return {
|
|
5
|
-
entry:
|
|
6
|
-
mode:
|
|
5
|
+
entry: "./src/app.ts",
|
|
6
|
+
mode: "none",
|
|
7
7
|
module: {
|
|
8
8
|
rules: [
|
|
9
9
|
{
|
|
10
10
|
test: /\.tsx?$/,
|
|
11
|
-
use:
|
|
11
|
+
use: "ts-loader",
|
|
12
12
|
exclude: /node_modules/,
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
test: /\.js$/,
|
|
16
16
|
exclude: /node_modules/,
|
|
17
|
-
use: [
|
|
17
|
+
use: ["babel-loader"],
|
|
18
18
|
},
|
|
19
19
|
],
|
|
20
20
|
},
|
|
21
21
|
resolve: {
|
|
22
|
-
extensions: [
|
|
22
|
+
extensions: [".tsx", ".ts", ".js"],
|
|
23
23
|
},
|
|
24
24
|
output: {
|
|
25
|
-
filename:
|
|
26
|
-
path: path.resolve(__dirname,
|
|
25
|
+
filename: "WIRISplugins.js",
|
|
26
|
+
path: path.resolve(__dirname, "dist"),
|
|
27
27
|
},
|
|
28
28
|
devServer: {
|
|
29
29
|
devMiddleware: {
|
|
30
30
|
writeToDisk: true,
|
|
31
31
|
},
|
|
32
|
-
static:
|
|
32
|
+
static: "./",
|
|
33
33
|
hot: true,
|
|
34
34
|
port: 8001,
|
|
35
35
|
open: true,
|
|
@@ -37,5 +37,5 @@ module.exports = (config, context) => {
|
|
|
37
37
|
optimization: {
|
|
38
38
|
minimize: true, // enabling this reduces file size and readability
|
|
39
39
|
},
|
|
40
|
-
}
|
|
40
|
+
};
|
|
41
41
|
};
|
package/dist/utils.d.ts
DELETED
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAoBA,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAoB9D;AAID,eAAO,MAAM,aAAa,UAAqG,CAAC"}
|
package/src/utils.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Takes a string possibly containing encoded entities (e.g.  ) and
|
|
3
|
-
* returns the same string with these replaced by the UTF-8 characters they represent
|
|
4
|
-
* @param {string} text - the string with encoded entities
|
|
5
|
-
* @returns the same string with the entities decoded
|
|
6
|
-
*/
|
|
7
|
-
function decodeEntities(text: string): string {
|
|
8
|
-
const element = document.createElement('textarea');
|
|
9
|
-
element.innerHTML = text;
|
|
10
|
-
return element.value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Takes a string possibly containing encoded named HTML entities (e.g. ) and
|
|
15
|
-
* returns the same string with these replaced by the encoding that uses numbers (e.g.  ).
|
|
16
|
-
* By its implementation, this method also possibly encodes special characters that were
|
|
17
|
-
* previously unencoded.
|
|
18
|
-
* @param {string} text - the string with encoded entities
|
|
19
|
-
* @returns the same string with the entities decoded
|
|
20
|
-
*/
|
|
21
|
-
export function htmlEntitiesToXmlEntities(text: string): string {
|
|
22
|
-
text = decodeEntities(text);
|
|
23
|
-
|
|
24
|
-
// Replaces the '<', '&', '>', and '"' characters to its HTMLEntity to avoid render issues.
|
|
25
|
-
text = text.split('&').join('&')
|
|
26
|
-
.split('"<"').join('"<"')
|
|
27
|
-
.split('">"').join('">"')
|
|
28
|
-
.split('><<').join('><<');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let result = '';
|
|
32
|
-
for (let i = 0; i < text.length; i++) {
|
|
33
|
-
const character = text.charAt(i);
|
|
34
|
-
if (text.charCodeAt(i) > 128) {
|
|
35
|
-
result += '&#' + text.charCodeAt(i) + ';';
|
|
36
|
-
} else {
|
|
37
|
-
result += character;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Set of mathml and characters which don't have an accessible text associated
|
|
44
|
-
// and can not be translated or transformed to LaTeX.
|
|
45
|
-
export const corruptMathML = ['⟦', '⟦', '⟧', '⟧', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow'];
|