@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.mjs
CHANGED
|
@@ -1609,6 +1609,11 @@ var MATRIX_ENV_CSS = `
|
|
|
1609
1609
|
transform-origin: center;
|
|
1610
1610
|
}
|
|
1611
1611
|
|
|
1612
|
+
.matrix-env--cases .matrix-env__wrapper:empty {
|
|
1613
|
+
min-width: 0;
|
|
1614
|
+
padding: 0;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1612
1617
|
.matrix-env__grid {
|
|
1613
1618
|
display: inline-grid;
|
|
1614
1619
|
direction: ltr;
|
|
@@ -1653,9 +1658,10 @@ function applyMatrixDelimiterScale(wrap, grid) {
|
|
|
1653
1658
|
}
|
|
1654
1659
|
function buildMatrixEnvNodeBody(node, buildChain, side) {
|
|
1655
1660
|
const wrap = document.createElement("span");
|
|
1656
|
-
wrap.className = `matrix-env matrix-env--${side}`;
|
|
1661
|
+
wrap.className = `matrix-env matrix-env--${side}${node.envName === "cases" ? " matrix-env--cases" : ""}`;
|
|
1662
|
+
if (node.envName === "cases") wrap.dir = "ltr";
|
|
1657
1663
|
const style = node.envName ?? node.matrixStyle ?? "matrix";
|
|
1658
|
-
const glyphs = style === "array" || style === "aligned" ? void 0 : WRAPPERS[style];
|
|
1664
|
+
const glyphs = style === "cases" ? side === "arabic" ? { left: "", right: "}" } : { left: "{", right: "" } : style === "array" || style === "aligned" ? void 0 : WRAPPERS[style];
|
|
1659
1665
|
const left = document.createElement("span");
|
|
1660
1666
|
left.className = "matrix-env__wrapper matrix-env__wrapper--left";
|
|
1661
1667
|
left.textContent = glyphs?.left ?? "";
|
|
@@ -1812,6 +1818,7 @@ var EQUATION_EDITOR_MESSAGES = {
|
|
|
1812
1818
|
matrix: "\u0645\u0635\u0641\u0648\u0641\u0629",
|
|
1813
1819
|
array: "\u062C\u062F\u0648\u0644",
|
|
1814
1820
|
aligned: "\u0645\u062D\u0627\u0630\u0627\u0629",
|
|
1821
|
+
piecewise: "\u062F\u0627\u0644\u0629 \u0645\u062A\u0639\u062F\u062F\u0629 \u0627\u0644\u062A\u0639\u0631\u064A\u0641",
|
|
1815
1822
|
matrixType: "\u0646\u0648\u0639 \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629",
|
|
1816
1823
|
chooseEnvironmentSize: "\u0627\u062E\u062A\u064A\u0627\u0631 \u062D\u062C\u0645 \u0627\u0644\u0628\u064A\u0626\u0629",
|
|
1817
1824
|
rows: "\u0635\u0641\u0648\u0641",
|
|
@@ -1939,6 +1946,7 @@ var EQUATION_EDITOR_MESSAGES = {
|
|
|
1939
1946
|
matrix: "Matrix",
|
|
1940
1947
|
array: "Array",
|
|
1941
1948
|
aligned: "Aligned",
|
|
1949
|
+
piecewise: "Piecewise (cases)",
|
|
1942
1950
|
matrixType: "Matrix type",
|
|
1943
1951
|
chooseEnvironmentSize: "Choose environment size",
|
|
1944
1952
|
rows: "Rows",
|
|
@@ -3259,6 +3267,7 @@ __export(editor_exports, {
|
|
|
3259
3267
|
insertArrayEnv: () => insertArrayEnv,
|
|
3260
3268
|
insertAtomicCommand: () => insertAtomicCommand,
|
|
3261
3269
|
insertAtomicOperatorCommand: () => insertAtomicOperatorCommand,
|
|
3270
|
+
insertCasesEnv: () => insertCasesEnv,
|
|
3262
3271
|
insertChar: () => insertChar,
|
|
3263
3272
|
insertDelimiterPair: () => insertDelimiterPair,
|
|
3264
3273
|
insertDivideOperator: () => insertDivideOperator,
|
|
@@ -3291,6 +3300,7 @@ __export(editor_exports, {
|
|
|
3291
3300
|
removeSub: () => removeSub,
|
|
3292
3301
|
removeSup: () => removeSup,
|
|
3293
3302
|
renderArabicLatexFromSession: () => renderArabicLatexFromSession,
|
|
3303
|
+
renderArabicPreviewLatexFromSession: () => renderArabicPreviewLatexFromSession,
|
|
3294
3304
|
renderChainArabic: () => renderChainArabic,
|
|
3295
3305
|
renderChainEnglish: () => renderChainEnglish,
|
|
3296
3306
|
renderEnglishLatexFromSession: () => renderEnglishLatexFromSession,
|
|
@@ -3411,7 +3421,7 @@ function createMatrixEnvNode(style, rows, columns) {
|
|
|
3411
3421
|
}
|
|
3412
3422
|
function createGridEnvNode(envName, rows, columns, columnAlignments) {
|
|
3413
3423
|
const safeRows = Math.max(1, Math.min(12, Math.trunc(rows)));
|
|
3414
|
-
const safeColumns = Math.max(1, Math.min(12, Math.trunc(columns)));
|
|
3424
|
+
const safeColumns = envName === "cases" ? 2 : Math.max(1, Math.min(12, Math.trunc(columns)));
|
|
3415
3425
|
const matrixStyles = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
|
|
3416
3426
|
const isMatrix = matrixStyles.has(envName) && envName !== "array" && envName !== "aligned";
|
|
3417
3427
|
return {
|
|
@@ -3696,6 +3706,9 @@ function renderMatrixRowsArabic(node, options) {
|
|
|
3696
3706
|
const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).reverse().map(reverseAlignmentForArabic).join("");
|
|
3697
3707
|
return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
|
|
3698
3708
|
}
|
|
3709
|
+
if (envName === "cases" && options?.casesPresentation) {
|
|
3710
|
+
return `\\left.\\begin{array}{rl}${rows.join(" \\\\\n")}\\end{array}\\right\\}`;
|
|
3711
|
+
}
|
|
3699
3712
|
return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
|
|
3700
3713
|
}
|
|
3701
3714
|
function renderAccentEnglish(command, accent, base, options) {
|
|
@@ -3717,6 +3730,10 @@ function renderAccentArabic(command, accent, base, options) {
|
|
|
3717
3730
|
function escapeText(s) {
|
|
3718
3731
|
return s.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
|
|
3719
3732
|
}
|
|
3733
|
+
function escapeAtomicLiteral(text) {
|
|
3734
|
+
const unescaped = text.replace(/\\([%_&#{}$])/g, "$1");
|
|
3735
|
+
return escapeText(unescaped).replace(/[%_&#$]/g, "\\$&");
|
|
3736
|
+
}
|
|
3720
3737
|
function renderCharContent(node, options) {
|
|
3721
3738
|
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3722
3739
|
const font = node.characterFont ?? "default";
|
|
@@ -3763,7 +3780,7 @@ function renderNodeEnglish(node, options) {
|
|
|
3763
3780
|
return `${body}${latinScripts(node, options)}`;
|
|
3764
3781
|
}
|
|
3765
3782
|
if (node.kind === "atomicOperatorCommand") {
|
|
3766
|
-
const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
3783
|
+
const body = node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
3767
3784
|
return `${body}${latinScripts(node, options)}`;
|
|
3768
3785
|
}
|
|
3769
3786
|
if (node.kind === "standardCommand") {
|
|
@@ -3780,7 +3797,8 @@ function renderNodeEnglish(node, options) {
|
|
|
3780
3797
|
if (node.wrapperCommand) {
|
|
3781
3798
|
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3782
3799
|
const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
|
|
3783
|
-
|
|
3800
|
+
const escaped = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : escapeText(expr);
|
|
3801
|
+
return `${wrapper}{${escaped}}${latinScripts(node, options)}`;
|
|
3784
3802
|
}
|
|
3785
3803
|
return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
|
|
3786
3804
|
}
|
|
@@ -3841,7 +3859,8 @@ function renderNodeArabic(node, options) {
|
|
|
3841
3859
|
const content = renderCharContent(node, options);
|
|
3842
3860
|
if (node.wrapperCommand) {
|
|
3843
3861
|
const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
|
|
3844
|
-
|
|
3862
|
+
const literal = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : content;
|
|
3863
|
+
return arabicScripts(node, `${wrapper}{${literal}}`, options);
|
|
3845
3864
|
}
|
|
3846
3865
|
return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
|
|
3847
3866
|
}
|
|
@@ -3870,6 +3889,9 @@ function renderEnglishLatexFromSession(session) {
|
|
|
3870
3889
|
function renderArabicLatexFromSession(session) {
|
|
3871
3890
|
return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
3872
3891
|
}
|
|
3892
|
+
function renderArabicPreviewLatexFromSession(session) {
|
|
3893
|
+
return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western", casesPresentation: true });
|
|
3894
|
+
}
|
|
3873
3895
|
|
|
3874
3896
|
// src/editor/caretOrder.ts
|
|
3875
3897
|
function collectCaretPositions(chain) {
|
|
@@ -4700,6 +4722,9 @@ function markExprSync(session, nodeId) {
|
|
|
4700
4722
|
function clearSourceIdentity(session, nodeId) {
|
|
4701
4723
|
const english = findNodeById(session.englishTree, nodeId);
|
|
4702
4724
|
const arabic = findNodeById(session.arabicTree, nodeId);
|
|
4725
|
+
if (session.activeSide === "arabic" && english?.node.kind === "char" && ["\\mathtt", "\\operatorname", "\\text"].includes(english.node.wrapperCommand ?? "") && english.node.sourceLatex) {
|
|
4726
|
+
return;
|
|
4727
|
+
}
|
|
4703
4728
|
if (english) {
|
|
4704
4729
|
delete english.node.sourceLatex;
|
|
4705
4730
|
}
|
|
@@ -5700,6 +5725,9 @@ function insertArrayEnv(session, rows, columns, columnAlignments) {
|
|
|
5700
5725
|
function insertAlignedEnv(session, rows, columns) {
|
|
5701
5726
|
return insertGridEnv(session, "aligned", rows, columns);
|
|
5702
5727
|
}
|
|
5728
|
+
function insertCasesEnv(session, rows) {
|
|
5729
|
+
return insertGridEnv(session, "cases", rows, 2);
|
|
5730
|
+
}
|
|
5703
5731
|
function insertGridEnv(session, envName, rows, columns, columnAlignments) {
|
|
5704
5732
|
const base = replaceSelectionFirst(session);
|
|
5705
5733
|
const next = cloneEditorSession(base);
|
|
@@ -5720,7 +5748,7 @@ function insertGridEnv(session, envName, rows, columns, columnAlignments) {
|
|
|
5720
5748
|
function setMatrixEnvStyle(session, style) {
|
|
5721
5749
|
const next = cloneEditorSession(session);
|
|
5722
5750
|
const pair = findSelectedMatrixPair(next);
|
|
5723
|
-
if (!pair) {
|
|
5751
|
+
if (!pair || pair.english.envName === "cases") {
|
|
5724
5752
|
return session;
|
|
5725
5753
|
}
|
|
5726
5754
|
pair.english.envName = style;
|
|
@@ -5784,7 +5812,7 @@ function removeMatrixRow(session) {
|
|
|
5784
5812
|
function addMatrixColumn(session) {
|
|
5785
5813
|
const next = cloneEditorSession(session);
|
|
5786
5814
|
const pair = findSelectedMatrixPair(next);
|
|
5787
|
-
if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows) {
|
|
5815
|
+
if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows || pair.english.envName === "cases") {
|
|
5788
5816
|
return session;
|
|
5789
5817
|
}
|
|
5790
5818
|
const columnCount = pair.english.matrixRows[0]?.length ?? 0;
|
|
@@ -5806,7 +5834,7 @@ function addMatrixColumn(session) {
|
|
|
5806
5834
|
function removeMatrixColumn(session) {
|
|
5807
5835
|
const next = cloneEditorSession(session);
|
|
5808
5836
|
const pair = findSelectedMatrixPair(next);
|
|
5809
|
-
if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows) {
|
|
5837
|
+
if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows || pair.english.envName === "cases") {
|
|
5810
5838
|
return session;
|
|
5811
5839
|
}
|
|
5812
5840
|
const columnCount = pair.english.matrixRows[0]?.length ?? 0;
|
|
@@ -6033,6 +6061,9 @@ function setExpr(session, nodeId, expr) {
|
|
|
6033
6061
|
return session;
|
|
6034
6062
|
}
|
|
6035
6063
|
activeNode.node.expr = expr;
|
|
6064
|
+
if (["\\mathtt", "\\operatorname", "\\text"].includes(activeNode.node.wrapperCommand ?? "")) {
|
|
6065
|
+
passiveNode.node.expr = expr;
|
|
6066
|
+
}
|
|
6036
6067
|
clearSourceIdentity(next, nodeId);
|
|
6037
6068
|
markExprSync(next, nodeId);
|
|
6038
6069
|
appendDebug(next, "setExpr", nodeId);
|
|
@@ -6133,6 +6164,14 @@ function pasteText(session, text) {
|
|
|
6133
6164
|
if (!text) {
|
|
6134
6165
|
return session;
|
|
6135
6166
|
}
|
|
6167
|
+
const selection = session.selection;
|
|
6168
|
+
if (selection && Math.abs(selection.anchorIndex - selection.focusIndex) === 1) {
|
|
6169
|
+
const selectedChain = findChainById(session[activeTreeKey(session.activeSide)], selection.chainId);
|
|
6170
|
+
const selected = selectedChain?.chain.nodes[Math.min(selection.anchorIndex, selection.focusIndex)];
|
|
6171
|
+
if (selected?.kind === "char" && ["\\mathtt", "\\operatorname", "\\text"].includes(selected.wrapperCommand ?? "")) {
|
|
6172
|
+
return setExpr(session, selected.id, text);
|
|
6173
|
+
}
|
|
6174
|
+
}
|
|
6136
6175
|
let s = session;
|
|
6137
6176
|
let i = 0;
|
|
6138
6177
|
while (i < text.length) {
|
|
@@ -6192,6 +6231,8 @@ function buildBaseNodeBody(node, digitForm = "western", side = "english") {
|
|
|
6192
6231
|
if (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") {
|
|
6193
6232
|
value.classList.add("node-value--bold");
|
|
6194
6233
|
}
|
|
6234
|
+
if (node.wrapperCommand === "\\text") value.dir = "auto";
|
|
6235
|
+
if (node.wrapperCommand === "\\operatorname") value.classList.add("node-value--operator-name");
|
|
6195
6236
|
if (node.wrapperCommand === "\\unit") {
|
|
6196
6237
|
value.classList.add("node-value--unit");
|
|
6197
6238
|
value.title = "\u0648\u062D\u062F\u0629 (unit)";
|
|
@@ -7120,6 +7161,10 @@ function createEditorRuntime(options) {
|
|
|
7120
7161
|
applyStructural((prev) => insertAlignedEnv(prev, rows, columns));
|
|
7121
7162
|
focusInput();
|
|
7122
7163
|
},
|
|
7164
|
+
insertCasesEnv: (rows) => {
|
|
7165
|
+
applyStructural((prev) => insertCasesEnv(prev, rows));
|
|
7166
|
+
focusInput();
|
|
7167
|
+
},
|
|
7123
7168
|
insertSqrt: () => {
|
|
7124
7169
|
applyStructural((prev) => insertSqrt(prev));
|
|
7125
7170
|
focusInput();
|