@harbour-enterprises/superdoc 1.0.0-beta.87 → 1.0.0-beta.89

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 (27) hide show
  1. package/dist/chunks/{PdfViewer-Cwmc4rak.cjs → PdfViewer-64l7m5Lq.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-DAayAt76.es.js → PdfViewer-Dj0ADYo6.es.js} +1 -1
  3. package/dist/chunks/{index-huIbWXSg.cjs → index-Cnq_7qcp.cjs} +3 -3
  4. package/dist/chunks/{index-BV2SxVfK.es.js → index-DXKu3E-3.es.js} +3 -3
  5. package/dist/chunks/{index-rv7o9043-DVlRSGhv.es.js → index-DcTrJ8db-9XJOggtC.es.js} +1 -1
  6. package/dist/chunks/{index-rv7o9043-DD5SvBoC.cjs → index-DcTrJ8db-kUMXGs8M.cjs} +1 -1
  7. package/dist/chunks/{super-editor.es-BuujpqOr.es.js → super-editor.es-D0fgEP38.es.js} +297 -68
  8. package/dist/chunks/{super-editor.es-C43B4f8Z.cjs → super-editor.es-D8F0msfn.cjs} +297 -68
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-G519mwN2.js → converter-DPyEmTPY.js} +1 -1
  11. package/dist/super-editor/chunks/{docx-zipper-CHfjJ_h-.js → docx-zipper-BTkZSGvz.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-BQsR9BR1.js → editor-4iR-p-_J.js} +293 -64
  13. package/dist/super-editor/chunks/{index-rv7o9043.js → index-DcTrJ8db.js} +1 -1
  14. package/dist/super-editor/chunks/{toolbar-DNfQq2Cl.js → toolbar-Dx7gHXE2.js} +2 -2
  15. package/dist/super-editor/converter.es.js +1 -1
  16. package/dist/super-editor/docx-zipper.es.js +2 -2
  17. package/dist/super-editor/editor.es.js +3 -3
  18. package/dist/super-editor/file-zipper.es.js +1 -1
  19. package/dist/super-editor/super-editor.es.js +6 -6
  20. package/dist/super-editor/toolbar.es.js +2 -2
  21. package/dist/super-editor.cjs +1 -1
  22. package/dist/super-editor.es.js +1 -1
  23. package/dist/superdoc.cjs +2 -2
  24. package/dist/superdoc.es.js +2 -2
  25. package/dist/superdoc.umd.js +299 -70
  26. package/dist/superdoc.umd.js.map +1 -1
  27. package/package.json +1 -1
@@ -19632,9 +19632,9 @@
19632
19632
  const { spacing, indent: indent2, borders, justification } = paragraphProperties;
19633
19633
  const nextStyleId = nextParagraphProps?.styleId;
19634
19634
  if (spacing) {
19635
- const getEffectiveBefore = (nextSpacing, isListItem) => {
19635
+ const getEffectiveBefore = (nextSpacing, isListItem2) => {
19636
19636
  if (!nextSpacing) return 0;
19637
- if (nextSpacing.beforeAutospacing && isListItem) {
19637
+ if (nextSpacing.beforeAutospacing && isListItem2) {
19638
19638
  return 0;
19639
19639
  }
19640
19640
  return nextSpacing.before || 0;
@@ -20015,7 +20015,7 @@
20015
20015
  }
20016
20016
  String(value).split(/\s+/).map((entry) => entry.trim()).filter(Boolean).forEach((entry) => targetSet.add(entry));
20017
20017
  }
20018
- const getSpacingStyle = (spacing, isListItem) => {
20018
+ const getSpacingStyle = (spacing, isListItem2) => {
20019
20019
  let { before, after, line, lineRule, beforeAutospacing, afterAutospacing } = spacing;
20020
20020
  line = twipsToLines(line);
20021
20021
  if (line != null && line < 1) {
@@ -20026,13 +20026,13 @@
20026
20026
  }
20027
20027
  before = twipsToPixels$2(before);
20028
20028
  if (beforeAutospacing) {
20029
- if (isListItem) {
20029
+ if (isListItem2) {
20030
20030
  before = 0;
20031
20031
  }
20032
20032
  }
20033
20033
  after = twipsToPixels$2(after);
20034
20034
  if (afterAutospacing) {
20035
- if (isListItem) {
20035
+ if (isListItem2) {
20036
20036
  after = 0;
20037
20037
  }
20038
20038
  }
@@ -42398,7 +42398,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
42398
42398
  static getStoredSuperdocVersion(docx) {
42399
42399
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42400
42400
  }
42401
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.87") {
42401
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.89") {
42402
42402
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42403
42403
  }
42404
42404
  /**
@@ -67461,7 +67461,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67461
67461
  const shouldSkipNodeView = (editor) => {
67462
67462
  return isHeadless(editor);
67463
67463
  };
67464
- const summaryVersion = "1.0.0-beta.87";
67464
+ const summaryVersion = "1.0.0-beta.89";
67465
67465
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
67466
67466
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
67467
67467
  function mapAttributes(attrs) {
@@ -68250,7 +68250,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
68250
68250
  { default: remarkStringify2 },
68251
68251
  { default: remarkGfm2 }
68252
68252
  ] = await Promise.all([
68253
- Promise.resolve().then(() => indexRv7o9043),
68253
+ Promise.resolve().then(() => indexDcTrJ8db),
68254
68254
  Promise.resolve().then(() => indexDRCvimau),
68255
68255
  Promise.resolve().then(() => indexC_x_N6Uh),
68256
68256
  Promise.resolve().then(() => indexD_sWOSiG),
@@ -68455,7 +68455,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
68455
68455
  * Process collaboration migrations
68456
68456
  */
68457
68457
  processCollaborationMigrations() {
68458
- console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.87");
68458
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.89");
68459
68459
  if (!this.options.ydoc) return;
68460
68460
  const metaMap = this.options.ydoc.getMap("meta");
68461
68461
  let docVersion = metaMap.get("version");
@@ -81367,7 +81367,14 @@ ${l}
81367
81367
  let renderedHeight = 0;
81368
81368
  for (let lineIdx = localStartLine; lineIdx < localEndLine && lineIdx < lines.length; lineIdx++) {
81369
81369
  const line = lines[lineIdx];
81370
- const lineEl = renderLine(block, line, { ...context, section: "body" });
81370
+ const isLastLine = lineIdx === lines.length - 1;
81371
+ const lineEl = renderLine(
81372
+ block,
81373
+ line,
81374
+ { ...context, section: "body" },
81375
+ lineIdx,
81376
+ isLastLine
81377
+ );
81371
81378
  lineEl.style.paddingLeft = "";
81372
81379
  lineEl.style.paddingRight = "";
81373
81380
  lineEl.style.textIndent = "";
@@ -83999,8 +84006,11 @@ ${l}
83999
84006
  const applyFragmentFrameWithSection = (el, frag) => {
84000
84007
  this.applyFragmentFrame(el, frag, context.section);
84001
84008
  };
84002
- const renderLineForTableCell = (block, line, ctx2) => {
84003
- return this.renderLine(block, line, ctx2, void 0, void 0, true);
84009
+ const renderLineForTableCell = (block, line, ctx2, lineIndex, isLastLine) => {
84010
+ const lastRun = block.runs.length > 0 ? block.runs[block.runs.length - 1] : null;
84011
+ const paragraphEndsWithLineBreak = lastRun?.kind === "lineBreak";
84012
+ const shouldSkipJustify = isLastLine && !paragraphEndsWithLineBreak;
84013
+ return this.renderLine(block, line, ctx2, void 0, lineIndex, shouldSkipJustify);
84004
84014
  };
84005
84015
  const renderDrawingContentForTableCell = (block) => {
84006
84016
  if (block.drawingKind === "image") {
@@ -84609,9 +84619,10 @@ ${l}
84609
84619
  el.setAttribute("styleid", styleId);
84610
84620
  }
84611
84621
  const alignment2 = block.attrs?.alignment;
84612
- if (alignment2 === "center" || alignment2 === "right") {
84613
- el.style.textAlign = alignment2;
84614
- } else if (alignment2 === "justify") {
84622
+ const effectiveAlignment = alignment2;
84623
+ if (effectiveAlignment === "center" || effectiveAlignment === "right") {
84624
+ el.style.textAlign = effectiveAlignment;
84625
+ } else if (effectiveAlignment === "justify") {
84615
84626
  el.style.textAlign = "left";
84616
84627
  } else {
84617
84628
  el.style.textAlign = "left";
@@ -84673,16 +84684,16 @@ ${l}
84673
84684
  }
84674
84685
  const hasExplicitPositioning = line.segments?.some((seg) => seg.x !== void 0);
84675
84686
  const availableWidth = availableWidthOverride ?? line.maxWidth ?? line.width;
84676
- const shouldJustify = !skipJustify && alignment2 === "justify" && !hasExplicitPositioning;
84687
+ const shouldJustify = !skipJustify && effectiveAlignment === "justify" && !hasExplicitPositioning;
84677
84688
  if (shouldJustify) {
84678
84689
  const spaceCount = textSlices.reduce(
84679
84690
  (sum, s2) => sum + Array.from(s2).filter((ch) => ch === " " || ch === " ").length,
84680
84691
  0
84681
84692
  );
84682
- const slack = Math.max(0, availableWidth - line.width);
84683
- if (spaceCount > 0 && slack > 0) {
84684
- const extraPerSpace = slack / spaceCount;
84685
- el.style.wordSpacing = `${extraPerSpace}px`;
84693
+ const slack = availableWidth - line.width;
84694
+ if (spaceCount > 0 && slack !== 0) {
84695
+ const spacingPerSpace = slack / spaceCount;
84696
+ el.style.wordSpacing = `${spacingPerSpace}px`;
84686
84697
  }
84687
84698
  }
84688
84699
  if (hasExplicitPositioning && line.segments) {
@@ -86143,6 +86154,50 @@ ${l}
86143
86154
  }
86144
86155
  return index2;
86145
86156
  }
86157
+ function getWordLayoutConfig(block) {
86158
+ if (!block || block.kind !== "paragraph") {
86159
+ return void 0;
86160
+ }
86161
+ return block.attrs?.wordLayout;
86162
+ }
86163
+ function isListItem(markerWidth, block) {
86164
+ const hasMarkerWidth = markerWidth > 0;
86165
+ if (hasMarkerWidth) {
86166
+ return true;
86167
+ }
86168
+ if (!block || block.kind !== "paragraph") {
86169
+ return false;
86170
+ }
86171
+ const wordLayout = getWordLayoutConfig(block);
86172
+ const hasListAttrs = block.attrs?.listItem != null || wordLayout?.marker != null;
86173
+ if (hasListAttrs) {
86174
+ return true;
86175
+ }
86176
+ const hangingIndent = block.attrs?.indent?.hanging ?? 0;
86177
+ const paraIndentLeft = block.attrs?.indent?.left ?? 0;
86178
+ const hasHangingIndentPattern = hangingIndent > 0 && paraIndentLeft > 0;
86179
+ return hasHangingIndentPattern;
86180
+ }
86181
+ function calculateTextStartIndent(params2) {
86182
+ const { isFirstLine, isListItem: isListItem2, markerWidth, paraIndentLeft, firstLineIndent, hangingIndent, wordLayout } = params2;
86183
+ const firstLineOffset = firstLineIndent - hangingIndent;
86184
+ const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
86185
+ let indentAdjust = paraIndentLeft;
86186
+ if (isListItem2 && isFirstLine && isFirstLineIndentMode) {
86187
+ const textStartFallback = paraIndentLeft + Math.max(firstLineIndent, 0) + markerWidth;
86188
+ indentAdjust = typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : textStartFallback;
86189
+ } else if (isFirstLine && !isListItem2) {
86190
+ indentAdjust += firstLineOffset;
86191
+ }
86192
+ return indentAdjust;
86193
+ }
86194
+ function extractParagraphIndent(indent2) {
86195
+ const left2 = typeof indent2?.left === "number" && Number.isFinite(indent2.left) ? indent2.left : 0;
86196
+ const right2 = typeof indent2?.right === "number" && Number.isFinite(indent2.right) ? indent2.right : 0;
86197
+ const firstLine = typeof indent2?.firstLine === "number" && Number.isFinite(indent2.firstLine) ? indent2.firstLine : 0;
86198
+ const hanging = typeof indent2?.hanging === "number" && Number.isFinite(indent2.hanging) ? indent2.hanging : 0;
86199
+ return { left: left2, right: right2, firstLine, hanging };
86200
+ }
86146
86201
  const defaultHeaderFooterIdentifier = () => ({
86147
86202
  headerIds: { default: null, first: null, even: null, odd: null },
86148
86203
  footerIds: { default: null, first: null, even: null, odd: null },
@@ -91154,8 +91209,8 @@ ${l}
91154
91209
  );
91155
91210
  }
91156
91211
  const markerWidth = fragment.markerWidth ?? measure.marker?.markerWidth ?? 0;
91157
- const isListItem = markerWidth > 0;
91158
- const alignmentOverride = isListItem ? "left" : void 0;
91212
+ const isListItem3 = markerWidth > 0;
91213
+ const alignmentOverride = isListItem3 ? "left" : void 0;
91159
91214
  const pos = mapPointToPm(block, line, pageRelativePoint.x - fragment.x, isRTL, availableWidth, alignmentOverride);
91160
91215
  if (pos == null) {
91161
91216
  logClickStage("warn", "no-position", {
@@ -91199,8 +91254,8 @@ ${l}
91199
91254
  );
91200
91255
  }
91201
91256
  const cellMarkerWidth = cellMeasure.marker?.markerWidth ?? 0;
91202
- const isListItem = cellMarkerWidth > 0;
91203
- const alignmentOverride = isListItem ? "left" : void 0;
91257
+ const isListItem3 = cellMarkerWidth > 0;
91258
+ const alignmentOverride = isListItem3 ? "left" : void 0;
91204
91259
  const pos = mapPointToPm(cellBlock, line, localX, isRTL, availableWidth, alignmentOverride);
91205
91260
  if (pos != null) {
91206
91261
  logClickStage("log", "success", {
@@ -91358,17 +91413,22 @@ ${l}
91358
91413
  const charOffsetFrom = pmPosToCharOffset(block, line, sliceFrom);
91359
91414
  const charOffsetTo = pmPosToCharOffset(block, line, sliceTo);
91360
91415
  const markerWidth = fragment.markerWidth ?? measure.marker?.markerWidth ?? 0;
91361
- const isListItem = markerWidth > 0;
91362
- const alignmentOverride = isListItem ? "left" : void 0;
91416
+ const isListItemFlag = isListItem(markerWidth, block);
91417
+ const alignmentOverride = isListItemFlag ? "left" : void 0;
91363
91418
  const startX = mapPmToX(block, line, charOffsetFrom, fragment.width, alignmentOverride);
91364
91419
  const endX = mapPmToX(block, line, charOffsetTo, fragment.width, alignmentOverride);
91365
- const paraIndentLeft = block.attrs?.indent?.left ?? 0;
91366
- const firstLineOffset = (block.attrs?.indent?.firstLine ?? 0) - (block.attrs?.indent?.hanging ?? 0);
91420
+ const indent2 = extractParagraphIndent(block.attrs?.indent);
91421
+ const wordLayout = getWordLayoutConfig(block);
91367
91422
  const isFirstLine = index2 === fragment.fromLine;
91368
- let indentAdjust = paraIndentLeft;
91369
- if (isFirstLine && !isListItem) {
91370
- indentAdjust += firstLineOffset;
91371
- }
91423
+ const indentAdjust = calculateTextStartIndent({
91424
+ isFirstLine,
91425
+ isListItem: isListItemFlag,
91426
+ markerWidth,
91427
+ paraIndentLeft: indent2.left,
91428
+ firstLineIndent: indent2.firstLine,
91429
+ hangingIndent: indent2.hanging,
91430
+ wordLayout
91431
+ });
91372
91432
  const rectX = fragment.x + indentAdjust + Math.min(startX, endX);
91373
91433
  const rectWidth = Math.max(1, Math.abs(endX - startX));
91374
91434
  const lineOffset = lineHeightBeforeIndex(measure, index2) - lineHeightBeforeIndex(measure, fragment.fromLine);
@@ -91471,9 +91531,12 @@ ${l}
91471
91531
  let blockTopCursor = padding.top + verticalOffset;
91472
91532
  renderedBlocks.forEach((info) => {
91473
91533
  const paragraphMarkerWidth = info.measure.marker?.markerWidth ?? 0;
91474
- const isListItem = paragraphMarkerWidth > 0;
91475
- const alignmentOverride = isListItem ? "left" : void 0;
91476
- const paraIndentLeft = info.block.kind === "paragraph" ? info.block.attrs?.indent?.left ?? 0 : 0;
91534
+ const cellIsListItem = isListItem(paragraphMarkerWidth, info.block);
91535
+ const alignmentOverride = cellIsListItem ? "left" : void 0;
91536
+ const cellIndent = extractParagraphIndent(
91537
+ info.block.kind === "paragraph" ? info.block.attrs?.indent : void 0
91538
+ );
91539
+ const cellWordLayout = getWordLayoutConfig(info.block);
91477
91540
  const intersectingLines = findLinesIntersectingRange(info.block, info.measure, from2, to);
91478
91541
  intersectingLines.forEach(({ line, index: index2 }) => {
91479
91542
  if (index2 < info.startLine || index2 >= info.endLine) {
@@ -91489,7 +91552,17 @@ ${l}
91489
91552
  const availableWidth = Math.max(1, cellMeasure.width - padding.left - padding.right);
91490
91553
  const startX = mapPmToX(info.block, line, charOffsetFrom, availableWidth, alignmentOverride);
91491
91554
  const endX = mapPmToX(info.block, line, charOffsetTo, availableWidth, alignmentOverride);
91492
- const rectX = fragment.x + cellX + padding.left + paraIndentLeft + Math.min(startX, endX);
91555
+ const isFirstLine = index2 === info.startLine;
91556
+ const textIndentAdjust = calculateTextStartIndent({
91557
+ isFirstLine,
91558
+ isListItem: cellIsListItem,
91559
+ markerWidth: paragraphMarkerWidth,
91560
+ paraIndentLeft: cellIndent.left,
91561
+ firstLineIndent: cellIndent.firstLine,
91562
+ hangingIndent: cellIndent.hanging,
91563
+ wordLayout: cellWordLayout
91564
+ });
91565
+ const rectX = fragment.x + cellX + padding.left + textIndentAdjust + Math.min(startX, endX);
91493
91566
  const rectWidth = Math.max(1, Math.abs(endX - startX));
91494
91567
  const lineOffset = lineHeightBeforeIndex(info.measure, index2) - lineHeightBeforeIndex(info.measure, info.startLine);
91495
91568
  const rectY = fragment.y + rowOffset + blockTopCursor + lineOffset;
@@ -91861,9 +91934,7 @@ ${l}
91861
91934
  try {
91862
91935
  ctx2.font = font;
91863
91936
  const metrics = ctx2.measureText(text2);
91864
- const advanceWidth = metrics.width;
91865
- const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
91866
- const baseWidth = Math.max(advanceWidth, paintedWidth);
91937
+ const baseWidth = metrics.width;
91867
91938
  const extra = letterSpacing ? Math.max(0, text2.length - 1) * letterSpacing : 0;
91868
91939
  const width = baseWidth + extra;
91869
91940
  cache$1$1.set(key2, { width });
@@ -92072,7 +92143,8 @@ ${l}
92072
92143
  const isWordLayoutList = Boolean(wordLayout?.marker);
92073
92144
  const suppressFirstLine = block.attrs?.suppressFirstLineIndent === true;
92074
92145
  const rawFirstLineOffset = suppressFirstLine ? 0 : firstLine - hanging;
92075
- const firstLineOffset = isWordLayoutList ? 0 : rawFirstLineOffset;
92146
+ const clampedFirstLineOffset = Math.max(0, rawFirstLineOffset);
92147
+ const firstLineOffset = isWordLayoutList ? 0 : clampedFirstLineOffset;
92076
92148
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
92077
92149
  let leftJustifiedMarkerSpace = 0;
92078
92150
  if (wordLayout?.marker) {
@@ -92225,7 +92297,8 @@ ${l}
92225
92297
  if (run2.kind === "break") {
92226
92298
  if (currentLine) {
92227
92299
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
92228
- const completedLine = { ...currentLine, ...metrics };
92300
+ const { spaceCount: _sc, ...lineBase } = currentLine;
92301
+ const completedLine = { ...lineBase, ...metrics };
92229
92302
  addBarTabsToLine(completedLine);
92230
92303
  lines.push(completedLine);
92231
92304
  currentLine = null;
@@ -92286,7 +92359,8 @@ ${l}
92286
92359
  width: 0,
92287
92360
  maxFontSize: lastFontSize,
92288
92361
  maxWidth: nextLineMaxWidth,
92289
- segments: []
92362
+ segments: [],
92363
+ spaceCount: 0
92290
92364
  };
92291
92365
  tabStopCursor = 0;
92292
92366
  pendingTabAlignment = null;
@@ -92304,7 +92378,8 @@ ${l}
92304
92378
  maxFontSize: 12,
92305
92379
  // Default font size for tabs
92306
92380
  maxWidth: getEffectiveWidth(initialAvailableWidth),
92307
- segments: []
92381
+ segments: [],
92382
+ spaceCount: 0
92308
92383
  };
92309
92384
  }
92310
92385
  const originX = currentLine.width;
@@ -92353,6 +92428,7 @@ ${l}
92353
92428
  maxFontSize: imageHeight,
92354
92429
  // Use image height for line height calculation
92355
92430
  maxWidth: getEffectiveWidth(initialAvailableWidth),
92431
+ spaceCount: 0,
92356
92432
  segments: [
92357
92433
  {
92358
92434
  runIndex,
@@ -92368,8 +92444,9 @@ ${l}
92368
92444
  const appliedTabAlign = lastAppliedTabAlign;
92369
92445
  if (currentLine.width + imageWidth > currentLine.maxWidth && currentLine.width > 0) {
92370
92446
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
92447
+ const { spaceCount: _sc, ...lineBase } = currentLine;
92371
92448
  const completedLine = {
92372
- ...currentLine,
92449
+ ...lineBase,
92373
92450
  ...metrics
92374
92451
  };
92375
92452
  addBarTabsToLine(completedLine);
@@ -92385,6 +92462,7 @@ ${l}
92385
92462
  width: imageWidth,
92386
92463
  maxFontSize: imageHeight,
92387
92464
  maxWidth: getEffectiveWidth(contentWidth),
92465
+ spaceCount: 0,
92388
92466
  segments: [
92389
92467
  {
92390
92468
  runIndex,
@@ -92440,6 +92518,7 @@ ${l}
92440
92518
  width: annotationWidth,
92441
92519
  maxFontSize: annotationHeight,
92442
92520
  maxWidth: getEffectiveWidth(initialAvailableWidth),
92521
+ spaceCount: 0,
92443
92522
  segments: [
92444
92523
  {
92445
92524
  runIndex,
@@ -92454,8 +92533,9 @@ ${l}
92454
92533
  }
92455
92534
  if (currentLine.width + annotationWidth > currentLine.maxWidth && currentLine.width > 0) {
92456
92535
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
92536
+ const { spaceCount: _sc, ...lineBase } = currentLine;
92457
92537
  const completedLine = {
92458
- ...currentLine,
92538
+ ...lineBase,
92459
92539
  ...metrics
92460
92540
  };
92461
92541
  addBarTabsToLine(completedLine);
@@ -92471,6 +92551,7 @@ ${l}
92471
92551
  width: annotationWidth,
92472
92552
  maxFontSize: annotationHeight,
92473
92553
  maxWidth: getEffectiveWidth(contentWidth),
92554
+ spaceCount: 0,
92474
92555
  segments: [
92475
92556
  {
92476
92557
  runIndex,
@@ -92526,14 +92607,16 @@ ${l}
92526
92607
  maxFontSize: run2.fontSize,
92527
92608
  maxFontInfo: getFontInfoFromRun(run2),
92528
92609
  maxWidth: getEffectiveWidth(initialAvailableWidth),
92529
- segments: [{ runIndex, fromChar: spacesStartChar, toChar: spacesEndChar, width: spacesWidth }]
92610
+ segments: [{ runIndex, fromChar: spacesStartChar, toChar: spacesEndChar, width: spacesWidth }],
92611
+ spaceCount: spacesLength
92530
92612
  };
92531
92613
  } else {
92532
92614
  const boundarySpacing = currentLine.width > 0 ? run2.letterSpacing ?? 0 : 0;
92533
92615
  if (currentLine.width + boundarySpacing + spacesWidth > currentLine.maxWidth - WIDTH_FUDGE_PX && currentLine.width > 0) {
92534
92616
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
92617
+ const { spaceCount: _sc, ...lineBase } = currentLine;
92535
92618
  const completedLine = {
92536
- ...currentLine,
92619
+ ...lineBase,
92537
92620
  ...metrics
92538
92621
  };
92539
92622
  addBarTabsToLine(completedLine);
@@ -92550,7 +92633,8 @@ ${l}
92550
92633
  maxFontSize: run2.fontSize,
92551
92634
  maxFontInfo: getFontInfoFromRun(run2),
92552
92635
  maxWidth: getEffectiveWidth(contentWidth),
92553
- segments: [{ runIndex, fromChar: spacesStartChar, toChar: spacesEndChar, width: spacesWidth }]
92636
+ segments: [{ runIndex, fromChar: spacesStartChar, toChar: spacesEndChar, width: spacesWidth }],
92637
+ spaceCount: spacesLength
92554
92638
  };
92555
92639
  } else {
92556
92640
  currentLine.toRun = runIndex;
@@ -92559,6 +92643,7 @@ ${l}
92559
92643
  currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
92560
92644
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, run2.fontSize);
92561
92645
  appendSegment(currentLine.segments, runIndex, spacesStartChar, spacesEndChar, spacesWidth);
92646
+ currentLine.spaceCount += spacesLength;
92562
92647
  }
92563
92648
  }
92564
92649
  charPosInRun = spacesEndChar;
@@ -92575,7 +92660,56 @@ ${l}
92575
92660
  for (let wordIndex = 0; wordIndex < words.length; wordIndex++) {
92576
92661
  const word = words[wordIndex];
92577
92662
  if (word === "") {
92578
- charPosInRun += 1;
92663
+ const spaceStartChar = charPosInRun;
92664
+ const spaceEndChar = charPosInRun + 1;
92665
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2);
92666
+ if (!currentLine) {
92667
+ currentLine = {
92668
+ fromRun: runIndex,
92669
+ fromChar: spaceStartChar,
92670
+ toRun: runIndex,
92671
+ toChar: spaceEndChar,
92672
+ width: singleSpaceWidth,
92673
+ maxFontSize: run2.fontSize,
92674
+ maxFontInfo: getFontInfoFromRun(run2),
92675
+ maxWidth: getEffectiveWidth(initialAvailableWidth),
92676
+ segments: [{ runIndex, fromChar: spaceStartChar, toChar: spaceEndChar, width: singleSpaceWidth }],
92677
+ spaceCount: 1
92678
+ };
92679
+ } else {
92680
+ const boundarySpacing2 = currentLine.width > 0 ? run2.letterSpacing ?? 0 : 0;
92681
+ if (currentLine.width + boundarySpacing2 + singleSpaceWidth > currentLine.maxWidth - WIDTH_FUDGE_PX && currentLine.width > 0) {
92682
+ const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
92683
+ const { spaceCount: _sc, ...lineBase } = currentLine;
92684
+ const completedLine = { ...lineBase, ...metrics };
92685
+ addBarTabsToLine(completedLine);
92686
+ lines.push(completedLine);
92687
+ tabStopCursor = 0;
92688
+ pendingTabAlignment = null;
92689
+ lastAppliedTabAlign = null;
92690
+ currentLine = {
92691
+ fromRun: runIndex,
92692
+ fromChar: spaceStartChar,
92693
+ toRun: runIndex,
92694
+ toChar: spaceEndChar,
92695
+ width: singleSpaceWidth,
92696
+ maxFontSize: run2.fontSize,
92697
+ maxFontInfo: getFontInfoFromRun(run2),
92698
+ maxWidth: getEffectiveWidth(contentWidth),
92699
+ segments: [{ runIndex, fromChar: spaceStartChar, toChar: spaceEndChar, width: singleSpaceWidth }],
92700
+ spaceCount: 1
92701
+ };
92702
+ } else {
92703
+ currentLine.toRun = runIndex;
92704
+ currentLine.toChar = spaceEndChar;
92705
+ currentLine.width = roundValue(currentLine.width + boundarySpacing2 + singleSpaceWidth);
92706
+ currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
92707
+ currentLine.maxFontSize = Math.max(currentLine.maxFontSize, run2.fontSize);
92708
+ appendSegment(currentLine.segments, runIndex, spaceStartChar, spaceEndChar, singleSpaceWidth);
92709
+ currentLine.spaceCount += 1;
92710
+ }
92711
+ }
92712
+ charPosInRun = spaceEndChar;
92579
92713
  continue;
92580
92714
  }
92581
92715
  const isLastWordInSegment = wordIndex === words.length - 1;
@@ -92596,13 +92730,15 @@ ${l}
92596
92730
  maxFontSize: run2.fontSize,
92597
92731
  maxFontInfo: getFontInfoFromRun(run2),
92598
92732
  maxWidth: getEffectiveWidth(initialAvailableWidth),
92599
- segments: [{ runIndex, fromChar: wordStartChar, toChar: wordEndNoSpace, width: wordOnlyWidth }]
92733
+ segments: [{ runIndex, fromChar: wordStartChar, toChar: wordEndNoSpace, width: wordOnlyWidth }],
92734
+ spaceCount: 0
92600
92735
  };
92601
92736
  const ls = run2.letterSpacing ?? 0;
92602
92737
  if (!isLastWord && currentLine.width + spaceWidth <= currentLine.maxWidth - WIDTH_FUDGE_PX) {
92603
92738
  currentLine.toChar = wordEndWithSpace;
92604
92739
  currentLine.width = roundValue(currentLine.width + spaceWidth + ls);
92605
92740
  charPosInRun = wordEndWithSpace;
92741
+ currentLine.spaceCount += 1;
92606
92742
  } else {
92607
92743
  charPosInRun = wordEndWithSpace;
92608
92744
  }
@@ -92610,10 +92746,36 @@ ${l}
92610
92746
  }
92611
92747
  const isTocEntry = block.attrs?.isTocEntry;
92612
92748
  const boundarySpacing = currentLine.width > 0 ? run2.letterSpacing ?? 0 : 0;
92613
- if (currentLine.width + boundarySpacing + wordOnlyWidth > currentLine.maxWidth - WIDTH_FUDGE_PX && currentLine.width > 0 && !isTocEntry) {
92749
+ const justifyAlignment = block.attrs?.alignment === "justify";
92750
+ const totalWidthWithWord = currentLine.width + boundarySpacing + wordCommitWidth + // Safe cast: only TextRuns produce word segments from split(), other run types are handled earlier
92751
+ (isLastWord ? 0 : run2.letterSpacing ?? 0);
92752
+ const availableWidth = currentLine.maxWidth - WIDTH_FUDGE_PX;
92753
+ let shouldBreak = currentLine.width + boundarySpacing + wordOnlyWidth > availableWidth && currentLine.width > 0 && !isTocEntry;
92754
+ let compressedWidth = null;
92755
+ if (shouldBreak && justifyAlignment) {
92756
+ const isParagraphLastWord = isLastWord && runIndex === runsToProcess.length - 1;
92757
+ if (!isParagraphLastWord) {
92758
+ const existingSpaces = currentLine.spaceCount ?? 0;
92759
+ const candidateSpaces = existingSpaces + (isLastWord ? 0 : 1);
92760
+ if (candidateSpaces > 0) {
92761
+ const overflow = totalWidthWithWord - availableWidth;
92762
+ if (overflow > 0) {
92763
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2) || Math.max(1, boundarySpacing);
92764
+ const perSpaceCompression = overflow / candidateSpaces;
92765
+ const maxPerSpaceCompression = baseSpaceWidth * 0.25;
92766
+ if (perSpaceCompression <= maxPerSpaceCompression) {
92767
+ shouldBreak = false;
92768
+ compressedWidth = availableWidth;
92769
+ }
92770
+ }
92771
+ }
92772
+ }
92773
+ }
92774
+ if (shouldBreak) {
92614
92775
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
92776
+ const { spaceCount: _sc, ...lineBase } = currentLine;
92615
92777
  const completedLine = {
92616
- ...currentLine,
92778
+ ...lineBase,
92617
92779
  ...metrics
92618
92780
  };
92619
92781
  addBarTabsToLine(completedLine);
@@ -92629,12 +92791,14 @@ ${l}
92629
92791
  maxFontSize: run2.fontSize,
92630
92792
  maxFontInfo: getFontInfoFromRun(run2),
92631
92793
  maxWidth: getEffectiveWidth(contentWidth),
92632
- segments: [{ runIndex, fromChar: wordStartChar, toChar: wordEndNoSpace, width: wordOnlyWidth }]
92794
+ segments: [{ runIndex, fromChar: wordStartChar, toChar: wordEndNoSpace, width: wordOnlyWidth }],
92795
+ spaceCount: 0
92633
92796
  };
92634
92797
  if (!isLastWord && currentLine.width + spaceWidth <= currentLine.maxWidth - WIDTH_FUDGE_PX) {
92635
92798
  currentLine.toChar = wordEndWithSpace;
92636
92799
  currentLine.width = roundValue(currentLine.width + spaceWidth + (run2.letterSpacing ?? 0));
92637
92800
  charPosInRun = wordEndWithSpace;
92801
+ currentLine.spaceCount += 1;
92638
92802
  } else {
92639
92803
  charPosInRun = wordEndWithSpace;
92640
92804
  }
@@ -92655,7 +92819,8 @@ ${l}
92655
92819
  useExplicitXHere ? segmentStartX : void 0
92656
92820
  );
92657
92821
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
92658
- const completedLine = { ...currentLine, ...metrics };
92822
+ const { spaceCount: _sc, ...lineBase } = currentLine;
92823
+ const completedLine = { ...lineBase, ...metrics };
92659
92824
  addBarTabsToLine(completedLine);
92660
92825
  lines.push(completedLine);
92661
92826
  tabStopCursor = 0;
@@ -92668,12 +92833,14 @@ ${l}
92668
92833
  currentLine.toChar = newToChar;
92669
92834
  const useExplicitX = wordIndex === 0 && segmentStartX !== void 0;
92670
92835
  const explicitX = useExplicitX ? segmentStartX : void 0;
92671
- currentLine.width = roundValue(
92672
- currentLine.width + boundarySpacing + wordCommitWidth + (isLastWord ? 0 : run2.letterSpacing ?? 0)
92673
- );
92836
+ const targetWidth = compressedWidth != null ? compressedWidth : currentLine.width + boundarySpacing + wordCommitWidth + (isLastWord ? 0 : run2.letterSpacing ?? 0);
92837
+ currentLine.width = roundValue(targetWidth);
92674
92838
  currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
92675
92839
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, run2.fontSize);
92676
92840
  appendSegment(currentLine.segments, runIndex, wordStartChar, newToChar, wordCommitWidth, explicitX);
92841
+ if (!isLastWord) {
92842
+ currentLine.spaceCount += 1;
92843
+ }
92677
92844
  }
92678
92845
  charPosInRun = isLastWord ? wordEndNoSpace : wordEndWithSpace;
92679
92846
  }
@@ -92696,7 +92863,8 @@ ${l}
92696
92863
  maxFontSize: run2.fontSize,
92697
92864
  maxFontInfo: getFontInfoFromRun(run2),
92698
92865
  maxWidth: getEffectiveWidth(initialAvailableWidth),
92699
- segments: []
92866
+ segments: [],
92867
+ spaceCount: 0
92700
92868
  };
92701
92869
  }
92702
92870
  const originX = currentLine.width;
@@ -92742,8 +92910,9 @@ ${l}
92742
92910
  }
92743
92911
  if (currentLine) {
92744
92912
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
92913
+ const { spaceCount: _sc, ...lineBase } = currentLine;
92745
92914
  const finalLine = {
92746
- ...currentLine,
92915
+ ...lineBase,
92747
92916
  ...metrics
92748
92917
  };
92749
92918
  addBarTabsToLine(finalLine);
@@ -99033,18 +99202,78 @@ ${l}
99033
99202
  if (range2.pmStart == null || range2.pmEnd == null) return null;
99034
99203
  const pmOffset = pmPosToCharOffset(block, line, pos);
99035
99204
  const markerWidth = fragment.markerWidth ?? measure.marker?.markerWidth ?? 0;
99036
- const paraIndentLeft = block.attrs?.indent?.left ?? 0;
99037
- const paraIndentRight = block.attrs?.indent?.right ?? 0;
99038
- const availableWidth = Math.max(0, fragment.width - (paraIndentLeft + paraIndentRight));
99205
+ const indent2 = extractParagraphIndent(block.attrs?.indent);
99206
+ const availableWidth = Math.max(0, fragment.width - (indent2.left + indent2.right));
99039
99207
  const charX = measureCharacterX(block, line, pmOffset, availableWidth);
99040
- const firstLineOffset = (block.attrs?.indent?.firstLine ?? 0) - (block.attrs?.indent?.hanging ?? 0);
99041
99208
  const isFirstLine = index2 === fragment.fromLine;
99042
- const isListFirstLine = isFirstLine && !fragment.continuesFromPrev && (fragment.markerWidth ?? 0) > 0;
99043
- let indentAdjust = 0;
99044
- if (!isListFirstLine) {
99045
- indentAdjust = paraIndentLeft + (isFirstLine ? firstLineOffset : 0);
99209
+ const isListItemFlag = isListItem(markerWidth, block);
99210
+ const isListFirstLine = isFirstLine && !fragment.continuesFromPrev && isListItemFlag;
99211
+ const wordLayout = getWordLayoutConfig(block);
99212
+ const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
99213
+ if (isListFirstLine && isFirstLineIndentMode) {
99214
+ const textStartPx = calculateTextStartIndent({
99215
+ isFirstLine,
99216
+ isListItem: isListItemFlag,
99217
+ markerWidth,
99218
+ paraIndentLeft: indent2.left,
99219
+ firstLineIndent: indent2.firstLine,
99220
+ hangingIndent: indent2.hanging,
99221
+ wordLayout
99222
+ });
99223
+ const localX2 = fragment.x + textStartPx + charX;
99224
+ const lineOffset2 = __privateMethod$1(this, _PresentationEditor_instances, lineHeightBeforeIndex_fn).call(this, measure.lines, fragment.fromLine, index2);
99225
+ const localY2 = fragment.y + lineOffset2;
99226
+ const result2 = {
99227
+ pageIndex: hit.pageIndex,
99228
+ x: localX2,
99229
+ y: localY2,
99230
+ height: line.lineHeight
99231
+ };
99232
+ const pageEl2 = __privateGet$1(this, _painterHost)?.querySelector(
99233
+ `.superdoc-page[data-page-index="${hit.pageIndex}"]`
99234
+ );
99235
+ const pageRect2 = pageEl2?.getBoundingClientRect();
99236
+ const zoom2 = __privateGet$1(this, _layoutOptions).zoom ?? 1;
99237
+ let domCaretX2 = null;
99238
+ let domCaretY2 = null;
99239
+ const spanEls2 = pageEl2?.querySelectorAll("span[data-pm-start][data-pm-end]") ?? [];
99240
+ for (const spanEl of spanEls2) {
99241
+ const pmStart = Number(spanEl.dataset.pmStart);
99242
+ const pmEnd = Number(spanEl.dataset.pmEnd);
99243
+ if (pos >= pmStart && pos <= pmEnd && spanEl.firstChild?.nodeType === Node.TEXT_NODE) {
99244
+ const textNode = spanEl.firstChild;
99245
+ const charIndex = Math.min(pos - pmStart, textNode.length);
99246
+ const rangeObj = document.createRange();
99247
+ rangeObj.setStart(textNode, charIndex);
99248
+ rangeObj.setEnd(textNode, charIndex);
99249
+ const rangeRect = rangeObj.getBoundingClientRect();
99250
+ if (pageRect2) {
99251
+ domCaretX2 = (rangeRect.left - pageRect2.left) / zoom2;
99252
+ domCaretY2 = (rangeRect.top - pageRect2.top) / zoom2;
99253
+ }
99254
+ break;
99255
+ }
99256
+ }
99257
+ if (includeDomFallback && domCaretX2 != null && domCaretY2 != null) {
99258
+ return {
99259
+ pageIndex: hit.pageIndex,
99260
+ x: domCaretX2,
99261
+ y: domCaretY2,
99262
+ height: line.lineHeight
99263
+ };
99264
+ }
99265
+ return result2;
99046
99266
  }
99047
- const localX = fragment.x + markerWidth + indentAdjust + charX;
99267
+ const indentAdjust = calculateTextStartIndent({
99268
+ isFirstLine,
99269
+ isListItem: isListItemFlag,
99270
+ markerWidth,
99271
+ paraIndentLeft: indent2.left,
99272
+ firstLineIndent: indent2.firstLine,
99273
+ hangingIndent: indent2.hanging,
99274
+ wordLayout
99275
+ });
99276
+ const localX = fragment.x + indentAdjust + charX;
99048
99277
  const lineOffset = __privateMethod$1(this, _PresentationEditor_instances, lineHeightBeforeIndex_fn).call(this, measure.lines, fragment.fromLine, index2);
99049
99278
  const localY = fragment.y + lineOffset;
99050
99279
  const result = {
@@ -151393,7 +151622,7 @@ ${style2}
151393
151622
  this.config.colors = shuffleArray(this.config.colors);
151394
151623
  this.userColorMap = /* @__PURE__ */ new Map();
151395
151624
  this.colorIndex = 0;
151396
- this.version = "1.0.0-beta.87";
151625
+ this.version = "1.0.0-beta.89";
151397
151626
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
151398
151627
  this.superdocId = config2.superdocId || v4();
151399
151628
  this.colors = this.config.colors;
@@ -153865,7 +154094,7 @@ ${style2}
153865
154094
  value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
153866
154095
  );
153867
154096
  }
153868
- const indexRv7o9043 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
154097
+ const indexDcTrJ8db = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
153869
154098
  __proto__: null,
153870
154099
  unified
153871
154100
  }, Symbol.toStringTag, { value: "Module" }));