@drghaliasri/butex 7.2.1 → 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 +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
@@ -386,6 +386,7 @@ var BaseAstNode = class {
386
386
  superscript;
387
387
  subscript;
388
388
  nodeType;
389
+ sourceLatex;
389
390
  constructor(state = null) {
390
391
  if (state === null) {
391
392
  state = new State();
@@ -394,6 +395,7 @@ var BaseAstNode = class {
394
395
  this.superscript = null;
395
396
  this.subscript = null;
396
397
  this.nodeType = this.constructor.name;
398
+ this.sourceLatex = null;
397
399
  }
398
400
  latex() {
399
401
  throw new Error("NotImplementedError");
@@ -582,6 +584,7 @@ ${this.closing}`;
582
584
  }
583
585
  };
584
586
  function parseScripts(node, json, mode) {
587
+ node.sourceLatex = typeof json.source_latex === "string" && json.source_latex.length > 0 ? json.source_latex : null;
585
588
  if (json.superscript) {
586
589
  node.superscript = parseChain(json.superscript, mode);
587
590
  }
@@ -721,7 +724,8 @@ function fromMathObjectJson(json, mode = "english") {
721
724
  function scriptsToJson(node, path) {
722
725
  return {
723
726
  ...node.superscript ? { superscript: chainToJson(node.superscript, `${path}.superscript`) } : {},
724
- ...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {}
727
+ ...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {},
728
+ ...node.sourceLatex ? { source_latex: node.sourceLatex } : {}
725
729
  };
726
730
  }
727
731
  function nodeToJson(node, path) {
@@ -2190,6 +2194,15 @@ var ATOMIC_OPERATOR_COMMANDS = {
2190
2194
  title: "\u0627\u0644\u0644\u0627\u0646\u0647\u0627\u064A\u0629",
2191
2195
  svg_path: null
2192
2196
  },
2197
+ top: {
2198
+ id: "top",
2199
+ category: "operators1",
2200
+ Tex: "\\top",
2201
+ mirror: false,
2202
+ Label: "\u22A4",
2203
+ title: "\u0627\u0644\u0645\u0646\u0642\u0648\u0644",
2204
+ svg_path: null
2205
+ },
2193
2206
  times: {
2194
2207
  id: "times",
2195
2208
  category: "operators1",
@@ -2927,6 +2940,7 @@ function cloneEditorSession(session) {
2927
2940
  forceSplitNextLeaf: session.forceSplitNextLeaf,
2928
2941
  arabicReverseNumberTyping: session.arabicReverseNumberTyping,
2929
2942
  currentCharacterFont: session.currentCharacterFont ?? "default",
2943
+ currentCharacterWrapper: session.currentCharacterWrapper ?? null,
2930
2944
  currentDigitForm: session.currentDigitForm ?? "western",
2931
2945
  caret: { ...session.caret },
2932
2946
  selection: session.selection ? { ...session.selection } : null,
@@ -2999,6 +3013,7 @@ function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
2999
3013
  forceSplitNextLeaf: false,
3000
3014
  arabicReverseNumberTyping: true,
3001
3015
  currentCharacterFont: "default",
3016
+ currentCharacterWrapper: null,
3002
3017
  currentDigitForm: "western",
3003
3018
  caret: {
3004
3019
  chainId: englishTree.id,
@@ -3235,6 +3250,14 @@ function renderNodeEnglish(node, options) {
3235
3250
  return `${node.expr}${latinScripts(node, options)}`;
3236
3251
  }
3237
3252
  if (node.kind === "char") {
3253
+ if (node.sourceLatex) {
3254
+ return `${node.sourceLatex}${latinScripts(node, options)}`;
3255
+ }
3256
+ if (node.wrapperCommand) {
3257
+ const expr = formatDigits(node.expr, selectedDigitForm(options));
3258
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
3259
+ return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
3260
+ }
3238
3261
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3239
3262
  }
3240
3263
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3288,6 +3311,10 @@ function renderNodeArabic(node, options) {
3288
3311
  if (node.kind === "char") {
3289
3312
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3290
3313
  const content = renderCharContent(node, options);
3314
+ if (node.wrapperCommand) {
3315
+ const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
3316
+ return arabicScripts(node, `${wrapper}{${content}}`, options);
3317
+ }
3291
3318
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
3292
3319
  }
3293
3320
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3886,6 +3913,11 @@ ${BUTEX_FONT_FACE_CSS}
3886
3913
 
3887
3914
  ${CHARACTER_FONT_CSS}
3888
3915
 
3916
+ .node-value--bold {
3917
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
3918
+ font-weight: 700;
3919
+ }
3920
+
3889
3921
  .chain {
3890
3922
  display: inline-flex;
3891
3923
  align-items: center;
@@ -4136,6 +4168,10 @@ var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
4136
4168
  function charEditorNodeToAstNode(node) {
4137
4169
  const font = node.characterFont ?? "default";
4138
4170
  const charNode = new CharNode(node.expr);
4171
+ if (node.wrapperCommand) {
4172
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
4173
+ return new CommandNode(wrapper, [], [new ChainNode([charNode])]);
4174
+ }
4139
4175
  if (font === "default") {
4140
4176
  return charNode;
4141
4177
  }
@@ -4162,6 +4198,9 @@ function cloneChainWithFreshIds(chain) {
4162
4198
  return structuredClone(chain);
4163
4199
  }
4164
4200
  function attachScripts(astNode, editorNode) {
4201
+ if (astNode.sourceLatex) {
4202
+ editorNode.sourceLatex = astNode.sourceLatex;
4203
+ }
4165
4204
  if (astNode.superscript) {
4166
4205
  const sup = chainToEditorChain(astNode.superscript);
4167
4206
  if (!sup.editable) {
@@ -4288,6 +4327,49 @@ function charFromTextLikeCommand(node) {
4288
4327
  const scripts = attachScripts(node, editorNode);
4289
4328
  return scripts ?? { editable: true, node: editorNode };
4290
4329
  }
4330
+ function singleCommandChar(node) {
4331
+ if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
4332
+ return null;
4333
+ }
4334
+ const arg = node.mandatoryArgs[0];
4335
+ if (arg.chain.length !== 1 || !(arg.chain[0] instanceof CharNode)) {
4336
+ return null;
4337
+ }
4338
+ return arg.chain[0];
4339
+ }
4340
+ function wrappedAtomicCommandId(node) {
4341
+ if (node.name !== "\\mathbb" && node.name !== "\\mathrm") {
4342
+ return null;
4343
+ }
4344
+ const child = singleCommandChar(node);
4345
+ if (!child) {
4346
+ return null;
4347
+ }
4348
+ return commandIdForTex(`${node.name}{${child.expr}}`);
4349
+ }
4350
+ function editableWrapperCommand(node) {
4351
+ if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
4352
+ return null;
4353
+ }
4354
+ const child = singleCommandChar(node);
4355
+ if (!child) {
4356
+ return null;
4357
+ }
4358
+ const normalized = normalizeCharImportExpr(child.expr);
4359
+ const editorNode = createEditorNode("char", normalized.expr);
4360
+ if (normalized.characterFont !== "default") {
4361
+ editorNode.characterFont = normalized.characterFont;
4362
+ }
4363
+ editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
4364
+ const scripts = attachScripts(node, editorNode);
4365
+ if (scripts) {
4366
+ return scripts;
4367
+ }
4368
+ if (!editorNode.sourceLatex && node.name === "\\mathsf") {
4369
+ editorNode.sourceLatex = `\\mathsf{${child.expr}}`;
4370
+ }
4371
+ return { editable: true, node: editorNode };
4372
+ }
4291
4373
  function commandToEditorNode(node) {
4292
4374
  if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
4293
4375
  const frac = createFracNode();
@@ -4377,6 +4459,19 @@ function commandToEditorNode(node) {
4377
4459
  }
4378
4460
  return { editable: true, node: accent };
4379
4461
  }
4462
+ const wrappedAtomicId = wrappedAtomicCommandId(node);
4463
+ if (wrappedAtomicId) {
4464
+ const atomic = createEditorNode("atomicCommand", wrappedAtomicId);
4465
+ const scripts = attachScripts(node, atomic);
4466
+ if (scripts) {
4467
+ return scripts;
4468
+ }
4469
+ return { editable: true, node: atomic };
4470
+ }
4471
+ const wrapper = editableWrapperCommand(node);
4472
+ if (wrapper) {
4473
+ return wrapper;
4474
+ }
4380
4475
  const atomicId = commandIdForTex(node.name);
4381
4476
  if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
4382
4477
  const atomic = createEditorNode("atomicCommand", atomicId);
@@ -4656,7 +4751,13 @@ function editorNodeToAstNode(node) {
4656
4751
  if (!tex) {
4657
4752
  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}` };
4658
4753
  }
4659
- astNode = new CommandNode(tex);
4754
+ if (node.expr === "ad") {
4755
+ astNode = new CommandNode("\\mathrm", [], [new ChainNode([new CharNode("d")])]);
4756
+ } else if (["N", "Z", "Q", "R", "C", "H"].includes(node.expr)) {
4757
+ astNode = new CommandNode("\\mathbb", [], [new ChainNode([new CharNode(node.expr)])]);
4758
+ } else {
4759
+ astNode = new CommandNode(tex);
4760
+ }
4660
4761
  } else if (node.kind === "atomicOperatorCommand") {
4661
4762
  const tex = atomicOperatorCommandSpec(node.expr)?.Tex;
4662
4763
  if (!tex) {
@@ -4673,6 +4774,9 @@ function editorNodeToAstNode(node) {
4673
4774
  } else {
4674
4775
  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}` };
4675
4776
  }
4777
+ if (node.sourceLatex) {
4778
+ astNode.sourceLatex = node.sourceLatex;
4779
+ }
4676
4780
  const scripts = attachAstScripts(node, astNode);
4677
4781
  return scripts ?? { ok: true, node: astNode };
4678
4782
  }