@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
package/README.md CHANGED
@@ -153,6 +153,7 @@ Use this when you want the same editor UX as the demo:
153
153
  - Wire your toolbar/actions to runtime methods (`toggleSide`, `insertDelimiterByKind`, `addSup`, `addSub`, `removeSup`, `removeSub`, `deleteStructure`, `performUndo`, `performRedo`, `performCopy`, `performCut`, `performPaste`).
154
154
  - Use `onSessionChange(session)` to render external previews (e.g., MathJax pane, status labels).
155
155
  - **Imported `MathObject` / `CharObject` for the editor:** document LaTeX preview treats `CharObject.expr` as already-rendered Arabic TeX (e.g. `\text{م}`). When opening an imported equation in `<ButexEditor />` via `mathObjectToEditorSession`, BuTeX unwraps supported LaTeX text/font wrappers into plain glyph `expr` plus editor `characterFont`. Supported patterns: `\text{…}`, `\takween{…}`, `\diwani{…}`, `\butextakween{…}`, `\butexdiwani{…}`, `\butexdiwanioutline{…}`, `\butexmaghribi{…}`, and nested forms such as `\text{\takween{…}}`. On save, default-font chars stay plain `CharObject` nodes; non-default fonts are stored as font `CommandObject` wrappers so editor round-trip preserves `characterFont`. Upstream converters may still emit wrapped `expr` on import.
156
+ - **Standard math round-trip:** imported structured equations preserve explicit `\top`, the six `\mathbb{N/Z/Q/R/C/H}` number systems, exact differential `\mathrm{d}`, atomic named variables carried by `\mathtt{...}`, and units carried through `\unit{...}` / upstream `\mathsf{...}` source identity. Node-bound `source_latex` is preserved only while that editable occurrence is unchanged and is cleared when its editable name changes.
156
157
 
157
158
  Minimal browser example:
158
159
 
@@ -12,6 +12,7 @@ type ArabicNodeJson = {
12
12
  opening?: string;
13
13
  closing?: string;
14
14
  lines?: ChainJson[];
15
+ source_latex?: string;
15
16
  };
16
17
  type ChainJson = {
17
18
  node_type: 'ChainClass';
@@ -24,6 +25,7 @@ declare class BaseAstNode {
24
25
  superscript: ChainNode | null;
25
26
  subscript: ChainNode | null;
26
27
  nodeType: string;
28
+ sourceLatex: string | null;
27
29
  constructor(state?: State | null);
28
30
  latex(): string;
29
31
  arabicLatex(): string;
@@ -177,6 +179,10 @@ type EditorNode = {
177
179
  kind: EditorNodeKind;
178
180
  expr: string;
179
181
  characterFont?: CharacterFontId;
182
+ /** Minimal upstream source identity used only while the node remains unchanged. */
183
+ sourceLatex?: string;
184
+ /** Existing editor node reused for wrapper commands that need editable content. */
185
+ wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
180
186
  superscript: EditorChain | null;
181
187
  subscript: EditorChain | null;
182
188
  leftDelimExpr: string;
@@ -228,6 +234,8 @@ type EditorSession = {
228
234
  arabicReverseNumberTyping: boolean;
229
235
  /** Font applied to newly typed char nodes. */
230
236
  currentCharacterFont: CharacterFontId;
237
+ /** Structured command wrapper applied to newly typed chars; kept separate from fonts. */
238
+ currentCharacterWrapper: '\\boldarabic' | null;
231
239
  /** Digit glyph form used for editor display and LaTeX preview output. */
232
240
  currentDigitForm: DigitFormId;
233
241
  caret: EditorCaret;
@@ -12,6 +12,7 @@ type ArabicNodeJson = {
12
12
  opening?: string;
13
13
  closing?: string;
14
14
  lines?: ChainJson[];
15
+ source_latex?: string;
15
16
  };
16
17
  type ChainJson = {
17
18
  node_type: 'ChainClass';
@@ -24,6 +25,7 @@ declare class BaseAstNode {
24
25
  superscript: ChainNode | null;
25
26
  subscript: ChainNode | null;
26
27
  nodeType: string;
28
+ sourceLatex: string | null;
27
29
  constructor(state?: State | null);
28
30
  latex(): string;
29
31
  arabicLatex(): string;
@@ -177,6 +179,10 @@ type EditorNode = {
177
179
  kind: EditorNodeKind;
178
180
  expr: string;
179
181
  characterFont?: CharacterFontId;
182
+ /** Minimal upstream source identity used only while the node remains unchanged. */
183
+ sourceLatex?: string;
184
+ /** Existing editor node reused for wrapper commands that need editable content. */
185
+ wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
180
186
  superscript: EditorChain | null;
181
187
  subscript: EditorChain | null;
182
188
  leftDelimExpr: string;
@@ -228,6 +234,8 @@ type EditorSession = {
228
234
  arabicReverseNumberTyping: boolean;
229
235
  /** Font applied to newly typed char nodes. */
230
236
  currentCharacterFont: CharacterFontId;
237
+ /** Structured command wrapper applied to newly typed chars; kept separate from fonts. */
238
+ currentCharacterWrapper: '\\boldarabic' | null;
231
239
  /** Digit glyph form used for editor display and LaTeX preview output. */
232
240
  currentDigitForm: DigitFormId;
233
241
  caret: EditorCaret;
package/dist/document.js CHANGED
@@ -78,6 +78,7 @@ var BaseAstNode = class {
78
78
  superscript;
79
79
  subscript;
80
80
  nodeType;
81
+ sourceLatex;
81
82
  constructor(state = null) {
82
83
  if (state === null) {
83
84
  state = new State();
@@ -86,6 +87,7 @@ var BaseAstNode = class {
86
87
  this.superscript = null;
87
88
  this.subscript = null;
88
89
  this.nodeType = this.constructor.name;
90
+ this.sourceLatex = null;
89
91
  }
90
92
  latex() {
91
93
  throw new Error("NotImplementedError");
@@ -274,6 +276,7 @@ ${this.closing}`;
274
276
  }
275
277
  };
276
278
  function parseScripts(node, json, mode) {
279
+ node.sourceLatex = typeof json.source_latex === "string" && json.source_latex.length > 0 ? json.source_latex : null;
277
280
  if (json.superscript) {
278
281
  node.superscript = parseChain(json.superscript, mode);
279
282
  }
@@ -413,7 +416,8 @@ function fromMathObjectJson(json, mode = "english") {
413
416
  function scriptsToJson(node, path) {
414
417
  return {
415
418
  ...node.superscript ? { superscript: chainToJson(node.superscript, `${path}.superscript`) } : {},
416
- ...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {}
419
+ ...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {},
420
+ ...node.sourceLatex ? { source_latex: node.sourceLatex } : {}
417
421
  };
418
422
  }
419
423
  function nodeToJson(node, path) {
@@ -1346,6 +1350,15 @@ var ATOMIC_OPERATOR_COMMANDS = {
1346
1350
  title: "\u0627\u0644\u0644\u0627\u0646\u0647\u0627\u064A\u0629",
1347
1351
  svg_path: null
1348
1352
  },
1353
+ top: {
1354
+ id: "top",
1355
+ category: "operators1",
1356
+ Tex: "\\top",
1357
+ mirror: false,
1358
+ Label: "\u22A4",
1359
+ title: "\u0627\u0644\u0645\u0646\u0642\u0648\u0644",
1360
+ svg_path: null
1361
+ },
1349
1362
  times: {
1350
1363
  id: "times",
1351
1364
  category: "operators1",
@@ -2134,6 +2147,10 @@ function renderNodeArabic(node, options) {
2134
2147
  if (node.kind === "char") {
2135
2148
  const expr = formatDigits(node.expr, selectedDigitForm(options));
2136
2149
  const content = renderCharContent(node, options);
2150
+ if (node.wrapperCommand) {
2151
+ const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
2152
+ return arabicScripts(node, `${wrapper}{${content}}`, options);
2153
+ }
2137
2154
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
2138
2155
  }
2139
2156
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -2704,6 +2721,11 @@ ${BUTEX_FONT_FACE_CSS}
2704
2721
 
2705
2722
  ${CHARACTER_FONT_CSS}
2706
2723
 
2724
+ .node-value--bold {
2725
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
2726
+ font-weight: 700;
2727
+ }
2728
+
2707
2729
  .chain {
2708
2730
  display: inline-flex;
2709
2731
  align-items: center;
@@ -2899,6 +2921,10 @@ var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
2899
2921
  function charEditorNodeToAstNode(node) {
2900
2922
  const font = node.characterFont ?? "default";
2901
2923
  const charNode = new CharNode(node.expr);
2924
+ if (node.wrapperCommand) {
2925
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
2926
+ return new CommandNode(wrapper, [], [new ChainNode([charNode])]);
2927
+ }
2902
2928
  if (font === "default") {
2903
2929
  return charNode;
2904
2930
  }
@@ -3044,7 +3070,13 @@ function editorNodeToAstNode(node) {
3044
3070
  if (!tex) {
3045
3071
  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}` };
3046
3072
  }
3047
- astNode = new CommandNode(tex);
3073
+ if (node.expr === "ad") {
3074
+ astNode = new CommandNode("\\mathrm", [], [new ChainNode([new CharNode("d")])]);
3075
+ } else if (["N", "Z", "Q", "R", "C", "H"].includes(node.expr)) {
3076
+ astNode = new CommandNode("\\mathbb", [], [new ChainNode([new CharNode(node.expr)])]);
3077
+ } else {
3078
+ astNode = new CommandNode(tex);
3079
+ }
3048
3080
  } else if (node.kind === "atomicOperatorCommand") {
3049
3081
  const tex = atomicOperatorCommandSpec(node.expr)?.Tex;
3050
3082
  if (!tex) {
@@ -3061,6 +3093,9 @@ function editorNodeToAstNode(node) {
3061
3093
  } else {
3062
3094
  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}` };
3063
3095
  }
3096
+ if (node.sourceLatex) {
3097
+ astNode.sourceLatex = node.sourceLatex;
3098
+ }
3064
3099
  const scripts = attachAstScripts(node, astNode);
3065
3100
  return scripts ?? { ok: true, node: astNode };
3066
3101
  }