@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
@@ -3127,6 +3127,31 @@ function renderRawOperatorLatex(expr, side) {
3127
3127
  return expr;
3128
3128
  }
3129
3129
 
3130
+ // src/editor/indexSequence.ts
3131
+ function isIndexComma(node) {
3132
+ return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
3133
+ }
3134
+ function isValidIndexSequence(chain) {
3135
+ let count = 0;
3136
+ let afterComma = false;
3137
+ for (const node of chain.nodes) {
3138
+ if (node.superscript || node.subscript) return false;
3139
+ if (isIndexComma(node)) {
3140
+ if (count === 0 || afterComma) return false;
3141
+ afterComma = true;
3142
+ continue;
3143
+ }
3144
+ const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
3145
+ const identity = node.sourceLatex ?? node.expr;
3146
+ const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
3147
+ if (!isDigit && !isLetter) return false;
3148
+ count += 1;
3149
+ afterComma = false;
3150
+ if (count > 64) return false;
3151
+ }
3152
+ return count >= 2 && !afterComma;
3153
+ }
3154
+
3130
3155
  // src/editor/render.ts
3131
3156
  function selectedDigitForm(options) {
3132
3157
  return options?.digitForm ?? "western";
@@ -3353,10 +3378,18 @@ function renderNodeArabic(node, options) {
3353
3378
  return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
3354
3379
  }
3355
3380
  function renderChainEnglish(chain, options) {
3381
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3382
+ const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
3383
+ return "\\mathnormal{" + atoms.join("") + "}";
3384
+ }
3356
3385
  return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
3357
3386
  }
3358
3387
  function renderChainArabic(chain, options) {
3359
- return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
3388
+ const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
3389
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3390
+ return "\\mathnormal{" + rendered.join("\\,") + "}";
3391
+ }
3392
+ return rendered.join(" ");
3360
3393
  }
3361
3394
  function renderEnglishLatexFromSession(session) {
3362
3395
  return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
@@ -4256,14 +4289,14 @@ function attachScripts(astNode, editorNode) {
4256
4289
  editorNode.sourceLatex = astNode.sourceLatex;
4257
4290
  }
4258
4291
  if (astNode.superscript) {
4259
- const sup = chainToEditorChain(astNode.superscript);
4292
+ const sup = chainToEditorChain(astNode.superscript, true);
4260
4293
  if (!sup.editable) {
4261
4294
  return sup;
4262
4295
  }
4263
4296
  editorNode.superscript = sup.chain;
4264
4297
  }
4265
4298
  if (astNode.subscript) {
4266
- const sub = chainToEditorChain(astNode.subscript);
4299
+ const sub = chainToEditorChain(astNode.subscript, true);
4267
4300
  if (!sub.editable) {
4268
4301
  return sub;
4269
4302
  }
@@ -4651,7 +4684,33 @@ function normalizeVerticalDelimiterCommands(chain) {
4651
4684
  }
4652
4685
  return new ChainNode(normalized);
4653
4686
  }
4654
- function chainToEditorChain(chain) {
4687
+ function chainToEditorChain(chain, script = false) {
4688
+ if (script && chain.chain.length === 1) {
4689
+ const wrapper = chain.chain[0];
4690
+ if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
4691
+ if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
4692
+ 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" };
4693
+ }
4694
+ const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
4695
+ if (!imported.editable) return imported;
4696
+ const atoms = [];
4697
+ for (const node of imported.chain.nodes) {
4698
+ if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
4699
+ atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
4700
+ } else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
4701
+ atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
4702
+ } else {
4703
+ atoms.push(node);
4704
+ }
4705
+ }
4706
+ imported.chain.nodes = atoms;
4707
+ if (!isValidIndexSequence(imported.chain)) {
4708
+ 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" };
4709
+ }
4710
+ imported.chain.indexSequence = true;
4711
+ return imported;
4712
+ }
4713
+ }
4655
4714
  const nodes = [];
4656
4715
  for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
4657
4716
  const converted = astNodeToEditorNode(astNode);
@@ -4859,7 +4918,11 @@ function editorChainToAstChain(chain) {
4859
4918
  }
4860
4919
  nodes.push(converted.node);
4861
4920
  }
4862
- return { ok: true, chain: new ChainNode(nodes) };
4921
+ const content = new ChainNode(nodes);
4922
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
4923
+ return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
4924
+ }
4925
+ return { ok: true, chain: content };
4863
4926
  }
4864
4927
  function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
4865
4928
  const converted = editorChainToAstChain(session.englishTree);