@hailin-zheng/editor-core 1.0.6 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/package.json +2 -2
  2. package/{lib/doc-ruler.js → src/med_editor/doc-ruler.ts} +101 -74
  3. package/src/med_editor/framework/common-util.ts +200 -0
  4. package/{lib/framework/document-change.js → src/med_editor/framework/document-change.ts} +308 -259
  5. package/{lib/framework/document-combine.js → src/med_editor/framework/document-combine.ts} +15 -11
  6. package/{lib/framework/document-comment.js → src/med_editor/framework/document-comment.ts} +52 -37
  7. package/{lib/framework/document-context.js → src/med_editor/framework/document-context.ts} +181 -101
  8. package/{lib/framework/document-eval-func.js → src/med_editor/framework/document-eval-func.ts} +16 -11
  9. package/{lib/framework/document-event.js → src/med_editor/framework/document-event.ts} +244 -216
  10. package/{lib/framework/document-history.js → src/med_editor/framework/document-history.ts} +25 -14
  11. package/{lib/framework/document-images-loader.js → src/med_editor/framework/document-images-loader.ts} +25 -17
  12. package/{lib/framework/document-input-cursor.js → src/med_editor/framework/document-input-cursor.ts} +76 -71
  13. package/{lib/framework/document-paint.js → src/med_editor/framework/document-paint.ts} +35 -28
  14. package/{lib/framework/document-print-offscreen.js → src/med_editor/framework/document-print-offscreen.ts} +25 -19
  15. package/{lib/framework/document-print.js → src/med_editor/framework/document-print.ts} +57 -41
  16. package/src/med_editor/framework/document-segmenter.ts +211 -0
  17. package/{lib/framework/document-selection.js → src/med_editor/framework/document-selection.ts} +116 -85
  18. package/{lib/framework/document-template.js → src/med_editor/framework/document-template.ts} +3 -3
  19. package/src/med_editor/framework/document-textline-mode.ts +34 -0
  20. package/{lib/framework/element-define.js → src/med_editor/framework/element-define.ts} +301 -206
  21. package/src/med_editor/framework/element-event-define.ts +141 -0
  22. package/{lib/framework/element-measure.js → src/med_editor/framework/element-measure.ts} +143 -121
  23. package/{lib/framework/element-paint.js → src/med_editor/framework/element-paint.ts} +44 -38
  24. package/{lib/framework/element-props.js → src/med_editor/framework/element-props.ts} +331 -202
  25. package/{lib/framework/element-reader.js → src/med_editor/framework/element-reader.ts} +39 -31
  26. package/{lib/framework/element-render-cut.js → src/med_editor/framework/element-render-cut.ts} +113 -106
  27. package/{lib/framework/element-serialize.js → src/med_editor/framework/element-serialize.ts} +37 -24
  28. package/{lib/framework/element-util.js → src/med_editor/framework/element-util.ts} +317 -216
  29. package/{lib/framework/impl/checkbox/checkbox-impl.js → src/med_editor/framework/impl/checkbox/checkbox-impl.ts} +27 -20
  30. package/{lib/framework/impl/comments/comment-content-impl.js → src/med_editor/framework/impl/comments/comment-content-impl.ts} +45 -31
  31. package/{lib/framework/impl/comments/comment-element-impl.js → src/med_editor/framework/impl/comments/comment-element-impl.ts} +23 -20
  32. package/{lib/framework/impl/comments/comments-container-impl.js → src/med_editor/framework/impl/comments/comments-container-impl.ts} +22 -16
  33. package/{lib/framework/impl/comments/comments-util.js → src/med_editor/framework/impl/comments/comments-util.ts} +34 -17
  34. package/{lib/framework/impl/comments/validate-msg-impl.js → src/med_editor/framework/impl/comments/validate-msg-impl.ts} +28 -17
  35. package/{lib/framework/impl/data-element/data-decorate-impl.js → src/med_editor/framework/impl/data-element/data-decorate-impl.ts} +26 -22
  36. package/{lib/framework/impl/data-element/data-element-barcode.js → src/med_editor/framework/impl/data-element/data-element-barcode.ts} +41 -29
  37. package/{lib/framework/impl/data-element/data-element-base-impl.js → src/med_editor/framework/impl/data-element/data-element-base-impl.ts} +73 -44
  38. package/{lib/framework/impl/data-element/data-element-check-impl.js → src/med_editor/framework/impl/data-element/data-element-check-impl.ts} +48 -35
  39. package/{lib/framework/impl/data-element/data-element-date-impl.js → src/med_editor/framework/impl/data-element/data-element-date-impl.ts} +41 -24
  40. package/{lib/framework/impl/data-element/data-element-group-impl.js → src/med_editor/framework/impl/data-element/data-element-group-impl.ts} +52 -32
  41. package/{lib/framework/impl/data-element/data-element-image-impl.js → src/med_editor/framework/impl/data-element/data-element-image-impl.ts} +38 -28
  42. package/{lib/framework/impl/data-element/data-element-list-impl.js → src/med_editor/framework/impl/data-element/data-element-list-impl.ts} +42 -31
  43. package/{lib/framework/impl/data-element/data-element-text-impl.js → src/med_editor/framework/impl/data-element/data-element-text-impl.ts} +36 -22
  44. package/{lib/framework/impl/decorate/fill-null-space-imple.js → src/med_editor/framework/impl/decorate/fill-null-space-imple.ts} +15 -10
  45. package/{lib/framework/impl/document/doc-body-impl.js → src/med_editor/framework/impl/document/doc-body-impl.ts} +32 -16
  46. package/{lib/framework/impl/document/doc-body-part-impl.js → src/med_editor/framework/impl/document/doc-body-part-impl.ts} +27 -17
  47. package/src/med_editor/framework/impl/document/doc-container-impl.ts +24 -0
  48. package/{lib/framework/impl/document/doc-footer-impl.js → src/med_editor/framework/impl/document/doc-footer-impl.ts} +30 -19
  49. package/{lib/framework/impl/document/doc-header-impl.js → src/med_editor/framework/impl/document/doc-header-impl.ts} +34 -17
  50. package/{lib/framework/impl/document/doc-impl.js → src/med_editor/framework/impl/document/doc-impl.ts} +62 -45
  51. package/{lib/framework/impl/media-formula/menstrual-history.js → src/med_editor/framework/impl/media-formula/menstrual-history.ts} +58 -36
  52. package/{lib/framework/impl/paragraph/p-impl.js → src/med_editor/framework/impl/paragraph/p-impl.ts} +64 -30
  53. package/{lib/framework/impl/picture/image-impl.js → src/med_editor/framework/impl/picture/image-impl.ts} +37 -25
  54. package/{lib/framework/impl/radio/radio-impl.js → src/med_editor/framework/impl/radio/radio-impl.ts} +28 -21
  55. package/{lib/framework/impl/symbol/br-symbol-impl.js → src/med_editor/framework/impl/symbol/br-symbol-impl.ts} +21 -15
  56. package/{lib/framework/impl/symbol/p-symbol-impl.js → src/med_editor/framework/impl/symbol/p-symbol-impl.ts} +15 -12
  57. package/{lib/framework/impl/table/table-cell-impl.js → src/med_editor/framework/impl/table/table-cell-impl.ts} +41 -30
  58. package/{lib/framework/impl/table/table-impl.js → src/med_editor/framework/impl/table/table-impl.ts} +122 -84
  59. package/{lib/framework/impl/table/table-row-impl.js → src/med_editor/framework/impl/table/table-row-impl.ts} +26 -18
  60. package/{lib/framework/impl/table/table-split-cell-patch.js → src/med_editor/framework/impl/table/table-split-cell-patch.ts} +31 -22
  61. package/{lib/framework/impl/table/table-split-cell.js → src/med_editor/framework/impl/table/table-split-cell.ts} +105 -94
  62. package/{lib/framework/impl/table/table-util.js → src/med_editor/framework/impl/table/table-util.ts} +197 -159
  63. package/{lib/framework/impl/text/text-impl.js → src/med_editor/framework/impl/text/text-impl.ts} +49 -35
  64. package/{lib/framework/impl/text/track-run-impl.js → src/med_editor/framework/impl/text/track-run-impl.ts} +53 -30
  65. package/{lib/framework/notify.js → src/med_editor/framework/notify.ts} +50 -36
  66. package/{lib/framework/range-util.js → src/med_editor/framework/range-util.ts} +80 -71
  67. package/{lib/framework/render-context.js → src/med_editor/framework/render-context.ts} +111 -64
  68. package/{lib/framework/render-define.js → src/med_editor/framework/render-define.ts} +90 -61
  69. package/{lib/framework/selection-overlays.js → src/med_editor/framework/selection-overlays.ts} +25 -16
  70. package/{lib/texteditor.js → src/med_editor/texteditor.ts} +288 -191
  71. package/src/med_editor/util/subject.ts +118 -0
  72. package/{lib/util/table-bind.js → src/med_editor/util/table-bind.ts} +2 -2
  73. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225.json +3573 -0
  74. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225.json +3573 -0
  75. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225bug.json +315 -0
  76. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225/346/211/271/346/263/250.json +122 -0
  77. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225/346/226/207/346/241/243/351/252/214/350/257/201.json +3599 -0
  78. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225/351/225/277/346/226/207/346/234/254.json +24586 -0
  79. package/src/med_editor//345/220/210/345/271/266/347/227/205/347/250/213/345/275/225.json +2874 -0
  80. package/src/med_editor//346/211/213/346/234/257/350/256/260/345/275/225.json +341 -0
  81. package/src/med_editor//346/231/256/351/200/232doc/347/261/273/346/226/207/346/241/243.json +2201 -0
  82. package/src/med_editor//346/243/200/351/252/214/347/224/263/350/257/267/345/215/225.json +1069 -0
  83. package/src/med_editor//347/227/205/347/250/213/345/275/225//345/206/205/351/225/234/344/270/213/346/262/273/347/226/227/350/256/260/345/275/225.json +125 -0
  84. package/src/med_editor//347/227/205/347/250/213/345/275/225//345/220/210/345/271/266/347/227/205/347/250/213/345/275/225/346/250/241/346/235/277.json +86 -0
  85. package/src/med_editor//347/227/205/347/250/213/345/275/225//346/227/245/345/270/270/347/227/205/347/250/213/350/256/260/345/275/225.json +115 -0
  86. package/src/med_editor//347/227/205/347/250/213/345/275/225//346/237/245/346/210/277/350/256/260/345/275/2251.json +108 -0
  87. package/src/med_editor//347/227/205/347/250/213/345/275/225//351/246/226/346/254/241/344/270/212/347/272/247/345/214/273/345/270/210/346/237/245/346/210/277/350/256/260/345/275/225.json +272 -0
  88. package/src/med_editor//351/225/277/346/234/237/345/214/273/345/230/261/345/215/225.json +1070 -0
  89. package/lib/doc-ruler.d.ts +0 -51
  90. package/lib/doc-ruler.js.map +0 -1
  91. package/lib/framework/common-util.d.ts +0 -63
  92. package/lib/framework/common-util.js +0 -178
  93. package/lib/framework/common-util.js.map +0 -1
  94. package/lib/framework/document-change.d.ts +0 -265
  95. package/lib/framework/document-change.js.map +0 -1
  96. package/lib/framework/document-combine.d.ts +0 -24
  97. package/lib/framework/document-combine.js.map +0 -1
  98. package/lib/framework/document-comment.d.ts +0 -46
  99. package/lib/framework/document-comment.js.map +0 -1
  100. package/lib/framework/document-context.d.ts +0 -149
  101. package/lib/framework/document-context.js.map +0 -1
  102. package/lib/framework/document-eval-func.d.ts +0 -18
  103. package/lib/framework/document-eval-func.js.map +0 -1
  104. package/lib/framework/document-event.d.ts +0 -213
  105. package/lib/framework/document-event.js.map +0 -1
  106. package/lib/framework/document-history.d.ts +0 -26
  107. package/lib/framework/document-history.js.map +0 -1
  108. package/lib/framework/document-images-loader.d.ts +0 -16
  109. package/lib/framework/document-images-loader.js.map +0 -1
  110. package/lib/framework/document-input-cursor.d.ts +0 -78
  111. package/lib/framework/document-input-cursor.js.map +0 -1
  112. package/lib/framework/document-paint.d.ts +0 -34
  113. package/lib/framework/document-paint.js.map +0 -1
  114. package/lib/framework/document-print-offscreen.d.ts +0 -38
  115. package/lib/framework/document-print-offscreen.js.map +0 -1
  116. package/lib/framework/document-print.d.ts +0 -60
  117. package/lib/framework/document-print.js.map +0 -1
  118. package/lib/framework/document-segmenter.d.ts +0 -2
  119. package/lib/framework/document-segmenter.js +0 -106
  120. package/lib/framework/document-segmenter.js.map +0 -1
  121. package/lib/framework/document-selection.d.ts +0 -89
  122. package/lib/framework/document-selection.js.map +0 -1
  123. package/lib/framework/document-template.d.ts +0 -4
  124. package/lib/framework/document-template.js.map +0 -1
  125. package/lib/framework/document-textline-mode.d.ts +0 -7
  126. package/lib/framework/document-textline-mode.js +0 -30
  127. package/lib/framework/document-textline-mode.js.map +0 -1
  128. package/lib/framework/element-define.d.ts +0 -319
  129. package/lib/framework/element-define.js.map +0 -1
  130. package/lib/framework/element-event-define.d.ts +0 -99
  131. package/lib/framework/element-event-define.js +0 -108
  132. package/lib/framework/element-event-define.js.map +0 -1
  133. package/lib/framework/element-measure.d.ts +0 -97
  134. package/lib/framework/element-measure.js.map +0 -1
  135. package/lib/framework/element-paint.d.ts +0 -42
  136. package/lib/framework/element-paint.js.map +0 -1
  137. package/lib/framework/element-props.d.ts +0 -301
  138. package/lib/framework/element-props.js.map +0 -1
  139. package/lib/framework/element-reader.d.ts +0 -19
  140. package/lib/framework/element-reader.js.map +0 -1
  141. package/lib/framework/element-render-cut.d.ts +0 -55
  142. package/lib/framework/element-render-cut.js.map +0 -1
  143. package/lib/framework/element-serialize.d.ts +0 -30
  144. package/lib/framework/element-serialize.js.map +0 -1
  145. package/lib/framework/element-util.d.ts +0 -369
  146. package/lib/framework/element-util.js.map +0 -1
  147. package/lib/framework/impl/checkbox/checkbox-impl.d.ts +0 -24
  148. package/lib/framework/impl/checkbox/checkbox-impl.js.map +0 -1
  149. package/lib/framework/impl/comments/comment-content-impl.d.ts +0 -40
  150. package/lib/framework/impl/comments/comment-content-impl.js.map +0 -1
  151. package/lib/framework/impl/comments/comment-element-impl.d.ts +0 -21
  152. package/lib/framework/impl/comments/comment-element-impl.js.map +0 -1
  153. package/lib/framework/impl/comments/comments-container-impl.d.ts +0 -22
  154. package/lib/framework/impl/comments/comments-container-impl.js.map +0 -1
  155. package/lib/framework/impl/comments/comments-util.d.ts +0 -12
  156. package/lib/framework/impl/comments/comments-util.js.map +0 -1
  157. package/lib/framework/impl/comments/validate-msg-impl.d.ts +0 -21
  158. package/lib/framework/impl/comments/validate-msg-impl.js.map +0 -1
  159. package/lib/framework/impl/data-element/data-decorate-impl.d.ts +0 -30
  160. package/lib/framework/impl/data-element/data-decorate-impl.js.map +0 -1
  161. package/lib/framework/impl/data-element/data-element-barcode.d.ts +0 -31
  162. package/lib/framework/impl/data-element/data-element-barcode.js.map +0 -1
  163. package/lib/framework/impl/data-element/data-element-base-impl.d.ts +0 -68
  164. package/lib/framework/impl/data-element/data-element-base-impl.js.map +0 -1
  165. package/lib/framework/impl/data-element/data-element-check-impl.d.ts +0 -35
  166. package/lib/framework/impl/data-element/data-element-check-impl.js.map +0 -1
  167. package/lib/framework/impl/data-element/data-element-date-impl.d.ts +0 -23
  168. package/lib/framework/impl/data-element/data-element-date-impl.js.map +0 -1
  169. package/lib/framework/impl/data-element/data-element-group-impl.d.ts +0 -23
  170. package/lib/framework/impl/data-element/data-element-group-impl.js.map +0 -1
  171. package/lib/framework/impl/data-element/data-element-image-impl.d.ts +0 -30
  172. package/lib/framework/impl/data-element/data-element-image-impl.js.map +0 -1
  173. package/lib/framework/impl/data-element/data-element-list-impl.d.ts +0 -22
  174. package/lib/framework/impl/data-element/data-element-list-impl.js.map +0 -1
  175. package/lib/framework/impl/data-element/data-element-text-impl.d.ts +0 -23
  176. package/lib/framework/impl/data-element/data-element-text-impl.js.map +0 -1
  177. package/lib/framework/impl/decorate/fill-null-space-imple.d.ts +0 -21
  178. package/lib/framework/impl/decorate/fill-null-space-imple.js.map +0 -1
  179. package/lib/framework/impl/document/doc-body-impl.d.ts +0 -27
  180. package/lib/framework/impl/document/doc-body-impl.js.map +0 -1
  181. package/lib/framework/impl/document/doc-body-part-impl.d.ts +0 -30
  182. package/lib/framework/impl/document/doc-body-part-impl.js.map +0 -1
  183. package/lib/framework/impl/document/doc-container-impl.d.ts +0 -16
  184. package/lib/framework/impl/document/doc-container-impl.js +0 -21
  185. package/lib/framework/impl/document/doc-container-impl.js.map +0 -1
  186. package/lib/framework/impl/document/doc-footer-impl.d.ts +0 -26
  187. package/lib/framework/impl/document/doc-footer-impl.js.map +0 -1
  188. package/lib/framework/impl/document/doc-header-impl.d.ts +0 -26
  189. package/lib/framework/impl/document/doc-header-impl.js.map +0 -1
  190. package/lib/framework/impl/document/doc-impl.d.ts +0 -61
  191. package/lib/framework/impl/document/doc-impl.js.map +0 -1
  192. package/lib/framework/impl/media-formula/menstrual-history.d.ts +0 -35
  193. package/lib/framework/impl/media-formula/menstrual-history.js.map +0 -1
  194. package/lib/framework/impl/paragraph/p-impl.d.ts +0 -45
  195. package/lib/framework/impl/paragraph/p-impl.js.map +0 -1
  196. package/lib/framework/impl/picture/image-impl.d.ts +0 -31
  197. package/lib/framework/impl/picture/image-impl.js.map +0 -1
  198. package/lib/framework/impl/radio/radio-impl.d.ts +0 -22
  199. package/lib/framework/impl/radio/radio-impl.js.map +0 -1
  200. package/lib/framework/impl/symbol/br-symbol-impl.d.ts +0 -22
  201. package/lib/framework/impl/symbol/br-symbol-impl.js.map +0 -1
  202. package/lib/framework/impl/symbol/p-symbol-impl.d.ts +0 -19
  203. package/lib/framework/impl/symbol/p-symbol-impl.js.map +0 -1
  204. package/lib/framework/impl/table/table-cell-impl.d.ts +0 -37
  205. package/lib/framework/impl/table/table-cell-impl.js.map +0 -1
  206. package/lib/framework/impl/table/table-impl.d.ts +0 -55
  207. package/lib/framework/impl/table/table-impl.js.map +0 -1
  208. package/lib/framework/impl/table/table-row-impl.d.ts +0 -26
  209. package/lib/framework/impl/table/table-row-impl.js.map +0 -1
  210. package/lib/framework/impl/table/table-split-cell-patch.d.ts +0 -20
  211. package/lib/framework/impl/table/table-split-cell-patch.js.map +0 -1
  212. package/lib/framework/impl/table/table-split-cell.d.ts +0 -90
  213. package/lib/framework/impl/table/table-split-cell.js.map +0 -1
  214. package/lib/framework/impl/table/table-util.d.ts +0 -150
  215. package/lib/framework/impl/table/table-util.js.map +0 -1
  216. package/lib/framework/impl/text/text-impl.d.ts +0 -32
  217. package/lib/framework/impl/text/text-impl.js.map +0 -1
  218. package/lib/framework/impl/text/track-run-impl.d.ts +0 -27
  219. package/lib/framework/impl/text/track-run-impl.js.map +0 -1
  220. package/lib/framework/notify.d.ts +0 -13
  221. package/lib/framework/notify.js.map +0 -1
  222. package/lib/framework/range-util.d.ts +0 -40
  223. package/lib/framework/range-util.js.map +0 -1
  224. package/lib/framework/render-context.d.ts +0 -91
  225. package/lib/framework/render-context.js.map +0 -1
  226. package/lib/framework/render-define.d.ts +0 -109
  227. package/lib/framework/render-define.js.map +0 -1
  228. package/lib/framework/selection-overlays.d.ts +0 -30
  229. package/lib/framework/selection-overlays.js.map +0 -1
  230. package/lib/texteditor.d.ts +0 -318
  231. package/lib/texteditor.js.map +0 -1
  232. package/lib/util/subject.d.ts +0 -34
  233. package/lib/util/subject.js +0 -88
  234. package/lib/util/subject.js.map +0 -1
  235. package/lib/util/table-bind.d.ts +0 -5
  236. package/lib/util/table-bind.js.map +0 -1
@@ -6,17 +6,19 @@ import { ViewOptions } from "./element-define";
6
6
  import { ElementPaint } from "./element-paint";
7
7
  import { ElementReader } from "./element-reader";
8
8
  import { ElementUtil } from "./element-util";
9
- import { RenderContenxt } from "./render-context";
9
+ import { DocumentElement, DocumentRenderObject } from "./impl/document/doc-impl";
10
+ import { RenderContenxt, RenderContenxtType } from "./render-context";
11
+
10
12
  /**
11
13
  * 离屏打印
12
14
  */
13
15
  export class DocumentPrintOffscreen {
14
- documentPaint;
15
- viewOptions;
16
- docCtx;
17
- renderCtx;
18
- elementReader;
19
- ctx;
16
+ documentPaint: DocumentPaint;
17
+ viewOptions: ViewOptions;
18
+ docCtx: EditorContext;
19
+ renderCtx: RenderContenxt;
20
+ elementReader: ElementReader;
21
+ ctx: CanvasRenderingContext2D;
20
22
  constructor() {
21
23
  this.viewOptions = new ViewOptions();
22
24
  this.viewOptions.copyRightInfo = '万达信息电子病历编辑器,www.wondersgroup.com';
@@ -36,7 +38,7 @@ export class DocumentPrintOffscreen {
36
38
  name: '管理员'
37
39
  };
38
40
  const canvas = document.createElement('canvas');
39
- this.ctx = canvas.getContext('2d');
41
+ this.ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
40
42
  const ss = new SelectionState();
41
43
  this.docCtx = new EditorContext(ss, this.viewOptions);
42
44
  this.renderCtx = new RenderContenxt(this.ctx, this.viewOptions, this.docCtx);
@@ -45,16 +47,17 @@ export class DocumentPrintOffscreen {
45
47
  this.docCtx.syncRefresh = () => {
46
48
  };
47
49
  }
48
- async print(data, ranges = null) {
50
+ async print(data: any | DocumentElement, ranges: Array<number> | null = null): Promise<void> {
49
51
  await this.prepare(data);
50
52
  const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
51
53
  if (!canvasNodes.length) {
52
- console.warn('无可打印页');
54
+ console.warn('无可打印页')
53
55
  return;
54
56
  }
55
57
  const docProps = this.docCtx.document.props;
56
58
  printNodes(canvasNodes, { ...docProps });
57
59
  }
60
+
58
61
  /**
59
62
  * 导出PDF
60
63
  * @param fileName
@@ -63,40 +66,44 @@ export class DocumentPrintOffscreen {
63
66
  * @param docCtx
64
67
  * @param ranges
65
68
  */
66
- async exportToPDF(data, fileName, ranges = null) {
69
+ async exportToPDF(data: any | DocumentElement, fileName: string, ranges: Array<number> | null = null): Promise<void> {
67
70
  await this.prepare(data);
68
71
  const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
69
72
  if (!canvasNodes.length) {
70
- console.warn('无可导出页');
73
+ console.warn('无可导出页')
71
74
  return;
72
75
  }
73
76
  exportCanvasToPDF(fileName, canvasNodes, this.docCtx.document.props);
74
77
  }
78
+
79
+
75
80
  /**
76
81
  * 获取绘制的图片,格式为Base64编码
77
82
  */
78
- async getImagesContent(data, ranges = null) {
83
+ async getImagesContent(data: any | DocumentElement, ranges: Array<number> | null = null): Promise<Array<string>> {
79
84
  await this.prepare(data);
80
85
  const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
81
86
  if (!canvasNodes.length) {
82
- console.warn('无可导出页');
87
+ console.warn('无可导出页')
83
88
  return [];
84
89
  }
85
90
  return canvasNodes.map(node => node.toDataURL());
86
91
  }
92
+
87
93
  /**
88
94
  * 读取数据,排版
89
95
  * @param data
90
96
  */
91
- async prepare(data) {
97
+ private async prepare(data: any | DocumentElement,): Promise<void> {
92
98
  this.elementReader.read(data);
93
99
  this.documentPaint.rePages();
94
100
  await Promise.all(this.docCtx.imageLoader.getLoadTasks());
95
101
  this.renderCtx.setCanvasProps(this.viewOptions.docPageSettings);
96
102
  }
97
- getCanvasNodes(printPages, printRanges = null) {
103
+
104
+ private getCanvasNodes(printPages: Array<DocumentRenderObject>, printRanges: Array<number> | null = null): Array<HTMLCanvasElement> {
98
105
  const { width, height } = this.viewOptions.docPageSettings;
99
- const canvasList = [];
106
+ const canvasList: Array<HTMLCanvasElement> = [];
100
107
  for (let i = 0; i < printPages.length; i++) {
101
108
  if (printRanges && printRanges.indexOf(i) === -1) {
102
109
  continue;
@@ -105,7 +112,7 @@ export class DocumentPrintOffscreen {
105
112
  canvasNode.style.cursor = 'text';
106
113
  canvasNode.style.width = width + 'px';
107
114
  canvasNode.style.height = height + 'px';
108
- const ctx = canvasNode.getContext('2d');
115
+ const ctx = canvasNode.getContext('2d') as CanvasRenderingContext2D;
109
116
  ElementUtil.setCanvasProps(canvasNode, ctx, this.viewOptions.docPageSettings);
110
117
  const renderCtx = new RenderContenxt(ctx, this.viewOptions, this.docCtx);
111
118
  renderCtx.setCanvasProps(this.viewOptions.docPageSettings);
@@ -125,4 +132,3 @@ export class DocumentPrintOffscreen {
125
132
  return canvasList;
126
133
  }
127
134
  }
128
- //# sourceMappingURL=document-print-offscreen.js.map
@@ -1,11 +1,14 @@
1
- import { PageOptions } from "./element-define";
1
+ import { EditorContext } from "./document-context";
2
+ import { SelectionState } from "./document-selection";
3
+ import { OrientType, PageOptions, ViewOptions } from "./element-define";
2
4
  import { ElementPaint } from "./element-paint";
3
5
  import { ElementUtil } from "./element-util";
4
6
  import { DocumentRenderObject } from "./impl/document/doc-impl";
5
7
  import { RenderContenxt } from "./render-context";
6
- import { jsPDF } from 'jspdf';
8
+ import { jsPDF } from 'jspdf'
9
+
7
10
  export class documentPrint {
8
- static print(ss, viewOptions, docCtx, printRanges = null) {
11
+ static print(ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext, printRanges: Array<number> | null = null): void {
9
12
  const renderCanvasNodes = this.getRenderCanvasNodes(ss, viewOptions, docCtx, printRanges);
10
13
  if (!renderCanvasNodes.length) {
11
14
  console.warn('无可打印节点');
@@ -13,22 +16,23 @@ export class documentPrint {
13
16
  }
14
17
  printNodes(renderCanvasNodes, { ...docCtx.document.props });
15
18
  }
19
+
16
20
  /**
17
21
  * 获取绘制的canvas节点
18
- * @param ss
19
- * @param viewOptions
20
- * @param docCtx
21
- * @param printRanges
22
- * @returns
22
+ * @param ss
23
+ * @param viewOptions
24
+ * @param docCtx
25
+ * @param printRanges
26
+ * @returns
23
27
  */
24
- static getRenderCanvasNodes(ss, viewOptions, docCtx, printRanges = null) {
28
+ private static getRenderCanvasNodes(ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext, printRanges: Array<number> | null = null): Array<HTMLCanvasElement> {
25
29
  const { width, height } = viewOptions.docPageSettings;
26
30
  const dc = ss.renderContainer;
27
- const canvasList = [];
28
- const printPages = [];
31
+ const canvasList: Array<HTMLCanvasElement> = [];
32
+ const printPages: Array<DocumentRenderObject> = [];
29
33
  for (let i = 0; i < dc.length; i++) {
30
34
  if (!printRanges || printRanges.some(pageIndex => pageIndex === i)) {
31
- printPages.push(dc.getChild(i));
35
+ printPages.push(<DocumentRenderObject>dc.getChild(i));
32
36
  }
33
37
  }
34
38
  for (let i = 0; i < printPages.length; i++) {
@@ -36,7 +40,7 @@ export class documentPrint {
36
40
  canvasNode.style.cursor = 'text';
37
41
  canvasNode.style.width = width + 'px';
38
42
  canvasNode.style.height = height + 'px';
39
- const ctx = canvasNode.getContext('2d');
43
+ const ctx = canvasNode.getContext('2d') as CanvasRenderingContext2D;
40
44
  ElementUtil.setCanvasProps(canvasNode, ctx, viewOptions.docPageSettings);
41
45
  const renderCtx = new RenderContenxt(ctx, viewOptions, docCtx);
42
46
  renderCtx.setCanvasProps(viewOptions.docPageSettings);
@@ -53,19 +57,21 @@ export class documentPrint {
53
57
  doc.rect = tmp;
54
58
  canvasList.push(canvasNode);
55
59
  }
56
- return canvasList;
60
+ return canvasList
57
61
  }
62
+
58
63
  /**
59
64
  * 导出base64
60
- * @param ss
61
- * @param viewOptions
62
- * @param docCtx
63
- * @param printRanges
64
- * @returns
65
+ * @param ss
66
+ * @param viewOptions
67
+ * @param docCtx
68
+ * @param printRanges
69
+ * @returns
65
70
  */
66
- static exportCanvasNodes(ss, viewOptions, docCtx, printRanges = null) {
71
+ static exportCanvasNodes(ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext, printRanges: Array<number> | null = null): Array<HTMLCanvasElement> {
67
72
  return this.getRenderCanvasNodes(ss, viewOptions, docCtx, printRanges);
68
73
  }
74
+
69
75
  /**
70
76
  * 导出PDF
71
77
  * @param fileName
@@ -74,16 +80,17 @@ export class documentPrint {
74
80
  * @param docCtx
75
81
  * @param printRanges
76
82
  */
77
- static exportPDF(fileName, ss, viewOptions, docCtx, printRanges = null) {
83
+ static exportPDF(fileName: string, ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext, printRanges: Array<number> | null = null): void {
78
84
  const nodes = this.getRenderCanvasNodes(ss, viewOptions, docCtx, printRanges);
79
- exportCanvasToPDF(fileName, nodes, { ...docCtx.document.props });
85
+ exportCanvasToPDF(fileName, nodes, { ...docCtx.document.props })
80
86
  }
87
+
81
88
  /**
82
89
  * 当前当前页
83
- * @param ss
84
- * @param viewOptions
90
+ * @param ss
91
+ * @param viewOptions
85
92
  */
86
- static printCurrPage(ss, viewOptions, docCtx) {
93
+ static printCurrPage(ss: SelectionState, viewOptions: ViewOptions, docCtx: EditorContext,): void {
87
94
  const { startHitInfo } = ss;
88
95
  if (!startHitInfo) {
89
96
  return;
@@ -95,7 +102,9 @@ export class documentPrint {
95
102
  this.print(ss, viewOptions, docCtx, [docPage.getIndex()]);
96
103
  }
97
104
  }
98
- export function createPrintTemplate({ width, height, orient }) {
105
+
106
+
107
+ export function createPrintTemplate({ width, height, orient }: PageOptions): string {
99
108
  const str = `
100
109
  <!DOCTYPE html>
101
110
  <html lang="zh">
@@ -139,14 +148,22 @@ export function createPrintTemplate({ width, height, orient }) {
139
148
  `.replace(/\n/g, '').replace(/\s+/g, ' ').replace(/'/g, '\\\'');
140
149
  return str;
141
150
  }
151
+
152
+
153
+ type PrintPaperOptions = {
154
+ width: number;
155
+ height: number;
156
+ orient: OrientType;
157
+ };
158
+
142
159
  /**
143
160
  * 打印DOM
144
- * @param printNodes
145
- * @param options
146
- * @returns
161
+ * @param printNodes
162
+ * @param options
163
+ * @returns
147
164
  */
148
- export function printNodes(printNodes, options) {
149
- const printIFrame = document.createElement("iframe");
165
+ export function printNodes(printNodes: Array<Node>, options: PrintPaperOptions): void {
166
+ const printIFrame = document.createElement("iframe") as HTMLIFrameElement;
150
167
  printIFrame.src = 'about:blank';
151
168
  printIFrame.style.borderWidth = '0';
152
169
  printIFrame.style.height = "0";
@@ -157,7 +174,7 @@ export function printNodes(printNodes, options) {
157
174
  console.warn('无可打印节点');
158
175
  return;
159
176
  }
160
- const printSize = new PageOptions(options.width, options.height, options.orient);
177
+ const printSize: PageOptions = new PageOptions(options.width, options.height, options.orient);
161
178
  const iframeHTML = createPrintTemplate(printSize);
162
179
  printIFrame.contentWindow?.document.write(iframeHTML);
163
180
  printIFrame.contentWindow?.document.close();
@@ -165,7 +182,7 @@ export function printNodes(printNodes, options) {
165
182
  const item = printNodes[i];
166
183
  const div = document.createElement('div');
167
184
  div.appendChild(item);
168
- printIFrame.contentWindow?.document.body.appendChild(div);
185
+ printIFrame.contentWindow?.document.body.appendChild(div)
169
186
  }
170
187
  printIFrame.contentWindow?.document.body.focus();
171
188
  setTimeout(() => {
@@ -173,17 +190,17 @@ export function printNodes(printNodes, options) {
173
190
  printIFrame.parentNode?.removeChild(printIFrame);
174
191
  }, 0);
175
192
  }
193
+
176
194
  /**
177
195
  * canvas节点导出到PDF
178
- * @param fileName
179
- * @param nodes
180
- * @param options
196
+ * @param fileName
197
+ * @param nodes
198
+ * @param options
181
199
  */
182
- export function exportCanvasToPDF(fileName, nodes, options) {
200
+ export function exportCanvasToPDF(fileName: string, nodes: Array<HTMLCanvasElement>, options: PrintPaperOptions): void {
183
201
  if (!fileName) {
184
202
  fileName = 'document.pdf';
185
- }
186
- else {
203
+ } else {
187
204
  fileName = fileName.replace(/[\/\\:*?"<>|]/g, '_');
188
205
  if (!fileName.endsWith('.pdf')) {
189
206
  fileName += '.pdf';
@@ -199,5 +216,4 @@ export function exportCanvasToPDF(fileName, nodes, options) {
199
216
  }
200
217
  }
201
218
  pdf.save(fileName);
202
- }
203
- //# sourceMappingURL=document-print.js.map
219
+ }
@@ -0,0 +1,211 @@
1
+ import { Element, LeafElement } from "./element-define";
2
+ import { TextGroupElement } from "./impl/text/text-impl";
3
+ import { ElementUtil } from "./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
+ }