@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
@@ -3181,6 +3181,31 @@ function renderRawOperatorLatex(expr, side) {
3181
3181
  return expr;
3182
3182
  }
3183
3183
 
3184
+ // src/editor/indexSequence.ts
3185
+ function isIndexComma(node) {
3186
+ return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
3187
+ }
3188
+ function isValidIndexSequence(chain) {
3189
+ let count = 0;
3190
+ let afterComma = false;
3191
+ for (const node of chain.nodes) {
3192
+ if (node.superscript || node.subscript) return false;
3193
+ if (isIndexComma(node)) {
3194
+ if (count === 0 || afterComma) return false;
3195
+ afterComma = true;
3196
+ continue;
3197
+ }
3198
+ const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
3199
+ const identity = node.sourceLatex ?? node.expr;
3200
+ const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
3201
+ if (!isDigit && !isLetter) return false;
3202
+ count += 1;
3203
+ afterComma = false;
3204
+ if (count > 64) return false;
3205
+ }
3206
+ return count >= 2 && !afterComma;
3207
+ }
3208
+
3184
3209
  // src/editor/render.ts
3185
3210
  function selectedDigitForm(options) {
3186
3211
  return options?.digitForm ?? "western";
@@ -3407,10 +3432,18 @@ function renderNodeArabic(node, options) {
3407
3432
  return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
3408
3433
  }
3409
3434
  function renderChainEnglish(chain, options) {
3435
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3436
+ const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
3437
+ return "\\mathnormal{" + atoms.join("") + "}";
3438
+ }
3410
3439
  return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
3411
3440
  }
3412
3441
  function renderChainArabic(chain, options) {
3413
- return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
3442
+ const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
3443
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3444
+ return "\\mathnormal{" + rendered.join("\\,") + "}";
3445
+ }
3446
+ return rendered.join(" ");
3414
3447
  }
3415
3448
  function renderEnglishLatexFromSession(session) {
3416
3449
  return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
@@ -5250,6 +5283,7 @@ function tryMergeLeafTyping(session, kind, fragment) {
5250
5283
  if (!engLocated) {
5251
5284
  return false;
5252
5285
  }
5286
+ if (engLocated.chain.indexSequence) return false;
5253
5287
  const nodes = engLocated.chain.nodes;
5254
5288
  const i = session.caret.index;
5255
5289
  let targetId = null;
@@ -8280,14 +8314,14 @@ function attachScripts(astNode, editorNode) {
8280
8314
  editorNode.sourceLatex = astNode.sourceLatex;
8281
8315
  }
8282
8316
  if (astNode.superscript) {
8283
- const sup = chainToEditorChain(astNode.superscript);
8317
+ const sup = chainToEditorChain(astNode.superscript, true);
8284
8318
  if (!sup.editable) {
8285
8319
  return sup;
8286
8320
  }
8287
8321
  editorNode.superscript = sup.chain;
8288
8322
  }
8289
8323
  if (astNode.subscript) {
8290
- const sub = chainToEditorChain(astNode.subscript);
8324
+ const sub = chainToEditorChain(astNode.subscript, true);
8291
8325
  if (!sub.editable) {
8292
8326
  return sub;
8293
8327
  }
@@ -8675,7 +8709,33 @@ function normalizeVerticalDelimiterCommands(chain) {
8675
8709
  }
8676
8710
  return new ChainNode(normalized);
8677
8711
  }
8678
- function chainToEditorChain(chain) {
8712
+ function chainToEditorChain(chain, script = false) {
8713
+ if (script && chain.chain.length === 1) {
8714
+ const wrapper = chain.chain[0];
8715
+ if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
8716
+ if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
8717
+ 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" };
8718
+ }
8719
+ const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
8720
+ if (!imported.editable) return imported;
8721
+ const atoms = [];
8722
+ for (const node of imported.chain.nodes) {
8723
+ if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
8724
+ atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
8725
+ } else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
8726
+ atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
8727
+ } else {
8728
+ atoms.push(node);
8729
+ }
8730
+ }
8731
+ imported.chain.nodes = atoms;
8732
+ if (!isValidIndexSequence(imported.chain)) {
8733
+ 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" };
8734
+ }
8735
+ imported.chain.indexSequence = true;
8736
+ return imported;
8737
+ }
8738
+ }
8679
8739
  const nodes = [];
8680
8740
  for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
8681
8741
  const converted = astNodeToEditorNode(astNode);
@@ -8883,7 +8943,11 @@ function editorChainToAstChain(chain) {
8883
8943
  }
8884
8944
  nodes.push(converted.node);
8885
8945
  }
8886
- return { ok: true, chain: new ChainNode(nodes) };
8946
+ const content = new ChainNode(nodes);
8947
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
8948
+ return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
8949
+ }
8950
+ return { ok: true, chain: content };
8887
8951
  }
8888
8952
  function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
8889
8953
  const converted = editorChainToAstChain(session.englishTree);