@drghaliasri/butex 8.0.2 → 8.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/README.md +7 -7
- package/dist/document-cli.js +231 -88
- package/dist/document-cli.js.map +1 -1
- package/dist/document.d.mts +35 -2
- package/dist/document.d.ts +35 -2
- package/dist/document.js +187 -100
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +182 -100
- package/dist/document.mjs.map +1 -1
- package/dist/react-document-preview.d.mts +4 -0
- package/dist/react-document-preview.d.ts +4 -0
- package/dist/react-document-preview.js +78 -71
- package/dist/react-document-preview.js.map +1 -1
- package/dist/react-document-preview.mjs +78 -71
- package/dist/react-document-preview.mjs.map +1 -1
- package/dist/react-document.d.mts +8 -1
- package/dist/react-document.d.ts +8 -1
- package/dist/react-document.js +177 -115
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +177 -115
- package/dist/react-document.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react-document.js
CHANGED
|
@@ -875,82 +875,79 @@ function refTokenLatex(keys, refCommand) {
|
|
|
875
875
|
const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
|
|
876
876
|
return `${command}{${keys.join(",")}}`;
|
|
877
877
|
}
|
|
878
|
-
function
|
|
879
|
-
const
|
|
878
|
+
function implicitReferenceKey(kind, ownerId, unitId) {
|
|
879
|
+
const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
880
|
+
const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
|
|
881
|
+
return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
|
|
882
|
+
}
|
|
883
|
+
function supportsSingleEquationNumbering(token) {
|
|
884
|
+
return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
|
|
885
|
+
}
|
|
886
|
+
function isNumberedEquation(token) {
|
|
887
|
+
if (!supportsSingleEquationNumbering(token)) return false;
|
|
888
|
+
if (typeof token.numbered === "boolean") return token.numbered;
|
|
889
|
+
return token.opening === "\\begin{equation}" || Boolean(token.labelEnabled) && Boolean(token.label?.trim());
|
|
890
|
+
}
|
|
891
|
+
function isNumberedFloat(block) {
|
|
892
|
+
return block.captionEnabled && block.caption.trim().length > 0 || block.labelEnabled && block.label.trim().length > 0;
|
|
893
|
+
}
|
|
894
|
+
function collectDocumentReferenceTargets(document2) {
|
|
895
|
+
const targets = [];
|
|
880
896
|
const counters = { fig: 0, tab: 0, eq: 0 };
|
|
881
|
-
function
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
897
|
+
function append(kind, ownerId, caption, numbered, manualKey = "") {
|
|
898
|
+
if (numbered) counters[kind] += 1;
|
|
899
|
+
targets.push({
|
|
900
|
+
key: implicitReferenceKey(kind, ownerId),
|
|
901
|
+
kind,
|
|
902
|
+
ownerId,
|
|
903
|
+
caption,
|
|
904
|
+
number: numbered ? counters[kind] : null,
|
|
905
|
+
...manualKey.trim() ? { manualKey: manualKey.trim() } : {}
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
function visitField(field) {
|
|
909
|
+
for (const token of field.tokens) {
|
|
910
|
+
if (token.kind === "math" && supportsSingleEquationNumbering(token)) {
|
|
911
|
+
append("eq", token.id, "", isNumberedEquation(token), token.labelEnabled ? token.label ?? "" : "");
|
|
895
912
|
}
|
|
896
913
|
}
|
|
897
914
|
}
|
|
898
915
|
function walk(blocks) {
|
|
899
916
|
for (const block of blocks) {
|
|
900
|
-
if (block.kind === "image") {
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
if (block.captionEnabled) {
|
|
912
|
-
pushEqFromField(block.captionField.tokens);
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
if (block.kind === "table") {
|
|
916
|
-
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
917
|
-
counters.tab += 1;
|
|
918
|
-
entries.push({
|
|
919
|
-
key: block.label.trim(),
|
|
920
|
-
kind: "tab",
|
|
921
|
-
caption: block.captionEnabled ? block.caption : "",
|
|
922
|
-
ownerId: block.id,
|
|
923
|
-
number: counters.tab
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
if (block.captionEnabled) {
|
|
927
|
-
pushEqFromField(block.captionField.tokens);
|
|
928
|
-
}
|
|
929
|
-
for (const row of block.rows) {
|
|
930
|
-
for (const cell of row) {
|
|
931
|
-
pushEqFromField(cell.tokens);
|
|
932
|
-
}
|
|
917
|
+
if (block.kind === "image" || block.kind === "table") {
|
|
918
|
+
append(
|
|
919
|
+
block.kind === "image" ? "fig" : "tab",
|
|
920
|
+
block.id,
|
|
921
|
+
block.captionEnabled ? block.caption : "",
|
|
922
|
+
isNumberedFloat(block),
|
|
923
|
+
block.labelEnabled ? block.label : ""
|
|
924
|
+
);
|
|
925
|
+
if (block.captionEnabled) visitField(block.captionField);
|
|
926
|
+
if (block.kind === "table") {
|
|
927
|
+
for (const row of block.rows) for (const cell of row) visitField(cell);
|
|
933
928
|
}
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
}
|
|
938
|
-
if (block.kind === "list") {
|
|
929
|
+
} else if (block.kind === "textBlock") {
|
|
930
|
+
visitField(block.field);
|
|
931
|
+
} else if (block.kind === "list") {
|
|
939
932
|
for (const item of block.items) {
|
|
940
|
-
|
|
933
|
+
visitField(item.field);
|
|
941
934
|
walk(item.blocks);
|
|
942
935
|
}
|
|
943
936
|
}
|
|
944
937
|
}
|
|
945
938
|
}
|
|
946
939
|
walk(document2.blocks);
|
|
947
|
-
return
|
|
940
|
+
return targets;
|
|
941
|
+
}
|
|
942
|
+
function collectDocumentLabels(document2) {
|
|
943
|
+
return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null && Boolean(target.manualKey)).map(({ manualKey, kind, caption, ownerId, number }) => ({ key: manualKey, kind, caption, ownerId, number }));
|
|
948
944
|
}
|
|
949
945
|
function labelNumberMap(document2) {
|
|
950
946
|
const map = /* @__PURE__ */ new Map();
|
|
951
|
-
for (const
|
|
952
|
-
if (
|
|
953
|
-
|
|
947
|
+
for (const target of collectDocumentReferenceTargets(document2)) {
|
|
948
|
+
if (target.number === null) continue;
|
|
949
|
+
for (const key of [target.key, target.manualKey]) {
|
|
950
|
+
if (key && !map.has(key)) map.set(key, { kind: target.kind, number: target.number });
|
|
954
951
|
}
|
|
955
952
|
}
|
|
956
953
|
return map;
|
|
@@ -1004,8 +1001,12 @@ function stripDisplayMathDelimiters(source) {
|
|
|
1004
1001
|
if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) {
|
|
1005
1002
|
return trimmed.slice(2, -2).trim();
|
|
1006
1003
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1004
|
+
for (const environment of ["equation", "equation*"]) {
|
|
1005
|
+
const opening = `\\begin{${environment}}`;
|
|
1006
|
+
const closing = `\\end{${environment}}`;
|
|
1007
|
+
if (trimmed.startsWith(opening) && trimmed.endsWith(closing)) {
|
|
1008
|
+
return trimmed.slice(opening.length, -closing.length).trim();
|
|
1009
|
+
}
|
|
1009
1010
|
}
|
|
1010
1011
|
return trimmed;
|
|
1011
1012
|
}
|
|
@@ -1398,7 +1399,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1398
1399
|
editable: true,
|
|
1399
1400
|
sourceOwner: structuredMathJson.source_owner === "editor" ? "editor" : "imported-structured",
|
|
1400
1401
|
...typeof structuredMathJson.label_enabled === "boolean" ? { labelEnabled: structuredMathJson.label_enabled } : {},
|
|
1401
|
-
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {}
|
|
1402
|
+
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {},
|
|
1403
|
+
...typeof structuredMathJson.numbered === "boolean" ? { numbered: structuredMathJson.numbered } : {}
|
|
1402
1404
|
});
|
|
1403
1405
|
} else {
|
|
1404
1406
|
tokens.push({
|
|
@@ -1413,7 +1415,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1413
1415
|
reason: "\u0647\u0630\u0647 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u0645\u062D\u0641\u0648\u0638\u0629 \u0643\u0646\u0635 \u062E\u0627\u0645 \u0641\u0642\u0637 \u062D\u0627\u0644\u064A\u0627",
|
|
1414
1416
|
sourceOwner: "raw",
|
|
1415
1417
|
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label_enabled === "boolean" ? { labelEnabled: mathJson.label_enabled } : {},
|
|
1416
|
-
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {}
|
|
1418
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {},
|
|
1419
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.numbered === "boolean" ? { numbered: mathJson.numbered } : {}
|
|
1417
1420
|
});
|
|
1418
1421
|
}
|
|
1419
1422
|
index = span.end;
|
|
@@ -9489,6 +9492,9 @@ function replaceMathTokenFromSession(document2, tokenId, session, opening, closi
|
|
|
9489
9492
|
if (current.label !== void 0) {
|
|
9490
9493
|
replaced.label = current.label;
|
|
9491
9494
|
}
|
|
9495
|
+
if (current.numbered !== void 0) {
|
|
9496
|
+
replaced.numbered = current.numbered;
|
|
9497
|
+
}
|
|
9492
9498
|
field.tokens[index] = replaced;
|
|
9493
9499
|
return true;
|
|
9494
9500
|
});
|
|
@@ -9708,6 +9714,9 @@ function updateMathTokenLabel(document2, tokenId, patch) {
|
|
|
9708
9714
|
if (typeof patch.label === "string") {
|
|
9709
9715
|
token.label = patch.label;
|
|
9710
9716
|
}
|
|
9717
|
+
if (typeof patch.numbered === "boolean") {
|
|
9718
|
+
token.numbered = patch.numbered;
|
|
9719
|
+
}
|
|
9711
9720
|
return true;
|
|
9712
9721
|
});
|
|
9713
9722
|
return next;
|
|
@@ -10025,12 +10034,13 @@ function serializeField(field) {
|
|
|
10025
10034
|
}
|
|
10026
10035
|
value += token.source;
|
|
10027
10036
|
if (!token.math || token.sourceOwner === "raw") {
|
|
10028
|
-
if (token.labelEnabled !== void 0 || token.label !== void 0) {
|
|
10037
|
+
if (token.labelEnabled !== void 0 || token.label !== void 0 || token.numbered !== void 0) {
|
|
10029
10038
|
hasPersistedMath = true;
|
|
10030
10039
|
mathObjects.push({
|
|
10031
10040
|
node_type: "RawMathObject",
|
|
10032
10041
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
10033
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
10042
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
10043
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
10034
10044
|
});
|
|
10035
10045
|
} else {
|
|
10036
10046
|
mathObjects.push(null);
|
|
@@ -10043,7 +10053,8 @@ function serializeField(field) {
|
|
|
10043
10053
|
...token.sourceSide ? { source_side: token.sourceSide } : {},
|
|
10044
10054
|
source_owner: token.sourceOwner,
|
|
10045
10055
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
10046
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
10056
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
10057
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
10047
10058
|
});
|
|
10048
10059
|
}
|
|
10049
10060
|
return { value, formats, mathObjects, hasPersistedMath, inlineIds: inlineIdsFromField(field) };
|
|
@@ -10411,9 +10422,13 @@ function digitsMappingFromDigitForm(digitForm) {
|
|
|
10411
10422
|
}
|
|
10412
10423
|
return "arabicdigits";
|
|
10413
10424
|
}
|
|
10425
|
+
function editorMathLatexForCompile(token) {
|
|
10426
|
+
const source = token.math && token.sourceSide === "arabic" && token.source.includes("\\begin{cases}") ? mathTokenSourceForSide(token, "arabic", void 0, true) : token.source;
|
|
10427
|
+
return mirrorBuTeXOperatorsInTex(source, { target: "compile" });
|
|
10428
|
+
}
|
|
10414
10429
|
function mathBodyLatex(token) {
|
|
10415
10430
|
if (token.sourceOwner === "editor") {
|
|
10416
|
-
return stripDisplayMathDelimiters(
|
|
10431
|
+
return stripDisplayMathDelimiters(editorMathLatexForCompile(token));
|
|
10417
10432
|
}
|
|
10418
10433
|
if (!token.math || token.sourceOwner === "raw") {
|
|
10419
10434
|
return stripDisplayMathDelimiters(token.source);
|
|
@@ -10480,15 +10495,18 @@ function tokenLatex(token, labelKinds, previousToken) {
|
|
|
10480
10495
|
if (token.kind === "ref") {
|
|
10481
10496
|
return refTokenLatexForDocument(token, labelKinds, previousToken);
|
|
10482
10497
|
}
|
|
10483
|
-
if (token
|
|
10498
|
+
if (isNumberedEquation(token)) {
|
|
10484
10499
|
const body = mathBodyLatex(token);
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
\\end{equation}
|
|
10500
|
+
const autoKey = implicitReferenceKey("eq", token.id);
|
|
10501
|
+
const aliases = [autoKey];
|
|
10502
|
+
if (token.labelEnabled && token.label?.trim() && token.label.trim() !== autoKey) aliases.push(token.label.trim());
|
|
10503
|
+
return "\\begin{equation}\n" + body + "\n" + aliases.map((key) => "\\label{" + key + "}").join("\n") + "\n\\end{equation}";
|
|
10504
|
+
}
|
|
10505
|
+
if (token.display && token.numbered === false && token.opening === "\\begin{equation}") {
|
|
10506
|
+
return "\\[" + mathBodyLatex(token) + "\\]";
|
|
10489
10507
|
}
|
|
10490
10508
|
if (token.sourceOwner === "editor") {
|
|
10491
|
-
return
|
|
10509
|
+
return editorMathLatexForCompile(token);
|
|
10492
10510
|
}
|
|
10493
10511
|
if (!token.math || token.sourceOwner === "raw") {
|
|
10494
10512
|
return token.source;
|
|
@@ -10552,11 +10570,12 @@ function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
|
10552
10570
|
if (hasCaption) {
|
|
10553
10571
|
lines.push(` \\caption{${caption}}`);
|
|
10554
10572
|
}
|
|
10555
|
-
|
|
10556
|
-
|
|
10557
|
-
|
|
10558
|
-
|
|
10559
|
-
lines.push(
|
|
10573
|
+
const hasManualLabel = block.labelEnabled && block.label.trim().length > 0;
|
|
10574
|
+
if (hasCaption || hasManualLabel) {
|
|
10575
|
+
if (!hasCaption) lines.push(" \\refstepcounter{" + counter + "}");
|
|
10576
|
+
const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id);
|
|
10577
|
+
lines.push(" \\label{" + autoKey + "}");
|
|
10578
|
+
if (hasManualLabel && block.label.trim() !== autoKey) lines.push(" \\label{" + block.label.trim() + "}");
|
|
10560
10579
|
}
|
|
10561
10580
|
return lines;
|
|
10562
10581
|
}
|
|
@@ -10652,10 +10671,8 @@ ${meta.abstract.trim()}
|
|
|
10652
10671
|
}
|
|
10653
10672
|
function documentLabelKindMap(document2) {
|
|
10654
10673
|
const map = /* @__PURE__ */ new Map();
|
|
10655
|
-
for (const entry of
|
|
10656
|
-
|
|
10657
|
-
map.set(entry.key, entry.kind);
|
|
10658
|
-
}
|
|
10674
|
+
for (const [key, entry] of labelNumberMap(document2)) {
|
|
10675
|
+
map.set(key, entry.kind);
|
|
10659
10676
|
}
|
|
10660
10677
|
return map;
|
|
10661
10678
|
}
|
|
@@ -10754,10 +10771,17 @@ function validateToken(context, token, path, blockId) {
|
|
|
10754
10771
|
return;
|
|
10755
10772
|
}
|
|
10756
10773
|
validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
|
|
10774
|
+
if (token.numbered === true && !supportsSingleEquationNumbering(token)) {
|
|
10775
|
+
addIssue(context, "invalid_equation_label", `${path}.numbered`, blockId, token.id);
|
|
10776
|
+
}
|
|
10757
10777
|
if (!token.labelEnabled) {
|
|
10758
10778
|
return;
|
|
10759
10779
|
}
|
|
10760
|
-
if (!token
|
|
10780
|
+
if (!supportsSingleEquationNumbering(token)) {
|
|
10781
|
+
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
10782
|
+
return;
|
|
10783
|
+
}
|
|
10784
|
+
if (!isNumberedEquation(token)) {
|
|
10761
10785
|
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
10762
10786
|
return;
|
|
10763
10787
|
}
|
|
@@ -10855,7 +10879,7 @@ function validatePendingReferences(context) {
|
|
|
10855
10879
|
for (const pending of context.pendingReferences) {
|
|
10856
10880
|
for (const key of pending.token.keys) {
|
|
10857
10881
|
const normalized = normalizeDocumentKey(key);
|
|
10858
|
-
if (!isValidDocumentKey(normalized)) {
|
|
10882
|
+
if (!isValidDocumentKey(normalized) || !context.labelKinds.has(normalized)) {
|
|
10859
10883
|
addIssue(
|
|
10860
10884
|
context,
|
|
10861
10885
|
"missing_reference",
|
|
@@ -10954,6 +10978,18 @@ function validateDocument(document2) {
|
|
|
10954
10978
|
resolved.blocks.forEach((block, index) => {
|
|
10955
10979
|
validateBlock(context, block, `$.blocks[${String(index)}]`);
|
|
10956
10980
|
});
|
|
10981
|
+
for (const target of collectDocumentReferenceTargets(resolved)) {
|
|
10982
|
+
if (target.number !== null && target.manualKey !== target.key) {
|
|
10983
|
+
registerKey(
|
|
10984
|
+
context,
|
|
10985
|
+
target.key,
|
|
10986
|
+
"$.automatic_labels",
|
|
10987
|
+
target.kind,
|
|
10988
|
+
target.kind === "eq" ? void 0 : target.ownerId,
|
|
10989
|
+
target.kind === "eq" ? target.ownerId : void 0
|
|
10990
|
+
);
|
|
10991
|
+
}
|
|
10992
|
+
}
|
|
10957
10993
|
for (const diagnostic of resolved.diagnostics) {
|
|
10958
10994
|
addIssue(context, "parser_diagnostic", diagnostic.path);
|
|
10959
10995
|
}
|
|
@@ -11094,6 +11130,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
11094
11130
|
})
|
|
11095
11131
|
};
|
|
11096
11132
|
}
|
|
11133
|
+
const number = collectDocumentReferenceTargets(document2).find((target) => target.kind === "eq" && target.ownerId === token.id)?.number;
|
|
11097
11134
|
const island = {
|
|
11098
11135
|
id: token.id,
|
|
11099
11136
|
tex: mathTex(token, equationSide, previewOptions.digitForm),
|
|
@@ -11101,8 +11138,12 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
11101
11138
|
output,
|
|
11102
11139
|
editable: token.editable
|
|
11103
11140
|
};
|
|
11141
|
+
const numberLabel = number == null ? void 0 : formatBibliographyNumber(number, {
|
|
11142
|
+
documentDirection: previewOptions.documentDirection,
|
|
11143
|
+
digitForm: previewOptions.digitForm
|
|
11144
|
+
});
|
|
11104
11145
|
islands.push(island);
|
|
11105
|
-
return { kind: "math", ...island };
|
|
11146
|
+
return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
|
|
11106
11147
|
});
|
|
11107
11148
|
}
|
|
11108
11149
|
function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
@@ -11125,12 +11166,9 @@ function textBlockPreview(block, islands, output, equationSide, document2, previ
|
|
|
11125
11166
|
...block.centered ? { centered: true } : {}
|
|
11126
11167
|
};
|
|
11127
11168
|
}
|
|
11128
|
-
function floatNumberLabel(document2,
|
|
11129
|
-
|
|
11130
|
-
|
|
11131
|
-
}
|
|
11132
|
-
const hit = labelNumberMap(document2).get(key.trim());
|
|
11133
|
-
if (!hit || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
11169
|
+
function floatNumberLabel(document2, ownerId, previewOptions) {
|
|
11170
|
+
const hit = collectDocumentReferenceTargets(document2).find((target) => target.ownerId === ownerId);
|
|
11171
|
+
if (!hit || hit.number === null || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
11134
11172
|
return void 0;
|
|
11135
11173
|
}
|
|
11136
11174
|
return formatFloatCaptionTitle(hit.kind, hit.number, {
|
|
@@ -11172,7 +11210,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
11172
11210
|
id: block.id,
|
|
11173
11211
|
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
|
|
11174
11212
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
11175
|
-
...label.length > 0 ? { label
|
|
11213
|
+
...label.length > 0 ? { label } : {},
|
|
11214
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
11176
11215
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
11177
11216
|
};
|
|
11178
11217
|
}
|
|
@@ -11186,7 +11225,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
11186
11225
|
options: block.options,
|
|
11187
11226
|
centered: block.centered,
|
|
11188
11227
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
11189
|
-
...label.length > 0 ? { label
|
|
11228
|
+
...label.length > 0 ? { label } : {},
|
|
11229
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
11190
11230
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
11191
11231
|
};
|
|
11192
11232
|
}
|
|
@@ -14408,7 +14448,14 @@ function PreviewInlines({ inlines, output }) {
|
|
|
14408
14448
|
if (inline.kind === "ref") {
|
|
14409
14449
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "butex-document-widget__preview-cite butex-document-widget__preview-ref", children: contextualRefLabel(inlines, index, inline.label) }, inline.id);
|
|
14410
14450
|
}
|
|
14411
|
-
return /* @__PURE__ */ (0, import_jsx_runtime12.
|
|
14451
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "butex-document-widget__preview-math-numbered", children: [
|
|
14452
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }),
|
|
14453
|
+
inline.numberLabel ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "butex-document-widget__preview-equation-number", children: [
|
|
14454
|
+
"(",
|
|
14455
|
+
inline.numberLabel,
|
|
14456
|
+
")"
|
|
14457
|
+
] }) : null
|
|
14458
|
+
] }, inline.id);
|
|
14412
14459
|
}) });
|
|
14413
14460
|
}
|
|
14414
14461
|
function isBodyPreviewBlock(block) {
|
|
@@ -18464,6 +18511,8 @@ function EquationDrawer({
|
|
|
18464
18511
|
responsiveMode = "auto",
|
|
18465
18512
|
labelEnabled = false,
|
|
18466
18513
|
label = "",
|
|
18514
|
+
numbered = false,
|
|
18515
|
+
onNumberedChange,
|
|
18467
18516
|
labels = [],
|
|
18468
18517
|
references = [],
|
|
18469
18518
|
ownerId = "",
|
|
@@ -18553,6 +18602,10 @@ function EquationDrawer({
|
|
|
18553
18602
|
] })
|
|
18554
18603
|
] }),
|
|
18555
18604
|
mathMode === "display" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "butex-document-widget__float-meta", children: [
|
|
18605
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "butex-document-widget__float-meta-toggle", children: [
|
|
18606
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("input", { type: "checkbox", checked: numbered, onChange: (event) => onNumberedChange?.(event.currentTarget.checked) }),
|
|
18607
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { children: uiLocale === "ar" ? "\u062A\u0631\u0642\u064A\u0645 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629" : "Number equation" })
|
|
18608
|
+
] }),
|
|
18556
18609
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "butex-document-widget__float-meta-toggle", children: [
|
|
18557
18610
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
18558
18611
|
"input",
|
|
@@ -19076,13 +19129,14 @@ var import_react16 = require("react");
|
|
|
19076
19129
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
19077
19130
|
function RefPickerPopover({
|
|
19078
19131
|
open,
|
|
19079
|
-
|
|
19132
|
+
targets,
|
|
19080
19133
|
initialKeys = [],
|
|
19081
19134
|
initialRefCommand = "ref",
|
|
19082
19135
|
uiLocale = "ar",
|
|
19083
19136
|
digitForm = "arabicIndic",
|
|
19084
19137
|
onClose,
|
|
19085
19138
|
onConfirm,
|
|
19139
|
+
onNumberEquation,
|
|
19086
19140
|
onManageLabels
|
|
19087
19141
|
}) {
|
|
19088
19142
|
const messages = documentMessages(uiLocale);
|
|
@@ -19119,22 +19173,19 @@ function RefPickerPopover({
|
|
|
19119
19173
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("strong", { children: messages.refPickerTitle }),
|
|
19120
19174
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { type: "button", "data-dialog-initial-focus": true, className: "butex-document-widget__icon-btn", title: messages.close, "aria-label": messages.close, onClick: onClose, children: "\xD7" })
|
|
19121
19175
|
] }),
|
|
19122
|
-
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "butex-document-widget__dialog-body", children:
|
|
19123
|
-
const checked = selected.includes(entry.key);
|
|
19124
|
-
const title = formatFloatCaptionTitle(entry.kind, entry.number, {
|
|
19176
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "butex-document-widget__dialog-body", children: targets.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("p", { className: "butex-document-widget__cite-picker-empty", children: messages.noLabelsYet }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("ul", { className: "butex-document-widget__cite-picker-list", children: targets.filter((entry) => entry.number !== null || entry.kind === "eq").map((entry) => {
|
|
19177
|
+
const checked = selected.includes(entry.key) || Boolean(entry.manualKey && selected.includes(entry.manualKey));
|
|
19178
|
+
const title = entry.number === null ? uiLocale === "ar" ? "\u0645\u0639\u0627\u062F\u0644\u0629 \u063A\u064A\u0631 \u0645\u0631\u0642\u0645\u0629" : "Unnumbered equation" : formatFloatCaptionTitle(entry.kind, entry.number, {
|
|
19125
19179
|
uiLocale,
|
|
19126
19180
|
digitForm,
|
|
19127
19181
|
documentDirection
|
|
19128
19182
|
});
|
|
19129
19183
|
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("label", { className: "butex-document-widget__cite-picker-item", children: [
|
|
19130
|
-
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("input", { type: "radio", name: "butex-ref-key", checked, onChange: () => selectKey(entry.key, entry.kind) }),
|
|
19184
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("input", { type: "radio", name: "butex-ref-key", checked, disabled: entry.number === null, onChange: () => selectKey(entry.key, entry.kind) }),
|
|
19131
19185
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("span", { children: [
|
|
19132
|
-
/* @__PURE__ */ (0, import_jsx_runtime18.
|
|
19133
|
-
|
|
19134
|
-
|
|
19135
|
-
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "butex-document-widget__refs-item-key", children: entry.key })
|
|
19136
|
-
] }),
|
|
19137
|
-
entry.caption ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "butex-document-widget__cite-picker-meta", children: entry.caption }) : null
|
|
19186
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("strong", { children: entry.kind === "eq" && entry.number !== null ? title.replace(/(\d+|[٠-٩]+)$/, "($1)") : title }),
|
|
19187
|
+
entry.caption ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "butex-document-widget__cite-picker-meta", children: entry.caption }) : null,
|
|
19188
|
+
entry.kind === "eq" && entry.number === null && onNumberEquation ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { type: "button", onClick: () => onNumberEquation(entry.ownerId), children: uiLocale === "ar" ? "\u0631\u0642\u0651\u0645 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u0623\u0648\u0644\u0627\u064B" : "Number equation first" }) : null
|
|
19138
19189
|
] })
|
|
19139
19190
|
] }) }, `${entry.kind}:${entry.ownerId}`);
|
|
19140
19191
|
}) }) }),
|
|
@@ -21854,6 +21905,7 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
|
|
|
21854
21905
|
const latex = documentLatex(documentNode, { digitForm });
|
|
21855
21906
|
const documentJson = (0, import_react17.useMemo)(() => toDocumentJson(documentNode), [documentNode]);
|
|
21856
21907
|
const documentLabels = (0, import_react17.useMemo)(() => collectDocumentLabels(documentNode), [documentNode]);
|
|
21908
|
+
const referenceTargets = (0, import_react17.useMemo)(() => collectDocumentReferenceTargets(documentNode), [documentNode]);
|
|
21857
21909
|
const preview = (0, import_react17.useMemo)(
|
|
21858
21910
|
() => documentPreview(documentNode, mathOutput, equationSide, {
|
|
21859
21911
|
documentDirection,
|
|
@@ -22189,7 +22241,8 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
|
|
|
22189
22241
|
session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
|
|
22190
22242
|
reason: null,
|
|
22191
22243
|
labelEnabled: false,
|
|
22192
|
-
label: ""
|
|
22244
|
+
label: "",
|
|
22245
|
+
numbered: false
|
|
22193
22246
|
});
|
|
22194
22247
|
}
|
|
22195
22248
|
function openMath(token, origin) {
|
|
@@ -22214,7 +22267,8 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
|
|
|
22214
22267
|
session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
|
|
22215
22268
|
reason: result.reason,
|
|
22216
22269
|
labelEnabled: Boolean(token.labelEnabled),
|
|
22217
|
-
label: token.label ?? ""
|
|
22270
|
+
label: token.label ?? "",
|
|
22271
|
+
numbered: isNumberedEquation(token)
|
|
22218
22272
|
});
|
|
22219
22273
|
return;
|
|
22220
22274
|
}
|
|
@@ -22227,7 +22281,8 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
|
|
|
22227
22281
|
session: equationSessionWithDocumentDigits(result.session),
|
|
22228
22282
|
reason: null,
|
|
22229
22283
|
labelEnabled: Boolean(token.labelEnabled),
|
|
22230
|
-
label: token.label ?? ""
|
|
22284
|
+
label: token.label ?? "",
|
|
22285
|
+
numbered: isNumberedEquation(token)
|
|
22231
22286
|
});
|
|
22232
22287
|
}
|
|
22233
22288
|
function selectMobileView(view) {
|
|
@@ -22318,10 +22373,11 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
|
|
|
22318
22373
|
if (selectedMath.mathMode === "display") {
|
|
22319
22374
|
next2 = updateMathTokenLabel(next2, selectedMath.tokenId, {
|
|
22320
22375
|
labelEnabled: selectedMath.labelEnabled,
|
|
22321
|
-
label: selectedMath.label
|
|
22376
|
+
label: selectedMath.label,
|
|
22377
|
+
numbered: selectedMath.numbered
|
|
22322
22378
|
});
|
|
22323
22379
|
} else {
|
|
22324
|
-
next2 = updateMathTokenLabel(next2, selectedMath.tokenId, { labelEnabled: false, label: "" });
|
|
22380
|
+
next2 = updateMathTokenLabel(next2, selectedMath.tokenId, { labelEnabled: false, label: "", numbered: false });
|
|
22325
22381
|
}
|
|
22326
22382
|
pendingFocusRef.current = { kind: "math", tokenId: selectedMath.tokenId };
|
|
22327
22383
|
applyDocument(next2, "immediate");
|
|
@@ -22366,10 +22422,11 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
|
|
|
22366
22422
|
0,
|
|
22367
22423
|
fieldAfter.tokens.findIndex((token) => token.id === trailingTextTokenId) - 1
|
|
22368
22424
|
)]?.id : null : fieldAfter?.tokens.filter((token) => token.kind === "math").at(-1)?.id ?? null;
|
|
22369
|
-
if (insertedMathId && selectedMath.mathMode === "display"
|
|
22425
|
+
if (insertedMathId && selectedMath.mathMode === "display") {
|
|
22370
22426
|
next = updateMathTokenLabel(next, insertedMathId, {
|
|
22371
|
-
labelEnabled:
|
|
22372
|
-
label: selectedMath.label
|
|
22427
|
+
labelEnabled: selectedMath.labelEnabled,
|
|
22428
|
+
label: selectedMath.label,
|
|
22429
|
+
numbered: selectedMath.numbered
|
|
22373
22430
|
});
|
|
22374
22431
|
}
|
|
22375
22432
|
if (insertedMathId) {
|
|
@@ -22821,10 +22878,12 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
|
|
|
22821
22878
|
responsiveMode,
|
|
22822
22879
|
labelEnabled: selectedMath.labelEnabled,
|
|
22823
22880
|
label: selectedMath.label,
|
|
22881
|
+
numbered: selectedMath.numbered,
|
|
22882
|
+
onNumberedChange: (numbered) => setSelectedMath((current) => current ? { ...current, numbered } : current),
|
|
22824
22883
|
labels: documentLabels,
|
|
22825
22884
|
references: documentNode.references,
|
|
22826
22885
|
ownerId: selectedMath.tokenId ?? void 0,
|
|
22827
|
-
onLabelEnabledChange: (enabled) => setSelectedMath((current) => current ? { ...current, labelEnabled: enabled } : current),
|
|
22886
|
+
onLabelEnabledChange: (enabled) => setSelectedMath((current) => current ? { ...current, labelEnabled: enabled, numbered: enabled || current.numbered } : current),
|
|
22828
22887
|
onLabelChange: (nextLabel) => setSelectedMath((current) => current ? { ...current, label: nextLabel } : current),
|
|
22829
22888
|
onMathModeChange: (mode) => setSelectedMath((current) => current ? { ...current, mathMode: mode } : current),
|
|
22830
22889
|
onClose: closeEquationAndRestoreOrigin,
|
|
@@ -22852,13 +22911,16 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
|
|
|
22852
22911
|
RefPickerPopover,
|
|
22853
22912
|
{
|
|
22854
22913
|
open: refPicker !== null,
|
|
22855
|
-
|
|
22914
|
+
targets: referenceTargets,
|
|
22856
22915
|
initialKeys: refPicker?.keys ?? [],
|
|
22857
22916
|
initialRefCommand: refPicker?.refCommand ?? "ref",
|
|
22858
22917
|
uiLocale,
|
|
22859
22918
|
digitForm,
|
|
22860
22919
|
onClose: () => setRefPicker(null),
|
|
22861
22920
|
onConfirm: confirmRefKeys,
|
|
22921
|
+
onNumberEquation: (tokenId) => {
|
|
22922
|
+
applyDocument(updateMathTokenLabel(documentRef.current, tokenId, { numbered: true }), "immediate");
|
|
22923
|
+
},
|
|
22862
22924
|
onManageLabels: () => {
|
|
22863
22925
|
setRefPicker(null);
|
|
22864
22926
|
openLabelsManager();
|