@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-document2.js
CHANGED
|
@@ -3218,6 +3218,31 @@ function renderRawOperatorLatex(expr, side) {
|
|
|
3218
3218
|
return expr;
|
|
3219
3219
|
}
|
|
3220
3220
|
|
|
3221
|
+
// src/editor/indexSequence.ts
|
|
3222
|
+
function isIndexComma(node) {
|
|
3223
|
+
return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
|
|
3224
|
+
}
|
|
3225
|
+
function isValidIndexSequence(chain) {
|
|
3226
|
+
let count = 0;
|
|
3227
|
+
let afterComma = false;
|
|
3228
|
+
for (const node of chain.nodes) {
|
|
3229
|
+
if (node.superscript || node.subscript) return false;
|
|
3230
|
+
if (isIndexComma(node)) {
|
|
3231
|
+
if (count === 0 || afterComma) return false;
|
|
3232
|
+
afterComma = true;
|
|
3233
|
+
continue;
|
|
3234
|
+
}
|
|
3235
|
+
const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
|
|
3236
|
+
const identity = node.sourceLatex ?? node.expr;
|
|
3237
|
+
const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
|
|
3238
|
+
if (!isDigit && !isLetter) return false;
|
|
3239
|
+
count += 1;
|
|
3240
|
+
afterComma = false;
|
|
3241
|
+
if (count > 64) return false;
|
|
3242
|
+
}
|
|
3243
|
+
return count >= 2 && !afterComma;
|
|
3244
|
+
}
|
|
3245
|
+
|
|
3221
3246
|
// src/editor/render.ts
|
|
3222
3247
|
function selectedDigitForm(options) {
|
|
3223
3248
|
return options?.digitForm ?? "western";
|
|
@@ -3444,10 +3469,18 @@ function renderNodeArabic(node, options) {
|
|
|
3444
3469
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
3445
3470
|
}
|
|
3446
3471
|
function renderChainEnglish(chain, options) {
|
|
3472
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3473
|
+
const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
|
|
3474
|
+
return "\\mathnormal{" + atoms.join("") + "}";
|
|
3475
|
+
}
|
|
3447
3476
|
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
3448
3477
|
}
|
|
3449
3478
|
function renderChainArabic(chain, options) {
|
|
3450
|
-
|
|
3479
|
+
const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
|
|
3480
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3481
|
+
return "\\mathnormal{" + rendered.join("\\,") + "}";
|
|
3482
|
+
}
|
|
3483
|
+
return rendered.join(" ");
|
|
3451
3484
|
}
|
|
3452
3485
|
function renderEnglishLatexFromSession(session) {
|
|
3453
3486
|
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
@@ -5287,6 +5320,7 @@ function tryMergeLeafTyping(session, kind, fragment) {
|
|
|
5287
5320
|
if (!engLocated) {
|
|
5288
5321
|
return false;
|
|
5289
5322
|
}
|
|
5323
|
+
if (engLocated.chain.indexSequence) return false;
|
|
5290
5324
|
const nodes = engLocated.chain.nodes;
|
|
5291
5325
|
const i = session.caret.index;
|
|
5292
5326
|
let targetId = null;
|
|
@@ -8317,14 +8351,14 @@ function attachScripts(astNode, editorNode) {
|
|
|
8317
8351
|
editorNode.sourceLatex = astNode.sourceLatex;
|
|
8318
8352
|
}
|
|
8319
8353
|
if (astNode.superscript) {
|
|
8320
|
-
const sup = chainToEditorChain(astNode.superscript);
|
|
8354
|
+
const sup = chainToEditorChain(astNode.superscript, true);
|
|
8321
8355
|
if (!sup.editable) {
|
|
8322
8356
|
return sup;
|
|
8323
8357
|
}
|
|
8324
8358
|
editorNode.superscript = sup.chain;
|
|
8325
8359
|
}
|
|
8326
8360
|
if (astNode.subscript) {
|
|
8327
|
-
const sub = chainToEditorChain(astNode.subscript);
|
|
8361
|
+
const sub = chainToEditorChain(astNode.subscript, true);
|
|
8328
8362
|
if (!sub.editable) {
|
|
8329
8363
|
return sub;
|
|
8330
8364
|
}
|
|
@@ -8712,7 +8746,33 @@ function normalizeVerticalDelimiterCommands(chain) {
|
|
|
8712
8746
|
}
|
|
8713
8747
|
return new ChainNode(normalized);
|
|
8714
8748
|
}
|
|
8715
|
-
function chainToEditorChain(chain) {
|
|
8749
|
+
function chainToEditorChain(chain, script = false) {
|
|
8750
|
+
if (script && chain.chain.length === 1) {
|
|
8751
|
+
const wrapper = chain.chain[0];
|
|
8752
|
+
if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
|
|
8753
|
+
if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
|
|
8754
|
+
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" };
|
|
8755
|
+
}
|
|
8756
|
+
const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
|
|
8757
|
+
if (!imported.editable) return imported;
|
|
8758
|
+
const atoms = [];
|
|
8759
|
+
for (const node of imported.chain.nodes) {
|
|
8760
|
+
if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
|
|
8761
|
+
atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
|
|
8762
|
+
} else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
|
|
8763
|
+
atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
|
|
8764
|
+
} else {
|
|
8765
|
+
atoms.push(node);
|
|
8766
|
+
}
|
|
8767
|
+
}
|
|
8768
|
+
imported.chain.nodes = atoms;
|
|
8769
|
+
if (!isValidIndexSequence(imported.chain)) {
|
|
8770
|
+
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" };
|
|
8771
|
+
}
|
|
8772
|
+
imported.chain.indexSequence = true;
|
|
8773
|
+
return imported;
|
|
8774
|
+
}
|
|
8775
|
+
}
|
|
8716
8776
|
const nodes = [];
|
|
8717
8777
|
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
8718
8778
|
const converted = astNodeToEditorNode(astNode);
|
|
@@ -8920,7 +8980,11 @@ function editorChainToAstChain(chain) {
|
|
|
8920
8980
|
}
|
|
8921
8981
|
nodes.push(converted.node);
|
|
8922
8982
|
}
|
|
8923
|
-
|
|
8983
|
+
const content = new ChainNode(nodes);
|
|
8984
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
8985
|
+
return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
|
|
8986
|
+
}
|
|
8987
|
+
return { ok: true, chain: content };
|
|
8924
8988
|
}
|
|
8925
8989
|
function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
8926
8990
|
const converted = editorChainToAstChain(session.englishTree);
|