@drghaliasri/butex 8.1.1 → 8.1.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,527 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ type EditorSide = 'english' | 'arabic';
5
+ type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
6
+
7
+ type ButexUiLocale = 'ar' | 'en';
8
+
9
+ type ArabicNodeJson = {
10
+ node_type: string;
11
+ expr?: string;
12
+ name?: string;
13
+ superscript?: ChainJson | null;
14
+ subscript?: ChainJson | null;
15
+ left_delim_expr?: string;
16
+ right_delim_expr?: string;
17
+ inner_expr?: ChainJson;
18
+ optional_args?: ChainJson[];
19
+ mandatory_args?: ChainJson[];
20
+ opening?: string;
21
+ closing?: string;
22
+ lines?: ChainJson[];
23
+ source_latex?: string;
24
+ };
25
+ type ChainJson = {
26
+ node_type: 'ChainClass';
27
+ chain: ArabicNodeJson[];
28
+ };
29
+ declare class State {
30
+ }
31
+ declare class BaseAstNode {
32
+ state: State;
33
+ superscript: ChainNode | null;
34
+ subscript: ChainNode | null;
35
+ nodeType: string;
36
+ sourceLatex: string | null;
37
+ constructor(state?: State | null);
38
+ latex(): string;
39
+ arabicLatex(): string;
40
+ toArabicLatex(): string;
41
+ /** Latin-style scripts: `^{...}` and `_{...}` for english_json rendering. */
42
+ latexScripts(): string;
43
+ /**
44
+ * Arabic scripts use \\prescript{sup}{sub}{content} (matches reference Python output).
45
+ * Call with rendered strings for sup/sub chains (may be empty strings).
46
+ */
47
+ arabicLatexScripts(sup: string, sub: string, content: string): string;
48
+ }
49
+ declare class ChainNode {
50
+ chain: BaseAstNode[];
51
+ constructor(chain?: BaseAstNode[]);
52
+ latex(): string;
53
+ toEnglishLatex(): string;
54
+ /** RTL: reverse order relative to Latin chain (see test/ref_tests.txt). */
55
+ arabicLatex(): string;
56
+ toArabicLatex(): string;
57
+ }
58
+
59
+ type MathNode = {
60
+ nodeType: 'MathObject';
61
+ mathMode: string;
62
+ lines: ChainNode[];
63
+ closing: string;
64
+ };
65
+
66
+ type DocumentParseMode = 'english' | 'arabic';
67
+ type DocumentMathOutput = 'svg' | 'chtml';
68
+ type MathObject2Json = {
69
+ node_type: 'MathObject';
70
+ math_mode: string;
71
+ lines: ChainJson[];
72
+ closing: string;
73
+ /** Side used by the delimited source stored in the containing value/cell. */
74
+ source_side?: DocumentParseMode;
75
+ /** Preserve whether LaTeX export should prefer imported AST rendering or editor source. */
76
+ source_owner?: 'imported-structured' | 'editor';
77
+ label_enabled?: boolean;
78
+ label?: string;
79
+ numbered?: boolean;
80
+ };
81
+ /** Positional metadata for a raw-only span that has no structured equation AST. */
82
+ type RawMathObject2Json = {
83
+ node_type: 'RawMathObject';
84
+ label_enabled?: boolean;
85
+ label?: string;
86
+ numbered?: boolean;
87
+ };
88
+ type DocumentMathObjectJson = MathObject2Json | RawMathObject2Json;
89
+ type ReferenceFieldSeparator = ',' | '،';
90
+ type Reference2Json = {
91
+ key: string;
92
+ authors?: string;
93
+ title?: string;
94
+ year?: string;
95
+ url?: string;
96
+ venue?: string;
97
+ /** Bibliography field join: LTR `,` or Arabic `،`. Defaults to `،` when omitted. */
98
+ field_separator?: ReferenceFieldSeparator;
99
+ };
100
+ type HijriMonthId = 'محرم' | 'صفر' | 'ربيع الأول' | 'ربيع الآخر' | 'جمادى الأولى' | 'جمادى الآخرة' | 'رجب' | 'شعبان' | 'رمضان' | 'شوال' | 'ذو القعدة' | 'ذو الحجة';
101
+ type DocumentHijriDate = {
102
+ day: number;
103
+ month: HijriMonthId;
104
+ year: number;
105
+ };
106
+ type DocumentMeta = {
107
+ title: string;
108
+ authors: string;
109
+ date: DocumentHijriDate;
110
+ abstract: string;
111
+ };
112
+ type DocumentJson = {
113
+ node_type: 'DocumentObject';
114
+ meta?: DocumentMeta;
115
+ references?: Reference2Json[];
116
+ blocks: DocumentBlockJson[];
117
+ };
118
+ type DocumentInlineTokenIdJson = {
119
+ id: string;
120
+ kind: InlineToken2['kind'];
121
+ start: number;
122
+ end: number;
123
+ };
124
+ type DocumentInlineIdsJson = {
125
+ field_id: string;
126
+ tokens: DocumentInlineTokenIdJson[];
127
+ };
128
+ type DocumentBlockMetadata = {
129
+ source?: 'agent' | 'user';
130
+ };
131
+ type DocumentBlockJson = {
132
+ /** Stable identity used by headless commands. Legacy JSON may omit it. */
133
+ id?: string;
134
+ command: string;
135
+ value?: string;
136
+ formats?: TextFormatSpan2Json[];
137
+ inline_ids?: DocumentInlineIdsJson;
138
+ metadata?: DocumentBlockMetadata;
139
+ /** Stable host asset identity (e.g. S3 key / UUID); optional for \\includegraphics. */
140
+ asset_id?: string;
141
+ math_objects?: Array<DocumentMathObjectJson | null>;
142
+ options?: Record<string, string>;
143
+ closing?: string;
144
+ items?: DocumentListItemJson[];
145
+ rows?: string[][];
146
+ cell_formats?: TextFormatSpan2Json[][][];
147
+ cell_inline_ids?: DocumentInlineIdsJson[][];
148
+ columns?: string;
149
+ caption?: string;
150
+ /** Optional formatting sidecar for caption text spans. */
151
+ caption_formats?: TextFormatSpan2Json[];
152
+ /** Stable caption field/token identities; omitted by legacy documents. */
153
+ caption_inline_ids?: DocumentInlineIdsJson;
154
+ /** Caption-only structured math sidecar, independent from table cell math_objects. */
155
+ caption_math_objects?: Array<DocumentMathObjectJson | null>;
156
+ label?: string;
157
+ caption_enabled?: boolean;
158
+ label_enabled?: boolean;
159
+ centered?: boolean;
160
+ };
161
+ type DocumentListItemJson = {
162
+ id?: string;
163
+ value: string;
164
+ formats?: TextFormatSpan2Json[];
165
+ inline_ids?: DocumentInlineIdsJson;
166
+ math_objects?: Array<DocumentMathObjectJson | null>;
167
+ blocks?: DocumentBlockJson[];
168
+ };
169
+ type DocumentDiagnostic = {
170
+ code: string;
171
+ message: string;
172
+ path: string;
173
+ };
174
+ type Reference2 = {
175
+ id: string;
176
+ key: string;
177
+ authors: string;
178
+ title: string;
179
+ year: string;
180
+ url: string;
181
+ venue: string;
182
+ /** Joins authors/title/venue/year in bibliography display and export. */
183
+ fieldSeparator: ReferenceFieldSeparator;
184
+ };
185
+ type TextStyle2 = {
186
+ bold?: true;
187
+ italic?: true;
188
+ underline?: true;
189
+ };
190
+ type TextFormatSpan2Json = {
191
+ start: number;
192
+ end: number;
193
+ bold?: boolean;
194
+ italic?: boolean;
195
+ underline?: boolean;
196
+ };
197
+ type TextToken2 = {
198
+ id: string;
199
+ kind: 'text';
200
+ text: string;
201
+ style?: TextStyle2;
202
+ };
203
+ type MathToken2 = {
204
+ id: string;
205
+ kind: 'math';
206
+ display: boolean;
207
+ opening: string;
208
+ closing: string;
209
+ source: string;
210
+ sourceSide?: DocumentParseMode;
211
+ math: MathNode | null;
212
+ editable: boolean;
213
+ reason?: string;
214
+ sourceOwner: 'imported-structured' | 'raw' | 'editor';
215
+ /** When true on display math, export as equation env with \\label. */
216
+ labelEnabled?: boolean;
217
+ label?: string;
218
+ /** Independent display-equation numbering override; absent means legacy semantics. */
219
+ numbered?: boolean;
220
+ };
221
+ type CiteToken2 = {
222
+ id: string;
223
+ kind: 'cite';
224
+ keys: string[];
225
+ };
226
+ type RefToken2 = {
227
+ id: string;
228
+ kind: 'ref';
229
+ keys: string[];
230
+ refCommand: 'ref' | 'eqref';
231
+ };
232
+ type InlineToken2 = TextToken2 | MathToken2 | CiteToken2 | RefToken2;
233
+ type InlineField2 = {
234
+ id: string;
235
+ tokens: InlineToken2[];
236
+ };
237
+ type TextBlock2 = {
238
+ id: string;
239
+ kind: 'textBlock';
240
+ command: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph';
241
+ field: InlineField2;
242
+ /** Optional imported or authored label for a section heading. */
243
+ label?: string;
244
+ metadata?: DocumentBlockMetadata;
245
+ /** When true on \\paragraph, center in preview and LaTeX export. */
246
+ centered?: boolean;
247
+ };
248
+ type ListItem2 = {
249
+ id: string;
250
+ field: InlineField2;
251
+ blocks: DocumentBlock[];
252
+ };
253
+ type ListBlock2 = {
254
+ id: string;
255
+ kind: 'list';
256
+ command: '\\begin{itemize}' | '\\begin{enumerate}';
257
+ closing: '\\end{itemize}' | '\\end{enumerate}';
258
+ items: ListItem2[];
259
+ metadata?: DocumentBlockMetadata;
260
+ };
261
+ type FloatMeta2 = {
262
+ centered: boolean;
263
+ captionEnabled: boolean;
264
+ /** Compatibility source string; captionField is the structured source of truth. */
265
+ caption: string;
266
+ /** Stable inline field used by the editor, commands, preview, and persistence. */
267
+ captionField: InlineField2;
268
+ labelEnabled: boolean;
269
+ label: string;
270
+ };
271
+ type TableBlock2 = {
272
+ id: string;
273
+ kind: 'table';
274
+ command: '\\begin{tabular}';
275
+ closing: '\\end{tabular}';
276
+ columns: string;
277
+ rows: InlineField2[][];
278
+ metadata?: DocumentBlockMetadata;
279
+ } & FloatMeta2;
280
+ type ImageBlock2 = {
281
+ id: string;
282
+ kind: 'image';
283
+ command: '\\includegraphics';
284
+ value: string;
285
+ /** Host asset identity from wire `asset_id`; preserved across value edits. */
286
+ assetId?: string;
287
+ options: Record<string, string>;
288
+ metadata?: DocumentBlockMetadata;
289
+ } & FloatMeta2;
290
+ type BibliographyBlock2 = {
291
+ id: string;
292
+ kind: 'bibliography';
293
+ command: '\\begin{thebibliography}';
294
+ closing: '\\end{thebibliography}';
295
+ metadata?: DocumentBlockMetadata;
296
+ };
297
+ type RawBlock2 = {
298
+ id: string;
299
+ kind: 'raw';
300
+ command: '\\raw';
301
+ value: string;
302
+ metadata?: DocumentBlockMetadata;
303
+ };
304
+ type DocumentBlock = TextBlock2 | ListBlock2 | TableBlock2 | ImageBlock2 | BibliographyBlock2 | RawBlock2;
305
+ type DocumentNode = {
306
+ nodeType: 'DocumentObject';
307
+ meta: DocumentMeta;
308
+ references: Reference2[];
309
+ blocks: DocumentBlock[];
310
+ diagnostics: DocumentDiagnostic[];
311
+ };
312
+
313
+ type DocumentLabelKind = 'fig' | 'tab' | 'eq';
314
+
315
+ type DocumentMetaProp = Partial<Omit<DocumentMeta, 'date'>> & {
316
+ date?: Partial<DocumentHijriDate>;
317
+ };
318
+
319
+ /** Read-only, host-supplied projection. Never copy these catalogs into a unit DocumentJson. */
320
+ type DocumentBookTarget = {
321
+ unitId: string;
322
+ ownerId: string;
323
+ key: string;
324
+ kind: DocumentLabelKind | 'section' | 'subsection' | 'subsubsection' | 'chapter' | 'appendix';
325
+ caption?: string;
326
+ displayLabel?: string;
327
+ manualKey?: string;
328
+ };
329
+ type DocumentBookContext = {
330
+ unitId: string;
331
+ references?: Reference2Json[];
332
+ targets?: DocumentBookTarget[];
333
+ };
334
+ type DocumentEditorMode = 'article' | 'book-content';
335
+
336
+ /** Phase-0 canonical book wire types. No book runtime or exported package endpoint. */
337
+
338
+ type BookMetaJson = {
339
+ title: string;
340
+ authors: string[];
341
+ date?: string;
342
+ language: 'ar';
343
+ direction: 'rtl';
344
+ numbering?: {
345
+ digit_form?: 'arabicIndic' | 'western';
346
+ chapter_heading?: 'ordinal-words' | 'digits';
347
+ appendix_heading?: 'letters' | 'digits';
348
+ };
349
+ };
350
+ type BookUnitType = 'abstract' | 'dedication' | 'acknowledgements' | 'preface' | 'abbreviations' | 'chapter' | 'appendix' | 'backmatter';
351
+ type BookUnitEntry = {
352
+ kind: 'document';
353
+ id: string;
354
+ type: BookUnitType;
355
+ title: string;
356
+ document_path: string;
357
+ label?: string;
358
+ numbered: boolean;
359
+ include_in_toc: boolean;
360
+ };
361
+ type BookGeneratedType = 'title-page' | 'table-of-contents' | 'list-of-figures' | 'list-of-tables' | 'bibliography';
362
+ type BookGeneratedEntry = {
363
+ kind: 'generated';
364
+ id: string;
365
+ generated: BookGeneratedType;
366
+ };
367
+ type BookEntry = BookUnitEntry | BookGeneratedEntry;
368
+ type BookManifestJson = {
369
+ node_type: 'BookManifest';
370
+ schema_version: 1;
371
+ id: string;
372
+ meta: BookMetaJson;
373
+ references_path: 'references.json';
374
+ /** One author-controlled total order, regardless of semantic unit type. */
375
+ entries: BookEntry[];
376
+ };
377
+ type BookReferencesJson = {
378
+ node_type: 'BookReferences';
379
+ schema_version: 1;
380
+ references: Reference2Json[];
381
+ };
382
+
383
+ type BookCommand = {
384
+ op: 'reorder_entries';
385
+ entry_ids: string[];
386
+ } | {
387
+ op: 'update_entry';
388
+ entry_id: string;
389
+ title?: string;
390
+ numbered?: boolean;
391
+ include_in_toc?: boolean;
392
+ label?: string | null;
393
+ } | {
394
+ op: 'set_meta';
395
+ meta: BookMetaJson;
396
+ } | {
397
+ op: 'set_references';
398
+ references: Reference2Json[];
399
+ } | {
400
+ op: 'insert_entry';
401
+ entry: BookEntry;
402
+ document?: DocumentJson;
403
+ index: number;
404
+ } | {
405
+ op: 'remove_entry';
406
+ entry_id: string;
407
+ };
408
+
409
+ type BookIssue = {
410
+ code: 'invalid_snapshot' | 'invalid_entry' | 'missing_document' | 'duplicate_entry' | 'duplicate_generated' | 'local_bibliography' | 'unstable_block_id' | 'duplicate_key' | 'invalid_key' | 'missing_citation' | 'missing_reference' | 'invalid_reference_kind';
411
+ path: string;
412
+ severity: 'error' | 'warning';
413
+ unit_id?: string;
414
+ block_id?: string;
415
+ token_id?: string;
416
+ key?: string;
417
+ };
418
+ type BookOutlineEntry = {
419
+ id: string;
420
+ kind: 'chapter' | 'appendix' | 'unit' | 'generated' | 'section' | 'subsection' | 'subsubsection';
421
+ title: string;
422
+ display_label: string;
423
+ level: number;
424
+ unit_id?: string;
425
+ parent_unit_id?: string;
426
+ numbered: boolean;
427
+ include_in_toc: boolean;
428
+ };
429
+ type BookTarget = DocumentBookTarget & {
430
+ numbered: boolean;
431
+ ordinal?: string;
432
+ };
433
+ type BookResolution = {
434
+ manifest_id: string;
435
+ outline: BookOutlineEntry[];
436
+ targets: BookTarget[];
437
+ citations: Array<{
438
+ key: string;
439
+ number: number;
440
+ display_label: string;
441
+ }>;
442
+ issues: BookIssue[];
443
+ };
444
+
445
+ type ImageAssetRef = {
446
+ assetId: string;
447
+ value?: string;
448
+ label?: string;
449
+ thumbUrl?: string;
450
+ };
451
+ type ImageBlockEditorRenderContext = {
452
+ blockId: string;
453
+ assetId?: string;
454
+ value: string;
455
+ resolvedUrl: string;
456
+ uiLocale: ButexUiLocale;
457
+ onSelectAsset: (ref: ImageAssetRef) => void;
458
+ onClearAsset: () => void;
459
+ defaultUi: ReactNode;
460
+ };
461
+
462
+ /** Controls which responsive interaction workflow a React editor uses. */
463
+ type ButexResponsiveMode = 'auto' | 'desktop' | 'compact';
464
+
465
+ type ButexDocumentEditorProps$1 = {
466
+ /** Opt-in chapter body editing. Article remains the default. */
467
+ mode?: DocumentEditorMode;
468
+ /** Read-only externally supplied book references/targets. */
469
+ bookContext?: DocumentBookContext;
470
+ initialDocument?: DocumentJson | DocumentNode;
471
+ /** Seed article metadata when JSON/node omits fields (JSON wins when present). */
472
+ documentMeta?: DocumentMetaProp;
473
+ className?: string;
474
+ debug?: boolean;
475
+ documentDirection?: 'rtl' | 'ltr';
476
+ equationSide?: EditorSide;
477
+ editableEquations?: boolean;
478
+ /** When true, render only the read-only document preview (no toolbar, editor panel, or equation drawer). */
479
+ previewOnly?: boolean;
480
+ uiLocale?: ButexUiLocale;
481
+ /** Selects the responsive interaction workflow. Automatic mode follows the layout viewport. */
482
+ responsiveMode?: ButexResponsiveMode;
483
+ mathOutput?: DocumentMathOutput;
484
+ /** Digit shaping for citation and bibliography numbers (western / arabicIndic / persianIndic). */
485
+ digitForm?: DigitFormId;
486
+ onDigitFormChange?: (digitForm: DigitFormId) => void;
487
+ /** Host maps assetId / literal value to a browser-loadable image URL (S3, CDN, local). */
488
+ resolveImageUrl?: (ref: {
489
+ assetId?: string;
490
+ value: string;
491
+ }) => string;
492
+ onRequestImagePick?: (ctx: {
493
+ blockId: string;
494
+ current: ImageAssetRef | null;
495
+ }) => Promise<ImageAssetRef | null> | ImageAssetRef | null;
496
+ listImageAssets?: () => Promise<ImageAssetRef[]> | ImageAssetRef[];
497
+ renderImageBlockEditor?: (ctx: ImageBlockEditorRenderContext) => ReactNode;
498
+ onDocumentChange?: (document: DocumentNode) => void;
499
+ /** Canonical JSON wire format for API/database persistence. */
500
+ onDocumentJsonChange?: (document: DocumentJson) => void;
501
+ onLatexChange?: (latex: string) => void;
502
+ };
503
+
504
+ type ButexDocumentEditorProps = ButexDocumentEditorProps$1 & {
505
+ /** Reports whether the current draft is safe for LaTeX compilation. */
506
+ onValidityChange?: (isValid: boolean) => void;
507
+ };
508
+
509
+ /** Book UI is deliberately stateless about persistence. The host owns auth, CAS, retries and history. */
510
+ type ButexBookEditorProps = {
511
+ manifest: BookManifestJson;
512
+ references: BookReferencesJson;
513
+ resolution: BookResolution;
514
+ loadUnit: (unitId: string) => Promise<DocumentJson>;
515
+ onUnitDraftChange: (unitId: string, document: DocumentJson) => void;
516
+ onStructureCommand: (command: BookCommand) => Promise<void>;
517
+ saveStatus?: Record<string, 'saved' | 'pending' | 'saving' | 'failed' | 'conflict'>;
518
+ onRequestImagePick?: ButexDocumentEditorProps['onRequestImagePick'];
519
+ resolveImageUrl?: ButexDocumentEditorProps['resolveImageUrl'];
520
+ initialUnitId?: string;
521
+ onActiveUnitChange?: (unitId: string | null) => void;
522
+ className?: string;
523
+ };
524
+ /** Only the active chapter has a mounted Document editor. Drafts for inactive units stay in memory. */
525
+ declare function ButexBookEditor({ manifest, references, resolution, loadUnit, onUnitDraftChange, onStructureCommand, saveStatus, onRequestImagePick, resolveImageUrl, initialUnitId, onActiveUnitChange, className, }: ButexBookEditorProps): react_jsx_runtime.JSX.Element;
526
+
527
+ export { ButexBookEditor, type ButexBookEditorProps };