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