@superdoc-dev/cli 0.2.0-next.2 → 0.2.0-next.3

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 +341 -87
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -18045,7 +18045,7 @@ var init_constants_DBKi0Amm_es = __esm(() => {
18045
18045
  ]);
18046
18046
  });
18047
18047
 
18048
- // ../../packages/superdoc/dist/chunks/SuperConverter-D9XMPi6H.es.js
18048
+ // ../../packages/superdoc/dist/chunks/SuperConverter-Cf1y7bFA.es.js
18049
18049
  function getExtensionConfigField(extension, field, context = { name: "" }) {
18050
18050
  const fieldValue = extension.config[field];
18051
18051
  if (typeof fieldValue === "function")
@@ -35280,6 +35280,16 @@ var isRegExp = (value) => {
35280
35280
  i2++;
35281
35281
  continue;
35282
35282
  }
35283
+ const childElements = node2.elements || [];
35284
+ if (childElements.length > 0) {
35285
+ for (const child of childElements) {
35286
+ if (Array.isArray(child.elements))
35287
+ child.elements = preProcessPageFieldsOnly(child.elements, depth + 1).processedNodes;
35288
+ processedNodes.push(child);
35289
+ }
35290
+ i2++;
35291
+ continue;
35292
+ }
35283
35293
  }
35284
35294
  if (fldType === "begin") {
35285
35295
  const fieldInfo = scanFieldSequence(nodes, i2);
@@ -35301,6 +35311,12 @@ var isRegExp = (value) => {
35301
35311
  continue;
35302
35312
  }
35303
35313
  }
35314
+ if (node2.name === "w:r" && node2.elements?.some((el) => el.name === "w:pgNum")) {
35315
+ const processedField = preProcessPageInstruction([], "", node2.elements.find((el) => el.name === "w:rPr") || null);
35316
+ processedNodes.push(...processedField);
35317
+ i2++;
35318
+ continue;
35319
+ }
35304
35320
  if (Array.isArray(node2.elements))
35305
35321
  node2.elements = preProcessPageFieldsOnly(node2.elements, depth + 1).processedNodes;
35306
35322
  processedNodes.push(node2);
@@ -41780,7 +41796,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41780
41796
  state.kern = kernNode.attributes["w:val"];
41781
41797
  }
41782
41798
  }, SuperConverter;
41783
- var init_SuperConverter_D9XMPi6H_es = __esm(() => {
41799
+ var init_SuperConverter_Cf1y7bFA_es = __esm(() => {
41784
41800
  init_rolldown_runtime_B2q5OVn9_es();
41785
41801
  init_jszip_ChlR43oI_es();
41786
41802
  init_xml_js_DLE8mr0n_es();
@@ -87168,9 +87184,9 @@ var init_remark_gfm_RDxetNVS_es = __esm(() => {
87168
87184
  emptyOptions4 = {};
87169
87185
  });
87170
87186
 
87171
- // ../../packages/superdoc/dist/chunks/src-CYnAk7Cg.es.js
87172
- var exports_src_CYnAk7Cg_es = {};
87173
- __export(exports_src_CYnAk7Cg_es, {
87187
+ // ../../packages/superdoc/dist/chunks/src-eL3w4G7e.es.js
87188
+ var exports_src_eL3w4G7e_es = {};
87189
+ __export(exports_src_eL3w4G7e_es, {
87174
87190
  zt: () => defineMark,
87175
87191
  z: () => cM,
87176
87192
  yt: () => removeAwarenessStates,
@@ -107085,24 +107101,26 @@ function normalizeClientPoint(options, clientX, clientY) {
107085
107101
  const baseX = (clientX - rect.left + scrollLeft) / options.zoom;
107086
107102
  const baseY = (clientY - rect.top + scrollTop) / options.zoom;
107087
107103
  let adjustedX = baseX;
107088
- let adjustedY = baseY;
107104
+ let detectedPageIndex;
107105
+ let pageLocalY;
107089
107106
  const doc$2 = options.visibleHost.ownerDocument ?? document;
107090
107107
  const hitChain = typeof doc$2.elementsFromPoint === "function" ? doc$2.elementsFromPoint(clientX, clientY) : [];
107091
107108
  const pageEl = Array.isArray(hitChain) ? hitChain.find((el) => el?.classList?.contains("superdoc-page")) : null;
107092
107109
  if (pageEl) {
107093
107110
  const pageIndex = Number(pageEl.dataset.pageIndex ?? "NaN");
107094
107111
  if (Number.isFinite(pageIndex)) {
107112
+ detectedPageIndex = pageIndex;
107095
107113
  const pageOffsetX = options.getPageOffsetX(pageIndex);
107096
107114
  if (pageOffsetX != null)
107097
107115
  adjustedX = baseX - pageOffsetX;
107098
- const pageOffsetY = options.getPageOffsetY(pageIndex);
107099
- if (pageOffsetY != null)
107100
- adjustedY = baseY - pageOffsetY;
107116
+ pageLocalY = (clientY - pageEl.getBoundingClientRect().top) / options.zoom;
107101
107117
  }
107102
107118
  }
107103
107119
  return {
107104
107120
  x: adjustedX,
107105
- y: adjustedY
107121
+ y: baseY,
107122
+ pageIndex: detectedPageIndex,
107123
+ pageLocalY
107106
107124
  };
107107
107125
  }
107108
107126
  function denormalizeClientPoint(options, layoutX, layoutY, pageIndex, height) {
@@ -107474,7 +107492,9 @@ function publishSectionMetadata(sectionRanges, options) {
107474
107492
  footerRefs: section.footerRefs,
107475
107493
  numbering: section.numbering,
107476
107494
  titlePg: section.titlePg,
107477
- vAlign: section.vAlign
107495
+ vAlign: section.vAlign,
107496
+ margins: section.margins,
107497
+ pageSize: section.pageSize
107478
107498
  });
107479
107499
  });
107480
107500
  }
@@ -116255,6 +116275,84 @@ async function measureListBlock(block, constraints) {
116255
116275
  totalHeight
116256
116276
  };
116257
116277
  }
116278
+ function buildSectionContentWidth(section, fallback) {
116279
+ const pageW = section.pageSize?.w ?? fallback.pageWidth;
116280
+ const marginL = section.margins?.left ?? fallback.margins.left;
116281
+ const marginR = section.margins?.right ?? fallback.margins.right;
116282
+ return pageW - marginL - marginR;
116283
+ }
116284
+ function buildConstraintsForSection(section, fallback, minWidth) {
116285
+ const pageW = section.pageSize?.w ?? fallback.pageWidth;
116286
+ const marginL = section.margins?.left ?? fallback.margins.left;
116287
+ const marginR = section.margins?.right ?? fallback.margins.right;
116288
+ const contentWidth = pageW - marginL - marginR;
116289
+ const maxWidth = pageW - marginL;
116290
+ return {
116291
+ width: minWidth ? Math.min(Math.max(contentWidth, minWidth), maxWidth) : contentWidth,
116292
+ height: fallback.height,
116293
+ pageWidth: pageW,
116294
+ margins: {
116295
+ left: marginL,
116296
+ right: marginR
116297
+ }
116298
+ };
116299
+ }
116300
+ function getTableWidthSpec(blocks2) {
116301
+ let result;
116302
+ let maxResolvedWidth = 0;
116303
+ for (const block of blocks2) {
116304
+ if (block.kind !== "table")
116305
+ continue;
116306
+ const tableWidth = block.attrs?.tableWidth;
116307
+ const widthValue = tableWidth?.width ?? tableWidth?.value;
116308
+ if (tableWidth?.type === "pct" && typeof widthValue === "number" && widthValue > 0) {
116309
+ if (!result || result.type !== "pct" || widthValue > result.value) {
116310
+ result = {
116311
+ type: "pct",
116312
+ value: widthValue
116313
+ };
116314
+ maxResolvedWidth = Infinity;
116315
+ }
116316
+ } else if ((tableWidth?.type === "px" || tableWidth?.type === "pixel") && typeof widthValue === "number") {
116317
+ if (widthValue > maxResolvedWidth) {
116318
+ maxResolvedWidth = widthValue;
116319
+ result = {
116320
+ type: "px",
116321
+ value: widthValue
116322
+ };
116323
+ }
116324
+ } else if (block.columnWidths && block.columnWidths.length > 0) {
116325
+ const gridTotal = block.columnWidths.reduce((sum, w2) => sum + w2, 0);
116326
+ if (gridTotal > maxResolvedWidth) {
116327
+ maxResolvedWidth = gridTotal;
116328
+ result = {
116329
+ type: "grid",
116330
+ value: gridTotal
116331
+ };
116332
+ }
116333
+ }
116334
+ }
116335
+ return result;
116336
+ }
116337
+ function resolveTableMinWidth(spec, contentWidth) {
116338
+ if (!spec)
116339
+ return 0;
116340
+ if (spec.type === "pct")
116341
+ return contentWidth * (spec.value / OOXML_PCT_DIVISOR);
116342
+ return spec.value;
116343
+ }
116344
+ function resolveRIdPerSection(sectionMetadata, kind) {
116345
+ const result = /* @__PURE__ */ new Map;
116346
+ let inherited;
116347
+ for (const section of sectionMetadata) {
116348
+ const rId = (kind === "header" ? section.headerRefs : section.footerRefs)?.default;
116349
+ if (rId)
116350
+ inherited = rId;
116351
+ if (inherited)
116352
+ result.set(section.sectionIndex, inherited);
116353
+ }
116354
+ return result;
116355
+ }
116258
116356
  async function layoutPerRIdHeaderFooters(headerFooterInput, layout, sectionMetadata, deps) {
116259
116357
  deps.headerLayoutsByRId.clear();
116260
116358
  deps.footerLayoutsByRId.clear();
@@ -116269,42 +116367,127 @@ async function layoutPerRIdHeaderFooters(headerFooterInput, layout, sectionMetad
116269
116367
  totalPages
116270
116368
  };
116271
116369
  };
116272
- if (headerBlocksByRId)
116273
- for (const [rId, blocks2] of headerBlocksByRId) {
116274
- if (!blocks2 || blocks2.length === 0)
116275
- continue;
116276
- try {
116277
- const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, (block, c$3) => measureBlock(block, c$3), undefined, undefined, pageResolver);
116278
- if (batchResult.default)
116279
- deps.headerLayoutsByRId.set(rId, {
116280
- kind: "header",
116281
- type: "default",
116282
- layout: batchResult.default.layout,
116283
- blocks: batchResult.default.blocks,
116284
- measures: batchResult.default.measures
116285
- });
116286
- } catch (error) {
116287
- console.warn(`[PresentationEditor] Failed to layout header rId=${rId}:`, error);
116288
- }
116370
+ if (sectionMetadata.length > 1 && sectionMetadata.some((s2) => s2.margins || s2.pageSize)) {
116371
+ await layoutWithPerSectionConstraints("header", headerBlocksByRId, sectionMetadata, constraints, pageResolver, deps.headerLayoutsByRId);
116372
+ await layoutWithPerSectionConstraints("footer", footerBlocksByRId, sectionMetadata, constraints, pageResolver, deps.footerLayoutsByRId);
116373
+ } else {
116374
+ await layoutBlocksByRId("header", headerBlocksByRId, constraints, pageResolver, deps.headerLayoutsByRId);
116375
+ await layoutBlocksByRId("footer", footerBlocksByRId, constraints, pageResolver, deps.footerLayoutsByRId);
116376
+ }
116377
+ }
116378
+ async function layoutBlocksByRId(kind, blocksByRId, constraints, pageResolver, layoutsByRId) {
116379
+ if (!blocksByRId)
116380
+ return;
116381
+ for (const [rId, blocks2] of blocksByRId) {
116382
+ if (!blocks2 || blocks2.length === 0)
116383
+ continue;
116384
+ try {
116385
+ const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, (block, c$3) => measureBlock(block, c$3), undefined, undefined, pageResolver);
116386
+ if (batchResult.default)
116387
+ layoutsByRId.set(rId, {
116388
+ kind,
116389
+ type: "default",
116390
+ layout: batchResult.default.layout,
116391
+ blocks: batchResult.default.blocks,
116392
+ measures: batchResult.default.measures
116393
+ });
116394
+ } catch (error) {
116395
+ console.warn(`[PresentationEditor] Failed to layout ${kind} rId=${rId}:`, error);
116289
116396
  }
116290
- if (footerBlocksByRId)
116291
- for (const [rId, blocks2] of footerBlocksByRId) {
116292
- if (!blocks2 || blocks2.length === 0)
116397
+ }
116398
+ }
116399
+ function cloneHeaderFooterLayout(layout) {
116400
+ return {
116401
+ ...layout,
116402
+ pages: layout.pages.map((page) => ({
116403
+ ...page,
116404
+ fragments: page.fragments.map((f) => ({ ...f }))
116405
+ }))
116406
+ };
116407
+ }
116408
+ function adjustFramePositionsForContentWidth(layout, blocks2, effectiveWidth, contentWidth) {
116409
+ if (effectiveWidth <= contentWidth)
116410
+ return;
116411
+ const widthDiff = effectiveWidth - contentWidth;
116412
+ const blockById = /* @__PURE__ */ new Map;
116413
+ for (const block of blocks2)
116414
+ blockById.set(block.id, block);
116415
+ for (const page of layout.pages)
116416
+ for (const fragment of page.fragments) {
116417
+ if (fragment.kind !== "para")
116293
116418
  continue;
116294
- try {
116295
- const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, (block, c$3) => measureBlock(block, c$3), undefined, undefined, pageResolver);
116296
- if (batchResult.default)
116297
- deps.footerLayoutsByRId.set(rId, {
116298
- kind: "footer",
116419
+ const block = blockById.get(fragment.blockId);
116420
+ if (!block || block.kind !== "paragraph")
116421
+ continue;
116422
+ const frame = block.attrs?.frame;
116423
+ if (!frame || frame.wrap !== "none")
116424
+ continue;
116425
+ if (frame.xAlign === "right")
116426
+ fragment.x -= widthDiff;
116427
+ else if (frame.xAlign === "center")
116428
+ fragment.x -= widthDiff / 2;
116429
+ }
116430
+ }
116431
+ async function layoutWithPerSectionConstraints(kind, blocksByRId, sectionMetadata, fallbackConstraints, pageResolver, layoutsByRId) {
116432
+ if (!blocksByRId)
116433
+ return;
116434
+ const rIdPerSection = resolveRIdPerSection(sectionMetadata, kind);
116435
+ const tableWidthSpecByRId = /* @__PURE__ */ new Map;
116436
+ for (const [rId, blocks2] of blocksByRId) {
116437
+ const spec = getTableWidthSpec(blocks2);
116438
+ if (spec)
116439
+ tableWidthSpecByRId.set(rId, spec);
116440
+ }
116441
+ const groups = /* @__PURE__ */ new Map;
116442
+ for (const section of sectionMetadata) {
116443
+ const rId = rIdPerSection.get(section.sectionIndex);
116444
+ if (!rId || !blocksByRId.has(rId))
116445
+ continue;
116446
+ const contentWidth = buildSectionContentWidth(section, fallbackConstraints);
116447
+ const sectionConstraints = buildConstraintsForSection(section, fallbackConstraints, resolveTableMinWidth(tableWidthSpecByRId.get(rId), contentWidth) || undefined);
116448
+ const effectiveWidth = sectionConstraints.width;
116449
+ const groupKey = `${rId}::w${effectiveWidth}`;
116450
+ let group = groups.get(groupKey);
116451
+ if (!group) {
116452
+ group = {
116453
+ sectionConstraints,
116454
+ sectionIndices: [],
116455
+ rId,
116456
+ effectiveWidth
116457
+ };
116458
+ groups.set(groupKey, group);
116459
+ }
116460
+ group.sectionIndices.push(section.sectionIndex);
116461
+ }
116462
+ for (const [, group] of groups) {
116463
+ const blocks2 = blocksByRId.get(group.rId);
116464
+ if (!blocks2 || blocks2.length === 0)
116465
+ continue;
116466
+ try {
116467
+ const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, group.sectionConstraints, (block, c$3) => measureBlock(block, c$3), undefined, undefined, pageResolver);
116468
+ if (batchResult.default)
116469
+ for (const sectionIndex of group.sectionIndices) {
116470
+ const contentWidth = buildSectionContentWidth(sectionMetadata.find((s2) => s2.sectionIndex === sectionIndex), fallbackConstraints);
116471
+ const needsFrameAdjust = group.effectiveWidth > contentWidth;
116472
+ let layout = batchResult.default.layout;
116473
+ if (needsFrameAdjust) {
116474
+ layout = cloneHeaderFooterLayout(layout);
116475
+ adjustFramePositionsForContentWidth(layout, batchResult.default.blocks, group.effectiveWidth, contentWidth);
116476
+ }
116477
+ const result = {
116478
+ kind,
116299
116479
  type: "default",
116300
- layout: batchResult.default.layout,
116480
+ layout,
116301
116481
  blocks: batchResult.default.blocks,
116302
- measures: batchResult.default.measures
116303
- });
116304
- } catch (error) {
116305
- console.warn(`[PresentationEditor] Failed to layout footer rId=${rId}:`, error);
116306
- }
116482
+ measures: batchResult.default.measures,
116483
+ effectiveWidth: needsFrameAdjust ? group.effectiveWidth : undefined
116484
+ };
116485
+ layoutsByRId.set(`${group.rId}::s${sectionIndex}`, result);
116486
+ }
116487
+ } catch (error) {
116488
+ console.warn(`[PresentationEditor] Failed to layout ${kind} rId=${group.rId}:`, error);
116307
116489
  }
116490
+ }
116308
116491
  }
116309
116492
  function dropCursor(options = {}) {
116310
116493
  return new Plugin({ view(editorView) {
@@ -143527,11 +143710,13 @@ var Node$13 = class Node$14 {
143527
143710
  return;
143528
143711
  }
143529
143712
  if ((this.#deps.getHeaderFooterSession()?.session?.mode ?? "body") !== "body") {
143530
- if (this.#handleClickInHeaderFooterMode(event, x2, y$1))
143713
+ if (this.#handleClickInHeaderFooterMode(event, x2, y$1, normalizedPoint.pageIndex, normalizedPoint.pageLocalY))
143531
143714
  return;
143532
143715
  }
143533
- if (this.#callbacks.hitTestHeaderFooterRegion?.(x2, y$1))
143716
+ if (this.#callbacks.hitTestHeaderFooterRegion?.(x2, y$1, normalizedPoint.pageIndex, normalizedPoint.pageLocalY)) {
143717
+ event.preventDefault();
143534
143718
  return;
143719
+ }
143535
143720
  const viewportHost = this.#deps.getViewportHost();
143536
143721
  const pageGeometryHelper = this.#deps.getPageGeometryHelper();
143537
143722
  const rawHit = clickToPosition(layoutState.layout, layoutState.blocks, layoutState.measures, {
@@ -143758,15 +143943,10 @@ var Node$13 = class Node$14 {
143758
143943
  }
143759
143944
  if (!this.#deps.getLayoutState().layout)
143760
143945
  return;
143761
- const viewportHost = this.#deps.getViewportHost();
143762
- const visibleHost = this.#deps.getVisibleHost();
143763
- const zoom = this.#deps.getZoom();
143764
- const rect = viewportHost.getBoundingClientRect();
143765
- const scrollLeft = visibleHost.scrollLeft ?? 0;
143766
- const scrollTop = visibleHost.scrollTop ?? 0;
143767
- const x2 = (event.clientX - rect.left + scrollLeft) / zoom;
143768
- const y$1 = (event.clientY - rect.top + scrollTop) / zoom;
143769
- const region = this.#callbacks.hitTestHeaderFooterRegion?.(x2, y$1);
143946
+ const normalized = this.#callbacks.normalizeClientPoint?.(event.clientX, event.clientY);
143947
+ if (!normalized)
143948
+ return;
143949
+ const region = this.#callbacks.hitTestHeaderFooterRegion?.(normalized.x, normalized.y, normalized.pageIndex, normalized.pageLocalY);
143770
143950
  if (region) {
143771
143951
  event.preventDefault();
143772
143952
  event.stopPropagation();
@@ -144020,15 +144200,15 @@ var Node$13 = class Node$14 {
144020
144200
  document.activeElement.blur();
144021
144201
  this.#focusEditorAtFirstPosition();
144022
144202
  }
144023
- #handleClickInHeaderFooterMode(event, x2, y$1) {
144203
+ #handleClickInHeaderFooterMode(event, x2, y$1, pageIndex, pageLocalY) {
144024
144204
  const activeEditorHost = this.#deps?.getHeaderFooterSession()?.overlayManager?.getActiveEditorHost?.();
144025
144205
  if (activeEditorHost && (activeEditorHost.contains(event.target) || activeEditorHost === event.target))
144026
144206
  return true;
144027
- if (!this.#callbacks.hitTestHeaderFooterRegion?.(x2, y$1)) {
144207
+ if (!this.#callbacks.hitTestHeaderFooterRegion?.(x2, y$1, pageIndex, pageLocalY)) {
144028
144208
  this.#callbacks.exitHeaderFooterMode?.();
144029
144209
  return false;
144030
144210
  }
144031
- return true;
144211
+ return false;
144032
144212
  }
144033
144213
  #handleInlineImageClick(event, targetImg, rawHit, doc$2, epochMapper) {
144034
144214
  if (!targetImg)
@@ -144230,7 +144410,7 @@ var Node$13 = class Node$14 {
144230
144410
  this.#callbacks.clearHoverRegion?.();
144231
144411
  return;
144232
144412
  }
144233
- const region = this.#callbacks.hitTestHeaderFooterRegion?.(normalized.x, normalized.y);
144413
+ const region = this.#callbacks.hitTestHeaderFooterRegion?.(normalized.x, normalized.y, normalized.pageIndex, normalized.pageLocalY);
144234
144414
  if (!region) {
144235
144415
  this.#callbacks.clearHoverRegion?.();
144236
144416
  return;
@@ -145000,6 +145180,7 @@ var Node$13 = class Node$14 {
145000
145180
  pm.style.minHeight = "100%";
145001
145181
  pm.style.outline = "none";
145002
145182
  pm.style.border = "none";
145183
+ pm.classList.add("sd-header-footer");
145003
145184
  pm.setAttribute("role", "textbox");
145004
145185
  pm.setAttribute("aria-multiline", true);
145005
145186
  pm.setAttribute("aria-label", `${type} content area. Double click to start typing.`);
@@ -145242,7 +145423,7 @@ var Node$13 = class Node$14 {
145242
145423
  position: "absolute",
145243
145424
  pointerEvents: "auto",
145244
145425
  visibility: "hidden",
145245
- overflow: "hidden",
145426
+ overflow: "visible",
145246
145427
  boxSizing: "border-box"
145247
145428
  });
145248
145429
  if (decorationContainer)
@@ -145669,12 +145850,14 @@ var Node$13 = class Node$14 {
145669
145850
  const actualPageHeight = page.size?.h ?? pageHeight;
145670
145851
  const headerPayload = this.#headerDecorationProvider?.(page.number, margins, page);
145671
145852
  const headerBox = this.#computeDecorationBox("header", margins, actualPageHeight);
145853
+ const displayPageNumber = page.numberText ?? String(page.number);
145672
145854
  this.#headerRegions.set(pageIndex, {
145673
145855
  kind: "header",
145674
145856
  headerId: headerPayload?.headerId,
145675
145857
  sectionType: headerPayload?.sectionType ?? this.#computeExpectedSectionType("header", page, sectionFirstPageNumbers),
145676
145858
  pageIndex,
145677
145859
  pageNumber: page.number,
145860
+ displayPageNumber,
145678
145861
  localX: headerPayload?.hitRegion?.x ?? headerBox.x,
145679
145862
  localY: headerPayload?.hitRegion?.y ?? headerBox.offset,
145680
145863
  width: headerPayload?.hitRegion?.width ?? headerBox.width,
@@ -145689,6 +145872,7 @@ var Node$13 = class Node$14 {
145689
145872
  sectionType: footerPayload?.sectionType ?? this.#computeExpectedSectionType("footer", page, sectionFirstPageNumbers),
145690
145873
  pageIndex,
145691
145874
  pageNumber: page.number,
145875
+ displayPageNumber,
145692
145876
  localX: footerPayload?.hitRegion?.x ?? footerBox.x,
145693
145877
  localY: footerPayload?.hitRegion?.y ?? footerBox.offset,
145694
145878
  width: footerPayload?.hitRegion?.width ?? footerBox.width,
@@ -145698,16 +145882,29 @@ var Node$13 = class Node$14 {
145698
145882
  });
145699
145883
  });
145700
145884
  }
145701
- hitTestRegion(x2, y$1, layout) {
145885
+ hitTestRegion(x2, y$1, layout, knownPageIndex, knownPageLocalY) {
145702
145886
  if (!layout)
145703
145887
  return null;
145704
145888
  const layoutOptions = this.#deps?.getLayoutOptions() ?? {};
145705
- const pageHeight = layout.pageSize?.h ?? layoutOptions.pageSize?.h ?? this.#options.defaultPageSize.h;
145889
+ const defaultPageHeight = layout.pageSize?.h ?? layoutOptions.pageSize?.h ?? this.#options.defaultPageSize.h;
145706
145890
  const pageGap = layout.pageGap ?? 0;
145707
- if (pageHeight <= 0)
145891
+ if (defaultPageHeight <= 0)
145708
145892
  return null;
145709
- const pageIndex = Math.max(0, Math.floor(y$1 / (pageHeight + pageGap)));
145710
- const pageLocalY = y$1 - pageIndex * (pageHeight + pageGap);
145893
+ let pageIndex;
145894
+ let pageLocalY;
145895
+ if (knownPageIndex != null && knownPageLocalY != null) {
145896
+ pageIndex = knownPageIndex;
145897
+ pageLocalY = knownPageLocalY;
145898
+ } else if (knownPageIndex != null) {
145899
+ pageIndex = knownPageIndex;
145900
+ let pageTopY = 0;
145901
+ for (let i$1 = 0;i$1 < pageIndex && i$1 < layout.pages.length; i$1++)
145902
+ pageTopY += (layout.pages[i$1].size?.h ?? defaultPageHeight) + pageGap;
145903
+ pageLocalY = y$1 - pageTopY;
145904
+ } else {
145905
+ pageIndex = Math.max(0, Math.floor(y$1 / (defaultPageHeight + pageGap)));
145906
+ pageLocalY = y$1 - pageIndex * (defaultPageHeight + pageGap);
145907
+ }
145711
145908
  const headerRegion = this.#headerRegions.get(pageIndex);
145712
145909
  if (headerRegion && this.#pointInRegion(headerRegion, x2, pageLocalY))
145713
145910
  return headerRegion;
@@ -145795,6 +145992,15 @@ var Node$13 = class Node$14 {
145795
145992
  this.clearHover();
145796
145993
  return;
145797
145994
  }
145995
+ if (this.#session.mode !== "body") {
145996
+ if (this.#activeEditor) {
145997
+ this.#activeEditor.setEditable(false);
145998
+ this.#activeEditor.setOptions({ documentMode: "viewing" });
145999
+ }
146000
+ this.#overlayManager.hideEditingOverlay();
146001
+ this.#activeEditor = null;
146002
+ this.#session = { mode: "body" };
146003
+ }
145798
146004
  const descriptor = this.#resolveDescriptorForRegion(region);
145799
146005
  if (!descriptor) {
145800
146006
  console.warn("[HeaderFooterSessionManager] No descriptor found for region:", region);
@@ -145849,7 +146055,7 @@ var Node$13 = class Node$14 {
145849
146055
  });
145850
146056
  return;
145851
146057
  }
145852
- const layout = this.#headerLayoutResults?.[0]?.layout;
146058
+ const bodyPageCount = this.#deps?.getBodyPageCount() ?? 1;
145853
146059
  let editor;
145854
146060
  try {
145855
146061
  editor = await this.#headerFooterManager.ensureEditor(descriptor, {
@@ -145857,7 +146063,7 @@ var Node$13 = class Node$14 {
145857
146063
  availableWidth: region.width,
145858
146064
  availableHeight: region.height,
145859
146065
  currentPageNumber: region.pageNumber,
145860
- totalPageCount: layout?.pages?.length ?? 1
146066
+ totalPageCount: bodyPageCount
145861
146067
  });
145862
146068
  } catch (editorError) {
145863
146069
  console.error("[HeaderFooterSessionManager] Error creating editor:", editorError);
@@ -146310,8 +146516,10 @@ var Node$13 = class Node$14 {
146310
146516
  }
146311
146517
  if (!headerFooterType)
146312
146518
  return null;
146313
- if (sectionRId && layoutsByRId.has(sectionRId)) {
146314
- const rIdLayout = layoutsByRId.get(sectionRId);
146519
+ const compositeKey = sectionRId ? `${sectionRId}::s${sectionIndex}` : undefined;
146520
+ const rIdLayoutKey = compositeKey && layoutsByRId.has(compositeKey) && compositeKey || sectionRId && layoutsByRId.has(sectionRId) && sectionRId || undefined;
146521
+ if (rIdLayoutKey) {
146522
+ const rIdLayout = layoutsByRId.get(rIdLayoutKey);
146315
146523
  if (!rIdLayout)
146316
146524
  console.warn(`[HeaderFooterSessionManager] Inconsistent state: layoutsByRId.has('${sectionRId}') returned true but get() returned undefined`);
146317
146525
  else {
@@ -146322,6 +146530,7 @@ var Node$13 = class Node$14 {
146322
146530
  const margins$1 = pageMargins ?? layout.pages[0]?.margins ?? layoutOptions.margins ?? defaultMargins;
146323
146531
  const decorationMargins$1 = kind === "footer" ? this.#stripFootnoteReserveFromBottomMargin(margins$1, page ?? null) : margins$1;
146324
146532
  const box$1 = this.#computeDecorationBox(kind, decorationMargins$1, pageHeight$1);
146533
+ const effectiveWidth = rIdLayout.effectiveWidth ?? box$1.width;
146325
146534
  const rawLayoutHeight$1 = rIdLayout.layout.height ?? 0;
146326
146535
  const metrics$1 = this.#computeMetrics(kind, rawLayoutHeight$1, box$1, pageHeight$1, margins$1?.footer ?? 0);
146327
146536
  const layoutMinY$1 = rIdLayout.layout.minY ?? 0;
@@ -146334,20 +146543,20 @@ var Node$13 = class Node$14 {
146334
146543
  contentHeight: metrics$1.layoutHeight > 0 ? metrics$1.layoutHeight : metrics$1.containerHeight,
146335
146544
  offset: metrics$1.offset,
146336
146545
  marginLeft: box$1.x,
146337
- contentWidth: box$1.width,
146546
+ contentWidth: effectiveWidth,
146338
146547
  headerId: sectionRId,
146339
146548
  sectionType: headerFooterType,
146340
146549
  minY: layoutMinY$1,
146341
146550
  box: {
146342
146551
  x: box$1.x,
146343
146552
  y: metrics$1.offset,
146344
- width: box$1.width,
146553
+ width: effectiveWidth,
146345
146554
  height: metrics$1.containerHeight
146346
146555
  },
146347
146556
  hitRegion: {
146348
146557
  x: box$1.x,
146349
146558
  y: metrics$1.offset,
146350
- width: box$1.width,
146559
+ width: effectiveWidth,
146351
146560
  height: metrics$1.containerHeight
146352
146561
  }
146353
146562
  };
@@ -148922,7 +149131,7 @@ var Node$13 = class Node$14 {
148922
149131
  };
148923
149132
  case "total-page-number":
148924
149133
  return {
148925
- text: editor.options.parentEditor?.currentTotalPages || "1",
149134
+ text: editor.options.totalPageCount || editor.options.parentEditor?.currentTotalPages || "1",
148926
149135
  className: "sd-editor-auto-total-pages",
148927
149136
  dataId: "auto-total-pages",
148928
149137
  ariaLabel: "Total page count node"
@@ -148984,6 +149193,10 @@ var Node$13 = class Node$14 {
148984
149193
  if (!incomingType || incomingType !== currentType)
148985
149194
  return false;
148986
149195
  this.node = node3;
149196
+ const attrs = getNodeAttributes(this.node.type.name, this.editor);
149197
+ const newText = String(attrs.text);
149198
+ if (this.dom.textContent !== newText)
149199
+ this.dom.textContent = newText;
148987
149200
  return true;
148988
149201
  }
148989
149202
  }, getMarksFromNeighbors = (currentPos, view) => {
@@ -152132,9 +152345,9 @@ var Node$13 = class Node$14 {
152132
152345
  trackedChanges: context.trackedChanges ?? []
152133
152346
  });
152134
152347
  }, _hoisted_1$6, _hoisted_2$1, _hoisted_3, _hoisted_4, ContextMenu_default, _hoisted_1$5, BasicUpload_default, _hoisted_1$4, MIN_WIDTH = 200, PPI = 96, alignment = "flex-end", Ruler_default, GenericPopover_default, _hoisted_1$3, RESIZE_HANDLE_WIDTH_PX = 9, RESIZE_HANDLE_OFFSET_PX = 4, DRAG_OVERLAY_EXTENSION_PX = 1000, MIN_DRAG_OVERLAY_WIDTH_PX = 2000, THROTTLE_INTERVAL_MS = 16, MIN_RESIZE_DELTA_PX = 1, TableResizeOverlay_default, _hoisted_1$2, OVERLAY_EXPANSION_PX = 2000, RESIZE_HANDLE_SIZE_PX = 12, MOUSE_MOVE_THROTTLE_MS = 16, DIMENSION_CHANGE_THRESHOLD_PX = 1, Z_INDEX_OVERLAY = 10, Z_INDEX_HANDLE = 15, Z_INDEX_GUIDELINE = 20, ImageResizeOverlay_default, LINK_CLICK_DEBOUNCE_MS = 300, CURSOR_UPDATE_TIMEOUT_MS = 10, LinkClickHandler_default, _hoisted_1$1, _hoisted_2, DOCX2 = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", TABLE_RESIZE_HOVER_THRESHOLD = 8, TABLE_RESIZE_THROTTLE_MS = 16, SuperEditor_default, _hoisted_1, SuperInput_default, SlashMenu, Extensions;
152135
- var init_src_CYnAk7Cg_es = __esm(() => {
152348
+ var init_src_eL3w4G7e_es = __esm(() => {
152136
152349
  init_rolldown_runtime_B2q5OVn9_es();
152137
- init_SuperConverter_D9XMPi6H_es();
152350
+ init_SuperConverter_Cf1y7bFA_es();
152138
152351
  init_jszip_ChlR43oI_es();
152139
152352
  init_uuid_2IzDu5nl_es();
152140
152353
  init_constants_DBKi0Amm_es();
@@ -170753,8 +170966,10 @@ function print() { __p += __j.call(arguments, '') }
170753
170966
  updateOptions.availableWidth = options.availableWidth;
170754
170967
  if (options.availableHeight !== undefined)
170755
170968
  updateOptions.availableHeight = options.availableHeight;
170756
- if (Object.keys(updateOptions).length > 0)
170969
+ if (Object.keys(updateOptions).length > 0) {
170757
170970
  existing.editor.setOptions(updateOptions);
170971
+ this.#refreshPageNumberDisplay(existing.editor);
170972
+ }
170758
170973
  }
170759
170974
  return existing.editor;
170760
170975
  }
@@ -170785,6 +171000,25 @@ function print() { __p += __j.call(arguments, '') }
170785
171000
  this.#pendingCreations.set(descriptor.id, creationPromise);
170786
171001
  return creationPromise;
170787
171002
  }
171003
+ #refreshPageNumberDisplay(editor) {
171004
+ const container = editor.view?.dom;
171005
+ if (!container)
171006
+ return;
171007
+ const opts = editor.options;
171008
+ const parentEditor = opts.parentEditor;
171009
+ const currentPage = String(opts.currentPageNumber || "1");
171010
+ const totalPages = String(opts.totalPageCount || parentEditor?.currentTotalPages || "1");
171011
+ const pageNumberEls = container.querySelectorAll('[data-id="auto-page-number"]');
171012
+ const totalPagesEls = container.querySelectorAll('[data-id="auto-total-pages"]');
171013
+ pageNumberEls.forEach((el) => {
171014
+ if (el.textContent !== currentPage)
171015
+ el.textContent = currentPage;
171016
+ });
171017
+ totalPagesEls.forEach((el) => {
171018
+ if (el.textContent !== totalPages)
171019
+ el.textContent = totalPages;
171020
+ });
171021
+ }
170788
171022
  getEditor(descriptor) {
170789
171023
  if (!descriptor?.id)
170790
171024
  return null;
@@ -172465,7 +172699,7 @@ function print() { __p += __j.call(arguments, '') }
172465
172699
  goToAnchor: (href) => this.goToAnchor(href),
172466
172700
  emit: (event, payload) => this.emit(event, payload),
172467
172701
  normalizeClientPoint: (clientX, clientY) => this.#normalizeClientPoint(clientX, clientY),
172468
- hitTestHeaderFooterRegion: (x2, y$1) => this.#hitTestHeaderFooterRegion(x2, y$1),
172702
+ hitTestHeaderFooterRegion: (x2, y$1, pageIndex, pageLocalY) => this.#hitTestHeaderFooterRegion(x2, y$1, pageIndex, pageLocalY),
172469
172703
  exitHeaderFooterMode: () => this.#exitHeaderFooterMode(),
172470
172704
  activateHeaderFooterRegion: (region) => this.#activateHeaderFooterRegion(region),
172471
172705
  createDefaultHeaderFooter: (region) => this.#createDefaultHeaderFooter(region),
@@ -172588,7 +172822,8 @@ function print() { __p += __j.call(arguments, '') }
172588
172822
  scheduleRerender: () => this.#scheduleRerender(),
172589
172823
  setPendingDocChange: () => {
172590
172824
  this.#pendingDocChange = true;
172591
- }
172825
+ },
172826
+ getBodyPageCount: () => this.#layoutState?.layout?.pages?.length ?? 1
172592
172827
  });
172593
172828
  this.#headerFooterSession.setCallbacks({
172594
172829
  onModeChanged: (session) => {
@@ -173504,8 +173739,8 @@ function print() { __p += __j.call(arguments, '') }
173504
173739
  #updateDecorationProviders(layout) {
173505
173740
  this.#headerFooterSession?.updateDecorationProviders(layout);
173506
173741
  }
173507
- #hitTestHeaderFooterRegion(x2, y$1) {
173508
- return this.#headerFooterSession?.hitTestRegion(x2, y$1, this.#layoutState.layout) ?? null;
173742
+ #hitTestHeaderFooterRegion(x2, y$1, pageIndex, pageLocalY) {
173743
+ return this.#headerFooterSession?.hitTestRegion(x2, y$1, this.#layoutState.layout, pageIndex, pageLocalY) ?? null;
173509
173744
  }
173510
173745
  #activateHeaderFooterRegion(region) {
173511
173746
  this.#headerFooterSession?.activateRegion(region);
@@ -178257,7 +178492,7 @@ function print() { __p += __j.call(arguments, '') }
178257
178492
  const { schema } = state;
178258
178493
  if (!schema.nodes?.["total-page-number"])
178259
178494
  return false;
178260
- const currentPages = editor?.options?.parentEditor?.currentTotalPages || 1;
178495
+ const currentPages = editor?.options?.totalPageCount || editor?.options?.parentEditor?.currentTotalPages || 1;
178261
178496
  const pageNumberNode = {
178262
178497
  type: "total-page-number",
178263
178498
  content: [{
@@ -183582,8 +183817,8 @@ function print() { __p += __j.call(arguments, '') }
183582
183817
  return isObjectLike_default(value) && hasOwnProperty$8.call(value, "callee") && !propertyIsEnumerable$1.call(value, "callee");
183583
183818
  };
183584
183819
  stubFalse_default = stubFalse;
183585
- freeExports$2 = typeof exports_src_CYnAk7Cg_es == "object" && exports_src_CYnAk7Cg_es && !exports_src_CYnAk7Cg_es.nodeType && exports_src_CYnAk7Cg_es;
183586
- freeModule$2 = freeExports$2 && typeof module_src_CYnAk7Cg_es == "object" && module_src_CYnAk7Cg_es && !module_src_CYnAk7Cg_es.nodeType && module_src_CYnAk7Cg_es;
183820
+ freeExports$2 = typeof exports_src_eL3w4G7e_es == "object" && exports_src_eL3w4G7e_es && !exports_src_eL3w4G7e_es.nodeType && exports_src_eL3w4G7e_es;
183821
+ freeModule$2 = freeExports$2 && typeof module_src_eL3w4G7e_es == "object" && module_src_eL3w4G7e_es && !module_src_eL3w4G7e_es.nodeType && module_src_eL3w4G7e_es;
183587
183822
  Buffer$1 = freeModule$2 && freeModule$2.exports === freeExports$2 ? _root_default.Buffer : undefined;
183588
183823
  isBuffer_default = (Buffer$1 ? Buffer$1.isBuffer : undefined) || stubFalse_default;
183589
183824
  typedArrayTags = {};
@@ -183591,8 +183826,8 @@ function print() { __p += __j.call(arguments, '') }
183591
183826
  typedArrayTags[argsTag$1] = typedArrayTags[arrayTag$1] = typedArrayTags[arrayBufferTag$1] = typedArrayTags[boolTag$1] = typedArrayTags[dataViewTag$2] = typedArrayTags[dateTag$1] = typedArrayTags[errorTag$1] = typedArrayTags[funcTag] = typedArrayTags[mapTag$2] = typedArrayTags[numberTag$1] = typedArrayTags[objectTag$3] = typedArrayTags[regexpTag$1] = typedArrayTags[setTag$2] = typedArrayTags[stringTag$1] = typedArrayTags[weakMapTag$1] = false;
183592
183827
  _baseIsTypedArray_default = baseIsTypedArray;
183593
183828
  _baseUnary_default = baseUnary;
183594
- freeExports$1 = typeof exports_src_CYnAk7Cg_es == "object" && exports_src_CYnAk7Cg_es && !exports_src_CYnAk7Cg_es.nodeType && exports_src_CYnAk7Cg_es;
183595
- freeModule$1 = freeExports$1 && typeof module_src_CYnAk7Cg_es == "object" && module_src_CYnAk7Cg_es && !module_src_CYnAk7Cg_es.nodeType && module_src_CYnAk7Cg_es;
183829
+ freeExports$1 = typeof exports_src_eL3w4G7e_es == "object" && exports_src_eL3w4G7e_es && !exports_src_eL3w4G7e_es.nodeType && exports_src_eL3w4G7e_es;
183830
+ freeModule$1 = freeExports$1 && typeof module_src_eL3w4G7e_es == "object" && module_src_eL3w4G7e_es && !module_src_eL3w4G7e_es.nodeType && module_src_eL3w4G7e_es;
183596
183831
  freeProcess = freeModule$1 && freeModule$1.exports === freeExports$1 && _freeGlobal_default.process;
183597
183832
  _nodeUtil_default = function() {
183598
183833
  try {
@@ -183697,8 +183932,8 @@ function print() { __p += __j.call(arguments, '') }
183697
183932
  Stack.prototype.has = _stackHas_default;
183698
183933
  Stack.prototype.set = _stackSet_default;
183699
183934
  _Stack_default = Stack;
183700
- freeExports = typeof exports_src_CYnAk7Cg_es == "object" && exports_src_CYnAk7Cg_es && !exports_src_CYnAk7Cg_es.nodeType && exports_src_CYnAk7Cg_es;
183701
- freeModule = freeExports && typeof module_src_CYnAk7Cg_es == "object" && module_src_CYnAk7Cg_es && !module_src_CYnAk7Cg_es.nodeType && module_src_CYnAk7Cg_es;
183935
+ freeExports = typeof exports_src_eL3w4G7e_es == "object" && exports_src_eL3w4G7e_es && !exports_src_eL3w4G7e_es.nodeType && exports_src_eL3w4G7e_es;
183936
+ freeModule = freeExports && typeof module_src_eL3w4G7e_es == "object" && module_src_eL3w4G7e_es && !module_src_eL3w4G7e_es.nodeType && module_src_eL3w4G7e_es;
183702
183937
  Buffer4 = freeModule && freeModule.exports === freeExports ? _root_default.Buffer : undefined;
183703
183938
  allocUnsafe = Buffer4 ? Buffer4.allocUnsafe : undefined;
183704
183939
  _cloneBuffer_default = cloneBuffer;
@@ -191317,8 +191552,8 @@ var init_zipper_BJHqrQMq_es = __esm(() => {
191317
191552
 
191318
191553
  // ../../packages/superdoc/dist/super-editor.es.js
191319
191554
  var init_super_editor_es = __esm(() => {
191320
- init_src_CYnAk7Cg_es();
191321
- init_SuperConverter_D9XMPi6H_es();
191555
+ init_src_eL3w4G7e_es();
191556
+ init_SuperConverter_Cf1y7bFA_es();
191322
191557
  init_jszip_ChlR43oI_es();
191323
191558
  init_xml_js_DLE8mr0n_es();
191324
191559
  init_constants_DBKi0Amm_es();
@@ -219406,6 +219641,18 @@ var SKIP_FIELD_PROCESSING_NODE_NAMES3, shouldSkipFieldProcessing3 = (node3) => S
219406
219641
  i4++;
219407
219642
  continue;
219408
219643
  }
219644
+ const childElements = node3.elements || [];
219645
+ if (childElements.length > 0) {
219646
+ for (const child of childElements) {
219647
+ if (Array.isArray(child.elements)) {
219648
+ const childResult = preProcessPageFieldsOnly2(child.elements, depth + 1);
219649
+ child.elements = childResult.processedNodes;
219650
+ }
219651
+ processedNodes.push(child);
219652
+ }
219653
+ i4++;
219654
+ continue;
219655
+ }
219409
219656
  }
219410
219657
  if (fldType === "begin") {
219411
219658
  const fieldInfo = scanFieldSequence2(nodes, i4);
@@ -219431,6 +219678,13 @@ var SKIP_FIELD_PROCESSING_NODE_NAMES3, shouldSkipFieldProcessing3 = (node3) => S
219431
219678
  }
219432
219679
  }
219433
219680
  }
219681
+ if (node3.name === "w:r" && node3.elements?.some((el) => el.name === "w:pgNum")) {
219682
+ const rPr = node3.elements.find((el) => el.name === "w:rPr") || null;
219683
+ const processedField = preProcessPageInstruction2([], "", rPr);
219684
+ processedNodes.push(...processedField);
219685
+ i4++;
219686
+ continue;
219687
+ }
219434
219688
  if (Array.isArray(node3.elements)) {
219435
219689
  const childResult = preProcessPageFieldsOnly2(node3.elements, depth + 1);
219436
219690
  node3.elements = childResult.processedNodes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/cli",
3
- "version": "0.2.0-next.2",
3
+ "version": "0.2.0-next.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -28,11 +28,11 @@
28
28
  "access": "public"
29
29
  },
30
30
  "optionalDependencies": {
31
- "@superdoc-dev/cli-darwin-x64": "0.2.0-next.2",
32
- "@superdoc-dev/cli-darwin-arm64": "0.2.0-next.2",
33
- "@superdoc-dev/cli-linux-x64": "0.2.0-next.2",
34
- "@superdoc-dev/cli-windows-x64": "0.2.0-next.2",
35
- "@superdoc-dev/cli-linux-arm64": "0.2.0-next.2"
31
+ "@superdoc-dev/cli-darwin-arm64": "0.2.0-next.3",
32
+ "@superdoc-dev/cli-darwin-x64": "0.2.0-next.3",
33
+ "@superdoc-dev/cli-linux-arm64": "0.2.0-next.3",
34
+ "@superdoc-dev/cli-windows-x64": "0.2.0-next.3",
35
+ "@superdoc-dev/cli-linux-x64": "0.2.0-next.3"
36
36
  },
37
37
  "scripts": {
38
38
  "dev": "bun run src/index.ts",