@drghaliasri/butex 8.1.0 → 8.1.1

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.
@@ -638,11 +638,17 @@ function refTokenLatex(keys, refCommand) {
638
638
  const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
639
639
  return `${command}{${keys.join(",")}}`;
640
640
  }
641
- function implicitReferenceKey(kind, ownerId, unitId) {
641
+ function implicitObjectKey(kind, ownerId, unitId) {
642
642
  const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
643
643
  const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
644
644
  return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
645
645
  }
646
+ function implicitReferenceKey(kind, ownerId, unitId) {
647
+ return implicitObjectKey(kind, ownerId, unitId);
648
+ }
649
+ function implicitHeadingReferenceKey(kind, ownerId, unitId) {
650
+ return implicitObjectKey(kind, ownerId, unitId);
651
+ }
646
652
  function supportsSingleEquationNumbering(token) {
647
653
  return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
648
654
  }
@@ -1223,6 +1229,7 @@ function parseTextBlock(json, options, path, diagnostics, identities) {
1223
1229
  identities
1224
1230
  ),
1225
1231
  ...metadataFromJson(json.metadata),
1232
+ ...typeof json.label === "string" && json.command !== "\\paragraph" ? { label: json.label } : {},
1226
1233
  ...json.centered === true ? { centered: true } : {}
1227
1234
  };
1228
1235
  }
@@ -1402,6 +1409,33 @@ function createEmptyDocument() {
1402
1409
  };
1403
1410
  }
1404
1411
 
1412
+ // src/document/bookContent.ts
1413
+ function bookContextReferences(context) {
1414
+ return (context?.references ?? []).map((entry, index) => ({
1415
+ ...referenceFromJson(entry),
1416
+ id: "book-ref-" + String(index)
1417
+ }));
1418
+ }
1419
+ function formatBookReferenceLabel(keys, document2, command, context, options = {}) {
1420
+ const targets = context.targets ?? [];
1421
+ return keys.map((key) => {
1422
+ const target = targets.find((entry) => entry.key === key || entry.manualKey === key);
1423
+ if (target?.displayLabel) return target.displayLabel;
1424
+ const local = collectDocumentReferenceTargets(document2).find((entry) => entry.manualKey === key || implicitReferenceKey(entry.kind, entry.ownerId, context.unitId) === key);
1425
+ if (local) return formatRefLabel([local.manualKey || local.key], document2, command, options);
1426
+ const heading = document2.blocks.find((block) => block.kind === "textBlock" && block.command !== "\\paragraph" && (block.label === key || implicitHeadingReferenceKey(
1427
+ block.command.slice(1),
1428
+ block.id,
1429
+ context.unitId
1430
+ ) === key));
1431
+ if (heading?.kind === "textBlock") {
1432
+ const caption = heading.field.tokens.filter((token) => token.kind === "text").map((token) => token.text).join("").trim();
1433
+ return caption || heading.command.slice(1);
1434
+ }
1435
+ return command === "eqref" ? "(?)" : "?";
1436
+ }).join(options.documentDirection === "ltr" ? ", " : "\u060C");
1437
+ }
1438
+
1405
1439
  // src/editor/accentCommands.ts
1406
1440
  var ACCENT_COMMANDS = {
1407
1441
  vec: {
@@ -4565,7 +4599,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
4565
4599
  kind: "cite",
4566
4600
  id: token.id,
4567
4601
  keys: [...token.keys],
4568
- label: formatCiteLabel(token.keys, document2.references, {
4602
+ label: formatCiteLabel(token.keys, previewOptions.mode === "book-content" ? bookContextReferences(previewOptions.bookContext) : document2.references, {
4569
4603
  documentDirection: previewOptions.documentDirection,
4570
4604
  digitForm: previewOptions.digitForm
4571
4605
  })
@@ -4577,7 +4611,10 @@ function previewInlines(field, islands, output, equationSide, document2, preview
4577
4611
  id: token.id,
4578
4612
  keys: [...token.keys],
4579
4613
  refCommand: token.refCommand,
4580
- label: formatRefLabel(token.keys, document2, token.refCommand, {
4614
+ label: previewOptions.mode === "book-content" && previewOptions.bookContext ? formatBookReferenceLabel(token.keys, document2, token.refCommand, previewOptions.bookContext, {
4615
+ documentDirection: previewOptions.documentDirection,
4616
+ digitForm: previewOptions.digitForm
4617
+ }) : formatRefLabel(token.keys, document2, token.refCommand, {
4581
4618
  documentDirection: previewOptions.documentDirection,
4582
4619
  digitForm: previewOptions.digitForm
4583
4620
  })
@@ -4733,14 +4770,16 @@ function documentPreview(document2, output = "svg", equationSide = "arabic", pre
4733
4770
  const options = {
4734
4771
  documentDirection: previewOptions.documentDirection ?? "rtl",
4735
4772
  digitForm: previewOptions.digitForm ?? (previewOptions.documentDirection === "ltr" ? "western" : "arabicIndic"),
4736
- uiLocale: previewOptions.uiLocale ?? "ar"
4773
+ uiLocale: previewOptions.uiLocale ?? "ar",
4774
+ mode: previewOptions.mode ?? "article",
4775
+ bookContext: previewOptions.bookContext
4737
4776
  };
4738
- const body = document2.blocks.map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
4777
+ const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
4739
4778
  return {
4740
4779
  blocks: [
4741
- ...articleChromePreview(document2, options.uiLocale ?? "ar", options),
4780
+ ...options.mode === "book-content" ? [] : articleChromePreview(document2, options.uiLocale ?? "ar", options),
4742
4781
  ...body,
4743
- { kind: "closing", id: "article-closing", text: BUTEX_CLOSING_HAMDALA, tex: butexMaghribiDisplayTex(BUTEX_CLOSING_HAMDALA) }
4782
+ ...options.mode === "book-content" ? [] : [{ kind: "closing", id: "article-closing", text: BUTEX_CLOSING_HAMDALA, tex: butexMaghribiDisplayTex(BUTEX_CLOSING_HAMDALA) }]
4744
4783
  ],
4745
4784
  mathIslands
4746
4785
  };
@@ -8063,6 +8102,8 @@ function resolvePreviewDocument(input, uiLocale = "ar") {
8063
8102
  }
8064
8103
  }
8065
8104
  function ButexDocumentPreview({
8105
+ mode = "article",
8106
+ bookContext,
8066
8107
  document: document2,
8067
8108
  className,
8068
8109
  documentDirection = "rtl",
@@ -8081,7 +8122,9 @@ function ButexDocumentPreview({
8081
8122
  preview: documentPreview(resolved.document, mathOutput, equationSide, {
8082
8123
  documentDirection,
8083
8124
  digitForm: resolvedDigitForm,
8084
- uiLocale
8125
+ uiLocale,
8126
+ mode,
8127
+ bookContext
8085
8128
  }),
8086
8129
  error: resolved.error
8087
8130
  };
@@ -8091,12 +8134,14 @@ function ButexDocumentPreview({
8091
8134
  preview: documentPreview(createEmptyDocument(), mathOutput, equationSide, {
8092
8135
  documentDirection,
8093
8136
  digitForm: resolvedDigitForm,
8094
- uiLocale
8137
+ uiLocale,
8138
+ mode,
8139
+ bookContext
8095
8140
  }),
8096
8141
  error: `${messages.loadDocumentError}: ${detail}`
8097
8142
  };
8098
8143
  }
8099
- }, [documentDirection, equationSide, mathOutput, messages.loadDocumentError, resolved, resolvedDigitForm, uiLocale]);
8144
+ }, [bookContext, mode, documentDirection, equationSide, mathOutput, messages.loadDocumentError, resolved, resolvedDigitForm, uiLocale]);
8100
8145
  useEffect2(() => {
8101
8146
  injectBuTeXDocumentStyles();
8102
8147
  }, []);