@drghaliasri/butex 4.0.1 → 4.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.
- package/README.md +4 -2
- package/dist/document.js +37 -1
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +37 -1
- package/dist/document.mjs.map +1 -1
- package/dist/document2.js +160 -2
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +160 -2
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.global.js +223 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +223 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +223 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +437 -6
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +437 -6
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2.js +437 -6
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +437 -6
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +11 -0
- package/dist/react.d.ts +11 -0
- package/dist/react.js +303 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +303 -4
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document2.js
CHANGED
|
@@ -997,6 +997,16 @@ var ATOMIC_COMMANDS = {
|
|
|
997
997
|
arabicLabel: "\u0645\u062D\u062F\u062F",
|
|
998
998
|
title: "\u0645\u062D\u062F\u062F"
|
|
999
999
|
},
|
|
1000
|
+
////////////////////// Derivatives ////////////////////////////////
|
|
1001
|
+
ad: {
|
|
1002
|
+
id: "ad",
|
|
1003
|
+
category: "derivative",
|
|
1004
|
+
englishTex: "\\mathrm{d}",
|
|
1005
|
+
englishLabel: "d",
|
|
1006
|
+
arabicTex: "\\ad",
|
|
1007
|
+
arabicLabel: "\u0621",
|
|
1008
|
+
title: "\u0639\u0644\u0627\u0645\u0629 \u0627\u0644\u0627\u0634\u062A\u0642\u0627\u0642"
|
|
1009
|
+
},
|
|
1000
1010
|
////////////////////// Groups /////////////////////////////////
|
|
1001
1011
|
N: {
|
|
1002
1012
|
id: "N",
|
|
@@ -1745,6 +1755,16 @@ function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
|
|
|
1745
1755
|
};
|
|
1746
1756
|
}
|
|
1747
1757
|
|
|
1758
|
+
// src/editor/divideOperator.ts
|
|
1759
|
+
var DIVIDE_OPERATOR_EN = "/";
|
|
1760
|
+
var DIVIDE_OPERATOR_AR = "\\";
|
|
1761
|
+
function isDivideOperatorExpr(expr) {
|
|
1762
|
+
return expr === DIVIDE_OPERATOR_EN || expr === DIVIDE_OPERATOR_AR;
|
|
1763
|
+
}
|
|
1764
|
+
function renderDivideOperatorLatex(side) {
|
|
1765
|
+
return side === "arabic" ? "\\backslash" : DIVIDE_OPERATOR_EN;
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1748
1768
|
// src/editor/digits.ts
|
|
1749
1769
|
var WESTERN = "0123456789";
|
|
1750
1770
|
var ARABIC_INDIC = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
|
|
@@ -1893,6 +1913,9 @@ function renderNodeEnglish(node, options) {
|
|
|
1893
1913
|
if (node.kind === "char") {
|
|
1894
1914
|
return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
|
|
1895
1915
|
}
|
|
1916
|
+
if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
|
|
1917
|
+
return `${renderDivideOperatorLatex("english")}${latinScripts(node, options)}`;
|
|
1918
|
+
}
|
|
1896
1919
|
return `${formatDigits(node.expr, selectedDigitForm(options))}${latinScripts(node, options)}`;
|
|
1897
1920
|
}
|
|
1898
1921
|
function renderNodeArabic(node, options) {
|
|
@@ -1927,6 +1950,9 @@ function renderNodeArabic(node, options) {
|
|
|
1927
1950
|
const content = renderCharContent(node, options);
|
|
1928
1951
|
return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
|
|
1929
1952
|
}
|
|
1953
|
+
if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
|
|
1954
|
+
return arabicScripts(node, renderDivideOperatorLatex("arabic"), options);
|
|
1955
|
+
}
|
|
1930
1956
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
1931
1957
|
}
|
|
1932
1958
|
function renderChainEnglish(chain, options) {
|
|
@@ -2503,7 +2529,95 @@ ${ATOMIC_COMMAND_CSS}
|
|
|
2503
2529
|
${ATOMIC_OPERATOR_COMMAND_CSS}
|
|
2504
2530
|
`.trim();
|
|
2505
2531
|
|
|
2532
|
+
// src/document/normalizeCharImport.ts
|
|
2533
|
+
var WRAPPER_SPECS = [
|
|
2534
|
+
{ prefix: "\\butexdiwanioutline", font: "diwaniOutline" },
|
|
2535
|
+
{ prefix: "\\diwanioutlineshaded", font: "diwaniOutline" },
|
|
2536
|
+
{ prefix: "\\butexdiwani", font: "diwani" },
|
|
2537
|
+
{ prefix: "\\butextakween", font: "takween" },
|
|
2538
|
+
{ prefix: "\\diwani", font: "diwani" },
|
|
2539
|
+
{ prefix: "\\takween", font: "takween" },
|
|
2540
|
+
{ prefix: "\\text" }
|
|
2541
|
+
];
|
|
2542
|
+
function readBracedArg(source, openBraceIndex) {
|
|
2543
|
+
if (source[openBraceIndex] !== "{") {
|
|
2544
|
+
return null;
|
|
2545
|
+
}
|
|
2546
|
+
let depth = 0;
|
|
2547
|
+
for (let index = openBraceIndex; index < source.length; index += 1) {
|
|
2548
|
+
const char = source[index];
|
|
2549
|
+
if (char === "{") {
|
|
2550
|
+
depth += 1;
|
|
2551
|
+
} else if (char === "}") {
|
|
2552
|
+
depth -= 1;
|
|
2553
|
+
if (depth === 0) {
|
|
2554
|
+
return { inner: source.slice(openBraceIndex + 1, index), end: index + 1 };
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
return null;
|
|
2559
|
+
}
|
|
2560
|
+
function peelWrapper(source) {
|
|
2561
|
+
for (const wrapper of WRAPPER_SPECS) {
|
|
2562
|
+
if (!source.startsWith(wrapper.prefix)) {
|
|
2563
|
+
continue;
|
|
2564
|
+
}
|
|
2565
|
+
const braced = readBracedArg(source, wrapper.prefix.length);
|
|
2566
|
+
if (!braced || braced.end !== source.length) {
|
|
2567
|
+
continue;
|
|
2568
|
+
}
|
|
2569
|
+
return { inner: braced.inner, font: wrapper.font };
|
|
2570
|
+
}
|
|
2571
|
+
return null;
|
|
2572
|
+
}
|
|
2573
|
+
function normalizeCharImportExpr(expr) {
|
|
2574
|
+
const original = expr;
|
|
2575
|
+
let current = expr;
|
|
2576
|
+
let characterFont = "default";
|
|
2577
|
+
let changed = false;
|
|
2578
|
+
while (true) {
|
|
2579
|
+
const peeled = peelWrapper(current);
|
|
2580
|
+
if (!peeled) {
|
|
2581
|
+
break;
|
|
2582
|
+
}
|
|
2583
|
+
current = peeled.inner;
|
|
2584
|
+
if (peeled.font) {
|
|
2585
|
+
characterFont = peeled.font;
|
|
2586
|
+
}
|
|
2587
|
+
changed = true;
|
|
2588
|
+
}
|
|
2589
|
+
if (!changed) {
|
|
2590
|
+
return { expr: original, characterFont: "default" };
|
|
2591
|
+
}
|
|
2592
|
+
if (current.includes("\\")) {
|
|
2593
|
+
return { expr: original, characterFont: "default" };
|
|
2594
|
+
}
|
|
2595
|
+
return { expr: current, characterFont };
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2506
2598
|
// src/document/mathEditorAdapter.ts
|
|
2599
|
+
var COMMAND_FONT_MAP = {
|
|
2600
|
+
"\\text": "infer",
|
|
2601
|
+
"\\butextakween": "takween",
|
|
2602
|
+
"\\takween": "takween",
|
|
2603
|
+
"\\butexdiwani": "diwani",
|
|
2604
|
+
"\\diwani": "diwani",
|
|
2605
|
+
"\\butexdiwanioutline": "diwaniOutline",
|
|
2606
|
+
"\\diwanioutlineshaded": "diwaniOutline"
|
|
2607
|
+
};
|
|
2608
|
+
var CHAR_FONT_EXPORT_TEX = {
|
|
2609
|
+
takween: "\\butextakween",
|
|
2610
|
+
diwani: "\\butexdiwani",
|
|
2611
|
+
diwaniOutline: "\\butexdiwanioutline"
|
|
2612
|
+
};
|
|
2613
|
+
function charEditorNodeToAstNode(node) {
|
|
2614
|
+
const font = node.characterFont ?? "default";
|
|
2615
|
+
const charNode = new CharNode(node.expr);
|
|
2616
|
+
if (font === "default") {
|
|
2617
|
+
return charNode;
|
|
2618
|
+
}
|
|
2619
|
+
return new CommandNode(CHAR_FONT_EXPORT_TEX[font], [], [new ChainNode([charNode])]);
|
|
2620
|
+
}
|
|
2507
2621
|
function commandIdForTex(tex) {
|
|
2508
2622
|
for (const spec of Object.values(ATOMIC_COMMANDS)) {
|
|
2509
2623
|
const renderTex = spec.arabicRenderTex;
|
|
@@ -2615,6 +2729,42 @@ function envToEditorNode(node) {
|
|
|
2615
2729
|
const scripts = attachScripts(node, env);
|
|
2616
2730
|
return scripts ?? { editable: true, node: env };
|
|
2617
2731
|
}
|
|
2732
|
+
function charFromTextLikeCommand(node) {
|
|
2733
|
+
const commandFont = COMMAND_FONT_MAP[node.name];
|
|
2734
|
+
if (commandFont === void 0) {
|
|
2735
|
+
return null;
|
|
2736
|
+
}
|
|
2737
|
+
if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
|
|
2738
|
+
return null;
|
|
2739
|
+
}
|
|
2740
|
+
const arg = node.mandatoryArgs[0];
|
|
2741
|
+
if (arg.chain.length !== 1) {
|
|
2742
|
+
return null;
|
|
2743
|
+
}
|
|
2744
|
+
const child = arg.chain[0];
|
|
2745
|
+
if (child instanceof CommandNode) {
|
|
2746
|
+
const nested = charFromTextLikeCommand(child);
|
|
2747
|
+
if (!nested?.editable) {
|
|
2748
|
+
return null;
|
|
2749
|
+
}
|
|
2750
|
+
if (commandFont !== "infer") {
|
|
2751
|
+
nested.node.characterFont = commandFont;
|
|
2752
|
+
}
|
|
2753
|
+
const scripts2 = attachScripts(node, nested.node);
|
|
2754
|
+
return scripts2 ?? nested;
|
|
2755
|
+
}
|
|
2756
|
+
if (!(child instanceof CharNode)) {
|
|
2757
|
+
return null;
|
|
2758
|
+
}
|
|
2759
|
+
const normalized = normalizeCharImportExpr(child.expr);
|
|
2760
|
+
const characterFont = commandFont === "infer" ? normalized.characterFont : commandFont;
|
|
2761
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
2762
|
+
if (characterFont !== "default") {
|
|
2763
|
+
editorNode.characterFont = characterFont;
|
|
2764
|
+
}
|
|
2765
|
+
const scripts = attachScripts(node, editorNode);
|
|
2766
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
2767
|
+
}
|
|
2618
2768
|
function commandToEditorNode(node) {
|
|
2619
2769
|
if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
|
|
2620
2770
|
const frac = createFracNode();
|
|
@@ -2672,11 +2822,19 @@ function commandToEditorNode(node) {
|
|
|
2672
2822
|
}
|
|
2673
2823
|
return { editable: true, node: atomicOperator };
|
|
2674
2824
|
}
|
|
2825
|
+
const textLike = charFromTextLikeCommand(node);
|
|
2826
|
+
if (textLike) {
|
|
2827
|
+
return textLike;
|
|
2828
|
+
}
|
|
2675
2829
|
return { editable: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.name}` };
|
|
2676
2830
|
}
|
|
2677
2831
|
function astNodeToEditorNode(node) {
|
|
2678
2832
|
if (node instanceof CharNode) {
|
|
2679
|
-
const
|
|
2833
|
+
const normalized = normalizeCharImportExpr(node.expr);
|
|
2834
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
2835
|
+
if (normalized.characterFont !== "default") {
|
|
2836
|
+
editorNode.characterFont = normalized.characterFont;
|
|
2837
|
+
}
|
|
2680
2838
|
const scripts = attachScripts(node, editorNode);
|
|
2681
2839
|
return scripts ?? { editable: true, node: editorNode };
|
|
2682
2840
|
}
|
|
@@ -2785,7 +2943,7 @@ function editorEnvToAstNode(node) {
|
|
|
2785
2943
|
function editorNodeToAstNode(node) {
|
|
2786
2944
|
let astNode;
|
|
2787
2945
|
if (node.kind === "char") {
|
|
2788
|
-
astNode =
|
|
2946
|
+
astNode = charEditorNodeToAstNode(node);
|
|
2789
2947
|
} else if (node.kind === "number") {
|
|
2790
2948
|
astNode = new NumberNode(node.expr);
|
|
2791
2949
|
} else if (node.kind === "operator") {
|