@drghaliasri/butex 6.0.0 → 6.1.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.
@@ -185,12 +185,27 @@ type Document2Json = {
185
185
  references?: Reference2Json[];
186
186
  blocks: Document2BlockJson[];
187
187
  };
188
+ type Document2InlineTokenIdJson = {
189
+ id: string;
190
+ kind: InlineToken2['kind'];
191
+ start: number;
192
+ end: number;
193
+ };
194
+ type Document2InlineIdsJson = {
195
+ field_id: string;
196
+ tokens: Document2InlineTokenIdJson[];
197
+ };
198
+ type Document2BlockMetadata = {
199
+ source?: 'agent' | 'user';
200
+ };
188
201
  type Document2BlockJson = {
189
202
  /** Stable identity used by headless commands. Legacy JSON may omit it. */
190
203
  id?: string;
191
204
  command: string;
192
205
  value?: string;
193
206
  formats?: TextFormatSpan2Json[];
207
+ inline_ids?: Document2InlineIdsJson;
208
+ metadata?: Document2BlockMetadata;
194
209
  /** Stable host asset identity (e.g. S3 key / UUID); optional for \\includegraphics. */
195
210
  asset_id?: string;
196
211
  math_objects?: Array<Document2MathObjectJson | null>;
@@ -199,6 +214,7 @@ type Document2BlockJson = {
199
214
  items?: Document2ListItemJson[];
200
215
  rows?: string[][];
201
216
  cell_formats?: TextFormatSpan2Json[][][];
217
+ cell_inline_ids?: Document2InlineIdsJson[][];
202
218
  columns?: string;
203
219
  caption?: string;
204
220
  label?: string;
@@ -207,8 +223,10 @@ type Document2BlockJson = {
207
223
  centered?: boolean;
208
224
  };
209
225
  type Document2ListItemJson = {
226
+ id?: string;
210
227
  value: string;
211
228
  formats?: TextFormatSpan2Json[];
229
+ inline_ids?: Document2InlineIdsJson;
212
230
  math_objects?: Array<Document2MathObjectJson | null>;
213
231
  blocks?: Document2BlockJson[];
214
232
  };
@@ -283,6 +301,7 @@ type TextBlock2 = {
283
301
  kind: 'textBlock';
284
302
  command: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph';
285
303
  field: InlineField2;
304
+ metadata?: Document2BlockMetadata;
286
305
  /** When true on \\paragraph, center in preview and LaTeX export. */
287
306
  centered?: boolean;
288
307
  };
@@ -297,6 +316,7 @@ type ListBlock2 = {
297
316
  command: '\\begin{itemize}' | '\\begin{enumerate}';
298
317
  closing: '\\end{itemize}' | '\\end{enumerate}';
299
318
  items: ListItem2[];
319
+ metadata?: Document2BlockMetadata;
300
320
  };
301
321
  type FloatMeta2 = {
302
322
  centered: boolean;
@@ -312,6 +332,7 @@ type TableBlock2 = {
312
332
  closing: '\\end{tabular}';
313
333
  columns: string;
314
334
  rows: InlineField2[][];
335
+ metadata?: Document2BlockMetadata;
315
336
  } & FloatMeta2;
316
337
  type ImageBlock2 = {
317
338
  id: string;
@@ -321,18 +342,21 @@ type ImageBlock2 = {
321
342
  /** Host asset identity from wire `asset_id`; preserved across value edits. */
322
343
  assetId?: string;
323
344
  options: Record<string, string>;
345
+ metadata?: Document2BlockMetadata;
324
346
  } & FloatMeta2;
325
347
  type BibliographyBlock2 = {
326
348
  id: string;
327
349
  kind: 'bibliography';
328
350
  command: '\\begin{thebibliography}';
329
351
  closing: '\\end{thebibliography}';
352
+ metadata?: Document2BlockMetadata;
330
353
  };
331
354
  type RawBlock2 = {
332
355
  id: string;
333
356
  kind: 'raw';
334
357
  command: '\\raw';
335
358
  value: string;
359
+ metadata?: Document2BlockMetadata;
336
360
  };
337
361
  type Document2Block = TextBlock2 | ListBlock2 | TableBlock2 | ImageBlock2 | BibliographyBlock2 | RawBlock2;
338
362
  type Document2Node = {
@@ -420,11 +444,13 @@ type PreviewBlock2 = {
420
444
  id: string;
421
445
  level: 1 | 2 | 3;
422
446
  inlines: PreviewInline2[];
447
+ metadata?: Document2BlockMetadata;
423
448
  } | {
424
449
  kind: 'paragraph';
425
450
  id: string;
426
451
  inlines: PreviewInline2[];
427
452
  centered?: boolean;
453
+ metadata?: Document2BlockMetadata;
428
454
  } | {
429
455
  kind: 'list';
430
456
  id: string;
@@ -434,6 +460,7 @@ type PreviewBlock2 = {
434
460
  inlines: PreviewInline2[];
435
461
  blocks: PreviewBlock2[];
436
462
  }>;
463
+ metadata?: Document2BlockMetadata;
437
464
  } | {
438
465
  kind: 'table';
439
466
  id: string;
@@ -441,6 +468,7 @@ type PreviewBlock2 = {
441
468
  caption?: string;
442
469
  label?: string;
443
470
  numberLabel?: string;
471
+ metadata?: Document2BlockMetadata;
444
472
  } | {
445
473
  kind: 'image';
446
474
  id: string;
@@ -450,6 +478,7 @@ type PreviewBlock2 = {
450
478
  caption?: string;
451
479
  label?: string;
452
480
  numberLabel?: string;
481
+ metadata?: Document2BlockMetadata;
453
482
  } | {
454
483
  kind: 'bibliography';
455
484
  id: string;
@@ -464,11 +493,13 @@ type PreviewBlock2 = {
464
493
  venue: string;
465
494
  fieldSeparator: ReferenceFieldSeparator;
466
495
  }>;
496
+ metadata?: Document2BlockMetadata;
467
497
  }
468
498
  /** Preview-only: raw / unknown blocks are omitted from preview until we add proper rendering. */
469
499
  | {
470
500
  kind: 'omit';
471
501
  id: string;
502
+ metadata?: Document2BlockMetadata;
472
503
  };
473
504
  type MathIsland2 = {
474
505
  id: string;
@@ -649,36 +680,153 @@ declare function updateDocument2Meta(document: Document2Node, patch: Document2Me
649
680
 
650
681
  type Document2TextBlockKind = 'section' | 'subsection' | 'subsubsection' | 'paragraph';
651
682
  type Document2Anchor = {
683
+ before_block_id: string;
684
+ } | {
652
685
  after_block_id: string;
653
686
  } | {
654
687
  end: true;
655
688
  };
656
- type Document2Command = {
689
+ type Document2InlineAnchor = {
690
+ before_token_id: string;
691
+ } | {
692
+ after_token_id: string;
693
+ } | {
694
+ start: true;
695
+ } | {
696
+ end: true;
697
+ };
698
+ type Document2ListItemAnchor = {
699
+ before_item_id: string;
700
+ } | {
701
+ after_item_id: string;
702
+ } | {
703
+ end: true;
704
+ };
705
+ type Document2InlineTokenInput = {
706
+ kind: 'text';
707
+ text: string;
708
+ style?: TextStyle2;
709
+ } | {
710
+ kind: 'math';
711
+ source: string;
712
+ math_object: MathObject2Json;
713
+ } | {
714
+ kind: 'cite';
715
+ keys: string[];
716
+ } | {
717
+ kind: 'ref';
718
+ keys: string[];
719
+ ref_command: 'ref' | 'eqref';
720
+ };
721
+ type BlockInsertion = {
722
+ anchor: Document2Anchor;
723
+ metadata?: Document2BlockMetadata;
724
+ };
725
+ type Document2Command = ({
657
726
  op: 'insert_text_block';
658
727
  kind: Document2TextBlockKind;
659
728
  text: string;
660
- anchor: Document2Anchor;
661
- } | {
729
+ } & BlockInsertion) | {
662
730
  op: 'replace_text_block';
663
731
  block_id: string;
664
732
  text: string;
665
733
  } | {
666
734
  op: 'remove_block';
667
735
  block_id: string;
668
- } | {
736
+ } | ({
669
737
  op: 'insert_figure';
670
738
  asset_id: string;
671
739
  value?: string;
672
740
  caption?: string;
673
741
  label?: string;
674
- anchor: Document2Anchor;
742
+ } & BlockInsertion) | {
743
+ op: 'insert_inline_token';
744
+ field_id: string;
745
+ token: Document2InlineTokenInput;
746
+ anchor: Document2InlineAnchor;
747
+ } | {
748
+ op: 'replace_inline_token';
749
+ field_id: string;
750
+ token_id: string;
751
+ token: Document2InlineTokenInput;
752
+ } | {
753
+ op: 'remove_inline_token';
754
+ field_id: string;
755
+ token_id: string;
756
+ } | ({
757
+ op: 'insert_list';
758
+ ordered: boolean;
759
+ items: string[];
760
+ } & BlockInsertion) | {
761
+ op: 'insert_list_item';
762
+ list_id: string;
763
+ text: string;
764
+ anchor: Document2ListItemAnchor;
765
+ } | {
766
+ op: 'replace_list_item';
767
+ list_id: string;
768
+ item_id: string;
769
+ text: string;
770
+ } | {
771
+ op: 'remove_list_item';
772
+ list_id: string;
773
+ item_id: string;
774
+ } | {
775
+ op: 'move_list_item';
776
+ list_id: string;
777
+ item_id: string;
778
+ anchor: Document2ListItemAnchor;
779
+ } | ({
780
+ op: 'insert_table';
781
+ rows: string[][];
782
+ columns: string;
783
+ caption?: string;
784
+ label?: string;
785
+ } & BlockInsertion) | {
786
+ op: 'replace_table_cell';
787
+ table_id: string;
788
+ row_index: number;
789
+ column_index: number;
790
+ text: string;
791
+ } | {
792
+ op: 'insert_table_row';
793
+ table_id: string;
794
+ index: number;
795
+ values: string[];
796
+ } | {
797
+ op: 'remove_table_row';
798
+ table_id: string;
799
+ index: number;
800
+ } | {
801
+ op: 'move_table_row';
802
+ table_id: string;
803
+ from_index: number;
804
+ to_index: number;
805
+ } | {
806
+ op: 'insert_table_column';
807
+ table_id: string;
808
+ index: number;
809
+ values: string[];
810
+ columns: string;
811
+ } | {
812
+ op: 'remove_table_column';
813
+ table_id: string;
814
+ index: number;
815
+ columns: string;
816
+ } | {
817
+ op: 'move_table_column';
818
+ table_id: string;
819
+ from_index: number;
820
+ to_index: number;
821
+ columns: string;
675
822
  };
676
- type Document2CommandErrorCode = 'invalid_document' | 'invalid_command' | 'missing_block_id' | 'duplicate_block_id' | 'anchor_not_found' | 'block_not_found' | 'block_kind_mismatch' | 'unsupported_inline_content';
823
+ 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';
677
824
  declare class Document2CommandError extends Error {
678
825
  readonly code: Document2CommandErrorCode;
679
826
  constructor(code: Document2CommandErrorCode, message: string);
680
827
  }
681
- /** Apply one validated, top-level command and return canonical JSON. */
828
+
829
+ /** Apply one validated command to canonical JSON without mutating caller input. */
682
830
  declare function applyDocument2Command(json: Document2Json, commandInput: Document2Command): Document2Json;
683
831
 
684
832
  type Document2OutlineKind = 'section' | 'subsection' | 'subsubsection' | 'paragraph' | 'list' | 'table' | 'figure' | 'bibliography' | 'raw';
@@ -824,4 +972,4 @@ type Document2PreviewOptions = {
824
972
  };
825
973
  declare function document2Preview(document: Document2Node, output?: Document2MathOutput, equationSide?: EditorSide, previewOptions?: Document2PreviewOptions): Document2Preview;
826
974
 
827
- 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 Document2Command, Document2CommandError, type Document2CommandErrorCode, type Document2Diagnostic, type Document2Direction, type Document2HijriDate, type Document2HistoryStacks, type Document2ImageAssetRef, type Document2Json, type Document2KeyError, type Document2KeyNamespace, type Document2LabelEntry, type Document2LabelKind, type Document2LatexOptions, type Document2MathObjectJson, type Document2MathOutput, type Document2Meta, type Document2MetaProp, type Document2Node, type Document2OutlineEntry, type Document2OutlineKind, type Document2Preview, type Document2PreviewOptions, type Document2TextBlockKind, 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 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, document2HasAbstract, document2HasMaketitle, document2HasTitleStack, document2HistoryCanRedo, document2HistoryCanUndo, document2KeyError, document2Latex, document2Outline, document2Preview, emptyBlockSelection, emptyDocument2Meta, ensureDocument2BibliographyBlock, extendBlockSelectionFromAnchor, fillDocument2MetaGaps, findFirstInlineField, formatBibliographyNumber, formatCiteLabel, formatFloatCaptionPreview, formatFloatCaptionTitle, formatHijriDate, formatRefLabel, fromDocumentJson2, getArabicXeLatexPreamble, hijriMonthLabel, inlineFieldLatex, insertCiteTokenAtCaret, insertDocument2BlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, 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 };
975
+ 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 Document2Command, Document2CommandError, type Document2CommandErrorCode, type Document2Diagnostic, type Document2Direction, type Document2HijriDate, type Document2HistoryStacks, type Document2ImageAssetRef, 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 Document2TextBlockKind, 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, document2HasAbstract, document2HasMaketitle, document2HasTitleStack, document2HistoryCanRedo, document2HistoryCanUndo, document2KeyError, document2Latex, document2Outline, document2Preview, emptyBlockSelection, emptyDocument2Meta, ensureDocument2BibliographyBlock, extendBlockSelectionFromAnchor, fillDocument2MetaGaps, findFirstInlineField, formatBibliographyNumber, formatCiteLabel, formatFloatCaptionPreview, formatFloatCaptionTitle, formatHijriDate, formatRefLabel, fromDocumentJson2, getArabicXeLatexPreamble, hijriMonthLabel, inlineFieldLatex, insertCiteTokenAtCaret, insertDocument2BlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, 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 };
@@ -185,12 +185,27 @@ type Document2Json = {
185
185
  references?: Reference2Json[];
186
186
  blocks: Document2BlockJson[];
187
187
  };
188
+ type Document2InlineTokenIdJson = {
189
+ id: string;
190
+ kind: InlineToken2['kind'];
191
+ start: number;
192
+ end: number;
193
+ };
194
+ type Document2InlineIdsJson = {
195
+ field_id: string;
196
+ tokens: Document2InlineTokenIdJson[];
197
+ };
198
+ type Document2BlockMetadata = {
199
+ source?: 'agent' | 'user';
200
+ };
188
201
  type Document2BlockJson = {
189
202
  /** Stable identity used by headless commands. Legacy JSON may omit it. */
190
203
  id?: string;
191
204
  command: string;
192
205
  value?: string;
193
206
  formats?: TextFormatSpan2Json[];
207
+ inline_ids?: Document2InlineIdsJson;
208
+ metadata?: Document2BlockMetadata;
194
209
  /** Stable host asset identity (e.g. S3 key / UUID); optional for \\includegraphics. */
195
210
  asset_id?: string;
196
211
  math_objects?: Array<Document2MathObjectJson | null>;
@@ -199,6 +214,7 @@ type Document2BlockJson = {
199
214
  items?: Document2ListItemJson[];
200
215
  rows?: string[][];
201
216
  cell_formats?: TextFormatSpan2Json[][][];
217
+ cell_inline_ids?: Document2InlineIdsJson[][];
202
218
  columns?: string;
203
219
  caption?: string;
204
220
  label?: string;
@@ -207,8 +223,10 @@ type Document2BlockJson = {
207
223
  centered?: boolean;
208
224
  };
209
225
  type Document2ListItemJson = {
226
+ id?: string;
210
227
  value: string;
211
228
  formats?: TextFormatSpan2Json[];
229
+ inline_ids?: Document2InlineIdsJson;
212
230
  math_objects?: Array<Document2MathObjectJson | null>;
213
231
  blocks?: Document2BlockJson[];
214
232
  };
@@ -283,6 +301,7 @@ type TextBlock2 = {
283
301
  kind: 'textBlock';
284
302
  command: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph';
285
303
  field: InlineField2;
304
+ metadata?: Document2BlockMetadata;
286
305
  /** When true on \\paragraph, center in preview and LaTeX export. */
287
306
  centered?: boolean;
288
307
  };
@@ -297,6 +316,7 @@ type ListBlock2 = {
297
316
  command: '\\begin{itemize}' | '\\begin{enumerate}';
298
317
  closing: '\\end{itemize}' | '\\end{enumerate}';
299
318
  items: ListItem2[];
319
+ metadata?: Document2BlockMetadata;
300
320
  };
301
321
  type FloatMeta2 = {
302
322
  centered: boolean;
@@ -312,6 +332,7 @@ type TableBlock2 = {
312
332
  closing: '\\end{tabular}';
313
333
  columns: string;
314
334
  rows: InlineField2[][];
335
+ metadata?: Document2BlockMetadata;
315
336
  } & FloatMeta2;
316
337
  type ImageBlock2 = {
317
338
  id: string;
@@ -321,18 +342,21 @@ type ImageBlock2 = {
321
342
  /** Host asset identity from wire `asset_id`; preserved across value edits. */
322
343
  assetId?: string;
323
344
  options: Record<string, string>;
345
+ metadata?: Document2BlockMetadata;
324
346
  } & FloatMeta2;
325
347
  type BibliographyBlock2 = {
326
348
  id: string;
327
349
  kind: 'bibliography';
328
350
  command: '\\begin{thebibliography}';
329
351
  closing: '\\end{thebibliography}';
352
+ metadata?: Document2BlockMetadata;
330
353
  };
331
354
  type RawBlock2 = {
332
355
  id: string;
333
356
  kind: 'raw';
334
357
  command: '\\raw';
335
358
  value: string;
359
+ metadata?: Document2BlockMetadata;
336
360
  };
337
361
  type Document2Block = TextBlock2 | ListBlock2 | TableBlock2 | ImageBlock2 | BibliographyBlock2 | RawBlock2;
338
362
  type Document2Node = {
@@ -420,11 +444,13 @@ type PreviewBlock2 = {
420
444
  id: string;
421
445
  level: 1 | 2 | 3;
422
446
  inlines: PreviewInline2[];
447
+ metadata?: Document2BlockMetadata;
423
448
  } | {
424
449
  kind: 'paragraph';
425
450
  id: string;
426
451
  inlines: PreviewInline2[];
427
452
  centered?: boolean;
453
+ metadata?: Document2BlockMetadata;
428
454
  } | {
429
455
  kind: 'list';
430
456
  id: string;
@@ -434,6 +460,7 @@ type PreviewBlock2 = {
434
460
  inlines: PreviewInline2[];
435
461
  blocks: PreviewBlock2[];
436
462
  }>;
463
+ metadata?: Document2BlockMetadata;
437
464
  } | {
438
465
  kind: 'table';
439
466
  id: string;
@@ -441,6 +468,7 @@ type PreviewBlock2 = {
441
468
  caption?: string;
442
469
  label?: string;
443
470
  numberLabel?: string;
471
+ metadata?: Document2BlockMetadata;
444
472
  } | {
445
473
  kind: 'image';
446
474
  id: string;
@@ -450,6 +478,7 @@ type PreviewBlock2 = {
450
478
  caption?: string;
451
479
  label?: string;
452
480
  numberLabel?: string;
481
+ metadata?: Document2BlockMetadata;
453
482
  } | {
454
483
  kind: 'bibliography';
455
484
  id: string;
@@ -464,11 +493,13 @@ type PreviewBlock2 = {
464
493
  venue: string;
465
494
  fieldSeparator: ReferenceFieldSeparator;
466
495
  }>;
496
+ metadata?: Document2BlockMetadata;
467
497
  }
468
498
  /** Preview-only: raw / unknown blocks are omitted from preview until we add proper rendering. */
469
499
  | {
470
500
  kind: 'omit';
471
501
  id: string;
502
+ metadata?: Document2BlockMetadata;
472
503
  };
473
504
  type MathIsland2 = {
474
505
  id: string;
@@ -649,36 +680,153 @@ declare function updateDocument2Meta(document: Document2Node, patch: Document2Me
649
680
 
650
681
  type Document2TextBlockKind = 'section' | 'subsection' | 'subsubsection' | 'paragraph';
651
682
  type Document2Anchor = {
683
+ before_block_id: string;
684
+ } | {
652
685
  after_block_id: string;
653
686
  } | {
654
687
  end: true;
655
688
  };
656
- type Document2Command = {
689
+ type Document2InlineAnchor = {
690
+ before_token_id: string;
691
+ } | {
692
+ after_token_id: string;
693
+ } | {
694
+ start: true;
695
+ } | {
696
+ end: true;
697
+ };
698
+ type Document2ListItemAnchor = {
699
+ before_item_id: string;
700
+ } | {
701
+ after_item_id: string;
702
+ } | {
703
+ end: true;
704
+ };
705
+ type Document2InlineTokenInput = {
706
+ kind: 'text';
707
+ text: string;
708
+ style?: TextStyle2;
709
+ } | {
710
+ kind: 'math';
711
+ source: string;
712
+ math_object: MathObject2Json;
713
+ } | {
714
+ kind: 'cite';
715
+ keys: string[];
716
+ } | {
717
+ kind: 'ref';
718
+ keys: string[];
719
+ ref_command: 'ref' | 'eqref';
720
+ };
721
+ type BlockInsertion = {
722
+ anchor: Document2Anchor;
723
+ metadata?: Document2BlockMetadata;
724
+ };
725
+ type Document2Command = ({
657
726
  op: 'insert_text_block';
658
727
  kind: Document2TextBlockKind;
659
728
  text: string;
660
- anchor: Document2Anchor;
661
- } | {
729
+ } & BlockInsertion) | {
662
730
  op: 'replace_text_block';
663
731
  block_id: string;
664
732
  text: string;
665
733
  } | {
666
734
  op: 'remove_block';
667
735
  block_id: string;
668
- } | {
736
+ } | ({
669
737
  op: 'insert_figure';
670
738
  asset_id: string;
671
739
  value?: string;
672
740
  caption?: string;
673
741
  label?: string;
674
- anchor: Document2Anchor;
742
+ } & BlockInsertion) | {
743
+ op: 'insert_inline_token';
744
+ field_id: string;
745
+ token: Document2InlineTokenInput;
746
+ anchor: Document2InlineAnchor;
747
+ } | {
748
+ op: 'replace_inline_token';
749
+ field_id: string;
750
+ token_id: string;
751
+ token: Document2InlineTokenInput;
752
+ } | {
753
+ op: 'remove_inline_token';
754
+ field_id: string;
755
+ token_id: string;
756
+ } | ({
757
+ op: 'insert_list';
758
+ ordered: boolean;
759
+ items: string[];
760
+ } & BlockInsertion) | {
761
+ op: 'insert_list_item';
762
+ list_id: string;
763
+ text: string;
764
+ anchor: Document2ListItemAnchor;
765
+ } | {
766
+ op: 'replace_list_item';
767
+ list_id: string;
768
+ item_id: string;
769
+ text: string;
770
+ } | {
771
+ op: 'remove_list_item';
772
+ list_id: string;
773
+ item_id: string;
774
+ } | {
775
+ op: 'move_list_item';
776
+ list_id: string;
777
+ item_id: string;
778
+ anchor: Document2ListItemAnchor;
779
+ } | ({
780
+ op: 'insert_table';
781
+ rows: string[][];
782
+ columns: string;
783
+ caption?: string;
784
+ label?: string;
785
+ } & BlockInsertion) | {
786
+ op: 'replace_table_cell';
787
+ table_id: string;
788
+ row_index: number;
789
+ column_index: number;
790
+ text: string;
791
+ } | {
792
+ op: 'insert_table_row';
793
+ table_id: string;
794
+ index: number;
795
+ values: string[];
796
+ } | {
797
+ op: 'remove_table_row';
798
+ table_id: string;
799
+ index: number;
800
+ } | {
801
+ op: 'move_table_row';
802
+ table_id: string;
803
+ from_index: number;
804
+ to_index: number;
805
+ } | {
806
+ op: 'insert_table_column';
807
+ table_id: string;
808
+ index: number;
809
+ values: string[];
810
+ columns: string;
811
+ } | {
812
+ op: 'remove_table_column';
813
+ table_id: string;
814
+ index: number;
815
+ columns: string;
816
+ } | {
817
+ op: 'move_table_column';
818
+ table_id: string;
819
+ from_index: number;
820
+ to_index: number;
821
+ columns: string;
675
822
  };
676
- type Document2CommandErrorCode = 'invalid_document' | 'invalid_command' | 'missing_block_id' | 'duplicate_block_id' | 'anchor_not_found' | 'block_not_found' | 'block_kind_mismatch' | 'unsupported_inline_content';
823
+ 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';
677
824
  declare class Document2CommandError extends Error {
678
825
  readonly code: Document2CommandErrorCode;
679
826
  constructor(code: Document2CommandErrorCode, message: string);
680
827
  }
681
- /** Apply one validated, top-level command and return canonical JSON. */
828
+
829
+ /** Apply one validated command to canonical JSON without mutating caller input. */
682
830
  declare function applyDocument2Command(json: Document2Json, commandInput: Document2Command): Document2Json;
683
831
 
684
832
  type Document2OutlineKind = 'section' | 'subsection' | 'subsubsection' | 'paragraph' | 'list' | 'table' | 'figure' | 'bibliography' | 'raw';
@@ -824,4 +972,4 @@ type Document2PreviewOptions = {
824
972
  };
825
973
  declare function document2Preview(document: Document2Node, output?: Document2MathOutput, equationSide?: EditorSide, previewOptions?: Document2PreviewOptions): Document2Preview;
826
974
 
827
- 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 Document2Command, Document2CommandError, type Document2CommandErrorCode, type Document2Diagnostic, type Document2Direction, type Document2HijriDate, type Document2HistoryStacks, type Document2ImageAssetRef, type Document2Json, type Document2KeyError, type Document2KeyNamespace, type Document2LabelEntry, type Document2LabelKind, type Document2LatexOptions, type Document2MathObjectJson, type Document2MathOutput, type Document2Meta, type Document2MetaProp, type Document2Node, type Document2OutlineEntry, type Document2OutlineKind, type Document2Preview, type Document2PreviewOptions, type Document2TextBlockKind, 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 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, document2HasAbstract, document2HasMaketitle, document2HasTitleStack, document2HistoryCanRedo, document2HistoryCanUndo, document2KeyError, document2Latex, document2Outline, document2Preview, emptyBlockSelection, emptyDocument2Meta, ensureDocument2BibliographyBlock, extendBlockSelectionFromAnchor, fillDocument2MetaGaps, findFirstInlineField, formatBibliographyNumber, formatCiteLabel, formatFloatCaptionPreview, formatFloatCaptionTitle, formatHijriDate, formatRefLabel, fromDocumentJson2, getArabicXeLatexPreamble, hijriMonthLabel, inlineFieldLatex, insertCiteTokenAtCaret, insertDocument2BlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, 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 };
975
+ 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 Document2Command, Document2CommandError, type Document2CommandErrorCode, type Document2Diagnostic, type Document2Direction, type Document2HijriDate, type Document2HistoryStacks, type Document2ImageAssetRef, 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 Document2TextBlockKind, 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, document2HasAbstract, document2HasMaketitle, document2HasTitleStack, document2HistoryCanRedo, document2HistoryCanUndo, document2KeyError, document2Latex, document2Outline, document2Preview, emptyBlockSelection, emptyDocument2Meta, ensureDocument2BibliographyBlock, extendBlockSelectionFromAnchor, fillDocument2MetaGaps, findFirstInlineField, formatBibliographyNumber, formatCiteLabel, formatFloatCaptionPreview, formatFloatCaptionTitle, formatHijriDate, formatRefLabel, fromDocumentJson2, getArabicXeLatexPreamble, hijriMonthLabel, inlineFieldLatex, insertCiteTokenAtCaret, insertDocument2BlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, 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 };