@drghaliasri/butex 7.3.4 → 7.3.6
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-document.mjs
CHANGED
|
@@ -2259,6 +2259,31 @@ function formatDigits(value, digitForm = "western") {
|
|
|
2259
2259
|
}).join("");
|
|
2260
2260
|
}
|
|
2261
2261
|
|
|
2262
|
+
// src/editor/indexSequence.ts
|
|
2263
|
+
function isIndexComma(node) {
|
|
2264
|
+
return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
|
|
2265
|
+
}
|
|
2266
|
+
function isValidIndexSequence(chain) {
|
|
2267
|
+
let count = 0;
|
|
2268
|
+
let afterComma = false;
|
|
2269
|
+
for (const node of chain.nodes) {
|
|
2270
|
+
if (node.superscript || node.subscript) return false;
|
|
2271
|
+
if (isIndexComma(node)) {
|
|
2272
|
+
if (count === 0 || afterComma) return false;
|
|
2273
|
+
afterComma = true;
|
|
2274
|
+
continue;
|
|
2275
|
+
}
|
|
2276
|
+
const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
|
|
2277
|
+
const identity = node.sourceLatex ?? node.expr;
|
|
2278
|
+
const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
|
|
2279
|
+
if (!isDigit && !isLetter) return false;
|
|
2280
|
+
count += 1;
|
|
2281
|
+
afterComma = false;
|
|
2282
|
+
if (count > 64) return false;
|
|
2283
|
+
}
|
|
2284
|
+
return count >= 2 && !afterComma;
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2262
2287
|
// src/editor/render.ts
|
|
2263
2288
|
function selectedDigitForm(options) {
|
|
2264
2289
|
return options?.digitForm ?? "western";
|
|
@@ -2485,10 +2510,18 @@ function renderNodeArabic(node, options) {
|
|
|
2485
2510
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
2486
2511
|
}
|
|
2487
2512
|
function renderChainEnglish(chain, options) {
|
|
2513
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
2514
|
+
const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
|
|
2515
|
+
return "\\mathnormal{" + atoms.join("") + "}";
|
|
2516
|
+
}
|
|
2488
2517
|
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
2489
2518
|
}
|
|
2490
2519
|
function renderChainArabic(chain, options) {
|
|
2491
|
-
|
|
2520
|
+
const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
|
|
2521
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
2522
|
+
return "\\mathnormal{" + rendered.join("\\,") + "}";
|
|
2523
|
+
}
|
|
2524
|
+
return rendered.join(" ");
|
|
2492
2525
|
}
|
|
2493
2526
|
function renderEnglishLatexFromSession(session) {
|
|
2494
2527
|
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
@@ -4328,6 +4361,7 @@ function tryMergeLeafTyping(session, kind, fragment) {
|
|
|
4328
4361
|
if (!engLocated) {
|
|
4329
4362
|
return false;
|
|
4330
4363
|
}
|
|
4364
|
+
if (engLocated.chain.indexSequence) return false;
|
|
4331
4365
|
const nodes = engLocated.chain.nodes;
|
|
4332
4366
|
const i = session.caret.index;
|
|
4333
4367
|
let targetId = null;
|
|
@@ -7358,14 +7392,14 @@ function attachScripts(astNode, editorNode) {
|
|
|
7358
7392
|
editorNode.sourceLatex = astNode.sourceLatex;
|
|
7359
7393
|
}
|
|
7360
7394
|
if (astNode.superscript) {
|
|
7361
|
-
const sup = chainToEditorChain(astNode.superscript);
|
|
7395
|
+
const sup = chainToEditorChain(astNode.superscript, true);
|
|
7362
7396
|
if (!sup.editable) {
|
|
7363
7397
|
return sup;
|
|
7364
7398
|
}
|
|
7365
7399
|
editorNode.superscript = sup.chain;
|
|
7366
7400
|
}
|
|
7367
7401
|
if (astNode.subscript) {
|
|
7368
|
-
const sub = chainToEditorChain(astNode.subscript);
|
|
7402
|
+
const sub = chainToEditorChain(astNode.subscript, true);
|
|
7369
7403
|
if (!sub.editable) {
|
|
7370
7404
|
return sub;
|
|
7371
7405
|
}
|
|
@@ -7753,7 +7787,33 @@ function normalizeVerticalDelimiterCommands(chain) {
|
|
|
7753
7787
|
}
|
|
7754
7788
|
return new ChainNode(normalized);
|
|
7755
7789
|
}
|
|
7756
|
-
function chainToEditorChain(chain) {
|
|
7790
|
+
function chainToEditorChain(chain, script = false) {
|
|
7791
|
+
if (script && chain.chain.length === 1) {
|
|
7792
|
+
const wrapper = chain.chain[0];
|
|
7793
|
+
if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
|
|
7794
|
+
if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
|
|
7795
|
+
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" };
|
|
7796
|
+
}
|
|
7797
|
+
const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
|
|
7798
|
+
if (!imported.editable) return imported;
|
|
7799
|
+
const atoms = [];
|
|
7800
|
+
for (const node of imported.chain.nodes) {
|
|
7801
|
+
if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
|
|
7802
|
+
atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
|
|
7803
|
+
} else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
|
|
7804
|
+
atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
|
|
7805
|
+
} else {
|
|
7806
|
+
atoms.push(node);
|
|
7807
|
+
}
|
|
7808
|
+
}
|
|
7809
|
+
imported.chain.nodes = atoms;
|
|
7810
|
+
if (!isValidIndexSequence(imported.chain)) {
|
|
7811
|
+
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" };
|
|
7812
|
+
}
|
|
7813
|
+
imported.chain.indexSequence = true;
|
|
7814
|
+
return imported;
|
|
7815
|
+
}
|
|
7816
|
+
}
|
|
7757
7817
|
const nodes = [];
|
|
7758
7818
|
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
7759
7819
|
const converted = astNodeToEditorNode(astNode);
|
|
@@ -7961,7 +8021,11 @@ function editorChainToAstChain(chain) {
|
|
|
7961
8021
|
}
|
|
7962
8022
|
nodes.push(converted.node);
|
|
7963
8023
|
}
|
|
7964
|
-
|
|
8024
|
+
const content = new ChainNode(nodes);
|
|
8025
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
8026
|
+
return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
|
|
8027
|
+
}
|
|
8028
|
+
return { ok: true, chain: content };
|
|
7965
8029
|
}
|
|
7966
8030
|
function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
7967
8031
|
const converted = editorChainToAstChain(session.englishTree);
|