@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.
package/dist/book.d.ts ADDED
@@ -0,0 +1,362 @@
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
+ source_latex?: string;
16
+ };
17
+ type ChainJson = {
18
+ node_type: 'ChainClass';
19
+ chain: ArabicNodeJson[];
20
+ };
21
+ declare class State {
22
+ }
23
+ declare class BaseAstNode {
24
+ state: State;
25
+ superscript: ChainNode | null;
26
+ subscript: ChainNode | null;
27
+ nodeType: string;
28
+ sourceLatex: string | null;
29
+ constructor(state?: State | null);
30
+ latex(): string;
31
+ arabicLatex(): string;
32
+ toArabicLatex(): string;
33
+ /** Latin-style scripts: `^{...}` and `_{...}` for english_json rendering. */
34
+ latexScripts(): string;
35
+ /**
36
+ * Arabic scripts use \\prescript{sup}{sub}{content} (matches reference Python output).
37
+ * Call with rendered strings for sup/sub chains (may be empty strings).
38
+ */
39
+ arabicLatexScripts(sup: string, sub: string, content: string): string;
40
+ }
41
+ declare class ChainNode {
42
+ chain: BaseAstNode[];
43
+ constructor(chain?: BaseAstNode[]);
44
+ latex(): string;
45
+ toEnglishLatex(): string;
46
+ /** RTL: reverse order relative to Latin chain (see test/ref_tests.txt). */
47
+ arabicLatex(): string;
48
+ toArabicLatex(): string;
49
+ }
50
+
51
+ type MathNode = {
52
+ nodeType: 'MathObject';
53
+ mathMode: string;
54
+ lines: ChainNode[];
55
+ closing: string;
56
+ };
57
+
58
+ type DocumentParseMode = 'english' | 'arabic';
59
+ type MathObject2Json = {
60
+ node_type: 'MathObject';
61
+ math_mode: string;
62
+ lines: ChainJson[];
63
+ closing: string;
64
+ /** Side used by the delimited source stored in the containing value/cell. */
65
+ source_side?: DocumentParseMode;
66
+ /** Preserve whether LaTeX export should prefer imported AST rendering or editor source. */
67
+ source_owner?: 'imported-structured' | 'editor';
68
+ label_enabled?: boolean;
69
+ label?: string;
70
+ numbered?: boolean;
71
+ };
72
+ /** Positional metadata for a raw-only span that has no structured equation AST. */
73
+ type RawMathObject2Json = {
74
+ node_type: 'RawMathObject';
75
+ label_enabled?: boolean;
76
+ label?: string;
77
+ numbered?: boolean;
78
+ };
79
+ type DocumentMathObjectJson = MathObject2Json | RawMathObject2Json;
80
+ type ReferenceFieldSeparator = ',' | '،';
81
+ type Reference2Json = {
82
+ key: string;
83
+ authors?: string;
84
+ title?: string;
85
+ year?: string;
86
+ url?: string;
87
+ venue?: string;
88
+ /** Bibliography field join: LTR `,` or Arabic `،`. Defaults to `،` when omitted. */
89
+ field_separator?: ReferenceFieldSeparator;
90
+ };
91
+ type HijriMonthId = 'محرم' | 'صفر' | 'ربيع الأول' | 'ربيع الآخر' | 'جمادى الأولى' | 'جمادى الآخرة' | 'رجب' | 'شعبان' | 'رمضان' | 'شوال' | 'ذو القعدة' | 'ذو الحجة';
92
+ type DocumentHijriDate = {
93
+ day: number;
94
+ month: HijriMonthId;
95
+ year: number;
96
+ };
97
+ type DocumentMeta = {
98
+ title: string;
99
+ authors: string;
100
+ date: DocumentHijriDate;
101
+ abstract: string;
102
+ };
103
+ type DocumentJson = {
104
+ node_type: 'DocumentObject';
105
+ meta?: DocumentMeta;
106
+ references?: Reference2Json[];
107
+ blocks: DocumentBlockJson[];
108
+ };
109
+ type DocumentInlineTokenIdJson = {
110
+ id: string;
111
+ kind: InlineToken2['kind'];
112
+ start: number;
113
+ end: number;
114
+ };
115
+ type DocumentInlineIdsJson = {
116
+ field_id: string;
117
+ tokens: DocumentInlineTokenIdJson[];
118
+ };
119
+ type DocumentBlockMetadata = {
120
+ source?: 'agent' | 'user';
121
+ };
122
+ type DocumentBlockJson = {
123
+ /** Stable identity used by headless commands. Legacy JSON may omit it. */
124
+ id?: string;
125
+ command: string;
126
+ value?: string;
127
+ formats?: TextFormatSpan2Json[];
128
+ inline_ids?: DocumentInlineIdsJson;
129
+ metadata?: DocumentBlockMetadata;
130
+ /** Stable host asset identity (e.g. S3 key / UUID); optional for \\includegraphics. */
131
+ asset_id?: string;
132
+ math_objects?: Array<DocumentMathObjectJson | null>;
133
+ options?: Record<string, string>;
134
+ closing?: string;
135
+ items?: DocumentListItemJson[];
136
+ rows?: string[][];
137
+ cell_formats?: TextFormatSpan2Json[][][];
138
+ cell_inline_ids?: DocumentInlineIdsJson[][];
139
+ columns?: string;
140
+ caption?: string;
141
+ /** Optional formatting sidecar for caption text spans. */
142
+ caption_formats?: TextFormatSpan2Json[];
143
+ /** Stable caption field/token identities; omitted by legacy documents. */
144
+ caption_inline_ids?: DocumentInlineIdsJson;
145
+ /** Caption-only structured math sidecar, independent from table cell math_objects. */
146
+ caption_math_objects?: Array<DocumentMathObjectJson | null>;
147
+ label?: string;
148
+ caption_enabled?: boolean;
149
+ label_enabled?: boolean;
150
+ centered?: boolean;
151
+ };
152
+ type DocumentListItemJson = {
153
+ id?: string;
154
+ value: string;
155
+ formats?: TextFormatSpan2Json[];
156
+ inline_ids?: DocumentInlineIdsJson;
157
+ math_objects?: Array<DocumentMathObjectJson | null>;
158
+ blocks?: DocumentBlockJson[];
159
+ };
160
+ type TextStyle2 = {
161
+ bold?: true;
162
+ italic?: true;
163
+ underline?: true;
164
+ };
165
+ type TextFormatSpan2Json = {
166
+ start: number;
167
+ end: number;
168
+ bold?: boolean;
169
+ italic?: boolean;
170
+ underline?: boolean;
171
+ };
172
+ type TextToken2 = {
173
+ id: string;
174
+ kind: 'text';
175
+ text: string;
176
+ style?: TextStyle2;
177
+ };
178
+ type MathToken2 = {
179
+ id: string;
180
+ kind: 'math';
181
+ display: boolean;
182
+ opening: string;
183
+ closing: string;
184
+ source: string;
185
+ sourceSide?: DocumentParseMode;
186
+ math: MathNode | null;
187
+ editable: boolean;
188
+ reason?: string;
189
+ sourceOwner: 'imported-structured' | 'raw' | 'editor';
190
+ /** When true on display math, export as equation env with \\label. */
191
+ labelEnabled?: boolean;
192
+ label?: string;
193
+ /** Independent display-equation numbering override; absent means legacy semantics. */
194
+ numbered?: boolean;
195
+ };
196
+ type CiteToken2 = {
197
+ id: string;
198
+ kind: 'cite';
199
+ keys: string[];
200
+ };
201
+ type RefToken2 = {
202
+ id: string;
203
+ kind: 'ref';
204
+ keys: string[];
205
+ refCommand: 'ref' | 'eqref';
206
+ };
207
+ type InlineToken2 = TextToken2 | MathToken2 | CiteToken2 | RefToken2;
208
+
209
+ /** Phase-0 canonical book wire types. No book runtime or exported package endpoint. */
210
+
211
+ type BookMetaJson = {
212
+ title: string;
213
+ authors: string[];
214
+ date?: string;
215
+ language: 'ar';
216
+ direction: 'rtl';
217
+ numbering?: {
218
+ digit_form?: 'arabicIndic' | 'western';
219
+ chapter_heading?: 'ordinal-words' | 'digits';
220
+ appendix_heading?: 'letters' | 'digits';
221
+ };
222
+ };
223
+ type BookUnitType = 'abstract' | 'dedication' | 'acknowledgements' | 'preface' | 'abbreviations' | 'chapter' | 'appendix' | 'backmatter';
224
+ type BookUnitEntry = {
225
+ kind: 'document';
226
+ id: string;
227
+ type: BookUnitType;
228
+ title: string;
229
+ document_path: string;
230
+ label?: string;
231
+ numbered: boolean;
232
+ include_in_toc: boolean;
233
+ };
234
+ type BookGeneratedType = 'title-page' | 'table-of-contents' | 'list-of-figures' | 'list-of-tables' | 'bibliography';
235
+ type BookGeneratedEntry = {
236
+ kind: 'generated';
237
+ id: string;
238
+ generated: BookGeneratedType;
239
+ };
240
+ type BookEntry = BookUnitEntry | BookGeneratedEntry;
241
+ type BookManifestJson = {
242
+ node_type: 'BookManifest';
243
+ schema_version: 1;
244
+ id: string;
245
+ meta: BookMetaJson;
246
+ references_path: 'references.json';
247
+ /** One author-controlled total order, regardless of semantic unit type. */
248
+ entries: BookEntry[];
249
+ };
250
+ type BookReferencesJson = {
251
+ node_type: 'BookReferences';
252
+ schema_version: 1;
253
+ references: Reference2Json[];
254
+ };
255
+ /** In-memory processing snapshot: Al-Bayan persists unit revisions separately. */
256
+ type BookSnapshotJson = {
257
+ manifest: BookManifestJson;
258
+ references: BookReferencesJson;
259
+ documents: Record<string, DocumentJson>;
260
+ };
261
+
262
+ declare class BookContractError extends Error {
263
+ readonly code = "invalid_book";
264
+ constructor(message: string);
265
+ }
266
+ /** Structural validation is deterministic and preserves every authored title and key. */
267
+ declare function normalizeBookSnapshot(value: unknown): BookSnapshotJson;
268
+
269
+ type DocumentLabelKind = 'fig' | 'tab' | 'eq';
270
+
271
+ /** Read-only, host-supplied projection. Never copy these catalogs into a unit DocumentJson. */
272
+ type DocumentBookTarget = {
273
+ unitId: string;
274
+ ownerId: string;
275
+ key: string;
276
+ kind: DocumentLabelKind | 'section' | 'subsection' | 'subsubsection' | 'chapter' | 'appendix';
277
+ caption?: string;
278
+ displayLabel?: string;
279
+ manualKey?: string;
280
+ };
281
+ type DocumentBookContext = {
282
+ unitId: string;
283
+ references?: Reference2Json[];
284
+ targets?: DocumentBookTarget[];
285
+ };
286
+
287
+ type BookCommand = {
288
+ op: 'reorder_entries';
289
+ entry_ids: string[];
290
+ } | {
291
+ op: 'update_entry';
292
+ entry_id: string;
293
+ title?: string;
294
+ numbered?: boolean;
295
+ include_in_toc?: boolean;
296
+ label?: string | null;
297
+ } | {
298
+ op: 'set_meta';
299
+ meta: BookMetaJson;
300
+ } | {
301
+ op: 'set_references';
302
+ references: Reference2Json[];
303
+ } | {
304
+ op: 'insert_entry';
305
+ entry: BookEntry;
306
+ document?: DocumentJson;
307
+ index: number;
308
+ } | {
309
+ op: 'remove_entry';
310
+ entry_id: string;
311
+ };
312
+ /** Validate untrusted book-command JSON before it reaches the typed reducer. */
313
+ declare function parseBookCommand(value: unknown): BookCommand;
314
+ /** Commands only edit a manifest/catalog; individual Document commands remain on /v1/document. */
315
+ declare function applyBookCommand(raw: unknown, command: BookCommand): BookSnapshotJson;
316
+
317
+ type BookIssue = {
318
+ 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';
319
+ path: string;
320
+ severity: 'error' | 'warning';
321
+ unit_id?: string;
322
+ block_id?: string;
323
+ token_id?: string;
324
+ key?: string;
325
+ };
326
+ type BookOutlineEntry = {
327
+ id: string;
328
+ kind: 'chapter' | 'appendix' | 'unit' | 'generated' | 'section' | 'subsection' | 'subsubsection';
329
+ title: string;
330
+ display_label: string;
331
+ level: number;
332
+ unit_id?: string;
333
+ parent_unit_id?: string;
334
+ numbered: boolean;
335
+ include_in_toc: boolean;
336
+ };
337
+ type BookTarget = DocumentBookTarget & {
338
+ numbered: boolean;
339
+ ordinal?: string;
340
+ };
341
+ type BookResolution = {
342
+ manifest_id: string;
343
+ outline: BookOutlineEntry[];
344
+ targets: BookTarget[];
345
+ citations: Array<{
346
+ key: string;
347
+ number: number;
348
+ display_label: string;
349
+ }>;
350
+ issues: BookIssue[];
351
+ };
352
+ /** One global, read-only catalog; no ordinals or shared bibliography are written into chapter JSON. */
353
+ declare function resolveBookSnapshot(raw: unknown): BookResolution;
354
+ declare function bookContextForUnit(snapshot: BookSnapshotJson, unitId: string): DocumentBookContext;
355
+ declare function bookOutline(snapshot: unknown): BookOutlineEntry[];
356
+ declare function getBookReferenceIndex(snapshot: unknown): BookResolution;
357
+ declare function validateBookSnapshot(snapshot: unknown): {
358
+ valid: boolean;
359
+ issues: BookIssue[];
360
+ };
361
+
362
+ export { type BookCommand, BookContractError, type BookEntry, type BookGeneratedEntry, type BookGeneratedType, type BookIssue, type BookManifestJson, type BookMetaJson, type BookOutlineEntry, type BookReferencesJson, type BookResolution, type BookSnapshotJson, type BookTarget, type BookUnitEntry, type BookUnitType, applyBookCommand, bookContextForUnit, bookOutline, getBookReferenceIndex, normalizeBookSnapshot, parseBookCommand, resolveBookSnapshot, validateBookSnapshot };