@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.
@@ -12200,17 +12200,31 @@ function previewInlines(field, islands, output, equationSide, document2, preview
12200
12200
  return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
12201
12201
  });
12202
12202
  }
12203
- function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
12203
+ function nextHeadingNumber(block, counters, options) {
12204
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
12205
+ counters[level - 1] += 1;
12206
+ for (let index = level; index < counters.length; index += 1) counters[index] = 0;
12207
+ const kind = block.command.slice(1);
12208
+ 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;
12209
+ if (projected?.ordinal) return projected.ordinal;
12210
+ return counters.slice(0, level).map((number) => formatBibliographyNumber(number, {
12211
+ documentDirection: options.documentDirection,
12212
+ digitForm: options.digitForm
12213
+ })).join(".");
12214
+ }
12215
+ function textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
12204
12216
  const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
12205
12217
  const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
12206
- if (block.command === "\\section") {
12207
- return { kind: "heading", id: block.id, level: 1, inlines, ...metadata };
12208
- }
12209
- if (block.command === "\\subsection") {
12210
- return { kind: "heading", id: block.id, level: 2, inlines, ...metadata };
12211
- }
12212
- if (block.command === "\\subsubsection") {
12213
- return { kind: "heading", id: block.id, level: 3, inlines, ...metadata };
12218
+ if (block.command === "\\section" || block.command === "\\subsection" || block.command === "\\subsubsection") {
12219
+ const level = block.command === "\\section" ? 1 : block.command === "\\subsection" ? 2 : 3;
12220
+ return {
12221
+ kind: "heading",
12222
+ id: block.id,
12223
+ level,
12224
+ inlines,
12225
+ numberLabel: nextHeadingNumber(block, headingCounters, previewOptions),
12226
+ ...metadata
12227
+ };
12214
12228
  }
12215
12229
  return {
12216
12230
  kind: "paragraph",
@@ -12242,9 +12256,9 @@ function captionPreview(block, islands, output, equationSide, document2, preview
12242
12256
  captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
12243
12257
  };
12244
12258
  }
12245
- function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
12259
+ function blockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters) {
12246
12260
  if (block.kind === "textBlock") {
12247
- return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
12261
+ return textBlockPreview(block, islands, output, equationSide, document2, previewOptions, headingCounters);
12248
12262
  }
12249
12263
  if (block.kind === "list") {
12250
12264
  return {
@@ -12254,7 +12268,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
12254
12268
  items: block.items.map((item) => ({
12255
12269
  id: item.id,
12256
12270
  inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
12257
- blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
12271
+ blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions, headingCounters))
12258
12272
  })),
12259
12273
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
12260
12274
  };
@@ -12340,7 +12354,8 @@ function documentPreview(document2, output = "svg", equationSide = "arabic", pre
12340
12354
  mode: previewOptions.mode ?? "article",
12341
12355
  bookContext: previewOptions.bookContext
12342
12356
  };
12343
- const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
12357
+ const headingCounters = [0, 0, 0];
12358
+ const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options, headingCounters));
12344
12359
  return {
12345
12360
  blocks: [
12346
12361
  ...options.mode === "book-content" ? [] : articleChromePreview(document2, options.uiLocale ?? "ar", options),
@@ -15492,7 +15507,10 @@ function PreviewBlock({
15492
15507
  }
15493
15508
  if (block.kind === "heading") {
15494
15509
  const Tag = block.level === 1 ? "h1" : block.level === 2 ? "h2" : "h3";
15495
- return /* @__PURE__ */ jsx14(Tag, { "data-butex-block-source": source, children: /* @__PURE__ */ jsx14(PreviewInlines, { inlines: block.inlines, output }) });
15510
+ return /* @__PURE__ */ jsxs13(Tag, { "data-butex-block-source": source, children: [
15511
+ block.numberLabel ? /* @__PURE__ */ jsx14("span", { className: "butex-document-widget__preview-heading-number", dir: "auto", children: block.numberLabel }) : null,
15512
+ /* @__PURE__ */ jsx14(PreviewInlines, { inlines: block.inlines, output })
15513
+ ] });
15496
15514
  }
15497
15515
  if (block.kind === "paragraph") {
15498
15516
  return /* @__PURE__ */ jsx14("p", { "data-butex-block-source": source, className: block.centered ? "butex-document-widget__preview-paragraph--centered" : void 0, children: /* @__PURE__ */ jsx14(PreviewInlines, { inlines: block.inlines, output }) });
@@ -20965,6 +20983,12 @@ var DOCUMENT_WIDGET_CSS = `
20965
20983
  word-break: break-word;
20966
20984
  }
20967
20985
 
20986
+ .butex-document-widget__preview-heading-number {
20987
+ display: inline-block;
20988
+ margin-inline-end: 0.6em;
20989
+ font-variant-numeric: tabular-nums;
20990
+ }
20991
+
20968
20992
  .butex-document-widget__preview h1 {
20969
20993
  font-size: 1.75rem;
20970
20994
  font-weight: 700;