@drghaliasri/butex 7.2.0 → 7.2.2

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 (48) hide show
  1. package/README.md +1 -0
  2. package/dist/document.d.mts +8 -0
  3. package/dist/document.d.ts +8 -0
  4. package/dist/document.js +38 -2
  5. package/dist/document.js.map +1 -1
  6. package/dist/document.mjs +38 -2
  7. package/dist/document.mjs.map +1 -1
  8. package/dist/document2-cli.js +107 -2
  9. package/dist/document2-cli.js.map +1 -1
  10. package/dist/document2.d.mts +8 -0
  11. package/dist/document2.d.ts +8 -0
  12. package/dist/document2.js +107 -2
  13. package/dist/document2.js.map +1 -1
  14. package/dist/document2.mjs +107 -2
  15. package/dist/document2.mjs.map +1 -1
  16. package/dist/index.d.mts +19 -1
  17. package/dist/index.d.ts +19 -1
  18. package/dist/index.global.js +109 -11
  19. package/dist/index.global.js.map +1 -1
  20. package/dist/index.js +109 -11
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +109 -11
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/react-document.d.mts +2 -0
  25. package/dist/react-document.d.ts +2 -0
  26. package/dist/react-document.js +230 -40
  27. package/dist/react-document.js.map +1 -1
  28. package/dist/react-document.mjs +230 -40
  29. package/dist/react-document.mjs.map +1 -1
  30. package/dist/react-document2-preview.d.mts +2 -0
  31. package/dist/react-document2-preview.d.ts +2 -0
  32. package/dist/react-document2-preview.js +91 -0
  33. package/dist/react-document2-preview.js.map +1 -1
  34. package/dist/react-document2-preview.mjs +91 -0
  35. package/dist/react-document2-preview.mjs.map +1 -1
  36. package/dist/react-document2.d.mts +8 -0
  37. package/dist/react-document2.d.ts +8 -0
  38. package/dist/react-document2.js +230 -40
  39. package/dist/react-document2.js.map +1 -1
  40. package/dist/react-document2.mjs +230 -40
  41. package/dist/react-document2.mjs.map +1 -1
  42. package/dist/react.d.mts +16 -0
  43. package/dist/react.d.ts +16 -0
  44. package/dist/react.js +230 -40
  45. package/dist/react.js.map +1 -1
  46. package/dist/react.mjs +230 -40
  47. package/dist/react.mjs.map +1 -1
  48. package/package.json +1 -1
@@ -17,6 +17,7 @@ var BaseAstNode = class {
17
17
  superscript;
18
18
  subscript;
19
19
  nodeType;
20
+ sourceLatex;
20
21
  constructor(state = null) {
21
22
  if (state === null) {
22
23
  state = new State();
@@ -25,6 +26,7 @@ var BaseAstNode = class {
25
26
  this.superscript = null;
26
27
  this.subscript = null;
27
28
  this.nodeType = this.constructor.name;
29
+ this.sourceLatex = null;
28
30
  }
29
31
  latex() {
30
32
  throw new Error("NotImplementedError");
@@ -213,6 +215,7 @@ ${this.closing}`;
213
215
  }
214
216
  };
215
217
  function parseScripts(node, json, mode) {
218
+ node.sourceLatex = typeof json.source_latex === "string" && json.source_latex.length > 0 ? json.source_latex : null;
216
219
  if (json.superscript) {
217
220
  node.superscript = parseChain(json.superscript, mode);
218
221
  }
@@ -1932,6 +1935,15 @@ var ATOMIC_OPERATOR_COMMANDS = {
1932
1935
  title: "\u0627\u0644\u0644\u0627\u0646\u0647\u0627\u064A\u0629",
1933
1936
  svg_path: null
1934
1937
  },
1938
+ top: {
1939
+ id: "top",
1940
+ category: "operators1",
1941
+ Tex: "\\top",
1942
+ mirror: false,
1943
+ Label: "\u22A4",
1944
+ title: "\u0627\u0644\u0645\u0646\u0642\u0648\u0644",
1945
+ svg_path: null
1946
+ },
1935
1947
  times: {
1936
1948
  id: "times",
1937
1949
  category: "operators1",
@@ -2669,6 +2681,7 @@ function cloneEditorSession(session) {
2669
2681
  forceSplitNextLeaf: session.forceSplitNextLeaf,
2670
2682
  arabicReverseNumberTyping: session.arabicReverseNumberTyping,
2671
2683
  currentCharacterFont: session.currentCharacterFont ?? "default",
2684
+ currentCharacterWrapper: session.currentCharacterWrapper ?? null,
2672
2685
  currentDigitForm: session.currentDigitForm ?? "western",
2673
2686
  caret: { ...session.caret },
2674
2687
  selection: session.selection ? { ...session.selection } : null,
@@ -2741,6 +2754,7 @@ function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
2741
2754
  forceSplitNextLeaf: false,
2742
2755
  arabicReverseNumberTyping: true,
2743
2756
  currentCharacterFont: "default",
2757
+ currentCharacterWrapper: null,
2744
2758
  currentDigitForm: "western",
2745
2759
  caret: {
2746
2760
  chainId: englishTree.id,
@@ -2810,6 +2824,7 @@ var CHARACTER_FONT_SPECS = [
2810
2824
  latexFontCommand: "\\maghribi",
2811
2825
  latexFontFamily: "Almaghribi Warsh Quran",
2812
2826
  browserFontStack: '"Almaghribi Warsh Quran", Amiri, "Segoe UI", Tahoma, sans-serif',
2827
+ importAliases: ["\\maghribi"],
2813
2828
  svgLayoutKey: "maghribi"
2814
2829
  }
2815
2830
  ];
@@ -2976,6 +2991,14 @@ function renderNodeEnglish(node, options) {
2976
2991
  return `${node.expr}${latinScripts(node, options)}`;
2977
2992
  }
2978
2993
  if (node.kind === "char") {
2994
+ if (node.sourceLatex) {
2995
+ return `${node.sourceLatex}${latinScripts(node, options)}`;
2996
+ }
2997
+ if (node.wrapperCommand) {
2998
+ const expr = formatDigits(node.expr, selectedDigitForm(options));
2999
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
3000
+ return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
3001
+ }
2979
3002
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
2980
3003
  }
2981
3004
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3029,6 +3052,10 @@ function renderNodeArabic(node, options) {
3029
3052
  if (node.kind === "char") {
3030
3053
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3031
3054
  const content = renderCharContent(node, options);
3055
+ if (node.wrapperCommand) {
3056
+ const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
3057
+ return arabicScripts(node, `${wrapper}{${content}}`, options);
3058
+ }
3032
3059
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
3033
3060
  }
3034
3061
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3627,6 +3654,11 @@ ${BUTEX_FONT_FACE_CSS}
3627
3654
 
3628
3655
  ${CHARACTER_FONT_CSS}
3629
3656
 
3657
+ .node-value--bold {
3658
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
3659
+ font-weight: 700;
3660
+ }
3661
+
3630
3662
  .chain {
3631
3663
  display: inline-flex;
3632
3664
  align-items: center;
@@ -3895,6 +3927,9 @@ function cloneChainWithFreshIds(chain) {
3895
3927
  return structuredClone(chain);
3896
3928
  }
3897
3929
  function attachScripts(astNode, editorNode) {
3930
+ if (astNode.sourceLatex) {
3931
+ editorNode.sourceLatex = astNode.sourceLatex;
3932
+ }
3898
3933
  if (astNode.superscript) {
3899
3934
  const sup = chainToEditorChain(astNode.superscript);
3900
3935
  if (!sup.editable) {
@@ -4021,6 +4056,49 @@ function charFromTextLikeCommand(node) {
4021
4056
  const scripts = attachScripts(node, editorNode);
4022
4057
  return scripts ?? { editable: true, node: editorNode };
4023
4058
  }
4059
+ function singleCommandChar(node) {
4060
+ if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
4061
+ return null;
4062
+ }
4063
+ const arg = node.mandatoryArgs[0];
4064
+ if (arg.chain.length !== 1 || !(arg.chain[0] instanceof CharNode)) {
4065
+ return null;
4066
+ }
4067
+ return arg.chain[0];
4068
+ }
4069
+ function wrappedAtomicCommandId(node) {
4070
+ if (node.name !== "\\mathbb" && node.name !== "\\mathrm") {
4071
+ return null;
4072
+ }
4073
+ const child = singleCommandChar(node);
4074
+ if (!child) {
4075
+ return null;
4076
+ }
4077
+ return commandIdForTex(`${node.name}{${child.expr}}`);
4078
+ }
4079
+ function editableWrapperCommand(node) {
4080
+ if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
4081
+ return null;
4082
+ }
4083
+ const child = singleCommandChar(node);
4084
+ if (!child) {
4085
+ return null;
4086
+ }
4087
+ const normalized = normalizeCharImportExpr(child.expr);
4088
+ const editorNode = createEditorNode("char", normalized.expr);
4089
+ if (normalized.characterFont !== "default") {
4090
+ editorNode.characterFont = normalized.characterFont;
4091
+ }
4092
+ editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
4093
+ const scripts = attachScripts(node, editorNode);
4094
+ if (scripts) {
4095
+ return scripts;
4096
+ }
4097
+ if (!editorNode.sourceLatex && node.name === "\\mathsf") {
4098
+ editorNode.sourceLatex = `\\mathsf{${child.expr}}`;
4099
+ }
4100
+ return { editable: true, node: editorNode };
4101
+ }
4024
4102
  function commandToEditorNode(node) {
4025
4103
  if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
4026
4104
  const frac = createFracNode();
@@ -4110,6 +4188,19 @@ function commandToEditorNode(node) {
4110
4188
  }
4111
4189
  return { editable: true, node: accent };
4112
4190
  }
4191
+ const wrappedAtomicId = wrappedAtomicCommandId(node);
4192
+ if (wrappedAtomicId) {
4193
+ const atomic = createEditorNode("atomicCommand", wrappedAtomicId);
4194
+ const scripts = attachScripts(node, atomic);
4195
+ if (scripts) {
4196
+ return scripts;
4197
+ }
4198
+ return { editable: true, node: atomic };
4199
+ }
4200
+ const wrapper = editableWrapperCommand(node);
4201
+ if (wrapper) {
4202
+ return wrapper;
4203
+ }
4113
4204
  const atomicId = commandIdForTex(node.name);
4114
4205
  if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
4115
4206
  const atomic = createEditorNode("atomicCommand", atomicId);