@windoc/core 0.3.22 → 0.3.24

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.22";
81
+ var version = "0.3.24";
82
82
 
83
83
  // src/dataset/enum/Common.ts
84
84
  var MaxHeightRatio = /* @__PURE__ */ ((MaxHeightRatio2) => {
@@ -185,21 +185,6 @@ function debounce(func, delay) {
185
185
  }, delay);
186
186
  };
187
187
  }
188
- function deepCloneOmitKeys(obj, omitKeys) {
189
- if (!obj || typeof obj !== "object") {
190
- return obj;
191
- }
192
- let newObj = {};
193
- if (Array.isArray(obj)) {
194
- newObj = obj.map((item) => deepCloneOmitKeys(item, omitKeys));
195
- } else {
196
- Object.keys(obj).forEach((key) => {
197
- if (omitKeys.includes(key)) return;
198
- newObj[key] = deepCloneOmitKeys(obj[key], omitKeys);
199
- });
200
- }
201
- return newObj;
202
- }
203
188
  function deepClone(obj) {
204
189
  if (typeof structuredClone === "function") {
205
190
  return structuredClone(obj);
@@ -4501,6 +4486,7 @@ function mergeOption(options = {}) {
4501
4486
  wordBreak: "break-word" /* BREAK_WORD */,
4502
4487
  printPixelRatio: 3,
4503
4488
  maskMargin: [0, 0, 0, 0],
4489
+ scrollPaddingLines: 3,
4504
4490
  letterClass: [LETTER_CLASS.ENGLISH],
4505
4491
  contextMenuDisableKeys: [],
4506
4492
  shortcutDisableKeys: [],
@@ -5022,9 +5008,7 @@ function mergeSplitTableRowsForZip(trList) {
5022
5008
  for (let t = trList.length - 1; t >= 0; t--) {
5023
5009
  const splitTr = trList[t];
5024
5010
  if (!splitTr.splitParentId) continue;
5025
- const parentTrIdx = trList.findIndex(
5026
- (tr) => tr.id === splitTr.splitParentId
5027
- );
5011
+ const parentTrIdx = trList.findIndex((tr) => tr.id === splitTr.splitParentId);
5028
5012
  if (!~parentTrIdx) continue;
5029
5013
  const parentTr = trList[parentTrIdx];
5030
5014
  parentTr.height += splitTr.height;
@@ -6070,10 +6054,184 @@ ${ulListStyleText || `${listIndex + 1}.`}${buildText(
6070
6054
  return buildText(zipElementList(elementList));
6071
6055
  }
6072
6056
  function getSlimCloneElementList(elementList) {
6073
- return deepCloneOmitKeys(elementList, [
6074
- "metrics",
6075
- "style"
6076
- ]);
6057
+ const snapshotElementList = [];
6058
+ let preSourceElement = null;
6059
+ let preSnapshotElement = null;
6060
+ for (let i = 0; i < elementList.length; i++) {
6061
+ const element = elementList[i];
6062
+ if (preSourceElement && preSnapshotElement && isHistoryTextSnapshotMergeable(preSourceElement, element)) {
6063
+ preSnapshotElement.value += element.value;
6064
+ preSourceElement = element;
6065
+ continue;
6066
+ }
6067
+ const snapshotElement = cloneHistorySnapshotElement(element);
6068
+ snapshotElementList.push(snapshotElement);
6069
+ preSourceElement = element;
6070
+ preSnapshotElement = snapshotElement;
6071
+ }
6072
+ return snapshotElementList;
6073
+ }
6074
+ var HISTORY_SNAPSHOT_OMIT_ATTR = /* @__PURE__ */ new Set([
6075
+ "metrics",
6076
+ "style",
6077
+ "rowList",
6078
+ "positionList",
6079
+ "x",
6080
+ "y",
6081
+ "trIndex",
6082
+ "tdIndex",
6083
+ "isLastRowTd",
6084
+ "isLastColTd",
6085
+ "isLastTd",
6086
+ "rowIndex",
6087
+ "colIndex",
6088
+ "mainHeight",
6089
+ "realHeight",
6090
+ "realMinHeight",
6091
+ "splitBoundaryTop",
6092
+ "splitBoundaryBottom",
6093
+ "actualSize"
6094
+ ]);
6095
+ function cloneHistorySnapshotValue(payload) {
6096
+ if (!payload || typeof payload !== "object") {
6097
+ return payload;
6098
+ }
6099
+ if (Array.isArray(payload)) {
6100
+ return payload.map((item) => cloneHistorySnapshotValue(item));
6101
+ }
6102
+ const snapshot = {};
6103
+ for (const key of Object.keys(payload)) {
6104
+ if (HISTORY_SNAPSHOT_OMIT_ATTR.has(String(key))) continue;
6105
+ snapshot[String(key)] = cloneHistorySnapshotValue(
6106
+ payload[key]
6107
+ );
6108
+ }
6109
+ return snapshot;
6110
+ }
6111
+ function cloneHistorySnapshotTd(td) {
6112
+ const snapshot = {};
6113
+ for (const key of Object.keys(td)) {
6114
+ if (HISTORY_SNAPSHOT_OMIT_ATTR.has(String(key))) continue;
6115
+ const value = td[key];
6116
+ if (key === "value") {
6117
+ snapshot.value = getSlimCloneElementList(value);
6118
+ continue;
6119
+ }
6120
+ snapshot[String(key)] = cloneHistorySnapshotValue(value);
6121
+ }
6122
+ return snapshot;
6123
+ }
6124
+ function cloneHistorySnapshotTr(tr) {
6125
+ const snapshot = {};
6126
+ for (const key of Object.keys(tr)) {
6127
+ if (HISTORY_SNAPSHOT_OMIT_ATTR.has(String(key))) continue;
6128
+ const value = tr[key];
6129
+ if (key === "tdList") {
6130
+ snapshot.tdList = value.map((td) => cloneHistorySnapshotTd(td));
6131
+ continue;
6132
+ }
6133
+ snapshot[String(key)] = cloneHistorySnapshotValue(value);
6134
+ }
6135
+ return snapshot;
6136
+ }
6137
+ function cloneHistorySnapshotElement(element) {
6138
+ const snapshot = {};
6139
+ for (const key of Object.keys(element)) {
6140
+ if (HISTORY_SNAPSHOT_OMIT_ATTR.has(String(key))) continue;
6141
+ const value = element[key];
6142
+ if (key === "trList" && Array.isArray(value)) {
6143
+ snapshot.trList = value.map((tr) => cloneHistorySnapshotTr(tr));
6144
+ continue;
6145
+ }
6146
+ if (key === "valueList" && Array.isArray(value)) {
6147
+ snapshot.valueList = getSlimCloneElementList(value);
6148
+ continue;
6149
+ }
6150
+ if (key === "control" && value && typeof value === "object") {
6151
+ snapshot.control = cloneHistorySnapshotControl(
6152
+ value
6153
+ );
6154
+ continue;
6155
+ }
6156
+ snapshot[String(key)] = cloneHistorySnapshotValue(value);
6157
+ }
6158
+ return snapshot;
6159
+ }
6160
+ function cloneHistorySnapshotControl(control) {
6161
+ const snapshot = {};
6162
+ for (const key of Object.keys(control)) {
6163
+ const value = control[key];
6164
+ if (key === "value" && Array.isArray(value)) {
6165
+ snapshot.value = getSlimCloneElementList(value);
6166
+ continue;
6167
+ }
6168
+ snapshot[String(key)] = cloneHistorySnapshotValue(value);
6169
+ }
6170
+ return snapshot;
6171
+ }
6172
+ function isHistoryTextSnapshotElement(element) {
6173
+ return !element.type || TEXTLIKE_ELEMENT_TYPE.includes(element.type);
6174
+ }
6175
+ function isHistoryTextSnapshotMergeable(source, target) {
6176
+ if (!isHistoryTextSnapshotElement(source) || !isHistoryTextSnapshotElement(target)) {
6177
+ return false;
6178
+ }
6179
+ return isSameHistoryElementExceptValue(source, target);
6180
+ }
6181
+ function isSameHistoryElementExceptValue(source, target) {
6182
+ const sourceKeys = Object.keys(source).filter(
6183
+ (key) => !HISTORY_SNAPSHOT_OMIT_ATTR.has(key)
6184
+ );
6185
+ const targetKeys = Object.keys(target).filter(
6186
+ (key) => !HISTORY_SNAPSHOT_OMIT_ATTR.has(key)
6187
+ );
6188
+ if (sourceKeys.length !== targetKeys.length) return false;
6189
+ for (let s = 0; s < sourceKeys.length; s++) {
6190
+ const key = sourceKeys[s];
6191
+ if (key === "value") continue;
6192
+ if (key === "groupIds" && Array.isArray(source[key]) && Array.isArray(target[key]) && isArrayEqual(source[key], target[key])) {
6193
+ continue;
6194
+ }
6195
+ if (source[key] !== target[key]) {
6196
+ return false;
6197
+ }
6198
+ }
6199
+ return true;
6200
+ }
6201
+ function inflateElementList(elementList) {
6202
+ let i = 0;
6203
+ while (i < elementList.length) {
6204
+ const element = elementList[i];
6205
+ if (element.trList?.length) {
6206
+ for (let t = 0; t < element.trList.length; t++) {
6207
+ const tr = element.trList[t];
6208
+ for (let d = 0; d < tr.tdList.length; d++) {
6209
+ inflateElementList(tr.tdList[d].value);
6210
+ }
6211
+ }
6212
+ }
6213
+ if (element.valueList?.length) {
6214
+ inflateElementList(element.valueList);
6215
+ }
6216
+ if (element.control?.value?.length) {
6217
+ inflateElementList(element.control.value);
6218
+ }
6219
+ if (isHistoryTextSnapshotElement(element) && element.value?.length > 1) {
6220
+ const textList = splitText(element.value);
6221
+ elementList.splice(
6222
+ i,
6223
+ 1,
6224
+ ...textList.map((value) => ({
6225
+ ...element,
6226
+ value
6227
+ }))
6228
+ );
6229
+ i += textList.length;
6230
+ continue;
6231
+ }
6232
+ i++;
6233
+ }
6234
+ return elementList;
6077
6235
  }
6078
6236
  function getIsBlockElement(element) {
6079
6237
  return !!element?.type && (BLOCK_ELEMENT_TYPE.includes(element.type) || element.imgDisplay === "inline" /* INLINE */);
@@ -6489,7 +6647,10 @@ var Cursor = class {
6489
6647
  const agentCursorDom = this.cursorAgent.getAgentCursorDom();
6490
6648
  if (document.activeElement !== agentCursorDom) {
6491
6649
  agentCursorDom.focus({ preventScroll: true });
6650
+ const scrollContainer = findScrollContainer(this.container);
6651
+ const { scrollLeft, scrollTop } = scrollContainer;
6492
6652
  agentCursorDom.setSelectionRange(0, 0);
6653
+ scrollContainer.scroll(scrollLeft, scrollTop);
6493
6654
  }
6494
6655
  }
6495
6656
  drawCursor(payload) {
@@ -6559,7 +6720,6 @@ var Cursor = class {
6559
6720
  this.recoveryCursor();
6560
6721
  return;
6561
6722
  }
6562
- const oldTop = this.cursorDom.style.top;
6563
6723
  const isReadonly = this.draw.isReadonly();
6564
6724
  this.cursorDom.style.width = `${width * scale}px`;
6565
6725
  this.cursorDom.style.backgroundColor = color;
@@ -6573,10 +6733,7 @@ var Cursor = class {
6573
6733
  this._clearBlinkTimeout();
6574
6734
  }
6575
6735
  nextTick2(() => {
6576
- this.moveCursorToVisible({
6577
- cursorPosition,
6578
- direction: parseInt(oldTop) > cursorTop ? "top" /* UP */ : "down" /* DOWN */
6579
- });
6736
+ this.moveCursorToVisible({ cursorPosition });
6580
6737
  });
6581
6738
  }
6582
6739
  recoveryCursor() {
@@ -6584,41 +6741,44 @@ var Cursor = class {
6584
6741
  this._clearBlinkTimeout();
6585
6742
  }
6586
6743
  moveCursorToVisible(payload) {
6587
- const { cursorPosition, direction } = payload;
6588
- if (!cursorPosition || !direction) return;
6744
+ const { cursorPosition } = payload;
6745
+ if (!cursorPosition) return;
6589
6746
  const {
6590
6747
  pageNo,
6591
- coordinate: { leftTop, leftBottom }
6748
+ coordinate: { leftTop },
6749
+ ascent,
6750
+ metrics: { boundingBoxAscent, boundingBoxDescent }
6592
6751
  } = cursorPosition;
6593
- const prePageY = pageNo * (this.draw.getHeight() + this.draw.getPageGap()) + this.container.getBoundingClientRect().top;
6594
- const isUp = direction === "top" /* UP */;
6595
- const x = leftBottom[0];
6596
- const cursorTop = leftTop[1] + cursorPosition.ascent - cursorPosition.metrics.boundingBoxAscent;
6597
- const cursorBottom = cursorTop + cursorPosition.metrics.boundingBoxAscent + cursorPosition.metrics.boundingBoxDescent;
6598
- const y = isUp ? cursorTop + prePageY : cursorBottom + prePageY;
6752
+ const containerRect = this.container.getBoundingClientRect();
6753
+ const pageOffset = pageNo * (this.draw.getHeight() + this.draw.getPageGap());
6754
+ const cursorTopViewport = containerRect.top + pageOffset + leftTop[1] + ascent - boundingBoxAscent;
6755
+ const cursorBottomViewport = cursorTopViewport + boundingBoxAscent + boundingBoxDescent;
6599
6756
  const scrollContainer = findScrollContainer(this.container);
6600
- const rect = {
6601
- left: 0,
6602
- right: 0,
6603
- top: 0,
6604
- bottom: 0
6605
- };
6757
+ let visibleTop;
6758
+ let visibleBottom;
6606
6759
  if (scrollContainer === document.documentElement) {
6607
- rect.right = window.innerWidth;
6608
- rect.bottom = window.innerHeight;
6760
+ visibleTop = 0;
6761
+ visibleBottom = window.innerHeight;
6609
6762
  } else {
6610
- const { left: left2, right: right2, top, bottom } = scrollContainer.getBoundingClientRect();
6611
- rect.left = left2;
6612
- rect.right = right2;
6613
- rect.top = top;
6614
- rect.bottom = bottom;
6615
- }
6616
- const { maskMargin } = this.options;
6617
- rect.top += maskMargin[0];
6618
- rect.bottom -= maskMargin[2];
6619
- if (!(x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom)) {
6620
- const { scrollLeft, scrollTop } = scrollContainer;
6621
- isUp ? scrollContainer.scroll(scrollLeft, scrollTop - (rect.top - y)) : scrollContainer.scroll(scrollLeft, scrollTop + y - rect.bottom);
6763
+ const scrollRect = scrollContainer.getBoundingClientRect();
6764
+ visibleTop = scrollRect.top;
6765
+ visibleBottom = scrollRect.bottom;
6766
+ }
6767
+ if (cursorTopViewport >= visibleTop && cursorBottomViewport <= visibleBottom) {
6768
+ return;
6769
+ }
6770
+ const scrollPadding = (boundingBoxAscent + boundingBoxDescent) * this.options.scrollPaddingLines;
6771
+ const { scrollLeft, scrollTop } = scrollContainer;
6772
+ if (cursorTopViewport < visibleTop) {
6773
+ scrollContainer.scroll(
6774
+ scrollLeft,
6775
+ scrollTop - (visibleTop - cursorTopViewport) - scrollPadding
6776
+ );
6777
+ } else {
6778
+ scrollContainer.scroll(
6779
+ scrollLeft,
6780
+ scrollTop + (cursorBottomViewport - visibleBottom) + scrollPadding
6781
+ );
6622
6782
  }
6623
6783
  }
6624
6784
  };
@@ -7744,7 +7904,8 @@ function backspace(evt, host) {
7744
7904
  } else {
7745
7905
  rangeManager.setRange(curIndex, curIndex);
7746
7906
  draw.render({
7747
- curIndex
7907
+ curIndex,
7908
+ dirtyStartIndex: curIndex + 1
7748
7909
  });
7749
7910
  }
7750
7911
  }
@@ -7886,7 +8047,8 @@ function del(evt, host) {
7886
8047
  } else {
7887
8048
  rangeManager.setRange(curIndex, curIndex);
7888
8049
  draw.render({
7889
- curIndex
8050
+ curIndex,
8051
+ dirtyStartIndex: curIndex + 1
7890
8052
  });
7891
8053
  }
7892
8054
  }
@@ -8590,8 +8752,7 @@ function updown(evt, host) {
8590
8752
  });
8591
8753
  if (!isCollapsed) {
8592
8754
  draw.getCursor().moveCursorToVisible({
8593
- cursorPosition: positionList[isUp ? anchorStartIndex : anchorEndIndex],
8594
- direction: isUp ? "top" /* UP */ : "down" /* DOWN */
8755
+ cursorPosition: positionList[isUp ? anchorStartIndex : anchorEndIndex]
8595
8756
  });
8596
8757
  }
8597
8758
  }
@@ -8729,10 +8890,12 @@ function input(data2, host) {
8729
8890
  if (~curIndex) {
8730
8891
  rangeManager.setRange(curIndex, curIndex);
8731
8892
  const isWordBoundary = !isComposing && /[\s\p{P}]/u.test(data2);
8893
+ const dirtyStartIndex = startIndex + 1;
8732
8894
  draw.render({
8733
8895
  curIndex,
8734
8896
  isSubmitHistory: !isComposing,
8735
- isInputHistory: !isComposing && !isWordBoundary
8897
+ isInputHistory: !isComposing && !isWordBoundary,
8898
+ dirtyStartIndex
8736
8899
  });
8737
8900
  }
8738
8901
  if (isComposing && ~curIndex) {
@@ -9416,7 +9579,7 @@ var HistoryManager = class {
9416
9579
  const pop = this.undoStack.pop();
9417
9580
  this.redoStack.push(pop);
9418
9581
  if (this.undoStack.length) {
9419
- this.undoStack[this.undoStack.length - 1]();
9582
+ this.undoStack[this.undoStack.length - 1].restore();
9420
9583
  }
9421
9584
  }
9422
9585
  }
@@ -9424,11 +9587,11 @@ var HistoryManager = class {
9424
9587
  if (this.redoStack.length) {
9425
9588
  const pop = this.redoStack.pop();
9426
9589
  this.undoStack.push(pop);
9427
- pop();
9590
+ pop.restore();
9428
9591
  }
9429
9592
  }
9430
- execute(fn) {
9431
- this.undoStack.push(fn);
9593
+ execute(entry) {
9594
+ this.undoStack.push(this._normalizeEntry(entry));
9432
9595
  if (this.redoStack.length) {
9433
9596
  this.redoStack = [];
9434
9597
  }
@@ -9436,11 +9599,12 @@ var HistoryManager = class {
9436
9599
  this.undoStack.shift();
9437
9600
  }
9438
9601
  }
9439
- replaceLatest(fn) {
9602
+ replaceLatest(entry) {
9603
+ const normalizedEntry = this._normalizeEntry(entry);
9440
9604
  if (this.undoStack.length > 0) {
9441
- this.undoStack[this.undoStack.length - 1] = fn;
9605
+ this.undoStack[this.undoStack.length - 1] = normalizedEntry;
9442
9606
  } else {
9443
- this.execute(fn);
9607
+ this.execute(normalizedEntry);
9444
9608
  }
9445
9609
  if (this.redoStack.length) {
9446
9610
  this.redoStack = [];
@@ -9471,6 +9635,14 @@ var HistoryManager = class {
9471
9635
  popUndo() {
9472
9636
  return this.undoStack.pop();
9473
9637
  }
9638
+ _normalizeEntry(entry) {
9639
+ if (typeof entry === "function") {
9640
+ return {
9641
+ restore: entry
9642
+ };
9643
+ }
9644
+ return entry;
9645
+ }
9474
9646
  };
9475
9647
 
9476
9648
  // src/core/position/Position.ts
@@ -11678,6 +11850,7 @@ var ScrollObserver = class {
11678
11850
  const { intersectionPageNo, visiblePageNoList } = this.getPageVisibleInfo();
11679
11851
  this.draw.setIntersectionPageNo(intersectionPageNo);
11680
11852
  this.draw.setVisiblePageNoList(visiblePageNoList);
11853
+ this.draw.renderVisiblePages(visiblePageNoList);
11681
11854
  }, 150);
11682
11855
  this.draw = draw;
11683
11856
  this.options = draw.getOptions();
@@ -20485,6 +20658,9 @@ var Area = class {
20485
20658
  getAreaInfo() {
20486
20659
  return this.areaInfoMap;
20487
20660
  }
20661
+ clear() {
20662
+ this.areaInfoMap.clear();
20663
+ }
20488
20664
  getActiveAreaId() {
20489
20665
  if (!this.areaInfoMap.size) return null;
20490
20666
  const { startIndex } = this.range.getRange();
@@ -20876,6 +21052,7 @@ var Draw = class {
20876
21052
  this.container = this._wrapContainer(rootContainer);
20877
21053
  this.pageList = [];
20878
21054
  this.ctxList = [];
21055
+ this.pageRenderVersionList = [];
20879
21056
  this.pageNo = 0;
20880
21057
  this.renderCount = 0;
20881
21058
  this.pagePixelRatio = null;
@@ -20888,6 +21065,7 @@ var Draw = class {
20888
21065
  this._formatContainer();
20889
21066
  this.pageContainer = this._createPageContainer();
20890
21067
  this._createPage(0);
21068
+ this.measureCtx = this._createMeasureContext();
20891
21069
  this.i18n = new I18n(options.locale);
20892
21070
  this.historyManager = new HistoryManager(this);
20893
21071
  this.position = new Position(this);
@@ -20952,6 +21130,8 @@ var Draw = class {
20952
21130
  this.pageRowList = [];
20953
21131
  this.painterStyle = null;
20954
21132
  this.painterOptions = null;
21133
+ this.elementFontCache = /* @__PURE__ */ new WeakMap();
21134
+ this.elementRowMarginCache = /* @__PURE__ */ new WeakMap();
20955
21135
  this.visiblePageNoList = [];
20956
21136
  this.intersectionPageNo = 0;
20957
21137
  this.lazyRenderIntersectionObserver = null;
@@ -21118,7 +21298,9 @@ var Draw = class {
21118
21298
  getContextInnerWidth() {
21119
21299
  const positionContext = this.position.getPositionContext();
21120
21300
  if (positionContext.isTable) {
21121
- const td = this.resolveTableCellContext(this.getOriginalElementList())?.td;
21301
+ const td = this.resolveTableCellContext(
21302
+ this.getOriginalElementList()
21303
+ )?.td;
21122
21304
  if (!td) return this.getColumnWidth() / this.options.scale;
21123
21305
  const tdPadding = this.getTdPadding();
21124
21306
  return td.width - tdPadding[1] - tdPadding[3];
@@ -21171,6 +21353,7 @@ var Draw = class {
21171
21353
  return this.visiblePageNoList;
21172
21354
  }
21173
21355
  setVisiblePageNoList(payload) {
21356
+ if (isArrayEqual(this.visiblePageNoList, payload)) return;
21174
21357
  this.visiblePageNoList = payload;
21175
21358
  if (this.listener.visiblePageNoListChange) {
21176
21359
  this.listener.visiblePageNoListChange(this.visiblePageNoList);
@@ -21183,6 +21366,7 @@ var Draw = class {
21183
21366
  return this.intersectionPageNo;
21184
21367
  }
21185
21368
  setIntersectionPageNo(payload) {
21369
+ if (this.intersectionPageNo === payload) return;
21186
21370
  this.intersectionPageNo = payload;
21187
21371
  if (this.listener.intersectionPageNoChange) {
21188
21372
  this.listener.intersectionPageNoChange(this.intersectionPageNo);
@@ -21210,7 +21394,9 @@ var Draw = class {
21210
21394
  candidateIndexes.push(context.index);
21211
21395
  }
21212
21396
  if (context.tableId) {
21213
- const tableIndex = sourceElementList.findIndex((el) => el.id === context.tableId);
21397
+ const tableIndex = sourceElementList.findIndex(
21398
+ (el) => el.id === context.tableId
21399
+ );
21214
21400
  if (~tableIndex && !candidateIndexes.includes(tableIndex)) {
21215
21401
  candidateIndexes.push(tableIndex);
21216
21402
  }
@@ -21319,9 +21505,7 @@ var Draw = class {
21319
21505
  return this.header.getElementList();
21320
21506
  }
21321
21507
  getTableElementList(sourceElementList) {
21322
- const splitCellSelectionContext = this.getSplitCellSelectionContext(
21323
- sourceElementList
21324
- );
21508
+ const splitCellSelectionContext = this.getSplitCellSelectionContext(sourceElementList);
21325
21509
  if (splitCellSelectionContext) {
21326
21510
  return splitCellSelectionContext.value;
21327
21511
  }
@@ -21445,10 +21629,7 @@ var Draw = class {
21445
21629
  positionContext.trId = continuationTr.id;
21446
21630
  positionContext.tableId = tableId;
21447
21631
  this.position.setPositionContext(positionContext);
21448
- this.range.setRange(
21449
- continuationCursorIndex,
21450
- continuationCursorIndex
21451
- );
21632
+ this.range.setRange(continuationCursorIndex, continuationCursorIndex);
21452
21633
  this.pendingTableCursorIndex = continuationCursorIndex;
21453
21634
  return true;
21454
21635
  }
@@ -21508,7 +21689,10 @@ var Draw = class {
21508
21689
  });
21509
21690
  const splitCellSelection = this.range.getSplitCellSelection();
21510
21691
  if (splitCellSelection) {
21511
- const curIndex2 = this.replaceSplitCellSelection(payload, splitCellSelection);
21692
+ const curIndex2 = this.replaceSplitCellSelection(
21693
+ payload,
21694
+ splitCellSelection
21695
+ );
21512
21696
  if (~curIndex2) {
21513
21697
  this.range.setRange(curIndex2, curIndex2);
21514
21698
  this.render({
@@ -21638,12 +21822,7 @@ var Draw = class {
21638
21822
  trId: rootCellContext.tr.id,
21639
21823
  tdId: rootTd.id
21640
21824
  });
21641
- this.spliceElementList(
21642
- rootTd.value,
21643
- 1,
21644
- rootTd.value.length - 1,
21645
- payload
21646
- );
21825
+ this.spliceElementList(rootTd.value, 1, rootTd.value.length - 1, payload);
21647
21826
  rootTd.rowList = void 0;
21648
21827
  rootTd.positionList = void 0;
21649
21828
  rootTd.mainHeight = void 0;
@@ -22063,6 +22242,15 @@ var Draw = class {
22063
22242
  this._initPageContext(ctx);
22064
22243
  this.pageList.push(canvas);
22065
22244
  this.ctxList.push(ctx);
22245
+ this.pageRenderVersionList.push(0);
22246
+ }
22247
+ _createMeasureContext() {
22248
+ const canvas = document.createElement("canvas");
22249
+ const ctx = canvas.getContext("2d");
22250
+ ctx.letterSpacing = "0px";
22251
+ ctx.wordSpacing = "0px";
22252
+ ctx.direction = "ltr";
22253
+ return ctx;
22066
22254
  }
22067
22255
  _initPageContext(ctx) {
22068
22256
  const dpr = this.getPagePixelRatio();
@@ -22075,8 +22263,22 @@ var Draw = class {
22075
22263
  const { defaultSize, defaultFont } = this.options;
22076
22264
  const font = el.font || defaultFont;
22077
22265
  const size = el.actualSize || el.size || defaultSize;
22266
+ const cache = this.elementFontCache.get(el);
22267
+ if (cache && cache.scale === scale && cache.font === font && cache.size === size && cache.actualSize === el.actualSize && cache.bold === el.bold && cache.italic === el.italic) {
22268
+ return cache.style;
22269
+ }
22078
22270
  const sizePx = size * (96 / 72) * scale;
22079
- return `${el.italic ? "italic " : ""}${el.bold ? "bold " : ""}${sizePx}px ${font}`;
22271
+ const style = `${el.italic ? "italic " : ""}${el.bold ? "bold " : ""}${sizePx}px ${font}`;
22272
+ this.elementFontCache.set(el, {
22273
+ scale,
22274
+ font,
22275
+ size,
22276
+ actualSize: el.actualSize,
22277
+ bold: el.bold,
22278
+ italic: el.italic,
22279
+ style
22280
+ });
22281
+ return style;
22080
22282
  }
22081
22283
  getElementSize(el) {
22082
22284
  return el.actualSize || el.size || this.options.defaultSize;
@@ -22089,13 +22291,25 @@ var Draw = class {
22089
22291
  scale
22090
22292
  } = this.options;
22091
22293
  const fontSize = el.size || defaultSize;
22294
+ const rowMarginValue = el.rowMargin ?? defaultRowMargin;
22295
+ const cache = this.elementRowMarginCache.get(el);
22296
+ if (cache && cache.scale === scale && cache.size === fontSize && cache.rowMargin === rowMarginValue) {
22297
+ return cache.value;
22298
+ }
22092
22299
  let ratio = 1;
22093
22300
  if (fontSize < 12) {
22094
22301
  ratio = fontSize / 12;
22095
22302
  } else if (fontSize > 30) {
22096
22303
  ratio = 1 + (fontSize - 30) / 30;
22097
22304
  }
22098
- return defaultBasicRowMarginHeight * ratio * (el.rowMargin ?? defaultRowMargin) * scale;
22305
+ const value = defaultBasicRowMarginHeight * ratio * rowMarginValue * scale;
22306
+ this.elementRowMarginCache.set(el, {
22307
+ scale,
22308
+ size: fontSize,
22309
+ rowMargin: rowMarginValue,
22310
+ value
22311
+ });
22312
+ return value;
22099
22313
  }
22100
22314
  createListStateSeed(initialListState) {
22101
22315
  const listLevelIndex = /* @__PURE__ */ new Map();
@@ -22174,7 +22388,12 @@ var Draw = class {
22174
22388
  pageHeight = 0,
22175
22389
  mainOuterHeight = 0,
22176
22390
  surroundElementList = [],
22177
- initialListState
22391
+ initialListState,
22392
+ hasListElement = true,
22393
+ fromIndex = 0,
22394
+ initialY = startY,
22395
+ initialPageNo = 0,
22396
+ initialRowIndex = 0
22178
22397
  } = payload;
22179
22398
  const {
22180
22399
  defaultSize,
@@ -22183,27 +22402,62 @@ var Draw = class {
22183
22402
  defaultTabWidth
22184
22403
  } = this.options;
22185
22404
  const defaultBasicRowMarginHeight = this.getDefaultBasicRowMarginHeight();
22186
- const canvas = document.createElement("canvas");
22187
- const ctx = canvas.getContext("2d");
22188
- const listStyleMap = this.listParticle.computeListStyle(ctx, elementList);
22405
+ const ctx = this.measureCtx;
22406
+ ctx.save();
22407
+ ctx.font = "10px sans-serif";
22408
+ ctx.textAlign = "start";
22409
+ ctx.textBaseline = "alphabetic";
22410
+ const listStyleMap = hasListElement ? this.listParticle.computeListStyle(ctx, elementList) : /* @__PURE__ */ new Map();
22411
+ const wordMeasureCache = /* @__PURE__ */ new Map();
22412
+ const getWordMeasure = (curIndex, elementFont) => {
22413
+ const cache = wordMeasureCache.get(curIndex);
22414
+ if (cache) return cache;
22415
+ let endIndex = curIndex;
22416
+ while (endIndex < elementList.length) {
22417
+ const measureElement = elementList[endIndex];
22418
+ if (measureElement.type && measureElement.type !== "text" /* TEXT */ || !this.LETTER_REG.test(measureElement.value)) {
22419
+ break;
22420
+ }
22421
+ if (this.getElementFont(measureElement) !== elementFont) {
22422
+ const fallbackWord = this.textParticle.measureWord(
22423
+ ctx,
22424
+ elementList,
22425
+ curIndex
22426
+ );
22427
+ wordMeasureCache.set(curIndex, fallbackWord);
22428
+ return fallbackWord;
22429
+ }
22430
+ endIndex++;
22431
+ }
22432
+ const endElement = elementList[endIndex] || null;
22433
+ let suffixWidth = 0;
22434
+ for (let i = endIndex - 1; i >= curIndex; i--) {
22435
+ suffixWidth += this.textParticle.measureText(ctx, elementList[i]).width;
22436
+ wordMeasureCache.set(i, {
22437
+ width: suffixWidth,
22438
+ endElement
22439
+ });
22440
+ }
22441
+ return wordMeasureCache.get(curIndex);
22442
+ };
22189
22443
  const rowList = [];
22190
- if (elementList.length) {
22444
+ if (elementList.length && fromIndex < elementList.length) {
22191
22445
  rowList.push({
22192
22446
  width: 0,
22193
22447
  height: 0,
22194
22448
  ascent: 0,
22195
22449
  elementList: [],
22196
- startIndex: 0,
22197
- rowIndex: 0,
22198
- rowFlex: elementList?.[0]?.rowFlex || elementList?.[1]?.rowFlex
22450
+ startIndex: fromIndex,
22451
+ rowIndex: initialRowIndex,
22452
+ rowFlex: elementList?.[fromIndex]?.rowFlex || elementList?.[fromIndex + 1]?.rowFlex
22199
22453
  });
22200
22454
  }
22201
22455
  let x = startX;
22202
- let y = startY;
22203
- let pageNo = 0;
22456
+ let y = initialY;
22457
+ let pageNo = initialPageNo;
22204
22458
  const listState = this.createListStateSeed(initialListState);
22205
22459
  let controlRealWidth = 0;
22206
- for (let i = 0; i < elementList.length; i++) {
22460
+ for (let i = fromIndex; i < elementList.length; i++) {
22207
22461
  const curRow = rowList[rowList.length - 1];
22208
22462
  const element = elementList[i];
22209
22463
  const rowMargin = this.getElementRowMargin(element);
@@ -22249,9 +22503,7 @@ var Draw = class {
22249
22503
  } else if (element.type === "table" /* TABLE */) {
22250
22504
  let activeSplitRange;
22251
22505
  let mergedSplitFallback;
22252
- const logicalSplitCursor = this.getCollapsedSplitTableCursorContext(
22253
- element
22254
- );
22506
+ const logicalSplitCursor = this.getCollapsedSplitTableCursorContext(element);
22255
22507
  if (element.pagingId) {
22256
22508
  let tableIndex = i + 1;
22257
22509
  let combineCount = 0;
@@ -22856,16 +23108,14 @@ var Draw = class {
22856
23108
  element.actualSize = Math.ceil(size * 0.6);
22857
23109
  }
22858
23110
  metrics.height = (element.actualSize || size) * scale;
22859
- ctx.font = this.getElementFont(element);
23111
+ const elementFont = this.getElementFont(element);
23112
+ ctx.font = elementFont;
22860
23113
  const fontMetrics = this.textParticle.measureText(ctx, element);
22861
23114
  metrics.width = fontMetrics.width * scale;
22862
23115
  if (element.letterSpacing) {
22863
23116
  metrics.width += element.letterSpacing * scale;
22864
23117
  }
22865
- const basisMetrics = this.textParticle.measureBasisWord(
22866
- ctx,
22867
- element.font
22868
- );
23118
+ const basisMetrics = this.textParticle.measureBasisWord(ctx, elementFont);
22869
23119
  metrics.boundingBoxAscent = basisMetrics.fontBoundingBoxAscent * scale;
22870
23120
  metrics.boundingBoxDescent = basisMetrics.fontBoundingBoxDescent * scale;
22871
23121
  if (element.type === "superscript" /* SUPERSCRIPT */) {
@@ -22902,11 +23152,7 @@ var Draw = class {
22902
23152
  if ((!preElement?.type || preElement?.type === "text" /* TEXT */) && (!element.type || element.type === "text" /* TEXT */)) {
22903
23153
  const word = `${preElement?.value || ""}${element.value}`;
22904
23154
  if (this.WORD_LIKE_REG.test(word)) {
22905
- const { width, endElement } = this.textParticle.measureWord(
22906
- ctx,
22907
- elementList,
22908
- i
22909
- );
23155
+ const { width, endElement } = getWordMeasure(i, ctx.font);
22910
23156
  const wordWidth = width * scale;
22911
23157
  if (endElement && wordWidth <= availableWidth) {
22912
23158
  curRowWidth += wordWidth;
@@ -23039,6 +23285,7 @@ var Draw = class {
23039
23285
  x += metrics.width;
23040
23286
  }
23041
23287
  }
23288
+ ctx.restore();
23042
23289
  return rowList;
23043
23290
  }
23044
23291
  _applyRowSpacing() {
@@ -23631,30 +23878,11 @@ var Draw = class {
23631
23878
  if (this.isGraffitiMode()) {
23632
23879
  this.graffiti.render(ctx, pageNo);
23633
23880
  }
23881
+ this.pageRenderVersionList[pageNo] = this.renderCount;
23634
23882
  }
23635
23883
  _disconnectLazyRender() {
23636
23884
  this.lazyRenderIntersectionObserver?.disconnect();
23637
- }
23638
- _lazyRender() {
23639
- const positionList = this.position.getOriginalMainPositionList();
23640
- const elementList = this.getOriginalMainElementList();
23641
- this._disconnectLazyRender();
23642
- this.lazyRenderIntersectionObserver = new IntersectionObserver((entries) => {
23643
- entries.forEach((entry) => {
23644
- if (entry.isIntersecting) {
23645
- const index = Number(entry.target.dataset.index);
23646
- this._drawPage({
23647
- elementList,
23648
- positionList,
23649
- rowList: this.pageRowList[index],
23650
- pageNo: index
23651
- });
23652
- }
23653
- });
23654
- });
23655
- this.pageList.forEach((el) => {
23656
- this.lazyRenderIntersectionObserver.observe(el);
23657
- });
23885
+ this.lazyRenderIntersectionObserver = null;
23658
23886
  }
23659
23887
  _immediateRender() {
23660
23888
  const positionList = this.position.getOriginalMainPositionList();
@@ -23668,6 +23896,100 @@ var Draw = class {
23668
23896
  });
23669
23897
  }
23670
23898
  }
23899
+ _collectMainRenderMeta() {
23900
+ const surroundElementList = [];
23901
+ let hasAreaElement = false;
23902
+ let hasListElement = false;
23903
+ let hasStructuralElement = false;
23904
+ for (let i = 0; i < this.elementList.length; i++) {
23905
+ const element = this.elementList[i];
23906
+ if (!hasAreaElement && element.areaId) {
23907
+ hasAreaElement = true;
23908
+ }
23909
+ if (!hasListElement && element.listId) {
23910
+ hasListElement = true;
23911
+ }
23912
+ if (!hasStructuralElement && (element.type === "table" /* TABLE */ || element.type === "block" /* BLOCK */ || element.type === "pageBreak" /* PAGE_BREAK */ || element.type === "columnBreak" /* COLUMN_BREAK */ || element.type === "image" /* IMAGE */ || element.type === "latex" /* LATEX */ || element.type === "separator" /* SEPARATOR */)) {
23913
+ hasStructuralElement = true;
23914
+ }
23915
+ if (element.imgDisplay === "surround" /* SURROUND */) {
23916
+ surroundElementList.push(element);
23917
+ }
23918
+ }
23919
+ return {
23920
+ hasAreaElement,
23921
+ hasListElement,
23922
+ hasStructuralElement,
23923
+ surroundElementList
23924
+ };
23925
+ }
23926
+ _getIncrementalRestartState(dirtyStartIndex, rowList, pageRowList, startY) {
23927
+ if (!rowList.length || !pageRowList.length) return null;
23928
+ const searchIndex = Math.max(dirtyStartIndex - 1, 0);
23929
+ let restartRowIndex = -1;
23930
+ for (let i = 0; i < rowList.length; i++) {
23931
+ if (rowList[i].startIndex <= searchIndex) {
23932
+ restartRowIndex = i;
23933
+ } else {
23934
+ break;
23935
+ }
23936
+ }
23937
+ if (restartRowIndex < 0) return null;
23938
+ if (restartRowIndex > 0 && this.elementList[rowList[restartRowIndex].startIndex]?.value === ZERO && !this.elementList[rowList[restartRowIndex].startIndex]?.listWrap) {
23939
+ restartRowIndex -= 1;
23940
+ }
23941
+ const restartRow = rowList[restartRowIndex];
23942
+ const fromIndex = Math.min(restartRow.startIndex, this.elementList.length);
23943
+ let initialPageNo = 0;
23944
+ let initialY = startY;
23945
+ let absoluteRowIndex = 0;
23946
+ let isFound = false;
23947
+ for (let pageNo = 0; pageNo < pageRowList.length; pageNo++) {
23948
+ const rows = pageRowList[pageNo];
23949
+ let y = startY;
23950
+ for (let rowNo = 0; rowNo < rows.length; rowNo++) {
23951
+ if (absoluteRowIndex === restartRowIndex) {
23952
+ initialPageNo = pageNo;
23953
+ initialY = y;
23954
+ isFound = true;
23955
+ break;
23956
+ }
23957
+ const row = rows[rowNo];
23958
+ y += (row.offsetY || 0) + (row.spaceAbove || 0) + row.height + (row.spaceBelow || 0);
23959
+ absoluteRowIndex++;
23960
+ }
23961
+ if (isFound) break;
23962
+ }
23963
+ if (!isFound) return null;
23964
+ return {
23965
+ fromIndex,
23966
+ initialY,
23967
+ initialPageNo,
23968
+ initialRowIndex: restartRow.rowIndex,
23969
+ initialListState: this.getListStateBeforeIndex(this.elementList, fromIndex),
23970
+ prefixRows: rowList.slice(0, restartRowIndex)
23971
+ };
23972
+ }
23973
+ renderVisiblePages(pageNoList) {
23974
+ const positionList = this.position.getOriginalMainPositionList();
23975
+ const elementList = this.getOriginalMainElementList();
23976
+ const targetPageNoList = pageNoList ?? this.visiblePageNoList;
23977
+ if (!targetPageNoList?.length) return;
23978
+ const renderedPageNoSet = /* @__PURE__ */ new Set();
23979
+ for (let i = 0; i < targetPageNoList.length; i++) {
23980
+ const pageNo = targetPageNoList[i];
23981
+ if (renderedPageNoSet.has(pageNo) || pageNo < 0 || pageNo >= this.pageRowList.length || this.pageRenderVersionList[pageNo] === this.renderCount) {
23982
+ continue;
23983
+ }
23984
+ renderedPageNoSet.add(pageNo);
23985
+ this._drawPage({
23986
+ elementList,
23987
+ positionList,
23988
+ rowList: this.pageRowList[pageNo],
23989
+ pageNo
23990
+ });
23991
+ }
23992
+ }
23671
23993
  render(payload) {
23672
23994
  this.renderCount++;
23673
23995
  const { header, footer } = this.options;
@@ -23679,15 +24001,19 @@ var Draw = class {
23679
24001
  isLazy = true,
23680
24002
  isInit = false,
23681
24003
  isSourceHistory = false,
23682
- isFirstRender = false
24004
+ isFirstRender = false,
24005
+ dirtyStartIndex
23683
24006
  } = payload || {};
23684
24007
  let { curIndex } = payload || {};
23685
24008
  this.pendingTableCursorIndex = void 0;
23686
24009
  const innerWidth = this.getInnerWidth();
23687
24010
  const columnWidth = this.getColumnWidth();
23688
24011
  const isPagingMode = this.getIsPagingMode();
24012
+ const columnCount = this.getColumnCount();
23689
24013
  const oldPageSize = this.pageRowList.length;
23690
24014
  if (isCompute) {
24015
+ const oldRowList = this.rowList;
24016
+ const oldPageRowList = this.pageRowList;
23691
24017
  this.position.setFloatPositionList([]);
23692
24018
  if (isPagingMode) {
23693
24019
  if (!header.disabled) {
@@ -23703,8 +24029,13 @@ var Draw = class {
23703
24029
  const mainOuterHeight = this.getMainOuterHeight();
23704
24030
  const startX = margins[3];
23705
24031
  const startY = margins[0] + extraHeight;
23706
- const surroundElementList = pickSurroundElementList(this.elementList);
23707
- this.rowList = this.computeRowList({
24032
+ const {
24033
+ hasAreaElement,
24034
+ hasListElement,
24035
+ hasStructuralElement,
24036
+ surroundElementList
24037
+ } = this._collectMainRenderMeta();
24038
+ const rowListPayload = {
23708
24039
  startX,
23709
24040
  startY,
23710
24041
  pageHeight,
@@ -23712,12 +24043,41 @@ var Draw = class {
23712
24043
  isPagingMode,
23713
24044
  innerWidth: columnWidth,
23714
24045
  surroundElementList,
24046
+ hasListElement,
23715
24047
  elementList: this.elementList
23716
- });
24048
+ };
24049
+ const canUseIncrementalMainRows = dirtyStartIndex !== void 0 && dirtyStartIndex >= 0 && !isInit && !isSourceHistory && isPagingMode && columnCount === 1 && !hasAreaElement && !hasStructuralElement && surroundElementList.length === 0 && oldRowList.length > 0 && oldPageRowList.length > 0;
24050
+ if (canUseIncrementalMainRows) {
24051
+ const restartState = this._getIncrementalRestartState(
24052
+ dirtyStartIndex,
24053
+ oldRowList,
24054
+ oldPageRowList,
24055
+ startY
24056
+ );
24057
+ if (restartState) {
24058
+ const suffixRows = this.computeRowList({
24059
+ ...rowListPayload,
24060
+ fromIndex: restartState.fromIndex,
24061
+ initialY: restartState.initialY,
24062
+ initialPageNo: restartState.initialPageNo,
24063
+ initialRowIndex: restartState.initialRowIndex,
24064
+ initialListState: restartState.initialListState
24065
+ });
24066
+ this.rowList = restartState.prefixRows.concat(suffixRows);
24067
+ } else {
24068
+ this.rowList = this.computeRowList(rowListPayload);
24069
+ }
24070
+ } else {
24071
+ this.rowList = this.computeRowList(rowListPayload);
24072
+ }
23717
24073
  this._applyRowSpacing();
23718
24074
  this.pageRowList = this._computePageList();
23719
24075
  this.position.computePositionList();
23720
- this.area.compute();
24076
+ if (hasAreaElement) {
24077
+ this.area.compute();
24078
+ } else {
24079
+ this.area.clear();
24080
+ }
23721
24081
  if (!this.isPrintMode()) {
23722
24082
  const searchKeyword = this.search.getSearchKeyword();
23723
24083
  if (searchKeyword) {
@@ -23741,10 +24101,26 @@ var Draw = class {
23741
24101
  if (prePageCount > curPageCount) {
23742
24102
  const deleteCount = prePageCount - curPageCount;
23743
24103
  this.ctxList.splice(curPageCount, deleteCount);
24104
+ this.pageRenderVersionList.splice(curPageCount, deleteCount);
23744
24105
  this.pageList.splice(curPageCount, deleteCount).forEach((page) => page.remove());
23745
24106
  }
23746
24107
  if (isLazy && isPagingMode) {
23747
- this._lazyRender();
24108
+ let visiblePageNoList = this.visiblePageNoList.filter(
24109
+ (pageNo) => pageNo >= 0 && pageNo < curPageCount
24110
+ );
24111
+ let intersectionPageNo = Math.min(
24112
+ this.intersectionPageNo,
24113
+ Math.max(curPageCount - 1, 0)
24114
+ );
24115
+ if (!visiblePageNoList.length || oldPageSize !== curPageCount || intersectionPageNo >= curPageCount) {
24116
+ const visibleInfo = this.scrollObserver.getPageVisibleInfo();
24117
+ intersectionPageNo = visibleInfo.intersectionPageNo;
24118
+ visiblePageNoList = visibleInfo.visiblePageNoList;
24119
+ this.setIntersectionPageNo(intersectionPageNo);
24120
+ this.setVisiblePageNoList(visiblePageNoList);
24121
+ }
24122
+ const renderPageNoList = visiblePageNoList.length ? visiblePageNoList : [intersectionPageNo];
24123
+ this.renderVisiblePages(renderPageNoList);
23748
24124
  } else {
23749
24125
  this._immediateRender();
23750
24126
  }
@@ -23793,7 +24169,9 @@ var Draw = class {
23793
24169
  const positionContext = this.position.getPositionContext();
23794
24170
  const positionList = this.position.getPositionList();
23795
24171
  if (positionContext.isTable) {
23796
- const tablePositionList = this.resolveTableCellContext(this.getOriginalElementList())?.td.positionList;
24172
+ const tablePositionList = this.resolveTableCellContext(
24173
+ this.getOriginalElementList()
24174
+ )?.td.positionList;
23797
24175
  if (curIndex === void 0 && tablePositionList) {
23798
24176
  curIndex = tablePositionList.length - 1;
23799
24177
  }
@@ -23820,36 +24198,51 @@ var Draw = class {
23820
24198
  return curIndex;
23821
24199
  }
23822
24200
  submitHistory(curIndex, isInput = false) {
23823
- const positionContext = this.position.getPositionContext();
23824
- const oldElementList = getSlimCloneElementList(this.elementList);
23825
- const oldHeaderElementList = getSlimCloneElementList(
23826
- this.header.getElementList()
23827
- );
23828
- const oldFooterElementList = getSlimCloneElementList(
23829
- this.footer.getElementList()
23830
- );
23831
- const oldRange = deepClone(this.range.getRange());
23832
- const pageNo = this.pageNo;
23833
- const oldPositionContext = deepClone(positionContext);
23834
- const zone = this.zone.getZone();
23835
- const fn = () => {
23836
- this.zone.setZone(zone);
23837
- this.setPageNo(pageNo);
23838
- this.position.setPositionContext(deepClone(oldPositionContext));
23839
- this.header.setElementList(deepClone(oldHeaderElementList));
23840
- this.footer.setElementList(deepClone(oldFooterElementList));
23841
- this.elementList = deepClone(oldElementList);
23842
- this.range.replaceRange(deepClone(oldRange));
23843
- this.render({
23844
- curIndex,
23845
- isSubmitHistory: false,
23846
- isSourceHistory: true
23847
- });
24201
+ const snapshot = {
24202
+ elementList: getSlimCloneElementList(this.elementList),
24203
+ headerElementList: getSlimCloneElementList(this.header.getElementList()),
24204
+ footerElementList: getSlimCloneElementList(this.footer.getElementList()),
24205
+ range: deepClone(this.range.getRange()),
24206
+ pageNo: this.pageNo,
24207
+ positionContext: deepClone(this.position.getPositionContext()),
24208
+ zone: this.zone.getZone()
24209
+ };
24210
+ const entry = {
24211
+ restore: () => {
24212
+ const {
24213
+ elementList,
24214
+ headerElementList,
24215
+ footerElementList,
24216
+ range,
24217
+ pageNo,
24218
+ positionContext,
24219
+ zone
24220
+ } = snapshot;
24221
+ const restoredHeaderElementList = inflateElementList(
24222
+ deepClone(headerElementList)
24223
+ );
24224
+ const restoredFooterElementList = inflateElementList(
24225
+ deepClone(footerElementList)
24226
+ );
24227
+ const restoredMainElementList = inflateElementList(deepClone(elementList));
24228
+ this.zone.setZone(zone);
24229
+ this.setPageNo(pageNo);
24230
+ this.position.setPositionContext(deepClone(positionContext));
24231
+ this.header.setElementList(restoredHeaderElementList);
24232
+ this.footer.setElementList(restoredFooterElementList);
24233
+ this.elementList = restoredMainElementList;
24234
+ this.range.replaceRange(deepClone(range));
24235
+ this.render({
24236
+ curIndex,
24237
+ isSubmitHistory: false,
24238
+ isSourceHistory: true
24239
+ });
24240
+ }
23848
24241
  };
23849
24242
  if (isInput && this.historyManager.isInputGroupable()) {
23850
- this.historyManager.replaceLatest(fn);
24243
+ this.historyManager.replaceLatest(entry);
23851
24244
  } else {
23852
- this.historyManager.execute(fn);
24245
+ this.historyManager.execute(entry);
23853
24246
  }
23854
24247
  if (isInput) {
23855
24248
  this.historyManager.recordInputTime();