@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.
package/dist/document.mjs CHANGED
@@ -8985,17 +8985,31 @@ function previewInlines(field, islands, output, equationSide, document2, preview
8985
8985
  return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
8986
8986
  });
8987
8987
  }
8988
- function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
8988
+ function nextHeadingNumber(block, counters, options) {
8989
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
8990
+ counters[level - 1] += 1;
8991
+ for (let index = level; index < counters.length; index += 1) counters[index] = 0;
8992
+ const kind = block.command.slice(1);
8993
+ 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;
8994
+ if (projected?.ordinal) return projected.ordinal;
8995
+ return counters.slice(0, level).map((number) => formatBibliographyNumber(number, {
8996
+ documentDirection: options.documentDirection,
8997
+ digitForm: options.digitForm
8998
+ })).join(".");
8999
+ }
9000
+ function textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
8989
9001
  const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
8990
9002
  const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
8991
- if (block.command === "\\section") {
8992
- return { kind: "heading", id: block.id, level: 1, inlines, ...metadata };
8993
- }
8994
- if (block.command === "\\subsection") {
8995
- return { kind: "heading", id: block.id, level: 2, inlines, ...metadata };
8996
- }
8997
- if (block.command === "\\subsubsection") {
8998
- return { kind: "heading", id: block.id, level: 3, inlines, ...metadata };
9003
+ if (block.command === "\\section" || block.command === "\\subsection" || block.command === "\\subsubsection") {
9004
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
9005
+ return {
9006
+ kind: "heading",
9007
+ id: block.id,
9008
+ level,
9009
+ inlines,
9010
+ numberLabel: nextHeadingNumber(block, headingCounters, previewOptions),
9011
+ ...metadata
9012
+ };
8999
9013
  }
9000
9014
  return {
9001
9015
  kind: "paragraph",
@@ -9027,9 +9041,9 @@ function captionPreview(block, islands, output, equationSide, document2, preview
9027
9041
  captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
9028
9042
  };
9029
9043
  }
9030
- function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
9044
+ function blockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
9031
9045
  if (block.kind === "textBlock") {
9032
- return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
9046
+ return textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters);
9033
9047
  }
9034
9048
  if (block.kind === "list") {
9035
9049
  return {
@@ -9039,7 +9053,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9039
9053
  items: block.items.map((item) => ({
9040
9054
  id: item.id,
9041
9055
  inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
9042
- blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
9056
+ blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions, headingCounters))
9043
9057
  })),
9044
9058
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
9045
9059
  };
@@ -9125,7 +9139,8 @@ function documentPreview(document2, output = "svg", equationSide = "arabic", pre
9125
9139
  mode: previewOptions.mode ?? "article",
9126
9140
  bookContext: previewOptions.bookContext
9127
9141
  };
9128
- const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
9142
+ const headingCounters = [0, 0, 0];
9143
+ const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options, headingCounters));
9129
9144
  return {
9130
9145
  blocks: [
9131
9146
  ...options.mode === "book-content" ? [] : articleChromePreview(document2, options.uiLocale ?? "ar", options),