acsi-core 0.9.6 → 0.9.8
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/dist/components/MarkdownLatexRender/index.d.ts +3 -3
- package/dist/index.js +450 -61
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +450 -61
- package/dist/index.modern.js.map +1 -1
- package/dist/utils/latexExtractor.d.ts +42 -4
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -9,9 +9,7 @@ import { FormGroup, Input, Label, Modal, ModalHeader, ModalBody, ModalFooter, To
|
|
|
9
9
|
import ReactSelect, { components } from 'react-select';
|
|
10
10
|
import ReactMarkdown from 'react-markdown';
|
|
11
11
|
import remarkMath from 'remark-math';
|
|
12
|
-
import remarkGfm from 'remark-gfm';
|
|
13
12
|
import rehypeKatex from 'rehype-katex';
|
|
14
|
-
import remarkRehype from 'remark-rehype';
|
|
15
13
|
import rehypeRaw from 'rehype-raw';
|
|
16
14
|
import 'katex/dist/katex.min.css';
|
|
17
15
|
import Cookies from 'js-cookie';
|
|
@@ -690,6 +688,28 @@ function _catch(body, recover) {
|
|
|
690
688
|
return result;
|
|
691
689
|
}
|
|
692
690
|
|
|
691
|
+
function _arrayLikeToArray(r, a) {
|
|
692
|
+
(null == a || a > r.length) && (a = r.length);
|
|
693
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
694
|
+
return n;
|
|
695
|
+
}
|
|
696
|
+
function _createForOfIteratorHelperLoose(r, e) {
|
|
697
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
698
|
+
if (t) return (t = t.call(r)).next.bind(t);
|
|
699
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
700
|
+
t && (r = t);
|
|
701
|
+
var o = 0;
|
|
702
|
+
return function () {
|
|
703
|
+
return o >= r.length ? {
|
|
704
|
+
done: !0
|
|
705
|
+
} : {
|
|
706
|
+
done: !1,
|
|
707
|
+
value: r[o++]
|
|
708
|
+
};
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
712
|
+
}
|
|
693
713
|
function _extends$1() {
|
|
694
714
|
return _extends$1 = Object.assign ? Object.assign.bind() : function (n) {
|
|
695
715
|
for (var e = 1; e < arguments.length; e++) {
|
|
@@ -708,6 +728,13 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
708
728
|
}
|
|
709
729
|
return t;
|
|
710
730
|
}
|
|
731
|
+
function _unsupportedIterableToArray(r, a) {
|
|
732
|
+
if (r) {
|
|
733
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
734
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
735
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
711
738
|
|
|
712
739
|
var styles = {"core-button":"_xvNBN","primary":"_U9Qyp","secondary":"_1VzMy","text":"_pZNuj","danger":"_2uYm1","light":"_wxH5S"};
|
|
713
740
|
|
|
@@ -1669,72 +1696,434 @@ var CoreTooltip = function CoreTooltip(_ref) {
|
|
|
1669
1696
|
|
|
1670
1697
|
var LatexExtractor = /*#__PURE__*/function () {
|
|
1671
1698
|
function LatexExtractor() {}
|
|
1672
|
-
LatexExtractor.
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
if (
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1699
|
+
LatexExtractor.isLatexFormula = function isLatexFormula(text) {
|
|
1700
|
+
if (!text || text.trim().length === 0) {
|
|
1701
|
+
return false;
|
|
1702
|
+
}
|
|
1703
|
+
if (/^[a-zA-Z\s]+$/.test(text.trim()) && !/^[a-zA-Z]_|^[a-zA-Z]\^/.test(text.trim())) {
|
|
1704
|
+
return false;
|
|
1705
|
+
}
|
|
1706
|
+
if (text.length > 100 && text.split(' ').length > 15) {
|
|
1707
|
+
return false;
|
|
1708
|
+
}
|
|
1709
|
+
var englishPhrases = ['the surface of', 'acceleration caused by', 'force of gravity', 'measured value', 'approximately equal to', 'has a', 'is', 'are', 'will be', 'can be', 'may be', 'should be', 'would be'];
|
|
1710
|
+
for (var _i = 0, _englishPhrases = englishPhrases; _i < _englishPhrases.length; _i++) {
|
|
1711
|
+
var phrase = _englishPhrases[_i];
|
|
1712
|
+
if (text.toLowerCase().includes(phrase)) {
|
|
1713
|
+
return false;
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
for (var _iterator = _createForOfIteratorHelperLoose(this.LATEX_COMMANDS), _step; !(_step = _iterator()).done;) {
|
|
1717
|
+
var command = _step.value;
|
|
1718
|
+
if (text.includes(command)) {
|
|
1719
|
+
return true;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
if (/_\{[^}]*\}/.test(text) || /\^\{[^}]*\}/.test(text)) {
|
|
1723
|
+
return true;
|
|
1724
|
+
}
|
|
1725
|
+
if (/^[a-zA-Z0-9_{}\\]+\s*[=~≈]\s*[a-zA-Z0-9_{}\\+\-*/^().\s]*$/.test(text.trim())) {
|
|
1726
|
+
return true;
|
|
1727
|
+
}
|
|
1728
|
+
if (/\\/.test(text) && /[=+\-*/^_{}[\]]/.test(text)) {
|
|
1729
|
+
return true;
|
|
1730
|
+
}
|
|
1731
|
+
if (/[≈~±∞∂∇∑∏∫]/.test(text)) {
|
|
1732
|
+
return true;
|
|
1733
|
+
}
|
|
1734
|
+
if (/^[a-zA-Z0-9_{}\\]*[a-zA-Z]_[a-zA-Z0-9{}\\]*$/.test(text.trim()) || /^[a-zA-Z0-9_{}\\]*[a-zA-Z]\^[a-zA-Z0-9{}\\]*$/.test(text.trim())) {
|
|
1735
|
+
return true;
|
|
1736
|
+
}
|
|
1737
|
+
if (/^[a-zA-Z0-9_{}\\]+\/[a-zA-Z0-9_{}\\^]+$/.test(text.trim()) && /[a-zA-Z]/.test(text)) {
|
|
1738
|
+
return true;
|
|
1739
|
+
}
|
|
1740
|
+
return false;
|
|
1741
|
+
};
|
|
1742
|
+
LatexExtractor.hasAnyMathematicalContent = function hasAnyMathematicalContent(content) {
|
|
1743
|
+
if (/\\[a-zA-Z]/.test(content)) return true;
|
|
1744
|
+
if (/_\{|\^\{/.test(content)) return true;
|
|
1745
|
+
if (/[a-zA-Z]\s*=\s*[a-zA-Z0-9]/.test(content)) return true;
|
|
1746
|
+
if (/(?:Relevant|Derived)\s+equation:/i.test(content)) return true;
|
|
1747
|
+
if (/[≈~±∞∂∇∑∏∫\\]/.test(content)) return true;
|
|
1748
|
+
if (/[a-zA-Z]_[a-zA-Z0-9]/.test(content)) return true;
|
|
1749
|
+
if (/[a-zA-Z]\^[a-zA-Z0-9]/.test(content)) return true;
|
|
1750
|
+
if (/\$[^$]+\$/.test(content)) return true;
|
|
1751
|
+
return false;
|
|
1752
|
+
};
|
|
1753
|
+
LatexExtractor.isAlreadyWrapped = function isAlreadyWrapped(content) {
|
|
1754
|
+
if (/^\$[^$]+\$$/.test(content.trim())) return true;
|
|
1755
|
+
if (/^\$\$[^$]+\$\$$/.test(content.trim())) return true;
|
|
1756
|
+
return false;
|
|
1757
|
+
};
|
|
1758
|
+
LatexExtractor.extractExistingMathContent = function extractExistingMathContent(content) {
|
|
1759
|
+
var mathBlocks = [];
|
|
1760
|
+
var displayMathPattern = /\$\$([^$]+)\$\$/g;
|
|
1761
|
+
var displayMatch;
|
|
1762
|
+
while ((displayMatch = displayMathPattern.exec(content)) !== null) {
|
|
1763
|
+
mathBlocks.push({
|
|
1764
|
+
text: displayMatch[1],
|
|
1765
|
+
start: displayMatch.index,
|
|
1766
|
+
end: displayMatch.index + displayMatch[0].length,
|
|
1767
|
+
type: 'display'
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
var inlineMathPattern = /\$([^$]+)\$/g;
|
|
1771
|
+
var inlineMatch;
|
|
1772
|
+
var _loop = function _loop() {
|
|
1773
|
+
var matchStart = inlineMatch.index;
|
|
1774
|
+
var isOverlapping = mathBlocks.some(function (block) {
|
|
1775
|
+
return matchStart >= block.start && matchStart < block.end;
|
|
1776
|
+
});
|
|
1777
|
+
if (!isOverlapping) {
|
|
1778
|
+
mathBlocks.push({
|
|
1779
|
+
text: inlineMatch[1],
|
|
1780
|
+
start: inlineMatch.index,
|
|
1781
|
+
end: inlineMatch.index + inlineMatch[0].length,
|
|
1782
|
+
type: 'inline'
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
};
|
|
1786
|
+
while ((inlineMatch = inlineMathPattern.exec(content)) !== null) {
|
|
1787
|
+
_loop();
|
|
1788
|
+
}
|
|
1789
|
+
return mathBlocks.sort(function (a, b) {
|
|
1790
|
+
return a.start - b.start;
|
|
1791
|
+
});
|
|
1792
|
+
};
|
|
1793
|
+
LatexExtractor.extractLatexFormulas = function extractLatexFormulas(content) {
|
|
1794
|
+
var _this = this;
|
|
1795
|
+
var formulas = [];
|
|
1796
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(this.LATEX_PATTERNS), _step2; !(_step2 = _iterator2()).done;) {
|
|
1797
|
+
var pattern = _step2.value;
|
|
1798
|
+
var matches = content.match(pattern);
|
|
1799
|
+
if (matches) {
|
|
1800
|
+
var processedMatches = matches.map(function (match) {
|
|
1801
|
+
if (match.startsWith(',')) {
|
|
1802
|
+
return match.substring(1).trim();
|
|
1803
|
+
}
|
|
1804
|
+
if (match.endsWith(',')) {
|
|
1805
|
+
return match.substring(0, match.length - 1).trim();
|
|
1806
|
+
}
|
|
1807
|
+
return match.trim();
|
|
1808
|
+
});
|
|
1809
|
+
formulas.push.apply(formulas, processedMatches);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
var lines = content.split(/\\\\/);
|
|
1813
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(lines), _step3; !(_step3 = _iterator3()).done;) {
|
|
1814
|
+
var line = _step3.value;
|
|
1815
|
+
var trimmed = line.trim().replace(/\.$/, '');
|
|
1816
|
+
if (trimmed && this.isLatexFormula(trimmed)) {
|
|
1817
|
+
formulas.push(trimmed);
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
var commaSeparatedParts = content.split(',');
|
|
1821
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(commaSeparatedParts), _step4; !(_step4 = _iterator4()).done;) {
|
|
1822
|
+
var part = _step4.value;
|
|
1823
|
+
var _trimmed = part.trim();
|
|
1824
|
+
if (_trimmed && this.isLatexFormula(_trimmed)) {
|
|
1825
|
+
formulas.push(_trimmed);
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
var uniqueFormulas = Array.from(new Set(formulas));
|
|
1829
|
+
return uniqueFormulas.filter(function (formula) {
|
|
1830
|
+
return formula.length > 1 && !formula.match(/^[,\s.]*$/) && _this.isLatexFormula(formula);
|
|
1831
|
+
});
|
|
1832
|
+
};
|
|
1833
|
+
LatexExtractor.findLatexExpressions = function findLatexExpressions(content) {
|
|
1834
|
+
var expressions = [];
|
|
1835
|
+
var mathStartPatterns = [/\\[a-zA-Z]+(?:\s*\{[^}]*\})*|\\[a-zA-Z]+/g, /[a-zA-Z][_^]\{[^}]*\}/g, /[a-zA-Z][_^][a-zA-Z0-9]/g, /[≈~±∞∂∇∑∏∫]/g, /\b[a-zA-Z]+\/[a-zA-Z]+\^?\{?[0-9]+\}?/g];
|
|
1836
|
+
for (var _i2 = 0, _mathStartPatterns = mathStartPatterns; _i2 < _mathStartPatterns.length; _i2++) {
|
|
1837
|
+
var pattern = _mathStartPatterns[_i2];
|
|
1838
|
+
var match = void 0;
|
|
1839
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
1840
|
+
var startPos = match.index;
|
|
1841
|
+
var endPos = startPos + match[0].length;
|
|
1842
|
+
var remaining = content.substring(endPos);
|
|
1843
|
+
var limitedContinuationPattern = /^[\s]*[=~≈]\s*[a-zA-Z0-9_{}\\]+|^[\s]*[+\-*/]\s*[a-zA-Z0-9_{}\\]+/;
|
|
1844
|
+
var continuationMatch = remaining.match(limitedContinuationPattern);
|
|
1845
|
+
if (continuationMatch) {
|
|
1846
|
+
endPos += continuationMatch[0].length;
|
|
1847
|
+
}
|
|
1848
|
+
var expressionText = content.substring(startPos, endPos).trim();
|
|
1849
|
+
if (this.isLatexFormula(expressionText) && expressionText.length > 0) {
|
|
1850
|
+
expressions.push({
|
|
1851
|
+
text: expressionText,
|
|
1852
|
+
start: startPos,
|
|
1853
|
+
end: startPos + expressionText.length
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
var equationPattern = /\b[a-zA-Z][a-zA-Z0-9_{}\\]*\s*[=~≈]\s*[a-zA-Z0-9_{}\\+\-*/^().\s]*?\b/g;
|
|
1859
|
+
var eqMatch;
|
|
1860
|
+
while ((eqMatch = equationPattern.exec(content)) !== null) {
|
|
1861
|
+
var _expressionText = eqMatch[0].trim();
|
|
1862
|
+
if (this.isLatexFormula(_expressionText) && _expressionText.length > 3) {
|
|
1863
|
+
expressions.push({
|
|
1864
|
+
text: _expressionText,
|
|
1865
|
+
start: eqMatch.index,
|
|
1866
|
+
end: eqMatch.index + eqMatch[0].length
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
this.findKeywordSeparatedExpressions(content, expressions);
|
|
1871
|
+
expressions.sort(function (a, b) {
|
|
1872
|
+
return a.start - b.start;
|
|
1873
|
+
});
|
|
1874
|
+
var merged = [];
|
|
1875
|
+
for (var _i3 = 0, _expressions = expressions; _i3 < _expressions.length; _i3++) {
|
|
1876
|
+
var expr = _expressions[_i3];
|
|
1877
|
+
var last = merged[merged.length - 1];
|
|
1878
|
+
if (last && expr.start <= last.end) {
|
|
1879
|
+
if (this.isLatexFormula(content.substring(last.start, expr.end).trim())) {
|
|
1880
|
+
last.end = Math.max(last.end, expr.end);
|
|
1881
|
+
last.text = content.substring(last.start, last.end).trim();
|
|
1882
|
+
}
|
|
1883
|
+
} else {
|
|
1884
|
+
merged.push(expr);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
return merged;
|
|
1888
|
+
};
|
|
1889
|
+
LatexExtractor.findKeywordSeparatedExpressions = function findKeywordSeparatedExpressions(content, expressions) {
|
|
1890
|
+
var afterCommaPattern = /,\s*([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^~≈]\s*[a-zA-Z0-9_{}\\().\s]*)*)/g;
|
|
1891
|
+
var match;
|
|
1892
|
+
while ((match = afterCommaPattern.exec(content)) !== null) {
|
|
1893
|
+
var expression = match[1].trim();
|
|
1894
|
+
if (this.isLatexFormula(expression) && expression.length > 1) {
|
|
1895
|
+
var startPos = match.index + match[0].indexOf(expression);
|
|
1896
|
+
expressions.push({
|
|
1897
|
+
text: expression,
|
|
1898
|
+
start: startPos,
|
|
1899
|
+
end: startPos + expression.length
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
var beforeCommaPattern = /([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^~≈]\s*[a-zA-Z0-9_{}\\().\s]*)*)\s*,/g;
|
|
1904
|
+
while ((match = beforeCommaPattern.exec(content)) !== null) {
|
|
1905
|
+
var _expression = match[1].trim();
|
|
1906
|
+
if (this.isLatexFormula(_expression) && _expression.length > 1) {
|
|
1907
|
+
var _startPos = match.index;
|
|
1908
|
+
expressions.push({
|
|
1909
|
+
text: _expression,
|
|
1910
|
+
start: _startPos,
|
|
1911
|
+
end: _startPos + _expression.length
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
var afterToPattern = /\bto\s+([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^~≈]\s*[a-zA-Z0-9_{}\\().\s]*)*)/g;
|
|
1916
|
+
while ((match = afterToPattern.exec(content)) !== null) {
|
|
1917
|
+
var _expression2 = match[1].trim();
|
|
1918
|
+
if (this.isLatexFormula(_expression2) && _expression2.length > 1) {
|
|
1919
|
+
var _startPos2 = match.index + match[0].indexOf(_expression2);
|
|
1920
|
+
expressions.push({
|
|
1921
|
+
text: _expression2,
|
|
1922
|
+
start: _startPos2,
|
|
1923
|
+
end: _startPos2 + _expression2.length
|
|
1924
|
+
});
|
|
1682
1925
|
}
|
|
1683
|
-
|
|
1926
|
+
}
|
|
1927
|
+
var beforeToPattern = /([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^~≈]\s*[a-zA-Z0-9_{}\\().\s]*)*)\s+to\b/g;
|
|
1928
|
+
while ((match = beforeToPattern.exec(content)) !== null) {
|
|
1929
|
+
var _expression3 = match[1].trim();
|
|
1930
|
+
if (this.isLatexFormula(_expression3) && _expression3.length > 1) {
|
|
1931
|
+
var _startPos3 = match.index;
|
|
1932
|
+
expressions.push({
|
|
1933
|
+
text: _expression3,
|
|
1934
|
+
start: _startPos3,
|
|
1935
|
+
end: _startPos3 + _expression3.length
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
LatexExtractor.applyLatexFormat = function applyLatexFormat(content) {
|
|
1941
|
+
if (!content || content.trim().length === 0) {
|
|
1942
|
+
return content;
|
|
1943
|
+
}
|
|
1944
|
+
if (!this.hasAnyMathematicalContent(content)) {
|
|
1945
|
+
return content;
|
|
1946
|
+
}
|
|
1947
|
+
var existingMathBlocks = this.extractExistingMathContent(content);
|
|
1948
|
+
if (existingMathBlocks.length === 1 && existingMathBlocks[0].start === 0 && existingMathBlocks[0].end === content.length) {
|
|
1949
|
+
return content;
|
|
1950
|
+
}
|
|
1951
|
+
if (this.isAlreadyWrapped(content)) {
|
|
1952
|
+
return content;
|
|
1953
|
+
}
|
|
1954
|
+
var trimmedContent = content.trim();
|
|
1955
|
+
if (!trimmedContent.includes('\n') && this.hasAnyMathematicalContent(trimmedContent)) {
|
|
1956
|
+
var words = trimmedContent.toLowerCase().split(/\s+/);
|
|
1957
|
+
var englishWords = words.filter(function (word) {
|
|
1958
|
+
return /^[a-z]{3,}$/.test(word) && !['cos', 'sin', 'tan', 'log', 'exp', 'max', 'min'].includes(word);
|
|
1959
|
+
});
|
|
1960
|
+
if (englishWords.length === 0) {
|
|
1961
|
+
return "$$" + trimmedContent + "$$";
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
if (!trimmedContent.includes('\n') && this.isLatexFormula(trimmedContent) && !/\b(?:the|is|are|and|or|of|to|in|on|at|by|for|with|from|into|onto|upon|over|under|above|below|between|among|through|during|before|after|since|until|while|where|when|why|how|what|who|which|that|this|these|those|some|many|few|all|no|not|very|more|most|less|least|better|best|worse|worst)\b/i.test(trimmedContent)) {
|
|
1965
|
+
return "$$" + trimmedContent + "$$";
|
|
1966
|
+
}
|
|
1967
|
+
var expressions = this.findLatexExpressions(content);
|
|
1968
|
+
var newExpressions = expressions.filter(function (expr) {
|
|
1969
|
+
return !existingMathBlocks.some(function (mathBlock) {
|
|
1970
|
+
return expr.start >= mathBlock.start && expr.end <= mathBlock.end;
|
|
1971
|
+
});
|
|
1972
|
+
});
|
|
1973
|
+
if (newExpressions.length === 0) {
|
|
1974
|
+
return content;
|
|
1975
|
+
}
|
|
1976
|
+
var result = content;
|
|
1977
|
+
var offset = 0;
|
|
1978
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(newExpressions), _step5; !(_step5 = _iterator5()).done;) {
|
|
1979
|
+
var expr = _step5.value;
|
|
1980
|
+
var adjustedStart = expr.start + offset;
|
|
1981
|
+
var adjustedEnd = expr.end + offset;
|
|
1982
|
+
var beforeStart = Math.max(0, adjustedStart - 2);
|
|
1983
|
+
var afterEnd = Math.min(result.length, adjustedEnd + 2);
|
|
1984
|
+
var context = result.substring(beforeStart, afterEnd);
|
|
1985
|
+
if (!context.includes('$$') && !context.includes('$')) {
|
|
1986
|
+
var wrappedExpr = "$$" + expr.text + "$$";
|
|
1987
|
+
result = result.substring(0, adjustedStart) + wrappedExpr + result.substring(adjustedEnd);
|
|
1988
|
+
offset += wrappedExpr.length - expr.text.length;
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
return result;
|
|
1992
|
+
};
|
|
1993
|
+
LatexExtractor.applyLatexFormatSimple = function applyLatexFormatSimple(content) {
|
|
1994
|
+
if (!content || content.trim().length === 0) {
|
|
1995
|
+
return content;
|
|
1996
|
+
}
|
|
1997
|
+
if (!this.hasAnyMathematicalContent(content)) {
|
|
1998
|
+
return content;
|
|
1999
|
+
}
|
|
2000
|
+
if (this.isAlreadyWrapped(content)) {
|
|
2001
|
+
return content;
|
|
2002
|
+
}
|
|
2003
|
+
var trimmedContent = content.trim();
|
|
2004
|
+
if (!content.includes('\n') && this.hasAnyMathematicalContent(content)) {
|
|
2005
|
+
var words = content.toLowerCase().split(/\s+/);
|
|
2006
|
+
var englishWords = words.filter(function (word) {
|
|
2007
|
+
return /^[a-z]{3,}$/.test(word) && !['cos', 'sin', 'tan', 'log', 'exp', 'max', 'min'].includes(word);
|
|
2008
|
+
});
|
|
2009
|
+
if (englishWords.length === 0) {
|
|
2010
|
+
return "$$" + content + "$$";
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
if (this.isLatexFormula(trimmedContent) && !/\b(?:the|is|are|and|or|of|to|in|on|at|by|for|with|from|that|this|these|those|states|theorem|equation|formula)\b/i.test(trimmedContent)) {
|
|
2014
|
+
return "$$" + trimmedContent + "$$";
|
|
2015
|
+
}
|
|
2016
|
+
if (/(?:Relevant|Derived)\s+equation:/i.test(content)) {
|
|
2017
|
+
var parts = content.split(/(?:Relevant|Derived)\s+equation:\s*/i);
|
|
2018
|
+
if (parts.length === 2) {
|
|
2019
|
+
var textPart = parts[0].trim();
|
|
2020
|
+
var formulaPart = parts[1].trim();
|
|
2021
|
+
if (this.isLatexFormula(formulaPart) && !this.isAlreadyWrapped(formulaPart)) {
|
|
2022
|
+
return textPart + "\n$$" + formulaPart + "$$";
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
var processedContent = this.processCommaSeparatedFormulas(content);
|
|
2027
|
+
if (processedContent !== content) {
|
|
2028
|
+
return processedContent;
|
|
2029
|
+
}
|
|
2030
|
+
var formulas = this.extractLatexFormulas(content);
|
|
2031
|
+
if (formulas.length > 0) {
|
|
2032
|
+
var result = content;
|
|
2033
|
+
var mainFormula = formulas.reduce(function (longest, current) {
|
|
2034
|
+
return current.length > longest.length ? current : longest;
|
|
2035
|
+
});
|
|
2036
|
+
if (!result.includes('$$') && !result.includes('$')) {
|
|
2037
|
+
var formulaIndex = result.indexOf(mainFormula);
|
|
2038
|
+
if (formulaIndex !== -1) {
|
|
2039
|
+
result = result.substring(0, formulaIndex) + ("$$" + mainFormula + "$$") + result.substring(formulaIndex + mainFormula.length);
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
return result;
|
|
1684
2043
|
}
|
|
1685
2044
|
return content;
|
|
1686
2045
|
};
|
|
2046
|
+
LatexExtractor.processCommaSeparatedFormulas = function processCommaSeparatedFormulas(content) {
|
|
2047
|
+
var _this2 = this;
|
|
2048
|
+
if (!this.hasAnyMathematicalContent(content)) {
|
|
2049
|
+
return content;
|
|
2050
|
+
}
|
|
2051
|
+
var result = content;
|
|
2052
|
+
var hasChanges = false;
|
|
2053
|
+
var beforeCommaPattern = /([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^~≈]\s*[a-zA-Z0-9_{}\\().\s]+)*)\s*,/g;
|
|
2054
|
+
result = result.replace(beforeCommaPattern, function (match, formula) {
|
|
2055
|
+
if (_this2.isLatexFormula(formula.trim()) && !match.includes('$$') && !match.includes('$')) {
|
|
2056
|
+
hasChanges = true;
|
|
2057
|
+
return "$$" + formula.trim() + "$$,";
|
|
2058
|
+
}
|
|
2059
|
+
return match;
|
|
2060
|
+
});
|
|
2061
|
+
var afterCommaPattern = /,\s*([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^~≈]\s*[a-zA-Z0-9_{}\\().\s]+)*)/g;
|
|
2062
|
+
result = result.replace(afterCommaPattern, function (match, formula) {
|
|
2063
|
+
if (_this2.isLatexFormula(formula.trim()) && !match.includes('$$') && !match.includes('$')) {
|
|
2064
|
+
hasChanges = true;
|
|
2065
|
+
return ", $$" + formula.trim() + "$$";
|
|
2066
|
+
}
|
|
2067
|
+
return match;
|
|
2068
|
+
});
|
|
2069
|
+
return hasChanges ? result : content;
|
|
2070
|
+
};
|
|
1687
2071
|
return LatexExtractor;
|
|
1688
2072
|
}();
|
|
1689
|
-
LatexExtractor.
|
|
1690
|
-
|
|
1691
|
-
var matches = content.match(latexRegex) || [];
|
|
1692
|
-
return matches.filter(function (match) {
|
|
1693
|
-
return match.length > 1 && !match.match(/^[,\s\.]*$/) && (match.includes("\\") || match.includes("^{") || match.includes("_{") || match.includes("$") || !!match.match(/[a-zA-Z]\s*[=+\-*/]\s*[a-zA-Z0-9]/));
|
|
1694
|
-
});
|
|
1695
|
-
};
|
|
1696
|
-
LatexExtractor.extractMultiLineFormulas = function (content) {
|
|
1697
|
-
var formulas = content.split(/\\\\/);
|
|
1698
|
-
return formulas.map(function (formula) {
|
|
1699
|
-
var cleaned = formula.trim();
|
|
1700
|
-
cleaned = cleaned.replace(/\.$/, "");
|
|
1701
|
-
return cleaned;
|
|
1702
|
-
}).filter(function (formula) {
|
|
1703
|
-
return formula.length > 0 && LatexExtractor.isMathFormula(formula);
|
|
1704
|
-
});
|
|
1705
|
-
};
|
|
1706
|
-
LatexExtractor.isMathFormula = function (text) {
|
|
1707
|
-
return !!text && (text.includes("=") || text.includes("\\") || text.includes("^{") || text.includes("_{") || !!text.match(/[a-zA-Z]\s*[=+\-*/]\s*[a-zA-Z0-9]/));
|
|
1708
|
-
};
|
|
2073
|
+
LatexExtractor.LATEX_COMMANDS = ['\\frac', '\\sqrt', '\\sum', '\\prod', '\\int', '\\oint', '\\lim', '\\sin', '\\cos', '\\tan', '\\log', '\\ln', '\\exp', '\\alpha', '\\beta', '\\gamma', '\\delta', '\\epsilon', '\\varepsilon', '\\zeta', '\\eta', '\\theta', '\\vartheta', '\\iota', '\\kappa', '\\lambda', '\\mu', '\\nu', '\\xi', '\\pi', '\\varpi', '\\rho', '\\varrho', '\\sigma', '\\varsigma', '\\tau', "\\upsilon", '\\phi', '\\varphi', '\\chi', '\\psi', '\\omega', '\\Gamma', '\\Delta', '\\Theta', '\\Lambda', '\\Xi', '\\Pi', '\\Sigma', "\\Upsilon", '\\Phi', '\\Psi', '\\Omega', '\\to', '\\gets', '\\mapsto', '\\implies', '\\iff', '\\leftrightarrow', '\\longleftarrow', '\\longrightarrow', '\\longleftrightarrow', '\\Leftarrow', '\\Rightarrow', '\\Leftrightarrow', '\\le', '\\ge', '\\leq', '\\geq', '\\lt', '\\gt', '\\neq', '\\approx', '\\equiv', '\\sim', '\\cong', '\\leqslant', '\\geqslant', '\\parallel', '\\perp', '\\in', '\\notin', '\\subset', '\\subseteq', '\\cup', '\\cap', '\\emptyset', '\\forall', '\\exists', '\\nexists', '\\wedge', '\\vee', '\\neg', '\\partial', '\\nabla', '\\infty', '\\pm', '\\mp', '\\vec', '\\overrightarrow', "\\underrightarrow", '\\overline', "\\underline", '\\widehat', '\\widetilde', '\\overbrace', "\\underbrace", '\\mathbb', '\\mathrm', '\\mathcal', '\\mathfrak', '\\mathscr', '\\text', '\\textbf', '\\textit', '\\left', '\\right', '\\lfloor', '\\rfloor', '\\lceil', '\\rceil', '\\langle', '\\rangle', '\\cdot', '\\times', '\\div', '\\parallel', '\\angle', '\\bot', '\\newline', '\\ldots', '\\cdots', '\\vdots', '\\ddots'];
|
|
2074
|
+
LatexExtractor.LATEX_PATTERNS = [/[a-zA-Z0-9]_\{[^}]*\}/g, /[a-zA-Z0-9]\^\{[^}]*\}/g, /\\[a-zA-Z]+\s*\{[^}]*\}(?:\s*\{[^}]*\})*/g, /\\[a-zA-Z]+(?![a-zA-Z])/g, /\\frac\s*\{[^}]*\}\s*\{[^}]*\}/g, /\\sqrt(?:\[[^\]]*\])?\s*\{[^}]*\}/g, /\\vec\s*\{[^}]*\}/g, /\\(?:alpha|beta|gamma|delta|epsilon|varepsilon|zeta|eta|theta|vartheta|iota|kappa|lambda|mu|nu|xi|pi|varpi|rho|varrho|sigma|varsigma|tau|upsilon|phi|varphi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega)(?![a-zA-Z])/g, /[a-zA-Z0-9_{}\\]+\s*=\s*[a-zA-Z0-9_{}\\+\-*/^().\s]+/g, /\\Delta\s*[a-zA-Z]/g, /[a-zA-Z]+_\{[a-zA-Z0-9]+\}/g, /[a-zA-Z0-9_{}\\]+\s*[+\-*/]\s*[a-zA-Z0-9_{}\\().\s]+/g, /,\s*([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^]\s*[a-zA-Z0-9_{}\\().\s]*)*)/g, /([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^]\s*[a-zA-Z0-9_{}\\().\s]*)*)\s*,/g, /\bto\s+([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^~≈]\s*[a-zA-Z0-9_{}\\().\s]*)*)/g, /([a-zA-Z0-9_{}\\]+(?:\s*[=+\-*/^~≈]\s*[a-zA-Z0-9_{}\\().\s]*)*)\s+to\b/g];
|
|
1709
2075
|
|
|
1710
|
-
var
|
|
1711
|
-
var MarkdownLatexRender = function MarkdownLatexRender(_ref) {
|
|
2076
|
+
var MarkdownRenderer = function MarkdownRenderer(_ref) {
|
|
1712
2077
|
var content = _ref.content;
|
|
1713
|
-
var
|
|
1714
|
-
return React.createElement(
|
|
1715
|
-
remarkPlugins: [remarkMath
|
|
1716
|
-
rehypePlugins: [rehypeKatex, rehypeRaw]
|
|
1717
|
-
|
|
1718
|
-
p: function p(_ref2) {
|
|
1719
|
-
var props = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
|
|
1720
|
-
return React.createElement("span", Object.assign({}, props));
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
}, updatedMarkdown));
|
|
2078
|
+
var formattedContent = formatContent(content);
|
|
2079
|
+
return React.createElement(ReactMarkdown, {
|
|
2080
|
+
remarkPlugins: [remarkMath],
|
|
2081
|
+
rehypePlugins: [rehypeKatex, rehypeRaw]
|
|
2082
|
+
}, formattedContent);
|
|
1724
2083
|
};
|
|
1725
2084
|
function formatContent(content) {
|
|
1726
|
-
|
|
2085
|
+
if (!content || content.trim() === "") {
|
|
2086
|
+
return content;
|
|
2087
|
+
}
|
|
2088
|
+
var processedContent = content.replace(/\s*\\\\\s*/g, '\n');
|
|
2089
|
+
var lines = processedContent.split("\n");
|
|
1727
2090
|
var result = [];
|
|
1728
2091
|
var i = 0;
|
|
1729
2092
|
while (i < lines.length) {
|
|
1730
|
-
var line = lines[i];
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
result.push(appliedLatexFormat);
|
|
2093
|
+
var line = lines[i].trim();
|
|
2094
|
+
if (line === '') {
|
|
2095
|
+
result.push('');
|
|
1734
2096
|
i++;
|
|
1735
2097
|
continue;
|
|
1736
2098
|
}
|
|
1737
|
-
|
|
2099
|
+
var isEquationLabel = /\\textit\{.*(?:Relevant|Derived).*equation.*\}/i.test(line) || /^(?:Relevant|Derived)\s+equation:\s*$/i.test(line);
|
|
2100
|
+
if (isEquationLabel) {
|
|
2101
|
+
var processedLabel = line;
|
|
2102
|
+
if (line.includes('\\textit{') && !line.startsWith('$')) {
|
|
2103
|
+
processedLabel = "$" + line + "$";
|
|
2104
|
+
}
|
|
2105
|
+
result.push(processedLabel);
|
|
2106
|
+
i++;
|
|
2107
|
+
if (i < lines.length) {
|
|
2108
|
+
var equationLine = lines[i].trim();
|
|
2109
|
+
if (equationLine) {
|
|
2110
|
+
if (LatexExtractor.isAlreadyWrapped(equationLine)) {
|
|
2111
|
+
result.push(equationLine);
|
|
2112
|
+
} else {
|
|
2113
|
+
var formatText = LatexExtractor.applyLatexFormat(equationLine);
|
|
2114
|
+
result.push(formatText);
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
i++;
|
|
2118
|
+
}
|
|
2119
|
+
continue;
|
|
2120
|
+
}
|
|
2121
|
+
if (LatexExtractor.isAlreadyWrapped(line)) {
|
|
2122
|
+
result.push(line);
|
|
2123
|
+
} else {
|
|
2124
|
+
var _formatText = LatexExtractor.applyLatexFormatSimple(line);
|
|
2125
|
+
result.push(_formatText);
|
|
2126
|
+
}
|
|
1738
2127
|
i++;
|
|
1739
2128
|
}
|
|
1740
2129
|
return result.join("\n");
|
|
@@ -3335,7 +3724,7 @@ var CustomOption = function CustomOption(props) {
|
|
|
3335
3724
|
}, props.data.label));
|
|
3336
3725
|
};
|
|
3337
3726
|
|
|
3338
|
-
var _excluded$
|
|
3727
|
+
var _excluded$3 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
|
|
3339
3728
|
var CustomSelect = function CustomSelect(_ref) {
|
|
3340
3729
|
var isDefault = _ref.isDefault,
|
|
3341
3730
|
options = _ref.options,
|
|
@@ -3343,7 +3732,7 @@ var CustomSelect = function CustomSelect(_ref) {
|
|
|
3343
3732
|
scrollBottom = _ref.scrollBottom,
|
|
3344
3733
|
value = _ref.value,
|
|
3345
3734
|
isMulti = _ref.isMulti,
|
|
3346
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
3735
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
3347
3736
|
var initialValues = Array.isArray(value) ? options.filter(function (i) {
|
|
3348
3737
|
return value.includes(i.value);
|
|
3349
3738
|
}) : isMulti ? options === null || options === void 0 ? void 0 : options.filter(function (i) {
|
|
@@ -3370,7 +3759,7 @@ var CustomSelect = function CustomSelect(_ref) {
|
|
|
3370
3759
|
}, rest));
|
|
3371
3760
|
};
|
|
3372
3761
|
|
|
3373
|
-
var _excluded$
|
|
3762
|
+
var _excluded$4 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
|
|
3374
3763
|
var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
|
|
3375
3764
|
var isDefault = _ref.isDefault,
|
|
3376
3765
|
options = _ref.options,
|
|
@@ -3378,7 +3767,7 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
|
|
|
3378
3767
|
scrollBottom = _ref.scrollBottom,
|
|
3379
3768
|
value = _ref.value,
|
|
3380
3769
|
isMulti = _ref.isMulti,
|
|
3381
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
3770
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
3382
3771
|
var initialValues = Array.isArray(value) ? options.filter(function (i) {
|
|
3383
3772
|
return value.includes(i.value);
|
|
3384
3773
|
}) : isMulti ? options.filter(function (i) {
|
|
@@ -3405,14 +3794,14 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
|
|
|
3405
3794
|
}, rest));
|
|
3406
3795
|
};
|
|
3407
3796
|
|
|
3408
|
-
var _excluded$
|
|
3797
|
+
var _excluded$5 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
|
|
3409
3798
|
var CustomCreatable = function CustomCreatable(_ref) {
|
|
3410
3799
|
var options = _ref.options,
|
|
3411
3800
|
isDisabled = _ref.isDisabled,
|
|
3412
3801
|
scrollBottom = _ref.scrollBottom,
|
|
3413
3802
|
value = _ref.value,
|
|
3414
3803
|
isMulti = _ref.isMulti,
|
|
3415
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
3804
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
|
|
3416
3805
|
var initialValues = Array.isArray(value) ? options.filter(function (i) {
|
|
3417
3806
|
return value.includes(i.value);
|
|
3418
3807
|
}) : isMulti ? options.filter(function (i) {
|
|
@@ -3439,7 +3828,7 @@ var CustomCreatable = function CustomCreatable(_ref) {
|
|
|
3439
3828
|
}, rest));
|
|
3440
3829
|
};
|
|
3441
3830
|
|
|
3442
|
-
var _excluded$
|
|
3831
|
+
var _excluded$6 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
|
|
3443
3832
|
var CustomSelectOption = function CustomSelectOption(_ref) {
|
|
3444
3833
|
var defaultValue = _ref.defaultValue,
|
|
3445
3834
|
options = _ref.options,
|
|
@@ -3447,7 +3836,7 @@ var CustomSelectOption = function CustomSelectOption(_ref) {
|
|
|
3447
3836
|
scrollBottom = _ref.scrollBottom,
|
|
3448
3837
|
value = _ref.value,
|
|
3449
3838
|
isMulti = _ref.isMulti,
|
|
3450
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
3839
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
|
|
3451
3840
|
var initialValues = defaultValue !== null && typeof defaultValue !== "undefined" ? options.find(function (option) {
|
|
3452
3841
|
return option.value === defaultValue;
|
|
3453
3842
|
}) || null : null;
|
|
@@ -3481,5 +3870,5 @@ var utcToLocalTime = (function (time, FORMAT) {
|
|
|
3481
3870
|
|
|
3482
3871
|
var historyCore = createBrowserHistory();
|
|
3483
3872
|
|
|
3484
|
-
export { ACCESS_TOKEN, AmplitudeEvent, BASE_URL, CommonDialog, ConfirmDialog, CoreButton, CoreInput$1 as CoreCheckbox, CoreError, CoreInput, CoreInputCompact, CoreModal, CoreRadio, CoreRange, CoreSearch, CoreSelect, CoreSelectCompact, CoreTextArea, CoreTitleInput, CoreTooltip, CustomAsyncSelect, CustomCreatable, CustomPagination, CustomSelect, CustomSelectOption, DATE_TIME_MIN_VALUE, LayoutContext, Loading, Login, MarkdownLatexRender, NotFound, OPENSALT_BASE_URL, ORGANIZATION_TEAM, ORGANIZATION_TENANT, Role, api, apiUpload, firstCheckToken, getAccessToken, getErrorMessage, getImageUrl, historyCore, initSentry, initializeAmplitude, setAddTenant, setAlert, setIsRefetchSidebar, setLoading, setLoadingPage, setMenuCollapse, setTeam, setTenant, setUser, store, useAmplitude, useGoogleSignOut, utcToLocalTime };
|
|
3873
|
+
export { ACCESS_TOKEN, AmplitudeEvent, BASE_URL, CommonDialog, ConfirmDialog, CoreButton, CoreInput$1 as CoreCheckbox, CoreError, CoreInput, CoreInputCompact, CoreModal, CoreRadio, CoreRange, CoreSearch, CoreSelect, CoreSelectCompact, CoreTextArea, CoreTitleInput, CoreTooltip, CustomAsyncSelect, CustomCreatable, CustomPagination, CustomSelect, CustomSelectOption, DATE_TIME_MIN_VALUE, LayoutContext, Loading, Login, MarkdownRenderer as MarkdownLatexRender, NotFound, OPENSALT_BASE_URL, ORGANIZATION_TEAM, ORGANIZATION_TENANT, Role, api, apiUpload, firstCheckToken, getAccessToken, getErrorMessage, getImageUrl, historyCore, initSentry, initializeAmplitude, setAddTenant, setAlert, setIsRefetchSidebar, setLoading, setLoadingPage, setMenuCollapse, setTeam, setTenant, setUser, store, useAmplitude, useGoogleSignOut, utcToLocalTime };
|
|
3485
3874
|
//# sourceMappingURL=index.modern.js.map
|