@drghaliasri/butex 7.3.4 → 7.3.5
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/document.d.mts +2 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.js +35 -2
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +35 -2
- package/dist/document.mjs.map +1 -1
- package/dist/document2-cli.js +68 -5
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +2 -0
- package/dist/document2.d.ts +2 -0
- package/dist/document2.js +68 -5
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +68 -5
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.global.js +35 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +69 -5
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +69 -5
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2-preview.js +63 -4
- package/dist/react-document2-preview.js.map +1 -1
- package/dist/react-document2-preview.mjs +63 -4
- package/dist/react-document2-preview.mjs.map +1 -1
- package/dist/react-document2.d.mts +2 -0
- package/dist/react-document2.d.ts +2 -0
- package/dist/react-document2.js +69 -5
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +69 -5
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +2 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +69 -5
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +69 -5
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.d.mts
CHANGED
package/dist/react.d.ts
CHANGED
package/dist/react.js
CHANGED
|
@@ -1557,6 +1557,31 @@ function formatDigits(value, digitForm = "western") {
|
|
|
1557
1557
|
}).join("");
|
|
1558
1558
|
}
|
|
1559
1559
|
|
|
1560
|
+
// src/editor/indexSequence.ts
|
|
1561
|
+
function isIndexComma(node) {
|
|
1562
|
+
return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
|
|
1563
|
+
}
|
|
1564
|
+
function isValidIndexSequence(chain) {
|
|
1565
|
+
let count = 0;
|
|
1566
|
+
let afterComma = false;
|
|
1567
|
+
for (const node of chain.nodes) {
|
|
1568
|
+
if (node.superscript || node.subscript) return false;
|
|
1569
|
+
if (isIndexComma(node)) {
|
|
1570
|
+
if (count === 0 || afterComma) return false;
|
|
1571
|
+
afterComma = true;
|
|
1572
|
+
continue;
|
|
1573
|
+
}
|
|
1574
|
+
const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
|
|
1575
|
+
const identity = node.sourceLatex ?? node.expr;
|
|
1576
|
+
const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
|
|
1577
|
+
if (!isDigit && !isLetter) return false;
|
|
1578
|
+
count += 1;
|
|
1579
|
+
afterComma = false;
|
|
1580
|
+
if (count > 64) return false;
|
|
1581
|
+
}
|
|
1582
|
+
return count >= 2 && !afterComma;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1560
1585
|
// src/editor/render.ts
|
|
1561
1586
|
function selectedDigitForm(options) {
|
|
1562
1587
|
return options?.digitForm ?? "western";
|
|
@@ -1783,10 +1808,18 @@ function renderNodeArabic(node, options) {
|
|
|
1783
1808
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
1784
1809
|
}
|
|
1785
1810
|
function renderChainEnglish(chain, options) {
|
|
1811
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
1812
|
+
const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
|
|
1813
|
+
return "\\mathnormal{" + atoms.join("") + "}";
|
|
1814
|
+
}
|
|
1786
1815
|
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
1787
1816
|
}
|
|
1788
1817
|
function renderChainArabic(chain, options) {
|
|
1789
|
-
|
|
1818
|
+
const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
|
|
1819
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
1820
|
+
return "\\mathnormal{" + rendered.join("") + "}";
|
|
1821
|
+
}
|
|
1822
|
+
return rendered.join(" ");
|
|
1790
1823
|
}
|
|
1791
1824
|
function renderEnglishLatexFromSession(session) {
|
|
1792
1825
|
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
@@ -3626,6 +3659,7 @@ function tryMergeLeafTyping(session, kind, fragment) {
|
|
|
3626
3659
|
if (!engLocated) {
|
|
3627
3660
|
return false;
|
|
3628
3661
|
}
|
|
3662
|
+
if (engLocated.chain.indexSequence) return false;
|
|
3629
3663
|
const nodes = engLocated.chain.nodes;
|
|
3630
3664
|
const i = session.caret.index;
|
|
3631
3665
|
let targetId = null;
|
|
@@ -8907,14 +8941,14 @@ function attachScripts(astNode, editorNode) {
|
|
|
8907
8941
|
editorNode.sourceLatex = astNode.sourceLatex;
|
|
8908
8942
|
}
|
|
8909
8943
|
if (astNode.superscript) {
|
|
8910
|
-
const sup = chainToEditorChain(astNode.superscript);
|
|
8944
|
+
const sup = chainToEditorChain(astNode.superscript, true);
|
|
8911
8945
|
if (!sup.editable) {
|
|
8912
8946
|
return sup;
|
|
8913
8947
|
}
|
|
8914
8948
|
editorNode.superscript = sup.chain;
|
|
8915
8949
|
}
|
|
8916
8950
|
if (astNode.subscript) {
|
|
8917
|
-
const sub = chainToEditorChain(astNode.subscript);
|
|
8951
|
+
const sub = chainToEditorChain(astNode.subscript, true);
|
|
8918
8952
|
if (!sub.editable) {
|
|
8919
8953
|
return sub;
|
|
8920
8954
|
}
|
|
@@ -9302,7 +9336,33 @@ function normalizeVerticalDelimiterCommands(chain) {
|
|
|
9302
9336
|
}
|
|
9303
9337
|
return new ChainNode(normalized);
|
|
9304
9338
|
}
|
|
9305
|
-
function chainToEditorChain(chain) {
|
|
9339
|
+
function chainToEditorChain(chain, script = false) {
|
|
9340
|
+
if (script && chain.chain.length === 1) {
|
|
9341
|
+
const wrapper = chain.chain[0];
|
|
9342
|
+
if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
|
|
9343
|
+
if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
|
|
9344
|
+
return { editable: false, reason: "\u0635\u064A\u063A\u0629 \u0645\u062C\u0645\u0648\u0639\u0629 \u0627\u0644\u0641\u0647\u0627\u0631\u0633 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629" };
|
|
9345
|
+
}
|
|
9346
|
+
const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
|
|
9347
|
+
if (!imported.editable) return imported;
|
|
9348
|
+
const atoms = [];
|
|
9349
|
+
for (const node of imported.chain.nodes) {
|
|
9350
|
+
if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
|
|
9351
|
+
atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
|
|
9352
|
+
} else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
|
|
9353
|
+
atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
|
|
9354
|
+
} else {
|
|
9355
|
+
atoms.push(node);
|
|
9356
|
+
}
|
|
9357
|
+
}
|
|
9358
|
+
imported.chain.nodes = atoms;
|
|
9359
|
+
if (!isValidIndexSequence(imported.chain)) {
|
|
9360
|
+
return { editable: false, reason: "\u0645\u062D\u062A\u0648\u0649 \u0645\u062C\u0645\u0648\u0639\u0629 \u0627\u0644\u0641\u0647\u0627\u0631\u0633 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645" };
|
|
9361
|
+
}
|
|
9362
|
+
imported.chain.indexSequence = true;
|
|
9363
|
+
return imported;
|
|
9364
|
+
}
|
|
9365
|
+
}
|
|
9306
9366
|
const nodes = [];
|
|
9307
9367
|
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
9308
9368
|
const converted = astNodeToEditorNode(astNode);
|
|
@@ -9510,7 +9570,11 @@ function editorChainToAstChain(chain) {
|
|
|
9510
9570
|
}
|
|
9511
9571
|
nodes.push(converted.node);
|
|
9512
9572
|
}
|
|
9513
|
-
|
|
9573
|
+
const content = new ChainNode(nodes);
|
|
9574
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
9575
|
+
return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
|
|
9576
|
+
}
|
|
9577
|
+
return { ok: true, chain: content };
|
|
9514
9578
|
}
|
|
9515
9579
|
function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
9516
9580
|
const converted = editorChainToAstChain(session.englishTree);
|