@univerjs/engine-render 0.25.0 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -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
@@ -10878,8 +10878,8 @@ const TINF_OK = 0;
10878
10878
  const TINF_DATA_ERROR = -3;
10879
10879
  var Tree = class {
10880
10880
  constructor() {
10881
- _defineProperty(this, "table", new Uint16Array(16));
10882
- _defineProperty(this, "trans", new Uint16Array(288));
10881
+ _defineProperty(this, "table", /* @__PURE__ */ new Uint16Array(16));
10882
+ _defineProperty(this, "trans", /* @__PURE__ */ new Uint16Array(288));
10883
10883
  }
10884
10884
  };
10885
10885
  var Data = class {
@@ -10904,10 +10904,10 @@ var Data = class {
10904
10904
  };
10905
10905
  const sltree = new Tree();
10906
10906
  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);
10907
+ const length_bits = /* @__PURE__ */ new Uint8Array(30);
10908
+ const length_base = /* @__PURE__ */ new Uint16Array(30);
10909
+ const dist_bits = /* @__PURE__ */ new Uint8Array(30);
10910
+ const dist_base = /* @__PURE__ */ new Uint16Array(30);
10911
10911
  const clcidx = new Uint8Array([
10912
10912
  16,
10913
10913
  17,
@@ -10930,7 +10930,7 @@ const clcidx = new Uint8Array([
10930
10930
  15
10931
10931
  ]);
10932
10932
  const code_tree = new Tree();
10933
- const lengths = new Uint8Array(320);
10933
+ const lengths = /* @__PURE__ */ new Uint8Array(320);
10934
10934
  function tinf_build_bits_base(bits, base, delta, first) {
10935
10935
  let i;
10936
10936
  let sum;
@@ -10955,7 +10955,7 @@ function tinf_build_fixed_trees(lt, dt) {
10955
10955
  dt.table[5] = 32;
10956
10956
  for (i = 0; i < 32; ++i) dt.trans[i] = i;
10957
10957
  }
10958
- const offs = new Uint16Array(16);
10958
+ const offs = /* @__PURE__ */ new Uint16Array(16);
10959
10959
  function tinf_build_tree(t, lengths, off, num) {
10960
10960
  let i;
10961
10961
  let sum;
@@ -12111,6 +12111,13 @@ function getDocsTableRenderViewport(unitId, tableId) {
12111
12111
  var _docsTableRenderViewp;
12112
12112
  return (_docsTableRenderViewp = docsTableRenderViewportProvider === null || docsTableRenderViewportProvider === void 0 ? void 0 : docsTableRenderViewportProvider(unitId, tableId)) !== null && _docsTableRenderViewp !== void 0 ? _docsTableRenderViewp : null;
12113
12113
  }
12114
+ function getDocsTableVirtualContentWidth(viewport) {
12115
+ var _viewport$leadingInse, _viewport$trailingIns;
12116
+ 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);
12117
+ }
12118
+ function hasDocsTableHorizontalViewport(viewport) {
12119
+ return viewport != null && getDocsTableVirtualContentWidth(viewport) > viewport.viewportWidth;
12120
+ }
12114
12121
 
12115
12122
  //#endregion
12116
12123
  //#region src/components/docs/view-model/data-stream-tree-node.ts
@@ -12581,6 +12588,68 @@ var DocumentViewModel = class DocumentViewModel {
12581
12588
  }
12582
12589
  };
12583
12590
 
12591
+ //#endregion
12592
+ //#region src/components/docs/document-compatibility.ts
12593
+ const MODERN_DOCUMENT_COMPATIBILITY_POLICY = {
12594
+ mode: "modern",
12595
+ applyDocumentDefaultParagraphStyle: true,
12596
+ useWordStyleLineHeight: true,
12597
+ font: { metricScaleRules: [] },
12598
+ table: {
12599
+ currentPageOverflowTolerance: 0,
12600
+ rowOverflowTolerance: 0,
12601
+ allowImportedTableMarginOverflow: false
12602
+ }
12603
+ };
12604
+ const TRADITIONAL_DOCUMENT_COMPATIBILITY_POLICY = {
12605
+ mode: "traditional",
12606
+ applyDocumentDefaultParagraphStyle: false,
12607
+ useWordStyleLineHeight: true,
12608
+ font: { metricScaleRules: [{
12609
+ fontFamily: /^calibri$/i,
12610
+ minFontSize: 20,
12611
+ fontString: /\bbold\b/i,
12612
+ content: /^[\d/]+$/u,
12613
+ widthScale: .92
12614
+ }] },
12615
+ table: {
12616
+ currentPageOverflowTolerance: 12,
12617
+ rowOverflowTolerance: 4,
12618
+ allowImportedTableMarginOverflow: true
12619
+ }
12620
+ };
12621
+ const UNSPECIFIED_DOCUMENT_COMPATIBILITY_POLICY = {
12622
+ mode: "unspecified",
12623
+ applyDocumentDefaultParagraphStyle: false,
12624
+ useWordStyleLineHeight: false,
12625
+ font: { metricScaleRules: [] },
12626
+ table: {
12627
+ currentPageOverflowTolerance: 0,
12628
+ rowOverflowTolerance: 0,
12629
+ allowImportedTableMarginOverflow: false
12630
+ }
12631
+ };
12632
+ function getDocumentCompatibilityPolicy(documentFlavor) {
12633
+ if (documentFlavor === _univerjs_core.DocumentFlavor.MODERN) return MODERN_DOCUMENT_COMPATIBILITY_POLICY;
12634
+ if (documentFlavor === _univerjs_core.DocumentFlavor.TRADITIONAL) return TRADITIONAL_DOCUMENT_COMPATIBILITY_POLICY;
12635
+ return UNSPECIFIED_DOCUMENT_COMPATIBILITY_POLICY;
12636
+ }
12637
+ function applyFontMetricCompatibility(content, fontStyle, bBox, policy) {
12638
+ const fontFamilies = fontStyle.fontFamily.split(",").map((item) => item.trim().replace(/^['"]|['"]$/g, ""));
12639
+ const rule = policy.font.metricScaleRules.find((rule) => (rule.minFontSize == null || fontStyle.originFontSize >= rule.minFontSize) && (rule.fontString == null || rule.fontString.test(fontStyle.fontString)) && (rule.content == null || rule.content.test(content)) && fontFamilies.some((family) => rule.fontFamily.test(family)));
12640
+ if ((rule === null || rule === void 0 ? void 0 : rule.widthScale) == null) return bBox;
12641
+ return {
12642
+ ...bBox,
12643
+ width: bBox.width * rule.widthScale
12644
+ };
12645
+ }
12646
+ function isTraditionalDocumentCompatibility(policy) {
12647
+ return policy.mode === "traditional";
12648
+ }
12649
+ function shouldAllowImportedTableMarginOverflow(policy, tableSource) {
12650
+ return policy.table.allowImportedTableMarginOverflow && tableSource != null && typeof tableSource === "object" && "docxWidth" in tableSource;
12651
+ }
12652
+
12584
12653
  //#endregion
12585
12654
  //#region src/components/docs/layout/model/glyph.ts
12586
12655
  function isSpace(char) {
@@ -12661,6 +12730,7 @@ function createSkeletonCustomBlockGlyph(config, glyphWidth = 0, glyphHeight = 0,
12661
12730
  };
12662
12731
  }
12663
12732
  function _createSkeletonWordOrLetter(glyphType, content, config, glyphWidth, glyphInfo) {
12733
+ var _config$documentCompa;
12664
12734
  const { fontStyle, textStyle, charSpace = 1, gridType = _univerjs_core.GridType.LINES, snapToGrid = _univerjs_core.BooleanNumber.FALSE } = config;
12665
12735
  const skipWidthList = [
12666
12736
  _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK,
@@ -12711,6 +12781,7 @@ function _createSkeletonWordOrLetter(glyphType, content, config, glyphWidth, gly
12711
12781
  let xOffset = 0;
12712
12782
  if (glyphInfo && glyphInfo.boundingBox && glyphInfo.font) bBox = FontCache.getBBoxFromGlyphInfo(glyphInfo, fontStyle);
12713
12783
  else bBox = FontCache.getTextSize(content, fontStyle);
12784
+ bBox = applyFontMetricCompatibility(content, fontStyle, bBox, (_config$documentCompa = config.documentCompatibilityPolicy) !== null && _config$documentCompa !== void 0 ? _config$documentCompa : getDocumentCompatibilityPolicy());
12714
12785
  const { width: contentWidth = 0 } = bBox;
12715
12786
  let width = glyphWidth !== null && glyphWidth !== void 0 ? glyphWidth : contentWidth;
12716
12787
  if (validationGrid(gridType, snapToGrid)) {
@@ -12831,11 +12902,11 @@ function createSkeletonLine(paragraphIndex, lineType, lineBoundingBox, columnWid
12831
12902
  lineSke.isBehindTable = true;
12832
12903
  lineSke.tableId = tableId;
12833
12904
  }
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)));
12905
+ lineSke.divides = _calculateDividesByDrawings(lineHeight, lineTop, columnWidth, paddingLeft, paddingRight, page, headerPage, footerPage, new Map(Array.from(pageSkeDrawings).filter(([_, drawing]) => drawing.drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE && drawing.drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE)), headersDrawings, footersDrawings, new Map(Array.from(pageSkeTables).filter(([_, table]) => table.tableSource.textWrap === _univerjs_core.TableTextWrapType.WRAP)));
12835
12906
  for (const divide of lineSke.divides) divide.parent = lineSke;
12836
12907
  return lineSke;
12837
12908
  }
12838
- function calculateLineTopByDrawings(lineHeight = 15.6, lineTop = 0, page, headerPage, footerPage) {
12909
+ function calculateLineTopByDrawings(lineHeight = 15.6, lineTop = 0, page, headerPage, footerPage, columnLeft = 0, columnWidth = 0) {
12839
12910
  let maxTop = lineTop;
12840
12911
  const pageSkeDrawings = page.skeDrawings;
12841
12912
  const skeNonWrapTables = new Map(Array.from(page.skeTables).filter(([_, table]) => table.tableSource.textWrap === _univerjs_core.TableTextWrapType.NONE));
@@ -12852,6 +12923,8 @@ function calculateLineTopByDrawings(lineHeight = 15.6, lineTop = 0, page, header
12852
12923
  pageSkeDrawings === null || pageSkeDrawings === void 0 || pageSkeDrawings.forEach((drawing) => {
12853
12924
  const top = _getLineTopWidthWrapTopBottom(drawing, lineHeight, lineTop);
12854
12925
  if (top) maxTop = Math.max(maxTop, top);
12926
+ const blockingWrapTop = _getLineTopWithFullColumnWrap(drawing, lineHeight, lineTop, columnLeft, columnWidth);
12927
+ if (blockingWrapTop) maxTop = Math.max(maxTop, blockingWrapTop);
12855
12928
  });
12856
12929
  skeNonWrapTables === null || skeNonWrapTables === void 0 || skeNonWrapTables.forEach((table) => {
12857
12930
  const top = _getLineTopWidthWrapNone(table, lineHeight, lineTop);
@@ -12859,6 +12932,37 @@ function calculateLineTopByDrawings(lineHeight = 15.6, lineTop = 0, page, header
12859
12932
  });
12860
12933
  return maxTop;
12861
12934
  }
12935
+ function _getLineTopWithFullColumnWrap(drawing, lineHeight, lineTop, columnLeft, columnWidth) {
12936
+ if (columnWidth <= 0) return;
12937
+ const { aTop, height, aLeft, width, angle = 0, drawingOrigin } = drawing;
12938
+ const { layoutType, distL = 0, distT = 0, distB = 0, distR = 0, wrapText } = drawingOrigin;
12939
+ if (layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE || layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE || layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) return;
12940
+ let top = aTop;
12941
+ let drawingHeight = height;
12942
+ let left = aLeft - columnLeft;
12943
+ let drawingWidth = width;
12944
+ if (angle !== 0) {
12945
+ var _boundingBox$top, _boundingBox$height, _boundingBox$left, _boundingBox$width;
12946
+ const boundingBox = getBoundingBox(angle, left, width, top, height);
12947
+ top = (_boundingBox$top = boundingBox.top) !== null && _boundingBox$top !== void 0 ? _boundingBox$top : top;
12948
+ drawingHeight = (_boundingBox$height = boundingBox.height) !== null && _boundingBox$height !== void 0 ? _boundingBox$height : drawingHeight;
12949
+ left = (_boundingBox$left = boundingBox.left) !== null && _boundingBox$left !== void 0 ? _boundingBox$left : left;
12950
+ drawingWidth = (_boundingBox$width = boundingBox.width) !== null && _boundingBox$width !== void 0 ? _boundingBox$width : drawingWidth;
12951
+ }
12952
+ const newTop = top - (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE ? distT : 0);
12953
+ const newHeight = drawingHeight + (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE ? distB + distT : 0);
12954
+ const bottom = newTop + newHeight;
12955
+ if (bottom <= lineTop) return;
12956
+ const split = __getSplitWidthNoAngle(top, drawingHeight, left, drawingWidth, newTop, Math.max(1, newHeight), columnWidth, {
12957
+ distL,
12958
+ distT,
12959
+ distB,
12960
+ distR
12961
+ }, layoutType, wrapText);
12962
+ if (!split) return;
12963
+ if (split.left > 0 || split.left + split.width < columnWidth) return;
12964
+ return bottom;
12965
+ }
12862
12966
  function _getLineTopWidthWrapNone(table, lineHeight, lineTop) {
12863
12967
  const { top, height } = table;
12864
12968
  if (top + height < lineTop || top > lineHeight + lineTop) return;
@@ -13058,6 +13162,7 @@ function _calculateDivideByDrawings(columnWidth, drawingSplit) {
13058
13162
  divideSkeleton.push(divide);
13059
13163
  }
13060
13164
  }
13165
+ if (divideSkeleton.length === 0 && columnWidth > 0) return [__getDivideSKe(0, columnWidth)];
13061
13166
  return divideSkeleton;
13062
13167
  }
13063
13168
  function __getDivideSKe(left, width) {
@@ -13114,17 +13219,11 @@ function createSkeletonSection(columnProperties = [], columnSeparatorType = _uni
13114
13219
  let colWidth = 0;
13115
13220
  let spaceWidth = 0;
13116
13221
  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];
13222
+ else for (const { width, paddingEnd } of _fitColumnProperties(columnProperties, sectionWidth)) {
13119
13223
  spaceWidth = paddingEnd;
13120
13224
  colWidth = width;
13121
13225
  columns.push(_getSkeletonColumn(left, colWidth, spaceWidth, columnSeparatorType));
13122
13226
  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
13227
  }
13129
13228
  const newSection = {
13130
13229
  columns,
@@ -13139,6 +13238,42 @@ function createSkeletonSection(columnProperties = [], columnSeparatorType = _uni
13139
13238
  });
13140
13239
  return newSection;
13141
13240
  }
13241
+ function _fitColumnProperties(columnProperties, sectionWidth) {
13242
+ if (sectionWidth === Number.POSITIVE_INFINITY || columnProperties.length === 0) return columnProperties;
13243
+ const safeSectionWidth = Math.max(0, sectionWidth);
13244
+ const widths = columnProperties.map(({ width }) => Math.max(0, width));
13245
+ const spaces = columnProperties.map(({ paddingEnd }, index) => index === columnProperties.length - 1 ? 0 : Math.max(0, paddingEnd));
13246
+ const totalWidth = widths.reduce((sum, width) => sum + width, 0);
13247
+ if (safeSectionWidth === 0) return columnProperties.map((columnProperty) => ({
13248
+ ...columnProperty,
13249
+ width: 0,
13250
+ paddingEnd: 0
13251
+ }));
13252
+ if (totalWidth <= 0) {
13253
+ const equalWidth = safeSectionWidth / columnProperties.length;
13254
+ return columnProperties.map((columnProperty, index) => ({
13255
+ ...columnProperty,
13256
+ width: equalWidth,
13257
+ paddingEnd: 0
13258
+ }));
13259
+ }
13260
+ if (totalWidth > safeSectionWidth) {
13261
+ const scale = safeSectionWidth / totalWidth;
13262
+ return columnProperties.map((columnProperty, index) => ({
13263
+ ...columnProperty,
13264
+ width: widths[index] * scale,
13265
+ paddingEnd: 0
13266
+ }));
13267
+ }
13268
+ const spaceBudget = safeSectionWidth - totalWidth;
13269
+ const totalSpace = spaces.reduce((sum, space) => sum + space, 0);
13270
+ const fittedSpaces = totalSpace > spaceBudget && totalSpace > 0 ? spaces.map((space) => space / totalSpace * spaceBudget) : spaces;
13271
+ return columnProperties.map((columnProperty, index) => ({
13272
+ ...columnProperty,
13273
+ width: widths[index],
13274
+ paddingEnd: fittedSpaces[index]
13275
+ }));
13276
+ }
13142
13277
  function setColumnFullState(column, state) {
13143
13278
  column.isFull = state;
13144
13279
  }
@@ -13239,12 +13374,13 @@ function createTableSkeleton(ctx, curPage, viewModel, tableNode, sectionBreakCon
13239
13374
  function rollbackListCache(listLevel, table) {
13240
13375
  const { startIndex, endIndex } = table;
13241
13376
  for (const paragraphLists of listLevel.values()) for (const paragraphList of paragraphLists) {
13377
+ if (paragraphList == null) continue;
13242
13378
  const paragraphListIndex = paragraphList.findIndex((p) => p.paragraph.startIndex > startIndex && p.paragraph.startIndex < endIndex);
13243
13379
  if (paragraphListIndex > -1) paragraphList.splice(paragraphListIndex);
13244
13380
  }
13245
13381
  }
13246
13382
  function createTableSkeletons(ctx, curPage, viewModel, tableNode, sectionBreakConfig, availableHeight) {
13247
- var _viewModel$getTableBy2;
13383
+ var _viewModel$getTableBy2, _sectionBreakConfig$d;
13248
13384
  const skeTables = [];
13249
13385
  const { startIndex, endIndex, children: rowNodes } = tableNode;
13250
13386
  const table = (_viewModel$getTableBy2 = viewModel.getTableByStartIndex(startIndex)) === null || _viewModel$getTableBy2 === void 0 ? void 0 : _viewModel$getTableBy2.tableSource;
@@ -13267,9 +13403,10 @@ function createTableSkeletons(ctx, curPage, viewModel, tableNode, sectionBreakCo
13267
13403
  skeTables.push(curTableSkeleton);
13268
13404
  for (const rowNode of rowNodes) dealWithTableRow(ctx, curPage, skeTables, viewModel, sectionBreakConfig, rowNode, rowNodes.indexOf(rowNode), table, createCache);
13269
13405
  updateTableSkeletonsPosition(createCache, curPage, skeTables, table);
13406
+ const documentCompatibilityPolicy = (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy();
13270
13407
  return {
13271
13408
  skeTables,
13272
- fromCurrentPage: skeTables[0].height <= availableHeight
13409
+ fromCurrentPage: skeTables[0].height <= availableHeight + documentCompatibilityPolicy.table.currentPageOverflowTolerance
13273
13410
  };
13274
13411
  }
13275
13412
  function updateTableSkeletonsPosition(cache, curPage, skeTables, table) {
@@ -13299,14 +13436,16 @@ function getAvailableHeight(curPage, cache, hasRepeatHeader) {
13299
13436
  return pageContentHeight;
13300
13437
  }
13301
13438
  function dealWithTableRow(ctx, curPage, skeTables, viewModel, sectionBreakConfig, rowNode, row, table, cache, isRepeatRow = false) {
13439
+ var _sectionBreakConfig$d2;
13302
13440
  const pageContentHeight = getAvailableHeight(curPage, cache, false);
13303
13441
  const availableHeight = getAvailableHeight(curPage, cache, true);
13442
+ const documentCompatibilityPolicy = (_sectionBreakConfig$d2 = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d2 !== void 0 ? _sectionBreakConfig$d2 : getDocumentCompatibilityPolicy();
13304
13443
  const { children: cellNodes, startIndex, endIndex } = rowNode;
13305
13444
  const rowSource = table.tableRows[row];
13306
13445
  const { trHeight, cantSplit } = rowSource;
13307
13446
  const rowSkeletons = [];
13308
13447
  const { hRule, val } = trHeight;
13309
- const canRowSplit = cantSplit === _univerjs_core.BooleanNumber.TRUE && trHeight.hRule === _univerjs_core.TableRowHeightRule.AUTO;
13448
+ const canRowSplit = cantSplit !== _univerjs_core.BooleanNumber.TRUE && trHeight.hRule === _univerjs_core.TableRowHeightRule.AUTO;
13310
13449
  const MAX_FONT_SIZE = 72;
13311
13450
  const needOpenNewTable = cache.remainHeight <= MAX_FONT_SIZE;
13312
13451
  let curTableSkeleton = getCurTableSkeleton(skeTables);
@@ -13352,7 +13491,8 @@ function dealWithTableRow(ctx, curPage, skeTables, viewModel, sectionBreakConfig
13352
13491
  while (rowSkeletons.length > 0) {
13353
13492
  const rowSkeleton = rowSkeletons.shift();
13354
13493
  const lastRow = curTableSkeleton.rows[curTableSkeleton.rows.length - 1];
13355
- if (cache.remainHeight < MAX_FONT_SIZE || cache.remainHeight < rowSkeleton.height) {
13494
+ const rowOverflowHeight = rowSkeleton.height - cache.remainHeight;
13495
+ if (cache.remainHeight < MAX_FONT_SIZE || rowOverflowHeight > documentCompatibilityPolicy.table.rowOverflowTolerance) {
13356
13496
  cache.remainHeight = getAvailableHeight(curPage, cache, row !== 0 && rowSkeleton.index !== lastRow.index);
13357
13497
  cache.rowTop = 0;
13358
13498
  if (curTableSkeleton.rows.length > 0) {
@@ -13528,18 +13668,22 @@ function getTableIdAndSliceIndex(tableSliceId) {
13528
13668
 
13529
13669
  //#endregion
13530
13670
  //#region src/components/docs/layout/block/paragraph/layout-ruler.ts
13671
+ const LINE_LAYOUT_OVERFLOW_TOLERANCE = 2;
13672
+ const FLOAT_OBJECT_RELAYOUT_LIMIT = 5;
13531
13673
  function layoutParagraph(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType = "Normal") {
13532
13674
  if (isParagraphFirstShapedText) if (paragraphConfig.bulletSkeleton) {
13675
+ var _paragraphProperties$;
13533
13676
  const { bulletSkeleton, paragraphStyle = {} } = paragraphConfig;
13534
13677
  const { gridType = _univerjs_core.GridType.LINES, charSpace = 0, defaultTabStop = 10.5 } = sectionBreakConfig;
13535
13678
  const { snapToGrid = _univerjs_core.BooleanNumber.TRUE } = paragraphStyle;
13536
13679
  const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
13537
13680
  const bulletGlyph = createSkeletonBulletGlyph(glyphGroup[0], bulletSkeleton, charSpaceApply);
13538
13681
  const paragraphProperties = bulletSkeleton.paragraphProperties || {};
13539
- paragraphConfig.paragraphStyle = mergeByV(paragraphConfig.paragraphStyle, {
13682
+ paragraphConfig.paragraphStyle = {
13540
13683
  ...paragraphProperties,
13541
- hanging: { v: bulletGlyph.width }
13542
- }, "max");
13684
+ hanging: (_paragraphProperties$ = paragraphProperties.hanging) !== null && _paragraphProperties$ !== void 0 ? _paragraphProperties$ : { v: bulletGlyph.width },
13685
+ ...paragraphConfig.paragraphStyle
13686
+ };
13543
13687
  _lineOperator(ctx, [bulletGlyph, ...glyphGroup], pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);
13544
13688
  } else _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);
13545
13689
  else _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);
@@ -13568,6 +13712,11 @@ function isGlyphGroupBeyondContentBox(glyphGroup, left, divideWidth) {
13568
13712
  }
13569
13713
  return isBeyondContentBox;
13570
13714
  }
13715
+ function shouldKeepOverflowingTextOnLine(sectionBreakConfig) {
13716
+ var _sectionBreakConfig$r;
13717
+ const wrapStrategy = (_sectionBreakConfig$r = sectionBreakConfig.renderConfig) === null || _sectionBreakConfig$r === void 0 ? void 0 : _sectionBreakConfig$r.wrapStrategy;
13718
+ return wrapStrategy === _univerjs_core.WrapStrategy.CLIP || wrapStrategy === _univerjs_core.WrapStrategy.OVERFLOW;
13719
+ }
13571
13720
  function _getConsecutiveHyphenLineCount(divide) {
13572
13721
  var _divide$parent;
13573
13722
  const column = (_divide$parent = divide.parent) === null || _divide$parent === void 0 ? void 0 : _divide$parent.parent;
@@ -13603,12 +13752,20 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13603
13752
  const preOffsetLeft = ((lastGlyph === null || lastGlyph === void 0 ? void 0 : lastGlyph.width) || 0) + ((lastGlyph === null || lastGlyph === void 0 ? void 0 : lastGlyph.left) || 0);
13604
13753
  const { hyphenationZone } = sectionBreakConfig;
13605
13754
  if (preOffsetLeft + width > divide.width) {
13755
+ if (shouldKeepOverflowingTextOnLine(sectionBreakConfig)) {
13756
+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13757
+ updateDivideInfo(divide, { breakType: breakPointType });
13758
+ return;
13759
+ }
13606
13760
  updateDivideInfo(divide, { isFull: true });
13607
13761
  const hyphenLineCount = _getConsecutiveHyphenLineCount(divideInfo.divide);
13608
13762
  const { consecutiveHyphenLimit = Number.POSITIVE_INFINITY } = sectionBreakConfig;
13609
13763
  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
13764
  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) {
13765
+ else if (!isLast && (divide === null || divide === void 0 ? void 0 : divide.glyphGroup.length) === 0 && glyphGroup.length === 1 && glyphGroup[0].streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyphGroup[0].width > divide.width) {
13766
+ updateDivideInfo(divide, { isFull: true });
13767
+ _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType, defaultSpanLineHeight);
13768
+ } else if ((divide === null || divide === void 0 ? void 0 : divide.glyphGroup.length) === 0) {
13612
13769
  const sliceGlyphGroup = [];
13613
13770
  while (glyphGroup.length) {
13614
13771
  sliceGlyphGroup.push(glyphGroup.shift());
@@ -13633,11 +13790,16 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13633
13790
  } else {
13634
13791
  const currentLine = divide.parent;
13635
13792
  const maxBox = __maxFontBoundingBoxByGlyphGroup(glyphGroup);
13636
- if (currentLine && maxBox && !__isNullLine(currentLine)) {
13793
+ if (currentLine && __isZeroWidthNonFlowFloatingAnchorLine(__getGlyphGroupByLine(currentLine), paragraphConfig.paragraphNonInlineSkeDrawings) && __hasFlowGlyph(glyphGroup)) {
13794
+ for (const lineDivide of currentLine.divides) updateDivideInfo(lineDivide, { isFull: true });
13795
+ _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, false, breakPointType);
13796
+ return;
13797
+ }
13798
+ if (currentLine && maxBox && !__isNullLine(currentLine) && __hasFlowGlyph(__getGlyphGroupByLine(currentLine)) && !__isZeroWidthNonFlowFloatingAnchorLine(glyphGroup, paragraphConfig.paragraphNonInlineSkeDrawings)) {
13637
13799
  const { paragraphLineGapDefault, linePitch, lineSpacing, spacingRule, snapToGrid, gridType } = getLineHeightConfig(sectionBreakConfig, paragraphConfig);
13638
13800
  const { boundingBoxAscent, boundingBoxDescent } = maxBox;
13639
- const { contentHeight } = __getLineHeight(boundingBoxAscent + boundingBoxDescent, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid);
13640
- if (currentLine.contentHeight < contentHeight) {
13801
+ const { contentHeight } = getLineHeightMetrics(boundingBoxAscent + boundingBoxDescent, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid, paragraphConfig.useWordStyleLineHeight);
13802
+ if (contentHeight - currentLine.contentHeight > LINE_LAYOUT_OVERFLOW_TOLERANCE) {
13641
13803
  const spanGroupCached = __getGlyphGroupByLine(currentLine);
13642
13804
  const spanGroupCachedLen = spanGroupCached.length;
13643
13805
  let newGlyphGroup = [];
@@ -13653,6 +13815,15 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13653
13815
  return;
13654
13816
  }
13655
13817
  }
13818
+ if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.parent) {
13819
+ const anchorDrawings = __getZeroWidthNonFlowFloatingAnchorDrawings(glyphGroup, paragraphConfig.paragraphNonInlineSkeDrawings);
13820
+ if (anchorDrawings.length > 0) {
13821
+ var _paragraphConfig$para, _paragraphConfig$pDra;
13822
+ const paragraphAnchorLeft = __getParagraphAnchorLeft(sectionBreakConfig, paragraphConfig, (_paragraphConfig$para = paragraphConfig.paragraphStyle) === null || _paragraphConfig$para === void 0 ? void 0 : _paragraphConfig$para.indentStart);
13823
+ const drawings = __getDrawingPosition(currentLine.top, currentLine.lineHeight, currentLine.parent, true, (_paragraphConfig$pDra = paragraphConfig.pDrawingAnchor) === null || _paragraphConfig$pDra === void 0 || (_paragraphConfig$pDra = _paragraphConfig$pDra.get(paragraphConfig.paragraphIndex)) === null || _paragraphConfig$pDra === void 0 ? void 0 : _paragraphConfig$pDra.top, anchorDrawings, paragraphAnchorLeft);
13824
+ __updateDrawingPosition(currentLine.parent, drawings);
13825
+ }
13826
+ }
13656
13827
  addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13657
13828
  updateDivideInfo(divide, { breakType: breakPointType });
13658
13829
  }
@@ -13678,6 +13849,7 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13678
13849
  const descent = Math.max(...glyphGroup.map((glyph) => glyph.bBox.bd));
13679
13850
  const glyphLineHeight = defaultGlyphLineHeight || ascent + descent;
13680
13851
  const { paragraphStyle: originParagraphStyle = {}, paragraphNonInlineSkeDrawings, skeTablesInParagraph, skeHeaders, skeFooters, pDrawingAnchor, paragraphIndex } = paragraphConfig;
13852
+ const isZeroWidthNonFlowFloatingAnchorLine = __isZeroWidthNonFlowFloatingAnchorLine(glyphGroup, paragraphNonInlineSkeDrawings);
13681
13853
  const { namedStyleType } = originParagraphStyle;
13682
13854
  const namedStyle = namedStyleType !== void 0 ? _univerjs_core.NAMED_STYLE_SPACE_MAP[namedStyleType] : null;
13683
13855
  const { spaceAbove, spaceBelow, indentFirstLine, hanging, indentStart, indentEnd } = {
@@ -13686,9 +13858,22 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13686
13858
  spaceBelow: (_originParagraphStyle2 = originParagraphStyle.spaceBelow) !== null && _originParagraphStyle2 !== void 0 ? _originParagraphStyle2 : namedStyle === null || namedStyle === void 0 ? void 0 : namedStyle.spaceBelow
13687
13859
  };
13688
13860
  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);
13861
+ const hasInlineCustomBlock = glyphGroup.some((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.width !== 0);
13862
+ const glyphGroupCustomBlockIds = new Set(glyphGroup.filter((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.drawingId != null).map((glyph) => glyph.drawingId));
13863
+ let { paddingTop, paddingBottom, contentHeight, lineSpacingApply } = getLineHeightMetrics(glyphLineHeight, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid, paragraphConfig.useWordStyleLineHeight, !hasInlineCustomBlock);
13864
+ let { marginTop, spaceBelowApply } = __getParagraphSpace(ctx, lineSpacingApply, spaceAbove, spaceBelow, isParagraphFirstShapedText, preLine);
13865
+ if (isZeroWidthNonFlowFloatingAnchorLine) {
13866
+ paddingTop = 0;
13867
+ paddingBottom = 0;
13868
+ contentHeight = 0;
13869
+ lineSpacingApply = 0;
13870
+ marginTop = 0;
13871
+ spaceBelowApply = 0;
13872
+ }
13691
13873
  const lineHeight = marginTop + paddingTop + contentHeight + paddingBottom;
13874
+ const { charSpace, defaultTabStop } = getCharSpaceConfig(sectionBreakConfig, paragraphConfig);
13875
+ const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
13876
+ const paragraphAnchorLeft = __getParagraphAnchorLeft(sectionBreakConfig, paragraphConfig, indentStart);
13692
13877
  let section = column.parent;
13693
13878
  if (!section) section = getLastSection(lastPage);
13694
13879
  const lineTop = ((preLine === null || preLine === void 0 ? void 0 : preLine.lineHeight) || 0) + ((preLine === null || preLine === void 0 ? void 0 : preLine.top) || 0);
@@ -13705,16 +13890,22 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13705
13890
  if (relativeLineDrawings.length > 0) __updateAndPositionDrawings(ctx, preLine.top, preLine.lineHeight, column, relativeLineDrawings, preLine.paragraphIndex, isParagraphFirstShapedText);
13706
13891
  }
13707
13892
  }
13893
+ let deferredInlineGroupAnchorDrawings = [];
13708
13894
  if (paragraphNonInlineSkeDrawings != null && paragraphNonInlineSkeDrawings.size > 0) {
13709
13895
  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);
13896
+ let targetDrawings = [...paragraphNonInlineSkeDrawings.values()].filter((drawing) => drawing.drawingOrigin.docTransform.positionV.relativeFrom !== _univerjs_core.ObjectRelativeFromV.LINE);
13897
+ if (hasInlineCustomBlock) {
13898
+ deferredInlineGroupAnchorDrawings = targetDrawings.filter((drawing) => glyphGroupCustomBlockIds.has(drawing.drawingId) && drawing.drawingOrigin.docTransform.positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE);
13899
+ targetDrawings = targetDrawings.filter((drawing) => !deferredInlineGroupAnchorDrawings.includes(drawing));
13900
+ }
13901
+ __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
13902
  }
13712
13903
  if (skeTablesInParagraph != null && skeTablesInParagraph.length > 0) {
13713
13904
  var _pDrawingAnchor$get2;
13714
13905
  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
13906
  }
13716
13907
  const newLineTop = calculateLineTopByDrawings(lineHeight, lineTop, lastPage, headerPage, footerPage);
13717
- if (lineHeight + newLineTop > section.height && column.lines.length > 0 && lastPage.sections.length > 0 || needOpenNewPageByTableLayout) {
13908
+ if (lineHeight + newLineTop - section.height > LINE_LAYOUT_OVERFLOW_TOLERANCE && column.lines.length > 0 && lastPage.sections.length > 0 || needOpenNewPageByTableLayout) {
13718
13909
  setColumnFullState(column, true);
13719
13910
  _columnOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType, defaultGlyphLineHeight);
13720
13911
  if (isParagraphFirstShapedText && paragraphNonInlineSkeDrawings && paragraphNonInlineSkeDrawings.size > 0) for (const drawing of paragraphNonInlineSkeDrawings.values()) {
@@ -13728,8 +13919,7 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13728
13919
  return;
13729
13920
  }
13730
13921
  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);
13922
+ let { paddingLeft, paddingRight } = __getIndentPadding(indentFirstLine, hanging, indentStart, indentEnd, charSpaceApply, isParagraphFirstShapedText);
13733
13923
  if (paddingLeft + paddingRight >= column.width) {
13734
13924
  const leftPercent = paddingLeft / (paddingLeft + paddingRight);
13735
13925
  paddingLeft = column.width * leftPercent - .5;
@@ -13750,12 +13940,16 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
13750
13940
  newLine.parent = column;
13751
13941
  createAndUpdateBlockAnchor(paragraphIndex, newLine, lineTop, pDrawingAnchor);
13752
13942
  _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType, defaultGlyphLineHeight);
13943
+ if (deferredInlineGroupAnchorDrawings.length > 0) {
13944
+ var _pDrawingAnchor$get3;
13945
+ __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);
13946
+ }
13753
13947
  }
13754
- function __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDrawings, paragraphIndex, isParagraphFirstShapedText, drawingAnchorTop) {
13948
+ function __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDrawings, paragraphIndex, isParagraphFirstShapedText, drawingAnchorTop, drawingAnchorLeft = 0, skipRelayoutCheck = false) {
13755
13949
  if (targetDrawings.length === 0) return;
13756
- const drawings = __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, drawingAnchorTop, targetDrawings);
13950
+ const drawings = __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, drawingAnchorTop, targetDrawings, drawingAnchorLeft);
13757
13951
  if (drawings == null || drawings.size === 0) return;
13758
- _reLayoutCheck(ctx, [...drawings.values()].filter((drawing) => {
13952
+ const floatObjects = [...drawings.values()].filter((drawing) => {
13759
13953
  const layoutType = drawing.drawingOrigin.layoutType;
13760
13954
  return layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE && layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE;
13761
13955
  }).map((drawing) => {
@@ -13768,10 +13962,13 @@ function __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDra
13768
13962
  width,
13769
13963
  height,
13770
13964
  angle,
13965
+ behindDoc: drawingOrigin.behindDoc,
13966
+ layoutType: drawingOrigin.layoutType,
13771
13967
  type: "IMAGE",
13772
13968
  positionV
13773
13969
  };
13774
- }), column, paragraphIndex);
13970
+ });
13971
+ if (!skipRelayoutCheck) _reLayoutCheck(ctx, floatObjects, column, paragraphIndex);
13775
13972
  __updateDrawingPosition(column, drawings);
13776
13973
  }
13777
13974
  function __updateWrapTablePosition(ctx, table, lineTop, lineHeight, column, paragraphIndex, drawingAnchorTop) {
@@ -13804,6 +14001,22 @@ function __getWrapTablePosition(table, column, lineTop, lineHeight, drawingAncho
13804
14001
  top: (_getPositionVertical = getPositionVertical(positionV, page, lineTop, lineHeight, height, drawingAnchorTop, isPageBreak)) !== null && _getPositionVertical !== void 0 ? _getPositionVertical : 0
13805
14002
  };
13806
14003
  }
14004
+ function __avoidFlowAffectingDrawingsForTable(table, page, column) {
14005
+ const tableTop = table.top;
14006
+ const tableBottom = table.top + table.height;
14007
+ const tableRight = table.left + table.width;
14008
+ for (const drawing of page.skeDrawings.values()) {
14009
+ var _drawingOrigin$distR;
14010
+ const drawingOrigin = drawing.drawingOrigin;
14011
+ 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;
14012
+ const drawingTop = drawing.aTop;
14013
+ const drawingBottom = drawing.aTop + drawing.height;
14014
+ if (drawingTop >= tableBottom || drawingBottom <= tableTop) continue;
14015
+ const drawingRight = drawing.aLeft + drawing.width + ((_drawingOrigin$distR = drawingOrigin.distR) !== null && _drawingOrigin$distR !== void 0 ? _drawingOrigin$distR : 0);
14016
+ if (drawing.aLeft >= tableRight || drawingRight <= table.left) continue;
14017
+ if (drawingRight + table.width <= column.width) table.left = Math.max(table.left, drawingRight);
14018
+ }
14019
+ }
13807
14020
  function _updateAndPositionTable(ctx, lineTop, lineHeight, page, column, section, skeTablesInParagraph, paragraphIndex, sectionBreakConfig, drawingAnchorTop) {
13808
14021
  if (skeTablesInParagraph.length === 0) return false;
13809
14022
  const firstUnPositionedTable = skeTablesInParagraph.find((table) => table.hasPositioned === false);
@@ -13813,6 +14026,7 @@ function _updateAndPositionTable(ctx, lineTop, lineHeight, page, column, section
13813
14026
  if (firstUnPositionedTable.isSlideTable === false) switch (tableSource.textWrap) {
13814
14027
  case _univerjs_core.TableTextWrapType.NONE:
13815
14028
  table.top = lineTop;
14029
+ __avoidFlowAffectingDrawingsForTable(table, page, column);
13816
14030
  break;
13817
14031
  case _univerjs_core.TableTextWrapType.WRAP:
13818
14032
  __updateWrapTablePosition(ctx, table, lineTop, lineHeight, column, paragraphIndex, drawingAnchorTop);
@@ -13866,15 +14080,47 @@ function _getCustomBlockIdsInLine(line) {
13866
14080
  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
14081
  return customBlockIds;
13868
14082
  }
14083
+ function __isZeroWidthNonFlowFloatingAnchorLine(glyphGroup, paragraphNonInlineSkeDrawings) {
14084
+ return __getZeroWidthNonFlowFloatingAnchorDrawings(glyphGroup, paragraphNonInlineSkeDrawings).length > 0;
14085
+ }
14086
+ function __getZeroWidthNonFlowFloatingAnchorDrawings(glyphGroup, paragraphNonInlineSkeDrawings) {
14087
+ const drawings = [];
14088
+ for (const glyph of glyphGroup) {
14089
+ if (__isStructuralTerminatorGlyph(glyph)) continue;
14090
+ if (__isIgnorableZeroSizeGlyph(glyph)) continue;
14091
+ if (glyph.streamType !== _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK || glyph.width !== 0 || glyph.drawingId == null) return [];
14092
+ const drawing = paragraphNonInlineSkeDrawings === null || paragraphNonInlineSkeDrawings === void 0 ? void 0 : paragraphNonInlineSkeDrawings.get(glyph.drawingId);
14093
+ const drawingOrigin = drawing === null || drawing === void 0 ? void 0 : drawing.drawingOrigin;
14094
+ if (drawing == null || drawingOrigin == null) return [];
14095
+ if (drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE) return [];
14096
+ drawings.push(drawing);
14097
+ }
14098
+ return drawings;
14099
+ }
14100
+ function __isIgnorableZeroSizeGlyph(glyph) {
14101
+ return glyph.content === "" && glyph.drawingId == null && glyph.width === 0 && glyph.bBox.ba + glyph.bBox.bd === 0;
14102
+ }
14103
+ function __isStructuralTerminatorGlyph(glyph) {
14104
+ return glyph.streamType === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH || glyph.streamType === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK || glyph.streamType === _univerjs_core.DataStreamTreeTokenType.DOCS_END;
14105
+ }
14106
+ function __hasFlowGlyph(glyphGroup) {
14107
+ return glyphGroup.some((glyph) => {
14108
+ if (__isStructuralTerminatorGlyph(glyph)) return false;
14109
+ if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK) return glyph.width !== 0;
14110
+ return glyph.content !== "" || glyph.width > 0 || glyph.bBox.ba + glyph.bBox.bd > 0;
14111
+ });
14112
+ }
13869
14113
  function _reLayoutCheck(ctx, floatObjects, column, paragraphIndex) {
13870
14114
  var _column$parent2;
13871
14115
  const page = (_column$parent2 = column.parent) === null || _column$parent2 === void 0 ? void 0 : _column$parent2.parent;
13872
- if (floatObjects.length === 0 || page == null) return;
14116
+ const flowAffectingFloatObjects = floatObjects.filter((floatObject) => floatObject.behindDoc !== _univerjs_core.BooleanNumber.TRUE || floatObject.layoutType != null && floatObject.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE);
14117
+ if (flowAffectingFloatObjects.length === 0 || page == null) return;
13873
14118
  let needBreakLineIterator = false;
13874
- for (const floatObject of floatObjects) {
14119
+ for (const floatObject of flowAffectingFloatObjects) {
13875
14120
  var _floatObjectCache$pag, _page$sections$;
13876
14121
  const floatObjectCache = ctx.floatObjectsCache.get(floatObject.id);
13877
14122
  if (floatObjectCache == null || floatObjectCache.page.segmentId !== page.segmentId) continue;
14123
+ if (floatObjectCache.count >= FLOAT_OBJECT_RELAYOUT_LIMIT) continue;
13878
14124
  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
14125
  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
14126
  if (floatObjectCache.page && cachePageStartParagraphIndex && startIndex && cachePageStartParagraphIndex !== startIndex) {
@@ -13900,7 +14146,7 @@ function _reLayoutCheck(ctx, floatObjects, column, paragraphIndex) {
13900
14146
  const { lineHeight, top } = line;
13901
14147
  const { width: columnWidth, left: columnLeft } = column;
13902
14148
  if (needBreakLineIterator) return;
13903
- for (const floatObject of floatObjects.values()) {
14149
+ for (const floatObject of flowAffectingFloatObjects.values()) {
13904
14150
  let targetObject = floatObject;
13905
14151
  if (ctx.floatObjectsCache.has(floatObject.id)) {
13906
14152
  const drawingCache = ctx.floatObjectsCache.get(floatObject.id);
@@ -13938,7 +14184,7 @@ function checkRelativeDrawingNeedRePosition(ctx, floatObject) {
13938
14184
  if (drawingCache == null) return false;
13939
14185
  if (relativeFrom === _univerjs_core.ObjectRelativeFromV.PARAGRAPH || relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE) {
13940
14186
  const { count, floatObject: prevObject } = drawingCache;
13941
- if (count < 5 && Math.abs(floatObject.top - prevObject.top) > 5) return true;
14187
+ if (count < FLOAT_OBJECT_RELAYOUT_LIMIT && Math.abs(floatObject.top - prevObject.top) > 5) return true;
13942
14188
  }
13943
14189
  return false;
13944
14190
  }
@@ -13995,43 +14241,87 @@ function __getParagraphSpace(ctx, lineSpacing = 0, spaceAbove, spaceBelow, isPar
13995
14241
  spaceBelowApply
13996
14242
  };
13997
14243
  }
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 {
14244
+ function __getParagraphAnchorLeft(sectionBreakConfig, paragraphConfig, indentStart) {
14245
+ const { paragraphStyle = {} } = paragraphConfig;
14246
+ const { snapToGrid = _univerjs_core.BooleanNumber.TRUE } = paragraphStyle;
14247
+ const { gridType = _univerjs_core.GridType.LINES } = sectionBreakConfig;
14248
+ const { charSpace, defaultTabStop } = getCharSpaceConfig(sectionBreakConfig, paragraphConfig);
14249
+ const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
14250
+ const paragraphAnchorLeft = getNumberUnitValue(indentStart, charSpaceApply);
14251
+ if (paragraphAnchorLeft > 0) return paragraphAnchorLeft;
14252
+ return getNumberUnitValue(paragraphConfig.docxFallbackAnchorLeft, charSpaceApply);
14253
+ }
14254
+ function getLineHeightMetrics(glyphLineHeight, paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid, useWordStyleLineHeight = true, scaleAutoLineSpacingByGlyphHeight = true) {
14255
+ if (!useWordStyleLineHeight) {
14256
+ let paddingTop = paragraphLineGapDefault;
14257
+ let paddingBottom = paragraphLineGapDefault;
14258
+ if (gridType === _univerjs_core.GridType.DEFAULT || snapToGrid === _univerjs_core.BooleanNumber.FALSE) {
14259
+ if (spacingRule === _univerjs_core.SpacingRule.AUTO) return {
14260
+ paddingTop,
14261
+ paddingBottom,
14262
+ contentHeight: lineSpacing * glyphLineHeight,
14263
+ lineSpacingApply: glyphLineHeight
14264
+ };
14265
+ return {
14266
+ paddingTop,
14267
+ paddingBottom,
14268
+ contentHeight: Math.max(lineSpacing, glyphLineHeight),
14269
+ lineSpacingApply: lineSpacing
14270
+ };
14271
+ }
14272
+ let lineSpacingApply = 0;
14273
+ if (spacingRule === _univerjs_core.SpacingRule.AUTO) lineSpacingApply = lineSpacing * linePitch;
14274
+ else lineSpacingApply = lineSpacing;
14275
+ if (glyphLineHeight + paragraphLineGapDefault * 2 < lineSpacingApply) paddingTop = paddingBottom = (lineSpacingApply - glyphLineHeight) / 2;
14276
+ else lineSpacingApply = glyphLineHeight;
14277
+ return {
14003
14278
  paddingTop,
14004
14279
  paddingBottom,
14005
- contentHeight: lineSpacing * glyphLineHeight,
14006
- lineSpacingApply: glyphLineHeight
14280
+ contentHeight: glyphLineHeight,
14281
+ lineSpacingApply
14007
14282
  };
14283
+ }
14284
+ const usesDocumentGrid = spacingRule === _univerjs_core.SpacingRule.AUTO && snapToGrid === _univerjs_core.BooleanNumber.TRUE && gridType !== _univerjs_core.GridType.DEFAULT;
14285
+ if (spacingRule === _univerjs_core.SpacingRule.AUTO) {
14286
+ const lineSpacingApply = usesDocumentGrid ? lineSpacing * linePitch : scaleAutoLineSpacingByGlyphHeight ? lineSpacing * glyphLineHeight : glyphLineHeight;
14287
+ const padding = (lineSpacingApply - glyphLineHeight) / 2;
14008
14288
  return {
14009
- paddingTop,
14010
- paddingBottom,
14011
- contentHeight: Math.max(lineSpacing, glyphLineHeight),
14012
- lineSpacingApply: lineSpacing
14289
+ paddingTop: padding,
14290
+ paddingBottom: padding,
14291
+ contentHeight: glyphLineHeight,
14292
+ lineSpacingApply
14293
+ };
14294
+ }
14295
+ if (spacingRule === _univerjs_core.SpacingRule.AT_LEAST) {
14296
+ const lineSpacingApply = Math.max(lineSpacing, glyphLineHeight);
14297
+ const padding = (lineSpacingApply - glyphLineHeight) / 2;
14298
+ return {
14299
+ paddingTop: padding,
14300
+ paddingBottom: padding,
14301
+ contentHeight: glyphLineHeight,
14302
+ lineSpacingApply
14013
14303
  };
14014
14304
  }
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;
14305
+ const exactLineSpacingApply = snapToGrid === _univerjs_core.BooleanNumber.TRUE && gridType !== _univerjs_core.GridType.DEFAULT ? Math.max(lineSpacing, linePitch) : lineSpacing;
14306
+ const exactPadding = (exactLineSpacingApply - glyphLineHeight) / 2;
14020
14307
  return {
14021
- paddingTop,
14022
- paddingBottom,
14308
+ paddingTop: exactPadding,
14309
+ paddingBottom: exactPadding,
14023
14310
  contentHeight: glyphLineHeight,
14024
- lineSpacingApply
14311
+ lineSpacingApply: exactLineSpacingApply
14025
14312
  };
14026
14313
  }
14027
- function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnchorTop) {
14028
- var _line$parent;
14314
+ function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnchorTop, paragraphNonInlineSkeDrawings) {
14315
+ var _line$parent, _section$top;
14029
14316
  const column = line.parent;
14317
+ const section = column === null || column === void 0 ? void 0 : column.parent;
14030
14318
  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
14319
  if (page == null || column == null) return;
14032
14320
  const isPageBreak = __checkPageBreak(column);
14033
14321
  const drawings = /* @__PURE__ */ new Map();
14034
14322
  const { top, lineHeight, marginBottom = 0 } = line;
14323
+ const sectionTop = (_section$top = section === null || section === void 0 ? void 0 : section.top) !== null && _section$top !== void 0 ? _section$top : 0;
14324
+ const lineTop = sectionTop + top;
14035
14325
  for (const divide of line.divides) for (const glyph of divide.glyphGroup) if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.width !== 0) {
14036
14326
  const { drawingId } = glyph;
14037
14327
  if (drawingId == null) continue;
@@ -14042,21 +14332,37 @@ function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnch
14042
14332
  const { size, angle } = docTransform;
14043
14333
  const { width = 0, height = 0 } = size;
14044
14334
  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;
14335
+ drawing.aLeft = column.left + divide.left + divide.paddingLeft + glyph.left + .5 * glyph.width - .5 * width || 0;
14336
+ if (glyph.width > divide.width) {
14337
+ var _paragraphNonInlineSk;
14338
+ for (const positionedDrawing of (_paragraphNonInlineSk = paragraphNonInlineSkeDrawings === null || paragraphNonInlineSkeDrawings === void 0 ? void 0 : paragraphNonInlineSkeDrawings.values()) !== null && _paragraphNonInlineSk !== void 0 ? _paragraphNonInlineSk : []) {
14339
+ const positionedOrigin = positionedDrawing.drawingOrigin;
14340
+ 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;
14341
+ const positionedBottom = positionedDrawing.aTop + positionedDrawing.height;
14342
+ const lineBottom = lineTop + lineHeight;
14343
+ if (positionedDrawing.aTop >= lineBottom || positionedBottom <= lineTop) continue;
14344
+ const positionedRight = positionedDrawing.aLeft + positionedDrawing.width;
14345
+ const drawingRight = drawing.aLeft + width;
14346
+ if (positionedDrawing.aLeft < drawingRight && positionedRight > drawing.aLeft) {
14347
+ var _positionedOrigin$dis;
14348
+ drawing.aLeft = Math.max(drawing.aLeft, positionedDrawing.aLeft + positionedDrawing.width + ((_positionedOrigin$dis = positionedOrigin.distR) !== null && _positionedOrigin$dis !== void 0 ? _positionedOrigin$dis : 0));
14349
+ }
14350
+ }
14351
+ }
14352
+ drawing.aTop = lineTop + lineHeight - .5 * glyphHeight - .5 * height - marginBottom;
14047
14353
  drawing.width = width;
14048
14354
  drawing.height = height;
14049
14355
  drawing.angle = angle;
14050
14356
  drawing.isPageBreak = isPageBreak;
14051
- drawing.lineTop = top;
14357
+ drawing.lineTop = lineTop;
14052
14358
  drawing.columnLeft = column.left;
14053
- drawing.blockAnchorTop = blockAnchorTop !== null && blockAnchorTop !== void 0 ? blockAnchorTop : top;
14359
+ drawing.blockAnchorTop = blockAnchorTop == null ? lineTop : sectionTop + blockAnchorTop;
14054
14360
  drawing.lineHeight = line.lineHeight;
14055
14361
  drawings.set(drawing.drawingId, drawing);
14056
14362
  }
14057
14363
  page.skeDrawings = new Map([...page.skeDrawings, ...drawings]);
14058
14364
  }
14059
- function __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, blockAnchorTop, needPositionDrawings = []) {
14365
+ function __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, blockAnchorTop, needPositionDrawings = [], blockAnchorLeft = 0) {
14060
14366
  var _column$parent3;
14061
14367
  const page = (_column$parent3 = column.parent) === null || _column$parent3 === void 0 ? void 0 : _column$parent3.parent;
14062
14368
  if (page == null || needPositionDrawings.length === 0) return;
@@ -14070,7 +14376,12 @@ function __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShape
14070
14376
  const { docTransform } = drawingOrigin;
14071
14377
  const { positionH, positionV, size, angle } = docTransform;
14072
14378
  const { width = 0, height = 0 } = size;
14073
- drawing.aLeft = (_getPositionHorizon2 = getPositionHorizon(positionH, column, page, width, isPageBreak)) !== null && _getPositionHorizon2 !== void 0 ? _getPositionHorizon2 : 0;
14379
+ let aLeft = (_getPositionHorizon2 = getPositionHorizon(positionH, column, page, width, isPageBreak)) !== null && _getPositionHorizon2 !== void 0 ? _getPositionHorizon2 : 0;
14380
+ if (positionH.relativeFrom === _univerjs_core.ObjectRelativeFromH.COLUMN && blockAnchorLeft > 0) {
14381
+ const renderedColumnOrigin = isPageBreak ? 0 : column.left || page.marginLeft;
14382
+ aLeft += blockAnchorLeft - renderedColumnOrigin;
14383
+ }
14384
+ drawing.aLeft = aLeft;
14074
14385
  drawing.aTop = (_getPositionVertical2 = getPositionVertical(positionV, page, lineTop, lineHeight, height, blockAnchorTop, isPageBreak)) !== null && _getPositionVertical2 !== void 0 ? _getPositionVertical2 : 0;
14075
14386
  drawing.width = width;
14076
14387
  drawing.height = height;
@@ -14139,7 +14450,7 @@ function __getGlyphGroupByLine({ divides }) {
14139
14450
  return divides.flatMap((divide) => divide.glyphGroup);
14140
14451
  }
14141
14452
  function __isNullLine(line) {
14142
- return !line.divides[0].glyphGroup[0];
14453
+ return __getGlyphGroupByLine(line).every((glyph) => !glyph.content && !glyph.drawingId);
14143
14454
  }
14144
14455
 
14145
14456
  //#endregion
@@ -14222,6 +14533,7 @@ function isColumnFull(page) {
14222
14533
  function getNumberUnitValue(unitValue, benchMark) {
14223
14534
  if (!unitValue) return 0;
14224
14535
  const { v: value, u: unit } = unitValue;
14536
+ if (typeof value !== "number" || !Number.isFinite(value)) return 0;
14225
14537
  if (!unit) return value;
14226
14538
  if (unit === _univerjs_core.NumberUnitType.PIXEL) return value;
14227
14539
  return value * benchMark;
@@ -14236,18 +14548,22 @@ function validationGrid(gridType = _univerjs_core.GridType.LINES, snapToGrid = _
14236
14548
  return snapToGrid === _univerjs_core.BooleanNumber.TRUE && (gridType === _univerjs_core.GridType.LINES_AND_CHARS || gridType === _univerjs_core.GridType.SNAP_TO_CHARS);
14237
14549
  }
14238
14550
  function getLineHeightConfig(sectionBreakConfig, paragraphConfig) {
14239
- const { paragraphStyle = {} } = paragraphConfig;
14551
+ const { paragraphStyle = {}, useWordStyleLineHeight = false } = paragraphConfig;
14240
14552
  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;
14553
+ const hasDocumentGrid = gridType === _univerjs_core.GridType.LINES_AND_CHARS || gridType === _univerjs_core.GridType.SNAP_TO_CHARS;
14554
+ const defaultSnapToGrid = useWordStyleLineHeight && !hasDocumentGrid ? _univerjs_core.BooleanNumber.FALSE : _univerjs_core.BooleanNumber.TRUE;
14555
+ const { lineSpacing = 0, spacingRule = _univerjs_core.SpacingRule.AUTO, snapToGrid = defaultSnapToGrid } = paragraphStyle;
14242
14556
  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;
14557
+ if (useWordStyleLineHeight && lineSpacing === 0 && spacingRule === _univerjs_core.SpacingRule.AUTO) lineSpacingApply = 1;
14558
+ 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
14559
  return {
14245
14560
  paragraphLineGapDefault,
14246
14561
  linePitch,
14247
14562
  gridType,
14248
14563
  lineSpacing: lineSpacingApply,
14249
14564
  spacingRule,
14250
- snapToGrid
14565
+ snapToGrid,
14566
+ useWordStyleLineHeight
14251
14567
  };
14252
14568
  }
14253
14569
  function getCharSpaceConfig(sectionBreakConfig, paragraphConfig) {
@@ -14354,13 +14670,16 @@ function updateBlockIndex(pages, start = -1) {
14354
14670
  }
14355
14671
  function updateInlineDrawingCoordsAndBorder(ctx, pages) {
14356
14672
  lineIterator(pages, (line, _, __, page) => {
14357
- var _ctx$paragraphConfigC, _ctx$skeletonResource;
14673
+ var _ctx$paragraphConfigC, _ctx$skeletonResource, _paragraphStyle$shadi;
14358
14674
  const { segmentId } = page;
14359
14675
  const paragraphConfig = (_ctx$paragraphConfigC = ctx.paragraphConfigCache.get(segmentId)) === null || _ctx$paragraphConfigC === void 0 ? void 0 : _ctx$paragraphConfigC.get(line.paragraphIndex);
14360
14676
  const affectInlineDrawings = paragraphConfig === null || paragraphConfig === void 0 ? void 0 : paragraphConfig.paragraphInlineSkeDrawings;
14677
+ const affectNonInlineDrawings = paragraphConfig === null || paragraphConfig === void 0 ? void 0 : paragraphConfig.paragraphNonInlineSkeDrawings;
14361
14678
  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);
14679
+ if (affectInlineDrawings && affectInlineDrawings.size > 0) updateInlineDrawingPosition(line, affectInlineDrawings, drawingAnchor === null || drawingAnchor === void 0 ? void 0 : drawingAnchor.top, affectNonInlineDrawings);
14363
14680
  const paragraphStyle = paragraphConfig === null || paragraphConfig === void 0 ? void 0 : paragraphConfig.paragraphStyle;
14681
+ const paragraphBackgroundColor = paragraphStyle === null || paragraphStyle === void 0 || (_paragraphStyle$shadi = paragraphStyle.shading) === null || _paragraphStyle$shadi === void 0 ? void 0 : _paragraphStyle$shadi.backgroundColor;
14682
+ if (paragraphBackgroundColor) line.backgroundColor = paragraphBackgroundColor;
14364
14683
  if (line.divides.length > 0) {
14365
14684
  const lastDivide = line.divides[line.divides.length - 1];
14366
14685
  const lastGlyph = lastDivide.glyphGroup[lastDivide.glyphGroup.length - 1];
@@ -14430,14 +14749,12 @@ function getPositionHorizon(positionH, column, page, objectWidth, isPageBreak =
14430
14749
  return absoluteLeft;
14431
14750
  }
14432
14751
  }
14433
- else if (posOffset) {
14434
- const { pageWidth, marginLeft, marginRight } = page;
14435
- const boundaryRight = pageWidth - marginRight;
14752
+ else if (posOffset != null) {
14436
14753
  let absoluteLeft = 0;
14754
+ const { marginLeft } = page;
14437
14755
  if (relativeFrom === _univerjs_core.ObjectRelativeFromH.COLUMN) absoluteLeft = (isPageBreak ? 0 : (column === null || column === void 0 ? void 0 : column.left) || 0) + posOffset;
14438
14756
  else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.LEFT_MARGIN) {} else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.MARGIN) absoluteLeft = posOffset + marginLeft;
14439
14757
  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
14758
  return absoluteLeft;
14442
14759
  } else if (percent) {
14443
14760
  const { pageWidth, marginLeft, marginRight } = page;
@@ -14499,9 +14816,9 @@ function getFontConfigFromLastGlyph(glyph, sectionBreakConfig, paragraphStyle) {
14499
14816
  };
14500
14817
  }
14501
14818
  function getBulletParagraphTextStyle(bullet, viewModel) {
14502
- var _lists$listType$nesti;
14819
+ var _lists$listType;
14503
14820
  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;
14821
+ 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
14822
  }
14506
14823
  const DEFAULT_TEXT_RUN = {
14507
14824
  ts: {},
@@ -14509,6 +14826,7 @@ const DEFAULT_TEXT_RUN = {
14509
14826
  ed: 0
14510
14827
  };
14511
14828
  function getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig, paragraph) {
14829
+ var _sectionBreakConfig$d;
14512
14830
  const { gridType = _univerjs_core.GridType.LINES, charSpace = 0, documentTextStyle = {}, pageSize = {
14513
14831
  width: Number.POSITIVE_INFINITY,
14514
14832
  height: Number.POSITIVE_INFINITY
@@ -14540,16 +14858,20 @@ function getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig
14540
14858
  ...customRangeStyle,
14541
14859
  ...bulletTextStyle
14542
14860
  };
14861
+ const fontStyle = getFontStyleString(textStyle);
14862
+ const mixTextStyle = {
14863
+ ...documentTextStyle,
14864
+ ...textStyle
14865
+ };
14866
+ const pageWidth = pageSize.width || Number.POSITIVE_INFINITY - marginLeft - marginRight;
14543
14867
  const result = {
14544
- fontStyle: getFontStyleString(textStyle),
14545
- textStyle: {
14546
- ...documentTextStyle,
14547
- ...textStyle
14548
- },
14868
+ fontStyle,
14869
+ textStyle: mixTextStyle,
14549
14870
  charSpace,
14550
14871
  gridType,
14551
14872
  snapToGrid,
14552
- pageWidth: pageSize.width || Number.POSITIVE_INFINITY - marginLeft - marginRight
14873
+ documentCompatibilityPolicy: (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy(),
14874
+ pageWidth
14553
14875
  };
14554
14876
  if (!hasAddonStyle && originTextRun) fontCreateConfigCache.setValue(st, ed, result);
14555
14877
  return result;
@@ -14684,17 +15006,6 @@ function resetContext(ctx) {
14684
15006
  ctx.isDirty = false;
14685
15007
  (_ctx$skeleton$drawing = ctx.skeleton.drawingAnchor) === null || _ctx$skeleton$drawing === void 0 || _ctx$skeleton$drawing.clear();
14686
15008
  }
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
15009
  function getPageFromPath(skeletonData, path) {
14699
15010
  const pathCopy = [...path];
14700
15011
  let page = null;
@@ -14760,7 +15071,7 @@ function createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference,
14760
15071
  header = (_skeHeaders$get2 = skeHeaders.get(headerId)) === null || _skeHeaders$get2 === void 0 ? void 0 : _skeHeaders$get2.get(pageWidth);
14761
15072
  } else if (headerTreeMap && headerTreeMap.has(headerId)) {
14762
15073
  header = _createSkeletonHeaderFooter(ctx, headerTreeMap.get(headerId), sectionBreakConfig, skeletonResourceReference, headerId, true);
14763
- skeHeaders.set(headerId, new Map([[pageWidth, header]]));
15074
+ skeHeaders.set(headerId, /* @__PURE__ */ new Map([[pageWidth, header]]));
14764
15075
  }
14765
15076
  page.headerId = headerId;
14766
15077
  }
@@ -14771,7 +15082,7 @@ function createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference,
14771
15082
  footer = (_skeFooters$get2 = skeFooters.get(footerId)) === null || _skeFooters$get2 === void 0 ? void 0 : _skeFooters$get2.get(pageWidth);
14772
15083
  } else if (footerTreeMap && footerTreeMap.has(footerId)) {
14773
15084
  footer = _createSkeletonHeaderFooter(ctx, footerTreeMap.get(footerId), sectionBreakConfig, skeletonResourceReference, footerId, false);
14774
- skeFooters.set(footerId, new Map([[pageWidth, footer]]));
15085
+ skeFooters.set(footerId, /* @__PURE__ */ new Map([[pageWidth, footer]]));
14775
15086
  }
14776
15087
  page.footerId = footerId;
14777
15088
  }
@@ -14866,9 +15177,22 @@ function createNullCellPage(ctx, sectionBreakConfig, tableConfig, row, col, avai
14866
15177
  const { skeletonResourceReference } = ctx;
14867
15178
  const { cellMargin, tableRows, tableColumns, tableId } = tableConfig;
14868
15179
  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 : {};
15180
+ 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
15181
  const columnSpan = Math.max(1, (_cellConfig$columnSpa = cellConfig.columnSpan) !== null && _cellConfig$columnSpa !== void 0 ? _cellConfig$columnSpa : 1);
14871
15182
  const pageWidth = tableColumns.slice(col, col + columnSpan).reduce((sum, column) => sum + column.size.width.v, 0);
15183
+ if (start.v + end.v >= pageWidth) {
15184
+ const marginWidth = start.v + end.v;
15185
+ const availableMarginWidth = Math.max(0, pageWidth - 1);
15186
+ const startRatio = marginWidth > 0 ? start.v / marginWidth : .5;
15187
+ start = {
15188
+ ...start,
15189
+ v: availableMarginWidth * startRatio
15190
+ };
15191
+ end = {
15192
+ ...end,
15193
+ v: availableMarginWidth - start.v
15194
+ };
15195
+ }
14872
15196
  const pageHeight = maxCellPageHeight;
14873
15197
  const cellSectionBreakConfig = {
14874
15198
  lists,
@@ -14936,11 +15260,8 @@ function applyTrailingCellBlockRangeSpaceBelow(pages, body, cellEndIndex) {
14936
15260
  page.height += lastLine.spaceBelowApply || trailingBlockRangeSpace;
14937
15261
  }
14938
15262
  }
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));
15263
+ function _getVerticalMargin(marginTB, _headerOrFooter, _pageHeight) {
15264
+ return marginTB;
14944
15265
  }
14945
15266
 
14946
15267
  //#endregion
@@ -15053,7 +15374,26 @@ function adjustGlyphsInDivide(divide, justificationRatio, extraJustification) {
15053
15374
  * Therefore, multiple calculations are performed, which may impact performance.
15054
15375
  * Needs optimization for efficiency.
15055
15376
  */
15056
- function horizontalAlignHandler(line, horizontalAlign) {
15377
+ function shouldAllowOverflowHorizontalOffset(sectionBreakConfig) {
15378
+ var _sectionBreakConfig$r;
15379
+ return ((_sectionBreakConfig$r = sectionBreakConfig.renderConfig) === null || _sectionBreakConfig$r === void 0 ? void 0 : _sectionBreakConfig$r.wrapStrategy) === _univerjs_core.WrapStrategy.OVERFLOW;
15380
+ }
15381
+ function getGlyphGroupInkBounds(divide) {
15382
+ if (divide.glyphGroup.length === 0) return null;
15383
+ let left = Infinity;
15384
+ let right = -Infinity;
15385
+ for (const glyph of divide.glyphGroup) {
15386
+ const glyphLeft = glyph.left + glyph.xOffset;
15387
+ left = Math.min(left, glyphLeft);
15388
+ right = Math.max(right, glyphLeft + glyph.bBox.width);
15389
+ }
15390
+ if (!Number.isFinite(left) || !Number.isFinite(right)) return null;
15391
+ return {
15392
+ left,
15393
+ right
15394
+ };
15395
+ }
15396
+ function horizontalAlignHandler(line, horizontalAlign, allowOverflowHorizontalOffset = false) {
15057
15397
  const { divides } = line;
15058
15398
  for (let i = 0; i < divides.length; i++) {
15059
15399
  const divide = divides[i];
@@ -15092,9 +15432,12 @@ function horizontalAlignHandler(line, horizontalAlign) {
15092
15432
  divide.glyphGroupWidth = glyphGroupWidth;
15093
15433
  }
15094
15434
  }
15095
- if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER) divide.paddingLeft = (width - glyphGroupWidth) / 2;
15435
+ const inkBounds = allowOverflowHorizontalOffset ? getGlyphGroupInkBounds(divide) : null;
15436
+ if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER && inkBounds) divide.paddingLeft = width / 2 - (inkBounds.left + inkBounds.right) / 2;
15437
+ else if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT && inkBounds) divide.paddingLeft = width - inkBounds.right;
15438
+ else if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER) divide.paddingLeft = (width - glyphGroupWidth) / 2;
15096
15439
  else if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT) divide.paddingLeft = width - glyphGroupWidth;
15097
- divide.paddingLeft = Math.max(divide.paddingLeft, 0);
15440
+ if (!allowOverflowHorizontalOffset) divide.paddingLeft = Math.max(divide.paddingLeft, 0);
15098
15441
  }
15099
15442
  }
15100
15443
  function restoreLastCJKGlyphWidth(line) {
@@ -15139,7 +15482,10 @@ function addHyphenDash(line, viewModel, paragraphNode, sectionBreakConfig, parag
15139
15482
  }
15140
15483
  function lineAdjustment(pages, viewModel, paragraphNode, sectionBreakConfig) {
15141
15484
  const { endIndex } = paragraphNode;
15142
- const paragraph = viewModel.getParagraph(endIndex) || { startIndex: 0 };
15485
+ const paragraph = viewModel.getParagraph(endIndex) || {
15486
+ startIndex: 0,
15487
+ paragraphId: "para_render_fallback"
15488
+ };
15143
15489
  lineIterator(pages, (line) => {
15144
15490
  if (line.paragraphIndex !== paragraph.startIndex) return;
15145
15491
  const { paragraphStyle = {} } = paragraph;
@@ -15147,7 +15493,7 @@ function lineAdjustment(pages, viewModel, paragraphNode, sectionBreakConfig) {
15147
15493
  shrinkStartAndEndCJKPunctuation(line);
15148
15494
  restoreLastCJKGlyphWidth(line);
15149
15495
  addHyphenDash(line, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
15150
- horizontalAlignHandler(line, horizontalAlign);
15496
+ horizontalAlignHandler(line, horizontalAlign, shouldAllowOverflowHorizontalOffset(sectionBreakConfig));
15151
15497
  });
15152
15498
  }
15153
15499
 
@@ -15342,11 +15688,43 @@ function ___getLevelAndSuffix(levelAndSuffixPre) {
15342
15688
 
15343
15689
  //#endregion
15344
15690
  //#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]
15691
+ const BLOCK_LAYOUT_OUTER_SPACING_MAP = /* @__PURE__ */ new Map([
15692
+ [_univerjs_core.DocumentBlockRangeType.CALLOUT, 34],
15693
+ [_univerjs_core.DocumentBlockRangeType.CODE, 32],
15694
+ [_univerjs_core.DocumentBlockRangeType.QUOTE, 24]
15349
15695
  ]);
15696
+ function _endsWithToken(text, glyphs, token) {
15697
+ var _glyphs, _glyphs2;
15698
+ 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;
15699
+ }
15700
+ function _isMarkedDocxColumnBreak(viewModel, absoluteIndex) {
15701
+ const customRange = viewModel.getCustomRange(absoluteIndex);
15702
+ const properties = customRange === null || customRange === void 0 ? void 0 : customRange.properties;
15703
+ return (properties === null || properties === void 0 ? void 0 : properties.docxBreakType) === "column";
15704
+ }
15705
+ function _glyphCount(glyphs) {
15706
+ return glyphs.reduce((count, glyph) => count + glyph.count, 0);
15707
+ }
15708
+ function _hasOnlyCustomBlockGlyphs(glyphs) {
15709
+ return glyphs.length > 0 && glyphs.every((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK);
15710
+ }
15711
+ function _mergeAdjacentCustomBlockShapedTexts(shapedTextList) {
15712
+ const mergedShapedTextList = [];
15713
+ for (const shapedText of shapedTextList) {
15714
+ const lastShapedText = mergedShapedTextList[mergedShapedTextList.length - 1];
15715
+ if (lastShapedText && _hasOnlyCustomBlockGlyphs(lastShapedText.glyphs) && _hasOnlyCustomBlockGlyphs(shapedText.glyphs)) {
15716
+ lastShapedText.text += shapedText.text;
15717
+ lastShapedText.glyphs.push(...shapedText.glyphs);
15718
+ lastShapedText.breakPointType = shapedText.breakPointType;
15719
+ continue;
15720
+ }
15721
+ mergedShapedTextList.push({
15722
+ ...shapedText,
15723
+ glyphs: [...shapedText.glyphs]
15724
+ });
15725
+ }
15726
+ return mergedShapedTextList;
15727
+ }
15350
15728
  function _getListLevelAncestors(bullet, listLevel) {
15351
15729
  if (!bullet || !listLevel) return;
15352
15730
  const { listId, nestingLevel } = bullet;
@@ -15417,12 +15795,23 @@ function _applyBlockRangeLayoutParagraphStyle(body, paragraph, paragraphStyle, s
15417
15795
  if ((lastParagraph === null || lastParagraph === void 0 ? void 0 : lastParagraph.startIndex) === paragraph.startIndex && !_hasNextAdjacentLayoutBlockRange(blockRanges, blockRange)) _withMinSpacing(style, "spaceBelow", outerSpacing);
15418
15796
  return style;
15419
15797
  }
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;
15798
+ function _isOnlyFloatingCustomBlockParagraph(viewModel, paragraphNode, drawings) {
15799
+ var _paragraphNode$blocks, _paragraphNode$conten;
15800
+ if (!((_paragraphNode$blocks = paragraphNode.blocks) === null || _paragraphNode$blocks === void 0 ? void 0 : _paragraphNode$blocks.length)) return false;
15801
+ 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;
15802
+ return paragraphNode.blocks.every((charIndex) => {
15803
+ const customBlock = viewModel.getCustomBlock(charIndex);
15804
+ const drawing = customBlock == null ? null : drawings[customBlock.blockId];
15805
+ return drawing != null && drawing.layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE;
15806
+ });
15807
+ }
15808
+ function _getFollowingIndentedParagraphAnchorLeft(viewModel, paragraph, paragraphNode, drawings, isTraditionalDocument) {
15809
+ var _paragraph$paragraphS, _paragraph$paragraphS2, _viewModel$getBody$pa, _viewModel$getBody, _paragraphs$0$paragra, _paragraphs$, _paragraphs$0$paragra2;
15810
+ if (!isTraditionalDocument) return;
15811
+ 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;
15812
+ if (!_isOnlyFloatingCustomBlockParagraph(viewModel, paragraphNode, drawings)) return;
15813
+ 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);
15814
+ 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
15815
  }
15427
15816
  function _getDrawingSkeletonFormat(drawingOrigin) {
15428
15817
  const { drawingId } = drawingOrigin;
@@ -15446,16 +15835,24 @@ function _getNextPageNumber(lastPage) {
15446
15835
  return lastPage.pageNumber + 1;
15447
15836
  }
15448
15837
  function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, sectionBreakConfig, tableSkeleton) {
15449
- var _viewModel$getBody, _viewModel$getBody2;
15838
+ var _sectionBreakConfig$d, _viewModel$getSnapsho, _viewModel$getBody2, _viewModel$getBody3;
15450
15839
  const { skeletonResourceReference } = ctx;
15451
15840
  const { lists, drawings = {}, localeService } = sectionBreakConfig;
15452
15841
  const { endIndex, blocks = [], children } = paragraphNode;
15453
15842
  const { segmentId } = curPage;
15454
- const paragraph = viewModel.getParagraph(endIndex) || { startIndex: 0 };
15843
+ const paragraph = viewModel.getParagraph(endIndex) || {
15844
+ startIndex: 0,
15845
+ paragraphId: "para_render_fallback"
15846
+ };
15455
15847
  const { paragraphStyle = {}, bullet } = paragraph;
15848
+ 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);
15849
+ const shouldApplyDocumentDefaults = documentCompatibilityPolicy.applyDocumentDefaultParagraphStyle;
15850
+ const useWordStyleLineHeight = documentCompatibilityPolicy.useWordStyleLineHeight;
15456
15851
  const { skeHeaders, skeFooters, skeListLevel, drawingAnchor } = skeletonResourceReference;
15457
15852
  const paragraphNonInlineSkeDrawings = /* @__PURE__ */ new Map();
15458
15853
  const paragraphInlineSkeDrawings = /* @__PURE__ */ new Map();
15854
+ const paragraphNonInlineSkeDrawingsByBlockId = /* @__PURE__ */ new Map();
15855
+ const paragraphInlineSkeDrawingsByBlockId = /* @__PURE__ */ new Map();
15459
15856
  let segmentDrawingAnchorCache = drawingAnchor === null || drawingAnchor === void 0 ? void 0 : drawingAnchor.get(segmentId);
15460
15857
  if (segmentDrawingAnchorCache == null) {
15461
15858
  segmentDrawingAnchorCache = /* @__PURE__ */ new Map();
@@ -15463,7 +15860,10 @@ function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, se
15463
15860
  }
15464
15861
  const paragraphConfig = {
15465
15862
  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)),
15863
+ documentCompatibilityPolicy,
15864
+ 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),
15865
+ docxFallbackAnchorLeft: _getFollowingIndentedParagraphAnchorLeft(viewModel, paragraph, paragraphNode, drawings, isTraditionalDocumentCompatibility(documentCompatibilityPolicy)),
15866
+ useWordStyleLineHeight,
15467
15867
  paragraphNonInlineSkeDrawings,
15468
15868
  paragraphInlineSkeDrawings,
15469
15869
  skeTablesInParagraph: tableSkeleton ? [{
@@ -15496,36 +15896,60 @@ function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, se
15496
15896
  if (customBlock == null) continue;
15497
15897
  const { blockId } = customBlock;
15498
15898
  const drawingOrigin = drawings[blockId];
15499
- if (drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) paragraphInlineSkeDrawings.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
15500
- else paragraphNonInlineSkeDrawings.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
15899
+ if (drawingOrigin == null) continue;
15900
+ if (drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) paragraphInlineSkeDrawingsByBlockId.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
15901
+ else paragraphNonInlineSkeDrawingsByBlockId.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
15501
15902
  }
15502
15903
  segmentParagraphCache.set(endIndex, paragraphConfig);
15503
15904
  let allPages = [curPage];
15504
15905
  let isParagraphFirstShapedText = true;
15505
- for (const [_index, { text, glyphs, breakPointType }] of shapedTextList.entries()) {
15906
+ let shapedTextOffset = 0;
15907
+ for (const [_index, { text, glyphs, breakPointType }] of _mergeAdjacentCustomBlockShapedTexts(shapedTextList).entries()) {
15908
+ const textStartIndex = paragraphNode.startIndex + shapedTextOffset;
15909
+ const textGlyphCount = _glyphCount(glyphs);
15910
+ const textEndIndex = textStartIndex + textGlyphCount;
15506
15911
  const pushPending = () => {
15507
15912
  if (glyphs.length === 0) return;
15508
- allPages = layoutParagraph(ctx, glyphs, allPages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);
15913
+ syncActiveParagraphDrawings(glyphs, paragraphNonInlineSkeDrawings, paragraphInlineSkeDrawings, paragraphNonInlineSkeDrawingsByBlockId, paragraphInlineSkeDrawingsByBlockId);
15914
+ allPages = layoutParagraph(ctx, glyphs, allPages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText || hasOnlyFloatingCustomBlockGlyphs(glyphs, paragraphNonInlineSkeDrawingsByBlockId), breakPointType);
15509
15915
  isParagraphFirstShapedText = false;
15510
15916
  };
15511
- if (text.endsWith(_univerjs_core.DataStreamTreeTokenType.PAGE_BREAK)) {
15917
+ if (_endsWithToken(text, glyphs, _univerjs_core.DataStreamTreeTokenType.PAGE_BREAK)) {
15512
15918
  pushPending();
15513
15919
  allPages.push(createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(allPages[allPages.length - 1]), 1));
15514
15920
  paragraphNonInlineSkeDrawings.clear();
15515
- paragraphInlineSkeDrawings.clear();
15921
+ isParagraphFirstShapedText = true;
15922
+ shapedTextOffset += textGlyphCount;
15516
15923
  continue;
15517
- } else if (text.endsWith(_univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK)) {
15924
+ } else if (_endsWithToken(text, glyphs, _univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK) && (!isTraditionalDocumentCompatibility(documentCompatibilityPolicy) || _isMarkedDocxColumnBreak(viewModel, textEndIndex - 1))) {
15518
15925
  pushPending();
15519
15926
  const lastPage = allPages[allPages.length - 1];
15520
15927
  const columnInfo = getLastNotFullColumnInfo(lastPage);
15521
15928
  if (columnInfo && !columnInfo.isLast) setColumnFullState(columnInfo.column, true);
15522
15929
  else allPages.push(createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(lastPage), 2));
15930
+ shapedTextOffset += textGlyphCount;
15523
15931
  continue;
15524
15932
  }
15525
15933
  pushPending();
15934
+ shapedTextOffset += textGlyphCount;
15526
15935
  }
15527
15936
  return allPages;
15528
15937
  }
15938
+ function syncActiveParagraphDrawings(glyphs, paragraphNonInlineSkeDrawings, paragraphInlineSkeDrawings, paragraphNonInlineSkeDrawingsByBlockId, paragraphInlineSkeDrawingsByBlockId) {
15939
+ for (const glyph of glyphs) {
15940
+ if (glyph.streamType !== _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK || glyph.drawingId == null) continue;
15941
+ const inlineDrawing = paragraphInlineSkeDrawingsByBlockId.get(glyph.drawingId);
15942
+ if (inlineDrawing != null) {
15943
+ paragraphInlineSkeDrawings.set(glyph.drawingId, inlineDrawing);
15944
+ continue;
15945
+ }
15946
+ const nonInlineDrawing = paragraphNonInlineSkeDrawingsByBlockId.get(glyph.drawingId);
15947
+ if (nonInlineDrawing != null) paragraphNonInlineSkeDrawings.set(glyph.drawingId, nonInlineDrawing);
15948
+ }
15949
+ }
15950
+ function hasOnlyFloatingCustomBlockGlyphs(glyphs, paragraphNonInlineSkeDrawingsByBlockId) {
15951
+ return glyphs.length > 0 && glyphs.every((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.drawingId != null && paragraphNonInlineSkeDrawingsByBlockId.has(glyph.drawingId));
15952
+ }
15529
15953
 
15530
15954
  //#endregion
15531
15955
  //#region src/components/docs/layout/line-breaker/enhancers/hyphen-enhancer.ts
@@ -15849,6 +16273,26 @@ function prepareTextChunks(body) {
15849
16273
  //#region src/components/docs/layout/shaping-engine/text-shaping.ts
15850
16274
  const fontCache = /* @__PURE__ */ new Map();
15851
16275
  const glyphCache = /* @__PURE__ */ new Map();
16276
+ const fontFamilyCache = /* @__PURE__ */ new Map();
16277
+ function trimOuterQuotes(value) {
16278
+ const firstChar = value.charCodeAt(0);
16279
+ const lastChar = value.charCodeAt(value.length - 1);
16280
+ const hasLeadingQuote = firstChar === 34 || firstChar === 39;
16281
+ const hasTrailingQuote = lastChar === 34 || lastChar === 39;
16282
+ if (hasLeadingQuote && hasTrailingQuote) return value.slice(1, -1);
16283
+ if (hasLeadingQuote) return value.slice(1);
16284
+ if (hasTrailingQuote) return value.slice(0, -1);
16285
+ return value;
16286
+ }
16287
+ function expandFontFamilies(fontFamily) {
16288
+ if (!(fontFamily === null || fontFamily === void 0 ? void 0 : fontFamily.trim())) return [];
16289
+ let families = fontFamilyCache.get(fontFamily);
16290
+ if (families) return families;
16291
+ families = fontFamily.split(",").map((family) => trimOuterQuotes(family.trim())).filter(Boolean);
16292
+ fontFamilyCache.set(fontFamily, families);
16293
+ return families;
16294
+ }
16295
+ const defaultFontFamilies = expandFontFamilies(DEFAULT_FONTFACE_PLANE);
15852
16296
  function shapeChunk(content, charPosition, used, families, style) {
15853
16297
  var _style$bl, _style$it, _content$match;
15854
16298
  let fi = 0;
@@ -15951,8 +16395,7 @@ function textShape(body) {
15951
16395
  for (const chunk of chunks) {
15952
16396
  var _style$ff;
15953
16397
  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");
16398
+ let fontFamilies = [...expandFontFamilies((_style$ff = style.ff) !== null && _style$ff !== void 0 ? _style$ff : "Arial"), ...defaultFontFamilies];
15956
16399
  fontFamilies = fontLibrary.getValidFontFamilies(fontFamilies);
15957
16400
  glyphs.push(...shapeChunk(content, charPosition, /* @__PURE__ */ new Set(), fontFamilies, style));
15958
16401
  charPosition += content.length;
@@ -15990,7 +16433,7 @@ function ArabicHandler(index, charArray, viewModel, paragraphNode, sectionBreakC
15990
16433
  for (let i = 0; i < charArray.length; i++) {
15991
16434
  const newChar = charArray[i];
15992
16435
  if (hasArabic(newChar)) {
15993
- glyph.unshift(newChar);
16436
+ glyph.push(newChar);
15994
16437
  step++;
15995
16438
  } else break;
15996
16439
  }
@@ -16087,7 +16530,10 @@ function shaping(ctx, content, viewModel, paragraphNode, sectionBreakConfig, use
16087
16530
  const shapedTextList = [];
16088
16531
  let breaker = new LineBreaker(content);
16089
16532
  const { endIndex } = paragraphNode;
16090
- const paragraph = viewModel.getParagraph(endIndex) || { startIndex: 0 };
16533
+ const paragraph = viewModel.getParagraph(endIndex) || {
16534
+ startIndex: 0,
16535
+ paragraphId: "para_render_fallback"
16536
+ };
16091
16537
  const { paragraphStyle = {} } = paragraph;
16092
16538
  const { snapToGrid = _univerjs_core.BooleanNumber.TRUE } = paragraphStyle;
16093
16539
  let last = 0;
@@ -16146,12 +16592,12 @@ function shaping(ctx, content, viewModel, paragraphNode, sectionBreakConfig, use
16146
16592
  if (customBlock != null) {
16147
16593
  const { blockId } = customBlock;
16148
16594
  const drawingOrigin = drawings[blockId];
16149
- if (drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) {
16595
+ if ((drawingOrigin === null || drawingOrigin === void 0 ? void 0 : drawingOrigin.layoutType) === _univerjs_core.PositionedObjectLayoutType.INLINE) {
16150
16596
  const { angle } = drawingOrigin.docTransform;
16151
16597
  const { width = 0, height = 0 } = drawingOrigin.docTransform.size;
16152
16598
  const boundingBox = getBoundingBox(angle, 0, width, 0, height);
16153
16599
  newGlyph = createSkeletonCustomBlockGlyph(config, boundingBox.width, boundingBox.height, drawingOrigin.drawingId);
16154
- } else newGlyph = createSkeletonCustomBlockGlyph(config, 0, 0, drawingOrigin.drawingId);
16600
+ } else if (drawingOrigin != null) newGlyph = createSkeletonCustomBlockGlyph(config, 0, 0, drawingOrigin.drawingId);
16155
16601
  }
16156
16602
  if (newGlyph == null) newGlyph = createSkeletonLetterGlyph(char, config);
16157
16603
  shapedGlyphs.push(newGlyph);
@@ -17093,9 +17539,9 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17093
17539
  const viewport = getDocsTableRenderViewport(unitId, sourceTableId);
17094
17540
  (_this$_findLiquid = this._findLiquid) === null || _this$_findLiquid === void 0 || _this$_findLiquid.translateSave();
17095
17541
  (_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;
17542
+ if (hasDocsTableHorizontalViewport(viewport)) {
17543
+ var _viewport$leadingInse, _this$_findLiquid4;
17544
+ const visibleLeft = this._findLiquid.x + page.marginLeft - ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0);
17099
17545
  const visibleRight = visibleLeft + viewport.viewportWidth;
17100
17546
  if (x < visibleLeft || x > visibleRight) {
17101
17547
  var _this$_findLiquid3;
@@ -17191,6 +17637,7 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17191
17637
  lists,
17192
17638
  drawings,
17193
17639
  localeService: this._localeService,
17640
+ documentCompatibilityPolicy: getDocumentCompatibilityPolicy(documentStyle.documentFlavor),
17194
17641
  paragraphLineGapDefault,
17195
17642
  defaultTabStop,
17196
17643
  documentTextStyle: textStyle
@@ -17265,7 +17712,7 @@ var DocumentSkeleton = class DocumentSkeleton extends _univerjs_core.Skeleton {
17265
17712
  let curSkeletonPage = getLastPage(allSkeletonPages);
17266
17713
  let isContinuous = false;
17267
17714
  ctx.sectionBreakConfigCache.set(sectionNode.endIndex, sectionBreakConfig);
17268
- if (sectionType === _univerjs_core.SectionType.CONTINUOUS) {
17715
+ if (sectionType === _univerjs_core.SectionType.CONTINUOUS && curSkeletonPage != null) {
17269
17716
  updateBlockIndex(allSkeletonPages);
17270
17717
  this._addNewSectionByContinuous(curSkeletonPage, columnProperties, columnSeparatorType);
17271
17718
  isContinuous = true;
@@ -17397,6 +17844,7 @@ function createDocumentModelWithStyle(content, textStyle, config = {}) {
17397
17844
  }],
17398
17845
  paragraphs: [{
17399
17846
  startIndex: contentLength,
17847
+ paragraphId: (0, _univerjs_core.createParagraphId)(/* @__PURE__ */ new Set()),
17400
17848
  paragraphStyle: { horizontalAlign }
17401
17849
  }],
17402
17850
  sectionBreaks: [{ startIndex: contentLength + 1 }]
@@ -17453,7 +17901,7 @@ function getFontFormat(format) {
17453
17901
  }
17454
17902
 
17455
17903
  //#endregion
17456
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
17904
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
17457
17905
  function __decorateParam(paramIndex, decorator) {
17458
17906
  return function(target, key) {
17459
17907
  decorator(target, key, paramIndex);
@@ -17461,7 +17909,7 @@ function __decorateParam(paramIndex, decorator) {
17461
17909
  }
17462
17910
 
17463
17911
  //#endregion
17464
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
17912
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
17465
17913
  function __decorate(decorators, target, key, desc) {
17466
17914
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17467
17915
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -18274,7 +18722,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18274
18722
  this.makeDirty(true);
18275
18723
  }
18276
18724
  _setBorderStylesCache(row, col, style, options) {
18277
- if (_univerjs_core.Tools.isDefine(this._handleBorderMatrix.getValue(row, col))) return;
18725
+ if (_univerjs_core.Tools.isDefine(this._handleBorderMatrix.getValue(row, col)) && !(options === null || options === void 0 ? void 0 : options.mergeRange)) return;
18278
18726
  if (!((options === null || options === void 0 ? void 0 : options.cacheItem) || {
18279
18727
  bg: true,
18280
18728
  border: true
@@ -19413,6 +19861,56 @@ var docExtension = class extends ComponentExtension {
19413
19861
  }
19414
19862
  };
19415
19863
 
19864
+ //#endregion
19865
+ //#region src/components/docs/extensions/background-runs.ts
19866
+ function collectBackgroundGlyphRuns(glyphGroup) {
19867
+ const runs = [];
19868
+ let activeGlyph = null;
19869
+ let activeColor = "";
19870
+ let activeLeft = 0;
19871
+ let activeRight = 0;
19872
+ const flush = () => {
19873
+ if (!activeGlyph) return;
19874
+ runs.push({
19875
+ glyph: {
19876
+ ...activeGlyph,
19877
+ width: activeRight - activeLeft
19878
+ },
19879
+ left: activeLeft,
19880
+ width: activeRight - activeLeft
19881
+ });
19882
+ activeGlyph = null;
19883
+ activeColor = "";
19884
+ activeLeft = 0;
19885
+ activeRight = 0;
19886
+ };
19887
+ for (const glyph of glyphGroup) {
19888
+ var _glyph$ts;
19889
+ if (!glyph.content || glyph.content === "\r") {
19890
+ flush();
19891
+ continue;
19892
+ }
19893
+ const backgroundColor = ((_glyph$ts = glyph.ts) === null || _glyph$ts === void 0 ? void 0 : _glyph$ts.bg) ? (0, _univerjs_core.getColorStyle)(glyph.ts.bg) : "";
19894
+ if (!backgroundColor) {
19895
+ flush();
19896
+ continue;
19897
+ }
19898
+ const glyphLeft = glyph.left;
19899
+ const glyphRight = glyph.left + glyph.width;
19900
+ if (activeGlyph && activeColor === backgroundColor) {
19901
+ activeRight = Math.max(activeRight, glyphRight);
19902
+ continue;
19903
+ }
19904
+ flush();
19905
+ activeGlyph = glyph;
19906
+ activeColor = backgroundColor;
19907
+ activeLeft = glyphLeft;
19908
+ activeRight = glyphRight;
19909
+ }
19910
+ flush();
19911
+ return runs;
19912
+ }
19913
+
19416
19914
  //#endregion
19417
19915
  //#region src/components/docs/extensions/background.ts
19418
19916
  const UNIQUE_KEY$3 = "DefaultDocsBackgroundExtension";
@@ -19828,7 +20326,6 @@ var Image$1 = class extends Shape {
19828
20326
  this.makeDirty(true);
19829
20327
  } else if (config.url) {
19830
20328
  this._native = document.createElement("img");
19831
- this._native.src = config.url;
19832
20329
  this._native.crossOrigin = "anonymous";
19833
20330
  this._native.onload = () => {
19834
20331
  var _config$success, _this$getEngine;
@@ -19843,6 +20340,7 @@ var Image$1 = class extends Shape {
19843
20340
  this.makeDirty(true);
19844
20341
  }
19845
20342
  };
20343
+ this._native.src = config.url;
19846
20344
  }
19847
20345
  this._init();
19848
20346
  }
@@ -19856,10 +20354,17 @@ var Image$1 = class extends Shape {
19856
20354
  var _this$_props$opacity;
19857
20355
  return (_this$_props$opacity = this._props.opacity) !== null && _this$_props$opacity !== void 0 ? _this$_props$opacity : 1;
19858
20356
  }
20357
+ get clipBounds() {
20358
+ return this._props.clipBounds;
20359
+ }
19859
20360
  setOpacity(opacity) {
19860
20361
  this._props.opacity = opacity;
19861
20362
  this.makeDirty(true);
19862
20363
  }
20364
+ setClipBounds(clipBounds) {
20365
+ this._props.clipBounds = clipBounds;
20366
+ this.makeDirty(true);
20367
+ }
19863
20368
  setClipService(clipService) {
19864
20369
  this._clipService = clipService;
19865
20370
  }
@@ -19876,10 +20381,10 @@ var Image$1 = class extends Shape {
19876
20381
  }
19877
20382
  changeSource(url) {
19878
20383
  if (this._native == null) this._native = document.createElement("img");
19879
- this._native.src = url;
19880
20384
  this._native.onload = () => {
19881
20385
  this.makeDirty(true);
19882
20386
  };
20387
+ this._native.src = url;
19883
20388
  }
19884
20389
  resetSize() {
19885
20390
  if (this._native == null) return;
@@ -19985,6 +20490,12 @@ var Image$1 = class extends Shape {
19985
20490
  }
19986
20491
  const m = this.transform.getMatrix();
19987
20492
  mainCtx.save();
20493
+ const { clipBounds } = this;
20494
+ if (clipBounds) {
20495
+ mainCtx.beginPath();
20496
+ mainCtx.rect(clipBounds.left, clipBounds.top, clipBounds.width, clipBounds.height);
20497
+ mainCtx.clip();
20498
+ }
19988
20499
  const centerX = realLeft + realWidth / 2;
19989
20500
  const centerY = realTop + realHeight / 2;
19990
20501
  mainCtx.transform(m[0], m[1], m[2], m[3], centerX, centerY);
@@ -21625,6 +22136,7 @@ var FontAndBaseLine = class extends docExtension {
21625
22136
  "actualFontMap",
21626
22137
  {}
21627
22138
  );
22139
+ _defineProperty(this, "_textFillImageCache", /* @__PURE__ */ new Map());
21628
22140
  }
21629
22141
  draw(ctx, _parentScale, glyph, _, _more) {
21630
22142
  var _glyph$parent;
@@ -21643,13 +22155,162 @@ var FontAndBaseLine = class extends docExtension {
21643
22155
  this.actualFontMap[fontStringPxStr] = ctx.font;
21644
22156
  }
21645
22157
  }
21646
- const { cl: colorStyle, va: baselineOffset } = textStyle;
22158
+ const { cl: colorStyle, va: baselineOffset, textFill } = textStyle;
21647
22159
  const fontColor = (0, _univerjs_core.getColorStyle)(colorStyle) || "rgb(0,0,0)";
21648
- if (fontColor && this._preFontColor !== fontColor) ctx.fillStyle = fontColor;
21649
22160
  if (baselineOffset === _univerjs_core.BaselineOffset.SUPERSCRIPT) spanPointWithFont.y += -bBox.spo;
21650
22161
  else if (baselineOffset === _univerjs_core.BaselineOffset.SUBSCRIPT) spanPointWithFont.y += bBox.sbo;
22162
+ if (this._fillTextWithTextFill(ctx, glyph, spanPointWithFont, textFill, fontColor)) return;
22163
+ if (fontColor && this._preFontColor !== fontColor) ctx.fillStyle = fontColor;
21651
22164
  this._fillText(ctx, glyph, spanPointWithFont);
21652
22165
  }
22166
+ _fillTextWithTextFill(ctx, glyph, spanPointWithFont, textFill, fallbackColor) {
22167
+ if (!textFill || textFill.type === "none") return (textFill === null || textFill === void 0 ? void 0 : textFill.type) === "none";
22168
+ const { content, glyphType } = glyph;
22169
+ if (content == null || glyphType === 2) return false;
22170
+ const { renderConfig } = this.extensionOffset;
22171
+ const { vertexAngle, centerAngle } = renderConfig !== null && renderConfig !== void 0 ? renderConfig : {};
22172
+ const VERTICAL_DEG = 90;
22173
+ if (vertexAngle === VERTICAL_DEG && centerAngle === VERTICAL_DEG) return false;
22174
+ const bounds = this._getGlyphPaintBounds(glyph, spanPointWithFont);
22175
+ if (bounds.width <= 0 || bounds.height <= 0) return false;
22176
+ const color = this._colorWithOpacity(textFill.color || fallbackColor, textFill.opacity);
22177
+ if (textFill.type === "solid") {
22178
+ ctx.fillStyle = color;
22179
+ this._fillText(ctx, glyph, spanPointWithFont);
22180
+ return true;
22181
+ }
22182
+ if (textFill.type === "gradient") {
22183
+ const gradient = this._createTextGradient(ctx, bounds, textFill, fallbackColor);
22184
+ if (!gradient) return false;
22185
+ ctx.fillStyle = gradient;
22186
+ this._fillText(ctx, glyph, spanPointWithFont);
22187
+ return true;
22188
+ }
22189
+ if (textFill.type === "picture") {
22190
+ const pattern = this._createTextPicturePattern(ctx, bounds, textFill);
22191
+ if (!pattern) return false;
22192
+ ctx.fillStyle = pattern;
22193
+ this._fillText(ctx, glyph, spanPointWithFont);
22194
+ return true;
22195
+ }
22196
+ return false;
22197
+ }
22198
+ _getGlyphPaintBounds(glyph, spanPointWithFont) {
22199
+ const { width, bBox } = glyph;
22200
+ const textWidth = Math.max(width, bBox.width, 1);
22201
+ const textHeight = Math.max(bBox.aba + bBox.abd, 1);
22202
+ return {
22203
+ left: spanPointWithFont.x,
22204
+ top: spanPointWithFont.y - bBox.aba,
22205
+ width: textWidth,
22206
+ height: textHeight
22207
+ };
22208
+ }
22209
+ _createTextGradient(ctx, bounds, textFill, fallbackColor) {
22210
+ var _gradient$type, _gradient$angle, _context;
22211
+ const gradient = textFill.gradient;
22212
+ const type = (_gradient$type = gradient === null || gradient === void 0 ? void 0 : gradient.type) !== null && _gradient$type !== void 0 ? _gradient$type : "linear";
22213
+ const angle = (_gradient$angle = gradient === null || gradient === void 0 ? void 0 : gradient.angle) !== null && _gradient$angle !== void 0 ? _gradient$angle : 0;
22214
+ const stops = this._normalizeGradientStops(gradient === null || gradient === void 0 ? void 0 : gradient.stops, textFill.color || fallbackColor);
22215
+ const centerX = bounds.left + bounds.width / 2;
22216
+ const centerY = bounds.top + bounds.height / 2;
22217
+ let canvasGradient;
22218
+ if (type === "radial") {
22219
+ const radius = Math.max(bounds.width, bounds.height) / 2;
22220
+ canvasGradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, radius);
22221
+ } else if (type === "angular" && "createConicGradient" in ((_context = ctx._context) !== null && _context !== void 0 ? _context : ctx)) {
22222
+ var _context2;
22223
+ canvasGradient = ((_context2 = ctx._context) !== null && _context2 !== void 0 ? _context2 : ctx).createConicGradient((angle - 90) * Math.PI / 180, centerX, centerY);
22224
+ } else if (type === "diamond") {
22225
+ const radius = Math.max(bounds.width, bounds.height) / 2;
22226
+ canvasGradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, radius);
22227
+ } else {
22228
+ const line = this._getLinearGradientLine(bounds, angle);
22229
+ canvasGradient = ctx.createLinearGradient(line.x0, line.y0, line.x1, line.y1);
22230
+ }
22231
+ for (const stop of stops) {
22232
+ var _textFill$opacity, _stop$opacity;
22233
+ 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);
22234
+ canvasGradient.addColorStop(stop.offset, this._colorWithOpacity(stop.color, opacity));
22235
+ }
22236
+ return canvasGradient;
22237
+ }
22238
+ _createTextPicturePattern(ctx, bounds, textFill) {
22239
+ var _textFill$picture, _ref, _textFill$picture$opa, _textFill$picture2, _textFill$picture3, _pattern$setTransform;
22240
+ const source = (_textFill$picture = textFill.picture) === null || _textFill$picture === void 0 ? void 0 : _textFill$picture.source;
22241
+ if (!source) return null;
22242
+ const image = this._getTextFillImage(source);
22243
+ if (!image || !image.complete || !(image.naturalWidth || image.width)) return null;
22244
+ const canvas = document.createElement("canvas");
22245
+ canvas.width = Math.max(1, Math.ceil(bounds.width));
22246
+ canvas.height = Math.max(1, Math.ceil(bounds.height));
22247
+ const canvasContext = canvas.getContext("2d");
22248
+ if (!canvasContext) return null;
22249
+ 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);
22250
+ if (((_textFill$picture3 = textFill.picture) === null || _textFill$picture3 === void 0 ? void 0 : _textFill$picture3.mode) === "tile") {
22251
+ var _textFill$picture$sca, _textFill$picture$sca2, _textFill$picture$off, _textFill$picture$off2;
22252
+ const scaleX = (_textFill$picture$sca = textFill.picture.scaleX) !== null && _textFill$picture$sca !== void 0 ? _textFill$picture$sca : 1;
22253
+ const scaleY = (_textFill$picture$sca2 = textFill.picture.scaleY) !== null && _textFill$picture$sca2 !== void 0 ? _textFill$picture$sca2 : 1;
22254
+ const cellWidth = Math.max(1, (image.naturalWidth || image.width) * scaleX);
22255
+ const cellHeight = Math.max(1, (image.naturalHeight || image.height) * scaleY);
22256
+ const offsetX = (_textFill$picture$off = textFill.picture.offsetX) !== null && _textFill$picture$off !== void 0 ? _textFill$picture$off : 0;
22257
+ const offsetY = (_textFill$picture$off2 = textFill.picture.offsetY) !== null && _textFill$picture$off2 !== void 0 ? _textFill$picture$off2 : 0;
22258
+ 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);
22259
+ } else canvasContext.drawImage(image, 0, 0, canvas.width, canvas.height);
22260
+ const pattern = ctx.createPattern(canvas, "no-repeat");
22261
+ 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));
22262
+ return pattern;
22263
+ }
22264
+ _getTextFillImage(source) {
22265
+ const cached = this._textFillImageCache.get(source);
22266
+ if (cached) return cached;
22267
+ const image = new Image();
22268
+ image.crossOrigin = "anonymous";
22269
+ image.src = source;
22270
+ this._textFillImageCache.set(source, image);
22271
+ return image.complete ? image : null;
22272
+ }
22273
+ _normalizeGradientStops(stops, fallbackColor) {
22274
+ return (stops && stops.length >= 2 ? stops : [{
22275
+ offset: 0,
22276
+ color: fallbackColor
22277
+ }, {
22278
+ offset: 100,
22279
+ color: "#ffffff"
22280
+ }]).map((stop) => ({
22281
+ color: stop.color,
22282
+ offset: this._clamp(stop.offset > 1 ? stop.offset / 100 : stop.offset, 0, 1),
22283
+ opacity: stop.opacity
22284
+ }));
22285
+ }
22286
+ _getLinearGradientLine(bounds, angle) {
22287
+ const angleRad = angle * Math.PI / 180;
22288
+ const centerX = bounds.left + bounds.width / 2;
22289
+ const centerY = bounds.top + bounds.height / 2;
22290
+ const cos = Math.cos(angleRad);
22291
+ const sin = Math.sin(angleRad);
22292
+ const halfDiagonal = (Math.abs(bounds.width * cos) + Math.abs(bounds.height * sin)) / 2;
22293
+ return {
22294
+ x0: centerX - cos * halfDiagonal,
22295
+ y0: centerY - sin * halfDiagonal,
22296
+ x1: centerX + cos * halfDiagonal,
22297
+ y1: centerY + sin * halfDiagonal
22298
+ };
22299
+ }
22300
+ _colorWithOpacity(color, opacity) {
22301
+ if (opacity === void 0 || opacity >= 1) return color;
22302
+ const alpha = this._clamp(opacity, 0, 1);
22303
+ const hex = color.trim();
22304
+ if (/^#[0-9a-f]{3}$/i.test(hex)) {
22305
+ const [, r, g, b] = hex;
22306
+ return `rgba(${Number.parseInt(r + r, 16)}, ${Number.parseInt(g + g, 16)}, ${Number.parseInt(b + b, 16)}, ${alpha})`;
22307
+ }
22308
+ 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})`;
22309
+ return color;
22310
+ }
22311
+ _clamp(value, min, max) {
22312
+ return Math.max(min, Math.min(max, value));
22313
+ }
21653
22314
  _fillText(ctx, glyph, spanPointWithFont) {
21654
22315
  const { renderConfig, spanStartPoint, centerPoint } = this.extensionOffset;
21655
22316
  const { content, width, bBox } = glyph;
@@ -21997,24 +22658,14 @@ var Documents = class Documents extends DocComponent {
21997
22658
  this._drawLiquid.translateSave();
21998
22659
  this._drawLiquid.translateLine(line, true, true);
21999
22660
  rotateTranslateXListApply && this._drawLiquid.translate(rotateTranslateXListApply[i]);
22661
+ this._drawLineBackground(ctx, page, line);
22000
22662
  const divideLength = divides.length;
22001
22663
  for (let i = 0; i < divideLength; i++) {
22002
22664
  const divide = divides[i];
22003
22665
  const { glyphGroup } = divide;
22004
22666
  this._drawLiquid.translateSave();
22005
22667
  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
- }
22668
+ this._drawGlyphGroupBackgrounds(ctx, parentScale, glyphGroup, lineHeight, alignOffset, centerAngle, vertexAngle, backgroundExtension);
22018
22669
  for (const glyph of glyphGroup) {
22019
22670
  if (!glyph.content || glyph.content.length === 0) continue;
22020
22671
  const { width: spanWidth, left: spanLeft, xOffset } = glyph;
@@ -22070,15 +22721,18 @@ var Documents = class Documents extends DocComponent {
22070
22721
  const viewport = this._getTableViewport(page, tableSkeleton, renderUnitId, sourceTableId);
22071
22722
  drawLiquid.translateSave();
22072
22723
  drawLiquid.translate(tableLeft, tableTop);
22073
- if (viewport && viewport.contentWidth > viewport.viewportWidth) {
22724
+ if (hasDocsTableHorizontalViewport(viewport)) {
22725
+ var _viewport$leadingInse;
22074
22726
  const { x, y } = drawLiquid;
22727
+ const clipLeft = x + page.marginLeft - ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0);
22075
22728
  ctx.save();
22076
22729
  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);
22730
+ 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
22731
  ctx.closePath();
22079
22732
  ctx.clip();
22080
22733
  drawLiquid.translate(-viewport.scrollLeft, 0);
22081
22734
  }
22735
+ this._drawTableCellBackgrounds(ctx, page, tableSkeleton);
22082
22736
  for (const row of rows) {
22083
22737
  const { top: rowTop, cells } = row;
22084
22738
  drawLiquid.translateSave();
@@ -22093,16 +22747,49 @@ var Documents = class Documents extends DocComponent {
22093
22747
  }
22094
22748
  drawLiquid.translateRestore();
22095
22749
  }
22096
- if (viewport && viewport.contentWidth > viewport.viewportWidth) ctx.restore();
22750
+ if (hasDocsTableHorizontalViewport(viewport)) ctx.restore();
22097
22751
  drawLiquid.translateRestore();
22098
22752
  }
22099
22753
  }
22754
+ _drawTableCellBackgrounds(ctx, page, tableSkeleton) {
22755
+ if (this._drawLiquid == null) return;
22756
+ const backgrounds = /* @__PURE__ */ new Map();
22757
+ const tableX = this._drawLiquid.x + page.marginLeft;
22758
+ const tableY = this._drawLiquid.y + page.marginTop;
22759
+ for (const row of tableSkeleton.rows) row.cells.forEach((cell, index) => {
22760
+ var _cellSource$backgroun, _backgrounds$get;
22761
+ if (cell.isMergedCellCovered) return;
22762
+ const cellSource = row.rowSource.tableCells[index];
22763
+ if (!cellSource || cellSource.rowSpan === 0 || cellSource.columnSpan === 0) return;
22764
+ const color = (_cellSource$backgroun = cellSource.backgroundColor) === null || _cellSource$backgroun === void 0 ? void 0 : _cellSource$backgroun.rgb;
22765
+ if (!color) return;
22766
+ const rects = (_backgrounds$get = backgrounds.get(color)) !== null && _backgrounds$get !== void 0 ? _backgrounds$get : [];
22767
+ rects.push({
22768
+ x: tableX + cell.left,
22769
+ y: tableY + row.top,
22770
+ width: cell.pageWidth,
22771
+ height: cell.pageHeight
22772
+ });
22773
+ backgrounds.set(color, rects);
22774
+ });
22775
+ backgrounds.forEach((rects, color) => {
22776
+ ctx.save();
22777
+ ctx.fillStyle = color;
22778
+ ctx.beginPath();
22779
+ rects.forEach(({ x, y, width, height }) => {
22780
+ rectByPrecisionBounds(ctx, x, y, width, height);
22781
+ });
22782
+ ctx.fill();
22783
+ ctx.closePath();
22784
+ ctx.restore();
22785
+ });
22786
+ }
22100
22787
  _getTableViewport(page, tableSkeleton, unitId, tableId) {
22101
22788
  const viewport = getDocsTableRenderViewport(unitId, tableId);
22102
22789
  if (viewport) return viewport;
22103
22790
  const { pageWidth, marginLeft = 0, marginRight = 0 } = page;
22104
22791
  if (!Number.isFinite(pageWidth)) return null;
22105
- const viewportWidth = Math.max(0, pageWidth - marginLeft - marginRight - tableSkeleton.left);
22792
+ 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
22793
  if (viewportWidth <= 0 || tableSkeleton.width <= viewportWidth) return null;
22107
22794
  return {
22108
22795
  contentWidth: tableSkeleton.width,
@@ -22117,6 +22804,26 @@ var Documents = class Documents extends DocComponent {
22117
22804
  const dataModel = viewModel === null || viewModel === void 0 || (_viewModel$getDataMod = viewModel.getDataModel) === null || _viewModel$getDataMod === void 0 ? void 0 : _viewModel$getDataMod.call(viewModel);
22118
22805
  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
22806
  }
22807
+ _getDocumentCompatibilityPolicy() {
22808
+ var _skeleton$getViewMode2, _skeleton$getViewMode3;
22809
+ const skeleton = this.getSkeleton();
22810
+ 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);
22811
+ }
22812
+ _drawLineBackground(ctx, page, line, left = 0, top = 0) {
22813
+ var _line$backgroundColor;
22814
+ const color = (_line$backgroundColor = line.backgroundColor) === null || _line$backgroundColor === void 0 ? void 0 : _line$backgroundColor.rgb;
22815
+ if (!color || this._drawLiquid == null) return;
22816
+ let { x, y } = this._drawLiquid;
22817
+ const { pageWidth, marginLeft, marginRight, marginTop } = page;
22818
+ x += marginLeft + (left !== null && left !== void 0 ? left : 0);
22819
+ y -= line.marginTop;
22820
+ y -= line.paddingTop;
22821
+ y += marginTop + top;
22822
+ ctx.save();
22823
+ ctx.fillStyle = color;
22824
+ fillRectByPrecisionBounds(ctx, x, y, pageWidth - marginLeft - marginRight, line.lineHeight);
22825
+ ctx.restore();
22826
+ }
22120
22827
  _drawBorderBottom(ctx, page, line, left = 0, top = 0) {
22121
22828
  var _line$borderBottom$pa, _line$borderBottom, _line$borderBottom$co, _line$borderBottom2;
22122
22829
  if (this._drawLiquid == null) return;
@@ -22137,9 +22844,21 @@ var Documents = class Documents extends DocComponent {
22137
22844
  });
22138
22845
  ctx.restore();
22139
22846
  }
22847
+ _drawGlyphGroupBackgrounds(ctx, parentScale, glyphGroup, lineHeight, alignOffset, centerAngle, vertexAngle, backgroundExtension) {
22848
+ if (!backgroundExtension || this._drawLiquid == null) return;
22849
+ const backgroundRuns = collectBackgroundGlyphRuns(glyphGroup);
22850
+ for (const backgroundRun of backgroundRuns) {
22851
+ const { glyph, left: spanLeft, width: spanWidth } = backgroundRun;
22852
+ const { x: translateX, y: translateY } = this._drawLiquid;
22853
+ const originTranslate = Vector2.create(translateX, translateY);
22854
+ const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
22855
+ backgroundExtension.extensionOffset = { spanStartPoint: calculateRectRotate(originTranslate.addByPoint(spanLeft, 0), centerPoint, centerAngle, vertexAngle, alignOffset) };
22856
+ backgroundExtension.draw(ctx, parentScale, glyph);
22857
+ }
22858
+ }
22140
22859
  _drawTableCell(ctx, page, cell, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale) {
22141
22860
  if (this._drawLiquid == null) return;
22142
- this._drawTableCellBordersAndBg(ctx, page, cell);
22861
+ this._drawTableCellBordersAndBg(ctx, page, cell, false);
22143
22862
  const { sections, marginLeft, marginTop } = cell;
22144
22863
  alignOffsetNoAngle = Vector2.create(alignOffsetNoAngle.x + marginLeft, alignOffsetNoAngle.y + marginTop);
22145
22864
  ctx.save();
@@ -22176,24 +22895,14 @@ var Documents = class Documents extends DocComponent {
22176
22895
  } else {
22177
22896
  this._drawLiquid.translateSave();
22178
22897
  this._drawLiquid.translateLine(line, true, true);
22898
+ this._drawLineBackground(ctx, cell, line, page.marginLeft, page.marginTop);
22179
22899
  const divideLength = divides.length;
22180
22900
  for (let i = 0; i < divideLength; i++) {
22181
22901
  const divide = divides[i];
22182
22902
  const { glyphGroup } = divide;
22183
22903
  this._drawLiquid.translateSave();
22184
22904
  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
- }
22905
+ this._drawGlyphGroupBackgrounds(ctx, parentScale, glyphGroup, lineHeight, alignOffset, centerAngle, vertexAngle, backgroundExtension);
22197
22906
  for (const glyph of glyphGroup) {
22198
22907
  if (!glyph.content || glyph.content.length === 0) continue;
22199
22908
  const { width: spanWidth, left: spanLeft, xOffset } = glyph;
@@ -22225,8 +22934,8 @@ var Documents = class Documents extends DocComponent {
22225
22934
  }
22226
22935
  ctx.restore();
22227
22936
  }
22228
- _drawTableCellBordersAndBg(ctx, page, cell) {
22229
- var _rowSke$index, _cellSource$backgroun;
22937
+ _drawTableCellBordersAndBg(ctx, page, cell, drawBackground = true) {
22938
+ var _rowSke$index, _cellSource$backgroun2;
22230
22939
  const { marginLeft, marginTop } = page;
22231
22940
  const { pageWidth, pageHeight } = cell;
22232
22941
  const rowSke = cell.parent;
@@ -22241,10 +22950,10 @@ var Documents = class Documents extends DocComponent {
22241
22950
  let { x, y } = this._drawLiquid;
22242
22951
  x += marginLeft;
22243
22952
  y += marginTop;
22244
- if ((_cellSource$backgroun = cellSource.backgroundColor) === null || _cellSource$backgroun === void 0 ? void 0 : _cellSource$backgroun.rgb) {
22953
+ if (drawBackground && ((_cellSource$backgroun2 = cellSource.backgroundColor) === null || _cellSource$backgroun2 === void 0 ? void 0 : _cellSource$backgroun2.rgb)) {
22245
22954
  ctx.save();
22246
22955
  ctx.fillStyle = cellSource.backgroundColor.rgb;
22247
- ctx.fillRectByPrecision(x, y, pageWidth, pageHeight);
22956
+ fillRectByPrecisionBounds(ctx, x, y, pageWidth, pageHeight);
22248
22957
  ctx.restore();
22249
22958
  }
22250
22959
  const position = {
@@ -22292,8 +23001,9 @@ var Documents = class Documents extends DocComponent {
22292
23001
  }
22293
23002
  _drawHeaderFooter(page, ctx, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale, parentPage, isHeader = true) {
22294
23003
  if (this._drawLiquid == null) return;
22295
- const { sections } = page;
23004
+ const { sections, skeTables } = page;
22296
23005
  const { y: originY } = this._drawLiquid;
23006
+ if (skeTables.size > 0) this._drawTable(ctx, page, skeTables, extensions, backgroundExtension, glyphExtensionsExcludeBackground, alignOffsetNoAngle, centerAngle, vertexAngle, renderConfig, parentScale);
22297
23007
  for (const section of sections) {
22298
23008
  const { columns } = section;
22299
23009
  this._drawLiquid.translateSave();
@@ -22322,33 +23032,20 @@ var Documents = class Documents extends DocComponent {
22322
23032
  this._drawLiquid.translateSave();
22323
23033
  this._drawLiquid.translateLine(line, true, true);
22324
23034
  const { y } = this._drawLiquid;
22325
- if (isHeader) {
22326
- if (y - originY + alignOffset.y > (parentPage.pageHeight - 100) / 2) {
23035
+ if (!isHeader) {
23036
+ if (y - originY + alignOffset.y + lineHeight < (parentPage.pageHeight - 100) / 2 + 100) {
22327
23037
  this._drawLiquid.translateRestore();
22328
23038
  continue;
22329
23039
  }
22330
- } else if (y - originY + alignOffset.y + lineHeight < (parentPage.pageHeight - 100) / 2 + 100) {
22331
- this._drawLiquid.translateRestore();
22332
- continue;
22333
23040
  }
23041
+ this._drawLineBackground(ctx, page, line, parentPage.marginLeft);
22334
23042
  const divideLength = divides.length;
22335
23043
  for (let i = 0; i < divideLength; i++) {
22336
23044
  const divide = divides[i];
22337
23045
  const { glyphGroup } = divide;
22338
23046
  this._drawLiquid.translateSave();
22339
23047
  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
- }
23048
+ this._drawGlyphGroupBackgrounds(ctx, parentScale, glyphGroup, lineHeight, alignOffset, centerAngle, vertexAngle, backgroundExtension);
22352
23049
  for (const glyph of glyphGroup) {
22353
23050
  if (!glyph.content || glyph.content.length === 0) continue;
22354
23051
  const { width: spanWidth, left: spanLeft, xOffset } = glyph;
@@ -22384,18 +23081,19 @@ var Documents = class Documents extends DocComponent {
22384
23081
  * In Excel, if horizontal alignment is not specified,
22385
23082
  * rotated text aligns to the right when rotated downwards and aligns to the left when rotated upwards.
22386
23083
  */
22387
- if (horizontalAlign === _univerjs_core.HorizontalAlign.UNSPECIFIED) if (centerAngleDeg === 90 && vertexAngleDeg === 90) horizontalAlign = _univerjs_core.HorizontalAlign.CENTER;
23084
+ let resolvedHorizontalAlign = horizontalAlign;
23085
+ if (resolvedHorizontalAlign === _univerjs_core.HorizontalAlign.UNSPECIFIED) if (centerAngleDeg === 90 && vertexAngleDeg === 90) resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.CENTER;
22388
23086
  else if (vertexAngleDeg > 0 && vertexAngleDeg !== 90 || vertexAngleDeg === -90)
22389
23087
  /**
22390
23088
  * https://github.com/dream-num/univer-pro/issues/334
22391
23089
  */
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;
23090
+ resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.RIGHT;
23091
+ else if (cellValueType === _univerjs_core.CellValueType.NUMBER) resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.RIGHT;
23092
+ else if (cellValueType === _univerjs_core.CellValueType.BOOLEAN) resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.CENTER;
23093
+ else resolvedHorizontalAlign = _univerjs_core.HorizontalAlign.LEFT;
22396
23094
  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;
23095
+ if (resolvedHorizontalAlign === _univerjs_core.HorizontalAlign.CENTER) offsetLeft = (this.width - pageWidth) / 2;
23096
+ else if (resolvedHorizontalAlign === _univerjs_core.HorizontalAlign.RIGHT) offsetLeft = this.width - pageWidth - pagePaddingRight;
22399
23097
  else offsetLeft = pagePaddingLeft;
22400
23098
  return offsetLeft;
22401
23099
  }
@@ -22429,6 +23127,22 @@ function setTableCellBorderDash(ctx, dashStyle) {
22429
23127
  }
22430
23128
  ctx.setLineDash([0]);
22431
23129
  }
23130
+ function fillRectByPrecisionBounds(ctx, x, y, width, height) {
23131
+ const { scaleX, scaleY } = ctx.getScale();
23132
+ const startX = fixLineWidthByScale(x, scaleX);
23133
+ const startY = fixLineWidthByScale(y, scaleY);
23134
+ const endX = fixLineWidthByScale(x + width, scaleX);
23135
+ const endY = fixLineWidthByScale(y + height, scaleY);
23136
+ ctx.fillRect(startX, startY, endX - startX, endY - startY);
23137
+ }
23138
+ function rectByPrecisionBounds(ctx, x, y, width, height) {
23139
+ const { scaleX, scaleY } = ctx.getScale();
23140
+ const startX = fixLineWidthByScale(x, scaleX);
23141
+ const startY = fixLineWidthByScale(y, scaleY);
23142
+ const endX = fixLineWidthByScale(x + width, scaleX);
23143
+ const endY = fixLineWidthByScale(y + height, scaleY);
23144
+ ctx.rect(startX, startY, endX - startX, endY - startY);
23145
+ }
22432
23146
 
22433
23147
  //#endregion
22434
23148
  //#region src/components/sheets/spreadsheet.ts
@@ -23641,6 +24355,8 @@ var DocBackground = class DocBackground extends DocComponent {
23641
24355
  _defineProperty(this, "_pageFillColor", void 0);
23642
24356
  _defineProperty(this, "_pageStrokeColor", void 0);
23643
24357
  _defineProperty(this, "_marginStrokeColor", void 0);
24358
+ _defineProperty(this, "_pageBackgroundSource", void 0);
24359
+ _defineProperty(this, "_pageBackgroundImage", void 0);
23644
24360
  this._drawLiquid = new Liquid();
23645
24361
  this._backgroundFillColor = config === null || config === void 0 ? void 0 : config.backgroundFillColor;
23646
24362
  this._pageFillColor = config === null || config === void 0 ? void 0 : config.pageFillColor;
@@ -23664,7 +24380,7 @@ var DocBackground = class DocBackground extends DocComponent {
23664
24380
  const skeletonData = (_this$getSkeleton = this.getSkeleton()) === null || _this$getSkeleton === void 0 ? void 0 : _this$getSkeleton.getSkeletonData();
23665
24381
  const docDataModel = (_this$getSkeleton2 = this.getSkeleton()) === null || _this$getSkeleton2 === void 0 ? void 0 : _this$getSkeleton2.getViewModel().getDataModel();
23666
24382
  if (skeletonData == null || docDataModel == null) return;
23667
- const { documentFlavor } = docDataModel.getSnapshot().documentStyle;
24383
+ const { documentFlavor, background } = docDataModel.getSnapshot().documentStyle;
23668
24384
  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
24385
  this._drawWorkspaceBackground(ctx, workspaceFill, bounds);
23670
24386
  if (documentFlavor === _univerjs_core.DocumentFlavor.MODERN) return;
@@ -23693,6 +24409,7 @@ var DocBackground = class DocBackground extends DocComponent {
23693
24409
  zIndex: 3
23694
24410
  };
23695
24411
  Rect.drawWith(ctx, backgroundOptions);
24412
+ 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
24413
  const IDENTIFIER_WIDTH = 15;
23697
24414
  const marginIdentification = {
23698
24415
  dataArray: [
@@ -23773,6 +24490,22 @@ var DocBackground = class DocBackground extends DocComponent {
23773
24490
  });
23774
24491
  ctx.restore();
23775
24492
  }
24493
+ _drawPageBackgroundImage(ctx, source, width, height) {
24494
+ if (!source || width <= 0 || height <= 0) return;
24495
+ const image = this._getPageBackgroundImage(source);
24496
+ if (!image.complete) return;
24497
+ ctx.drawImage(image, 0, 0, width, height);
24498
+ }
24499
+ _getPageBackgroundImage(source) {
24500
+ if (this._pageBackgroundSource === source && this._pageBackgroundImage != null) return this._pageBackgroundImage;
24501
+ const image = document.createElement("img");
24502
+ image.crossOrigin = "anonymous";
24503
+ image.onload = () => this.makeDirty(true);
24504
+ image.src = source;
24505
+ this._pageBackgroundSource = source;
24506
+ this._pageBackgroundImage = image;
24507
+ return image;
24508
+ }
23776
24509
  changeSkeleton(newSkeleton) {
23777
24510
  this.setSkeleton(newSkeleton);
23778
24511
  return this;
@@ -24209,6 +24942,42 @@ var DumbCanvasColorService = class {
24209
24942
  return color;
24210
24943
  }
24211
24944
  };
24945
+ const DARK_RENDER_COLOR_OVERRIDES = {
24946
+ "#17212b": "#e2e8f0",
24947
+ "#64748b": "#94a3b8",
24948
+ "#d9e0e7": "#253044",
24949
+ "#edf1f5": "#1b2535",
24950
+ "#eef2f6": "#1b2535",
24951
+ "#f2f5f8": "#101827",
24952
+ "#f3f6fa": "#18243a",
24953
+ "#f4f8ff": "#172a46",
24954
+ "#f5f9ff": "#12233a",
24955
+ "#f7f9fb": "#0d1422",
24956
+ "#f7f9fc": "#0d1422",
24957
+ "#f8fafc": "#0f172a",
24958
+ "#fbfcfd": "#07111f",
24959
+ "#fcfdff": "#050914",
24960
+ "#e8f1ff": "#173a69",
24961
+ "#eaf5ff": "#12315a",
24962
+ "#dbeafe": "#1e3a8a",
24963
+ "#bfdbfe": "#60a5fa",
24964
+ "#93c5fd": "#60a5fa",
24965
+ "#8eb6f5": "#60a5fa",
24966
+ "#60a5fa": "#60a5fa",
24967
+ "#2563eb": "#60a5fa",
24968
+ "#1d64d8": "#93c5fd",
24969
+ "#1d5cff": "#60a5fa",
24970
+ "#0f766e": "#2dd4bf",
24971
+ "#d7f4ef": "#134e4a",
24972
+ "rgba(37,99,235,0.05)": "rgba(96,165,250,0.16)",
24973
+ "rgba(37,99,235,0.06)": "rgba(96,165,250,0.18)",
24974
+ "rgba(37,99,235,0.08)": "rgba(96,165,250,0.22)",
24975
+ "rgba(37,99,235,0.12)": "rgba(96,165,250,0.26)",
24976
+ "rgba(37,99,235,0.18)": "rgba(96,165,250,0.30)",
24977
+ "rgba(37,99,235,0.28)": "rgba(96,165,250,0.38)",
24978
+ "rgba(239,246,255,0.88)": "rgba(30,64,175,0.72)",
24979
+ "rgba(148,163,184,0.45)": "rgba(148,163,184,0.52)"
24980
+ };
24212
24981
  let CanvasColorService = class CanvasColorService extends _univerjs_core.Disposable {
24213
24982
  constructor(_themeService) {
24214
24983
  super();
@@ -24219,8 +24988,14 @@ let CanvasColorService = class CanvasColorService extends _univerjs_core.Disposa
24219
24988
  getRenderColor(color) {
24220
24989
  if (!this._themeService.darkMode) return color;
24221
24990
  if (this._cache.has(color)) return this._cache.get(color);
24991
+ if (normalizeRenderColor(color) === "transparent") {
24992
+ this._cache.set(color, "transparent");
24993
+ return "transparent";
24994
+ }
24222
24995
  let cachedColor = "";
24223
- if (color.startsWith("#")) {
24996
+ const mappedColor = getDarkRenderColorOverride(color);
24997
+ if (mappedColor) cachedColor = mappedColor;
24998
+ else if (color.startsWith("#")) {
24224
24999
  cachedColor = rgbToHex(this._invertAlgo(hexToRgb(color)));
24225
25000
  if (color.length === 5) {
24226
25001
  const alpha = color.charAt(4);
@@ -24252,6 +25027,15 @@ let CanvasColorService = class CanvasColorService extends _univerjs_core.Disposa
24252
25027
  }
24253
25028
  };
24254
25029
  CanvasColorService = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService))], CanvasColorService);
25030
+ function getDarkRenderColorOverride(color) {
25031
+ var _DARK_RENDER_COLOR_OV;
25032
+ return (_DARK_RENDER_COLOR_OV = DARK_RENDER_COLOR_OVERRIDES[normalizeRenderColor(color)]) !== null && _DARK_RENDER_COLOR_OV !== void 0 ? _DARK_RENDER_COLOR_OV : null;
25033
+ }
25034
+ function normalizeRenderColor(color) {
25035
+ const trimmed = color.trim().toLowerCase();
25036
+ if (trimmed.startsWith("rgb")) return trimmed.replace(/\s+/g, "");
25037
+ return trimmed;
25038
+ }
24255
25039
  function hexToRgb(_hex) {
24256
25040
  const hex = _hex.replace(/^#/, "");
24257
25041
  let r;
@@ -24925,7 +25709,7 @@ Engine = __decorate([__decorateParam(2, ICanvasColorService)], Engine);
24925
25709
  //#endregion
24926
25710
  //#region package.json
24927
25711
  var name = "@univerjs/engine-render";
24928
- var version = "0.25.0";
25712
+ var version = "1.0.0-alpha.0";
24929
25713
 
24930
25714
  //#endregion
24931
25715
  //#region src/config/config.ts
@@ -25397,7 +26181,47 @@ const DEFAULT_TRANSFORMER_LAYER_INDEX = 2;
25397
26181
  const MINI_WIDTH_LIMIT = 20;
25398
26182
  const MINI_HEIGHT_LIMIT = 20;
25399
26183
  const DEFAULT_CONTROL_PLUS_INDEX = 5e3;
25400
- const SINGLE_ACTIVE_OBJECT_TYPE_MAP = new Set([6]);
26184
+ const SINGLE_ACTIVE_OBJECT_TYPE_MAP = /* @__PURE__ */ new Set([6]);
26185
+ const ROTATE_ICON_SIZE = 14;
26186
+ var TransformerRotateIcon = class extends Rect {
26187
+ _draw(ctx) {
26188
+ const iconWidth = this.width || ROTATE_ICON_SIZE;
26189
+ const iconHeight = this.height || ROTATE_ICON_SIZE;
26190
+ const scaleX = iconWidth / 24;
26191
+ const scaleY = iconHeight / 24;
26192
+ ctx.save();
26193
+ ctx.scale(scaleX, scaleY);
26194
+ ctx.beginPath();
26195
+ ctx.lineWidth = (this.strokeWidth || 2) / Math.max(scaleX, scaleY);
26196
+ ctx.lineCap = "round";
26197
+ ctx.lineJoin = "round";
26198
+ ctx.strokeStyle = this.stroke || "currentColor";
26199
+ ctx.moveTo(21, 12);
26200
+ ctx.arc(12, 12, 9, 0, Math.PI * 1.5, false);
26201
+ ctx.bezierCurveTo(14.52, 3, 16.93, 4, 18.74, 5.74);
26202
+ ctx.lineTo(21, 8);
26203
+ ctx.moveTo(21, 3);
26204
+ ctx.lineTo(21, 8);
26205
+ ctx.lineTo(16, 8);
26206
+ ctx.stroke();
26207
+ ctx.restore();
26208
+ }
26209
+ };
26210
+ var TransformerAnchor = class extends Rect {
26211
+ _draw(ctx) {
26212
+ if (!this.shadowColor || !this.shadowBlur && !this.shadowOffsetX && !this.shadowOffsetY) {
26213
+ Rect.drawWith(ctx, this);
26214
+ return;
26215
+ }
26216
+ ctx.save();
26217
+ ctx.shadowColor = this.shadowColor;
26218
+ ctx.shadowBlur = this.shadowBlur;
26219
+ ctx.shadowOffsetX = this.shadowOffsetX;
26220
+ ctx.shadowOffsetY = this.shadowOffsetY;
26221
+ Rect.drawWith(ctx, this);
26222
+ ctx.restore();
26223
+ }
26224
+ };
25401
26225
  /**
25402
26226
  * Transformer constructor. Transformer is a special type of group that allow you transform
25403
26227
  * primitives and shapes. Transforming tool is not changing `width` and `height` properties of nodes
@@ -25416,8 +26240,16 @@ var Transformer = class extends _univerjs_core.Disposable {
25416
26240
  _defineProperty(this, "rotationSnaps", []);
25417
26241
  _defineProperty(this, "rotationSnapTolerance", 5);
25418
26242
  _defineProperty(this, "rotateAnchorOffset", 50);
26243
+ _defineProperty(this, "rotateAnchorPosition", "top");
26244
+ _defineProperty(this, "rotateLineEnabled", true);
25419
26245
  _defineProperty(this, "rotateSize", 10);
25420
26246
  _defineProperty(this, "rotateCornerRadius", 10);
26247
+ _defineProperty(this, "rotateFill", void 0);
26248
+ _defineProperty(this, "rotateStroke", void 0);
26249
+ _defineProperty(this, "rotateStrokeWidth", void 0);
26250
+ _defineProperty(this, "rotateIconEnabled", false);
26251
+ _defineProperty(this, "rotateIconStroke", void 0);
26252
+ _defineProperty(this, "rotateIconStrokeWidth", 1.5);
25421
26253
  _defineProperty(this, "borderEnabled", true);
25422
26254
  _defineProperty(this, "borderStroke", "rgb(97, 97, 97)");
25423
26255
  _defineProperty(this, "borderStrokeWidth", 1);
@@ -25428,10 +26260,19 @@ var Transformer = class extends _univerjs_core.Disposable {
25428
26260
  _defineProperty(this, "anchorStrokeWidth", 1);
25429
26261
  _defineProperty(this, "anchorSize", 10);
25430
26262
  _defineProperty(this, "anchorCornerRadius", 10);
26263
+ _defineProperty(this, "anchorStyle", "default");
26264
+ _defineProperty(this, "anchorSideLongSize", 16);
26265
+ _defineProperty(this, "anchorSideShortSize", 5);
26266
+ _defineProperty(this, "anchorSideCornerRadius", 2.5);
26267
+ _defineProperty(this, "anchorShadowColor", void 0);
26268
+ _defineProperty(this, "anchorShadowBlur", 0);
26269
+ _defineProperty(this, "anchorShadowOffsetX", 0);
26270
+ _defineProperty(this, "anchorShadowOffsetY", 0);
25431
26271
  _defineProperty(this, "keepRatio", true);
25432
26272
  _defineProperty(this, "centeredScaling", false);
25433
26273
  _defineProperty(this, "zeroLeft", 0);
25434
26274
  _defineProperty(this, "zeroTop", 0);
26275
+ _defineProperty(this, "moveBoundaryEnabled", true);
25435
26276
  _defineProperty(
25436
26277
  this,
25437
26278
  /**
@@ -25545,9 +26386,9 @@ var Transformer = class extends _univerjs_core.Disposable {
25545
26386
  }
25546
26387
  _getConfig(applyObject) {
25547
26388
  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;
26389
+ 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
26390
  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;
26391
+ 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
26392
  isCropper = (_objectTransformerCon = objectTransformerConfig.isCropper) !== null && _objectTransformerCon !== void 0 ? _objectTransformerCon : isCropper;
25552
26393
  hoverEnabled = (_objectTransformerCon2 = objectTransformerConfig.hoverEnabled) !== null && _objectTransformerCon2 !== void 0 ? _objectTransformerCon2 : hoverEnabled;
25553
26394
  hoverEnterFunc = (_objectTransformerCon3 = objectTransformerConfig.hoverEnterFunc) !== null && _objectTransformerCon3 !== void 0 ? _objectTransformerCon3 : hoverEnterFunc;
@@ -25557,26 +26398,43 @@ var Transformer = class extends _univerjs_core.Disposable {
25557
26398
  rotationSnaps = (_objectTransformerCon7 = objectTransformerConfig.rotationSnaps) !== null && _objectTransformerCon7 !== void 0 ? _objectTransformerCon7 : rotationSnaps;
25558
26399
  rotationSnapTolerance = (_objectTransformerCon8 = objectTransformerConfig.rotationSnapTolerance) !== null && _objectTransformerCon8 !== void 0 ? _objectTransformerCon8 : rotationSnapTolerance;
25559
26400
  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;
26401
+ rotateAnchorPosition = (_objectTransformerCon10 = objectTransformerConfig.rotateAnchorPosition) !== null && _objectTransformerCon10 !== void 0 ? _objectTransformerCon10 : rotateAnchorPosition;
26402
+ rotateLineEnabled = (_objectTransformerCon11 = objectTransformerConfig.rotateLineEnabled) !== null && _objectTransformerCon11 !== void 0 ? _objectTransformerCon11 : rotateLineEnabled;
26403
+ rotateSize = (_objectTransformerCon12 = objectTransformerConfig.rotateSize) !== null && _objectTransformerCon12 !== void 0 ? _objectTransformerCon12 : rotateSize;
26404
+ rotateCornerRadius = (_objectTransformerCon13 = objectTransformerConfig.rotateCornerRadius) !== null && _objectTransformerCon13 !== void 0 ? _objectTransformerCon13 : rotateCornerRadius;
26405
+ rotateFill = (_objectTransformerCon14 = objectTransformerConfig.rotateFill) !== null && _objectTransformerCon14 !== void 0 ? _objectTransformerCon14 : rotateFill;
26406
+ rotateStroke = (_objectTransformerCon15 = objectTransformerConfig.rotateStroke) !== null && _objectTransformerCon15 !== void 0 ? _objectTransformerCon15 : rotateStroke;
26407
+ rotateStrokeWidth = (_objectTransformerCon16 = objectTransformerConfig.rotateStrokeWidth) !== null && _objectTransformerCon16 !== void 0 ? _objectTransformerCon16 : rotateStrokeWidth;
26408
+ rotateIconEnabled = (_objectTransformerCon17 = objectTransformerConfig.rotateIconEnabled) !== null && _objectTransformerCon17 !== void 0 ? _objectTransformerCon17 : rotateIconEnabled;
26409
+ rotateIconStroke = (_objectTransformerCon18 = objectTransformerConfig.rotateIconStroke) !== null && _objectTransformerCon18 !== void 0 ? _objectTransformerCon18 : rotateIconStroke;
26410
+ rotateIconStrokeWidth = (_objectTransformerCon19 = objectTransformerConfig.rotateIconStrokeWidth) !== null && _objectTransformerCon19 !== void 0 ? _objectTransformerCon19 : rotateIconStrokeWidth;
26411
+ borderEnabled = (_objectTransformerCon20 = objectTransformerConfig.borderEnabled) !== null && _objectTransformerCon20 !== void 0 ? _objectTransformerCon20 : borderEnabled;
26412
+ borderStroke = (_objectTransformerCon21 = objectTransformerConfig.borderStroke) !== null && _objectTransformerCon21 !== void 0 ? _objectTransformerCon21 : borderStroke;
26413
+ borderStrokeWidth = (_objectTransformerCon22 = objectTransformerConfig.borderStrokeWidth) !== null && _objectTransformerCon22 !== void 0 ? _objectTransformerCon22 : borderStrokeWidth;
26414
+ borderDash = (_objectTransformerCon23 = objectTransformerConfig.borderDash) !== null && _objectTransformerCon23 !== void 0 ? _objectTransformerCon23 : borderDash;
26415
+ borderSpacing = (_objectTransformerCon24 = objectTransformerConfig.borderSpacing) !== null && _objectTransformerCon24 !== void 0 ? _objectTransformerCon24 : borderSpacing;
26416
+ anchorFill = (_objectTransformerCon25 = objectTransformerConfig.anchorFill) !== null && _objectTransformerCon25 !== void 0 ? _objectTransformerCon25 : anchorFill;
26417
+ anchorStroke = (_objectTransformerCon26 = objectTransformerConfig.anchorStroke) !== null && _objectTransformerCon26 !== void 0 ? _objectTransformerCon26 : anchorStroke;
26418
+ anchorStrokeWidth = (_objectTransformerCon27 = objectTransformerConfig.anchorStrokeWidth) !== null && _objectTransformerCon27 !== void 0 ? _objectTransformerCon27 : anchorStrokeWidth;
26419
+ anchorSize = (_objectTransformerCon28 = objectTransformerConfig.anchorSize) !== null && _objectTransformerCon28 !== void 0 ? _objectTransformerCon28 : anchorSize;
26420
+ anchorCornerRadius = (_objectTransformerCon29 = objectTransformerConfig.anchorCornerRadius) !== null && _objectTransformerCon29 !== void 0 ? _objectTransformerCon29 : anchorCornerRadius;
26421
+ anchorStyle = (_objectTransformerCon30 = objectTransformerConfig.anchorStyle) !== null && _objectTransformerCon30 !== void 0 ? _objectTransformerCon30 : anchorStyle;
26422
+ anchorSideLongSize = (_objectTransformerCon31 = objectTransformerConfig.anchorSideLongSize) !== null && _objectTransformerCon31 !== void 0 ? _objectTransformerCon31 : anchorSideLongSize;
26423
+ anchorSideShortSize = (_objectTransformerCon32 = objectTransformerConfig.anchorSideShortSize) !== null && _objectTransformerCon32 !== void 0 ? _objectTransformerCon32 : anchorSideShortSize;
26424
+ anchorSideCornerRadius = (_objectTransformerCon33 = objectTransformerConfig.anchorSideCornerRadius) !== null && _objectTransformerCon33 !== void 0 ? _objectTransformerCon33 : anchorSideCornerRadius;
26425
+ anchorShadowColor = (_objectTransformerCon34 = objectTransformerConfig.anchorShadowColor) !== null && _objectTransformerCon34 !== void 0 ? _objectTransformerCon34 : anchorShadowColor;
26426
+ anchorShadowBlur = (_objectTransformerCon35 = objectTransformerConfig.anchorShadowBlur) !== null && _objectTransformerCon35 !== void 0 ? _objectTransformerCon35 : anchorShadowBlur;
26427
+ anchorShadowOffsetX = (_objectTransformerCon36 = objectTransformerConfig.anchorShadowOffsetX) !== null && _objectTransformerCon36 !== void 0 ? _objectTransformerCon36 : anchorShadowOffsetX;
26428
+ anchorShadowOffsetY = (_objectTransformerCon37 = objectTransformerConfig.anchorShadowOffsetY) !== null && _objectTransformerCon37 !== void 0 ? _objectTransformerCon37 : anchorShadowOffsetY;
26429
+ keepRatio = (_objectTransformerCon38 = objectTransformerConfig.keepRatio) !== null && _objectTransformerCon38 !== void 0 ? _objectTransformerCon38 : keepRatio;
26430
+ centeredScaling = (_objectTransformerCon39 = objectTransformerConfig.centeredScaling) !== null && _objectTransformerCon39 !== void 0 ? _objectTransformerCon39 : centeredScaling;
26431
+ enabledAnchors = (_objectTransformerCon40 = objectTransformerConfig.enabledAnchors) !== null && _objectTransformerCon40 !== void 0 ? _objectTransformerCon40 : enabledAnchors;
26432
+ flipEnabled = (_objectTransformerCon41 = objectTransformerConfig.flipEnabled) !== null && _objectTransformerCon41 !== void 0 ? _objectTransformerCon41 : flipEnabled;
26433
+ ignoreStroke = (_objectTransformerCon42 = objectTransformerConfig.ignoreStroke) !== null && _objectTransformerCon42 !== void 0 ? _objectTransformerCon42 : ignoreStroke;
26434
+ boundBoxFunc = (_objectTransformerCon43 = objectTransformerConfig.boundBoxFunc) !== null && _objectTransformerCon43 !== void 0 ? _objectTransformerCon43 : boundBoxFunc;
26435
+ useSingleNodeRotation = (_objectTransformerCon44 = objectTransformerConfig.useSingleNodeRotation) !== null && _objectTransformerCon44 !== void 0 ? _objectTransformerCon44 : useSingleNodeRotation;
26436
+ shouldOverdrawWholeArea = (_objectTransformerCon45 = objectTransformerConfig.shouldOverdrawWholeArea) !== null && _objectTransformerCon45 !== void 0 ? _objectTransformerCon45 : shouldOverdrawWholeArea;
26437
+ moveBoundaryEnabled = (_objectTransformerCon46 = objectTransformerConfig.moveBoundaryEnabled) !== null && _objectTransformerCon46 !== void 0 ? _objectTransformerCon46 : moveBoundaryEnabled;
25580
26438
  }
25581
26439
  return {
25582
26440
  isCropper,
@@ -25588,8 +26446,16 @@ var Transformer = class extends _univerjs_core.Disposable {
25588
26446
  rotationSnaps,
25589
26447
  rotationSnapTolerance,
25590
26448
  rotateAnchorOffset,
26449
+ rotateAnchorPosition,
26450
+ rotateLineEnabled,
25591
26451
  rotateSize,
25592
26452
  rotateCornerRadius,
26453
+ rotateFill,
26454
+ rotateStroke,
26455
+ rotateStrokeWidth,
26456
+ rotateIconEnabled,
26457
+ rotateIconStroke,
26458
+ rotateIconStrokeWidth,
25593
26459
  borderEnabled,
25594
26460
  borderStroke,
25595
26461
  borderStrokeWidth,
@@ -25600,6 +26466,14 @@ var Transformer = class extends _univerjs_core.Disposable {
25600
26466
  anchorStrokeWidth,
25601
26467
  anchorSize,
25602
26468
  anchorCornerRadius,
26469
+ anchorStyle,
26470
+ anchorSideLongSize,
26471
+ anchorSideShortSize,
26472
+ anchorSideCornerRadius,
26473
+ anchorShadowColor,
26474
+ anchorShadowBlur,
26475
+ anchorShadowOffsetX,
26476
+ anchorShadowOffsetY,
25603
26477
  keepRatio,
25604
26478
  centeredScaling,
25605
26479
  enabledAnchors,
@@ -25607,7 +26481,8 @@ var Transformer = class extends _univerjs_core.Disposable {
25607
26481
  ignoreStroke,
25608
26482
  boundBoxFunc,
25609
26483
  useSingleNodeRotation,
25610
- shouldOverdrawWholeArea
26484
+ shouldOverdrawWholeArea,
26485
+ moveBoundaryEnabled
25611
26486
  };
25612
26487
  }
25613
26488
  attachTo(applyObject) {
@@ -25641,7 +26516,7 @@ var Transformer = class extends _univerjs_core.Disposable {
25641
26516
  this._copperSelectedObject = applyObject;
25642
26517
  this._changeStart$.next({
25643
26518
  target: applyObject,
25644
- objects: new Map([[applyObject.oKey, applyObject]]),
26519
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
25645
26520
  type: 0
25646
26521
  });
25647
26522
  }
@@ -25669,7 +26544,7 @@ var Transformer = class extends _univerjs_core.Disposable {
25669
26544
  event
25670
26545
  });
25671
26546
  else this._changeEnd$.next({
25672
- objects: new Map([[applyObject.oKey, applyObject]]),
26547
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
25673
26548
  type: 2,
25674
26549
  offsetX,
25675
26550
  offsetY,
@@ -25716,6 +26591,10 @@ var Transformer = class extends _univerjs_core.Disposable {
25716
26591
  });
25717
26592
  }
25718
26593
  _checkMoveBoundary(moveObject, moveLeft, moveTop, ancestorLeft, ancestorTop, topSceneWidth, topSceneHeight) {
26594
+ if (this._getConfig(moveObject).moveBoundaryEnabled === false) return {
26595
+ moveLeft,
26596
+ moveTop
26597
+ };
25719
26598
  const { left, top, width, height } = moveObject;
25720
26599
  let resultMoveLeft = moveLeft;
25721
26600
  let resultMoveTop = moveTop;
@@ -25765,7 +26644,7 @@ var Transformer = class extends _univerjs_core.Disposable {
25765
26644
  moveTop = boundary.moveTop;
25766
26645
  cropper.translate(moveLeft + cropper.left, moveTop + cropper.top);
25767
26646
  this._changing$.next({
25768
- objects: new Map([[cropper.oKey, cropper]]),
26647
+ objects: /* @__PURE__ */ new Map([[cropper.oKey, cropper]]),
25769
26648
  moveX: moveLeft,
25770
26649
  moveY: moveTop,
25771
26650
  type: 1,
@@ -25800,7 +26679,7 @@ var Transformer = class extends _univerjs_core.Disposable {
25800
26679
  } else {
25801
26680
  this._moveFunc(applyObject, type, x, y, keepRatio, isCropper, isGroup);
25802
26681
  this._changing$.next({
25803
- objects: new Map([[applyObject.oKey, applyObject]]),
26682
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
25804
26683
  type: 1,
25805
26684
  offsetX: moveOffsetX,
25806
26685
  offsetY: moveOffsetY
@@ -26047,7 +26926,7 @@ var Transformer = class extends _univerjs_core.Disposable {
26047
26926
  });
26048
26927
  } else {
26049
26928
  this._changeStart$.next({
26050
- objects: new Map([[applyObject.oKey, applyObject]]),
26929
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
26051
26930
  type: 0
26052
26931
  });
26053
26932
  const { width, height, left, top } = applyObject.getState();
@@ -26088,7 +26967,7 @@ var Transformer = class extends _univerjs_core.Disposable {
26088
26967
  } else {
26089
26968
  this._recoverySizeBoundary([applyObject], ancestorLeft, ancestorTop, topSceneWidth, topSceneHeight);
26090
26969
  this._changeEnd$.next({
26091
- objects: new Map([[applyObject.oKey, applyObject]]),
26970
+ objects: /* @__PURE__ */ new Map([[applyObject.oKey, applyObject]]),
26092
26971
  type: 2,
26093
26972
  offsetX,
26094
26973
  offsetY,
@@ -26163,7 +27042,11 @@ var Transformer = class extends _univerjs_core.Disposable {
26163
27042
  _rotateMoving(moveOffsetX, moveOffsetY, centerX, centerY, agentOrigin) {
26164
27043
  const { ancestorScaleX, ancestorScaleY } = this._scene;
26165
27044
  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));
27045
+ const moveSceneX = moveOffsetX / ancestorScaleX + this._viewportScrollX;
27046
+ const moveSceneY = moveOffsetY / ancestorScaleY + this._viewportScrollY;
27047
+ const startSceneX = this._startOffsetX / ancestorScaleX + this._viewportScrollX;
27048
+ const startSceneY = this._startOffsetY / ancestorScaleY + this._viewportScrollY;
27049
+ let angle = agentOrigin + radToDeg(Math.atan2(moveSceneY - centerY, moveSceneX - centerX) - Math.atan2(startSceneY - centerY, startSceneX - centerX));
26167
27050
  if (angle < 0) angle = 360 + angle;
26168
27051
  angle %= 360;
26169
27052
  angle = this._smoothAccuracy(angle);
@@ -26220,6 +27103,23 @@ var Transformer = class extends _univerjs_core.Disposable {
26220
27103
  }
26221
27104
  return cursor;
26222
27105
  }
27106
+ _createRotateIcon(applyObject, zIndex, left, top) {
27107
+ const { rotateSize, rotateIconStroke, rotateIconStrokeWidth, borderStroke } = this._getConfig(applyObject);
27108
+ const iconOffset = (rotateSize - ROTATE_ICON_SIZE) / 2;
27109
+ return new TransformerRotateIcon(`__SpreadsheetTransformerRotate___ICON_${zIndex}`, {
27110
+ zIndex,
27111
+ evented: false,
27112
+ left: left + iconOffset,
27113
+ top: top + iconOffset,
27114
+ width: ROTATE_ICON_SIZE,
27115
+ height: ROTATE_ICON_SIZE,
27116
+ fill: null,
27117
+ stroke: rotateIconStroke !== null && rotateIconStroke !== void 0 ? rotateIconStroke : borderStroke,
27118
+ strokeWidth: rotateIconStrokeWidth,
27119
+ strokeLineCap: "round",
27120
+ strokeLineJoin: "round"
27121
+ });
27122
+ }
26223
27123
  _getCopperAnchorPosition(type, height, width, applyObject) {
26224
27124
  const { borderStrokeWidth, borderSpacing, anchorSize } = this._getConfig(applyObject);
26225
27125
  let left = 0;
@@ -26266,17 +27166,18 @@ var Transformer = class extends _univerjs_core.Disposable {
26266
27166
  };
26267
27167
  }
26268
27168
  _getRotateAnchorPosition(type, height, width, applyObject) {
26269
- const { rotateAnchorOffset, rotateSize, borderStrokeWidth, borderSpacing, anchorSize } = this._getConfig(applyObject);
27169
+ const { rotateAnchorOffset, rotateAnchorPosition, rotateSize, borderStrokeWidth, borderSpacing, anchorSize } = this._getConfig(applyObject);
27170
+ const isBottomRotateAnchor = rotateAnchorPosition === "bottom";
26270
27171
  let left = -anchorSize / 2;
26271
27172
  let top = -anchorSize / 2;
26272
27173
  switch (type) {
26273
27174
  case "__SpreadsheetTransformerRotate__":
26274
27175
  left = width / 2 - rotateSize / 2;
26275
- top = -rotateAnchorOffset - borderSpacing - borderStrokeWidth * 2 - rotateSize;
27176
+ top = isBottomRotateAnchor ? height + rotateAnchorOffset + borderSpacing + borderStrokeWidth * 2 : -rotateAnchorOffset - borderSpacing - borderStrokeWidth * 2 - rotateSize;
26276
27177
  break;
26277
27178
  case "__SpreadsheetTransformerRotateLine__":
26278
27179
  left = width / 2;
26279
- top = -rotateAnchorOffset - borderSpacing - borderStrokeWidth;
27180
+ top = isBottomRotateAnchor ? height + borderSpacing + borderStrokeWidth : -rotateAnchorOffset - borderSpacing - borderStrokeWidth;
26280
27181
  break;
26281
27182
  case "__SpreadsheetTransformerResizeLT__":
26282
27183
  left += -borderSpacing - borderStrokeWidth;
@@ -26316,21 +27217,43 @@ var Transformer = class extends _univerjs_core.Disposable {
26316
27217
  top
26317
27218
  };
26318
27219
  }
27220
+ _isMiddleAnchor(type) {
27221
+ return type === "__SpreadsheetTransformerResizeCT__" || type === "__SpreadsheetTransformerResizeLM__" || type === "__SpreadsheetTransformerResizeRM__" || type === "__SpreadsheetTransformerResizeCB__";
27222
+ }
27223
+ _getResizeAnchorProps(type, applyObject) {
27224
+ const { anchorSize, anchorCornerRadius, anchorStyle, anchorSideLongSize, anchorSideShortSize, anchorSideCornerRadius } = this._getConfig(applyObject);
27225
+ if (anchorStyle !== "canva" || !this._isMiddleAnchor(type)) return {
27226
+ width: anchorSize,
27227
+ height: anchorSize,
27228
+ radius: anchorStyle === "canva" ? anchorSize / 2 : anchorCornerRadius
27229
+ };
27230
+ const isHorizontal = type === "__SpreadsheetTransformerResizeCT__" || type === "__SpreadsheetTransformerResizeCB__";
27231
+ return {
27232
+ width: isHorizontal ? anchorSideLongSize : anchorSideShortSize,
27233
+ height: isHorizontal ? anchorSideShortSize : anchorSideLongSize,
27234
+ radius: anchorSideCornerRadius
27235
+ };
27236
+ }
26319
27237
  _createResizeAnchor(type, applyObject, zIndex) {
26320
27238
  const { height = 0, width = 0, scaleX = 1, scaleY = 1 } = applyObject.getState();
26321
- const { anchorFill, anchorStroke, anchorStrokeWidth, anchorCornerRadius, anchorSize } = this._getConfig(applyObject);
27239
+ const { anchorFill, anchorStroke, anchorStrokeWidth, anchorSize, anchorShadowColor, anchorShadowBlur, anchorShadowOffsetX, anchorShadowOffsetY } = this._getConfig(applyObject);
26322
27240
  const { left, top } = this._getRotateAnchorPosition(type, height, width, applyObject);
27241
+ const anchorProps = this._getResizeAnchorProps(type, applyObject);
26323
27242
  const cursor = this._getRotateAnchorCursor(type);
26324
- const anchor = new Rect(`${type}_${zIndex}`, {
27243
+ const anchor = new TransformerAnchor(`${type}_${zIndex}`, {
26325
27244
  zIndex: zIndex - 1,
26326
27245
  fill: anchorFill,
26327
27246
  stroke: anchorStroke,
26328
27247
  strokeWidth: anchorStrokeWidth,
26329
- width: anchorSize,
26330
- height: anchorSize,
26331
- radius: anchorCornerRadius,
26332
- left,
26333
- top
27248
+ width: anchorProps.width,
27249
+ height: anchorProps.height,
27250
+ radius: anchorProps.radius,
27251
+ left: left + (anchorSize - anchorProps.width) / 2,
27252
+ top: top + (anchorSize - anchorProps.height) / 2,
27253
+ shadowColor: anchorShadowColor,
27254
+ shadowBlur: anchorShadowBlur,
27255
+ shadowOffsetX: anchorShadowOffsetX,
27256
+ shadowOffsetY: anchorShadowOffsetY
26334
27257
  });
26335
27258
  this._attachHover(anchor, cursor, "default");
26336
27259
  return anchor;
@@ -26578,7 +27501,7 @@ var Transformer = class extends _univerjs_core.Disposable {
26578
27501
  _createControl(applyObject, isSkipOnCropper = true) {
26579
27502
  const { left = 0, top = 0, height = 0, width = 0 } = applyObject.getState();
26580
27503
  const angle = applyObject.angle;
26581
- const { isCropper, resizeEnabled, rotateEnabled, rotateAnchorOffset, rotateSize, rotateCornerRadius, borderEnabled, borderStroke, borderStrokeWidth, borderSpacing, enabledAnchors } = this._getConfig(applyObject);
27504
+ 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
27505
  if (isSkipOnCropper && isCropper) return;
26583
27506
  const oKey = applyObject.oKey;
26584
27507
  const zIndex = this._selectedObjectMap.size + applyObject.maxZIndex + DEFAULT_CONTROL_PLUS_INDEX;
@@ -26609,19 +27532,26 @@ var Transformer = class extends _univerjs_core.Disposable {
26609
27532
  });
26610
27533
  const { left: rotateLeft, top: rotateTop } = this._getRotateAnchorPosition("__SpreadsheetTransformerRotate__", height, width, applyObject);
26611
27534
  const cursor = this._getRotateAnchorCursor("__SpreadsheetTransformerRotate__");
26612
- const rotate = new Rect(`__SpreadsheetTransformerRotate___${zIndex}`, {
27535
+ const rotate = new TransformerAnchor(`__SpreadsheetTransformerRotate___${zIndex}`, {
26613
27536
  zIndex: zIndex - 1,
26614
27537
  left: rotateLeft,
26615
27538
  top: rotateTop,
26616
27539
  height: rotateSize,
26617
27540
  width: rotateSize,
26618
27541
  radius: rotateCornerRadius,
26619
- strokeWidth: borderStrokeWidth * 2,
26620
- stroke: borderStroke
27542
+ fill: rotateFill,
27543
+ strokeWidth: rotateStrokeWidth !== null && rotateStrokeWidth !== void 0 ? rotateStrokeWidth : borderStrokeWidth * 2,
27544
+ stroke: rotateStroke !== null && rotateStroke !== void 0 ? rotateStroke : borderStroke,
27545
+ shadowColor: anchorShadowColor,
27546
+ shadowBlur: anchorShadowBlur,
27547
+ shadowOffsetX: anchorShadowOffsetX,
27548
+ shadowOffsetY: anchorShadowOffsetY
26621
27549
  });
26622
27550
  this._attachEventToRotate(rotate, applyObject);
26623
27551
  this._attachHover(rotate, cursor, "default");
26624
- groupElements.push(rotateLine, rotate);
27552
+ if (rotateLineEnabled) groupElements.push(rotateLine);
27553
+ groupElements.push(rotate);
27554
+ if (rotateIconEnabled) groupElements.push(this._createRotateIcon(applyObject, zIndex, rotateLeft, rotateTop));
26625
27555
  }
26626
27556
  }
26627
27557
  if (resizeEnabled) for (let i = 0, len = enabledAnchors.length; i < len; i++) {