@drghaliasri/butex 7.2.0 → 7.2.2
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.d.mts +8 -0
- package/dist/document.d.ts +8 -0
- package/dist/document.js +38 -2
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +38 -2
- package/dist/document.mjs.map +1 -1
- package/dist/document2-cli.js +107 -2
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +8 -0
- package/dist/document2.d.ts +8 -0
- package/dist/document2.js +107 -2
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +107 -2
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.global.js +109 -11
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +109 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -11
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.d.mts +2 -0
- package/dist/react-document.d.ts +2 -0
- package/dist/react-document.js +230 -40
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +230 -40
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2-preview.d.mts +2 -0
- package/dist/react-document2-preview.d.ts +2 -0
- package/dist/react-document2-preview.js +91 -0
- package/dist/react-document2-preview.js.map +1 -1
- package/dist/react-document2-preview.mjs +91 -0
- package/dist/react-document2-preview.mjs.map +1 -1
- package/dist/react-document2.d.mts +8 -0
- package/dist/react-document2.d.ts +8 -0
- package/dist/react-document2.js +230 -40
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +230 -40
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +16 -0
- package/dist/react.d.ts +16 -0
- package/dist/react.js +230 -40
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +230 -40
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document2.d.mts
CHANGED
|
@@ -15,6 +15,10 @@ type EditorNode = {
|
|
|
15
15
|
kind: EditorNodeKind;
|
|
16
16
|
expr: string;
|
|
17
17
|
characterFont?: CharacterFontId;
|
|
18
|
+
/** Minimal upstream source identity used only while the node remains unchanged. */
|
|
19
|
+
sourceLatex?: string;
|
|
20
|
+
/** Existing editor node reused for wrapper commands that need editable content. */
|
|
21
|
+
wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
|
|
18
22
|
superscript: EditorChain | null;
|
|
19
23
|
subscript: EditorChain | null;
|
|
20
24
|
leftDelimExpr: string;
|
|
@@ -66,6 +70,8 @@ type EditorSession = {
|
|
|
66
70
|
arabicReverseNumberTyping: boolean;
|
|
67
71
|
/** Font applied to newly typed char nodes. */
|
|
68
72
|
currentCharacterFont: CharacterFontId;
|
|
73
|
+
/** Structured command wrapper applied to newly typed chars; kept separate from fonts. */
|
|
74
|
+
currentCharacterWrapper: '\\boldarabic' | null;
|
|
69
75
|
/** Digit glyph form used for editor display and LaTeX preview output. */
|
|
70
76
|
currentDigitForm: DigitFormId;
|
|
71
77
|
caret: EditorCaret;
|
|
@@ -93,6 +99,7 @@ type ArabicNodeJson = {
|
|
|
93
99
|
opening?: string;
|
|
94
100
|
closing?: string;
|
|
95
101
|
lines?: ChainJson[];
|
|
102
|
+
source_latex?: string;
|
|
96
103
|
};
|
|
97
104
|
type ChainJson = {
|
|
98
105
|
node_type: 'ChainClass';
|
|
@@ -105,6 +112,7 @@ declare class BaseAstNode {
|
|
|
105
112
|
superscript: ChainNode | null;
|
|
106
113
|
subscript: ChainNode | null;
|
|
107
114
|
nodeType: string;
|
|
115
|
+
sourceLatex: string | null;
|
|
108
116
|
constructor(state?: State | null);
|
|
109
117
|
latex(): string;
|
|
110
118
|
arabicLatex(): string;
|
package/dist/document2.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ type EditorNode = {
|
|
|
15
15
|
kind: EditorNodeKind;
|
|
16
16
|
expr: string;
|
|
17
17
|
characterFont?: CharacterFontId;
|
|
18
|
+
/** Minimal upstream source identity used only while the node remains unchanged. */
|
|
19
|
+
sourceLatex?: string;
|
|
20
|
+
/** Existing editor node reused for wrapper commands that need editable content. */
|
|
21
|
+
wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
|
|
18
22
|
superscript: EditorChain | null;
|
|
19
23
|
subscript: EditorChain | null;
|
|
20
24
|
leftDelimExpr: string;
|
|
@@ -66,6 +70,8 @@ type EditorSession = {
|
|
|
66
70
|
arabicReverseNumberTyping: boolean;
|
|
67
71
|
/** Font applied to newly typed char nodes. */
|
|
68
72
|
currentCharacterFont: CharacterFontId;
|
|
73
|
+
/** Structured command wrapper applied to newly typed chars; kept separate from fonts. */
|
|
74
|
+
currentCharacterWrapper: '\\boldarabic' | null;
|
|
69
75
|
/** Digit glyph form used for editor display and LaTeX preview output. */
|
|
70
76
|
currentDigitForm: DigitFormId;
|
|
71
77
|
caret: EditorCaret;
|
|
@@ -93,6 +99,7 @@ type ArabicNodeJson = {
|
|
|
93
99
|
opening?: string;
|
|
94
100
|
closing?: string;
|
|
95
101
|
lines?: ChainJson[];
|
|
102
|
+
source_latex?: string;
|
|
96
103
|
};
|
|
97
104
|
type ChainJson = {
|
|
98
105
|
node_type: 'ChainClass';
|
|
@@ -105,6 +112,7 @@ declare class BaseAstNode {
|
|
|
105
112
|
superscript: ChainNode | null;
|
|
106
113
|
subscript: ChainNode | null;
|
|
107
114
|
nodeType: string;
|
|
115
|
+
sourceLatex: string | null;
|
|
108
116
|
constructor(state?: State | null);
|
|
109
117
|
latex(): string;
|
|
110
118
|
arabicLatex(): string;
|
package/dist/document2.js
CHANGED
|
@@ -550,6 +550,7 @@ var BaseAstNode = class {
|
|
|
550
550
|
superscript;
|
|
551
551
|
subscript;
|
|
552
552
|
nodeType;
|
|
553
|
+
sourceLatex;
|
|
553
554
|
constructor(state = null) {
|
|
554
555
|
if (state === null) {
|
|
555
556
|
state = new State();
|
|
@@ -558,6 +559,7 @@ var BaseAstNode = class {
|
|
|
558
559
|
this.superscript = null;
|
|
559
560
|
this.subscript = null;
|
|
560
561
|
this.nodeType = this.constructor.name;
|
|
562
|
+
this.sourceLatex = null;
|
|
561
563
|
}
|
|
562
564
|
latex() {
|
|
563
565
|
throw new Error("NotImplementedError");
|
|
@@ -746,6 +748,7 @@ ${this.closing}`;
|
|
|
746
748
|
}
|
|
747
749
|
};
|
|
748
750
|
function parseScripts(node, json, mode) {
|
|
751
|
+
node.sourceLatex = typeof json.source_latex === "string" && json.source_latex.length > 0 ? json.source_latex : null;
|
|
749
752
|
if (json.superscript) {
|
|
750
753
|
node.superscript = parseChain(json.superscript, mode);
|
|
751
754
|
}
|
|
@@ -885,7 +888,8 @@ function fromMathObjectJson(json, mode = "english") {
|
|
|
885
888
|
function scriptsToJson(node, path) {
|
|
886
889
|
return {
|
|
887
890
|
...node.superscript ? { superscript: chainToJson(node.superscript, `${path}.superscript`) } : {},
|
|
888
|
-
...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {}
|
|
891
|
+
...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {},
|
|
892
|
+
...node.sourceLatex ? { source_latex: node.sourceLatex } : {}
|
|
889
893
|
};
|
|
890
894
|
}
|
|
891
895
|
function nodeToJson(node, path) {
|
|
@@ -2354,6 +2358,15 @@ var ATOMIC_OPERATOR_COMMANDS = {
|
|
|
2354
2358
|
title: "\u0627\u0644\u0644\u0627\u0646\u0647\u0627\u064A\u0629",
|
|
2355
2359
|
svg_path: null
|
|
2356
2360
|
},
|
|
2361
|
+
top: {
|
|
2362
|
+
id: "top",
|
|
2363
|
+
category: "operators1",
|
|
2364
|
+
Tex: "\\top",
|
|
2365
|
+
mirror: false,
|
|
2366
|
+
Label: "\u22A4",
|
|
2367
|
+
title: "\u0627\u0644\u0645\u0646\u0642\u0648\u0644",
|
|
2368
|
+
svg_path: null
|
|
2369
|
+
},
|
|
2357
2370
|
times: {
|
|
2358
2371
|
id: "times",
|
|
2359
2372
|
category: "operators1",
|
|
@@ -3091,6 +3104,7 @@ function cloneEditorSession(session) {
|
|
|
3091
3104
|
forceSplitNextLeaf: session.forceSplitNextLeaf,
|
|
3092
3105
|
arabicReverseNumberTyping: session.arabicReverseNumberTyping,
|
|
3093
3106
|
currentCharacterFont: session.currentCharacterFont ?? "default",
|
|
3107
|
+
currentCharacterWrapper: session.currentCharacterWrapper ?? null,
|
|
3094
3108
|
currentDigitForm: session.currentDigitForm ?? "western",
|
|
3095
3109
|
caret: { ...session.caret },
|
|
3096
3110
|
selection: session.selection ? { ...session.selection } : null,
|
|
@@ -3163,6 +3177,7 @@ function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
|
|
|
3163
3177
|
forceSplitNextLeaf: false,
|
|
3164
3178
|
arabicReverseNumberTyping: true,
|
|
3165
3179
|
currentCharacterFont: "default",
|
|
3180
|
+
currentCharacterWrapper: null,
|
|
3166
3181
|
currentDigitForm: "western",
|
|
3167
3182
|
caret: {
|
|
3168
3183
|
chainId: englishTree.id,
|
|
@@ -3232,6 +3247,7 @@ var CHARACTER_FONT_SPECS = [
|
|
|
3232
3247
|
latexFontCommand: "\\maghribi",
|
|
3233
3248
|
latexFontFamily: "Almaghribi Warsh Quran",
|
|
3234
3249
|
browserFontStack: '"Almaghribi Warsh Quran", Amiri, "Segoe UI", Tahoma, sans-serif',
|
|
3250
|
+
importAliases: ["\\maghribi"],
|
|
3235
3251
|
svgLayoutKey: "maghribi"
|
|
3236
3252
|
}
|
|
3237
3253
|
];
|
|
@@ -3398,6 +3414,14 @@ function renderNodeEnglish(node, options) {
|
|
|
3398
3414
|
return `${node.expr}${latinScripts(node, options)}`;
|
|
3399
3415
|
}
|
|
3400
3416
|
if (node.kind === "char") {
|
|
3417
|
+
if (node.sourceLatex) {
|
|
3418
|
+
return `${node.sourceLatex}${latinScripts(node, options)}`;
|
|
3419
|
+
}
|
|
3420
|
+
if (node.wrapperCommand) {
|
|
3421
|
+
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3422
|
+
const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
|
|
3423
|
+
return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
|
|
3424
|
+
}
|
|
3401
3425
|
return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
|
|
3402
3426
|
}
|
|
3403
3427
|
if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
|
|
@@ -3451,6 +3475,10 @@ function renderNodeArabic(node, options) {
|
|
|
3451
3475
|
if (node.kind === "char") {
|
|
3452
3476
|
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3453
3477
|
const content = renderCharContent(node, options);
|
|
3478
|
+
if (node.wrapperCommand) {
|
|
3479
|
+
const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
|
|
3480
|
+
return arabicScripts(node, `${wrapper}{${content}}`, options);
|
|
3481
|
+
}
|
|
3454
3482
|
return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
|
|
3455
3483
|
}
|
|
3456
3484
|
if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
|
|
@@ -4049,6 +4077,11 @@ ${BUTEX_FONT_FACE_CSS}
|
|
|
4049
4077
|
|
|
4050
4078
|
${CHARACTER_FONT_CSS}
|
|
4051
4079
|
|
|
4080
|
+
.node-value--bold {
|
|
4081
|
+
font-family: var(--font-display-ar, Amiri), "Noto Serif Arabic", serif;
|
|
4082
|
+
font-weight: 700;
|
|
4083
|
+
}
|
|
4084
|
+
|
|
4052
4085
|
.chain {
|
|
4053
4086
|
display: inline-flex;
|
|
4054
4087
|
align-items: center;
|
|
@@ -4299,6 +4332,10 @@ var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
|
|
|
4299
4332
|
function charEditorNodeToAstNode(node) {
|
|
4300
4333
|
const font = node.characterFont ?? "default";
|
|
4301
4334
|
const charNode = new CharNode(node.expr);
|
|
4335
|
+
if (node.wrapperCommand) {
|
|
4336
|
+
const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
|
|
4337
|
+
return new CommandNode(wrapper, [], [new ChainNode([charNode])]);
|
|
4338
|
+
}
|
|
4302
4339
|
if (font === "default") {
|
|
4303
4340
|
return charNode;
|
|
4304
4341
|
}
|
|
@@ -4325,6 +4362,9 @@ function cloneChainWithFreshIds(chain) {
|
|
|
4325
4362
|
return structuredClone(chain);
|
|
4326
4363
|
}
|
|
4327
4364
|
function attachScripts(astNode, editorNode) {
|
|
4365
|
+
if (astNode.sourceLatex) {
|
|
4366
|
+
editorNode.sourceLatex = astNode.sourceLatex;
|
|
4367
|
+
}
|
|
4328
4368
|
if (astNode.superscript) {
|
|
4329
4369
|
const sup = chainToEditorChain(astNode.superscript);
|
|
4330
4370
|
if (!sup.editable) {
|
|
@@ -4451,6 +4491,49 @@ function charFromTextLikeCommand(node) {
|
|
|
4451
4491
|
const scripts = attachScripts(node, editorNode);
|
|
4452
4492
|
return scripts ?? { editable: true, node: editorNode };
|
|
4453
4493
|
}
|
|
4494
|
+
function singleCommandChar(node) {
|
|
4495
|
+
if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
|
|
4496
|
+
return null;
|
|
4497
|
+
}
|
|
4498
|
+
const arg = node.mandatoryArgs[0];
|
|
4499
|
+
if (arg.chain.length !== 1 || !(arg.chain[0] instanceof CharNode)) {
|
|
4500
|
+
return null;
|
|
4501
|
+
}
|
|
4502
|
+
return arg.chain[0];
|
|
4503
|
+
}
|
|
4504
|
+
function wrappedAtomicCommandId(node) {
|
|
4505
|
+
if (node.name !== "\\mathbb" && node.name !== "\\mathrm") {
|
|
4506
|
+
return null;
|
|
4507
|
+
}
|
|
4508
|
+
const child = singleCommandChar(node);
|
|
4509
|
+
if (!child) {
|
|
4510
|
+
return null;
|
|
4511
|
+
}
|
|
4512
|
+
return commandIdForTex(`${node.name}{${child.expr}}`);
|
|
4513
|
+
}
|
|
4514
|
+
function editableWrapperCommand(node) {
|
|
4515
|
+
if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
|
|
4516
|
+
return null;
|
|
4517
|
+
}
|
|
4518
|
+
const child = singleCommandChar(node);
|
|
4519
|
+
if (!child) {
|
|
4520
|
+
return null;
|
|
4521
|
+
}
|
|
4522
|
+
const normalized = normalizeCharImportExpr(child.expr);
|
|
4523
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
4524
|
+
if (normalized.characterFont !== "default") {
|
|
4525
|
+
editorNode.characterFont = normalized.characterFont;
|
|
4526
|
+
}
|
|
4527
|
+
editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
|
|
4528
|
+
const scripts = attachScripts(node, editorNode);
|
|
4529
|
+
if (scripts) {
|
|
4530
|
+
return scripts;
|
|
4531
|
+
}
|
|
4532
|
+
if (!editorNode.sourceLatex && node.name === "\\mathsf") {
|
|
4533
|
+
editorNode.sourceLatex = `\\mathsf{${child.expr}}`;
|
|
4534
|
+
}
|
|
4535
|
+
return { editable: true, node: editorNode };
|
|
4536
|
+
}
|
|
4454
4537
|
function commandToEditorNode(node) {
|
|
4455
4538
|
if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
|
|
4456
4539
|
const frac = createFracNode();
|
|
@@ -4540,6 +4623,19 @@ function commandToEditorNode(node) {
|
|
|
4540
4623
|
}
|
|
4541
4624
|
return { editable: true, node: accent };
|
|
4542
4625
|
}
|
|
4626
|
+
const wrappedAtomicId = wrappedAtomicCommandId(node);
|
|
4627
|
+
if (wrappedAtomicId) {
|
|
4628
|
+
const atomic = createEditorNode("atomicCommand", wrappedAtomicId);
|
|
4629
|
+
const scripts = attachScripts(node, atomic);
|
|
4630
|
+
if (scripts) {
|
|
4631
|
+
return scripts;
|
|
4632
|
+
}
|
|
4633
|
+
return { editable: true, node: atomic };
|
|
4634
|
+
}
|
|
4635
|
+
const wrapper = editableWrapperCommand(node);
|
|
4636
|
+
if (wrapper) {
|
|
4637
|
+
return wrapper;
|
|
4638
|
+
}
|
|
4543
4639
|
const atomicId = commandIdForTex(node.name);
|
|
4544
4640
|
if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
4545
4641
|
const atomic = createEditorNode("atomicCommand", atomicId);
|
|
@@ -4819,7 +4915,13 @@ function editorNodeToAstNode(node) {
|
|
|
4819
4915
|
if (!tex) {
|
|
4820
4916
|
return { ok: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
|
|
4821
4917
|
}
|
|
4822
|
-
|
|
4918
|
+
if (node.expr === "ad") {
|
|
4919
|
+
astNode = new CommandNode("\\mathrm", [], [new ChainNode([new CharNode("d")])]);
|
|
4920
|
+
} else if (["N", "Z", "Q", "R", "C", "H"].includes(node.expr)) {
|
|
4921
|
+
astNode = new CommandNode("\\mathbb", [], [new ChainNode([new CharNode(node.expr)])]);
|
|
4922
|
+
} else {
|
|
4923
|
+
astNode = new CommandNode(tex);
|
|
4924
|
+
}
|
|
4823
4925
|
} else if (node.kind === "atomicOperatorCommand") {
|
|
4824
4926
|
const tex = atomicOperatorCommandSpec(node.expr)?.Tex;
|
|
4825
4927
|
if (!tex) {
|
|
@@ -4836,6 +4938,9 @@ function editorNodeToAstNode(node) {
|
|
|
4836
4938
|
} else {
|
|
4837
4939
|
return { ok: false, reason: `\u0639\u0642\u062F\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.kind}` };
|
|
4838
4940
|
}
|
|
4941
|
+
if (node.sourceLatex) {
|
|
4942
|
+
astNode.sourceLatex = node.sourceLatex;
|
|
4943
|
+
}
|
|
4839
4944
|
const scripts = attachAstScripts(node, astNode);
|
|
4840
4945
|
return scripts ?? { ok: true, node: astNode };
|
|
4841
4946
|
}
|