@hailin-zheng/editor-core 1.0.15 → 1.0.22

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 (149) hide show
  1. package/README.md +1613 -0
  2. package/lib/framework/element-props.d.ts +2 -2
  3. package/lib/framework/impl/index.d.ts +36 -0
  4. package/lib/index.d.ts +34 -0
  5. package/lib/index.js +15672 -0
  6. package/lib/texteditor.d.ts +3 -3
  7. package/package.json +27 -26
  8. package/lib/doc-ruler.js +0 -313
  9. package/lib/doc-ruler.js.map +0 -1
  10. package/lib/framework/common-util.js +0 -178
  11. package/lib/framework/common-util.js.map +0 -1
  12. package/lib/framework/document-change.js +0 -1342
  13. package/lib/framework/document-change.js.map +0 -1
  14. package/lib/framework/document-combine.js +0 -40
  15. package/lib/framework/document-combine.js.map +0 -1
  16. package/lib/framework/document-comment.js +0 -148
  17. package/lib/framework/document-comment.js.map +0 -1
  18. package/lib/framework/document-context.js +0 -330
  19. package/lib/framework/document-context.js.map +0 -1
  20. package/lib/framework/document-eval-func.js +0 -48
  21. package/lib/framework/document-eval-func.js.map +0 -1
  22. package/lib/framework/document-event.js +0 -1054
  23. package/lib/framework/document-event.js.map +0 -1
  24. package/lib/framework/document-history.js +0 -65
  25. package/lib/framework/document-history.js.map +0 -1
  26. package/lib/framework/document-images-loader.js +0 -66
  27. package/lib/framework/document-images-loader.js.map +0 -1
  28. package/lib/framework/document-input-cursor.js +0 -239
  29. package/lib/framework/document-input-cursor.js.map +0 -1
  30. package/lib/framework/document-paint.js +0 -103
  31. package/lib/framework/document-paint.js.map +0 -1
  32. package/lib/framework/document-print-offscreen.js +0 -128
  33. package/lib/framework/document-print-offscreen.js.map +0 -1
  34. package/lib/framework/document-print.js +0 -203
  35. package/lib/framework/document-print.js.map +0 -1
  36. package/lib/framework/document-segmenter.js +0 -106
  37. package/lib/framework/document-segmenter.js.map +0 -1
  38. package/lib/framework/document-selection.js +0 -358
  39. package/lib/framework/document-selection.js.map +0 -1
  40. package/lib/framework/document-template.js +0 -20
  41. package/lib/framework/document-template.js.map +0 -1
  42. package/lib/framework/document-textline-mode.js +0 -30
  43. package/lib/framework/document-textline-mode.js.map +0 -1
  44. package/lib/framework/element-define.js +0 -579
  45. package/lib/framework/element-define.js.map +0 -1
  46. package/lib/framework/element-event-define.js +0 -108
  47. package/lib/framework/element-event-define.js.map +0 -1
  48. package/lib/framework/element-measure.js +0 -551
  49. package/lib/framework/element-measure.js.map +0 -1
  50. package/lib/framework/element-paint.js +0 -170
  51. package/lib/framework/element-paint.js.map +0 -1
  52. package/lib/framework/element-props.js +0 -809
  53. package/lib/framework/element-props.js.map +0 -1
  54. package/lib/framework/element-reader.js +0 -151
  55. package/lib/framework/element-reader.js.map +0 -1
  56. package/lib/framework/element-render-cut.js +0 -449
  57. package/lib/framework/element-render-cut.js.map +0 -1
  58. package/lib/framework/element-serialize.js +0 -113
  59. package/lib/framework/element-serialize.js.map +0 -1
  60. package/lib/framework/element-util.js +0 -1463
  61. package/lib/framework/element-util.js.map +0 -1
  62. package/lib/framework/impl/checkbox/checkbox-impl.js +0 -64
  63. package/lib/framework/impl/checkbox/checkbox-impl.js.map +0 -1
  64. package/lib/framework/impl/comments/comment-content-impl.js +0 -105
  65. package/lib/framework/impl/comments/comment-content-impl.js.map +0 -1
  66. package/lib/framework/impl/comments/comment-element-impl.js +0 -62
  67. package/lib/framework/impl/comments/comment-element-impl.js.map +0 -1
  68. package/lib/framework/impl/comments/comments-container-impl.js +0 -62
  69. package/lib/framework/impl/comments/comments-container-impl.js.map +0 -1
  70. package/lib/framework/impl/comments/comments-util.js +0 -67
  71. package/lib/framework/impl/comments/comments-util.js.map +0 -1
  72. package/lib/framework/impl/comments/validate-msg-impl.js +0 -83
  73. package/lib/framework/impl/comments/validate-msg-impl.js.map +0 -1
  74. package/lib/framework/impl/data-element/data-decorate-impl.js +0 -91
  75. package/lib/framework/impl/data-element/data-decorate-impl.js.map +0 -1
  76. package/lib/framework/impl/data-element/data-element-barcode.js +0 -115
  77. package/lib/framework/impl/data-element/data-element-barcode.js.map +0 -1
  78. package/lib/framework/impl/data-element/data-element-base-impl.js +0 -205
  79. package/lib/framework/impl/data-element/data-element-base-impl.js.map +0 -1
  80. package/lib/framework/impl/data-element/data-element-check-impl.js +0 -133
  81. package/lib/framework/impl/data-element/data-element-check-impl.js.map +0 -1
  82. package/lib/framework/impl/data-element/data-element-date-impl.js +0 -111
  83. package/lib/framework/impl/data-element/data-element-date-impl.js.map +0 -1
  84. package/lib/framework/impl/data-element/data-element-group-impl.js +0 -130
  85. package/lib/framework/impl/data-element/data-element-group-impl.js.map +0 -1
  86. package/lib/framework/impl/data-element/data-element-image-impl.js +0 -137
  87. package/lib/framework/impl/data-element/data-element-image-impl.js.map +0 -1
  88. package/lib/framework/impl/data-element/data-element-list-impl.js +0 -131
  89. package/lib/framework/impl/data-element/data-element-list-impl.js.map +0 -1
  90. package/lib/framework/impl/data-element/data-element-text-impl.js +0 -103
  91. package/lib/framework/impl/data-element/data-element-text-impl.js.map +0 -1
  92. package/lib/framework/impl/decorate/fill-null-space-imple.js +0 -43
  93. package/lib/framework/impl/decorate/fill-null-space-imple.js.map +0 -1
  94. package/lib/framework/impl/document/doc-body-impl.js +0 -79
  95. package/lib/framework/impl/document/doc-body-impl.js.map +0 -1
  96. package/lib/framework/impl/document/doc-body-part-impl.js +0 -94
  97. package/lib/framework/impl/document/doc-body-part-impl.js.map +0 -1
  98. package/lib/framework/impl/document/doc-container-impl.js +0 -21
  99. package/lib/framework/impl/document/doc-container-impl.js.map +0 -1
  100. package/lib/framework/impl/document/doc-footer-impl.js +0 -77
  101. package/lib/framework/impl/document/doc-footer-impl.js.map +0 -1
  102. package/lib/framework/impl/document/doc-header-impl.js +0 -83
  103. package/lib/framework/impl/document/doc-header-impl.js.map +0 -1
  104. package/lib/framework/impl/document/doc-impl.js +0 -209
  105. package/lib/framework/impl/document/doc-impl.js.map +0 -1
  106. package/lib/framework/impl/media-formula/menstrual-history.js +0 -153
  107. package/lib/framework/impl/media-formula/menstrual-history.js.map +0 -1
  108. package/lib/framework/impl/paragraph/p-impl.js +0 -156
  109. package/lib/framework/impl/paragraph/p-impl.js.map +0 -1
  110. package/lib/framework/impl/picture/image-impl.js +0 -124
  111. package/lib/framework/impl/picture/image-impl.js.map +0 -1
  112. package/lib/framework/impl/radio/radio-impl.js +0 -72
  113. package/lib/framework/impl/radio/radio-impl.js.map +0 -1
  114. package/lib/framework/impl/symbol/br-symbol-impl.js +0 -54
  115. package/lib/framework/impl/symbol/br-symbol-impl.js.map +0 -1
  116. package/lib/framework/impl/symbol/p-symbol-impl.js +0 -54
  117. package/lib/framework/impl/symbol/p-symbol-impl.js.map +0 -1
  118. package/lib/framework/impl/table/table-cell-impl.js +0 -145
  119. package/lib/framework/impl/table/table-cell-impl.js.map +0 -1
  120. package/lib/framework/impl/table/table-impl.js +0 -363
  121. package/lib/framework/impl/table/table-impl.js.map +0 -1
  122. package/lib/framework/impl/table/table-row-impl.js +0 -75
  123. package/lib/framework/impl/table/table-row-impl.js.map +0 -1
  124. package/lib/framework/impl/table/table-split-cell-patch.js +0 -89
  125. package/lib/framework/impl/table/table-split-cell-patch.js.map +0 -1
  126. package/lib/framework/impl/table/table-split-cell.js +0 -464
  127. package/lib/framework/impl/table/table-split-cell.js.map +0 -1
  128. package/lib/framework/impl/table/table-util.js +0 -678
  129. package/lib/framework/impl/table/table-util.js.map +0 -1
  130. package/lib/framework/impl/text/text-impl.js +0 -149
  131. package/lib/framework/impl/text/text-impl.js.map +0 -1
  132. package/lib/framework/impl/text/track-run-impl.js +0 -112
  133. package/lib/framework/impl/text/track-run-impl.js.map +0 -1
  134. package/lib/framework/notify.js +0 -116
  135. package/lib/framework/notify.js.map +0 -1
  136. package/lib/framework/range-util.js +0 -312
  137. package/lib/framework/range-util.js.map +0 -1
  138. package/lib/framework/render-context.js +0 -384
  139. package/lib/framework/render-context.js.map +0 -1
  140. package/lib/framework/render-define.js +0 -195
  141. package/lib/framework/render-define.js.map +0 -1
  142. package/lib/framework/selection-overlays.js +0 -124
  143. package/lib/framework/selection-overlays.js.map +0 -1
  144. package/lib/texteditor.js +0 -913
  145. package/lib/texteditor.js.map +0 -1
  146. package/lib/util/subject.js +0 -88
  147. package/lib/util/subject.js.map +0 -1
  148. package/lib/util/table-bind.js +0 -6
  149. package/lib/util/table-bind.js.map +0 -1
@@ -3,10 +3,10 @@ import { ElementReader } from './framework/element-reader';
3
3
  import { Subject } from 'rxjs';
4
4
  import { SelectionState } from './framework/document-selection';
5
5
  import { BranchElement, Element, ICancelTokenFn, LeafElement, MarginProps, OrientType, Position, TextAlign, ViewOptions } from './framework/element-define';
6
- import { DataElementInlineGroup, DataElementLeaf } from './framework/impl/data-element/data-element-base-impl';
6
+ import { DataElementInlineGroup, DataElementLeaf } from './framework/impl';
7
7
  import { ParagraphProps, TextProps } from './framework/element-props';
8
8
  import { EditorContext } from './framework/document-context';
9
- import { DocumentElement } from './framework/impl/document/doc-impl';
9
+ import { DocumentElement } from './framework/impl';
10
10
  export declare class CanvasTextEditor {
11
11
  private docScroll;
12
12
  private holdSpace;
@@ -113,7 +113,7 @@ export declare class CanvasTextEditor {
113
113
  x: number;
114
114
  y: number;
115
115
  translateY: number;
116
- };
116
+ } | undefined;
117
117
  /**
118
118
  * 获取文档模型
119
119
  * @returns
package/package.json CHANGED
@@ -1,42 +1,43 @@
1
1
  {
2
2
  "name": "@hailin-zheng/editor-core",
3
- "version": "1.0.15",
4
- "description": "",
5
- "main": "texteditor.ts",
6
- "scripts": {
7
- "test": "echo \"Error: on test\"",
8
- "build": "webpack",
9
- "watch": "webpack --watch",
10
- "start": "webpack serve --open",
11
- "build-ts": "tsc"
12
- },
13
3
  "keywords": [],
14
4
  "author": "",
15
5
  "private": false,
16
6
  "license": "ISC",
17
- "devDependencies": {
18
- "clean-webpack-plugin": "^4.0.0",
19
- "css-loader": "^6.7.1",
20
- "file-loader": "^6.2.0",
21
- "html-webpack-plugin": "^5.5.0",
22
- "style-loader": "^3.3.1",
23
- "ts-loader": "^9.3.1",
24
- "typescript": "^4.7.4",
25
- "webpack": "^5.73.0",
26
- "webpack-cli": "^4.10.0",
27
- "webpack-dev-server": "^4.9.2",
28
- "@types/file-saver": "^2.0.5",
29
- "@types/node": "^17.0.23",
30
- "@types/resize-observer-browser": "^0.1.6",
31
- "@types/bwip-js": "^3.0.0"
7
+ "version": "1.0.22",
8
+ "scripts": {
9
+ "dev": "vite",
10
+ "build": "vue-tsc --noEmit && vite build",
11
+ "preview": "vite preview",
12
+ "clean": "rimraf lib/",
13
+ "build-ts": "npm run clean && tsc --project tsconfig.build-lib.json",
14
+ "publish": "npm publish --access public",
15
+ "build-rollup": "rollup --config"
32
16
  },
33
17
  "dependencies": {
34
18
  "bwip-js": "^3.0.5",
19
+ "element-plus": "^2.0.2",
35
20
  "file-saver": "^2.0.5",
36
21
  "jspdf": "^2.5.1",
37
22
  "moment": "^2.29.3",
38
23
  "nanoid": "^3.1.30",
39
- "rxjs": "^6.6.7"
24
+ "rxjs": "^6.6.7",
25
+ "vue": "^3.2.25"
26
+ },
27
+ "devDependencies": {
28
+ "@types/bwip-js": "^3.0.0",
29
+ "@types/file-saver": "^2.0.5",
30
+ "@types/node": "^17.0.23",
31
+ "@types/resize-observer-browser": "^0.1.6",
32
+ "@vitejs/plugin-vue": "^2.2.0",
33
+ "sass": "^1.32.7",
34
+ "sass-loader": "^12.0.0",
35
+ "typescript": "^4.5.4",
36
+ "vite": "^2.8.0",
37
+ "vue-tsc": "^0.29.8",
38
+ "rimraf": "^3.0.2",
39
+ "rollup": "^2.75.7",
40
+ "@rollup/plugin-typescript": "^8.3.3"
40
41
  },
41
42
  "files": [
42
43
  "lib",
package/lib/doc-ruler.js DELETED
@@ -1,313 +0,0 @@
1
- import { ElementUtil } from "./framework/element-util";
2
- import { DocumentCursor } from "./framework/document-selection";
3
- import { DocumentRenderObject } from "./framework/impl/document/doc-impl";
4
- import { ParagraphElement, ParagraphRenderObject } from "./framework/impl/paragraph/p-impl";
5
- import { TableRowRenderObject } from "./framework/impl/table/table-row-impl";
6
- export class DocRule {
7
- canvas;
8
- viewOptions;
9
- ss;
10
- ctx;
11
- options;
12
- //标尺高度
13
- ruleHeight = 30;
14
- //当前标尺的位置
15
- thumbX;
16
- mouseDownPos;
17
- indentThumbPoints = [];
18
- hangThumbPoints = [];
19
- mouseDownThumbType = 'none';
20
- constructor(canvas, viewOptions, ss) {
21
- this.canvas = canvas;
22
- this.viewOptions = viewOptions;
23
- this.ss = ss;
24
- this.ctx = this.canvas.getContext('2d');
25
- this.options = {
26
- width: 0,
27
- pagePL: 0,
28
- pagePR: 0,
29
- docLeft: 0
30
- };
31
- this.thumbX = {
32
- indent: 0,
33
- hanging: 0
34
- };
35
- this.canvas.addEventListener("mousedown", (evt) => this.canvasMousedown(evt));
36
- this.canvas.addEventListener("mousemove", (evt) => this.canvasMousemove(evt));
37
- this.canvas.addEventListener("mouseup", (evt) => this.canvasMouseup(evt));
38
- }
39
- destroy() {
40
- this.canvas.removeEventListener("mousedown", this.canvasMousedown);
41
- this.canvas.removeEventListener("mousemove", this.canvasMousemove);
42
- this.canvas.removeEventListener("mouseup", this.canvasMouseup);
43
- }
44
- setRuleOptions(options) {
45
- this.options = options;
46
- const convertRatio = this.viewOptions.mmToPixelsRatio;
47
- this.options.pagePL = Math.floor(this.options.pagePL * convertRatio);
48
- this.options.pagePR = Math.floor(this.options.pagePR * convertRatio);
49
- this.scaleView();
50
- ElementUtil.setCanvasProps(this.canvas, this.ctx, { width: this.getParentWidth(), height: this.ruleHeight });
51
- //this.canvas.style.left = this.options.docLeft + 'px';
52
- }
53
- getParentWidth() {
54
- const parent = this.canvas.parentElement;
55
- return parent.getBoundingClientRect().width;
56
- }
57
- fillRect(x, y, width, height, color) {
58
- this.ctx.fillStyle = color;
59
- this.ctx.fillRect(x, y, width, height);
60
- }
61
- drawIndentThumb(x, y) {
62
- const points = [];
63
- x -= 4;
64
- points.push({ x: x, y });
65
- points.push({ x: x, y: y + 3 });
66
- points.push({ x: x + 4, y: y + 7 });
67
- points.push({ x: x + 8, y: y + 3 });
68
- points.push({ x: x + 8, y });
69
- points.push({ x: x, y });
70
- this.drawLine(points);
71
- return points;
72
- }
73
- drawHangThumb(x, y) {
74
- const points = [];
75
- x -= 4;
76
- points.push({ x: x, y });
77
- points.push({ x: x, y: y - 3 });
78
- points.push({ x: x + 4, y: y - 7 });
79
- points.push({ x: x + 8, y: y - 3 });
80
- points.push({ x: x + 8, y });
81
- points.push({ x: x, y });
82
- points.push({ x: x, y: y + 3 });
83
- points.push({ x: x + 8, y: y + 3 });
84
- points.push({ x: x + 8, y: y });
85
- this.drawLine(points);
86
- return points;
87
- }
88
- measureText(text) {
89
- this.ctx.font = "8px 'Times New Roman'";
90
- const measure = this.ctx.measureText(text);
91
- return measure.width;
92
- }
93
- drawLine(points) {
94
- this.ctx.beginPath();
95
- this.ctx.save();
96
- this.ctx.fillStyle = "white";
97
- this.ctx.lineWidth = 0.5;
98
- for (let j = 0; j < points.length; j++) {
99
- let { x, y } = points[j];
100
- x += 0.5;
101
- y += 0.5;
102
- if (j === 0) {
103
- this.ctx.moveTo(x, y);
104
- }
105
- else {
106
- this.ctx.lineTo(x, y);
107
- }
108
- }
109
- this.ctx.stroke();
110
- this.ctx.fill();
111
- this.ctx.closePath();
112
- this.ctx.restore();
113
- }
114
- drawText(text, x, y) {
115
- this.ctx.save();
116
- this.ctx.fillStyle = "rgb(0,0,0)";
117
- this.ctx.textBaseline = "alphabetic";
118
- this.ctx.font = "8px 'Times New Roman'";
119
- this.ctx.fillText(text, x, y + 8 - 1);
120
- this.ctx.restore();
121
- }
122
- /**
123
- * 刷新新的状态
124
- * @param indent
125
- * @param hang
126
- */
127
- refreshRule() {
128
- this.ctx.clearRect(0, 0, this.canvas.width, this.ruleHeight);
129
- this.ctx.save();
130
- this.ctx.translate(this.options.docLeft, 0);
131
- this.drawRule();
132
- this.ctx.restore();
133
- }
134
- canvasMousedown(evt) {
135
- const clickPos = this.getMousePos(evt);
136
- if (this.pointInPoly(clickPos, this.indentThumbPoints)) {
137
- this.mouseDownThumbType = 'indent';
138
- this.mouseDownPos = clickPos;
139
- }
140
- else if (this.pointInPoly(clickPos, this.hangThumbPoints)) {
141
- this.mouseDownThumbType = 'hang';
142
- this.mouseDownPos = clickPos;
143
- }
144
- else {
145
- console.log("未点击在里面");
146
- }
147
- }
148
- getMousePos(evt) {
149
- return {
150
- x: evt.offsetX - this.options.docLeft,
151
- y: evt.offsetY
152
- };
153
- }
154
- canvasMousemove(evt) {
155
- if (['indent', 'hang'].indexOf(this.mouseDownThumbType) < 0) {
156
- return;
157
- }
158
- if (!this.mouseDownPos) {
159
- return;
160
- }
161
- const canvasPos = this.getMousePos(evt);
162
- let moveX = canvasPos.x - this.mouseDownPos.x;
163
- //至少移动5px再进行修改
164
- const remainder = moveX % 5;
165
- if (Math.abs(remainder) < 3) {
166
- return;
167
- }
168
- else {
169
- if (remainder < 0) {
170
- moveX -= 5 + remainder;
171
- }
172
- else {
173
- moveX += 5 - remainder;
174
- }
175
- }
176
- if (moveX === 0) {
177
- return;
178
- }
179
- canvasPos.x = this.mouseDownPos.x + moveX;
180
- const para = this.getCurrPara();
181
- if (!para) {
182
- throw new Error('para is null');
183
- }
184
- if (this.mouseDownThumbType === 'indent') {
185
- this.thumbX.indent += moveX;
186
- this.thumbX.indent = this.thumbX.indent < 0 ? 0 : this.thumbX.indent;
187
- this.thumbX.indent = this.thumbX.indent > this.options.width ? this.options.width : this.thumbX.indent;
188
- this.mouseDownPos = canvasPos;
189
- para.props.indent += moveX;
190
- this.drawRule();
191
- }
192
- if (this.mouseDownThumbType === 'hang') {
193
- this.thumbX.hanging += moveX;
194
- this.thumbX.hanging = this.thumbX.hanging < 0 ? 0 : this.thumbX.hanging;
195
- this.thumbX.hanging = this.thumbX.hanging > this.options.width ? this.options.width : this.thumbX.hanging;
196
- this.mouseDownPos = canvasPos;
197
- para.props.hanging += moveX;
198
- this.drawRule();
199
- }
200
- }
201
- canvasMouseup(evt) {
202
- this.mouseDownThumbType = 'none';
203
- this.mouseDownPos = null;
204
- }
205
- pointInPoly(pt, poly) {
206
- let c = false;
207
- for (let i = -1, l = poly.length, j = l - 1; ++i < l; j = i) {
208
- if (((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y)) && pt.x < ((poly[j].x - poly[i].x) * (pt.y - poly[i].y)) / (poly[j].y - poly[i].y) + poly[i].x) {
209
- c = !c;
210
- }
211
- }
212
- return c;
213
- }
214
- /**
215
- * 绘制
216
- */
217
- drawRule() {
218
- this.fillRect(0, 0, this.options.pagePL, this.ruleHeight, "rgb(198,198,198)");
219
- this.fillRect(this.options.width - this.options.pagePR, 0, this.options.pagePR, this.ruleHeight, "rgb(198,198,198)");
220
- for (let j = 0; j < 50; j++) {
221
- const gantWidth = 20;
222
- const points = [];
223
- const x = j * gantWidth;
224
- if (x > this.options.width) {
225
- break;
226
- }
227
- const y = 10;
228
- points.push({ x, y }, { x, y: y + 10 });
229
- this.drawLine(points);
230
- const textWidth = this.measureText(j + "");
231
- this.drawText(j + '', x + Math.floor((gantWidth - textWidth) / 2), y + 1);
232
- }
233
- this.getRuleMarksPos();
234
- this.indentThumbPoints = this.drawIndentThumb(this.thumbX.indent, 6);
235
- this.hangThumbPoints = this.drawHangThumb(this.thumbX.hanging, 25);
236
- }
237
- getRuleMarksPos() {
238
- const { startControl, startOffset, startHitInfo } = this.ss;
239
- if (!startControl || !startHitInfo) {
240
- return;
241
- }
242
- const para = ElementUtil.getParentByType(startControl, ParagraphElement);
243
- const indent = para.props.indent;
244
- const hanging = para.props.hanging;
245
- const { startRegion, hitDocIndex } = this.ss.startHitInfo;
246
- const cursorPosi = DocumentCursor.getElementCursorPos(startControl, startOffset, startRegion, hitDocIndex);
247
- //当前段落
248
- const paraRender = ElementUtil.getParentRender(cursorPosi.render, ParagraphRenderObject);
249
- //当前段落位置
250
- const paraRenderPos = ElementUtil.getRenderAbsolutePaintPos(paraRender);
251
- //当前文档
252
- const docRender = ElementUtil.getParentRender(paraRender, DocumentRenderObject);
253
- //当前文档位置
254
- const docRenderPos = ElementUtil.getRenderAbsolutePaintPos(docRender);
255
- this.thumbX.indent = paraRenderPos.x - docRenderPos.x + indent;
256
- this.thumbX.hanging = paraRenderPos.x - docRenderPos.x + hanging;
257
- this.setParentMarksPos(paraRender);
258
- }
259
- getCurrPara() {
260
- const { startControl, startOffset } = this.ss;
261
- if (!startControl) {
262
- return null;
263
- }
264
- return ElementUtil.getParentByType(startControl, ParagraphElement);
265
- }
266
- setParentMarksPos(childRender) {
267
- const items = [];
268
- const parentRender = childRender.parent;
269
- if (!parentRender || parentRender instanceof DocumentRenderObject) {
270
- return items;
271
- }
272
- if (parentRender instanceof TableRowRenderObject) {
273
- const docRender = ElementUtil.getParentRender(parentRender, DocumentRenderObject);
274
- const docRenderPos = ElementUtil.getRenderAbsolutePaintPos(docRender);
275
- for (let i = 0; i < parentRender.length; i++) {
276
- const cellRender = parentRender.getChild(i);
277
- const pos = ElementUtil.getRenderAbsolutePaintPos(cellRender);
278
- this.drawCellMark(pos.x - docRenderPos.x, 0, cellRender.padding.left);
279
- }
280
- }
281
- items.push(...this.setParentMarksPos(parentRender));
282
- return items;
283
- }
284
- drawCellMark(x, y, width) {
285
- x += 0.5;
286
- y += 0.5;
287
- this.fillRect(x, y, width, this.ruleHeight, 'rgb(198,198,198,0.2)');
288
- for (let i = 0; i < width; i++) {
289
- this.ctx.save();
290
- this.ctx.beginPath();
291
- this.ctx.lineWidth = 0.3;
292
- this.ctx.setLineDash([0.5, 0.5, 0.5]);
293
- this.ctx.moveTo(x + i, y);
294
- this.ctx.lineTo(x + i, y + this.ruleHeight);
295
- this.ctx.stroke();
296
- this.ctx.closePath();
297
- this.ctx.restore();
298
- }
299
- }
300
- scaleView() {
301
- return;
302
- const { scale } = this.viewOptions;
303
- //this.canvas.style.transformOrigin = 'center center';
304
- const parent = this.canvas.parentElement;
305
- if (scale === 1) {
306
- parent.style.transform = '';
307
- }
308
- else {
309
- parent.style.transform = `scale(${this.viewOptions.scale})`;
310
- }
311
- }
312
- }
313
- //# sourceMappingURL=doc-ruler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"doc-ruler.js","sourceRoot":"lib/","sources":["doc-ruler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAkB,MAAM,gCAAgC,CAAC;AAGhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAU7E,MAAM,OAAO,OAAO;IAcG;IAAkC;IAAiC;IAb9E,GAAG,CAA4B;IAC/B,OAAO,CAAc;IAC7B,MAAM;IACE,UAAU,GAAG,EAAE,CAAC;IACxB,SAAS;IACD,MAAM,CAGb;IACO,YAAY,CAAmB;IAC/B,iBAAiB,GAAoB,EAAE,CAAC;IACxC,eAAe,GAAoB,EAAE,CAAC;IACtC,kBAAkB,GAA+B,MAAM,CAAC;IAChE,YAAmB,MAAyB,EAAS,WAAwB,EAAS,EAAkB;QAArF,WAAM,GAAN,MAAM,CAAmB;QAAS,gBAAW,GAAX,WAAW,CAAa;QAAS,OAAE,GAAF,EAAE,CAAgB;QACpG,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAA6B,CAAC;QACpE,IAAI,CAAC,OAAO,GAAG;YACX,KAAK,EAAE,CAAC;YACR,MAAM,EAAE,CAAC;YACT,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,CAAC;SACb,CAAC;QACF,IAAI,CAAC,MAAM,GAAG;YACV,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,CAAC;SACb,CAAC;QACF,IAAI,CAAC,M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GAAG,CAAC,SAAS,EAAE,CAAC;YACrB,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC;YACzB,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YACtC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;YACrB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;SACtB;IACL,CAAC;IAED,SAAS;QACL,OAAO;QACP,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC;QACnC,sDAAsD;QACtD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,aAA+B,CAAC;QAC3D,IAAI,KAAK,KAAK,CAAC,EAAE;YACb,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC;SAC/B;aAAM;YACH,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK,GAAG,CAAC;SAC/D;IACL,CAAC;CAGJ","sourcesContent":["import { ElementUtil } from \"./framework/element-util\";\nimport { DocumentCursor, SelectionState } from \"./framework/document-selection\";\nimport { Position, ViewOptions } from \"./framework/element-define\";\nimport { HitEventInfo } from \"./framework/element-event-define\";\nimport { DocumentRenderObject } from \"./framework/impl/document/doc-impl\";\nimport { ParagraphElement, ParagraphRenderObject } from \"./framework/impl/paragraph/p-impl\";\nimport { TableCellRenderObject } from \"./framework/impl/table/table-cell-impl\";\nimport { TableRowRenderObject } from \"./framework/impl/table/table-row-impl\";\nimport { RenderObject } from \"./framework/render-define\";\n\nexport interface RuleOptions {\n width: number;\n pagePL: number;\n pagePR: number;\n docLeft: number;\n\n}\nexport class DocRule {\n private ctx!: CanvasRenderingContext2D;\n private options: RuleOptions;\n //标尺高度\n private ruleHeight = 30;\n //当前标尺的位置\n private thumbX: {\n indent: number,\n hanging: number\n }\n private mouseDownPos!: Position | null;\n private indentThumbPoints: Array<Position> = [];\n private hangThumbPoints: Array<Position> = [];\n private mouseDownThumbType: 'none' | 'indent' | 'hang' = 'none';\n constructor(public canvas: HTMLCanvasElement, public viewOptions: ViewOptions, public ss: SelectionState) {\n this.ctx = this.canvas.getContext('2d') as CanvasRenderingContext2D;\n this.options = {\n width: 0,\n pagePL: 0,\n pagePR: 0,\n docLeft: 0\n };\n this.thumbX = {\n indent: 0,\n hanging: 0\n };\n this.canvas.addEventListener(\"mousedown\", (evt) => this.canvasMousedown(evt));\n this.canvas.addEventListener(\"mousemove\", (evt) => this.canvasMousemove(evt));\n this.canvas.addEventListener(\"mouseup\", (evt) => this.canvasMouseup(evt));\n }\n\n destroy(): void {\n this.canvas.removeEventListener(\"mousedown\", this.canvasMousedown);\n this.canvas.removeEventListener(\"mousemove\", this.canvasMousemove);\n this.canvas.removeEventListener(\"mouseup\", this.canvasMouseup);\n }\n\n setRuleOptions(options: RuleOptions) {\n this.options = options;\n const convertRatio = this.viewOptions.mmToPixelsRatio;\n this.options.pagePL = Math.floor(this.options.pagePL * convertRatio);\n this.options.pagePR = Math.floor(this.options.pagePR * convertRatio);\n this.scaleView();\n ElementUtil.setCanvasProps(this.canvas, this.ctx, { width: this.getParentWidth(), height: this.ruleHeight });\n //this.canvas.style.left = this.options.docLeft + 'px';\n }\n\n getParentWidth(): number {\n const parent = this.canvas.parentElement as HTMLDivElement;\n return parent.getBoundingClientRect().width;\n }\n\n private fillRect(x: number, y: number, width: number, height: number, color: string) {\n this.ctx.fillStyle = color;\n this.ctx.fillRect(x, y, width, height);\n }\n\n private drawIndentThumb(x: number, y: number): Array<Position> {\n const points: Array<Position> = [];\n x -= 4;\n points.push({ x: x, y });\n points.push({ x: x, y: y + 3 });\n points.push({ x: x + 4, y: y + 7 });\n points.push({ x: x + 8, y: y + 3 });\n points.push({ x: x + 8, y });\n points.push({ x: x, y });\n this.drawLine(points);\n return points;\n }\n\n private drawHangThumb(x: number, y: number): Array<Position> {\n const points: Array<{ x: number, y: number }> = [];\n x -= 4;\n points.push({ x: x, y });\n points.push({ x: x, y: y - 3 });\n points.push({ x: x + 4, y: y - 7 });\n points.push({ x: x + 8, y: y - 3 });\n points.push({ x: x + 8, y });\n points.push({ x: x, y });\n points.push({ x: x, y: y + 3 });\n points.push({ x: x + 8, y: y + 3 });\n points.push({ x: x + 8, y: y });\n this.drawLine(points);\n return points;\n }\n\n private measureText(text: string) {\n this.ctx.font = \"8px 'Times New Roman'\";\n const measure = this.ctx.measureText(text);\n return measure.width;\n }\n\n private drawLine(points: Array<Position>): void {\n this.ctx.beginPath();\n this.ctx.save();\n this.ctx.fillStyle = \"white\";\n this.ctx.lineWidth = 0.5;\n for (let j = 0; j < points.length; j++) {\n let { x, y } = points[j];\n x += 0.5;\n y += 0.5;\n if (j === 0) {\n this.ctx.moveTo(x, y);\n } else {\n this.ctx.lineTo(x, y);\n }\n }\n this.ctx.stroke();\n this.ctx.fill();\n this.ctx.closePath();\n this.ctx.restore();\n }\n\n private drawText(text: string, x: number, y: number) {\n this.ctx.save();\n this.ctx.fillStyle = \"rgb(0,0,0)\";\n this.ctx.textBaseline = \"alphabetic\";\n this.ctx.font = \"8px 'Times New Roman'\";\n this.ctx.fillText(text, x, y + 8 - 1);\n this.ctx.restore();\n }\n\n /**\n * 刷新新的状态\n * @param indent \n * @param hang \n */\n refreshRule(): void {\n this.ctx.clearRect(0, 0, this.canvas.width, this.ruleHeight);\n this.ctx.save();\n this.ctx.translate(this.options.docLeft, 0);\n this.drawRule();\n this.ctx.restore();\n }\n\n private canvasMousedown(evt: MouseEvent): void {\n const clickPos = this.getMousePos(evt);\n if (this.pointInPoly(clickPos, this.indentThumbPoints)) {\n this.mouseDownThumbType = 'indent';\n this.mouseDownPos = clickPos;\n } else if (this.pointInPoly(clickPos, this.hangThumbPoints)) {\n this.mouseDownThumbType = 'hang';\n this.mouseDownPos = clickPos;\n } else {\n console.log(\"未点击在里面\");\n }\n }\n\n private getMousePos(evt: MouseEvent): Position {\n return {\n x: evt.offsetX - this.options.docLeft,\n y: evt.offsetY\n }\n }\n\n private canvasMousemove(evt: MouseEvent): void {\n if (['indent', 'hang'].indexOf(this.mouseDownThumbType) < 0) {\n return;\n }\n if (!this.mouseDownPos) {\n return;\n }\n const canvasPos = this.getMousePos(evt);\n let moveX = canvasPos.x - this.mouseDownPos.x;\n //至少移动5px再进行修改\n const remainder = moveX % 5;\n if (Math.abs(remainder) < 3) {\n return;\n } else {\n if (remainder < 0) {\n moveX -= 5 + remainder;\n } else {\n moveX += 5 - remainder;\n }\n }\n if (moveX === 0) {\n return;\n }\n canvasPos.x = this.mouseDownPos.x + moveX;\n const para = this.getCurrPara();\n if (!para) {\n throw new Error('para is null')\n }\n if (this.mouseDownThumbType === 'indent') {\n this.thumbX.indent += moveX;\n this.thumbX.indent = this.thumbX.indent < 0 ? 0 : this.thumbX.indent;\n this.thumbX.indent = this.thumbX.indent > this.options.width ? this.options.width : this.thumbX.indent;\n this.mouseDownPos = canvasPos;\n para.props.indent += moveX;\n this.drawRule();\n }\n if (this.mouseDownThumbType === 'hang') {\n this.thumbX.hanging += moveX;\n this.thumbX.hanging = this.thumbX.hanging < 0 ? 0 : this.thumbX.hanging;\n this.thumbX.hanging = this.thumbX.hanging > this.options.width ? this.options.width : this.thumbX.hanging;\n this.mouseDownPos = canvasPos;\n para.props.hanging += moveX;\n this.drawRule();\n }\n }\n\n private canvasMouseup(evt: MouseEvent): void {\n this.mouseDownThumbType = 'none';\n this.mouseDownPos = null;\n }\n\n\n private pointInPoly(pt: Position, poly: Array<Position>): boolean {\n let c = false;\n for (let i = -1, l = poly.length, j = l - 1; ++i < l; j = i) {\n if (((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y)) && pt.x < ((poly[j].x - poly[i].x) * (pt.y - poly[i].y)) / (poly[j].y - poly[i].y) + poly[i].x) {\n c = !c\n }\n }\n return c;\n }\n\n\n /**\n * 绘制\n */\n private drawRule(): void {\n this.fillRect(0, 0, this.options.pagePL, this.ruleHeight, \"rgb(198,198,198)\");\n this.fillRect(this.options.width - this.options.pagePR, 0, this.options.pagePR, this.ruleHeight, \"rgb(198,198,198)\");\n for (let j = 0; j < 50; j++) {\n const gantWidth = 20;\n const points: Array<Position> = [];\n const x = j * gantWidth;\n if (x > this.options.width) {\n break;\n }\n const y = 10;\n points.push({ x, y }, { x, y: y + 10 });\n this.drawLine(points);\n const textWidth = this.measureText(j + \"\");\n this.drawText(j + '', x + Math.floor((gantWidth - textWidth) / 2), y + 1);\n }\n this.getRuleMarksPos();\n this.indentThumbPoints = this.drawIndentThumb(this.thumbX.indent, 6);\n this.hangThumbPoints = this.drawHangThumb(this.thumbX.hanging, 25);\n }\n\n private getRuleMarksPos(): void {\n const { startControl, startOffset, startHitInfo } = this.ss;\n if (!startControl || !startHitInfo) {\n return;\n }\n const para = ElementUtil.getParentByType(startControl, ParagraphElement) as ParagraphElement;\n const indent = para.props.indent;\n const hanging = para.props.hanging;\n const { startRegion, hitDocIndex } = this.ss.startHitInfo as HitEventInfo;\n const cursorPosi = DocumentCursor.getElementCursorPos(startControl, startOffset, startRegion, hitDocIndex);\n //当前段落\n const paraRender = ElementUtil.getParentRender(cursorPosi.render, ParagraphRenderObject) as ParagraphRenderObject;\n //当前段落位置\n const paraRenderPos = ElementUtil.getRenderAbsolutePaintPos(paraRender)\n //当前文档\n const docRender = ElementUtil.getParentRender(paraRender, DocumentRenderObject) as DocumentRenderObject;\n //当前文档位置\n const docRenderPos = ElementUtil.getRenderAbsolutePaintPos(docRender)\n this.thumbX.indent = paraRenderPos.x - docRenderPos.x + indent;\n this.thumbX.hanging = paraRenderPos.x - docRenderPos.x + hanging;\n this.setParentMarksPos(paraRender);\n }\n\n private getCurrPara(): ParagraphElement | null {\n const { startControl, startOffset } = this.ss;\n if (!startControl) {\n return null;\n }\n return ElementUtil.getParentByType(startControl, ParagraphElement);\n }\n\n private setParentMarksPos(childRender: RenderObject): Array<{ pos: Position }> {\n const items: Array<{ pos: Position }> = [];\n const parentRender = childRender.parent;\n if (!parentRender || parentRender instanceof DocumentRenderObject) {\n return items;\n }\n if (parentRender instanceof TableRowRenderObject) {\n const docRender = ElementUtil.getParentRender(parentRender, DocumentRenderObject) as DocumentRenderObject;\n const docRenderPos = ElementUtil.getRenderAbsolutePaintPos(docRender)\n for (let i = 0; i < parentRender.length; i++) {\n const cellRender = parentRender.getChild(i) as TableCellRenderObject;\n const pos = ElementUtil.getRenderAbsolutePaintPos(cellRender)\n this.drawCellMark(pos.x - docRenderPos.x, 0, cellRender.padding.left);\n }\n }\n items.push(...this.setParentMarksPos(parentRender));\n return items;\n }\n\n private drawCellMark(x: number, y: number, width: number): void {\n x += 0.5;\n y += 0.5;\n this.fillRect(x, y, width, this.ruleHeight, 'rgb(198,198,198,0.2)')\n for (let i = 0; i < width; i++) {\n this.ctx.save();\n this.ctx.beginPath();\n this.ctx.lineWidth = 0.3;\n this.ctx.setLineDash([0.5, 0.5, 0.5]);\n this.ctx.moveTo(x + i, y);\n this.ctx.lineTo(x + i, y + this.ruleHeight);\n this.ctx.stroke();\n this.ctx.closePath();\n this.ctx.restore();\n }\n }\n\n scaleView(): void {\n return;\n const { scale } = this.viewOptions;\n //this.canvas.style.transformOrigin = 'center center';\n const parent = this.canvas.parentElement as HTMLDivElement;\n if (scale === 1) {\n parent.style.transform = '';\n } else {\n parent.style.transform = `scale(${this.viewOptions.scale})`;\n }\n }\n\n\n}\n"]}
@@ -1,178 +0,0 @@
1
- import moment from "moment";
2
- export class CommonUtil {
3
- /**
4
- * 判断坐标是否在矩形框内
5
- * @param rect
6
- * @param position
7
- * @returns
8
- */
9
- static isInsideRectByPosition(rect, position) {
10
- return position.x >= rect.x
11
- &&
12
- position.x <= rect.x + rect.width
13
- &&
14
- position.y >= rect.y
15
- &&
16
- position.y <= rect.y + rect.height;
17
- }
18
- static isInsideRectByRect(rect, position) {
19
- return position.x >= rect.x
20
- &&
21
- position.x <= rect.x + rect.width
22
- &&
23
- position.y >= rect.y
24
- &&
25
- position.y <= rect.y + rect.height
26
- &&
27
- position.y + position.height <= rect.y + rect.height
28
- &&
29
- position.x + position.width <= rect.x + rect.width;
30
- }
31
- /**
32
- * 判断坐标是否在矩形的边框上
33
- * @param rect
34
- * @param borderWidth
35
- * @param position
36
- */
37
- static isInRectBorder(rect, borderWidth, position) {
38
- const leftBorderRect = { x: 0, y: 0, width: borderWidth, height: rect.height, maxWidth: 0, maxHeight: 0 };
39
- const rightBorderRect = { x: rect.width - borderWidth, y: 0, width: borderWidth, height: rect.height, maxWidth: 0, maxHeight: 0 };
40
- const topBorderRect = { x: 0, y: 0, width: rect.width, height: borderWidth, maxWidth: 0, maxHeight: 0 };
41
- const bottomBorderRect = { x: 0, y: rect.height - borderWidth, width: rect.width, height: borderWidth, maxWidth: 0, maxHeight: 0 };
42
- let borderType = 'none';
43
- if (this.isInsideRectByPosition(leftBorderRect, position)) {
44
- borderType = 'left';
45
- }
46
- else if (this.isInsideRectByPosition(rightBorderRect, position)) {
47
- borderType = 'right';
48
- }
49
- else if (this.isInsideRectByPosition(topBorderRect, position)) {
50
- borderType = 'top';
51
- }
52
- else if (this.isInsideRectByPosition(bottomBorderRect, position)) {
53
- borderType = 'bottom';
54
- }
55
- return { borderType };
56
- }
57
- /**
58
- * 判断坐标是否在图片的缩放操作点上
59
- */
60
- static isInPictureResizePoint(rect, pos, r) {
61
- const { width, height } = rect;
62
- const x = 0;
63
- const y = 0;
64
- const points = [{ x, y, type: 'left-top' }, { x: x + width, y, type: 'right-top' }, { x: x + (Math.floor(width / 2)), y: y, type: 'top-middle' }, { x, y: y + Math.floor(height / 2), type: 'left-middle' }, { x, y: y + height, type: 'left-bottom' }, { x: width, y: Math.floor(height / 2), type: 'right-middle' }, { x: x + width, y: y + height, type: 'right-bottom' }, { x: x + (Math.floor(width / 2)), y: y + height, type: 'bottom-middle' }];
65
- for (let i = 0; i < points.length; i++) {
66
- const point = points[i];
67
- const { x: px, y: py } = point;
68
- if (((px - pos.x) * (px - pos.x) + (py - pos.y) * (py - pos.y)) < r * r) {
69
- return { borderType: point.type };
70
- }
71
- }
72
- return null;
73
- }
74
- /**
75
- * 整形符合连线要求
76
- * @param points
77
- * @param width
78
- * @param strokeColor
79
- */
80
- static resharpPoints(points) {
81
- let prevPoint = points[0];
82
- const array = [];
83
- array.push(prevPoint);
84
- for (let i = 1; i < points.length; i++) {
85
- const currPoint = points[i];
86
- //不在同一水平线
87
- if (currPoint.y !== prevPoint.y && currPoint.x !== prevPoint.x) {
88
- array.push({ x: currPoint.x, y: prevPoint.y });
89
- }
90
- array.push(currPoint);
91
- prevPoint = currPoint;
92
- }
93
- return array;
94
- }
95
- static getOffsetX(node) {
96
- if (!node.parentElement) {
97
- throw new Error('node.parentElement is null');
98
- }
99
- const parent = node.parentElement.getBoundingClientRect().left;
100
- const curr = node.getBoundingClientRect().left;
101
- return curr - parent;
102
- }
103
- static randomColor() {
104
- let str = "#";
105
- for (let i = 0; i < 6; i++) {
106
- str += Math.floor(Math.random() * 16).toString(16);
107
- }
108
- return str;
109
- }
110
- /**
111
- * 判断一个数值是否在另一个数值的增益区间中
112
- * @param val
113
- * @param offset
114
- * @param compareValue
115
- * @returns
116
- */
117
- static ApproxmateValueInRange(val, offset, compareValue) {
118
- return (val - offset) <= compareValue && (val + offset) >= compareValue;
119
- }
120
- static getEmptyValue(val, emptyVal) {
121
- if (!val) {
122
- return emptyVal;
123
- }
124
- return val;
125
- }
126
- /**
127
- * 移除并集
128
- * @param array
129
- * @param deleteItems
130
- * @returns
131
- */
132
- static removeUnionSet(array, deleteItems) {
133
- const arraySet = new Set(array);
134
- for (let i = 0; i < deleteItems.length; i++) {
135
- const item = deleteItems[i];
136
- if (arraySet.has(item)) {
137
- arraySet.delete(item);
138
- }
139
- }
140
- return Array.from(arraySet);
141
- }
142
- static nullToString(val) {
143
- if (val === null || val === undefined) {
144
- return '';
145
- }
146
- return val;
147
- }
148
- static formatDate(date, format) {
149
- return moment(date).format(format);
150
- }
151
- static formatNow(format) {
152
- return this.formatDate(new Date(), format);
153
- }
154
- static parseText(text, data) {
155
- const reg = /\{(.*?)\}/g;
156
- let result = text;
157
- let match;
158
- while (match = reg.exec(text)) {
159
- const key = match[1];
160
- const value = data[key];
161
- result = result.replace(match[0], value);
162
- }
163
- return result;
164
- }
165
- //获取和当前日期相差的秒数
166
- static getNowDiffSeconds(date) {
167
- date = typeof date === 'string' ? new Date(date) : date;
168
- const now = new Date();
169
- const diff = now.getTime() - date.getTime();
170
- return diff / 1000;
171
- }
172
- //验证当前字符串是否为日期格式
173
- static isDate(str) {
174
- const reg = /^\d{4}-\d{2}-\d{2}$/;
175
- return reg.test(str);
176
- }
177
- }
178
- //# sourceMappingURL=common-util.js.map