@wiris/mathtype-viewer 1.2.0 → 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.
@@ -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/app.d.ts CHANGED
@@ -1,2 +1,10 @@
1
- export {};
1
+ import { Properties } from './properties';
2
+ declare global {
3
+ interface Window {
4
+ viewer: {
5
+ properties: Properties;
6
+ isLoaded: boolean;
7
+ };
8
+ }
9
+ }
2
10
  //# sourceMappingURL=app.d.ts.map
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,EAAE;YACN,UAAU,EAAE,UAAU,CAAC;YACvB,QAAQ,EAAE,OAAO,CAAA;SAClB,CAAC;KACH;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"mathml.d.ts","sourceRoot":"","sources":["../src/mathml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAmB1C,wBAAsB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B3F"}
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"}
@@ -18,6 +18,7 @@ export declare class Properties {
18
18
  config: Config;
19
19
  private new;
20
20
  static generate(): Promise<Properties>;
21
+ private checkServices;
21
22
  get editorServicesRoot(): string;
22
23
  set editorServicesRoot(editorServicesRoot: string);
23
24
  get editorServicesExtension(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../src/properties.ts"],"names":[],"mappings":"AAGA,aAAK,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AACpD,aAAK,sBAAsB,GAAG,MAAM,GAAG,OAAO,CAAC;AAK/C,oBAAY,MAAM,GAAG;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,EAAE;QACd,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;QAChD,0BAA0B,CAAC,EAAE,MAAM,CAAC;KACrC,CAAC;IACF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAsBF,qBAAa,UAAU;IAErB,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAkB;IAG7C,MAAM,EAAE,MAAM,CAAiB;IAM/B,OAAO,CAAC,GAAG;WAKE,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;IAmD5C,IAAI,kBAAkB,IAAI,MAAM,CAG/B;IAED,IAAI,kBAAkB,CAAC,kBAAkB,EAAE,MAAM,EAGhD;IAED,IAAI,uBAAuB,IAAI,MAAM,CAGpC;IAED,IAAI,uBAAuB,CAAC,uBAAuB,EAAE,MAAM,EAG1D;IAWD,IAAI,IAAI,IAAI,MAAM,CAMjB;IAED,IAA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,IAAI,CAAC,CAAkB;IAG7C,MAAM,EAAE,MAAM,CAAiB;IAM/B,OAAO,CAAC,GAAG;WAKE,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;IAuD5C,OAAO,CAAC,aAAa;IAcrB,IAAI,kBAAkB,IAAI,MAAM,CAG/B;IAED,IAAI,kBAAkB,CAAC,kBAAkB,EAAE,MAAM,EAGhD;IAED,IAAI,uBAAuB,IAAI,MAAM,CAGpC;IAED,IAAI,uBAAuB,CAAC,uBAAuB,EAAE,MAAM,EAG1D;IAWD,IAAI,IAAI,IAAI,MAAM,CAMjB;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAGpB;IAQD,IAAI,MAAM,IAAI,MAAM,CAGnB;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAGxB;IAQD,IAAI,GAAG,IAAI,MAAM,CAGhB;IAED,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,EAGlB;IAQD,IAAI,IAAI,IAAI,MAAM,CAGjB;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAGpB;IAQD,IAAI,OAAO,IAAI,MAAM,CAGpB;IAED,IAAI,OAAO,CAAC,OAAO,EAAE,MAAM,EAG1B;IAQD,IAAI,sBAAsB,IAAI,sBAAsB,CAGnD;IAED,IAAI,sBAAsB,CAAC,sBAAsB,EAAE,sBAAsB,EAGxE;IAQD,IAAI,0BAA0B,IAAI,MAAM,CAGvC;IAED,IAAI,0BAA0B,CAAC,0BAA0B,EAAE,MAAM,EAGhE;CACF"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@wiris/mathtype-viewer",
3
- "version": "1.2.0",
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.14.0"
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/app.ts CHANGED
@@ -3,6 +3,15 @@ import { renderLatex } from './latex';
3
3
  import { renderMathML } from './mathml';
4
4
  import { bypassEncapsulation } from './retro';
5
5
 
6
+ declare global {
7
+ interface Window {
8
+ viewer: {
9
+ properties: Properties,
10
+ isLoaded: boolean
11
+ };
12
+ }
13
+ }
14
+
6
15
  // This should be the only code executed outside of a function
7
16
  // and the only code containing browser globals (e.g. window)
8
17
  // TODO try to set up the linter to check these two constraints
@@ -17,9 +26,12 @@ async function main(w: Window): Promise<void> {
17
26
  const properties: Properties = await Properties.generate();
18
27
 
19
28
  // Expose the globals to the browser
20
- (w as any).viewer = {
21
- properties,
22
- };
29
+ if (!w.viewer) {
30
+ w.viewer = {
31
+ properties,
32
+ isLoaded: false,
33
+ };
34
+ }
23
35
 
24
36
  const document = w.document;
25
37
 
@@ -40,6 +52,11 @@ async function main(w: Window): Promise<void> {
40
52
  // Initial function to call once document is loaded
41
53
  // Renders formulas and sets observer
42
54
  const start = async () => {
55
+ // Check if the viewer is alredy loaded
56
+ if (w.viewer.isLoaded) return;
57
+
58
+ w.viewer.isLoaded = true;
59
+
43
60
  // First render
44
61
  properties.render();
45
62
 
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/src/properties.ts CHANGED
@@ -66,7 +66,6 @@ export class Properties {
66
66
  const script: HTMLScriptElement = document.querySelector(`script[src*="${pluginName}"]`);
67
67
 
68
68
  if (!!script) {
69
-
70
69
  const pluginNamePosition: number = script.src.lastIndexOf(pluginName);
71
70
  const params: string = script.src.substring(pluginNamePosition + pluginName.length);
72
71
  const urlParams = new URLSearchParams(params);
@@ -86,9 +85,10 @@ export class Properties {
86
85
  if (urlParams.get('zoom') !== null && urlParams.get('zoom') !== undefined) {
87
86
  instance.config.zoom = +urlParams.get('zoom');
88
87
  }
89
-
90
88
  }
91
89
 
90
+ instance.checkServices();
91
+
92
92
  // Get backend parameters calling the configurationjson service
93
93
  try {
94
94
  instance.config.backendConfig = await configurationJson(
@@ -108,6 +108,24 @@ export class Properties {
108
108
  return instance;
109
109
  }
110
110
 
111
+ /**
112
+ * Check if is inside Integrations Services
113
+ * @deprecated This will be removed once the viewer uncouple from the integration services.
114
+ */
115
+ private checkServices(): void {
116
+ const path = ((document.currentScript as HTMLScriptElement).src);
117
+
118
+ if (path.includes('pluginwiris_engine')) {
119
+ // If the path includes pluginwiris_engine use Java Integrations Services
120
+ this.config.editorServicesRoot = path;
121
+ this.config.editorServicesExtension = '';
122
+ } else if (path.includes('integration/WIRISplugins')) {
123
+ // If the path includes 'integration/WIRISplugins' use PHP Integrations Services
124
+ this.config.editorServicesRoot = path;
125
+ this.config.editorServicesExtension = '.php';
126
+ }
127
+ }
128
+
111
129
  get editorServicesRoot(): string {
112
130
  return this.config.editorServicesRoot ||
113
131
  defaultValues.editorServicesRoot;
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: 'development',
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
  };