@hufe921/canvas-editor 0.9.17 → 0.9.19
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/canvas-editor.es.js +383 -217
- package/dist/canvas-editor.es.js.map +1 -1
- package/dist/canvas-editor.umd.js +18 -18
- package/dist/canvas-editor.umd.js.map +1 -1
- package/dist/src/editor/core/command/Command.d.ts +2 -2
- package/dist/src/editor/core/command/CommandAdapt.d.ts +2 -2
- package/dist/src/editor/core/draw/Draw.d.ts +15 -4
- package/dist/src/editor/core/draw/control/Control.d.ts +1 -0
- package/dist/src/editor/core/draw/frame/Margin.d.ts +1 -1
- package/dist/src/editor/core/draw/particle/ImageParticle.d.ts +2 -0
- package/dist/src/editor/core/observer/ImageObserver.d.ts +7 -0
- package/dist/src/editor/core/observer/SelectionObserver.d.ts +2 -4
- package/dist/src/editor/core/position/Position.d.ts +2 -0
- package/dist/src/editor/interface/Draw.d.ts +2 -8
- package/dist/src/editor/interface/Position.d.ts +15 -0
- package/dist/src/editor/interface/Row.d.ts +1 -0
- package/dist/src/editor/utils/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/canvas-editor.es.js
CHANGED
|
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
|
|
|
23
23
|
return value;
|
|
24
24
|
};
|
|
25
25
|
var index = "";
|
|
26
|
-
const version = "0.9.
|
|
26
|
+
const version = "0.9.19";
|
|
27
27
|
const ZERO = "\u200B";
|
|
28
28
|
const WRAP = "\n";
|
|
29
29
|
var RowFlex;
|
|
@@ -130,6 +130,11 @@ function mergeObject(source, target) {
|
|
|
130
130
|
}
|
|
131
131
|
return target;
|
|
132
132
|
}
|
|
133
|
+
function nextTick(fn) {
|
|
134
|
+
setTimeout(() => {
|
|
135
|
+
fn();
|
|
136
|
+
}, 0);
|
|
137
|
+
}
|
|
133
138
|
const CURSOR_AGENT_HEIGHT = 12;
|
|
134
139
|
const defaultCursorOption = {
|
|
135
140
|
width: 1,
|
|
@@ -235,11 +240,16 @@ var ImageDisplay;
|
|
|
235
240
|
})(ImageDisplay || (ImageDisplay = {}));
|
|
236
241
|
class ImageParticle {
|
|
237
242
|
constructor(draw) {
|
|
243
|
+
__publicField(this, "draw");
|
|
238
244
|
__publicField(this, "options");
|
|
239
245
|
__publicField(this, "imageCache");
|
|
246
|
+
this.draw = draw;
|
|
240
247
|
this.options = draw.getOptions();
|
|
241
248
|
this.imageCache = new Map();
|
|
242
249
|
}
|
|
250
|
+
addImageObserver(promise) {
|
|
251
|
+
this.draw.getImageObserver().add(promise);
|
|
252
|
+
}
|
|
243
253
|
render(ctx, element, x, y) {
|
|
244
254
|
const { scale } = this.options;
|
|
245
255
|
const width = element.width * scale;
|
|
@@ -248,12 +258,19 @@ class ImageParticle {
|
|
|
248
258
|
const img = this.imageCache.get(element.id);
|
|
249
259
|
ctx.drawImage(img, x, y, width, height);
|
|
250
260
|
} else {
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
261
|
+
const imageLoadPromise = new Promise((resolve, reject) => {
|
|
262
|
+
const img = new Image();
|
|
263
|
+
img.src = element.value;
|
|
264
|
+
img.onload = () => {
|
|
265
|
+
ctx.drawImage(img, x, y, width, height);
|
|
266
|
+
this.imageCache.set(element.id, img);
|
|
267
|
+
resolve(element);
|
|
268
|
+
};
|
|
269
|
+
img.onerror = (error) => {
|
|
270
|
+
reject(error);
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
this.addImageObserver(imageLoadPromise);
|
|
257
274
|
}
|
|
258
275
|
}
|
|
259
276
|
}
|
|
@@ -3201,12 +3218,19 @@ class LaTexParticle extends ImageParticle {
|
|
|
3201
3218
|
const img = this.imageCache.get(element.value);
|
|
3202
3219
|
ctx.drawImage(img, x, y, width, height);
|
|
3203
3220
|
} else {
|
|
3204
|
-
const
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3221
|
+
const laTexLoadPromise = new Promise((resolve, reject) => {
|
|
3222
|
+
const img = new Image();
|
|
3223
|
+
img.src = element.laTexSVG;
|
|
3224
|
+
img.onload = () => {
|
|
3225
|
+
ctx.drawImage(img, x, y, width, height);
|
|
3226
|
+
this.imageCache.set(element.value, img);
|
|
3227
|
+
resolve(element);
|
|
3228
|
+
};
|
|
3229
|
+
img.onerror = (error) => {
|
|
3230
|
+
reject(error);
|
|
3231
|
+
};
|
|
3232
|
+
});
|
|
3233
|
+
this.addImageObserver(laTexLoadPromise);
|
|
3210
3234
|
}
|
|
3211
3235
|
}
|
|
3212
3236
|
}
|
|
@@ -3249,7 +3273,9 @@ function formatElementList(elementList, options) {
|
|
|
3249
3273
|
const td = tr.tdList[d];
|
|
3250
3274
|
const tdId = getUUID();
|
|
3251
3275
|
td.id = tdId;
|
|
3252
|
-
formatElementList(td.value, options)
|
|
3276
|
+
formatElementList(td.value, __spreadProps(__spreadValues({}, options), {
|
|
3277
|
+
isHandleFirstElement: true
|
|
3278
|
+
}));
|
|
3253
3279
|
for (let v = 0; v < td.value.length; v++) {
|
|
3254
3280
|
const value = td.value[v];
|
|
3255
3281
|
value.tdId = tdId;
|
|
@@ -4144,8 +4170,7 @@ class CheckboxControl {
|
|
|
4144
4170
|
return data2;
|
|
4145
4171
|
}
|
|
4146
4172
|
setValue() {
|
|
4147
|
-
|
|
4148
|
-
return endIndex;
|
|
4173
|
+
return -1;
|
|
4149
4174
|
}
|
|
4150
4175
|
setSelect() {
|
|
4151
4176
|
const { control } = this.element;
|
|
@@ -4260,7 +4285,7 @@ function mousedown(evt, host) {
|
|
|
4260
4285
|
curIndex,
|
|
4261
4286
|
isSubmitHistory: isSetCheckbox,
|
|
4262
4287
|
isSetCursor: !isDirectHitImage && !isDirectHitCheckbox,
|
|
4263
|
-
|
|
4288
|
+
isCompute: false
|
|
4264
4289
|
});
|
|
4265
4290
|
}
|
|
4266
4291
|
const previewer = draw.getPreviewer();
|
|
@@ -4410,7 +4435,7 @@ function mousemove(evt, host) {
|
|
|
4410
4435
|
draw.render({
|
|
4411
4436
|
isSubmitHistory: false,
|
|
4412
4437
|
isSetCursor: false,
|
|
4413
|
-
|
|
4438
|
+
isCompute: false
|
|
4414
4439
|
});
|
|
4415
4440
|
}
|
|
4416
4441
|
const isApple = typeof navigator !== "undefined" && /Mac OS X/.test(navigator.userAgent);
|
|
@@ -4488,7 +4513,7 @@ function keydown(evt, host) {
|
|
|
4488
4513
|
value: ZERO
|
|
4489
4514
|
}, restArg);
|
|
4490
4515
|
let curIndex;
|
|
4491
|
-
if (activeControl) {
|
|
4516
|
+
if (activeControl && !control.isRangInPostfix()) {
|
|
4492
4517
|
curIndex = control.setValue([enterText]);
|
|
4493
4518
|
} else {
|
|
4494
4519
|
if (isCollapsed) {
|
|
@@ -4498,8 +4523,10 @@ function keydown(evt, host) {
|
|
|
4498
4523
|
}
|
|
4499
4524
|
curIndex = index2 + 1;
|
|
4500
4525
|
}
|
|
4501
|
-
|
|
4502
|
-
|
|
4526
|
+
if (~curIndex) {
|
|
4527
|
+
rangeManager.setRange(curIndex, curIndex);
|
|
4528
|
+
draw.render({ curIndex });
|
|
4529
|
+
}
|
|
4503
4530
|
evt.preventDefault();
|
|
4504
4531
|
} else if (evt.key === KeyMap.Left) {
|
|
4505
4532
|
if (isReadonly)
|
|
@@ -4530,7 +4557,7 @@ function keydown(evt, host) {
|
|
|
4530
4557
|
curIndex: isCollapsed2 ? anchorStartIndex : void 0,
|
|
4531
4558
|
isSetCursor: isCollapsed2,
|
|
4532
4559
|
isSubmitHistory: false,
|
|
4533
|
-
|
|
4560
|
+
isCompute: false
|
|
4534
4561
|
});
|
|
4535
4562
|
evt.preventDefault();
|
|
4536
4563
|
}
|
|
@@ -4564,7 +4591,7 @@ function keydown(evt, host) {
|
|
|
4564
4591
|
curIndex: isCollapsed2 ? anchorStartIndex : void 0,
|
|
4565
4592
|
isSetCursor: isCollapsed2,
|
|
4566
4593
|
isSubmitHistory: false,
|
|
4567
|
-
|
|
4594
|
+
isCompute: false
|
|
4568
4595
|
});
|
|
4569
4596
|
evt.preventDefault();
|
|
4570
4597
|
}
|
|
@@ -4633,7 +4660,7 @@ function keydown(evt, host) {
|
|
|
4633
4660
|
curIndex: isCollapsed2 ? anchorStartIndex : void 0,
|
|
4634
4661
|
isSetCursor: isCollapsed2,
|
|
4635
4662
|
isSubmitHistory: false,
|
|
4636
|
-
|
|
4663
|
+
isCompute: false
|
|
4637
4664
|
});
|
|
4638
4665
|
}
|
|
4639
4666
|
} else if (isMod(evt) && evt.key === KeyMap.Z) {
|
|
@@ -4675,7 +4702,6 @@ function keydown(evt, host) {
|
|
|
4675
4702
|
}
|
|
4676
4703
|
}
|
|
4677
4704
|
function input(data2, host) {
|
|
4678
|
-
var _a;
|
|
4679
4705
|
const draw = host.getDraw();
|
|
4680
4706
|
const isReadonly = draw.isReadonly();
|
|
4681
4707
|
if (isReadonly)
|
|
@@ -4728,7 +4754,7 @@ function input(data2, host) {
|
|
|
4728
4754
|
return newElement;
|
|
4729
4755
|
});
|
|
4730
4756
|
let curIndex;
|
|
4731
|
-
if (activeControl && (
|
|
4757
|
+
if (activeControl && !control.isRangInPostfix()) {
|
|
4732
4758
|
curIndex = control.setValue(inputData);
|
|
4733
4759
|
} else {
|
|
4734
4760
|
const start = startIndex + 1;
|
|
@@ -4740,11 +4766,13 @@ function input(data2, host) {
|
|
|
4740
4766
|
}
|
|
4741
4767
|
curIndex = startIndex + inputData.length;
|
|
4742
4768
|
}
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4769
|
+
if (~curIndex) {
|
|
4770
|
+
rangeManager.setRange(curIndex, curIndex);
|
|
4771
|
+
draw.render({
|
|
4772
|
+
curIndex,
|
|
4773
|
+
isSubmitHistory: !isComposing
|
|
4774
|
+
});
|
|
4775
|
+
}
|
|
4748
4776
|
if (isComposing) {
|
|
4749
4777
|
host.compositionInfo = {
|
|
4750
4778
|
elementList,
|
|
@@ -4869,7 +4897,7 @@ function dblclick(host) {
|
|
|
4869
4897
|
draw.render({
|
|
4870
4898
|
isSubmitHistory: false,
|
|
4871
4899
|
isSetCursor: false,
|
|
4872
|
-
|
|
4900
|
+
isCompute: false
|
|
4873
4901
|
});
|
|
4874
4902
|
}
|
|
4875
4903
|
function threeClick(host) {
|
|
@@ -4907,7 +4935,7 @@ function threeClick(host) {
|
|
|
4907
4935
|
draw.render({
|
|
4908
4936
|
isSubmitHistory: false,
|
|
4909
4937
|
isSetCursor: false,
|
|
4910
|
-
|
|
4938
|
+
isCompute: false
|
|
4911
4939
|
});
|
|
4912
4940
|
}
|
|
4913
4941
|
var click = {
|
|
@@ -5064,7 +5092,7 @@ class CanvasEvent {
|
|
|
5064
5092
|
this.draw.render({
|
|
5065
5093
|
isSubmitHistory: false,
|
|
5066
5094
|
isSetCursor: false,
|
|
5067
|
-
|
|
5095
|
+
isCompute: false
|
|
5068
5096
|
});
|
|
5069
5097
|
}
|
|
5070
5098
|
mousemove(evt) {
|
|
@@ -5285,6 +5313,94 @@ class Position {
|
|
|
5285
5313
|
setPositionList(payload) {
|
|
5286
5314
|
this.positionList = payload;
|
|
5287
5315
|
}
|
|
5316
|
+
computePageRowPosition(payload) {
|
|
5317
|
+
const { positionList, rowList, pageNo, startX, startY, startIndex, innerWidth } = payload;
|
|
5318
|
+
const { scale, tdPadding } = this.options;
|
|
5319
|
+
let x = startX;
|
|
5320
|
+
let y = startY;
|
|
5321
|
+
let index2 = startIndex;
|
|
5322
|
+
for (let i = 0; i < rowList.length; i++) {
|
|
5323
|
+
const curRow = rowList[i];
|
|
5324
|
+
if (curRow.rowFlex === RowFlex.CENTER) {
|
|
5325
|
+
x += (innerWidth - curRow.width) / 2;
|
|
5326
|
+
} else if (curRow.rowFlex === RowFlex.RIGHT) {
|
|
5327
|
+
x += innerWidth - curRow.width;
|
|
5328
|
+
}
|
|
5329
|
+
const tablePreX = x;
|
|
5330
|
+
const tablePreY = y;
|
|
5331
|
+
for (let j = 0; j < curRow.elementList.length; j++) {
|
|
5332
|
+
const element = curRow.elementList[j];
|
|
5333
|
+
const metrics = element.metrics;
|
|
5334
|
+
const offsetY = element.imgDisplay !== ImageDisplay.INLINE && element.type === ElementType.IMAGE || element.type === ElementType.LATEX ? curRow.ascent - metrics.height : curRow.ascent;
|
|
5335
|
+
const positionItem = {
|
|
5336
|
+
pageNo,
|
|
5337
|
+
index: index2,
|
|
5338
|
+
value: element.value,
|
|
5339
|
+
rowNo: i,
|
|
5340
|
+
metrics,
|
|
5341
|
+
ascent: offsetY,
|
|
5342
|
+
lineHeight: curRow.height,
|
|
5343
|
+
isLastLetter: j === curRow.elementList.length - 1,
|
|
5344
|
+
coordinate: {
|
|
5345
|
+
leftTop: [x, y],
|
|
5346
|
+
leftBottom: [x, y + curRow.height],
|
|
5347
|
+
rightTop: [x + metrics.width, y],
|
|
5348
|
+
rightBottom: [x + metrics.width, y + curRow.height]
|
|
5349
|
+
}
|
|
5350
|
+
};
|
|
5351
|
+
positionList.push(positionItem);
|
|
5352
|
+
index2++;
|
|
5353
|
+
x += metrics.width;
|
|
5354
|
+
if (element.type === ElementType.TABLE) {
|
|
5355
|
+
const tdGap = tdPadding * 2;
|
|
5356
|
+
for (let t = 0; t < element.trList.length; t++) {
|
|
5357
|
+
const tr = element.trList[t];
|
|
5358
|
+
for (let d = 0; d < tr.tdList.length; d++) {
|
|
5359
|
+
const td = tr.tdList[d];
|
|
5360
|
+
td.positionList = [];
|
|
5361
|
+
const drawRowResult = this.computePageRowPosition({
|
|
5362
|
+
positionList: td.positionList,
|
|
5363
|
+
rowList: td.rowList,
|
|
5364
|
+
pageNo,
|
|
5365
|
+
startIndex: 0,
|
|
5366
|
+
startX: (td.x + tdPadding) * scale + tablePreX,
|
|
5367
|
+
startY: td.y * scale + tablePreY,
|
|
5368
|
+
innerWidth: (td.width - tdGap) * scale
|
|
5369
|
+
});
|
|
5370
|
+
x = drawRowResult.x;
|
|
5371
|
+
y = drawRowResult.y;
|
|
5372
|
+
}
|
|
5373
|
+
}
|
|
5374
|
+
x = tablePreX;
|
|
5375
|
+
y = tablePreY;
|
|
5376
|
+
}
|
|
5377
|
+
}
|
|
5378
|
+
x = startX;
|
|
5379
|
+
y += curRow.height;
|
|
5380
|
+
}
|
|
5381
|
+
return { x, y, index: index2 };
|
|
5382
|
+
}
|
|
5383
|
+
computePositionList() {
|
|
5384
|
+
this.positionList = [];
|
|
5385
|
+
const innerWidth = this.draw.getInnerWidth();
|
|
5386
|
+
const pageRowList = this.draw.getPageRowList();
|
|
5387
|
+
const margins = this.draw.getMargins();
|
|
5388
|
+
const startX = margins[3];
|
|
5389
|
+
const startY = margins[0];
|
|
5390
|
+
for (let i = 0; i < pageRowList.length; i++) {
|
|
5391
|
+
const rowList = pageRowList[i];
|
|
5392
|
+
const startIndex = rowList[0].startIndex;
|
|
5393
|
+
this.computePageRowPosition({
|
|
5394
|
+
positionList: this.positionList,
|
|
5395
|
+
rowList,
|
|
5396
|
+
pageNo: i,
|
|
5397
|
+
startIndex,
|
|
5398
|
+
startX,
|
|
5399
|
+
startY,
|
|
5400
|
+
innerWidth
|
|
5401
|
+
});
|
|
5402
|
+
}
|
|
5403
|
+
}
|
|
5288
5404
|
setCursorPosition(position) {
|
|
5289
5405
|
this.cursorPosition = position;
|
|
5290
5406
|
}
|
|
@@ -5778,10 +5894,10 @@ class Margin {
|
|
|
5778
5894
|
this.draw = draw;
|
|
5779
5895
|
this.options = draw.getOptions();
|
|
5780
5896
|
}
|
|
5781
|
-
render(ctx) {
|
|
5897
|
+
render(ctx, pageNo) {
|
|
5782
5898
|
const { marginIndicatorColor, pageMode } = this.options;
|
|
5783
5899
|
const width = this.draw.getWidth();
|
|
5784
|
-
const height = pageMode === PageMode.CONTINUITY ? this.draw.getCanvasHeight() : this.draw.getHeight();
|
|
5900
|
+
const height = pageMode === PageMode.CONTINUITY ? this.draw.getCanvasHeight(pageNo) : this.draw.getHeight();
|
|
5785
5901
|
const margins = this.draw.getMargins();
|
|
5786
5902
|
const marginIndicatorSize = this.draw.getMarginIndicatorSize();
|
|
5787
5903
|
ctx.save();
|
|
@@ -6036,7 +6152,10 @@ class Search {
|
|
|
6036
6152
|
const searchMatchIndexList = this.getSearchNavigateIndexList();
|
|
6037
6153
|
if (searchMatchIndexList.includes(s)) {
|
|
6038
6154
|
ctx.fillStyle = searchNavigateMatchColor;
|
|
6039
|
-
this.
|
|
6155
|
+
const preSearchMatch = this.searchMatchList[s - 1];
|
|
6156
|
+
if (!preSearchMatch || preSearchMatch.groupId !== searchMatch.groupId) {
|
|
6157
|
+
this.searchNavigateScrollIntoView(position);
|
|
6158
|
+
}
|
|
6040
6159
|
} else {
|
|
6041
6160
|
ctx.fillStyle = searchMatchColor;
|
|
6042
6161
|
}
|
|
@@ -6162,7 +6281,7 @@ class PageNumber {
|
|
|
6162
6281
|
render(ctx, pageNo) {
|
|
6163
6282
|
const { pageNumberSize, pageNumberFont, scale, pageMode } = this.options;
|
|
6164
6283
|
const width = this.draw.getWidth();
|
|
6165
|
-
const height = pageMode === PageMode.CONTINUITY ? this.draw.getCanvasHeight() : this.draw.getHeight();
|
|
6284
|
+
const height = pageMode === PageMode.CONTINUITY ? this.draw.getCanvasHeight(pageNo) : this.draw.getHeight();
|
|
6166
6285
|
const pageNumberBottom = this.draw.getPageNumberBottom();
|
|
6167
6286
|
ctx.save();
|
|
6168
6287
|
ctx.fillStyle = "#00000";
|
|
@@ -6234,13 +6353,11 @@ var MoveDirection;
|
|
|
6234
6353
|
})(MoveDirection || (MoveDirection = {}));
|
|
6235
6354
|
class SelectionObserver {
|
|
6236
6355
|
constructor() {
|
|
6237
|
-
__publicField(this, "
|
|
6356
|
+
__publicField(this, "step", 5);
|
|
6357
|
+
__publicField(this, "thresholdPoints", [70, 40, 10, 20]);
|
|
6238
6358
|
__publicField(this, "requestAnimationFrameId");
|
|
6239
|
-
__publicField(this, "tippingPoints");
|
|
6240
6359
|
__publicField(this, "isMousedown");
|
|
6241
6360
|
__publicField(this, "isMoving");
|
|
6242
|
-
__publicField(this, "clientWidth");
|
|
6243
|
-
__publicField(this, "clientHeight");
|
|
6244
6361
|
__publicField(this, "_mousedown", () => {
|
|
6245
6362
|
this.isMousedown = true;
|
|
6246
6363
|
});
|
|
@@ -6252,25 +6369,23 @@ class SelectionObserver {
|
|
|
6252
6369
|
if (!this.isMousedown)
|
|
6253
6370
|
return;
|
|
6254
6371
|
const { x, y } = evt;
|
|
6255
|
-
|
|
6372
|
+
const clientWidth = document.documentElement.clientWidth;
|
|
6373
|
+
const clientHeight = document.documentElement.clientHeight;
|
|
6374
|
+
if (y < this.thresholdPoints[0]) {
|
|
6256
6375
|
this._startMove(MoveDirection.UP);
|
|
6257
|
-
} else if (
|
|
6376
|
+
} else if (clientHeight - y <= this.thresholdPoints[1]) {
|
|
6258
6377
|
this._startMove(MoveDirection.DOWN);
|
|
6259
|
-
} else if (x < this.
|
|
6378
|
+
} else if (x < this.thresholdPoints[2]) {
|
|
6260
6379
|
this._startMove(MoveDirection.LEFT);
|
|
6261
|
-
} else if (
|
|
6380
|
+
} else if (clientWidth - x < this.thresholdPoints[3]) {
|
|
6262
6381
|
this._startMove(MoveDirection.RIGHT);
|
|
6263
6382
|
} else {
|
|
6264
6383
|
this._stopMove();
|
|
6265
6384
|
}
|
|
6266
6385
|
});
|
|
6267
|
-
this.
|
|
6268
|
-
this.tippingPoints = [70, 40, 10, 20];
|
|
6269
|
-
this.requestAnimationFrameId = -1;
|
|
6386
|
+
this.requestAnimationFrameId = null;
|
|
6270
6387
|
this.isMousedown = false;
|
|
6271
6388
|
this.isMoving = false;
|
|
6272
|
-
this.clientWidth = 0;
|
|
6273
|
-
this.clientHeight = 0;
|
|
6274
6389
|
this._addEvent();
|
|
6275
6390
|
}
|
|
6276
6391
|
_addEvent() {
|
|
@@ -6284,34 +6399,31 @@ class SelectionObserver {
|
|
|
6284
6399
|
document.removeEventListener("mouseup", this._mouseup);
|
|
6285
6400
|
}
|
|
6286
6401
|
_move(direction) {
|
|
6287
|
-
const x = window.
|
|
6288
|
-
const y = window.
|
|
6402
|
+
const x = window.scrollX;
|
|
6403
|
+
const y = window.scrollY;
|
|
6289
6404
|
if (direction === MoveDirection.DOWN) {
|
|
6290
|
-
window.
|
|
6405
|
+
window.scrollTo(x, y + this.step);
|
|
6291
6406
|
} else if (direction === MoveDirection.UP) {
|
|
6292
|
-
window.
|
|
6407
|
+
window.scrollTo(x, y - this.step);
|
|
6293
6408
|
} else if (direction === MoveDirection.LEFT) {
|
|
6294
|
-
window.
|
|
6409
|
+
window.scrollTo(x - this.step, y);
|
|
6295
6410
|
} else {
|
|
6296
|
-
window.
|
|
6411
|
+
window.scrollTo(x + this.step, y);
|
|
6297
6412
|
}
|
|
6298
6413
|
this.requestAnimationFrameId = window.requestAnimationFrame(this._move.bind(this, direction));
|
|
6299
6414
|
}
|
|
6300
6415
|
_startMove(direction) {
|
|
6301
6416
|
if (this.isMoving)
|
|
6302
6417
|
return;
|
|
6303
|
-
this.clientWidth = document.documentElement.clientWidth;
|
|
6304
|
-
this.clientHeight = document.documentElement.clientHeight;
|
|
6305
6418
|
this.isMoving = true;
|
|
6306
|
-
this.
|
|
6419
|
+
this._move(direction);
|
|
6307
6420
|
}
|
|
6308
6421
|
_stopMove() {
|
|
6309
|
-
if (
|
|
6310
|
-
return;
|
|
6311
|
-
if (~this.requestAnimationFrameId) {
|
|
6422
|
+
if (this.requestAnimationFrameId) {
|
|
6312
6423
|
window.cancelAnimationFrame(this.requestAnimationFrameId);
|
|
6424
|
+
this.requestAnimationFrameId = null;
|
|
6425
|
+
this.isMoving = false;
|
|
6313
6426
|
}
|
|
6314
|
-
this.isMoving = false;
|
|
6315
6427
|
}
|
|
6316
6428
|
}
|
|
6317
6429
|
class TableParticle {
|
|
@@ -6918,8 +7030,7 @@ class SelectControl {
|
|
|
6918
7030
|
return data2;
|
|
6919
7031
|
}
|
|
6920
7032
|
setValue() {
|
|
6921
|
-
|
|
6922
|
-
return range.endIndex;
|
|
7033
|
+
return -1;
|
|
6923
7034
|
}
|
|
6924
7035
|
keydown(evt) {
|
|
6925
7036
|
const elementList = this.control.getElementList();
|
|
@@ -7218,6 +7329,16 @@ class Control {
|
|
|
7218
7329
|
}
|
|
7219
7330
|
return false;
|
|
7220
7331
|
}
|
|
7332
|
+
isRangInPostfix() {
|
|
7333
|
+
if (!this.activeControl)
|
|
7334
|
+
return false;
|
|
7335
|
+
const { startIndex, endIndex } = this.getRange();
|
|
7336
|
+
if (startIndex !== endIndex)
|
|
7337
|
+
return false;
|
|
7338
|
+
const elementList = this.getElementList();
|
|
7339
|
+
const element = elementList[startIndex];
|
|
7340
|
+
return element.controlComponent === ControlComponent.POSTFIX;
|
|
7341
|
+
}
|
|
7221
7342
|
getContainer() {
|
|
7222
7343
|
return this.draw.getContainer();
|
|
7223
7344
|
}
|
|
@@ -7386,8 +7507,9 @@ class Control {
|
|
|
7386
7507
|
if (nextIndex === elementList.length) {
|
|
7387
7508
|
rightIndex = nextIndex - 1;
|
|
7388
7509
|
}
|
|
7389
|
-
if (!~leftIndex
|
|
7510
|
+
if (!~leftIndex && !~rightIndex)
|
|
7390
7511
|
return startIndex;
|
|
7512
|
+
leftIndex = ~leftIndex ? leftIndex : 0;
|
|
7391
7513
|
elementList.splice(leftIndex + 1, rightIndex - leftIndex);
|
|
7392
7514
|
return leftIndex;
|
|
7393
7515
|
}
|
|
@@ -8662,6 +8784,21 @@ class I18n {
|
|
|
8662
8784
|
return value;
|
|
8663
8785
|
}
|
|
8664
8786
|
}
|
|
8787
|
+
class ImageObserver {
|
|
8788
|
+
constructor() {
|
|
8789
|
+
__publicField(this, "promiseList");
|
|
8790
|
+
this.promiseList = [];
|
|
8791
|
+
}
|
|
8792
|
+
add(payload) {
|
|
8793
|
+
this.promiseList.push(payload);
|
|
8794
|
+
}
|
|
8795
|
+
clearAll() {
|
|
8796
|
+
this.promiseList = [];
|
|
8797
|
+
}
|
|
8798
|
+
allSettled() {
|
|
8799
|
+
return Promise.allSettled(this.promiseList);
|
|
8800
|
+
}
|
|
8801
|
+
}
|
|
8665
8802
|
class Draw {
|
|
8666
8803
|
constructor(rootContainer, options, elementList, listener) {
|
|
8667
8804
|
__publicField(this, "container");
|
|
@@ -8707,11 +8844,14 @@ class Draw {
|
|
|
8707
8844
|
__publicField(this, "workerManager");
|
|
8708
8845
|
__publicField(this, "scrollObserver");
|
|
8709
8846
|
__publicField(this, "selectionObserver");
|
|
8847
|
+
__publicField(this, "imageObserver");
|
|
8710
8848
|
__publicField(this, "rowList");
|
|
8849
|
+
__publicField(this, "pageRowList");
|
|
8711
8850
|
__publicField(this, "painterStyle");
|
|
8712
8851
|
__publicField(this, "painterOptions");
|
|
8713
8852
|
__publicField(this, "visiblePageNoList");
|
|
8714
8853
|
__publicField(this, "intersectionPageNo");
|
|
8854
|
+
__publicField(this, "lazyRenderIntersectionObserver");
|
|
8715
8855
|
this.container = this._wrapContainer(rootContainer);
|
|
8716
8856
|
this.pageList = [];
|
|
8717
8857
|
this.ctxList = [];
|
|
@@ -8753,6 +8893,7 @@ class Draw {
|
|
|
8753
8893
|
this.control = new Control(this);
|
|
8754
8894
|
this.scrollObserver = new ScrollObserver(this);
|
|
8755
8895
|
this.selectionObserver = new SelectionObserver();
|
|
8896
|
+
this.imageObserver = new ImageObserver();
|
|
8756
8897
|
this.canvasEvent = new CanvasEvent(this);
|
|
8757
8898
|
this.cursor = new Cursor(this, this.canvasEvent);
|
|
8758
8899
|
this.canvasEvent.register();
|
|
@@ -8760,10 +8901,12 @@ class Draw {
|
|
|
8760
8901
|
this.globalEvent.register();
|
|
8761
8902
|
this.workerManager = new WorkerManager(this);
|
|
8762
8903
|
this.rowList = [];
|
|
8904
|
+
this.pageRowList = [];
|
|
8763
8905
|
this.painterStyle = null;
|
|
8764
8906
|
this.painterOptions = null;
|
|
8765
8907
|
this.visiblePageNoList = [];
|
|
8766
8908
|
this.intersectionPageNo = 0;
|
|
8909
|
+
this.lazyRenderIntersectionObserver = null;
|
|
8767
8910
|
this.render({ isSetCursor: false });
|
|
8768
8911
|
}
|
|
8769
8912
|
getMode() {
|
|
@@ -8781,12 +8924,12 @@ class Draw {
|
|
|
8781
8924
|
getHeight() {
|
|
8782
8925
|
return Math.floor(this.options.height * this.options.scale);
|
|
8783
8926
|
}
|
|
8784
|
-
getCanvasWidth() {
|
|
8785
|
-
const page = this.getPage();
|
|
8927
|
+
getCanvasWidth(pageNo = -1) {
|
|
8928
|
+
const page = this.getPage(pageNo);
|
|
8786
8929
|
return page.width;
|
|
8787
8930
|
}
|
|
8788
|
-
getCanvasHeight() {
|
|
8789
|
-
const page = this.getPage();
|
|
8931
|
+
getCanvasHeight(pageNo = -1) {
|
|
8932
|
+
const page = this.getPage(pageNo);
|
|
8790
8933
|
return page.height;
|
|
8791
8934
|
}
|
|
8792
8935
|
getInnerWidth() {
|
|
@@ -8852,12 +8995,18 @@ class Draw {
|
|
|
8852
8995
|
setPageNo(payload) {
|
|
8853
8996
|
this.pageNo = payload;
|
|
8854
8997
|
}
|
|
8855
|
-
getPage() {
|
|
8856
|
-
return this.pageList[this.pageNo];
|
|
8998
|
+
getPage(pageNo = -1) {
|
|
8999
|
+
return this.pageList[~pageNo ? pageNo : this.pageNo];
|
|
8857
9000
|
}
|
|
8858
9001
|
getPageList() {
|
|
8859
9002
|
return this.pageList;
|
|
8860
9003
|
}
|
|
9004
|
+
getRowList() {
|
|
9005
|
+
return this.rowList;
|
|
9006
|
+
}
|
|
9007
|
+
getPageRowList() {
|
|
9008
|
+
return this.pageRowList;
|
|
9009
|
+
}
|
|
8861
9010
|
getCtx() {
|
|
8862
9011
|
return this.ctxList[this.pageNo];
|
|
8863
9012
|
}
|
|
@@ -8887,9 +9036,6 @@ class Draw {
|
|
|
8887
9036
|
insertElementList(payload) {
|
|
8888
9037
|
if (!payload.length)
|
|
8889
9038
|
return;
|
|
8890
|
-
const activeControl = this.control.getActiveControl();
|
|
8891
|
-
if (activeControl)
|
|
8892
|
-
return;
|
|
8893
9039
|
const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside();
|
|
8894
9040
|
if (isPartRangeInControlOutside)
|
|
8895
9041
|
return;
|
|
@@ -8900,27 +9046,35 @@ class Draw {
|
|
|
8900
9046
|
isHandleFirstElement: false,
|
|
8901
9047
|
editorOptions: this.options
|
|
8902
9048
|
});
|
|
8903
|
-
|
|
8904
|
-
const
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
9049
|
+
let curIndex = -1;
|
|
9050
|
+
const activeControl = this.control.getActiveControl();
|
|
9051
|
+
if (activeControl && !this.control.isRangInPostfix()) {
|
|
9052
|
+
curIndex = activeControl.setValue(payload);
|
|
9053
|
+
} else {
|
|
9054
|
+
const elementList = this.getElementList();
|
|
9055
|
+
const isCollapsed = startIndex === endIndex;
|
|
9056
|
+
const start = startIndex + 1;
|
|
9057
|
+
if (!isCollapsed) {
|
|
9058
|
+
elementList.splice(start, endIndex - startIndex);
|
|
9059
|
+
}
|
|
9060
|
+
const positionContext = this.position.getPositionContext();
|
|
9061
|
+
for (let i = 0; i < payload.length; i++) {
|
|
9062
|
+
const element = payload[i];
|
|
9063
|
+
if (positionContext.isTable) {
|
|
9064
|
+
element.tdId = positionContext.tdId;
|
|
9065
|
+
element.trId = positionContext.trId;
|
|
9066
|
+
element.tableId = positionContext.tableId;
|
|
9067
|
+
}
|
|
9068
|
+
elementList.splice(start + i, 0, element);
|
|
8916
9069
|
}
|
|
8917
|
-
|
|
9070
|
+
curIndex = startIndex + payload.length;
|
|
9071
|
+
}
|
|
9072
|
+
if (~curIndex) {
|
|
9073
|
+
this.range.setRange(curIndex, curIndex);
|
|
9074
|
+
this.render({
|
|
9075
|
+
curIndex
|
|
9076
|
+
});
|
|
8918
9077
|
}
|
|
8919
|
-
const curIndex = startIndex + payload.length;
|
|
8920
|
-
this.range.setRange(curIndex, curIndex);
|
|
8921
|
-
this.render({
|
|
8922
|
-
curIndex
|
|
8923
|
-
});
|
|
8924
9078
|
}
|
|
8925
9079
|
getOriginalElementList() {
|
|
8926
9080
|
return this.elementList;
|
|
@@ -8955,13 +9109,23 @@ class Draw {
|
|
|
8955
9109
|
getWorkerManager() {
|
|
8956
9110
|
return this.workerManager;
|
|
8957
9111
|
}
|
|
9112
|
+
getImageObserver() {
|
|
9113
|
+
return this.imageObserver;
|
|
9114
|
+
}
|
|
8958
9115
|
getI18n() {
|
|
8959
9116
|
return this.i18n;
|
|
8960
9117
|
}
|
|
8961
9118
|
getRowCount() {
|
|
8962
9119
|
return this.rowList.length;
|
|
8963
9120
|
}
|
|
8964
|
-
getDataURL() {
|
|
9121
|
+
async getDataURL() {
|
|
9122
|
+
this.render({
|
|
9123
|
+
isLazy: false,
|
|
9124
|
+
isCompute: false,
|
|
9125
|
+
isSetCursor: false,
|
|
9126
|
+
isSubmitHistory: false
|
|
9127
|
+
});
|
|
9128
|
+
await this.imageObserver.allSettled();
|
|
8965
9129
|
return this.pageList.map((c) => c.toDataURL());
|
|
8966
9130
|
}
|
|
8967
9131
|
getPainterStyle() {
|
|
@@ -8996,6 +9160,7 @@ class Draw {
|
|
|
8996
9160
|
const canvas = this.pageList[0];
|
|
8997
9161
|
canvas.style.height = `${height}px`;
|
|
8998
9162
|
canvas.height = height * dpr;
|
|
9163
|
+
this.ctxList[0].scale(dpr, dpr);
|
|
8999
9164
|
}
|
|
9000
9165
|
this.render({
|
|
9001
9166
|
isSubmitHistory: false,
|
|
@@ -9126,7 +9291,6 @@ class Draw {
|
|
|
9126
9291
|
var _a, _b, _c, _d;
|
|
9127
9292
|
const { defaultSize, defaultRowMargin, scale, tdPadding, defaultTabWidth } = this.options;
|
|
9128
9293
|
const defaultBasicRowMarginHeight = this.getDefaultBasicRowMarginHeight();
|
|
9129
|
-
const tdGap = tdPadding * 2;
|
|
9130
9294
|
const canvas = document.createElement("canvas");
|
|
9131
9295
|
const ctx = canvas.getContext("2d");
|
|
9132
9296
|
const rowList = [];
|
|
@@ -9136,6 +9300,7 @@ class Draw {
|
|
|
9136
9300
|
height: 0,
|
|
9137
9301
|
ascent: 0,
|
|
9138
9302
|
elementList: [],
|
|
9303
|
+
startIndex: 0,
|
|
9139
9304
|
rowFlex: (_a = elementList == null ? void 0 : elementList[1]) == null ? void 0 : _a.rowFlex
|
|
9140
9305
|
});
|
|
9141
9306
|
}
|
|
@@ -9167,6 +9332,7 @@ class Draw {
|
|
|
9167
9332
|
}
|
|
9168
9333
|
metrics.boundingBoxAscent = 0;
|
|
9169
9334
|
} else if (element.type === ElementType.TABLE) {
|
|
9335
|
+
const tdGap = tdPadding * 2;
|
|
9170
9336
|
this.tableParticle.computeRowColInfo(element);
|
|
9171
9337
|
const trList = element.trList;
|
|
9172
9338
|
for (let t = 0; t < trList.length; t++) {
|
|
@@ -9320,6 +9486,7 @@ class Draw {
|
|
|
9320
9486
|
rowList.push({
|
|
9321
9487
|
width: metrics.width,
|
|
9322
9488
|
height,
|
|
9489
|
+
startIndex: i,
|
|
9323
9490
|
elementList: [rowElement],
|
|
9324
9491
|
ascent,
|
|
9325
9492
|
rowFlex: (_d = elementList[i + 1]) == null ? void 0 : _d.rowFlex,
|
|
@@ -9340,6 +9507,45 @@ class Draw {
|
|
|
9340
9507
|
}
|
|
9341
9508
|
return rowList;
|
|
9342
9509
|
}
|
|
9510
|
+
_computePageList() {
|
|
9511
|
+
var _a;
|
|
9512
|
+
const pageRowList = [[]];
|
|
9513
|
+
const { pageMode } = this.options;
|
|
9514
|
+
const height = this.getHeight();
|
|
9515
|
+
const margins = this.getMargins();
|
|
9516
|
+
const marginHeight = margins[0] + margins[2];
|
|
9517
|
+
let pageHeight = marginHeight;
|
|
9518
|
+
let pageNo = 0;
|
|
9519
|
+
if (pageMode === PageMode.CONTINUITY) {
|
|
9520
|
+
pageRowList[0] = this.rowList;
|
|
9521
|
+
pageHeight += this.rowList.reduce((pre, cur) => pre + cur.height, 0);
|
|
9522
|
+
const dpr = window.devicePixelRatio;
|
|
9523
|
+
const pageDom = this.pageList[0];
|
|
9524
|
+
const pageDomHeight = Number(pageDom.style.height.replace("px", ""));
|
|
9525
|
+
if (pageHeight > pageDomHeight) {
|
|
9526
|
+
pageDom.style.height = `${pageHeight}px`;
|
|
9527
|
+
pageDom.height = pageHeight * dpr;
|
|
9528
|
+
} else {
|
|
9529
|
+
const reduceHeight = pageHeight < height ? height : pageHeight;
|
|
9530
|
+
pageDom.style.height = `${reduceHeight}px`;
|
|
9531
|
+
pageDom.height = reduceHeight * dpr;
|
|
9532
|
+
}
|
|
9533
|
+
this.ctxList[0].scale(dpr, dpr);
|
|
9534
|
+
} else {
|
|
9535
|
+
for (let i = 0; i < this.rowList.length; i++) {
|
|
9536
|
+
const row = this.rowList[i];
|
|
9537
|
+
if (row.height + pageHeight > height || ((_a = this.rowList[i - 1]) == null ? void 0 : _a.isPageBreak)) {
|
|
9538
|
+
pageHeight = marginHeight + row.height;
|
|
9539
|
+
pageRowList.push([row]);
|
|
9540
|
+
pageNo++;
|
|
9541
|
+
} else {
|
|
9542
|
+
pageHeight += row.height;
|
|
9543
|
+
pageRowList[pageNo].push(row);
|
|
9544
|
+
}
|
|
9545
|
+
}
|
|
9546
|
+
}
|
|
9547
|
+
return pageRowList;
|
|
9548
|
+
}
|
|
9343
9549
|
_drawRichText(ctx) {
|
|
9344
9550
|
this.underline.render(ctx);
|
|
9345
9551
|
this.strikeout.render(ctx);
|
|
@@ -9347,22 +9553,12 @@ class Draw {
|
|
|
9347
9553
|
this.textParticle.complete();
|
|
9348
9554
|
}
|
|
9349
9555
|
_drawRow(ctx, payload) {
|
|
9350
|
-
const {
|
|
9556
|
+
const { rowList, pageNo, positionList, startIndex } = payload;
|
|
9351
9557
|
const { scale, tdPadding } = this.options;
|
|
9352
9558
|
const { isCrossRowCol, tableId } = this.range.getRange();
|
|
9353
|
-
const tdGap = tdPadding * 2;
|
|
9354
|
-
let x = startX;
|
|
9355
|
-
let y = startY;
|
|
9356
9559
|
let index2 = startIndex;
|
|
9357
9560
|
for (let i = 0; i < rowList.length; i++) {
|
|
9358
9561
|
const curRow = rowList[i];
|
|
9359
|
-
if (curRow.rowFlex === RowFlex.CENTER) {
|
|
9360
|
-
x += (innerWidth - curRow.width) / 2;
|
|
9361
|
-
} else if (curRow.rowFlex === RowFlex.RIGHT) {
|
|
9362
|
-
x += innerWidth - curRow.width;
|
|
9363
|
-
}
|
|
9364
|
-
const tablePreX = x;
|
|
9365
|
-
const tablePreY = y;
|
|
9366
9562
|
const rangeRecord = {
|
|
9367
9563
|
x: 0,
|
|
9368
9564
|
y: 0,
|
|
@@ -9373,24 +9569,7 @@ class Draw {
|
|
|
9373
9569
|
for (let j = 0; j < curRow.elementList.length; j++) {
|
|
9374
9570
|
const element = curRow.elementList[j];
|
|
9375
9571
|
const metrics = element.metrics;
|
|
9376
|
-
const
|
|
9377
|
-
const positionItem = {
|
|
9378
|
-
pageNo,
|
|
9379
|
-
index: index2,
|
|
9380
|
-
value: element.value,
|
|
9381
|
-
rowNo: i,
|
|
9382
|
-
metrics,
|
|
9383
|
-
ascent: offsetY,
|
|
9384
|
-
lineHeight: curRow.height,
|
|
9385
|
-
isLastLetter: j === curRow.elementList.length - 1,
|
|
9386
|
-
coordinate: {
|
|
9387
|
-
leftTop: [x, y],
|
|
9388
|
-
leftBottom: [x, y + curRow.height],
|
|
9389
|
-
rightTop: [x + metrics.width, y],
|
|
9390
|
-
rightBottom: [x + metrics.width, y + curRow.height]
|
|
9391
|
-
}
|
|
9392
|
-
};
|
|
9393
|
-
positionList.push(positionItem);
|
|
9572
|
+
const { ascent: offsetY, coordinate: { leftTop: [x, y] } } = positionList[curRow.startIndex + j];
|
|
9394
9573
|
if (element.type === ElementType.IMAGE) {
|
|
9395
9574
|
this._drawRichText(ctx);
|
|
9396
9575
|
this.imageParticle.render(ctx, element, x, y + offsetY);
|
|
@@ -9479,42 +9658,33 @@ class Draw {
|
|
|
9479
9658
|
}
|
|
9480
9659
|
}
|
|
9481
9660
|
index2++;
|
|
9482
|
-
x += metrics.width;
|
|
9483
9661
|
if (element.type === ElementType.TABLE) {
|
|
9662
|
+
const tdGap = tdPadding * 2;
|
|
9484
9663
|
for (let t = 0; t < element.trList.length; t++) {
|
|
9485
9664
|
const tr = element.trList[t];
|
|
9486
9665
|
for (let d = 0; d < tr.tdList.length; d++) {
|
|
9487
9666
|
const td = tr.tdList[d];
|
|
9488
|
-
|
|
9489
|
-
const drawRowResult = this._drawRow(ctx, {
|
|
9667
|
+
this._drawRow(ctx, {
|
|
9490
9668
|
positionList: td.positionList,
|
|
9491
9669
|
rowList: td.rowList,
|
|
9492
9670
|
pageNo,
|
|
9493
9671
|
startIndex: 0,
|
|
9494
|
-
startX: (td.x + tdPadding) * scale + tablePreX,
|
|
9495
|
-
startY: td.y * scale + tablePreY,
|
|
9496
9672
|
innerWidth: (td.width - tdGap) * scale
|
|
9497
9673
|
});
|
|
9498
|
-
x = drawRowResult.x;
|
|
9499
|
-
y = drawRowResult.y;
|
|
9500
9674
|
}
|
|
9501
9675
|
}
|
|
9502
|
-
x = tablePreX;
|
|
9503
|
-
y = tablePreY;
|
|
9504
9676
|
}
|
|
9505
9677
|
}
|
|
9506
9678
|
this._drawRichText(ctx);
|
|
9507
9679
|
if (rangeRecord.width && rangeRecord.height) {
|
|
9508
|
-
const { x
|
|
9509
|
-
this.range.render(ctx,
|
|
9680
|
+
const { x, y, width, height } = rangeRecord;
|
|
9681
|
+
this.range.render(ctx, x, y, width, height);
|
|
9510
9682
|
}
|
|
9511
9683
|
if (isCrossRowCol && tableRangeElement && tableRangeElement.id === tableId) {
|
|
9684
|
+
const { coordinate: { leftTop: [x, y] } } = positionList[curRow.startIndex];
|
|
9512
9685
|
this.tableParticle.drawRange(ctx, tableRangeElement, x, y);
|
|
9513
9686
|
}
|
|
9514
|
-
x = startX;
|
|
9515
|
-
y += curRow.height;
|
|
9516
9687
|
}
|
|
9517
|
-
return { x, y, index: index2 };
|
|
9518
9688
|
}
|
|
9519
9689
|
_clearPage(pageNo) {
|
|
9520
9690
|
const ctx = this.ctxList[pageNo];
|
|
@@ -9524,28 +9694,19 @@ class Draw {
|
|
|
9524
9694
|
}
|
|
9525
9695
|
_drawPage(positionList, rowList, pageNo) {
|
|
9526
9696
|
const { pageMode } = this.options;
|
|
9527
|
-
const margins = this.getMargins();
|
|
9528
9697
|
const innerWidth = this.getInnerWidth();
|
|
9529
9698
|
const ctx = this.ctxList[pageNo];
|
|
9530
9699
|
this._clearPage(pageNo);
|
|
9531
9700
|
this.background.render(ctx);
|
|
9532
|
-
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
let y = leftTopPoint[1];
|
|
9536
|
-
let index2 = positionList.length;
|
|
9537
|
-
const drawRowResult = this._drawRow(ctx, {
|
|
9701
|
+
this.margin.render(ctx, pageNo);
|
|
9702
|
+
const index2 = rowList[0].startIndex;
|
|
9703
|
+
this._drawRow(ctx, {
|
|
9538
9704
|
positionList,
|
|
9539
9705
|
rowList,
|
|
9540
9706
|
pageNo,
|
|
9541
9707
|
startIndex: index2,
|
|
9542
|
-
startX: x,
|
|
9543
|
-
startY: y,
|
|
9544
9708
|
innerWidth
|
|
9545
9709
|
});
|
|
9546
|
-
x = drawRowResult.x;
|
|
9547
|
-
y = drawRowResult.y;
|
|
9548
|
-
index2 = drawRowResult.index;
|
|
9549
9710
|
this.header.render(ctx);
|
|
9550
9711
|
this.pageNumber.render(ctx, pageNo);
|
|
9551
9712
|
if (this.search.getSearchKeyword()) {
|
|
@@ -9555,76 +9716,68 @@ class Draw {
|
|
|
9555
9716
|
this.waterMark.render(ctx);
|
|
9556
9717
|
}
|
|
9557
9718
|
}
|
|
9719
|
+
_lazyRender() {
|
|
9720
|
+
var _a;
|
|
9721
|
+
const positionList = this.position.getOriginalPositionList();
|
|
9722
|
+
(_a = this.lazyRenderIntersectionObserver) == null ? void 0 : _a.disconnect();
|
|
9723
|
+
this.lazyRenderIntersectionObserver = new IntersectionObserver((entries) => {
|
|
9724
|
+
entries.forEach((entry) => {
|
|
9725
|
+
if (entry.isIntersecting) {
|
|
9726
|
+
const index2 = Number(entry.target.dataset.index);
|
|
9727
|
+
this._drawPage(positionList, this.pageRowList[index2], index2);
|
|
9728
|
+
}
|
|
9729
|
+
});
|
|
9730
|
+
});
|
|
9731
|
+
this.pageList.forEach((el) => {
|
|
9732
|
+
this.lazyRenderIntersectionObserver.observe(el);
|
|
9733
|
+
});
|
|
9734
|
+
}
|
|
9735
|
+
_immediateRender() {
|
|
9736
|
+
const positionList = this.position.getOriginalPositionList();
|
|
9737
|
+
for (let i = 0; i < this.pageRowList.length; i++) {
|
|
9738
|
+
this._drawPage(positionList, this.pageRowList[i], i);
|
|
9739
|
+
}
|
|
9740
|
+
}
|
|
9558
9741
|
render(payload) {
|
|
9559
|
-
var _a
|
|
9742
|
+
var _a;
|
|
9560
9743
|
const { pageMode } = this.options;
|
|
9561
|
-
const { isSubmitHistory = true, isSetCursor = true,
|
|
9744
|
+
const { isSubmitHistory = true, isSetCursor = true, isCompute = true, isLazy = true } = payload || {};
|
|
9562
9745
|
let { curIndex } = payload || {};
|
|
9563
|
-
const height = this.getHeight();
|
|
9564
9746
|
const innerWidth = this.getInnerWidth();
|
|
9565
|
-
if (
|
|
9747
|
+
if (isCompute) {
|
|
9566
9748
|
this.rowList = this._computeRowList(innerWidth, this.elementList);
|
|
9749
|
+
this.pageRowList = this._computePageList();
|
|
9750
|
+
this.position.computePositionList();
|
|
9567
9751
|
const searchKeyword = this.search.getSearchKeyword();
|
|
9568
9752
|
if (searchKeyword) {
|
|
9569
9753
|
this.search.compute(searchKeyword);
|
|
9570
9754
|
}
|
|
9571
9755
|
}
|
|
9756
|
+
this.imageObserver.clearAll();
|
|
9572
9757
|
this.cursor.recoveryCursor();
|
|
9573
|
-
this.position.setPositionList([]);
|
|
9574
9758
|
const positionList = this.position.getOriginalPositionList();
|
|
9575
|
-
|
|
9576
|
-
const marginHeight = margins[0] + margins[2];
|
|
9577
|
-
let pageHeight = marginHeight;
|
|
9578
|
-
let pageNo = 0;
|
|
9579
|
-
const pageRowList = [[]];
|
|
9580
|
-
if (pageMode === PageMode.CONTINUITY) {
|
|
9581
|
-
pageRowList[0] = this.rowList;
|
|
9582
|
-
pageHeight += this.rowList.reduce((pre, cur) => pre + cur.height, 0);
|
|
9583
|
-
const dpr = window.devicePixelRatio;
|
|
9584
|
-
const pageDom = this.pageList[0];
|
|
9585
|
-
const pageDomHeight = Number(pageDom.style.height.replace("px", ""));
|
|
9586
|
-
if (pageHeight > pageDomHeight) {
|
|
9587
|
-
pageDom.style.height = `${pageHeight}px`;
|
|
9588
|
-
pageDom.height = pageHeight * dpr;
|
|
9589
|
-
} else {
|
|
9590
|
-
const reduceHeight = pageHeight < height ? height : pageHeight;
|
|
9591
|
-
pageDom.style.height = `${reduceHeight}px`;
|
|
9592
|
-
pageDom.height = reduceHeight * dpr;
|
|
9593
|
-
}
|
|
9594
|
-
} else {
|
|
9595
|
-
for (let i = 0; i < this.rowList.length; i++) {
|
|
9596
|
-
const row = this.rowList[i];
|
|
9597
|
-
if (row.height + pageHeight > height || ((_a = this.rowList[i - 1]) == null ? void 0 : _a.isPageBreak)) {
|
|
9598
|
-
pageHeight = marginHeight + row.height;
|
|
9599
|
-
pageRowList.push([row]);
|
|
9600
|
-
pageNo++;
|
|
9601
|
-
} else {
|
|
9602
|
-
pageHeight += row.height;
|
|
9603
|
-
pageRowList[pageNo].push(row);
|
|
9604
|
-
}
|
|
9605
|
-
}
|
|
9606
|
-
}
|
|
9607
|
-
for (let i = 0; i < pageRowList.length; i++) {
|
|
9759
|
+
for (let i = 0; i < this.pageRowList.length; i++) {
|
|
9608
9760
|
if (!this.pageList[i]) {
|
|
9609
9761
|
this._createPage(i);
|
|
9610
9762
|
}
|
|
9611
|
-
const rowList = pageRowList[i];
|
|
9612
|
-
this._drawPage(positionList, rowList, i);
|
|
9613
9763
|
}
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9764
|
+
const curPageCount = this.pageRowList.length;
|
|
9765
|
+
const prePageCount = this.pageList.length;
|
|
9766
|
+
if (prePageCount > curPageCount) {
|
|
9767
|
+
const deleteCount = prePageCount - curPageCount;
|
|
9768
|
+
this.ctxList.splice(curPageCount, deleteCount);
|
|
9769
|
+
this.pageList.splice(curPageCount, deleteCount).forEach((page) => page.remove());
|
|
9770
|
+
}
|
|
9771
|
+
if (isLazy && pageMode === PageMode.PAGING) {
|
|
9772
|
+
this._lazyRender();
|
|
9773
|
+
} else {
|
|
9774
|
+
this._immediateRender();
|
|
9775
|
+
}
|
|
9623
9776
|
if (isSetCursor) {
|
|
9624
9777
|
const positionContext = this.position.getPositionContext();
|
|
9625
9778
|
if (positionContext.isTable) {
|
|
9626
9779
|
const { index: index2, trIndex, tdIndex } = positionContext;
|
|
9627
|
-
const tablePositionList = (
|
|
9780
|
+
const tablePositionList = (_a = this.elementList[index2].trList) == null ? void 0 : _a[trIndex].tdList[tdIndex].positionList;
|
|
9628
9781
|
if (curIndex === void 0 && tablePositionList) {
|
|
9629
9782
|
curIndex = tablePositionList.length - 1;
|
|
9630
9783
|
}
|
|
@@ -9642,19 +9795,19 @@ class Draw {
|
|
|
9642
9795
|
const self = this;
|
|
9643
9796
|
const oldElementList = deepClone(this.elementList);
|
|
9644
9797
|
const { startIndex, endIndex } = this.range.getRange();
|
|
9645
|
-
const
|
|
9798
|
+
const pageNo = this.pageNo;
|
|
9646
9799
|
const oldPositionContext = deepClone(this.position.getPositionContext());
|
|
9647
9800
|
this.historyManager.execute(function() {
|
|
9648
|
-
self.setPageNo(
|
|
9801
|
+
self.setPageNo(pageNo);
|
|
9649
9802
|
self.position.setPositionContext(oldPositionContext);
|
|
9650
9803
|
self.elementList = deepClone(oldElementList);
|
|
9651
9804
|
self.range.setRange(startIndex, endIndex);
|
|
9652
9805
|
self.render({ curIndex, isSubmitHistory: false });
|
|
9653
9806
|
});
|
|
9654
9807
|
}
|
|
9655
|
-
|
|
9808
|
+
nextTick(() => {
|
|
9656
9809
|
if (this.listener.pageSizeChange) {
|
|
9657
|
-
this.listener.pageSizeChange(pageRowList.length);
|
|
9810
|
+
this.listener.pageSizeChange(this.pageRowList.length);
|
|
9658
9811
|
}
|
|
9659
9812
|
if (this.listener.contentChange && isSubmitHistory) {
|
|
9660
9813
|
this.listener.contentChange();
|
|
@@ -10148,7 +10301,7 @@ class CommandAdapt {
|
|
|
10148
10301
|
const isCollapsed = startIndex === endIndex;
|
|
10149
10302
|
this.draw.render({
|
|
10150
10303
|
curIndex: isCollapsed ? startIndex : void 0,
|
|
10151
|
-
|
|
10304
|
+
isCompute: false,
|
|
10152
10305
|
isSubmitHistory: false,
|
|
10153
10306
|
isSetCursor: isCollapsed
|
|
10154
10307
|
});
|
|
@@ -10370,7 +10523,10 @@ class CommandAdapt {
|
|
|
10370
10523
|
selection.forEach((el) => {
|
|
10371
10524
|
el.color = payload;
|
|
10372
10525
|
});
|
|
10373
|
-
this.draw.render({
|
|
10526
|
+
this.draw.render({
|
|
10527
|
+
isSetCursor: false,
|
|
10528
|
+
isCompute: false
|
|
10529
|
+
});
|
|
10374
10530
|
}
|
|
10375
10531
|
highlight(payload) {
|
|
10376
10532
|
const isReadonly = this.draw.isReadonly();
|
|
@@ -10382,7 +10538,10 @@ class CommandAdapt {
|
|
|
10382
10538
|
selection.forEach((el) => {
|
|
10383
10539
|
el.highlight = payload;
|
|
10384
10540
|
});
|
|
10385
|
-
this.draw.render({
|
|
10541
|
+
this.draw.render({
|
|
10542
|
+
isSetCursor: false,
|
|
10543
|
+
isCompute: false
|
|
10544
|
+
});
|
|
10386
10545
|
}
|
|
10387
10546
|
rowFlex(payload) {
|
|
10388
10547
|
const isReadonly = this.draw.isReadonly();
|
|
@@ -11099,7 +11258,7 @@ class CommandAdapt {
|
|
|
11099
11258
|
const { endIndex } = this.range.getRange();
|
|
11100
11259
|
this.draw.render({
|
|
11101
11260
|
curIndex: endIndex,
|
|
11102
|
-
|
|
11261
|
+
isCompute: false
|
|
11103
11262
|
});
|
|
11104
11263
|
}
|
|
11105
11264
|
editHyperlink(payload) {
|
|
@@ -11116,7 +11275,7 @@ class CommandAdapt {
|
|
|
11116
11275
|
const { endIndex } = this.range.getRange();
|
|
11117
11276
|
this.draw.render({
|
|
11118
11277
|
curIndex: endIndex,
|
|
11119
|
-
|
|
11278
|
+
isCompute: false
|
|
11120
11279
|
});
|
|
11121
11280
|
}
|
|
11122
11281
|
separator(payload) {
|
|
@@ -11179,7 +11338,8 @@ class CommandAdapt {
|
|
|
11179
11338
|
options.watermark.font = payload.font || font;
|
|
11180
11339
|
this.draw.render({
|
|
11181
11340
|
isSetCursor: false,
|
|
11182
|
-
isSubmitHistory: false
|
|
11341
|
+
isSubmitHistory: false,
|
|
11342
|
+
isCompute: false
|
|
11183
11343
|
});
|
|
11184
11344
|
}
|
|
11185
11345
|
deleteWatermark() {
|
|
@@ -11191,7 +11351,8 @@ class CommandAdapt {
|
|
|
11191
11351
|
options.watermark = __spreadValues({}, defaultWatermarkOption);
|
|
11192
11352
|
this.draw.render({
|
|
11193
11353
|
isSetCursor: false,
|
|
11194
|
-
isSubmitHistory: false
|
|
11354
|
+
isSubmitHistory: false,
|
|
11355
|
+
isCompute: false
|
|
11195
11356
|
});
|
|
11196
11357
|
}
|
|
11197
11358
|
}
|
|
@@ -11236,7 +11397,9 @@ class CommandAdapt {
|
|
|
11236
11397
|
return;
|
|
11237
11398
|
this.draw.render({
|
|
11238
11399
|
isSetCursor: false,
|
|
11239
|
-
isSubmitHistory: false
|
|
11400
|
+
isSubmitHistory: false,
|
|
11401
|
+
isCompute: false,
|
|
11402
|
+
isLazy: false
|
|
11240
11403
|
});
|
|
11241
11404
|
}
|
|
11242
11405
|
searchNavigateNext() {
|
|
@@ -11245,7 +11408,9 @@ class CommandAdapt {
|
|
|
11245
11408
|
return;
|
|
11246
11409
|
this.draw.render({
|
|
11247
11410
|
isSetCursor: false,
|
|
11248
|
-
isSubmitHistory: false
|
|
11411
|
+
isSubmitHistory: false,
|
|
11412
|
+
isCompute: false,
|
|
11413
|
+
isLazy: false
|
|
11249
11414
|
});
|
|
11250
11415
|
}
|
|
11251
11416
|
getSearchNavigateInfo() {
|
|
@@ -11348,12 +11513,13 @@ class CommandAdapt {
|
|
|
11348
11513
|
curIndex: firstIndex
|
|
11349
11514
|
});
|
|
11350
11515
|
}
|
|
11351
|
-
print() {
|
|
11516
|
+
async print() {
|
|
11352
11517
|
const { width, height, scale } = this.options;
|
|
11353
11518
|
if (scale !== 1) {
|
|
11354
11519
|
this.draw.setPageScale(1);
|
|
11355
11520
|
}
|
|
11356
|
-
|
|
11521
|
+
const base64List = await this.draw.getDataURL();
|
|
11522
|
+
printImageBase64(base64List, width, height);
|
|
11357
11523
|
if (scale !== 1) {
|
|
11358
11524
|
this.draw.setPageScale(scale);
|
|
11359
11525
|
}
|