@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.
@@ -470,6 +470,7 @@ type PreviewBlock2 = {
470
470
  id: string;
471
471
  level: 1 | 2 | 3;
472
472
  inlines: PreviewInline2[];
473
+ numberLabel?: string;
473
474
  metadata?: DocumentBlockMetadata;
474
475
  } | {
475
476
  kind: 'paragraph';
@@ -470,6 +470,7 @@ type PreviewBlock2 = {
470
470
  id: string;
471
471
  level: 1 | 2 | 3;
472
472
  inlines: PreviewInline2[];
473
+ numberLabel?: string;
473
474
  metadata?: DocumentBlockMetadata;
474
475
  } | {
475
476
  kind: 'paragraph';
package/dist/document.js CHANGED
@@ -9160,17 +9160,31 @@ function previewInlines(field, islands, output, equationSide, document2, preview
9160
9160
  return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
9161
9161
  });
9162
9162
  }
9163
- function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
9163
+ function nextHeadingNumber(block, counters, options) {
9164
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
9165
+ counters[level - 1] += 1;
9166
+ for (let index = level; index < counters.length; index += 1) counters[index] = 0;
9167
+ const kind = block.command.slice(1);
9168
+ 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;
9169
+ if (projected?.ordinal) return projected.ordinal;
9170
+ return counters.slice(0, level).map((number) => formatBibliographyNumber(number, {
9171
+ documentDirection: options.documentDirection,
9172
+ digitForm: options.digitForm
9173
+ })).join(".");
9174
+ }
9175
+ function textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
9164
9176
  const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
9165
9177
  const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
9166
- if (block.command === "\\section") {
9167
- return { kind: "heading", id: block.id, level: 1, inlines, ...metadata };
9168
- }
9169
- if (block.command === "\\subsection") {
9170
- return { kind: "heading", id: block.id, level: 2, inlines, ...metadata };
9171
- }
9172
- if (block.command === "\\subsubsection") {
9173
- return { kind: "heading", id: block.id, level: 3, inlines, ...metadata };
9178
+ if (block.command === "\\section" || block.command === "\\subsection" || block.command === "\\subsubsection") {
9179
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
9180
+ return {
9181
+ kind: "heading",
9182
+ id: block.id,
9183
+ level,
9184
+ inlines,
9185
+ numberLabel: nextHeadingNumber(block, headingCounters, previewOptions),
9186
+ ...metadata
9187
+ };
9174
9188
  }
9175
9189
  return {
9176
9190
  kind: "paragraph",
@@ -9202,9 +9216,9 @@ function captionPreview(block, islands, output, equationSide, document2, preview
9202
9216
  captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
9203
9217
  };
9204
9218
  }
9205
- function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
9219
+ function blockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
9206
9220
  if (block.kind === "textBlock") {
9207
- return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
9221
+ return textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters);
9208
9222
  }
9209
9223
  if (block.kind === "list") {
9210
9224
  return {
@@ -9214,7 +9228,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9214
9228
  items: block.items.map((item) => ({
9215
9229
  id: item.id,
9216
9230
  inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
9217
- blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
9231
+ blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions, headingCounters))
9218
9232
  })),
9219
9233
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
9220
9234
  };
@@ -9300,7 +9314,8 @@ function documentPreview(document2, output = "svg", equationSide = "arabic", pre
9300
9314
  mode: previewOptions.mode ?? "article",
9301
9315
  bookContext: previewOptions.bookContext
9302
9316
  };
9303
- const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
9317
+ const headingCounters = [0, 0, 0];
9318
+ const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options, headingCounters));
9304
9319
  return {
9305
9320
  blocks: [
9306
9321
  ...options.mode === "book-content" ? [] : articleChromePreview(document2, options.uiLocale ?? "ar", options),