@drghaliasri/butex 3.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.
@@ -0,0 +1,353 @@
1
+ type ArabicNodeJson = {
2
+ node_type: string;
3
+ expr?: string;
4
+ name?: string;
5
+ superscript?: ChainJson | null;
6
+ subscript?: ChainJson | null;
7
+ left_delim_expr?: string;
8
+ right_delim_expr?: string;
9
+ inner_expr?: ChainJson;
10
+ optional_args?: ChainJson[];
11
+ mandatory_args?: ChainJson[];
12
+ opening?: string;
13
+ closing?: string;
14
+ lines?: ChainJson[];
15
+ };
16
+ type ChainJson = {
17
+ node_type: 'ChainClass';
18
+ chain: ArabicNodeJson[];
19
+ };
20
+ declare class State {
21
+ }
22
+ declare class BaseAstNode {
23
+ state: State;
24
+ superscript: ChainNode | null;
25
+ subscript: ChainNode | null;
26
+ nodeType: string;
27
+ constructor(state?: State | null);
28
+ latex(): string;
29
+ arabicLatex(): string;
30
+ toArabicLatex(): string;
31
+ /** Latin-style scripts: `^{...}` and `_{...}` for english_json rendering. */
32
+ latexScripts(): string;
33
+ /**
34
+ * Arabic scripts use \\prescript{sup}{sub}{content} (matches reference Python output).
35
+ * Call with rendered strings for sup/sub chains (may be empty strings).
36
+ */
37
+ arabicLatexScripts(sup: string, sub: string, content: string): string;
38
+ }
39
+ declare class ChainNode {
40
+ chain: BaseAstNode[];
41
+ constructor(chain?: BaseAstNode[]);
42
+ latex(): string;
43
+ toEnglishLatex(): string;
44
+ /** RTL: reverse order relative to Latin chain (see test/ref_tests.txt). */
45
+ arabicLatex(): string;
46
+ toArabicLatex(): string;
47
+ }
48
+
49
+ type MathNode = {
50
+ nodeType: 'MathObject';
51
+ mathMode: string;
52
+ lines: ChainNode[];
53
+ closing: string;
54
+ };
55
+
56
+ type Document2ParseMode = 'english' | 'arabic';
57
+ type Document2MathOutput = 'svg' | 'chtml';
58
+ type MathObject2Json = {
59
+ node_type: 'MathObject';
60
+ math_mode: string;
61
+ lines: ChainJson[];
62
+ closing: string;
63
+ };
64
+ type Document2Json = {
65
+ node_type: 'DocumentObject';
66
+ blocks: Document2BlockJson[];
67
+ };
68
+ type Document2BlockJson = {
69
+ command: string;
70
+ value?: string;
71
+ math_objects?: MathObject2Json[];
72
+ options?: Record<string, string>;
73
+ closing?: string;
74
+ items?: Document2ListItemJson[];
75
+ rows?: string[][];
76
+ columns?: string;
77
+ };
78
+ type Document2ListItemJson = {
79
+ value: string;
80
+ math_objects?: MathObject2Json[];
81
+ blocks?: Document2BlockJson[];
82
+ };
83
+ type Document2Diagnostic = {
84
+ code: string;
85
+ message: string;
86
+ path: string;
87
+ };
88
+ type TextToken2 = {
89
+ id: string;
90
+ kind: 'text';
91
+ text: string;
92
+ };
93
+ type MathToken2 = {
94
+ id: string;
95
+ kind: 'math';
96
+ display: boolean;
97
+ opening: string;
98
+ closing: string;
99
+ source: string;
100
+ math: MathNode | null;
101
+ editable: boolean;
102
+ reason?: string;
103
+ sourceOwner: 'imported-structured' | 'raw' | 'editor';
104
+ };
105
+ type InlineToken2 = TextToken2 | MathToken2;
106
+ type InlineField2 = {
107
+ id: string;
108
+ tokens: InlineToken2[];
109
+ };
110
+ type TextBlock2 = {
111
+ id: string;
112
+ kind: 'textBlock';
113
+ command: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph';
114
+ field: InlineField2;
115
+ };
116
+ type ListItem2 = {
117
+ id: string;
118
+ field: InlineField2;
119
+ blocks: Document2Block[];
120
+ };
121
+ type ListBlock2 = {
122
+ id: string;
123
+ kind: 'list';
124
+ command: '\\begin{itemize}' | '\\begin{enumerate}';
125
+ closing: '\\end{itemize}' | '\\end{enumerate}';
126
+ items: ListItem2[];
127
+ };
128
+ type TableBlock2 = {
129
+ id: string;
130
+ kind: 'table';
131
+ command: '\\begin{tabular}';
132
+ closing: '\\end{tabular}';
133
+ columns: string;
134
+ rows: InlineField2[][];
135
+ };
136
+ type ImageBlock2 = {
137
+ id: string;
138
+ kind: 'image';
139
+ command: '\\includegraphics';
140
+ value: string;
141
+ options: Record<string, string>;
142
+ };
143
+ type RawBlock2 = {
144
+ id: string;
145
+ kind: 'raw';
146
+ command: '\\raw';
147
+ value: string;
148
+ };
149
+ type Document2Block = TextBlock2 | ListBlock2 | TableBlock2 | ImageBlock2 | RawBlock2;
150
+ type Document2Node = {
151
+ nodeType: 'DocumentObject';
152
+ blocks: Document2Block[];
153
+ diagnostics: Document2Diagnostic[];
154
+ };
155
+ type ImportDocument2Options = {
156
+ strict?: boolean;
157
+ mode?: Document2ParseMode;
158
+ };
159
+ type DetectedMathSpan2 = {
160
+ start: number;
161
+ end: number;
162
+ source: string;
163
+ opening: string;
164
+ closing: string;
165
+ display: boolean;
166
+ };
167
+ type PreviewInline2 = {
168
+ kind: 'text';
169
+ text: string;
170
+ } | {
171
+ kind: 'math';
172
+ id: string;
173
+ tex: string;
174
+ display: boolean;
175
+ output: Document2MathOutput;
176
+ editable: boolean;
177
+ };
178
+ type PreviewBlock2 = {
179
+ kind: 'heading';
180
+ id: string;
181
+ level: 1 | 2 | 3;
182
+ inlines: PreviewInline2[];
183
+ } | {
184
+ kind: 'paragraph';
185
+ id: string;
186
+ inlines: PreviewInline2[];
187
+ } | {
188
+ kind: 'list';
189
+ id: string;
190
+ ordered: boolean;
191
+ items: Array<{
192
+ id: string;
193
+ inlines: PreviewInline2[];
194
+ blocks: PreviewBlock2[];
195
+ }>;
196
+ } | {
197
+ kind: 'table';
198
+ id: string;
199
+ rows: PreviewInline2[][][];
200
+ } | {
201
+ kind: 'image';
202
+ id: string;
203
+ src: string;
204
+ options: Record<string, string>;
205
+ }
206
+ /** Preview-only: raw / unknown blocks are omitted from preview until we add proper rendering. */
207
+ | {
208
+ kind: 'omit';
209
+ id: string;
210
+ };
211
+ type MathIsland2 = {
212
+ id: string;
213
+ tex: string;
214
+ display: boolean;
215
+ output: Document2MathOutput;
216
+ editable: boolean;
217
+ };
218
+ type Document2Preview = {
219
+ blocks: PreviewBlock2[];
220
+ mathIslands: MathIsland2[];
221
+ };
222
+
223
+ type EditorSide = 'english' | 'arabic';
224
+ type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'frac' | 'sqrt' | 'env' | 'atomicCommand' | 'atomicOperatorCommand';
225
+ type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
226
+ type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
227
+ type EnvColumnAlignment = 'l' | 'c' | 'r';
228
+ type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline';
229
+ type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
230
+ type EditorSyncState = 'synced' | 'diverged';
231
+ type EditorChain = {
232
+ id: string;
233
+ nodes: EditorNode[];
234
+ };
235
+ type EditorNode = {
236
+ id: string;
237
+ kind: EditorNodeKind;
238
+ expr: string;
239
+ characterFont?: CharacterFontId;
240
+ superscript: EditorChain | null;
241
+ subscript: EditorChain | null;
242
+ leftDelimExpr: string;
243
+ rightDelimExpr: string;
244
+ innerExpr: EditorChain | null;
245
+ numerator: EditorChain | null;
246
+ denominator: EditorChain | null;
247
+ radicand: EditorChain | null;
248
+ rootIndex: EditorChain | null;
249
+ envName: GridEnvName | null;
250
+ matrixStyle: MatrixEnvStyle | null;
251
+ matrixRows: EditorChain[][] | null;
252
+ columnAlignments: EnvColumnAlignment[] | null;
253
+ };
254
+ type EditorCaret = {
255
+ chainId: string;
256
+ index: number;
257
+ };
258
+ type EditorSelectionRange = {
259
+ chainId: string;
260
+ anchorIndex: number;
261
+ focusIndex: number;
262
+ };
263
+ type EditorSyncMap = Record<string, {
264
+ expr: EditorSyncState;
265
+ }>;
266
+ type EditorDebugEntry = {
267
+ timestamp: string;
268
+ command: string;
269
+ activeSide: EditorSide;
270
+ englishLatex: string;
271
+ arabicLatex: string;
272
+ renderOk: boolean;
273
+ renderError: string | null;
274
+ note: string;
275
+ };
276
+ type EditorSession = {
277
+ englishTree: EditorChain;
278
+ arabicTree: EditorChain;
279
+ activeSide: EditorSide;
280
+ /** When true, each typed letter/digit inserts a new char/number leaf; when false, merge into adjacent same-kind leaves. */
281
+ splitLeafTyping: boolean;
282
+ /** One-shot: when true, the next insertChar/insertNumber bypasses leaf-merge (used by Space in merge mode). */
283
+ forceSplitNextLeaf: boolean;
284
+ /** When true and active side is Arabic, merged number typing prepends digits (RTL-style); still mirrored on EN/AR. */
285
+ arabicReverseNumberTyping: boolean;
286
+ /** Font applied to newly typed char nodes. */
287
+ currentCharacterFont: CharacterFontId;
288
+ /** Digit glyph form used for editor display and LaTeX preview output. */
289
+ currentDigitForm: DigitFormId;
290
+ caret: EditorCaret;
291
+ /** Whole-node range selection inside a single chain (anchor==focus means no selection). */
292
+ selection: EditorSelectionRange | null;
293
+ selectedNodeId: string | null;
294
+ selectedStructureNodeId: string | null;
295
+ sync: EditorSyncMap;
296
+ debugLog: EditorDebugEntry[];
297
+ };
298
+
299
+ declare function findFirstInlineField(document: Document2Node): InlineField2 | null;
300
+ declare function updateTextToken(document: Document2Node, fieldId: string, tokenId: string, text: string): Document2Node;
301
+ declare function cloneDocument2Node(document: Document2Node): Document2Node;
302
+ declare function insertDocument2BlockAfter(document: Document2Node, afterBlockId: string | null | undefined, block: Document2Block): Document2Node;
303
+ declare function moveDocument2BlockById(document: Document2Node, blockId: string, direction: -1 | 1): Document2Node;
304
+ declare function removeMathTokenById(document: Document2Node, tokenId: string): Document2Node;
305
+ declare function insertMathTokenAtCaret(document: Document2Node, fieldId: string, textTokenId: string | null, caretOffset: number, session: EditorSession, opening?: string, closing?: string): Document2Node;
306
+ declare function insertMathToken(document: Document2Node, fieldId: string, insertIndex: number, session: EditorSession, opening?: string, closing?: string): Document2Node;
307
+ declare function replaceMathTokenFromSession(document: Document2Node, tokenId: string, session: EditorSession, opening?: string, closing?: string): Document2Node;
308
+ declare function addDocument2TextBlock(document: Document2Node, command?: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph', afterBlockId?: string | null): Document2Node;
309
+ declare function removeDocument2BlockById(document: Document2Node, blockId: string): Document2Node;
310
+ declare function addDocument2ListBlock(document: Document2Node, ordered: boolean, afterBlockId?: string | null): Document2Node;
311
+ declare function addDocument2TableBlock(document: Document2Node, columns?: string, rowCount?: number, colCount?: number, afterBlockId?: string | null): Document2Node;
312
+ declare function addDocument2ImageBlock(document: Document2Node, src?: string, afterBlockId?: string | null): Document2Node;
313
+ declare function updateDocument2ImageValue(document: Document2Node, blockId: string, value: string): Document2Node;
314
+ declare function addDocument2ListItem(document: Document2Node, listBlockId: string): Document2Node;
315
+ declare function removeDocument2ListItem(document: Document2Node, listBlockId: string, itemId: string): Document2Node;
316
+
317
+ declare function inlineFieldLatex(field: InlineField2): string;
318
+ declare function document2Latex(document: Document2Node): string;
319
+
320
+ declare const DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
321
+ type Document2HistoryStacks = {
322
+ past: Document2Node[];
323
+ future: Document2Node[];
324
+ maxDepth: number;
325
+ };
326
+ declare function createDocument2History(maxDepth?: number): Document2HistoryStacks;
327
+ declare function pushDocument2Snapshot(stacks: Document2HistoryStacks, documentBeforeEdit: Document2Node): void;
328
+ declare function restoreDocument2Undo(stacks: Document2HistoryStacks, documentNow: Document2Node): Document2Node | null;
329
+ declare function restoreDocument2Redo(stacks: Document2HistoryStacks, documentNow: Document2Node): Document2Node | null;
330
+ declare function document2HistoryCanUndo(stacks: Document2HistoryStacks): boolean;
331
+ declare function document2HistoryCanRedo(stacks: Document2HistoryStacks): boolean;
332
+
333
+ declare function createInlineField2(value?: string, mathObjects?: MathObject2Json[], options?: ImportDocument2Options, path?: string, diagnostics?: Document2Diagnostic[]): InlineField2;
334
+ declare function fromDocumentJson2(json: unknown, options?: ImportDocument2Options): Document2Node;
335
+ declare function createEmptyDocument2(): Document2Node;
336
+
337
+ declare function detectMathSpans2(value: string): DetectedMathSpan2[];
338
+
339
+ type Document2MathBridgeResult = {
340
+ editable: true;
341
+ session: EditorSession;
342
+ } | {
343
+ editable: false;
344
+ reason: string;
345
+ };
346
+ declare function createEmptyArabicEquationSession(): EditorSession;
347
+ declare function mathTokenToArabicEditorSession(math: MathNode | null): Document2MathBridgeResult;
348
+ declare function mathSourceFromArabicSession(session: EditorSession, opening?: string, closing?: string): string;
349
+ declare function mathNodeFromArabicSession(session: EditorSession, opening?: string, closing?: string): MathNode;
350
+
351
+ declare function document2Preview(document: Document2Node, output?: Document2MathOutput): Document2Preview;
352
+
353
+ export { DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH, type Document2Block, type Document2BlockJson, type Document2Diagnostic, type Document2HistoryStacks, type Document2Json, type Document2MathOutput, type Document2Node, type ImageBlock2, type ImportDocument2Options, type InlineField2, type InlineToken2, type ListBlock2, type MathIsland2, type MathObject2Json, type MathToken2, type PreviewBlock2, type PreviewInline2, type RawBlock2, type TableBlock2, type TextBlock2, type TextToken2, addDocument2ImageBlock, addDocument2ListBlock, addDocument2ListItem, addDocument2TableBlock, addDocument2TextBlock, cloneDocument2Node, createDocument2History, createEmptyArabicEquationSession, createEmptyDocument2, createInlineField2, detectMathSpans2, document2HistoryCanRedo, document2HistoryCanUndo, document2Latex, document2Preview, findFirstInlineField, fromDocumentJson2, inlineFieldLatex, insertDocument2BlockAfter, insertMathToken, insertMathTokenAtCaret, mathNodeFromArabicSession, mathSourceFromArabicSession, mathTokenToArabicEditorSession, moveDocument2BlockById, pushDocument2Snapshot, removeDocument2BlockById, removeDocument2ListItem, removeMathTokenById, replaceMathTokenFromSession, restoreDocument2Redo, restoreDocument2Undo, updateDocument2ImageValue, updateTextToken };
@@ -0,0 +1,353 @@
1
+ type ArabicNodeJson = {
2
+ node_type: string;
3
+ expr?: string;
4
+ name?: string;
5
+ superscript?: ChainJson | null;
6
+ subscript?: ChainJson | null;
7
+ left_delim_expr?: string;
8
+ right_delim_expr?: string;
9
+ inner_expr?: ChainJson;
10
+ optional_args?: ChainJson[];
11
+ mandatory_args?: ChainJson[];
12
+ opening?: string;
13
+ closing?: string;
14
+ lines?: ChainJson[];
15
+ };
16
+ type ChainJson = {
17
+ node_type: 'ChainClass';
18
+ chain: ArabicNodeJson[];
19
+ };
20
+ declare class State {
21
+ }
22
+ declare class BaseAstNode {
23
+ state: State;
24
+ superscript: ChainNode | null;
25
+ subscript: ChainNode | null;
26
+ nodeType: string;
27
+ constructor(state?: State | null);
28
+ latex(): string;
29
+ arabicLatex(): string;
30
+ toArabicLatex(): string;
31
+ /** Latin-style scripts: `^{...}` and `_{...}` for english_json rendering. */
32
+ latexScripts(): string;
33
+ /**
34
+ * Arabic scripts use \\prescript{sup}{sub}{content} (matches reference Python output).
35
+ * Call with rendered strings for sup/sub chains (may be empty strings).
36
+ */
37
+ arabicLatexScripts(sup: string, sub: string, content: string): string;
38
+ }
39
+ declare class ChainNode {
40
+ chain: BaseAstNode[];
41
+ constructor(chain?: BaseAstNode[]);
42
+ latex(): string;
43
+ toEnglishLatex(): string;
44
+ /** RTL: reverse order relative to Latin chain (see test/ref_tests.txt). */
45
+ arabicLatex(): string;
46
+ toArabicLatex(): string;
47
+ }
48
+
49
+ type MathNode = {
50
+ nodeType: 'MathObject';
51
+ mathMode: string;
52
+ lines: ChainNode[];
53
+ closing: string;
54
+ };
55
+
56
+ type Document2ParseMode = 'english' | 'arabic';
57
+ type Document2MathOutput = 'svg' | 'chtml';
58
+ type MathObject2Json = {
59
+ node_type: 'MathObject';
60
+ math_mode: string;
61
+ lines: ChainJson[];
62
+ closing: string;
63
+ };
64
+ type Document2Json = {
65
+ node_type: 'DocumentObject';
66
+ blocks: Document2BlockJson[];
67
+ };
68
+ type Document2BlockJson = {
69
+ command: string;
70
+ value?: string;
71
+ math_objects?: MathObject2Json[];
72
+ options?: Record<string, string>;
73
+ closing?: string;
74
+ items?: Document2ListItemJson[];
75
+ rows?: string[][];
76
+ columns?: string;
77
+ };
78
+ type Document2ListItemJson = {
79
+ value: string;
80
+ math_objects?: MathObject2Json[];
81
+ blocks?: Document2BlockJson[];
82
+ };
83
+ type Document2Diagnostic = {
84
+ code: string;
85
+ message: string;
86
+ path: string;
87
+ };
88
+ type TextToken2 = {
89
+ id: string;
90
+ kind: 'text';
91
+ text: string;
92
+ };
93
+ type MathToken2 = {
94
+ id: string;
95
+ kind: 'math';
96
+ display: boolean;
97
+ opening: string;
98
+ closing: string;
99
+ source: string;
100
+ math: MathNode | null;
101
+ editable: boolean;
102
+ reason?: string;
103
+ sourceOwner: 'imported-structured' | 'raw' | 'editor';
104
+ };
105
+ type InlineToken2 = TextToken2 | MathToken2;
106
+ type InlineField2 = {
107
+ id: string;
108
+ tokens: InlineToken2[];
109
+ };
110
+ type TextBlock2 = {
111
+ id: string;
112
+ kind: 'textBlock';
113
+ command: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph';
114
+ field: InlineField2;
115
+ };
116
+ type ListItem2 = {
117
+ id: string;
118
+ field: InlineField2;
119
+ blocks: Document2Block[];
120
+ };
121
+ type ListBlock2 = {
122
+ id: string;
123
+ kind: 'list';
124
+ command: '\\begin{itemize}' | '\\begin{enumerate}';
125
+ closing: '\\end{itemize}' | '\\end{enumerate}';
126
+ items: ListItem2[];
127
+ };
128
+ type TableBlock2 = {
129
+ id: string;
130
+ kind: 'table';
131
+ command: '\\begin{tabular}';
132
+ closing: '\\end{tabular}';
133
+ columns: string;
134
+ rows: InlineField2[][];
135
+ };
136
+ type ImageBlock2 = {
137
+ id: string;
138
+ kind: 'image';
139
+ command: '\\includegraphics';
140
+ value: string;
141
+ options: Record<string, string>;
142
+ };
143
+ type RawBlock2 = {
144
+ id: string;
145
+ kind: 'raw';
146
+ command: '\\raw';
147
+ value: string;
148
+ };
149
+ type Document2Block = TextBlock2 | ListBlock2 | TableBlock2 | ImageBlock2 | RawBlock2;
150
+ type Document2Node = {
151
+ nodeType: 'DocumentObject';
152
+ blocks: Document2Block[];
153
+ diagnostics: Document2Diagnostic[];
154
+ };
155
+ type ImportDocument2Options = {
156
+ strict?: boolean;
157
+ mode?: Document2ParseMode;
158
+ };
159
+ type DetectedMathSpan2 = {
160
+ start: number;
161
+ end: number;
162
+ source: string;
163
+ opening: string;
164
+ closing: string;
165
+ display: boolean;
166
+ };
167
+ type PreviewInline2 = {
168
+ kind: 'text';
169
+ text: string;
170
+ } | {
171
+ kind: 'math';
172
+ id: string;
173
+ tex: string;
174
+ display: boolean;
175
+ output: Document2MathOutput;
176
+ editable: boolean;
177
+ };
178
+ type PreviewBlock2 = {
179
+ kind: 'heading';
180
+ id: string;
181
+ level: 1 | 2 | 3;
182
+ inlines: PreviewInline2[];
183
+ } | {
184
+ kind: 'paragraph';
185
+ id: string;
186
+ inlines: PreviewInline2[];
187
+ } | {
188
+ kind: 'list';
189
+ id: string;
190
+ ordered: boolean;
191
+ items: Array<{
192
+ id: string;
193
+ inlines: PreviewInline2[];
194
+ blocks: PreviewBlock2[];
195
+ }>;
196
+ } | {
197
+ kind: 'table';
198
+ id: string;
199
+ rows: PreviewInline2[][][];
200
+ } | {
201
+ kind: 'image';
202
+ id: string;
203
+ src: string;
204
+ options: Record<string, string>;
205
+ }
206
+ /** Preview-only: raw / unknown blocks are omitted from preview until we add proper rendering. */
207
+ | {
208
+ kind: 'omit';
209
+ id: string;
210
+ };
211
+ type MathIsland2 = {
212
+ id: string;
213
+ tex: string;
214
+ display: boolean;
215
+ output: Document2MathOutput;
216
+ editable: boolean;
217
+ };
218
+ type Document2Preview = {
219
+ blocks: PreviewBlock2[];
220
+ mathIslands: MathIsland2[];
221
+ };
222
+
223
+ type EditorSide = 'english' | 'arabic';
224
+ type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'frac' | 'sqrt' | 'env' | 'atomicCommand' | 'atomicOperatorCommand';
225
+ type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
226
+ type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
227
+ type EnvColumnAlignment = 'l' | 'c' | 'r';
228
+ type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline';
229
+ type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
230
+ type EditorSyncState = 'synced' | 'diverged';
231
+ type EditorChain = {
232
+ id: string;
233
+ nodes: EditorNode[];
234
+ };
235
+ type EditorNode = {
236
+ id: string;
237
+ kind: EditorNodeKind;
238
+ expr: string;
239
+ characterFont?: CharacterFontId;
240
+ superscript: EditorChain | null;
241
+ subscript: EditorChain | null;
242
+ leftDelimExpr: string;
243
+ rightDelimExpr: string;
244
+ innerExpr: EditorChain | null;
245
+ numerator: EditorChain | null;
246
+ denominator: EditorChain | null;
247
+ radicand: EditorChain | null;
248
+ rootIndex: EditorChain | null;
249
+ envName: GridEnvName | null;
250
+ matrixStyle: MatrixEnvStyle | null;
251
+ matrixRows: EditorChain[][] | null;
252
+ columnAlignments: EnvColumnAlignment[] | null;
253
+ };
254
+ type EditorCaret = {
255
+ chainId: string;
256
+ index: number;
257
+ };
258
+ type EditorSelectionRange = {
259
+ chainId: string;
260
+ anchorIndex: number;
261
+ focusIndex: number;
262
+ };
263
+ type EditorSyncMap = Record<string, {
264
+ expr: EditorSyncState;
265
+ }>;
266
+ type EditorDebugEntry = {
267
+ timestamp: string;
268
+ command: string;
269
+ activeSide: EditorSide;
270
+ englishLatex: string;
271
+ arabicLatex: string;
272
+ renderOk: boolean;
273
+ renderError: string | null;
274
+ note: string;
275
+ };
276
+ type EditorSession = {
277
+ englishTree: EditorChain;
278
+ arabicTree: EditorChain;
279
+ activeSide: EditorSide;
280
+ /** When true, each typed letter/digit inserts a new char/number leaf; when false, merge into adjacent same-kind leaves. */
281
+ splitLeafTyping: boolean;
282
+ /** One-shot: when true, the next insertChar/insertNumber bypasses leaf-merge (used by Space in merge mode). */
283
+ forceSplitNextLeaf: boolean;
284
+ /** When true and active side is Arabic, merged number typing prepends digits (RTL-style); still mirrored on EN/AR. */
285
+ arabicReverseNumberTyping: boolean;
286
+ /** Font applied to newly typed char nodes. */
287
+ currentCharacterFont: CharacterFontId;
288
+ /** Digit glyph form used for editor display and LaTeX preview output. */
289
+ currentDigitForm: DigitFormId;
290
+ caret: EditorCaret;
291
+ /** Whole-node range selection inside a single chain (anchor==focus means no selection). */
292
+ selection: EditorSelectionRange | null;
293
+ selectedNodeId: string | null;
294
+ selectedStructureNodeId: string | null;
295
+ sync: EditorSyncMap;
296
+ debugLog: EditorDebugEntry[];
297
+ };
298
+
299
+ declare function findFirstInlineField(document: Document2Node): InlineField2 | null;
300
+ declare function updateTextToken(document: Document2Node, fieldId: string, tokenId: string, text: string): Document2Node;
301
+ declare function cloneDocument2Node(document: Document2Node): Document2Node;
302
+ declare function insertDocument2BlockAfter(document: Document2Node, afterBlockId: string | null | undefined, block: Document2Block): Document2Node;
303
+ declare function moveDocument2BlockById(document: Document2Node, blockId: string, direction: -1 | 1): Document2Node;
304
+ declare function removeMathTokenById(document: Document2Node, tokenId: string): Document2Node;
305
+ declare function insertMathTokenAtCaret(document: Document2Node, fieldId: string, textTokenId: string | null, caretOffset: number, session: EditorSession, opening?: string, closing?: string): Document2Node;
306
+ declare function insertMathToken(document: Document2Node, fieldId: string, insertIndex: number, session: EditorSession, opening?: string, closing?: string): Document2Node;
307
+ declare function replaceMathTokenFromSession(document: Document2Node, tokenId: string, session: EditorSession, opening?: string, closing?: string): Document2Node;
308
+ declare function addDocument2TextBlock(document: Document2Node, command?: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph', afterBlockId?: string | null): Document2Node;
309
+ declare function removeDocument2BlockById(document: Document2Node, blockId: string): Document2Node;
310
+ declare function addDocument2ListBlock(document: Document2Node, ordered: boolean, afterBlockId?: string | null): Document2Node;
311
+ declare function addDocument2TableBlock(document: Document2Node, columns?: string, rowCount?: number, colCount?: number, afterBlockId?: string | null): Document2Node;
312
+ declare function addDocument2ImageBlock(document: Document2Node, src?: string, afterBlockId?: string | null): Document2Node;
313
+ declare function updateDocument2ImageValue(document: Document2Node, blockId: string, value: string): Document2Node;
314
+ declare function addDocument2ListItem(document: Document2Node, listBlockId: string): Document2Node;
315
+ declare function removeDocument2ListItem(document: Document2Node, listBlockId: string, itemId: string): Document2Node;
316
+
317
+ declare function inlineFieldLatex(field: InlineField2): string;
318
+ declare function document2Latex(document: Document2Node): string;
319
+
320
+ declare const DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
321
+ type Document2HistoryStacks = {
322
+ past: Document2Node[];
323
+ future: Document2Node[];
324
+ maxDepth: number;
325
+ };
326
+ declare function createDocument2History(maxDepth?: number): Document2HistoryStacks;
327
+ declare function pushDocument2Snapshot(stacks: Document2HistoryStacks, documentBeforeEdit: Document2Node): void;
328
+ declare function restoreDocument2Undo(stacks: Document2HistoryStacks, documentNow: Document2Node): Document2Node | null;
329
+ declare function restoreDocument2Redo(stacks: Document2HistoryStacks, documentNow: Document2Node): Document2Node | null;
330
+ declare function document2HistoryCanUndo(stacks: Document2HistoryStacks): boolean;
331
+ declare function document2HistoryCanRedo(stacks: Document2HistoryStacks): boolean;
332
+
333
+ declare function createInlineField2(value?: string, mathObjects?: MathObject2Json[], options?: ImportDocument2Options, path?: string, diagnostics?: Document2Diagnostic[]): InlineField2;
334
+ declare function fromDocumentJson2(json: unknown, options?: ImportDocument2Options): Document2Node;
335
+ declare function createEmptyDocument2(): Document2Node;
336
+
337
+ declare function detectMathSpans2(value: string): DetectedMathSpan2[];
338
+
339
+ type Document2MathBridgeResult = {
340
+ editable: true;
341
+ session: EditorSession;
342
+ } | {
343
+ editable: false;
344
+ reason: string;
345
+ };
346
+ declare function createEmptyArabicEquationSession(): EditorSession;
347
+ declare function mathTokenToArabicEditorSession(math: MathNode | null): Document2MathBridgeResult;
348
+ declare function mathSourceFromArabicSession(session: EditorSession, opening?: string, closing?: string): string;
349
+ declare function mathNodeFromArabicSession(session: EditorSession, opening?: string, closing?: string): MathNode;
350
+
351
+ declare function document2Preview(document: Document2Node, output?: Document2MathOutput): Document2Preview;
352
+
353
+ export { DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH, type Document2Block, type Document2BlockJson, type Document2Diagnostic, type Document2HistoryStacks, type Document2Json, type Document2MathOutput, type Document2Node, type ImageBlock2, type ImportDocument2Options, type InlineField2, type InlineToken2, type ListBlock2, type MathIsland2, type MathObject2Json, type MathToken2, type PreviewBlock2, type PreviewInline2, type RawBlock2, type TableBlock2, type TextBlock2, type TextToken2, addDocument2ImageBlock, addDocument2ListBlock, addDocument2ListItem, addDocument2TableBlock, addDocument2TextBlock, cloneDocument2Node, createDocument2History, createEmptyArabicEquationSession, createEmptyDocument2, createInlineField2, detectMathSpans2, document2HistoryCanRedo, document2HistoryCanUndo, document2Latex, document2Preview, findFirstInlineField, fromDocumentJson2, inlineFieldLatex, insertDocument2BlockAfter, insertMathToken, insertMathTokenAtCaret, mathNodeFromArabicSession, mathSourceFromArabicSession, mathTokenToArabicEditorSession, moveDocument2BlockById, pushDocument2Snapshot, removeDocument2BlockById, removeDocument2ListItem, removeMathTokenById, replaceMathTokenFromSession, restoreDocument2Redo, restoreDocument2Undo, updateDocument2ImageValue, updateTextToken };