@drghaliasri/butex 7.2.1 → 7.3.0

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 +37 -2
  5. package/dist/document.js.map +1 -1
  6. package/dist/document.mjs +37 -2
  7. package/dist/document.mjs.map +1 -1
  8. package/dist/document2-cli.js +106 -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 +106 -2
  13. package/dist/document2.js.map +1 -1
  14. package/dist/document2.mjs +106 -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 +108 -11
  19. package/dist/index.global.js.map +1 -1
  20. package/dist/index.js +108 -11
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +108 -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 +229 -40
  27. package/dist/react-document.js.map +1 -1
  28. package/dist/react-document.mjs +229 -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 +90 -0
  33. package/dist/react-document2-preview.js.map +1 -1
  34. package/dist/react-document2-preview.mjs +90 -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 +229 -40
  39. package/dist/react-document2.js.map +1 -1
  40. package/dist/react-document2.mjs +229 -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 +229 -40
  45. package/dist/react.js.map +1 -1
  46. package/dist/react.mjs +229 -40
  47. package/dist/react.mjs.map +1 -1
  48. package/package.json +1 -1
@@ -14,6 +14,7 @@ type ArabicNodeJson = {
14
14
  opening?: string;
15
15
  closing?: string;
16
16
  lines?: ChainJson[];
17
+ source_latex?: string;
17
18
  };
18
19
  type ChainJson = {
19
20
  node_type: 'ChainClass';
@@ -26,6 +27,7 @@ declare class BaseAstNode {
26
27
  superscript: ChainNode | null;
27
28
  subscript: ChainNode | null;
28
29
  nodeType: string;
30
+ sourceLatex: string | null;
29
31
  constructor(state?: State | null);
30
32
  latex(): string;
31
33
  arabicLatex(): string;
@@ -14,6 +14,7 @@ type ArabicNodeJson = {
14
14
  opening?: string;
15
15
  closing?: string;
16
16
  lines?: ChainJson[];
17
+ source_latex?: string;
17
18
  };
18
19
  type ChainJson = {
19
20
  node_type: 'ChainClass';
@@ -26,6 +27,7 @@ declare class BaseAstNode {
26
27
  superscript: ChainNode | null;
27
28
  subscript: ChainNode | null;
28
29
  nodeType: string;
30
+ sourceLatex: string | null;
29
31
  constructor(state?: State | null);
30
32
  latex(): string;
31
33
  arabicLatex(): string;
@@ -46,6 +46,7 @@ var BaseAstNode = class {
46
46
  superscript;
47
47
  subscript;
48
48
  nodeType;
49
+ sourceLatex;
49
50
  constructor(state = null) {
50
51
  if (state === null) {
51
52
  state = new State();
@@ -54,6 +55,7 @@ var BaseAstNode = class {
54
55
  this.superscript = null;
55
56
  this.subscript = null;
56
57
  this.nodeType = this.constructor.name;
58
+ this.sourceLatex = null;
57
59
  }
58
60
  latex() {
59
61
  throw new Error("NotImplementedError");
@@ -242,6 +244,7 @@ ${this.closing}`;
242
244
  }
243
245
  };
244
246
  function parseScripts(node, json, mode) {
247
+ node.sourceLatex = typeof json.source_latex === "string" && json.source_latex.length > 0 ? json.source_latex : null;
245
248
  if (json.superscript) {
246
249
  node.superscript = parseChain(json.superscript, mode);
247
250
  }
@@ -1961,6 +1964,15 @@ var ATOMIC_OPERATOR_COMMANDS = {
1961
1964
  title: "\u0627\u0644\u0644\u0627\u0646\u0647\u0627\u064A\u0629",
1962
1965
  svg_path: null
1963
1966
  },
1967
+ top: {
1968
+ id: "top",
1969
+ category: "operators1",
1970
+ Tex: "\\top",
1971
+ mirror: false,
1972
+ Label: "\u22A4",
1973
+ title: "\u0627\u0644\u0645\u0646\u0642\u0648\u0644",
1974
+ svg_path: null
1975
+ },
1964
1976
  times: {
1965
1977
  id: "times",
1966
1978
  category: "operators1",
@@ -2698,6 +2710,7 @@ function cloneEditorSession(session) {
2698
2710
  forceSplitNextLeaf: session.forceSplitNextLeaf,
2699
2711
  arabicReverseNumberTyping: session.arabicReverseNumberTyping,
2700
2712
  currentCharacterFont: session.currentCharacterFont ?? "default",
2713
+ currentCharacterWrapper: session.currentCharacterWrapper ?? null,
2701
2714
  currentDigitForm: session.currentDigitForm ?? "western",
2702
2715
  caret: { ...session.caret },
2703
2716
  selection: session.selection ? { ...session.selection } : null,
@@ -2770,6 +2783,7 @@ function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
2770
2783
  forceSplitNextLeaf: false,
2771
2784
  arabicReverseNumberTyping: true,
2772
2785
  currentCharacterFont: "default",
2786
+ currentCharacterWrapper: null,
2773
2787
  currentDigitForm: "western",
2774
2788
  caret: {
2775
2789
  chainId: englishTree.id,
@@ -3006,6 +3020,14 @@ function renderNodeEnglish(node, options) {
3006
3020
  return `${node.expr}${latinScripts(node, options)}`;
3007
3021
  }
3008
3022
  if (node.kind === "char") {
3023
+ if (node.sourceLatex) {
3024
+ return `${node.sourceLatex}${latinScripts(node, options)}`;
3025
+ }
3026
+ if (node.wrapperCommand) {
3027
+ const expr = formatDigits(node.expr, selectedDigitForm(options));
3028
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
3029
+ return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
3030
+ }
3009
3031
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3010
3032
  }
3011
3033
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3059,6 +3081,10 @@ function renderNodeArabic(node, options) {
3059
3081
  if (node.kind === "char") {
3060
3082
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3061
3083
  const content = renderCharContent(node, options);
3084
+ if (node.wrapperCommand) {
3085
+ const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
3086
+ return arabicScripts(node, `${wrapper}{${content}}`, options);
3087
+ }
3062
3088
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
3063
3089
  }
3064
3090
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3657,6 +3683,11 @@ ${BUTEX_FONT_FACE_CSS}
3657
3683
 
3658
3684
  ${CHARACTER_FONT_CSS}
3659
3685
 
3686
+ .node-value--bold {
3687
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
3688
+ font-weight: 700;
3689
+ }
3690
+
3660
3691
  .chain {
3661
3692
  display: inline-flex;
3662
3693
  align-items: center;
@@ -3925,6 +3956,9 @@ function cloneChainWithFreshIds(chain) {
3925
3956
  return structuredClone(chain);
3926
3957
  }
3927
3958
  function attachScripts(astNode, editorNode) {
3959
+ if (astNode.sourceLatex) {
3960
+ editorNode.sourceLatex = astNode.sourceLatex;
3961
+ }
3928
3962
  if (astNode.superscript) {
3929
3963
  const sup = chainToEditorChain(astNode.superscript);
3930
3964
  if (!sup.editable) {
@@ -4051,6 +4085,49 @@ function charFromTextLikeCommand(node) {
4051
4085
  const scripts = attachScripts(node, editorNode);
4052
4086
  return scripts ?? { editable: true, node: editorNode };
4053
4087
  }
4088
+ function singleCommandChar(node) {
4089
+ if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
4090
+ return null;
4091
+ }
4092
+ const arg = node.mandatoryArgs[0];
4093
+ if (arg.chain.length !== 1 || !(arg.chain[0] instanceof CharNode)) {
4094
+ return null;
4095
+ }
4096
+ return arg.chain[0];
4097
+ }
4098
+ function wrappedAtomicCommandId(node) {
4099
+ if (node.name !== "\\mathbb" && node.name !== "\\mathrm") {
4100
+ return null;
4101
+ }
4102
+ const child = singleCommandChar(node);
4103
+ if (!child) {
4104
+ return null;
4105
+ }
4106
+ return commandIdForTex(`${node.name}{${child.expr}}`);
4107
+ }
4108
+ function editableWrapperCommand(node) {
4109
+ if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
4110
+ return null;
4111
+ }
4112
+ const child = singleCommandChar(node);
4113
+ if (!child) {
4114
+ return null;
4115
+ }
4116
+ const normalized = normalizeCharImportExpr(child.expr);
4117
+ const editorNode = createEditorNode("char", normalized.expr);
4118
+ if (normalized.characterFont !== "default") {
4119
+ editorNode.characterFont = normalized.characterFont;
4120
+ }
4121
+ editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
4122
+ const scripts = attachScripts(node, editorNode);
4123
+ if (scripts) {
4124
+ return scripts;
4125
+ }
4126
+ if (!editorNode.sourceLatex && node.name === "\\mathsf") {
4127
+ editorNode.sourceLatex = `\\mathsf{${child.expr}}`;
4128
+ }
4129
+ return { editable: true, node: editorNode };
4130
+ }
4054
4131
  function commandToEditorNode(node) {
4055
4132
  if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
4056
4133
  const frac = createFracNode();
@@ -4140,6 +4217,19 @@ function commandToEditorNode(node) {
4140
4217
  }
4141
4218
  return { editable: true, node: accent };
4142
4219
  }
4220
+ const wrappedAtomicId = wrappedAtomicCommandId(node);
4221
+ if (wrappedAtomicId) {
4222
+ const atomic = createEditorNode("atomicCommand", wrappedAtomicId);
4223
+ const scripts = attachScripts(node, atomic);
4224
+ if (scripts) {
4225
+ return scripts;
4226
+ }
4227
+ return { editable: true, node: atomic };
4228
+ }
4229
+ const wrapper = editableWrapperCommand(node);
4230
+ if (wrapper) {
4231
+ return wrapper;
4232
+ }
4143
4233
  const atomicId = commandIdForTex(node.name);
4144
4234
  if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
4145
4235
  const atomic = createEditorNode("atomicCommand", atomicId);