@harbour-enterprises/superdoc 1.3.0-next.5 → 1.3.0-next.6

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.
@@ -36366,7 +36366,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36366
36366
  static getStoredSuperdocVersion(docx) {
36367
36367
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
36368
36368
  }
36369
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.5") {
36369
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.6") {
36370
36370
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
36371
36371
  }
36372
36372
  /**
@@ -62076,7 +62076,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62076
62076
  return false;
62077
62077
  }
62078
62078
  };
62079
- const summaryVersion = "1.3.0-next.5";
62079
+ const summaryVersion = "1.3.0-next.6";
62080
62080
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
62081
62081
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
62082
62082
  function mapAttributes(attrs) {
@@ -64710,7 +64710,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64710
64710
  * Process collaboration migrations
64711
64711
  */
64712
64712
  processCollaborationMigrations() {
64713
- console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.5");
64713
+ console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.6");
64714
64714
  if (!this.options.ydoc) return;
64715
64715
  const metaMap = this.options.ydoc.getMap("meta");
64716
64716
  let docVersion = metaMap.get("version");
@@ -77585,8 +77585,7 @@ ${l}
77585
77585
  const titlePgEnabled = sectionTitlePg === true;
77586
77586
  const isFirstPageOfSection = sectionPageNumber === 1;
77587
77587
  if (isFirstPageOfSection && titlePgEnabled) {
77588
- if (hasFirst) return "first";
77589
- if (!hasDefault && !hasEven && !hasOdd) return null;
77588
+ if (hasFirst || hasDefault || hasEven || hasOdd) return "first";
77590
77589
  return null;
77591
77590
  }
77592
77591
  if (identifier.alternateHeaders) {
@@ -79643,6 +79642,45 @@ ${l}
79643
79642
  return height;
79644
79643
  };
79645
79644
  const headerContentHeights = options.headerContentHeights;
79645
+ const footerContentHeights = options.footerContentHeights;
79646
+ const headerContentHeightsByRId = options.headerContentHeightsByRId;
79647
+ const footerContentHeightsByRId = options.footerContentHeightsByRId;
79648
+ const getVariantTypeForPage = (sectionPageNumber, titlePgEnabled, alternateHeaders) => {
79649
+ if (sectionPageNumber === 1 && titlePgEnabled) {
79650
+ return "first";
79651
+ }
79652
+ return "default";
79653
+ };
79654
+ const getHeaderHeightForPage = (variantType, headerRef) => {
79655
+ if (headerRef && headerContentHeightsByRId?.has(headerRef)) {
79656
+ return validateContentHeight(headerContentHeightsByRId.get(headerRef));
79657
+ }
79658
+ if (headerContentHeights) {
79659
+ return validateContentHeight(headerContentHeights[variantType]);
79660
+ }
79661
+ return 0;
79662
+ };
79663
+ const getFooterHeightForPage = (variantType, footerRef) => {
79664
+ if (footerRef && footerContentHeightsByRId?.has(footerRef)) {
79665
+ return validateContentHeight(footerContentHeightsByRId.get(footerRef));
79666
+ }
79667
+ if (footerContentHeights) {
79668
+ return validateContentHeight(footerContentHeights[variantType]);
79669
+ }
79670
+ return 0;
79671
+ };
79672
+ const calculateEffectiveTopMargin = (headerContentHeight, currentHeaderDistance, baseTopMargin) => {
79673
+ if (headerContentHeight > 0) {
79674
+ return Math.max(baseTopMargin, currentHeaderDistance + headerContentHeight);
79675
+ }
79676
+ return baseTopMargin;
79677
+ };
79678
+ const calculateEffectiveBottomMargin = (footerContentHeight, currentFooterDistance, baseBottomMargin) => {
79679
+ if (footerContentHeight > 0) {
79680
+ return Math.max(baseBottomMargin, currentFooterDistance + footerContentHeight);
79681
+ }
79682
+ return baseBottomMargin;
79683
+ };
79646
79684
  const maxHeaderContentHeight = headerContentHeights ? Math.max(
79647
79685
  0,
79648
79686
  validateContentHeight(headerContentHeights.default),
@@ -79650,9 +79688,6 @@ ${l}
79650
79688
  validateContentHeight(headerContentHeights.even),
79651
79689
  validateContentHeight(headerContentHeights.odd)
79652
79690
  ) : 0;
79653
- const headerDistance = margins.header ?? margins.top;
79654
- const effectiveTopMargin = maxHeaderContentHeight > 0 ? Math.max(margins.top, headerDistance + maxHeaderContentHeight) : margins.top;
79655
- const footerContentHeights = options.footerContentHeights;
79656
79691
  const maxFooterContentHeight = footerContentHeights ? Math.max(
79657
79692
  0,
79658
79693
  validateContentHeight(footerContentHeights.default),
@@ -79660,8 +79695,12 @@ ${l}
79660
79695
  validateContentHeight(footerContentHeights.even),
79661
79696
  validateContentHeight(footerContentHeights.odd)
79662
79697
  ) : 0;
79698
+ const headerDistance = margins.header ?? margins.top;
79663
79699
  const footerDistance = margins.footer ?? margins.bottom;
79664
- const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
79700
+ const defaultHeaderHeight = getHeaderHeightForPage("default", void 0);
79701
+ const defaultFooterHeight = getFooterHeightForPage("default", void 0);
79702
+ const effectiveTopMargin = calculateEffectiveTopMargin(defaultHeaderHeight, headerDistance, margins.top);
79703
+ const effectiveBottomMargin = calculateEffectiveBottomMargin(defaultFooterHeight, footerDistance, margins.bottom);
79665
79704
  let activeTopMargin = effectiveTopMargin;
79666
79705
  let activeBottomMargin = effectiveBottomMargin;
79667
79706
  let activeLeftMargin = margins.left;
@@ -79670,6 +79709,10 @@ ${l}
79670
79709
  let pendingBottomMargin = null;
79671
79710
  let pendingLeftMargin = null;
79672
79711
  let pendingRightMargin = null;
79712
+ let activeSectionBaseTopMargin = margins.top;
79713
+ let activeSectionBaseBottomMargin = margins.bottom;
79714
+ let pendingSectionBaseTopMargin = null;
79715
+ let pendingSectionBaseBottomMargin = null;
79673
79716
  let activeHeaderDistance = margins.header ?? margins.top;
79674
79717
  let pendingHeaderDistance = null;
79675
79718
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -79875,6 +79918,7 @@ ${l}
79875
79918
  }
79876
79919
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
79877
79920
  let pendingSectionIndex = null;
79921
+ const sectionFirstPageNumbers = /* @__PURE__ */ new Map();
79878
79922
  const paginator = createPaginator({
79879
79923
  margins: paginatorMargins,
79880
79924
  getActiveTopMargin: () => activeTopMargin,
@@ -79888,6 +79932,7 @@ ${l}
79888
79932
  createPage,
79889
79933
  onNewPage: (state) => {
79890
79934
  if (!state) {
79935
+ const isEnteringNewSection = pendingSectionIndex !== null;
79891
79936
  const applied = applyPendingToActive({
79892
79937
  activeTopMargin,
79893
79938
  activeBottomMargin,
@@ -79955,7 +80000,69 @@ ${l}
79955
80000
  activeVAlign = pendingVAlign;
79956
80001
  pendingVAlign = null;
79957
80002
  }
80003
+ if (pendingSectionBaseTopMargin !== null) {
80004
+ activeSectionBaseTopMargin = pendingSectionBaseTopMargin;
80005
+ pendingSectionBaseTopMargin = null;
80006
+ }
80007
+ if (pendingSectionBaseBottomMargin !== null) {
80008
+ activeSectionBaseBottomMargin = pendingSectionBaseBottomMargin;
80009
+ pendingSectionBaseBottomMargin = null;
80010
+ }
79958
80011
  pageCount += 1;
80012
+ const newPageNumber = pageCount;
80013
+ if (isEnteringNewSection || !sectionFirstPageNumbers.has(activeSectionIndex)) {
80014
+ sectionFirstPageNumbers.set(activeSectionIndex, newPageNumber);
80015
+ }
80016
+ const firstPageInSection = sectionFirstPageNumbers.get(activeSectionIndex) ?? newPageNumber;
80017
+ const sectionPageNumber = newPageNumber - firstPageInSection + 1;
80018
+ const sectionMetadata = sectionMetadataList[activeSectionIndex];
80019
+ const titlePgEnabled = sectionMetadata?.titlePg ?? false;
80020
+ const variantType = getVariantTypeForPage(sectionPageNumber, titlePgEnabled);
80021
+ let headerRef = activeSectionRefs?.headerRefs?.[variantType];
80022
+ let footerRef = activeSectionRefs?.footerRefs?.[variantType];
80023
+ let effectiveVariantType = variantType;
80024
+ if (!headerRef && variantType !== "default" && activeSectionIndex > 0) {
80025
+ const prevSectionMetadata = sectionMetadataList[activeSectionIndex - 1];
80026
+ if (prevSectionMetadata?.headerRefs?.[variantType]) {
80027
+ headerRef = prevSectionMetadata.headerRefs[variantType];
80028
+ layoutLog(
80029
+ `[Layout] Page ${newPageNumber}: Inheriting header '${variantType}' from section ${activeSectionIndex - 1}: ${headerRef}`
80030
+ );
80031
+ }
80032
+ }
80033
+ if (!footerRef && variantType !== "default" && activeSectionIndex > 0) {
80034
+ const prevSectionMetadata = sectionMetadataList[activeSectionIndex - 1];
80035
+ if (prevSectionMetadata?.footerRefs?.[variantType]) {
80036
+ footerRef = prevSectionMetadata.footerRefs[variantType];
80037
+ layoutLog(
80038
+ `[Layout] Page ${newPageNumber}: Inheriting footer '${variantType}' from section ${activeSectionIndex - 1}: ${footerRef}`
80039
+ );
80040
+ }
80041
+ }
80042
+ if (!headerRef && variantType !== "default" && activeSectionRefs?.headerRefs?.default) {
80043
+ headerRef = activeSectionRefs.headerRefs.default;
80044
+ effectiveVariantType = "default";
80045
+ }
80046
+ if (!footerRef && variantType !== "default" && activeSectionRefs?.footerRefs?.default) {
80047
+ footerRef = activeSectionRefs.footerRefs.default;
80048
+ }
80049
+ const headerHeight = getHeaderHeightForPage(effectiveVariantType, headerRef);
80050
+ const footerHeight = getFooterHeightForPage(
80051
+ variantType !== "default" && !activeSectionRefs?.footerRefs?.[variantType] ? "default" : variantType,
80052
+ footerRef
80053
+ );
80054
+ activeTopMargin = calculateEffectiveTopMargin(headerHeight, activeHeaderDistance, activeSectionBaseTopMargin);
80055
+ activeBottomMargin = calculateEffectiveBottomMargin(
80056
+ footerHeight,
80057
+ activeFooterDistance,
80058
+ activeSectionBaseBottomMargin
80059
+ );
80060
+ layoutLog(
80061
+ `[Layout] Page ${newPageNumber}: Using variant '${variantType}' - headerHeight: ${headerHeight}, footerHeight: ${footerHeight}`
80062
+ );
80063
+ layoutLog(
80064
+ `[Layout] Page ${newPageNumber}: Adjusted margins - top: ${activeTopMargin}, bottom: ${activeBottomMargin} (base: ${activeSectionBaseTopMargin}, ${activeSectionBaseBottomMargin})`
80065
+ );
79959
80066
  return;
79960
80067
  }
79961
80068
  if (state?.page) {
@@ -80161,6 +80268,20 @@ ${l}
80161
80268
  pendingColumns = updatedState.pendingColumns;
80162
80269
  activeOrientation = updatedState.activeOrientation;
80163
80270
  pendingOrientation = updatedState.pendingOrientation;
80271
+ const isFirstSection = effectiveBlock.attrs?.isFirstSection && states.length === 0;
80272
+ const blockTopMargin = effectiveBlock.margins?.top;
80273
+ const blockBottomMargin = effectiveBlock.margins?.bottom;
80274
+ if (isFirstSection) {
80275
+ activeSectionBaseTopMargin = typeof blockTopMargin === "number" ? blockTopMargin : margins.top;
80276
+ activeSectionBaseBottomMargin = typeof blockBottomMargin === "number" ? blockBottomMargin : margins.bottom;
80277
+ } else if (blockTopMargin !== void 0 || blockBottomMargin !== void 0) {
80278
+ if (blockTopMargin !== void 0) {
80279
+ pendingSectionBaseTopMargin = typeof blockTopMargin === "number" ? blockTopMargin : margins.top;
80280
+ }
80281
+ if (blockBottomMargin !== void 0) {
80282
+ pendingSectionBaseBottomMargin = typeof blockBottomMargin === "number" ? blockBottomMargin : margins.bottom;
80283
+ }
80284
+ }
80164
80285
  if (effectiveBlock.vAlign) {
80165
80286
  const isFirstSection2 = effectiveBlock.attrs?.isFirstSection && states.length === 0;
80166
80287
  if (isFirstSection2) {
@@ -80179,7 +80300,6 @@ ${l}
80179
80300
  }
80180
80301
  const sectionIndexRaw = effectiveBlock.attrs?.sectionIndex;
80181
80302
  const metadataIndex = typeof sectionIndexRaw === "number" ? sectionIndexRaw : Number(sectionIndexRaw ?? NaN);
80182
- const isFirstSection = effectiveBlock.attrs?.isFirstSection && states.length === 0;
80183
80303
  if (Number.isFinite(metadataIndex)) {
80184
80304
  if (isFirstSection) {
80185
80305
  activeSectionIndex = metadataIndex;
@@ -82369,6 +82489,7 @@ ${l}
82369
82489
  `[Perf] 4.1 Measure all blocks: ${(measureEnd - measureStart).toFixed(2)}ms (${cacheMisses} measured, ${cacheHits} cached)`
82370
82490
  );
82371
82491
  let headerContentHeights;
82492
+ let headerContentHeightsByRId;
82372
82493
  const hasHeaderBlocks = headerFooter?.headerBlocks && Object.keys(headerFooter.headerBlocks).length > 0;
82373
82494
  const hasHeaderBlocksByRId = headerFooter?.headerBlocksByRId && headerFooter.headerBlocksByRId.size > 0;
82374
82495
  if (headerFooter?.constraints && (hasHeaderBlocks || hasHeaderBlocksByRId)) {
@@ -82408,7 +82529,8 @@ ${l}
82408
82529
  }
82409
82530
  }
82410
82531
  if (hasHeaderBlocksByRId && headerFooter.headerBlocksByRId) {
82411
- for (const [_rId, blocks2] of headerFooter.headerBlocksByRId) {
82532
+ headerContentHeightsByRId = /* @__PURE__ */ new Map();
82533
+ for (const [rId, blocks2] of headerFooter.headerBlocksByRId) {
82412
82534
  if (!blocks2 || blocks2.length === 0) continue;
82413
82535
  const measureConstraints = {
82414
82536
  maxWidth: headerFooter.constraints.width,
@@ -82420,8 +82542,7 @@ ${l}
82420
82542
  height: headerFooter.constraints.height
82421
82543
  });
82422
82544
  if (layout2.height > 0) {
82423
- const currentDefault = headerContentHeights.default ?? 0;
82424
- headerContentHeights.default = Math.max(currentDefault, layout2.height);
82545
+ headerContentHeightsByRId.set(rId, layout2.height);
82425
82546
  }
82426
82547
  }
82427
82548
  }
@@ -82429,6 +82550,7 @@ ${l}
82429
82550
  perfLog(`[Perf] 4.1.5 Pre-layout headers for height: ${(hfPreEnd - hfPreStart).toFixed(2)}ms`);
82430
82551
  }
82431
82552
  let footerContentHeights;
82553
+ let footerContentHeightsByRId;
82432
82554
  const hasFooterBlocks = headerFooter?.footerBlocks && Object.keys(headerFooter.footerBlocks).length > 0;
82433
82555
  const hasFooterBlocksByRId = headerFooter?.footerBlocksByRId && headerFooter.footerBlocksByRId.size > 0;
82434
82556
  if (headerFooter?.constraints && (hasFooterBlocks || hasFooterBlocksByRId)) {
@@ -82471,7 +82593,8 @@ ${l}
82471
82593
  }
82472
82594
  }
82473
82595
  if (hasFooterBlocksByRId && headerFooter.footerBlocksByRId) {
82474
- for (const [_rId, blocks2] of headerFooter.footerBlocksByRId) {
82596
+ footerContentHeightsByRId = /* @__PURE__ */ new Map();
82597
+ for (const [rId, blocks2] of headerFooter.footerBlocksByRId) {
82475
82598
  if (!blocks2 || blocks2.length === 0) continue;
82476
82599
  const measureConstraints = {
82477
82600
  maxWidth: headerFooter.constraints.width,
@@ -82483,8 +82606,7 @@ ${l}
82483
82606
  height: headerFooter.constraints.height
82484
82607
  });
82485
82608
  if (layout2.height > 0) {
82486
- const currentDefault = footerContentHeights.default ?? 0;
82487
- footerContentHeights.default = Math.max(currentDefault, layout2.height);
82609
+ footerContentHeightsByRId.set(rId, layout2.height);
82488
82610
  }
82489
82611
  }
82490
82612
  }
@@ -82499,9 +82621,13 @@ ${l}
82499
82621
  let layout = layoutDocument(nextBlocks, measures, {
82500
82622
  ...options,
82501
82623
  headerContentHeights,
82502
- // Pass header heights to prevent overlap
82624
+ // Pass header heights to prevent overlap (per-variant)
82503
82625
  footerContentHeights,
82504
- // Pass footer heights to prevent overlap
82626
+ // Pass footer heights to prevent overlap (per-variant)
82627
+ headerContentHeightsByRId,
82628
+ // Pass header heights by rId for per-page margin calculation
82629
+ footerContentHeightsByRId,
82630
+ // Pass footer heights by rId for per-page margin calculation
82505
82631
  remeasureParagraph: (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent)
82506
82632
  });
82507
82633
  const layoutEnd = performance.now();
@@ -82549,9 +82675,13 @@ ${l}
82549
82675
  layout = layoutDocument(currentBlocks, currentMeasures, {
82550
82676
  ...options,
82551
82677
  headerContentHeights,
82552
- // Pass header heights to prevent overlap
82678
+ // Pass header heights to prevent overlap (per-variant)
82553
82679
  footerContentHeights,
82554
- // Pass footer heights to prevent overlap
82680
+ // Pass footer heights to prevent overlap (per-variant)
82681
+ headerContentHeightsByRId,
82682
+ // Pass header heights by rId for per-page margin calculation
82683
+ footerContentHeightsByRId,
82684
+ // Pass footer heights by rId for per-page margin calculation
82555
82685
  remeasureParagraph: (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent)
82556
82686
  });
82557
82687
  const relayoutEnd = performance.now();
@@ -100036,7 +100166,26 @@ ${l}
100036
100166
  const firstPageInSection = sectionFirstPageNumbers.get(sectionIndex);
100037
100167
  const sectionPageNumber = typeof firstPageInSection === "number" ? pageNumber - firstPageInSection + 1 : pageNumber;
100038
100168
  const headerFooterType = multiSectionId ? getHeaderFooterTypeForSection(pageNumber, sectionIndex, multiSectionId, { kind, sectionPageNumber }) : getHeaderFooterType(pageNumber, legacyIdentifier, { kind });
100039
- const sectionRId = page?.sectionRefs && kind === "header" ? page.sectionRefs.headerRefs?.[headerFooterType] ?? void 0 : page?.sectionRefs && kind === "footer" ? page.sectionRefs.footerRefs?.[headerFooterType] ?? void 0 : void 0;
100169
+ let sectionRId;
100170
+ if (page?.sectionRefs && kind === "header") {
100171
+ sectionRId = page.sectionRefs.headerRefs?.[headerFooterType];
100172
+ if (!sectionRId && headerFooterType && headerFooterType !== "default" && sectionIndex > 0 && multiSectionId) {
100173
+ const prevSectionIds = multiSectionId.sectionHeaderIds.get(sectionIndex - 1);
100174
+ sectionRId = prevSectionIds?.[headerFooterType] ?? void 0;
100175
+ }
100176
+ if (!sectionRId && headerFooterType !== "default") {
100177
+ sectionRId = page.sectionRefs.headerRefs?.default;
100178
+ }
100179
+ } else if (page?.sectionRefs && kind === "footer") {
100180
+ sectionRId = page.sectionRefs.footerRefs?.[headerFooterType];
100181
+ if (!sectionRId && headerFooterType && headerFooterType !== "default" && sectionIndex > 0 && multiSectionId) {
100182
+ const prevSectionIds = multiSectionId.sectionFooterIds.get(sectionIndex - 1);
100183
+ sectionRId = prevSectionIds?.[headerFooterType] ?? void 0;
100184
+ }
100185
+ if (!sectionRId && headerFooterType !== "default") {
100186
+ sectionRId = page.sectionRefs.footerRefs?.default;
100187
+ }
100188
+ }
100040
100189
  if (!headerFooterType) {
100041
100190
  return null;
100042
100191
  }
@@ -143864,7 +144013,7 @@ ${reason}`);
143864
144013
  this.config.colors = shuffleArray(this.config.colors);
143865
144014
  this.userColorMap = /* @__PURE__ */ new Map();
143866
144015
  this.colorIndex = 0;
143867
- this.version = "1.3.0-next.5";
144016
+ this.version = "1.3.0-next.6";
143868
144017
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
143869
144018
  this.superdocId = config2.superdocId || v4();
143870
144019
  this.colors = this.config.colors;