@univerjs/engine-render 1.0.0-alpha.2 → 1.0.0-alpha.3

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
@@ -1,11 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
4
  var __exportAll = (all, no_symbols) => {
10
5
  let target = {};
11
6
  for (var name in all) {
@@ -19,29 +14,9 @@ var __exportAll = (all, no_symbols) => {
19
14
  }
20
15
  return target;
21
16
  };
22
- var __copyProps = (to, from, except, desc) => {
23
- if (from && typeof from === "object" || typeof from === "function") {
24
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
25
- key = keys[i];
26
- if (!__hasOwnProp.call(to, key) && key !== except) {
27
- __defProp(to, key, {
28
- get: ((k) => from[k]).bind(null, key),
29
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
30
- });
31
- }
32
- }
33
- }
34
- return to;
35
- };
36
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
37
- value: mod,
38
- enumerable: true
39
- }) : target, mod));
40
17
 
41
18
  //#endregion
42
19
  let _univerjs_core = require("@univerjs/core");
43
- let cjk_regex = require("cjk-regex");
44
- cjk_regex = __toESM(cjk_regex);
45
20
  let rxjs = require("rxjs");
46
21
  let opentype_js = require("opentype.js");
47
22
  let franc_min = require("franc-min");
@@ -324,7 +299,7 @@ function getFontStyleString(textStyle) {
324
299
  let bold = _univerjs_core.FontStyleType.BOLD;
325
300
  if (textStyle.bl === 0 || textStyle.bl === void 0) bold = _univerjs_core.FontStyleType.NORMAL;
326
301
  let originFontSize = defaultFontSize;
327
- if (textStyle.fs) originFontSize = Math.ceil(textStyle.fs);
302
+ if (textStyle.fs) originFontSize = textStyle.fs;
328
303
  let fontSize = originFontSize;
329
304
  const fontFamilyResult = normalizeFontFamily(textStyle.ff, defaultFont);
330
305
  const { va: baselineOffset } = textStyle;
@@ -348,18 +323,6 @@ function normalizeFontFamily(fontFamily, defaultFont) {
348
323
  return family.includes(" ") ? `"${family}"` : family;
349
324
  }).filter(Boolean).join(", ");
350
325
  }
351
- const CJK_LETTER_REG = cjk_regex.letters().toRegExp();
352
- function hasCJKText(text) {
353
- return CJK_LETTER_REG.test(text);
354
- }
355
- const CJK_ALL_REG = cjk_regex.all().toRegExp();
356
- function hasCJK(text) {
357
- return CJK_ALL_REG.test(text);
358
- }
359
- const CJK_PUNCTUATION_REG = cjk_regex.punctuations().toRegExp();
360
- function hasCJKPunctuation(text) {
361
- return CJK_PUNCTUATION_REG.test(text);
362
- }
363
326
  function hasAllLatin(text) {
364
327
  if (!/[\u0000-\u024F]/gi.exec(text)) return false;
365
328
  return true;
@@ -948,6 +911,220 @@ _defineProperty(FontCache, "_context", void 0);
948
911
  _defineProperty(FontCache, "_fontDataMap", /* @__PURE__ */ new Map());
949
912
  _defineProperty(FontCache, "_globalFontMeasureCache", /* @__PURE__ */ new Map());
950
913
 
914
+ //#endregion
915
+ //#region src/basics/cjk-regexp.ts
916
+ /**
917
+ * Copyright 2023-present DreamNum Co., Ltd.
918
+ *
919
+ * Licensed under the Apache License, Version 2.0 (the "License");
920
+ * you may not use this file except in compliance with the License.
921
+ * You may obtain a copy of the License at
922
+ *
923
+ * http://www.apache.org/licenses/LICENSE-2.0
924
+ *
925
+ * Unless required by applicable law or agreed to in writing, software
926
+ * distributed under the License is distributed on an "AS IS" BASIS,
927
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
928
+ * See the License for the specific language governing permissions and
929
+ * limitations under the License.
930
+ */
931
+ /**
932
+ * Golden regex sources generated from `cjk-regex@3.4.0`.
933
+ *
934
+ * Keep these strings stable unless intentionally upgrading cjk-regex semantics. The tests
935
+ * assert exact source equality so document CJK layout behavior does not drift through
936
+ * manual range edits.
937
+ */
938
+ const CJK_LETTER_SOURCE = String.raw`[\u1100-\u11ff\u2e80-\u2e99\u2e9b-\u2ef3\u2f00-\u2fd5\u3005\u3007\u3021-\u3029\u3038-\u303b\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fd-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u321e\u3260-\u327e\u32d0-\u32fe\u3300-\u3357\u3400-\u4dbf\u4e00-\u9fff\ua960-\ua97c\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\uff66-\uff6f\uff71-\uff9d\uffa0-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc]|[\ud840-\ud868\ud86a-\ud86d\ud86f-\ud872\ud874-\ud879\ud880-\ud883\ud885-\ud88c][\udc00-\udfff]|\ud81b[\udfe3\udff2-\udff6]|\ud82b[\udff0-\udff3\udff5-\udffb\udffd-\udffe]|\ud82c[\udc00-\udd22\udd32\udd50-\udd52\udd55\udd64-\udd67]|\ud83c[\ude00]|\ud869[\udc00-\udedf\udf00-\udfff]|\ud86e[\udc00-\udc1d\udc20-\udfff]|\ud873[\udc00-\udead\udeb0-\udfff]|\ud87a[\udc00-\udfe0\udff0-\udfff]|\ud87b[\udc00-\ude5d]|\ud87e[\udc00-\ude1d]|\ud884[\udc00-\udf4a\udf50-\udfff]|\ud88d[\udc00-\udc79]`;
939
+ const CJK_PUNCTUATION_SOURCE = String.raw`[\u2ff0-\u3004\u3006\u3008-\u3020\u302a-\u3037\u303c-\u303f\u30a0\u30fb-\u30fc\u3190-\u319f\u31c0-\u31ef\u321f-\u325f\u327f-\u32cf\u32ff\u3358-\u33ff\ufe10-\ufe1f\ufe30-\ufe6f\uff00-\uff65\uff70\uff9e-\uff9f\uffbf-\uffc1\uffc8-\uffc9\uffd0-\uffd1\uffd8-\uffd9\uffdd-\uffef]`;
940
+ const CJK_ALL_SOURCE = String.raw`[\u1100-\u11ff\u2e80-\u2e99\u2e9b-\u2ef3\u2f00-\u2fd5\u2ff0-\u303f\u3041-\u3096\u309d-\u30ff\u3105-\u312f\u3131-\u318e\u3190-\u4dbf\u4e00-\u9fff\ua960-\ua97c\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufe10-\ufe1f\ufe30-\ufe6f\uff00-\uffef]|[\ud840-\ud868\ud86a-\ud86d\ud86f-\ud872\ud874-\ud879\ud880-\ud883\ud885-\ud88c][\udc00-\udfff]|\ud81b[\udfe3\udff2-\udff6]|\ud82b[\udff0-\udff3\udff5-\udffb\udffd-\udffe]|\ud82c[\udc00-\udd22\udd32\udd50-\udd52\udd55\udd64-\udd67]|\ud83c[\ude00]|\ud869[\udc00-\udedf\udf00-\udfff]|\ud86e[\udc00-\udc1d\udc20-\udfff]|\ud873[\udc00-\udead\udeb0-\udfff]|\ud87a[\udc00-\udfe0\udff0-\udfff]|\ud87b[\udc00-\ude5d]|\ud87e[\udc00-\ude1d]|\ud884[\udc00-\udf4a\udf50-\udfff]|\ud88d[\udc00-\udc79]`;
941
+ const CJK_LETTER_REG = new RegExp(CJK_LETTER_SOURCE);
942
+ const CJK_PUNCTUATION_REG = new RegExp(CJK_PUNCTUATION_SOURCE);
943
+ const CJK_ALL_REG = new RegExp(CJK_ALL_SOURCE);
944
+ /**
945
+ * Golden code-point ranges generated from `cjk-regex@3.4.0` snapshots.
946
+ *
947
+ * These are kept alongside the regex sources so compatibility can be checked against
948
+ * both matching behavior and `Charset.data`-style range snapshots.
949
+ */
950
+ const CJK_LETTER_DATA = [
951
+ [4352, 4607],
952
+ [11904, 11929],
953
+ [11931, 12019],
954
+ [12032, 12245],
955
+ [12293, 12293],
956
+ [12295, 12295],
957
+ [12321, 12329],
958
+ [12344, 12347],
959
+ [12353, 12438],
960
+ [12445, 12447],
961
+ [12449, 12538],
962
+ [12541, 12543],
963
+ [12549, 12591],
964
+ [12593, 12686],
965
+ [12704, 12735],
966
+ [12784, 12830],
967
+ [12896, 12926],
968
+ [13008, 13054],
969
+ [13056, 13143],
970
+ [13312, 19903],
971
+ [19968, 40959],
972
+ [43360, 43388],
973
+ [44032, 55203],
974
+ [55216, 55238],
975
+ [55243, 55291],
976
+ [63744, 64109],
977
+ [64112, 64217],
978
+ [65382, 65391],
979
+ [65393, 65437],
980
+ [65440, 65470],
981
+ [65474, 65479],
982
+ [65482, 65487],
983
+ [65490, 65495],
984
+ [65498, 65500],
985
+ [94179, 94179],
986
+ [94194, 94198],
987
+ [110576, 110579],
988
+ [110581, 110587],
989
+ [110589, 110590],
990
+ [110592, 110882],
991
+ [110898, 110898],
992
+ [110928, 110930],
993
+ [110933, 110933],
994
+ [110948, 110951],
995
+ [127488, 127488],
996
+ [131072, 173791],
997
+ [173824, 178205],
998
+ [178208, 183981],
999
+ [183984, 191456],
1000
+ [191472, 192093],
1001
+ [194560, 195101],
1002
+ [196608, 201546],
1003
+ [201552, 210041]
1004
+ ];
1005
+ const CJK_PUNCTUATION_DATA = [
1006
+ [12272, 12292],
1007
+ [12294, 12294],
1008
+ [12296, 12320],
1009
+ [12330, 12343],
1010
+ [12348, 12351],
1011
+ [12448, 12448],
1012
+ [12539, 12540],
1013
+ [12688, 12703],
1014
+ [12736, 12783],
1015
+ [12831, 12895],
1016
+ [12927, 13007],
1017
+ [13055, 13055],
1018
+ [13144, 13311],
1019
+ [65040, 65055],
1020
+ [65072, 65135],
1021
+ [65280, 65381],
1022
+ [65392, 65392],
1023
+ [65438, 65439],
1024
+ [65471, 65473],
1025
+ [65480, 65481],
1026
+ [65488, 65489],
1027
+ [65496, 65497],
1028
+ [65501, 65519]
1029
+ ];
1030
+ const CJK_ALL_DATA = [
1031
+ [4352, 4607],
1032
+ [11904, 11929],
1033
+ [11931, 12019],
1034
+ [12032, 12245],
1035
+ [12272, 12351],
1036
+ [12353, 12438],
1037
+ [12445, 12543],
1038
+ [12549, 12591],
1039
+ [12593, 12686],
1040
+ [12688, 19903],
1041
+ [19968, 40959],
1042
+ [43360, 43388],
1043
+ [44032, 55203],
1044
+ [55216, 55238],
1045
+ [55243, 55291],
1046
+ [63744, 64109],
1047
+ [64112, 64217],
1048
+ [65040, 65055],
1049
+ [65072, 65135],
1050
+ [65280, 65519],
1051
+ [94179, 94179],
1052
+ [94194, 94198],
1053
+ [110576, 110579],
1054
+ [110581, 110587],
1055
+ [110589, 110590],
1056
+ [110592, 110882],
1057
+ [110898, 110898],
1058
+ [110928, 110930],
1059
+ [110933, 110933],
1060
+ [110948, 110951],
1061
+ [127488, 127488],
1062
+ [131072, 173791],
1063
+ [173824, 178205],
1064
+ [178208, 183981],
1065
+ [183984, 191456],
1066
+ [191472, 192093],
1067
+ [194560, 195101],
1068
+ [196608, 201546],
1069
+ [201552, 210041]
1070
+ ];
1071
+ /**
1072
+ * Returns the CJK letter charset generated from `cjk-regex@3.4.0`.
1073
+ */
1074
+ function letters() {
1075
+ return _univerjs_core.regexp.charset(...CJK_LETTER_DATA);
1076
+ }
1077
+ /**
1078
+ * Returns the CJK punctuation charset generated from `cjk-regex@3.4.0`.
1079
+ */
1080
+ function punctuations() {
1081
+ return _univerjs_core.regexp.charset(...CJK_PUNCTUATION_DATA);
1082
+ }
1083
+ /**
1084
+ * Returns the combined CJK letter and punctuation charset generated from `cjk-regex@3.4.0`.
1085
+ */
1086
+ function all() {
1087
+ return _univerjs_core.regexp.charset(...CJK_ALL_DATA);
1088
+ }
1089
+ /**
1090
+ * Returns true when text contains CJK letters, excluding punctuation and symbols.
1091
+ */
1092
+ function hasCJKText(text) {
1093
+ return CJK_LETTER_REG.test(text);
1094
+ }
1095
+ /**
1096
+ * Returns true when text contains CJK letters or CJK punctuation.
1097
+ */
1098
+ function hasCJK(text) {
1099
+ return CJK_ALL_REG.test(text);
1100
+ }
1101
+ /**
1102
+ * Returns true when text contains CJK punctuation, excluding CJK letters.
1103
+ */
1104
+ function hasCJKPunctuation(text) {
1105
+ return CJK_PUNCTUATION_REG.test(text);
1106
+ }
1107
+ /**
1108
+ * Namespace-style CJK regex API used by document rendering and layout.
1109
+ */
1110
+ const cjk = {
1111
+ CJK_LETTER_SOURCE,
1112
+ CJK_PUNCTUATION_SOURCE,
1113
+ CJK_ALL_SOURCE,
1114
+ CJK_LETTER_REG,
1115
+ CJK_PUNCTUATION_REG,
1116
+ CJK_ALL_REG,
1117
+ CJK_LETTER_DATA,
1118
+ CJK_PUNCTUATION_DATA,
1119
+ CJK_ALL_DATA,
1120
+ letters,
1121
+ punctuations,
1122
+ all,
1123
+ hasCJKText,
1124
+ hasCJK,
1125
+ hasCJKPunctuation
1126
+ };
1127
+
951
1128
  //#endregion
952
1129
  //#region src/basics/i-document-skeleton-cached.ts
953
1130
  let DocumentSkeletonPageType = /* @__PURE__ */ function(DocumentSkeletonPageType) {
@@ -4858,6 +5035,13 @@ var SheetExtension = class extends ComponentExtension {
4858
5035
  super(..._args);
4859
5036
  _defineProperty(this, "type", 0);
4860
5037
  }
5038
+ /**
5039
+ * Return an isolated instance when this extension is safe to render in a print scene.
5040
+ * Editor-only extensions remain excluded by default.
5041
+ */
5042
+ copyForPrinting() {
5043
+ return null;
5044
+ }
4861
5045
  isRenderDiffRangesByCell(rangeP, diffRanges) {
4862
5046
  if (diffRanges == null || diffRanges.length === 0) return true;
4863
5047
  for (const range of diffRanges) {
@@ -4944,6 +5128,11 @@ const UNIQUE_KEY$10 = "DefaultBackgroundExtension";
4944
5128
  */
4945
5129
  const DOC_EXTENSION_Z_INDEX$3 = 21;
4946
5130
  const PRINTING_Z_INDEX = 21;
5131
+ function getRangeCellCount(ranges) {
5132
+ return ranges.reduce((sum, range) => {
5133
+ return sum + Math.max(range.endRow - range.startRow + 1, 0) * Math.max(range.endColumn - range.startColumn + 1, 0);
5134
+ }, 0);
5135
+ }
4947
5136
  var Background = class extends SheetExtension {
4948
5137
  constructor(..._args) {
4949
5138
  super(..._args);
@@ -4955,7 +5144,7 @@ var Background = class extends SheetExtension {
4955
5144
  var _this$parent;
4956
5145
  return ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.isPrinting) ? this.PRINTING_Z_INDEX : this.Z_INDEX;
4957
5146
  }
4958
- draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges, { viewRanges, checkOutOfViewBound }) {
5147
+ draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges, { viewRanges, checkOutOfViewBound, hasMergeData = true }) {
4959
5148
  const { stylesCache, worksheet, rowHeightAccumulation, columnTotalWidth, columnWidthAccumulation, rowTotalHeight } = spreadsheetSkeleton;
4960
5149
  const { background: bgMatrixCacheByColor, backgroundPositions } = stylesCache;
4961
5150
  if (!worksheet || !bgMatrixCacheByColor) return;
@@ -4973,15 +5162,19 @@ var Background = class extends SheetExtension {
4973
5162
  spreadsheetSkeleton
4974
5163
  };
4975
5164
  const mergeRanges = [];
4976
- viewRanges.forEach((range) => {
5165
+ if (hasMergeData) viewRanges.forEach((range) => {
4977
5166
  const intersectMergeRangesInViewRanges = spreadsheetSkeleton.worksheet.getMergedCellRange(range.startRow, range.startColumn, range.endRow, range.endColumn);
4978
5167
  mergeRanges.push(...intersectMergeRangesInViewRanges);
4979
5168
  });
4980
5169
  const renderBGCore = (rgb) => {
4981
5170
  const bgColorMatrix = bgMatrixCacheByColor[rgb];
5171
+ const renderRanges = diffRanges && diffRanges.length > 0 ? diffRanges : viewRanges;
4982
5172
  const rangeForEachFn = (row, col, bgConfigParam) => {
4983
- if (spreadsheetSkeleton.worksheet.getSpanModel().getMergeDataIndex(row, col) !== -1) return;
4984
- const cellInfo = spreadsheetSkeleton.getCellByIndexWithNoHeader(row, col);
5173
+ var _backgroundPositions$;
5174
+ if (hasMergeData) {
5175
+ if (spreadsheetSkeleton.worksheet.getSpanModel().getMergeDataIndex(row, col) !== -1) return;
5176
+ }
5177
+ const cellInfo = (_backgroundPositions$ = backgroundPositions === null || backgroundPositions === void 0 ? void 0 : backgroundPositions.getValue(row, col)) !== null && _backgroundPositions$ !== void 0 ? _backgroundPositions$ : spreadsheetSkeleton.getCellByIndexWithNoHeader(row, col);
4985
5178
  if (!cellInfo) return;
4986
5179
  if (bgConfigParam || bgColorMatrix.getValue(row, col)) {
4987
5180
  renderBGContext.cellInfo = cellInfo;
@@ -4997,12 +5190,16 @@ var Background = class extends SheetExtension {
4997
5190
  renderBGContext.backgroundPaths = backgroundPaths;
4998
5191
  ctx.beginPath();
4999
5192
  const matrixSize = bgColorMatrix.getSizeOf();
5000
- if (viewRanges.reduce((sum, range) => {
5001
- return sum + (range.endRow - range.startRow) * (range.endColumn - range.startColumn);
5002
- }, 0) < matrixSize) viewRanges.forEach((range) => {
5003
- _univerjs_core.Range.foreach(range, rangeForEachFn);
5004
- });
5005
- else bgColorMatrix.forValue(rangeForEachFn);
5193
+ if (getRangeCellCount(renderRanges) < matrixSize) {
5194
+ renderBGContext.skipRenderRangeCheck = true;
5195
+ renderRanges.forEach((range) => {
5196
+ _univerjs_core.Range.foreach(range, rangeForEachFn);
5197
+ });
5198
+ renderBGContext.skipRenderRangeCheck = false;
5199
+ } else {
5200
+ renderBGContext.skipRenderRangeCheck = false;
5201
+ bgColorMatrix.forValue(rangeForEachFn);
5202
+ }
5006
5203
  ctx.fill(backgroundPaths);
5007
5204
  ctx.closePath();
5008
5205
  };
@@ -5031,12 +5228,12 @@ var Background = class extends SheetExtension {
5031
5228
  for (let index = 0; index < rgbList.length; index++) {
5032
5229
  const rgb = rgbList[index];
5033
5230
  renderBGCore(rgb);
5034
- renderBGForMergedCells(rgb);
5231
+ if (hasMergeData) renderBGForMergedCells(rgb);
5035
5232
  }
5036
5233
  ctx.restore();
5037
5234
  }
5038
5235
  renderBGByCell(bgContext, row, col) {
5039
- const { spreadsheetSkeleton, backgroundPaths, scaleX, scaleY, viewRanges, diffRanges, cellInfo } = bgContext;
5236
+ const { spreadsheetSkeleton, backgroundPaths, scaleX, scaleY, viewRanges, diffRanges, cellInfo, skipRenderRangeCheck } = bgContext;
5040
5237
  let { startY, endY, startX, endX } = cellInfo;
5041
5238
  const { isMerged, isMergedMainCell, mergeInfo } = cellInfo;
5042
5239
  const renderRange = diffRanges && diffRanges.length > 0 ? diffRanges : viewRanges;
@@ -5044,7 +5241,7 @@ var Background = class extends SheetExtension {
5044
5241
  endY = mergeInfo.endY;
5045
5242
  startX = mergeInfo.startX;
5046
5243
  endX = mergeInfo.endX;
5047
- if (!isMerged && !isMergedMainCell && !inViewRanges(renderRange, row, col)) return true;
5244
+ if (!skipRenderRangeCheck && !isMerged && !isMergedMainCell && !inViewRanges(renderRange, row, col)) return true;
5048
5245
  if (!isMerged && !isMergedMainCell) {
5049
5246
  if (!spreadsheetSkeleton.worksheet.getRowVisible(row)) return true;
5050
5247
  if (!spreadsheetSkeleton.worksheet.getColVisible(col)) return true;
@@ -11812,11 +12009,12 @@ var Text = class Text extends Shape {
11812
12009
  this.skeleton = new DocSimpleSkeleton(props.text, props.fontStyle, Boolean(props.warp), props.width, props.height);
11813
12010
  }
11814
12011
  static drawWith(ctx, props, _skeleton) {
11815
- var _props$color;
12012
+ var _cachedLayout$lines, _cachedLayout$totalHe, _props$color;
11816
12013
  const { text, fontStyle, warp, hAlign, vAlign, width, height, left = 0, top = 0, cellValueType } = props;
11817
- const skeleton = _skeleton !== null && _skeleton !== void 0 ? _skeleton : new DocSimpleSkeleton(text, fontStyle, Boolean(warp), width, vAlign === _univerjs_core.VerticalAlign.TOP ? height : Infinity);
11818
- const lines = skeleton.calculate();
11819
- const totalHeight = skeleton.getTotalHeight();
12014
+ const cachedLayout = !_skeleton && !warp ? Text._getCachedLayout(text, fontStyle) : null;
12015
+ const skeleton = cachedLayout ? null : _skeleton !== null && _skeleton !== void 0 ? _skeleton : new DocSimpleSkeleton(text, fontStyle, Boolean(warp), width, vAlign === _univerjs_core.VerticalAlign.TOP ? height : Infinity);
12016
+ const lines = (_cachedLayout$lines = cachedLayout === null || cachedLayout === void 0 ? void 0 : cachedLayout.lines) !== null && _cachedLayout$lines !== void 0 ? _cachedLayout$lines : skeleton.calculate();
12017
+ const totalHeight = (_cachedLayout$totalHe = cachedLayout === null || cachedLayout === void 0 ? void 0 : cachedLayout.totalHeight) !== null && _cachedLayout$totalHe !== void 0 ? _cachedLayout$totalHe : skeleton.getTotalHeight();
11820
12018
  let lineTop = top + (vAlign === _univerjs_core.VerticalAlign.TOP ? 0 : vAlign === _univerjs_core.VerticalAlign.MIDDLE ? (height - totalHeight) / 2 : height - totalHeight);
11821
12019
  ctx.save();
11822
12020
  ctx.font = fontStyle;
@@ -11867,6 +12065,46 @@ var Text = class Text extends Shape {
11867
12065
  ctx.restore();
11868
12066
  return totalHeight;
11869
12067
  }
12068
+ static drawPlainWith(ctx, props) {
12069
+ var _props$color2;
12070
+ const { text, fontStyle, hAlign, vAlign, width, height, left = 0, top = 0, cellValueType } = props;
12071
+ const { lines, totalHeight } = Text._getCachedLayout(text, fontStyle);
12072
+ let lineTop = top + (vAlign === _univerjs_core.VerticalAlign.TOP ? 0 : vAlign === _univerjs_core.VerticalAlign.MIDDLE ? (height - totalHeight) / 2 : height - totalHeight);
12073
+ ctx.font = fontStyle;
12074
+ ctx.fillStyle = (_props$color2 = props.color) !== null && _props$color2 !== void 0 ? _props$color2 : COLOR_BLACK_RGB;
12075
+ for (const line of lines) {
12076
+ const lineWidth = line.width;
12077
+ let lineX = 0;
12078
+ if (!(width < lineWidth && cellValueType === _univerjs_core.CellValueType.NUMBER)) switch (hAlign) {
12079
+ case _univerjs_core.HorizontalAlign.CENTER:
12080
+ lineX = (width - lineWidth) / 2;
12081
+ break;
12082
+ case _univerjs_core.HorizontalAlign.RIGHT:
12083
+ lineX = width - lineWidth;
12084
+ break;
12085
+ default: lineX = 0;
12086
+ }
12087
+ ctx.fillText(line.text, left + lineX, lineTop + line.baseline);
12088
+ lineTop += line.height;
12089
+ }
12090
+ return totalHeight;
12091
+ }
12092
+ static _getCachedLayout(text, fontStyle) {
12093
+ const cacheKey = `${fontStyle}\u0000${text}`;
12094
+ const cached = Text._layoutCache.get(cacheKey);
12095
+ if (cached) return cached;
12096
+ const skeleton = new DocSimpleSkeleton(text, fontStyle, false, 0, Infinity);
12097
+ const layout = {
12098
+ lines: skeleton.calculate(),
12099
+ totalHeight: skeleton.getTotalHeight()
12100
+ };
12101
+ Text._layoutCache.set(cacheKey, layout);
12102
+ if (Text._layoutCache.size > Text._MAX_LAYOUT_CACHE_SIZE) {
12103
+ const oldestKey = Text._layoutCache.keys().next().value;
12104
+ if (oldestKey !== void 0) Text._layoutCache.delete(oldestKey);
12105
+ }
12106
+ return layout;
12107
+ }
11870
12108
  /**
11871
12109
  * Draw text decoration lines (underline, strikethrough, etc.)
11872
12110
  */
@@ -11999,6 +12237,8 @@ var Text = class Text extends Shape {
11999
12237
  };
12000
12238
  }
12001
12239
  };
12240
+ _defineProperty(Text, "_MAX_LAYOUT_CACHE_SIZE", 5e3);
12241
+ _defineProperty(Text, "_layoutCache", /* @__PURE__ */ new Map());
12002
12242
 
12003
12243
  //#endregion
12004
12244
  //#region src/components/docs/document-compatibility.ts
@@ -12714,6 +12954,34 @@ var DocumentViewModel = class DocumentViewModel {
12714
12954
  }
12715
12955
  };
12716
12956
 
12957
+ //#endregion
12958
+ //#region src/components/docs/custom-block-render-viewport.ts
12959
+ let docsCustomBlockRenderViewportProvider = null;
12960
+ const docsCustomBlockRenderViewportProviders = /* @__PURE__ */ new Set();
12961
+ function setDocsCustomBlockRenderViewportProvider(provider) {
12962
+ if (provider == null) {
12963
+ docsCustomBlockRenderViewportProvider = null;
12964
+ docsCustomBlockRenderViewportProviders.clear();
12965
+ return () => {};
12966
+ }
12967
+ docsCustomBlockRenderViewportProvider = provider;
12968
+ docsCustomBlockRenderViewportProviders.add(provider);
12969
+ return () => {
12970
+ var _providers;
12971
+ docsCustomBlockRenderViewportProviders.delete(provider);
12972
+ const providers = Array.from(docsCustomBlockRenderViewportProviders);
12973
+ docsCustomBlockRenderViewportProvider = (_providers = providers[providers.length - 1]) !== null && _providers !== void 0 ? _providers : null;
12974
+ };
12975
+ }
12976
+ function getDocsCustomBlockRenderViewport(unitId, blockId, input) {
12977
+ const providers = docsCustomBlockRenderViewportProviders.size ? Array.from(docsCustomBlockRenderViewportProviders).reverse() : docsCustomBlockRenderViewportProvider ? [docsCustomBlockRenderViewportProvider] : [];
12978
+ for (const provider of providers) {
12979
+ const viewport = provider(unitId, blockId, input);
12980
+ if (viewport != null) return viewport;
12981
+ }
12982
+ return null;
12983
+ }
12984
+
12717
12985
  //#endregion
12718
12986
  //#region src/components/docs/layout/model/glyph.ts
12719
12987
  function isSpace(char) {
@@ -12724,7 +12992,7 @@ function isSpace(char) {
12724
12992
  ].includes(char);
12725
12993
  }
12726
12994
  function isJustifiable(content) {
12727
- return isSpace(content) || hasCJKText(content) || isCjkLeftAlignedPunctuation(content) || isCjkRightAlignedPunctuation(content) || isCjkCenterAlignedPunctuation(content);
12995
+ return isSpace(content) || cjk.hasCJKText(content) || isCjkLeftAlignedPunctuation(content) || isCjkRightAlignedPunctuation(content) || isCjkCenterAlignedPunctuation(content);
12728
12996
  }
12729
12997
  function baseAdjustability(content, width) {
12730
12998
  if (isSpace(content)) return {
@@ -12853,7 +13121,7 @@ function _createSkeletonWordOrLetter(glyphType, content, config, glyphWidth, gly
12853
13121
  const { width: contentWidth = 0 } = bBox;
12854
13122
  let width = glyphWidth !== null && glyphWidth !== void 0 ? glyphWidth : contentWidth;
12855
13123
  if (validationGrid(gridType, snapToGrid)) {
12856
- width = contentWidth + (hasCJK(content) ? charSpace : charSpace / 2);
13124
+ width = contentWidth + (cjk.hasCJK(content) ? charSpace : charSpace / 2);
12857
13125
  if (gridType === _univerjs_core.GridType.SNAP_TO_CHARS) xOffset = (width - contentWidth) / 2;
12858
13126
  }
12859
13127
  if (glyphInfo && glyphInfo.kerning !== 0 && glyphInfo.font) {
@@ -13749,6 +14017,12 @@ function isBeyondDivideWidth(width, divideWidth) {
13749
14017
  const tolerance = Math.min(MAX_LINE_WIDTH_TOLERANCE, Math.max(MIN_LINE_WIDTH_TOLERANCE, divideWidth * RELATIVE_LINE_WIDTH_TOLERANCE));
13750
14018
  return width - divideWidth > tolerance;
13751
14019
  }
14020
+ function isGlyphGroupBeyondDivideWidth(glyphGroup, offsetLeft, divideWidth) {
14021
+ var _glyphGroup$adjustabi, _glyphGroup;
14022
+ const width = __getGlyphGroupWidth(glyphGroup);
14023
+ const trailingShrinkability = (_glyphGroup$adjustabi = (_glyphGroup = glyphGroup[glyphGroup.length - 1]) === null || _glyphGroup === void 0 || (_glyphGroup = _glyphGroup.adjustability) === null || _glyphGroup === void 0 || (_glyphGroup = _glyphGroup.shrinkability) === null || _glyphGroup === void 0 ? void 0 : _glyphGroup[1]) !== null && _glyphGroup$adjustabi !== void 0 ? _glyphGroup$adjustabi : 0;
14024
+ return isBeyondDivideWidth(offsetLeft + width - trailingShrinkability, divideWidth);
14025
+ }
13752
14026
  function layoutParagraph(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType = "Normal") {
13753
14027
  if (isParagraphFirstShapedText) if (paragraphConfig.bulletSkeleton) {
13754
14028
  var _paragraphProperties$;
@@ -13825,12 +14099,11 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13825
14099
  const divideInfo = getLastNotFullDivideInfo(getLastPage(pages));
13826
14100
  if (divideInfo) {
13827
14101
  var _divide$glyphGroup;
13828
- const width = __getGlyphGroupWidth(glyphGroup);
13829
14102
  const { divide, isLast } = divideInfo;
13830
14103
  const lastGlyph = divide === null || divide === void 0 || (_divide$glyphGroup = divide.glyphGroup) === null || _divide$glyphGroup === void 0 ? void 0 : _divide$glyphGroup[divide.glyphGroup.length - 1];
13831
14104
  const preOffsetLeft = ((lastGlyph === null || lastGlyph === void 0 ? void 0 : lastGlyph.width) || 0) + ((lastGlyph === null || lastGlyph === void 0 ? void 0 : lastGlyph.left) || 0);
13832
14105
  const { hyphenationZone } = sectionBreakConfig;
13833
- if (isBeyondDivideWidth(preOffsetLeft + width, divide.width)) {
14106
+ if (isGlyphGroupBeyondDivideWidth(glyphGroup, preOffsetLeft, divide.width)) {
13834
14107
  if ((divide === null || divide === void 0 ? void 0 : divide.glyphGroup.length) === 0 && glyphGroup.length > 0 && glyphGroup[0].streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK) {
13835
14108
  addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13836
14109
  updateDivideInfo(divide, { breakType: breakPointType });
@@ -13853,7 +14126,7 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13853
14126
  const sliceGlyphGroup = [];
13854
14127
  while (glyphGroup.length) {
13855
14128
  sliceGlyphGroup.push(glyphGroup.shift());
13856
- if (isBeyondDivideWidth(__getGlyphGroupWidth(sliceGlyphGroup), divide.width)) {
14129
+ if (isGlyphGroupBeyondDivideWidth(sliceGlyphGroup, 0, divide.width)) {
13857
14130
  if (sliceGlyphGroup.length > 1) glyphGroup.unshift(sliceGlyphGroup.pop());
13858
14131
  break;
13859
14132
  }
@@ -13904,7 +14177,7 @@ function _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphCo
13904
14177
  if (anchorDrawings.length > 0) {
13905
14178
  var _paragraphConfig$para, _paragraphConfig$pDra;
13906
14179
  const paragraphAnchorLeft = __getParagraphAnchorLeft(sectionBreakConfig, paragraphConfig, (_paragraphConfig$para = paragraphConfig.paragraphStyle) === null || _paragraphConfig$para === void 0 ? void 0 : _paragraphConfig$para.indentStart);
13907
- 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);
14180
+ const drawings = __getDrawingPosition(ctx, 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, false);
13908
14181
  __updateDrawingPosition(currentLine.parent, drawings);
13909
14182
  addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
13910
14183
  updateDivideInfo(divide, { breakType: breakPointType });
@@ -14004,6 +14277,7 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
14004
14277
  }
14005
14278
  }
14006
14279
  let deferredInlineGroupAnchorDrawings = [];
14280
+ let deferredTopBottomAnchorDrawings = [];
14007
14281
  if (paragraphNonInlineSkeDrawings != null && paragraphNonInlineSkeDrawings.size > 0) {
14008
14282
  var _pDrawingAnchor$get;
14009
14283
  let targetDrawings = [...paragraphNonInlineSkeDrawings.values()].filter((drawing) => drawing.drawingOrigin.docTransform.positionV.relativeFrom !== _univerjs_core.ObjectRelativeFromV.LINE);
@@ -14011,13 +14285,17 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
14011
14285
  deferredInlineGroupAnchorDrawings = targetDrawings.filter((drawing) => glyphGroupCustomBlockIds.has(drawing.drawingId) && drawing.drawingOrigin.docTransform.positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE);
14012
14286
  targetDrawings = targetDrawings.filter((drawing) => !deferredInlineGroupAnchorDrawings.includes(drawing));
14013
14287
  }
14014
- __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);
14288
+ deferredTopBottomAnchorDrawings = targetDrawings.filter((drawing) => glyphGroupCustomBlockIds.has(drawing.drawingId) && drawing.drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM);
14289
+ targetDrawings = targetDrawings.filter((drawing) => drawing.drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM);
14290
+ __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, false, deferredTopBottomAnchorDrawings.length > 0);
14015
14291
  }
14016
14292
  if (skeTablesInParagraph != null && skeTablesInParagraph.length > 0) {
14017
14293
  var _pDrawingAnchor$get2;
14018
14294
  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);
14019
14295
  }
14020
- const newLineTop = positionedCustomBlockOnly ? lineTop : calculateLineTopByDrawings(lineHeight, lineTop, lastPage, headerPage, footerPage);
14296
+ const calculatedLineTop = positionedCustomBlockOnly ? lineTop : calculateLineTopByDrawings(lineHeight, lineTop, lastPage, headerPage, footerPage);
14297
+ const previousTopBottomCustomBlockFlowBottom = deferredTopBottomAnchorDrawings.length > 0 ? paragraphConfig.topBottomCustomBlockFlowBottom : void 0;
14298
+ const newLineTop = previousTopBottomCustomBlockFlowBottom == null ? calculatedLineTop : Math.max(calculatedLineTop, previousTopBottomCustomBlockFlowBottom);
14021
14299
  if (lineHeight + newLineTop - section.height > LINE_LAYOUT_OVERFLOW_TOLERANCE && column.lines.length > 0 && lastPage.sections.length > 0 || needOpenNewPageByTableLayout) {
14022
14300
  setColumnFullState(column, true);
14023
14301
  _columnOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType, defaultGlyphLineHeight);
@@ -14051,16 +14329,21 @@ function _lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConf
14051
14329
  }, column.width, lineIndex, isParagraphFirstShapedText, paragraphConfig, lastPage, headerPage, footerPage);
14052
14330
  column.lines.push(newLine);
14053
14331
  newLine.parent = column;
14054
- createAndUpdateBlockAnchor(paragraphIndex, newLine, lineTop, pDrawingAnchor);
14332
+ const blockAnchorTop = deferredTopBottomAnchorDrawings.length > 0 ? newLineTop : lineTop;
14333
+ createAndUpdateBlockAnchor(paragraphIndex, newLine, blockAnchorTop, pDrawingAnchor);
14334
+ if (deferredTopBottomAnchorDrawings.length > 0) {
14335
+ __updateAndPositionDrawings(ctx, newLineTop, lineHeight, column, deferredTopBottomAnchorDrawings, paragraphConfig.paragraphIndex, isParagraphFirstShapedText, blockAnchorTop, paragraphAnchorLeft, true, true);
14336
+ __updateTopBottomCustomBlockFlowBottom(paragraphConfig, deferredTopBottomAnchorDrawings);
14337
+ }
14055
14338
  _divideOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType, defaultGlyphLineHeight);
14056
14339
  if (deferredInlineGroupAnchorDrawings.length > 0) {
14057
14340
  var _pDrawingAnchor$get3;
14058
14341
  __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);
14059
14342
  }
14060
14343
  }
14061
- function __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDrawings, paragraphIndex, isParagraphFirstShapedText, drawingAnchorTop, drawingAnchorLeft = 0, skipRelayoutCheck = false) {
14344
+ function __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDrawings, paragraphIndex, isParagraphFirstShapedText, drawingAnchorTop, drawingAnchorLeft = 0, skipRelayoutCheck = false, overwriteTopBottomPosition = false) {
14062
14345
  if (targetDrawings.length === 0) return;
14063
- const drawings = __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, drawingAnchorTop, targetDrawings, drawingAnchorLeft);
14346
+ const drawings = __getDrawingPosition(ctx, lineTop, lineHeight, column, isParagraphFirstShapedText, drawingAnchorTop, targetDrawings, drawingAnchorLeft);
14064
14347
  if (drawings == null || drawings.size === 0) return;
14065
14348
  const floatObjects = [...drawings.values()].filter((drawing) => {
14066
14349
  const layoutType = drawing.drawingOrigin.layoutType;
@@ -14082,7 +14365,7 @@ function __updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDra
14082
14365
  };
14083
14366
  });
14084
14367
  if (!skipRelayoutCheck) _reLayoutCheck(ctx, floatObjects, column, paragraphIndex);
14085
- __updateDrawingPosition(column, drawings);
14368
+ __updateDrawingPosition(column, drawings, overwriteTopBottomPosition);
14086
14369
  }
14087
14370
  function __updateWrapTablePosition(ctx, table, lineTop, lineHeight, column, paragraphIndex, drawingAnchorTop) {
14088
14371
  const wrapTablePosition = __getWrapTablePosition(table, column, lineTop, lineHeight, drawingAnchorTop);
@@ -14193,6 +14476,15 @@ function _getCustomBlockIdsInLine(line) {
14193
14476
  for (const divide of line.divides) for (const glyph of divide.glyphGroup) if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK) customBlockIds.push(glyph.drawingId);
14194
14477
  return customBlockIds;
14195
14478
  }
14479
+ function __updateTopBottomCustomBlockFlowBottom(paragraphConfig, drawings) {
14480
+ for (const drawing of drawings) {
14481
+ var _drawingOrigin$distB, _paragraphConfig$topB;
14482
+ const { drawingOrigin } = drawing;
14483
+ if (drawingOrigin.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM || drawingOrigin.behindDoc === _univerjs_core.BooleanNumber.TRUE) continue;
14484
+ const bottom = drawing.aTop + drawing.height + ((_drawingOrigin$distB = drawingOrigin.distB) !== null && _drawingOrigin$distB !== void 0 ? _drawingOrigin$distB : 0);
14485
+ paragraphConfig.topBottomCustomBlockFlowBottom = Math.max((_paragraphConfig$topB = paragraphConfig.topBottomCustomBlockFlowBottom) !== null && _paragraphConfig$topB !== void 0 ? _paragraphConfig$topB : Number.NEGATIVE_INFINITY, bottom);
14486
+ }
14487
+ }
14196
14488
  function __isZeroWidthNonFlowFloatingAnchorLine(glyphGroup, paragraphNonInlineSkeDrawings) {
14197
14489
  return __getZeroWidthNonFlowFloatingAnchorDrawings(glyphGroup, paragraphNonInlineSkeDrawings).length > 0;
14198
14490
  }
@@ -14396,7 +14688,8 @@ function getLineHeightMetrics(glyphLineHeight, paragraphLineGapDefault, linePitc
14396
14688
  }
14397
14689
  const usesDocumentGrid = spacingRule === _univerjs_core.SpacingRule.AUTO && snapToGrid === _univerjs_core.BooleanNumber.TRUE && gridType !== _univerjs_core.GridType.DEFAULT;
14398
14690
  if (spacingRule === _univerjs_core.SpacingRule.AUTO) {
14399
- const lineSpacingApply = usesDocumentGrid ? lineSpacing * linePitch : scaleAutoLineSpacingByGlyphHeight ? lineSpacing * glyphLineHeight : glyphLineHeight;
14691
+ let lineSpacingApply = usesDocumentGrid ? lineSpacing * linePitch : scaleAutoLineSpacingByGlyphHeight ? lineSpacing * glyphLineHeight : glyphLineHeight;
14692
+ if (!usesDocumentGrid && scaleAutoLineSpacingByGlyphHeight && lineSpacing <= 1.05 && glyphLineHeight >= 30) lineSpacingApply *= 1.18;
14400
14693
  const padding = (lineSpacingApply - glyphLineHeight) / 2;
14401
14694
  return {
14402
14695
  paddingTop: padding,
@@ -14424,7 +14717,7 @@ function getLineHeightMetrics(glyphLineHeight, paragraphLineGapDefault, linePitc
14424
14717
  lineSpacingApply: exactLineSpacingApply
14425
14718
  };
14426
14719
  }
14427
- function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnchorTop, paragraphNonInlineSkeDrawings) {
14720
+ function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, unitId = "", blockAnchorTop, paragraphNonInlineSkeDrawings) {
14428
14721
  var _line$parent, _section$top;
14429
14722
  const column = line.parent;
14430
14723
  const section = column === null || column === void 0 ? void 0 : column.parent;
@@ -14436,6 +14729,7 @@ function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnch
14436
14729
  const sectionTop = (_section$top = section === null || section === void 0 ? void 0 : section.top) !== null && _section$top !== void 0 ? _section$top : 0;
14437
14730
  const lineTop = sectionTop + top;
14438
14731
  for (const divide of line.divides) for (const glyph of divide.glyphGroup) if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK && glyph.width !== 0) {
14732
+ var _viewport$width, _viewport$height, _viewport$offsetLeft;
14439
14733
  const { drawingId } = glyph;
14440
14734
  if (drawingId == null) continue;
14441
14735
  const drawing = paragraphInlineSkeDrawings === null || paragraphInlineSkeDrawings === void 0 ? void 0 : paragraphInlineSkeDrawings.get(drawingId);
@@ -14445,7 +14739,19 @@ function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnch
14445
14739
  const { size, angle } = docTransform;
14446
14740
  const { width = 0, height = 0 } = size;
14447
14741
  const glyphHeight = glyph.bBox.bd + glyph.bBox.ba;
14448
- drawing.aLeft = column.left + divide.left + divide.paddingLeft + glyph.left + .5 * glyph.width - .5 * width || 0;
14742
+ const glyphLeft = divide.left + divide.paddingLeft + glyph.left;
14743
+ const blockLeft = column.left + glyphLeft;
14744
+ const viewport = getDocsCustomBlockRenderViewport(unitId, drawingId, {
14745
+ blockLeft,
14746
+ fallbackHeight: height,
14747
+ fallbackWidth: width,
14748
+ pageMarginLeft: page.marginLeft,
14749
+ pageMarginRight: page.marginRight,
14750
+ pageWidth: page.pageWidth
14751
+ });
14752
+ const drawingWidth = (_viewport$width = viewport === null || viewport === void 0 ? void 0 : viewport.width) !== null && _viewport$width !== void 0 ? _viewport$width : width;
14753
+ const drawingHeight = (_viewport$height = viewport === null || viewport === void 0 ? void 0 : viewport.height) !== null && _viewport$height !== void 0 ? _viewport$height : height;
14754
+ drawing.aLeft = viewport ? blockLeft + ((_viewport$offsetLeft = viewport.offsetLeft) !== null && _viewport$offsetLeft !== void 0 ? _viewport$offsetLeft : 0) : blockLeft + .5 * glyph.width - .5 * drawingWidth || 0;
14449
14755
  if (glyph.width > divide.width) {
14450
14756
  var _paragraphNonInlineSk;
14451
14757
  for (const positionedDrawing of (_paragraphNonInlineSk = paragraphNonInlineSkeDrawings === null || paragraphNonInlineSkeDrawings === void 0 ? void 0 : paragraphNonInlineSkeDrawings.values()) !== null && _paragraphNonInlineSk !== void 0 ? _paragraphNonInlineSk : []) {
@@ -14455,17 +14761,25 @@ function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnch
14455
14761
  const lineBottom = lineTop + lineHeight;
14456
14762
  if (positionedDrawing.aTop >= lineBottom || positionedBottom <= lineTop) continue;
14457
14763
  const positionedRight = positionedDrawing.aLeft + positionedDrawing.width;
14458
- const drawingRight = drawing.aLeft + width;
14764
+ const drawingRight = drawing.aLeft + drawingWidth;
14459
14765
  if (positionedDrawing.aLeft < drawingRight && positionedRight > drawing.aLeft) {
14460
14766
  var _positionedOrigin$dis;
14461
14767
  drawing.aLeft = Math.max(drawing.aLeft, positionedDrawing.aLeft + positionedDrawing.width + ((_positionedOrigin$dis = positionedOrigin.distR) !== null && _positionedOrigin$dis !== void 0 ? _positionedOrigin$dis : 0));
14462
14768
  }
14463
14769
  }
14464
14770
  }
14465
- drawing.aTop = lineTop + lineHeight - .5 * glyphHeight - .5 * height - marginBottom;
14466
- drawing.width = width;
14467
- drawing.height = height;
14771
+ drawing.width = drawingWidth;
14772
+ drawing.height = drawingHeight;
14773
+ drawing.aTop = lineTop + lineHeight - .5 * glyphHeight - .5 * drawingHeight - marginBottom;
14468
14774
  drawing.angle = angle;
14775
+ drawing.customBlockRenderViewport = viewport ? {
14776
+ bleedLeft: viewport.bleedLeft,
14777
+ bleedWidth: viewport.bleedWidth,
14778
+ contentHeight: viewport.contentHeight,
14779
+ contentWidth: viewport.contentWidth,
14780
+ height: viewport.height,
14781
+ viewportHeight: viewport.viewportHeight
14782
+ } : void 0;
14469
14783
  drawing.isPageBreak = isPageBreak;
14470
14784
  drawing.lineTop = lineTop;
14471
14785
  drawing.columnLeft = column.left;
@@ -14475,7 +14789,7 @@ function updateInlineDrawingPosition(line, paragraphInlineSkeDrawings, blockAnch
14475
14789
  }
14476
14790
  page.skeDrawings = new Map([...page.skeDrawings, ...drawings]);
14477
14791
  }
14478
- function __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShapedText, blockAnchorTop, needPositionDrawings = [], blockAnchorLeft = 0) {
14792
+ function __getDrawingPosition(ctx, lineTop, lineHeight, column, isParagraphFirstShapedText, blockAnchorTop, needPositionDrawings = [], blockAnchorLeft = 0, normalizeTraditionalColumnAnchor = true) {
14479
14793
  var _column$parent3;
14480
14794
  const page = (_column$parent3 = column.parent) === null || _column$parent3 === void 0 ? void 0 : _column$parent3.parent;
14481
14795
  if (page == null || needPositionDrawings.length === 0) return;
@@ -14483,22 +14797,42 @@ function __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShape
14483
14797
  const isPageBreak = __checkPageBreak(column);
14484
14798
  if (isPageBreak && !isParagraphFirstShapedText) return;
14485
14799
  for (const drawing of needPositionDrawings) {
14486
- var _getPositionHorizon2, _getPositionVertical2;
14800
+ var _ctx$dataModel$getUni, _ctx$dataModel$getUni2, _ctx$dataModel, _viewport$width2, _viewport$height2, _getPositionHorizon2, _getPositionVertical2;
14487
14801
  const { drawingOrigin } = drawing;
14488
14802
  if (!drawingOrigin) continue;
14489
14803
  const { docTransform } = drawingOrigin;
14490
14804
  const { positionH, positionV, size, angle } = docTransform;
14491
- const { width = 0, height = 0 } = size;
14492
- let aLeft = (_getPositionHorizon2 = getPositionHorizon(positionH, column, page, width, isPageBreak)) !== null && _getPositionHorizon2 !== void 0 ? _getPositionHorizon2 : 0;
14805
+ const { width, height } = size;
14806
+ const fallbackWidth = width !== null && width !== void 0 ? width : 0;
14807
+ const fallbackHeight = height !== null && height !== void 0 ? height : 0;
14808
+ const viewport = drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM ? getDocsCustomBlockRenderViewport((_ctx$dataModel$getUni = (_ctx$dataModel$getUni2 = (_ctx$dataModel = ctx.dataModel).getUnitId) === null || _ctx$dataModel$getUni2 === void 0 ? void 0 : _ctx$dataModel$getUni2.call(_ctx$dataModel)) !== null && _ctx$dataModel$getUni !== void 0 ? _ctx$dataModel$getUni : "", drawing.drawingId, {
14809
+ fallbackHeight,
14810
+ fallbackWidth,
14811
+ pageMarginLeft: page.marginLeft,
14812
+ pageMarginRight: page.marginRight,
14813
+ pageWidth: page.pageWidth
14814
+ }) : null;
14815
+ const drawingWidth = (_viewport$width2 = viewport === null || viewport === void 0 ? void 0 : viewport.width) !== null && _viewport$width2 !== void 0 ? _viewport$width2 : fallbackWidth;
14816
+ const drawingHeight = (_viewport$height2 = viewport === null || viewport === void 0 ? void 0 : viewport.height) !== null && _viewport$height2 !== void 0 ? _viewport$height2 : fallbackHeight;
14817
+ let aLeft = (_getPositionHorizon2 = getPositionHorizon(positionH, column, page, drawingWidth, isPageBreak)) !== null && _getPositionHorizon2 !== void 0 ? _getPositionHorizon2 : 0;
14493
14818
  if (positionH.relativeFrom === _univerjs_core.ObjectRelativeFromH.COLUMN && blockAnchorLeft > 0) {
14494
14819
  const renderedColumnOrigin = isPageBreak ? 0 : column.left || page.marginLeft;
14495
14820
  aLeft += blockAnchorLeft - renderedColumnOrigin;
14821
+ if (normalizeTraditionalColumnAnchor && ctx.dataModel.documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.TRADITIONAL && positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.PARAGRAPH) aLeft -= page.marginLeft;
14496
14822
  }
14497
14823
  drawing.aLeft = aLeft;
14498
- drawing.aTop = (_getPositionVertical2 = getPositionVertical(positionV, page, lineTop, lineHeight, height, blockAnchorTop, isPageBreak)) !== null && _getPositionVertical2 !== void 0 ? _getPositionVertical2 : 0;
14499
- drawing.width = width;
14500
- drawing.height = height;
14824
+ drawing.aTop = (_getPositionVertical2 = getPositionVertical(positionV, page, lineTop, lineHeight, drawingHeight, blockAnchorTop, isPageBreak)) !== null && _getPositionVertical2 !== void 0 ? _getPositionVertical2 : 0;
14825
+ drawing.width = drawingWidth;
14826
+ drawing.height = drawingHeight;
14501
14827
  drawing.angle = angle;
14828
+ drawing.customBlockRenderViewport = viewport ? {
14829
+ bleedLeft: viewport.bleedLeft,
14830
+ bleedWidth: viewport.bleedWidth,
14831
+ contentHeight: viewport.contentHeight,
14832
+ contentWidth: viewport.contentWidth,
14833
+ height: viewport.height,
14834
+ viewportHeight: viewport.viewportHeight
14835
+ } : void 0;
14502
14836
  drawing.initialState = true;
14503
14837
  drawing.columnLeft = column.left;
14504
14838
  drawing.lineTop = lineTop;
@@ -14509,16 +14843,18 @@ function __getDrawingPosition(lineTop, lineHeight, column, isParagraphFirstShape
14509
14843
  }
14510
14844
  return drawings;
14511
14845
  }
14512
- function __updateDrawingPosition(column, drawings) {
14846
+ function __updateDrawingPosition(column, drawings, overwriteTopBottomPosition = false) {
14513
14847
  var _column$parent4;
14514
14848
  const page = (_column$parent4 = column.parent) === null || _column$parent4 === void 0 ? void 0 : _column$parent4.parent;
14515
14849
  if (drawings == null || drawings.size === 0 || page == null) return;
14516
14850
  for (const drawing of drawings.values()) {
14517
14851
  const originDrawing = page.skeDrawings.get(drawing.drawingId);
14518
- if (originDrawing) if (originDrawing.drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) {
14852
+ if (originDrawing) if (originDrawing.drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) if (overwriteTopBottomPosition) page.skeDrawings.set(drawing.drawingId, drawing);
14853
+ else {
14519
14854
  const lowerDrawing = originDrawing.aTop > drawing.aTop ? originDrawing : drawing;
14520
14855
  page.skeDrawings.set(drawing.drawingId, lowerDrawing);
14521
- } else page.skeDrawings.set(drawing.drawingId, drawing);
14856
+ }
14857
+ else page.skeDrawings.set(drawing.drawingId, drawing);
14522
14858
  else page.skeDrawings.set(drawing.drawingId, drawing);
14523
14859
  }
14524
14860
  }
@@ -14847,7 +15183,10 @@ function updateInlineDrawingCoordsAndBorder(ctx, pages) {
14847
15183
  const affectInlineDrawings = paragraphConfig === null || paragraphConfig === void 0 ? void 0 : paragraphConfig.paragraphInlineSkeDrawings;
14848
15184
  const affectNonInlineDrawings = paragraphConfig === null || paragraphConfig === void 0 ? void 0 : paragraphConfig.paragraphNonInlineSkeDrawings;
14849
15185
  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);
14850
- if (affectInlineDrawings && affectInlineDrawings.size > 0) updateInlineDrawingPosition(line, affectInlineDrawings, drawingAnchor === null || drawingAnchor === void 0 ? void 0 : drawingAnchor.top, affectNonInlineDrawings);
15186
+ if (affectInlineDrawings && affectInlineDrawings.size > 0) {
15187
+ var _ctx$dataModel$getUni, _ctx$dataModel$getUni2, _ctx$dataModel;
15188
+ updateInlineDrawingPosition(line, affectInlineDrawings, (_ctx$dataModel$getUni = (_ctx$dataModel$getUni2 = (_ctx$dataModel = ctx.dataModel).getUnitId) === null || _ctx$dataModel$getUni2 === void 0 ? void 0 : _ctx$dataModel$getUni2.call(_ctx$dataModel)) !== null && _ctx$dataModel$getUni !== void 0 ? _ctx$dataModel$getUni : "", drawingAnchor === null || drawingAnchor === void 0 ? void 0 : drawingAnchor.top, affectNonInlineDrawings);
15189
+ }
14851
15190
  const paragraphStyle = paragraphConfig === null || paragraphConfig === void 0 ? void 0 : paragraphConfig.paragraphStyle;
14852
15191
  const paragraphBackgroundColor = paragraphStyle === null || paragraphStyle === void 0 || (_paragraphStyle$shadi = paragraphStyle.shading) === null || _paragraphStyle$shadi === void 0 ? void 0 : _paragraphStyle$shadi.backgroundColor;
14853
15192
  if (paragraphBackgroundColor) line.backgroundColor = paragraphBackgroundColor;
@@ -15342,6 +15681,12 @@ function getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig
15342
15681
  if (!hasAddonStyle && originTextRun) fontCreateConfigCache.setValue(st, ed, result);
15343
15682
  return result;
15344
15683
  }
15684
+ function getCustomRangeGlyphWidth(index, viewModel, paragraphNode, config) {
15685
+ const customRange = viewModel.getCustomRange(index + paragraphNode.startIndex);
15686
+ const glyphWidthEm = customRange === null || customRange === void 0 ? void 0 : customRange.glyphWidthEm;
15687
+ if (typeof glyphWidthEm !== "number" || !Number.isFinite(glyphWidthEm) || glyphWidthEm < 0) return;
15688
+ return glyphWidthEm * config.fontStyle.originFontSize;
15689
+ }
15345
15690
  function getNullSkeleton() {
15346
15691
  return {
15347
15692
  pages: [],
@@ -15358,6 +15703,7 @@ function setPageParent(pages, parent) {
15358
15703
  for (const page of pages) page.parent = parent;
15359
15704
  }
15360
15705
  const DEFAULT_SECTION_BREAK = {
15706
+ sectionId: "section_render_default",
15361
15707
  columnProperties: [],
15362
15708
  columnSeparatorType: _univerjs_core.ColumnSeparatorType.NONE,
15363
15709
  sectionType: _univerjs_core.SectionType.SECTION_TYPE_UNSPECIFIED,
@@ -15405,6 +15751,11 @@ function prepareSectionBreakConfig(ctx, nodeIndex) {
15405
15751
  let { documentStyle } = dataModel;
15406
15752
  const { documentFlavor } = documentStyle;
15407
15753
  let sectionBreak = viewModel.getSectionBreak(sectionNode.endIndex) || DEFAULT_SECTION_BREAK;
15754
+ const sectionBreaks = viewModel.getChildren().map((node) => viewModel.getSectionBreak(node.endIndex) || DEFAULT_SECTION_BREAK);
15755
+ sectionBreak = {
15756
+ ...sectionBreak,
15757
+ ...(0, _univerjs_core.resolveSectionHeaderFooterReferences)(documentStyle, sectionBreaks, nodeIndex)
15758
+ };
15408
15759
  if (documentFlavor === _univerjs_core.DocumentFlavor.MODERN) {
15409
15760
  var _documentStyle$pageSi, _documentStyle$pageSi2;
15410
15761
  const modernPageWidth = (_documentStyle$pageSi = (_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.width) !== null && _documentStyle$pageSi !== void 0 ? _documentStyle$pageSi : DEFAULT_MODERN_DOCUMENT_STYLE.pageSize.width;
@@ -15421,7 +15772,7 @@ function prepareSectionBreakConfig(ctx, nodeIndex) {
15421
15772
  vertexAngle: 0,
15422
15773
  wrapStrategy: _univerjs_core.WrapStrategy.UNSPECIFIED
15423
15774
  } } = documentStyle;
15424
- const { charSpace = 0, linePitch = 15.6, gridType = _univerjs_core.GridType.LINES, pageNumberStart = global_pageNumberStart, pageSize = global_pageSize, pageOrient = global_pageOrient, marginTop = global_marginTop, marginBottom = global_marginBottom, marginRight = global_marginRight, marginLeft = global_marginLeft, marginHeader = global_marginHeader, marginFooter = global_marginFooter, defaultHeaderId = global_defaultHeaderId, defaultFooterId = global_defaultFooterId, evenPageHeaderId = global_evenPageHeaderId, evenPageFooterId = global_evenPageFooterId, firstPageHeaderId = global_firstPageHeaderId, firstPageFooterId = global_firstPageFooterId, useFirstPageHeaderFooter = global_useFirstPageHeaderFooter, evenAndOddHeaders = global_evenAndOddHeaders, columnProperties = [], columnSeparatorType = _univerjs_core.ColumnSeparatorType.NONE, contentDirection, sectionType, textDirection, renderConfig = global_renderConfig } = sectionBreak;
15775
+ const { sectionId, charSpace = 0, linePitch = 15.6, gridType = _univerjs_core.GridType.LINES, pageNumberStart = global_pageNumberStart, pageSize = global_pageSize, pageOrient = global_pageOrient, marginTop = global_marginTop, marginBottom = global_marginBottom, marginRight = global_marginRight, marginLeft = global_marginLeft, marginHeader = global_marginHeader, marginFooter = global_marginFooter, defaultHeaderId = global_defaultHeaderId, defaultFooterId = global_defaultFooterId, evenPageHeaderId = global_evenPageHeaderId, evenPageFooterId = global_evenPageFooterId, firstPageHeaderId = global_firstPageHeaderId, firstPageFooterId = global_firstPageFooterId, useFirstPageHeaderFooter = global_useFirstPageHeaderFooter, evenAndOddHeaders = global_evenAndOddHeaders, columnProperties = [], columnSeparatorType = _univerjs_core.ColumnSeparatorType.NONE, contentDirection, sectionType, textDirection, renderConfig = global_renderConfig } = sectionBreak;
15425
15776
  const sectionNodeNext = viewModel.getChildren()[nodeIndex + 1];
15426
15777
  const sectionTypeNext = (_viewModel$getSection = viewModel.getSectionBreak(sectionNodeNext === null || sectionNodeNext === void 0 ? void 0 : sectionNodeNext.endIndex)) === null || _viewModel$getSection === void 0 ? void 0 : _viewModel$getSection.sectionType;
15427
15778
  const headerIds = {
@@ -15437,6 +15788,7 @@ function prepareSectionBreakConfig(ctx, nodeIndex) {
15437
15788
  if (pageSize.width === null) pageSize.width = Number.POSITIVE_INFINITY;
15438
15789
  if (pageSize.height === null) pageSize.height = Number.POSITIVE_INFINITY;
15439
15790
  return {
15791
+ sectionId,
15440
15792
  charSpace,
15441
15793
  linePitch,
15442
15794
  gridType,
@@ -15509,13 +15861,14 @@ function getHeaderFooterMaxHeight(pageHeight) {
15509
15861
  }
15510
15862
  function createSkeletonPage(ctx, sectionBreakConfig, skeletonResourceReference, pageNumber = 1, breakType = 0) {
15511
15863
  const page = _getNullPage();
15512
- const { pageNumberStart = 1, pageSize = {
15864
+ const { sectionId, pageNumberStart = 1, pageSize = {
15513
15865
  width: Number.POSITIVE_INFINITY,
15514
15866
  height: Number.POSITIVE_INFINITY
15515
15867
  }, pageOrient = _univerjs_core.PageOrientType.PORTRAIT, headerIds = {}, footerIds = {}, useFirstPageHeaderFooter, evenAndOddHeaders, footerTreeMap, headerTreeMap, columnProperties = [], columnSeparatorType, marginTop = 0, marginBottom = 0, marginHeader: _marginHeader = 0, marginFooter: _marginFooter = 0, marginLeft = 0, marginRight = 0, renderConfig = {} } = sectionBreakConfig;
15516
15868
  const { skeHeaders, skeFooters } = skeletonResourceReference;
15517
15869
  const { width: pageWidth = Number.POSITIVE_INFINITY, height: pageHeight = Number.POSITIVE_INFINITY } = pageSize;
15518
15870
  page.pageNumber = pageNumber;
15871
+ page.sectionId = sectionId;
15519
15872
  page.pageNumberStart = pageNumberStart;
15520
15873
  page.renderConfig = renderConfig;
15521
15874
  page.marginLeft = marginLeft;
@@ -15610,10 +15963,11 @@ function _getNullPage(type = 0, segmentId = "") {
15610
15963
  }
15611
15964
  function _createSkeletonHeaderFooter(ctx, headerOrFooterViewModel, sectionBreakConfig, skeletonResourceReference, segmentId, isHeader = true, areaPage, count = 0) {
15612
15965
  var _sectionBreakConfig$d;
15613
- const { lists, footerTreeMap, headerTreeMap, localeService, pageSize, drawings, marginLeft = 0, marginRight = 0, marginHeader = 0, marginFooter = 0 } = sectionBreakConfig;
15966
+ const { sectionId, lists, footerTreeMap, headerTreeMap, localeService, pageSize, drawings, marginLeft = 0, marginRight = 0, marginHeader = 0, marginFooter = 0 } = sectionBreakConfig;
15614
15967
  const pageWidth = (pageSize === null || pageSize === void 0 ? void 0 : pageSize.width) || Number.POSITIVE_INFINITY;
15615
15968
  const pageHeight = (pageSize === null || pageSize === void 0 ? void 0 : pageSize.height) || Number.POSITIVE_INFINITY;
15616
15969
  const headerFooterConfig = {
15970
+ sectionId,
15617
15971
  lists,
15618
15972
  footerTreeMap,
15619
15973
  headerTreeMap,
@@ -15650,7 +16004,7 @@ function _createSkeletonHeaderFooter(ctx, headerOrFooterViewModel, sectionBreakC
15650
16004
  }
15651
16005
  function createNullCellPage(ctx, sectionBreakConfig, tableConfig, row, col, availableHeight = Number.POSITIVE_INFINITY, maxCellPageHeight = Number.POSITIVE_INFINITY) {
15652
16006
  var _ref, _cellConfig$margin, _cellConfig$columnSpa;
15653
- const { lists, footerTreeMap, headerTreeMap, localeService, drawings } = sectionBreakConfig;
16007
+ const { sectionId, lists, footerTreeMap, headerTreeMap, localeService, drawings } = sectionBreakConfig;
15654
16008
  const { skeletonResourceReference } = ctx;
15655
16009
  const { cellMargin, tableRows, tableColumns, tableId } = tableConfig;
15656
16010
  const cellConfig = tableRows[row].tableCells[col];
@@ -15672,6 +16026,7 @@ function createNullCellPage(ctx, sectionBreakConfig, tableConfig, row, col, avai
15672
16026
  }
15673
16027
  const pageHeight = maxCellPageHeight;
15674
16028
  const cellSectionBreakConfig = {
16029
+ sectionId,
15675
16030
  lists,
15676
16031
  footerTreeMap,
15677
16032
  headerTreeMap,
@@ -15832,7 +16187,7 @@ function getDivideStretchability(divide) {
15832
16187
  function getJustifiables(divide) {
15833
16188
  const justifiables = divide.glyphGroup.filter((glyph) => glyph.isJustifiable).length;
15834
16189
  const lastGlyph = divide.glyphGroup[divide.glyphGroup.length - 1];
15835
- if (hasCJK(lastGlyph.content)) return justifiables - 1;
16190
+ if (cjk.hasCJK(lastGlyph.content)) return justifiables - 1;
15836
16191
  return justifiables;
15837
16192
  }
15838
16193
  function adjustGlyphsInDivide(divide, justificationRatio, extraJustification) {
@@ -15937,7 +16292,7 @@ function horizontalAlignHandler(line, horizontalAlign, allowOverflowHorizontalOf
15937
16292
  function restoreLastCJKGlyphWidth(line) {
15938
16293
  for (const divide of line.divides) {
15939
16294
  const lastGlyph = divide.glyphGroup[divide.glyphGroup.length - 1];
15940
- if (lastGlyph && divide.isFull && hasCJKText(lastGlyph.content) && lastGlyph.width - lastGlyph.xOffset > lastGlyph.bBox.width) {
16295
+ if (lastGlyph && divide.isFull && cjk.hasCJKText(lastGlyph.content) && lastGlyph.width - lastGlyph.xOffset > lastGlyph.bBox.width) {
15941
16296
  const shrinkAmount = lastGlyph.width - lastGlyph.xOffset - lastGlyph.bBox.width;
15942
16297
  lastGlyph.width -= shrinkAmount;
15943
16298
  lastGlyph.adjustability.shrinkability[1] = 0;
@@ -16210,22 +16565,66 @@ function _isDocxColumnBreakVisuallyBlankColumn(column) {
16210
16565
  function _hasOnlyCustomBlockGlyphs(glyphs) {
16211
16566
  return glyphs.length > 0 && glyphs.every((glyph) => glyph.streamType === _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK);
16212
16567
  }
16213
- function _mergeAdjacentCustomBlockShapedTexts(shapedTextList) {
16568
+ function _mergeAdjacentCustomBlockShapedTexts(shapedTextList, customBlockDrawings) {
16214
16569
  const mergedShapedTextList = [];
16215
- for (const shapedText of shapedTextList) {
16216
- const lastShapedText = mergedShapedTextList[mergedShapedTextList.length - 1];
16217
- if (lastShapedText && _hasOnlyCustomBlockGlyphs(lastShapedText.glyphs) && _hasOnlyCustomBlockGlyphs(shapedText.glyphs)) {
16218
- lastShapedText.text += shapedText.text;
16219
- lastShapedText.glyphs.push(...shapedText.glyphs);
16220
- lastShapedText.breakPointType = shapedText.breakPointType;
16221
- continue;
16570
+ for (const originShapedText of shapedTextList) {
16571
+ const splitShapedTexts = _splitTopBottomCustomBlockShapedText(originShapedText, customBlockDrawings);
16572
+ for (const shapedText of splitShapedTexts) {
16573
+ const lastShapedText = mergedShapedTextList[mergedShapedTextList.length - 1];
16574
+ if (lastShapedText && _hasOnlyCustomBlockGlyphs(lastShapedText.glyphs) && _hasOnlyCustomBlockGlyphs(shapedText.glyphs) && !_hasTopBottomCustomBlockGlyph(lastShapedText.glyphs, customBlockDrawings) && !_hasTopBottomCustomBlockGlyph(shapedText.glyphs, customBlockDrawings)) {
16575
+ lastShapedText.text += shapedText.text;
16576
+ lastShapedText.glyphs.push(...shapedText.glyphs);
16577
+ lastShapedText.breakPointType = shapedText.breakPointType;
16578
+ continue;
16579
+ }
16580
+ mergedShapedTextList.push({
16581
+ ...shapedText,
16582
+ glyphs: [...shapedText.glyphs]
16583
+ });
16222
16584
  }
16223
- mergedShapedTextList.push({
16585
+ }
16586
+ return mergedShapedTextList;
16587
+ }
16588
+ function _splitTopBottomCustomBlockShapedText(shapedText, customBlockDrawings) {
16589
+ const splitShapedTexts = [];
16590
+ let pendingGlyphs = [];
16591
+ let pendingText = "";
16592
+ let textOffset = 0;
16593
+ const flushPending = () => {
16594
+ if (pendingGlyphs.length === 0) return;
16595
+ splitShapedTexts.push({
16224
16596
  ...shapedText,
16225
- glyphs: [...shapedText.glyphs]
16597
+ text: pendingText,
16598
+ glyphs: pendingGlyphs
16226
16599
  });
16600
+ pendingGlyphs = [];
16601
+ pendingText = "";
16602
+ };
16603
+ for (const glyph of shapedText.glyphs) {
16604
+ const glyphText = shapedText.text.slice(textOffset, textOffset + glyph.count);
16605
+ textOffset += glyph.count;
16606
+ if (_isTopBottomCustomBlockGlyph(glyph, customBlockDrawings)) {
16607
+ flushPending();
16608
+ splitShapedTexts.push({
16609
+ ...shapedText,
16610
+ text: glyphText,
16611
+ glyphs: [glyph]
16612
+ });
16613
+ continue;
16614
+ }
16615
+ pendingGlyphs.push(glyph);
16616
+ pendingText += glyphText;
16227
16617
  }
16228
- return mergedShapedTextList;
16618
+ flushPending();
16619
+ return splitShapedTexts.length > 0 ? splitShapedTexts : [shapedText];
16620
+ }
16621
+ function _hasTopBottomCustomBlockGlyph(glyphs, customBlockDrawings) {
16622
+ return glyphs.some((glyph) => _isTopBottomCustomBlockGlyph(glyph, customBlockDrawings));
16623
+ }
16624
+ function _isTopBottomCustomBlockGlyph(glyph, customBlockDrawings) {
16625
+ var _customBlockDrawings$;
16626
+ if (glyph.streamType !== _univerjs_core.DataStreamTreeTokenType.CUSTOM_BLOCK || glyph.drawingId == null) return false;
16627
+ return ((_customBlockDrawings$ = customBlockDrawings.get(glyph.drawingId)) === null || _customBlockDrawings$ === void 0 ? void 0 : _customBlockDrawings$.drawingOrigin.layoutType) === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM;
16229
16628
  }
16230
16629
  function _getListLevelAncestors(bullet, listLevel) {
16231
16630
  if (!bullet || !listLevel) return;
@@ -16271,26 +16670,17 @@ function _hasNextAdjacentLayoutBlockRange(blockRanges, blockRange) {
16271
16670
  const nextBlockRange = _getNextAdjacentBlockRange(blockRanges, blockRange);
16272
16671
  return nextBlockRange != null && BLOCK_LAYOUT_OUTER_SPACING_MAP.has(nextBlockRange.blockType) && nextBlockRange.startIndex === blockRange.endIndex + 1;
16273
16672
  }
16274
- function _applyDefaultLayoutParagraphStyle(style, hasBlockRange) {
16275
- if (style.lineSpacing == null) style.lineSpacing = _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING;
16276
- if (hasBlockRange) return;
16277
- if (style.spaceAbove == null) style.spaceAbove = { v: _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_SPACE_ABOVE };
16278
- if (style.spaceBelow == null) style.spaceBelow = { v: _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_SPACE_BELOW };
16279
- }
16280
- function _applyBlockRangeLayoutParagraphStyle(body, paragraph, paragraphStyle, shouldApplyDocumentDefaults) {
16673
+ function _applyBlockRangeLayoutParagraphStyle(body, paragraph, paragraphStyle, documentStyle, useLegacyModernDefaults) {
16281
16674
  var _body$paragraphs, _BLOCK_LAYOUT_OUTER_S;
16282
- const style = _univerjs_core.Tools.deepClone(paragraphStyle);
16283
16675
  const blockRanges = body === null || body === void 0 ? void 0 : body.blockRanges;
16284
- if (!(blockRanges === null || blockRanges === void 0 ? void 0 : blockRanges.length)) {
16285
- if (shouldApplyDocumentDefaults) _applyDefaultLayoutParagraphStyle(style, false);
16286
- return style;
16287
- }
16676
+ if (!(blockRanges === null || blockRanges === void 0 ? void 0 : blockRanges.length)) return (0, _univerjs_core.resolveDocumentParagraphStyle)(documentStyle, paragraphStyle, { useLegacyModernDefaults });
16288
16677
  const blockRange = blockRanges.find((range) => BLOCK_LAYOUT_OUTER_SPACING_MAP.has(range.blockType) && paragraph.startIndex > range.startIndex && paragraph.startIndex < range.endIndex);
16289
- if (!blockRange) {
16290
- if (shouldApplyDocumentDefaults) _applyDefaultLayoutParagraphStyle(style, false);
16291
- return style;
16292
- }
16293
- _applyDefaultLayoutParagraphStyle(style, true);
16678
+ if (!blockRange) return (0, _univerjs_core.resolveDocumentParagraphStyle)(documentStyle, paragraphStyle, { useLegacyModernDefaults });
16679
+ const style = (0, _univerjs_core.resolveDocumentParagraphStyle)(documentStyle, paragraphStyle, {
16680
+ excludeDocumentOuterSpacing: true,
16681
+ useLegacyModernDefaults
16682
+ });
16683
+ if (style.lineSpacing == null) style.lineSpacing = _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING;
16294
16684
  const blockParagraphs = ((_body$paragraphs = body === null || body === void 0 ? void 0 : body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).filter((item) => item.startIndex > blockRange.startIndex && item.startIndex < blockRange.endIndex).sort((left, right) => left.startIndex - right.startIndex);
16295
16685
  const firstParagraph = blockParagraphs[0];
16296
16686
  const lastParagraph = blockParagraphs[blockParagraphs.length - 1];
@@ -16339,7 +16729,7 @@ function _getNextPageNumber(lastPage) {
16339
16729
  return lastPage.pageNumber + 1;
16340
16730
  }
16341
16731
  function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, sectionBreakConfig, tableSkeleton) {
16342
- var _sectionBreakConfig$d, _viewModel$getSnapsho, _viewModel$getBody2, _viewModel$getBody3;
16732
+ var _viewModel$getSnapsho, _sectionBreakConfig$d, _viewModel$getBody2, _viewModel$getBody3;
16343
16733
  const { skeletonResourceReference } = ctx;
16344
16734
  const { lists, drawings = {}, localeService } = sectionBreakConfig;
16345
16735
  const { endIndex, blocks = [], children } = paragraphNode;
@@ -16349,7 +16739,8 @@ function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, se
16349
16739
  paragraphId: "para_render_fallback"
16350
16740
  };
16351
16741
  const { paragraphStyle = {}, bullet } = paragraph;
16352
- 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);
16742
+ const documentStyle = (_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;
16743
+ const documentCompatibilityPolicy = (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy(documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.documentFlavor);
16353
16744
  const shouldApplyDocumentDefaults = documentCompatibilityPolicy.applyDocumentDefaultParagraphStyle;
16354
16745
  const useWordStyleLineHeight = documentCompatibilityPolicy.useWordStyleLineHeight;
16355
16746
  const { skeHeaders, skeFooters, skeListLevel, drawingAnchor } = skeletonResourceReference;
@@ -16365,7 +16756,7 @@ function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, se
16365
16756
  const paragraphConfig = {
16366
16757
  paragraphIndex: endIndex,
16367
16758
  documentCompatibilityPolicy,
16368
- 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),
16759
+ 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, documentStyle, shouldApplyDocumentDefaults),
16369
16760
  docxFallbackAnchorLeft: _getFollowingIndentedParagraphAnchorLeft(viewModel, paragraph, paragraphNode, drawings, isTraditionalDocumentCompatibility(documentCompatibilityPolicy)),
16370
16761
  useWordStyleLineHeight,
16371
16762
  paragraphNonInlineSkeDrawings,
@@ -16408,7 +16799,7 @@ function lineBreaking(ctx, viewModel, shapedTextList, curPage, paragraphNode, se
16408
16799
  let allPages = [curPage];
16409
16800
  let isParagraphFirstShapedText = true;
16410
16801
  let shapedTextOffset = 0;
16411
- for (const [_index, { text, glyphs, breakPointType }] of _mergeAdjacentCustomBlockShapedTexts(shapedTextList).entries()) {
16802
+ for (const [_index, { text, glyphs, breakPointType }] of _mergeAdjacentCustomBlockShapedTexts(shapedTextList, paragraphNonInlineSkeDrawingsByBlockId).entries()) {
16412
16803
  const textStartIndex = paragraphNode.startIndex + shapedTextOffset;
16413
16804
  const textGlyphCount = _glyphCount(glyphs);
16414
16805
  const textEndIndex = textStartIndex + textGlyphCount;
@@ -16925,7 +17316,8 @@ function otherHandler(index, charArray, viewModel, paragraphNode, sectionBreakCo
16925
17316
  const char = (_src$match = src.match(/^[\s\S]/gu)) === null || _src$match === void 0 ? void 0 : _src$match[0];
16926
17317
  if (char == null) break;
16927
17318
  if (hasSpace(char) || startWithEmoji(charArray.substring(step))) break;
16928
- const glyph = createSkeletonLetterGlyph(char, getFontCreateConfig(index + step, viewModel, paragraphNode, sectionBreakConfig, paragraph));
17319
+ const config = getFontCreateConfig(index + step, viewModel, paragraphNode, sectionBreakConfig, paragraph);
17320
+ const glyph = createSkeletonLetterGlyph(char, config, getCustomRangeGlyphWidth(index + step, viewModel, paragraphNode, config));
16929
17321
  glyphGroup.push(glyph);
16930
17322
  src = src.substring(char.length);
16931
17323
  step += char.length;
@@ -17001,7 +17393,7 @@ function punctuationSpaceAdjustment(shapedGlyphs) {
17001
17393
  const nextGlyph = shapedGlyphs[i + 1];
17002
17394
  const { width, content } = curGlyph;
17003
17395
  const delta = width / 2;
17004
- if (hasCJKPunctuation(content) && hasCJKPunctuation(nextGlyph.content) && curGlyph.adjustability.shrinkability[1] + nextGlyph.adjustability.shrinkability[0] >= delta) {
17396
+ if (cjk.hasCJKPunctuation(content) && cjk.hasCJKPunctuation(nextGlyph.content) && curGlyph.adjustability.shrinkability[1] + nextGlyph.adjustability.shrinkability[0] >= delta) {
17005
17397
  const leftDelta = Math.min(curGlyph.adjustability.shrinkability[1], delta);
17006
17398
  glyphShrinkRight(curGlyph, leftDelta);
17007
17399
  glyphShrinkLeft(nextGlyph, delta - leftDelta);
@@ -17017,11 +17409,11 @@ function addCJKLatinSpacing(shapedTextList) {
17017
17409
  const curGlyph = shapedGlyphs[i];
17018
17410
  const nextGlyph = i < len - 1 ? shapedGlyphs[i + 1] : null;
17019
17411
  const { width } = curGlyph;
17020
- if (hasCJKText(curGlyph.content) && nextGlyph && LATIN_REG.test(nextGlyph.content)) {
17412
+ if (cjk.hasCJKText(curGlyph.content) && nextGlyph && LATIN_REG.test(nextGlyph.content)) {
17021
17413
  curGlyph.width += width / 4;
17022
17414
  curGlyph.adjustability.shrinkability[1] += width / 8;
17023
17415
  }
17024
- if (hasCJKText(curGlyph.content) && prevGlyph && LATIN_REG.test(prevGlyph.content)) {
17416
+ if (cjk.hasCJKText(curGlyph.content) && prevGlyph && LATIN_REG.test(prevGlyph.content)) {
17025
17417
  curGlyph.width += width / 4;
17026
17418
  curGlyph.xOffset += width / 4;
17027
17419
  curGlyph.adjustability.shrinkability[0] += width / 8;
@@ -17083,7 +17475,7 @@ function shaping(ctx, content, viewModel, paragraphNode, sectionBreakConfig, use
17083
17475
  const newSpan = createSkeletonLetterGlyph(char, config);
17084
17476
  shapedGlyphs.push(newSpan);
17085
17477
  } else {
17086
- const newSpan = createSkeletonLetterGlyph(char, config, void 0, glyphInfo);
17478
+ const newSpan = createSkeletonLetterGlyph(char, config, getCustomRangeGlyphWidth(start, viewModel, paragraphNode, config), glyphInfo);
17087
17479
  shapedGlyphs.push(newSpan);
17088
17480
  }
17089
17481
  }
@@ -17102,24 +17494,29 @@ function shaping(ctx, content, viewModel, paragraphNode, sectionBreakConfig, use
17102
17494
  const { blockId } = customBlock;
17103
17495
  const drawingOrigin = drawings[blockId];
17104
17496
  if ((drawingOrigin === null || drawingOrigin === void 0 ? void 0 : drawingOrigin.layoutType) === _univerjs_core.PositionedObjectLayoutType.INLINE) {
17497
+ var _viewModel$getDataMod, _viewModel$getDataMod2, _viewModel$getDataMod3, _boundingBox$height, _boundingBox$width, _ref, _viewport$layoutWidth, _viewport$height;
17105
17498
  const { angle } = drawingOrigin.docTransform;
17106
17499
  const { width = 0, height = 0 } = drawingOrigin.docTransform.size;
17107
17500
  const boundingBox = getBoundingBox(angle, 0, width, 0, height);
17108
- newGlyph = createSkeletonCustomBlockGlyph(config, boundingBox.width, boundingBox.height, drawingOrigin.drawingId);
17501
+ const viewport = getDocsCustomBlockRenderViewport((_viewModel$getDataMod = (_viewModel$getDataMod2 = (_viewModel$getDataMod3 = viewModel.getDataModel()).getUnitId) === null || _viewModel$getDataMod2 === void 0 ? void 0 : _viewModel$getDataMod2.call(_viewModel$getDataMod3)) !== null && _viewModel$getDataMod !== void 0 ? _viewModel$getDataMod : "", drawingOrigin.drawingId, {
17502
+ fallbackHeight: (_boundingBox$height = boundingBox.height) !== null && _boundingBox$height !== void 0 ? _boundingBox$height : 0,
17503
+ fallbackWidth: (_boundingBox$width = boundingBox.width) !== null && _boundingBox$width !== void 0 ? _boundingBox$width : 0
17504
+ });
17505
+ newGlyph = createSkeletonCustomBlockGlyph(config, (_ref = (_viewport$layoutWidth = viewport === null || viewport === void 0 ? void 0 : viewport.layoutWidth) !== null && _viewport$layoutWidth !== void 0 ? _viewport$layoutWidth : viewport === null || viewport === void 0 ? void 0 : viewport.width) !== null && _ref !== void 0 ? _ref : boundingBox.width, (_viewport$height = viewport === null || viewport === void 0 ? void 0 : viewport.height) !== null && _viewport$height !== void 0 ? _viewport$height : boundingBox.height, drawingOrigin.drawingId);
17109
17506
  } else if (drawingOrigin != null) newGlyph = createSkeletonCustomBlockGlyph(config, 0, 0, drawingOrigin.drawingId);
17110
17507
  }
17111
17508
  if (newGlyph == null) newGlyph = createSkeletonLetterGlyph(char, config);
17112
17509
  shapedGlyphs.push(newGlyph);
17113
17510
  i += char.length;
17114
17511
  src = src.substring(char.length);
17115
- } else if (/\s/.test(char) || hasCJK(char)) {
17512
+ } else if (/\s/.test(char) || cjk.hasCJK(char)) {
17116
17513
  const config = getFontCreateConfig(i, viewModel, paragraphNode, sectionBreakConfig, paragraph);
17117
17514
  let newGlyph = null;
17118
17515
  if (char === _univerjs_core.DataStreamTreeTokenType.TAB) newGlyph = createSkeletonTabGlyph(config, getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid));
17119
17516
  else if (char === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH) {
17120
17517
  var _sectionBreakConfig$r;
17121
17518
  if (((_sectionBreakConfig$r = sectionBreakConfig.renderConfig) === null || _sectionBreakConfig$r === void 0 ? void 0 : _sectionBreakConfig$r.zeroWidthParagraphBreak) === _univerjs_core.BooleanNumber.TRUE) newGlyph = createSkeletonLetterGlyph(char, config, 0);
17122
- else newGlyph = createSkeletonLetterGlyph(char, config);
17519
+ else newGlyph = createSkeletonLetterGlyph(char, config, getCustomRangeGlyphWidth(i, viewModel, paragraphNode, config));
17123
17520
  } else newGlyph = createSkeletonLetterGlyph(char, config);
17124
17521
  shapedGlyphs.push(newGlyph);
17125
17522
  i += char.length;
@@ -17266,6 +17663,7 @@ function createColumnContentPage(ctx, viewModel, columnNode, sectionBreakConfig,
17266
17663
  const page = createSkeletonPage(ctx, columnSectionBreakConfig, ctx.skeletonResourceReference);
17267
17664
  page.type = 3;
17268
17665
  for (const paragraphNode of getColumnParagraphNodes(columnNode)) dealWidthParagraph(ctx, viewModel, paragraphNode, page, columnSectionBreakConfig);
17666
+ updateInlineDrawingCoordsAndBorder(ctx, [page]);
17269
17667
  updateBlockIndex([page], columnNode.startIndex, (_sectionBreakConfig$d = sectionBreakConfig.documentCompatibilityPolicy) !== null && _sectionBreakConfig$d !== void 0 ? _sectionBreakConfig$d : getDocumentCompatibilityPolicy());
17270
17668
  applyTrailingBlockRangeSpaceBelow([page], (_ctx$dataModel = ctx.dataModel) === null || _ctx$dataModel === void 0 || (_ctx$dataModel$getBod = _ctx$dataModel.getBody) === null || _ctx$dataModel$getBod === void 0 ? void 0 : _ctx$dataModel$getBod.call(_ctx$dataModel), columnNode.endIndex);
17271
17669
  return page;
@@ -18707,7 +19105,10 @@ function createDocumentModelWithStyle(content, textStyle, config = {}) {
18707
19105
  paragraphId: (0, _univerjs_core.createParagraphId)(/* @__PURE__ */ new Set()),
18708
19106
  paragraphStyle: { horizontalAlign }
18709
19107
  }],
18710
- sectionBreaks: [{ startIndex: contentLength + 1 }]
19108
+ sectionBreaks: [{
19109
+ sectionId: (0, _univerjs_core.createSectionId)(/* @__PURE__ */ new Set()),
19110
+ startIndex: contentLength + 1
19111
+ }]
18711
19112
  },
18712
19113
  documentStyle: {
18713
19114
  pageSize: {
@@ -18791,6 +19192,36 @@ const DEFAULT_PADDING_DATA = {
18791
19192
  r: 2
18792
19193
  };
18793
19194
  const RENDER_RAW_FORMULA_KEY = "RENDER_RAW_FORMULA";
19195
+ function getResolvedRenderHorizontalAlign$1(horizontalAlign, cellData) {
19196
+ if (horizontalAlign !== _univerjs_core.HorizontalAlign.UNSPECIFIED) return horizontalAlign;
19197
+ if ((cellData === null || cellData === void 0 ? void 0 : cellData.t) === _univerjs_core.CellValueType.NUMBER || !_univerjs_core.Tools.isDefine(cellData === null || cellData === void 0 ? void 0 : cellData.t) && typeof (cellData === null || cellData === void 0 ? void 0 : cellData.v) === "number") return _univerjs_core.HorizontalAlign.RIGHT;
19198
+ if ((cellData === null || cellData === void 0 ? void 0 : cellData.t) === _univerjs_core.CellValueType.BOOLEAN) return _univerjs_core.HorizontalAlign.CENTER;
19199
+ return horizontalAlign;
19200
+ }
19201
+ function setRenderTextCache(cacheItem, cellData) {
19202
+ var _cacheItem$horizontal;
19203
+ if (cacheItem.documentSkeleton) {
19204
+ cacheItem.displayText = void 0;
19205
+ cacheItem.resolvedHorizontalAlign = void 0;
19206
+ return;
19207
+ }
19208
+ cacheItem.displayText = (0, _univerjs_core.getDisplayValueFromCell)(cellData);
19209
+ cacheItem.resolvedHorizontalAlign = getResolvedRenderHorizontalAlign$1((_cacheItem$horizontal = cacheItem.horizontalAlign) !== null && _cacheItem$horizontal !== void 0 ? _cacheItem$horizontal : _univerjs_core.HorizontalAlign.UNSPECIFIED, cellData);
19210
+ }
19211
+ function pushRowRange(ranges, row, startColumn, endColumn) {
19212
+ if (endColumn < startColumn) return;
19213
+ const last = ranges[ranges.length - 1];
19214
+ if (last && last.startRow === row && last.endRow === row && last.endColumn + 1 === startColumn) {
19215
+ last.endColumn = endColumn;
19216
+ return;
19217
+ }
19218
+ ranges.push({
19219
+ startRow: row,
19220
+ endRow: row,
19221
+ startColumn,
19222
+ endColumn
19223
+ });
19224
+ }
18794
19225
  const CACHE_COUNT = 100;
18795
19226
  let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.SheetSkeleton {
18796
19227
  constructor(worksheet, _styles, _localeService, _contextService, _configService, _injector) {
@@ -18804,6 +19235,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18804
19235
  _defineProperty(this, "_cacheRangeMap", /* @__PURE__ */ new Map());
18805
19236
  _defineProperty(this, "_visibleRangeMap", /* @__PURE__ */ new Map());
18806
19237
  _defineProperty(this, "_overflowCache", new _univerjs_core.ObjectMatrix());
19238
+ _defineProperty(this, "_incrementalFontRenderRanges", []);
18807
19239
  _defineProperty(this, "_stylesCache", {
18808
19240
  background: {},
18809
19241
  backgroundPositions: new _univerjs_core.ObjectMatrix(),
@@ -18861,6 +19293,9 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18861
19293
  get overflowCache() {
18862
19294
  return this._overflowCache;
18863
19295
  }
19296
+ get incrementalFontRenderRanges() {
19297
+ return this._incrementalFontRenderRanges;
19298
+ }
18864
19299
  get showGridlines() {
18865
19300
  return this._showGridlines;
18866
19301
  }
@@ -18946,7 +19381,31 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18946
19381
  this.updateVisibleRange(vpInfo);
18947
19382
  const rowColumnSegment = this._drawingRange;
18948
19383
  const columnWidthAccumulation = this.columnWidthAccumulation;
18949
- const styleRanges = !!vpInfo && !vpInfo.isDirty && !vpInfo.isForceDirty && (!!((_vpInfo$diffBounds = vpInfo.diffBounds) === null || _vpInfo$diffBounds === void 0 ? void 0 : _vpInfo$diffBounds.length) || !!((_vpInfo$diffCacheBoun = vpInfo.diffCacheBounds) === null || _vpInfo$diffCacheBoun === void 0 ? void 0 : _vpInfo$diffCacheBoun.length) || !!vpInfo.diffX || !!vpInfo.diffY) ? vpInfo.shouldCacheUpdate ? (_vpInfo$diffCacheBoun2 = (_vpInfo$diffCacheBoun3 = vpInfo.diffCacheBounds) === null || _vpInfo$diffCacheBoun3 === void 0 ? void 0 : _vpInfo$diffCacheBoun3.map((bound) => this.getRangeByViewBound(bound))) !== null && _vpInfo$diffCacheBoun2 !== void 0 ? _vpInfo$diffCacheBoun2 : [] : [] : [rowColumnSegment];
19384
+ const isIncrementalScroll = !!vpInfo && !vpInfo.isDirty && !vpInfo.isForceDirty && (!!((_vpInfo$diffBounds = vpInfo.diffBounds) === null || _vpInfo$diffBounds === void 0 ? void 0 : _vpInfo$diffBounds.length) || !!((_vpInfo$diffCacheBoun = vpInfo.diffCacheBounds) === null || _vpInfo$diffCacheBoun === void 0 ? void 0 : _vpInfo$diffCacheBoun.length) || !!vpInfo.diffX || !!vpInfo.diffY);
19385
+ const hasMergeData = this.worksheet.getMergeData().length > 0;
19386
+ const isScrolling = !!vpInfo && (!!vpInfo.diffX || !!vpInfo.diffY);
19387
+ const shouldRefreshCacheForScroll = isIncrementalScroll && (hasMergeData && isScrolling || !!vpInfo.shouldCacheUpdate && !!vpInfo.diffX);
19388
+ const shouldUseIncrementalStyleRange = isIncrementalScroll && !shouldRefreshCacheForScroll;
19389
+ const styleRanges = shouldUseIncrementalStyleRange ? vpInfo.shouldCacheUpdate ? (_vpInfo$diffCacheBoun2 = (_vpInfo$diffCacheBoun3 = vpInfo.diffCacheBounds) === null || _vpInfo$diffCacheBoun3 === void 0 ? void 0 : _vpInfo$diffCacheBoun3.map((bound) => this.getRangeByViewBound(bound))) !== null && _vpInfo$diffCacheBoun2 !== void 0 ? _vpInfo$diffCacheBoun2 : [] : [] : [rowColumnSegment];
19390
+ const visibleCellOptions = hasMergeData ? null : {
19391
+ cacheItem: {
19392
+ bg: true,
19393
+ border: true
19394
+ },
19395
+ reuseExisting: shouldUseIncrementalStyleRange,
19396
+ hasMergeData,
19397
+ rowVisible: true
19398
+ };
19399
+ const overflowCellOptions = hasMergeData ? null : {
19400
+ cacheItem: {
19401
+ bg: false,
19402
+ border: false
19403
+ },
19404
+ reuseExisting: shouldUseIncrementalStyleRange,
19405
+ hasMergeData,
19406
+ rowVisible: true
19407
+ };
19408
+ this._incrementalFontRenderRanges = [];
18950
19409
  for (const styleRange of styleRanges) {
18951
19410
  const { startRow: visibleStartRow, endRow: visibleEndRow, startColumn: visibleStartColumn, endColumn: visibleEndColumn } = styleRange;
18952
19411
  if (visibleEndColumn === -1 || visibleEndRow === -1) continue;
@@ -18971,26 +19430,57 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18971
19430
  startColumn: visibleStartColumn,
18972
19431
  endColumn: visibleEndColumn
18973
19432
  });
18974
- for (let c = visibleStartColumn; c <= visibleEndColumn; c++) this._setStylesCacheForOneCell(r, c, { cacheItem: {
18975
- bg: true,
18976
- border: true
18977
- } });
18978
- for (let c = expandStartCol; c < visibleEndColumn; c++) this._setStylesCacheForOneCell(r, c, { cacheItem: {
18979
- bg: false,
18980
- border: false
18981
- } });
19433
+ for (let c = visibleStartColumn; c <= visibleEndColumn; c++) this._setStylesCacheForOneCell(r, c, visibleCellOptions !== null && visibleCellOptions !== void 0 ? visibleCellOptions : {
19434
+ cacheItem: {
19435
+ bg: true,
19436
+ border: true
19437
+ },
19438
+ reuseExisting: shouldUseIncrementalStyleRange,
19439
+ hasMergeData,
19440
+ rowVisible: true
19441
+ });
19442
+ if (shouldUseIncrementalStyleRange) pushRowRange(this._incrementalFontRenderRanges, r, visibleStartColumn, visibleEndColumn);
19443
+ for (let c = visibleStartColumn - 1; c >= expandStartCol; c--) {
19444
+ this._setStylesCacheForOneCell(r, c, overflowCellOptions !== null && overflowCellOptions !== void 0 ? overflowCellOptions : {
19445
+ cacheItem: {
19446
+ bg: false,
19447
+ border: false
19448
+ },
19449
+ reuseExisting: shouldUseIncrementalStyleRange,
19450
+ hasMergeData,
19451
+ rowVisible: true
19452
+ });
19453
+ if (shouldUseIncrementalStyleRange) pushRowRange(this._incrementalFontRenderRanges, r, c, c);
19454
+ if (!(0, _univerjs_core.isCellCoverable)(this.worksheet.getCell(r, c)) || hasMergeData && this.intersectMergeRange(r, c)) break;
19455
+ }
18982
19456
  if (visibleEndColumn === 0) continue;
18983
- for (let c = visibleEndColumn + 1; c < expandEndCol; c++) this._setStylesCacheForOneCell(r, c, { cacheItem: {
18984
- bg: false,
18985
- border: false
18986
- } });
19457
+ for (let c = visibleEndColumn + 1; c <= expandEndCol; c++) {
19458
+ this._setStylesCacheForOneCell(r, c, overflowCellOptions !== null && overflowCellOptions !== void 0 ? overflowCellOptions : {
19459
+ cacheItem: {
19460
+ bg: false,
19461
+ border: false
19462
+ },
19463
+ reuseExisting: shouldUseIncrementalStyleRange,
19464
+ hasMergeData,
19465
+ rowVisible: true
19466
+ });
19467
+ if (shouldUseIncrementalStyleRange) pushRowRange(this._incrementalFontRenderRanges, r, c, c);
19468
+ if (!(0, _univerjs_core.isCellCoverable)(this.worksheet.getCell(r, c)) || hasMergeData && this.intersectMergeRange(r, c)) break;
19469
+ }
18987
19470
  }
18988
19471
  const mergeRanges = [];
18989
19472
  for (const mergeVisibleRange of mergeVisibleRanges) {
18990
19473
  const mergeRangeInVisible = this.getCurrentRowColumnSegmentMergeData(mergeVisibleRange);
18991
19474
  mergeRanges.push(...mergeRangeInVisible);
18992
19475
  }
18993
- for (const mergeRange of mergeRanges) this._setStylesCacheForOneCell(mergeRange.startRow, mergeRange.startColumn, { mergeRange });
19476
+ for (const mergeRange of mergeRanges) {
19477
+ this._setStylesCacheForOneCell(mergeRange.startRow, mergeRange.startColumn, {
19478
+ mergeRange,
19479
+ reuseExisting: shouldUseIncrementalStyleRange,
19480
+ hasMergeData
19481
+ });
19482
+ if (shouldUseIncrementalStyleRange) pushRowRange(this._incrementalFontRenderRanges, mergeRange.startRow, mergeRange.startColumn, mergeRange.startColumn);
19483
+ }
18994
19484
  }
18995
19485
  return this;
18996
19486
  }
@@ -19275,6 +19765,22 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19275
19765
  endColumn
19276
19766
  };
19277
19767
  }
19768
+ _isOverflowBlockedByAdjacentCell(row, column, horizontalAlign, hasMergeData = true) {
19769
+ const leftBlocked = () => this._isOverflowSideBlocked(row, column, -1, hasMergeData);
19770
+ const rightBlocked = () => this._isOverflowSideBlocked(row, column, 1, hasMergeData);
19771
+ if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER) return leftBlocked() && rightBlocked();
19772
+ if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT) return leftBlocked();
19773
+ return rightBlocked();
19774
+ }
19775
+ _isOverflowSideBlocked(row, column, direction, hasMergeData = true) {
19776
+ var _this$_stylesCache$fo;
19777
+ const adjacentColumn = column + direction;
19778
+ if (adjacentColumn < 0 || adjacentColumn >= this.getColumnCount()) return true;
19779
+ const rawAdjacentCell = this._cellData.getValue(row, adjacentColumn);
19780
+ if (rawAdjacentCell && !(0, _univerjs_core.isCellCoverable)(rawAdjacentCell)) return true;
19781
+ const cachedAdjacentCell = (_this$_stylesCache$fo = this._stylesCache.fontMatrix.getValue(row, adjacentColumn)) === null || _this$_stylesCache$fo === void 0 ? void 0 : _this$_stylesCache$fo.cellData;
19782
+ return !(0, _univerjs_core.isCellCoverable)(cachedAdjacentCell !== null && cachedAdjacentCell !== void 0 ? cachedAdjacentCell : this.worksheet.getCell(row, adjacentColumn)) || hasMergeData && this.intersectMergeRange(row, adjacentColumn);
19783
+ }
19278
19784
  /**
19279
19785
  * Get cell by pos(offsetX, offsetY).
19280
19786
  * @deprecated Please use `getCellWithCoordByOffset` instead.
@@ -19444,7 +19950,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19444
19950
  * the text content of this cell can be drawn to both sides, not limited by the cell's width.
19445
19951
  * Overflow on the left or right is aligned according to the text's horizontal alignment.
19446
19952
  */
19447
- _calculateOverflowCell(row, column, docsConfig) {
19953
+ _calculateOverflowCell(row, column, docsConfig, hasMergeData = true) {
19448
19954
  const { documentSkeleton, vertexAngle = 0, centerAngle = 0, horizontalAlign, wrapStrategy } = docsConfig;
19449
19955
  const { t: cellValueType = _univerjs_core.CellValueType.STRING } = this._cellData.getValue(row, column) || {};
19450
19956
  let horizontalAlignPos = horizontalAlign;
@@ -19460,7 +19966,13 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19460
19966
  * Numerical and Boolean values are not displayed with overflow.
19461
19967
  */
19462
19968
  if ((wrapStrategy === _univerjs_core.WrapStrategy.OVERFLOW || wrapStrategy === _univerjs_core.WrapStrategy.UNSPECIFIED) && cellValueType !== _univerjs_core.CellValueType.NUMBER && cellValueType !== _univerjs_core.CellValueType.BOOLEAN && horizontalAlign !== _univerjs_core.HorizontalAlign.JUSTIFIED) {
19463
- if (this.intersectMergeRange(row, column)) return true;
19969
+ var _docsConfig$cellData$, _docsConfig$cellData, _docsConfig$cellData2;
19970
+ docsConfig.textFitsCurrentCell = false;
19971
+ if (hasMergeData && this.intersectMergeRange(row, column)) return true;
19972
+ const columnStart = this.columnWidthAccumulation[column - 1] || 0;
19973
+ const currentColumnWidth = (this.columnWidthAccumulation[column] || columnStart) - columnStart;
19974
+ const rawText = (_docsConfig$cellData$ = (_docsConfig$cellData = docsConfig.cellData) === null || _docsConfig$cellData === void 0 || (_docsConfig$cellData = _docsConfig$cellData.p) === null || _docsConfig$cellData === void 0 || (_docsConfig$cellData = _docsConfig$cellData.body) === null || _docsConfig$cellData === void 0 ? void 0 : _docsConfig$cellData.dataStream) !== null && _docsConfig$cellData$ !== void 0 ? _docsConfig$cellData$ : (_docsConfig$cellData2 = docsConfig.cellData) === null || _docsConfig$cellData2 === void 0 ? void 0 : _docsConfig$cellData2.v;
19975
+ if ((Boolean(documentSkeleton) || `${rawText !== null && rawText !== void 0 ? rawText : ""}`.length * 4 > currentColumnWidth) && this._isOverflowBlockedByAdjacentCell(row, column, horizontalAlignPos, hasMergeData)) return true;
19464
19976
  let contentSize;
19465
19977
  if (documentSkeleton) contentSize = getDocsSkeletonPageSize(documentSkeleton, vertexAngle);
19466
19978
  else {
@@ -19480,11 +19992,15 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19480
19992
  height: cellHeight
19481
19993
  };
19482
19994
  }
19995
+ if (contentSize.width < currentColumnWidth) {
19996
+ docsConfig.textFitsCurrentCell = true;
19997
+ return true;
19998
+ }
19483
19999
  const { startColumn, endColumn } = this.getOverflowPosition(contentSize, horizontalAlignPos, row, column, this.getColumnCount());
19484
20000
  if (startColumn === endColumn) return true;
19485
20001
  this.appendToOverflowCache(row, column, startColumn, endColumn);
19486
20002
  } else if (wrapStrategy === _univerjs_core.WrapStrategy.WRAP && vertexAngle !== 0) {
19487
- if (this.intersectMergeRange(row, column)) return true;
20003
+ if (hasMergeData && this.intersectMergeRange(row, column)) return true;
19488
20004
  const { startY, endY } = this.getCellWithCoordByIndex(row, column);
19489
20005
  const cellHeight = endY - startY;
19490
20006
  documentSkeleton.getViewModel().getDataModel().updateDocumentDataPageSize(cellHeight);
@@ -19516,16 +20032,18 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19516
20032
  const startRow = (0, _univerjs_core.searchArray)(rowHeightAccumulation, Math.round(viewBound.top) - this.columnHeaderHeightAndMarginTop);
19517
20033
  const endY = Math.round(viewBound.bottom) - this.columnHeaderHeightAndMarginTop;
19518
20034
  let endRow = (0, _univerjs_core.searchArray)(rowHeightAccumulation, endY);
19519
- if (endRow < lenOfRowData && rowHeightAccumulation[endRow - 1] === endY) endRow -= 1;
20035
+ const isEndYOnBoundary = endRow < lenOfRowData && rowHeightAccumulation[endRow - 1] === endY;
20036
+ if (isEndYOnBoundary) endRow -= 1;
19520
20037
  const startColumn = (0, _univerjs_core.searchArray)(columnWidthAccumulation, Math.round(viewBound.left) - this.rowHeaderWidthAndMarginLeft);
19521
20038
  const endX = Math.round(viewBound.right) - this.rowHeaderWidthAndMarginLeft;
19522
20039
  let endColumn = (0, _univerjs_core.searchArray)(columnWidthAccumulation, endX);
19523
- if (endColumn < lenOfColData && columnWidthAccumulation[endColumn - 1] === endX) endColumn -= 1;
20040
+ const isEndXOnBoundary = endColumn < lenOfColData && columnWidthAccumulation[endColumn - 1] === endX;
20041
+ if (isEndXOnBoundary) endColumn -= 1;
19524
20042
  if (isPrinting) return {
19525
20043
  startRow,
19526
- endRow: endRow === lenOfRowData - 1 ? endRow : endRow - 1,
20044
+ endRow: endRow === lenOfRowData - 1 || isEndYOnBoundary ? endRow : endRow - 1,
19527
20045
  startColumn,
19528
- endColumn: endColumn === lenOfColData - 1 ? endColumn : endColumn - 1
20046
+ endColumn: endColumn === lenOfColData - 1 || isEndXOnBoundary ? endColumn : endColumn - 1
19529
20047
  };
19530
20048
  return {
19531
20049
  startRow,
@@ -19576,7 +20094,15 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19576
20094
  for (let i = 0; i < ranges.length; i++) {
19577
20095
  const range = ranges[i];
19578
20096
  _univerjs_core.Range.foreach(range, (row, col) => {
20097
+ var _this$_stylesCache$bo, _this$_stylesCache$ba, _this$_stylesCache$ba2;
19579
20098
  this._stylesCache.fontMatrix.realDeleteValue(row, col);
20099
+ (_this$_stylesCache$bo = this._stylesCache.border) === null || _this$_stylesCache$bo === void 0 || _this$_stylesCache$bo.realDeleteValue(row, col);
20100
+ (_this$_stylesCache$ba = this._stylesCache.backgroundPositions) === null || _this$_stylesCache$ba === void 0 || _this$_stylesCache$ba.realDeleteValue(row, col);
20101
+ this._handleBgMatrix.realDeleteValue(row, col);
20102
+ this._handleBorderMatrix.realDeleteValue(row, col);
20103
+ Object.values((_this$_stylesCache$ba2 = this._stylesCache.background) !== null && _this$_stylesCache$ba2 !== void 0 ? _this$_stylesCache$ba2 : {}).forEach((backgroundMatrix) => {
20104
+ backgroundMatrix.realDeleteValue(row, col);
20105
+ });
19580
20106
  });
19581
20107
  }
19582
20108
  this.makeDirty(true);
@@ -19617,15 +20143,15 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19617
20143
  }).bg) return;
19618
20144
  this._handleBgMatrix.setValue(row, col, true);
19619
20145
  if (style && style.bg && style.bg.rgb) {
19620
- var _this$_stylesCache$ba;
20146
+ var _this$_stylesCache$ba3;
19621
20147
  const rgb = style.bg.rgb;
19622
20148
  if (!this._stylesCache.background[rgb]) this._stylesCache.background[rgb] = new _univerjs_core.ObjectMatrix();
19623
20149
  this._stylesCache.background[rgb].setValue(row, col, rgb);
19624
20150
  const cellInfo = this.getCellWithCoordByIndex(row, col, false);
19625
- (_this$_stylesCache$ba = this._stylesCache.backgroundPositions) === null || _this$_stylesCache$ba === void 0 || _this$_stylesCache$ba.setValue(row, col, cellInfo);
20151
+ (_this$_stylesCache$ba3 = this._stylesCache.backgroundPositions) === null || _this$_stylesCache$ba3 === void 0 || _this$_stylesCache$ba3.setValue(row, col, cellInfo);
19626
20152
  }
19627
20153
  }
19628
- _setFontStylesCache(row, col, cellData, style) {
20154
+ _setFontStylesCache(row, col, cellData, style, hasMergeData = true) {
19629
20155
  var _style$tr2;
19630
20156
  if ((0, _univerjs_core.isNullCell)(cellData)) return;
19631
20157
  let config = {
@@ -19637,6 +20163,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19637
20163
  else {
19638
20164
  const cacheItem = cacheValue;
19639
20165
  cacheItem.cellData = cellData;
20166
+ setRenderTextCache(cacheItem, cellData);
19640
20167
  this._stylesCache.fontMatrix.setValue(row, col, cacheValue);
19641
20168
  return;
19642
20169
  }
@@ -19680,8 +20207,10 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19680
20207
  style
19681
20208
  };
19682
20209
  }
19683
- this._calculateOverflowCell(row, col, config);
19684
- this._stylesCache.fontMatrix.setValue(row, col, config);
20210
+ const fontCacheItem = config;
20211
+ setRenderTextCache(fontCacheItem, cellData);
20212
+ this._calculateOverflowCell(row, col, fontCacheItem, hasMergeData);
20213
+ this._stylesCache.fontMatrix.setValue(row, col, fontCacheItem);
19685
20214
  }
19686
20215
  /**
19687
20216
  * Set border background and font to this._stylesCache cell by cell.
@@ -19690,19 +20219,37 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19690
20219
  * @param options {{ mergeRange: IRange; cacheItem: ICacheItem } | undefined}
19691
20220
  */
19692
20221
  _setStylesCacheForOneCell(row, col, options) {
20222
+ var _options$hasMergeData, _options$rowVisible, _options$hasMergeData2;
19693
20223
  if (row === -1 || col === -1) return;
19694
20224
  if (!options) options = { cacheItem: {
19695
20225
  bg: true,
19696
20226
  border: true
19697
20227
  } };
19698
- const { isMerged, isMergedMainCell, startRow, startColumn, endRow, endColumn } = this.worksheet.getCellInfoInMergeData(row, col);
19699
- if (isMerged) options.mergeRange = {
19700
- startRow,
19701
- startColumn,
19702
- endRow,
19703
- endColumn
19704
- };
19705
- if (this.worksheet.getColVisible(col) === false || this.worksheet.getRowVisible(row) === false) {
20228
+ const cacheItem = options.cacheItem;
20229
+ if (options.reuseExisting && cacheItem && !options.mergeRange) {
20230
+ const bgHandled = !cacheItem.bg || _univerjs_core.Tools.isDefine(this._handleBgMatrix.getValue(row, col));
20231
+ const borderHandled = !cacheItem.border || _univerjs_core.Tools.isDefine(this._handleBorderMatrix.getValue(row, col));
20232
+ if (bgHandled && borderHandled && this._stylesCache.fontMatrix.getValue(row, col)) return;
20233
+ }
20234
+ const hasMergeData = (_options$hasMergeData = options.hasMergeData) !== null && _options$hasMergeData !== void 0 ? _options$hasMergeData : true;
20235
+ let isMerged = false;
20236
+ let isMergedMainCell = false;
20237
+ if (hasMergeData) {
20238
+ const mergeInfo = this.worksheet.getCellInfoInMergeData(row, col);
20239
+ isMerged = mergeInfo.isMerged;
20240
+ isMergedMainCell = mergeInfo.isMergedMainCell;
20241
+ if (isMerged) {
20242
+ const { startRow, startColumn, endRow, endColumn } = mergeInfo;
20243
+ options.mergeRange = {
20244
+ startRow,
20245
+ startColumn,
20246
+ endRow,
20247
+ endColumn
20248
+ };
20249
+ }
20250
+ }
20251
+ const rowVisible = (_options$rowVisible = options.rowVisible) !== null && _options$rowVisible !== void 0 ? _options$rowVisible : this.worksheet.getRowVisible(row);
20252
+ if (this.worksheet.getColVisible(col) === false || rowVisible === false) {
19706
20253
  if (isMerged && !isMergedMainCell) return;
19707
20254
  else if (!isMergedMainCell) return;
19708
20255
  }
@@ -19714,7 +20261,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19714
20261
  this._setFontStylesCache(row, col, {
19715
20262
  ...cell,
19716
20263
  s: style
19717
- }, style);
20264
+ }, style, (_options$hasMergeData2 = options.hasMergeData) !== null && _options$hasMergeData2 !== void 0 ? _options$hasMergeData2 : true);
19718
20265
  }
19719
20266
  /**
19720
20267
  * pro/issues/344
@@ -19927,6 +20474,19 @@ function rotatedBoundingBox(width, height, angleDegrees) {
19927
20474
  rotatedHeight: Math.abs(width * Math.sin(angle)) + Math.abs(height * Math.cos(angle))
19928
20475
  };
19929
20476
  }
20477
+ function getResolvedRenderHorizontalAlign(fontCache, cellData) {
20478
+ if (fontCache.resolvedHorizontalAlign !== void 0) return fontCache.resolvedHorizontalAlign;
20479
+ const { horizontalAlign } = fontCache;
20480
+ if (horizontalAlign !== _univerjs_core.HorizontalAlign.UNSPECIFIED) return horizontalAlign;
20481
+ if (cellData.t === _univerjs_core.CellValueType.NUMBER || !_univerjs_core.Tools.isDefine(cellData.t) && typeof cellData.v === "number") return _univerjs_core.HorizontalAlign.RIGHT;
20482
+ if (cellData.t === _univerjs_core.CellValueType.BOOLEAN) return _univerjs_core.HorizontalAlign.CENTER;
20483
+ return horizontalAlign;
20484
+ }
20485
+ function needsFontRenderExtensionBounds(fontCache) {
20486
+ var _fontCache$cellData;
20487
+ const extension = (_fontCache$cellData = fontCache.cellData) === null || _fontCache$cellData === void 0 ? void 0 : _fontCache$cellData.fontRenderExtension;
20488
+ return Boolean((extension === null || extension === void 0 ? void 0 : extension.isSkip) || (extension === null || extension === void 0 ? void 0 : extension.leftOffset) || (extension === null || extension === void 0 ? void 0 : extension.rightOffset));
20489
+ }
19930
20490
  var Font = class extends SheetExtension {
19931
20491
  constructor() {
19932
20492
  super();
@@ -19957,7 +20517,7 @@ var Font = class extends SheetExtension {
19957
20517
  const { rowHeightAccumulation, columnTotalWidth, columnWidthAccumulation, rowTotalHeight } = spreadsheetSkeleton;
19958
20518
  if (!rowHeightAccumulation || !columnWidthAccumulation || columnTotalWidth === void 0 || rowTotalHeight === void 0 || !worksheet) return;
19959
20519
  const scale = this._getScale(parentScale);
19960
- const { viewRanges = [], checkOutOfViewBound } = moreBoundsInfo;
20520
+ const { fontRenderRanges, viewRanges = [], checkOutOfViewBound } = moreBoundsInfo;
19961
20521
  const lastRowIndex = spreadsheetSkeleton.getRowCount() - 1;
19962
20522
  const lastColIndex = spreadsheetSkeleton.getColumnCount() - 1;
19963
20523
  const expandedViewRanges = viewRanges.map((range) => clampRange({
@@ -19965,43 +20525,51 @@ var Font = class extends SheetExtension {
19965
20525
  startColumn: range.startColumn - 20,
19966
20526
  endColumn: range.endColumn + 20
19967
20527
  }, lastRowIndex, lastColIndex));
20528
+ const rangesToScan = (fontRenderRanges === null || fontRenderRanges === void 0 ? void 0 : fontRenderRanges.length) ? fontRenderRanges : expandedViewRanges;
19968
20529
  const renderFontContext = {
19969
20530
  ctx,
19970
20531
  scale,
19971
20532
  columnTotalWidth,
19972
20533
  rowTotalHeight,
19973
- viewRanges: expandedViewRanges,
20534
+ viewRanges: (fontRenderRanges === null || fontRenderRanges === void 0 ? void 0 : fontRenderRanges.length) ? viewRanges : expandedViewRanges,
19974
20535
  checkOutOfViewBound: checkOutOfViewBound || true,
19975
20536
  diffRanges,
19976
20537
  spreadsheetSkeleton
19977
20538
  };
19978
20539
  ctx.save();
20540
+ const hasMerge = spreadsheetSkeleton.worksheet.getMergeData().length > 0;
19979
20541
  const uniqueMergeRanges = [];
19980
- const mergeRangeIDSet = /* @__PURE__ */ new Set();
19981
- expandedViewRanges.forEach((range) => {
19982
- spreadsheetSkeleton.worksheet.getMergedCellRange(range.startRow, range.startColumn, range.endRow, range.endColumn).forEach((mergeRange) => {
19983
- const mergeRangeIndex = spreadsheetSkeleton.worksheet.getSpanModel().getMergeDataIndex(mergeRange.startRow, mergeRange.startColumn);
20542
+ const mergeRangeIDSet = hasMerge ? /* @__PURE__ */ new Set() : null;
20543
+ const spanModel = hasMerge ? spreadsheetSkeleton.worksheet.getSpanModel() : null;
20544
+ rangesToScan.forEach((range) => {
20545
+ if (hasMerge && spanModel && mergeRangeIDSet) spreadsheetSkeleton.worksheet.getMergedCellRange(range.startRow, range.startColumn, range.endRow, range.endColumn).forEach((mergeRange) => {
20546
+ const mergeRangeIndex = spanModel.getMergeDataIndex(mergeRange.startRow, mergeRange.startColumn);
19984
20547
  if (!mergeRangeIDSet.has(mergeRangeIndex)) {
19985
20548
  mergeRangeIDSet.add(mergeRangeIndex);
19986
20549
  uniqueMergeRanges.push(mergeRange);
19987
20550
  }
19988
20551
  });
19989
- _univerjs_core.Range.foreach(range, (row, col) => {
19990
- if (spreadsheetSkeleton.worksheet.getSpanModel().getMergeDataIndex(row, col) !== -1) return;
20552
+ const { startRow, endRow, startColumn, endColumn } = range;
20553
+ for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
20554
+ const fontCache = fontMatrix.getValue(row, col);
20555
+ if (!fontCache) continue;
20556
+ if (spanModel && spanModel.getMergeDataIndex(row, col) !== -1) continue;
19991
20557
  const cellInfo = spreadsheetSkeleton.getCellWithCoordByIndex(row, col, false);
19992
- if (!cellInfo) return;
20558
+ if (!cellInfo) continue;
19993
20559
  renderFontContext.cellInfo = cellInfo;
19994
- this._renderFontEachCell(renderFontContext, row, col, fontMatrix);
19995
- });
20560
+ this._renderFontEachCell(renderFontContext, row, col, fontMatrix, fontCache);
20561
+ }
19996
20562
  });
19997
20563
  uniqueMergeRanges.forEach((range) => {
20564
+ const fontCache = fontMatrix.getValue(range.startRow, range.startColumn);
20565
+ if (!fontCache) return;
19998
20566
  renderFontContext.cellInfo = spreadsheetSkeleton.getCellWithCoordByIndex(range.startRow, range.startColumn, false);
19999
- this._renderFontEachCell(renderFontContext, range.startRow, range.startColumn, fontMatrix);
20567
+ this._renderFontEachCell(renderFontContext, range.startRow, range.startColumn, fontMatrix, fontCache);
20000
20568
  });
20001
20569
  ctx.restore();
20002
20570
  }
20003
- _renderFontEachCell(renderFontCtx, row, col, fontMatrix) {
20004
- var _cellData$fontRenderE;
20571
+ _renderFontEachCell(renderFontCtx, row, col, fontMatrix, cacheValue) {
20572
+ var _fontCache$cellData2;
20005
20573
  const { ctx, viewRanges, diffRanges, spreadsheetSkeleton, cellInfo } = renderFontCtx;
20006
20574
  const { startY, endY, startX, endX } = cellInfo;
20007
20575
  const { isMerged, isMergedMainCell, mergeInfo } = cellInfo;
@@ -20016,7 +20584,7 @@ var Font = class extends SheetExtension {
20016
20584
  renderFontCtx.endX = mergeInfo.endX;
20017
20585
  renderFontCtx.endY = mergeInfo.endY;
20018
20586
  }
20019
- const fontCache = fontMatrix.getValue(row, col);
20587
+ const fontCache = cacheValue !== null && cacheValue !== void 0 ? cacheValue : fontMatrix.getValue(row, col);
20020
20588
  if (!fontCache) return true;
20021
20589
  renderFontCtx.fontCache = fontCache;
20022
20590
  const overflowRange = spreadsheetSkeleton.overflowCache.getValue(row, col);
@@ -20042,8 +20610,19 @@ var Font = class extends SheetExtension {
20042
20610
  }
20043
20611
  if (isAllColHidden) return true;
20044
20612
  }
20045
- const cellData = spreadsheetSkeleton.worksheet.getCell(row, col) || {};
20046
- if (cellData === null || cellData === void 0 || (_cellData$fontRenderE = cellData.fontRenderExtension) === null || _cellData$fontRenderE === void 0 ? void 0 : _cellData$fontRenderE.isSkip) return true;
20613
+ if ((_fontCache$cellData2 = fontCache.cellData) === null || _fontCache$cellData2 === void 0 ? void 0 : _fontCache$cellData2.fontRenderExtension) {
20614
+ var _cellData$fontRenderE;
20615
+ const cellData = spreadsheetSkeleton.worksheet.getCell(row, col) || {};
20616
+ if (cellData === null || cellData === void 0 || (_cellData$fontRenderE = cellData.fontRenderExtension) === null || _cellData$fontRenderE === void 0 ? void 0 : _cellData$fontRenderE.isSkip) return true;
20617
+ }
20618
+ if (this._renderPlainTextWithoutClip(ctx, renderFontCtx, fontCache)) {
20619
+ renderFontCtx.startX = 0;
20620
+ renderFontCtx.startY = 0;
20621
+ renderFontCtx.endX = 0;
20622
+ renderFontCtx.endY = 0;
20623
+ renderFontCtx.overflowRectangle = null;
20624
+ return false;
20625
+ }
20047
20626
  ctx.save();
20048
20627
  ctx.beginPath();
20049
20628
  renderFontCtx.overflowRectangle = overflowRange;
@@ -20051,7 +20630,6 @@ var Font = class extends SheetExtension {
20051
20630
  ctx.translate(renderFontCtx.startX + FIX_ONE_PIXEL_BLUR_OFFSET, renderFontCtx.startY + FIX_ONE_PIXEL_BLUR_OFFSET);
20052
20631
  if (fontCache.documentSkeleton) this._renderDocuments(ctx, row, col, renderFontCtx, spreadsheetSkeleton.overflowCache);
20053
20632
  else this._renderText(ctx, row, col, renderFontCtx, spreadsheetSkeleton.overflowCache);
20054
- ctx.closePath();
20055
20633
  ctx.restore();
20056
20634
  if (fontCache.documentSkeleton) {
20057
20635
  var _documentDataModel$ge;
@@ -20071,15 +20649,49 @@ var Font = class extends SheetExtension {
20071
20649
  renderFontCtx.overflowRectangle = null;
20072
20650
  return false;
20073
20651
  }
20652
+ _renderPlainTextWithoutClip(ctx, renderFontCtx, fontCache) {
20653
+ var _fontCache$style, _fontCache$style2, _fontCache$style$pd, _fontCache$style3, _padding$l, _padding$r, _padding$t, _padding$b, _fontCache$displayTex, _fontCache$style4;
20654
+ const { cellData, documentSkeleton, textFitsCurrentCell, vertexAngle = 0, centerAngle = 0, wrapStrategy } = fontCache;
20655
+ if (!textFitsCurrentCell) return false;
20656
+ if (documentSkeleton) return false;
20657
+ if (vertexAngle !== 0 || centerAngle !== 0) return false;
20658
+ if (wrapStrategy === _univerjs_core.WrapStrategy.WRAP) return false;
20659
+ if (needsFontRenderExtensionBounds(fontCache)) return false;
20660
+ if (((_fontCache$style = fontCache.style) === null || _fontCache$style === void 0 || (_fontCache$style = _fontCache$style.st) === null || _fontCache$style === void 0 ? void 0 : _fontCache$style.s) || ((_fontCache$style2 = fontCache.style) === null || _fontCache$style2 === void 0 || (_fontCache$style2 = _fontCache$style2.ul) === null || _fontCache$style2 === void 0 ? void 0 : _fontCache$style2.s)) return false;
20661
+ if ((cellData === null || cellData === void 0 ? void 0 : cellData.v) === void 0 || (cellData === null || cellData === void 0 ? void 0 : cellData.v) === null) return false;
20662
+ const padding = (_fontCache$style$pd = (_fontCache$style3 = fontCache.style) === null || _fontCache$style3 === void 0 ? void 0 : _fontCache$style3.pd) !== null && _fontCache$style$pd !== void 0 ? _fontCache$style$pd : DEFAULT_PADDING_DATA;
20663
+ const paddingLeft = (_padding$l = padding.l) !== null && _padding$l !== void 0 ? _padding$l : DEFAULT_PADDING_DATA.l;
20664
+ const paddingRight = (_padding$r = padding.r) !== null && _padding$r !== void 0 ? _padding$r : DEFAULT_PADDING_DATA.r;
20665
+ const paddingTop = (_padding$t = padding.t) !== null && _padding$t !== void 0 ? _padding$t : DEFAULT_PADDING_DATA.t;
20666
+ const paddingBottom = (_padding$b = padding.b) !== null && _padding$b !== void 0 ? _padding$b : DEFAULT_PADDING_DATA.b;
20667
+ const text = (_fontCache$displayTex = fontCache.displayText) !== null && _fontCache$displayTex !== void 0 ? _fontCache$displayTex : (0, _univerjs_core.getDisplayValueFromCell)(cellData);
20668
+ const { startX, startY, endX, endY } = renderFontCtx;
20669
+ const cellWidth = endX - startX - paddingLeft - paddingRight;
20670
+ const cellHeight = endY - startY - paddingTop - paddingBottom;
20671
+ const hAlign = getResolvedRenderHorizontalAlign(fontCache, cellData);
20672
+ Text.drawPlainWith(ctx, {
20673
+ text,
20674
+ fontStyle: fontCache.fontString,
20675
+ hAlign,
20676
+ vAlign: fontCache.verticalAlign,
20677
+ width: cellWidth,
20678
+ height: cellHeight,
20679
+ left: startX + FIX_ONE_PIXEL_BLUR_OFFSET + paddingLeft,
20680
+ top: startY + FIX_ONE_PIXEL_BLUR_OFFSET + paddingTop,
20681
+ color: (_fontCache$style4 = fontCache.style) === null || _fontCache$style4 === void 0 || (_fontCache$style4 = _fontCache$style4.cl) === null || _fontCache$style4 === void 0 ? void 0 : _fontCache$style4.rgb,
20682
+ cellValueType: cellData.t
20683
+ });
20684
+ return true;
20685
+ }
20074
20686
  _renderImages(ctx, fontsConfig, startX, startY, endX, endY) {
20075
- var _fontsConfig$style, _padding$l, _padding$r, _padding$t, _padding$b, _getSkeletonData;
20687
+ var _fontsConfig$style, _padding$l2, _padding$r2, _padding$t2, _padding$b2, _getSkeletonData;
20076
20688
  const { documentSkeleton, verticalAlign, horizontalAlign } = fontsConfig;
20077
20689
  const PADDING = 2;
20078
20690
  const padding = (_fontsConfig$style = fontsConfig.style) === null || _fontsConfig$style === void 0 ? void 0 : _fontsConfig$style.pd;
20079
- const paddingLeft = (_padding$l = padding === null || padding === void 0 ? void 0 : padding.l) !== null && _padding$l !== void 0 ? _padding$l : PADDING;
20080
- const paddingRight = (_padding$r = padding === null || padding === void 0 ? void 0 : padding.r) !== null && _padding$r !== void 0 ? _padding$r : PADDING;
20081
- const paddingTop = (_padding$t = padding === null || padding === void 0 ? void 0 : padding.t) !== null && _padding$t !== void 0 ? _padding$t : PADDING;
20082
- const paddingBottom = (_padding$b = padding === null || padding === void 0 ? void 0 : padding.b) !== null && _padding$b !== void 0 ? _padding$b : PADDING;
20691
+ const paddingLeft = (_padding$l2 = padding === null || padding === void 0 ? void 0 : padding.l) !== null && _padding$l2 !== void 0 ? _padding$l2 : PADDING;
20692
+ const paddingRight = (_padding$r2 = padding === null || padding === void 0 ? void 0 : padding.r) !== null && _padding$r2 !== void 0 ? _padding$r2 : PADDING;
20693
+ const paddingTop = (_padding$t2 = padding === null || padding === void 0 ? void 0 : padding.t) !== null && _padding$t2 !== void 0 ? _padding$t2 : PADDING;
20694
+ const paddingBottom = (_padding$b2 = padding === null || padding === void 0 ? void 0 : padding.b) !== null && _padding$b2 !== void 0 ? _padding$b2 : PADDING;
20083
20695
  const contentStartX = startX + paddingLeft;
20084
20696
  const contentEndX = endX - paddingRight;
20085
20697
  const contentStartY = startY + paddingTop;
@@ -20149,7 +20761,7 @@ var Font = class extends SheetExtension {
20149
20761
  * @param fontCache
20150
20762
  */
20151
20763
  _clipByRenderBounds(renderFontContext, row, col, padding = 0) {
20152
- var _fontCache$cellData$f, _fontCache$cellData, _fontCache$cellData$f2, _fontCache$cellData2;
20764
+ var _fontCache$cellData$f, _fontCache$cellData3, _fontCache$cellData$f2, _fontCache$cellData4;
20153
20765
  const { ctx, scale, overflowRectangle, fontCache } = renderFontContext;
20154
20766
  let { startX, endX, startY, endY } = renderFontContext;
20155
20767
  const { horizontalAlign = 0, vertexAngle = 0, centerAngle = 0 } = fontCache;
@@ -20158,8 +20770,8 @@ var Font = class extends SheetExtension {
20158
20770
  if (centerAngle === 90 && vertexAngle === 90) horizontalAlignOverFlow = _univerjs_core.HorizontalAlign.CENTER;
20159
20771
  else if (vertexAngle > 0 && vertexAngle !== 90 || vertexAngle === -90) horizontalAlignOverFlow = _univerjs_core.HorizontalAlign.RIGHT;
20160
20772
  }
20161
- const rightOffset = (_fontCache$cellData$f = fontCache === null || fontCache === void 0 || (_fontCache$cellData = fontCache.cellData) === null || _fontCache$cellData === void 0 || (_fontCache$cellData = _fontCache$cellData.fontRenderExtension) === null || _fontCache$cellData === void 0 ? void 0 : _fontCache$cellData.rightOffset) !== null && _fontCache$cellData$f !== void 0 ? _fontCache$cellData$f : 0;
20162
- const leftOffset = (_fontCache$cellData$f2 = fontCache === null || fontCache === void 0 || (_fontCache$cellData2 = fontCache.cellData) === null || _fontCache$cellData2 === void 0 || (_fontCache$cellData2 = _fontCache$cellData2.fontRenderExtension) === null || _fontCache$cellData2 === void 0 ? void 0 : _fontCache$cellData2.leftOffset) !== null && _fontCache$cellData$f2 !== void 0 ? _fontCache$cellData$f2 : 0;
20773
+ const rightOffset = (_fontCache$cellData$f = fontCache === null || fontCache === void 0 || (_fontCache$cellData3 = fontCache.cellData) === null || _fontCache$cellData3 === void 0 || (_fontCache$cellData3 = _fontCache$cellData3.fontRenderExtension) === null || _fontCache$cellData3 === void 0 ? void 0 : _fontCache$cellData3.rightOffset) !== null && _fontCache$cellData$f !== void 0 ? _fontCache$cellData$f : 0;
20774
+ const leftOffset = (_fontCache$cellData$f2 = fontCache === null || fontCache === void 0 || (_fontCache$cellData4 = fontCache.cellData) === null || _fontCache$cellData4 === void 0 || (_fontCache$cellData4 = _fontCache$cellData4.fontRenderExtension) === null || _fontCache$cellData4 === void 0 ? void 0 : _fontCache$cellData4.leftOffset) !== null && _fontCache$cellData$f2 !== void 0 ? _fontCache$cellData$f2 : 0;
20163
20775
  let isOverflow = true;
20164
20776
  if (vertexAngle === 0) {
20165
20777
  startX = startX + leftOffset;
@@ -20191,26 +20803,22 @@ var Font = class extends SheetExtension {
20191
20803
  renderFontContext.endY = endY;
20192
20804
  }
20193
20805
  _renderText(ctx, row, col, renderFontCtx, overflowCache) {
20194
- var _fontCache$style$pd, _fontCache$style, _padding$l2, _padding$r2, _padding$t2, _padding$b2, _fontCache$style2, _fontCache$style3, _fontCache$style4, _fontCache$style5;
20806
+ var _fontCache$style$pd2, _fontCache$style5, _padding$l3, _padding$r3, _padding$t3, _padding$b3, _fontCache$displayTex2, _fontCache$style6, _fontCache$style7, _fontCache$style8, _fontCache$style9;
20195
20807
  const { fontCache } = renderFontCtx;
20196
20808
  if (!fontCache) return;
20197
- const padding = (_fontCache$style$pd = (_fontCache$style = fontCache.style) === null || _fontCache$style === void 0 ? void 0 : _fontCache$style.pd) !== null && _fontCache$style$pd !== void 0 ? _fontCache$style$pd : DEFAULT_PADDING_DATA;
20198
- const paddingLeft = (_padding$l2 = padding.l) !== null && _padding$l2 !== void 0 ? _padding$l2 : DEFAULT_PADDING_DATA.l;
20199
- const paddingRight = (_padding$r2 = padding.r) !== null && _padding$r2 !== void 0 ? _padding$r2 : DEFAULT_PADDING_DATA.r;
20200
- const paddingTop = (_padding$t2 = padding.t) !== null && _padding$t2 !== void 0 ? _padding$t2 : DEFAULT_PADDING_DATA.t;
20201
- const paddingBottom = (_padding$b2 = padding.b) !== null && _padding$b2 !== void 0 ? _padding$b2 : DEFAULT_PADDING_DATA.b;
20809
+ const padding = (_fontCache$style$pd2 = (_fontCache$style5 = fontCache.style) === null || _fontCache$style5 === void 0 ? void 0 : _fontCache$style5.pd) !== null && _fontCache$style$pd2 !== void 0 ? _fontCache$style$pd2 : DEFAULT_PADDING_DATA;
20810
+ const paddingLeft = (_padding$l3 = padding.l) !== null && _padding$l3 !== void 0 ? _padding$l3 : DEFAULT_PADDING_DATA.l;
20811
+ const paddingRight = (_padding$r3 = padding.r) !== null && _padding$r3 !== void 0 ? _padding$r3 : DEFAULT_PADDING_DATA.r;
20812
+ const paddingTop = (_padding$t3 = padding.t) !== null && _padding$t3 !== void 0 ? _padding$t3 : DEFAULT_PADDING_DATA.t;
20813
+ const paddingBottom = (_padding$b3 = padding.b) !== null && _padding$b3 !== void 0 ? _padding$b3 : DEFAULT_PADDING_DATA.b;
20202
20814
  const { vertexAngle = 0, wrapStrategy, cellData } = fontCache;
20203
20815
  if ((cellData === null || cellData === void 0 ? void 0 : cellData.v) === void 0 || (cellData === null || cellData === void 0 ? void 0 : cellData.v) === null) return;
20204
- const text = (0, _univerjs_core.getDisplayValueFromCell)(cellData);
20816
+ const text = (_fontCache$displayTex2 = fontCache.displayText) !== null && _fontCache$displayTex2 !== void 0 ? _fontCache$displayTex2 : (0, _univerjs_core.getDisplayValueFromCell)(cellData);
20205
20817
  const { startX, startY, endX, endY } = renderFontCtx;
20206
20818
  const cellWidth = endX - startX - paddingLeft - paddingRight;
20207
20819
  const cellHeight = endY - startY - paddingTop - paddingBottom;
20208
- let hAlign = fontCache.horizontalAlign;
20209
- if (fontCache.horizontalAlign === _univerjs_core.HorizontalAlign.UNSPECIFIED) {
20210
- if (cellData.t === _univerjs_core.CellValueType.NUMBER || !_univerjs_core.Tools.isDefine(cellData.t) && typeof cellData.v === "number") hAlign = _univerjs_core.HorizontalAlign.RIGHT;
20211
- else if (cellData.t === _univerjs_core.CellValueType.BOOLEAN) hAlign = _univerjs_core.HorizontalAlign.CENTER;
20212
- }
20213
- Text.drawWith(ctx, {
20820
+ const hAlign = getResolvedRenderHorizontalAlign(fontCache, cellData);
20821
+ const textProps = {
20214
20822
  text,
20215
20823
  fontStyle: fontCache.fontString,
20216
20824
  warp: wrapStrategy === _univerjs_core.WrapStrategy.WRAP && vertexAngle === 0,
@@ -20220,12 +20828,17 @@ var Font = class extends SheetExtension {
20220
20828
  height: cellHeight,
20221
20829
  left: paddingLeft,
20222
20830
  top: paddingTop,
20223
- color: (_fontCache$style2 = fontCache.style) === null || _fontCache$style2 === void 0 || (_fontCache$style2 = _fontCache$style2.cl) === null || _fontCache$style2 === void 0 ? void 0 : _fontCache$style2.rgb,
20224
- strokeLine: Boolean((_fontCache$style3 = fontCache.style) === null || _fontCache$style3 === void 0 || (_fontCache$style3 = _fontCache$style3.st) === null || _fontCache$style3 === void 0 ? void 0 : _fontCache$style3.s),
20225
- underline: Boolean((_fontCache$style4 = fontCache.style) === null || _fontCache$style4 === void 0 || (_fontCache$style4 = _fontCache$style4.ul) === null || _fontCache$style4 === void 0 ? void 0 : _fontCache$style4.s),
20226
- underlineType: (_fontCache$style5 = fontCache.style) === null || _fontCache$style5 === void 0 || (_fontCache$style5 = _fontCache$style5.ul) === null || _fontCache$style5 === void 0 ? void 0 : _fontCache$style5.t,
20831
+ color: (_fontCache$style6 = fontCache.style) === null || _fontCache$style6 === void 0 || (_fontCache$style6 = _fontCache$style6.cl) === null || _fontCache$style6 === void 0 ? void 0 : _fontCache$style6.rgb,
20832
+ strokeLine: Boolean((_fontCache$style7 = fontCache.style) === null || _fontCache$style7 === void 0 || (_fontCache$style7 = _fontCache$style7.st) === null || _fontCache$style7 === void 0 ? void 0 : _fontCache$style7.s),
20833
+ underline: Boolean((_fontCache$style8 = fontCache.style) === null || _fontCache$style8 === void 0 || (_fontCache$style8 = _fontCache$style8.ul) === null || _fontCache$style8 === void 0 ? void 0 : _fontCache$style8.s),
20834
+ underlineType: (_fontCache$style9 = fontCache.style) === null || _fontCache$style9 === void 0 || (_fontCache$style9 = _fontCache$style9.ul) === null || _fontCache$style9 === void 0 ? void 0 : _fontCache$style9.t,
20227
20835
  cellValueType: cellData.t
20228
- });
20836
+ };
20837
+ if (!textProps.warp && !textProps.strokeLine && !textProps.underline) {
20838
+ Text.drawPlainWith(ctx, textProps);
20839
+ return;
20840
+ }
20841
+ Text.drawWith(ctx, textProps);
20229
20842
  }
20230
20843
  _renderDocuments(ctx, row, col, renderFontCtx, overflowCache) {
20231
20844
  const documents = this.getDocuments();
@@ -20295,6 +20908,15 @@ const stringifyRange = (range) => {
20295
20908
  const { startRow, endRow, startColumn, endColumn } = range;
20296
20909
  return `${startRow}-${endRow}-${startColumn}-${endColumn}`;
20297
20910
  };
20911
+ function drawTriangleMarker(ctx, color, x, y, x2, y2, x3, y3) {
20912
+ ctx.fillStyle = color;
20913
+ ctx.beginPath();
20914
+ ctx.moveTo(x, y);
20915
+ ctx.lineTo(x2, y2);
20916
+ ctx.lineTo(x3, y3);
20917
+ ctx.closePath();
20918
+ ctx.fill();
20919
+ }
20298
20920
  var Marker = class extends SheetExtension {
20299
20921
  constructor(..._args) {
20300
20922
  super(..._args);
@@ -20306,11 +20928,15 @@ var Marker = class extends SheetExtension {
20306
20928
  const { worksheet, rowColumnSegment } = skeleton;
20307
20929
  if (!worksheet) return;
20308
20930
  const mergeCellRendered = /* @__PURE__ */ new Set();
20309
- ((diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [rowColumnSegment]).forEach((range) => {
20310
- _univerjs_core.Range.foreach(range, (row, col) => {
20931
+ const renderRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [rowColumnSegment];
20932
+ const hasMerge = worksheet.getMergeData().length > 0;
20933
+ renderRanges.forEach((range) => {
20934
+ const { startRow, endRow, startColumn, endColumn } = range;
20935
+ for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
20311
20936
  var _cellData$markers, _cellData$markers2, _cellData$markers3, _cellData$markers4;
20312
- if (!worksheet.getRowVisible(row) || !worksheet.getColVisible(col)) return;
20937
+ if (!worksheet.getRowVisible(row) || !worksheet.getColVisible(col)) continue;
20313
20938
  let cellData = worksheet.getCell(row, col);
20939
+ if (!hasMerge && !(cellData === null || cellData === void 0 ? void 0 : cellData.markers)) continue;
20314
20940
  const cellInfo = skeleton.getCellWithCoordByIndex(row, col, false);
20315
20941
  const { isMerged, isMergedMainCell, mergeInfo } = cellInfo;
20316
20942
  let { startY, endY, startX, endX } = cellInfo;
@@ -20327,74 +20953,38 @@ var Marker = class extends SheetExtension {
20327
20953
  };
20328
20954
  cellData = worksheet.getCell(mainCell.row, mainCell.col);
20329
20955
  }
20330
- if (!this.isRenderDiffRangesByRow(mergeInfo.startRow, mergeInfo.endRow, diffRanges)) return true;
20956
+ if (!this.isRenderDiffRangesByRow(mergeInfo.startRow, mergeInfo.endRow, diffRanges)) continue;
20331
20957
  if (cellInfo.isMerged || cellInfo.isMergedMainCell) {
20332
20958
  const rangeStr = stringifyRange(mergeInfo);
20333
- if (mergeCellRendered.has(rangeStr)) return;
20959
+ if (mergeCellRendered.has(rangeStr)) continue;
20334
20960
  mergeCellRendered.add(rangeStr);
20335
20961
  }
20336
- if (!cellData) return;
20962
+ if (!cellData) continue;
20337
20963
  if ((_cellData$markers = cellData.markers) === null || _cellData$markers === void 0 ? void 0 : _cellData$markers.tr) {
20338
- ctx.save();
20339
20964
  const marker = cellData.markers.tr;
20340
20965
  const x = endX;
20341
20966
  const y = startY;
20342
- ctx.fillStyle = marker.color;
20343
- ctx.moveTo(x, y);
20344
- ctx.beginPath();
20345
- ctx.lineTo(x - marker.size, y);
20346
- ctx.lineTo(x, y + marker.size);
20347
- ctx.lineTo(x, y);
20348
- ctx.closePath();
20349
- ctx.fill();
20350
- ctx.restore();
20967
+ drawTriangleMarker(ctx, marker.color, x, y, x - marker.size, y, x, y + marker.size);
20351
20968
  }
20352
20969
  if ((_cellData$markers2 = cellData.markers) === null || _cellData$markers2 === void 0 ? void 0 : _cellData$markers2.tl) {
20353
- ctx.save();
20354
20970
  const marker = cellData.markers.tl;
20355
20971
  const x = startX;
20356
20972
  const y = startY;
20357
- ctx.fillStyle = marker.color;
20358
- ctx.moveTo(x, y);
20359
- ctx.beginPath();
20360
- ctx.lineTo(x + marker.size, y);
20361
- ctx.lineTo(x, y + marker.size);
20362
- ctx.lineTo(x, y);
20363
- ctx.closePath();
20364
- ctx.fill();
20365
- ctx.restore();
20973
+ drawTriangleMarker(ctx, marker.color, x, y, x + marker.size, y, x, y + marker.size);
20366
20974
  }
20367
20975
  if ((_cellData$markers3 = cellData.markers) === null || _cellData$markers3 === void 0 ? void 0 : _cellData$markers3.br) {
20368
- ctx.save();
20369
20976
  const marker = cellData.markers.br;
20370
20977
  const x = endX;
20371
20978
  const y = endY;
20372
- ctx.fillStyle = marker.color;
20373
- ctx.moveTo(x, y);
20374
- ctx.beginPath();
20375
- ctx.lineTo(x - marker.size, y);
20376
- ctx.lineTo(x, y - marker.size);
20377
- ctx.lineTo(x, y);
20378
- ctx.closePath();
20379
- ctx.fill();
20380
- ctx.restore();
20979
+ drawTriangleMarker(ctx, marker.color, x, y, x - marker.size, y, x, y - marker.size);
20381
20980
  }
20382
20981
  if ((_cellData$markers4 = cellData.markers) === null || _cellData$markers4 === void 0 ? void 0 : _cellData$markers4.bl) {
20383
- ctx.save();
20384
20982
  const marker = cellData.markers.bl;
20385
20983
  const x = startX;
20386
20984
  const y = endY;
20387
- ctx.fillStyle = marker.color;
20388
- ctx.moveTo(x, y);
20389
- ctx.beginPath();
20390
- ctx.lineTo(x + marker.size, y);
20391
- ctx.lineTo(x, y - marker.size);
20392
- ctx.lineTo(x, y);
20393
- ctx.closePath();
20394
- ctx.fill();
20395
- ctx.restore();
20985
+ drawTriangleMarker(ctx, marker.color, x, y, x + marker.size, y, x, y - marker.size);
20396
20986
  }
20397
- });
20987
+ }
20398
20988
  });
20399
20989
  }
20400
20990
  };
@@ -22503,6 +23093,7 @@ const MIN_THUMB_SIZE = 17;
22503
23093
  const DEFAULT_TRACK_SIZE = 10;
22504
23094
  const DEFAULT_THUMB_MARGIN = 2;
22505
23095
  const HOVER_THUMB_MARGIN = 1;
23096
+ const BAR_DRAG_SCROLL_THROTTLE_MS = 32;
22506
23097
  var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22507
23098
  constructor(view, props) {
22508
23099
  super();
@@ -22525,6 +23116,10 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22525
23116
  _defineProperty(this, "_lastY", -1);
22526
23117
  _defineProperty(this, "_isHorizonMove", false);
22527
23118
  _defineProperty(this, "_isVerticalMove", false);
23119
+ _defineProperty(this, "_pendingBarDeltaX", 0);
23120
+ _defineProperty(this, "_pendingBarDeltaY", 0);
23121
+ _defineProperty(this, "_pendingBarScrollFrameId", null);
23122
+ _defineProperty(this, "_pendingBarScrollThrottleId", null);
22528
23123
  _defineProperty(this, "_horizonPointerMoveSub", void 0);
22529
23124
  _defineProperty(this, "_horizonPointerUpSub", void 0);
22530
23125
  _defineProperty(this, "_verticalPointerMoveSub", void 0);
@@ -22662,6 +23257,7 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22662
23257
  dispose() {
22663
23258
  var _this$horizonScrollTr, _this$horizonThumbRec3, _this$verticalScrollT, _this$verticalThumbRe3, _this$placeholderBarR, _this$_horizonPointer, _this$_horizonPointer2, _this$_verticalPointe, _this$_verticalPointe2;
22664
23259
  super.dispose();
23260
+ this._flushPendingBarScroll();
22665
23261
  (_this$horizonScrollTr = this.horizonScrollTrack) === null || _this$horizonScrollTr === void 0 || _this$horizonScrollTr.dispose();
22666
23262
  (_this$horizonThumbRec3 = this.horizonThumbRect) === null || _this$horizonThumbRec3 === void 0 || _this$horizonThumbRec3.dispose();
22667
23263
  (_this$verticalScrollT = this.verticalScrollTrack) === null || _this$verticalScrollT === void 0 || _this$verticalScrollT.dispose();
@@ -22680,6 +23276,47 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22680
23276
  this._mainScene = null;
22681
23277
  this._viewport.removeScrollBar();
22682
23278
  }
23279
+ _scheduleBarScrollDelta(delta) {
23280
+ var _delta$x, _delta$y;
23281
+ this._pendingBarDeltaX += (_delta$x = delta.x) !== null && _delta$x !== void 0 ? _delta$x : 0;
23282
+ this._pendingBarDeltaY += (_delta$y = delta.y) !== null && _delta$y !== void 0 ? _delta$y : 0;
23283
+ if (this._pendingBarScrollFrameId !== null || this._pendingBarScrollThrottleId !== null) return;
23284
+ this._requestPendingBarScrollFrame();
23285
+ }
23286
+ _requestPendingBarScrollFrame() {
23287
+ this._pendingBarScrollFrameId = requestAnimationFrame(() => {
23288
+ this._pendingBarScrollFrameId = null;
23289
+ this._applyPendingBarScroll({ isBarDragging: true });
23290
+ if (!this._isHorizonMove && !this._isVerticalMove) return;
23291
+ this._pendingBarScrollThrottleId = window.setTimeout(() => {
23292
+ this._pendingBarScrollThrottleId = null;
23293
+ if (this._pendingBarDeltaX !== 0 || this._pendingBarDeltaY !== 0) this._requestPendingBarScrollFrame();
23294
+ }, BAR_DRAG_SCROLL_THROTTLE_MS);
23295
+ });
23296
+ }
23297
+ _flushPendingBarScroll(isBarDragEnd = false) {
23298
+ if (this._pendingBarScrollFrameId !== null) {
23299
+ cancelAnimationFrame(this._pendingBarScrollFrameId);
23300
+ this._pendingBarScrollFrameId = null;
23301
+ }
23302
+ if (this._pendingBarScrollThrottleId !== null) {
23303
+ clearTimeout(this._pendingBarScrollThrottleId);
23304
+ this._pendingBarScrollThrottleId = null;
23305
+ }
23306
+ return this._applyPendingBarScroll({ isBarDragEnd });
23307
+ }
23308
+ _applyPendingBarScroll(options) {
23309
+ const x = this._pendingBarDeltaX;
23310
+ const y = this._pendingBarDeltaY;
23311
+ if (x === 0 && y === 0) return false;
23312
+ this._pendingBarDeltaX = 0;
23313
+ this._pendingBarDeltaY = 0;
23314
+ this._viewport.scrollByBarDeltaValue({
23315
+ ...x === 0 ? null : { x },
23316
+ ...y === 0 ? null : { y }
23317
+ }, true, options);
23318
+ return true;
23319
+ }
22683
23320
  render(ctx, left = 0, top = 0) {
22684
23321
  const { scrollX, scrollY } = this._viewport;
22685
23322
  ctx.save();
@@ -22884,12 +23521,14 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22884
23521
  var _mainScene$getEngine;
22885
23522
  const e = evt;
22886
23523
  if (!this._isVerticalMove) return;
22887
- this._viewport.scrollByBarDeltaValue({ y: e.offsetY - this._lastY });
23524
+ this._scheduleBarScrollDelta({ y: e.offsetY - this._lastY });
22888
23525
  this._lastY = e.offsetY;
22889
23526
  (_mainScene$getEngine = mainScene.getEngine()) === null || _mainScene$getEngine === void 0 || _mainScene$getEngine.setCapture();
22890
23527
  });
22891
23528
  this._verticalPointerUpSub = mainScene.onPointerUp$.subscribeEvent((_evt, _state) => {
23529
+ if (!this._isVerticalMove) return;
22892
23530
  const srcElement = this.verticalThumbRect;
23531
+ if (!this._flushPendingBarScroll(true)) this._viewport.scrollByBarDeltaValue({ y: 0 }, true, { isBarDragEnd: true });
22893
23532
  this._isVerticalMove = false;
22894
23533
  mainScene.releaseCapturedObject();
22895
23534
  mainScene.enableObjectsEvent();
@@ -22958,12 +23597,14 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22958
23597
  var _mainScene$getEngine2;
22959
23598
  const e = evt;
22960
23599
  if (!this._isHorizonMove) return;
22961
- this._viewport.scrollByBarDeltaValue({ x: e.offsetX - this._lastX });
23600
+ this._scheduleBarScrollDelta({ x: e.offsetX - this._lastX });
22962
23601
  this._lastX = e.offsetX;
22963
23602
  (_mainScene$getEngine2 = mainScene.getEngine()) === null || _mainScene$getEngine2 === void 0 || _mainScene$getEngine2.setCapture();
22964
23603
  });
22965
23604
  this._horizonPointerUpSub = mainScene.onPointerUp$.subscribeEvent((evt, state) => {
22966
23605
  var _this$horizonThumbRec11;
23606
+ if (!this._isHorizonMove) return;
23607
+ if (!this._flushPendingBarScroll(true)) this._viewport.scrollByBarDeltaValue({ x: 0 }, true, { isBarDragEnd: true });
22967
23608
  this._isHorizonMove = false;
22968
23609
  mainScene.releaseCapturedObject();
22969
23610
  mainScene.enableObjectsEvent();
@@ -23179,7 +23820,7 @@ var FontAndBaseLine = class extends docExtension {
23179
23820
  const { vertexAngle, centerAngle } = renderConfig !== null && renderConfig !== void 0 ? renderConfig : {};
23180
23821
  const VERTICAL_DEG = 90;
23181
23822
  const isVertical = vertexAngle === VERTICAL_DEG && centerAngle === VERTICAL_DEG;
23182
- if (isVertical && !hasCJK(content)) {
23823
+ if (isVertical && !cjk.hasCJK(content)) {
23183
23824
  ctx.save();
23184
23825
  ctx.translate(spanStartPoint.x + centerPoint.x, spanStartPoint.y + centerPoint.y);
23185
23826
  ctx.rotate(Math.PI / 2);
@@ -23701,7 +24342,7 @@ var Documents = class Documents extends DocComponent {
23701
24342
  ctx.restore();
23702
24343
  }
23703
24344
  _drawBorderBottom(ctx, page, line, left = 0, top = 0) {
23704
- var _line$borderBottom$pa, _line$borderBottom, _line$borderBottom$co, _line$borderBottom2;
24345
+ var _line$borderBottom$pa, _line$borderBottom, _border$width, _border$color$rgb;
23705
24346
  if (this._drawLiquid == null) return;
23706
24347
  let { x, y } = this._drawLiquid;
23707
24348
  const { pageWidth, marginLeft, marginRight, marginTop } = page;
@@ -23710,8 +24351,10 @@ var Documents = class Documents extends DocComponent {
23710
24351
  y -= line.paddingTop;
23711
24352
  y += marginTop + top + line.lineHeight + ((_line$borderBottom$pa = (_line$borderBottom = line.borderBottom) === null || _line$borderBottom === void 0 ? void 0 : _line$borderBottom.padding) !== null && _line$borderBottom$pa !== void 0 ? _line$borderBottom$pa : 0);
23712
24353
  ctx.save();
23713
- ctx.setLineWidthByPrecision(1);
23714
- ctx.strokeStyle = (_line$borderBottom$co = (_line$borderBottom2 = line.borderBottom) === null || _line$borderBottom2 === void 0 ? void 0 : _line$borderBottom2.color.rgb) !== null && _line$borderBottom$co !== void 0 ? _line$borderBottom$co : "#CDD0D8";
24354
+ const border = line.borderBottom;
24355
+ ctx.setLineWidthByPrecision(Math.max(0, (_border$width = border === null || border === void 0 ? void 0 : border.width) !== null && _border$width !== void 0 ? _border$width : 1));
24356
+ ctx.strokeStyle = (_border$color$rgb = border === null || border === void 0 ? void 0 : border.color.rgb) !== null && _border$color$rgb !== void 0 ? _border$color$rgb : "#CDD0D8";
24357
+ setDocsBorderDash(ctx, border === null || border === void 0 ? void 0 : border.dashStyle);
23715
24358
  drawLineByBorderType(ctx, "b", 0, {
23716
24359
  startX: x,
23717
24360
  startY: y,
@@ -23873,21 +24516,21 @@ var Documents = class Documents extends DocComponent {
23873
24516
  return DEFAULT_BORDER_COLOR;
23874
24517
  }
23875
24518
  _isDrawableTableCellBorder(border) {
23876
- var _border$width$v, _border$width, _border$color$rgb, _border$color;
24519
+ var _border$width$v, _border$width2, _border$color$rgb2, _border$color;
23877
24520
  if (!border) return false;
23878
- const lineWidth = (_border$width$v = (_border$width = border.width) === null || _border$width === void 0 ? void 0 : _border$width.v) !== null && _border$width$v !== void 0 ? _border$width$v : 1;
23879
- const color = (_border$color$rgb = (_border$color = border.color) === null || _border$color === void 0 ? void 0 : _border$color.rgb) !== null && _border$color$rgb !== void 0 ? _border$color$rgb : DEFAULT_BORDER_COLOR.color.rgb;
24521
+ const lineWidth = (_border$width$v = (_border$width2 = border.width) === null || _border$width2 === void 0 ? void 0 : _border$width2.v) !== null && _border$width$v !== void 0 ? _border$width$v : 1;
24522
+ const color = (_border$color$rgb2 = (_border$color = border.color) === null || _border$color === void 0 ? void 0 : _border$color.rgb) !== null && _border$color$rgb2 !== void 0 ? _border$color$rgb2 : DEFAULT_BORDER_COLOR.color.rgb;
23880
24523
  return lineWidth > 0 && color !== "transparent";
23881
24524
  }
23882
24525
  _drawTableCellBorder(ctx, border, type, position) {
23883
- var _border$width$v2, _border$width2, _border$color$rgb2, _border$color2;
24526
+ var _border$width$v2, _border$width3, _border$color$rgb3, _border$color2;
23884
24527
  if (!border) return;
23885
- const lineWidth = (_border$width$v2 = (_border$width2 = border.width) === null || _border$width2 === void 0 ? void 0 : _border$width2.v) !== null && _border$width$v2 !== void 0 ? _border$width$v2 : 1;
23886
- const color = (_border$color$rgb2 = (_border$color2 = border.color) === null || _border$color2 === void 0 ? void 0 : _border$color2.rgb) !== null && _border$color$rgb2 !== void 0 ? _border$color$rgb2 : DEFAULT_BORDER_COLOR.color.rgb;
24528
+ const lineWidth = (_border$width$v2 = (_border$width3 = border.width) === null || _border$width3 === void 0 ? void 0 : _border$width3.v) !== null && _border$width$v2 !== void 0 ? _border$width$v2 : 1;
24529
+ const color = (_border$color$rgb3 = (_border$color2 = border.color) === null || _border$color2 === void 0 ? void 0 : _border$color2.rgb) !== null && _border$color$rgb3 !== void 0 ? _border$color$rgb3 : DEFAULT_BORDER_COLOR.color.rgb;
23887
24530
  if (lineWidth <= 0 || color === "transparent") return;
23888
24531
  ctx.save();
23889
24532
  ctx.setLineWidthByPrecision(lineWidth);
23890
- setTableCellBorderDash(ctx, border.dashStyle);
24533
+ setDocsBorderDash(ctx, border.dashStyle);
23891
24534
  ctx.strokeStyle = color;
23892
24535
  drawLineByBorderType(ctx, type, 0, position);
23893
24536
  ctx.restore();
@@ -24017,7 +24660,7 @@ var Documents = class Documents extends DocComponent {
24017
24660
  });
24018
24661
  }
24019
24662
  };
24020
- function setTableCellBorderDash(ctx, dashStyle) {
24663
+ function setDocsBorderDash(ctx, dashStyle) {
24021
24664
  if (dashStyle === _univerjs_core.DashStyleType.DOT) {
24022
24665
  ctx.setLineDash([2]);
24023
24666
  return;
@@ -24063,6 +24706,85 @@ function rectByPrecisionBounds(ctx, x, y, width, height) {
24063
24706
  //#endregion
24064
24707
  //#region src/components/sheets/spreadsheet.ts
24065
24708
  const OBJECT_KEY = "__SHEET_EXTENSION_FONT_DOCUMENT_INSTANCE__";
24709
+ function pushSparseCellRange(ranges, row, col) {
24710
+ const last = ranges[ranges.length - 1];
24711
+ if (last && last.startRow === row && last.endRow === row && last.endColumn + 1 === col) {
24712
+ last.endColumn = col;
24713
+ return;
24714
+ }
24715
+ ranges.push({
24716
+ startRow: row,
24717
+ endRow: row,
24718
+ startColumn: col,
24719
+ endColumn: col
24720
+ });
24721
+ }
24722
+ function scanSparseExtensionFeatures(spreadsheetSkeleton, ranges) {
24723
+ const { worksheet } = spreadsheetSkeleton;
24724
+ if (!worksheet || !ranges.length || worksheet.getMergeData().length > 0) return null;
24725
+ const flags = {
24726
+ hasCustomRender: false,
24727
+ hasMarkers: false,
24728
+ hasSelectionProtection: false,
24729
+ customRenderRanges: [],
24730
+ markerRanges: [],
24731
+ selectionProtectionRanges: []
24732
+ };
24733
+ for (const range of ranges) for (let row = range.startRow; row <= range.endRow; row++) {
24734
+ if (!worksheet.getRowVisible(row)) continue;
24735
+ for (let col = range.startColumn; col <= range.endColumn; col++) {
24736
+ var _spreadsheetSkeleton$, _cell$customRender, _cell$selectionProtec;
24737
+ if (!worksheet.getColVisible(col)) continue;
24738
+ const cachedCell = (_spreadsheetSkeleton$ = spreadsheetSkeleton.stylesCache.fontMatrix.getValue(row, col)) === null || _spreadsheetSkeleton$ === void 0 ? void 0 : _spreadsheetSkeleton$.cellData;
24739
+ const cell = cachedCell !== null && cachedCell !== void 0 ? cachedCell : worksheet.getCell(row, col);
24740
+ if (!cell) continue;
24741
+ if ((_cell$customRender = cell.customRender) === null || _cell$customRender === void 0 ? void 0 : _cell$customRender.length) {
24742
+ flags.hasCustomRender = true;
24743
+ pushSparseCellRange(flags.customRenderRanges, row, col);
24744
+ }
24745
+ if (cell.markers) {
24746
+ flags.hasMarkers = true;
24747
+ pushSparseCellRange(flags.markerRanges, row, col);
24748
+ }
24749
+ if ((_cell$selectionProtec = cell.selectionProtection) === null || _cell$selectionProtec === void 0 ? void 0 : _cell$selectionProtec.length) {
24750
+ flags.hasSelectionProtection = true;
24751
+ pushSparseCellRange(flags.selectionProtectionRanges, row, col);
24752
+ }
24753
+ }
24754
+ }
24755
+ return flags;
24756
+ }
24757
+ function shouldSkipSparseExtension(uKey, flags) {
24758
+ if (!flags) return false;
24759
+ switch (uKey) {
24760
+ case "DefaultCustomExtension": return !flags.hasCustomRender;
24761
+ case "DefaultMarkerExtension": return !flags.hasMarkers;
24762
+ case "RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY":
24763
+ case "RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY": return !flags.hasSelectionProtection;
24764
+ default: return false;
24765
+ }
24766
+ }
24767
+ function hasSparseExtension(extensions) {
24768
+ return extensions.some((extension) => {
24769
+ switch (extension.uKey) {
24770
+ case "DefaultCustomExtension":
24771
+ case "DefaultMarkerExtension":
24772
+ case "RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY":
24773
+ case "RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY": return true;
24774
+ default: return false;
24775
+ }
24776
+ });
24777
+ }
24778
+ function getSparseExtensionDiffRanges(uKey, flags, diffRanges) {
24779
+ if (!flags) return diffRanges;
24780
+ switch (uKey) {
24781
+ case "DefaultCustomExtension": return flags.customRenderRanges;
24782
+ case "DefaultMarkerExtension": return flags.markerRanges;
24783
+ case "RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY":
24784
+ case "RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY": return flags.selectionProtectionRanges;
24785
+ default: return diffRanges;
24786
+ }
24787
+ }
24066
24788
  var Spreadsheet = class extends SheetComponent {
24067
24789
  constructor(oKey, spreadsheetSkeleton, _allowCache = true) {
24068
24790
  super(oKey, spreadsheetSkeleton);
@@ -24117,7 +24839,8 @@ var Spreadsheet = class extends SheetComponent {
24117
24839
  var _viewportInfo$diffBou;
24118
24840
  const spreadsheetSkeleton = this.getSkeleton();
24119
24841
  if (!spreadsheetSkeleton) return;
24120
- this._drawAuxiliary(ctx);
24842
+ const hasMergeData = spreadsheetSkeleton.worksheet.getMergeData().length > 0;
24843
+ this._drawAuxiliary(ctx, hasMergeData);
24121
24844
  const parentScale = this.getParentScale();
24122
24845
  const diffRanges = this._refreshIncrementalState && viewportInfo.diffBounds ? (_viewportInfo$diffBou = viewportInfo.diffBounds) === null || _viewportInfo$diffBou === void 0 ? void 0 : _viewportInfo$diffBou.map((bound) => spreadsheetSkeleton.getRangeByViewBound(bound)) : [];
24123
24846
  const cacheRange = spreadsheetSkeleton.getCacheRangeByViewport(viewportInfo, this.isPrinting);
@@ -24128,14 +24851,19 @@ var Spreadsheet = class extends SheetComponent {
24128
24851
  endColumn: cacheRange.endColumn
24129
24852
  })) : viewRanges;
24130
24853
  const extensions = this.getExtensionsByOrder();
24854
+ const sparseExtensionFeatures = !hasMergeData && hasSparseExtension(extensions) ? scanSparseExtensionFeatures(spreadsheetSkeleton, viewRanges) : null;
24131
24855
  const scene = this.getScene();
24132
24856
  for (const extension of extensions) {
24857
+ if (shouldSkipSparseExtension(extension.uKey, sparseExtensionFeatures)) continue;
24133
24858
  const extensionViewRanges = extension === this._fontExtension || extension === this._borderExtension ? overflowSafeViewRanges : viewRanges;
24859
+ const extensionDiffRanges = getSparseExtensionDiffRanges(extension.uKey, sparseExtensionFeatures, diffRanges);
24134
24860
  const timeKey = `${SHEET_EXTENSION_PREFIX}${extension.uKey}`;
24135
24861
  const st = _univerjs_core.Tools.now();
24136
- extension.draw(ctx, parentScale, spreadsheetSkeleton, diffRanges, {
24862
+ extension.draw(ctx, parentScale, spreadsheetSkeleton, extensionDiffRanges, {
24137
24863
  viewRanges: extensionViewRanges,
24138
24864
  checkOutOfViewBound: true,
24865
+ fontRenderRanges: extension === this._fontExtension ? spreadsheetSkeleton.incrementalFontRenderRanges : void 0,
24866
+ hasMergeData,
24139
24867
  viewportKey: viewportInfo.viewportKey,
24140
24868
  viewBound: viewportInfo.cacheBound,
24141
24869
  diffBounds: viewportInfo.diffBounds
@@ -24233,7 +24961,7 @@ var Spreadsheet = class extends SheetComponent {
24233
24961
  this._dirtyBounds = dirtyBounds;
24234
24962
  }
24235
24963
  renderByViewports(mainCtx, viewportInfo, spreadsheetSkeleton) {
24236
- const { diffBounds, diffX, diffY, viewPortPosition, cacheCanvas, leftOrigin, topOrigin, bufferEdgeX, bufferEdgeY, isDirty: isViewportDirty, isForceDirty: isViewportForceDirty } = viewportInfo;
24964
+ const { diffBounds, diffX, diffY, viewPortPosition, cacheCanvas, leftOrigin, topOrigin, bufferEdgeX, bufferEdgeY, isDirty: isViewportDirty, isForceDirty: isViewportForceDirty, shouldCacheUpdate } = viewportInfo;
24237
24965
  const { rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop } = spreadsheetSkeleton;
24238
24966
  const { a: scaleX = 1, d: scaleY = 1 } = mainCtx.getTransform();
24239
24967
  const bufferEdgeSizeX = bufferEdgeX * scaleX / window.devicePixelRatio;
@@ -24242,8 +24970,10 @@ var Spreadsheet = class extends SheetComponent {
24242
24970
  cacheCtx.save();
24243
24971
  const isForceDirty = isViewportForceDirty || this.isForceDirty();
24244
24972
  const isDirty = isViewportDirty || this.isDirty();
24245
- const isScrollJumpOutsideCache = Math.abs(diffX) * scaleX >= cacheCanvas.getWidth() || Math.abs(diffY) * scaleY >= cacheCanvas.getHeight();
24246
- const shouldRefreshCache = isDirty || isForceDirty || isScrollJumpOutsideCache;
24973
+ const cachePixelRatio = cacheCanvas.getPixelRatio();
24974
+ const isScrollJumpOutsideCache = Math.abs(diffX) * scaleX >= cacheCanvas.getWidth() * cachePixelRatio || Math.abs(diffY) * scaleY >= cacheCanvas.getHeight() * cachePixelRatio;
24975
+ const hasMergeData = spreadsheetSkeleton.worksheet.getMergeData().length > 0;
24976
+ const shouldRefreshCache = isDirty || isForceDirty || isScrollJumpOutsideCache || hasMergeData && (diffX !== 0 || diffY !== 0) || shouldCacheUpdate && diffX !== 0;
24247
24977
  if (diffBounds.length === 0 || diffX === 0 && diffY === 0 || shouldRefreshCache) {
24248
24978
  if (shouldRefreshCache) {
24249
24979
  this.addRenderTagToScene("scrolling", false);
@@ -24337,6 +25067,8 @@ var Spreadsheet = class extends SheetComponent {
24337
25067
  }
24338
25068
  const spreadsheetSkeleton = this.getSkeleton();
24339
25069
  if (!spreadsheetSkeleton) return;
25070
+ const { viewportKey } = viewportInfo;
25071
+ if (sheetHeaderViewportKeys.includes(viewportKey)) return this;
24340
25072
  spreadsheetSkeleton.setStylesCache(viewportInfo);
24341
25073
  const segment = spreadsheetSkeleton.rowColumnSegment;
24342
25074
  if (!segment) return;
@@ -24345,10 +25077,9 @@ var Spreadsheet = class extends SheetComponent {
24345
25077
  const { rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop } = spreadsheetSkeleton;
24346
25078
  mainCtx.translateWithPrecision(rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop);
24347
25079
  (_this$getScene = this.getScene()) === null || _this$getScene === void 0 || _this$getScene.updateTransformerZero(rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop);
24348
- const { viewportKey } = viewportInfo;
24349
25080
  if (sheetContentViewportKeys.includes(viewportKey)) if (viewportInfo && viewportInfo.cacheCanvas) this.renderByViewports(mainCtx, viewportInfo, spreadsheetSkeleton);
24350
25081
  else this._draw(mainCtx, viewportInfo);
24351
- else if (sheetHeaderViewportKeys.includes(viewportKey)) {} else if (viewportInfo && viewportInfo.cacheCanvas) this.renderByViewports(mainCtx, viewportInfo, spreadsheetSkeleton);
25082
+ else if (viewportInfo && viewportInfo.cacheCanvas) this.renderByViewports(mainCtx, viewportInfo, spreadsheetSkeleton);
24352
25083
  else this._draw(mainCtx, viewportInfo);
24353
25084
  mainCtx.restore();
24354
25085
  return this;
@@ -24416,7 +25147,7 @@ var Spreadsheet = class extends SheetComponent {
24416
25147
  * draw gridlines
24417
25148
  * @param ctx
24418
25149
  */
24419
- _drawAuxiliary(ctx) {
25150
+ _drawAuxiliary(ctx, hasMergeData = true) {
24420
25151
  var _ref;
24421
25152
  const spreadsheetSkeleton = this.getSkeleton();
24422
25153
  if (spreadsheetSkeleton == null) return;
@@ -24458,22 +25189,24 @@ var Spreadsheet = class extends SheetComponent {
24458
25189
  const mergeVisibleRanges = [];
24459
25190
  let mergeVisibleRangeStartRow = startRow;
24460
25191
  for (let r = rowStart; r <= rowEnd; r++) {
24461
- if (worksheet.getRowVisible(r) === false) {
24462
- if (mergeVisibleRangeStartRow < r) {
24463
- mergeVisibleRanges.push({
24464
- startRow: mergeVisibleRangeStartRow,
24465
- endRow: r - 1,
24466
- startColumn,
24467
- endColumn
24468
- });
24469
- mergeVisibleRangeStartRow = r + 1;
24470
- } else if (mergeVisibleRangeStartRow === r) mergeVisibleRangeStartRow = r + 1;
24471
- } else if (r === endRow && mergeVisibleRangeStartRow <= r) mergeVisibleRanges.push({
24472
- startRow: mergeVisibleRangeStartRow,
24473
- endRow: r,
24474
- startColumn,
24475
- endColumn
24476
- });
25192
+ if (hasMergeData) {
25193
+ if (worksheet.getRowVisible(r) === false) {
25194
+ if (mergeVisibleRangeStartRow < r) {
25195
+ mergeVisibleRanges.push({
25196
+ startRow: mergeVisibleRangeStartRow,
25197
+ endRow: r - 1,
25198
+ startColumn,
25199
+ endColumn
25200
+ });
25201
+ mergeVisibleRangeStartRow = r + 1;
25202
+ } else if (mergeVisibleRangeStartRow === r) mergeVisibleRangeStartRow = r + 1;
25203
+ } else if (r === endRow && mergeVisibleRangeStartRow <= r) mergeVisibleRanges.push({
25204
+ startRow: mergeVisibleRangeStartRow,
25205
+ endRow: r,
25206
+ startColumn,
25207
+ endColumn
25208
+ });
25209
+ }
24477
25210
  if (r < 0 || r > rowHeightAccumulationLength - 1) continue;
24478
25211
  const rowEndPosition = rowHeightAccumulation[r];
24479
25212
  ctx.beginPath();
@@ -24492,7 +25225,7 @@ var Spreadsheet = class extends SheetComponent {
24492
25225
  ctx.stroke();
24493
25226
  }
24494
25227
  const mergeCellRanges = [];
24495
- for (const mergeVisibleRange of mergeVisibleRanges) {
25228
+ if (hasMergeData) for (const mergeVisibleRange of mergeVisibleRanges) {
24496
25229
  const mergeRangeInVisible = spreadsheetSkeleton.getCurrentRowColumnSegmentMergeData(mergeVisibleRange);
24497
25230
  mergeCellRanges.push(...mergeRangeInVisible);
24498
25231
  }
@@ -25431,6 +26164,164 @@ var DocBackground = class DocBackground extends DocComponent {
25431
26164
  }
25432
26165
  };
25433
26166
 
26167
+ //#endregion
26168
+ //#region src/components/docs/layout/doc-no-wrap-measure.ts
26169
+ function splitDocumentNoWrapMeasureLines(text) {
26170
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
26171
+ }
26172
+ function isDocumentNoWrapMeasureTrailingWhitespace(char) {
26173
+ return char === " " || char === " " || char === "\xA0";
26174
+ }
26175
+ function getDocumentNoWrapMeasureTrailingWhitespaceStart(text) {
26176
+ let index = text.length;
26177
+ while (index > 0 && isDocumentNoWrapMeasureTrailingWhitespace(text[index - 1])) index--;
26178
+ return index;
26179
+ }
26180
+ function isDocumentNoWrapMeasureCJKText(char) {
26181
+ return /[\u2E80-\u9FFF\uF900-\uFAFF]/u.test(char);
26182
+ }
26183
+ function isDocumentNoWrapMeasureLatinText(char) {
26184
+ return /[a-z\d]/i.test(char);
26185
+ }
26186
+ function measureDocumentNoWrapTextByStyle(text, textStyle) {
26187
+ if (!text) return 0;
26188
+ return FontCache.getMeasureText(text, getFontStyleString(textStyle).fontCache).width;
26189
+ }
26190
+ function measureDocumentNoWrapCJKLatinSpacing(segment, textStyle, previous) {
26191
+ let spacing = 0;
26192
+ for (const char of Array.from(segment)) {
26193
+ const isCJK = isDocumentNoWrapMeasureCJKText(char);
26194
+ const cjkWidth = isCJK ? measureDocumentNoWrapTextByStyle(char, textStyle) : 0;
26195
+ if (isCJK && isDocumentNoWrapMeasureLatinText(previous.char)) spacing += cjkWidth / 4;
26196
+ if (isDocumentNoWrapMeasureLatinText(char) && isDocumentNoWrapMeasureCJKText(previous.char)) spacing += previous.cjkWidth / 4;
26197
+ previous.char = char;
26198
+ previous.cjkWidth = cjkWidth;
26199
+ }
26200
+ return spacing;
26201
+ }
26202
+ function measureDocumentNoWrapLineByStyle(text, textStyle) {
26203
+ const visibleText = text.slice(0, getDocumentNoWrapMeasureTrailingWhitespaceStart(text));
26204
+ return measureDocumentNoWrapTextByStyle(visibleText, textStyle) + measureDocumentNoWrapCJKLatinSpacing(visibleText, textStyle, {
26205
+ char: "",
26206
+ cjkWidth: 0
26207
+ });
26208
+ }
26209
+ function measureDocumentNoWrapRunsWidth(dataStream, textRuns, fallbackTextStyle) {
26210
+ let currentLineWidth = 0;
26211
+ let maxLineWidth = 0;
26212
+ let pendingTrailingWhitespaceWidth = 0;
26213
+ const previous = {
26214
+ char: "",
26215
+ cjkWidth: 0
26216
+ };
26217
+ const appendSegment = (segment, textStyle) => {
26218
+ if (!segment) return;
26219
+ const trailingStart = getDocumentNoWrapMeasureTrailingWhitespaceStart(segment);
26220
+ const visibleSegment = segment.slice(0, trailingStart);
26221
+ const trailingWhitespace = segment.slice(trailingStart);
26222
+ if (visibleSegment) {
26223
+ currentLineWidth += pendingTrailingWhitespaceWidth;
26224
+ pendingTrailingWhitespaceWidth = 0;
26225
+ currentLineWidth += measureDocumentNoWrapTextByStyle(visibleSegment, textStyle);
26226
+ currentLineWidth += measureDocumentNoWrapCJKLatinSpacing(visibleSegment, textStyle, previous);
26227
+ }
26228
+ if (trailingWhitespace) {
26229
+ pendingTrailingWhitespaceWidth += measureDocumentNoWrapTextByStyle(trailingWhitespace, textStyle);
26230
+ measureDocumentNoWrapCJKLatinSpacing(trailingWhitespace, textStyle, previous);
26231
+ }
26232
+ };
26233
+ const finishLine = () => {
26234
+ maxLineWidth = Math.max(maxLineWidth, currentLineWidth);
26235
+ currentLineWidth = 0;
26236
+ pendingTrailingWhitespaceWidth = 0;
26237
+ previous.char = "";
26238
+ previous.cjkWidth = 0;
26239
+ };
26240
+ const appendRange = (text, textStyle) => {
26241
+ splitDocumentNoWrapMeasureLines(text).forEach((segment, index) => {
26242
+ if (index > 0) finishLine();
26243
+ appendSegment(segment, textStyle);
26244
+ });
26245
+ };
26246
+ let cursor = 0;
26247
+ [...textRuns].sort((a, b) => a.st - b.st).forEach((run) => {
26248
+ const start = Math.max(0, run.st);
26249
+ const end = Math.max(start, run.ed);
26250
+ if (start > cursor) appendRange(dataStream.slice(cursor, start), fallbackTextStyle);
26251
+ const effectiveStart = Math.max(start, cursor);
26252
+ if (end > effectiveStart) appendRange(dataStream.slice(effectiveStart, end), run.ts);
26253
+ cursor = Math.max(cursor, end);
26254
+ });
26255
+ if (cursor < dataStream.length) appendRange(dataStream.slice(cursor), fallbackTextStyle);
26256
+ return Math.max(maxLineWidth, currentLineWidth);
26257
+ }
26258
+ function measureDocumentNoWrapTextRangeWidth(documentData, start, end) {
26259
+ var _body$dataStream, _body$textRuns, _documentData$documen2;
26260
+ const body = documentData.body;
26261
+ const dataStream = (_body$dataStream = body === null || body === void 0 ? void 0 : body.dataStream) !== null && _body$dataStream !== void 0 ? _body$dataStream : "";
26262
+ const rangeStart = Math.max(0, Math.min(dataStream.length, start));
26263
+ const rangeEnd = Math.max(rangeStart, Math.min(dataStream.length, end));
26264
+ const rangeText = dataStream.slice(rangeStart, rangeEnd);
26265
+ const textRuns = ((_body$textRuns = body === null || body === void 0 ? void 0 : body.textRuns) !== null && _body$textRuns !== void 0 ? _body$textRuns : []).map((run) => {
26266
+ const runStart = Math.max(rangeStart, run.st);
26267
+ const runEnd = Math.min(rangeEnd, run.ed);
26268
+ if (runEnd <= runStart) return null;
26269
+ return {
26270
+ ...run,
26271
+ st: runStart - rangeStart,
26272
+ ed: runEnd - rangeStart
26273
+ };
26274
+ }).filter((run) => run !== null);
26275
+ if (textRuns.length) {
26276
+ var _documentData$documen;
26277
+ return measureDocumentNoWrapRunsWidth(rangeText, textRuns, (_documentData$documen = documentData.documentStyle) === null || _documentData$documen === void 0 ? void 0 : _documentData$documen.textStyle);
26278
+ }
26279
+ return measureDocumentNoWrapLineByStyle(rangeText, (_documentData$documen2 = documentData.documentStyle) === null || _documentData$documen2 === void 0 ? void 0 : _documentData$documen2.textStyle);
26280
+ }
26281
+ /**
26282
+ * Measures the widest no-wrap line using the same text-width policy that docs
26283
+ * layout relies on for lightweight shape/text-box autofit flows.
26284
+ *
26285
+ * This is intentionally not a full document layout replacement: callers that
26286
+ * need line breaking, pagination, floating objects, or final line metrics should
26287
+ * use `DocumentSkeleton`. This helper exists for consumers that must size a
26288
+ * no-wrap host before committing a full layout pass. Keep docs-specific glyph
26289
+ * width adjustments here so feature packages do not duplicate paragraph shaping
26290
+ * details such as CJK-Latin spacing.
26291
+ */
26292
+ function measureDocumentNoWrapTextWidth(documentData) {
26293
+ var _body$dataStream2, _documentData$documen4;
26294
+ const body = documentData === null || documentData === void 0 ? void 0 : documentData.body;
26295
+ const dataStream = (_body$dataStream2 = body === null || body === void 0 ? void 0 : body.dataStream) !== null && _body$dataStream2 !== void 0 ? _body$dataStream2 : "";
26296
+ const textRuns = body === null || body === void 0 ? void 0 : body.textRuns;
26297
+ if (textRuns === null || textRuns === void 0 ? void 0 : textRuns.length) {
26298
+ var _documentData$documen3;
26299
+ return measureDocumentNoWrapRunsWidth(dataStream, textRuns, documentData === null || documentData === void 0 || (_documentData$documen3 = documentData.documentStyle) === null || _documentData$documen3 === void 0 ? void 0 : _documentData$documen3.textStyle);
26300
+ }
26301
+ const fallbackTextStyle = documentData === null || documentData === void 0 || (_documentData$documen4 = documentData.documentStyle) === null || _documentData$documen4 === void 0 ? void 0 : _documentData$documen4.textStyle;
26302
+ return Math.max(0, ...splitDocumentNoWrapMeasureLines(dataStream).map((line) => measureDocumentNoWrapLineByStyle(line, fallbackTextStyle)));
26303
+ }
26304
+ /**
26305
+ * Measures the widest segment that docs line breaking keeps together. This is
26306
+ * useful when a host may wrap normally but still needs enough width to avoid
26307
+ * clipping an individual word, CJK glyph, or punctuation segment.
26308
+ */
26309
+ function measureDocumentUnbreakableTextWidth(documentData) {
26310
+ var _documentData$body$da, _documentData$body;
26311
+ const dataStream = (_documentData$body$da = documentData === null || documentData === void 0 || (_documentData$body = documentData.body) === null || _documentData$body === void 0 ? void 0 : _documentData$body.dataStream) !== null && _documentData$body$da !== void 0 ? _documentData$body$da : "";
26312
+ if (!documentData || !dataStream) return 0;
26313
+ const breaker = new LineBreaker(dataStream);
26314
+ let start = 0;
26315
+ let maxWidth = 0;
26316
+ let breakPoint = breaker.nextBreakPoint();
26317
+ while (breakPoint) {
26318
+ maxWidth = Math.max(maxWidth, measureDocumentNoWrapTextRangeWidth(documentData, start, breakPoint.position));
26319
+ start = breakPoint.position;
26320
+ breakPoint = breaker.nextBreakPoint();
26321
+ }
26322
+ return maxWidth;
26323
+ }
26324
+
25434
26325
  //#endregion
25435
26326
  //#region src/custom/custom-object.ts
25436
26327
  var CustomObject = class extends BaseObject {
@@ -26625,7 +27516,7 @@ Engine = __decorate([__decorateParam(2, ICanvasColorService)], Engine);
26625
27516
  //#endregion
26626
27517
  //#region package.json
26627
27518
  var name = "@univerjs/engine-render";
26628
- var version = "1.0.0-alpha.2";
27519
+ var version = "1.0.0-alpha.3";
26629
27520
 
26630
27521
  //#endregion
26631
27522
  //#region src/config/config.ts
@@ -27978,11 +28869,13 @@ var Transformer = class extends _univerjs_core.Disposable {
27978
28869
  });
27979
28870
  }
27980
28871
  _getOutlinePosition(width, height, borderSpacing, borderStrokeWidth) {
28872
+ const offset = borderSpacing + borderStrokeWidth;
28873
+ const strokeOffset = borderStrokeWidth / 2;
27981
28874
  return {
27982
- left: borderSpacing - borderStrokeWidth,
27983
- top: -borderSpacing - this.borderStrokeWidth,
27984
- width: width + borderSpacing * 2,
27985
- height: height + borderSpacing * 2
28875
+ left: -offset - strokeOffset,
28876
+ top: -offset - strokeOffset,
28877
+ width: width + offset * 2,
28878
+ height: height + offset * 2
27986
28879
  };
27987
28880
  }
27988
28881
  _getRotateAnchorCursor(type) {
@@ -28056,7 +28949,7 @@ var Transformer = class extends _univerjs_core.Disposable {
28056
28949
  top += -borderSpacing - borderStrokeWidth;
28057
28950
  break;
28058
28951
  case "__SpreadsheetTransformerResizeLM__":
28059
- left += borderSpacing - borderStrokeWidth;
28952
+ left += -borderSpacing - borderStrokeWidth;
28060
28953
  top += height / 2 - longEdge / 2;
28061
28954
  break;
28062
28955
  case "__SpreadsheetTransformerResizeRM__":
@@ -28064,7 +28957,7 @@ var Transformer = class extends _univerjs_core.Disposable {
28064
28957
  top += height / 2 - longEdge / 2;
28065
28958
  break;
28066
28959
  case "__SpreadsheetTransformerResizeLB__":
28067
- left += -this.borderSpacing - borderStrokeWidth;
28960
+ left += -borderSpacing - borderStrokeWidth;
28068
28961
  top += height + borderSpacing - borderStrokeWidth - longEdge;
28069
28962
  break;
28070
28963
  case "__SpreadsheetTransformerResizeCB__":
@@ -28104,28 +28997,28 @@ var Transformer = class extends _univerjs_core.Disposable {
28104
28997
  top += -borderSpacing - borderStrokeWidth;
28105
28998
  break;
28106
28999
  case "__SpreadsheetTransformerResizeRT__":
28107
- left += width + borderSpacing - borderStrokeWidth;
29000
+ left += width + borderSpacing + borderStrokeWidth;
28108
29001
  top += -borderSpacing - borderStrokeWidth;
28109
29002
  break;
28110
29003
  case "__SpreadsheetTransformerResizeLM__":
28111
- left += borderSpacing - borderStrokeWidth;
29004
+ left += -borderSpacing - borderStrokeWidth;
28112
29005
  top += height / 2;
28113
29006
  break;
28114
29007
  case "__SpreadsheetTransformerResizeRM__":
28115
- left += width + borderSpacing - borderStrokeWidth;
29008
+ left += width + borderSpacing + borderStrokeWidth;
28116
29009
  top += height / 2;
28117
29010
  break;
28118
29011
  case "__SpreadsheetTransformerResizeLB__":
28119
- left += -this.borderSpacing - borderStrokeWidth;
28120
- top += height + borderSpacing - borderStrokeWidth;
29012
+ left += -borderSpacing - borderStrokeWidth;
29013
+ top += height + borderSpacing + borderStrokeWidth;
28121
29014
  break;
28122
29015
  case "__SpreadsheetTransformerResizeCB__":
28123
29016
  left += width / 2;
28124
- top += height + borderSpacing - borderStrokeWidth;
29017
+ top += height + borderSpacing + borderStrokeWidth;
28125
29018
  break;
28126
29019
  case "__SpreadsheetTransformerResizeRB__":
28127
- left += width + borderSpacing - borderStrokeWidth;
28128
- top += height + borderSpacing - borderStrokeWidth;
29020
+ left += width + borderSpacing + borderStrokeWidth;
29021
+ top += height + borderSpacing + borderStrokeWidth;
28129
29022
  break;
28130
29023
  }
28131
29024
  return {
@@ -28164,8 +29057,8 @@ var Transformer = class extends _univerjs_core.Disposable {
28164
29057
  width: anchorProps.width,
28165
29058
  height: anchorProps.height,
28166
29059
  radius: anchorProps.radius,
28167
- left: left + (anchorSize - anchorProps.width) / 2,
28168
- top: top + (anchorSize - anchorProps.height) / 2,
29060
+ left: left + (anchorSize - anchorProps.width) / 2 - anchorStrokeWidth / 2,
29061
+ top: top + (anchorSize - anchorProps.height) / 2 - anchorStrokeWidth / 2,
28169
29062
  shadowColor: anchorShadowColor,
28170
29063
  shadowBlur: anchorShadowBlur,
28171
29064
  shadowOffsetX: anchorShadowOffsetX,
@@ -29479,14 +30372,17 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29479
30372
  return this._renderContext.components;
29480
30373
  }
29481
30374
  constructor(init, parentInjector) {
29482
- var _init$createUnitOptio;
30375
+ var _init$createUnitOptio, _init$createUnitOptio2, _init$createUnitOptio3;
29483
30376
  super();
29484
30377
  _defineProperty(this, "isRenderUnit", true);
29485
30378
  _defineProperty(this, "_activated$", new rxjs.BehaviorSubject(true));
29486
30379
  _defineProperty(this, "activated$", this._activated$.pipe((0, rxjs.distinctUntilChanged)()));
29487
30380
  _defineProperty(this, "_injector", void 0);
29488
30381
  _defineProperty(this, "_renderContext", void 0);
29489
- this._injector = parentInjector.createChild();
30382
+ _defineProperty(this, "_dependencyService", void 0);
30383
+ const renderParentInjector = (_init$createUnitOptio = (_init$createUnitOptio2 = init.createUnitOptions) === null || _init$createUnitOptio2 === void 0 ? void 0 : _init$createUnitOptio2.renderParentInjector) !== null && _init$createUnitOptio !== void 0 ? _init$createUnitOptio : parentInjector;
30384
+ this._injector = renderParentInjector.createChild();
30385
+ this._dependencyService = new RenderUnitDependencyService(this._injector, () => this._renderContext);
29490
30386
  this._renderContext = {
29491
30387
  unit: init.unit,
29492
30388
  unitId: init.unit.getUnitId(),
@@ -29500,13 +30396,14 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29500
30396
  activate: () => this._activated$.next(true),
29501
30397
  deactivate: () => this._activated$.next(false)
29502
30398
  };
29503
- if (((_init$createUnitOptio = init.createUnitOptions) === null || _init$createUnitOptio === void 0 ? void 0 : _init$createUnitOptio.makeCurrent) === false) this.deactivate();
30399
+ if (((_init$createUnitOptio3 = init.createUnitOptions) === null || _init$createUnitOptio3 === void 0 ? void 0 : _init$createUnitOptio3.makeCurrent) === false) this.deactivate();
29504
30400
  }
29505
30401
  dispose() {
29506
- this._injector.dispose();
29507
- super.dispose();
30402
+ if (this._disposed) return;
29508
30403
  this._activated$.next(false);
29509
30404
  this._activated$.complete();
30405
+ super.dispose();
30406
+ this._injector.dispose();
29510
30407
  this._renderContext.unit = null;
29511
30408
  this._renderContext.components.clear();
29512
30409
  }
@@ -29517,7 +30414,10 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29517
30414
  * Get a dependency from the RenderUnit's injector.
29518
30415
  */
29519
30416
  with(dependency) {
29520
- return this._injector.get(dependency);
30417
+ return this._dependencyService.resolve(dependency);
30418
+ }
30419
+ getInjector() {
30420
+ return this._injector;
29521
30421
  }
29522
30422
  /**
29523
30423
  * Add render dependencies to the RenderUnit's injector. Note that the dependencies would be initialized immediately
@@ -29527,16 +30427,8 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29527
30427
  this._initDependencies(dependencies);
29528
30428
  }
29529
30429
  _initDependencies(dependencies) {
29530
- const j = this._injector;
29531
- dependencies.forEach((dep) => {
29532
- const [identifier, implOrNull] = Array.isArray(dep) ? dep : [dep, null];
29533
- if (!implOrNull) j.add([identifier, { useFactory: () => j.createInstance(identifier, this._renderContext) }]);
29534
- else if ((0, _univerjs_core.isClassDependencyItem)(implOrNull)) j.add([identifier, { useFactory: () => j.createInstance(implOrNull.useClass, this._renderContext) }]);
29535
- else throw new Error("[RenderUnit]: render dependency could only be an class!");
29536
- });
29537
- dependencies.forEach((dep) => {
29538
- const [identifier] = Array.isArray(dep) ? dep : [dep, null];
29539
- j.get(identifier);
30430
+ this._dependencyService.register(dependencies).forEach((record) => {
30431
+ this._dependencyService.resolveRecord(record);
29540
30432
  });
29541
30433
  }
29542
30434
  getRenderContext() {
@@ -29550,6 +30442,86 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29550
30442
  }
29551
30443
  };
29552
30444
  RenderUnit = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector))], RenderUnit);
30445
+ var RenderUnitDependencyService = class {
30446
+ constructor(_injector, _getRenderContext) {
30447
+ this._injector = _injector;
30448
+ this._getRenderContext = _getRenderContext;
30449
+ _defineProperty(this, "_records", /* @__PURE__ */ new Map());
30450
+ _defineProperty(this, "_resolved", /* @__PURE__ */ new Map());
30451
+ _defineProperty(this, "_resolving", /* @__PURE__ */ new Set());
30452
+ }
30453
+ register(dependencies) {
30454
+ const records = [];
30455
+ const seen = /* @__PURE__ */ new Set();
30456
+ dependencies.forEach((dependency) => {
30457
+ const parsed = this._parseDependency(dependency);
30458
+ const key = getRenderDependencyIdentifierKey$1(parsed.identifier);
30459
+ const existing = this._records.get(key);
30460
+ const record = existing !== null && existing !== void 0 ? existing : this._addRecord(key, parsed.identifier, parsed.create);
30461
+ if (seen.has(record.key)) return;
30462
+ seen.add(record.key);
30463
+ records.push(record);
30464
+ });
30465
+ return records;
30466
+ }
30467
+ resolve(dependency) {
30468
+ const key = getRenderDependencyIdentifierKey$1(dependency);
30469
+ if (this._resolved.has(key)) return this._resolved.get(key);
30470
+ if (this._resolving.has(key)) return;
30471
+ const record = this._records.get(key);
30472
+ if (record) return this.resolveRecord(record);
30473
+ return this._injector.get(dependency, _univerjs_core.LookUp.SELF);
30474
+ }
30475
+ resolveRecord(record) {
30476
+ if (this._resolved.has(record.key)) return this._resolved.get(record.key);
30477
+ if (this._resolving.has(record.key)) return;
30478
+ this._resolving.add(record.key);
30479
+ try {
30480
+ return this._injector.get(record.identifier, _univerjs_core.LookUp.SELF);
30481
+ } finally {
30482
+ this._resolving.delete(record.key);
30483
+ }
30484
+ }
30485
+ _addRecord(key, identifier, create) {
30486
+ const record = {
30487
+ key,
30488
+ identifier,
30489
+ create
30490
+ };
30491
+ this._records.set(key, record);
30492
+ this._injector.add([identifier, { useFactory: () => this._create(record) }]);
30493
+ return record;
30494
+ }
30495
+ _create(record) {
30496
+ if (this._resolved.has(record.key)) return this._resolved.get(record.key);
30497
+ const alreadyResolving = this._resolving.has(record.key);
30498
+ if (!alreadyResolving) this._resolving.add(record.key);
30499
+ try {
30500
+ const instance = record.create();
30501
+ this._resolved.set(record.key, instance);
30502
+ return instance;
30503
+ } finally {
30504
+ if (!alreadyResolving) this._resolving.delete(record.key);
30505
+ }
30506
+ }
30507
+ _parseDependency(dependency) {
30508
+ const [identifier, implOrNull] = Array.isArray(dependency) ? dependency : [dependency, null];
30509
+ if (!implOrNull) return {
30510
+ identifier,
30511
+ create: () => this._injector.createInstance(identifier, this._getRenderContext())
30512
+ };
30513
+ if ((0, _univerjs_core.isClassDependencyItem)(implOrNull)) return {
30514
+ identifier,
30515
+ create: () => this._injector.createInstance(implOrNull.useClass, this._getRenderContext())
30516
+ };
30517
+ throw new Error("[RenderUnit]: render dependency could only be an class!");
30518
+ }
30519
+ };
30520
+ function getRenderDependencyIdentifierKey$1(identifier) {
30521
+ const decoratorName = identifier === null || identifier === void 0 ? void 0 : identifier.decoratorName;
30522
+ if (typeof decoratorName === "string" && decoratorName) return `identifier:${decoratorName}`;
30523
+ return identifier;
30524
+ }
29553
30525
 
29554
30526
  //#endregion
29555
30527
  //#region src/render-manager/render-manager.service.ts
@@ -29590,10 +30562,11 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29590
30562
  registerRenderModules(type, deps) {
29591
30563
  if (!this._renderDependencies.has(type)) this._renderDependencies.set(type, []);
29592
30564
  const dependencies = this._renderDependencies.get(type);
29593
- dependencies.push(...deps);
29594
- for (const [_, render] of this._renderMap) if (render.type === type) this._tryAddRenderDependencies(render, deps);
30565
+ const registeredDeps = deps.filter((dep) => !hasRenderDependency(dependencies, dep));
30566
+ dependencies.push(...registeredDeps);
30567
+ for (const [_, render] of this._renderMap) if (render.type === type) this._tryAddRenderDependencies(render, registeredDeps);
29595
30568
  return (0, _univerjs_core.toDisposable)(() => {
29596
- deps.forEach((dep) => (0, _univerjs_core.remove)(dependencies, dep));
30569
+ registeredDeps.forEach((dep) => (0, _univerjs_core.remove)(dependencies, dep));
29597
30570
  });
29598
30571
  }
29599
30572
  /**
@@ -29604,6 +30577,7 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29604
30577
  registerRenderModule(type, depCtor) {
29605
30578
  if (!this._renderDependencies.has(type)) this._renderDependencies.set(type, []);
29606
30579
  const dependencies = this._renderDependencies.get(type);
30580
+ if (hasRenderDependency(dependencies, depCtor)) return (0, _univerjs_core.toDisposable)(() => {});
29607
30581
  dependencies.push(depCtor);
29608
30582
  for (const [_, render] of this._renderMap) if (render.type === type) this._tryAddRenderDependencies(render, [depCtor]);
29609
30583
  return (0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(dependencies, depCtor));
@@ -29636,7 +30610,9 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29636
30610
  * @returns renderUnit:IRender
29637
30611
  */
29638
30612
  createRender(unitId, createUnitOptions) {
29639
- const renderer = this._createRender(unitId, this._injector.createInstance(Engine, unitId, void 0), true, createUnitOptions);
30613
+ var _createUnitOptions$re;
30614
+ const parentInjector = (_createUnitOptions$re = createUnitOptions === null || createUnitOptions === void 0 ? void 0 : createUnitOptions.renderParentInjector) !== null && _createUnitOptions$re !== void 0 ? _createUnitOptions$re : this._injector;
30615
+ const renderer = this._createRender(unitId, parentInjector.createInstance(Engine, unitId, void 0), (createUnitOptions === null || createUnitOptions === void 0 ? void 0 : createUnitOptions.embeddedRender) !== true, createUnitOptions, parentInjector);
29640
30616
  this._renderCreated$.next(renderer);
29641
30617
  return renderer;
29642
30618
  }
@@ -29660,7 +30636,7 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29660
30636
  * @param isMainScene
29661
30637
  * @returns renderUnit:IRender
29662
30638
  */
29663
- _createRender(unitId, engine, isMainScene = true, createUnitOptions) {
30639
+ _createRender(unitId, engine, isMainScene = true, createUnitOptions, parentInjector = this._injector) {
29664
30640
  const existItem = this.getRenderById(unitId);
29665
30641
  let shouldDestroyEngine = true;
29666
30642
  if (existItem != null) {
@@ -29677,7 +30653,7 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29677
30653
  if (unit) {
29678
30654
  const type = this._univerInstanceService.getUnitType(unitId);
29679
30655
  const ctorOfDeps = this._getRenderDepsByType(type);
29680
- renderUnit = this._injector.createInstance(RenderUnit, {
30656
+ renderUnit = parentInjector.createInstance(RenderUnit, {
29681
30657
  unit,
29682
30658
  engine,
29683
30659
  scene,
@@ -29685,7 +30661,16 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29685
30661
  createUnitOptions
29686
30662
  });
29687
30663
  this._addRenderUnit(unitId, renderUnit);
29688
- this._tryAddRenderDependencies(renderUnit, ctorOfDeps);
30664
+ try {
30665
+ this._tryAddRenderDependencies(renderUnit, ctorOfDeps);
30666
+ } catch (error) {
30667
+ try {
30668
+ this._disposeItem(renderUnit);
30669
+ } finally {
30670
+ this._renderMap.delete(unitId);
30671
+ }
30672
+ throw error;
30673
+ }
29689
30674
  } else {
29690
30675
  renderUnit = {
29691
30676
  isThumbNail: true,
@@ -29748,6 +30733,18 @@ RenderManagerService = __decorate([
29748
30733
  __decorateParam(1, _univerjs_core.IUniverInstanceService),
29749
30734
  __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService))
29750
30735
  ], RenderManagerService);
30736
+ function hasRenderDependency(dependencies, dep) {
30737
+ const key = getRenderDependencyIdentifierKey(getRenderDependencyIdentifier(dep));
30738
+ return dependencies.some((registered) => getRenderDependencyIdentifierKey(getRenderDependencyIdentifier(registered)) === key);
30739
+ }
30740
+ function getRenderDependencyIdentifier(dep) {
30741
+ return Array.isArray(dep) ? dep[0] : dep;
30742
+ }
30743
+ function getRenderDependencyIdentifierKey(identifier) {
30744
+ const decoratorName = identifier.decoratorName;
30745
+ if (typeof decoratorName === "string" && decoratorName) return `identifier:${decoratorName}`;
30746
+ return identifier;
30747
+ }
29751
30748
  const IRenderManagerService = (0, _univerjs_core.createIdentifier)("engine-render.render-manager.service");
29752
30749
  function isDisposable(thing) {
29753
30750
  return !!thing && typeof thing.dispose === "function";
@@ -30176,13 +31173,13 @@ var Viewport = class {
30176
31173
  * @param delta
30177
31174
  * @returns isLimited
30178
31175
  */
30179
- scrollByBarDeltaValue(delta, isTrigger = true) {
31176
+ scrollByBarDeltaValue(delta, isTrigger = true, options) {
30180
31177
  const x = this.scrollX + (delta.x || 0);
30181
31178
  const y = this.scrollY + (delta.y || 0);
30182
31179
  return this._scrollToBarPosCore({
30183
31180
  x,
30184
31181
  y
30185
- }, isTrigger);
31182
+ }, isTrigger, options);
30186
31183
  }
30187
31184
  /**
30188
31185
  * Viewport scroll to certain position.
@@ -30720,7 +31717,7 @@ var Viewport = class {
30720
31717
  * @param rawScrollXY Partial<IViewportScrollPosition>
30721
31718
  * @param isTrigger
30722
31719
  */
30723
- _scrollToBarPosCore(rawScrollXY, isTrigger = true) {
31720
+ _scrollToBarPosCore(rawScrollXY, isTrigger = true, options) {
30724
31721
  var _this$_scrollBar6, _this$_scrollBar7, _this$_scrollBar8, _this$_scrollBar9, _this$_scrollBar10;
30725
31722
  if (this._scrollBar == null) return;
30726
31723
  let scrollX = rawScrollXY.x;
@@ -30741,7 +31738,9 @@ var Viewport = class {
30741
31738
  rawScrollY: rawScrollXY.y,
30742
31739
  limitX: (_this$_scrollBar6 = this._scrollBar) === null || _this$_scrollBar6 === void 0 ? void 0 : _this$_scrollBar6.limitX,
30743
31740
  limitY: (_this$_scrollBar7 = this._scrollBar) === null || _this$_scrollBar7 === void 0 ? void 0 : _this$_scrollBar7.limitY,
30744
- isTrigger
31741
+ isTrigger,
31742
+ isBarDragging: options === null || options === void 0 ? void 0 : options.isBarDragging,
31743
+ isBarDragEnd: options === null || options === void 0 ? void 0 : options.isBarDragEnd
30745
31744
  };
30746
31745
  (_this$_scrollBar8 = this._scrollBar) === null || _this$_scrollBar8 === void 0 || _this$_scrollBar8.makeDirty(true);
30747
31746
  this.onScrollAfter$.emitEvent(scrollSubParam);
@@ -30754,7 +31753,9 @@ var Viewport = class {
30754
31753
  viewportScrollY: this.viewportScrollY,
30755
31754
  limitX: (_this$_scrollBar9 = this._scrollBar) === null || _this$_scrollBar9 === void 0 ? void 0 : _this$_scrollBar9.limitX,
30756
31755
  limitY: (_this$_scrollBar10 = this._scrollBar) === null || _this$_scrollBar10 === void 0 ? void 0 : _this$_scrollBar10.limitY,
30757
- isTrigger
31756
+ isTrigger,
31757
+ isBarDragging: options === null || options === void 0 ? void 0 : options.isBarDragging,
31758
+ isBarDragEnd: options === null || options === void 0 ? void 0 : options.isBarDragEnd
30758
31759
  });
30759
31760
  return afterLimit;
30760
31761
  }
@@ -30870,13 +31871,11 @@ var Viewport = class {
30870
31871
  left: Math.max(prevBound.left, currBound.left),
30871
31872
  right: Math.min(prevBound.right, currBound.right)
30872
31873
  });
30873
- const expandX = this.bufferEdgeX;
30874
- const expandY = this.bufferEdgeY;
30875
31874
  for (const bound of additionalAreas) {
30876
- bound.left = bound.left - expandX;
30877
- bound.right = bound.right + expandX;
30878
- bound.top = bound.top - expandY;
30879
- bound.bottom = bound.bottom + expandY;
31875
+ bound.left = bound.left - this.bufferEdgeX;
31876
+ bound.right = bound.right + this.bufferEdgeX;
31877
+ bound.top = bound.top - this.bufferEdgeY;
31878
+ bound.bottom = bound.bottom + this.bufferEdgeY;
30880
31879
  }
30881
31880
  return additionalAreas;
30882
31881
  }
@@ -31079,6 +32078,7 @@ exports.WatermarkLayer = WatermarkLayer;
31079
32078
  exports.calculateRectRotate = calculateRectRotate;
31080
32079
  exports.cancelRequestFrame = cancelRequestFrame;
31081
32080
  exports.checkStyle = checkStyle;
32081
+ exports.cjk = cjk;
31082
32082
  exports.clampRange = clampRange;
31083
32083
  exports.clearLineByBorderType = clearLineByBorderType;
31084
32084
  exports.compareDocumentSkeletonNestedPagePathOrder = compareDocumentSkeletonNestedPagePathOrder;
@@ -31103,6 +32103,7 @@ exports.getCurrentScrollXY = getCurrentScrollXY;
31103
32103
  exports.getCurrentTypeOfRenderer = getCurrentTypeOfRenderer;
31104
32104
  exports.getDPI = getDPI;
31105
32105
  exports.getDevicePixelRatio = getDevicePixelRatio;
32106
+ exports.getDocsCustomBlockRenderViewport = getDocsCustomBlockRenderViewport;
31106
32107
  exports.getDocsSkeletonPageSize = getDocsSkeletonPageSize;
31107
32108
  exports.getDocsTableRenderViewport = getDocsTableRenderViewport;
31108
32109
  exports.getDocumentSkeletonColumnPagePathInfo = getDocumentSkeletonColumnPagePathInfo;
@@ -31136,9 +32137,6 @@ exports.glyphIterator = glyphIterator;
31136
32137
  exports.hasAllLatin = hasAllLatin;
31137
32138
  exports.hasArabic = hasArabic;
31138
32139
  exports.hasBasicLatin = hasBasicLatin;
31139
- exports.hasCJK = hasCJK;
31140
- exports.hasCJKPunctuation = hasCJKPunctuation;
31141
- exports.hasCJKText = hasCJKText;
31142
32140
  exports.hasLatinExtendedA = hasLatinExtendedA;
31143
32141
  exports.hasLatinExtendedB = hasLatinExtendedB;
31144
32142
  exports.hasLatinOneSupplement = hasLatinOneSupplement;
@@ -31167,6 +32165,9 @@ exports.isRegExp = isRegExp;
31167
32165
  exports.isSameLine = isSameLine;
31168
32166
  exports.isString = isString;
31169
32167
  exports.lineIterator = lineIterator;
32168
+ exports.measureDocumentNoWrapTextRangeWidth = measureDocumentNoWrapTextRangeWidth;
32169
+ exports.measureDocumentNoWrapTextWidth = measureDocumentNoWrapTextWidth;
32170
+ exports.measureDocumentUnbreakableTextWidth = measureDocumentUnbreakableTextWidth;
31170
32171
  exports.mergeInfoOffset = mergeInfoOffset;
31171
32172
  exports.parseDataStreamToTree = parseDataStreamToTree;
31172
32173
  exports.pixelToPt = pixelToPt;
@@ -31183,6 +32184,7 @@ exports.renderTextWatermark = renderTextWatermark;
31183
32184
  exports.renderUserInfoWatermark = renderUserInfoWatermark;
31184
32185
  exports.renderWatermark = renderWatermark;
31185
32186
  exports.requestNewFrame = requestNewFrame;
32187
+ exports.setDocsCustomBlockRenderViewportProvider = setDocsCustomBlockRenderViewportProvider;
31186
32188
  exports.setDocsTableRenderViewportProvider = setDocsTableRenderViewportProvider;
31187
32189
  exports.setLineType = setLineType;
31188
32190
  exports.sheetContentViewportKeys = sheetContentViewportKeys;