@wiris/mathtype-viewer 1.5.0 → 8.9.2
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 +3 -3
- package/dist/properties.d.ts.map +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 +10 -5
- package/project.json +4 -12
- package/src/app.ts +10 -11
- package/src/latex.ts +16 -20
- package/src/mathml.spec.ts +189 -0
- package/src/mathml.ts +89 -47
- package/src/properties.ts +58 -66
- package/src/retro.ts +37 -38
- package/src/services.ts +55 -49
- package/tsconfig.json +25 -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/properties.ts
CHANGED
|
@@ -1,51 +1,50 @@
|
|
|
1
|
-
import { configurationJson, StatusError } from
|
|
2
|
-
import Util from
|
|
1
|
+
import { configurationJson, StatusError } from "./services";
|
|
2
|
+
import Util from "@wiris/mathtype-html-integration-devkit/src/util";
|
|
3
3
|
|
|
4
4
|
// Helper types for Config below
|
|
5
|
-
type Viewer =
|
|
6
|
-
type Wirispluginperformance =
|
|
5
|
+
type Viewer = "none" | "image" | "mathml" | "latex";
|
|
6
|
+
type Wirispluginperformance = "true" | "false";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Type representing all the configuration for the viewer.
|
|
10
10
|
*/
|
|
11
11
|
export type Config = {
|
|
12
|
-
editorServicesRoot?: string
|
|
13
|
-
editorServicesExtension?: string
|
|
12
|
+
editorServicesRoot?: string;
|
|
13
|
+
editorServicesExtension?: string;
|
|
14
14
|
backendConfig?: {
|
|
15
|
-
wirispluginperformance?: Wirispluginperformance
|
|
16
|
-
wiriseditormathmlattribute?: string
|
|
17
|
-
wiriscustomheaders?: object
|
|
18
|
-
}
|
|
19
|
-
dpi?: number
|
|
20
|
-
element?: string
|
|
21
|
-
lang?: string
|
|
22
|
-
viewer?: Viewer
|
|
23
|
-
zoom?: number
|
|
15
|
+
wirispluginperformance?: Wirispluginperformance;
|
|
16
|
+
wiriseditormathmlattribute?: string;
|
|
17
|
+
wiriscustomheaders?: object;
|
|
18
|
+
};
|
|
19
|
+
dpi?: number;
|
|
20
|
+
element?: string;
|
|
21
|
+
lang?: string;
|
|
22
|
+
viewer?: Viewer;
|
|
23
|
+
zoom?: number;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Fallback values for the configurations that are not set.
|
|
28
28
|
*/
|
|
29
29
|
const defaultValues: Config = {
|
|
30
|
-
editorServicesRoot:
|
|
31
|
-
editorServicesExtension:
|
|
30
|
+
editorServicesRoot: "https://www.wiris.net/demo/plugins/app/",
|
|
31
|
+
editorServicesExtension: "",
|
|
32
32
|
backendConfig: {
|
|
33
|
-
wirispluginperformance:
|
|
34
|
-
wiriseditormathmlattribute:
|
|
33
|
+
wirispluginperformance: "true",
|
|
34
|
+
wiriseditormathmlattribute: "data-mathml",
|
|
35
35
|
wiriscustomheaders: {},
|
|
36
36
|
},
|
|
37
37
|
dpi: 96,
|
|
38
|
-
element:
|
|
39
|
-
lang:
|
|
40
|
-
viewer:
|
|
38
|
+
element: "body",
|
|
39
|
+
lang: "en",
|
|
40
|
+
viewer: "none",
|
|
41
41
|
zoom: 1,
|
|
42
|
-
}
|
|
42
|
+
};
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* This class will handle the parameters defined by the user.
|
|
46
46
|
*/
|
|
47
47
|
export class Properties {
|
|
48
|
-
|
|
49
48
|
private static instance: Properties | null = null;
|
|
50
49
|
|
|
51
50
|
render: () => Promise<void> = async () => {};
|
|
@@ -72,7 +71,7 @@ export class Properties {
|
|
|
72
71
|
*/
|
|
73
72
|
private async initialize(): Promise<void> {
|
|
74
73
|
// Get URL parameters from <script>
|
|
75
|
-
const pluginName =
|
|
74
|
+
const pluginName = "WIRISplugins.js";
|
|
76
75
|
const script: HTMLScriptElement = document.querySelector(`script[src*="${pluginName}"]`);
|
|
77
76
|
|
|
78
77
|
if (!!script) {
|
|
@@ -80,20 +79,20 @@ export class Properties {
|
|
|
80
79
|
const params: string = script.src.substring(pluginNamePosition + pluginName.length);
|
|
81
80
|
const urlParams = new URLSearchParams(params);
|
|
82
81
|
|
|
83
|
-
if (urlParams.get(
|
|
84
|
-
Properties.instance.config.dpi = +urlParams.get(
|
|
82
|
+
if (urlParams.get("dpi") !== null && urlParams.get("dpi") !== undefined) {
|
|
83
|
+
Properties.instance.config.dpi = +urlParams.get("dpi");
|
|
85
84
|
}
|
|
86
|
-
if (urlParams.get(
|
|
87
|
-
Properties.instance.config.element = urlParams.get(
|
|
85
|
+
if (urlParams.get("element") !== null && urlParams.get("element") !== undefined) {
|
|
86
|
+
Properties.instance.config.element = urlParams.get("element");
|
|
88
87
|
}
|
|
89
|
-
if (urlParams.get(
|
|
90
|
-
Properties.instance.config.lang = urlParams.get(
|
|
88
|
+
if (urlParams.get("lang") !== null && urlParams.get("lang") !== undefined) {
|
|
89
|
+
Properties.instance.config.lang = urlParams.get("lang");
|
|
91
90
|
}
|
|
92
|
-
if (urlParams.get(
|
|
93
|
-
Properties.instance.config.viewer =
|
|
91
|
+
if (urlParams.get("viewer") !== null && urlParams.get("viewer") !== undefined) {
|
|
92
|
+
Properties.instance.config.viewer = urlParams.get("viewer") as Viewer;
|
|
94
93
|
}
|
|
95
|
-
if (urlParams.get(
|
|
96
|
-
Properties.instance.config.zoom = +urlParams.get(
|
|
94
|
+
if (urlParams.get("zoom") !== null && urlParams.get("zoom") !== undefined) {
|
|
95
|
+
Properties.instance.config.zoom = +urlParams.get("zoom");
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
|
|
@@ -102,14 +101,16 @@ export class Properties {
|
|
|
102
101
|
// Get backend parameters calling the configurationjson service
|
|
103
102
|
try {
|
|
104
103
|
Properties.instance.config.backendConfig = await configurationJson(
|
|
105
|
-
[
|
|
104
|
+
["wirispluginperformance", "wiriseditormathmlattribute", "wiriscustomheaders"],
|
|
106
105
|
Properties.instance.editorServicesRoot,
|
|
107
|
-
Properties.instance.editorServicesExtension
|
|
106
|
+
Properties.instance.editorServicesExtension,
|
|
108
107
|
);
|
|
109
108
|
|
|
110
|
-
// We'll always get a string from the wiriscustomheaders backend parameter. It needs to be converted to an object.
|
|
111
|
-
Properties.instance.config.backendConfig.wiriscustomheaders = Util.convertStringToObject(
|
|
112
|
-
|
|
109
|
+
// We'll always get a string from the wiriscustomheaders backend parameter. It needs to be converted to an object.
|
|
110
|
+
Properties.instance.config.backendConfig.wiriscustomheaders = Util.convertStringToObject(
|
|
111
|
+
Properties.instance.config.backendConfig.wiriscustomheaders,
|
|
112
|
+
);
|
|
113
|
+
} catch (e) {
|
|
113
114
|
if (e instanceof StatusError) {
|
|
114
115
|
// Do nothing; leave default values.
|
|
115
116
|
console.error(e);
|
|
@@ -124,22 +125,21 @@ export class Properties {
|
|
|
124
125
|
* @deprecated This will be removed once the viewer uncouple from the integration services.
|
|
125
126
|
*/
|
|
126
127
|
private checkServices(): void {
|
|
127
|
-
const path = (
|
|
128
|
+
const path = (document.currentScript as HTMLScriptElement).src;
|
|
128
129
|
|
|
129
|
-
if (path.includes(
|
|
130
|
+
if (path.includes("pluginwiris_engine")) {
|
|
130
131
|
// If the path includes pluginwiris_engine use Java Integrations Services
|
|
131
132
|
this.config.editorServicesRoot = path;
|
|
132
|
-
this.config.editorServicesExtension =
|
|
133
|
-
} else if (path.includes(
|
|
133
|
+
this.config.editorServicesExtension = "";
|
|
134
|
+
} else if (path.includes("integration/WIRISplugins")) {
|
|
134
135
|
// If the path includes 'integration/WIRISplugins' use PHP Integrations Services
|
|
135
136
|
this.config.editorServicesRoot = path;
|
|
136
|
-
this.config.editorServicesExtension =
|
|
137
|
+
this.config.editorServicesExtension = ".php";
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
get editorServicesRoot(): string {
|
|
141
|
-
return this.config.editorServicesRoot ||
|
|
142
|
-
defaultValues.editorServicesRoot;
|
|
142
|
+
return this.config.editorServicesRoot || defaultValues.editorServicesRoot;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
set editorServicesRoot(editorServicesRoot: string) {
|
|
@@ -148,8 +148,7 @@ export class Properties {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
get editorServicesExtension(): string {
|
|
151
|
-
return this.config.editorServicesExtension ||
|
|
152
|
-
defaultValues.editorServicesExtension;
|
|
151
|
+
return this.config.editorServicesExtension || defaultValues.editorServicesExtension;
|
|
153
152
|
}
|
|
154
153
|
|
|
155
154
|
set editorServicesExtension(editorServicesExtension: string) {
|
|
@@ -167,11 +166,8 @@ export class Properties {
|
|
|
167
166
|
* @returns {string} Encoded language string.
|
|
168
167
|
*/
|
|
169
168
|
get lang(): string {
|
|
170
|
-
const configLang =
|
|
171
|
-
return configLang ||
|
|
172
|
-
document.getElementsByTagName('html')[0].lang ||
|
|
173
|
-
navigator.language ||
|
|
174
|
-
defaultValues.lang;
|
|
169
|
+
const configLang = this.config.lang === "inherit" ? null : this.config.lang;
|
|
170
|
+
return configLang || document.getElementsByTagName("html")[0].lang || navigator.language || defaultValues.lang;
|
|
175
171
|
}
|
|
176
172
|
|
|
177
173
|
set lang(lang: string) {
|
|
@@ -186,8 +182,7 @@ export class Properties {
|
|
|
186
182
|
* - none, by default.
|
|
187
183
|
*/
|
|
188
184
|
get viewer(): Viewer {
|
|
189
|
-
return this.config.viewer ||
|
|
190
|
-
defaultValues.viewer;
|
|
185
|
+
return this.config.viewer || defaultValues.viewer;
|
|
191
186
|
}
|
|
192
187
|
|
|
193
188
|
set viewer(viewer: Viewer) {
|
|
@@ -202,8 +197,7 @@ export class Properties {
|
|
|
202
197
|
* - 96, by default.
|
|
203
198
|
*/
|
|
204
199
|
get dpi(): number {
|
|
205
|
-
return this.config.dpi ||
|
|
206
|
-
defaultValues.dpi;
|
|
200
|
+
return this.config.dpi || defaultValues.dpi;
|
|
207
201
|
}
|
|
208
202
|
|
|
209
203
|
set dpi(dpi: number) {
|
|
@@ -218,8 +212,7 @@ export class Properties {
|
|
|
218
212
|
* - 1, by default.
|
|
219
213
|
*/
|
|
220
214
|
get zoom(): number {
|
|
221
|
-
return this.config.zoom ||
|
|
222
|
-
defaultValues.zoom;
|
|
215
|
+
return this.config.zoom || defaultValues.zoom;
|
|
223
216
|
}
|
|
224
217
|
|
|
225
218
|
set zoom(zoom: number) {
|
|
@@ -234,8 +227,7 @@ export class Properties {
|
|
|
234
227
|
* - 'body', by default.
|
|
235
228
|
*/
|
|
236
229
|
get element(): string {
|
|
237
|
-
return this.config.element ||
|
|
238
|
-
defaultValues.element;
|
|
230
|
+
return this.config.element || defaultValues.element;
|
|
239
231
|
}
|
|
240
232
|
|
|
241
233
|
set element(element: string) {
|
|
@@ -250,8 +242,7 @@ export class Properties {
|
|
|
250
242
|
* - true, by default.
|
|
251
243
|
*/
|
|
252
244
|
get wirispluginperformance(): Wirispluginperformance {
|
|
253
|
-
return this.config.backendConfig.wirispluginperformance ||
|
|
254
|
-
defaultValues.backendConfig.wirispluginperformance;
|
|
245
|
+
return this.config.backendConfig.wirispluginperformance || defaultValues.backendConfig.wirispluginperformance;
|
|
255
246
|
}
|
|
256
247
|
|
|
257
248
|
set wirispluginperformance(wirispluginperformance: Wirispluginperformance) {
|
|
@@ -266,8 +257,9 @@ export class Properties {
|
|
|
266
257
|
* - data-mathml, by default.
|
|
267
258
|
*/
|
|
268
259
|
get wiriseditormathmlattribute(): string {
|
|
269
|
-
return
|
|
270
|
-
defaultValues.backendConfig.wiriseditormathmlattribute
|
|
260
|
+
return (
|
|
261
|
+
this.config.backendConfig.wiriseditormathmlattribute || defaultValues.backendConfig.wiriseditormathmlattribute
|
|
262
|
+
);
|
|
271
263
|
}
|
|
272
264
|
|
|
273
265
|
set wiriseditormathmlattribute(wiriseditormathmlattribute: string) {
|
package/src/retro.ts
CHANGED
|
@@ -11,19 +11,19 @@ import { Properties } from "./properties";
|
|
|
11
11
|
export function bypassEncapsulation(properties: Properties, w: Window) {
|
|
12
12
|
const wany = w as any;
|
|
13
13
|
|
|
14
|
-
if (typeof wany.com ===
|
|
14
|
+
if (typeof wany.com === "undefined") {
|
|
15
15
|
wany.com = {};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
if (typeof wany.com.wiris ===
|
|
18
|
+
if (typeof wany.com.wiris === "undefined") {
|
|
19
19
|
wany.com.wiris = {};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
if (typeof wany.com.wiris.js ===
|
|
22
|
+
if (typeof wany.com.wiris.js === "undefined") {
|
|
23
23
|
wany.com.wiris.js = {};
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
if (typeof wany.com.wiris.js.JsPluginViewer ===
|
|
26
|
+
if (typeof wany.com.wiris.js.JsPluginViewer === "undefined") {
|
|
27
27
|
wany.com.wiris.js.JsPluginViewer = JsPluginViewer.getInstance();
|
|
28
28
|
JsPluginViewer.properties = properties;
|
|
29
29
|
}
|
|
@@ -122,7 +122,6 @@ class JsPluginViewer {
|
|
|
122
122
|
var doubleQuoteEntity = safeXMLCharactersEntities.doubleQuote;
|
|
123
123
|
var realDoubleQuoteEntity = safeXMLCharactersEntities.realDoubleQuote;
|
|
124
124
|
|
|
125
|
-
|
|
126
125
|
// Important to not change function parameter.
|
|
127
126
|
var inputCopy = input.slice();
|
|
128
127
|
|
|
@@ -148,25 +147,26 @@ class JsPluginViewer {
|
|
|
148
147
|
|
|
149
148
|
// We are replacing $ by & when its part of an entity for retrocompatibility.
|
|
150
149
|
// Now, the standard is replace § by &.
|
|
151
|
-
var returnValue =
|
|
150
|
+
var returnValue = "";
|
|
152
151
|
var currentEntity = null;
|
|
153
152
|
|
|
154
153
|
var i = 0;
|
|
155
154
|
while (i < inputCopy.length) {
|
|
156
155
|
var character = inputCopy.charAt(i);
|
|
157
156
|
if (currentEntity == null) {
|
|
158
|
-
if (character ==
|
|
159
|
-
currentEntity =
|
|
157
|
+
if (character == "$") {
|
|
158
|
+
currentEntity = "";
|
|
160
159
|
} else {
|
|
161
160
|
returnValue += character;
|
|
162
161
|
}
|
|
163
|
-
} else if (character ==
|
|
164
|
-
returnValue +=
|
|
162
|
+
} else if (character == ";") {
|
|
163
|
+
returnValue += "&" + currentEntity;
|
|
165
164
|
currentEntity = null;
|
|
166
|
-
} else if (character.match(/([a-zA-Z0-9#._-] | '-')/)) {
|
|
165
|
+
} else if (character.match(/([a-zA-Z0-9#._-] | '-')/)) {
|
|
166
|
+
// Character is part of an entity.
|
|
167
167
|
currentEntity += character;
|
|
168
168
|
} else {
|
|
169
|
-
returnValue +=
|
|
169
|
+
returnValue += "$" + "currentEntity"; // Is not an entity.
|
|
170
170
|
currentEntity = null;
|
|
171
171
|
i -= 1; // Parse again the current character.
|
|
172
172
|
}
|
|
@@ -191,66 +191,65 @@ class JsPluginViewer {
|
|
|
191
191
|
|
|
192
192
|
private static getMathMLPositionsAtNode(node: Node, mathmlPositions) {
|
|
193
193
|
var safeXMLCharacters = JsCharacters.getSafeXMLCharacters();
|
|
194
|
-
if(node.nodeType == 3) {
|
|
194
|
+
if (node.nodeType == 3) {
|
|
195
195
|
var startMathmlTag = safeXMLCharacters.tagOpener + "math";
|
|
196
196
|
var endMathmlTag = safeXMLCharacters.tagOpener + "/math" + safeXMLCharacters.tagCloser;
|
|
197
197
|
var start = node.textContent.indexOf(startMathmlTag);
|
|
198
198
|
var end = 0;
|
|
199
|
-
while(start != -1) {
|
|
200
|
-
end = node.textContent.indexOf(endMathmlTag,start + startMathmlTag.length);
|
|
199
|
+
while (start != -1) {
|
|
200
|
+
end = node.textContent.indexOf(endMathmlTag, start + startMathmlTag.length);
|
|
201
201
|
|
|
202
|
-
if(end == -1) break;
|
|
202
|
+
if (end == -1) break;
|
|
203
203
|
|
|
204
|
-
var nextMathML = node.textContent.indexOf(startMathmlTag,end + endMathmlTag.length);
|
|
204
|
+
var nextMathML = node.textContent.indexOf(startMathmlTag, end + endMathmlTag.length);
|
|
205
205
|
|
|
206
|
-
if(nextMathML >= 0 && end > nextMathML) break;
|
|
206
|
+
if (nextMathML >= 0 && end > nextMathML) break;
|
|
207
207
|
|
|
208
|
-
var safeMathml = node.textContent.substring(start,end + endMathmlTag.length);
|
|
208
|
+
var safeMathml = node.textContent.substring(start, end + endMathmlTag.length);
|
|
209
209
|
|
|
210
|
-
node.textContent = node.textContent.substring(0,start) + node.textContent.substring(end + endMathmlTag.length);
|
|
210
|
+
node.textContent = node.textContent.substring(0, start) + node.textContent.substring(end + endMathmlTag.length);
|
|
211
211
|
node = (node as Text).splitText(start);
|
|
212
212
|
start = node.textContent.indexOf(startMathmlTag);
|
|
213
213
|
|
|
214
214
|
mathmlPositions.push({
|
|
215
215
|
safeMML: safeMathml,
|
|
216
|
-
nextElement: node
|
|
216
|
+
nextElement: node,
|
|
217
217
|
});
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
|
|
222
221
|
}
|
|
223
222
|
|
|
224
223
|
class JsCharacters {
|
|
225
224
|
static getSafeXMLCharactersEntities(): any {
|
|
226
225
|
return {
|
|
227
|
-
tagOpener:
|
|
228
|
-
tagCloser:
|
|
229
|
-
doubleQuote:
|
|
230
|
-
realDoubleQuote:
|
|
226
|
+
tagOpener: "«",
|
|
227
|
+
tagCloser: "»",
|
|
228
|
+
doubleQuote: "¨",
|
|
229
|
+
realDoubleQuote: """,
|
|
231
230
|
};
|
|
232
231
|
}
|
|
233
232
|
|
|
234
233
|
static getXMLCharacters(): any {
|
|
235
234
|
return {
|
|
236
|
-
id:
|
|
237
|
-
tagOpener:
|
|
238
|
-
tagCloser:
|
|
235
|
+
id: "xmlCharacters",
|
|
236
|
+
tagOpener: "<", // Hex: \x3C.
|
|
237
|
+
tagCloser: ">", // Hex: \x3E.
|
|
239
238
|
doubleQuote: '"', // Hex: \x22.
|
|
240
|
-
ampersand:
|
|
241
|
-
quote: '
|
|
239
|
+
ampersand: "&", // Hex: \x26.
|
|
240
|
+
quote: "'", // Hex: \x27.
|
|
242
241
|
};
|
|
243
242
|
}
|
|
244
243
|
|
|
245
244
|
static getSafeXMLCharacters(): any {
|
|
246
245
|
return {
|
|
247
|
-
id:
|
|
248
|
-
tagOpener:
|
|
249
|
-
tagCloser:
|
|
250
|
-
doubleQuote:
|
|
251
|
-
ampersand:
|
|
252
|
-
quote:
|
|
253
|
-
realDoubleQuote:
|
|
246
|
+
id: "safeXmlCharacters",
|
|
247
|
+
tagOpener: "«", // Hex: \xAB.
|
|
248
|
+
tagCloser: "»", // Hex: \xBB.
|
|
249
|
+
doubleQuote: "¨", // Hex: \xA8.
|
|
250
|
+
ampersand: "§", // Hex: \xA7.
|
|
251
|
+
quote: "`", // Hex: \x60.
|
|
252
|
+
realDoubleQuote: "¨",
|
|
254
253
|
};
|
|
255
254
|
}
|
|
256
255
|
}
|
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,25 @@ 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
|
const properties = Properties.getInstance();
|
|
55
61
|
const headers = {
|
|
56
|
-
|
|
57
|
-
...properties.config.backendConfig.wiriscustomheaders
|
|
58
|
-
}
|
|
62
|
+
"Content-type": "application/x-www-form-urlencoded; charset=utf-8",
|
|
63
|
+
...properties.config.backendConfig.wiriscustomheaders,
|
|
64
|
+
};
|
|
59
65
|
|
|
60
66
|
const init: RequestInit = {
|
|
61
67
|
method,
|
|
62
|
-
headers
|
|
68
|
+
headers,
|
|
63
69
|
};
|
|
64
70
|
|
|
65
71
|
if (method === MethodType.Get) {
|
|
@@ -69,11 +75,11 @@ export async function callService(query: object, serviceName: string, method: Me
|
|
|
69
75
|
}
|
|
70
76
|
} else {
|
|
71
77
|
// Add the query as the body of the request
|
|
72
|
-
init.body = new URLSearchParams({...query});
|
|
78
|
+
init.body = new URLSearchParams({ ...query });
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
return fetch(url.toString(), init);
|
|
76
|
-
} catch(e) {
|
|
82
|
+
} catch (e) {
|
|
77
83
|
// TODO manage network and status non-ok errors
|
|
78
84
|
throw e;
|
|
79
85
|
}
|
|
@@ -87,18 +93,18 @@ export async function callService(query: object, serviceName: string, method: Me
|
|
|
87
93
|
* @param {string} extension - Extension to add to the end of the serviceName (including the dot if necessary).
|
|
88
94
|
* @returns {Promise<Response>} The mathml2accessible service response.
|
|
89
95
|
*/
|
|
90
|
-
export async function mathml2accessible(mml: string, lang: string, url: string, extension: string)
|
|
96
|
+
export async function mathml2accessible(mml: string, lang: string, url: string, extension: string): Promise<any> {
|
|
91
97
|
// Set the needed params to retrieve the alt text.
|
|
92
98
|
const params = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const response = callService(params,
|
|
99
|
+
service: "mathml2accessible",
|
|
100
|
+
mml: mml,
|
|
101
|
+
metrics: "true",
|
|
102
|
+
centerbaseline: "false",
|
|
103
|
+
lang: lang,
|
|
104
|
+
ignoreStyles: "true",
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const response = callService(params, "service", MethodType.Post, url, extension);
|
|
102
108
|
return processJsonResponse(response);
|
|
103
109
|
}
|
|
104
110
|
|
|
@@ -112,18 +118,18 @@ export async function mathml2accessible(mml: string, lang: string, url: string,
|
|
|
112
118
|
*/
|
|
113
119
|
export async function showImage(mml: string, lang: string, url: string, extension: string): Promise<any> {
|
|
114
120
|
const params = {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
121
|
+
mml: mml,
|
|
122
|
+
metrics: "true",
|
|
123
|
+
centerbaseline: "false",
|
|
124
|
+
lang: lang,
|
|
125
|
+
};
|
|
120
126
|
|
|
121
127
|
// Try to obtain the image via GET
|
|
122
128
|
const getParams = Parser.createShowImageSrcData(params, params.lang);
|
|
123
|
-
const getResponse = callService(getParams,
|
|
129
|
+
const getResponse = callService(getParams, "showimage", MethodType.Get, url, extension);
|
|
124
130
|
try {
|
|
125
131
|
return await processJsonResponse(getResponse);
|
|
126
|
-
} catch(e) {
|
|
132
|
+
} catch (e) {
|
|
127
133
|
if (e instanceof StatusError) {
|
|
128
134
|
// Formula was not in cache; proceed with calling showimage via POST
|
|
129
135
|
} else {
|
|
@@ -132,10 +138,9 @@ export async function showImage(mml: string, lang: string, url: string, extensio
|
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
// If GET request fails, it means that the formula was not in cache. Proceed with POST:
|
|
135
|
-
const response = callService(params,
|
|
141
|
+
const response = callService(params, "showimage", MethodType.Post, url, extension);
|
|
136
142
|
return processJsonResponse(response);
|
|
137
|
-
|
|
138
|
-
};
|
|
143
|
+
}
|
|
139
144
|
|
|
140
145
|
/**
|
|
141
146
|
* Calls the createImage service with the given MathML and returns the received Response object.
|
|
@@ -147,15 +152,16 @@ export async function showImage(mml: string, lang: string, url: string, extensio
|
|
|
147
152
|
*/
|
|
148
153
|
export async function createImage(mml: string, lang: string, url: string, extension: string): Promise<any> {
|
|
149
154
|
const params = {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
mml: mml,
|
|
156
|
+
metrics: "true",
|
|
157
|
+
centerbaseline: "false",
|
|
158
|
+
lang: lang,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// POST request to retrieve the corresponding image.
|
|
162
|
+
const response = callService(params, "showimage", MethodType.Post, url, extension);
|
|
163
|
+
return processJsonResponse(response);
|
|
164
|
+
}
|
|
159
165
|
|
|
160
166
|
/**
|
|
161
167
|
* Calls the latex2mathml service with the given LaTeX and returns the received Response object.
|
|
@@ -166,11 +172,11 @@ export async function createImage(mml: string, lang: string, url: string, extens
|
|
|
166
172
|
*/
|
|
167
173
|
export async function latexToMathml(latex: string, url: string, extension: string): Promise<any> {
|
|
168
174
|
const params = {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
175
|
+
service: "latex2mathml",
|
|
176
|
+
latex: latex,
|
|
177
|
+
};
|
|
172
178
|
|
|
173
|
-
const response = callService(params,
|
|
179
|
+
const response = callService(params, "service", MethodType.Post, url, extension);
|
|
174
180
|
return processJsonResponse(response);
|
|
175
181
|
}
|
|
176
182
|
|
|
@@ -180,11 +186,11 @@ export async function latexToMathml(latex: string, url: string, extension: strin
|
|
|
180
186
|
* @param {string} extension - Extension to add to the end of the serviceName (including the dot if necessary).
|
|
181
187
|
* @returns {Promise<Response>} The configurationjson service response.
|
|
182
188
|
*/
|
|
183
|
-
export async function configurationJson(variablekeys: string[], url: string, extension: string)
|
|
189
|
+
export async function configurationJson(variablekeys: string[], url: string, extension: string): Promise<any> {
|
|
184
190
|
const params = {
|
|
185
|
-
|
|
186
|
-
}
|
|
191
|
+
variablekeys: variablekeys.join(","),
|
|
192
|
+
};
|
|
187
193
|
|
|
188
|
-
const response = callService(params,
|
|
194
|
+
const response = callService(params, "configurationjson", MethodType.Get, url, extension);
|
|
189
195
|
return processJsonResponse(response);
|
|
190
196
|
}
|