@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/react-document.js
CHANGED
|
@@ -5581,7 +5581,82 @@ function createEditorRuntime(options) {
|
|
|
5581
5581
|
return api;
|
|
5582
5582
|
}
|
|
5583
5583
|
|
|
5584
|
+
// src/document/normalizeCharImport.ts
|
|
5585
|
+
var WRAPPER_SPECS = [
|
|
5586
|
+
{ prefix: "\\butexdiwanioutline", font: "diwaniOutline" },
|
|
5587
|
+
{ prefix: "\\diwanioutlineshaded", font: "diwaniOutline" },
|
|
5588
|
+
{ prefix: "\\butexdiwani", font: "diwani" },
|
|
5589
|
+
{ prefix: "\\butextakween", font: "takween" },
|
|
5590
|
+
{ prefix: "\\diwani", font: "diwani" },
|
|
5591
|
+
{ prefix: "\\takween", font: "takween" },
|
|
5592
|
+
{ prefix: "\\text" }
|
|
5593
|
+
];
|
|
5594
|
+
function readBracedArg(source, openBraceIndex) {
|
|
5595
|
+
if (source[openBraceIndex] !== "{") {
|
|
5596
|
+
return null;
|
|
5597
|
+
}
|
|
5598
|
+
let depth = 0;
|
|
5599
|
+
for (let index = openBraceIndex; index < source.length; index += 1) {
|
|
5600
|
+
const char = source[index];
|
|
5601
|
+
if (char === "{") {
|
|
5602
|
+
depth += 1;
|
|
5603
|
+
} else if (char === "}") {
|
|
5604
|
+
depth -= 1;
|
|
5605
|
+
if (depth === 0) {
|
|
5606
|
+
return { inner: source.slice(openBraceIndex + 1, index), end: index + 1 };
|
|
5607
|
+
}
|
|
5608
|
+
}
|
|
5609
|
+
}
|
|
5610
|
+
return null;
|
|
5611
|
+
}
|
|
5612
|
+
function peelWrapper(source) {
|
|
5613
|
+
for (const wrapper of WRAPPER_SPECS) {
|
|
5614
|
+
if (!source.startsWith(wrapper.prefix)) {
|
|
5615
|
+
continue;
|
|
5616
|
+
}
|
|
5617
|
+
const braced = readBracedArg(source, wrapper.prefix.length);
|
|
5618
|
+
if (!braced || braced.end !== source.length) {
|
|
5619
|
+
continue;
|
|
5620
|
+
}
|
|
5621
|
+
return { inner: braced.inner, font: wrapper.font };
|
|
5622
|
+
}
|
|
5623
|
+
return null;
|
|
5624
|
+
}
|
|
5625
|
+
function normalizeCharImportExpr(expr) {
|
|
5626
|
+
const original = expr;
|
|
5627
|
+
let current = expr;
|
|
5628
|
+
let characterFont = "default";
|
|
5629
|
+
let changed = false;
|
|
5630
|
+
while (true) {
|
|
5631
|
+
const peeled = peelWrapper(current);
|
|
5632
|
+
if (!peeled) {
|
|
5633
|
+
break;
|
|
5634
|
+
}
|
|
5635
|
+
current = peeled.inner;
|
|
5636
|
+
if (peeled.font) {
|
|
5637
|
+
characterFont = peeled.font;
|
|
5638
|
+
}
|
|
5639
|
+
changed = true;
|
|
5640
|
+
}
|
|
5641
|
+
if (!changed) {
|
|
5642
|
+
return { expr: original, characterFont: "default" };
|
|
5643
|
+
}
|
|
5644
|
+
if (current.includes("\\")) {
|
|
5645
|
+
return { expr: original, characterFont: "default" };
|
|
5646
|
+
}
|
|
5647
|
+
return { expr: current, characterFont };
|
|
5648
|
+
}
|
|
5649
|
+
|
|
5584
5650
|
// src/document/mathEditorAdapter.ts
|
|
5651
|
+
var COMMAND_FONT_MAP = {
|
|
5652
|
+
"\\text": "infer",
|
|
5653
|
+
"\\butextakween": "takween",
|
|
5654
|
+
"\\takween": "takween",
|
|
5655
|
+
"\\butexdiwani": "diwani",
|
|
5656
|
+
"\\diwani": "diwani",
|
|
5657
|
+
"\\butexdiwanioutline": "diwaniOutline",
|
|
5658
|
+
"\\diwanioutlineshaded": "diwaniOutline"
|
|
5659
|
+
};
|
|
5585
5660
|
function commandIdForTex(tex) {
|
|
5586
5661
|
for (const spec of Object.values(ATOMIC_COMMANDS)) {
|
|
5587
5662
|
const renderTex = spec.arabicRenderTex;
|
|
@@ -5693,6 +5768,42 @@ function envToEditorNode(node) {
|
|
|
5693
5768
|
const scripts = attachScripts(node, env);
|
|
5694
5769
|
return scripts ?? { editable: true, node: env };
|
|
5695
5770
|
}
|
|
5771
|
+
function charFromTextLikeCommand(node) {
|
|
5772
|
+
const commandFont = COMMAND_FONT_MAP[node.name];
|
|
5773
|
+
if (commandFont === void 0) {
|
|
5774
|
+
return null;
|
|
5775
|
+
}
|
|
5776
|
+
if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
|
|
5777
|
+
return null;
|
|
5778
|
+
}
|
|
5779
|
+
const arg = node.mandatoryArgs[0];
|
|
5780
|
+
if (arg.chain.length !== 1) {
|
|
5781
|
+
return null;
|
|
5782
|
+
}
|
|
5783
|
+
const child = arg.chain[0];
|
|
5784
|
+
if (child instanceof CommandNode) {
|
|
5785
|
+
const nested = charFromTextLikeCommand(child);
|
|
5786
|
+
if (!nested?.editable) {
|
|
5787
|
+
return null;
|
|
5788
|
+
}
|
|
5789
|
+
if (commandFont !== "infer") {
|
|
5790
|
+
nested.node.characterFont = commandFont;
|
|
5791
|
+
}
|
|
5792
|
+
const scripts2 = attachScripts(node, nested.node);
|
|
5793
|
+
return scripts2 ?? nested;
|
|
5794
|
+
}
|
|
5795
|
+
if (!(child instanceof CharNode)) {
|
|
5796
|
+
return null;
|
|
5797
|
+
}
|
|
5798
|
+
const normalized = normalizeCharImportExpr(child.expr);
|
|
5799
|
+
const characterFont = commandFont === "infer" ? normalized.characterFont : commandFont;
|
|
5800
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
5801
|
+
if (characterFont !== "default") {
|
|
5802
|
+
editorNode.characterFont = characterFont;
|
|
5803
|
+
}
|
|
5804
|
+
const scripts = attachScripts(node, editorNode);
|
|
5805
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
5806
|
+
}
|
|
5696
5807
|
function commandToEditorNode(node) {
|
|
5697
5808
|
if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
|
|
5698
5809
|
const frac = createFracNode();
|
|
@@ -5750,11 +5861,19 @@ function commandToEditorNode(node) {
|
|
|
5750
5861
|
}
|
|
5751
5862
|
return { editable: true, node: atomicOperator };
|
|
5752
5863
|
}
|
|
5864
|
+
const textLike = charFromTextLikeCommand(node);
|
|
5865
|
+
if (textLike) {
|
|
5866
|
+
return textLike;
|
|
5867
|
+
}
|
|
5753
5868
|
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}` };
|
|
5754
5869
|
}
|
|
5755
5870
|
function astNodeToEditorNode(node) {
|
|
5756
5871
|
if (node instanceof CharNode) {
|
|
5757
|
-
const
|
|
5872
|
+
const normalized = normalizeCharImportExpr(node.expr);
|
|
5873
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
5874
|
+
if (normalized.characterFont !== "default") {
|
|
5875
|
+
editorNode.characterFont = normalized.characterFont;
|
|
5876
|
+
}
|
|
5758
5877
|
const scripts = attachScripts(node, editorNode);
|
|
5759
5878
|
return scripts ?? { editable: true, node: editorNode };
|
|
5760
5879
|
}
|