@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
@@ -289,6 +289,7 @@ var BaseAstNode = class {
289
289
  superscript;
290
290
  subscript;
291
291
  nodeType;
292
+ sourceLatex;
292
293
  constructor(state = null) {
293
294
  if (state === null) {
294
295
  state = new State();
@@ -297,6 +298,7 @@ var BaseAstNode = class {
297
298
  this.superscript = null;
298
299
  this.subscript = null;
299
300
  this.nodeType = this.constructor.name;
301
+ this.sourceLatex = null;
300
302
  }
301
303
  latex() {
302
304
  throw new Error("NotImplementedError");
@@ -485,6 +487,7 @@ ${this.closing}`;
485
487
  }
486
488
  };
487
489
  function parseScripts(node, json, mode) {
490
+ node.sourceLatex = typeof json.source_latex === "string" && json.source_latex.length > 0 ? json.source_latex : null;
488
491
  if (json.superscript) {
489
492
  node.superscript = parseChain(json.superscript, mode);
490
493
  }
@@ -624,7 +627,8 @@ function fromMathObjectJson(json, mode = "english") {
624
627
  function scriptsToJson(node, path) {
625
628
  return {
626
629
  ...node.superscript ? { superscript: chainToJson(node.superscript, `${path}.superscript`) } : {},
627
- ...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {}
630
+ ...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {},
631
+ ...node.sourceLatex ? { source_latex: node.sourceLatex } : {}
628
632
  };
629
633
  }
630
634
  function nodeToJson(node, path) {
@@ -2034,6 +2038,15 @@ var ATOMIC_OPERATOR_COMMANDS = {
2034
2038
  title: "\u0627\u0644\u0644\u0627\u0646\u0647\u0627\u064A\u0629",
2035
2039
  svg_path: null
2036
2040
  },
2041
+ top: {
2042
+ id: "top",
2043
+ category: "operators1",
2044
+ Tex: "\\top",
2045
+ mirror: false,
2046
+ Label: "\u22A4",
2047
+ title: "\u0627\u0644\u0645\u0646\u0642\u0648\u0644",
2048
+ svg_path: null
2049
+ },
2037
2050
  times: {
2038
2051
  id: "times",
2039
2052
  category: "operators1",
@@ -2771,6 +2784,7 @@ function cloneEditorSession(session) {
2771
2784
  forceSplitNextLeaf: session.forceSplitNextLeaf,
2772
2785
  arabicReverseNumberTyping: session.arabicReverseNumberTyping,
2773
2786
  currentCharacterFont: session.currentCharacterFont ?? "default",
2787
+ currentCharacterWrapper: session.currentCharacterWrapper ?? null,
2774
2788
  currentDigitForm: session.currentDigitForm ?? "western",
2775
2789
  caret: { ...session.caret },
2776
2790
  selection: session.selection ? { ...session.selection } : null,
@@ -2843,6 +2857,7 @@ function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
2843
2857
  forceSplitNextLeaf: false,
2844
2858
  arabicReverseNumberTyping: true,
2845
2859
  currentCharacterFont: "default",
2860
+ currentCharacterWrapper: null,
2846
2861
  currentDigitForm: "western",
2847
2862
  caret: {
2848
2863
  chainId: englishTree.id,
@@ -3079,6 +3094,14 @@ function renderNodeEnglish(node, options) {
3079
3094
  return `${node.expr}${latinScripts(node, options)}`;
3080
3095
  }
3081
3096
  if (node.kind === "char") {
3097
+ if (node.sourceLatex) {
3098
+ return `${node.sourceLatex}${latinScripts(node, options)}`;
3099
+ }
3100
+ if (node.wrapperCommand) {
3101
+ const expr = formatDigits(node.expr, selectedDigitForm(options));
3102
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
3103
+ return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
3104
+ }
3082
3105
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3083
3106
  }
3084
3107
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3132,6 +3155,10 @@ function renderNodeArabic(node, options) {
3132
3155
  if (node.kind === "char") {
3133
3156
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3134
3157
  const content = renderCharContent(node, options);
3158
+ if (node.wrapperCommand) {
3159
+ const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
3160
+ return arabicScripts(node, `${wrapper}{${content}}`, options);
3161
+ }
3135
3162
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
3136
3163
  }
3137
3164
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3708,6 +3735,11 @@ ${BUTEX_FONT_FACE_CSS}
3708
3735
 
3709
3736
  ${CHARACTER_FONT_CSS}
3710
3737
 
3738
+ .node-value--bold {
3739
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
3740
+ font-weight: 700;
3741
+ }
3742
+
3711
3743
  .chain {
3712
3744
  display: inline-flex;
3713
3745
  align-items: center;
@@ -3958,6 +3990,10 @@ var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
3958
3990
  function charEditorNodeToAstNode(node) {
3959
3991
  const font = node.characterFont ?? "default";
3960
3992
  const charNode = new CharNode(node.expr);
3993
+ if (node.wrapperCommand) {
3994
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
3995
+ return new CommandNode(wrapper, [], [new ChainNode([charNode])]);
3996
+ }
3961
3997
  if (font === "default") {
3962
3998
  return charNode;
3963
3999
  }
@@ -3984,6 +4020,9 @@ function cloneChainWithFreshIds(chain) {
3984
4020
  return structuredClone(chain);
3985
4021
  }
3986
4022
  function attachScripts(astNode, editorNode) {
4023
+ if (astNode.sourceLatex) {
4024
+ editorNode.sourceLatex = astNode.sourceLatex;
4025
+ }
3987
4026
  if (astNode.superscript) {
3988
4027
  const sup = chainToEditorChain(astNode.superscript);
3989
4028
  if (!sup.editable) {
@@ -4110,6 +4149,49 @@ function charFromTextLikeCommand(node) {
4110
4149
  const scripts = attachScripts(node, editorNode);
4111
4150
  return scripts ?? { editable: true, node: editorNode };
4112
4151
  }
4152
+ function singleCommandChar(node) {
4153
+ if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
4154
+ return null;
4155
+ }
4156
+ const arg = node.mandatoryArgs[0];
4157
+ if (arg.chain.length !== 1 || !(arg.chain[0] instanceof CharNode)) {
4158
+ return null;
4159
+ }
4160
+ return arg.chain[0];
4161
+ }
4162
+ function wrappedAtomicCommandId(node) {
4163
+ if (node.name !== "\\mathbb" && node.name !== "\\mathrm") {
4164
+ return null;
4165
+ }
4166
+ const child = singleCommandChar(node);
4167
+ if (!child) {
4168
+ return null;
4169
+ }
4170
+ return commandIdForTex(`${node.name}{${child.expr}}`);
4171
+ }
4172
+ function editableWrapperCommand(node) {
4173
+ if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
4174
+ return null;
4175
+ }
4176
+ const child = singleCommandChar(node);
4177
+ if (!child) {
4178
+ return null;
4179
+ }
4180
+ const normalized = normalizeCharImportExpr(child.expr);
4181
+ const editorNode = createEditorNode("char", normalized.expr);
4182
+ if (normalized.characterFont !== "default") {
4183
+ editorNode.characterFont = normalized.characterFont;
4184
+ }
4185
+ editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
4186
+ const scripts = attachScripts(node, editorNode);
4187
+ if (scripts) {
4188
+ return scripts;
4189
+ }
4190
+ if (!editorNode.sourceLatex && node.name === "\\mathsf") {
4191
+ editorNode.sourceLatex = `\\mathsf{${child.expr}}`;
4192
+ }
4193
+ return { editable: true, node: editorNode };
4194
+ }
4113
4195
  function commandToEditorNode(node) {
4114
4196
  if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
4115
4197
  const frac = createFracNode();
@@ -4199,6 +4281,19 @@ function commandToEditorNode(node) {
4199
4281
  }
4200
4282
  return { editable: true, node: accent };
4201
4283
  }
4284
+ const wrappedAtomicId = wrappedAtomicCommandId(node);
4285
+ if (wrappedAtomicId) {
4286
+ const atomic = createEditorNode("atomicCommand", wrappedAtomicId);
4287
+ const scripts = attachScripts(node, atomic);
4288
+ if (scripts) {
4289
+ return scripts;
4290
+ }
4291
+ return { editable: true, node: atomic };
4292
+ }
4293
+ const wrapper = editableWrapperCommand(node);
4294
+ if (wrapper) {
4295
+ return wrapper;
4296
+ }
4202
4297
  const atomicId = commandIdForTex(node.name);
4203
4298
  if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
4204
4299
  const atomic = createEditorNode("atomicCommand", atomicId);
@@ -4478,7 +4573,13 @@ function editorNodeToAstNode(node) {
4478
4573
  if (!tex) {
4479
4574
  return { ok: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
4480
4575
  }
4481
- astNode = new CommandNode(tex);
4576
+ if (node.expr === "ad") {
4577
+ astNode = new CommandNode("\\mathrm", [], [new ChainNode([new CharNode("d")])]);
4578
+ } else if (["N", "Z", "Q", "R", "C", "H"].includes(node.expr)) {
4579
+ astNode = new CommandNode("\\mathbb", [], [new ChainNode([new CharNode(node.expr)])]);
4580
+ } else {
4581
+ astNode = new CommandNode(tex);
4582
+ }
4482
4583
  } else if (node.kind === "atomicOperatorCommand") {
4483
4584
  const tex = atomicOperatorCommandSpec(node.expr)?.Tex;
4484
4585
  if (!tex) {
@@ -4495,6 +4596,9 @@ function editorNodeToAstNode(node) {
4495
4596
  } else {
4496
4597
  return { ok: false, reason: `\u0639\u0642\u062F\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.kind}` };
4497
4598
  }
4599
+ if (node.sourceLatex) {
4600
+ astNode.sourceLatex = node.sourceLatex;
4601
+ }
4498
4602
  const scripts = attachAstScripts(node, astNode);
4499
4603
  return scripts ?? { ok: true, node: astNode };
4500
4604
  }