@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.
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
@@ -2897,6 +2897,31 @@ function renderRawOperatorLatex(expr, side) {
2897
2897
  return expr;
2898
2898
  }
2899
2899
 
2900
+ // src/editor/indexSequence.ts
2901
+ function isIndexComma(node) {
2902
+ return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
2903
+ }
2904
+ function isValidIndexSequence(chain) {
2905
+ let count = 0;
2906
+ let afterComma = false;
2907
+ for (const node of chain.nodes) {
2908
+ if (node.superscript || node.subscript) return false;
2909
+ if (isIndexComma(node)) {
2910
+ if (count === 0 || afterComma) return false;
2911
+ afterComma = true;
2912
+ continue;
2913
+ }
2914
+ const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
2915
+ const identity = node.sourceLatex ?? node.expr;
2916
+ const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
2917
+ if (!isDigit && !isLetter) return false;
2918
+ count += 1;
2919
+ afterComma = false;
2920
+ if (count > 64) return false;
2921
+ }
2922
+ return count >= 2 && !afterComma;
2923
+ }
2924
+
2900
2925
  // src/editor/render.ts
2901
2926
  function selectedDigitForm(options) {
2902
2927
  return options?.digitForm ?? "western";
@@ -3123,10 +3148,18 @@ function renderNodeArabic(node, options) {
3123
3148
  return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
3124
3149
  }
3125
3150
  function renderChainEnglish(chain, options) {
3151
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3152
+ const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
3153
+ return "\\mathnormal{" + atoms.join("") + "}";
3154
+ }
3126
3155
  return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
3127
3156
  }
3128
3157
  function renderChainArabic(chain, options) {
3129
- return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
3158
+ const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
3159
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3160
+ return "\\mathnormal{" + rendered.join("\\,") + "}";
3161
+ }
3162
+ return rendered.join(" ");
3130
3163
  }
3131
3164
  function renderEnglishLatexFromSession(session) {
3132
3165
  return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
@@ -4014,14 +4047,14 @@ function attachScripts(astNode, editorNode) {
4014
4047
  editorNode.sourceLatex = astNode.sourceLatex;
4015
4048
  }
4016
4049
  if (astNode.superscript) {
4017
- const sup = chainToEditorChain(astNode.superscript);
4050
+ const sup = chainToEditorChain(astNode.superscript, true);
4018
4051
  if (!sup.editable) {
4019
4052
  return sup;
4020
4053
  }
4021
4054
  editorNode.superscript = sup.chain;
4022
4055
  }
4023
4056
  if (astNode.subscript) {
4024
- const sub = chainToEditorChain(astNode.subscript);
4057
+ const sub = chainToEditorChain(astNode.subscript, true);
4025
4058
  if (!sub.editable) {
4026
4059
  return sub;
4027
4060
  }
@@ -4409,7 +4442,33 @@ function normalizeVerticalDelimiterCommands(chain) {
4409
4442
  }
4410
4443
  return new ChainNode(normalized);
4411
4444
  }
4412
- function chainToEditorChain(chain) {
4445
+ function chainToEditorChain(chain, script = false) {
4446
+ if (script && chain.chain.length === 1) {
4447
+ const wrapper = chain.chain[0];
4448
+ if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
4449
+ if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
4450
+ 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" };
4451
+ }
4452
+ const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
4453
+ if (!imported.editable) return imported;
4454
+ const atoms = [];
4455
+ for (const node of imported.chain.nodes) {
4456
+ if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
4457
+ atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
4458
+ } else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
4459
+ atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
4460
+ } else {
4461
+ atoms.push(node);
4462
+ }
4463
+ }
4464
+ imported.chain.nodes = atoms;
4465
+ if (!isValidIndexSequence(imported.chain)) {
4466
+ 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" };
4467
+ }
4468
+ imported.chain.indexSequence = true;
4469
+ return imported;
4470
+ }
4471
+ }
4413
4472
  const nodes = [];
4414
4473
  for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
4415
4474
  const converted = astNodeToEditorNode(astNode);