@drghaliasri/butex 4.0.1 → 4.1.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 +1 -0
- package/dist/document.js.map +1 -1
- package/dist/document.mjs.map +1 -1
- package/dist/document2.js +120 -1
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +120 -1
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document.js +120 -1
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +120 -1
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2.js +120 -1
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +120 -1
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document2.js
CHANGED
|
@@ -2503,7 +2503,82 @@ ${ATOMIC_COMMAND_CSS}
|
|
|
2503
2503
|
${ATOMIC_OPERATOR_COMMAND_CSS}
|
|
2504
2504
|
`.trim();
|
|
2505
2505
|
|
|
2506
|
+
// src/document/normalizeCharImport.ts
|
|
2507
|
+
var WRAPPER_SPECS = [
|
|
2508
|
+
{ prefix: "\\butexdiwanioutline", font: "diwaniOutline" },
|
|
2509
|
+
{ prefix: "\\diwanioutlineshaded", font: "diwaniOutline" },
|
|
2510
|
+
{ prefix: "\\butexdiwani", font: "diwani" },
|
|
2511
|
+
{ prefix: "\\butextakween", font: "takween" },
|
|
2512
|
+
{ prefix: "\\diwani", font: "diwani" },
|
|
2513
|
+
{ prefix: "\\takween", font: "takween" },
|
|
2514
|
+
{ prefix: "\\text" }
|
|
2515
|
+
];
|
|
2516
|
+
function readBracedArg(source, openBraceIndex) {
|
|
2517
|
+
if (source[openBraceIndex] !== "{") {
|
|
2518
|
+
return null;
|
|
2519
|
+
}
|
|
2520
|
+
let depth = 0;
|
|
2521
|
+
for (let index = openBraceIndex; index < source.length; index += 1) {
|
|
2522
|
+
const char = source[index];
|
|
2523
|
+
if (char === "{") {
|
|
2524
|
+
depth += 1;
|
|
2525
|
+
} else if (char === "}") {
|
|
2526
|
+
depth -= 1;
|
|
2527
|
+
if (depth === 0) {
|
|
2528
|
+
return { inner: source.slice(openBraceIndex + 1, index), end: index + 1 };
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
return null;
|
|
2533
|
+
}
|
|
2534
|
+
function peelWrapper(source) {
|
|
2535
|
+
for (const wrapper of WRAPPER_SPECS) {
|
|
2536
|
+
if (!source.startsWith(wrapper.prefix)) {
|
|
2537
|
+
continue;
|
|
2538
|
+
}
|
|
2539
|
+
const braced = readBracedArg(source, wrapper.prefix.length);
|
|
2540
|
+
if (!braced || braced.end !== source.length) {
|
|
2541
|
+
continue;
|
|
2542
|
+
}
|
|
2543
|
+
return { inner: braced.inner, font: wrapper.font };
|
|
2544
|
+
}
|
|
2545
|
+
return null;
|
|
2546
|
+
}
|
|
2547
|
+
function normalizeCharImportExpr(expr) {
|
|
2548
|
+
const original = expr;
|
|
2549
|
+
let current = expr;
|
|
2550
|
+
let characterFont = "default";
|
|
2551
|
+
let changed = false;
|
|
2552
|
+
while (true) {
|
|
2553
|
+
const peeled = peelWrapper(current);
|
|
2554
|
+
if (!peeled) {
|
|
2555
|
+
break;
|
|
2556
|
+
}
|
|
2557
|
+
current = peeled.inner;
|
|
2558
|
+
if (peeled.font) {
|
|
2559
|
+
characterFont = peeled.font;
|
|
2560
|
+
}
|
|
2561
|
+
changed = true;
|
|
2562
|
+
}
|
|
2563
|
+
if (!changed) {
|
|
2564
|
+
return { expr: original, characterFont: "default" };
|
|
2565
|
+
}
|
|
2566
|
+
if (current.includes("\\")) {
|
|
2567
|
+
return { expr: original, characterFont: "default" };
|
|
2568
|
+
}
|
|
2569
|
+
return { expr: current, characterFont };
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2506
2572
|
// src/document/mathEditorAdapter.ts
|
|
2573
|
+
var COMMAND_FONT_MAP = {
|
|
2574
|
+
"\\text": "infer",
|
|
2575
|
+
"\\butextakween": "takween",
|
|
2576
|
+
"\\takween": "takween",
|
|
2577
|
+
"\\butexdiwani": "diwani",
|
|
2578
|
+
"\\diwani": "diwani",
|
|
2579
|
+
"\\butexdiwanioutline": "diwaniOutline",
|
|
2580
|
+
"\\diwanioutlineshaded": "diwaniOutline"
|
|
2581
|
+
};
|
|
2507
2582
|
function commandIdForTex(tex) {
|
|
2508
2583
|
for (const spec of Object.values(ATOMIC_COMMANDS)) {
|
|
2509
2584
|
const renderTex = spec.arabicRenderTex;
|
|
@@ -2615,6 +2690,42 @@ function envToEditorNode(node) {
|
|
|
2615
2690
|
const scripts = attachScripts(node, env);
|
|
2616
2691
|
return scripts ?? { editable: true, node: env };
|
|
2617
2692
|
}
|
|
2693
|
+
function charFromTextLikeCommand(node) {
|
|
2694
|
+
const commandFont = COMMAND_FONT_MAP[node.name];
|
|
2695
|
+
if (commandFont === void 0) {
|
|
2696
|
+
return null;
|
|
2697
|
+
}
|
|
2698
|
+
if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
|
|
2699
|
+
return null;
|
|
2700
|
+
}
|
|
2701
|
+
const arg = node.mandatoryArgs[0];
|
|
2702
|
+
if (arg.chain.length !== 1) {
|
|
2703
|
+
return null;
|
|
2704
|
+
}
|
|
2705
|
+
const child = arg.chain[0];
|
|
2706
|
+
if (child instanceof CommandNode) {
|
|
2707
|
+
const nested = charFromTextLikeCommand(child);
|
|
2708
|
+
if (!nested?.editable) {
|
|
2709
|
+
return null;
|
|
2710
|
+
}
|
|
2711
|
+
if (commandFont !== "infer") {
|
|
2712
|
+
nested.node.characterFont = commandFont;
|
|
2713
|
+
}
|
|
2714
|
+
const scripts2 = attachScripts(node, nested.node);
|
|
2715
|
+
return scripts2 ?? nested;
|
|
2716
|
+
}
|
|
2717
|
+
if (!(child instanceof CharNode)) {
|
|
2718
|
+
return null;
|
|
2719
|
+
}
|
|
2720
|
+
const normalized = normalizeCharImportExpr(child.expr);
|
|
2721
|
+
const characterFont = commandFont === "infer" ? normalized.characterFont : commandFont;
|
|
2722
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
2723
|
+
if (characterFont !== "default") {
|
|
2724
|
+
editorNode.characterFont = characterFont;
|
|
2725
|
+
}
|
|
2726
|
+
const scripts = attachScripts(node, editorNode);
|
|
2727
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
2728
|
+
}
|
|
2618
2729
|
function commandToEditorNode(node) {
|
|
2619
2730
|
if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
|
|
2620
2731
|
const frac = createFracNode();
|
|
@@ -2672,11 +2783,19 @@ function commandToEditorNode(node) {
|
|
|
2672
2783
|
}
|
|
2673
2784
|
return { editable: true, node: atomicOperator };
|
|
2674
2785
|
}
|
|
2786
|
+
const textLike = charFromTextLikeCommand(node);
|
|
2787
|
+
if (textLike) {
|
|
2788
|
+
return textLike;
|
|
2789
|
+
}
|
|
2675
2790
|
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
2791
|
}
|
|
2677
2792
|
function astNodeToEditorNode(node) {
|
|
2678
2793
|
if (node instanceof CharNode) {
|
|
2679
|
-
const
|
|
2794
|
+
const normalized = normalizeCharImportExpr(node.expr);
|
|
2795
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
2796
|
+
if (normalized.characterFont !== "default") {
|
|
2797
|
+
editorNode.characterFont = normalized.characterFont;
|
|
2798
|
+
}
|
|
2680
2799
|
const scripts = attachScripts(node, editorNode);
|
|
2681
2800
|
return scripts ?? { editable: true, node: editorNode };
|
|
2682
2801
|
}
|