superdoc 1.3.0-next.1 → 1.3.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35919,7 +35919,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35919
35919
  static getStoredSuperdocVersion(docx) {
35920
35920
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
35921
35921
  }
35922
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.1") {
35922
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.2") {
35923
35923
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
35924
35924
  }
35925
35925
  /**
@@ -61541,7 +61541,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61541
61541
  return false;
61542
61542
  }
61543
61543
  };
61544
- const summaryVersion = "1.3.0-next.1";
61544
+ const summaryVersion = "1.3.0-next.2";
61545
61545
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
61546
61546
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
61547
61547
  function mapAttributes(attrs) {
@@ -64175,7 +64175,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64175
64175
  * Process collaboration migrations
64176
64176
  */
64177
64177
  processCollaborationMigrations() {
64178
- console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.1");
64178
+ console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.2");
64179
64179
  if (!this.options.ydoc) return;
64180
64180
  const metaMap = this.options.ydoc.getMap("meta");
64181
64181
  let docVersion = metaMap.get("version");
@@ -66595,18 +66595,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66595
66595
  case "decimal":
66596
66596
  return num.toString();
66597
66597
  case "lowerLetter":
66598
- return toLetter$1(num, false);
66598
+ return toLetter(num, false);
66599
66599
  case "upperLetter":
66600
- return toLetter$1(num, true);
66600
+ return toLetter(num, true);
66601
66601
  case "lowerRoman":
66602
- return toRoman$2(num).toLowerCase();
66602
+ return toRoman$1(num).toLowerCase();
66603
66603
  case "upperRoman":
66604
- return toRoman$2(num);
66604
+ return toRoman$1(num);
66605
66605
  default:
66606
66606
  return num.toString();
66607
66607
  }
66608
66608
  }
66609
- function toLetter$1(num, uppercase) {
66609
+ function toLetter(num, uppercase) {
66610
66610
  let result = "";
66611
66611
  let n = num;
66612
66612
  while (n > 0) {
@@ -66617,7 +66617,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66617
66617
  }
66618
66618
  return result || (uppercase ? "A" : "a");
66619
66619
  }
66620
- function toRoman$2(num) {
66620
+ function toRoman$1(num) {
66621
66621
  const lookup = [
66622
66622
  [1e3, "M"],
66623
66623
  [900, "CM"],
@@ -72021,7 +72021,14 @@ ${l}
72021
72021
  fragmentEl.dataset.continuesOnNext = "true";
72022
72022
  }
72023
72023
  const lines = fragment.lines ?? measure.lines.slice(fragment.fromLine, fragment.toLine);
72024
- applyParagraphBlockStyles(fragmentEl, block.attrs);
72024
+ applyParagraphBlockStyles(fragmentEl, block.attrs, { includeBorders: false, includeShading: false });
72025
+ const { shadingLayer, borderLayer } = createParagraphDecorationLayers(this.doc, fragment.width, block.attrs);
72026
+ if (shadingLayer) {
72027
+ fragmentEl.appendChild(shadingLayer);
72028
+ }
72029
+ if (borderLayer) {
72030
+ fragmentEl.appendChild(borderLayer);
72031
+ }
72025
72032
  if (block.attrs?.styleId) {
72026
72033
  fragmentEl.dataset.styleId = block.attrs.styleId;
72027
72034
  fragmentEl.setAttribute("styleid", block.attrs.styleId);
@@ -72405,10 +72412,18 @@ ${l}
72405
72412
  contentEl.classList.add("superdoc-list-content");
72406
72413
  this.applySdtDataset(contentEl, paragraphMetadata);
72407
72414
  contentEl.style.display = "inline-block";
72415
+ contentEl.style.position = "relative";
72408
72416
  contentEl.style.width = `${fragment.width}px`;
72409
72417
  const lines = itemMeasure.paragraph.lines.slice(fragment.fromLine, fragment.toLine);
72410
72418
  const contentAttrs = wordLayout ? item.paragraph.attrs : stripListIndent(item.paragraph.attrs);
72411
- applyParagraphBlockStyles(contentEl, contentAttrs);
72419
+ applyParagraphBlockStyles(contentEl, contentAttrs, { includeBorders: false, includeShading: false });
72420
+ const { shadingLayer, borderLayer } = createParagraphDecorationLayers(this.doc, fragment.width, contentAttrs);
72421
+ if (shadingLayer) {
72422
+ contentEl.appendChild(shadingLayer);
72423
+ }
72424
+ if (borderLayer) {
72425
+ contentEl.appendChild(borderLayer);
72426
+ }
72412
72427
  contentEl.style.textAlign = "left";
72413
72428
  const paraForList = {
72414
72429
  ...item.paragraph,
@@ -74632,7 +74647,7 @@ ${l}
74632
74647
  }
74633
74648
  });
74634
74649
  };
74635
- const applyParagraphBlockStyles = (element2, attrs) => {
74650
+ const applyParagraphBlockStyles = (element2, attrs, options = {}) => {
74636
74651
  if (!attrs) return;
74637
74652
  if (attrs.styleId) {
74638
74653
  element2.setAttribute("styleid", attrs.styleId);
@@ -74659,8 +74674,55 @@ ${l}
74659
74674
  }
74660
74675
  }
74661
74676
  }
74662
- applyParagraphBorderStyles(element2, attrs.borders);
74663
- applyParagraphShadingStyles(element2, attrs.shading);
74677
+ if (options.includeBorders ?? true) {
74678
+ applyParagraphBorderStyles(element2, attrs.borders);
74679
+ }
74680
+ if (options.includeShading ?? true) {
74681
+ applyParagraphShadingStyles(element2, attrs.shading);
74682
+ }
74683
+ };
74684
+ const getParagraphBorderBox = (fragmentWidth, indent2) => {
74685
+ const indentLeft = Number.isFinite(indent2?.left) ? indent2.left : 0;
74686
+ const indentRight = Number.isFinite(indent2?.right) ? indent2.right : 0;
74687
+ const firstLine = Number.isFinite(indent2?.firstLine) ? indent2.firstLine : 0;
74688
+ const hanging = Number.isFinite(indent2?.hanging) ? indent2.hanging : 0;
74689
+ const firstLineOffset = firstLine - hanging;
74690
+ const minLeftInset = Math.min(indentLeft, indentLeft + firstLineOffset);
74691
+ const leftInset = Math.max(0, minLeftInset);
74692
+ const rightInset = Math.max(0, indentRight);
74693
+ return {
74694
+ leftInset,
74695
+ width: Math.max(0, fragmentWidth - leftInset - rightInset)
74696
+ };
74697
+ };
74698
+ const createParagraphDecorationLayers = (doc2, fragmentWidth, attrs) => {
74699
+ if (!attrs?.borders && !attrs?.shading) return {};
74700
+ const borderBox = getParagraphBorderBox(fragmentWidth, attrs.indent);
74701
+ const baseStyles = {
74702
+ position: "absolute",
74703
+ top: "0px",
74704
+ bottom: "0px",
74705
+ left: `${borderBox.leftInset}px`,
74706
+ width: `${borderBox.width}px`,
74707
+ pointerEvents: "none",
74708
+ boxSizing: "border-box"
74709
+ };
74710
+ let shadingLayer;
74711
+ if (attrs.shading) {
74712
+ shadingLayer = doc2.createElement("div");
74713
+ shadingLayer.classList.add("superdoc-paragraph-shading");
74714
+ Object.assign(shadingLayer.style, baseStyles);
74715
+ applyParagraphShadingStyles(shadingLayer, attrs.shading);
74716
+ }
74717
+ let borderLayer;
74718
+ if (attrs.borders) {
74719
+ borderLayer = doc2.createElement("div");
74720
+ borderLayer.classList.add("superdoc-paragraph-border");
74721
+ Object.assign(borderLayer.style, baseStyles);
74722
+ borderLayer.style.zIndex = "1";
74723
+ applyParagraphBorderStyles(borderLayer, attrs.borders);
74724
+ }
74725
+ return { shadingLayer, borderLayer };
74664
74726
  };
74665
74727
  const BORDER_SIDES = ["top", "right", "bottom", "left"];
74666
74728
  const applyParagraphBorderStyles = (element2, borders) => {
@@ -78311,33 +78373,13 @@ ${l}
78311
78373
  toLineByCell.push(cutLine);
78312
78374
  heightByCell.push(cumulativeHeight);
78313
78375
  }
78314
- const allCellsCompleteInFirstPass = toLineByCell.every((cutLine, idx) => {
78315
- const totalLines = getCellTotalLines(row2.cells[idx]);
78316
- return cutLine >= totalLines;
78317
- });
78318
- const lineAdvancements = toLineByCell.map((cutLine, idx) => cutLine - (startLines[idx] || 0));
78319
- const positiveAdvancements = lineAdvancements.filter((adv) => adv > 0);
78320
- const minLineAdvancement = positiveAdvancements.length > 0 ? Math.min(...positiveAdvancements) : 0;
78321
78376
  let actualPartialHeight = 0;
78322
78377
  let maxPaddingTotal = 0;
78323
78378
  for (let cellIdx = 0; cellIdx < cellCount; cellIdx++) {
78324
- const cell2 = row2.cells[cellIdx];
78325
- const startLine = startLines[cellIdx] || 0;
78326
- const lines = getCellLines(cell2);
78327
78379
  const cellPadding = cellPaddings[cellIdx];
78328
78380
  const paddingTotal = cellPadding.top + cellPadding.bottom;
78329
78381
  maxPaddingTotal = Math.max(maxPaddingTotal, paddingTotal);
78330
- if (allCellsCompleteInFirstPass) {
78331
- actualPartialHeight = Math.max(actualPartialHeight, heightByCell[cellIdx] + paddingTotal);
78332
- } else {
78333
- const targetLine = Math.min(startLine + minLineAdvancement, lines.length);
78334
- let cumulativeHeight = 0;
78335
- for (let i2 = startLine; i2 < targetLine; i2++) {
78336
- cumulativeHeight += lines[i2].lineHeight || 0;
78337
- }
78338
- toLineByCell[cellIdx] = targetLine;
78339
- actualPartialHeight = Math.max(actualPartialHeight, cumulativeHeight + paddingTotal);
78340
- }
78382
+ actualPartialHeight = Math.max(actualPartialHeight, heightByCell[cellIdx] + paddingTotal);
78341
78383
  }
78342
78384
  const madeProgress = toLineByCell.some((cutLine, idx) => cutLine > (startLines[idx] || 0));
78343
78385
  const isFirstPart = startLines.every((l) => l === 0);
@@ -78890,7 +78932,7 @@ ${l}
78890
78932
  function toLowerLetter(num) {
78891
78933
  return toUpperLetter(num).toLowerCase();
78892
78934
  }
78893
- function formatPageNumber$1(pageNumber, format) {
78935
+ function formatPageNumber(pageNumber, format) {
78894
78936
  const num = Math.max(1, pageNumber);
78895
78937
  switch (format) {
78896
78938
  case "decimal":
@@ -78903,6 +78945,8 @@ ${l}
78903
78945
  return toUpperLetter(num);
78904
78946
  case "lowerLetter":
78905
78947
  return toLowerLetter(num);
78948
+ case "numberInDash":
78949
+ return `-${num}-`;
78906
78950
  default:
78907
78951
  return String(num);
78908
78952
  }
@@ -78931,7 +78975,7 @@ ${l}
78931
78975
  const sectionMetadata = sectionMap.get(pageSectionIndex);
78932
78976
  const format = sectionMetadata?.numbering?.format ?? "decimal";
78933
78977
  const displayNumber = runningCounter;
78934
- const displayText = formatPageNumber$1(displayNumber, format);
78978
+ const displayText = formatPageNumber(displayNumber, format);
78935
78979
  result.push({
78936
78980
  physicalPage: page.number,
78937
78981
  displayNumber,
@@ -79067,59 +79111,6 @@ ${l}
79067
79111
  if (!layoutDebugEnabled$1) return;
79068
79112
  console.log(...args);
79069
79113
  };
79070
- function formatPageNumber(num, format) {
79071
- switch (format) {
79072
- case "decimal":
79073
- return String(num);
79074
- case "lowerLetter":
79075
- return toLetter(num, false);
79076
- case "upperLetter":
79077
- return toLetter(num, true);
79078
- case "lowerRoman":
79079
- return toRoman$1(num).toLowerCase();
79080
- case "upperRoman":
79081
- return toRoman$1(num);
79082
- default:
79083
- return String(num);
79084
- }
79085
- }
79086
- function toLetter(num, uppercase) {
79087
- let result = "";
79088
- let n = Math.max(1, Math.floor(num));
79089
- while (n > 0) {
79090
- const remainder = (n - 1) % 26;
79091
- const char = String.fromCharCode((uppercase ? 65 : 97) + remainder);
79092
- result = char + result;
79093
- n = Math.floor((n - 1) / 26);
79094
- }
79095
- return result;
79096
- }
79097
- function toRoman$1(num) {
79098
- const lookup = [
79099
- [1e3, "M"],
79100
- [900, "CM"],
79101
- [500, "D"],
79102
- [400, "CD"],
79103
- [100, "C"],
79104
- [90, "XC"],
79105
- [50, "L"],
79106
- [40, "XL"],
79107
- [10, "X"],
79108
- [9, "IX"],
79109
- [5, "V"],
79110
- [4, "IV"],
79111
- [1, "I"]
79112
- ];
79113
- let result = "";
79114
- let n = Math.max(1, Math.floor(num));
79115
- for (const [value, numeral] of lookup) {
79116
- while (n >= value) {
79117
- result += numeral;
79118
- n -= value;
79119
- }
79120
- }
79121
- return result;
79122
- }
79123
79114
  function layoutDocument(blocks2, measures, options = {}) {
79124
79115
  if (blocks2.length !== measures.length) {
79125
79116
  throw new Error(
@@ -80575,7 +80566,7 @@ ${l}
80575
80566
  return `${block.id}@${safeWidth}x${safeHeight}:${hash2}`;
80576
80567
  }
80577
80568
  }
80578
- function resolveHeaderFooterTokens(blocks2, pageNumber, totalPages) {
80569
+ function resolveHeaderFooterTokens(blocks2, pageNumber, totalPages, pageNumberText) {
80579
80570
  if (!blocks2 || blocks2.length === 0) {
80580
80571
  return;
80581
80572
  }
@@ -80587,7 +80578,7 @@ ${l}
80587
80578
  console.warn("[resolveHeaderFooterTokens] Invalid totalPages:", totalPages, "- using 1 as fallback");
80588
80579
  totalPages = 1;
80589
80580
  }
80590
- const pageNumberStr = String(pageNumber);
80581
+ const pageNumberStr = pageNumberText ?? String(pageNumber);
80591
80582
  const totalPagesStr = String(totalPages);
80592
80583
  for (const block of blocks2) {
80593
80584
  if (block.kind !== "paragraph") continue;
@@ -81011,15 +81002,31 @@ ${l}
81011
81002
  for (const pageNum of pagesToLayout) {
81012
81003
  const clonedBlocks = cloneHeaderFooterBlocks(blocks2);
81013
81004
  const { displayText, totalPages: totalPagesForPage } = pageResolver(pageNum);
81014
- const resolvedPageNum = parseInt(displayText, 10) || pageNum;
81015
- resolveHeaderFooterTokens(clonedBlocks, resolvedPageNum, totalPagesForPage);
81005
+ resolveHeaderFooterTokens(clonedBlocks, pageNum, totalPagesForPage, displayText);
81016
81006
  const measures = await cache2.measureBlocks(clonedBlocks, constraints, measureBlock2);
81017
81007
  const pageLayout = layoutHeaderFooter(clonedBlocks, measures, constraints);
81008
+ const measuresById = /* @__PURE__ */ new Map();
81009
+ for (let i2 = 0; i2 < clonedBlocks.length; i2 += 1) {
81010
+ measuresById.set(clonedBlocks[i2].id, measures[i2]);
81011
+ }
81012
+ const fragmentsWithLines = pageLayout.pages[0]?.fragments.map((fragment) => {
81013
+ if (fragment.kind !== "para") {
81014
+ return fragment;
81015
+ }
81016
+ const measure = measuresById.get(fragment.blockId);
81017
+ if (!measure || measure.kind !== "paragraph") {
81018
+ return fragment;
81019
+ }
81020
+ return {
81021
+ ...fragment,
81022
+ lines: measure.lines.slice(fragment.fromLine, fragment.toLine)
81023
+ };
81024
+ }) ?? [];
81018
81025
  pages.push({
81019
81026
  number: pageNum,
81020
81027
  blocks: clonedBlocks,
81021
81028
  measures,
81022
- fragments: pageLayout.pages[0]?.fragments ?? []
81029
+ fragments: fragmentsWithLines
81023
81030
  });
81024
81031
  }
81025
81032
  const firstPageLayout = pages[0] ? layoutHeaderFooter(pages[0].blocks, pages[0].measures, constraints) : { height: 0 };
@@ -85898,7 +85905,14 @@ ${l}
85898
85905
  const pgNumType = elements.find((el) => el?.name === "w:pgNumType");
85899
85906
  if (!pgNumType?.attributes) return void 0;
85900
85907
  const fmtRaw = pgNumType.attributes["w:fmt"];
85901
- const validFormats = ["decimal", "lowerLetter", "upperLetter", "lowerRoman", "upperRoman"];
85908
+ const validFormats = [
85909
+ "decimal",
85910
+ "lowerLetter",
85911
+ "upperLetter",
85912
+ "lowerRoman",
85913
+ "upperRoman",
85914
+ "numberInDash"
85915
+ ];
85902
85916
  const fmt = validFormats.includes(fmtRaw) ? fmtRaw : void 0;
85903
85917
  const startRaw = pgNumType.attributes["w:start"];
85904
85918
  const startNum = startRaw != null ? Number(startRaw) : void 0;
@@ -143178,7 +143192,7 @@ ${reason}`);
143178
143192
  this.config.colors = shuffleArray(this.config.colors);
143179
143193
  this.userColorMap = /* @__PURE__ */ new Map();
143180
143194
  this.colorIndex = 0;
143181
- this.version = "1.3.0-next.1";
143195
+ this.version = "1.3.0-next.2";
143182
143196
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
143183
143197
  this.superdocId = config2.superdocId || v4();
143184
143198
  this.colors = this.config.colors;