@drghaliasri/butex 8.2.1 → 8.3.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.
@@ -4642,17 +4642,31 @@ function previewInlines(field, islands, output, equationSide, document2, preview
4642
4642
  return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
4643
4643
  });
4644
4644
  }
4645
- function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
4645
+ function nextHeadingNumber(block, counters, options) {
4646
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
4647
+ counters[level - 1] += 1;
4648
+ for (let index = level; index < counters.length; index += 1) counters[index] = 0;
4649
+ const kind = block.command.slice(1);
4650
+ const projected = options.mode === "book-content" ? options.bookContext?.targets?.find((target) => target.unitId === options.bookContext?.unitId && target.ownerId === block.id && target.kind === kind) : void 0;
4651
+ if (projected?.ordinal) return projected.ordinal;
4652
+ return counters.slice(0, level).map((number) => formatBibliographyNumber(number, {
4653
+ documentDirection: options.documentDirection,
4654
+ digitForm: options.digitForm
4655
+ })).join(".");
4656
+ }
4657
+ function textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
4646
4658
  const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
4647
4659
  const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
4648
- if (block.command === "\\section") {
4649
- return { kind: "heading", id: block.id, level: 1, inlines, ...metadata };
4650
- }
4651
- if (block.command === "\\subsection") {
4652
- return { kind: "heading", id: block.id, level: 2, inlines, ...metadata };
4653
- }
4654
- if (block.command === "\\subsubsection") {
4655
- return { kind: "heading", id: block.id, level: 3, inlines, ...metadata };
4660
+ if (block.command === "\\section" || block.command === "\\subsection" || block.command === "\\subsubsection") {
4661
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
4662
+ return {
4663
+ kind: "heading",
4664
+ id: block.id,
4665
+ level,
4666
+ inlines,
4667
+ numberLabel: nextHeadingNumber(block, headingCounters, previewOptions),
4668
+ ...metadata
4669
+ };
4656
4670
  }
4657
4671
  return {
4658
4672
  kind: "paragraph",
@@ -4684,9 +4698,9 @@ function captionPreview(block, islands, output, equationSide, document2, preview
4684
4698
  captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
4685
4699
  };
4686
4700
  }
4687
- function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
4701
+ function blockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
4688
4702
  if (block.kind === "textBlock") {
4689
- return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
4703
+ return textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters);
4690
4704
  }
4691
4705
  if (block.kind === "list") {
4692
4706
  return {
@@ -4696,7 +4710,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
4696
4710
  items: block.items.map((item) => ({
4697
4711
  id: item.id,
4698
4712
  inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
4699
- blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
4713
+ blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions, headingCounters))
4700
4714
  })),
4701
4715
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
4702
4716
  };
@@ -4782,7 +4796,8 @@ function documentPreview(document2, output = "svg", equationSide = "arabic", pre
4782
4796
  mode: previewOptions.mode ?? "article",
4783
4797
  bookContext: previewOptions.bookContext
4784
4798
  };
4785
- const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
4799
+ const headingCounters = [0, 0, 0];
4800
+ const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options, headingCounters));
4786
4801
  return {
4787
4802
  blocks: [
4788
4803
  ...options.mode === "book-content" ? [] : articleChromePreview(document2, options.uiLocale ?? "ar", options),
@@ -5725,6 +5740,12 @@ var DOCUMENT_WIDGET_CSS = `
5725
5740
  word-break: break-word;
5726
5741
  }
5727
5742
 
5743
+ .butex-document-widget__preview-heading-number {
5744
+ display: inline-block;
5745
+ margin-inline-end: 0.6em;
5746
+ font-variant-numeric: tabular-nums;
5747
+ }
5748
+
5728
5749
  .butex-document-widget__preview h1 {
5729
5750
  font-size: 1.75rem;
5730
5751
  font-weight: 700;
@@ -7879,7 +7900,10 @@ function PreviewBlock({
7879
7900
  }
7880
7901
  if (block.kind === "heading") {
7881
7902
  const Tag = block.level === 1 ? "h1" : block.level === 2 ? "h2" : "h3";
7882
- return /* @__PURE__ */ jsx2(Tag, { "data-butex-block-source": source, children: /* @__PURE__ */ jsx2(PreviewInlines, { inlines: block.inlines, output }) });
7903
+ return /* @__PURE__ */ jsxs(Tag, { "data-butex-block-source": source, children: [
7904
+ block.numberLabel ? /* @__PURE__ */ jsx2("span", { className: "butex-document-widget__preview-heading-number", dir: "auto", children: block.numberLabel }) : null,
7905
+ /* @__PURE__ */ jsx2(PreviewInlines, { inlines: block.inlines, output })
7906
+ ] });
7883
7907
  }
7884
7908
  if (block.kind === "paragraph") {
7885
7909
  return /* @__PURE__ */ jsx2("p", { "data-butex-block-source": source, className: block.centered ? "butex-document-widget__preview-paragraph--centered" : void 0, children: /* @__PURE__ */ jsx2(PreviewInlines, { inlines: block.inlines, output }) });