@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
|
@@ -638,82 +638,76 @@ function refTokenLatex(keys, refCommand) {
|
|
|
638
638
|
const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
|
|
639
639
|
return `${command}{${keys.join(",")}}`;
|
|
640
640
|
}
|
|
641
|
-
function
|
|
642
|
-
const
|
|
641
|
+
function implicitReferenceKey(kind, ownerId, unitId) {
|
|
642
|
+
const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
643
|
+
const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
|
|
644
|
+
return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
|
|
645
|
+
}
|
|
646
|
+
function supportsSingleEquationNumbering(token) {
|
|
647
|
+
return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
|
|
648
|
+
}
|
|
649
|
+
function isNumberedEquation(token) {
|
|
650
|
+
if (!supportsSingleEquationNumbering(token)) return false;
|
|
651
|
+
if (typeof token.numbered === "boolean") return token.numbered;
|
|
652
|
+
return token.opening === "\\begin{equation}" || Boolean(token.labelEnabled) && Boolean(token.label?.trim());
|
|
653
|
+
}
|
|
654
|
+
function isNumberedFloat(block) {
|
|
655
|
+
return block.captionEnabled && block.caption.trim().length > 0 || block.labelEnabled && block.label.trim().length > 0;
|
|
656
|
+
}
|
|
657
|
+
function collectDocumentReferenceTargets(document2) {
|
|
658
|
+
const targets = [];
|
|
643
659
|
const counters = { fig: 0, tab: 0, eq: 0 };
|
|
644
|
-
function
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
660
|
+
function append(kind, ownerId, caption, numbered, manualKey = "") {
|
|
661
|
+
if (numbered) counters[kind] += 1;
|
|
662
|
+
targets.push({
|
|
663
|
+
key: implicitReferenceKey(kind, ownerId),
|
|
664
|
+
kind,
|
|
665
|
+
ownerId,
|
|
666
|
+
caption,
|
|
667
|
+
number: numbered ? counters[kind] : null,
|
|
668
|
+
...manualKey.trim() ? { manualKey: manualKey.trim() } : {}
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
function visitField(field) {
|
|
672
|
+
for (const token of field.tokens) {
|
|
673
|
+
if (token.kind === "math" && supportsSingleEquationNumbering(token)) {
|
|
674
|
+
append("eq", token.id, "", isNumberedEquation(token), token.labelEnabled ? token.label ?? "" : "");
|
|
658
675
|
}
|
|
659
676
|
}
|
|
660
677
|
}
|
|
661
678
|
function walk(blocks) {
|
|
662
679
|
for (const block of blocks) {
|
|
663
|
-
if (block.kind === "image") {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
if (block.captionEnabled) {
|
|
675
|
-
pushEqFromField(block.captionField.tokens);
|
|
680
|
+
if (block.kind === "image" || block.kind === "table") {
|
|
681
|
+
append(
|
|
682
|
+
block.kind === "image" ? "fig" : "tab",
|
|
683
|
+
block.id,
|
|
684
|
+
block.captionEnabled ? block.caption : "",
|
|
685
|
+
isNumberedFloat(block),
|
|
686
|
+
block.labelEnabled ? block.label : ""
|
|
687
|
+
);
|
|
688
|
+
if (block.captionEnabled) visitField(block.captionField);
|
|
689
|
+
if (block.kind === "table") {
|
|
690
|
+
for (const row of block.rows) for (const cell of row) visitField(cell);
|
|
676
691
|
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
counters.tab += 1;
|
|
681
|
-
entries.push({
|
|
682
|
-
key: block.label.trim(),
|
|
683
|
-
kind: "tab",
|
|
684
|
-
caption: block.captionEnabled ? block.caption : "",
|
|
685
|
-
ownerId: block.id,
|
|
686
|
-
number: counters.tab
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
if (block.captionEnabled) {
|
|
690
|
-
pushEqFromField(block.captionField.tokens);
|
|
691
|
-
}
|
|
692
|
-
for (const row of block.rows) {
|
|
693
|
-
for (const cell of row) {
|
|
694
|
-
pushEqFromField(cell.tokens);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
if (block.kind === "textBlock") {
|
|
699
|
-
pushEqFromField(block.field.tokens);
|
|
700
|
-
}
|
|
701
|
-
if (block.kind === "list") {
|
|
692
|
+
} else if (block.kind === "textBlock") {
|
|
693
|
+
visitField(block.field);
|
|
694
|
+
} else if (block.kind === "list") {
|
|
702
695
|
for (const item of block.items) {
|
|
703
|
-
|
|
696
|
+
visitField(item.field);
|
|
704
697
|
walk(item.blocks);
|
|
705
698
|
}
|
|
706
699
|
}
|
|
707
700
|
}
|
|
708
701
|
}
|
|
709
702
|
walk(document2.blocks);
|
|
710
|
-
return
|
|
703
|
+
return targets;
|
|
711
704
|
}
|
|
712
705
|
function labelNumberMap(document2) {
|
|
713
706
|
const map = /* @__PURE__ */ new Map();
|
|
714
|
-
for (const
|
|
715
|
-
if (
|
|
716
|
-
|
|
707
|
+
for (const target of collectDocumentReferenceTargets(document2)) {
|
|
708
|
+
if (target.number === null) continue;
|
|
709
|
+
for (const key of [target.key, target.manualKey]) {
|
|
710
|
+
if (key && !map.has(key)) map.set(key, { kind: target.kind, number: target.number });
|
|
717
711
|
}
|
|
718
712
|
}
|
|
719
713
|
return map;
|
|
@@ -1115,7 +1109,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1115
1109
|
editable: true,
|
|
1116
1110
|
sourceOwner: structuredMathJson.source_owner === "editor" ? "editor" : "imported-structured",
|
|
1117
1111
|
...typeof structuredMathJson.label_enabled === "boolean" ? { labelEnabled: structuredMathJson.label_enabled } : {},
|
|
1118
|
-
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {}
|
|
1112
|
+
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {},
|
|
1113
|
+
...typeof structuredMathJson.numbered === "boolean" ? { numbered: structuredMathJson.numbered } : {}
|
|
1119
1114
|
});
|
|
1120
1115
|
} else {
|
|
1121
1116
|
tokens.push({
|
|
@@ -1130,7 +1125,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1130
1125
|
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",
|
|
1131
1126
|
sourceOwner: "raw",
|
|
1132
1127
|
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label_enabled === "boolean" ? { labelEnabled: mathJson.label_enabled } : {},
|
|
1133
|
-
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {}
|
|
1128
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {},
|
|
1129
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.numbered === "boolean" ? { numbered: mathJson.numbered } : {}
|
|
1134
1130
|
});
|
|
1135
1131
|
}
|
|
1136
1132
|
index = span.end;
|
|
@@ -4587,6 +4583,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
4587
4583
|
})
|
|
4588
4584
|
};
|
|
4589
4585
|
}
|
|
4586
|
+
const number = collectDocumentReferenceTargets(document2).find((target) => target.kind === "eq" && target.ownerId === token.id)?.number;
|
|
4590
4587
|
const island = {
|
|
4591
4588
|
id: token.id,
|
|
4592
4589
|
tex: mathTex(token, equationSide, previewOptions.digitForm),
|
|
@@ -4594,8 +4591,12 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
4594
4591
|
output,
|
|
4595
4592
|
editable: token.editable
|
|
4596
4593
|
};
|
|
4594
|
+
const numberLabel = number == null ? void 0 : formatBibliographyNumber(number, {
|
|
4595
|
+
documentDirection: previewOptions.documentDirection,
|
|
4596
|
+
digitForm: previewOptions.digitForm
|
|
4597
|
+
});
|
|
4597
4598
|
islands.push(island);
|
|
4598
|
-
return { kind: "math", ...island };
|
|
4599
|
+
return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
|
|
4599
4600
|
});
|
|
4600
4601
|
}
|
|
4601
4602
|
function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
@@ -4618,12 +4619,9 @@ function textBlockPreview(block, islands, output, equationSide, document2, previ
|
|
|
4618
4619
|
...block.centered ? { centered: true } : {}
|
|
4619
4620
|
};
|
|
4620
4621
|
}
|
|
4621
|
-
function floatNumberLabel(document2,
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
}
|
|
4625
|
-
const hit = labelNumberMap(document2).get(key.trim());
|
|
4626
|
-
if (!hit || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
4622
|
+
function floatNumberLabel(document2, ownerId, previewOptions) {
|
|
4623
|
+
const hit = collectDocumentReferenceTargets(document2).find((target) => target.ownerId === ownerId);
|
|
4624
|
+
if (!hit || hit.number === null || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
4627
4625
|
return void 0;
|
|
4628
4626
|
}
|
|
4629
4627
|
return formatFloatCaptionTitle(hit.kind, hit.number, {
|
|
@@ -4665,7 +4663,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
4665
4663
|
id: block.id,
|
|
4666
4664
|
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
|
|
4667
4665
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
4668
|
-
...label.length > 0 ? { label
|
|
4666
|
+
...label.length > 0 ? { label } : {},
|
|
4667
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
4669
4668
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
4670
4669
|
};
|
|
4671
4670
|
}
|
|
@@ -4679,7 +4678,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
4679
4678
|
options: block.options,
|
|
4680
4679
|
centered: block.centered,
|
|
4681
4680
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
4682
|
-
...label.length > 0 ? { label
|
|
4681
|
+
...label.length > 0 ? { label } : {},
|
|
4682
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
4683
4683
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
4684
4684
|
};
|
|
4685
4685
|
}
|
|
@@ -7868,7 +7868,14 @@ function PreviewInlines({ inlines, output }) {
|
|
|
7868
7868
|
if (inline.kind === "ref") {
|
|
7869
7869
|
return /* @__PURE__ */ jsx2("span", { className: "butex-document-widget__preview-cite butex-document-widget__preview-ref", children: contextualRefLabel(inlines, index, inline.label) }, inline.id);
|
|
7870
7870
|
}
|
|
7871
|
-
return /* @__PURE__ */
|
|
7871
|
+
return /* @__PURE__ */ jsxs("span", { className: "butex-document-widget__preview-math-numbered", children: [
|
|
7872
|
+
/* @__PURE__ */ jsx2(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }),
|
|
7873
|
+
inline.numberLabel ? /* @__PURE__ */ jsxs("span", { className: "butex-document-widget__preview-equation-number", children: [
|
|
7874
|
+
"(",
|
|
7875
|
+
inline.numberLabel,
|
|
7876
|
+
")"
|
|
7877
|
+
] }) : null
|
|
7878
|
+
] }, inline.id);
|
|
7872
7879
|
}) });
|
|
7873
7880
|
}
|
|
7874
7881
|
function isBodyPreviewBlock(block) {
|