@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.mjs
CHANGED
|
@@ -805,6 +805,10 @@ function defaultFloatMeta() {
|
|
|
805
805
|
centered: true,
|
|
806
806
|
captionEnabled: false,
|
|
807
807
|
caption: "",
|
|
808
|
+
captionField: {
|
|
809
|
+
id: document2Id("field"),
|
|
810
|
+
tokens: [{ id: document2Id("text"), kind: "text", text: "" }]
|
|
811
|
+
},
|
|
808
812
|
labelEnabled: false,
|
|
809
813
|
label: ""
|
|
810
814
|
};
|
|
@@ -863,15 +867,20 @@ function collectDocument2Labels(document2) {
|
|
|
863
867
|
}
|
|
864
868
|
function walk(blocks) {
|
|
865
869
|
for (const block of blocks) {
|
|
866
|
-
if (block.kind === "image"
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
870
|
+
if (block.kind === "image") {
|
|
871
|
+
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
872
|
+
counters.fig += 1;
|
|
873
|
+
entries.push({
|
|
874
|
+
key: block.label.trim(),
|
|
875
|
+
kind: "fig",
|
|
876
|
+
caption: block.captionEnabled ? block.caption : "",
|
|
877
|
+
ownerId: block.id,
|
|
878
|
+
number: counters.fig
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
if (block.captionEnabled) {
|
|
882
|
+
pushEqFromField(block.captionField.tokens);
|
|
883
|
+
}
|
|
875
884
|
}
|
|
876
885
|
if (block.kind === "table") {
|
|
877
886
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
@@ -884,6 +893,9 @@ function collectDocument2Labels(document2) {
|
|
|
884
893
|
number: counters.tab
|
|
885
894
|
});
|
|
886
895
|
}
|
|
896
|
+
if (block.captionEnabled) {
|
|
897
|
+
pushEqFromField(block.captionField.tokens);
|
|
898
|
+
}
|
|
887
899
|
for (const row of block.rows) {
|
|
888
900
|
for (const cell of row) {
|
|
889
901
|
pushEqFromField(cell.tokens);
|
|
@@ -976,6 +988,14 @@ function applyFloatMetaPatch(block, patch) {
|
|
|
976
988
|
}
|
|
977
989
|
if (typeof patch.caption === "string") {
|
|
978
990
|
block.caption = patch.caption;
|
|
991
|
+
const existingText = block.captionField.tokens.find((token) => token.kind === "text");
|
|
992
|
+
block.captionField.tokens = [
|
|
993
|
+
{
|
|
994
|
+
id: existingText?.id ?? document2Id("text"),
|
|
995
|
+
kind: "text",
|
|
996
|
+
text: patch.caption
|
|
997
|
+
}
|
|
998
|
+
];
|
|
979
999
|
}
|
|
980
1000
|
if (typeof patch.labelEnabled === "boolean") {
|
|
981
1001
|
block.labelEnabled = patch.labelEnabled;
|
|
@@ -1495,6 +1515,21 @@ function parseListBlock(json, options, path, diagnostics, identities) {
|
|
|
1495
1515
|
...metadataFromJson(json.metadata)
|
|
1496
1516
|
};
|
|
1497
1517
|
}
|
|
1518
|
+
function captionFieldFromJson(json, options, path, diagnostics, identities) {
|
|
1519
|
+
const caption = typeof json.caption === "string" ? json.caption : "";
|
|
1520
|
+
return applyImportedInlineIds(
|
|
1521
|
+
createInlineField2(
|
|
1522
|
+
caption,
|
|
1523
|
+
json.caption_math_objects ?? [],
|
|
1524
|
+
options,
|
|
1525
|
+
`${path}.caption`,
|
|
1526
|
+
diagnostics,
|
|
1527
|
+
json.caption_formats ?? []
|
|
1528
|
+
),
|
|
1529
|
+
json.caption_inline_ids,
|
|
1530
|
+
identities
|
|
1531
|
+
);
|
|
1532
|
+
}
|
|
1498
1533
|
function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
1499
1534
|
if (!Array.isArray(json.rows)) {
|
|
1500
1535
|
throw new Error("\\begin{tabular} requires rows array");
|
|
@@ -1521,6 +1556,7 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1521
1556
|
if (mathObjects.length > 0 && mathObjects.length !== mathObjectIndex) {
|
|
1522
1557
|
pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathObjectIndex)}, got ${String(mathObjects.length)}`);
|
|
1523
1558
|
}
|
|
1559
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1524
1560
|
return {
|
|
1525
1561
|
id: blockIdFromJson(json, identities),
|
|
1526
1562
|
kind: "table",
|
|
@@ -1528,13 +1564,15 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1528
1564
|
closing: "\\end{tabular}",
|
|
1529
1565
|
columns: typeof json.columns === "string" ? json.columns : "",
|
|
1530
1566
|
rows,
|
|
1531
|
-
...
|
|
1567
|
+
...floatMeta,
|
|
1568
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1532
1569
|
...metadataFromJson(json.metadata)
|
|
1533
1570
|
};
|
|
1534
1571
|
}
|
|
1535
|
-
function parseImageBlock(json, identities) {
|
|
1572
|
+
function parseImageBlock(json, options, path, diagnostics, identities) {
|
|
1536
1573
|
const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
|
|
1537
1574
|
const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
|
|
1575
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1538
1576
|
return {
|
|
1539
1577
|
id: blockIdFromJson(json, identities),
|
|
1540
1578
|
kind: "image",
|
|
@@ -1542,7 +1580,8 @@ function parseImageBlock(json, identities) {
|
|
|
1542
1580
|
value,
|
|
1543
1581
|
...assetId !== void 0 ? { assetId } : {},
|
|
1544
1582
|
options: isRecordOfStrings(json.options) ? json.options : {},
|
|
1545
|
-
...
|
|
1583
|
+
...floatMeta,
|
|
1584
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1546
1585
|
...metadataFromJson(json.metadata)
|
|
1547
1586
|
};
|
|
1548
1587
|
}
|
|
@@ -1575,7 +1614,7 @@ function parseBlock(json, options, path, diagnostics, identities) {
|
|
|
1575
1614
|
return parseTableBlock(json, options, path, diagnostics, identities);
|
|
1576
1615
|
}
|
|
1577
1616
|
if (json.command === "\\includegraphics") {
|
|
1578
|
-
return parseImageBlock(json, identities);
|
|
1617
|
+
return parseImageBlock(json, options, path, diagnostics, identities);
|
|
1579
1618
|
}
|
|
1580
1619
|
if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
|
|
1581
1620
|
return parseBibliographyBlock(json, identities);
|
|
@@ -4602,6 +4641,20 @@ function cloneToken(token) {
|
|
|
4602
4641
|
function cloneField(field) {
|
|
4603
4642
|
return { id: field.id, tokens: field.tokens.map(cloneToken) };
|
|
4604
4643
|
}
|
|
4644
|
+
function inlineFieldSource(field) {
|
|
4645
|
+
return field.tokens.map((token) => {
|
|
4646
|
+
if (token.kind === "text") {
|
|
4647
|
+
return token.text;
|
|
4648
|
+
}
|
|
4649
|
+
if (token.kind === "cite") {
|
|
4650
|
+
return citeTokenLatex(token.keys);
|
|
4651
|
+
}
|
|
4652
|
+
if (token.kind === "ref") {
|
|
4653
|
+
return refTokenLatex(token.keys, token.refCommand);
|
|
4654
|
+
}
|
|
4655
|
+
return token.source;
|
|
4656
|
+
}).join("");
|
|
4657
|
+
}
|
|
4605
4658
|
function cloneBlock(block) {
|
|
4606
4659
|
const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
|
|
4607
4660
|
if (block.kind === "textBlock") {
|
|
@@ -4619,10 +4672,20 @@ function cloneBlock(block) {
|
|
|
4619
4672
|
};
|
|
4620
4673
|
}
|
|
4621
4674
|
if (block.kind === "table") {
|
|
4622
|
-
return {
|
|
4675
|
+
return {
|
|
4676
|
+
...block,
|
|
4677
|
+
...metadata,
|
|
4678
|
+
rows: block.rows.map((row) => row.map(cloneField)),
|
|
4679
|
+
captionField: cloneField(block.captionField)
|
|
4680
|
+
};
|
|
4623
4681
|
}
|
|
4624
4682
|
if (block.kind === "image") {
|
|
4625
|
-
return {
|
|
4683
|
+
return {
|
|
4684
|
+
...block,
|
|
4685
|
+
...metadata,
|
|
4686
|
+
options: { ...block.options },
|
|
4687
|
+
captionField: cloneField(block.captionField)
|
|
4688
|
+
};
|
|
4626
4689
|
}
|
|
4627
4690
|
return { ...block, ...metadata };
|
|
4628
4691
|
}
|
|
@@ -4635,6 +4698,13 @@ function cloneDocument(document2) {
|
|
|
4635
4698
|
diagnostics: document2.diagnostics.map((diagnostic) => ({ ...diagnostic }))
|
|
4636
4699
|
};
|
|
4637
4700
|
}
|
|
4701
|
+
function visitCaptionField(block, visitor) {
|
|
4702
|
+
if (!visitor(block.captionField)) {
|
|
4703
|
+
return false;
|
|
4704
|
+
}
|
|
4705
|
+
block.caption = inlineFieldSource(block.captionField);
|
|
4706
|
+
return true;
|
|
4707
|
+
}
|
|
4638
4708
|
function visitFields(blocks, visitor) {
|
|
4639
4709
|
for (const block of blocks) {
|
|
4640
4710
|
if (block.kind === "textBlock") {
|
|
@@ -4655,6 +4725,11 @@ function visitFields(blocks, visitor) {
|
|
|
4655
4725
|
}
|
|
4656
4726
|
}
|
|
4657
4727
|
}
|
|
4728
|
+
if (visitCaptionField(block, visitor)) {
|
|
4729
|
+
return true;
|
|
4730
|
+
}
|
|
4731
|
+
} else if (block.kind === "image" && visitCaptionField(block, visitor)) {
|
|
4732
|
+
return true;
|
|
4658
4733
|
}
|
|
4659
4734
|
}
|
|
4660
4735
|
return false;
|
|
@@ -5532,6 +5607,9 @@ function findField(blocks, fieldId) {
|
|
|
5532
5607
|
if (block.kind === "textBlock" && block.field.id === fieldId) {
|
|
5533
5608
|
return block.field;
|
|
5534
5609
|
}
|
|
5610
|
+
if ((block.kind === "image" || block.kind === "table") && block.captionField.id === fieldId) {
|
|
5611
|
+
return block.captionField;
|
|
5612
|
+
}
|
|
5535
5613
|
if (block.kind === "list") {
|
|
5536
5614
|
for (const item of block.items) {
|
|
5537
5615
|
if (item.field.id === fieldId) {
|
|
@@ -5570,26 +5648,30 @@ function findBlock(blocks, blockId) {
|
|
|
5570
5648
|
}
|
|
5571
5649
|
return null;
|
|
5572
5650
|
}
|
|
5651
|
+
function collectFieldIdentity(field, sets) {
|
|
5652
|
+
sets.fields.add(field.id);
|
|
5653
|
+
field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5654
|
+
}
|
|
5573
5655
|
function collectIdentitySets(blocks, sets) {
|
|
5574
5656
|
for (const block of blocks) {
|
|
5575
5657
|
sets.blocks.add(block.id);
|
|
5576
5658
|
if (block.kind === "textBlock") {
|
|
5577
|
-
|
|
5578
|
-
block.field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5659
|
+
collectFieldIdentity(block.field, sets);
|
|
5579
5660
|
} else if (block.kind === "list") {
|
|
5580
5661
|
for (const item of block.items) {
|
|
5581
5662
|
sets.items.add(item.id);
|
|
5582
|
-
|
|
5583
|
-
item.field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5663
|
+
collectFieldIdentity(item.field, sets);
|
|
5584
5664
|
collectIdentitySets(item.blocks, sets);
|
|
5585
5665
|
}
|
|
5586
5666
|
} else if (block.kind === "table") {
|
|
5667
|
+
collectFieldIdentity(block.captionField, sets);
|
|
5587
5668
|
for (const row of block.rows) {
|
|
5588
5669
|
for (const field of row) {
|
|
5589
|
-
|
|
5590
|
-
field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5670
|
+
collectFieldIdentity(field, sets);
|
|
5591
5671
|
}
|
|
5592
5672
|
}
|
|
5673
|
+
} else if (block.kind === "image") {
|
|
5674
|
+
collectFieldIdentity(block.captionField, sets);
|
|
5593
5675
|
}
|
|
5594
5676
|
}
|
|
5595
5677
|
}
|
|
@@ -5924,6 +6006,37 @@ function applyReferenceFields(reference, command) {
|
|
|
5924
6006
|
reference.fieldSeparator = command.field_separator;
|
|
5925
6007
|
}
|
|
5926
6008
|
}
|
|
6009
|
+
function replaceCitationKey(document2, previousKey, nextKey) {
|
|
6010
|
+
function replaceInField(field) {
|
|
6011
|
+
for (const token of field.tokens) {
|
|
6012
|
+
if (token.kind === "cite") {
|
|
6013
|
+
token.keys = token.keys.map((key) => key === previousKey ? nextKey : key);
|
|
6014
|
+
}
|
|
6015
|
+
}
|
|
6016
|
+
}
|
|
6017
|
+
function visitBlocks(blocks) {
|
|
6018
|
+
for (const block of blocks) {
|
|
6019
|
+
if (block.kind === "textBlock") {
|
|
6020
|
+
replaceInField(block.field);
|
|
6021
|
+
} else if (block.kind === "table") {
|
|
6022
|
+
replaceInField(block.captionField);
|
|
6023
|
+
for (const row of block.rows) {
|
|
6024
|
+
for (const cell of row) {
|
|
6025
|
+
replaceInField(cell);
|
|
6026
|
+
}
|
|
6027
|
+
}
|
|
6028
|
+
} else if (block.kind === "image") {
|
|
6029
|
+
replaceInField(block.captionField);
|
|
6030
|
+
} else if (block.kind === "list") {
|
|
6031
|
+
for (const item of block.items) {
|
|
6032
|
+
replaceInField(item.field);
|
|
6033
|
+
visitBlocks(item.blocks);
|
|
6034
|
+
}
|
|
6035
|
+
}
|
|
6036
|
+
}
|
|
6037
|
+
}
|
|
6038
|
+
visitBlocks(document2.blocks);
|
|
6039
|
+
}
|
|
5927
6040
|
function applyArticleCommand(document2, command) {
|
|
5928
6041
|
if (command.op === "update_document_meta") {
|
|
5929
6042
|
document2.meta = {
|
|
@@ -5952,7 +6065,10 @@ function applyArticleCommand(document2, command) {
|
|
|
5952
6065
|
const target = document2.references[targetIndex];
|
|
5953
6066
|
if (command.op === "update_reference") {
|
|
5954
6067
|
if (command.key !== void 0) {
|
|
5955
|
-
|
|
6068
|
+
const previousKey = target.key;
|
|
6069
|
+
const nextKey = validateReferenceKey(document2, command.key, target.id);
|
|
6070
|
+
target.key = nextKey;
|
|
6071
|
+
replaceCitationKey(document2, previousKey, nextKey);
|
|
5956
6072
|
}
|
|
5957
6073
|
applyReferenceFields(target, command);
|
|
5958
6074
|
return;
|
|
@@ -6381,10 +6497,15 @@ function insertTable(document2, command) {
|
|
|
6381
6497
|
columns: command.columns,
|
|
6382
6498
|
rows: command.rows.map((row) => row.map((cell) => createCommandInlineField(document2, cell))),
|
|
6383
6499
|
...defaultFloatMeta(),
|
|
6384
|
-
...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
|
|
6385
6500
|
...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
|
|
6386
6501
|
...command.metadata ? { metadata: { ...command.metadata } } : {}
|
|
6387
6502
|
};
|
|
6503
|
+
if (command.caption !== void 0) {
|
|
6504
|
+
applyFloatMetaPatch(block, {
|
|
6505
|
+
caption: command.caption,
|
|
6506
|
+
captionEnabled: command.caption.trim().length > 0
|
|
6507
|
+
});
|
|
6508
|
+
}
|
|
6388
6509
|
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
|
|
6389
6510
|
}
|
|
6390
6511
|
function checkCell(table, rowIndex, columnIndex) {
|
|
@@ -6529,6 +6650,15 @@ function fieldJson(field) {
|
|
|
6529
6650
|
...serialized.hasPersistedMath ? { math_objects: serialized.mathObjects } : {}
|
|
6530
6651
|
};
|
|
6531
6652
|
}
|
|
6653
|
+
function captionJson(field) {
|
|
6654
|
+
const serialized = serializeField(field);
|
|
6655
|
+
return {
|
|
6656
|
+
caption: serialized.value,
|
|
6657
|
+
caption_inline_ids: serialized.inlineIds,
|
|
6658
|
+
...serialized.formats.length > 0 ? { caption_formats: serialized.formats } : {},
|
|
6659
|
+
...serialized.hasPersistedMath ? { caption_math_objects: serialized.mathObjects } : {}
|
|
6660
|
+
};
|
|
6661
|
+
}
|
|
6532
6662
|
function listItemJson(item) {
|
|
6533
6663
|
const field = fieldJson(item.field);
|
|
6534
6664
|
return {
|
|
@@ -6573,7 +6703,7 @@ function blockJson(block) {
|
|
|
6573
6703
|
...hasPersistedMath ? { math_objects: fields.flatMap((row) => row.flatMap((field) => field.mathObjects)) } : {},
|
|
6574
6704
|
centered: block.centered,
|
|
6575
6705
|
caption_enabled: block.captionEnabled,
|
|
6576
|
-
|
|
6706
|
+
...captionJson(block.captionField),
|
|
6577
6707
|
label_enabled: block.labelEnabled,
|
|
6578
6708
|
label: block.label,
|
|
6579
6709
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -6588,7 +6718,7 @@ function blockJson(block) {
|
|
|
6588
6718
|
options: { ...block.options },
|
|
6589
6719
|
centered: block.centered,
|
|
6590
6720
|
caption_enabled: block.captionEnabled,
|
|
6591
|
-
|
|
6721
|
+
...captionJson(block.captionField),
|
|
6592
6722
|
label_enabled: block.labelEnabled,
|
|
6593
6723
|
label: block.label,
|
|
6594
6724
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -6915,10 +7045,15 @@ function applyBasicCommand(document2, command) {
|
|
|
6915
7045
|
assetId: command.asset_id,
|
|
6916
7046
|
options: { width: "0.8\\columnwidth" },
|
|
6917
7047
|
...defaultFloatMeta(),
|
|
6918
|
-
...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
|
|
6919
7048
|
...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
|
|
6920
7049
|
...command.metadata ? { metadata: { ...command.metadata } } : {}
|
|
6921
7050
|
};
|
|
7051
|
+
if (command.caption !== void 0) {
|
|
7052
|
+
applyFloatMetaPatch(block, {
|
|
7053
|
+
caption: command.caption,
|
|
7054
|
+
captionEnabled: command.caption.trim().length > 0
|
|
7055
|
+
});
|
|
7056
|
+
}
|
|
6922
7057
|
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
|
|
6923
7058
|
}
|
|
6924
7059
|
function applyDocument2Command(json, commandInput) {
|
|
@@ -6938,6 +7073,104 @@ function applyDocument2Command(json, commandInput) {
|
|
|
6938
7073
|
return toDocumentJson2(document2);
|
|
6939
7074
|
}
|
|
6940
7075
|
|
|
7076
|
+
// src/document2/diff.ts
|
|
7077
|
+
import { diffJson } from "diff";
|
|
7078
|
+
var MAX_TOTAL_TEXT_CHARS = 16e3;
|
|
7079
|
+
var MAX_CHANGED_CHUNK_CHARS = 4e3;
|
|
7080
|
+
var MAX_CONTEXT_CHUNK_CHARS = 600;
|
|
7081
|
+
var TRUNCATION_MARKER = "\n\u2026\n";
|
|
7082
|
+
var IDENTITY_KEYS = /* @__PURE__ */ new Set(["id", "inline_ids", "caption_inline_ids", "cell_inline_ids"]);
|
|
7083
|
+
function comparisonValue(value, key) {
|
|
7084
|
+
if (key && IDENTITY_KEYS.has(key)) {
|
|
7085
|
+
return void 0;
|
|
7086
|
+
}
|
|
7087
|
+
if (Array.isArray(value)) {
|
|
7088
|
+
return value.map((entry) => comparisonValue(entry));
|
|
7089
|
+
}
|
|
7090
|
+
if (value && typeof value === "object") {
|
|
7091
|
+
const result = {};
|
|
7092
|
+
for (const childKey of Object.keys(value).sort()) {
|
|
7093
|
+
const child = comparisonValue(value[childKey], childKey);
|
|
7094
|
+
if (child !== void 0) {
|
|
7095
|
+
result[childKey] = child;
|
|
7096
|
+
}
|
|
7097
|
+
}
|
|
7098
|
+
return result;
|
|
7099
|
+
}
|
|
7100
|
+
return value;
|
|
7101
|
+
}
|
|
7102
|
+
function normalizedComparisonDocument(document2) {
|
|
7103
|
+
return comparisonValue(toDocumentJson2(fromDocumentJson2(document2)));
|
|
7104
|
+
}
|
|
7105
|
+
function withoutFinalNewline(value) {
|
|
7106
|
+
return value.endsWith("\n") ? value.slice(0, -1) : value;
|
|
7107
|
+
}
|
|
7108
|
+
function shorten(text, limit, mode) {
|
|
7109
|
+
if (text.length <= limit) {
|
|
7110
|
+
return { text, truncated: false };
|
|
7111
|
+
}
|
|
7112
|
+
if (limit <= TRUNCATION_MARKER.length) {
|
|
7113
|
+
return { text: text.slice(0, Math.max(0, limit)), truncated: true };
|
|
7114
|
+
}
|
|
7115
|
+
const available = limit - TRUNCATION_MARKER.length;
|
|
7116
|
+
if (mode === "head") {
|
|
7117
|
+
return { text: `${text.slice(0, available)}${TRUNCATION_MARKER}`, truncated: true };
|
|
7118
|
+
}
|
|
7119
|
+
if (mode === "tail") {
|
|
7120
|
+
return { text: `${TRUNCATION_MARKER}${text.slice(text.length - available)}`, truncated: true };
|
|
7121
|
+
}
|
|
7122
|
+
const head = Math.ceil(available / 2);
|
|
7123
|
+
const tail = available - head;
|
|
7124
|
+
return {
|
|
7125
|
+
text: `${text.slice(0, head)}${TRUNCATION_MARKER}${text.slice(text.length - tail)}`,
|
|
7126
|
+
truncated: true
|
|
7127
|
+
};
|
|
7128
|
+
}
|
|
7129
|
+
function diffDocument2(before, after) {
|
|
7130
|
+
const beforeComparable = normalizedComparisonDocument(before);
|
|
7131
|
+
const afterComparable = normalizedComparisonDocument(after);
|
|
7132
|
+
const parts = diffJson(beforeComparable, afterComparable);
|
|
7133
|
+
const changed = parts.some((part) => part.added === true || part.removed === true);
|
|
7134
|
+
if (!changed) {
|
|
7135
|
+
return { version: 1, changed: false, truncated: false, chunks: [] };
|
|
7136
|
+
}
|
|
7137
|
+
const chunks = [];
|
|
7138
|
+
let truncated = false;
|
|
7139
|
+
let totalTextChars = 0;
|
|
7140
|
+
const append = (kind, rawText, limit, mode) => {
|
|
7141
|
+
const cleaned = withoutFinalNewline(rawText);
|
|
7142
|
+
if (cleaned.length === 0) return;
|
|
7143
|
+
const perChunk = shorten(cleaned, limit, mode);
|
|
7144
|
+
truncated ||= perChunk.truncated;
|
|
7145
|
+
const remaining = MAX_TOTAL_TEXT_CHARS - totalTextChars;
|
|
7146
|
+
if (remaining <= 0) {
|
|
7147
|
+
truncated = true;
|
|
7148
|
+
return;
|
|
7149
|
+
}
|
|
7150
|
+
const withinBudget = shorten(perChunk.text, remaining, mode);
|
|
7151
|
+
truncated ||= withinBudget.truncated;
|
|
7152
|
+
if (withinBudget.text.length === 0) return;
|
|
7153
|
+
chunks.push({ kind, text: withinBudget.text });
|
|
7154
|
+
totalTextChars += withinBudget.text.length;
|
|
7155
|
+
};
|
|
7156
|
+
parts.forEach((part, index) => {
|
|
7157
|
+
if (part.added) {
|
|
7158
|
+
append("added", part.value, MAX_CHANGED_CHUNK_CHARS, "both");
|
|
7159
|
+
return;
|
|
7160
|
+
}
|
|
7161
|
+
if (part.removed) {
|
|
7162
|
+
append("removed", part.value, MAX_CHANGED_CHUNK_CHARS, "both");
|
|
7163
|
+
return;
|
|
7164
|
+
}
|
|
7165
|
+
const previousChanged = index > 0 && (parts[index - 1]?.added === true || parts[index - 1]?.removed === true);
|
|
7166
|
+
const nextChanged = index + 1 < parts.length && (parts[index + 1]?.added === true || parts[index + 1]?.removed === true);
|
|
7167
|
+
if (!previousChanged && !nextChanged) return;
|
|
7168
|
+
const mode = previousChanged && nextChanged ? "both" : previousChanged ? "head" : "tail";
|
|
7169
|
+
append("context", part.value, MAX_CONTEXT_CHUNK_CHARS, mode);
|
|
7170
|
+
});
|
|
7171
|
+
return { version: 1, changed: true, truncated, chunks };
|
|
7172
|
+
}
|
|
7173
|
+
|
|
6941
7174
|
// src/document2/outline.ts
|
|
6942
7175
|
var EXCERPT_LIMIT = 160;
|
|
6943
7176
|
function normalizeExcerpt(value) {
|
|
@@ -7012,6 +7245,119 @@ function document2Outline(json) {
|
|
|
7012
7245
|
});
|
|
7013
7246
|
}
|
|
7014
7247
|
|
|
7248
|
+
// src/document2/introspection.ts
|
|
7249
|
+
function appendUnique(target, seen, values) {
|
|
7250
|
+
for (const value of values) {
|
|
7251
|
+
if (!seen.has(value)) {
|
|
7252
|
+
seen.add(value);
|
|
7253
|
+
target.push(value);
|
|
7254
|
+
}
|
|
7255
|
+
}
|
|
7256
|
+
}
|
|
7257
|
+
function getDocument2References(document2) {
|
|
7258
|
+
return document2.references.map((reference) => ({
|
|
7259
|
+
key: reference.key,
|
|
7260
|
+
authors: reference.authors,
|
|
7261
|
+
title: reference.title,
|
|
7262
|
+
year: reference.year,
|
|
7263
|
+
venue: reference.venue,
|
|
7264
|
+
url: reference.url,
|
|
7265
|
+
field_separator: reference.fieldSeparator
|
|
7266
|
+
}));
|
|
7267
|
+
}
|
|
7268
|
+
function getDocument2ReferenceIndex(document2) {
|
|
7269
|
+
const referenceKeys = new Set(document2.references.map((reference) => reference.key));
|
|
7270
|
+
const labelEntries = collectDocument2Labels(document2);
|
|
7271
|
+
const labelKeys = new Set(labelEntries.map((entry) => entry.key));
|
|
7272
|
+
const citations = [];
|
|
7273
|
+
const crossReferences = [];
|
|
7274
|
+
const tokenLocations = /* @__PURE__ */ new Map();
|
|
7275
|
+
const unresolvedCitationKeys = [];
|
|
7276
|
+
const unresolvedCrossReferenceKeys = [];
|
|
7277
|
+
const seenCitationKeys = /* @__PURE__ */ new Set();
|
|
7278
|
+
const seenCrossReferenceKeys = /* @__PURE__ */ new Set();
|
|
7279
|
+
function visitField(blockId, field) {
|
|
7280
|
+
for (const token of field.tokens) {
|
|
7281
|
+
tokenLocations.set(token.id, { block_id: blockId, field_id: field.id });
|
|
7282
|
+
if (token.kind === "cite") {
|
|
7283
|
+
const unresolvedKeys = token.keys.filter((key) => !referenceKeys.has(key));
|
|
7284
|
+
citations.push({
|
|
7285
|
+
kind: "cite",
|
|
7286
|
+
block_id: blockId,
|
|
7287
|
+
field_id: field.id,
|
|
7288
|
+
token_id: token.id,
|
|
7289
|
+
keys: [...token.keys],
|
|
7290
|
+
unresolved_keys: unresolvedKeys
|
|
7291
|
+
});
|
|
7292
|
+
appendUnique(unresolvedCitationKeys, seenCitationKeys, unresolvedKeys);
|
|
7293
|
+
} else if (token.kind === "ref") {
|
|
7294
|
+
const unresolvedKeys = token.keys.filter((key) => !labelKeys.has(key));
|
|
7295
|
+
crossReferences.push({
|
|
7296
|
+
kind: "ref",
|
|
7297
|
+
ref_command: token.refCommand,
|
|
7298
|
+
block_id: blockId,
|
|
7299
|
+
field_id: field.id,
|
|
7300
|
+
token_id: token.id,
|
|
7301
|
+
keys: [...token.keys],
|
|
7302
|
+
unresolved_keys: unresolvedKeys
|
|
7303
|
+
});
|
|
7304
|
+
appendUnique(unresolvedCrossReferenceKeys, seenCrossReferenceKeys, unresolvedKeys);
|
|
7305
|
+
}
|
|
7306
|
+
}
|
|
7307
|
+
}
|
|
7308
|
+
function visitBlocks(blocks) {
|
|
7309
|
+
for (const block of blocks) {
|
|
7310
|
+
if (block.kind === "textBlock") {
|
|
7311
|
+
visitField(block.id, block.field);
|
|
7312
|
+
} else if (block.kind === "table") {
|
|
7313
|
+
visitField(block.id, block.captionField);
|
|
7314
|
+
for (const row of block.rows) {
|
|
7315
|
+
for (const cell of row) {
|
|
7316
|
+
visitField(block.id, cell);
|
|
7317
|
+
}
|
|
7318
|
+
}
|
|
7319
|
+
} else if (block.kind === "image") {
|
|
7320
|
+
visitField(block.id, block.captionField);
|
|
7321
|
+
} else if (block.kind === "list") {
|
|
7322
|
+
for (const item of block.items) {
|
|
7323
|
+
visitField(block.id, item.field);
|
|
7324
|
+
visitBlocks(item.blocks);
|
|
7325
|
+
}
|
|
7326
|
+
}
|
|
7327
|
+
}
|
|
7328
|
+
}
|
|
7329
|
+
visitBlocks(document2.blocks);
|
|
7330
|
+
const labels = labelEntries.map((entry) => {
|
|
7331
|
+
if (entry.kind !== "eq") {
|
|
7332
|
+
return {
|
|
7333
|
+
key: entry.key,
|
|
7334
|
+
kind: entry.kind,
|
|
7335
|
+
caption: entry.caption,
|
|
7336
|
+
number: entry.number,
|
|
7337
|
+
block_id: entry.ownerId
|
|
7338
|
+
};
|
|
7339
|
+
}
|
|
7340
|
+
const location = tokenLocations.get(entry.ownerId);
|
|
7341
|
+
return {
|
|
7342
|
+
key: entry.key,
|
|
7343
|
+
kind: entry.kind,
|
|
7344
|
+
caption: entry.caption,
|
|
7345
|
+
number: entry.number,
|
|
7346
|
+
...location ? { block_id: location.block_id, field_id: location.field_id } : {},
|
|
7347
|
+
token_id: entry.ownerId
|
|
7348
|
+
};
|
|
7349
|
+
});
|
|
7350
|
+
return {
|
|
7351
|
+
citations,
|
|
7352
|
+
cross_references: crossReferences,
|
|
7353
|
+
labels,
|
|
7354
|
+
unresolved: {
|
|
7355
|
+
citation_keys: unresolvedCitationKeys,
|
|
7356
|
+
cross_reference_keys: unresolvedCrossReferenceKeys
|
|
7357
|
+
}
|
|
7358
|
+
};
|
|
7359
|
+
}
|
|
7360
|
+
|
|
7015
7361
|
// src/document2/arabicPreamble.ts
|
|
7016
7362
|
function fontOptions(digitsMapping, includeScript = true) {
|
|
7017
7363
|
const parts = [];
|
|
@@ -7382,11 +7728,12 @@ ${block.closing}`;
|
|
|
7382
7728
|
${rows.join(" \\\\\n")}
|
|
7383
7729
|
${block.closing}`;
|
|
7384
7730
|
}
|
|
7385
|
-
function floatCaptionLabelLines(block, counter) {
|
|
7731
|
+
function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
7386
7732
|
const lines = [];
|
|
7387
|
-
const
|
|
7733
|
+
const caption = inlineFieldLatexWithLabelKinds(block.captionField, labelKinds).trim();
|
|
7734
|
+
const hasCaption = block.captionEnabled && caption.length > 0;
|
|
7388
7735
|
if (hasCaption) {
|
|
7389
|
-
lines.push(` \\caption{${
|
|
7736
|
+
lines.push(` \\caption{${caption}}`);
|
|
7390
7737
|
}
|
|
7391
7738
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
7392
7739
|
if (!hasCaption) {
|
|
@@ -7402,7 +7749,7 @@ function tableBlockLatex(block, labelKinds, fixedFloats) {
|
|
|
7402
7749
|
if (block.centered) {
|
|
7403
7750
|
lines.push(" \\centering");
|
|
7404
7751
|
}
|
|
7405
|
-
lines.push(...floatCaptionLabelLines(block, "table"));
|
|
7752
|
+
lines.push(...floatCaptionLabelLines(block, "table", labelKinds));
|
|
7406
7753
|
lines.push(indent(tabularInnerLatex(block, labelKinds)));
|
|
7407
7754
|
lines.push("\\end{table}");
|
|
7408
7755
|
return lines.join("\n");
|
|
@@ -7422,14 +7769,14 @@ function imageOptionsLatex(block, constrainToColumn) {
|
|
|
7422
7769
|
}
|
|
7423
7770
|
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
7424
7771
|
}
|
|
7425
|
-
function imageBlockLatex(block, fixedFloats) {
|
|
7772
|
+
function imageBlockLatex(block, labelKinds, fixedFloats) {
|
|
7426
7773
|
const placement = fixedFloats ? "H" : "htbp";
|
|
7427
7774
|
const lines = [`\\begin{figure}[${placement}]`];
|
|
7428
7775
|
if (block.centered) {
|
|
7429
7776
|
lines.push(" \\centering");
|
|
7430
7777
|
}
|
|
7431
7778
|
lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
|
|
7432
|
-
lines.push(...floatCaptionLabelLines(block, "figure"));
|
|
7779
|
+
lines.push(...floatCaptionLabelLines(block, "figure", labelKinds));
|
|
7433
7780
|
lines.push("\\end{figure}");
|
|
7434
7781
|
return lines.join("\n");
|
|
7435
7782
|
}
|
|
@@ -7444,7 +7791,7 @@ function blockLatex(block, references, labelKinds, fixedFloats) {
|
|
|
7444
7791
|
return tableBlockLatex(block, labelKinds, fixedFloats);
|
|
7445
7792
|
}
|
|
7446
7793
|
if (block.kind === "image") {
|
|
7447
|
-
return imageBlockLatex(block, fixedFloats);
|
|
7794
|
+
return imageBlockLatex(block, labelKinds, fixedFloats);
|
|
7448
7795
|
}
|
|
7449
7796
|
if (block.kind === "bibliography") {
|
|
7450
7797
|
const width = String(Math.max(references.length, 9));
|
|
@@ -7637,7 +7984,7 @@ function validateBlock(context, block, path) {
|
|
|
7637
7984
|
);
|
|
7638
7985
|
});
|
|
7639
7986
|
});
|
|
7640
|
-
|
|
7987
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
7641
7988
|
if (block.labelEnabled) {
|
|
7642
7989
|
registerKey(context, block.label, `${path}.label`, "tab", block.id);
|
|
7643
7990
|
}
|
|
@@ -7650,7 +7997,7 @@ function validateBlock(context, block, path) {
|
|
|
7650
7997
|
addIssue(context, "empty_image", path, block.id);
|
|
7651
7998
|
}
|
|
7652
7999
|
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
7653
|
-
|
|
8000
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
7654
8001
|
if (block.labelEnabled) {
|
|
7655
8002
|
registerKey(context, block.label, `${path}.label`, "fig", block.id);
|
|
7656
8003
|
}
|
|
@@ -7983,6 +8330,15 @@ function floatNumberLabel(document2, key, previewOptions) {
|
|
|
7983
8330
|
digitForm: previewOptions.digitForm
|
|
7984
8331
|
});
|
|
7985
8332
|
}
|
|
8333
|
+
function captionPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
8334
|
+
if (!block.captionEnabled || block.caption.trim().length === 0) {
|
|
8335
|
+
return {};
|
|
8336
|
+
}
|
|
8337
|
+
return {
|
|
8338
|
+
caption: block.caption.trim(),
|
|
8339
|
+
captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
|
|
8340
|
+
};
|
|
8341
|
+
}
|
|
7986
8342
|
function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
7987
8343
|
if (block.kind === "textBlock") {
|
|
7988
8344
|
return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
|
|
@@ -8006,7 +8362,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
8006
8362
|
kind: "table",
|
|
8007
8363
|
id: block.id,
|
|
8008
8364
|
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
|
|
8009
|
-
...block
|
|
8365
|
+
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
8010
8366
|
...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
|
|
8011
8367
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
8012
8368
|
};
|
|
@@ -8020,7 +8376,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
8020
8376
|
...block.assetId !== void 0 ? { assetId: block.assetId } : {},
|
|
8021
8377
|
options: block.options,
|
|
8022
8378
|
centered: block.centered,
|
|
8023
|
-
...block
|
|
8379
|
+
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
8024
8380
|
...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
|
|
8025
8381
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
8026
8382
|
};
|
|
@@ -8146,6 +8502,7 @@ export {
|
|
|
8146
8502
|
defaultFloatMeta,
|
|
8147
8503
|
detectInlineSpans2,
|
|
8148
8504
|
detectMathSpans2,
|
|
8505
|
+
diffDocument2,
|
|
8149
8506
|
document2HasAbstract,
|
|
8150
8507
|
document2HasMaketitle,
|
|
8151
8508
|
document2HasTitleStack,
|
|
@@ -8169,6 +8526,8 @@ export {
|
|
|
8169
8526
|
formatRefLabel,
|
|
8170
8527
|
fromDocumentJson2,
|
|
8171
8528
|
getArabicXeLatexPreamble,
|
|
8529
|
+
getDocument2ReferenceIndex,
|
|
8530
|
+
getDocument2References,
|
|
8172
8531
|
hasXeLatexUnsupportedEmoji,
|
|
8173
8532
|
hijriMonthLabel,
|
|
8174
8533
|
inlineFieldLatex,
|