@drghaliasri/butex 7.1.4 → 7.2.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.d.mts +1 -2
- package/dist/document.d.ts +1 -2
- package/dist/document.js +56 -0
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +56 -0
- package/dist/document.mjs.map +1 -1
- package/dist/document2-cli.js +298 -4
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +1 -1
- package/dist/document2.d.ts +1 -1
- package/dist/document2.js +67 -0
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +67 -0
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +129 -2
- package/dist/index.d.ts +129 -2
- package/dist/index.global.js +99 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +78 -0
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +78 -0
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2-preview.js +62 -0
- package/dist/react-document2-preview.js.map +1 -1
- package/dist/react-document2-preview.mjs +62 -0
- package/dist/react-document2-preview.mjs.map +1 -1
- package/dist/react-document2.d.mts +1 -1
- package/dist/react-document2.d.ts +1 -1
- package/dist/react-document2.js +119 -0
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +119 -0
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +78 -0
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +78 -0
- package/dist/react.mjs.map +1 -1
- 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';
|
package/dist/react-document2.js
CHANGED
|
@@ -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) {
|
|
@@ -3083,6 +3144,7 @@ var CHARACTER_FONT_SPECS = [
|
|
|
3083
3144
|
latexFontCommand: "\\maghribi",
|
|
3084
3145
|
latexFontFamily: "Almaghribi Warsh Quran",
|
|
3085
3146
|
browserFontStack: '"Almaghribi Warsh Quran", Amiri, "Segoe UI", Tahoma, sans-serif',
|
|
3147
|
+
importAliases: ["\\maghribi"],
|
|
3086
3148
|
svgLayoutKey: "maghribi"
|
|
3087
3149
|
}
|
|
3088
3150
|
];
|
|
@@ -3251,6 +3313,9 @@ function renderNodeEnglish(node, options) {
|
|
|
3251
3313
|
const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
3252
3314
|
return `${body}${latinScripts(node, options)}`;
|
|
3253
3315
|
}
|
|
3316
|
+
if (node.kind === "standardCommand") {
|
|
3317
|
+
return `${node.expr}${latinScripts(node, options)}`;
|
|
3318
|
+
}
|
|
3254
3319
|
if (node.kind === "char") {
|
|
3255
3320
|
return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
|
|
3256
3321
|
}
|
|
@@ -3299,6 +3364,9 @@ function renderNodeArabic(node, options) {
|
|
|
3299
3364
|
const content = spec?.mirror ? `\\butexmirror{${tex}}` : tex;
|
|
3300
3365
|
return arabicScripts(node, content, options);
|
|
3301
3366
|
}
|
|
3367
|
+
if (node.kind === "standardCommand") {
|
|
3368
|
+
return arabicScripts(node, node.expr, options);
|
|
3369
|
+
}
|
|
3302
3370
|
if (node.kind === "char") {
|
|
3303
3371
|
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3304
3372
|
const content = renderCharContent(node, options);
|
|
@@ -6755,6 +6823,27 @@ function buildAtomicOperatorCommandNodeBody(node, side, uiLocale = "ar") {
|
|
|
6755
6823
|
return value;
|
|
6756
6824
|
}
|
|
6757
6825
|
|
|
6826
|
+
// src/editor/display/standardCommand.ts
|
|
6827
|
+
var STANDARD_COMMAND_CSS = `
|
|
6828
|
+
.standard-command {
|
|
6829
|
+
display: inline-flex;
|
|
6830
|
+
align-items: center;
|
|
6831
|
+
justify-content: center;
|
|
6832
|
+
min-width: 0.9em;
|
|
6833
|
+
font-family: "Cambria Math", "Times New Roman", serif;
|
|
6834
|
+
font-size: 1.05em;
|
|
6835
|
+
line-height: 1;
|
|
6836
|
+
}
|
|
6837
|
+
`.trim();
|
|
6838
|
+
function buildStandardCommandNodeBody(node) {
|
|
6839
|
+
const spec = standardCommandSpec(node.expr);
|
|
6840
|
+
const value = document.createElement("span");
|
|
6841
|
+
value.className = "standard-command";
|
|
6842
|
+
value.title = spec?.title ?? node.expr;
|
|
6843
|
+
value.textContent = spec?.label ?? node.expr;
|
|
6844
|
+
return value;
|
|
6845
|
+
}
|
|
6846
|
+
|
|
6758
6847
|
// src/editor/display/scripts.ts
|
|
6759
6848
|
function buildNodeScripts(node, buildChain) {
|
|
6760
6849
|
const hasScripts = Boolean(node.superscript) || Boolean(node.subscript);
|
|
@@ -6814,6 +6903,9 @@ function buildNodeBody(node, buildChain, side, digitForm = "western", uiLocale =
|
|
|
6814
6903
|
if (node.kind === "atomicOperatorCommand") {
|
|
6815
6904
|
return buildAtomicOperatorCommandNodeBody(node, side, uiLocale);
|
|
6816
6905
|
}
|
|
6906
|
+
if (node.kind === "standardCommand") {
|
|
6907
|
+
return buildStandardCommandNodeBody(node);
|
|
6908
|
+
}
|
|
6817
6909
|
return buildBaseNodeBody(node, digitForm, side);
|
|
6818
6910
|
}
|
|
6819
6911
|
|
|
@@ -7026,6 +7118,8 @@ ${MATRIX_ENV_CSS}
|
|
|
7026
7118
|
${ATOMIC_COMMAND_CSS}
|
|
7027
7119
|
|
|
7028
7120
|
${ATOMIC_OPERATOR_COMMAND_CSS}
|
|
7121
|
+
|
|
7122
|
+
${STANDARD_COMMAND_CSS}
|
|
7029
7123
|
`.trim();
|
|
7030
7124
|
function injectBuTeXEditorStyles(doc) {
|
|
7031
7125
|
const d = doc ?? (typeof document !== "undefined" ? document : void 0);
|
|
@@ -8302,6 +8396,14 @@ function commandToEditorNode(node) {
|
|
|
8302
8396
|
}
|
|
8303
8397
|
return { editable: true, node: atomicOperator };
|
|
8304
8398
|
}
|
|
8399
|
+
if (isStandardCommandTex(node.name) && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
8400
|
+
const standard = createEditorNode("standardCommand", node.name);
|
|
8401
|
+
const scripts = attachScripts(node, standard);
|
|
8402
|
+
if (scripts) {
|
|
8403
|
+
return scripts;
|
|
8404
|
+
}
|
|
8405
|
+
return { editable: true, node: standard };
|
|
8406
|
+
}
|
|
8305
8407
|
const textLike = charFromTextLikeCommand(node);
|
|
8306
8408
|
if (textLike) {
|
|
8307
8409
|
return textLike;
|
|
@@ -8562,6 +8664,11 @@ function editorNodeToAstNode(node) {
|
|
|
8562
8664
|
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
8665
|
}
|
|
8564
8666
|
astNode = new CommandNode(tex);
|
|
8667
|
+
} else if (node.kind === "standardCommand") {
|
|
8668
|
+
if (!isStandardCommandTex(node.expr)) {
|
|
8669
|
+
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}` };
|
|
8670
|
+
}
|
|
8671
|
+
astNode = new CommandNode(node.expr);
|
|
8565
8672
|
} else if (node.kind === "env") {
|
|
8566
8673
|
return editorEnvToAstNode(node);
|
|
8567
8674
|
} else {
|
|
@@ -17886,6 +17993,9 @@ function keyErrorMessage2(error, messages) {
|
|
|
17886
17993
|
}
|
|
17887
17994
|
return null;
|
|
17888
17995
|
}
|
|
17996
|
+
function standardCommandWarning(uiLocale) {
|
|
17997
|
+
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.";
|
|
17998
|
+
}
|
|
17889
17999
|
function EquationDrawer({
|
|
17890
18000
|
debug = false,
|
|
17891
18001
|
session,
|
|
@@ -17913,6 +18023,9 @@ function EquationDrawer({
|
|
|
17913
18023
|
const dialogRef = (0, import_react13.useRef)(null);
|
|
17914
18024
|
const titleId = (0, import_react13.useId)();
|
|
17915
18025
|
const [labelOverride, setLabelOverride] = (0, import_react13.useState)(null);
|
|
18026
|
+
const [hasStandardCommandWarning, setHasStandardCommandWarning] = (0, import_react13.useState)(
|
|
18027
|
+
() => sessionHasStandardCommands(session)
|
|
18028
|
+
);
|
|
17916
18029
|
const displayedLabel = labelOverride ?? label;
|
|
17917
18030
|
const labelError = labelEnabled && mathMode === "display" ? document2KeyError(displayedLabel, {
|
|
17918
18031
|
references,
|
|
@@ -17922,6 +18035,10 @@ function EquationDrawer({
|
|
|
17922
18035
|
(0, import_react13.useEffect)(() => {
|
|
17923
18036
|
setLabelOverride(null);
|
|
17924
18037
|
}, [ownerId, label]);
|
|
18038
|
+
(0, import_react13.useEffect)(() => {
|
|
18039
|
+
latestSession.current = session;
|
|
18040
|
+
setHasStandardCommandWarning(sessionHasStandardCommands(session));
|
|
18041
|
+
}, [session]);
|
|
17925
18042
|
useDialogFocus({ open: true, dialogRef, onClose });
|
|
17926
18043
|
(0, import_react13.useEffect)(() => observeVisibleViewport(window, ({ snapshot }) => {
|
|
17927
18044
|
const modal = modalRef.current;
|
|
@@ -18019,6 +18136,7 @@ function EquationDrawer({
|
|
|
18019
18136
|
] }) : null
|
|
18020
18137
|
] }) : null,
|
|
18021
18138
|
reason ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "butex-document2-widget__error", children: uiLocale === "en" ? messages.equationUnavailable : reason }) : null,
|
|
18139
|
+
hasStandardCommandWarning && !reason ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "butex-document2-widget__standard-command-warning", role: "status", children: standardCommandWarning(uiLocale) }) : null,
|
|
18022
18140
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
18023
18141
|
ButexEditor,
|
|
18024
18142
|
{
|
|
@@ -18030,6 +18148,7 @@ function EquationDrawer({
|
|
|
18030
18148
|
initialSession: session,
|
|
18031
18149
|
onSessionChange: (nextSession) => {
|
|
18032
18150
|
latestSession.current = nextSession;
|
|
18151
|
+
setHasStandardCommandWarning(sessionHasStandardCommands(nextSession));
|
|
18033
18152
|
}
|
|
18034
18153
|
}
|
|
18035
18154
|
)
|