@drghaliasri/butex 5.5.2 → 5.5.3

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.
@@ -142,7 +142,20 @@ type MathObject2Json = {
142
142
  math_mode: string;
143
143
  lines: ChainJson[];
144
144
  closing: string;
145
+ /** Side used by the delimited source stored in the containing value/cell. */
146
+ source_side?: Document2ParseMode;
147
+ /** Preserve whether LaTeX export should prefer imported AST rendering or editor source. */
148
+ source_owner?: 'imported-structured' | 'editor';
149
+ label_enabled?: boolean;
150
+ label?: string;
151
+ };
152
+ /** Positional metadata for a raw-only span that has no structured equation AST. */
153
+ type RawMathObject2Json = {
154
+ node_type: 'RawMathObject';
155
+ label_enabled?: boolean;
156
+ label?: string;
145
157
  };
158
+ type Document2MathObjectJson = MathObject2Json | RawMathObject2Json;
146
159
  type ReferenceFieldSeparator = ',' | '،';
147
160
  type Reference2Json = {
148
161
  key: string;
@@ -178,7 +191,7 @@ type Document2BlockJson = {
178
191
  formats?: TextFormatSpan2Json[];
179
192
  /** Stable host asset identity (e.g. S3 key / UUID); optional for \\includegraphics. */
180
193
  asset_id?: string;
181
- math_objects?: MathObject2Json[];
194
+ math_objects?: Array<Document2MathObjectJson | null>;
182
195
  options?: Record<string, string>;
183
196
  closing?: string;
184
197
  items?: Document2ListItemJson[];
@@ -194,7 +207,7 @@ type Document2BlockJson = {
194
207
  type Document2ListItemJson = {
195
208
  value: string;
196
209
  formats?: TextFormatSpan2Json[];
197
- math_objects?: MathObject2Json[];
210
+ math_objects?: Array<Document2MathObjectJson | null>;
198
211
  blocks?: Document2BlockJson[];
199
212
  };
200
213
  type Document2Diagnostic = {
@@ -688,6 +701,9 @@ type Document2LatexOptions = {
688
701
  declare function inlineFieldLatex(field: InlineField2): string;
689
702
  declare function document2Latex(document: Document2Node, options?: Document2LatexOptions): string;
690
703
 
704
+ /** Convert the live editor AST to the canonical JSON wire format. */
705
+ declare function toDocumentJson2(document: Document2Node): Document2Json;
706
+
691
707
  declare const DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
692
708
  type Document2HistoryStacks = {
693
709
  past: Document2Node[];
@@ -717,7 +733,7 @@ declare function toggleBlockInSelection(state: BlockSelectionState, index: numbe
717
733
  declare function extendBlockSelectionFromAnchor(state: BlockSelectionState, index: number, blockCount: number): BlockSelectionState;
718
734
  declare function remapSelectionAfterRangeMove(selection: BlockSelectionRange, direction: -1 | 1): BlockSelectionRange;
719
735
 
720
- declare function createInlineField2(value?: string, mathObjects?: MathObject2Json[], options?: ImportDocument2Options, path?: string, diagnostics?: Document2Diagnostic[], formats?: TextFormatSpan2Json[]): InlineField2;
736
+ declare function createInlineField2(value?: string, mathObjects?: Array<Document2MathObjectJson | null>, options?: ImportDocument2Options, path?: string, diagnostics?: Document2Diagnostic[], formats?: TextFormatSpan2Json[]): InlineField2;
721
737
  declare function fromDocumentJson2(json: unknown, options?: ImportDocument2Options): Document2Node;
722
738
  declare function createEmptyDocument2(): Document2Node;
723
739
 
@@ -750,4 +766,4 @@ type Document2PreviewOptions = {
750
766
  };
751
767
  declare function document2Preview(document: Document2Node, output?: Document2MathOutput, equationSide?: EditorSide, previewOptions?: Document2PreviewOptions): Document2Preview;
752
768
 
753
- 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 Document2Block, type Document2BlockJson, type Document2Diagnostic, type Document2Direction, type Document2HijriDate, type Document2HistoryStacks, type Document2Json, type Document2KeyError, type Document2KeyNamespace, type Document2LabelEntry, type Document2LabelKind, type Document2LatexOptions, type Document2MathOutput, type Document2Meta, type Document2MetaProp, type Document2Node, type Document2Preview, type Document2PreviewOptions, 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 RefToken2, type Reference2, type Reference2Json, type ReferenceFieldSeparator, type TableBlock2, type TextBlock2, type TextFormatSpan2Json, type TextStyle2, type TextToken2, absoluteHttpHref, addDocument2ImageBlock, addDocument2ListBlock, addDocument2ListItem, addDocument2Reference, addDocument2TableBlock, addDocument2TextBlock, applyFloatMetaPatch, arabicXeLatexPreambleCmd, arabicXeLatexPreambleFont, arabicXeLatexPreamblePkg, bibliographyEntryBody, bibliographyEntryLatex, butexBasmalaDisplayLatex, butexBasmalaDisplayTex, butexBasmalaTitlingPreamble, butexDiwaniDisplayLatex, butexDiwaniDisplayTex, butexInColumnMaketitleHook, citeTokenLatex, cloneDocument2Meta, cloneDocument2Node, collectDocument2Labels, createDocument2History, createEmptyArabicEquationSession, createEmptyDocument2, createEmptyEquationSession, createEmptyReference2, createInlineField2, defaultFloatMeta, detectInlineSpans2, detectMathSpans2, document2HasAbstract, document2HasMaketitle, document2HasTitleStack, document2HistoryCanRedo, document2HistoryCanUndo, document2KeyError, document2Latex, 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, toggleBlockInSelection, toggleTextTokenStyle, updateCiteTokenKeys, updateDocument2ImageMeta, updateDocument2ImageValue, updateDocument2Meta, updateDocument2Reference, updateDocument2TableMeta, updateDocument2TextBlockCentered, updateMathTokenLabel, updateRefTokenKeys, updateTextToken };
769
+ 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 Document2Block, type Document2BlockJson, type Document2Diagnostic, type Document2Direction, type Document2HijriDate, type Document2HistoryStacks, type Document2Json, type Document2KeyError, type Document2KeyNamespace, type Document2LabelEntry, type Document2LabelKind, type Document2LatexOptions, type Document2MathObjectJson, type Document2MathOutput, type Document2Meta, type Document2MetaProp, type Document2Node, type Document2Preview, type Document2PreviewOptions, 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, applyFloatMetaPatch, arabicXeLatexPreambleCmd, arabicXeLatexPreambleFont, arabicXeLatexPreamblePkg, bibliographyEntryBody, bibliographyEntryLatex, butexBasmalaDisplayLatex, butexBasmalaDisplayTex, butexBasmalaTitlingPreamble, butexDiwaniDisplayLatex, butexDiwaniDisplayTex, butexInColumnMaketitleHook, citeTokenLatex, cloneDocument2Meta, cloneDocument2Node, collectDocument2Labels, createDocument2History, createEmptyArabicEquationSession, createEmptyDocument2, createEmptyEquationSession, createEmptyReference2, createInlineField2, defaultFloatMeta, detectInlineSpans2, detectMathSpans2, document2HasAbstract, document2HasMaketitle, document2HasTitleStack, document2HistoryCanRedo, document2HistoryCanUndo, document2KeyError, document2Latex, 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, updateDocument2ImageMeta, updateDocument2ImageValue, updateDocument2Meta, updateDocument2Reference, updateDocument2TableMeta, updateDocument2TextBlockCentered, updateMathTokenLabel, updateRefTokenKeys, updateTextToken };
@@ -142,7 +142,20 @@ type MathObject2Json = {
142
142
  math_mode: string;
143
143
  lines: ChainJson[];
144
144
  closing: string;
145
+ /** Side used by the delimited source stored in the containing value/cell. */
146
+ source_side?: Document2ParseMode;
147
+ /** Preserve whether LaTeX export should prefer imported AST rendering or editor source. */
148
+ source_owner?: 'imported-structured' | 'editor';
149
+ label_enabled?: boolean;
150
+ label?: string;
151
+ };
152
+ /** Positional metadata for a raw-only span that has no structured equation AST. */
153
+ type RawMathObject2Json = {
154
+ node_type: 'RawMathObject';
155
+ label_enabled?: boolean;
156
+ label?: string;
145
157
  };
158
+ type Document2MathObjectJson = MathObject2Json | RawMathObject2Json;
146
159
  type ReferenceFieldSeparator = ',' | '،';
147
160
  type Reference2Json = {
148
161
  key: string;
@@ -178,7 +191,7 @@ type Document2BlockJson = {
178
191
  formats?: TextFormatSpan2Json[];
179
192
  /** Stable host asset identity (e.g. S3 key / UUID); optional for \\includegraphics. */
180
193
  asset_id?: string;
181
- math_objects?: MathObject2Json[];
194
+ math_objects?: Array<Document2MathObjectJson | null>;
182
195
  options?: Record<string, string>;
183
196
  closing?: string;
184
197
  items?: Document2ListItemJson[];
@@ -194,7 +207,7 @@ type Document2BlockJson = {
194
207
  type Document2ListItemJson = {
195
208
  value: string;
196
209
  formats?: TextFormatSpan2Json[];
197
- math_objects?: MathObject2Json[];
210
+ math_objects?: Array<Document2MathObjectJson | null>;
198
211
  blocks?: Document2BlockJson[];
199
212
  };
200
213
  type Document2Diagnostic = {
@@ -688,6 +701,9 @@ type Document2LatexOptions = {
688
701
  declare function inlineFieldLatex(field: InlineField2): string;
689
702
  declare function document2Latex(document: Document2Node, options?: Document2LatexOptions): string;
690
703
 
704
+ /** Convert the live editor AST to the canonical JSON wire format. */
705
+ declare function toDocumentJson2(document: Document2Node): Document2Json;
706
+
691
707
  declare const DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
692
708
  type Document2HistoryStacks = {
693
709
  past: Document2Node[];
@@ -717,7 +733,7 @@ declare function toggleBlockInSelection(state: BlockSelectionState, index: numbe
717
733
  declare function extendBlockSelectionFromAnchor(state: BlockSelectionState, index: number, blockCount: number): BlockSelectionState;
718
734
  declare function remapSelectionAfterRangeMove(selection: BlockSelectionRange, direction: -1 | 1): BlockSelectionRange;
719
735
 
720
- declare function createInlineField2(value?: string, mathObjects?: MathObject2Json[], options?: ImportDocument2Options, path?: string, diagnostics?: Document2Diagnostic[], formats?: TextFormatSpan2Json[]): InlineField2;
736
+ declare function createInlineField2(value?: string, mathObjects?: Array<Document2MathObjectJson | null>, options?: ImportDocument2Options, path?: string, diagnostics?: Document2Diagnostic[], formats?: TextFormatSpan2Json[]): InlineField2;
721
737
  declare function fromDocumentJson2(json: unknown, options?: ImportDocument2Options): Document2Node;
722
738
  declare function createEmptyDocument2(): Document2Node;
723
739
 
@@ -750,4 +766,4 @@ type Document2PreviewOptions = {
750
766
  };
751
767
  declare function document2Preview(document: Document2Node, output?: Document2MathOutput, equationSide?: EditorSide, previewOptions?: Document2PreviewOptions): Document2Preview;
752
768
 
753
- 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 Document2Block, type Document2BlockJson, type Document2Diagnostic, type Document2Direction, type Document2HijriDate, type Document2HistoryStacks, type Document2Json, type Document2KeyError, type Document2KeyNamespace, type Document2LabelEntry, type Document2LabelKind, type Document2LatexOptions, type Document2MathOutput, type Document2Meta, type Document2MetaProp, type Document2Node, type Document2Preview, type Document2PreviewOptions, 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 RefToken2, type Reference2, type Reference2Json, type ReferenceFieldSeparator, type TableBlock2, type TextBlock2, type TextFormatSpan2Json, type TextStyle2, type TextToken2, absoluteHttpHref, addDocument2ImageBlock, addDocument2ListBlock, addDocument2ListItem, addDocument2Reference, addDocument2TableBlock, addDocument2TextBlock, applyFloatMetaPatch, arabicXeLatexPreambleCmd, arabicXeLatexPreambleFont, arabicXeLatexPreamblePkg, bibliographyEntryBody, bibliographyEntryLatex, butexBasmalaDisplayLatex, butexBasmalaDisplayTex, butexBasmalaTitlingPreamble, butexDiwaniDisplayLatex, butexDiwaniDisplayTex, butexInColumnMaketitleHook, citeTokenLatex, cloneDocument2Meta, cloneDocument2Node, collectDocument2Labels, createDocument2History, createEmptyArabicEquationSession, createEmptyDocument2, createEmptyEquationSession, createEmptyReference2, createInlineField2, defaultFloatMeta, detectInlineSpans2, detectMathSpans2, document2HasAbstract, document2HasMaketitle, document2HasTitleStack, document2HistoryCanRedo, document2HistoryCanUndo, document2KeyError, document2Latex, 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, toggleBlockInSelection, toggleTextTokenStyle, updateCiteTokenKeys, updateDocument2ImageMeta, updateDocument2ImageValue, updateDocument2Meta, updateDocument2Reference, updateDocument2TableMeta, updateDocument2TextBlockCentered, updateMathTokenLabel, updateRefTokenKeys, updateTextToken };
769
+ 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 Document2Block, type Document2BlockJson, type Document2Diagnostic, type Document2Direction, type Document2HijriDate, type Document2HistoryStacks, type Document2Json, type Document2KeyError, type Document2KeyNamespace, type Document2LabelEntry, type Document2LabelKind, type Document2LatexOptions, type Document2MathObjectJson, type Document2MathOutput, type Document2Meta, type Document2MetaProp, type Document2Node, type Document2Preview, type Document2PreviewOptions, 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, applyFloatMetaPatch, arabicXeLatexPreambleCmd, arabicXeLatexPreambleFont, arabicXeLatexPreamblePkg, bibliographyEntryBody, bibliographyEntryLatex, butexBasmalaDisplayLatex, butexBasmalaDisplayTex, butexBasmalaTitlingPreamble, butexDiwaniDisplayLatex, butexDiwaniDisplayTex, butexInColumnMaketitleHook, citeTokenLatex, cloneDocument2Meta, cloneDocument2Node, collectDocument2Labels, createDocument2History, createEmptyArabicEquationSession, createEmptyDocument2, createEmptyEquationSession, createEmptyReference2, createInlineField2, defaultFloatMeta, detectInlineSpans2, detectMathSpans2, document2HasAbstract, document2HasMaketitle, document2HasTitleStack, document2HistoryCanRedo, document2HistoryCanUndo, document2KeyError, document2Latex, 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, updateDocument2ImageMeta, updateDocument2ImageValue, updateDocument2Meta, updateDocument2Reference, updateDocument2TableMeta, updateDocument2TextBlockCentered, updateMathTokenLabel, updateRefTokenKeys, updateTextToken };
package/dist/document2.js CHANGED
@@ -132,6 +132,7 @@ __export(document2_exports, {
132
132
  restoreDocument2Undo: () => restoreDocument2Undo,
133
133
  setDocument2References: () => setDocument2References,
134
134
  stripDisplayMathDelimiters: () => stripDisplayMathDelimiters,
135
+ toDocumentJson2: () => toDocumentJson2,
135
136
  toggleBlockInSelection: () => toggleBlockInSelection,
136
137
  toggleTextTokenStyle: () => toggleTextTokenStyle,
137
138
  updateCiteTokenKeys: () => updateCiteTokenKeys,
@@ -853,6 +854,66 @@ function fromMathObjectJson(json, mode = "english") {
853
854
  closing: json.closing
854
855
  };
855
856
  }
857
+ function scriptsToJson(node, path) {
858
+ return {
859
+ ...node.superscript ? { superscript: chainToJson(node.superscript, `${path}.superscript`) } : {},
860
+ ...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {}
861
+ };
862
+ }
863
+ function nodeToJson(node, path) {
864
+ const scripts = scriptsToJson(node, path);
865
+ if (node instanceof CharNode || node instanceof NumberNode || node instanceof OperatorNode) {
866
+ return { node_type: node.nodeType, expr: node.expr, ...scripts };
867
+ }
868
+ if (node instanceof DelimiterNode) {
869
+ return {
870
+ node_type: "DelimiterObject",
871
+ left_delim_expr: node.leftDelimExpr,
872
+ inner_expr: chainToJson(node.innerExpr, `${path}.inner_expr`),
873
+ right_delim_expr: node.rightDelimExpr,
874
+ ...scripts
875
+ };
876
+ }
877
+ if (node instanceof CommandNode) {
878
+ return {
879
+ node_type: "CommandObject",
880
+ name: node.name,
881
+ optional_args: node.optionalArgs.map((arg, index) => chainToJson(arg, `${path}.optional_args[${String(index)}]`)),
882
+ mandatory_args: node.mandatoryArgs.map((arg, index) => chainToJson(arg, `${path}.mandatory_args[${String(index)}]`)),
883
+ ...scripts
884
+ };
885
+ }
886
+ if (node instanceof EnvNode) {
887
+ return {
888
+ node_type: "EnvObject",
889
+ opening: node.opening,
890
+ lines: node.lines.map((line, index) => chainToJson(line, `${path}.lines[${String(index)}]`)),
891
+ closing: node.closing,
892
+ ...scripts
893
+ };
894
+ }
895
+ throw new Error(`Unsupported runtime math node at ${path}: ${node.nodeType}`);
896
+ }
897
+ function chainToJson(chain, path) {
898
+ if (!(chain instanceof ChainNode)) {
899
+ throw new Error(`Expected live ChainNode at ${path}`);
900
+ }
901
+ return {
902
+ node_type: "ChainClass",
903
+ chain: chain.chain.map((node, index) => nodeToJson(node, `${path}.chain[${String(index)}]`))
904
+ };
905
+ }
906
+ function toMathObjectJson(math) {
907
+ if (math.nodeType !== "MathObject" || !Array.isArray(math.lines) || math.lines.length === 0) {
908
+ throw new Error("Cannot serialize invalid runtime MathObject");
909
+ }
910
+ return {
911
+ node_type: "MathObject",
912
+ math_mode: math.mathMode,
913
+ lines: math.lines.map((line, index) => chainToJson(line, `$.lines[${String(index)}]`)),
914
+ closing: math.closing
915
+ };
916
+ }
856
917
  function renderMathNodeLatex(math) {
857
918
  const lines = math.lines.map((line) => line.arabicLatex());
858
919
  if (math.mathMode === "$" || math.mathMode === "\\(") {
@@ -1317,10 +1378,11 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
1317
1378
  }
1318
1379
  const mathJson = mathObjects[mathObjectIndex];
1319
1380
  mathObjectIndex += 1;
1320
- if (mathJson && (mathJson.math_mode !== span.opening || mathJson.closing !== span.closing)) {
1381
+ const structuredMathJson = mathJson?.node_type === "MathObject" ? mathJson : null;
1382
+ if (structuredMathJson && (structuredMathJson.math_mode !== span.opening || structuredMathJson.closing !== span.closing)) {
1321
1383
  pushDiagnostic(diagnostics, options, path, "math_objects order mismatch");
1322
1384
  }
1323
- if (mathJson && mathJson.math_mode === span.opening && mathJson.closing === span.closing) {
1385
+ if (structuredMathJson && structuredMathJson.math_mode === span.opening && structuredMathJson.closing === span.closing) {
1324
1386
  tokens.push({
1325
1387
  id: document2Id("math"),
1326
1388
  kind: "math",
@@ -1328,10 +1390,12 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
1328
1390
  opening: span.opening,
1329
1391
  closing: span.closing,
1330
1392
  source: span.source,
1331
- sourceSide: mode,
1332
- math: fromMathObjectJson(mathJson, mode),
1393
+ sourceSide: structuredMathJson.source_side === "arabic" || structuredMathJson.source_side === "english" ? structuredMathJson.source_side : mode,
1394
+ math: fromMathObjectJson(structuredMathJson, mode),
1333
1395
  editable: true,
1334
- sourceOwner: "imported-structured"
1396
+ sourceOwner: structuredMathJson.source_owner === "editor" ? "editor" : "imported-structured",
1397
+ ...typeof structuredMathJson.label_enabled === "boolean" ? { labelEnabled: structuredMathJson.label_enabled } : {},
1398
+ ...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {}
1335
1399
  });
1336
1400
  } else {
1337
1401
  tokens.push({
@@ -1344,7 +1408,9 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
1344
1408
  math: null,
1345
1409
  editable: false,
1346
1410
  reason: "\u0647\u0630\u0647 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u0645\u062D\u0641\u0648\u0638\u0629 \u0643\u0646\u0635 \u062E\u0627\u0645 \u0641\u0642\u0637 \u062D\u0627\u0644\u064A\u0627",
1347
- sourceOwner: "raw"
1411
+ sourceOwner: "raw",
1412
+ ...mathJson?.node_type === "RawMathObject" && typeof mathJson.label_enabled === "boolean" ? { labelEnabled: mathJson.label_enabled } : {},
1413
+ ...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {}
1348
1414
  });
1349
1415
  }
1350
1416
  index = span.end;
@@ -5552,6 +5618,155 @@ ${body}
5552
5618
  `;
5553
5619
  }
5554
5620
 
5621
+ // src/document2/exportJson.ts
5622
+ function serializeField(field) {
5623
+ let value = "";
5624
+ let hasPersistedMath = false;
5625
+ const formats = [];
5626
+ const mathObjects = [];
5627
+ for (const token of field.tokens) {
5628
+ if (token.kind === "text") {
5629
+ const start = value.length;
5630
+ value += token.text;
5631
+ if (token.text.length > 0 && (token.style?.bold || token.style?.italic || token.style?.underline)) {
5632
+ formats.push({
5633
+ start,
5634
+ end: value.length,
5635
+ ...token.style.bold ? { bold: true } : {},
5636
+ ...token.style.italic ? { italic: true } : {},
5637
+ ...token.style.underline ? { underline: true } : {}
5638
+ });
5639
+ }
5640
+ continue;
5641
+ }
5642
+ if (token.kind === "cite") {
5643
+ value += citeTokenLatex(token.keys);
5644
+ continue;
5645
+ }
5646
+ if (token.kind === "ref") {
5647
+ value += refTokenLatex(token.keys, token.refCommand);
5648
+ continue;
5649
+ }
5650
+ value += token.source;
5651
+ if (!token.math || token.sourceOwner === "raw") {
5652
+ if (token.labelEnabled !== void 0 || token.label !== void 0) {
5653
+ hasPersistedMath = true;
5654
+ mathObjects.push({
5655
+ node_type: "RawMathObject",
5656
+ ...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
5657
+ ...token.label !== void 0 ? { label: token.label } : {}
5658
+ });
5659
+ } else {
5660
+ mathObjects.push(null);
5661
+ }
5662
+ continue;
5663
+ }
5664
+ hasPersistedMath = true;
5665
+ mathObjects.push({
5666
+ ...toMathObjectJson(token.math),
5667
+ ...token.sourceSide ? { source_side: token.sourceSide } : {},
5668
+ source_owner: token.sourceOwner,
5669
+ ...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
5670
+ ...token.label !== void 0 ? { label: token.label } : {}
5671
+ });
5672
+ }
5673
+ return { value, formats, mathObjects, hasPersistedMath };
5674
+ }
5675
+ function fieldJson(field) {
5676
+ const serialized = serializeField(field);
5677
+ return {
5678
+ value: serialized.value,
5679
+ ...serialized.formats.length > 0 ? { formats: serialized.formats } : {},
5680
+ ...serialized.hasPersistedMath ? { math_objects: serialized.mathObjects } : {}
5681
+ };
5682
+ }
5683
+ function listItemJson(item) {
5684
+ const field = fieldJson(item.field);
5685
+ return {
5686
+ value: field.value ?? "",
5687
+ ...field.formats ? { formats: field.formats } : {},
5688
+ ...field.math_objects ? { math_objects: field.math_objects } : {},
5689
+ ...item.blocks.length > 0 ? { blocks: item.blocks.map(blockJson) } : {}
5690
+ };
5691
+ }
5692
+ function blockJson(block) {
5693
+ if (block.kind === "textBlock") {
5694
+ return {
5695
+ command: block.command,
5696
+ ...fieldJson(block.field),
5697
+ ...block.command === "\\paragraph" ? { centered: block.centered === true } : {}
5698
+ };
5699
+ }
5700
+ if (block.kind === "list") {
5701
+ return {
5702
+ command: block.command,
5703
+ closing: block.closing,
5704
+ items: block.items.map(listItemJson)
5705
+ };
5706
+ }
5707
+ if (block.kind === "table") {
5708
+ const fields = block.rows.map((row) => row.map(serializeField));
5709
+ const hasPersistedMath = fields.some((row) => row.some((field) => field.hasPersistedMath));
5710
+ return {
5711
+ command: block.command,
5712
+ closing: block.closing,
5713
+ columns: block.columns,
5714
+ rows: fields.map((row) => row.map((field) => field.value)),
5715
+ ...fields.some((row) => row.some((field) => field.formats.length > 0)) ? { cell_formats: fields.map((row) => row.map((field) => field.formats)) } : {},
5716
+ ...hasPersistedMath ? { math_objects: fields.flatMap((row) => row.flatMap((field) => field.mathObjects)) } : {},
5717
+ centered: block.centered,
5718
+ caption_enabled: block.captionEnabled,
5719
+ caption: block.caption,
5720
+ label_enabled: block.labelEnabled,
5721
+ label: block.label
5722
+ };
5723
+ }
5724
+ if (block.kind === "image") {
5725
+ return {
5726
+ command: block.command,
5727
+ value: block.value,
5728
+ ...block.assetId !== void 0 ? { asset_id: block.assetId } : {},
5729
+ options: { ...block.options },
5730
+ centered: block.centered,
5731
+ caption_enabled: block.captionEnabled,
5732
+ caption: block.caption,
5733
+ label_enabled: block.labelEnabled,
5734
+ label: block.label
5735
+ };
5736
+ }
5737
+ if (block.kind === "bibliography") {
5738
+ return { command: block.command, closing: block.closing };
5739
+ }
5740
+ return { command: block.command, value: block.value };
5741
+ }
5742
+ function referenceJson(reference) {
5743
+ return {
5744
+ key: reference.key,
5745
+ authors: reference.authors,
5746
+ title: reference.title,
5747
+ year: reference.year,
5748
+ url: reference.url,
5749
+ venue: reference.venue,
5750
+ field_separator: reference.fieldSeparator
5751
+ };
5752
+ }
5753
+ function toDocumentJson2(document2) {
5754
+ if (document2.nodeType !== "DocumentObject" || !Array.isArray(document2.blocks)) {
5755
+ throw new Error("toDocumentJson2 requires a live Document2Node");
5756
+ }
5757
+ return {
5758
+ node_type: "DocumentObject",
5759
+ meta: {
5760
+ title: document2.meta.title,
5761
+ authors: document2.meta.authors,
5762
+ date: { ...document2.meta.date },
5763
+ abstract: document2.meta.abstract
5764
+ },
5765
+ references: document2.references.map(referenceJson),
5766
+ blocks: document2.blocks.map(blockJson)
5767
+ };
5768
+ }
5769
+
5555
5770
  // src/document2/history.ts
5556
5771
  var DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
5557
5772
  function createDocument2History(maxDepth = DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH) {
@@ -5934,6 +6149,7 @@ function document2Preview(document2, output = "svg", equationSide = "arabic", pr
5934
6149
  restoreDocument2Undo,
5935
6150
  setDocument2References,
5936
6151
  stripDisplayMathDelimiters,
6152
+ toDocumentJson2,
5937
6153
  toggleBlockInSelection,
5938
6154
  toggleTextTokenStyle,
5939
6155
  updateCiteTokenKeys,