@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,307 @@
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 DocumentParseMode = 'english' | 'arabic';
50
+ type MathObjectJson = {
51
+ node_type: 'MathObject';
52
+ math_mode: string;
53
+ lines: ChainJson[];
54
+ closing: string;
55
+ };
56
+ type DocumentJson = {
57
+ node_type: 'DocumentObject';
58
+ blocks: DocumentBlockJson[];
59
+ };
60
+ type DocumentBlockJson = {
61
+ command: string;
62
+ value?: string;
63
+ math_objects?: MathObjectJson[];
64
+ options?: Record<string, string>;
65
+ closing?: string;
66
+ items?: DocumentListItemJson[];
67
+ rows?: string[][];
68
+ columns?: string;
69
+ };
70
+ type DocumentListItemJson = {
71
+ value: string;
72
+ math_objects?: MathObjectJson[];
73
+ blocks?: DocumentBlockJson[];
74
+ };
75
+ type DocumentCommand = '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph' | '\\begin{itemize}' | '\\begin{enumerate}' | '\\begin{tabular}' | '\\includegraphics' | '\\raw';
76
+ type MathNode = {
77
+ nodeType: 'MathObject';
78
+ mathMode: string;
79
+ lines: ChainNode[];
80
+ closing: string;
81
+ };
82
+ type TextInline = {
83
+ kind: 'text';
84
+ text: string;
85
+ };
86
+ type MathInline = {
87
+ kind: 'math';
88
+ source: string;
89
+ math: MathNode | null;
90
+ };
91
+ type DocumentInline = TextInline | MathInline;
92
+ type TextBlockNode = {
93
+ kind: 'textBlock';
94
+ command: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph';
95
+ value: string;
96
+ inlines: DocumentInline[];
97
+ };
98
+ type ListItemNode = {
99
+ value: string;
100
+ inlines: DocumentInline[];
101
+ blocks: DocumentBlockNode[];
102
+ };
103
+ type ListBlockNode = {
104
+ kind: 'list';
105
+ command: '\\begin{itemize}' | '\\begin{enumerate}';
106
+ closing: '\\end{itemize}' | '\\end{enumerate}';
107
+ items: ListItemNode[];
108
+ };
109
+ type TableBlockNode = {
110
+ kind: 'table';
111
+ command: '\\begin{tabular}';
112
+ closing: '\\end{tabular}';
113
+ columns: string;
114
+ rows: DocumentInline[][][];
115
+ };
116
+ type ImageBlockNode = {
117
+ kind: 'image';
118
+ command: '\\includegraphics';
119
+ value: string;
120
+ options: Record<string, string>;
121
+ };
122
+ type RawBlockNode = {
123
+ kind: 'raw';
124
+ command: '\\raw';
125
+ value: string;
126
+ };
127
+ type DocumentBlockNode = TextBlockNode | ListBlockNode | TableBlockNode | ImageBlockNode | RawBlockNode;
128
+ type DocumentNode = {
129
+ nodeType: 'DocumentObject';
130
+ blocks: DocumentBlockNode[];
131
+ };
132
+ type DetectedMathSpan = {
133
+ start: number;
134
+ end: number;
135
+ source: string;
136
+ mathMode: string;
137
+ closing: string;
138
+ };
139
+ type DocumentPreviewMathIsland = {
140
+ id: string;
141
+ tex: string;
142
+ display: boolean;
143
+ };
144
+ type DocumentPreview = {
145
+ html: string;
146
+ mathIslands: DocumentPreviewMathIsland[];
147
+ };
148
+
149
+ declare function fromDocumentJson(json: unknown, mode?: DocumentParseMode): DocumentNode;
150
+ declare function createEmptyDocument(): DocumentNode;
151
+ declare function createTextBlock(command: TextBlockNode['command'], value?: string): TextBlockNode;
152
+ declare function createRawBlock(value?: string): RawBlockNode;
153
+ declare function createListBlock(command: ListBlockNode['command'], items?: string[]): ListBlockNode;
154
+ declare function createTableBlock(rows?: string[][], columns?: string): TableBlockNode;
155
+ declare function createImageBlock(value?: string, options?: Record<string, string>): ImageBlockNode;
156
+ declare function isSupportedDocumentCommand(command: string): command is DocumentCommand;
157
+
158
+ declare function fromMathObjectJson(json: unknown, mode?: DocumentParseMode): MathNode;
159
+ declare function renderMathNodeLatex(math: MathNode): string;
160
+ declare function isDisplayMathNode(math: MathNode): boolean;
161
+
162
+ type EditorSide = 'english' | 'arabic';
163
+ type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'frac' | 'sqrt' | 'env' | 'atomicCommand' | 'atomicOperatorCommand';
164
+ type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
165
+ type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
166
+ type EnvColumnAlignment = 'l' | 'c' | 'r';
167
+ type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline';
168
+ type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
169
+ type EditorSyncState = 'synced' | 'diverged';
170
+ type EditorChain = {
171
+ id: string;
172
+ nodes: EditorNode[];
173
+ };
174
+ type EditorNode = {
175
+ id: string;
176
+ kind: EditorNodeKind;
177
+ expr: string;
178
+ characterFont?: CharacterFontId;
179
+ superscript: EditorChain | null;
180
+ subscript: EditorChain | null;
181
+ leftDelimExpr: string;
182
+ rightDelimExpr: string;
183
+ innerExpr: EditorChain | null;
184
+ numerator: EditorChain | null;
185
+ denominator: EditorChain | null;
186
+ radicand: EditorChain | null;
187
+ rootIndex: EditorChain | null;
188
+ envName: GridEnvName | null;
189
+ matrixStyle: MatrixEnvStyle | null;
190
+ matrixRows: EditorChain[][] | null;
191
+ columnAlignments: EnvColumnAlignment[] | null;
192
+ };
193
+ type EditorCaret = {
194
+ chainId: string;
195
+ index: number;
196
+ };
197
+ type EditorSelectionRange = {
198
+ chainId: string;
199
+ anchorIndex: number;
200
+ focusIndex: number;
201
+ };
202
+ type EditorSyncMap = Record<string, {
203
+ expr: EditorSyncState;
204
+ }>;
205
+ type EditorDebugEntry = {
206
+ timestamp: string;
207
+ command: string;
208
+ activeSide: EditorSide;
209
+ englishLatex: string;
210
+ arabicLatex: string;
211
+ renderOk: boolean;
212
+ renderError: string | null;
213
+ note: string;
214
+ };
215
+ type EditorSession = {
216
+ englishTree: EditorChain;
217
+ arabicTree: EditorChain;
218
+ activeSide: EditorSide;
219
+ /** When true, each typed letter/digit inserts a new char/number leaf; when false, merge into adjacent same-kind leaves. */
220
+ splitLeafTyping: boolean;
221
+ /** One-shot: when true, the next insertChar/insertNumber bypasses leaf-merge (used by Space in merge mode). */
222
+ forceSplitNextLeaf: boolean;
223
+ /** When true and active side is Arabic, merged number typing prepends digits (RTL-style); still mirrored on EN/AR. */
224
+ arabicReverseNumberTyping: boolean;
225
+ /** Font applied to newly typed char nodes. */
226
+ currentCharacterFont: CharacterFontId;
227
+ /** Digit glyph form used for editor display and LaTeX preview output. */
228
+ currentDigitForm: DigitFormId;
229
+ caret: EditorCaret;
230
+ /** Whole-node range selection inside a single chain (anchor==focus means no selection). */
231
+ selection: EditorSelectionRange | null;
232
+ selectedNodeId: string | null;
233
+ selectedStructureNodeId: string | null;
234
+ sync: EditorSyncMap;
235
+ debugLog: EditorDebugEntry[];
236
+ };
237
+
238
+ type MathNodeFromEditorResult = {
239
+ ok: true;
240
+ math: MathNode;
241
+ } | {
242
+ ok: false;
243
+ reason: string;
244
+ };
245
+ declare function mathNodeFromEditorSession(session: EditorSession, mathMode?: string, closing?: string): MathNodeFromEditorResult;
246
+ /** Delimited Arabic TeX for document text/preview — matches `<ButexEditor />` arabic output. */
247
+ declare function mathSourceFromEditorSession(session: EditorSession, mathMode?: string, closing?: string): string;
248
+
249
+ declare function detectMathSpans(value: string): DetectedMathSpan[];
250
+ declare function buildInlines(value: string, mathObjects?: MathObjectJson[], mode?: DocumentParseMode): DocumentInline[];
251
+
252
+ declare function renderDocumentLatex(document: DocumentNode): string;
253
+ declare function buildDocumentPreview(document: DocumentNode): DocumentPreview;
254
+
255
+ type NewDocumentBlockKind = 'section' | 'subsection' | 'subsubsection' | 'paragraph' | 'itemize' | 'enumerate' | 'table' | 'image' | 'raw';
256
+ type DocumentMathTarget = {
257
+ scope: 'block';
258
+ blockIndex: number;
259
+ spanIndex: number;
260
+ } | {
261
+ scope: 'listItem';
262
+ blockIndex: number;
263
+ itemIndex: number;
264
+ spanIndex: number;
265
+ } | {
266
+ scope: 'tableCell';
267
+ blockIndex: number;
268
+ rowIndex: number;
269
+ columnIndex: number;
270
+ spanIndex: number;
271
+ };
272
+ type DocumentInlineTarget = {
273
+ scope: 'block';
274
+ blockIndex: number;
275
+ } | {
276
+ scope: 'listItem';
277
+ blockIndex: number;
278
+ itemIndex: number;
279
+ } | {
280
+ scope: 'tableCell';
281
+ blockIndex: number;
282
+ rowIndex: number;
283
+ columnIndex: number;
284
+ };
285
+ declare function createDocumentBlock(kind: NewDocumentBlockKind): DocumentBlockNode;
286
+ declare function addDocumentBlock(document: DocumentNode, kind: NewDocumentBlockKind): DocumentNode;
287
+ declare function removeDocumentBlock(document: DocumentNode, blockIndex: number): DocumentNode;
288
+ declare function moveDocumentBlock(document: DocumentNode, blockIndex: number, direction: -1 | 1): DocumentNode;
289
+ declare function updateTextBlockValue(document: DocumentNode, blockIndex: number, value: string): DocumentNode;
290
+ declare function updateRawBlockValue(document: DocumentNode, blockIndex: number, value: string): DocumentNode;
291
+ declare function updateImageBlock(document: DocumentNode, blockIndex: number, value: string, options: Record<string, string>): DocumentNode;
292
+ declare function updateListItemValue(document: DocumentNode, blockIndex: number, itemIndex: number, value: string): DocumentNode;
293
+ declare function addListItem(document: DocumentNode, blockIndex: number): DocumentNode;
294
+ declare function removeListItem(document: DocumentNode, blockIndex: number, itemIndex: number): DocumentNode;
295
+ declare function addNestedListBlock(document: DocumentNode, blockIndex: number, itemIndex: number, kind: 'itemize' | 'enumerate'): DocumentNode;
296
+ declare function updateTableCell(document: DocumentNode, blockIndex: number, rowIndex: number, columnIndex: number, value: string): DocumentNode;
297
+ declare function updateTableColumns(document: DocumentNode, blockIndex: number, columns: string): DocumentNode;
298
+ declare function addTableRow(document: DocumentNode, blockIndex: number): DocumentNode;
299
+ declare function removeTableRow(document: DocumentNode, blockIndex: number): DocumentNode;
300
+ declare function addTableColumn(document: DocumentNode, blockIndex: number): DocumentNode;
301
+ declare function removeTableColumn(document: DocumentNode, blockIndex: number): DocumentNode;
302
+ declare function replaceMathSpanSource(document: DocumentNode, target: DocumentMathTarget, source: string): DocumentNode;
303
+ declare function replaceMathSpanFromEditor(document: DocumentNode, target: DocumentMathTarget, math: MathNode, source?: string): DocumentNode;
304
+ declare function insertMathSpanFromEditor(document: DocumentNode, target: DocumentInlineTarget, insertAt: number, math: MathNode, source?: string): DocumentNode;
305
+ declare function documentInlineText(inlines: DocumentInline[]): string;
306
+
307
+ export { type DetectedMathSpan, type DocumentBlockJson, type DocumentBlockNode, type DocumentCommand, type DocumentInline, type DocumentInlineTarget, type DocumentJson, type DocumentListItemJson, type DocumentMathTarget, type DocumentNode, type DocumentParseMode, type DocumentPreview, type DocumentPreviewMathIsland, type ImageBlockNode, type ListBlockNode, type ListItemNode, type MathInline, type MathNode, type MathObjectJson, type NewDocumentBlockKind, type RawBlockNode, type TableBlockNode, type TextBlockNode, type TextInline, addDocumentBlock, addListItem, addNestedListBlock, addTableColumn, addTableRow, buildDocumentPreview, buildInlines, createDocumentBlock, createEmptyDocument, createImageBlock, createListBlock, createRawBlock, createTableBlock, createTextBlock, detectMathSpans, documentInlineText, fromDocumentJson, fromMathObjectJson, insertMathSpanFromEditor, isDisplayMathNode, isSupportedDocumentCommand, mathNodeFromEditorSession, mathSourceFromEditorSession, moveDocumentBlock, removeDocumentBlock, removeListItem, removeTableColumn, removeTableRow, renderDocumentLatex, renderMathNodeLatex, replaceMathSpanFromEditor, replaceMathSpanSource, updateImageBlock, updateListItemValue, updateRawBlockValue, updateTableCell, updateTableColumns, updateTextBlockValue };