@drghaliasri/butex 7.0.3 → 7.1.0
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 +376 -34
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +83 -3
- package/dist/document2.d.ts +83 -3
- package/dist/document2.js +399 -37
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +396 -37
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document2-preview.d.mts +336 -0
- package/dist/react-document2-preview.d.ts +336 -0
- package/dist/react-document2-preview.js +7767 -0
- package/dist/react-document2-preview.js.map +1 -0
- package/dist/react-document2-preview.mjs +7737 -0
- package/dist/react-document2-preview.mjs.map +1 -0
- package/dist/react-document2.d.mts +53 -14
- package/dist/react-document2.d.ts +53 -14
- package/dist/react-document2.js +284 -42
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +281 -41
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +9 -2
package/dist/document2.js
CHANGED
|
@@ -69,6 +69,7 @@ __export(public_exports, {
|
|
|
69
69
|
defaultFloatMeta: () => defaultFloatMeta,
|
|
70
70
|
detectInlineSpans2: () => detectInlineSpans2,
|
|
71
71
|
detectMathSpans2: () => detectMathSpans2,
|
|
72
|
+
diffDocument2: () => diffDocument2,
|
|
72
73
|
document2HasAbstract: () => document2HasAbstract,
|
|
73
74
|
document2HasMaketitle: () => document2HasMaketitle,
|
|
74
75
|
document2HasTitleStack: () => document2HasTitleStack,
|
|
@@ -92,6 +93,8 @@ __export(public_exports, {
|
|
|
92
93
|
formatRefLabel: () => formatRefLabel,
|
|
93
94
|
fromDocumentJson2: () => fromDocumentJson2,
|
|
94
95
|
getArabicXeLatexPreamble: () => getArabicXeLatexPreamble,
|
|
96
|
+
getDocument2ReferenceIndex: () => getDocument2ReferenceIndex,
|
|
97
|
+
getDocument2References: () => getDocument2References,
|
|
95
98
|
hasXeLatexUnsupportedEmoji: () => hasXeLatexUnsupportedEmoji,
|
|
96
99
|
hijriMonthLabel: () => hijriMonthLabel,
|
|
97
100
|
inlineFieldLatex: () => inlineFieldLatex,
|
|
@@ -966,6 +969,10 @@ function defaultFloatMeta() {
|
|
|
966
969
|
centered: true,
|
|
967
970
|
captionEnabled: false,
|
|
968
971
|
caption: "",
|
|
972
|
+
captionField: {
|
|
973
|
+
id: document2Id("field"),
|
|
974
|
+
tokens: [{ id: document2Id("text"), kind: "text", text: "" }]
|
|
975
|
+
},
|
|
969
976
|
labelEnabled: false,
|
|
970
977
|
label: ""
|
|
971
978
|
};
|
|
@@ -1024,15 +1031,20 @@ function collectDocument2Labels(document2) {
|
|
|
1024
1031
|
}
|
|
1025
1032
|
function walk(blocks) {
|
|
1026
1033
|
for (const block of blocks) {
|
|
1027
|
-
if (block.kind === "image"
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1034
|
+
if (block.kind === "image") {
|
|
1035
|
+
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
1036
|
+
counters.fig += 1;
|
|
1037
|
+
entries.push({
|
|
1038
|
+
key: block.label.trim(),
|
|
1039
|
+
kind: "fig",
|
|
1040
|
+
caption: block.captionEnabled ? block.caption : "",
|
|
1041
|
+
ownerId: block.id,
|
|
1042
|
+
number: counters.fig
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
if (block.captionEnabled) {
|
|
1046
|
+
pushEqFromField(block.captionField.tokens);
|
|
1047
|
+
}
|
|
1036
1048
|
}
|
|
1037
1049
|
if (block.kind === "table") {
|
|
1038
1050
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
@@ -1045,6 +1057,9 @@ function collectDocument2Labels(document2) {
|
|
|
1045
1057
|
number: counters.tab
|
|
1046
1058
|
});
|
|
1047
1059
|
}
|
|
1060
|
+
if (block.captionEnabled) {
|
|
1061
|
+
pushEqFromField(block.captionField.tokens);
|
|
1062
|
+
}
|
|
1048
1063
|
for (const row of block.rows) {
|
|
1049
1064
|
for (const cell of row) {
|
|
1050
1065
|
pushEqFromField(cell.tokens);
|
|
@@ -1137,6 +1152,14 @@ function applyFloatMetaPatch(block, patch) {
|
|
|
1137
1152
|
}
|
|
1138
1153
|
if (typeof patch.caption === "string") {
|
|
1139
1154
|
block.caption = patch.caption;
|
|
1155
|
+
const existingText = block.captionField.tokens.find((token) => token.kind === "text");
|
|
1156
|
+
block.captionField.tokens = [
|
|
1157
|
+
{
|
|
1158
|
+
id: existingText?.id ?? document2Id("text"),
|
|
1159
|
+
kind: "text",
|
|
1160
|
+
text: patch.caption
|
|
1161
|
+
}
|
|
1162
|
+
];
|
|
1140
1163
|
}
|
|
1141
1164
|
if (typeof patch.labelEnabled === "boolean") {
|
|
1142
1165
|
block.labelEnabled = patch.labelEnabled;
|
|
@@ -1656,6 +1679,21 @@ function parseListBlock(json, options, path, diagnostics, identities) {
|
|
|
1656
1679
|
...metadataFromJson(json.metadata)
|
|
1657
1680
|
};
|
|
1658
1681
|
}
|
|
1682
|
+
function captionFieldFromJson(json, options, path, diagnostics, identities) {
|
|
1683
|
+
const caption = typeof json.caption === "string" ? json.caption : "";
|
|
1684
|
+
return applyImportedInlineIds(
|
|
1685
|
+
createInlineField2(
|
|
1686
|
+
caption,
|
|
1687
|
+
json.caption_math_objects ?? [],
|
|
1688
|
+
options,
|
|
1689
|
+
`${path}.caption`,
|
|
1690
|
+
diagnostics,
|
|
1691
|
+
json.caption_formats ?? []
|
|
1692
|
+
),
|
|
1693
|
+
json.caption_inline_ids,
|
|
1694
|
+
identities
|
|
1695
|
+
);
|
|
1696
|
+
}
|
|
1659
1697
|
function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
1660
1698
|
if (!Array.isArray(json.rows)) {
|
|
1661
1699
|
throw new Error("\\begin{tabular} requires rows array");
|
|
@@ -1682,6 +1720,7 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1682
1720
|
if (mathObjects.length > 0 && mathObjects.length !== mathObjectIndex) {
|
|
1683
1721
|
pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathObjectIndex)}, got ${String(mathObjects.length)}`);
|
|
1684
1722
|
}
|
|
1723
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1685
1724
|
return {
|
|
1686
1725
|
id: blockIdFromJson(json, identities),
|
|
1687
1726
|
kind: "table",
|
|
@@ -1689,13 +1728,15 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1689
1728
|
closing: "\\end{tabular}",
|
|
1690
1729
|
columns: typeof json.columns === "string" ? json.columns : "",
|
|
1691
1730
|
rows,
|
|
1692
|
-
...
|
|
1731
|
+
...floatMeta,
|
|
1732
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1693
1733
|
...metadataFromJson(json.metadata)
|
|
1694
1734
|
};
|
|
1695
1735
|
}
|
|
1696
|
-
function parseImageBlock(json, identities) {
|
|
1736
|
+
function parseImageBlock(json, options, path, diagnostics, identities) {
|
|
1697
1737
|
const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
|
|
1698
1738
|
const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
|
|
1739
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1699
1740
|
return {
|
|
1700
1741
|
id: blockIdFromJson(json, identities),
|
|
1701
1742
|
kind: "image",
|
|
@@ -1703,7 +1744,8 @@ function parseImageBlock(json, identities) {
|
|
|
1703
1744
|
value,
|
|
1704
1745
|
...assetId !== void 0 ? { assetId } : {},
|
|
1705
1746
|
options: isRecordOfStrings(json.options) ? json.options : {},
|
|
1706
|
-
...
|
|
1747
|
+
...floatMeta,
|
|
1748
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1707
1749
|
...metadataFromJson(json.metadata)
|
|
1708
1750
|
};
|
|
1709
1751
|
}
|
|
@@ -1736,7 +1778,7 @@ function parseBlock(json, options, path, diagnostics, identities) {
|
|
|
1736
1778
|
return parseTableBlock(json, options, path, diagnostics, identities);
|
|
1737
1779
|
}
|
|
1738
1780
|
if (json.command === "\\includegraphics") {
|
|
1739
|
-
return parseImageBlock(json, identities);
|
|
1781
|
+
return parseImageBlock(json, options, path, diagnostics, identities);
|
|
1740
1782
|
}
|
|
1741
1783
|
if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
|
|
1742
1784
|
return parseBibliographyBlock(json, identities);
|
|
@@ -4763,6 +4805,20 @@ function cloneToken(token) {
|
|
|
4763
4805
|
function cloneField(field) {
|
|
4764
4806
|
return { id: field.id, tokens: field.tokens.map(cloneToken) };
|
|
4765
4807
|
}
|
|
4808
|
+
function inlineFieldSource(field) {
|
|
4809
|
+
return field.tokens.map((token) => {
|
|
4810
|
+
if (token.kind === "text") {
|
|
4811
|
+
return token.text;
|
|
4812
|
+
}
|
|
4813
|
+
if (token.kind === "cite") {
|
|
4814
|
+
return citeTokenLatex(token.keys);
|
|
4815
|
+
}
|
|
4816
|
+
if (token.kind === "ref") {
|
|
4817
|
+
return refTokenLatex(token.keys, token.refCommand);
|
|
4818
|
+
}
|
|
4819
|
+
return token.source;
|
|
4820
|
+
}).join("");
|
|
4821
|
+
}
|
|
4766
4822
|
function cloneBlock(block) {
|
|
4767
4823
|
const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
|
|
4768
4824
|
if (block.kind === "textBlock") {
|
|
@@ -4780,10 +4836,20 @@ function cloneBlock(block) {
|
|
|
4780
4836
|
};
|
|
4781
4837
|
}
|
|
4782
4838
|
if (block.kind === "table") {
|
|
4783
|
-
return {
|
|
4839
|
+
return {
|
|
4840
|
+
...block,
|
|
4841
|
+
...metadata,
|
|
4842
|
+
rows: block.rows.map((row) => row.map(cloneField)),
|
|
4843
|
+
captionField: cloneField(block.captionField)
|
|
4844
|
+
};
|
|
4784
4845
|
}
|
|
4785
4846
|
if (block.kind === "image") {
|
|
4786
|
-
return {
|
|
4847
|
+
return {
|
|
4848
|
+
...block,
|
|
4849
|
+
...metadata,
|
|
4850
|
+
options: { ...block.options },
|
|
4851
|
+
captionField: cloneField(block.captionField)
|
|
4852
|
+
};
|
|
4787
4853
|
}
|
|
4788
4854
|
return { ...block, ...metadata };
|
|
4789
4855
|
}
|
|
@@ -4796,6 +4862,13 @@ function cloneDocument(document2) {
|
|
|
4796
4862
|
diagnostics: document2.diagnostics.map((diagnostic) => ({ ...diagnostic }))
|
|
4797
4863
|
};
|
|
4798
4864
|
}
|
|
4865
|
+
function visitCaptionField(block, visitor) {
|
|
4866
|
+
if (!visitor(block.captionField)) {
|
|
4867
|
+
return false;
|
|
4868
|
+
}
|
|
4869
|
+
block.caption = inlineFieldSource(block.captionField);
|
|
4870
|
+
return true;
|
|
4871
|
+
}
|
|
4799
4872
|
function visitFields(blocks, visitor) {
|
|
4800
4873
|
for (const block of blocks) {
|
|
4801
4874
|
if (block.kind === "textBlock") {
|
|
@@ -4816,6 +4889,11 @@ function visitFields(blocks, visitor) {
|
|
|
4816
4889
|
}
|
|
4817
4890
|
}
|
|
4818
4891
|
}
|
|
4892
|
+
if (visitCaptionField(block, visitor)) {
|
|
4893
|
+
return true;
|
|
4894
|
+
}
|
|
4895
|
+
} else if (block.kind === "image" && visitCaptionField(block, visitor)) {
|
|
4896
|
+
return true;
|
|
4819
4897
|
}
|
|
4820
4898
|
}
|
|
4821
4899
|
return false;
|
|
@@ -5693,6 +5771,9 @@ function findField(blocks, fieldId) {
|
|
|
5693
5771
|
if (block.kind === "textBlock" && block.field.id === fieldId) {
|
|
5694
5772
|
return block.field;
|
|
5695
5773
|
}
|
|
5774
|
+
if ((block.kind === "image" || block.kind === "table") && block.captionField.id === fieldId) {
|
|
5775
|
+
return block.captionField;
|
|
5776
|
+
}
|
|
5696
5777
|
if (block.kind === "list") {
|
|
5697
5778
|
for (const item of block.items) {
|
|
5698
5779
|
if (item.field.id === fieldId) {
|
|
@@ -5731,26 +5812,30 @@ function findBlock(blocks, blockId) {
|
|
|
5731
5812
|
}
|
|
5732
5813
|
return null;
|
|
5733
5814
|
}
|
|
5815
|
+
function collectFieldIdentity(field, sets) {
|
|
5816
|
+
sets.fields.add(field.id);
|
|
5817
|
+
field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5818
|
+
}
|
|
5734
5819
|
function collectIdentitySets(blocks, sets) {
|
|
5735
5820
|
for (const block of blocks) {
|
|
5736
5821
|
sets.blocks.add(block.id);
|
|
5737
5822
|
if (block.kind === "textBlock") {
|
|
5738
|
-
|
|
5739
|
-
block.field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5823
|
+
collectFieldIdentity(block.field, sets);
|
|
5740
5824
|
} else if (block.kind === "list") {
|
|
5741
5825
|
for (const item of block.items) {
|
|
5742
5826
|
sets.items.add(item.id);
|
|
5743
|
-
|
|
5744
|
-
item.field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5827
|
+
collectFieldIdentity(item.field, sets);
|
|
5745
5828
|
collectIdentitySets(item.blocks, sets);
|
|
5746
5829
|
}
|
|
5747
5830
|
} else if (block.kind === "table") {
|
|
5831
|
+
collectFieldIdentity(block.captionField, sets);
|
|
5748
5832
|
for (const row of block.rows) {
|
|
5749
5833
|
for (const field of row) {
|
|
5750
|
-
|
|
5751
|
-
field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5834
|
+
collectFieldIdentity(field, sets);
|
|
5752
5835
|
}
|
|
5753
5836
|
}
|
|
5837
|
+
} else if (block.kind === "image") {
|
|
5838
|
+
collectFieldIdentity(block.captionField, sets);
|
|
5754
5839
|
}
|
|
5755
5840
|
}
|
|
5756
5841
|
}
|
|
@@ -6085,6 +6170,37 @@ function applyReferenceFields(reference, command) {
|
|
|
6085
6170
|
reference.fieldSeparator = command.field_separator;
|
|
6086
6171
|
}
|
|
6087
6172
|
}
|
|
6173
|
+
function replaceCitationKey(document2, previousKey, nextKey) {
|
|
6174
|
+
function replaceInField(field) {
|
|
6175
|
+
for (const token of field.tokens) {
|
|
6176
|
+
if (token.kind === "cite") {
|
|
6177
|
+
token.keys = token.keys.map((key) => key === previousKey ? nextKey : key);
|
|
6178
|
+
}
|
|
6179
|
+
}
|
|
6180
|
+
}
|
|
6181
|
+
function visitBlocks(blocks) {
|
|
6182
|
+
for (const block of blocks) {
|
|
6183
|
+
if (block.kind === "textBlock") {
|
|
6184
|
+
replaceInField(block.field);
|
|
6185
|
+
} else if (block.kind === "table") {
|
|
6186
|
+
replaceInField(block.captionField);
|
|
6187
|
+
for (const row of block.rows) {
|
|
6188
|
+
for (const cell of row) {
|
|
6189
|
+
replaceInField(cell);
|
|
6190
|
+
}
|
|
6191
|
+
}
|
|
6192
|
+
} else if (block.kind === "image") {
|
|
6193
|
+
replaceInField(block.captionField);
|
|
6194
|
+
} else if (block.kind === "list") {
|
|
6195
|
+
for (const item of block.items) {
|
|
6196
|
+
replaceInField(item.field);
|
|
6197
|
+
visitBlocks(item.blocks);
|
|
6198
|
+
}
|
|
6199
|
+
}
|
|
6200
|
+
}
|
|
6201
|
+
}
|
|
6202
|
+
visitBlocks(document2.blocks);
|
|
6203
|
+
}
|
|
6088
6204
|
function applyArticleCommand(document2, command) {
|
|
6089
6205
|
if (command.op === "update_document_meta") {
|
|
6090
6206
|
document2.meta = {
|
|
@@ -6113,7 +6229,10 @@ function applyArticleCommand(document2, command) {
|
|
|
6113
6229
|
const target = document2.references[targetIndex];
|
|
6114
6230
|
if (command.op === "update_reference") {
|
|
6115
6231
|
if (command.key !== void 0) {
|
|
6116
|
-
|
|
6232
|
+
const previousKey = target.key;
|
|
6233
|
+
const nextKey = validateReferenceKey(document2, command.key, target.id);
|
|
6234
|
+
target.key = nextKey;
|
|
6235
|
+
replaceCitationKey(document2, previousKey, nextKey);
|
|
6117
6236
|
}
|
|
6118
6237
|
applyReferenceFields(target, command);
|
|
6119
6238
|
return;
|
|
@@ -6542,10 +6661,15 @@ function insertTable(document2, command) {
|
|
|
6542
6661
|
columns: command.columns,
|
|
6543
6662
|
rows: command.rows.map((row) => row.map((cell) => createCommandInlineField(document2, cell))),
|
|
6544
6663
|
...defaultFloatMeta(),
|
|
6545
|
-
...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
|
|
6546
6664
|
...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
|
|
6547
6665
|
...command.metadata ? { metadata: { ...command.metadata } } : {}
|
|
6548
6666
|
};
|
|
6667
|
+
if (command.caption !== void 0) {
|
|
6668
|
+
applyFloatMetaPatch(block, {
|
|
6669
|
+
caption: command.caption,
|
|
6670
|
+
captionEnabled: command.caption.trim().length > 0
|
|
6671
|
+
});
|
|
6672
|
+
}
|
|
6549
6673
|
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
|
|
6550
6674
|
}
|
|
6551
6675
|
function checkCell(table, rowIndex, columnIndex) {
|
|
@@ -6690,6 +6814,15 @@ function fieldJson(field) {
|
|
|
6690
6814
|
...serialized.hasPersistedMath ? { math_objects: serialized.mathObjects } : {}
|
|
6691
6815
|
};
|
|
6692
6816
|
}
|
|
6817
|
+
function captionJson(field) {
|
|
6818
|
+
const serialized = serializeField(field);
|
|
6819
|
+
return {
|
|
6820
|
+
caption: serialized.value,
|
|
6821
|
+
caption_inline_ids: serialized.inlineIds,
|
|
6822
|
+
...serialized.formats.length > 0 ? { caption_formats: serialized.formats } : {},
|
|
6823
|
+
...serialized.hasPersistedMath ? { caption_math_objects: serialized.mathObjects } : {}
|
|
6824
|
+
};
|
|
6825
|
+
}
|
|
6693
6826
|
function listItemJson(item) {
|
|
6694
6827
|
const field = fieldJson(item.field);
|
|
6695
6828
|
return {
|
|
@@ -6734,7 +6867,7 @@ function blockJson(block) {
|
|
|
6734
6867
|
...hasPersistedMath ? { math_objects: fields.flatMap((row) => row.flatMap((field) => field.mathObjects)) } : {},
|
|
6735
6868
|
centered: block.centered,
|
|
6736
6869
|
caption_enabled: block.captionEnabled,
|
|
6737
|
-
|
|
6870
|
+
...captionJson(block.captionField),
|
|
6738
6871
|
label_enabled: block.labelEnabled,
|
|
6739
6872
|
label: block.label,
|
|
6740
6873
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -6749,7 +6882,7 @@ function blockJson(block) {
|
|
|
6749
6882
|
options: { ...block.options },
|
|
6750
6883
|
centered: block.centered,
|
|
6751
6884
|
caption_enabled: block.captionEnabled,
|
|
6752
|
-
|
|
6885
|
+
...captionJson(block.captionField),
|
|
6753
6886
|
label_enabled: block.labelEnabled,
|
|
6754
6887
|
label: block.label,
|
|
6755
6888
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -7076,10 +7209,15 @@ function applyBasicCommand(document2, command) {
|
|
|
7076
7209
|
assetId: command.asset_id,
|
|
7077
7210
|
options: { width: "0.8\\columnwidth" },
|
|
7078
7211
|
...defaultFloatMeta(),
|
|
7079
|
-
...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
|
|
7080
7212
|
...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
|
|
7081
7213
|
...command.metadata ? { metadata: { ...command.metadata } } : {}
|
|
7082
7214
|
};
|
|
7215
|
+
if (command.caption !== void 0) {
|
|
7216
|
+
applyFloatMetaPatch(block, {
|
|
7217
|
+
caption: command.caption,
|
|
7218
|
+
captionEnabled: command.caption.trim().length > 0
|
|
7219
|
+
});
|
|
7220
|
+
}
|
|
7083
7221
|
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
|
|
7084
7222
|
}
|
|
7085
7223
|
function applyDocument2Command(json, commandInput) {
|
|
@@ -7099,6 +7237,104 @@ function applyDocument2Command(json, commandInput) {
|
|
|
7099
7237
|
return toDocumentJson2(document2);
|
|
7100
7238
|
}
|
|
7101
7239
|
|
|
7240
|
+
// src/document2/diff.ts
|
|
7241
|
+
var import_diff = require("diff");
|
|
7242
|
+
var MAX_TOTAL_TEXT_CHARS = 16e3;
|
|
7243
|
+
var MAX_CHANGED_CHUNK_CHARS = 4e3;
|
|
7244
|
+
var MAX_CONTEXT_CHUNK_CHARS = 600;
|
|
7245
|
+
var TRUNCATION_MARKER = "\n\u2026\n";
|
|
7246
|
+
var IDENTITY_KEYS = /* @__PURE__ */ new Set(["id", "inline_ids", "caption_inline_ids", "cell_inline_ids"]);
|
|
7247
|
+
function comparisonValue(value, key) {
|
|
7248
|
+
if (key && IDENTITY_KEYS.has(key)) {
|
|
7249
|
+
return void 0;
|
|
7250
|
+
}
|
|
7251
|
+
if (Array.isArray(value)) {
|
|
7252
|
+
return value.map((entry) => comparisonValue(entry));
|
|
7253
|
+
}
|
|
7254
|
+
if (value && typeof value === "object") {
|
|
7255
|
+
const result = {};
|
|
7256
|
+
for (const childKey of Object.keys(value).sort()) {
|
|
7257
|
+
const child = comparisonValue(value[childKey], childKey);
|
|
7258
|
+
if (child !== void 0) {
|
|
7259
|
+
result[childKey] = child;
|
|
7260
|
+
}
|
|
7261
|
+
}
|
|
7262
|
+
return result;
|
|
7263
|
+
}
|
|
7264
|
+
return value;
|
|
7265
|
+
}
|
|
7266
|
+
function normalizedComparisonDocument(document2) {
|
|
7267
|
+
return comparisonValue(toDocumentJson2(fromDocumentJson2(document2)));
|
|
7268
|
+
}
|
|
7269
|
+
function withoutFinalNewline(value) {
|
|
7270
|
+
return value.endsWith("\n") ? value.slice(0, -1) : value;
|
|
7271
|
+
}
|
|
7272
|
+
function shorten(text, limit, mode) {
|
|
7273
|
+
if (text.length <= limit) {
|
|
7274
|
+
return { text, truncated: false };
|
|
7275
|
+
}
|
|
7276
|
+
if (limit <= TRUNCATION_MARKER.length) {
|
|
7277
|
+
return { text: text.slice(0, Math.max(0, limit)), truncated: true };
|
|
7278
|
+
}
|
|
7279
|
+
const available = limit - TRUNCATION_MARKER.length;
|
|
7280
|
+
if (mode === "head") {
|
|
7281
|
+
return { text: `${text.slice(0, available)}${TRUNCATION_MARKER}`, truncated: true };
|
|
7282
|
+
}
|
|
7283
|
+
if (mode === "tail") {
|
|
7284
|
+
return { text: `${TRUNCATION_MARKER}${text.slice(text.length - available)}`, truncated: true };
|
|
7285
|
+
}
|
|
7286
|
+
const head = Math.ceil(available / 2);
|
|
7287
|
+
const tail = available - head;
|
|
7288
|
+
return {
|
|
7289
|
+
text: `${text.slice(0, head)}${TRUNCATION_MARKER}${text.slice(text.length - tail)}`,
|
|
7290
|
+
truncated: true
|
|
7291
|
+
};
|
|
7292
|
+
}
|
|
7293
|
+
function diffDocument2(before, after) {
|
|
7294
|
+
const beforeComparable = normalizedComparisonDocument(before);
|
|
7295
|
+
const afterComparable = normalizedComparisonDocument(after);
|
|
7296
|
+
const parts = (0, import_diff.diffJson)(beforeComparable, afterComparable);
|
|
7297
|
+
const changed = parts.some((part) => part.added === true || part.removed === true);
|
|
7298
|
+
if (!changed) {
|
|
7299
|
+
return { version: 1, changed: false, truncated: false, chunks: [] };
|
|
7300
|
+
}
|
|
7301
|
+
const chunks = [];
|
|
7302
|
+
let truncated = false;
|
|
7303
|
+
let totalTextChars = 0;
|
|
7304
|
+
const append = (kind, rawText, limit, mode) => {
|
|
7305
|
+
const cleaned = withoutFinalNewline(rawText);
|
|
7306
|
+
if (cleaned.length === 0) return;
|
|
7307
|
+
const perChunk = shorten(cleaned, limit, mode);
|
|
7308
|
+
truncated ||= perChunk.truncated;
|
|
7309
|
+
const remaining = MAX_TOTAL_TEXT_CHARS - totalTextChars;
|
|
7310
|
+
if (remaining <= 0) {
|
|
7311
|
+
truncated = true;
|
|
7312
|
+
return;
|
|
7313
|
+
}
|
|
7314
|
+
const withinBudget = shorten(perChunk.text, remaining, mode);
|
|
7315
|
+
truncated ||= withinBudget.truncated;
|
|
7316
|
+
if (withinBudget.text.length === 0) return;
|
|
7317
|
+
chunks.push({ kind, text: withinBudget.text });
|
|
7318
|
+
totalTextChars += withinBudget.text.length;
|
|
7319
|
+
};
|
|
7320
|
+
parts.forEach((part, index) => {
|
|
7321
|
+
if (part.added) {
|
|
7322
|
+
append("added", part.value, MAX_CHANGED_CHUNK_CHARS, "both");
|
|
7323
|
+
return;
|
|
7324
|
+
}
|
|
7325
|
+
if (part.removed) {
|
|
7326
|
+
append("removed", part.value, MAX_CHANGED_CHUNK_CHARS, "both");
|
|
7327
|
+
return;
|
|
7328
|
+
}
|
|
7329
|
+
const previousChanged = index > 0 && (parts[index - 1]?.added === true || parts[index - 1]?.removed === true);
|
|
7330
|
+
const nextChanged = index + 1 < parts.length && (parts[index + 1]?.added === true || parts[index + 1]?.removed === true);
|
|
7331
|
+
if (!previousChanged && !nextChanged) return;
|
|
7332
|
+
const mode = previousChanged && nextChanged ? "both" : previousChanged ? "head" : "tail";
|
|
7333
|
+
append("context", part.value, MAX_CONTEXT_CHUNK_CHARS, mode);
|
|
7334
|
+
});
|
|
7335
|
+
return { version: 1, changed: true, truncated, chunks };
|
|
7336
|
+
}
|
|
7337
|
+
|
|
7102
7338
|
// src/document2/outline.ts
|
|
7103
7339
|
var EXCERPT_LIMIT = 160;
|
|
7104
7340
|
function normalizeExcerpt(value) {
|
|
@@ -7173,6 +7409,119 @@ function document2Outline(json) {
|
|
|
7173
7409
|
});
|
|
7174
7410
|
}
|
|
7175
7411
|
|
|
7412
|
+
// src/document2/introspection.ts
|
|
7413
|
+
function appendUnique(target, seen, values) {
|
|
7414
|
+
for (const value of values) {
|
|
7415
|
+
if (!seen.has(value)) {
|
|
7416
|
+
seen.add(value);
|
|
7417
|
+
target.push(value);
|
|
7418
|
+
}
|
|
7419
|
+
}
|
|
7420
|
+
}
|
|
7421
|
+
function getDocument2References(document2) {
|
|
7422
|
+
return document2.references.map((reference) => ({
|
|
7423
|
+
key: reference.key,
|
|
7424
|
+
authors: reference.authors,
|
|
7425
|
+
title: reference.title,
|
|
7426
|
+
year: reference.year,
|
|
7427
|
+
venue: reference.venue,
|
|
7428
|
+
url: reference.url,
|
|
7429
|
+
field_separator: reference.fieldSeparator
|
|
7430
|
+
}));
|
|
7431
|
+
}
|
|
7432
|
+
function getDocument2ReferenceIndex(document2) {
|
|
7433
|
+
const referenceKeys = new Set(document2.references.map((reference) => reference.key));
|
|
7434
|
+
const labelEntries = collectDocument2Labels(document2);
|
|
7435
|
+
const labelKeys = new Set(labelEntries.map((entry) => entry.key));
|
|
7436
|
+
const citations = [];
|
|
7437
|
+
const crossReferences = [];
|
|
7438
|
+
const tokenLocations = /* @__PURE__ */ new Map();
|
|
7439
|
+
const unresolvedCitationKeys = [];
|
|
7440
|
+
const unresolvedCrossReferenceKeys = [];
|
|
7441
|
+
const seenCitationKeys = /* @__PURE__ */ new Set();
|
|
7442
|
+
const seenCrossReferenceKeys = /* @__PURE__ */ new Set();
|
|
7443
|
+
function visitField(blockId, field) {
|
|
7444
|
+
for (const token of field.tokens) {
|
|
7445
|
+
tokenLocations.set(token.id, { block_id: blockId, field_id: field.id });
|
|
7446
|
+
if (token.kind === "cite") {
|
|
7447
|
+
const unresolvedKeys = token.keys.filter((key) => !referenceKeys.has(key));
|
|
7448
|
+
citations.push({
|
|
7449
|
+
kind: "cite",
|
|
7450
|
+
block_id: blockId,
|
|
7451
|
+
field_id: field.id,
|
|
7452
|
+
token_id: token.id,
|
|
7453
|
+
keys: [...token.keys],
|
|
7454
|
+
unresolved_keys: unresolvedKeys
|
|
7455
|
+
});
|
|
7456
|
+
appendUnique(unresolvedCitationKeys, seenCitationKeys, unresolvedKeys);
|
|
7457
|
+
} else if (token.kind === "ref") {
|
|
7458
|
+
const unresolvedKeys = token.keys.filter((key) => !labelKeys.has(key));
|
|
7459
|
+
crossReferences.push({
|
|
7460
|
+
kind: "ref",
|
|
7461
|
+
ref_command: token.refCommand,
|
|
7462
|
+
block_id: blockId,
|
|
7463
|
+
field_id: field.id,
|
|
7464
|
+
token_id: token.id,
|
|
7465
|
+
keys: [...token.keys],
|
|
7466
|
+
unresolved_keys: unresolvedKeys
|
|
7467
|
+
});
|
|
7468
|
+
appendUnique(unresolvedCrossReferenceKeys, seenCrossReferenceKeys, unresolvedKeys);
|
|
7469
|
+
}
|
|
7470
|
+
}
|
|
7471
|
+
}
|
|
7472
|
+
function visitBlocks(blocks) {
|
|
7473
|
+
for (const block of blocks) {
|
|
7474
|
+
if (block.kind === "textBlock") {
|
|
7475
|
+
visitField(block.id, block.field);
|
|
7476
|
+
} else if (block.kind === "table") {
|
|
7477
|
+
visitField(block.id, block.captionField);
|
|
7478
|
+
for (const row of block.rows) {
|
|
7479
|
+
for (const cell of row) {
|
|
7480
|
+
visitField(block.id, cell);
|
|
7481
|
+
}
|
|
7482
|
+
}
|
|
7483
|
+
} else if (block.kind === "image") {
|
|
7484
|
+
visitField(block.id, block.captionField);
|
|
7485
|
+
} else if (block.kind === "list") {
|
|
7486
|
+
for (const item of block.items) {
|
|
7487
|
+
visitField(block.id, item.field);
|
|
7488
|
+
visitBlocks(item.blocks);
|
|
7489
|
+
}
|
|
7490
|
+
}
|
|
7491
|
+
}
|
|
7492
|
+
}
|
|
7493
|
+
visitBlocks(document2.blocks);
|
|
7494
|
+
const labels = labelEntries.map((entry) => {
|
|
7495
|
+
if (entry.kind !== "eq") {
|
|
7496
|
+
return {
|
|
7497
|
+
key: entry.key,
|
|
7498
|
+
kind: entry.kind,
|
|
7499
|
+
caption: entry.caption,
|
|
7500
|
+
number: entry.number,
|
|
7501
|
+
block_id: entry.ownerId
|
|
7502
|
+
};
|
|
7503
|
+
}
|
|
7504
|
+
const location = tokenLocations.get(entry.ownerId);
|
|
7505
|
+
return {
|
|
7506
|
+
key: entry.key,
|
|
7507
|
+
kind: entry.kind,
|
|
7508
|
+
caption: entry.caption,
|
|
7509
|
+
number: entry.number,
|
|
7510
|
+
...location ? { block_id: location.block_id, field_id: location.field_id } : {},
|
|
7511
|
+
token_id: entry.ownerId
|
|
7512
|
+
};
|
|
7513
|
+
});
|
|
7514
|
+
return {
|
|
7515
|
+
citations,
|
|
7516
|
+
cross_references: crossReferences,
|
|
7517
|
+
labels,
|
|
7518
|
+
unresolved: {
|
|
7519
|
+
citation_keys: unresolvedCitationKeys,
|
|
7520
|
+
cross_reference_keys: unresolvedCrossReferenceKeys
|
|
7521
|
+
}
|
|
7522
|
+
};
|
|
7523
|
+
}
|
|
7524
|
+
|
|
7176
7525
|
// src/document2/arabicPreamble.ts
|
|
7177
7526
|
function fontOptions(digitsMapping, includeScript = true) {
|
|
7178
7527
|
const parts = [];
|
|
@@ -7543,11 +7892,12 @@ ${block.closing}`;
|
|
|
7543
7892
|
${rows.join(" \\\\\n")}
|
|
7544
7893
|
${block.closing}`;
|
|
7545
7894
|
}
|
|
7546
|
-
function floatCaptionLabelLines(block, counter) {
|
|
7895
|
+
function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
7547
7896
|
const lines = [];
|
|
7548
|
-
const
|
|
7897
|
+
const caption = inlineFieldLatexWithLabelKinds(block.captionField, labelKinds).trim();
|
|
7898
|
+
const hasCaption = block.captionEnabled && caption.length > 0;
|
|
7549
7899
|
if (hasCaption) {
|
|
7550
|
-
lines.push(` \\caption{${
|
|
7900
|
+
lines.push(` \\caption{${caption}}`);
|
|
7551
7901
|
}
|
|
7552
7902
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
7553
7903
|
if (!hasCaption) {
|
|
@@ -7563,7 +7913,7 @@ function tableBlockLatex(block, labelKinds, fixedFloats) {
|
|
|
7563
7913
|
if (block.centered) {
|
|
7564
7914
|
lines.push(" \\centering");
|
|
7565
7915
|
}
|
|
7566
|
-
lines.push(...floatCaptionLabelLines(block, "table"));
|
|
7916
|
+
lines.push(...floatCaptionLabelLines(block, "table", labelKinds));
|
|
7567
7917
|
lines.push(indent(tabularInnerLatex(block, labelKinds)));
|
|
7568
7918
|
lines.push("\\end{table}");
|
|
7569
7919
|
return lines.join("\n");
|
|
@@ -7583,14 +7933,14 @@ function imageOptionsLatex(block, constrainToColumn) {
|
|
|
7583
7933
|
}
|
|
7584
7934
|
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
7585
7935
|
}
|
|
7586
|
-
function imageBlockLatex(block, fixedFloats) {
|
|
7936
|
+
function imageBlockLatex(block, labelKinds, fixedFloats) {
|
|
7587
7937
|
const placement = fixedFloats ? "H" : "htbp";
|
|
7588
7938
|
const lines = [`\\begin{figure}[${placement}]`];
|
|
7589
7939
|
if (block.centered) {
|
|
7590
7940
|
lines.push(" \\centering");
|
|
7591
7941
|
}
|
|
7592
7942
|
lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
|
|
7593
|
-
lines.push(...floatCaptionLabelLines(block, "figure"));
|
|
7943
|
+
lines.push(...floatCaptionLabelLines(block, "figure", labelKinds));
|
|
7594
7944
|
lines.push("\\end{figure}");
|
|
7595
7945
|
return lines.join("\n");
|
|
7596
7946
|
}
|
|
@@ -7605,7 +7955,7 @@ function blockLatex(block, references, labelKinds, fixedFloats) {
|
|
|
7605
7955
|
return tableBlockLatex(block, labelKinds, fixedFloats);
|
|
7606
7956
|
}
|
|
7607
7957
|
if (block.kind === "image") {
|
|
7608
|
-
return imageBlockLatex(block, fixedFloats);
|
|
7958
|
+
return imageBlockLatex(block, labelKinds, fixedFloats);
|
|
7609
7959
|
}
|
|
7610
7960
|
if (block.kind === "bibliography") {
|
|
7611
7961
|
const width = String(Math.max(references.length, 9));
|
|
@@ -7798,7 +8148,7 @@ function validateBlock(context, block, path) {
|
|
|
7798
8148
|
);
|
|
7799
8149
|
});
|
|
7800
8150
|
});
|
|
7801
|
-
|
|
8151
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
7802
8152
|
if (block.labelEnabled) {
|
|
7803
8153
|
registerKey(context, block.label, `${path}.label`, "tab", block.id);
|
|
7804
8154
|
}
|
|
@@ -7811,7 +8161,7 @@ function validateBlock(context, block, path) {
|
|
|
7811
8161
|
addIssue(context, "empty_image", path, block.id);
|
|
7812
8162
|
}
|
|
7813
8163
|
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
7814
|
-
|
|
8164
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
7815
8165
|
if (block.labelEnabled) {
|
|
7816
8166
|
registerKey(context, block.label, `${path}.label`, "fig", block.id);
|
|
7817
8167
|
}
|
|
@@ -8144,6 +8494,15 @@ function floatNumberLabel(document2, key, previewOptions) {
|
|
|
8144
8494
|
digitForm: previewOptions.digitForm
|
|
8145
8495
|
});
|
|
8146
8496
|
}
|
|
8497
|
+
function captionPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
8498
|
+
if (!block.captionEnabled || block.caption.trim().length === 0) {
|
|
8499
|
+
return {};
|
|
8500
|
+
}
|
|
8501
|
+
return {
|
|
8502
|
+
caption: block.caption.trim(),
|
|
8503
|
+
captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
|
|
8504
|
+
};
|
|
8505
|
+
}
|
|
8147
8506
|
function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
8148
8507
|
if (block.kind === "textBlock") {
|
|
8149
8508
|
return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
|
|
@@ -8167,7 +8526,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
8167
8526
|
kind: "table",
|
|
8168
8527
|
id: block.id,
|
|
8169
8528
|
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
|
|
8170
|
-
...block
|
|
8529
|
+
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
8171
8530
|
...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
|
|
8172
8531
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
8173
8532
|
};
|
|
@@ -8181,7 +8540,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
8181
8540
|
...block.assetId !== void 0 ? { assetId: block.assetId } : {},
|
|
8182
8541
|
options: block.options,
|
|
8183
8542
|
centered: block.centered,
|
|
8184
|
-
...block
|
|
8543
|
+
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
8185
8544
|
...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
|
|
8186
8545
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
8187
8546
|
};
|
|
@@ -8308,6 +8667,7 @@ function document2Latex2(document2, options = {}) {
|
|
|
8308
8667
|
defaultFloatMeta,
|
|
8309
8668
|
detectInlineSpans2,
|
|
8310
8669
|
detectMathSpans2,
|
|
8670
|
+
diffDocument2,
|
|
8311
8671
|
document2HasAbstract,
|
|
8312
8672
|
document2HasMaketitle,
|
|
8313
8673
|
document2HasTitleStack,
|
|
@@ -8331,6 +8691,8 @@ function document2Latex2(document2, options = {}) {
|
|
|
8331
8691
|
formatRefLabel,
|
|
8332
8692
|
fromDocumentJson2,
|
|
8333
8693
|
getArabicXeLatexPreamble,
|
|
8694
|
+
getDocument2ReferenceIndex,
|
|
8695
|
+
getDocument2References,
|
|
8334
8696
|
hasXeLatexUnsupportedEmoji,
|
|
8335
8697
|
hijriMonthLabel,
|
|
8336
8698
|
inlineFieldLatex,
|