@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
@@ -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,
@@ -2912,6 +2927,7 @@ var CHARACTER_FONT_SPECS = [
2912
2927
  latexFontCommand: "\\maghribi",
2913
2928
  latexFontFamily: "Almaghribi Warsh Quran",
2914
2929
  browserFontStack: '"Almaghribi Warsh Quran", Amiri, "Segoe UI", Tahoma, sans-serif',
2930
+ importAliases: ["\\maghribi"],
2915
2931
  svgLayoutKey: "maghribi"
2916
2932
  }
2917
2933
  ];
@@ -3078,6 +3094,14 @@ function renderNodeEnglish(node, options) {
3078
3094
  return `${node.expr}${latinScripts(node, options)}`;
3079
3095
  }
3080
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
+ }
3081
3105
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3082
3106
  }
3083
3107
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3131,6 +3155,10 @@ function renderNodeArabic(node, options) {
3131
3155
  if (node.kind === "char") {
3132
3156
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3133
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
+ }
3134
3162
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
3135
3163
  }
3136
3164
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3707,6 +3735,11 @@ ${BUTEX_FONT_FACE_CSS}
3707
3735
 
3708
3736
  ${CHARACTER_FONT_CSS}
3709
3737
 
3738
+ .node-value--bold {
3739
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
3740
+ font-weight: 700;
3741
+ }
3742
+
3710
3743
  .chain {
3711
3744
  display: inline-flex;
3712
3745
  align-items: center;
@@ -3957,6 +3990,10 @@ var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
3957
3990
  function charEditorNodeToAstNode(node) {
3958
3991
  const font = node.characterFont ?? "default";
3959
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
+ }
3960
3997
  if (font === "default") {
3961
3998
  return charNode;
3962
3999
  }
@@ -3983,6 +4020,9 @@ function cloneChainWithFreshIds(chain) {
3983
4020
  return structuredClone(chain);
3984
4021
  }
3985
4022
  function attachScripts(astNode, editorNode) {
4023
+ if (astNode.sourceLatex) {
4024
+ editorNode.sourceLatex = astNode.sourceLatex;
4025
+ }
3986
4026
  if (astNode.superscript) {
3987
4027
  const sup = chainToEditorChain(astNode.superscript);
3988
4028
  if (!sup.editable) {
@@ -4109,6 +4149,49 @@ function charFromTextLikeCommand(node) {
4109
4149
  const scripts = attachScripts(node, editorNode);
4110
4150
  return scripts ?? { editable: true, node: editorNode };
4111
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
+ }
4112
4195
  function commandToEditorNode(node) {
4113
4196
  if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
4114
4197
  const frac = createFracNode();
@@ -4198,6 +4281,19 @@ function commandToEditorNode(node) {
4198
4281
  }
4199
4282
  return { editable: true, node: accent };
4200
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
+ }
4201
4297
  const atomicId = commandIdForTex(node.name);
4202
4298
  if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
4203
4299
  const atomic = createEditorNode("atomicCommand", atomicId);
@@ -4477,7 +4573,13 @@ function editorNodeToAstNode(node) {
4477
4573
  if (!tex) {
4478
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}` };
4479
4575
  }
4480
- 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
+ }
4481
4583
  } else if (node.kind === "atomicOperatorCommand") {
4482
4584
  const tex = atomicOperatorCommandSpec(node.expr)?.Tex;
4483
4585
  if (!tex) {
@@ -4494,6 +4596,9 @@ function editorNodeToAstNode(node) {
4494
4596
  } else {
4495
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}` };
4496
4598
  }
4599
+ if (node.sourceLatex) {
4600
+ astNode.sourceLatex = node.sourceLatex;
4601
+ }
4497
4602
  const scripts = attachAstScripts(node, astNode);
4498
4603
  return scripts ?? { ok: true, node: astNode };
4499
4604
  }