@drghaliasri/butex 5.3.3 → 5.4.1

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.
package/dist/document.mjs CHANGED
@@ -705,6 +705,141 @@ function isSupportedDocumentCommand(command) {
705
705
  return TEXT_COMMANDS.has(command) || LIST_COMMANDS.has(command) || command === "\\begin{tabular}" || command === "\\includegraphics" || command === "\\raw";
706
706
  }
707
707
 
708
+ // src/editor/accentCommands.ts
709
+ var ACCENT_COMMANDS = {
710
+ vec: {
711
+ id: "vec",
712
+ englishTex: "\\vec",
713
+ arabicTex: "\\arabvec",
714
+ placement: "over",
715
+ label: "\u20D7",
716
+ title: "\u0633\u0647\u0645 \u0641\u0648\u0642"
717
+ },
718
+ hat: {
719
+ id: "hat",
720
+ englishTex: "\\hat",
721
+ arabicTex: "\\hat",
722
+ placement: "over",
723
+ label: "\u02C6",
724
+ title: "\u0642\u0628\u0639\u0629"
725
+ },
726
+ tilde: {
727
+ id: "tilde",
728
+ englishTex: "\\tilde",
729
+ arabicTex: "\\tilde",
730
+ placement: "over",
731
+ label: "\u02DC",
732
+ title: "\u0645\u062F\u0629"
733
+ },
734
+ dot: {
735
+ id: "dot",
736
+ englishTex: "\\dot",
737
+ arabicTex: "\\dot",
738
+ placement: "over",
739
+ label: "\u02D9",
740
+ title: "\u0646\u0642\u0637\u0629 \u0641\u0648\u0642"
741
+ },
742
+ ddot: {
743
+ id: "ddot",
744
+ englishTex: "\\ddot",
745
+ arabicTex: "\\ddot",
746
+ placement: "over",
747
+ label: "\xA8",
748
+ title: "\u0646\u0642\u0637\u062A\u0627\u0646 \u0641\u0648\u0642"
749
+ },
750
+ dddot: {
751
+ id: "dddot",
752
+ englishTex: "\\dddot",
753
+ arabicTex: "\\dddot",
754
+ placement: "over",
755
+ label: "\u20DB",
756
+ title: "\u062B\u0644\u0627\u062B \u0646\u0642\u0627\u0637 \u0641\u0648\u0642"
757
+ },
758
+ bar: {
759
+ id: "bar",
760
+ englishTex: "\\bar",
761
+ arabicTex: "\\bar",
762
+ placement: "over",
763
+ label: "\xAF",
764
+ title: "\u062E\u0637 \u0641\u0648\u0642"
765
+ },
766
+ check: {
767
+ id: "check",
768
+ englishTex: "\\check",
769
+ arabicTex: "\\check",
770
+ placement: "over",
771
+ label: "\u02C7",
772
+ title: "\u0639\u0644\u0627\u0645\u0629 \u062A\u062D\u0642\u0642"
773
+ },
774
+ breve: {
775
+ id: "breve",
776
+ englishTex: "\\breve",
777
+ arabicTex: "\\breve",
778
+ placement: "over",
779
+ label: "\u02D8",
780
+ title: "\u0642\u0648\u0633 \u0642\u0635\u064A\u0631"
781
+ },
782
+ acute: {
783
+ id: "acute",
784
+ englishTex: "\\acute",
785
+ arabicTex: "\\grave",
786
+ placement: "over",
787
+ label: "\xB4",
788
+ title: "\u0646\u0628\u0631\u0629 \u062D\u0627\u062F\u0629"
789
+ },
790
+ grave: {
791
+ id: "grave",
792
+ englishTex: "\\grave",
793
+ arabicTex: "\\acute",
794
+ placement: "over",
795
+ label: "`",
796
+ title: "\u0646\u0628\u0631\u0629 \u062B\u0642\u064A\u0644\u0629"
797
+ },
798
+ overline: {
799
+ id: "overline",
800
+ englishTex: "\\overline",
801
+ arabicTex: "\\overline",
802
+ placement: "over",
803
+ label: "\u203E",
804
+ title: "\u062E\u0637 \u0639\u0644\u0648\u064A \u0645\u0645\u062A\u062F"
805
+ },
806
+ underline: {
807
+ id: "underline",
808
+ englishTex: "\\underline",
809
+ arabicTex: "\\underline",
810
+ placement: "under",
811
+ label: "_",
812
+ title: "\u062E\u0637 \u0633\u0641\u0644\u064A"
813
+ },
814
+ overleftarrow: {
815
+ id: "overleftarrow",
816
+ englishTex: "\\overleftarrow",
817
+ arabicTex: "\\overrightarrow",
818
+ placement: "over",
819
+ label: "\u2190",
820
+ title: "\u0633\u0647\u0645 \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631"
821
+ },
822
+ overrightarrow: {
823
+ id: "overrightarrow",
824
+ englishTex: "\\overrightarrow",
825
+ arabicTex: "\\overleftarrow",
826
+ placement: "over",
827
+ label: "\u2192",
828
+ title: "\u0633\u0647\u0645 \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646"
829
+ },
830
+ overleftrightarrow: {
831
+ id: "overleftrightarrow",
832
+ englishTex: "\\overleftrightarrow",
833
+ arabicTex: "\\overleftrightarrow",
834
+ placement: "over",
835
+ label: "\u2194",
836
+ title: "\u0633\u0647\u0645 \u0639\u0644\u0648\u064A \u0645\u0632\u062F\u0648\u062C \u0627\u0644\u0627\u062A\u062C\u0627\u0647"
837
+ }
838
+ };
839
+ function accentCommandSpec(id) {
840
+ return Object.prototype.hasOwnProperty.call(ACCENT_COMMANDS, id) ? ACCENT_COMMANDS[id] : null;
841
+ }
842
+
708
843
  // src/editor/atomicCommands.ts
709
844
  var ATOMIC_COMMANDS = {
710
845
  ///////////////////////// Functions ////////////////////////////////
@@ -1665,6 +1800,14 @@ function renderMatrixRowsArabic(node, options) {
1665
1800
  }
1666
1801
  return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
1667
1802
  }
1803
+ function renderAccentArabic(command, accent, base, options) {
1804
+ const baseTex = base ? renderChainArabic(base, options) : "";
1805
+ const accentTex = accent ? renderChainArabic(accent, options) : "";
1806
+ if (accentTex === "") {
1807
+ return baseTex;
1808
+ }
1809
+ return `\\${command}{${accentTex}}{${baseTex}}`;
1810
+ }
1668
1811
  function escapeText(s) {
1669
1812
  return s.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
1670
1813
  }
@@ -1695,6 +1838,19 @@ function renderNodeArabic(node, options) {
1695
1838
  const content = `\\arabsqrt${optionalRootIndexArabic(node, options)}{${renderChainArabic(node.radicand, options)}}`;
1696
1839
  return arabicScripts(node, content, options);
1697
1840
  }
1841
+ if (node.kind === "overset" && node.baseExpr) {
1842
+ const content = renderAccentArabic("overset", node.overExpr, node.baseExpr, options);
1843
+ return arabicScripts(node, content, options);
1844
+ }
1845
+ if (node.kind === "underset" && node.baseExpr) {
1846
+ const content = renderAccentArabic("underset", node.underExpr, node.baseExpr, options);
1847
+ return arabicScripts(node, content, options);
1848
+ }
1849
+ if (node.kind === "accent" && node.baseExpr) {
1850
+ const cmd = accentCommandSpec(node.expr)?.arabicTex ?? `\\${node.expr}`;
1851
+ const content = `${cmd}{${renderChainArabic(node.baseExpr, options)}}`;
1852
+ return arabicScripts(node, content, options);
1853
+ }
1698
1854
  if (node.kind === "env") {
1699
1855
  return arabicScripts(node, renderMatrixRowsArabic(node, options), options);
1700
1856
  }
@@ -1893,6 +2049,109 @@ var SQRT_CSS = `
1893
2049
  }
1894
2050
  `.trim();
1895
2051
 
2052
+ // src/editor/display/overset.ts
2053
+ var OVERSET_CSS = `
2054
+ .overset {
2055
+ display: inline-flex;
2056
+ flex-direction: column;
2057
+ align-items: center;
2058
+ justify-content: center;
2059
+ vertical-align: middle;
2060
+ margin: 0 2px;
2061
+ min-width: 1.2em;
2062
+ }
2063
+
2064
+ .overset-over {
2065
+ display: inline-flex;
2066
+ justify-content: center;
2067
+ align-items: center;
2068
+ min-height: 0.85em;
2069
+ padding: 0 2px;
2070
+ font-size: 0.72em;
2071
+ line-height: 1.1;
2072
+ }
2073
+
2074
+ .overset-base {
2075
+ display: inline-flex;
2076
+ justify-content: center;
2077
+ align-items: center;
2078
+ min-height: 1.05em;
2079
+ padding: 0 2px;
2080
+ }
2081
+ `.trim();
2082
+
2083
+ // src/editor/display/underset.ts
2084
+ var UNDERSET_CSS = `
2085
+ .underset {
2086
+ display: inline-flex;
2087
+ flex-direction: column;
2088
+ align-items: center;
2089
+ justify-content: center;
2090
+ vertical-align: middle;
2091
+ margin: 0 2px;
2092
+ min-width: 1.2em;
2093
+ }
2094
+
2095
+ .underset-base {
2096
+ display: inline-flex;
2097
+ justify-content: center;
2098
+ align-items: center;
2099
+ min-height: 1.05em;
2100
+ padding: 0 2px;
2101
+ }
2102
+
2103
+ .underset-under {
2104
+ display: inline-flex;
2105
+ justify-content: center;
2106
+ align-items: center;
2107
+ min-height: 0.85em;
2108
+ padding: 0 2px;
2109
+ font-size: 0.72em;
2110
+ line-height: 1.1;
2111
+ }
2112
+ `.trim();
2113
+
2114
+ // src/editor/display/accent.ts
2115
+ var ACCENT_CSS = `
2116
+ .math-accent {
2117
+ display: inline-flex;
2118
+ flex-direction: column;
2119
+ align-items: center;
2120
+ justify-content: center;
2121
+ vertical-align: middle;
2122
+ margin: 0 2px;
2123
+ min-width: 1.1em;
2124
+ }
2125
+
2126
+ .math-accent-chrome {
2127
+ display: inline-flex;
2128
+ justify-content: center;
2129
+ align-items: center;
2130
+ min-height: 0.7em;
2131
+ padding: 0 2px;
2132
+ font-size: 0.85em;
2133
+ line-height: 1;
2134
+ color: var(--butex-script-color, #475569);
2135
+ user-select: none;
2136
+ }
2137
+
2138
+ .math-accent-base {
2139
+ display: inline-flex;
2140
+ justify-content: center;
2141
+ align-items: center;
2142
+ min-height: 1.05em;
2143
+ padding: 0 2px;
2144
+ }
2145
+
2146
+ .math-accent--under .math-accent-chrome {
2147
+ min-height: 0.45em;
2148
+ border-top: 1.5px solid currentColor;
2149
+ width: 100%;
2150
+ font-size: 0;
2151
+ color: var(--butex-surface-fg, #0f172a);
2152
+ }
2153
+ `.trim();
2154
+
1896
2155
  // src/editor/display/env.ts
1897
2156
  var MATRIX_ENV_CSS = `
1898
2157
  .matrix-env {
@@ -2280,6 +2539,12 @@ ${FRAC_CSS}
2280
2539
 
2281
2540
  ${SQRT_CSS}
2282
2541
 
2542
+ ${OVERSET_CSS}
2543
+
2544
+ ${UNDERSET_CSS}
2545
+
2546
+ ${ACCENT_CSS}
2547
+
2283
2548
  ${MATRIX_ENV_CSS}
2284
2549
 
2285
2550
  ${ATOMIC_COMMAND_CSS}
@@ -2353,6 +2618,21 @@ function editorEnvToAstNode(node) {
2353
2618
  const scripts = attachAstScripts(node, env);
2354
2619
  return scripts ?? { ok: true, node: env };
2355
2620
  }
2621
+ function accentChainForExport(accent) {
2622
+ if (!accent) {
2623
+ return { ok: true, chain: new ChainNode([]) };
2624
+ }
2625
+ return editorChainToAstChain(accent);
2626
+ }
2627
+ function nodeFromAccentBase(command, accent, base) {
2628
+ if (accent.chain.length > 0) {
2629
+ return new CommandNode(command, [], [accent, base]);
2630
+ }
2631
+ if (base.chain.length === 1) {
2632
+ return base.chain[0];
2633
+ }
2634
+ return new DelimiterNode("", base, "");
2635
+ }
2356
2636
  function editorNodeToAstNode(node) {
2357
2637
  let astNode;
2358
2638
  if (node.kind === "char") {
@@ -2391,6 +2671,36 @@ function editorNodeToAstNode(node) {
2391
2671
  optionalArgs.push(rootIndex.chain);
2392
2672
  }
2393
2673
  astNode = new CommandNode("\\sqrt", optionalArgs, [radicand.chain]);
2674
+ } else if (node.kind === "overset" && node.baseExpr) {
2675
+ const accent = accentChainForExport(node.overExpr);
2676
+ if (!accent.ok) {
2677
+ return accent;
2678
+ }
2679
+ const baseExpr = editorChainToAstChain(node.baseExpr);
2680
+ if (!baseExpr.ok) {
2681
+ return baseExpr;
2682
+ }
2683
+ astNode = nodeFromAccentBase("\\overset", accent.chain, baseExpr.chain);
2684
+ } else if (node.kind === "underset" && node.baseExpr) {
2685
+ const accent = accentChainForExport(node.underExpr);
2686
+ if (!accent.ok) {
2687
+ return accent;
2688
+ }
2689
+ const baseExpr = editorChainToAstChain(node.baseExpr);
2690
+ if (!baseExpr.ok) {
2691
+ return baseExpr;
2692
+ }
2693
+ astNode = nodeFromAccentBase("\\underset", accent.chain, baseExpr.chain);
2694
+ } else if (node.kind === "accent" && node.baseExpr) {
2695
+ const tex = accentCommandSpec(node.expr)?.englishTex;
2696
+ if (!tex) {
2697
+ return { ok: false, reason: `\u0644\u0643\u0646\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
2698
+ }
2699
+ const baseExpr = editorChainToAstChain(node.baseExpr);
2700
+ if (!baseExpr.ok) {
2701
+ return baseExpr;
2702
+ }
2703
+ astNode = new CommandNode(tex, [], [baseExpr.chain]);
2394
2704
  } else if (node.kind === "atomicCommand") {
2395
2705
  const tex = atomicCommandSpec(node.expr)?.englishTex;
2396
2706
  if (!tex) {