@drghaliasri/butex 8.0.3 → 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/dist/document.mjs CHANGED
@@ -851,82 +851,85 @@ function refTokenLatex(keys, refCommand) {
851
851
  const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
852
852
  return `${command}{${keys.join(",")}}`;
853
853
  }
854
- function collectDocumentLabels(document2) {
855
- const entries = [];
854
+ function implicitReferenceKey(kind, ownerId, unitId) {
855
+ const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
856
+ const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
857
+ return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
858
+ }
859
+ function supportsSingleEquationNumbering(token) {
860
+ return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
861
+ }
862
+ function isNumberedEquation(token) {
863
+ if (!supportsSingleEquationNumbering(token)) return false;
864
+ if (typeof token.numbered === "boolean") return token.numbered;
865
+ return token.opening === "\\begin{equation}" || Boolean(token.labelEnabled) && Boolean(token.label?.trim());
866
+ }
867
+ function isNumberedFloat(block) {
868
+ return block.captionEnabled && block.caption.trim().length > 0 || block.labelEnabled && block.label.trim().length > 0;
869
+ }
870
+ function collectDocumentReferenceTargets(document2) {
871
+ const targets = [];
856
872
  const counters = { fig: 0, tab: 0, eq: 0 };
857
- function pushEqFromField(tokens) {
858
- for (const token of tokens) {
859
- if (token.kind !== "math") {
860
- continue;
861
- }
862
- if (token.display && token.labelEnabled && token.label && token.label.trim().length > 0) {
863
- counters.eq += 1;
864
- entries.push({
865
- key: token.label.trim(),
866
- kind: "eq",
867
- caption: "",
868
- ownerId: token.id,
869
- number: counters.eq
870
- });
873
+ function append(kind, ownerId, caption, numbered, manualKey = "") {
874
+ if (numbered) counters[kind] += 1;
875
+ targets.push({
876
+ key: implicitReferenceKey(kind, ownerId),
877
+ kind,
878
+ ownerId,
879
+ caption,
880
+ number: numbered ? counters[kind] : null,
881
+ ...manualKey.trim() ? { manualKey: manualKey.trim() } : {}
882
+ });
883
+ }
884
+ function visitField(field) {
885
+ for (const token of field.tokens) {
886
+ if (token.kind === "math" && supportsSingleEquationNumbering(token)) {
887
+ append("eq", token.id, "", isNumberedEquation(token), token.labelEnabled ? token.label ?? "" : "");
871
888
  }
872
889
  }
873
890
  }
874
891
  function walk(blocks) {
875
892
  for (const block of blocks) {
876
- if (block.kind === "image") {
877
- if (block.labelEnabled && block.label.trim().length > 0) {
878
- counters.fig += 1;
879
- entries.push({
880
- key: block.label.trim(),
881
- kind: "fig",
882
- caption: block.captionEnabled ? block.caption : "",
883
- ownerId: block.id,
884
- number: counters.fig
885
- });
886
- }
887
- if (block.captionEnabled) {
888
- pushEqFromField(block.captionField.tokens);
889
- }
890
- }
891
- if (block.kind === "table") {
892
- if (block.labelEnabled && block.label.trim().length > 0) {
893
- counters.tab += 1;
894
- entries.push({
895
- key: block.label.trim(),
896
- kind: "tab",
897
- caption: block.captionEnabled ? block.caption : "",
898
- ownerId: block.id,
899
- number: counters.tab
900
- });
901
- }
902
- if (block.captionEnabled) {
903
- pushEqFromField(block.captionField.tokens);
904
- }
905
- for (const row of block.rows) {
906
- for (const cell of row) {
907
- pushEqFromField(cell.tokens);
908
- }
893
+ if (block.kind === "image" || block.kind === "table") {
894
+ append(
895
+ block.kind === "image" ? "fig" : "tab",
896
+ block.id,
897
+ block.captionEnabled ? block.caption : "",
898
+ isNumberedFloat(block),
899
+ block.labelEnabled ? block.label : ""
900
+ );
901
+ if (block.captionEnabled) visitField(block.captionField);
902
+ if (block.kind === "table") {
903
+ for (const row of block.rows) for (const cell of row) visitField(cell);
909
904
  }
910
- }
911
- if (block.kind === "textBlock") {
912
- pushEqFromField(block.field.tokens);
913
- }
914
- if (block.kind === "list") {
905
+ } else if (block.kind === "textBlock") {
906
+ visitField(block.field);
907
+ } else if (block.kind === "list") {
915
908
  for (const item of block.items) {
916
- pushEqFromField(item.field.tokens);
909
+ visitField(item.field);
917
910
  walk(item.blocks);
918
911
  }
919
912
  }
920
913
  }
921
914
  }
922
915
  walk(document2.blocks);
923
- return entries;
916
+ return targets;
917
+ }
918
+ function collectDocumentLabels(document2) {
919
+ return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null && Boolean(target.manualKey)).map(({ manualKey, kind, caption, ownerId, number }) => ({ key: manualKey, kind, caption, ownerId, number }));
920
+ }
921
+ function collectDocumentKeyLabels(document2) {
922
+ return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null).flatMap((target) => [
923
+ { key: target.key, ownerId: target.ownerId },
924
+ ...target.manualKey && target.manualKey !== target.key ? [{ key: target.manualKey, ownerId: target.ownerId }] : []
925
+ ]);
924
926
  }
925
927
  function labelNumberMap(document2) {
926
928
  const map = /* @__PURE__ */ new Map();
927
- for (const entry of collectDocumentLabels(document2)) {
928
- if (!map.has(entry.key)) {
929
- map.set(entry.key, { kind: entry.kind, number: entry.number });
929
+ for (const target of collectDocumentReferenceTargets(document2)) {
930
+ if (target.number === null) continue;
931
+ for (const key of [target.key, target.manualKey]) {
932
+ if (key && !map.has(key)) map.set(key, { kind: target.kind, number: target.number });
930
933
  }
931
934
  }
932
935
  return map;
@@ -980,8 +983,12 @@ function stripDisplayMathDelimiters(source) {
980
983
  if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) {
981
984
  return trimmed.slice(2, -2).trim();
982
985
  }
983
- if (trimmed.startsWith("\\begin{equation}") && trimmed.endsWith("\\end{equation}")) {
984
- return trimmed.slice("\\begin{equation}".length, -"\\end{equation}".length).trim();
986
+ for (const environment of ["equation", "equation*"]) {
987
+ const opening = `\\begin{${environment}}`;
988
+ const closing = `\\end{${environment}}`;
989
+ if (trimmed.startsWith(opening) && trimmed.endsWith(closing)) {
990
+ return trimmed.slice(opening.length, -closing.length).trim();
991
+ }
985
992
  }
986
993
  return trimmed;
987
994
  }
@@ -1374,7 +1381,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
1374
1381
  editable: true,
1375
1382
  sourceOwner: structuredMathJson.source_owner === "editor" ? "editor" : "imported-structured",
1376
1383
  ...typeof structuredMathJson.label_enabled === "boolean" ? { labelEnabled: structuredMathJson.label_enabled } : {},
1377
- ...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {}
1384
+ ...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {},
1385
+ ...typeof structuredMathJson.numbered === "boolean" ? { numbered: structuredMathJson.numbered } : {}
1378
1386
  });
1379
1387
  } else {
1380
1388
  tokens.push({
@@ -1389,7 +1397,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
1389
1397
  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",
1390
1398
  sourceOwner: "raw",
1391
1399
  ...mathJson?.node_type === "RawMathObject" && typeof mathJson.label_enabled === "boolean" ? { labelEnabled: mathJson.label_enabled } : {},
1392
- ...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {}
1400
+ ...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {},
1401
+ ...mathJson?.node_type === "RawMathObject" && typeof mathJson.numbered === "boolean" ? { numbered: mathJson.numbered } : {}
1393
1402
  });
1394
1403
  }
1395
1404
  index = span.end;
@@ -5443,6 +5452,9 @@ function replaceMathTokenFromSession(document2, tokenId, session, opening, closi
5443
5452
  if (current.label !== void 0) {
5444
5453
  replaced.label = current.label;
5445
5454
  }
5455
+ if (current.numbered !== void 0) {
5456
+ replaced.numbered = current.numbered;
5457
+ }
5446
5458
  field.tokens[index] = replaced;
5447
5459
  return true;
5448
5460
  });
@@ -5667,6 +5679,9 @@ function updateMathTokenLabel(document2, tokenId, patch) {
5667
5679
  if (typeof patch.label === "string") {
5668
5680
  token.label = patch.label;
5669
5681
  }
5682
+ if (typeof patch.numbered === "boolean") {
5683
+ token.numbered = patch.numbered;
5684
+ }
5670
5685
  return true;
5671
5686
  });
5672
5687
  return next;
@@ -5975,7 +5990,7 @@ function normalizedNewFloatLabel(document2, label) {
5975
5990
  if (!normalized) return "";
5976
5991
  const error = documentKeyError(normalized, {
5977
5992
  references: document2.references,
5978
- labels: collectDocumentLabels(document2)
5993
+ labels: collectDocumentKeyLabels(document2)
5979
5994
  });
5980
5995
  if (error === "duplicate") {
5981
5996
  throw new DocumentCommandError("duplicate_key", "Float label is already in use");
@@ -6419,7 +6434,7 @@ function validateReferenceKey(document2, key, excludeReferenceId) {
6419
6434
  const normalized = normalizeDocumentKey(key);
6420
6435
  const error = documentKeyError(normalized, {
6421
6436
  references: document2.references,
6422
- labels: collectDocumentLabels(document2),
6437
+ labels: collectDocumentKeyLabels(document2),
6423
6438
  ...excludeReferenceId ? { excludeReferenceId } : {}
6424
6439
  });
6425
6440
  if (error === "duplicate") {
@@ -6641,6 +6656,17 @@ function parseToken(value) {
6641
6656
  throw new DocumentCommandError("invalid_inline_token", "Unsupported inline token kind");
6642
6657
  }
6643
6658
  function parseInlineCommand(value) {
6659
+ if (value.op === "set_equation_numbering") {
6660
+ if (typeof value.numbered !== "boolean") {
6661
+ throw new DocumentCommandError("invalid_command", "numbered must be boolean");
6662
+ }
6663
+ return {
6664
+ op: "set_equation_numbering",
6665
+ field_id: requireString2(value.field_id, "field_id", false).trim(),
6666
+ token_id: requireString2(value.token_id, "token_id", false).trim(),
6667
+ numbered: value.numbered
6668
+ };
6669
+ }
6644
6670
  if (value.op === "insert_inline_token") {
6645
6671
  return {
6646
6672
  op: value.op,
@@ -6694,7 +6720,8 @@ function liveToken(input, id) {
6694
6720
  editable: true,
6695
6721
  sourceOwner: mathObject.source_owner === "editor" ? "editor" : "imported-structured",
6696
6722
  ...mathObject.label_enabled !== void 0 ? { labelEnabled: mathObject.label_enabled } : {},
6697
- ...mathObject.label !== void 0 ? { label: mathObject.label } : {}
6723
+ ...mathObject.label !== void 0 ? { label: mathObject.label } : {},
6724
+ ...mathObject.numbered !== void 0 ? { numbered: mathObject.numbered } : {}
6698
6725
  };
6699
6726
  }
6700
6727
  function insertionIndex(tokens, anchor) {
@@ -6716,6 +6743,17 @@ function applyInlineCommand(document2, command) {
6716
6743
  if (!field) {
6717
6744
  throw new DocumentCommandError("field_not_found", "Inline field was not found");
6718
6745
  }
6746
+ if (command.op === "set_equation_numbering") {
6747
+ const token = field.tokens.find((entry) => entry.id === command.token_id);
6748
+ if (!token || token.kind !== "math") {
6749
+ throw new DocumentCommandError("token_not_found", "Equation token was not found");
6750
+ }
6751
+ if (!supportsSingleEquationNumbering(token)) {
6752
+ throw new DocumentCommandError("invalid_inline_token", "Only a single display equation can be numbered");
6753
+ }
6754
+ token.numbered = command.numbered;
6755
+ return;
6756
+ }
6719
6757
  if (command.op === "insert_inline_token") {
6720
6758
  const index2 = insertionIndex(field.tokens, command.anchor);
6721
6759
  field.tokens.splice(index2, 0, liveToken(command.token, newTokenId(document2, command.token.kind)));
@@ -7068,12 +7106,13 @@ function serializeField(field) {
7068
7106
  }
7069
7107
  value += token.source;
7070
7108
  if (!token.math || token.sourceOwner === "raw") {
7071
- if (token.labelEnabled !== void 0 || token.label !== void 0) {
7109
+ if (token.labelEnabled !== void 0 || token.label !== void 0 || token.numbered !== void 0) {
7072
7110
  hasPersistedMath = true;
7073
7111
  mathObjects.push({
7074
7112
  node_type: "RawMathObject",
7075
7113
  ...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
7076
- ...token.label !== void 0 ? { label: token.label } : {}
7114
+ ...token.label !== void 0 ? { label: token.label } : {},
7115
+ ...token.numbered !== void 0 ? { numbered: token.numbered } : {}
7077
7116
  });
7078
7117
  } else {
7079
7118
  mathObjects.push(null);
@@ -7086,7 +7125,8 @@ function serializeField(field) {
7086
7125
  ...token.sourceSide ? { source_side: token.sourceSide } : {},
7087
7126
  source_owner: token.sourceOwner,
7088
7127
  ...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
7089
- ...token.label !== void 0 ? { label: token.label } : {}
7128
+ ...token.label !== void 0 ? { label: token.label } : {},
7129
+ ...token.numbered !== void 0 ? { numbered: token.numbered } : {}
7090
7130
  });
7091
7131
  }
7092
7132
  return { value, formats, mathObjects, hasPersistedMath, inlineIds: inlineIdsFromField(field) };
@@ -7219,7 +7259,7 @@ function toDocumentJson(document2) {
7219
7259
 
7220
7260
  // src/document/jsonCommands.ts
7221
7261
  function isInlineCommand(command) {
7222
- return command.op === "insert_inline_token" || command.op === "replace_inline_token" || command.op === "remove_inline_token";
7262
+ return command.op === "insert_inline_token" || command.op === "replace_inline_token" || command.op === "remove_inline_token" || command.op === "set_equation_numbering";
7223
7263
  }
7224
7264
  function isListCommand(command) {
7225
7265
  return command.op === "insert_list" || command.op === "insert_list_item" || command.op === "replace_list_item" || command.op === "remove_list_item" || command.op === "move_list_item";
@@ -7334,7 +7374,7 @@ function parseCommand2(value) {
7334
7374
  if (!isObject3(value) || typeof value.op !== "string") {
7335
7375
  throw new DocumentCommandError("invalid_command", "command requires an op");
7336
7376
  }
7337
- if (value.op === "insert_inline_token" || value.op === "replace_inline_token" || value.op === "remove_inline_token") {
7377
+ if (value.op === "insert_inline_token" || value.op === "replace_inline_token" || value.op === "remove_inline_token" || value.op === "set_equation_numbering") {
7338
7378
  return parseInlineCommand(value);
7339
7379
  }
7340
7380
  if (value.op === "insert_list" || value.op === "insert_list_item" || value.op === "replace_list_item" || value.op === "remove_list_item" || value.op === "move_list_item") {
@@ -7468,7 +7508,7 @@ function applyBasicCommand(document2, command) {
7468
7508
  if (label2 !== void 0 && label2.length > 0) {
7469
7509
  const keyError = documentKeyError(label2, {
7470
7510
  references: document2.references,
7471
- labels: collectDocumentLabels(document2),
7511
+ labels: collectDocumentKeyLabels(document2),
7472
7512
  excludeOwnerId: block2.id
7473
7513
  });
7474
7514
  if (keyError === "duplicate") {
@@ -7723,7 +7763,7 @@ function getDocumentReferences(document2) {
7723
7763
  function getDocumentReferenceIndex(document2) {
7724
7764
  const referenceKeys = new Set(document2.references.map((reference) => reference.key));
7725
7765
  const labelEntries = collectDocumentLabels(document2);
7726
- const labelKeys = new Set(labelEntries.map((entry) => entry.key));
7766
+ const labelKeys = new Set(labelNumberMap(document2).keys());
7727
7767
  const citations = [];
7728
7768
  const crossReferences = [];
7729
7769
  const tokenLocations = /* @__PURE__ */ new Map();
@@ -7806,6 +7846,14 @@ function getDocumentReferenceIndex(document2) {
7806
7846
  citations,
7807
7847
  cross_references: crossReferences,
7808
7848
  labels,
7849
+ reference_targets: collectDocumentReferenceTargets(document2).map((target) => ({
7850
+ key: target.key,
7851
+ kind: target.kind,
7852
+ caption: target.caption,
7853
+ number: target.number,
7854
+ ...target.kind === "eq" ? { token_id: target.ownerId } : { block_id: target.ownerId },
7855
+ ...target.manualKey ? { manual_key: target.manualKey } : {}
7856
+ })),
7809
7857
  unresolved: {
7810
7858
  citation_keys: unresolvedCitationKeys,
7811
7859
  cross_reference_keys: unresolvedCrossReferenceKeys
@@ -8120,12 +8168,15 @@ function tokenLatex(token, labelKinds, previousToken) {
8120
8168
  if (token.kind === "ref") {
8121
8169
  return refTokenLatexForDocument(token, labelKinds, previousToken);
8122
8170
  }
8123
- if (token.display && token.labelEnabled && token.label && token.label.trim().length > 0) {
8171
+ if (isNumberedEquation(token)) {
8124
8172
  const body = mathBodyLatex(token);
8125
- return `\\begin{equation}
8126
- ${body}
8127
- \\label{${token.label.trim()}}
8128
- \\end{equation}`;
8173
+ const autoKey = implicitReferenceKey("eq", token.id);
8174
+ const aliases = [autoKey];
8175
+ if (token.labelEnabled && token.label?.trim() && token.label.trim() !== autoKey) aliases.push(token.label.trim());
8176
+ return "\\begin{equation}\n" + body + "\n" + aliases.map((key) => "\\label{" + key + "}").join("\n") + "\n\\end{equation}";
8177
+ }
8178
+ if (token.display && token.numbered === false && token.opening === "\\begin{equation}") {
8179
+ return "\\[" + mathBodyLatex(token) + "\\]";
8129
8180
  }
8130
8181
  if (token.sourceOwner === "editor") {
8131
8182
  return editorMathLatexForCompile(token);
@@ -8195,11 +8246,12 @@ function floatCaptionLabelLines(block, counter, labelKinds) {
8195
8246
  if (hasCaption) {
8196
8247
  lines.push(` \\caption{${caption}}`);
8197
8248
  }
8198
- if (block.labelEnabled && block.label.trim().length > 0) {
8199
- if (!hasCaption) {
8200
- lines.push(` \\refstepcounter{${counter}}`);
8201
- }
8202
- lines.push(` \\label{${block.label.trim()}}`);
8249
+ const hasManualLabel = block.labelEnabled && block.label.trim().length > 0;
8250
+ if (hasCaption || hasManualLabel) {
8251
+ if (!hasCaption) lines.push(" \\refstepcounter{" + counter + "}");
8252
+ const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id);
8253
+ lines.push(" \\label{" + autoKey + "}");
8254
+ if (hasManualLabel && block.label.trim() !== autoKey) lines.push(" \\label{" + block.label.trim() + "}");
8203
8255
  }
8204
8256
  return lines;
8205
8257
  }
@@ -8295,10 +8347,8 @@ ${meta.abstract.trim()}
8295
8347
  }
8296
8348
  function documentLabelKindMap(document2) {
8297
8349
  const map = /* @__PURE__ */ new Map();
8298
- for (const entry of collectDocumentLabels(document2)) {
8299
- if (!map.has(entry.key)) {
8300
- map.set(entry.key, entry.kind);
8301
- }
8350
+ for (const [key, entry] of labelNumberMap(document2)) {
8351
+ map.set(key, entry.kind);
8302
8352
  }
8303
8353
  return map;
8304
8354
  }
@@ -8397,10 +8447,17 @@ function validateToken(context, token, path, blockId) {
8397
8447
  return;
8398
8448
  }
8399
8449
  validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
8450
+ if (token.numbered === true && !supportsSingleEquationNumbering(token)) {
8451
+ addIssue(context, "invalid_equation_label", `${path}.numbered`, blockId, token.id);
8452
+ }
8400
8453
  if (!token.labelEnabled) {
8401
8454
  return;
8402
8455
  }
8403
- if (!token.display) {
8456
+ if (!supportsSingleEquationNumbering(token)) {
8457
+ addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
8458
+ return;
8459
+ }
8460
+ if (!isNumberedEquation(token)) {
8404
8461
  addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
8405
8462
  return;
8406
8463
  }
@@ -8498,7 +8555,7 @@ function validatePendingReferences(context) {
8498
8555
  for (const pending of context.pendingReferences) {
8499
8556
  for (const key of pending.token.keys) {
8500
8557
  const normalized = normalizeDocumentKey(key);
8501
- if (!isValidDocumentKey(normalized)) {
8558
+ if (!isValidDocumentKey(normalized) || !context.labelKinds.has(normalized)) {
8502
8559
  addIssue(
8503
8560
  context,
8504
8561
  "missing_reference",
@@ -8597,6 +8654,18 @@ function validateDocument(document2) {
8597
8654
  resolved.blocks.forEach((block, index) => {
8598
8655
  validateBlock(context, block, `$.blocks[${String(index)}]`);
8599
8656
  });
8657
+ for (const target of collectDocumentReferenceTargets(resolved)) {
8658
+ if (target.number !== null && target.manualKey !== target.key) {
8659
+ registerKey(
8660
+ context,
8661
+ target.key,
8662
+ "$.automatic_labels",
8663
+ target.kind,
8664
+ target.kind === "eq" ? void 0 : target.ownerId,
8665
+ target.kind === "eq" ? target.ownerId : void 0
8666
+ );
8667
+ }
8668
+ }
8600
8669
  for (const diagnostic of resolved.diagnostics) {
8601
8670
  addIssue(context, "parser_diagnostic", diagnostic.path);
8602
8671
  }
@@ -8745,6 +8814,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
8745
8814
  })
8746
8815
  };
8747
8816
  }
8817
+ const number = collectDocumentReferenceTargets(document2).find((target) => target.kind === "eq" && target.ownerId === token.id)?.number;
8748
8818
  const island = {
8749
8819
  id: token.id,
8750
8820
  tex: mathTex(token, equationSide, previewOptions.digitForm),
@@ -8752,8 +8822,12 @@ function previewInlines(field, islands, output, equationSide, document2, preview
8752
8822
  output,
8753
8823
  editable: token.editable
8754
8824
  };
8825
+ const numberLabel = number == null ? void 0 : formatBibliographyNumber(number, {
8826
+ documentDirection: previewOptions.documentDirection,
8827
+ digitForm: previewOptions.digitForm
8828
+ });
8755
8829
  islands.push(island);
8756
- return { kind: "math", ...island };
8830
+ return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
8757
8831
  });
8758
8832
  }
8759
8833
  function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
@@ -8776,12 +8850,9 @@ function textBlockPreview(block, islands, output, equationSide, document2, previ
8776
8850
  ...block.centered ? { centered: true } : {}
8777
8851
  };
8778
8852
  }
8779
- function floatNumberLabel(document2, key, previewOptions) {
8780
- if (!key || key.trim().length === 0) {
8781
- return void 0;
8782
- }
8783
- const hit = labelNumberMap(document2).get(key.trim());
8784
- if (!hit || hit.kind !== "fig" && hit.kind !== "tab") {
8853
+ function floatNumberLabel(document2, ownerId, previewOptions) {
8854
+ const hit = collectDocumentReferenceTargets(document2).find((target) => target.ownerId === ownerId);
8855
+ if (!hit || hit.number === null || hit.kind !== "fig" && hit.kind !== "tab") {
8785
8856
  return void 0;
8786
8857
  }
8787
8858
  return formatFloatCaptionTitle(hit.kind, hit.number, {
@@ -8823,7 +8894,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
8823
8894
  id: block.id,
8824
8895
  rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
8825
8896
  ...captionPreview(block, islands, output, equationSide, document2, previewOptions),
8826
- ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
8897
+ ...label.length > 0 ? { label } : {},
8898
+ ...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
8827
8899
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
8828
8900
  };
8829
8901
  }
@@ -8837,7 +8909,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
8837
8909
  options: block.options,
8838
8910
  centered: block.centered,
8839
8911
  ...captionPreview(block, islands, output, equationSide, document2, previewOptions),
8840
- ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
8912
+ ...label.length > 0 ? { label } : {},
8913
+ ...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
8841
8914
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
8842
8915
  };
8843
8916
  }
@@ -8952,7 +9025,9 @@ export {
8952
9025
  clearDocumentImageAsset,
8953
9026
  cloneDocumentMeta,
8954
9027
  cloneDocumentNode,
9028
+ collectDocumentKeyLabels,
8955
9029
  collectDocumentLabels,
9030
+ collectDocumentReferenceTargets,
8956
9031
  createDocumentHistory,
8957
9032
  createEmptyArabicEquationSession,
8958
9033
  createEmptyDocument,
@@ -8990,6 +9065,7 @@ export {
8990
9065
  getDocumentReferences,
8991
9066
  hasXeLatexUnsupportedEmoji,
8992
9067
  hijriMonthLabel,
9068
+ implicitReferenceKey,
8993
9069
  inlineFieldLatex,
8994
9070
  insertCiteTokenAtCaret,
8995
9071
  insertDocumentBlockAfter,
@@ -8998,6 +9074,8 @@ export {
8998
9074
  insertRefTokenAtCaret,
8999
9075
  isDocumentValid,
9000
9076
  isDuplicateDocumentKey,
9077
+ isNumberedEquation,
9078
+ isNumberedFloat,
9001
9079
  isValidDocumentKey,
9002
9080
  labelNumberMap,
9003
9081
  mathNodeFromArabicSession,