@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.
@@ -12226,17 +12226,31 @@ function previewInlines(field, islands, output, equationSide, document2, preview
12226
12226
  return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
12227
12227
  });
12228
12228
  }
12229
- function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
12229
+ function nextHeadingNumber(block, counters, options) {
12230
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
12231
+ counters[level - 1] += 1;
12232
+ for (let index = level; index < counters.length; index += 1) counters[index] = 0;
12233
+ const kind = block.command.slice(1);
12234
+ 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;
12235
+ if (projected?.ordinal) return projected.ordinal;
12236
+ return counters.slice(0, level).map((number) => formatBibliographyNumber(number, {
12237
+ documentDirection: options.documentDirection,
12238
+ digitForm: options.digitForm
12239
+ })).join(".");
12240
+ }
12241
+ function textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
12230
12242
  const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
12231
12243
  const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
12232
- if (block.command === "\\section") {
12233
- return { kind: "heading", id: block.id, level: 1, inlines, ...metadata };
12234
- }
12235
- if (block.command === "\\subsection") {
12236
- return { kind: "heading", id: block.id, level: 2, inlines, ...metadata };
12237
- }
12238
- if (block.command === "\\subsubsection") {
12239
- return { kind: "heading", id: block.id, level: 3, inlines, ...metadata };
12244
+ if (block.command === "\\section" || block.command === "\\subsection" || block.command === "\\subsubsection") {
12245
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
12246
+ return {
12247
+ kind: "heading",
12248
+ id: block.id,
12249
+ level,
12250
+ inlines,
12251
+ numberLabel: nextHeadingNumber(block, headingCounters, previewOptions),
12252
+ ...metadata
12253
+ };
12240
12254
  }
12241
12255
  return {
12242
12256
  kind: "paragraph",
@@ -12268,9 +12282,9 @@ function captionPreview(block, islands, output, equationSide, document2, preview
12268
12282
  captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
12269
12283
  };
12270
12284
  }
12271
- function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
12285
+ function blockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
12272
12286
  if (block.kind === "textBlock") {
12273
- return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
12287
+ return textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters);
12274
12288
  }
12275
12289
  if (block.kind === "list") {
12276
12290
  return {
@@ -12280,7 +12294,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
12280
12294
  items: block.items.map((item) => ({
12281
12295
  id: item.id,
12282
12296
  inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
12283
- blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
12297
+ blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions, headingCounters))
12284
12298
  })),
12285
12299
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
12286
12300
  };
@@ -12366,7 +12380,8 @@ function documentPreview(document2, output = "svg", equationSide = "arabic", pre
12366
12380
  mode: previewOptions.mode ?? "article",
12367
12381
  bookContext: previewOptions.bookContext
12368
12382
  };
12369
- const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
12383
+ const headingCounters = [0, 0, 0];
12384
+ const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options, headingCounters));
12370
12385
  return {
12371
12386
  blocks: [
12372
12387
  ...options.mode === "book-content" ? [] : articleChromePreview(document2, options.uiLocale ?? "ar", options),
@@ -15518,7 +15533,10 @@ function PreviewBlock({
15518
15533
  }
15519
15534
  if (block.kind === "heading") {
15520
15535
  const Tag = block.level === 1 ? "h1" : block.level === 2 ? "h2" : "h3";
15521
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Tag, { "data-butex-block-source": source, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
15536
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Tag, { "data-butex-block-source": source, children: [
15537
+ block.numberLabel ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "butex-document-widget__preview-heading-number", dir: "auto", children: block.numberLabel }) : null,
15538
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(PreviewInlines, { inlines: block.inlines, output })
15539
+ ] });
15522
15540
  }
15523
15541
  if (block.kind === "paragraph") {
15524
15542
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { "data-butex-block-source": source, className: block.centered ? "butex-document-widget__preview-paragraph--centered" : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
@@ -20983,6 +21001,12 @@ var DOCUMENT_WIDGET_CSS = `
20983
21001
  word-break: break-word;
20984
21002
  }
20985
21003
 
21004
+ .butex-document-widget__preview-heading-number {
21005
+ display: inline-block;
21006
+ margin-inline-end: 0.6em;
21007
+ font-variant-numeric: tabular-nums;
21008
+ }
21009
+
20986
21010
  .butex-document-widget__preview h1 {
20987
21011
  font-size: 1.75rem;
20988
21012
  font-weight: 700;