@pie-element/ebsr 7.0.22 → 7.0.24-next.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.
Files changed (144) hide show
  1. package/CHANGELOG.md +0 -16
  2. package/configure/CHANGELOG.md +0 -16
  3. package/configure/lib/main.js +6 -4
  4. package/configure/lib/main.js.map +1 -1
  5. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +1972 -0
  6. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +1793 -0
  7. package/{LICENSE.md → configure/node_modules/@pie-element/multiple-choice/LICENSE.md} +0 -0
  8. package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +35 -0
  9. package/configure/node_modules/@pie-element/multiple-choice/README.md +56 -0
  10. package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
  11. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +1387 -0
  12. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +1334 -0
  13. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +104 -0
  14. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +1 -0
  15. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +198 -0
  16. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +1 -0
  17. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +599 -0
  18. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +1 -0
  19. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +18 -0
  20. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +1 -0
  21. package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +20 -0
  22. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +527 -0
  23. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +768 -0
  24. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +18 -0
  25. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +1 -0
  26. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +305 -0
  27. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +1 -0
  28. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +36 -0
  29. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +1 -0
  30. package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +15 -0
  31. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +353 -0
  32. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +277 -0
  33. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +8 -0
  34. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +52 -0
  35. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +1 -0
  36. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +7 -0
  37. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +338 -0
  38. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +274 -0
  39. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +298 -0
  40. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +1 -0
  41. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +157 -0
  42. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +1 -0
  43. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +174 -0
  44. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +1 -0
  45. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +151 -0
  46. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +1 -0
  47. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +97 -0
  48. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +1 -0
  49. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +254 -0
  50. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +1 -0
  51. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +129 -0
  52. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +1 -0
  53. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +35 -0
  54. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +1 -0
  55. package/configure/node_modules/@pie-element/multiple-choice/module/configure.js +843 -0
  56. package/{module → configure/node_modules/@pie-element/multiple-choice/module}/controller.js +17304 -17374
  57. package/configure/node_modules/@pie-element/multiple-choice/module/demo.js +77 -0
  58. package/{module → configure/node_modules/@pie-element/multiple-choice/module}/element.js +42 -171
  59. package/{module → configure/node_modules/@pie-element/multiple-choice/module}/index.html +1 -1
  60. package/{module → configure/node_modules/@pie-element/multiple-choice/module}/manifest.json +4 -4
  61. package/{module → configure/node_modules/@pie-element/multiple-choice/module}/print-demo.js +46 -46
  62. package/{module → configure/node_modules/@pie-element/multiple-choice/module}/print.html +1 -1
  63. package/{module → configure/node_modules/@pie-element/multiple-choice/module}/print.js +70 -259
  64. package/configure/node_modules/@pie-element/multiple-choice/package.json +34 -0
  65. package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.json +672 -0
  66. package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.md +427 -0
  67. package/configure/node_modules/@pie-lib/math-rendering/LICENSE.md +5 -0
  68. package/configure/node_modules/@pie-lib/math-rendering/lib/index.js +30 -0
  69. package/configure/node_modules/@pie-lib/math-rendering/lib/index.js.map +1 -0
  70. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js +316 -0
  71. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js.map +1 -0
  72. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js +23 -0
  73. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js.map +1 -0
  74. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js +123 -0
  75. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js.map +1 -0
  76. package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js +103 -0
  77. package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js.map +1 -0
  78. package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js +275 -0
  79. package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js.map +1 -0
  80. package/configure/node_modules/@pie-lib/math-rendering/package.json +19 -0
  81. package/configure/node_modules/@pie-lib/math-rendering/playground/demo.html +872 -0
  82. package/configure/node_modules/@pie-lib/math-rendering/playground/demo.js +108 -0
  83. package/configure/node_modules/@pie-lib/math-rendering/playground/main.html +156 -0
  84. package/configure/node_modules/@pie-lib/math-rendering/playground/main.js +16 -0
  85. package/configure/node_modules/@pie-lib/math-rendering/playground/webpack.config.js +29 -0
  86. package/configure/node_modules/@pie-lib/math-rendering/src/index.js +4 -0
  87. package/configure/node_modules/@pie-lib/math-rendering/src/mstack/chtml.js +215 -0
  88. package/configure/node_modules/@pie-lib/math-rendering/src/mstack/index.js +13 -0
  89. package/configure/node_modules/@pie-lib/math-rendering/src/mstack/mml.js +24 -0
  90. package/configure/node_modules/@pie-lib/math-rendering/src/normalization.js +69 -0
  91. package/configure/node_modules/@pie-lib/math-rendering/src/render-math.js +234 -0
  92. package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.json +937 -0
  93. package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.md +602 -0
  94. package/configure/node_modules/@pie-lib/render-ui/LICENSE.md +5 -0
  95. package/configure/node_modules/@pie-lib/render-ui/README.md +33 -0
  96. package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js +146 -0
  97. package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js.map +1 -0
  98. package/configure/node_modules/@pie-lib/render-ui/lib/color.js +134 -0
  99. package/configure/node_modules/@pie-lib/render-ui/lib/color.js.map +1 -0
  100. package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js +160 -0
  101. package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js.map +1 -0
  102. package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js +24 -0
  103. package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js.map +1 -0
  104. package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js +102 -0
  105. package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js.map +1 -0
  106. package/configure/node_modules/@pie-lib/render-ui/lib/index.js +104 -0
  107. package/configure/node_modules/@pie-lib/render-ui/lib/index.js.map +1 -0
  108. package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js +60 -0
  109. package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js.map +1 -0
  110. package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js +133 -0
  111. package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js.map +1 -0
  112. package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js +162 -0
  113. package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js.map +1 -0
  114. package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js +28 -0
  115. package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js.map +1 -0
  116. package/configure/node_modules/@pie-lib/render-ui/lib/readable.js +28 -0
  117. package/configure/node_modules/@pie-lib/render-ui/lib/readable.js.map +1 -0
  118. package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js +160 -0
  119. package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js.map +1 -0
  120. package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js +206 -0
  121. package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js.map +1 -0
  122. package/configure/node_modules/@pie-lib/render-ui/package.json +30 -0
  123. package/configure/node_modules/@pie-lib/render-ui/src/collapsible/index.jsx +68 -0
  124. package/configure/node_modules/@pie-lib/render-ui/src/color.js +48 -0
  125. package/configure/node_modules/@pie-lib/render-ui/src/feedback.jsx +100 -0
  126. package/configure/node_modules/@pie-lib/render-ui/src/has-text.js +14 -0
  127. package/configure/node_modules/@pie-lib/render-ui/src/html-and-math.js +40 -0
  128. package/configure/node_modules/@pie-lib/render-ui/src/index.js +27 -0
  129. package/configure/node_modules/@pie-lib/render-ui/src/input-container.jsx +41 -0
  130. package/configure/node_modules/@pie-lib/render-ui/src/preview-layout.jsx +77 -0
  131. package/configure/node_modules/@pie-lib/render-ui/src/preview-prompt.jsx +90 -0
  132. package/configure/node_modules/@pie-lib/render-ui/src/purpose.jsx +19 -0
  133. package/configure/node_modules/@pie-lib/render-ui/src/readable.jsx +19 -0
  134. package/configure/node_modules/@pie-lib/render-ui/src/response-indicators.jsx +89 -0
  135. package/configure/node_modules/@pie-lib/render-ui/src/withUndoReset.jsx +118 -0
  136. package/configure/package.json +3 -3
  137. package/configure/src/__tests__/index.test.js +4 -2
  138. package/configure/src/main.jsx +8 -3
  139. package/controller/lib/index.js +79 -3
  140. package/controller/lib/index.js.map +1 -1
  141. package/controller/src/index.js +55 -0
  142. package/package.json +3 -3
  143. package/module/configure.js +0 -472
  144. package/module/demo.js +0 -77
@@ -0,0 +1,108 @@
1
+ console.log('demo');
2
+ // import { renderMath } from '../lib/index';
3
+
4
+ // document.addEventListener('DOMContentLoaded', () => {
5
+ // renderMath(document.querySelector('#mathml-node'));
6
+ // });
7
+ /*************************************************************************
8
+ *
9
+ * mj3-mml2html-beta.js
10
+ *
11
+ * Uses MathJax v3 to convert MathML to HTML within a browser page.
12
+ *
13
+ * ----------------------------------------------------------------------
14
+ *
15
+ * Copyright (c) 2018 The MathJax Consortium
16
+ *
17
+ * Licensed under the Apache License, Version 2.0 (the "License");
18
+ * you may not use this file except in compliance with the License.
19
+ * You may obtain a copy of the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software
24
+ * distributed under the License is distributed on an "AS IS" BASIS,
25
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ * See the License for the specific language governing permissions and
27
+ * limitations under the License.
28
+ */
29
+
30
+ const MathJax = require('mathjax3/mathjax3/mathjax.js').MathJax; // MathJax core
31
+ const MathML = require('mathjax3/mathjax3/input/mathml.js').MathML; // MathML input
32
+ const CHTML = require('mathjax3/mathjax3/output/chtml.js').CHTML; // HTML output
33
+ const adaptor = require('mathjax3/mathjax3/adaptors/browserAdaptor').browserAdaptor; // browser DOM
34
+ const PACKAGES = [
35
+ 'action', 'ams',
36
+ 'amscd', 'base',
37
+ 'bbox', 'boldsymbol',
38
+ 'braket', 'bussproofs',
39
+ 'cancel', 'color',
40
+ 'configmacros', 'enclose',
41
+ 'extpfeil', 'html',
42
+ 'mhchem', 'newcommand',
43
+ 'noerrors', 'noundefined',
44
+ 'tagformat', 'textmacros',
45
+ 'unicode', 'verb'
46
+ ]
47
+ //
48
+ // Register the HTML handler with the browser adaptor
49
+ //
50
+ require('mathjax3/mathjax3/handlers/html.js').RegisterHTMLHandler(adaptor());
51
+
52
+ //
53
+ // Get the input and output jax configurations from the user
54
+ //
55
+ const MathJaxConfig = window.MathJaxConfig || {};
56
+
57
+ const mmlConfig = Object.assign({}, MathJaxConfig.MathML || {});
58
+ const htmlConfig = Object.assign(
59
+ {
60
+ fontURL: 'https://cdn.rawgit.com/mathjax/mathjax-v3/3.0.0-beta.1/mathjax2/css'
61
+ },
62
+ MathJaxConfig.HTML || {}
63
+ );
64
+ const texConfig = { packages: PACKAGES, inlineMath: [['$', '$'], ['\\(', '\\)']], processEscapes: true, macros: {
65
+ parallelogram: '\\lower.2em{\\Large\\unicode{x25B1}}' }
66
+ //
67
+ // Initialize mathjax with a DOM document.
68
+ //
69
+ const html = MathJax.document(document, {
70
+ InputJax: [new TeX(texConfig), new MathML(mmlConfig)],
71
+ OutputJax: new CHTML(htmlConfig)
72
+ });
73
+
74
+ //
75
+ // Process the document
76
+ //
77
+ window.MathJax = {
78
+ version: MathJax.version,
79
+ html: html,
80
+ Typeset: function(...elements) {
81
+ this.html
82
+ .findMath(elements.length ? { elements } : {})
83
+ .compile()
84
+ .getMetrics()
85
+ .typeset()
86
+ .updateDocument()
87
+ .clear();
88
+ }
89
+ };
90
+
91
+ //
92
+ // Do the initial typesetting
93
+ //
94
+ if (!MathJaxConfig.skipInitialTypeset) {
95
+ //
96
+ // If the window is already loaded, just call Typeset()
97
+ // Otherwise, set an event listener and run Typeset() when DOM is loaded
98
+ //
99
+ if (document.readyState && document.readyState !== 'loading') {
100
+ window.MathJax.Typeset(...(MathJaxConfig.elements || []));
101
+ } else {
102
+ window.addEventListener(
103
+ 'DOMContentLoaded',
104
+ () => window.MathJax.Typeset(...(MathJaxConfig.elements || [])),
105
+ false
106
+ );
107
+ }
108
+ }
@@ -0,0 +1,156 @@
1
+ <!doctype html>
2
+ <html>
3
+
4
+ <head>
5
+
6
+ <script>
7
+ window.pie = window.pie || {}
8
+ window.pie.mathRendering = { useSingleDollar: false }
9
+ </script>
10
+ <script src="./main.bundle.js"></script>
11
+ </head>
12
+
13
+ <body>
14
+ <div id="mathml-node">
15
+
16
+ <br/>
17
+ <span>inline: \(\frac{1}{2}\)</span>
18
+ <br/> block: <span>\[\frac{1}{2}\]</span>
19
+ <br/>
20
+ <span>single dollar: $\frac{1}{2}$</span>
21
+ <br/>
22
+ <span> double dollar: $$\frac{1}{2}$$</span>
23
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
24
+ <mi>a</mi>
25
+ <mo>&#x2260;</mo>
26
+ <mn>0</mn>
27
+ </math>, there are two solutions to
28
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
29
+ <mi>ab</mi>
30
+ <msup>
31
+ <mi>x</mi>
32
+ <mn>2</mn>
33
+ </msup>
34
+ <mo>+</mo>
35
+ <mi>b</mi>
36
+ <mi>x</mi>
37
+ <mo>+</mo>
38
+ <mi>c</mi>
39
+ <mo>=</mo>
40
+ <mn>0</mn>
41
+ </math> and they are
42
+ <br/>
43
+ <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
44
+ <mi>x</mi>
45
+ <mo>=</mo>
46
+ <mrow>
47
+ <mfrac>
48
+ <mrow>
49
+ <mo>&#x2212;</mo>
50
+ <mi>b</mi>
51
+ <mo>&#x00B1;</mo>
52
+ <msqrt>
53
+ <msup>
54
+ <mi>bfoo bar</mi>
55
+ <mn>2</mn>
56
+ </msup>
57
+ <mo>&#x2212;</mo>
58
+ <mn>4</mn>
59
+ <mi>a</mi>
60
+ <mi>c</mi>
61
+ </msqrt>
62
+ </mrow>
63
+ <mrow>
64
+ <mn>2</mn>
65
+ <mi>a</mi>
66
+ </mrow>
67
+ </mfrac>
68
+ </mrow>
69
+ <mtext>.</mtext>
70
+ </math>
71
+
72
+ <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
73
+ <msup>
74
+ <mrow>
75
+ <mo>(</mo>
76
+ <mrow>
77
+ <munderover>
78
+ <mo>&#x2211;
79
+ <!-- ∑ -->
80
+ </mo>
81
+ <mrow class="MJX-TeXAtom-ORD">
82
+ <mi>k</mi>
83
+ <mo>=</mo>
84
+ <mn>1</mn>
85
+ </mrow>
86
+ <mi>n</mi>
87
+ </munderover>
88
+ <msub>
89
+ <mi>a</mi>
90
+ <mi>k</mi>
91
+ </msub>
92
+ <msub>
93
+ <mi>b</mi>
94
+ <mi>k</mi>
95
+ </msub>
96
+ </mrow>
97
+ <mo>)</mo>
98
+ </mrow>
99
+ <mrow class="MJX-TeXAtom-ORD">
100
+ <mspace width="negativethinmathspace" />
101
+ <mspace width="negativethinmathspace" />
102
+ <mn>2</mn>
103
+ </mrow>
104
+ </msup>
105
+ <mo>&#x2264;
106
+ <!-- ≤ -->
107
+ </mo>
108
+ <mrow>
109
+ <mo>(</mo>
110
+ <mrow>
111
+ <munderover>
112
+ <mo>&#x2211;
113
+ <!-- ∑ -->
114
+ </mo>
115
+ <mrow class="MJX-TeXAtom-ORD">
116
+ <mi>k</mi>
117
+ <mo>=</mo>
118
+ <mn>1</mn>
119
+ </mrow>
120
+ <mi>n</mi>
121
+ </munderover>
122
+ <msubsup>
123
+ <mi>a</mi>
124
+ <mi>k</mi>
125
+ <mn>2</mn>
126
+ </msubsup>
127
+ </mrow>
128
+ <mo>)</mo>
129
+ </mrow>
130
+ <mrow>
131
+ <mo>(</mo>
132
+ <mrow>
133
+ <munderover>
134
+ <mo>&#x2211;
135
+ <!-- ∑ -->
136
+ </mo>
137
+ <mrow class="MJX-TeXAtom-ORD">
138
+ <mi>k</mi>
139
+ <mo>=</mo>
140
+ <mn>1</mn>
141
+ </mrow>
142
+ <mi>n</mi>
143
+ </munderover>
144
+ <msubsup>
145
+ <mi>b</mi>
146
+ <mi>k</mi>
147
+ <mn>2</mn>
148
+ </msubsup>
149
+ </mrow>
150
+ <mo>)</mo>
151
+ </mrow>
152
+ </math>
153
+ </div>
154
+ </body>
155
+
156
+ </html>
@@ -0,0 +1,16 @@
1
+ import renderMath from '../src/render-math';
2
+
3
+ const init = () => {
4
+ const mathNodes = document.querySelectorAll('div');
5
+
6
+ // const node = document.querySelector('#mathml-node');
7
+ renderMath(mathNodes);
8
+ };
9
+
10
+ if (document.readyState === 'ready') {
11
+ init();
12
+ } else {
13
+ document.addEventListener('DOMContentLoaded', () => {
14
+ init();
15
+ });
16
+ }
@@ -0,0 +1,29 @@
1
+ const { resolve } = require('path');
2
+
3
+ module.exports = {
4
+ mode: 'development',
5
+ module: {
6
+ rules: [
7
+ {
8
+ test: /\.js$/,
9
+ exclude: /(node_modules)/,
10
+ use: {
11
+ loader: 'babel-loader',
12
+ options: {
13
+ presets: ['env']
14
+ }
15
+ }
16
+ }
17
+ ]
18
+ },
19
+ entry: {
20
+ demo: './demo.js',
21
+ main: './main.js'
22
+ },
23
+ output: {
24
+ filename: '[name].bundle.js'
25
+ },
26
+ resolveLoader: {
27
+ modules: ['node_modules', '../../../node_modules']
28
+ }
29
+ };
@@ -0,0 +1,4 @@
1
+ import renderMath from './render-math';
2
+ import { wrapMath, unWrapMath } from './normalization';
3
+
4
+ export { renderMath, wrapMath, unWrapMath };
@@ -0,0 +1,215 @@
1
+ import { CHTMLWrapper } from 'mathjax-full/js/output/chtml/Wrapper';
2
+ import _ from 'lodash';
3
+
4
+ const reduceText = (acc, n) => {
5
+ if (n.node && n.node.kind === 'text') {
6
+ acc += n.node.text;
7
+ }
8
+ return acc;
9
+ };
10
+
11
+ export class Line {
12
+ constructor() {
13
+ this.kind = 'line';
14
+ }
15
+
16
+ get columns() {
17
+ return [];
18
+ }
19
+ }
20
+
21
+ export class Row {
22
+ constructor(columns, operator) {
23
+ this.kind = 'row';
24
+ this.operator = operator;
25
+ this.columns = columns;
26
+ }
27
+
28
+ pad(count, direction = 'right') {
29
+ if (count < this.columns.length) {
30
+ throw new Error('no');
31
+ }
32
+
33
+ const diff = count - this.columns.length;
34
+
35
+ const padding = _.times(diff).map(n => '__pad__');
36
+ return direction === 'right' ? [...padding, ...this.columns] : [...this.columns, ...padding];
37
+ }
38
+ }
39
+
40
+ const mathNodeToCharArray = mn => {
41
+ const text = mn.childNodes.reduce(reduceText, '');
42
+ return text.split('');
43
+ };
44
+
45
+ /**
46
+ * Convert child a column entry
47
+ * @param {*} child
48
+ * @return an array of column content
49
+ */
50
+ const toColumnArray = child => {
51
+ if (!child || !child.kind) {
52
+ return [];
53
+ }
54
+
55
+ if (child.kind === 'msrow') {
56
+ throw new Error('msrow in msrow?');
57
+ }
58
+
59
+ if (child.kind === 'mo') {
60
+ // We are going to treat this operator as a text array.
61
+ // It's probably going to be a decimal point
62
+ console.warn('mo that is not 1st node in msrow?');
63
+ return mathNodeToCharArray(child);
64
+ // throw new Error('mo must be first child of msrow');
65
+ }
66
+
67
+ if (child.kind === 'mn') {
68
+ return mathNodeToCharArray(child);
69
+ }
70
+
71
+ if (child.toCHTML) {
72
+ return child;
73
+ }
74
+ };
75
+
76
+ /**
77
+ * convert mstack chtml childNodes into a Row
78
+ * @param child chtml child node of mstack
79
+ * @return Row | Line
80
+ */
81
+ const rowStack = child => {
82
+ if (!child || !child.kind) {
83
+ return;
84
+ }
85
+
86
+ if (child.kind === 'msrow') {
87
+ if (!child.childNodes || child.childNodes.length === 0) {
88
+ return new Row([]);
89
+ }
90
+ const f = _.first(child.childNodes);
91
+ const nodes = f && f.kind === 'mo' ? _.tail(child.childNodes) : child.childNodes;
92
+
93
+ const columns = _.flatten(nodes.map(toColumnArray));
94
+
95
+ return new Row(columns, f.kind === 'mo' ? f : undefined);
96
+ }
97
+
98
+ if (child.kind === 'mn') {
99
+ const columns = mathNodeToCharArray(child);
100
+ return new Row(columns, undefined);
101
+ }
102
+
103
+ if (child.kind === 'mo') {
104
+ console.warn('mo on its own row?');
105
+ return new Row([], child);
106
+ }
107
+
108
+ if (child.kind === 'msline') {
109
+ return new Line();
110
+ }
111
+
112
+ if (child.toCHTML) {
113
+ return new Row([child]);
114
+ }
115
+ };
116
+
117
+ /** convert MathJax chtml tree to Row[]
118
+ * @param mstack the root of the mathjax chtml tree
119
+ * @return Row[]
120
+ */
121
+
122
+ export const getStackData = mstack => {
123
+ if (!mstack || !mstack.childNodes) {
124
+ return [];
125
+ }
126
+ return _.compact(mstack.childNodes.map(rowStack));
127
+ };
128
+
129
+ export class CHTMLmstack extends CHTMLWrapper {
130
+ constructor(factory, node, parent = null) {
131
+ super(factory, node, parent);
132
+
133
+ this.ce = this.adaptor.document.createElement.bind(this.adaptor.document);
134
+ }
135
+
136
+ toCHTML(parent) {
137
+ const chtml = this.standardCHTMLnode(parent);
138
+
139
+ const stackData = getStackData(this);
140
+
141
+ // console.log('stackData', stackData);
142
+ const maxCols = stackData.reduce((acc, r) => {
143
+ if (r && r.columns.length > acc) {
144
+ acc = r.columns.length;
145
+ }
146
+ return acc;
147
+ }, 0);
148
+
149
+ const table = this.ce('table');
150
+ chtml.appendChild(table);
151
+
152
+ stackData.forEach(row => {
153
+ const tr = this.ce('tr');
154
+ table.appendChild(tr);
155
+
156
+ if (row.kind === 'row') {
157
+ const td = this.ce('td');
158
+ tr.appendChild(td);
159
+ if (row.operator && row.operator.toCHTML) {
160
+ td.setAttribute('class', 'inner');
161
+ row.operator.toCHTML(td);
162
+ } else {
163
+ td.textContent = '';
164
+ }
165
+
166
+ // align right for now:
167
+ const cols = row.pad(maxCols, 'right');
168
+ cols.forEach(c => {
169
+ const t = this.ce('td');
170
+ tr.appendChild(t);
171
+ if (c === '__pad__') {
172
+ t.textContent = '';
173
+ } else if (typeof c === 'string') {
174
+ t.textContent = c;
175
+ } else if (c.kind === 'none') {
176
+ t.textContent = '';
177
+ } else if (c.toCHTML) {
178
+ t.setAttribute('class', 'inner');
179
+ c.toCHTML(t);
180
+ }
181
+ });
182
+ } else if (row.kind === 'line') {
183
+ const td = this.ce('td');
184
+ tr.appendChild(td);
185
+ td.setAttribute('colspan', maxCols + 1);
186
+ td.setAttribute('class', 'mjx-line');
187
+ td.textContent = '';
188
+ }
189
+ });
190
+ }
191
+ }
192
+ CHTMLmstack.styles = {
193
+ 'mjx-mstack > table': {
194
+ 'line-height': 'initial',
195
+ border: 'solid 0px red',
196
+ 'border-spacing': '0em',
197
+ 'border-collapse': 'separate'
198
+ },
199
+ 'mjx-mstack > table > tr': {
200
+ 'line-height': 'initial'
201
+ },
202
+ 'mjx-mstack > table > tr > td': {
203
+ // padding: '1.2rem',
204
+ border: 'solid 0px blue',
205
+ 'font-family': 'sans-serif',
206
+ 'line-height': 'initial'
207
+ },
208
+ 'mjx-mstack > table > tr > td.inner': {
209
+ 'font-family': 'inherit'
210
+ },
211
+ 'mjx-mstack > table > tr > .mjx-line': {
212
+ padding: 0,
213
+ 'border-top': 'solid 1px black'
214
+ }
215
+ };
@@ -0,0 +1,13 @@
1
+ import { CHTMLmstack } from './chtml';
2
+ import { MmlNone, MmlMsline, MmlMstack, MmlMsrow } from './mml';
3
+
4
+ export const chtmlNodes = {
5
+ mstack: CHTMLmstack
6
+ };
7
+
8
+ export const mmlNodes = {
9
+ mstack: MmlMstack,
10
+ msline: MmlMsline,
11
+ msrow: MmlMsrow,
12
+ none: MmlNone
13
+ };
@@ -0,0 +1,24 @@
1
+ import { AbstractMmlNode } from 'mathjax-full/js/core/MmlTree/MmlNode';
2
+
3
+ export class MmlNone extends AbstractMmlNode {
4
+ get kind() {
5
+ return 'none';
6
+ }
7
+ }
8
+
9
+ export class MmlMstack extends AbstractMmlNode {
10
+ get kind() {
11
+ return 'mstack';
12
+ }
13
+ }
14
+
15
+ export class MmlMsrow extends AbstractMmlNode {
16
+ get kind() {
17
+ return 'msrow';
18
+ }
19
+ }
20
+ export class MmlMsline extends AbstractMmlNode {
21
+ get kind() {
22
+ return 'msline';
23
+ }
24
+ }
@@ -0,0 +1,69 @@
1
+ export const BracketTypes = {};
2
+
3
+ BracketTypes.ROUND_BRACKETS = 'round_brackets';
4
+ BracketTypes.SQUARE_BRACKETS = 'square_brackets';
5
+ BracketTypes.DOLLAR = 'dollar';
6
+ BracketTypes.DOUBLE_DOLLAR = 'double_dollar';
7
+
8
+ const PAIRS = {
9
+ [BracketTypes.ROUND_BRACKETS]: ['\\(', '\\)'],
10
+ [BracketTypes.SQUARE_BRACKETS]: ['\\[', '\\]'],
11
+ [BracketTypes.DOLLAR]: ['$', '$'],
12
+ [BracketTypes.DOUBLE_DOLLAR]: ['$$', '$$']
13
+ };
14
+
15
+ export const wrapMath = (content, wrapType) => {
16
+ if (wrapType === BracketTypes.SQUARE_BRACKETS) {
17
+ console.warn('\\[...\\] is not supported yet'); // eslint-disable-line
18
+ wrapType = BracketTypes.ROUND_BRACKETS;
19
+ }
20
+ if (wrapType === BracketTypes.DOUBLE_DOLLAR) {
21
+ console.warn('$$...$$ is not supported yet'); // eslint-disable-line
22
+ wrapType = BracketTypes.DOLLAR;
23
+ }
24
+
25
+ const [start, end] = PAIRS[wrapType] || PAIRS[BracketTypes.ROUND_BRACKETS];
26
+ return `${start}${content}${end}`;
27
+ };
28
+
29
+ export const unWrapMath = content => {
30
+ const displayStyleIndex = content.indexOf('\\displaystyle');
31
+ if (displayStyleIndex !== -1) {
32
+ console.warn('\\displaystyle is not supported - removing'); // eslint-disable-line
33
+ content = content.replace('\\displaystyle', '').trim();
34
+ }
35
+
36
+ if (content.startsWith('$$') && content.endsWith('$$')) {
37
+ console.warn('$$ syntax is not yet supported'); // eslint-disable-line
38
+ return {
39
+ unwrapped: content.substring(2, content.length - 2),
40
+ wrapType: BracketTypes.DOLLAR
41
+ };
42
+ }
43
+ if (content.startsWith('$') && content.endsWith('$')) {
44
+ return {
45
+ unwrapped: content.substring(1, content.length - 1),
46
+ wrapType: BracketTypes.DOLLAR
47
+ };
48
+ }
49
+
50
+ if (content.startsWith('\\[') && content.endsWith('\\]')) {
51
+ console.warn('\\[..\\] syntax is not yet supported'); // eslint-disable-line
52
+ return {
53
+ unwrapped: content.substring(2, content.length - 2),
54
+ wrapType: BracketTypes.ROUND_BRACKETS
55
+ };
56
+ }
57
+
58
+ if (content.startsWith('\\(') && content.endsWith('\\)')) {
59
+ return {
60
+ unwrapped: content.substring(2, content.length - 2),
61
+ wrapType: BracketTypes.ROUND_BRACKETS
62
+ };
63
+ }
64
+
65
+ return {
66
+ unwrapped: content,
67
+ wrapType: BracketTypes.ROUND_BRACKETS
68
+ };
69
+ };