@drghaliasri/butex 8.2.0 → 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.
@@ -4671,17 +4671,31 @@ function previewInlines(field, islands, output, equationSide, document2, preview
4671
4671
  return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
4672
4672
  });
4673
4673
  }
4674
- function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
4674
+ function nextHeadingNumber(block, counters, options) {
4675
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
4676
+ counters[level - 1] += 1;
4677
+ for (let index = level; index < counters.length; index += 1) counters[index] = 0;
4678
+ const kind = block.command.slice(1);
4679
+ 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;
4680
+ if (projected?.ordinal) return projected.ordinal;
4681
+ return counters.slice(0, level).map((number) => formatBibliographyNumber(number, {
4682
+ documentDirection: options.documentDirection,
4683
+ digitForm: options.digitForm
4684
+ })).join(".");
4685
+ }
4686
+ function textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
4675
4687
  const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
4676
4688
  const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
4677
- if (block.command === "\\section") {
4678
- return { kind: "heading", id: block.id, level: 1, inlines, ...metadata };
4679
- }
4680
- if (block.command === "\\subsection") {
4681
- return { kind: "heading", id: block.id, level: 2, inlines, ...metadata };
4682
- }
4683
- if (block.command === "\\subsubsection") {
4684
- return { kind: "heading", id: block.id, level: 3, inlines, ...metadata };
4689
+ if (block.command === "\\section" || block.command === "\\subsection" || block.command === "\\subsubsection") {
4690
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
4691
+ return {
4692
+ kind: "heading",
4693
+ id: block.id,
4694
+ level,
4695
+ inlines,
4696
+ numberLabel: nextHeadingNumber(block, headingCounters, previewOptions),
4697
+ ...metadata
4698
+ };
4685
4699
  }
4686
4700
  return {
4687
4701
  kind: "paragraph",
@@ -4713,9 +4727,9 @@ function captionPreview(block, islands, output, equationSide, document2, preview
4713
4727
  captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
4714
4728
  };
4715
4729
  }
4716
- function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
4730
+ function blockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
4717
4731
  if (block.kind === "textBlock") {
4718
- return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
4732
+ return textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters);
4719
4733
  }
4720
4734
  if (block.kind === "list") {
4721
4735
  return {
@@ -4725,7 +4739,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
4725
4739
  items: block.items.map((item) => ({
4726
4740
  id: item.id,
4727
4741
  inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
4728
- blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
4742
+ blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions, headingCounters))
4729
4743
  })),
4730
4744
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
4731
4745
  };
@@ -4811,7 +4825,8 @@ function documentPreview(document2, output = "svg", equationSide = "arabic", pre
4811
4825
  mode: previewOptions.mode ?? "article",
4812
4826
  bookContext: previewOptions.bookContext
4813
4827
  };
4814
- const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
4828
+ const headingCounters = [0, 0, 0];
4829
+ const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options, headingCounters));
4815
4830
  return {
4816
4831
  blocks: [
4817
4832
  ...options.mode === "book-content" ? [] : articleChromePreview(document2, options.uiLocale ?? "ar", options),
@@ -5754,6 +5769,12 @@ var DOCUMENT_WIDGET_CSS = `
5754
5769
  word-break: break-word;
5755
5770
  }
5756
5771
 
5772
+ .butex-document-widget__preview-heading-number {
5773
+ display: inline-block;
5774
+ margin-inline-end: 0.6em;
5775
+ font-variant-numeric: tabular-nums;
5776
+ }
5777
+
5757
5778
  .butex-document-widget__preview h1 {
5758
5779
  font-size: 1.75rem;
5759
5780
  font-weight: 700;
@@ -7908,7 +7929,10 @@ function PreviewBlock({
7908
7929
  }
7909
7930
  if (block.kind === "heading") {
7910
7931
  const Tag = block.level === 1 ? "h1" : block.level === 2 ? "h2" : "h3";
7911
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Tag, { "data-butex-block-source": source, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
7932
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Tag, { "data-butex-block-source": source, children: [
7933
+ block.numberLabel ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "butex-document-widget__preview-heading-number", dir: "auto", children: block.numberLabel }) : null,
7934
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PreviewInlines, { inlines: block.inlines, output })
7935
+ ] });
7912
7936
  }
7913
7937
  if (block.kind === "paragraph") {
7914
7938
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { "data-butex-block-source": source, className: block.centered ? "butex-document-widget__preview-paragraph--centered" : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PreviewInlines, { inlines: block.inlines, output }) });