@hailin-zheng/editor-core 1.0.9 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/doc-ruler.d.ts +51 -0
- package/{src/med_editor/doc-ruler.ts → lib/doc-ruler.js} +73 -100
- package/lib/doc-ruler.js.map +1 -0
- package/lib/framework/common-util.d.ts +63 -0
- package/lib/framework/common-util.js +178 -0
- package/lib/framework/common-util.js.map +1 -0
- package/lib/framework/document-change.d.ts +265 -0
- package/{src/med_editor/framework/document-change.ts → lib/framework/document-change.js} +257 -306
- package/lib/framework/document-change.js.map +1 -0
- package/lib/framework/document-combine.d.ts +24 -0
- package/{src/med_editor/framework/document-combine.ts → lib/framework/document-combine.js} +11 -15
- package/lib/framework/document-combine.js.map +1 -0
- package/lib/framework/document-comment.d.ts +46 -0
- package/{src/med_editor/framework/document-comment.ts → lib/framework/document-comment.js} +37 -52
- package/lib/framework/document-comment.js.map +1 -0
- package/lib/framework/document-context.d.ts +149 -0
- package/{src/med_editor/framework/document-context.ts → lib/framework/document-context.js} +101 -181
- package/lib/framework/document-context.js.map +1 -0
- package/lib/framework/document-eval-func.d.ts +18 -0
- package/{src/med_editor/framework/document-eval-func.ts → lib/framework/document-eval-func.js} +11 -16
- package/lib/framework/document-eval-func.js.map +1 -0
- package/lib/framework/document-event.d.ts +213 -0
- package/{src/med_editor/framework/document-event.ts → lib/framework/document-event.js} +216 -244
- package/lib/framework/document-event.js.map +1 -0
- package/lib/framework/document-history.d.ts +26 -0
- package/{src/med_editor/framework/document-history.ts → lib/framework/document-history.js} +14 -25
- package/lib/framework/document-history.js.map +1 -0
- package/lib/framework/document-images-loader.d.ts +16 -0
- package/{src/med_editor/framework/document-images-loader.ts → lib/framework/document-images-loader.js} +17 -25
- package/lib/framework/document-images-loader.js.map +1 -0
- package/lib/framework/document-input-cursor.d.ts +78 -0
- package/{src/med_editor/framework/document-input-cursor.ts → lib/framework/document-input-cursor.js} +71 -76
- package/lib/framework/document-input-cursor.js.map +1 -0
- package/lib/framework/document-paint.d.ts +34 -0
- package/{src/med_editor/framework/document-paint.ts → lib/framework/document-paint.js} +28 -35
- package/lib/framework/document-paint.js.map +1 -0
- package/lib/framework/document-print-offscreen.d.ts +38 -0
- package/{src/med_editor/framework/document-print-offscreen.ts → lib/framework/document-print-offscreen.js} +19 -25
- package/lib/framework/document-print-offscreen.js.map +1 -0
- package/lib/framework/document-print.d.ts +60 -0
- package/{src/med_editor/framework/document-print.ts → lib/framework/document-print.js} +41 -57
- package/lib/framework/document-print.js.map +1 -0
- package/lib/framework/document-segmenter.d.ts +2 -0
- package/lib/framework/document-segmenter.js +106 -0
- package/lib/framework/document-segmenter.js.map +1 -0
- package/lib/framework/document-selection.d.ts +89 -0
- package/{src/med_editor/framework/document-selection.ts → lib/framework/document-selection.js} +84 -115
- package/lib/framework/document-selection.js.map +1 -0
- package/lib/framework/document-template.d.ts +4 -0
- package/{src/med_editor/framework/document-template.ts → lib/framework/document-template.js} +3 -3
- package/lib/framework/document-template.js.map +1 -0
- package/lib/framework/document-textline-mode.d.ts +7 -0
- package/lib/framework/document-textline-mode.js +30 -0
- package/lib/framework/document-textline-mode.js.map +1 -0
- package/lib/framework/element-define.d.ts +319 -0
- package/{src/med_editor/framework/element-define.ts → lib/framework/element-define.js} +206 -301
- package/lib/framework/element-define.js.map +1 -0
- package/lib/framework/element-event-define.d.ts +98 -0
- package/lib/framework/element-event-define.js +108 -0
- package/lib/framework/element-event-define.js.map +1 -0
- package/lib/framework/element-measure.d.ts +97 -0
- package/{src/med_editor/framework/element-measure.ts → lib/framework/element-measure.js} +121 -143
- package/lib/framework/element-measure.js.map +1 -0
- package/lib/framework/element-paint.d.ts +42 -0
- package/{src/med_editor/framework/element-paint.ts → lib/framework/element-paint.js} +37 -43
- package/lib/framework/element-paint.js.map +1 -0
- package/lib/framework/element-props.d.ts +301 -0
- package/{src/med_editor/framework/element-props.ts → lib/framework/element-props.js} +202 -331
- package/lib/framework/element-props.js.map +1 -0
- package/lib/framework/element-reader.d.ts +19 -0
- package/{src/med_editor/framework/element-reader.ts → lib/framework/element-reader.js} +30 -38
- package/lib/framework/element-reader.js.map +1 -0
- package/lib/framework/element-render-cut.d.ts +55 -0
- package/{src/med_editor/framework/element-render-cut.ts → lib/framework/element-render-cut.js} +106 -113
- package/lib/framework/element-render-cut.js.map +1 -0
- package/lib/framework/element-serialize.d.ts +30 -0
- package/{src/med_editor/framework/element-serialize.ts → lib/framework/element-serialize.js} +24 -37
- package/lib/framework/element-serialize.js.map +1 -0
- package/lib/framework/element-util.d.ts +369 -0
- package/{src/med_editor/framework/element-util.ts → lib/framework/element-util.js} +216 -317
- package/lib/framework/element-util.js.map +1 -0
- package/lib/framework/impl/checkbox/checkbox-impl.d.ts +24 -0
- package/{src/med_editor/framework/impl/checkbox/checkbox-impl.ts → lib/framework/impl/checkbox/checkbox-impl.js} +18 -25
- package/lib/framework/impl/checkbox/checkbox-impl.js.map +1 -0
- package/lib/framework/impl/comments/comment-content-impl.d.ts +40 -0
- package/{src/med_editor/framework/impl/comments/comment-content-impl.ts → lib/framework/impl/comments/comment-content-impl.js} +31 -45
- package/lib/framework/impl/comments/comment-content-impl.js.map +1 -0
- package/lib/framework/impl/comments/comment-element-impl.d.ts +21 -0
- package/{src/med_editor/framework/impl/comments/comment-element-impl.ts → lib/framework/impl/comments/comment-element-impl.js} +18 -21
- package/lib/framework/impl/comments/comment-element-impl.js.map +1 -0
- package/lib/framework/impl/comments/comments-container-impl.d.ts +22 -0
- package/{src/med_editor/framework/impl/comments/comments-container-impl.ts → lib/framework/impl/comments/comments-container-impl.js} +15 -21
- package/lib/framework/impl/comments/comments-container-impl.js.map +1 -0
- package/lib/framework/impl/comments/comments-util.d.ts +12 -0
- package/{src/med_editor/framework/impl/comments/comments-util.ts → lib/framework/impl/comments/comments-util.js} +17 -34
- package/lib/framework/impl/comments/comments-util.js.map +1 -0
- package/lib/framework/impl/comments/validate-msg-impl.d.ts +21 -0
- package/{src/med_editor/framework/impl/comments/validate-msg-impl.ts → lib/framework/impl/comments/validate-msg-impl.js} +15 -26
- package/lib/framework/impl/comments/validate-msg-impl.js.map +1 -0
- package/lib/framework/impl/data-element/data-decorate-impl.d.ts +30 -0
- package/{src/med_editor/framework/impl/data-element/data-decorate-impl.ts → lib/framework/impl/data-element/data-decorate-impl.js} +21 -25
- package/lib/framework/impl/data-element/data-decorate-impl.js.map +1 -0
- package/lib/framework/impl/data-element/data-element-barcode.d.ts +31 -0
- package/{src/med_editor/framework/impl/data-element/data-element-barcode.ts → lib/framework/impl/data-element/data-element-barcode.js} +27 -39
- package/lib/framework/impl/data-element/data-element-barcode.js.map +1 -0
- package/lib/framework/impl/data-element/data-element-base-impl.d.ts +68 -0
- package/{src/med_editor/framework/impl/data-element/data-element-base-impl.ts → lib/framework/impl/data-element/data-element-base-impl.js} +44 -73
- package/lib/framework/impl/data-element/data-element-base-impl.js.map +1 -0
- package/lib/framework/impl/data-element/data-element-check-impl.d.ts +35 -0
- package/{src/med_editor/framework/impl/data-element/data-element-check-impl.ts → lib/framework/impl/data-element/data-element-check-impl.js} +33 -46
- package/lib/framework/impl/data-element/data-element-check-impl.js.map +1 -0
- package/lib/framework/impl/data-element/data-element-date-impl.d.ts +23 -0
- package/{src/med_editor/framework/impl/data-element/data-element-date-impl.ts → lib/framework/impl/data-element/data-element-date-impl.js} +22 -39
- package/lib/framework/impl/data-element/data-element-date-impl.js.map +1 -0
- package/lib/framework/impl/data-element/data-element-group-impl.d.ts +23 -0
- package/{src/med_editor/framework/impl/data-element/data-element-group-impl.ts → lib/framework/impl/data-element/data-element-group-impl.js} +29 -49
- package/lib/framework/impl/data-element/data-element-group-impl.js.map +1 -0
- package/lib/framework/impl/data-element/data-element-image-impl.d.ts +30 -0
- package/{src/med_editor/framework/impl/data-element/data-element-image-impl.ts → lib/framework/impl/data-element/data-element-image-impl.js} +26 -36
- package/lib/framework/impl/data-element/data-element-image-impl.js.map +1 -0
- package/lib/framework/impl/data-element/data-element-list-impl.d.ts +22 -0
- package/{src/med_editor/framework/impl/data-element/data-element-list-impl.ts → lib/framework/impl/data-element/data-element-list-impl.js} +30 -41
- package/lib/framework/impl/data-element/data-element-list-impl.js.map +1 -0
- package/lib/framework/impl/data-element/data-element-text-impl.d.ts +23 -0
- package/{src/med_editor/framework/impl/data-element/data-element-text-impl.ts → lib/framework/impl/data-element/data-element-text-impl.js} +20 -34
- package/lib/framework/impl/data-element/data-element-text-impl.js.map +1 -0
- package/lib/framework/impl/decorate/fill-null-space-imple.d.ts +21 -0
- package/{src/med_editor/framework/impl/decorate/fill-null-space-imple.ts → lib/framework/impl/decorate/fill-null-space-imple.js} +10 -15
- package/lib/framework/impl/decorate/fill-null-space-imple.js.map +1 -0
- package/lib/framework/impl/document/doc-body-impl.d.ts +27 -0
- package/{src/med_editor/framework/impl/document/doc-body-impl.ts → lib/framework/impl/document/doc-body-impl.js} +15 -31
- package/lib/framework/impl/document/doc-body-impl.js.map +1 -0
- package/lib/framework/impl/document/doc-body-part-impl.d.ts +30 -0
- package/{src/med_editor/framework/impl/document/doc-body-part-impl.ts → lib/framework/impl/document/doc-body-part-impl.js} +16 -26
- package/lib/framework/impl/document/doc-body-part-impl.js.map +1 -0
- package/lib/framework/impl/document/doc-container-impl.d.ts +16 -0
- package/lib/framework/impl/document/doc-container-impl.js +21 -0
- package/lib/framework/impl/document/doc-container-impl.js.map +1 -0
- package/lib/framework/impl/document/doc-footer-impl.d.ts +26 -0
- package/{src/med_editor/framework/impl/document/doc-footer-impl.ts → lib/framework/impl/document/doc-footer-impl.js} +18 -29
- package/lib/framework/impl/document/doc-footer-impl.js.map +1 -0
- package/lib/framework/impl/document/doc-header-impl.d.ts +26 -0
- package/{src/med_editor/framework/impl/document/doc-header-impl.ts → lib/framework/impl/document/doc-header-impl.js} +16 -33
- package/lib/framework/impl/document/doc-header-impl.js.map +1 -0
- package/lib/framework/impl/document/doc-impl.d.ts +61 -0
- package/{src/med_editor/framework/impl/document/doc-impl.ts → lib/framework/impl/document/doc-impl.js} +42 -59
- package/lib/framework/impl/document/doc-impl.js.map +1 -0
- package/lib/framework/impl/media-formula/menstrual-history.d.ts +35 -0
- package/{src/med_editor/framework/impl/media-formula/menstrual-history.ts → lib/framework/impl/media-formula/menstrual-history.js} +35 -57
- package/lib/framework/impl/media-formula/menstrual-history.js.map +1 -0
- package/lib/framework/impl/paragraph/p-impl.d.ts +45 -0
- package/{src/med_editor/framework/impl/paragraph/p-impl.ts → lib/framework/impl/paragraph/p-impl.js} +28 -62
- package/lib/framework/impl/paragraph/p-impl.js.map +1 -0
- package/lib/framework/impl/picture/image-impl.d.ts +31 -0
- package/{src/med_editor/framework/impl/picture/image-impl.ts → lib/framework/impl/picture/image-impl.js} +23 -35
- package/lib/framework/impl/picture/image-impl.js.map +1 -0
- package/lib/framework/impl/radio/radio-impl.d.ts +22 -0
- package/{src/med_editor/framework/impl/radio/radio-impl.ts → lib/framework/impl/radio/radio-impl.js} +19 -26
- package/lib/framework/impl/radio/radio-impl.js.map +1 -0
- package/lib/framework/impl/symbol/br-symbol-impl.d.ts +22 -0
- package/{src/med_editor/framework/impl/symbol/br-symbol-impl.ts → lib/framework/impl/symbol/br-symbol-impl.js} +14 -20
- package/lib/framework/impl/symbol/br-symbol-impl.js.map +1 -0
- package/lib/framework/impl/symbol/p-symbol-impl.d.ts +19 -0
- package/{src/med_editor/framework/impl/symbol/p-symbol-impl.ts → lib/framework/impl/symbol/p-symbol-impl.js} +11 -14
- package/lib/framework/impl/symbol/p-symbol-impl.js.map +1 -0
- package/lib/framework/impl/table/table-cell-impl.d.ts +37 -0
- package/{src/med_editor/framework/impl/table/table-cell-impl.ts → lib/framework/impl/table/table-cell-impl.js} +28 -39
- package/lib/framework/impl/table/table-cell-impl.js.map +1 -0
- package/lib/framework/impl/table/table-impl.d.ts +55 -0
- package/{src/med_editor/framework/impl/table/table-impl.ts → lib/framework/impl/table/table-impl.js} +82 -120
- package/lib/framework/impl/table/table-impl.js.map +1 -0
- package/lib/framework/impl/table/table-row-impl.d.ts +26 -0
- package/{src/med_editor/framework/impl/table/table-row-impl.ts → lib/framework/impl/table/table-row-impl.js} +16 -24
- package/lib/framework/impl/table/table-row-impl.js.map +1 -0
- package/lib/framework/impl/table/table-split-cell-patch.d.ts +20 -0
- package/{src/med_editor/framework/impl/table/table-split-cell-patch.ts → lib/framework/impl/table/table-split-cell-patch.js} +22 -31
- package/lib/framework/impl/table/table-split-cell-patch.js.map +1 -0
- package/lib/framework/impl/table/table-split-cell.d.ts +90 -0
- package/{src/med_editor/framework/impl/table/table-split-cell.ts → lib/framework/impl/table/table-split-cell.js} +94 -105
- package/lib/framework/impl/table/table-split-cell.js.map +1 -0
- package/lib/framework/impl/table/table-util.d.ts +150 -0
- package/{src/med_editor/framework/impl/table/table-util.ts → lib/framework/impl/table/table-util.js} +157 -195
- package/lib/framework/impl/table/table-util.js.map +1 -0
- package/lib/framework/impl/text/text-impl.d.ts +32 -0
- package/{src/med_editor/framework/impl/text/text-impl.ts → lib/framework/impl/text/text-impl.js} +32 -46
- package/lib/framework/impl/text/text-impl.js.map +1 -0
- package/lib/framework/impl/text/track-run-impl.d.ts +27 -0
- package/{src/med_editor/framework/impl/text/track-run-impl.ts → lib/framework/impl/text/track-run-impl.js} +28 -51
- package/lib/framework/impl/text/track-run-impl.js.map +1 -0
- package/lib/framework/notify.d.ts +13 -0
- package/{src/med_editor/framework/notify.ts → lib/framework/notify.js} +36 -50
- package/lib/framework/notify.js.map +1 -0
- package/lib/framework/range-util.d.ts +40 -0
- package/{src/med_editor/framework/range-util.ts → lib/framework/range-util.js} +71 -80
- package/lib/framework/range-util.js.map +1 -0
- package/lib/framework/render-context.d.ts +91 -0
- package/{src/med_editor/framework/render-context.ts → lib/framework/render-context.js} +64 -111
- package/lib/framework/render-context.js.map +1 -0
- package/lib/framework/render-define.d.ts +109 -0
- package/{src/med_editor/framework/render-define.ts → lib/framework/render-define.js} +61 -90
- package/lib/framework/render-define.js.map +1 -0
- package/lib/framework/selection-overlays.d.ts +30 -0
- package/{src/med_editor/framework/selection-overlays.ts → lib/framework/selection-overlays.js} +16 -25
- package/lib/framework/selection-overlays.js.map +1 -0
- package/lib/texteditor.d.ts +318 -0
- package/{src/med_editor/texteditor.ts → lib/texteditor.js} +189 -286
- package/lib/texteditor.js.map +1 -0
- package/lib/util/subject.d.ts +34 -0
- package/lib/util/subject.js +88 -0
- package/lib/util/subject.js.map +1 -0
- package/lib/util/table-bind.d.ts +5 -0
- package/{src/med_editor/util/table-bind.ts → lib/util/table-bind.js} +2 -2
- package/lib/util/table-bind.js.map +1 -0
- package/package.json +2 -2
- package/src/med_editor/framework/common-util.ts +0 -200
- package/src/med_editor/framework/document-segmenter.ts +0 -211
- package/src/med_editor/framework/document-textline-mode.ts +0 -34
- package/src/med_editor/framework/element-event-define.ts +0 -141
- package/src/med_editor/framework/impl/document/doc-container-impl.ts +0 -24
- package/src/med_editor/util/subject.ts +0 -118
- package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225.json +0 -3573
- package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225.json +0 -3573
- package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225bug.json +0 -315
- package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225/346/211/271/346/263/250.json +0 -122
- package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225/346/226/207/346/241/243/351/252/214/350/257/201.json +0 -3599
- package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225/351/225/277/346/226/207/346/234/254.json +0 -24586
- package/src/med_editor//345/220/210/345/271/266/347/227/205/347/250/213/345/275/225.json +0 -2874
- package/src/med_editor//346/211/213/346/234/257/350/256/260/345/275/225.json +0 -341
- package/src/med_editor//346/231/256/351/200/232doc/347/261/273/346/226/207/346/241/243.json +0 -2201
- package/src/med_editor//346/243/200/351/252/214/347/224/263/350/257/267/345/215/225.json +0 -1069
- package/src/med_editor//347/227/205/347/250/213/345/275/225//345/206/205/351/225/234/344/270/213/346/262/273/347/226/227/350/256/260/345/275/225.json +0 -125
- package/src/med_editor//347/227/205/347/250/213/345/275/225//345/220/210/345/271/266/347/227/205/347/250/213/345/275/225/346/250/241/346/235/277.json +0 -86
- package/src/med_editor//347/227/205/347/250/213/345/275/225//346/227/245/345/270/270/347/227/205/347/250/213/350/256/260/345/275/225.json +0 -115
- package/src/med_editor//347/227/205/347/250/213/345/275/225//346/237/245/346/210/277/350/256/260/345/275/2251.json +0 -108
- package/src/med_editor//347/227/205/347/250/213/345/275/225//351/246/226/346/254/241/344/270/212/347/272/247/345/214/273/345/270/210/346/237/245/346/210/277/350/256/260/345/275/225.json +0 -272
- package/src/med_editor//351/225/277/346/234/237/345/214/273/345/230/261/345/215/225.json +0 -1070
@@ -1,48 +1,22 @@
|
|
1
1
|
import { nanoid } from "nanoid";
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
BlockContainerElement,
|
5
|
-
BranchElement,
|
6
|
-
Element,
|
7
|
-
LeafElement,
|
8
|
-
Position,
|
9
|
-
Rect,
|
10
|
-
SelectionContentRange,
|
11
|
-
ViewOptions
|
12
|
-
} from "./element-define";
|
13
|
-
import { HitRegion } from "./element-event-define";
|
14
|
-
import { DataEleBaseProps, TextProps } from "./element-props";
|
2
|
+
import { BranchElement, LeafElement, Rect } from "./element-define";
|
3
|
+
import { TextProps } from "./element-props";
|
15
4
|
import { CommsContainerElement } from "./impl/comments/comments-container-impl";
|
16
|
-
import { DataElementInlineGroup} from "./impl/data-element/data-element-base-impl";
|
5
|
+
import { DataElementInlineGroup } from "./impl/data-element/data-element-base-impl";
|
17
6
|
import { DocumentBodyElement } from "./impl/document/doc-body-impl";
|
18
7
|
import { DocumentFooterElement } from "./impl/document/doc-footer-impl";
|
19
8
|
import { DocumentHeaderElement } from "./impl/document/doc-header-impl";
|
20
9
|
import { DocumentRenderObject } from "./impl/document/doc-impl";
|
21
10
|
import { ParagraphElement, ParagraphLineRectRenderObject, ParagraphRenderObject } from "./impl/paragraph/p-impl";
|
22
11
|
import { PSymbolElement } from "./impl/symbol/p-symbol-impl";
|
23
|
-
import { TableCellElement
|
24
|
-
import {
|
25
|
-
import {
|
12
|
+
import { TableCellElement } from "./impl/table/table-cell-impl";
|
13
|
+
import { TableRenderObject } from "./impl/table/table-impl";
|
14
|
+
import { TableRowRenderObject } from "./impl/table/table-row-impl";
|
26
15
|
import { TextGroupElement, TextGroupRenderObject } from "./impl/text/text-impl";
|
27
|
-
import { TrackRunElement
|
28
|
-
import {
|
29
|
-
BlockContainerRenderObject,
|
30
|
-
BlockContentRenderObject,
|
31
|
-
BorderType,
|
32
|
-
BranchRenderObject,
|
33
|
-
CursorType,
|
34
|
-
InlineGroupRenderObject,
|
35
|
-
LeafRenderObject,
|
36
|
-
RenderObject
|
37
|
-
} from "./render-define";
|
38
|
-
|
39
|
-
|
40
|
-
type PAIR = { x: number, y: number };
|
41
|
-
|
16
|
+
import { TrackRunElement } from "./impl/text/track-run-impl";
|
17
|
+
import { BranchRenderObject, LeafRenderObject } from "./render-define";
|
42
18
|
export class ElementUtil {
|
43
|
-
|
44
|
-
|
45
|
-
static setCanvasProps(canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D, viewOptions: { width: number, height: number }, scale: number = 1): void {
|
19
|
+
static setCanvasProps(canvas, ctx, viewOptions, scale = 1) {
|
46
20
|
// if (canvas instanceof OffscreenCanvas) {
|
47
21
|
// this.setOffscreenCanvas(canvas, ctx as OffscreenCanvasRenderingContext2D, viewOptions, scale);
|
48
22
|
// return
|
@@ -61,9 +35,7 @@ export class ElementUtil {
|
|
61
35
|
canvas.height = scaleHeight * dpr;
|
62
36
|
ctx.scale(dpr, dpr);
|
63
37
|
}
|
64
|
-
|
65
38
|
// static setOffscreenCanvas(canvas: OffscreenCanvas, ctx: OffscreenCanvasRenderingContext2D, viewOptions: { width: number, height: number }, scale: number = 1): void {
|
66
|
-
|
67
39
|
// const { width, height } = viewOptions;
|
68
40
|
// let dpr = window.devicePixelRatio || 1;
|
69
41
|
// if (scale > 1) {
|
@@ -76,17 +48,15 @@ export class ElementUtil {
|
|
76
48
|
// canvas.height = scaleHeight * dpr;
|
77
49
|
// ctx.scale(dpr, dpr);
|
78
50
|
// }
|
79
|
-
|
80
|
-
static getDprNumber(val: number, scale: number = 1): number {
|
51
|
+
static getDprNumber(val, scale = 1) {
|
81
52
|
let dpr = window.devicePixelRatio || 1;
|
82
53
|
if (scale > 1) {
|
83
54
|
dpr *= scale;
|
84
55
|
}
|
85
56
|
dpr = Math.ceil(dpr);
|
86
|
-
return Math.floor(val * dpr) / dpr
|
57
|
+
return Math.floor(val * dpr) / dpr;
|
87
58
|
}
|
88
|
-
|
89
|
-
static readTextProps(dest: TextProps | null, props: TextProps | undefined, options: ViewOptions): TextProps {
|
59
|
+
static readTextProps(dest, props, options) {
|
90
60
|
if (!props) {
|
91
61
|
return this.createTextProps(dest, options);
|
92
62
|
}
|
@@ -121,8 +91,7 @@ export class ElementUtil {
|
|
121
91
|
}
|
122
92
|
return textProps;
|
123
93
|
}
|
124
|
-
|
125
|
-
static readEleBaseProps(dest: DataEleBaseProps, props: DataEleBaseProps): DataEleBaseProps {
|
94
|
+
static readEleBaseProps(dest, props) {
|
126
95
|
dest.id = props.id ?? nanoid(5);
|
127
96
|
dest.name = props.name;
|
128
97
|
dest.caption = props.caption;
|
@@ -137,35 +106,32 @@ export class ElementUtil {
|
|
137
106
|
dest.type = props.type;
|
138
107
|
return dest;
|
139
108
|
}
|
140
|
-
|
141
109
|
/**
|
142
110
|
* 获取内容区域最大高度
|
143
111
|
* @param render
|
144
112
|
* @param renderHeight
|
145
113
|
* @returns
|
146
114
|
*/
|
147
|
-
static innerRectMaxHeight(render
|
115
|
+
static innerRectMaxHeight(render, renderHeight) {
|
148
116
|
const { padding } = render;
|
149
117
|
return renderHeight - padding.top - padding.bottom;
|
150
118
|
}
|
151
|
-
|
152
119
|
/**
|
153
120
|
* 根据内框内容高度,更新外框框体高度
|
154
121
|
* @param render
|
155
122
|
* @param innerRect
|
156
123
|
*/
|
157
|
-
static updateRenderHeightByInnerRect(render
|
124
|
+
static updateRenderHeightByInnerRect(render, innerRect) {
|
158
125
|
const { padding, margin } = render;
|
159
126
|
//外层容器高度等于内容高度+外边距+内边距
|
160
127
|
render.rect.height = innerRect.height + margin.top + margin.bottom + padding.top + padding.bottom;
|
161
128
|
}
|
162
|
-
|
163
129
|
/**
|
164
130
|
* 设置块级元素限制尺寸
|
165
131
|
* @param render
|
166
132
|
* @param parentLimitRect
|
167
133
|
*/
|
168
|
-
static setBlockElementLimitSize(render
|
134
|
+
static setBlockElementLimitSize(render, parentLimitRect) {
|
169
135
|
render.rect.x = parentLimitRect.x;
|
170
136
|
render.rect.y = parentLimitRect.y + parentLimitRect.height;
|
171
137
|
render.rect.width = parentLimitRect.maxWidth ?? 0;
|
@@ -174,13 +140,12 @@ export class ElementUtil {
|
|
174
140
|
render.rect.maxHeight = parentLimitRect.maxHeight - parentLimitRect.height;
|
175
141
|
}
|
176
142
|
}
|
177
|
-
|
178
143
|
/**
|
179
144
|
* 克隆框体
|
180
145
|
* @param rect
|
181
146
|
* @returns
|
182
147
|
*/
|
183
|
-
static cloneRect(rect
|
148
|
+
static cloneRect(rect) {
|
184
149
|
const cloneRect = new Rect();
|
185
150
|
cloneRect.x = rect.x;
|
186
151
|
cloneRect.y = rect.y;
|
@@ -190,14 +155,13 @@ export class ElementUtil {
|
|
190
155
|
cloneRect.maxWidth = rect.maxWidth;
|
191
156
|
return cloneRect;
|
192
157
|
}
|
193
|
-
|
194
158
|
/**
|
195
159
|
* 重新限定子元素以及当前高度值,并返回内边框内容高度
|
196
160
|
* @param render
|
197
161
|
* @param resetX 测量段落外框时,内框不需要重置x,因为内框已经存在对齐
|
198
162
|
* @returns
|
199
163
|
*/
|
200
|
-
static remeasure(render
|
164
|
+
static remeasure(render, resetX = true) {
|
201
165
|
if (render.rect.width === 0) {
|
202
166
|
return -1;
|
203
167
|
}
|
@@ -220,9 +184,8 @@ export class ElementUtil {
|
|
220
184
|
render.updateRenderHeight(innerRect);
|
221
185
|
return innerRect.height;
|
222
186
|
}
|
223
|
-
|
224
|
-
|
225
|
-
const rowEle = rowRender.element as TableRowElement;
|
187
|
+
static remeasureTableRow(rowRender, foreceColIndex = -1) {
|
188
|
+
const rowEle = rowRender.element;
|
226
189
|
const rowMinHeight = rowEle.props.minHeight > 19 ? rowEle.props.minHeight : 19;
|
227
190
|
let maxCellheight = rowMinHeight;
|
228
191
|
//限制行最小高度
|
@@ -230,15 +193,15 @@ export class ElementUtil {
|
|
230
193
|
//获取行内非纵向合并单元格的最高单元格高度
|
231
194
|
for (let i = 0; i < rowRender.length; i++) {
|
232
195
|
const cellRender = rowRender.getChild(i);
|
233
|
-
const { vMerge } =
|
196
|
+
const { vMerge } = cellRender.element.props;
|
234
197
|
if (cellRender.rect.height > maxCellheight && (vMerge !== 'restart' || i === foreceColIndex)) {
|
235
198
|
maxCellheight = cellRender.rect.height;
|
236
199
|
}
|
237
200
|
}
|
238
201
|
//循环设置单元格高度为行内最大单元格高度
|
239
202
|
for (let i = 0; i < rowRender.length; i++) {
|
240
|
-
const cellRender = rowRender.getChild(i)
|
241
|
-
const cellElement =
|
203
|
+
const cellRender = rowRender.getChild(i);
|
204
|
+
const cellElement = cellRender.element;
|
242
205
|
const { vMerge } = cellElement.props;
|
243
206
|
if ((vMerge !== 'restart' || i === foreceColIndex) || cellRender.rect.height < maxCellheight) {
|
244
207
|
cellRender.rect.height = maxCellheight;
|
@@ -250,46 +213,43 @@ export class ElementUtil {
|
|
250
213
|
rowRender.updateRenderHeight(maxCellheight);
|
251
214
|
return maxCellheight;
|
252
215
|
}
|
253
|
-
|
254
216
|
/**
|
255
217
|
* 获取表格行绘制元素的内容高度,用于缩放行高度时,获取最小内容高度,缩放的高度不能小于内容最小高度
|
256
218
|
*/
|
257
|
-
static getTableRowRenderContentHeight(rowRender
|
258
|
-
const rowEle = rowRender.element
|
219
|
+
static getTableRowRenderContentHeight(rowRender) {
|
220
|
+
const rowEle = rowRender.element;
|
259
221
|
let maxCellheight = 19;
|
260
222
|
//限制行最小高度
|
261
223
|
//获取行内非纵向合并单元格的最高单元格高度
|
262
224
|
for (let i = 0; i < rowRender.length; i++) {
|
263
|
-
const cellRender = rowRender.getChild(i)
|
225
|
+
const cellRender = rowRender.getChild(i);
|
264
226
|
const cellContentHeight = this.getTableCellRenderContentHeight(cellRender);
|
265
|
-
const { vMerge } =
|
227
|
+
const { vMerge } = cellRender.element.props;
|
266
228
|
if (cellContentHeight > maxCellheight && vMerge !== 'restart') {
|
267
229
|
maxCellheight = cellContentHeight;
|
268
230
|
}
|
269
231
|
}
|
270
232
|
return maxCellheight;
|
271
233
|
}
|
272
|
-
|
273
234
|
/**
|
274
235
|
* 获取单元格内容高度
|
275
236
|
* 单元格暂不处理上下margin、padding
|
276
237
|
* @param cellRender
|
277
238
|
* @returns
|
278
239
|
*/
|
279
|
-
static getTableCellRenderContentHeight(cellRender
|
240
|
+
static getTableCellRenderContentHeight(cellRender) {
|
280
241
|
let contentHeight = 0;
|
281
242
|
for (let i = 0; i < cellRender.length; i++) {
|
282
243
|
contentHeight += cellRender.getChild(i).rect.height;
|
283
244
|
}
|
284
245
|
return contentHeight;
|
285
246
|
}
|
286
|
-
|
287
247
|
/**
|
288
248
|
* 处理单元格内容纵向对齐
|
289
249
|
* @param render
|
290
250
|
*/
|
291
|
-
|
292
|
-
const tcElement = render.element
|
251
|
+
static measureCellVAlign(render) {
|
252
|
+
const tcElement = render.element;
|
293
253
|
const { vAlign } = tcElement.props;
|
294
254
|
if (!vAlign || vAlign === 'top') {
|
295
255
|
return;
|
@@ -299,7 +259,7 @@ export class ElementUtil {
|
|
299
259
|
sumHeight += render.getChild(i).rect.height;
|
300
260
|
}
|
301
261
|
let spaceHeight = 0;
|
302
|
-
spaceHeight = vAlign === 'middle' ? Math.floor((render.rect.height - sumHeight) / 2) : vAlign === 'bottom' ? render.rect.height - sumHeight : 0
|
262
|
+
spaceHeight = vAlign === 'middle' ? Math.floor((render.rect.height - sumHeight) / 2) : vAlign === 'bottom' ? render.rect.height - sumHeight : 0;
|
303
263
|
if (spaceHeight <= 0) {
|
304
264
|
return;
|
305
265
|
}
|
@@ -309,20 +269,19 @@ export class ElementUtil {
|
|
309
269
|
y += render.getChild(i).rect.height;
|
310
270
|
}
|
311
271
|
}
|
312
|
-
|
313
272
|
/**
|
314
273
|
* 重新测量合并单元格高度
|
315
274
|
* @param tbRender
|
316
275
|
* @returns
|
317
276
|
*/
|
318
|
-
static remeasureTableMerge(tbRender
|
277
|
+
static remeasureTableMerge(tbRender) {
|
319
278
|
//是否需要重新计算,主要解决:之前合并计算的列,可能会被后面合并计算的列所影响,需要再次重新计算测量
|
320
279
|
let needReCalc = false;
|
321
280
|
for (let i = 0; i < tbRender.length; i++) {
|
322
|
-
const row = tbRender.getChild(i)
|
281
|
+
const row = tbRender.getChild(i);
|
323
282
|
for (let j = 0; j < row.length; j++) {
|
324
|
-
const cellRender = row.getChild(j)
|
325
|
-
const ele = cellRender.element
|
283
|
+
const cellRender = row.getChild(j);
|
284
|
+
const ele = cellRender.element;
|
326
285
|
const { vMerge } = ele.props;
|
327
286
|
if (vMerge === 'restart') {
|
328
287
|
const eleIndex = ele.getIndex();
|
@@ -335,7 +294,7 @@ export class ElementUtil {
|
|
335
294
|
}
|
336
295
|
continue;
|
337
296
|
}
|
338
|
-
const continueCellHeight = continueRows.reduce((prev, curr) => prev + curr.rect.height, 0)
|
297
|
+
const continueCellHeight = continueRows.reduce((prev, curr) => prev + curr.rect.height, 0);
|
339
298
|
const overflowHeight = cellRender.rect.height - row.rect.height - continueCellHeight;
|
340
299
|
//溢出的高度加到最后一个合并单元格中
|
341
300
|
if (overflowHeight > 0) {
|
@@ -343,7 +302,8 @@ export class ElementUtil {
|
|
343
302
|
lastRow.rect.height += overflowHeight;
|
344
303
|
this.resizeCellToFillRow(lastRow);
|
345
304
|
needReCalc = true;
|
346
|
-
}
|
305
|
+
}
|
306
|
+
else {
|
347
307
|
cellRender.rect.height = row.rect.height + continueCellHeight;
|
348
308
|
}
|
349
309
|
}
|
@@ -354,7 +314,6 @@ export class ElementUtil {
|
|
354
314
|
return;
|
355
315
|
}
|
356
316
|
}
|
357
|
-
|
358
317
|
/**
|
359
318
|
* 获取向下纵向合并的行
|
360
319
|
* @param render
|
@@ -362,12 +321,12 @@ export class ElementUtil {
|
|
362
321
|
* @param colIndex
|
363
322
|
* @returns
|
364
323
|
*/
|
365
|
-
|
366
|
-
const rows
|
324
|
+
static getContinueVMergeRenderRows(render, rowIndex, colIndex) {
|
325
|
+
const rows = [];
|
367
326
|
for (let i = rowIndex + 1; i < render.length; i++) {
|
368
|
-
const rowRender = render.getChild(i)
|
369
|
-
const rowEle = rowRender.element
|
370
|
-
const ele = rowEle.getChild(colIndex)
|
327
|
+
const rowRender = render.getChild(i);
|
328
|
+
const rowEle = rowRender.element;
|
329
|
+
const ele = rowEle.getChild(colIndex);
|
371
330
|
const { vMerge } = ele.props;
|
372
331
|
if (vMerge !== 'continue') {
|
373
332
|
break;
|
@@ -376,41 +335,38 @@ export class ElementUtil {
|
|
376
335
|
}
|
377
336
|
return rows;
|
378
337
|
}
|
379
|
-
|
380
338
|
/**
|
381
339
|
* 根据横向当前被合并的单元格
|
382
340
|
* @param tb
|
383
341
|
* @param rowIndex
|
384
342
|
* @param colIndex
|
385
343
|
*/
|
386
|
-
static getHorizontalRestartCellIndex(tb
|
387
|
-
const row = tb.getChild(rowIndex)
|
344
|
+
static getHorizontalRestartCellIndex(tb, rowIndex, colIndex) {
|
345
|
+
const row = tb.getChild(rowIndex);
|
388
346
|
for (let i = colIndex - 1; i >= 0; i--) {
|
389
|
-
const cell = row.getChild(i)
|
347
|
+
const cell = row.getChild(i);
|
390
348
|
if (cell.props.hMerge === 'restart') {
|
391
349
|
return i;
|
392
350
|
}
|
393
351
|
}
|
394
352
|
throw new Error('未找到主合并单元格');
|
395
353
|
}
|
396
|
-
|
397
354
|
/**
|
398
355
|
* 根据横向当前被合并的单元格
|
399
356
|
* @param tb
|
400
357
|
* @param rowIndex
|
401
358
|
* @param colIndex
|
402
359
|
*/
|
403
|
-
static getVerticalRestartCellIndex(tb
|
360
|
+
static getVerticalRestartCellIndex(tb, rowIndex, colIndex) {
|
404
361
|
for (let i = rowIndex - 1; i >= 0; i--) {
|
405
|
-
const row = tb.getChild(i)
|
406
|
-
const cell = row.getChild(colIndex)
|
362
|
+
const row = tb.getChild(i);
|
363
|
+
const cell = row.getChild(colIndex);
|
407
364
|
if (cell.props.vMerge === 'restart') {
|
408
365
|
return i;
|
409
366
|
}
|
410
367
|
}
|
411
|
-
throw new Error('未找到横向当前被合并的单元格')
|
368
|
+
throw new Error('未找到横向当前被合并的单元格');
|
412
369
|
}
|
413
|
-
|
414
370
|
/**
|
415
371
|
* 获取合并单元格主单元格
|
416
372
|
* @param tb
|
@@ -418,9 +374,9 @@ export class ElementUtil {
|
|
418
374
|
* @param colIndex
|
419
375
|
* @returns
|
420
376
|
*/
|
421
|
-
static getRestartCellPosition(tb
|
422
|
-
const row = tb.getChild(rowIndex)
|
423
|
-
const cell = row.getChild(colIndex)
|
377
|
+
static getRestartCellPosition(tb, rowIndex, colIndex) {
|
378
|
+
const row = tb.getChild(rowIndex);
|
379
|
+
const cell = row.getChild(colIndex);
|
424
380
|
if (cell.props.hMerge === 'continue') {
|
425
381
|
const restartCellIndex = this.getHorizontalRestartCellIndex(tb, rowIndex, colIndex);
|
426
382
|
return this.getRestartCellPosition(tb, rowIndex, restartCellIndex);
|
@@ -429,26 +385,23 @@ export class ElementUtil {
|
|
429
385
|
const restartRowIndex = this.getVerticalRestartCellIndex(tb, rowIndex, colIndex);
|
430
386
|
return this.getRestartCellPosition(tb, restartRowIndex, colIndex);
|
431
387
|
}
|
432
|
-
return { rowIndex, colIndex }
|
388
|
+
return { rowIndex, colIndex };
|
433
389
|
}
|
434
|
-
|
435
390
|
/**
|
436
391
|
* 调整单元格高度填满整个行的高度
|
437
392
|
*/
|
438
|
-
|
393
|
+
static resizeCellToFillRow(row) {
|
439
394
|
for (let i = 0; i < row.length; i++) {
|
440
395
|
const cell = row.getChild(i);
|
441
396
|
cell.rect.height = row.rect.height;
|
442
397
|
}
|
443
398
|
}
|
444
|
-
|
445
|
-
|
446
399
|
/**
|
447
400
|
* 获取元素的全局索引位置
|
448
401
|
* @param control
|
449
402
|
* @returns
|
450
403
|
*/
|
451
|
-
static getControlIndex(control
|
404
|
+
static getControlIndex(control) {
|
452
405
|
const parent = control.parent;
|
453
406
|
if (parent) {
|
454
407
|
const index = control.getIndex();
|
@@ -458,25 +411,26 @@ export class ElementUtil {
|
|
458
411
|
counter += child.getSelfLength();
|
459
412
|
}
|
460
413
|
return counter + this.getControlIndex(parent);
|
461
|
-
}
|
414
|
+
}
|
415
|
+
else {
|
462
416
|
return 0;
|
463
417
|
}
|
464
418
|
}
|
465
|
-
|
466
419
|
/**
|
467
420
|
* 根据全局索引位置获取元素
|
468
421
|
* @param control
|
469
422
|
* @param counter
|
470
423
|
* @returns
|
471
424
|
*/
|
472
|
-
static getControlByIndex(control
|
425
|
+
static getControlByIndex(control, counter) {
|
473
426
|
counter.currIndex++;
|
474
427
|
if (counter.currIndex === counter.index) {
|
475
428
|
return control;
|
476
429
|
}
|
477
430
|
if (control instanceof LeafElement) {
|
478
431
|
return null;
|
479
|
-
}
|
432
|
+
}
|
433
|
+
else if (control instanceof BranchElement) {
|
480
434
|
for (let i = 0; i < control.length; i++) {
|
481
435
|
const res = this.getControlByIndex(control.getChild(i), counter);
|
482
436
|
if (res) {
|
@@ -486,13 +440,12 @@ export class ElementUtil {
|
|
486
440
|
}
|
487
441
|
return null;
|
488
442
|
}
|
489
|
-
|
490
443
|
/**
|
491
444
|
* 获取同级紧挨前方的兄弟元素
|
492
445
|
* @param element
|
493
446
|
* @returns
|
494
447
|
*/
|
495
|
-
static getPrevSiblingElement(element
|
448
|
+
static getPrevSiblingElement(element) {
|
496
449
|
const parent = element.parent;
|
497
450
|
if (!parent) {
|
498
451
|
return null;
|
@@ -505,13 +458,12 @@ export class ElementUtil {
|
|
505
458
|
}
|
506
459
|
return null;
|
507
460
|
}
|
508
|
-
|
509
461
|
/**
|
510
462
|
* 获取同级紧挨下方的元素
|
511
463
|
* @param element
|
512
464
|
* @returns
|
513
465
|
*/
|
514
|
-
static getNextSiblingElement(element
|
466
|
+
static getNextSiblingElement(element) {
|
515
467
|
const parent = element.parent;
|
516
468
|
if (!parent) {
|
517
469
|
return null;
|
@@ -519,13 +471,12 @@ export class ElementUtil {
|
|
519
471
|
if (parent) {
|
520
472
|
const index = parent.getChildIndex(element);
|
521
473
|
if (index < parent.length - 1) {
|
522
|
-
return parent.getChild(index + 1)
|
474
|
+
return parent.getChild(index + 1);
|
523
475
|
}
|
524
476
|
}
|
525
477
|
return null;
|
526
478
|
}
|
527
|
-
|
528
|
-
static getNextSiblingTrackElement(element: Element, type: TrackRunTypeEnum, userId: string): TrackRunElement | null {
|
479
|
+
static getNextSiblingTrackElement(element, type, userId) {
|
529
480
|
const nextSiblingEle = this.getNextSiblingElement(element);
|
530
481
|
if (nextSiblingEle instanceof TrackRunElement) {
|
531
482
|
if (nextSiblingEle.type === type && nextSiblingEle.props.userId === userId) {
|
@@ -534,8 +485,7 @@ export class ElementUtil {
|
|
534
485
|
}
|
535
486
|
return null;
|
536
487
|
}
|
537
|
-
|
538
|
-
static getPrevSiblingTrackElement(element: Element, type: TrackRunTypeEnum, userId: string): TrackRunElement | null {
|
488
|
+
static getPrevSiblingTrackElement(element, type, userId) {
|
539
489
|
const prevSiblingEle = this.getPrevSiblingElement(element);
|
540
490
|
if (prevSiblingEle instanceof TrackRunElement) {
|
541
491
|
if (prevSiblingEle.type === type && prevSiblingEle.props.userId === userId) {
|
@@ -544,36 +494,33 @@ export class ElementUtil {
|
|
544
494
|
}
|
545
495
|
return null;
|
546
496
|
}
|
547
|
-
|
548
497
|
/**
|
549
498
|
* 根据默认配置创建长文本
|
550
499
|
* @param viewOptions
|
551
500
|
* @returns
|
552
501
|
*/
|
553
|
-
static getNewTextGroup(textProps
|
554
|
-
const text = new TextGroupElement()
|
502
|
+
static getNewTextGroup(textProps) {
|
503
|
+
const text = new TextGroupElement();
|
555
504
|
textProps.clone(text.props);
|
556
505
|
return text;
|
557
506
|
}
|
558
|
-
|
559
|
-
static createTextProps(dest: TextProps | null, viewOptions: ViewOptions): TextProps {
|
507
|
+
static createTextProps(dest, viewOptions) {
|
560
508
|
const textProps = dest ?? new TextProps();
|
561
509
|
textProps.fontSize = viewOptions.defaultFontSize;
|
562
510
|
textProps.fontName = viewOptions.defaultFontName;
|
563
511
|
textProps.color = viewOptions.defaultColor;
|
564
512
|
return textProps;
|
565
513
|
}
|
566
|
-
|
567
514
|
/**
|
568
515
|
* 获取容器内的最小渲染元素集合
|
569
516
|
* @param parPos
|
570
517
|
* @param array
|
571
518
|
*/
|
572
|
-
static getAvailHitLeafRenderObjects(render
|
519
|
+
static getAvailHitLeafRenderObjects(render, parPos) {
|
573
520
|
if (!this.checkAvailHitRender(render)) {
|
574
521
|
return [];
|
575
522
|
}
|
576
|
-
const renderObjectRect
|
523
|
+
const renderObjectRect = {
|
577
524
|
x: parPos.x + render.rect.x,
|
578
525
|
y: parPos.y + render.rect.y,
|
579
526
|
width: render.rect.width,
|
@@ -581,52 +528,53 @@ export class ElementUtil {
|
|
581
528
|
maxWidth: 0,
|
582
529
|
maxHeight: 0
|
583
530
|
};
|
584
|
-
const array
|
531
|
+
const array = [];
|
585
532
|
if (render instanceof BranchRenderObject) {
|
586
533
|
for (let i = 0; i < render.length; i++) {
|
587
534
|
const child = render.getChild(i);
|
588
535
|
array.push(...this.getAvailHitLeafRenderObjects(child, { x: renderObjectRect.x, y: renderObjectRect.y }));
|
589
536
|
}
|
590
|
-
}
|
537
|
+
}
|
538
|
+
else if (render instanceof LeafRenderObject) {
|
591
539
|
array.push({ render: render, rect: renderObjectRect });
|
592
|
-
}
|
540
|
+
}
|
541
|
+
else {
|
593
542
|
throw new Error('未实现');
|
594
543
|
}
|
595
544
|
return array;
|
596
545
|
}
|
597
|
-
|
598
546
|
/**
|
599
547
|
* 获取容器内的最小渲染元素集合
|
600
548
|
* @param parPos
|
601
549
|
* @param array
|
602
550
|
*/
|
603
|
-
static getAvailHitRenderObjects(render
|
551
|
+
static getAvailHitRenderObjects(render, parPos) {
|
604
552
|
if (!this.checkAvailHitRender(render)) {
|
605
553
|
return [];
|
606
554
|
}
|
607
|
-
const renderObjectRect
|
608
|
-
const array
|
555
|
+
const renderObjectRect = this.getRenderObjectAbsoluteRect(render, parPos);
|
556
|
+
const array = [];
|
609
557
|
if (render instanceof BranchRenderObject) {
|
610
558
|
for (let i = 0; i < render.length; i++) {
|
611
559
|
const child = render.getChild(i);
|
612
560
|
if (this.checkAvailHitRender(child)) {
|
613
|
-
array.push({ render: child, rect: this.getRenderObjectAbsoluteRect(child, renderObjectRect) })
|
614
|
-
|
561
|
+
array.push({ render: child, rect: this.getRenderObjectAbsoluteRect(child, renderObjectRect) });
|
615
562
|
}
|
616
563
|
}
|
617
|
-
}
|
564
|
+
}
|
565
|
+
else if (render instanceof LeafRenderObject) {
|
618
566
|
array.push({ render: render, rect: renderObjectRect });
|
619
|
-
}
|
567
|
+
}
|
568
|
+
else {
|
620
569
|
throw new Error('未实现');
|
621
570
|
}
|
622
571
|
return array;
|
623
572
|
}
|
624
|
-
|
625
573
|
/**
|
626
574
|
* 获取绘制元素的绝对位置框
|
627
575
|
*/
|
628
|
-
static getRenderObjectAbsoluteRect(render
|
629
|
-
const renderObjectRect
|
576
|
+
static getRenderObjectAbsoluteRect(render, parPos) {
|
577
|
+
const renderObjectRect = {
|
630
578
|
x: parPos.x + render.rect.x,
|
631
579
|
y: parPos.y + render.rect.y,
|
632
580
|
width: render.rect.width,
|
@@ -636,29 +584,26 @@ export class ElementUtil {
|
|
636
584
|
};
|
637
585
|
return renderObjectRect;
|
638
586
|
}
|
639
|
-
|
640
|
-
|
641
587
|
/**
|
642
588
|
* 检查当前绘制元素是否属于有效点击元素
|
643
589
|
*/
|
644
|
-
static checkAvailHitRender(render
|
590
|
+
static checkAvailHitRender(render) {
|
645
591
|
if (render.element && render.element.disableClick) {
|
646
592
|
return false;
|
647
593
|
}
|
648
594
|
if (render instanceof TableRowRenderObject) {
|
649
|
-
const rowEle = render.element
|
595
|
+
const rowEle = render.element;
|
650
596
|
if (rowEle.props.headerRow) {
|
651
597
|
return rowEle.paintRenders.indexOf(render) === 0;
|
652
598
|
}
|
653
599
|
}
|
654
600
|
return !render.disableClick;
|
655
601
|
}
|
656
|
-
|
657
602
|
/**
|
658
603
|
* 验证点击可操作性
|
659
604
|
* 主要限制页眉页脚的编辑模式
|
660
605
|
*/
|
661
|
-
static verifyHitable(sourceElement
|
606
|
+
static verifyHitable(sourceElement) {
|
662
607
|
if (!sourceElement) {
|
663
608
|
return false;
|
664
609
|
}
|
@@ -671,15 +616,14 @@ export class ElementUtil {
|
|
671
616
|
}
|
672
617
|
return true;
|
673
618
|
}
|
674
|
-
|
675
619
|
/**
|
676
620
|
* 获取一个点到一个矩形最短的距离
|
677
621
|
* @param rect
|
678
622
|
* @param p
|
679
623
|
* @returns
|
680
624
|
*/
|
681
|
-
static getDistanceToRect(rect
|
682
|
-
const lines
|
625
|
+
static getDistanceToRect(rect, p) {
|
626
|
+
const lines = [];
|
683
627
|
lines.push({
|
684
628
|
f: {
|
685
629
|
x: rect.x,
|
@@ -716,33 +660,28 @@ export class ElementUtil {
|
|
716
660
|
x: rect.x + rect.width,
|
717
661
|
y: rect.y + rect.height
|
718
662
|
}
|
719
|
-
})
|
720
|
-
const distances = lines.map(item => this.minDistance(item.f, item.s, p))
|
663
|
+
});
|
664
|
+
const distances = lines.map(item => this.minDistance(item.f, item.s, p));
|
721
665
|
return Math.min(...distances);
|
722
666
|
}
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
const
|
727
|
-
|
728
|
-
const BE: PAIR = { x: E.x - B.x, y: E.y - B.y };
|
729
|
-
|
730
|
-
const AE: PAIR = { x: E.x - A.x, y: E.y - A.y }
|
731
|
-
|
667
|
+
static minDistance(A, B, E) {
|
668
|
+
const AB = { x: B.x - A.x, y: B.y - A.y };
|
669
|
+
const BE = { x: E.x - B.x, y: E.y - B.y };
|
670
|
+
const AE = { x: E.x - A.x, y: E.y - A.y };
|
732
671
|
const AB_BE = (AB.x * BE.x + AB.y * BE.y);
|
733
672
|
const AB_AE = (AB.x * AE.x + AB.y * AE.y);
|
734
|
-
|
735
673
|
let reqAns = 0;
|
736
|
-
|
737
674
|
if (AB_BE > 0) {
|
738
675
|
const y = E.y - B.y;
|
739
676
|
const x = E.x - B.x;
|
740
677
|
reqAns = Math.sqrt(x * x + y * y);
|
741
|
-
}
|
678
|
+
}
|
679
|
+
else if (AB_AE < 0) {
|
742
680
|
const y = E.y - A.y;
|
743
681
|
const x = E.x - A.x;
|
744
682
|
reqAns = Math.sqrt(x * x + y * y);
|
745
|
-
}
|
683
|
+
}
|
684
|
+
else {
|
746
685
|
const x1 = AB.x;
|
747
686
|
const y1 = AB.y;
|
748
687
|
const x2 = AE.x;
|
@@ -752,71 +691,70 @@ export class ElementUtil {
|
|
752
691
|
}
|
753
692
|
return reqAns;
|
754
693
|
}
|
755
|
-
|
756
694
|
/**
|
757
695
|
* 获取父级层级渲染对象
|
758
696
|
* @param render
|
759
697
|
* @returns
|
760
698
|
*/
|
761
|
-
static getParentRenders(render
|
699
|
+
static getParentRenders(render) {
|
762
700
|
if (render) {
|
763
701
|
return [render, ...this.getParentRenders(render.parent)];
|
764
|
-
}
|
702
|
+
}
|
703
|
+
else {
|
765
704
|
return [];
|
766
705
|
}
|
767
706
|
}
|
768
|
-
|
769
|
-
static getRenderMapElements(render: RenderObject): Array<Element> {
|
707
|
+
static getRenderMapElements(render) {
|
770
708
|
const renders = this.getParentRenders(render);
|
771
709
|
return renders.map(render => render.element).filter(ele => ele);
|
772
710
|
}
|
773
|
-
|
774
|
-
static getParentRender<T extends BranchRenderObject>(child: RenderObject, parentType: { new(...args: any): T }): T | null {
|
711
|
+
static getParentRender(child, parentType) {
|
775
712
|
if (!child) {
|
776
713
|
return null;
|
777
714
|
}
|
778
715
|
if (child instanceof parentType) {
|
779
716
|
return child;
|
780
|
-
}
|
717
|
+
}
|
718
|
+
else {
|
781
719
|
return this.getParentRender(child.parent, parentType);
|
782
720
|
}
|
783
721
|
}
|
784
|
-
|
785
|
-
static getParentRenderByPredicate(child: RenderObject, predicate: (item: RenderObject) => boolean): RenderObject | null {
|
722
|
+
static getParentRenderByPredicate(child, predicate) {
|
786
723
|
if (!child) {
|
787
724
|
return null;
|
788
725
|
}
|
789
726
|
if (predicate(child)) {
|
790
727
|
return child;
|
791
|
-
}
|
728
|
+
}
|
729
|
+
else {
|
792
730
|
return this.getParentRenderByPredicate(child.parent, predicate);
|
793
731
|
}
|
794
732
|
}
|
795
|
-
|
796
733
|
/**
|
797
734
|
* 获取父级层级元素对象
|
798
735
|
* @param element
|
799
736
|
* @returns
|
800
737
|
*/
|
801
|
-
static getParentElements(element
|
738
|
+
static getParentElements(element) {
|
802
739
|
if (element) {
|
803
740
|
return [element, ...this.getParentElements(element.parent)];
|
804
|
-
}
|
741
|
+
}
|
742
|
+
else {
|
805
743
|
return [];
|
806
744
|
}
|
807
745
|
}
|
808
|
-
|
809
746
|
/**
|
810
747
|
* 获取最后一个子元素
|
811
748
|
* @param element
|
812
749
|
* @returns
|
813
750
|
*/
|
814
|
-
static getLastLeafElement(element
|
751
|
+
static getLastLeafElement(element, predicate = null) {
|
815
752
|
if (element instanceof LeafElement && (!predicate || predicate(element))) {
|
816
753
|
return element;
|
817
|
-
}
|
754
|
+
}
|
755
|
+
else if (element instanceof BranchElement) {
|
818
756
|
for (let i = element.length - 1; i >= 0; i--) {
|
819
|
-
const res = this.getLastLeafElement(element.getChild(i), predicate)
|
757
|
+
const res = this.getLastLeafElement(element.getChild(i), predicate);
|
820
758
|
if (res) {
|
821
759
|
return res;
|
822
760
|
}
|
@@ -825,17 +763,16 @@ export class ElementUtil {
|
|
825
763
|
}
|
826
764
|
return null;
|
827
765
|
}
|
828
|
-
|
829
|
-
|
830
766
|
/**
|
831
767
|
* 获取第一个子元素
|
832
768
|
* @param element
|
833
769
|
* @returns
|
834
770
|
*/
|
835
|
-
static getFirstLeafElement(element
|
771
|
+
static getFirstLeafElement(element) {
|
836
772
|
if (element instanceof LeafElement) {
|
837
773
|
return element;
|
838
|
-
}
|
774
|
+
}
|
775
|
+
else if (element instanceof BranchElement) {
|
839
776
|
for (let i = 0; i < element.length; i++) {
|
840
777
|
const res = this.getFirstLeafElement(element.getChild(i));
|
841
778
|
if (res) {
|
@@ -846,19 +783,17 @@ export class ElementUtil {
|
|
846
783
|
}
|
847
784
|
return null;
|
848
785
|
}
|
849
|
-
|
850
786
|
/**
|
851
787
|
* 校验两个元素是否在同一个段落中
|
852
788
|
* @param element1
|
853
789
|
* @param element2
|
854
790
|
*/
|
855
|
-
static isInSameParagraph(element1
|
791
|
+
static isInSameParagraph(element1, element2) {
|
856
792
|
const par1 = this.getParentByType(element1, ParagraphElement);
|
857
793
|
const par2 = this.getParentByType(element2, ParagraphElement);
|
858
794
|
return par1 === par2;
|
859
795
|
}
|
860
|
-
|
861
|
-
static getBorderCursor(borderType: BorderType): CursorType {
|
796
|
+
static getBorderCursor(borderType) {
|
862
797
|
switch (borderType) {
|
863
798
|
case 'none':
|
864
799
|
return 'text';
|
@@ -869,7 +804,7 @@ export class ElementUtil {
|
|
869
804
|
case 'right':
|
870
805
|
return 'col-resize';
|
871
806
|
case 'bottom':
|
872
|
-
return 'row-resize'
|
807
|
+
return 'row-resize';
|
873
808
|
case 'left-middle':
|
874
809
|
case 'right-middle':
|
875
810
|
return 'w-resize';
|
@@ -886,40 +821,38 @@ export class ElementUtil {
|
|
886
821
|
return 'text';
|
887
822
|
}
|
888
823
|
}
|
889
|
-
|
890
|
-
static getParentByType<P extends Element, T>(child: P | null, parentType: { new(...args: any): T }): T | null {
|
824
|
+
static getParentByType(child, parentType) {
|
891
825
|
if (!child) {
|
892
826
|
return null;
|
893
827
|
}
|
894
828
|
if (child instanceof parentType) {
|
895
829
|
return child;
|
896
|
-
}
|
830
|
+
}
|
831
|
+
else {
|
897
832
|
return this.getParentByType(child.parent, parentType);
|
898
833
|
}
|
899
834
|
}
|
900
|
-
|
901
|
-
static getParent(child: Element | null, predicate: (item: Element) => boolean): Element | null {
|
835
|
+
static getParent(child, predicate) {
|
902
836
|
if (!child) {
|
903
837
|
return null;
|
904
838
|
}
|
905
839
|
if (predicate(child)) {
|
906
840
|
return child;
|
907
|
-
}
|
841
|
+
}
|
842
|
+
else {
|
908
843
|
return this.getParent(child.parent, predicate);
|
909
844
|
}
|
910
845
|
}
|
911
|
-
|
912
|
-
|
913
846
|
/**
|
914
847
|
* 修正段落内容
|
915
848
|
* @returns
|
916
849
|
*/
|
917
|
-
static fixParagraphContent(control
|
850
|
+
static fixParagraphContent(control) {
|
918
851
|
//如果最后一个元素不是段落符号,则补足
|
919
852
|
if (!(control.getChild(control.length - 1) instanceof PSymbolElement)) {
|
920
853
|
control.addChild(new PSymbolElement());
|
921
854
|
}
|
922
|
-
const items
|
855
|
+
const items = [];
|
923
856
|
for (let i = 0; i < control.length - 1; i++) {
|
924
857
|
const child = control.getChild(i);
|
925
858
|
if (child instanceof PSymbolElement) {
|
@@ -927,15 +860,14 @@ export class ElementUtil {
|
|
927
860
|
}
|
928
861
|
}
|
929
862
|
items.forEach(item => {
|
930
|
-
control.removeChild(item)
|
863
|
+
control.removeChild(item);
|
931
864
|
});
|
932
865
|
}
|
933
|
-
|
934
866
|
/**
|
935
867
|
* 修正块级容器内容
|
936
868
|
* @param control
|
937
869
|
*/
|
938
|
-
static fixBlockContainer(control
|
870
|
+
static fixBlockContainer(control) {
|
939
871
|
if (control.length === 0) {
|
940
872
|
if (control instanceof TableCellElement && (control.props.vMerge === 'continue' || control.props.hMerge === 'continue')) {
|
941
873
|
return;
|
@@ -946,8 +878,6 @@ export class ElementUtil {
|
|
946
878
|
control.addChild(new ParagraphElement());
|
947
879
|
}
|
948
880
|
}
|
949
|
-
|
950
|
-
|
951
881
|
/**
|
952
882
|
* 获取绘制元素相对于整个画布的绝对位置
|
953
883
|
* 整个画布绘制的时候不一定从x=0,y=0时绘制的,下拉滚动时,上面从负y坐标开始绘制
|
@@ -956,58 +886,51 @@ export class ElementUtil {
|
|
956
886
|
* @param refPos 参照位置
|
957
887
|
* @returns
|
958
888
|
*/
|
959
|
-
static getRenderAbsolutePaintPos(render
|
889
|
+
static getRenderAbsolutePaintPos(render, refPos = null) {
|
960
890
|
refPos = refPos ?? { x: 0, y: 0 };
|
961
|
-
const currPos
|
891
|
+
const currPos = { x: render.rect.x + refPos.x, y: render.rect.y + refPos.y };
|
962
892
|
if (!render.parent) {
|
963
893
|
return currPos;
|
964
894
|
}
|
965
895
|
return this.getRenderAbsolutePaintPos(render.parent, currPos);
|
966
896
|
}
|
967
|
-
|
968
|
-
static getRenderAbsolutePaintRect(render: RenderObject, childPos: Position | null = null): Rect {
|
897
|
+
static getRenderAbsolutePaintRect(render, childPos = null) {
|
969
898
|
const pos = this.getRenderAbsolutePaintPos(render, childPos);
|
970
899
|
return { ...pos, width: render.rect.width, height: render.rect.height, maxWidth: 0, maxHeight: 0 };
|
971
900
|
}
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
901
|
/**
|
978
902
|
* 获取选中区域的开始区域
|
979
903
|
* @param range
|
980
904
|
* @returns
|
981
905
|
*/
|
982
|
-
static getFirstSelectedRange(range
|
906
|
+
static getFirstSelectedRange(range) {
|
983
907
|
if (range.selectedChildren.length === 0 || range.target instanceof TextGroupElement) {
|
984
908
|
return range;
|
985
|
-
}
|
909
|
+
}
|
910
|
+
else {
|
986
911
|
return this.getFirstSelectedRange(range.selectedChildren[0]);
|
987
912
|
}
|
988
913
|
}
|
989
|
-
|
990
914
|
/**
|
991
915
|
* 获取选中区域的开始区域
|
992
916
|
* @param range \
|
993
917
|
* @returns
|
994
918
|
*/
|
995
|
-
static getLastSelectedRange(range
|
919
|
+
static getLastSelectedRange(range) {
|
996
920
|
if (range.selectedChildren.length === 0 || range.target instanceof TextGroupElement) {
|
997
921
|
return range;
|
998
|
-
}
|
922
|
+
}
|
923
|
+
else {
|
999
924
|
return this.getLastSelectedRange(range.selectedChildren[range.selectedChildren.length - 1]);
|
1000
925
|
}
|
1001
926
|
}
|
1002
|
-
|
1003
|
-
|
1004
927
|
/**
|
1005
928
|
* 克隆选区内容
|
1006
929
|
* @param range
|
1007
930
|
* @param isDelete
|
1008
931
|
* @returns
|
1009
932
|
*/
|
1010
|
-
static cloneRange(range
|
933
|
+
static cloneRange(range, isDelete, cloneMode = 'clone') {
|
1011
934
|
const { target, isFullSelected, startOffset, endOffset, selectedChildren } = range;
|
1012
935
|
if (isFullSelected) {
|
1013
936
|
//修饰元素不能复制 审阅标记、数据元NullText
|
@@ -1019,7 +942,8 @@ export class ElementUtil {
|
|
1019
942
|
target.remove();
|
1020
943
|
}
|
1021
944
|
return clone;
|
1022
|
-
}
|
945
|
+
}
|
946
|
+
else {
|
1023
947
|
if (target instanceof LeafElement) {
|
1024
948
|
if (target instanceof TextGroupElement && startOffset !== endOffset) {
|
1025
949
|
if (isDelete) {
|
@@ -1028,14 +952,16 @@ export class ElementUtil {
|
|
1028
952
|
target.remove();
|
1029
953
|
}
|
1030
954
|
return copyTarget;
|
1031
|
-
}
|
955
|
+
}
|
956
|
+
else {
|
1032
957
|
const copyTarget = target.spliceText(startOffset, endOffset, false);
|
1033
958
|
return copyTarget;
|
1034
959
|
}
|
1035
960
|
}
|
1036
961
|
return null;
|
1037
|
-
}
|
1038
|
-
|
962
|
+
}
|
963
|
+
else if (target instanceof BranchElement) {
|
964
|
+
const array = [];
|
1039
965
|
for (let i = 0; i < selectedChildren.length; i++) {
|
1040
966
|
const copyChild = this.cloneRange(selectedChildren[i], isDelete, cloneMode);
|
1041
967
|
if (copyChild) {
|
@@ -1044,10 +970,11 @@ export class ElementUtil {
|
|
1044
970
|
}
|
1045
971
|
if (!array.length) {
|
1046
972
|
return null;
|
1047
|
-
}
|
1048
|
-
|
973
|
+
}
|
974
|
+
else {
|
975
|
+
const copyTarget = target.clone(false);
|
1049
976
|
array.forEach(item => {
|
1050
|
-
copyTarget.addChild(item)
|
977
|
+
copyTarget.addChild(item);
|
1051
978
|
});
|
1052
979
|
return copyTarget;
|
1053
980
|
}
|
@@ -1055,20 +982,18 @@ export class ElementUtil {
|
|
1055
982
|
}
|
1056
983
|
return null;
|
1057
984
|
}
|
1058
|
-
|
1059
985
|
/**
|
1060
986
|
* 获取所有的子级元素
|
1061
987
|
* @param branchEle
|
1062
988
|
* @returns
|
1063
989
|
*/
|
1064
|
-
static getChildrenElements(branchEle
|
990
|
+
static getChildrenElements(branchEle) {
|
1065
991
|
const array = [];
|
1066
992
|
for (let i = 0; i < branchEle.length; i++) {
|
1067
993
|
array.push(branchEle.getChild(i));
|
1068
994
|
}
|
1069
995
|
return array;
|
1070
996
|
}
|
1071
|
-
|
1072
997
|
/**
|
1073
998
|
* 递归向前寻找最近的元素
|
1074
999
|
* @param currElement
|
@@ -1076,7 +1001,7 @@ export class ElementUtil {
|
|
1076
1001
|
* @param forCursor 查找结果是否用于光标定位
|
1077
1002
|
* @returns
|
1078
1003
|
*/
|
1079
|
-
static getRecursionPrevSiblingElement(currElement
|
1004
|
+
static getRecursionPrevSiblingElement(currElement, inPara = false, forCursor = false) {
|
1080
1005
|
const parent = currElement?.parent;
|
1081
1006
|
//删除留痕块的measureRender在不显示留痕模式下,不生成render
|
1082
1007
|
if (!currElement || !parent || (!currElement.measureRender && !(currElement instanceof TrackRunElement))) {
|
@@ -1095,8 +1020,9 @@ export class ElementUtil {
|
|
1095
1020
|
return null;
|
1096
1021
|
}
|
1097
1022
|
return this.getRecursionPrevSiblingElement(parent, inPara, forCursor);
|
1098
|
-
}
|
1099
|
-
|
1023
|
+
}
|
1024
|
+
else {
|
1025
|
+
let prevElement = null;
|
1100
1026
|
for (let i = index - 1; i >= 0; i--) {
|
1101
1027
|
prevElement = parent.getChild(i);
|
1102
1028
|
if (prevElement && !prevElement.disableClick) {
|
@@ -1113,19 +1039,18 @@ export class ElementUtil {
|
|
1113
1039
|
}
|
1114
1040
|
if (lastLeafElement) {
|
1115
1041
|
return lastLeafElement;
|
1116
|
-
}
|
1042
|
+
}
|
1043
|
+
else {
|
1117
1044
|
return this.getRecursionPrevSiblingElement(prevElement.parent, inPara, forCursor);
|
1118
1045
|
}
|
1119
1046
|
}
|
1120
1047
|
}
|
1121
|
-
|
1122
|
-
|
1123
1048
|
/**
|
1124
1049
|
* 循环向前寻找可定位的数据元
|
1125
|
-
* @param currElement
|
1050
|
+
* @param currElement
|
1126
1051
|
*/
|
1127
|
-
static getPrevDataElement(ctx
|
1128
|
-
const dataEle = ctx.getCurrentCtx(currElement).getControlInstanceList().filter(item => item instanceof DataElementInlineGroup)
|
1052
|
+
static getPrevDataElement(ctx, currElement) {
|
1053
|
+
const dataEle = ctx.getCurrentCtx(currElement).getControlInstanceList().filter(item => item instanceof DataElementInlineGroup);
|
1129
1054
|
const index = dataEle.indexOf(currElement);
|
1130
1055
|
if (index > 0) {
|
1131
1056
|
for (let i = index - 1; i >= 0; i--) {
|
@@ -1136,7 +1061,6 @@ export class ElementUtil {
|
|
1136
1061
|
}
|
1137
1062
|
return null;
|
1138
1063
|
}
|
1139
|
-
|
1140
1064
|
// /**
|
1141
1065
|
// * 递归向前寻找最近的可点击元素
|
1142
1066
|
// */
|
@@ -1147,7 +1071,6 @@ export class ElementUtil {
|
|
1147
1071
|
// } while (ele && ele.disableClick)
|
1148
1072
|
// return ele;
|
1149
1073
|
// }
|
1150
|
-
|
1151
1074
|
// /**
|
1152
1075
|
// * 在同一段落中,递归向前寻找最近的元素
|
1153
1076
|
// */
|
@@ -1172,7 +1095,6 @@ export class ElementUtil {
|
|
1172
1095
|
// }
|
1173
1096
|
// }
|
1174
1097
|
// }
|
1175
|
-
|
1176
1098
|
// /**
|
1177
1099
|
// * 在同一段落中,递归向前寻找最近的可点击元素
|
1178
1100
|
// */
|
@@ -1183,12 +1105,10 @@ export class ElementUtil {
|
|
1183
1105
|
// } while (ele && ele.disableClick)
|
1184
1106
|
// return ele;
|
1185
1107
|
// }
|
1186
|
-
|
1187
|
-
|
1188
1108
|
/**
|
1189
1109
|
* 递归向后寻找最近的元素
|
1190
1110
|
*/
|
1191
|
-
static getRecursionNextSiblingElement(currElement
|
1111
|
+
static getRecursionNextSiblingElement(currElement, inPara = false, forCursor = false) {
|
1192
1112
|
const parent = currElement?.parent;
|
1193
1113
|
if (!currElement || !parent || !currElement.measureRender) {
|
1194
1114
|
return null;
|
@@ -1206,8 +1126,9 @@ export class ElementUtil {
|
|
1206
1126
|
return null;
|
1207
1127
|
}
|
1208
1128
|
return this.getRecursionNextSiblingElement(parent, inPara, forCursor);
|
1209
|
-
}
|
1210
|
-
|
1129
|
+
}
|
1130
|
+
else {
|
1131
|
+
let nextElement = null;
|
1211
1132
|
for (let i = index + 1; i < parent.length; i++) {
|
1212
1133
|
nextElement = parent.getChild(i);
|
1213
1134
|
if (nextElement && !nextElement.disableClick) {
|
@@ -1224,13 +1145,12 @@ export class ElementUtil {
|
|
1224
1145
|
}
|
1225
1146
|
if (lastLeafElement) {
|
1226
1147
|
return lastLeafElement;
|
1227
|
-
}
|
1148
|
+
}
|
1149
|
+
else {
|
1228
1150
|
return this.getRecursionNextSiblingElement(nextElement.parent, inPara, forCursor);
|
1229
1151
|
}
|
1230
1152
|
}
|
1231
1153
|
}
|
1232
|
-
|
1233
|
-
|
1234
1154
|
// /**
|
1235
1155
|
// * 在同一段落中,递归向后寻找最近的元素
|
1236
1156
|
// */
|
@@ -1255,7 +1175,6 @@ export class ElementUtil {
|
|
1255
1175
|
// }
|
1256
1176
|
// }
|
1257
1177
|
// }
|
1258
|
-
|
1259
1178
|
// /**
|
1260
1179
|
// * 在同一段落中,递归向后寻找最近的可点击元素
|
1261
1180
|
// */
|
@@ -1266,7 +1185,6 @@ export class ElementUtil {
|
|
1266
1185
|
// } while (ele && ele.disableClick)
|
1267
1186
|
// return ele;
|
1268
1187
|
// }
|
1269
|
-
|
1270
1188
|
// /**
|
1271
1189
|
// * 在同一段落中,递归向后寻找最近的可点击元素
|
1272
1190
|
// */
|
@@ -1277,13 +1195,12 @@ export class ElementUtil {
|
|
1277
1195
|
// } while (ele && ele.disableClick)
|
1278
1196
|
// return ele;
|
1279
1197
|
// }
|
1280
|
-
|
1281
1198
|
/**
|
1282
1199
|
* 获取行内最大渲染单元格高度,主要处理纵向合并单元格问题
|
1283
1200
|
* @param row
|
1284
1201
|
* @returns
|
1285
1202
|
*/
|
1286
|
-
static getRowMaxCellHeight(row
|
1203
|
+
static getRowMaxCellHeight(row) {
|
1287
1204
|
let maxHeight = 0;
|
1288
1205
|
for (let i = 0; i < row.length; i++) {
|
1289
1206
|
if (row.getChild(i).rect.height > maxHeight) {
|
@@ -1292,29 +1209,26 @@ export class ElementUtil {
|
|
1292
1209
|
}
|
1293
1210
|
return maxHeight;
|
1294
1211
|
}
|
1295
|
-
|
1296
|
-
|
1297
1212
|
/**
|
1298
1213
|
* 校验是否为空内容
|
1299
1214
|
* @param ele
|
1300
1215
|
*/
|
1301
|
-
static checkEmptyContent(ele
|
1216
|
+
static checkEmptyContent(ele) {
|
1302
1217
|
if (ele.length === 1) {
|
1303
1218
|
const firstRender = ele.getChild(0);
|
1304
1219
|
if (firstRender instanceof ParagraphRenderObject) {
|
1305
|
-
if ((
|
1220
|
+
if ((firstRender.element).length === 1) {
|
1306
1221
|
return true;
|
1307
1222
|
}
|
1308
1223
|
}
|
1309
1224
|
}
|
1310
1225
|
return false;
|
1311
1226
|
}
|
1312
|
-
|
1313
1227
|
/**
|
1314
1228
|
* 测量行内编组元素
|
1315
1229
|
* @param render
|
1316
1230
|
*/
|
1317
|
-
static remeasureInlineGroupRender(render
|
1231
|
+
static remeasureInlineGroupRender(render) {
|
1318
1232
|
let x = 0;
|
1319
1233
|
let maxHeight = 0;
|
1320
1234
|
for (let i = 0; i < render.length; i++) {
|
@@ -1332,37 +1246,34 @@ export class ElementUtil {
|
|
1332
1246
|
render.rect.width = x;
|
1333
1247
|
render.rect.height = maxHeight;
|
1334
1248
|
}
|
1335
|
-
|
1336
|
-
static getParaLinePos(childRender: RenderObject, childRenderPos: Position): Rect {
|
1249
|
+
static getParaLinePos(childRender, childRenderPos) {
|
1337
1250
|
const parent = childRender.parent;
|
1338
1251
|
const rect = ElementUtil.cloneRect(parent.rect);
|
1339
1252
|
rect.x = childRenderPos.x - childRender.rect.x;
|
1340
1253
|
rect.y = childRenderPos.y - childRender.rect.y;
|
1341
1254
|
if (parent instanceof ParagraphLineRectRenderObject) {
|
1342
1255
|
return rect;
|
1343
|
-
}
|
1256
|
+
}
|
1257
|
+
else {
|
1344
1258
|
return this.getParaLinePos(parent, rect);
|
1345
1259
|
}
|
1346
1260
|
}
|
1347
|
-
|
1348
|
-
|
1349
|
-
static getParentRenderPos(parentRender: RenderObject, childRender: RenderObject, childRenderPos: Position): Rect {
|
1261
|
+
static getParentRenderPos(parentRender, childRender, childRenderPos) {
|
1350
1262
|
const parent = childRender.parent;
|
1351
1263
|
const rect = ElementUtil.cloneRect(parent.rect);
|
1352
1264
|
rect.x = childRenderPos.x - childRender.rect.x;
|
1353
1265
|
rect.y = childRenderPos.y - childRender.rect.y;
|
1354
1266
|
if (parent === parentRender) {
|
1355
1267
|
return rect;
|
1356
|
-
}
|
1268
|
+
}
|
1269
|
+
else {
|
1357
1270
|
return this.getParentRenderPos(parentRender, parent, rect);
|
1358
1271
|
}
|
1359
1272
|
}
|
1360
|
-
|
1361
|
-
|
1362
1273
|
/**
|
1363
1274
|
* 获取绘制元素所在的区域
|
1364
1275
|
*/
|
1365
|
-
static getRenderObjectRegion(render
|
1276
|
+
static getRenderObjectRegion(render) {
|
1366
1277
|
if (!render) {
|
1367
1278
|
return undefined;
|
1368
1279
|
}
|
@@ -1371,18 +1282,16 @@ export class ElementUtil {
|
|
1371
1282
|
}
|
1372
1283
|
return this.getRenderObjectRegion(render.parent);
|
1373
1284
|
}
|
1374
|
-
|
1375
1285
|
/**
|
1376
1286
|
* 获取文档元素所在的区域
|
1377
1287
|
* @param element
|
1378
1288
|
* @returns
|
1379
1289
|
*/
|
1380
|
-
static getElementRegion(element
|
1290
|
+
static getElementRegion(element) {
|
1381
1291
|
const regionTarget = this.getElementRegionTarget(element);
|
1382
1292
|
return regionTarget?.type;
|
1383
1293
|
}
|
1384
|
-
|
1385
|
-
static getElementRegionTarget(element: Element | null): { type: HitRegion, target: BranchElement } | null {
|
1294
|
+
static getElementRegionTarget(element) {
|
1386
1295
|
if (!element) {
|
1387
1296
|
return null;
|
1388
1297
|
}
|
@@ -1396,30 +1305,30 @@ export class ElementUtil {
|
|
1396
1305
|
return { type: 'header', target: element };
|
1397
1306
|
}
|
1398
1307
|
if (element instanceof CommsContainerElement) {
|
1399
|
-
return { type: 'review', target: element }
|
1308
|
+
return { type: 'review', target: element };
|
1400
1309
|
}
|
1401
1310
|
return this.getElementRegionTarget(element.parent);
|
1402
1311
|
}
|
1403
|
-
|
1404
1312
|
/**
|
1405
1313
|
* 根据坐标系统偏移位获取所在的文本偏移位置
|
1406
1314
|
* @param textRender
|
1407
1315
|
* @param x
|
1408
1316
|
* @returns
|
1409
1317
|
*/
|
1410
|
-
static getTextRenderOffset(textRender
|
1411
|
-
const ele = textRender.element
|
1318
|
+
static getTextRenderOffset(textRender, x) {
|
1319
|
+
const ele = textRender.element;
|
1412
1320
|
const docRender = ElementUtil.getParentRender(textRender, DocumentRenderObject);
|
1413
1321
|
if (!docRender) {
|
1414
|
-
throw new Error('docRender is null')
|
1322
|
+
throw new Error('docRender is null');
|
1415
1323
|
}
|
1416
1324
|
const elePaintRenders = ele.paintRenders.filter(item => ElementUtil.getParentRender(item, DocumentRenderObject) === docRender);
|
1417
1325
|
let count = 0;
|
1418
1326
|
for (let i = 0; i < elePaintRenders.length; i++) {
|
1419
|
-
const render = elePaintRenders[i]
|
1327
|
+
const render = elePaintRenders[i];
|
1420
1328
|
if (render !== textRender) {
|
1421
1329
|
count += render.textMeasures.length;
|
1422
|
-
}
|
1330
|
+
}
|
1331
|
+
else {
|
1423
1332
|
let horX = 0;
|
1424
1333
|
for (let j = 0; j < render.textMeasures.length; j++) {
|
1425
1334
|
if (horX + render.textMeasures[j].actualSize >= x) {
|
@@ -1427,7 +1336,8 @@ export class ElementUtil {
|
|
1427
1336
|
if (j === 0 && i > 0) {
|
1428
1337
|
j += 0.5;
|
1429
1338
|
}
|
1430
|
-
}
|
1339
|
+
}
|
1340
|
+
else {
|
1431
1341
|
j += 1;
|
1432
1342
|
}
|
1433
1343
|
return j + count;
|
@@ -1439,28 +1349,28 @@ export class ElementUtil {
|
|
1439
1349
|
}
|
1440
1350
|
throw new Error('未找到当前文本元素的光标偏移量');
|
1441
1351
|
}
|
1442
|
-
|
1443
|
-
static getHitRenderOffset(render: LeafRenderObject, x: number): number {
|
1352
|
+
static getHitRenderOffset(render, x) {
|
1444
1353
|
if (render instanceof TextGroupRenderObject) {
|
1445
1354
|
return this.getTextRenderOffset(render, x);
|
1446
|
-
}
|
1355
|
+
}
|
1356
|
+
else {
|
1447
1357
|
if (render.element && render.element.type === 'psym') {
|
1448
1358
|
return 0;
|
1449
1359
|
}
|
1450
1360
|
return (render.rect.width / 2) >= x ? 0 : 1;
|
1451
1361
|
}
|
1452
1362
|
}
|
1453
|
-
|
1454
|
-
|
1455
|
-
const textEle = currRender.element as TextGroupElement;
|
1363
|
+
static getTextRenderHorX(currRender, startOffset, endOffset) {
|
1364
|
+
const textEle = currRender.element;
|
1456
1365
|
let endX = 0;
|
1457
1366
|
let startX = 0;
|
1458
1367
|
let count = 0;
|
1459
1368
|
for (let i = 0; i < textEle.paintRenders.length; i++) {
|
1460
|
-
const paintRender = textEle.paintRenders[i]
|
1369
|
+
const paintRender = textEle.paintRenders[i];
|
1461
1370
|
if (paintRender !== currRender) {
|
1462
1371
|
count += paintRender.textMeasures.length;
|
1463
|
-
}
|
1372
|
+
}
|
1373
|
+
else {
|
1464
1374
|
if (count + paintRender.textMeasures.length < startOffset) {
|
1465
1375
|
continue;
|
1466
1376
|
}
|
@@ -1480,59 +1390,54 @@ export class ElementUtil {
|
|
1480
1390
|
}
|
1481
1391
|
return { startX, endX };
|
1482
1392
|
}
|
1483
|
-
|
1484
1393
|
/**
|
1485
1394
|
* 获取一个元素结尾偏移量
|
1486
1395
|
* 文本以字符长度进行确定
|
1487
1396
|
* @param ele
|
1488
1397
|
* @returns
|
1489
1398
|
*/
|
1490
|
-
static getElementEndOffset(ele
|
1399
|
+
static getElementEndOffset(ele) {
|
1491
1400
|
if (ele instanceof TextGroupElement) {
|
1492
1401
|
return ele.textMeasures.length;
|
1493
1402
|
}
|
1494
1403
|
return 1;
|
1495
1404
|
}
|
1496
|
-
|
1497
1405
|
/**
|
1498
1406
|
* 判断当前偏移量是否是最终偏移量
|
1499
1407
|
* @param ele
|
1500
1408
|
* @param offset
|
1501
1409
|
*/
|
1502
|
-
static isElementEndOffset(ele
|
1410
|
+
static isElementEndOffset(ele, offset) {
|
1503
1411
|
return this.getElementEndOffset(ele) === offset;
|
1504
1412
|
}
|
1505
|
-
|
1506
1413
|
/**
|
1507
1414
|
* 获取直接子节点的所有渲染元素
|
1508
1415
|
* @param ele
|
1509
1416
|
* @returns
|
1510
1417
|
*/
|
1511
|
-
static getChildRenders
|
1512
|
-
const items
|
1418
|
+
static getChildRenders(ele) {
|
1419
|
+
const items = [];
|
1513
1420
|
for (let i = 0; i < ele.length; i++) {
|
1514
|
-
items.push(ele.getChild(i)
|
1421
|
+
items.push(ele.getChild(i));
|
1515
1422
|
}
|
1516
1423
|
return items;
|
1517
1424
|
}
|
1518
|
-
|
1519
1425
|
/**
|
1520
1426
|
* 获取当前单元格内所有的段落行
|
1521
1427
|
* @param cell
|
1522
1428
|
* @returns
|
1523
1429
|
*/
|
1524
|
-
static getCellParaLines(cell
|
1525
|
-
const items
|
1430
|
+
static getCellParaLines(cell) {
|
1431
|
+
const items = [];
|
1526
1432
|
for (let i = 0; i < cell.length; i++) {
|
1527
|
-
const para = cell.getChild(i)
|
1433
|
+
const para = cell.getChild(i);
|
1528
1434
|
for (let j = 0; j < para.length; j++) {
|
1529
|
-
items.push(para.getChild(j)
|
1435
|
+
items.push(para.getChild(j));
|
1530
1436
|
}
|
1531
1437
|
}
|
1532
1438
|
return items;
|
1533
1439
|
}
|
1534
|
-
|
1535
|
-
static getRandomColor(seed: number) {
|
1440
|
+
static getRandomColor(seed) {
|
1536
1441
|
let letters = '0123456789ABCDEF';
|
1537
1442
|
let color = '#';
|
1538
1443
|
for (let i = 0; i < 6; i++) {
|
@@ -1540,14 +1445,10 @@ export class ElementUtil {
|
|
1540
1445
|
}
|
1541
1446
|
return color;
|
1542
1447
|
}
|
1543
|
-
|
1544
|
-
|
1545
|
-
static getSeedRandom(seed: number): number {
|
1448
|
+
static getSeedRandom(seed) {
|
1546
1449
|
return Number("0." + Math.sin(seed * Math.random()).toString().substr(6));
|
1547
1450
|
}
|
1548
|
-
|
1549
|
-
|
1550
|
-
static findChildRender(render: BranchRenderObject, predicate: (child: RenderObject) => boolean): RenderObject | null {
|
1451
|
+
static findChildRender(render, predicate) {
|
1551
1452
|
for (let i = 0; i < render.length; i++) {
|
1552
1453
|
if (predicate(render.getChild(i))) {
|
1553
1454
|
return render.getChild(i);
|
@@ -1555,10 +1456,8 @@ export class ElementUtil {
|
|
1555
1456
|
}
|
1556
1457
|
return null;
|
1557
1458
|
}
|
1558
|
-
|
1559
|
-
|
1560
|
-
static getDataElement(ele: Element): DataElementInlineGroup {
|
1561
|
-
return this.getParent(ele, item => item instanceof DataElementInlineGroup) as DataElementInlineGroup;
|
1459
|
+
static getDataElement(ele) {
|
1460
|
+
return this.getParent(ele, item => item instanceof DataElementInlineGroup);
|
1562
1461
|
}
|
1563
1462
|
}
|
1564
|
-
|
1463
|
+
//# sourceMappingURL=element-util.js.map
|