@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
@@ -15,6 +15,10 @@ type EditorNode = {
15
15
  kind: EditorNodeKind;
16
16
  expr: string;
17
17
  characterFont?: CharacterFontId;
18
+ /** Minimal upstream source identity used only while the node remains unchanged. */
19
+ sourceLatex?: string;
20
+ /** Existing editor node reused for wrapper commands that need editable content. */
21
+ wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
18
22
  superscript: EditorChain | null;
19
23
  subscript: EditorChain | null;
20
24
  leftDelimExpr: string;
@@ -66,6 +70,8 @@ type EditorSession = {
66
70
  arabicReverseNumberTyping: boolean;
67
71
  /** Font applied to newly typed char nodes. */
68
72
  currentCharacterFont: CharacterFontId;
73
+ /** Structured command wrapper applied to newly typed chars; kept separate from fonts. */
74
+ currentCharacterWrapper: '\\boldarabic' | null;
69
75
  /** Digit glyph form used for editor display and LaTeX preview output. */
70
76
  currentDigitForm: DigitFormId;
71
77
  caret: EditorCaret;
@@ -93,6 +99,7 @@ type ArabicNodeJson = {
93
99
  opening?: string;
94
100
  closing?: string;
95
101
  lines?: ChainJson[];
102
+ source_latex?: string;
96
103
  };
97
104
  type ChainJson = {
98
105
  node_type: 'ChainClass';
@@ -105,6 +112,7 @@ declare class BaseAstNode {
105
112
  superscript: ChainNode | null;
106
113
  subscript: ChainNode | null;
107
114
  nodeType: string;
115
+ sourceLatex: string | null;
108
116
  constructor(state?: State | null);
109
117
  latex(): string;
110
118
  arabicLatex(): string;
@@ -15,6 +15,10 @@ type EditorNode = {
15
15
  kind: EditorNodeKind;
16
16
  expr: string;
17
17
  characterFont?: CharacterFontId;
18
+ /** Minimal upstream source identity used only while the node remains unchanged. */
19
+ sourceLatex?: string;
20
+ /** Existing editor node reused for wrapper commands that need editable content. */
21
+ wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
18
22
  superscript: EditorChain | null;
19
23
  subscript: EditorChain | null;
20
24
  leftDelimExpr: string;
@@ -66,6 +70,8 @@ type EditorSession = {
66
70
  arabicReverseNumberTyping: boolean;
67
71
  /** Font applied to newly typed char nodes. */
68
72
  currentCharacterFont: CharacterFontId;
73
+ /** Structured command wrapper applied to newly typed chars; kept separate from fonts. */
74
+ currentCharacterWrapper: '\\boldarabic' | null;
69
75
  /** Digit glyph form used for editor display and LaTeX preview output. */
70
76
  currentDigitForm: DigitFormId;
71
77
  caret: EditorCaret;
@@ -93,6 +99,7 @@ type ArabicNodeJson = {
93
99
  opening?: string;
94
100
  closing?: string;
95
101
  lines?: ChainJson[];
102
+ source_latex?: string;
96
103
  };
97
104
  type ChainJson = {
98
105
  node_type: 'ChainClass';
@@ -105,6 +112,7 @@ declare class BaseAstNode {
105
112
  superscript: ChainNode | null;
106
113
  subscript: ChainNode | null;
107
114
  nodeType: string;
115
+ sourceLatex: string | null;
108
116
  constructor(state?: State | null);
109
117
  latex(): string;
110
118
  arabicLatex(): string;
package/dist/document2.js CHANGED
@@ -550,6 +550,7 @@ var BaseAstNode = class {
550
550
  superscript;
551
551
  subscript;
552
552
  nodeType;
553
+ sourceLatex;
553
554
  constructor(state = null) {
554
555
  if (state === null) {
555
556
  state = new State();
@@ -558,6 +559,7 @@ var BaseAstNode = class {
558
559
  this.superscript = null;
559
560
  this.subscript = null;
560
561
  this.nodeType = this.constructor.name;
562
+ this.sourceLatex = null;
561
563
  }
562
564
  latex() {
563
565
  throw new Error("NotImplementedError");
@@ -746,6 +748,7 @@ ${this.closing}`;
746
748
  }
747
749
  };
748
750
  function parseScripts(node, json, mode) {
751
+ node.sourceLatex = typeof json.source_latex === "string" && json.source_latex.length > 0 ? json.source_latex : null;
749
752
  if (json.superscript) {
750
753
  node.superscript = parseChain(json.superscript, mode);
751
754
  }
@@ -885,7 +888,8 @@ function fromMathObjectJson(json, mode = "english") {
885
888
  function scriptsToJson(node, path) {
886
889
  return {
887
890
  ...node.superscript ? { superscript: chainToJson(node.superscript, `${path}.superscript`) } : {},
888
- ...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {}
891
+ ...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {},
892
+ ...node.sourceLatex ? { source_latex: node.sourceLatex } : {}
889
893
  };
890
894
  }
891
895
  function nodeToJson(node, path) {
@@ -2354,6 +2358,15 @@ var ATOMIC_OPERATOR_COMMANDS = {
2354
2358
  title: "\u0627\u0644\u0644\u0627\u0646\u0647\u0627\u064A\u0629",
2355
2359
  svg_path: null
2356
2360
  },
2361
+ top: {
2362
+ id: "top",
2363
+ category: "operators1",
2364
+ Tex: "\\top",
2365
+ mirror: false,
2366
+ Label: "\u22A4",
2367
+ title: "\u0627\u0644\u0645\u0646\u0642\u0648\u0644",
2368
+ svg_path: null
2369
+ },
2357
2370
  times: {
2358
2371
  id: "times",
2359
2372
  category: "operators1",
@@ -3091,6 +3104,7 @@ function cloneEditorSession(session) {
3091
3104
  forceSplitNextLeaf: session.forceSplitNextLeaf,
3092
3105
  arabicReverseNumberTyping: session.arabicReverseNumberTyping,
3093
3106
  currentCharacterFont: session.currentCharacterFont ?? "default",
3107
+ currentCharacterWrapper: session.currentCharacterWrapper ?? null,
3094
3108
  currentDigitForm: session.currentDigitForm ?? "western",
3095
3109
  caret: { ...session.caret },
3096
3110
  selection: session.selection ? { ...session.selection } : null,
@@ -3163,6 +3177,7 @@ function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
3163
3177
  forceSplitNextLeaf: false,
3164
3178
  arabicReverseNumberTyping: true,
3165
3179
  currentCharacterFont: "default",
3180
+ currentCharacterWrapper: null,
3166
3181
  currentDigitForm: "western",
3167
3182
  caret: {
3168
3183
  chainId: englishTree.id,
@@ -3399,6 +3414,14 @@ function renderNodeEnglish(node, options) {
3399
3414
  return `${node.expr}${latinScripts(node, options)}`;
3400
3415
  }
3401
3416
  if (node.kind === "char") {
3417
+ if (node.sourceLatex) {
3418
+ return `${node.sourceLatex}${latinScripts(node, options)}`;
3419
+ }
3420
+ if (node.wrapperCommand) {
3421
+ const expr = formatDigits(node.expr, selectedDigitForm(options));
3422
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
3423
+ return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
3424
+ }
3402
3425
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3403
3426
  }
3404
3427
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3452,6 +3475,10 @@ function renderNodeArabic(node, options) {
3452
3475
  if (node.kind === "char") {
3453
3476
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3454
3477
  const content = renderCharContent(node, options);
3478
+ if (node.wrapperCommand) {
3479
+ const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
3480
+ return arabicScripts(node, `${wrapper}{${content}}`, options);
3481
+ }
3455
3482
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
3456
3483
  }
3457
3484
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -4050,6 +4077,11 @@ ${BUTEX_FONT_FACE_CSS}
4050
4077
 
4051
4078
  ${CHARACTER_FONT_CSS}
4052
4079
 
4080
+ .node-value--bold {
4081
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
4082
+ font-weight: 700;
4083
+ }
4084
+
4053
4085
  .chain {
4054
4086
  display: inline-flex;
4055
4087
  align-items: center;
@@ -4300,6 +4332,10 @@ var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
4300
4332
  function charEditorNodeToAstNode(node) {
4301
4333
  const font = node.characterFont ?? "default";
4302
4334
  const charNode = new CharNode(node.expr);
4335
+ if (node.wrapperCommand) {
4336
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
4337
+ return new CommandNode(wrapper, [], [new ChainNode([charNode])]);
4338
+ }
4303
4339
  if (font === "default") {
4304
4340
  return charNode;
4305
4341
  }
@@ -4326,6 +4362,9 @@ function cloneChainWithFreshIds(chain) {
4326
4362
  return structuredClone(chain);
4327
4363
  }
4328
4364
  function attachScripts(astNode, editorNode) {
4365
+ if (astNode.sourceLatex) {
4366
+ editorNode.sourceLatex = astNode.sourceLatex;
4367
+ }
4329
4368
  if (astNode.superscript) {
4330
4369
  const sup = chainToEditorChain(astNode.superscript);
4331
4370
  if (!sup.editable) {
@@ -4452,6 +4491,49 @@ function charFromTextLikeCommand(node) {
4452
4491
  const scripts = attachScripts(node, editorNode);
4453
4492
  return scripts ?? { editable: true, node: editorNode };
4454
4493
  }
4494
+ function singleCommandChar(node) {
4495
+ if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
4496
+ return null;
4497
+ }
4498
+ const arg = node.mandatoryArgs[0];
4499
+ if (arg.chain.length !== 1 || !(arg.chain[0] instanceof CharNode)) {
4500
+ return null;
4501
+ }
4502
+ return arg.chain[0];
4503
+ }
4504
+ function wrappedAtomicCommandId(node) {
4505
+ if (node.name !== "\\mathbb" && node.name !== "\\mathrm") {
4506
+ return null;
4507
+ }
4508
+ const child = singleCommandChar(node);
4509
+ if (!child) {
4510
+ return null;
4511
+ }
4512
+ return commandIdForTex(`${node.name}{${child.expr}}`);
4513
+ }
4514
+ function editableWrapperCommand(node) {
4515
+ if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
4516
+ return null;
4517
+ }
4518
+ const child = singleCommandChar(node);
4519
+ if (!child) {
4520
+ return null;
4521
+ }
4522
+ const normalized = normalizeCharImportExpr(child.expr);
4523
+ const editorNode = createEditorNode("char", normalized.expr);
4524
+ if (normalized.characterFont !== "default") {
4525
+ editorNode.characterFont = normalized.characterFont;
4526
+ }
4527
+ editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
4528
+ const scripts = attachScripts(node, editorNode);
4529
+ if (scripts) {
4530
+ return scripts;
4531
+ }
4532
+ if (!editorNode.sourceLatex && node.name === "\\mathsf") {
4533
+ editorNode.sourceLatex = `\\mathsf{${child.expr}}`;
4534
+ }
4535
+ return { editable: true, node: editorNode };
4536
+ }
4455
4537
  function commandToEditorNode(node) {
4456
4538
  if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
4457
4539
  const frac = createFracNode();
@@ -4541,6 +4623,19 @@ function commandToEditorNode(node) {
4541
4623
  }
4542
4624
  return { editable: true, node: accent };
4543
4625
  }
4626
+ const wrappedAtomicId = wrappedAtomicCommandId(node);
4627
+ if (wrappedAtomicId) {
4628
+ const atomic = createEditorNode("atomicCommand", wrappedAtomicId);
4629
+ const scripts = attachScripts(node, atomic);
4630
+ if (scripts) {
4631
+ return scripts;
4632
+ }
4633
+ return { editable: true, node: atomic };
4634
+ }
4635
+ const wrapper = editableWrapperCommand(node);
4636
+ if (wrapper) {
4637
+ return wrapper;
4638
+ }
4544
4639
  const atomicId = commandIdForTex(node.name);
4545
4640
  if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
4546
4641
  const atomic = createEditorNode("atomicCommand", atomicId);
@@ -4820,7 +4915,13 @@ function editorNodeToAstNode(node) {
4820
4915
  if (!tex) {
4821
4916
  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}` };
4822
4917
  }
4823
- astNode = new CommandNode(tex);
4918
+ if (node.expr === "ad") {
4919
+ astNode = new CommandNode("\\mathrm", [], [new ChainNode([new CharNode("d")])]);
4920
+ } else if (["N", "Z", "Q", "R", "C", "H"].includes(node.expr)) {
4921
+ astNode = new CommandNode("\\mathbb", [], [new ChainNode([new CharNode(node.expr)])]);
4922
+ } else {
4923
+ astNode = new CommandNode(tex);
4924
+ }
4824
4925
  } else if (node.kind === "atomicOperatorCommand") {
4825
4926
  const tex = atomicOperatorCommandSpec(node.expr)?.Tex;
4826
4927
  if (!tex) {
@@ -4837,6 +4938,9 @@ function editorNodeToAstNode(node) {
4837
4938
  } else {
4838
4939
  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}` };
4839
4940
  }
4941
+ if (node.sourceLatex) {
4942
+ astNode.sourceLatex = node.sourceLatex;
4943
+ }
4840
4944
  const scripts = attachAstScripts(node, astNode);
4841
4945
  return scripts ?? { ok: true, node: astNode };
4842
4946
  }