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