@drghaliasri/butex 7.4.2 → 8.0.1

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.
Files changed (53) hide show
  1. package/README.md +49 -553
  2. package/dist/{document2-cli.js → document-cli.js} +419 -348
  3. package/dist/document-cli.js.map +1 -0
  4. package/dist/document.d.mts +1022 -186
  5. package/dist/document.d.ts +1022 -186
  6. package/dist/document.js +6103 -652
  7. package/dist/document.js.map +1 -1
  8. package/dist/document.mjs +5963 -612
  9. package/dist/document.mjs.map +1 -1
  10. package/dist/index.d.mts +12 -0
  11. package/dist/index.d.ts +12 -0
  12. package/dist/index.global.js +14 -0
  13. package/dist/index.global.js.map +1 -1
  14. package/dist/index.js +14 -0
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +14 -0
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/react-document-preview.d.mts +338 -0
  19. package/dist/react-document-preview.d.ts +338 -0
  20. package/dist/{react-document2-preview.js → react-document-preview.js} +811 -791
  21. package/dist/react-document-preview.js.map +1 -0
  22. package/dist/{react-document2-preview.mjs → react-document-preview.mjs} +804 -784
  23. package/dist/react-document-preview.mjs.map +1 -0
  24. package/dist/react-document.d.mts +634 -35
  25. package/dist/react-document.d.ts +634 -35
  26. package/dist/react-document.js +13540 -4542
  27. package/dist/react-document.js.map +1 -1
  28. package/dist/react-document.mjs +13536 -4546
  29. package/dist/react-document.mjs.map +1 -1
  30. package/dist/react.d.mts +12 -0
  31. package/dist/react.d.ts +12 -0
  32. package/dist/react.js +33 -12
  33. package/dist/react.js.map +1 -1
  34. package/dist/react.mjs +33 -12
  35. package/dist/react.mjs.map +1 -1
  36. package/package.json +7 -17
  37. package/dist/document2-cli.js.map +0 -1
  38. package/dist/document2.d.mts +0 -1156
  39. package/dist/document2.d.ts +0 -1156
  40. package/dist/document2.js +0 -9137
  41. package/dist/document2.js.map +0 -1
  42. package/dist/document2.mjs +0 -8972
  43. package/dist/document2.mjs.map +0 -1
  44. package/dist/react-document2-preview.d.mts +0 -338
  45. package/dist/react-document2-preview.d.ts +0 -338
  46. package/dist/react-document2-preview.js.map +0 -1
  47. package/dist/react-document2-preview.mjs.map +0 -1
  48. package/dist/react-document2.d.mts +0 -754
  49. package/dist/react-document2.d.ts +0 -754
  50. package/dist/react-document2.js +0 -23011
  51. package/dist/react-document2.js.map +0 -1
  52. package/dist/react-document2.mjs +0 -22981
  53. package/dist/react-document2.mjs.map +0 -1
@@ -1,1156 +0,0 @@
1
- type EditorSide = 'english' | 'arabic';
2
- type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'boxed' | 'frac' | 'sqrt' | 'overset' | 'underset' | 'accent' | 'env' | 'atomicCommand' | 'atomicOperatorCommand' | 'standardCommand';
3
- type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
4
- type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
5
- type EnvColumnAlignment = 'l' | 'c' | 'r';
6
- type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline' | 'maghribi';
7
- type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
8
- type EditorSyncState = 'synced' | 'diverged';
9
- type EditorChain = {
10
- id: string;
11
- nodes: EditorNode[];
12
- /** Complete script authored as \\mathnormal{ordered,index,atoms}. */
13
- indexSequence?: boolean;
14
- };
15
- type EditorNode = {
16
- id: string;
17
- kind: EditorNodeKind;
18
- expr: string;
19
- characterFont?: CharacterFontId;
20
- /** Minimal upstream source identity used only while the node remains unchanged. */
21
- sourceLatex?: string;
22
- /** Existing editor node reused for wrapper commands that need editable content. */
23
- wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
24
- superscript: EditorChain | null;
25
- subscript: EditorChain | null;
26
- leftDelimExpr: string;
27
- rightDelimExpr: string;
28
- innerExpr: EditorChain | null;
29
- numerator: EditorChain | null;
30
- denominator: EditorChain | null;
31
- radicand: EditorChain | null;
32
- rootIndex: EditorChain | null;
33
- overExpr: EditorChain | null;
34
- underExpr: EditorChain | null;
35
- baseExpr: EditorChain | null;
36
- envName: GridEnvName | null;
37
- matrixStyle: MatrixEnvStyle | null;
38
- matrixRows: EditorChain[][] | null;
39
- columnAlignments: EnvColumnAlignment[] | null;
40
- };
41
- type EditorCaret = {
42
- chainId: string;
43
- index: number;
44
- };
45
- type EditorSelectionRange = {
46
- chainId: string;
47
- anchorIndex: number;
48
- focusIndex: number;
49
- };
50
- type EditorSyncMap = Record<string, {
51
- expr: EditorSyncState;
52
- }>;
53
- type EditorDebugEntry = {
54
- timestamp: string;
55
- command: string;
56
- activeSide: EditorSide;
57
- englishLatex: string;
58
- arabicLatex: string;
59
- renderOk: boolean;
60
- renderError: string | null;
61
- note: string;
62
- };
63
- type EditorSession = {
64
- englishTree: EditorChain;
65
- arabicTree: EditorChain;
66
- activeSide: EditorSide;
67
- /** When true, each typed letter/digit inserts a new char/number leaf; when false, merge into adjacent same-kind leaves. */
68
- splitLeafTyping: boolean;
69
- /** One-shot: when true, the next insertChar/insertNumber bypasses leaf-merge (used by Space in merge mode). */
70
- forceSplitNextLeaf: boolean;
71
- /** When true and active side is Arabic, merged number typing prepends digits (RTL-style); still mirrored on EN/AR. */
72
- arabicReverseNumberTyping: boolean;
73
- /** Font applied to newly typed char nodes. */
74
- currentCharacterFont: CharacterFontId;
75
- /** Structured command wrapper applied to newly typed chars; kept separate from fonts. */
76
- currentCharacterWrapper: '\\boldarabic' | null;
77
- /** Digit glyph form used for editor display and LaTeX preview output. */
78
- currentDigitForm: DigitFormId;
79
- caret: EditorCaret;
80
- /** Whole-node range selection inside a single chain (anchor==focus means no selection). */
81
- selection: EditorSelectionRange | null;
82
- selectedNodeId: string | null;
83
- selectedStructureNodeId: string | null;
84
- sync: EditorSyncMap;
85
- debugLog: EditorDebugEntry[];
86
- };
87
-
88
- type ButexUiLocale = 'ar' | 'en';
89
-
90
- type ArabicNodeJson = {
91
- node_type: string;
92
- expr?: string;
93
- name?: string;
94
- superscript?: ChainJson | null;
95
- subscript?: ChainJson | null;
96
- left_delim_expr?: string;
97
- right_delim_expr?: string;
98
- inner_expr?: ChainJson;
99
- optional_args?: ChainJson[];
100
- mandatory_args?: ChainJson[];
101
- opening?: string;
102
- closing?: string;
103
- lines?: ChainJson[];
104
- source_latex?: string;
105
- };
106
- type ChainJson = {
107
- node_type: 'ChainClass';
108
- chain: ArabicNodeJson[];
109
- };
110
- declare class State {
111
- }
112
- declare class BaseAstNode {
113
- state: State;
114
- superscript: ChainNode | null;
115
- subscript: ChainNode | null;
116
- nodeType: string;
117
- sourceLatex: string | null;
118
- constructor(state?: State | null);
119
- latex(): string;
120
- arabicLatex(): string;
121
- toArabicLatex(): string;
122
- /** Latin-style scripts: `^{...}` and `_{...}` for english_json rendering. */
123
- latexScripts(): string;
124
- /**
125
- * Arabic scripts use \\prescript{sup}{sub}{content} (matches reference Python output).
126
- * Call with rendered strings for sup/sub chains (may be empty strings).
127
- */
128
- arabicLatexScripts(sup: string, sub: string, content: string): string;
129
- }
130
- declare class ChainNode {
131
- chain: BaseAstNode[];
132
- constructor(chain?: BaseAstNode[]);
133
- latex(): string;
134
- toEnglishLatex(): string;
135
- /** RTL: reverse order relative to Latin chain (see test/ref_tests.txt). */
136
- arabicLatex(): string;
137
- toArabicLatex(): string;
138
- }
139
-
140
- type MathNode = {
141
- nodeType: 'MathObject';
142
- mathMode: string;
143
- lines: ChainNode[];
144
- closing: string;
145
- };
146
-
147
- type Document2ParseMode = 'english' | 'arabic';
148
- type Document2MathOutput = 'svg' | 'chtml';
149
- type Document2Direction = 'rtl' | 'ltr';
150
- type MathObject2Json = {
151
- node_type: 'MathObject';
152
- math_mode: string;
153
- lines: ChainJson[];
154
- closing: string;
155
- /** Side used by the delimited source stored in the containing value/cell. */
156
- source_side?: Document2ParseMode;
157
- /** Preserve whether LaTeX export should prefer imported AST rendering or editor source. */
158
- source_owner?: 'imported-structured' | 'editor';
159
- label_enabled?: boolean;
160
- label?: string;
161
- };
162
- /** Positional metadata for a raw-only span that has no structured equation AST. */
163
- type RawMathObject2Json = {
164
- node_type: 'RawMathObject';
165
- label_enabled?: boolean;
166
- label?: string;
167
- };
168
- type Document2MathObjectJson = MathObject2Json | RawMathObject2Json;
169
- type ReferenceFieldSeparator = ',' | '،';
170
- type Reference2Json = {
171
- key: string;
172
- authors?: string;
173
- title?: string;
174
- year?: string;
175
- url?: string;
176
- venue?: string;
177
- /** Bibliography field join: LTR `,` or Arabic `،`. Defaults to `،` when omitted. */
178
- field_separator?: ReferenceFieldSeparator;
179
- };
180
- type HijriMonthId = 'محرم' | 'صفر' | 'ربيع الأول' | 'ربيع الآخر' | 'جمادى الأولى' | 'جمادى الآخرة' | 'رجب' | 'شعبان' | 'رمضان' | 'شوال' | 'ذو القعدة' | 'ذو الحجة';
181
- type Document2HijriDate = {
182
- day: number;
183
- month: HijriMonthId;
184
- year: number;
185
- };
186
- type Document2Meta = {
187
- title: string;
188
- authors: string;
189
- date: Document2HijriDate;
190
- abstract: string;
191
- };
192
- type Document2Json = {
193
- node_type: 'DocumentObject';
194
- meta?: Document2Meta;
195
- references?: Reference2Json[];
196
- blocks: Document2BlockJson[];
197
- };
198
- type Document2InlineTokenIdJson = {
199
- id: string;
200
- kind: InlineToken2['kind'];
201
- start: number;
202
- end: number;
203
- };
204
- type Document2InlineIdsJson = {
205
- field_id: string;
206
- tokens: Document2InlineTokenIdJson[];
207
- };
208
- type Document2BlockMetadata = {
209
- source?: 'agent' | 'user';
210
- };
211
- type Document2BlockJson = {
212
- /** Stable identity used by headless commands. Legacy JSON may omit it. */
213
- id?: string;
214
- command: string;
215
- value?: string;
216
- formats?: TextFormatSpan2Json[];
217
- inline_ids?: Document2InlineIdsJson;
218
- metadata?: Document2BlockMetadata;
219
- /** Stable host asset identity (e.g. S3 key / UUID); optional for \\includegraphics. */
220
- asset_id?: string;
221
- math_objects?: Array<Document2MathObjectJson | null>;
222
- options?: Record<string, string>;
223
- closing?: string;
224
- items?: Document2ListItemJson[];
225
- rows?: string[][];
226
- cell_formats?: TextFormatSpan2Json[][][];
227
- cell_inline_ids?: Document2InlineIdsJson[][];
228
- columns?: string;
229
- caption?: string;
230
- /** Optional formatting sidecar for caption text spans. */
231
- caption_formats?: TextFormatSpan2Json[];
232
- /** Stable caption field/token identities; omitted by legacy documents. */
233
- caption_inline_ids?: Document2InlineIdsJson;
234
- /** Caption-only structured math sidecar, independent from table cell math_objects. */
235
- caption_math_objects?: Array<Document2MathObjectJson | null>;
236
- label?: string;
237
- caption_enabled?: boolean;
238
- label_enabled?: boolean;
239
- centered?: boolean;
240
- };
241
- type Document2ListItemJson = {
242
- id?: string;
243
- value: string;
244
- formats?: TextFormatSpan2Json[];
245
- inline_ids?: Document2InlineIdsJson;
246
- math_objects?: Array<Document2MathObjectJson | null>;
247
- blocks?: Document2BlockJson[];
248
- };
249
- type Document2Diagnostic = {
250
- code: string;
251
- message: string;
252
- path: string;
253
- };
254
- type Reference2 = {
255
- id: string;
256
- key: string;
257
- authors: string;
258
- title: string;
259
- year: string;
260
- url: string;
261
- venue: string;
262
- /** Joins authors/title/venue/year in bibliography display and export. */
263
- fieldSeparator: ReferenceFieldSeparator;
264
- };
265
- type TextStyle2 = {
266
- bold?: true;
267
- italic?: true;
268
- underline?: true;
269
- };
270
- type TextFormatSpan2Json = {
271
- start: number;
272
- end: number;
273
- bold?: boolean;
274
- italic?: boolean;
275
- underline?: boolean;
276
- };
277
- type TextToken2 = {
278
- id: string;
279
- kind: 'text';
280
- text: string;
281
- style?: TextStyle2;
282
- };
283
- type MathToken2 = {
284
- id: string;
285
- kind: 'math';
286
- display: boolean;
287
- opening: string;
288
- closing: string;
289
- source: string;
290
- sourceSide?: Document2ParseMode;
291
- math: MathNode | null;
292
- editable: boolean;
293
- reason?: string;
294
- sourceOwner: 'imported-structured' | 'raw' | 'editor';
295
- /** When true on display math, export as equation env with \\label. */
296
- labelEnabled?: boolean;
297
- label?: string;
298
- };
299
- type CiteToken2 = {
300
- id: string;
301
- kind: 'cite';
302
- keys: string[];
303
- };
304
- type RefToken2 = {
305
- id: string;
306
- kind: 'ref';
307
- keys: string[];
308
- refCommand: 'ref' | 'eqref';
309
- };
310
- type InlineToken2 = TextToken2 | MathToken2 | CiteToken2 | RefToken2;
311
- type InlineField2 = {
312
- id: string;
313
- tokens: InlineToken2[];
314
- };
315
- type TextBlock2 = {
316
- id: string;
317
- kind: 'textBlock';
318
- command: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph';
319
- field: InlineField2;
320
- metadata?: Document2BlockMetadata;
321
- /** When true on \\paragraph, center in preview and LaTeX export. */
322
- centered?: boolean;
323
- };
324
- type ListItem2 = {
325
- id: string;
326
- field: InlineField2;
327
- blocks: Document2Block[];
328
- };
329
- type ListBlock2 = {
330
- id: string;
331
- kind: 'list';
332
- command: '\\begin{itemize}' | '\\begin{enumerate}';
333
- closing: '\\end{itemize}' | '\\end{enumerate}';
334
- items: ListItem2[];
335
- metadata?: Document2BlockMetadata;
336
- };
337
- type FloatMeta2 = {
338
- centered: boolean;
339
- captionEnabled: boolean;
340
- /** Compatibility source string; captionField is the structured source of truth. */
341
- caption: string;
342
- /** Stable inline field used by the editor, commands, preview, and persistence. */
343
- captionField: InlineField2;
344
- labelEnabled: boolean;
345
- label: string;
346
- };
347
- type TableBlock2 = {
348
- id: string;
349
- kind: 'table';
350
- command: '\\begin{tabular}';
351
- closing: '\\end{tabular}';
352
- columns: string;
353
- rows: InlineField2[][];
354
- metadata?: Document2BlockMetadata;
355
- } & FloatMeta2;
356
- type ImageBlock2 = {
357
- id: string;
358
- kind: 'image';
359
- command: '\\includegraphics';
360
- value: string;
361
- /** Host asset identity from wire `asset_id`; preserved across value edits. */
362
- assetId?: string;
363
- options: Record<string, string>;
364
- metadata?: Document2BlockMetadata;
365
- } & FloatMeta2;
366
- type BibliographyBlock2 = {
367
- id: string;
368
- kind: 'bibliography';
369
- command: '\\begin{thebibliography}';
370
- closing: '\\end{thebibliography}';
371
- metadata?: Document2BlockMetadata;
372
- };
373
- type RawBlock2 = {
374
- id: string;
375
- kind: 'raw';
376
- command: '\\raw';
377
- value: string;
378
- metadata?: Document2BlockMetadata;
379
- };
380
- type Document2Block = TextBlock2 | ListBlock2 | TableBlock2 | ImageBlock2 | BibliographyBlock2 | RawBlock2;
381
- type Document2Node = {
382
- nodeType: 'DocumentObject';
383
- meta: Document2Meta;
384
- references: Reference2[];
385
- blocks: Document2Block[];
386
- diagnostics: Document2Diagnostic[];
387
- };
388
- type ImportDocument2Options = {
389
- strict?: boolean;
390
- mode?: Document2ParseMode;
391
- };
392
- type DetectedMathSpan2 = {
393
- start: number;
394
- end: number;
395
- source: string;
396
- opening: string;
397
- closing: string;
398
- display: boolean;
399
- };
400
- type DetectedCiteSpan2 = {
401
- kind: 'cite';
402
- start: number;
403
- end: number;
404
- source: string;
405
- keys: string[];
406
- };
407
- type DetectedRefSpan2 = {
408
- kind: 'ref';
409
- start: number;
410
- end: number;
411
- source: string;
412
- keys: string[];
413
- refCommand: 'ref' | 'eqref';
414
- };
415
- type DetectedInlineSpan2 = ({
416
- kind: 'math';
417
- } & DetectedMathSpan2) | DetectedCiteSpan2 | DetectedRefSpan2;
418
- type PreviewInline2 = {
419
- kind: 'text';
420
- text: string;
421
- style?: TextStyle2;
422
- } | {
423
- kind: 'math';
424
- id: string;
425
- tex: string;
426
- display: boolean;
427
- output: Document2MathOutput;
428
- editable: boolean;
429
- } | {
430
- kind: 'cite';
431
- id: string;
432
- keys: string[];
433
- label: string;
434
- } | {
435
- kind: 'ref';
436
- id: string;
437
- keys: string[];
438
- refCommand: 'ref' | 'eqref';
439
- label: string;
440
- };
441
- type PreviewBlock2 = {
442
- kind: 'basmala';
443
- id: string;
444
- text: string;
445
- tex: string;
446
- } | {
447
- kind: 'titleBlock';
448
- id: string;
449
- title?: string;
450
- authors?: string;
451
- date?: string;
452
- } | {
453
- kind: 'abstract';
454
- id: string;
455
- text: string;
456
- } | {
457
- kind: 'closing';
458
- id: string;
459
- text: string;
460
- tex: string;
461
- } | {
462
- kind: 'heading';
463
- id: string;
464
- level: 1 | 2 | 3;
465
- inlines: PreviewInline2[];
466
- metadata?: Document2BlockMetadata;
467
- } | {
468
- kind: 'paragraph';
469
- id: string;
470
- inlines: PreviewInline2[];
471
- centered?: boolean;
472
- metadata?: Document2BlockMetadata;
473
- } | {
474
- kind: 'list';
475
- id: string;
476
- ordered: boolean;
477
- items: Array<{
478
- id: string;
479
- inlines: PreviewInline2[];
480
- blocks: PreviewBlock2[];
481
- }>;
482
- metadata?: Document2BlockMetadata;
483
- } | {
484
- kind: 'table';
485
- id: string;
486
- rows: PreviewInline2[][][];
487
- /** Compatibility source string for hosts that still read caption directly. */
488
- caption?: string;
489
- /** Structured caption rendering path, including MathIsland tokens. */
490
- captionInlines?: PreviewInline2[];
491
- label?: string;
492
- numberLabel?: string;
493
- metadata?: Document2BlockMetadata;
494
- } | {
495
- kind: 'image';
496
- id: string;
497
- src: string;
498
- assetId?: string;
499
- options: Record<string, string>;
500
- centered?: boolean;
501
- /** Compatibility source string for alt text/legacy hosts. */
502
- caption?: string;
503
- /** Structured caption rendering path, including MathIsland tokens. */
504
- captionInlines?: PreviewInline2[];
505
- label?: string;
506
- numberLabel?: string;
507
- metadata?: Document2BlockMetadata;
508
- } | {
509
- kind: 'bibliography';
510
- id: string;
511
- items: Array<{
512
- id: string;
513
- numberLabel: string;
514
- key: string;
515
- authors: string;
516
- title: string;
517
- year: string;
518
- url: string;
519
- venue: string;
520
- fieldSeparator: ReferenceFieldSeparator;
521
- }>;
522
- metadata?: Document2BlockMetadata;
523
- }
524
- /** Preview-only: raw / unknown blocks are omitted from preview until we add proper rendering. */
525
- | {
526
- kind: 'omit';
527
- id: string;
528
- metadata?: Document2BlockMetadata;
529
- };
530
- type MathIsland2 = {
531
- id: string;
532
- tex: string;
533
- display: boolean;
534
- output: Document2MathOutput;
535
- editable: boolean;
536
- };
537
- type Document2Preview = {
538
- blocks: PreviewBlock2[];
539
- mathIslands: MathIsland2[];
540
- };
541
- type FormatCiteLabelOptions = {
542
- documentDirection?: Document2Direction;
543
- digitForm?: DigitFormId;
544
- };
545
-
546
- type Document2LabelKind = 'fig' | 'tab' | 'eq';
547
- type Document2LabelEntry = {
548
- key: string;
549
- kind: Document2LabelKind;
550
- caption: string;
551
- /** Block id for fig/tab, or math token id for eq. */
552
- ownerId: string;
553
- number: number;
554
- };
555
- type FloatMetaPatch = {
556
- centered?: boolean;
557
- captionEnabled?: boolean;
558
- caption?: string;
559
- labelEnabled?: boolean;
560
- label?: string;
561
- };
562
- declare function defaultFloatMeta(): {
563
- centered: true;
564
- captionEnabled: false;
565
- caption: string;
566
- captionField: InlineField2;
567
- labelEnabled: false;
568
- label: string;
569
- };
570
- declare function parseFloatMetaFromJson(json: {
571
- caption?: string;
572
- label?: string;
573
- caption_enabled?: boolean;
574
- label_enabled?: boolean;
575
- centered?: boolean;
576
- }): {
577
- centered: boolean;
578
- captionEnabled: boolean;
579
- caption: string;
580
- labelEnabled: boolean;
581
- label: string;
582
- };
583
- declare function parseRefKeys(source: string): {
584
- keys: string[];
585
- refCommand: 'ref' | 'eqref';
586
- };
587
- declare function refTokenLatex(keys: string[], refCommand: 'ref' | 'eqref'): string;
588
- /** Collect enabled labels in document order, numbering per kind. */
589
- declare function collectDocument2Labels(document: Document2Node): Document2LabelEntry[];
590
- declare function labelNumberMap(document: Document2Node): Map<string, {
591
- kind: Document2LabelKind;
592
- number: number;
593
- }>;
594
- type FormatFloatCaptionTitleOptions = {
595
- uiLocale?: ButexUiLocale;
596
- documentDirection?: Document2Direction;
597
- digitForm?: DigitFormId;
598
- };
599
- /** Localized numbered float/equation title: الشكل ١ / Figure 1 / المعادلة ١. */
600
- declare function formatFloatCaptionTitle(kind: Document2LabelKind, number: number, options?: FormatFloatCaptionTitleOptions): string;
601
- /** Caption line as shown in document preview: الشكل ١: نص / Figure 1. text. */
602
- declare function formatFloatCaptionPreview(title: string, caption: string | undefined, uiLocale?: ButexUiLocale): string;
603
- declare function formatRefLabel(keys: string[], document: Document2Node, refCommand: 'ref' | 'eqref', options?: FormatCiteLabelOptions): string;
604
- declare function stripDisplayMathDelimiters(source: string): string;
605
- declare function applyFloatMetaPatch<T extends ImageBlock2 | TableBlock2>(block: T, patch: FloatMetaPatch): void;
606
-
607
- declare const BUTEX_BASMALA_LINE1 = "\u0628\u0650\u0633\u0652\u0645\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0652\u0645\u064E\u0670\u0646\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0650\u064A\u0645\u0650";
608
- declare const BUTEX_BASMALA_LINE2 = "\u0648\u064E\u0671\u0644\u0635\u064E\u0651\u0644\u064E\u0627\u0629\u064F \u0648\u064E\u0671\u0644\u0633\u064E\u0651\u0644\u064E\u0627\u0645\u064F \u0639\u064E\u0644\u064E\u0649\u0670 \u0631\u064E\u0633\u064F\u0648\u0644\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650";
609
- declare const BUTEX_BASMALA_SALAWAT = "\u0635\u064E\u0644\u064E\u0651\u0649 \u0671\u0644\u0644\u064E\u0651\u0647\u064F \u0639\u064E\u0644\u064E\u064A\u0652\u0647\u0650 \u0648\u064E\u0633\u064E\u0644\u064E\u0651\u0645\u064E";
610
- /** Three-line basmala joined for UI / plain-text matchers. */
611
- declare const BUTEX_BASMALA = "\u0628\u0650\u0633\u0652\u0645\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0652\u0645\u064E\u0670\u0646\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0650\u064A\u0645\u0650\n\u0648\u064E\u0671\u0644\u0635\u064E\u0651\u0644\u064E\u0627\u0629\u064F \u0648\u064E\u0671\u0644\u0633\u064E\u0651\u0644\u064E\u0627\u0645\u064F \u0639\u064E\u0644\u064E\u0649\u0670 \u0631\u064E\u0633\u064F\u0648\u0644\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650\n\u0635\u064E\u0644\u064E\u0651\u0649 \u0671\u0644\u0644\u064E\u0651\u0647\u064F \u0639\u064E\u0644\u064E\u064A\u0652\u0647\u0650 \u0648\u064E\u0633\u064E\u0644\u064E\u0651\u0645\u064E";
612
- declare const BUTEX_CLOSING_HAMDALA = "\u0627\u0644\u0652\u062D\u064E\u0645\u0652\u062F\u064F \u0644\u0650\u0644\u064E\u0651\u0647\u0650 \u0646\u064E\u0641\u064E\u0639\u064E\u0646\u064E\u0627 \u0628\u0650\u0639\u0650\u0644\u0652\u0645\u0650\u0647\u0650";
613
- /** Display-math body using BuTeX Diwani (for MathJax preview islands). */
614
- declare function butexDiwaniDisplayTex(text: string): string;
615
- /** Full display equation for XeLaTeX export. */
616
- declare function butexDiwaniDisplayLatex(text: string): string;
617
- /** Display-math body using BuTeX Maghribi (for document chrome). */
618
- declare function butexMaghribiDisplayTex(text: string): string;
619
- /** Full display equation using BuTeX Maghribi for XeLaTeX export. */
620
- declare function butexMaghribiDisplayLatex(text: string): string;
621
- /** Three-line Maghribi body for MathJax basmala islands. */
622
- declare function butexBasmalaDisplayTex(): string;
623
- /** Standalone display equation when there is no \\maketitle (title-less docs). */
624
- declare function butexBasmalaDisplayLatex(): string;
625
- /**
626
- * Keep \\maketitle inside the current column when twocolumn is on.
627
- * Standard article otherwise does \\twocolumn[\\@maketitle] and spans both columns.
628
- * Call after titling so \\@maketitle still includes \\pretitle hooks.
629
- */
630
- declare function butexInColumnMaketitleHook(): string;
631
- /** Titling hooks so the basmala stays attached to the visible title. */
632
- declare function butexBasmalaTitlingPreamble(options?: {
633
- twocolumn?: boolean;
634
- }): string;
635
- declare const HIJRI_YEAR_MIN = 1400;
636
- declare const HIJRI_YEAR_MAX = 1500;
637
- declare const HIJRI_MONTH_IDS: HijriMonthId[];
638
- declare const DEFAULT_HIJRI_DATE: Document2HijriDate;
639
- declare function hijriMonthLabel(month: HijriMonthId, locale?: ButexUiLocale): string;
640
- declare function emptyDocument2Meta(): Document2Meta;
641
- declare function normalizeDocument2HijriDate(value: unknown): Document2HijriDate;
642
- declare function normalizeDocument2Meta(value: unknown): Document2Meta;
643
- type Document2MetaProp = Partial<Omit<Document2Meta, 'date'>> & {
644
- date?: Partial<Document2HijriDate>;
645
- };
646
- /** Prop fills gaps; JSON wins only when the key is present on the JSON object. */
647
- declare function mergeDocument2Meta(fromJson: unknown, fromProp?: Document2MetaProp): Document2Meta;
648
- /** For live Document2Node meta: prop fills empty title/authors/abstract; date patch merges. */
649
- declare function fillDocument2MetaGaps(current: Document2Meta, fromProp?: Document2MetaProp): Document2Meta;
650
- declare function document2HasMaketitle(meta: Document2Meta): boolean;
651
- declare function document2HasAbstract(meta: Document2Meta): boolean;
652
- declare function document2HasTitleStack(meta: Document2Meta): boolean;
653
- type FormatHijriDateOptions = {
654
- locale?: ButexUiLocale;
655
- digitForm?: DigitFormId;
656
- };
657
- declare function formatHijriDate(date: Document2HijriDate, options?: FormatHijriDateOptions | ButexUiLocale): string;
658
- declare function cloneDocument2Meta(meta: Document2Meta): Document2Meta;
659
-
660
- type Document2ImageAssetRef = {
661
- assetId: string;
662
- value?: string;
663
- };
664
- type Document2ImageInput = string | Document2ImageAssetRef | undefined;
665
- declare function findFirstInlineField(document: Document2Node): InlineField2 | null;
666
- declare function updateTextToken(document: Document2Node, fieldId: string, tokenId: string, text: string): Document2Node;
667
- declare function cloneDocument2Node(document: Document2Node): Document2Node;
668
- declare function insertDocument2BlockAfter(document: Document2Node, afterBlockId: string | null | undefined, block: Document2Block): Document2Node;
669
- declare function moveDocument2BlockById(document: Document2Node, blockId: string, direction: -1 | 1): Document2Node;
670
- declare function moveDocument2BlockRange(document: Document2Node, from: number, to: number, direction: -1 | 1): Document2Node;
671
- declare function removeDocument2BlockRange(document: Document2Node, from: number, to: number): Document2Node;
672
- declare function toggleTextTokenStyle(document: Document2Node, fieldId: string, tokenId: string, selectionStart: number, selectionEnd: number, styleName: keyof TextStyle2): Document2Node;
673
- declare function removeMathTokenById(document: Document2Node, tokenId: string): Document2Node;
674
- declare function insertMathTokenAtCaret(document: Document2Node, fieldId: string, textTokenId: string | null, caretOffset: number, session: EditorSession, opening?: string, closing?: string, side?: EditorSide): Document2Node;
675
- declare function insertMathToken(document: Document2Node, fieldId: string, insertIndex: number, session: EditorSession, opening?: string, closing?: string, side?: EditorSide): Document2Node;
676
- declare function replaceMathTokenFromSession(document: Document2Node, tokenId: string, session: EditorSession, opening?: string, closing?: string, side?: EditorSide): Document2Node;
677
- declare function addDocument2TextBlock(document: Document2Node, command?: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph', afterBlockId?: string | null): Document2Node;
678
- declare function updateDocument2TextBlockCentered(document: Document2Node, blockId: string, centered: boolean): Document2Node;
679
- declare function removeDocument2BlockById(document: Document2Node, blockId: string): Document2Node;
680
- declare function addDocument2ListBlock(document: Document2Node, ordered: boolean, afterBlockId?: string | null): Document2Node;
681
- declare function addDocument2TableBlock(document: Document2Node, columns?: string, rowCount?: number, colCount?: number, afterBlockId?: string | null): Document2Node;
682
- declare function addDocument2ImageBlock(document: Document2Node, srcOrAsset?: Document2ImageInput, afterBlockId?: string | null): Document2Node;
683
- declare function updateDocument2ImageValue(document: Document2Node, blockId: string, value: string): Document2Node;
684
- declare function updateDocument2ImageAsset(document: Document2Node, blockId: string, asset: Document2ImageAssetRef): Document2Node;
685
- declare function clearDocument2ImageAsset(document: Document2Node, blockId: string): Document2Node;
686
- declare function updateDocument2ImageMeta(document: Document2Node, blockId: string, patch: FloatMetaPatch): Document2Node;
687
- declare function updateDocument2TableMeta(document: Document2Node, blockId: string, patch: FloatMetaPatch): Document2Node;
688
- declare function updateMathTokenLabel(document: Document2Node, tokenId: string, patch: {
689
- labelEnabled?: boolean;
690
- label?: string;
691
- }): Document2Node;
692
- declare function insertRefTokenAtCaret(document: Document2Node, fieldId: string, textTokenId: string | null, caretOffset: number, keys: string[], refCommand?: 'ref' | 'eqref'): Document2Node;
693
- declare function updateRefTokenKeys(document: Document2Node, tokenId: string, keys: string[], refCommand?: 'ref' | 'eqref'): Document2Node;
694
- declare function removeRefTokenById(document: Document2Node, tokenId: string): Document2Node;
695
- declare function addDocument2ListItem(document: Document2Node, listBlockId: string): Document2Node;
696
- declare function removeDocument2ListItem(document: Document2Node, listBlockId: string, itemId: string): Document2Node;
697
- declare function insertCiteTokenAtCaret(document: Document2Node, fieldId: string, textTokenId: string | null, caretOffset: number, keys: string[]): Document2Node;
698
- declare function updateCiteTokenKeys(document: Document2Node, tokenId: string, keys: string[]): Document2Node;
699
- declare function removeCiteTokenById(document: Document2Node, tokenId: string): Document2Node;
700
- declare function ensureDocument2BibliographyBlock(document: Document2Node, afterBlockId?: string | null): Document2Node;
701
- declare function addDocument2Reference(document: Document2Node, partial?: Partial<Reference2Json>): Document2Node;
702
- declare function updateDocument2Reference(document: Document2Node, referenceId: string, patch: Partial<Reference2Json>): Document2Node;
703
- declare function removeDocument2Reference(document: Document2Node, referenceId: string): Document2Node;
704
- declare function moveDocument2Reference(document: Document2Node, referenceId: string, direction: -1 | 1): Document2Node;
705
- declare function setDocument2References(document: Document2Node, references: Reference2[]): Document2Node;
706
- declare function updateDocument2Meta(document: Document2Node, patch: Document2MetaProp): Document2Node;
707
-
708
- type Document2TextBlockKind = 'section' | 'subsection' | 'subsubsection' | 'paragraph';
709
- type Document2Anchor = {
710
- before_block_id: string;
711
- } | {
712
- after_block_id: string;
713
- } | {
714
- end: true;
715
- };
716
- type Document2InlineAnchor = {
717
- before_token_id: string;
718
- } | {
719
- after_token_id: string;
720
- } | {
721
- start: true;
722
- } | {
723
- end: true;
724
- };
725
- type Document2ListItemAnchor = {
726
- before_item_id: string;
727
- } | {
728
- after_item_id: string;
729
- } | {
730
- end: true;
731
- };
732
- type Document2ReferenceAnchor = {
733
- before_reference_key: string;
734
- } | {
735
- after_reference_key: string;
736
- } | {
737
- end: true;
738
- };
739
- type Document2InlineTokenInput = {
740
- kind: 'text';
741
- text: string;
742
- style?: TextStyle2;
743
- } | {
744
- kind: 'math';
745
- source: string;
746
- math_object: MathObject2Json;
747
- } | {
748
- kind: 'cite';
749
- keys: string[];
750
- } | {
751
- kind: 'ref';
752
- keys: string[];
753
- ref_command: 'ref' | 'eqref';
754
- };
755
- type BlockInsertion = {
756
- anchor: Document2Anchor;
757
- metadata?: Document2BlockMetadata;
758
- };
759
- type Document2Command = ({
760
- op: 'insert_text_block';
761
- kind: Document2TextBlockKind;
762
- text: string;
763
- } & BlockInsertion) | {
764
- op: 'replace_text_block';
765
- block_id: string;
766
- text: string;
767
- } | {
768
- op: 'remove_block';
769
- block_id: string;
770
- } | {
771
- op: 'move_block';
772
- block_id: string;
773
- anchor: Document2Anchor;
774
- } | ({
775
- op: 'insert_figure';
776
- asset_id: string;
777
- value?: string;
778
- caption?: string;
779
- label?: string;
780
- } & BlockInsertion) | {
781
- op: 'update_figure';
782
- block_id: string;
783
- asset_id?: string | null;
784
- value?: string;
785
- } | {
786
- op: 'update_float_meta';
787
- block_id: string;
788
- centered?: boolean;
789
- caption_enabled?: boolean;
790
- caption?: string;
791
- label_enabled?: boolean;
792
- label?: string;
793
- } | ({
794
- op: 'insert_bibliography';
795
- } & BlockInsertion) | {
796
- op: 'update_document_meta';
797
- title?: string;
798
- authors?: string;
799
- abstract?: string;
800
- date?: Partial<Document2HijriDate>;
801
- } | ({
802
- op: 'insert_reference';
803
- key: string;
804
- authors?: string;
805
- title?: string;
806
- year?: string;
807
- venue?: string;
808
- url?: string;
809
- field_separator?: ReferenceFieldSeparator;
810
- anchor: Document2ReferenceAnchor;
811
- }) | {
812
- op: 'update_reference';
813
- reference_key: string;
814
- key?: string;
815
- authors?: string;
816
- title?: string;
817
- year?: string;
818
- venue?: string;
819
- url?: string;
820
- field_separator?: ReferenceFieldSeparator;
821
- } | {
822
- op: 'remove_reference';
823
- reference_key: string;
824
- } | {
825
- op: 'move_reference';
826
- reference_key: string;
827
- anchor: Document2ReferenceAnchor;
828
- } | {
829
- op: 'insert_inline_token';
830
- field_id: string;
831
- token: Document2InlineTokenInput;
832
- anchor: Document2InlineAnchor;
833
- } | {
834
- op: 'replace_inline_token';
835
- field_id: string;
836
- token_id: string;
837
- token: Document2InlineTokenInput;
838
- } | {
839
- op: 'remove_inline_token';
840
- field_id: string;
841
- token_id: string;
842
- } | ({
843
- op: 'insert_list';
844
- ordered: boolean;
845
- items: string[];
846
- } & BlockInsertion) | {
847
- op: 'insert_list_item';
848
- list_id: string;
849
- text: string;
850
- anchor: Document2ListItemAnchor;
851
- } | {
852
- op: 'replace_list_item';
853
- list_id: string;
854
- item_id: string;
855
- text: string;
856
- } | {
857
- op: 'remove_list_item';
858
- list_id: string;
859
- item_id: string;
860
- } | {
861
- op: 'move_list_item';
862
- list_id: string;
863
- item_id: string;
864
- anchor: Document2ListItemAnchor;
865
- } | ({
866
- op: 'insert_table';
867
- rows: string[][];
868
- columns: string;
869
- caption?: string;
870
- label?: string;
871
- } & BlockInsertion) | {
872
- op: 'replace_table_cell';
873
- table_id: string;
874
- row_index: number;
875
- column_index: number;
876
- text: string;
877
- } | {
878
- op: 'insert_table_row';
879
- table_id: string;
880
- index: number;
881
- values: string[];
882
- } | {
883
- op: 'remove_table_row';
884
- table_id: string;
885
- index: number;
886
- } | {
887
- op: 'move_table_row';
888
- table_id: string;
889
- from_index: number;
890
- to_index: number;
891
- } | {
892
- op: 'insert_table_column';
893
- table_id: string;
894
- index: number;
895
- values: string[];
896
- columns: string;
897
- } | {
898
- op: 'remove_table_column';
899
- table_id: string;
900
- index: number;
901
- columns: string;
902
- } | {
903
- op: 'move_table_column';
904
- table_id: string;
905
- from_index: number;
906
- to_index: number;
907
- columns: string;
908
- };
909
- type Document2CommandErrorCode = 'invalid_document' | 'invalid_command' | 'missing_block_id' | 'duplicate_block_id' | 'invalid_anchor' | 'anchor_not_found' | 'block_not_found' | 'block_kind_mismatch' | 'field_not_found' | 'token_not_found' | 'list_not_found' | 'item_not_found' | 'table_not_found' | 'invalid_table_shape' | 'index_out_of_range' | 'minimum_structure' | 'invalid_inline_token' | 'math_object_mismatch' | 'unsupported_inline_content' | 'reference_not_found' | 'invalid_key' | 'duplicate_key' | 'bibliography_exists';
910
- declare class Document2CommandError extends Error {
911
- readonly code: Document2CommandErrorCode;
912
- constructor(code: Document2CommandErrorCode, message: string);
913
- }
914
-
915
- /** Apply one validated command to canonical JSON without mutating caller input. */
916
- declare function applyDocument2Command(json: Document2Json, commandInput: Document2Command): Document2Json;
917
-
918
- type Document2DiffChunkKind = 'added' | 'removed' | 'context';
919
- type Document2DiffChunk = {
920
- kind: Document2DiffChunkKind;
921
- text: string;
922
- };
923
- type Document2Diff = {
924
- version: 1;
925
- changed: boolean;
926
- truncated: boolean;
927
- chunks: Document2DiffChunk[];
928
- };
929
- /**
930
- * Compare two persisted Document2 documents using canonical Document2 import/export
931
- * semantics and jsdiff's maintained JSON diff implementation.
932
- *
933
- * Generated editor identity sidecars are intentionally excluded so equivalent
934
- * legacy documents do not differ merely because normalization assigned new IDs.
935
- */
936
- declare function diffDocument2(before: Document2Json, after: Document2Json): Document2Diff;
937
-
938
- type Document2OutlineKind = 'section' | 'subsection' | 'subsubsection' | 'paragraph' | 'list' | 'table' | 'figure' | 'bibliography' | 'raw';
939
- type Document2OutlineEntry = {
940
- id: string;
941
- kind: Document2OutlineKind;
942
- command: string;
943
- excerpt: string;
944
- };
945
- /** Return a compact top-level outline for a canonical document. */
946
- declare function document2Outline(json: Document2Json): Document2OutlineEntry[];
947
-
948
- type Document2CitationIndexEntry = {
949
- kind: 'cite';
950
- block_id: string;
951
- field_id: string;
952
- token_id: string;
953
- keys: string[];
954
- unresolved_keys: string[];
955
- };
956
- type Document2CrossReferenceIndexEntry = {
957
- kind: 'ref';
958
- ref_command: 'ref' | 'eqref';
959
- block_id: string;
960
- field_id: string;
961
- token_id: string;
962
- keys: string[];
963
- unresolved_keys: string[];
964
- };
965
- type Document2IndexedLabel = {
966
- key: string;
967
- kind: Document2LabelKind;
968
- caption: string;
969
- number: number;
970
- block_id?: string;
971
- field_id?: string;
972
- token_id?: string;
973
- };
974
- type Document2ReferenceIndex = {
975
- citations: Document2CitationIndexEntry[];
976
- cross_references: Document2CrossReferenceIndexEntry[];
977
- labels: Document2IndexedLabel[];
978
- unresolved: {
979
- citation_keys: string[];
980
- cross_reference_keys: string[];
981
- };
982
- };
983
- /** Return a detached, read-only view of the registered bibliography catalog. */
984
- declare function getDocument2References(document: Document2Node): Reference2Json[];
985
- /**
986
- * Return semantic citation, cross-reference, and label relationships without
987
- * changing the document. Entries follow document/token order and preserve the
988
- * stable IDs already present in the live Document2 node.
989
- */
990
- declare function getDocument2ReferenceIndex(document: Document2Node): Document2ReferenceIndex;
991
-
992
- type Document2KeyError = 'empty' | 'invalid' | 'duplicate';
993
- /** NFC-normalize and trim a document key (label or bibliography). */
994
- declare function normalizeDocument2Key(key: string): string;
995
- /** True when key matches Unicode letters/marks, decimal digits, and :._- with no spaces. */
996
- declare function isValidDocument2Key(key: string): boolean;
997
- type Document2KeyNamespace = {
998
- references?: Array<Pick<Reference2, 'id' | 'key'>>;
999
- labels?: Array<Pick<Document2LabelEntry, 'ownerId' | 'key'>>;
1000
- /** Skip this reference id when checking (editing that entry). */
1001
- excludeReferenceId?: string;
1002
- /** Skip this label owner id when checking (editing that float/eq). */
1003
- excludeOwnerId?: string;
1004
- };
1005
- /** Returns true if another reference or label already uses this key (NFC match). */
1006
- declare function isDuplicateDocument2Key(key: string, namespace: Document2KeyNamespace): boolean;
1007
- /** Classify a key for UI messaging: empty, invalid charset, or duplicate. */
1008
- declare function document2KeyError(key: string, namespace?: Document2KeyNamespace): Document2KeyError | null;
1009
-
1010
- declare const DEFAULT_REFERENCE_FIELD_SEPARATOR: ReferenceFieldSeparator;
1011
- declare function normalizeReferenceFieldSeparator(value: unknown): ReferenceFieldSeparator;
1012
- declare function referenceNumberMap(references: Array<Pick<Reference2, 'key'>>): Map<string, number>;
1013
- declare function resolveCiteNumbers(keys: string[], references: Array<Pick<Reference2, 'key'>>): Array<number | null>;
1014
- declare function formatCiteLabel(keys: string[], references: Array<Pick<Reference2, 'key'>>, options?: FormatCiteLabelOptions): string;
1015
- declare function formatBibliographyNumber(index: number, options?: FormatCiteLabelOptions): string;
1016
- declare function parseCiteKeys(source: string): string[];
1017
- declare function citeTokenLatex(keys: string[]): string;
1018
- declare function referenceFromJson(json: Reference2Json): Reference2;
1019
- declare function createEmptyReference2(partial?: Partial<Reference2Json>): Reference2;
1020
- /** Joined authors/title/venue/year for preview and export (no \\bibitem wrapper). */
1021
- declare function bibliographyEntryBody(reference: Pick<Reference2, 'authors' | 'title' | 'venue' | 'year' | 'fieldSeparator'>, separator?: ReferenceFieldSeparator, options?: {
1022
- digitForm?: DigitFormId;
1023
- }): string;
1024
- declare function bibliographyEntryLatex(reference: Reference2): string;
1025
- /**
1026
- * Build an href for a bibliography URL. Values without a scheme become https://…
1027
- * so the browser does not resolve them against the editor origin (e.g. localhost).
1028
- * Leaves http(s)/mailto/ftp and other schemed URLs unchanged. Empty → ''.
1029
- */
1030
- declare function absoluteHttpHref(url: string): string;
1031
-
1032
- type ArabicDigitsMapping = 'arabicdigits' | 'farsidigits' | 'digits';
1033
- type ArabicXeLatexPreambleOptions = {
1034
- digitsMapping?: ArabicDigitsMapping;
1035
- /** When true, add the article class twocolumn option. Default false. */
1036
- twocolumn?: boolean;
1037
- };
1038
- declare function arabicXeLatexPreamblePkg(twocolumn?: boolean): string;
1039
- declare function arabicXeLatexPreambleFont(digitsMapping?: ArabicDigitsMapping): string;
1040
- declare function arabicXeLatexPreambleCmd(): string;
1041
- declare function getArabicXeLatexPreamble(digitsMappingOrOptions?: ArabicDigitsMapping | ArabicXeLatexPreambleOptions): string;
1042
-
1043
- type Document2LatexOptions = {
1044
- /**
1045
- * When true (default), emit a complete Arabic XeLaTeX file:
1046
- * preamble + \\begin{document} + body + \\end{document}.
1047
- * Pass false for body-only blocks.
1048
- */
1049
- wrapDocument?: boolean;
1050
- /** Font digit Mapping when wrapping. Default 'arabicdigits'. */
1051
- digitsMapping?: ArabicDigitsMapping;
1052
- /** Document-level digit form for XeLaTeX font Mapping. Ignored when digitsMapping is set. */
1053
- digitForm?: DigitFormId;
1054
- /** When true, use article class option twocolumn. Default false. */
1055
- twocolumn?: boolean;
1056
- };
1057
- declare function inlineFieldLatex(field: InlineField2): string;
1058
-
1059
- /** Convert the live editor AST to the canonical JSON wire format. */
1060
- declare function toDocumentJson2(document: Document2Node): Document2Json;
1061
-
1062
- type Document2ValidationIssueCode = 'malformed_document' | 'parser_diagnostic' | 'empty_image' | 'unsupported_emoji' | 'key_empty' | 'key_invalid' | 'key_duplicate' | 'empty_citation' | 'missing_citation' | 'empty_reference' | 'missing_reference' | 'reference_kind_mismatch' | 'invalid_equation_label' | 'invalid_table';
1063
- type Document2ValidationIssue = {
1064
- code: Document2ValidationIssueCode;
1065
- path: string;
1066
- blockId?: string;
1067
- tokenId?: string;
1068
- };
1069
- type Document2ValidationResult = {
1070
- valid: boolean;
1071
- issues: Document2ValidationIssue[];
1072
- };
1073
- /** True when the current XeLaTeX text profile cannot render the value reliably. */
1074
- declare function hasXeLatexUnsupportedEmoji(value: string): boolean;
1075
- /**
1076
- * Validate a Document2 draft without mutating it. Detailed issues are kept in
1077
- * BuTeX so React can identify the field while hosts only need the boolean API.
1078
- */
1079
- declare function validateDocument2(document: Document2Json | Document2Node): Document2ValidationResult;
1080
- /** Public host contract: drafts may be saved, but only valid documents may compile. */
1081
- declare function isDocument2Valid(document: Document2Json | Document2Node): boolean;
1082
- /** Error thrown when LaTeX export is attempted for an invalid Document2 draft. */
1083
- declare class Document2ValidationError extends Error {
1084
- readonly issues: Document2ValidationIssue[];
1085
- constructor(issues: Document2ValidationIssue[]);
1086
- }
1087
-
1088
- declare const DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
1089
- type Document2HistoryStacks = {
1090
- past: Document2Node[];
1091
- future: Document2Node[];
1092
- maxDepth: number;
1093
- };
1094
- declare function createDocument2History(maxDepth?: number): Document2HistoryStacks;
1095
- declare function pushDocument2Snapshot(stacks: Document2HistoryStacks, documentBeforeEdit: Document2Node): void;
1096
- declare function restoreDocument2Undo(stacks: Document2HistoryStacks, documentNow: Document2Node): Document2Node | null;
1097
- declare function restoreDocument2Redo(stacks: Document2HistoryStacks, documentNow: Document2Node): Document2Node | null;
1098
- declare function document2HistoryCanUndo(stacks: Document2HistoryStacks): boolean;
1099
- declare function document2HistoryCanRedo(stacks: Document2HistoryStacks): boolean;
1100
-
1101
- type BlockSelectionRange = {
1102
- from: number;
1103
- to: number;
1104
- };
1105
- type BlockSelectionState = {
1106
- selection: BlockSelectionRange | null;
1107
- anchor: number | null;
1108
- };
1109
- declare function emptyBlockSelection(): BlockSelectionState;
1110
- declare function normalizeBlockSelection(selection: BlockSelectionRange | null, blockCount: number): BlockSelectionRange | null;
1111
- /** Checkbox click without Shift */
1112
- declare function toggleBlockInSelection(state: BlockSelectionState, index: number, blockCount: number): BlockSelectionState;
1113
- /** Shift+click on checkbox or header label */
1114
- declare function extendBlockSelectionFromAnchor(state: BlockSelectionState, index: number, blockCount: number): BlockSelectionState;
1115
- declare function remapSelectionAfterRangeMove(selection: BlockSelectionRange, direction: -1 | 1): BlockSelectionRange;
1116
-
1117
- declare function createInlineField2(value?: string, mathObjects?: Array<Document2MathObjectJson | null>, options?: ImportDocument2Options, path?: string, diagnostics?: Document2Diagnostic[], formats?: TextFormatSpan2Json[]): InlineField2;
1118
- declare function fromDocumentJson2(json: unknown, options?: ImportDocument2Options): Document2Node;
1119
- declare function createEmptyDocument2(): Document2Node;
1120
-
1121
- /** Math-only spans (used for math_objects alignment counts). */
1122
- declare function detectMathSpans2(value: string): DetectedMathSpan2[];
1123
- /** Left-to-right math + \\cite + \\ref/\\eqref spans without overlap. */
1124
- declare function detectInlineSpans2(value: string): DetectedInlineSpan2[];
1125
-
1126
- type Document2MathBridgeResult = {
1127
- editable: true;
1128
- session: EditorSession;
1129
- } | {
1130
- editable: false;
1131
- reason: string;
1132
- };
1133
- declare function createEmptyEquationSession(side?: EditorSide): EditorSession;
1134
- declare function createEmptyArabicEquationSession(): EditorSession;
1135
- declare function mathTokenToEditorSession(math: MathNode | null, side?: EditorSide): Document2MathBridgeResult;
1136
- declare function mathTokenToArabicEditorSession(math: MathNode | null): Document2MathBridgeResult;
1137
- declare function mathSourceFromSession(session: EditorSession, side: EditorSide, opening?: string, closing?: string): string;
1138
- declare function mathSourceFromArabicSession(session: EditorSession, opening?: string, closing?: string): string;
1139
- declare function mathNodeFromSession(session: EditorSession, opening?: string, closing?: string): MathNode;
1140
- declare function mathNodeFromArabicSession(session: EditorSession, opening?: string, closing?: string): MathNode;
1141
- declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide, digitForm?: DigitFormId): string;
1142
-
1143
- type Document2PreviewOptions = {
1144
- documentDirection?: Document2Direction;
1145
- digitForm?: DigitFormId;
1146
- uiLocale?: ButexUiLocale;
1147
- };
1148
- declare function document2Preview(document: Document2Node, output?: Document2MathOutput, equationSide?: EditorSide, previewOptions?: Document2PreviewOptions): Document2Preview;
1149
-
1150
- /**
1151
- * Export a validated Document2 runtime node. Invalid drafts remain saveable,
1152
- * but compilation must not silently receive unsafe or unreliable LaTeX.
1153
- */
1154
- declare function document2Latex(document: Document2Node, options?: Document2LatexOptions): string;
1155
-
1156
- export { type ArabicDigitsMapping, type ArabicXeLatexPreambleOptions, BUTEX_BASMALA, BUTEX_BASMALA_LINE1, BUTEX_BASMALA_LINE2, BUTEX_BASMALA_SALAWAT, BUTEX_CLOSING_HAMDALA, type BibliographyBlock2, type BlockSelectionRange, type BlockSelectionState, type CiteToken2, DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH, DEFAULT_HIJRI_DATE, DEFAULT_REFERENCE_FIELD_SEPARATOR, type Document2Anchor, type Document2Block, type Document2BlockJson, type Document2BlockMetadata, type Document2CitationIndexEntry, type Document2Command, Document2CommandError, type Document2CommandErrorCode, type Document2CrossReferenceIndexEntry, type Document2Diagnostic, type Document2Diff, type Document2DiffChunk, type Document2DiffChunkKind, type Document2Direction, type Document2HijriDate, type Document2HistoryStacks, type Document2ImageAssetRef, type Document2IndexedLabel, type Document2InlineAnchor, type Document2InlineIdsJson, type Document2InlineTokenIdJson, type Document2InlineTokenInput, type Document2Json, type Document2KeyError, type Document2KeyNamespace, type Document2LabelEntry, type Document2LabelKind, type Document2LatexOptions, type Document2ListItemAnchor, type Document2MathObjectJson, type Document2MathOutput, type Document2Meta, type Document2MetaProp, type Document2Node, type Document2OutlineEntry, type Document2OutlineKind, type Document2Preview, type Document2PreviewOptions, type Document2ReferenceAnchor, type Document2ReferenceIndex, type Document2TextBlockKind, Document2ValidationError, type Document2ValidationIssue, type Document2ValidationIssueCode, type Document2ValidationResult, type FloatMeta2, type FloatMetaPatch, type FormatCiteLabelOptions, type FormatFloatCaptionTitleOptions, HIJRI_MONTH_IDS, HIJRI_YEAR_MAX, HIJRI_YEAR_MIN, type HijriMonthId, type ImageBlock2, type ImportDocument2Options, type InlineField2, type InlineToken2, type ListBlock2, type ListItem2, type MathIsland2, type MathObject2Json, type MathToken2, type PreviewBlock2, type PreviewInline2, type RawBlock2, type RawMathObject2Json, type RefToken2, type Reference2, type Reference2Json, type ReferenceFieldSeparator, type TableBlock2, type TextBlock2, type TextFormatSpan2Json, type TextStyle2, type TextToken2, absoluteHttpHref, addDocument2ImageBlock, addDocument2ListBlock, addDocument2ListItem, addDocument2Reference, addDocument2TableBlock, addDocument2TextBlock, applyDocument2Command, applyFloatMetaPatch, arabicXeLatexPreambleCmd, arabicXeLatexPreambleFont, arabicXeLatexPreamblePkg, bibliographyEntryBody, bibliographyEntryLatex, butexBasmalaDisplayLatex, butexBasmalaDisplayTex, butexBasmalaTitlingPreamble, butexDiwaniDisplayLatex, butexDiwaniDisplayTex, butexInColumnMaketitleHook, butexMaghribiDisplayLatex, butexMaghribiDisplayTex, citeTokenLatex, clearDocument2ImageAsset, cloneDocument2Meta, cloneDocument2Node, collectDocument2Labels, createDocument2History, createEmptyArabicEquationSession, createEmptyDocument2, createEmptyEquationSession, createEmptyReference2, createInlineField2, defaultFloatMeta, detectInlineSpans2, detectMathSpans2, diffDocument2, document2HasAbstract, document2HasMaketitle, document2HasTitleStack, document2HistoryCanRedo, document2HistoryCanUndo, document2KeyError, document2Latex, document2Outline, document2Preview, emptyBlockSelection, emptyDocument2Meta, ensureDocument2BibliographyBlock, extendBlockSelectionFromAnchor, fillDocument2MetaGaps, findFirstInlineField, formatBibliographyNumber, formatCiteLabel, formatFloatCaptionPreview, formatFloatCaptionTitle, formatHijriDate, formatRefLabel, fromDocumentJson2, getArabicXeLatexPreamble, getDocument2ReferenceIndex, getDocument2References, hasXeLatexUnsupportedEmoji, hijriMonthLabel, inlineFieldLatex, insertCiteTokenAtCaret, insertDocument2BlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, isDocument2Valid, isDuplicateDocument2Key, isValidDocument2Key, labelNumberMap, mathNodeFromArabicSession, mathNodeFromSession, mathSourceFromArabicSession, mathSourceFromSession, mathTokenSourceForSide, mathTokenToArabicEditorSession, mathTokenToEditorSession, mergeDocument2Meta, moveDocument2BlockById, moveDocument2BlockRange, moveDocument2Reference, normalizeBlockSelection, normalizeDocument2HijriDate, normalizeDocument2Key, normalizeDocument2Meta, normalizeReferenceFieldSeparator, parseCiteKeys, parseFloatMetaFromJson, parseRefKeys, pushDocument2Snapshot, refTokenLatex, referenceFromJson, referenceNumberMap, remapSelectionAfterRangeMove, removeCiteTokenById, removeDocument2BlockById, removeDocument2BlockRange, removeDocument2ListItem, removeDocument2Reference, removeMathTokenById, removeRefTokenById, replaceMathTokenFromSession, resolveCiteNumbers, restoreDocument2Redo, restoreDocument2Undo, setDocument2References, stripDisplayMathDelimiters, toDocumentJson2, toggleBlockInSelection, toggleTextTokenStyle, updateCiteTokenKeys, updateDocument2ImageAsset, updateDocument2ImageMeta, updateDocument2ImageValue, updateDocument2Meta, updateDocument2Reference, updateDocument2TableMeta, updateDocument2TextBlockCentered, updateMathTokenLabel, updateRefTokenKeys, updateTextToken, validateDocument2 };