@pie-lib/math-rendering-accessible 3.22.1 → 3.23.0-mui-update.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,95 +1,68 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.wrapMath = exports.unWrapMath = exports.BracketTypes = void 0;
9
-
10
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
- var _PAIRS;
15
-
16
- var BracketTypes = {};
17
- exports.BracketTypes = BracketTypes;
10
+ var BracketTypes = exports.BracketTypes = {};
18
11
  BracketTypes.ROUND_BRACKETS = 'round_brackets';
19
12
  BracketTypes.SQUARE_BRACKETS = 'square_brackets';
20
13
  BracketTypes.DOLLAR = 'dollar';
21
14
  BracketTypes.DOUBLE_DOLLAR = 'double_dollar';
22
- var PAIRS = (_PAIRS = {}, (0, _defineProperty2["default"])(_PAIRS, BracketTypes.ROUND_BRACKETS, ['\\(', '\\)']), (0, _defineProperty2["default"])(_PAIRS, BracketTypes.SQUARE_BRACKETS, ['\\[', '\\]']), (0, _defineProperty2["default"])(_PAIRS, BracketTypes.DOLLAR, ['$', '$']), (0, _defineProperty2["default"])(_PAIRS, BracketTypes.DOUBLE_DOLLAR, ['$$', '$$']), _PAIRS);
23
-
24
- var wrapMath = function wrapMath(content, wrapType) {
15
+ var PAIRS = (0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, BracketTypes.ROUND_BRACKETS, ['\\(', '\\)']), BracketTypes.SQUARE_BRACKETS, ['\\[', '\\]']), BracketTypes.DOLLAR, ['$', '$']), BracketTypes.DOUBLE_DOLLAR, ['$$', '$$']);
16
+ var wrapMath = exports.wrapMath = function wrapMath(content, wrapType) {
25
17
  if (wrapType === BracketTypes.SQUARE_BRACKETS) {
26
18
  console.warn('\\[...\\] is not supported yet'); // eslint-disable-line
27
-
28
19
  wrapType = BracketTypes.ROUND_BRACKETS;
29
20
  }
30
-
31
21
  if (wrapType === BracketTypes.DOUBLE_DOLLAR) {
32
22
  console.warn('$$...$$ is not supported yet'); // eslint-disable-line
33
-
34
23
  wrapType = BracketTypes.DOLLAR;
35
24
  }
36
-
37
25
  var _ref = PAIRS[wrapType] || PAIRS[BracketTypes.ROUND_BRACKETS],
38
- _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
39
- start = _ref2[0],
40
- end = _ref2[1];
41
-
26
+ _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
27
+ start = _ref2[0],
28
+ end = _ref2[1];
42
29
  return "".concat(start).concat(content).concat(end);
43
30
  };
44
-
45
- exports.wrapMath = wrapMath;
46
-
47
- var unWrapMath = function unWrapMath(content) {
31
+ var unWrapMath = exports.unWrapMath = function unWrapMath(content) {
48
32
  var displayStyleIndex = content.indexOf('\\displaystyle');
49
-
50
33
  if (displayStyleIndex !== -1) {
51
34
  console.warn('\\displaystyle is not supported - removing'); // eslint-disable-line
52
-
53
35
  content = content.replace('\\displaystyle', '').trim();
54
36
  }
55
-
56
37
  if (content.startsWith('$$') && content.endsWith('$$')) {
57
38
  console.warn('$$ syntax is not yet supported'); // eslint-disable-line
58
-
59
39
  return {
60
40
  unwrapped: content.substring(2, content.length - 2),
61
41
  wrapType: BracketTypes.DOLLAR
62
42
  };
63
43
  }
64
-
65
44
  if (content.startsWith('$') && content.endsWith('$')) {
66
45
  return {
67
46
  unwrapped: content.substring(1, content.length - 1),
68
47
  wrapType: BracketTypes.DOLLAR
69
48
  };
70
49
  }
71
-
72
50
  if (content.startsWith('\\[') && content.endsWith('\\]')) {
73
51
  console.warn('\\[..\\] syntax is not yet supported'); // eslint-disable-line
74
-
75
52
  return {
76
53
  unwrapped: content.substring(2, content.length - 2),
77
54
  wrapType: BracketTypes.ROUND_BRACKETS
78
55
  };
79
56
  }
80
-
81
57
  if (content.startsWith('\\(') && content.endsWith('\\)')) {
82
58
  return {
83
59
  unwrapped: content.substring(2, content.length - 2),
84
60
  wrapType: BracketTypes.ROUND_BRACKETS
85
61
  };
86
62
  }
87
-
88
63
  return {
89
64
  unwrapped: content,
90
65
  wrapType: BracketTypes.ROUND_BRACKETS
91
66
  };
92
67
  };
93
-
94
- exports.unWrapMath = unWrapMath;
95
68
  //# sourceMappingURL=normalization.js.map
@@ -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":";;;;;;;;;;;;;;;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,0DACRL,YAAY,CAACC,cADL,EACsB,CAAC,KAAD,EAAQ,KAAR,CADtB,4CAERD,YAAY,CAACE,eAFL,EAEuB,CAAC,KAAD,EAAQ,KAAR,CAFvB,4CAGRF,YAAY,CAACG,MAHL,EAGc,CAAC,GAAD,EAAM,GAAN,CAHd,4CAIRH,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,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,OAAO,CAACc,SAAR,CAAkB,CAAlB,EAAqBd,OAAO,CAACe,MAAR,GAAiB,CAAtC,CADN;AAELd,MAAAA,QAAQ,EAAER,YAAY,CAACG;AAFlB,KAAP;AAID;;AAED,MAAII,OAAO,CAACW,UAAR,CAAmB,KAAnB,KAA6BX,OAAO,CAACY,QAAR,CAAiB,KAAjB,CAAjC,EAA0D;AACxDV,IAAAA,OAAO,CAACC,IAAR,CAAa,sCAAb,EADwD,CACF;;AACtD,WAAO;AACLU,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,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"}
1
+ {"version":3,"file":"normalization.js","names":["BracketTypes","exports","ROUND_BRACKETS","SQUARE_BRACKETS","DOLLAR","DOUBLE_DOLLAR","PAIRS","_defineProperty2","wrapMath","content","wrapType","console","warn","_ref","_ref2","_slicedToArray2","start","end","concat","unWrapMath","displayStyleIndex","indexOf","replace","trim","startsWith","endsWith","unwrapped","substring","length"],"sources":["../src/normalization.js"],"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"],"mappings":";;;;;;;;;AAAO,IAAMA,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,CAAC,CAAC;AAE9BA,YAAY,CAACE,cAAc,GAAG,gBAAgB;AAC9CF,YAAY,CAACG,eAAe,GAAG,iBAAiB;AAChDH,YAAY,CAACI,MAAM,GAAG,QAAQ;AAC9BJ,YAAY,CAACK,aAAa,GAAG,eAAe;AAE5C,IAAMC,KAAK,OAAAC,gBAAA,iBAAAA,gBAAA,iBAAAA,gBAAA,iBAAAA,gBAAA,iBACRP,YAAY,CAACE,cAAc,EAAG,CAAC,KAAK,EAAE,KAAK,CAAC,GAC5CF,YAAY,CAACG,eAAe,EAAG,CAAC,KAAK,EAAE,KAAK,CAAC,GAC7CH,YAAY,CAACI,MAAM,EAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAChCJ,YAAY,CAACK,aAAa,EAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAC3C;AAEM,IAAMG,QAAQ,GAAAP,OAAA,CAAAO,QAAA,GAAG,SAAXA,QAAQA,CAAIC,OAAO,EAAEC,QAAQ,EAAK;EAC7C,IAAIA,QAAQ,KAAKV,YAAY,CAACG,eAAe,EAAE;IAC7CQ,OAAO,CAACC,IAAI,CAAC,gCAAgC,CAAC,CAAC,CAAC;IAChDF,QAAQ,GAAGV,YAAY,CAACE,cAAc;EACxC;EACA,IAAIQ,QAAQ,KAAKV,YAAY,CAACK,aAAa,EAAE;IAC3CM,OAAO,CAACC,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;IAC9CF,QAAQ,GAAGV,YAAY,CAACI,MAAM;EAChC;EAEA,IAAAS,IAAA,GAAqBP,KAAK,CAACI,QAAQ,CAAC,IAAIJ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AACgB,QAAQ,CAAC,KAAK,CAAC,EAAE;IACxDd,OAAO,CAACC,IAAI,CAAC,sCAAsC,CAAC,CAAC,CAAC;IACtD,OAAO;MACLc,SAAS,EAAEjB,OAAO,CAACkB,SAAS,CAAC,CAAC,EAAElB,OAAO,CAACmB,MAAM,GAAG,CAAC,CAAC;MACnDlB,QAAQ,EAAEV,YAAY,CAACE;IACzB,CAAC;EACH;EAEA,IAAIO,OAAO,CAACe,UAAU,CAAC,KAAK,CAAC,IAAIf,OAAO,CAACgB,QAAQ,CAAC,KAAK,CAAC,EAAE;IACxD,OAAO;MACLC,SAAS,EAAEjB,OAAO,CAACkB,SAAS,CAAC,CAAC,EAAElB,OAAO,CAACmB,MAAM,GAAG,CAAC,CAAC;MACnDlB,QAAQ,EAAEV,YAAY,CAACE;IACzB,CAAC;EACH;EAEA,OAAO;IACLwB,SAAS,EAAEjB,OAAO;IAClBC,QAAQ,EAAEV,YAAY,CAACE;EACzB,CAAC;AACH,CAAC","ignoreList":[]}
@@ -1,34 +1,24 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.initializeMathJax = exports.getGlobal = exports.fixMathElements = exports.fixMathElement = exports["default"] = exports.MathJaxVersion = void 0;
9
-
10
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
-
12
9
  var _normalization = require("./normalization");
13
-
14
10
  var _SerializedMmlVisitor = require("mathjax-full/js/core/MmlTree/SerializedMmlVisitor");
15
-
16
11
  var _TexError = _interopRequireDefault(require("mathjax-full/js/input/tex/TexError"));
17
-
18
12
  var visitor = new _SerializedMmlVisitor.SerializedMmlVisitor();
19
-
20
13
  var toMMl = function toMMl(node) {
21
14
  return visitor.visitTree(node);
22
15
  };
23
-
24
16
  var NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
25
17
  var NEWLINE_LATEX = '\\newline ';
26
18
  var mathRenderingKEY = '@pie-lib/math-rendering@2';
27
19
  var mathRenderingAccessibleKEY = '@pie-lib/math-rendering-accessible@1';
28
- var MathJaxVersion = '3.2.2';
29
- exports.MathJaxVersion = MathJaxVersion;
30
-
31
- var getGlobal = function getGlobal() {
20
+ var MathJaxVersion = exports.MathJaxVersion = '3.2.2';
21
+ var getGlobal = exports.getGlobal = function getGlobal() {
32
22
  // TODO does it make sense to use version?
33
23
  // const key = `${pkg.name}@${pkg.version.split('.')[0]}`;
34
24
  // It looks like Ed made this change when he switched from mathjax3 to mathjax-full
@@ -40,47 +30,34 @@ var getGlobal = function getGlobal() {
40
30
  if (!window[mathRenderingAccessibleKEY]) {
41
31
  window[mathRenderingAccessibleKEY] = {};
42
32
  }
43
-
44
33
  return window[mathRenderingAccessibleKEY];
45
34
  } else {
46
35
  return {};
47
36
  }
48
37
  };
49
-
50
- exports.getGlobal = getGlobal;
51
-
52
- var fixMathElement = function fixMathElement(element) {
38
+ var fixMathElement = exports.fixMathElement = function fixMathElement(element) {
53
39
  if (element.dataset.mathHandled) {
54
40
  return;
55
41
  }
56
-
57
42
  var property = 'innerText';
58
-
59
43
  if (element.textContent) {
60
44
  property = 'textContent';
61
45
  }
62
-
63
46
  if (element[property]) {
64
- element[property] = (0, _normalization.wrapMath)((0, _normalization.unWrapMath)(element[property]).unwrapped); // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.
47
+ element[property] = (0, _normalization.wrapMath)((0, _normalization.unWrapMath)(element[property]).unwrapped);
48
+ // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.
65
49
  // we need to replace the custom embedded elements with valid latex that Mathjax can understand
66
-
67
50
  element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);
68
51
  element.dataset.mathHandled = true;
69
52
  }
70
53
  };
71
-
72
- exports.fixMathElement = fixMathElement;
73
-
74
- var fixMathElements = function fixMathElements() {
54
+ var fixMathElements = exports.fixMathElements = function fixMathElements() {
75
55
  var el = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
76
56
  var mathElements = el.querySelectorAll('[data-latex]');
77
57
  mathElements.forEach(function (item) {
78
58
  return fixMathElement(item);
79
59
  });
80
60
  };
81
-
82
- exports.fixMathElements = fixMathElements;
83
-
84
61
  var adjustMathMLStyle = function adjustMathMLStyle() {
85
62
  var el = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
86
63
  var nodes = el.querySelectorAll('math');
@@ -88,43 +65,36 @@ var adjustMathMLStyle = function adjustMathMLStyle() {
88
65
  return node.setAttribute('displaystyle', 'true');
89
66
  });
90
67
  };
91
-
92
68
  var createPlaceholder = function createPlaceholder(element) {
93
69
  var _element$previousSibl;
94
-
95
70
  if (!element.previousSibling || !((_element$previousSibl = element.previousSibling.classList) !== null && _element$previousSibl !== void 0 && _element$previousSibl.contains('math-placeholder'))) {
96
71
  var _element$parentNode;
97
-
98
72
  // Store the original display style before setting it to 'none'
99
73
  element.dataset.originalDisplay = element.style.display || '';
100
74
  element.style.display = 'none';
101
75
  var placeholder = document.createElement('span');
102
76
  placeholder.style.cssText = 'height: 10px; width: 50px; display: inline-block; vertical-align: middle; justify-content: center; background: #fafafa; border-radius: 4px;';
103
77
  placeholder.classList.add('math-placeholder');
104
- (_element$parentNode = element.parentNode) === null || _element$parentNode === void 0 ? void 0 : _element$parentNode.insertBefore(placeholder, element);
78
+ (_element$parentNode = element.parentNode) === null || _element$parentNode === void 0 || _element$parentNode.insertBefore(placeholder, element);
105
79
  }
106
80
  };
107
-
108
81
  var removePlaceholdersAndRestoreDisplay = function removePlaceholdersAndRestoreDisplay() {
109
82
  document.querySelectorAll('.math-placeholder').forEach(function (placeholder) {
110
83
  var _targetElement$datase;
111
-
112
84
  var targetElement = placeholder.nextElementSibling;
113
-
114
85
  if (targetElement && ((_targetElement$datase = targetElement.dataset) === null || _targetElement$datase === void 0 ? void 0 : _targetElement$datase.originalDisplay) !== undefined) {
115
86
  targetElement.style.display = targetElement.dataset.originalDisplay;
116
87
  delete targetElement.dataset.originalDisplay;
117
88
  }
118
-
119
89
  placeholder.remove();
120
90
  });
121
91
  };
122
-
123
92
  var removeExcessMjxContainers = function removeExcessMjxContainers(content) {
124
93
  var elements = content.querySelectorAll('[data-latex][data-math-handled="true"]');
125
94
  elements.forEach(function (element) {
126
- var mjxContainers = element.querySelectorAll('mjx-container'); // Check if there are more than one mjx-container children.
95
+ var mjxContainers = element.querySelectorAll('mjx-container');
127
96
 
97
+ // Check if there are more than one mjx-container children.
128
98
  if (mjxContainers.length > 1) {
129
99
  for (var i = 1; i < mjxContainers.length; i++) {
130
100
  mjxContainers[i].parentNode.removeChild(mjxContainers[i]);
@@ -132,7 +102,6 @@ var removeExcessMjxContainers = function removeExcessMjxContainers(content) {
132
102
  }
133
103
  });
134
104
  };
135
-
136
105
  var renderContentsWithMathJax = function renderContentsWithMathJax(el) {
137
106
  // el sometimes is an array
138
107
  // renderMath is used like that in pie-print-support and pie-element-extensions
@@ -145,52 +114,54 @@ var renderContentsWithMathJax = function renderContentsWithMathJax(el) {
145
114
  renderContentWithMathJax(el);
146
115
  }
147
116
  };
148
-
149
117
  var renderContentWithMathJax = function renderContentWithMathJax(executeOn) {
150
- executeOn = executeOn || document.body; // this happens for charting - mark-label; we receive a ref which is not yet ready ( el = { current: null })
151
- // we have to fix this in charting
118
+ executeOn = executeOn || document.body;
152
119
 
120
+ // this happens for charting - mark-label; we receive a ref which is not yet ready ( el = { current: null })
121
+ // we have to fix this in charting
153
122
  if (!(executeOn instanceof HTMLElement)) return;
154
123
  fixMathElements(executeOn);
155
124
  adjustMathMLStyle(executeOn);
156
125
  var mathJaxInstance = getGlobal().instance;
157
-
158
126
  if (mathJaxInstance) {
159
127
  // Reset and clear typesetting before processing the new content
160
128
  // Reset the tex labels (and automatic equation number).
161
- mathJaxInstance.texReset(); // Reset the typesetting system (font caches, etc.)
162
129
 
163
- mathJaxInstance.typesetClear(); // Use typesetPromise for asynchronous typesetting
130
+ mathJaxInstance.texReset();
131
+
132
+ // Reset the typesetting system (font caches, etc.)
133
+ mathJaxInstance.typesetClear();
134
+
135
+ // Use typesetPromise for asynchronous typesetting
164
136
  // Using MathJax.typesetPromise() for asynchronous typesetting to handle situations where additional code needs to be loaded (e.g., for certain TeX commands or characters).
165
137
  // This ensures typesetting waits for any needed resources to load and complete processing, unlike the synchronous MathJax.typeset() which can't handle such dynamic loading.
166
-
167
138
  mathJaxInstance.typesetPromise([executeOn]).then(function () {
168
139
  try {
169
140
  removePlaceholdersAndRestoreDisplay();
170
141
  removeExcessMjxContainers(executeOn);
171
142
  var updatedDocument = mathJaxInstance.startup.document;
172
143
  var list = updatedDocument.math.list;
173
-
174
144
  for (var item = list.next; (0, _typeof2["default"])(item.data) !== 'symbol'; item = item.next) {
175
145
  var mathMl = toMMl(item.data.root);
176
146
  var parsedMathMl = mathMl.replaceAll('\n', '');
177
147
  item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);
178
148
  item.data.typesetRoot.setAttribute('tabindex', '-1');
179
- } // If the original input was a string, return the parsed MathML
149
+ }
180
150
 
151
+ // If the original input was a string, return the parsed MathML
181
152
  } catch (e) {
182
153
  console.error('Error post-processing MathJax typesetting:', e.toString());
183
- } // Clearing the document if needed
184
-
154
+ }
185
155
 
156
+ // Clearing the document if needed
186
157
  mathJaxInstance.startup.document.clear();
187
158
  })["catch"](function (error) {
188
159
  // If there was an internal error, put the message into the output instead
160
+
189
161
  console.error('Error in typesetting with MathJax:', error);
190
162
  });
191
163
  }
192
164
  };
193
-
194
165
  var convertMathJax2ToMathJax3 = function convertMathJax2ToMathJax3() {
195
166
  // Make MathJax v2 compatible with v3
196
167
  // https://docs.mathjax.org/en/v3.2-latest/upgrading/v2.html#version-2-compatibility-example
@@ -202,24 +173,22 @@ var convertMathJax2ToMathJax3 = function convertMathJax2ToMathJax3() {
202
173
  var RequireMethods = {
203
174
  Require: function Require(parser, name) {
204
175
  var required = parser.GetArgument(name);
205
-
206
176
  if (required.match(/[^_a-zA-Z0-9]/) || required === '') {
207
177
  throw new _TexError["default"]('BadPackageName', 'Argument for %1 is not a valid package name', name);
208
178
  }
209
-
210
179
  if (requireMap.hasOwnProperty(required)) {
211
180
  required = requireMap[required];
212
181
  }
213
-
214
182
  RequireLoad(parser, required);
215
183
  }
216
184
  };
217
185
  new CommandMap('require', {
218
186
  require: 'Require'
219
- }, RequireMethods); //
187
+ }, RequireMethods);
188
+
189
+ //
220
190
  // Add a replacement for MathJax.Callback command
221
191
  //
222
-
223
192
  MathJax.Callback = function (args) {
224
193
  if (Array.isArray(args)) {
225
194
  if (args.length === 1 && typeof args[0] === 'function') {
@@ -234,29 +203,25 @@ var convertMathJax2ToMathJax3 = function convertMathJax2ToMathJax3() {
234
203
  } else if (typeof args === 'function') {
235
204
  return args;
236
205
  }
237
-
238
206
  throw Error("Can't make callback from given data");
239
- }; //
207
+ };
208
+
209
+ //
240
210
  // Add a replacement for MathJax.Hub commands
241
211
  //
242
-
243
-
244
212
  MathJax.Hub = {
245
213
  Queue: function Queue() {
246
214
  for (var i = 0, m = arguments.length; i < m; i++) {
247
215
  var fn = MathJax.Callback(arguments[i]);
248
216
  MathJax.startup.promise = MathJax.startup.promise.then(fn);
249
217
  }
250
-
251
218
  return MathJax.startup.promise;
252
219
  },
253
220
  Typeset: function Typeset(elements, callback) {
254
221
  var promise = MathJax.typesetPromise(elements);
255
-
256
222
  if (callback) {
257
223
  promise = promise.then(callback);
258
224
  }
259
-
260
225
  return promise;
261
226
  },
262
227
  Register: {
@@ -275,12 +240,10 @@ var convertMathJax2ToMathJax3 = function convertMathJax2ToMathJax3() {
275
240
  }
276
241
  };
277
242
  };
278
-
279
- var initializeMathJax = function initializeMathJax(callback) {
243
+ var initializeMathJax = exports.initializeMathJax = function initializeMathJax(callback) {
280
244
  if (window.mathjaxLoadedP) {
281
245
  return;
282
246
  }
283
-
284
247
  var PreviousMathJaxIsUsed = window.MathJax && window.MathJax.version && window.MathJax.version !== MathJaxVersion && window.MathJax.version[0] === '2';
285
248
  var texConfig = {
286
249
  macros: {
@@ -291,17 +254,15 @@ var initializeMathJax = function initializeMathJax(callback) {
291
254
  },
292
255
  displayMath: [['$$', '$$'], ['\\[', '\\]']]
293
256
  };
294
-
295
257
  if (PreviousMathJaxIsUsed) {
296
258
  texConfig.autoload = {
297
259
  color: [],
298
260
  // don't autoload the color extension
299
261
  colorv2: ['color'] // do autoload the colorv2 extension
300
-
301
262
  };
302
- } // Create a new promise that resolves when MathJax is ready
303
-
263
+ }
304
264
 
265
+ // Create a new promise that resolves when MathJax is ready
305
266
  window.mathjaxLoadedP = new Promise(function (resolve) {
306
267
  // Set up the MathJax configuration
307
268
  window.MathJax = {
@@ -322,34 +283,32 @@ var initializeMathJax = function initializeMathJax(callback) {
322
283
  if (PreviousMathJaxIsUsed) {
323
284
  convertMathJax2ToMathJax3();
324
285
  }
325
-
326
286
  var mathjax = MathJax._.mathjax.mathjax;
327
287
  var STATE = MathJax._.core.MathItem.STATE;
328
288
  var Menu = MathJax._.ui.menu.Menu.Menu;
329
289
  var rerender = Menu.prototype.rerender;
330
-
331
290
  Menu.prototype.rerender = function () {
332
291
  var _this = this;
333
-
334
292
  var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : STATE.TYPESET;
335
293
  mathjax.handleRetriesFor(function () {
336
294
  return rerender.call(_this, start);
337
295
  });
338
296
  };
339
-
340
- MathJax.startup.defaultReady(); // Set the MathJax instance in the global object
297
+ MathJax.startup.defaultReady();
298
+ // Set the MathJax instance in the global object
341
299
 
342
300
  var globalObj = getGlobal();
343
301
  globalObj.instance = MathJax;
344
302
  window.mathjaxLoadedComplete = true;
345
- console.log('MathJax has initialised!', new Date().toString()); // in this file, initializeMathJax is called with a callback that has to be executed when MathJax was loaded
303
+ console.log('MathJax has initialised!', new Date().toString());
346
304
 
305
+ // in this file, initializeMathJax is called with a callback that has to be executed when MathJax was loaded
347
306
  if (callback) {
348
307
  callback();
349
- } // but previous versions of math-rendering-accessible they're expecting window.mathjaxLoadedP to be a Promise, so we also keep the
350
- // resolve here;
351
-
308
+ }
352
309
 
310
+ // but previous versions of math-rendering-accessible they're expecting window.mathjaxLoadedP to be a Promise, so we also keep the
311
+ // resolve here;
353
312
  resolve();
354
313
  }
355
314
  },
@@ -389,31 +348,27 @@ var initializeMathJax = function initializeMathJax(callback) {
389
348
  }
390
349
  }
391
350
  }
392
- }; // Load the MathJax script
393
-
351
+ };
352
+ // Load the MathJax script
394
353
  var script = document.createElement('script');
395
354
  script.type = 'text/javascript';
396
355
  script.src = "https://cdn.jsdelivr.net/npm/mathjax@".concat(MathJaxVersion, "/es5/tex-chtml-full.js");
397
356
  script.async = true;
398
- document.head.appendChild(script); // at this time of the execution, there's no document.body; setTimeout does the trick
357
+ document.head.appendChild(script);
399
358
 
359
+ // at this time of the execution, there's no document.body; setTimeout does the trick
400
360
  setTimeout(function () {
401
361
  if (!window.mathjaxLoadedComplete) {
402
- var _document, _document$body;
403
-
404
- var mathElements = (_document = document) === null || _document === void 0 ? void 0 : (_document$body = _document.body) === null || _document$body === void 0 ? void 0 : _document$body.querySelectorAll('[data-latex]');
362
+ var _document;
363
+ var mathElements = (_document = document) === null || _document === void 0 || (_document = _document.body) === null || _document === void 0 ? void 0 : _document.querySelectorAll('[data-latex]');
405
364
  (mathElements || []).forEach(createPlaceholder);
406
365
  }
407
366
  });
408
367
  });
409
368
  };
410
-
411
- exports.initializeMathJax = initializeMathJax;
412
-
413
369
  var renderMath = function renderMath(el, renderOpts) {
414
370
  var usedForMmlOutput = typeof el === 'string';
415
371
  var executeOn = document.body;
416
-
417
372
  if (!usedForMmlOutput) {
418
373
  // If math-rendering was not available, then:
419
374
  // If window.mathjaxLoadedComplete, it means that we initialised MathJax using the function from this file,
@@ -438,7 +393,6 @@ var renderMath = function renderMath(el, renderOpts) {
438
393
  var div = document.createElement('div');
439
394
  div.innerHTML = el;
440
395
  executeOn = div;
441
-
442
396
  try {
443
397
  MathJax.texReset();
444
398
  MathJax.typesetClear();
@@ -452,15 +406,13 @@ var renderMath = function renderMath(el, renderOpts) {
452
406
  } catch (error) {
453
407
  console.error('Error rendering math:', error.message);
454
408
  }
455
-
456
409
  return el;
457
410
  }
458
-
459
411
  return el;
460
412
  }
461
- }; // this function calls itself
462
-
413
+ };
463
414
 
415
+ // this function calls itself
464
416
  (function () {
465
417
  initializeMathJax(renderContentWithMathJax);
466
418
  window[mathRenderingKEY] = {
@@ -469,7 +421,5 @@ var renderMath = function renderMath(el, renderOpts) {
469
421
  }
470
422
  };
471
423
  })();
472
-
473
- var _default = renderMath;
474
- exports["default"] = _default;
424
+ var _default = exports["default"] = renderMath;
475
425
  //# sourceMappingURL=render-math.js.map