@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.mjs
CHANGED
|
@@ -2438,7 +2438,82 @@ ${ATOMIC_COMMAND_CSS}
|
|
|
2438
2438
|
${ATOMIC_OPERATOR_COMMAND_CSS}
|
|
2439
2439
|
`.trim();
|
|
2440
2440
|
|
|
2441
|
+
// src/document/normalizeCharImport.ts
|
|
2442
|
+
var WRAPPER_SPECS = [
|
|
2443
|
+
{ prefix: "\\butexdiwanioutline", font: "diwaniOutline" },
|
|
2444
|
+
{ prefix: "\\diwanioutlineshaded", font: "diwaniOutline" },
|
|
2445
|
+
{ prefix: "\\butexdiwani", font: "diwani" },
|
|
2446
|
+
{ prefix: "\\butextakween", font: "takween" },
|
|
2447
|
+
{ prefix: "\\diwani", font: "diwani" },
|
|
2448
|
+
{ prefix: "\\takween", font: "takween" },
|
|
2449
|
+
{ prefix: "\\text" }
|
|
2450
|
+
];
|
|
2451
|
+
function readBracedArg(source, openBraceIndex) {
|
|
2452
|
+
if (source[openBraceIndex] !== "{") {
|
|
2453
|
+
return null;
|
|
2454
|
+
}
|
|
2455
|
+
let depth = 0;
|
|
2456
|
+
for (let index = openBraceIndex; index < source.length; index += 1) {
|
|
2457
|
+
const char = source[index];
|
|
2458
|
+
if (char === "{") {
|
|
2459
|
+
depth += 1;
|
|
2460
|
+
} else if (char === "}") {
|
|
2461
|
+
depth -= 1;
|
|
2462
|
+
if (depth === 0) {
|
|
2463
|
+
return { inner: source.slice(openBraceIndex + 1, index), end: index + 1 };
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
return null;
|
|
2468
|
+
}
|
|
2469
|
+
function peelWrapper(source) {
|
|
2470
|
+
for (const wrapper of WRAPPER_SPECS) {
|
|
2471
|
+
if (!source.startsWith(wrapper.prefix)) {
|
|
2472
|
+
continue;
|
|
2473
|
+
}
|
|
2474
|
+
const braced = readBracedArg(source, wrapper.prefix.length);
|
|
2475
|
+
if (!braced || braced.end !== source.length) {
|
|
2476
|
+
continue;
|
|
2477
|
+
}
|
|
2478
|
+
return { inner: braced.inner, font: wrapper.font };
|
|
2479
|
+
}
|
|
2480
|
+
return null;
|
|
2481
|
+
}
|
|
2482
|
+
function normalizeCharImportExpr(expr) {
|
|
2483
|
+
const original = expr;
|
|
2484
|
+
let current = expr;
|
|
2485
|
+
let characterFont = "default";
|
|
2486
|
+
let changed = false;
|
|
2487
|
+
while (true) {
|
|
2488
|
+
const peeled = peelWrapper(current);
|
|
2489
|
+
if (!peeled) {
|
|
2490
|
+
break;
|
|
2491
|
+
}
|
|
2492
|
+
current = peeled.inner;
|
|
2493
|
+
if (peeled.font) {
|
|
2494
|
+
characterFont = peeled.font;
|
|
2495
|
+
}
|
|
2496
|
+
changed = true;
|
|
2497
|
+
}
|
|
2498
|
+
if (!changed) {
|
|
2499
|
+
return { expr: original, characterFont: "default" };
|
|
2500
|
+
}
|
|
2501
|
+
if (current.includes("\\")) {
|
|
2502
|
+
return { expr: original, characterFont: "default" };
|
|
2503
|
+
}
|
|
2504
|
+
return { expr: current, characterFont };
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2441
2507
|
// src/document/mathEditorAdapter.ts
|
|
2508
|
+
var COMMAND_FONT_MAP = {
|
|
2509
|
+
"\\text": "infer",
|
|
2510
|
+
"\\butextakween": "takween",
|
|
2511
|
+
"\\takween": "takween",
|
|
2512
|
+
"\\butexdiwani": "diwani",
|
|
2513
|
+
"\\diwani": "diwani",
|
|
2514
|
+
"\\butexdiwanioutline": "diwaniOutline",
|
|
2515
|
+
"\\diwanioutlineshaded": "diwaniOutline"
|
|
2516
|
+
};
|
|
2442
2517
|
function commandIdForTex(tex) {
|
|
2443
2518
|
for (const spec of Object.values(ATOMIC_COMMANDS)) {
|
|
2444
2519
|
const renderTex = spec.arabicRenderTex;
|
|
@@ -2550,6 +2625,42 @@ function envToEditorNode(node) {
|
|
|
2550
2625
|
const scripts = attachScripts(node, env);
|
|
2551
2626
|
return scripts ?? { editable: true, node: env };
|
|
2552
2627
|
}
|
|
2628
|
+
function charFromTextLikeCommand(node) {
|
|
2629
|
+
const commandFont = COMMAND_FONT_MAP[node.name];
|
|
2630
|
+
if (commandFont === void 0) {
|
|
2631
|
+
return null;
|
|
2632
|
+
}
|
|
2633
|
+
if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
|
|
2634
|
+
return null;
|
|
2635
|
+
}
|
|
2636
|
+
const arg = node.mandatoryArgs[0];
|
|
2637
|
+
if (arg.chain.length !== 1) {
|
|
2638
|
+
return null;
|
|
2639
|
+
}
|
|
2640
|
+
const child = arg.chain[0];
|
|
2641
|
+
if (child instanceof CommandNode) {
|
|
2642
|
+
const nested = charFromTextLikeCommand(child);
|
|
2643
|
+
if (!nested?.editable) {
|
|
2644
|
+
return null;
|
|
2645
|
+
}
|
|
2646
|
+
if (commandFont !== "infer") {
|
|
2647
|
+
nested.node.characterFont = commandFont;
|
|
2648
|
+
}
|
|
2649
|
+
const scripts2 = attachScripts(node, nested.node);
|
|
2650
|
+
return scripts2 ?? nested;
|
|
2651
|
+
}
|
|
2652
|
+
if (!(child instanceof CharNode)) {
|
|
2653
|
+
return null;
|
|
2654
|
+
}
|
|
2655
|
+
const normalized = normalizeCharImportExpr(child.expr);
|
|
2656
|
+
const characterFont = commandFont === "infer" ? normalized.characterFont : commandFont;
|
|
2657
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
2658
|
+
if (characterFont !== "default") {
|
|
2659
|
+
editorNode.characterFont = characterFont;
|
|
2660
|
+
}
|
|
2661
|
+
const scripts = attachScripts(node, editorNode);
|
|
2662
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
2663
|
+
}
|
|
2553
2664
|
function commandToEditorNode(node) {
|
|
2554
2665
|
if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
|
|
2555
2666
|
const frac = createFracNode();
|
|
@@ -2607,11 +2718,19 @@ function commandToEditorNode(node) {
|
|
|
2607
2718
|
}
|
|
2608
2719
|
return { editable: true, node: atomicOperator };
|
|
2609
2720
|
}
|
|
2721
|
+
const textLike = charFromTextLikeCommand(node);
|
|
2722
|
+
if (textLike) {
|
|
2723
|
+
return textLike;
|
|
2724
|
+
}
|
|
2610
2725
|
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}` };
|
|
2611
2726
|
}
|
|
2612
2727
|
function astNodeToEditorNode(node) {
|
|
2613
2728
|
if (node instanceof CharNode) {
|
|
2614
|
-
const
|
|
2729
|
+
const normalized = normalizeCharImportExpr(node.expr);
|
|
2730
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
2731
|
+
if (normalized.characterFont !== "default") {
|
|
2732
|
+
editorNode.characterFont = normalized.characterFont;
|
|
2733
|
+
}
|
|
2615
2734
|
const scripts = attachScripts(node, editorNode);
|
|
2616
2735
|
return scripts ?? { editable: true, node: editorNode };
|
|
2617
2736
|
}
|