@pie-lib/math-rendering 2.3.9-next.69 → 2.3.10-next.234
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/CHANGELOG.json +30 -0
- package/CHANGELOG.md +10 -38
- package/lib/index.js +4 -4
- package/lib/mstack/chtml.js +24 -20
- package/lib/mstack/chtml.js.map +1 -1
- package/lib/mstack/mml.js +29 -25
- package/lib/mstack/mml.js.map +1 -1
- package/lib/normalization.js +8 -4
- package/lib/normalization.js.map +1 -1
- package/lib/render-math.js +51 -15
- package/lib/render-math.js.map +1 -1
- package/package.json +3 -3
- package/src/render-math.js +47 -16
package/CHANGELOG.json
CHANGED
|
@@ -638,5 +638,35 @@
|
|
|
638
638
|
"committerDate": "2021-02-22 09:01:40 +0200",
|
|
639
639
|
"isTagged": true,
|
|
640
640
|
"tag": "@pie-lib/math-rendering@2.3.5"
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
"type": "fix",
|
|
644
|
+
"scope": "math-rendering",
|
|
645
|
+
"subject": "fix symbols in math markup that trigger undefined control sequence error PD-1267, PD-368, PD-1173",
|
|
646
|
+
"merge": null,
|
|
647
|
+
"header": "fix(math-rendering): fix symbols in math markup that trigger undefined control sequence error PD-1267, PD-368, PD-1173",
|
|
648
|
+
"body": null,
|
|
649
|
+
"footer": null,
|
|
650
|
+
"notes": [],
|
|
651
|
+
"hash": "a7d9934bea5d0305daa6d75820c007d1e76f3fbb",
|
|
652
|
+
"gitTags": "",
|
|
653
|
+
"committerDate": "2021-08-17 10:59:50 +0300",
|
|
654
|
+
"isTagged": true,
|
|
655
|
+
"tag": "@pie-lib/math-rendering@2.3.9"
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
"type": "fix",
|
|
659
|
+
"scope": null,
|
|
660
|
+
"subject": "wip",
|
|
661
|
+
"merge": null,
|
|
662
|
+
"header": "fix: wip",
|
|
663
|
+
"body": null,
|
|
664
|
+
"footer": null,
|
|
665
|
+
"notes": [],
|
|
666
|
+
"hash": "fe4316df075edfc2c0565641b58c4ca453057651",
|
|
667
|
+
"gitTags": " (origin/fix/fix-math-module)",
|
|
668
|
+
"committerDate": "2021-09-06 13:29:44 +0100",
|
|
669
|
+
"isTagged": true,
|
|
670
|
+
"tag": "@pie-lib/math-rendering@2.3.10"
|
|
641
671
|
}
|
|
642
672
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -3,87 +3,59 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [2.3.
|
|
6
|
+
## [2.3.9](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.8...@pie-lib/math-rendering@2.3.9) (2021-08-30)
|
|
7
7
|
|
|
8
|
-
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
9
8
|
|
|
9
|
+
### Bug Fixes
|
|
10
10
|
|
|
11
|
+
* **math-rendering:** fix symbols in math markup that trigger undefined control sequence error PD-1267, PD-368, PD-1173 ([a7d9934](https://github.com/pie-framework/pie-lib/commit/a7d9934))
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
## [2.3.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.5...@pie-lib/math-rendering@2.3.6) (2021-03-01)
|
|
15
15
|
|
|
16
|
-
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
17
16
|
|
|
17
|
+
## [2.3.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.6...@pie-lib/math-rendering@2.3.8) (2021-06-25)
|
|
18
18
|
|
|
19
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
19
20
|
|
|
21
|
+
## [2.3.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.5...@pie-lib/math-rendering@2.3.6) (2021-03-01)
|
|
20
22
|
|
|
23
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
21
24
|
|
|
22
25
|
## [2.3.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.4...@pie-lib/math-rendering@2.3.5) (2021-03-01)
|
|
23
26
|
|
|
24
|
-
|
|
25
27
|
### Bug Fixes
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
- **math-rendering:** linebreak rendering fixed for mathquill custom elements - PD-787 ([5216f6a](https://github.com/pie-framework/pie-lib/commit/5216f6a))
|
|
32
30
|
|
|
33
31
|
## [2.3.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.3...@pie-lib/math-rendering@2.3.4) (2021-02-15)
|
|
34
32
|
|
|
35
33
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
35
|
## [2.3.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.1...@pie-lib/math-rendering@2.3.3) (2021-02-15)
|
|
42
36
|
|
|
43
37
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
44
38
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
39
|
## [2.3.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.0...@pie-lib/math-rendering@2.3.1) (2021-01-28)
|
|
50
40
|
|
|
51
|
-
|
|
52
41
|
### Bug Fixes
|
|
53
42
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
- add lodash dependency ([de2227f](https://github.com/pie-framework/pie-lib/commit/de2227f))
|
|
59
44
|
|
|
60
45
|
# [2.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.4...@pie-lib/math-rendering@2.3.0) (2021-01-25)
|
|
61
46
|
|
|
62
|
-
|
|
63
47
|
### Features
|
|
64
48
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
- demo changes include for the issue PD-368 ([c493d9f](https://github.com/pie-framework/pie-lib/commit/c493d9f))
|
|
70
50
|
|
|
71
51
|
## [2.2.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.3...@pie-lib/math-rendering@2.2.4) (2021-01-11)
|
|
72
52
|
|
|
73
53
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
74
54
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
55
|
## [2.2.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.2...@pie-lib/math-rendering@2.2.3) (2020-10-26)
|
|
80
56
|
|
|
81
57
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
82
58
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
59
|
## [2.2.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.1...@pie-lib/math-rendering@2.2.2) (2020-10-26)
|
|
88
60
|
|
|
89
61
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
package/lib/index.js
CHANGED
|
@@ -9,16 +9,16 @@ Object.defineProperty(exports, "renderMath", {
|
|
|
9
9
|
return _renderMath["default"];
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "unWrapMath", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function get() {
|
|
15
|
-
return _normalization.
|
|
15
|
+
return _normalization.unWrapMath;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "wrapMath", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function get() {
|
|
21
|
-
return _normalization.
|
|
21
|
+
return _normalization.wrapMath;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
|
package/lib/mstack/chtml.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
|
-
exports.
|
|
8
|
+
exports.getStackData = exports.Row = exports.Line = exports.CHTMLmstack = void 0;
|
|
7
9
|
|
|
8
10
|
var _Wrapper = require("mathjax-full/js/output/chtml/Wrapper");
|
|
9
11
|
|
|
@@ -11,31 +13,37 @@ var _lodash = _interopRequireDefault(require("lodash"));
|
|
|
11
13
|
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
15
|
|
|
14
|
-
function
|
|
16
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
17
|
+
|
|
18
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
19
|
+
|
|
20
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
21
|
|
|
16
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
22
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
17
23
|
|
|
18
24
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
19
25
|
|
|
26
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
27
|
+
|
|
20
28
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
21
29
|
|
|
22
|
-
function
|
|
30
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
23
31
|
|
|
24
|
-
function
|
|
32
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
25
33
|
|
|
26
|
-
function
|
|
34
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
35
|
|
|
28
|
-
function
|
|
36
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
29
37
|
|
|
30
|
-
function
|
|
38
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
31
39
|
|
|
32
|
-
function
|
|
40
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
33
41
|
|
|
34
42
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
35
43
|
|
|
36
44
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
37
45
|
|
|
38
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
46
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
39
47
|
|
|
40
48
|
var reduceText = function reduceText(acc, n) {
|
|
41
49
|
if (n.node && n.node.kind === 'text') {
|
|
@@ -45,9 +53,7 @@ var reduceText = function reduceText(acc, n) {
|
|
|
45
53
|
return acc;
|
|
46
54
|
};
|
|
47
55
|
|
|
48
|
-
var Line =
|
|
49
|
-
/*#__PURE__*/
|
|
50
|
-
function () {
|
|
56
|
+
var Line = /*#__PURE__*/function () {
|
|
51
57
|
function Line() {
|
|
52
58
|
_classCallCheck(this, Line);
|
|
53
59
|
|
|
@@ -66,9 +72,7 @@ function () {
|
|
|
66
72
|
|
|
67
73
|
exports.Line = Line;
|
|
68
74
|
|
|
69
|
-
var Row =
|
|
70
|
-
/*#__PURE__*/
|
|
71
|
-
function () {
|
|
75
|
+
var Row = /*#__PURE__*/function () {
|
|
72
76
|
function Row(columns, operator) {
|
|
73
77
|
_classCallCheck(this, Row);
|
|
74
78
|
|
|
@@ -197,11 +201,11 @@ var getStackData = function getStackData(mstack) {
|
|
|
197
201
|
|
|
198
202
|
exports.getStackData = getStackData;
|
|
199
203
|
|
|
200
|
-
var CHTMLmstack =
|
|
201
|
-
/*#__PURE__*/
|
|
202
|
-
function (_CHTMLWrapper) {
|
|
204
|
+
var CHTMLmstack = /*#__PURE__*/function (_CHTMLWrapper) {
|
|
203
205
|
_inherits(CHTMLmstack, _CHTMLWrapper);
|
|
204
206
|
|
|
207
|
+
var _super = _createSuper(CHTMLmstack);
|
|
208
|
+
|
|
205
209
|
function CHTMLmstack(factory, node) {
|
|
206
210
|
var _this;
|
|
207
211
|
|
|
@@ -209,7 +213,7 @@ function (_CHTMLWrapper) {
|
|
|
209
213
|
|
|
210
214
|
_classCallCheck(this, CHTMLmstack);
|
|
211
215
|
|
|
212
|
-
_this =
|
|
216
|
+
_this = _super.call(this, factory, node, parent);
|
|
213
217
|
_this.ce = _this.adaptor.document.createElement.bind(_this.adaptor.document);
|
|
214
218
|
return _this;
|
|
215
219
|
}
|
package/lib/mstack/chtml.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mstack/chtml.js"],"names":["reduceText","acc","n","node","kind","text","Line","Row","columns","operator","count","direction","length","Error","diff","padding","_","times","map","mathNodeToCharArray","mn","childNodes","reduce","split","toColumnArray","child","console","warn","toCHTML","rowStack","f","first","nodes","tail","flatten","undefined","getStackData","mstack","compact","CHTMLmstack","factory","parent","ce","adaptor","document","createElement","bind","chtml","standardCHTMLnode","stackData","maxCols","r","table","appendChild","forEach","row","tr","td","setAttribute","textContent","cols","pad","c","t","CHTMLWrapper","styles","border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WAAW,CAAC0B,MAAZ,GAAqB;AACnB,wBAAsB;AACpB,mBAAe,SADK;AAEpBC,IAAAA,MAAM,EAAE,eAFY;AAGpB,sBAAkB,KAHE;AAIpB,uBAAmB;AAJC,GADH;AAOnB,6BAA2B;AACzB,mBAAe;AADU,GAPR;AAUnB,kCAAgC;AAC9B;AACAA,IAAAA,MAAM,EAAE,gBAFsB;AAG9B,mBAAe,YAHe;AAI9B,mBAAe;AAJe,GAVb;AAgBnB,wCAAsC;AACpC,mBAAe;AADqB,GAhBnB;AAmBnB,yCAAuC;AACrCnD,IAAAA,OAAO,EAAE,CAD4B;AAErC,kBAAc;AAFuB;AAnBpB,CAArB","sourcesContent":["import { CHTMLWrapper } from 'mathjax-full/js/output/chtml/Wrapper';\nimport _ from 'lodash';\n\nconst reduceText = (acc, n) => {\n if (n.node && n.node.kind === 'text') {\n acc += n.node.text;\n }\n return acc;\n};\n\nexport class Line {\n constructor() {\n this.kind = 'line';\n }\n\n get columns() {\n return [];\n }\n}\n\nexport class Row {\n constructor(columns, operator) {\n this.kind = 'row';\n this.operator = operator;\n this.columns = columns;\n }\n\n pad(count, direction = 'right') {\n if (count < this.columns.length) {\n throw new Error('no');\n }\n\n const diff = count - this.columns.length;\n\n const padding = _.times(diff).map(n => '__pad__');\n return direction === 'right' ? [...padding, ...this.columns] : [...this.columns, ...padding];\n }\n}\n\nconst mathNodeToCharArray = mn => {\n const text = mn.childNodes.reduce(reduceText, '');\n return text.split('');\n};\n\n/**\n * Convert child a column entry\n * @param {*} child\n * @return an array of column content\n */\nconst toColumnArray = child => {\n if (!child || !child.kind) {\n return [];\n }\n\n if (child.kind === 'msrow') {\n throw new Error('msrow in msrow?');\n }\n\n if (child.kind === 'mo') {\n // We are going to treat this operator as a text array.\n // It's probably going to be a decimal point\n console.warn('mo that is not 1st node in msrow?');\n return mathNodeToCharArray(child);\n // throw new Error('mo must be first child of msrow');\n }\n\n if (child.kind === 'mn') {\n return mathNodeToCharArray(child);\n }\n\n if (child.toCHTML) {\n return child;\n }\n};\n\n/**\n * convert mstack chtml childNodes into a Row\n * @param child chtml child node of mstack\n * @return Row | Line\n */\nconst rowStack = child => {\n if (!child || !child.kind) {\n return;\n }\n\n if (child.kind === 'msrow') {\n if (!child.childNodes || child.childNodes.length === 0) {\n return new Row([]);\n }\n const f = _.first(child.childNodes);\n const nodes = f && f.kind === 'mo' ? _.tail(child.childNodes) : child.childNodes;\n\n const columns = _.flatten(nodes.map(toColumnArray));\n\n return new Row(columns, f.kind === 'mo' ? f : undefined);\n }\n\n if (child.kind === 'mn') {\n const columns = mathNodeToCharArray(child);\n return new Row(columns, undefined);\n }\n\n if (child.kind === 'mo') {\n console.warn('mo on its own row?');\n return new Row([], child);\n }\n\n if (child.kind === 'msline') {\n return new Line();\n }\n\n if (child.toCHTML) {\n return new Row([child]);\n }\n};\n\n/** convert MathJax chtml tree to Row[]\n * @param mstack the root of the mathjax chtml tree\n * @return Row[]\n */\n\nexport const getStackData = mstack => {\n if (!mstack || !mstack.childNodes) {\n return [];\n }\n return _.compact(mstack.childNodes.map(rowStack));\n};\n\nexport class CHTMLmstack extends CHTMLWrapper {\n constructor(factory, node, parent = null) {\n super(factory, node, parent);\n\n this.ce = this.adaptor.document.createElement.bind(this.adaptor.document);\n }\n\n toCHTML(parent) {\n const chtml = this.standardCHTMLnode(parent);\n\n const stackData = getStackData(this);\n\n // console.log('stackData', stackData);\n const maxCols = stackData.reduce((acc, r) => {\n if (r && r.columns.length > acc) {\n acc = r.columns.length;\n }\n return acc;\n }, 0);\n\n const table = this.ce('table');\n chtml.appendChild(table);\n\n stackData.forEach(row => {\n const tr = this.ce('tr');\n table.appendChild(tr);\n\n if (row.kind === 'row') {\n const td = this.ce('td');\n tr.appendChild(td);\n if (row.operator && row.operator.toCHTML) {\n td.setAttribute('class', 'inner');\n row.operator.toCHTML(td);\n } else {\n td.textContent = '';\n }\n\n // align right for now:\n const cols = row.pad(maxCols, 'right');\n cols.forEach(c => {\n const t = this.ce('td');\n tr.appendChild(t);\n if (c === '__pad__') {\n t.textContent = '';\n } else if (typeof c === 'string') {\n t.textContent = c;\n } else if (c.kind === 'none') {\n t.textContent = '';\n } else if (c.toCHTML) {\n t.setAttribute('class', 'inner');\n c.toCHTML(t);\n }\n });\n } else if (row.kind === 'line') {\n const td = this.ce('td');\n tr.appendChild(td);\n td.setAttribute('colspan', maxCols + 1);\n td.setAttribute('class', 'mjx-line');\n td.textContent = '';\n }\n });\n }\n}\nCHTMLmstack.styles = {\n 'mjx-mstack > table': {\n 'line-height': 'initial',\n border: 'solid 0px red',\n 'border-spacing': '0em',\n 'border-collapse': 'separate'\n },\n 'mjx-mstack > table > tr': {\n 'line-height': 'initial'\n },\n 'mjx-mstack > table > tr > td': {\n // padding: '1.2rem',\n border: 'solid 0px blue',\n 'font-family': 'sans-serif',\n 'line-height': 'initial'\n },\n 'mjx-mstack > table > tr > td.inner': {\n 'font-family': 'inherit'\n },\n 'mjx-mstack > table > tr > .mjx-line': {\n padding: 0,\n 'border-top': 'solid 1px black'\n }\n};\n"],"file":"chtml.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/mstack/chtml.js"],"names":["reduceText","acc","n","node","kind","text","Line","Row","columns","operator","count","direction","length","Error","diff","padding","_","times","map","mathNodeToCharArray","mn","childNodes","reduce","split","toColumnArray","child","console","warn","toCHTML","rowStack","f","first","nodes","tail","flatten","undefined","getStackData","mstack","compact","CHTMLmstack","factory","parent","ce","adaptor","document","createElement","bind","chtml","standardCHTMLnode","stackData","maxCols","r","table","appendChild","forEach","row","tr","td","setAttribute","textContent","cols","pad","c","t","CHTMLWrapper","styles","border"],"mappings":";;;;;;;;;AAAA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,UAAU,GAAG,SAAbA,UAAa,CAACC,GAAD,EAAMC,CAAN,EAAY;AAC7B,MAAIA,CAAC,CAACC,IAAF,IAAUD,CAAC,CAACC,IAAF,CAAOC,IAAP,KAAgB,MAA9B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mBAAe;AADU,GAPR;AAUnB,kCAAgC;AAC9B;AACAA,IAAAA,MAAM,EAAE,gBAFsB;AAG9B,mBAAe,YAHe;AAI9B,mBAAe;AAJe,GAVb;AAgBnB,wCAAsC;AACpC,mBAAe;AADqB,GAhBnB;AAmBnB,yCAAuC;AACrCnD,IAAAA,OAAO,EAAE,CAD4B;AAErC,kBAAc;AAFuB;AAnBpB,CAArB","sourcesContent":["import { CHTMLWrapper } from 'mathjax-full/js/output/chtml/Wrapper';\nimport _ from 'lodash';\n\nconst reduceText = (acc, n) => {\n if (n.node && n.node.kind === 'text') {\n acc += n.node.text;\n }\n return acc;\n};\n\nexport class Line {\n constructor() {\n this.kind = 'line';\n }\n\n get columns() {\n return [];\n }\n}\n\nexport class Row {\n constructor(columns, operator) {\n this.kind = 'row';\n this.operator = operator;\n this.columns = columns;\n }\n\n pad(count, direction = 'right') {\n if (count < this.columns.length) {\n throw new Error('no');\n }\n\n const diff = count - this.columns.length;\n\n const padding = _.times(diff).map(n => '__pad__');\n return direction === 'right' ? [...padding, ...this.columns] : [...this.columns, ...padding];\n }\n}\n\nconst mathNodeToCharArray = mn => {\n const text = mn.childNodes.reduce(reduceText, '');\n return text.split('');\n};\n\n/**\n * Convert child a column entry\n * @param {*} child\n * @return an array of column content\n */\nconst toColumnArray = child => {\n if (!child || !child.kind) {\n return [];\n }\n\n if (child.kind === 'msrow') {\n throw new Error('msrow in msrow?');\n }\n\n if (child.kind === 'mo') {\n // We are going to treat this operator as a text array.\n // It's probably going to be a decimal point\n console.warn('mo that is not 1st node in msrow?');\n return mathNodeToCharArray(child);\n // throw new Error('mo must be first child of msrow');\n }\n\n if (child.kind === 'mn') {\n return mathNodeToCharArray(child);\n }\n\n if (child.toCHTML) {\n return child;\n }\n};\n\n/**\n * convert mstack chtml childNodes into a Row\n * @param child chtml child node of mstack\n * @return Row | Line\n */\nconst rowStack = child => {\n if (!child || !child.kind) {\n return;\n }\n\n if (child.kind === 'msrow') {\n if (!child.childNodes || child.childNodes.length === 0) {\n return new Row([]);\n }\n const f = _.first(child.childNodes);\n const nodes = f && f.kind === 'mo' ? _.tail(child.childNodes) : child.childNodes;\n\n const columns = _.flatten(nodes.map(toColumnArray));\n\n return new Row(columns, f.kind === 'mo' ? f : undefined);\n }\n\n if (child.kind === 'mn') {\n const columns = mathNodeToCharArray(child);\n return new Row(columns, undefined);\n }\n\n if (child.kind === 'mo') {\n console.warn('mo on its own row?');\n return new Row([], child);\n }\n\n if (child.kind === 'msline') {\n return new Line();\n }\n\n if (child.toCHTML) {\n return new Row([child]);\n }\n};\n\n/** convert MathJax chtml tree to Row[]\n * @param mstack the root of the mathjax chtml tree\n * @return Row[]\n */\n\nexport const getStackData = mstack => {\n if (!mstack || !mstack.childNodes) {\n return [];\n }\n return _.compact(mstack.childNodes.map(rowStack));\n};\n\nexport class CHTMLmstack extends CHTMLWrapper {\n constructor(factory, node, parent = null) {\n super(factory, node, parent);\n\n this.ce = this.adaptor.document.createElement.bind(this.adaptor.document);\n }\n\n toCHTML(parent) {\n const chtml = this.standardCHTMLnode(parent);\n\n const stackData = getStackData(this);\n\n // console.log('stackData', stackData);\n const maxCols = stackData.reduce((acc, r) => {\n if (r && r.columns.length > acc) {\n acc = r.columns.length;\n }\n return acc;\n }, 0);\n\n const table = this.ce('table');\n chtml.appendChild(table);\n\n stackData.forEach(row => {\n const tr = this.ce('tr');\n table.appendChild(tr);\n\n if (row.kind === 'row') {\n const td = this.ce('td');\n tr.appendChild(td);\n if (row.operator && row.operator.toCHTML) {\n td.setAttribute('class', 'inner');\n row.operator.toCHTML(td);\n } else {\n td.textContent = '';\n }\n\n // align right for now:\n const cols = row.pad(maxCols, 'right');\n cols.forEach(c => {\n const t = this.ce('td');\n tr.appendChild(t);\n if (c === '__pad__') {\n t.textContent = '';\n } else if (typeof c === 'string') {\n t.textContent = c;\n } else if (c.kind === 'none') {\n t.textContent = '';\n } else if (c.toCHTML) {\n t.setAttribute('class', 'inner');\n c.toCHTML(t);\n }\n });\n } else if (row.kind === 'line') {\n const td = this.ce('td');\n tr.appendChild(td);\n td.setAttribute('colspan', maxCols + 1);\n td.setAttribute('class', 'mjx-line');\n td.textContent = '';\n }\n });\n }\n}\nCHTMLmstack.styles = {\n 'mjx-mstack > table': {\n 'line-height': 'initial',\n border: 'solid 0px red',\n 'border-spacing': '0em',\n 'border-collapse': 'separate'\n },\n 'mjx-mstack > table > tr': {\n 'line-height': 'initial'\n },\n 'mjx-mstack > table > tr > td': {\n // padding: '1.2rem',\n border: 'solid 0px blue',\n 'font-family': 'sans-serif',\n 'line-height': 'initial'\n },\n 'mjx-mstack > table > tr > td.inner': {\n 'font-family': 'inherit'\n },\n 'mjx-mstack > table > tr > .mjx-line': {\n padding: 0,\n 'border-top': 'solid 1px black'\n }\n};\n"],"file":"chtml.js"}
|
package/lib/mstack/mml.js
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
|
-
exports.
|
|
8
|
+
exports.MmlNone = exports.MmlMstack = exports.MmlMsrow = exports.MmlMsline = void 0;
|
|
7
9
|
|
|
8
10
|
var _MmlNode = require("mathjax-full/js/core/MmlTree/MmlNode");
|
|
9
11
|
|
|
10
|
-
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
11
|
-
|
|
12
12
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
13
|
|
|
14
14
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
15
15
|
|
|
16
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
16
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
19
19
|
|
|
20
|
-
function
|
|
20
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
21
|
|
|
22
|
-
function
|
|
22
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
23
23
|
|
|
24
|
-
function
|
|
24
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
25
25
|
|
|
26
|
-
function
|
|
26
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function (
|
|
28
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
29
|
+
|
|
30
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
31
|
+
|
|
32
|
+
var MmlNone = /*#__PURE__*/function (_AbstractMmlNode) {
|
|
31
33
|
_inherits(MmlNone, _AbstractMmlNode);
|
|
32
34
|
|
|
35
|
+
var _super = _createSuper(MmlNone);
|
|
36
|
+
|
|
33
37
|
function MmlNone() {
|
|
34
38
|
_classCallCheck(this, MmlNone);
|
|
35
39
|
|
|
36
|
-
return
|
|
40
|
+
return _super.apply(this, arguments);
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
_createClass(MmlNone, [{
|
|
@@ -48,15 +52,15 @@ function (_AbstractMmlNode) {
|
|
|
48
52
|
|
|
49
53
|
exports.MmlNone = MmlNone;
|
|
50
54
|
|
|
51
|
-
var MmlMstack =
|
|
52
|
-
/*#__PURE__*/
|
|
53
|
-
function (_AbstractMmlNode2) {
|
|
55
|
+
var MmlMstack = /*#__PURE__*/function (_AbstractMmlNode2) {
|
|
54
56
|
_inherits(MmlMstack, _AbstractMmlNode2);
|
|
55
57
|
|
|
58
|
+
var _super2 = _createSuper(MmlMstack);
|
|
59
|
+
|
|
56
60
|
function MmlMstack() {
|
|
57
61
|
_classCallCheck(this, MmlMstack);
|
|
58
62
|
|
|
59
|
-
return
|
|
63
|
+
return _super2.apply(this, arguments);
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
_createClass(MmlMstack, [{
|
|
@@ -71,15 +75,15 @@ function (_AbstractMmlNode2) {
|
|
|
71
75
|
|
|
72
76
|
exports.MmlMstack = MmlMstack;
|
|
73
77
|
|
|
74
|
-
var MmlMsrow =
|
|
75
|
-
/*#__PURE__*/
|
|
76
|
-
function (_AbstractMmlNode3) {
|
|
78
|
+
var MmlMsrow = /*#__PURE__*/function (_AbstractMmlNode3) {
|
|
77
79
|
_inherits(MmlMsrow, _AbstractMmlNode3);
|
|
78
80
|
|
|
81
|
+
var _super3 = _createSuper(MmlMsrow);
|
|
82
|
+
|
|
79
83
|
function MmlMsrow() {
|
|
80
84
|
_classCallCheck(this, MmlMsrow);
|
|
81
85
|
|
|
82
|
-
return
|
|
86
|
+
return _super3.apply(this, arguments);
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
_createClass(MmlMsrow, [{
|
|
@@ -94,15 +98,15 @@ function (_AbstractMmlNode3) {
|
|
|
94
98
|
|
|
95
99
|
exports.MmlMsrow = MmlMsrow;
|
|
96
100
|
|
|
97
|
-
var MmlMsline =
|
|
98
|
-
/*#__PURE__*/
|
|
99
|
-
function (_AbstractMmlNode4) {
|
|
101
|
+
var MmlMsline = /*#__PURE__*/function (_AbstractMmlNode4) {
|
|
100
102
|
_inherits(MmlMsline, _AbstractMmlNode4);
|
|
101
103
|
|
|
104
|
+
var _super4 = _createSuper(MmlMsline);
|
|
105
|
+
|
|
102
106
|
function MmlMsline() {
|
|
103
107
|
_classCallCheck(this, MmlMsline);
|
|
104
108
|
|
|
105
|
-
return
|
|
109
|
+
return _super4.apply(this, arguments);
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
_createClass(MmlMsline, [{
|
package/lib/mstack/mml.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mstack/mml.js"],"names":["MmlNone","AbstractMmlNode","MmlMstack","MmlMsrow","MmlMsline"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/mstack/mml.js"],"names":["MmlNone","AbstractMmlNode","MmlMstack","MmlMsrow","MmlMsline"],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;IAEaA,O;;;;;;;;;;;;;SACX,eAAW;AACT,aAAO,MAAP;AACD;;;;EAH0BC,wB;;;;IAMhBC,S;;;;;;;;;;;;;SACX,eAAW;AACT,aAAO,QAAP;AACD;;;;EAH4BD,wB;;;;IAMlBE,Q;;;;;;;;;;;;;SACX,eAAW;AACT,aAAO,OAAP;AACD;;;;EAH2BF,wB;;;;IAKjBG,S;;;;;;;;;;;;;SACX,eAAW;AACT,aAAO,QAAP;AACD;;;;EAH4BH,wB","sourcesContent":["import { AbstractMmlNode } from 'mathjax-full/js/core/MmlTree/MmlNode';\n\nexport class MmlNone extends AbstractMmlNode {\n get kind() {\n return 'none';\n }\n}\n\nexport class MmlMstack extends AbstractMmlNode {\n get kind() {\n return 'mstack';\n }\n}\n\nexport class MmlMsrow extends AbstractMmlNode {\n get kind() {\n return 'msrow';\n }\n}\nexport class MmlMsline extends AbstractMmlNode {\n get kind() {\n return 'msline';\n }\n}\n"],"file":"mml.js"}
|
package/lib/normalization.js
CHANGED
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.wrapMath = exports.unWrapMath = exports.BracketTypes = void 0;
|
|
7
7
|
|
|
8
8
|
var _PAIRS;
|
|
9
9
|
|
|
10
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
11
|
|
|
12
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
12
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
13
|
|
|
14
|
-
function
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
|
|
16
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
17
|
+
|
|
18
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
15
19
|
|
|
16
20
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
21
|
|
package/lib/normalization.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/normalization.js"],"names":["BracketTypes","ROUND_BRACKETS","SQUARE_BRACKETS","DOLLAR","DOUBLE_DOLLAR","PAIRS","wrapMath","content","wrapType","console","warn","start","end","unWrapMath","displayStyleIndex","indexOf","replace","trim","startsWith","endsWith","unwrapped","substring","length"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/normalization.js"],"names":["BracketTypes","ROUND_BRACKETS","SQUARE_BRACKETS","DOLLAR","DOUBLE_DOLLAR","PAIRS","wrapMath","content","wrapType","console","warn","start","end","unWrapMath","displayStyleIndex","indexOf","replace","trim","startsWith","endsWith","unwrapped","substring","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAMA,YAAY,GAAG,EAArB;;AAEPA,YAAY,CAACC,cAAb,GAA8B,gBAA9B;AACAD,YAAY,CAACE,eAAb,GAA+B,iBAA/B;AACAF,YAAY,CAACG,MAAb,GAAsB,QAAtB;AACAH,YAAY,CAACI,aAAb,GAA6B,eAA7B;AAEA,IAAMC,KAAK,yCACRL,YAAY,CAACC,cADL,EACsB,CAAC,KAAD,EAAQ,KAAR,CADtB,2BAERD,YAAY,CAACE,eAFL,EAEuB,CAAC,KAAD,EAAQ,KAAR,CAFvB,2BAGRF,YAAY,CAACG,MAHL,EAGc,CAAC,GAAD,EAAM,GAAN,CAHd,2BAIRH,YAAY,CAACI,aAJL,EAIqB,CAAC,IAAD,EAAO,IAAP,CAJrB,UAAX;;AAOO,IAAME,QAAQ,GAAG,SAAXA,QAAW,CAACC,OAAD,EAAUC,QAAV,EAAuB;AAC7C,MAAIA,QAAQ,KAAKR,YAAY,CAACE,eAA9B,EAA+C;AAC7CO,IAAAA,OAAO,CAACC,IAAR,CAAa,gCAAb,EAD6C,CACG;;AAChDF,IAAAA,QAAQ,GAAGR,YAAY,CAACC,cAAxB;AACD;;AACD,MAAIO,QAAQ,KAAKR,YAAY,CAACI,aAA9B,EAA6C;AAC3CK,IAAAA,OAAO,CAACC,IAAR,CAAa,8BAAb,EAD2C,CACG;;AAC9CF,IAAAA,QAAQ,GAAGR,YAAY,CAACG,MAAxB;AACD;;AAED,aAAqBE,KAAK,CAACG,QAAD,CAAL,IAAmBH,KAAK,CAACL,YAAY,CAACC,cAAd,CAA7C;AAAA;AAAA,MAAOU,KAAP;AAAA,MAAcC,GAAd;;A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CAAlB,EAAqBd,OAAO,CAACe,MAAR,GAAiB,CAAtC,CADN;AAELd,MAAAA,QAAQ,EAAER,YAAY,CAACC;AAFlB,KAAP;AAID;;AAED,MAAIM,OAAO,CAACW,UAAR,CAAmB,KAAnB,KAA6BX,OAAO,CAACY,QAAR,CAAiB,KAAjB,CAAjC,EAA0D;AACxD,WAAO;AACLC,MAAAA,SAAS,EAAEb,OAAO,CAACc,SAAR,CAAkB,CAAlB,EAAqBd,OAAO,CAACe,MAAR,GAAiB,CAAtC,CADN;AAELd,MAAAA,QAAQ,EAAER,YAAY,CAACC;AAFlB,KAAP;AAID;;AAED,SAAO;AACLmB,IAAAA,SAAS,EAAEb,OADN;AAELC,IAAAA,QAAQ,EAAER,YAAY,CAACC;AAFlB,GAAP;AAID,CAxCM","sourcesContent":["export const BracketTypes = {};\n\nBracketTypes.ROUND_BRACKETS = 'round_brackets';\nBracketTypes.SQUARE_BRACKETS = 'square_brackets';\nBracketTypes.DOLLAR = 'dollar';\nBracketTypes.DOUBLE_DOLLAR = 'double_dollar';\n\nconst PAIRS = {\n [BracketTypes.ROUND_BRACKETS]: ['\\\\(', '\\\\)'],\n [BracketTypes.SQUARE_BRACKETS]: ['\\\\[', '\\\\]'],\n [BracketTypes.DOLLAR]: ['$', '$'],\n [BracketTypes.DOUBLE_DOLLAR]: ['$$', '$$']\n};\n\nexport const wrapMath = (content, wrapType) => {\n if (wrapType === BracketTypes.SQUARE_BRACKETS) {\n console.warn('\\\\[...\\\\] is not supported yet'); // eslint-disable-line\n wrapType = BracketTypes.ROUND_BRACKETS;\n }\n if (wrapType === BracketTypes.DOUBLE_DOLLAR) {\n console.warn('$$...$$ is not supported yet'); // eslint-disable-line\n wrapType = BracketTypes.DOLLAR;\n }\n\n const [start, end] = PAIRS[wrapType] || PAIRS[BracketTypes.ROUND_BRACKETS];\n return `${start}${content}${end}`;\n};\n\nexport const unWrapMath = content => {\n const displayStyleIndex = content.indexOf('\\\\displaystyle');\n if (displayStyleIndex !== -1) {\n console.warn('\\\\displaystyle is not supported - removing'); // eslint-disable-line\n content = content.replace('\\\\displaystyle', '').trim();\n }\n\n if (content.startsWith('$$') && content.endsWith('$$')) {\n console.warn('$$ syntax is not yet supported'); // eslint-disable-line\n return {\n unwrapped: content.substring(2, content.length - 2),\n wrapType: BracketTypes.DOLLAR\n };\n }\n if (content.startsWith('$') && content.endsWith('$')) {\n return {\n unwrapped: content.substring(1, content.length - 1),\n wrapType: BracketTypes.DOLLAR\n };\n }\n\n if (content.startsWith('\\\\[') && content.endsWith('\\\\]')) {\n console.warn('\\\\[..\\\\] syntax is not yet supported'); // eslint-disable-line\n return {\n unwrapped: content.substring(2, content.length - 2),\n wrapType: BracketTypes.ROUND_BRACKETS\n };\n }\n\n if (content.startsWith('\\\\(') && content.endsWith('\\\\)')) {\n return {\n unwrapped: content.substring(2, content.length - 2),\n wrapType: BracketTypes.ROUND_BRACKETS\n };\n }\n\n return {\n unwrapped: content,\n wrapType: BracketTypes.ROUND_BRACKETS\n };\n};\n"],"file":"normalization.js"}
|
package/lib/render-math.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports.fixMathElements = exports.fixMathElement = exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _mathjax = require("mathjax-full/js/mathjax");
|
|
9
9
|
|
|
@@ -29,23 +29,31 @@ var _normalization = require("./normalization");
|
|
|
29
29
|
|
|
30
30
|
var _MmlFactory = require("mathjax-full/js/core/MmlTree/MmlFactory");
|
|
31
31
|
|
|
32
|
+
var _SerializedMmlVisitor = require("mathjax-full/js/core/MmlTree/SerializedMmlVisitor");
|
|
33
|
+
|
|
32
34
|
var _WrapperFactory = require("mathjax-full/js/output/chtml/WrapperFactory");
|
|
33
35
|
|
|
34
36
|
var _mspace = require("mathjax-full/js/output/chtml/Wrappers/mspace");
|
|
35
37
|
|
|
36
38
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
37
39
|
|
|
38
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
40
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
41
|
+
|
|
42
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
43
|
+
|
|
44
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
39
45
|
|
|
40
|
-
function
|
|
46
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
41
47
|
|
|
42
|
-
function
|
|
48
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
43
49
|
|
|
44
|
-
function
|
|
50
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
45
51
|
|
|
46
|
-
function
|
|
52
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
47
53
|
|
|
48
|
-
function
|
|
54
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
55
|
+
|
|
56
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
49
57
|
|
|
50
58
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
51
59
|
|
|
@@ -53,6 +61,12 @@ if (typeof window !== 'undefined') {
|
|
|
53
61
|
(0, _html.RegisterHTMLHandler)((0, _browserAdaptor.browserAdaptor)());
|
|
54
62
|
}
|
|
55
63
|
|
|
64
|
+
var visitor = new _SerializedMmlVisitor.SerializedMmlVisitor();
|
|
65
|
+
|
|
66
|
+
var toMMl = function toMMl(node) {
|
|
67
|
+
return visitor.visitTree(node);
|
|
68
|
+
};
|
|
69
|
+
|
|
56
70
|
var log = (0, _debug["default"])('pie-lib:math-rendering');
|
|
57
71
|
var NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
|
|
58
72
|
var NEWLINE_LATEX = '\\newline ';
|
|
@@ -140,15 +154,21 @@ var bootstrap = function bootstrap(opts) {
|
|
|
140
154
|
longdiv: '\\enclose{longdiv}'
|
|
141
155
|
};
|
|
142
156
|
var texConfig = opts.useSingleDollar ? {
|
|
157
|
+
loader: {
|
|
158
|
+
require: require
|
|
159
|
+
},
|
|
143
160
|
packages: packages,
|
|
144
161
|
macros: macros,
|
|
145
162
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
|
163
|
+
displayMath: [['$$', '$$'], ['\\[', '\\]']],
|
|
146
164
|
processEscapes: true
|
|
147
165
|
} : {
|
|
148
166
|
packages: packages,
|
|
149
167
|
macros: macros
|
|
150
168
|
};
|
|
151
169
|
var mmlConfig = {
|
|
170
|
+
parseAs: 'html',
|
|
171
|
+
forceReparse: false,
|
|
152
172
|
parseError: function parseError(node) {
|
|
153
173
|
// function to process parsing errors
|
|
154
174
|
console.log('error:', node);
|
|
@@ -158,10 +178,11 @@ var bootstrap = function bootstrap(opts) {
|
|
|
158
178
|
var fontURL = "https://unpkg.com/mathjax-full@".concat(_mathjax.mathjax.version, "/ts/output/chtml/fonts/tex-woff-v2");
|
|
159
179
|
var htmlConfig = {
|
|
160
180
|
fontURL: fontURL,
|
|
161
|
-
wrapperFactory: new _WrapperFactory.CHTMLWrapperFactory(_objectSpread({}, _WrapperFactory.CHTMLWrapperFactory.defaultNodes,
|
|
181
|
+
wrapperFactory: new _WrapperFactory.CHTMLWrapperFactory(_objectSpread(_objectSpread({}, _WrapperFactory.CHTMLWrapperFactory.defaultNodes), _mstack.chtmlNodes))
|
|
162
182
|
};
|
|
163
183
|
var mml = new _mathml.MathML(mmlConfig);
|
|
164
|
-
|
|
184
|
+
console.log([new _tex.TeX(texConfig), mml]);
|
|
185
|
+
var customMmlFactory = new _MmlFactory.MmlFactory(_objectSpread(_objectSpread({}, _MmlFactory.MmlFactory.defaultNodes), _mstack.mmlNodes));
|
|
165
186
|
|
|
166
187
|
var html = _mathjax.mathjax.document(document, {
|
|
167
188
|
compileError: function compileError(mj, math, err) {
|
|
@@ -187,9 +208,23 @@ var bootstrap = function bootstrap(opts) {
|
|
|
187
208
|
elements[_key] = arguments[_key];
|
|
188
209
|
}
|
|
189
210
|
|
|
190
|
-
this.html.findMath(elements.length ? {
|
|
211
|
+
var updatedDocument = this.html.findMath(elements.length ? {
|
|
191
212
|
elements: elements
|
|
192
|
-
} : {}).compile().getMetrics().typeset().updateDocument()
|
|
213
|
+
} : {}).compile().getMetrics().typeset().updateDocument();
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
var list = updatedDocument.math.list;
|
|
217
|
+
|
|
218
|
+
for (var item = list.next; _typeof(item.data) !== 'symbol'; item = item.next) {
|
|
219
|
+
var mathMl = toMMl(item.data.root);
|
|
220
|
+
var parsedMathMl = mathMl.replaceAll('\n', '');
|
|
221
|
+
item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);
|
|
222
|
+
}
|
|
223
|
+
} catch (e) {
|
|
224
|
+
console.error(e.toString());
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
updatedDocument.clear();
|
|
193
228
|
}
|
|
194
229
|
};
|
|
195
230
|
};
|
|
@@ -222,16 +257,17 @@ var renderMath = function renderMath(el, renderOpts) {
|
|
|
222
257
|
* In mathjax src code \newline latex gets parsed to <mjx-mspace></mjx-mspace>,
|
|
223
258
|
* but has the default style
|
|
224
259
|
* 'mjx-mspace': {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
260
|
+
"display": 'in-line',
|
|
261
|
+
"text-align": 'left'
|
|
262
|
+
} which prevents it from showing as a newline value
|
|
228
263
|
*/
|
|
229
264
|
|
|
230
265
|
|
|
231
266
|
_mspace.CHTMLmspace.styles = {
|
|
232
267
|
'mjx-mspace': {
|
|
233
268
|
display: 'block',
|
|
234
|
-
'text-align': 'center'
|
|
269
|
+
'text-align': 'center',
|
|
270
|
+
height: '5px'
|
|
235
271
|
}
|
|
236
272
|
};
|
|
237
273
|
var _default = renderMath;
|
package/lib/render-math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/render-math.js"],"names":["window","log","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","getGlobal","key","pkg","name","version","split","defaultOpts","opts","fixMathElement","element","property","textContent","unwrapped","replace","fixMathElements","mathElements","document","querySelectorAll","forEach","item","bootstrap","Typeset","useSingleDollar","console","warn","packages","AllPackages","filter","push","macros","parallelogram","overarc","napprox","longdiv","texConfig","inlineMath","processEscapes","mmlConfig","parseError","node","error","adaptor","fontURL","mathjax","htmlConfig","wrapperFactory","CHTMLWrapperFactory","defaultNodes","chtmlNodes","mml","MathML","customMmlFactory","MmlFactory","mmlNodes","html","compileError","mj","math","err","typesetError","doc","InputJax","TeX","OutputJax","CHTML","setMmlFactory","elements","findMath","length","compile","getMetrics","typeset","updateDocument","clear","renderMath","el","renderOpts","instance","Element","arr","Array","from","CHTMLmspace","styles","display"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;AAVA,IAAI,OAAOA,MAAP,KAAkB,WAAtB,EAAmC;AACjC,iCAAoB,qCAApB;AACD;;AAUD,IAAMC,GAAG,GAAG,uBAAM,wBAAN,CAAZ;AAEA,IAAMC,mBAAmB,GAAG,yBAA5B;AACA,IAAMC,aAAa,GAAG,YAAtB;;AAEA,IAAMC,SAAS,GAAG,SAAZA,SAAY,GAAM;AACtB,MAAMC,GAAG,aAAMC,oBAAIC,IAAV,cAAkBD,oBAAIE,OAAJ,CAAYC,KAAZ,CAAkB,GAAlB,EAAuB,CAAvB,CAAlB,CAAT;;AAEA,MAAI,OAAOT,MAAP,KAAkB,WAAtB,EAAmC;AACjC,QAAI,CAACA,MAAM,CAACK,GAAD,CAAX,EAAkB;AAChBL,MAAAA,MAAM,CAACK,GAAD,CAAN,GAAc,EAAd;AACD;;AACD,WAAOL,MAAM,CAACK,GAAD,CAAb;AACD,GALD,MAKO;AACL,WAAO,EAAP;AACD;AACF,CAXD;AAaA;;;;;;;;;AAOA,IAAMK,WAAW,GAAG,SAAdA,WAAc;AAAA,SAAMN,SAAS,GAAGO,IAAZ,IAAoB,EAA1B;AAAA,CAApB;;AAEO,IAAMC,cAAc,GAAG,SAAjBA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AAD,CAAhC;AACD;;AAED,MAAI,CAACD,EAAL,EAAS;AACP9E,IAAAA,GAAG,CAAC,iBAAD,CAAH;AACA;AACD;;AAED,MAAI8E,EAAE,YAAYG,OAAlB,EAA2B;AACzB9E,IAAAA,SAAS,GAAG6E,QAAZ,CAAqBxD,OAArB,CAA6BsD,EAA7B;AACD,GAFD,MAEO,IAAIA,EAAE,CAACP,MAAP,EAAe;AAAA;;AACpB,QAAMW,GAAG,GAAGC,KAAK,CAACC,IAAN,CAAWN,EAAX,CAAZ;;AACA,2BAAA3E,SAAS,GAAG6E,QAAZ,EAAqBxD,OAArB,+CAAgC0D,GAAhC;AACD;AACF,CAnBD;AAqBA;;;;;;;;;;;AASAG,oBAAYC,MAAZ,GAAqB;AACnB,gBAAc;AACZC,IAAAA,OAAO,EAAE,OADG;AAEZ,kBAAc;AAFF;AADK,CAArB;eAOeV,U","sourcesContent":["import { mathjax } from 'mathjax-full/js/mathjax';\nimport { MathML } from 'mathjax-full/js/input/mathml';\nimport { TeX } from 'mathjax-full/js/input/tex';\n\nimport { CHTML } from 'mathjax-full/js/output/chtml';\nimport { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';\nimport { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';\nimport { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';\n\nif (typeof window !== 'undefined') {\n RegisterHTMLHandler(browserAdaptor());\n}\n\nimport pkg from '../package.json';\nimport { mmlNodes, chtmlNodes } from './mstack';\nimport debug from 'debug';\nimport { wrapMath, unWrapMath } from './normalization';\nimport { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';\nimport { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';\nimport { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';\n\nconst log = debug('pie-lib:math-rendering');\n\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\nconst getGlobal = () => {\n const key = `${pkg.name}@${pkg.version.split('.')[0]}`;\n\n if (typeof window !== 'undefined') {\n if (!window[key]) {\n window[key] = {};\n }\n return window[key];\n } else {\n return {};\n }\n};\n\n/** Add temporary support for a global singleDollar override\n * <code>\n * // This will enable single dollar rendering\n * window.pie = window.pie || {};\n * window.pie.mathRendering = {useSingleDollar: true };\n * </code>\n */\nconst defaultOpts = () => getGlobal().opts || {};\n\nexport const fixMathElement = element => {\n let property = 'innerText';\n\n if (element.textContent) {\n property = 'textContent';\n }\n\n if (element[property]) {\n element[property] = wrapMath(unWrapMath(element[property]).unwrapped);\n // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.\n // we need to replace the custom embedded elements with valid latex that Mathjax can understand\n element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);\n }\n};\n\nexport const fixMathElements = () => {\n const mathElements = document.querySelectorAll('[data-latex]');\n\n mathElements.forEach(item => fixMathElement(item));\n};\n\nconst bootstrap = opts => {\n if (typeof window === 'undefined') {\n return { Typeset: () => ({}) };\n }\n\n opts = opts || defaultOpts();\n\n if (opts.useSingleDollar) {\n // eslint-disable-next-line\n console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\\\(...\\\\)');\n }\n\n const packages = AllPackages.filter(name => name !== 'bussproofs'); // Bussproofs needs an output jax\n\n // The autoload extension predefines all the macros from the extensions that haven't been loaded already\n // so that they automatically load the needed extension when they are first used\n packages.push('autoload');\n\n const macros = {\n parallelogram: '\\\\lower.2em{\\\\Huge\\\\unicode{x25B1}}',\n overarc: '\\\\overparen',\n napprox: '\\\\not\\\\approx',\n longdiv: '\\\\enclose{longdiv}'\n };\n\n const texConfig = opts.useSingleDollar\n ? {\n packages,\n macros,\n inlineMath: [['$', '$'], ['\\\\(', '\\\\)']],\n processEscapes: true\n }\n : {\n packages,\n macros\n };\n\n const mmlConfig = {\n parseError: function(node) {\n // function to process parsing errors\n console.log('error:', node);\n this.error(this.adaptor.textContent(node).replace(/\\n.*/g, ''));\n }\n };\n\n const fontURL = `https://unpkg.com/mathjax-full@${mathjax.version}/ts/output/chtml/fonts/tex-woff-v2`;\n const htmlConfig = {\n fontURL,\n\n wrapperFactory: new CHTMLWrapperFactory({\n ...CHTMLWrapperFactory.defaultNodes,\n ...chtmlNodes\n })\n };\n\n const mml = new MathML(mmlConfig);\n\n const customMmlFactory = new MmlFactory({\n ...MmlFactory.defaultNodes,\n ...mmlNodes\n });\n\n const html = mathjax.document(document, {\n compileError: (mj, math, err) => {\n console.log('bad math?:', math);\n console.error(err);\n },\n typesetError: function(doc, math, err) {\n console.log('typeset error');\n console.error(err);\n doc.typesetError(math, err);\n },\n\n InputJax: [new TeX(texConfig), mml],\n OutputJax: new CHTML(htmlConfig)\n });\n\n // Note: we must set this *after* mathjax.document (no idea why)\n mml.setMmlFactory(customMmlFactory);\n\n return {\n version: mathjax.version,\n html: html,\n\n Typeset: function(...elements) {\n this.html\n .findMath(elements.length ? { elements } : {})\n .compile()\n .getMetrics()\n .typeset()\n .updateDocument()\n .clear();\n }\n };\n};\n\nconst renderMath = (el, renderOpts) => {\n //TODO: remove this - has nothing to do with math-rendering (it's from editable-html)\n fixMathElements();\n\n if (!getGlobal().instance) {\n getGlobal().instance = bootstrap(renderOpts);\n }\n\n if (!el) {\n log('el is undefined');\n return;\n }\n\n if (el instanceof Element) {\n getGlobal().instance.Typeset(el);\n } else if (el.length) {\n const arr = Array.from(el);\n getGlobal().instance.Typeset(...arr);\n }\n};\n\n/**\n * This style is added to overried default styling of mjx-mspace Mathjax tag\n * In mathjax src code \\newline latex gets parsed to <mjx-mspace></mjx-mspace>,\n * but has the default style\n * 'mjx-mspace': {\n \"display\": 'in-line',\n \"text-align\": 'left'\n } which prevents it from showing as a newline value\n */\nCHTMLmspace.styles = {\n 'mjx-mspace': {\n display: 'block',\n 'text-align': 'center'\n }\n};\n\nexport default renderMath;\n"],"file":"render-math.js"}
|
|
1
|
+
{"version":3,"sources":["../src/render-math.js"],"names":["window","visitor","SerializedMmlVisitor","toMMl","node","visitTree","log","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","getGlobal","key","pkg","name","version","split","defaultOpts","opts","fixMathElement","element","property","textContent","unwrapped","replace","fixMathElements","mathElements","document","querySelectorAll","forEach","item","bootstrap","Typeset","useSingleDollar","console","warn","packages","AllPackages","filter","push","macros","parallelogram","overarc","napprox","longdiv","texConfig","loader","require","inlineMath","displayMath","processEscapes","mmlConfig","parseAs","forceReparse","parseError","error","adaptor","fontURL","mathjax","htmlConfig","wrapperFactory","CHTMLWrapperFactory","defaultNodes","chtmlNodes","mml","MathML","TeX","customMmlFactory","MmlFactory","mmlNodes","html","compileError","mj","math","err","typesetError","doc","InputJax","OutputJax","CHTML","setMmlFactory","elements","updatedDocument","findMath","length","compile","getMetrics","typeset","updateDocument","list","next","data","mathMl","root","parsedMathMl","replaceAll","typesetRoot","setAttribute","e","toString","clear","renderMath","el","renderOpts","instance","Element","arr","Array","from","CHTMLmspace","styles","display","height"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;AAXA,IAAI,OAAOA,MAAP,KAAkB,WAAtB,EAAmC;AACjC,iCAAoB,qCAApB;AACD;;AAWD,IAAMC,OAAO,GAAG,IAAIC,0CAAJ,EAAhB;;AACA,IAAMC,KAAK,GAAG,SAARA,KAAQ,CAAAC,IAAI;AAAA,SAAIH,OAAO,CAACI,SAAR,CAAkBD,IAAlB,CAAJ;AAAA,CAAlB;;AAEA,IAAME,GAAG,GAAG,uBAAM,wBAAN,CAAZ;AAEA,IAAMC,mBAAmB,GAAG,yBAA5B;AACA,IAAMC,aAAa,GAAG,YAAtB;;AAEA,IAAMC,SAAS,GAAG,SAAZA,SAAY,GAAM;AACtB,MAAMC,GAAG,aAAMC,oBAAIC,IAAV,cAAkBD,oBAAIE,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B;AACD;AAzBI,GAAP;AA2BD,CAxHD;;AA0HA,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,EAAD,EAAKC,UAAL,EAAoB;AACrC;AACA9E,EAAAA,eAAe;;AAEf,MAAI,CAACd,SAAS,GAAG6F,QAAjB,EAA2B;AACzB7F,IAAAA,SAAS,GAAG6F,QAAZ,GAAuBzE,SAAS,CAACwE,UAAD,CAAhC;AACD;;AAED,MAAI,CAACD,EAAL,EAAS;AACP9F,IAAAA,GAAG,CAAC,iBAAD,CAAH;AACA;AACD;;AAED,MAAI8F,EAAE,YAAYG,OAAlB,EAA2B;AACzB9F,IAAAA,SAAS,GAAG6F,QAAZ,CAAqBxE,OAArB,CAA6BsE,EAA7B;AACD,GAFD,MAEO,IAAIA,EAAE,CAAClB,MAAP,EAAe;AAAA;;AACpB,QAAMsB,GAAG,GAAGC,KAAK,CAACC,IAAN,CAAWN,EAAX,CAAZ;;AACA,2BAAA3F,SAAS,GAAG6F,QAAZ,EAAqBxE,OAArB,+CAAgC0E,GAAhC;AACD;AACF,CAnBD;AAqBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACAG,oBAAYC,MAAZ,GAAqB;AACnB,gBAAc;AACZC,IAAAA,OAAO,EAAE,OADG;AAEZ,kBAAc,QAFF;AAGZC,IAAAA,MAAM,EAAE;AAHI;AADK,CAArB;eAQeX,U","sourcesContent":["import { mathjax } from 'mathjax-full/js/mathjax';\nimport { MathML } from 'mathjax-full/js/input/mathml';\nimport { TeX } from 'mathjax-full/js/input/tex';\n\nimport { CHTML } from 'mathjax-full/js/output/chtml';\nimport { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';\nimport { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';\nimport { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';\n\nif (typeof window !== 'undefined') {\n RegisterHTMLHandler(browserAdaptor());\n}\n\nimport pkg from '../package.json';\nimport { mmlNodes, chtmlNodes } from './mstack';\nimport debug from 'debug';\nimport { wrapMath, unWrapMath } from './normalization';\nimport { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';\nimport { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';\nimport { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';\nimport { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';\n\nconst visitor = new SerializedMmlVisitor();\nconst toMMl = node => visitor.visitTree(node);\n\nconst log = debug('pie-lib:math-rendering');\n\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\nconst getGlobal = () => {\n const key = `${pkg.name}@${pkg.version.split('.')[0]}`;\n\n if (typeof window !== 'undefined') {\n if (!window[key]) {\n window[key] = {};\n }\n return window[key];\n } else {\n return {};\n }\n};\n\n/** Add temporary support for a global singleDollar override\n * <code>\n * // This will enable single dollar rendering\n * window.pie = window.pie || {};\n * window.pie.mathRendering = {useSingleDollar: true };\n * </code>\n */\nconst defaultOpts = () => getGlobal().opts || {};\n\nexport const fixMathElement = element => {\n let property = 'innerText';\n\n if (element.textContent) {\n property = 'textContent';\n }\n\n if (element[property]) {\n element[property] = wrapMath(unWrapMath(element[property]).unwrapped);\n // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.\n // we need to replace the custom embedded elements with valid latex that Mathjax can understand\n element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);\n }\n};\n\nexport const fixMathElements = () => {\n const mathElements = document.querySelectorAll('[data-latex]');\n\n mathElements.forEach(item => fixMathElement(item));\n};\n\nconst bootstrap = opts => {\n if (typeof window === 'undefined') {\n return { Typeset: () => ({}) };\n }\n\n opts = opts || defaultOpts();\n\n if (opts.useSingleDollar) {\n // eslint-disable-next-line\n console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\\\(...\\\\)');\n }\n\n const packages = AllPackages.filter(name => name !== 'bussproofs'); // Bussproofs needs an output jax\n\n // The autoload extension predefines all the macros from the extensions that haven't been loaded already\n // so that they automatically load the needed extension when they are first used\n packages.push('autoload');\n\n const macros = {\n parallelogram: '\\\\lower.2em{\\\\Huge\\\\unicode{x25B1}}',\n overarc: '\\\\overparen',\n napprox: '\\\\not\\\\approx',\n longdiv: '\\\\enclose{longdiv}'\n };\n\n const texConfig = opts.useSingleDollar\n ? {\n loader: {\n require: require\n },\n packages,\n macros,\n inlineMath: [\n ['$', '$'],\n ['\\\\(', '\\\\)']\n ],\n displayMath: [\n ['$$', '$$'],\n ['\\\\[', '\\\\]']\n ],\n processEscapes: true\n }\n : {\n packages,\n macros\n };\n\n const mmlConfig = {\n parseAs: 'html',\n forceReparse: false,\n parseError: function(node) {\n // function to process parsing errors\n console.log('error:', node);\n this.error(this.adaptor.textContent(node).replace(/\\n.*/g, ''));\n }\n };\n\n const fontURL = `https://unpkg.com/mathjax-full@${mathjax.version}/ts/output/chtml/fonts/tex-woff-v2`;\n const htmlConfig = {\n fontURL,\n\n wrapperFactory: new CHTMLWrapperFactory({\n ...CHTMLWrapperFactory.defaultNodes,\n ...chtmlNodes\n })\n };\n\n const mml = new MathML(mmlConfig);\n console.log([new TeX(texConfig), mml]);\n\n const customMmlFactory = new MmlFactory({\n ...MmlFactory.defaultNodes,\n ...mmlNodes\n });\n\n const html = mathjax.document(document, {\n compileError: (mj, math, err) => {\n console.log('bad math?:', math);\n console.error(err);\n },\n typesetError: function(doc, math, err) {\n console.log('typeset error');\n console.error(err);\n doc.typesetError(math, err);\n },\n\n InputJax: [new TeX(texConfig), mml],\n OutputJax: new CHTML(htmlConfig)\n });\n\n // Note: we must set this *after* mathjax.document (no idea why)\n mml.setMmlFactory(customMmlFactory);\n\n return {\n version: mathjax.version,\n html: html,\n Typeset: function(...elements) {\n const updatedDocument = this.html\n .findMath(elements.length ? { elements } : {})\n .compile()\n .getMetrics()\n .typeset()\n .updateDocument();\n\n try {\n const list = updatedDocument.math.list;\n\n for (let item = list.next; typeof item.data !== 'symbol'; item = item.next) {\n const mathMl = toMMl(item.data.root);\n const parsedMathMl = mathMl.replaceAll('\\n', '');\n\n item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);\n }\n } catch (e) {\n console.error(e.toString());\n }\n\n updatedDocument.clear();\n }\n };\n};\n\nconst renderMath = (el, renderOpts) => {\n //TODO: remove this - has nothing to do with math-rendering (it's from editable-html)\n fixMathElements();\n\n if (!getGlobal().instance) {\n getGlobal().instance = bootstrap(renderOpts);\n }\n\n if (!el) {\n log('el is undefined');\n return;\n }\n\n if (el instanceof Element) {\n getGlobal().instance.Typeset(el);\n } else if (el.length) {\n const arr = Array.from(el);\n getGlobal().instance.Typeset(...arr);\n }\n};\n\n/**\n * This style is added to overried default styling of mjx-mspace Mathjax tag\n * In mathjax src code \\newline latex gets parsed to <mjx-mspace></mjx-mspace>,\n * but has the default style\n * 'mjx-mspace': {\n \"display\": 'in-line',\n \"text-align\": 'left'\n} which prevents it from showing as a newline value\n */\nCHTMLmspace.styles = {\n 'mjx-mspace': {\n display: 'block',\n 'text-align': 'center',\n height: '5px'\n }\n};\n\nexport default renderMath;\n"],"file":"render-math.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/math-rendering",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.10-next.234+3bb6d0e9",
|
|
4
4
|
"description": "math rendering utilities",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"debug": "^4.1.1",
|
|
14
14
|
"lodash": "^4.17.11",
|
|
15
|
-
"mathjax-full": "^3.
|
|
15
|
+
"mathjax-full": "^3.2.0"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "3bb6d0e9216e3292f4fcd4ff5c557397d62fb82f",
|
|
18
18
|
"scripts": {}
|
|
19
19
|
}
|
package/src/render-math.js
CHANGED
|
@@ -16,9 +16,13 @@ import { mmlNodes, chtmlNodes } from './mstack';
|
|
|
16
16
|
import debug from 'debug';
|
|
17
17
|
import { wrapMath, unWrapMath } from './normalization';
|
|
18
18
|
import { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';
|
|
19
|
+
import { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';
|
|
19
20
|
import { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';
|
|
20
21
|
import { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';
|
|
21
22
|
|
|
23
|
+
const visitor = new SerializedMmlVisitor();
|
|
24
|
+
const toMMl = node => visitor.visitTree(node);
|
|
25
|
+
|
|
22
26
|
const log = debug('pie-lib:math-rendering');
|
|
23
27
|
|
|
24
28
|
const NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
|
|
@@ -94,17 +98,29 @@ const bootstrap = opts => {
|
|
|
94
98
|
|
|
95
99
|
const texConfig = opts.useSingleDollar
|
|
96
100
|
? {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
loader: {
|
|
102
|
+
require: require
|
|
103
|
+
},
|
|
104
|
+
packages,
|
|
105
|
+
macros,
|
|
106
|
+
inlineMath: [
|
|
107
|
+
['$', '$'],
|
|
108
|
+
['\\(', '\\)']
|
|
109
|
+
],
|
|
110
|
+
displayMath: [
|
|
111
|
+
['$$', '$$'],
|
|
112
|
+
['\\[', '\\]']
|
|
113
|
+
],
|
|
114
|
+
processEscapes: true
|
|
115
|
+
}
|
|
102
116
|
: {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
packages,
|
|
118
|
+
macros
|
|
119
|
+
};
|
|
106
120
|
|
|
107
121
|
const mmlConfig = {
|
|
122
|
+
parseAs: 'html',
|
|
123
|
+
forceReparse: false,
|
|
108
124
|
parseError: function(node) {
|
|
109
125
|
// function to process parsing errors
|
|
110
126
|
console.log('error:', node);
|
|
@@ -123,6 +139,7 @@ const bootstrap = opts => {
|
|
|
123
139
|
};
|
|
124
140
|
|
|
125
141
|
const mml = new MathML(mmlConfig);
|
|
142
|
+
console.log([new TeX(texConfig), mml]);
|
|
126
143
|
|
|
127
144
|
const customMmlFactory = new MmlFactory({
|
|
128
145
|
...MmlFactory.defaultNodes,
|
|
@@ -150,15 +167,28 @@ const bootstrap = opts => {
|
|
|
150
167
|
return {
|
|
151
168
|
version: mathjax.version,
|
|
152
169
|
html: html,
|
|
153
|
-
|
|
154
170
|
Typeset: function(...elements) {
|
|
155
|
-
this.html
|
|
171
|
+
const updatedDocument = this.html
|
|
156
172
|
.findMath(elements.length ? { elements } : {})
|
|
157
173
|
.compile()
|
|
158
174
|
.getMetrics()
|
|
159
175
|
.typeset()
|
|
160
|
-
.updateDocument()
|
|
161
|
-
|
|
176
|
+
.updateDocument();
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
const list = updatedDocument.math.list;
|
|
180
|
+
|
|
181
|
+
for (let item = list.next; typeof item.data !== 'symbol'; item = item.next) {
|
|
182
|
+
const mathMl = toMMl(item.data.root);
|
|
183
|
+
const parsedMathMl = mathMl.replaceAll('\n', '');
|
|
184
|
+
|
|
185
|
+
item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);
|
|
186
|
+
}
|
|
187
|
+
} catch (e) {
|
|
188
|
+
console.error(e.toString());
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
updatedDocument.clear();
|
|
162
192
|
}
|
|
163
193
|
};
|
|
164
194
|
};
|
|
@@ -189,14 +219,15 @@ const renderMath = (el, renderOpts) => {
|
|
|
189
219
|
* In mathjax src code \newline latex gets parsed to <mjx-mspace></mjx-mspace>,
|
|
190
220
|
* but has the default style
|
|
191
221
|
* 'mjx-mspace': {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
222
|
+
"display": 'in-line',
|
|
223
|
+
"text-align": 'left'
|
|
224
|
+
} which prevents it from showing as a newline value
|
|
195
225
|
*/
|
|
196
226
|
CHTMLmspace.styles = {
|
|
197
227
|
'mjx-mspace': {
|
|
198
228
|
display: 'block',
|
|
199
|
-
'text-align': 'center'
|
|
229
|
+
'text-align': 'center',
|
|
230
|
+
height: '5px'
|
|
200
231
|
}
|
|
201
232
|
};
|
|
202
233
|
|