@univerjs/engine-render 0.25.1 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/lib/cjs/index.js +2100 -319
  2. package/lib/es/index.js +2097 -321
  3. package/lib/types/basics/document-node-tools.d.ts +1 -0
  4. package/lib/types/basics/i-document-skeleton-cached.d.ts +26 -1
  5. package/lib/types/basics/interfaces.d.ts +6 -0
  6. package/lib/types/basics/transformer-config.d.ts +17 -0
  7. package/lib/types/components/docs/doc-background.d.ts +4 -0
  8. package/lib/types/components/docs/document-compatibility.d.ts +43 -0
  9. package/lib/types/components/docs/document.d.ts +6 -0
  10. package/lib/types/components/docs/extensions/background-runs.d.ts +22 -0
  11. package/lib/types/components/docs/extensions/font-and-base-line.d.ts +10 -0
  12. package/lib/types/components/docs/layout/block/column.d.ts +23 -0
  13. package/lib/types/components/docs/layout/block/paragraph/layout-ruler.d.ts +17 -3
  14. package/lib/types/components/docs/layout/model/line.d.ts +1 -1
  15. package/lib/types/components/docs/layout/model/page.d.ts +2 -1
  16. package/lib/types/components/docs/layout/tools.d.ts +83 -3
  17. package/lib/types/components/docs/table-render-viewport.d.ts +4 -0
  18. package/lib/types/components/docs/view-model/document-view-model.d.ts +8 -1
  19. package/lib/types/components/sheets/extensions/border.d.ts +2 -2
  20. package/lib/types/components/sheets/interfaces.d.ts +6 -6
  21. package/lib/types/index.d.ts +7 -5
  22. package/lib/types/render-manager/render-manager.service.d.ts +1 -0
  23. package/lib/types/scene.transformer.d.ts +20 -0
  24. package/lib/types/services/canvas-color.service.d.ts +1 -0
  25. package/lib/types/shape/image.d.ts +3 -0
  26. package/lib/umd/index.js +2 -2
  27. package/package.json +8 -8
package/lib/cjs/index.js CHANGED
@@ -665,7 +665,7 @@ function getSystemHighlightColor() {
665
665
  }
666
666
 
667
667
  //#endregion
668
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
668
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
669
669
  function _typeof(o) {
670
670
  "@babel/helpers - typeof";
671
671
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -676,7 +676,7 @@ function _typeof(o) {
676
676
  }
677
677
 
678
678
  //#endregion
679
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
679
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
680
680
  function toPrimitive(t, r) {
681
681
  if ("object" != _typeof(t) || !t) return t;
682
682
  var e = t[Symbol.toPrimitive];
@@ -689,14 +689,14 @@ function toPrimitive(t, r) {
689
689
  }
690
690
 
691
691
  //#endregion
692
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
692
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
693
693
  function toPropertyKey(t) {
694
694
  var i = toPrimitive(t, "string");
695
695
  return "symbol" == _typeof(i) ? i : i + "";
696
696
  }
697
697
 
698
698
  //#endregion
699
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
699
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
700
700
  function _defineProperty(e, r, t) {
701
701
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
702
702
  value: t,
@@ -2313,8 +2313,8 @@ var Path2 = class {
2313
2313
  const from = this._lines[o - 1];
2314
2314
  const to = this._lines[o];
2315
2315
  for (let n = 1; n < lines.length; n++) {
2316
- const contrastFrom = this._lines[o - 1];
2317
- const contrastTo = this._lines[o];
2316
+ const contrastFrom = lines[n - 1];
2317
+ const contrastTo = lines[n];
2318
2318
  const point = this._intersection({
2319
2319
  from,
2320
2320
  to
@@ -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,
@@ -10878,8 +10879,8 @@ const TINF_OK = 0;
10878
10879
  const TINF_DATA_ERROR = -3;
10879
10880
  var Tree = class {
10880
10881
  constructor() {
10881
- _defineProperty(this, "table", new Uint16Array(16));
10882
- _defineProperty(this, "trans", new Uint16Array(288));
10882
+ _defineProperty(this, "table", /* @__PURE__ */ new Uint16Array(16));
10883
+ _defineProperty(this, "trans", /* @__PURE__ */ new Uint16Array(288));
10883
10884
  }
10884
10885
  };
10885
10886
  var Data = class {
@@ -10904,10 +10905,10 @@ var Data = class {
10904
10905
  };
10905
10906
  const sltree = new Tree();
10906
10907
  const sdtree = new Tree();
10907
- const length_bits = new Uint8Array(30);
10908
- const length_base = new Uint16Array(30);
10909
- const dist_bits = new Uint8Array(30);
10910
- const dist_base = new Uint16Array(30);
10908
+ const length_bits = /* @__PURE__ */ new Uint8Array(30);
10909
+ const length_base = /* @__PURE__ */ new Uint16Array(30);
10910
+ const dist_bits = /* @__PURE__ */ new Uint8Array(30);
10911
+ const dist_base = /* @__PURE__ */ new Uint16Array(30);
10911
10912
  const clcidx = new Uint8Array([
10912
10913
  16,
10913
10914
  17,
@@ -10930,7 +10931,7 @@ const clcidx = new Uint8Array([
10930
10931
  15
10931
10932
  ]);
10932
10933
  const code_tree = new Tree();
10933
- const lengths = new Uint8Array(320);
10934
+ const lengths = /* @__PURE__ */ new Uint8Array(320);
10934
10935
  function tinf_build_bits_base(bits, base, delta, first) {
10935
10936
  let i;
10936
10937
  let sum;
@@ -10955,7 +10956,7 @@ function tinf_build_fixed_trees(lt, dt) {
10955
10956
  dt.table[5] = 32;
10956
10957
  for (i = 0; i < 32; ++i) dt.trans[i] = i;
10957
10958
  }
10958
- const offs = new Uint16Array(16);
10959
+ const offs = /* @__PURE__ */ new Uint16Array(16);
10959
10960
  function tinf_build_tree(t, lengths, off, num) {
10960
10961
  let i;
10961
10962
  let sum;
@@ -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 {
@@ -12111,6 +12174,13 @@ function getDocsTableRenderViewport(unitId, tableId) {
12111
12174
  var _docsTableRenderViewp;
12112
12175
  return (_docsTableRenderViewp = docsTableRenderViewportProvider === null || docsTableRenderViewportProvider === void 0 ? void 0 : docsTableRenderViewportProvider(unitId, tableId)) !== null && _docsTableRenderViewp !== void 0 ? _docsTableRenderViewp : null;
12113
12176
  }
12177
+ function getDocsTableVirtualContentWidth(viewport) {
12178
+ var _viewport$leadingInse, _viewport$trailingIns;
12179
+ return ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0) + viewport.contentWidth + ((_viewport$trailingIns = viewport.trailingInsetRight) !== null && _viewport$trailingIns !== void 0 ? _viewport$trailingIns : 0);
12180
+ }
12181
+ function hasDocsTableHorizontalViewport(viewport) {
12182
+ return viewport != null && getDocsTableVirtualContentWidth(viewport) > viewport.viewportWidth;
12183
+ }
12114
12184
 
12115
12185
  //#endregion
12116
12186
  //#region src/components/docs/view-model/data-stream-tree-node.ts
@@ -12279,8 +12349,16 @@ function parseDataStreamToTree(dataStream, tables) {
12279
12349
  const tableList = [];
12280
12350
  const tableRowList = [];
12281
12351
  const tableCellList = [];
12352
+ const columnGroupList = [];
12353
+ const columnList = [];
12354
+ const columnParagraphList = [];
12355
+ const columnSectionList = [];
12282
12356
  const currentBlocks = [];
12283
- 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
+ };
12284
12362
  const appendToPreviousParagraph = (char) => {
12285
12363
  const tempParagraphList = getParagraphList();
12286
12364
  const lastParagraph = tempParagraphList[tempParagraphList.length - 1];
@@ -12310,10 +12388,11 @@ function parseDataStreamToTree(dataStream, tables) {
12310
12388
  currentBlocks.length = 0;
12311
12389
  content = "";
12312
12390
  if (tableCellList.length > 0) cellParagraphList.push(paragraphNode);
12391
+ else if (columnGroupList.length > 0) columnParagraphList.push(paragraphNode);
12313
12392
  else paragraphList.push(paragraphNode);
12314
12393
  } else if (char === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK) {
12315
12394
  const sectionNode = DataStreamTreeNode.create(_univerjs_core.DataStreamTreeNodeType.SECTION_BREAK);
12316
- const tempParagraphList = tableCellList.length > 0 ? cellParagraphList : paragraphList;
12395
+ const tempParagraphList = tableCellList.length > 0 ? cellParagraphList : columnGroupList.length > 0 ? columnParagraphList : paragraphList;
12317
12396
  if (tempParagraphList.length === 0) {
12318
12397
  const emptyParagraph = DataStreamTreeNode.create(_univerjs_core.DataStreamTreeNodeType.PARAGRAPH, "");
12319
12398
  emptyParagraph.setIndexRange(i, i - 1);
@@ -12325,7 +12404,8 @@ function parseDataStreamToTree(dataStream, tables) {
12325
12404
  if (tableCellList.length > 0) {
12326
12405
  const lastCell = tableCellList[tableCellList.length - 1];
12327
12406
  batchParent(lastCell, [sectionNode], _univerjs_core.DataStreamTreeNodeType.TABLE_CELL);
12328
- } else sectionList.push(sectionNode);
12407
+ } else if (columnGroupList.length > 0) columnSectionList.push(sectionNode);
12408
+ else sectionList.push(sectionNode);
12329
12409
  tempParagraphList.length = 0;
12330
12410
  } else if (char === _univerjs_core.DataStreamTreeTokenType.TABLE_START) {
12331
12411
  const tableNode = DataStreamTreeNode.create(_univerjs_core.DataStreamTreeNodeType.TABLE);
@@ -12351,6 +12431,32 @@ function parseDataStreamToTree(dataStream, tables) {
12351
12431
  const cellNode = tableCellList.pop();
12352
12432
  const lastRow = tableRowList[tableRowList.length - 1];
12353
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 = "";
12354
12460
  } else if (char === _univerjs_core.DataStreamTreeTokenType.BLOCK_START) content += char;
12355
12461
  else if (char === _univerjs_core.DataStreamTreeTokenType.BLOCK_END) {
12356
12462
  if (content.length > 0 || !appendToPreviousParagraph(char)) content += char;
@@ -12374,6 +12480,7 @@ var DocumentViewModel = class DocumentViewModel {
12374
12480
  _defineProperty(this, "_sectionBreakCache", /* @__PURE__ */ new Map());
12375
12481
  _defineProperty(this, "_customBlockCache", /* @__PURE__ */ new Map());
12376
12482
  _defineProperty(this, "_tableCache", /* @__PURE__ */ new Map());
12483
+ _defineProperty(this, "_columnGroupCache", /* @__PURE__ */ new Map());
12377
12484
  _defineProperty(this, "_tableNodeCache", /* @__PURE__ */ new Map());
12378
12485
  _defineProperty(this, "_children", []);
12379
12486
  _defineProperty(this, "_editArea", "BODY");
@@ -12404,6 +12511,7 @@ var DocumentViewModel = class DocumentViewModel {
12404
12511
  this._sectionBreakCache.clear();
12405
12512
  this._customBlockCache.clear();
12406
12513
  this._tableCache.clear();
12514
+ this._columnGroupCache.clear();
12407
12515
  this._tableNodeCache.clear();
12408
12516
  this._segmentViewModels$.complete();
12409
12517
  this._editAreaChange$.complete();
@@ -12475,6 +12583,9 @@ var DocumentViewModel = class DocumentViewModel {
12475
12583
  getTableByStartIndex(index) {
12476
12584
  return this._tableCache.get(index);
12477
12585
  }
12586
+ getColumnGroupByStartIndex(index) {
12587
+ return this._columnGroupCache.get(index);
12588
+ }
12478
12589
  findTableNodeById(id) {
12479
12590
  var _this$_tableNodeCache;
12480
12591
  return (_this$_tableNodeCache = this._tableNodeCache.get(id)) === null || _this$_tableNodeCache === void 0 ? void 0 : _this$_tableNodeCache.table;
@@ -12509,6 +12620,7 @@ var DocumentViewModel = class DocumentViewModel {
12509
12620
  this._buildSectionBreakCache();
12510
12621
  this._buildCustomBlockCache();
12511
12622
  this._buildTableCache();
12623
+ this._buildColumnGroupCache();
12512
12624
  }
12513
12625
  _buildParagraphCache() {
12514
12626
  var _this$getBody$paragra, _this$getBody;
@@ -12553,9 +12665,23 @@ var DocumentViewModel = class DocumentViewModel {
12553
12665
  });
12554
12666
  }
12555
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
+ }
12556
12682
  _buildTextRunsCache() {
12557
- var _this$getBody$textRun, _this$getBody5;
12558
- 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 : [];
12559
12685
  this._textRunsCache.clear();
12560
12686
  for (const textRun of textRuns) {
12561
12687
  const { st, ed } = textRun;
@@ -12661,6 +12787,7 @@ function createSkeletonCustomBlockGlyph(config, glyphWidth = 0, glyphHeight = 0,
12661
12787
  };
12662
12788
  }
12663
12789
  function _createSkeletonWordOrLetter(glyphType, content, config, glyphWidth, glyphInfo) {
12790
+ var _config$documentCompa;
12664
12791
  const { fontStyle, textStyle, charSpace = 1, gridType = _univerjs_core.GridType.LINES, snapToGrid = _univerjs_core.BooleanNumber.FALSE } = config;
12665
12792
  const skipWidthList = [
12666
12793
  _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK,
@@ -12670,6 +12797,10 @@ function _createSkeletonWordOrLetter(glyphType, content, config, glyphWidth, gly
12670
12797
  _univerjs_core.DataStreamTreeTokenType.TABLE_ROW_END,
12671
12798
  _univerjs_core.DataStreamTreeTokenType.TABLE_CELL_START,
12672
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,
12673
12804
  _univerjs_core.DataStreamTreeTokenType.BLOCK_START,
12674
12805
  _univerjs_core.DataStreamTreeTokenType.BLOCK_END,
12675
12806
  _univerjs_core.DataStreamTreeTokenType.CUSTOM_RANGE_START,
@@ -12711,6 +12842,7 @@ function _createSkeletonWordOrLetter(glyphType, content, config, glyphWidth, gly
12711
12842
  let xOffset = 0;
12712
12843
  if (glyphInfo && glyphInfo.boundingBox && glyphInfo.font) bBox = FontCache.getBBoxFromGlyphInfo(glyphInfo, fontStyle);
12713
12844
  else bBox = FontCache.getTextSize(content, fontStyle);
12845
+ bBox = applyFontMetricCompatibility(content, fontStyle, bBox, (_config$documentCompa = config.documentCompatibilityPolicy) !== null && _config$documentCompa !== void 0 ? _config$documentCompa : getDocumentCompatibilityPolicy());
12714
12846
  const { width: contentWidth = 0 } = bBox;
12715
12847
  let width = glyphWidth !== null && glyphWidth !== void 0 ? glyphWidth : contentWidth;
12716
12848
  if (validationGrid(gridType, snapToGrid)) {
@@ -12831,11 +12963,13 @@ function createSkeletonLine(paragraphIndex, lineType, lineBoundingBox, columnWid
12831
12963
  lineSke.isBehindTable = true;
12832
12964
  lineSke.tableId = tableId;
12833
12965
  }
12834
- 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)), 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);
12835
12969
  for (const divide of lineSke.divides) divide.parent = lineSke;
12836
12970
  return lineSke;
12837
12971
  }
12838
- function calculateLineTopByDrawings(lineHeight = 15.6, lineTop = 0, page, headerPage, footerPage) {
12972
+ function calculateLineTopByDrawings(lineHeight = 15.6, lineTop = 0, page, headerPage, footerPage, columnLeft = 0, columnWidth = 0) {
12839
12973
  let maxTop = lineTop;
12840
12974
  const pageSkeDrawings = page.skeDrawings;
12841
12975
  const skeNonWrapTables = new Map(Array.from(page.skeTables).filter(([_, table]) => table.tableSource.textWrap === _univerjs_core.TableTextWrapType.NONE));
@@ -12852,6 +12986,8 @@ function calculateLineTopByDrawings(lineHeight = 15.6, lineTop = 0, page, header
12852
12986
  pageSkeDrawings === null || pageSkeDrawings === void 0 || pageSkeDrawings.forEach((drawing) => {
12853
12987
  const top = _getLineTopWidthWrapTopBottom(drawing, lineHeight, lineTop);
12854
12988
  if (top) maxTop = Math.max(maxTop, top);
12989
+ const blockingWrapTop = _getLineTopWithFullColumnWrap(drawing, lineHeight, lineTop, columnLeft, columnWidth);
12990
+ if (blockingWrapTop) maxTop = Math.max(maxTop, blockingWrapTop);
12855
12991
  });
12856
12992
  skeNonWrapTables === null || skeNonWrapTables === void 0 || skeNonWrapTables.forEach((table) => {
12857
12993
  const top = _getLineTopWidthWrapNone(table, lineHeight, lineTop);
@@ -12859,6 +12995,37 @@ function calculateLineTopByDrawings(lineHeight = 15.6, lineTop = 0, page, header
12859
12995
  });
12860
12996
  return maxTop;
12861
12997
  }
12998
+ function _getLineTopWithFullColumnWrap(drawing, lineHeight, lineTop, columnLeft, columnWidth) {
12999
+ if (columnWidth <= 0) return;
13000
+ const { aTop, height, aLeft, width, angle = 0, drawingOrigin } = drawing;
13001
+ const { layoutType, distL = 0, distT = 0, distB = 0, distR = 0, wrapText } = drawingOrigin;
13002
+ if (layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE || layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE || layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) return;
13003
+ let top = aTop;
13004
+ let drawingHeight = height;
13005
+ let left = aLeft - columnLeft;
13006
+ let drawingWidth = width;
13007
+ if (angle !== 0) {
13008
+ var _boundingBox$top, _boundingBox$height, _boundingBox$left, _boundingBox$width;
13009
+ const boundingBox = getBoundingBox(angle, left, width, top, height);
13010
+ top = (_boundingBox$top = boundingBox.top) !== null && _boundingBox$top !== void 0 ? _boundingBox$top : top;
13011
+ drawingHeight = (_boundingBox$height = boundingBox.height) !== null && _boundingBox$height !== void 0 ? _boundingBox$height : drawingHeight;
13012
+ left = (_boundingBox$left = boundingBox.left) !== null && _boundingBox$left !== void 0 ? _boundingBox$left : left;
13013
+ drawingWidth = (_boundingBox$width = boundingBox.width) !== null && _boundingBox$width !== void 0 ? _boundingBox$width : drawingWidth;
13014
+ }
13015
+ const newTop = top - (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE ? distT : 0);
13016
+ const newHeight = drawingHeight + (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE ? distB + distT : 0);
13017
+ const bottom = newTop + newHeight;
13018
+ if (bottom <= lineTop) return;
13019
+ const split = __getSplitWidthNoAngle(top, drawingHeight, left, drawingWidth, newTop, Math.max(1, newHeight), columnWidth, {
13020
+ distL,
13021
+ distT,
13022
+ distB,
13023
+ distR
13024
+ }, layoutType, wrapText);
13025
+ if (!split) return;
13026
+ if (split.left > 0 || split.left + split.width < columnWidth) return;
13027
+ return bottom;
13028
+ }
12862
13029
  function _getLineTopWidthWrapNone(table, lineHeight, lineTop) {
12863
13030
  const { top, height } = table;
12864
13031
  if (top + height < lineTop || top > lineHeight + lineTop) return;
@@ -13037,6 +13204,8 @@ function ___getWrapTextRuler(wrapText, resultLeft, resultWidth, columnWidth) {
13037
13204
  return ruler;
13038
13205
  }
13039
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);
13040
13209
  drawingSplit.sort((pre, next) => {
13041
13210
  if (pre.left > next.left) return 1;
13042
13211
  return -1;
@@ -13058,6 +13227,7 @@ function _calculateDivideByDrawings(columnWidth, drawingSplit) {
13058
13227
  divideSkeleton.push(divide);
13059
13228
  }
13060
13229
  }
13230
+ if (divideSkeleton.length === 0 && columnWidth > 0) return [__getDivideSKe(0, columnWidth)];
13061
13231
  return divideSkeleton;
13062
13232
  }
13063
13233
  function __getDivideSKe(left, width) {
@@ -13114,17 +13284,11 @@ function createSkeletonSection(columnProperties = [], columnSeparatorType = _uni
13114
13284
  let colWidth = 0;
13115
13285
  let spaceWidth = 0;
13116
13286
  if (columnProperties.length === 0) columns.push(_getSkeletonColumn(left, sectionWidth, 0, _univerjs_core.ColumnSeparatorType.NONE));
13117
- else for (let i = 0; i < columnProperties.length; i++) {
13118
- const { width, paddingEnd } = columnProperties[i];
13287
+ else for (const { width, paddingEnd } of _fitColumnProperties(columnProperties, sectionWidth)) {
13119
13288
  spaceWidth = paddingEnd;
13120
13289
  colWidth = width;
13121
13290
  columns.push(_getSkeletonColumn(left, colWidth, spaceWidth, columnSeparatorType));
13122
13291
  left += colWidth + spaceWidth;
13123
- if (i === columnProperties.length - 1) {
13124
- colWidth = sectionWidth !== Number.POSITIVE_INFINITY ? sectionWidth - colWidth : width;
13125
- spaceWidth = 0;
13126
- columns.push(_getSkeletonColumn(left, colWidth, spaceWidth, columnSeparatorType));
13127
- }
13128
13292
  }
13129
13293
  const newSection = {
13130
13294
  columns,
@@ -13139,6 +13303,42 @@ function createSkeletonSection(columnProperties = [], columnSeparatorType = _uni
13139
13303
  });
13140
13304
  return newSection;
13141
13305
  }
13306
+ function _fitColumnProperties(columnProperties, sectionWidth) {
13307
+ if (sectionWidth === Number.POSITIVE_INFINITY || columnProperties.length === 0) return columnProperties;
13308
+ const safeSectionWidth = Math.max(0, sectionWidth);
13309
+ const widths = columnProperties.map(({ width }) => Math.max(0, width));
13310
+ const spaces = columnProperties.map(({ paddingEnd }, index) => index === columnProperties.length - 1 ? 0 : Math.max(0, paddingEnd));
13311
+ const totalWidth = widths.reduce((sum, width) => sum + width, 0);
13312
+ if (safeSectionWidth === 0) return columnProperties.map((columnProperty) => ({
13313
+ ...columnProperty,
13314
+ width: 0,
13315
+ paddingEnd: 0
13316
+ }));
13317
+ if (totalWidth <= 0) {
13318
+ const equalWidth = safeSectionWidth / columnProperties.length;
13319
+ return columnProperties.map((columnProperty, index) => ({
13320
+ ...columnProperty,
13321
+ width: equalWidth,
13322
+ paddingEnd: 0
13323
+ }));
13324
+ }
13325
+ if (totalWidth > safeSectionWidth) {
13326
+ const scale = safeSectionWidth / totalWidth;
13327
+ return columnProperties.map((columnProperty, index) => ({
13328
+ ...columnProperty,
13329
+ width: widths[index] * scale,
13330
+ paddingEnd: 0
13331
+ }));
13332
+ }
13333
+ const spaceBudget = safeSectionWidth - totalWidth;
13334
+ const totalSpace = spaces.reduce((sum, space) => sum + space, 0);
13335
+ const fittedSpaces = totalSpace > spaceBudget && totalSpace > 0 ? spaces.map((space) => space / totalSpace * spaceBudget) : spaces;
13336
+ return columnProperties.map((columnProperty, index) => ({
13337
+ ...columnProperty,
13338
+ width: widths[index],
13339
+ paddingEnd: fittedSpaces[index]
13340
+ }));
13341
+ }
13142
13342
  function setColumnFullState(column, state) {
13143
13343
  column.isFull = state;
13144
13344
  }
@@ -13239,12 +13439,13 @@ function createTableSkeleton(ctx, curPage, viewModel, tableNode, sectionBreakCon
13239
13439
  function rollbackListCache(listLevel, table) {
13240
13440
  const { startIndex, endIndex } = table;
13241
13441
  for (const paragraphLists of listLevel.values()) for (const paragraphList of paragraphLists) {
13442
+ if (paragraphList == null) continue;
13242
13443
  const paragraphListIndex = paragraphList.findIndex((p) => p.paragraph.startIndex > startIndex && p.paragraph.startIndex < endIndex);
13243
13444
  if (paragraphListIndex > -1) paragraphList.splice(paragraphListIndex);
13244
13445
  }
13245
13446
  }
13246
13447
  function createTableSkeletons(ctx, curPage, viewModel, tableNode, sectionBreakConfig, availableHeight) {
13247
- var _viewModel$getTableBy2;
13448
+ var _viewModel$getTableBy2, _sectionBreakConfig$d;
13248
13449
  const skeTables = [];
13249
13450
  const { startIndex, endIndex, children: rowNodes } = tableNode;
13250
13451
  const table = (_viewModel$getTableBy2 = viewModel.getTableByStartIndex(startIndex)) === null || _viewModel$getTableBy2 === void 0 ? void 0 : _viewModel$getTableBy2.tableSource;
@@ -13267,9 +13468,10 @@ function createTableSkeletons(ctx, curPage, viewModel, tableNode, sectionBreakCo
13267
13468
  skeTables.push(curTableSkeleton);
13268
13469
  for (const rowNode of rowNodes) dealWithTableRow(ctx, curPage, skeTables, viewModel, sectionBreakConfig, rowNode, rowNodes.indexOf(rowNode), table, createCache);
13269
13470
  updateTableSkeletonsPosition(createCache, curPage, skeTables, table);
13471
+ const documentCompatibilityPolicy = (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy();
13270
13472
  return {
13271
13473
  skeTables,
13272
- fromCurrentPage: skeTables[0].height <= availableHeight
13474
+ fromCurrentPage: skeTables[0].height <= availableHeight + documentCompatibilityPolicy.table.currentPageOverflowTolerance
13273
13475
  };
13274
13476
  }
13275
13477
  function updateTableSkeletonsPosition(cache, curPage, skeTables, table) {
@@ -13299,14 +13501,16 @@ function getAvailableHeight(curPage, cache, hasRepeatHeader) {
13299
13501
  return pageContentHeight;
13300
13502
  }
13301
13503
  function dealWithTableRow(ctx, curPage, skeTables, viewModel, sectionBreakConfig, rowNode, row, table, cache, isRepeatRow = false) {
13504
+ var _sectionBreakConfig$d2;
13302
13505
  const pageContentHeight = getAvailableHeight(curPage, cache, false);
13303
13506
  const availableHeight = getAvailableHeight(curPage, cache, true);
13507
+ const documentCompatibilityPolicy = (_sectionBreakConfig$d2 = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d2 !== void 0 ? _sectionBreakConfig$d2 : getDocumentCompatibilityPolicy();
13304
13508
  const { children: cellNodes, startIndex, endIndex } = rowNode;
13305
13509
  const rowSource = table.tableRows[row];
13306
13510
  const { trHeight, cantSplit } = rowSource;
13307
13511
  const rowSkeletons = [];
13308
13512
  const { hRule, val } = trHeight;
13309
- const canRowSplit = cantSplit === _univerjs_core.BooleanNumber.TRUE && trHeight.hRule === _univerjs_core.TableRowHeightRule.AUTO;
13513
+ const canRowSplit = cantSplit !== _univerjs_core.BooleanNumber.TRUE && trHeight.hRule === _univerjs_core.TableRowHeightRule.AUTO;
13310
13514
  const MAX_FONT_SIZE = 72;
13311
13515
  const needOpenNewTable = cache.remainHeight <= MAX_FONT_SIZE;
13312
13516
  let curTableSkeleton = getCurTableSkeleton(skeTables);
@@ -13352,7 +13556,8 @@ function dealWithTableRow(ctx, curPage, skeTables, viewModel, sectionBreakConfig
13352
13556
  while (rowSkeletons.length > 0) {
13353
13557
  const rowSkeleton = rowSkeletons.shift();
13354
13558
  const lastRow = curTableSkeleton.rows[curTableSkeleton.rows.length - 1];
13355
- if (cache.remainHeight < MAX_FONT_SIZE || cache.remainHeight < rowSkeleton.height) {
13559
+ const rowOverflowHeight = rowSkeleton.height - cache.remainHeight;
13560
+ if (cache.remainHeight < MAX_FONT_SIZE || rowOverflowHeight > documentCompatibilityPolicy.table.rowOverflowTolerance) {
13356
13561
  cache.remainHeight = getAvailableHeight(curPage, cache, row !== 0 && rowSkeleton.index !== lastRow.index);
13357
13562
  cache.rowTop = 0;
13358
13563
  if (curTableSkeleton.rows.length > 0) {
@@ -13528,18 +13733,29 @@ function getTableIdAndSliceIndex(tableSliceId) {
13528
13733
 
13529
13734
  //#endregion
13530
13735
  //#region src/components/docs/layout/block/paragraph/layout-ruler.ts
13736
+ const LINE_LAYOUT_OVERFLOW_TOLERANCE = 2;
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
+ }
13531
13745
  function layoutParagraph(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType = "Normal") {
13532
13746
  if (isParagraphFirstShapedText) if (paragraphConfig.bulletSkeleton) {
13747
+ var _paragraphProperties$;
13533
13748
  const { bulletSkeleton, paragraphStyle = {} } = paragraphConfig;
13534
13749
  const { gridType = _univerjs_core.GridType.LINES, charSpace = 0, defaultTabStop = 10.5 } = sectionBreakConfig;
13535
13750
  const { snapToGrid = _univerjs_core.BooleanNumber.TRUE } = paragraphStyle;
13536
13751
  const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
13537
13752
  const bulletGlyph = createSkeletonBulletGlyph(glyphGroup[0], bulletSkeleton, charSpaceApply);
13538
13753
  const paragraphProperties = bulletSkeleton.paragraphProperties || {};
13539
- paragraphConfig.paragraphStyle = mergeByV(paragraphConfig.paragraphStyle, {
13754
+ paragraphConfig.paragraphStyle = {
13540
13755
  ...paragraphProperties,
13541
- hanging: { v: bulletGlyph.width }
13542
- }, "max");
13756
+ hanging: (_paragraphProperties$ = paragraphProperties.hanging) !== null && _paragraphProperties$ !== void 0 ? _paragraphProperties$ : { v: bulletGlyph.width },
13757
+ ...paragraphConfig.paragraphStyle
13758
+ };
13543
13759
  _lineOperator(ctx, [bulletGlyph, ...glyphGroup], pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);
13544
13760
  } else _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);
13545
13761
  else _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);
@@ -13568,6 +13784,11 @@ function isGlyphGroupBeyondContentBox(glyphGroup, left, divideWidth) {
13568
13784
  }
13569
13785
  return isBeyondContentBox;
13570
13786
  }
13787
+ function shouldKeepOverflowingTextOnLine(sectionBreakConfig) {
13788
+ var _sectionBreakConfig$r;
13789
+ const wrapStrategy = (_sectionBreakConfig$r = sectionBreakConfig.renderConfig) === null || _sectionBreakConfig$r === void 0 ? void 0 : _sectionBreakConfig$r.wrapStrategy;
13790
+ return wrapStrategy === _univerjs_core.WrapStrategy.CLIP || wrapStrategy === _univerjs_core.WrapStrategy.OVERFLOW;
13791
+ }
13571
13792
  function _getConsecutiveHyphenLineCount(divide) {
13572
13793
  var _divide$parent;
13573
13794
  const column = (_divide$parent = divide.parent) === null || _divide$parent === void 0 ? void 0 : _divide$parent.parent;
@@ -13602,17 +13823,30 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13602
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];
13603
13824
  const preOffsetLeft = ((lastGlyph === null || lastGlyph === void 0 ? void 0 : lastGlyph.width) || 0) + ((lastGlyph === null || lastGlyph === void 0 ? void 0 : lastGlyph.left) || 0);
13604
13825
  const { hyphenationZone } = sectionBreakConfig;
13605
- 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
+ }
13832
+ if (shouldKeepOverflowingTextOnLine(sectionBreakConfig)) {
13833
+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13834
+ updateDivideInfo(divide, { breakType: breakPointType });
13835
+ return;
13836
+ }
13606
13837
  updateDivideInfo(divide, { isFull: true });
13607
13838
  const hyphenLineCount = _getConsecutiveHyphenLineCount(divideInfo.divide);
13608
13839
  const { consecutiveHyphenLimit = Number.POSITIVE_INFINITY } = sectionBreakConfig;
13609
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);
13610
13841
  else if (divideInfo.isLast && !isGlyphGroupBeyondContentBox(glyphGroup, preOffsetLeft, divide.width) && isGlyphGroupEndWithWhiteSpaces(glyphGroup)) addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13611
- else if ((divide === null || divide === void 0 ? void 0 : divide.glyphGroup.length) === 0) {
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) {
13843
+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13844
+ updateDivideInfo(divide, { breakType: breakPointType });
13845
+ } else if ((divide === null || divide === void 0 ? void 0 : divide.glyphGroup.length) === 0) {
13612
13846
  const sliceGlyphGroup = [];
13613
13847
  while (glyphGroup.length) {
13614
13848
  sliceGlyphGroup.push(glyphGroup.shift());
13615
- if (__getGlyphGroupWidth(sliceGlyphGroup) > divide.width) {
13849
+ if (isBeyondDivideWidth(__getGlyphGroupWidth(sliceGlyphGroup), divide.width)) {
13616
13850
  if (sliceGlyphGroup.length > 1) glyphGroup.unshift(sliceGlyphGroup.pop());
13617
13851
  break;
13618
13852
  }
@@ -13633,11 +13867,16 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13633
13867
  } else {
13634
13868
  const currentLine = divide.parent;
13635
13869
  const maxBox = __maxFontBoundingBoxByGlyphGroup(glyphGroup);
13636
- if (currentLine && maxBox && !__isNullLine(currentLine)) {
13870
+ if (currentLine && __isZeroWidthNonFlowFloatingAnchorLine(__getGlyphGroupByLine(currentLine), paragraphConfig.paragraphNonInlineSkeDrawings) && __hasFlowGlyph(glyphGroup)) {
13871
+ for (const lineDivide of currentLine.divides) updateDivideInfo(lineDivide, { isFull: true });
13872
+ _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, false, breakPointType);
13873
+ return;
13874
+ }
13875
+ if (currentLine && maxBox && !__isNullLine(currentLine) && __hasFlowGlyph(__getGlyphGroupByLine(currentLine)) && !__isZeroWidthNonFlowFloatingAnchorLine(glyphGroup, paragraphConfig.paragraphNonInlineSkeDrawings)) {
13637
13876
  const { paragraphLineGapDefault, linePitch, lineSpacing, spacingRule, snapToGrid, gridType } = getLineHeightConfig(sectionBreakConfig, paragraphConfig);
13638
13877
  const { boundingBoxAscent, boundingBoxDescent } = maxBox;
13639
- const { contentHeight } = __getLineHeight(boundingBoxAscent + boundingBoxDescent, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid);
13640
- if (currentLine.contentHeight < contentHeight) {
13878
+ const { contentHeight } = getLineHeightMetrics(boundingBoxAscent + boundingBoxDescent, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid, paragraphConfig.useWordStyleLineHeight);
13879
+ if (contentHeight - currentLine.contentHeight > LINE_LAYOUT_OVERFLOW_TOLERANCE) {
13641
13880
  const spanGroupCached = __getGlyphGroupByLine(currentLine);
13642
13881
  const spanGroupCachedLen = spanGroupCached.length;
13643
13882
  let newGlyphGroup = [];
@@ -13653,6 +13892,19 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13653
13892
  return;
13654
13893
  }
13655
13894
  }
13895
+ if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.parent) {
13896
+ const anchorDrawings = __getZeroWidthNonFlowFloatingAnchorDrawings(glyphGroup, paragraphConfig.paragraphNonInlineSkeDrawings);
13897
+ if (anchorDrawings.length > 0) {
13898
+ var _paragraphConfig$para, _paragraphConfig$pDra;
13899
+ const paragraphAnchorLeft = __getParagraphAnchorLeft(sectionBreakConfig, paragraphConfig, (_paragraphConfig$para = paragraphConfig.paragraphStyle) === null || _paragraphConfig$para === void 0 ? void 0 : _paragraphConfig$para.indentStart);
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);
13901
+ __updateDrawingPosition(currentLine.parent, drawings);
13902
+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13903
+ updateDivideInfo(divide, { breakType: breakPointType });
13904
+ glyphGroup.length = 0;
13905
+ return;
13906
+ }
13907
+ }
13656
13908
  addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13657
13909
  updateDivideInfo(divide, { breakType: breakPointType });
13658
13910
  }
@@ -13662,6 +13914,19 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13662
13914
  var _originParagraphStyle, _originParagraphStyle2, _skeHeaders$get, _skeFooters$get;
13663
13915
  let lastPage = getLastPage(pages);
13664
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
+ }
13665
13930
  if (!columnInfo || !columnInfo.column) {
13666
13931
  _pageOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, true, breakPointType);
13667
13932
  lastPage = getLastPage(pages);
@@ -13678,6 +13943,7 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13678
13943
  const descent = Math.max(...glyphGroup.map((glyph) => glyph.bBox.bd));
13679
13944
  const glyphLineHeight = defaultGlyphLineHeight || ascent + descent;
13680
13945
  const { paragraphStyle: originParagraphStyle = {}, paragraphNonInlineSkeDrawings, skeTablesInParagraph, skeHeaders, skeFooters, pDrawingAnchor, paragraphIndex } = paragraphConfig;
13946
+ const isZeroWidthNonFlowFloatingAnchorLine = __isZeroWidthNonFlowFloatingAnchorLine(glyphGroup, paragraphNonInlineSkeDrawings);
13681
13947
  const { namedStyleType } = originParagraphStyle;
13682
13948
  const namedStyle = namedStyleType !== void 0 ? _univerjs_core.NAMED_STYLE_SPACE_MAP[namedStyleType] : null;
13683
13949
  const { spaceAbove, spaceBelow, indentFirstLine, hanging, indentStart, indentEnd } = {
@@ -13686,9 +13952,34 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13686
13952
  spaceBelow: (_originParagraphStyle2 = originParagraphStyle.spaceBelow) !== null && _originParagraphStyle2 !== void 0 ? _originParagraphStyle2 : namedStyle === null || namedStyle === void 0 ? void 0 : namedStyle.spaceBelow
13687
13953
  };
13688
13954
  const { paragraphLineGapDefault, linePitch, lineSpacing, spacingRule, snapToGrid, gridType } = getLineHeightConfig(sectionBreakConfig, paragraphConfig);
13689
- const { paddingTop, paddingBottom, contentHeight, lineSpacingApply } = __getLineHeight(glyphLineHeight, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid);
13690
- const { marginTop, spaceBelowApply } = __getParagraphSpace(ctx, lineSpacingApply, spaceAbove, spaceBelow, isParagraphFirstShapedText, preLine);
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
+ });
13961
+ const glyphGroupCustomBlockIds = new Set(glyphGroup.filter((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.drawingId != null).map((glyph) => glyph.drawingId));
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
+ }
13969
+ let { marginTop, spaceBelowApply } = __getParagraphSpace(ctx, lineSpacingApply, spaceAbove, spaceBelow, isParagraphFirstShapedText, preLine);
13970
+ if (positionedCustomBlockOnly) spaceBelowApply = 0;
13971
+ if (isZeroWidthNonFlowFloatingAnchorLine) {
13972
+ paddingTop = 0;
13973
+ paddingBottom = 0;
13974
+ contentHeight = 0;
13975
+ lineSpacingApply = 0;
13976
+ marginTop = 0;
13977
+ spaceBelowApply = 0;
13978
+ }
13691
13979
  const lineHeight = marginTop + paddingTop + contentHeight + paddingBottom;
13980
+ const { charSpace, defaultTabStop } = getCharSpaceConfig(sectionBreakConfig, paragraphConfig);
13981
+ const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
13982
+ const paragraphAnchorLeft = __getParagraphAnchorLeft(sectionBreakConfig, paragraphConfig, indentStart);
13692
13983
  let section = column.parent;
13693
13984
  if (!section) section = getLastSection(lastPage);
13694
13985
  const lineTop = ((preLine === null || preLine === void 0 ? void 0 : preLine.lineHeight) || 0) + ((preLine === null || preLine === void 0 ? void 0 : preLine.top) || 0);
@@ -13705,16 +13996,22 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13705
13996
  if (relativeLineDrawings.length > 0) __updateAndPositionDrawings(ctx, preLine.top, preLine.lineHeight, column, relativeLineDrawings, preLine.paragraphIndex, isParagraphFirstShapedText);
13706
13997
  }
13707
13998
  }
13999
+ let deferredInlineGroupAnchorDrawings = [];
13708
14000
  if (paragraphNonInlineSkeDrawings != null && paragraphNonInlineSkeDrawings.size > 0) {
13709
14001
  var _pDrawingAnchor$get;
13710
- __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, [...paragraphNonInlineSkeDrawings.values()].filter((drawing) => drawing.drawingOrigin.docTransform.positionV.relativeFrom !== _univerjs_core.ObjectRelativeFromV.LINE), paragraphConfig.paragraphIndex, isParagraphFirstShapedText, pDrawingAnchor === null || pDrawingAnchor === void 0 || (_pDrawingAnchor$get = pDrawingAnchor.get(paragraphIndex)) === null || _pDrawingAnchor$get === void 0 ? void 0 : _pDrawingAnchor$get.top);
14002
+ let targetDrawings = [...paragraphNonInlineSkeDrawings.values()].filter((drawing) => drawing.drawingOrigin.docTransform.positionV.relativeFrom !== _univerjs_core.ObjectRelativeFromV.LINE);
14003
+ if (hasInlineCustomBlock) {
14004
+ deferredInlineGroupAnchorDrawings = targetDrawings.filter((drawing) => glyphGroupCustomBlockIds.has(drawing.drawingId) && drawing.drawingOrigin.docTransform.positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE);
14005
+ targetDrawings = targetDrawings.filter((drawing) => !deferredInlineGroupAnchorDrawings.includes(drawing));
14006
+ }
14007
+ __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDrawings, paragraphConfig.paragraphIndex, isParagraphFirstShapedText, pDrawingAnchor === null || pDrawingAnchor === void 0 || (_pDrawingAnchor$get = pDrawingAnchor.get(paragraphIndex)) === null || _pDrawingAnchor$get === void 0 ? void 0 : _pDrawingAnchor$get.top, paragraphAnchorLeft);
13711
14008
  }
13712
14009
  if (skeTablesInParagraph != null && skeTablesInParagraph.length > 0) {
13713
14010
  var _pDrawingAnchor$get2;
13714
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);
13715
14012
  }
13716
- const newLineTop = calculateLineTopByDrawings(lineHeight, lineTop, lastPage, headerPage, footerPage);
13717
- if (lineHeight + newLineTop > section.height && column.lines.length > 0 && lastPage.sections.length > 0 || needOpenNewPageByTableLayout) {
14013
+ const newLineTop = positionedCustomBlockOnly ? lineTop : calculateLineTopByDrawings(lineHeight, lineTop, lastPage, headerPage, footerPage);
14014
+ if (lineHeight + newLineTop - section.height > LINE_LAYOUT_OVERFLOW_TOLERANCE && column.lines.length > 0 && lastPage.sections.length > 0 || needOpenNewPageByTableLayout) {
13718
14015
  setColumnFullState(column, true);
13719
14016
  _columnOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType, defaultGlyphLineHeight);
13720
14017
  if (isParagraphFirstShapedText && paragraphNonInlineSkeDrawings && paragraphNonInlineSkeDrawings.size > 0) for (const drawing of paragraphNonInlineSkeDrawings.values()) {
@@ -13728,8 +14025,7 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13728
14025
  return;
13729
14026
  }
13730
14027
  const lineIndex = preLine ? preLine.lineIndex + 1 : 0;
13731
- const { charSpace, defaultTabStop } = getCharSpaceConfig(sectionBreakConfig, paragraphConfig);
13732
- let { paddingLeft, paddingRight } = __getIndentPadding(indentFirstLine, hanging, indentStart, indentEnd, getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid), isParagraphFirstShapedText);
14028
+ let { paddingLeft, paddingRight } = __getIndentPadding(indentFirstLine, hanging, indentStart, indentEnd, charSpaceApply, isParagraphFirstShapedText);
13733
14029
  if (paddingLeft + paddingRight >= column.width) {
13734
14030
  const leftPercent = paddingLeft / (paddingLeft + paddingRight);
13735
14031
  paddingLeft = column.width * leftPercent - .5;
@@ -13750,12 +14046,16 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13750
14046
  newLine.parent = column;
13751
14047
  createAndUpdateBlockAnchor(paragraphIndex, newLine, lineTop, pDrawingAnchor);
13752
14048
  _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType, defaultGlyphLineHeight);
14049
+ if (deferredInlineGroupAnchorDrawings.length > 0) {
14050
+ var _pDrawingAnchor$get3;
14051
+ __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, deferredInlineGroupAnchorDrawings, paragraphConfig.paragraphIndex, isParagraphFirstShapedText, pDrawingAnchor === null || pDrawingAnchor === void 0 || (_pDrawingAnchor$get3 = pDrawingAnchor.get(paragraphIndex)) === null || _pDrawingAnchor$get3 === void 0 ? void 0 : _pDrawingAnchor$get3.top, paragraphAnchorLeft, true);
14052
+ }
13753
14053
  }
13754
- function __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDrawings, paragraphIndex, isParagraphFirstShapedText, drawingAnchorTop) {
14054
+ function __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDrawings, paragraphIndex, isParagraphFirstShapedText, drawingAnchorTop, drawingAnchorLeft = 0, skipRelayoutCheck = false) {
13755
14055
  if (targetDrawings.length === 0) return;
13756
- const drawings = __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, drawingAnchorTop, targetDrawings);
14056
+ const drawings = __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, drawingAnchorTop, targetDrawings, drawingAnchorLeft);
13757
14057
  if (drawings == null || drawings.size === 0) return;
13758
- _reLayoutCheck(ctx, [...drawings.values()].filter((drawing) => {
14058
+ const floatObjects = [...drawings.values()].filter((drawing) => {
13759
14059
  const layoutType = drawing.drawingOrigin.layoutType;
13760
14060
  return layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE && layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE;
13761
14061
  }).map((drawing) => {
@@ -13768,10 +14068,13 @@ function __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDra
13768
14068
  width,
13769
14069
  height,
13770
14070
  angle,
14071
+ behindDoc: drawingOrigin.behindDoc,
14072
+ layoutType: drawingOrigin.layoutType,
13771
14073
  type: "IMAGE",
13772
14074
  positionV
13773
14075
  };
13774
- }), column, paragraphIndex);
14076
+ });
14077
+ if (!skipRelayoutCheck) _reLayoutCheck(ctx, floatObjects, column, paragraphIndex);
13775
14078
  __updateDrawingPosition(column, drawings);
13776
14079
  }
13777
14080
  function __updateWrapTablePosition(ctx, table, lineTop, lineHeight, column, paragraphIndex, drawingAnchorTop) {
@@ -13804,6 +14107,22 @@ function __getWrapTablePosition(table, column, lineTop, lineHeight, drawingAncho
13804
14107
  top: (_getPositionVertical = getPositionVertical(positionV, page, lineTop, lineHeight, height, drawingAnchorTop, isPageBreak)) !== null && _getPositionVertical !== void 0 ? _getPositionVertical : 0
13805
14108
  };
13806
14109
  }
14110
+ function __avoidFlowAffectingDrawingsForTable(table, page, column) {
14111
+ const tableTop = table.top;
14112
+ const tableBottom = table.top + table.height;
14113
+ const tableRight = table.left + table.width;
14114
+ for (const drawing of page.skeDrawings.values()) {
14115
+ var _drawingOrigin$distR;
14116
+ const drawingOrigin = drawing.drawingOrigin;
14117
+ if (drawingOrigin == null || drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE || drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE || drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) continue;
14118
+ const drawingTop = drawing.aTop;
14119
+ const drawingBottom = drawing.aTop + drawing.height;
14120
+ if (drawingTop >= tableBottom || drawingBottom <= tableTop) continue;
14121
+ const drawingRight = drawing.aLeft + drawing.width + ((_drawingOrigin$distR = drawingOrigin.distR) !== null && _drawingOrigin$distR !== void 0 ? _drawingOrigin$distR : 0);
14122
+ if (drawing.aLeft >= tableRight || drawingRight <= table.left) continue;
14123
+ if (drawingRight + table.width <= column.width) table.left = Math.max(table.left, drawingRight);
14124
+ }
14125
+ }
13807
14126
  function _updateAndPositionTable(ctx, lineTop, lineHeight, page, column, section, skeTablesInParagraph, paragraphIndex, sectionBreakConfig, drawingAnchorTop) {
13808
14127
  if (skeTablesInParagraph.length === 0) return false;
13809
14128
  const firstUnPositionedTable = skeTablesInParagraph.find((table) => table.hasPositioned === false);
@@ -13813,6 +14132,7 @@ function _updateAndPositionTable(ctx, lineTop, lineHeight, page, column, section
13813
14132
  if (firstUnPositionedTable.isSlideTable === false) switch (tableSource.textWrap) {
13814
14133
  case _univerjs_core.TableTextWrapType.NONE:
13815
14134
  table.top = lineTop;
14135
+ __avoidFlowAffectingDrawingsForTable(table, page, column);
13816
14136
  break;
13817
14137
  case _univerjs_core.TableTextWrapType.WRAP:
13818
14138
  __updateWrapTablePosition(ctx, table, lineTop, lineHeight, column, paragraphIndex, drawingAnchorTop);
@@ -13866,15 +14186,47 @@ function _getCustomBlockIdsInLine(line) {
13866
14186
  for (const divide of line.divides) for (const glyph of divide.glyphGroup) if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK) customBlockIds.push(glyph.drawingId);
13867
14187
  return customBlockIds;
13868
14188
  }
14189
+ function __isZeroWidthNonFlowFloatingAnchorLine(glyphGroup, paragraphNonInlineSkeDrawings) {
14190
+ return __getZeroWidthNonFlowFloatingAnchorDrawings(glyphGroup, paragraphNonInlineSkeDrawings).length > 0;
14191
+ }
14192
+ function __getZeroWidthNonFlowFloatingAnchorDrawings(glyphGroup, paragraphNonInlineSkeDrawings) {
14193
+ const drawings = [];
14194
+ for (const glyph of glyphGroup) {
14195
+ if (__isStructuralTerminatorGlyph(glyph)) continue;
14196
+ if (__isIgnorableZeroSizeGlyph(glyph)) continue;
14197
+ if (glyph.streamType !== _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK || glyph.width !== 0 || glyph.drawingId == null) return [];
14198
+ const drawing = paragraphNonInlineSkeDrawings === null || paragraphNonInlineSkeDrawings === void 0 ? void 0 : paragraphNonInlineSkeDrawings.get(glyph.drawingId);
14199
+ const drawingOrigin = drawing === null || drawing === void 0 ? void 0 : drawing.drawingOrigin;
14200
+ if (drawing == null || drawingOrigin == null) return [];
14201
+ if (drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE) return [];
14202
+ drawings.push(drawing);
14203
+ }
14204
+ return drawings;
14205
+ }
14206
+ function __isIgnorableZeroSizeGlyph(glyph) {
14207
+ return glyph.content === "" && glyph.drawingId == null && glyph.width === 0 && glyph.bBox.ba + glyph.bBox.bd === 0;
14208
+ }
14209
+ function __isStructuralTerminatorGlyph(glyph) {
14210
+ return glyph.streamType === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH || glyph.streamType === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK || glyph.streamType === _univerjs_core.DataStreamTreeTokenType.DOCS_END;
14211
+ }
14212
+ function __hasFlowGlyph(glyphGroup) {
14213
+ return glyphGroup.some((glyph) => {
14214
+ if (__isStructuralTerminatorGlyph(glyph)) return false;
14215
+ if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK) return glyph.width !== 0;
14216
+ return glyph.content !== "" || glyph.width > 0 || glyph.bBox.ba + glyph.bBox.bd > 0;
14217
+ });
14218
+ }
13869
14219
  function _reLayoutCheck(ctx, floatObjects, column, paragraphIndex) {
13870
14220
  var _column$parent2;
13871
14221
  const page = (_column$parent2 = column.parent) === null || _column$parent2 === void 0 ? void 0 : _column$parent2.parent;
13872
- if (floatObjects.length === 0 || page == null) return;
14222
+ const flowAffectingFloatObjects = floatObjects.filter((floatObject) => floatObject.behindDoc !== _univerjs_core.BooleanNumber.TRUE || floatObject.layoutType != null && floatObject.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE);
14223
+ if (flowAffectingFloatObjects.length === 0 || page == null) return;
13873
14224
  let needBreakLineIterator = false;
13874
- for (const floatObject of floatObjects) {
14225
+ for (const floatObject of flowAffectingFloatObjects) {
13875
14226
  var _floatObjectCache$pag, _page$sections$;
13876
14227
  const floatObjectCache = ctx.floatObjectsCache.get(floatObject.id);
13877
14228
  if (floatObjectCache == null || floatObjectCache.page.segmentId !== page.segmentId) continue;
14229
+ if (floatObjectCache.count >= FLOAT_OBJECT_RELAYOUT_LIMIT) continue;
13878
14230
  const cachePageStartParagraphIndex = (_floatObjectCache$pag = floatObjectCache.page.sections[0]) === null || _floatObjectCache$pag === void 0 || (_floatObjectCache$pag = _floatObjectCache$pag.columns[0]) === null || _floatObjectCache$pag === void 0 || (_floatObjectCache$pag = _floatObjectCache$pag.lines[0]) === null || _floatObjectCache$pag === void 0 ? void 0 : _floatObjectCache$pag.paragraphIndex;
13879
14231
  const startIndex = (_page$sections$ = page.sections[0]) === null || _page$sections$ === void 0 || (_page$sections$ = _page$sections$.columns[0]) === null || _page$sections$ === void 0 || (_page$sections$ = _page$sections$.lines[0]) === null || _page$sections$ === void 0 ? void 0 : _page$sections$.paragraphIndex;
13880
14232
  if (floatObjectCache.page && cachePageStartParagraphIndex && startIndex && cachePageStartParagraphIndex !== startIndex) {
@@ -13900,7 +14252,7 @@ function _reLayoutCheck(ctx, floatObjects, column, paragraphIndex) {
13900
14252
  const { lineHeight, top } = line;
13901
14253
  const { width: columnWidth, left: columnLeft } = column;
13902
14254
  if (needBreakLineIterator) return;
13903
- for (const floatObject of floatObjects.values()) {
14255
+ for (const floatObject of flowAffectingFloatObjects.values()) {
13904
14256
  let targetObject = floatObject;
13905
14257
  if (ctx.floatObjectsCache.has(floatObject.id)) {
13906
14258
  const drawingCache = ctx.floatObjectsCache.get(floatObject.id);
@@ -13938,7 +14290,7 @@ function checkRelativeDrawingNeedRePosition(ctx, floatObject) {
13938
14290
  if (drawingCache == null) return false;
13939
14291
  if (relativeFrom === _univerjs_core.ObjectRelativeFromV.PARAGRAPH || relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE) {
13940
14292
  const { count, floatObject: prevObject } = drawingCache;
13941
- if (count < 5 && Math.abs(floatObject.top - prevObject.top) > 5) return true;
14293
+ if (count < FLOAT_OBJECT_RELAYOUT_LIMIT && Math.abs(floatObject.top - prevObject.top) > 5) return true;
13942
14294
  }
13943
14295
  return false;
13944
14296
  }
@@ -13995,43 +14347,87 @@ function __getParagraphSpace(ctx, lineSpacing = 0, spaceAbove, spaceBelow, isPar
13995
14347
  spaceBelowApply
13996
14348
  };
13997
14349
  }
13998
- function __getLineHeight(glyphLineHeight, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid) {
13999
- let paddingTop = paragraphLineGapDefault;
14000
- let paddingBottom = paragraphLineGapDefault;
14001
- if (gridType === _univerjs_core.GridType.DEFAULT || snapToGrid === _univerjs_core.BooleanNumber.FALSE) {
14002
- if (spacingRule === _univerjs_core.SpacingRule.AUTO) return {
14350
+ function __getParagraphAnchorLeft(sectionBreakConfig, paragraphConfig, indentStart) {
14351
+ const { paragraphStyle = {} } = paragraphConfig;
14352
+ const { snapToGrid = _univerjs_core.BooleanNumber.TRUE } = paragraphStyle;
14353
+ const { gridType = _univerjs_core.GridType.LINES } = sectionBreakConfig;
14354
+ const { charSpace, defaultTabStop } = getCharSpaceConfig(sectionBreakConfig, paragraphConfig);
14355
+ const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
14356
+ const paragraphAnchorLeft = getNumberUnitValue(indentStart, charSpaceApply);
14357
+ if (paragraphAnchorLeft > 0) return paragraphAnchorLeft;
14358
+ return getNumberUnitValue(paragraphConfig.docxFallbackAnchorLeft, charSpaceApply);
14359
+ }
14360
+ function getLineHeightMetrics(glyphLineHeight, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid, useWordStyleLineHeight = true, scaleAutoLineSpacingByGlyphHeight = true) {
14361
+ if (!useWordStyleLineHeight) {
14362
+ let paddingTop = paragraphLineGapDefault;
14363
+ let paddingBottom = paragraphLineGapDefault;
14364
+ if (gridType === _univerjs_core.GridType.DEFAULT || snapToGrid === _univerjs_core.BooleanNumber.FALSE) {
14365
+ if (spacingRule === _univerjs_core.SpacingRule.AUTO) return {
14366
+ paddingTop,
14367
+ paddingBottom,
14368
+ contentHeight: lineSpacing * glyphLineHeight,
14369
+ lineSpacingApply: glyphLineHeight
14370
+ };
14371
+ return {
14372
+ paddingTop,
14373
+ paddingBottom,
14374
+ contentHeight: Math.max(lineSpacing, glyphLineHeight),
14375
+ lineSpacingApply: lineSpacing
14376
+ };
14377
+ }
14378
+ let lineSpacingApply = 0;
14379
+ if (spacingRule === _univerjs_core.SpacingRule.AUTO) lineSpacingApply = lineSpacing * linePitch;
14380
+ else lineSpacingApply = lineSpacing;
14381
+ if (glyphLineHeight + paragraphLineGapDefault * 2 < lineSpacingApply) paddingTop = paddingBottom = (lineSpacingApply - glyphLineHeight) / 2;
14382
+ else lineSpacingApply = glyphLineHeight;
14383
+ return {
14003
14384
  paddingTop,
14004
14385
  paddingBottom,
14005
- contentHeight: lineSpacing * glyphLineHeight,
14006
- lineSpacingApply: glyphLineHeight
14386
+ contentHeight: glyphLineHeight,
14387
+ lineSpacingApply
14007
14388
  };
14389
+ }
14390
+ const usesDocumentGrid = spacingRule === _univerjs_core.SpacingRule.AUTO && snapToGrid === _univerjs_core.BooleanNumber.TRUE && gridType !== _univerjs_core.GridType.DEFAULT;
14391
+ if (spacingRule === _univerjs_core.SpacingRule.AUTO) {
14392
+ const lineSpacingApply = usesDocumentGrid ? lineSpacing * linePitch : scaleAutoLineSpacingByGlyphHeight ? lineSpacing * glyphLineHeight : glyphLineHeight;
14393
+ const padding = (lineSpacingApply - glyphLineHeight) / 2;
14008
14394
  return {
14009
- paddingTop,
14010
- paddingBottom,
14011
- contentHeight: Math.max(lineSpacing, glyphLineHeight),
14012
- lineSpacingApply: lineSpacing
14395
+ paddingTop: padding,
14396
+ paddingBottom: padding,
14397
+ contentHeight: glyphLineHeight,
14398
+ lineSpacingApply
14013
14399
  };
14014
14400
  }
14015
- let lineSpacingApply = 0;
14016
- if (spacingRule === _univerjs_core.SpacingRule.AUTO) lineSpacingApply = lineSpacing * linePitch;
14017
- else lineSpacingApply = lineSpacing;
14018
- if (glyphLineHeight + paragraphLineGapDefault * 2 < lineSpacingApply) paddingTop = paddingBottom = (lineSpacingApply - glyphLineHeight) / 2;
14019
- else lineSpacingApply = glyphLineHeight;
14401
+ if (spacingRule === _univerjs_core.SpacingRule.AT_LEAST) {
14402
+ const lineSpacingApply = Math.max(lineSpacing, glyphLineHeight);
14403
+ const padding = (lineSpacingApply - glyphLineHeight) / 2;
14404
+ return {
14405
+ paddingTop: padding,
14406
+ paddingBottom: padding,
14407
+ contentHeight: glyphLineHeight,
14408
+ lineSpacingApply
14409
+ };
14410
+ }
14411
+ const exactLineSpacingApply = snapToGrid === _univerjs_core.BooleanNumber.TRUE && gridType !== _univerjs_core.GridType.DEFAULT ? Math.max(lineSpacing, linePitch) : lineSpacing;
14412
+ const exactPadding = (exactLineSpacingApply - glyphLineHeight) / 2;
14020
14413
  return {
14021
- paddingTop,
14022
- paddingBottom,
14414
+ paddingTop: exactPadding,
14415
+ paddingBottom: exactPadding,
14023
14416
  contentHeight: glyphLineHeight,
14024
- lineSpacingApply
14417
+ lineSpacingApply: exactLineSpacingApply
14025
14418
  };
14026
14419
  }
14027
- function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnchorTop) {
14028
- var _line$parent;
14420
+ function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnchorTop, paragraphNonInlineSkeDrawings) {
14421
+ var _line$parent, _section$top;
14029
14422
  const column = line.parent;
14423
+ const section = column === null || column === void 0 ? void 0 : column.parent;
14030
14424
  const page = line === null || line === void 0 || (_line$parent = line.parent) === null || _line$parent === void 0 || (_line$parent = _line$parent.parent) === null || _line$parent === void 0 ? void 0 : _line$parent.parent;
14031
14425
  if (page == null || column == null) return;
14032
14426
  const isPageBreak = __checkPageBreak(column);
14033
14427
  const drawings = /* @__PURE__ */ new Map();
14034
14428
  const { top, lineHeight, marginBottom = 0 } = line;
14429
+ const sectionTop = (_section$top = section === null || section === void 0 ? void 0 : section.top) !== null && _section$top !== void 0 ? _section$top : 0;
14430
+ const lineTop = sectionTop + top;
14035
14431
  for (const divide of line.divides) for (const glyph of divide.glyphGroup) if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.width !== 0) {
14036
14432
  const { drawingId } = glyph;
14037
14433
  if (drawingId == null) continue;
@@ -14042,21 +14438,37 @@ function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnch
14042
14438
  const { size, angle } = docTransform;
14043
14439
  const { width = 0, height = 0 } = size;
14044
14440
  const glyphHeight = glyph.bBox.bd + glyph.bBox.ba;
14045
- drawing.aLeft = divide.left + divide.paddingLeft + glyph.left + .5 * glyph.width - .5 * width || 0;
14046
- drawing.aTop = top + lineHeight - .5 * glyphHeight - .5 * height - marginBottom;
14441
+ drawing.aLeft = column.left + divide.left + divide.paddingLeft + glyph.left + .5 * glyph.width - .5 * width || 0;
14442
+ if (glyph.width > divide.width) {
14443
+ var _paragraphNonInlineSk;
14444
+ for (const positionedDrawing of (_paragraphNonInlineSk = paragraphNonInlineSkeDrawings === null || paragraphNonInlineSkeDrawings === void 0 ? void 0 : paragraphNonInlineSkeDrawings.values()) !== null && _paragraphNonInlineSk !== void 0 ? _paragraphNonInlineSk : []) {
14445
+ const positionedOrigin = positionedDrawing.drawingOrigin;
14446
+ if (positionedOrigin == null || positionedOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE || positionedOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE || positionedOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) continue;
14447
+ const positionedBottom = positionedDrawing.aTop + positionedDrawing.height;
14448
+ const lineBottom = lineTop + lineHeight;
14449
+ if (positionedDrawing.aTop >= lineBottom || positionedBottom <= lineTop) continue;
14450
+ const positionedRight = positionedDrawing.aLeft + positionedDrawing.width;
14451
+ const drawingRight = drawing.aLeft + width;
14452
+ if (positionedDrawing.aLeft < drawingRight && positionedRight > drawing.aLeft) {
14453
+ var _positionedOrigin$dis;
14454
+ drawing.aLeft = Math.max(drawing.aLeft, positionedDrawing.aLeft + positionedDrawing.width + ((_positionedOrigin$dis = positionedOrigin.distR) !== null && _positionedOrigin$dis !== void 0 ? _positionedOrigin$dis : 0));
14455
+ }
14456
+ }
14457
+ }
14458
+ drawing.aTop = lineTop + lineHeight - .5 * glyphHeight - .5 * height - marginBottom;
14047
14459
  drawing.width = width;
14048
14460
  drawing.height = height;
14049
14461
  drawing.angle = angle;
14050
14462
  drawing.isPageBreak = isPageBreak;
14051
- drawing.lineTop = top;
14463
+ drawing.lineTop = lineTop;
14052
14464
  drawing.columnLeft = column.left;
14053
- drawing.blockAnchorTop = blockAnchorTop !== null && blockAnchorTop !== void 0 ? blockAnchorTop : top;
14465
+ drawing.blockAnchorTop = blockAnchorTop == null ? lineTop : sectionTop + blockAnchorTop;
14054
14466
  drawing.lineHeight = line.lineHeight;
14055
14467
  drawings.set(drawing.drawingId, drawing);
14056
14468
  }
14057
14469
  page.skeDrawings = new Map([...page.skeDrawings, ...drawings]);
14058
14470
  }
14059
- function __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, blockAnchorTop, needPositionDrawings = []) {
14471
+ function __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, blockAnchorTop, needPositionDrawings = [], blockAnchorLeft = 0) {
14060
14472
  var _column$parent3;
14061
14473
  const page = (_column$parent3 = column.parent) === null || _column$parent3 === void 0 ? void 0 : _column$parent3.parent;
14062
14474
  if (page == null || needPositionDrawings.length === 0) return;
@@ -14070,7 +14482,12 @@ function __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShape
14070
14482
  const { docTransform } = drawingOrigin;
14071
14483
  const { positionH, positionV, size, angle } = docTransform;
14072
14484
  const { width = 0, height = 0 } = size;
14073
- drawing.aLeft = (_getPositionHorizon2 = getPositionHorizon(positionH, column, page, width, isPageBreak)) !== null && _getPositionHorizon2 !== void 0 ? _getPositionHorizon2 : 0;
14485
+ let aLeft = (_getPositionHorizon2 = getPositionHorizon(positionH, column, page, width, isPageBreak)) !== null && _getPositionHorizon2 !== void 0 ? _getPositionHorizon2 : 0;
14486
+ if (positionH.relativeFrom === _univerjs_core.ObjectRelativeFromH.COLUMN && blockAnchorLeft > 0) {
14487
+ const renderedColumnOrigin = isPageBreak ? 0 : column.left || page.marginLeft;
14488
+ aLeft += blockAnchorLeft - renderedColumnOrigin;
14489
+ }
14490
+ drawing.aLeft = aLeft;
14074
14491
  drawing.aTop = (_getPositionVertical2 = getPositionVertical(positionV, page, lineTop, lineHeight, height, blockAnchorTop, isPageBreak)) !== null && _getPositionVertical2 !== void 0 ? _getPositionVertical2 : 0;
14075
14492
  drawing.width = width;
14076
14493
  drawing.height = height;
@@ -14139,7 +14556,7 @@ function __getGlyphGroupByLine({ divides }) {
14139
14556
  return divides.flatMap((divide) => divide.glyphGroup);
14140
14557
  }
14141
14558
  function __isNullLine(line) {
14142
- return !line.divides[0].glyphGroup[0];
14559
+ return __getGlyphGroupByLine(line).every((glyph) => !glyph.content && !glyph.drawingId);
14143
14560
  }
14144
14561
 
14145
14562
  //#endregion
@@ -14219,9 +14636,29 @@ function isColumnFull(page) {
14219
14636
  for (let i = 0; i < columnsLen; i++) if (!section.columns[i].isFull) return false;
14220
14637
  return true;
14221
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
+ }
14222
14658
  function getNumberUnitValue(unitValue, benchMark) {
14223
14659
  if (!unitValue) return 0;
14224
14660
  const { v: value, u: unit } = unitValue;
14661
+ if (typeof value !== "number" || !Number.isFinite(value)) return 0;
14225
14662
  if (!unit) return value;
14226
14663
  if (unit === _univerjs_core.NumberUnitType.PIXEL) return value;
14227
14664
  return value * benchMark;
@@ -14236,18 +14673,22 @@ function validationGrid(gridType = _univerjs_core.GridType.LINES, snapToGrid = _
14236
14673
  return snapToGrid === _univerjs_core.BooleanNumber.TRUE && (gridType === _univerjs_core.GridType.LINES_AND_CHARS || gridType === _univerjs_core.GridType.SNAP_TO_CHARS);
14237
14674
  }
14238
14675
  function getLineHeightConfig(sectionBreakConfig, paragraphConfig) {
14239
- const { paragraphStyle = {} } = paragraphConfig;
14676
+ const { paragraphStyle = {}, useWordStyleLineHeight = false } = paragraphConfig;
14240
14677
  const { linePitch = 15.6, gridType = _univerjs_core.GridType.LINES, paragraphLineGapDefault = 0 } = sectionBreakConfig;
14241
- const { lineSpacing = 0, spacingRule = _univerjs_core.SpacingRule.AUTO, snapToGrid = _univerjs_core.BooleanNumber.TRUE } = paragraphStyle;
14678
+ const hasDocumentGrid = gridType === _univerjs_core.GridType.LINES_AND_CHARS || gridType === _univerjs_core.GridType.SNAP_TO_CHARS;
14679
+ const defaultSnapToGrid = useWordStyleLineHeight && !hasDocumentGrid ? _univerjs_core.BooleanNumber.FALSE : _univerjs_core.BooleanNumber.TRUE;
14680
+ const { lineSpacing = 0, spacingRule = _univerjs_core.SpacingRule.AUTO, snapToGrid = defaultSnapToGrid } = paragraphStyle;
14242
14681
  let lineSpacingApply = lineSpacing;
14243
- if ((gridType === _univerjs_core.GridType.LINES || gridType === _univerjs_core.GridType.LINES_AND_CHARS) && lineSpacing === 0 && spacingRule === _univerjs_core.SpacingRule.AUTO) lineSpacingApply = 1;
14682
+ if (useWordStyleLineHeight && lineSpacing === 0 && spacingRule === _univerjs_core.SpacingRule.AUTO) lineSpacingApply = 1;
14683
+ else if (!useWordStyleLineHeight && (gridType === _univerjs_core.GridType.LINES || gridType === _univerjs_core.GridType.LINES_AND_CHARS) && lineSpacing === 0 && spacingRule === _univerjs_core.SpacingRule.AUTO) lineSpacingApply = 1;
14244
14684
  return {
14245
14685
  paragraphLineGapDefault,
14246
14686
  linePitch,
14247
14687
  gridType,
14248
14688
  lineSpacing: lineSpacingApply,
14249
14689
  spacingRule,
14250
- snapToGrid
14690
+ snapToGrid,
14691
+ useWordStyleLineHeight
14251
14692
  };
14252
14693
  }
14253
14694
  function getCharSpaceConfig(sectionBreakConfig, paragraphConfig) {
@@ -14263,15 +14704,17 @@ function getCharSpaceConfig(sectionBreakConfig, paragraphConfig) {
14263
14704
  snapToGrid
14264
14705
  };
14265
14706
  }
14266
- function updateBlockIndex(pages, start = -1) {
14707
+ function updateBlockIndex(pages, start = -1, documentCompatibilityPolicy) {
14267
14708
  let prePageStartIndex = start;
14709
+ const shouldUseLayoutColumnWidth = (documentCompatibilityPolicy === null || documentCompatibilityPolicy === void 0 ? void 0 : documentCompatibilityPolicy.mode) !== "unspecified";
14268
14710
  for (const page of pages) {
14269
- const { sections, skeTables } = page;
14711
+ const { sections, skeTables, skeColumnGroups = /* @__PURE__ */ new Map() } = page;
14270
14712
  const pageStartIndex = prePageStartIndex;
14271
14713
  let preSectionStartIndex = pageStartIndex;
14272
14714
  let maxContentWidth = Number.NEGATIVE_INFINITY;
14273
14715
  let contentHeight = 0;
14274
14716
  for (const section of sections) {
14717
+ collapseRedundantColumnBreakOverflow(section);
14275
14718
  const { columns } = section;
14276
14719
  const sectionStartIndex = preSectionStartIndex;
14277
14720
  let preColumnStartIndex = sectionStartIndex;
@@ -14290,6 +14733,16 @@ function updateBlockIndex(pages, start = -1) {
14290
14733
  const table = skeTables.get(tableId);
14291
14734
  if (table) lineStartIndex = table.ed;
14292
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
+ }
14293
14746
  let preDivideStartIndex = lineStartIndex;
14294
14747
  let actualWidth = 0;
14295
14748
  let maxLineAsc = 0;
@@ -14329,8 +14782,9 @@ function updateBlockIndex(pages, start = -1) {
14329
14782
  column.st = columStartIndex + 1;
14330
14783
  column.ed = preLineStartIndex >= column.st ? preLineStartIndex : column.st;
14331
14784
  column.height = columnHeight;
14332
- column.width = maxColumnWidth;
14333
- sectionWidth += maxColumnWidth;
14785
+ const measuredColumnWidth = shouldUseLayoutColumnWidth && Number.isFinite(column.width) && column.width > 0 ? column.width : maxColumnWidth;
14786
+ column.width = measuredColumnWidth;
14787
+ sectionWidth += measuredColumnWidth;
14334
14788
  maxSectionHeight = Math.max(maxSectionHeight, column.height);
14335
14789
  preColumnStartIndex = column.ed;
14336
14790
  }
@@ -14345,6 +14799,10 @@ function updateBlockIndex(pages, start = -1) {
14345
14799
  const { ed } = table;
14346
14800
  preSectionStartIndex = Math.max(preSectionStartIndex, ed);
14347
14801
  }
14802
+ for (const columnGroup of skeColumnGroups.values()) {
14803
+ const { ed } = columnGroup;
14804
+ preSectionStartIndex = Math.max(preSectionStartIndex, ed);
14805
+ }
14348
14806
  page.st = pageStartIndex + 1;
14349
14807
  page.ed = preSectionStartIndex >= page.st ? preSectionStartIndex : page.st;
14350
14808
  page.height = contentHeight;
@@ -14352,15 +14810,40 @@ function updateBlockIndex(pages, start = -1) {
14352
14810
  prePageStartIndex = page.ed;
14353
14811
  }
14354
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
+ }
14355
14835
  function updateInlineDrawingCoordsAndBorder(ctx, pages) {
14356
14836
  lineIterator(pages, (line, _, __, page) => {
14357
- var _ctx$paragraphConfigC, _ctx$skeletonResource;
14837
+ var _ctx$paragraphConfigC, _ctx$skeletonResource, _paragraphStyle$shadi;
14358
14838
  const { segmentId } = page;
14359
14839
  const paragraphConfig = (_ctx$paragraphConfigC = ctx.paragraphConfigCache.get(segmentId)) === null || _ctx$paragraphConfigC === void 0 ? void 0 : _ctx$paragraphConfigC.get(line.paragraphIndex);
14360
14840
  const affectInlineDrawings = paragraphConfig === null || paragraphConfig === void 0 ? void 0 : paragraphConfig.paragraphInlineSkeDrawings;
14841
+ const affectNonInlineDrawings = paragraphConfig === null || paragraphConfig === void 0 ? void 0 : paragraphConfig.paragraphNonInlineSkeDrawings;
14361
14842
  const drawingAnchor = (_ctx$skeletonResource = ctx.skeletonResourceReference) === null || _ctx$skeletonResource === void 0 || (_ctx$skeletonResource = _ctx$skeletonResource.drawingAnchor) === null || _ctx$skeletonResource === void 0 || (_ctx$skeletonResource = _ctx$skeletonResource.get(segmentId)) === null || _ctx$skeletonResource === void 0 ? void 0 : _ctx$skeletonResource.get(line.paragraphIndex);
14362
- if (affectInlineDrawings && affectInlineDrawings.size > 0) updateInlineDrawingPosition(line, affectInlineDrawings, drawingAnchor === null || drawingAnchor === void 0 ? void 0 : drawingAnchor.top);
14843
+ if (affectInlineDrawings && affectInlineDrawings.size > 0) updateInlineDrawingPosition(line, affectInlineDrawings, drawingAnchor === null || drawingAnchor === void 0 ? void 0 : drawingAnchor.top, affectNonInlineDrawings);
14363
14844
  const paragraphStyle = paragraphConfig === null || paragraphConfig === void 0 ? void 0 : paragraphConfig.paragraphStyle;
14845
+ const paragraphBackgroundColor = paragraphStyle === null || paragraphStyle === void 0 || (_paragraphStyle$shadi = paragraphStyle.shading) === null || _paragraphStyle$shadi === void 0 ? void 0 : _paragraphStyle$shadi.backgroundColor;
14846
+ if (paragraphBackgroundColor) line.backgroundColor = paragraphBackgroundColor;
14364
14847
  if (line.divides.length > 0) {
14365
14848
  const lastDivide = line.divides[line.divides.length - 1];
14366
14849
  const lastGlyph = lastDivide.glyphGroup[lastDivide.glyphGroup.length - 1];
@@ -14400,6 +14883,264 @@ function lineIterator(pagesOrCells, cb) {
14400
14883
  }
14401
14884
  }
14402
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
+ }
14403
15144
  function columnIterator(pages, iteratorFunction) {
14404
15145
  for (const page of pages) {
14405
15146
  const { sections } = page;
@@ -14422,7 +15163,14 @@ function getPositionHorizon(positionH, column, page, objectWidth, isPageBreak =
14422
15163
  else if (align === _univerjs_core.AlignTypeH.CENTER) absoluteLeft = left + width / 2 - objectWidth / 2;
14423
15164
  return absoluteLeft;
14424
15165
  }
14425
- 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) {
14426
15174
  const { pageWidth } = page;
14427
15175
  let absoluteLeft = 0;
14428
15176
  if (align === _univerjs_core.AlignTypeH.RIGHT) absoluteLeft = pageWidth - objectWidth;
@@ -14430,14 +15178,12 @@ function getPositionHorizon(positionH, column, page, objectWidth, isPageBreak =
14430
15178
  return absoluteLeft;
14431
15179
  }
14432
15180
  }
14433
- else if (posOffset) {
14434
- const { pageWidth, marginLeft, marginRight } = page;
14435
- const boundaryRight = pageWidth - marginRight;
15181
+ else if (posOffset != null) {
14436
15182
  let absoluteLeft = 0;
15183
+ const { marginLeft } = page;
14437
15184
  if (relativeFrom === _univerjs_core.ObjectRelativeFromH.COLUMN) absoluteLeft = (isPageBreak ? 0 : (column === null || column === void 0 ? void 0 : column.left) || 0) + posOffset;
14438
15185
  else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.LEFT_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.MARGIN) absoluteLeft = posOffset + marginLeft;
14439
15186
  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) absoluteLeft = posOffset;
14440
- if (absoluteLeft + objectWidth > boundaryRight) absoluteLeft = boundaryRight - objectWidth;
14441
15187
  return absoluteLeft;
14442
15188
  } else if (percent) {
14443
15189
  const { pageWidth, marginLeft, marginRight } = page;
@@ -14499,9 +15245,9 @@ function getFontConfigFromLastGlyph(glyph, sectionBreakConfig, paragraphStyle) {
14499
15245
  };
14500
15246
  }
14501
15247
  function getBulletParagraphTextStyle(bullet, viewModel) {
14502
- var _lists$listType$nesti;
15248
+ var _lists$listType;
14503
15249
  const { listType } = bullet;
14504
- return (_lists$listType$nesti = viewModel.getDataModel().getBulletPresetList()[listType].nestingLevel[0].paragraphProperties) === null || _lists$listType$nesti === void 0 ? void 0 : _lists$listType$nesti.textStyle;
15250
+ return (_lists$listType = viewModel.getDataModel().getBulletPresetList()[listType]) === null || _lists$listType === void 0 || (_lists$listType = _lists$listType.nestingLevel) === null || _lists$listType === void 0 || (_lists$listType = _lists$listType[0]) === null || _lists$listType === void 0 || (_lists$listType = _lists$listType.paragraphProperties) === null || _lists$listType === void 0 ? void 0 : _lists$listType.textStyle;
14505
15251
  }
14506
15252
  const DEFAULT_TEXT_RUN = {
14507
15253
  ts: {},
@@ -14509,6 +15255,7 @@ const DEFAULT_TEXT_RUN = {
14509
15255
  ed: 0
14510
15256
  };
14511
15257
  function getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig, paragraph) {
15258
+ var _sectionBreakConfig$d;
14512
15259
  const { gridType = _univerjs_core.GridType.LINES, charSpace = 0, documentTextStyle = {}, pageSize = {
14513
15260
  width: Number.POSITIVE_INFINITY,
14514
15261
  height: Number.POSITIVE_INFINITY
@@ -14540,16 +15287,20 @@ function getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig
14540
15287
  ...customRangeStyle,
14541
15288
  ...bulletTextStyle
14542
15289
  };
15290
+ const fontStyle = getFontStyleString(textStyle);
15291
+ const mixTextStyle = {
15292
+ ...documentTextStyle,
15293
+ ...textStyle
15294
+ };
15295
+ const pageWidth = pageSize.width || Number.POSITIVE_INFINITY - marginLeft - marginRight;
14543
15296
  const result = {
14544
- fontStyle: getFontStyleString(textStyle),
14545
- textStyle: {
14546
- ...documentTextStyle,
14547
- ...textStyle
14548
- },
15297
+ fontStyle,
15298
+ textStyle: mixTextStyle,
14549
15299
  charSpace,
14550
15300
  gridType,
14551
15301
  snapToGrid,
14552
- pageWidth: pageSize.width || Number.POSITIVE_INFINITY - marginLeft - marginRight
15302
+ documentCompatibilityPolicy: (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy(),
15303
+ pageWidth
14553
15304
  };
14554
15305
  if (!hasAddonStyle && originTextRun) fontCreateConfigCache.setValue(st, ed, result);
14555
15306
  return result;
@@ -14684,17 +15435,6 @@ function resetContext(ctx) {
14684
15435
  ctx.isDirty = false;
14685
15436
  (_ctx$skeleton$drawing = ctx.skeleton.drawingAnchor) === null || _ctx$skeleton$drawing === void 0 || _ctx$skeleton$drawing.clear();
14686
15437
  }
14687
- function mergeByV(object, originObject, type) {
14688
- const mergeIterator = (obj, originObj, key) => {
14689
- if (key !== "v") if (typeof originObj === "object") return (0, _univerjs_core.mergeWith)(obj, originObj, mergeIterator);
14690
- else return originObj !== null && originObj !== void 0 ? originObj : obj;
14691
- if (typeof originObj === "number") {
14692
- if (typeof obj === "number") return type === "max" ? Math.max(originObj, obj) : Math.min(originObj, obj);
14693
- }
14694
- return originObj !== null && originObj !== void 0 ? originObj : obj;
14695
- };
14696
- return (0, _univerjs_core.mergeWith)(object, originObject, mergeIterator);
14697
- }
14698
15438
  function getPageFromPath(skeletonData, path) {
14699
15439
  const pathCopy = [...path];
14700
15440
  let page = null;
@@ -14711,6 +15451,13 @@ function getPageFromPath(skeletonData, path) {
14711
15451
  pathCopy.shift();
14712
15452
  const cellIndex = pathCopy.shift();
14713
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;
14714
15461
  }
14715
15462
  }
14716
15463
  return page;
@@ -14760,7 +15507,7 @@ function createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference,
14760
15507
  header = (_skeHeaders$get2 = skeHeaders.get(headerId)) === null || _skeHeaders$get2 === void 0 ? void 0 : _skeHeaders$get2.get(pageWidth);
14761
15508
  } else if (headerTreeMap && headerTreeMap.has(headerId)) {
14762
15509
  header = _createSkeletonHeaderFooter(ctx, headerTreeMap.get(headerId), sectionBreakConfig, skeletonResourceReference, headerId, true);
14763
- skeHeaders.set(headerId, new Map([[pageWidth, header]]));
15510
+ skeHeaders.set(headerId, /* @__PURE__ */ new Map([[pageWidth, header]]));
14764
15511
  }
14765
15512
  page.headerId = headerId;
14766
15513
  }
@@ -14771,7 +15518,7 @@ function createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference,
14771
15518
  footer = (_skeFooters$get2 = skeFooters.get(footerId)) === null || _skeFooters$get2 === void 0 ? void 0 : _skeFooters$get2.get(pageWidth);
14772
15519
  } else if (footerTreeMap && footerTreeMap.has(footerId)) {
14773
15520
  footer = _createSkeletonHeaderFooter(ctx, footerTreeMap.get(footerId), sectionBreakConfig, skeletonResourceReference, footerId, false);
14774
- skeFooters.set(footerId, new Map([[pageWidth, footer]]));
15521
+ skeFooters.set(footerId, /* @__PURE__ */ new Map([[pageWidth, footer]]));
14775
15522
  }
14776
15523
  page.footerId = footerId;
14777
15524
  }
@@ -14817,11 +15564,13 @@ function _getNullPage(type = 0, segmentId = "") {
14817
15564
  ed: 0,
14818
15565
  skeDrawings: /* @__PURE__ */ new Map(),
14819
15566
  skeTables: /* @__PURE__ */ new Map(),
15567
+ skeColumnGroups: /* @__PURE__ */ new Map(),
14820
15568
  type,
14821
15569
  segmentId
14822
15570
  };
14823
15571
  }
14824
15572
  function _createSkeletonHeaderFooter(ctx, headerOrFooterViewModel, sectionBreakConfig, skeletonResourceReference, segmentId, isHeader = true, areaPage, count = 0) {
15573
+ var _sectionBreakConfig$d;
14825
15574
  const { lists, footerTreeMap, headerTreeMap, localeService, pageSize, drawings, marginLeft = 0, marginRight = 0, marginHeader = 0, marginFooter = 0 } = sectionBreakConfig;
14826
15575
  const pageWidth = (pageSize === null || pageSize === void 0 ? void 0 : pageSize.width) || Number.POSITIVE_INFINITY;
14827
15576
  const pageHeight = (pageSize === null || pageSize === void 0 ? void 0 : pageSize.height) || Number.POSITIVE_INFINITY;
@@ -14849,7 +15598,7 @@ function _createSkeletonHeaderFooter(ctx, headerOrFooterViewModel, sectionBreakC
14849
15598
  resetContext(ctx);
14850
15599
  return _createSkeletonHeaderFooter(ctx, headerOrFooterViewModel, sectionBreakConfig, skeletonResourceReference, segmentId, isHeader, areaPage, count);
14851
15600
  }
14852
- updateBlockIndex([page]);
15601
+ updateBlockIndex([page], -1, (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy());
14853
15602
  if (isHeader) Object.assign(page, {
14854
15603
  marginTop: marginHeader,
14855
15604
  marginBottom: 5
@@ -14866,9 +15615,22 @@ function createNullCellPage(ctx, sectionBreakConfig, tableConfig, row, col, avai
14866
15615
  const { skeletonResourceReference } = ctx;
14867
15616
  const { cellMargin, tableRows, tableColumns, tableId } = tableConfig;
14868
15617
  const cellConfig = tableRows[row].tableCells[col];
14869
- const { start = { v: 10 }, end = { v: 10 }, top = { v: 5 }, bottom = { v: 5 } } = (_ref = (_cellConfig$margin = cellConfig.margin) !== null && _cellConfig$margin !== void 0 ? _cellConfig$margin : cellMargin) !== null && _ref !== void 0 ? _ref : {};
15618
+ let { start = { v: 10 }, end = { v: 10 }, top = { v: 5 }, bottom = { v: 5 } } = (_ref = (_cellConfig$margin = cellConfig.margin) !== null && _cellConfig$margin !== void 0 ? _cellConfig$margin : cellMargin) !== null && _ref !== void 0 ? _ref : {};
14870
15619
  const columnSpan = Math.max(1, (_cellConfig$columnSpa = cellConfig.columnSpan) !== null && _cellConfig$columnSpa !== void 0 ? _cellConfig$columnSpa : 1);
14871
15620
  const pageWidth = tableColumns.slice(col, col + columnSpan).reduce((sum, column) => sum + column.size.width.v, 0);
15621
+ if (start.v + end.v >= pageWidth) {
15622
+ const marginWidth = start.v + end.v;
15623
+ const availableMarginWidth = Math.max(0, pageWidth - 1);
15624
+ const startRatio = marginWidth > 0 ? start.v / marginWidth : .5;
15625
+ start = {
15626
+ ...start,
15627
+ v: availableMarginWidth * startRatio
15628
+ };
15629
+ end = {
15630
+ ...end,
15631
+ v: availableMarginWidth - start.v
15632
+ };
15633
+ }
14872
15634
  const pageHeight = maxCellPageHeight;
14873
15635
  const cellSectionBreakConfig = {
14874
15636
  lists,
@@ -14897,7 +15659,7 @@ function createNullCellPage(ctx, sectionBreakConfig, tableConfig, row, col, avai
14897
15659
  };
14898
15660
  }
14899
15661
  function createSkeletonCellPages(ctx, viewModel, cellNode, sectionBreakConfig, tableConfig, row, col, availableHeight = Number.POSITIVE_INFINITY, maxCellPageHeight = Number.POSITIVE_INFINITY) {
14900
- var _ctx$dataModel, _ctx$dataModel$getBod;
15662
+ var _sectionBreakConfig$d2, _ctx$dataModel, _ctx$dataModel$getBod;
14901
15663
  const sectionNode = cellNode.children[0];
14902
15664
  const { page: areaPage, sectionBreakConfig: cellSectionBreakConfig } = createNullCellPage(ctx, sectionBreakConfig, tableConfig, row, col, availableHeight, maxCellPageHeight);
14903
15665
  const { pages } = dealWithSection(ctx, viewModel, sectionNode, areaPage, cellSectionBreakConfig);
@@ -14905,8 +15667,8 @@ function createSkeletonCellPages(ctx, viewModel, cellNode, sectionBreakConfig, t
14905
15667
  p.type = 3;
14906
15668
  p.segmentId = tableConfig.tableId;
14907
15669
  }
14908
- updateBlockIndex(pages, cellNode.startIndex);
14909
- 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);
14910
15672
  updateInlineDrawingCoordsAndBorder(ctx, pages);
14911
15673
  expandCellPageHeightForInlineDrawings(pages);
14912
15674
  return pages;
@@ -14922,7 +15684,7 @@ function expandCellPageHeightForInlineDrawings(pages) {
14922
15684
  });
14923
15685
  }
14924
15686
  }
14925
- function applyTrailingCellBlockRangeSpaceBelow(pages, body, cellEndIndex) {
15687
+ function applyTrailingBlockRangeSpaceBelow(pages, body, containerEndIndex) {
14926
15688
  const blockRanges = body === null || body === void 0 ? void 0 : body.blockRanges;
14927
15689
  const trailingBlockRangeSpace = 28;
14928
15690
  if (!(blockRanges === null || blockRanges === void 0 ? void 0 : blockRanges.length)) return;
@@ -14932,15 +15694,12 @@ function applyTrailingCellBlockRangeSpaceBelow(pages, body, cellEndIndex) {
14932
15694
  if (!lastLine) continue;
14933
15695
  const paragraphIndex = lastLine.paragraphIndex;
14934
15696
  if (!blockRanges.some((range) => range.startIndex < paragraphIndex && paragraphIndex < range.endIndex)) continue;
14935
- 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;
14936
15698
  page.height += lastLine.spaceBelowApply || trailingBlockRangeSpace;
14937
15699
  }
14938
15700
  }
14939
- function _getVerticalMargin(marginTB, headerOrFooter, pageHeight) {
14940
- if (!headerOrFooter || headerOrFooter.sections[0].columns[0].lines.length === 0) return marginTB;
14941
- const HeaderFooterPageHeight = headerOrFooter.height + headerOrFooter.marginTop + headerOrFooter.marginBottom;
14942
- const maxMargin = getHeaderFooterMaxHeight(pageHeight);
14943
- return Math.min(maxMargin, Math.max(marginTB, HeaderFooterPageHeight));
15701
+ function _getVerticalMargin(marginTB, _headerOrFooter, _pageHeight) {
15702
+ return marginTB;
14944
15703
  }
14945
15704
 
14946
15705
  //#endregion
@@ -15047,13 +15806,41 @@ function adjustGlyphsInDivide(divide, justificationRatio, extraJustification) {
15047
15806
  }
15048
15807
  setGlyphGroupLeft(divide.glyphGroup);
15049
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
+ }
15050
15818
  /**
15051
15819
  * When aligning text horizontally within a document,
15052
15820
  * it may be ineffective if the total line width is not initially calculated.
15053
15821
  * Therefore, multiple calculations are performed, which may impact performance.
15054
15822
  * Needs optimization for efficiency.
15055
15823
  */
15056
- function horizontalAlignHandler(line, horizontalAlign) {
15824
+ function shouldAllowOverflowHorizontalOffset(sectionBreakConfig) {
15825
+ var _sectionBreakConfig$r;
15826
+ return ((_sectionBreakConfig$r = sectionBreakConfig.renderConfig) === null || _sectionBreakConfig$r === void 0 ? void 0 : _sectionBreakConfig$r.wrapStrategy) === _univerjs_core.WrapStrategy.OVERFLOW;
15827
+ }
15828
+ function getGlyphGroupInkBounds(divide) {
15829
+ if (divide.glyphGroup.length === 0) return null;
15830
+ let left = Infinity;
15831
+ let right = -Infinity;
15832
+ for (const glyph of divide.glyphGroup) {
15833
+ const glyphLeft = glyph.left + glyph.xOffset;
15834
+ left = Math.min(left, glyphLeft);
15835
+ right = Math.max(right, glyphLeft + glyph.bBox.width);
15836
+ }
15837
+ if (!Number.isFinite(left) || !Number.isFinite(right)) return null;
15838
+ return {
15839
+ left,
15840
+ right
15841
+ };
15842
+ }
15843
+ function horizontalAlignHandler(line, horizontalAlign, allowOverflowHorizontalOffset = false) {
15057
15844
  const { divides } = line;
15058
15845
  for (let i = 0; i < divides.length; i++) {
15059
15846
  const divide = divides[i];
@@ -15092,9 +15879,18 @@ function horizontalAlignHandler(line, horizontalAlign) {
15092
15879
  divide.glyphGroupWidth = glyphGroupWidth;
15093
15880
  }
15094
15881
  }
15095
- if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER) divide.paddingLeft = (width - glyphGroupWidth) / 2;
15882
+ const inkBounds = allowOverflowHorizontalOffset ? getGlyphGroupInkBounds(divide) : null;
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;
15890
+ else if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT && inkBounds) divide.paddingLeft = width - inkBounds.right;
15891
+ else if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER) divide.paddingLeft = (width - glyphGroupWidth) / 2;
15096
15892
  else if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT) divide.paddingLeft = width - glyphGroupWidth;
15097
- divide.paddingLeft = Math.max(divide.paddingLeft, 0);
15893
+ if (!allowOverflowHorizontalOffset) divide.paddingLeft = Math.max(divide.paddingLeft, 0);
15098
15894
  }
15099
15895
  }
15100
15896
  function restoreLastCJKGlyphWidth(line) {
@@ -15139,7 +15935,10 @@ function addHyphenDash(line, viewModel, paragraphNode, sectionBreakConfig, parag
15139
15935
  }
15140
15936
  function lineAdjustment(pages, viewModel, paragraphNode, sectionBreakConfig) {
15141
15937
  const { endIndex } = paragraphNode;
15142
- const paragraph = viewModel.getParagraph(endIndex) || { startIndex: 0 };
15938
+ const paragraph = viewModel.getParagraph(endIndex) || {
15939
+ startIndex: 0,
15940
+ paragraphId: "para_render_fallback"
15941
+ };
15143
15942
  lineIterator(pages, (line) => {
15144
15943
  if (line.paragraphIndex !== paragraph.startIndex) return;
15145
15944
  const { paragraphStyle = {} } = paragraph;
@@ -15147,7 +15946,7 @@ function lineAdjustment(pages, viewModel, paragraphNode, sectionBreakConfig) {
15147
15946
  shrinkStartAndEndCJKPunctuation(line);
15148
15947
  restoreLastCJKGlyphWidth(line);
15149
15948
  addHyphenDash(line, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
15150
- horizontalAlignHandler(line, horizontalAlign);
15949
+ horizontalAlignHandler(line, horizontalAlign, shouldAllowOverflowHorizontalOffset(sectionBreakConfig));
15151
15950
  });
15152
15951
  }
15153
15952
 
@@ -15342,11 +16141,51 @@ function ___getLevelAndSuffix(levelAndSuffixPre) {
15342
16141
 
15343
16142
  //#endregion
15344
16143
  //#region src/components/docs/layout/block/paragraph/linebreaking.ts
15345
- const BLOCK_LAYOUT_OUTER_SPACING_MAP = new Map([
15346
- ["callout", 34],
15347
- ["code", 32],
15348
- ["quote", 24]
16144
+ const BLOCK_LAYOUT_OUTER_SPACING_MAP = /* @__PURE__ */ new Map([
16145
+ [_univerjs_core.DocumentBlockRangeType.CALLOUT, 34],
16146
+ [_univerjs_core.DocumentBlockRangeType.CODE, 32],
16147
+ [_univerjs_core.DocumentBlockRangeType.QUOTE, 24]
15349
16148
  ]);
16149
+ function _endsWithToken(text, glyphs, token) {
16150
+ var _glyphs, _glyphs2;
16151
+ return text.endsWith(token) || ((_glyphs = glyphs[glyphs.length - 1]) === null || _glyphs === void 0 ? void 0 : _glyphs.raw) === token || ((_glyphs2 = glyphs[glyphs.length - 1]) === null || _glyphs2 === void 0 ? void 0 : _glyphs2.streamType) === token;
16152
+ }
16153
+ function _isMarkedDocxColumnBreak(viewModel, absoluteIndex) {
16154
+ const customRange = viewModel.getCustomRange(absoluteIndex);
16155
+ const properties = customRange === null || customRange === void 0 ? void 0 : customRange.properties;
16156
+ return (properties === null || properties === void 0 ? void 0 : properties.docxBreakType) === "column";
16157
+ }
16158
+ function _glyphCount(glyphs) {
16159
+ return glyphs.reduce((count, glyph) => count + glyph.count, 0);
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
+ }
16169
+ function _hasOnlyCustomBlockGlyphs(glyphs) {
16170
+ return glyphs.length > 0 && glyphs.every((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK);
16171
+ }
16172
+ function _mergeAdjacentCustomBlockShapedTexts(shapedTextList) {
16173
+ const mergedShapedTextList = [];
16174
+ for (const shapedText of shapedTextList) {
16175
+ const lastShapedText = mergedShapedTextList[mergedShapedTextList.length - 1];
16176
+ if (lastShapedText && _hasOnlyCustomBlockGlyphs(lastShapedText.glyphs) && _hasOnlyCustomBlockGlyphs(shapedText.glyphs)) {
16177
+ lastShapedText.text += shapedText.text;
16178
+ lastShapedText.glyphs.push(...shapedText.glyphs);
16179
+ lastShapedText.breakPointType = shapedText.breakPointType;
16180
+ continue;
16181
+ }
16182
+ mergedShapedTextList.push({
16183
+ ...shapedText,
16184
+ glyphs: [...shapedText.glyphs]
16185
+ });
16186
+ }
16187
+ return mergedShapedTextList;
16188
+ }
15350
16189
  function _getListLevelAncestors(bullet, listLevel) {
15351
16190
  if (!bullet || !listLevel) return;
15352
16191
  const { listId, nestingLevel } = bullet;
@@ -15383,7 +16222,9 @@ function _withMinSpacing(style, key, value) {
15383
16222
  };
15384
16223
  }
15385
16224
  function _getNextAdjacentBlockRange(blockRanges, blockRange) {
15386
- 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;
15387
16228
  }
15388
16229
  function _hasNextAdjacentLayoutBlockRange(blockRanges, blockRange) {
15389
16230
  const nextBlockRange = _getNextAdjacentBlockRange(blockRanges, blockRange);
@@ -15417,12 +16258,23 @@ function _applyBlockRangeLayoutParagraphStyle(body, paragraph, paragraphStyle, s
15417
16258
  if ((lastParagraph === null || lastParagraph === void 0 ? void 0 : lastParagraph.startIndex) === paragraph.startIndex && !_hasNextAdjacentLayoutBlockRange(blockRanges, blockRange)) _withMinSpacing(style, "spaceBelow", outerSpacing);
15418
16259
  return style;
15419
16260
  }
15420
- function _shouldApplyDocumentDefaultParagraphStyle(viewModel) {
15421
- var _viewModel$getSnapsho;
15422
- const snapshot = (_viewModel$getSnapsho = viewModel.getSnapshot) === null || _viewModel$getSnapsho === void 0 ? void 0 : _viewModel$getSnapsho.call(viewModel);
15423
- const documentFlavor = snapshot === null || snapshot === void 0 ? void 0 : snapshot.documentStyle.documentFlavor;
15424
- if (snapshot == null) return true;
15425
- return documentFlavor != null && documentFlavor !== _univerjs_core.DocumentFlavor.UNSPECIFIED;
16261
+ function _isOnlyFloatingCustomBlockParagraph(viewModel, paragraphNode, drawings) {
16262
+ var _paragraphNode$blocks, _paragraphNode$conten;
16263
+ if (!((_paragraphNode$blocks = paragraphNode.blocks) === null || _paragraphNode$blocks === void 0 ? void 0 : _paragraphNode$blocks.length)) return false;
16264
+ if (!((_paragraphNode$conten = paragraphNode.content) !== null && _paragraphNode$conten !== void 0 ? _paragraphNode$conten : "").split("").every((char) => char === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK || char === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH || char === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK)) return false;
16265
+ return paragraphNode.blocks.every((charIndex) => {
16266
+ const customBlock = viewModel.getCustomBlock(charIndex);
16267
+ const drawing = customBlock == null ? null : drawings[customBlock.blockId];
16268
+ return drawing != null && drawing.layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE;
16269
+ });
16270
+ }
16271
+ function _getFollowingIndentedParagraphAnchorLeft(viewModel, paragraph, paragraphNode, drawings, isTraditionalDocument) {
16272
+ var _paragraph$paragraphS, _paragraph$paragraphS2, _viewModel$getBody$pa, _viewModel$getBody, _paragraphs$0$paragra, _paragraphs$, _paragraphs$0$paragra2;
16273
+ if (!isTraditionalDocument) return;
16274
+ if (((_paragraph$paragraphS = (_paragraph$paragraphS2 = paragraph.paragraphStyle) === null || _paragraph$paragraphS2 === void 0 || (_paragraph$paragraphS2 = _paragraph$paragraphS2.indentStart) === null || _paragraph$paragraphS2 === void 0 ? void 0 : _paragraph$paragraphS2.v) !== null && _paragraph$paragraphS !== void 0 ? _paragraph$paragraphS : 0) > 0) return;
16275
+ if (!_isOnlyFloatingCustomBlockParagraph(viewModel, paragraphNode, drawings)) return;
16276
+ const paragraphs = [...(_viewModel$getBody$pa = (_viewModel$getBody = viewModel.getBody) === null || _viewModel$getBody === void 0 || (_viewModel$getBody = _viewModel$getBody.call(viewModel)) === null || _viewModel$getBody === void 0 ? void 0 : _viewModel$getBody.paragraphs) !== null && _viewModel$getBody$pa !== void 0 ? _viewModel$getBody$pa : []].filter((item) => item.startIndex > paragraph.startIndex).sort((left, right) => left.startIndex - right.startIndex);
16277
+ return ((_paragraphs$0$paragra = (_paragraphs$ = paragraphs[0]) === null || _paragraphs$ === void 0 || (_paragraphs$ = _paragraphs$.paragraphStyle) === null || _paragraphs$ === void 0 || (_paragraphs$ = _paragraphs$.indentStart) === null || _paragraphs$ === void 0 ? void 0 : _paragraphs$.v) !== null && _paragraphs$0$paragra !== void 0 ? _paragraphs$0$paragra : 0) > 0 ? (_paragraphs$0$paragra2 = paragraphs[0].paragraphStyle) === null || _paragraphs$0$paragra2 === void 0 ? void 0 : _paragraphs$0$paragra2.indentStart : void 0;
15426
16278
  }
15427
16279
  function _getDrawingSkeletonFormat(drawingOrigin) {
15428
16280
  const { drawingId } = drawingOrigin;
@@ -15446,16 +16298,24 @@ function _getNextPageNumber(lastPage) {
15446
16298
  return lastPage.pageNumber + 1;
15447
16299
  }
15448
16300
  function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, sectionBreakConfig, tableSkeleton) {
15449
- var _viewModel$getBody, _viewModel$getBody2;
16301
+ var _sectionBreakConfig$d, _viewModel$getSnapsho, _viewModel$getBody2, _viewModel$getBody3;
15450
16302
  const { skeletonResourceReference } = ctx;
15451
16303
  const { lists, drawings = {}, localeService } = sectionBreakConfig;
15452
16304
  const { endIndex, blocks = [], children } = paragraphNode;
15453
16305
  const { segmentId } = curPage;
15454
- const paragraph = viewModel.getParagraph(endIndex) || { startIndex: 0 };
16306
+ const paragraph = viewModel.getParagraph(endIndex) || {
16307
+ startIndex: 0,
16308
+ paragraphId: "para_render_fallback"
16309
+ };
15455
16310
  const { paragraphStyle = {}, bullet } = paragraph;
16311
+ const documentCompatibilityPolicy = (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy((_viewModel$getSnapsho = viewModel.getSnapshot) === null || _viewModel$getSnapsho === void 0 || (_viewModel$getSnapsho = _viewModel$getSnapsho.call(viewModel)) === null || _viewModel$getSnapsho === void 0 ? void 0 : _viewModel$getSnapsho.documentStyle.documentFlavor);
16312
+ const shouldApplyDocumentDefaults = documentCompatibilityPolicy.applyDocumentDefaultParagraphStyle;
16313
+ const useWordStyleLineHeight = documentCompatibilityPolicy.useWordStyleLineHeight;
15456
16314
  const { skeHeaders, skeFooters, skeListLevel, drawingAnchor } = skeletonResourceReference;
15457
16315
  const paragraphNonInlineSkeDrawings = /* @__PURE__ */ new Map();
15458
16316
  const paragraphInlineSkeDrawings = /* @__PURE__ */ new Map();
16317
+ const paragraphNonInlineSkeDrawingsByBlockId = /* @__PURE__ */ new Map();
16318
+ const paragraphInlineSkeDrawingsByBlockId = /* @__PURE__ */ new Map();
15459
16319
  let segmentDrawingAnchorCache = drawingAnchor === null || drawingAnchor === void 0 ? void 0 : drawingAnchor.get(segmentId);
15460
16320
  if (segmentDrawingAnchorCache == null) {
15461
16321
  segmentDrawingAnchorCache = /* @__PURE__ */ new Map();
@@ -15463,7 +16323,10 @@ function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, se
15463
16323
  }
15464
16324
  const paragraphConfig = {
15465
16325
  paragraphIndex: endIndex,
15466
- paragraphStyle: _applyBlockRangeLayoutParagraphStyle((_viewModel$getBody = (_viewModel$getBody2 = viewModel.getBody) === null || _viewModel$getBody2 === void 0 ? void 0 : _viewModel$getBody2.call(viewModel)) !== null && _viewModel$getBody !== void 0 ? _viewModel$getBody : null, paragraph, paragraphStyle, _shouldApplyDocumentDefaultParagraphStyle(viewModel)),
16326
+ documentCompatibilityPolicy,
16327
+ paragraphStyle: _applyBlockRangeLayoutParagraphStyle((_viewModel$getBody2 = (_viewModel$getBody3 = viewModel.getBody) === null || _viewModel$getBody3 === void 0 ? void 0 : _viewModel$getBody3.call(viewModel)) !== null && _viewModel$getBody2 !== void 0 ? _viewModel$getBody2 : null, paragraph, paragraphStyle, shouldApplyDocumentDefaults),
16328
+ docxFallbackAnchorLeft: _getFollowingIndentedParagraphAnchorLeft(viewModel, paragraph, paragraphNode, drawings, isTraditionalDocumentCompatibility(documentCompatibilityPolicy)),
16329
+ useWordStyleLineHeight,
15467
16330
  paragraphNonInlineSkeDrawings,
15468
16331
  paragraphInlineSkeDrawings,
15469
16332
  skeTablesInParagraph: tableSkeleton ? [{
@@ -15496,36 +16359,65 @@ function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, se
15496
16359
  if (customBlock == null) continue;
15497
16360
  const { blockId } = customBlock;
15498
16361
  const drawingOrigin = drawings[blockId];
15499
- if (drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) paragraphInlineSkeDrawings.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
15500
- else paragraphNonInlineSkeDrawings.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
16362
+ if (drawingOrigin == null) continue;
16363
+ if (drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) paragraphInlineSkeDrawingsByBlockId.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
16364
+ else paragraphNonInlineSkeDrawingsByBlockId.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
15501
16365
  }
15502
16366
  segmentParagraphCache.set(endIndex, paragraphConfig);
15503
16367
  let allPages = [curPage];
15504
16368
  let isParagraphFirstShapedText = true;
15505
- for (const [_index, { text, glyphs, breakPointType }] of shapedTextList.entries()) {
16369
+ let shapedTextOffset = 0;
16370
+ for (const [_index, { text, glyphs, breakPointType }] of _mergeAdjacentCustomBlockShapedTexts(shapedTextList).entries()) {
16371
+ const textStartIndex = paragraphNode.startIndex + shapedTextOffset;
16372
+ const textGlyphCount = _glyphCount(glyphs);
16373
+ const textEndIndex = textStartIndex + textGlyphCount;
15506
16374
  const pushPending = () => {
15507
16375
  if (glyphs.length === 0) return;
15508
- allPages = layoutParagraph(ctx, glyphs, allPages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);
16376
+ syncActiveParagraphDrawings(glyphs, paragraphNonInlineSkeDrawings, paragraphInlineSkeDrawings, paragraphNonInlineSkeDrawingsByBlockId, paragraphInlineSkeDrawingsByBlockId);
16377
+ allPages = layoutParagraph(ctx, glyphs, allPages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText || hasOnlyFloatingCustomBlockGlyphs(glyphs, paragraphNonInlineSkeDrawingsByBlockId), breakPointType);
15509
16378
  isParagraphFirstShapedText = false;
15510
16379
  };
15511
- if (text.endsWith(_univerjs_core.DataStreamTreeTokenType.PAGE_BREAK)) {
16380
+ if (_endsWithToken(text, glyphs, _univerjs_core.DataStreamTreeTokenType.PAGE_BREAK)) {
15512
16381
  pushPending();
15513
16382
  allPages.push(createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(allPages[allPages.length - 1]), 1));
15514
16383
  paragraphNonInlineSkeDrawings.clear();
15515
- paragraphInlineSkeDrawings.clear();
16384
+ isParagraphFirstShapedText = true;
16385
+ shapedTextOffset += textGlyphCount;
15516
16386
  continue;
15517
- } else if (text.endsWith(_univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK)) {
16387
+ } else if (_endsWithToken(text, glyphs, _univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK) && (!isTraditionalDocumentCompatibility(documentCompatibilityPolicy) || _isMarkedDocxColumnBreak(viewModel, textEndIndex - 1))) {
15518
16388
  pushPending();
15519
16389
  const lastPage = allPages[allPages.length - 1];
15520
16390
  const columnInfo = getLastNotFullColumnInfo(lastPage);
15521
16391
  if (columnInfo && !columnInfo.isLast) setColumnFullState(columnInfo.column, true);
15522
- 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));
16398
+ shapedTextOffset += textGlyphCount;
15523
16399
  continue;
15524
16400
  }
15525
16401
  pushPending();
16402
+ shapedTextOffset += textGlyphCount;
15526
16403
  }
15527
16404
  return allPages;
15528
16405
  }
16406
+ function syncActiveParagraphDrawings(glyphs, paragraphNonInlineSkeDrawings, paragraphInlineSkeDrawings, paragraphNonInlineSkeDrawingsByBlockId, paragraphInlineSkeDrawingsByBlockId) {
16407
+ for (const glyph of glyphs) {
16408
+ if (glyph.streamType !== _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK || glyph.drawingId == null) continue;
16409
+ const inlineDrawing = paragraphInlineSkeDrawingsByBlockId.get(glyph.drawingId);
16410
+ if (inlineDrawing != null) {
16411
+ paragraphInlineSkeDrawings.set(glyph.drawingId, inlineDrawing);
16412
+ continue;
16413
+ }
16414
+ const nonInlineDrawing = paragraphNonInlineSkeDrawingsByBlockId.get(glyph.drawingId);
16415
+ if (nonInlineDrawing != null) paragraphNonInlineSkeDrawings.set(glyph.drawingId, nonInlineDrawing);
16416
+ }
16417
+ }
16418
+ function hasOnlyFloatingCustomBlockGlyphs(glyphs, paragraphNonInlineSkeDrawingsByBlockId) {
16419
+ return glyphs.length > 0 && glyphs.every((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.drawingId != null && paragraphNonInlineSkeDrawingsByBlockId.has(glyph.drawingId));
16420
+ }
15529
16421
 
15530
16422
  //#endregion
15531
16423
  //#region src/components/docs/layout/line-breaker/enhancers/hyphen-enhancer.ts
@@ -15849,6 +16741,26 @@ function prepareTextChunks(body) {
15849
16741
  //#region src/components/docs/layout/shaping-engine/text-shaping.ts
15850
16742
  const fontCache = /* @__PURE__ */ new Map();
15851
16743
  const glyphCache = /* @__PURE__ */ new Map();
16744
+ const fontFamilyCache = /* @__PURE__ */ new Map();
16745
+ function trimOuterQuotes(value) {
16746
+ const firstChar = value.charCodeAt(0);
16747
+ const lastChar = value.charCodeAt(value.length - 1);
16748
+ const hasLeadingQuote = firstChar === 34 || firstChar === 39;
16749
+ const hasTrailingQuote = lastChar === 34 || lastChar === 39;
16750
+ if (hasLeadingQuote && hasTrailingQuote) return value.slice(1, -1);
16751
+ if (hasLeadingQuote) return value.slice(1);
16752
+ if (hasTrailingQuote) return value.slice(0, -1);
16753
+ return value;
16754
+ }
16755
+ function expandFontFamilies(fontFamily) {
16756
+ if (!(fontFamily === null || fontFamily === void 0 ? void 0 : fontFamily.trim())) return [];
16757
+ let families = fontFamilyCache.get(fontFamily);
16758
+ if (families) return families;
16759
+ families = fontFamily.split(",").map((family) => trimOuterQuotes(family.trim())).filter(Boolean);
16760
+ fontFamilyCache.set(fontFamily, families);
16761
+ return families;
16762
+ }
16763
+ const defaultFontFamilies = expandFontFamilies(DEFAULT_FONTFACE_PLANE);
15852
16764
  function shapeChunk(content, charPosition, used, families, style) {
15853
16765
  var _style$bl, _style$it, _content$match;
15854
16766
  let fi = 0;
@@ -15951,8 +16863,7 @@ function textShape(body) {
15951
16863
  for (const chunk of chunks) {
15952
16864
  var _style$ff;
15953
16865
  const { content, style = {} } = chunk;
15954
- let fontFamilies = DEFAULT_FONTFACE_PLANE.split(",").map((family) => family.trim().replace(/["']/g, ""));
15955
- fontFamilies.unshift((_style$ff = style.ff) !== null && _style$ff !== void 0 ? _style$ff : "Arial");
16866
+ let fontFamilies = [...expandFontFamilies((_style$ff = style.ff) !== null && _style$ff !== void 0 ? _style$ff : "Arial"), ...defaultFontFamilies];
15956
16867
  fontFamilies = fontLibrary.getValidFontFamilies(fontFamilies);
15957
16868
  glyphs.push(...shapeChunk(content, charPosition, /* @__PURE__ */ new Set(), fontFamilies, style));
15958
16869
  charPosition += content.length;
@@ -15990,7 +16901,7 @@ function ArabicHandler(index, charArray, viewModel, paragraphNode, sectionBreakC
15990
16901
  for (let i = 0; i < charArray.length; i++) {
15991
16902
  const newChar = charArray[i];
15992
16903
  if (hasArabic(newChar)) {
15993
- glyph.unshift(newChar);
16904
+ glyph.push(newChar);
15994
16905
  step++;
15995
16906
  } else break;
15996
16907
  }
@@ -16087,7 +16998,10 @@ function shaping(ctx, content, viewModel, paragraphNode, sectionBreakConfig, use
16087
16998
  const shapedTextList = [];
16088
16999
  let breaker = new LineBreaker(content);
16089
17000
  const { endIndex } = paragraphNode;
16090
- const paragraph = viewModel.getParagraph(endIndex) || { startIndex: 0 };
17001
+ const paragraph = viewModel.getParagraph(endIndex) || {
17002
+ startIndex: 0,
17003
+ paragraphId: "para_render_fallback"
17004
+ };
16091
17005
  const { paragraphStyle = {} } = paragraph;
16092
17006
  const { snapToGrid = _univerjs_core.BooleanNumber.TRUE } = paragraphStyle;
16093
17007
  let last = 0;
@@ -16146,12 +17060,12 @@ function shaping(ctx, content, viewModel, paragraphNode, sectionBreakConfig, use
16146
17060
  if (customBlock != null) {
16147
17061
  const { blockId } = customBlock;
16148
17062
  const drawingOrigin = drawings[blockId];
16149
- if (drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) {
17063
+ if ((drawingOrigin === null || drawingOrigin === void 0 ? void 0 : drawingOrigin.layoutType) === _univerjs_core.PositionedObjectLayoutType.INLINE) {
16150
17064
  const { angle } = drawingOrigin.docTransform;
16151
17065
  const { width = 0, height = 0 } = drawingOrigin.docTransform.size;
16152
17066
  const boundingBox = getBoundingBox(angle, 0, width, 0, height);
16153
17067
  newGlyph = createSkeletonCustomBlockGlyph(config, boundingBox.width, boundingBox.height, drawingOrigin.drawingId);
16154
- } else newGlyph = createSkeletonCustomBlockGlyph(config, 0, 0, drawingOrigin.drawingId);
17068
+ } else if (drawingOrigin != null) newGlyph = createSkeletonCustomBlockGlyph(config, 0, 0, drawingOrigin.drawingId);
16155
17069
  }
16156
17070
  if (newGlyph == null) newGlyph = createSkeletonLetterGlyph(char, config);
16157
17071
  shapedGlyphs.push(newGlyph);
@@ -16234,6 +17148,219 @@ function dealWidthParagraph(ctx, viewModel, paragraphNode, curPage, sectionBreak
16234
17148
  return allPages;
16235
17149
  }
16236
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
+
16237
17364
  //#endregion
16238
17365
  //#region src/components/docs/layout/block/section.ts
16239
17366
  function dealWithSection(ctx, viewModel, sectionNode, curPage, sectionBreakConfig, layoutAnchor) {
@@ -16258,6 +17385,10 @@ function dealWithSection(ctx, viewModel, sectionNode, curPage, sectionBreakConfi
16258
17385
  if (ctx.paragraphsOpenNewPage.has(paragraphNode.endIndex)) currentPageCache = createSkeletonPage(ctx, sectionBreakConfig, ctx.skeletonResourceReference, currentPageCache.pageNumber + 1);
16259
17386
  skeletonPages = dealWidthParagraph(ctx, viewModel, paragraphNode, currentPageCache, sectionBreakConfig);
16260
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
+ }
16261
17392
  if (skeletonPages.length === 0) skeletonPages = dealWithBlockError();
16262
17393
  _pushPage(allCurrentSkeletonPages, skeletonPages);
16263
17394
  if (ctx.isDirty) break;
@@ -16640,11 +17771,49 @@ function removeDupPages(ctx) {
16640
17771
  return !hasPage;
16641
17772
  });
16642
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
+ }
16643
17804
  function getPagePath(page) {
16644
17805
  const path = [];
16645
17806
  let skeNode = page;
16646
17807
  let parent = skeNode.parent;
16647
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
+ }
16648
17817
  if (parent.pages) {
16649
17818
  const index = parent.pages.indexOf(skeNode);
16650
17819
  if (index !== -1) path.unshift("pages", index);
@@ -16655,11 +17824,53 @@ function getPagePath(page) {
16655
17824
  const index = parent.rows.indexOf(skeNode);
16656
17825
  if (index !== -1) path.unshift("rows", index);
16657
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);
16658
17828
  skeNode = parent;
16659
17829
  parent = parent === null || parent === void 0 ? void 0 : parent.parent;
16660
17830
  }
16661
17831
  return path;
16662
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
+ }
16663
17874
  var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
16664
17875
  constructor(_docViewModel, localeService) {
16665
17876
  super(localeService);
@@ -16959,7 +18170,7 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
16959
18170
  return this._getNearestNode(cache.nearestNodeList, cache.nearestNodeDistanceList);
16960
18171
  }
16961
18172
  _collectNearestNode(segmentPage, pageType, page, segmentId, pi, cache, x, y, pageLength, nestLevel = 0) {
16962
- const { sections, skeTables } = segmentPage;
18173
+ const { sections, skeTables, skeColumnGroups = /* @__PURE__ */ new Map() } = segmentPage;
16963
18174
  this._findLiquid.translateSave();
16964
18175
  const pageLeft = this._findLiquid.x;
16965
18176
  const pageRight = pageLeft + page.pageWidth;
@@ -17020,7 +18231,7 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17020
18231
  this._findLiquid.translateDivide(divide);
17021
18232
  const { x: startX } = this._findLiquid;
17022
18233
  for (const glyph of glyphGroup) {
17023
- if (!glyph.content || glyph.content.length === 0) continue;
18234
+ if (!isHitTestAddressableGlyph(glyph)) continue;
17024
18235
  const { width: glyphWidth, left: glyphLeft } = glyph;
17025
18236
  const startX_fin = startX + glyphLeft;
17026
18237
  const endX_fin = startX + glyphLeft + glyphWidth;
@@ -17093,9 +18304,9 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17093
18304
  const viewport = getDocsTableRenderViewport(unitId, sourceTableId);
17094
18305
  (_this$_findLiquid = this._findLiquid) === null || _this$_findLiquid === void 0 || _this$_findLiquid.translateSave();
17095
18306
  (_this$_findLiquid2 = this._findLiquid) === null || _this$_findLiquid2 === void 0 || _this$_findLiquid2.translate(tableLeft, tableTop);
17096
- if (viewport && viewport.contentWidth > viewport.viewportWidth) {
17097
- var _this$_findLiquid4;
17098
- const visibleLeft = this._findLiquid.x;
18307
+ if (hasDocsTableHorizontalViewport(viewport)) {
18308
+ var _viewport$leadingInse, _this$_findLiquid4;
18309
+ const visibleLeft = this._findLiquid.x + page.marginLeft - ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0);
17099
18310
  const visibleRight = visibleLeft + viewport.viewportWidth;
17100
18311
  if (x < visibleLeft || x > visibleRight) {
17101
18312
  var _this$_findLiquid3;
@@ -17123,6 +18334,30 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17123
18334
  (_this$_findLiquid11 = this._findLiquid) === null || _this$_findLiquid11 === void 0 || _this$_findLiquid11.translateRestore();
17124
18335
  }
17125
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
+ }
17126
18361
  if (exactMatch) {
17127
18362
  this._findLiquid.translateRestore();
17128
18363
  return exactMatch;
@@ -17191,6 +18426,7 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17191
18426
  lists,
17192
18427
  drawings,
17193
18428
  localeService: this._localeService,
18429
+ documentCompatibilityPolicy: getDocumentCompatibilityPolicy(documentStyle.documentFlavor),
17194
18430
  paragraphLineGapDefault,
17195
18431
  defaultTabStop,
17196
18432
  documentTextStyle: textStyle
@@ -17265,8 +18501,8 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17265
18501
  let curSkeletonPage = getLastPage(allSkeletonPages);
17266
18502
  let isContinuous = false;
17267
18503
  ctx.sectionBreakConfigCache.set(sectionNode.endIndex, sectionBreakConfig);
17268
- if (sectionType === _univerjs_core.SectionType.CONTINUOUS) {
17269
- updateBlockIndex(allSkeletonPages);
18504
+ if (sectionType === _univerjs_core.SectionType.CONTINUOUS && curSkeletonPage != null) {
18505
+ updateBlockIndex(allSkeletonPages, -1, ctx.docsConfig.documentCompatibilityPolicy);
17270
18506
  this._addNewSectionByContinuous(curSkeletonPage, columnProperties, columnSeparatorType);
17271
18507
  isContinuous = true;
17272
18508
  } else if (layoutAnchor == null || curSkeletonPage == null) {
@@ -17275,7 +18511,10 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17275
18511
  }
17276
18512
  const { pages } = dealWithSection(ctx, viewModel, sectionNode, curSkeletonPage, sectionBreakConfig, layoutAnchor);
17277
18513
  if (sectionTypeNext === _univerjs_core.SectionType.CONTINUOUS && columnProperties.length > 0) {}
17278
- 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
+ }
17279
18518
  allSkeletonPages.push(...pages);
17280
18519
  if (ctx.isDirty) break;
17281
18520
  }
@@ -17286,7 +18525,8 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17286
18525
  } else {
17287
18526
  this._iteratorCount = 0;
17288
18527
  removeDupPages(ctx);
17289
- updateBlockIndex(skeleton.pages);
18528
+ updateBlockIndex(skeleton.pages, -1, ctx.docsConfig.documentCompatibilityPolicy);
18529
+ mergeContinuousDuplicatePages(skeleton.pages);
17290
18530
  updateInlineDrawingCoordsAndBorder(ctx, skeleton.pages);
17291
18531
  for (const hSkeMap of skeleton.skeHeaders.values()) for (const page of hSkeMap.values()) updateInlineDrawingCoordsAndBorder(ctx, [page]);
17292
18532
  for (const fSkeMap of skeleton.skeFooters.values()) for (const page of fSkeMap.values()) updateInlineDrawingCoordsAndBorder(ctx, [page]);
@@ -17310,9 +18550,10 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17310
18550
  if (skeletonData == null) return;
17311
18551
  const { pages, skeFooters, skeHeaders } = skeletonData;
17312
18552
  for (const page of pages) {
18553
+ var _segmentPageParent$pa;
17313
18554
  const curPageIndex = pages.indexOf(page);
17314
18555
  if (segmentId && curPageIndex !== segmentPageIndex) continue;
17315
- const { pageWidth, skeTables } = page;
18556
+ const { pageWidth } = page;
17316
18557
  let segmentPage = page;
17317
18558
  if (segmentId) {
17318
18559
  var _skeHeaders$get5, _skeFooters$get5;
@@ -17322,27 +18563,22 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17322
18563
  else if (maybeFooterSke) segmentPage = maybeFooterSke;
17323
18564
  else continue;
17324
18565
  }
17325
- if (segmentId === "") {
17326
- let foundCell = false;
17327
- for (const table of skeTables.values()) {
17328
- const { rows } = table;
17329
- for (const row of rows) {
17330
- const { cells } = row;
17331
- for (const cell of cells) {
17332
- const { st, ed } = cell;
17333
- if (charIndex >= st && charIndex <= ed) {
17334
- segmentPage = cell;
17335
- foundCell = true;
17336
- break;
17337
- }
17338
- }
17339
- if (foundCell) break;
17340
- }
17341
- 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
+ };
17342
18579
  }
18580
+ continue;
17343
18581
  }
17344
- const { sections, st, ed } = segmentPage;
17345
- if (charIndex < st || charIndex > ed) continue;
17346
18582
  for (const section of sections) {
17347
18583
  const { columns, st, ed } = section;
17348
18584
  if (charIndex < st || charIndex > ed) continue;
@@ -17375,6 +18611,15 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17375
18611
  }
17376
18612
  }
17377
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
+ }
17378
18623
  }
17379
18624
  }
17380
18625
  };
@@ -17397,6 +18642,7 @@ function createDocumentModelWithStyle(content, textStyle, config = {}) {
17397
18642
  }],
17398
18643
  paragraphs: [{
17399
18644
  startIndex: contentLength,
18645
+ paragraphId: (0, _univerjs_core.createParagraphId)(/* @__PURE__ */ new Set()),
17400
18646
  paragraphStyle: { horizontalAlign }
17401
18647
  }],
17402
18648
  sectionBreaks: [{ startIndex: contentLength + 1 }]
@@ -17453,7 +18699,7 @@ function getFontFormat(format) {
17453
18699
  }
17454
18700
 
17455
18701
  //#endregion
17456
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
18702
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
17457
18703
  function __decorateParam(paramIndex, decorator) {
17458
18704
  return function(target, key) {
17459
18705
  decorator(target, key, paramIndex);
@@ -17461,7 +18707,7 @@ function __decorateParam(paramIndex, decorator) {
17461
18707
  }
17462
18708
 
17463
18709
  //#endregion
17464
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
18710
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
17465
18711
  function __decorate(decorators, target, key, desc) {
17466
18712
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17467
18713
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -18274,7 +19520,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18274
19520
  this.makeDirty(true);
18275
19521
  }
18276
19522
  _setBorderStylesCache(row, col, style, options) {
18277
- if (_univerjs_core.Tools.isDefine(this._handleBorderMatrix.getValue(row, col))) return;
19523
+ if (_univerjs_core.Tools.isDefine(this._handleBorderMatrix.getValue(row, col)) && !(options === null || options === void 0 ? void 0 : options.mergeRange)) return;
18278
19524
  if (!((options === null || options === void 0 ? void 0 : options.cacheItem) || {
18279
19525
  bg: true,
18280
19526
  border: true
@@ -19413,6 +20659,56 @@ var docExtension = class extends ComponentExtension {
19413
20659
  }
19414
20660
  };
19415
20661
 
20662
+ //#endregion
20663
+ //#region src/components/docs/extensions/background-runs.ts
20664
+ function collectBackgroundGlyphRuns(glyphGroup) {
20665
+ const runs = [];
20666
+ let activeGlyph = null;
20667
+ let activeColor = "";
20668
+ let activeLeft = 0;
20669
+ let activeRight = 0;
20670
+ const flush = () => {
20671
+ if (!activeGlyph) return;
20672
+ runs.push({
20673
+ glyph: {
20674
+ ...activeGlyph,
20675
+ width: activeRight - activeLeft
20676
+ },
20677
+ left: activeLeft,
20678
+ width: activeRight - activeLeft
20679
+ });
20680
+ activeGlyph = null;
20681
+ activeColor = "";
20682
+ activeLeft = 0;
20683
+ activeRight = 0;
20684
+ };
20685
+ for (const glyph of glyphGroup) {
20686
+ var _glyph$ts;
20687
+ if (!glyph.content || glyph.content === "\r") {
20688
+ flush();
20689
+ continue;
20690
+ }
20691
+ const backgroundColor = ((_glyph$ts = glyph.ts) === null || _glyph$ts === void 0 ? void 0 : _glyph$ts.bg) ? (0, _univerjs_core.getColorStyle)(glyph.ts.bg) : "";
20692
+ if (!backgroundColor) {
20693
+ flush();
20694
+ continue;
20695
+ }
20696
+ const glyphLeft = glyph.left;
20697
+ const glyphRight = glyph.left + glyph.width;
20698
+ if (activeGlyph && activeColor === backgroundColor) {
20699
+ activeRight = Math.max(activeRight, glyphRight);
20700
+ continue;
20701
+ }
20702
+ flush();
20703
+ activeGlyph = glyph;
20704
+ activeColor = backgroundColor;
20705
+ activeLeft = glyphLeft;
20706
+ activeRight = glyphRight;
20707
+ }
20708
+ flush();
20709
+ return runs;
20710
+ }
20711
+
19416
20712
  //#endregion
19417
20713
  //#region src/components/docs/extensions/background.ts
19418
20714
  const UNIQUE_KEY$3 = "DefaultDocsBackgroundExtension";
@@ -19828,7 +21124,6 @@ var Image$1 = class extends Shape {
19828
21124
  this.makeDirty(true);
19829
21125
  } else if (config.url) {
19830
21126
  this._native = document.createElement("img");
19831
- this._native.src = config.url;
19832
21127
  this._native.crossOrigin = "anonymous";
19833
21128
  this._native.onload = () => {
19834
21129
  var _config$success, _this$getEngine;
@@ -19843,6 +21138,7 @@ var Image$1 = class extends Shape {
19843
21138
  this.makeDirty(true);
19844
21139
  }
19845
21140
  };
21141
+ this._native.src = config.url;
19846
21142
  }
19847
21143
  this._init();
19848
21144
  }
@@ -19856,10 +21152,17 @@ var Image$1 = class extends Shape {
19856
21152
  var _this$_props$opacity;
19857
21153
  return (_this$_props$opacity = this._props.opacity) !== null && _this$_props$opacity !== void 0 ? _this$_props$opacity : 1;
19858
21154
  }
21155
+ get clipBounds() {
21156
+ return this._props.clipBounds;
21157
+ }
19859
21158
  setOpacity(opacity) {
19860
21159
  this._props.opacity = opacity;
19861
21160
  this.makeDirty(true);
19862
21161
  }
21162
+ setClipBounds(clipBounds) {
21163
+ this._props.clipBounds = clipBounds;
21164
+ this.makeDirty(true);
21165
+ }
19863
21166
  setClipService(clipService) {
19864
21167
  this._clipService = clipService;
19865
21168
  }
@@ -19876,10 +21179,10 @@ var Image$1 = class extends Shape {
19876
21179
  }
19877
21180
  changeSource(url) {
19878
21181
  if (this._native == null) this._native = document.createElement("img");
19879
- this._native.src = url;
19880
21182
  this._native.onload = () => {
19881
21183
  this.makeDirty(true);
19882
21184
  };
21185
+ this._native.src = url;
19883
21186
  }
19884
21187
  resetSize() {
19885
21188
  if (this._native == null) return;
@@ -19985,6 +21288,12 @@ var Image$1 = class extends Shape {
19985
21288
  }
19986
21289
  const m = this.transform.getMatrix();
19987
21290
  mainCtx.save();
21291
+ const { clipBounds } = this;
21292
+ if (clipBounds) {
21293
+ mainCtx.beginPath();
21294
+ mainCtx.rect(clipBounds.left, clipBounds.top, clipBounds.width, clipBounds.height);
21295
+ mainCtx.clip();
21296
+ }
19988
21297
  const centerX = realLeft + realWidth / 2;
19989
21298
  const centerY = realTop + realHeight / 2;
19990
21299
  mainCtx.transform(m[0], m[1], m[2], m[3], centerX, centerY);
@@ -21625,6 +22934,7 @@ var FontAndBaseLine = class extends docExtension {
21625
22934
  "actualFontMap",
21626
22935
  {}
21627
22936
  );
22937
+ _defineProperty(this, "_textFillImageCache", /* @__PURE__ */ new Map());
21628
22938
  }
21629
22939
  draw(ctx, _parentScale, glyph, _, _more) {
21630
22940
  var _glyph$parent;
@@ -21643,13 +22953,162 @@ var FontAndBaseLine = class extends docExtension {
21643
22953
  this.actualFontMap[fontStringPxStr] = ctx.font;
21644
22954
  }
21645
22955
  }
21646
- const { cl: colorStyle, va: baselineOffset } = textStyle;
22956
+ const { cl: colorStyle, va: baselineOffset, textFill } = textStyle;
21647
22957
  const fontColor = (0, _univerjs_core.getColorStyle)(colorStyle) || "rgb(0,0,0)";
21648
- if (fontColor && this._preFontColor !== fontColor) ctx.fillStyle = fontColor;
21649
22958
  if (baselineOffset === _univerjs_core.BaselineOffset.SUPERSCRIPT) spanPointWithFont.y += -bBox.spo;
21650
22959
  else if (baselineOffset === _univerjs_core.BaselineOffset.SUBSCRIPT) spanPointWithFont.y += bBox.sbo;
22960
+ if (this._fillTextWithTextFill(ctx, glyph, spanPointWithFont, textFill, fontColor)) return;
22961
+ if (fontColor && this._preFontColor !== fontColor) ctx.fillStyle = fontColor;
21651
22962
  this._fillText(ctx, glyph, spanPointWithFont);
21652
22963
  }
22964
+ _fillTextWithTextFill(ctx, glyph, spanPointWithFont, textFill, fallbackColor) {
22965
+ if (!textFill || textFill.type === "none") return (textFill === null || textFill === void 0 ? void 0 : textFill.type) === "none";
22966
+ const { content, glyphType } = glyph;
22967
+ if (content == null || glyphType === 2) return false;
22968
+ const { renderConfig } = this.extensionOffset;
22969
+ const { vertexAngle, centerAngle } = renderConfig !== null && renderConfig !== void 0 ? renderConfig : {};
22970
+ const VERTICAL_DEG = 90;
22971
+ if (vertexAngle === VERTICAL_DEG && centerAngle === VERTICAL_DEG) return false;
22972
+ const bounds = this._getGlyphPaintBounds(glyph, spanPointWithFont);
22973
+ if (bounds.width <= 0 || bounds.height <= 0) return false;
22974
+ const color = this._colorWithOpacity(textFill.color || fallbackColor, textFill.opacity);
22975
+ if (textFill.type === "solid") {
22976
+ ctx.fillStyle = color;
22977
+ this._fillText(ctx, glyph, spanPointWithFont);
22978
+ return true;
22979
+ }
22980
+ if (textFill.type === "gradient") {
22981
+ const gradient = this._createTextGradient(ctx, bounds, textFill, fallbackColor);
22982
+ if (!gradient) return false;
22983
+ ctx.fillStyle = gradient;
22984
+ this._fillText(ctx, glyph, spanPointWithFont);
22985
+ return true;
22986
+ }
22987
+ if (textFill.type === "picture") {
22988
+ const pattern = this._createTextPicturePattern(ctx, bounds, textFill);
22989
+ if (!pattern) return false;
22990
+ ctx.fillStyle = pattern;
22991
+ this._fillText(ctx, glyph, spanPointWithFont);
22992
+ return true;
22993
+ }
22994
+ return false;
22995
+ }
22996
+ _getGlyphPaintBounds(glyph, spanPointWithFont) {
22997
+ const { width, bBox } = glyph;
22998
+ const textWidth = Math.max(width, bBox.width, 1);
22999
+ const textHeight = Math.max(bBox.aba + bBox.abd, 1);
23000
+ return {
23001
+ left: spanPointWithFont.x,
23002
+ top: spanPointWithFont.y - bBox.aba,
23003
+ width: textWidth,
23004
+ height: textHeight
23005
+ };
23006
+ }
23007
+ _createTextGradient(ctx, bounds, textFill, fallbackColor) {
23008
+ var _gradient$type, _gradient$angle, _context;
23009
+ const gradient = textFill.gradient;
23010
+ const type = (_gradient$type = gradient === null || gradient === void 0 ? void 0 : gradient.type) !== null && _gradient$type !== void 0 ? _gradient$type : "linear";
23011
+ const angle = (_gradient$angle = gradient === null || gradient === void 0 ? void 0 : gradient.angle) !== null && _gradient$angle !== void 0 ? _gradient$angle : 0;
23012
+ const stops = this._normalizeGradientStops(gradient === null || gradient === void 0 ? void 0 : gradient.stops, textFill.color || fallbackColor);
23013
+ const centerX = bounds.left + bounds.width / 2;
23014
+ const centerY = bounds.top + bounds.height / 2;
23015
+ let canvasGradient;
23016
+ if (type === "radial") {
23017
+ const radius = Math.max(bounds.width, bounds.height) / 2;
23018
+ canvasGradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, radius);
23019
+ } else if (type === "angular" && "createConicGradient" in ((_context = ctx._context) !== null && _context !== void 0 ? _context : ctx)) {
23020
+ var _context2;
23021
+ canvasGradient = ((_context2 = ctx._context) !== null && _context2 !== void 0 ? _context2 : ctx).createConicGradient((angle - 90) * Math.PI / 180, centerX, centerY);
23022
+ } else if (type === "diamond") {
23023
+ const radius = Math.max(bounds.width, bounds.height) / 2;
23024
+ canvasGradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, radius);
23025
+ } else {
23026
+ const line = this._getLinearGradientLine(bounds, angle);
23027
+ canvasGradient = ctx.createLinearGradient(line.x0, line.y0, line.x1, line.y1);
23028
+ }
23029
+ for (const stop of stops) {
23030
+ var _textFill$opacity, _stop$opacity;
23031
+ const opacity = ((_textFill$opacity = textFill.opacity) !== null && _textFill$opacity !== void 0 ? _textFill$opacity : 1) * ((_stop$opacity = stop.opacity) !== null && _stop$opacity !== void 0 ? _stop$opacity : 1);
23032
+ canvasGradient.addColorStop(stop.offset, this._colorWithOpacity(stop.color, opacity));
23033
+ }
23034
+ return canvasGradient;
23035
+ }
23036
+ _createTextPicturePattern(ctx, bounds, textFill) {
23037
+ var _textFill$picture, _ref, _textFill$picture$opa, _textFill$picture2, _textFill$picture3, _pattern$setTransform;
23038
+ const source = (_textFill$picture = textFill.picture) === null || _textFill$picture === void 0 ? void 0 : _textFill$picture.source;
23039
+ if (!source) return null;
23040
+ const image = this._getTextFillImage(source);
23041
+ if (!image || !image.complete || !(image.naturalWidth || image.width)) return null;
23042
+ const canvas = document.createElement("canvas");
23043
+ canvas.width = Math.max(1, Math.ceil(bounds.width));
23044
+ canvas.height = Math.max(1, Math.ceil(bounds.height));
23045
+ const canvasContext = canvas.getContext("2d");
23046
+ if (!canvasContext) return null;
23047
+ canvasContext.globalAlpha = this._clamp((_ref = (_textFill$picture$opa = (_textFill$picture2 = textFill.picture) === null || _textFill$picture2 === void 0 ? void 0 : _textFill$picture2.opacity) !== null && _textFill$picture$opa !== void 0 ? _textFill$picture$opa : textFill.opacity) !== null && _ref !== void 0 ? _ref : 1, 0, 1);
23048
+ if (((_textFill$picture3 = textFill.picture) === null || _textFill$picture3 === void 0 ? void 0 : _textFill$picture3.mode) === "tile") {
23049
+ var _textFill$picture$sca, _textFill$picture$sca2, _textFill$picture$off, _textFill$picture$off2;
23050
+ const scaleX = (_textFill$picture$sca = textFill.picture.scaleX) !== null && _textFill$picture$sca !== void 0 ? _textFill$picture$sca : 1;
23051
+ const scaleY = (_textFill$picture$sca2 = textFill.picture.scaleY) !== null && _textFill$picture$sca2 !== void 0 ? _textFill$picture$sca2 : 1;
23052
+ const cellWidth = Math.max(1, (image.naturalWidth || image.width) * scaleX);
23053
+ const cellHeight = Math.max(1, (image.naturalHeight || image.height) * scaleY);
23054
+ const offsetX = (_textFill$picture$off = textFill.picture.offsetX) !== null && _textFill$picture$off !== void 0 ? _textFill$picture$off : 0;
23055
+ const offsetY = (_textFill$picture$off2 = textFill.picture.offsetY) !== null && _textFill$picture$off2 !== void 0 ? _textFill$picture$off2 : 0;
23056
+ for (let x = (offsetX % cellWidth + cellWidth) % cellWidth - cellWidth; x < canvas.width; x += cellWidth) for (let y = (offsetY % cellHeight + cellHeight) % cellHeight - cellHeight; y < canvas.height; y += cellHeight) canvasContext.drawImage(image, x, y, cellWidth, cellHeight);
23057
+ } else canvasContext.drawImage(image, 0, 0, canvas.width, canvas.height);
23058
+ const pattern = ctx.createPattern(canvas, "no-repeat");
23059
+ pattern === null || pattern === void 0 || (_pattern$setTransform = pattern.setTransform) === null || _pattern$setTransform === void 0 || _pattern$setTransform.call(pattern, new DOMMatrix().translate(bounds.left, bounds.top));
23060
+ return pattern;
23061
+ }
23062
+ _getTextFillImage(source) {
23063
+ const cached = this._textFillImageCache.get(source);
23064
+ if (cached) return cached;
23065
+ const image = new Image();
23066
+ image.crossOrigin = "anonymous";
23067
+ image.src = source;
23068
+ this._textFillImageCache.set(source, image);
23069
+ return image.complete ? image : null;
23070
+ }
23071
+ _normalizeGradientStops(stops, fallbackColor) {
23072
+ return (stops && stops.length >= 2 ? stops : [{
23073
+ offset: 0,
23074
+ color: fallbackColor
23075
+ }, {
23076
+ offset: 100,
23077
+ color: "#ffffff"
23078
+ }]).map((stop) => ({
23079
+ color: stop.color,
23080
+ offset: this._clamp(stop.offset > 1 ? stop.offset / 100 : stop.offset, 0, 1),
23081
+ opacity: stop.opacity
23082
+ }));
23083
+ }
23084
+ _getLinearGradientLine(bounds, angle) {
23085
+ const angleRad = angle * Math.PI / 180;
23086
+ const centerX = bounds.left + bounds.width / 2;
23087
+ const centerY = bounds.top + bounds.height / 2;
23088
+ const cos = Math.cos(angleRad);
23089
+ const sin = Math.sin(angleRad);
23090
+ const halfDiagonal = (Math.abs(bounds.width * cos) + Math.abs(bounds.height * sin)) / 2;
23091
+ return {
23092
+ x0: centerX - cos * halfDiagonal,
23093
+ y0: centerY - sin * halfDiagonal,
23094
+ x1: centerX + cos * halfDiagonal,
23095
+ y1: centerY + sin * halfDiagonal
23096
+ };
23097
+ }
23098
+ _colorWithOpacity(color, opacity) {
23099
+ if (opacity === void 0 || opacity >= 1) return color;
23100
+ const alpha = this._clamp(opacity, 0, 1);
23101
+ const hex = color.trim();
23102
+ if (/^#[0-9a-f]{3}$/i.test(hex)) {
23103
+ const [, r, g, b] = hex;
23104
+ return `rgba(${Number.parseInt(r + r, 16)}, ${Number.parseInt(g + g, 16)}, ${Number.parseInt(b + b, 16)}, ${alpha})`;
23105
+ }
23106
+ if (/^#[0-9a-f]{6}$/i.test(hex)) return `rgba(${Number.parseInt(hex.slice(1, 3), 16)}, ${Number.parseInt(hex.slice(3, 5), 16)}, ${Number.parseInt(hex.slice(5, 7), 16)}, ${alpha})`;
23107
+ return color;
23108
+ }
23109
+ _clamp(value, min, max) {
23110
+ return Math.max(min, Math.min(max, value));
23111
+ }
21653
23112
  _fillText(ctx, glyph, spanPointWithFont) {
21654
23113
  const { renderConfig, spanStartPoint, centerPoint } = this.extensionOffset;
21655
23114
  const { content, width, bBox } = glyph;
@@ -21933,7 +23392,7 @@ var Documents = class Documents extends DocComponent {
21933
23392
  for (let i = 0, len = pages.length; i < len; i++) {
21934
23393
  var _skeHeaders$get, _headerSkeletonPage$m, _skeFooters$get;
21935
23394
  const page = pages[i];
21936
- 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;
21937
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;
21938
23397
  const isVertical = vertexAngleDeg === 90 && centerAngleDeg === 90;
21939
23398
  const horizontalOffsetNoAngle = this._horizontalHandler(actualWidth, pagePaddingLeft, pagePaddingRight, horizontalAlign, vertexAngleDeg, centerAngleDeg, cellValueType);
@@ -21997,24 +23456,14 @@ var Documents = class Documents extends DocComponent {
21997
23456
  this._drawLiquid.translateSave();
21998
23457
  this._drawLiquid.translateLine(line, true, true);
21999
23458
  rotateTranslateXListApply && this._drawLiquid.translate(rotateTranslateXListApply[i]);
23459
+ this._drawLineBackground(ctx, page, line);
22000
23460
  const divideLength = divides.length;
22001
23461
  for (let i = 0; i < divideLength; i++) {
22002
23462
  const divide = divides[i];
22003
23463
  const { glyphGroup } = divide;
22004
23464
  this._drawLiquid.translateSave();
22005
23465
  this._drawLiquid.translateDivide(divide, isVertical && wrapStrategy === _univerjs_core.WrapStrategy.WRAP, verticalAlign, rotatedHeightStore);
22006
- for (const glyph of glyphGroup) {
22007
- if (!glyph.content || glyph.content.length === 0) continue;
22008
- const { width: spanWidth, left: spanLeft } = glyph;
22009
- const { x: translateX, y: translateY } = this._drawLiquid;
22010
- const originTranslate = Vector2.create(translateX, translateY);
22011
- const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
22012
- const extensionOffset = { spanStartPoint: calculateRectRotate(originTranslate.addByPoint(spanLeft, 0), centerPoint, centerAngle, vertexAngle, alignOffset) };
22013
- if (backgroundExtension) {
22014
- backgroundExtension.extensionOffset = extensionOffset;
22015
- backgroundExtension.draw(ctx, parentScale, glyph);
22016
- }
22017
- }
23466
+ this._drawGlyphGroupBackgrounds(ctx, parentScale, glyphGroup, lineHeight, alignOffset, centerAngle, vertexAngle, backgroundExtension);
22018
23467
  for (const glyph of glyphGroup) {
22019
23468
  if (!glyph.content || glyph.content.length === 0) continue;
22020
23469
  const { width: spanWidth, left: spanLeft, xOffset } = glyph;
@@ -22043,6 +23492,7 @@ var Documents = class Documents extends DocComponent {
22043
23492
  this._drawLiquid.translateRestore();
22044
23493
  }
22045
23494
  }
23495
+ if (skeColumnGroups.size > 0) this._drawColumnGroups(ctx, page, skeColumnGroups, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale);
22046
23496
  this._resetRotation(ctx, finalAngle);
22047
23497
  const footerSkeletonPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
22048
23498
  if (footerSkeletonPage) {
@@ -22070,15 +23520,18 @@ var Documents = class Documents extends DocComponent {
22070
23520
  const viewport = this._getTableViewport(page, tableSkeleton, renderUnitId, sourceTableId);
22071
23521
  drawLiquid.translateSave();
22072
23522
  drawLiquid.translate(tableLeft, tableTop);
22073
- if (viewport && viewport.contentWidth > viewport.viewportWidth) {
23523
+ if (hasDocsTableHorizontalViewport(viewport)) {
23524
+ var _viewport$leadingInse;
22074
23525
  const { x, y } = drawLiquid;
23526
+ const clipLeft = x + page.marginLeft - ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0);
22075
23527
  ctx.save();
22076
23528
  ctx.beginPath();
22077
- ctx.rectByPrecision(x + page.marginLeft - TABLE_VIEWPORT_BORDER_CLIP_PADDING, y + page.marginTop - TABLE_VIEWPORT_BORDER_CLIP_PADDING, viewport.viewportWidth + TABLE_VIEWPORT_BORDER_CLIP_PADDING * 2, tableSkeleton.height + TABLE_VIEWPORT_BORDER_CLIP_PADDING * 2);
23529
+ ctx.rectByPrecision(clipLeft - TABLE_VIEWPORT_BORDER_CLIP_PADDING, y + page.marginTop - TABLE_VIEWPORT_BORDER_CLIP_PADDING, viewport.viewportWidth + TABLE_VIEWPORT_BORDER_CLIP_PADDING * 2, tableSkeleton.height + TABLE_VIEWPORT_BORDER_CLIP_PADDING * 2);
22078
23530
  ctx.closePath();
22079
23531
  ctx.clip();
22080
23532
  drawLiquid.translate(-viewport.scrollLeft, 0);
22081
23533
  }
23534
+ this._drawTableCellBackgrounds(ctx, page, tableSkeleton);
22082
23535
  for (const row of rows) {
22083
23536
  const { top: rowTop, cells } = row;
22084
23537
  drawLiquid.translateSave();
@@ -22093,16 +23546,64 @@ var Documents = class Documents extends DocComponent {
22093
23546
  }
22094
23547
  drawLiquid.translateRestore();
22095
23548
  }
22096
- if (viewport && viewport.contentWidth > viewport.viewportWidth) ctx.restore();
23549
+ if (hasDocsTableHorizontalViewport(viewport)) ctx.restore();
22097
23550
  drawLiquid.translateRestore();
22098
23551
  }
22099
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
+ }
23568
+ _drawTableCellBackgrounds(ctx, page, tableSkeleton) {
23569
+ if (this._drawLiquid == null) return;
23570
+ const backgrounds = /* @__PURE__ */ new Map();
23571
+ const tableX = this._drawLiquid.x + page.marginLeft;
23572
+ const tableY = this._drawLiquid.y + page.marginTop;
23573
+ for (const row of tableSkeleton.rows) row.cells.forEach((cell, index) => {
23574
+ var _cellSource$backgroun, _backgrounds$get;
23575
+ if (cell.isMergedCellCovered) return;
23576
+ const cellSource = row.rowSource.tableCells[index];
23577
+ if (!cellSource || cellSource.rowSpan === 0 || cellSource.columnSpan === 0) return;
23578
+ const color = (_cellSource$backgroun = cellSource.backgroundColor) === null || _cellSource$backgroun === void 0 ? void 0 : _cellSource$backgroun.rgb;
23579
+ if (!color) return;
23580
+ const rects = (_backgrounds$get = backgrounds.get(color)) !== null && _backgrounds$get !== void 0 ? _backgrounds$get : [];
23581
+ rects.push({
23582
+ x: tableX + cell.left,
23583
+ y: tableY + row.top,
23584
+ width: cell.pageWidth,
23585
+ height: cell.pageHeight
23586
+ });
23587
+ backgrounds.set(color, rects);
23588
+ });
23589
+ backgrounds.forEach((rects, color) => {
23590
+ ctx.save();
23591
+ ctx.fillStyle = color;
23592
+ ctx.beginPath();
23593
+ rects.forEach(({ x, y, width, height }) => {
23594
+ rectByPrecisionBounds(ctx, x, y, width, height);
23595
+ });
23596
+ ctx.fill();
23597
+ ctx.closePath();
23598
+ ctx.restore();
23599
+ });
23600
+ }
22100
23601
  _getTableViewport(page, tableSkeleton, unitId, tableId) {
22101
23602
  const viewport = getDocsTableRenderViewport(unitId, tableId);
22102
23603
  if (viewport) return viewport;
22103
23604
  const { pageWidth, marginLeft = 0, marginRight = 0 } = page;
22104
23605
  if (!Number.isFinite(pageWidth)) return null;
22105
- const viewportWidth = Math.max(0, pageWidth - marginLeft - marginRight - tableSkeleton.left);
23606
+ const viewportWidth = shouldAllowImportedTableMarginOverflow(this._getDocumentCompatibilityPolicy(), tableSkeleton.tableSource) ? Math.max(0, pageWidth - Math.max(0, marginLeft + tableSkeleton.left)) : Math.max(0, pageWidth - marginLeft - marginRight - tableSkeleton.left);
22106
23607
  if (viewportWidth <= 0 || tableSkeleton.width <= viewportWidth) return null;
22107
23608
  return {
22108
23609
  contentWidth: tableSkeleton.width,
@@ -22117,6 +23618,26 @@ var Documents = class Documents extends DocComponent {
22117
23618
  const dataModel = viewModel === null || viewModel === void 0 || (_viewModel$getDataMod = viewModel.getDataModel) === null || _viewModel$getDataMod === void 0 ? void 0 : _viewModel$getDataMod.call(viewModel);
22118
23619
  return (_dataModel$getUnitId = dataModel === null || dataModel === void 0 || (_dataModel$getUnitId2 = dataModel.getUnitId) === null || _dataModel$getUnitId2 === void 0 ? void 0 : _dataModel$getUnitId2.call(dataModel)) !== null && _dataModel$getUnitId !== void 0 ? _dataModel$getUnitId : this.oKey;
22119
23620
  }
23621
+ _getDocumentCompatibilityPolicy() {
23622
+ var _skeleton$getViewMode2, _skeleton$getViewMode3;
23623
+ const skeleton = this.getSkeleton();
23624
+ return getDocumentCompatibilityPolicy(skeleton === null || skeleton === void 0 || (_skeleton$getViewMode2 = skeleton.getViewModel) === null || _skeleton$getViewMode2 === void 0 || (_skeleton$getViewMode2 = _skeleton$getViewMode2.call(skeleton)) === null || _skeleton$getViewMode2 === void 0 || (_skeleton$getViewMode3 = _skeleton$getViewMode2.getSnapshot) === null || _skeleton$getViewMode3 === void 0 || (_skeleton$getViewMode3 = _skeleton$getViewMode3.call(_skeleton$getViewMode2)) === null || _skeleton$getViewMode3 === void 0 || (_skeleton$getViewMode3 = _skeleton$getViewMode3.documentStyle) === null || _skeleton$getViewMode3 === void 0 ? void 0 : _skeleton$getViewMode3.documentFlavor);
23625
+ }
23626
+ _drawLineBackground(ctx, page, line, left = 0, top = 0) {
23627
+ var _line$backgroundColor;
23628
+ const color = (_line$backgroundColor = line.backgroundColor) === null || _line$backgroundColor === void 0 ? void 0 : _line$backgroundColor.rgb;
23629
+ if (!color || this._drawLiquid == null) return;
23630
+ let { x, y } = this._drawLiquid;
23631
+ const { pageWidth, marginLeft, marginRight, marginTop } = page;
23632
+ x += marginLeft + (left !== null && left !== void 0 ? left : 0);
23633
+ y -= line.marginTop;
23634
+ y -= line.paddingTop;
23635
+ y += marginTop + top;
23636
+ ctx.save();
23637
+ ctx.fillStyle = color;
23638
+ fillRectByPrecisionBounds(ctx, x, y, pageWidth - marginLeft - marginRight, line.lineHeight);
23639
+ ctx.restore();
23640
+ }
22120
23641
  _drawBorderBottom(ctx, page, line, left = 0, top = 0) {
22121
23642
  var _line$borderBottom$pa, _line$borderBottom, _line$borderBottom$co, _line$borderBottom2;
22122
23643
  if (this._drawLiquid == null) return;
@@ -22137,18 +23658,48 @@ var Documents = class Documents extends DocComponent {
22137
23658
  });
22138
23659
  ctx.restore();
22139
23660
  }
23661
+ _drawGlyphGroupBackgrounds(ctx, parentScale, glyphGroup, lineHeight, alignOffset, centerAngle, vertexAngle, backgroundExtension) {
23662
+ if (!backgroundExtension || this._drawLiquid == null) return;
23663
+ const backgroundRuns = collectBackgroundGlyphRuns(glyphGroup);
23664
+ for (const backgroundRun of backgroundRuns) {
23665
+ const { glyph, left: spanLeft, width: spanWidth } = backgroundRun;
23666
+ const { x: translateX, y: translateY } = this._drawLiquid;
23667
+ const originTranslate = Vector2.create(translateX, translateY);
23668
+ const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
23669
+ backgroundExtension.extensionOffset = { spanStartPoint: calculateRectRotate(originTranslate.addByPoint(spanLeft, 0), centerPoint, centerAngle, vertexAngle, alignOffset) };
23670
+ backgroundExtension.draw(ctx, parentScale, glyph);
23671
+ }
23672
+ }
22140
23673
  _drawTableCell(ctx, page, cell, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale) {
22141
23674
  if (this._drawLiquid == null) return;
22142
- this._drawTableCellBordersAndBg(ctx, page, cell);
22143
- const { sections, marginLeft, marginTop } = cell;
22144
- alignOffsetNoAngle = Vector2.create(alignOffsetNoAngle.x + marginLeft, alignOffsetNoAngle.y + marginTop);
23675
+ this._drawTableCellBordersAndBg(ctx, page, cell, false);
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);
22145
23682
  ctx.save();
22146
23683
  const { x, y } = this._drawLiquid;
22147
- const { pageWidth, pageHeight } = cell;
23684
+ const { pageWidth, pageHeight } = nestedPage;
23685
+ const clipOrigin = getNestedPageClipOrigin(parentPage, nestedPage, {
23686
+ x,
23687
+ y
23688
+ }, alignOffset);
22148
23689
  ctx.beginPath();
22149
- ctx.rectByPrecision(x + page.marginLeft, y + page.marginTop, pageWidth, pageHeight);
23690
+ ctx.rectByPrecision(clipOrigin.x, clipOrigin.y, pageWidth, pageHeight);
22150
23691
  ctx.closePath();
22151
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);
22152
23703
  for (const section of sections) {
22153
23704
  const { columns } = section;
22154
23705
  this._drawLiquid.translateSave();
@@ -22158,7 +23709,6 @@ var Documents = class Documents extends DocComponent {
22158
23709
  this._drawLiquid.translateSave();
22159
23710
  this._drawLiquid.translateColumn(column);
22160
23711
  const linesCount = lines.length;
22161
- const alignOffset = alignOffsetNoAngle;
22162
23712
  for (let i = 0; i < linesCount; i++) {
22163
23713
  const line = lines[i];
22164
23714
  const { divides, asc = 0, type, lineHeight = 0 } = line;
@@ -22176,24 +23726,14 @@ var Documents = class Documents extends DocComponent {
22176
23726
  } else {
22177
23727
  this._drawLiquid.translateSave();
22178
23728
  this._drawLiquid.translateLine(line, true, true);
23729
+ this._drawLineBackground(ctx, nestedPage, line);
22179
23730
  const divideLength = divides.length;
22180
23731
  for (let i = 0; i < divideLength; i++) {
22181
23732
  const divide = divides[i];
22182
23733
  const { glyphGroup } = divide;
22183
23734
  this._drawLiquid.translateSave();
22184
23735
  this._drawLiquid.translateDivide(divide);
22185
- for (const glyph of glyphGroup) {
22186
- if (!glyph.content || glyph.content.length === 0) continue;
22187
- const { width: spanWidth, left: spanLeft } = glyph;
22188
- const { x: translateX, y: translateY } = this._drawLiquid;
22189
- const originTranslate = Vector2.create(translateX, translateY);
22190
- const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
22191
- const extensionOffset = { spanStartPoint: calculateRectRotate(originTranslate.addByPoint(spanLeft, 0), centerPoint, centerAngle, vertexAngle, alignOffset) };
22192
- if (backgroundExtension) {
22193
- backgroundExtension.extensionOffset = extensionOffset;
22194
- backgroundExtension.draw(ctx, parentScale, glyph);
22195
- }
22196
- }
23736
+ this._drawGlyphGroupBackgrounds(ctx, parentScale, glyphGroup, lineHeight, alignOffset, centerAngle, vertexAngle, backgroundExtension);
22197
23737
  for (const glyph of glyphGroup) {
22198
23738
  if (!glyph.content || glyph.content.length === 0) continue;
22199
23739
  const { width: spanWidth, left: spanLeft, xOffset } = glyph;
@@ -22215,7 +23755,7 @@ var Documents = class Documents extends DocComponent {
22215
23755
  }
22216
23756
  this._drawLiquid.translateRestore();
22217
23757
  }
22218
- 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);
22219
23759
  this._drawLiquid.translateRestore();
22220
23760
  }
22221
23761
  }
@@ -22225,8 +23765,8 @@ var Documents = class Documents extends DocComponent {
22225
23765
  }
22226
23766
  ctx.restore();
22227
23767
  }
22228
- _drawTableCellBordersAndBg(ctx, page, cell) {
22229
- var _rowSke$index, _cellSource$backgroun;
23768
+ _drawTableCellBordersAndBg(ctx, page, cell, drawBackground = true) {
23769
+ var _rowSke$index, _cellSource$backgroun2;
22230
23770
  const { marginLeft, marginTop } = page;
22231
23771
  const { pageWidth, pageHeight } = cell;
22232
23772
  const rowSke = cell.parent;
@@ -22241,10 +23781,10 @@ var Documents = class Documents extends DocComponent {
22241
23781
  let { x, y } = this._drawLiquid;
22242
23782
  x += marginLeft;
22243
23783
  y += marginTop;
22244
- if ((_cellSource$backgroun = cellSource.backgroundColor) === null || _cellSource$backgroun === void 0 ? void 0 : _cellSource$backgroun.rgb) {
23784
+ if (drawBackground && ((_cellSource$backgroun2 = cellSource.backgroundColor) === null || _cellSource$backgroun2 === void 0 ? void 0 : _cellSource$backgroun2.rgb)) {
22245
23785
  ctx.save();
22246
23786
  ctx.fillStyle = cellSource.backgroundColor.rgb;
22247
- ctx.fillRectByPrecision(x, y, pageWidth, pageHeight);
23787
+ fillRectByPrecisionBounds(ctx, x, y, pageWidth, pageHeight);
22248
23788
  ctx.restore();
22249
23789
  }
22250
23790
  const position = {
@@ -22292,8 +23832,9 @@ var Documents = class Documents extends DocComponent {
22292
23832
  }
22293
23833
  _drawHeaderFooter(page, ctx, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale, parentPage, isHeader = true) {
22294
23834
  if (this._drawLiquid == null) return;
22295
- const { sections } = page;
23835
+ const { sections, skeTables } = page;
22296
23836
  const { y: originY } = this._drawLiquid;
23837
+ if (skeTables.size > 0) this._drawTable(ctx, page, skeTables, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale);
22297
23838
  for (const section of sections) {
22298
23839
  const { columns } = section;
22299
23840
  this._drawLiquid.translateSave();
@@ -22322,33 +23863,20 @@ var Documents = class Documents extends DocComponent {
22322
23863
  this._drawLiquid.translateSave();
22323
23864
  this._drawLiquid.translateLine(line, true, true);
22324
23865
  const { y } = this._drawLiquid;
22325
- if (isHeader) {
22326
- if (y - originY + alignOffset.y > (parentPage.pageHeight - 100) / 2) {
23866
+ if (!isHeader) {
23867
+ if (y - originY + alignOffset.y + lineHeight < (parentPage.pageHeight - 100) / 2 + 100) {
22327
23868
  this._drawLiquid.translateRestore();
22328
23869
  continue;
22329
23870
  }
22330
- } else if (y - originY + alignOffset.y + lineHeight < (parentPage.pageHeight - 100) / 2 + 100) {
22331
- this._drawLiquid.translateRestore();
22332
- continue;
22333
23871
  }
23872
+ this._drawLineBackground(ctx, page, line, parentPage.marginLeft);
22334
23873
  const divideLength = divides.length;
22335
23874
  for (let i = 0; i < divideLength; i++) {
22336
23875
  const divide = divides[i];
22337
23876
  const { glyphGroup } = divide;
22338
23877
  this._drawLiquid.translateSave();
22339
23878
  this._drawLiquid.translateDivide(divide);
22340
- for (const glyph of glyphGroup) {
22341
- if (!glyph.content || glyph.content.length === 0) continue;
22342
- const { width: spanWidth, left: spanLeft } = glyph;
22343
- const { x: translateX, y: translateY } = this._drawLiquid;
22344
- const originTranslate = Vector2.create(translateX, translateY);
22345
- const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
22346
- const extensionOffset = { spanStartPoint: calculateRectRotate(originTranslate.addByPoint(spanLeft, 0), centerPoint, centerAngle, vertexAngle, alignOffset) };
22347
- if (backgroundExtension) {
22348
- backgroundExtension.extensionOffset = extensionOffset;
22349
- backgroundExtension.draw(ctx, parentScale, glyph);
22350
- }
22351
- }
23879
+ this._drawGlyphGroupBackgrounds(ctx, parentScale, glyphGroup, lineHeight, alignOffset, centerAngle, vertexAngle, backgroundExtension);
22352
23880
  for (const glyph of glyphGroup) {
22353
23881
  if (!glyph.content || glyph.content.length === 0) continue;
22354
23882
  const { width: spanWidth, left: spanLeft, xOffset } = glyph;
@@ -22384,18 +23912,19 @@ var Documents = class Documents extends DocComponent {
22384
23912
  * In Excel, if horizontal alignment is not specified,
22385
23913
  * rotated text aligns to the right when rotated downwards and aligns to the left when rotated upwards.
22386
23914
  */
22387
- if (horizontalAlign === _univerjs_core.HorizontalAlign.UNSPECIFIED) if (centerAngleDeg === 90 && vertexAngleDeg === 90) horizontalAlign = _univerjs_core.HorizontalAlign.CENTER;
23915
+ let resolvedHorizontalAlign = horizontalAlign;
23916
+ if (resolvedHorizontalAlign === _univerjs_core.HorizontalAlign.UNSPECIFIED) if (centerAngleDeg === 90 && vertexAngleDeg === 90) resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.CENTER;
22388
23917
  else if (vertexAngleDeg > 0 && vertexAngleDeg !== 90 || vertexAngleDeg === -90)
22389
23918
  /**
22390
23919
  * https://github.com/dream-num/univer-pro/issues/334
22391
23920
  */
22392
- horizontalAlign = _univerjs_core.HorizontalAlign.RIGHT;
22393
- else if (cellValueType === _univerjs_core.CellValueType.NUMBER) horizontalAlign = _univerjs_core.HorizontalAlign.RIGHT;
22394
- else if (cellValueType === _univerjs_core.CellValueType.BOOLEAN) horizontalAlign = _univerjs_core.HorizontalAlign.CENTER;
22395
- else horizontalAlign = _univerjs_core.HorizontalAlign.LEFT;
23921
+ resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.RIGHT;
23922
+ else if (cellValueType === _univerjs_core.CellValueType.NUMBER) resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.RIGHT;
23923
+ else if (cellValueType === _univerjs_core.CellValueType.BOOLEAN) resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.CENTER;
23924
+ else resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.LEFT;
22396
23925
  let offsetLeft = 0;
22397
- if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER) offsetLeft = (this.width - pageWidth) / 2;
22398
- else if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT) offsetLeft = this.width - pageWidth - pagePaddingRight;
23926
+ if (resolvedHorizontalAlign === _univerjs_core.HorizontalAlign.CENTER) offsetLeft = (this.width - pageWidth) / 2;
23927
+ else if (resolvedHorizontalAlign === _univerjs_core.HorizontalAlign.RIGHT) offsetLeft = this.width - pageWidth - pagePaddingRight;
22399
23928
  else offsetLeft = pagePaddingLeft;
22400
23929
  return offsetLeft;
22401
23930
  }
@@ -22429,6 +23958,37 @@ function setTableCellBorderDash(ctx, dashStyle) {
22429
23958
  }
22430
23959
  ctx.setLineDash([0]);
22431
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
+ }
23976
+ function fillRectByPrecisionBounds(ctx, x, y, width, height) {
23977
+ const { scaleX, scaleY } = ctx.getScale();
23978
+ const startX = fixLineWidthByScale(x, scaleX);
23979
+ const startY = fixLineWidthByScale(y, scaleY);
23980
+ const endX = fixLineWidthByScale(x + width, scaleX);
23981
+ const endY = fixLineWidthByScale(y + height, scaleY);
23982
+ ctx.fillRect(startX, startY, endX - startX, endY - startY);
23983
+ }
23984
+ function rectByPrecisionBounds(ctx, x, y, width, height) {
23985
+ const { scaleX, scaleY } = ctx.getScale();
23986
+ const startX = fixLineWidthByScale(x, scaleX);
23987
+ const startY = fixLineWidthByScale(y, scaleY);
23988
+ const endX = fixLineWidthByScale(x + width, scaleX);
23989
+ const endY = fixLineWidthByScale(y + height, scaleY);
23990
+ ctx.rect(startX, startY, endX - startX, endY - startY);
23991
+ }
22432
23992
 
22433
23993
  //#endregion
22434
23994
  //#region src/components/sheets/spreadsheet.ts
@@ -23641,6 +25201,8 @@ var DocBackground = class DocBackground extends DocComponent {
23641
25201
  _defineProperty(this, "_pageFillColor", void 0);
23642
25202
  _defineProperty(this, "_pageStrokeColor", void 0);
23643
25203
  _defineProperty(this, "_marginStrokeColor", void 0);
25204
+ _defineProperty(this, "_pageBackgroundSource", void 0);
25205
+ _defineProperty(this, "_pageBackgroundImage", void 0);
23644
25206
  this._drawLiquid = new Liquid();
23645
25207
  this._backgroundFillColor = config === null || config === void 0 ? void 0 : config.backgroundFillColor;
23646
25208
  this._pageFillColor = config === null || config === void 0 ? void 0 : config.pageFillColor;
@@ -23664,7 +25226,7 @@ var DocBackground = class DocBackground extends DocComponent {
23664
25226
  const skeletonData = (_this$getSkeleton = this.getSkeleton()) === null || _this$getSkeleton === void 0 ? void 0 : _this$getSkeleton.getSkeletonData();
23665
25227
  const docDataModel = (_this$getSkeleton2 = this.getSkeleton()) === null || _this$getSkeleton2 === void 0 ? void 0 : _this$getSkeleton2.getViewModel().getDataModel();
23666
25228
  if (skeletonData == null || docDataModel == null) return;
23667
- const { documentFlavor } = docDataModel.getSnapshot().documentStyle;
25229
+ const { documentFlavor, background } = docDataModel.getSnapshot().documentStyle;
23668
25230
  const workspaceFill = (_this$_backgroundFill = this._backgroundFillColor) !== null && _this$_backgroundFill !== void 0 ? _this$_backgroundFill : documentFlavor === _univerjs_core.DocumentFlavor.MODERN ? PAGE_FILL_COLOR : DOCS_WORKSPACE_FILL_COLOR;
23669
25231
  this._drawWorkspaceBackground(ctx, workspaceFill, bounds);
23670
25232
  if (documentFlavor === _univerjs_core.DocumentFlavor.MODERN) return;
@@ -23693,6 +25255,7 @@ var DocBackground = class DocBackground extends DocComponent {
23693
25255
  zIndex: 3
23694
25256
  };
23695
25257
  Rect.drawWith(ctx, backgroundOptions);
25258
+ this._drawPageBackgroundImage(ctx, background === null || background === void 0 ? void 0 : background.source, pageWidth !== null && pageWidth !== void 0 ? pageWidth : width, pageHeight !== null && pageHeight !== void 0 ? pageHeight : height);
23696
25259
  const IDENTIFIER_WIDTH = 15;
23697
25260
  const marginIdentification = {
23698
25261
  dataArray: [
@@ -23773,6 +25336,22 @@ var DocBackground = class DocBackground extends DocComponent {
23773
25336
  });
23774
25337
  ctx.restore();
23775
25338
  }
25339
+ _drawPageBackgroundImage(ctx, source, width, height) {
25340
+ if (!source || width <= 0 || height <= 0) return;
25341
+ const image = this._getPageBackgroundImage(source);
25342
+ if (!image.complete) return;
25343
+ ctx.drawImage(image, 0, 0, width, height);
25344
+ }
25345
+ _getPageBackgroundImage(source) {
25346
+ if (this._pageBackgroundSource === source && this._pageBackgroundImage != null) return this._pageBackgroundImage;
25347
+ const image = document.createElement("img");
25348
+ image.crossOrigin = "anonymous";
25349
+ image.onload = () => this.makeDirty(true);
25350
+ image.src = source;
25351
+ this._pageBackgroundSource = source;
25352
+ this._pageBackgroundImage = image;
25353
+ return image;
25354
+ }
23776
25355
  changeSkeleton(newSkeleton) {
23777
25356
  this.setSkeleton(newSkeleton);
23778
25357
  return this;
@@ -24209,6 +25788,42 @@ var DumbCanvasColorService = class {
24209
25788
  return color;
24210
25789
  }
24211
25790
  };
25791
+ const DARK_RENDER_COLOR_OVERRIDES = {
25792
+ "#17212b": "#e2e8f0",
25793
+ "#64748b": "#94a3b8",
25794
+ "#d9e0e7": "#253044",
25795
+ "#edf1f5": "#1b2535",
25796
+ "#eef2f6": "#1b2535",
25797
+ "#f2f5f8": "#101827",
25798
+ "#f3f6fa": "#18243a",
25799
+ "#f4f8ff": "#172a46",
25800
+ "#f5f9ff": "#12233a",
25801
+ "#f7f9fb": "#0d1422",
25802
+ "#f7f9fc": "#0d1422",
25803
+ "#f8fafc": "#0f172a",
25804
+ "#fbfcfd": "#07111f",
25805
+ "#fcfdff": "#050914",
25806
+ "#e8f1ff": "#173a69",
25807
+ "#eaf5ff": "#12315a",
25808
+ "#dbeafe": "#1e3a8a",
25809
+ "#bfdbfe": "#60a5fa",
25810
+ "#93c5fd": "#60a5fa",
25811
+ "#8eb6f5": "#60a5fa",
25812
+ "#60a5fa": "#60a5fa",
25813
+ "#2563eb": "#60a5fa",
25814
+ "#1d64d8": "#93c5fd",
25815
+ "#1d5cff": "#60a5fa",
25816
+ "#0f766e": "#2dd4bf",
25817
+ "#d7f4ef": "#134e4a",
25818
+ "rgba(37,99,235,0.05)": "rgba(96,165,250,0.16)",
25819
+ "rgba(37,99,235,0.06)": "rgba(96,165,250,0.18)",
25820
+ "rgba(37,99,235,0.08)": "rgba(96,165,250,0.22)",
25821
+ "rgba(37,99,235,0.12)": "rgba(96,165,250,0.26)",
25822
+ "rgba(37,99,235,0.18)": "rgba(96,165,250,0.30)",
25823
+ "rgba(37,99,235,0.28)": "rgba(96,165,250,0.38)",
25824
+ "rgba(239,246,255,0.88)": "rgba(30,64,175,0.72)",
25825
+ "rgba(148,163,184,0.45)": "rgba(148,163,184,0.52)"
25826
+ };
24212
25827
  let CanvasColorService = class CanvasColorService extends _univerjs_core.Disposable {
24213
25828
  constructor(_themeService) {
24214
25829
  super();
@@ -24219,8 +25834,14 @@ let CanvasColorService = class CanvasColorService extends _univerjs_core.Disposa
24219
25834
  getRenderColor(color) {
24220
25835
  if (!this._themeService.darkMode) return color;
24221
25836
  if (this._cache.has(color)) return this._cache.get(color);
25837
+ if (normalizeRenderColor(color) === "transparent") {
25838
+ this._cache.set(color, "transparent");
25839
+ return "transparent";
25840
+ }
24222
25841
  let cachedColor = "";
24223
- if (color.startsWith("#")) {
25842
+ const mappedColor = getDarkRenderColorOverride(color);
25843
+ if (mappedColor) cachedColor = mappedColor;
25844
+ else if (color.startsWith("#")) {
24224
25845
  cachedColor = rgbToHex(this._invertAlgo(hexToRgb(color)));
24225
25846
  if (color.length === 5) {
24226
25847
  const alpha = color.charAt(4);
@@ -24252,6 +25873,15 @@ let CanvasColorService = class CanvasColorService extends _univerjs_core.Disposa
24252
25873
  }
24253
25874
  };
24254
25875
  CanvasColorService = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService))], CanvasColorService);
25876
+ function getDarkRenderColorOverride(color) {
25877
+ var _DARK_RENDER_COLOR_OV;
25878
+ return (_DARK_RENDER_COLOR_OV = DARK_RENDER_COLOR_OVERRIDES[normalizeRenderColor(color)]) !== null && _DARK_RENDER_COLOR_OV !== void 0 ? _DARK_RENDER_COLOR_OV : null;
25879
+ }
25880
+ function normalizeRenderColor(color) {
25881
+ const trimmed = color.trim().toLowerCase();
25882
+ if (trimmed.startsWith("rgb")) return trimmed.replace(/\s+/g, "");
25883
+ return trimmed;
25884
+ }
24255
25885
  function hexToRgb(_hex) {
24256
25886
  const hex = _hex.replace(/^#/, "");
24257
25887
  let r;
@@ -24925,7 +26555,7 @@ Engine = __decorate([__decorateParam(2, ICanvasColorService)], Engine);
24925
26555
  //#endregion
24926
26556
  //#region package.json
24927
26557
  var name = "@univerjs/engine-render";
24928
- var version = "0.25.1";
26558
+ var version = "1.0.0-alpha.1";
24929
26559
 
24930
26560
  //#endregion
24931
26561
  //#region src/config/config.ts
@@ -25397,7 +27027,47 @@ const DEFAULT_TRANSFORMER_LAYER_INDEX = 2;
25397
27027
  const MINI_WIDTH_LIMIT = 20;
25398
27028
  const MINI_HEIGHT_LIMIT = 20;
25399
27029
  const DEFAULT_CONTROL_PLUS_INDEX = 5e3;
25400
- const SINGLE_ACTIVE_OBJECT_TYPE_MAP = new Set([6]);
27030
+ const SINGLE_ACTIVE_OBJECT_TYPE_MAP = /* @__PURE__ */ new Set([6]);
27031
+ const ROTATE_ICON_SIZE = 14;
27032
+ var TransformerRotateIcon = class extends Rect {
27033
+ _draw(ctx) {
27034
+ const iconWidth = this.width || ROTATE_ICON_SIZE;
27035
+ const iconHeight = this.height || ROTATE_ICON_SIZE;
27036
+ const scaleX = iconWidth / 24;
27037
+ const scaleY = iconHeight / 24;
27038
+ ctx.save();
27039
+ ctx.scale(scaleX, scaleY);
27040
+ ctx.beginPath();
27041
+ ctx.lineWidth = (this.strokeWidth || 2) / Math.max(scaleX, scaleY);
27042
+ ctx.lineCap = "round";
27043
+ ctx.lineJoin = "round";
27044
+ ctx.strokeStyle = this.stroke || "currentColor";
27045
+ ctx.moveTo(21, 12);
27046
+ ctx.arc(12, 12, 9, 0, Math.PI * 1.5, false);
27047
+ ctx.bezierCurveTo(14.52, 3, 16.93, 4, 18.74, 5.74);
27048
+ ctx.lineTo(21, 8);
27049
+ ctx.moveTo(21, 3);
27050
+ ctx.lineTo(21, 8);
27051
+ ctx.lineTo(16, 8);
27052
+ ctx.stroke();
27053
+ ctx.restore();
27054
+ }
27055
+ };
27056
+ var TransformerAnchor = class extends Rect {
27057
+ _draw(ctx) {
27058
+ if (!this.shadowColor || !this.shadowBlur && !this.shadowOffsetX && !this.shadowOffsetY) {
27059
+ Rect.drawWith(ctx, this);
27060
+ return;
27061
+ }
27062
+ ctx.save();
27063
+ ctx.shadowColor = this.shadowColor;
27064
+ ctx.shadowBlur = this.shadowBlur;
27065
+ ctx.shadowOffsetX = this.shadowOffsetX;
27066
+ ctx.shadowOffsetY = this.shadowOffsetY;
27067
+ Rect.drawWith(ctx, this);
27068
+ ctx.restore();
27069
+ }
27070
+ };
25401
27071
  /**
25402
27072
  * Transformer constructor. Transformer is a special type of group that allow you transform
25403
27073
  * primitives and shapes. Transforming tool is not changing `width` and `height` properties of nodes
@@ -25416,8 +27086,16 @@ var Transformer = class extends _univerjs_core.Disposable {
25416
27086
  _defineProperty(this, "rotationSnaps", []);
25417
27087
  _defineProperty(this, "rotationSnapTolerance", 5);
25418
27088
  _defineProperty(this, "rotateAnchorOffset", 50);
27089
+ _defineProperty(this, "rotateAnchorPosition", "top");
27090
+ _defineProperty(this, "rotateLineEnabled", true);
25419
27091
  _defineProperty(this, "rotateSize", 10);
25420
27092
  _defineProperty(this, "rotateCornerRadius", 10);
27093
+ _defineProperty(this, "rotateFill", void 0);
27094
+ _defineProperty(this, "rotateStroke", void 0);
27095
+ _defineProperty(this, "rotateStrokeWidth", void 0);
27096
+ _defineProperty(this, "rotateIconEnabled", false);
27097
+ _defineProperty(this, "rotateIconStroke", void 0);
27098
+ _defineProperty(this, "rotateIconStrokeWidth", 1.5);
25421
27099
  _defineProperty(this, "borderEnabled", true);
25422
27100
  _defineProperty(this, "borderStroke", "rgb(97, 97, 97)");
25423
27101
  _defineProperty(this, "borderStrokeWidth", 1);
@@ -25428,10 +27106,19 @@ var Transformer = class extends _univerjs_core.Disposable {
25428
27106
  _defineProperty(this, "anchorStrokeWidth", 1);
25429
27107
  _defineProperty(this, "anchorSize", 10);
25430
27108
  _defineProperty(this, "anchorCornerRadius", 10);
27109
+ _defineProperty(this, "anchorStyle", "default");
27110
+ _defineProperty(this, "anchorSideLongSize", 16);
27111
+ _defineProperty(this, "anchorSideShortSize", 5);
27112
+ _defineProperty(this, "anchorSideCornerRadius", 2.5);
27113
+ _defineProperty(this, "anchorShadowColor", void 0);
27114
+ _defineProperty(this, "anchorShadowBlur", 0);
27115
+ _defineProperty(this, "anchorShadowOffsetX", 0);
27116
+ _defineProperty(this, "anchorShadowOffsetY", 0);
25431
27117
  _defineProperty(this, "keepRatio", true);
25432
27118
  _defineProperty(this, "centeredScaling", false);
25433
27119
  _defineProperty(this, "zeroLeft", 0);
25434
27120
  _defineProperty(this, "zeroTop", 0);
27121
+ _defineProperty(this, "moveBoundaryEnabled", true);
25435
27122
  _defineProperty(
25436
27123
  this,
25437
27124
  /**
@@ -25545,9 +27232,9 @@ var Transformer = class extends _univerjs_core.Disposable {
25545
27232
  }
25546
27233
  _getConfig(applyObject) {
25547
27234
  const objectTransformerConfig = applyObject.transformerConfig;
25548
- let { isCropper, hoverEnabled, hoverEnterFunc, hoverLeaveFunc, resizeEnabled, rotateEnabled, rotationSnaps, rotationSnapTolerance, rotateAnchorOffset, rotateSize, rotateCornerRadius, borderEnabled, borderStroke, borderStrokeWidth, borderDash, borderSpacing, anchorFill, anchorStroke, anchorStrokeWidth, anchorSize, anchorCornerRadius, keepRatio, centeredScaling, enabledAnchors, flipEnabled, ignoreStroke, boundBoxFunc, useSingleNodeRotation, shouldOverdrawWholeArea } = this;
27235
+ let { isCropper, hoverEnabled, hoverEnterFunc, hoverLeaveFunc, resizeEnabled, rotateEnabled, rotationSnaps, rotationSnapTolerance, rotateAnchorOffset, rotateAnchorPosition, rotateLineEnabled, rotateSize, rotateCornerRadius, rotateFill, rotateStroke, rotateStrokeWidth, rotateIconEnabled, rotateIconStroke, rotateIconStrokeWidth, borderEnabled, borderStroke, borderStrokeWidth, borderDash, borderSpacing, anchorFill, anchorStroke, anchorStrokeWidth, anchorSize, anchorCornerRadius, anchorStyle, anchorSideLongSize, anchorSideShortSize, anchorSideCornerRadius, anchorShadowColor, anchorShadowBlur, anchorShadowOffsetX, anchorShadowOffsetY, keepRatio, centeredScaling, enabledAnchors, flipEnabled, ignoreStroke, boundBoxFunc, useSingleNodeRotation, shouldOverdrawWholeArea, moveBoundaryEnabled } = this;
25549
27236
  if (objectTransformerConfig != null) {
25550
- var _objectTransformerCon, _objectTransformerCon2, _objectTransformerCon3, _objectTransformerCon4, _objectTransformerCon5, _objectTransformerCon6, _objectTransformerCon7, _objectTransformerCon8, _objectTransformerCon9, _objectTransformerCon10, _objectTransformerCon11, _objectTransformerCon12, _objectTransformerCon13, _objectTransformerCon14, _objectTransformerCon15, _objectTransformerCon16, _objectTransformerCon17, _objectTransformerCon18, _objectTransformerCon19, _objectTransformerCon20, _objectTransformerCon21, _objectTransformerCon22, _objectTransformerCon23, _objectTransformerCon24, _objectTransformerCon25, _objectTransformerCon26, _objectTransformerCon27, _objectTransformerCon28, _objectTransformerCon29;
27237
+ var _objectTransformerCon, _objectTransformerCon2, _objectTransformerCon3, _objectTransformerCon4, _objectTransformerCon5, _objectTransformerCon6, _objectTransformerCon7, _objectTransformerCon8, _objectTransformerCon9, _objectTransformerCon10, _objectTransformerCon11, _objectTransformerCon12, _objectTransformerCon13, _objectTransformerCon14, _objectTransformerCon15, _objectTransformerCon16, _objectTransformerCon17, _objectTransformerCon18, _objectTransformerCon19, _objectTransformerCon20, _objectTransformerCon21, _objectTransformerCon22, _objectTransformerCon23, _objectTransformerCon24, _objectTransformerCon25, _objectTransformerCon26, _objectTransformerCon27, _objectTransformerCon28, _objectTransformerCon29, _objectTransformerCon30, _objectTransformerCon31, _objectTransformerCon32, _objectTransformerCon33, _objectTransformerCon34, _objectTransformerCon35, _objectTransformerCon36, _objectTransformerCon37, _objectTransformerCon38, _objectTransformerCon39, _objectTransformerCon40, _objectTransformerCon41, _objectTransformerCon42, _objectTransformerCon43, _objectTransformerCon44, _objectTransformerCon45, _objectTransformerCon46;
25551
27238
  isCropper = (_objectTransformerCon = objectTransformerConfig.isCropper) !== null && _objectTransformerCon !== void 0 ? _objectTransformerCon : isCropper;
25552
27239
  hoverEnabled = (_objectTransformerCon2 = objectTransformerConfig.hoverEnabled) !== null && _objectTransformerCon2 !== void 0 ? _objectTransformerCon2 : hoverEnabled;
25553
27240
  hoverEnterFunc = (_objectTransformerCon3 = objectTransformerConfig.hoverEnterFunc) !== null && _objectTransformerCon3 !== void 0 ? _objectTransformerCon3 : hoverEnterFunc;
@@ -25557,26 +27244,43 @@ var Transformer = class extends _univerjs_core.Disposable {
25557
27244
  rotationSnaps = (_objectTransformerCon7 = objectTransformerConfig.rotationSnaps) !== null && _objectTransformerCon7 !== void 0 ? _objectTransformerCon7 : rotationSnaps;
25558
27245
  rotationSnapTolerance = (_objectTransformerCon8 = objectTransformerConfig.rotationSnapTolerance) !== null && _objectTransformerCon8 !== void 0 ? _objectTransformerCon8 : rotationSnapTolerance;
25559
27246
  rotateAnchorOffset = (_objectTransformerCon9 = objectTransformerConfig.rotateAnchorOffset) !== null && _objectTransformerCon9 !== void 0 ? _objectTransformerCon9 : rotateAnchorOffset;
25560
- rotateSize = (_objectTransformerCon10 = objectTransformerConfig.rotateSize) !== null && _objectTransformerCon10 !== void 0 ? _objectTransformerCon10 : rotateSize;
25561
- rotateCornerRadius = (_objectTransformerCon11 = objectTransformerConfig.rotateCornerRadius) !== null && _objectTransformerCon11 !== void 0 ? _objectTransformerCon11 : rotateCornerRadius;
25562
- borderEnabled = (_objectTransformerCon12 = objectTransformerConfig.borderEnabled) !== null && _objectTransformerCon12 !== void 0 ? _objectTransformerCon12 : borderEnabled;
25563
- borderStroke = (_objectTransformerCon13 = objectTransformerConfig.borderStroke) !== null && _objectTransformerCon13 !== void 0 ? _objectTransformerCon13 : borderStroke;
25564
- borderStrokeWidth = (_objectTransformerCon14 = objectTransformerConfig.borderStrokeWidth) !== null && _objectTransformerCon14 !== void 0 ? _objectTransformerCon14 : borderStrokeWidth;
25565
- borderDash = (_objectTransformerCon15 = objectTransformerConfig.borderDash) !== null && _objectTransformerCon15 !== void 0 ? _objectTransformerCon15 : borderDash;
25566
- borderSpacing = (_objectTransformerCon16 = objectTransformerConfig.borderSpacing) !== null && _objectTransformerCon16 !== void 0 ? _objectTransformerCon16 : borderSpacing;
25567
- anchorFill = (_objectTransformerCon17 = objectTransformerConfig.anchorFill) !== null && _objectTransformerCon17 !== void 0 ? _objectTransformerCon17 : anchorFill;
25568
- anchorStroke = (_objectTransformerCon18 = objectTransformerConfig.anchorStroke) !== null && _objectTransformerCon18 !== void 0 ? _objectTransformerCon18 : anchorStroke;
25569
- anchorStrokeWidth = (_objectTransformerCon19 = objectTransformerConfig.anchorStrokeWidth) !== null && _objectTransformerCon19 !== void 0 ? _objectTransformerCon19 : anchorStrokeWidth;
25570
- anchorSize = (_objectTransformerCon20 = objectTransformerConfig.anchorSize) !== null && _objectTransformerCon20 !== void 0 ? _objectTransformerCon20 : anchorSize;
25571
- anchorCornerRadius = (_objectTransformerCon21 = objectTransformerConfig.anchorCornerRadius) !== null && _objectTransformerCon21 !== void 0 ? _objectTransformerCon21 : anchorCornerRadius;
25572
- keepRatio = (_objectTransformerCon22 = objectTransformerConfig.keepRatio) !== null && _objectTransformerCon22 !== void 0 ? _objectTransformerCon22 : keepRatio;
25573
- centeredScaling = (_objectTransformerCon23 = objectTransformerConfig.centeredScaling) !== null && _objectTransformerCon23 !== void 0 ? _objectTransformerCon23 : centeredScaling;
25574
- enabledAnchors = (_objectTransformerCon24 = objectTransformerConfig.enabledAnchors) !== null && _objectTransformerCon24 !== void 0 ? _objectTransformerCon24 : enabledAnchors;
25575
- flipEnabled = (_objectTransformerCon25 = objectTransformerConfig.flipEnabled) !== null && _objectTransformerCon25 !== void 0 ? _objectTransformerCon25 : flipEnabled;
25576
- ignoreStroke = (_objectTransformerCon26 = objectTransformerConfig.ignoreStroke) !== null && _objectTransformerCon26 !== void 0 ? _objectTransformerCon26 : ignoreStroke;
25577
- boundBoxFunc = (_objectTransformerCon27 = objectTransformerConfig.boundBoxFunc) !== null && _objectTransformerCon27 !== void 0 ? _objectTransformerCon27 : boundBoxFunc;
25578
- useSingleNodeRotation = (_objectTransformerCon28 = objectTransformerConfig.useSingleNodeRotation) !== null && _objectTransformerCon28 !== void 0 ? _objectTransformerCon28 : useSingleNodeRotation;
25579
- shouldOverdrawWholeArea = (_objectTransformerCon29 = objectTransformerConfig.shouldOverdrawWholeArea) !== null && _objectTransformerCon29 !== void 0 ? _objectTransformerCon29 : shouldOverdrawWholeArea;
27247
+ rotateAnchorPosition = (_objectTransformerCon10 = objectTransformerConfig.rotateAnchorPosition) !== null && _objectTransformerCon10 !== void 0 ? _objectTransformerCon10 : rotateAnchorPosition;
27248
+ rotateLineEnabled = (_objectTransformerCon11 = objectTransformerConfig.rotateLineEnabled) !== null && _objectTransformerCon11 !== void 0 ? _objectTransformerCon11 : rotateLineEnabled;
27249
+ rotateSize = (_objectTransformerCon12 = objectTransformerConfig.rotateSize) !== null && _objectTransformerCon12 !== void 0 ? _objectTransformerCon12 : rotateSize;
27250
+ rotateCornerRadius = (_objectTransformerCon13 = objectTransformerConfig.rotateCornerRadius) !== null && _objectTransformerCon13 !== void 0 ? _objectTransformerCon13 : rotateCornerRadius;
27251
+ rotateFill = (_objectTransformerCon14 = objectTransformerConfig.rotateFill) !== null && _objectTransformerCon14 !== void 0 ? _objectTransformerCon14 : rotateFill;
27252
+ rotateStroke = (_objectTransformerCon15 = objectTransformerConfig.rotateStroke) !== null && _objectTransformerCon15 !== void 0 ? _objectTransformerCon15 : rotateStroke;
27253
+ rotateStrokeWidth = (_objectTransformerCon16 = objectTransformerConfig.rotateStrokeWidth) !== null && _objectTransformerCon16 !== void 0 ? _objectTransformerCon16 : rotateStrokeWidth;
27254
+ rotateIconEnabled = (_objectTransformerCon17 = objectTransformerConfig.rotateIconEnabled) !== null && _objectTransformerCon17 !== void 0 ? _objectTransformerCon17 : rotateIconEnabled;
27255
+ rotateIconStroke = (_objectTransformerCon18 = objectTransformerConfig.rotateIconStroke) !== null && _objectTransformerCon18 !== void 0 ? _objectTransformerCon18 : rotateIconStroke;
27256
+ rotateIconStrokeWidth = (_objectTransformerCon19 = objectTransformerConfig.rotateIconStrokeWidth) !== null && _objectTransformerCon19 !== void 0 ? _objectTransformerCon19 : rotateIconStrokeWidth;
27257
+ borderEnabled = (_objectTransformerCon20 = objectTransformerConfig.borderEnabled) !== null && _objectTransformerCon20 !== void 0 ? _objectTransformerCon20 : borderEnabled;
27258
+ borderStroke = (_objectTransformerCon21 = objectTransformerConfig.borderStroke) !== null && _objectTransformerCon21 !== void 0 ? _objectTransformerCon21 : borderStroke;
27259
+ borderStrokeWidth = (_objectTransformerCon22 = objectTransformerConfig.borderStrokeWidth) !== null && _objectTransformerCon22 !== void 0 ? _objectTransformerCon22 : borderStrokeWidth;
27260
+ borderDash = (_objectTransformerCon23 = objectTransformerConfig.borderDash) !== null && _objectTransformerCon23 !== void 0 ? _objectTransformerCon23 : borderDash;
27261
+ borderSpacing = (_objectTransformerCon24 = objectTransformerConfig.borderSpacing) !== null && _objectTransformerCon24 !== void 0 ? _objectTransformerCon24 : borderSpacing;
27262
+ anchorFill = (_objectTransformerCon25 = objectTransformerConfig.anchorFill) !== null && _objectTransformerCon25 !== void 0 ? _objectTransformerCon25 : anchorFill;
27263
+ anchorStroke = (_objectTransformerCon26 = objectTransformerConfig.anchorStroke) !== null && _objectTransformerCon26 !== void 0 ? _objectTransformerCon26 : anchorStroke;
27264
+ anchorStrokeWidth = (_objectTransformerCon27 = objectTransformerConfig.anchorStrokeWidth) !== null && _objectTransformerCon27 !== void 0 ? _objectTransformerCon27 : anchorStrokeWidth;
27265
+ anchorSize = (_objectTransformerCon28 = objectTransformerConfig.anchorSize) !== null && _objectTransformerCon28 !== void 0 ? _objectTransformerCon28 : anchorSize;
27266
+ anchorCornerRadius = (_objectTransformerCon29 = objectTransformerConfig.anchorCornerRadius) !== null && _objectTransformerCon29 !== void 0 ? _objectTransformerCon29 : anchorCornerRadius;
27267
+ anchorStyle = (_objectTransformerCon30 = objectTransformerConfig.anchorStyle) !== null && _objectTransformerCon30 !== void 0 ? _objectTransformerCon30 : anchorStyle;
27268
+ anchorSideLongSize = (_objectTransformerCon31 = objectTransformerConfig.anchorSideLongSize) !== null && _objectTransformerCon31 !== void 0 ? _objectTransformerCon31 : anchorSideLongSize;
27269
+ anchorSideShortSize = (_objectTransformerCon32 = objectTransformerConfig.anchorSideShortSize) !== null && _objectTransformerCon32 !== void 0 ? _objectTransformerCon32 : anchorSideShortSize;
27270
+ anchorSideCornerRadius = (_objectTransformerCon33 = objectTransformerConfig.anchorSideCornerRadius) !== null && _objectTransformerCon33 !== void 0 ? _objectTransformerCon33 : anchorSideCornerRadius;
27271
+ anchorShadowColor = (_objectTransformerCon34 = objectTransformerConfig.anchorShadowColor) !== null && _objectTransformerCon34 !== void 0 ? _objectTransformerCon34 : anchorShadowColor;
27272
+ anchorShadowBlur = (_objectTransformerCon35 = objectTransformerConfig.anchorShadowBlur) !== null && _objectTransformerCon35 !== void 0 ? _objectTransformerCon35 : anchorShadowBlur;
27273
+ anchorShadowOffsetX = (_objectTransformerCon36 = objectTransformerConfig.anchorShadowOffsetX) !== null && _objectTransformerCon36 !== void 0 ? _objectTransformerCon36 : anchorShadowOffsetX;
27274
+ anchorShadowOffsetY = (_objectTransformerCon37 = objectTransformerConfig.anchorShadowOffsetY) !== null && _objectTransformerCon37 !== void 0 ? _objectTransformerCon37 : anchorShadowOffsetY;
27275
+ keepRatio = (_objectTransformerCon38 = objectTransformerConfig.keepRatio) !== null && _objectTransformerCon38 !== void 0 ? _objectTransformerCon38 : keepRatio;
27276
+ centeredScaling = (_objectTransformerCon39 = objectTransformerConfig.centeredScaling) !== null && _objectTransformerCon39 !== void 0 ? _objectTransformerCon39 : centeredScaling;
27277
+ enabledAnchors = (_objectTransformerCon40 = objectTransformerConfig.enabledAnchors) !== null && _objectTransformerCon40 !== void 0 ? _objectTransformerCon40 : enabledAnchors;
27278
+ flipEnabled = (_objectTransformerCon41 = objectTransformerConfig.flipEnabled) !== null && _objectTransformerCon41 !== void 0 ? _objectTransformerCon41 : flipEnabled;
27279
+ ignoreStroke = (_objectTransformerCon42 = objectTransformerConfig.ignoreStroke) !== null && _objectTransformerCon42 !== void 0 ? _objectTransformerCon42 : ignoreStroke;
27280
+ boundBoxFunc = (_objectTransformerCon43 = objectTransformerConfig.boundBoxFunc) !== null && _objectTransformerCon43 !== void 0 ? _objectTransformerCon43 : boundBoxFunc;
27281
+ useSingleNodeRotation = (_objectTransformerCon44 = objectTransformerConfig.useSingleNodeRotation) !== null && _objectTransformerCon44 !== void 0 ? _objectTransformerCon44 : useSingleNodeRotation;
27282
+ shouldOverdrawWholeArea = (_objectTransformerCon45 = objectTransformerConfig.shouldOverdrawWholeArea) !== null && _objectTransformerCon45 !== void 0 ? _objectTransformerCon45 : shouldOverdrawWholeArea;
27283
+ moveBoundaryEnabled = (_objectTransformerCon46 = objectTransformerConfig.moveBoundaryEnabled) !== null && _objectTransformerCon46 !== void 0 ? _objectTransformerCon46 : moveBoundaryEnabled;
25580
27284
  }
25581
27285
  return {
25582
27286
  isCropper,
@@ -25588,8 +27292,16 @@ var Transformer = class extends _univerjs_core.Disposable {
25588
27292
  rotationSnaps,
25589
27293
  rotationSnapTolerance,
25590
27294
  rotateAnchorOffset,
27295
+ rotateAnchorPosition,
27296
+ rotateLineEnabled,
25591
27297
  rotateSize,
25592
27298
  rotateCornerRadius,
27299
+ rotateFill,
27300
+ rotateStroke,
27301
+ rotateStrokeWidth,
27302
+ rotateIconEnabled,
27303
+ rotateIconStroke,
27304
+ rotateIconStrokeWidth,
25593
27305
  borderEnabled,
25594
27306
  borderStroke,
25595
27307
  borderStrokeWidth,
@@ -25600,6 +27312,14 @@ var Transformer = class extends _univerjs_core.Disposable {
25600
27312
  anchorStrokeWidth,
25601
27313
  anchorSize,
25602
27314
  anchorCornerRadius,
27315
+ anchorStyle,
27316
+ anchorSideLongSize,
27317
+ anchorSideShortSize,
27318
+ anchorSideCornerRadius,
27319
+ anchorShadowColor,
27320
+ anchorShadowBlur,
27321
+ anchorShadowOffsetX,
27322
+ anchorShadowOffsetY,
25603
27323
  keepRatio,
25604
27324
  centeredScaling,
25605
27325
  enabledAnchors,
@@ -25607,7 +27327,8 @@ var Transformer = class extends _univerjs_core.Disposable {
25607
27327
  ignoreStroke,
25608
27328
  boundBoxFunc,
25609
27329
  useSingleNodeRotation,
25610
- shouldOverdrawWholeArea
27330
+ shouldOverdrawWholeArea,
27331
+ moveBoundaryEnabled
25611
27332
  };
25612
27333
  }
25613
27334
  attachTo(applyObject) {
@@ -25641,7 +27362,7 @@ var Transformer = class extends _univerjs_core.Disposable {
25641
27362
  this._copperSelectedObject = applyObject;
25642
27363
  this._changeStart$.next({
25643
27364
  target: applyObject,
25644
- objects: new Map([[applyObject.oKey, applyObject]]),
27365
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
25645
27366
  type: 0
25646
27367
  });
25647
27368
  }
@@ -25669,7 +27390,7 @@ var Transformer = class extends _univerjs_core.Disposable {
25669
27390
  event
25670
27391
  });
25671
27392
  else this._changeEnd$.next({
25672
- objects: new Map([[applyObject.oKey, applyObject]]),
27393
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
25673
27394
  type: 2,
25674
27395
  offsetX,
25675
27396
  offsetY,
@@ -25716,6 +27437,10 @@ var Transformer = class extends _univerjs_core.Disposable {
25716
27437
  });
25717
27438
  }
25718
27439
  _checkMoveBoundary(moveObject, moveLeft, moveTop, ancestorLeft, ancestorTop, topSceneWidth, topSceneHeight) {
27440
+ if (this._getConfig(moveObject).moveBoundaryEnabled === false) return {
27441
+ moveLeft,
27442
+ moveTop
27443
+ };
25719
27444
  const { left, top, width, height } = moveObject;
25720
27445
  let resultMoveLeft = moveLeft;
25721
27446
  let resultMoveTop = moveTop;
@@ -25765,7 +27490,7 @@ var Transformer = class extends _univerjs_core.Disposable {
25765
27490
  moveTop = boundary.moveTop;
25766
27491
  cropper.translate(moveLeft + cropper.left, moveTop + cropper.top);
25767
27492
  this._changing$.next({
25768
- objects: new Map([[cropper.oKey, cropper]]),
27493
+ objects: /* @__PURE__ */ new Map([[cropper.oKey, cropper]]),
25769
27494
  moveX: moveLeft,
25770
27495
  moveY: moveTop,
25771
27496
  type: 1,
@@ -25800,7 +27525,7 @@ var Transformer = class extends _univerjs_core.Disposable {
25800
27525
  } else {
25801
27526
  this._moveFunc(applyObject, type, x, y, keepRatio, isCropper, isGroup);
25802
27527
  this._changing$.next({
25803
- objects: new Map([[applyObject.oKey, applyObject]]),
27528
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
25804
27529
  type: 1,
25805
27530
  offsetX: moveOffsetX,
25806
27531
  offsetY: moveOffsetY
@@ -26047,7 +27772,7 @@ var Transformer = class extends _univerjs_core.Disposable {
26047
27772
  });
26048
27773
  } else {
26049
27774
  this._changeStart$.next({
26050
- objects: new Map([[applyObject.oKey, applyObject]]),
27775
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
26051
27776
  type: 0
26052
27777
  });
26053
27778
  const { width, height, left, top } = applyObject.getState();
@@ -26088,7 +27813,7 @@ var Transformer = class extends _univerjs_core.Disposable {
26088
27813
  } else {
26089
27814
  this._recoverySizeBoundary([applyObject], ancestorLeft, ancestorTop, topSceneWidth, topSceneHeight);
26090
27815
  this._changeEnd$.next({
26091
- objects: new Map([[applyObject.oKey, applyObject]]),
27816
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
26092
27817
  type: 2,
26093
27818
  offsetX,
26094
27819
  offsetY,
@@ -26163,7 +27888,11 @@ var Transformer = class extends _univerjs_core.Disposable {
26163
27888
  _rotateMoving(moveOffsetX, moveOffsetY, centerX, centerY, agentOrigin) {
26164
27889
  const { ancestorScaleX, ancestorScaleY } = this._scene;
26165
27890
  if (this._moveBufferBlocker(moveOffsetX, moveOffsetY)) return;
26166
- let angle = agentOrigin + radToDeg(Math.atan2((moveOffsetY - centerY) / ancestorScaleY + this._viewportScrollY, (moveOffsetX - centerX) / ancestorScaleX + this._viewportScrollX) - Math.atan2((this._startOffsetY - centerY) / ancestorScaleY + this._viewportScrollY, (this._startOffsetX - centerX) / ancestorScaleX + this._viewportScrollX));
27891
+ const moveSceneX = moveOffsetX / ancestorScaleX + this._viewportScrollX;
27892
+ const moveSceneY = moveOffsetY / ancestorScaleY + this._viewportScrollY;
27893
+ const startSceneX = this._startOffsetX / ancestorScaleX + this._viewportScrollX;
27894
+ const startSceneY = this._startOffsetY / ancestorScaleY + this._viewportScrollY;
27895
+ let angle = agentOrigin + radToDeg(Math.atan2(moveSceneY - centerY, moveSceneX - centerX) - Math.atan2(startSceneY - centerY, startSceneX - centerX));
26167
27896
  if (angle < 0) angle = 360 + angle;
26168
27897
  angle %= 360;
26169
27898
  angle = this._smoothAccuracy(angle);
@@ -26220,6 +27949,23 @@ var Transformer = class extends _univerjs_core.Disposable {
26220
27949
  }
26221
27950
  return cursor;
26222
27951
  }
27952
+ _createRotateIcon(applyObject, zIndex, left, top) {
27953
+ const { rotateSize, rotateIconStroke, rotateIconStrokeWidth, borderStroke } = this._getConfig(applyObject);
27954
+ const iconOffset = (rotateSize - ROTATE_ICON_SIZE) / 2;
27955
+ return new TransformerRotateIcon(`__SpreadsheetTransformerRotate___ICON_${zIndex}`, {
27956
+ zIndex,
27957
+ evented: false,
27958
+ left: left + iconOffset,
27959
+ top: top + iconOffset,
27960
+ width: ROTATE_ICON_SIZE,
27961
+ height: ROTATE_ICON_SIZE,
27962
+ fill: null,
27963
+ stroke: rotateIconStroke !== null && rotateIconStroke !== void 0 ? rotateIconStroke : borderStroke,
27964
+ strokeWidth: rotateIconStrokeWidth,
27965
+ strokeLineCap: "round",
27966
+ strokeLineJoin: "round"
27967
+ });
27968
+ }
26223
27969
  _getCopperAnchorPosition(type, height, width, applyObject) {
26224
27970
  const { borderStrokeWidth, borderSpacing, anchorSize } = this._getConfig(applyObject);
26225
27971
  let left = 0;
@@ -26266,17 +28012,18 @@ var Transformer = class extends _univerjs_core.Disposable {
26266
28012
  };
26267
28013
  }
26268
28014
  _getRotateAnchorPosition(type, height, width, applyObject) {
26269
- const { rotateAnchorOffset, rotateSize, borderStrokeWidth, borderSpacing, anchorSize } = this._getConfig(applyObject);
28015
+ const { rotateAnchorOffset, rotateAnchorPosition, rotateSize, borderStrokeWidth, borderSpacing, anchorSize } = this._getConfig(applyObject);
28016
+ const isBottomRotateAnchor = rotateAnchorPosition === "bottom";
26270
28017
  let left = -anchorSize / 2;
26271
28018
  let top = -anchorSize / 2;
26272
28019
  switch (type) {
26273
28020
  case "__SpreadsheetTransformerRotate__":
26274
28021
  left = width / 2 - rotateSize / 2;
26275
- top = -rotateAnchorOffset - borderSpacing - borderStrokeWidth * 2 - rotateSize;
28022
+ top = isBottomRotateAnchor ? height + rotateAnchorOffset + borderSpacing + borderStrokeWidth * 2 : -rotateAnchorOffset - borderSpacing - borderStrokeWidth * 2 - rotateSize;
26276
28023
  break;
26277
28024
  case "__SpreadsheetTransformerRotateLine__":
26278
28025
  left = width / 2;
26279
- top = -rotateAnchorOffset - borderSpacing - borderStrokeWidth;
28026
+ top = isBottomRotateAnchor ? height + borderSpacing + borderStrokeWidth : -rotateAnchorOffset - borderSpacing - borderStrokeWidth;
26280
28027
  break;
26281
28028
  case "__SpreadsheetTransformerResizeLT__":
26282
28029
  left += -borderSpacing - borderStrokeWidth;
@@ -26316,21 +28063,43 @@ var Transformer = class extends _univerjs_core.Disposable {
26316
28063
  top
26317
28064
  };
26318
28065
  }
28066
+ _isMiddleAnchor(type) {
28067
+ return type === "__SpreadsheetTransformerResizeCT__" || type === "__SpreadsheetTransformerResizeLM__" || type === "__SpreadsheetTransformerResizeRM__" || type === "__SpreadsheetTransformerResizeCB__";
28068
+ }
28069
+ _getResizeAnchorProps(type, applyObject) {
28070
+ const { anchorSize, anchorCornerRadius, anchorStyle, anchorSideLongSize, anchorSideShortSize, anchorSideCornerRadius } = this._getConfig(applyObject);
28071
+ if (anchorStyle !== "canva" || !this._isMiddleAnchor(type)) return {
28072
+ width: anchorSize,
28073
+ height: anchorSize,
28074
+ radius: anchorStyle === "canva" ? anchorSize / 2 : anchorCornerRadius
28075
+ };
28076
+ const isHorizontal = type === "__SpreadsheetTransformerResizeCT__" || type === "__SpreadsheetTransformerResizeCB__";
28077
+ return {
28078
+ width: isHorizontal ? anchorSideLongSize : anchorSideShortSize,
28079
+ height: isHorizontal ? anchorSideShortSize : anchorSideLongSize,
28080
+ radius: anchorSideCornerRadius
28081
+ };
28082
+ }
26319
28083
  _createResizeAnchor(type, applyObject, zIndex) {
26320
28084
  const { height = 0, width = 0, scaleX = 1, scaleY = 1 } = applyObject.getState();
26321
- const { anchorFill, anchorStroke, anchorStrokeWidth, anchorCornerRadius, anchorSize } = this._getConfig(applyObject);
28085
+ const { anchorFill, anchorStroke, anchorStrokeWidth, anchorSize, anchorShadowColor, anchorShadowBlur, anchorShadowOffsetX, anchorShadowOffsetY } = this._getConfig(applyObject);
26322
28086
  const { left, top } = this._getRotateAnchorPosition(type, height, width, applyObject);
28087
+ const anchorProps = this._getResizeAnchorProps(type, applyObject);
26323
28088
  const cursor = this._getRotateAnchorCursor(type);
26324
- const anchor = new Rect(`${type}_${zIndex}`, {
28089
+ const anchor = new TransformerAnchor(`${type}_${zIndex}`, {
26325
28090
  zIndex: zIndex - 1,
26326
28091
  fill: anchorFill,
26327
28092
  stroke: anchorStroke,
26328
28093
  strokeWidth: anchorStrokeWidth,
26329
- width: anchorSize,
26330
- height: anchorSize,
26331
- radius: anchorCornerRadius,
26332
- left,
26333
- top
28094
+ width: anchorProps.width,
28095
+ height: anchorProps.height,
28096
+ radius: anchorProps.radius,
28097
+ left: left + (anchorSize - anchorProps.width) / 2,
28098
+ top: top + (anchorSize - anchorProps.height) / 2,
28099
+ shadowColor: anchorShadowColor,
28100
+ shadowBlur: anchorShadowBlur,
28101
+ shadowOffsetX: anchorShadowOffsetX,
28102
+ shadowOffsetY: anchorShadowOffsetY
26334
28103
  });
26335
28104
  this._attachHover(anchor, cursor, "default");
26336
28105
  return anchor;
@@ -26578,7 +28347,7 @@ var Transformer = class extends _univerjs_core.Disposable {
26578
28347
  _createControl(applyObject, isSkipOnCropper = true) {
26579
28348
  const { left = 0, top = 0, height = 0, width = 0 } = applyObject.getState();
26580
28349
  const angle = applyObject.angle;
26581
- const { isCropper, resizeEnabled, rotateEnabled, rotateAnchorOffset, rotateSize, rotateCornerRadius, borderEnabled, borderStroke, borderStrokeWidth, borderSpacing, enabledAnchors } = this._getConfig(applyObject);
28350
+ const { isCropper, resizeEnabled, rotateEnabled, rotateAnchorOffset, rotateLineEnabled, rotateSize, rotateCornerRadius, rotateFill, rotateStroke, rotateStrokeWidth, rotateIconEnabled, anchorShadowColor, anchorShadowBlur, anchorShadowOffsetX, anchorShadowOffsetY, borderEnabled, borderStroke, borderStrokeWidth, borderSpacing, enabledAnchors } = this._getConfig(applyObject);
26582
28351
  if (isSkipOnCropper && isCropper) return;
26583
28352
  const oKey = applyObject.oKey;
26584
28353
  const zIndex = this._selectedObjectMap.size + applyObject.maxZIndex + DEFAULT_CONTROL_PLUS_INDEX;
@@ -26609,19 +28378,26 @@ var Transformer = class extends _univerjs_core.Disposable {
26609
28378
  });
26610
28379
  const { left: rotateLeft, top: rotateTop } = this._getRotateAnchorPosition("__SpreadsheetTransformerRotate__", height, width, applyObject);
26611
28380
  const cursor = this._getRotateAnchorCursor("__SpreadsheetTransformerRotate__");
26612
- const rotate = new Rect(`__SpreadsheetTransformerRotate___${zIndex}`, {
28381
+ const rotate = new TransformerAnchor(`__SpreadsheetTransformerRotate___${zIndex}`, {
26613
28382
  zIndex: zIndex - 1,
26614
28383
  left: rotateLeft,
26615
28384
  top: rotateTop,
26616
28385
  height: rotateSize,
26617
28386
  width: rotateSize,
26618
28387
  radius: rotateCornerRadius,
26619
- strokeWidth: borderStrokeWidth * 2,
26620
- stroke: borderStroke
28388
+ fill: rotateFill,
28389
+ strokeWidth: rotateStrokeWidth !== null && rotateStrokeWidth !== void 0 ? rotateStrokeWidth : borderStrokeWidth * 2,
28390
+ stroke: rotateStroke !== null && rotateStroke !== void 0 ? rotateStroke : borderStroke,
28391
+ shadowColor: anchorShadowColor,
28392
+ shadowBlur: anchorShadowBlur,
28393
+ shadowOffsetX: anchorShadowOffsetX,
28394
+ shadowOffsetY: anchorShadowOffsetY
26621
28395
  });
26622
28396
  this._attachEventToRotate(rotate, applyObject);
26623
28397
  this._attachHover(rotate, cursor, "default");
26624
- groupElements.push(rotateLine, rotate);
28398
+ if (rotateLineEnabled) groupElements.push(rotateLine);
28399
+ groupElements.push(rotate);
28400
+ if (rotateIconEnabled) groupElements.push(this._createRotateIcon(applyObject, zIndex, rotateLeft, rotateTop));
26625
28401
  }
26626
28402
  }
26627
28403
  if (resizeEnabled) for (let i = 0, len = enabledAnchors.length; i < len; i++) {
@@ -29235,12 +31011,15 @@ exports.cancelRequestFrame = cancelRequestFrame;
29235
31011
  exports.checkStyle = checkStyle;
29236
31012
  exports.clampRange = clampRange;
29237
31013
  exports.clearLineByBorderType = clearLineByBorderType;
31014
+ exports.compareDocumentSkeletonNestedPagePathOrder = compareDocumentSkeletonNestedPagePathOrder;
29238
31015
  exports.convertTextRotation = convertTextRotation;
29239
31016
  exports.convertTransformToOffsetX = convertTransformToOffsetX;
29240
31017
  exports.convertTransformToOffsetY = convertTransformToOffsetY;
29241
31018
  exports.createCanvasElement = createCanvasElement;
29242
31019
  exports.createImageElement = createImageElement;
29243
31020
  exports.degToRad = degToRad;
31021
+ exports.documentSkeletonLineIterator = documentSkeletonLineIterator;
31022
+ exports.documentSkeletonTableIterator = documentSkeletonTableIterator;
29244
31023
  exports.drawDiagonalLineByBorderType = drawDiagonalLineByBorderType;
29245
31024
  exports.drawLineByBorderType = drawLineByBorderType;
29246
31025
  exports.expandRangeIfIntersects = expandRangeIfIntersects;
@@ -29256,6 +31035,8 @@ exports.getDPI = getDPI;
29256
31035
  exports.getDevicePixelRatio = getDevicePixelRatio;
29257
31036
  exports.getDocsSkeletonPageSize = getDocsSkeletonPageSize;
29258
31037
  exports.getDocsTableRenderViewport = getDocsTableRenderViewport;
31038
+ exports.getDocumentSkeletonColumnPagePathInfo = getDocumentSkeletonColumnPagePathInfo;
31039
+ exports.getDocumentSkeletonNestedPageOffset = getDocumentSkeletonNestedPageOffset;
29259
31040
  exports.getDrawingGroupState = getDrawingGroupState;
29260
31041
  exports.getFirstGrapheme = getFirstGrapheme;
29261
31042
  exports.getFontStyleString = getFontStyleString;