katex 0.16.32 → 0.16.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +3 -3
  2. package/contrib/auto-render/{auto-render.js → auto-render.ts} +41 -19
  3. package/contrib/auto-render/{splitAtDelimiters.js → splitAtDelimiters.ts} +18 -4
  4. package/contrib/auto-render/test/{auto-render-spec.js → auto-render-spec.ts} +10 -2
  5. package/contrib/copy-tex/README.md +2 -2
  6. package/contrib/copy-tex/{copy-tex.js → copy-tex.ts} +4 -6
  7. package/contrib/copy-tex/{katex2tex.js → katex2tex.ts} +2 -3
  8. package/contrib/mathtex-script-type/README.md +5 -5
  9. package/contrib/mhchem/README.md +1 -1
  10. package/contrib/render-a11y-string/{render-a11y-string.js → render-a11y-string.ts} +18 -33
  11. package/contrib/render-a11y-string/test/{render-a11y-string-spec.js → render-a11y-string-spec.ts} +0 -1
  12. package/dist/README.md +3 -3
  13. package/dist/contrib/auto-render.js +24 -57
  14. package/dist/contrib/auto-render.min.js +1 -1
  15. package/dist/contrib/auto-render.mjs +16586 -210
  16. package/dist/contrib/copy-tex.js +23 -37
  17. package/dist/contrib/copy-tex.min.js +1 -1
  18. package/dist/contrib/copy-tex.mjs +77 -95
  19. package/dist/contrib/mathtex-script-type.js +0 -3
  20. package/dist/contrib/mathtex-script-type.mjs +16427 -4
  21. package/dist/contrib/mhchem.js +55 -303
  22. package/dist/contrib/mhchem.mjs +12884 -723
  23. package/dist/contrib/render-a11y-string.js +13 -108
  24. package/dist/contrib/render-a11y-string.min.js +1 -1
  25. package/dist/contrib/render-a11y-string.mjs +17020 -760
  26. package/dist/katex-swap.css +2 -1
  27. package/dist/katex-swap.min.css +1 -1
  28. package/dist/katex.css +2 -1
  29. package/dist/katex.js +4547 -5680
  30. package/dist/katex.min.css +1 -1
  31. package/dist/katex.min.js +1 -1
  32. package/dist/katex.mjs +11854 -13828
  33. package/{katex.js → katex.ts} +8 -5
  34. package/package.json +34 -31
  35. package/src/{Lexer.js → Lexer.ts} +1 -2
  36. package/src/{MacroExpander.js → MacroExpander.ts} +11 -15
  37. package/src/{Namespace.js → Namespace.ts} +4 -6
  38. package/src/{Options.js → Options.ts} +7 -12
  39. package/src/{ParseError.js → ParseError.ts} +16 -26
  40. package/src/{Parser.js → Parser.ts} +68 -56
  41. package/src/{Settings.js → Settings.ts} +70 -70
  42. package/src/{SourceLocation.js → SourceLocation.ts} +6 -7
  43. package/src/{Style.js → Style.ts} +4 -5
  44. package/src/{Token.js → Token.ts} +8 -6
  45. package/src/{buildCommon.js → buildCommon.ts} +62 -55
  46. package/src/{buildHTML.js → buildHTML.ts} +29 -25
  47. package/src/{buildMathML.js → buildMathML.ts} +15 -13
  48. package/src/{buildTree.js → buildTree.ts} +1 -2
  49. package/src/{defineEnvironment.js → defineEnvironment.ts} +26 -27
  50. package/src/{defineFunction.js → defineFunction.ts} +54 -56
  51. package/src/{defineMacro.js → defineMacro.ts} +12 -13
  52. package/src/{delimiter.js → delimiter.ts} +19 -17
  53. package/src/{domTree.js → domTree.ts} +94 -103
  54. package/src/environments/{array.js → array.ts} +109 -99
  55. package/src/environments/{cd.js → cd.ts} +9 -11
  56. package/src/{environments.js → environments.ts} +0 -1
  57. package/src/{fontMetrics.js → fontMetrics.ts} +10 -12
  58. package/src/fontMetricsData.d.ts +3 -0
  59. package/src/functions/{accent.js → accent.ts} +1 -2
  60. package/src/functions/{accentunder.js → accentunder.ts} +0 -1
  61. package/src/functions/{arrow.js → arrow.ts} +4 -6
  62. package/src/functions/{char.js → char.ts} +0 -1
  63. package/src/functions/{color.js → color.ts} +5 -6
  64. package/src/functions/{cr.js → cr.ts} +0 -1
  65. package/src/functions/{def.js → def.ts} +9 -7
  66. package/src/functions/{delimsizing.js → delimsizing.ts} +11 -9
  67. package/src/functions/{enclose.js → enclose.ts} +3 -4
  68. package/src/functions/{environment.js → environment.ts} +2 -3
  69. package/src/functions/{font.js → font.ts} +4 -4
  70. package/src/functions/{genfrac.js → genfrac.ts} +14 -15
  71. package/src/functions/{hbox.js → hbox.ts} +0 -1
  72. package/src/functions/{horizBrace.js → horizBrace.ts} +4 -5
  73. package/src/functions/{href.js → href.ts} +4 -4
  74. package/src/functions/{html.js → html.ts} +3 -3
  75. package/src/functions/{htmlmathml.js → htmlmathml.ts} +0 -1
  76. package/src/functions/{includegraphics.js → includegraphics.ts} +0 -1
  77. package/src/functions/{kern.js → kern.ts} +0 -1
  78. package/src/functions/{lap.js → lap.ts} +0 -1
  79. package/src/functions/{math.js → math.ts} +0 -1
  80. package/src/functions/{mathchoice.js → mathchoice.ts} +2 -2
  81. package/src/functions/{mclass.js → mclass.ts} +5 -6
  82. package/src/functions/{op.js → op.ts} +9 -11
  83. package/src/functions/{operatorname.js → operatorname.ts} +4 -7
  84. package/src/functions/{ordgroup.js → ordgroup.ts} +0 -2
  85. package/src/functions/{overline.js → overline.ts} +0 -1
  86. package/src/functions/{phantom.js → phantom.ts} +0 -1
  87. package/src/functions/{pmb.js → pmb.ts} +0 -1
  88. package/src/functions/{raisebox.js → raisebox.ts} +0 -1
  89. package/src/functions/{relax.js → relax.ts} +0 -1
  90. package/src/functions/{rule.js → rule.ts} +0 -1
  91. package/src/functions/{sizing.js → sizing.ts} +0 -1
  92. package/src/functions/{smash.js → smash.ts} +2 -4
  93. package/src/functions/{sqrt.js → sqrt.ts} +0 -1
  94. package/src/functions/{styling.js → styling.ts} +3 -3
  95. package/src/functions/{supsub.js → supsub.ts} +6 -8
  96. package/src/functions/{symbolsOp.js → symbolsOp.ts} +0 -2
  97. package/src/functions/{symbolsOrd.js → symbolsOrd.ts} +1 -2
  98. package/src/functions/{symbolsSpacing.js → symbolsSpacing.ts} +2 -3
  99. package/src/functions/{tag.js → tag.ts} +0 -2
  100. package/src/functions/{text.js → text.ts} +7 -6
  101. package/src/functions/{underline.js → underline.ts} +0 -1
  102. package/src/functions/utils/{assembleSupSub.js → assembleSupSub.ts} +2 -3
  103. package/src/functions/{vcenter.js → vcenter.ts} +0 -2
  104. package/src/functions/{verb.js → verb.ts} +0 -1
  105. package/src/{functions.js → functions.ts} +0 -1
  106. package/src/{macros.js → macros.ts} +10 -8
  107. package/src/{mathMLTree.js → mathMLTree.ts} +5 -6
  108. package/src/parseNode.ts +522 -0
  109. package/src/{parseTree.js → parseTree.ts} +5 -3
  110. package/src/{spacingData.js → spacingData.ts} +11 -12
  111. package/src/{stretchy.js → stretchy.ts} +7 -7
  112. package/src/styles/katex-swap.scss +1 -4
  113. package/src/styles/katex.scss +9 -0
  114. package/src/{svgGeometry.js → svgGeometry.ts} +1 -2
  115. package/src/{symbols.js → symbols.ts} +6 -6
  116. package/src/{tree.js → tree.ts} +5 -7
  117. package/src/{types.js → types.ts} +1 -2
  118. package/src/unicodeAccents.js +4 -1
  119. package/src/{unicodeScripts.js → unicodeScripts.ts} +1 -3
  120. package/src/{unicodeSupOrSub.js → unicodeSupOrSub.ts} +1 -1
  121. package/src/unicodeSymbols.js +4 -3
  122. package/src/{units.js → units.ts} +2 -4
  123. package/src/{utils.js → utils.ts} +2 -3
  124. package/src/{wide-character.js → wide-character.ts} +8 -10
  125. package/types/katex.d.ts +13 -12
  126. package/src/parseNode.js +0 -523
@@ -12,112 +12,98 @@ return /******/ (function() { // webpackBootstrap
12
12
  /******/ "use strict";
13
13
  var __webpack_exports__ = {};
14
14
 
15
- ;// ./contrib/copy-tex/katex2tex.js
15
+ ;// ./contrib/copy-tex/katex2tex.ts
16
16
  // Set these to how you want inline and display math to be delimited.
17
17
  const defaultCopyDelimiters = {
18
18
  inline: ['$', '$'],
19
19
  // alternative: ['\(', '\)']
20
20
  display: ['$$', '$$'] // alternative: ['\[', '\]']
21
+ };
21
22
 
22
- }; // Replace .katex elements with their TeX source (<annotation> element).
23
+ // Replace .katex elements with their TeX source (<annotation> element).
23
24
  // Modifies fragment in-place. Useful for writing your own 'copy' handler,
24
25
  // as in copy-tex.js.
25
-
26
26
  function katexReplaceWithTex(fragment, copyDelimiters) {
27
27
  if (copyDelimiters === void 0) {
28
28
  copyDelimiters = defaultCopyDelimiters;
29
29
  }
30
-
31
30
  // Remove .katex-html blocks that are preceded by .katex-mathml blocks
32
31
  // (which will get replaced below).
33
32
  const katexHtml = fragment.querySelectorAll('.katex-mathml + .katex-html');
34
-
35
33
  for (let i = 0; i < katexHtml.length; i++) {
36
34
  const element = katexHtml[i];
37
-
38
35
  if (element.remove) {
39
36
  element.remove();
40
37
  } else if (element.parentNode) {
41
38
  element.parentNode.removeChild(element);
42
39
  }
43
- } // Replace .katex-mathml elements with their annotation (TeX source)
40
+ }
41
+ // Replace .katex-mathml elements with their annotation (TeX source)
44
42
  // descendant, with inline delimiters.
45
-
46
-
47
43
  const katexMathml = fragment.querySelectorAll('.katex-mathml');
48
-
49
44
  for (let i = 0; i < katexMathml.length; i++) {
50
45
  const element = katexMathml[i];
51
46
  const texSource = element.querySelector('annotation');
52
-
53
47
  if (texSource) {
54
48
  if (element.replaceWith) {
55
49
  element.replaceWith(texSource);
56
50
  } else if (element.parentNode) {
57
51
  element.parentNode.replaceChild(texSource, element);
58
52
  }
59
-
60
53
  texSource.innerHTML = copyDelimiters.inline[0] + texSource.innerHTML + copyDelimiters.inline[1];
61
54
  }
62
- } // Switch display math to display delimiters.
63
-
64
-
55
+ }
56
+ // Switch display math to display delimiters.
65
57
  const displays = fragment.querySelectorAll('.katex-display annotation');
66
-
67
58
  for (let i = 0; i < displays.length; i++) {
68
59
  const element = displays[i];
69
60
  element.innerHTML = copyDelimiters.display[0] + element.innerHTML.substr(copyDelimiters.inline[0].length, element.innerHTML.length - copyDelimiters.inline[0].length - copyDelimiters.inline[1].length) + copyDelimiters.display[1];
70
61
  }
71
-
72
62
  return fragment;
73
63
  }
74
64
  /* harmony default export */ var katex2tex = (katexReplaceWithTex);
75
- ;// ./contrib/copy-tex/copy-tex.js
76
- // Return <div class="katex"> element containing node, or null if not found.
65
+ ;// ./contrib/copy-tex/copy-tex.ts
77
66
 
67
+
68
+ // Return <div class="katex"> element containing node, or null if not found.
78
69
  function closestKatex(node) {
79
70
  // If node is a Text Node, for example, go up to containing Element,
80
71
  // where we can apply the `closest` method.
81
72
  const element = node instanceof Element ? node : node.parentElement;
82
73
  return element && element.closest('.katex');
83
- } // Global copy handler to modify behavior on/within .katex elements.
84
-
74
+ }
85
75
 
76
+ // Global copy handler to modify behavior on/within .katex elements.
86
77
  document.addEventListener('copy', function (event) {
87
78
  const selection = window.getSelection();
88
-
89
- if (selection.isCollapsed || !event.clipboardData) {
79
+ if (!selection || selection.isCollapsed || !event.clipboardData) {
90
80
  return; // default action OK if selection is empty or unchangeable
91
81
  }
92
-
93
82
  const clipboardData = event.clipboardData;
94
- const range = selection.getRangeAt(0); // When start point is within a formula, expand to entire formula.
83
+ const range = selection.getRangeAt(0);
95
84
 
85
+ // When start point is within a formula, expand to entire formula.
96
86
  const startKatex = closestKatex(range.startContainer);
97
-
98
87
  if (startKatex) {
99
88
  range.setStartBefore(startKatex);
100
- } // Similarly, when end point is within a formula, expand to entire formula.
101
-
89
+ }
102
90
 
91
+ // Similarly, when end point is within a formula, expand to entire formula.
103
92
  const endKatex = closestKatex(range.endContainer);
104
-
105
93
  if (endKatex) {
106
94
  range.setEndAfter(endKatex);
107
95
  }
108
-
109
96
  const fragment = range.cloneContents();
110
-
111
97
  if (!fragment.querySelector('.katex-mathml')) {
112
98
  return; // default action OK if no .katex-mathml elements
113
99
  }
100
+ const htmlContents = Array.prototype.map.call(fragment.childNodes, el => el instanceof Text ? el.textContent : el.outerHTML).join('');
114
101
 
115
- const htmlContents = Array.prototype.map.call(fragment.childNodes, el => el instanceof Text ? el.textContent : el.outerHTML).join(''); // Preserve usual HTML copy/paste behavior.
116
-
117
- clipboardData.setData('text/html', htmlContents); // Rewrite plain-text version.
118
-
119
- clipboardData.setData('text/plain', katex2tex(fragment).textContent); // Prevent normal copy handling.
120
-
102
+ // Preserve usual HTML copy/paste behavior.
103
+ clipboardData.setData('text/html', htmlContents);
104
+ // Rewrite plain-text version.
105
+ clipboardData.setData('text/plain', katex2tex(fragment).textContent);
106
+ // Prevent normal copy handling.
121
107
  event.preventDefault();
122
108
  });
123
109
  __webpack_exports__ = __webpack_exports__["default"];
@@ -1 +1 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}("undefined"!=typeof self?self:this,function(){return function(){"use strict";var e={};const t={inline:["$","$"],display:["$$","$$"]};var n=function(e,n){void 0===n&&(n=t);const o=e.querySelectorAll(".katex-mathml + .katex-html");for(let e=0;e<o.length;e++){const t=o[e];t.remove?t.remove():t.parentNode&&t.parentNode.removeChild(t)}const r=e.querySelectorAll(".katex-mathml");for(let e=0;e<r.length;e++){const t=r[e],o=t.querySelector("annotation");o&&(t.replaceWith?t.replaceWith(o):t.parentNode&&t.parentNode.replaceChild(o,t),o.innerHTML=n.inline[0]+o.innerHTML+n.inline[1])}const l=e.querySelectorAll(".katex-display annotation");for(let e=0;e<l.length;e++){const t=l[e];t.innerHTML=n.display[0]+t.innerHTML.substr(n.inline[0].length,t.innerHTML.length-n.inline[0].length-n.inline[1].length)+n.display[1]}return e};function o(e){const t=e instanceof Element?e:e.parentElement;return t&&t.closest(".katex")}return document.addEventListener("copy",function(e){const t=window.getSelection();if(t.isCollapsed||!e.clipboardData)return;const r=e.clipboardData,l=t.getRangeAt(0),i=o(l.startContainer);i&&l.setStartBefore(i);const a=o(l.endContainer);a&&l.setEndAfter(a);const s=l.cloneContents();if(!s.querySelector(".katex-mathml"))return;const c=Array.prototype.map.call(s.childNodes,e=>e instanceof Text?e.textContent:e.outerHTML).join("");r.setData("text/html",c),r.setData("text/plain",n(s).textContent),e.preventDefault()}),e=e.default}()});
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}("undefined"!=typeof self?self:this,function(){return function(){"use strict";var e={};const t={inline:["$","$"],display:["$$","$$"]};var n=function(e,n){void 0===n&&(n=t);const o=e.querySelectorAll(".katex-mathml + .katex-html");for(let e=0;e<o.length;e++){const t=o[e];t.remove?t.remove():t.parentNode&&t.parentNode.removeChild(t)}const r=e.querySelectorAll(".katex-mathml");for(let e=0;e<r.length;e++){const t=r[e],o=t.querySelector("annotation");o&&(t.replaceWith?t.replaceWith(o):t.parentNode&&t.parentNode.replaceChild(o,t),o.innerHTML=n.inline[0]+o.innerHTML+n.inline[1])}const l=e.querySelectorAll(".katex-display annotation");for(let e=0;e<l.length;e++){const t=l[e];t.innerHTML=n.display[0]+t.innerHTML.substr(n.inline[0].length,t.innerHTML.length-n.inline[0].length-n.inline[1].length)+n.display[1]}return e};function o(e){const t=e instanceof Element?e:e.parentElement;return t&&t.closest(".katex")}return document.addEventListener("copy",function(e){const t=window.getSelection();if(!t||t.isCollapsed||!e.clipboardData)return;const r=e.clipboardData,l=t.getRangeAt(0),i=o(l.startContainer);i&&l.setStartBefore(i);const a=o(l.endContainer);a&&l.setEndAfter(a);const s=l.cloneContents();if(!s.querySelector(".katex-mathml"))return;const c=Array.prototype.map.call(s.childNodes,e=>e instanceof Text?e.textContent:e.outerHTML).join("");r.setData("text/html",c),r.setData("text/plain",n(s).textContent),e.preventDefault()}),e=e.default}()});
@@ -1,105 +1,87 @@
1
1
  // Set these to how you want inline and display math to be delimited.
2
- var defaultCopyDelimiters = {
3
- inline: ['$', '$'],
4
- // alternative: ['\(', '\)']
5
- display: ['$$', '$$'] // alternative: ['\[', '\]']
6
-
7
- }; // Replace .katex elements with their TeX source (<annotation> element).
2
+ const defaultCopyDelimiters = {
3
+ inline: ['$', '$'], // alternative: ['\(', '\)']
4
+ display: ['$$', '$$'], // alternative: ['\[', '\]']
5
+ };
6
+ // Replace .katex elements with their TeX source (<annotation> element).
8
7
  // Modifies fragment in-place. Useful for writing your own 'copy' handler,
9
8
  // as in copy-tex.js.
10
-
11
- function katexReplaceWithTex(fragment, copyDelimiters) {
12
- if (copyDelimiters === void 0) {
13
- copyDelimiters = defaultCopyDelimiters;
14
- }
15
-
16
- // Remove .katex-html blocks that are preceded by .katex-mathml blocks
17
- // (which will get replaced below).
18
- var katexHtml = fragment.querySelectorAll('.katex-mathml + .katex-html');
19
-
20
- for (var i = 0; i < katexHtml.length; i++) {
21
- var element = katexHtml[i];
22
-
23
- if (element.remove) {
24
- element.remove();
25
- } else if (element.parentNode) {
26
- element.parentNode.removeChild(element);
9
+ function katexReplaceWithTex(fragment, copyDelimiters = defaultCopyDelimiters) {
10
+ // Remove .katex-html blocks that are preceded by .katex-mathml blocks
11
+ // (which will get replaced below).
12
+ const katexHtml = fragment.querySelectorAll('.katex-mathml + .katex-html');
13
+ for (let i = 0; i < katexHtml.length; i++) {
14
+ const element = katexHtml[i];
15
+ if (element.remove) {
16
+ element.remove();
17
+ }
18
+ else if (element.parentNode) {
19
+ element.parentNode.removeChild(element);
20
+ }
27
21
  }
28
- } // Replace .katex-mathml elements with their annotation (TeX source)
29
- // descendant, with inline delimiters.
30
-
31
-
32
- var katexMathml = fragment.querySelectorAll('.katex-mathml');
33
-
34
- for (var _i = 0; _i < katexMathml.length; _i++) {
35
- var _element = katexMathml[_i];
36
-
37
- var texSource = _element.querySelector('annotation');
38
-
39
- if (texSource) {
40
- if (_element.replaceWith) {
41
- _element.replaceWith(texSource);
42
- } else if (_element.parentNode) {
43
- _element.parentNode.replaceChild(texSource, _element);
44
- }
45
-
46
- texSource.innerHTML = copyDelimiters.inline[0] + texSource.innerHTML + copyDelimiters.inline[1];
22
+ // Replace .katex-mathml elements with their annotation (TeX source)
23
+ // descendant, with inline delimiters.
24
+ const katexMathml = fragment.querySelectorAll('.katex-mathml');
25
+ for (let i = 0; i < katexMathml.length; i++) {
26
+ const element = katexMathml[i];
27
+ const texSource = element.querySelector('annotation');
28
+ if (texSource) {
29
+ if (element.replaceWith) {
30
+ element.replaceWith(texSource);
31
+ }
32
+ else if (element.parentNode) {
33
+ element.parentNode.replaceChild(texSource, element);
34
+ }
35
+ texSource.innerHTML = copyDelimiters.inline[0] +
36
+ texSource.innerHTML + copyDelimiters.inline[1];
37
+ }
47
38
  }
48
- } // Switch display math to display delimiters.
49
-
50
-
51
- var displays = fragment.querySelectorAll('.katex-display annotation');
52
-
53
- for (var _i2 = 0; _i2 < displays.length; _i2++) {
54
- var _element2 = displays[_i2];
55
- _element2.innerHTML = copyDelimiters.display[0] + _element2.innerHTML.substr(copyDelimiters.inline[0].length, _element2.innerHTML.length - copyDelimiters.inline[0].length - copyDelimiters.inline[1].length) + copyDelimiters.display[1];
56
- }
57
-
58
- return fragment;
39
+ // Switch display math to display delimiters.
40
+ const displays = fragment.querySelectorAll('.katex-display annotation');
41
+ for (let i = 0; i < displays.length; i++) {
42
+ const element = displays[i];
43
+ element.innerHTML = copyDelimiters.display[0] +
44
+ element.innerHTML.substr(copyDelimiters.inline[0].length, element.innerHTML.length - copyDelimiters.inline[0].length
45
+ - copyDelimiters.inline[1].length)
46
+ + copyDelimiters.display[1];
47
+ }
48
+ return fragment;
59
49
  }
60
50
 
51
+ // Return <div class="katex"> element containing node, or null if not found.
61
52
  function closestKatex(node) {
62
- // If node is a Text Node, for example, go up to containing Element,
63
- // where we can apply the `closest` method.
64
- var element = node instanceof Element ? node : node.parentElement;
65
- return element && element.closest('.katex');
66
- } // Global copy handler to modify behavior on/within .katex elements.
67
-
68
-
53
+ // If node is a Text Node, for example, go up to containing Element,
54
+ // where we can apply the `closest` method.
55
+ const element = (node instanceof Element ? node : node.parentElement);
56
+ return element && element.closest('.katex');
57
+ }
58
+ // Global copy handler to modify behavior on/within .katex elements.
69
59
  document.addEventListener('copy', function (event) {
70
- var selection = window.getSelection();
71
-
72
- if (selection.isCollapsed || !event.clipboardData) {
73
- return; // default action OK if selection is empty or unchangeable
74
- }
75
-
76
- var clipboardData = event.clipboardData;
77
- var range = selection.getRangeAt(0); // When start point is within a formula, expand to entire formula.
78
-
79
- var startKatex = closestKatex(range.startContainer);
80
-
81
- if (startKatex) {
82
- range.setStartBefore(startKatex);
83
- } // Similarly, when end point is within a formula, expand to entire formula.
84
-
85
-
86
- var endKatex = closestKatex(range.endContainer);
87
-
88
- if (endKatex) {
89
- range.setEndAfter(endKatex);
90
- }
91
-
92
- var fragment = range.cloneContents();
93
-
94
- if (!fragment.querySelector('.katex-mathml')) {
95
- return; // default action OK if no .katex-mathml elements
96
- }
97
-
98
- var htmlContents = Array.prototype.map.call(fragment.childNodes, el => el instanceof Text ? el.textContent : el.outerHTML).join(''); // Preserve usual HTML copy/paste behavior.
99
-
100
- clipboardData.setData('text/html', htmlContents); // Rewrite plain-text version.
101
-
102
- clipboardData.setData('text/plain', katexReplaceWithTex(fragment).textContent); // Prevent normal copy handling.
103
-
104
- event.preventDefault();
60
+ const selection = window.getSelection();
61
+ if (!selection || selection.isCollapsed || !event.clipboardData) {
62
+ return; // default action OK if selection is empty or unchangeable
63
+ }
64
+ const clipboardData = event.clipboardData;
65
+ const range = selection.getRangeAt(0);
66
+ // When start point is within a formula, expand to entire formula.
67
+ const startKatex = closestKatex(range.startContainer);
68
+ if (startKatex) {
69
+ range.setStartBefore(startKatex);
70
+ }
71
+ // Similarly, when end point is within a formula, expand to entire formula.
72
+ const endKatex = closestKatex(range.endContainer);
73
+ if (endKatex) {
74
+ range.setEndAfter(endKatex);
75
+ }
76
+ const fragment = range.cloneContents();
77
+ if (!fragment.querySelector('.katex-mathml')) {
78
+ return; // default action OK if no .katex-mathml elements
79
+ }
80
+ const htmlContents = Array.prototype.map.call(fragment.childNodes, (el) => (el instanceof Text ? el.textContent : el.outerHTML)).join('');
81
+ // Preserve usual HTML copy/paste behavior.
82
+ clipboardData.setData('text/html', htmlContents);
83
+ // Rewrite plain-text version.
84
+ clipboardData.setData('text/plain', katexReplaceWithTex(fragment).textContent);
85
+ // Prevent normal copy handling.
86
+ event.preventDefault();
105
87
  });
@@ -86,11 +86,9 @@ scripts.forEach(function (script) {
86
86
  if (!script.type || !script.type.match(/math\/tex/i)) {
87
87
  return -1;
88
88
  }
89
-
90
89
  const display = script.type.match(/mode\s*=\s*display(;|\s|\n|$)/) != null;
91
90
  const katexElement = document.createElement(display ? "div" : "span");
92
91
  katexElement.setAttribute("class", display ? "equation" : "inline-equation");
93
-
94
92
  try {
95
93
  katex__WEBPACK_IMPORTED_MODULE_0___default().render(script.text, katexElement, {
96
94
  displayMode: display
@@ -99,7 +97,6 @@ scripts.forEach(function (script) {
99
97
  //console.error(err); linter doesn't like this
100
98
  katexElement.textContent = script.text;
101
99
  }
102
-
103
100
  script.parentNode.replaceChild(katexElement, script);
104
101
  });
105
102
  __webpack_exports__ = __webpack_exports__["default"];