@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
@@ -2971,6 +2971,31 @@ function renderRawOperatorLatex(expr, side) {
2971
2971
  return expr;
2972
2972
  }
2973
2973
 
2974
+ // src/editor/indexSequence.ts
2975
+ function isIndexComma(node) {
2976
+ return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
2977
+ }
2978
+ function isValidIndexSequence(chain) {
2979
+ let count = 0;
2980
+ let afterComma = false;
2981
+ for (const node of chain.nodes) {
2982
+ if (node.superscript || node.subscript) return false;
2983
+ if (isIndexComma(node)) {
2984
+ if (count === 0 || afterComma) return false;
2985
+ afterComma = true;
2986
+ continue;
2987
+ }
2988
+ const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
2989
+ const identity = node.sourceLatex ?? node.expr;
2990
+ const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && new RegExp("^\\p{L}$", "u").test(identity));
2991
+ if (!isDigit && !isLetter) return false;
2992
+ count += 1;
2993
+ afterComma = false;
2994
+ if (count > 64) return false;
2995
+ }
2996
+ return count >= 2 && !afterComma;
2997
+ }
2998
+
2974
2999
  // src/editor/render.ts
2975
3000
  function selectedDigitForm(options) {
2976
3001
  return options?.digitForm ?? "western";
@@ -3197,10 +3222,18 @@ function renderNodeArabic(node, options) {
3197
3222
  return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
3198
3223
  }
3199
3224
  function renderChainEnglish(chain, options) {
3225
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3226
+ const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
3227
+ return "\\mathnormal{" + atoms.join("") + "}";
3228
+ }
3200
3229
  return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
3201
3230
  }
3202
3231
  function renderChainArabic(chain, options) {
3203
- return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
3232
+ const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
3233
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3234
+ return "\\mathnormal{" + rendered.join("\\,") + "}";
3235
+ }
3236
+ return rendered.join(" ");
3204
3237
  }
3205
3238
  function renderEnglishLatexFromSession(session) {
3206
3239
  return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
@@ -4078,14 +4111,14 @@ function attachScripts(astNode, editorNode) {
4078
4111
  editorNode.sourceLatex = astNode.sourceLatex;
4079
4112
  }
4080
4113
  if (astNode.superscript) {
4081
- const sup = chainToEditorChain(astNode.superscript);
4114
+ const sup = chainToEditorChain(astNode.superscript, true);
4082
4115
  if (!sup.editable) {
4083
4116
  return sup;
4084
4117
  }
4085
4118
  editorNode.superscript = sup.chain;
4086
4119
  }
4087
4120
  if (astNode.subscript) {
4088
- const sub = chainToEditorChain(astNode.subscript);
4121
+ const sub = chainToEditorChain(astNode.subscript, true);
4089
4122
  if (!sub.editable) {
4090
4123
  return sub;
4091
4124
  }
@@ -4473,7 +4506,33 @@ function normalizeVerticalDelimiterCommands(chain) {
4473
4506
  }
4474
4507
  return new ChainNode(normalized);
4475
4508
  }
4476
- function chainToEditorChain(chain) {
4509
+ function chainToEditorChain(chain, script = false) {
4510
+ if (script && chain.chain.length === 1) {
4511
+ const wrapper = chain.chain[0];
4512
+ if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
4513
+ if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
4514
+ 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" };
4515
+ }
4516
+ const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
4517
+ if (!imported.editable) return imported;
4518
+ const atoms = [];
4519
+ for (const node of imported.chain.nodes) {
4520
+ if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
4521
+ atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
4522
+ } else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
4523
+ atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
4524
+ } else {
4525
+ atoms.push(node);
4526
+ }
4527
+ }
4528
+ imported.chain.nodes = atoms;
4529
+ if (!isValidIndexSequence(imported.chain)) {
4530
+ 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" };
4531
+ }
4532
+ imported.chain.indexSequence = true;
4533
+ return imported;
4534
+ }
4535
+ }
4477
4536
  const nodes = [];
4478
4537
  for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
4479
4538
  const converted = astNodeToEditorNode(astNode);
@@ -4681,7 +4740,11 @@ function editorChainToAstChain(chain) {
4681
4740
  }
4682
4741
  nodes.push(converted.node);
4683
4742
  }
4684
- return { ok: true, chain: new ChainNode(nodes) };
4743
+ const content = new ChainNode(nodes);
4744
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
4745
+ return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
4746
+ }
4747
+ return { ok: true, chain: content };
4685
4748
  }
4686
4749
  function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
4687
4750
  const converted = editorChainToAstChain(session.englishTree);