@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
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  type EditorSide = 'english' | 'arabic';
6
- type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'frac' | 'sqrt' | 'overset' | 'underset' | 'accent' | 'env' | 'atomicCommand' | 'atomicOperatorCommand';
6
+ type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'frac' | 'sqrt' | 'overset' | 'underset' | 'accent' | 'env' | 'atomicCommand' | 'atomicOperatorCommand' | 'standardCommand';
7
7
  type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
8
8
  type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
9
9
  type EnvColumnAlignment = 'l' | 'c' | 'r';
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  type EditorSide = 'english' | 'arabic';
6
- type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'frac' | 'sqrt' | 'overset' | 'underset' | 'accent' | 'env' | 'atomicCommand' | 'atomicOperatorCommand';
6
+ type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'frac' | 'sqrt' | 'overset' | 'underset' | 'accent' | 'env' | 'atomicCommand' | 'atomicOperatorCommand' | 'standardCommand';
7
7
  type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
8
8
  type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
9
9
  type EnvColumnAlignment = 'l' | 'c' | 'r';
@@ -2832,6 +2832,67 @@ function atomicOperatorCommandSpec(id) {
2832
2832
  return Object.prototype.hasOwnProperty.call(ATOMIC_OPERATOR_COMMANDS, id) ? ATOMIC_OPERATOR_COMMANDS[id] : null;
2833
2833
  }
2834
2834
 
2835
+ // src/editor/standardCommands.ts
2836
+ var STANDARD_COMMANDS = {
2837
+ "\\alpha": { tex: "\\alpha", label: "\u03B1", title: "alpha" },
2838
+ "\\beta": { tex: "\\beta", label: "\u03B2", title: "beta" },
2839
+ "\\gamma": { tex: "\\gamma", label: "\u03B3", title: "gamma" },
2840
+ "\\delta": { tex: "\\delta", label: "\u03B4", title: "delta" },
2841
+ "\\epsilon": { tex: "\\epsilon", label: "\u03B5", title: "epsilon" },
2842
+ "\\eta": { tex: "\\eta", label: "\u03B7", title: "eta" },
2843
+ "\\theta": { tex: "\\theta", label: "\u03B8", title: "theta" },
2844
+ "\\lambda": { tex: "\\lambda", label: "\u03BB", title: "lambda" },
2845
+ "\\mu": { tex: "\\mu", label: "\u03BC", title: "mu" },
2846
+ "\\rho": { tex: "\\rho", label: "\u03C1", title: "rho" },
2847
+ "\\sigma": { tex: "\\sigma", label: "\u03C3", title: "sigma" },
2848
+ "\\tau": { tex: "\\tau", label: "\u03C4", title: "tau" },
2849
+ "\\phi": { tex: "\\phi", label: "\u03C6", title: "phi" },
2850
+ "\\chi": { tex: "\\chi", label: "\u03C7", title: "chi" },
2851
+ "\\psi": { tex: "\\psi", label: "\u03C8", title: "psi" },
2852
+ "\\omega": { tex: "\\omega", label: "\u03C9", title: "omega" },
2853
+ "\\zeta": { tex: "\\zeta", label: "\u03B6", title: "zeta" },
2854
+ "\\nabla": { tex: "\\nabla", label: "\u2207", title: "nabla" },
2855
+ "\\Delta": { tex: "\\Delta", label: "\u0394", title: "Delta" },
2856
+ "\\partial": { tex: "\\partial", label: "\u2202", title: "partial derivative" },
2857
+ "\\Longleftrightarrow": { tex: "\\Longleftrightarrow", label: "\u27FA", title: "long equivalence arrow" },
2858
+ "\\backslash": { tex: "\\backslash", label: "\u2216", title: "reverse solidus" }
2859
+ };
2860
+ function standardCommandSpec(tex) {
2861
+ return Object.prototype.hasOwnProperty.call(STANDARD_COMMANDS, tex) ? STANDARD_COMMANDS[tex] : null;
2862
+ }
2863
+ function isStandardCommandTex(tex) {
2864
+ return standardCommandSpec(tex) !== null;
2865
+ }
2866
+ function chainHasStandardCommands(chain) {
2867
+ for (const node of chain.nodes) {
2868
+ if (node.kind === "standardCommand") {
2869
+ return true;
2870
+ }
2871
+ const childChains = [
2872
+ node.superscript,
2873
+ node.subscript,
2874
+ node.innerExpr,
2875
+ node.numerator,
2876
+ node.denominator,
2877
+ node.radicand,
2878
+ node.rootIndex,
2879
+ node.overExpr,
2880
+ node.underExpr,
2881
+ node.baseExpr
2882
+ ];
2883
+ if (childChains.some((child) => child && chainHasStandardCommands(child))) {
2884
+ return true;
2885
+ }
2886
+ if (node.matrixRows?.some((row) => row.some(chainHasStandardCommands))) {
2887
+ return true;
2888
+ }
2889
+ }
2890
+ return false;
2891
+ }
2892
+ function sessionHasStandardCommands(session) {
2893
+ return chainHasStandardCommands(session.englishTree) || chainHasStandardCommands(session.arabicTree);
2894
+ }
2895
+
2835
2896
  // src/editor/factory.ts
2836
2897
  var nextId2 = 1;
2837
2898
  function makeId(prefix) {
@@ -3251,6 +3312,9 @@ function renderNodeEnglish(node, options) {
3251
3312
  const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
3252
3313
  return `${body}${latinScripts(node, options)}`;
3253
3314
  }
3315
+ if (node.kind === "standardCommand") {
3316
+ return `${node.expr}${latinScripts(node, options)}`;
3317
+ }
3254
3318
  if (node.kind === "char") {
3255
3319
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3256
3320
  }
@@ -3299,6 +3363,9 @@ function renderNodeArabic(node, options) {
3299
3363
  const content = spec?.mirror ? `\\butexmirror{${tex}}` : tex;
3300
3364
  return arabicScripts(node, content, options);
3301
3365
  }
3366
+ if (node.kind === "standardCommand") {
3367
+ return arabicScripts(node, node.expr, options);
3368
+ }
3302
3369
  if (node.kind === "char") {
3303
3370
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3304
3371
  const content = renderCharContent(node, options);
@@ -6755,6 +6822,27 @@ function buildAtomicOperatorCommandNodeBody(node, side, uiLocale = "ar") {
6755
6822
  return value;
6756
6823
  }
6757
6824
 
6825
+ // src/editor/display/standardCommand.ts
6826
+ var STANDARD_COMMAND_CSS = `
6827
+ .standard-command {
6828
+ display: inline-flex;
6829
+ align-items: center;
6830
+ justify-content: center;
6831
+ min-width: 0.9em;
6832
+ font-family: "Cambria Math", "Times New Roman", serif;
6833
+ font-size: 1.05em;
6834
+ line-height: 1;
6835
+ }
6836
+ `.trim();
6837
+ function buildStandardCommandNodeBody(node) {
6838
+ const spec = standardCommandSpec(node.expr);
6839
+ const value = document.createElement("span");
6840
+ value.className = "standard-command";
6841
+ value.title = spec?.title ?? node.expr;
6842
+ value.textContent = spec?.label ?? node.expr;
6843
+ return value;
6844
+ }
6845
+
6758
6846
  // src/editor/display/scripts.ts
6759
6847
  function buildNodeScripts(node, buildChain) {
6760
6848
  const hasScripts = Boolean(node.superscript) || Boolean(node.subscript);
@@ -6814,6 +6902,9 @@ function buildNodeBody(node, buildChain, side, digitForm = "western", uiLocale =
6814
6902
  if (node.kind === "atomicOperatorCommand") {
6815
6903
  return buildAtomicOperatorCommandNodeBody(node, side, uiLocale);
6816
6904
  }
6905
+ if (node.kind === "standardCommand") {
6906
+ return buildStandardCommandNodeBody(node);
6907
+ }
6817
6908
  return buildBaseNodeBody(node, digitForm, side);
6818
6909
  }
6819
6910
 
@@ -7026,6 +7117,8 @@ ${MATRIX_ENV_CSS}
7026
7117
  ${ATOMIC_COMMAND_CSS}
7027
7118
 
7028
7119
  ${ATOMIC_OPERATOR_COMMAND_CSS}
7120
+
7121
+ ${STANDARD_COMMAND_CSS}
7029
7122
  `.trim();
7030
7123
  function injectBuTeXEditorStyles(doc) {
7031
7124
  const d = doc ?? (typeof document !== "undefined" ? document : void 0);
@@ -8302,6 +8395,14 @@ function commandToEditorNode(node) {
8302
8395
  }
8303
8396
  return { editable: true, node: atomicOperator };
8304
8397
  }
8398
+ if (isStandardCommandTex(node.name) && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
8399
+ const standard = createEditorNode("standardCommand", node.name);
8400
+ const scripts = attachScripts(node, standard);
8401
+ if (scripts) {
8402
+ return scripts;
8403
+ }
8404
+ return { editable: true, node: standard };
8405
+ }
8305
8406
  const textLike = charFromTextLikeCommand(node);
8306
8407
  if (textLike) {
8307
8408
  return textLike;
@@ -8562,6 +8663,11 @@ function editorNodeToAstNode(node) {
8562
8663
  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}` };
8563
8664
  }
8564
8665
  astNode = new CommandNode(tex);
8666
+ } else if (node.kind === "standardCommand") {
8667
+ if (!isStandardCommandTex(node.expr)) {
8668
+ 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}` };
8669
+ }
8670
+ astNode = new CommandNode(node.expr);
8565
8671
  } else if (node.kind === "env") {
8566
8672
  return editorEnvToAstNode(node);
8567
8673
  } else {
@@ -17886,6 +17992,9 @@ function keyErrorMessage2(error, messages) {
17886
17992
  }
17887
17993
  return null;
17888
17994
  }
17995
+ function standardCommandWarning(uiLocale) {
17996
+ 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.";
17997
+ }
17889
17998
  function EquationDrawer({
17890
17999
  debug = false,
17891
18000
  session,
@@ -17913,6 +18022,9 @@ function EquationDrawer({
17913
18022
  const dialogRef = (0, import_react13.useRef)(null);
17914
18023
  const titleId = (0, import_react13.useId)();
17915
18024
  const [labelOverride, setLabelOverride] = (0, import_react13.useState)(null);
18025
+ const [hasStandardCommandWarning, setHasStandardCommandWarning] = (0, import_react13.useState)(
18026
+ () => sessionHasStandardCommands(session)
18027
+ );
17916
18028
  const displayedLabel = labelOverride ?? label;
17917
18029
  const labelError = labelEnabled && mathMode === "display" ? document2KeyError(displayedLabel, {
17918
18030
  references,
@@ -17922,6 +18034,10 @@ function EquationDrawer({
17922
18034
  (0, import_react13.useEffect)(() => {
17923
18035
  setLabelOverride(null);
17924
18036
  }, [ownerId, label]);
18037
+ (0, import_react13.useEffect)(() => {
18038
+ latestSession.current = session;
18039
+ setHasStandardCommandWarning(sessionHasStandardCommands(session));
18040
+ }, [session]);
17925
18041
  useDialogFocus({ open: true, dialogRef, onClose });
17926
18042
  (0, import_react13.useEffect)(() => observeVisibleViewport(window, ({ snapshot }) => {
17927
18043
  const modal = modalRef.current;
@@ -18019,6 +18135,7 @@ function EquationDrawer({
18019
18135
  ] }) : null
18020
18136
  ] }) : null,
18021
18137
  reason ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "butex-document2-widget__error", children: uiLocale === "en" ? messages.equationUnavailable : reason }) : null,
18138
+ hasStandardCommandWarning && !reason ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "butex-document2-widget__standard-command-warning", role: "status", children: standardCommandWarning(uiLocale) }) : null,
18022
18139
  /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
18023
18140
  ButexEditor,
18024
18141
  {
@@ -18030,6 +18147,7 @@ function EquationDrawer({
18030
18147
  initialSession: session,
18031
18148
  onSessionChange: (nextSession) => {
18032
18149
  latestSession.current = nextSession;
18150
+ setHasStandardCommandWarning(sessionHasStandardCommands(nextSession));
18033
18151
  }
18034
18152
  }
18035
18153
  )