@hailin-zheng/editor-core 1.0.3 → 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/package.json +6 -2
- package/dist/doc-ruler.d.ts +0 -51
- package/dist/doc-ruler.js +0 -313
- package/dist/doc-ruler.js.map +0 -1
- package/dist/framework/common-util.d.ts +0 -63
- package/dist/framework/common-util.js +0 -178
- package/dist/framework/common-util.js.map +0 -1
- package/dist/framework/document-change.d.ts +0 -265
- package/dist/framework/document-change.js +0 -1342
- package/dist/framework/document-change.js.map +0 -1
- package/dist/framework/document-combine.d.ts +0 -24
- package/dist/framework/document-combine.js +0 -40
- package/dist/framework/document-combine.js.map +0 -1
- package/dist/framework/document-comment.d.ts +0 -46
- package/dist/framework/document-comment.js +0 -148
- package/dist/framework/document-comment.js.map +0 -1
- package/dist/framework/document-context.d.ts +0 -149
- package/dist/framework/document-context.js +0 -330
- package/dist/framework/document-context.js.map +0 -1
- package/dist/framework/document-eval-func.d.ts +0 -18
- package/dist/framework/document-eval-func.js +0 -48
- package/dist/framework/document-eval-func.js.map +0 -1
- package/dist/framework/document-event.d.ts +0 -213
- package/dist/framework/document-event.js +0 -1054
- package/dist/framework/document-event.js.map +0 -1
- package/dist/framework/document-history.d.ts +0 -26
- package/dist/framework/document-history.js +0 -65
- package/dist/framework/document-history.js.map +0 -1
- package/dist/framework/document-images-loader.d.ts +0 -16
- package/dist/framework/document-images-loader.js +0 -66
- package/dist/framework/document-images-loader.js.map +0 -1
- package/dist/framework/document-input-cursor.d.ts +0 -78
- package/dist/framework/document-input-cursor.js +0 -239
- package/dist/framework/document-input-cursor.js.map +0 -1
- package/dist/framework/document-paint.d.ts +0 -34
- package/dist/framework/document-paint.js +0 -103
- package/dist/framework/document-paint.js.map +0 -1
- package/dist/framework/document-print-offscreen.d.ts +0 -38
- package/dist/framework/document-print-offscreen.js +0 -128
- package/dist/framework/document-print-offscreen.js.map +0 -1
- package/dist/framework/document-print.d.ts +0 -60
- package/dist/framework/document-print.js +0 -203
- package/dist/framework/document-print.js.map +0 -1
- package/dist/framework/document-segmenter.d.ts +0 -2
- package/dist/framework/document-segmenter.js +0 -106
- package/dist/framework/document-segmenter.js.map +0 -1
- package/dist/framework/document-selection.d.ts +0 -89
- package/dist/framework/document-selection.js +0 -358
- package/dist/framework/document-selection.js.map +0 -1
- package/dist/framework/document-template.d.ts +0 -4
- package/dist/framework/document-template.js +0 -20
- package/dist/framework/document-template.js.map +0 -1
- package/dist/framework/document-textline-mode.d.ts +0 -7
- package/dist/framework/document-textline-mode.js +0 -30
- package/dist/framework/document-textline-mode.js.map +0 -1
- package/dist/framework/element-define.d.ts +0 -319
- package/dist/framework/element-define.js +0 -579
- package/dist/framework/element-define.js.map +0 -1
- package/dist/framework/element-event-define.d.ts +0 -99
- package/dist/framework/element-event-define.js +0 -108
- package/dist/framework/element-event-define.js.map +0 -1
- package/dist/framework/element-measure.d.ts +0 -97
- package/dist/framework/element-measure.js +0 -551
- package/dist/framework/element-measure.js.map +0 -1
- package/dist/framework/element-paint.d.ts +0 -42
- package/dist/framework/element-paint.js +0 -170
- package/dist/framework/element-paint.js.map +0 -1
- package/dist/framework/element-props.d.ts +0 -301
- package/dist/framework/element-props.js +0 -809
- package/dist/framework/element-props.js.map +0 -1
- package/dist/framework/element-reader.d.ts +0 -19
- package/dist/framework/element-reader.js +0 -151
- package/dist/framework/element-reader.js.map +0 -1
- package/dist/framework/element-render-cut.d.ts +0 -55
- package/dist/framework/element-render-cut.js +0 -449
- package/dist/framework/element-render-cut.js.map +0 -1
- package/dist/framework/element-serialize.d.ts +0 -30
- package/dist/framework/element-serialize.js +0 -113
- package/dist/framework/element-serialize.js.map +0 -1
- package/dist/framework/element-util.d.ts +0 -369
- package/dist/framework/element-util.js +0 -1463
- package/dist/framework/element-util.js.map +0 -1
- package/dist/framework/impl/checkbox/checkbox-impl.d.ts +0 -24
- package/dist/framework/impl/checkbox/checkbox-impl.js +0 -64
- package/dist/framework/impl/checkbox/checkbox-impl.js.map +0 -1
- package/dist/framework/impl/comments/comment-content-impl.d.ts +0 -40
- package/dist/framework/impl/comments/comment-content-impl.js +0 -105
- package/dist/framework/impl/comments/comment-content-impl.js.map +0 -1
- package/dist/framework/impl/comments/comment-element-impl.d.ts +0 -21
- package/dist/framework/impl/comments/comment-element-impl.js +0 -62
- package/dist/framework/impl/comments/comment-element-impl.js.map +0 -1
- package/dist/framework/impl/comments/comments-container-impl.d.ts +0 -22
- package/dist/framework/impl/comments/comments-container-impl.js +0 -62
- package/dist/framework/impl/comments/comments-container-impl.js.map +0 -1
- package/dist/framework/impl/comments/comments-util.d.ts +0 -12
- package/dist/framework/impl/comments/comments-util.js +0 -67
- package/dist/framework/impl/comments/comments-util.js.map +0 -1
- package/dist/framework/impl/comments/validate-msg-impl.d.ts +0 -21
- package/dist/framework/impl/comments/validate-msg-impl.js +0 -83
- package/dist/framework/impl/comments/validate-msg-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-decorate-impl.d.ts +0 -30
- package/dist/framework/impl/data-element/data-decorate-impl.js +0 -91
- package/dist/framework/impl/data-element/data-decorate-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-barcode.d.ts +0 -31
- package/dist/framework/impl/data-element/data-element-barcode.js +0 -115
- package/dist/framework/impl/data-element/data-element-barcode.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-base-impl.d.ts +0 -68
- package/dist/framework/impl/data-element/data-element-base-impl.js +0 -205
- package/dist/framework/impl/data-element/data-element-base-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-check-impl.d.ts +0 -35
- package/dist/framework/impl/data-element/data-element-check-impl.js +0 -133
- package/dist/framework/impl/data-element/data-element-check-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-date-impl.d.ts +0 -23
- package/dist/framework/impl/data-element/data-element-date-impl.js +0 -111
- package/dist/framework/impl/data-element/data-element-date-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-group-impl.d.ts +0 -23
- package/dist/framework/impl/data-element/data-element-group-impl.js +0 -130
- package/dist/framework/impl/data-element/data-element-group-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-image-impl.d.ts +0 -30
- package/dist/framework/impl/data-element/data-element-image-impl.js +0 -137
- package/dist/framework/impl/data-element/data-element-image-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-list-impl.d.ts +0 -22
- package/dist/framework/impl/data-element/data-element-list-impl.js +0 -131
- package/dist/framework/impl/data-element/data-element-list-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-text-impl.d.ts +0 -23
- package/dist/framework/impl/data-element/data-element-text-impl.js +0 -103
- package/dist/framework/impl/data-element/data-element-text-impl.js.map +0 -1
- package/dist/framework/impl/decorate/fill-null-space-imple.d.ts +0 -21
- package/dist/framework/impl/decorate/fill-null-space-imple.js +0 -43
- package/dist/framework/impl/decorate/fill-null-space-imple.js.map +0 -1
- package/dist/framework/impl/document/doc-body-impl.d.ts +0 -27
- package/dist/framework/impl/document/doc-body-impl.js +0 -79
- package/dist/framework/impl/document/doc-body-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-body-part-impl.d.ts +0 -30
- package/dist/framework/impl/document/doc-body-part-impl.js +0 -94
- package/dist/framework/impl/document/doc-body-part-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-container-impl.d.ts +0 -16
- package/dist/framework/impl/document/doc-container-impl.js +0 -21
- package/dist/framework/impl/document/doc-container-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-footer-impl.d.ts +0 -26
- package/dist/framework/impl/document/doc-footer-impl.js +0 -77
- package/dist/framework/impl/document/doc-footer-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-header-impl.d.ts +0 -26
- package/dist/framework/impl/document/doc-header-impl.js +0 -83
- package/dist/framework/impl/document/doc-header-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-impl.d.ts +0 -61
- package/dist/framework/impl/document/doc-impl.js +0 -209
- package/dist/framework/impl/document/doc-impl.js.map +0 -1
- package/dist/framework/impl/media-formula/menstrual-history.d.ts +0 -35
- package/dist/framework/impl/media-formula/menstrual-history.js +0 -153
- package/dist/framework/impl/media-formula/menstrual-history.js.map +0 -1
- package/dist/framework/impl/paragraph/p-impl.d.ts +0 -45
- package/dist/framework/impl/paragraph/p-impl.js +0 -156
- package/dist/framework/impl/paragraph/p-impl.js.map +0 -1
- package/dist/framework/impl/picture/image-impl.d.ts +0 -31
- package/dist/framework/impl/picture/image-impl.js +0 -124
- package/dist/framework/impl/picture/image-impl.js.map +0 -1
- package/dist/framework/impl/radio/radio-impl.d.ts +0 -22
- package/dist/framework/impl/radio/radio-impl.js +0 -72
- package/dist/framework/impl/radio/radio-impl.js.map +0 -1
- package/dist/framework/impl/symbol/br-symbol-impl.d.ts +0 -22
- package/dist/framework/impl/symbol/br-symbol-impl.js +0 -54
- package/dist/framework/impl/symbol/br-symbol-impl.js.map +0 -1
- package/dist/framework/impl/symbol/p-symbol-impl.d.ts +0 -19
- package/dist/framework/impl/symbol/p-symbol-impl.js +0 -54
- package/dist/framework/impl/symbol/p-symbol-impl.js.map +0 -1
- package/dist/framework/impl/table/table-cell-impl.d.ts +0 -37
- package/dist/framework/impl/table/table-cell-impl.js +0 -145
- package/dist/framework/impl/table/table-cell-impl.js.map +0 -1
- package/dist/framework/impl/table/table-impl.d.ts +0 -55
- package/dist/framework/impl/table/table-impl.js +0 -363
- package/dist/framework/impl/table/table-impl.js.map +0 -1
- package/dist/framework/impl/table/table-row-impl.d.ts +0 -26
- package/dist/framework/impl/table/table-row-impl.js +0 -75
- package/dist/framework/impl/table/table-row-impl.js.map +0 -1
- package/dist/framework/impl/table/table-split-cell-patch.d.ts +0 -20
- package/dist/framework/impl/table/table-split-cell-patch.js +0 -89
- package/dist/framework/impl/table/table-split-cell-patch.js.map +0 -1
- package/dist/framework/impl/table/table-split-cell.d.ts +0 -90
- package/dist/framework/impl/table/table-split-cell.js +0 -464
- package/dist/framework/impl/table/table-split-cell.js.map +0 -1
- package/dist/framework/impl/table/table-util.d.ts +0 -150
- package/dist/framework/impl/table/table-util.js +0 -678
- package/dist/framework/impl/table/table-util.js.map +0 -1
- package/dist/framework/impl/text/text-impl.d.ts +0 -32
- package/dist/framework/impl/text/text-impl.js +0 -149
- package/dist/framework/impl/text/text-impl.js.map +0 -1
- package/dist/framework/impl/text/track-run-impl.d.ts +0 -27
- package/dist/framework/impl/text/track-run-impl.js +0 -112
- package/dist/framework/impl/text/track-run-impl.js.map +0 -1
- package/dist/framework/notify.d.ts +0 -13
- package/dist/framework/notify.js +0 -116
- package/dist/framework/notify.js.map +0 -1
- package/dist/framework/range-util.d.ts +0 -40
- package/dist/framework/range-util.js +0 -312
- package/dist/framework/range-util.js.map +0 -1
- package/dist/framework/render-context.d.ts +0 -91
- package/dist/framework/render-context.js +0 -384
- package/dist/framework/render-context.js.map +0 -1
- package/dist/framework/render-define.d.ts +0 -109
- package/dist/framework/render-define.js +0 -195
- package/dist/framework/render-define.js.map +0 -1
- package/dist/framework/selection-overlays.d.ts +0 -30
- package/dist/framework/selection-overlays.js +0 -124
- package/dist/framework/selection-overlays.js.map +0 -1
- package/dist/texteditor.d.ts +0 -318
- package/dist/texteditor.js +0 -913
- package/dist/texteditor.js.map +0 -1
- package/dist/util/subject.d.ts +0 -34
- package/dist/util/subject.js +0 -88
- package/dist/util/subject.js.map +0 -1
- package/dist/util/table-bind.d.ts +0 -5
- package/dist/util/table-bind.js +0 -6
- package/dist/util/table-bind.js.map +0 -1
- package/src/med_editor/doc-ruler.ts +0 -340
- package/src/med_editor/framework/common-util.ts +0 -200
- package/src/med_editor/framework/document-change.ts +0 -1392
- package/src/med_editor/framework/document-combine.ts +0 -44
- package/src/med_editor/framework/document-comment.ts +0 -168
- package/src/med_editor/framework/document-context.ts +0 -410
- package/src/med_editor/framework/document-eval-func.ts +0 -53
- package/src/med_editor/framework/document-event.ts +0 -1082
- package/src/med_editor/framework/document-history.ts +0 -76
- package/src/med_editor/framework/document-images-loader.ts +0 -74
- package/src/med_editor/framework/document-input-cursor.ts +0 -244
- package/src/med_editor/framework/document-paint.ts +0 -110
- package/src/med_editor/framework/document-print-offscreen.ts +0 -134
- package/src/med_editor/framework/document-print.ts +0 -219
- package/src/med_editor/framework/document-segmenter.ts +0 -211
- package/src/med_editor/framework/document-selection.ts +0 -391
- package/src/med_editor/framework/document-template.ts +0 -20
- package/src/med_editor/framework/document-textline-mode.ts +0 -34
- package/src/med_editor/framework/element-define.ts +0 -674
- package/src/med_editor/framework/element-event-define.ts +0 -142
- package/src/med_editor/framework/element-measure.ts +0 -573
- package/src/med_editor/framework/element-paint.ts +0 -176
- package/src/med_editor/framework/element-props.ts +0 -938
- package/src/med_editor/framework/element-reader.ts +0 -159
- package/src/med_editor/framework/element-render-cut.ts +0 -456
- package/src/med_editor/framework/element-serialize.ts +0 -128
- package/src/med_editor/framework/element-util.ts +0 -1565
- package/src/med_editor/framework/impl/checkbox/checkbox-impl.ts +0 -71
- package/src/med_editor/framework/impl/comments/comment-content-impl.ts +0 -119
- package/src/med_editor/framework/impl/comments/comment-element-impl.ts +0 -65
- package/src/med_editor/framework/impl/comments/comments-container-impl.ts +0 -68
- package/src/med_editor/framework/impl/comments/comments-util.ts +0 -84
- package/src/med_editor/framework/impl/comments/validate-msg-impl.ts +0 -94
- package/src/med_editor/framework/impl/data-element/data-decorate-impl.ts +0 -95
- package/src/med_editor/framework/impl/data-element/data-element-barcode.ts +0 -127
- package/src/med_editor/framework/impl/data-element/data-element-base-impl.ts +0 -234
- package/src/med_editor/framework/impl/data-element/data-element-check-impl.ts +0 -146
- package/src/med_editor/framework/impl/data-element/data-element-date-impl.ts +0 -128
- package/src/med_editor/framework/impl/data-element/data-element-group-impl.ts +0 -150
- package/src/med_editor/framework/impl/data-element/data-element-image-impl.ts +0 -147
- package/src/med_editor/framework/impl/data-element/data-element-list-impl.ts +0 -142
- package/src/med_editor/framework/impl/data-element/data-element-text-impl.ts +0 -117
- package/src/med_editor/framework/impl/decorate/fill-null-space-imple.ts +0 -48
- package/src/med_editor/framework/impl/document/doc-body-impl.ts +0 -95
- package/src/med_editor/framework/impl/document/doc-body-part-impl.ts +0 -104
- package/src/med_editor/framework/impl/document/doc-container-impl.ts +0 -24
- package/src/med_editor/framework/impl/document/doc-footer-impl.ts +0 -88
- package/src/med_editor/framework/impl/document/doc-header-impl.ts +0 -100
- package/src/med_editor/framework/impl/document/doc-impl.ts +0 -226
- package/src/med_editor/framework/impl/media-formula/menstrual-history.ts +0 -175
- package/src/med_editor/framework/impl/paragraph/p-impl.ts +0 -190
- package/src/med_editor/framework/impl/picture/image-impl.ts +0 -136
- package/src/med_editor/framework/impl/radio/radio-impl.ts +0 -79
- package/src/med_editor/framework/impl/symbol/br-symbol-impl.ts +0 -60
- package/src/med_editor/framework/impl/symbol/p-symbol-impl.ts +0 -57
- package/src/med_editor/framework/impl/table/table-cell-impl.ts +0 -156
- package/src/med_editor/framework/impl/table/table-impl.ts +0 -401
- package/src/med_editor/framework/impl/table/table-row-impl.ts +0 -83
- package/src/med_editor/framework/impl/table/table-split-cell-patch.ts +0 -98
- package/src/med_editor/framework/impl/table/table-split-cell.ts +0 -475
- package/src/med_editor/framework/impl/table/table-util.ts +0 -716
- package/src/med_editor/framework/impl/text/text-impl.ts +0 -164
- package/src/med_editor/framework/impl/text/track-run-impl.ts +0 -135
- package/src/med_editor/framework/notify.ts +0 -130
- package/src/med_editor/framework/range-util.ts +0 -321
- package/src/med_editor/framework/render-context.ts +0 -431
- package/src/med_editor/framework/render-define.ts +0 -224
- package/src/med_editor/framework/selection-overlays.ts +0 -134
- package/src/med_editor/texteditor.ts +0 -1011
- package/src/med_editor/util/subject.ts +0 -118
- package/src/med_editor/util/table-bind.ts +0 -6
- 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,219 +0,0 @@
|
|
1
|
-
import { EditorContext } from "./document-context";
|
2
|
-
import { SelectionState } from "./document-selection";
|
3
|
-
import { OrientType, PageOptions, ViewOptions } from "./element-define";
|
4
|
-
import { ElementPaint } from "./element-paint";
|
5
|
-
import { ElementUtil } from "./element-util";
|
6
|
-
import { DocumentRenderObject } from "./impl/document/doc-impl";
|
7
|
-
import { RenderContenxt } from "./render-context";
|
8
|
-
import { jsPDF } from 'jspdf'
|
9
|
-
|
10
|
-
export class documentPrint {
|
11
|
-
static print(ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext, printRanges: Array<number> | null = null): void {
|
12
|
-
const renderCanvasNodes = this.getRenderCanvasNodes(ss, viewOptions, docCtx, printRanges);
|
13
|
-
if (!renderCanvasNodes.length) {
|
14
|
-
console.warn('无可打印节点');
|
15
|
-
return;
|
16
|
-
}
|
17
|
-
printNodes(renderCanvasNodes, { ...docCtx.document.props });
|
18
|
-
}
|
19
|
-
|
20
|
-
/**
|
21
|
-
* 获取绘制的canvas节点
|
22
|
-
* @param ss
|
23
|
-
* @param viewOptions
|
24
|
-
* @param docCtx
|
25
|
-
* @param printRanges
|
26
|
-
* @returns
|
27
|
-
*/
|
28
|
-
private static getRenderCanvasNodes(ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext, printRanges: Array<number> | null = null): Array<HTMLCanvasElement> {
|
29
|
-
const { width, height } = viewOptions.docPageSettings;
|
30
|
-
const dc = ss.renderContainer;
|
31
|
-
const canvasList: Array<HTMLCanvasElement> = [];
|
32
|
-
const printPages: Array<DocumentRenderObject> = [];
|
33
|
-
for (let i = 0; i < dc.length; i++) {
|
34
|
-
if (!printRanges || printRanges.some(pageIndex => pageIndex === i)) {
|
35
|
-
printPages.push(<DocumentRenderObject>dc.getChild(i));
|
36
|
-
}
|
37
|
-
}
|
38
|
-
for (let i = 0; i < printPages.length; i++) {
|
39
|
-
const canvasNode = document.createElement('canvas');
|
40
|
-
canvasNode.style.cursor = 'text';
|
41
|
-
canvasNode.style.width = width + 'px';
|
42
|
-
canvasNode.style.height = height + 'px';
|
43
|
-
const ctx = canvasNode.getContext('2d') as CanvasRenderingContext2D;
|
44
|
-
ElementUtil.setCanvasProps(canvasNode, ctx, viewOptions.docPageSettings);
|
45
|
-
const renderCtx = new RenderContenxt(ctx, viewOptions, docCtx);
|
46
|
-
renderCtx.setCanvasProps(viewOptions.docPageSettings);
|
47
|
-
renderCtx.drawMode = 'print';
|
48
|
-
const doc = printPages[i];
|
49
|
-
const tmp = ElementUtil.cloneRect(doc.rect);
|
50
|
-
doc.rect.x = 0;
|
51
|
-
doc.rect.y = 0;
|
52
|
-
ElementPaint.drawPage(renderCtx, doc, { x: 0, y: 0 });
|
53
|
-
renderCtx.overlaysContext.clear();
|
54
|
-
renderCtx.mainCtx.fillStyle = 'white';
|
55
|
-
renderCtx.mainCtx.fillRect(0, 0, width, height);
|
56
|
-
renderCtx.commit(viewOptions.docPageSettings);
|
57
|
-
doc.rect = tmp;
|
58
|
-
canvasList.push(canvasNode);
|
59
|
-
}
|
60
|
-
return canvasList
|
61
|
-
}
|
62
|
-
|
63
|
-
/**
|
64
|
-
* 导出base64
|
65
|
-
* @param ss
|
66
|
-
* @param viewOptions
|
67
|
-
* @param docCtx
|
68
|
-
* @param printRanges
|
69
|
-
* @returns
|
70
|
-
*/
|
71
|
-
static exportCanvasNodes(ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext, printRanges: Array<number> | null = null): Array<HTMLCanvasElement> {
|
72
|
-
return this.getRenderCanvasNodes(ss, viewOptions, docCtx, printRanges);
|
73
|
-
}
|
74
|
-
|
75
|
-
/**
|
76
|
-
* 导出PDF
|
77
|
-
* @param fileName
|
78
|
-
* @param ss
|
79
|
-
* @param viewOptions
|
80
|
-
* @param docCtx
|
81
|
-
* @param printRanges
|
82
|
-
*/
|
83
|
-
static exportPDF(fileName: string, ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext, printRanges: Array<number> | null = null): void {
|
84
|
-
const nodes = this.getRenderCanvasNodes(ss, viewOptions, docCtx, printRanges);
|
85
|
-
exportCanvasToPDF(fileName, nodes, { ...docCtx.document.props })
|
86
|
-
}
|
87
|
-
|
88
|
-
/**
|
89
|
-
* 当前当前页
|
90
|
-
* @param ss
|
91
|
-
* @param viewOptions
|
92
|
-
*/
|
93
|
-
static printCurrPage(ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext,): void {
|
94
|
-
const { startHitInfo } = ss;
|
95
|
-
if (!startHitInfo) {
|
96
|
-
return;
|
97
|
-
}
|
98
|
-
const docPage = ElementUtil.getParentRender(startHitInfo.render, DocumentRenderObject);
|
99
|
-
if (!docPage) {
|
100
|
-
return;
|
101
|
-
}
|
102
|
-
this.print(ss, viewOptions, docCtx, [docPage.getIndex()]);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
|
107
|
-
export function createPrintTemplate({ width, height, orient }: PageOptions): string {
|
108
|
-
const str = `
|
109
|
-
<!DOCTYPE html>
|
110
|
-
<html lang="zh">
|
111
|
-
<head>
|
112
|
-
<meta charset="UTF-8">
|
113
|
-
<title></title>
|
114
|
-
<style >
|
115
|
-
html,
|
116
|
-
body {
|
117
|
-
margin: 0;
|
118
|
-
padding: 0;
|
119
|
-
}
|
120
|
-
* {
|
121
|
-
box-sizing: border-box;
|
122
|
-
-moz-box-sizing: border-box;
|
123
|
-
}
|
124
|
-
@page {
|
125
|
-
size: ${orient};
|
126
|
-
margin: 0;
|
127
|
-
}
|
128
|
-
div {
|
129
|
-
width: ${width}mm;
|
130
|
-
min-height: ${height}mm;
|
131
|
-
font-size: 0;
|
132
|
-
}
|
133
|
-
@media print {
|
134
|
-
html,
|
135
|
-
body {
|
136
|
-
width: ${width}mm;
|
137
|
-
height: ${height}mm;
|
138
|
-
}
|
139
|
-
div {
|
140
|
-
width: initial;
|
141
|
-
min-height: initial;
|
142
|
-
}
|
143
|
-
}
|
144
|
-
</style>
|
145
|
-
</head>
|
146
|
-
<body></body>
|
147
|
-
</html>
|
148
|
-
`.replace(/\n/g, '').replace(/\s+/g, ' ').replace(/'/g, '\\\'');
|
149
|
-
return str;
|
150
|
-
}
|
151
|
-
|
152
|
-
|
153
|
-
type PrintPaperOptions = {
|
154
|
-
width: number;
|
155
|
-
height: number;
|
156
|
-
orient: OrientType;
|
157
|
-
};
|
158
|
-
|
159
|
-
/**
|
160
|
-
* 打印DOM
|
161
|
-
* @param printNodes
|
162
|
-
* @param options
|
163
|
-
* @returns
|
164
|
-
*/
|
165
|
-
export function printNodes(printNodes: Array<Node>, options: PrintPaperOptions): void {
|
166
|
-
const printIFrame = document.createElement("iframe") as HTMLIFrameElement;
|
167
|
-
printIFrame.src = 'about:blank';
|
168
|
-
printIFrame.style.borderWidth = '0';
|
169
|
-
printIFrame.style.height = "0";
|
170
|
-
printIFrame.style.display = 'none';
|
171
|
-
document.body.appendChild(printIFrame);
|
172
|
-
printIFrame.contentWindow?.document.open("text/html", "printer");
|
173
|
-
if (!printNodes.length) {
|
174
|
-
console.warn('无可打印节点');
|
175
|
-
return;
|
176
|
-
}
|
177
|
-
const printSize: PageOptions = new PageOptions(options.width, options.height, options.orient);
|
178
|
-
const iframeHTML = createPrintTemplate(printSize);
|
179
|
-
printIFrame.contentWindow?.document.write(iframeHTML);
|
180
|
-
printIFrame.contentWindow?.document.close();
|
181
|
-
for (let i = 0; i < printNodes.length; i++) {
|
182
|
-
const item = printNodes[i];
|
183
|
-
const div = document.createElement('div');
|
184
|
-
div.appendChild(item);
|
185
|
-
printIFrame.contentWindow?.document.body.appendChild(div)
|
186
|
-
}
|
187
|
-
printIFrame.contentWindow?.document.body.focus();
|
188
|
-
setTimeout(() => {
|
189
|
-
printIFrame.contentWindow?.print();
|
190
|
-
printIFrame.parentNode?.removeChild(printIFrame);
|
191
|
-
}, 0);
|
192
|
-
}
|
193
|
-
|
194
|
-
/**
|
195
|
-
* canvas节点导出到PDF
|
196
|
-
* @param fileName
|
197
|
-
* @param nodes
|
198
|
-
* @param options
|
199
|
-
*/
|
200
|
-
export function exportCanvasToPDF(fileName: string, nodes: Array<HTMLCanvasElement>, options: PrintPaperOptions): void {
|
201
|
-
if (!fileName) {
|
202
|
-
fileName = 'document.pdf';
|
203
|
-
} else {
|
204
|
-
fileName = fileName.replace(/[\/\\:*?"<>|]/g, '_');
|
205
|
-
if (!fileName.endsWith('.pdf')) {
|
206
|
-
fileName += '.pdf';
|
207
|
-
}
|
208
|
-
}
|
209
|
-
const pdf = new jsPDF(options.orient, 'px', [options.width, options.height]);
|
210
|
-
for (let i = 0; i < nodes.length; i++) {
|
211
|
-
const canvas = nodes[i];
|
212
|
-
const imgData = canvas.toDataURL('image/jpeg', 1.0);
|
213
|
-
pdf.addImage(imgData, 'JPEG', 0, 0, options.width, options.height);
|
214
|
-
if (i < nodes.length - 1) {
|
215
|
-
pdf.addPage();
|
216
|
-
}
|
217
|
-
}
|
218
|
-
pdf.save(fileName);
|
219
|
-
}
|
@@ -1,211 +0,0 @@
|
|
1
|
-
import { Element, LeafElement } from "@/med_editor/framework/element-define";
|
2
|
-
import { TextGroupElement } from "@/med_editor/framework/impl/text/text-impl";
|
3
|
-
import { ElementUtil } from "@/med_editor/framework/element-util";
|
4
|
-
import { SelectionRange, SelectionState } from "./document-selection";
|
5
|
-
|
6
|
-
declare namespace Intl {
|
7
|
-
|
8
|
-
type BCP47LanguageTag = string;
|
9
|
-
|
10
|
-
/**
|
11
|
-
* An object with some or all properties of the `Intl.Segmenter` constructor `options` parameter.
|
12
|
-
*
|
13
|
-
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#parameters)
|
14
|
-
*/
|
15
|
-
interface SegmenterOptions {
|
16
|
-
/** The locale matching algorithm to use. For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation). */
|
17
|
-
localeMatcher?: "best fit" | "lookup" | undefined;
|
18
|
-
/** The type of input to be split */
|
19
|
-
granularity?: "grapheme" | "word" | "sentence" | undefined;
|
20
|
-
}
|
21
|
-
|
22
|
-
interface Segmenter {
|
23
|
-
/**
|
24
|
-
* Returns `Segments` object containing the segments of the input string, using the segmenter's locale and granularity.
|
25
|
-
*
|
26
|
-
* @param input - The text to be segmented as a `string`.
|
27
|
-
*
|
28
|
-
* @returns A new iterable Segments object containing the segments of the input string, using the segmenter's locale and granularity.
|
29
|
-
*/
|
30
|
-
segment(input: string): Segments;
|
31
|
-
|
32
|
-
resolvedOptions(): ResolvedSegmenterOptions;
|
33
|
-
}
|
34
|
-
|
35
|
-
interface ResolvedSegmenterOptions {
|
36
|
-
locale: string;
|
37
|
-
granularity: "grapheme" | "word" | "sentence";
|
38
|
-
}
|
39
|
-
|
40
|
-
interface Segments {
|
41
|
-
/**
|
42
|
-
* Returns an object describing the segment in the original string that includes the code unit at a specified index.
|
43
|
-
*
|
44
|
-
* @param codeUnitIndex - A number specifying the index of the code unit in the original input string. If the value is omitted, it defaults to `0`.
|
45
|
-
*/
|
46
|
-
containing(codeUnitIndex?: number): SegmentData;
|
47
|
-
|
48
|
-
/** Returns an iterator to iterate over the segments. */
|
49
|
-
[Symbol.iterator](): IterableIterator<SegmentData>;
|
50
|
-
}
|
51
|
-
|
52
|
-
interface SegmentData {
|
53
|
-
/** A string containing the segment extracted from the original input string. */
|
54
|
-
segment: string;
|
55
|
-
/** The code unit index in the original input string at which the segment begins. */
|
56
|
-
index: number;
|
57
|
-
/** The complete input string that was segmented. */
|
58
|
-
input: string;
|
59
|
-
/**
|
60
|
-
* A boolean value only if granularity is "word"; otherwise, undefined.
|
61
|
-
* If granularity is "word", then isWordLike is true when the segment is word-like (i.e., consists of letters/numbers/ideographs/etc.); otherwise, false.
|
62
|
-
*/
|
63
|
-
isWordLike?: boolean;
|
64
|
-
}
|
65
|
-
|
66
|
-
const Segmenter: {
|
67
|
-
prototype: Segmenter;
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Creates a new `Intl.Segmenter` object.
|
71
|
-
*
|
72
|
-
* @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
|
73
|
-
* For the general form and interpretation of the `locales` argument,
|
74
|
-
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
|
75
|
-
*
|
76
|
-
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#parameters)
|
77
|
-
* with some or all options of `SegmenterOptions`.
|
78
|
-
*
|
79
|
-
* @returns [Intl.Segmenter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segments) object.
|
80
|
-
*
|
81
|
-
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter).
|
82
|
-
*/
|
83
|
-
new(locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: SegmenterOptions): Segmenter;
|
84
|
-
|
85
|
-
/**
|
86
|
-
* Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.
|
87
|
-
*
|
88
|
-
* @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
|
89
|
-
* For the general form and interpretation of the `locales` argument,
|
90
|
-
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
|
91
|
-
*
|
92
|
-
* @param options An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf#parameters).
|
93
|
-
* with some or all possible options.
|
94
|
-
*
|
95
|
-
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
|
96
|
-
*/
|
97
|
-
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: Pick<SegmenterOptions, "localeMatcher">): BCP47LanguageTag[];
|
98
|
-
};
|
99
|
-
}
|
100
|
-
|
101
|
-
export function getFocusTextSegment(selection: SelectionState): boolean {
|
102
|
-
let { startControl: element, startOffset: offset } = selection;
|
103
|
-
if (!(element instanceof TextGroupElement)) return false;
|
104
|
-
if (!supportSegment()) return false;
|
105
|
-
const focusEle = element as TextGroupElement;
|
106
|
-
offset = offset + 1;
|
107
|
-
offset = offset > focusEle.textMeasures.length ? focusEle.textMeasures.length : offset;
|
108
|
-
//获取连续的字符
|
109
|
-
const items = [...getConsecutiveTextsByDirection(element), element, ...getConsecutiveTextsByDirection(element, false)];
|
110
|
-
const sortItems = getTextSortData(items);
|
111
|
-
const { index, text } = sortItems.reduce((prev, curr) => {
|
112
|
-
prev.text += curr.text;
|
113
|
-
if (prev.completed) {
|
114
|
-
return prev;
|
115
|
-
}
|
116
|
-
if (curr.item === focusEle) {
|
117
|
-
prev.index += offset;
|
118
|
-
prev.completed = true;
|
119
|
-
} else {
|
120
|
-
prev.index += curr.item.textMeasures.length;
|
121
|
-
}
|
122
|
-
return prev
|
123
|
-
}, { completed: false, index: 0, text: '' });
|
124
|
-
const { index: hitIndex, len: hitLen } = getHitSegment(text, index);
|
125
|
-
const matchSegment = sortItems.filter(item => (item.index <= hitIndex && item.endIndex > hitIndex) || (item.index <= hitIndex + hitLen && item.endIndex > hitIndex + hitLen));
|
126
|
-
const startSegment = matchSegment[0];
|
127
|
-
const endSegment = matchSegment[matchSegment.length - 1];
|
128
|
-
const startOffset = hitIndex - startSegment.index;
|
129
|
-
const endOffset = hitIndex + hitLen - endSegment.index;
|
130
|
-
const newRange = new SelectionRange();
|
131
|
-
newRange.setStart(startSegment.item, startOffset);
|
132
|
-
newRange.setEnd(endSegment.item, endOffset);
|
133
|
-
selection.addRange(newRange);
|
134
|
-
return true;
|
135
|
-
}
|
136
|
-
|
137
|
-
interface TextSegmentData {
|
138
|
-
item: TextGroupElement,
|
139
|
-
len: number,
|
140
|
-
index: number,
|
141
|
-
endIndex: number,
|
142
|
-
text: string
|
143
|
-
}
|
144
|
-
|
145
|
-
/**
|
146
|
-
* 进行分词
|
147
|
-
* @param text
|
148
|
-
* @param focusOffset
|
149
|
-
*/
|
150
|
-
function getHitSegment(text: string, focusOffset): { index: number, len: number } {
|
151
|
-
const segmenter = new Intl.Segmenter("zh-CN", { granularity: "word" });
|
152
|
-
const iterator1 = segmenter.segment(text)[Symbol.iterator]();
|
153
|
-
const segItems = Array.from(iterator1);
|
154
|
-
let index = 0;
|
155
|
-
for (let i = 0; i < segItems.length; i++) {
|
156
|
-
const segItem = segItems[i];
|
157
|
-
const currIndex = segItem.index;
|
158
|
-
const currLen = segItem.segment.length;
|
159
|
-
if (focusOffset > currIndex && focusOffset <= currLen + currIndex) {
|
160
|
-
return {
|
161
|
-
index,
|
162
|
-
len: currLen
|
163
|
-
}
|
164
|
-
}
|
165
|
-
index += currLen;
|
166
|
-
}
|
167
|
-
throw new Error('未获取到对应的分词词组');
|
168
|
-
}
|
169
|
-
|
170
|
-
function supportSegment(): boolean {
|
171
|
-
return typeof Intl.Segmenter === 'function';
|
172
|
-
}
|
173
|
-
|
174
|
-
/**
|
175
|
-
* 根据前后顺序标识索引位
|
176
|
-
* @param texts
|
177
|
-
*/
|
178
|
-
function getTextSortData(texts: Array<TextGroupElement>): Array<TextSegmentData> {
|
179
|
-
let index = 0;
|
180
|
-
const sortItems: Array<TextSegmentData> = [];
|
181
|
-
for (let i = 0; i < texts.length; i++) {
|
182
|
-
const item = texts[i];
|
183
|
-
const sortData = {
|
184
|
-
len: item.textMeasures.length,
|
185
|
-
index,
|
186
|
-
endIndex: index + item.textMeasures.length,
|
187
|
-
item,
|
188
|
-
text: item.text
|
189
|
-
};
|
190
|
-
sortItems.push(sortData);
|
191
|
-
index += sortData.len;
|
192
|
-
}
|
193
|
-
return sortItems;
|
194
|
-
}
|
195
|
-
|
196
|
-
/**
|
197
|
-
* 获取指定方向上连续的字符
|
198
|
-
* @param element
|
199
|
-
* @param prev
|
200
|
-
*/
|
201
|
-
function getConsecutiveTextsByDirection(element: TextGroupElement, prev = true): Array<TextGroupElement> {
|
202
|
-
let prevText: Element | null = element;
|
203
|
-
const prevTexts: Array<TextGroupElement> = [];
|
204
|
-
const func = prev ? ElementUtil.getPrevSiblingElement : ElementUtil.getNextSiblingElement;
|
205
|
-
const addItem = prev ? prevTexts.unshift : prevTexts.push;
|
206
|
-
while ((prevText = func(prevText)) && prevText instanceof TextGroupElement) {
|
207
|
-
//addItem(prevText);
|
208
|
-
addItem.apply(prevTexts, [prevText]);
|
209
|
-
}
|
210
|
-
return prevTexts;
|
211
|
-
}
|