@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.mjs
CHANGED
|
@@ -838,82 +838,79 @@ function refTokenLatex(keys, refCommand) {
|
|
|
838
838
|
const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
|
|
839
839
|
return `${command}{${keys.join(",")}}`;
|
|
840
840
|
}
|
|
841
|
-
function
|
|
842
|
-
const
|
|
841
|
+
function implicitReferenceKey(kind, ownerId, unitId) {
|
|
842
|
+
const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
843
|
+
const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
|
|
844
|
+
return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
|
|
845
|
+
}
|
|
846
|
+
function supportsSingleEquationNumbering(token) {
|
|
847
|
+
return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
|
|
848
|
+
}
|
|
849
|
+
function isNumberedEquation(token) {
|
|
850
|
+
if (!supportsSingleEquationNumbering(token)) return false;
|
|
851
|
+
if (typeof token.numbered === "boolean") return token.numbered;
|
|
852
|
+
return token.opening === "\\begin{equation}" || Boolean(token.labelEnabled) && Boolean(token.label?.trim());
|
|
853
|
+
}
|
|
854
|
+
function isNumberedFloat(block) {
|
|
855
|
+
return block.captionEnabled && block.caption.trim().length > 0 || block.labelEnabled && block.label.trim().length > 0;
|
|
856
|
+
}
|
|
857
|
+
function collectDocumentReferenceTargets(document2) {
|
|
858
|
+
const targets = [];
|
|
843
859
|
const counters = { fig: 0, tab: 0, eq: 0 };
|
|
844
|
-
function
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
860
|
+
function append(kind, ownerId, caption, numbered, manualKey = "") {
|
|
861
|
+
if (numbered) counters[kind] += 1;
|
|
862
|
+
targets.push({
|
|
863
|
+
key: implicitReferenceKey(kind, ownerId),
|
|
864
|
+
kind,
|
|
865
|
+
ownerId,
|
|
866
|
+
caption,
|
|
867
|
+
number: numbered ? counters[kind] : null,
|
|
868
|
+
...manualKey.trim() ? { manualKey: manualKey.trim() } : {}
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
function visitField(field) {
|
|
872
|
+
for (const token of field.tokens) {
|
|
873
|
+
if (token.kind === "math" && supportsSingleEquationNumbering(token)) {
|
|
874
|
+
append("eq", token.id, "", isNumberedEquation(token), token.labelEnabled ? token.label ?? "" : "");
|
|
858
875
|
}
|
|
859
876
|
}
|
|
860
877
|
}
|
|
861
878
|
function walk(blocks) {
|
|
862
879
|
for (const block of blocks) {
|
|
863
|
-
if (block.kind === "image") {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
if (block.captionEnabled) {
|
|
875
|
-
pushEqFromField(block.captionField.tokens);
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
if (block.kind === "table") {
|
|
879
|
-
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
880
|
-
counters.tab += 1;
|
|
881
|
-
entries.push({
|
|
882
|
-
key: block.label.trim(),
|
|
883
|
-
kind: "tab",
|
|
884
|
-
caption: block.captionEnabled ? block.caption : "",
|
|
885
|
-
ownerId: block.id,
|
|
886
|
-
number: counters.tab
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
if (block.captionEnabled) {
|
|
890
|
-
pushEqFromField(block.captionField.tokens);
|
|
891
|
-
}
|
|
892
|
-
for (const row of block.rows) {
|
|
893
|
-
for (const cell of row) {
|
|
894
|
-
pushEqFromField(cell.tokens);
|
|
895
|
-
}
|
|
880
|
+
if (block.kind === "image" || block.kind === "table") {
|
|
881
|
+
append(
|
|
882
|
+
block.kind === "image" ? "fig" : "tab",
|
|
883
|
+
block.id,
|
|
884
|
+
block.captionEnabled ? block.caption : "",
|
|
885
|
+
isNumberedFloat(block),
|
|
886
|
+
block.labelEnabled ? block.label : ""
|
|
887
|
+
);
|
|
888
|
+
if (block.captionEnabled) visitField(block.captionField);
|
|
889
|
+
if (block.kind === "table") {
|
|
890
|
+
for (const row of block.rows) for (const cell of row) visitField(cell);
|
|
896
891
|
}
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
}
|
|
901
|
-
if (block.kind === "list") {
|
|
892
|
+
} else if (block.kind === "textBlock") {
|
|
893
|
+
visitField(block.field);
|
|
894
|
+
} else if (block.kind === "list") {
|
|
902
895
|
for (const item of block.items) {
|
|
903
|
-
|
|
896
|
+
visitField(item.field);
|
|
904
897
|
walk(item.blocks);
|
|
905
898
|
}
|
|
906
899
|
}
|
|
907
900
|
}
|
|
908
901
|
}
|
|
909
902
|
walk(document2.blocks);
|
|
910
|
-
return
|
|
903
|
+
return targets;
|
|
904
|
+
}
|
|
905
|
+
function collectDocumentLabels(document2) {
|
|
906
|
+
return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null && Boolean(target.manualKey)).map(({ manualKey, kind, caption, ownerId, number }) => ({ key: manualKey, kind, caption, ownerId, number }));
|
|
911
907
|
}
|
|
912
908
|
function labelNumberMap(document2) {
|
|
913
909
|
const map = /* @__PURE__ */ new Map();
|
|
914
|
-
for (const
|
|
915
|
-
if (
|
|
916
|
-
|
|
910
|
+
for (const target of collectDocumentReferenceTargets(document2)) {
|
|
911
|
+
if (target.number === null) continue;
|
|
912
|
+
for (const key of [target.key, target.manualKey]) {
|
|
913
|
+
if (key && !map.has(key)) map.set(key, { kind: target.kind, number: target.number });
|
|
917
914
|
}
|
|
918
915
|
}
|
|
919
916
|
return map;
|
|
@@ -967,8 +964,12 @@ function stripDisplayMathDelimiters(source) {
|
|
|
967
964
|
if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) {
|
|
968
965
|
return trimmed.slice(2, -2).trim();
|
|
969
966
|
}
|
|
970
|
-
|
|
971
|
-
|
|
967
|
+
for (const environment of ["equation", "equation*"]) {
|
|
968
|
+
const opening = `\\begin{${environment}}`;
|
|
969
|
+
const closing = `\\end{${environment}}`;
|
|
970
|
+
if (trimmed.startsWith(opening) && trimmed.endsWith(closing)) {
|
|
971
|
+
return trimmed.slice(opening.length, -closing.length).trim();
|
|
972
|
+
}
|
|
972
973
|
}
|
|
973
974
|
return trimmed;
|
|
974
975
|
}
|
|
@@ -1361,7 +1362,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1361
1362
|
editable: true,
|
|
1362
1363
|
sourceOwner: structuredMathJson.source_owner === "editor" ? "editor" : "imported-structured",
|
|
1363
1364
|
...typeof structuredMathJson.label_enabled === "boolean" ? { labelEnabled: structuredMathJson.label_enabled } : {},
|
|
1364
|
-
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {}
|
|
1365
|
+
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {},
|
|
1366
|
+
...typeof structuredMathJson.numbered === "boolean" ? { numbered: structuredMathJson.numbered } : {}
|
|
1365
1367
|
});
|
|
1366
1368
|
} else {
|
|
1367
1369
|
tokens.push({
|
|
@@ -1376,7 +1378,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1376
1378
|
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",
|
|
1377
1379
|
sourceOwner: "raw",
|
|
1378
1380
|
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label_enabled === "boolean" ? { labelEnabled: mathJson.label_enabled } : {},
|
|
1379
|
-
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {}
|
|
1381
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {},
|
|
1382
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.numbered === "boolean" ? { numbered: mathJson.numbered } : {}
|
|
1380
1383
|
});
|
|
1381
1384
|
}
|
|
1382
1385
|
index = span.end;
|
|
@@ -9452,6 +9455,9 @@ function replaceMathTokenFromSession(document2, tokenId, session, opening, closi
|
|
|
9452
9455
|
if (current.label !== void 0) {
|
|
9453
9456
|
replaced.label = current.label;
|
|
9454
9457
|
}
|
|
9458
|
+
if (current.numbered !== void 0) {
|
|
9459
|
+
replaced.numbered = current.numbered;
|
|
9460
|
+
}
|
|
9455
9461
|
field.tokens[index] = replaced;
|
|
9456
9462
|
return true;
|
|
9457
9463
|
});
|
|
@@ -9671,6 +9677,9 @@ function updateMathTokenLabel(document2, tokenId, patch) {
|
|
|
9671
9677
|
if (typeof patch.label === "string") {
|
|
9672
9678
|
token.label = patch.label;
|
|
9673
9679
|
}
|
|
9680
|
+
if (typeof patch.numbered === "boolean") {
|
|
9681
|
+
token.numbered = patch.numbered;
|
|
9682
|
+
}
|
|
9674
9683
|
return true;
|
|
9675
9684
|
});
|
|
9676
9685
|
return next;
|
|
@@ -9988,12 +9997,13 @@ function serializeField(field) {
|
|
|
9988
9997
|
}
|
|
9989
9998
|
value += token.source;
|
|
9990
9999
|
if (!token.math || token.sourceOwner === "raw") {
|
|
9991
|
-
if (token.labelEnabled !== void 0 || token.label !== void 0) {
|
|
10000
|
+
if (token.labelEnabled !== void 0 || token.label !== void 0 || token.numbered !== void 0) {
|
|
9992
10001
|
hasPersistedMath = true;
|
|
9993
10002
|
mathObjects.push({
|
|
9994
10003
|
node_type: "RawMathObject",
|
|
9995
10004
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
9996
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
10005
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
10006
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
9997
10007
|
});
|
|
9998
10008
|
} else {
|
|
9999
10009
|
mathObjects.push(null);
|
|
@@ -10006,7 +10016,8 @@ function serializeField(field) {
|
|
|
10006
10016
|
...token.sourceSide ? { source_side: token.sourceSide } : {},
|
|
10007
10017
|
source_owner: token.sourceOwner,
|
|
10008
10018
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
10009
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
10019
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
10020
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
10010
10021
|
});
|
|
10011
10022
|
}
|
|
10012
10023
|
return { value, formats, mathObjects, hasPersistedMath, inlineIds: inlineIdsFromField(field) };
|
|
@@ -10374,9 +10385,13 @@ function digitsMappingFromDigitForm(digitForm) {
|
|
|
10374
10385
|
}
|
|
10375
10386
|
return "arabicdigits";
|
|
10376
10387
|
}
|
|
10388
|
+
function editorMathLatexForCompile(token) {
|
|
10389
|
+
const source = token.math && token.sourceSide === "arabic" && token.source.includes("\\begin{cases}") ? mathTokenSourceForSide(token, "arabic", void 0, true) : token.source;
|
|
10390
|
+
return mirrorBuTeXOperatorsInTex(source, { target: "compile" });
|
|
10391
|
+
}
|
|
10377
10392
|
function mathBodyLatex(token) {
|
|
10378
10393
|
if (token.sourceOwner === "editor") {
|
|
10379
|
-
return stripDisplayMathDelimiters(
|
|
10394
|
+
return stripDisplayMathDelimiters(editorMathLatexForCompile(token));
|
|
10380
10395
|
}
|
|
10381
10396
|
if (!token.math || token.sourceOwner === "raw") {
|
|
10382
10397
|
return stripDisplayMathDelimiters(token.source);
|
|
@@ -10443,15 +10458,18 @@ function tokenLatex(token, labelKinds, previousToken) {
|
|
|
10443
10458
|
if (token.kind === "ref") {
|
|
10444
10459
|
return refTokenLatexForDocument(token, labelKinds, previousToken);
|
|
10445
10460
|
}
|
|
10446
|
-
if (token
|
|
10461
|
+
if (isNumberedEquation(token)) {
|
|
10447
10462
|
const body = mathBodyLatex(token);
|
|
10448
|
-
|
|
10449
|
-
|
|
10450
|
-
|
|
10451
|
-
\\end{equation}
|
|
10463
|
+
const autoKey = implicitReferenceKey("eq", token.id);
|
|
10464
|
+
const aliases = [autoKey];
|
|
10465
|
+
if (token.labelEnabled && token.label?.trim() && token.label.trim() !== autoKey) aliases.push(token.label.trim());
|
|
10466
|
+
return "\\begin{equation}\n" + body + "\n" + aliases.map((key) => "\\label{" + key + "}").join("\n") + "\n\\end{equation}";
|
|
10467
|
+
}
|
|
10468
|
+
if (token.display && token.numbered === false && token.opening === "\\begin{equation}") {
|
|
10469
|
+
return "\\[" + mathBodyLatex(token) + "\\]";
|
|
10452
10470
|
}
|
|
10453
10471
|
if (token.sourceOwner === "editor") {
|
|
10454
|
-
return
|
|
10472
|
+
return editorMathLatexForCompile(token);
|
|
10455
10473
|
}
|
|
10456
10474
|
if (!token.math || token.sourceOwner === "raw") {
|
|
10457
10475
|
return token.source;
|
|
@@ -10515,11 +10533,12 @@ function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
|
10515
10533
|
if (hasCaption) {
|
|
10516
10534
|
lines.push(` \\caption{${caption}}`);
|
|
10517
10535
|
}
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
lines.push(
|
|
10536
|
+
const hasManualLabel = block.labelEnabled && block.label.trim().length > 0;
|
|
10537
|
+
if (hasCaption || hasManualLabel) {
|
|
10538
|
+
if (!hasCaption) lines.push(" \\refstepcounter{" + counter + "}");
|
|
10539
|
+
const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id);
|
|
10540
|
+
lines.push(" \\label{" + autoKey + "}");
|
|
10541
|
+
if (hasManualLabel && block.label.trim() !== autoKey) lines.push(" \\label{" + block.label.trim() + "}");
|
|
10523
10542
|
}
|
|
10524
10543
|
return lines;
|
|
10525
10544
|
}
|
|
@@ -10615,10 +10634,8 @@ ${meta.abstract.trim()}
|
|
|
10615
10634
|
}
|
|
10616
10635
|
function documentLabelKindMap(document2) {
|
|
10617
10636
|
const map = /* @__PURE__ */ new Map();
|
|
10618
|
-
for (const entry of
|
|
10619
|
-
|
|
10620
|
-
map.set(entry.key, entry.kind);
|
|
10621
|
-
}
|
|
10637
|
+
for (const [key, entry] of labelNumberMap(document2)) {
|
|
10638
|
+
map.set(key, entry.kind);
|
|
10622
10639
|
}
|
|
10623
10640
|
return map;
|
|
10624
10641
|
}
|
|
@@ -10717,10 +10734,17 @@ function validateToken(context, token, path, blockId) {
|
|
|
10717
10734
|
return;
|
|
10718
10735
|
}
|
|
10719
10736
|
validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
|
|
10737
|
+
if (token.numbered === true && !supportsSingleEquationNumbering(token)) {
|
|
10738
|
+
addIssue(context, "invalid_equation_label", `${path}.numbered`, blockId, token.id);
|
|
10739
|
+
}
|
|
10720
10740
|
if (!token.labelEnabled) {
|
|
10721
10741
|
return;
|
|
10722
10742
|
}
|
|
10723
|
-
if (!token
|
|
10743
|
+
if (!supportsSingleEquationNumbering(token)) {
|
|
10744
|
+
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
10745
|
+
return;
|
|
10746
|
+
}
|
|
10747
|
+
if (!isNumberedEquation(token)) {
|
|
10724
10748
|
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
10725
10749
|
return;
|
|
10726
10750
|
}
|
|
@@ -10818,7 +10842,7 @@ function validatePendingReferences(context) {
|
|
|
10818
10842
|
for (const pending of context.pendingReferences) {
|
|
10819
10843
|
for (const key of pending.token.keys) {
|
|
10820
10844
|
const normalized = normalizeDocumentKey(key);
|
|
10821
|
-
if (!isValidDocumentKey(normalized)) {
|
|
10845
|
+
if (!isValidDocumentKey(normalized) || !context.labelKinds.has(normalized)) {
|
|
10822
10846
|
addIssue(
|
|
10823
10847
|
context,
|
|
10824
10848
|
"missing_reference",
|
|
@@ -10917,6 +10941,18 @@ function validateDocument(document2) {
|
|
|
10917
10941
|
resolved.blocks.forEach((block, index) => {
|
|
10918
10942
|
validateBlock(context, block, `$.blocks[${String(index)}]`);
|
|
10919
10943
|
});
|
|
10944
|
+
for (const target of collectDocumentReferenceTargets(resolved)) {
|
|
10945
|
+
if (target.number !== null && target.manualKey !== target.key) {
|
|
10946
|
+
registerKey(
|
|
10947
|
+
context,
|
|
10948
|
+
target.key,
|
|
10949
|
+
"$.automatic_labels",
|
|
10950
|
+
target.kind,
|
|
10951
|
+
target.kind === "eq" ? void 0 : target.ownerId,
|
|
10952
|
+
target.kind === "eq" ? target.ownerId : void 0
|
|
10953
|
+
);
|
|
10954
|
+
}
|
|
10955
|
+
}
|
|
10920
10956
|
for (const diagnostic of resolved.diagnostics) {
|
|
10921
10957
|
addIssue(context, "parser_diagnostic", diagnostic.path);
|
|
10922
10958
|
}
|
|
@@ -11057,6 +11093,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
11057
11093
|
})
|
|
11058
11094
|
};
|
|
11059
11095
|
}
|
|
11096
|
+
const number = collectDocumentReferenceTargets(document2).find((target) => target.kind === "eq" && target.ownerId === token.id)?.number;
|
|
11060
11097
|
const island = {
|
|
11061
11098
|
id: token.id,
|
|
11062
11099
|
tex: mathTex(token, equationSide, previewOptions.digitForm),
|
|
@@ -11064,8 +11101,12 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
11064
11101
|
output,
|
|
11065
11102
|
editable: token.editable
|
|
11066
11103
|
};
|
|
11104
|
+
const numberLabel = number == null ? void 0 : formatBibliographyNumber(number, {
|
|
11105
|
+
documentDirection: previewOptions.documentDirection,
|
|
11106
|
+
digitForm: previewOptions.digitForm
|
|
11107
|
+
});
|
|
11067
11108
|
islands.push(island);
|
|
11068
|
-
return { kind: "math", ...island };
|
|
11109
|
+
return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
|
|
11069
11110
|
});
|
|
11070
11111
|
}
|
|
11071
11112
|
function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
@@ -11088,12 +11129,9 @@ function textBlockPreview(block, islands, output, equationSide, document2, previ
|
|
|
11088
11129
|
...block.centered ? { centered: true } : {}
|
|
11089
11130
|
};
|
|
11090
11131
|
}
|
|
11091
|
-
function floatNumberLabel(document2,
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
}
|
|
11095
|
-
const hit = labelNumberMap(document2).get(key.trim());
|
|
11096
|
-
if (!hit || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
11132
|
+
function floatNumberLabel(document2, ownerId, previewOptions) {
|
|
11133
|
+
const hit = collectDocumentReferenceTargets(document2).find((target) => target.ownerId === ownerId);
|
|
11134
|
+
if (!hit || hit.number === null || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
11097
11135
|
return void 0;
|
|
11098
11136
|
}
|
|
11099
11137
|
return formatFloatCaptionTitle(hit.kind, hit.number, {
|
|
@@ -11135,7 +11173,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
11135
11173
|
id: block.id,
|
|
11136
11174
|
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
|
|
11137
11175
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
11138
|
-
...label.length > 0 ? { label
|
|
11176
|
+
...label.length > 0 ? { label } : {},
|
|
11177
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
11139
11178
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
11140
11179
|
};
|
|
11141
11180
|
}
|
|
@@ -11149,7 +11188,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
11149
11188
|
options: block.options,
|
|
11150
11189
|
centered: block.centered,
|
|
11151
11190
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
11152
|
-
...label.length > 0 ? { label
|
|
11191
|
+
...label.length > 0 ? { label } : {},
|
|
11192
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
11153
11193
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
11154
11194
|
};
|
|
11155
11195
|
}
|
|
@@ -14371,7 +14411,14 @@ function PreviewInlines({ inlines, output }) {
|
|
|
14371
14411
|
if (inline.kind === "ref") {
|
|
14372
14412
|
return /* @__PURE__ */ jsx12("span", { className: "butex-document-widget__preview-cite butex-document-widget__preview-ref", children: contextualRefLabel(inlines, index, inline.label) }, inline.id);
|
|
14373
14413
|
}
|
|
14374
|
-
return /* @__PURE__ */
|
|
14414
|
+
return /* @__PURE__ */ jsxs11("span", { className: "butex-document-widget__preview-math-numbered", children: [
|
|
14415
|
+
/* @__PURE__ */ jsx12(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }),
|
|
14416
|
+
inline.numberLabel ? /* @__PURE__ */ jsxs11("span", { className: "butex-document-widget__preview-equation-number", children: [
|
|
14417
|
+
"(",
|
|
14418
|
+
inline.numberLabel,
|
|
14419
|
+
")"
|
|
14420
|
+
] }) : null
|
|
14421
|
+
] }, inline.id);
|
|
14375
14422
|
}) });
|
|
14376
14423
|
}
|
|
14377
14424
|
function isBodyPreviewBlock(block) {
|
|
@@ -18435,6 +18482,8 @@ function EquationDrawer({
|
|
|
18435
18482
|
responsiveMode = "auto",
|
|
18436
18483
|
labelEnabled = false,
|
|
18437
18484
|
label = "",
|
|
18485
|
+
numbered = false,
|
|
18486
|
+
onNumberedChange,
|
|
18438
18487
|
labels = [],
|
|
18439
18488
|
references = [],
|
|
18440
18489
|
ownerId = "",
|
|
@@ -18524,6 +18573,10 @@ function EquationDrawer({
|
|
|
18524
18573
|
] })
|
|
18525
18574
|
] }),
|
|
18526
18575
|
mathMode === "display" ? /* @__PURE__ */ jsxs14("div", { className: "butex-document-widget__float-meta", children: [
|
|
18576
|
+
/* @__PURE__ */ jsxs14("label", { className: "butex-document-widget__float-meta-toggle", children: [
|
|
18577
|
+
/* @__PURE__ */ jsx15("input", { type: "checkbox", checked: numbered, onChange: (event) => onNumberedChange?.(event.currentTarget.checked) }),
|
|
18578
|
+
/* @__PURE__ */ jsx15("span", { children: uiLocale === "ar" ? "\u062A\u0631\u0642\u064A\u0645 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629" : "Number equation" })
|
|
18579
|
+
] }),
|
|
18527
18580
|
/* @__PURE__ */ jsxs14("label", { className: "butex-document-widget__float-meta-toggle", children: [
|
|
18528
18581
|
/* @__PURE__ */ jsx15(
|
|
18529
18582
|
"input",
|
|
@@ -19047,13 +19100,14 @@ import { useEffect as useEffect12, useRef as useRef14, useState as useState13 }
|
|
|
19047
19100
|
import { jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
19048
19101
|
function RefPickerPopover({
|
|
19049
19102
|
open,
|
|
19050
|
-
|
|
19103
|
+
targets,
|
|
19051
19104
|
initialKeys = [],
|
|
19052
19105
|
initialRefCommand = "ref",
|
|
19053
19106
|
uiLocale = "ar",
|
|
19054
19107
|
digitForm = "arabicIndic",
|
|
19055
19108
|
onClose,
|
|
19056
19109
|
onConfirm,
|
|
19110
|
+
onNumberEquation,
|
|
19057
19111
|
onManageLabels
|
|
19058
19112
|
}) {
|
|
19059
19113
|
const messages = documentMessages(uiLocale);
|
|
@@ -19090,22 +19144,19 @@ function RefPickerPopover({
|
|
|
19090
19144
|
/* @__PURE__ */ jsx18("strong", { children: messages.refPickerTitle }),
|
|
19091
19145
|
/* @__PURE__ */ jsx18("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" })
|
|
19092
19146
|
] }),
|
|
19093
|
-
/* @__PURE__ */ jsx18("div", { className: "butex-document-widget__dialog-body", children:
|
|
19094
|
-
const checked = selected.includes(entry.key);
|
|
19095
|
-
const title = formatFloatCaptionTitle(entry.kind, entry.number, {
|
|
19147
|
+
/* @__PURE__ */ jsx18("div", { className: "butex-document-widget__dialog-body", children: targets.length === 0 ? /* @__PURE__ */ jsx18("p", { className: "butex-document-widget__cite-picker-empty", children: messages.noLabelsYet }) : /* @__PURE__ */ jsx18("ul", { className: "butex-document-widget__cite-picker-list", children: targets.filter((entry) => entry.number !== null || entry.kind === "eq").map((entry) => {
|
|
19148
|
+
const checked = selected.includes(entry.key) || Boolean(entry.manualKey && selected.includes(entry.manualKey));
|
|
19149
|
+
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, {
|
|
19096
19150
|
uiLocale,
|
|
19097
19151
|
digitForm,
|
|
19098
19152
|
documentDirection
|
|
19099
19153
|
});
|
|
19100
19154
|
return /* @__PURE__ */ jsx18("li", { children: /* @__PURE__ */ jsxs17("label", { className: "butex-document-widget__cite-picker-item", children: [
|
|
19101
|
-
/* @__PURE__ */ jsx18("input", { type: "radio", name: "butex-ref-key", checked, onChange: () => selectKey(entry.key, entry.kind) }),
|
|
19155
|
+
/* @__PURE__ */ jsx18("input", { type: "radio", name: "butex-ref-key", checked, disabled: entry.number === null, onChange: () => selectKey(entry.key, entry.kind) }),
|
|
19102
19156
|
/* @__PURE__ */ jsxs17("span", { children: [
|
|
19103
|
-
/* @__PURE__ */
|
|
19104
|
-
|
|
19105
|
-
|
|
19106
|
-
/* @__PURE__ */ jsx18("span", { className: "butex-document-widget__refs-item-key", children: entry.key })
|
|
19107
|
-
] }),
|
|
19108
|
-
entry.caption ? /* @__PURE__ */ jsx18("span", { className: "butex-document-widget__cite-picker-meta", children: entry.caption }) : null
|
|
19157
|
+
/* @__PURE__ */ jsx18("strong", { children: entry.kind === "eq" && entry.number !== null ? title.replace(/(\d+|[٠-٩]+)$/, "($1)") : title }),
|
|
19158
|
+
entry.caption ? /* @__PURE__ */ jsx18("span", { className: "butex-document-widget__cite-picker-meta", children: entry.caption }) : null,
|
|
19159
|
+
entry.kind === "eq" && entry.number === null && onNumberEquation ? /* @__PURE__ */ jsx18("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
|
|
19109
19160
|
] })
|
|
19110
19161
|
] }) }, `${entry.kind}:${entry.ownerId}`);
|
|
19111
19162
|
}) }) }),
|
|
@@ -21825,6 +21876,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
21825
21876
|
const latex = documentLatex(documentNode, { digitForm });
|
|
21826
21877
|
const documentJson = useMemo2(() => toDocumentJson(documentNode), [documentNode]);
|
|
21827
21878
|
const documentLabels = useMemo2(() => collectDocumentLabels(documentNode), [documentNode]);
|
|
21879
|
+
const referenceTargets = useMemo2(() => collectDocumentReferenceTargets(documentNode), [documentNode]);
|
|
21828
21880
|
const preview = useMemo2(
|
|
21829
21881
|
() => documentPreview(documentNode, mathOutput, equationSide, {
|
|
21830
21882
|
documentDirection,
|
|
@@ -22160,7 +22212,8 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22160
22212
|
session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
|
|
22161
22213
|
reason: null,
|
|
22162
22214
|
labelEnabled: false,
|
|
22163
|
-
label: ""
|
|
22215
|
+
label: "",
|
|
22216
|
+
numbered: false
|
|
22164
22217
|
});
|
|
22165
22218
|
}
|
|
22166
22219
|
function openMath(token, origin) {
|
|
@@ -22185,7 +22238,8 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22185
22238
|
session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
|
|
22186
22239
|
reason: result.reason,
|
|
22187
22240
|
labelEnabled: Boolean(token.labelEnabled),
|
|
22188
|
-
label: token.label ?? ""
|
|
22241
|
+
label: token.label ?? "",
|
|
22242
|
+
numbered: isNumberedEquation(token)
|
|
22189
22243
|
});
|
|
22190
22244
|
return;
|
|
22191
22245
|
}
|
|
@@ -22198,7 +22252,8 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22198
22252
|
session: equationSessionWithDocumentDigits(result.session),
|
|
22199
22253
|
reason: null,
|
|
22200
22254
|
labelEnabled: Boolean(token.labelEnabled),
|
|
22201
|
-
label: token.label ?? ""
|
|
22255
|
+
label: token.label ?? "",
|
|
22256
|
+
numbered: isNumberedEquation(token)
|
|
22202
22257
|
});
|
|
22203
22258
|
}
|
|
22204
22259
|
function selectMobileView(view) {
|
|
@@ -22289,10 +22344,11 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22289
22344
|
if (selectedMath.mathMode === "display") {
|
|
22290
22345
|
next2 = updateMathTokenLabel(next2, selectedMath.tokenId, {
|
|
22291
22346
|
labelEnabled: selectedMath.labelEnabled,
|
|
22292
|
-
label: selectedMath.label
|
|
22347
|
+
label: selectedMath.label,
|
|
22348
|
+
numbered: selectedMath.numbered
|
|
22293
22349
|
});
|
|
22294
22350
|
} else {
|
|
22295
|
-
next2 = updateMathTokenLabel(next2, selectedMath.tokenId, { labelEnabled: false, label: "" });
|
|
22351
|
+
next2 = updateMathTokenLabel(next2, selectedMath.tokenId, { labelEnabled: false, label: "", numbered: false });
|
|
22296
22352
|
}
|
|
22297
22353
|
pendingFocusRef.current = { kind: "math", tokenId: selectedMath.tokenId };
|
|
22298
22354
|
applyDocument(next2, "immediate");
|
|
@@ -22337,10 +22393,11 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22337
22393
|
0,
|
|
22338
22394
|
fieldAfter.tokens.findIndex((token) => token.id === trailingTextTokenId) - 1
|
|
22339
22395
|
)]?.id : null : fieldAfter?.tokens.filter((token) => token.kind === "math").at(-1)?.id ?? null;
|
|
22340
|
-
if (insertedMathId && selectedMath.mathMode === "display"
|
|
22396
|
+
if (insertedMathId && selectedMath.mathMode === "display") {
|
|
22341
22397
|
next = updateMathTokenLabel(next, insertedMathId, {
|
|
22342
|
-
labelEnabled:
|
|
22343
|
-
label: selectedMath.label
|
|
22398
|
+
labelEnabled: selectedMath.labelEnabled,
|
|
22399
|
+
label: selectedMath.label,
|
|
22400
|
+
numbered: selectedMath.numbered
|
|
22344
22401
|
});
|
|
22345
22402
|
}
|
|
22346
22403
|
if (insertedMathId) {
|
|
@@ -22792,10 +22849,12 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22792
22849
|
responsiveMode,
|
|
22793
22850
|
labelEnabled: selectedMath.labelEnabled,
|
|
22794
22851
|
label: selectedMath.label,
|
|
22852
|
+
numbered: selectedMath.numbered,
|
|
22853
|
+
onNumberedChange: (numbered) => setSelectedMath((current) => current ? { ...current, numbered } : current),
|
|
22795
22854
|
labels: documentLabels,
|
|
22796
22855
|
references: documentNode.references,
|
|
22797
22856
|
ownerId: selectedMath.tokenId ?? void 0,
|
|
22798
|
-
onLabelEnabledChange: (enabled) => setSelectedMath((current) => current ? { ...current, labelEnabled: enabled } : current),
|
|
22857
|
+
onLabelEnabledChange: (enabled) => setSelectedMath((current) => current ? { ...current, labelEnabled: enabled, numbered: enabled || current.numbered } : current),
|
|
22799
22858
|
onLabelChange: (nextLabel) => setSelectedMath((current) => current ? { ...current, label: nextLabel } : current),
|
|
22800
22859
|
onMathModeChange: (mode) => setSelectedMath((current) => current ? { ...current, mathMode: mode } : current),
|
|
22801
22860
|
onClose: closeEquationAndRestoreOrigin,
|
|
@@ -22823,13 +22882,16 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22823
22882
|
RefPickerPopover,
|
|
22824
22883
|
{
|
|
22825
22884
|
open: refPicker !== null,
|
|
22826
|
-
|
|
22885
|
+
targets: referenceTargets,
|
|
22827
22886
|
initialKeys: refPicker?.keys ?? [],
|
|
22828
22887
|
initialRefCommand: refPicker?.refCommand ?? "ref",
|
|
22829
22888
|
uiLocale,
|
|
22830
22889
|
digitForm,
|
|
22831
22890
|
onClose: () => setRefPicker(null),
|
|
22832
22891
|
onConfirm: confirmRefKeys,
|
|
22892
|
+
onNumberEquation: (tokenId) => {
|
|
22893
|
+
applyDocument(updateMathTokenLabel(documentRef.current, tokenId, { numbered: true }), "immediate");
|
|
22894
|
+
},
|
|
22833
22895
|
onManageLabels: () => {
|
|
22834
22896
|
setRefPicker(null);
|
|
22835
22897
|
openLabelsManager();
|