@windoc/core 0.3.20 → 0.3.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -78,7 +78,7 @@ __export(index_exports, {
78
78
  module.exports = __toCommonJS(index_exports);
79
79
 
80
80
  // src/version.ts
81
- var version = "0.3.20";
81
+ var version = "0.3.22";
82
82
 
83
83
  // src/dataset/enum/Common.ts
84
84
  var MaxHeightRatio = /* @__PURE__ */ ((MaxHeightRatio2) => {
@@ -503,7 +503,7 @@ var ElementType = /* @__PURE__ */ ((ElementType2) => {
503
503
  // src/utils/ua.ts
504
504
  var isApple = typeof navigator !== "undefined" && /Mac OS X/.test(navigator.userAgent);
505
505
  var isIOS = typeof navigator !== "undefined" && /iPad|iPhone/.test(navigator.userAgent);
506
- var isMobile = /Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
506
+ var isMobile = typeof navigator !== "undefined" && /Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
507
507
  navigator.userAgent
508
508
  );
509
509
  var isFirefox = typeof navigator !== "undefined" && /Firefox/.test(navigator.userAgent);
@@ -598,6 +598,8 @@ var TABLE_TD_ZIP_ATTR = [
598
598
  "externalId",
599
599
  "verticalAlign",
600
600
  "backgroundColor",
601
+ "borderColor",
602
+ "padding",
601
603
  "borderTypes",
602
604
  "slashTypes",
603
605
  "disabled",
@@ -5016,6 +5018,37 @@ function pickElementAttr(payload, option = {}) {
5016
5018
  });
5017
5019
  return element;
5018
5020
  }
5021
+ function mergeSplitTableRowsForZip(trList) {
5022
+ for (let t = trList.length - 1; t >= 0; t--) {
5023
+ const splitTr = trList[t];
5024
+ if (!splitTr.splitParentId) continue;
5025
+ const parentTrIdx = trList.findIndex(
5026
+ (tr) => tr.id === splitTr.splitParentId
5027
+ );
5028
+ if (!~parentTrIdx) continue;
5029
+ const parentTr = trList[parentTrIdx];
5030
+ parentTr.height += splitTr.height;
5031
+ for (let d = 0; d < parentTr.tdList.length; d++) {
5032
+ const parentTd = parentTr.tdList[d];
5033
+ const splitTd = splitTr.tdList[d];
5034
+ if (!parentTd || !splitTd) continue;
5035
+ const hasSyntheticLeadingZero = !!splitTd.splitSyntheticLeadingZero && splitTd.value[0]?.value === ZERO;
5036
+ parentTd.value.push(
5037
+ ...hasSyntheticLeadingZero ? splitTd.value.slice(1) : splitTd.value
5038
+ );
5039
+ }
5040
+ trList.splice(t, 1);
5041
+ }
5042
+ for (let t = 0; t < trList.length; t++) {
5043
+ const tr = trList[t];
5044
+ delete tr.id;
5045
+ delete tr.splitParentId;
5046
+ delete tr.splitRootId;
5047
+ delete tr.splitLevel;
5048
+ delete tr.splitBoundaryTop;
5049
+ delete tr.splitBoundaryBottom;
5050
+ }
5051
+ }
5019
5052
  function zipElementList(payload, options = {}) {
5020
5053
  const { extraPickAttrs, isClassifyArea = false, isClone = true } = options;
5021
5054
  const elementList = isClone ? deepClone(payload) : payload;
@@ -5115,8 +5148,11 @@ function zipElementList(payload, options = {}) {
5115
5148
  while (tableIndex < elementList.length) {
5116
5149
  const nextElement = elementList[tableIndex];
5117
5150
  if (nextElement.pagingId === element.pagingId) {
5151
+ const nextTrList = nextElement.trList.filter(
5152
+ (tr) => !tr.pagingRepeat
5153
+ );
5118
5154
  element.height += nextElement.height;
5119
- element.trList.push(...nextElement.trList);
5155
+ element.trList.push(...nextTrList);
5120
5156
  tableIndex++;
5121
5157
  combineCount++;
5122
5158
  } else {
@@ -5126,9 +5162,9 @@ function zipElementList(payload, options = {}) {
5126
5162
  e += combineCount;
5127
5163
  }
5128
5164
  if (element.trList) {
5165
+ mergeSplitTableRowsForZip(element.trList);
5129
5166
  for (let t = 0; t < element.trList.length; t++) {
5130
5167
  const tr = element.trList[t];
5131
- delete tr.id;
5132
5168
  for (let d = 0; d < tr.tdList.length; d++) {
5133
5169
  const td = tr.tdList[d];
5134
5170
  const zipTd = {
@@ -6828,6 +6864,57 @@ var RadioControl = class extends CheckboxControl {
6828
6864
  }
6829
6865
  };
6830
6866
 
6867
+ // src/core/event/handlers/splitCell.ts
6868
+ function isSameSplitCellSelection(first, second) {
6869
+ if (!first || !second) return false;
6870
+ return first.pagingId === second.pagingId && first.rootTrId === second.rootTrId && first.colIndex === second.colIndex;
6871
+ }
6872
+ function getSplitCellPointer(draw, position) {
6873
+ if (!position.isTable || position.index === void 0 || position.tdIndex === void 0 || position.tdValueIndex === void 0 || !position.trId) {
6874
+ return null;
6875
+ }
6876
+ const originalElementList = draw.getOriginalElementList();
6877
+ const tableElement = originalElementList[position.index];
6878
+ if (tableElement?.type !== "table" /* TABLE */ || !tableElement.pagingId || !tableElement.trList?.length) {
6879
+ return null;
6880
+ }
6881
+ const tr = tableElement.trList.find((row) => row.id === position.trId);
6882
+ const td = tr?.tdList[position.tdIndex];
6883
+ if (!tr || !td || td.colIndex === void 0 || !tr.id) {
6884
+ return null;
6885
+ }
6886
+ const splitCellSelection = {
6887
+ pagingId: tableElement.pagingId,
6888
+ rootTrId: tr.splitRootId || tr.id,
6889
+ colIndex: td.colIndex
6890
+ };
6891
+ const splitCellContext = draw.getSplitCellSelectionContext(
6892
+ originalElementList,
6893
+ splitCellSelection
6894
+ );
6895
+ if (!splitCellContext) {
6896
+ return null;
6897
+ }
6898
+ let globalIndex = 0;
6899
+ for (let c = 0; c < splitCellContext.cellContextList.length; c++) {
6900
+ const cellContext = splitCellContext.cellContextList[c];
6901
+ const currentTd = cellContext.td;
6902
+ const skipLeadingZero = !!currentTd.splitSyntheticLeadingZero && currentTd.value[0]?.value === ZERO ? 1 : 0;
6903
+ if (cellContext.tr.id === tr.id && currentTd.id === td.id) {
6904
+ globalIndex += Math.max(position.tdValueIndex - skipLeadingZero, 0);
6905
+ return {
6906
+ splitCellSelection,
6907
+ globalIndex
6908
+ };
6909
+ }
6910
+ globalIndex += Math.max(currentTd.value.length - skipLeadingZero, 0);
6911
+ }
6912
+ return null;
6913
+ }
6914
+ function isSameSplitCellPointer(first, second) {
6915
+ return isSameSplitCellSelection(first, second);
6916
+ }
6917
+
6831
6918
  // src/core/event/handlers/mousedown.ts
6832
6919
  function setRangeCache(host) {
6833
6920
  const draw = host.getDraw();
@@ -6915,9 +7002,11 @@ function mousedown(evt, host) {
6915
7002
  tdValueIndex,
6916
7003
  hitLineStartIndex
6917
7004
  } = positionResult;
7005
+ const splitCellPointer = getSplitCellPointer(draw, positionResult);
6918
7006
  host.mouseDownStartPosition = {
6919
7007
  ...positionResult,
6920
- index: isTable ? tdValueIndex : index,
7008
+ index: splitCellPointer ? splitCellPointer.globalIndex : isTable ? tdValueIndex : index,
7009
+ splitCellSelection: splitCellPointer?.splitCellSelection,
6921
7010
  x: evt.offsetX,
6922
7011
  y: evt.offsetY
6923
7012
  };
@@ -7357,10 +7446,33 @@ function mousemove(evt, host) {
7357
7446
  isTable: startIsTable,
7358
7447
  tdIndex: startTdIndex,
7359
7448
  trIndex: startTrIndex,
7360
- tableId: startTableId
7449
+ tableId: startTableId,
7450
+ splitCellSelection: startSplitCellSelection
7361
7451
  } = host.mouseDownStartPosition;
7362
7452
  const endIndex = isTable ? tdValueIndex : index;
7363
7453
  const rangeManager = draw.getRange();
7454
+ if (startSplitCellSelection) {
7455
+ const currentSplitCellPointer = getSplitCellPointer(draw, positionResult);
7456
+ if (currentSplitCellPointer && isSameSplitCellPointer(
7457
+ startSplitCellSelection,
7458
+ currentSplitCellPointer.splitCellSelection
7459
+ )) {
7460
+ let start = startIndex;
7461
+ let end = currentSplitCellPointer.globalIndex;
7462
+ if (start > end) {
7463
+ [start, end] = [end, start];
7464
+ }
7465
+ if (start === end) return;
7466
+ rangeManager.setRange(start, end);
7467
+ rangeManager.setSplitCellSelection(startSplitCellSelection);
7468
+ draw.render({
7469
+ isSubmitHistory: false,
7470
+ isSetCursor: false,
7471
+ isCompute: false
7472
+ });
7473
+ return;
7474
+ }
7475
+ }
7364
7476
  if (isTable && startIsTable && (tdIndex !== startTdIndex || trIndex !== startTrIndex)) {
7365
7477
  rangeManager.setRange(
7366
7478
  endIndex,
@@ -7403,6 +7515,71 @@ function mousemove(evt, host) {
7403
7515
  });
7404
7516
  }
7405
7517
 
7518
+ // src/core/event/handlers/keydown/tableSplit.ts
7519
+ function moveEmptySplitTdCursorToParent(host) {
7520
+ const draw = host.getDraw();
7521
+ const position = draw.getPosition();
7522
+ const positionContext = position.getPositionContext();
7523
+ const cursorPosition = position.getCursorPosition();
7524
+ if (!positionContext.isTable || !cursorPosition || cursorPosition.index !== 0) {
7525
+ return null;
7526
+ }
7527
+ const elementList = draw.getOriginalElementList();
7528
+ const resolved = draw.resolveTableCellContext(elementList, positionContext);
7529
+ if (!resolved) return null;
7530
+ const currentTr = resolved.element.trList?.[resolved.trIndex];
7531
+ const currentTd = resolved.td;
7532
+ if (!currentTr?.splitParentId || currentTd.value.length !== 1 || currentTd.value[0]?.value !== ZERO) {
7533
+ return null;
7534
+ }
7535
+ const pagingId = resolved.element.pagingId;
7536
+ if (!pagingId) return null;
7537
+ let parentTarget;
7538
+ for (let i = resolved.index; i >= 0; i--) {
7539
+ const tableElement = elementList[i];
7540
+ if (tableElement.type !== "table" /* TABLE */) continue;
7541
+ if (tableElement.pagingId !== pagingId) {
7542
+ if (i < resolved.index) break;
7543
+ continue;
7544
+ }
7545
+ const parentTrIndex = tableElement.trList?.findIndex((tr) => tr.id === currentTr.splitParentId) ?? -1;
7546
+ if (parentTrIndex < 0) continue;
7547
+ const parentTr2 = tableElement.trList[parentTrIndex];
7548
+ const parentTdIndex = parentTr2.tdList.findIndex(
7549
+ (td) => td.colIndex === currentTd.colIndex
7550
+ );
7551
+ if (parentTdIndex < 0) return null;
7552
+ parentTarget = {
7553
+ tableId: tableElement.id,
7554
+ tableIndex: i,
7555
+ trIndex: parentTrIndex,
7556
+ tdIndex: parentTdIndex
7557
+ };
7558
+ break;
7559
+ }
7560
+ if (!parentTarget) return null;
7561
+ const parentElement = elementList[parentTarget.tableIndex];
7562
+ const parentTr = parentElement.trList[parentTarget.trIndex];
7563
+ const parentTd = parentTr.tdList[parentTarget.tdIndex];
7564
+ if (!currentTd.splitSyntheticLeadingZero) {
7565
+ currentTd.value.splice(0, 1);
7566
+ currentTd.rowList = void 0;
7567
+ currentTd.positionList = void 0;
7568
+ }
7569
+ const curIndex = Math.max(parentTd.value.length - 1, 0);
7570
+ position.setPositionContext({
7571
+ isTable: true,
7572
+ index: parentTarget.tableIndex,
7573
+ trIndex: parentTarget.trIndex,
7574
+ tdIndex: parentTarget.tdIndex,
7575
+ tdId: parentTd.id,
7576
+ trId: parentTr.id,
7577
+ tableId: parentTarget.tableId
7578
+ });
7579
+ draw.getRange().setRange(curIndex, curIndex);
7580
+ return curIndex;
7581
+ }
7582
+
7406
7583
  // src/core/event/handlers/keydown/backspace.ts
7407
7584
  function backspaceHideElement(host) {
7408
7585
  const draw = host.getDraw();
@@ -7444,13 +7621,27 @@ function backspace(evt, host) {
7444
7621
  if (draw.isReadonly()) return;
7445
7622
  const rangeManager = draw.getRange();
7446
7623
  if (!rangeManager.getIsCanInput()) return;
7624
+ if (rangeManager.getIsCollapsed()) {
7625
+ const splitParentIndex = moveEmptySplitTdCursorToParent(host);
7626
+ if (splitParentIndex !== null) {
7627
+ draw.getGlobalEvent().setCanvasEventAbility();
7628
+ draw.render({
7629
+ curIndex: splitParentIndex,
7630
+ isSubmitHistory: false
7631
+ });
7632
+ evt.preventDefault();
7633
+ return;
7634
+ }
7635
+ }
7447
7636
  if (rangeManager.getIsCollapsed()) {
7448
7637
  backspaceHideElement(host);
7449
7638
  }
7450
7639
  const control = draw.getControl();
7451
7640
  const { startIndex, endIndex, isCrossRowCol } = rangeManager.getRange();
7452
7641
  let curIndex;
7453
- if (isCrossRowCol) {
7642
+ if (rangeManager.getSplitCellSelection() && startIndex !== endIndex) {
7643
+ curIndex = draw.replaceSplitCellSelection([]);
7644
+ } else if (isCrossRowCol) {
7454
7645
  const rowCol = draw.getTableParticle().getRangeRowCol();
7455
7646
  if (!rowCol) return;
7456
7647
  let isDeleted = false;
@@ -7589,6 +7780,18 @@ function del(evt, host) {
7589
7780
  if (draw.isReadonly()) return;
7590
7781
  const rangeManager = draw.getRange();
7591
7782
  if (!rangeManager.getIsCanInput()) return;
7783
+ if (rangeManager.getIsCollapsed()) {
7784
+ const splitParentIndex = moveEmptySplitTdCursorToParent(host);
7785
+ if (splitParentIndex !== null) {
7786
+ draw.getGlobalEvent().setCanvasEventAbility();
7787
+ draw.render({
7788
+ curIndex: splitParentIndex,
7789
+ isSubmitHistory: false
7790
+ });
7791
+ evt.preventDefault();
7792
+ return;
7793
+ }
7794
+ }
7592
7795
  const { startIndex, endIndex, isCrossRowCol } = rangeManager.getRange();
7593
7796
  const elementList = draw.getElementList();
7594
7797
  const control = draw.getControl();
@@ -7596,7 +7799,9 @@ function del(evt, host) {
7596
7799
  deleteHideElement(host);
7597
7800
  }
7598
7801
  let curIndex;
7599
- if (isCrossRowCol) {
7802
+ if (rangeManager.getSplitCellSelection() && startIndex !== endIndex) {
7803
+ curIndex = draw.replaceSplitCellSelection([]);
7804
+ } else if (isCrossRowCol) {
7600
7805
  const rowCol = draw.getTableParticle().getRangeRowCol();
7601
7806
  if (!rowCol) return;
7602
7807
  let isDeleted = false;
@@ -8508,6 +8713,8 @@ function input(data2, host) {
8508
8713
  if (!isComposing) {
8509
8714
  control.emitControlContentChange();
8510
8715
  }
8716
+ } else if (rangeManager.getSplitCellSelection()) {
8717
+ curIndex = draw.replaceSplitCellSelection(inputData);
8511
8718
  } else {
8512
8719
  const start = startIndex + 1;
8513
8720
  if (startIndex !== endIndex) {
@@ -9007,7 +9214,7 @@ var CanvasEvent = class {
9007
9214
  }
9008
9215
  selectAll() {
9009
9216
  if (this.position.getPositionContext().isTable) {
9010
- this.draw.getTableOperate().tableSelectAll();
9217
+ this.draw.getTableOperate().tableTdSelectAll();
9011
9218
  } else {
9012
9219
  const positionList = this.position.getPositionList();
9013
9220
  this.range.setRange(0, positionList.length - 1);
@@ -9284,8 +9491,11 @@ var Position = class {
9284
9491
  return this.floatPositionList;
9285
9492
  }
9286
9493
  getTablePositionList(sourceElementList) {
9287
- const { index, trIndex, tdIndex } = this.positionContext;
9288
- return sourceElementList[index].trList[trIndex].tdList[tdIndex].positionList || [];
9494
+ const splitCellSelectionContext = this.draw.getSplitCellSelectionContext(sourceElementList);
9495
+ if (splitCellSelectionContext) {
9496
+ return splitCellSelectionContext.positionList;
9497
+ }
9498
+ return this.draw.resolveTableCellContext(sourceElementList, this.positionContext)?.td.positionList || [];
9289
9499
  }
9290
9500
  getPositionList() {
9291
9501
  return this.positionContext.isTable ? this.getTablePositionList(this.draw.getOriginalElementList()) : this.getOriginalPositionList();
@@ -9939,6 +10149,46 @@ var Position = class {
9939
10149
  positionResult.index = newIndex;
9940
10150
  }
9941
10151
  }
10152
+ if (positionResult.isTable && positionResult.trId != null) {
10153
+ const elementList = this.draw.getOriginalMainElementList();
10154
+ const tableElement = elementList[positionResult.index];
10155
+ if (tableElement?.trList) {
10156
+ const matchedTr = tableElement.trList.find(
10157
+ (r) => r.id === positionResult.trId
10158
+ );
10159
+ if (matchedTr?.splitRootId) {
10160
+ const matchedTd = matchedTr.tdList[positionResult.tdIndex];
10161
+ if (matchedTd && matchedTd.splitSyntheticLeadingZero && matchedTd.value.length === 1 && matchedTd.value[0].value === ZERO) {
10162
+ const pagingId = tableElement.pagingId;
10163
+ if (pagingId) {
10164
+ for (let i = positionResult.index - 1; i >= 0; i--) {
10165
+ const prevElement = elementList[i];
10166
+ if (prevElement.pagingId !== pagingId) break;
10167
+ const rootTr = prevElement.trList?.find(
10168
+ (r) => r.id === matchedTr.splitRootId
10169
+ );
10170
+ if (rootTr) {
10171
+ const rootTd = rootTr.tdList.find(
10172
+ (t) => t.colIndex === matchedTd.colIndex
10173
+ );
10174
+ const isRootTdEmpty = !!rootTd && rootTd.value.length === 1 && rootTd.value[0].value === ZERO;
10175
+ if (rootTd && isRootTdEmpty) {
10176
+ positionResult.index = i;
10177
+ positionResult.trIndex = prevElement.trList.indexOf(rootTr);
10178
+ positionResult.tdIndex = rootTr.tdList.indexOf(rootTd);
10179
+ positionResult.trId = rootTr.id;
10180
+ positionResult.tdId = rootTd.id;
10181
+ positionResult.tableId = prevElement.id;
10182
+ positionResult.tdValueIndex = 0;
10183
+ }
10184
+ break;
10185
+ }
10186
+ }
10187
+ }
10188
+ }
10189
+ }
10190
+ }
10191
+ }
9942
10192
  const {
9943
10193
  index,
9944
10194
  isCheckbox,
@@ -10035,6 +10285,18 @@ var RangeManager = class {
10035
10285
  clearRange() {
10036
10286
  this.setRange(-1, -1);
10037
10287
  }
10288
+ getSplitCellSelection() {
10289
+ return this.range.splitCellSelection;
10290
+ }
10291
+ setSplitCellSelection(payload) {
10292
+ this.range.splitCellSelection = payload || void 0;
10293
+ }
10294
+ getTableCellSelection() {
10295
+ return this.range.tableCellSelection;
10296
+ }
10297
+ setTableCellSelection(payload) {
10298
+ this.range.tableCellSelection = payload || void 0;
10299
+ }
10038
10300
  setDefaultStyle(style) {
10039
10301
  if (!style) {
10040
10302
  this.defaultStyle = null;
@@ -10325,6 +10587,8 @@ var RangeManager = class {
10325
10587
  this.range.isCrossRowCol = !!(startTdIndex || endTdIndex || startTrIndex || endTrIndex);
10326
10588
  this.setDefaultStyle(null);
10327
10589
  }
10590
+ this.range.splitCellSelection = void 0;
10591
+ this.range.tableCellSelection = void 0;
10328
10592
  this.range.zone = this.draw.getZone().getZone();
10329
10593
  const control = this.draw.getControl();
10330
10594
  if (~startIndex && ~endIndex) {
@@ -11655,13 +11919,18 @@ var TableParticle = class {
11655
11919
  ctx.beginPath();
11656
11920
  const x = Math.round(startX);
11657
11921
  const y = Math.round(startY);
11922
+ const rx = Math.round(startX + width);
11923
+ const ry = Math.round(startY + height);
11658
11924
  ctx.translate(0.5, 0.5);
11659
11925
  if (isDrawFullBorder) {
11660
- ctx.rect(x, y, width, height);
11926
+ ctx.rect(x, y, rx - x, ry - y);
11927
+ } else if (borderExternalWidth) {
11928
+ ctx.moveTo(x, ry);
11929
+ ctx.lineTo(x, y);
11930
+ ctx.lineTo(rx, y);
11661
11931
  } else {
11662
- ctx.moveTo(x, y + height);
11932
+ ctx.moveTo(x, ry);
11663
11933
  ctx.lineTo(x, y);
11664
- ctx.lineTo(x + width, y);
11665
11934
  }
11666
11935
  ctx.stroke();
11667
11936
  if (borderExternalWidth) {
@@ -11669,20 +11938,32 @@ var TableParticle = class {
11669
11938
  }
11670
11939
  ctx.translate(-0.5, -0.5);
11671
11940
  }
11941
+ _drawHorizontalBorder(payload) {
11942
+ const { ctx, startX, endX, y } = payload;
11943
+ const x = Math.round(startX);
11944
+ const rx = Math.round(endX);
11945
+ const ty = Math.round(y);
11946
+ ctx.beginPath();
11947
+ ctx.translate(0.5, 0.5);
11948
+ ctx.moveTo(x, ty);
11949
+ ctx.lineTo(rx, ty);
11950
+ ctx.stroke();
11951
+ ctx.translate(-0.5, -0.5);
11952
+ }
11672
11953
  _drawSlash(ctx, td, startX, startY) {
11673
11954
  const { scale } = this.options;
11674
11955
  ctx.save();
11675
- const width = td.width * scale;
11676
- const height = td.height * scale;
11677
- const x = Math.round(td.x * scale + startX);
11678
- const y = Math.round(td.y * scale + startY);
11956
+ const lx = Math.round(td.x * scale + startX);
11957
+ const ty = Math.round(td.y * scale + startY);
11958
+ const rx = Math.round((td.x + td.width) * scale + startX);
11959
+ const by = Math.round((td.y + td.height) * scale + startY);
11679
11960
  if (td.slashTypes?.includes("forward" /* FORWARD */)) {
11680
- ctx.moveTo(x + width, y);
11681
- ctx.lineTo(x, y + height);
11961
+ ctx.moveTo(rx, ty);
11962
+ ctx.lineTo(lx, by);
11682
11963
  }
11683
11964
  if (td.slashTypes?.includes("back" /* BACK */)) {
11684
- ctx.moveTo(x, y);
11685
- ctx.lineTo(x + width, y + height);
11965
+ ctx.moveTo(lx, ty);
11966
+ ctx.lineTo(rx, by);
11686
11967
  }
11687
11968
  ctx.stroke();
11688
11969
  ctx.restore();
@@ -11723,6 +12004,8 @@ var TableParticle = class {
11723
12004
  isDrawFullBorder: isExternalBorderType
11724
12005
  });
11725
12006
  }
12007
+ const firstTr = trList[0];
12008
+ const lastTr = trList[trList.length - 1];
11726
12009
  for (let t = 0; t < trList.length; t++) {
11727
12010
  const tr = trList[t];
11728
12011
  for (let d = 0; d < tr.tdList.length; d++) {
@@ -11733,10 +12016,10 @@ var TableParticle = class {
11733
12016
  if (!td.borderTypes?.length && (isEmptyBorderType || isExternalBorderType)) {
11734
12017
  continue;
11735
12018
  }
11736
- const width = td.width * scale;
11737
- const height = td.height * scale;
11738
- const x = Math.round(td.x * scale + startX + width);
11739
- const y = Math.round(td.y * scale + startY);
12019
+ const lx = Math.round(td.x * scale + startX);
12020
+ const ty = Math.round(td.y * scale + startY);
12021
+ const rx = Math.round((td.x + td.width) * scale + startX);
12022
+ const by = Math.round((td.y + td.height) * scale + startY);
11740
12023
  if (td.borderColor) {
11741
12024
  ctx.save();
11742
12025
  ctx.strokeStyle = td.borderColor;
@@ -11744,29 +12027,33 @@ var TableParticle = class {
11744
12027
  ctx.translate(0.5, 0.5);
11745
12028
  ctx.beginPath();
11746
12029
  if (td.borderTypes?.includes("top" /* TOP */)) {
11747
- ctx.moveTo(x - width, y);
11748
- ctx.lineTo(x, y);
12030
+ ctx.moveTo(lx, ty);
12031
+ ctx.lineTo(rx, ty);
11749
12032
  ctx.stroke();
11750
12033
  }
11751
12034
  if (td.borderTypes?.includes("right" /* RIGHT */)) {
11752
- ctx.moveTo(x, y);
11753
- ctx.lineTo(x, y + height);
12035
+ ctx.moveTo(rx, ty);
12036
+ ctx.lineTo(rx, by);
11754
12037
  ctx.stroke();
11755
12038
  }
11756
12039
  if (td.borderTypes?.includes("bottom" /* BOTTOM */)) {
11757
- ctx.moveTo(x, y + height);
11758
- ctx.lineTo(x - width, y + height);
12040
+ ctx.moveTo(rx, by);
12041
+ ctx.lineTo(lx, by);
11759
12042
  ctx.stroke();
11760
12043
  }
11761
12044
  if (td.borderTypes?.includes("left" /* LEFT */)) {
11762
- ctx.moveTo(x - width, y);
11763
- ctx.lineTo(x - width, y + height);
12045
+ ctx.moveTo(lx, ty);
12046
+ ctx.lineTo(lx, by);
11764
12047
  ctx.stroke();
11765
12048
  }
11766
12049
  if (!isEmptyBorderType && !isExternalBorderType) {
12050
+ if (td.rowIndex === 0 && !borderExternalWidth) {
12051
+ ctx.moveTo(lx, ty);
12052
+ ctx.lineTo(rx, ty);
12053
+ }
11767
12054
  if (!isInternalBorderType || td.colIndex + td.colspan < colgroup.length) {
11768
- ctx.moveTo(x, y);
11769
- ctx.lineTo(x, y + height);
12055
+ ctx.moveTo(rx, ty);
12056
+ ctx.lineTo(rx, by);
11770
12057
  if (borderExternalWidth && borderExternalWidth !== borderWidth && td.colIndex + td.colspan === colgroup.length) {
11771
12058
  const lineWidth = ctx.lineWidth;
11772
12059
  ctx.lineWidth = borderExternalWidth * scale;
@@ -11776,13 +12063,14 @@ var TableParticle = class {
11776
12063
  }
11777
12064
  }
11778
12065
  if (!isInternalBorderType || td.rowIndex + td.rowspan < trList.length) {
11779
- const isSetExternalBottomBorder = borderExternalWidth && borderExternalWidth !== borderWidth && td.rowIndex + td.rowspan === trList.length;
12066
+ const isBottomEdge = td.rowIndex + td.rowspan === trList.length;
12067
+ const isSetExternalBottomBorder = borderExternalWidth && borderExternalWidth !== borderWidth && isBottomEdge;
11780
12068
  if (isSetExternalBottomBorder) {
11781
12069
  ctx.stroke();
11782
12070
  ctx.beginPath();
11783
12071
  }
11784
- ctx.moveTo(x, y + height);
11785
- ctx.lineTo(x - width, y + height);
12072
+ ctx.moveTo(rx, by);
12073
+ ctx.lineTo(lx, by);
11786
12074
  if (isSetExternalBottomBorder) {
11787
12075
  const lineWidth = ctx.lineWidth;
11788
12076
  ctx.lineWidth = borderExternalWidth * scale;
@@ -11798,12 +12086,12 @@ var TableParticle = class {
11798
12086
  ctx.translate(0.5, 0.5);
11799
12087
  ctx.beginPath();
11800
12088
  if (td.rowIndex === 0) {
11801
- ctx.moveTo(x - width, y);
11802
- ctx.lineTo(x, y);
12089
+ ctx.moveTo(lx, ty);
12090
+ ctx.lineTo(rx, ty);
11803
12091
  }
11804
12092
  if (td.colIndex === 0) {
11805
- ctx.moveTo(x - width, y);
11806
- ctx.lineTo(x - width, y + height);
12093
+ ctx.moveTo(lx, ty);
12094
+ ctx.lineTo(lx, by);
11807
12095
  }
11808
12096
  if (td.rowIndex === 0 || td.colIndex === 0) {
11809
12097
  ctx.stroke();
@@ -11815,6 +12103,22 @@ var TableParticle = class {
11815
12103
  }
11816
12104
  }
11817
12105
  }
12106
+ if (!isEmptyBorderType && !isExternalBorderType && !borderExternalWidth && firstTr?.splitBoundaryTop) {
12107
+ this._drawHorizontalBorder({
12108
+ ctx,
12109
+ startX,
12110
+ endX: startX + tableWidth,
12111
+ y: startY
12112
+ });
12113
+ }
12114
+ if (!isEmptyBorderType && !isExternalBorderType && !borderExternalWidth && lastTr?.splitBoundaryBottom) {
12115
+ this._drawHorizontalBorder({
12116
+ ctx,
12117
+ startX,
12118
+ endX: startX + tableWidth,
12119
+ y: startY + tableHeight
12120
+ });
12121
+ }
11818
12122
  ctx.restore();
11819
12123
  }
11820
12124
  _drawBackgroundColor(ctx, element, startX, startY) {
@@ -11827,12 +12131,12 @@ var TableParticle = class {
11827
12131
  const td = tr.tdList[d];
11828
12132
  if (!td.backgroundColor) continue;
11829
12133
  ctx.save();
11830
- const width = td.width * scale;
11831
- const height = td.height * scale;
11832
- const x = Math.round(td.x * scale + startX);
11833
- const y = Math.round(td.y * scale + startY);
12134
+ const lx = Math.round(td.x * scale + startX);
12135
+ const ty = Math.round(td.y * scale + startY);
12136
+ const rx = Math.round((td.x + td.width) * scale + startX);
12137
+ const by = Math.round((td.y + td.height) * scale + startY);
11834
12138
  ctx.fillStyle = td.backgroundColor;
11835
- ctx.fillRect(x, y, width, height);
12139
+ ctx.fillRect(lx, ty, rx - lx, by - ty);
11836
12140
  ctx.restore();
11837
12141
  }
11838
12142
  }
@@ -12007,6 +12311,44 @@ var TableParticle = class {
12007
12311
  }
12008
12312
  ctx.restore();
12009
12313
  }
12314
+ _isSelectedCell(element, tr, td, selection) {
12315
+ if (selection.pagingId && selection.rootTrId && selection.colIndex !== void 0) {
12316
+ return element.pagingId === selection.pagingId && (tr.id === selection.rootTrId || tr.splitRootId === selection.rootTrId) && td.colIndex === selection.colIndex;
12317
+ }
12318
+ if (selection.tableId && element.id !== selection.tableId) {
12319
+ return false;
12320
+ }
12321
+ if (selection.trId && tr.id !== selection.trId) {
12322
+ return false;
12323
+ }
12324
+ if (selection.tdId) {
12325
+ return td.id === selection.tdId;
12326
+ }
12327
+ return false;
12328
+ }
12329
+ drawCellRange(ctx, element, startX, startY, selection) {
12330
+ const { scale, rangeAlpha, rangeColor } = this.options;
12331
+ const { type, trList } = element;
12332
+ if (!trList || type !== "table" /* TABLE */) return;
12333
+ ctx.save();
12334
+ ctx.globalAlpha = rangeAlpha;
12335
+ ctx.fillStyle = rangeColor;
12336
+ for (let t = 0; t < trList.length; t++) {
12337
+ const tr = trList[t];
12338
+ for (let d = 0; d < tr.tdList.length; d++) {
12339
+ const td = tr.tdList[d];
12340
+ if (!this._isSelectedCell(element, tr, td, selection)) {
12341
+ continue;
12342
+ }
12343
+ const x = td.x * scale;
12344
+ const y = td.y * scale;
12345
+ const width = td.width * scale;
12346
+ const height = td.height * scale;
12347
+ ctx.fillRect(x + startX, y + startY, width, height);
12348
+ }
12349
+ }
12350
+ ctx.restore();
12351
+ }
12010
12352
  render(ctx, element, startX, startY) {
12011
12353
  this._drawBackgroundColor(ctx, element, startX, startY);
12012
12354
  this._drawBorder(ctx, element, startX, startY);
@@ -15242,7 +15584,12 @@ var Control = class {
15242
15584
  let element;
15243
15585
  const newIndex = position.isTable ? tdValueIndex : index;
15244
15586
  if (position.isTable) {
15245
- elementList = elementList[index].trList[trIndex].tdList[tdIndex].value;
15587
+ elementList = this.draw.resolveTableCellContext(elementList, {
15588
+ isTable: true,
15589
+ index,
15590
+ trIndex,
15591
+ tdIndex
15592
+ })?.td.value || [];
15246
15593
  element = elementList[tdValueIndex];
15247
15594
  } else {
15248
15595
  element = elementList[index];
@@ -16506,17 +16853,14 @@ function computeValue(data2, options) {
16506
16853
  const { extraPickAttrs = [] } = options || {};
16507
16854
  return {
16508
16855
  header: zipElementList(data2.header, {
16509
- extraPickAttrs,
16510
- isClone: false
16856
+ extraPickAttrs
16511
16857
  }),
16512
16858
  main: zipElementList(data2.main, {
16513
16859
  extraPickAttrs,
16514
- isClassifyArea: true,
16515
- isClone: false
16860
+ isClassifyArea: true
16516
16861
  }),
16517
16862
  footer: zipElementList(data2.footer, {
16518
- extraPickAttrs,
16519
- isClone: false
16863
+ extraPickAttrs
16520
16864
  })
16521
16865
  };
16522
16866
  }
@@ -18555,6 +18899,38 @@ var ListParticle = class {
18555
18899
  const level = element.listLevel ?? 0;
18556
18900
  return level * INDENT_PER_LEVEL * scale;
18557
18901
  }
18902
+ _getListMarkerStyleElement(elementList, startIndex = 0) {
18903
+ const startElement = elementList[startIndex];
18904
+ for (let i = startIndex + 1; i < elementList.length; i++) {
18905
+ const element = elementList[i];
18906
+ if (element.value === ZERO && !element.listWrap) {
18907
+ break;
18908
+ }
18909
+ if (element.type === "tab" /* TAB */) {
18910
+ continue;
18911
+ }
18912
+ if (element.value !== ZERO || element.type) {
18913
+ return element;
18914
+ }
18915
+ }
18916
+ return startElement;
18917
+ }
18918
+ _getListMarkerText(element, listIndex) {
18919
+ if (element.listStyle === "checkbox" /* CHECKBOX */) {
18920
+ return "";
18921
+ }
18922
+ if (element.listType === "ul" /* UL */) {
18923
+ if (element.listPreset) {
18924
+ return this._getUlBulletForLevel(element);
18925
+ }
18926
+ return ulStyleMapping[element.listStyle] || ulStyleMapping["disc" /* DISC */];
18927
+ }
18928
+ if (element.listPreset) {
18929
+ const olStyle = this._getOlStyleForLevel(element);
18930
+ return formatOlNumber(listIndex, olStyle);
18931
+ }
18932
+ return `${listIndex + 1}${"." /* PERIOD */}`;
18933
+ }
18558
18934
  computeListStyle(ctx, elementList) {
18559
18935
  const listStyleMap = /* @__PURE__ */ new Map();
18560
18936
  let start = 0;
@@ -18585,23 +18961,40 @@ var ListParticle = class {
18585
18961
  }
18586
18962
  getListStyleWidth(ctx, listElementList) {
18587
18963
  const { scale, checkbox } = this.options;
18588
- const startElement = listElementList[0];
18589
- if (startElement.listStyle && startElement.listStyle !== "decimal" /* DECIMAL */) {
18590
- if (startElement.listStyle === "checkbox" /* CHECKBOX */) {
18591
- return (checkbox.width + this.LIST_GAP) * scale;
18964
+ let maxWidth = 0;
18965
+ let listIndex = 0;
18966
+ for (let i = 0; i < listElementList.length; i++) {
18967
+ const element = listElementList[i];
18968
+ if (element.value !== ZERO || element.listWrap) continue;
18969
+ if (element.listStyle === "checkbox" /* CHECKBOX */) {
18970
+ maxWidth = Math.max(maxWidth, checkbox.width + this.LIST_GAP);
18971
+ listIndex++;
18972
+ continue;
18592
18973
  }
18593
- return this.UN_COUNT_STYLE_WIDTH * scale;
18594
- }
18595
- const count = listElementList.reduce((pre, cur) => {
18596
- if (cur.value === ZERO) {
18597
- pre += 1;
18974
+ const markerStyleElement = this._getListMarkerStyleElement(
18975
+ listElementList,
18976
+ i
18977
+ );
18978
+ const text = this._getListMarkerText(element, listIndex);
18979
+ if (!text) {
18980
+ listIndex++;
18981
+ continue;
18598
18982
  }
18599
- return pre;
18600
- }, 0);
18601
- if (!count) return 0;
18602
- const text = `${this.MEASURE_BASE_TEXT.repeat(String(count).length)}${"." /* PERIOD */}`;
18603
- const textMetrics = ctx.measureText(text);
18604
- return Math.ceil((textMetrics.width + this.LIST_GAP) * scale);
18983
+ ctx.save();
18984
+ ctx.font = this.draw.getElementFont(markerStyleElement);
18985
+ const textMetrics = ctx.measureText(text);
18986
+ ctx.restore();
18987
+ maxWidth = Math.max(maxWidth, textMetrics.width + this.LIST_GAP);
18988
+ listIndex++;
18989
+ }
18990
+ if (maxWidth > 0) {
18991
+ return Math.ceil(maxWidth * scale);
18992
+ }
18993
+ const startElement = listElementList[0];
18994
+ if (startElement?.listStyle === "checkbox" /* CHECKBOX */) {
18995
+ return (checkbox.width + this.LIST_GAP) * scale;
18996
+ }
18997
+ return this.UN_COUNT_STYLE_WIDTH * scale;
18605
18998
  }
18606
18999
  _getOlStyleForLevel(element) {
18607
19000
  const preset = element.listPreset || "olDefault" /* DEFAULT */;
@@ -18622,7 +19015,7 @@ var ListParticle = class {
18622
19015
  const startElement = elementList[0];
18623
19016
  if (startElement.value !== ZERO || startElement.listWrap) return;
18624
19017
  let tabWidth = 0;
18625
- const { defaultTabWidth, scale, defaultFont, defaultSize } = this.options;
19018
+ const { defaultTabWidth, scale } = this.options;
18626
19019
  for (let i = 1; i < elementList.length; i++) {
18627
19020
  const element = elementList[i];
18628
19021
  if (element?.type !== "tab" /* TAB */) break;
@@ -18660,24 +19053,11 @@ var ListParticle = class {
18660
19053
  }
18661
19054
  });
18662
19055
  } else {
18663
- let text = "";
18664
- if (startElement.listType === "ul" /* UL */) {
18665
- if (startElement.listPreset) {
18666
- text = this._getUlBulletForLevel(startElement);
18667
- } else {
18668
- text = ulStyleMapping[startElement.listStyle] || ulStyleMapping["disc" /* DISC */];
18669
- }
18670
- } else {
18671
- if (startElement.listPreset) {
18672
- const olStyle = this._getOlStyleForLevel(startElement);
18673
- text = formatOlNumber(listIndex, olStyle);
18674
- } else {
18675
- text = `${listIndex + 1}${"." /* PERIOD */}`;
18676
- }
18677
- }
19056
+ const text = this._getListMarkerText(startElement, listIndex);
18678
19057
  if (!text) return;
19058
+ const markerStyleElement = this._getListMarkerStyleElement(elementList);
18679
19059
  ctx.save();
18680
- ctx.font = `${defaultSize * (96 / 72) * scale}px ${defaultFont}`;
19060
+ ctx.font = this.draw.getElementFont(markerStyleElement, scale);
18681
19061
  ctx.fillText(text, x, y);
18682
19062
  ctx.restore();
18683
19063
  }
@@ -19127,6 +19507,39 @@ var TableOperate = class {
19127
19507
  this.tableParticle = draw.getTableParticle();
19128
19508
  this.options = draw.getOptions();
19129
19509
  }
19510
+ getActiveTableElements() {
19511
+ const positionContext = this.position.getPositionContext();
19512
+ if (!positionContext.isTable) return [];
19513
+ const originalElementList = this.draw.getOriginalElementList();
19514
+ const element = originalElementList[positionContext.index];
19515
+ if (!element || element.type !== "table" /* TABLE */) return [];
19516
+ if (!element.pagingId) return [element];
19517
+ return originalElementList.filter(
19518
+ (item) => item.type === "table" /* TABLE */ && item.pagingId === element.pagingId
19519
+ );
19520
+ }
19521
+ getSplitCellStyleSelection() {
19522
+ const tableCellSelection = this.range.getTableCellSelection();
19523
+ if (tableCellSelection?.pagingId && tableCellSelection.rootTrId && tableCellSelection.colIndex !== void 0) {
19524
+ return tableCellSelection;
19525
+ }
19526
+ return this.range.getSplitCellSelection();
19527
+ }
19528
+ getStyleTargetRowCol() {
19529
+ const splitCellSelection = this.getSplitCellStyleSelection();
19530
+ if (splitCellSelection) {
19531
+ const splitCellContext = this.draw.getSplitCellSelectionContext(
19532
+ this.draw.getOriginalElementList(),
19533
+ splitCellSelection
19534
+ );
19535
+ if (splitCellContext) {
19536
+ return splitCellContext.cellContextList.map((cellContext) => [
19537
+ cellContext.td
19538
+ ]);
19539
+ }
19540
+ }
19541
+ return this.tableParticle.getRangeRowCol();
19542
+ }
19130
19543
  insertTable(row, col) {
19131
19544
  const { startIndex, endIndex } = this.range.getRange();
19132
19545
  if (!~startIndex && !~endIndex) return;
@@ -19807,7 +20220,7 @@ var TableOperate = class {
19807
20220
  this.tableTool.render();
19808
20221
  }
19809
20222
  tableTdVerticalAlign(payload) {
19810
- const rowCol = this.tableParticle.getRangeRowCol();
20223
+ const rowCol = this.getStyleTargetRowCol();
19811
20224
  if (!rowCol) return;
19812
20225
  for (let r = 0; r < rowCol.length; r++) {
19813
20226
  const row = rowCol[r];
@@ -19827,13 +20240,17 @@ var TableOperate = class {
19827
20240
  tableBorderType(payload) {
19828
20241
  const positionContext = this.position.getPositionContext();
19829
20242
  if (!positionContext.isTable) return;
19830
- const { index } = positionContext;
19831
- const originalElementList = this.draw.getOriginalElementList();
19832
- const element = originalElementList[index];
19833
- if (!element.borderType && payload === "all" /* ALL */ || element.borderType === payload) {
20243
+ const tableElements = this.getActiveTableElements();
20244
+ if (!tableElements.length) return;
20245
+ const isAllSame = tableElements.every(
20246
+ (element) => !element.borderType && payload === "all" /* ALL */ || element.borderType === payload
20247
+ );
20248
+ if (isAllSame) {
19834
20249
  return;
19835
20250
  }
19836
- element.borderType = payload;
20251
+ tableElements.forEach((element) => {
20252
+ element.borderType = payload;
20253
+ });
19837
20254
  const { endIndex } = this.range.getRange();
19838
20255
  this.draw.render({
19839
20256
  curIndex: endIndex
@@ -19842,13 +20259,17 @@ var TableOperate = class {
19842
20259
  tableBorderColor(payload) {
19843
20260
  const positionContext = this.position.getPositionContext();
19844
20261
  if (!positionContext.isTable) return;
19845
- const { index } = positionContext;
19846
- const originalElementList = this.draw.getOriginalElementList();
19847
- const element = originalElementList[index];
19848
- if (!element.borderColor && payload === this.options.table.defaultBorderColor || element.borderColor === payload) {
20262
+ const tableElements = this.getActiveTableElements();
20263
+ if (!tableElements.length) return;
20264
+ const isAllSame = tableElements.every(
20265
+ (element) => !element.borderColor && payload === this.options.table.defaultBorderColor || element.borderColor === payload
20266
+ );
20267
+ if (isAllSame) {
19849
20268
  return;
19850
20269
  }
19851
- element.borderColor = payload;
20270
+ tableElements.forEach((element) => {
20271
+ element.borderColor = payload;
20272
+ });
19852
20273
  const { endIndex } = this.range.getRange();
19853
20274
  this.draw.render({
19854
20275
  curIndex: endIndex,
@@ -19856,7 +20277,7 @@ var TableOperate = class {
19856
20277
  });
19857
20278
  }
19858
20279
  tableTdBorderType(payload) {
19859
- const rowCol = this.tableParticle.getRangeRowCol();
20280
+ const rowCol = this.getStyleTargetRowCol();
19860
20281
  if (!rowCol) return;
19861
20282
  const tdList = rowCol.flat();
19862
20283
  const isSetBorderType = tdList.some(
@@ -19888,7 +20309,7 @@ var TableOperate = class {
19888
20309
  });
19889
20310
  }
19890
20311
  tableTdSlashType(payload) {
19891
- const rowCol = this.tableParticle.getRangeRowCol();
20312
+ const rowCol = this.getStyleTargetRowCol();
19892
20313
  if (!rowCol) return;
19893
20314
  const tdList = rowCol.flat();
19894
20315
  const isSetTdSlashType = tdList.some(
@@ -19918,7 +20339,7 @@ var TableOperate = class {
19918
20339
  });
19919
20340
  }
19920
20341
  tableTdBackgroundColor(payload) {
19921
- const rowCol = this.tableParticle.getRangeRowCol();
20342
+ const rowCol = this.getStyleTargetRowCol();
19922
20343
  if (!rowCol) return;
19923
20344
  for (let r = 0; r < rowCol.length; r++) {
19924
20345
  const row = rowCol[r];
@@ -19939,14 +20360,14 @@ var TableOperate = class {
19939
20360
  const { index } = positionContext;
19940
20361
  const originalElementList = this.draw.getOriginalElementList();
19941
20362
  const element = originalElementList[index];
19942
- const rowCol = this.tableParticle.getRangeRowCol();
20363
+ const rowCol = this.getStyleTargetRowCol();
19943
20364
  if (!rowCol) return;
19944
20365
  const tdList = rowCol.flat();
19945
20366
  const totalCells = element.trList.reduce(
19946
20367
  (sum, tr) => sum + tr.tdList.length,
19947
20368
  0
19948
20369
  );
19949
- const allSelected = tdList.length >= totalCells;
20370
+ const allSelected = !element.pagingId && !this.getSplitCellStyleSelection() && tdList.length >= totalCells;
19950
20371
  if (allSelected) {
19951
20372
  element.borderColor = payload || void 0;
19952
20373
  element.trList.forEach(
@@ -19966,7 +20387,7 @@ var TableOperate = class {
19966
20387
  });
19967
20388
  }
19968
20389
  tableTdPadding(payload) {
19969
- const rowCol = this.tableParticle.getRangeRowCol();
20390
+ const rowCol = this.getStyleTargetRowCol();
19970
20391
  if (!rowCol) return;
19971
20392
  const tdList = rowCol.flat();
19972
20393
  tdList.forEach((td) => {
@@ -20001,6 +20422,46 @@ var TableOperate = class {
20001
20422
  isSubmitHistory: false
20002
20423
  });
20003
20424
  }
20425
+ tableTdSelectAll() {
20426
+ const originalElementList = this.draw.getOriginalElementList();
20427
+ const resolved = this.draw.resolveTableCellContext(originalElementList);
20428
+ if (!resolved) return;
20429
+ const currentTr = resolved.element.trList?.[resolved.trIndex];
20430
+ if (!currentTr) return;
20431
+ const currentTd = resolved.td;
20432
+ const currentElement = resolved.element;
20433
+ const splitCellSelection = currentElement.pagingId && currentTr.id && currentTd.colIndex !== void 0 ? {
20434
+ pagingId: currentElement.pagingId,
20435
+ rootTrId: currentTr.splitRootId || currentTr.id,
20436
+ colIndex: currentTd.colIndex
20437
+ } : void 0;
20438
+ const splitCellSelectionContext = this.draw.getSplitCellSelectionContext(
20439
+ originalElementList,
20440
+ splitCellSelection
20441
+ );
20442
+ if (splitCellSelectionContext) {
20443
+ const endIndex = Math.max(
20444
+ splitCellSelectionContext.positionList.length - 1,
20445
+ 0
20446
+ );
20447
+ this.range.setRange(0, endIndex);
20448
+ this.range.setSplitCellSelection(splitCellSelection);
20449
+ this.range.setTableCellSelection(splitCellSelection);
20450
+ } else {
20451
+ const endIndex = Math.max(currentTd.value.length - 1, 0);
20452
+ this.range.setRange(0, endIndex);
20453
+ this.range.setTableCellSelection({
20454
+ tableId: currentElement.id,
20455
+ trId: currentTr.id,
20456
+ tdId: currentTd.id
20457
+ });
20458
+ }
20459
+ this.draw.render({
20460
+ isSetCursor: false,
20461
+ isCompute: false,
20462
+ isSubmitHistory: false
20463
+ });
20464
+ }
20004
20465
  };
20005
20466
 
20006
20467
  // src/dataset/enum/Area.ts
@@ -20495,6 +20956,7 @@ var Draw = class {
20495
20956
  this.intersectionPageNo = 0;
20496
20957
  this.lazyRenderIntersectionObserver = null;
20497
20958
  this.printModeData = null;
20959
+ this.pendingTableCursorIndex = void 0;
20498
20960
  if (this.mode === "print" /* PRINT */) {
20499
20961
  this.setPrintData();
20500
20962
  }
@@ -20656,9 +21118,8 @@ var Draw = class {
20656
21118
  getContextInnerWidth() {
20657
21119
  const positionContext = this.position.getPositionContext();
20658
21120
  if (positionContext.isTable) {
20659
- const { index, trIndex, tdIndex } = positionContext;
20660
- const elementList = this.getOriginalElementList();
20661
- const td = elementList[index].trList[trIndex].tdList[tdIndex];
21121
+ const td = this.resolveTableCellContext(this.getOriginalElementList())?.td;
21122
+ if (!td) return this.getColumnWidth() / this.options.scale;
20662
21123
  const tdPadding = this.getTdPadding();
20663
21124
  return td.width - tdPadding[1] - tdPadding[3];
20664
21125
  }
@@ -20742,6 +21203,56 @@ var Draw = class {
20742
21203
  getPage(pageNo = -1) {
20743
21204
  return this.pageList[~pageNo ? pageNo : this.pageNo];
20744
21205
  }
21206
+ resolveTableCellContext(sourceElementList = this.getOriginalElementList(), context = this.position.getPositionContext()) {
21207
+ if (!context.isTable) return null;
21208
+ const candidateIndexes = [];
21209
+ if (context.index !== void 0 && sourceElementList[context.index]?.type === "table" /* TABLE */) {
21210
+ candidateIndexes.push(context.index);
21211
+ }
21212
+ if (context.tableId) {
21213
+ const tableIndex = sourceElementList.findIndex((el) => el.id === context.tableId);
21214
+ if (~tableIndex && !candidateIndexes.includes(tableIndex)) {
21215
+ candidateIndexes.push(tableIndex);
21216
+ }
21217
+ }
21218
+ for (let i = 0; i < sourceElementList.length; i++) {
21219
+ const element = sourceElementList[i];
21220
+ if (element.type !== "table" /* TABLE */ || candidateIndexes.includes(i)) {
21221
+ continue;
21222
+ }
21223
+ candidateIndexes.push(i);
21224
+ }
21225
+ for (const tableIndex of candidateIndexes) {
21226
+ const element = sourceElementList[tableIndex];
21227
+ const trList = element.trList;
21228
+ if (!trList?.length) continue;
21229
+ let resolvedTrIndex = -1;
21230
+ if (context.trId) {
21231
+ resolvedTrIndex = trList.findIndex((tr) => tr.id === context.trId);
21232
+ }
21233
+ if (resolvedTrIndex < 0 && context.trIndex !== void 0 && trList[context.trIndex]) {
21234
+ resolvedTrIndex = context.trIndex;
21235
+ }
21236
+ if (resolvedTrIndex < 0) continue;
21237
+ const tdList = trList[resolvedTrIndex].tdList;
21238
+ let resolvedTdIndex = -1;
21239
+ if (context.tdId) {
21240
+ resolvedTdIndex = tdList.findIndex((td) => td.id === context.tdId);
21241
+ }
21242
+ if (resolvedTdIndex < 0 && context.tdIndex !== void 0 && tdList[context.tdIndex]) {
21243
+ resolvedTdIndex = context.tdIndex;
21244
+ }
21245
+ if (resolvedTdIndex < 0) continue;
21246
+ return {
21247
+ index: tableIndex,
21248
+ trIndex: resolvedTrIndex,
21249
+ tdIndex: resolvedTdIndex,
21250
+ element,
21251
+ td: tdList[resolvedTdIndex]
21252
+ };
21253
+ }
21254
+ return null;
21255
+ }
20745
21256
  getPageList() {
20746
21257
  return this.pageList;
20747
21258
  }
@@ -20749,9 +21260,7 @@ var Draw = class {
20749
21260
  return this.pageList.length;
20750
21261
  }
20751
21262
  getTableRowList(sourceElementList) {
20752
- const positionContext = this.position.getPositionContext();
20753
- const { index, trIndex, tdIndex } = positionContext;
20754
- return sourceElementList[index].trList[trIndex].tdList[tdIndex].rowList;
21263
+ return this.resolveTableCellContext(sourceElementList)?.td.rowList || [];
20755
21264
  }
20756
21265
  getOriginalRowList() {
20757
21266
  const zoneManager = this.getZone();
@@ -20810,9 +21319,155 @@ var Draw = class {
20810
21319
  return this.header.getElementList();
20811
21320
  }
20812
21321
  getTableElementList(sourceElementList) {
21322
+ const splitCellSelectionContext = this.getSplitCellSelectionContext(
21323
+ sourceElementList
21324
+ );
21325
+ if (splitCellSelectionContext) {
21326
+ return splitCellSelectionContext.value;
21327
+ }
21328
+ return this.resolveTableCellContext(sourceElementList)?.td.value || [];
21329
+ }
21330
+ getSplitCellSelectionContext(sourceElementList = this.getOriginalElementList(), splitCellSelection = this.range.getSplitCellSelection()) {
21331
+ if (!splitCellSelection) return null;
21332
+ const { pagingId, rootTrId, colIndex } = splitCellSelection;
21333
+ const cellContextList = [];
21334
+ for (let i = 0; i < sourceElementList.length; i++) {
21335
+ const element = sourceElementList[i];
21336
+ if (element.type !== "table" /* TABLE */ || element.pagingId !== pagingId) {
21337
+ continue;
21338
+ }
21339
+ const trList = element.trList;
21340
+ if (!trList?.length) continue;
21341
+ for (let t = 0; t < trList.length; t++) {
21342
+ const tr = trList[t];
21343
+ if (tr.id !== rootTrId && tr.splitRootId !== rootTrId) continue;
21344
+ const tdIndex = tr.tdList.findIndex((td2) => td2.colIndex === colIndex);
21345
+ if (tdIndex < 0) continue;
21346
+ const td = tr.tdList[tdIndex];
21347
+ cellContextList.push({
21348
+ tableIndex: i,
21349
+ trIndex: t,
21350
+ tdIndex,
21351
+ element,
21352
+ tr,
21353
+ td
21354
+ });
21355
+ }
21356
+ }
21357
+ if (cellContextList.length < 2) return null;
21358
+ const value = [];
21359
+ const positionList = [];
21360
+ for (let c = 0; c < cellContextList.length; c++) {
21361
+ const { td } = cellContextList[c];
21362
+ const skipLeadingZero = !!td.splitSyntheticLeadingZero && td.value[0]?.value === ZERO ? 1 : 0;
21363
+ value.push(...td.value.slice(skipLeadingZero));
21364
+ if (td.positionList?.length) {
21365
+ positionList.push(...td.positionList.slice(skipLeadingZero));
21366
+ }
21367
+ }
21368
+ return {
21369
+ value,
21370
+ positionList,
21371
+ cellContextList
21372
+ };
21373
+ }
21374
+ syncTableElementContext(elementList, context) {
21375
+ const { tableId, trId, tdId } = context;
21376
+ for (let i = 0; i < elementList.length; i++) {
21377
+ const element = elementList[i];
21378
+ element.tableId = tableId;
21379
+ element.trId = trId;
21380
+ element.tdId = tdId;
21381
+ }
21382
+ }
21383
+ getCollapsedSplitTableCursorContext(element) {
20813
21384
  const positionContext = this.position.getPositionContext();
20814
- const { index, trIndex, tdIndex } = positionContext;
20815
- return sourceElementList[index].trList?.[trIndex].tdList[tdIndex].value || [];
21385
+ const { startIndex, endIndex } = this.range.getRange();
21386
+ if (!element.pagingId || !positionContext.isTable || startIndex !== endIndex || positionContext.tableId !== element.id || !positionContext.trId) {
21387
+ return null;
21388
+ }
21389
+ const trList = element.trList;
21390
+ if (!trList?.length) return null;
21391
+ const currentTr = trList.find((tr) => tr.id === positionContext.trId);
21392
+ const currentTd = currentTr && (positionContext.tdId ? currentTr.tdList.find((td) => td.id === positionContext.tdId) : currentTr.tdList[positionContext.tdIndex]);
21393
+ if (!currentTr?.id || !currentTd || currentTd.colIndex === void 0) {
21394
+ return null;
21395
+ }
21396
+ const rootTrId = currentTr.splitRootId || currentTr.id;
21397
+ let mergedIndex = 0;
21398
+ for (let t = 0; t < trList.length; t++) {
21399
+ const tr = trList[t];
21400
+ if (tr.id !== rootTrId && tr.splitRootId !== rootTrId) {
21401
+ continue;
21402
+ }
21403
+ const td = tr.tdList.find((cell) => cell.colIndex === currentTd.colIndex);
21404
+ if (!td) continue;
21405
+ const skipLeadingZero = !!td.splitSyntheticLeadingZero && td.value[0]?.value === ZERO ? 1 : 0;
21406
+ if (tr.id === currentTr.id && td.id === currentTd.id) {
21407
+ mergedIndex += Math.max(startIndex - skipLeadingZero, 0);
21408
+ return {
21409
+ rootTrId,
21410
+ colIndex: currentTd.colIndex,
21411
+ mergedIndex
21412
+ };
21413
+ }
21414
+ mergedIndex += Math.max(td.value.length - skipLeadingZero, 0);
21415
+ }
21416
+ return null;
21417
+ }
21418
+ applyCollapsedSplitTableCursor(payload) {
21419
+ const {
21420
+ tableIndex,
21421
+ tableId,
21422
+ overflowTr,
21423
+ overflowTrIdx,
21424
+ continuationTr,
21425
+ continuationTdList,
21426
+ logicalCursor,
21427
+ splits
21428
+ } = payload;
21429
+ const tdIndex = overflowTr.tdList.findIndex(
21430
+ (td) => td.colIndex === logicalCursor.colIndex
21431
+ );
21432
+ if (tdIndex < 0) return false;
21433
+ const splitIdx = splits[tdIndex]?.elemIdx;
21434
+ if (splitIdx === void 0) return false;
21435
+ const positionContext = this.position.getPositionContext();
21436
+ if (logicalCursor.mergedIndex >= splitIdx) {
21437
+ const continuationTd = continuationTdList[tdIndex];
21438
+ if (!continuationTd) return false;
21439
+ const hasPrependedZero = !!continuationTd.splitSyntheticLeadingZero && continuationTd.value[0]?.value === ZERO;
21440
+ const continuationCursorIndex = logicalCursor.mergedIndex - splitIdx + (hasPrependedZero ? 1 : 0);
21441
+ positionContext.index = tableIndex;
21442
+ positionContext.trIndex = overflowTrIdx + 1;
21443
+ positionContext.tdIndex = tdIndex;
21444
+ positionContext.tdId = continuationTd.id;
21445
+ positionContext.trId = continuationTr.id;
21446
+ positionContext.tableId = tableId;
21447
+ this.position.setPositionContext(positionContext);
21448
+ this.range.setRange(
21449
+ continuationCursorIndex,
21450
+ continuationCursorIndex
21451
+ );
21452
+ this.pendingTableCursorIndex = continuationCursorIndex;
21453
+ return true;
21454
+ }
21455
+ const rootTd = overflowTr.tdList[tdIndex];
21456
+ if (!rootTd) return false;
21457
+ const rootCursorIndex = Math.min(
21458
+ logicalCursor.mergedIndex,
21459
+ Math.max(rootTd.value.length - 1, 0)
21460
+ );
21461
+ positionContext.index = tableIndex;
21462
+ positionContext.trIndex = overflowTrIdx;
21463
+ positionContext.tdIndex = tdIndex;
21464
+ positionContext.tdId = rootTd.id;
21465
+ positionContext.trId = overflowTr.id;
21466
+ positionContext.tableId = tableId;
21467
+ this.position.setPositionContext(positionContext);
21468
+ this.range.setRange(rootCursorIndex, rootCursorIndex);
21469
+ this.pendingTableCursorIndex = rootCursorIndex;
21470
+ return true;
20816
21471
  }
20817
21472
  getElementList() {
20818
21473
  const positionContext = this.position.getPositionContext();
@@ -20840,13 +21495,7 @@ var Draw = class {
20840
21495
  return this.footer.getElementList();
20841
21496
  }
20842
21497
  getTd() {
20843
- const positionContext = this.position.getPositionContext();
20844
- const { index, trIndex, tdIndex, isTable } = positionContext;
20845
- if (isTable) {
20846
- const elementList = this.getOriginalElementList();
20847
- return elementList[index].trList[trIndex].tdList[tdIndex];
20848
- }
20849
- return null;
21498
+ return this.resolveTableCellContext(this.getOriginalElementList())?.td || null;
20850
21499
  }
20851
21500
  insertElementList(payload, options = {}) {
20852
21501
  if (!payload.length || !this.range.getIsCanInput()) return;
@@ -20857,6 +21506,18 @@ var Draw = class {
20857
21506
  isHandleFirstElement: false,
20858
21507
  editorOptions: this.options
20859
21508
  });
21509
+ const splitCellSelection = this.range.getSplitCellSelection();
21510
+ if (splitCellSelection) {
21511
+ const curIndex2 = this.replaceSplitCellSelection(payload, splitCellSelection);
21512
+ if (~curIndex2) {
21513
+ this.range.setRange(curIndex2, curIndex2);
21514
+ this.render({
21515
+ curIndex: curIndex2,
21516
+ isSubmitHistory
21517
+ });
21518
+ }
21519
+ return;
21520
+ }
20860
21521
  let curIndex = -1;
20861
21522
  let activeControl = this.control.getActiveControl();
20862
21523
  if (!activeControl && this.control.getIsRangeWithinControl()) {
@@ -20952,6 +21613,80 @@ var Draw = class {
20952
21613
  }
20953
21614
  }
20954
21615
  }
21616
+ replaceSplitCellSelection(payload, splitCellSelection = this.range.getSplitCellSelection()) {
21617
+ const splitCellSelectionContext = this.getSplitCellSelectionContext(
21618
+ this.getOriginalElementList(),
21619
+ splitCellSelection
21620
+ );
21621
+ if (!splitCellSelectionContext) return -1;
21622
+ const [rootCellContext, ...continuationCellContextList] = splitCellSelectionContext.cellContextList;
21623
+ const rootTd = rootCellContext.td;
21624
+ const rootStartIndex = rootTd.value[0]?.value === ZERO ? 1 : 0;
21625
+ if (!rootStartIndex) {
21626
+ rootTd.value.unshift({
21627
+ value: ZERO,
21628
+ type: "text" /* TEXT */
21629
+ });
21630
+ this.syncTableElementContext([rootTd.value[0]], {
21631
+ tableId: rootCellContext.element.id,
21632
+ trId: rootCellContext.tr.id,
21633
+ tdId: rootTd.id
21634
+ });
21635
+ }
21636
+ this.syncTableElementContext(payload, {
21637
+ tableId: rootCellContext.element.id,
21638
+ trId: rootCellContext.tr.id,
21639
+ tdId: rootTd.id
21640
+ });
21641
+ this.spliceElementList(
21642
+ rootTd.value,
21643
+ 1,
21644
+ rootTd.value.length - 1,
21645
+ payload
21646
+ );
21647
+ rootTd.rowList = void 0;
21648
+ rootTd.positionList = void 0;
21649
+ rootTd.mainHeight = void 0;
21650
+ rootTd.realHeight = void 0;
21651
+ rootTd.realMinHeight = void 0;
21652
+ for (let c = 0; c < continuationCellContextList.length; c++) {
21653
+ const continuationTd = continuationCellContextList[c].td;
21654
+ const startIndex = continuationTd.value[0]?.value === ZERO ? 1 : 0;
21655
+ if (!startIndex) {
21656
+ continuationTd.value.unshift({
21657
+ value: ZERO,
21658
+ type: "text" /* TEXT */
21659
+ });
21660
+ this.syncTableElementContext([continuationTd.value[0]], {
21661
+ tableId: continuationCellContextList[c].element.id,
21662
+ trId: continuationCellContextList[c].tr.id,
21663
+ tdId: continuationTd.id
21664
+ });
21665
+ }
21666
+ if (continuationTd.value.length > 1) {
21667
+ this.spliceElementList(
21668
+ continuationTd.value,
21669
+ 1,
21670
+ continuationTd.value.length - 1
21671
+ );
21672
+ }
21673
+ continuationTd.rowList = void 0;
21674
+ continuationTd.positionList = void 0;
21675
+ continuationTd.mainHeight = void 0;
21676
+ continuationTd.realHeight = void 0;
21677
+ continuationTd.realMinHeight = void 0;
21678
+ }
21679
+ this.position.setPositionContext({
21680
+ isTable: true,
21681
+ index: rootCellContext.tableIndex,
21682
+ trIndex: rootCellContext.trIndex,
21683
+ tdIndex: rootCellContext.tdIndex,
21684
+ tdId: rootTd.id,
21685
+ trId: rootCellContext.tr.id,
21686
+ tableId: rootCellContext.element.id
21687
+ });
21688
+ return Math.max(rootTd.value.length - 1, 0);
21689
+ }
20955
21690
  getCanvasEvent() {
20956
21691
  return this.canvasEvent;
20957
21692
  }
@@ -21362,6 +22097,72 @@ var Draw = class {
21362
22097
  }
21363
22098
  return defaultBasicRowMarginHeight * ratio * (el.rowMargin ?? defaultRowMargin) * scale;
21364
22099
  }
22100
+ createListStateSeed(initialListState) {
22101
+ const listLevelIndex = /* @__PURE__ */ new Map();
22102
+ if (initialListState?.listLevelIndex) {
22103
+ Object.entries(initialListState.listLevelIndex).forEach(
22104
+ ([level, index]) => {
22105
+ listLevelIndex.set(Number(level), index);
22106
+ }
22107
+ );
22108
+ }
22109
+ return {
22110
+ listId: initialListState?.listId,
22111
+ listIndex: initialListState?.listIndex ?? 0,
22112
+ prevListLevel: initialListState?.prevListLevel ?? 0,
22113
+ listLevelIndex
22114
+ };
22115
+ }
22116
+ advanceListState(element, listState) {
22117
+ if (element.listId) {
22118
+ const curLevel = element.listLevel ?? 0;
22119
+ if (element.listId !== listState.listId) {
22120
+ listState.listIndex = 0;
22121
+ listState.listLevelIndex = /* @__PURE__ */ new Map();
22122
+ listState.listLevelIndex.set(curLevel, 0);
22123
+ listState.prevListLevel = curLevel;
22124
+ } else if (element.value === ZERO && !element.listWrap) {
22125
+ if (curLevel !== listState.prevListLevel) {
22126
+ if (curLevel > listState.prevListLevel) {
22127
+ listState.listLevelIndex.set(curLevel, 0);
22128
+ } else {
22129
+ for (const [lvl] of listState.listLevelIndex) {
22130
+ if (lvl > curLevel) {
22131
+ listState.listLevelIndex.delete(lvl);
22132
+ }
22133
+ }
22134
+ listState.listLevelIndex.set(
22135
+ curLevel,
22136
+ (listState.listLevelIndex.get(curLevel) ?? -1) + 1
22137
+ );
22138
+ }
22139
+ } else {
22140
+ listState.listLevelIndex.set(
22141
+ curLevel,
22142
+ (listState.listLevelIndex.get(curLevel) ?? -1) + 1
22143
+ );
22144
+ }
22145
+ listState.listIndex = listState.listLevelIndex.get(curLevel) ?? 0;
22146
+ listState.prevListLevel = curLevel;
22147
+ }
22148
+ }
22149
+ listState.listId = element.listId;
22150
+ }
22151
+ getListStateBeforeIndex(elementList, endExclusive) {
22152
+ const limit = Math.min(endExclusive, elementList.length);
22153
+ if (limit <= 0) return;
22154
+ const listState = this.createListStateSeed();
22155
+ for (let i = 0; i < limit; i++) {
22156
+ this.advanceListState(elementList[i], listState);
22157
+ }
22158
+ if (!listState.listId) return;
22159
+ return {
22160
+ listId: listState.listId,
22161
+ listIndex: listState.listIndex,
22162
+ prevListLevel: listState.prevListLevel,
22163
+ listLevelIndex: Object.fromEntries(listState.listLevelIndex)
22164
+ };
22165
+ }
21365
22166
  computeRowList(payload) {
21366
22167
  const {
21367
22168
  innerWidth,
@@ -21372,7 +22173,8 @@ var Draw = class {
21372
22173
  startY = 0,
21373
22174
  pageHeight = 0,
21374
22175
  mainOuterHeight = 0,
21375
- surroundElementList = []
22176
+ surroundElementList = [],
22177
+ initialListState
21376
22178
  } = payload;
21377
22179
  const {
21378
22180
  defaultSize,
@@ -21399,10 +22201,7 @@ var Draw = class {
21399
22201
  let x = startX;
21400
22202
  let y = startY;
21401
22203
  let pageNo = 0;
21402
- let listId;
21403
- let listIndex = 0;
21404
- let listLevelIndex = /* @__PURE__ */ new Map();
21405
- let prevListLevel = 0;
22204
+ const listState = this.createListStateSeed(initialListState);
21406
22205
  let controlRealWidth = 0;
21407
22206
  for (let i = 0; i < elementList.length; i++) {
21408
22207
  const curRow = rowList[rowList.length - 1];
@@ -21448,6 +22247,11 @@ var Draw = class {
21448
22247
  }
21449
22248
  metrics.boundingBoxAscent = 0;
21450
22249
  } else if (element.type === "table" /* TABLE */) {
22250
+ let activeSplitRange;
22251
+ let mergedSplitFallback;
22252
+ const logicalSplitCursor = this.getCollapsedSplitTableCursorContext(
22253
+ element
22254
+ );
21451
22255
  if (element.pagingId) {
21452
22256
  let tableIndex = i + 1;
21453
22257
  let combineCount = 0;
@@ -21468,11 +22272,66 @@ var Draw = class {
21468
22272
  if (combineCount) {
21469
22273
  elementList.splice(i + 1, combineCount);
21470
22274
  }
22275
+ const mergedTrList = element.trList;
22276
+ for (let t = mergedTrList.length - 1; t >= 0; t--) {
22277
+ const splitTr = mergedTrList[t];
22278
+ if (!splitTr.splitParentId) continue;
22279
+ const parentTrIdx = mergedTrList.findIndex(
22280
+ (r) => r.id === splitTr.splitParentId
22281
+ );
22282
+ if (!~parentTrIdx) continue;
22283
+ const parentTr = mergedTrList[parentTrIdx];
22284
+ const posCtx = this.position.getPositionContext();
22285
+ const { startIndex, endIndex } = this.range.getRange();
22286
+ if (posCtx.isTable && posCtx.trId === splitTr.id && startIndex === endIndex && posCtx.tdIndex !== void 0) {
22287
+ const splitTd = splitTr.tdList[posCtx.tdIndex];
22288
+ const parentTd = parentTr.tdList[posCtx.tdIndex];
22289
+ if (splitTd && parentTd) {
22290
+ const hasSyntheticLeadingZero = !!splitTd.splitSyntheticLeadingZero && splitTd.value[0]?.value === ZERO;
22291
+ const mergedIndex = parentTd.value.length + startIndex - (hasSyntheticLeadingZero ? 1 : 0);
22292
+ activeSplitRange = {
22293
+ tdIndex: posCtx.tdIndex,
22294
+ mergedIndex,
22295
+ trId: splitTr.id
22296
+ };
22297
+ mergedSplitFallback = {
22298
+ tdIndex: posCtx.tdIndex,
22299
+ mergedIndex,
22300
+ trId: splitTr.id,
22301
+ parentTrId: parentTr.id,
22302
+ parentTdId: parentTd.id,
22303
+ parentTrIndex: parentTrIdx
22304
+ };
22305
+ }
22306
+ }
22307
+ for (let d = 0; d < parentTr.tdList.length; d++) {
22308
+ const parentTd = parentTr.tdList[d];
22309
+ const splitTd = splitTr.tdList[d];
22310
+ if (!splitTd) continue;
22311
+ const hasSyntheticLeadingZero = !!splitTd.splitSyntheticLeadingZero && splitTd.value[0]?.value === ZERO;
22312
+ const splitValue = hasSyntheticLeadingZero ? splitTd.value.slice(1) : splitTd.value;
22313
+ this.syncTableElementContext(splitValue, {
22314
+ tableId: element.id,
22315
+ trId: parentTr.id,
22316
+ tdId: parentTd.id
22317
+ });
22318
+ parentTd.value.push(...splitValue);
22319
+ parentTd.rowList = void 0;
22320
+ parentTd.positionList = void 0;
22321
+ }
22322
+ if (posCtx.isTable && posCtx.trId === splitTr.id) {
22323
+ posCtx.index = i;
22324
+ this.position.setPositionContext(posCtx);
22325
+ }
22326
+ mergedTrList.splice(t, 1);
22327
+ }
21471
22328
  }
21472
22329
  element.pagingIndex = element.pagingIndex ?? 0;
21473
22330
  const trList = element.trList;
21474
22331
  for (let t = 0; t < trList.length; t++) {
21475
22332
  const tr = trList[t];
22333
+ delete tr.splitBoundaryTop;
22334
+ delete tr.splitBoundaryBottom;
21476
22335
  tr.height = tr.minHeight || defaultTrMinHeight;
21477
22336
  tr.minHeight = tr.height;
21478
22337
  }
@@ -21487,6 +22346,7 @@ var Draw = class {
21487
22346
  const rowList2 = this.computeRowList({
21488
22347
  innerWidth: (td.width - cellPaddingWidth) * scale,
21489
22348
  elementList: td.value,
22349
+ initialListState: td.splitListState,
21490
22350
  isFromTable: true,
21491
22351
  isPagingMode
21492
22352
  });
@@ -21569,6 +22429,7 @@ var Draw = class {
21569
22429
  const tdRowList = this.computeRowList({
21570
22430
  innerWidth: (td.width - cellPaddingWidth) * scale,
21571
22431
  elementList: td.value,
22432
+ initialListState: td.splitListState,
21572
22433
  isFromTable: true,
21573
22434
  isPagingMode
21574
22435
  });
@@ -21662,6 +22523,197 @@ var Draw = class {
21662
22523
  }
21663
22524
  }
21664
22525
  }
22526
+ if (deleteCount === 0) {
22527
+ let overflowTrIdx = -1;
22528
+ let preHeightScaled = 0;
22529
+ for (let r = 0; r < trList2.length; r++) {
22530
+ const trHeight = trList2[r].height * scale;
22531
+ if (curPagePreHeight + rowMarginHeight + preHeightScaled + trHeight > height2) {
22532
+ overflowTrIdx = r;
22533
+ break;
22534
+ }
22535
+ preHeightScaled += trHeight;
22536
+ }
22537
+ if (overflowTrIdx >= 0) {
22538
+ const availableScaled = height2 - curPagePreHeight - rowMarginHeight - preHeightScaled;
22539
+ const availableUnscaled = availableScaled / scale;
22540
+ if (availableUnscaled >= defaultTrMinHeight) {
22541
+ const overflowTr = trList2[overflowTrIdx];
22542
+ const originalTrHeight = overflowTr.height;
22543
+ const {
22544
+ table: { tdPadding: defaultTdPadding, defaultTrMinHeight: defaultTrMinHeight2 }
22545
+ } = this.options;
22546
+ const splits = [];
22547
+ let anySplit = false;
22548
+ for (let d = 0; d < overflowTr.tdList.length; d++) {
22549
+ const td = overflowTr.tdList[d];
22550
+ const cellPadding = td.padding || defaultTdPadding;
22551
+ const cellPaddingH = cellPadding[0] + cellPadding[2];
22552
+ const contentAvailableScaled = (availableUnscaled - cellPaddingH) * scale;
22553
+ if (!td.rowList || td.rowList.length === 0) {
22554
+ splits.push({
22555
+ elemIdx: td.value.length,
22556
+ rowIdx: 0
22557
+ });
22558
+ continue;
22559
+ }
22560
+ let cumHeight = 0;
22561
+ let elemIdx = td.value.length;
22562
+ let rowIdx = td.rowList.length;
22563
+ for (let ri = 0; ri < td.rowList.length; ri++) {
22564
+ const row = td.rowList[ri];
22565
+ if (cumHeight + row.height > contentAvailableScaled) {
22566
+ elemIdx = row.startIndex;
22567
+ rowIdx = ri;
22568
+ break;
22569
+ }
22570
+ cumHeight += row.height;
22571
+ }
22572
+ if (elemIdx > 0 && elemIdx < td.value.length) {
22573
+ anySplit = true;
22574
+ }
22575
+ splits.push({ elemIdx, rowIdx });
22576
+ }
22577
+ if (anySplit) {
22578
+ if (!activeSplitRange) {
22579
+ const posCtx = this.position.getPositionContext();
22580
+ const { startIndex, endIndex } = this.range.getRange();
22581
+ if (posCtx.isTable && posCtx.trId === overflowTr.id && startIndex === endIndex && posCtx.tdIndex !== void 0) {
22582
+ const splitIdx = splits[posCtx.tdIndex]?.elemIdx;
22583
+ if (splitIdx !== void 0 && startIndex >= splitIdx && splitIdx < overflowTr.tdList[posCtx.tdIndex].value.length) {
22584
+ activeSplitRange = {
22585
+ tdIndex: posCtx.tdIndex,
22586
+ mergedIndex: startIndex,
22587
+ trId: overflowTr.id
22588
+ };
22589
+ }
22590
+ }
22591
+ }
22592
+ const continuationTrHeight = originalTrHeight - availableUnscaled;
22593
+ const splitRootId = overflowTr.splitRootId || overflowTr.id;
22594
+ const splitLevel = (overflowTr.splitLevel || 0) + 1;
22595
+ const newTrId = `${splitRootId}_c${splitLevel}`;
22596
+ const continuationTdList = overflowTr.tdList.map(
22597
+ (td, d) => {
22598
+ const splitIdx = splits[d].elemIdx;
22599
+ const newTdId = getUUID();
22600
+ const initialListState2 = this.getListStateBeforeIndex(
22601
+ td.value,
22602
+ splitIdx
22603
+ );
22604
+ const overflowElements = td.value.slice(splitIdx);
22605
+ const overflowStartElement = overflowElements[0];
22606
+ let splitSyntheticLeadingZero = false;
22607
+ if (!overflowElements.length || overflowElements[0]?.value !== ZERO) {
22608
+ overflowElements.unshift({
22609
+ value: ZERO,
22610
+ type: "text" /* TEXT */,
22611
+ listId: overflowStartElement?.listId,
22612
+ listType: overflowStartElement?.listType,
22613
+ listStyle: overflowStartElement?.listStyle,
22614
+ listLevel: overflowStartElement?.listLevel,
22615
+ listPreset: overflowStartElement?.listPreset,
22616
+ listWrap: !!overflowStartElement?.listId
22617
+ });
22618
+ splitSyntheticLeadingZero = true;
22619
+ }
22620
+ this.syncTableElementContext(overflowElements, {
22621
+ tableId: element.id,
22622
+ trId: newTrId,
22623
+ tdId: newTdId
22624
+ });
22625
+ const {
22626
+ id: _tdId,
22627
+ value: _v,
22628
+ rowList: _rl,
22629
+ positionList: _pl,
22630
+ splitSyntheticLeadingZero: _slz,
22631
+ splitListState: _sls,
22632
+ ...tdMeta
22633
+ } = td;
22634
+ return {
22635
+ ...deepClone(tdMeta),
22636
+ id: newTdId,
22637
+ value: overflowElements,
22638
+ splitSyntheticLeadingZero,
22639
+ splitListState: initialListState2,
22640
+ height: continuationTrHeight,
22641
+ rowList: void 0,
22642
+ positionList: void 0,
22643
+ mainHeight: void 0,
22644
+ realHeight: void 0,
22645
+ realMinHeight: void 0
22646
+ };
22647
+ }
22648
+ );
22649
+ const continuationTr = {
22650
+ id: newTrId,
22651
+ height: continuationTrHeight,
22652
+ minHeight: defaultTrMinHeight2,
22653
+ tdList: continuationTdList,
22654
+ splitParentId: overflowTr.id,
22655
+ splitRootId,
22656
+ splitLevel
22657
+ };
22658
+ let isLogicalSplitCursorHandled = false;
22659
+ if (logicalSplitCursor && logicalSplitCursor.rootTrId === splitRootId) {
22660
+ isLogicalSplitCursorHandled = this.applyCollapsedSplitTableCursor({
22661
+ tableIndex: i,
22662
+ tableId: element.id,
22663
+ overflowTr,
22664
+ overflowTrIdx,
22665
+ continuationTr,
22666
+ continuationTdList,
22667
+ logicalCursor: logicalSplitCursor,
22668
+ splits
22669
+ });
22670
+ }
22671
+ const positionContext = this.position.getPositionContext();
22672
+ if (!isLogicalSplitCursorHandled && activeSplitRange && positionContext.isTable && positionContext.trId === activeSplitRange.trId) {
22673
+ const splitIdx = splits[activeSplitRange.tdIndex]?.elemIdx;
22674
+ const continuationTd = continuationTdList[activeSplitRange.tdIndex];
22675
+ if (splitIdx !== void 0 && continuationTd && activeSplitRange.mergedIndex >= splitIdx) {
22676
+ const hasPrependedZero = !!continuationTd.splitSyntheticLeadingZero && continuationTd.value[0]?.value === ZERO;
22677
+ const continuationCursorIndex = activeSplitRange.mergedIndex - splitIdx + (hasPrependedZero ? 1 : 0);
22678
+ positionContext.index = i;
22679
+ positionContext.trIndex = overflowTrIdx + 1;
22680
+ positionContext.tdIndex = activeSplitRange.tdIndex;
22681
+ positionContext.tdId = continuationTd.id;
22682
+ positionContext.trId = continuationTr.id;
22683
+ positionContext.tableId = element.id;
22684
+ this.position.setPositionContext(positionContext);
22685
+ this.range.setRange(
22686
+ continuationCursorIndex,
22687
+ continuationCursorIndex
22688
+ );
22689
+ this.pendingTableCursorIndex = continuationCursorIndex;
22690
+ }
22691
+ }
22692
+ for (let d = 0; d < overflowTr.tdList.length; d++) {
22693
+ const td = overflowTr.tdList[d];
22694
+ const { elemIdx, rowIdx } = splits[d];
22695
+ td.value = td.value.slice(0, elemIdx);
22696
+ td.rowList = td.rowList ? td.rowList.slice(0, rowIdx) : void 0;
22697
+ td.positionList = void 0;
22698
+ td.height = availableUnscaled;
22699
+ td.mainHeight = void 0;
22700
+ td.realHeight = void 0;
22701
+ td.realMinHeight = void 0;
22702
+ }
22703
+ overflowTr.height = availableUnscaled;
22704
+ overflowTr.minHeight = Math.min(
22705
+ overflowTr.minHeight || defaultTrMinHeight2,
22706
+ availableUnscaled
22707
+ );
22708
+ overflowTr.splitBoundaryBottom = true;
22709
+ continuationTr.splitBoundaryTop = true;
22710
+ trList2.splice(overflowTrIdx + 1, 0, continuationTr);
22711
+ deleteStart = overflowTrIdx + 1;
22712
+ deleteCount = trList2.length - deleteStart;
22713
+ }
22714
+ }
22715
+ }
22716
+ }
21665
22717
  if (deleteCount) {
21666
22718
  const cloneTrList = trList2.splice(deleteStart, deleteCount);
21667
22719
  const cloneTrHeight = cloneTrList.reduce(
@@ -21674,16 +22726,26 @@ var Draw = class {
21674
22726
  element.height -= cloneTrHeight;
21675
22727
  metrics.height -= cloneTrRealHeight;
21676
22728
  metrics.boundingBoxDescent -= cloneTrRealHeight;
21677
- const cloneElement = deepClone(element);
21678
- cloneElement.pagingId = pagingId;
21679
- cloneElement.pagingIndex = element.pagingIndex + 1;
22729
+ const {
22730
+ trList: _currentTrList,
22731
+ id: _currentId,
22732
+ height: _currentHeight,
22733
+ pagingIndex: _currentPagingIndex,
22734
+ ...cloneElementMeta
22735
+ } = element;
22736
+ const cloneElement = {
22737
+ ...deepClone(cloneElementMeta),
22738
+ trList: cloneTrList,
22739
+ height: cloneTrHeight,
22740
+ pagingId,
22741
+ pagingIndex: element.pagingIndex + 1
22742
+ };
21680
22743
  const repeatTrList = trList2.filter((tr) => tr.pagingRepeat);
21681
22744
  if (repeatTrList.length) {
21682
22745
  const cloneRepeatTrList = deepClone(repeatTrList);
21683
22746
  cloneRepeatTrList.forEach((tr) => tr.id = getUUID());
21684
22747
  cloneTrList.unshift(...cloneRepeatTrList);
21685
22748
  }
21686
- cloneElement.trList = cloneTrList;
21687
22749
  cloneElement.id = getUUID();
21688
22750
  this.spliceElementList(elementList, i + 1, 0, [cloneElement]);
21689
22751
  }
@@ -21711,6 +22773,21 @@ var Draw = class {
21711
22773
  positionContext.index = newPositionContextIndex;
21712
22774
  positionContext.trIndex = newPositionContextTrIndex;
21713
22775
  this.position.setPositionContext(positionContext);
22776
+ } else if (mergedSplitFallback && positionContext.trId === mergedSplitFallback.trId) {
22777
+ const fallbackTd = element.trList?.[mergedSplitFallback.parentTrIndex]?.tdList[mergedSplitFallback.tdIndex];
22778
+ const fallbackCursorIndex = Math.min(
22779
+ mergedSplitFallback.mergedIndex,
22780
+ Math.max((fallbackTd?.value.length || 1) - 1, 0)
22781
+ );
22782
+ positionContext.index = i;
22783
+ positionContext.trIndex = mergedSplitFallback.parentTrIndex;
22784
+ positionContext.tdIndex = mergedSplitFallback.tdIndex;
22785
+ positionContext.tdId = mergedSplitFallback.parentTdId;
22786
+ positionContext.trId = mergedSplitFallback.parentTrId;
22787
+ positionContext.tableId = element.id;
22788
+ this.position.setPositionContext(positionContext);
22789
+ this.range.setRange(fallbackCursorIndex, fallbackCursorIndex);
22790
+ this.pendingTableCursorIndex = fallbackCursorIndex;
21714
22791
  }
21715
22792
  }
21716
22793
  }
@@ -21843,39 +22920,7 @@ var Draw = class {
21843
22920
  curRowWidth += punctuationWidth * scale;
21844
22921
  }
21845
22922
  }
21846
- if (element.listId) {
21847
- const curLevel = element.listLevel ?? 0;
21848
- if (element.listId !== listId) {
21849
- listIndex = 0;
21850
- listLevelIndex = /* @__PURE__ */ new Map();
21851
- listLevelIndex.set(curLevel, 0);
21852
- prevListLevel = curLevel;
21853
- } else if (element.value === ZERO && !element.listWrap) {
21854
- if (curLevel !== prevListLevel) {
21855
- if (curLevel > prevListLevel) {
21856
- listLevelIndex.set(curLevel, 0);
21857
- } else {
21858
- for (const [lvl] of listLevelIndex) {
21859
- if (lvl > curLevel) {
21860
- listLevelIndex.delete(lvl);
21861
- }
21862
- }
21863
- listLevelIndex.set(
21864
- curLevel,
21865
- (listLevelIndex.get(curLevel) ?? -1) + 1
21866
- );
21867
- }
21868
- } else {
21869
- listLevelIndex.set(
21870
- curLevel,
21871
- (listLevelIndex.get(curLevel) ?? -1) + 1
21872
- );
21873
- }
21874
- listIndex = listLevelIndex.get(curLevel) ?? 0;
21875
- prevListLevel = curLevel;
21876
- }
21877
- }
21878
- listId = element.listId;
22923
+ this.advanceListState(element, listState);
21879
22924
  const surroundPosition = this.position.setSurroundPosition({
21880
22925
  pageNo,
21881
22926
  rowElement,
@@ -21927,7 +22972,7 @@ var Draw = class {
21927
22972
  const baseListOffset = listStyleMap.get(element.listId) || 0;
21928
22973
  const rowListIndent = this.listParticle.getListIndentWidth(element);
21929
22974
  row.offsetX = baseListOffset + rowListIndent;
21930
- row.listIndex = listIndex;
22975
+ row.listIndex = listState.listIndex;
21931
22976
  }
21932
22977
  row.offsetY = !isFromTable && element.area?.top && element.areaId !== elementList[i - 1]?.areaId ? element.area.top * scale : 0;
21933
22978
  rowList.push(row);
@@ -22148,6 +23193,27 @@ var Draw = class {
22148
23193
  const isPrintMode = this.isPrintMode();
22149
23194
  const isGraffitiMode = this.isGraffitiMode();
22150
23195
  const { isCrossRowCol, tableId } = this.range.getRange();
23196
+ const splitCellSelection = this.range.getSplitCellSelection();
23197
+ const tableCellSelection = this.range.getTableCellSelection();
23198
+ const splitCellRenderOffsetMap = splitCellSelection ? (() => {
23199
+ const splitCellContext = this.getSplitCellSelectionContext(
23200
+ this.getOriginalElementList(),
23201
+ splitCellSelection
23202
+ );
23203
+ if (!splitCellContext) return null;
23204
+ const offsetMap = /* @__PURE__ */ new Map();
23205
+ let offset = 0;
23206
+ for (let c = 0; c < splitCellContext.cellContextList.length; c++) {
23207
+ const { td } = splitCellContext.cellContextList[c];
23208
+ const skipLeadingZero = !!td.splitSyntheticLeadingZero && td.value[0]?.value === ZERO ? 1 : 0;
23209
+ offsetMap.set(td.id, {
23210
+ offset,
23211
+ skipLeadingZero
23212
+ });
23213
+ offset += Math.max(td.value.length - skipLeadingZero, 0);
23214
+ }
23215
+ return offsetMap;
23216
+ })() : null;
22151
23217
  let index = startIndex;
22152
23218
  for (let i = 0; i < rowList.length; i++) {
22153
23219
  const curRow = rowList[i];
@@ -22179,6 +23245,9 @@ var Draw = class {
22179
23245
  this.textParticle.complete();
22180
23246
  this.laTexParticle.render(ctx, element, x, y + offsetY);
22181
23247
  } else if (element.type === "table" /* TABLE */) {
23248
+ if (tableCellSelection) {
23249
+ tableRangeElement = element;
23250
+ }
22182
23251
  if (isCrossRowCol) {
22183
23252
  rangeRecord.x = x;
22184
23253
  rangeRecord.y = y;
@@ -22326,11 +23395,14 @@ var Draw = class {
22326
23395
  startIndex: startIndex2,
22327
23396
  endIndex
22328
23397
  } = this.range.getRange();
22329
- if (currentZone === zone && startIndex2 !== endIndex && startIndex2 <= index && index <= endIndex) {
23398
+ const splitCellOffset = element.tdId ? splitCellRenderOffsetMap?.get(element.tdId) : void 0;
23399
+ const splitCellIndex = splitCellOffset ? index - splitCellOffset.skipLeadingZero + splitCellOffset.offset : index;
23400
+ const isSplitCellElement = !!splitCellOffset && index >= splitCellOffset.skipLeadingZero;
23401
+ if (currentZone === zone && startIndex2 !== endIndex && startIndex2 <= splitCellIndex && splitCellIndex <= endIndex) {
22330
23402
  const positionContext = this.position.getPositionContext();
22331
- if (!positionContext.isTable && !element.tdId || positionContext.tdId === element.tdId) {
22332
- if (startIndex2 === index) {
22333
- const nextElement = elementList[startIndex2 + 1];
23403
+ if (splitCellRenderOffsetMap && isSplitCellElement || !splitCellRenderOffsetMap && (!positionContext.isTable && !element.tdId || positionContext.tdId === element.tdId)) {
23404
+ if (startIndex2 === splitCellIndex) {
23405
+ const nextElement = splitCellRenderOffsetMap && isSplitCellElement ? this.getElementList()[startIndex2 + 1] : elementList[startIndex2 + 1];
22334
23406
  if (nextElement && nextElement.value === ZERO) {
22335
23407
  rangeRecord.x = x + metrics.width;
22336
23408
  rangeRecord.y = y - (curRow.spaceAbove || 0);
@@ -22395,7 +23467,7 @@ var Draw = class {
22395
23467
  this.strikeout.render(ctx);
22396
23468
  this.group.render(ctx);
22397
23469
  if (!isPrintMode && !isGraffitiMode) {
22398
- if (rangeRecord.width && rangeRecord.height) {
23470
+ if (!tableCellSelection && rangeRecord.width && rangeRecord.height) {
22399
23471
  const { x, y, width, height } = rangeRecord;
22400
23472
  this.range.render(ctx, x, y, width, height);
22401
23473
  }
@@ -22407,6 +23479,20 @@ var Draw = class {
22407
23479
  } = positionList[curRow.startIndex];
22408
23480
  this.tableParticle.drawRange(ctx, tableRangeElement, x, y);
22409
23481
  }
23482
+ if (tableCellSelection && tableRangeElement) {
23483
+ const {
23484
+ coordinate: {
23485
+ leftTop: [x, y]
23486
+ }
23487
+ } = positionList[curRow.startIndex];
23488
+ this.tableParticle.drawCellRange(
23489
+ ctx,
23490
+ tableRangeElement,
23491
+ x,
23492
+ y,
23493
+ tableCellSelection
23494
+ );
23495
+ }
22410
23496
  }
22411
23497
  }
22412
23498
  }
@@ -22596,6 +23682,7 @@ var Draw = class {
22596
23682
  isFirstRender = false
22597
23683
  } = payload || {};
22598
23684
  let { curIndex } = payload || {};
23685
+ this.pendingTableCursorIndex = void 0;
22599
23686
  const innerWidth = this.getInnerWidth();
22600
23687
  const columnWidth = this.getColumnWidth();
22601
23688
  const isPagingMode = this.getIsPagingMode();
@@ -22661,6 +23748,10 @@ var Draw = class {
22661
23748
  } else {
22662
23749
  this._immediateRender();
22663
23750
  }
23751
+ if (this.pendingTableCursorIndex !== void 0) {
23752
+ curIndex = this.pendingTableCursorIndex;
23753
+ this.pendingTableCursorIndex = void 0;
23754
+ }
22664
23755
  if (isSetCursor) {
22665
23756
  curIndex = this.setCursor(curIndex);
22666
23757
  } else if (this.range.getIsSelection()) {
@@ -22702,9 +23793,7 @@ var Draw = class {
22702
23793
  const positionContext = this.position.getPositionContext();
22703
23794
  const positionList = this.position.getPositionList();
22704
23795
  if (positionContext.isTable) {
22705
- const { index, trIndex, tdIndex } = positionContext;
22706
- const elementList = this.getOriginalElementList();
22707
- const tablePositionList = elementList[index].trList?.[trIndex].tdList[tdIndex].positionList;
23796
+ const tablePositionList = this.resolveTableCellContext(this.getOriginalElementList())?.td.positionList;
22708
23797
  if (curIndex === void 0 && tablePositionList) {
22709
23798
  curIndex = tablePositionList.length - 1;
22710
23799
  }
@@ -23030,6 +24119,34 @@ var CommandAdapt = class {
23030
24119
  this.zone = draw.getZone();
23031
24120
  this.tableOperate = draw.getTableOperate();
23032
24121
  }
24122
+ getStyleSelectionElementList(options = {}) {
24123
+ const selection = this.range.getSelectionElementList();
24124
+ if (!selection?.length) return null;
24125
+ const { textLikeOnly = false } = options;
24126
+ const result = [];
24127
+ const collect = (elementList) => {
24128
+ for (let i = 0; i < elementList.length; i++) {
24129
+ const element = elementList[i];
24130
+ if (element.type === "table" /* TABLE */ && element.trList?.length) {
24131
+ for (let t = 0; t < element.trList.length; t++) {
24132
+ const tr = element.trList[t];
24133
+ for (let d = 0; d < tr.tdList.length; d++) {
24134
+ collect(tr.tdList[d].value);
24135
+ }
24136
+ }
24137
+ continue;
24138
+ }
24139
+ result.push(element);
24140
+ }
24141
+ };
24142
+ collect(selection);
24143
+ if (!textLikeOnly) {
24144
+ return result;
24145
+ }
24146
+ return result.filter(
24147
+ (element) => isTextLikeElement(element) || element.type === "label" /* LABEL */
24148
+ );
24149
+ }
23033
24150
  mode(payload) {
23034
24151
  this.draw.setMode(payload);
23035
24152
  }
@@ -23175,7 +24292,7 @@ var CommandAdapt = class {
23175
24292
  const { isIgnoreDisabledRule = false } = options || {};
23176
24293
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23177
24294
  if (isDisabled) return;
23178
- const selection = this.range.getSelectionElementList();
24295
+ const selection = this.getStyleSelectionElementList();
23179
24296
  let renderOption = {};
23180
24297
  let changeElementList = [];
23181
24298
  if (selection?.length) {
@@ -23202,7 +24319,7 @@ var CommandAdapt = class {
23202
24319
  const { isIgnoreDisabledRule = false } = options || {};
23203
24320
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23204
24321
  if (isDisabled) return;
23205
- const selection = this.range.getSelectionElementList();
24322
+ const selection = this.getStyleSelectionElementList();
23206
24323
  if (selection?.length) {
23207
24324
  selection.forEach((el) => {
23208
24325
  el.font = payload;
@@ -23236,7 +24353,9 @@ var CommandAdapt = class {
23236
24353
  if (payload < minSize || payload > maxSize) return;
23237
24354
  let renderOption = {};
23238
24355
  let changeElementList = [];
23239
- const selection = this.range.getTextLikeSelectionElementList();
24356
+ const selection = this.getStyleSelectionElementList({
24357
+ textLikeOnly: true
24358
+ });
23240
24359
  if (selection?.length) {
23241
24360
  changeElementList = selection;
23242
24361
  renderOption = { isSetCursor: false };
@@ -23276,7 +24395,9 @@ var CommandAdapt = class {
23276
24395
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23277
24396
  if (isDisabled) return;
23278
24397
  const { defaultSize, maxSize } = this.options;
23279
- const selection = this.range.getTextLikeSelectionElementList();
24398
+ const selection = this.getStyleSelectionElementList({
24399
+ textLikeOnly: true
24400
+ });
23280
24401
  let renderOption = {};
23281
24402
  let changeElementList = [];
23282
24403
  if (selection?.length) {
@@ -23325,7 +24446,9 @@ var CommandAdapt = class {
23325
24446
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23326
24447
  if (isDisabled) return;
23327
24448
  const { defaultSize, minSize } = this.options;
23328
- const selection = this.range.getTextLikeSelectionElementList();
24449
+ const selection = this.getStyleSelectionElementList({
24450
+ textLikeOnly: true
24451
+ });
23329
24452
  let renderOption = {};
23330
24453
  let changeElementList = [];
23331
24454
  if (selection?.length) {
@@ -23373,7 +24496,7 @@ var CommandAdapt = class {
23373
24496
  const { isIgnoreDisabledRule = false } = options || {};
23374
24497
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23375
24498
  if (isDisabled) return;
23376
- const selection = this.range.getSelectionElementList();
24499
+ const selection = this.getStyleSelectionElementList();
23377
24500
  if (selection?.length) {
23378
24501
  const noBoldIndex = selection.findIndex((s) => !s.bold);
23379
24502
  selection.forEach((el) => {
@@ -23405,7 +24528,7 @@ var CommandAdapt = class {
23405
24528
  const { isIgnoreDisabledRule = false } = options || {};
23406
24529
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23407
24530
  if (isDisabled) return;
23408
- const selection = this.range.getSelectionElementList();
24531
+ const selection = this.getStyleSelectionElementList();
23409
24532
  if (selection?.length) {
23410
24533
  const noItalicIndex = selection.findIndex((s) => !s.italic);
23411
24534
  selection.forEach((el) => {
@@ -23437,7 +24560,7 @@ var CommandAdapt = class {
23437
24560
  const { isIgnoreDisabledRule = false } = options || {};
23438
24561
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23439
24562
  if (isDisabled) return;
23440
- const selection = this.range.getSelectionElementList();
24563
+ const selection = this.getStyleSelectionElementList();
23441
24564
  if (selection?.length) {
23442
24565
  const isSetUnderline = selection.some(
23443
24566
  (s) => !s.underline || !textDecoration && s.textDecoration || textDecoration && !s.textDecoration || textDecoration && s.textDecoration && !isObjectEqual(s.textDecoration, textDecoration)
@@ -23479,7 +24602,7 @@ var CommandAdapt = class {
23479
24602
  const { isIgnoreDisabledRule = false } = options || {};
23480
24603
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23481
24604
  if (isDisabled) return;
23482
- const selection = this.range.getSelectionElementList();
24605
+ const selection = this.getStyleSelectionElementList();
23483
24606
  if (selection?.length) {
23484
24607
  const noStrikeoutIndex = selection.findIndex((s) => !s.strikeout);
23485
24608
  selection.forEach((el) => {
@@ -23514,7 +24637,7 @@ var CommandAdapt = class {
23514
24637
  const { isIgnoreDisabledRule = false } = options || {};
23515
24638
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23516
24639
  if (isDisabled) return;
23517
- const selection = this.range.getSelectionElementList();
24640
+ const selection = this.getStyleSelectionElementList();
23518
24641
  if (!selection) return;
23519
24642
  const superscriptIndex = selection.findIndex(
23520
24643
  (s) => s.type === "superscript" /* SUPERSCRIPT */
@@ -23537,7 +24660,7 @@ var CommandAdapt = class {
23537
24660
  const { isIgnoreDisabledRule = false } = options || {};
23538
24661
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23539
24662
  if (isDisabled) return;
23540
- const selection = this.range.getSelectionElementList();
24663
+ const selection = this.getStyleSelectionElementList();
23541
24664
  if (!selection) return;
23542
24665
  const subscriptIndex = selection.findIndex(
23543
24666
  (s) => s.type === "subscript" /* SUBSCRIPT */
@@ -23560,7 +24683,7 @@ var CommandAdapt = class {
23560
24683
  const { isIgnoreDisabledRule = false } = options || {};
23561
24684
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23562
24685
  if (isDisabled) return;
23563
- const selection = this.range.getSelectionElementList();
24686
+ const selection = this.getStyleSelectionElementList();
23564
24687
  if (selection?.length) {
23565
24688
  selection.forEach((el) => {
23566
24689
  if (payload) {
@@ -23601,7 +24724,7 @@ var CommandAdapt = class {
23601
24724
  const { isIgnoreDisabledRule = false } = options || {};
23602
24725
  const isDisabled = !isIgnoreDisabledRule && (this.draw.isReadonly() || this.draw.isDisabled());
23603
24726
  if (isDisabled) return;
23604
- const selection = this.range.getSelectionElementList();
24727
+ const selection = this.getStyleSelectionElementList();
23605
24728
  if (selection?.length) {
23606
24729
  selection.forEach((el) => {
23607
24730
  if (payload) {
@@ -24232,25 +25355,39 @@ var CommandAdapt = class {
24232
25355
  const endElement = pickElementAttr(elementList[endIndex], {
24233
25356
  extraPickAttrs: ["id", "controlComponent"]
24234
25357
  });
24235
- const rowList = this.draw.getRowList();
24236
25358
  const positionList = this.position.getPositionList();
24237
25359
  const startPosition = positionList[startIndex];
24238
25360
  const endPosition = positionList[endIndex];
25361
+ if (!startPosition || !endPosition) return null;
24239
25362
  const startPageNo = startPosition.pageNo;
24240
25363
  const endPageNo = endPosition.pageNo;
24241
25364
  const startRowNo = startPosition.rowIndex;
24242
25365
  const endRowNo = endPosition.rowIndex;
24243
- const startRow = rowList[startRowNo];
24244
- const endRow = rowList[endRowNo];
25366
+ const getRowStartPositionIndex = (targetIndex) => {
25367
+ let rowStartIndex = targetIndex;
25368
+ const targetPosition = positionList[targetIndex];
25369
+ while (rowStartIndex > 0) {
25370
+ const prePosition = positionList[rowStartIndex - 1];
25371
+ if (!prePosition || prePosition.pageNo !== targetPosition.pageNo || prePosition.rowNo !== targetPosition.rowNo || prePosition.columnNo !== targetPosition.columnNo) {
25372
+ break;
25373
+ }
25374
+ rowStartIndex--;
25375
+ }
25376
+ return rowStartIndex;
25377
+ };
25378
+ const startRowStartIndex = getRowStartPositionIndex(startIndex);
25379
+ const endRowStartIndex = getRowStartPositionIndex(endIndex);
25380
+ const startRowStartsWithZero = elementList[startRowStartIndex]?.value === ZERO;
25381
+ const endRowStartsWithZero = elementList[endRowStartIndex]?.value === ZERO;
24245
25382
  let startColNo = 0;
24246
25383
  let endColNo = 0;
24247
25384
  if (!this.draw.getCursor().getHitLineStartIndex()) {
24248
- startColNo = startRow.elementList[0]?.value === ZERO ? startPosition.index - startRow.startIndex : startPosition.index - startRow.startIndex + 1;
25385
+ startColNo = startRowStartsWithZero ? startIndex - startRowStartIndex : startIndex - startRowStartIndex + 1;
24249
25386
  }
24250
25387
  if (startPosition === endPosition) {
24251
25388
  endColNo = startColNo;
24252
25389
  } else {
24253
- endColNo = endRow.elementList[0]?.value === ZERO ? endPosition.index - endRow.startIndex : endPosition.index - endRow.startIndex + 1;
25390
+ endColNo = endRowStartsWithZero ? endIndex - endRowStartIndex : endIndex - endRowStartIndex + 1;
24254
25391
  }
24255
25392
  const rangeRects = [];
24256
25393
  const height = this.draw.getOriginalHeight();
@@ -24258,6 +25395,7 @@ var CommandAdapt = class {
24258
25395
  const selectionPositionList = this.position.getSelectionPositionList();
24259
25396
  if (selectionPositionList) {
24260
25397
  let currentRowNo = null;
25398
+ let currentPageNo = null;
24261
25399
  let currentX = 0;
24262
25400
  let rangeRect = null;
24263
25401
  for (let p = 0; p < selectionPositionList.length; p++) {
@@ -24267,7 +25405,7 @@ var CommandAdapt = class {
24267
25405
  coordinate: { leftTop, rightTop },
24268
25406
  lineHeight
24269
25407
  } = selectionPositionList[p];
24270
- if (currentRowNo === null || currentRowNo !== rowNo) {
25408
+ if (currentRowNo === null || currentPageNo === null || currentRowNo !== rowNo || currentPageNo !== pageNo) {
24271
25409
  if (rangeRect) {
24272
25410
  rangeRects.push(rangeRect);
24273
25411
  }
@@ -24278,6 +25416,7 @@ var CommandAdapt = class {
24278
25416
  height: lineHeight
24279
25417
  };
24280
25418
  currentRowNo = rowNo;
25419
+ currentPageNo = pageNo;
24281
25420
  currentX = leftTop[0];
24282
25421
  } else {
24283
25422
  rangeRect.width = rightTop[0] - currentX;