@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
@@ -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,
@@ -3068,6 +3083,7 @@ var CHARACTER_FONT_SPECS = [
3068
3083
  latexFontCommand: "\\maghribi",
3069
3084
  latexFontFamily: "Almaghribi Warsh Quran",
3070
3085
  browserFontStack: '"Almaghribi Warsh Quran", Amiri, "Segoe UI", Tahoma, sans-serif',
3086
+ importAliases: ["\\maghribi"],
3071
3087
  svgLayoutKey: "maghribi"
3072
3088
  }
3073
3089
  ];
@@ -3234,6 +3250,14 @@ function renderNodeEnglish(node, options) {
3234
3250
  return `${node.expr}${latinScripts(node, options)}`;
3235
3251
  }
3236
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
+ }
3237
3261
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3238
3262
  }
3239
3263
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3287,6 +3311,10 @@ function renderNodeArabic(node, options) {
3287
3311
  if (node.kind === "char") {
3288
3312
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3289
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
+ }
3290
3318
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
3291
3319
  }
3292
3320
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3885,6 +3913,11 @@ ${BUTEX_FONT_FACE_CSS}
3885
3913
 
3886
3914
  ${CHARACTER_FONT_CSS}
3887
3915
 
3916
+ .node-value--bold {
3917
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
3918
+ font-weight: 700;
3919
+ }
3920
+
3888
3921
  .chain {
3889
3922
  display: inline-flex;
3890
3923
  align-items: center;
@@ -4135,6 +4168,10 @@ var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
4135
4168
  function charEditorNodeToAstNode(node) {
4136
4169
  const font = node.characterFont ?? "default";
4137
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
+ }
4138
4175
  if (font === "default") {
4139
4176
  return charNode;
4140
4177
  }
@@ -4161,6 +4198,9 @@ function cloneChainWithFreshIds(chain) {
4161
4198
  return structuredClone(chain);
4162
4199
  }
4163
4200
  function attachScripts(astNode, editorNode) {
4201
+ if (astNode.sourceLatex) {
4202
+ editorNode.sourceLatex = astNode.sourceLatex;
4203
+ }
4164
4204
  if (astNode.superscript) {
4165
4205
  const sup = chainToEditorChain(astNode.superscript);
4166
4206
  if (!sup.editable) {
@@ -4287,6 +4327,49 @@ function charFromTextLikeCommand(node) {
4287
4327
  const scripts = attachScripts(node, editorNode);
4288
4328
  return scripts ?? { editable: true, node: editorNode };
4289
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
+ }
4290
4373
  function commandToEditorNode(node) {
4291
4374
  if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
4292
4375
  const frac = createFracNode();
@@ -4376,6 +4459,19 @@ function commandToEditorNode(node) {
4376
4459
  }
4377
4460
  return { editable: true, node: accent };
4378
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
+ }
4379
4475
  const atomicId = commandIdForTex(node.name);
4380
4476
  if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
4381
4477
  const atomic = createEditorNode("atomicCommand", atomicId);
@@ -4655,7 +4751,13 @@ function editorNodeToAstNode(node) {
4655
4751
  if (!tex) {
4656
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}` };
4657
4753
  }
4658
- 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
+ }
4659
4761
  } else if (node.kind === "atomicOperatorCommand") {
4660
4762
  const tex = atomicOperatorCommandSpec(node.expr)?.Tex;
4661
4763
  if (!tex) {
@@ -4672,6 +4774,9 @@ function editorNodeToAstNode(node) {
4672
4774
  } else {
4673
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}` };
4674
4776
  }
4777
+ if (node.sourceLatex) {
4778
+ astNode.sourceLatex = node.sourceLatex;
4779
+ }
4675
4780
  const scripts = attachAstScripts(node, astNode);
4676
4781
  return scripts ?? { ok: true, node: astNode };
4677
4782
  }