@hailin-zheng/editor-core 2.1.18 → 2.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/index-cjs.d.ts +0 -1
  2. package/index-cjs.js +983 -1720
  3. package/index-cjs.js.map +1 -1
  4. package/index.d.ts +0 -1
  5. package/index.js +979 -1719
  6. package/index.js.map +1 -1
  7. package/med_editor/doc-editor.d.ts +2 -0
  8. package/med_editor/editor-core.d.ts +4 -0
  9. package/med_editor/framework/common-util.d.ts +1 -0
  10. package/med_editor/framework/document-arrange.d.ts +9 -4
  11. package/med_editor/framework/document-context.d.ts +0 -8
  12. package/med_editor/framework/document-paint.d.ts +3 -5
  13. package/med_editor/framework/document-print-offscreen.d.ts +4 -4
  14. package/med_editor/framework/document-svg.d.ts +10 -4
  15. package/med_editor/framework/element-define.d.ts +2 -4
  16. package/med_editor/framework/element-props.d.ts +23 -1
  17. package/med_editor/framework/element-reader.d.ts +6 -1
  18. package/med_editor/framework/event-subject.d.ts +9 -0
  19. package/med_editor/framework/impl/checkbox/checkbox-impl.d.ts +2 -3
  20. package/med_editor/framework/impl/comments/comment-content-impl.d.ts +1 -2
  21. package/med_editor/framework/impl/comments/comment-element-impl.d.ts +8 -2
  22. package/med_editor/framework/impl/comments/comments-container-impl.d.ts +3 -27
  23. package/med_editor/framework/impl/comments/validate-msg-impl.d.ts +1 -2
  24. package/med_editor/framework/impl/data-element/data-decorate-impl.d.ts +1 -2
  25. package/med_editor/framework/impl/data-element/data-element-barcode.d.ts +2 -5
  26. package/med_editor/framework/impl/data-element/data-element-base-impl.d.ts +0 -1
  27. package/med_editor/framework/impl/data-element/data-element-check-impl.d.ts +1 -2
  28. package/med_editor/framework/impl/data-element/data-element-group-impl.d.ts +1 -2
  29. package/med_editor/framework/impl/data-element/data-element-image-impl.d.ts +2 -7
  30. package/med_editor/framework/impl/decorate/fill-null-space-imple.d.ts +1 -2
  31. package/med_editor/framework/impl/document/doc-body-impl.d.ts +1 -2
  32. package/med_editor/framework/impl/document/doc-body-part-impl.d.ts +1 -2
  33. package/med_editor/framework/impl/document/doc-container-impl.d.ts +1 -2
  34. package/med_editor/framework/impl/document/doc-footer-impl.d.ts +1 -2
  35. package/med_editor/framework/impl/document/doc-header-impl.d.ts +1 -2
  36. package/med_editor/framework/impl/document/doc-impl.d.ts +21 -4
  37. package/med_editor/framework/impl/index.d.ts +1 -0
  38. package/med_editor/framework/impl/media-formula/menstrual-history.d.ts +1 -2
  39. package/med_editor/framework/impl/media-formula/permanent-teeth.d.ts +1 -2
  40. package/med_editor/framework/impl/paragraph/p-impl.d.ts +0 -2
  41. package/med_editor/framework/impl/picture/RectEle.d.ts +1 -6
  42. package/med_editor/framework/impl/picture/image-impl.d.ts +2 -7
  43. package/med_editor/framework/impl/radio/radio-impl.d.ts +1 -2
  44. package/med_editor/framework/impl/svg/svg-impl.d.ts +20 -0
  45. package/med_editor/framework/impl/symbol/br-symbol-impl.d.ts +1 -2
  46. package/med_editor/framework/impl/symbol/p-symbol-impl.d.ts +1 -2
  47. package/med_editor/framework/impl/symbol/page-br-symbol-impl.d.ts +1 -2
  48. package/med_editor/framework/impl/symbol/tab-symbol-impl.d.ts +1 -2
  49. package/med_editor/framework/impl/table/table-cell-impl.d.ts +1 -2
  50. package/med_editor/framework/impl/table/table-impl.d.ts +1 -2
  51. package/med_editor/framework/impl/table/table-row-impl.d.ts +1 -2
  52. package/med_editor/framework/impl/text/text-impl.d.ts +1 -2
  53. package/med_editor/framework/impl/text/track-run-impl.d.ts +1 -2
  54. package/med_editor/framework/range-util.d.ts +1 -1
  55. package/med_editor/framework/render-define.d.ts +0 -2
  56. package/med_editor/framework/selection-overlays.d.ts +4 -2
  57. package/package.json +1 -1
  58. package/med_editor/framework/document-images-loader.d.ts +0 -20
package/index-cjs.js CHANGED
@@ -275,8 +275,6 @@ class RenderObject {
275
275
  this.margin = new MarginProps();
276
276
  this.padding = new PaddingProps();
277
277
  }
278
- pagePaintCompleted(e) {
279
- }
280
278
  destroy() {
281
279
  //this.parent = null;
282
280
  //this.margin = null;
@@ -582,6 +580,16 @@ class CommonUtil {
582
580
  }
583
581
  return str;
584
582
  }
583
+ //随机生成rgb颜色
584
+ static randomRgbColor(opacity = -1) {
585
+ let r = Math.floor(Math.random() * 256); //随机生成256以内r值
586
+ let g = Math.floor(Math.random() * 256); //随机生成256以内g值
587
+ let b = Math.floor(Math.random() * 256); //随机生成256以内b值
588
+ if (opacity === -1) {
589
+ return `rgb(${r},${g},${b})`; //返回rgb(r,g,b)格式颜色
590
+ }
591
+ return `rgba(${r},${g},${b},${opacity})`; //返回rgba(r,g,b,a)格式颜色
592
+ }
585
593
  /**
586
594
  * 判断一个数值是否在另一个数值的增益区间中
587
595
  * @param val
@@ -1101,6 +1109,40 @@ class SubjectSubscription$1 extends Subscription$1 {
1101
1109
  function fromEvent(dom, type) {
1102
1110
  return new DOMEventSource(dom, type);
1103
1111
  }
1112
+ class EventBus {
1113
+ subs = new Map();
1114
+ on(event, handler) {
1115
+ let handlers = this.subs.get(event);
1116
+ if (!handlers) {
1117
+ handlers = [];
1118
+ this.subs.set(event, handlers);
1119
+ }
1120
+ const sub = new Subject$1();
1121
+ sub.subscribe(handler);
1122
+ handlers.push(sub);
1123
+ }
1124
+ off(event) {
1125
+ const subs = this.subs.get(event);
1126
+ if (subs) {
1127
+ subs.forEach(item => item.unsubscribe());
1128
+ }
1129
+ this.subs.delete(event);
1130
+ }
1131
+ emit(event, data) {
1132
+ const subs = this.subs.get(event);
1133
+ if (subs) {
1134
+ subs.forEach(item => item.next(data));
1135
+ }
1136
+ }
1137
+ clear() {
1138
+ this.subs.forEach((subs) => {
1139
+ subs.forEach((sub) => {
1140
+ sub.unsubscribe();
1141
+ });
1142
+ });
1143
+ this.subs.clear();
1144
+ }
1145
+ }
1104
1146
 
1105
1147
  class Rect {
1106
1148
  x = 0;
@@ -1705,17 +1747,7 @@ class ViewOptions {
1705
1747
  //两个页的间距
1706
1748
  docSpace = 0;
1707
1749
  //是否显示审阅窗口
1708
- _showReviewWindow = false;
1709
- get showReviewWindow() {
1710
- return this._showReviewWindow;
1711
- }
1712
- set showReviewWindow(value) {
1713
- if (value === this._showReviewWindow) {
1714
- return;
1715
- }
1716
- this._showReviewWindow = value;
1717
- // this.onChange.next();
1718
- }
1750
+ showReviewWindow = false;
1719
1751
  //审阅窗口宽度
1720
1752
  reviewWindowWidth = 200;
1721
1753
  //缩放
@@ -2218,6 +2250,32 @@ class PictureProps extends INotifyPropertyChanged {
2218
2250
  return props;
2219
2251
  }
2220
2252
  }
2253
+ class SVGProps extends INotifyPropertyChanged {
2254
+ title;
2255
+ width = 5;
2256
+ height = 5;
2257
+ value;
2258
+ clone(dest) {
2259
+ const clone = dest ?? new SVGProps();
2260
+ super.cloneAttachedProperty(clone);
2261
+ clone.width = this.width;
2262
+ clone.height = this.height;
2263
+ clone.value = this.value;
2264
+ clone.title = this.title;
2265
+ return clone;
2266
+ }
2267
+ getSerializeProps(viewOptions) {
2268
+ const props = {
2269
+ width: this.width,
2270
+ height: this.height,
2271
+ value: this.value,
2272
+ };
2273
+ if (this.title) {
2274
+ props['title'] = this.title;
2275
+ }
2276
+ return props;
2277
+ }
2278
+ }
2221
2279
  class DataDecorateProps extends INotifyPropertyChanged {
2222
2280
  content;
2223
2281
  size;
@@ -2400,32 +2458,47 @@ class CommContentProps extends INotifyPropertyChanged {
2400
2458
  createId;
2401
2459
  createName;
2402
2460
  createDate;
2461
+ text;
2403
2462
  clone(dest) {
2404
2463
  const clone = dest ?? new CommContentProps();
2405
2464
  super.cloneAttachedProperty(clone);
2406
2465
  clone.id = this.id;
2466
+ clone.text = this.text;
2407
2467
  return clone;
2408
2468
  }
2409
2469
  getSerializeProps(viewOptions) {
2410
2470
  return {
2411
- id: this.id
2471
+ id: this.id,
2472
+ text: this.text
2412
2473
  };
2413
2474
  }
2414
2475
  }
2415
2476
  class CommProps extends INotifyPropertyChanged {
2416
2477
  id;
2417
2478
  markType;
2479
+ text;
2480
+ userId;
2481
+ userName;
2482
+ date;
2418
2483
  clone(dest) {
2419
2484
  const clone = dest ?? new CommProps();
2420
2485
  super.cloneAttachedProperty(clone);
2421
2486
  clone.id = this.id;
2422
2487
  clone.markType = this.markType;
2488
+ clone.text = this.text;
2489
+ clone.userId = this.userId;
2490
+ clone.userName = this.userName;
2491
+ clone.date = this.date;
2423
2492
  return clone;
2424
2493
  }
2425
2494
  getSerializeProps(viewOptions) {
2426
2495
  return {
2427
2496
  id: this.id,
2428
- markType: this.markType
2497
+ markType: this.markType,
2498
+ text: this.text,
2499
+ userId: this.userId,
2500
+ userName: this.userName,
2501
+ date: this.date
2429
2502
  };
2430
2503
  }
2431
2504
  }
@@ -2753,76 +2826,11 @@ class CommsContainerElement extends BlockContainerElement {
2753
2826
  }
2754
2827
  return clone;
2755
2828
  }
2756
- markPairs = [];
2757
- /**
2758
- * 清除所有的批注标识组合
2759
- */
2760
- clearMarkItems() {
2761
- this.markPairs.length = 0;
2762
- }
2763
- identifyCommMark(markElement) {
2764
- const { id } = markElement.props;
2765
- let matchItem = this.markPairs.find(item => item.id === id);
2766
- if (!matchItem) {
2767
- matchItem = { id };
2768
- this.markPairs.push(matchItem);
2769
- }
2770
- matchItem[markElement.props.markType] = markElement;
2771
- }
2772
- /**
2773
- * 根据id,移除批注标记以及批注内容
2774
- * @param id
2775
- */
2776
- removeCommMark(id) {
2777
- const matchIndex = this.markPairs.findIndex(item => item.id === id);
2778
- if (matchIndex >= 0) {
2779
- const matchItem = this.markPairs[matchIndex];
2780
- matchItem.start?.remove();
2781
- matchItem.end?.remove();
2782
- this.markPairs.splice(matchIndex, 1);
2783
- }
2784
- const commContent = this.getCommContent(id);
2785
- if (commContent) {
2786
- commContent.remove();
2787
- }
2788
- }
2789
- /**
2790
- * 清除所有批注
2791
- */
2792
- clearAllComms() {
2793
- for (let i = 0; i < this.markPairs.length; i++) {
2794
- const { start, end } = this.markPairs[i];
2795
- if (start) {
2796
- start.remove();
2797
- }
2798
- if (end) {
2799
- end.remove();
2800
- }
2801
- }
2802
- this.clearItems();
2803
- }
2804
- getCommContent(id) {
2805
- for (let i = 0; i < this.length; i++) {
2806
- const commContent = this.getChild(i);
2807
- if (commContent.props.id === id) {
2808
- return commContent;
2809
- }
2810
- }
2811
- return null;
2812
- }
2813
2829
  }
2814
2830
  class CommsContainerRenderObject extends BlockContainerRenderObject {
2815
2831
  //批注内容是否已经重组,只要重新绘制的时候组合一次即可
2816
2832
  isMeasureComm;
2817
- selectedSet;
2818
- commentRangeStatus = [];
2819
2833
  commsMarks = [];
2820
- render(e) {
2821
- if (this.rect.height === 0) {
2822
- return;
2823
- }
2824
- e.render.contentContext.strokeRect(e.position.x, e.position.y, this.rect.width, this.rect.height, 'black', 0.5);
2825
- }
2826
2834
  clone() {
2827
2835
  const clone = new CommsContainerRenderObject(this.element);
2828
2836
  clone.rect = ElementUtil.cloneRect(this.rect);
@@ -2903,9 +2911,6 @@ class DataDecorateElement extends LeafElement {
2903
2911
  }
2904
2912
  }
2905
2913
  class DataDecorateRenderObject extends LeafRenderObject {
2906
- render(e) {
2907
- this.renderDecorRect(e.render, e.position);
2908
- }
2909
2914
  renderDecorRect(ctx, position) {
2910
2915
  if (ctx.drawMode === 'print') {
2911
2916
  return;
@@ -3115,10 +3120,6 @@ class ParagraphElement extends BlockContentElement {
3115
3120
  }
3116
3121
  }
3117
3122
  class ParagraphRenderObject extends MuiltBlockLineRenderObject {
3118
- render(e) {
3119
- e.nextRender();
3120
- this.drawProjectNumber(e.render, e.docCtx.viewOptions, e);
3121
- }
3122
3123
  /**
3123
3124
  * 绘制项目符号
3124
3125
  */
@@ -3196,8 +3197,6 @@ class ParagraphLineRectRenderObject extends BlockLineRectRenderObject {
3196
3197
  baseTopLine = 0;
3197
3198
  baseBottomLine = 0;
3198
3199
  startX = 0;
3199
- render(e) {
3200
- }
3201
3200
  clone() {
3202
3201
  const cloneRender = new ParagraphLineRectRenderObject(this.element);
3203
3202
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
@@ -3271,7 +3270,7 @@ class DocumentElement extends BlockContainerElement {
3271
3270
  bodyElement;
3272
3271
  headerElement;
3273
3272
  footerElement;
3274
- commentsContainerElement;
3273
+ //commentsContainerElement!: CommsContainerElement;
3275
3274
  headerEditState = false;
3276
3275
  constructor() {
3277
3276
  super('doc');
@@ -3349,6 +3348,49 @@ class DocumentElement extends BlockContainerElement {
3349
3348
  ss.clear();
3350
3349
  this.refreshView();
3351
3350
  }
3351
+ markPairs = [];
3352
+ /**
3353
+ * 清除所有的批注标识组合
3354
+ */
3355
+ clearMarkItems() {
3356
+ this.markPairs.length = 0;
3357
+ }
3358
+ identifyCommMark(markElement) {
3359
+ const { id } = markElement.props;
3360
+ let matchItem = this.markPairs.find(item => item.id === id);
3361
+ if (!matchItem) {
3362
+ matchItem = { id };
3363
+ this.markPairs.push(matchItem);
3364
+ }
3365
+ matchItem[markElement.props.markType] = markElement;
3366
+ }
3367
+ /**
3368
+ * 根据id,移除批注标记以及批注内容
3369
+ * @param id
3370
+ */
3371
+ removeCommMark(id) {
3372
+ const matchIndex = this.markPairs.findIndex(item => item.id === id);
3373
+ if (matchIndex >= 0) {
3374
+ const matchItem = this.markPairs[matchIndex];
3375
+ matchItem.start?.remove();
3376
+ matchItem.end?.remove();
3377
+ this.markPairs.splice(matchIndex, 1);
3378
+ }
3379
+ }
3380
+ /**
3381
+ * 清除所有批注
3382
+ */
3383
+ clearAllComms() {
3384
+ for (let i = 0; i < this.markPairs.length; i++) {
3385
+ const { start, end } = this.markPairs[i];
3386
+ if (start) {
3387
+ start.remove();
3388
+ }
3389
+ if (end) {
3390
+ end.remove();
3391
+ }
3392
+ }
3393
+ }
3352
3394
  }
3353
3395
  class DocumentRenderObject extends BlockContainerRenderObject {
3354
3396
  constructor(ele) {
@@ -3356,21 +3398,6 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3356
3398
  }
3357
3399
  headerLine;
3358
3400
  footerLine;
3359
- render(e) {
3360
- const { render, position, docCtx: { viewOptions } } = e;
3361
- const { width: docWidth, height: docHeight } = viewOptions.docPageSettings;
3362
- render.overlaysContext.fillRect(position.x, position.y, docWidth, this.rect.height, 'white', 5, 'black');
3363
- e.render.tran(() => {
3364
- e.render.contentContext.ctx.fillStyle = e.docCtx.viewOptions.defaultColor;
3365
- this.checkPrintMode(e);
3366
- e.nextRender();
3367
- this.drawCopyRight(viewOptions, render, position);
3368
- this.drawDocPageNum(render, viewOptions, position);
3369
- //绘制文档边距线
3370
- this.drawMarginLine(position, render, docWidth, docHeight);
3371
- this.drawWatermark(render, viewOptions, position);
3372
- });
3373
- }
3374
3401
  /**
3375
3402
  * 打印模式检查
3376
3403
  * 如果是续打模式,需要进行裁剪打印范围,页眉页脚都不需要打印
@@ -3806,45 +3833,6 @@ function getCurrOptions(ele) {
3806
3833
  return doc?.viewOptions;
3807
3834
  }
3808
3835
  class DataElementRenderObject extends InlineGroupRenderObject {
3809
- render(e) {
3810
- const { render, position, docCtx: { viewOptions } } = e;
3811
- this.paintPos = e.position;
3812
- //数据元不打印
3813
- if (!this.element.props.printable && render.drawMode === 'print') {
3814
- return;
3815
- }
3816
- render.contentContext.tran(() => {
3817
- //绘制数据元区域底色
3818
- let bgColor = '';
3819
- if (this.element.isMouseenter) {
3820
- bgColor = this.element.props.editable ? viewOptions.dataEleOverlaysColor : viewOptions.dataEleReadOnlyOverlayColor;
3821
- }
3822
- if (this.element.isFocused) {
3823
- bgColor = e.docCtx.viewOptions.dataEleFocusedBgColor;
3824
- }
3825
- if (this.element.errorTip) {
3826
- bgColor = viewOptions.dataEleErrorBgColor;
3827
- }
3828
- if (bgColor) {
3829
- render.contentContext.fillRect(position.x, position.y, this.rect.width, this.rect.height, bgColor);
3830
- }
3831
- if (this.element.props.secretBrowse && viewOptions.secretBrowse) {
3832
- render.contentContext.ctx.filter = "blur(10px)";
3833
- }
3834
- if (this.element.props.underline) {
3835
- const y = position.y + 2 + this.rect.height;
3836
- render.contentContext.strokeLines([{ x: position.x, y }, {
3837
- x: position.x + this.rect.width,
3838
- y
3839
- }], 1, '#595959');
3840
- }
3841
- e.nextRender();
3842
- this.drawCaption(e);
3843
- });
3844
- e.render.onRenderCompleted.subscribe(() => {
3845
- drawDecorator(e, this);
3846
- });
3847
- }
3848
3836
  exportHTML(event) {
3849
3837
  const node = super.exportHTML(event);
3850
3838
  exportDecoratorHTML(event, this);
@@ -4130,15 +4118,6 @@ class DocumentBodyElement extends BlockContainerElement {
4130
4118
  }
4131
4119
  }
4132
4120
  class DocumentBodyRenderObject extends MuiltBlockLineRenderObject {
4133
- render(e) {
4134
- const { render, position } = e;
4135
- render.tran(() => {
4136
- if (this.element.disableClick && render.drawMode === 'view') {
4137
- render.contentContext.setGlobalAlpha(0.5);
4138
- }
4139
- e.nextRender();
4140
- });
4141
- }
4142
4121
  clone(cloneData = true) {
4143
4122
  const cloneRender = new DocumentBodyRenderObject(this.element);
4144
4123
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
@@ -4208,22 +4187,6 @@ class DocumentFooterElement extends BlockContainerElement {
4208
4187
  }
4209
4188
  }
4210
4189
  class DocumentFooterRenderObject extends BlockContainerRenderObject {
4211
- render(e) {
4212
- const { render, position } = e;
4213
- render.tran(() => {
4214
- //判断页眉是否为输入内容
4215
- const isFooterEmpty = ElementUtil.checkEmptyRenderContent(this);
4216
- if (this.element.disableClick && render.drawMode === 'view') {
4217
- if (isFooterEmpty) {
4218
- render.contentContext.setGlobalAlpha(0);
4219
- }
4220
- else {
4221
- render.contentContext.setGlobalAlpha(0.5);
4222
- }
4223
- }
4224
- e.nextRender();
4225
- });
4226
- }
4227
4190
  clone() {
4228
4191
  const cloneRender = new DocumentFooterRenderObject(this.element);
4229
4192
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
@@ -4304,27 +4267,6 @@ class DocumentHeaderElement extends BlockContainerElement {
4304
4267
  }
4305
4268
  }
4306
4269
  class DocumentHeaderRenderObject extends BlockContainerRenderObject {
4307
- render(e) {
4308
- const { render, position } = e;
4309
- render.tran(() => {
4310
- //判断页眉是否为输入内容
4311
- const isHeaderEmpty = ElementUtil.checkEmptyRenderContent(this);
4312
- //存在输入内容时,绘制页眉-页体分割线
4313
- if (!isHeaderEmpty || !this.element.disableClick) {
4314
- const headerLineY = this.rect.height;
4315
- render.contentContext.drawHoriLine(position.x, position.y + headerLineY, this.rect.width, 'black', 0.5);
4316
- }
4317
- if (this.element.disableClick && render.drawMode === 'view') {
4318
- if (isHeaderEmpty) {
4319
- render.contentContext.setGlobalAlpha(0);
4320
- }
4321
- else {
4322
- render.contentContext.setGlobalAlpha(0.5);
4323
- }
4324
- }
4325
- e.nextRender();
4326
- });
4327
- }
4328
4270
  clone() {
4329
4271
  const cloneRender = new DocumentHeaderRenderObject(this.element);
4330
4272
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
@@ -4404,13 +4346,6 @@ class PSymbolElement extends LeafElement {
4404
4346
  }
4405
4347
  }
4406
4348
  class PSymbolRenderObject extends LeafRenderObject {
4407
- render(e) {
4408
- const { render, position } = e;
4409
- if (render.drawMode === 'print' || !e.docCtx.viewOptions.showParaSymbol) {
4410
- return;
4411
- }
4412
- render.contentContext.drawText('↩', this.element.textProps, position.x, position.y, 20, this.rect.height);
4413
- }
4414
4349
  exportHTML(event) {
4415
4350
  if (!event.options.showEnterSymbol || event.mode === 'print') {
4416
4351
  return null;
@@ -4523,22 +4458,6 @@ class TableCellElement extends BlockContainerElement {
4523
4458
  }
4524
4459
  }
4525
4460
  class TableCellRenderObject extends InlineMuiltBlockLineRenderObject {
4526
- render(e) {
4527
- const { render, position } = e;
4528
- render.tran(() => {
4529
- render.contentContext.clip(position.x, position.y, this.rect.width, this.rect.height);
4530
- const { hMerge, vMerge, backgroundColor, diagonal } = this.element.props;
4531
- if (hMerge === 'continue' || vMerge === 'continue') {
4532
- render.contentContext.setGlobalAlpha(0);
4533
- render.overlaysContext.setGlobalAlpha(0);
4534
- }
4535
- if (backgroundColor && this.rect.width && this.rect.height) {
4536
- render.contentContext.fillRect(position.x, position.y, this.rect.width, this.rect.height, backgroundColor);
4537
- }
4538
- this.renderDiagonal(render, diagonal, position);
4539
- e.nextRender();
4540
- });
4541
- }
4542
4461
  /**
4543
4462
  * 绘制对角线
4544
4463
  * @private
@@ -4706,9 +4625,7 @@ class TableRowRenderObject extends MuiltBlockLineRenderObject {
4706
4625
  //被截断的行是否需要重新计算高度
4707
4626
  remeasureState = true;
4708
4627
  //当前行是否存在合并单元格
4709
- hasMergeCells = false;
4710
- render(e) {
4711
- }
4628
+ hasMergeCells = undefined;
4712
4629
  clone() {
4713
4630
  const cloneRender = new TableRowRenderObject(this.element);
4714
4631
  cloneRender.remeasureState = this.remeasureState;
@@ -4737,17 +4654,6 @@ class DocumentContainerRender extends BlockContainerRenderObject {
4737
4654
  constructor() {
4738
4655
  super(null);
4739
4656
  }
4740
- render(e) {
4741
- const { render, nextRender, docCtx: { viewOptions } } = e;
4742
- const { viewSettings, docPageSettings, viewBackcolor, scale } = viewOptions;
4743
- render.clear();
4744
- //render.overlaysContext.fillRect(0, 0, viewSettings.width, viewSettings.height, viewBackcolor);
4745
- render.tran(() => {
4746
- render.overlaysContext.ctx.scale(scale, scale);
4747
- render.contentContext.ctx.scale(scale, scale);
4748
- nextRender();
4749
- });
4750
- }
4751
4657
  clone() {
4752
4658
  throw new Error("Method not implemented.");
4753
4659
  }
@@ -4864,17 +4770,6 @@ class TextGroupElement extends LeafElement {
4864
4770
  }
4865
4771
  class TextGroupRenderObject extends LeafRenderObject {
4866
4772
  textMeasures;
4867
- render(e) {
4868
- const { render, position } = e;
4869
- //null-text不打印
4870
- if (render.drawMode === 'print' && this.element.isDecorate) {
4871
- return;
4872
- }
4873
- if (this.element.props.border) {
4874
- render.contentContext.strokeRect(position.x, position.y, this.rect.width, this.rect.height);
4875
- }
4876
- render.contentContext.drawTextUnits(this, position.x, position.y + (this.rect.height - this.element.props.fontSize) / 2);
4877
- }
4878
4773
  constructor(element) {
4879
4774
  super(element);
4880
4775
  }
@@ -5345,7 +5240,7 @@ class DocumentCursor {
5345
5240
  }
5346
5241
 
5347
5242
  class RangeUtil {
5348
- static getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl) {
5243
+ static getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl) {
5349
5244
  if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
5350
5245
  const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
5351
5246
  return this.getTableSelectionRange(startControl, startOffset, endControl, endOffset, tbElement);
@@ -5424,7 +5319,7 @@ class RangeUtil {
5424
5319
  });
5425
5320
  }
5426
5321
  else {
5427
- const cellRange = this.getSelctionRange(cellFirstLeafElement, 0, cellLastLeafElement, 1, cell);
5322
+ const cellRange = this.getSectionRange(cellFirstLeafElement, 0, cellLastLeafElement, 1, cell);
5428
5323
  cellRanges.push(cellRange);
5429
5324
  }
5430
5325
  }
@@ -6590,56 +6485,6 @@ class TableRenderObject extends MuiltBlockLineRenderObject {
6590
6485
  setRenderWidth(maxWidth) {
6591
6486
  super.setRenderWidth(maxWidth);
6592
6487
  }
6593
- render(e) {
6594
- const { render, position } = e;
6595
- //绘制表格线
6596
- const border = this.element.props.border;
6597
- if (border === 'none') {
6598
- return;
6599
- }
6600
- const lineDash = border === 'dashed' ? [2, 2] : [];
6601
- for (let i = 0; i < this.length; i++) {
6602
- const rowRender = this.getChild(i);
6603
- const rowPos = { x: rowRender.rect.x + position.x, y: rowRender.rect.y + position.y };
6604
- for (let j = 0; j < rowRender.length; j++) {
6605
- const cellRender = rowRender.getChild(j);
6606
- const cellPos = { x: cellRender.rect.x + rowPos.x, y: cellRender.rect.y + rowPos.y };
6607
- //绘制单元格上边框
6608
- if (i === 0) {
6609
- //ctx.contentContext.fillRect(cellPos.x, cellPos.y, cellRender.rect.width, 1);
6610
- render.contentContext.fillLines([{ x: cellPos.x, y: cellPos.y }, {
6611
- x: cellPos.x + cellRender.rect.width,
6612
- y: cellPos.y
6613
- }], 1, '#000', lineDash);
6614
- //this.drawLine(ctx, { x: cellPos.x, y: cellPos.y }, { x: cellPos.x + cellRender.rect.width, y: cellPos.y });
6615
- }
6616
- //绘制左边框
6617
- if (j === 0) {
6618
- //ctx.contentContext.fillRect(cellPos.x, cellPos.y, 1, cellRender.rect.height);
6619
- render.contentContext.fillLines([{ x: cellPos.x, y: cellPos.y }, {
6620
- x: cellPos.x,
6621
- y: cellPos.y + cellRender.rect.height
6622
- }], 1, '#000', lineDash);
6623
- //this.drawLine(ctx, { x: cellPos.x, y: cellPos.y }, { x: cellPos.x, y: cellPos.y + cellRender.rect.height });
6624
- }
6625
- //绘制右边框
6626
- //ctx.contentContext.fillRect(cellPos.x + cellRender.rect.width, cellPos.y, 1, cellRender.rect.height);
6627
- render.contentContext.fillLines([{
6628
- x: cellPos.x + cellRender.rect.width,
6629
- y: cellPos.y
6630
- }, { x: cellPos.x + cellRender.rect.width, y: cellPos.y + cellRender.rect.height }], 1, '#000', lineDash);
6631
- //this.drawLine(ctx, { x: cellPos.x + cellRender.rect.width, y: cellPos.y }, { x: cellPos.x + cellRender.rect.width, y: cellPos.y + cellRender.rect.height });
6632
- //绘制下边框
6633
- //ctx.contentContext.fillRect(cellPos.x, cellPos.y + cellRender.rect.height, cellRender.rect.width, 1);
6634
- render.contentContext.fillLines([{
6635
- x: cellPos.x,
6636
- y: cellPos.y + cellRender.rect.height
6637
- }, { x: cellPos.x + cellRender.rect.width, y: cellPos.y + cellRender.rect.height }], 1, '#000', lineDash);
6638
- //this.drawLine(ctx, { x: cellPos.x, y: cellPos.y + cellRender.rect.height }, { x: cellPos.x + cellRender.rect.width, y: cellPos.y + cellRender.rect.height });
6639
- //cellRender.beginRender(ctx, { x: position.x + cellRender.offsetX, y: position.y + cellRender.offsetY });
6640
- }
6641
- }
6642
- }
6643
6488
  exportTableBorder() {
6644
6489
  //绘制表格线
6645
6490
  const border = this.element.props.border;
@@ -6924,10 +6769,7 @@ class CheckBoxFactory extends ElementFactory {
6924
6769
  }
6925
6770
  }
6926
6771
  class CheckBoxRenderObject extends LeafRenderObject {
6927
- render(e) {
6928
- e.render.contentContext.drawCheckBox(e.position.x + 2, e.position.y, this.element.props.size, this.element.props.size, this.element.props.isChecked);
6929
- }
6930
- clone(cloneData = true) {
6772
+ clone() {
6931
6773
  const clone = new CheckBoxRenderObject(this.element);
6932
6774
  clone.rect = ElementUtil.cloneRect(this.rect);
6933
6775
  return clone;
@@ -7026,34 +6868,6 @@ class CommContentElement extends CommContentBaseElement {
7026
6868
  }
7027
6869
  }
7028
6870
  class CommContentRenderObject extends CommContentBaseRenderObject {
7029
- render(e) {
7030
- let borderColor = this.element.focus ? '#fa8c16' : '#ffd591';
7031
- e.render.contentContext.strokeRect(e.position.x, e.position.y, this.rect.width, this.rect.height, borderColor);
7032
- e.render.contentContext.fillRect(e.position.x, e.position.y, 8, this.rect.height, '#871400');
7033
- const docRender = ElementUtil.getParentRender(this.commMarkRender.render, DocumentRenderObject);
7034
- //获取审阅标记的绘制坐标
7035
- let commMarkPos = ElementUtil.getRenderAbsolutePaintPos(this.commMarkRender.render, {
7036
- x: 0,
7037
- y: -e.docCtx.viewOptions.pageOffset.y
7038
- });
7039
- const commMarkLinePos = ElementUtil.getParaLinePos(this.commMarkRender.render, commMarkPos);
7040
- commMarkPos.y = commMarkLinePos.y + 2;
7041
- const docRenderPos = ElementUtil.getRenderAbsolutePaintPos(docRender, {
7042
- x: 0,
7043
- y: -e.docCtx.viewOptions.pageOffset.y
7044
- });
7045
- const marginLeft = commMarkPos.x - docRenderPos.x - docRender.padding.left;
7046
- const marginRight = e.docCtx.viewOptions.docPageSettings.width - marginLeft - docRender.padding.right * 2;
7047
- e.render.overlaysContext.drawDashLine([commMarkPos, {
7048
- x: commMarkPos.x + marginRight,
7049
- y: commMarkPos.y
7050
- }], [1, 1], 'red');
7051
- e.render.overlaysContext.drawDashLine([{
7052
- x: commMarkPos.x + marginRight,
7053
- y: commMarkPos.y
7054
- }, e.position], [1, 1], 'red');
7055
- this.renderTitle(e.render, e.position);
7056
- }
7057
6871
  exportHTML(event) {
7058
6872
  const t = super.exportHTML(event);
7059
6873
  t.children = [];
@@ -7263,26 +7077,56 @@ class CommentsUtil {
7263
7077
  }
7264
7078
  }
7265
7079
 
7266
- class CommentElement extends LeafElement {
7267
- constructor() {
7268
- super('comm');
7269
- this.isDecorate = true;
7270
- this.disableClick = true;
7271
- this.props = new CommProps();
7272
- }
7273
- createRenderObject() {
7274
- const render = new CommentRenderObject(this);
7275
- render.rect.width = 0;
7276
- render.rect.height = 14;
7277
- return render;
7278
- }
7279
- serialize(viewOptions) {
7280
- if (this.isDecorate) {
7281
- return null;
7282
- }
7283
- return {
7284
- type: this.type,
7285
- props: {
7080
+ let activeEditorContext = null;
7081
+ function setActiveEditorContext(ctx) {
7082
+ activeEditorContext = ctx;
7083
+ }
7084
+ function getActiveEditorContext() {
7085
+ return activeEditorContext;
7086
+ }
7087
+ function createSignal(state) {
7088
+ let _state = state;
7089
+ const activeCtx = activeEditorContext;
7090
+ const signal = {
7091
+ get value() {
7092
+ return _state;
7093
+ },
7094
+ set value(v) {
7095
+ if (v === _state) {
7096
+ return;
7097
+ }
7098
+ _state = v;
7099
+ signal.onChange();
7100
+ },
7101
+ onChange: () => {
7102
+ activeCtx?.onChange();
7103
+ }
7104
+ };
7105
+ return signal;
7106
+ }
7107
+
7108
+ class CommentElement extends LeafElement {
7109
+ color;
7110
+ constructor() {
7111
+ super('comm');
7112
+ this.isDecorate = true;
7113
+ this.disableClick = true;
7114
+ this.props = new CommProps();
7115
+ this.color = CommonUtil.randomRgbColor(0.5);
7116
+ }
7117
+ createRenderObject() {
7118
+ const render = new CommentRenderObject(this);
7119
+ render.rect.width = 0;
7120
+ render.rect.height = 14;
7121
+ return render;
7122
+ }
7123
+ serialize(viewOptions) {
7124
+ if (this.isDecorate) {
7125
+ return null;
7126
+ }
7127
+ return {
7128
+ type: this.type,
7129
+ props: {
7286
7130
  ...this.props.getSerializeProps(viewOptions)
7287
7131
  }
7288
7132
  };
@@ -7294,16 +7138,6 @@ class CommentElement extends LeafElement {
7294
7138
  }
7295
7139
  }
7296
7140
  class CommentRenderObject extends LeafRenderObject {
7297
- //renderPos!: Position;
7298
- render(e) {
7299
- // if (!e.docCtx.viewOptions.showReviewWindow) {
7300
- // return;
7301
- // }
7302
- // this.renderPos = e.position;
7303
- // const paraLinePos = ElementUtil.getParaLinePos(this, {x: e.position.x, y: e.position.y});
7304
- // const color = '#ff4d4f';
7305
- // e.render.contentContext.fillRect(e.position.x - 1, paraLinePos.y, 2, paraLinePos.height, color)
7306
- }
7307
7141
  exportHTML(event) {
7308
7142
  const renderPos = { ...event.relativePagePos };
7309
7143
  const paraLinePos = ElementUtil.getParaLinePos(this, { x: renderPos.x, y: renderPos.y });
@@ -7321,6 +7155,7 @@ class CommentRenderObject extends LeafRenderObject {
7321
7155
  }
7322
7156
  }
7323
7157
  }];
7158
+ this.createCommentTips(event);
7324
7159
  return t;
7325
7160
  }
7326
7161
  clone() {
@@ -7328,6 +7163,90 @@ class CommentRenderObject extends LeafRenderObject {
7328
7163
  clone.rect = ElementUtil.cloneRect(this.rect);
7329
7164
  return clone;
7330
7165
  }
7166
+ createCommentTips(event) {
7167
+ if (this.element.props.markType === 'end') {
7168
+ return;
7169
+ }
7170
+ if (this.element.paintRenders.indexOf(this) !== 0) {
7171
+ return;
7172
+ }
7173
+ const appCtx = getActiveEditorContext();
7174
+ const opType = '批注:';
7175
+ const content = this.element.props.text;
7176
+ const left = 5;
7177
+ let sel = 'div.tg-container';
7178
+ const node = {
7179
+ sel,
7180
+ key: this.element.props.id,
7181
+ data: {
7182
+ style: {
7183
+ left: `${left}px`,
7184
+ top: `${event.globalPos.y}px`
7185
+ },
7186
+ on: {
7187
+ click: (e) => {
7188
+ e.stopPropagation();
7189
+ appCtx?.emit('comment-click', {
7190
+ ...this.element.props
7191
+ });
7192
+ //this.showCommentRange(appCtx!);
7193
+ },
7194
+ dblclick: (e) => {
7195
+ e.stopPropagation();
7196
+ appCtx?.emit('comment-dblclick', {
7197
+ ...this.element.props
7198
+ });
7199
+ }
7200
+ }
7201
+ },
7202
+ children: [{
7203
+ sel: 'div.header',
7204
+ data: {},
7205
+ children: [{
7206
+ sel: 'span.header-user',
7207
+ data: {},
7208
+ text: this.element.props.userName,
7209
+ }, {
7210
+ sel: 'span.header-date',
7211
+ data: {},
7212
+ text: this.element.props.date,
7213
+ }]
7214
+ }, {
7215
+ sel: 'div.content',
7216
+ data: {},
7217
+ text: opType + content
7218
+ }, {
7219
+ sel: 'div.bg',
7220
+ data: {
7221
+ style: {
7222
+ background: this.element.color
7223
+ }
7224
+ }
7225
+ }]
7226
+ };
7227
+ event.addChangeTips(node);
7228
+ // <div class="container">
7229
+ // <div class="header">
7230
+ // <span class="header-user">张三</span>
7231
+ // <span class="header-date">2023.1.21 16:06</span>
7232
+ // </div>
7233
+ // <div class="content">修改了字符串</div>
7234
+ // </div>
7235
+ }
7236
+ /**
7237
+ * 显示批注范围
7238
+ * @private
7239
+ */
7240
+ showCommentRange(appCtx) {
7241
+ const doc = ElementUtil.getParent(this.element, (item) => item.type === 'doc');
7242
+ const commPair = doc.treeFilter(item => item instanceof CommentElement && item.props.id === this.element.props.id);
7243
+ if (commPair.length === 2) {
7244
+ const range = new SelectionRange();
7245
+ range.setStart(commPair[0], 0);
7246
+ range.setEnd(commPair[1], 1);
7247
+ appCtx.selectionState.addRange(range);
7248
+ }
7249
+ }
7331
7250
  }
7332
7251
  class CommentFactory extends ElementFactory {
7333
7252
  match(type) {
@@ -7338,6 +7257,7 @@ class CommentFactory extends ElementFactory {
7338
7257
  const props = data.props;
7339
7258
  ele.props.id = props.id;
7340
7259
  ele.props.markType = props.markType;
7260
+ ele.props.text = props.text;
7341
7261
  return ele;
7342
7262
  }
7343
7263
  }
@@ -7383,31 +7303,6 @@ class ValidateElement extends CommContentBaseElement {
7383
7303
  }
7384
7304
  }
7385
7305
  class ValidateRenderObject extends CommContentBaseRenderObject {
7386
- render(e) {
7387
- let borderColor = this.element.focus ? '#fa8c16' : '#ffd591';
7388
- e.render.contentContext.strokeRect(e.position.x, e.position.y, this.rect.width, this.rect.height, borderColor);
7389
- e.render.contentContext.fillRect(e.position.x, e.position.y, 8, this.rect.height, '#871400');
7390
- const docRender = ElementUtil.getParentRender(this.commMarkRender.render, DocumentRenderObject);
7391
- //获取审阅标记的绘制坐标
7392
- let commMarkPos = ElementUtil.getRenderAbsolutePaintPos(this.commMarkRender.render, {
7393
- x: 0,
7394
- y: -e.docCtx.viewOptions.pageOffset.y
7395
- });
7396
- const commMarkLinePos = ElementUtil.getParaLinePos(this.commMarkRender.render, commMarkPos);
7397
- commMarkPos.y = commMarkLinePos.y + 2;
7398
- const docRenderPos = ElementUtil.getRenderAbsolutePaintPos(docRender, { x: 0, y: -e.docCtx.viewOptions.pageOffset.y });
7399
- const marginLeft = commMarkPos.x - docRenderPos.x - docRender.padding.left;
7400
- const marginRight = e.docCtx.viewOptions.docPageSettings.width - marginLeft - docRender.padding.right * 2;
7401
- e.render.overlaysContext.drawDashLine([commMarkPos, {
7402
- x: commMarkPos.x + marginRight,
7403
- y: commMarkPos.y
7404
- }], [1, 1], 'red');
7405
- e.render.overlaysContext.drawDashLine([{
7406
- x: commMarkPos.x + marginRight,
7407
- y: commMarkPos.y
7408
- }, e.position], [1, 1], 'red');
7409
- this.renderTitle(e.render, e.position);
7410
- }
7411
7306
  renderTitle(ctx, position) {
7412
7307
  const topPadding = 24;
7413
7308
  const textProps = new TextProps();
@@ -8333,40 +8228,11 @@ class DataElementBarcode extends DataElementLeaf {
8333
8228
  }
8334
8229
  }
8335
8230
  class DataElementBarcodeRenderObject extends ResizeLeafRenderObject {
8336
- render(e) {
8337
- // const barcodeEle = this.element as DataElementBarcode;
8338
- // barcodeEle.drawBarcode(e.render, e.position);
8339
- }
8340
8231
  clone() {
8341
8232
  const clone = new DataElementBarcodeRenderObject(this.element);
8342
8233
  clone.rect = ElementUtil.cloneRect(this.rect);
8343
8234
  return clone;
8344
8235
  }
8345
- pagePaintCompleted(e) {
8346
- if (this.element.isFocused) {
8347
- const { render, position: pos } = e;
8348
- const { width, height } = this.rect;
8349
- render.contentContext.strokeRect(pos.x, pos.y, this.rect.width, this.rect.height, '#1890ff', 0.5);
8350
- this.drawResizeCircle(render, pos.x, pos.y);
8351
- this.drawResizeCircle(render, pos.x + width, pos.y);
8352
- this.drawResizeCircle(render, pos.x, pos.y + height);
8353
- this.drawResizeCircle(render, pos.x + width, pos.y + height);
8354
- this.drawResizeCircle(render, pos.x + (Math.floor(width / 2)), pos.y);
8355
- this.drawResizeCircle(render, pos.x + (Math.floor(width / 2)), pos.y + height);
8356
- this.drawResizeCircle(render, pos.x, pos.y + (Math.floor(height / 2)));
8357
- this.drawResizeCircle(render, pos.x + width, pos.y + (Math.floor(height / 2)));
8358
- }
8359
- }
8360
- drawResizeCircle(ctx, x, y) {
8361
- const ctxNative = ctx.contentContext.ctx;
8362
- ctxNative.save();
8363
- ctxNative.fillStyle = '#69c0ff';
8364
- ctxNative.beginPath();
8365
- ctxNative.arc(x, y, Math.floor(4 / 5 * 4), 0, 2 * Math.PI);
8366
- ctxNative.closePath();
8367
- ctxNative.fill();
8368
- ctxNative.restore();
8369
- }
8370
8236
  exportHTML(event) {
8371
8237
  const t = super.exportHTML(event);
8372
8238
  if (this.element.props.type === 'qrcode') {
@@ -8531,27 +8397,6 @@ class DataElementCheckRenderObject extends LeafRenderObject {
8531
8397
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
8532
8398
  return cloneRender;
8533
8399
  }
8534
- render(e) {
8535
- const { render, position } = e;
8536
- const element = this.element;
8537
- if (element.props.drawStateChar) {
8538
- const font = `${element.props.size - 2}px 微软雅黑`;
8539
- const str = element.props.checked ? element.props.trueChar : element.props.falseChar;
8540
- const color = element.props.checked ? element.props.trueStateColor : element.props.falseStateColor;
8541
- e.render.contentContext.drawText2(str, font, color, position.x, position.y, element.props.size, element.props.size);
8542
- if (element.props.border) {
8543
- e.render.contentContext.strokeRect(position.x + 2, position.y, element.props.size, element.props.size);
8544
- }
8545
- }
8546
- else {
8547
- if (element.props.multiSelect) {
8548
- render.contentContext.drawCheckBox(position.x + 2, position.y, element.props.size, element.props.size, element.props.checked);
8549
- }
8550
- else {
8551
- render.contentContext.drawRadioBox(position.x + 2, position.y, element.props.size, element.props.size, element.props.checked);
8552
- }
8553
- }
8554
- }
8555
8400
  exportHTML(event) {
8556
8401
  const t = super.exportHTML(event);
8557
8402
  const props = this.element.props;
@@ -8842,12 +8687,6 @@ class DataElementGroupElement extends InlineGroupInputElement {
8842
8687
  }
8843
8688
  }
8844
8689
  class DataElementGroupRenderObject extends InlineGroupRenderObject {
8845
- render(e) {
8846
- this.paintPos = e.position;
8847
- e.render.onRenderCompleted.subscribe(() => {
8848
- drawDecorator(e, this);
8849
- });
8850
- }
8851
8690
  clone() {
8852
8691
  const cloneRender = new DataElementGroupRenderObject(this.element);
8853
8692
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
@@ -8901,18 +8740,6 @@ class DataElementImage extends DataElementLeaf {
8901
8740
  this.props.clone(clone.props);
8902
8741
  return clone;
8903
8742
  }
8904
- loadImage(ctx) {
8905
- if (this.status === 'no') {
8906
- this.status = 'loading';
8907
- const onCallback = (status) => {
8908
- this.status = status;
8909
- if (status === 'completed') {
8910
- this.refreshView();
8911
- }
8912
- };
8913
- ctx.imageLoader.loadImage(this.props.src, onCallback);
8914
- }
8915
- }
8916
8743
  destroy() {
8917
8744
  super.destroy();
8918
8745
  }
@@ -8927,70 +8754,11 @@ class DataElementImage extends DataElementLeaf {
8927
8754
  }
8928
8755
  }
8929
8756
  class DataImageRenderObject extends ResizeLeafRenderObject {
8930
- render(e) {
8931
- const { render, position, docCtx } = e;
8932
- const dataImgElement = this.element;
8933
- const picProps = dataImgElement.props;
8934
- if (dataImgElement.status === 'no') {
8935
- dataImgElement.loadImage(docCtx);
8936
- return;
8937
- }
8938
- if (dataImgElement.status === 'completed') {
8939
- const imageSource = docCtx.imageLoader.getImage(picProps.src);
8940
- if (!imageSource) {
8941
- return;
8942
- }
8943
- if (picProps.border === 'all') {
8944
- render.contentContext.strokeRect(position.x, position.y, this.rect.width, this.rect.height, 'black');
8945
- }
8946
- render.contentContext.ctx.drawImage(imageSource, 0, 0, imageSource.naturalWidth, imageSource.naturalHeight, position.x + 2, position.y + 2, picProps.width, picProps.height);
8947
- }
8948
- if (render.drawMode === 'view') {
8949
- let { x, y } = position;
8950
- const { width, height } = this.rect;
8951
- const lineWidth = 5;
8952
- const paintColor = '#0050b3';
8953
- render.contentContext.strokeLines([{ x: x + lineWidth, y }, { x, y }, { x, y: y + height }, {
8954
- x: x + lineWidth,
8955
- y: y + height
8956
- }], 1, paintColor);
8957
- x = x + width;
8958
- render.contentContext.strokeLines([{ x: x - lineWidth, y }, { x, y }, { x, y: y + height }, {
8959
- x: x - lineWidth,
8960
- y: y + height
8961
- }], 1, paintColor);
8962
- }
8963
- }
8964
8757
  clone() {
8965
8758
  const clone = new DataImageRenderObject(this.element);
8966
8759
  clone.rect = ElementUtil.cloneRect(this.rect);
8967
8760
  return clone;
8968
8761
  }
8969
- pagePaintCompleted(e) {
8970
- if (this.element.isFocused) {
8971
- const { render, position: pos } = e;
8972
- const { width, height } = this.rect;
8973
- render.contentContext.strokeRect(pos.x, pos.y, this.rect.width, this.rect.height, '#1890ff', 0.5);
8974
- this.drawResizeCircle(render, pos.x, pos.y);
8975
- this.drawResizeCircle(render, pos.x + width, pos.y);
8976
- this.drawResizeCircle(render, pos.x, pos.y + height);
8977
- this.drawResizeCircle(render, pos.x + width, pos.y + height);
8978
- this.drawResizeCircle(render, pos.x + (Math.floor(width / 2)), pos.y);
8979
- this.drawResizeCircle(render, pos.x + (Math.floor(width / 2)), pos.y + height);
8980
- this.drawResizeCircle(render, pos.x, pos.y + (Math.floor(height / 2)));
8981
- this.drawResizeCircle(render, pos.x + width, pos.y + (Math.floor(height / 2)));
8982
- }
8983
- }
8984
- drawResizeCircle(ctx, x, y) {
8985
- const ctxNative = ctx.contentContext.ctx;
8986
- ctxNative.save();
8987
- ctxNative.fillStyle = '#69c0ff';
8988
- ctxNative.beginPath();
8989
- ctxNative.arc(x, y, Math.floor(4 / 5 * 4), 0, 2 * Math.PI);
8990
- ctxNative.closePath();
8991
- ctxNative.fill();
8992
- ctxNative.restore();
8993
- }
8994
8762
  exportHTML(event) {
8995
8763
  const t = super.exportHTML(event);
8996
8764
  t.children = [{
@@ -9226,13 +8994,6 @@ class BreakElement extends LeafElement {
9226
8994
  }
9227
8995
  }
9228
8996
  class BreakRenderObject extends LeafRenderObject {
9229
- render(e) {
9230
- const { render, position } = e;
9231
- if (render.drawMode === 'print') {
9232
- return;
9233
- }
9234
- render.contentContext.drawText('↓', this.element.textProps, position.x, position.y, 20, this.rect.height);
9235
- }
9236
8997
  exportHTML(event) {
9237
8998
  if (!event.options.showEnterSymbol || event.mode === 'print') {
9238
8999
  return null;
@@ -9398,8 +9159,6 @@ class FillNullSpaceRenderObject extends LeafRenderObject {
9398
9159
  super(null);
9399
9160
  this.disableClick = true;
9400
9161
  }
9401
- render(e) {
9402
- }
9403
9162
  clone() {
9404
9163
  const clone = new FillNullSpaceRenderObject();
9405
9164
  clone.rect = ElementUtil.cloneRect(this.rect);
@@ -9460,11 +9219,6 @@ class DocumentBodyPartElement extends BlockContainerElement {
9460
9219
  }
9461
9220
  }
9462
9221
  class DocumentBodyPartRenderObject extends MuiltBlockLineRenderObject {
9463
- render(e) {
9464
- const { render, position } = e;
9465
- const bgColor = (this.element.isFocused || this.element.isMouseenter) ? '#d9d9d9' : '#ffffff';
9466
- render.overlaysContext.fillRect(position.x - 2, position.y - 2, this.rect.width + 4, this.rect.height + 4, bgColor, 5, 'black');
9467
- }
9468
9222
  clone(cloneData = true) {
9469
9223
  const cloneRender = new DocumentBodyPartRenderObject(this.element);
9470
9224
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
@@ -9604,9 +9358,6 @@ function getMHItem(kind) {
9604
9358
  return mhLayoutItems[kindIndex];
9605
9359
  }
9606
9360
  class DataRenderMH extends LeafRenderObject {
9607
- render(e) {
9608
- renderMH(this.element, e.render, e.position, true);
9609
- }
9610
9361
  exportHTML(event) {
9611
9362
  const t = super.exportHTML(event);
9612
9363
  const children = [];
@@ -9836,80 +9587,16 @@ class PictureElement extends LeafElement {
9836
9587
  this.props.clone(clone.props);
9837
9588
  return clone;
9838
9589
  }
9839
- loadImage(ctx) {
9840
- if (this.status === 'no') {
9841
- this.status = 'loading';
9842
- //this.imageSource = new Image();
9843
- //this.imageSource.src = this.props.src;
9844
- // const onload = (e: any) => {
9845
- // this.isLoad = 'completed';
9846
- // this.refreshView('appearance');
9847
- // };
9848
- // const onerror = (e: any) => {
9849
- // this.isLoad = 'error';
9850
- // console.error(e);
9851
- // };
9852
- const onCallback = (status) => {
9853
- this.status = status;
9854
- if (status === 'completed') {
9855
- this.refreshView();
9856
- }
9857
- };
9858
- ctx.imageLoader.loadImage(this.props.src, onCallback);
9859
- }
9860
- }
9861
9590
  destroy() {
9862
9591
  super.destroy();
9863
9592
  }
9864
9593
  }
9865
9594
  class PictureRenderObject extends ResizeLeafRenderObject {
9866
- render(e) {
9867
- const { render, position, docCtx } = e;
9868
- const picElement = this.element;
9869
- const picProps = picElement.props;
9870
- if (picElement.status === 'no') {
9871
- picElement.loadImage(docCtx);
9872
- return;
9873
- }
9874
- if (picElement.status === 'completed') {
9875
- const imageSource = docCtx.imageLoader.getImage(picProps.src);
9876
- if (!imageSource) {
9877
- return;
9878
- }
9879
- if (picProps.border === 'all') {
9880
- render.contentContext.strokeRect(position.x, position.y, this.rect.width, this.rect.height, 'black');
9881
- }
9882
- render.contentContext.ctx.drawImage(imageSource, 0, 0, imageSource.naturalWidth, imageSource.naturalHeight, position.x + 2, position.y + 2, picProps.width, picProps.height);
9883
- }
9884
- }
9885
9595
  clone() {
9886
9596
  const clone = new PictureRenderObject(this.element);
9887
9597
  clone.rect = ElementUtil.cloneRect(this.rect);
9888
9598
  return clone;
9889
9599
  }
9890
- pagePaintCompleted(e) {
9891
- if (this.element.isFocused) {
9892
- const { render, position: pos } = e;
9893
- const { width, height } = this.rect;
9894
- render.contentContext.strokeRect(pos.x, pos.y, width, height, '#1890ff', 0.5);
9895
- this.drawResizeCircle(render, pos.x, pos.y);
9896
- this.drawResizeCircle(render, pos.x + width, pos.y);
9897
- this.drawResizeCircle(render, pos.x, pos.y + height);
9898
- this.drawResizeCircle(render, pos.x + width, pos.y + height);
9899
- this.drawResizeCircle(render, pos.x + (Math.floor(width / 2)), pos.y);
9900
- this.drawResizeCircle(render, pos.x + (Math.floor(width / 2)), pos.y + height);
9901
- this.drawResizeCircle(render, pos.x, pos.y + (Math.floor(height / 2)));
9902
- this.drawResizeCircle(render, pos.x + width, pos.y + (Math.floor(height / 2)));
9903
- }
9904
- }
9905
- drawResizeCircle(ctx, x, y) {
9906
- const ctxNative = ctx.contentContext.ctx;
9907
- ctxNative.fillStyle = '#69c0ff';
9908
- ctxNative.beginPath();
9909
- ctxNative.arc(x, y, Math.floor(4 / 5 * 4), 0, 2 * Math.PI);
9910
- ctxNative.closePath();
9911
- ctxNative.fill();
9912
- }
9913
9600
  exportHTML(event) {
9914
9601
  const picElement = this.element;
9915
9602
  const picProps = picElement.props;
@@ -10041,10 +9728,6 @@ class RadioBoxFactory extends ElementFactory {
10041
9728
  }
10042
9729
  }
10043
9730
  class RadioBoxRenderObject extends LeafRenderObject {
10044
- render(e) {
10045
- const { render, position } = e;
10046
- render.contentContext.drawRadioBox(position.x + 2, position.y, this.element.props.size, this.element.props.size, this.element.props.isChecked);
10047
- }
10048
9731
  clone(cloneData = true) {
10049
9732
  const clone = new RadioBoxRenderObject(this.element);
10050
9733
  clone.rect = ElementUtil.cloneRect(this.rect);
@@ -10083,13 +9766,6 @@ class PageBreakElement extends LeafElement {
10083
9766
  }
10084
9767
  }
10085
9768
  class PageBreakRenderObject extends LeafRenderObject {
10086
- render(e) {
10087
- const { render, position } = e;
10088
- if (render.drawMode === 'print') {
10089
- return;
10090
- }
10091
- render.contentContext.drawText('↩', this.element.textProps, position.x, position.y, 20, this.rect.height);
10092
- }
10093
9769
  clone() {
10094
9770
  const render = new PageBreakRenderObject(this.element);
10095
9771
  render.rect = ElementUtil.cloneRect(this.rect);
@@ -10126,13 +9802,6 @@ class TabElement extends LeafElement {
10126
9802
  }
10127
9803
  }
10128
9804
  class TabRenderObject extends LeafRenderObject {
10129
- render(e) {
10130
- const { render, position } = e;
10131
- if (render.drawMode === 'print') {
10132
- return;
10133
- }
10134
- //render.contentContext.fillRect(position.x,position.y,this.rect.width,this.rect.height,'red');
10135
- }
10136
9805
  clone() {
10137
9806
  const render = new TabRenderObject(this.element);
10138
9807
  render.rect = ElementUtil.cloneRect(this.rect);
@@ -10698,42 +10367,151 @@ class TableSplitCell {
10698
10367
  }
10699
10368
  }
10700
10369
 
10701
- class ElementSerialize {
10702
- /**
10703
- * 将当前文档对象构建并输出到标准的JSON对象
10704
- * @param element
10705
- * @param viewOptions
10706
- */
10707
- static serialize(element, viewOptions) {
10708
- const result = element.serialize(viewOptions);
10709
- if (!result) {
10710
- return null;
10711
- }
10712
- if (result.complete) {
10713
- return result;
10714
- }
10715
- if (element instanceof BranchElement) {
10716
- result.children = [];
10717
- let prevEle = null;
10718
- for (let i = 0; i < element.length; i++) {
10719
- const child = element.getChild(i);
10720
- const serializeChild = this.serialize(child, viewOptions);
10721
- if (child.type === 'text' && prevEle && prevEle.ele.type === 'text') {
10722
- if (child.props.equals(prevEle.ele.props)) {
10723
- prevEle.props.content += serializeChild.content;
10724
- continue;
10725
- }
10726
- }
10727
- if (serializeChild) {
10728
- delete serializeChild.complete;
10729
- serializeChild.props = serializeChild.props || {};
10730
- if (Object.keys(serializeChild.props).length === 0) {
10731
- delete serializeChild.props;
10732
- }
10733
- if (serializeChild.children && serializeChild.children.length === 0) {
10734
- delete serializeChild.children;
10735
- }
10736
- result.children.push(serializeChild);
10370
+ class SVGElement extends LeafElement {
10371
+ resizeable = true;
10372
+ constructor() {
10373
+ super('svg');
10374
+ this.props = new SVGProps();
10375
+ //this.addPropValueChangedSub(this.props);
10376
+ this.cursorType = 'move';
10377
+ this.focusable = true;
10378
+ }
10379
+ createRenderObject() {
10380
+ const render = new SVGRenderObject(this);
10381
+ render.rect.width = this.props.width;
10382
+ render.rect.height = this.props.height;
10383
+ return render;
10384
+ }
10385
+ serialize(options) {
10386
+ return {
10387
+ type: 'svg',
10388
+ props: {
10389
+ ...this.props.getSerializeProps(options)
10390
+ }
10391
+ };
10392
+ }
10393
+ clone(data) {
10394
+ const clone = new SVGElement();
10395
+ this.props.clone(clone.props);
10396
+ return clone;
10397
+ }
10398
+ destroy() {
10399
+ super.destroy();
10400
+ }
10401
+ }
10402
+ class SVGRenderObject extends ResizeLeafRenderObject {
10403
+ clone() {
10404
+ const clone = new SVGRenderObject(this.element);
10405
+ clone.rect = ElementUtil.cloneRect(this.rect);
10406
+ return clone;
10407
+ }
10408
+ drawResizeCircle(ctx, x, y) {
10409
+ const ctxNative = ctx.contentContext.ctx;
10410
+ ctxNative.fillStyle = '#69c0ff';
10411
+ ctxNative.beginPath();
10412
+ ctxNative.arc(x, y, Math.floor(4 / 5 * 4), 0, 2 * Math.PI);
10413
+ ctxNative.closePath();
10414
+ ctxNative.fill();
10415
+ }
10416
+ exportHTML(event) {
10417
+ const props = this.element.props;
10418
+ const t = super.exportHTML(event);
10419
+ t.children = [{
10420
+ sel: 'svg',
10421
+ data: {
10422
+ ns: "http://www.w3.org/2000/svg",
10423
+ attrs: {
10424
+ width: this.rect.width,
10425
+ height: this.rect.height
10426
+ }
10427
+ },
10428
+ children: [{
10429
+ sel: 'image',
10430
+ data: {
10431
+ ns: "http://www.w3.org/2000/svg",
10432
+ attrs: {
10433
+ "xlink:href": props.value,
10434
+ width: Math.min(this.rect.width, this.rect.height),
10435
+ height: Math.min(this.rect.width, this.rect.height)
10436
+ }
10437
+ }
10438
+ }]
10439
+ }];
10440
+ //绘制拖动圆圈
10441
+ if (this.element.isFocused) {
10442
+ const { width, height } = this.rect;
10443
+ const circlePoints = [{ x: 0, y: 0 }, { x: width, y: 0 }, { x: 0, y: height }, { x: width, y: height }, { x: Math.floor(width / 2), y: 0 }, { x: Math.floor(width / 2), y: height }, { x: 0, y: Math.floor(height / 2) }, { x: width, y: Math.floor(height / 2) }];
10444
+ circlePoints.forEach((p) => {
10445
+ t.children.push({
10446
+ sel: 'circle',
10447
+ data: {
10448
+ ns: "http://www.w3.org/2000/svg",
10449
+ attrs: {
10450
+ cx: p.x,
10451
+ cy: p.y,
10452
+ r: Math.floor(4 / 5 * 4),
10453
+ fill: '#69c0ff'
10454
+ }
10455
+ }
10456
+ });
10457
+ });
10458
+ }
10459
+ return t;
10460
+ }
10461
+ }
10462
+ class SVGFactory extends ElementFactory {
10463
+ match(type) {
10464
+ return type === 'svg';
10465
+ }
10466
+ createElement(data) {
10467
+ const props = data.props;
10468
+ const pic = new SVGElement();
10469
+ const picProps = pic.props;
10470
+ picProps.width = props.width;
10471
+ picProps.height = props.height;
10472
+ picProps.value = props.value;
10473
+ picProps.title = props.title;
10474
+ pic.props = picProps;
10475
+ return pic;
10476
+ }
10477
+ }
10478
+
10479
+ class ElementSerialize {
10480
+ /**
10481
+ * 将当前文档对象构建并输出到标准的JSON对象
10482
+ * @param element
10483
+ * @param viewOptions
10484
+ */
10485
+ static serialize(element, viewOptions) {
10486
+ const result = element.serialize(viewOptions);
10487
+ if (!result) {
10488
+ return null;
10489
+ }
10490
+ if (result.complete) {
10491
+ return result;
10492
+ }
10493
+ if (element instanceof BranchElement) {
10494
+ result.children = [];
10495
+ let prevEle = null;
10496
+ for (let i = 0; i < element.length; i++) {
10497
+ const child = element.getChild(i);
10498
+ const serializeChild = this.serialize(child, viewOptions);
10499
+ if (child.type === 'text' && prevEle && prevEle.ele.type === 'text') {
10500
+ if (child.props.equals(prevEle.ele.props)) {
10501
+ prevEle.props.content += serializeChild.content;
10502
+ continue;
10503
+ }
10504
+ }
10505
+ if (serializeChild) {
10506
+ delete serializeChild.complete;
10507
+ serializeChild.props = serializeChild.props || {};
10508
+ if (Object.keys(serializeChild.props).length === 0) {
10509
+ delete serializeChild.props;
10510
+ }
10511
+ if (serializeChild.children && serializeChild.children.length === 0) {
10512
+ delete serializeChild.children;
10513
+ }
10514
+ result.children.push(serializeChild);
10737
10515
  prevEle = { ele: child, props: serializeChild };
10738
10516
  }
10739
10517
  }
@@ -10750,6 +10528,9 @@ class ElementSerialize {
10750
10528
  if (element instanceof TextGroupElement && !element.isDecorate) {
10751
10529
  return element.text;
10752
10530
  }
10531
+ if (element instanceof PSymbolElement) {
10532
+ return '\n';
10533
+ }
10753
10534
  if (element instanceof BranchElement) {
10754
10535
  const items = [];
10755
10536
  for (let i = 0; i < element.length; i++) {
@@ -10900,32 +10681,6 @@ class TrackRunRenderObject extends InlineGroupRenderObject {
10900
10681
  constructor(ele) {
10901
10682
  super(ele);
10902
10683
  }
10903
- render(e) {
10904
- const { render, position, docCtx: { viewOptions } } = e;
10905
- render.tran(() => {
10906
- let fillColor = viewOptions.showTrackChanges ? this.element.type === 'ins-run' ? viewOptions.trackInsColor : viewOptions.trackDelColor : '';
10907
- if (fillColor) {
10908
- render.contentContext.ctx.fillStyle = fillColor;
10909
- }
10910
- e.nextRender();
10911
- });
10912
- const { x, y } = position;
10913
- //不显示痕迹
10914
- if (!viewOptions.showTrackChanges) {
10915
- return;
10916
- }
10917
- const color = this.element.type === 'ins-run' ? 'green' : 'red';
10918
- for (let i = 0; i < this.length; i++) {
10919
- const childRender = this.getChild(i);
10920
- const { rect } = childRender;
10921
- if (childRender.element && childRender.element.type === 'del-run') {
10922
- continue;
10923
- }
10924
- let lineY = y + rect.y + rect.height;
10925
- lineY = this.element.type === 'ins-run' ? lineY : lineY - rect.height / 2;
10926
- render.contentContext.drawHoriLine(x + rect.x, lineY, rect.width, color, 1);
10927
- }
10928
- }
10929
10684
  exportHTML(event) {
10930
10685
  const { options } = event;
10931
10686
  const t = super.exportHTML(event);
@@ -12488,9 +12243,9 @@ class ElementUtil {
12488
12243
  return this.getTextRenderOffset(render, x);
12489
12244
  }
12490
12245
  else {
12491
- if (render.element && render.element.type === 'psym') {
12492
- return 0;
12493
- }
12246
+ // if (render.element && render.element.type === 'psym') {
12247
+ // return 0;
12248
+ // }
12494
12249
  return (render.rect.width / 2) >= x ? 0 : 1;
12495
12250
  }
12496
12251
  }
@@ -13220,12 +12975,12 @@ class ElementPaint {
13220
12975
  }
13221
12976
  }
13222
12977
  });
13223
- docContainer.render({
13224
- render: this.renderCtx,
13225
- position: { x: docContainer.rect.x, y: docContainer.rect.y },
13226
- nextRender: nextRenderFn,
13227
- docCtx: this.docCtx
13228
- });
12978
+ // docContainer.render({
12979
+ // render: this.renderCtx,
12980
+ // position: { x: docContainer.rect.x, y: docContainer.rect.y },
12981
+ // nextRender: nextRenderFn,
12982
+ // docCtx: this.docCtx
12983
+ // })
13229
12984
  nextRenderFn();
13230
12985
  const { scale, viewSettings: { width, height } } = this.viewOptions;
13231
12986
  while (this.renderCtx.onRenderCompleted.subs.length > 0) {
@@ -13254,25 +13009,25 @@ class ElementPaint {
13254
13009
  this.drawRenderObject(child, currPosition, inViewPort);
13255
13010
  }
13256
13011
  });
13257
- const renderData = {
13012
+ ({
13258
13013
  position: currPosition,
13259
13014
  nextRender: nextRenderFn,
13260
13015
  render: this.renderCtx,
13261
13016
  docCtx: this.docCtx
13262
- };
13263
- renderObject.render(renderData);
13017
+ });
13018
+ //renderObject.render(renderData);
13264
13019
  nextRenderFn();
13265
13020
  }
13266
13021
  }
13267
13022
  else if (renderObject instanceof LeafRenderObject) {
13268
13023
  if (inViewPort) {
13269
- const renderData = {
13024
+ ({
13270
13025
  position: currPosition,
13271
13026
  nextRender: () => { },
13272
13027
  render: this.renderCtx,
13273
13028
  docCtx: this.docCtx
13274
- };
13275
- renderObject.render(renderData);
13029
+ });
13030
+ //renderObject.render(renderData);
13276
13031
  }
13277
13032
  }
13278
13033
  //处理选中拖蓝
@@ -13297,42 +13052,42 @@ class ElementPaint {
13297
13052
  this.renderCtx.contentContext.fillRect(currPosition.x, currPosition.y, renderObject.rect.width, renderObject.rect.height, this.viewOptions.selectionOverlaysColor);
13298
13053
  }
13299
13054
  }
13300
- if (inViewPort && this.viewOptions.showReviewWindow && this.docCtx.document.commentsContainerElement.cacheRender.selectedSet.has(element)) {
13301
- if (renderObject instanceof LeafRenderObject || renderObject instanceof DataElementRenderObject) {
13302
- const measureCommContainer = this.docCtx.document.commentsContainerElement.cacheRender;
13303
- const range = measureCommContainer.selectedSet.get(element);
13304
- if (range.isFullSelected) {
13305
- let commentRangePaintColor = '#ffd591';
13306
- for (let i = 0; i < measureCommContainer.commentRangeStatus.length; i++) {
13307
- const commentRangeStatus = measureCommContainer.commentRangeStatus[i];
13308
- if (commentRangeStatus.commContent.focus) {
13309
- if (RangeUtil.checkElementFullInRange(commentRangeStatus.range, element)) {
13310
- commentRangePaintColor = '#fa8c16';
13311
- }
13312
- }
13313
- }
13314
- const overlayRect = { x: currPosition.x, y: currPosition.y, width: rw, height: rh };
13315
- const paraLinePos = ElementUtil.getParaLinePos(renderObject, {
13316
- x: currPosition.x,
13317
- y: currPosition.y
13318
- });
13319
- this.renderCtx.overlaysContext.fillRect(overlayRect.x, paraLinePos.y, overlayRect.width, paraLinePos.height, commentRangePaintColor);
13320
- }
13321
- }
13322
- }
13055
+ // if (inViewPort && this.viewOptions.showReviewWindow && (<CommsContainerRenderObject>this.docCtx.document.commentsContainerElement.cacheRender).selectedSet.has(element)) {
13056
+ // if (renderObject instanceof LeafRenderObject || renderObject instanceof DataElementRenderObject) {
13057
+ // const measureCommContainer=<CommsContainerRenderObject>this.docCtx.document.commentsContainerElement.cacheRender;
13058
+ // const range = measureCommContainer.selectedSet.get(element) as SelectionContentRange;
13059
+ // if (range.isFullSelected) {
13060
+ // let commentRangePaintColor = '#ffd591';
13061
+ // for (let i = 0; i < measureCommContainer.commentRangeStatus.length; i++) {
13062
+ // const commentRangeStatus = measureCommContainer.commentRangeStatus[i];
13063
+ // if (commentRangeStatus.commContent.focus) {
13064
+ // if (RangeUtil.checkElementFullInRange(commentRangeStatus.range, element)) {
13065
+ // commentRangePaintColor = '#fa8c16';
13066
+ // }
13067
+ // }
13068
+ // }
13069
+ // const overlayRect = { x: currPosition.x, y: currPosition.y, width: rw, height: rh };
13070
+ // const paraLinePos = ElementUtil.getParaLinePos(renderObject, {
13071
+ // x: currPosition.x,
13072
+ // y: currPosition.y
13073
+ // });
13074
+ // this.renderCtx.overlaysContext.fillRect(overlayRect.x, paraLinePos.y, overlayRect.width, paraLinePos.height, commentRangePaintColor);
13075
+ // }
13076
+ // }
13077
+ // }
13323
13078
  }
13324
13079
  /**
13325
13080
  * 触发页面绘制结束事件
13326
13081
  */
13327
13082
  invokedPagePaintCompleted(renderObject, parent) {
13328
- const { x: rx, y: ry, width: rw, height: rh } = renderObject.rect;
13329
- const currPosition = { x: rx + parent.x, y: ry + parent.y };
13330
- renderObject.pagePaintCompleted({ render: this.renderCtx, position: currPosition, docCtx: this.docCtx });
13331
- if (renderObject instanceof BranchRenderObject) {
13332
- for (let i = 0; i < renderObject.length; i++) {
13333
- this.invokedPagePaintCompleted(renderObject.getChild(i), currPosition);
13334
- }
13335
- }
13083
+ // const { x: rx, y: ry, width: rw, height: rh } = renderObject.rect;
13084
+ // const currPosition = { x: rx + parent.x, y: ry + parent.y };
13085
+ // renderObject.pagePaintCompleted({ render: this.renderCtx, position: currPosition, docCtx: this.docCtx })
13086
+ // if (renderObject instanceof BranchRenderObject) {
13087
+ // for (let i = 0; i < renderObject.length; i++) {
13088
+ // this.invokedPagePaintCompleted(renderObject.getChild(i), currPosition);
13089
+ // }
13090
+ // }
13336
13091
  }
13337
13092
  static drawPage(renderCtx, docCtx, renderObject, parent) {
13338
13093
  const { x: rx, y: ry } = renderObject.rect;
@@ -13344,266 +13099,60 @@ class ElementPaint {
13344
13099
  this.drawPage(renderCtx, docCtx, child, currPosition);
13345
13100
  }
13346
13101
  });
13347
- const renderData = {
13348
- position: currPosition,
13349
- nextRender: nextRenderFn,
13350
- render: renderCtx,
13351
- docCtx
13352
- };
13353
- renderObject.render(renderData);
13102
+ //renderObject.render(renderData);
13354
13103
  nextRenderFn();
13355
13104
  }
13356
- else if (renderObject instanceof LeafRenderObject) {
13357
- const renderData = {
13358
- position: currPosition,
13359
- nextRender: () => { },
13360
- render: renderCtx,
13361
- docCtx: docCtx
13362
- };
13363
- renderObject.render(renderData);
13364
- }
13365
13105
  }
13366
13106
  }
13367
13107
 
13368
- /**
13369
- * 用于处理选区拖蓝
13370
- */
13371
- class SelectionOverlays {
13372
- selectionState;
13373
- selectionRange;
13374
- selectedSets = new Map();
13375
- constructor(selectionState) {
13376
- this.selectionState = selectionState;
13377
- }
13378
- getSelectionTreeData() {
13379
- let { ancestorCommonControl, startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
13380
- this.selectedSets.clear();
13381
- if (this.selectionRange) {
13382
- this.selectionRange.selectedChildren.length = 0;
13383
- }
13384
- this.selectionRange = null;
13385
- if (!startControl || !endControl || !ancestorCommonControl) {
13386
- //this.selectionRange?.selectedChildren.length=0;
13387
- this.selectionState.selectedRange = null;
13388
- return;
13389
- }
13390
- if (collapsed) {
13391
- const commonRange = RangeUtil.getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
13392
- this.selectionState.selectedRange = commonRange;
13393
- this.selectedSets.clear();
13394
- return;
13395
- }
13396
- const fixStartElement = this.fixStartSelectionElement(startControl, startOffset, ancestorCommonControl);
13397
- startControl = fixStartElement.element;
13398
- startOffset = fixStartElement.offset;
13399
- const fixEndElement = this.fixEndSelectionElement(endControl, endOffset, ancestorCommonControl);
13400
- endControl = fixEndElement.element;
13401
- endOffset = fixEndElement.offset;
13402
- const commonRange = RangeUtil.getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
13403
- //console.log(commonRange);
13404
- this.selectionRange = commonRange;
13405
- this.convertSelectRangeToSet();
13406
- this.selectionState.selectedRange = commonRange;
13407
- }
13408
- convertSelectRangeToSet() {
13409
- this.selectedSets.clear();
13410
- if (this.selectionRange) {
13411
- SelectionOverlays.addToSets(this.selectionRange, this.selectedSets);
13412
- }
13108
+ class DocumentEvalFunc {
13109
+ docCtx;
13110
+ constructor(docCtx) {
13111
+ this.docCtx = docCtx;
13413
13112
  }
13414
- static addToSets(range, set) {
13415
- set.set(range.target, range);
13416
- for (let i = 0; i < range.selectedChildren.length; i++) {
13417
- //单元格全部选中效果,单元格整个拖蓝即可
13418
- if (range.isFullSelected && range.target.type === 'tbc') {
13419
- continue;
13113
+ scriptsFunc;
13114
+ /**
13115
+ * 实例化动态脚本
13116
+ */
13117
+ initScripts(scripts) {
13118
+ this.destroyScripts();
13119
+ if (scripts) {
13120
+ try {
13121
+ const func = new Function("docCtx", scripts);
13122
+ this.scriptsFunc = func(this.docCtx);
13123
+ }
13124
+ catch (e) {
13125
+ console.error("自定义标本解析错误", e);
13420
13126
  }
13421
- this.addToSets(range.selectedChildren[i], set);
13422
13127
  }
13128
+ // const func = (docCtx: DocumentContext) => {
13129
+ // const sexELe = docCtx.getControlById('NqoYI')
13130
+ // const dyEle = docCtx.getControlById('gTuBI');
13131
+ // return () => {
13132
+ // if (sexELe && dyEle) {
13133
+ // const sexValue = sexELe.getValue();
13134
+ // const dyValue = sexValue === '1' ? '男的吗' : sexValue === '2' ? '女的吗' : '难道是人妖吗';
13135
+ // dyEle.setValue(dyValue);
13136
+ // }
13137
+ // };
13138
+ // };
13423
13139
  }
13424
13140
  /**
13425
- * 添加到批注集合
13426
- * @param range
13427
- * @param set
13141
+ * 销毁动态脚本实例
13428
13142
  */
13429
- static addToCommentSets(range, set) {
13430
- set.set(range.target, range);
13431
- for (let i = 0; i < range.selectedChildren.length; i++) {
13432
- this.addToCommentSets(range.selectedChildren[i], set);
13143
+ destroyScripts() {
13144
+ if (this.scriptsFunc) {
13145
+ this.scriptsFunc = null;
13433
13146
  }
13434
13147
  }
13435
13148
  /**
13436
- * 修正开始选区内容
13437
- * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
13438
- */
13439
- fixStartSelectionElement(element, offset, ancestorCommonControl) {
13440
- if (!(ancestorCommonControl instanceof TableElement)) {
13441
- const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
13442
- if (lookupParentCell) {
13443
- if (!lookupParentCell.parent || !lookupParentCell.parent.parent) ;
13444
- const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
13445
- const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
13446
- if (ancestorCommonControlIndex < lookupParentTbIndex) {
13447
- const rowFirstLeafElement = ElementUtil.getFirstLeafElement(lookupParentCell.parent);
13448
- if (!rowFirstLeafElement) {
13449
- throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
13450
- }
13451
- return {
13452
- element: rowFirstLeafElement,
13453
- offset: 0
13454
- };
13455
- }
13456
- }
13457
- }
13458
- return { element, offset };
13459
- }
13460
- /**
13461
- * 修正开始选区内容
13462
- * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
13463
- */
13464
- fixEndSelectionElement(element, offset, ancestorCommonControl) {
13465
- if (!(ancestorCommonControl instanceof TableElement)) {
13466
- const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
13467
- if (lookupParentCell) {
13468
- const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
13469
- const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
13470
- if (ancestorCommonControlIndex < lookupParentTbIndex) {
13471
- const rowLastLeafElement = ElementUtil.getLastLeafElement(lookupParentCell.parent);
13472
- if (!rowLastLeafElement) {
13473
- ElementUtil.getLastLeafElement(lookupParentCell.parent);
13474
- throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
13475
- }
13476
- return {
13477
- element: rowLastLeafElement,
13478
- offset: 1
13479
- };
13480
- }
13481
- }
13482
- }
13483
- return { element, offset };
13484
- }
13485
- }
13486
-
13487
- class DocumentEvalFunc {
13488
- docCtx;
13489
- constructor(docCtx) {
13490
- this.docCtx = docCtx;
13491
- }
13492
- scriptsFunc;
13493
- /**
13494
- * 实例化动态脚本
13495
- */
13496
- initScripts(scripts) {
13497
- this.destroyScripts();
13498
- if (scripts) {
13499
- try {
13500
- const func = new Function("docCtx", scripts);
13501
- this.scriptsFunc = func(this.docCtx);
13502
- }
13503
- catch (e) {
13504
- console.error("自定义标本解析错误", e);
13505
- }
13506
- }
13507
- // const func = (docCtx: DocumentContext) => {
13508
- // const sexELe = docCtx.getControlById('NqoYI')
13509
- // const dyEle = docCtx.getControlById('gTuBI');
13510
- // return () => {
13511
- // if (sexELe && dyEle) {
13512
- // const sexValue = sexELe.getValue();
13513
- // const dyValue = sexValue === '1' ? '男的吗' : sexValue === '2' ? '女的吗' : '难道是人妖吗';
13514
- // dyEle.setValue(dyValue);
13515
- // }
13516
- // };
13517
- // };
13518
- }
13519
- /**
13520
- * 销毁动态脚本实例
13521
- */
13522
- destroyScripts() {
13523
- if (this.scriptsFunc) {
13524
- this.scriptsFunc = null;
13525
- }
13526
- }
13527
- /**
13528
- * 触发动态脚本
13149
+ * 触发动态脚本
13529
13150
  */
13530
13151
  invokedScripts() {
13531
13152
  this.scriptsFunc?.();
13532
13153
  }
13533
13154
  }
13534
13155
 
13535
- class DocumentImagesBaseLoader {
13536
- images = [];
13537
- clear() {
13538
- this.images.length = 0;
13539
- }
13540
- loadImage(src, onCallback) {
13541
- if (!src) {
13542
- return;
13543
- }
13544
- //已经存在的资源不需要重新加载
13545
- let matchItem = this.images.find(item => item.src === src);
13546
- if (matchItem) {
13547
- if (matchItem.loadStatus === 'no') {
13548
- matchItem.cbs.push(onCallback);
13549
- }
13550
- else {
13551
- onCallback(matchItem.loadStatus);
13552
- }
13553
- return;
13554
- }
13555
- const task = this.createRequestImage(src);
13556
- const imgItem = {
13557
- ele: undefined,
13558
- src,
13559
- cbs: [onCallback],
13560
- loadStatus: 'no',
13561
- task
13562
- };
13563
- this.images.push(imgItem);
13564
- // if (this.viewOptions.resourceMode === 'immediate') {
13565
- // ele.onload = (e) => { this.invokeImgLoad(src, 'completed'); };
13566
- // ele.onerror = (e) => { this.invokeImgLoad(src, 'error'); };
13567
- // }
13568
- }
13569
- invokeImgLoad(src, status, data) {
13570
- const img = this.images.find(item => item.src === src);
13571
- if (img) {
13572
- img.loadStatus = status;
13573
- img.cbs.forEach(cb => cb(status));
13574
- img.ele = data;
13575
- }
13576
- }
13577
- getLoadTasks() {
13578
- return this.images.map(item => item.task);
13579
- }
13580
- getImage(src) {
13581
- const img = this.images.find(item => item.src === src);
13582
- return img?.ele;
13583
- }
13584
- /**
13585
- * 判断图片是否都已经加载完毕
13586
- * 用于打印时判断,如果当前图片没有加载完毕就打印,图片是打印不出来
13587
- * @returns
13588
- */
13589
- imagesLoadCompleted() {
13590
- if (this.images.length === 0) {
13591
- return true;
13592
- }
13593
- return this.images.every(item => ['completed', 'error'].includes(item.loadStatus));
13594
- }
13595
- }
13596
- class DocumentImagesLoader extends DocumentImagesBaseLoader {
13597
- createRequestImage(url) {
13598
- const ele = new Image();
13599
- ele.src = url;
13600
- return new Promise((r, i) => {
13601
- ele.onload = (e) => { this.invokeImgLoad(url, 'completed', ele); r(); };
13602
- ele.onerror = (e) => { this.invokeImgLoad(url, 'error', ele); r(); };
13603
- });
13604
- }
13605
- }
13606
-
13607
13156
  /**
13608
13157
  * 当前打开的文档的上下文信息,当前文档所有的属性设置都暴露在上下文中
13609
13158
  */
@@ -13616,7 +13165,7 @@ class EditorContext {
13616
13165
  //文档刷新的订阅事件
13617
13166
  //refSub!: Subscription;
13618
13167
  syncRefresh;
13619
- imageLoader;
13168
+ //imageLoader: IImageLoader;
13620
13169
  dynamicFunc;
13621
13170
  docChange;
13622
13171
  clearPrevDocCb;
@@ -13626,7 +13175,7 @@ class EditorContext {
13626
13175
  this.selectionState = selectionState;
13627
13176
  this.viewOptions = viewOptions;
13628
13177
  this.dynamicFunc = new DocumentEvalFunc(this);
13629
- this.imageLoader = new DocumentImagesLoader();
13178
+ //this.imageLoader = new DocumentImagesLoader();
13630
13179
  this.selectionState.onChangedEvent.subscribe(() => {
13631
13180
  this.syncRefresh?.();
13632
13181
  });
@@ -13667,7 +13216,7 @@ class EditorContext {
13667
13216
  }
13668
13217
  clear() {
13669
13218
  this.selectionState.clear();
13670
- this.imageLoader.clear();
13219
+ //this.imageLoader.clear();
13671
13220
  this.dynamicFunc.destroyScripts();
13672
13221
  this.isDirty = false;
13673
13222
  }
@@ -13709,7 +13258,7 @@ class EditorContext {
13709
13258
  this.document.destroy();
13710
13259
  this.clearPrevDocCb?.();
13711
13260
  //this.ele_types_handlers.length = 0;
13712
- this.imageLoader.clear();
13261
+ //this.imageLoader.clear();
13713
13262
  this._document = null;
13714
13263
  }
13715
13264
  /**
@@ -13744,6 +13293,17 @@ class EditorContext {
13744
13293
  return this._document.modifyFlag === exports.ModifyFlag.None ? 'appearance' : 'content';
13745
13294
  }
13746
13295
  }
13296
+ // export interface IImageLoader {
13297
+ // clear(): void;
13298
+ //
13299
+ // loadImage(src: string, onCallback: (status: ImgLoadStatus) => void): void;
13300
+ //
13301
+ // getImage(src: string): HTMLImageElement | undefined;
13302
+ //
13303
+ // imagesLoadCompleted(): boolean;
13304
+ //
13305
+ // getLoadTasks(): Array<Promise<void>>;
13306
+ // }
13747
13307
  /**
13748
13308
  * 文档上下文
13749
13309
  */
@@ -14637,13 +14197,139 @@ class ParagraphMeasure {
14637
14197
  }
14638
14198
  }
14639
14199
 
14200
+ /**
14201
+ * 用于处理选区拖蓝
14202
+ */
14203
+ class SelectionOverlays {
14204
+ selectionState;
14205
+ selectionRange;
14206
+ //选区对象集合
14207
+ selectionEleSets = new Map();
14208
+ //批注对象集合
14209
+ commRangeSets = new Map();
14210
+ constructor(selectionState) {
14211
+ this.selectionState = selectionState;
14212
+ }
14213
+ getSelectionTreeData() {
14214
+ let { ancestorCommonControl, startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
14215
+ this.selectionEleSets.clear();
14216
+ if (this.selectionRange) {
14217
+ this.selectionRange.selectedChildren.length = 0;
14218
+ }
14219
+ this.selectionRange = null;
14220
+ if (!startControl || !endControl || !ancestorCommonControl) {
14221
+ //this.selectionRange?.selectedChildren.length=0;
14222
+ this.selectionState.selectedRange = null;
14223
+ return;
14224
+ }
14225
+ if (collapsed) {
14226
+ const commonRange = RangeUtil.getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
14227
+ this.selectionState.selectedRange = commonRange;
14228
+ this.selectionEleSets.clear();
14229
+ return;
14230
+ }
14231
+ const fixStartElement = this.fixStartSelectionElement(startControl, startOffset, ancestorCommonControl);
14232
+ startControl = fixStartElement.element;
14233
+ startOffset = fixStartElement.offset;
14234
+ const fixEndElement = this.fixEndSelectionElement(endControl, endOffset, ancestorCommonControl);
14235
+ endControl = fixEndElement.element;
14236
+ endOffset = fixEndElement.offset;
14237
+ const commonRange = RangeUtil.getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
14238
+ //console.log(commonRange);
14239
+ this.selectionRange = commonRange;
14240
+ this.convertSelectRangeToSet();
14241
+ this.selectionState.selectedRange = commonRange;
14242
+ }
14243
+ convertSelectRangeToSet() {
14244
+ this.selectionEleSets.clear();
14245
+ if (this.selectionRange) {
14246
+ SelectionOverlays.addToSets(this.selectionRange, this.selectionEleSets);
14247
+ }
14248
+ }
14249
+ static addToSets(range, set) {
14250
+ set.set(range.target, range);
14251
+ for (let i = 0; i < range.selectedChildren.length; i++) {
14252
+ //单元格全部选中效果,单元格整个拖蓝即可
14253
+ if (range.isFullSelected && range.target.type === 'tbc') {
14254
+ continue;
14255
+ }
14256
+ this.addToSets(range.selectedChildren[i], set);
14257
+ }
14258
+ }
14259
+ /**
14260
+ * 添加到批注集合
14261
+ * @param range
14262
+ * @param set
14263
+ * @param rangeColor 用以显示批注区间的颜色
14264
+ */
14265
+ static addToCommentSets(range, set, rangeColor) {
14266
+ range['rangeColor'] = rangeColor;
14267
+ set.set(range.target, range);
14268
+ for (let i = 0; i < range.selectedChildren.length; i++) {
14269
+ this.addToCommentSets(range.selectedChildren[i], set, rangeColor);
14270
+ }
14271
+ }
14272
+ /**
14273
+ * 修正开始选区内容
14274
+ * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
14275
+ */
14276
+ fixStartSelectionElement(element, offset, ancestorCommonControl) {
14277
+ if (!(ancestorCommonControl instanceof TableElement)) {
14278
+ const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
14279
+ if (lookupParentCell) {
14280
+ if (!lookupParentCell.parent || !lookupParentCell.parent.parent) ;
14281
+ const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
14282
+ const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
14283
+ if (ancestorCommonControlIndex < lookupParentTbIndex) {
14284
+ const rowFirstLeafElement = ElementUtil.getFirstLeafElement(lookupParentCell.parent);
14285
+ if (!rowFirstLeafElement) {
14286
+ throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
14287
+ }
14288
+ return {
14289
+ element: rowFirstLeafElement,
14290
+ offset: 0
14291
+ };
14292
+ }
14293
+ }
14294
+ }
14295
+ return { element, offset };
14296
+ }
14297
+ /**
14298
+ * 修正开始选区内容
14299
+ * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
14300
+ */
14301
+ fixEndSelectionElement(element, offset, ancestorCommonControl) {
14302
+ if (!(ancestorCommonControl instanceof TableElement)) {
14303
+ const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
14304
+ if (lookupParentCell) {
14305
+ const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
14306
+ const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
14307
+ if (ancestorCommonControlIndex < lookupParentTbIndex) {
14308
+ const rowLastLeafElement = ElementUtil.getLastLeafElement(lookupParentCell.parent);
14309
+ if (!rowLastLeafElement) {
14310
+ ElementUtil.getLastLeafElement(lookupParentCell.parent);
14311
+ throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
14312
+ }
14313
+ return {
14314
+ element: rowLastLeafElement,
14315
+ offset: 1
14316
+ };
14317
+ }
14318
+ }
14319
+ }
14320
+ return { element, offset };
14321
+ }
14322
+ }
14323
+
14640
14324
  class DocumentArrange {
14641
14325
  docCtx;
14642
14326
  renderCtx;
14327
+ seo;
14643
14328
  options;
14644
- constructor(docCtx, renderCtx) {
14329
+ constructor(docCtx, renderCtx, seo) {
14645
14330
  this.docCtx = docCtx;
14646
14331
  this.renderCtx = renderCtx;
14332
+ this.seo = seo;
14647
14333
  this.options = this.docCtx.viewOptions;
14648
14334
  }
14649
14335
  /**
@@ -14665,24 +14351,25 @@ class DocumentArrange {
14665
14351
  parser: new DynamicContextParser(doc, this.docCtx.selectionState),
14666
14352
  createParaFn: () => this.createDefaultPara()
14667
14353
  };
14668
- doc.commentsContainerElement.clearMarkItems();
14354
+ doc.clearMarkItems();
14669
14355
  this.clearPaintCache(doc, data);
14670
- this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
14356
+ //this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
14671
14357
  const docRenders = this.arrangeDoc();
14672
14358
  this.setMeasureCompletedModifyFlag(doc);
14673
14359
  this.cacheDocRenders(docRenders);
14360
+ this.generateCommRange();
14674
14361
  return docRenders;
14675
14362
  });
14676
14363
  }
14677
- commentsRender;
14364
+ //commentsRender!: CommsContainerRenderObject;
14678
14365
  arrangeDoc() {
14679
14366
  const doc = this.docCtx.document;
14680
14367
  const docRender = doc.createRenderObject();
14681
14368
  const innerRect = docRender.getInnerRect();
14682
14369
  const headerRender = this.measureControl(doc.headerElement, innerRect.width);
14683
14370
  const footerRender = this.measureControl(doc.footerElement, innerRect.width);
14684
- const commentsRender = this.measureControl(doc.commentsContainerElement, this.options.reviewWindowWidth);
14685
- this.commentsRender = commentsRender;
14371
+ //const commentsRender = this.measureControl(doc.commentsContainerElement, this.options.reviewWindowWidth) as CommsContainerRenderObject;
14372
+ //this.commentsRender = commentsRender;
14686
14373
  const { headerLine, footerLine } = docRender;
14687
14374
  let bodyMarginTop = headerLine + headerRender.rect.height + 6;
14688
14375
  let bodyMarginBottom = footerLine + footerRender.rect.height;
@@ -14777,15 +14464,15 @@ class DocumentArrange {
14777
14464
  cloneFooterRender.rect.x = limitRect.x;
14778
14465
  cloneFooterRender.rect.y = documentRender.rect.height - bodyMarginBottom;
14779
14466
  currColumn === 0 && documentRender.addChild(cloneFooterRender);
14780
- //审阅模式,添加审阅窗口
14781
- if (this.options.showReviewWindow && commentsRender) {
14782
- const commentsContainer = this.createRenderObject(commentsRender.element);
14783
- commentsContainer.padding.top = bodyMarginTop;
14784
- commentsContainer.rect.height = documentRender.rect.height;
14785
- documentRender.addChild(commentsContainer);
14786
- commentsContainer.rect.x = documentRender.rect.x + documentRender.rect.width;
14787
- documentRender.rect.width += this.options.reviewWindowWidth;
14788
- }
14467
+ // //审阅模式,添加审阅窗口
14468
+ // if (this.options.showReviewWindow && commentsRender) {
14469
+ // const commentsContainer = this.createRenderObject(commentsRender.element) as CommsContainerRenderObject;
14470
+ // commentsContainer.padding.top = bodyMarginTop;
14471
+ // commentsContainer.rect.height = documentRender.rect.height;
14472
+ // documentRender.addChild(commentsContainer);
14473
+ // commentsContainer.rect.x = documentRender.rect.x + documentRender.rect.width;
14474
+ // documentRender.rect.width += this.options.reviewWindowWidth;
14475
+ // }
14789
14476
  currColumn++;
14790
14477
  if (currColumn === docColumns) {
14791
14478
  currColumn = 0;
@@ -14813,8 +14500,7 @@ class DocumentArrange {
14813
14500
  }
14814
14501
  if (element instanceof BlockContentElement) {
14815
14502
  const pRange = new ParagraphMeasure(this.options, this.renderCtx);
14816
- const innerLineRects = pRange.measureParagraph(element, maxWidth);
14817
- return innerLineRects;
14503
+ return pRange.measureParagraph(element, maxWidth);
14818
14504
  }
14819
14505
  else if (element instanceof BlockContainerElement) {
14820
14506
  const renders = [];
@@ -14952,7 +14638,6 @@ class DocumentArrange {
14952
14638
  * 切割渲染元素
14953
14639
  * @param tbRender 被切割的对象
14954
14640
  * @param limitHeight
14955
- * @param addFunc
14956
14641
  * @returns
14957
14642
  */
14958
14643
  cutTable(tbRender, limitHeight) {
@@ -14980,8 +14665,13 @@ class DocumentArrange {
14980
14665
  let currRow = rows[j];
14981
14666
  const cutRows = [];
14982
14667
  while (currRow) {
14668
+ const minHeight = currRow.element.props.minHeight;
14983
14669
  const rowContentHeight = this.getBlockLineHeight(currRow);
14984
14670
  if (rowContentHeight + sumHeight > limitHeight) {
14671
+ //行存在最小高度,且当前行内容的高度小于最小高度,且当前行跨页的情况下,不截断该行
14672
+ if (minHeight > 0 && minHeight > rowContentHeight) {
14673
+ break;
14674
+ }
14985
14675
  //限制的外框尺寸
14986
14676
  const availHeight = limitHeight - sumHeight;
14987
14677
  const limitRenderInnerHeight = ElementUtil.innerRectMaxHeight(tbRender, availHeight);
@@ -15222,7 +14912,7 @@ class DocumentArrange {
15222
14912
  }
15223
14913
  identifyComment(ele) {
15224
14914
  if (ele instanceof CommentElement) {
15225
- this.docCtx.document.commentsContainerElement.identifyCommMark(ele);
14915
+ this.docCtx.document.identifyCommMark(ele);
15226
14916
  }
15227
14917
  }
15228
14918
  cacheDoc;
@@ -15233,6 +14923,22 @@ class DocumentArrange {
15233
14923
  });
15234
14924
  this.cacheDoc = null;
15235
14925
  }
14926
+ /**
14927
+ * 生成批注区间信息
14928
+ * @param renderTree
14929
+ */
14930
+ generateCommRange() {
14931
+ this.seo.commRangeSets.clear();
14932
+ const commMarks = this.docCtx.document.markPairs;
14933
+ for (let i = 0; i < commMarks.length; i++) {
14934
+ const commMark = commMarks[i];
14935
+ if (commMark.start && commMark.end) {
14936
+ const ancestor = DocumentSelection.getAncestorCommonControl(commMark.start, commMark.end);
14937
+ const range = RangeUtil.getSectionRange(commMark.start, 0, commMark.end, 1, ancestor);
14938
+ SelectionOverlays.addToCommentSets(range, this.seo.commRangeSets, commMark.start.color);
14939
+ }
14940
+ }
14941
+ }
15236
14942
  cacheRenders(renderTree) {
15237
14943
  if (renderTree.element) {
15238
14944
  renderTree.element.paintRenders.push(renderTree);
@@ -15705,644 +15411,157 @@ class ElementMeasure {
15705
15411
  if (this.containPostPunctuation(render.textMeasures[i + 1]?.char)) {
15706
15412
  i--;
15707
15413
  }
15708
- else {
15709
- i++;
15710
- }
15711
- }
15712
- else {
15713
- if (i > 1 && this.containPostPunctuation(render.textMeasures[i]?.char)) {
15714
- i--;
15715
- }
15716
- }
15717
- return i;
15718
- }
15719
- /**
15720
- * 是否包含后置标点
15721
- * @param str
15722
- * @returns
15723
- */
15724
- containPostPunctuation(str) {
15725
- return '!),.:;?]}¨·ˇˉ―‖’”…∶、。〃々〉》」』】〕〗!"'),.:;?]`|}~¢'.indexOf(str) > -1;
15726
- }
15727
- //是否包含前置标点
15728
- containLeadingPunctuation(str) {
15729
- return '‘“〈《「『【〔〖([{£'.indexOf(str) > -1;
15730
- }
15731
- /**
15732
- * 文本开头是否包含后置标点
15733
- * @param render
15734
- * @returns
15735
- */
15736
- containerStartSymbolInTextStart(render) {
15737
- //return false;
15738
- if (render instanceof TextGroupRenderObject) {
15739
- if (render.textMeasures.length > 0) {
15740
- return this.containPostPunctuation(render.textMeasures[0].char);
15741
- }
15742
- }
15743
- return false;
15744
- }
15745
- cutFillNullRender(render, limitWidth) {
15746
- if (limitWidth === 0) {
15747
- return { firstItem: null, lastItem: null };
15748
- }
15749
- if (render.rect.width > limitWidth) {
15750
- const cutRender = new FillNullSpaceRenderObject();
15751
- cutRender.rect.width = limitWidth;
15752
- cutRender.rect.height = render.rect.height;
15753
- render.rect.width = render.rect.width - limitWidth;
15754
- return { firstItem: cutRender, lastItem: render };
15755
- }
15756
- else {
15757
- return { firstItem: render, lastItem: null };
15758
- }
15759
- }
15760
- /**
15761
- * 行内编组元素超出行内可用空间,需要根据剩余空间长度进行截断
15762
- */
15763
- cutInlineGroupRenderItem(render, limitWidth, emptyLine, inCloseBody) {
15764
- const cutRender = render.element.createRenderObject({ options: this.options, renderCtx: this.renderCtx });
15765
- let x = 0;
15766
- let br = false;
15767
- const items = [...render.getItems()];
15768
- for (let i = 0; i < items.length; i++) {
15769
- const child = items[i];
15770
- if (child instanceof LeafRenderObject) {
15771
- if (x + child.rect.width > limitWidth) {
15772
- const { firstItem, lastItem, br: childBr } = this.cutRenderItem(child, items[i + 1], limitWidth - x, emptyLine && cutRender.length === 0, inCloseBody);
15773
- if (firstItem) {
15774
- cutRender.addChild(firstItem);
15775
- }
15776
- br = childBr || br;
15777
- break;
15778
- }
15779
- else {
15780
- render.removeChild(child);
15781
- cutRender.addChild(child);
15782
- }
15783
- //软换行符
15784
- if (child.element && child.element.type === 'br') {
15785
- br = true;
15786
- break;
15787
- }
15788
- }
15789
- else if (child instanceof InlineGroupRenderObject) {
15790
- if (x + child.rect.width > limitWidth) {
15791
- const { firstItem, br: childBr } = this.cutInlineGroupRenderItem(child, limitWidth - x, emptyLine && cutRender.length === 0, inCloseBody);
15792
- if (firstItem) {
15793
- cutRender.addChild(firstItem);
15794
- }
15795
- br = childBr || br;
15796
- break;
15797
- }
15798
- else {
15799
- render.removeChild(child);
15800
- cutRender.addChild(child);
15801
- }
15802
- }
15803
- x += child.rect.width;
15804
- }
15805
- if (!cutRender.length) {
15806
- return { firstItem: null, lastItem: null };
15807
- }
15808
- ElementUtil.remeasureInlineGroupRender(cutRender);
15809
- ElementUtil.remeasureInlineGroupRender(render);
15810
- return { firstItem: cutRender, lastItem: render.length ? render : null, br };
15811
- }
15812
- /**
15813
- * 修改测量完毕后的元素状态
15814
- * @param ele
15815
- */
15816
- setMeasureCompletedModifyFlag(ele) {
15817
- if (ele instanceof BranchElement) {
15818
- for (let i = 0; i < ele.length; i++) {
15819
- this.setMeasureCompletedModifyFlag(ele.getChild(i));
15820
- }
15821
- }
15822
- ele.modifyFlag = exports.ModifyFlag.None;
15823
- }
15824
- clearPaintCache(ele, data) {
15825
- ele.beginMeasure(data);
15826
- if (ele instanceof BranchElement) {
15827
- for (let i = 0; i < ele.length; i++) {
15828
- this.clearPaintCache(ele.getChild(i), data);
15829
- }
15830
- }
15831
- }
15832
- endMeasures(ele) {
15833
- if (ele instanceof BranchElement) {
15834
- for (let i = 0; i < ele.length; i++) {
15835
- this.endMeasures(ele.getChild(i));
15836
- }
15837
- }
15838
- }
15839
- }
15840
-
15841
- class ElementRenderCut {
15842
- options;
15843
- renderContext;
15844
- constructor(options, renderContext) {
15845
- this.options = options;
15846
- this.renderContext = renderContext;
15847
- }
15848
- cutPage(documentRender, documentElement) {
15849
- if (this.options.fullPageView) {
15850
- return this.getFullViewDocRender(documentRender, documentElement);
15851
- }
15852
- const headerRender = documentRender.getChild(0);
15853
- const bodyRender = documentRender.getChild(1).clone();
15854
- const footerRender = documentRender.getChild(2);
15855
- const commentsRender = documentRender.getChild(3);
15856
- const { headerLine, footerLine } = documentRender;
15857
- let bodyMarginTop = headerLine + headerRender.rect.height + 6;
15858
- let bodyMarginBottom = footerLine + footerRender.rect.height;
15859
- const { top: bodyTop, bottom: bodyBottom } = documentRender.padding;
15860
- bodyMarginTop = bodyMarginTop > bodyTop ? bodyMarginTop : bodyTop;
15861
- bodyMarginBottom = bodyMarginBottom > bodyBottom ? bodyMarginBottom : bodyBottom;
15862
- documentRender.padding.top = bodyMarginTop;
15863
- documentRender.padding.bottom = bodyMarginBottom;
15864
- const bodyLimitRect = this.getDocInnerRect(documentRender);
15865
- const bodyArray = [];
15866
- let { emptyBody: pageBodyRender, innerRect: bodyInnerLimitRect } = this.createEmptyBodyRender(bodyRender, bodyLimitRect);
15867
- bodyArray.push(pageBodyRender);
15868
- const createBodyHolder = () => {
15869
- const { emptyBody, innerRect } = this.createEmptyBodyRender(bodyRender, bodyLimitRect);
15870
- pageBodyRender = emptyBody;
15871
- bodyInnerLimitRect = innerRect;
15872
- bodyArray.push(pageBodyRender);
15873
- };
15874
- const appendToBody = (item) => {
15875
- item.rect.y = bodyInnerLimitRect.height + item.margin.top;
15876
- pageBodyRender.addChild(item);
15877
- bodyInnerLimitRect.height += item.rect.height + item.margin.top + item.margin.bottom;
15878
- //上一个元素的bottom-margin
15879
- //bodyInnerLimitRect.prevMargin = item.margin.bottom;
15880
- ElementUtil.updateRenderHeightByInnerRect(pageBodyRender, bodyInnerLimitRect);
15881
- };
15882
- let i = 0;
15883
- let cloneBlockContentRender = bodyRender.getChild(i);
15884
- while (cloneBlockContentRender) {
15885
- if (bodyInnerLimitRect.maxHeight - bodyInnerLimitRect.height - cloneBlockContentRender.rect.height - cloneBlockContentRender.margin.bottom - cloneBlockContentRender.margin.top < 0) {
15886
- //限制的外框尺寸
15887
- const bodyAvailHeight = bodyInnerLimitRect.maxHeight - bodyInnerLimitRect.height - cloneBlockContentRender.margin.bottom - cloneBlockContentRender.margin.top;
15888
- //限制的内框尺寸
15889
- const limitRenderInnterHeight = ElementUtil.innerRectMaxHeight(cloneBlockContentRender, bodyAvailHeight);
15890
- const cutRenderObject = this.cutRenderItem(cloneBlockContentRender, limitRenderInnterHeight);
15891
- //至少有一个块级行元素被切割出来
15892
- if (cutRenderObject) {
15893
- appendToBody(cutRenderObject);
15894
- }
15895
- createBodyHolder();
15896
- }
15897
- else {
15898
- appendToBody(cloneBlockContentRender);
15899
- if (++i < bodyRender.length) {
15900
- cloneBlockContentRender = bodyRender.getChild(i);
15901
- }
15902
- else {
15903
- cloneBlockContentRender = null;
15904
- }
15905
- }
15906
- }
15907
- const docPages = [];
15908
- let pageY = this.options.docSpace;
15909
- for (let i = 0; i < bodyArray.length; i++) {
15910
- const body = bodyArray[i];
15911
- const documentRender = documentElement.createRenderObject();
15912
- docPages.push(documentRender);
15913
- documentRender.rect.y = pageY;
15914
- const limitRect = documentRender.getInnerRect();
15915
- const cloneHeaderRender = headerRender.clone();
15916
- cloneHeaderRender.rect.x = limitRect.x;
15917
- cloneHeaderRender.rect.y = headerLine;
15918
- documentRender.addChild(cloneHeaderRender);
15919
- body.rect.x = limitRect.x;
15920
- body.rect.y = bodyMarginTop;
15921
- body.rect.height = bodyInnerLimitRect.maxHeight;
15922
- documentRender.addChild(body);
15923
- pageY += documentRender.rect.height + this.options.docSpace;
15924
- const cloneFooterRender = footerRender.clone();
15925
- cloneFooterRender.rect.x = limitRect.x;
15926
- cloneFooterRender.rect.y = documentRender.rect.height - bodyMarginBottom;
15927
- documentRender.addChild(cloneFooterRender);
15928
- //审阅模式,添加审阅窗口
15929
- if (this.options.showReviewWindow && commentsRender) {
15930
- const commentsContainer = commentsRender.element.createRenderObject({
15931
- options: this.options,
15932
- renderCtx: this.renderContext
15933
- });
15934
- commentsContainer.padding.top = bodyMarginTop;
15935
- commentsContainer.rect.height = documentRender.rect.height;
15936
- documentRender.addChild(commentsContainer);
15937
- commentsContainer.rect.x = documentRender.rect.x + documentRender.rect.width;
15938
- documentRender.rect.width += this.options.reviewWindowWidth;
15939
- }
15940
- }
15941
- return docPages;
15942
- }
15943
- getDocInnerRect(documentRender) {
15944
- const render = documentRender.element.createRenderObject({
15945
- options: this.options,
15946
- renderCtx: this.renderContext
15947
- });
15948
- render.padding = documentRender.padding;
15949
- return render.getInnerRect();
15950
- }
15951
- getFullViewDocRender(documentRender, documentElement) {
15952
- const commentsRender = documentRender.getChild(3);
15953
- const commentsContainer = commentsRender.element.createRenderObject({
15954
- options: this.options,
15955
- renderCtx: this.renderContext
15956
- });
15957
- documentRender.rect.height -= commentsContainer.rect.height;
15958
- const bodyRender = documentRender.getChild(1);
15959
- if (this.options.showReviewWindow) {
15960
- documentRender.removeChild(commentsRender);
15961
- documentRender.addChild(commentsContainer);
15962
- commentsContainer.padding.top = bodyRender.rect.y;
15963
- commentsContainer.rect.height = documentRender.rect.height;
15964
- commentsContainer.rect.x = documentRender.rect.x + documentRender.rect.width;
15965
- documentRender.rect.width += this.options.reviewWindowWidth;
15966
- }
15967
- return [documentRender];
15968
- }
15969
- createEmptyBodyRender(bodyRender, limitRect) {
15970
- const pageBodyRender = bodyRender.element.createRenderObject({
15971
- options: this.options,
15972
- renderCtx: this.renderContext
15973
- });
15974
- pageBodyRender.rect.width = limitRect.width;
15975
- const bodyInnerLimitRect = pageBodyRender.getInnerRect();
15976
- if (this.options.fullPageView) {
15977
- bodyInnerLimitRect.height = Number.MAX_VALUE;
15978
- }
15979
- return {
15980
- emptyBody: pageBodyRender,
15981
- innerRect: { ...bodyInnerLimitRect, prevMargin: 0, maxWidth: limitRect.width, maxHeight: limitRect.height }
15982
- };
15983
- }
15984
- /**
15985
- * 切割渲染元素
15986
- * @param render 被切割的对象
15987
- * @param limitHeight
15988
- * @returns
15989
- */
15990
- cutRenderItem(render, limitHeight) {
15991
- if (render instanceof TableRowRenderObject) {
15992
- return this.cutRowRenderItem(render, limitHeight);
15993
- }
15994
- if (render instanceof TableRenderObject) {
15995
- return this.cutTable(render, limitHeight);
15996
- }
15997
- const cloneRender = render.element.createRenderObject({
15998
- options: this.options,
15999
- renderCtx: this.renderContext
16000
- });
16001
- cloneRender.setRenderWidth(render.rect.width);
16002
- if (render instanceof MuiltBlockLineRenderObject) {
16003
- let sumHeight = 0;
16004
- const children = [...render.getItems()];
16005
- let j = 0;
16006
- let blockLine = children[j];
16007
- while (blockLine) {
16008
- //sumHeight = ElementUtil.remeasure(cloneRender);
16009
- const calcBlockLineHeight = this.getBlockLineHeight(blockLine);
16010
- if (calcBlockLineHeight + sumHeight > limitHeight) {
16011
- if (blockLine instanceof MuiltBlockLineRenderObject) {
16012
- //限制的外框尺寸
16013
- const availHeight = limitHeight - sumHeight;
16014
- //限制的内框尺寸
16015
- const limitRenderInnterHeight = ElementUtil.innerRectMaxHeight(render, availHeight);
16016
- const cutRenderObject = this.cutRenderItem(blockLine, limitRenderInnterHeight);
16017
- if (cutRenderObject) {
16018
- cloneRender.addChild(cutRenderObject);
16019
- sumHeight += cutRenderObject.rect.height;
16020
- blockLine = children[++j];
16021
- break;
16022
- }
16023
- else {
16024
- break;
16025
- }
16026
- }
16027
- else {
16028
- break;
16029
- }
16030
- }
16031
- else {
16032
- render.removeChild(blockLine);
16033
- cloneRender.addChild(blockLine);
16034
- sumHeight += blockLine.rect.height;
16035
- blockLine = children[++j];
16036
- }
16037
- }
16038
- ElementUtil.remeasure(cloneRender);
16039
- ElementUtil.remeasure(render);
16040
- if (cloneRender.length === 0) {
16041
- return null;
16042
- }
16043
- else {
16044
- return cloneRender;
16045
- }
16046
- }
16047
- else {
16048
- throw new Error('未实现');
16049
- }
16050
- }
16051
- /**
16052
- * 切割渲染元素
16053
- * @param tbRender 被切割的对象
16054
- * @param limitHeight
16055
- * @param addFunc
16056
- * @returns
16057
- */
16058
- cutTable(tbRender, limitHeight) {
16059
- const cloneTbRender = tbRender.element.createRenderObject();
16060
- cloneTbRender.setRenderWidth(tbRender.rect.width);
16061
- let sumHeight = 0;
16062
- const rows = [...tbRender.getItems()];
16063
- //获取跨页需要重复显示的行
16064
- const headerRows = this.getHeaderRows(tbRender);
16065
- //跨页头的高度
16066
- const headerHeight = headerRows.reduce((prev, curr) => prev + curr.rect.height, 0);
16067
- if (headerHeight > limitHeight) {
16068
- return null;
16069
- }
16070
- const copyHeaderRows = headerRows.map(item => item.clone());
16071
- //获取最后一个截断行,需要根据截断行判断最后一个截断的行位置
16072
- const cutOffRows = rows.filter(row => limitHeight >= row.rect.y && limitHeight <= row.rect.y + row.rect.height)
16073
- .map((row) => ({ rowIndex: row.element.getIndex(), row }))
16074
- .sort((first, second) => second.rowIndex - first.rowIndex);
16075
- if (cutOffRows.length === 0) {
16076
- throw new Error('无法获取截断行');
16077
- }
16078
- const joinRow = cutOffRows[0].row;
16079
- let j = 0;
16080
- let currRow = rows[j];
16081
- const cutRows = [];
16082
- while (currRow) {
16083
- const rowContentHeight = this.getBlockLineHeight(currRow);
16084
- if (rowContentHeight + sumHeight > limitHeight) {
16085
- if (currRow instanceof MuiltBlockLineRenderObject) {
16086
- //限制的外框尺寸
16087
- const availHeight = limitHeight - sumHeight;
16088
- //限制的内框尺寸
16089
- const limitRenderInnterHeight = ElementUtil.innerRectMaxHeight(tbRender, availHeight);
16090
- const cutRow = this.cutRowRenderItem(currRow, limitRenderInnterHeight);
16091
- if (cutRow) {
16092
- cloneTbRender.addChild(cutRow);
16093
- sumHeight += cutRow.rect.height;
16094
- cutRows.push(currRow);
16095
- if (currRow === joinRow) {
16096
- break;
16097
- }
16098
- currRow = rows[++j];
16099
- }
16100
- else {
16101
- break;
16102
- }
16103
- }
16104
- else {
16105
- break;
16106
- }
16107
- }
16108
- else {
16109
- tbRender.removeChild(currRow);
16110
- cloneTbRender.addChild(currRow);
16111
- sumHeight += currRow.rect.height;
16112
- currRow = rows[++j];
16113
- }
16114
- }
16115
- this.fixCutTable(tbRender, cutRows);
16116
- ElementUtil.remeasure(cloneTbRender);
16117
- //存在跨页需要重复显示的行头,则需要重新放置行头
16118
- if (copyHeaderRows.length) {
16119
- copyHeaderRows.forEach((r, i) => tbRender.insertChild(r, i));
16120
- }
16121
- ElementUtil.remeasure(tbRender);
16122
- if (cloneTbRender.length === 0) {
16123
- return null;
16124
- }
16125
- else {
16126
- return cloneTbRender;
16127
- }
16128
- }
16129
- cutRowRenderItem(render, limitHeight) {
16130
- if (render.element.props.minHeight > 0 && render.rect.height > limitHeight) {
16131
- return null;
16132
- }
16133
- const cloneRowRender = render.element.createRenderObject();
16134
- cloneRowRender.rect.width = render.rect.width;
16135
- render.remeasureState = true;
16136
- //cloneRowRender.rect.maxWidth = render.rect.height;
16137
- const cellRenders = [...render.getItems()];
16138
- const cutCellRenders = [];
16139
- for (let i = 0; i < cellRenders.length; i++) {
16140
- const cellRender = cellRenders[i];
16141
- this.markMergeRowRenderDirty(cellRender);
16142
- if (cellRender.rect.height > limitHeight) {
16143
- //限制的内框尺寸
16144
- const limitCellHeight = ElementUtil.innerRectMaxHeight(cellRender, limitHeight);
16145
- const cutCellRender = this.cutRenderItem(cellRender, limitCellHeight);
16146
- if (cutCellRender) {
16147
- cutCellRenders.push(cutCellRender);
16148
- }
16149
- else {
16150
- cutCellRenders.push(null);
16151
- }
16152
- }
16153
- else {
16154
- const cloneCellRender = cellRender;
16155
- render.removeChild(cellRender);
16156
- cutCellRenders.push(cloneCellRender);
16157
- }
16158
- }
16159
- ElementUtil.remeasure(render);
16160
- if (cutCellRenders.filter(item => item).length === 0) {
16161
- return null;
16162
- }
16163
- else {
16164
- //补齐单元格
16165
- for (let i = 0; i < cutCellRenders.length; i++) {
16166
- let cellRender = cutCellRenders[i];
16167
- if (!cellRender) {
16168
- cellRender = cellRenders[i].element.createRenderObject({
16169
- options: this.options,
16170
- renderCtx: this.renderContext
16171
- });
16172
- cellRender.rect = ElementUtil.cloneRect(cellRenders[i].rect);
16173
- ElementUtil.remeasure(cellRender);
16174
- }
16175
- cloneRowRender.addChild(cellRender);
16176
- }
16177
- ElementUtil.remeasure(cloneRowRender);
16178
- return cloneRowRender;
16179
- }
16180
- }
16181
- /**
16182
- * 标记合并单元格所在行需要重新计算
16183
- * @param cellRender
16184
- * @private
16185
- */
16186
- markMergeRowRenderDirty(cellRender) {
16187
- const cellEle = cellRender.element;
16188
- if (cellEle.props.vMerge !== 'restart') {
16189
- return;
16190
- }
16191
- const rowRender = cellRender.parent;
16192
- rowRender.element;
16193
- const tb = rowRender.parent;
16194
- const cellYPos = cellRender.rect.y;
16195
- for (let i = rowRender.getIndex() + 1; i < tb.length; i++) {
16196
- const nextRowRender = tb.getChild(i);
16197
- if (nextRowRender.rect.y <= cellYPos) {
16198
- nextRowRender.remeasureState = true;
16199
- nextRowRender.getItems().forEach(item => {
16200
- this.markMergeRowRenderDirty(item);
16201
- });
16202
- }
16203
- else {
16204
- break;
16205
- }
16206
- }
16207
- }
16208
- /**
16209
- * 修复->已经截断的合并单元格要向下移动到合适的位置
16210
- * @param tbRender
16211
- * @param cutRows
16212
- * @returns
16213
- */
16214
- fixCutTable(tbRender, cutRows) {
16215
- if (!cutRows.length) {
16216
- return;
16217
- }
16218
- const tbEle = tbRender.element;
16219
- const belowMergeRows = new Set();
16220
- for (let i = 0; i < tbRender.length; i++) {
16221
- const row = tbRender.getChild(i);
16222
- const nextRow = tbRender.getChild(i + 1);
16223
- if (!nextRow) {
16224
- break;
16225
- }
16226
- if (!cutRows.some(item => item === row)) {
16227
- break;
16228
- }
16229
- if (row.length === tbEle.getColsCount()) {
16230
- break;
16231
- }
16232
- if (this.checkFullRow(row)) {
16233
- break;
16234
- }
16235
- for (let j = 0; j < row.length; j++) {
16236
- const cell = row.getChild(j);
16237
- const cellEle = cell.element;
16238
- const colIndex = cellEle.getIndex();
16239
- if (!this.existsCellRender(nextRow, colIndex)) {
16240
- const insertColIndex = this.getRowInsertCellIndex(cell, nextRow);
16241
- if (insertColIndex === -1) {
16242
- this.getRowInsertCellIndex(cell, nextRow);
16243
- throw new Error('未在紧挨下方找到可以放置的位置');
16244
- }
16245
- //row.removeChild(cell);
16246
- nextRow.insertChild(cell, insertColIndex);
16247
- belowMergeRows.add(row);
16248
- ElementUtil.remeasure(nextRow);
16249
- }
15414
+ else {
15415
+ i++;
16250
15416
  }
16251
15417
  }
16252
- if (belowMergeRows.size) {
16253
- for (const row of belowMergeRows) {
16254
- tbRender.removeChild(row);
16255
- row.clear();
15418
+ else {
15419
+ if (i > 1 && this.containPostPunctuation(render.textMeasures[i]?.char)) {
15420
+ i--;
16256
15421
  }
16257
- ElementUtil.remeasure(tbRender);
16258
15422
  }
15423
+ return i;
16259
15424
  }
16260
15425
  /**
16261
- * 校验当前是否是一个完整的行,没有Null单元格,检查当前是否还需要向下合并
16262
- * @param row
15426
+ * 是否包含后置标点
15427
+ * @param str
15428
+ * @returns
16263
15429
  */
16264
- checkFullRow(row) {
16265
- let x = 0;
16266
- for (let i = 0; i < row.length; i++) {
16267
- const cell = row.getChild(i);
16268
- if (cell.rect.x !== x) {
16269
- return false;
16270
- }
16271
- x += cell.rect.width;
16272
- }
16273
- return x === row.rect.width;
15430
+ containPostPunctuation(str) {
15431
+ return '!),.:;?]}¨·ˇˉ―‖’”…∶、。〃々〉》」』】〕〗!"'),.:;?]`|}~¢'.indexOf(str) > -1;
16274
15432
  }
16275
- existsCellRender(rowRender, cellIndex) {
16276
- for (let i = 0; i < rowRender.length; i++) {
16277
- const cellRender = rowRender.getChild(i);
16278
- const cellEle = cellRender.element;
16279
- if (cellEle.getIndex() === cellIndex) {
16280
- return true;
15433
+ //是否包含前置标点
15434
+ containLeadingPunctuation(str) {
15435
+ return '‘“〈《「『【〔〖([{£'.indexOf(str) > -1;
15436
+ }
15437
+ /**
15438
+ * 文本开头是否包含后置标点
15439
+ * @param render
15440
+ * @returns
15441
+ */
15442
+ containerStartSymbolInTextStart(render) {
15443
+ //return false;
15444
+ if (render instanceof TextGroupRenderObject) {
15445
+ if (render.textMeasures.length > 0) {
15446
+ return this.containPostPunctuation(render.textMeasures[0].char);
16281
15447
  }
16282
15448
  }
16283
15449
  return false;
16284
15450
  }
16285
- getBlockLineHeight(render) {
16286
- if (render instanceof TableRowRenderObject) {
16287
- let maxCellHeight = 0;
16288
- for (let i = 0; i < render.length; i++) {
16289
- const itemHeight = render.getChild(i).rect.height;
16290
- if (itemHeight > maxCellHeight) {
16291
- maxCellHeight = itemHeight;
15451
+ cutFillNullRender(render, limitWidth) {
15452
+ if (limitWidth === 0) {
15453
+ return { firstItem: null, lastItem: null };
15454
+ }
15455
+ if (render.rect.width > limitWidth) {
15456
+ const cutRender = new FillNullSpaceRenderObject();
15457
+ cutRender.rect.width = limitWidth;
15458
+ cutRender.rect.height = render.rect.height;
15459
+ render.rect.width = render.rect.width - limitWidth;
15460
+ return { firstItem: cutRender, lastItem: render };
15461
+ }
15462
+ else {
15463
+ return { firstItem: render, lastItem: null };
15464
+ }
15465
+ }
15466
+ /**
15467
+ * 行内编组元素超出行内可用空间,需要根据剩余空间长度进行截断
15468
+ */
15469
+ cutInlineGroupRenderItem(render, limitWidth, emptyLine, inCloseBody) {
15470
+ const cutRender = render.element.createRenderObject({ options: this.options, renderCtx: this.renderCtx });
15471
+ let x = 0;
15472
+ let br = false;
15473
+ const items = [...render.getItems()];
15474
+ for (let i = 0; i < items.length; i++) {
15475
+ const child = items[i];
15476
+ if (child instanceof LeafRenderObject) {
15477
+ if (x + child.rect.width > limitWidth) {
15478
+ const { firstItem, lastItem, br: childBr } = this.cutRenderItem(child, items[i + 1], limitWidth - x, emptyLine && cutRender.length === 0, inCloseBody);
15479
+ if (firstItem) {
15480
+ cutRender.addChild(firstItem);
15481
+ }
15482
+ br = childBr || br;
15483
+ break;
15484
+ }
15485
+ else {
15486
+ render.removeChild(child);
15487
+ cutRender.addChild(child);
15488
+ }
15489
+ //软换行符
15490
+ if (child.element && child.element.type === 'br') {
15491
+ br = true;
15492
+ break;
16292
15493
  }
16293
15494
  }
16294
- return maxCellHeight;
15495
+ else if (child instanceof InlineGroupRenderObject) {
15496
+ if (x + child.rect.width > limitWidth) {
15497
+ const { firstItem, br: childBr } = this.cutInlineGroupRenderItem(child, limitWidth - x, emptyLine && cutRender.length === 0, inCloseBody);
15498
+ if (firstItem) {
15499
+ cutRender.addChild(firstItem);
15500
+ }
15501
+ br = childBr || br;
15502
+ break;
15503
+ }
15504
+ else {
15505
+ render.removeChild(child);
15506
+ cutRender.addChild(child);
15507
+ }
15508
+ }
15509
+ x += child.rect.width;
16295
15510
  }
16296
- return render.rect.height;
15511
+ if (!cutRender.length) {
15512
+ return { firstItem: null, lastItem: null };
15513
+ }
15514
+ ElementUtil.remeasureInlineGroupRender(cutRender);
15515
+ ElementUtil.remeasureInlineGroupRender(render);
15516
+ return { firstItem: cutRender, lastItem: render.length ? render : null, br };
16297
15517
  }
16298
- getRowInsertCellIndex(sourceCell, destRow) {
16299
- for (let i = 0; i < destRow.length; i++) {
16300
- const cell = destRow.getChild(i);
16301
- const rect = cell.rect;
16302
- if (sourceCell.rect.x < rect.x) {
16303
- return i;
15518
+ /**
15519
+ * 修改测量完毕后的元素状态
15520
+ * @param ele
15521
+ */
15522
+ setMeasureCompletedModifyFlag(ele) {
15523
+ if (ele instanceof BranchElement) {
15524
+ for (let i = 0; i < ele.length; i++) {
15525
+ this.setMeasureCompletedModifyFlag(ele.getChild(i));
16304
15526
  }
16305
15527
  }
16306
- const lastCell = destRow.getChild(destRow.length - 1);
16307
- if (sourceCell.rect.x >= lastCell.rect.x + lastCell.rect.width) {
16308
- return destRow.length;
16309
- }
16310
- return -1;
15528
+ ele.modifyFlag = exports.ModifyFlag.None;
16311
15529
  }
16312
- getHeaderRows(tb) {
16313
- const rows = [];
16314
- for (let i = 0; i < tb.length; i++) {
16315
- const rowRender = tb.getChild(i);
16316
- const rowEle = rowRender.element;
16317
- if (rowEle.props.headerRow) {
16318
- rows.push(rowRender);
15530
+ clearPaintCache(ele, data) {
15531
+ ele.beginMeasure(data);
15532
+ if (ele instanceof BranchElement) {
15533
+ for (let i = 0; i < ele.length; i++) {
15534
+ this.clearPaintCache(ele.getChild(i), data);
16319
15535
  }
16320
- else {
16321
- break;
15536
+ }
15537
+ }
15538
+ endMeasures(ele) {
15539
+ if (ele instanceof BranchElement) {
15540
+ for (let i = 0; i < ele.length; i++) {
15541
+ this.endMeasures(ele.getChild(i));
16322
15542
  }
16323
15543
  }
16324
- return rows;
16325
15544
  }
16326
15545
  }
16327
15546
 
16328
15547
  class DocumentPaint {
16329
15548
  renderContext;
16330
15549
  docCtx;
16331
- selectedSets;
15550
+ seo;
16332
15551
  elementMeasure;
16333
- elementRenderCut;
15552
+ //elementRenderCut: ElementRenderCut;
16334
15553
  elementPaint;
16335
15554
  docPages;
16336
15555
  docContainer;
16337
15556
  //commsContainer!: CommsContainerRenderObject;
16338
15557
  viewOptions;
16339
- constructor(renderContext, docCtx, selectedSets) {
15558
+ constructor(renderContext, docCtx, seo) {
16340
15559
  this.renderContext = renderContext;
16341
15560
  this.docCtx = docCtx;
16342
- this.selectedSets = selectedSets;
15561
+ this.seo = seo;
16343
15562
  this.viewOptions = this.docCtx.viewOptions;
16344
15563
  this.elementMeasure = new ElementMeasure(this.docCtx, this.renderContext);
16345
- this.elementRenderCut = new ElementRenderCut(this.viewOptions, this.renderContext);
15564
+ //this.elementRenderCut = new ElementRenderCut(this.viewOptions, this.renderContext);
16346
15565
  this.elementPaint = new ElementPaint(this.renderContext, this.docCtx);
16347
15566
  }
16348
15567
  rePages() {
@@ -16361,7 +15580,7 @@ class DocumentPaint {
16361
15580
  // //console.timeEnd('排版计时');
16362
15581
  // //console.time('断页计时');
16363
15582
  // const docPages = this.elementRenderCut.cutPage(documentRender, this.docCtx.document);
16364
- const newMeasure = new DocumentArrange(this.docCtx, this.renderContext);
15583
+ const newMeasure = new DocumentArrange(this.docCtx, this.renderContext, this.seo);
16365
15584
  const docPages = newMeasure.measureDoc();
16366
15585
  // this.commsContainer = newMeasure.commentsRender as CommsContainerRenderObject;
16367
15586
  // if (this.commsContainer) {
@@ -16458,7 +15677,7 @@ class DocumentPaint {
16458
15677
  }
16459
15678
  }
16460
15679
  refreshView() {
16461
- this.elementPaint.drawPages(this.docContainer, this.selectedSets);
15680
+ this.elementPaint.drawPages(this.docContainer, this.seo.selectionEleSets);
16462
15681
  }
16463
15682
  getDocPages() {
16464
15683
  return this.docPages;
@@ -16473,31 +15692,31 @@ class DocumentPaint {
16473
15692
  if (!this.viewOptions.showReviewWindow) {
16474
15693
  return;
16475
15694
  }
16476
- const cce = this.docCtx.document.commentsContainerElement;
16477
- const set = new Map();
16478
- const commentRangeStatus = [];
16479
- for (let i = 0; i < cce.length; i++) {
16480
- const commContent = cce.getChild(i);
16481
- const commMarkPair = cce.markPairs.find(item => item.id === commContent.props.id);
16482
- if (commMarkPair) {
16483
- if (commMarkPair.start) {
16484
- commContent.startMark = commMarkPair.start;
16485
- }
16486
- if (commMarkPair.end) {
16487
- commContent.endMark = commMarkPair.end;
16488
- }
16489
- }
16490
- const { startMark, endMark, props: { id }, focus } = commContent;
16491
- const ancestorCommonControl = DocumentSelection.getAncestorCommonControl(startMark, endMark);
16492
- const commonRange = RangeUtil.getSelctionRange(startMark, 0, endMark, 1, ancestorCommonControl);
16493
- SelectionOverlays.addToCommentSets(commonRange, set);
16494
- commentRangeStatus.push({
16495
- commContent,
16496
- range: commonRange
16497
- });
16498
- }
16499
- cce.cacheRender.selectedSet = set;
16500
- cce.cacheRender.commentRangeStatus = commentRangeStatus;
15695
+ // const cce = this.docCtx.document.commentsContainerElement;
15696
+ // const set = new Map<Element, SelectionContentRange>();
15697
+ // const commentRangeStatus: Array<CommentRangeStatus> = [];
15698
+ // for (let i = 0; i < cce.length; i++) {
15699
+ // const commContent = cce.getChild(i) as CommContentElement;
15700
+ // const commMarkPair = cce.markPairs.find(item => item.id === commContent.props.id);
15701
+ // if (commMarkPair) {
15702
+ // if (commMarkPair.start) {
15703
+ // commContent.startMark = commMarkPair.start;
15704
+ // }
15705
+ // if (commMarkPair.end) {
15706
+ // commContent.endMark = commMarkPair.end;
15707
+ // }
15708
+ // }
15709
+ // const {startMark, endMark, props: {id}, focus} = commContent;
15710
+ // const ancestorCommonControl = DocumentSelection.getAncestorCommonControl(startMark, endMark);
15711
+ // const commonRange = RangeUtil.getSectionRange(startMark, 0, endMark, 1, ancestorCommonControl);
15712
+ // SelectionOverlays.addToCommentSets(commonRange, set);
15713
+ // commentRangeStatus.push({
15714
+ // commContent,
15715
+ // range: commonRange
15716
+ // })
15717
+ // }
15718
+ // (<CommsContainerRenderObject>cce.cacheRender).selectedSet = set;
15719
+ // (<CommsContainerRenderObject>cce.cacheRender).commentRangeStatus = commentRangeStatus;
16501
15720
  }
16502
15721
  }
16503
15722
 
@@ -16536,8 +15755,6 @@ class PermanentTeethElement extends LeafElement {
16536
15755
  }
16537
15756
  }
16538
15757
  class PermanentTeethRenderObject extends LeafRenderObject {
16539
- render(e) {
16540
- }
16541
15758
  clone() {
16542
15759
  const clone = new PermanentTeethRenderObject(this.element);
16543
15760
  clone.rect = ElementUtil.cloneRect(this.rect);
@@ -16669,6 +15886,7 @@ class ElementReader {
16669
15886
  this.addFactory(PageBreakFactory);
16670
15887
  this.addFactory(TabFactory);
16671
15888
  this.addFactory(PermanentTeethFactory);
15889
+ this.addFactory(SVGFactory);
16672
15890
  // this.registerReadFunc<TrackRunProps>('ins-run', (data) => {
16673
15891
  // const props = new TrackRunProps(data.type);
16674
15892
  // props.userId = data.userId;
@@ -16697,15 +15915,15 @@ class ElementReader {
16697
15915
  document.bodyElement = document.find((item) => item instanceof DocumentBodyElement);
16698
15916
  document.headerElement = document.find((item) => item instanceof DocumentHeaderElement);
16699
15917
  document.footerElement = document.find((item) => item instanceof DocumentFooterElement);
16700
- document.commentsContainerElement = document.find((item) => item instanceof CommsContainerElement);
16701
- if (!document.commentsContainerElement) {
16702
- document.commentsContainerElement = new CommsContainerElement();
16703
- }
15918
+ // document.commentsContainerElement = document.find((item) => item instanceof CommsContainerElement) as CommsContainerElement;
15919
+ // if (!document.commentsContainerElement) {
15920
+ // document.commentsContainerElement = new CommsContainerElement();
15921
+ // }
16704
15922
  document.clearItems();
16705
15923
  document.addChild(document.headerElement);
16706
15924
  document.addChild(document.bodyElement);
16707
15925
  document.addChild(document.footerElement);
16708
- document.addChild(document.commentsContainerElement);
15926
+ //document.addChild(document.commentsContainerElement);
16709
15927
  this.docCtx.document = document;
16710
15928
  document.viewOptions = this.docCtx.viewOptions;
16711
15929
  const width = Math.floor(document.props.width * this.docCtx.viewOptions.mmToPixelsRatio);
@@ -16713,7 +15931,7 @@ class ElementReader {
16713
15931
  this.docCtx.viewOptions.docPageSettings = new PageOptions(width, height, document.props.orient);
16714
15932
  //this.viewOptions.viewSettings.width = this.viewOptions.docPageSettings.width + 10;
16715
15933
  }
16716
- readElement(data) {
15934
+ readElement(data, strictMode = false) {
16717
15935
  if (typeof data === 'string') {
16718
15936
  data = JSON.parse(data);
16719
15937
  }
@@ -16728,19 +15946,27 @@ class ElementReader {
16728
15946
  const children = data.children || [];
16729
15947
  for (const child of children) {
16730
15948
  //element.addChild(this.readElement(child));
16731
- childArr.push(this.readElement(child));
15949
+ const childEle = this.readElement(child);
15950
+ childEle && childArr.push(childEle);
16732
15951
  }
16733
15952
  }
16734
15953
  factory.readCompleted(element, childArr);
16735
15954
  return element;
16736
15955
  }
16737
15956
  }
16738
- throw new Error('未知的元素类型:' + type);
15957
+ if (strictMode) {
15958
+ throw new Error('未知的元素类型:' + type, data);
15959
+ }
15960
+ else {
15961
+ console.error('未知的元素类型:' + type, data);
15962
+ return null;
15963
+ }
16739
15964
  }
16740
- // propsReadFuncs: Map<string, (data: any) => any> = new Map();
16741
- // registerReadFunc<T>(propName: string, func: (data: T) => T): void {
16742
- // this.propsReadFuncs.set(propName, func);
16743
- // }
15965
+ /**
15966
+ * 读取扩展属性
15967
+ * @param data
15968
+ * @param element
15969
+ */
16744
15970
  readExtendsProps(data, element) {
16745
15971
  if (!data.props) {
16746
15972
  return;
@@ -17801,7 +17027,10 @@ class DocumentEvent {
17801
17027
  if (renderObject instanceof LeafRenderObject) {
17802
17028
  if (CommonUtil.isInsideRectByPosition(renderObjectRect, hitPos)) {
17803
17029
  const x = hitPos.x - renderObjectRect.x;
17804
- const offset = ElementUtil.getHitRenderOffset(renderObject, x);
17030
+ let offset = ElementUtil.getHitRenderOffset(renderObject, x);
17031
+ if (!this.ismousedown && renderObject.element && renderObject.element.type === 'psym') {
17032
+ offset = 0;
17033
+ }
17805
17034
  return {
17806
17035
  render: renderObject,
17807
17036
  offset,
@@ -17893,7 +17122,10 @@ class DocumentEvent {
17893
17122
  else {
17894
17123
  x = position.x - adjacentRender.rect.x;
17895
17124
  }
17896
- const offset = ElementUtil.getHitRenderOffset(adjacentRender.render, x);
17125
+ let offset = ElementUtil.getHitRenderOffset(adjacentRender.render, x);
17126
+ if (!this.ismousedown && renderObject.element && renderObject.element.type === 'psym') {
17127
+ offset = 0;
17128
+ }
17897
17129
  return {
17898
17130
  render: adjacentRender.render,
17899
17131
  absoluteRenderRect: adjacentRender.rect,
@@ -17983,6 +17215,7 @@ class DocumentEvent {
17983
17215
  startHitInfo: this.startHitInfo,
17984
17216
  endHitInfo: this.endHitInfo
17985
17217
  });
17218
+ console.log(this.endHitInfo);
17986
17219
  }
17987
17220
  /**
17988
17221
  * 获取鼠标所在的渲染元素对象
@@ -19588,7 +18821,7 @@ class DocumentChange {
19588
18821
  return paragraph;
19589
18822
  }
19590
18823
  const last = ElementUtil.getLastLeafElement(paragraph);
19591
- const selectedParaRange = RangeUtil.getSelctionRange(startControl, startOffset, last, 1, paragraph);
18824
+ const selectedParaRange = RangeUtil.getSectionRange(startControl, startOffset, last, 1, paragraph);
19592
18825
  selectedParaRange.isFullSelected = false;
19593
18826
  const breakPara = ElementUtil.cloneRange(selectedParaRange, true);
19594
18827
  ElementUtil.fixParagraphContent(paragraph);
@@ -20210,22 +19443,26 @@ class DocumentChange {
20210
19443
  const id = nanoid.nanoid(5);
20211
19444
  const startCommMark = new CommentElement();
20212
19445
  startCommMark.props.id = id;
19446
+ startCommMark.props.userId = this.viewOptions.editUser.id;
19447
+ startCommMark.props.userName = this.viewOptions.editUser.name;
19448
+ startCommMark.props.date = CommonUtil.formatNow('YYYY-MM-DD HH:mm:ss');
20213
19449
  startCommMark.props.markType = 'start';
20214
19450
  const endCommMark = new CommentElement();
20215
19451
  endCommMark.props.id = id;
20216
19452
  endCommMark.props.markType = 'end';
20217
19453
  this.insertElement(endControl, endOffset, [endCommMark]);
20218
19454
  this.insertElement(startControl, startOffset, [startCommMark]);
20219
- const commContent = new CommContentElement();
20220
- commContent.props.id = id;
20221
- commContent.props.createId = this.viewOptions.editUser.id;
20222
- commContent.props.createName = this.viewOptions.editUser.name;
20223
- commContent.props.createDate = new Date();
20224
- const pos = this.docComment.getCommMarkIndex(startCommMark);
20225
- if (pos < 0) {
20226
- throw new Error('获取插入的批注位置不正确');
20227
- }
20228
- this.docCtx.document.commentsContainerElement.addChild(commContent, pos);
19455
+ startCommMark.props.text = '插入测试批注信息' + new Date();
19456
+ // const commContent = new CommContentElement();
19457
+ // commContent.props.id = id;
19458
+ // commContent.props.createId = this.viewOptions.editUser.id;
19459
+ // commContent.props.createName = this.viewOptions.editUser.name;
19460
+ // commContent.props.createDate = new Date();
19461
+ // const pos = this.docComment.getCommMarkIndex(startCommMark);
19462
+ // if (pos < 0) {
19463
+ // throw new Error('获取插入的批注位置不正确');
19464
+ // }
19465
+ // this.docCtx.document.commentsContainerElement.addChild(commContent, pos);
20229
19466
  this.selectionState.clear();
20230
19467
  }
20231
19468
  validate() {
@@ -20249,8 +19486,8 @@ class DocumentChange {
20249
19486
  validateElement.props.title = caption + '验证';
20250
19487
  validateElement.props.id = id;
20251
19488
  validateElement.setContent(item.error);
20252
- const pos = this.docComment.getCommMarkIndex(startCommMark);
20253
- this.docCtx.document.commentsContainerElement.addChild(validateElement, pos);
19489
+ this.docComment.getCommMarkIndex(startCommMark);
19490
+ //this.docCtx.document.commentsContainerElement.addChild(validateElement, pos);
20254
19491
  });
20255
19492
  this.docCtx.selectionState.clear();
20256
19493
  return false;
@@ -20676,7 +19913,6 @@ class DocumentComment {
20676
19913
  // }
20677
19914
  // this.commMarkList = commList;
20678
19915
  // this.commContentList = commContentList;
20679
- this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
20680
19916
  this.isDirty = false;
20681
19917
  }
20682
19918
  /**
@@ -20712,28 +19948,46 @@ class DocumentComment {
20712
19948
  if (!endRange) {
20713
19949
  return;
20714
19950
  }
20715
- const commPairs = [];
20716
- const markPairs = this.docCtx.document.commentsContainerElement.markPairs;
20717
- for (let i = 0; i < markPairs.length; i++) {
20718
- const { start: startMark, end: endMark } = markPairs[i];
20719
- if (!startMark || !endMark) {
20720
- continue;
20721
- }
20722
- const commPair = {
20723
- startMark,
20724
- endMark,
20725
- startMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, startMark),
20726
- endMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, endMark),
20727
- };
20728
- commPairs.push(commPair);
20729
- }
20730
- for (let i = 0; i < commPairs.length; i++) {
20731
- const commPair = commPairs[i];
20732
- if (commPair.endMarkStatus) {
20733
- this.removeComment(commPair.endMark.props.id);
19951
+ const selectedComms = [];
19952
+ RangeUtil.recursionTraversalRangeHandler(selectedRange, (range) => {
19953
+ if (range.target instanceof CommentElement && range.isFullSelected) {
19954
+ selectedComms.push(range.target);
20734
19955
  }
20735
- else if (commPair.startMarkStatus) ;
19956
+ });
19957
+ if (selectedComms.length > 0) {
19958
+ const ids = selectedComms.map(item => item.props.id);
19959
+ const commList = this.docCtx.document.treeFilter(item => item.type === 'comm' && ids.indexOf(item.props.id) >= 0);
19960
+ commList.forEach(item => item.remove());
19961
+ return;
20736
19962
  }
19963
+ return;
19964
+ // const commPairs: Array<CommMarkSelectedStatus> = [];
19965
+ // const markPairs = this.docCtx.document.commentsContainerElement.markPairs;
19966
+ // for (let i = 0; i < markPairs.length; i++) {
19967
+ // const {start: startMark, end: endMark} = markPairs[i];
19968
+ // if (!startMark || !endMark) {
19969
+ // continue;
19970
+ // }
19971
+ // const commPair: CommMarkSelectedStatus = {
19972
+ // startMark,
19973
+ // endMark,
19974
+ // startMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, startMark),
19975
+ // endMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, endMark),
19976
+ // };
19977
+ // commPairs.push(commPair)
19978
+ // }
19979
+ //
19980
+ // for (let i = 0; i < commPairs.length; i++) {
19981
+ // const commPair = commPairs[i];
19982
+ // if (commPair.endMarkStatus) {
19983
+ // this.removeComment(commPair.endMark.props.id);
19984
+ // } else if (commPair.startMarkStatus) {
19985
+ // // const newStartMark = new CommentElement();
19986
+ // // newStartMark.props.id = commPair.startMark.props.id;
19987
+ // // commPair.startMark.isDecorate = false;
19988
+ // // DocumentChange.insertElement(endRange.target, endRange.endOffset, [newStartMark]);
19989
+ // }
19990
+ // }
20737
19991
  }
20738
19992
  }
20739
19993
  /**
@@ -20741,7 +19995,7 @@ class DocumentComment {
20741
19995
  * @param id
20742
19996
  */
20743
19997
  removeComment(id) {
20744
- this.docCtx.document.commentsContainerElement.removeCommMark(id);
19998
+ this.docCtx.document.removeCommMark(id);
20745
19999
  }
20746
20000
  getCommMarkIndex(commMark) {
20747
20001
  const markType = commMark.props.markType;
@@ -20753,7 +20007,7 @@ class DocumentComment {
20753
20007
  * 清除所有批注
20754
20008
  */
20755
20009
  clearAllComments() {
20756
- this.docCtx.document.commentsContainerElement.clearAllComms();
20010
+ this.docCtx.document.clearAllComms();
20757
20011
  this.docCtx.selectionState.clear();
20758
20012
  }
20759
20013
  /**
@@ -21179,15 +20433,15 @@ class ElementTrackManage {
21179
20433
 
21180
20434
  class DocumentSvg {
21181
20435
  viewOptions;
21182
- selectedSets;
20436
+ sso;
21183
20437
  renderCtx;
21184
20438
  highlights = [];
21185
20439
  mode = "view";
21186
20440
  //当前页位置
21187
20441
  pagePos;
21188
- constructor(viewOptions, selectedSets, renderCtx) {
20442
+ constructor(viewOptions, sso, renderCtx) {
21189
20443
  this.viewOptions = viewOptions;
21190
- this.selectedSets = selectedSets;
20444
+ this.sso = sso;
21191
20445
  this.renderCtx = renderCtx;
21192
20446
  }
21193
20447
  getVNode(render, selectionRects, parentPos) {
@@ -21197,22 +20451,8 @@ class DocumentSvg {
21197
20451
  width: render.rect.width,
21198
20452
  height: render.rect.height
21199
20453
  };
21200
- if (this.selectedSets.has(render.element)) {
21201
- const range = this.selectedSets.get(render.element);
21202
- if (render.element && render instanceof LeafRenderObject) {
21203
- if (range.isFullSelected) {
21204
- selectionRects.push(currPos);
21205
- }
21206
- else {
21207
- if (render.element instanceof TextGroupElement && range.endOffset > range.startOffset) {
21208
- const { startX, endX } = ElementUtil.getTextRenderHorX(render, range.startOffset, range.endOffset);
21209
- const width = endX - startX;
21210
- const x = currPos.x + startX;
21211
- selectionRects.push({ x, y: currPos.y, width, height: currPos.height });
21212
- }
21213
- }
21214
- }
21215
- }
20454
+ //处理选区遮罩
20455
+ this.createSelectionRect(render, selectionRects, currPos);
21216
20456
  //审阅窗口重新计算位置
21217
20457
  if (this.viewOptions.showReviewWindow && render instanceof CommsContainerRenderObject) {
21218
20458
  CommentsUtil.arrangeComments(render);
@@ -21276,12 +20516,18 @@ class DocumentSvg {
21276
20516
  if (selectionRectsTemp.length > 0) {
21277
20517
  const startX = selectionRectsTemp[0].x;
21278
20518
  const endX = selectionRectsTemp[selectionRectsTemp.length - 1].x + selectionRectsTemp[selectionRectsTemp.length - 1].width;
21279
- selectionRects.push({ x: startX, y: currPos.y, width: endX - startX, height: currPos.height });
20519
+ selectionRects.push({
20520
+ x: startX,
20521
+ y: currPos.y,
20522
+ width: endX - startX,
20523
+ height: currPos.height,
20524
+ color: selectionRectsTemp[0].color
20525
+ });
21280
20526
  selectionRectsTemp.length = 0;
21281
20527
  }
21282
20528
  }
21283
20529
  else if (render instanceof TableCellRenderObject) {
21284
- if (this.selectedSets.has(render.element) && this.selectedSets.get(render.element)?.isFullSelected) {
20530
+ if (this.sso.selectionEleSets.has(render.element) && this.sso.selectionEleSets.get(render.element)?.isFullSelected) {
21285
20531
  selectionRects.push(currPos);
21286
20532
  selectionRectsTemp.length = 0;
21287
20533
  }
@@ -21323,11 +20569,39 @@ class DocumentSvg {
21323
20569
  }
21324
20570
  return currVNode;
21325
20571
  }
20572
+ createSelectionRect(render, selectionRects, currPos) {
20573
+ const items = [this.sso.selectionEleSets, this.sso.commRangeSets];
20574
+ for (const item of items) {
20575
+ if (item.has(render.element)) {
20576
+ const range = item.get(render.element);
20577
+ if (render.element && render instanceof LeafRenderObject) {
20578
+ if (range.isFullSelected) {
20579
+ selectionRects.push({ ...currPos, color: range['rangeColor'] });
20580
+ }
20581
+ else {
20582
+ if (render.element instanceof TextGroupElement && range.endOffset > range.startOffset) {
20583
+ const { startX, endX } = ElementUtil.getTextRenderHorX(render, range.startOffset, range.endOffset);
20584
+ const width = endX - startX;
20585
+ const x = currPos.x + startX;
20586
+ // @ts-ignore
20587
+ selectionRects.push({
20588
+ x,
20589
+ y: currPos.y,
20590
+ width,
20591
+ height: currPos.height,
20592
+ color: range['rangeColor']
20593
+ });
20594
+ }
20595
+ }
20596
+ }
20597
+ }
20598
+ }
20599
+ }
21326
20600
  getHTMLVNode(docRenders) {
21327
20601
  this.counterMap = {};
21328
- const pageNodes = docRenders.filter(item => this.checkInViewBox(item)).map(item => {
20602
+ return docRenders.filter(item => this.checkInViewBox(item)).map(item => {
21329
20603
  const pageSvg = this.getPageSvgVNode(item);
21330
- const pageUnit = {
20604
+ return {
21331
20605
  sel: 'div.page-unit',
21332
20606
  data: {
21333
20607
  style: {
@@ -21342,9 +20616,7 @@ class DocumentSvg {
21342
20616
  },
21343
20617
  children: [pageSvg]
21344
20618
  };
21345
- return pageUnit;
21346
20619
  });
21347
- return pageNodes;
21348
20620
  }
21349
20621
  /**
21350
20622
  * 判断当前元素是否在视窗内
@@ -21382,7 +20654,7 @@ class DocumentSvg {
21382
20654
  ns: 'http://www.w3.org/2000/svg',
21383
20655
  attrs: {
21384
20656
  stroke: 'none',
21385
- fill: 'rgb(85,165,255)',
20657
+ fill: item.color ?? 'rgb(85,165,255)',
21386
20658
  'paint-order': 'stroke fill markers',
21387
20659
  d: `M${item.x} ${item.y} L${item.x + item.width} ${item.y} L${item.x + item.width} ${item.y + item.height} L${item.x} ${item.y + item.height} Z`,
21388
20660
  'fill-opacity': '0.5'
@@ -26392,7 +25664,10 @@ class DocumentPrintOffscreenBase {
26392
25664
  const ss = new SelectionState();
26393
25665
  this.docCtx = new EditorContext(ss, this.viewOptions);
26394
25666
  this.renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
26395
- this.documentPaint = new DocumentPaint(this.renderCtx, this.docCtx, new Map());
25667
+ this.documentPaint = new DocumentPaint(this.renderCtx, this.docCtx, {
25668
+ selectionEleSets: new Map(),
25669
+ commRangeSets: new Map()
25670
+ });
26396
25671
  this.elementReader = new ElementReader(this.docCtx);
26397
25672
  this.docCtx.syncRefresh = () => {
26398
25673
  };
@@ -26407,8 +25682,8 @@ class DocumentPrintOffscreenBase {
26407
25682
  // const docProps = this.docCtx.document.props;
26408
25683
  // printNodes(canvasNodes, {...docProps});
26409
25684
  // }
26410
- async print(data, ranges = null) {
26411
- await this.prepare(data);
25685
+ print(data, ranges = null) {
25686
+ this.prepare(data);
26412
25687
  const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
26413
25688
  if (!canvasNodes.length) {
26414
25689
  console.warn('无可打印页');
@@ -26423,7 +25698,7 @@ class DocumentPrintOffscreenBase {
26423
25698
  /**
26424
25699
  * 续打
26425
25700
  */
26426
- async printForContinuation(data, options) {
25701
+ printForContinuation(data, options) {
26427
25702
  this.afterRenderEvent.subscribe((event) => {
26428
25703
  const { index, renderCtx, docRender, pageSvgVNode } = event;
26429
25704
  if (index === options.startDocIndex && options.startY !== 0) {
@@ -26437,7 +25712,7 @@ class DocumentPrintOffscreenBase {
26437
25712
  pageSvgVNode.data.attrs['clip-path'] = `url(#${'page-clip-' + index})`;
26438
25713
  }
26439
25714
  });
26440
- await this.prepare(data);
25715
+ this.prepare(data);
26441
25716
  const printRanges = new Array(this.documentPaint.docPages.length).fill(0).map((item, index) => index).filter(index => index >= options.startDocIndex);
26442
25717
  let svgNodes = this.getSvgNodes(this.documentPaint.docPages, printRanges);
26443
25718
  if (!svgNodes.length) {
@@ -26462,8 +25737,8 @@ class DocumentPrintOffscreenBase {
26462
25737
  // }
26463
25738
  // return canvasNodes.map(node => node.toDataURL());
26464
25739
  // }
26465
- async getPrintNodes(data, ranges = null) {
26466
- await this.prepare(data);
25740
+ getPrintNodes(data, ranges = null) {
25741
+ this.prepare(data);
26467
25742
  const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
26468
25743
  return canvasNodes;
26469
25744
  }
@@ -26474,11 +25749,11 @@ class DocumentPrintOffscreenBase {
26474
25749
  * 读取数据,排版
26475
25750
  * @param data
26476
25751
  */
26477
- async prepare(data) {
25752
+ prepare(data) {
26478
25753
  //将doc的json格式数据读取转化为DocumentElement的树
26479
25754
  this.elementReader.read(data);
26480
25755
  this.documentPaint.rePages();
26481
- await Promise.all(this.docCtx.imageLoader.getLoadTasks());
25756
+ //await Promise.all(this.docCtx.imageLoader.getLoadTasks());
26482
25757
  const { scale, docPageSettings: { width, height } } = this.viewOptions;
26483
25758
  this.renderCtx.update({ scale, width, height });
26484
25759
  ElementUtil.setCanvasProps(this.renderCtx.mainContext.ctx.canvas, this.renderCtx.mainContext.ctx, {
@@ -26513,7 +25788,10 @@ class DocumentPrintOffscreenBase {
26513
25788
  // return canvasList;
26514
25789
  // }
26515
25790
  getSvgNodes(docRenders, printRanges = null) {
26516
- const docSvgHelper = new DocumentSvg(this.viewOptions, new Map(), this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
25791
+ const docSvgHelper = new DocumentSvg(this.viewOptions, {
25792
+ selectionEleSets: new Map,
25793
+ commRangeSets: new Map()
25794
+ }, this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
26517
25795
  docSvgHelper.mode = 'print';
26518
25796
  const patch = init([
26519
25797
  modules.class,
@@ -26557,31 +25835,6 @@ class DocumentPrintOffscreen extends DocumentPrintOffscreenBase {
26557
25835
  }
26558
25836
  }
26559
25837
 
26560
- let activeEditorContext = null;
26561
- function setActiveEditorContext(ctx) {
26562
- activeEditorContext = ctx;
26563
- }
26564
- function createSignal(state) {
26565
- let _state = state;
26566
- const activeCtx = activeEditorContext;
26567
- const signal = {
26568
- get value() {
26569
- return _state;
26570
- },
26571
- set value(v) {
26572
- if (v === _state) {
26573
- return;
26574
- }
26575
- _state = v;
26576
- signal.onChange();
26577
- },
26578
- onChange: () => {
26579
- activeCtx?.onChange();
26580
- }
26581
- };
26582
- return signal;
26583
- }
26584
-
26585
25838
  /**
26586
25839
  * 渲染日历虚拟节点处理类
26587
25840
  */
@@ -27450,6 +26703,8 @@ class DocEditor {
27450
26703
  onDestroy = new Subject$1();
27451
26704
  beforeNodePatch = new Subject$1();
27452
26705
  afterNodePatch = new Subject$1();
26706
+ //自定义事件传递消息
26707
+ eventBus;
27453
26708
  editInput;
27454
26709
  scrollContainer;
27455
26710
  constructor(svgContainer) {
@@ -27480,13 +26735,14 @@ class DocEditor {
27480
26735
  this.renderContext.init({ width: 500, height: 500, scale: 1 });
27481
26736
  this.selectionState = this.documentSelection.selectionState;
27482
26737
  this.selectionOverlays = new SelectionOverlays(this.documentSelection.selectionState);
27483
- this.documentPaint = new DocumentPaint(this.renderContext, this.docCtx, this.selectionOverlays.selectedSets);
26738
+ this.documentPaint = new DocumentPaint(this.renderContext, this.docCtx, this.selectionOverlays);
27484
26739
  this.documentInput = new DocumentInput(this.docCtx);
27485
26740
  this.docComment = new DocumentComment(this.docCtx);
27486
26741
  this.elementReader = new ElementReader(this.docCtx);
27487
26742
  this.documentChange = new DocumentChange(this.elementReader, this.docCtx, this.docComment, this.documentInput);
27488
26743
  this.documentEvent = new DocumentEvent(this.documentPaint, this.docCtx, this.documentInput);
27489
26744
  this.historyMange = new ElementTrackManage(this.docCtx, this.elementReader);
26745
+ this.eventBus = new EventBus();
27490
26746
  this.createPatch();
27491
26747
  this.documentEvent.hitInfoChanged.subscribe((hitInfo) => {
27492
26748
  this.hitInfoChanged(hitInfo);
@@ -28071,6 +27327,7 @@ class DocEditor {
28071
27327
  this.docCtx.destroy();
28072
27328
  this.documentEvent.clearSubEvent();
28073
27329
  this.selectionState.destroy();
27330
+ this.eventBus.clear();
28074
27331
  this.destroyDOM();
28075
27332
  this.flushTask = null;
28076
27333
  Object.keys(this).forEach(key => {
@@ -28584,7 +27841,7 @@ class DocEditor {
28584
27841
  this.tipContainer = tipsContainer;
28585
27842
  docContent.data.style.height = this.documentPaint.getDocumentContainerHeight().height + 'px';
28586
27843
  const docRenders = this.documentPaint.docContainer.getItems();
28587
- const svgGenerator = new DocumentSvg(this.viewOptions, this.selectionOverlays.selectedSets, this.renderContext);
27844
+ const svgGenerator = new DocumentSvg(this.viewOptions, this.selectionOverlays, this.renderContext);
28588
27845
  const vNode = svgGenerator.getHTMLVNode(docRenders);
28589
27846
  const children = docContent.children;
28590
27847
  children.push(tipsContainer);
@@ -28891,7 +28148,7 @@ class DocEditor {
28891
28148
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
28892
28149
  }
28893
28150
  version() {
28894
- return "2.1.18";
28151
+ return "2.1.20";
28895
28152
  }
28896
28153
  switchPageHeaderEditor() {
28897
28154
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -28899,7 +28156,10 @@ class DocEditor {
28899
28156
  getTextContent() {
28900
28157
  const paras = this.docCtx.document.treeFilter(item => item instanceof ParagraphElement);
28901
28158
  const paraTexts = paras.map(item => ElementSerialize.serializeString(item, { all: false }));
28902
- return paraTexts.join('\n');
28159
+ return paraTexts.join('');
28160
+ }
28161
+ emit(event, args) {
28162
+ this.eventBus.emit(event, args);
28903
28163
  }
28904
28164
  }
28905
28165
 
@@ -29172,8 +28432,6 @@ exports.DocumentFooterRenderObject = DocumentFooterRenderObject;
29172
28432
  exports.DocumentHeaderElement = DocumentHeaderElement;
29173
28433
  exports.DocumentHeaderFactory = DocumentHeaderFactory;
29174
28434
  exports.DocumentHeaderRenderObject = DocumentHeaderRenderObject;
29175
- exports.DocumentImagesBaseLoader = DocumentImagesBaseLoader;
29176
- exports.DocumentImagesLoader = DocumentImagesLoader;
29177
28435
  exports.DocumentInput = DocumentInput;
29178
28436
  exports.DocumentPaint = DocumentPaint;
29179
28437
  exports.DocumentPrintOffscreen = DocumentPrintOffscreen;
@@ -29191,6 +28449,7 @@ exports.ElementPaint = ElementPaint;
29191
28449
  exports.ElementReader = ElementReader;
29192
28450
  exports.ElementSerialize = ElementSerialize;
29193
28451
  exports.ElementUtil = ElementUtil;
28452
+ exports.EventBus = EventBus;
29194
28453
  exports.EventMap = EventMap;
29195
28454
  exports.EventSourceCore = EventSourceCore$1;
29196
28455
  exports.FillNullSpaceElement = FillNullSpaceElement;
@@ -29244,6 +28503,10 @@ exports.RenderContext = RenderContext;
29244
28503
  exports.RenderObject = RenderObject;
29245
28504
  exports.ResizeLeafRenderObject = ResizeLeafRenderObject;
29246
28505
  exports.RunElementFactory = RunElementFactory;
28506
+ exports.SVGElement = SVGElement;
28507
+ exports.SVGFactory = SVGFactory;
28508
+ exports.SVGProps = SVGProps;
28509
+ exports.SVGRenderObject = SVGRenderObject;
29247
28510
  exports.SelectionOverlays = SelectionOverlays;
29248
28511
  exports.SelectionRange = SelectionRange;
29249
28512
  exports.SelectionState = SelectionState;