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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/lib/cjs/index.js +1446 -355
  2. package/lib/es/index.js +1440 -330
  3. package/lib/types/basics/cjk-regexp.d.ts +61 -0
  4. package/lib/types/basics/draw.d.ts +4 -4
  5. package/lib/types/basics/i-document-skeleton-cached.d.ts +10 -0
  6. package/lib/types/basics/index.d.ts +2 -0
  7. package/lib/types/basics/interfaces.d.ts +3 -1
  8. package/lib/types/basics/tools.d.ts +0 -3
  9. package/lib/types/components/docs/custom-block-render-viewport.d.ts +37 -0
  10. package/lib/types/components/docs/doc-component.d.ts +3 -0
  11. package/lib/types/components/docs/extensions/font-and-base-line.d.ts +1 -0
  12. package/lib/types/components/docs/layout/block/paragraph/layout-ruler.d.ts +3 -1
  13. package/lib/types/components/docs/layout/doc-no-wrap-measure.d.ts +35 -0
  14. package/lib/types/components/docs/layout/tools.d.ts +1 -0
  15. package/lib/types/components/extension.d.ts +2 -0
  16. package/lib/types/components/sheets/extensions/background.d.ts +2 -1
  17. package/lib/types/components/sheets/extensions/font.d.ts +2 -1
  18. package/lib/types/components/sheets/extensions/sheet-extension.d.ts +5 -0
  19. package/lib/types/components/sheets/interfaces.d.ts +4 -0
  20. package/lib/types/components/sheets/sheet.render-skeleton.d.ts +19 -11
  21. package/lib/types/drawing-group.d.ts +8 -0
  22. package/lib/types/index.d.ts +4 -0
  23. package/lib/types/render-manager/render-manager.service.d.ts +1 -1
  24. package/lib/types/render-manager/render-unit.d.ts +3 -0
  25. package/lib/types/shape/scroll-bar.d.ts +8 -0
  26. package/lib/types/shape/text.d.ts +4 -0
  27. package/lib/types/viewport.d.ts +7 -1
  28. package/lib/umd/index.js +5 -2
  29. package/package.json +4 -5
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,59 @@ const DEFAULT_PADDING_DATA = {
18791
19192
  r: 2
18792
19193
  };
18793
19194
  const RENDER_RAW_FORMULA_KEY = "RENDER_RAW_FORMULA";
19195
+ function getShrinkToFitScale(contentWidth, availableWidth, fontSize) {
19196
+ if (contentWidth <= availableWidth || contentWidth <= 0 || availableWidth <= 0 || fontSize <= 0) return 1;
19197
+ return Math.max(1 / fontSize, availableWidth / contentWidth);
19198
+ }
19199
+ function scaleDocumentDataForShrinkToFit(documentData, scale, fallbackFontSize) {
19200
+ var _scaled$documentStyle, _defaultTextStyle$fs, _scaled$body;
19201
+ const scaled = _univerjs_core.Tools.deepClone(documentData);
19202
+ const defaultTextStyle = (_scaled$documentStyle = scaled.documentStyle.textStyle) !== null && _scaled$documentStyle !== void 0 ? _scaled$documentStyle : {};
19203
+ const defaultFontSize = (_defaultTextStyle$fs = defaultTextStyle.fs) !== null && _defaultTextStyle$fs !== void 0 ? _defaultTextStyle$fs : fallbackFontSize;
19204
+ scaled.documentStyle.textStyle = {
19205
+ ...defaultTextStyle,
19206
+ fs: defaultFontSize * scale
19207
+ };
19208
+ (_scaled$body = scaled.body) === null || _scaled$body === void 0 || (_scaled$body = _scaled$body.textRuns) === null || _scaled$body === void 0 || _scaled$body.forEach((textRun) => {
19209
+ var _textRun$ts, _textStyle$fs;
19210
+ const textStyle = (_textRun$ts = textRun.ts) !== null && _textRun$ts !== void 0 ? _textRun$ts : {};
19211
+ textRun.ts = {
19212
+ ...textStyle,
19213
+ fs: ((_textStyle$fs = textStyle.fs) !== null && _textStyle$fs !== void 0 ? _textStyle$fs : defaultFontSize) * scale
19214
+ };
19215
+ });
19216
+ return scaled;
19217
+ }
19218
+ function getResolvedRenderHorizontalAlign$1(horizontalAlign, cellData) {
19219
+ if (horizontalAlign !== _univerjs_core.HorizontalAlign.UNSPECIFIED) return horizontalAlign;
19220
+ 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;
19221
+ if ((cellData === null || cellData === void 0 ? void 0 : cellData.t) === _univerjs_core.CellValueType.BOOLEAN) return _univerjs_core.HorizontalAlign.CENTER;
19222
+ return horizontalAlign;
19223
+ }
19224
+ function setRenderTextCache(cacheItem, cellData) {
19225
+ var _cacheItem$horizontal;
19226
+ if (cacheItem.documentSkeleton) {
19227
+ cacheItem.displayText = void 0;
19228
+ cacheItem.resolvedHorizontalAlign = void 0;
19229
+ return;
19230
+ }
19231
+ cacheItem.displayText = (0, _univerjs_core.getDisplayValueFromCell)(cellData);
19232
+ cacheItem.resolvedHorizontalAlign = getResolvedRenderHorizontalAlign$1((_cacheItem$horizontal = cacheItem.horizontalAlign) !== null && _cacheItem$horizontal !== void 0 ? _cacheItem$horizontal : _univerjs_core.HorizontalAlign.UNSPECIFIED, cellData);
19233
+ }
19234
+ function pushRowRange(ranges, row, startColumn, endColumn) {
19235
+ if (endColumn < startColumn) return;
19236
+ const last = ranges[ranges.length - 1];
19237
+ if (last && last.startRow === row && last.endRow === row && last.endColumn + 1 === startColumn) {
19238
+ last.endColumn = endColumn;
19239
+ return;
19240
+ }
19241
+ ranges.push({
19242
+ startRow: row,
19243
+ endRow: row,
19244
+ startColumn,
19245
+ endColumn
19246
+ });
19247
+ }
18794
19248
  const CACHE_COUNT = 100;
18795
19249
  let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.SheetSkeleton {
18796
19250
  constructor(worksheet, _styles, _localeService, _contextService, _configService, _injector) {
@@ -18804,6 +19258,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18804
19258
  _defineProperty(this, "_cacheRangeMap", /* @__PURE__ */ new Map());
18805
19259
  _defineProperty(this, "_visibleRangeMap", /* @__PURE__ */ new Map());
18806
19260
  _defineProperty(this, "_overflowCache", new _univerjs_core.ObjectMatrix());
19261
+ _defineProperty(this, "_incrementalFontRenderRanges", []);
18807
19262
  _defineProperty(this, "_stylesCache", {
18808
19263
  background: {},
18809
19264
  backgroundPositions: new _univerjs_core.ObjectMatrix(),
@@ -18861,6 +19316,9 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18861
19316
  get overflowCache() {
18862
19317
  return this._overflowCache;
18863
19318
  }
19319
+ get incrementalFontRenderRanges() {
19320
+ return this._incrementalFontRenderRanges;
19321
+ }
18864
19322
  get showGridlines() {
18865
19323
  return this._showGridlines;
18866
19324
  }
@@ -18946,7 +19404,31 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18946
19404
  this.updateVisibleRange(vpInfo);
18947
19405
  const rowColumnSegment = this._drawingRange;
18948
19406
  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];
19407
+ 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);
19408
+ const hasMergeData = this.worksheet.getMergeData().length > 0;
19409
+ const isScrolling = !!vpInfo && (!!vpInfo.diffX || !!vpInfo.diffY);
19410
+ const shouldRefreshCacheForScroll = isIncrementalScroll && (hasMergeData && isScrolling || !!vpInfo.shouldCacheUpdate && !!vpInfo.diffX);
19411
+ const shouldUseIncrementalStyleRange = isIncrementalScroll && !shouldRefreshCacheForScroll;
19412
+ 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];
19413
+ const visibleCellOptions = hasMergeData ? null : {
19414
+ cacheItem: {
19415
+ bg: true,
19416
+ border: true
19417
+ },
19418
+ reuseExisting: shouldUseIncrementalStyleRange,
19419
+ hasMergeData,
19420
+ rowVisible: true
19421
+ };
19422
+ const overflowCellOptions = hasMergeData ? null : {
19423
+ cacheItem: {
19424
+ bg: false,
19425
+ border: false
19426
+ },
19427
+ reuseExisting: shouldUseIncrementalStyleRange,
19428
+ hasMergeData,
19429
+ rowVisible: true
19430
+ };
19431
+ this._incrementalFontRenderRanges = [];
18950
19432
  for (const styleRange of styleRanges) {
18951
19433
  const { startRow: visibleStartRow, endRow: visibleEndRow, startColumn: visibleStartColumn, endColumn: visibleEndColumn } = styleRange;
18952
19434
  if (visibleEndColumn === -1 || visibleEndRow === -1) continue;
@@ -18971,26 +19453,57 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
18971
19453
  startColumn: visibleStartColumn,
18972
19454
  endColumn: visibleEndColumn
18973
19455
  });
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
- } });
19456
+ for (let c = visibleStartColumn; c <= visibleEndColumn; c++) this._setStylesCacheForOneCell(r, c, visibleCellOptions !== null && visibleCellOptions !== void 0 ? visibleCellOptions : {
19457
+ cacheItem: {
19458
+ bg: true,
19459
+ border: true
19460
+ },
19461
+ reuseExisting: shouldUseIncrementalStyleRange,
19462
+ hasMergeData,
19463
+ rowVisible: true
19464
+ });
19465
+ if (shouldUseIncrementalStyleRange) pushRowRange(this._incrementalFontRenderRanges, r, visibleStartColumn, visibleEndColumn);
19466
+ for (let c = visibleStartColumn - 1; c >= expandStartCol; c--) {
19467
+ this._setStylesCacheForOneCell(r, c, overflowCellOptions !== null && overflowCellOptions !== void 0 ? overflowCellOptions : {
19468
+ cacheItem: {
19469
+ bg: false,
19470
+ border: false
19471
+ },
19472
+ reuseExisting: shouldUseIncrementalStyleRange,
19473
+ hasMergeData,
19474
+ rowVisible: true
19475
+ });
19476
+ if (shouldUseIncrementalStyleRange) pushRowRange(this._incrementalFontRenderRanges, r, c, c);
19477
+ if (!(0, _univerjs_core.isCellCoverable)(this.worksheet.getCell(r, c)) || hasMergeData && this.intersectMergeRange(r, c)) break;
19478
+ }
18982
19479
  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
- } });
19480
+ for (let c = visibleEndColumn + 1; c <= expandEndCol; c++) {
19481
+ this._setStylesCacheForOneCell(r, c, overflowCellOptions !== null && overflowCellOptions !== void 0 ? overflowCellOptions : {
19482
+ cacheItem: {
19483
+ bg: false,
19484
+ border: false
19485
+ },
19486
+ reuseExisting: shouldUseIncrementalStyleRange,
19487
+ hasMergeData,
19488
+ rowVisible: true
19489
+ });
19490
+ if (shouldUseIncrementalStyleRange) pushRowRange(this._incrementalFontRenderRanges, r, c, c);
19491
+ if (!(0, _univerjs_core.isCellCoverable)(this.worksheet.getCell(r, c)) || hasMergeData && this.intersectMergeRange(r, c)) break;
19492
+ }
18987
19493
  }
18988
19494
  const mergeRanges = [];
18989
19495
  for (const mergeVisibleRange of mergeVisibleRanges) {
18990
19496
  const mergeRangeInVisible = this.getCurrentRowColumnSegmentMergeData(mergeVisibleRange);
18991
19497
  mergeRanges.push(...mergeRangeInVisible);
18992
19498
  }
18993
- for (const mergeRange of mergeRanges) this._setStylesCacheForOneCell(mergeRange.startRow, mergeRange.startColumn, { mergeRange });
19499
+ for (const mergeRange of mergeRanges) {
19500
+ this._setStylesCacheForOneCell(mergeRange.startRow, mergeRange.startColumn, {
19501
+ mergeRange,
19502
+ reuseExisting: shouldUseIncrementalStyleRange,
19503
+ hasMergeData
19504
+ });
19505
+ if (shouldUseIncrementalStyleRange) pushRowRange(this._incrementalFontRenderRanges, mergeRange.startRow, mergeRange.startColumn, mergeRange.startColumn);
19506
+ }
18994
19507
  }
18995
19508
  return this;
18996
19509
  }
@@ -19275,6 +19788,22 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19275
19788
  endColumn
19276
19789
  };
19277
19790
  }
19791
+ _isOverflowBlockedByAdjacentCell(row, column, horizontalAlign, hasMergeData = true) {
19792
+ const leftBlocked = () => this._isOverflowSideBlocked(row, column, -1, hasMergeData);
19793
+ const rightBlocked = () => this._isOverflowSideBlocked(row, column, 1, hasMergeData);
19794
+ if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER) return leftBlocked() && rightBlocked();
19795
+ if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT) return leftBlocked();
19796
+ return rightBlocked();
19797
+ }
19798
+ _isOverflowSideBlocked(row, column, direction, hasMergeData = true) {
19799
+ var _this$_stylesCache$fo;
19800
+ const adjacentColumn = column + direction;
19801
+ if (adjacentColumn < 0 || adjacentColumn >= this.getColumnCount()) return true;
19802
+ const rawAdjacentCell = this._cellData.getValue(row, adjacentColumn);
19803
+ if (rawAdjacentCell && !(0, _univerjs_core.isCellCoverable)(rawAdjacentCell)) return true;
19804
+ const cachedAdjacentCell = (_this$_stylesCache$fo = this._stylesCache.fontMatrix.getValue(row, adjacentColumn)) === null || _this$_stylesCache$fo === void 0 ? void 0 : _this$_stylesCache$fo.cellData;
19805
+ return !(0, _univerjs_core.isCellCoverable)(cachedAdjacentCell !== null && cachedAdjacentCell !== void 0 ? cachedAdjacentCell : this.worksheet.getCell(row, adjacentColumn)) || hasMergeData && this.intersectMergeRange(row, adjacentColumn);
19806
+ }
19278
19807
  /**
19279
19808
  * Get cell by pos(offsetX, offsetY).
19280
19809
  * @deprecated Please use `getCellWithCoordByOffset` instead.
@@ -19444,7 +19973,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19444
19973
  * the text content of this cell can be drawn to both sides, not limited by the cell's width.
19445
19974
  * Overflow on the left or right is aligned according to the text's horizontal alignment.
19446
19975
  */
19447
- _calculateOverflowCell(row, column, docsConfig) {
19976
+ _calculateOverflowCell(row, column, docsConfig, hasMergeData = true) {
19448
19977
  const { documentSkeleton, vertexAngle = 0, centerAngle = 0, horizontalAlign, wrapStrategy } = docsConfig;
19449
19978
  const { t: cellValueType = _univerjs_core.CellValueType.STRING } = this._cellData.getValue(row, column) || {};
19450
19979
  let horizontalAlignPos = horizontalAlign;
@@ -19460,7 +19989,13 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19460
19989
  * Numerical and Boolean values are not displayed with overflow.
19461
19990
  */
19462
19991
  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;
19992
+ var _docsConfig$cellData$, _docsConfig$cellData, _docsConfig$cellData2;
19993
+ docsConfig.textFitsCurrentCell = false;
19994
+ if (hasMergeData && this.intersectMergeRange(row, column)) return true;
19995
+ const columnStart = this.columnWidthAccumulation[column - 1] || 0;
19996
+ const currentColumnWidth = (this.columnWidthAccumulation[column] || columnStart) - columnStart;
19997
+ 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;
19998
+ if ((Boolean(documentSkeleton) || `${rawText !== null && rawText !== void 0 ? rawText : ""}`.length * 4 > currentColumnWidth) && this._isOverflowBlockedByAdjacentCell(row, column, horizontalAlignPos, hasMergeData)) return true;
19464
19999
  let contentSize;
19465
20000
  if (documentSkeleton) contentSize = getDocsSkeletonPageSize(documentSkeleton, vertexAngle);
19466
20001
  else {
@@ -19480,11 +20015,15 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19480
20015
  height: cellHeight
19481
20016
  };
19482
20017
  }
20018
+ if (contentSize.width < currentColumnWidth) {
20019
+ docsConfig.textFitsCurrentCell = true;
20020
+ return true;
20021
+ }
19483
20022
  const { startColumn, endColumn } = this.getOverflowPosition(contentSize, horizontalAlignPos, row, column, this.getColumnCount());
19484
20023
  if (startColumn === endColumn) return true;
19485
20024
  this.appendToOverflowCache(row, column, startColumn, endColumn);
19486
20025
  } else if (wrapStrategy === _univerjs_core.WrapStrategy.WRAP && vertexAngle !== 0) {
19487
- if (this.intersectMergeRange(row, column)) return true;
20026
+ if (hasMergeData && this.intersectMergeRange(row, column)) return true;
19488
20027
  const { startY, endY } = this.getCellWithCoordByIndex(row, column);
19489
20028
  const cellHeight = endY - startY;
19490
20029
  documentSkeleton.getViewModel().getDataModel().updateDocumentDataPageSize(cellHeight);
@@ -19516,16 +20055,18 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19516
20055
  const startRow = (0, _univerjs_core.searchArray)(rowHeightAccumulation, Math.round(viewBound.top) - this.columnHeaderHeightAndMarginTop);
19517
20056
  const endY = Math.round(viewBound.bottom) - this.columnHeaderHeightAndMarginTop;
19518
20057
  let endRow = (0, _univerjs_core.searchArray)(rowHeightAccumulation, endY);
19519
- if (endRow < lenOfRowData && rowHeightAccumulation[endRow - 1] === endY) endRow -= 1;
20058
+ const isEndYOnBoundary = endRow < lenOfRowData && rowHeightAccumulation[endRow - 1] === endY;
20059
+ if (isEndYOnBoundary) endRow -= 1;
19520
20060
  const startColumn = (0, _univerjs_core.searchArray)(columnWidthAccumulation, Math.round(viewBound.left) - this.rowHeaderWidthAndMarginLeft);
19521
20061
  const endX = Math.round(viewBound.right) - this.rowHeaderWidthAndMarginLeft;
19522
20062
  let endColumn = (0, _univerjs_core.searchArray)(columnWidthAccumulation, endX);
19523
- if (endColumn < lenOfColData && columnWidthAccumulation[endColumn - 1] === endX) endColumn -= 1;
20063
+ const isEndXOnBoundary = endColumn < lenOfColData && columnWidthAccumulation[endColumn - 1] === endX;
20064
+ if (isEndXOnBoundary) endColumn -= 1;
19524
20065
  if (isPrinting) return {
19525
20066
  startRow,
19526
- endRow: endRow === lenOfRowData - 1 ? endRow : endRow - 1,
20067
+ endRow: endRow === lenOfRowData - 1 || isEndYOnBoundary ? endRow : endRow - 1,
19527
20068
  startColumn,
19528
- endColumn: endColumn === lenOfColData - 1 ? endColumn : endColumn - 1
20069
+ endColumn: endColumn === lenOfColData - 1 || isEndXOnBoundary ? endColumn : endColumn - 1
19529
20070
  };
19530
20071
  return {
19531
20072
  startRow,
@@ -19576,7 +20117,15 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19576
20117
  for (let i = 0; i < ranges.length; i++) {
19577
20118
  const range = ranges[i];
19578
20119
  _univerjs_core.Range.foreach(range, (row, col) => {
20120
+ var _this$_stylesCache$bo, _this$_stylesCache$ba, _this$_stylesCache$ba2;
19579
20121
  this._stylesCache.fontMatrix.realDeleteValue(row, col);
20122
+ (_this$_stylesCache$bo = this._stylesCache.border) === null || _this$_stylesCache$bo === void 0 || _this$_stylesCache$bo.realDeleteValue(row, col);
20123
+ (_this$_stylesCache$ba = this._stylesCache.backgroundPositions) === null || _this$_stylesCache$ba === void 0 || _this$_stylesCache$ba.realDeleteValue(row, col);
20124
+ this._handleBgMatrix.realDeleteValue(row, col);
20125
+ this._handleBorderMatrix.realDeleteValue(row, col);
20126
+ Object.values((_this$_stylesCache$ba2 = this._stylesCache.background) !== null && _this$_stylesCache$ba2 !== void 0 ? _this$_stylesCache$ba2 : {}).forEach((backgroundMatrix) => {
20127
+ backgroundMatrix.realDeleteValue(row, col);
20128
+ });
19580
20129
  });
19581
20130
  }
19582
20131
  this.makeDirty(true);
@@ -19617,15 +20166,38 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19617
20166
  }).bg) return;
19618
20167
  this._handleBgMatrix.setValue(row, col, true);
19619
20168
  if (style && style.bg && style.bg.rgb) {
19620
- var _this$_stylesCache$ba;
20169
+ var _this$_stylesCache$ba3;
19621
20170
  const rgb = style.bg.rgb;
19622
20171
  if (!this._stylesCache.background[rgb]) this._stylesCache.background[rgb] = new _univerjs_core.ObjectMatrix();
19623
20172
  this._stylesCache.background[rgb].setValue(row, col, rgb);
19624
20173
  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);
19626
- }
20174
+ (_this$_stylesCache$ba3 = this._stylesCache.backgroundPositions) === null || _this$_stylesCache$ba3 === void 0 || _this$_stylesCache$ba3.setValue(row, col, cellInfo);
20175
+ }
20176
+ }
20177
+ _applyShrinkToFit(row, col, fontCache, style) {
20178
+ var _style$pd5, _fontCache$cellData, _padding$l, _padding$r, _extension$leftOffset, _extension$rightOffse, _style$fs, _getDocsSkeletonPageS3, _fontCache$displayTex;
20179
+ if (style.stf !== _univerjs_core.BooleanNumber.TRUE) return;
20180
+ const cellInfo = this.getCellWithCoordByIndex(row, col, false);
20181
+ const startX = cellInfo.isMergedMainCell ? cellInfo.mergeInfo.startX : cellInfo.startX;
20182
+ const endX = cellInfo.isMergedMainCell ? cellInfo.mergeInfo.endX : cellInfo.endX;
20183
+ const padding = (_style$pd5 = style.pd) !== null && _style$pd5 !== void 0 ? _style$pd5 : DEFAULT_PADDING_DATA;
20184
+ const extension = (_fontCache$cellData = fontCache.cellData) === null || _fontCache$cellData === void 0 ? void 0 : _fontCache$cellData.fontRenderExtension;
20185
+ const availableWidth = endX - startX - ((_padding$l = padding.l) !== null && _padding$l !== void 0 ? _padding$l : DEFAULT_PADDING_DATA.l) - ((_padding$r = padding.r) !== null && _padding$r !== void 0 ? _padding$r : DEFAULT_PADDING_DATA.r) - ((_extension$leftOffset = extension === null || extension === void 0 ? void 0 : extension.leftOffset) !== null && _extension$leftOffset !== void 0 ? _extension$leftOffset : 0) - ((_extension$rightOffse = extension === null || extension === void 0 ? void 0 : extension.rightOffset) !== null && _extension$rightOffse !== void 0 ? _extension$rightOffse : 0);
20186
+ const fallbackFontSize = (_style$fs = style.fs) !== null && _style$fs !== void 0 ? _style$fs : _univerjs_core.DEFAULT_STYLES.fs;
20187
+ const scale = getShrinkToFitScale(fontCache.documentSkeleton ? ((_getDocsSkeletonPageS3 = getDocsSkeletonPageSize(fontCache.documentSkeleton, fontCache.vertexAngle)) !== null && _getDocsSkeletonPageS3 !== void 0 ? _getDocsSkeletonPageS3 : { width: 0 }).width : FontCache.getMeasureText((_fontCache$displayTex = fontCache.displayText) !== null && _fontCache$displayTex !== void 0 ? _fontCache$displayTex : (0, _univerjs_core.getDisplayValueFromCell)(fontCache.cellData), fontCache.fontString).width, availableWidth, fallbackFontSize);
20188
+ if (scale >= 1) return;
20189
+ fontCache.shrinkScale = scale;
20190
+ if (fontCache.documentSkeleton) {
20191
+ const documentModel = new _univerjs_core.DocumentDataModel(scaleDocumentDataForShrinkToFit(fontCache.documentSkeleton.getViewModel().getDataModel().getSnapshot(), scale, fallbackFontSize));
20192
+ const documentSkeleton = DocumentSkeleton.create(new DocumentViewModel(documentModel), this._localeService);
20193
+ documentSkeleton.calculate();
20194
+ fontCache.documentSkeleton = documentSkeleton;
20195
+ } else fontCache.fontString = getFontStyleString({
20196
+ ...style,
20197
+ fs: fallbackFontSize * scale
20198
+ }).fontCache;
19627
20199
  }
19628
- _setFontStylesCache(row, col, cellData, style) {
20200
+ _setFontStylesCache(row, col, cellData, style, hasMergeData = true) {
19629
20201
  var _style$tr2;
19630
20202
  if ((0, _univerjs_core.isNullCell)(cellData)) return;
19631
20203
  let config = {
@@ -19637,6 +20209,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19637
20209
  else {
19638
20210
  const cacheItem = cacheValue;
19639
20211
  cacheItem.cellData = cellData;
20212
+ setRenderTextCache(cacheItem, cellData);
19640
20213
  this._stylesCache.fontMatrix.setValue(row, col, cacheValue);
19641
20214
  return;
19642
20215
  }
@@ -19680,8 +20253,11 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19680
20253
  style
19681
20254
  };
19682
20255
  }
19683
- this._calculateOverflowCell(row, col, config);
19684
- this._stylesCache.fontMatrix.setValue(row, col, config);
20256
+ const fontCacheItem = config;
20257
+ setRenderTextCache(fontCacheItem, cellData);
20258
+ this._applyShrinkToFit(row, col, fontCacheItem, style);
20259
+ this._calculateOverflowCell(row, col, fontCacheItem, hasMergeData);
20260
+ this._stylesCache.fontMatrix.setValue(row, col, fontCacheItem);
19685
20261
  }
19686
20262
  /**
19687
20263
  * Set border background and font to this._stylesCache cell by cell.
@@ -19690,19 +20266,37 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19690
20266
  * @param options {{ mergeRange: IRange; cacheItem: ICacheItem } | undefined}
19691
20267
  */
19692
20268
  _setStylesCacheForOneCell(row, col, options) {
20269
+ var _options$hasMergeData, _options$rowVisible, _options$hasMergeData2;
19693
20270
  if (row === -1 || col === -1) return;
19694
20271
  if (!options) options = { cacheItem: {
19695
20272
  bg: true,
19696
20273
  border: true
19697
20274
  } };
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) {
20275
+ const cacheItem = options.cacheItem;
20276
+ if (options.reuseExisting && cacheItem && !options.mergeRange) {
20277
+ const bgHandled = !cacheItem.bg || _univerjs_core.Tools.isDefine(this._handleBgMatrix.getValue(row, col));
20278
+ const borderHandled = !cacheItem.border || _univerjs_core.Tools.isDefine(this._handleBorderMatrix.getValue(row, col));
20279
+ if (bgHandled && borderHandled && this._stylesCache.fontMatrix.getValue(row, col)) return;
20280
+ }
20281
+ const hasMergeData = (_options$hasMergeData = options.hasMergeData) !== null && _options$hasMergeData !== void 0 ? _options$hasMergeData : true;
20282
+ let isMerged = false;
20283
+ let isMergedMainCell = false;
20284
+ if (hasMergeData) {
20285
+ const mergeInfo = this.worksheet.getCellInfoInMergeData(row, col);
20286
+ isMerged = mergeInfo.isMerged;
20287
+ isMergedMainCell = mergeInfo.isMergedMainCell;
20288
+ if (isMerged) {
20289
+ const { startRow, startColumn, endRow, endColumn } = mergeInfo;
20290
+ options.mergeRange = {
20291
+ startRow,
20292
+ startColumn,
20293
+ endRow,
20294
+ endColumn
20295
+ };
20296
+ }
20297
+ }
20298
+ const rowVisible = (_options$rowVisible = options.rowVisible) !== null && _options$rowVisible !== void 0 ? _options$rowVisible : this.worksheet.getRowVisible(row);
20299
+ if (this.worksheet.getColVisible(col) === false || rowVisible === false) {
19706
20300
  if (isMerged && !isMergedMainCell) return;
19707
20301
  else if (!isMergedMainCell) return;
19708
20302
  }
@@ -19714,7 +20308,7 @@ let SpreadsheetSkeleton = class SpreadsheetSkeleton extends _univerjs_core.Sheet
19714
20308
  this._setFontStylesCache(row, col, {
19715
20309
  ...cell,
19716
20310
  s: style
19717
- }, style);
20311
+ }, style, (_options$hasMergeData2 = options.hasMergeData) !== null && _options$hasMergeData2 !== void 0 ? _options$hasMergeData2 : true);
19718
20312
  }
19719
20313
  /**
19720
20314
  * pro/issues/344
@@ -19927,6 +20521,19 @@ function rotatedBoundingBox(width, height, angleDegrees) {
19927
20521
  rotatedHeight: Math.abs(width * Math.sin(angle)) + Math.abs(height * Math.cos(angle))
19928
20522
  };
19929
20523
  }
20524
+ function getResolvedRenderHorizontalAlign(fontCache, cellData) {
20525
+ if (fontCache.resolvedHorizontalAlign !== void 0) return fontCache.resolvedHorizontalAlign;
20526
+ const { horizontalAlign } = fontCache;
20527
+ if (horizontalAlign !== _univerjs_core.HorizontalAlign.UNSPECIFIED) return horizontalAlign;
20528
+ if (cellData.t === _univerjs_core.CellValueType.NUMBER || !_univerjs_core.Tools.isDefine(cellData.t) && typeof cellData.v === "number") return _univerjs_core.HorizontalAlign.RIGHT;
20529
+ if (cellData.t === _univerjs_core.CellValueType.BOOLEAN) return _univerjs_core.HorizontalAlign.CENTER;
20530
+ return horizontalAlign;
20531
+ }
20532
+ function needsFontRenderExtensionBounds(fontCache) {
20533
+ var _fontCache$cellData;
20534
+ const extension = (_fontCache$cellData = fontCache.cellData) === null || _fontCache$cellData === void 0 ? void 0 : _fontCache$cellData.fontRenderExtension;
20535
+ 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));
20536
+ }
19930
20537
  var Font = class extends SheetExtension {
19931
20538
  constructor() {
19932
20539
  super();
@@ -19957,7 +20564,7 @@ var Font = class extends SheetExtension {
19957
20564
  const { rowHeightAccumulation, columnTotalWidth, columnWidthAccumulation, rowTotalHeight } = spreadsheetSkeleton;
19958
20565
  if (!rowHeightAccumulation || !columnWidthAccumulation || columnTotalWidth === void 0 || rowTotalHeight === void 0 || !worksheet) return;
19959
20566
  const scale = this._getScale(parentScale);
19960
- const { viewRanges = [], checkOutOfViewBound } = moreBoundsInfo;
20567
+ const { fontRenderRanges, viewRanges = [], checkOutOfViewBound } = moreBoundsInfo;
19961
20568
  const lastRowIndex = spreadsheetSkeleton.getRowCount() - 1;
19962
20569
  const lastColIndex = spreadsheetSkeleton.getColumnCount() - 1;
19963
20570
  const expandedViewRanges = viewRanges.map((range) => clampRange({
@@ -19965,43 +20572,51 @@ var Font = class extends SheetExtension {
19965
20572
  startColumn: range.startColumn - 20,
19966
20573
  endColumn: range.endColumn + 20
19967
20574
  }, lastRowIndex, lastColIndex));
20575
+ const rangesToScan = (fontRenderRanges === null || fontRenderRanges === void 0 ? void 0 : fontRenderRanges.length) ? fontRenderRanges : expandedViewRanges;
19968
20576
  const renderFontContext = {
19969
20577
  ctx,
19970
20578
  scale,
19971
20579
  columnTotalWidth,
19972
20580
  rowTotalHeight,
19973
- viewRanges: expandedViewRanges,
20581
+ viewRanges: (fontRenderRanges === null || fontRenderRanges === void 0 ? void 0 : fontRenderRanges.length) ? viewRanges : expandedViewRanges,
19974
20582
  checkOutOfViewBound: checkOutOfViewBound || true,
19975
20583
  diffRanges,
19976
20584
  spreadsheetSkeleton
19977
20585
  };
19978
20586
  ctx.save();
20587
+ const hasMerge = spreadsheetSkeleton.worksheet.getMergeData().length > 0;
19979
20588
  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);
20589
+ const mergeRangeIDSet = hasMerge ? /* @__PURE__ */ new Set() : null;
20590
+ const spanModel = hasMerge ? spreadsheetSkeleton.worksheet.getSpanModel() : null;
20591
+ rangesToScan.forEach((range) => {
20592
+ if (hasMerge && spanModel && mergeRangeIDSet) spreadsheetSkeleton.worksheet.getMergedCellRange(range.startRow, range.startColumn, range.endRow, range.endColumn).forEach((mergeRange) => {
20593
+ const mergeRangeIndex = spanModel.getMergeDataIndex(mergeRange.startRow, mergeRange.startColumn);
19984
20594
  if (!mergeRangeIDSet.has(mergeRangeIndex)) {
19985
20595
  mergeRangeIDSet.add(mergeRangeIndex);
19986
20596
  uniqueMergeRanges.push(mergeRange);
19987
20597
  }
19988
20598
  });
19989
- _univerjs_core.Range.foreach(range, (row, col) => {
19990
- if (spreadsheetSkeleton.worksheet.getSpanModel().getMergeDataIndex(row, col) !== -1) return;
20599
+ const { startRow, endRow, startColumn, endColumn } = range;
20600
+ for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
20601
+ const fontCache = fontMatrix.getValue(row, col);
20602
+ if (!fontCache) continue;
20603
+ if (spanModel && spanModel.getMergeDataIndex(row, col) !== -1) continue;
19991
20604
  const cellInfo = spreadsheetSkeleton.getCellWithCoordByIndex(row, col, false);
19992
- if (!cellInfo) return;
20605
+ if (!cellInfo) continue;
19993
20606
  renderFontContext.cellInfo = cellInfo;
19994
- this._renderFontEachCell(renderFontContext, row, col, fontMatrix);
19995
- });
20607
+ this._renderFontEachCell(renderFontContext, row, col, fontMatrix, fontCache);
20608
+ }
19996
20609
  });
19997
20610
  uniqueMergeRanges.forEach((range) => {
20611
+ const fontCache = fontMatrix.getValue(range.startRow, range.startColumn);
20612
+ if (!fontCache) return;
19998
20613
  renderFontContext.cellInfo = spreadsheetSkeleton.getCellWithCoordByIndex(range.startRow, range.startColumn, false);
19999
- this._renderFontEachCell(renderFontContext, range.startRow, range.startColumn, fontMatrix);
20614
+ this._renderFontEachCell(renderFontContext, range.startRow, range.startColumn, fontMatrix, fontCache);
20000
20615
  });
20001
20616
  ctx.restore();
20002
20617
  }
20003
- _renderFontEachCell(renderFontCtx, row, col, fontMatrix) {
20004
- var _cellData$fontRenderE;
20618
+ _renderFontEachCell(renderFontCtx, row, col, fontMatrix, cacheValue) {
20619
+ var _fontCache$cellData2;
20005
20620
  const { ctx, viewRanges, diffRanges, spreadsheetSkeleton, cellInfo } = renderFontCtx;
20006
20621
  const { startY, endY, startX, endX } = cellInfo;
20007
20622
  const { isMerged, isMergedMainCell, mergeInfo } = cellInfo;
@@ -20016,7 +20631,7 @@ var Font = class extends SheetExtension {
20016
20631
  renderFontCtx.endX = mergeInfo.endX;
20017
20632
  renderFontCtx.endY = mergeInfo.endY;
20018
20633
  }
20019
- const fontCache = fontMatrix.getValue(row, col);
20634
+ const fontCache = cacheValue !== null && cacheValue !== void 0 ? cacheValue : fontMatrix.getValue(row, col);
20020
20635
  if (!fontCache) return true;
20021
20636
  renderFontCtx.fontCache = fontCache;
20022
20637
  const overflowRange = spreadsheetSkeleton.overflowCache.getValue(row, col);
@@ -20042,8 +20657,19 @@ var Font = class extends SheetExtension {
20042
20657
  }
20043
20658
  if (isAllColHidden) return true;
20044
20659
  }
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;
20660
+ if ((_fontCache$cellData2 = fontCache.cellData) === null || _fontCache$cellData2 === void 0 ? void 0 : _fontCache$cellData2.fontRenderExtension) {
20661
+ var _cellData$fontRenderE;
20662
+ const cellData = spreadsheetSkeleton.worksheet.getCell(row, col) || {};
20663
+ if (cellData === null || cellData === void 0 || (_cellData$fontRenderE = cellData.fontRenderExtension) === null || _cellData$fontRenderE === void 0 ? void 0 : _cellData$fontRenderE.isSkip) return true;
20664
+ }
20665
+ if (this._renderPlainTextWithoutClip(ctx, renderFontCtx, fontCache)) {
20666
+ renderFontCtx.startX = 0;
20667
+ renderFontCtx.startY = 0;
20668
+ renderFontCtx.endX = 0;
20669
+ renderFontCtx.endY = 0;
20670
+ renderFontCtx.overflowRectangle = null;
20671
+ return false;
20672
+ }
20047
20673
  ctx.save();
20048
20674
  ctx.beginPath();
20049
20675
  renderFontCtx.overflowRectangle = overflowRange;
@@ -20051,7 +20677,6 @@ var Font = class extends SheetExtension {
20051
20677
  ctx.translate(renderFontCtx.startX + FIX_ONE_PIXEL_BLUR_OFFSET, renderFontCtx.startY + FIX_ONE_PIXEL_BLUR_OFFSET);
20052
20678
  if (fontCache.documentSkeleton) this._renderDocuments(ctx, row, col, renderFontCtx, spreadsheetSkeleton.overflowCache);
20053
20679
  else this._renderText(ctx, row, col, renderFontCtx, spreadsheetSkeleton.overflowCache);
20054
- ctx.closePath();
20055
20680
  ctx.restore();
20056
20681
  if (fontCache.documentSkeleton) {
20057
20682
  var _documentDataModel$ge;
@@ -20071,15 +20696,49 @@ var Font = class extends SheetExtension {
20071
20696
  renderFontCtx.overflowRectangle = null;
20072
20697
  return false;
20073
20698
  }
20699
+ _renderPlainTextWithoutClip(ctx, renderFontCtx, fontCache) {
20700
+ var _fontCache$style, _fontCache$style2, _fontCache$style$pd, _fontCache$style3, _padding$l, _padding$r, _padding$t, _padding$b, _fontCache$displayTex, _fontCache$style4;
20701
+ const { cellData, documentSkeleton, textFitsCurrentCell, vertexAngle = 0, centerAngle = 0, wrapStrategy } = fontCache;
20702
+ if (!textFitsCurrentCell) return false;
20703
+ if (documentSkeleton) return false;
20704
+ if (vertexAngle !== 0 || centerAngle !== 0) return false;
20705
+ if (wrapStrategy === _univerjs_core.WrapStrategy.WRAP) return false;
20706
+ if (needsFontRenderExtensionBounds(fontCache)) return false;
20707
+ 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;
20708
+ if ((cellData === null || cellData === void 0 ? void 0 : cellData.v) === void 0 || (cellData === null || cellData === void 0 ? void 0 : cellData.v) === null) return false;
20709
+ 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;
20710
+ const paddingLeft = (_padding$l = padding.l) !== null && _padding$l !== void 0 ? _padding$l : DEFAULT_PADDING_DATA.l;
20711
+ const paddingRight = (_padding$r = padding.r) !== null && _padding$r !== void 0 ? _padding$r : DEFAULT_PADDING_DATA.r;
20712
+ const paddingTop = (_padding$t = padding.t) !== null && _padding$t !== void 0 ? _padding$t : DEFAULT_PADDING_DATA.t;
20713
+ const paddingBottom = (_padding$b = padding.b) !== null && _padding$b !== void 0 ? _padding$b : DEFAULT_PADDING_DATA.b;
20714
+ const text = (_fontCache$displayTex = fontCache.displayText) !== null && _fontCache$displayTex !== void 0 ? _fontCache$displayTex : (0, _univerjs_core.getDisplayValueFromCell)(cellData);
20715
+ const { startX, startY, endX, endY } = renderFontCtx;
20716
+ const cellWidth = endX - startX - paddingLeft - paddingRight;
20717
+ const cellHeight = endY - startY - paddingTop - paddingBottom;
20718
+ const hAlign = getResolvedRenderHorizontalAlign(fontCache, cellData);
20719
+ Text.drawPlainWith(ctx, {
20720
+ text,
20721
+ fontStyle: fontCache.fontString,
20722
+ hAlign,
20723
+ vAlign: fontCache.verticalAlign,
20724
+ width: cellWidth,
20725
+ height: cellHeight,
20726
+ left: startX + FIX_ONE_PIXEL_BLUR_OFFSET + paddingLeft,
20727
+ top: startY + FIX_ONE_PIXEL_BLUR_OFFSET + paddingTop,
20728
+ 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,
20729
+ cellValueType: cellData.t
20730
+ });
20731
+ return true;
20732
+ }
20074
20733
  _renderImages(ctx, fontsConfig, startX, startY, endX, endY) {
20075
- var _fontsConfig$style, _padding$l, _padding$r, _padding$t, _padding$b, _getSkeletonData;
20734
+ var _fontsConfig$style, _padding$l2, _padding$r2, _padding$t2, _padding$b2, _getSkeletonData;
20076
20735
  const { documentSkeleton, verticalAlign, horizontalAlign } = fontsConfig;
20077
20736
  const PADDING = 2;
20078
20737
  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;
20738
+ const paddingLeft = (_padding$l2 = padding === null || padding === void 0 ? void 0 : padding.l) !== null && _padding$l2 !== void 0 ? _padding$l2 : PADDING;
20739
+ const paddingRight = (_padding$r2 = padding === null || padding === void 0 ? void 0 : padding.r) !== null && _padding$r2 !== void 0 ? _padding$r2 : PADDING;
20740
+ const paddingTop = (_padding$t2 = padding === null || padding === void 0 ? void 0 : padding.t) !== null && _padding$t2 !== void 0 ? _padding$t2 : PADDING;
20741
+ const paddingBottom = (_padding$b2 = padding === null || padding === void 0 ? void 0 : padding.b) !== null && _padding$b2 !== void 0 ? _padding$b2 : PADDING;
20083
20742
  const contentStartX = startX + paddingLeft;
20084
20743
  const contentEndX = endX - paddingRight;
20085
20744
  const contentStartY = startY + paddingTop;
@@ -20149,7 +20808,7 @@ var Font = class extends SheetExtension {
20149
20808
  * @param fontCache
20150
20809
  */
20151
20810
  _clipByRenderBounds(renderFontContext, row, col, padding = 0) {
20152
- var _fontCache$cellData$f, _fontCache$cellData, _fontCache$cellData$f2, _fontCache$cellData2;
20811
+ var _fontCache$cellData$f, _fontCache$cellData3, _fontCache$cellData$f2, _fontCache$cellData4;
20153
20812
  const { ctx, scale, overflowRectangle, fontCache } = renderFontContext;
20154
20813
  let { startX, endX, startY, endY } = renderFontContext;
20155
20814
  const { horizontalAlign = 0, vertexAngle = 0, centerAngle = 0 } = fontCache;
@@ -20158,8 +20817,8 @@ var Font = class extends SheetExtension {
20158
20817
  if (centerAngle === 90 && vertexAngle === 90) horizontalAlignOverFlow = _univerjs_core.HorizontalAlign.CENTER;
20159
20818
  else if (vertexAngle > 0 && vertexAngle !== 90 || vertexAngle === -90) horizontalAlignOverFlow = _univerjs_core.HorizontalAlign.RIGHT;
20160
20819
  }
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;
20820
+ 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;
20821
+ 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
20822
  let isOverflow = true;
20164
20823
  if (vertexAngle === 0) {
20165
20824
  startX = startX + leftOffset;
@@ -20191,26 +20850,22 @@ var Font = class extends SheetExtension {
20191
20850
  renderFontContext.endY = endY;
20192
20851
  }
20193
20852
  _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;
20853
+ 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
20854
  const { fontCache } = renderFontCtx;
20196
20855
  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;
20856
+ 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;
20857
+ const paddingLeft = (_padding$l3 = padding.l) !== null && _padding$l3 !== void 0 ? _padding$l3 : DEFAULT_PADDING_DATA.l;
20858
+ const paddingRight = (_padding$r3 = padding.r) !== null && _padding$r3 !== void 0 ? _padding$r3 : DEFAULT_PADDING_DATA.r;
20859
+ const paddingTop = (_padding$t3 = padding.t) !== null && _padding$t3 !== void 0 ? _padding$t3 : DEFAULT_PADDING_DATA.t;
20860
+ const paddingBottom = (_padding$b3 = padding.b) !== null && _padding$b3 !== void 0 ? _padding$b3 : DEFAULT_PADDING_DATA.b;
20202
20861
  const { vertexAngle = 0, wrapStrategy, cellData } = fontCache;
20203
20862
  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);
20863
+ const text = (_fontCache$displayTex2 = fontCache.displayText) !== null && _fontCache$displayTex2 !== void 0 ? _fontCache$displayTex2 : (0, _univerjs_core.getDisplayValueFromCell)(cellData);
20205
20864
  const { startX, startY, endX, endY } = renderFontCtx;
20206
20865
  const cellWidth = endX - startX - paddingLeft - paddingRight;
20207
20866
  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, {
20867
+ const hAlign = getResolvedRenderHorizontalAlign(fontCache, cellData);
20868
+ const textProps = {
20214
20869
  text,
20215
20870
  fontStyle: fontCache.fontString,
20216
20871
  warp: wrapStrategy === _univerjs_core.WrapStrategy.WRAP && vertexAngle === 0,
@@ -20220,12 +20875,17 @@ var Font = class extends SheetExtension {
20220
20875
  height: cellHeight,
20221
20876
  left: paddingLeft,
20222
20877
  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,
20878
+ 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,
20879
+ 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),
20880
+ 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),
20881
+ 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
20882
  cellValueType: cellData.t
20228
- });
20883
+ };
20884
+ if (!textProps.warp && !textProps.strokeLine && !textProps.underline) {
20885
+ Text.drawPlainWith(ctx, textProps);
20886
+ return;
20887
+ }
20888
+ Text.drawWith(ctx, textProps);
20229
20889
  }
20230
20890
  _renderDocuments(ctx, row, col, renderFontCtx, overflowCache) {
20231
20891
  const documents = this.getDocuments();
@@ -20295,6 +20955,15 @@ const stringifyRange = (range) => {
20295
20955
  const { startRow, endRow, startColumn, endColumn } = range;
20296
20956
  return `${startRow}-${endRow}-${startColumn}-${endColumn}`;
20297
20957
  };
20958
+ function drawTriangleMarker(ctx, color, x, y, x2, y2, x3, y3) {
20959
+ ctx.fillStyle = color;
20960
+ ctx.beginPath();
20961
+ ctx.moveTo(x, y);
20962
+ ctx.lineTo(x2, y2);
20963
+ ctx.lineTo(x3, y3);
20964
+ ctx.closePath();
20965
+ ctx.fill();
20966
+ }
20298
20967
  var Marker = class extends SheetExtension {
20299
20968
  constructor(..._args) {
20300
20969
  super(..._args);
@@ -20306,11 +20975,15 @@ var Marker = class extends SheetExtension {
20306
20975
  const { worksheet, rowColumnSegment } = skeleton;
20307
20976
  if (!worksheet) return;
20308
20977
  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) => {
20978
+ const renderRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [rowColumnSegment];
20979
+ const hasMerge = worksheet.getMergeData().length > 0;
20980
+ renderRanges.forEach((range) => {
20981
+ const { startRow, endRow, startColumn, endColumn } = range;
20982
+ for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
20311
20983
  var _cellData$markers, _cellData$markers2, _cellData$markers3, _cellData$markers4;
20312
- if (!worksheet.getRowVisible(row) || !worksheet.getColVisible(col)) return;
20984
+ if (!worksheet.getRowVisible(row) || !worksheet.getColVisible(col)) continue;
20313
20985
  let cellData = worksheet.getCell(row, col);
20986
+ if (!hasMerge && !(cellData === null || cellData === void 0 ? void 0 : cellData.markers)) continue;
20314
20987
  const cellInfo = skeleton.getCellWithCoordByIndex(row, col, false);
20315
20988
  const { isMerged, isMergedMainCell, mergeInfo } = cellInfo;
20316
20989
  let { startY, endY, startX, endX } = cellInfo;
@@ -20327,74 +21000,38 @@ var Marker = class extends SheetExtension {
20327
21000
  };
20328
21001
  cellData = worksheet.getCell(mainCell.row, mainCell.col);
20329
21002
  }
20330
- if (!this.isRenderDiffRangesByRow(mergeInfo.startRow, mergeInfo.endRow, diffRanges)) return true;
21003
+ if (!this.isRenderDiffRangesByRow(mergeInfo.startRow, mergeInfo.endRow, diffRanges)) continue;
20331
21004
  if (cellInfo.isMerged || cellInfo.isMergedMainCell) {
20332
21005
  const rangeStr = stringifyRange(mergeInfo);
20333
- if (mergeCellRendered.has(rangeStr)) return;
21006
+ if (mergeCellRendered.has(rangeStr)) continue;
20334
21007
  mergeCellRendered.add(rangeStr);
20335
21008
  }
20336
- if (!cellData) return;
21009
+ if (!cellData) continue;
20337
21010
  if ((_cellData$markers = cellData.markers) === null || _cellData$markers === void 0 ? void 0 : _cellData$markers.tr) {
20338
- ctx.save();
20339
21011
  const marker = cellData.markers.tr;
20340
21012
  const x = endX;
20341
21013
  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();
21014
+ drawTriangleMarker(ctx, marker.color, x, y, x - marker.size, y, x, y + marker.size);
20351
21015
  }
20352
21016
  if ((_cellData$markers2 = cellData.markers) === null || _cellData$markers2 === void 0 ? void 0 : _cellData$markers2.tl) {
20353
- ctx.save();
20354
21017
  const marker = cellData.markers.tl;
20355
21018
  const x = startX;
20356
21019
  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();
21020
+ drawTriangleMarker(ctx, marker.color, x, y, x + marker.size, y, x, y + marker.size);
20366
21021
  }
20367
21022
  if ((_cellData$markers3 = cellData.markers) === null || _cellData$markers3 === void 0 ? void 0 : _cellData$markers3.br) {
20368
- ctx.save();
20369
21023
  const marker = cellData.markers.br;
20370
21024
  const x = endX;
20371
21025
  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();
21026
+ drawTriangleMarker(ctx, marker.color, x, y, x - marker.size, y, x, y - marker.size);
20381
21027
  }
20382
21028
  if ((_cellData$markers4 = cellData.markers) === null || _cellData$markers4 === void 0 ? void 0 : _cellData$markers4.bl) {
20383
- ctx.save();
20384
21029
  const marker = cellData.markers.bl;
20385
21030
  const x = startX;
20386
21031
  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();
21032
+ drawTriangleMarker(ctx, marker.color, x, y, x + marker.size, y, x, y - marker.size);
20396
21033
  }
20397
- });
21034
+ }
20398
21035
  });
20399
21036
  }
20400
21037
  };
@@ -20654,6 +21291,12 @@ var DocComponent = class extends RenderComponent {
20654
21291
  _defineProperty(this, "pageMarginLeft", 0);
20655
21292
  _defineProperty(this, "pageMarginTop", 0);
20656
21293
  _defineProperty(this, "pageLayoutType", 0);
21294
+ _defineProperty(this, "onTextFillImageLoaded", void 0);
21295
+ this.onTextFillImageLoaded = () => {
21296
+ var _config$onTextFillIma;
21297
+ this.makeDirty(true);
21298
+ config === null || config === void 0 || (_config$onTextFillIma = config.onTextFillImageLoaded) === null || _config$onTextFillIma === void 0 || _config$onTextFillIma.call(config);
21299
+ };
20657
21300
  this._setConfig(config);
20658
21301
  }
20659
21302
  getSkeleton() {
@@ -21182,7 +21825,6 @@ var Image$1 = class extends Shape {
21182
21825
  this._props = { ...config };
21183
21826
  if (config.image) {
21184
21827
  this._native = config.image;
21185
- this._native.crossOrigin = "anonymous";
21186
21828
  this.makeDirty(true);
21187
21829
  } else if (config.url) {
21188
21830
  this._native = document.createElement("img");
@@ -22503,6 +23145,7 @@ const MIN_THUMB_SIZE = 17;
22503
23145
  const DEFAULT_TRACK_SIZE = 10;
22504
23146
  const DEFAULT_THUMB_MARGIN = 2;
22505
23147
  const HOVER_THUMB_MARGIN = 1;
23148
+ const BAR_DRAG_SCROLL_THROTTLE_MS = 32;
22506
23149
  var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22507
23150
  constructor(view, props) {
22508
23151
  super();
@@ -22525,6 +23168,10 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22525
23168
  _defineProperty(this, "_lastY", -1);
22526
23169
  _defineProperty(this, "_isHorizonMove", false);
22527
23170
  _defineProperty(this, "_isVerticalMove", false);
23171
+ _defineProperty(this, "_pendingBarDeltaX", 0);
23172
+ _defineProperty(this, "_pendingBarDeltaY", 0);
23173
+ _defineProperty(this, "_pendingBarScrollFrameId", null);
23174
+ _defineProperty(this, "_pendingBarScrollThrottleId", null);
22528
23175
  _defineProperty(this, "_horizonPointerMoveSub", void 0);
22529
23176
  _defineProperty(this, "_horizonPointerUpSub", void 0);
22530
23177
  _defineProperty(this, "_verticalPointerMoveSub", void 0);
@@ -22662,6 +23309,7 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22662
23309
  dispose() {
22663
23310
  var _this$horizonScrollTr, _this$horizonThumbRec3, _this$verticalScrollT, _this$verticalThumbRe3, _this$placeholderBarR, _this$_horizonPointer, _this$_horizonPointer2, _this$_verticalPointe, _this$_verticalPointe2;
22664
23311
  super.dispose();
23312
+ this._flushPendingBarScroll();
22665
23313
  (_this$horizonScrollTr = this.horizonScrollTrack) === null || _this$horizonScrollTr === void 0 || _this$horizonScrollTr.dispose();
22666
23314
  (_this$horizonThumbRec3 = this.horizonThumbRect) === null || _this$horizonThumbRec3 === void 0 || _this$horizonThumbRec3.dispose();
22667
23315
  (_this$verticalScrollT = this.verticalScrollTrack) === null || _this$verticalScrollT === void 0 || _this$verticalScrollT.dispose();
@@ -22680,6 +23328,47 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22680
23328
  this._mainScene = null;
22681
23329
  this._viewport.removeScrollBar();
22682
23330
  }
23331
+ _scheduleBarScrollDelta(delta) {
23332
+ var _delta$x, _delta$y;
23333
+ this._pendingBarDeltaX += (_delta$x = delta.x) !== null && _delta$x !== void 0 ? _delta$x : 0;
23334
+ this._pendingBarDeltaY += (_delta$y = delta.y) !== null && _delta$y !== void 0 ? _delta$y : 0;
23335
+ if (this._pendingBarScrollFrameId !== null || this._pendingBarScrollThrottleId !== null) return;
23336
+ this._requestPendingBarScrollFrame();
23337
+ }
23338
+ _requestPendingBarScrollFrame() {
23339
+ this._pendingBarScrollFrameId = requestAnimationFrame(() => {
23340
+ this._pendingBarScrollFrameId = null;
23341
+ this._applyPendingBarScroll({ isBarDragging: true });
23342
+ if (!this._isHorizonMove && !this._isVerticalMove) return;
23343
+ this._pendingBarScrollThrottleId = window.setTimeout(() => {
23344
+ this._pendingBarScrollThrottleId = null;
23345
+ if (this._pendingBarDeltaX !== 0 || this._pendingBarDeltaY !== 0) this._requestPendingBarScrollFrame();
23346
+ }, BAR_DRAG_SCROLL_THROTTLE_MS);
23347
+ });
23348
+ }
23349
+ _flushPendingBarScroll(isBarDragEnd = false) {
23350
+ if (this._pendingBarScrollFrameId !== null) {
23351
+ cancelAnimationFrame(this._pendingBarScrollFrameId);
23352
+ this._pendingBarScrollFrameId = null;
23353
+ }
23354
+ if (this._pendingBarScrollThrottleId !== null) {
23355
+ clearTimeout(this._pendingBarScrollThrottleId);
23356
+ this._pendingBarScrollThrottleId = null;
23357
+ }
23358
+ return this._applyPendingBarScroll({ isBarDragEnd });
23359
+ }
23360
+ _applyPendingBarScroll(options) {
23361
+ const x = this._pendingBarDeltaX;
23362
+ const y = this._pendingBarDeltaY;
23363
+ if (x === 0 && y === 0) return false;
23364
+ this._pendingBarDeltaX = 0;
23365
+ this._pendingBarDeltaY = 0;
23366
+ this._viewport.scrollByBarDeltaValue({
23367
+ ...x === 0 ? null : { x },
23368
+ ...y === 0 ? null : { y }
23369
+ }, true, options);
23370
+ return true;
23371
+ }
22683
23372
  render(ctx, left = 0, top = 0) {
22684
23373
  const { scrollX, scrollY } = this._viewport;
22685
23374
  ctx.save();
@@ -22884,12 +23573,14 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22884
23573
  var _mainScene$getEngine;
22885
23574
  const e = evt;
22886
23575
  if (!this._isVerticalMove) return;
22887
- this._viewport.scrollByBarDeltaValue({ y: e.offsetY - this._lastY });
23576
+ this._scheduleBarScrollDelta({ y: e.offsetY - this._lastY });
22888
23577
  this._lastY = e.offsetY;
22889
23578
  (_mainScene$getEngine = mainScene.getEngine()) === null || _mainScene$getEngine === void 0 || _mainScene$getEngine.setCapture();
22890
23579
  });
22891
23580
  this._verticalPointerUpSub = mainScene.onPointerUp$.subscribeEvent((_evt, _state) => {
23581
+ if (!this._isVerticalMove) return;
22892
23582
  const srcElement = this.verticalThumbRect;
23583
+ if (!this._flushPendingBarScroll(true)) this._viewport.scrollByBarDeltaValue({ y: 0 }, true, { isBarDragEnd: true });
22893
23584
  this._isVerticalMove = false;
22894
23585
  mainScene.releaseCapturedObject();
22895
23586
  mainScene.enableObjectsEvent();
@@ -22958,12 +23649,14 @@ var ScrollBar = class ScrollBar extends _univerjs_core.Disposable {
22958
23649
  var _mainScene$getEngine2;
22959
23650
  const e = evt;
22960
23651
  if (!this._isHorizonMove) return;
22961
- this._viewport.scrollByBarDeltaValue({ x: e.offsetX - this._lastX });
23652
+ this._scheduleBarScrollDelta({ x: e.offsetX - this._lastX });
22962
23653
  this._lastX = e.offsetX;
22963
23654
  (_mainScene$getEngine2 = mainScene.getEngine()) === null || _mainScene$getEngine2 === void 0 || _mainScene$getEngine2.setCapture();
22964
23655
  });
22965
23656
  this._horizonPointerUpSub = mainScene.onPointerUp$.subscribeEvent((evt, state) => {
22966
23657
  var _this$horizonThumbRec11;
23658
+ if (!this._isHorizonMove) return;
23659
+ if (!this._flushPendingBarScroll(true)) this._viewport.scrollByBarDeltaValue({ x: 0 }, true, { isBarDragEnd: true });
22967
23660
  this._isHorizonMove = false;
22968
23661
  mainScene.releaseCapturedObject();
22969
23662
  mainScene.enableObjectsEvent();
@@ -22997,6 +23690,7 @@ var FontAndBaseLine = class extends docExtension {
22997
23690
  {}
22998
23691
  );
22999
23692
  _defineProperty(this, "_textFillImageCache", /* @__PURE__ */ new Map());
23693
+ _defineProperty(this, "_textFillImageLoadListeners", /* @__PURE__ */ new Map());
23000
23694
  }
23001
23695
  draw(ctx, _parentScale, glyph, _, _more) {
23002
23696
  var _glyph$parent;
@@ -23122,10 +23816,32 @@ var FontAndBaseLine = class extends docExtension {
23122
23816
  return pattern;
23123
23817
  }
23124
23818
  _getTextFillImage(source) {
23819
+ var _this$parent;
23820
+ const onTextFillImageLoaded = (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.onTextFillImageLoaded;
23125
23821
  const cached = this._textFillImageCache.get(source);
23126
- if (cached) return cached;
23822
+ if (cached) {
23823
+ if (!cached.complete && onTextFillImageLoaded) {
23824
+ var _this$_textFillImageL;
23825
+ (_this$_textFillImageL = this._textFillImageLoadListeners.get(source)) === null || _this$_textFillImageL === void 0 || _this$_textFillImageL.add(onTextFillImageLoaded);
23826
+ }
23827
+ return cached;
23828
+ }
23127
23829
  const image = new Image();
23128
- image.crossOrigin = "anonymous";
23830
+ const listeners = /* @__PURE__ */ new Set();
23831
+ if (onTextFillImageLoaded) listeners.add(onTextFillImageLoaded);
23832
+ this._textFillImageLoadListeners.set(source, listeners);
23833
+ image.onload = () => {
23834
+ image.onload = null;
23835
+ image.onerror = null;
23836
+ const loadListeners = this._textFillImageLoadListeners.get(source);
23837
+ this._textFillImageLoadListeners.delete(source);
23838
+ loadListeners === null || loadListeners === void 0 || loadListeners.forEach((listener) => listener());
23839
+ };
23840
+ image.onerror = () => {
23841
+ image.onload = null;
23842
+ image.onerror = null;
23843
+ this._textFillImageLoadListeners.delete(source);
23844
+ };
23129
23845
  image.src = source;
23130
23846
  this._textFillImageCache.set(source, image);
23131
23847
  return image.complete ? image : null;
@@ -23179,7 +23895,7 @@ var FontAndBaseLine = class extends docExtension {
23179
23895
  const { vertexAngle, centerAngle } = renderConfig !== null && renderConfig !== void 0 ? renderConfig : {};
23180
23896
  const VERTICAL_DEG = 90;
23181
23897
  const isVertical = vertexAngle === VERTICAL_DEG && centerAngle === VERTICAL_DEG;
23182
- if (isVertical && !hasCJK(content)) {
23898
+ if (isVertical && !cjk.hasCJK(content)) {
23183
23899
  ctx.save();
23184
23900
  ctx.translate(spanStartPoint.x + centerPoint.x, spanStartPoint.y + centerPoint.y);
23185
23901
  ctx.rotate(Math.PI / 2);
@@ -23701,7 +24417,7 @@ var Documents = class Documents extends DocComponent {
23701
24417
  ctx.restore();
23702
24418
  }
23703
24419
  _drawBorderBottom(ctx, page, line, left = 0, top = 0) {
23704
- var _line$borderBottom$pa, _line$borderBottom, _line$borderBottom$co, _line$borderBottom2;
24420
+ var _line$borderBottom$pa, _line$borderBottom, _border$width, _border$color$rgb;
23705
24421
  if (this._drawLiquid == null) return;
23706
24422
  let { x, y } = this._drawLiquid;
23707
24423
  const { pageWidth, marginLeft, marginRight, marginTop } = page;
@@ -23710,8 +24426,10 @@ var Documents = class Documents extends DocComponent {
23710
24426
  y -= line.paddingTop;
23711
24427
  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
24428
  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";
24429
+ const border = line.borderBottom;
24430
+ ctx.setLineWidthByPrecision(Math.max(0, (_border$width = border === null || border === void 0 ? void 0 : border.width) !== null && _border$width !== void 0 ? _border$width : 1));
24431
+ 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";
24432
+ setDocsBorderDash(ctx, border === null || border === void 0 ? void 0 : border.dashStyle);
23715
24433
  drawLineByBorderType(ctx, "b", 0, {
23716
24434
  startX: x,
23717
24435
  startY: y,
@@ -23873,21 +24591,21 @@ var Documents = class Documents extends DocComponent {
23873
24591
  return DEFAULT_BORDER_COLOR;
23874
24592
  }
23875
24593
  _isDrawableTableCellBorder(border) {
23876
- var _border$width$v, _border$width, _border$color$rgb, _border$color;
24594
+ var _border$width$v, _border$width2, _border$color$rgb2, _border$color;
23877
24595
  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;
24596
+ 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;
24597
+ 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
24598
  return lineWidth > 0 && color !== "transparent";
23881
24599
  }
23882
24600
  _drawTableCellBorder(ctx, border, type, position) {
23883
- var _border$width$v2, _border$width2, _border$color$rgb2, _border$color2;
24601
+ var _border$width$v2, _border$width3, _border$color$rgb3, _border$color2;
23884
24602
  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;
24603
+ 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;
24604
+ 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
24605
  if (lineWidth <= 0 || color === "transparent") return;
23888
24606
  ctx.save();
23889
24607
  ctx.setLineWidthByPrecision(lineWidth);
23890
- setTableCellBorderDash(ctx, border.dashStyle);
24608
+ setDocsBorderDash(ctx, border.dashStyle);
23891
24609
  ctx.strokeStyle = color;
23892
24610
  drawLineByBorderType(ctx, type, 0, position);
23893
24611
  ctx.restore();
@@ -24017,7 +24735,7 @@ var Documents = class Documents extends DocComponent {
24017
24735
  });
24018
24736
  }
24019
24737
  };
24020
- function setTableCellBorderDash(ctx, dashStyle) {
24738
+ function setDocsBorderDash(ctx, dashStyle) {
24021
24739
  if (dashStyle === _univerjs_core.DashStyleType.DOT) {
24022
24740
  ctx.setLineDash([2]);
24023
24741
  return;
@@ -24063,6 +24781,85 @@ function rectByPrecisionBounds(ctx, x, y, width, height) {
24063
24781
  //#endregion
24064
24782
  //#region src/components/sheets/spreadsheet.ts
24065
24783
  const OBJECT_KEY = "__SHEET_EXTENSION_FONT_DOCUMENT_INSTANCE__";
24784
+ function pushSparseCellRange(ranges, row, col) {
24785
+ const last = ranges[ranges.length - 1];
24786
+ if (last && last.startRow === row && last.endRow === row && last.endColumn + 1 === col) {
24787
+ last.endColumn = col;
24788
+ return;
24789
+ }
24790
+ ranges.push({
24791
+ startRow: row,
24792
+ endRow: row,
24793
+ startColumn: col,
24794
+ endColumn: col
24795
+ });
24796
+ }
24797
+ function scanSparseExtensionFeatures(spreadsheetSkeleton, ranges) {
24798
+ const { worksheet } = spreadsheetSkeleton;
24799
+ if (!worksheet || !ranges.length || worksheet.getMergeData().length > 0) return null;
24800
+ const flags = {
24801
+ hasCustomRender: false,
24802
+ hasMarkers: false,
24803
+ hasSelectionProtection: false,
24804
+ customRenderRanges: [],
24805
+ markerRanges: [],
24806
+ selectionProtectionRanges: []
24807
+ };
24808
+ for (const range of ranges) for (let row = range.startRow; row <= range.endRow; row++) {
24809
+ if (!worksheet.getRowVisible(row)) continue;
24810
+ for (let col = range.startColumn; col <= range.endColumn; col++) {
24811
+ var _spreadsheetSkeleton$, _cell$customRender, _cell$selectionProtec;
24812
+ if (!worksheet.getColVisible(col)) continue;
24813
+ const cachedCell = (_spreadsheetSkeleton$ = spreadsheetSkeleton.stylesCache.fontMatrix.getValue(row, col)) === null || _spreadsheetSkeleton$ === void 0 ? void 0 : _spreadsheetSkeleton$.cellData;
24814
+ const cell = cachedCell !== null && cachedCell !== void 0 ? cachedCell : worksheet.getCell(row, col);
24815
+ if (!cell) continue;
24816
+ if ((_cell$customRender = cell.customRender) === null || _cell$customRender === void 0 ? void 0 : _cell$customRender.length) {
24817
+ flags.hasCustomRender = true;
24818
+ pushSparseCellRange(flags.customRenderRanges, row, col);
24819
+ }
24820
+ if (cell.markers) {
24821
+ flags.hasMarkers = true;
24822
+ pushSparseCellRange(flags.markerRanges, row, col);
24823
+ }
24824
+ if ((_cell$selectionProtec = cell.selectionProtection) === null || _cell$selectionProtec === void 0 ? void 0 : _cell$selectionProtec.length) {
24825
+ flags.hasSelectionProtection = true;
24826
+ pushSparseCellRange(flags.selectionProtectionRanges, row, col);
24827
+ }
24828
+ }
24829
+ }
24830
+ return flags;
24831
+ }
24832
+ function shouldSkipSparseExtension(uKey, flags) {
24833
+ if (!flags) return false;
24834
+ switch (uKey) {
24835
+ case "DefaultCustomExtension": return !flags.hasCustomRender;
24836
+ case "DefaultMarkerExtension": return !flags.hasMarkers;
24837
+ case "RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY":
24838
+ case "RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY": return !flags.hasSelectionProtection;
24839
+ default: return false;
24840
+ }
24841
+ }
24842
+ function hasSparseExtension(extensions) {
24843
+ return extensions.some((extension) => {
24844
+ switch (extension.uKey) {
24845
+ case "DefaultCustomExtension":
24846
+ case "DefaultMarkerExtension":
24847
+ case "RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY":
24848
+ case "RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY": return true;
24849
+ default: return false;
24850
+ }
24851
+ });
24852
+ }
24853
+ function getSparseExtensionDiffRanges(uKey, flags, diffRanges) {
24854
+ if (!flags) return diffRanges;
24855
+ switch (uKey) {
24856
+ case "DefaultCustomExtension": return flags.customRenderRanges;
24857
+ case "DefaultMarkerExtension": return flags.markerRanges;
24858
+ case "RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY":
24859
+ case "RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY": return flags.selectionProtectionRanges;
24860
+ default: return diffRanges;
24861
+ }
24862
+ }
24066
24863
  var Spreadsheet = class extends SheetComponent {
24067
24864
  constructor(oKey, spreadsheetSkeleton, _allowCache = true) {
24068
24865
  super(oKey, spreadsheetSkeleton);
@@ -24117,7 +24914,8 @@ var Spreadsheet = class extends SheetComponent {
24117
24914
  var _viewportInfo$diffBou;
24118
24915
  const spreadsheetSkeleton = this.getSkeleton();
24119
24916
  if (!spreadsheetSkeleton) return;
24120
- this._drawAuxiliary(ctx);
24917
+ const hasMergeData = spreadsheetSkeleton.worksheet.getMergeData().length > 0;
24918
+ this._drawAuxiliary(ctx, hasMergeData);
24121
24919
  const parentScale = this.getParentScale();
24122
24920
  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
24921
  const cacheRange = spreadsheetSkeleton.getCacheRangeByViewport(viewportInfo, this.isPrinting);
@@ -24128,14 +24926,19 @@ var Spreadsheet = class extends SheetComponent {
24128
24926
  endColumn: cacheRange.endColumn
24129
24927
  })) : viewRanges;
24130
24928
  const extensions = this.getExtensionsByOrder();
24929
+ const sparseExtensionFeatures = !hasMergeData && hasSparseExtension(extensions) ? scanSparseExtensionFeatures(spreadsheetSkeleton, viewRanges) : null;
24131
24930
  const scene = this.getScene();
24132
24931
  for (const extension of extensions) {
24932
+ if (shouldSkipSparseExtension(extension.uKey, sparseExtensionFeatures)) continue;
24133
24933
  const extensionViewRanges = extension === this._fontExtension || extension === this._borderExtension ? overflowSafeViewRanges : viewRanges;
24934
+ const extensionDiffRanges = getSparseExtensionDiffRanges(extension.uKey, sparseExtensionFeatures, diffRanges);
24134
24935
  const timeKey = `${SHEET_EXTENSION_PREFIX}${extension.uKey}`;
24135
24936
  const st = _univerjs_core.Tools.now();
24136
- extension.draw(ctx, parentScale, spreadsheetSkeleton, diffRanges, {
24937
+ extension.draw(ctx, parentScale, spreadsheetSkeleton, extensionDiffRanges, {
24137
24938
  viewRanges: extensionViewRanges,
24138
24939
  checkOutOfViewBound: true,
24940
+ fontRenderRanges: extension === this._fontExtension ? spreadsheetSkeleton.incrementalFontRenderRanges : void 0,
24941
+ hasMergeData,
24139
24942
  viewportKey: viewportInfo.viewportKey,
24140
24943
  viewBound: viewportInfo.cacheBound,
24141
24944
  diffBounds: viewportInfo.diffBounds
@@ -24233,7 +25036,7 @@ var Spreadsheet = class extends SheetComponent {
24233
25036
  this._dirtyBounds = dirtyBounds;
24234
25037
  }
24235
25038
  renderByViewports(mainCtx, viewportInfo, spreadsheetSkeleton) {
24236
- const { diffBounds, diffX, diffY, viewPortPosition, cacheCanvas, leftOrigin, topOrigin, bufferEdgeX, bufferEdgeY, isDirty: isViewportDirty, isForceDirty: isViewportForceDirty } = viewportInfo;
25039
+ const { diffBounds, diffX, diffY, viewPortPosition, cacheCanvas, leftOrigin, topOrigin, bufferEdgeX, bufferEdgeY, isDirty: isViewportDirty, isForceDirty: isViewportForceDirty, shouldCacheUpdate } = viewportInfo;
24237
25040
  const { rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop } = spreadsheetSkeleton;
24238
25041
  const { a: scaleX = 1, d: scaleY = 1 } = mainCtx.getTransform();
24239
25042
  const bufferEdgeSizeX = bufferEdgeX * scaleX / window.devicePixelRatio;
@@ -24242,8 +25045,10 @@ var Spreadsheet = class extends SheetComponent {
24242
25045
  cacheCtx.save();
24243
25046
  const isForceDirty = isViewportForceDirty || this.isForceDirty();
24244
25047
  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;
25048
+ const cachePixelRatio = cacheCanvas.getPixelRatio();
25049
+ const isScrollJumpOutsideCache = Math.abs(diffX) * scaleX >= cacheCanvas.getWidth() * cachePixelRatio || Math.abs(diffY) * scaleY >= cacheCanvas.getHeight() * cachePixelRatio;
25050
+ const hasMergeData = spreadsheetSkeleton.worksheet.getMergeData().length > 0;
25051
+ const shouldRefreshCache = isDirty || isForceDirty || isScrollJumpOutsideCache || hasMergeData && (diffX !== 0 || diffY !== 0) || shouldCacheUpdate && diffX !== 0;
24247
25052
  if (diffBounds.length === 0 || diffX === 0 && diffY === 0 || shouldRefreshCache) {
24248
25053
  if (shouldRefreshCache) {
24249
25054
  this.addRenderTagToScene("scrolling", false);
@@ -24337,6 +25142,8 @@ var Spreadsheet = class extends SheetComponent {
24337
25142
  }
24338
25143
  const spreadsheetSkeleton = this.getSkeleton();
24339
25144
  if (!spreadsheetSkeleton) return;
25145
+ const { viewportKey } = viewportInfo;
25146
+ if (sheetHeaderViewportKeys.includes(viewportKey)) return this;
24340
25147
  spreadsheetSkeleton.setStylesCache(viewportInfo);
24341
25148
  const segment = spreadsheetSkeleton.rowColumnSegment;
24342
25149
  if (!segment) return;
@@ -24345,10 +25152,9 @@ var Spreadsheet = class extends SheetComponent {
24345
25152
  const { rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop } = spreadsheetSkeleton;
24346
25153
  mainCtx.translateWithPrecision(rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop);
24347
25154
  (_this$getScene = this.getScene()) === null || _this$getScene === void 0 || _this$getScene.updateTransformerZero(rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop);
24348
- const { viewportKey } = viewportInfo;
24349
25155
  if (sheetContentViewportKeys.includes(viewportKey)) if (viewportInfo && viewportInfo.cacheCanvas) this.renderByViewports(mainCtx, viewportInfo, spreadsheetSkeleton);
24350
25156
  else this._draw(mainCtx, viewportInfo);
24351
- else if (sheetHeaderViewportKeys.includes(viewportKey)) {} else if (viewportInfo && viewportInfo.cacheCanvas) this.renderByViewports(mainCtx, viewportInfo, spreadsheetSkeleton);
25157
+ else if (viewportInfo && viewportInfo.cacheCanvas) this.renderByViewports(mainCtx, viewportInfo, spreadsheetSkeleton);
24352
25158
  else this._draw(mainCtx, viewportInfo);
24353
25159
  mainCtx.restore();
24354
25160
  return this;
@@ -24416,7 +25222,7 @@ var Spreadsheet = class extends SheetComponent {
24416
25222
  * draw gridlines
24417
25223
  * @param ctx
24418
25224
  */
24419
- _drawAuxiliary(ctx) {
25225
+ _drawAuxiliary(ctx, hasMergeData = true) {
24420
25226
  var _ref;
24421
25227
  const spreadsheetSkeleton = this.getSkeleton();
24422
25228
  if (spreadsheetSkeleton == null) return;
@@ -24458,22 +25264,24 @@ var Spreadsheet = class extends SheetComponent {
24458
25264
  const mergeVisibleRanges = [];
24459
25265
  let mergeVisibleRangeStartRow = startRow;
24460
25266
  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
- });
25267
+ if (hasMergeData) {
25268
+ if (worksheet.getRowVisible(r) === false) {
25269
+ if (mergeVisibleRangeStartRow < r) {
25270
+ mergeVisibleRanges.push({
25271
+ startRow: mergeVisibleRangeStartRow,
25272
+ endRow: r - 1,
25273
+ startColumn,
25274
+ endColumn
25275
+ });
25276
+ mergeVisibleRangeStartRow = r + 1;
25277
+ } else if (mergeVisibleRangeStartRow === r) mergeVisibleRangeStartRow = r + 1;
25278
+ } else if (r === endRow && mergeVisibleRangeStartRow <= r) mergeVisibleRanges.push({
25279
+ startRow: mergeVisibleRangeStartRow,
25280
+ endRow: r,
25281
+ startColumn,
25282
+ endColumn
25283
+ });
25284
+ }
24477
25285
  if (r < 0 || r > rowHeightAccumulationLength - 1) continue;
24478
25286
  const rowEndPosition = rowHeightAccumulation[r];
24479
25287
  ctx.beginPath();
@@ -24492,7 +25300,7 @@ var Spreadsheet = class extends SheetComponent {
24492
25300
  ctx.stroke();
24493
25301
  }
24494
25302
  const mergeCellRanges = [];
24495
- for (const mergeVisibleRange of mergeVisibleRanges) {
25303
+ if (hasMergeData) for (const mergeVisibleRange of mergeVisibleRanges) {
24496
25304
  const mergeRangeInVisible = spreadsheetSkeleton.getCurrentRowColumnSegmentMergeData(mergeVisibleRange);
24497
25305
  mergeCellRanges.push(...mergeRangeInVisible);
24498
25306
  }
@@ -25431,6 +26239,164 @@ var DocBackground = class DocBackground extends DocComponent {
25431
26239
  }
25432
26240
  };
25433
26241
 
26242
+ //#endregion
26243
+ //#region src/components/docs/layout/doc-no-wrap-measure.ts
26244
+ function splitDocumentNoWrapMeasureLines(text) {
26245
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
26246
+ }
26247
+ function isDocumentNoWrapMeasureTrailingWhitespace(char) {
26248
+ return char === " " || char === " " || char === "\xA0";
26249
+ }
26250
+ function getDocumentNoWrapMeasureTrailingWhitespaceStart(text) {
26251
+ let index = text.length;
26252
+ while (index > 0 && isDocumentNoWrapMeasureTrailingWhitespace(text[index - 1])) index--;
26253
+ return index;
26254
+ }
26255
+ function isDocumentNoWrapMeasureCJKText(char) {
26256
+ return /[\u2E80-\u9FFF\uF900-\uFAFF]/u.test(char);
26257
+ }
26258
+ function isDocumentNoWrapMeasureLatinText(char) {
26259
+ return /[a-z\d]/i.test(char);
26260
+ }
26261
+ function measureDocumentNoWrapTextByStyle(text, textStyle) {
26262
+ if (!text) return 0;
26263
+ return FontCache.getMeasureText(text, getFontStyleString(textStyle).fontCache).width;
26264
+ }
26265
+ function measureDocumentNoWrapCJKLatinSpacing(segment, textStyle, previous) {
26266
+ let spacing = 0;
26267
+ for (const char of Array.from(segment)) {
26268
+ const isCJK = isDocumentNoWrapMeasureCJKText(char);
26269
+ const cjkWidth = isCJK ? measureDocumentNoWrapTextByStyle(char, textStyle) : 0;
26270
+ if (isCJK && isDocumentNoWrapMeasureLatinText(previous.char)) spacing += cjkWidth / 4;
26271
+ if (isDocumentNoWrapMeasureLatinText(char) && isDocumentNoWrapMeasureCJKText(previous.char)) spacing += previous.cjkWidth / 4;
26272
+ previous.char = char;
26273
+ previous.cjkWidth = cjkWidth;
26274
+ }
26275
+ return spacing;
26276
+ }
26277
+ function measureDocumentNoWrapLineByStyle(text, textStyle) {
26278
+ const visibleText = text.slice(0, getDocumentNoWrapMeasureTrailingWhitespaceStart(text));
26279
+ return measureDocumentNoWrapTextByStyle(visibleText, textStyle) + measureDocumentNoWrapCJKLatinSpacing(visibleText, textStyle, {
26280
+ char: "",
26281
+ cjkWidth: 0
26282
+ });
26283
+ }
26284
+ function measureDocumentNoWrapRunsWidth(dataStream, textRuns, fallbackTextStyle) {
26285
+ let currentLineWidth = 0;
26286
+ let maxLineWidth = 0;
26287
+ let pendingTrailingWhitespaceWidth = 0;
26288
+ const previous = {
26289
+ char: "",
26290
+ cjkWidth: 0
26291
+ };
26292
+ const appendSegment = (segment, textStyle) => {
26293
+ if (!segment) return;
26294
+ const trailingStart = getDocumentNoWrapMeasureTrailingWhitespaceStart(segment);
26295
+ const visibleSegment = segment.slice(0, trailingStart);
26296
+ const trailingWhitespace = segment.slice(trailingStart);
26297
+ if (visibleSegment) {
26298
+ currentLineWidth += pendingTrailingWhitespaceWidth;
26299
+ pendingTrailingWhitespaceWidth = 0;
26300
+ currentLineWidth += measureDocumentNoWrapTextByStyle(visibleSegment, textStyle);
26301
+ currentLineWidth += measureDocumentNoWrapCJKLatinSpacing(visibleSegment, textStyle, previous);
26302
+ }
26303
+ if (trailingWhitespace) {
26304
+ pendingTrailingWhitespaceWidth += measureDocumentNoWrapTextByStyle(trailingWhitespace, textStyle);
26305
+ measureDocumentNoWrapCJKLatinSpacing(trailingWhitespace, textStyle, previous);
26306
+ }
26307
+ };
26308
+ const finishLine = () => {
26309
+ maxLineWidth = Math.max(maxLineWidth, currentLineWidth);
26310
+ currentLineWidth = 0;
26311
+ pendingTrailingWhitespaceWidth = 0;
26312
+ previous.char = "";
26313
+ previous.cjkWidth = 0;
26314
+ };
26315
+ const appendRange = (text, textStyle) => {
26316
+ splitDocumentNoWrapMeasureLines(text).forEach((segment, index) => {
26317
+ if (index > 0) finishLine();
26318
+ appendSegment(segment, textStyle);
26319
+ });
26320
+ };
26321
+ let cursor = 0;
26322
+ [...textRuns].sort((a, b) => a.st - b.st).forEach((run) => {
26323
+ const start = Math.max(0, run.st);
26324
+ const end = Math.max(start, run.ed);
26325
+ if (start > cursor) appendRange(dataStream.slice(cursor, start), fallbackTextStyle);
26326
+ const effectiveStart = Math.max(start, cursor);
26327
+ if (end > effectiveStart) appendRange(dataStream.slice(effectiveStart, end), run.ts);
26328
+ cursor = Math.max(cursor, end);
26329
+ });
26330
+ if (cursor < dataStream.length) appendRange(dataStream.slice(cursor), fallbackTextStyle);
26331
+ return Math.max(maxLineWidth, currentLineWidth);
26332
+ }
26333
+ function measureDocumentNoWrapTextRangeWidth(documentData, start, end) {
26334
+ var _body$dataStream, _body$textRuns, _documentData$documen2;
26335
+ const body = documentData.body;
26336
+ const dataStream = (_body$dataStream = body === null || body === void 0 ? void 0 : body.dataStream) !== null && _body$dataStream !== void 0 ? _body$dataStream : "";
26337
+ const rangeStart = Math.max(0, Math.min(dataStream.length, start));
26338
+ const rangeEnd = Math.max(rangeStart, Math.min(dataStream.length, end));
26339
+ const rangeText = dataStream.slice(rangeStart, rangeEnd);
26340
+ const textRuns = ((_body$textRuns = body === null || body === void 0 ? void 0 : body.textRuns) !== null && _body$textRuns !== void 0 ? _body$textRuns : []).map((run) => {
26341
+ const runStart = Math.max(rangeStart, run.st);
26342
+ const runEnd = Math.min(rangeEnd, run.ed);
26343
+ if (runEnd <= runStart) return null;
26344
+ return {
26345
+ ...run,
26346
+ st: runStart - rangeStart,
26347
+ ed: runEnd - rangeStart
26348
+ };
26349
+ }).filter((run) => run !== null);
26350
+ if (textRuns.length) {
26351
+ var _documentData$documen;
26352
+ return measureDocumentNoWrapRunsWidth(rangeText, textRuns, (_documentData$documen = documentData.documentStyle) === null || _documentData$documen === void 0 ? void 0 : _documentData$documen.textStyle);
26353
+ }
26354
+ return measureDocumentNoWrapLineByStyle(rangeText, (_documentData$documen2 = documentData.documentStyle) === null || _documentData$documen2 === void 0 ? void 0 : _documentData$documen2.textStyle);
26355
+ }
26356
+ /**
26357
+ * Measures the widest no-wrap line using the same text-width policy that docs
26358
+ * layout relies on for lightweight shape/text-box autofit flows.
26359
+ *
26360
+ * This is intentionally not a full document layout replacement: callers that
26361
+ * need line breaking, pagination, floating objects, or final line metrics should
26362
+ * use `DocumentSkeleton`. This helper exists for consumers that must size a
26363
+ * no-wrap host before committing a full layout pass. Keep docs-specific glyph
26364
+ * width adjustments here so feature packages do not duplicate paragraph shaping
26365
+ * details such as CJK-Latin spacing.
26366
+ */
26367
+ function measureDocumentNoWrapTextWidth(documentData) {
26368
+ var _body$dataStream2, _documentData$documen4;
26369
+ const body = documentData === null || documentData === void 0 ? void 0 : documentData.body;
26370
+ const dataStream = (_body$dataStream2 = body === null || body === void 0 ? void 0 : body.dataStream) !== null && _body$dataStream2 !== void 0 ? _body$dataStream2 : "";
26371
+ const textRuns = body === null || body === void 0 ? void 0 : body.textRuns;
26372
+ if (textRuns === null || textRuns === void 0 ? void 0 : textRuns.length) {
26373
+ var _documentData$documen3;
26374
+ return measureDocumentNoWrapRunsWidth(dataStream, textRuns, documentData === null || documentData === void 0 || (_documentData$documen3 = documentData.documentStyle) === null || _documentData$documen3 === void 0 ? void 0 : _documentData$documen3.textStyle);
26375
+ }
26376
+ const fallbackTextStyle = documentData === null || documentData === void 0 || (_documentData$documen4 = documentData.documentStyle) === null || _documentData$documen4 === void 0 ? void 0 : _documentData$documen4.textStyle;
26377
+ return Math.max(0, ...splitDocumentNoWrapMeasureLines(dataStream).map((line) => measureDocumentNoWrapLineByStyle(line, fallbackTextStyle)));
26378
+ }
26379
+ /**
26380
+ * Measures the widest segment that docs line breaking keeps together. This is
26381
+ * useful when a host may wrap normally but still needs enough width to avoid
26382
+ * clipping an individual word, CJK glyph, or punctuation segment.
26383
+ */
26384
+ function measureDocumentUnbreakableTextWidth(documentData) {
26385
+ var _documentData$body$da, _documentData$body;
26386
+ 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 : "";
26387
+ if (!documentData || !dataStream) return 0;
26388
+ const breaker = new LineBreaker(dataStream);
26389
+ let start = 0;
26390
+ let maxWidth = 0;
26391
+ let breakPoint = breaker.nextBreakPoint();
26392
+ while (breakPoint) {
26393
+ maxWidth = Math.max(maxWidth, measureDocumentNoWrapTextRangeWidth(documentData, start, breakPoint.position));
26394
+ start = breakPoint.position;
26395
+ breakPoint = breaker.nextBreakPoint();
26396
+ }
26397
+ return maxWidth;
26398
+ }
26399
+
25434
26400
  //#endregion
25435
26401
  //#region src/custom/custom-object.ts
25436
26402
  var CustomObject = class extends BaseObject {
@@ -25642,6 +26608,11 @@ var DrawingGroupObject = class extends Group {
25642
26608
  width: 0,
25643
26609
  height: 0
25644
26610
  });
26611
+ _defineProperty(this, "_outerShadow", void 0);
26612
+ }
26613
+ setOuterShadow(shadow) {
26614
+ this._outerShadow = shadow;
26615
+ this.makeDirty(true);
25645
26616
  }
25646
26617
  /**
25647
26618
  * Set the baseBound (chOff/chExt in OOXML) for this group.
@@ -25689,6 +26660,12 @@ var DrawingGroupObject = class extends Group {
25689
26660
  const centerX = realLeft + realWidth / 2;
25690
26661
  const centerY = realTop + realHeight / 2;
25691
26662
  ctx.transform(m[0], m[1], m[2], m[3], centerX, centerY);
26663
+ if (this._outerShadow) {
26664
+ ctx.shadowColor = this._outerShadow.shadowColor;
26665
+ ctx.shadowBlur = this._outerShadow.shadowBlur;
26666
+ ctx.shadowOffsetX = this._outerShadow.shadowOffsetX;
26667
+ ctx.shadowOffsetY = this._outerShadow.shadowOffsetY;
26668
+ }
25692
26669
  const objects = this.getObjectsByOrder();
25693
26670
  for (let i = 0; i < objects.length; i++) objects[i].render(ctx, bounds);
25694
26671
  ctx.restore();
@@ -26625,7 +27602,7 @@ Engine = __decorate([__decorateParam(2, ICanvasColorService)], Engine);
26625
27602
  //#endregion
26626
27603
  //#region package.json
26627
27604
  var name = "@univerjs/engine-render";
26628
- var version = "1.0.0-alpha.2";
27605
+ var version = "1.0.0-alpha.4";
26629
27606
 
26630
27607
  //#endregion
26631
27608
  //#region src/config/config.ts
@@ -27898,6 +28875,7 @@ var Transformer = class extends _univerjs_core.Disposable {
27898
28875
  _recoverySizeBoundary(selectedObjects, ancestorLeft, ancestorTop, topSceneWidth, topSceneHeight) {
27899
28876
  for (let i = 0; i < selectedObjects.length; i++) {
27900
28877
  const moveObject = selectedObjects[i];
28878
+ if (this._getConfig(moveObject).moveBoundaryEnabled === false) continue;
27901
28879
  const { left, top, width, height } = moveObject;
27902
28880
  const newTransform = {};
27903
28881
  if (left + ancestorLeft < this.zeroLeft) {
@@ -27978,11 +28956,13 @@ var Transformer = class extends _univerjs_core.Disposable {
27978
28956
  });
27979
28957
  }
27980
28958
  _getOutlinePosition(width, height, borderSpacing, borderStrokeWidth) {
28959
+ const offset = borderSpacing + borderStrokeWidth;
28960
+ const strokeOffset = borderStrokeWidth / 2;
27981
28961
  return {
27982
- left: borderSpacing - borderStrokeWidth,
27983
- top: -borderSpacing - this.borderStrokeWidth,
27984
- width: width + borderSpacing * 2,
27985
- height: height + borderSpacing * 2
28962
+ left: -offset - strokeOffset,
28963
+ top: -offset - strokeOffset,
28964
+ width: width + offset * 2,
28965
+ height: height + offset * 2
27986
28966
  };
27987
28967
  }
27988
28968
  _getRotateAnchorCursor(type) {
@@ -28056,7 +29036,7 @@ var Transformer = class extends _univerjs_core.Disposable {
28056
29036
  top += -borderSpacing - borderStrokeWidth;
28057
29037
  break;
28058
29038
  case "__SpreadsheetTransformerResizeLM__":
28059
- left += borderSpacing - borderStrokeWidth;
29039
+ left += -borderSpacing - borderStrokeWidth;
28060
29040
  top += height / 2 - longEdge / 2;
28061
29041
  break;
28062
29042
  case "__SpreadsheetTransformerResizeRM__":
@@ -28064,7 +29044,7 @@ var Transformer = class extends _univerjs_core.Disposable {
28064
29044
  top += height / 2 - longEdge / 2;
28065
29045
  break;
28066
29046
  case "__SpreadsheetTransformerResizeLB__":
28067
- left += -this.borderSpacing - borderStrokeWidth;
29047
+ left += -borderSpacing - borderStrokeWidth;
28068
29048
  top += height + borderSpacing - borderStrokeWidth - longEdge;
28069
29049
  break;
28070
29050
  case "__SpreadsheetTransformerResizeCB__":
@@ -28104,28 +29084,28 @@ var Transformer = class extends _univerjs_core.Disposable {
28104
29084
  top += -borderSpacing - borderStrokeWidth;
28105
29085
  break;
28106
29086
  case "__SpreadsheetTransformerResizeRT__":
28107
- left += width + borderSpacing - borderStrokeWidth;
29087
+ left += width + borderSpacing + borderStrokeWidth;
28108
29088
  top += -borderSpacing - borderStrokeWidth;
28109
29089
  break;
28110
29090
  case "__SpreadsheetTransformerResizeLM__":
28111
- left += borderSpacing - borderStrokeWidth;
29091
+ left += -borderSpacing - borderStrokeWidth;
28112
29092
  top += height / 2;
28113
29093
  break;
28114
29094
  case "__SpreadsheetTransformerResizeRM__":
28115
- left += width + borderSpacing - borderStrokeWidth;
29095
+ left += width + borderSpacing + borderStrokeWidth;
28116
29096
  top += height / 2;
28117
29097
  break;
28118
29098
  case "__SpreadsheetTransformerResizeLB__":
28119
- left += -this.borderSpacing - borderStrokeWidth;
28120
- top += height + borderSpacing - borderStrokeWidth;
29099
+ left += -borderSpacing - borderStrokeWidth;
29100
+ top += height + borderSpacing + borderStrokeWidth;
28121
29101
  break;
28122
29102
  case "__SpreadsheetTransformerResizeCB__":
28123
29103
  left += width / 2;
28124
- top += height + borderSpacing - borderStrokeWidth;
29104
+ top += height + borderSpacing + borderStrokeWidth;
28125
29105
  break;
28126
29106
  case "__SpreadsheetTransformerResizeRB__":
28127
- left += width + borderSpacing - borderStrokeWidth;
28128
- top += height + borderSpacing - borderStrokeWidth;
29107
+ left += width + borderSpacing + borderStrokeWidth;
29108
+ top += height + borderSpacing + borderStrokeWidth;
28129
29109
  break;
28130
29110
  }
28131
29111
  return {
@@ -28164,8 +29144,8 @@ var Transformer = class extends _univerjs_core.Disposable {
28164
29144
  width: anchorProps.width,
28165
29145
  height: anchorProps.height,
28166
29146
  radius: anchorProps.radius,
28167
- left: left + (anchorSize - anchorProps.width) / 2,
28168
- top: top + (anchorSize - anchorProps.height) / 2,
29147
+ left: left + (anchorSize - anchorProps.width) / 2 - anchorStrokeWidth / 2,
29148
+ top: top + (anchorSize - anchorProps.height) / 2 - anchorStrokeWidth / 2,
28169
29149
  shadowColor: anchorShadowColor,
28170
29150
  shadowBlur: anchorShadowBlur,
28171
29151
  shadowOffsetX: anchorShadowOffsetX,
@@ -29479,14 +30459,17 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29479
30459
  return this._renderContext.components;
29480
30460
  }
29481
30461
  constructor(init, parentInjector) {
29482
- var _init$createUnitOptio;
30462
+ var _init$createUnitOptio, _init$createUnitOptio2, _init$createUnitOptio3;
29483
30463
  super();
29484
30464
  _defineProperty(this, "isRenderUnit", true);
29485
30465
  _defineProperty(this, "_activated$", new rxjs.BehaviorSubject(true));
29486
30466
  _defineProperty(this, "activated$", this._activated$.pipe((0, rxjs.distinctUntilChanged)()));
29487
30467
  _defineProperty(this, "_injector", void 0);
29488
30468
  _defineProperty(this, "_renderContext", void 0);
29489
- this._injector = parentInjector.createChild();
30469
+ _defineProperty(this, "_dependencyService", void 0);
30470
+ 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;
30471
+ this._injector = renderParentInjector.createChild();
30472
+ this._dependencyService = new RenderUnitDependencyService(this._injector, () => this._renderContext);
29490
30473
  this._renderContext = {
29491
30474
  unit: init.unit,
29492
30475
  unitId: init.unit.getUnitId(),
@@ -29500,13 +30483,14 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29500
30483
  activate: () => this._activated$.next(true),
29501
30484
  deactivate: () => this._activated$.next(false)
29502
30485
  };
29503
- if (((_init$createUnitOptio = init.createUnitOptions) === null || _init$createUnitOptio === void 0 ? void 0 : _init$createUnitOptio.makeCurrent) === false) this.deactivate();
30486
+ if (((_init$createUnitOptio3 = init.createUnitOptions) === null || _init$createUnitOptio3 === void 0 ? void 0 : _init$createUnitOptio3.makeCurrent) === false) this.deactivate();
29504
30487
  }
29505
30488
  dispose() {
29506
- this._injector.dispose();
29507
- super.dispose();
30489
+ if (this._disposed) return;
29508
30490
  this._activated$.next(false);
29509
30491
  this._activated$.complete();
30492
+ super.dispose();
30493
+ this._injector.dispose();
29510
30494
  this._renderContext.unit = null;
29511
30495
  this._renderContext.components.clear();
29512
30496
  }
@@ -29517,7 +30501,10 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29517
30501
  * Get a dependency from the RenderUnit's injector.
29518
30502
  */
29519
30503
  with(dependency) {
29520
- return this._injector.get(dependency);
30504
+ return this._dependencyService.resolve(dependency);
30505
+ }
30506
+ getInjector() {
30507
+ return this._injector;
29521
30508
  }
29522
30509
  /**
29523
30510
  * Add render dependencies to the RenderUnit's injector. Note that the dependencies would be initialized immediately
@@ -29527,16 +30514,8 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29527
30514
  this._initDependencies(dependencies);
29528
30515
  }
29529
30516
  _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);
30517
+ this._dependencyService.register(dependencies).forEach((record) => {
30518
+ this._dependencyService.resolveRecord(record);
29540
30519
  });
29541
30520
  }
29542
30521
  getRenderContext() {
@@ -29550,6 +30529,86 @@ let RenderUnit = class RenderUnit extends _univerjs_core.Disposable {
29550
30529
  }
29551
30530
  };
29552
30531
  RenderUnit = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector))], RenderUnit);
30532
+ var RenderUnitDependencyService = class {
30533
+ constructor(_injector, _getRenderContext) {
30534
+ this._injector = _injector;
30535
+ this._getRenderContext = _getRenderContext;
30536
+ _defineProperty(this, "_records", /* @__PURE__ */ new Map());
30537
+ _defineProperty(this, "_resolved", /* @__PURE__ */ new Map());
30538
+ _defineProperty(this, "_resolving", /* @__PURE__ */ new Set());
30539
+ }
30540
+ register(dependencies) {
30541
+ const records = [];
30542
+ const seen = /* @__PURE__ */ new Set();
30543
+ dependencies.forEach((dependency) => {
30544
+ const parsed = this._parseDependency(dependency);
30545
+ const key = getRenderDependencyIdentifierKey$1(parsed.identifier);
30546
+ const existing = this._records.get(key);
30547
+ const record = existing !== null && existing !== void 0 ? existing : this._addRecord(key, parsed.identifier, parsed.create);
30548
+ if (seen.has(record.key)) return;
30549
+ seen.add(record.key);
30550
+ records.push(record);
30551
+ });
30552
+ return records;
30553
+ }
30554
+ resolve(dependency) {
30555
+ const key = getRenderDependencyIdentifierKey$1(dependency);
30556
+ if (this._resolved.has(key)) return this._resolved.get(key);
30557
+ if (this._resolving.has(key)) return;
30558
+ const record = this._records.get(key);
30559
+ if (record) return this.resolveRecord(record);
30560
+ return this._injector.get(dependency, _univerjs_core.LookUp.SELF);
30561
+ }
30562
+ resolveRecord(record) {
30563
+ if (this._resolved.has(record.key)) return this._resolved.get(record.key);
30564
+ if (this._resolving.has(record.key)) return;
30565
+ this._resolving.add(record.key);
30566
+ try {
30567
+ return this._injector.get(record.identifier, _univerjs_core.LookUp.SELF);
30568
+ } finally {
30569
+ this._resolving.delete(record.key);
30570
+ }
30571
+ }
30572
+ _addRecord(key, identifier, create) {
30573
+ const record = {
30574
+ key,
30575
+ identifier,
30576
+ create
30577
+ };
30578
+ this._records.set(key, record);
30579
+ this._injector.add([identifier, { useFactory: () => this._create(record) }]);
30580
+ return record;
30581
+ }
30582
+ _create(record) {
30583
+ if (this._resolved.has(record.key)) return this._resolved.get(record.key);
30584
+ const alreadyResolving = this._resolving.has(record.key);
30585
+ if (!alreadyResolving) this._resolving.add(record.key);
30586
+ try {
30587
+ const instance = record.create();
30588
+ this._resolved.set(record.key, instance);
30589
+ return instance;
30590
+ } finally {
30591
+ if (!alreadyResolving) this._resolving.delete(record.key);
30592
+ }
30593
+ }
30594
+ _parseDependency(dependency) {
30595
+ const [identifier, implOrNull] = Array.isArray(dependency) ? dependency : [dependency, null];
30596
+ if (!implOrNull) return {
30597
+ identifier,
30598
+ create: () => this._injector.createInstance(identifier, this._getRenderContext())
30599
+ };
30600
+ if ((0, _univerjs_core.isClassDependencyItem)(implOrNull)) return {
30601
+ identifier,
30602
+ create: () => this._injector.createInstance(implOrNull.useClass, this._getRenderContext())
30603
+ };
30604
+ throw new Error("[RenderUnit]: render dependency could only be an class!");
30605
+ }
30606
+ };
30607
+ function getRenderDependencyIdentifierKey$1(identifier) {
30608
+ const decoratorName = identifier === null || identifier === void 0 ? void 0 : identifier.decoratorName;
30609
+ if (typeof decoratorName === "string" && decoratorName) return `identifier:${decoratorName}`;
30610
+ return identifier;
30611
+ }
29553
30612
 
29554
30613
  //#endregion
29555
30614
  //#region src/render-manager/render-manager.service.ts
@@ -29590,10 +30649,11 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29590
30649
  registerRenderModules(type, deps) {
29591
30650
  if (!this._renderDependencies.has(type)) this._renderDependencies.set(type, []);
29592
30651
  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);
30652
+ const registeredDeps = deps.filter((dep) => !hasRenderDependency(dependencies, dep));
30653
+ dependencies.push(...registeredDeps);
30654
+ for (const [_, render] of this._renderMap) if (render.type === type) this._tryAddRenderDependencies(render, registeredDeps);
29595
30655
  return (0, _univerjs_core.toDisposable)(() => {
29596
- deps.forEach((dep) => (0, _univerjs_core.remove)(dependencies, dep));
30656
+ registeredDeps.forEach((dep) => (0, _univerjs_core.remove)(dependencies, dep));
29597
30657
  });
29598
30658
  }
29599
30659
  /**
@@ -29604,6 +30664,7 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29604
30664
  registerRenderModule(type, depCtor) {
29605
30665
  if (!this._renderDependencies.has(type)) this._renderDependencies.set(type, []);
29606
30666
  const dependencies = this._renderDependencies.get(type);
30667
+ if (hasRenderDependency(dependencies, depCtor)) return (0, _univerjs_core.toDisposable)(() => {});
29607
30668
  dependencies.push(depCtor);
29608
30669
  for (const [_, render] of this._renderMap) if (render.type === type) this._tryAddRenderDependencies(render, [depCtor]);
29609
30670
  return (0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(dependencies, depCtor));
@@ -29636,7 +30697,9 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29636
30697
  * @returns renderUnit:IRender
29637
30698
  */
29638
30699
  createRender(unitId, createUnitOptions) {
29639
- const renderer = this._createRender(unitId, this._injector.createInstance(Engine, unitId, void 0), true, createUnitOptions);
30700
+ var _createUnitOptions$re;
30701
+ const parentInjector = (_createUnitOptions$re = createUnitOptions === null || createUnitOptions === void 0 ? void 0 : createUnitOptions.renderParentInjector) !== null && _createUnitOptions$re !== void 0 ? _createUnitOptions$re : this._injector;
30702
+ const renderer = this._createRender(unitId, parentInjector.createInstance(Engine, unitId, void 0), (createUnitOptions === null || createUnitOptions === void 0 ? void 0 : createUnitOptions.embeddedRender) !== true, createUnitOptions, parentInjector);
29640
30703
  this._renderCreated$.next(renderer);
29641
30704
  return renderer;
29642
30705
  }
@@ -29660,7 +30723,7 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29660
30723
  * @param isMainScene
29661
30724
  * @returns renderUnit:IRender
29662
30725
  */
29663
- _createRender(unitId, engine, isMainScene = true, createUnitOptions) {
30726
+ _createRender(unitId, engine, isMainScene = true, createUnitOptions, parentInjector = this._injector) {
29664
30727
  const existItem = this.getRenderById(unitId);
29665
30728
  let shouldDestroyEngine = true;
29666
30729
  if (existItem != null) {
@@ -29677,7 +30740,7 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29677
30740
  if (unit) {
29678
30741
  const type = this._univerInstanceService.getUnitType(unitId);
29679
30742
  const ctorOfDeps = this._getRenderDepsByType(type);
29680
- renderUnit = this._injector.createInstance(RenderUnit, {
30743
+ renderUnit = parentInjector.createInstance(RenderUnit, {
29681
30744
  unit,
29682
30745
  engine,
29683
30746
  scene,
@@ -29685,7 +30748,16 @@ let RenderManagerService = class RenderManagerService extends _univerjs_core.Dis
29685
30748
  createUnitOptions
29686
30749
  });
29687
30750
  this._addRenderUnit(unitId, renderUnit);
29688
- this._tryAddRenderDependencies(renderUnit, ctorOfDeps);
30751
+ try {
30752
+ this._tryAddRenderDependencies(renderUnit, ctorOfDeps);
30753
+ } catch (error) {
30754
+ try {
30755
+ this._disposeItem(renderUnit);
30756
+ } finally {
30757
+ this._renderMap.delete(unitId);
30758
+ }
30759
+ throw error;
30760
+ }
29689
30761
  } else {
29690
30762
  renderUnit = {
29691
30763
  isThumbNail: true,
@@ -29748,6 +30820,18 @@ RenderManagerService = __decorate([
29748
30820
  __decorateParam(1, _univerjs_core.IUniverInstanceService),
29749
30821
  __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService))
29750
30822
  ], RenderManagerService);
30823
+ function hasRenderDependency(dependencies, dep) {
30824
+ const key = getRenderDependencyIdentifierKey(getRenderDependencyIdentifier(dep));
30825
+ return dependencies.some((registered) => getRenderDependencyIdentifierKey(getRenderDependencyIdentifier(registered)) === key);
30826
+ }
30827
+ function getRenderDependencyIdentifier(dep) {
30828
+ return Array.isArray(dep) ? dep[0] : dep;
30829
+ }
30830
+ function getRenderDependencyIdentifierKey(identifier) {
30831
+ const decoratorName = identifier.decoratorName;
30832
+ if (typeof decoratorName === "string" && decoratorName) return `identifier:${decoratorName}`;
30833
+ return identifier;
30834
+ }
29751
30835
  const IRenderManagerService = (0, _univerjs_core.createIdentifier)("engine-render.render-manager.service");
29752
30836
  function isDisposable(thing) {
29753
30837
  return !!thing && typeof thing.dispose === "function";
@@ -30176,13 +31260,13 @@ var Viewport = class {
30176
31260
  * @param delta
30177
31261
  * @returns isLimited
30178
31262
  */
30179
- scrollByBarDeltaValue(delta, isTrigger = true) {
31263
+ scrollByBarDeltaValue(delta, isTrigger = true, options) {
30180
31264
  const x = this.scrollX + (delta.x || 0);
30181
31265
  const y = this.scrollY + (delta.y || 0);
30182
31266
  return this._scrollToBarPosCore({
30183
31267
  x,
30184
31268
  y
30185
- }, isTrigger);
31269
+ }, isTrigger, options);
30186
31270
  }
30187
31271
  /**
30188
31272
  * Viewport scroll to certain position.
@@ -30720,7 +31804,7 @@ var Viewport = class {
30720
31804
  * @param rawScrollXY Partial<IViewportScrollPosition>
30721
31805
  * @param isTrigger
30722
31806
  */
30723
- _scrollToBarPosCore(rawScrollXY, isTrigger = true) {
31807
+ _scrollToBarPosCore(rawScrollXY, isTrigger = true, options) {
30724
31808
  var _this$_scrollBar6, _this$_scrollBar7, _this$_scrollBar8, _this$_scrollBar9, _this$_scrollBar10;
30725
31809
  if (this._scrollBar == null) return;
30726
31810
  let scrollX = rawScrollXY.x;
@@ -30741,7 +31825,9 @@ var Viewport = class {
30741
31825
  rawScrollY: rawScrollXY.y,
30742
31826
  limitX: (_this$_scrollBar6 = this._scrollBar) === null || _this$_scrollBar6 === void 0 ? void 0 : _this$_scrollBar6.limitX,
30743
31827
  limitY: (_this$_scrollBar7 = this._scrollBar) === null || _this$_scrollBar7 === void 0 ? void 0 : _this$_scrollBar7.limitY,
30744
- isTrigger
31828
+ isTrigger,
31829
+ isBarDragging: options === null || options === void 0 ? void 0 : options.isBarDragging,
31830
+ isBarDragEnd: options === null || options === void 0 ? void 0 : options.isBarDragEnd
30745
31831
  };
30746
31832
  (_this$_scrollBar8 = this._scrollBar) === null || _this$_scrollBar8 === void 0 || _this$_scrollBar8.makeDirty(true);
30747
31833
  this.onScrollAfter$.emitEvent(scrollSubParam);
@@ -30754,7 +31840,9 @@ var Viewport = class {
30754
31840
  viewportScrollY: this.viewportScrollY,
30755
31841
  limitX: (_this$_scrollBar9 = this._scrollBar) === null || _this$_scrollBar9 === void 0 ? void 0 : _this$_scrollBar9.limitX,
30756
31842
  limitY: (_this$_scrollBar10 = this._scrollBar) === null || _this$_scrollBar10 === void 0 ? void 0 : _this$_scrollBar10.limitY,
30757
- isTrigger
31843
+ isTrigger,
31844
+ isBarDragging: options === null || options === void 0 ? void 0 : options.isBarDragging,
31845
+ isBarDragEnd: options === null || options === void 0 ? void 0 : options.isBarDragEnd
30758
31846
  });
30759
31847
  return afterLimit;
30760
31848
  }
@@ -30870,13 +31958,11 @@ var Viewport = class {
30870
31958
  left: Math.max(prevBound.left, currBound.left),
30871
31959
  right: Math.min(prevBound.right, currBound.right)
30872
31960
  });
30873
- const expandX = this.bufferEdgeX;
30874
- const expandY = this.bufferEdgeY;
30875
31961
  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;
31962
+ bound.left = bound.left - this.bufferEdgeX;
31963
+ bound.right = bound.right + this.bufferEdgeX;
31964
+ bound.top = bound.top - this.bufferEdgeY;
31965
+ bound.bottom = bound.bottom + this.bufferEdgeY;
30880
31966
  }
30881
31967
  return additionalAreas;
30882
31968
  }
@@ -31079,6 +32165,7 @@ exports.WatermarkLayer = WatermarkLayer;
31079
32165
  exports.calculateRectRotate = calculateRectRotate;
31080
32166
  exports.cancelRequestFrame = cancelRequestFrame;
31081
32167
  exports.checkStyle = checkStyle;
32168
+ exports.cjk = cjk;
31082
32169
  exports.clampRange = clampRange;
31083
32170
  exports.clearLineByBorderType = clearLineByBorderType;
31084
32171
  exports.compareDocumentSkeletonNestedPagePathOrder = compareDocumentSkeletonNestedPagePathOrder;
@@ -31103,6 +32190,7 @@ exports.getCurrentScrollXY = getCurrentScrollXY;
31103
32190
  exports.getCurrentTypeOfRenderer = getCurrentTypeOfRenderer;
31104
32191
  exports.getDPI = getDPI;
31105
32192
  exports.getDevicePixelRatio = getDevicePixelRatio;
32193
+ exports.getDocsCustomBlockRenderViewport = getDocsCustomBlockRenderViewport;
31106
32194
  exports.getDocsSkeletonPageSize = getDocsSkeletonPageSize;
31107
32195
  exports.getDocsTableRenderViewport = getDocsTableRenderViewport;
31108
32196
  exports.getDocumentSkeletonColumnPagePathInfo = getDocumentSkeletonColumnPagePathInfo;
@@ -31127,6 +32215,7 @@ exports.getRotateOffsetAndFarthestHypotenuse = getRotateOffsetAndFarthestHypoten
31127
32215
  exports.getRotateOrientation = getRotateOrientation;
31128
32216
  exports.getRotatedBoundInGroup = getRotatedBoundInGroup;
31129
32217
  exports.getScale = getScale;
32218
+ exports.getShrinkToFitScale = getShrinkToFitScale;
31130
32219
  exports.getSizeForDom = getSizeForDom;
31131
32220
  exports.getSystemHighlightColor = getSystemHighlightColor;
31132
32221
  exports.getTableIdAndSliceIndex = getTableIdAndSliceIndex;
@@ -31136,9 +32225,6 @@ exports.glyphIterator = glyphIterator;
31136
32225
  exports.hasAllLatin = hasAllLatin;
31137
32226
  exports.hasArabic = hasArabic;
31138
32227
  exports.hasBasicLatin = hasBasicLatin;
31139
- exports.hasCJK = hasCJK;
31140
- exports.hasCJKPunctuation = hasCJKPunctuation;
31141
- exports.hasCJKText = hasCJKText;
31142
32228
  exports.hasLatinExtendedA = hasLatinExtendedA;
31143
32229
  exports.hasLatinExtendedB = hasLatinExtendedB;
31144
32230
  exports.hasLatinOneSupplement = hasLatinOneSupplement;
@@ -31167,6 +32253,9 @@ exports.isRegExp = isRegExp;
31167
32253
  exports.isSameLine = isSameLine;
31168
32254
  exports.isString = isString;
31169
32255
  exports.lineIterator = lineIterator;
32256
+ exports.measureDocumentNoWrapTextRangeWidth = measureDocumentNoWrapTextRangeWidth;
32257
+ exports.measureDocumentNoWrapTextWidth = measureDocumentNoWrapTextWidth;
32258
+ exports.measureDocumentUnbreakableTextWidth = measureDocumentUnbreakableTextWidth;
31170
32259
  exports.mergeInfoOffset = mergeInfoOffset;
31171
32260
  exports.parseDataStreamToTree = parseDataStreamToTree;
31172
32261
  exports.pixelToPt = pixelToPt;
@@ -31183,6 +32272,8 @@ exports.renderTextWatermark = renderTextWatermark;
31183
32272
  exports.renderUserInfoWatermark = renderUserInfoWatermark;
31184
32273
  exports.renderWatermark = renderWatermark;
31185
32274
  exports.requestNewFrame = requestNewFrame;
32275
+ exports.scaleDocumentDataForShrinkToFit = scaleDocumentDataForShrinkToFit;
32276
+ exports.setDocsCustomBlockRenderViewportProvider = setDocsCustomBlockRenderViewportProvider;
31186
32277
  exports.setDocsTableRenderViewportProvider = setDocsTableRenderViewportProvider;
31187
32278
  exports.setLineType = setLineType;
31188
32279
  exports.sheetContentViewportKeys = sheetContentViewportKeys;