@drghaliasri/butex 8.0.1 → 8.0.3
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/README.md +2 -0
- package/dist/document-cli.js +123 -16
- package/dist/document-cli.js.map +1 -1
- package/dist/document.d.mts +5 -5
- package/dist/document.d.ts +5 -5
- package/dist/document.js +65 -22
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +65 -22
- package/dist/document.mjs.map +1 -1
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.global.js +54 -9
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +54 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -9
- package/dist/index.mjs.map +1 -1
- package/dist/react-document-preview.js +44 -15
- package/dist/react-document-preview.js.map +1 -1
- package/dist/react-document-preview.mjs +44 -15
- package/dist/react-document-preview.mjs.map +1 -1
- package/dist/react-document.d.mts +3 -3
- package/dist/react-document.d.ts +3 -3
- package/dist/react-document.js +136 -46
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +136 -46
- package/dist/react-document.mjs.map +1 -1
- package/dist/react.d.mts +4 -3
- package/dist/react.d.ts +4 -3
- package/dist/react.js +123 -37
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +123 -37
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1651,6 +1651,11 @@ var MATRIX_ENV_CSS = `
|
|
|
1651
1651
|
transform-origin: center;
|
|
1652
1652
|
}
|
|
1653
1653
|
|
|
1654
|
+
.matrix-env--cases .matrix-env__wrapper:empty {
|
|
1655
|
+
min-width: 0;
|
|
1656
|
+
padding: 0;
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1654
1659
|
.matrix-env__grid {
|
|
1655
1660
|
display: inline-grid;
|
|
1656
1661
|
direction: ltr;
|
|
@@ -1695,9 +1700,10 @@ function applyMatrixDelimiterScale(wrap, grid) {
|
|
|
1695
1700
|
}
|
|
1696
1701
|
function buildMatrixEnvNodeBody(node, buildChain, side) {
|
|
1697
1702
|
const wrap = document.createElement("span");
|
|
1698
|
-
wrap.className = `matrix-env matrix-env--${side}`;
|
|
1703
|
+
wrap.className = `matrix-env matrix-env--${side}${node.envName === "cases" ? " matrix-env--cases" : ""}`;
|
|
1704
|
+
if (node.envName === "cases") wrap.dir = "ltr";
|
|
1699
1705
|
const style = node.envName ?? node.matrixStyle ?? "matrix";
|
|
1700
|
-
const glyphs = style === "array" || style === "aligned" ? void 0 : WRAPPERS[style];
|
|
1706
|
+
const glyphs = style === "cases" ? side === "arabic" ? { left: "", right: "}" } : { left: "{", right: "" } : style === "array" || style === "aligned" ? void 0 : WRAPPERS[style];
|
|
1701
1707
|
const left = document.createElement("span");
|
|
1702
1708
|
left.className = "matrix-env__wrapper matrix-env__wrapper--left";
|
|
1703
1709
|
left.textContent = glyphs?.left ?? "";
|
|
@@ -1854,6 +1860,7 @@ var EQUATION_EDITOR_MESSAGES = {
|
|
|
1854
1860
|
matrix: "\u0645\u0635\u0641\u0648\u0641\u0629",
|
|
1855
1861
|
array: "\u062C\u062F\u0648\u0644",
|
|
1856
1862
|
aligned: "\u0645\u062D\u0627\u0630\u0627\u0629",
|
|
1863
|
+
piecewise: "\u062F\u0627\u0644\u0629 \u0645\u062A\u0639\u062F\u062F\u0629 \u0627\u0644\u062A\u0639\u0631\u064A\u0641",
|
|
1857
1864
|
matrixType: "\u0646\u0648\u0639 \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629",
|
|
1858
1865
|
chooseEnvironmentSize: "\u0627\u062E\u062A\u064A\u0627\u0631 \u062D\u062C\u0645 \u0627\u0644\u0628\u064A\u0626\u0629",
|
|
1859
1866
|
rows: "\u0635\u0641\u0648\u0641",
|
|
@@ -1981,6 +1988,7 @@ var EQUATION_EDITOR_MESSAGES = {
|
|
|
1981
1988
|
matrix: "Matrix",
|
|
1982
1989
|
array: "Array",
|
|
1983
1990
|
aligned: "Aligned",
|
|
1991
|
+
piecewise: "Piecewise (cases)",
|
|
1984
1992
|
matrixType: "Matrix type",
|
|
1985
1993
|
chooseEnvironmentSize: "Choose environment size",
|
|
1986
1994
|
rows: "Rows",
|
|
@@ -3301,6 +3309,7 @@ __export(editor_exports, {
|
|
|
3301
3309
|
insertArrayEnv: () => insertArrayEnv,
|
|
3302
3310
|
insertAtomicCommand: () => insertAtomicCommand,
|
|
3303
3311
|
insertAtomicOperatorCommand: () => insertAtomicOperatorCommand,
|
|
3312
|
+
insertCasesEnv: () => insertCasesEnv,
|
|
3304
3313
|
insertChar: () => insertChar,
|
|
3305
3314
|
insertDelimiterPair: () => insertDelimiterPair,
|
|
3306
3315
|
insertDivideOperator: () => insertDivideOperator,
|
|
@@ -3333,6 +3342,7 @@ __export(editor_exports, {
|
|
|
3333
3342
|
removeSub: () => removeSub,
|
|
3334
3343
|
removeSup: () => removeSup,
|
|
3335
3344
|
renderArabicLatexFromSession: () => renderArabicLatexFromSession,
|
|
3345
|
+
renderArabicPreviewLatexFromSession: () => renderArabicPreviewLatexFromSession,
|
|
3336
3346
|
renderChainArabic: () => renderChainArabic,
|
|
3337
3347
|
renderChainEnglish: () => renderChainEnglish,
|
|
3338
3348
|
renderEnglishLatexFromSession: () => renderEnglishLatexFromSession,
|
|
@@ -3453,7 +3463,7 @@ function createMatrixEnvNode(style, rows, columns) {
|
|
|
3453
3463
|
}
|
|
3454
3464
|
function createGridEnvNode(envName, rows, columns, columnAlignments) {
|
|
3455
3465
|
const safeRows = Math.max(1, Math.min(12, Math.trunc(rows)));
|
|
3456
|
-
const safeColumns = Math.max(1, Math.min(12, Math.trunc(columns)));
|
|
3466
|
+
const safeColumns = envName === "cases" ? 2 : Math.max(1, Math.min(12, Math.trunc(columns)));
|
|
3457
3467
|
const matrixStyles = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
|
|
3458
3468
|
const isMatrix = matrixStyles.has(envName) && envName !== "array" && envName !== "aligned";
|
|
3459
3469
|
return {
|
|
@@ -3738,6 +3748,9 @@ function renderMatrixRowsArabic(node, options) {
|
|
|
3738
3748
|
const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).reverse().map(reverseAlignmentForArabic).join("");
|
|
3739
3749
|
return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
|
|
3740
3750
|
}
|
|
3751
|
+
if (envName === "cases" && options?.casesPresentation) {
|
|
3752
|
+
return `\\left.\\begin{array}{rl}${rows.join(" \\\\\n")}\\end{array}\\right\\}`;
|
|
3753
|
+
}
|
|
3741
3754
|
return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
|
|
3742
3755
|
}
|
|
3743
3756
|
function renderAccentEnglish(command, accent, base, options) {
|
|
@@ -3759,6 +3772,10 @@ function renderAccentArabic(command, accent, base, options) {
|
|
|
3759
3772
|
function escapeText(s) {
|
|
3760
3773
|
return s.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
|
|
3761
3774
|
}
|
|
3775
|
+
function escapeAtomicLiteral(text) {
|
|
3776
|
+
const unescaped = text.replace(/\\([%_&#{}$])/g, "$1");
|
|
3777
|
+
return escapeText(unescaped).replace(/[%_&#$]/g, "\\$&");
|
|
3778
|
+
}
|
|
3762
3779
|
function renderCharContent(node, options) {
|
|
3763
3780
|
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3764
3781
|
const font = node.characterFont ?? "default";
|
|
@@ -3805,7 +3822,7 @@ function renderNodeEnglish(node, options) {
|
|
|
3805
3822
|
return `${body}${latinScripts(node, options)}`;
|
|
3806
3823
|
}
|
|
3807
3824
|
if (node.kind === "atomicOperatorCommand") {
|
|
3808
|
-
const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
3825
|
+
const body = node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
3809
3826
|
return `${body}${latinScripts(node, options)}`;
|
|
3810
3827
|
}
|
|
3811
3828
|
if (node.kind === "standardCommand") {
|
|
@@ -3822,7 +3839,8 @@ function renderNodeEnglish(node, options) {
|
|
|
3822
3839
|
if (node.wrapperCommand) {
|
|
3823
3840
|
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3824
3841
|
const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
|
|
3825
|
-
|
|
3842
|
+
const escaped = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : escapeText(expr);
|
|
3843
|
+
return `${wrapper}{${escaped}}${latinScripts(node, options)}`;
|
|
3826
3844
|
}
|
|
3827
3845
|
return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
|
|
3828
3846
|
}
|
|
@@ -3883,7 +3901,8 @@ function renderNodeArabic(node, options) {
|
|
|
3883
3901
|
const content = renderCharContent(node, options);
|
|
3884
3902
|
if (node.wrapperCommand) {
|
|
3885
3903
|
const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
|
|
3886
|
-
|
|
3904
|
+
const literal = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : content;
|
|
3905
|
+
return arabicScripts(node, `${wrapper}{${literal}}`, options);
|
|
3887
3906
|
}
|
|
3888
3907
|
return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
|
|
3889
3908
|
}
|
|
@@ -3912,6 +3931,9 @@ function renderEnglishLatexFromSession(session) {
|
|
|
3912
3931
|
function renderArabicLatexFromSession(session) {
|
|
3913
3932
|
return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
3914
3933
|
}
|
|
3934
|
+
function renderArabicPreviewLatexFromSession(session) {
|
|
3935
|
+
return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western", casesPresentation: true });
|
|
3936
|
+
}
|
|
3915
3937
|
|
|
3916
3938
|
// src/editor/caretOrder.ts
|
|
3917
3939
|
function collectCaretPositions(chain) {
|
|
@@ -4742,6 +4764,9 @@ function markExprSync(session, nodeId) {
|
|
|
4742
4764
|
function clearSourceIdentity(session, nodeId) {
|
|
4743
4765
|
const english = findNodeById(session.englishTree, nodeId);
|
|
4744
4766
|
const arabic = findNodeById(session.arabicTree, nodeId);
|
|
4767
|
+
if (session.activeSide === "arabic" && english?.node.kind === "char" && ["\\mathtt", "\\operatorname", "\\text"].includes(english.node.wrapperCommand ?? "") && english.node.sourceLatex) {
|
|
4768
|
+
return;
|
|
4769
|
+
}
|
|
4745
4770
|
if (english) {
|
|
4746
4771
|
delete english.node.sourceLatex;
|
|
4747
4772
|
}
|
|
@@ -5742,6 +5767,9 @@ function insertArrayEnv(session, rows, columns, columnAlignments) {
|
|
|
5742
5767
|
function insertAlignedEnv(session, rows, columns) {
|
|
5743
5768
|
return insertGridEnv(session, "aligned", rows, columns);
|
|
5744
5769
|
}
|
|
5770
|
+
function insertCasesEnv(session, rows) {
|
|
5771
|
+
return insertGridEnv(session, "cases", rows, 2);
|
|
5772
|
+
}
|
|
5745
5773
|
function insertGridEnv(session, envName, rows, columns, columnAlignments) {
|
|
5746
5774
|
const base = replaceSelectionFirst(session);
|
|
5747
5775
|
const next = cloneEditorSession(base);
|
|
@@ -5762,7 +5790,7 @@ function insertGridEnv(session, envName, rows, columns, columnAlignments) {
|
|
|
5762
5790
|
function setMatrixEnvStyle(session, style) {
|
|
5763
5791
|
const next = cloneEditorSession(session);
|
|
5764
5792
|
const pair = findSelectedMatrixPair(next);
|
|
5765
|
-
if (!pair) {
|
|
5793
|
+
if (!pair || pair.english.envName === "cases") {
|
|
5766
5794
|
return session;
|
|
5767
5795
|
}
|
|
5768
5796
|
pair.english.envName = style;
|
|
@@ -5826,7 +5854,7 @@ function removeMatrixRow(session) {
|
|
|
5826
5854
|
function addMatrixColumn(session) {
|
|
5827
5855
|
const next = cloneEditorSession(session);
|
|
5828
5856
|
const pair = findSelectedMatrixPair(next);
|
|
5829
|
-
if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows) {
|
|
5857
|
+
if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows || pair.english.envName === "cases") {
|
|
5830
5858
|
return session;
|
|
5831
5859
|
}
|
|
5832
5860
|
const columnCount = pair.english.matrixRows[0]?.length ?? 0;
|
|
@@ -5848,7 +5876,7 @@ function addMatrixColumn(session) {
|
|
|
5848
5876
|
function removeMatrixColumn(session) {
|
|
5849
5877
|
const next = cloneEditorSession(session);
|
|
5850
5878
|
const pair = findSelectedMatrixPair(next);
|
|
5851
|
-
if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows) {
|
|
5879
|
+
if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows || pair.english.envName === "cases") {
|
|
5852
5880
|
return session;
|
|
5853
5881
|
}
|
|
5854
5882
|
const columnCount = pair.english.matrixRows[0]?.length ?? 0;
|
|
@@ -6075,6 +6103,9 @@ function setExpr(session, nodeId, expr) {
|
|
|
6075
6103
|
return session;
|
|
6076
6104
|
}
|
|
6077
6105
|
activeNode.node.expr = expr;
|
|
6106
|
+
if (["\\mathtt", "\\operatorname", "\\text"].includes(activeNode.node.wrapperCommand ?? "")) {
|
|
6107
|
+
passiveNode.node.expr = expr;
|
|
6108
|
+
}
|
|
6078
6109
|
clearSourceIdentity(next, nodeId);
|
|
6079
6110
|
markExprSync(next, nodeId);
|
|
6080
6111
|
appendDebug(next, "setExpr", nodeId);
|
|
@@ -6175,6 +6206,14 @@ function pasteText(session, text) {
|
|
|
6175
6206
|
if (!text) {
|
|
6176
6207
|
return session;
|
|
6177
6208
|
}
|
|
6209
|
+
const selection = session.selection;
|
|
6210
|
+
if (selection && Math.abs(selection.anchorIndex - selection.focusIndex) === 1) {
|
|
6211
|
+
const selectedChain = findChainById(session[activeTreeKey(session.activeSide)], selection.chainId);
|
|
6212
|
+
const selected = selectedChain?.chain.nodes[Math.min(selection.anchorIndex, selection.focusIndex)];
|
|
6213
|
+
if (selected?.kind === "char" && ["\\mathtt", "\\operatorname", "\\text"].includes(selected.wrapperCommand ?? "")) {
|
|
6214
|
+
return setExpr(session, selected.id, text);
|
|
6215
|
+
}
|
|
6216
|
+
}
|
|
6178
6217
|
let s = session;
|
|
6179
6218
|
let i = 0;
|
|
6180
6219
|
while (i < text.length) {
|
|
@@ -6234,6 +6273,8 @@ function buildBaseNodeBody(node, digitForm = "western", side = "english") {
|
|
|
6234
6273
|
if (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") {
|
|
6235
6274
|
value.classList.add("node-value--bold");
|
|
6236
6275
|
}
|
|
6276
|
+
if (node.wrapperCommand === "\\text") value.dir = "auto";
|
|
6277
|
+
if (node.wrapperCommand === "\\operatorname") value.classList.add("node-value--operator-name");
|
|
6237
6278
|
if (node.wrapperCommand === "\\unit") {
|
|
6238
6279
|
value.classList.add("node-value--unit");
|
|
6239
6280
|
value.title = "\u0648\u062D\u062F\u0629 (unit)";
|
|
@@ -7162,6 +7203,10 @@ function createEditorRuntime(options) {
|
|
|
7162
7203
|
applyStructural((prev) => insertAlignedEnv(prev, rows, columns));
|
|
7163
7204
|
focusInput();
|
|
7164
7205
|
},
|
|
7206
|
+
insertCasesEnv: (rows) => {
|
|
7207
|
+
applyStructural((prev) => insertCasesEnv(prev, rows));
|
|
7208
|
+
focusInput();
|
|
7209
|
+
},
|
|
7165
7210
|
insertSqrt: () => {
|
|
7166
7211
|
applyStructural((prev) => insertSqrt(prev));
|
|
7167
7212
|
focusInput();
|