@drghaliasri/butex 8.0.3 → 8.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.
@@ -158,12 +158,14 @@ type MathObject2Json = {
158
158
  source_owner?: 'imported-structured' | 'editor';
159
159
  label_enabled?: boolean;
160
160
  label?: string;
161
+ numbered?: boolean;
161
162
  };
162
163
  /** Positional metadata for a raw-only span that has no structured equation AST. */
163
164
  type RawMathObject2Json = {
164
165
  node_type: 'RawMathObject';
165
166
  label_enabled?: boolean;
166
167
  label?: string;
168
+ numbered?: boolean;
167
169
  };
168
170
  type DocumentMathObjectJson = MathObject2Json | RawMathObject2Json;
169
171
  type ReferenceFieldSeparator = ',' | '،';
@@ -295,6 +297,8 @@ type MathToken2 = {
295
297
  /** When true on display math, export as equation env with \\label. */
296
298
  labelEnabled?: boolean;
297
299
  label?: string;
300
+ /** Independent display-equation numbering override; absent means legacy semantics. */
301
+ numbered?: boolean;
298
302
  };
299
303
  type CiteToken2 = {
300
304
  id: string;
@@ -317,6 +321,8 @@ type TextBlock2 = {
317
321
  kind: 'textBlock';
318
322
  command: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph';
319
323
  field: InlineField2;
324
+ /** Optional imported or authored label for a section heading. */
325
+ label?: string;
320
326
  metadata?: DocumentBlockMetadata;
321
327
  /** When true on \\paragraph, center in preview and LaTeX export. */
322
328
  centered?: boolean;
@@ -426,6 +432,7 @@ type PreviewInline2 = {
426
432
  display: boolean;
427
433
  output: DocumentMathOutput;
428
434
  editable: boolean;
435
+ numberLabel?: string;
429
436
  } | {
430
437
  kind: 'cite';
431
438
  id: string;
@@ -585,8 +592,26 @@ declare function parseRefKeys(source: string): {
585
592
  refCommand: 'ref' | 'eqref';
586
593
  };
587
594
  declare function refTokenLatex(keys: string[], refCommand: 'ref' | 'eqref'): string;
588
- /** Collect enabled labels in document order, numbering per kind. */
595
+ declare function implicitReferenceKey(kind: DocumentLabelKind, ownerId: string, unitId?: string): string;
596
+ declare function implicitHeadingReferenceKey(kind: 'section' | 'subsection' | 'subsubsection', ownerId: string, unitId: string): string;
597
+ /** Explicit numbering wins; legacy labeled/equation-environment math stays numbered. */
598
+ declare function isNumberedEquation(token: MathToken2): boolean;
599
+ declare function isNumberedFloat(block: ImageBlock2 | TableBlock2): boolean;
600
+ type DocumentReferenceTarget = {
601
+ key: string;
602
+ kind: DocumentLabelKind;
603
+ caption: string;
604
+ ownerId: string;
605
+ /** null means a displayed equation that has not been numbered. */
606
+ number: number | null;
607
+ manualKey?: string;
608
+ };
609
+ /** Projection of object identities and ordinals; never mutates document state. */
610
+ declare function collectDocumentReferenceTargets(document: DocumentNode): DocumentReferenceTarget[];
611
+ /** Author-managed manual labels only; auto keys are not editable author metadata. */
589
612
  declare function collectDocumentLabels(document: DocumentNode): DocumentLabelEntry[];
613
+ /** Key collision checks include generated aliases without adding persistence fields. */
614
+ declare function collectDocumentKeyLabels(document: DocumentNode): Array<Pick<DocumentLabelEntry, 'key' | 'ownerId'>>;
590
615
  declare function labelNumberMap(document: DocumentNode): Map<string, {
591
616
  kind: DocumentLabelKind;
592
617
  number: number;
@@ -676,6 +701,8 @@ declare function insertMathToken(document: DocumentNode, fieldId: string, insert
676
701
  declare function replaceMathTokenFromSession(document: DocumentNode, tokenId: string, session: EditorSession, opening?: string, closing?: string, side?: EditorSide): DocumentNode;
677
702
  declare function addDocumentTextBlock(document: DocumentNode, command?: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph', afterBlockId?: string | null): DocumentNode;
678
703
  declare function updateDocumentTextBlockCentered(document: DocumentNode, blockId: string, centered: boolean): DocumentNode;
704
+ /** Edit optional heading labels without altering the heading's stable ID or text. */
705
+ declare function updateDocumentHeadingLabel(document: DocumentNode, blockId: string, label: string): DocumentNode;
679
706
  declare function removeDocumentBlockById(document: DocumentNode, blockId: string): DocumentNode;
680
707
  declare function addDocumentListBlock(document: DocumentNode, ordered: boolean, afterBlockId?: string | null): DocumentNode;
681
708
  declare function addDocumentTableBlock(document: DocumentNode, columns?: string, rowCount?: number, colCount?: number, afterBlockId?: string | null): DocumentNode;
@@ -688,6 +715,7 @@ declare function updateDocumentTableMeta(document: DocumentNode, blockId: string
688
715
  declare function updateMathTokenLabel(document: DocumentNode, tokenId: string, patch: {
689
716
  labelEnabled?: boolean;
690
717
  label?: string;
718
+ numbered?: boolean;
691
719
  }): DocumentNode;
692
720
  declare function insertRefTokenAtCaret(document: DocumentNode, fieldId: string, textTokenId: string | null, caretOffset: number, keys: string[], refCommand?: 'ref' | 'eqref'): DocumentNode;
693
721
  declare function updateRefTokenKeys(document: DocumentNode, tokenId: string, keys: string[], refCommand?: 'ref' | 'eqref'): DocumentNode;
@@ -764,6 +792,10 @@ type DocumentCommand = ({
764
792
  op: 'replace_text_block';
765
793
  block_id: string;
766
794
  text: string;
795
+ } | {
796
+ op: 'set_heading_label';
797
+ block_id: string;
798
+ label: string | null;
767
799
  } | {
768
800
  op: 'remove_block';
769
801
  block_id: string;
@@ -839,6 +871,11 @@ type DocumentCommand = ({
839
871
  op: 'remove_inline_token';
840
872
  field_id: string;
841
873
  token_id: string;
874
+ } | {
875
+ op: 'set_equation_numbering';
876
+ field_id: string;
877
+ token_id: string;
878
+ numbered: boolean;
842
879
  } | ({
843
880
  op: 'insert_list';
844
881
  ordered: boolean;
@@ -975,6 +1012,10 @@ type DocumentReferenceIndex = {
975
1012
  citations: DocumentCitationIndexEntry[];
976
1013
  cross_references: DocumentCrossReferenceIndexEntry[];
977
1014
  labels: DocumentIndexedLabel[];
1015
+ reference_targets: Array<Omit<DocumentIndexedLabel, 'number'> & {
1016
+ number: number | null;
1017
+ manual_key?: string;
1018
+ }>;
978
1019
  unresolved: {
979
1020
  citation_keys: string[];
980
1021
  cross_reference_keys: string[];
@@ -1040,6 +1081,34 @@ declare function arabicXeLatexPreambleFont(digitsMapping?: ArabicDigitsMapping):
1040
1081
  declare function arabicXeLatexPreambleCmd(): string;
1041
1082
  declare function getArabicXeLatexPreamble(digitsMappingOrOptions?: ArabicDigitsMapping | ArabicXeLatexPreambleOptions): string;
1042
1083
 
1084
+ /** Read-only, host-supplied projection. Never copy these catalogs into a unit DocumentJson. */
1085
+ type DocumentBookTarget = {
1086
+ unitId: string;
1087
+ ownerId: string;
1088
+ key: string;
1089
+ kind: DocumentLabelKind | 'section' | 'subsection' | 'subsubsection' | 'chapter' | 'appendix';
1090
+ caption?: string;
1091
+ displayLabel?: string;
1092
+ manualKey?: string;
1093
+ };
1094
+ type DocumentBookContext = {
1095
+ unitId: string;
1096
+ references?: Reference2Json[];
1097
+ targets?: DocumentBookTarget[];
1098
+ };
1099
+ type DocumentEditorMode = 'article' | 'book-content';
1100
+ type DocumentPickerBookTarget = (DocumentReferenceTarget & {
1101
+ displayLabel?: string;
1102
+ }) | (DocumentBookTarget & {
1103
+ number: number | null;
1104
+ caption: string;
1105
+ });
1106
+ declare function bookContextReferences(context?: DocumentBookContext): Reference2[];
1107
+ /** A local target's book alias is scoped by the immutable unit ID, not its displayed ordinal. */
1108
+ declare function bookContentTargets(document: DocumentNode, context: DocumentBookContext): DocumentPickerBookTarget[];
1109
+ /** Supplied book display strings have priority; local article numbering is only a fallback. */
1110
+ declare function formatBookReferenceLabel(keys: string[], document: DocumentNode, command: 'ref' | 'eqref', context: DocumentBookContext, options?: FormatCiteLabelOptions): string;
1111
+
1043
1112
  type DocumentLatexOptions = {
1044
1113
  /**
1045
1114
  * When true (default), emit a complete Arabic XeLaTeX file:
@@ -1059,7 +1128,7 @@ declare function inlineFieldLatex(field: InlineField2): string;
1059
1128
  /** Convert the live editor AST to the canonical JSON wire format. */
1060
1129
  declare function toDocumentJson(document: DocumentNode): DocumentJson;
1061
1130
 
1062
- type DocumentValidationIssueCode = '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';
1131
+ type DocumentValidationIssueCode = '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' | 'book_local_bibliography' | 'book_context_required';
1063
1132
  type DocumentValidationIssue = {
1064
1133
  code: DocumentValidationIssueCode;
1065
1134
  path: string;
@@ -1076,7 +1145,10 @@ declare function hasXeLatexUnsupportedEmoji(value: string): boolean;
1076
1145
  * Validate a Document draft without mutating it. Detailed issues are kept in
1077
1146
  * BuTeX so React can identify the field while hosts only need the boolean API.
1078
1147
  */
1079
- declare function validateDocument(document: DocumentJson | DocumentNode): DocumentValidationResult;
1148
+ declare function validateDocument(document: DocumentJson | DocumentNode, options?: {
1149
+ mode?: DocumentEditorMode;
1150
+ bookContext?: DocumentBookContext;
1151
+ }): DocumentValidationResult;
1080
1152
  /** Public host contract: drafts may be saved, but only valid documents may compile. */
1081
1153
  declare function isDocumentValid(document: DocumentJson | DocumentNode): boolean;
1082
1154
  /** Error thrown when LaTeX export is attempted for an invalid Document draft. */
@@ -1141,6 +1213,8 @@ declare function mathNodeFromArabicSession(session: EditorSession, opening?: str
1141
1213
  declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide, digitForm?: DigitFormId, presentation?: boolean): string;
1142
1214
 
1143
1215
  type DocumentPreviewOptions = {
1216
+ mode?: DocumentEditorMode;
1217
+ bookContext?: DocumentBookContext;
1144
1218
  documentDirection?: DocumentDirection;
1145
1219
  digitForm?: DigitFormId;
1146
1220
  uiLocale?: ButexUiLocale;
@@ -1152,5 +1226,7 @@ declare function documentPreview(document: DocumentNode, output?: DocumentMathOu
1152
1226
  * but compilation must not silently receive unsafe or unreliable LaTeX.
1153
1227
  */
1154
1228
  declare function documentLatex(document: DocumentNode, options?: DocumentLatexOptions): string;
1229
+ /** Content-only unit export, with book-scoped reference validation. */
1230
+ declare function documentContentLatex(document: DocumentNode, context?: DocumentBookContext): string;
1155
1231
 
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_DOCUMENT_HISTORY_MAX_DEPTH, DEFAULT_HIJRI_DATE, DEFAULT_REFERENCE_FIELD_SEPARATOR, type DocumentAnchor, type DocumentBlock, type DocumentBlockJson, type DocumentBlockMetadata, type DocumentCitationIndexEntry, type DocumentCommand, DocumentCommandError, type DocumentCommandErrorCode, type DocumentCrossReferenceIndexEntry, type DocumentDiagnostic, type DocumentDiff, type DocumentDiffChunk, type DocumentDiffChunkKind, type DocumentDirection, type DocumentHijriDate, type DocumentHistoryStacks, type DocumentImageAssetRef, type DocumentIndexedLabel, type DocumentInlineAnchor, type DocumentInlineIdsJson, type DocumentInlineTokenIdJson, type DocumentInlineTokenInput, type DocumentJson, type DocumentKeyError, type DocumentKeyNamespace, type DocumentLabelEntry, type DocumentLabelKind, type DocumentLatexOptions, type DocumentListItemAnchor, type DocumentMathObjectJson, type DocumentMathOutput, type DocumentMeta, type DocumentMetaProp, type DocumentNode, type DocumentOutlineEntry, type DocumentOutlineKind, type DocumentPreview, type DocumentPreviewOptions, type DocumentReferenceAnchor, type DocumentReferenceIndex, type DocumentTextBlockKind, DocumentValidationError, type DocumentValidationIssue, type DocumentValidationIssueCode, type DocumentValidationResult, type FloatMeta2, type FloatMetaPatch, type FormatCiteLabelOptions, type FormatFloatCaptionTitleOptions, HIJRI_MONTH_IDS, HIJRI_YEAR_MAX, HIJRI_YEAR_MIN, type HijriMonthId, type ImageBlock2, type ImportDocumentOptions, 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, addDocumentImageBlock, addDocumentListBlock, addDocumentListItem, addDocumentReference, addDocumentTableBlock, addDocumentTextBlock, applyDocumentCommand, applyFloatMetaPatch, arabicXeLatexPreambleCmd, arabicXeLatexPreambleFont, arabicXeLatexPreamblePkg, bibliographyEntryBody, bibliographyEntryLatex, butexBasmalaDisplayLatex, butexBasmalaDisplayTex, butexBasmalaTitlingPreamble, butexDiwaniDisplayLatex, butexDiwaniDisplayTex, butexInColumnMaketitleHook, butexMaghribiDisplayLatex, butexMaghribiDisplayTex, citeTokenLatex, clearDocumentImageAsset, cloneDocumentMeta, cloneDocumentNode, collectDocumentLabels, createDocumentHistory, createEmptyArabicEquationSession, createEmptyDocument, createEmptyEquationSession, createEmptyReference, createInlineField, defaultFloatMeta, detectInlineSpans, detectMathSpans, diffDocument, documentHasAbstract, documentHasMaketitle, documentHasTitleStack, documentHistoryCanRedo, documentHistoryCanUndo, documentKeyError, documentLatex, documentOutline, documentPreview, emptyBlockSelection, emptyDocumentMeta, ensureDocumentBibliographyBlock, extendBlockSelectionFromAnchor, fillDocumentMetaGaps, findFirstInlineField, formatBibliographyNumber, formatCiteLabel, formatFloatCaptionPreview, formatFloatCaptionTitle, formatHijriDate, formatRefLabel, fromDocumentJson, getArabicXeLatexPreamble, getDocumentReferenceIndex, getDocumentReferences, hasXeLatexUnsupportedEmoji, hijriMonthLabel, inlineFieldLatex, insertCiteTokenAtCaret, insertDocumentBlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, isDocumentValid, isDuplicateDocumentKey, isValidDocumentKey, labelNumberMap, mathNodeFromArabicSession, mathNodeFromSession, mathSourceFromArabicSession, mathSourceFromSession, mathTokenSourceForSide, mathTokenToArabicEditorSession, mathTokenToEditorSession, mergeDocumentMeta, moveDocumentBlockById, moveDocumentBlockRange, moveDocumentReference, normalizeBlockSelection, normalizeDocumentHijriDate, normalizeDocumentKey, normalizeDocumentMeta, normalizeReferenceFieldSeparator, parseCiteKeys, parseFloatMetaFromJson, parseRefKeys, pushDocumentSnapshot, refTokenLatex, referenceFromJson, referenceNumberMap, remapSelectionAfterRangeMove, removeCiteTokenById, removeDocumentBlockById, removeDocumentBlockRange, removeDocumentListItem, removeDocumentReference, removeMathTokenById, removeRefTokenById, replaceMathTokenFromSession, resolveCiteNumbers, restoreDocumentRedo, restoreDocumentUndo, setDocumentReferences, stripDisplayMathDelimiters, toDocumentJson, toggleBlockInSelection, toggleTextTokenStyle, updateCiteTokenKeys, updateDocumentImageAsset, updateDocumentImageMeta, updateDocumentImageValue, updateDocumentMeta, updateDocumentReference, updateDocumentTableMeta, updateDocumentTextBlockCentered, updateMathTokenLabel, updateRefTokenKeys, updateTextToken, validateDocument };
1232
+ 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_DOCUMENT_HISTORY_MAX_DEPTH, DEFAULT_HIJRI_DATE, DEFAULT_REFERENCE_FIELD_SEPARATOR, type DocumentAnchor, type DocumentBlock, type DocumentBlockJson, type DocumentBlockMetadata, type DocumentBookContext, type DocumentBookTarget, type DocumentCitationIndexEntry, type DocumentCommand, DocumentCommandError, type DocumentCommandErrorCode, type DocumentCrossReferenceIndexEntry, type DocumentDiagnostic, type DocumentDiff, type DocumentDiffChunk, type DocumentDiffChunkKind, type DocumentDirection, type DocumentEditorMode, type DocumentHijriDate, type DocumentHistoryStacks, type DocumentImageAssetRef, type DocumentIndexedLabel, type DocumentInlineAnchor, type DocumentInlineIdsJson, type DocumentInlineTokenIdJson, type DocumentInlineTokenInput, type DocumentJson, type DocumentKeyError, type DocumentKeyNamespace, type DocumentLabelEntry, type DocumentLabelKind, type DocumentLatexOptions, type DocumentListItemAnchor, type DocumentMathObjectJson, type DocumentMathOutput, type DocumentMeta, type DocumentMetaProp, type DocumentNode, type DocumentOutlineEntry, type DocumentOutlineKind, type DocumentPickerBookTarget, type DocumentPreview, type DocumentPreviewOptions, type DocumentReferenceAnchor, type DocumentReferenceIndex, type DocumentReferenceTarget, type DocumentTextBlockKind, DocumentValidationError, type DocumentValidationIssue, type DocumentValidationIssueCode, type DocumentValidationResult, type FloatMeta2, type FloatMetaPatch, type FormatCiteLabelOptions, type FormatFloatCaptionTitleOptions, HIJRI_MONTH_IDS, HIJRI_YEAR_MAX, HIJRI_YEAR_MIN, type HijriMonthId, type ImageBlock2, type ImportDocumentOptions, 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, addDocumentImageBlock, addDocumentListBlock, addDocumentListItem, addDocumentReference, addDocumentTableBlock, addDocumentTextBlock, applyDocumentCommand, applyFloatMetaPatch, arabicXeLatexPreambleCmd, arabicXeLatexPreambleFont, arabicXeLatexPreamblePkg, bibliographyEntryBody, bibliographyEntryLatex, bookContentTargets, bookContextReferences, butexBasmalaDisplayLatex, butexBasmalaDisplayTex, butexBasmalaTitlingPreamble, butexDiwaniDisplayLatex, butexDiwaniDisplayTex, butexInColumnMaketitleHook, butexMaghribiDisplayLatex, butexMaghribiDisplayTex, citeTokenLatex, clearDocumentImageAsset, cloneDocumentMeta, cloneDocumentNode, collectDocumentKeyLabels, collectDocumentLabels, collectDocumentReferenceTargets, createDocumentHistory, createEmptyArabicEquationSession, createEmptyDocument, createEmptyEquationSession, createEmptyReference, createInlineField, defaultFloatMeta, detectInlineSpans, detectMathSpans, diffDocument, documentContentLatex, documentHasAbstract, documentHasMaketitle, documentHasTitleStack, documentHistoryCanRedo, documentHistoryCanUndo, documentKeyError, documentLatex, documentOutline, documentPreview, emptyBlockSelection, emptyDocumentMeta, ensureDocumentBibliographyBlock, extendBlockSelectionFromAnchor, fillDocumentMetaGaps, findFirstInlineField, formatBibliographyNumber, formatBookReferenceLabel, formatCiteLabel, formatFloatCaptionPreview, formatFloatCaptionTitle, formatHijriDate, formatRefLabel, fromDocumentJson, getArabicXeLatexPreamble, getDocumentReferenceIndex, getDocumentReferences, hasXeLatexUnsupportedEmoji, hijriMonthLabel, implicitHeadingReferenceKey, implicitReferenceKey, inlineFieldLatex, insertCiteTokenAtCaret, insertDocumentBlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, isDocumentValid, isDuplicateDocumentKey, isNumberedEquation, isNumberedFloat, isValidDocumentKey, labelNumberMap, mathNodeFromArabicSession, mathNodeFromSession, mathSourceFromArabicSession, mathSourceFromSession, mathTokenSourceForSide, mathTokenToArabicEditorSession, mathTokenToEditorSession, mergeDocumentMeta, moveDocumentBlockById, moveDocumentBlockRange, moveDocumentReference, normalizeBlockSelection, normalizeDocumentHijriDate, normalizeDocumentKey, normalizeDocumentMeta, normalizeReferenceFieldSeparator, parseCiteKeys, parseFloatMetaFromJson, parseRefKeys, pushDocumentSnapshot, refTokenLatex, referenceFromJson, referenceNumberMap, remapSelectionAfterRangeMove, removeCiteTokenById, removeDocumentBlockById, removeDocumentBlockRange, removeDocumentListItem, removeDocumentReference, removeMathTokenById, removeRefTokenById, replaceMathTokenFromSession, resolveCiteNumbers, restoreDocumentRedo, restoreDocumentUndo, setDocumentReferences, stripDisplayMathDelimiters, toDocumentJson, toggleBlockInSelection, toggleTextTokenStyle, updateCiteTokenKeys, updateDocumentHeadingLabel, updateDocumentImageAsset, updateDocumentImageMeta, updateDocumentImageValue, updateDocumentMeta, updateDocumentReference, updateDocumentTableMeta, updateDocumentTextBlockCentered, updateMathTokenLabel, updateRefTokenKeys, updateTextToken, validateDocument };
@@ -158,12 +158,14 @@ type MathObject2Json = {
158
158
  source_owner?: 'imported-structured' | 'editor';
159
159
  label_enabled?: boolean;
160
160
  label?: string;
161
+ numbered?: boolean;
161
162
  };
162
163
  /** Positional metadata for a raw-only span that has no structured equation AST. */
163
164
  type RawMathObject2Json = {
164
165
  node_type: 'RawMathObject';
165
166
  label_enabled?: boolean;
166
167
  label?: string;
168
+ numbered?: boolean;
167
169
  };
168
170
  type DocumentMathObjectJson = MathObject2Json | RawMathObject2Json;
169
171
  type ReferenceFieldSeparator = ',' | '،';
@@ -295,6 +297,8 @@ type MathToken2 = {
295
297
  /** When true on display math, export as equation env with \\label. */
296
298
  labelEnabled?: boolean;
297
299
  label?: string;
300
+ /** Independent display-equation numbering override; absent means legacy semantics. */
301
+ numbered?: boolean;
298
302
  };
299
303
  type CiteToken2 = {
300
304
  id: string;
@@ -317,6 +321,8 @@ type TextBlock2 = {
317
321
  kind: 'textBlock';
318
322
  command: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph';
319
323
  field: InlineField2;
324
+ /** Optional imported or authored label for a section heading. */
325
+ label?: string;
320
326
  metadata?: DocumentBlockMetadata;
321
327
  /** When true on \\paragraph, center in preview and LaTeX export. */
322
328
  centered?: boolean;
@@ -426,6 +432,7 @@ type PreviewInline2 = {
426
432
  display: boolean;
427
433
  output: DocumentMathOutput;
428
434
  editable: boolean;
435
+ numberLabel?: string;
429
436
  } | {
430
437
  kind: 'cite';
431
438
  id: string;
@@ -585,8 +592,26 @@ declare function parseRefKeys(source: string): {
585
592
  refCommand: 'ref' | 'eqref';
586
593
  };
587
594
  declare function refTokenLatex(keys: string[], refCommand: 'ref' | 'eqref'): string;
588
- /** Collect enabled labels in document order, numbering per kind. */
595
+ declare function implicitReferenceKey(kind: DocumentLabelKind, ownerId: string, unitId?: string): string;
596
+ declare function implicitHeadingReferenceKey(kind: 'section' | 'subsection' | 'subsubsection', ownerId: string, unitId: string): string;
597
+ /** Explicit numbering wins; legacy labeled/equation-environment math stays numbered. */
598
+ declare function isNumberedEquation(token: MathToken2): boolean;
599
+ declare function isNumberedFloat(block: ImageBlock2 | TableBlock2): boolean;
600
+ type DocumentReferenceTarget = {
601
+ key: string;
602
+ kind: DocumentLabelKind;
603
+ caption: string;
604
+ ownerId: string;
605
+ /** null means a displayed equation that has not been numbered. */
606
+ number: number | null;
607
+ manualKey?: string;
608
+ };
609
+ /** Projection of object identities and ordinals; never mutates document state. */
610
+ declare function collectDocumentReferenceTargets(document: DocumentNode): DocumentReferenceTarget[];
611
+ /** Author-managed manual labels only; auto keys are not editable author metadata. */
589
612
  declare function collectDocumentLabels(document: DocumentNode): DocumentLabelEntry[];
613
+ /** Key collision checks include generated aliases without adding persistence fields. */
614
+ declare function collectDocumentKeyLabels(document: DocumentNode): Array<Pick<DocumentLabelEntry, 'key' | 'ownerId'>>;
590
615
  declare function labelNumberMap(document: DocumentNode): Map<string, {
591
616
  kind: DocumentLabelKind;
592
617
  number: number;
@@ -676,6 +701,8 @@ declare function insertMathToken(document: DocumentNode, fieldId: string, insert
676
701
  declare function replaceMathTokenFromSession(document: DocumentNode, tokenId: string, session: EditorSession, opening?: string, closing?: string, side?: EditorSide): DocumentNode;
677
702
  declare function addDocumentTextBlock(document: DocumentNode, command?: '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph', afterBlockId?: string | null): DocumentNode;
678
703
  declare function updateDocumentTextBlockCentered(document: DocumentNode, blockId: string, centered: boolean): DocumentNode;
704
+ /** Edit optional heading labels without altering the heading's stable ID or text. */
705
+ declare function updateDocumentHeadingLabel(document: DocumentNode, blockId: string, label: string): DocumentNode;
679
706
  declare function removeDocumentBlockById(document: DocumentNode, blockId: string): DocumentNode;
680
707
  declare function addDocumentListBlock(document: DocumentNode, ordered: boolean, afterBlockId?: string | null): DocumentNode;
681
708
  declare function addDocumentTableBlock(document: DocumentNode, columns?: string, rowCount?: number, colCount?: number, afterBlockId?: string | null): DocumentNode;
@@ -688,6 +715,7 @@ declare function updateDocumentTableMeta(document: DocumentNode, blockId: string
688
715
  declare function updateMathTokenLabel(document: DocumentNode, tokenId: string, patch: {
689
716
  labelEnabled?: boolean;
690
717
  label?: string;
718
+ numbered?: boolean;
691
719
  }): DocumentNode;
692
720
  declare function insertRefTokenAtCaret(document: DocumentNode, fieldId: string, textTokenId: string | null, caretOffset: number, keys: string[], refCommand?: 'ref' | 'eqref'): DocumentNode;
693
721
  declare function updateRefTokenKeys(document: DocumentNode, tokenId: string, keys: string[], refCommand?: 'ref' | 'eqref'): DocumentNode;
@@ -764,6 +792,10 @@ type DocumentCommand = ({
764
792
  op: 'replace_text_block';
765
793
  block_id: string;
766
794
  text: string;
795
+ } | {
796
+ op: 'set_heading_label';
797
+ block_id: string;
798
+ label: string | null;
767
799
  } | {
768
800
  op: 'remove_block';
769
801
  block_id: string;
@@ -839,6 +871,11 @@ type DocumentCommand = ({
839
871
  op: 'remove_inline_token';
840
872
  field_id: string;
841
873
  token_id: string;
874
+ } | {
875
+ op: 'set_equation_numbering';
876
+ field_id: string;
877
+ token_id: string;
878
+ numbered: boolean;
842
879
  } | ({
843
880
  op: 'insert_list';
844
881
  ordered: boolean;
@@ -975,6 +1012,10 @@ type DocumentReferenceIndex = {
975
1012
  citations: DocumentCitationIndexEntry[];
976
1013
  cross_references: DocumentCrossReferenceIndexEntry[];
977
1014
  labels: DocumentIndexedLabel[];
1015
+ reference_targets: Array<Omit<DocumentIndexedLabel, 'number'> & {
1016
+ number: number | null;
1017
+ manual_key?: string;
1018
+ }>;
978
1019
  unresolved: {
979
1020
  citation_keys: string[];
980
1021
  cross_reference_keys: string[];
@@ -1040,6 +1081,34 @@ declare function arabicXeLatexPreambleFont(digitsMapping?: ArabicDigitsMapping):
1040
1081
  declare function arabicXeLatexPreambleCmd(): string;
1041
1082
  declare function getArabicXeLatexPreamble(digitsMappingOrOptions?: ArabicDigitsMapping | ArabicXeLatexPreambleOptions): string;
1042
1083
 
1084
+ /** Read-only, host-supplied projection. Never copy these catalogs into a unit DocumentJson. */
1085
+ type DocumentBookTarget = {
1086
+ unitId: string;
1087
+ ownerId: string;
1088
+ key: string;
1089
+ kind: DocumentLabelKind | 'section' | 'subsection' | 'subsubsection' | 'chapter' | 'appendix';
1090
+ caption?: string;
1091
+ displayLabel?: string;
1092
+ manualKey?: string;
1093
+ };
1094
+ type DocumentBookContext = {
1095
+ unitId: string;
1096
+ references?: Reference2Json[];
1097
+ targets?: DocumentBookTarget[];
1098
+ };
1099
+ type DocumentEditorMode = 'article' | 'book-content';
1100
+ type DocumentPickerBookTarget = (DocumentReferenceTarget & {
1101
+ displayLabel?: string;
1102
+ }) | (DocumentBookTarget & {
1103
+ number: number | null;
1104
+ caption: string;
1105
+ });
1106
+ declare function bookContextReferences(context?: DocumentBookContext): Reference2[];
1107
+ /** A local target's book alias is scoped by the immutable unit ID, not its displayed ordinal. */
1108
+ declare function bookContentTargets(document: DocumentNode, context: DocumentBookContext): DocumentPickerBookTarget[];
1109
+ /** Supplied book display strings have priority; local article numbering is only a fallback. */
1110
+ declare function formatBookReferenceLabel(keys: string[], document: DocumentNode, command: 'ref' | 'eqref', context: DocumentBookContext, options?: FormatCiteLabelOptions): string;
1111
+
1043
1112
  type DocumentLatexOptions = {
1044
1113
  /**
1045
1114
  * When true (default), emit a complete Arabic XeLaTeX file:
@@ -1059,7 +1128,7 @@ declare function inlineFieldLatex(field: InlineField2): string;
1059
1128
  /** Convert the live editor AST to the canonical JSON wire format. */
1060
1129
  declare function toDocumentJson(document: DocumentNode): DocumentJson;
1061
1130
 
1062
- type DocumentValidationIssueCode = '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';
1131
+ type DocumentValidationIssueCode = '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' | 'book_local_bibliography' | 'book_context_required';
1063
1132
  type DocumentValidationIssue = {
1064
1133
  code: DocumentValidationIssueCode;
1065
1134
  path: string;
@@ -1076,7 +1145,10 @@ declare function hasXeLatexUnsupportedEmoji(value: string): boolean;
1076
1145
  * Validate a Document draft without mutating it. Detailed issues are kept in
1077
1146
  * BuTeX so React can identify the field while hosts only need the boolean API.
1078
1147
  */
1079
- declare function validateDocument(document: DocumentJson | DocumentNode): DocumentValidationResult;
1148
+ declare function validateDocument(document: DocumentJson | DocumentNode, options?: {
1149
+ mode?: DocumentEditorMode;
1150
+ bookContext?: DocumentBookContext;
1151
+ }): DocumentValidationResult;
1080
1152
  /** Public host contract: drafts may be saved, but only valid documents may compile. */
1081
1153
  declare function isDocumentValid(document: DocumentJson | DocumentNode): boolean;
1082
1154
  /** Error thrown when LaTeX export is attempted for an invalid Document draft. */
@@ -1141,6 +1213,8 @@ declare function mathNodeFromArabicSession(session: EditorSession, opening?: str
1141
1213
  declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide, digitForm?: DigitFormId, presentation?: boolean): string;
1142
1214
 
1143
1215
  type DocumentPreviewOptions = {
1216
+ mode?: DocumentEditorMode;
1217
+ bookContext?: DocumentBookContext;
1144
1218
  documentDirection?: DocumentDirection;
1145
1219
  digitForm?: DigitFormId;
1146
1220
  uiLocale?: ButexUiLocale;
@@ -1152,5 +1226,7 @@ declare function documentPreview(document: DocumentNode, output?: DocumentMathOu
1152
1226
  * but compilation must not silently receive unsafe or unreliable LaTeX.
1153
1227
  */
1154
1228
  declare function documentLatex(document: DocumentNode, options?: DocumentLatexOptions): string;
1229
+ /** Content-only unit export, with book-scoped reference validation. */
1230
+ declare function documentContentLatex(document: DocumentNode, context?: DocumentBookContext): string;
1155
1231
 
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_DOCUMENT_HISTORY_MAX_DEPTH, DEFAULT_HIJRI_DATE, DEFAULT_REFERENCE_FIELD_SEPARATOR, type DocumentAnchor, type DocumentBlock, type DocumentBlockJson, type DocumentBlockMetadata, type DocumentCitationIndexEntry, type DocumentCommand, DocumentCommandError, type DocumentCommandErrorCode, type DocumentCrossReferenceIndexEntry, type DocumentDiagnostic, type DocumentDiff, type DocumentDiffChunk, type DocumentDiffChunkKind, type DocumentDirection, type DocumentHijriDate, type DocumentHistoryStacks, type DocumentImageAssetRef, type DocumentIndexedLabel, type DocumentInlineAnchor, type DocumentInlineIdsJson, type DocumentInlineTokenIdJson, type DocumentInlineTokenInput, type DocumentJson, type DocumentKeyError, type DocumentKeyNamespace, type DocumentLabelEntry, type DocumentLabelKind, type DocumentLatexOptions, type DocumentListItemAnchor, type DocumentMathObjectJson, type DocumentMathOutput, type DocumentMeta, type DocumentMetaProp, type DocumentNode, type DocumentOutlineEntry, type DocumentOutlineKind, type DocumentPreview, type DocumentPreviewOptions, type DocumentReferenceAnchor, type DocumentReferenceIndex, type DocumentTextBlockKind, DocumentValidationError, type DocumentValidationIssue, type DocumentValidationIssueCode, type DocumentValidationResult, type FloatMeta2, type FloatMetaPatch, type FormatCiteLabelOptions, type FormatFloatCaptionTitleOptions, HIJRI_MONTH_IDS, HIJRI_YEAR_MAX, HIJRI_YEAR_MIN, type HijriMonthId, type ImageBlock2, type ImportDocumentOptions, 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, addDocumentImageBlock, addDocumentListBlock, addDocumentListItem, addDocumentReference, addDocumentTableBlock, addDocumentTextBlock, applyDocumentCommand, applyFloatMetaPatch, arabicXeLatexPreambleCmd, arabicXeLatexPreambleFont, arabicXeLatexPreamblePkg, bibliographyEntryBody, bibliographyEntryLatex, butexBasmalaDisplayLatex, butexBasmalaDisplayTex, butexBasmalaTitlingPreamble, butexDiwaniDisplayLatex, butexDiwaniDisplayTex, butexInColumnMaketitleHook, butexMaghribiDisplayLatex, butexMaghribiDisplayTex, citeTokenLatex, clearDocumentImageAsset, cloneDocumentMeta, cloneDocumentNode, collectDocumentLabels, createDocumentHistory, createEmptyArabicEquationSession, createEmptyDocument, createEmptyEquationSession, createEmptyReference, createInlineField, defaultFloatMeta, detectInlineSpans, detectMathSpans, diffDocument, documentHasAbstract, documentHasMaketitle, documentHasTitleStack, documentHistoryCanRedo, documentHistoryCanUndo, documentKeyError, documentLatex, documentOutline, documentPreview, emptyBlockSelection, emptyDocumentMeta, ensureDocumentBibliographyBlock, extendBlockSelectionFromAnchor, fillDocumentMetaGaps, findFirstInlineField, formatBibliographyNumber, formatCiteLabel, formatFloatCaptionPreview, formatFloatCaptionTitle, formatHijriDate, formatRefLabel, fromDocumentJson, getArabicXeLatexPreamble, getDocumentReferenceIndex, getDocumentReferences, hasXeLatexUnsupportedEmoji, hijriMonthLabel, inlineFieldLatex, insertCiteTokenAtCaret, insertDocumentBlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, isDocumentValid, isDuplicateDocumentKey, isValidDocumentKey, labelNumberMap, mathNodeFromArabicSession, mathNodeFromSession, mathSourceFromArabicSession, mathSourceFromSession, mathTokenSourceForSide, mathTokenToArabicEditorSession, mathTokenToEditorSession, mergeDocumentMeta, moveDocumentBlockById, moveDocumentBlockRange, moveDocumentReference, normalizeBlockSelection, normalizeDocumentHijriDate, normalizeDocumentKey, normalizeDocumentMeta, normalizeReferenceFieldSeparator, parseCiteKeys, parseFloatMetaFromJson, parseRefKeys, pushDocumentSnapshot, refTokenLatex, referenceFromJson, referenceNumberMap, remapSelectionAfterRangeMove, removeCiteTokenById, removeDocumentBlockById, removeDocumentBlockRange, removeDocumentListItem, removeDocumentReference, removeMathTokenById, removeRefTokenById, replaceMathTokenFromSession, resolveCiteNumbers, restoreDocumentRedo, restoreDocumentUndo, setDocumentReferences, stripDisplayMathDelimiters, toDocumentJson, toggleBlockInSelection, toggleTextTokenStyle, updateCiteTokenKeys, updateDocumentImageAsset, updateDocumentImageMeta, updateDocumentImageValue, updateDocumentMeta, updateDocumentReference, updateDocumentTableMeta, updateDocumentTextBlockCentered, updateMathTokenLabel, updateRefTokenKeys, updateTextToken, validateDocument };
1232
+ 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_DOCUMENT_HISTORY_MAX_DEPTH, DEFAULT_HIJRI_DATE, DEFAULT_REFERENCE_FIELD_SEPARATOR, type DocumentAnchor, type DocumentBlock, type DocumentBlockJson, type DocumentBlockMetadata, type DocumentBookContext, type DocumentBookTarget, type DocumentCitationIndexEntry, type DocumentCommand, DocumentCommandError, type DocumentCommandErrorCode, type DocumentCrossReferenceIndexEntry, type DocumentDiagnostic, type DocumentDiff, type DocumentDiffChunk, type DocumentDiffChunkKind, type DocumentDirection, type DocumentEditorMode, type DocumentHijriDate, type DocumentHistoryStacks, type DocumentImageAssetRef, type DocumentIndexedLabel, type DocumentInlineAnchor, type DocumentInlineIdsJson, type DocumentInlineTokenIdJson, type DocumentInlineTokenInput, type DocumentJson, type DocumentKeyError, type DocumentKeyNamespace, type DocumentLabelEntry, type DocumentLabelKind, type DocumentLatexOptions, type DocumentListItemAnchor, type DocumentMathObjectJson, type DocumentMathOutput, type DocumentMeta, type DocumentMetaProp, type DocumentNode, type DocumentOutlineEntry, type DocumentOutlineKind, type DocumentPickerBookTarget, type DocumentPreview, type DocumentPreviewOptions, type DocumentReferenceAnchor, type DocumentReferenceIndex, type DocumentReferenceTarget, type DocumentTextBlockKind, DocumentValidationError, type DocumentValidationIssue, type DocumentValidationIssueCode, type DocumentValidationResult, type FloatMeta2, type FloatMetaPatch, type FormatCiteLabelOptions, type FormatFloatCaptionTitleOptions, HIJRI_MONTH_IDS, HIJRI_YEAR_MAX, HIJRI_YEAR_MIN, type HijriMonthId, type ImageBlock2, type ImportDocumentOptions, 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, addDocumentImageBlock, addDocumentListBlock, addDocumentListItem, addDocumentReference, addDocumentTableBlock, addDocumentTextBlock, applyDocumentCommand, applyFloatMetaPatch, arabicXeLatexPreambleCmd, arabicXeLatexPreambleFont, arabicXeLatexPreamblePkg, bibliographyEntryBody, bibliographyEntryLatex, bookContentTargets, bookContextReferences, butexBasmalaDisplayLatex, butexBasmalaDisplayTex, butexBasmalaTitlingPreamble, butexDiwaniDisplayLatex, butexDiwaniDisplayTex, butexInColumnMaketitleHook, butexMaghribiDisplayLatex, butexMaghribiDisplayTex, citeTokenLatex, clearDocumentImageAsset, cloneDocumentMeta, cloneDocumentNode, collectDocumentKeyLabels, collectDocumentLabels, collectDocumentReferenceTargets, createDocumentHistory, createEmptyArabicEquationSession, createEmptyDocument, createEmptyEquationSession, createEmptyReference, createInlineField, defaultFloatMeta, detectInlineSpans, detectMathSpans, diffDocument, documentContentLatex, documentHasAbstract, documentHasMaketitle, documentHasTitleStack, documentHistoryCanRedo, documentHistoryCanUndo, documentKeyError, documentLatex, documentOutline, documentPreview, emptyBlockSelection, emptyDocumentMeta, ensureDocumentBibliographyBlock, extendBlockSelectionFromAnchor, fillDocumentMetaGaps, findFirstInlineField, formatBibliographyNumber, formatBookReferenceLabel, formatCiteLabel, formatFloatCaptionPreview, formatFloatCaptionTitle, formatHijriDate, formatRefLabel, fromDocumentJson, getArabicXeLatexPreamble, getDocumentReferenceIndex, getDocumentReferences, hasXeLatexUnsupportedEmoji, hijriMonthLabel, implicitHeadingReferenceKey, implicitReferenceKey, inlineFieldLatex, insertCiteTokenAtCaret, insertDocumentBlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, isDocumentValid, isDuplicateDocumentKey, isNumberedEquation, isNumberedFloat, isValidDocumentKey, labelNumberMap, mathNodeFromArabicSession, mathNodeFromSession, mathSourceFromArabicSession, mathSourceFromSession, mathTokenSourceForSide, mathTokenToArabicEditorSession, mathTokenToEditorSession, mergeDocumentMeta, moveDocumentBlockById, moveDocumentBlockRange, moveDocumentReference, normalizeBlockSelection, normalizeDocumentHijriDate, normalizeDocumentKey, normalizeDocumentMeta, normalizeReferenceFieldSeparator, parseCiteKeys, parseFloatMetaFromJson, parseRefKeys, pushDocumentSnapshot, refTokenLatex, referenceFromJson, referenceNumberMap, remapSelectionAfterRangeMove, removeCiteTokenById, removeDocumentBlockById, removeDocumentBlockRange, removeDocumentListItem, removeDocumentReference, removeMathTokenById, removeRefTokenById, replaceMathTokenFromSession, resolveCiteNumbers, restoreDocumentRedo, restoreDocumentUndo, setDocumentReferences, stripDisplayMathDelimiters, toDocumentJson, toggleBlockInSelection, toggleTextTokenStyle, updateCiteTokenKeys, updateDocumentHeadingLabel, updateDocumentImageAsset, updateDocumentImageMeta, updateDocumentImageValue, updateDocumentMeta, updateDocumentReference, updateDocumentTableMeta, updateDocumentTextBlockCentered, updateMathTokenLabel, updateRefTokenKeys, updateTextToken, validateDocument };