@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
package/dist/index.mjs CHANGED
@@ -161,6 +161,18 @@ mjx-container[jax="CHTML"] .butex-preview-mirror {
161
161
  font-family: ${BUTEX_DIWANI_OUTLINE_FONT_STACK} !important;
162
162
  }
163
163
 
164
+ .butex-bold-text {
165
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
166
+ font-weight: 700;
167
+ direction: rtl;
168
+ unicode-bidi: isolate;
169
+ }
170
+
171
+ .butex-bold-text mjx-utext {
172
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif !important;
173
+ font-weight: 700;
174
+ }
175
+
164
176
  .butex-takween-text {
165
177
  font-family: ${BUTEX_TAKWEEN_FONT_STACK};
166
178
  direction: rtl;
@@ -778,6 +790,7 @@ var CHARACTER_FONT_SPECS = [
778
790
  latexFontCommand: "\\maghribi",
779
791
  latexFontFamily: "Almaghribi Warsh Quran",
780
792
  browserFontStack: '"Almaghribi Warsh Quran", Amiri, "Segoe UI", Tahoma, sans-serif',
793
+ importAliases: ["\\maghribi"],
781
794
  svgLayoutKey: "maghribi"
782
795
  }
783
796
  ];
@@ -807,12 +820,15 @@ function fontText(className, parser, name) {
807
820
  parser.Push(node);
808
821
  }
809
822
  function registerFontTextCommands(CommandMap) {
810
- const mappings = Object.fromEntries(
811
- NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.mathJaxClass).map((font) => [
812
- font.macro.replace(/^\\/, ""),
813
- ((parser, name) => fontText(font.mathJaxClass, parser, name))
814
- ])
815
- );
823
+ const mappings = {
824
+ boldarabic: ((parser, name) => fontText("butex-bold-text", parser, name)),
825
+ ...Object.fromEntries(
826
+ NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.mathJaxClass).map((font) => [
827
+ font.macro.replace(/^\\/, ""),
828
+ ((parser, name) => fontText(font.mathJaxClass, parser, name))
829
+ ])
830
+ )
831
+ };
816
832
  new CommandMap(COMMAND_MAP5, mappings);
817
833
  return COMMAND_MAP5;
818
834
  }
@@ -2110,6 +2126,15 @@ var ATOMIC_OPERATOR_COMMANDS = {
2110
2126
  title: "\u0627\u0644\u0644\u0627\u0646\u0647\u0627\u064A\u0629",
2111
2127
  svg_path: null
2112
2128
  },
2129
+ top: {
2130
+ id: "top",
2131
+ category: "operators1",
2132
+ Tex: "\\top",
2133
+ mirror: false,
2134
+ Label: "\u22A4",
2135
+ title: "\u0627\u0644\u0645\u0646\u0642\u0648\u0644",
2136
+ svg_path: null
2137
+ },
2113
2138
  times: {
2114
2139
  id: "times",
2115
2140
  category: "operators1",
@@ -2898,6 +2923,11 @@ ${BUTEX_FONT_FACE_CSS}
2898
2923
 
2899
2924
  ${CHARACTER_FONT_CSS}
2900
2925
 
2926
+ .node-value--bold {
2927
+ font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
2928
+ font-weight: 700;
2929
+ }
2930
+
2901
2931
  .chain {
2902
2932
  display: inline-flex;
2903
2933
  align-items: center;
@@ -3212,6 +3242,7 @@ __export(editor_exports, {
3212
3242
  setArabicReverseNumberTyping: () => setArabicReverseNumberTyping,
3213
3243
  setArrayColumnAlignment: () => setArrayColumnAlignment,
3214
3244
  setCaret: () => setCaret,
3245
+ setCurrentBoldCharacterStyle: () => setCurrentBoldCharacterStyle,
3215
3246
  setCurrentCharacterFont: () => setCurrentCharacterFont,
3216
3247
  setCurrentDigitForm: () => setCurrentDigitForm,
3217
3248
  setExpr: () => setExpr,
@@ -3342,6 +3373,7 @@ function cloneEditorSession(session) {
3342
3373
  forceSplitNextLeaf: session.forceSplitNextLeaf,
3343
3374
  arabicReverseNumberTyping: session.arabicReverseNumberTyping,
3344
3375
  currentCharacterFont: session.currentCharacterFont ?? "default",
3376
+ currentCharacterWrapper: session.currentCharacterWrapper ?? null,
3345
3377
  currentDigitForm: session.currentDigitForm ?? "western",
3346
3378
  caret: { ...session.caret },
3347
3379
  selection: session.selection ? { ...session.selection } : null,
@@ -3414,6 +3446,7 @@ function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
3414
3446
  forceSplitNextLeaf: false,
3415
3447
  arabicReverseNumberTyping: true,
3416
3448
  currentCharacterFont: "default",
3449
+ currentCharacterWrapper: null,
3417
3450
  currentDigitForm: "western",
3418
3451
  caret: {
3419
3452
  chainId: englishTree.id,
@@ -3616,6 +3649,14 @@ function renderNodeEnglish(node, options) {
3616
3649
  return `${node.expr}${latinScripts(node, options)}`;
3617
3650
  }
3618
3651
  if (node.kind === "char") {
3652
+ if (node.sourceLatex) {
3653
+ return `${node.sourceLatex}${latinScripts(node, options)}`;
3654
+ }
3655
+ if (node.wrapperCommand) {
3656
+ const expr = formatDigits(node.expr, selectedDigitForm(options));
3657
+ const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
3658
+ return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
3659
+ }
3619
3660
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3620
3661
  }
3621
3662
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -3669,6 +3710,10 @@ function renderNodeArabic(node, options) {
3669
3710
  if (node.kind === "char") {
3670
3711
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3671
3712
  const content = renderCharContent(node, options);
3713
+ if (node.wrapperCommand) {
3714
+ const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
3715
+ return arabicScripts(node, `${wrapper}{${content}}`, options);
3716
+ }
3672
3717
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
3673
3718
  }
3674
3719
  if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
@@ -4515,6 +4560,16 @@ function markExprSync(session, nodeId) {
4515
4560
  }
4516
4561
  session.sync[nodeId].expr = english.node.expr === arabic.node.expr ? "synced" : "diverged";
4517
4562
  }
4563
+ function clearSourceIdentity(session, nodeId) {
4564
+ const english = findNodeById(session.englishTree, nodeId);
4565
+ const arabic = findNodeById(session.arabicTree, nodeId);
4566
+ if (english) {
4567
+ delete english.node.sourceLatex;
4568
+ }
4569
+ if (arabic) {
4570
+ delete arabic.node.sourceLatex;
4571
+ }
4572
+ }
4518
4573
  function syncSelectionToCaret(session) {
4519
4574
  const activeKey = activeTreeKey(session.activeSide);
4520
4575
  const tree = session[activeKey];
@@ -5098,7 +5153,10 @@ function insertLeaf(session, kind, expr) {
5098
5153
  const next = cloneEditorSession(session);
5099
5154
  const englishNode = createEditorNode(kind, expr);
5100
5155
  const arabicNode = createEditorNode(kind, expr);
5101
- if (kind === "char" && (next.currentCharacterFont ?? "default") !== "default") {
5156
+ if (kind === "char" && next.currentCharacterWrapper === "\\boldarabic") {
5157
+ englishNode.wrapperCommand = "\\boldarabic";
5158
+ arabicNode.wrapperCommand = "\\boldarabic";
5159
+ } else if (kind === "char" && (next.currentCharacterFont ?? "default") !== "default") {
5102
5160
  englishNode.characterFont = next.currentCharacterFont;
5103
5161
  arabicNode.characterFont = next.currentCharacterFont;
5104
5162
  }
@@ -5113,8 +5171,12 @@ function insertLeaf(session, kind, expr) {
5113
5171
  function shouldReverseArabicNumber(session) {
5114
5172
  return session.activeSide === "arabic" && session.arabicReverseNumberTyping;
5115
5173
  }
5116
- function characterFontOf(node) {
5117
- return node.kind === "char" ? node.characterFont ?? "default" : "default";
5174
+ function characterTypingStyleOf(node) {
5175
+ if (node.kind !== "char") return "none";
5176
+ return node.wrapperCommand ? `wrapper:${node.wrapperCommand}` : `font:${node.characterFont ?? "default"}`;
5177
+ }
5178
+ function currentCharacterTypingStyle(session) {
5179
+ return session.currentCharacterWrapper ? `wrapper:${session.currentCharacterWrapper}` : `font:${session.currentCharacterFont ?? "default"}`;
5118
5180
  }
5119
5181
  function tryMergeLeafTyping(session, kind, fragment) {
5120
5182
  const engLocated = findChainById(session.englishTree, session.caret.chainId);
@@ -5127,14 +5189,14 @@ function tryMergeLeafTyping(session, kind, fragment) {
5127
5189
  let prepend = false;
5128
5190
  if (i > 0) {
5129
5191
  const prev = nodes[i - 1];
5130
- if (prev.kind === kind && (kind !== "char" || characterFontOf(prev) === (session.currentCharacterFont ?? "default"))) {
5192
+ if (prev.kind === kind && (kind !== "char" || characterTypingStyleOf(prev) === currentCharacterTypingStyle(session))) {
5131
5193
  targetId = prev.id;
5132
5194
  prepend = false;
5133
5195
  }
5134
5196
  }
5135
5197
  if (!targetId && i < nodes.length) {
5136
5198
  const fwd = nodes[i];
5137
- if (fwd.kind === kind && (kind !== "char" || characterFontOf(fwd) === (session.currentCharacterFont ?? "default"))) {
5199
+ if (fwd.kind === kind && (kind !== "char" || characterTypingStyleOf(fwd) === currentCharacterTypingStyle(session))) {
5138
5200
  targetId = fwd.id;
5139
5201
  prepend = true;
5140
5202
  }
@@ -5155,6 +5217,7 @@ function tryMergeLeafTyping(session, kind, fragment) {
5155
5217
  englishHit.node.expr = `${englishHit.node.expr}${fragment}`;
5156
5218
  arabicHit.node.expr = `${arabicHit.node.expr}${fragment}`;
5157
5219
  }
5220
+ clearSourceIdentity(session, targetId);
5158
5221
  markExprSync(session, targetId);
5159
5222
  return true;
5160
5223
  }
@@ -5193,9 +5256,17 @@ function breakLeafTyping(session) {
5193
5256
  function setCurrentCharacterFont(session, fontId) {
5194
5257
  const next = cloneEditorSession(session);
5195
5258
  next.currentCharacterFont = fontId;
5259
+ next.currentCharacterWrapper = null;
5196
5260
  appendDebug(next, "setCurrentCharacterFont", fontId);
5197
5261
  return next;
5198
5262
  }
5263
+ function setCurrentBoldCharacterStyle(session) {
5264
+ const next = cloneEditorSession(session);
5265
+ next.currentCharacterFont = "default";
5266
+ next.currentCharacterWrapper = "\\boldarabic";
5267
+ appendDebug(next, "setCurrentBoldCharacterStyle", "\\boldarabic");
5268
+ return next;
5269
+ }
5199
5270
  function toggleTakweenCharacterFont(session) {
5200
5271
  return setCurrentCharacterFont(session, (session.currentCharacterFont ?? "default") === "takween" ? "default" : "takween");
5201
5272
  }
@@ -5744,6 +5815,7 @@ function deleteBackward(session) {
5744
5815
  englishHit.node.expr = englishHit.node.expr.slice(0, -1);
5745
5816
  arabicHit.node.expr = arabicHit.node.expr.slice(0, -1);
5746
5817
  }
5818
+ clearSourceIdentity(next, id);
5747
5819
  markExprSync(next, id);
5748
5820
  next.selectedStructureNodeId = null;
5749
5821
  syncSelectionToCaret(next);
@@ -5793,6 +5865,7 @@ function deleteForward(session) {
5793
5865
  englishHit.node.expr = englishHit.node.expr.slice(1);
5794
5866
  arabicHit.node.expr = arabicHit.node.expr.slice(1);
5795
5867
  }
5868
+ clearSourceIdentity(next, node.id);
5796
5869
  markExprSync(next, node.id);
5797
5870
  next.selectedStructureNodeId = null;
5798
5871
  syncSelectionToCaret(next);
@@ -5819,6 +5892,7 @@ function setExpr(session, nodeId, expr) {
5819
5892
  return session;
5820
5893
  }
5821
5894
  activeNode.node.expr = expr;
5895
+ clearSourceIdentity(next, nodeId);
5822
5896
  markExprSync(next, nodeId);
5823
5897
  appendDebug(next, "setExpr", nodeId);
5824
5898
  return next;
@@ -5836,6 +5910,7 @@ function createStarterSession() {
5836
5910
  forceSplitNextLeaf: false,
5837
5911
  arabicReverseNumberTyping: true,
5838
5912
  currentCharacterFont: "default",
5913
+ currentCharacterWrapper: null,
5839
5914
  currentDigitForm: "western",
5840
5915
  caret: {
5841
5916
  chainId: englishRoot.id,
@@ -5973,6 +6048,9 @@ function buildBaseNodeBody(node, digitForm = "western", side = "english") {
5973
6048
  if (cssClass) {
5974
6049
  value.classList.add(cssClass);
5975
6050
  }
6051
+ if (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") {
6052
+ value.classList.add("node-value--bold");
6053
+ }
5976
6054
  }
5977
6055
  const surfaceExpr = node.kind === "operator" ? divideOperatorSurfaceExpr(node.expr, side) : node.expr;
5978
6056
  value.textContent = surfaceExpr === "" ? "\u25A1" : formatDigits(surfaceExpr, digitForm);
@@ -6848,6 +6926,10 @@ function createEditorRuntime(options) {
6848
6926
  applyTransient((prev) => setCurrentCharacterFont(prev, fontId));
6849
6927
  focusInput();
6850
6928
  },
6929
+ setCurrentBoldCharacterStyle: () => {
6930
+ applyTransient((prev) => setCurrentBoldCharacterStyle(prev));
6931
+ focusInput();
6932
+ },
6851
6933
  setCurrentDigitForm: (digitForm) => {
6852
6934
  applyStructural((prev) => setCurrentDigitForm(prev, digitForm));
6853
6935
  focusInput();
@@ -7570,6 +7652,15 @@ var SVG_TEXT_ATTR = "data-butex-svg-text";
7570
7652
  var SVG_FONT_ATTR = "data-butex-svg-font";
7571
7653
  var EM = 1e3;
7572
7654
  var FALLBACK_CHAR_WIDTH = 0.72;
7655
+ var BOLD_LAYOUT = {
7656
+ key: "bold",
7657
+ stack: 'Amiri, "Noto Serif Arabic", serif',
7658
+ height: 0.75,
7659
+ depth: 0.25,
7660
+ drawScale: 1,
7661
+ baselineShift: 0,
7662
+ fontWeight: 700
7663
+ };
7573
7664
  var FONT_LAYOUTS = Object.fromEntries(
7574
7665
  NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.svgLayoutKey && font.browserFontStack).map((font) => {
7575
7666
  const key = font.svgLayoutKey;
@@ -7590,6 +7681,9 @@ var FONT_LAYOUTS = Object.fromEntries(
7590
7681
  );
7591
7682
  function fontLayoutForClass(className) {
7592
7683
  const classes = className.split(/\s+/);
7684
+ if (classes.includes("butex-bold-text")) {
7685
+ return BOLD_LAYOUT;
7686
+ }
7593
7687
  for (const font of NON_DEFAULT_CHARACTER_FONT_SPECS) {
7594
7688
  if (font.mathJaxClass && font.svgLayoutKey && classes.includes(font.mathJaxClass)) {
7595
7689
  return FONT_LAYOUTS[font.svgLayoutKey] ?? null;
@@ -7642,12 +7736,14 @@ function measureAdvance(wrapper, text, fontStack) {
7642
7736
  y: 0,
7643
7737
  "font-family": fontStack,
7644
7738
  "font-size": EM,
7739
+ "font-weight": fontStack === BOLD_LAYOUT.stack ? BOLD_LAYOUT.fontWeight : void 0,
7645
7740
  "text-anchor": "end",
7646
7741
  direction: "rtl",
7647
7742
  "unicode-bidi": "isolate",
7648
7743
  "dominant-baseline": "alphabetic",
7649
7744
  style: {
7650
7745
  "font-family": fontStack,
7746
+ "font-weight": fontStack === BOLD_LAYOUT.stack ? BOLD_LAYOUT.fontWeight : void 0,
7651
7747
  direction: "rtl",
7652
7748
  "unicode-bidi": "isolate"
7653
7749
  }
@@ -7747,6 +7843,7 @@ function createBuTeXSvgMtextClass(OriginalMtext) {
7747
7843
  transform: `scale(${formatSvgNumber(font.drawScale)},${formatSvgNumber(-font.drawScale)})`,
7748
7844
  "font-family": font.stack,
7749
7845
  "font-size": EM,
7846
+ "font-weight": font.fontWeight,
7750
7847
  "text-anchor": "end",
7751
7848
  direction: "rtl",
7752
7849
  "unicode-bidi": "isolate",
@@ -7755,6 +7852,7 @@ function createBuTeXSvgMtextClass(OriginalMtext) {
7755
7852
  [SVG_FONT_ATTR]: font.key,
7756
7853
  style: {
7757
7854
  "font-family": font.stack,
7855
+ "font-weight": font.fontWeight,
7758
7856
  direction: "rtl",
7759
7857
  "unicode-bidi": "isolate"
7760
7858
  }