@drghaliasri/butex 6.1.4 → 6.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +33 -2
- package/dist/document2.d.ts +33 -2
- package/dist/document2.js +321 -16
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +312 -11
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document2.d.mts +10 -2
- package/dist/react-document2.d.ts +10 -2
- package/dist/react-document2.js +414 -15
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +414 -15
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document2.d.mts
CHANGED
|
@@ -905,11 +905,36 @@ type Document2LatexOptions = {
|
|
|
905
905
|
twocolumn?: boolean;
|
|
906
906
|
};
|
|
907
907
|
declare function inlineFieldLatex(field: InlineField2): string;
|
|
908
|
-
declare function document2Latex(document: Document2Node, options?: Document2LatexOptions): string;
|
|
909
908
|
|
|
910
909
|
/** Convert the live editor AST to the canonical JSON wire format. */
|
|
911
910
|
declare function toDocumentJson2(document: Document2Node): Document2Json;
|
|
912
911
|
|
|
912
|
+
type Document2ValidationIssueCode = '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';
|
|
913
|
+
type Document2ValidationIssue = {
|
|
914
|
+
code: Document2ValidationIssueCode;
|
|
915
|
+
path: string;
|
|
916
|
+
blockId?: string;
|
|
917
|
+
tokenId?: string;
|
|
918
|
+
};
|
|
919
|
+
type Document2ValidationResult = {
|
|
920
|
+
valid: boolean;
|
|
921
|
+
issues: Document2ValidationIssue[];
|
|
922
|
+
};
|
|
923
|
+
/** True when the current XeLaTeX text profile cannot render the value reliably. */
|
|
924
|
+
declare function hasXeLatexUnsupportedEmoji(value: string): boolean;
|
|
925
|
+
/**
|
|
926
|
+
* Validate a Document2 draft without mutating it. Detailed issues are kept in
|
|
927
|
+
* BuTeX so React can identify the field while hosts only need the boolean API.
|
|
928
|
+
*/
|
|
929
|
+
declare function validateDocument2(document: Document2Json | Document2Node): Document2ValidationResult;
|
|
930
|
+
/** Public host contract: drafts may be saved, but only valid documents may compile. */
|
|
931
|
+
declare function isDocument2Valid(document: Document2Json | Document2Node): boolean;
|
|
932
|
+
/** Error thrown when LaTeX export is attempted for an invalid Document2 draft. */
|
|
933
|
+
declare class Document2ValidationError extends Error {
|
|
934
|
+
readonly issues: Document2ValidationIssue[];
|
|
935
|
+
constructor(issues: Document2ValidationIssue[]);
|
|
936
|
+
}
|
|
937
|
+
|
|
913
938
|
declare const DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
|
|
914
939
|
type Document2HistoryStacks = {
|
|
915
940
|
past: Document2Node[];
|
|
@@ -972,4 +997,10 @@ type Document2PreviewOptions = {
|
|
|
972
997
|
};
|
|
973
998
|
declare function document2Preview(document: Document2Node, output?: Document2MathOutput, equationSide?: EditorSide, previewOptions?: Document2PreviewOptions): Document2Preview;
|
|
974
999
|
|
|
975
|
-
|
|
1000
|
+
/**
|
|
1001
|
+
* Export a validated Document2 runtime node. Invalid drafts remain saveable,
|
|
1002
|
+
* but compilation must not silently receive unsafe or unreliable LaTeX.
|
|
1003
|
+
*/
|
|
1004
|
+
declare function document2Latex(document: Document2Node, options?: Document2LatexOptions): string;
|
|
1005
|
+
|
|
1006
|
+
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, Document2ValidationError, type Document2ValidationIssue, type Document2ValidationIssueCode, type Document2ValidationResult, 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, hasXeLatexUnsupportedEmoji, hijriMonthLabel, inlineFieldLatex, insertCiteTokenAtCaret, insertDocument2BlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, isDocument2Valid, 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, validateDocument2 };
|
package/dist/document2.d.ts
CHANGED
|
@@ -905,11 +905,36 @@ type Document2LatexOptions = {
|
|
|
905
905
|
twocolumn?: boolean;
|
|
906
906
|
};
|
|
907
907
|
declare function inlineFieldLatex(field: InlineField2): string;
|
|
908
|
-
declare function document2Latex(document: Document2Node, options?: Document2LatexOptions): string;
|
|
909
908
|
|
|
910
909
|
/** Convert the live editor AST to the canonical JSON wire format. */
|
|
911
910
|
declare function toDocumentJson2(document: Document2Node): Document2Json;
|
|
912
911
|
|
|
912
|
+
type Document2ValidationIssueCode = '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';
|
|
913
|
+
type Document2ValidationIssue = {
|
|
914
|
+
code: Document2ValidationIssueCode;
|
|
915
|
+
path: string;
|
|
916
|
+
blockId?: string;
|
|
917
|
+
tokenId?: string;
|
|
918
|
+
};
|
|
919
|
+
type Document2ValidationResult = {
|
|
920
|
+
valid: boolean;
|
|
921
|
+
issues: Document2ValidationIssue[];
|
|
922
|
+
};
|
|
923
|
+
/** True when the current XeLaTeX text profile cannot render the value reliably. */
|
|
924
|
+
declare function hasXeLatexUnsupportedEmoji(value: string): boolean;
|
|
925
|
+
/**
|
|
926
|
+
* Validate a Document2 draft without mutating it. Detailed issues are kept in
|
|
927
|
+
* BuTeX so React can identify the field while hosts only need the boolean API.
|
|
928
|
+
*/
|
|
929
|
+
declare function validateDocument2(document: Document2Json | Document2Node): Document2ValidationResult;
|
|
930
|
+
/** Public host contract: drafts may be saved, but only valid documents may compile. */
|
|
931
|
+
declare function isDocument2Valid(document: Document2Json | Document2Node): boolean;
|
|
932
|
+
/** Error thrown when LaTeX export is attempted for an invalid Document2 draft. */
|
|
933
|
+
declare class Document2ValidationError extends Error {
|
|
934
|
+
readonly issues: Document2ValidationIssue[];
|
|
935
|
+
constructor(issues: Document2ValidationIssue[]);
|
|
936
|
+
}
|
|
937
|
+
|
|
913
938
|
declare const DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
|
|
914
939
|
type Document2HistoryStacks = {
|
|
915
940
|
past: Document2Node[];
|
|
@@ -972,4 +997,10 @@ type Document2PreviewOptions = {
|
|
|
972
997
|
};
|
|
973
998
|
declare function document2Preview(document: Document2Node, output?: Document2MathOutput, equationSide?: EditorSide, previewOptions?: Document2PreviewOptions): Document2Preview;
|
|
974
999
|
|
|
975
|
-
|
|
1000
|
+
/**
|
|
1001
|
+
* Export a validated Document2 runtime node. Invalid drafts remain saveable,
|
|
1002
|
+
* but compilation must not silently receive unsafe or unreliable LaTeX.
|
|
1003
|
+
*/
|
|
1004
|
+
declare function document2Latex(document: Document2Node, options?: Document2LatexOptions): string;
|
|
1005
|
+
|
|
1006
|
+
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, Document2ValidationError, type Document2ValidationIssue, type Document2ValidationIssueCode, type Document2ValidationResult, 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, hasXeLatexUnsupportedEmoji, hijriMonthLabel, inlineFieldLatex, insertCiteTokenAtCaret, insertDocument2BlockAfter, insertMathToken, insertMathTokenAtCaret, insertRefTokenAtCaret, isDocument2Valid, 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, validateDocument2 };
|
package/dist/document2.js
CHANGED
|
@@ -17,9 +17,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/document2/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
20
|
+
// src/document2/public.ts
|
|
21
|
+
var public_exports = {};
|
|
22
|
+
__export(public_exports, {
|
|
23
23
|
BUTEX_BASMALA: () => BUTEX_BASMALA,
|
|
24
24
|
BUTEX_BASMALA_LINE1: () => BUTEX_BASMALA_LINE1,
|
|
25
25
|
BUTEX_BASMALA_LINE2: () => BUTEX_BASMALA_LINE2,
|
|
@@ -29,6 +29,7 @@ __export(document2_exports, {
|
|
|
29
29
|
DEFAULT_HIJRI_DATE: () => DEFAULT_HIJRI_DATE,
|
|
30
30
|
DEFAULT_REFERENCE_FIELD_SEPARATOR: () => DEFAULT_REFERENCE_FIELD_SEPARATOR,
|
|
31
31
|
Document2CommandError: () => Document2CommandError,
|
|
32
|
+
Document2ValidationError: () => Document2ValidationError,
|
|
32
33
|
HIJRI_MONTH_IDS: () => HIJRI_MONTH_IDS,
|
|
33
34
|
HIJRI_YEAR_MAX: () => HIJRI_YEAR_MAX,
|
|
34
35
|
HIJRI_YEAR_MIN: () => HIJRI_YEAR_MIN,
|
|
@@ -74,7 +75,7 @@ __export(document2_exports, {
|
|
|
74
75
|
document2HistoryCanRedo: () => document2HistoryCanRedo,
|
|
75
76
|
document2HistoryCanUndo: () => document2HistoryCanUndo,
|
|
76
77
|
document2KeyError: () => document2KeyError,
|
|
77
|
-
document2Latex: () =>
|
|
78
|
+
document2Latex: () => document2Latex2,
|
|
78
79
|
document2Outline: () => document2Outline,
|
|
79
80
|
document2Preview: () => document2Preview,
|
|
80
81
|
emptyBlockSelection: () => emptyBlockSelection,
|
|
@@ -91,6 +92,7 @@ __export(document2_exports, {
|
|
|
91
92
|
formatRefLabel: () => formatRefLabel,
|
|
92
93
|
fromDocumentJson2: () => fromDocumentJson2,
|
|
93
94
|
getArabicXeLatexPreamble: () => getArabicXeLatexPreamble,
|
|
95
|
+
hasXeLatexUnsupportedEmoji: () => hasXeLatexUnsupportedEmoji,
|
|
94
96
|
hijriMonthLabel: () => hijriMonthLabel,
|
|
95
97
|
inlineFieldLatex: () => inlineFieldLatex,
|
|
96
98
|
insertCiteTokenAtCaret: () => insertCiteTokenAtCaret,
|
|
@@ -98,6 +100,7 @@ __export(document2_exports, {
|
|
|
98
100
|
insertMathToken: () => insertMathToken,
|
|
99
101
|
insertMathTokenAtCaret: () => insertMathTokenAtCaret,
|
|
100
102
|
insertRefTokenAtCaret: () => insertRefTokenAtCaret,
|
|
103
|
+
isDocument2Valid: () => isDocument2Valid,
|
|
101
104
|
isDuplicateDocument2Key: () => isDuplicateDocument2Key,
|
|
102
105
|
isValidDocument2Key: () => isValidDocument2Key,
|
|
103
106
|
labelNumberMap: () => labelNumberMap,
|
|
@@ -151,9 +154,10 @@ __export(document2_exports, {
|
|
|
151
154
|
updateDocument2TextBlockCentered: () => updateDocument2TextBlockCentered,
|
|
152
155
|
updateMathTokenLabel: () => updateMathTokenLabel,
|
|
153
156
|
updateRefTokenKeys: () => updateRefTokenKeys,
|
|
154
|
-
updateTextToken: () => updateTextToken
|
|
157
|
+
updateTextToken: () => updateTextToken,
|
|
158
|
+
validateDocument2: () => validateDocument2
|
|
155
159
|
});
|
|
156
|
-
module.exports = __toCommonJS(
|
|
160
|
+
module.exports = __toCommonJS(public_exports);
|
|
157
161
|
|
|
158
162
|
// src/document2/ids.ts
|
|
159
163
|
var nextId = 1;
|
|
@@ -1070,14 +1074,22 @@ function labelNumberMap(document2) {
|
|
|
1070
1074
|
}
|
|
1071
1075
|
return map;
|
|
1072
1076
|
}
|
|
1077
|
+
function labelKindWord(kind, uiLocale) {
|
|
1078
|
+
if (kind === "fig") {
|
|
1079
|
+
return uiLocale === "ar" ? "\u0627\u0644\u0634\u0643\u0644" : "Figure";
|
|
1080
|
+
}
|
|
1081
|
+
if (kind === "tab") {
|
|
1082
|
+
return uiLocale === "ar" ? "\u0627\u0644\u062C\u062F\u0648\u0644" : "Table";
|
|
1083
|
+
}
|
|
1084
|
+
return uiLocale === "ar" ? "\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629" : "Equation";
|
|
1085
|
+
}
|
|
1073
1086
|
function formatFloatCaptionTitle(kind, number, options = {}) {
|
|
1074
1087
|
const locale = options.uiLocale ?? "ar";
|
|
1075
|
-
const kindWord = kind === "fig" ? locale === "ar" ? "\u0627\u0644\u0634\u0643\u0644" : "Figure" : kind === "tab" ? locale === "ar" ? "\u0627\u0644\u062C\u062F\u0648\u0644" : "Table" : locale === "ar" ? "\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629" : "Equation";
|
|
1076
1088
|
const digits = formatBibliographyNumber(number, {
|
|
1077
1089
|
documentDirection: options.documentDirection ?? (locale === "ar" ? "rtl" : "ltr"),
|
|
1078
1090
|
digitForm: options.digitForm ?? (locale === "ar" ? "arabicIndic" : "western")
|
|
1079
1091
|
});
|
|
1080
|
-
return `${
|
|
1092
|
+
return `${labelKindWord(kind, locale)} ${digits}`;
|
|
1081
1093
|
}
|
|
1082
1094
|
function formatFloatCaptionPreview(title, caption, uiLocale = "ar") {
|
|
1083
1095
|
const trimmed = caption?.trim() ?? "";
|
|
@@ -1090,19 +1102,18 @@ function formatFloatCaptionPreview(title, caption, uiLocale = "ar") {
|
|
|
1090
1102
|
function formatRefLabel(keys, document2, refCommand, options = {}) {
|
|
1091
1103
|
const documentDirection = options.documentDirection ?? "rtl";
|
|
1092
1104
|
const digitForm = options.digitForm ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
|
|
1105
|
+
const uiLocale = documentDirection === "rtl" ? "ar" : "en";
|
|
1093
1106
|
const map = labelNumberMap(document2);
|
|
1094
1107
|
const parts = keys.map((key) => {
|
|
1095
1108
|
const hit = map.get(key);
|
|
1096
1109
|
if (!hit) {
|
|
1097
|
-
return "?";
|
|
1110
|
+
return refCommand === "eqref" ? "(?)" : "?";
|
|
1098
1111
|
}
|
|
1099
|
-
|
|
1112
|
+
const digits = formatDigits(String(hit.number), digitForm);
|
|
1113
|
+
const numberLabel = refCommand === "eqref" ? `(${digits})` : digits;
|
|
1114
|
+
return `${labelKindWord(hit.kind, uiLocale)} ${numberLabel}`;
|
|
1100
1115
|
});
|
|
1101
|
-
|
|
1102
|
-
if (refCommand === "eqref") {
|
|
1103
|
-
return `(${body})`;
|
|
1104
|
-
}
|
|
1105
|
-
return body;
|
|
1116
|
+
return parts.join(documentDirection === "rtl" ? "\u060C" : ", ");
|
|
1106
1117
|
}
|
|
1107
1118
|
function stripDisplayMathDelimiters(source) {
|
|
1108
1119
|
const trimmed = source.trim();
|
|
@@ -7257,6 +7268,287 @@ ${body}
|
|
|
7257
7268
|
`;
|
|
7258
7269
|
}
|
|
7259
7270
|
|
|
7271
|
+
// src/document2/validation.ts
|
|
7272
|
+
var XELATEX_UNSUPPORTED_EMOJI_PATTERN = /[\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Regional_Indicator}\uFE0F\u20E3]/u;
|
|
7273
|
+
function hasXeLatexUnsupportedEmoji(value) {
|
|
7274
|
+
return XELATEX_UNSUPPORTED_EMOJI_PATTERN.test(value);
|
|
7275
|
+
}
|
|
7276
|
+
function addIssue(context, code, path, blockId, tokenId) {
|
|
7277
|
+
context.issues.push({
|
|
7278
|
+
code,
|
|
7279
|
+
path,
|
|
7280
|
+
...blockId ? { blockId } : {},
|
|
7281
|
+
...tokenId ? { tokenId } : {}
|
|
7282
|
+
});
|
|
7283
|
+
}
|
|
7284
|
+
function validateTextValue(context, value, path, blockId, tokenId) {
|
|
7285
|
+
if (hasXeLatexUnsupportedEmoji(value)) {
|
|
7286
|
+
addIssue(context, "unsupported_emoji", path, blockId, tokenId);
|
|
7287
|
+
}
|
|
7288
|
+
}
|
|
7289
|
+
function registerKey(context, key, path, kind, blockId, tokenId) {
|
|
7290
|
+
const normalized = normalizeDocument2Key(key);
|
|
7291
|
+
if (normalized.length === 0) {
|
|
7292
|
+
addIssue(context, "key_empty", path, blockId, tokenId);
|
|
7293
|
+
return;
|
|
7294
|
+
}
|
|
7295
|
+
if (!isValidDocument2Key(normalized)) {
|
|
7296
|
+
addIssue(context, "key_invalid", path, blockId, tokenId);
|
|
7297
|
+
return;
|
|
7298
|
+
}
|
|
7299
|
+
context.keyOwners.push({
|
|
7300
|
+
key: normalized,
|
|
7301
|
+
path,
|
|
7302
|
+
kind,
|
|
7303
|
+
...blockId ? { blockId } : {},
|
|
7304
|
+
...tokenId ? { tokenId } : {}
|
|
7305
|
+
});
|
|
7306
|
+
if (kind !== "reference" && !context.labelKinds.has(normalized)) {
|
|
7307
|
+
context.labelKinds.set(normalized, kind);
|
|
7308
|
+
}
|
|
7309
|
+
}
|
|
7310
|
+
function validateToken(context, token, path, blockId) {
|
|
7311
|
+
if (token.kind === "text") {
|
|
7312
|
+
validateTextValue(context, token.text, `${path}.text`, blockId, token.id);
|
|
7313
|
+
return;
|
|
7314
|
+
}
|
|
7315
|
+
if (token.kind === "cite") {
|
|
7316
|
+
if (token.keys.length === 0) {
|
|
7317
|
+
addIssue(context, "empty_citation", `${path}.keys`, blockId, token.id);
|
|
7318
|
+
}
|
|
7319
|
+
context.pendingCitations.push({ token, path, blockId });
|
|
7320
|
+
return;
|
|
7321
|
+
}
|
|
7322
|
+
if (token.kind === "ref") {
|
|
7323
|
+
if (token.keys.length === 0) {
|
|
7324
|
+
addIssue(context, "empty_reference", `${path}.keys`, blockId, token.id);
|
|
7325
|
+
}
|
|
7326
|
+
context.pendingReferences.push({ token, path, blockId });
|
|
7327
|
+
return;
|
|
7328
|
+
}
|
|
7329
|
+
validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
|
|
7330
|
+
if (!token.labelEnabled) {
|
|
7331
|
+
return;
|
|
7332
|
+
}
|
|
7333
|
+
if (!token.display) {
|
|
7334
|
+
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
7335
|
+
return;
|
|
7336
|
+
}
|
|
7337
|
+
registerKey(context, token.label ?? "", `${path}.label`, "eq", blockId, token.id);
|
|
7338
|
+
}
|
|
7339
|
+
function validateInlineField(context, field, path, blockId) {
|
|
7340
|
+
field.tokens.forEach((token, index) => {
|
|
7341
|
+
validateToken(context, token, `${path}.tokens[${String(index)}]`, blockId);
|
|
7342
|
+
});
|
|
7343
|
+
}
|
|
7344
|
+
function validateBlock(context, block, path) {
|
|
7345
|
+
if (block.kind === "textBlock") {
|
|
7346
|
+
validateInlineField(context, block.field, `${path}.field`, block.id);
|
|
7347
|
+
return;
|
|
7348
|
+
}
|
|
7349
|
+
if (block.kind === "list") {
|
|
7350
|
+
block.items.forEach((item, itemIndex) => {
|
|
7351
|
+
const itemPath = `${path}.items[${String(itemIndex)}]`;
|
|
7352
|
+
validateInlineField(context, item.field, `${itemPath}.field`, block.id);
|
|
7353
|
+
item.blocks.forEach((child, childIndex) => {
|
|
7354
|
+
validateBlock(context, child, `${itemPath}.blocks[${String(childIndex)}]`);
|
|
7355
|
+
});
|
|
7356
|
+
});
|
|
7357
|
+
return;
|
|
7358
|
+
}
|
|
7359
|
+
if (block.kind === "table") {
|
|
7360
|
+
if (block.columns.trim().length === 0 || block.rows.length === 0) {
|
|
7361
|
+
addIssue(context, "invalid_table", path, block.id);
|
|
7362
|
+
}
|
|
7363
|
+
const expectedColumns = block.rows[0]?.length ?? 0;
|
|
7364
|
+
if (expectedColumns === 0 || block.rows.some((row) => row.length !== expectedColumns)) {
|
|
7365
|
+
addIssue(context, "invalid_table", `${path}.rows`, block.id);
|
|
7366
|
+
}
|
|
7367
|
+
block.rows.forEach((row, rowIndex) => {
|
|
7368
|
+
row.forEach((cell, columnIndex) => {
|
|
7369
|
+
validateInlineField(
|
|
7370
|
+
context,
|
|
7371
|
+
cell,
|
|
7372
|
+
`${path}.rows[${String(rowIndex)}][${String(columnIndex)}]`,
|
|
7373
|
+
block.id
|
|
7374
|
+
);
|
|
7375
|
+
});
|
|
7376
|
+
});
|
|
7377
|
+
validateTextValue(context, block.caption, `${path}.caption`, block.id);
|
|
7378
|
+
if (block.labelEnabled) {
|
|
7379
|
+
registerKey(context, block.label, `${path}.label`, "tab", block.id);
|
|
7380
|
+
}
|
|
7381
|
+
return;
|
|
7382
|
+
}
|
|
7383
|
+
if (block.kind === "image") {
|
|
7384
|
+
const hasAssetId = typeof block.assetId === "string" && block.assetId.trim().length > 0;
|
|
7385
|
+
const hasValue = block.value.trim().length > 0;
|
|
7386
|
+
if (!hasAssetId && !hasValue) {
|
|
7387
|
+
addIssue(context, "empty_image", path, block.id);
|
|
7388
|
+
}
|
|
7389
|
+
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
7390
|
+
validateTextValue(context, block.caption, `${path}.caption`, block.id);
|
|
7391
|
+
if (block.labelEnabled) {
|
|
7392
|
+
registerKey(context, block.label, `${path}.label`, "fig", block.id);
|
|
7393
|
+
}
|
|
7394
|
+
return;
|
|
7395
|
+
}
|
|
7396
|
+
if (block.kind === "raw") {
|
|
7397
|
+
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
7398
|
+
}
|
|
7399
|
+
}
|
|
7400
|
+
function validateDuplicateKeys(context) {
|
|
7401
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
7402
|
+
for (const owner of context.keyOwners) {
|
|
7403
|
+
const group = grouped.get(owner.key) ?? [];
|
|
7404
|
+
group.push(owner);
|
|
7405
|
+
grouped.set(owner.key, group);
|
|
7406
|
+
}
|
|
7407
|
+
for (const owners of grouped.values()) {
|
|
7408
|
+
if (owners.length < 2) {
|
|
7409
|
+
continue;
|
|
7410
|
+
}
|
|
7411
|
+
for (const owner of owners) {
|
|
7412
|
+
addIssue(context, "key_duplicate", owner.path, owner.blockId, owner.tokenId);
|
|
7413
|
+
}
|
|
7414
|
+
}
|
|
7415
|
+
}
|
|
7416
|
+
function validatePendingReferences(context) {
|
|
7417
|
+
for (const pending of context.pendingCitations) {
|
|
7418
|
+
if (pending.token.keys.some((key) => !isValidDocument2Key(normalizeDocument2Key(key)))) {
|
|
7419
|
+
addIssue(
|
|
7420
|
+
context,
|
|
7421
|
+
"missing_citation",
|
|
7422
|
+
`${pending.path}.keys`,
|
|
7423
|
+
pending.blockId,
|
|
7424
|
+
pending.token.id
|
|
7425
|
+
);
|
|
7426
|
+
}
|
|
7427
|
+
}
|
|
7428
|
+
for (const pending of context.pendingReferences) {
|
|
7429
|
+
for (const key of pending.token.keys) {
|
|
7430
|
+
const normalized = normalizeDocument2Key(key);
|
|
7431
|
+
if (!isValidDocument2Key(normalized)) {
|
|
7432
|
+
addIssue(
|
|
7433
|
+
context,
|
|
7434
|
+
"missing_reference",
|
|
7435
|
+
`${pending.path}.keys`,
|
|
7436
|
+
pending.blockId,
|
|
7437
|
+
pending.token.id
|
|
7438
|
+
);
|
|
7439
|
+
break;
|
|
7440
|
+
}
|
|
7441
|
+
const kind = context.labelKinds.get(normalized);
|
|
7442
|
+
if (kind && pending.token.refCommand === "eqref" !== (kind === "eq")) {
|
|
7443
|
+
addIssue(
|
|
7444
|
+
context,
|
|
7445
|
+
"reference_kind_mismatch",
|
|
7446
|
+
`${pending.path}.keys`,
|
|
7447
|
+
pending.blockId,
|
|
7448
|
+
pending.token.id
|
|
7449
|
+
);
|
|
7450
|
+
break;
|
|
7451
|
+
}
|
|
7452
|
+
}
|
|
7453
|
+
}
|
|
7454
|
+
}
|
|
7455
|
+
function isRecord(value) {
|
|
7456
|
+
return typeof value === "object" && value !== null;
|
|
7457
|
+
}
|
|
7458
|
+
function hasRuntimeDocumentShape(document2) {
|
|
7459
|
+
const value = document2;
|
|
7460
|
+
return isRecord(value) && value.nodeType === "DocumentObject";
|
|
7461
|
+
}
|
|
7462
|
+
function hasWireDocumentShape(document2) {
|
|
7463
|
+
const value = document2;
|
|
7464
|
+
if (!isRecord(value) || value.node_type !== "DocumentObject" || !Array.isArray(value.blocks)) {
|
|
7465
|
+
return false;
|
|
7466
|
+
}
|
|
7467
|
+
if (value.meta !== void 0 && !isRecord(value.meta)) {
|
|
7468
|
+
return false;
|
|
7469
|
+
}
|
|
7470
|
+
if (value.references !== void 0) {
|
|
7471
|
+
if (!Array.isArray(value.references)) {
|
|
7472
|
+
return false;
|
|
7473
|
+
}
|
|
7474
|
+
for (const reference of value.references) {
|
|
7475
|
+
if (!isRecord(reference) || typeof reference.key !== "string" || reference.key.trim().length === 0) {
|
|
7476
|
+
return false;
|
|
7477
|
+
}
|
|
7478
|
+
}
|
|
7479
|
+
}
|
|
7480
|
+
return true;
|
|
7481
|
+
}
|
|
7482
|
+
function resolveDocument(document2) {
|
|
7483
|
+
if (hasRuntimeDocumentShape(document2)) {
|
|
7484
|
+
try {
|
|
7485
|
+
toDocumentJson2(document2);
|
|
7486
|
+
return document2;
|
|
7487
|
+
} catch {
|
|
7488
|
+
return null;
|
|
7489
|
+
}
|
|
7490
|
+
}
|
|
7491
|
+
if (!hasWireDocumentShape(document2)) {
|
|
7492
|
+
return null;
|
|
7493
|
+
}
|
|
7494
|
+
try {
|
|
7495
|
+
return fromDocumentJson2(document2);
|
|
7496
|
+
} catch {
|
|
7497
|
+
return null;
|
|
7498
|
+
}
|
|
7499
|
+
}
|
|
7500
|
+
function validateDocument2(document2) {
|
|
7501
|
+
const resolved = resolveDocument(document2);
|
|
7502
|
+
if (!resolved) {
|
|
7503
|
+
return {
|
|
7504
|
+
valid: false,
|
|
7505
|
+
issues: [{ code: "malformed_document", path: "$" }]
|
|
7506
|
+
};
|
|
7507
|
+
}
|
|
7508
|
+
const context = {
|
|
7509
|
+
issues: [],
|
|
7510
|
+
keyOwners: [],
|
|
7511
|
+
labelKinds: /* @__PURE__ */ new Map(),
|
|
7512
|
+
pendingCitations: [],
|
|
7513
|
+
pendingReferences: []
|
|
7514
|
+
};
|
|
7515
|
+
validateTextValue(context, resolved.meta.title, "$.meta.title");
|
|
7516
|
+
validateTextValue(context, resolved.meta.authors, "$.meta.authors");
|
|
7517
|
+
validateTextValue(context, resolved.meta.abstract, "$.meta.abstract");
|
|
7518
|
+
resolved.references.forEach((reference, index) => {
|
|
7519
|
+
const path = `$.references[${String(index)}]`;
|
|
7520
|
+
registerKey(context, reference.key, `${path}.key`, "reference");
|
|
7521
|
+
validateTextValue(context, reference.authors, `${path}.authors`);
|
|
7522
|
+
validateTextValue(context, reference.title, `${path}.title`);
|
|
7523
|
+
validateTextValue(context, reference.year, `${path}.year`);
|
|
7524
|
+
validateTextValue(context, reference.url, `${path}.url`);
|
|
7525
|
+
validateTextValue(context, reference.venue, `${path}.venue`);
|
|
7526
|
+
});
|
|
7527
|
+
resolved.blocks.forEach((block, index) => {
|
|
7528
|
+
validateBlock(context, block, `$.blocks[${String(index)}]`);
|
|
7529
|
+
});
|
|
7530
|
+
for (const diagnostic of resolved.diagnostics) {
|
|
7531
|
+
addIssue(context, "parser_diagnostic", diagnostic.path);
|
|
7532
|
+
}
|
|
7533
|
+
validateDuplicateKeys(context);
|
|
7534
|
+
validatePendingReferences(context);
|
|
7535
|
+
return {
|
|
7536
|
+
valid: context.issues.length === 0,
|
|
7537
|
+
issues: context.issues
|
|
7538
|
+
};
|
|
7539
|
+
}
|
|
7540
|
+
function isDocument2Valid(document2) {
|
|
7541
|
+
return validateDocument2(document2).valid;
|
|
7542
|
+
}
|
|
7543
|
+
var Document2ValidationError = class extends Error {
|
|
7544
|
+
issues;
|
|
7545
|
+
constructor(issues) {
|
|
7546
|
+
super("Document2 validation failed; invalid drafts cannot be exported to LaTeX.");
|
|
7547
|
+
this.name = "Document2ValidationError";
|
|
7548
|
+
this.issues = issues;
|
|
7549
|
+
}
|
|
7550
|
+
};
|
|
7551
|
+
|
|
7260
7552
|
// src/document2/history.ts
|
|
7261
7553
|
var DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
|
|
7262
7554
|
function createDocument2History(maxDepth = DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH) {
|
|
@@ -7531,6 +7823,15 @@ function document2Preview(document2, output = "svg", equationSide = "arabic", pr
|
|
|
7531
7823
|
mathIslands
|
|
7532
7824
|
};
|
|
7533
7825
|
}
|
|
7826
|
+
|
|
7827
|
+
// src/document2/validatedLatex.ts
|
|
7828
|
+
function document2Latex2(document2, options = {}) {
|
|
7829
|
+
const validation = validateDocument2(document2);
|
|
7830
|
+
if (!validation.valid) {
|
|
7831
|
+
throw new Document2ValidationError(validation.issues);
|
|
7832
|
+
}
|
|
7833
|
+
return document2Latex(document2, options);
|
|
7834
|
+
}
|
|
7534
7835
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7535
7836
|
0 && (module.exports = {
|
|
7536
7837
|
BUTEX_BASMALA,
|
|
@@ -7542,6 +7843,7 @@ function document2Preview(document2, output = "svg", equationSide = "arabic", pr
|
|
|
7542
7843
|
DEFAULT_HIJRI_DATE,
|
|
7543
7844
|
DEFAULT_REFERENCE_FIELD_SEPARATOR,
|
|
7544
7845
|
Document2CommandError,
|
|
7846
|
+
Document2ValidationError,
|
|
7545
7847
|
HIJRI_MONTH_IDS,
|
|
7546
7848
|
HIJRI_YEAR_MAX,
|
|
7547
7849
|
HIJRI_YEAR_MIN,
|
|
@@ -7604,6 +7906,7 @@ function document2Preview(document2, output = "svg", equationSide = "arabic", pr
|
|
|
7604
7906
|
formatRefLabel,
|
|
7605
7907
|
fromDocumentJson2,
|
|
7606
7908
|
getArabicXeLatexPreamble,
|
|
7909
|
+
hasXeLatexUnsupportedEmoji,
|
|
7607
7910
|
hijriMonthLabel,
|
|
7608
7911
|
inlineFieldLatex,
|
|
7609
7912
|
insertCiteTokenAtCaret,
|
|
@@ -7611,6 +7914,7 @@ function document2Preview(document2, output = "svg", equationSide = "arabic", pr
|
|
|
7611
7914
|
insertMathToken,
|
|
7612
7915
|
insertMathTokenAtCaret,
|
|
7613
7916
|
insertRefTokenAtCaret,
|
|
7917
|
+
isDocument2Valid,
|
|
7614
7918
|
isDuplicateDocument2Key,
|
|
7615
7919
|
isValidDocument2Key,
|
|
7616
7920
|
labelNumberMap,
|
|
@@ -7664,6 +7968,7 @@ function document2Preview(document2, output = "svg", equationSide = "arabic", pr
|
|
|
7664
7968
|
updateDocument2TextBlockCentered,
|
|
7665
7969
|
updateMathTokenLabel,
|
|
7666
7970
|
updateRefTokenKeys,
|
|
7667
|
-
updateTextToken
|
|
7971
|
+
updateTextToken,
|
|
7972
|
+
validateDocument2
|
|
7668
7973
|
});
|
|
7669
7974
|
//# sourceMappingURL=document2.js.map
|