@harbour-enterprises/superdoc 1.1.0 → 1.1.2

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 (28) hide show
  1. package/dist/chunks/{PdfViewer-ClRuoPWm.cjs → PdfViewer-Ba04yS5H.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-BgOzYGGE.es.js → PdfViewer-Cdnpadpf.es.js} +1 -1
  3. package/dist/chunks/{index-LKlY0uOW-D_ZqJ-GU.es.js → index-BBA3d9LK-CHGIE1LG.es.js} +1 -1
  4. package/dist/chunks/{index-LKlY0uOW-B70pXIte.cjs → index-BBA3d9LK-DdrFtQwl.cjs} +1 -1
  5. package/dist/chunks/{index-BKEi2CRJ.es.js → index-DSXEhZoY.es.js} +25 -13
  6. package/dist/chunks/{index-35PXpdi_.cjs → index-vuWEvtXh.cjs} +25 -13
  7. package/dist/chunks/{super-editor.es-Dt3pSUMk.es.js → super-editor.es-B1nGbDJe.es.js} +105 -48
  8. package/dist/chunks/{super-editor.es-COhOfA81.cjs → super-editor.es-DGCgR7rL.cjs} +105 -48
  9. package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
  10. package/dist/super-editor/ai-writer.es.js +2 -2
  11. package/dist/super-editor/chunks/{converter-CB_4LqhI.js → converter-BSBbIF0S.js} +1 -1
  12. package/dist/super-editor/chunks/{docx-zipper-0-ibLeHA.js → docx-zipper-Bh6HZNKL.js} +1 -1
  13. package/dist/super-editor/chunks/{editor-BKIkgBE0.js → editor-DWTzwjRX.js} +106 -49
  14. package/dist/super-editor/chunks/{index-LKlY0uOW.js → index-BBA3d9LK.js} +1 -1
  15. package/dist/super-editor/chunks/{toolbar-CfarRdhy.js → toolbar-Dpya3xe7.js} +2 -2
  16. package/dist/super-editor/converter.es.js +1 -1
  17. package/dist/super-editor/docx-zipper.es.js +2 -2
  18. package/dist/super-editor/editor.es.js +3 -3
  19. package/dist/super-editor/file-zipper.es.js +1 -1
  20. package/dist/super-editor/super-editor.es.js +6 -6
  21. package/dist/super-editor/toolbar.es.js +2 -2
  22. package/dist/super-editor.cjs +1 -1
  23. package/dist/super-editor.es.js +1 -1
  24. package/dist/superdoc.cjs +2 -2
  25. package/dist/superdoc.es.js +2 -2
  26. package/dist/superdoc.umd.js +129 -60
  27. package/dist/superdoc.umd.js.map +1 -1
  28. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const vue = require("./vue-gvuFr0vx.cjs");
4
- const superdoc = require("./index-35PXpdi_.cjs");
4
+ const superdoc = require("./index-vuWEvtXh.cjs");
5
5
  function self(vars) {
6
6
  const {
7
7
  opacityDisabled,
@@ -1,5 +1,5 @@
1
1
  import { y as defineComponent, A as h, P as Transition, a0 as process$1, K as watchEffect, a as computed, r as ref, j as onMounted, X as onUnmounted, b as createElementBlock, o as openBlock, f as createBaseVNode, e as createCommentVNode, s as createVNode, x as unref } from "./vue-CLFbn_1r.es.js";
2
- import { d as derived, c, a as cB, f as fadeInTransition, b as cM, N as NBaseLoading, w as warnOnce, u as useConfig, e as useTheme, p as pxfy, g as createKey, h as useThemeClass, i as useCompitable, _ as _export_sfc, j as useSuperdocStore, s as storeToRefs, k as useSelection } from "./index-BKEi2CRJ.es.js";
2
+ import { d as derived, c, a as cB, f as fadeInTransition, b as cM, N as NBaseLoading, w as warnOnce, u as useConfig, e as useTheme, p as pxfy, g as createKey, h as useThemeClass, i as useCompitable, _ as _export_sfc, j as useSuperdocStore, s as storeToRefs, k as useSelection } from "./index-DSXEhZoY.es.js";
3
3
  function self(vars) {
4
4
  const {
5
5
  opacityDisabled,
@@ -1,4 +1,4 @@
1
- import { s as getDefaultExportFromCjs$2 } from "./super-editor.es-Dt3pSUMk.es.js";
1
+ import { s as getDefaultExportFromCjs$2 } from "./super-editor.es-B1nGbDJe.es.js";
2
2
  import { V as VFile } from "./index-CvBqQJbG-CvBqQJbG.es.js";
3
3
  function bail(error) {
4
4
  if (error) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const superEditor_es = require("./super-editor.es-COhOfA81.cjs");
3
+ const superEditor_es = require("./super-editor.es-DGCgR7rL.cjs");
4
4
  const indexCvBqQJbG = require("./index-CvBqQJbG-Dwm0THD7.cjs");
5
5
  function bail(error) {
6
6
  if (error) {
@@ -1,4 +1,4 @@
1
- import { q as index, C as CommentsPluginKey, h as TrackChangesBasePluginKey, E as Editor, n as getRichTextExtensions, f as SuperInput, P as PresentationEditor, e as SuperEditor, A as AIWriter, g as SuperToolbar, i as createZip } from "./super-editor.es-Dt3pSUMk.es.js";
1
+ import { q as index, C as CommentsPluginKey, h as TrackChangesBasePluginKey, E as Editor, n as getRichTextExtensions, f as SuperInput, P as PresentationEditor, e as SuperEditor, A as AIWriter, g as SuperToolbar, i as createZip } from "./super-editor.es-B1nGbDJe.es.js";
2
2
  import { B as BlankDOCX } from "./blank-docx-ABm6XYAA.es.js";
3
3
  import { E as EventEmitter } from "./eventemitter3-D_2kqkfV.es.js";
4
4
  import { HocuspocusProvider, HocuspocusProviderWebsocket } from "@hocuspocus/provider";
@@ -17470,7 +17470,7 @@ const _sfc_main = {
17470
17470
  __name: "SuperDoc",
17471
17471
  emits: ["selection-update"],
17472
17472
  setup(__props, { emit: __emit }) {
17473
- const PdfViewer = defineAsyncComponent(() => import("./PdfViewer-BgOzYGGE.es.js"));
17473
+ const PdfViewer = defineAsyncComponent(() => import("./PdfViewer-Cdnpadpf.es.js"));
17474
17474
  const superdocStore = useSuperdocStore();
17475
17475
  const commentsStore = useCommentsStore();
17476
17476
  const {
@@ -18268,6 +18268,8 @@ const DEFAULT_USER = Object.freeze({
18268
18268
  class SuperDoc extends EventEmitter {
18269
18269
  /** @type {Array<string>} */
18270
18270
  static allowedTypes = [DOCX, PDF, HTML];
18271
+ /** @type {boolean} */
18272
+ #destroyed = false;
18271
18273
  /** @type {string} */
18272
18274
  version;
18273
18275
  /** @type {User[]} */
@@ -18374,12 +18376,16 @@ class SuperDoc extends EventEmitter {
18374
18376
  this.config.colors = shuffleArray(this.config.colors);
18375
18377
  this.userColorMap = /* @__PURE__ */ new Map();
18376
18378
  this.colorIndex = 0;
18377
- this.version = "1.1.0";
18379
+ this.version = "1.1.2";
18378
18380
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
18379
18381
  this.superdocId = config.superdocId || v4();
18380
18382
  this.colors = this.config.colors;
18381
18383
  this.#initDocuments();
18382
18384
  await this.#initCollaboration(this.config.modules);
18385
+ if (this.#destroyed) {
18386
+ this.#cleanupCollaboration();
18387
+ return;
18388
+ }
18383
18389
  if (this.config.cspNonce) this.#patchNaiveUIStyles();
18384
18390
  this.#initVueApp();
18385
18391
  this.#initListeners();
@@ -19065,14 +19071,10 @@ class SuperDoc extends EventEmitter {
19065
19071
  return result;
19066
19072
  }
19067
19073
  /**
19068
- * Destroy the superdoc instance
19074
+ * Clean up collaboration resources (providers, ydocs, sockets)
19069
19075
  * @returns {void}
19070
19076
  */
19071
- destroy() {
19072
- if (!this.app) {
19073
- return;
19074
- }
19075
- this.#log("[superdoc] Unmounting app");
19077
+ #cleanupCollaboration() {
19076
19078
  this.config.socket?.cancelWebsocketRetry();
19077
19079
  this.config.socket?.disconnect();
19078
19080
  this.config.socket?.destroy();
@@ -19080,12 +19082,22 @@ class SuperDoc extends EventEmitter {
19080
19082
  this.provider?.disconnect();
19081
19083
  this.provider?.destroy();
19082
19084
  this.config.documents.forEach((doc) => {
19083
- if (doc.provider) {
19084
- doc.provider.disconnect();
19085
- doc.provider.destroy();
19086
- }
19085
+ doc.provider?.disconnect();
19086
+ doc.provider?.destroy();
19087
19087
  doc.ydoc?.destroy();
19088
19088
  });
19089
+ }
19090
+ /**
19091
+ * Destroy the superdoc instance
19092
+ * @returns {void}
19093
+ */
19094
+ destroy() {
19095
+ this.#destroyed = true;
19096
+ this.#cleanupCollaboration();
19097
+ if (!this.app) {
19098
+ return;
19099
+ }
19100
+ this.#log("[superdoc] Unmounting app");
19089
19101
  this.superdocStore.reset();
19090
19102
  this.app.unmount();
19091
19103
  this.removeAllListeners();
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const superEditor_es = require("./super-editor.es-COhOfA81.cjs");
2
+ const superEditor_es = require("./super-editor.es-DGCgR7rL.cjs");
3
3
  const blankDocx = require("./blank-docx-DfW3Eeh2.cjs");
4
4
  const eventemitter3 = require("./eventemitter3-DIclNhoR.cjs");
5
5
  const provider = require("@hocuspocus/provider");
@@ -17487,7 +17487,7 @@ const _sfc_main = {
17487
17487
  __name: "SuperDoc",
17488
17488
  emits: ["selection-update"],
17489
17489
  setup(__props, { emit: __emit }) {
17490
- const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-ClRuoPWm.cjs")));
17490
+ const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-Ba04yS5H.cjs")));
17491
17491
  const superdocStore = useSuperdocStore();
17492
17492
  const commentsStore = useCommentsStore();
17493
17493
  const {
@@ -18285,6 +18285,8 @@ const DEFAULT_USER = Object.freeze({
18285
18285
  class SuperDoc extends eventemitter3.EventEmitter {
18286
18286
  /** @type {Array<string>} */
18287
18287
  static allowedTypes = [DOCX, PDF, HTML];
18288
+ /** @type {boolean} */
18289
+ #destroyed = false;
18288
18290
  /** @type {string} */
18289
18291
  version;
18290
18292
  /** @type {User[]} */
@@ -18391,12 +18393,16 @@ class SuperDoc extends eventemitter3.EventEmitter {
18391
18393
  this.config.colors = shuffleArray(this.config.colors);
18392
18394
  this.userColorMap = /* @__PURE__ */ new Map();
18393
18395
  this.colorIndex = 0;
18394
- this.version = "1.1.0";
18396
+ this.version = "1.1.2";
18395
18397
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
18396
18398
  this.superdocId = config.superdocId || uuid.v4();
18397
18399
  this.colors = this.config.colors;
18398
18400
  this.#initDocuments();
18399
18401
  await this.#initCollaboration(this.config.modules);
18402
+ if (this.#destroyed) {
18403
+ this.#cleanupCollaboration();
18404
+ return;
18405
+ }
18400
18406
  if (this.config.cspNonce) this.#patchNaiveUIStyles();
18401
18407
  this.#initVueApp();
18402
18408
  this.#initListeners();
@@ -19082,14 +19088,10 @@ class SuperDoc extends eventemitter3.EventEmitter {
19082
19088
  return result;
19083
19089
  }
19084
19090
  /**
19085
- * Destroy the superdoc instance
19091
+ * Clean up collaboration resources (providers, ydocs, sockets)
19086
19092
  * @returns {void}
19087
19093
  */
19088
- destroy() {
19089
- if (!this.app) {
19090
- return;
19091
- }
19092
- this.#log("[superdoc] Unmounting app");
19094
+ #cleanupCollaboration() {
19093
19095
  this.config.socket?.cancelWebsocketRetry();
19094
19096
  this.config.socket?.disconnect();
19095
19097
  this.config.socket?.destroy();
@@ -19097,12 +19099,22 @@ class SuperDoc extends eventemitter3.EventEmitter {
19097
19099
  this.provider?.disconnect();
19098
19100
  this.provider?.destroy();
19099
19101
  this.config.documents.forEach((doc) => {
19100
- if (doc.provider) {
19101
- doc.provider.disconnect();
19102
- doc.provider.destroy();
19103
- }
19102
+ doc.provider?.disconnect();
19103
+ doc.provider?.destroy();
19104
19104
  doc.ydoc?.destroy();
19105
19105
  });
19106
+ }
19107
+ /**
19108
+ * Destroy the superdoc instance
19109
+ * @returns {void}
19110
+ */
19111
+ destroy() {
19112
+ this.#destroyed = true;
19113
+ this.#cleanupCollaboration();
19114
+ if (!this.app) {
19115
+ return;
19116
+ }
19117
+ this.#log("[superdoc] Unmounting app");
19106
19118
  this.superdocStore.reset();
19107
19119
  this.app.unmount();
19108
19120
  this.removeAllListeners();
@@ -42410,7 +42410,7 @@ const _SuperConverter = class _SuperConverter2 {
42410
42410
  static getStoredSuperdocVersion(docx) {
42411
42411
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42412
42412
  }
42413
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.1.0") {
42413
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.1.2") {
42414
42414
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42415
42415
  }
42416
42416
  /**
@@ -60491,7 +60491,7 @@ const isHeadless = (editor) => {
60491
60491
  const shouldSkipNodeView = (editor) => {
60492
60492
  return isHeadless(editor);
60493
60493
  };
60494
- const summaryVersion = "1.1.0";
60494
+ const summaryVersion = "1.1.2";
60495
60495
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
60496
60496
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
60497
60497
  function mapAttributes(attrs) {
@@ -61280,7 +61280,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
61280
61280
  { default: remarkStringify },
61281
61281
  { default: remarkGfm }
61282
61282
  ] = await Promise.all([
61283
- import("./index-LKlY0uOW-D_ZqJ-GU.es.js"),
61283
+ import("./index-BBA3d9LK-CHGIE1LG.es.js"),
61284
61284
  import("./index-DRCvimau-Cw339678.es.js"),
61285
61285
  import("./index-C_x_N6Uh-DJn8hIEt.es.js"),
61286
61286
  import("./index-D_sWOSiG-DE96TaT5.es.js"),
@@ -61485,7 +61485,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
61485
61485
  * Process collaboration migrations
61486
61486
  */
61487
61487
  processCollaborationMigrations() {
61488
- console.debug("[checkVersionMigrations] Current editor version", "1.1.0");
61488
+ console.debug("[checkVersionMigrations] Current editor version", "1.1.2");
61489
61489
  if (!this.options.ydoc) return;
61490
61490
  const metaMap = this.options.ydoc.getMap("meta");
61491
61491
  let docVersion = metaMap.get("version");
@@ -75041,13 +75041,13 @@ function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight
75041
75041
  if (maxHeaderContentHeight > 0) {
75042
75042
  return Math.max(baseTop, headerDistance + maxHeaderContentHeight);
75043
75043
  }
75044
- return Math.max(baseTop, headerDistance);
75044
+ return baseTop;
75045
75045
  };
75046
75046
  const calcRequiredBottomMargin = (footerDistance, baseBottom) => {
75047
75047
  if (maxFooterContentHeight > 0) {
75048
75048
  return Math.max(baseBottom, footerDistance + maxFooterContentHeight);
75049
75049
  }
75050
- return Math.max(baseBottom, footerDistance);
75050
+ return baseBottom;
75051
75051
  };
75052
75052
  if (block.attrs?.isFirstSection && !next.hasAnyPages) {
75053
75053
  if (block.pageSize) {
@@ -75548,6 +75548,11 @@ function layoutParagraphBlock(ctx2, anchors) {
75548
75548
  const prevTrailing = state2.trailingSpacing ?? 0;
75549
75549
  const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
75550
75550
  if (state2.cursorY + neededSpacingBefore > state2.contentBottom) {
75551
+ if (state2.cursorY <= state2.topMargin) {
75552
+ state2.trailingSpacing = 0;
75553
+ appliedSpacingBefore = true;
75554
+ break;
75555
+ }
75551
75556
  state2 = advanceColumn(state2);
75552
75557
  if (state2.trailingSpacing == null) state2.trailingSpacing = 0;
75553
75558
  continue;
@@ -76863,12 +76868,12 @@ function layoutDocument(blocks, measures, options = {}) {
76863
76868
  next.pendingFooterDistance = footerDistance2;
76864
76869
  }
76865
76870
  if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
76866
- const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : headerDistance2;
76871
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : 0;
76867
76872
  next.activeTopMargin = Math.max(sectionTop, requiredTop);
76868
76873
  next.pendingTopMargin = next.activeTopMargin;
76869
76874
  }
76870
76875
  if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
76871
- const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
76876
+ const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : 0;
76872
76877
  next.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
76873
76878
  next.pendingBottomMargin = next.activeBottomMargin;
76874
76879
  }
@@ -77618,7 +77623,7 @@ function layoutHeaderFooter(blocks, measures, constraints) {
77618
77623
  throw new Error("layoutHeaderFooter: width must be positive");
77619
77624
  }
77620
77625
  if (!Number.isFinite(height) || height <= 0) {
77621
- throw new Error("layoutHeaderFooter: height must be positive");
77626
+ return { pages: [], height: 0 };
77622
77627
  }
77623
77628
  const maxBehindDocOverflow = Math.max(192, height * 4);
77624
77629
  const minBehindDocY = -maxBehindDocOverflow;
@@ -79463,7 +79468,9 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79463
79468
  `[Perf] 4.1 Measure all blocks: ${(measureEnd - measureStart).toFixed(2)}ms (${cacheMisses} measured, ${cacheHits} cached)`
79464
79469
  );
79465
79470
  let headerContentHeights;
79466
- if (headerFooter?.constraints && headerFooter.headerBlocks) {
79471
+ const hasHeaderBlocks = headerFooter?.headerBlocks && Object.keys(headerFooter.headerBlocks).length > 0;
79472
+ const hasHeaderBlocksByRId = headerFooter?.headerBlocksByRId && headerFooter.headerBlocksByRId.size > 0;
79473
+ if (headerFooter?.constraints && (hasHeaderBlocks || hasHeaderBlocksByRId)) {
79467
79474
  const hfPreStart = performance.now();
79468
79475
  const measureFn = headerFooter.measure ?? measureBlock2;
79469
79476
  invalidateHeaderFooterCache(
@@ -79475,25 +79482,45 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79475
79482
  options.sectionMetadata
79476
79483
  );
79477
79484
  const HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT = 1;
79478
- const preHeaderLayouts = await layoutHeaderFooterWithCache(
79479
- headerFooter.headerBlocks,
79480
- headerFooter.constraints,
79481
- measureFn,
79482
- headerMeasureCache,
79483
- HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
79484
- void 0
79485
- // No page resolver needed for height calculation
79486
- );
79487
79485
  const isValidHeaderType = (key2) => {
79488
79486
  return ["default", "first", "even", "odd"].includes(key2);
79489
79487
  };
79490
79488
  headerContentHeights = {};
79491
- for (const [type2, value] of Object.entries(preHeaderLayouts)) {
79492
- if (!isValidHeaderType(type2)) continue;
79493
- if (value?.layout && typeof value.layout.height === "number") {
79494
- const height = value.layout.height;
79495
- if (Number.isFinite(height) && height >= 0) {
79496
- headerContentHeights[type2] = height;
79489
+ if (hasHeaderBlocks && headerFooter.headerBlocks) {
79490
+ const preHeaderLayouts = await layoutHeaderFooterWithCache(
79491
+ headerFooter.headerBlocks,
79492
+ headerFooter.constraints,
79493
+ measureFn,
79494
+ headerMeasureCache,
79495
+ HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
79496
+ void 0
79497
+ // No page resolver needed for height calculation
79498
+ );
79499
+ for (const [type2, value] of Object.entries(preHeaderLayouts)) {
79500
+ if (!isValidHeaderType(type2)) continue;
79501
+ if (value?.layout && typeof value.layout.height === "number") {
79502
+ const height = value.layout.height;
79503
+ if (Number.isFinite(height) && height >= 0) {
79504
+ headerContentHeights[type2] = height;
79505
+ }
79506
+ }
79507
+ }
79508
+ }
79509
+ if (hasHeaderBlocksByRId && headerFooter.headerBlocksByRId) {
79510
+ for (const [_rId, blocks] of headerFooter.headerBlocksByRId) {
79511
+ if (!blocks || blocks.length === 0) continue;
79512
+ const measureConstraints = {
79513
+ maxWidth: headerFooter.constraints.width,
79514
+ maxHeight: headerFooter.constraints.height
79515
+ };
79516
+ const measures2 = await Promise.all(blocks.map((block) => measureFn(block, measureConstraints)));
79517
+ const layout2 = layoutHeaderFooter(blocks, measures2, {
79518
+ width: headerFooter.constraints.width,
79519
+ height: headerFooter.constraints.height
79520
+ });
79521
+ if (layout2.height > 0) {
79522
+ const currentDefault = headerContentHeights.default ?? 0;
79523
+ headerContentHeights.default = Math.max(currentDefault, layout2.height);
79497
79524
  }
79498
79525
  }
79499
79526
  }
@@ -79501,10 +79528,12 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79501
79528
  perfLog(`[Perf] 4.1.5 Pre-layout headers for height: ${(hfPreEnd - hfPreStart).toFixed(2)}ms`);
79502
79529
  }
79503
79530
  let footerContentHeights;
79504
- if (headerFooter?.constraints && headerFooter.footerBlocks) {
79531
+ const hasFooterBlocks = headerFooter?.footerBlocks && Object.keys(headerFooter.footerBlocks).length > 0;
79532
+ const hasFooterBlocksByRId = headerFooter?.footerBlocksByRId && headerFooter.footerBlocksByRId.size > 0;
79533
+ if (headerFooter?.constraints && (hasFooterBlocks || hasFooterBlocksByRId)) {
79505
79534
  const footerPreStart = performance.now();
79506
79535
  const measureFn = headerFooter.measure ?? measureBlock2;
79507
- if (!headerFooter.headerBlocks) {
79536
+ if (!hasHeaderBlocks && !hasHeaderBlocksByRId) {
79508
79537
  invalidateHeaderFooterCache(
79509
79538
  headerMeasureCache,
79510
79539
  headerFooterCacheState,
@@ -79515,26 +79544,46 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79515
79544
  );
79516
79545
  }
79517
79546
  const FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT = 1;
79547
+ const isValidFooterType = (key2) => {
79548
+ return ["default", "first", "even", "odd"].includes(key2);
79549
+ };
79550
+ footerContentHeights = {};
79518
79551
  try {
79519
- const preFooterLayouts = await layoutHeaderFooterWithCache(
79520
- headerFooter.footerBlocks,
79521
- headerFooter.constraints,
79522
- measureFn,
79523
- headerMeasureCache,
79524
- FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
79525
- void 0
79526
- // No page resolver needed for height calculation
79527
- );
79528
- const isValidFooterType = (key2) => {
79529
- return ["default", "first", "even", "odd"].includes(key2);
79530
- };
79531
- footerContentHeights = {};
79532
- for (const [type2, value] of Object.entries(preFooterLayouts)) {
79533
- if (!isValidFooterType(type2)) continue;
79534
- if (value?.layout && typeof value.layout.height === "number") {
79535
- const height = value.layout.height;
79536
- if (Number.isFinite(height) && height >= 0) {
79537
- footerContentHeights[type2] = height;
79552
+ if (hasFooterBlocks && headerFooter.footerBlocks) {
79553
+ const preFooterLayouts = await layoutHeaderFooterWithCache(
79554
+ headerFooter.footerBlocks,
79555
+ headerFooter.constraints,
79556
+ measureFn,
79557
+ headerMeasureCache,
79558
+ FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
79559
+ void 0
79560
+ // No page resolver needed for height calculation
79561
+ );
79562
+ for (const [type2, value] of Object.entries(preFooterLayouts)) {
79563
+ if (!isValidFooterType(type2)) continue;
79564
+ if (value?.layout && typeof value.layout.height === "number") {
79565
+ const height = value.layout.height;
79566
+ if (Number.isFinite(height) && height >= 0) {
79567
+ footerContentHeights[type2] = height;
79568
+ }
79569
+ }
79570
+ }
79571
+ }
79572
+ if (hasFooterBlocksByRId && headerFooter.footerBlocksByRId) {
79573
+ for (const [_rId, blocks] of headerFooter.footerBlocksByRId) {
79574
+ if (!blocks || blocks.length === 0) continue;
79575
+ const measureConstraints = {
79576
+ maxWidth: headerFooter.constraints.width,
79577
+ maxHeight: headerFooter.constraints.height
79578
+ };
79579
+ const measures2 = await Promise.all(blocks.map((block) => measureFn(block, measureConstraints)));
79580
+ const layout2 = layoutHeaderFooter(blocks, measures2, {
79581
+ width: headerFooter.constraints.width,
79582
+ height: headerFooter.constraints.height
79583
+ });
79584
+ if (layout2.height > 0) {
79585
+ const currentDefault = footerContentHeights.default ?? 0;
79586
+ footerContentHeights.default = Math.max(currentDefault, layout2.height);
79538
79587
  }
79539
79588
  }
79540
79589
  }
@@ -96479,7 +96528,14 @@ computeHeaderFooterConstraints_fn = function() {
96479
96528
  const footerMargin = margins.footer ?? 0;
96480
96529
  const headerContentSpace = Math.max(marginTop - headerMargin, 0);
96481
96530
  const footerContentSpace = Math.max(marginBottom - footerMargin, 0);
96482
- const height = Math.max(headerContentSpace, footerContentSpace, 1);
96531
+ const height = Math.max(
96532
+ headerContentSpace,
96533
+ footerContentSpace,
96534
+ headerMargin,
96535
+ footerMargin,
96536
+ marginTop,
96537
+ marginBottom
96538
+ );
96483
96539
  return {
96484
96540
  width: measurementWidth,
96485
96541
  height,
@@ -96629,7 +96685,8 @@ computeDecorationBox_fn = function(kind, pageMargins, pageHeight) {
96629
96685
  const headerMargin = margins.header ?? 0;
96630
96686
  const topMargin = margins.top ?? DEFAULT_MARGINS.top ?? 0;
96631
96687
  const height = Math.max(topMargin - headerMargin, 1);
96632
- return { x: left2, width, height, offset: headerMargin };
96688
+ const offset2 = headerMargin;
96689
+ return { x: left2, width, height, offset: offset2 };
96633
96690
  } else {
96634
96691
  const footerMargin = margins.footer ?? 0;
96635
96692
  const bottomMargin = margins.bottom ?? DEFAULT_MARGINS.bottom ?? 0;