@superdoc-dev/cli 0.16.0-next.3 → 0.16.0-next.5

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 +1635 -237
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -68110,7 +68110,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
68110
68110
  emptyOptions2 = {};
68111
68111
  });
68112
68112
 
68113
- // ../../packages/superdoc/dist/chunks/SuperConverter-kNDiQmof.es.js
68113
+ // ../../packages/superdoc/dist/chunks/SuperConverter-LqX_f8x4.es.js
68114
68114
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
68115
68115
  const fieldValue = extension$1.config[field];
68116
68116
  if (typeof fieldValue === "function")
@@ -68913,10 +68913,10 @@ function isStoryLocator2(value) {
68913
68913
  case "headerFooterSlot":
68914
68914
  return isSectionAddress2(value.section) && isStringEnumMember2(value.headerFooterKind, STORY_HEADER_FOOTER_KINDS2) && isStringEnumMember2(value.variant, STORY_HEADER_FOOTER_VARIANTS2) && isOptionalStringEnumMember2(value.resolution, STORY_HEADER_FOOTER_RESOLUTIONS2) && isOptionalStringEnumMember2(value.onWrite, STORY_HEADER_FOOTER_ON_WRITE_VALUES2);
68915
68915
  case "headerFooterPart":
68916
- return isNonEmptyString$1(value.refId);
68916
+ return isNonEmptyString$2(value.refId);
68917
68917
  case "footnote":
68918
68918
  case "endnote":
68919
- return isNonEmptyString$1(value.noteId);
68919
+ return isNonEmptyString$2(value.noteId);
68920
68920
  }
68921
68921
  }
68922
68922
  function getStoryHeaderFooterResolution(locator) {
@@ -68949,7 +68949,7 @@ function storyLocatorToKey2(locator) {
68949
68949
  function isObjectRecord$1(value) {
68950
68950
  return typeof value === "object" && value !== null;
68951
68951
  }
68952
- function isNonEmptyString$1(value) {
68952
+ function isNonEmptyString$2(value) {
68953
68953
  return typeof value === "string" && value.length > 0;
68954
68954
  }
68955
68955
  function isStringEnumMember2(value, allowed) {
@@ -98476,7 +98476,7 @@ function importNoteEntries({ partXml, childElementName, filename, docx, editor,
98476
98476
  const idNumber = Number(id2);
98477
98477
  const originalXml = carbonCopy(el);
98478
98478
  const type = el?.attributes?.["w:type"] || null;
98479
- if (type === "separator" || type === "continuationSeparator") {
98479
+ if (type === "separator" || type === "continuationSeparator" || type === "continuationNotice") {
98480
98480
  results.push({
98481
98481
  id: id2,
98482
98482
  type,
@@ -102188,17 +102188,78 @@ function buildReferenceMarkerRun(displayText, params3) {
102188
102188
  fontSize: baseFontSize * SUBSCRIPT_SUPERSCRIPT_SCALE
102189
102189
  }, params3);
102190
102190
  }
102191
+ function toUpperRoman(num) {
102192
+ if (num < 1 || num > 3999)
102193
+ return String(num);
102194
+ const values = [
102195
+ 1000,
102196
+ 900,
102197
+ 500,
102198
+ 400,
102199
+ 100,
102200
+ 90,
102201
+ 50,
102202
+ 40,
102203
+ 10,
102204
+ 9,
102205
+ 5,
102206
+ 4,
102207
+ 1
102208
+ ];
102209
+ const numerals = [
102210
+ "M",
102211
+ "CM",
102212
+ "D",
102213
+ "CD",
102214
+ "C",
102215
+ "XC",
102216
+ "L",
102217
+ "XL",
102218
+ "X",
102219
+ "IX",
102220
+ "V",
102221
+ "IV",
102222
+ "I"
102223
+ ];
102224
+ let result = "";
102225
+ let remaining = num;
102226
+ for (let i$1 = 0;i$1 < values.length; i$1 += 1)
102227
+ while (remaining >= values[i$1]) {
102228
+ result += numerals[i$1];
102229
+ remaining -= values[i$1];
102230
+ }
102231
+ return result;
102232
+ }
102233
+ function toUpperLetter(num) {
102234
+ if (num < 1)
102235
+ return "A";
102236
+ let result = "";
102237
+ let n = num;
102238
+ while (n > 0) {
102239
+ const remainder = (n - 1) % 26;
102240
+ result = String.fromCharCode(65 + remainder) + result;
102241
+ n = Math.floor((n - 1) / 26);
102242
+ }
102243
+ return result;
102244
+ }
102191
102245
  function footnoteReferenceToBlock(params3) {
102192
102246
  const { node: node3, converterContext } = params3;
102193
- const id2 = node3.attrs?.id;
102194
- const displayId = resolveFootnoteDisplayNumber(id2, converterContext.footnoteNumberById) ?? id2 ?? "*";
102195
- return buildReferenceMarkerRun(String(displayId), params3);
102247
+ const attrs = node3.attrs;
102248
+ const id2 = attrs?.id;
102249
+ if (isCustomMarkFollows(attrs?.customMarkFollows))
102250
+ return buildReferenceMarkerRun("", params3);
102251
+ const cardinal = resolveFootnoteDisplayNumber(id2, converterContext.footnoteNumberById);
102252
+ const key = id2 == null ? null : String(id2);
102253
+ const numFmt = key && converterContext.footnoteFormatById?.[key] || converterContext.footnoteNumberFormat;
102254
+ return buildReferenceMarkerRun(cardinal != null ? formatFootnoteCardinal(cardinal, numFmt) : id2 != null ? String(id2) : "*", params3);
102196
102255
  }
102197
102256
  function endnoteReferenceToBlock(params3) {
102198
102257
  const { node: node3, converterContext } = params3;
102199
102258
  const id2 = node3.attrs?.id;
102200
- const displayId = resolveEndnoteDisplayNumber(id2, converterContext.endnoteNumberById) ?? id2 ?? "*";
102201
- return buildReferenceMarkerRun(String(displayId), params3);
102259
+ const cardinal = resolveEndnoteDisplayNumber(id2, converterContext.endnoteNumberById);
102260
+ const key = id2 == null ? null : String(id2);
102261
+ const numFmt = key && converterContext.endnoteFormatById?.[key] || converterContext.endnoteNumberFormat;
102262
+ return buildReferenceMarkerRun(cardinal != null ? formatFootnoteCardinal(cardinal, numFmt) : id2 != null ? String(id2) : "*", params3);
102202
102263
  }
102203
102264
  function runNodeChildrenToRuns({ node: node3, inheritedMarks, sdtMetadata, converterContext, paragraphProperties, visitNode }) {
102204
102265
  const mergedMarks = [...node3.marks ?? [], ...inheritedMarks ?? []];
@@ -104708,6 +104769,7 @@ function toFlowBlocks(pmDoc, options) {
104708
104769
  bookmarks: bookmarks.size
104709
104770
  });
104710
104771
  const mergedBlocks = mergeFusedParagraphs(mergeDropCapParagraphs(hydrateImageBlocks(blocks, options?.mediaFiles)));
104772
+ stampTrackedChangeColors(mergedBlocks, options?.resolveTrackedChangeColor);
104711
104773
  flowBlockCache?.commit();
104712
104774
  return {
104713
104775
  blocks: mergedBlocks,
@@ -106752,6 +106814,147 @@ function setDefaultTableStyle(settingsRoot, styleId) {
106752
106814
  function removeDefaultTableStyle(settingsRoot) {
106753
106815
  settingsRoot.elements = ensureSettingsRootElements(settingsRoot).filter((entry) => entry.name !== "w:defaultTableStyle");
106754
106816
  }
106817
+ function readFootnoteNumberFormat(settingsRoot) {
106818
+ return readNoteNumberFormat(settingsRoot, "w:footnotePr");
106819
+ }
106820
+ function readEndnoteNumberFormat(settingsRoot) {
106821
+ return readNoteNumberFormat(settingsRoot, "w:endnotePr");
106822
+ }
106823
+ function readNoteNumberFormat(settingsRoot, containerName) {
106824
+ const container = settingsRoot.elements?.find((entry) => entry.name === containerName);
106825
+ if (!container || !Array.isArray(container.elements))
106826
+ return null;
106827
+ const numFmt = container.elements.find((entry) => entry.name === "w:numFmt");
106828
+ if (!numFmt)
106829
+ return null;
106830
+ const val = numFmt.attributes?.["w:val"];
106831
+ return typeof val === "string" && val.length > 0 ? val : null;
106832
+ }
106833
+ function readFootnoteNumberStart(settingsRoot) {
106834
+ return readNoteNumberStart(settingsRoot, "w:footnotePr");
106835
+ }
106836
+ function readEndnoteNumberStart(settingsRoot) {
106837
+ return readNoteNumberStart(settingsRoot, "w:endnotePr");
106838
+ }
106839
+ function readNoteNumberStart(settingsRoot, containerName) {
106840
+ const container = settingsRoot.elements?.find((entry) => entry.name === containerName);
106841
+ if (!container || !Array.isArray(container.elements))
106842
+ return null;
106843
+ const numStart = container.elements.find((entry) => entry.name === "w:numStart");
106844
+ if (!numStart)
106845
+ return null;
106846
+ const val = numStart.attributes?.["w:val"];
106847
+ if (typeof val !== "string" && typeof val !== "number")
106848
+ return null;
106849
+ const n = Number(val);
106850
+ return Number.isFinite(n) && n >= 1 ? Math.floor(n) : null;
106851
+ }
106852
+ function readFootnotePosition(settingsRoot) {
106853
+ return readNotePosition(settingsRoot, "w:footnotePr");
106854
+ }
106855
+ function readEndnotePosition(settingsRoot) {
106856
+ return readNotePosition(settingsRoot, "w:endnotePr");
106857
+ }
106858
+ function readNotePosition(settingsRoot, containerName) {
106859
+ const container = settingsRoot.elements?.find((entry) => entry.name === containerName);
106860
+ if (!container || !Array.isArray(container.elements))
106861
+ return null;
106862
+ const el = container.elements.find((entry) => entry.name === "w:pos");
106863
+ if (!el)
106864
+ return null;
106865
+ const val = el.attributes?.["w:val"];
106866
+ if (val === "pageBottom" || val === "beneathText" || val === "sectEnd" || val === "docEnd")
106867
+ return val;
106868
+ return null;
106869
+ }
106870
+ function readFootnoteNumberRestart(settingsRoot) {
106871
+ return readNoteNumberRestart(settingsRoot, "w:footnotePr");
106872
+ }
106873
+ function readEndnoteNumberRestart(settingsRoot) {
106874
+ return readNoteNumberRestart(settingsRoot, "w:endnotePr");
106875
+ }
106876
+ function readNoteNumberRestart(settingsRoot, containerName) {
106877
+ const container = settingsRoot.elements?.find((entry) => entry.name === containerName);
106878
+ if (!container || !Array.isArray(container.elements))
106879
+ return null;
106880
+ const el = container.elements.find((entry) => entry.name === "w:numRestart");
106881
+ if (!el)
106882
+ return null;
106883
+ const val = el.attributes?.["w:val"];
106884
+ if (val === "continuous" || val === "eachPage" || val === "eachSect")
106885
+ return val;
106886
+ return null;
106887
+ }
106888
+ function readSectionNoteConfigs(documentRoot, containerName) {
106889
+ const result = /* @__PURE__ */ new Map;
106890
+ if (!documentRoot)
106891
+ return result;
106892
+ const bodyEl = findBody(documentRoot);
106893
+ if (!bodyEl)
106894
+ return result;
106895
+ let sectionIndex = 0;
106896
+ for (const child of bodyEl.elements ?? [])
106897
+ if (child.name === "w:sectPr") {
106898
+ const config$42 = extractSectionNoteConfig(child, containerName);
106899
+ if (config$42)
106900
+ result.set(sectionIndex, config$42);
106901
+ sectionIndex += 1;
106902
+ } else if (child.name === "w:p") {
106903
+ const sectPr = findChildByName(findChildByName(child, "w:pPr"), "w:sectPr");
106904
+ if (sectPr) {
106905
+ const config$42 = extractSectionNoteConfig(sectPr, containerName);
106906
+ if (config$42)
106907
+ result.set(sectionIndex, config$42);
106908
+ sectionIndex += 1;
106909
+ }
106910
+ }
106911
+ return result;
106912
+ }
106913
+ function findBody(root2) {
106914
+ if (root2.name === "w:body")
106915
+ return root2;
106916
+ if (!Array.isArray(root2.elements))
106917
+ return null;
106918
+ for (const child of root2.elements) {
106919
+ if (child.name === "w:body")
106920
+ return child;
106921
+ const inner = child.elements?.find((g2) => g2.name === "w:body");
106922
+ if (inner)
106923
+ return inner;
106924
+ }
106925
+ return null;
106926
+ }
106927
+ function findChildByName(parent, name) {
106928
+ if (!parent)
106929
+ return null;
106930
+ return parent.elements?.find((entry) => entry.name === name) ?? null;
106931
+ }
106932
+ function extractSectionNoteConfig(sectPr, containerName) {
106933
+ const container = findChildByName(sectPr, containerName);
106934
+ if (!container)
106935
+ return null;
106936
+ const config$42 = {};
106937
+ const numFmt = findChildByName(container, "w:numFmt");
106938
+ if (numFmt) {
106939
+ const val = numFmt.attributes?.["w:val"];
106940
+ if (typeof val === "string" && val.length > 0)
106941
+ config$42.numFmt = val;
106942
+ }
106943
+ const numStart = findChildByName(container, "w:numStart");
106944
+ if (numStart) {
106945
+ const val = numStart.attributes?.["w:val"];
106946
+ const n = typeof val === "string" || typeof val === "number" ? Number(val) : NaN;
106947
+ if (Number.isFinite(n) && n >= 1)
106948
+ config$42.numStart = Math.floor(n);
106949
+ }
106950
+ const numRestart = findChildByName(container, "w:numRestart");
106951
+ if (numRestart) {
106952
+ const val = numRestart.attributes?.["w:val"];
106953
+ if (val === "continuous" || val === "eachPage" || val === "eachSect")
106954
+ config$42.numRestart = val;
106955
+ }
106956
+ return Object.keys(config$42).length > 0 ? config$42 : null;
106957
+ }
106755
106958
  function hasOddEvenHeadersFooters(settingsRoot) {
106756
106959
  return settingsRoot.elements?.some((entry) => entry.name === "w:evenAndOddHeaders") === true;
106757
106960
  }
@@ -108715,6 +108918,9 @@ function getTextAdapter(editor, input) {
108715
108918
  `, `
108716
108919
  `, { textModel: "visible" });
108717
108920
  }
108921
+ function rangesOverlap(a, b) {
108922
+ return a[0] < b[1] && b[0] < a[1];
108923
+ }
108718
108924
  function getRawTrackedMarks(editor) {
108719
108925
  try {
108720
108926
  const marks = getTrackChanges(editor.state);
@@ -108914,6 +109120,7 @@ function groupTrackedChanges(editor) {
108914
109120
  const wordRevisionId = toNonEmptyString(attrs.sourceId);
108915
109121
  const wordRevisionIdKey = getWordRevisionIdKey(markType);
108916
109122
  const excerptText = !wordRevisionId || !hasChildTrackedMarkOnNode(item, id2) ? getTrackedMarkText(editor, item) : "";
109123
+ const range = [item.from, item.to];
108917
109124
  if (!existing) {
108918
109125
  byRawId.set(groupKey, {
108919
109126
  rawId: groupKey,
@@ -108925,6 +109132,7 @@ function groupTrackedChanges(editor) {
108925
109132
  hasFormat: nextHasFormat,
108926
109133
  attrs: { ...attrs },
108927
109134
  excerptParts: excerptText ? [excerptText] : [],
109135
+ excerptRanges: excerptText ? [range] : [],
108928
109136
  wordRevisionIds: wordRevisionIdKey ? mergeWordRevisionId(undefined, wordRevisionIdKey, wordRevisionId ?? undefined) : undefined
108929
109137
  });
108930
109138
  continue;
@@ -108936,12 +109144,14 @@ function groupTrackedChanges(editor) {
108936
109144
  existing.hasFormat = existing.hasFormat || nextHasFormat;
108937
109145
  if (Object.keys(existing.attrs).length === 0 && Object.keys(attrs).length > 0)
108938
109146
  existing.attrs = { ...attrs };
108939
- if (excerptText)
109147
+ if (excerptText && !existing.excerptRanges.some((counted) => rangesOverlap(counted, range))) {
109148
+ existing.excerptRanges.push(range);
108940
109149
  existing.excerptParts.push(excerptText);
109150
+ }
108941
109151
  if (wordRevisionIdKey)
108942
109152
  existing.wordRevisionIds = mergeWordRevisionId(existing.wordRevisionIds, wordRevisionIdKey, wordRevisionId ?? undefined);
108943
109153
  }
108944
- const grouped = Array.from(byRawId.values()).map(({ excerptParts, ...change }) => {
109154
+ const grouped = Array.from(byRawId.values()).map(({ excerptParts, excerptRanges: _excerptRanges, ...change }) => {
108945
109155
  const hasWordSourceId = Boolean(toNonEmptyString(change.attrs.sourceId));
108946
109156
  const rawExcerpt = excerptParts.join("");
108947
109157
  const withExcerpt = {
@@ -112821,6 +113031,50 @@ var isRegExp = (value) => {
112821
113031
  partialRow: fragment2.kind === "table" ? fragment2.partialRow : undefined,
112822
113032
  sourceAnchor: fragment2.sourceAnchor ?? existing?.sourceAnchor
112823
113033
  });
113034
+ }, isNonEmptyString$1 = (value) => typeof value === "string" && value.length > 0, authorFromTrackedChangeMeta = (meta) => ({
113035
+ name: meta.author,
113036
+ email: meta.authorEmail,
113037
+ image: meta.authorImage
113038
+ }), applyColorToLayer = (meta, resolve2) => {
113039
+ const color2 = resolve2?.(authorFromTrackedChangeMeta(meta));
113040
+ if (isNonEmptyString$1(color2)) {
113041
+ meta.color = color2;
113042
+ return;
113043
+ }
113044
+ delete meta.color;
113045
+ }, stampRunTrackedChangeColors = (run$1, resolve2) => {
113046
+ if (Array.isArray(run$1.trackedChanges))
113047
+ for (const layer of run$1.trackedChanges)
113048
+ applyColorToLayer(layer, resolve2);
113049
+ if (run$1.trackedChange)
113050
+ applyColorToLayer(run$1.trackedChange, resolve2);
113051
+ }, stampBlockTrackedChangeColors = (block, resolve2) => {
113052
+ if (!block)
113053
+ return;
113054
+ switch (block.kind) {
113055
+ case "paragraph":
113056
+ for (const run$1 of block.runs)
113057
+ stampRunTrackedChangeColors(run$1, resolve2);
113058
+ break;
113059
+ case "list":
113060
+ for (const item of block.items)
113061
+ stampBlockTrackedChangeColors(item.paragraph, resolve2);
113062
+ break;
113063
+ case "table":
113064
+ for (const row of block.rows)
113065
+ for (const cell of row.cells) {
113066
+ stampBlockTrackedChangeColors(cell.paragraph, resolve2);
113067
+ if (Array.isArray(cell.blocks))
113068
+ for (const nested of cell.blocks)
113069
+ stampBlockTrackedChangeColors(nested, resolve2);
113070
+ }
113071
+ break;
113072
+ default:
113073
+ break;
113074
+ }
113075
+ }, stampTrackedChangeColors = (blocks, resolve2) => {
113076
+ for (const block of blocks)
113077
+ stampBlockTrackedChangeColors(block, resolve2);
112824
113078
  }, idlessSdtContainerKeys, nextIdlessSdtContainerKey = 0, engines_exports, EMPTY_SDT_PLACEHOLDER_TEXT = "Click or tap here to enter text", FONT_SLOT_THEME_PAIRS, TABLE_STYLE_ID_TABLE_GRID = "TableGrid", TABLE_FALLBACK_BORDER, TABLE_FALLBACK_BORDERS, TABLE_FALLBACK_CELL_PADDING, DEFAULT_TBL_LOOK, CNF_STYLE_MAP, TABLE_STYLE_PRECEDENCE, getToCssFontFamily = () => {
112825
113079
  return SuperConverter.toCssFontFamily;
112826
113080
  }, getSpacingStyle = (spacing, isListItem$1) => {
@@ -121685,7 +121939,7 @@ var isRegExp = (value) => {
121685
121939
  }, handleAlpha = (path2, lvlText) => generateNumbering(path2, lvlText, intToAlpha), handleLowerAlpha = (path2, lvlText) => {
121686
121940
  const result = handleAlpha(path2, lvlText);
121687
121941
  return result ? result.toLowerCase() : null;
121688
- }, handleOrdinal = (path2, lvlText) => generateNumbering(path2, lvlText, ordinalFormatter), handleCustom = (path2, lvlText, customFormat) => generateFromCustom(path2, lvlText, customFormat), handleJapaneseCounting = (path2, lvlText) => generateNumbering(path2, lvlText, intToJapaneseCounting), handleDecimalZero = (path2, lvlText) => generateNumbering(path2, lvlText, decimalZeroFormatter), listIndexMap, generateOrderedListIndex = ({ listLevel, lvlText, listNumberingType, customFormat }) => {
121942
+ }, handleOrdinal = (path2, lvlText) => generateNumbering(path2, lvlText, ordinalFormatter), handleOrdinalText = (path2, lvlText) => generateNumbering(path2, lvlText, ordinalTextFormatter), handleCardinalText = (path2, lvlText) => generateNumbering(path2, lvlText, cardinalTextFormatter), handleCustom = (path2, lvlText, customFormat) => generateFromCustom(path2, lvlText, customFormat), handleJapaneseCounting = (path2, lvlText) => generateNumbering(path2, lvlText, intToJapaneseCounting), handleDecimalZero = (path2, lvlText) => generateNumbering(path2, lvlText, decimalZeroFormatter), listIndexMap, generateOrderedListIndex = ({ listLevel, lvlText, listNumberingType, customFormat }) => {
121689
121943
  if (typeof lvlText !== "string")
121690
121944
  return null;
121691
121945
  const handler$1 = listIndexMap[listNumberingType];
@@ -121707,6 +121961,32 @@ var isRegExp = (value) => {
121707
121961
  ];
121708
121962
  const lastTwo = value % 100;
121709
121963
  return `${value}${suffixes[(lastTwo - 20) % 10] || suffixes[lastTwo] || suffixes[0]}`;
121964
+ }, ONES_ORDINAL, TENS_ORDINAL, ONES_CARDINAL, TENS_CARDINAL, ordinalTextFormatter = (value) => {
121965
+ if (!Number.isFinite(value) || value < 1)
121966
+ return "";
121967
+ if (value < ONES_ORDINAL.length)
121968
+ return ONES_ORDINAL[value];
121969
+ if (value < 100) {
121970
+ const t = Math.floor(value / 10);
121971
+ const o = value % 10;
121972
+ if (o === 0)
121973
+ return TENS_ORDINAL[t];
121974
+ return `${TENS_CARDINAL[t]}-${ONES_ORDINAL[o]}`;
121975
+ }
121976
+ return ordinalFormatter(value);
121977
+ }, cardinalTextFormatter = (value) => {
121978
+ if (!Number.isFinite(value) || value < 1)
121979
+ return "";
121980
+ if (value < ONES_CARDINAL.length)
121981
+ return ONES_CARDINAL[value];
121982
+ if (value < 100) {
121983
+ const t = Math.floor(value / 10);
121984
+ const o = value % 10;
121985
+ if (o === 0)
121986
+ return TENS_CARDINAL[t];
121987
+ return `${TENS_CARDINAL[t]}-${ONES_CARDINAL[o]}`;
121988
+ }
121989
+ return String(value);
121710
121990
  }, decimalZeroFormatter = (value, idx) => {
121711
121991
  if (value >= 10 || idx === 0)
121712
121992
  return String(value);
@@ -129007,7 +129287,33 @@ var isRegExp = (value) => {
129007
129287
  inheritedMarks: stripVerticalPositioningFromMarks(params3.inheritedMarks),
129008
129288
  runProperties: stripVerticalPositioningFromRunProperties(params3.runProperties),
129009
129289
  node: buildSyntheticTextNode(displayText, stripVerticalPositioningFromMarks(params3.node.marks))
129010
- }), resolveFootnoteDisplayNumber = (id2, footnoteNumberById) => {
129290
+ }), SUPPORTED_FORMATS, formatFootnoteCardinal = (cardinal, numFmt) => {
129291
+ const fmt = numFmt && SUPPORTED_FORMATS.has(numFmt) ? numFmt : "decimal";
129292
+ const num = Math.max(1, cardinal);
129293
+ switch (fmt) {
129294
+ case "decimal":
129295
+ return String(num);
129296
+ case "upperRoman":
129297
+ return toUpperRoman(num);
129298
+ case "lowerRoman":
129299
+ return toUpperRoman(num).toLowerCase();
129300
+ case "upperLetter":
129301
+ return toUpperLetter(num);
129302
+ case "lowerLetter":
129303
+ return toUpperLetter(num).toLowerCase();
129304
+ case "numberInDash":
129305
+ return `-${num}-`;
129306
+ default:
129307
+ return String(num);
129308
+ }
129309
+ }, isCustomMarkFollows = (value) => {
129310
+ if (value === true || value === 1)
129311
+ return true;
129312
+ if (typeof value !== "string")
129313
+ return false;
129314
+ const v = value.trim().toLowerCase();
129315
+ return v === "1" || v === "true" || v === "on";
129316
+ }, resolveFootnoteDisplayNumber = (id2, footnoteNumberById) => {
129011
129317
  const key = id2 == null ? null : String(id2);
129012
129318
  if (!key)
129013
129319
  return null;
@@ -130197,7 +130503,7 @@ var isRegExp = (value) => {
130197
130503
  state.kern = kernNode.attributes["w:val"];
130198
130504
  }
130199
130505
  }, SuperConverter;
130200
- var init_SuperConverter_kNDiQmof_es = __esm(() => {
130506
+ var init_SuperConverter_LqX_f8x4_es = __esm(() => {
130201
130507
  init_rolldown_runtime_Bg48TavK_es();
130202
130508
  init_jszip_C49i9kUs_es();
130203
130509
  init_xml_js_CqGKpaft_es();
@@ -160125,9 +160431,79 @@ var init_SuperConverter_kNDiQmof_es = __esm(() => {
160125
160431
  lowerLetter: handleLowerAlpha,
160126
160432
  upperLetter: handleAlpha,
160127
160433
  ordinal: handleOrdinal,
160434
+ ordinalText: handleOrdinalText,
160435
+ cardinalText: handleCardinalText,
160128
160436
  custom: handleCustom,
160129
160437
  japaneseCounting: handleJapaneseCounting
160130
160438
  };
160439
+ ONES_ORDINAL = [
160440
+ "",
160441
+ "First",
160442
+ "Second",
160443
+ "Third",
160444
+ "Fourth",
160445
+ "Fifth",
160446
+ "Sixth",
160447
+ "Seventh",
160448
+ "Eighth",
160449
+ "Ninth",
160450
+ "Tenth",
160451
+ "Eleventh",
160452
+ "Twelfth",
160453
+ "Thirteenth",
160454
+ "Fourteenth",
160455
+ "Fifteenth",
160456
+ "Sixteenth",
160457
+ "Seventeenth",
160458
+ "Eighteenth",
160459
+ "Nineteenth"
160460
+ ];
160461
+ TENS_ORDINAL = [
160462
+ "",
160463
+ "",
160464
+ "Twentieth",
160465
+ "Thirtieth",
160466
+ "Fortieth",
160467
+ "Fiftieth",
160468
+ "Sixtieth",
160469
+ "Seventieth",
160470
+ "Eightieth",
160471
+ "Ninetieth"
160472
+ ];
160473
+ ONES_CARDINAL = [
160474
+ "",
160475
+ "One",
160476
+ "Two",
160477
+ "Three",
160478
+ "Four",
160479
+ "Five",
160480
+ "Six",
160481
+ "Seven",
160482
+ "Eight",
160483
+ "Nine",
160484
+ "Ten",
160485
+ "Eleven",
160486
+ "Twelve",
160487
+ "Thirteen",
160488
+ "Fourteen",
160489
+ "Fifteen",
160490
+ "Sixteen",
160491
+ "Seventeen",
160492
+ "Eighteen",
160493
+ "Nineteen"
160494
+ ];
160495
+ TENS_CARDINAL = [
160496
+ "",
160497
+ "",
160498
+ "Twenty",
160499
+ "Thirty",
160500
+ "Forty",
160501
+ "Fifty",
160502
+ "Sixty",
160503
+ "Seventy",
160504
+ "Eighty",
160505
+ "Ninety"
160506
+ ];
160131
160507
  normalizeChars = new Set([
160132
160508
  "",
160133
160509
  "",
@@ -167384,6 +167760,14 @@ var init_SuperConverter_kNDiQmof_es = __esm(() => {
167384
167760
  this.name = "NotInlineNodeError";
167385
167761
  }
167386
167762
  };
167763
+ SUPPORTED_FORMATS = new Set([
167764
+ "decimal",
167765
+ "upperRoman",
167766
+ "lowerRoman",
167767
+ "upperLetter",
167768
+ "lowerLetter",
167769
+ "numberInDash"
167770
+ ]);
167387
167771
  sdtMetadataCache = /* @__PURE__ */ new Map;
167388
167772
  NON_RENDERED_STRUCTURAL_INLINE_TYPES = new Set([
167389
167773
  "bookmarkEnd",
@@ -168886,7 +169270,7 @@ var init_SuperConverter_kNDiQmof_es = __esm(() => {
168886
169270
  };
168887
169271
  });
168888
169272
 
168889
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-fRnbrGLy.es.js
169273
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-BOETXxAI.es.js
168890
169274
  function parseSizeUnit(val = "0") {
168891
169275
  const length3 = val.toString() || "0";
168892
169276
  const value = Number.parseFloat(length3);
@@ -179217,8 +179601,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, normalizeActorId = (value) => {
179217
179601
  }
179218
179602
  };
179219
179603
  };
179220
- var init_create_headless_toolbar_fRnbrGLy_es = __esm(() => {
179221
- init_SuperConverter_kNDiQmof_es();
179604
+ var init_create_headless_toolbar_BOETXxAI_es = __esm(() => {
179605
+ init_SuperConverter_LqX_f8x4_es();
179222
179606
  init_uuid_qzgm05fK_es();
179223
179607
  init_constants_D_X7xF4s_es();
179224
179608
  init_dist_B8HfvhaK_es();
@@ -228381,7 +228765,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
228381
228765
  init_remark_gfm_BhnWr3yf_es();
228382
228766
  });
228383
228767
 
228384
- // ../../packages/superdoc/dist/chunks/src-DckQskSY.es.js
228768
+ // ../../packages/superdoc/dist/chunks/src-iuHADPff.es.js
228385
228769
  function deleteProps(obj, propOrProps) {
228386
228770
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
228387
228771
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -268081,7 +268465,9 @@ function resolveParagraphContent(fragment2, block, measure) {
268081
268465
  bold: m$1.run?.bold,
268082
268466
  italic: m$1.run?.italic,
268083
268467
  color: m$1.run?.color,
268084
- letterSpacing: m$1.run?.letterSpacing
268468
+ letterSpacing: m$1.run?.letterSpacing,
268469
+ allCaps: m$1.run?.allCaps,
268470
+ smallCaps: m$1.run?.smallCaps
268085
268471
  },
268086
268472
  sourceAnchor: block.sourceAnchor
268087
268473
  };
@@ -269046,25 +269432,6 @@ function normalizeLines(measure) {
269046
269432
  lineHeight: measure.totalHeight || 0
269047
269433
  }];
269048
269434
  }
269049
- function sliceLines(lines, startIndex, availableHeight) {
269050
- let height = 0;
269051
- let index2 = startIndex;
269052
- while (index2 < lines.length) {
269053
- const lineHeight = lines[index2].lineHeight || 0;
269054
- if (height > 0 && height + lineHeight > availableHeight)
269055
- break;
269056
- height += lineHeight;
269057
- index2 += 1;
269058
- }
269059
- if (index2 === startIndex) {
269060
- height = lines[startIndex].lineHeight || 0;
269061
- index2 += 1;
269062
- }
269063
- return {
269064
- toLine: index2,
269065
- height
269066
- };
269067
- }
269068
269435
  function shouldSuppressOwnSpacing(ownStyleId, ownContextualSpacing, adjacentStyleId) {
269069
269436
  return ownContextualSpacing && !!ownStyleId && !!adjacentStyleId && ownStyleId === adjacentStyleId;
269070
269437
  }
@@ -269360,14 +269727,56 @@ function layoutParagraphBlock(ctx$1, anchors) {
269360
269727
  }
269361
269728
  else
269362
269729
  state.trailingSpacing = 0;
269363
- if (state.cursorY >= state.contentBottom)
269730
+ const FN_SAFETY_MARGIN_PX = 1;
269731
+ const fallbackBandOverhead = (refsTotal) => refsTotal > 0 ? 22 + Math.max(0, refsTotal - 1) * 2 : 0;
269732
+ const bandOverhead = (refsTotal) => {
269733
+ if (refsTotal <= 0)
269734
+ return 0;
269735
+ const fromCtx = ctx$1.getFootnoteBandOverhead?.(refsTotal);
269736
+ return (typeof fromCtx === "number" && Number.isFinite(fromCtx) && fromCtx >= 0 ? fromCtx : fallbackBandOverhead(refsTotal)) + FN_SAFETY_MARGIN_PX;
269737
+ };
269738
+ const rawContentBottom = state.contentBottom + state.pageFootnoteReserve;
269739
+ const computeEffectiveBottom = (extraDemand, extraRefs) => {
269740
+ const totalDemand = extraDemand;
269741
+ const totalRefs = state.footnoteRefsThisPage + extraRefs;
269742
+ const demandWithOverhead = totalDemand > 0 ? totalDemand + bandOverhead(totalRefs) : 0;
269743
+ const reservedSpace = Math.max(state.pageFootnoteReserve, demandWithOverhead);
269744
+ const minBodyLineHeight = lines[fromLine]?.lineHeight ?? 0;
269745
+ const maxAdditional = Math.max(0, rawContentBottom - state.topMargin - minBodyLineHeight);
269746
+ return rawContentBottom - Math.min(reservedSpace, maxAdditional);
269747
+ };
269748
+ const computeFootnoteClusterDemand = (pmStart, pmEnd) => {
269749
+ const candidate = ctx$1.getFootnoteAnchorsForBlockId ? ctx$1.getFootnoteAnchorsForBlockId(block.id, pmStart, pmEnd) : [];
269750
+ const committed = state.footnoteAnchorsThisPage ?? [];
269751
+ if (candidate.length === 0 && committed.length === 0)
269752
+ return 0;
269753
+ let demand = 0;
269754
+ for (const anchor of committed)
269755
+ demand += anchor.fullHeight;
269756
+ for (const anchor of candidate)
269757
+ demand += anchor.fullHeight;
269758
+ return demand;
269759
+ };
269760
+ const previewRange = computeFragmentPmRange2(block, lines, fromLine, fromLine + 1);
269761
+ const previewRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, previewRange.pmStart, previewRange.pmEnd) : 0;
269762
+ const computePreviewBottom = () => {
269763
+ return computeEffectiveBottom(computeFootnoteClusterDemand(previewRange.pmStart ?? 0, previewRange.pmEnd ?? 0), previewRefs);
269764
+ };
269765
+ let effectiveBottom = computePreviewBottom();
269766
+ if (state.cursorY >= effectiveBottom) {
269364
269767
  state = advanceColumn(state);
269365
- if (state.contentBottom - state.cursorY <= 0)
269768
+ effectiveBottom = computePreviewBottom();
269769
+ }
269770
+ if (effectiveBottom - state.cursorY <= 0) {
269366
269771
  state = advanceColumn(state);
269772
+ effectiveBottom = computePreviewBottom();
269773
+ }
269367
269774
  const nextLineHeight = lines[fromLine].lineHeight || 0;
269368
- const remainingHeight = state.contentBottom - state.cursorY;
269369
- if (state.page.fragments.length > 0 && remainingHeight < nextLineHeight)
269775
+ const remainingHeight = effectiveBottom - state.cursorY;
269776
+ if (state.page.fragments.length > 0 && remainingHeight < nextLineHeight) {
269370
269777
  state = advanceColumn(state);
269778
+ effectiveBottom = computePreviewBottom();
269779
+ }
269371
269780
  let effectiveColumnWidth = columnWidth;
269372
269781
  let offsetX = 0;
269373
269782
  if (didRemeasureForFloats) {
@@ -269375,9 +269784,50 @@ function layoutParagraphBlock(ctx$1, anchors) {
269375
269784
  offsetX = narrowestOffsetX;
269376
269785
  }
269377
269786
  const borderVertical = borderExpansion.top + borderExpansion.bottom;
269378
- const availableForSlice = Math.max(0, state.contentBottom - state.cursorY - borderVertical);
269379
- const slice2 = sliceLines(lines, fromLine, availableForSlice);
269787
+ let toLine = fromLine;
269788
+ let height = 0;
269789
+ let sliceDemand = 0;
269790
+ let sliceRefs = 0;
269791
+ while (toLine < lines.length) {
269792
+ const lineHeight = lines[toLine].lineHeight || 0;
269793
+ const range = computeFragmentPmRange2(block, lines, fromLine, toLine + 1);
269794
+ const orderedDemand = computeFootnoteClusterDemand(range.pmStart ?? 0, range.pmEnd ?? 0);
269795
+ const nextRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, range.pmStart, range.pmEnd) : 0;
269796
+ if (toLine === fromLine) {
269797
+ height = lineHeight;
269798
+ sliceDemand = orderedDemand;
269799
+ sliceRefs = nextRefs;
269800
+ toLine = fromLine + 1;
269801
+ continue;
269802
+ }
269803
+ if (state.cursorY + height + lineHeight + borderVertical > computeEffectiveBottom(orderedDemand, nextRefs))
269804
+ break;
269805
+ height += lineHeight;
269806
+ sliceDemand = orderedDemand;
269807
+ sliceRefs = nextRefs;
269808
+ toLine += 1;
269809
+ }
269810
+ const slice2 = {
269811
+ toLine,
269812
+ height
269813
+ };
269380
269814
  const fragmentHeight = slice2.height;
269815
+ if (sliceDemand > 0 || sliceRefs > 0) {
269816
+ state.footnoteDemandThisPage = sliceDemand;
269817
+ state.footnoteRefsThisPage = (state.footnoteRefsThisPage ?? 0) + sliceRefs;
269818
+ }
269819
+ if (ctx$1.getFootnoteAnchorsForBlockId) {
269820
+ const committedRange = computeFragmentPmRange2(block, lines, fromLine, toLine);
269821
+ const newAnchors = ctx$1.getFootnoteAnchorsForBlockId(block.id, committedRange.pmStart, committedRange.pmEnd);
269822
+ if (newAnchors.length > 0) {
269823
+ if (!state.footnoteAnchorsThisPage)
269824
+ state.footnoteAnchorsThisPage = [];
269825
+ const seen = new Set(state.footnoteAnchorsThisPage.map((a2) => a2.refId));
269826
+ for (const a2 of newAnchors)
269827
+ if (!seen.has(a2.refId))
269828
+ state.footnoteAnchorsThisPage.push(a2);
269829
+ }
269830
+ }
269381
269831
  const adjustedX = columnX(state.columnIndex) + offsetX + negativeLeftIndent;
269382
269832
  const adjustedWidth = effectiveColumnWidth - negativeLeftIndent - negativeRightIndent;
269383
269833
  const fragment2 = {
@@ -270804,8 +271254,10 @@ function createPaginator(opts) {
270804
271254
  footer: footerDistance
270805
271255
  };
270806
271256
  const pageSizeOverride = currentPageSize.w !== defaultPageSize.w || currentPageSize.h !== defaultPageSize.h ? currentPageSize : undefined;
271257
+ const pageIndex = pages.length;
271258
+ const pageFootnoteReserve = opts.getFootnoteReserveForPage?.(pageIndex) ?? 0;
270807
271259
  const state = {
270808
- page: opts.createPage(pages.length + 1, pageMargins, pageSizeOverride),
271260
+ page: opts.createPage(pageIndex + 1, pageMargins, pageSizeOverride),
270809
271261
  cursorY: topMargin,
270810
271262
  columnIndex: 0,
270811
271263
  topMargin,
@@ -270815,7 +271267,11 @@ function createPaginator(opts) {
270815
271267
  trailingSpacing: 0,
270816
271268
  lastParagraphStyleId: undefined,
270817
271269
  lastParagraphContextualSpacing: false,
270818
- maxCursorY: topMargin
271270
+ maxCursorY: topMargin,
271271
+ pageFootnoteReserve,
271272
+ footnoteDemandThisPage: 0,
271273
+ footnoteRefsThisPage: 0,
271274
+ footnoteAnchorsThisPage: []
270819
271275
  };
270820
271276
  states.push(state);
270821
271277
  pages.push(state.page);
@@ -270841,6 +271297,8 @@ function createPaginator(opts) {
270841
271297
  state.trailingSpacing = 0;
270842
271298
  state.lastParagraphStyleId = undefined;
270843
271299
  state.lastParagraphContextualSpacing = false;
271300
+ state.footnoteAnchorsThisPage = [];
271301
+ state.footnoteRefsThisPage = 0;
270844
271302
  return state;
270845
271303
  }
270846
271304
  return startNewPage();
@@ -270860,7 +271318,7 @@ function createPaginator(opts) {
270860
271318
  pruneTrailingEmptyPages
270861
271319
  };
270862
271320
  }
270863
- function toUpperRoman(num) {
271321
+ function toUpperRoman2(num) {
270864
271322
  if (num < 1 || num > 3999)
270865
271323
  return String(num);
270866
271324
  const values = [
@@ -270903,9 +271361,9 @@ function toUpperRoman(num) {
270903
271361
  return result;
270904
271362
  }
270905
271363
  function toLowerRoman(num) {
270906
- return toUpperRoman(num).toLowerCase();
271364
+ return toUpperRoman2(num).toLowerCase();
270907
271365
  }
270908
- function toUpperLetter(num) {
271366
+ function toUpperLetter2(num) {
270909
271367
  if (num < 1)
270910
271368
  return "A";
270911
271369
  let result = "";
@@ -270918,7 +271376,7 @@ function toUpperLetter(num) {
270918
271376
  return result;
270919
271377
  }
270920
271378
  function toLowerLetter(num) {
270921
- return toUpperLetter(num).toLowerCase();
271379
+ return toUpperLetter2(num).toLowerCase();
270922
271380
  }
270923
271381
  function formatPageNumber(pageNumber, format) {
270924
271382
  const num = Math.max(1, pageNumber);
@@ -270926,11 +271384,11 @@ function formatPageNumber(pageNumber, format) {
270926
271384
  case "decimal":
270927
271385
  return String(num);
270928
271386
  case "upperRoman":
270929
- return toUpperRoman(num);
271387
+ return toUpperRoman2(num);
270930
271388
  case "lowerRoman":
270931
271389
  return toLowerRoman(num);
270932
271390
  case "upperLetter":
270933
- return toUpperLetter(num);
271391
+ return toUpperLetter2(num);
270934
271392
  case "lowerLetter":
270935
271393
  return toLowerLetter(num);
270936
271394
  case "numberInDash":
@@ -271972,6 +272430,135 @@ function layoutDocument(blocks2, measures, options = {}) {
271972
272430
  }
271973
272431
  return page;
271974
272432
  };
272433
+ const footnoteAnchorsByBlockId = (() => {
272434
+ const out = /* @__PURE__ */ new Map;
272435
+ const refs = options.footnotes?.refs;
272436
+ const bodyHeights = options.footnotes?.bodyHeightById;
272437
+ const firstLineHeights = options.footnotes?.firstLineHeightById;
272438
+ if (!Array.isArray(refs) || refs.length === 0 || !bodyHeights)
272439
+ return out;
272440
+ const resolveBlockPmRange = (block) => {
272441
+ const attrsRange = block.attrs;
272442
+ let pmStart = typeof attrsRange?.pmStart === "number" ? attrsRange.pmStart : undefined;
272443
+ let pmEnd = typeof attrsRange?.pmEnd === "number" ? attrsRange.pmEnd : undefined;
272444
+ if (pmStart == null && block.kind === "paragraph") {
272445
+ const runs2 = block.runs;
272446
+ if (Array.isArray(runs2))
272447
+ for (const run2 of runs2) {
272448
+ const rs = run2.pmStart;
272449
+ const re2 = run2.pmEnd;
272450
+ if (typeof rs === "number")
272451
+ pmStart = pmStart == null ? rs : Math.min(pmStart, rs);
272452
+ if (typeof re2 === "number")
272453
+ pmEnd = pmEnd == null ? re2 : Math.max(pmEnd, re2);
272454
+ }
272455
+ }
272456
+ if (pmStart == null)
272457
+ return null;
272458
+ return {
272459
+ pmStart,
272460
+ pmEnd: pmEnd ?? pmStart + 1
272461
+ };
272462
+ };
272463
+ const refByPos = /* @__PURE__ */ new Map;
272464
+ const seenIds = /* @__PURE__ */ new Set;
272465
+ for (const ref$1 of refs) {
272466
+ if (seenIds.has(ref$1.id))
272467
+ continue;
272468
+ seenIds.add(ref$1.id);
272469
+ refByPos.set(ref$1.pos, ref$1.id);
272470
+ }
272471
+ const recordIfHit = (range, topLevelId) => {
272472
+ for (const [pos, refId] of refByPos.entries()) {
272473
+ if (pos < range.pmStart || pos > range.pmEnd)
272474
+ continue;
272475
+ const fullHeight = bodyHeights.get(refId);
272476
+ if (typeof fullHeight !== "number" || !Number.isFinite(fullHeight) || fullHeight <= 0)
272477
+ continue;
272478
+ const firstLineRaw = firstLineHeights?.get(refId);
272479
+ const firstLineHeight = typeof firstLineRaw === "number" && Number.isFinite(firstLineRaw) && firstLineRaw > 0 ? Math.min(firstLineRaw, fullHeight) : fullHeight;
272480
+ const list5 = out.get(topLevelId) ?? [];
272481
+ list5.push({
272482
+ pmPos: pos,
272483
+ refId,
272484
+ fullHeight,
272485
+ firstLineHeight
272486
+ });
272487
+ out.set(topLevelId, list5);
272488
+ refByPos.delete(pos);
272489
+ }
272490
+ };
272491
+ for (const block of blocks2) {
272492
+ if (refByPos.size === 0)
272493
+ break;
272494
+ const range = resolveBlockPmRange(block);
272495
+ if (range)
272496
+ recordIfHit(range, block.id);
272497
+ if (block.kind === "table")
272498
+ for (const row2 of block.rows ?? [])
272499
+ for (const cell2 of row2.cells ?? []) {
272500
+ const cellChildren = cell2.blocks ? cell2.blocks : cell2.paragraph ? [cell2.paragraph] : [];
272501
+ for (const child of cellChildren) {
272502
+ const childRange = resolveBlockPmRange(child);
272503
+ if (childRange)
272504
+ recordIfHit(childRange, block.id);
272505
+ }
272506
+ }
272507
+ }
272508
+ for (const list5 of out.values())
272509
+ list5.sort((a2, b$1) => a2.pmPos - b$1.pmPos);
272510
+ return out;
272511
+ })();
272512
+ const getFootnoteAnchorsForBlockId = (blockId, pmStart, pmEnd) => {
272513
+ const entries2 = footnoteAnchorsByBlockId.get(blockId);
272514
+ if (!entries2 || entries2.length === 0)
272515
+ return [];
272516
+ if (pmStart == null || pmEnd == null)
272517
+ return entries2;
272518
+ const out = [];
272519
+ for (const e of entries2)
272520
+ if (e.pmPos >= pmStart && e.pmPos <= pmEnd)
272521
+ out.push(e);
272522
+ return out;
272523
+ };
272524
+ const getFootnoteDemandForBlockId = (blockId, pmStart, pmEnd, committed) => {
272525
+ const candidate = getFootnoteAnchorsForBlockId(blockId, pmStart, pmEnd);
272526
+ if (candidate.length === 0 && (!committed || committed.length === 0))
272527
+ return 0;
272528
+ const cluster = committed && committed.length > 0 ? [...committed, ...candidate] : candidate;
272529
+ if (cluster.length === 0)
272530
+ return 0;
272531
+ let total = 0;
272532
+ for (let i4 = 0;i4 < cluster.length - 1; i4 += 1)
272533
+ total += cluster[i4].fullHeight;
272534
+ total += cluster[cluster.length - 1].firstLineHeight;
272535
+ return total;
272536
+ };
272537
+ const getFootnoteRefCountForBlockId = (blockId, pmStart, pmEnd) => {
272538
+ const entries2 = footnoteAnchorsByBlockId.get(blockId);
272539
+ if (!entries2 || entries2.length === 0)
272540
+ return 0;
272541
+ if (pmStart == null || pmEnd == null)
272542
+ return entries2.length;
272543
+ let count2 = 0;
272544
+ for (const e of entries2)
272545
+ if (e.pmPos >= pmStart && e.pmPos <= pmEnd)
272546
+ count2 += 1;
272547
+ return count2;
272548
+ };
272549
+ const getFootnoteBandOverhead = (() => {
272550
+ const fn2 = options.footnotes;
272551
+ const safeNum = (v, fallback) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : fallback;
272552
+ const topPadding = safeNum(fn2?.topPadding, 6);
272553
+ const dividerHeight = safeNum(fn2?.dividerHeight, 6);
272554
+ const separatorSpacingBefore = safeNum(fn2?.separatorSpacingBefore, 12);
272555
+ const gap = safeNum(fn2?.gap, 2);
272556
+ return (refsTotal) => {
272557
+ if (refsTotal <= 0)
272558
+ return 0;
272559
+ return topPadding + dividerHeight + separatorSpacingBefore + Math.max(0, refsTotal - 1) * gap;
272560
+ };
272561
+ })();
271975
272562
  let pageCount = 0;
271976
272563
  let activeNumberFormat = "decimal";
271977
272564
  let activePageCounter = 1;
@@ -272010,15 +272597,19 @@ function layoutDocument(blocks2, measures, options = {}) {
272010
272597
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
272011
272598
  let pendingSectionIndex = null;
272012
272599
  const sectionFirstPageNumbers = /* @__PURE__ */ new Map;
272600
+ const readFootnoteReserveForPageIndex = (pageIndex) => {
272601
+ const reserves = options.footnoteReservedByPageIndex;
272602
+ const reserve = Array.isArray(reserves) ? reserves[pageIndex] : 0;
272603
+ return typeof reserve === "number" && Number.isFinite(reserve) && reserve > 0 ? reserve : 0;
272604
+ };
272013
272605
  const paginator = createPaginator({
272014
272606
  margins: paginatorMargins,
272015
272607
  getActiveTopMargin: () => activeTopMargin,
272016
272608
  getActiveBottomMargin: () => {
272017
- const reserves = options.footnoteReservedByPageIndex;
272018
272609
  const pageIndex = Math.max(0, pageCount - 1);
272019
- const reserve = Array.isArray(reserves) ? reserves[pageIndex] : 0;
272020
- return activeBottomMargin + (typeof reserve === "number" && Number.isFinite(reserve) && reserve > 0 ? reserve : 0);
272610
+ return activeBottomMargin + readFootnoteReserveForPageIndex(pageIndex);
272021
272611
  },
272612
+ getFootnoteReserveForPage: (pageIndex) => readFootnoteReserveForPageIndex(pageIndex),
272022
272613
  getActiveHeaderDistance: () => activeHeaderDistance,
272023
272614
  getActiveFooterDistance: () => activeFooterDistance,
272024
272615
  getActivePageSize: () => activePageSize,
@@ -272651,7 +273242,11 @@ function layoutDocument(blocks2, measures, options = {}) {
272651
273242
  columnX,
272652
273243
  floatManager,
272653
273244
  remeasureParagraph: options.remeasureParagraph,
272654
- overrideSpacingAfter
273245
+ overrideSpacingAfter,
273246
+ getFootnoteDemandForBlockId,
273247
+ getFootnoteRefCountForBlockId,
273248
+ getFootnoteBandOverhead,
273249
+ getFootnoteAnchorsForBlockId
272655
273250
  }, anchorsForPara ? {
272656
273251
  anchoredDrawings: anchorsForPara,
272657
273252
  pageWidth: activePageSize.w,
@@ -272988,6 +273583,14 @@ function layoutDocument(blocks2, measures, options = {}) {
272988
273583
  }
272989
273584
  state.page.columnRegions = regions;
272990
273585
  }
273586
+ for (let i4 = 0;i4 < pages.length && i4 < paginator.states.length; i4++) {
273587
+ const s2 = paginator.states[i4];
273588
+ const maxY = s2.maxCursorY ?? 0;
273589
+ const cursorY = s2.cursorY ?? 0;
273590
+ const trailing = s2.trailingSpacing ?? 0;
273591
+ const adjusted = Math.max(maxY, cursorY) - (cursorY >= maxY ? trailing : 0);
273592
+ pages[i4].bodyMaxY = Math.max(s2.topMargin ?? 0, adjusted);
273593
+ }
272991
273594
  return {
272992
273595
  pageSize,
272993
273596
  pages,
@@ -274471,9 +275074,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274471
275074
  headerFooter = undefined;
274472
275075
  nextBlocks = rewriteSectionBreaksForSemanticFlow(nextBlocks, options);
274473
275076
  }
274474
- const dirtyStart = performance.now();
274475
275077
  const dirty = computeDirtyRegions(previousBlocks, nextBlocks);
274476
- performance.now() - dirtyStart;
274477
275078
  if (dirty.deletedBlockIds.length > 0)
274478
275079
  measureCache.invalidate(dirty.deletedBlockIds);
274479
275080
  const perSectionConstraints = computePerSectionConstraints(options, nextBlocks);
@@ -274664,7 +275265,6 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274664
275265
  remeasureParagraph: (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent)
274665
275266
  });
274666
275267
  perfLog$1(`[Perf] 4.2 Layout document (pagination): ${(performance.now() - layoutStart).toFixed(2)}ms`);
274667
- layout.pages.length;
274668
275268
  const maxIterations = 3;
274669
275269
  let currentBlocks = nextBlocks;
274670
275270
  let currentMeasures = measures;
@@ -274748,7 +275348,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274748
275348
  const safeTopPadding = Math.max(0, topPadding);
274749
275349
  const safeDividerHeight = Math.max(0, dividerHeight);
274750
275350
  const continuationDividerHeight = safeDividerHeight;
274751
- const continuationDividerWidthFactor = 0.3;
275351
+ const SEPARATOR_DEFAULT_WIDTH_FACTOR = 0.5;
274752
275352
  const footnoteWidth = resolveFootnoteMeasurementWidth(options, currentBlocks);
274753
275353
  if (footnoteWidth > 0) {
274754
275354
  const footnoteConstraints = {
@@ -274796,6 +275396,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274796
275396
  const hasContinuationByColumn = /* @__PURE__ */ new Map;
274797
275397
  const rangesByFootnoteId = /* @__PURE__ */ new Map;
274798
275398
  const cappedPages = /* @__PURE__ */ new Set;
275399
+ const ledgersByPage = /* @__PURE__ */ new Map;
274799
275400
  collectFootnoteIdsByColumn(idsByColumn$1).forEach((id2) => {
274800
275401
  const blocks2 = footnotesInput.blocksById.get(id2) ?? [];
274801
275402
  rangesByFootnoteId.set(id2, buildFootnoteRanges(blocks2, measuresById$1));
@@ -274808,25 +275409,23 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274808
275409
  const maxReserve = computeMaxFootnoteReserve(layoutForPages, pageIndex, baseReserve);
274809
275410
  const columns = pageColumns$1.get(pageIndex);
274810
275411
  const columnCount = Math.max(1, Math.floor(columns?.count ?? 1));
274811
- let demand = 0;
274812
- for (let columnIndex = 0;columnIndex < columnCount; columnIndex += 1) {
274813
- const ids = idsByColumn$1.get(pageIndex)?.get(columnIndex) ?? [];
274814
- let columnDemand = 0;
274815
- ids.forEach((id2, idx) => {
274816
- const ranges = rangesByFootnoteId.get(id2) ?? [];
274817
- let rangesHeight = 0;
274818
- ranges.forEach((range) => {
274819
- const spacingAfter = "spacingAfter" in range ? range.spacingAfter ?? 0 : 0;
274820
- rangesHeight += range.height + spacingAfter;
274821
- });
274822
- columnDemand += rangesHeight + (idx > 0 ? safeGap : 0);
275412
+ const placementCeiling = maxReserve;
275413
+ const fullHeightOf = (id2) => {
275414
+ const ranges = rangesByFootnoteId.get(id2) ?? [];
275415
+ let total = 0;
275416
+ ranges.forEach((range) => {
275417
+ const spacingAfter = "spacingAfter" in range ? range.spacingAfter ?? 0 : 0;
275418
+ total += range.height + spacingAfter;
274823
275419
  });
274824
- if (columnDemand > 0)
274825
- columnDemand += safeSeparatorSpacingBefore + safeDividerHeight + safeTopPadding;
274826
- if (columnDemand > demand)
274827
- demand = columnDemand;
274828
- }
274829
- const placementCeiling = demand > 0 ? Math.min(Math.ceil(demand), maxReserve) : maxReserve;
275420
+ return total;
275421
+ };
275422
+ const firstLineOf = (id2) => {
275423
+ const measured = firstLineHeightById.get(id2);
275424
+ if (typeof measured === "number" && Number.isFinite(measured) && measured > 0)
275425
+ return measured;
275426
+ const ranges = rangesByFootnoteId.get(id2) ?? [];
275427
+ return ranges.length > 0 ? ranges[0].height : 0;
275428
+ };
274830
275429
  const pendingForPage = /* @__PURE__ */ new Map;
274831
275430
  pendingByColumn.forEach((entries2, columnIndex) => {
274832
275431
  const targetIndex = columnIndex < columnCount ? columnIndex : Math.max(0, columnCount - 1);
@@ -274834,6 +275433,21 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274834
275433
  list5.push(...entries2);
274835
275434
  pendingForPage.set(targetIndex, list5);
274836
275435
  });
275436
+ const continuationInForPage = [];
275437
+ pendingForPage.forEach((entries2) => {
275438
+ entries2.forEach((entry) => {
275439
+ let total = 0;
275440
+ entry.ranges.forEach((range) => {
275441
+ const spacingAfter = "spacingAfter" in range ? range.spacingAfter ?? 0 : 0;
275442
+ total += range.height + spacingAfter;
275443
+ });
275444
+ continuationInForPage.push({
275445
+ id: entry.id,
275446
+ remainingRangeCount: entry.ranges.length,
275447
+ remainingHeightPx: total
275448
+ });
275449
+ });
275450
+ });
274837
275451
  pendingByColumn = /* @__PURE__ */ new Map;
274838
275452
  const pageSlices = [];
274839
275453
  let pageReserve = 0;
@@ -274841,9 +275455,8 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274841
275455
  let usedHeight = 0;
274842
275456
  const columnSlices = [];
274843
275457
  const nextPending = [];
274844
- let stopPlacement = false;
274845
275458
  const columnKey = footnoteColumnKey(pageIndex, columnIndex);
274846
- const placeFootnote = (id2, ranges, isContinuation) => {
275459
+ const placeFootnote = (id2, ranges, isContinuation, isLastOnPage) => {
274847
275460
  if (!ranges || ranges.length === 0)
274848
275461
  return {
274849
275462
  placed: false,
@@ -274852,12 +275465,17 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274852
275465
  const isFirstSlice = columnSlices.length === 0;
274853
275466
  const overhead = isFirstSlice ? (isFirstSlice ? safeSeparatorSpacingBefore : 0) + (isFirstSlice ? isContinuation ? continuationDividerHeight : safeDividerHeight : 0) + safeTopPadding : 0;
274854
275467
  const gapBefore = !isFirstSlice ? safeGap : 0;
274855
- const { slice: slice2, remainingRanges } = fitFootnoteContent(id2, ranges, Math.max(0, placementCeiling - usedHeight - overhead - gapBefore), pageIndex, columnIndex, isContinuation, measuresById$1, isFirstSlice && placementCeiling > 0);
275468
+ const { slice: slice2, remainingRanges } = fitFootnoteContent(id2, ranges, Math.max(0, placementCeiling - usedHeight - overhead - gapBefore), pageIndex, columnIndex, isContinuation, measuresById$1, (isLastOnPage || isContinuation) && placementCeiling > 0);
274856
275469
  if (slice2.ranges.length === 0)
274857
275470
  return {
274858
275471
  placed: false,
274859
275472
  remaining: ranges
274860
275473
  };
275474
+ if (!isLastOnPage && !isContinuation && remainingRanges.length > 0)
275475
+ return {
275476
+ placed: false,
275477
+ remaining: ranges
275478
+ };
274861
275479
  if (isFirstSlice) {
274862
275480
  usedHeight += overhead;
274863
275481
  if (isContinuation)
@@ -274872,19 +275490,25 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274872
275490
  remaining: remainingRanges
274873
275491
  };
274874
275492
  };
275493
+ const ids = idsByColumn$1.get(pageIndex)?.get(columnIndex) ?? [];
275494
+ const lastIdx = ids.length - 1;
275495
+ let clusterReserve = 0;
275496
+ for (let i4 = 0;i4 < ids.length; i4 += 1) {
275497
+ clusterReserve += i4 === lastIdx ? firstLineOf(ids[i4]) : fullHeightOf(ids[i4]);
275498
+ if (i4 > 0)
275499
+ clusterReserve += safeGap;
275500
+ }
275501
+ usedHeight += clusterReserve;
274875
275502
  const pending = pendingForPage.get(columnIndex) ?? [];
274876
- for (const entry of pending) {
274877
- if (stopPlacement) {
274878
- nextPending.push(entry);
274879
- continue;
274880
- }
275503
+ for (let pendingIdx = 0;pendingIdx < pending.length; pendingIdx += 1) {
275504
+ const entry = pending[pendingIdx];
274881
275505
  if (!entry.ranges || entry.ranges.length === 0)
274882
275506
  continue;
274883
- const result = placeFootnote(entry.id, entry.ranges, true);
275507
+ const result = placeFootnote(entry.id, entry.ranges, true, false);
274884
275508
  if (!result.placed) {
274885
- nextPending.push(entry);
274886
- stopPlacement = true;
274887
- continue;
275509
+ for (let deferIdx = pendingIdx;deferIdx < pending.length; deferIdx += 1)
275510
+ nextPending.push(pending[deferIdx]);
275511
+ break;
274888
275512
  }
274889
275513
  if (result.remaining.length > 0)
274890
275514
  nextPending.push({
@@ -274892,36 +275516,33 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274892
275516
  ranges: result.remaining
274893
275517
  });
274894
275518
  }
274895
- if (!stopPlacement) {
274896
- const ids = idsByColumn$1.get(pageIndex)?.get(columnIndex) ?? [];
274897
- for (let idIndex = 0;idIndex < ids.length; idIndex += 1) {
274898
- const id2 = ids[idIndex];
274899
- const ranges = rangesByFootnoteId.get(id2) ?? [];
274900
- if (ranges.length === 0)
274901
- continue;
274902
- const result = placeFootnote(id2, ranges, false);
274903
- if (!result.placed) {
275519
+ usedHeight -= clusterReserve;
275520
+ for (let idIndex = 0;idIndex < ids.length; idIndex += 1) {
275521
+ const id2 = ids[idIndex];
275522
+ const ranges = rangesByFootnoteId.get(id2) ?? [];
275523
+ if (ranges.length === 0)
275524
+ continue;
275525
+ const result = placeFootnote(id2, ranges, false, idIndex === lastIdx);
275526
+ if (!result.placed) {
275527
+ nextPending.push({
275528
+ id: id2,
275529
+ ranges
275530
+ });
275531
+ for (let remainingIndex = idIndex + 1;remainingIndex < ids.length; remainingIndex += 1) {
275532
+ const remainingId = ids[remainingIndex];
275533
+ const remainingRanges = rangesByFootnoteId.get(remainingId) ?? [];
274904
275534
  nextPending.push({
274905
- id: id2,
274906
- ranges
275535
+ id: remainingId,
275536
+ ranges: remainingRanges
274907
275537
  });
274908
- for (let remainingIndex = idIndex + 1;remainingIndex < ids.length; remainingIndex += 1) {
274909
- const remainingId = ids[remainingIndex];
274910
- const remainingRanges = rangesByFootnoteId.get(remainingId) ?? [];
274911
- nextPending.push({
274912
- id: remainingId,
274913
- ranges: remainingRanges
274914
- });
274915
- }
274916
- stopPlacement = true;
274917
- break;
274918
275538
  }
274919
- if (result.remaining.length > 0)
274920
- nextPending.push({
274921
- id: id2,
274922
- ranges: result.remaining
274923
- });
275539
+ break;
274924
275540
  }
275541
+ if (result.remaining.length > 0)
275542
+ nextPending.push({
275543
+ id: id2,
275544
+ ranges: result.remaining
275545
+ });
274925
275546
  }
274926
275547
  if (columnSlices.length > 0) {
274927
275548
  const rawReserve = Math.max(0, Math.ceil(usedHeight));
@@ -274936,7 +275557,148 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274936
275557
  }
274937
275558
  if (pageSlices.length > 0)
274938
275559
  slicesByPage.set(pageIndex, pageSlices);
274939
- reserves$1[pageIndex] = pageReserve;
275560
+ reserves$1[pageIndex] = Math.max(reserves$1[pageIndex] ?? 0, pageReserve);
275561
+ {
275562
+ const idsOnPage = (() => {
275563
+ const out = [];
275564
+ for (let cIdx = 0;cIdx < columnCount; cIdx += 1) {
275565
+ const colIds = idsByColumn$1.get(pageIndex)?.get(cIdx) ?? [];
275566
+ for (const id2 of colIds)
275567
+ if (!out.includes(id2))
275568
+ out.push(id2);
275569
+ }
275570
+ return out;
275571
+ })();
275572
+ const seenNewAnchor = /* @__PURE__ */ new Set;
275573
+ const mandatorySliceIds = [];
275574
+ const continuationSliceIds = [];
275575
+ const extendedSliceIds = [];
275576
+ let actualBandHeight = 0;
275577
+ const overheadBase = Math.max(0, separatorSpacingBefore) + safeDividerHeight + safeTopPadding;
275578
+ for (const slice2 of pageSlices) {
275579
+ if (slice2.isContinuation)
275580
+ continuationSliceIds.push(slice2.id);
275581
+ else if (!seenNewAnchor.has(slice2.id)) {
275582
+ mandatorySliceIds.push(slice2.id);
275583
+ seenNewAnchor.add(slice2.id);
275584
+ } else
275585
+ extendedSliceIds.push(slice2.id);
275586
+ actualBandHeight += slice2.totalHeight;
275587
+ }
275588
+ if (pageSlices.length > 0)
275589
+ actualBandHeight += overheadBase + safeGap * Math.max(0, pageSlices.length - 1);
275590
+ let mandatoryReserve = 0;
275591
+ let preferredReserve = 0;
275592
+ let continuationInHeight = 0;
275593
+ for (const entry of continuationInForPage)
275594
+ continuationInHeight += entry.remainingHeightPx;
275595
+ if (continuationInHeight > 0) {
275596
+ mandatoryReserve += continuationInHeight;
275597
+ preferredReserve += continuationInHeight;
275598
+ if (idsOnPage.length > 0) {
275599
+ mandatoryReserve += safeGap;
275600
+ preferredReserve += safeGap;
275601
+ }
275602
+ }
275603
+ if (idsOnPage.length > 0) {
275604
+ for (let i4 = 0;i4 < idsOnPage.length; i4 += 1) {
275605
+ const isLast = i4 === idsOnPage.length - 1;
275606
+ mandatoryReserve += isLast ? firstLineOf(idsOnPage[i4]) : fullHeightOf(idsOnPage[i4]);
275607
+ preferredReserve += fullHeightOf(idsOnPage[i4]);
275608
+ if (i4 > 0) {
275609
+ mandatoryReserve += safeGap;
275610
+ preferredReserve += safeGap;
275611
+ }
275612
+ }
275613
+ mandatoryReserve += overheadBase;
275614
+ preferredReserve += overheadBase;
275615
+ } else if (continuationInHeight > 0) {
275616
+ mandatoryReserve += overheadBase;
275617
+ preferredReserve += overheadBase;
275618
+ }
275619
+ let lastAnchorRenderedLines = 0;
275620
+ if (idsOnPage.length > 0) {
275621
+ const lastId = idsOnPage[idsOnPage.length - 1];
275622
+ for (const slice2 of pageSlices) {
275623
+ if (slice2.id !== lastId || slice2.isContinuation)
275624
+ continue;
275625
+ for (const range of slice2.ranges)
275626
+ if (range.kind === "paragraph" || range.kind === "list-item")
275627
+ lastAnchorRenderedLines += Math.max(0, range.toLine - range.fromLine);
275628
+ else
275629
+ lastAnchorRenderedLines += 1;
275630
+ }
275631
+ }
275632
+ const continuationOut = [];
275633
+ pendingByColumn.forEach((entries2) => {
275634
+ entries2.forEach((entry) => {
275635
+ let total = 0;
275636
+ entry.ranges.forEach((range) => {
275637
+ const spacingAfter = "spacingAfter" in range ? range.spacingAfter ?? 0 : 0;
275638
+ total += range.height + spacingAfter;
275639
+ });
275640
+ continuationOut.push({
275641
+ id: entry.id,
275642
+ remainingRangeCount: entry.ranges.length,
275643
+ remainingHeightPx: total
275644
+ });
275645
+ });
275646
+ });
275647
+ ledgersByPage.set(pageIndex, {
275648
+ anchorIds: idsOnPage,
275649
+ mandatorySliceIds,
275650
+ continuationSliceIds,
275651
+ extendedSliceIds,
275652
+ continuationIn: continuationInForPage,
275653
+ continuationOut,
275654
+ mandatoryReservePx: Math.ceil(mandatoryReserve),
275655
+ preferredReservePx: Math.ceil(preferredReserve),
275656
+ actualBandHeightPx: Math.ceil(actualBandHeight),
275657
+ lastAnchorRenderedLines
275658
+ });
275659
+ }
275660
+ if (pageIndex + 1 < pageCount) {
275661
+ let continuationDemand = 0;
275662
+ pendingByColumn.forEach((entries2) => {
275663
+ entries2.forEach((entry) => {
275664
+ entry.ranges.forEach((range) => {
275665
+ const spacingAfter = "spacingAfter" in range ? range.spacingAfter ?? 0 : 0;
275666
+ continuationDemand += range.height + spacingAfter;
275667
+ });
275668
+ });
275669
+ });
275670
+ let nextClusterDemand = 0;
275671
+ for (let cIdx = 0;cIdx < columnCount; cIdx += 1) {
275672
+ const idsNext = idsByColumn$1.get(pageIndex + 1)?.get(cIdx) ?? [];
275673
+ if (idsNext.length === 0)
275674
+ continue;
275675
+ let columnCluster = 0;
275676
+ for (let i4 = 0;i4 < idsNext.length; i4 += 1) {
275677
+ const isLast = i4 === idsNext.length - 1;
275678
+ columnCluster += isLast ? firstLineOf(idsNext[i4]) : fullHeightOf(idsNext[i4]);
275679
+ if (i4 > 0)
275680
+ columnCluster += safeGap;
275681
+ }
275682
+ if (columnCluster > nextClusterDemand)
275683
+ nextClusterDemand = columnCluster;
275684
+ }
275685
+ if (continuationDemand > 0 || nextClusterDemand > 0) {
275686
+ const overhead = safeSeparatorSpacingBefore + continuationDividerHeight + safeTopPadding;
275687
+ const nextPage = layoutForPages.pages?.[pageIndex + 1];
275688
+ const nextPageSize = nextPage?.size ?? layoutForPages.pageSize ?? DEFAULT_PAGE_SIZE$1;
275689
+ const nextTop = normalizeMargin(nextPage?.margins?.top, DEFAULT_MARGINS$1.top);
275690
+ const nextBottomRaw = normalizeMargin(nextPage?.margins?.bottom, DEFAULT_MARGINS$1.bottom);
275691
+ const physicalContentHeight = Math.max(0, nextPageSize.h - nextTop - nextBottomRaw);
275692
+ const minBodyHeight = MIN_FOOTNOTE_BODY_HEIGHT * 20;
275693
+ const nextPageMaxBand = Math.max(0, physicalContentHeight - minBodyHeight);
275694
+ const overheadForBand = nextClusterDemand > 0 || continuationDemand > 0 ? overhead : 0;
275695
+ const clusterRoomPx = nextClusterDemand > 0 ? Math.min(nextClusterDemand, Math.max(0, nextPageMaxBand - overheadForBand)) : 0;
275696
+ const continuationRoomPx = Math.max(0, nextPageMaxBand - overheadForBand - clusterRoomPx);
275697
+ const continuationToReservePx = Math.min(continuationDemand, continuationRoomPx);
275698
+ const finalReserve = Math.min(clusterRoomPx + continuationToReservePx + overheadForBand, nextPageMaxBand);
275699
+ reserves$1[pageIndex + 1] = Math.max(reserves$1[pageIndex + 1] ?? 0, Math.ceil(finalReserve));
275700
+ }
275701
+ }
274940
275702
  }
274941
275703
  if (cappedPages.size > 0)
274942
275704
  console.warn("[layout] Footnote reserve capped to preserve body area", { pages: Array.from(cappedPages) });
@@ -274949,7 +275711,8 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274949
275711
  slicesByPage,
274950
275712
  reserves: reserves$1,
274951
275713
  hasContinuationByColumn,
274952
- separatorSpacingBefore: safeSeparatorSpacingBefore
275714
+ separatorSpacingBefore: safeSeparatorSpacingBefore,
275715
+ ledgersByPage
274953
275716
  };
274954
275717
  };
274955
275718
  const injectFragments = (layoutForPages, plan$1, measuresById$1, reservesByPageIndex, blockById, pageColumns$1) => {
@@ -274958,6 +275721,23 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274958
275721
  for (let pageIndex = 0;pageIndex < layoutForPages.pages.length; pageIndex++) {
274959
275722
  const page = layoutForPages.pages[pageIndex];
274960
275723
  page.footnoteReserved = Math.max(0, reservesByPageIndex[pageIndex] ?? plan$1.reserves[pageIndex] ?? 0);
275724
+ const draft = plan$1.ledgersByPage.get(pageIndex);
275725
+ if (draft)
275726
+ page.footnoteLedger = {
275727
+ pageIndex,
275728
+ anchorIds: draft.anchorIds,
275729
+ mandatorySliceIds: draft.mandatorySliceIds,
275730
+ continuationSliceIds: draft.continuationSliceIds,
275731
+ extendedSliceIds: draft.extendedSliceIds,
275732
+ continuationIn: draft.continuationIn,
275733
+ continuationOut: draft.continuationOut,
275734
+ mandatoryReservePx: draft.mandatoryReservePx,
275735
+ preferredReservePx: draft.preferredReservePx,
275736
+ actualBandHeightPx: draft.actualBandHeightPx,
275737
+ appliedBodyReservePx: page.footnoteReserved ?? 0,
275738
+ deadReservePx: Math.max(0, (page.footnoteReserved ?? 0) - draft.actualBandHeightPx),
275739
+ lastAnchorRenderedLines: draft.lastAnchorRenderedLines
275740
+ };
274961
275741
  const slices = plan$1.slicesByPage.get(pageIndex) ?? [];
274962
275742
  if (slices.length === 0)
274963
275743
  continue;
@@ -274973,7 +275753,10 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274973
275753
  left: marginLeft,
274974
275754
  contentWidth: pageContentWidth
274975
275755
  };
274976
- const bandTopY = pageSize.h - (page.margins.bottom ?? 0);
275756
+ const physicalBottomMargin = Math.max(0, (page.margins.bottom ?? 0) - (page.footnoteReserved ?? 0));
275757
+ const pageBottomLimit = pageSize.h - physicalBottomMargin;
275758
+ const bodyMaxYValue = page.bodyMaxY;
275759
+ const bodyMaxY = typeof bodyMaxYValue === "number" && Number.isFinite(bodyMaxYValue) ? bodyMaxYValue : pageSize.h - (page.margins.bottom ?? 0);
274977
275760
  const slicesByColumn = /* @__PURE__ */ new Map;
274978
275761
  slices.forEach((slice2) => {
274979
275762
  const columnIndex = Number.isFinite(slice2.columnIndex) ? slice2.columnIndex : 0;
@@ -274992,9 +275775,16 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
274992
275775
  return;
274993
275776
  const columnKey = footnoteColumnKey(pageIndex, columnIndex);
274994
275777
  const isContinuation = plan$1.hasContinuationByColumn.get(columnKey) ?? false;
274995
- let cursorY = bandTopY + Math.max(0, plan$1.separatorSpacingBefore);
275778
+ const colSeparatorHeight = isContinuation ? continuationDividerHeight : safeDividerHeight;
275779
+ let colTotalBandHeight = Math.max(0, plan$1.separatorSpacingBefore) + colSeparatorHeight + safeTopPadding;
275780
+ for (let s2 = 0;s2 < columnSlices.length; s2 += 1) {
275781
+ colTotalBandHeight += columnSlices[s2].totalHeight;
275782
+ if (s2 > 0)
275783
+ colTotalBandHeight += safeGap;
275784
+ }
275785
+ let cursorY = Math.max(bodyMaxY, pageBottomLimit - colTotalBandHeight) + Math.max(0, plan$1.separatorSpacingBefore);
274996
275786
  const separatorHeight = isContinuation ? continuationDividerHeight : safeDividerHeight;
274997
- const separatorWidth = isContinuation ? Math.max(0, contentWidth * continuationDividerWidthFactor) : contentWidth;
275787
+ const separatorWidth = isContinuation ? contentWidth : Math.max(0, contentWidth * SEPARATOR_DEFAULT_WIDTH_FACTOR);
274998
275788
  if (separatorHeight > 0 && separatorWidth > 0) {
274999
275789
  const separatorId = isContinuation ? `footnote-continuation-separator-page-${page.number}-col-${columnIndex}` : `footnote-separator-page-${page.number}-col-${columnIndex}`;
275000
275790
  decorativeBlocks.push({
@@ -275170,9 +275960,77 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
275170
275960
  idsByColumn: assignFootnotesToColumns(layoutForPages, footnotesInput.refs, columns)
275171
275961
  };
275172
275962
  };
275173
- const relayout = (footnoteReservedByPageIndex) => layoutDocument(currentBlocks, currentMeasures, {
275963
+ let bodyHeightById = /* @__PURE__ */ new Map;
275964
+ let firstLineHeightById = /* @__PURE__ */ new Map;
275965
+ const refreshBodyHeights = (measures$1) => {
275966
+ const totalMap = /* @__PURE__ */ new Map;
275967
+ const firstLineMap = /* @__PURE__ */ new Map;
275968
+ footnotesInput.blocksById.forEach((blocks2, footnoteId) => {
275969
+ let total = 0;
275970
+ let firstLine = 0;
275971
+ for (const block of blocks2) {
275972
+ const measure = measures$1.get(block.id);
275973
+ if (!measure)
275974
+ continue;
275975
+ if (measure.kind === "paragraph") {
275976
+ const measureH = measure.totalHeight;
275977
+ if (typeof measureH === "number" && Number.isFinite(measureH))
275978
+ total += measureH;
275979
+ const spacing = block.attrs?.spacing;
275980
+ const after2 = spacing?.after ?? spacing?.lineSpaceAfter;
275981
+ if (typeof after2 === "number" && Number.isFinite(after2) && after2 > 0)
275982
+ total += after2;
275983
+ if (firstLine === 0) {
275984
+ const lines = measure.lines;
275985
+ const lh = lines && lines.length > 0 ? lines[0].lineHeight : undefined;
275986
+ if (typeof lh === "number" && Number.isFinite(lh) && lh > 0)
275987
+ firstLine = lh;
275988
+ }
275989
+ } else if (measure.kind === "image" || measure.kind === "drawing") {
275990
+ const measureH = measure.height;
275991
+ if (typeof measureH === "number" && Number.isFinite(measureH))
275992
+ total += measureH;
275993
+ if (firstLine === 0 && typeof measureH === "number" && Number.isFinite(measureH))
275994
+ firstLine = measureH;
275995
+ } else if (measure.kind === "table") {
275996
+ const measureH = measure.totalHeight;
275997
+ if (typeof measureH === "number" && Number.isFinite(measureH))
275998
+ total += measureH;
275999
+ if (firstLine === 0 && typeof measureH === "number" && Number.isFinite(measureH))
276000
+ firstLine = measureH;
276001
+ } else if (measure.kind === "list" && block.kind === "list") {
276002
+ for (const item of block.items) {
276003
+ const itemMeasure = measure.items.find((entry) => entry.itemId === item.id);
276004
+ if (!itemMeasure?.paragraph?.lines)
276005
+ continue;
276006
+ for (const line of itemMeasure.paragraph.lines)
276007
+ total += line.lineHeight ?? 0;
276008
+ total += getParagraphSpacingAfter(item.paragraph);
276009
+ }
276010
+ if (firstLine === 0) {
276011
+ const lh = measure.items[0]?.paragraph?.lines?.[0]?.lineHeight;
276012
+ if (typeof lh === "number" && Number.isFinite(lh) && lh > 0)
276013
+ firstLine = lh;
276014
+ }
276015
+ }
276016
+ }
276017
+ if (total > 0)
276018
+ totalMap.set(footnoteId, total);
276019
+ if (firstLine > 0)
276020
+ firstLineMap.set(footnoteId, firstLine);
276021
+ });
276022
+ bodyHeightById = totalMap;
276023
+ firstLineHeightById = firstLineMap;
276024
+ };
276025
+ const relayout = (footnoteReservedByPageIndex, plannerSeparatorSpacingBefore) => layoutDocument(currentBlocks, currentMeasures, {
275174
276026
  ...options,
275175
276027
  footnoteReservedByPageIndex,
276028
+ footnotes: {
276029
+ ...footnotesInput,
276030
+ bodyHeightById,
276031
+ firstLineHeightById,
276032
+ ...typeof plannerSeparatorSpacingBefore === "number" && Number.isFinite(plannerSeparatorSpacingBefore) ? { separatorSpacingBefore: plannerSeparatorSpacingBefore } : {}
276033
+ },
275176
276034
  headerContentHeights,
275177
276035
  footerContentHeights,
275178
276036
  headerContentHeightsBySectionRef,
@@ -275181,17 +276039,20 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
275181
276039
  footerContentHeightsByRId,
275182
276040
  remeasureParagraph: (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent)
275183
276041
  });
276042
+ const allFootnoteIds = new Set(footnotesInput.refs.map((ref$1) => ref$1.id));
275184
276043
  let { columns: pageColumns, idsByColumn } = resolveFootnoteAssignments(layout);
275185
- let { measuresById } = await measureFootnoteBlocks(collectFootnoteIdsByColumn(idsByColumn));
276044
+ let { measuresById } = await measureFootnoteBlocks(allFootnoteIds);
276045
+ refreshBodyHeights(measuresById);
275186
276046
  let plan = computeFootnoteLayoutPlan(layout, idsByColumn, measuresById, [], pageColumns);
275187
276047
  let reserves = plan.reserves;
275188
276048
  if (reserves.some((h$2) => h$2 > 0)) {
275189
276049
  let reservesStabilized = false;
275190
276050
  const seenReserveVectors = [reserves.slice()];
275191
276051
  for (let pass = 0;pass < MAX_FOOTNOTE_LAYOUT_PASSES; pass += 1) {
275192
- layout = relayout(reserves);
276052
+ layout = relayout(reserves, plan.separatorSpacingBefore);
275193
276053
  ({ columns: pageColumns, idsByColumn } = resolveFootnoteAssignments(layout));
275194
- ({ measuresById } = await measureFootnoteBlocks(collectFootnoteIdsByColumn(idsByColumn)));
276054
+ ({ measuresById } = await measureFootnoteBlocks(allFootnoteIds));
276055
+ refreshBodyHeights(measuresById);
275195
276056
  plan = computeFootnoteLayoutPlan(layout, idsByColumn, measuresById, reserves, pageColumns);
275196
276057
  const nextReserves = plan.reserves;
275197
276058
  if (nextReserves.length === reserves.length && nextReserves.every((h$2, i4) => (reserves[i4] ?? 0) === h$2) && reserves.every((h$2, i4) => (nextReserves[i4] ?? 0) === h$2)) {
@@ -275218,12 +276079,53 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
275218
276079
  return true;
275219
276080
  };
275220
276081
  const applyReserves = async (target) => {
275221
- layout = relayout(target);
276082
+ layout = relayout(target, finalPlan.separatorSpacingBefore);
275222
276083
  reservesAppliedToLayout = target;
275223
276084
  ({ columns: finalPageColumns, idsByColumn: finalIdsByColumn } = resolveFootnoteAssignments(layout));
275224
- ({ blocks: finalBlocks, measuresById: finalMeasuresById } = await measureFootnoteBlocks(collectFootnoteIdsByColumn(finalIdsByColumn)));
276085
+ ({ blocks: finalBlocks, measuresById: finalMeasuresById } = await measureFootnoteBlocks(allFootnoteIds));
276086
+ refreshBodyHeights(finalMeasuresById);
275225
276087
  finalPlan = computeFootnoteLayoutPlan(layout, finalIdsByColumn, finalMeasuresById, reservesAppliedToLayout, finalPageColumns);
275226
276088
  };
276089
+ const buildFootnoteLedgers = (plan$1, appliedReserves, pageCount) => {
276090
+ const ledgers = [];
276091
+ for (let pageIndex = 0;pageIndex < pageCount; pageIndex += 1) {
276092
+ const draft = plan$1.ledgersByPage.get(pageIndex);
276093
+ if (!draft)
276094
+ continue;
276095
+ const appliedBodyReservePx = Math.max(0, appliedReserves[pageIndex] ?? plan$1.reserves[pageIndex] ?? 0);
276096
+ ledgers.push({
276097
+ pageIndex,
276098
+ anchorIds: draft.anchorIds,
276099
+ mandatorySliceIds: draft.mandatorySliceIds,
276100
+ continuationSliceIds: draft.continuationSliceIds,
276101
+ extendedSliceIds: draft.extendedSliceIds,
276102
+ continuationIn: draft.continuationIn,
276103
+ continuationOut: draft.continuationOut,
276104
+ mandatoryReservePx: draft.mandatoryReservePx,
276105
+ preferredReservePx: draft.preferredReservePx,
276106
+ actualBandHeightPx: draft.actualBandHeightPx,
276107
+ appliedBodyReservePx,
276108
+ deadReservePx: Math.max(0, appliedBodyReservePx - draft.actualBandHeightPx),
276109
+ lastAnchorRenderedLines: draft.lastAnchorRenderedLines
276110
+ });
276111
+ }
276112
+ return ledgers;
276113
+ };
276114
+ const capReserveForRelayout = (requestedReserve, pageIndex, referenceLayout, referenceReserves) => {
276115
+ const requested = Number.isFinite(requestedReserve) ? Math.max(0, requestedReserve) : 0;
276116
+ const page = referenceLayout.pages?.[pageIndex];
276117
+ if (!page)
276118
+ return requested;
276119
+ const pageSize = page.size ?? referenceLayout.pageSize ?? DEFAULT_PAGE_SIZE$1;
276120
+ const topMargin = normalizeMargin(page.margins?.top, DEFAULT_MARGINS$1.top);
276121
+ const bottomWithReserve = normalizeMargin(page.margins?.bottom, DEFAULT_MARGINS$1.bottom);
276122
+ const currentReserve = Number.isFinite(referenceReserves[pageIndex]) ? Math.max(0, referenceReserves[pageIndex]) : 0;
276123
+ const physicalBottomMargin = Math.max(0, bottomWithReserve - currentReserve);
276124
+ const physicalContentHeight = pageSize.h - topMargin - physicalBottomMargin;
276125
+ if (!Number.isFinite(physicalContentHeight))
276126
+ return requested;
276127
+ return Math.min(requested, Math.max(0, physicalContentHeight - MIN_FOOTNOTE_BODY_HEIGHT));
276128
+ };
275227
276129
  const growReserves = async (maxPasses) => {
275228
276130
  const seen = [reservesAppliedToLayout.slice()];
275229
276131
  for (let pass = 0;pass < maxPasses; pass += 1) {
@@ -275249,6 +276151,74 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
275249
276151
  }
275250
276152
  return false;
275251
276153
  };
276154
+ const GROW_MAX_PASSES = 10;
276155
+ const PREFERRED_RESERVE_MAX_CANDIDATES = 12;
276156
+ const PREFERRED_RESERVE_MAX_ACCEPTED_CANDIDATES = PREFERRED_RESERVE_MAX_CANDIDATES;
276157
+ const PREFERRED_RESERVE_WINDOW_AHEAD = 3;
276158
+ const runPreferredReserveTrials = async () => {
276159
+ let acceptedPreferredTrials = 0;
276160
+ let rejectedPreferredTrials = 0;
276161
+ const rejectedPreferredPages = /* @__PURE__ */ new Set;
276162
+ for (let candidatePass = 0;candidatePass < PREFERRED_RESERVE_MAX_CANDIDATES; candidatePass += 1) {
276163
+ const beforeLayout = layout;
276164
+ const beforePlan = finalPlan;
276165
+ const beforeReserves = reservesAppliedToLayout.slice();
276166
+ const beforeLedgers = buildFootnoteLedgers(beforePlan, beforeReserves, beforeLayout.pages.length);
276167
+ const candidate = getPreferredReserveCandidates(beforeLedgers).find((entry) => !rejectedPreferredPages.has(entry.pageIndex));
276168
+ if (!candidate)
276169
+ break;
276170
+ const targetReserves = getPreferredReserveTrialTargets(candidate, beforeReserves[candidate.pageIndex] ?? 0);
276171
+ let acceptedCandidate = false;
276172
+ for (const targetReserve of targetReserves) {
276173
+ const trialReserves = beforeReserves.slice();
276174
+ const cappedPreferredReserve = capReserveForRelayout(targetReserve, candidate.pageIndex, beforeLayout, beforeReserves);
276175
+ trialReserves[candidate.pageIndex] = Math.max(trialReserves[candidate.pageIndex] ?? 0, cappedPreferredReserve);
276176
+ await applyReserves(trialReserves);
276177
+ const trialConverged = await growReserves(GROW_MAX_PASSES);
276178
+ const afterLedgers = buildFootnoteLedgers(finalPlan, reservesAppliedToLayout, layout.pages.length);
276179
+ const score = scoreFootnoteWindow({
276180
+ beforeLayout,
276181
+ afterLayout: layout,
276182
+ candidatePageIndex: candidate.pageIndex,
276183
+ candidateAnchorId: candidate.anchorIds[candidate.anchorIds.length - 1],
276184
+ beforeLedger: beforeLedgers,
276185
+ afterLedger: afterLedgers,
276186
+ windowAhead: PREFERRED_RESERVE_WINDOW_AHEAD
276187
+ });
276188
+ if (trialConverged && score.accept) {
276189
+ if (layoutDebugEnabled$1)
276190
+ console.log("[incrementalLayout] Accepted footnote preferred-reserve trial", {
276191
+ pageIndex: candidate.pageIndex,
276192
+ targetReserve,
276193
+ score
276194
+ });
276195
+ acceptedPreferredTrials += 1;
276196
+ acceptedCandidate = true;
276197
+ break;
276198
+ }
276199
+ if (layoutDebugEnabled$1)
276200
+ console.log("[incrementalLayout] Rejected footnote preferred-reserve trial", {
276201
+ pageIndex: candidate.pageIndex,
276202
+ targetReserve,
276203
+ trialConverged,
276204
+ score
276205
+ });
276206
+ await applyReserves(beforeReserves);
276207
+ }
276208
+ if (acceptedCandidate) {
276209
+ if (acceptedPreferredTrials >= PREFERRED_RESERVE_MAX_ACCEPTED_CANDIDATES)
276210
+ break;
276211
+ continue;
276212
+ }
276213
+ rejectedPreferredTrials += 1;
276214
+ rejectedPreferredPages.add(candidate.pageIndex);
276215
+ }
276216
+ if (layoutDebugEnabled$1 && (acceptedPreferredTrials > 0 || rejectedPreferredTrials > 0))
276217
+ console.log("[incrementalLayout] Footnote preferred-reserve trials", {
276218
+ accepted: acceptedPreferredTrials,
276219
+ rejected: rejectedPreferredTrials
276220
+ });
276221
+ };
275252
276222
  const TIGHTEN_SLACK_PX = 8;
275253
276223
  if ((() => {
275254
276224
  const plan$1 = finalPlan.reserves;
@@ -275261,10 +276231,11 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
275261
276231
  return true;
275262
276232
  if (a2 >= TIGHTEN_SLACK_PX && p$12 === 0)
275263
276233
  return true;
276234
+ if (a2 >= TIGHTEN_SLACK_PX && a2 - p$12 > TIGHTEN_SLACK_PX)
276235
+ return true;
275264
276236
  }
275265
276237
  return false;
275266
276238
  })()) {
275267
- const GROW_MAX_PASSES = 10;
275268
276239
  if (!await growReserves(GROW_MAX_PASSES))
275269
276240
  console.warn("[incrementalLayout] Footnote post-reserve loop did not converge; some pages may have footnotes overflowing the reserved band.");
275270
276241
  const MAX_TIGHTEN_ITERATIONS = 8;
@@ -275273,16 +276244,26 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
275273
276244
  for (let i4 = 0;i4 < reservesAppliedToLayout.length; i4 += 1) {
275274
276245
  const applied = reservesAppliedToLayout[i4] ?? 0;
275275
276246
  const planned = finalPlan.reserves[i4] ?? 0;
275276
- if (applied >= TIGHTEN_SLACK_PX && planned === 0)
275277
- pagesToTighten.push(i4);
276247
+ if (applied < TIGHTEN_SLACK_PX)
276248
+ continue;
276249
+ if (planned === 0)
276250
+ pagesToTighten.push({
276251
+ i: i4,
276252
+ target: 0
276253
+ });
276254
+ else if (applied - planned > TIGHTEN_SLACK_PX)
276255
+ pagesToTighten.push({
276256
+ i: i4,
276257
+ target: planned
276258
+ });
275278
276259
  }
275279
276260
  if (pagesToTighten.length === 0)
275280
276261
  break;
275281
276262
  const safeApplied = reservesAppliedToLayout.slice();
275282
276263
  const safePageCount = layout.pages.length;
275283
276264
  const tightened = reservesAppliedToLayout.slice();
275284
- for (const i4 of pagesToTighten)
275285
- tightened[i4] = 0;
276265
+ for (const { i: i4, target } of pagesToTighten)
276266
+ tightened[i4] = target;
275286
276267
  await applyReserves(tightened);
275287
276268
  if (!await growReserves(GROW_MAX_PASSES) || layout.pages.length > safePageCount) {
275288
276269
  await applyReserves(safeApplied);
@@ -275290,6 +276271,30 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
275290
276271
  }
275291
276272
  }
275292
276273
  }
276274
+ const ONE_LINE_TAIL_PX = 24;
276275
+ const runWidowOrphanAbsorb = async () => {
276276
+ const ledgers = buildFootnoteLedgers(finalPlan, reservesAppliedToLayout, layout.pages.length);
276277
+ const target = reservesAppliedToLayout.slice();
276278
+ let bumped = 0;
276279
+ for (const ledger of ledgers) {
276280
+ const tailPx = ledger.continuationOut.reduce((s2, e) => s2 + (e.remainingHeightPx || 0), 0);
276281
+ if (tailPx <= 0 || tailPx > ONE_LINE_TAIL_PX)
276282
+ continue;
276283
+ const requested = capReserveForRelayout(ledger.preferredReservePx, ledger.pageIndex, layout, reservesAppliedToLayout);
276284
+ if (requested > (target[ledger.pageIndex] ?? 0)) {
276285
+ target[ledger.pageIndex] = requested;
276286
+ bumped += 1;
276287
+ }
276288
+ }
276289
+ if (bumped === 0)
276290
+ return;
276291
+ const safeApplied = reservesAppliedToLayout.slice();
276292
+ await applyReserves(target);
276293
+ if (!await growReserves(GROW_MAX_PASSES))
276294
+ await applyReserves(safeApplied);
276295
+ };
276296
+ await runWidowOrphanAbsorb();
276297
+ await runPreferredReserveTrials();
275293
276298
  const blockById = /* @__PURE__ */ new Map;
275294
276299
  finalBlocks.forEach((block) => {
275295
276300
  blockById.set(block.id, block);
@@ -276146,7 +277151,7 @@ function selectionToRects(layout, blocks2, measures, from$1, to, geometryHelper)
276146
277151
  return;
276147
277152
  const block = blocks2[blockIndex];
276148
277153
  const pmRange = getAtomicPmRange(fragment2, block);
276149
- if (!rangesOverlap(pmRange.pmStart, pmRange.pmEnd, from$1, to))
277154
+ if (!rangesOverlap2(pmRange.pmStart, pmRange.pmEnd, from$1, to))
276150
277155
  return;
276151
277156
  rects.push({
276152
277157
  x: fragment2.x,
@@ -277705,15 +278710,95 @@ function createLayoutMetrics(perf, startMark, layout, blocks2) {
277705
278710
  pageCount: layout.pages?.length ?? 0
277706
278711
  };
277707
278712
  }
277708
- function buildFootnotesInput(editorState, converter, converterContext, themeColors, renderOverride = null) {
278713
+ function computeNoteNumbering(editorState, noteTypeName, options) {
278714
+ const numberById = {};
278715
+ const formatById = {};
278716
+ const order$1 = [];
278717
+ if (!editorState)
278718
+ return {
278719
+ numberById,
278720
+ order: order$1
278721
+ };
278722
+ const seen = /* @__PURE__ */ new Set;
278723
+ const sectionConfigs = options.sectionConfigs ?? /* @__PURE__ */ new Map;
278724
+ const refPageById = options.refPageById;
278725
+ let sectionIndex = 0;
278726
+ let lastPage = null;
278727
+ let anyOverride = false;
278728
+ const restartFor = (s2) => sectionConfigs.get(s2)?.numRestart ?? options.defaultRestart ?? "continuous";
278729
+ const numStartFor = (s2) => sectionConfigs.get(s2)?.numStart ?? options.startCounter;
278730
+ const numFmtFor = (s2) => sectionConfigs.get(s2)?.numFmt ?? options.defaultNumFmt;
278731
+ let counter = numStartFor(0);
278732
+ try {
278733
+ editorState.doc?.descendants?.((node3) => {
278734
+ const typeName = node3?.type?.name;
278735
+ if (typeName === "sectionBreak") {
278736
+ const nextSection = sectionIndex + 1;
278737
+ const nextRestart = restartFor(nextSection);
278738
+ if (nextRestart === "eachSect" || nextRestart === "eachPage") {
278739
+ counter = numStartFor(nextSection);
278740
+ lastPage = null;
278741
+ }
278742
+ sectionIndex = nextSection;
278743
+ return;
278744
+ }
278745
+ if (typeName !== noteTypeName)
278746
+ return;
278747
+ const rawId = node3?.attrs?.id;
278748
+ if (rawId == null)
278749
+ return;
278750
+ const key2 = String(rawId);
278751
+ if (!key2 || seen.has(key2))
278752
+ return;
278753
+ seen.add(key2);
278754
+ order$1.push(key2);
278755
+ if (isCustomMarkFollows2(node3?.attrs?.customMarkFollows))
278756
+ return;
278757
+ if (refPageById && restartFor(sectionIndex) === "eachPage") {
278758
+ const thisPage = refPageById.get(key2) ?? 0;
278759
+ if (lastPage !== null && thisPage !== lastPage)
278760
+ counter = numStartFor(sectionIndex);
278761
+ lastPage = thisPage;
278762
+ }
278763
+ numberById[key2] = counter;
278764
+ const fmt = numFmtFor(sectionIndex);
278765
+ if (fmt) {
278766
+ formatById[key2] = fmt;
278767
+ if (sectionConfigs.has(sectionIndex) && sectionConfigs.get(sectionIndex)?.numFmt)
278768
+ anyOverride = true;
278769
+ }
278770
+ counter += 1;
278771
+ });
278772
+ } catch (_$1) {}
278773
+ return anyOverride ? {
278774
+ numberById,
278775
+ formatById,
278776
+ order: order$1
278777
+ } : {
278778
+ numberById,
278779
+ order: order$1
278780
+ };
278781
+ }
278782
+ function isCustomMarkFollows2(value) {
278783
+ if (value === true || value === 1)
278784
+ return true;
278785
+ if (typeof value !== "string")
278786
+ return false;
278787
+ const v = value.trim().toLowerCase();
278788
+ return v === "1" || v === "true" || v === "on";
278789
+ }
278790
+ function buildFootnotesInput(editorState, converter, converterContext, themeColors, renderOverride = null, resolveTrackedChangeColor) {
277709
278791
  if (!editorState)
277710
278792
  return null;
277711
278793
  const footnoteNumberById = converterContext?.footnoteNumberById;
278794
+ const footnoteNumberFormat = converterContext?.footnoteNumberFormat;
278795
+ const footnoteFormatById = converterContext?.footnoteFormatById;
277712
278796
  const importedFootnotes = Array.isArray(converter?.footnotes) ? converter.footnotes : [];
277713
278797
  if (importedFootnotes.length === 0)
277714
278798
  return null;
277715
278799
  const refs = [];
277716
278800
  const idsInUse = /* @__PURE__ */ new Set;
278801
+ const customMarkIds = /* @__PURE__ */ new Set;
277717
278802
  editorState.doc.descendants((node3, pos) => {
277718
278803
  if (node3.type?.name !== "footnoteReference")
277719
278804
  return;
@@ -277727,6 +278812,8 @@ function buildFootnotesInput(editorState, converter, converterContext, themeColo
277727
278812
  pos: insidePos
277728
278813
  });
277729
278814
  idsInUse.add(key2);
278815
+ if (isCustomMarkFollows2(node3.attrs?.customMarkFollows))
278816
+ customMarkIds.add(key2);
277730
278817
  });
277731
278818
  if (refs.length === 0)
277732
278819
  return null;
@@ -277745,10 +278832,14 @@ function buildFootnotesInput(editorState, converter, converterContext, themeColo
277745
278832
  }),
277746
278833
  enableRichHyperlinks: true,
277747
278834
  themeColors,
277748
- converterContext
278835
+ converterContext,
278836
+ resolveTrackedChangeColor
277749
278837
  });
277750
278838
  if (result?.blocks?.length) {
277751
- ensureFootnoteMarker(result.blocks, id2, footnoteNumberById);
278839
+ if (!customMarkIds.has(id2)) {
278840
+ const numFmtForId = footnoteFormatById?.[id2] ?? footnoteNumberFormat;
278841
+ ensureFootnoteMarker(result.blocks, id2, footnoteNumberById, numFmtForId);
278842
+ }
277752
278843
  blocksById.set(id2, result.blocks);
277753
278844
  }
277754
278845
  } catch (_$1) {}
@@ -277774,9 +278865,6 @@ function resolveDisplayNumber$1(id2, footnoteNumberById) {
277774
278865
  return num;
277775
278866
  return 1;
277776
278867
  }
277777
- function resolveMarkerText(value) {
277778
- return String(value ?? "");
277779
- }
277780
278868
  function resolveMarkerFontFamily$1(firstTextRun) {
277781
278869
  return typeof firstTextRun?.fontFamily === "string" ? firstTextRun.fontFamily : DEFAULT_MARKER_FONT_FAMILY$1;
277782
278870
  }
@@ -277788,18 +278876,12 @@ function resolveMarkerBaseFontSize$1(firstTextRun) {
277788
278876
  function buildMarkerRun$1(markerText, firstTextRun) {
277789
278877
  const markerRun = {
277790
278878
  kind: "text",
277791
- text: markerText,
278879
+ text: `${markerText} `,
277792
278880
  dataAttrs: { [FOOTNOTE_MARKER_DATA_ATTR]: "true" },
277793
278881
  fontFamily: resolveMarkerFontFamily$1(firstTextRun),
277794
278882
  fontSize: resolveMarkerBaseFontSize$1(firstTextRun) * SUBSCRIPT_SUPERSCRIPT_SCALE,
277795
278883
  vertAlign: "superscript"
277796
278884
  };
277797
- if (typeof firstTextRun?.bold === "boolean")
277798
- markerRun.bold = firstTextRun.bold;
277799
- if (typeof firstTextRun?.italic === "boolean")
277800
- markerRun.italic = firstTextRun.italic;
277801
- if (typeof firstTextRun?.letterSpacing === "number" && Number.isFinite(firstTextRun.letterSpacing))
277802
- markerRun.letterSpacing = firstTextRun.letterSpacing;
277803
278885
  if (firstTextRun?.color != null)
277804
278886
  markerRun.color = firstTextRun.color;
277805
278887
  return markerRun;
@@ -277836,12 +278918,12 @@ function syncMarkerRun$1(target, source) {
277836
278918
  delete target.pmStart;
277837
278919
  delete target.pmEnd;
277838
278920
  }
277839
- function ensureFootnoteMarker(blocks2, id2, footnoteNumberById) {
278921
+ function ensureFootnoteMarker(blocks2, id2, footnoteNumberById, footnoteNumberFormat) {
277840
278922
  const firstParagraph = blocks2.find((b$1) => b$1?.kind === "paragraph");
277841
278923
  if (!firstParagraph)
277842
278924
  return;
277843
278925
  const runs2 = Array.isArray(firstParagraph.runs) ? firstParagraph.runs : [];
277844
- const normalizedMarkerRun = buildMarkerRun$1(resolveMarkerText(resolveDisplayNumber$1(id2, footnoteNumberById)), runs2.find((run2) => typeof run2.text === "string" && !isFootnoteMarker(run2)));
278926
+ const normalizedMarkerRun = buildMarkerRun$1(formatFootnoteCardinal(resolveDisplayNumber$1(id2, footnoteNumberById), footnoteNumberFormat), runs2.find((run2) => typeof run2.text === "string" && !isFootnoteMarker(run2)));
277845
278927
  const existingMarker = runs2.find(isFootnoteMarker);
277846
278928
  if (existingMarker) {
277847
278929
  syncMarkerRun$1(existingMarker, normalizedMarkerRun);
@@ -283790,15 +284872,18 @@ function getHostEditor(editor) {
283790
284872
  function resolveSessionHostEditor(editor, runtime) {
283791
284873
  return getHostEditor(editor) ?? getHostEditor(runtime.editor) ?? runtime.editor;
283792
284874
  }
283793
- function buildEndnoteBlocks(editorState, converter, converterContext, themeColors, renderOverride = null) {
284875
+ function buildEndnoteBlocks(editorState, converter, converterContext, themeColors, renderOverride = null, resolveTrackedChangeColor) {
283794
284876
  if (!editorState)
283795
284877
  return [];
283796
284878
  const endnoteNumberById = converterContext?.endnoteNumberById;
284879
+ const endnoteNumberFormat = converterContext?.endnoteNumberFormat;
284880
+ const endnoteFormatById = converterContext?.endnoteFormatById;
283797
284881
  const importedEndnotes = Array.isArray(converter?.endnotes) ? converter.endnotes : [];
283798
284882
  if (importedEndnotes.length === 0)
283799
284883
  return [];
283800
284884
  const orderedEndnoteIds = [];
283801
284885
  const seen = /* @__PURE__ */ new Set;
284886
+ const customMarkIds = /* @__PURE__ */ new Set;
283802
284887
  editorState.doc.descendants((node3) => {
283803
284888
  if (node3.type?.name !== "endnoteReference")
283804
284889
  return;
@@ -283810,6 +284895,8 @@ function buildEndnoteBlocks(editorState, converter, converterContext, themeColor
283810
284895
  return;
283811
284896
  seen.add(key2);
283812
284897
  orderedEndnoteIds.push(key2);
284898
+ if (isCustomMarkFollows2(node3.attrs?.customMarkFollows))
284899
+ customMarkIds.add(key2);
283813
284900
  });
283814
284901
  if (orderedEndnoteIds.length === 0)
283815
284902
  return [];
@@ -283828,10 +284915,14 @@ function buildEndnoteBlocks(editorState, converter, converterContext, themeColor
283828
284915
  }),
283829
284916
  enableRichHyperlinks: true,
283830
284917
  themeColors,
283831
- converterContext
284918
+ converterContext,
284919
+ resolveTrackedChangeColor
283832
284920
  });
283833
284921
  if (result?.blocks?.length) {
283834
- ensureEndnoteMarker(result.blocks, id2, endnoteNumberById);
284922
+ if (!customMarkIds.has(id2)) {
284923
+ const numFmtForId = endnoteFormatById?.[id2] ?? endnoteNumberFormat;
284924
+ ensureEndnoteMarker(result.blocks, id2, endnoteNumberById, numFmtForId);
284925
+ }
283835
284926
  blocks2.push(...result.blocks);
283836
284927
  }
283837
284928
  } catch {}
@@ -283863,18 +284954,12 @@ function resolveMarkerBaseFontSize(firstTextRun) {
283863
284954
  function buildMarkerRun(markerText, firstTextRun) {
283864
284955
  const markerRun = {
283865
284956
  kind: "text",
283866
- text: markerText,
284957
+ text: `${markerText} `,
283867
284958
  dataAttrs: { [ENDNOTE_MARKER_DATA_ATTR]: "true" },
283868
284959
  fontFamily: resolveMarkerFontFamily(firstTextRun),
283869
284960
  fontSize: resolveMarkerBaseFontSize(firstTextRun) * SUBSCRIPT_SUPERSCRIPT_SCALE,
283870
284961
  vertAlign: "superscript"
283871
284962
  };
283872
- if (typeof firstTextRun?.bold === "boolean")
283873
- markerRun.bold = firstTextRun.bold;
283874
- if (typeof firstTextRun?.italic === "boolean")
283875
- markerRun.italic = firstTextRun.italic;
283876
- if (typeof firstTextRun?.letterSpacing === "number" && Number.isFinite(firstTextRun.letterSpacing))
283877
- markerRun.letterSpacing = firstTextRun.letterSpacing;
283878
284963
  if (firstTextRun?.color != null)
283879
284964
  markerRun.color = firstTextRun.color;
283880
284965
  return markerRun;
@@ -283911,14 +284996,14 @@ function resolveEndnoteDocJson(id2, importedEndnotes, renderOverride) {
283911
284996
  content: cloneNoteContentJson(content3)
283912
284997
  });
283913
284998
  }
283914
- function ensureEndnoteMarker(blocks2, id2, endnoteNumberById) {
284999
+ function ensureEndnoteMarker(blocks2, id2, endnoteNumberById, endnoteNumberFormat) {
283915
285000
  const firstParagraph = blocks2.find((block) => block.kind === "paragraph");
283916
285001
  if (!firstParagraph)
283917
285002
  return;
283918
285003
  const runs2 = Array.isArray(firstParagraph.runs) ? firstParagraph.runs : [];
283919
285004
  firstParagraph.runs = runs2;
283920
285005
  const firstTextRun = runs2.find((run2) => isTextRun$12(run2) && !isEndnoteMarker(run2) && run2.text.length > 0);
283921
- const markerRun = buildMarkerRun(String(resolveDisplayNumber(id2, endnoteNumberById)), firstTextRun);
285006
+ const markerRun = buildMarkerRun(formatFootnoteCardinal(resolveDisplayNumber(id2, endnoteNumberById), endnoteNumberFormat), firstTextRun);
283922
285007
  if (runs2[0] && isTextRun$12(runs2[0]) && isEndnoteMarker(runs2[0])) {
283923
285008
  syncMarkerRun(runs2[0], markerRun);
283924
285009
  return;
@@ -284138,6 +285223,22 @@ function ensureEditorMovableObjectInteractionStyles(doc$12) {
284138
285223
  doc$12.head?.appendChild(styleEl);
284139
285224
  movableObjectInteractionStylesInjected = true;
284140
285225
  }
285226
+ function serializeSectionConfigs(map$12) {
285227
+ if (map$12.size === 0)
285228
+ return "";
285229
+ return [...map$12.entries()].sort((a2, b$1) => a2[0] - b$1[0]).map(([i4, c]) => `${i4}:${c.numFmt ?? ""}/${c.numStart ?? ""}/${c.numRestart ?? ""}`).join(";");
285230
+ }
285231
+ function serializePerIdNumbering(order$1, numberById, formatById) {
285232
+ if (order$1.length === 0)
285233
+ return "";
285234
+ const parts = [];
285235
+ for (const id2 of order$1) {
285236
+ const n = numberById[id2];
285237
+ const f2 = formatById?.[id2] ?? "";
285238
+ parts.push(`${id2}:${n ?? ""}/${f2}`);
285239
+ }
285240
+ return parts.join(";");
285241
+ }
284141
285242
  function parseRenderedNoteTarget(blockId) {
284142
285243
  if (typeof blockId !== "string" || blockId.length === 0)
284143
285244
  return null;
@@ -305151,6 +306252,10 @@ menclose::after {
305151
306252
  markerEl.style.color = run2.color;
305152
306253
  if (run2.letterSpacing != null)
305153
306254
  markerEl.style.letterSpacing = `${run2.letterSpacing}px`;
306255
+ if (run2.allCaps)
306256
+ markerEl.style.textTransform = "uppercase";
306257
+ else if (run2.smallCaps)
306258
+ markerEl.style.fontVariant = "small-caps";
305154
306259
  markerContainer.appendChild(markerEl);
305155
306260
  if (sourceAnchor)
305156
306261
  applySourceAnchorDataset(markerEl, sourceAnchor);
@@ -308409,7 +309514,47 @@ menclose::after {
308409
309514
  });
308410
309515
  return createErrorPlaceholder(fragment2.blockId, error3);
308411
309516
  }
308412
- }, TRACK_CHANGE_BASE_CLASS, TRACK_CHANGE_OVERLAP_INSERT_DELETE_CLASS = "track-overlap-insert-delete-dec", TRACK_CHANGE_MODIFIER_CLASS, getTrackedChangeLayers$1 = (run2) => {
309517
+ }, TRACK_CHANGE_BASE_CLASS, TRACK_CHANGE_OVERLAP_INSERT_DELETE_CLASS = "track-overlap-insert-delete-dec", TRACK_CHANGE_BACKGROUND_ALPHA = 34, TRACK_CHANGE_BACKGROUND_FOCUSED_ALPHA = 68, expandHexColor = (hex) => {
309518
+ const normalized = hex.replace("#", "");
309519
+ if (normalized.length === 3)
309520
+ return normalized.split("").map((char) => char + char).join("");
309521
+ if (normalized.length === 6 || normalized.length === 8)
309522
+ return normalized.slice(0, 6);
309523
+ return null;
309524
+ }, colorWithAlpha = (color2, alpha) => {
309525
+ const expanded = color2.trim().startsWith("#") ? expandHexColor(color2.trim()) : null;
309526
+ if (!expanded)
309527
+ return color2;
309528
+ return `#${expanded}${Math.max(0, Math.min(255, alpha)).toString(16).padStart(2, "0")}`;
309529
+ }, setColorVar = (elem, name, value) => {
309530
+ elem.style.setProperty(name, value);
309531
+ }, applyAuthorColorVariables = (elem, layer) => {
309532
+ const color2 = layer.color;
309533
+ if (!color2)
309534
+ return;
309535
+ const background = colorWithAlpha(color2, TRACK_CHANGE_BACKGROUND_ALPHA);
309536
+ const backgroundFocused = colorWithAlpha(color2, TRACK_CHANGE_BACKGROUND_FOCUSED_ALPHA);
309537
+ switch (layer.kind) {
309538
+ case "insert":
309539
+ setColorVar(elem, "--sd-tracked-changes-insert-border", color2);
309540
+ setColorVar(elem, "--sd-tracked-changes-insert-background", background);
309541
+ setColorVar(elem, "--sd-tracked-changes-insert-background-focused", backgroundFocused);
309542
+ break;
309543
+ case "delete":
309544
+ setColorVar(elem, "--sd-tracked-changes-delete-border", color2);
309545
+ setColorVar(elem, "--sd-tracked-changes-delete-background", background);
309546
+ setColorVar(elem, "--sd-tracked-changes-delete-background-focused", backgroundFocused);
309547
+ setColorVar(elem, "--sd-tracked-changes-delete-text", color2);
309548
+ break;
309549
+ case "format":
309550
+ setColorVar(elem, "--sd-tracked-changes-format-border", color2);
309551
+ setColorVar(elem, "--sd-tracked-changes-format-background", background);
309552
+ setColorVar(elem, "--sd-tracked-changes-format-background-focused", backgroundFocused);
309553
+ break;
309554
+ default:
309555
+ break;
309556
+ }
309557
+ }, TRACK_CHANGE_MODIFIER_CLASS, getTrackedChangeLayers$1 = (run2) => {
308413
309558
  if (Array.isArray(run2.trackedChanges) && run2.trackedChanges.length > 0)
308414
309559
  return run2.trackedChanges;
308415
309560
  return run2.trackedChange ? [run2.trackedChange] : [];
@@ -308446,6 +309591,7 @@ menclose::after {
308446
309591
  const modifier = TRACK_CHANGE_MODIFIER_CLASS[layer.kind]?.[config2.mode];
308447
309592
  if (modifier)
308448
309593
  elem.classList.add(modifier);
309594
+ applyAuthorColorVariables(elem, layer);
308449
309595
  });
308450
309596
  if (overlap) {
308451
309597
  elem.classList.add(TRACK_CHANGE_OVERLAP_INSERT_DELETE_CLASS);
@@ -313071,6 +314217,208 @@ menclose::after {
313071
314217
  this.constraintsHash = "";
313072
314218
  this.sectionMetadataHash = "";
313073
314219
  }
314220
+ }, DEFAULT_WINDOW_AHEAD = 3, DEFAULT_PREFERRED_DELTA_THRESHOLD_PX = 8, DEFAULT_MANDATORY_ONLY_TOLERANCE_PX = 2, DEFAULT_DEAD_RESERVE_BLOAT_THRESHOLD_PX = 128, DEFAULT_WHOLE_DOCUMENT_DEAD_RESERVE_BLOAT_THRESHOLD_PX = 128, FULL_ANCHOR_RENDER_SENTINEL, DEFAULT_TRIAL_TARGET_COUNT = 12, isMandatoryOnlyFootnotePage = (ledger, preferredDeltaThresholdPx = DEFAULT_PREFERRED_DELTA_THRESHOLD_PX, mandatoryOnlyTolerancePx = DEFAULT_MANDATORY_ONLY_TOLERANCE_PX) => {
314221
+ if (ledger.anchorIds.length === 0)
314222
+ return false;
314223
+ return Math.abs(ledger.actualBandHeightPx - ledger.mandatoryReservePx) <= mandatoryOnlyTolerancePx && ledger.preferredReservePx - ledger.mandatoryReservePx > preferredDeltaThresholdPx && ledger.lastAnchorRenderedLines <= 1;
314224
+ }, isSplitLastAnchorFootnotePage = (ledger, preferredDeltaThresholdPx = DEFAULT_PREFERRED_DELTA_THRESHOLD_PX) => {
314225
+ if (ledger.anchorIds.length === 0)
314226
+ return false;
314227
+ const lastAnchorId = ledger.anchorIds[ledger.anchorIds.length - 1];
314228
+ if (!ledger.continuationOut.some((entry) => entry.id === lastAnchorId))
314229
+ return false;
314230
+ return ledger.preferredReservePx - ledger.mandatoryReservePx > preferredDeltaThresholdPx && ledger.actualBandHeightPx < ledger.preferredReservePx - preferredDeltaThresholdPx;
314231
+ }, getPreferredReserveCandidates = (ledgers, preferredDeltaThresholdPx = DEFAULT_PREFERRED_DELTA_THRESHOLD_PX, mandatoryOnlyTolerancePx = DEFAULT_MANDATORY_ONLY_TOLERANCE_PX) => {
314232
+ return ledgers.filter((ledger) => isMandatoryOnlyFootnotePage(ledger, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx) || isSplitLastAnchorFootnotePage(ledger, preferredDeltaThresholdPx)).map((ledger) => ({
314233
+ pageIndex: ledger.pageIndex,
314234
+ anchorIds: ledger.anchorIds.slice(),
314235
+ mandatoryReservePx: ledger.mandatoryReservePx,
314236
+ preferredReservePx: ledger.preferredReservePx,
314237
+ reserveDeltaPx: ledger.preferredReservePx - ledger.mandatoryReservePx,
314238
+ actualBandHeightPx: ledger.actualBandHeightPx,
314239
+ lastAnchorRenderedLines: ledger.lastAnchorRenderedLines
314240
+ }));
314241
+ }, getPreferredReserveTrialTargets = (candidate, currentReservePx, preferredDeltaThresholdPx = DEFAULT_PREFERRED_DELTA_THRESHOLD_PX, maxTargets = DEFAULT_TRIAL_TARGET_COUNT) => {
314242
+ const current = Number.isFinite(currentReservePx) ? Math.max(0, currentReservePx) : 0;
314243
+ const floor$1 = Math.max(current, candidate.mandatoryReservePx);
314244
+ const ceiling = Math.max(floor$1, candidate.preferredReservePx);
314245
+ const delta = ceiling - floor$1;
314246
+ if (delta <= preferredDeltaThresholdPx)
314247
+ return [];
314248
+ const targets = /* @__PURE__ */ new Set;
314249
+ const addTarget = (value) => {
314250
+ if (!Number.isFinite(value))
314251
+ return;
314252
+ const rounded = Math.ceil(Math.max(floor$1, Math.min(ceiling, value)));
314253
+ if (rounded - floor$1 > preferredDeltaThresholdPx)
314254
+ targets.add(rounded);
314255
+ };
314256
+ [
314257
+ 1,
314258
+ 0.75,
314259
+ 0.5,
314260
+ 0.33,
314261
+ 0.25,
314262
+ 0.15
314263
+ ].forEach((fraction) => addTarget(floor$1 + delta * fraction));
314264
+ [
314265
+ 96,
314266
+ 72,
314267
+ 48,
314268
+ 24,
314269
+ 12
314270
+ ].forEach((px) => addTarget(floor$1 + Math.min(delta, px)));
314271
+ return Array.from(targets).sort((a2, b$1) => b$1 - a2).slice(0, Math.max(1, maxTargets));
314272
+ }, getWindowBounds = (layout, candidatePageIndex, windowAhead) => ({
314273
+ windowStart: Math.max(0, candidatePageIndex),
314274
+ windowEnd: Math.min(layout.pages.length - 1, candidatePageIndex + Math.max(0, windowAhead))
314275
+ }), getDocumentBounds = (layout) => ({
314276
+ windowStart: 0,
314277
+ windowEnd: Math.max(0, layout.pages.length - 1)
314278
+ }), isInWindow = (ledger, windowStart, windowEnd) => ledger.pageIndex >= windowStart && ledger.pageIndex <= windowEnd, getLastAnchorId = (ledger) => {
314279
+ if (!ledger || ledger.anchorIds.length === 0)
314280
+ return;
314281
+ return ledger.anchorIds[ledger.anchorIds.length - 1];
314282
+ }, collectLedgerDiagnostics = (ledgers, windowStart, windowEnd, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx) => {
314283
+ const diagnostics = {
314284
+ mandatoryOnlyCount: 0,
314285
+ mandatoryOnlyAnchorIds: /* @__PURE__ */ new Set,
314286
+ deadReserveSum: 0,
314287
+ clusterSplitCount: 0,
314288
+ clusterSplitAnchorIds: /* @__PURE__ */ new Set
314289
+ };
314290
+ for (const ledger of ledgers) {
314291
+ if (!isInWindow(ledger, windowStart, windowEnd))
314292
+ continue;
314293
+ diagnostics.deadReserveSum += Math.max(0, ledger.deadReservePx);
314294
+ if (isMandatoryOnlyFootnotePage(ledger, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx)) {
314295
+ diagnostics.mandatoryOnlyCount += 1;
314296
+ const id2 = getLastAnchorId(ledger);
314297
+ if (id2)
314298
+ diagnostics.mandatoryOnlyAnchorIds.add(id2);
314299
+ }
314300
+ const anchorIds = new Set(ledger.anchorIds);
314301
+ let splitsCurrentAnchorCluster = false;
314302
+ for (const entry of ledger.continuationOut) {
314303
+ if (!anchorIds.has(entry.id))
314304
+ continue;
314305
+ diagnostics.clusterSplitAnchorIds.add(entry.id);
314306
+ splitsCurrentAnchorCluster = true;
314307
+ }
314308
+ if (splitsCurrentAnchorCluster)
314309
+ diagnostics.clusterSplitCount += 1;
314310
+ }
314311
+ return diagnostics;
314312
+ }, hasNewId = (after2, before2) => {
314313
+ for (const id2 of after2)
314314
+ if (!before2.has(id2))
314315
+ return true;
314316
+ return false;
314317
+ }, getCandidateRenderedLines = (ledgers, candidateAnchorId) => {
314318
+ if (!candidateAnchorId)
314319
+ return;
314320
+ const anchorLedger = ledgers.find((ledger) => ledger.anchorIds.includes(candidateAnchorId));
314321
+ if (!anchorLedger)
314322
+ return;
314323
+ if (getLastAnchorId(anchorLedger) === candidateAnchorId)
314324
+ return anchorLedger.lastAnchorRenderedLines;
314325
+ return FULL_ANCHOR_RENDER_SENTINEL;
314326
+ }, candidateRenderedLinesImproved = (before2, after2) => typeof before2.candidateRenderedLines === "number" && typeof after2.candidateRenderedLines === "number" && after2.candidateRenderedLines > before2.candidateRenderedLines, summarizeFootnoteWindow = (layout, ledgers, candidatePageIndex, windowAhead = DEFAULT_WINDOW_AHEAD, preferredDeltaThresholdPx = DEFAULT_PREFERRED_DELTA_THRESHOLD_PX, mandatoryOnlyTolerancePx = DEFAULT_MANDATORY_ONLY_TOLERANCE_PX, candidateAnchorId) => {
314327
+ const { windowStart, windowEnd } = getWindowBounds(layout, candidatePageIndex, windowAhead);
314328
+ const diagnostics = collectLedgerDiagnostics(ledgers, windowStart, windowEnd, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx);
314329
+ return {
314330
+ totalPages: layout.pages.length,
314331
+ mandatoryOnlyCount: diagnostics.mandatoryOnlyCount,
314332
+ deadReserveSum: diagnostics.deadReserveSum,
314333
+ clusterSplitCount: diagnostics.clusterSplitCount,
314334
+ candidateRenderedLines: getCandidateRenderedLines(ledgers, candidateAnchorId)
314335
+ };
314336
+ }, scoreFootnoteWindow = (input2) => {
314337
+ const windowAhead = input2.windowAhead ?? DEFAULT_WINDOW_AHEAD;
314338
+ const preferredDeltaThresholdPx = input2.preferredDeltaThresholdPx ?? DEFAULT_PREFERRED_DELTA_THRESHOLD_PX;
314339
+ const mandatoryOnlyTolerancePx = input2.mandatoryOnlyTolerancePx ?? DEFAULT_MANDATORY_ONLY_TOLERANCE_PX;
314340
+ const deadReserveBloatThresholdPx = input2.deadReserveBloatThresholdPx ?? DEFAULT_DEAD_RESERVE_BLOAT_THRESHOLD_PX;
314341
+ const wholeDocumentDeadReserveBloatThresholdPx = input2.wholeDocumentDeadReserveBloatThresholdPx ?? DEFAULT_WHOLE_DOCUMENT_DEAD_RESERVE_BLOAT_THRESHOLD_PX;
314342
+ const beforeCandidateLedger = input2.beforeLedger.find((ledger) => ledger.pageIndex === input2.candidatePageIndex);
314343
+ const candidateAnchorId = input2.candidateAnchorId ?? getLastAnchorId(beforeCandidateLedger);
314344
+ const before2 = summarizeFootnoteWindow(input2.beforeLayout, input2.beforeLedger, input2.candidatePageIndex, windowAhead, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx, candidateAnchorId);
314345
+ const after2 = summarizeFootnoteWindow(input2.afterLayout, input2.afterLedger, input2.candidatePageIndex, windowAhead, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx, candidateAnchorId);
314346
+ const beforeBounds = getWindowBounds(input2.beforeLayout, input2.candidatePageIndex, windowAhead);
314347
+ const afterBounds = getWindowBounds(input2.afterLayout, input2.candidatePageIndex, windowAhead);
314348
+ const beforeWindowDiagnostics = collectLedgerDiagnostics(input2.beforeLedger, beforeBounds.windowStart, beforeBounds.windowEnd, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx);
314349
+ const afterWindowDiagnostics = collectLedgerDiagnostics(input2.afterLedger, afterBounds.windowStart, afterBounds.windowEnd, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx);
314350
+ const beforeDocumentBounds = getDocumentBounds(input2.beforeLayout);
314351
+ const afterDocumentBounds = getDocumentBounds(input2.afterLayout);
314352
+ const beforeDocumentDiagnostics = collectLedgerDiagnostics(input2.beforeLedger, beforeDocumentBounds.windowStart, beforeDocumentBounds.windowEnd, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx);
314353
+ const afterDocumentDiagnostics = collectLedgerDiagnostics(input2.afterLedger, afterDocumentBounds.windowStart, afterDocumentBounds.windowEnd, preferredDeltaThresholdPx, mandatoryOnlyTolerancePx);
314354
+ const eliminatesSplitInWindow = beforeWindowDiagnostics.clusterSplitCount > afterWindowDiagnostics.clusterSplitCount;
314355
+ const eliminatesSplitInDoc = beforeDocumentDiagnostics.clusterSplitCount > afterDocumentDiagnostics.clusterSplitCount;
314356
+ if (after2.totalPages > before2.totalPages) {
314357
+ if (!(after2.totalPages === before2.totalPages + 1 && eliminatesSplitInDoc))
314358
+ return {
314359
+ accept: false,
314360
+ reason: "page-count-grew",
314361
+ before: before2,
314362
+ after: after2
314363
+ };
314364
+ }
314365
+ if (after2.clusterSplitCount > before2.clusterSplitCount || hasNewId(afterWindowDiagnostics.clusterSplitAnchorIds, beforeWindowDiagnostics.clusterSplitAnchorIds))
314366
+ return {
314367
+ accept: false,
314368
+ reason: "cluster-spill",
314369
+ before: before2,
314370
+ after: after2
314371
+ };
314372
+ if (afterDocumentDiagnostics.clusterSplitAnchorIds.size > beforeDocumentDiagnostics.clusterSplitAnchorIds.size || hasNewId(afterDocumentDiagnostics.clusterSplitAnchorIds, beforeDocumentDiagnostics.clusterSplitAnchorIds))
314373
+ return {
314374
+ accept: false,
314375
+ reason: "cluster-spill",
314376
+ before: before2,
314377
+ after: after2
314378
+ };
314379
+ if (hasNewId(afterWindowDiagnostics.mandatoryOnlyAnchorIds, beforeWindowDiagnostics.mandatoryOnlyAnchorIds))
314380
+ return {
314381
+ accept: false,
314382
+ reason: "new-mandatory-only",
314383
+ before: before2,
314384
+ after: after2
314385
+ };
314386
+ if (hasNewId(afterDocumentDiagnostics.mandatoryOnlyAnchorIds, beforeDocumentDiagnostics.mandatoryOnlyAnchorIds))
314387
+ return {
314388
+ accept: false,
314389
+ reason: "new-mandatory-only",
314390
+ before: before2,
314391
+ after: after2
314392
+ };
314393
+ const windowDeadAllowance = eliminatesSplitInWindow ? deadReserveBloatThresholdPx * 2 : deadReserveBloatThresholdPx;
314394
+ const docDeadAllowance = eliminatesSplitInDoc ? wholeDocumentDeadReserveBloatThresholdPx * 2 : wholeDocumentDeadReserveBloatThresholdPx;
314395
+ if (after2.deadReserveSum > before2.deadReserveSum + windowDeadAllowance)
314396
+ return {
314397
+ accept: false,
314398
+ reason: "dead-reserve-bloat",
314399
+ before: before2,
314400
+ after: after2
314401
+ };
314402
+ if (afterDocumentDiagnostics.deadReserveSum > beforeDocumentDiagnostics.deadReserveSum + docDeadAllowance)
314403
+ return {
314404
+ accept: false,
314405
+ reason: "dead-reserve-bloat",
314406
+ before: before2,
314407
+ after: after2
314408
+ };
314409
+ if (!candidateRenderedLinesImproved(before2, after2))
314410
+ return {
314411
+ accept: false,
314412
+ reason: "candidate-not-improved",
314413
+ before: before2,
314414
+ after: after2
314415
+ };
314416
+ return {
314417
+ accept: true,
314418
+ reason: "globally-safe",
314419
+ before: before2,
314420
+ after: after2
314421
+ };
313074
314422
  }, measureCache, headerMeasureCache, headerFooterCacheState, layoutDebugEnabled$1, perfLog$1 = (...args$1) => {
313075
314423
  if (!layoutDebugEnabled$1)
313076
314424
  return;
@@ -313266,6 +314614,9 @@ menclose::after {
313266
314614
  const bottomWithReserve = normalizeMargin(page.margins?.bottom, DEFAULT_MARGINS$1.bottom);
313267
314615
  const baseReserveSafe = Number.isFinite(baseReserve) ? Math.max(0, baseReserve) : 0;
313268
314616
  const bottomMargin = Math.max(0, bottomWithReserve - baseReserveSafe);
314617
+ const bodyMaxY = page.bodyMaxY;
314618
+ if (typeof bodyMaxY === "number" && Number.isFinite(bodyMaxY) && bodyMaxY > topMargin)
314619
+ return Math.max(0, pageSize.h - bottomMargin - bodyMaxY);
313269
314620
  const availableForBody = pageSize.h - topMargin - bottomMargin;
313270
314621
  if (!Number.isFinite(availableForBody))
313271
314622
  return 0;
@@ -313430,14 +314781,17 @@ menclose::after {
313430
314781
  toLine: splitLine,
313431
314782
  height: sumLineHeights$1(measure.lines, range.fromLine, splitLine)
313432
314783
  };
313433
- if (splitLine >= range.toLine)
313434
- return getRangeRenderHeight(fitted) <= availableHeight ? {
313435
- fitted,
313436
- remaining: null
313437
- } : {
314784
+ if (splitLine >= range.toLine) {
314785
+ if (fitted.height <= availableHeight)
314786
+ return {
314787
+ fitted,
314788
+ remaining: null
314789
+ };
314790
+ return {
313438
314791
  fitted: null,
313439
314792
  remaining: range
313440
314793
  };
314794
+ }
313441
314795
  return {
313442
314796
  fitted,
313443
314797
  remaining: {
@@ -313493,9 +314847,14 @@ menclose::after {
313493
314847
  }
313494
314848
  if (range.kind === "paragraph") {
313495
314849
  const split3 = splitRangeAtHeight(range, remainingSpace, measuresById);
313496
- if (split3.fitted && getRangeRenderHeight(split3.fitted) <= remainingSpace) {
313497
- fittedRanges.push(split3.fitted);
313498
- usedHeight += getRangeRenderHeight(split3.fitted);
314850
+ if (split3.fitted) {
314851
+ const fittedBodyHeight = split3.fitted.height;
314852
+ const fittedFullHeight = getRangeRenderHeight(split3.fitted);
314853
+ const charged = !split3.remaining ? fittedBodyHeight : fittedFullHeight;
314854
+ if (charged <= remainingSpace) {
314855
+ fittedRanges.push(split3.fitted);
314856
+ usedHeight += charged;
314857
+ }
313499
314858
  }
313500
314859
  if (split3.remaining)
313501
314860
  remainingRanges = [split3.remaining, ...inputRanges.slice(index2 + 1)];
@@ -314004,7 +315363,7 @@ menclose::after {
314004
315363
  };
314005
315364
  }
314006
315365
  return null;
314007
- }, logSelectionMapDebug = (payload) => {}, rangesOverlap = (startA, endA, startB, endB) => {
315366
+ }, logSelectionMapDebug = (payload) => {}, rangesOverlap2 = (startA, endA, startB, endB) => {
314008
315367
  if (startA == null)
314009
315368
  return false;
314010
315369
  return (endA ?? startA + 1) > startB && startA < endB;
@@ -319432,13 +320791,13 @@ menclose::after {
319432
320791
  return;
319433
320792
  console.log(...args$1);
319434
320793
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions, TRACKED_MARK_NAMES;
319435
- var init_src_DckQskSY_es = __esm(() => {
320794
+ var init_src_iuHADPff_es = __esm(() => {
319436
320795
  init_rolldown_runtime_Bg48TavK_es();
319437
- init_SuperConverter_kNDiQmof_es();
320796
+ init_SuperConverter_LqX_f8x4_es();
319438
320797
  init_jszip_C49i9kUs_es();
319439
320798
  init_xml_js_CqGKpaft_es();
319440
320799
  init_uuid_qzgm05fK_es();
319441
- init_create_headless_toolbar_fRnbrGLy_es();
320800
+ init_create_headless_toolbar_BOETXxAI_es();
319442
320801
  init_constants_D_X7xF4s_es();
319443
320802
  init_dist_B8HfvhaK_es();
319444
320803
  init_unified_Dsuw2be5_es();
@@ -346439,6 +347798,7 @@ function print() { __p += __j.call(arguments, '') }
346439
347798
  "odd"
346440
347799
  ];
346441
347800
  TWIPS_PER_PX$2 = 1440 / 96;
347801
+ FULL_ANCHOR_RENDER_SENTINEL = Number.MAX_SAFE_INTEGER;
346442
347802
  init_dist4();
346443
347803
  measureCache = new MeasureCache;
346444
347804
  headerMeasureCache = new HeaderFooterLayoutCache;
@@ -347290,6 +348650,10 @@ function print() { __p += __j.call(arguments, '') }
347290
348650
  #flowBlockCache = new FlowBlockCache;
347291
348651
  #footnoteNumberSignature = null;
347292
348652
  #endnoteNumberSignature = null;
348653
+ #warnedUnsupportedRestart = {
348654
+ footnote: false,
348655
+ endnote: false
348656
+ };
347293
348657
  #painterAdapter = new PresentationPainterAdapter;
347294
348658
  #pageGeometryHelper = null;
347295
348659
  #dragDropManager = null;
@@ -347400,6 +348764,7 @@ function print() { __p += __j.call(arguments, '') }
347400
348764
  flowMode: requestedFlowMode,
347401
348765
  semanticOptions: options.layoutEngineOptions?.semanticOptions,
347402
348766
  trackedChanges: options.layoutEngineOptions?.trackedChanges,
348767
+ resolveTrackedChangeColor: options.layoutEngineOptions?.resolveTrackedChangeColor,
347403
348768
  emitCommentPositionsInViewing: options.layoutEngineOptions?.emitCommentPositionsInViewing,
347404
348769
  enableCommentsInViewing: options.layoutEngineOptions?.enableCommentsInViewing,
347405
348770
  presence: validatedPresence,
@@ -347606,6 +348971,12 @@ function print() { __p += __j.call(arguments, '') }
347606
348971
  throw error3;
347607
348972
  }
347608
348973
  }
348974
+ #warnUnsupportedNumberingRestart(kind) {
348975
+ if (this.#warnedUnsupportedRestart[kind])
348976
+ return;
348977
+ this.#warnedUnsupportedRestart[kind] = true;
348978
+ console.warn(`[PresentationEditor] ${kind} numRestart="eachPage" is not yet supported (requires a two-pass pagination handshake). Falling back to "continuous". Tracked for follow-up.`);
348979
+ }
347609
348980
  #wrapOffscreenEditorFocus(editor) {
347610
348981
  const view = editor?.view;
347611
348982
  if (!view || !view.dom || typeof view.focus !== "function")
@@ -350682,58 +352053,84 @@ function print() { __p += __j.call(arguments, '') }
350682
352053
  let converterContext = undefined;
350683
352054
  try {
350684
352055
  const converter$1 = this.#editor.converter;
350685
- const footnoteNumberById = {};
350686
- const footnoteOrder = [];
350687
- try {
350688
- const seen = /* @__PURE__ */ new Set;
350689
- let counter = 1;
350690
- this.#editor?.state?.doc?.descendants?.((node3) => {
350691
- if (node3?.type?.name !== "footnoteReference")
350692
- return;
350693
- const rawId = node3?.attrs?.id;
350694
- if (rawId == null)
350695
- return;
350696
- const key2 = String(rawId);
350697
- if (!key2 || seen.has(key2))
350698
- return;
350699
- seen.add(key2);
350700
- footnoteNumberById[key2] = counter;
350701
- footnoteOrder.push(key2);
350702
- counter += 1;
350703
- });
350704
- } catch (e) {
350705
- if (typeof console !== "undefined" && console.warn)
350706
- console.warn("[PresentationEditor] Failed to compute footnote numbering:", e);
352056
+ let defaultTableStyleId;
352057
+ let footnoteNumberFormat;
352058
+ let endnoteNumberFormat;
352059
+ let footnoteNumberStart = 1;
352060
+ let endnoteNumberStart = 1;
352061
+ let footnoteNumberRestart;
352062
+ let endnoteNumberRestart;
352063
+ let footnotePosition;
352064
+ let endnotePosition;
352065
+ let footnoteSectionConfigs = /* @__PURE__ */ new Map;
352066
+ let endnoteSectionConfigs = /* @__PURE__ */ new Map;
352067
+ if (converter$1) {
352068
+ const settingsRoot = readSettingsRoot(converter$1);
352069
+ if (settingsRoot) {
352070
+ defaultTableStyleId = readDefaultTableStyle(settingsRoot) ?? undefined;
352071
+ footnoteNumberFormat = readFootnoteNumberFormat(settingsRoot) ?? undefined;
352072
+ endnoteNumberFormat = readEndnoteNumberFormat(settingsRoot) ?? undefined;
352073
+ footnoteNumberStart = readFootnoteNumberStart(settingsRoot) ?? 1;
352074
+ endnoteNumberStart = readEndnoteNumberStart(settingsRoot) ?? 1;
352075
+ footnoteNumberRestart = readFootnoteNumberRestart(settingsRoot) ?? undefined;
352076
+ endnoteNumberRestart = readEndnoteNumberRestart(settingsRoot) ?? undefined;
352077
+ footnotePosition = readFootnotePosition(settingsRoot) ?? undefined;
352078
+ endnotePosition = readEndnotePosition(settingsRoot) ?? undefined;
352079
+ }
352080
+ const documentPart = converter$1.convertedXml?.["word/document.xml"];
352081
+ if (documentPart) {
352082
+ footnoteSectionConfigs = readSectionNoteConfigs(documentPart, "w:footnotePr");
352083
+ endnoteSectionConfigs = readSectionNoteConfigs(documentPart, "w:endnotePr");
352084
+ }
352085
+ }
352086
+ if (footnoteNumberRestart === "eachPage") {
352087
+ this.#warnUnsupportedNumberingRestart("footnote");
352088
+ footnoteNumberRestart = "continuous";
352089
+ }
352090
+ if (endnoteNumberRestart === "eachPage") {
352091
+ this.#warnUnsupportedNumberingRestart("endnote");
352092
+ endnoteNumberRestart = "continuous";
350707
352093
  }
350708
- const footnoteSignature = footnoteOrder.join("|");
352094
+ for (const [secIndex, cfg] of footnoteSectionConfigs)
352095
+ if (cfg.numRestart === "eachPage") {
352096
+ footnoteSectionConfigs.set(secIndex, {
352097
+ ...cfg,
352098
+ numRestart: "continuous"
352099
+ });
352100
+ this.#warnUnsupportedNumberingRestart("footnote");
352101
+ }
352102
+ for (const [secIndex, cfg] of endnoteSectionConfigs)
352103
+ if (cfg.numRestart === "eachPage") {
352104
+ endnoteSectionConfigs.set(secIndex, {
352105
+ ...cfg,
352106
+ numRestart: "continuous"
352107
+ });
352108
+ this.#warnUnsupportedNumberingRestart("endnote");
352109
+ }
352110
+ const footnoteNumbering = computeNoteNumbering(this.#editor?.state, "footnoteReference", {
352111
+ startCounter: footnoteNumberStart,
352112
+ defaultNumFmt: footnoteNumberFormat,
352113
+ defaultRestart: footnoteNumberRestart,
352114
+ sectionConfigs: footnoteSectionConfigs
352115
+ });
352116
+ const footnoteNumberById = footnoteNumbering.numberById;
352117
+ const footnoteFormatById = footnoteNumbering.formatById;
352118
+ const footnoteOrder = footnoteNumbering.order;
352119
+ const footnoteSignature = `${footnoteNumberStart}|${footnoteNumberFormat ?? ""}|${footnoteNumberRestart ?? ""}|${serializeSectionConfigs(footnoteSectionConfigs)}|${serializePerIdNumbering(footnoteOrder, footnoteNumberById, footnoteFormatById)}`;
350709
352120
  if (footnoteSignature !== this.#footnoteNumberSignature) {
350710
352121
  this.#flowBlockCache.clear();
350711
352122
  this.#footnoteNumberSignature = footnoteSignature;
350712
352123
  }
350713
- const endnoteNumberById = {};
350714
- const endnoteOrder = [];
350715
- try {
350716
- const seen = /* @__PURE__ */ new Set;
350717
- let counter = 1;
350718
- this.#editor?.state?.doc?.descendants?.((node3) => {
350719
- if (node3?.type?.name !== "endnoteReference")
350720
- return;
350721
- const rawId = node3?.attrs?.id;
350722
- if (rawId == null)
350723
- return;
350724
- const key2 = String(rawId);
350725
- if (!key2 || seen.has(key2))
350726
- return;
350727
- seen.add(key2);
350728
- endnoteNumberById[key2] = counter;
350729
- endnoteOrder.push(key2);
350730
- counter += 1;
350731
- });
350732
- } catch (e) {
350733
- if (typeof console !== "undefined" && console.warn)
350734
- console.warn("[PresentationEditor] Failed to compute endnote numbering:", e);
350735
- }
350736
- const endnoteSignature = endnoteOrder.join("|");
352124
+ const endnoteNumbering = computeNoteNumbering(this.#editor?.state, "endnoteReference", {
352125
+ startCounter: endnoteNumberStart,
352126
+ defaultNumFmt: endnoteNumberFormat,
352127
+ defaultRestart: endnoteNumberRestart,
352128
+ sectionConfigs: endnoteSectionConfigs
352129
+ });
352130
+ const endnoteNumberById = endnoteNumbering.numberById;
352131
+ const endnoteFormatById = endnoteNumbering.formatById;
352132
+ const endnoteOrder = endnoteNumbering.order;
352133
+ const endnoteSignature = `${endnoteNumberStart}|${endnoteNumberFormat ?? ""}|${endnoteNumberRestart ?? ""}|${serializeSectionConfigs(endnoteSectionConfigs)}|${serializePerIdNumbering(endnoteOrder, endnoteNumberById, endnoteFormatById)}`;
350737
352134
  if (endnoteSignature !== this.#endnoteNumberSignature) {
350738
352135
  this.#flowBlockCache.clear();
350739
352136
  this.#endnoteNumberSignature = endnoteSignature;
@@ -350744,16 +352141,16 @@ function print() { __p += __j.call(arguments, '') }
350744
352141
  converter$1["endnoteNumberById"] = endnoteNumberById;
350745
352142
  }
350746
352143
  } catch {}
350747
- let defaultTableStyleId;
350748
- if (converter$1) {
350749
- const settingsRoot = readSettingsRoot(converter$1);
350750
- if (settingsRoot)
350751
- defaultTableStyleId = readDefaultTableStyle(settingsRoot) ?? undefined;
350752
- }
350753
352144
  converterContext = converter$1 ? {
350754
352145
  docx: converter$1.convertedXml,
350755
352146
  ...Object.keys(footnoteNumberById).length ? { footnoteNumberById } : {},
350756
352147
  ...Object.keys(endnoteNumberById).length ? { endnoteNumberById } : {},
352148
+ ...footnoteNumberFormat ? { footnoteNumberFormat } : {},
352149
+ ...endnoteNumberFormat ? { endnoteNumberFormat } : {},
352150
+ ...footnoteFormatById && Object.keys(footnoteFormatById).length ? { footnoteFormatById } : {},
352151
+ ...endnoteFormatById && Object.keys(endnoteFormatById).length ? { endnoteFormatById } : {},
352152
+ ...footnotePosition ? { footnotePosition } : {},
352153
+ ...endnotePosition ? { endnotePosition } : {},
350757
352154
  translatedLinkedStyles: converter$1.translatedLinkedStyles,
350758
352155
  translatedNumbering: converter$1.translatedNumbering,
350759
352156
  ...defaultTableStyleId ? { defaultTableStyleId } : {}
@@ -350770,6 +352167,7 @@ function print() { __p += __j.call(arguments, '') }
350770
352167
  sectionMetadata,
350771
352168
  trackedChangesMode: this.#trackedChangesMode,
350772
352169
  enableTrackedChanges: this.#trackedChangesEnabled,
352170
+ resolveTrackedChangeColor: this.#layoutOptions.resolveTrackedChangeColor,
350773
352171
  enableComments: commentsEnabled,
350774
352172
  enableRichHyperlinks: true,
350775
352173
  themeColors: this.#editor?.converter?.themeColors ?? undefined,
@@ -350801,10 +352199,10 @@ function print() { __p += __j.call(arguments, '') }
350801
352199
  const isSemanticFlow = this.#isSemanticFlowMode();
350802
352200
  const baseLayoutOptions = this.#resolveLayoutOptions(blocks2, sectionMetadata);
350803
352201
  const activeFootnoteOverride = this.#buildActiveNoteRenderOverride("footnote");
350804
- const footnotesLayoutInput = buildFootnotesInput(this.#editor?.state, this.#editor?.converter, converterContext, this.#editor?.converter?.themeColors ?? undefined, activeFootnoteOverride);
352202
+ const footnotesLayoutInput = buildFootnotesInput(this.#editor?.state, this.#editor?.converter, converterContext, this.#editor?.converter?.themeColors ?? undefined, activeFootnoteOverride, this.#layoutOptions.resolveTrackedChangeColor);
350805
352203
  const semanticFootnoteBlocks = isSemanticFlow ? buildSemanticFootnoteBlocks(footnotesLayoutInput, this.#layoutOptions.semanticOptions?.footnotesMode) : [];
350806
352204
  const activeEndnoteOverride = this.#buildActiveNoteRenderOverride("endnote");
350807
- const endnoteBlocks = buildEndnoteBlocks(this.#editor?.state, this.#editor?.converter, converterContext, this.#editor?.converter?.themeColors ?? undefined, activeEndnoteOverride);
352205
+ const endnoteBlocks = buildEndnoteBlocks(this.#editor?.state, this.#editor?.converter, converterContext, this.#editor?.converter?.themeColors ?? undefined, activeEndnoteOverride, this.#layoutOptions.resolveTrackedChangeColor);
350808
352206
  const blocksForLayout = semanticFootnoteBlocks.length > 0 || endnoteBlocks.length > 0 ? [
350809
352207
  ...blocks2,
350810
352208
  ...semanticFootnoteBlocks,
@@ -353602,11 +355000,11 @@ function print() { __p += __j.call(arguments, '') }
353602
355000
  ]);
353603
355001
  });
353604
355002
 
353605
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-DQ3Apok7.es.js
355003
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-jemgYDso.es.js
353606
355004
  var MOD_ALIASES, ALT_ALIASES, CTRL_ALIASES, SHIFT_ALIASES, BUILTIN_CONTEXT_MENU_GROUPS, BUILTIN_GROUP_ORDER, RESERVED_PROXY_PROPERTY_NAMES, ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS;
353607
- var init_create_super_doc_ui_DQ3Apok7_es = __esm(() => {
353608
- init_SuperConverter_kNDiQmof_es();
353609
- init_create_headless_toolbar_fRnbrGLy_es();
355005
+ var init_create_super_doc_ui_jemgYDso_es = __esm(() => {
355006
+ init_SuperConverter_LqX_f8x4_es();
355007
+ init_create_headless_toolbar_BOETXxAI_es();
353610
355008
  MOD_ALIASES = new Set([
353611
355009
  "Mod",
353612
355010
  "Meta",
@@ -353648,16 +355046,16 @@ var init_zipper_yaJVJ4z9_es = __esm(() => {
353648
355046
 
353649
355047
  // ../../packages/superdoc/dist/super-editor.es.js
353650
355048
  var init_super_editor_es = __esm(() => {
353651
- init_src_DckQskSY_es();
353652
- init_SuperConverter_kNDiQmof_es();
355049
+ init_src_iuHADPff_es();
355050
+ init_SuperConverter_LqX_f8x4_es();
353653
355051
  init_jszip_C49i9kUs_es();
353654
355052
  init_xml_js_CqGKpaft_es();
353655
- init_create_headless_toolbar_fRnbrGLy_es();
355053
+ init_create_headless_toolbar_BOETXxAI_es();
353656
355054
  init_constants_D_X7xF4s_es();
353657
355055
  init_dist_B8HfvhaK_es();
353658
355056
  init_unified_Dsuw2be5_es();
353659
355057
  init_DocxZipper_nv_KfOqb_es();
353660
- init_create_super_doc_ui_DQ3Apok7_es();
355058
+ init_create_super_doc_ui_jemgYDso_es();
353661
355059
  init_ui_C5PAS9hY_es();
353662
355060
  init_eventemitter3_BnGqBE_Q_es();
353663
355061
  init_errors_CNaD6vcg_es();