@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.mjs
CHANGED
|
@@ -1539,6 +1539,31 @@ function formatDigits(value, digitForm = "western") {
|
|
|
1539
1539
|
}).join("");
|
|
1540
1540
|
}
|
|
1541
1541
|
|
|
1542
|
+
// src/editor/indexSequence.ts
|
|
1543
|
+
function isIndexComma(node) {
|
|
1544
|
+
return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
|
|
1545
|
+
}
|
|
1546
|
+
function isValidIndexSequence(chain) {
|
|
1547
|
+
let count = 0;
|
|
1548
|
+
let afterComma = false;
|
|
1549
|
+
for (const node of chain.nodes) {
|
|
1550
|
+
if (node.superscript || node.subscript) return false;
|
|
1551
|
+
if (isIndexComma(node)) {
|
|
1552
|
+
if (count === 0 || afterComma) return false;
|
|
1553
|
+
afterComma = true;
|
|
1554
|
+
continue;
|
|
1555
|
+
}
|
|
1556
|
+
const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
|
|
1557
|
+
const identity = node.sourceLatex ?? node.expr;
|
|
1558
|
+
const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
|
|
1559
|
+
if (!isDigit && !isLetter) return false;
|
|
1560
|
+
count += 1;
|
|
1561
|
+
afterComma = false;
|
|
1562
|
+
if (count > 64) return false;
|
|
1563
|
+
}
|
|
1564
|
+
return count >= 2 && !afterComma;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1542
1567
|
// src/editor/render.ts
|
|
1543
1568
|
function selectedDigitForm(options) {
|
|
1544
1569
|
return options?.digitForm ?? "western";
|
|
@@ -1765,10 +1790,18 @@ function renderNodeArabic(node, options) {
|
|
|
1765
1790
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
1766
1791
|
}
|
|
1767
1792
|
function renderChainEnglish(chain, options) {
|
|
1793
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
1794
|
+
const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
|
|
1795
|
+
return "\\mathnormal{" + atoms.join("") + "}";
|
|
1796
|
+
}
|
|
1768
1797
|
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
1769
1798
|
}
|
|
1770
1799
|
function renderChainArabic(chain, options) {
|
|
1771
|
-
|
|
1800
|
+
const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
|
|
1801
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
1802
|
+
return "\\mathnormal{" + rendered.join("") + "}";
|
|
1803
|
+
}
|
|
1804
|
+
return rendered.join(" ");
|
|
1772
1805
|
}
|
|
1773
1806
|
function renderEnglishLatexFromSession(session) {
|
|
1774
1807
|
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
@@ -3608,6 +3641,7 @@ function tryMergeLeafTyping(session, kind, fragment) {
|
|
|
3608
3641
|
if (!engLocated) {
|
|
3609
3642
|
return false;
|
|
3610
3643
|
}
|
|
3644
|
+
if (engLocated.chain.indexSequence) return false;
|
|
3611
3645
|
const nodes = engLocated.chain.nodes;
|
|
3612
3646
|
const i = session.caret.index;
|
|
3613
3647
|
let targetId = null;
|
|
@@ -8889,14 +8923,14 @@ function attachScripts(astNode, editorNode) {
|
|
|
8889
8923
|
editorNode.sourceLatex = astNode.sourceLatex;
|
|
8890
8924
|
}
|
|
8891
8925
|
if (astNode.superscript) {
|
|
8892
|
-
const sup = chainToEditorChain(astNode.superscript);
|
|
8926
|
+
const sup = chainToEditorChain(astNode.superscript, true);
|
|
8893
8927
|
if (!sup.editable) {
|
|
8894
8928
|
return sup;
|
|
8895
8929
|
}
|
|
8896
8930
|
editorNode.superscript = sup.chain;
|
|
8897
8931
|
}
|
|
8898
8932
|
if (astNode.subscript) {
|
|
8899
|
-
const sub = chainToEditorChain(astNode.subscript);
|
|
8933
|
+
const sub = chainToEditorChain(astNode.subscript, true);
|
|
8900
8934
|
if (!sub.editable) {
|
|
8901
8935
|
return sub;
|
|
8902
8936
|
}
|
|
@@ -9284,7 +9318,33 @@ function normalizeVerticalDelimiterCommands(chain) {
|
|
|
9284
9318
|
}
|
|
9285
9319
|
return new ChainNode(normalized);
|
|
9286
9320
|
}
|
|
9287
|
-
function chainToEditorChain(chain) {
|
|
9321
|
+
function chainToEditorChain(chain, script = false) {
|
|
9322
|
+
if (script && chain.chain.length === 1) {
|
|
9323
|
+
const wrapper = chain.chain[0];
|
|
9324
|
+
if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
|
|
9325
|
+
if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
|
|
9326
|
+
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" };
|
|
9327
|
+
}
|
|
9328
|
+
const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
|
|
9329
|
+
if (!imported.editable) return imported;
|
|
9330
|
+
const atoms = [];
|
|
9331
|
+
for (const node of imported.chain.nodes) {
|
|
9332
|
+
if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
|
|
9333
|
+
atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
|
|
9334
|
+
} else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
|
|
9335
|
+
atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
|
|
9336
|
+
} else {
|
|
9337
|
+
atoms.push(node);
|
|
9338
|
+
}
|
|
9339
|
+
}
|
|
9340
|
+
imported.chain.nodes = atoms;
|
|
9341
|
+
if (!isValidIndexSequence(imported.chain)) {
|
|
9342
|
+
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" };
|
|
9343
|
+
}
|
|
9344
|
+
imported.chain.indexSequence = true;
|
|
9345
|
+
return imported;
|
|
9346
|
+
}
|
|
9347
|
+
}
|
|
9288
9348
|
const nodes = [];
|
|
9289
9349
|
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
9290
9350
|
const converted = astNodeToEditorNode(astNode);
|
|
@@ -9492,7 +9552,11 @@ function editorChainToAstChain(chain) {
|
|
|
9492
9552
|
}
|
|
9493
9553
|
nodes.push(converted.node);
|
|
9494
9554
|
}
|
|
9495
|
-
|
|
9555
|
+
const content = new ChainNode(nodes);
|
|
9556
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
9557
|
+
return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
|
|
9558
|
+
}
|
|
9559
|
+
return { ok: true, chain: content };
|
|
9496
9560
|
}
|
|
9497
9561
|
function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
9498
9562
|
const converted = editorChainToAstChain(session.englishTree);
|