@superdoc-dev/cli 0.3.0-next.46 → 0.3.0-next.48

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.
Files changed (2) hide show
  1. package/dist/index.js +203 -98
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -148837,7 +148837,7 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
148837
148837
  init_remark_gfm_z_sDF4ss_es();
148838
148838
  });
148839
148839
 
148840
- // ../../packages/superdoc/dist/chunks/src-DFYcQ0qe.es.js
148840
+ // ../../packages/superdoc/dist/chunks/src-C9IXXt7g.es.js
148841
148841
  function deleteProps(obj, propOrProps) {
148842
148842
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
148843
148843
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -187305,6 +187305,43 @@ function collectAnchoredTables(blocks2, measures) {
187305
187305
  }
187306
187306
  return map$12;
187307
187307
  }
187308
+ function computePhysicalAnchorY(block, fragmentHeight, pageHeight) {
187309
+ const alignV = block.anchor?.alignV ?? "top";
187310
+ const offsetV = block.anchor?.offsetV ?? 0;
187311
+ if (alignV === "bottom")
187312
+ return pageHeight - fragmentHeight + offsetV;
187313
+ if (alignV === "center")
187314
+ return (pageHeight - fragmentHeight) / 2 + offsetV;
187315
+ return offsetV;
187316
+ }
187317
+ function computeFooterBandOrigin(constraints) {
187318
+ return (constraints.pageHeight ?? 0) - (constraints.margins?.bottom ?? 0);
187319
+ }
187320
+ function isAnchoredFragment(fragment2) {
187321
+ return (fragment2.kind === "image" || fragment2.kind === "drawing") && fragment2.isAnchored === true;
187322
+ }
187323
+ function isPageRelativeBlock(block) {
187324
+ return (block.kind === "image" || block.kind === "drawing") && block.anchor?.vRelativeFrom === "page";
187325
+ }
187326
+ function normalizeFragmentsForRegion(pages, blocks2, _measures, _kind, constraints) {
187327
+ if (constraints.pageHeight == null || !constraints.margins)
187328
+ return pages;
187329
+ const pageHeight = constraints.pageHeight;
187330
+ const bandOrigin = computeFooterBandOrigin(constraints);
187331
+ const blockById = /* @__PURE__ */ new Map;
187332
+ for (const block of blocks2)
187333
+ blockById.set(block.id, block);
187334
+ for (const page of pages)
187335
+ for (const fragment2 of page.fragments) {
187336
+ if (!isAnchoredFragment(fragment2))
187337
+ continue;
187338
+ const block = blockById.get(fragment2.blockId);
187339
+ if (!block || !isPageRelativeBlock(block))
187340
+ continue;
187341
+ fragment2.y = computePhysicalAnchorY(block, fragment2.height ?? 0, pageHeight) - bandOrigin;
187342
+ }
187343
+ return pages;
187344
+ }
187308
187345
  function createPaginator(opts) {
187309
187346
  const states = [];
187310
187347
  const pages = [];
@@ -188979,7 +189016,51 @@ function layoutDocument(blocks2, measures, options = {}) {
188979
189016
  } : undefined
188980
189017
  };
188981
189018
  }
188982
- function layoutHeaderFooter(blocks2, measures, constraints) {
189019
+ function computeFragmentBottom(fragment2, block, measure) {
189020
+ let bottom$1 = fragment2.y;
189021
+ if (fragment2.kind === "para" && measure?.kind === "paragraph") {
189022
+ let sum = 0;
189023
+ for (let li2 = fragment2.fromLine;li2 < fragment2.toLine; li2 += 1)
189024
+ sum += measure.lines[li2]?.lineHeight ?? 0;
189025
+ bottom$1 += sum;
189026
+ const spacingAfter = block?.attrs?.spacing?.after;
189027
+ if (spacingAfter && fragment2.toLine === measure.lines.length)
189028
+ bottom$1 += Math.max(0, Number(spacingAfter));
189029
+ } else if (fragment2.kind === "image")
189030
+ bottom$1 += typeof fragment2.height === "number" ? fragment2.height : measure?.height ?? 0;
189031
+ else if (fragment2.kind === "drawing")
189032
+ bottom$1 += typeof fragment2.height === "number" ? fragment2.height : measure?.height ?? 0;
189033
+ else if (fragment2.kind === "list-item") {
189034
+ const listMeasure = measure;
189035
+ if (listMeasure) {
189036
+ const item = listMeasure.items.find((it) => it.itemId === fragment2.itemId);
189037
+ if (item?.paragraph) {
189038
+ let sum = 0;
189039
+ for (let li2 = fragment2.fromLine;li2 < fragment2.toLine; li2 += 1)
189040
+ sum += item.paragraph.lines[li2]?.lineHeight ?? 0;
189041
+ bottom$1 += sum;
189042
+ }
189043
+ }
189044
+ }
189045
+ return bottom$1;
189046
+ }
189047
+ function shouldExcludeFromMeasurement(fragment2, block, canvasHeight) {
189048
+ if (!((fragment2.kind === "image" || fragment2.kind === "drawing") && fragment2.isAnchored === true))
189049
+ return false;
189050
+ if (block.kind !== "image" && block.kind !== "drawing")
189051
+ throw new Error(`Type mismatch: fragment kind is ${fragment2.kind} but block kind is ${block.kind} for block ${block.id}`);
189052
+ const anchoredBlock = block;
189053
+ if (anchoredBlock.anchor?.behindDoc)
189054
+ return true;
189055
+ if (isPageRelativeAnchor(anchoredBlock)) {
189056
+ const fragmentHeight = fragment2.height ?? 0;
189057
+ const fragmentTop = fragment2.y;
189058
+ if (fragment2.y + fragmentHeight <= 0 || fragmentTop >= canvasHeight)
189059
+ return true;
189060
+ }
189061
+ return false;
189062
+ }
189063
+ function layoutHeaderFooter(blocks2, measures, constraints, kind) {
188983
189064
  if (blocks2.length !== measures.length)
188984
189065
  throw new Error(`layoutHeaderFooter expected measures for every block (blocks=${blocks2.length}, measures=${measures.length})`);
188985
189066
  const width = Number(constraints?.width);
@@ -188991,18 +189072,7 @@ function layoutHeaderFooter(blocks2, measures, constraints) {
188991
189072
  pages: [],
188992
189073
  height: 0
188993
189074
  };
188994
- const marginLeft = constraints.margins?.left ?? 0;
188995
- const layout = layoutDocument(marginLeft > 0 ? blocks2.map((block) => {
188996
- if ((block.kind === "image" || block.kind === "drawing") && block.anchor?.hRelativeFrom === "page" && block.anchor.offsetH != null)
188997
- return {
188998
- ...block,
188999
- anchor: {
189000
- ...block.anchor,
189001
- offsetH: block.anchor.offsetH - marginLeft
189002
- }
189003
- };
189004
- return block;
189005
- }) : blocks2, measures, {
189075
+ const layout = layoutDocument(blocks2, measures, {
189006
189076
  pageSize: {
189007
189077
  w: width,
189008
189078
  h: height
@@ -189014,11 +189084,15 @@ function layoutHeaderFooter(blocks2, measures, constraints) {
189014
189084
  left: 0
189015
189085
  }
189016
189086
  });
189087
+ if (kind === "footer" && constraints.pageHeight != null)
189088
+ normalizeFragmentsForRegion(layout.pages, blocks2, measures, kind, constraints);
189017
189089
  const idToIndex = /* @__PURE__ */ new Map;
189018
189090
  for (let i4 = 0;i4 < blocks2.length; i4 += 1)
189019
189091
  idToIndex.set(blocks2[i4].id, i4);
189020
- let minY = 0;
189021
- let maxY = 0;
189092
+ let measureMinY = 0;
189093
+ let measureMaxY = 0;
189094
+ let renderMinY = 0;
189095
+ let renderMaxY = 0;
189022
189096
  for (const page of layout.pages)
189023
189097
  for (const fragment2 of page.fragments) {
189024
189098
  const idx = idToIndex.get(fragment2.blockId);
@@ -189026,48 +189100,23 @@ function layoutHeaderFooter(blocks2, measures, constraints) {
189026
189100
  continue;
189027
189101
  const block = blocks2[idx];
189028
189102
  const measure = measures[idx];
189029
- if ((fragment2.kind === "image" || fragment2.kind === "drawing") && fragment2.isAnchored === true) {
189030
- if (block.kind !== "image" && block.kind !== "drawing")
189031
- throw new Error(`Type mismatch: fragment kind is ${fragment2.kind} but block kind is ${block.kind} for block ${block.id}`);
189032
- if (block.anchor?.behindDoc)
189033
- continue;
189034
- }
189035
- if (fragment2.y < minY)
189036
- minY = fragment2.y;
189037
- let bottom$1 = fragment2.y;
189038
- if (fragment2.kind === "para" && measure?.kind === "paragraph") {
189039
- let sum = 0;
189040
- for (let li2 = fragment2.fromLine;li2 < fragment2.toLine; li2 += 1)
189041
- sum += measure.lines[li2]?.lineHeight ?? 0;
189042
- bottom$1 += sum;
189043
- const spacingAfter = block?.attrs?.spacing?.after;
189044
- if (spacingAfter && fragment2.toLine === measure.lines.length)
189045
- bottom$1 += Math.max(0, Number(spacingAfter));
189046
- } else if (fragment2.kind === "image") {
189047
- const h$2 = typeof fragment2.height === "number" ? fragment2.height : measure?.height ?? 0;
189048
- bottom$1 += h$2;
189049
- } else if (fragment2.kind === "drawing") {
189050
- const drawingHeight = typeof fragment2.height === "number" ? fragment2.height : measure?.height ?? 0;
189051
- bottom$1 += drawingHeight;
189052
- } else if (fragment2.kind === "list-item") {
189053
- const listMeasure = measure;
189054
- if (listMeasure) {
189055
- const item = listMeasure.items.find((it) => it.itemId === fragment2.itemId);
189056
- if (item?.paragraph) {
189057
- let sum = 0;
189058
- for (let li2 = fragment2.fromLine;li2 < fragment2.toLine; li2 += 1)
189059
- sum += item.paragraph.lines[li2]?.lineHeight ?? 0;
189060
- bottom$1 += sum;
189061
- }
189062
- }
189063
- }
189064
- if (bottom$1 > maxY)
189065
- maxY = bottom$1;
189103
+ const bottom$1 = computeFragmentBottom(fragment2, block, measure);
189104
+ if (fragment2.y < renderMinY)
189105
+ renderMinY = fragment2.y;
189106
+ if (bottom$1 > renderMaxY)
189107
+ renderMaxY = bottom$1;
189108
+ if (shouldExcludeFromMeasurement(fragment2, block, height))
189109
+ continue;
189110
+ if (fragment2.y < measureMinY)
189111
+ measureMinY = fragment2.y;
189112
+ if (bottom$1 > measureMaxY)
189113
+ measureMaxY = bottom$1;
189066
189114
  }
189067
189115
  return {
189068
- height: maxY - minY,
189069
- minY,
189070
- maxY,
189116
+ height: measureMaxY - measureMinY,
189117
+ minY: renderMinY,
189118
+ maxY: renderMaxY,
189119
+ renderHeight: renderMaxY - renderMinY,
189071
189120
  pages: layout.pages.map((page) => ({
189072
189121
  number: page.number,
189073
189122
  fragments: page.fragments
@@ -193922,7 +193971,7 @@ function hasPageTokens(blocks2) {
193922
193971
  }
193923
193972
  return false;
193924
193973
  }
193925
- async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1, cache$2 = sharedHeaderFooterCache, totalPages, pageResolver) {
193974
+ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1, cache$2 = sharedHeaderFooterCache, totalPages, pageResolver, kind) {
193926
193975
  const result = {};
193927
193976
  if (!pageResolver) {
193928
193977
  const numPages = totalPages ?? 1;
@@ -193935,7 +193984,7 @@ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1
193935
193984
  result[type] = {
193936
193985
  blocks: clonedBlocks,
193937
193986
  measures,
193938
- layout: layoutHeaderFooter(clonedBlocks, measures, constraints)
193987
+ layout: layoutHeaderFooter(clonedBlocks, measures, constraints, kind)
193939
193988
  };
193940
193989
  }
193941
193990
  return result;
@@ -193950,7 +193999,7 @@ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1
193950
193999
  result[type] = {
193951
194000
  blocks: blocks2,
193952
194001
  measures,
193953
- layout: layoutHeaderFooter(blocks2, measures, constraints)
194002
+ layout: layoutHeaderFooter(blocks2, measures, constraints, kind)
193954
194003
  };
193955
194004
  continue;
193956
194005
  }
@@ -193971,7 +194020,7 @@ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1
193971
194020
  const { displayText, totalPages: totalPagesForPage } = pageResolver(pageNum);
193972
194021
  resolveHeaderFooterTokens(clonedBlocks, pageNum, totalPagesForPage, displayText);
193973
194022
  const measures = await cache$2.measureBlocks(clonedBlocks, constraints, measureBlock$1);
193974
- const pageLayout = layoutHeaderFooter(clonedBlocks, measures, constraints);
194023
+ const pageLayout = layoutHeaderFooter(clonedBlocks, measures, constraints, kind);
193975
194024
  const measuresById = /* @__PURE__ */ new Map;
193976
194025
  for (let i4 = 0;i4 < clonedBlocks.length; i4 += 1)
193977
194026
  measuresById.set(clonedBlocks[i4].id, measures[i4]);
@@ -193993,7 +194042,7 @@ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1
193993
194042
  fragments: fragmentsWithLines
193994
194043
  });
193995
194044
  }
193996
- const firstPageLayout = pages[0] ? layoutHeaderFooter(pages[0].blocks, pages[0].measures, constraints) : {
194045
+ const firstPageLayout = pages[0] ? layoutHeaderFooter(pages[0].blocks, pages[0].measures, constraints, kind) : {
193997
194046
  height: 0,
193998
194047
  pages: []
193999
194048
  };
@@ -194001,6 +194050,7 @@ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1
194001
194050
  height: firstPageLayout.height,
194002
194051
  minY: firstPageLayout.minY,
194003
194052
  maxY: firstPageLayout.maxY,
194053
+ renderHeight: firstPageLayout.renderHeight,
194004
194054
  pages: pages.map((p$12) => ({
194005
194055
  number: p$12.number,
194006
194056
  fragments: p$12.fragments
@@ -194599,7 +194649,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
194599
194649
  };
194600
194650
  headerContentHeights = {};
194601
194651
  if (hasHeaderBlocks && headerFooter.headerBlocks) {
194602
- const preHeaderLayouts = await layoutHeaderFooterWithCache(headerFooter.headerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT, undefined);
194652
+ const preHeaderLayouts = await layoutHeaderFooterWithCache(headerFooter.headerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT, undefined, "header");
194603
194653
  for (const [type, value] of Object.entries(preHeaderLayouts)) {
194604
194654
  if (!isValidHeaderType(type))
194605
194655
  continue;
@@ -194619,10 +194669,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
194619
194669
  maxWidth: headerFooter.constraints.width,
194620
194670
  maxHeight: headerFooter.constraints.height
194621
194671
  };
194622
- const layout$1 = layoutHeaderFooter(blocks2, await Promise.all(blocks2.map((block) => measureFn(block, measureConstraints))), {
194623
- width: headerFooter.constraints.width,
194624
- height: headerFooter.constraints.height
194625
- });
194672
+ const layout$1 = layoutHeaderFooter(blocks2, await Promise.all(blocks2.map((block) => measureFn(block, measureConstraints))), headerFooter.constraints, "header");
194626
194673
  if (layout$1.height > 0)
194627
194674
  headerContentHeightsByRId.set(rId, layout$1.height);
194628
194675
  }
@@ -194650,7 +194697,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
194650
194697
  footerContentHeights = {};
194651
194698
  try {
194652
194699
  if (hasFooterBlocks && headerFooter.footerBlocks) {
194653
- const preFooterLayouts = await layoutHeaderFooterWithCache(headerFooter.footerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT, undefined);
194700
+ const preFooterLayouts = await layoutHeaderFooterWithCache(headerFooter.footerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT, undefined, "footer");
194654
194701
  for (const [type, value] of Object.entries(preFooterLayouts)) {
194655
194702
  if (!isValidFooterType(type))
194656
194703
  continue;
@@ -194670,10 +194717,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
194670
194717
  maxWidth: headerFooter.constraints.width,
194671
194718
  maxHeight: headerFooter.constraints.height
194672
194719
  };
194673
- const layout$1 = layoutHeaderFooter(blocks2, await Promise.all(blocks2.map((block) => measureFn(block, measureConstraints))), {
194674
- width: headerFooter.constraints.width,
194675
- height: headerFooter.constraints.height
194676
- });
194720
+ const layout$1 = layoutHeaderFooter(blocks2, await Promise.all(blocks2.map((block) => measureFn(block, measureConstraints))), headerFooter.constraints, "footer");
194677
194721
  if (layout$1.height > 0)
194678
194722
  footerContentHeightsByRId.set(rId, layout$1.height);
194679
194723
  }
@@ -195283,9 +195327,9 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
195283
195327
  };
195284
195328
  } : undefined;
195285
195329
  if (headerFooter.headerBlocks)
195286
- headers = serializeHeaderFooterResults("header", await layoutHeaderFooterWithCache(headerFooter.headerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FeatureFlags.HEADER_FOOTER_PAGE_TOKENS ? undefined : numberingCtx.totalPages, pageResolver));
195330
+ headers = serializeHeaderFooterResults("header", await layoutHeaderFooterWithCache(headerFooter.headerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FeatureFlags.HEADER_FOOTER_PAGE_TOKENS ? undefined : numberingCtx.totalPages, pageResolver, "header"));
195287
195331
  if (headerFooter.footerBlocks)
195288
- footers = serializeHeaderFooterResults("footer", await layoutHeaderFooterWithCache(headerFooter.footerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FeatureFlags.HEADER_FOOTER_PAGE_TOKENS ? undefined : numberingCtx.totalPages, pageResolver));
195332
+ footers = serializeHeaderFooterResults("footer", await layoutHeaderFooterWithCache(headerFooter.footerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FeatureFlags.HEADER_FOOTER_PAGE_TOKENS ? undefined : numberingCtx.totalPages, pageResolver, "footer"));
195289
195333
  perfLog$1(`[Perf] 4.4 Header/footer layout: ${(performance.now() - hfStart).toFixed(2)}ms`);
195290
195334
  const cacheStats = headerMeasureCache.getStats();
195291
195335
  globalMetrics.recordHeaderFooterCacheMetrics(cacheStats);
@@ -197746,25 +197790,37 @@ function initHeaderFooterRegistry({ painterHost, visibleHost, selectionOverlay,
197746
197790
  };
197747
197791
  }
197748
197792
  function buildSectionContentWidth(section, fallback) {
197749
- const pageW = section.pageSize?.w ?? fallback.pageWidth;
197750
- const marginL = section.margins?.left ?? fallback.margins.left;
197751
- const marginR = section.margins?.right ?? fallback.margins.right;
197793
+ const pageW = section.pageSize?.w ?? fallback.pageWidth ?? 0;
197794
+ const marginL = section.margins?.left ?? fallback.margins?.left ?? 0;
197795
+ const marginR = section.margins?.right ?? fallback.margins?.right ?? 0;
197752
197796
  return pageW - marginL - marginR;
197753
197797
  }
197754
197798
  function buildConstraintsForSection(section, fallback, minWidth) {
197755
- const pageW = section.pageSize?.w ?? fallback.pageWidth;
197756
- const marginL = section.margins?.left ?? fallback.margins.left;
197757
- const marginR = section.margins?.right ?? fallback.margins.right;
197799
+ const pageW = section.pageSize?.w ?? fallback.pageWidth ?? 0;
197800
+ const pageH = section.pageSize?.h ?? fallback.pageHeight;
197801
+ const marginL = section.margins?.left ?? fallback.margins?.left ?? 0;
197802
+ const marginR = section.margins?.right ?? fallback.margins?.right ?? 0;
197803
+ const marginT = section.margins?.top ?? fallback.margins?.top;
197804
+ const marginB = section.margins?.bottom ?? fallback.margins?.bottom;
197805
+ const marginHeader = section.margins?.header ?? fallback.margins?.header;
197758
197806
  const contentWidth = pageW - marginL - marginR;
197759
197807
  const maxWidth = pageW - marginL;
197808
+ const effectiveWidth = minWidth ? Math.min(Math.max(contentWidth, minWidth), maxWidth) : contentWidth;
197809
+ const sectionMarginTop = marginT ?? 0;
197810
+ const sectionMarginBottom = marginB ?? 0;
197760
197811
  return {
197761
- width: minWidth ? Math.min(Math.max(contentWidth, minWidth), maxWidth) : contentWidth,
197762
- height: fallback.height,
197812
+ width: effectiveWidth,
197813
+ height: pageH != null ? Math.max(1, pageH - sectionMarginTop - sectionMarginBottom) : fallback.height,
197763
197814
  pageWidth: pageW,
197815
+ pageHeight: pageH,
197764
197816
  margins: {
197765
197817
  left: marginL,
197766
- right: marginR
197767
- }
197818
+ right: marginR,
197819
+ top: marginT,
197820
+ bottom: marginB,
197821
+ header: marginHeader
197822
+ },
197823
+ overflowBaseHeight: fallback.overflowBaseHeight
197768
197824
  };
197769
197825
  }
197770
197826
  function getTableWidthSpec(blocks2) {
@@ -197852,7 +197908,7 @@ async function layoutBlocksByRId(kind, blocksByRId, constraints, pageResolver, l
197852
197908
  if (!blocks2 || blocks2.length === 0)
197853
197909
  continue;
197854
197910
  try {
197855
- const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, (block, c) => measureBlock(block, c), undefined, undefined, pageResolver);
197911
+ const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, (block, c) => measureBlock(block, c), undefined, undefined, pageResolver, kind);
197856
197912
  if (batchResult.default)
197857
197913
  layoutsByRId.set(rId, {
197858
197914
  kind,
@@ -197916,7 +197972,7 @@ async function layoutWithPerSectionConstraints(kind, blocksByRId, sectionMetadat
197916
197972
  const contentWidth = buildSectionContentWidth(section, fallbackConstraints);
197917
197973
  const sectionConstraints = buildConstraintsForSection(section, fallbackConstraints, resolveTableMinWidth(tableWidthSpecByRId.get(rId), contentWidth) || undefined);
197918
197974
  const effectiveWidth = sectionConstraints.width;
197919
- const groupKey = `${rId}::w${effectiveWidth}`;
197975
+ const groupKey = `${rId}::w${effectiveWidth}::ph${sectionConstraints.pageHeight ?? ""}::mt${sectionConstraints.margins?.top ?? ""}::mb${sectionConstraints.margins?.bottom ?? ""}::mh${sectionConstraints.margins?.header ?? ""}`;
197920
197976
  let group = groups.get(groupKey);
197921
197977
  if (!group) {
197922
197978
  group = {
@@ -197934,7 +197990,7 @@ async function layoutWithPerSectionConstraints(kind, blocksByRId, sectionMetadat
197934
197990
  if (!blocks2 || blocks2.length === 0)
197935
197991
  continue;
197936
197992
  try {
197937
- const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, group.sectionConstraints, (block, c) => measureBlock(block, c), undefined, undefined, pageResolver);
197993
+ const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, group.sectionConstraints, (block, c) => measureBlock(block, c), undefined, undefined, pageResolver, kind);
197938
197994
  if (batchResult.default)
197939
197995
  for (const sectionIndex of group.sectionIndices) {
197940
197996
  const contentWidth = buildSectionContentWidth(sectionMetadata.find((s2) => s2.sectionIndex === sectionIndex), fallbackConstraints);
@@ -215503,11 +215559,25 @@ var Node$13 = class Node$14 {
215503
215559
  console.warn(`[DomPainter] Failed to set data attribute "${key$1}":`, error);
215504
215560
  }
215505
215561
  });
215562
+ }, resolveParagraphDirection = (attrs) => {
215563
+ if (attrs?.direction)
215564
+ return attrs.direction;
215565
+ if (attrs?.rtl === true)
215566
+ return "rtl";
215567
+ if (attrs?.rtl === false)
215568
+ return "ltr";
215569
+ }, applyParagraphDirection = (element3, attrs) => {
215570
+ const direction = resolveParagraphDirection(attrs);
215571
+ if (!direction)
215572
+ return;
215573
+ element3.setAttribute("dir", direction);
215574
+ element3.style.direction = direction;
215506
215575
  }, applyParagraphBlockStyles = (element3, attrs) => {
215507
215576
  if (!attrs)
215508
215577
  return;
215509
215578
  if (attrs.styleId)
215510
215579
  element3.setAttribute("styleid", attrs.styleId);
215580
+ applyParagraphDirection(element3, attrs);
215511
215581
  if (attrs.alignment)
215512
215582
  element3.style.textAlign = attrs.alignment === "justify" ? "left" : attrs.alignment;
215513
215583
  if (attrs.dropCap)
@@ -216507,6 +216577,7 @@ var Node$13 = class Node$14 {
216507
216577
  const paragraphDecimalSeparator = DEFAULT_DECIMAL_SEPARATOR;
216508
216578
  const tabIntervalTwips = DEFAULT_TAB_INTERVAL_TWIPS$1;
216509
216579
  const normalizedFramePr = normalizeFramePr(resolvedParagraphProperties.framePr);
216580
+ const normalizedDirection = resolvedParagraphProperties.rightToLeft === true ? "rtl" : resolvedParagraphProperties.rightToLeft === false ? "ltr" : undefined;
216510
216581
  const floatAlignment = normalizedFramePr?.xAlign;
216511
216582
  const normalizedNumberingProperties = normalizeNumberingProperties(resolvedParagraphProperties.numberingProperties);
216512
216583
  const dropCapDescriptor = normalizeDropCap(resolvedParagraphProperties.framePr, para, converterContext);
@@ -216529,7 +216600,8 @@ var Node$13 = class Node$14 {
216529
216600
  keepLines: resolvedParagraphProperties.keepLines,
216530
216601
  floatAlignment,
216531
216602
  pageBreakBefore: resolvedParagraphProperties.pageBreakBefore,
216532
- direction: resolvedParagraphProperties.rightToLeft ? "rtl" : undefined
216603
+ direction: normalizedDirection,
216604
+ rtl: normalizedDirection === "rtl" ? true : normalizedDirection === "ltr" ? false : undefined
216533
216605
  };
216534
216606
  if (normalizedNumberingProperties && normalizedListRendering) {
216535
216607
  const markerRunAttrs = computeRunAttrs(resolveRunProperties(converterContext, resolvedParagraphProperties.runProperties, resolvedParagraphProperties, converterContext.tableInfo, true, Boolean(paragraphProperties.numberingProperties)), converterContext);
@@ -223762,9 +223834,13 @@ var Node$13 = class Node$14 {
223762
223834
  width: measurementWidth,
223763
223835
  height,
223764
223836
  pageWidth: pageSize.w,
223837
+ pageHeight: pageSize.h,
223765
223838
  margins: {
223766
223839
  left: marginLeft,
223767
- right: marginRight
223840
+ right: marginRight,
223841
+ top: marginTop,
223842
+ bottom: marginBottom,
223843
+ header: headerMargin
223768
223844
  },
223769
223845
  overflowBaseHeight
223770
223846
  };
@@ -229098,7 +229174,7 @@ var Node$13 = class Node$14 {
229098
229174
  return false;
229099
229175
  return Boolean(checker(attrs));
229100
229176
  }, SuperToolbar, ICONS, TEXTS, tableActionsOptions;
229101
- var init_src_DFYcQ0qe_es = __esm(() => {
229177
+ var init_src_C9IXXt7g_es = __esm(() => {
229102
229178
  init_rolldown_runtime_B2q5OVn9_es();
229103
229179
  init_SuperConverter_IVMRugL_es();
229104
229180
  init_jszip_ChlR43oI_es();
@@ -243529,7 +243605,7 @@ function print() { __p += __j.call(arguments, '') }
243529
243605
  this.renderDecorationSection(pageEl, page, pageIndex, "header");
243530
243606
  this.renderDecorationSection(pageEl, page, pageIndex, "footer");
243531
243607
  }
243532
- isPageRelativeVerticalAnchorFragment(fragment2) {
243608
+ isPageRelativeAnchoredFragment(fragment2) {
243533
243609
  if (fragment2.kind !== "image" && fragment2.kind !== "drawing")
243534
243610
  return false;
243535
243611
  const lookup3 = this.blockLookup.get(fragment2.blockId);
@@ -243540,6 +243616,18 @@ function print() { __p += __j.call(arguments, '') }
243540
243616
  return false;
243541
243617
  return block.anchor?.vRelativeFrom === "page";
243542
243618
  }
243619
+ getDecorationAnchorPageOriginY(pageEl, page, kind, effectiveOffset) {
243620
+ if (kind === "header")
243621
+ return effectiveOffset;
243622
+ const bottomMargin = page.margins?.bottom;
243623
+ if (bottomMargin == null)
243624
+ return effectiveOffset;
243625
+ const footnoteReserve = page.footnoteReserved ?? 0;
243626
+ const adjustedBottomMargin = Math.max(0, bottomMargin - footnoteReserve);
243627
+ const styledPageHeight = Number.parseFloat(pageEl.style.height || "");
243628
+ const pageHeight = page.size?.h ?? this.currentLayout?.pageSize?.h ?? (Number.isFinite(styledPageHeight) ? styledPageHeight : pageEl.clientHeight);
243629
+ return Math.max(0, pageHeight - adjustedBottomMargin);
243630
+ }
243543
243631
  renderDecorationSection(pageEl, page, pageIndex, kind) {
243544
243632
  if (!this.doc)
243545
243633
  return;
@@ -243574,6 +243662,8 @@ function print() { __p += __j.call(arguments, '') }
243574
243662
  container.style.top = `${Math.max(0, effectiveOffset)}px`;
243575
243663
  container.style.zIndex = "1";
243576
243664
  container.style.overflow = "visible";
243665
+ const footerAnchorPageOriginY = kind === "footer" ? this.getDecorationAnchorPageOriginY(pageEl, page, kind, effectiveOffset) : 0;
243666
+ const footerAnchorContainerOffsetY = kind === "footer" ? footerAnchorPageOriginY - effectiveOffset : 0;
243577
243667
  let footerYOffset = 0;
243578
243668
  if (kind === "footer" && data.fragments.length > 0) {
243579
243669
  const contentHeight = typeof data.contentHeight === "number" ? data.contentHeight : data.fragments.reduce((max$2, f2) => {
@@ -243612,7 +243702,14 @@ function print() { __p += __j.call(arguments, '') }
243612
243702
  pageEl.querySelectorAll(behindDocSelector).forEach((el) => el.remove());
243613
243703
  behindDocFragments.forEach(({ fragment: fragment2, originalIndex }) => {
243614
243704
  const fragEl = this.renderFragment(fragment2, context, undefined, betweenBorderFlags.get(originalIndex));
243615
- const pageY = this.isPageRelativeVerticalAnchorFragment(fragment2) ? fragment2.y : effectiveOffset + fragment2.y + (kind === "footer" ? footerYOffset : 0);
243705
+ const isPageRelative = this.isPageRelativeAnchoredFragment(fragment2);
243706
+ let pageY;
243707
+ if (isPageRelative && kind === "footer")
243708
+ pageY = footerAnchorPageOriginY + fragment2.y;
243709
+ else if (isPageRelative)
243710
+ pageY = fragment2.y;
243711
+ else
243712
+ pageY = effectiveOffset + fragment2.y + (kind === "footer" ? footerYOffset : 0);
243616
243713
  fragEl.style.top = `${pageY}px`;
243617
243714
  fragEl.style.left = `${marginLeft + fragment2.x}px`;
243618
243715
  fragEl.style.zIndex = "0";
@@ -243621,10 +243718,12 @@ function print() { __p += __j.call(arguments, '') }
243621
243718
  });
243622
243719
  normalFragments.forEach(({ fragment: fragment2, originalIndex }) => {
243623
243720
  const fragEl = this.renderFragment(fragment2, context, undefined, betweenBorderFlags.get(originalIndex));
243624
- const isPageRelativeVertical = this.isPageRelativeVerticalAnchorFragment(fragment2);
243625
- if (isPageRelativeVertical)
243721
+ const isPageRelative = this.isPageRelativeAnchoredFragment(fragment2);
243722
+ if (isPageRelative && kind === "footer")
243723
+ fragEl.style.top = `${fragment2.y + footerAnchorContainerOffsetY}px`;
243724
+ else if (isPageRelative)
243626
243725
  fragEl.style.top = `${fragment2.y - effectiveOffset}px`;
243627
- if (footerYOffset > 0 && !isPageRelativeVertical) {
243726
+ else if (footerYOffset > 0) {
243628
243727
  const currentTop = parseFloat(fragEl.style.top) || fragment2.y;
243629
243728
  fragEl.style.top = `${currentTop + footerYOffset}px`;
243630
243729
  }
@@ -245449,10 +245548,12 @@ function print() { __p += __j.call(arguments, '') }
245449
245548
  el.classList.add(CLASS_NAMES$1.line);
245450
245549
  applyStyles$1(el, lineStyles(line.lineHeight));
245451
245550
  el.dataset.layoutEpoch = String(this.layoutEpoch);
245452
- const styleId = block.attrs?.styleId;
245551
+ const paragraphAttrs = block.attrs ?? {};
245552
+ const styleId = paragraphAttrs.styleId;
245453
245553
  if (styleId)
245454
245554
  el.setAttribute("styleid", styleId);
245455
- const alignment$1 = block.attrs?.alignment;
245555
+ applyParagraphDirection(el, paragraphAttrs);
245556
+ const alignment$1 = paragraphAttrs.alignment;
245456
245557
  if (alignment$1 === "center" || alignment$1 === "right")
245457
245558
  el.style.textAlign = alignment$1;
245458
245559
  else
@@ -250033,9 +250134,13 @@ function print() { __p += __j.call(arguments, '') }
250033
250134
  width: measurementWidth,
250034
250135
  height,
250035
250136
  pageWidth: pageSize.w,
250137
+ pageHeight: pageSize.h,
250036
250138
  margins: {
250037
250139
  left: marginLeft,
250038
- right: marginRight
250140
+ right: marginRight,
250141
+ top: marginTop,
250142
+ bottom: marginBottom,
250143
+ header: headerMargin
250039
250144
  },
250040
250145
  overflowBaseHeight
250041
250146
  };
@@ -262432,7 +262537,7 @@ var init_zipper_DqXT7uTa_es = __esm(() => {
262432
262537
 
262433
262538
  // ../../packages/superdoc/dist/super-editor.es.js
262434
262539
  var init_super_editor_es = __esm(() => {
262435
- init_src_DFYcQ0qe_es();
262540
+ init_src_C9IXXt7g_es();
262436
262541
  init_SuperConverter_IVMRugL_es();
262437
262542
  init_jszip_ChlR43oI_es();
262438
262543
  init_xml_js_BtmJ6bNs_es();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/cli",
3
- "version": "0.3.0-next.46",
3
+ "version": "0.3.0-next.48",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -30,11 +30,11 @@
30
30
  "access": "public"
31
31
  },
32
32
  "optionalDependencies": {
33
- "@superdoc-dev/cli-darwin-arm64": "0.3.0-next.46",
34
- "@superdoc-dev/cli-darwin-x64": "0.3.0-next.46",
35
- "@superdoc-dev/cli-linux-arm64": "0.3.0-next.46",
36
- "@superdoc-dev/cli-windows-x64": "0.3.0-next.46",
37
- "@superdoc-dev/cli-linux-x64": "0.3.0-next.46"
33
+ "@superdoc-dev/cli-darwin-arm64": "0.3.0-next.48",
34
+ "@superdoc-dev/cli-linux-x64": "0.3.0-next.48",
35
+ "@superdoc-dev/cli-windows-x64": "0.3.0-next.48",
36
+ "@superdoc-dev/cli-linux-arm64": "0.3.0-next.48",
37
+ "@superdoc-dev/cli-darwin-x64": "0.3.0-next.48"
38
38
  },
39
39
  "scripts": {
40
40
  "predev": "node scripts/ensure-superdoc-build.js",