@drghaliasri/butex 7.1.3 → 7.2.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 (43) hide show
  1. package/dist/document.d.mts +1 -2
  2. package/dist/document.d.ts +1 -2
  3. package/dist/document.js +55 -0
  4. package/dist/document.js.map +1 -1
  5. package/dist/document.mjs +55 -0
  6. package/dist/document.mjs.map +1 -1
  7. package/dist/document2-cli.js +1712 -1
  8. package/dist/document2-cli.js.map +1 -1
  9. package/dist/document2.d.mts +1 -1
  10. package/dist/document2.d.ts +1 -1
  11. package/dist/document2.js +66 -0
  12. package/dist/document2.js.map +1 -1
  13. package/dist/document2.mjs +66 -0
  14. package/dist/document2.mjs.map +1 -1
  15. package/dist/index.d.mts +129 -2
  16. package/dist/index.d.ts +129 -2
  17. package/dist/index.global.js +98 -0
  18. package/dist/index.global.js.map +1 -1
  19. package/dist/index.js +98 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +98 -0
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/react-document.js +77 -0
  24. package/dist/react-document.js.map +1 -1
  25. package/dist/react-document.mjs +77 -0
  26. package/dist/react-document.mjs.map +1 -1
  27. package/dist/react-document2-preview.js +61 -0
  28. package/dist/react-document2-preview.js.map +1 -1
  29. package/dist/react-document2-preview.mjs +61 -0
  30. package/dist/react-document2-preview.mjs.map +1 -1
  31. package/dist/react-document2.d.mts +1 -1
  32. package/dist/react-document2.d.ts +1 -1
  33. package/dist/react-document2.js +118 -0
  34. package/dist/react-document2.js.map +1 -1
  35. package/dist/react-document2.mjs +118 -0
  36. package/dist/react-document2.mjs.map +1 -1
  37. package/dist/react.d.mts +1 -1
  38. package/dist/react.d.ts +1 -1
  39. package/dist/react.js +77 -0
  40. package/dist/react.js.map +1 -1
  41. package/dist/react.mjs +77 -0
  42. package/dist/react.mjs.map +1 -1
  43. package/package.json +1 -1
@@ -2795,6 +2795,67 @@ function atomicOperatorCommandSpec(id) {
2795
2795
  return Object.prototype.hasOwnProperty.call(ATOMIC_OPERATOR_COMMANDS, id) ? ATOMIC_OPERATOR_COMMANDS[id] : null;
2796
2796
  }
2797
2797
 
2798
+ // src/editor/standardCommands.ts
2799
+ var STANDARD_COMMANDS = {
2800
+ "\\alpha": { tex: "\\alpha", label: "\u03B1", title: "alpha" },
2801
+ "\\beta": { tex: "\\beta", label: "\u03B2", title: "beta" },
2802
+ "\\gamma": { tex: "\\gamma", label: "\u03B3", title: "gamma" },
2803
+ "\\delta": { tex: "\\delta", label: "\u03B4", title: "delta" },
2804
+ "\\epsilon": { tex: "\\epsilon", label: "\u03B5", title: "epsilon" },
2805
+ "\\eta": { tex: "\\eta", label: "\u03B7", title: "eta" },
2806
+ "\\theta": { tex: "\\theta", label: "\u03B8", title: "theta" },
2807
+ "\\lambda": { tex: "\\lambda", label: "\u03BB", title: "lambda" },
2808
+ "\\mu": { tex: "\\mu", label: "\u03BC", title: "mu" },
2809
+ "\\rho": { tex: "\\rho", label: "\u03C1", title: "rho" },
2810
+ "\\sigma": { tex: "\\sigma", label: "\u03C3", title: "sigma" },
2811
+ "\\tau": { tex: "\\tau", label: "\u03C4", title: "tau" },
2812
+ "\\phi": { tex: "\\phi", label: "\u03C6", title: "phi" },
2813
+ "\\chi": { tex: "\\chi", label: "\u03C7", title: "chi" },
2814
+ "\\psi": { tex: "\\psi", label: "\u03C8", title: "psi" },
2815
+ "\\omega": { tex: "\\omega", label: "\u03C9", title: "omega" },
2816
+ "\\zeta": { tex: "\\zeta", label: "\u03B6", title: "zeta" },
2817
+ "\\nabla": { tex: "\\nabla", label: "\u2207", title: "nabla" },
2818
+ "\\Delta": { tex: "\\Delta", label: "\u0394", title: "Delta" },
2819
+ "\\partial": { tex: "\\partial", label: "\u2202", title: "partial derivative" },
2820
+ "\\Longleftrightarrow": { tex: "\\Longleftrightarrow", label: "\u27FA", title: "long equivalence arrow" },
2821
+ "\\backslash": { tex: "\\backslash", label: "\u2216", title: "reverse solidus" }
2822
+ };
2823
+ function standardCommandSpec(tex) {
2824
+ return Object.prototype.hasOwnProperty.call(STANDARD_COMMANDS, tex) ? STANDARD_COMMANDS[tex] : null;
2825
+ }
2826
+ function isStandardCommandTex(tex) {
2827
+ return standardCommandSpec(tex) !== null;
2828
+ }
2829
+ function chainHasStandardCommands(chain) {
2830
+ for (const node of chain.nodes) {
2831
+ if (node.kind === "standardCommand") {
2832
+ return true;
2833
+ }
2834
+ const childChains = [
2835
+ node.superscript,
2836
+ node.subscript,
2837
+ node.innerExpr,
2838
+ node.numerator,
2839
+ node.denominator,
2840
+ node.radicand,
2841
+ node.rootIndex,
2842
+ node.overExpr,
2843
+ node.underExpr,
2844
+ node.baseExpr
2845
+ ];
2846
+ if (childChains.some((child) => child && chainHasStandardCommands(child))) {
2847
+ return true;
2848
+ }
2849
+ if (node.matrixRows?.some((row) => row.some(chainHasStandardCommands))) {
2850
+ return true;
2851
+ }
2852
+ }
2853
+ return false;
2854
+ }
2855
+ function sessionHasStandardCommands(session) {
2856
+ return chainHasStandardCommands(session.englishTree) || chainHasStandardCommands(session.arabicTree);
2857
+ }
2858
+
2798
2859
  // src/editor/factory.ts
2799
2860
  var nextId2 = 1;
2800
2861
  function makeId(prefix) {
@@ -3214,6 +3275,9 @@ function renderNodeEnglish(node, options) {
3214
3275
  const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
3215
3276
  return `${body}${latinScripts(node, options)}`;
3216
3277
  }
3278
+ if (node.kind === "standardCommand") {
3279
+ return `${node.expr}${latinScripts(node, options)}`;
3280
+ }
3217
3281
  if (node.kind === "char") {
3218
3282
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3219
3283
  }
@@ -3262,6 +3326,9 @@ function renderNodeArabic(node, options) {
3262
3326
  const content = spec?.mirror ? `\\butexmirror{${tex}}` : tex;
3263
3327
  return arabicScripts(node, content, options);
3264
3328
  }
3329
+ if (node.kind === "standardCommand") {
3330
+ return arabicScripts(node, node.expr, options);
3331
+ }
3265
3332
  if (node.kind === "char") {
3266
3333
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3267
3334
  const content = renderCharContent(node, options);
@@ -6718,6 +6785,27 @@ function buildAtomicOperatorCommandNodeBody(node, side, uiLocale = "ar") {
6718
6785
  return value;
6719
6786
  }
6720
6787
 
6788
+ // src/editor/display/standardCommand.ts
6789
+ var STANDARD_COMMAND_CSS = `
6790
+ .standard-command {
6791
+ display: inline-flex;
6792
+ align-items: center;
6793
+ justify-content: center;
6794
+ min-width: 0.9em;
6795
+ font-family: "Cambria Math", "Times New Roman", serif;
6796
+ font-size: 1.05em;
6797
+ line-height: 1;
6798
+ }
6799
+ `.trim();
6800
+ function buildStandardCommandNodeBody(node) {
6801
+ const spec = standardCommandSpec(node.expr);
6802
+ const value = document.createElement("span");
6803
+ value.className = "standard-command";
6804
+ value.title = spec?.title ?? node.expr;
6805
+ value.textContent = spec?.label ?? node.expr;
6806
+ return value;
6807
+ }
6808
+
6721
6809
  // src/editor/display/scripts.ts
6722
6810
  function buildNodeScripts(node, buildChain) {
6723
6811
  const hasScripts = Boolean(node.superscript) || Boolean(node.subscript);
@@ -6777,6 +6865,9 @@ function buildNodeBody(node, buildChain, side, digitForm = "western", uiLocale =
6777
6865
  if (node.kind === "atomicOperatorCommand") {
6778
6866
  return buildAtomicOperatorCommandNodeBody(node, side, uiLocale);
6779
6867
  }
6868
+ if (node.kind === "standardCommand") {
6869
+ return buildStandardCommandNodeBody(node);
6870
+ }
6780
6871
  return buildBaseNodeBody(node, digitForm, side);
6781
6872
  }
6782
6873
 
@@ -6989,6 +7080,8 @@ ${MATRIX_ENV_CSS}
6989
7080
  ${ATOMIC_COMMAND_CSS}
6990
7081
 
6991
7082
  ${ATOMIC_OPERATOR_COMMAND_CSS}
7083
+
7084
+ ${STANDARD_COMMAND_CSS}
6992
7085
  `.trim();
6993
7086
  function injectBuTeXEditorStyles(doc) {
6994
7087
  const d = doc ?? (typeof document !== "undefined" ? document : void 0);
@@ -8265,6 +8358,14 @@ function commandToEditorNode(node) {
8265
8358
  }
8266
8359
  return { editable: true, node: atomicOperator };
8267
8360
  }
8361
+ if (isStandardCommandTex(node.name) && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
8362
+ const standard = createEditorNode("standardCommand", node.name);
8363
+ const scripts = attachScripts(node, standard);
8364
+ if (scripts) {
8365
+ return scripts;
8366
+ }
8367
+ return { editable: true, node: standard };
8368
+ }
8268
8369
  const textLike = charFromTextLikeCommand(node);
8269
8370
  if (textLike) {
8270
8371
  return textLike;
@@ -8525,6 +8626,11 @@ function editorNodeToAstNode(node) {
8525
8626
  return { ok: false, reason: `\u0631\u0645\u0632 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
8526
8627
  }
8527
8628
  astNode = new CommandNode(tex);
8629
+ } else if (node.kind === "standardCommand") {
8630
+ if (!isStandardCommandTex(node.expr)) {
8631
+ return { ok: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u0642\u064A\u0627\u0633\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
8632
+ }
8633
+ astNode = new CommandNode(node.expr);
8528
8634
  } else if (node.kind === "env") {
8529
8635
  return editorEnvToAstNode(node);
8530
8636
  } else {
@@ -17857,6 +17963,9 @@ function keyErrorMessage2(error, messages) {
17857
17963
  }
17858
17964
  return null;
17859
17965
  }
17966
+ function standardCommandWarning(uiLocale) {
17967
+ return uiLocale === "en" ? "This equation contains standard non-Arabic math commands. Review them and replace them with the Arabic-oriented equivalent where appropriate." : "\u062A\u062D\u062A\u0648\u064A \u0647\u0630\u0647 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u0639\u0644\u0649 \u0631\u0645\u0648\u0632 \u0623\u0648 \u0623\u0648\u0627\u0645\u0631 \u0631\u064A\u0627\u0636\u064A\u0629 \u0642\u064A\u0627\u0633\u064A\u0629 \u063A\u064A\u0631 \u0645\u0639\u0631\u0651\u0628\u0629. \u064A\u064F\u0631\u062C\u0649 \u0645\u0631\u0627\u062C\u0639\u062A\u0647\u0627 \u0648\u0627\u0633\u062A\u0628\u062F\u0627\u0644\u0647\u0627 \u0628\u0627\u0644\u0645\u0642\u0627\u0628\u0644 \u0627\u0644\u0639\u0631\u0628\u064A \u0639\u0646\u062F \u0627\u0644\u062D\u0627\u062C\u0629.";
17968
+ }
17860
17969
  function EquationDrawer({
17861
17970
  debug = false,
17862
17971
  session,
@@ -17884,6 +17993,9 @@ function EquationDrawer({
17884
17993
  const dialogRef = useRef11(null);
17885
17994
  const titleId = useId5();
17886
17995
  const [labelOverride, setLabelOverride] = useState10(null);
17996
+ const [hasStandardCommandWarning, setHasStandardCommandWarning] = useState10(
17997
+ () => sessionHasStandardCommands(session)
17998
+ );
17887
17999
  const displayedLabel = labelOverride ?? label;
17888
18000
  const labelError = labelEnabled && mathMode === "display" ? document2KeyError(displayedLabel, {
17889
18001
  references,
@@ -17893,6 +18005,10 @@ function EquationDrawer({
17893
18005
  useEffect11(() => {
17894
18006
  setLabelOverride(null);
17895
18007
  }, [ownerId, label]);
18008
+ useEffect11(() => {
18009
+ latestSession.current = session;
18010
+ setHasStandardCommandWarning(sessionHasStandardCommands(session));
18011
+ }, [session]);
17896
18012
  useDialogFocus({ open: true, dialogRef, onClose });
17897
18013
  useEffect11(() => observeVisibleViewport(window, ({ snapshot }) => {
17898
18014
  const modal = modalRef.current;
@@ -17990,6 +18106,7 @@ function EquationDrawer({
17990
18106
  ] }) : null
17991
18107
  ] }) : null,
17992
18108
  reason ? /* @__PURE__ */ jsx15("p", { className: "butex-document2-widget__error", children: uiLocale === "en" ? messages.equationUnavailable : reason }) : null,
18109
+ hasStandardCommandWarning && !reason ? /* @__PURE__ */ jsx15("p", { className: "butex-document2-widget__standard-command-warning", role: "status", children: standardCommandWarning(uiLocale) }) : null,
17993
18110
  /* @__PURE__ */ jsx15(
17994
18111
  ButexEditor,
17995
18112
  {
@@ -18001,6 +18118,7 @@ function EquationDrawer({
18001
18118
  initialSession: session,
18002
18119
  onSessionChange: (nextSession) => {
18003
18120
  latestSession.current = nextSession;
18121
+ setHasStandardCommandWarning(sessionHasStandardCommands(nextSession));
18004
18122
  }
18005
18123
  }
18006
18124
  )