@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.
Files changed (43) hide show
  1. package/dist/document.d.mts +2 -0
  2. package/dist/document.d.ts +2 -0
  3. package/dist/document.js +35 -2
  4. package/dist/document.js.map +1 -1
  5. package/dist/document.mjs +35 -2
  6. package/dist/document.mjs.map +1 -1
  7. package/dist/document2-cli.js +68 -5
  8. package/dist/document2-cli.js.map +1 -1
  9. package/dist/document2.d.mts +2 -0
  10. package/dist/document2.d.ts +2 -0
  11. package/dist/document2.js +68 -5
  12. package/dist/document2.js.map +1 -1
  13. package/dist/document2.mjs +68 -5
  14. package/dist/document2.mjs.map +1 -1
  15. package/dist/index.d.mts +2 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.global.js +35 -1
  18. package/dist/index.global.js.map +1 -1
  19. package/dist/index.js +35 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +35 -1
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/react-document.js +69 -5
  24. package/dist/react-document.js.map +1 -1
  25. package/dist/react-document.mjs +69 -5
  26. package/dist/react-document.mjs.map +1 -1
  27. package/dist/react-document2-preview.js +63 -4
  28. package/dist/react-document2-preview.js.map +1 -1
  29. package/dist/react-document2-preview.mjs +63 -4
  30. package/dist/react-document2-preview.mjs.map +1 -1
  31. package/dist/react-document2.d.mts +2 -0
  32. package/dist/react-document2.d.ts +2 -0
  33. package/dist/react-document2.js +69 -5
  34. package/dist/react-document2.js.map +1 -1
  35. package/dist/react-document2.mjs +69 -5
  36. package/dist/react-document2.mjs.map +1 -1
  37. package/dist/react.d.mts +2 -0
  38. package/dist/react.d.ts +2 -0
  39. package/dist/react.js +69 -5
  40. package/dist/react.js.map +1 -1
  41. package/dist/react.mjs +69 -5
  42. package/dist/react.mjs.map +1 -1
  43. package/package.json +1 -1
@@ -2288,6 +2288,31 @@ function formatDigits(value, digitForm = "western") {
2288
2288
  }).join("");
2289
2289
  }
2290
2290
 
2291
+ // src/editor/indexSequence.ts
2292
+ function isIndexComma(node) {
2293
+ return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
2294
+ }
2295
+ function isValidIndexSequence(chain) {
2296
+ let count = 0;
2297
+ let afterComma = false;
2298
+ for (const node of chain.nodes) {
2299
+ if (node.superscript || node.subscript) return false;
2300
+ if (isIndexComma(node)) {
2301
+ if (count === 0 || afterComma) return false;
2302
+ afterComma = true;
2303
+ continue;
2304
+ }
2305
+ const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
2306
+ const identity = node.sourceLatex ?? node.expr;
2307
+ const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
2308
+ if (!isDigit && !isLetter) return false;
2309
+ count += 1;
2310
+ afterComma = false;
2311
+ if (count > 64) return false;
2312
+ }
2313
+ return count >= 2 && !afterComma;
2314
+ }
2315
+
2291
2316
  // src/editor/render.ts
2292
2317
  function selectedDigitForm(options) {
2293
2318
  return options?.digitForm ?? "western";
@@ -2514,10 +2539,18 @@ function renderNodeArabic(node, options) {
2514
2539
  return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
2515
2540
  }
2516
2541
  function renderChainEnglish(chain, options) {
2542
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
2543
+ const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
2544
+ return "\\mathnormal{" + atoms.join("") + "}";
2545
+ }
2517
2546
  return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
2518
2547
  }
2519
2548
  function renderChainArabic(chain, options) {
2520
- return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
2549
+ const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
2550
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
2551
+ return "\\mathnormal{" + rendered.join("") + "}";
2552
+ }
2553
+ return rendered.join(" ");
2521
2554
  }
2522
2555
  function renderEnglishLatexFromSession(session) {
2523
2556
  return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
@@ -4357,6 +4390,7 @@ function tryMergeLeafTyping(session, kind, fragment) {
4357
4390
  if (!engLocated) {
4358
4391
  return false;
4359
4392
  }
4393
+ if (engLocated.chain.indexSequence) return false;
4360
4394
  const nodes = engLocated.chain.nodes;
4361
4395
  const i = session.caret.index;
4362
4396
  let targetId = null;
@@ -7387,14 +7421,14 @@ function attachScripts(astNode, editorNode) {
7387
7421
  editorNode.sourceLatex = astNode.sourceLatex;
7388
7422
  }
7389
7423
  if (astNode.superscript) {
7390
- const sup = chainToEditorChain(astNode.superscript);
7424
+ const sup = chainToEditorChain(astNode.superscript, true);
7391
7425
  if (!sup.editable) {
7392
7426
  return sup;
7393
7427
  }
7394
7428
  editorNode.superscript = sup.chain;
7395
7429
  }
7396
7430
  if (astNode.subscript) {
7397
- const sub = chainToEditorChain(astNode.subscript);
7431
+ const sub = chainToEditorChain(astNode.subscript, true);
7398
7432
  if (!sub.editable) {
7399
7433
  return sub;
7400
7434
  }
@@ -7782,7 +7816,33 @@ function normalizeVerticalDelimiterCommands(chain) {
7782
7816
  }
7783
7817
  return new ChainNode(normalized);
7784
7818
  }
7785
- function chainToEditorChain(chain) {
7819
+ function chainToEditorChain(chain, script = false) {
7820
+ if (script && chain.chain.length === 1) {
7821
+ const wrapper = chain.chain[0];
7822
+ if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
7823
+ if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
7824
+ 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" };
7825
+ }
7826
+ const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
7827
+ if (!imported.editable) return imported;
7828
+ const atoms = [];
7829
+ for (const node of imported.chain.nodes) {
7830
+ if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
7831
+ atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
7832
+ } else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
7833
+ atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
7834
+ } else {
7835
+ atoms.push(node);
7836
+ }
7837
+ }
7838
+ imported.chain.nodes = atoms;
7839
+ if (!isValidIndexSequence(imported.chain)) {
7840
+ 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" };
7841
+ }
7842
+ imported.chain.indexSequence = true;
7843
+ return imported;
7844
+ }
7845
+ }
7786
7846
  const nodes = [];
7787
7847
  for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
7788
7848
  const converted = astNodeToEditorNode(astNode);
@@ -7990,7 +8050,11 @@ function editorChainToAstChain(chain) {
7990
8050
  }
7991
8051
  nodes.push(converted.node);
7992
8052
  }
7993
- return { ok: true, chain: new ChainNode(nodes) };
8053
+ const content = new ChainNode(nodes);
8054
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
8055
+ return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
8056
+ }
8057
+ return { ok: true, chain: content };
7994
8058
  }
7995
8059
  function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
7996
8060
  const converted = editorChainToAstChain(session.englishTree);