@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
@@ -9,6 +9,8 @@ type EditorSyncState = 'synced' | 'diverged';
9
9
  type EditorChain = {
10
10
  id: string;
11
11
  nodes: EditorNode[];
12
+ /** Complete script authored as \\mathnormal{ordered,index,atoms}. */
13
+ indexSequence?: boolean;
12
14
  };
13
15
  type EditorNode = {
14
16
  id: string;
@@ -9,6 +9,8 @@ type EditorSyncState = 'synced' | 'diverged';
9
9
  type EditorChain = {
10
10
  id: string;
11
11
  nodes: EditorNode[];
12
+ /** Complete script authored as \\mathnormal{ordered,index,atoms}. */
13
+ indexSequence?: boolean;
12
14
  };
13
15
  type EditorNode = {
14
16
  id: string;
package/dist/document2.js CHANGED
@@ -3291,6 +3291,31 @@ function renderRawOperatorLatex(expr, side) {
3291
3291
  return expr;
3292
3292
  }
3293
3293
 
3294
+ // src/editor/indexSequence.ts
3295
+ function isIndexComma(node) {
3296
+ return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
3297
+ }
3298
+ function isValidIndexSequence(chain) {
3299
+ let count = 0;
3300
+ let afterComma = false;
3301
+ for (const node of chain.nodes) {
3302
+ if (node.superscript || node.subscript) return false;
3303
+ if (isIndexComma(node)) {
3304
+ if (count === 0 || afterComma) return false;
3305
+ afterComma = true;
3306
+ continue;
3307
+ }
3308
+ const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
3309
+ const identity = node.sourceLatex ?? node.expr;
3310
+ const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
3311
+ if (!isDigit && !isLetter) return false;
3312
+ count += 1;
3313
+ afterComma = false;
3314
+ if (count > 64) return false;
3315
+ }
3316
+ return count >= 2 && !afterComma;
3317
+ }
3318
+
3294
3319
  // src/editor/render.ts
3295
3320
  function selectedDigitForm(options) {
3296
3321
  return options?.digitForm ?? "western";
@@ -3517,10 +3542,18 @@ function renderNodeArabic(node, options) {
3517
3542
  return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
3518
3543
  }
3519
3544
  function renderChainEnglish(chain, options) {
3545
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3546
+ const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
3547
+ return "\\mathnormal{" + atoms.join("") + "}";
3548
+ }
3520
3549
  return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
3521
3550
  }
3522
3551
  function renderChainArabic(chain, options) {
3523
- return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
3552
+ const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
3553
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3554
+ return "\\mathnormal{" + rendered.join("") + "}";
3555
+ }
3556
+ return rendered.join(" ");
3524
3557
  }
3525
3558
  function renderEnglishLatexFromSession(session) {
3526
3559
  return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
@@ -4420,14 +4453,14 @@ function attachScripts(astNode, editorNode) {
4420
4453
  editorNode.sourceLatex = astNode.sourceLatex;
4421
4454
  }
4422
4455
  if (astNode.superscript) {
4423
- const sup = chainToEditorChain(astNode.superscript);
4456
+ const sup = chainToEditorChain(astNode.superscript, true);
4424
4457
  if (!sup.editable) {
4425
4458
  return sup;
4426
4459
  }
4427
4460
  editorNode.superscript = sup.chain;
4428
4461
  }
4429
4462
  if (astNode.subscript) {
4430
- const sub = chainToEditorChain(astNode.subscript);
4463
+ const sub = chainToEditorChain(astNode.subscript, true);
4431
4464
  if (!sub.editable) {
4432
4465
  return sub;
4433
4466
  }
@@ -4815,7 +4848,33 @@ function normalizeVerticalDelimiterCommands(chain) {
4815
4848
  }
4816
4849
  return new ChainNode(normalized);
4817
4850
  }
4818
- function chainToEditorChain(chain) {
4851
+ function chainToEditorChain(chain, script = false) {
4852
+ if (script && chain.chain.length === 1) {
4853
+ const wrapper = chain.chain[0];
4854
+ if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
4855
+ if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
4856
+ 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" };
4857
+ }
4858
+ const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
4859
+ if (!imported.editable) return imported;
4860
+ const atoms = [];
4861
+ for (const node of imported.chain.nodes) {
4862
+ if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
4863
+ atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
4864
+ } else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
4865
+ atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
4866
+ } else {
4867
+ atoms.push(node);
4868
+ }
4869
+ }
4870
+ imported.chain.nodes = atoms;
4871
+ if (!isValidIndexSequence(imported.chain)) {
4872
+ 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" };
4873
+ }
4874
+ imported.chain.indexSequence = true;
4875
+ return imported;
4876
+ }
4877
+ }
4819
4878
  const nodes = [];
4820
4879
  for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
4821
4880
  const converted = astNodeToEditorNode(astNode);
@@ -5023,7 +5082,11 @@ function editorChainToAstChain(chain) {
5023
5082
  }
5024
5083
  nodes.push(converted.node);
5025
5084
  }
5026
- return { ok: true, chain: new ChainNode(nodes) };
5085
+ const content = new ChainNode(nodes);
5086
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
5087
+ return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
5088
+ }
5089
+ return { ok: true, chain: content };
5027
5090
  }
5028
5091
  function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
5029
5092
  const converted = editorChainToAstChain(session.englishTree);