@univerjs/engine-render 1.0.0-alpha.0 → 1.0.0-insiders.20260629-12f2e44

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.
package/lib/cjs/index.js CHANGED
@@ -3460,11 +3460,12 @@ var BaseObject = class extends _univerjs_core.Disposable {
3460
3460
  if (this.isInGroup && ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.classType) === "Group" && ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.getBaseBound)) baseBound = this.parent.getBaseBound();
3461
3461
  if (baseBound) {
3462
3462
  const parentState = this.getParent();
3463
+ const parentRealBound = typeof parentState.getRealBound === "function" ? parentState.getRealBound() : parentState;
3463
3464
  const parentBound = {
3464
- top: parentState.top || 0,
3465
- left: parentState.left,
3466
- width: parentState.width || 0,
3467
- height: parentState.height || 0
3465
+ top: parentRealBound.top || 0,
3466
+ left: parentRealBound.left,
3467
+ width: parentRealBound.width || 0,
3468
+ height: parentRealBound.height || 0
3468
3469
  };
3469
3470
  const realBound = getRenderTransformBaseOnParentBound(baseBound, parentBound, {
3470
3471
  width: realWidth,
@@ -11994,6 +11995,68 @@ var Text = class Text extends Shape {
11994
11995
  }
11995
11996
  };
11996
11997
 
11998
+ //#endregion
11999
+ //#region src/components/docs/document-compatibility.ts
12000
+ const MODERN_DOCUMENT_COMPATIBILITY_POLICY = {
12001
+ mode: "modern",
12002
+ applyDocumentDefaultParagraphStyle: true,
12003
+ useWordStyleLineHeight: true,
12004
+ font: { metricScaleRules: [] },
12005
+ table: {
12006
+ currentPageOverflowTolerance: 0,
12007
+ rowOverflowTolerance: 0,
12008
+ allowImportedTableMarginOverflow: false
12009
+ }
12010
+ };
12011
+ const TRADITIONAL_DOCUMENT_COMPATIBILITY_POLICY = {
12012
+ mode: "traditional",
12013
+ applyDocumentDefaultParagraphStyle: false,
12014
+ useWordStyleLineHeight: true,
12015
+ font: { metricScaleRules: [{
12016
+ fontFamily: /^calibri$/i,
12017
+ minFontSize: 20,
12018
+ fontString: /\bbold\b/i,
12019
+ content: /^[\d/]+$/u,
12020
+ widthScale: .92
12021
+ }] },
12022
+ table: {
12023
+ currentPageOverflowTolerance: 12,
12024
+ rowOverflowTolerance: 4,
12025
+ allowImportedTableMarginOverflow: true
12026
+ }
12027
+ };
12028
+ const UNSPECIFIED_DOCUMENT_COMPATIBILITY_POLICY = {
12029
+ mode: "unspecified",
12030
+ applyDocumentDefaultParagraphStyle: false,
12031
+ useWordStyleLineHeight: false,
12032
+ font: { metricScaleRules: [] },
12033
+ table: {
12034
+ currentPageOverflowTolerance: 0,
12035
+ rowOverflowTolerance: 0,
12036
+ allowImportedTableMarginOverflow: false
12037
+ }
12038
+ };
12039
+ function getDocumentCompatibilityPolicy(documentFlavor) {
12040
+ if (documentFlavor === _univerjs_core.DocumentFlavor.MODERN) return MODERN_DOCUMENT_COMPATIBILITY_POLICY;
12041
+ if (documentFlavor === _univerjs_core.DocumentFlavor.TRADITIONAL) return TRADITIONAL_DOCUMENT_COMPATIBILITY_POLICY;
12042
+ return UNSPECIFIED_DOCUMENT_COMPATIBILITY_POLICY;
12043
+ }
12044
+ function applyFontMetricCompatibility(content, fontStyle, bBox, policy) {
12045
+ const fontFamilies = fontStyle.fontFamily.split(",").map((item) => item.trim().replace(/^['"]|['"]$/g, ""));
12046
+ const rule = policy.font.metricScaleRules.find((rule) => (rule.minFontSize == null || fontStyle.originFontSize >= rule.minFontSize) && (rule.fontString == null || rule.fontString.test(fontStyle.fontString)) && (rule.content == null || rule.content.test(content)) && fontFamilies.some((family) => rule.fontFamily.test(family)));
12047
+ if ((rule === null || rule === void 0 ? void 0 : rule.widthScale) == null) return bBox;
12048
+ return {
12049
+ ...bBox,
12050
+ width: bBox.width * rule.widthScale
12051
+ };
12052
+ }
12053
+ function isTraditionalDocumentCompatibility(policy) {
12054
+ return policy.mode === "traditional";
12055
+ }
12056
+ function shouldAllowImportedTableMarginOverflow(policy, tableSource) {
12057
+ return policy.table.allowImportedTableMarginOverflow && tableSource != null && typeof tableSource === "object" && "docxWidth" in tableSource;
12058
+ }
12059
+
11997
12060
  //#endregion
11998
12061
  //#region src/components/docs/liquid.ts
11999
12062
  var Liquid = class {
@@ -12286,8 +12349,16 @@ function parseDataStreamToTree(dataStream, tables) {
12286
12349
  const tableList = [];
12287
12350
  const tableRowList = [];
12288
12351
  const tableCellList = [];
12352
+ const columnGroupList = [];
12353
+ const columnList = [];
12354
+ const columnParagraphList = [];
12355
+ const columnSectionList = [];
12289
12356
  const currentBlocks = [];
12290
- const getParagraphList = () => tableCellList.length > 0 ? cellParagraphList : paragraphList;
12357
+ const getParagraphList = () => {
12358
+ if (tableCellList.length > 0) return cellParagraphList;
12359
+ if (columnGroupList.length > 0) return columnParagraphList;
12360
+ return paragraphList;
12361
+ };
12291
12362
  const appendToPreviousParagraph = (char) => {
12292
12363
  const tempParagraphList = getParagraphList();
12293
12364
  const lastParagraph = tempParagraphList[tempParagraphList.length - 1];
@@ -12317,10 +12388,11 @@ function parseDataStreamToTree(dataStream, tables) {
12317
12388
  currentBlocks.length = 0;
12318
12389
  content = "";
12319
12390
  if (tableCellList.length > 0) cellParagraphList.push(paragraphNode);
12391
+ else if (columnGroupList.length > 0) columnParagraphList.push(paragraphNode);
12320
12392
  else paragraphList.push(paragraphNode);
12321
12393
  } else if (char === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK) {
12322
12394
  const sectionNode = DataStreamTreeNode.create(_univerjs_core.DataStreamTreeNodeType.SECTION_BREAK);
12323
- const tempParagraphList = tableCellList.length > 0 ? cellParagraphList : paragraphList;
12395
+ const tempParagraphList = tableCellList.length > 0 ? cellParagraphList : columnGroupList.length > 0 ? columnParagraphList : paragraphList;
12324
12396
  if (tempParagraphList.length === 0) {
12325
12397
  const emptyParagraph = DataStreamTreeNode.create(_univerjs_core.DataStreamTreeNodeType.PARAGRAPH, "");
12326
12398
  emptyParagraph.setIndexRange(i, i - 1);
@@ -12332,7 +12404,8 @@ function parseDataStreamToTree(dataStream, tables) {
12332
12404
  if (tableCellList.length > 0) {
12333
12405
  const lastCell = tableCellList[tableCellList.length - 1];
12334
12406
  batchParent(lastCell, [sectionNode], _univerjs_core.DataStreamTreeNodeType.TABLE_CELL);
12335
- } else sectionList.push(sectionNode);
12407
+ } else if (columnGroupList.length > 0) columnSectionList.push(sectionNode);
12408
+ else sectionList.push(sectionNode);
12336
12409
  tempParagraphList.length = 0;
12337
12410
  } else if (char === _univerjs_core.DataStreamTreeTokenType.TABLE_START) {
12338
12411
  const tableNode = DataStreamTreeNode.create(_univerjs_core.DataStreamTreeNodeType.TABLE);
@@ -12358,6 +12431,32 @@ function parseDataStreamToTree(dataStream, tables) {
12358
12431
  const cellNode = tableCellList.pop();
12359
12432
  const lastRow = tableRowList[tableRowList.length - 1];
12360
12433
  batchParent(lastRow, [cellNode], _univerjs_core.DataStreamTreeNodeType.TABLE_ROW);
12434
+ } else if (char === _univerjs_core.DataStreamTreeTokenType.COLUMN_GROUP_START) {
12435
+ const columnGroupNode = DataStreamTreeNode.create(_univerjs_core.DataStreamTreeNodeType.COLUMN_GROUP);
12436
+ columnGroupNode.setIndexRange(i, i);
12437
+ columnGroupList.push(columnGroupNode);
12438
+ } else if (char === _univerjs_core.DataStreamTreeTokenType.COLUMN_START) {
12439
+ const columnNode = DataStreamTreeNode.create(_univerjs_core.DataStreamTreeNodeType.COLUMN);
12440
+ columnNode.setIndexRange(i, i);
12441
+ columnList.push(columnNode);
12442
+ } else if (char === _univerjs_core.DataStreamTreeTokenType.COLUMN_END) {
12443
+ const columnNode = columnList[columnList.length - 1];
12444
+ const columnChildren = columnSectionList.length > 0 ? columnSectionList : columnParagraphList;
12445
+ const columnStartIndex = columnNode.startIndex;
12446
+ batchParent(columnNode, columnChildren, _univerjs_core.DataStreamTreeNodeType.COLUMN);
12447
+ columnNode.setIndexRange(columnStartIndex, i);
12448
+ columnParagraphList.length = 0;
12449
+ columnSectionList.length = 0;
12450
+ } else if (char === _univerjs_core.DataStreamTreeTokenType.COLUMN_GROUP_END) {
12451
+ const columnGroupNode = columnGroupList.pop();
12452
+ const columnGroupStartIndex = columnGroupNode.startIndex;
12453
+ batchParent(columnGroupNode, columnList, _univerjs_core.DataStreamTreeNodeType.COLUMN_GROUP);
12454
+ columnGroupNode.setIndexRange(columnGroupStartIndex, i);
12455
+ paragraphList.push(columnGroupNode);
12456
+ columnList.length = 0;
12457
+ columnParagraphList.length = 0;
12458
+ columnSectionList.length = 0;
12459
+ content = "";
12361
12460
  } else if (char === _univerjs_core.DataStreamTreeTokenType.BLOCK_START) content += char;
12362
12461
  else if (char === _univerjs_core.DataStreamTreeTokenType.BLOCK_END) {
12363
12462
  if (content.length > 0 || !appendToPreviousParagraph(char)) content += char;
@@ -12381,6 +12480,7 @@ var DocumentViewModel = class DocumentViewModel {
12381
12480
  _defineProperty(this, "_sectionBreakCache", /* @__PURE__ */ new Map());
12382
12481
  _defineProperty(this, "_customBlockCache", /* @__PURE__ */ new Map());
12383
12482
  _defineProperty(this, "_tableCache", /* @__PURE__ */ new Map());
12483
+ _defineProperty(this, "_columnGroupCache", /* @__PURE__ */ new Map());
12384
12484
  _defineProperty(this, "_tableNodeCache", /* @__PURE__ */ new Map());
12385
12485
  _defineProperty(this, "_children", []);
12386
12486
  _defineProperty(this, "_editArea", "BODY");
@@ -12411,6 +12511,7 @@ var DocumentViewModel = class DocumentViewModel {
12411
12511
  this._sectionBreakCache.clear();
12412
12512
  this._customBlockCache.clear();
12413
12513
  this._tableCache.clear();
12514
+ this._columnGroupCache.clear();
12414
12515
  this._tableNodeCache.clear();
12415
12516
  this._segmentViewModels$.complete();
12416
12517
  this._editAreaChange$.complete();
@@ -12482,6 +12583,9 @@ var DocumentViewModel = class DocumentViewModel {
12482
12583
  getTableByStartIndex(index) {
12483
12584
  return this._tableCache.get(index);
12484
12585
  }
12586
+ getColumnGroupByStartIndex(index) {
12587
+ return this._columnGroupCache.get(index);
12588
+ }
12485
12589
  findTableNodeById(id) {
12486
12590
  var _this$_tableNodeCache;
12487
12591
  return (_this$_tableNodeCache = this._tableNodeCache.get(id)) === null || _this$_tableNodeCache === void 0 ? void 0 : _this$_tableNodeCache.table;
@@ -12516,6 +12620,7 @@ var DocumentViewModel = class DocumentViewModel {
12516
12620
  this._buildSectionBreakCache();
12517
12621
  this._buildCustomBlockCache();
12518
12622
  this._buildTableCache();
12623
+ this._buildColumnGroupCache();
12519
12624
  }
12520
12625
  _buildParagraphCache() {
12521
12626
  var _this$getBody$paragra, _this$getBody;
@@ -12560,9 +12665,23 @@ var DocumentViewModel = class DocumentViewModel {
12560
12665
  });
12561
12666
  }
12562
12667
  }
12668
+ _buildColumnGroupCache() {
12669
+ var _this$getBody5;
12670
+ this._columnGroupCache.clear();
12671
+ const columnGroups = (_this$getBody5 = this.getBody()) === null || _this$getBody5 === void 0 ? void 0 : _this$getBody5.columnGroups;
12672
+ if (columnGroups == null) return;
12673
+ for (const columnGroup of columnGroups) {
12674
+ const { startIndex } = columnGroup;
12675
+ if (!columnGroup.columns) continue;
12676
+ this._columnGroupCache.set(startIndex, {
12677
+ columnGroup,
12678
+ columnGroupSource: columnGroup
12679
+ });
12680
+ }
12681
+ }
12563
12682
  _buildTextRunsCache() {
12564
- var _this$getBody$textRun, _this$getBody5;
12565
- const textRuns = (_this$getBody$textRun = (_this$getBody5 = this.getBody()) === null || _this$getBody5 === void 0 ? void 0 : _this$getBody5.textRuns) !== null && _this$getBody$textRun !== void 0 ? _this$getBody$textRun : [];
12683
+ var _this$getBody$textRun, _this$getBody6;
12684
+ const textRuns = (_this$getBody$textRun = (_this$getBody6 = this.getBody()) === null || _this$getBody6 === void 0 ? void 0 : _this$getBody6.textRuns) !== null && _this$getBody$textRun !== void 0 ? _this$getBody$textRun : [];
12566
12685
  this._textRunsCache.clear();
12567
12686
  for (const textRun of textRuns) {
12568
12687
  const { st, ed } = textRun;
@@ -12588,68 +12707,6 @@ var DocumentViewModel = class DocumentViewModel {
12588
12707
  }
12589
12708
  };
12590
12709
 
12591
- //#endregion
12592
- //#region src/components/docs/document-compatibility.ts
12593
- const MODERN_DOCUMENT_COMPATIBILITY_POLICY = {
12594
- mode: "modern",
12595
- applyDocumentDefaultParagraphStyle: true,
12596
- useWordStyleLineHeight: true,
12597
- font: { metricScaleRules: [] },
12598
- table: {
12599
- currentPageOverflowTolerance: 0,
12600
- rowOverflowTolerance: 0,
12601
- allowImportedTableMarginOverflow: false
12602
- }
12603
- };
12604
- const TRADITIONAL_DOCUMENT_COMPATIBILITY_POLICY = {
12605
- mode: "traditional",
12606
- applyDocumentDefaultParagraphStyle: false,
12607
- useWordStyleLineHeight: true,
12608
- font: { metricScaleRules: [{
12609
- fontFamily: /^calibri$/i,
12610
- minFontSize: 20,
12611
- fontString: /\bbold\b/i,
12612
- content: /^[\d/]+$/u,
12613
- widthScale: .92
12614
- }] },
12615
- table: {
12616
- currentPageOverflowTolerance: 12,
12617
- rowOverflowTolerance: 4,
12618
- allowImportedTableMarginOverflow: true
12619
- }
12620
- };
12621
- const UNSPECIFIED_DOCUMENT_COMPATIBILITY_POLICY = {
12622
- mode: "unspecified",
12623
- applyDocumentDefaultParagraphStyle: false,
12624
- useWordStyleLineHeight: false,
12625
- font: { metricScaleRules: [] },
12626
- table: {
12627
- currentPageOverflowTolerance: 0,
12628
- rowOverflowTolerance: 0,
12629
- allowImportedTableMarginOverflow: false
12630
- }
12631
- };
12632
- function getDocumentCompatibilityPolicy(documentFlavor) {
12633
- if (documentFlavor === _univerjs_core.DocumentFlavor.MODERN) return MODERN_DOCUMENT_COMPATIBILITY_POLICY;
12634
- if (documentFlavor === _univerjs_core.DocumentFlavor.TRADITIONAL) return TRADITIONAL_DOCUMENT_COMPATIBILITY_POLICY;
12635
- return UNSPECIFIED_DOCUMENT_COMPATIBILITY_POLICY;
12636
- }
12637
- function applyFontMetricCompatibility(content, fontStyle, bBox, policy) {
12638
- const fontFamilies = fontStyle.fontFamily.split(",").map((item) => item.trim().replace(/^['"]|['"]$/g, ""));
12639
- const rule = policy.font.metricScaleRules.find((rule) => (rule.minFontSize == null || fontStyle.originFontSize >= rule.minFontSize) && (rule.fontString == null || rule.fontString.test(fontStyle.fontString)) && (rule.content == null || rule.content.test(content)) && fontFamilies.some((family) => rule.fontFamily.test(family)));
12640
- if ((rule === null || rule === void 0 ? void 0 : rule.widthScale) == null) return bBox;
12641
- return {
12642
- ...bBox,
12643
- width: bBox.width * rule.widthScale
12644
- };
12645
- }
12646
- function isTraditionalDocumentCompatibility(policy) {
12647
- return policy.mode === "traditional";
12648
- }
12649
- function shouldAllowImportedTableMarginOverflow(policy, tableSource) {
12650
- return policy.table.allowImportedTableMarginOverflow && tableSource != null && typeof tableSource === "object" && "docxWidth" in tableSource;
12651
- }
12652
-
12653
12710
  //#endregion
12654
12711
  //#region src/components/docs/layout/model/glyph.ts
12655
12712
  function isSpace(char) {
@@ -12740,6 +12797,10 @@ function _createSkeletonWordOrLetter(glyphType, content, config, glyphWidth, gly
12740
12797
  _univerjs_core.DataStreamTreeTokenType.TABLE_ROW_END,
12741
12798
  _univerjs_core.DataStreamTreeTokenType.TABLE_CELL_START,
12742
12799
  _univerjs_core.DataStreamTreeTokenType.TABLE_CELL_END,
12800
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_GROUP_START,
12801
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_START,
12802
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_END,
12803
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_GROUP_END,
12743
12804
  _univerjs_core.DataStreamTreeTokenType.BLOCK_START,
12744
12805
  _univerjs_core.DataStreamTreeTokenType.BLOCK_END,
12745
12806
  _univerjs_core.DataStreamTreeTokenType.CUSTOM_RANGE_START,
@@ -12902,7 +12963,9 @@ function createSkeletonLine(paragraphIndex, lineType, lineBoundingBox, columnWid
12902
12963
  lineSke.isBehindTable = true;
12903
12964
  lineSke.tableId = tableId;
12904
12965
  }
12905
- lineSke.divides = _calculateDividesByDrawings(lineHeight, lineTop, columnWidth, paddingLeft, paddingRight, page, headerPage, footerPage, new Map(Array.from(pageSkeDrawings).filter(([_, drawing]) => drawing.drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE && drawing.drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE)), headersDrawings, footersDrawings, new Map(Array.from(pageSkeTables).filter(([_, table]) => table.tableSource.textWrap === _univerjs_core.TableTextWrapType.WRAP)));
12966
+ const affectSkeDrawings = new Map(Array.from(pageSkeDrawings).filter(([_, drawing]) => drawing.drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE && drawing.drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE));
12967
+ const wrapTypeTables = new Map(Array.from(pageSkeTables).filter(([_, table]) => table.tableSource.textWrap === _univerjs_core.TableTextWrapType.WRAP));
12968
+ lineSke.divides = lineHeight <= .01 ? [__getDivideSKe(0, columnWidth)] : _calculateDividesByDrawings(lineHeight, lineTop, columnWidth, paddingLeft, paddingRight, page, headerPage, footerPage, affectSkeDrawings, headersDrawings, footersDrawings, wrapTypeTables);
12906
12969
  for (const divide of lineSke.divides) divide.parent = lineSke;
12907
12970
  return lineSke;
12908
12971
  }
@@ -13141,6 +13204,8 @@ function ___getWrapTextRuler(wrapText, resultLeft, resultWidth, columnWidth) {
13141
13204
  return ruler;
13142
13205
  }
13143
13206
  function _calculateDivideByDrawings(columnWidth, drawingSplit) {
13207
+ if (!Number.isFinite(columnWidth) || columnWidth <= 0) return [__getDivideSKe(0, Math.max(1, columnWidth || 1))];
13208
+ drawingSplit = drawingSplit.filter(({ left, width }) => Number.isFinite(left) && Number.isFinite(width) && width > 0 && left < columnWidth && left + width > 0);
13144
13209
  drawingSplit.sort((pre, next) => {
13145
13210
  if (pre.left > next.left) return 1;
13146
13211
  return -1;
@@ -13670,6 +13735,13 @@ function getTableIdAndSliceIndex(tableSliceId) {
13670
13735
  //#region src/components/docs/layout/block/paragraph/layout-ruler.ts
13671
13736
  const LINE_LAYOUT_OVERFLOW_TOLERANCE = 2;
13672
13737
  const FLOAT_OBJECT_RELAYOUT_LIMIT = 5;
13738
+ const MIN_LINE_WIDTH_TOLERANCE = 1;
13739
+ const MAX_LINE_WIDTH_TOLERANCE = 3;
13740
+ const RELATIVE_LINE_WIDTH_TOLERANCE = .01;
13741
+ function isBeyondDivideWidth(width, divideWidth) {
13742
+ const tolerance = Math.min(MAX_LINE_WIDTH_TOLERANCE, Math.max(MIN_LINE_WIDTH_TOLERANCE, divideWidth * RELATIVE_LINE_WIDTH_TOLERANCE));
13743
+ return width - divideWidth > tolerance;
13744
+ }
13673
13745
  function layoutParagraph(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType = "Normal") {
13674
13746
  if (isParagraphFirstShapedText) if (paragraphConfig.bulletSkeleton) {
13675
13747
  var _paragraphProperties$;
@@ -13751,7 +13823,12 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13751
13823
  const lastGlyph = divide === null || divide === void 0 || (_divide$glyphGroup = divide.glyphGroup) === null || _divide$glyphGroup === void 0 ? void 0 : _divide$glyphGroup[divide.glyphGroup.length - 1];
13752
13824
  const preOffsetLeft = ((lastGlyph === null || lastGlyph === void 0 ? void 0 : lastGlyph.width) || 0) + ((lastGlyph === null || lastGlyph === void 0 ? void 0 : lastGlyph.left) || 0);
13753
13825
  const { hyphenationZone } = sectionBreakConfig;
13754
- if (preOffsetLeft + width > divide.width) {
13826
+ if (isBeyondDivideWidth(preOffsetLeft + width, divide.width)) {
13827
+ if ((divide === null || divide === void 0 ? void 0 : divide.glyphGroup.length) === 0 && glyphGroup.length > 0 && glyphGroup[0].streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK) {
13828
+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13829
+ updateDivideInfo(divide, { breakType: breakPointType });
13830
+ return;
13831
+ }
13755
13832
  if (shouldKeepOverflowingTextOnLine(sectionBreakConfig)) {
13756
13833
  addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13757
13834
  updateDivideInfo(divide, { breakType: breakPointType });
@@ -13763,13 +13840,13 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13763
13840
  if (divideInfo.isLast && glyphGroup.length === 1 && (glyphGroup[0].content === _univerjs_core.DataStreamTreeTokenType.SPACE || glyphGroup[0].content === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH)) addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13764
13841
  else if (divideInfo.isLast && !isGlyphGroupBeyondContentBox(glyphGroup, preOffsetLeft, divide.width) && isGlyphGroupEndWithWhiteSpaces(glyphGroup)) addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13765
13842
  else if (!isLast && (divide === null || divide === void 0 ? void 0 : divide.glyphGroup.length) === 0 && glyphGroup.length === 1 && glyphGroup[0].streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyphGroup[0].width > divide.width) {
13766
- updateDivideInfo(divide, { isFull: true });
13767
- _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType, defaultSpanLineHeight);
13843
+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13844
+ updateDivideInfo(divide, { breakType: breakPointType });
13768
13845
  } else if ((divide === null || divide === void 0 ? void 0 : divide.glyphGroup.length) === 0) {
13769
13846
  const sliceGlyphGroup = [];
13770
13847
  while (glyphGroup.length) {
13771
13848
  sliceGlyphGroup.push(glyphGroup.shift());
13772
- if (__getGlyphGroupWidth(sliceGlyphGroup) > divide.width) {
13849
+ if (isBeyondDivideWidth(__getGlyphGroupWidth(sliceGlyphGroup), divide.width)) {
13773
13850
  if (sliceGlyphGroup.length > 1) glyphGroup.unshift(sliceGlyphGroup.pop());
13774
13851
  break;
13775
13852
  }
@@ -13822,6 +13899,10 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13822
13899
  const paragraphAnchorLeft = __getParagraphAnchorLeft(sectionBreakConfig, paragraphConfig, (_paragraphConfig$para = paragraphConfig.paragraphStyle) === null || _paragraphConfig$para === void 0 ? void 0 : _paragraphConfig$para.indentStart);
13823
13900
  const drawings = __getDrawingPosition(currentLine.top, currentLine.lineHeight, currentLine.parent, true, (_paragraphConfig$pDra = paragraphConfig.pDrawingAnchor) === null || _paragraphConfig$pDra === void 0 || (_paragraphConfig$pDra = _paragraphConfig$pDra.get(paragraphConfig.paragraphIndex)) === null || _paragraphConfig$pDra === void 0 ? void 0 : _paragraphConfig$pDra.top, anchorDrawings, paragraphAnchorLeft);
13824
13901
  __updateDrawingPosition(currentLine.parent, drawings);
13902
+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13903
+ updateDivideInfo(divide, { breakType: breakPointType });
13904
+ glyphGroup.length = 0;
13905
+ return;
13825
13906
  }
13826
13907
  }
13827
13908
  addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
@@ -13833,6 +13914,19 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13833
13914
  var _originParagraphStyle, _originParagraphStyle2, _skeHeaders$get, _skeFooters$get;
13834
13915
  let lastPage = getLastPage(pages);
13835
13916
  let columnInfo = getLastNotFullColumnInfo(lastPage);
13917
+ if (!columnInfo || !columnInfo.column) {
13918
+ const lastSection = getLastSection(lastPage);
13919
+ const lastColumnIndex = lastSection.columns.length - 1;
13920
+ const lastColumn = lastSection.columns[lastColumnIndex];
13921
+ if (lastColumn && isBlankColumn(lastColumn)) {
13922
+ setColumnFullState(lastColumn, false);
13923
+ columnInfo = {
13924
+ column: lastColumn,
13925
+ index: lastColumnIndex,
13926
+ isLast: true
13927
+ };
13928
+ }
13929
+ }
13836
13930
  if (!columnInfo || !columnInfo.column) {
13837
13931
  _pageOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, true, breakPointType);
13838
13932
  lastPage = getLastPage(pages);
@@ -13859,9 +13953,21 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13859
13953
  };
13860
13954
  const { paragraphLineGapDefault, linePitch, lineSpacing, spacingRule, snapToGrid, gridType } = getLineHeightConfig(sectionBreakConfig, paragraphConfig);
13861
13955
  const hasInlineCustomBlock = glyphGroup.some((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.width !== 0);
13956
+ const positionedCustomBlockOnly = glyphGroup.length > 0 && paragraphNonInlineSkeDrawings != null && paragraphNonInlineSkeDrawings.size > 0 && glyphGroup.every((glyph) => {
13957
+ if (!glyph) return false;
13958
+ if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK) return [...paragraphNonInlineSkeDrawings.values()].some((drawing) => drawing.drawingId === glyph.drawingId);
13959
+ return glyph.streamType === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH || glyph.raw === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH;
13960
+ });
13862
13961
  const glyphGroupCustomBlockIds = new Set(glyphGroup.filter((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.drawingId != null).map((glyph) => glyph.drawingId));
13863
13962
  let { paddingTop, paddingBottom, contentHeight, lineSpacingApply } = getLineHeightMetrics(glyphLineHeight, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid, paragraphConfig.useWordStyleLineHeight, !hasInlineCustomBlock);
13963
+ if (positionedCustomBlockOnly) {
13964
+ paddingTop = 0;
13965
+ paddingBottom = 0;
13966
+ contentHeight = .01;
13967
+ lineSpacingApply = .01;
13968
+ }
13864
13969
  let { marginTop, spaceBelowApply } = __getParagraphSpace(ctx, lineSpacingApply, spaceAbove, spaceBelow, isParagraphFirstShapedText, preLine);
13970
+ if (positionedCustomBlockOnly) spaceBelowApply = 0;
13865
13971
  if (isZeroWidthNonFlowFloatingAnchorLine) {
13866
13972
  paddingTop = 0;
13867
13973
  paddingBottom = 0;
@@ -13904,7 +14010,7 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13904
14010
  var _pDrawingAnchor$get2;
13905
14011
  needOpenNewPageByTableLayout = _updateAndPositionTable(ctx, lineTop, lineHeight, lastPage, column, section, skeTablesInParagraph, paragraphConfig.paragraphIndex, sectionBreakConfig, pDrawingAnchor === null || pDrawingAnchor === void 0 || (_pDrawingAnchor$get2 = pDrawingAnchor.get(paragraphIndex)) === null || _pDrawingAnchor$get2 === void 0 ? void 0 : _pDrawingAnchor$get2.top);
13906
14012
  }
13907
- const newLineTop = calculateLineTopByDrawings(lineHeight, lineTop, lastPage, headerPage, footerPage);
14013
+ const newLineTop = positionedCustomBlockOnly ? lineTop : calculateLineTopByDrawings(lineHeight, lineTop, lastPage, headerPage, footerPage);
13908
14014
  if (lineHeight + newLineTop - section.height > LINE_LAYOUT_OVERFLOW_TOLERANCE && column.lines.length > 0 && lastPage.sections.length > 0 || needOpenNewPageByTableLayout) {
13909
14015
  setColumnFullState(column, true);
13910
14016
  _columnOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType, defaultGlyphLineHeight);
@@ -14530,6 +14636,25 @@ function isColumnFull(page) {
14530
14636
  for (let i = 0; i < columnsLen; i++) if (!section.columns[i].isFull) return false;
14531
14637
  return true;
14532
14638
  }
14639
+ function isBlankColumn(column) {
14640
+ const lines = column.lines;
14641
+ if (lines.length > 1) return false;
14642
+ const line = lines[lines.length - 1];
14643
+ return isLineBlank(line);
14644
+ }
14645
+ function isLineBlank(line) {
14646
+ if (!line) return true;
14647
+ for (let i = 0; i < line.divides.length; i++) {
14648
+ const spanCount = line.divides[i].glyphGroup.length;
14649
+ if (spanCount > 1) return false;
14650
+ if (spanCount === 1) {
14651
+ const { glyphType, raw, streamType, width } = line.divides[i].glyphGroup[0];
14652
+ const isZeroWidthColumnBreak = width === 0 && (raw === _univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK || streamType === _univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK);
14653
+ if (glyphType !== 4 && glyphType !== 2 && !isZeroWidthColumnBreak) return false;
14654
+ }
14655
+ }
14656
+ return true;
14657
+ }
14533
14658
  function getNumberUnitValue(unitValue, benchMark) {
14534
14659
  if (!unitValue) return 0;
14535
14660
  const { v: value, u: unit } = unitValue;
@@ -14579,15 +14704,17 @@ function getCharSpaceConfig(sectionBreakConfig, paragraphConfig) {
14579
14704
  snapToGrid
14580
14705
  };
14581
14706
  }
14582
- function updateBlockIndex(pages, start = -1) {
14707
+ function updateBlockIndex(pages, start = -1, documentCompatibilityPolicy) {
14583
14708
  let prePageStartIndex = start;
14709
+ const shouldUseLayoutColumnWidth = (documentCompatibilityPolicy === null || documentCompatibilityPolicy === void 0 ? void 0 : documentCompatibilityPolicy.mode) !== "unspecified";
14584
14710
  for (const page of pages) {
14585
- const { sections, skeTables } = page;
14711
+ const { sections, skeTables, skeColumnGroups = /* @__PURE__ */ new Map() } = page;
14586
14712
  const pageStartIndex = prePageStartIndex;
14587
14713
  let preSectionStartIndex = pageStartIndex;
14588
14714
  let maxContentWidth = Number.NEGATIVE_INFINITY;
14589
14715
  let contentHeight = 0;
14590
14716
  for (const section of sections) {
14717
+ collapseRedundantColumnBreakOverflow(section);
14591
14718
  const { columns } = section;
14592
14719
  const sectionStartIndex = preSectionStartIndex;
14593
14720
  let preColumnStartIndex = sectionStartIndex;
@@ -14606,6 +14733,16 @@ function updateBlockIndex(pages, start = -1) {
14606
14733
  const table = skeTables.get(tableId);
14607
14734
  if (table) lineStartIndex = table.ed;
14608
14735
  }
14736
+ if (line.type === 1 && divides.length === 0) {
14737
+ line.st = Math.max(line.st, lineStartIndex + 1);
14738
+ line.ed = Math.max(line.ed, line.st);
14739
+ line.width = 0;
14740
+ line.asc = 0;
14741
+ line.dsc = 0;
14742
+ columnHeight = top + lineHeight;
14743
+ preLineStartIndex = Math.max(preLineStartIndex, line.ed);
14744
+ continue;
14745
+ }
14609
14746
  let preDivideStartIndex = lineStartIndex;
14610
14747
  let actualWidth = 0;
14611
14748
  let maxLineAsc = 0;
@@ -14645,8 +14782,9 @@ function updateBlockIndex(pages, start = -1) {
14645
14782
  column.st = columStartIndex + 1;
14646
14783
  column.ed = preLineStartIndex >= column.st ? preLineStartIndex : column.st;
14647
14784
  column.height = columnHeight;
14648
- column.width = maxColumnWidth;
14649
- sectionWidth += maxColumnWidth;
14785
+ const measuredColumnWidth = shouldUseLayoutColumnWidth && Number.isFinite(column.width) && column.width > 0 ? column.width : maxColumnWidth;
14786
+ column.width = measuredColumnWidth;
14787
+ sectionWidth += measuredColumnWidth;
14650
14788
  maxSectionHeight = Math.max(maxSectionHeight, column.height);
14651
14789
  preColumnStartIndex = column.ed;
14652
14790
  }
@@ -14661,6 +14799,10 @@ function updateBlockIndex(pages, start = -1) {
14661
14799
  const { ed } = table;
14662
14800
  preSectionStartIndex = Math.max(preSectionStartIndex, ed);
14663
14801
  }
14802
+ for (const columnGroup of skeColumnGroups.values()) {
14803
+ const { ed } = columnGroup;
14804
+ preSectionStartIndex = Math.max(preSectionStartIndex, ed);
14805
+ }
14664
14806
  page.st = pageStartIndex + 1;
14665
14807
  page.ed = preSectionStartIndex >= page.st ? preSectionStartIndex : page.st;
14666
14808
  page.height = contentHeight;
@@ -14668,6 +14810,28 @@ function updateBlockIndex(pages, start = -1) {
14668
14810
  prePageStartIndex = page.ed;
14669
14811
  }
14670
14812
  }
14813
+ function collapseRedundantColumnBreakOverflow(section) {
14814
+ var _targetColumn$height;
14815
+ const expectedColumnCount = section.colCount || section.columns.length;
14816
+ if (expectedColumnCount <= 0 || section.columns.length <= expectedColumnCount) return;
14817
+ const targetColumn = section.columns[expectedColumnCount - 1];
14818
+ if (!targetColumn) return;
14819
+ const overflowColumns = section.columns.slice(expectedColumnCount);
14820
+ if (!overflowColumns.some((column) => column.lines.length > 0)) return;
14821
+ const targetHeight = (_targetColumn$height = targetColumn.height) !== null && _targetColumn$height !== void 0 ? _targetColumn$height : 0;
14822
+ const overflowLines = overflowColumns.flatMap((column) => column.lines);
14823
+ overflowLines.forEach((line) => {
14824
+ line.top += targetHeight;
14825
+ line.parent = targetColumn;
14826
+ });
14827
+ targetColumn.lines.push(...overflowLines);
14828
+ targetColumn.height = Math.max(...overflowColumns.map((column) => {
14829
+ var _column$height;
14830
+ return targetHeight + ((_column$height = column.height) !== null && _column$height !== void 0 ? _column$height : 0);
14831
+ }), targetHeight);
14832
+ targetColumn.isFull = overflowColumns.some((column) => column.isFull);
14833
+ section.columns.splice(expectedColumnCount);
14834
+ }
14671
14835
  function updateInlineDrawingCoordsAndBorder(ctx, pages) {
14672
14836
  lineIterator(pages, (line, _, __, page) => {
14673
14837
  var _ctx$paragraphConfigC, _ctx$skeletonResource, _paragraphStyle$shadi;
@@ -14719,6 +14883,264 @@ function lineIterator(pagesOrCells, cb) {
14719
14883
  }
14720
14884
  }
14721
14885
  }
14886
+ function documentSkeletonTableIterator(pages, options = {}) {
14887
+ const { docsLeft = 0, docsTop = 0, pageMarginTop = 0, resolveViewport = true, tableCellInsetX = 0, unitId = "" } = options;
14888
+ const contexts = [];
14889
+ pages.forEach((rootPage, pageIndex) => {
14890
+ var _rootPage$skeColumnGr;
14891
+ const rootPageTop = ((rootPage.pageHeight === Infinity ? 0 : rootPage.pageHeight) + pageMarginTop) * pageIndex + rootPage.marginTop + docsTop;
14892
+ const rootPageLeft = rootPage.marginLeft + docsLeft;
14893
+ collectPageTables({
14894
+ contexts,
14895
+ docsLeft,
14896
+ page: rootPage,
14897
+ pageIndex,
14898
+ pageLeft: rootPageLeft,
14899
+ pageTop: rootPageTop,
14900
+ rootPage,
14901
+ source: "page",
14902
+ resolveViewport,
14903
+ tableCellInsetX,
14904
+ unitId
14905
+ });
14906
+ (_rootPage$skeColumnGr = rootPage.skeColumnGroups) === null || _rootPage$skeColumnGr === void 0 || _rootPage$skeColumnGr.forEach((columnGroup) => {
14907
+ columnGroup.columns.forEach((columnGroupColumn) => {
14908
+ const nestedPage = columnGroupColumn.page;
14909
+ collectPageTables({
14910
+ contexts,
14911
+ docsLeft,
14912
+ page: nestedPage,
14913
+ pageIndex,
14914
+ pageLeft: rootPageLeft + columnGroup.left + columnGroupColumn.left + nestedPage.marginLeft,
14915
+ pageTop: rootPageTop + columnGroup.top + columnGroupColumn.top + nestedPage.marginTop,
14916
+ rootPage,
14917
+ source: "column",
14918
+ resolveViewport,
14919
+ tableCellInsetX,
14920
+ unitId
14921
+ });
14922
+ });
14923
+ });
14924
+ });
14925
+ return contexts;
14926
+ }
14927
+ function documentSkeletonLineIterator(pages, options, cb) {
14928
+ const { docsLeft = 0, pageMarginTop = 0, tableCellInsetX = 0, unitId = "" } = options;
14929
+ pages.forEach((page, pageIndex) => {
14930
+ var _page$skeTables, _page$skeColumnGroups;
14931
+ const pageTop = ((page.pageHeight === Infinity ? 0 : page.pageHeight) + pageMarginTop) * pageIndex + page.marginTop;
14932
+ const pageLeft = page.marginLeft;
14933
+ visitPageLines(page, {
14934
+ pageIndex,
14935
+ pageLeft,
14936
+ pageTop,
14937
+ source: "page",
14938
+ getBounds: (linePage, column, section) => getPageLineBounds(linePage, column, section.columns.length, pageLeft)
14939
+ }, cb);
14940
+ (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 || _page$skeTables.forEach((table) => {
14941
+ const viewport = getDocsTableRenderViewport(unitId, getSourceTableId(table.tableId));
14942
+ const hasHorizontalViewport = hasDocsTableHorizontalViewport(viewport);
14943
+ const tableViewportLeft = getTableViewportLeft(pageLeft, table.left, viewport, docsLeft);
14944
+ const tableViewportRight = tableViewportLeft + (hasHorizontalViewport ? viewport.viewportWidth : table.width);
14945
+ const tableScrollLeft = hasHorizontalViewport ? viewport.scrollLeft : 0;
14946
+ table.rows.forEach((row) => {
14947
+ row.cells.forEach((cell) => {
14948
+ const cellTop = pageTop + table.top + row.top + cell.marginTop;
14949
+ const cellLeft = pageLeft + table.left + cell.left - tableScrollLeft + cell.marginLeft;
14950
+ const cellContentRight = cellLeft + cell.pageWidth - cell.marginLeft - cell.marginRight;
14951
+ const visualLeft = cellLeft + tableCellInsetX;
14952
+ const visualRight = cellContentRight - tableCellInsetX;
14953
+ const visualWidth = Math.max(0, visualRight - visualLeft);
14954
+ const clipLeft = tableViewportLeft;
14955
+ const clipRight = Math.min(cellContentRight, tableViewportRight);
14956
+ if (visualWidth <= 0 || Math.min(visualRight, clipRight) <= Math.max(visualLeft, clipLeft)) return;
14957
+ visitPageLines(cell, {
14958
+ clipLeft,
14959
+ clipRight,
14960
+ pageIndex,
14961
+ pageLeft: cellLeft,
14962
+ pageTop: cellTop,
14963
+ source: "table-cell",
14964
+ visualLeft,
14965
+ visualWidth
14966
+ }, cb);
14967
+ });
14968
+ });
14969
+ });
14970
+ (_page$skeColumnGroups = page.skeColumnGroups) === null || _page$skeColumnGroups === void 0 || _page$skeColumnGroups.forEach((columnGroup) => {
14971
+ columnGroup.columns.forEach((columnGroupColumn) => {
14972
+ const nestedPage = columnGroupColumn.page;
14973
+ const nestedPageLeft = pageLeft + columnGroup.left + columnGroupColumn.left + nestedPage.marginLeft;
14974
+ const nestedPageTop = pageTop + columnGroup.top + columnGroupColumn.top + nestedPage.marginTop;
14975
+ const visualWidth = Math.max(0, columnGroupColumn.width - nestedPage.marginLeft - nestedPage.marginRight);
14976
+ visitPageLines(nestedPage, {
14977
+ pageIndex,
14978
+ pageLeft: nestedPageLeft,
14979
+ pageTop: nestedPageTop,
14980
+ source: "column",
14981
+ getBounds: (_linePage, column) => ({
14982
+ lineWidth: Math.max(getFiniteWidth(column.width), visualWidth - column.left),
14983
+ visualLeft: nestedPageLeft + column.left,
14984
+ visualWidth: Math.max(getFiniteWidth(column.width), visualWidth - column.left)
14985
+ })
14986
+ }, cb);
14987
+ });
14988
+ });
14989
+ });
14990
+ }
14991
+ function getDocumentSkeletonNestedPageOffset(page) {
14992
+ var _parent$parent, _parent$parent$column;
14993
+ const parent = page.parent;
14994
+ if ((parent === null || parent === void 0 ? void 0 : parent.page) === page && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.columnGroupId) && ((_parent$parent$column = parent.parent.columns) === null || _parent$parent$column === void 0 ? void 0 : _parent$parent$column.includes(parent))) {
14995
+ var _parent$parent$left, _parent$left, _parent$parent$top, _parent$top;
14996
+ return {
14997
+ left: ((_parent$parent$left = parent.parent.left) !== null && _parent$parent$left !== void 0 ? _parent$parent$left : 0) + ((_parent$left = parent.left) !== null && _parent$left !== void 0 ? _parent$left : 0),
14998
+ top: ((_parent$parent$top = parent.parent.top) !== null && _parent$parent$top !== void 0 ? _parent$parent$top : 0) + ((_parent$top = parent.top) !== null && _parent$top !== void 0 ? _parent$top : 0)
14999
+ };
15000
+ }
15001
+ }
15002
+ function getDocumentSkeletonColumnPagePathInfo(position) {
15003
+ var _path$indexOf, _path$indexOf2, _path$indexOf3;
15004
+ const { path } = position;
15005
+ const pagesIndex = (_path$indexOf = path === null || path === void 0 ? void 0 : path.indexOf("pages")) !== null && _path$indexOf !== void 0 ? _path$indexOf : -1;
15006
+ const columnGroupIndex = (_path$indexOf2 = path === null || path === void 0 ? void 0 : path.indexOf("skeColumnGroups")) !== null && _path$indexOf2 !== void 0 ? _path$indexOf2 : -1;
15007
+ const columnsIndex = (_path$indexOf3 = path === null || path === void 0 ? void 0 : path.indexOf("columns")) !== null && _path$indexOf3 !== void 0 ? _path$indexOf3 : -1;
15008
+ if (pagesIndex === -1 || columnGroupIndex === -1 || columnsIndex === -1 || (path === null || path === void 0 ? void 0 : path[columnsIndex + 2]) !== "page") return;
15009
+ const pageIndex = path === null || path === void 0 ? void 0 : path[pagesIndex + 1];
15010
+ const columnGroupId = path === null || path === void 0 ? void 0 : path[columnGroupIndex + 1];
15011
+ const columnIndex = path === null || path === void 0 ? void 0 : path[columnsIndex + 1];
15012
+ if (typeof pageIndex !== "number" || typeof columnGroupId !== "string" || typeof columnIndex !== "number") return;
15013
+ return {
15014
+ columnGroupId,
15015
+ columnIndex,
15016
+ pageIndex
15017
+ };
15018
+ }
15019
+ function compareDocumentSkeletonNestedPagePathOrder(pos1, pos2) {
15020
+ const columnGroupOrder1 = getDocumentSkeletonColumnPagePathInfo(pos1);
15021
+ const columnGroupOrder2 = getDocumentSkeletonColumnPagePathInfo(pos2);
15022
+ if (columnGroupOrder1 && columnGroupOrder2 && columnGroupOrder1.pageIndex === columnGroupOrder2.pageIndex && columnGroupOrder1.columnGroupId === columnGroupOrder2.columnGroupId && columnGroupOrder1.columnIndex !== columnGroupOrder2.columnIndex) return columnGroupOrder1.columnIndex < columnGroupOrder2.columnIndex;
15023
+ }
15024
+ function visitPageLines(page, options, cb) {
15025
+ page.sections.forEach((section) => {
15026
+ section.columns.forEach((column) => {
15027
+ column.lines.forEach((line) => {
15028
+ var _options$getBounds, _ref, _bounds$lineWidth, _bounds$visualLeft, _bounds$visualWidth;
15029
+ const bounds = (_options$getBounds = options.getBounds) === null || _options$getBounds === void 0 ? void 0 : _options$getBounds.call(options, page, column, section);
15030
+ cb({
15031
+ clipLeft: options.clipLeft,
15032
+ clipRight: options.clipRight,
15033
+ column,
15034
+ line,
15035
+ lineWidth: (_ref = (_bounds$lineWidth = bounds === null || bounds === void 0 ? void 0 : bounds.lineWidth) !== null && _bounds$lineWidth !== void 0 ? _bounds$lineWidth : bounds === null || bounds === void 0 ? void 0 : bounds.visualWidth) !== null && _ref !== void 0 ? _ref : getFiniteWidth(column.width),
15036
+ page,
15037
+ pageIndex: options.pageIndex,
15038
+ pageLeft: options.pageLeft,
15039
+ section,
15040
+ sectionTop: options.pageTop + section.top,
15041
+ source: options.source,
15042
+ visualLeft: (_bounds$visualLeft = bounds === null || bounds === void 0 ? void 0 : bounds.visualLeft) !== null && _bounds$visualLeft !== void 0 ? _bounds$visualLeft : options.visualLeft,
15043
+ visualWidth: (_bounds$visualWidth = bounds === null || bounds === void 0 ? void 0 : bounds.visualWidth) !== null && _bounds$visualWidth !== void 0 ? _bounds$visualWidth : options.visualWidth
15044
+ });
15045
+ });
15046
+ });
15047
+ });
15048
+ }
15049
+ function getPageLineBounds(page, column, columnCount, pageLeft) {
15050
+ if (columnCount !== 1 || !Number.isFinite(page.pageWidth)) return;
15051
+ const visualLeft = pageLeft + column.left;
15052
+ const visualRight = page.pageWidth - page.marginRight;
15053
+ const visualWidth = Math.max(0, visualRight - visualLeft);
15054
+ const lineWidth = Math.max(0, page.pageWidth - page.marginLeft - page.marginRight);
15055
+ return visualWidth > 0 ? {
15056
+ lineWidth,
15057
+ visualLeft,
15058
+ visualWidth
15059
+ } : void 0;
15060
+ }
15061
+ function collectPageTables(options) {
15062
+ var _page$skeTables2;
15063
+ const { contexts, docsLeft, page, pageIndex, pageLeft, pageTop, resolveViewport, rootPage, source, tableCellInsetX, unitId } = options;
15064
+ (_page$skeTables2 = page.skeTables) === null || _page$skeTables2 === void 0 || _page$skeTables2.forEach((table, tableId) => {
15065
+ var _table$tableId;
15066
+ const effectiveTableId = (_table$tableId = table.tableId) !== null && _table$tableId !== void 0 ? _table$tableId : tableId;
15067
+ const tableLeft = pageLeft + table.left;
15068
+ const tableTop = pageTop + table.top;
15069
+ const sourceTableId = getSourceTableId(effectiveTableId);
15070
+ const viewport = resolveViewport ? getDocsTableRenderViewport(unitId, sourceTableId) : null;
15071
+ const hasHorizontalViewport = hasDocsTableHorizontalViewport(viewport);
15072
+ const tableViewportLeft = getTableViewportLeft(pageLeft, table.left, viewport, docsLeft);
15073
+ const tableViewportRight = tableViewportLeft + (hasHorizontalViewport ? viewport.viewportWidth : table.width);
15074
+ const tableScrollLeft = hasHorizontalViewport ? viewport.scrollLeft : 0;
15075
+ const cells = [];
15076
+ table.rows.forEach((row, rowIndex) => {
15077
+ row.cells.forEach((cell, columnIndex) => {
15078
+ var _cell$marginLeft, _cell$marginRight, _cell$marginTop, _cell$marginBottom, _cell$pageWidth, _cell$pageHeight, _row$top, _cell$left;
15079
+ if (cell.isMergedCellCovered) return;
15080
+ const cellMarginLeft = (_cell$marginLeft = cell.marginLeft) !== null && _cell$marginLeft !== void 0 ? _cell$marginLeft : 0;
15081
+ const cellMarginRight = (_cell$marginRight = cell.marginRight) !== null && _cell$marginRight !== void 0 ? _cell$marginRight : 0;
15082
+ const cellMarginTop = (_cell$marginTop = cell.marginTop) !== null && _cell$marginTop !== void 0 ? _cell$marginTop : 0;
15083
+ const cellMarginBottom = (_cell$marginBottom = cell.marginBottom) !== null && _cell$marginBottom !== void 0 ? _cell$marginBottom : 0;
15084
+ const cellPageWidth = (_cell$pageWidth = cell.pageWidth) !== null && _cell$pageWidth !== void 0 ? _cell$pageWidth : 0;
15085
+ const cellPageHeight = (_cell$pageHeight = cell.pageHeight) !== null && _cell$pageHeight !== void 0 ? _cell$pageHeight : 0;
15086
+ const cellTop = tableTop + ((_row$top = row.top) !== null && _row$top !== void 0 ? _row$top : 0) + cellMarginTop;
15087
+ const cellLeft = tableLeft + ((_cell$left = cell.left) !== null && _cell$left !== void 0 ? _cell$left : 0) - tableScrollLeft + cellMarginLeft;
15088
+ const cellContentRight = cellLeft + cellPageWidth - cellMarginLeft - cellMarginRight;
15089
+ const visualLeft = cellLeft + tableCellInsetX;
15090
+ const visualRight = cellContentRight - tableCellInsetX;
15091
+ const visualWidth = Math.max(0, visualRight - visualLeft);
15092
+ const clipLeft = tableViewportLeft;
15093
+ const clipRight = Math.min(cellContentRight, tableViewportRight);
15094
+ if (visualWidth <= 0 || Math.min(visualRight, clipRight) <= Math.max(visualLeft, clipLeft)) return;
15095
+ cells.push({
15096
+ cell,
15097
+ cellRect: {
15098
+ bottom: cellTop + cellPageHeight - cellMarginBottom - cellMarginTop,
15099
+ left: Math.max(cellLeft, tableViewportLeft),
15100
+ right: Math.min(cellContentRight, tableViewportRight),
15101
+ top: cellTop
15102
+ },
15103
+ clipLeft,
15104
+ clipRight,
15105
+ columnIndex,
15106
+ pageLeft: cellLeft,
15107
+ pageTop: cellTop,
15108
+ row,
15109
+ rowIndex,
15110
+ visualLeft,
15111
+ visualWidth
15112
+ });
15113
+ });
15114
+ });
15115
+ contexts.push({
15116
+ cells,
15117
+ page,
15118
+ pageIndex,
15119
+ pageLeft,
15120
+ pageTop,
15121
+ rootPage,
15122
+ source,
15123
+ table,
15124
+ tableId: effectiveTableId,
15125
+ tableRect: {
15126
+ bottom: tableTop + table.height,
15127
+ left: tableLeft,
15128
+ right: tableLeft + table.width,
15129
+ top: tableTop
15130
+ }
15131
+ });
15132
+ });
15133
+ }
15134
+ function getTableViewportLeft(pageLeft, tableLeft, viewport, docsLeft) {
15135
+ const viewportLeft = viewport === null || viewport === void 0 ? void 0 : viewport.viewportLeft;
15136
+ return viewportLeft != null ? viewportLeft - docsLeft : pageLeft + tableLeft;
15137
+ }
15138
+ function getSourceTableId(tableId) {
15139
+ return tableId.includes("#-#") ? tableId.split("#-#")[0] : tableId;
15140
+ }
15141
+ function getFiniteWidth(width) {
15142
+ return Number.isFinite(width) ? width : 0;
15143
+ }
14722
15144
  function columnIterator(pages, iteratorFunction) {
14723
15145
  for (const page of pages) {
14724
15146
  const { sections } = page;
@@ -14741,7 +15163,14 @@ function getPositionHorizon(positionH, column, page, objectWidth, isPageBreak =
14741
15163
  else if (align === _univerjs_core.AlignTypeH.CENTER) absoluteLeft = left + width / 2 - objectWidth / 2;
14742
15164
  return absoluteLeft;
14743
15165
  }
14744
- if (relativeFrom === _univerjs_core.ObjectRelativeFromH.LEFT_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.RIGHT_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.INSIDE_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.OUTSIDE_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.PAGE) {
15166
+ if (relativeFrom === _univerjs_core.ObjectRelativeFromH.LEFT_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.MARGIN) {
15167
+ const { pageWidth, marginLeft, marginRight } = page;
15168
+ const marginWidth = pageWidth - marginLeft - marginRight;
15169
+ let absoluteLeft = marginLeft;
15170
+ if (align === _univerjs_core.AlignTypeH.RIGHT) absoluteLeft = marginLeft + marginWidth - objectWidth;
15171
+ else if (align === _univerjs_core.AlignTypeH.CENTER) absoluteLeft = marginLeft + marginWidth / 2 - objectWidth / 2;
15172
+ return absoluteLeft;
15173
+ } else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.RIGHT_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.INSIDE_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.OUTSIDE_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.PAGE) {
14745
15174
  const { pageWidth } = page;
14746
15175
  let absoluteLeft = 0;
14747
15176
  if (align === _univerjs_core.AlignTypeH.RIGHT) absoluteLeft = pageWidth - objectWidth;
@@ -15022,6 +15451,13 @@ function getPageFromPath(skeletonData, path) {
15022
15451
  pathCopy.shift();
15023
15452
  const cellIndex = pathCopy.shift();
15024
15453
  page = (_skeTables = page.skeTables) === null || _skeTables === void 0 || (_skeTables = _skeTables.get(tableId)) === null || _skeTables === void 0 || (_skeTables = _skeTables.rows[rowIndex]) === null || _skeTables === void 0 ? void 0 : _skeTables.cells[cellIndex];
15454
+ } else if (field === "skeColumnGroups") {
15455
+ var _skeColumnGroups;
15456
+ const columnGroupId = pathCopy.shift();
15457
+ pathCopy.shift();
15458
+ const columnIndex = pathCopy.shift();
15459
+ pathCopy.shift();
15460
+ page = (_skeColumnGroups = page.skeColumnGroups) === null || _skeColumnGroups === void 0 || (_skeColumnGroups = _skeColumnGroups.get(columnGroupId)) === null || _skeColumnGroups === void 0 || (_skeColumnGroups = _skeColumnGroups.columns[columnIndex]) === null || _skeColumnGroups === void 0 ? void 0 : _skeColumnGroups.page;
15025
15461
  }
15026
15462
  }
15027
15463
  return page;
@@ -15128,11 +15564,13 @@ function _getNullPage(type = 0, segmentId = "") {
15128
15564
  ed: 0,
15129
15565
  skeDrawings: /* @__PURE__ */ new Map(),
15130
15566
  skeTables: /* @__PURE__ */ new Map(),
15567
+ skeColumnGroups: /* @__PURE__ */ new Map(),
15131
15568
  type,
15132
15569
  segmentId
15133
15570
  };
15134
15571
  }
15135
15572
  function _createSkeletonHeaderFooter(ctx, headerOrFooterViewModel, sectionBreakConfig, skeletonResourceReference, segmentId, isHeader = true, areaPage, count = 0) {
15573
+ var _sectionBreakConfig$d;
15136
15574
  const { lists, footerTreeMap, headerTreeMap, localeService, pageSize, drawings, marginLeft = 0, marginRight = 0, marginHeader = 0, marginFooter = 0 } = sectionBreakConfig;
15137
15575
  const pageWidth = (pageSize === null || pageSize === void 0 ? void 0 : pageSize.width) || Number.POSITIVE_INFINITY;
15138
15576
  const pageHeight = (pageSize === null || pageSize === void 0 ? void 0 : pageSize.height) || Number.POSITIVE_INFINITY;
@@ -15160,7 +15598,7 @@ function _createSkeletonHeaderFooter(ctx, headerOrFooterViewModel, sectionBreakC
15160
15598
  resetContext(ctx);
15161
15599
  return _createSkeletonHeaderFooter(ctx, headerOrFooterViewModel, sectionBreakConfig, skeletonResourceReference, segmentId, isHeader, areaPage, count);
15162
15600
  }
15163
- updateBlockIndex([page]);
15601
+ updateBlockIndex([page], -1, (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy());
15164
15602
  if (isHeader) Object.assign(page, {
15165
15603
  marginTop: marginHeader,
15166
15604
  marginBottom: 5
@@ -15221,7 +15659,7 @@ function createNullCellPage(ctx, sectionBreakConfig, tableConfig, row, col, avai
15221
15659
  };
15222
15660
  }
15223
15661
  function createSkeletonCellPages(ctx, viewModel, cellNode, sectionBreakConfig, tableConfig, row, col, availableHeight = Number.POSITIVE_INFINITY, maxCellPageHeight = Number.POSITIVE_INFINITY) {
15224
- var _ctx$dataModel, _ctx$dataModel$getBod;
15662
+ var _sectionBreakConfig$d2, _ctx$dataModel, _ctx$dataModel$getBod;
15225
15663
  const sectionNode = cellNode.children[0];
15226
15664
  const { page: areaPage, sectionBreakConfig: cellSectionBreakConfig } = createNullCellPage(ctx, sectionBreakConfig, tableConfig, row, col, availableHeight, maxCellPageHeight);
15227
15665
  const { pages } = dealWithSection(ctx, viewModel, sectionNode, areaPage, cellSectionBreakConfig);
@@ -15229,8 +15667,8 @@ function createSkeletonCellPages(ctx, viewModel, cellNode, sectionBreakConfig, t
15229
15667
  p.type = 3;
15230
15668
  p.segmentId = tableConfig.tableId;
15231
15669
  }
15232
- updateBlockIndex(pages, cellNode.startIndex);
15233
- applyTrailingCellBlockRangeSpaceBelow(pages, (_ctx$dataModel = ctx.dataModel) === null || _ctx$dataModel === void 0 || (_ctx$dataModel$getBod = _ctx$dataModel.getBody) === null || _ctx$dataModel$getBod === void 0 ? void 0 : _ctx$dataModel$getBod.call(_ctx$dataModel), cellNode.endIndex);
15670
+ updateBlockIndex(pages, cellNode.startIndex, (_sectionBreakConfig$d2 = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d2 !== void 0 ? _sectionBreakConfig$d2 : getDocumentCompatibilityPolicy());
15671
+ applyTrailingBlockRangeSpaceBelow(pages, (_ctx$dataModel = ctx.dataModel) === null || _ctx$dataModel === void 0 || (_ctx$dataModel$getBod = _ctx$dataModel.getBody) === null || _ctx$dataModel$getBod === void 0 ? void 0 : _ctx$dataModel$getBod.call(_ctx$dataModel), cellNode.endIndex);
15234
15672
  updateInlineDrawingCoordsAndBorder(ctx, pages);
15235
15673
  expandCellPageHeightForInlineDrawings(pages);
15236
15674
  return pages;
@@ -15246,7 +15684,7 @@ function expandCellPageHeightForInlineDrawings(pages) {
15246
15684
  });
15247
15685
  }
15248
15686
  }
15249
- function applyTrailingCellBlockRangeSpaceBelow(pages, body, cellEndIndex) {
15687
+ function applyTrailingBlockRangeSpaceBelow(pages, body, containerEndIndex) {
15250
15688
  const blockRanges = body === null || body === void 0 ? void 0 : body.blockRanges;
15251
15689
  const trailingBlockRangeSpace = 28;
15252
15690
  if (!(blockRanges === null || blockRanges === void 0 ? void 0 : blockRanges.length)) return;
@@ -15256,7 +15694,7 @@ function applyTrailingCellBlockRangeSpaceBelow(pages, body, cellEndIndex) {
15256
15694
  if (!lastLine) continue;
15257
15695
  const paragraphIndex = lastLine.paragraphIndex;
15258
15696
  if (!blockRanges.some((range) => range.startIndex < paragraphIndex && paragraphIndex < range.endIndex)) continue;
15259
- if (body === null || body === void 0 || (_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.some((paragraph) => paragraph.startIndex > paragraphIndex && paragraph.startIndex < cellEndIndex)) continue;
15697
+ if (body === null || body === void 0 || (_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.some((paragraph) => paragraph.startIndex > paragraphIndex && paragraph.startIndex < containerEndIndex)) continue;
15260
15698
  page.height += lastLine.spaceBelowApply || trailingBlockRangeSpace;
15261
15699
  }
15262
15700
  }
@@ -15368,6 +15806,15 @@ function adjustGlyphsInDivide(divide, justificationRatio, extraJustification) {
15368
15806
  }
15369
15807
  setGlyphGroupLeft(divide.glyphGroup);
15370
15808
  }
15809
+ function distributeGlyphsInDivide(divide, remaining) {
15810
+ if (remaining <= 0) return false;
15811
+ const visibleGlyphs = divide.glyphGroup.filter((glyph) => glyph.content !== "" && glyph.width > 0);
15812
+ if (visibleGlyphs.length < 2) return false;
15813
+ const extraGap = remaining / (visibleGlyphs.length - 1);
15814
+ for (let i = 0; i < visibleGlyphs.length - 1; i++) visibleGlyphs[i].width += extraGap;
15815
+ setGlyphGroupLeft(divide.glyphGroup);
15816
+ return true;
15817
+ }
15371
15818
  /**
15372
15819
  * When aligning text horizontally within a document,
15373
15820
  * it may be ineffective if the total line width is not initially calculated.
@@ -15433,7 +15880,13 @@ function horizontalAlignHandler(line, horizontalAlign, allowOverflowHorizontalOf
15433
15880
  }
15434
15881
  }
15435
15882
  const inkBounds = allowOverflowHorizontalOffset ? getGlyphGroupInkBounds(divide) : null;
15436
- if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER && inkBounds) divide.paddingLeft = width / 2 - (inkBounds.left + inkBounds.right) / 2;
15883
+ if (horizontalAlign === _univerjs_core.HorizontalAlign.DISTRIBUTED) {
15884
+ if (distributeGlyphsInDivide(divide, width - glyphGroupWidth)) {
15885
+ glyphGroupWidth = getGlyphGroupWidth(divide);
15886
+ divide.glyphGroupWidth = glyphGroupWidth;
15887
+ }
15888
+ divide.paddingLeft = 0;
15889
+ } else if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER && inkBounds) divide.paddingLeft = width / 2 - (inkBounds.left + inkBounds.right) / 2;
15437
15890
  else if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT && inkBounds) divide.paddingLeft = width - inkBounds.right;
15438
15891
  else if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER) divide.paddingLeft = (width - glyphGroupWidth) / 2;
15439
15892
  else if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT) divide.paddingLeft = width - glyphGroupWidth;
@@ -15705,6 +16158,14 @@ function _isMarkedDocxColumnBreak(viewModel, absoluteIndex) {
15705
16158
  function _glyphCount(glyphs) {
15706
16159
  return glyphs.reduce((count, glyph) => count + glyph.count, 0);
15707
16160
  }
16161
+ function _isDocxColumnBreakVisuallyBlankColumn(column) {
16162
+ return column.lines.every((line) => line.divides.every((divide) => divide.glyphGroup.every((glyph) => {
16163
+ const { glyphType, raw, streamType, width } = glyph;
16164
+ const isParagraphMark = raw === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH || streamType === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH;
16165
+ const isColumnBreak = width === 0 && (raw === _univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK || streamType === _univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK);
16166
+ return glyphType === 4 || glyphType === 2 || isParagraphMark || isColumnBreak;
16167
+ })));
16168
+ }
15708
16169
  function _hasOnlyCustomBlockGlyphs(glyphs) {
15709
16170
  return glyphs.length > 0 && glyphs.every((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK);
15710
16171
  }
@@ -15761,7 +16222,9 @@ function _withMinSpacing(style, key, value) {
15761
16222
  };
15762
16223
  }
15763
16224
  function _getNextAdjacentBlockRange(blockRanges, blockRange) {
15764
- return blockRanges === null || blockRanges === void 0 ? void 0 : blockRanges.filter((range) => range.startIndex > blockRange.endIndex).sort((left, right) => left.startIndex - right.startIndex)[0];
16225
+ let nextBlockRange;
16226
+ for (const range of blockRanges !== null && blockRanges !== void 0 ? blockRanges : []) if (range.startIndex > blockRange.endIndex && (!nextBlockRange || range.startIndex < nextBlockRange.startIndex)) nextBlockRange = range;
16227
+ return nextBlockRange;
15765
16228
  }
15766
16229
  function _hasNextAdjacentLayoutBlockRange(blockRanges, blockRange) {
15767
16230
  const nextBlockRange = _getNextAdjacentBlockRange(blockRanges, blockRange);
@@ -15926,7 +16389,12 @@ function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, se
15926
16389
  const lastPage = allPages[allPages.length - 1];
15927
16390
  const columnInfo = getLastNotFullColumnInfo(lastPage);
15928
16391
  if (columnInfo && !columnInfo.isLast) setColumnFullState(columnInfo.column, true);
15929
- else allPages.push(createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(lastPage), 2));
16392
+ else if (columnInfo && columnInfo.isLast && isTraditionalDocumentCompatibility(documentCompatibilityPolicy) && (isBlankColumn(columnInfo.column) || _isDocxColumnBreakVisuallyBlankColumn(columnInfo.column))) {} else if (isTraditionalDocumentCompatibility(documentCompatibilityPolicy)) {
16393
+ var _getLastSection;
16394
+ const lastColumn = (_getLastSection = getLastSection(lastPage)) === null || _getLastSection === void 0 ? void 0 : _getLastSection.columns.at(-1);
16395
+ if (lastColumn && (isBlankColumn(lastColumn) || _isDocxColumnBreakVisuallyBlankColumn(lastColumn))) setColumnFullState(lastColumn, false);
16396
+ else allPages.push(createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(lastPage), 2));
16397
+ } else allPages.push(createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(lastPage), 2));
15930
16398
  shapedTextOffset += textGlyphCount;
15931
16399
  continue;
15932
16400
  }
@@ -16680,6 +17148,219 @@ function dealWidthParagraph(ctx, viewModel, paragraphNode, curPage, sectionBreak
16680
17148
  return allPages;
16681
17149
  }
16682
17150
 
17151
+ //#endregion
17152
+ //#region src/components/docs/layout/block/column.ts
17153
+ const EMPTY_COLUMN_GROUP_MIN_HEIGHT = 72;
17154
+ function createColumnGroupSkeleton(ctx, curPage, viewModel, columnGroupNode, sectionBreakConfig) {
17155
+ var _viewModel$getColumnG, _getLastNotFullColumn;
17156
+ const columnGroupSource = (_viewModel$getColumnG = viewModel.getColumnGroupByStartIndex(columnGroupNode.startIndex)) === null || _viewModel$getColumnG === void 0 ? void 0 : _viewModel$getColumnG.columnGroupSource;
17157
+ if (columnGroupSource == null) {
17158
+ console.warn("Column group not found when creating column group skeleton");
17159
+ return null;
17160
+ }
17161
+ const hostColumn = (_getLastNotFullColumn = getLastNotFullColumnInfo(curPage)) === null || _getLastNotFullColumn === void 0 ? void 0 : _getLastNotFullColumn.column;
17162
+ if (hostColumn == null) return null;
17163
+ const columnPages = columnGroupNode.children.map((columnNode, index) => {
17164
+ const sourceColumn = columnGroupSource.columns[index];
17165
+ return createColumnContentPage(ctx, viewModel, columnNode, sectionBreakConfig, Math.max(0, getInitialColumnWidth(columnGroupSource, sourceColumn, hostColumn.width)));
17166
+ });
17167
+ const columnHeights = columnPages.map((page) => Math.max(page.height, EMPTY_COLUMN_GROUP_MIN_HEIGHT));
17168
+ const layout = calculateColumnGroupLayout(columnGroupSource, hostColumn.width, columnHeights);
17169
+ const columns = layout.columns.map((layoutColumn, index) => {
17170
+ const page = columnPages[index];
17171
+ page.pageHeight = columnHeights[index];
17172
+ return {
17173
+ columnId: layoutColumn.columnId,
17174
+ left: layoutColumn.left,
17175
+ top: layoutColumn.top,
17176
+ width: layoutColumn.width,
17177
+ height: columnHeights[index],
17178
+ st: columnGroupNode.children[index].startIndex,
17179
+ ed: columnGroupNode.children[index].endIndex,
17180
+ page
17181
+ };
17182
+ });
17183
+ const columnGroupSkeleton = {
17184
+ columns,
17185
+ width: layout.width,
17186
+ height: layout.height,
17187
+ top: getNextBlockTop(hostColumn.lines),
17188
+ left: hostColumn.left,
17189
+ st: columnGroupNode.startIndex,
17190
+ ed: columnGroupNode.endIndex,
17191
+ columnGroupId: columnGroupSource.columnGroupId,
17192
+ columnGroupSource
17193
+ };
17194
+ columns.forEach((column) => {
17195
+ column.parent = columnGroupSkeleton;
17196
+ column.page.parent = column;
17197
+ });
17198
+ return columnGroupSkeleton;
17199
+ }
17200
+ function appendColumnGroupBlockLine(page, columnGroup) {
17201
+ const columnInfo = getLastNotFullColumnInfo(page);
17202
+ if (columnInfo == null) return false;
17203
+ const { column } = columnInfo;
17204
+ const line = createColumnGroupBlockLine(columnGroup, column.lines.length);
17205
+ line.parent = column;
17206
+ column.lines.push(line);
17207
+ page.skeColumnGroups.set(columnGroup.columnGroupId, columnGroup);
17208
+ columnGroup.parent = page;
17209
+ return true;
17210
+ }
17211
+ function createColumnContentPage(ctx, viewModel, columnNode, sectionBreakConfig, width) {
17212
+ var _sectionBreakConfig$d, _ctx$dataModel, _ctx$dataModel$getBod;
17213
+ const columnSectionBreakConfig = {
17214
+ ...sectionBreakConfig,
17215
+ pageSize: {
17216
+ width,
17217
+ height: Number.POSITIVE_INFINITY
17218
+ },
17219
+ marginTop: 0,
17220
+ marginBottom: 0,
17221
+ marginLeft: 0,
17222
+ marginRight: 0,
17223
+ columnProperties: []
17224
+ };
17225
+ const page = createSkeletonPage(ctx, columnSectionBreakConfig, ctx.skeletonResourceReference);
17226
+ page.type = 3;
17227
+ for (const paragraphNode of getColumnParagraphNodes(columnNode)) dealWidthParagraph(ctx, viewModel, paragraphNode, page, columnSectionBreakConfig);
17228
+ updateBlockIndex([page], columnNode.startIndex, (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy());
17229
+ applyTrailingBlockRangeSpaceBelow([page], (_ctx$dataModel = ctx.dataModel) === null || _ctx$dataModel === void 0 || (_ctx$dataModel$getBod = _ctx$dataModel.getBody) === null || _ctx$dataModel$getBod === void 0 ? void 0 : _ctx$dataModel$getBod.call(_ctx$dataModel), columnNode.endIndex);
17230
+ return page;
17231
+ }
17232
+ function getColumnParagraphNodes(columnNode) {
17233
+ const firstChild = columnNode.children[0];
17234
+ if ((firstChild === null || firstChild === void 0 ? void 0 : firstChild.nodeType) === _univerjs_core.DataStreamTreeNodeType.SECTION_BREAK) return firstChild.children;
17235
+ return columnNode.children;
17236
+ }
17237
+ function createColumnGroupBlockLine(columnGroup, lineIndex) {
17238
+ const top = columnGroup.top;
17239
+ return {
17240
+ paragraphIndex: columnGroup.ed,
17241
+ type: 1,
17242
+ divides: [],
17243
+ divideLen: 0,
17244
+ lineHeight: columnGroup.height,
17245
+ contentHeight: columnGroup.height,
17246
+ top,
17247
+ asc: 0,
17248
+ dsc: 0,
17249
+ paddingTop: 0,
17250
+ paddingBottom: 0,
17251
+ marginTop: 0,
17252
+ marginBottom: 0,
17253
+ spaceBelowApply: 0,
17254
+ st: columnGroup.st,
17255
+ ed: columnGroup.ed,
17256
+ lineIndex,
17257
+ paragraphStart: true,
17258
+ isBehindTable: false,
17259
+ tableId: ""
17260
+ };
17261
+ }
17262
+ function getNextBlockTop(lines) {
17263
+ const lastLine = lines[lines.length - 1];
17264
+ if (lastLine == null) return 0;
17265
+ return lastLine.top + lastLine.lineHeight;
17266
+ }
17267
+ function calculateColumnGroupLayout(source, availableWidth, columnHeights) {
17268
+ var _source$gap$v, _source$gap;
17269
+ const width = Math.max(0, availableWidth);
17270
+ const gap = Math.max(0, (_source$gap$v = (_source$gap = source.gap) === null || _source$gap === void 0 ? void 0 : _source$gap.v) !== null && _source$gap$v !== void 0 ? _source$gap$v : 0);
17271
+ const columns = source.columns;
17272
+ if (columns.length === 0) return {
17273
+ mode: "horizontal",
17274
+ width,
17275
+ height: 0,
17276
+ columns: []
17277
+ };
17278
+ if (shouldStack(columns, width, gap, source.responsive)) {
17279
+ let top = 0;
17280
+ return {
17281
+ mode: "stack",
17282
+ width,
17283
+ height: sumHeights(columnHeights),
17284
+ columns: columns.map((column, index) => {
17285
+ var _columnHeights$index;
17286
+ const layoutColumn = {
17287
+ columnId: column.columnId,
17288
+ left: 0,
17289
+ top,
17290
+ width
17291
+ };
17292
+ top += Math.max(0, (_columnHeights$index = columnHeights[index]) !== null && _columnHeights$index !== void 0 ? _columnHeights$index : 0);
17293
+ return layoutColumn;
17294
+ })
17295
+ };
17296
+ }
17297
+ const widths = allocateHorizontalWidths(columns, Math.max(0, width - gap * (columns.length - 1)));
17298
+ let left = 0;
17299
+ return {
17300
+ mode: "horizontal",
17301
+ width,
17302
+ height: Math.max(0, ...columnHeights),
17303
+ columns: columns.map((column, index) => {
17304
+ const layoutColumn = {
17305
+ columnId: column.columnId,
17306
+ left,
17307
+ top: 0,
17308
+ width: widths[index]
17309
+ };
17310
+ left += widths[index] + gap;
17311
+ return layoutColumn;
17312
+ })
17313
+ };
17314
+ }
17315
+ function shouldStack(columns, availableWidth, gap, responsive) {
17316
+ if (responsive !== _univerjs_core.ColumnResponsiveType.STACK) return false;
17317
+ return columns.reduce((sum, column) => sum + getMinWidth(column), 0) + gap * Math.max(0, columns.length - 1) > availableWidth;
17318
+ }
17319
+ function getInitialColumnWidth(source, column, availableWidth) {
17320
+ var _source$gap$v2, _source$gap2;
17321
+ if (column == null) return availableWidth;
17322
+ const contentWidth = Math.max(0, availableWidth - Math.max(0, (_source$gap$v2 = (_source$gap2 = source.gap) === null || _source$gap2 === void 0 ? void 0 : _source$gap2.v) !== null && _source$gap$v2 !== void 0 ? _source$gap$v2 : 0) * Math.max(0, source.columns.length - 1));
17323
+ const ratioSum = source.columns.reduce((sum, item) => sum + Math.max(0, item.widthRatio || 0), 0) || source.columns.length;
17324
+ return Math.max(getMinWidth(column), contentWidth * (Math.max(0, column.widthRatio || 0) || 1) / ratioSum);
17325
+ }
17326
+ function allocateHorizontalWidths(columns, contentWidth) {
17327
+ const ratioSum = columns.reduce((sum, column) => sum + Math.max(0, column.widthRatio || 0), 0) || columns.length;
17328
+ const idealWidths = columns.map((column) => contentWidth * (Math.max(0, column.widthRatio || 0) || 1) / ratioSum);
17329
+ const minWidths = columns.map(getMinWidth);
17330
+ const widths = idealWidths.map((width, index) => Math.max(width, minWidths[index]));
17331
+ const overflow = widths.reduce((sum, width) => sum + width, 0) - contentWidth;
17332
+ if (overflow <= 0) return widths;
17333
+ return compressToFit(widths, minWidths, overflow);
17334
+ }
17335
+ function compressToFit(widths, minWidths, overflow) {
17336
+ const nextWidths = [...widths];
17337
+ let remainingOverflow = overflow;
17338
+ let flexibleIndexes = getFlexibleIndexes(nextWidths, minWidths);
17339
+ while (remainingOverflow > 0 && flexibleIndexes.length > 0) {
17340
+ const totalShrink = flexibleIndexes.reduce((sum, item) => sum + item.shrink, 0);
17341
+ for (const item of flexibleIndexes) {
17342
+ const shrink = Math.min(item.shrink, remainingOverflow * item.shrink / totalShrink);
17343
+ nextWidths[item.index] -= shrink;
17344
+ remainingOverflow -= shrink;
17345
+ }
17346
+ flexibleIndexes = getFlexibleIndexes(nextWidths, minWidths);
17347
+ }
17348
+ return nextWidths;
17349
+ }
17350
+ function getFlexibleIndexes(widths, minWidths) {
17351
+ return widths.map((width, index) => ({
17352
+ index,
17353
+ shrink: Math.max(0, width - minWidths[index])
17354
+ })).filter((item) => item.shrink > 0);
17355
+ }
17356
+ function getMinWidth(column) {
17357
+ var _column$minWidth$v, _column$minWidth;
17358
+ return Math.max(0, (_column$minWidth$v = (_column$minWidth = column.minWidth) === null || _column$minWidth === void 0 ? void 0 : _column$minWidth.v) !== null && _column$minWidth$v !== void 0 ? _column$minWidth$v : 0);
17359
+ }
17360
+ function sumHeights(heights) {
17361
+ return heights.reduce((sum, height) => sum + Math.max(0, height), 0);
17362
+ }
17363
+
16683
17364
  //#endregion
16684
17365
  //#region src/components/docs/layout/block/section.ts
16685
17366
  function dealWithSection(ctx, viewModel, sectionNode, curPage, sectionBreakConfig, layoutAnchor) {
@@ -16704,6 +17385,10 @@ function dealWithSection(ctx, viewModel, sectionNode, curPage, sectionBreakConfi
16704
17385
  if (ctx.paragraphsOpenNewPage.has(paragraphNode.endIndex)) currentPageCache = createSkeletonPage(ctx, sectionBreakConfig, ctx.skeletonResourceReference, currentPageCache.pageNumber + 1);
16705
17386
  skeletonPages = dealWidthParagraph(ctx, viewModel, paragraphNode, currentPageCache, sectionBreakConfig);
16706
17387
  }
17388
+ if (paragraphNode.nodeType === _univerjs_core.DataStreamTreeNodeType.COLUMN_GROUP) {
17389
+ const columnGroupSkeleton = createColumnGroupSkeleton(ctx, currentPageCache, viewModel, paragraphNode, sectionBreakConfig);
17390
+ if (columnGroupSkeleton && appendColumnGroupBlockLine(currentPageCache, columnGroupSkeleton)) skeletonPages = [currentPageCache];
17391
+ }
16707
17392
  if (skeletonPages.length === 0) skeletonPages = dealWithBlockError();
16708
17393
  _pushPage(allCurrentSkeletonPages, skeletonPages);
16709
17394
  if (ctx.isDirty) break;
@@ -17086,11 +17771,49 @@ function removeDupPages(ctx) {
17086
17771
  return !hasPage;
17087
17772
  });
17088
17773
  }
17774
+ function mergeContinuousDuplicatePages(pages) {
17775
+ for (let index = 1; index < pages.length;) {
17776
+ var _page$skeDrawings, _page$skeTables;
17777
+ const previousPage = pages[index - 1];
17778
+ const page = pages[index];
17779
+ if (previousPage.pageNumber !== page.pageNumber) {
17780
+ index++;
17781
+ continue;
17782
+ }
17783
+ const topOffset = previousPage.height;
17784
+ for (const section of page.sections) {
17785
+ section.top += topOffset;
17786
+ section.parent = previousPage;
17787
+ previousPage.sections.push(section);
17788
+ }
17789
+ (_page$skeDrawings = page.skeDrawings) === null || _page$skeDrawings === void 0 || _page$skeDrawings.forEach((drawing, drawingId) => {
17790
+ drawing.aTop += topOffset;
17791
+ previousPage.skeDrawings.set(drawingId, drawing);
17792
+ });
17793
+ (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 || _page$skeTables.forEach((table, tableId) => {
17794
+ table.top += topOffset;
17795
+ table.parent = previousPage;
17796
+ previousPage.skeTables.set(tableId, table);
17797
+ });
17798
+ previousPage.height += page.height;
17799
+ previousPage.width = Math.max(previousPage.width, page.width);
17800
+ previousPage.ed = Math.max(previousPage.ed, page.ed);
17801
+ pages.splice(index, 1);
17802
+ }
17803
+ }
17089
17804
  function getPagePath(page) {
17090
17805
  const path = [];
17091
17806
  let skeNode = page;
17092
17807
  let parent = skeNode.parent;
17093
17808
  while (parent) {
17809
+ var _parent$parent;
17810
+ if (parent.page === skeNode && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.columns)) {
17811
+ const index = parent.parent.columns.indexOf(parent);
17812
+ if (index !== -1) path.unshift("columns", index, "page");
17813
+ skeNode = parent.parent;
17814
+ parent = skeNode === null || skeNode === void 0 ? void 0 : skeNode.parent;
17815
+ continue;
17816
+ }
17094
17817
  if (parent.pages) {
17095
17818
  const index = parent.pages.indexOf(skeNode);
17096
17819
  if (index !== -1) path.unshift("pages", index);
@@ -17101,11 +17824,53 @@ function getPagePath(page) {
17101
17824
  const index = parent.rows.indexOf(skeNode);
17102
17825
  if (index !== -1) path.unshift("rows", index);
17103
17826
  } else if (parent.skeTables && parent.skeTables.has(skeNode.tableId)) path.unshift("skeTables", skeNode.tableId);
17827
+ else if (parent.skeColumnGroups && parent.skeColumnGroups.has(skeNode.columnGroupId)) path.unshift("skeColumnGroups", skeNode.columnGroupId);
17104
17828
  skeNode = parent;
17105
17829
  parent = parent === null || parent === void 0 ? void 0 : parent.parent;
17106
17830
  }
17107
17831
  return path;
17108
17832
  }
17833
+ function getBoundaryGlyphInPage(page, useLast) {
17834
+ const sections = useLast ? [...page.sections].reverse() : page.sections;
17835
+ for (const section of sections) {
17836
+ const columns = useLast ? [...section.columns].reverse() : section.columns;
17837
+ for (const column of columns) {
17838
+ const lines = useLast ? [...column.lines].reverse() : column.lines;
17839
+ for (const line of lines) {
17840
+ const divides = useLast ? [...line.divides].reverse() : line.divides;
17841
+ for (const divide of divides) {
17842
+ const glyph = (useLast ? [...divide.glyphGroup].reverse() : divide.glyphGroup).find((item) => {
17843
+ var _item$content;
17844
+ return (_item$content = item.content) === null || _item$content === void 0 ? void 0 : _item$content.length;
17845
+ });
17846
+ if (glyph) return {
17847
+ section,
17848
+ column,
17849
+ line,
17850
+ divide,
17851
+ glyph
17852
+ };
17853
+ }
17854
+ }
17855
+ }
17856
+ }
17857
+ }
17858
+ function isHitTestAddressableGlyph(glyph) {
17859
+ var _glyph$content;
17860
+ return Boolean((_glyph$content = glyph.content) === null || _glyph$content === void 0 ? void 0 : _glyph$content.length) || glyph.streamType === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH && glyph.count > 0;
17861
+ }
17862
+ function resolveMostSpecificPageByCharIndex(page, charIndex) {
17863
+ var _page$skeTables$value, _page$skeTables2, _page$skeColumnGroups, _page$skeColumnGroups2;
17864
+ for (const table of (_page$skeTables$value = (_page$skeTables2 = page.skeTables) === null || _page$skeTables2 === void 0 ? void 0 : _page$skeTables2.values()) !== null && _page$skeTables$value !== void 0 ? _page$skeTables$value : []) for (const row of table.rows) for (const cell of row.cells) {
17865
+ const { st, ed } = cell;
17866
+ if (charIndex >= st && charIndex <= ed) return resolveMostSpecificPageByCharIndex(cell, charIndex);
17867
+ }
17868
+ for (const columnGroup of (_page$skeColumnGroups = (_page$skeColumnGroups2 = page.skeColumnGroups) === null || _page$skeColumnGroups2 === void 0 ? void 0 : _page$skeColumnGroups2.values()) !== null && _page$skeColumnGroups !== void 0 ? _page$skeColumnGroups : []) for (const column of columnGroup.columns) {
17869
+ const { st, ed } = column;
17870
+ if (charIndex >= st && charIndex <= ed) return resolveMostSpecificPageByCharIndex(column.page, charIndex);
17871
+ }
17872
+ return page;
17873
+ }
17109
17874
  var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17110
17875
  constructor(_docViewModel, localeService) {
17111
17876
  super(localeService);
@@ -17405,7 +18170,7 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17405
18170
  return this._getNearestNode(cache.nearestNodeList, cache.nearestNodeDistanceList);
17406
18171
  }
17407
18172
  _collectNearestNode(segmentPage, pageType, page, segmentId, pi, cache, x, y, pageLength, nestLevel = 0) {
17408
- const { sections, skeTables } = segmentPage;
18173
+ const { sections, skeTables, skeColumnGroups = /* @__PURE__ */ new Map() } = segmentPage;
17409
18174
  this._findLiquid.translateSave();
17410
18175
  const pageLeft = this._findLiquid.x;
17411
18176
  const pageRight = pageLeft + page.pageWidth;
@@ -17466,7 +18231,7 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17466
18231
  this._findLiquid.translateDivide(divide);
17467
18232
  const { x: startX } = this._findLiquid;
17468
18233
  for (const glyph of glyphGroup) {
17469
- if (!glyph.content || glyph.content.length === 0) continue;
18234
+ if (!isHitTestAddressableGlyph(glyph)) continue;
17470
18235
  const { width: glyphWidth, left: glyphLeft } = glyph;
17471
18236
  const startX_fin = startX + glyphLeft;
17472
18237
  const endX_fin = startX + glyphLeft + glyphWidth;
@@ -17569,6 +18334,30 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17569
18334
  (_this$_findLiquid11 = this._findLiquid) === null || _this$_findLiquid11 === void 0 || _this$_findLiquid11.translateRestore();
17570
18335
  }
17571
18336
  }
18337
+ if (skeColumnGroups.size > 0) for (const columnGroup of skeColumnGroups.values()) {
18338
+ var _this$_findLiquid12, _this$_findLiquid13, _this$_findLiquid17;
18339
+ const { top: columnGroupTop, left: columnGroupLeft, width: columnGroupWidth, height: columnGroupHeight, columns } = columnGroup;
18340
+ const absoluteColumnGroupLeft = this._findLiquid.x + columnGroupLeft;
18341
+ const absoluteColumnGroupTop = this._findLiquid.y + columnGroupTop;
18342
+ if (x < absoluteColumnGroupLeft || x > absoluteColumnGroupLeft + columnGroupWidth || y < absoluteColumnGroupTop || y > absoluteColumnGroupTop + columnGroupHeight) continue;
18343
+ (_this$_findLiquid12 = this._findLiquid) === null || _this$_findLiquid12 === void 0 || _this$_findLiquid12.translateSave();
18344
+ (_this$_findLiquid13 = this._findLiquid) === null || _this$_findLiquid13 === void 0 || _this$_findLiquid13.translate(columnGroupLeft, columnGroupTop);
18345
+ for (const column of columns) {
18346
+ var _this$_findLiquid14, _this$_findLiquid15, _ref, _exactMatch4, _this$_findLiquid16;
18347
+ const absoluteColumnLeft = absoluteColumnGroupLeft + column.left;
18348
+ const absoluteColumnTop = absoluteColumnGroupTop + column.top;
18349
+ if (x < absoluteColumnLeft || x > absoluteColumnLeft + column.width || y < absoluteColumnTop || y > absoluteColumnTop + column.height) continue;
18350
+ const nestedCache = {
18351
+ nearestNodeList: [],
18352
+ nearestNodeDistanceList: []
18353
+ };
18354
+ (_this$_findLiquid14 = this._findLiquid) === null || _this$_findLiquid14 === void 0 || _this$_findLiquid14.translateSave();
18355
+ (_this$_findLiquid15 = this._findLiquid) === null || _this$_findLiquid15 === void 0 || _this$_findLiquid15.translate(column.left, column.top);
18356
+ exactMatch = (_ref = (_exactMatch4 = exactMatch) !== null && _exactMatch4 !== void 0 ? _exactMatch4 : this._collectNearestNode(column.page, 3, column.page, segmentId, pi, nestedCache, x, y, pageLength, nestLevel + 1)) !== null && _ref !== void 0 ? _ref : this._getNearestNode(nestedCache.nearestNodeList, nestedCache.nearestNodeDistanceList);
18357
+ (_this$_findLiquid16 = this._findLiquid) === null || _this$_findLiquid16 === void 0 || _this$_findLiquid16.translateRestore();
18358
+ }
18359
+ (_this$_findLiquid17 = this._findLiquid) === null || _this$_findLiquid17 === void 0 || _this$_findLiquid17.translateRestore();
18360
+ }
17572
18361
  if (exactMatch) {
17573
18362
  this._findLiquid.translateRestore();
17574
18363
  return exactMatch;
@@ -17713,7 +18502,7 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17713
18502
  let isContinuous = false;
17714
18503
  ctx.sectionBreakConfigCache.set(sectionNode.endIndex, sectionBreakConfig);
17715
18504
  if (sectionType === _univerjs_core.SectionType.CONTINUOUS && curSkeletonPage != null) {
17716
- updateBlockIndex(allSkeletonPages);
18505
+ updateBlockIndex(allSkeletonPages, -1, ctx.docsConfig.documentCompatibilityPolicy);
17717
18506
  this._addNewSectionByContinuous(curSkeletonPage, columnProperties, columnSeparatorType);
17718
18507
  isContinuous = true;
17719
18508
  } else if (layoutAnchor == null || curSkeletonPage == null) {
@@ -17722,7 +18511,10 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17722
18511
  }
17723
18512
  const { pages } = dealWithSection(ctx, viewModel, sectionNode, curSkeletonPage, sectionBreakConfig, layoutAnchor);
17724
18513
  if (sectionTypeNext === _univerjs_core.SectionType.CONTINUOUS && columnProperties.length > 0) {}
17725
- if (isContinuous) pages.splice(0, 1);
18514
+ if (isContinuous) {
18515
+ const continuousFirstPage = pages.shift();
18516
+ if (continuousFirstPage && allSkeletonPages.length > 0) allSkeletonPages[allSkeletonPages.length - 1] = continuousFirstPage;
18517
+ }
17726
18518
  allSkeletonPages.push(...pages);
17727
18519
  if (ctx.isDirty) break;
17728
18520
  }
@@ -17733,7 +18525,8 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17733
18525
  } else {
17734
18526
  this._iteratorCount = 0;
17735
18527
  removeDupPages(ctx);
17736
- updateBlockIndex(skeleton.pages);
18528
+ updateBlockIndex(skeleton.pages, -1, ctx.docsConfig.documentCompatibilityPolicy);
18529
+ mergeContinuousDuplicatePages(skeleton.pages);
17737
18530
  updateInlineDrawingCoordsAndBorder(ctx, skeleton.pages);
17738
18531
  for (const hSkeMap of skeleton.skeHeaders.values()) for (const page of hSkeMap.values()) updateInlineDrawingCoordsAndBorder(ctx, [page]);
17739
18532
  for (const fSkeMap of skeleton.skeFooters.values()) for (const page of fSkeMap.values()) updateInlineDrawingCoordsAndBorder(ctx, [page]);
@@ -17757,9 +18550,10 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17757
18550
  if (skeletonData == null) return;
17758
18551
  const { pages, skeFooters, skeHeaders } = skeletonData;
17759
18552
  for (const page of pages) {
18553
+ var _segmentPageParent$pa;
17760
18554
  const curPageIndex = pages.indexOf(page);
17761
18555
  if (segmentId && curPageIndex !== segmentPageIndex) continue;
17762
- const { pageWidth, skeTables } = page;
18556
+ const { pageWidth } = page;
17763
18557
  let segmentPage = page;
17764
18558
  if (segmentId) {
17765
18559
  var _skeHeaders$get5, _skeFooters$get5;
@@ -17769,27 +18563,22 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17769
18563
  else if (maybeFooterSke) segmentPage = maybeFooterSke;
17770
18564
  else continue;
17771
18565
  }
17772
- if (segmentId === "") {
17773
- let foundCell = false;
17774
- for (const table of skeTables.values()) {
17775
- const { rows } = table;
17776
- for (const row of rows) {
17777
- const { cells } = row;
17778
- for (const cell of cells) {
17779
- const { st, ed } = cell;
17780
- if (charIndex >= st && charIndex <= ed) {
17781
- segmentPage = cell;
17782
- foundCell = true;
17783
- break;
17784
- }
17785
- }
17786
- if (foundCell) break;
17787
- }
17788
- if (foundCell) break;
18566
+ if (segmentId === "") segmentPage = resolveMostSpecificPageByCharIndex(page, charIndex);
18567
+ const { sections, st, ed } = segmentPage;
18568
+ const segmentPageParent = segmentPage.parent;
18569
+ const isColumnSegmentPage = segmentId === "" && (segmentPageParent === null || segmentPageParent === void 0 ? void 0 : segmentPageParent.page) === segmentPage && ((_segmentPageParent$pa = segmentPageParent.parent) === null || _segmentPageParent$pa === void 0 ? void 0 : _segmentPageParent$pa.columnGroupId);
18570
+ if (charIndex < st || charIndex > ed) {
18571
+ if (isColumnSegmentPage) {
18572
+ const boundary = getBoundaryGlyphInPage(segmentPage, charIndex >= ed);
18573
+ if (boundary) return {
18574
+ page: segmentPage,
18575
+ pageType: segmentPage.type,
18576
+ segmentPageIndex,
18577
+ ...boundary
18578
+ };
17789
18579
  }
18580
+ continue;
17790
18581
  }
17791
- const { sections, st, ed } = segmentPage;
17792
- if (charIndex < st || charIndex > ed) continue;
17793
18582
  for (const section of sections) {
17794
18583
  const { columns, st, ed } = section;
17795
18584
  if (charIndex < st || charIndex > ed) continue;
@@ -17822,6 +18611,15 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17822
18611
  }
17823
18612
  }
17824
18613
  }
18614
+ if (isColumnSegmentPage) {
18615
+ const boundary = getBoundaryGlyphInPage(segmentPage, charIndex >= segmentPage.ed);
18616
+ if (boundary) return {
18617
+ page: segmentPage,
18618
+ pageType: segmentPage.type,
18619
+ segmentPageIndex,
18620
+ ...boundary
18621
+ };
18622
+ }
17825
18623
  }
17826
18624
  }
17827
18625
  };
@@ -22594,7 +23392,7 @@ var Documents = class Documents extends DocComponent {
22594
23392
  for (let i = 0, len = pages.length; i < len; i++) {
22595
23393
  var _skeHeaders$get, _headerSkeletonPage$m, _skeFooters$get;
22596
23394
  const page = pages[i];
22597
- const { sections, marginTop: pagePaddingTop = 0, marginBottom: pagePaddingBottom = 0, marginLeft: pagePaddingLeft = 0, marginRight: pagePaddingRight = 0, width: actualWidth, height: actualHeight, pageWidth, headerId, footerId, renderConfig = {}, skeTables } = page;
23395
+ const { sections, marginTop: pagePaddingTop = 0, marginBottom: pagePaddingBottom = 0, marginLeft: pagePaddingLeft = 0, marginRight: pagePaddingRight = 0, width: actualWidth, height: actualHeight, pageWidth, headerId, footerId, renderConfig = {}, skeTables, skeColumnGroups = /* @__PURE__ */ new Map() } = page;
22598
23396
  const { verticalAlign = _univerjs_core.VerticalAlign.TOP, horizontalAlign = _univerjs_core.HorizontalAlign.LEFT, centerAngle: centerAngleDeg = 0, vertexAngle: vertexAngleDeg = 0, wrapStrategy = _univerjs_core.WrapStrategy.UNSPECIFIED, cellValueType } = renderConfig;
22599
23397
  const isVertical = vertexAngleDeg === 90 && centerAngleDeg === 90;
22600
23398
  const horizontalOffsetNoAngle = this._horizontalHandler(actualWidth, pagePaddingLeft, pagePaddingRight, horizontalAlign, vertexAngleDeg, centerAngleDeg, cellValueType);
@@ -22694,6 +23492,7 @@ var Documents = class Documents extends DocComponent {
22694
23492
  this._drawLiquid.translateRestore();
22695
23493
  }
22696
23494
  }
23495
+ if (skeColumnGroups.size > 0) this._drawColumnGroups(ctx, page, skeColumnGroups, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale);
22697
23496
  this._resetRotation(ctx, finalAngle);
22698
23497
  const footerSkeletonPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
22699
23498
  if (footerSkeletonPage) {
@@ -22751,6 +23550,21 @@ var Documents = class Documents extends DocComponent {
22751
23550
  drawLiquid.translateRestore();
22752
23551
  }
22753
23552
  }
23553
+ _drawColumnGroups(ctx, page, skeColumnGroups, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale) {
23554
+ const drawLiquid = this._drawLiquid;
23555
+ if (drawLiquid == null) return;
23556
+ for (const columnGroup of skeColumnGroups.values()) {
23557
+ drawLiquid.translateSave();
23558
+ drawLiquid.translate(columnGroup.left, columnGroup.top);
23559
+ for (const column of columnGroup.columns) {
23560
+ drawLiquid.translateSave();
23561
+ drawLiquid.translate(column.left, column.top);
23562
+ this._drawNestedPageContent(ctx, page, column.page, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale);
23563
+ drawLiquid.translateRestore();
23564
+ }
23565
+ drawLiquid.translateRestore();
23566
+ }
23567
+ }
22754
23568
  _drawTableCellBackgrounds(ctx, page, tableSkeleton) {
22755
23569
  if (this._drawLiquid == null) return;
22756
23570
  const backgrounds = /* @__PURE__ */ new Map();
@@ -22859,15 +23673,33 @@ var Documents = class Documents extends DocComponent {
22859
23673
  _drawTableCell(ctx, page, cell, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale) {
22860
23674
  if (this._drawLiquid == null) return;
22861
23675
  this._drawTableCellBordersAndBg(ctx, page, cell, false);
22862
- const { sections, marginLeft, marginTop } = cell;
22863
- alignOffsetNoAngle = Vector2.create(alignOffsetNoAngle.x + marginLeft, alignOffsetNoAngle.y + marginTop);
23676
+ this._drawNestedPageContent(ctx, page, cell, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale);
23677
+ }
23678
+ _drawNestedPageContent(ctx, parentPage, nestedPage, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale) {
23679
+ if (this._drawLiquid == null) return;
23680
+ const { sections, marginLeft, marginTop, skeTables } = nestedPage;
23681
+ const alignOffset = Vector2.create(alignOffsetNoAngle.x + marginLeft, alignOffsetNoAngle.y + marginTop);
22864
23682
  ctx.save();
22865
23683
  const { x, y } = this._drawLiquid;
22866
- const { pageWidth, pageHeight } = cell;
23684
+ const { pageWidth, pageHeight } = nestedPage;
23685
+ const clipOrigin = getNestedPageClipOrigin(parentPage, nestedPage, {
23686
+ x,
23687
+ y
23688
+ }, alignOffset);
22867
23689
  ctx.beginPath();
22868
- ctx.rectByPrecision(x + page.marginLeft, y + page.marginTop, pageWidth, pageHeight);
23690
+ ctx.rectByPrecision(clipOrigin.x, clipOrigin.y, pageWidth, pageHeight);
22869
23691
  ctx.closePath();
22870
23692
  ctx.clip();
23693
+ if (skeTables.size > 0) if (isColumnGroupNestedPage(nestedPage)) {
23694
+ this._drawLiquid.translateSave();
23695
+ this._drawLiquid.translate(alignOffset.x, alignOffset.y);
23696
+ this._drawTable(ctx, {
23697
+ ...nestedPage,
23698
+ marginLeft: 0,
23699
+ marginTop: 0
23700
+ }, skeTables, extensions, backgroundExtension, glyphExtensionsExcludeBackground, Vector2.create(0, 0), centerAngle, vertexAngle, renderConfig, parentScale);
23701
+ this._drawLiquid.translateRestore();
23702
+ } else this._drawTable(ctx, nestedPage, skeTables, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffset, centerAngle, vertexAngle, renderConfig, parentScale);
22871
23703
  for (const section of sections) {
22872
23704
  const { columns } = section;
22873
23705
  this._drawLiquid.translateSave();
@@ -22877,7 +23709,6 @@ var Documents = class Documents extends DocComponent {
22877
23709
  this._drawLiquid.translateSave();
22878
23710
  this._drawLiquid.translateColumn(column);
22879
23711
  const linesCount = lines.length;
22880
- const alignOffset = alignOffsetNoAngle;
22881
23712
  for (let i = 0; i < linesCount; i++) {
22882
23713
  const line = lines[i];
22883
23714
  const { divides, asc = 0, type, lineHeight = 0 } = line;
@@ -22895,7 +23726,7 @@ var Documents = class Documents extends DocComponent {
22895
23726
  } else {
22896
23727
  this._drawLiquid.translateSave();
22897
23728
  this._drawLiquid.translateLine(line, true, true);
22898
- this._drawLineBackground(ctx, cell, line, page.marginLeft, page.marginTop);
23729
+ this._drawLineBackground(ctx, nestedPage, line);
22899
23730
  const divideLength = divides.length;
22900
23731
  for (let i = 0; i < divideLength; i++) {
22901
23732
  const divide = divides[i];
@@ -22924,7 +23755,7 @@ var Documents = class Documents extends DocComponent {
22924
23755
  }
22925
23756
  this._drawLiquid.translateRestore();
22926
23757
  }
22927
- if (line.borderBottom) this._drawBorderBottom(ctx, cell, line, page.marginLeft, page.marginTop);
23758
+ if (line.borderBottom) this._drawBorderBottom(ctx, nestedPage, line, parentPage.marginLeft, parentPage.marginTop);
22928
23759
  this._drawLiquid.translateRestore();
22929
23760
  }
22930
23761
  }
@@ -23127,6 +23958,21 @@ function setTableCellBorderDash(ctx, dashStyle) {
23127
23958
  }
23128
23959
  ctx.setLineDash([0]);
23129
23960
  }
23961
+ function isColumnGroupNestedPage(page) {
23962
+ var _parent$parent;
23963
+ const parent = page.parent;
23964
+ return (parent === null || parent === void 0 ? void 0 : parent.columnId) != null && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.columnGroupId) != null;
23965
+ }
23966
+ function getNestedPageClipOrigin(parentPage, nestedPage, drawOrigin, alignOffset) {
23967
+ if (isColumnGroupNestedPage(nestedPage)) return {
23968
+ x: drawOrigin.x + alignOffset.x,
23969
+ y: drawOrigin.y + alignOffset.y
23970
+ };
23971
+ return {
23972
+ x: drawOrigin.x + parentPage.marginLeft,
23973
+ y: drawOrigin.y + parentPage.marginTop
23974
+ };
23975
+ }
23130
23976
  function fillRectByPrecisionBounds(ctx, x, y, width, height) {
23131
23977
  const { scaleX, scaleY } = ctx.getScale();
23132
23978
  const startX = fixLineWidthByScale(x, scaleX);
@@ -25709,7 +26555,7 @@ Engine = __decorate([__decorateParam(2, ICanvasColorService)], Engine);
25709
26555
  //#endregion
25710
26556
  //#region package.json
25711
26557
  var name = "@univerjs/engine-render";
25712
- var version = "1.0.0-alpha.0";
26558
+ var version = "1.0.0-insiders.20260629-12f2e44";
25713
26559
 
25714
26560
  //#endregion
25715
26561
  //#region src/config/config.ts
@@ -30165,12 +31011,15 @@ exports.cancelRequestFrame = cancelRequestFrame;
30165
31011
  exports.checkStyle = checkStyle;
30166
31012
  exports.clampRange = clampRange;
30167
31013
  exports.clearLineByBorderType = clearLineByBorderType;
31014
+ exports.compareDocumentSkeletonNestedPagePathOrder = compareDocumentSkeletonNestedPagePathOrder;
30168
31015
  exports.convertTextRotation = convertTextRotation;
30169
31016
  exports.convertTransformToOffsetX = convertTransformToOffsetX;
30170
31017
  exports.convertTransformToOffsetY = convertTransformToOffsetY;
30171
31018
  exports.createCanvasElement = createCanvasElement;
30172
31019
  exports.createImageElement = createImageElement;
30173
31020
  exports.degToRad = degToRad;
31021
+ exports.documentSkeletonLineIterator = documentSkeletonLineIterator;
31022
+ exports.documentSkeletonTableIterator = documentSkeletonTableIterator;
30174
31023
  exports.drawDiagonalLineByBorderType = drawDiagonalLineByBorderType;
30175
31024
  exports.drawLineByBorderType = drawLineByBorderType;
30176
31025
  exports.expandRangeIfIntersects = expandRangeIfIntersects;
@@ -30186,6 +31035,8 @@ exports.getDPI = getDPI;
30186
31035
  exports.getDevicePixelRatio = getDevicePixelRatio;
30187
31036
  exports.getDocsSkeletonPageSize = getDocsSkeletonPageSize;
30188
31037
  exports.getDocsTableRenderViewport = getDocsTableRenderViewport;
31038
+ exports.getDocumentSkeletonColumnPagePathInfo = getDocumentSkeletonColumnPagePathInfo;
31039
+ exports.getDocumentSkeletonNestedPageOffset = getDocumentSkeletonNestedPageOffset;
30189
31040
  exports.getDrawingGroupState = getDrawingGroupState;
30190
31041
  exports.getFirstGrapheme = getFirstGrapheme;
30191
31042
  exports.getFontStyleString = getFontStyleString;