aldehyde 0.2.472 → 0.2.474

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 (116) hide show
  1. package/lib/controls/entity-select/entity-select.js +1 -1
  2. package/lib/controls/entity-select/entity-select.js.map +1 -1
  3. package/lib/controls/entry-control.js +2 -2
  4. package/lib/controls/entry-control.js.map +1 -1
  5. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  6. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +12 -12
  7. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js.map +1 -1
  8. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  9. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  10. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  11. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  12. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts +5 -0
  13. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts.map +1 -0
  14. package/lib/draw-canvas/edit/components/asset-bar/index.js +78 -0
  15. package/lib/draw-canvas/edit/components/asset-bar/index.js.map +1 -0
  16. package/lib/draw-canvas/edit/components/asset-bar/index.less +36 -0
  17. package/lib/draw-canvas/edit/components/main-header/index.d.ts +14 -0
  18. package/lib/draw-canvas/edit/components/main-header/index.d.ts.map +1 -0
  19. package/lib/draw-canvas/edit/components/main-header/index.js +163 -0
  20. package/lib/draw-canvas/edit/components/main-header/index.js.map +1 -0
  21. package/lib/draw-canvas/edit/components/main-header/index.less +21 -0
  22. package/lib/draw-canvas/edit/components/render/index.d.ts +86 -0
  23. package/lib/draw-canvas/edit/components/render/index.d.ts.map +1 -0
  24. package/lib/draw-canvas/edit/components/render/index.js +686 -0
  25. package/lib/draw-canvas/edit/components/render/index.js.map +1 -0
  26. package/lib/draw-canvas/edit/components/render/types.d.ts +243 -0
  27. package/lib/draw-canvas/edit/components/render/types.d.ts.map +1 -0
  28. package/lib/draw-canvas/edit/components/render/types.js +66 -0
  29. package/lib/draw-canvas/edit/components/render/types.js.map +1 -0
  30. package/lib/draw-canvas/edit/components/setting-form/index.d.ts +19 -0
  31. package/lib/draw-canvas/edit/components/setting-form/index.d.ts.map +1 -0
  32. package/lib/draw-canvas/edit/components/setting-form/index.js +164 -0
  33. package/lib/draw-canvas/edit/components/setting-form/index.js.map +1 -0
  34. package/lib/draw-canvas/edit/index.d.ts +5 -0
  35. package/lib/draw-canvas/edit/index.d.ts.map +1 -0
  36. package/lib/draw-canvas/edit/index.js +112 -0
  37. package/lib/draw-canvas/edit/index.js.map +1 -0
  38. package/lib/draw-canvas/edit/index.less +34 -0
  39. package/lib/form/form-Item-group.d.ts.map +1 -1
  40. package/lib/form/form-Item-group.js +1 -1
  41. package/lib/form/form-Item-group.js.map +1 -1
  42. package/lib/icon/local-aliIcon/iconfont.js +5 -5
  43. package/lib/icon/local-aliIcon/iconfont.js.map +1 -1
  44. package/lib/table/relation-table.d.ts +4 -0
  45. package/lib/table/relation-table.d.ts.map +1 -1
  46. package/lib/tmpl/hcservice-v3.d.ts +1 -0
  47. package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
  48. package/lib/tmpl/hcservice-v3.js +27 -0
  49. package/lib/tmpl/hcservice-v3.js.map +1 -1
  50. package/lib/tmpl/interface.d.ts +4 -0
  51. package/lib/tmpl/interface.d.ts.map +1 -1
  52. package/lib/tmpl/interface.js.map +1 -1
  53. package/lib/units/index.d.ts +1 -0
  54. package/lib/units/index.d.ts.map +1 -1
  55. package/lib/units/index.js +16 -0
  56. package/lib/units/index.js.map +1 -1
  57. package/package.json +1 -1
  58. package/src/aldehyde/controls/entity-select/entity-select.tsx +1 -1
  59. package/src/aldehyde/controls/entry-control.tsx +2 -2
  60. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  61. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +1 -1
  62. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  63. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  64. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  65. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  66. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.less +36 -0
  67. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.tsx +93 -0
  68. package/src/aldehyde/draw-canvas/edit/components/main-header/index.less +21 -0
  69. package/src/aldehyde/draw-canvas/edit/components/main-header/index.tsx +187 -0
  70. package/src/aldehyde/draw-canvas/edit/components/render/draws/bg-draw.ts +98 -0
  71. package/src/aldehyde/draw-canvas/edit/components/render/draws/contextmenu-draw.ts +307 -0
  72. package/src/aldehyde/draw-canvas/edit/components/render/draws/graph-draw.ts +251 -0
  73. package/src/aldehyde/draw-canvas/edit/components/render/draws/index.ts +7 -0
  74. package/src/aldehyde/draw-canvas/edit/components/render/draws/link-draw.ts +1416 -0
  75. package/src/aldehyde/draw-canvas/edit/components/render/draws/preview-draw.ts +257 -0
  76. package/src/aldehyde/draw-canvas/edit/components/render/draws/ref-line-draw.ts +72 -0
  77. package/src/aldehyde/draw-canvas/edit/components/render/draws/ruler-draw.ts +167 -0
  78. package/src/aldehyde/draw-canvas/edit/components/render/graphs/base-graph.ts +241 -0
  79. package/src/aldehyde/draw-canvas/edit/components/render/graphs/bezier.ts +542 -0
  80. package/src/aldehyde/draw-canvas/edit/components/render/graphs/circle.ts +700 -0
  81. package/src/aldehyde/draw-canvas/edit/components/render/graphs/curve.ts +501 -0
  82. package/src/aldehyde/draw-canvas/edit/components/render/graphs/index.ts +6 -0
  83. package/src/aldehyde/draw-canvas/edit/components/render/graphs/line.ts +494 -0
  84. package/src/aldehyde/draw-canvas/edit/components/render/graphs/rect.ts +681 -0
  85. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-handlers.ts +69 -0
  86. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-outside-handlers.ts +162 -0
  87. package/src/aldehyde/draw-canvas/edit/components/render/handlers/graph-handlers.ts +108 -0
  88. package/src/aldehyde/draw-canvas/edit/components/render/handlers/index.ts +9 -0
  89. package/src/aldehyde/draw-canvas/edit/components/render/handlers/key-move-handlers.ts +50 -0
  90. package/src/aldehyde/draw-canvas/edit/components/render/handlers/link-handlers.ts +46 -0
  91. package/src/aldehyde/draw-canvas/edit/components/render/handlers/selection-handlers.ts +385 -0
  92. package/src/aldehyde/draw-canvas/edit/components/render/handlers/shutcut-handlers.ts +46 -0
  93. package/src/aldehyde/draw-canvas/edit/components/render/handlers/text-handlers.ts +82 -0
  94. package/src/aldehyde/draw-canvas/edit/components/render/handlers/zoom-handlers.ts +60 -0
  95. package/src/aldehyde/draw-canvas/edit/components/render/index.ts +768 -0
  96. package/src/aldehyde/draw-canvas/edit/components/render/tools/align-tool.ts +91 -0
  97. package/src/aldehyde/draw-canvas/edit/components/render/tools/asset-tool.ts +142 -0
  98. package/src/aldehyde/draw-canvas/edit/components/render/tools/attract-tool.ts +440 -0
  99. package/src/aldehyde/draw-canvas/edit/components/render/tools/copy-tool.ts +269 -0
  100. package/src/aldehyde/draw-canvas/edit/components/render/tools/import-export-tool.ts +603 -0
  101. package/src/aldehyde/draw-canvas/edit/components/render/tools/index.ts +9 -0
  102. package/src/aldehyde/draw-canvas/edit/components/render/tools/link-tool.ts +225 -0
  103. package/src/aldehyde/draw-canvas/edit/components/render/tools/position-tool.ts +212 -0
  104. package/src/aldehyde/draw-canvas/edit/components/render/tools/selection-tool.ts +132 -0
  105. package/src/aldehyde/draw-canvas/edit/components/render/tools/z-index-tool.ts +227 -0
  106. package/src/aldehyde/draw-canvas/edit/components/render/types.ts +287 -0
  107. package/src/aldehyde/draw-canvas/edit/components/render/utils/a-star.ts +116 -0
  108. package/src/aldehyde/draw-canvas/edit/components/render/utils/bezier-scene-func.ts +73 -0
  109. package/src/aldehyde/draw-canvas/edit/components/setting-form/index.tsx +200 -0
  110. package/src/aldehyde/draw-canvas/edit/index.less +34 -0
  111. package/src/aldehyde/draw-canvas/edit/index.tsx +138 -0
  112. package/src/aldehyde/form/form-Item-group.tsx +1 -0
  113. package/src/aldehyde/icon/local-aliIcon/iconfont.js +1 -1
  114. package/src/aldehyde/tmpl/hcservice-v3.tsx +14 -0
  115. package/src/aldehyde/tmpl/interface.tsx +2 -0
  116. package/src/aldehyde/units/index.tsx +15 -0
@@ -0,0 +1,257 @@
1
+ import Konva from 'konva';
2
+ import { BaseDraw, Draw, Render, MouseButton } from '../types';
3
+ import { LinkDraw } from '../draws';
4
+
5
+ // 编辑页预览框
6
+
7
+ export interface PreviewDrawOption {
8
+ size: number
9
+ }
10
+
11
+ export class PreviewDraw extends BaseDraw implements Draw {
12
+ // @ts-ignore
13
+ static override readonly name = 'preview';
14
+ option: PreviewDrawOption;
15
+
16
+ state: { [index: string]: any } = {
17
+ moving: false // 正在预览框内部拖动
18
+ }
19
+
20
+ constructor(render: Render, layer: Konva.Layer, option: PreviewDrawOption) {
21
+ super(render, layer);
22
+ this.option = option;
23
+ }
24
+
25
+ override draw() {
26
+ this.clear();
27
+ const stageState = this.render.getStageState();
28
+ const { pageWidth, pageHeight, background } = this.render.getPageSettings(); // 画布尺寸
29
+ const previewMargin = 20; // 预览框的外边距
30
+ // 预览框 group
31
+ const group = new Konva.Group({
32
+ name: 'preview',
33
+ scale: {
34
+ x: this.render.toStageValue(this.option.size),
35
+ y: this.render.toStageValue(this.option.size)
36
+ },
37
+ width: stageState.width,
38
+ height: stageState.height
39
+ });
40
+ const main = this.render.stage.find('#main')[0] as Konva.Layer;
41
+ const cover = this.render.stage.find('#cover')[0] as Konva.Layer;
42
+ // 提取节点
43
+ const nodes = [
44
+ ...main.getChildren((node) => !this.render.ignore(node)),
45
+ // 补充连线
46
+ ...cover.getChildren((node) => node.name() === LinkDraw.name)
47
+ ]
48
+ // 计算节点占用的区域
49
+ let minX = 0;
50
+ let maxX = group.width();
51
+ let minY = 0;
52
+ let maxY = group.height();
53
+
54
+ for (const node of nodes) {
55
+ const { x, y, width, height } = ((rect) => ({
56
+ x: this.render.toStageValue(rect.x - stageState.x),
57
+ y: this.render.toStageValue(rect.y - stageState.y),
58
+ width: this.render.toStageValue(rect.width),
59
+ height: this.render.toStageValue(rect.height)
60
+ }))(node.getClientRect());
61
+ if (x < minX) {
62
+ minX = x;
63
+ }
64
+ if (x + width > maxX) {
65
+ maxX = x + width;
66
+ }
67
+ if (y < minY) {
68
+ minY = y;
69
+ }
70
+ if (y + height > maxY) {
71
+ maxY = y + height;
72
+ }
73
+ }
74
+
75
+ // 根据占用的区域调整预览框的大小
76
+ group.setAttrs({
77
+ x: this.render.toStageValue(
78
+ -stageState.x +
79
+ this.render.rulerSize +
80
+ stageState.width -
81
+ maxX * this.option.size -
82
+ previewMargin
83
+ ),
84
+ y: this.render.toStageValue(
85
+ -stageState.y +
86
+ this.render.rulerSize +
87
+ stageState.height -
88
+ maxY * this.option.size -
89
+ previewMargin
90
+ ),
91
+ width: maxX - minX,
92
+ height: maxY - minY
93
+ });
94
+
95
+ // 预览框背景
96
+ const bg = new Konva.Rect({
97
+ name: this.constructor.name,
98
+ x: minX,
99
+ y: minY,
100
+ width: group.width(),
101
+ height: group.height(),
102
+ stroke: '#666',
103
+ strokeWidth: this.render.toStageValue(1),
104
+ fill: !background ? "#ffffff" : background
105
+ });
106
+
107
+ // 根据预览框内部拖动,同步画布的移动
108
+ const move = () => {
109
+ this.state.moving = true;
110
+ const pos = this.render.stage.getPointerPosition();
111
+ if (pos) {
112
+ const pWidth = group.width() * this.option.size;
113
+ const pHeight = group.height() * this.option.size;
114
+ const pOffsetX = pWidth - (stageState.width - pos.x - previewMargin);
115
+ const pOffsetY = pHeight - (stageState.height - pos.y - previewMargin);
116
+ const offsetX = pOffsetX / this.option.size;
117
+ const offsetY = pOffsetY / this.option.size;
118
+ // 点击预览框,点击位置作为画布中心
119
+ this.render.positionTool.updateCenter(
120
+ offsetX - this.render.rulerSize / this.option.size,
121
+ offsetY - this.render.rulerSize / this.option.size
122
+ );
123
+ }
124
+ }
125
+ // 预览框内拖动事件处理
126
+ bg.on('mousedown', (e) => {
127
+ if (e.evt.button === MouseButton.左键) {
128
+ move();
129
+ }
130
+ e.evt.preventDefault();
131
+ });
132
+ bg.on('mousemove', (e) => {
133
+ if (this.state.moving) {
134
+ move();
135
+ }
136
+ e.evt.preventDefault();
137
+ })
138
+ bg.on('mouseup', () => {
139
+ this.state.moving = false;
140
+ })
141
+ group.add(bg);
142
+ // 预览框 边框
143
+ group.add(
144
+ new Konva.Rect({
145
+ name: this.constructor.name,
146
+ x: 0,
147
+ y: 0,
148
+ width: this.render.toStageValue(pageWidth * stageState.scale),
149
+ height: this.render.toStageValue(pageHeight * stageState.scale),
150
+ stroke: 'rgba(255,0,0,0.2)',
151
+ strokeWidth: 1 / this.option.size,
152
+ listening: false
153
+ })
154
+ );
155
+ // 复制提取的节点,用作预览
156
+ for (const node of nodes) {
157
+ const copy = node.clone();
158
+ // 消除连接线选中状态
159
+ copy.find('.link-line').forEach((link: Konva.Line) => {
160
+ const dash = link.dash();
161
+ if (dash && dash.length === 2 && dash.every((o) => o === 1)) {
162
+ link.dash([]);
163
+ }
164
+ });
165
+ // 不显示 调整点
166
+ copy.find('.link-point').map((o: Konva.Shape) => o.destroy());
167
+ copy.find('.link-manual-point').map((o: Konva.Shape) => o.destroy());
168
+ // 不可交互
169
+ copy.listening(false);
170
+ // 设置名称用于 ignore
171
+ copy.name(this.constructor.name);
172
+ group.add(copy);
173
+ }
174
+ // 放大的时候,显示当前可视区域提示框
175
+ if (stageState.scale > 1) {
176
+ // 画布可视区域起点坐标(左上)
177
+ let x1 = this.render.toStageValue(-stageState.x + this.render.rulerSize);
178
+ let y1 = this.render.toStageValue(-stageState.y + this.render.rulerSize);
179
+ // 限制可视区域提示框不能超出预览区域
180
+ x1 = x1 > minX ? x1 : minX;
181
+ x1 = x1 < maxX ? x1 : maxX;
182
+ y1 = y1 > minY ? y1 : minY;
183
+ y1 = y1 < maxY ? y1 : maxY;
184
+ // 画布可视区域起点坐标(右下)
185
+ let x2 =
186
+ this.render.toStageValue(-stageState.x + this.render.rulerSize) +
187
+ this.render.toStageValue(stageState.width);
188
+ let y2 =
189
+ this.render.toStageValue(-stageState.y + this.render.rulerSize) +
190
+ this.render.toStageValue(stageState.height);
191
+ // 限制可视区域提示框不能超出预览区域
192
+ x2 = x2 > minX ? x2 : minX;
193
+ x2 = x2 < maxX ? x2 : maxX;
194
+ y2 = y2 > minY ? y2 : minY;
195
+ y2 = y2 < maxY ? y2 : maxY;
196
+ // 可视区域提示框 连线坐标序列
197
+ let points: Array<[x: number, y: number]> = [];
198
+
199
+ // 可视区域提示框“超出”预览区域影响的“边”不做绘制
200
+ // "超出"(上面实际处理:把超过的坐标设置为上/下线,判断方式如[以正则表达式表示]:(x|y)(1|2) === (min|max)(X|Y))
201
+ // 简单直接穷举 9 种情况:
202
+ // 不超出
203
+ // 上超出 下超出
204
+ // 左超出 右超出
205
+ // 左上超出 右上超出
206
+ // 左下超出 右下超出
207
+
208
+ // 不超出,绘制完整矩形
209
+ if (x1 > minX && x1 < maxX && x2 > minX && x2 < maxX && y1 > minY && y1 < maxY && y2 > minY && y2 < maxY) {
210
+ points = [[x1, y1], [x2, y1], [x2, y2], [x1, y2], [x1, y1]];
211
+ }
212
+ // 上超出,不绘制“上边”
213
+ if (x1 > minX && x1 < maxX && x2 > minX && x2 < maxX && y1 === minY && y1 < maxY && y2 > minY && y2 < maxY) {
214
+ points = [[x2, y1], [x2, y2], [x1, y2], [x1, y1]];
215
+ }
216
+ // 下超出,不绘制“下边”
217
+ if (x1 > minX && x1 < maxX && x2 > minX && x2 < maxX && y1 > minY && y1 < maxY && y2 > minY && y2 === maxY) {
218
+ points = [[x1, y2], [x1, y1], [x2, y1], [x2, y2]];
219
+ }
220
+ // 左超出,不绘制“左边”
221
+ if (x1 === minX && x1 < maxX && x2 > minX && x2 < maxX && y1 > minY && y1 < maxY && y2 > minY && y2 < maxY) {
222
+ points = [[x1, y1], [x2, y1], [x2, y2], [x1, y2]];
223
+ }
224
+ // 右超出,不绘制“右边”
225
+ if (x1 > minX && x1 < maxX && x2 > minX && x2 === maxX && y1 > minY && y1 < maxY && y2 > minY && y2 < maxY) {
226
+ points = [[x2, y1], [x1, y1], [x1, y2], [x2, y2]];
227
+ }
228
+ // 左上超出,不绘制“上边”、“左边”
229
+ if (x1 === minX && x1 < maxX && x2 > minX && x2 < maxX && y1 === minY && y1 < maxY && y2 > minY && y2 < maxY) {
230
+ points = [[x2, y1], [x2, y2], [x1, y2]];
231
+ }
232
+ // 右上超出,不绘制“上边”、“右边”
233
+ if (x1 > minX && x1 < maxX && x2 > minX && x2 === maxX && y1 === minY && y1 < maxY && y2 > minY && y2 < maxY) {
234
+ points = [[x2, y2], [x1, y2], [x1, y1]];
235
+ }
236
+ // 左下超出,不绘制“下边”、“左边”
237
+ if (x1 === minX && x1 < maxX && x2 > minX && x2 < maxX && y1 > minY && y1 < maxY && y2 > minY && y2 === maxY) {
238
+ points = [[x1, y1], [x2, y1], [x2, y2]];
239
+ }
240
+ // 右下超出,不绘制“下边”、“右边”
241
+ if (x1 > minX && x1 < maxX && x2 > minX && x2 === maxX && y1 > minY && y1 < maxY && y2 > minY && y2 === maxY) {
242
+ points = [[x2, y1], [x1, y1], [x1, y2]];
243
+ }
244
+ // 可视区域提示框
245
+ group.add(
246
+ new Konva.Line({
247
+ name: this.constructor.name,
248
+ points: points.flat(),
249
+ stroke: 'blue',
250
+ strokeWidth: 1 / this.option.size,
251
+ listening: false
252
+ })
253
+ );
254
+ }
255
+ this.group.add(group);
256
+ }
257
+ }
@@ -0,0 +1,72 @@
1
+ import Konva from 'konva';
2
+ import { BaseDraw, Draw, Handler, Render } from '../types';
3
+
4
+ // 参考线
5
+
6
+ export interface RefLineDrawOption {
7
+ padding: number
8
+ }
9
+
10
+ export class RefLineDraw extends BaseDraw implements Draw, Handler {
11
+ // @ts-ignore
12
+ static override readonly name = 'refLine';
13
+ option: RefLineDrawOption;
14
+
15
+ constructor(render: Render, layer: Konva.Layer, option: RefLineDrawOption) {
16
+ super(render, layer);
17
+ this.option = option;
18
+ this.group.listening(false);
19
+ }
20
+
21
+ override draw() {
22
+ this.clear();
23
+ const stageState = this.render.getStageState();
24
+ const group = new Konva.Group();
25
+ const pos = this.render.stage.getPointerPosition();
26
+ if (pos) {
27
+ if (pos.y >= this.option.padding) {
28
+ // 横
29
+ group.add(
30
+ new Konva.Line({
31
+ name: this.constructor.name,
32
+ points: [
33
+ [this.render.toStageValue(-stageState.x), this.render.toStageValue(pos.y - stageState.y)],
34
+ [this.render.toStageValue(stageState.width - stageState.x + this.render.rulerSize), this.render.toStageValue(pos.y - stageState.y)]
35
+ ].flat(),
36
+ stroke: 'rgba(255,0,0,0.2)',
37
+ strokeWidth: this.render.toStageValue(1),
38
+ listening: false
39
+ })
40
+ );
41
+ }
42
+ if (pos.x >= this.option.padding) {
43
+ // 竖
44
+ group.add(
45
+ new Konva.Line({
46
+ name: this.constructor.name,
47
+ points: [
48
+ [this.render.toStageValue(pos.x - stageState.x), this.render.toStageValue(-stageState.y)],
49
+ [this.render.toStageValue(pos.x - stageState.x), this.render.toStageValue(stageState.height - stageState.y + this.render.rulerSize)]
50
+ ].flat(),
51
+ stroke: 'rgba(255,0,0,0.2)',
52
+ strokeWidth: this.render.toStageValue(1),
53
+ listening: false
54
+ })
55
+ );
56
+ }
57
+ }
58
+ this.group.add(group);
59
+ }
60
+ handlers = {
61
+ dom: {
62
+ mousemove: () => {
63
+ // 更新参考线
64
+ this.draw();
65
+ },
66
+ mouseout: () => {
67
+ // 清除参考线
68
+ this.clear();
69
+ }
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,167 @@
1
+ import Konva from 'konva';
2
+ import { BaseDraw, Render, Draw } from '../types';
3
+
4
+ // 画布比例尺
5
+
6
+ export interface RulerDrawOption {
7
+ size: number
8
+ }
9
+
10
+ export class RulerDraw extends BaseDraw implements Draw {
11
+ // @ts-ignore
12
+ static override readonly name = 'ruler';
13
+ option: RulerDrawOption;
14
+
15
+ constructor(render: Render, layer: Konva.Layer, option: RulerDrawOption) {
16
+ super(render, layer);
17
+ this.option = option;
18
+ this.group.listening(false);
19
+ }
20
+
21
+ override draw() {
22
+ this.clear();
23
+ const stageState = this.render.getStageState();
24
+ // 格子大小
25
+ const cellSize = 20;
26
+ const fontSizeMax = 12;
27
+ const lenX = Math.ceil(this.render.toStageValue(stageState.width) / cellSize); // 列数
28
+ const lenY = Math.ceil(this.render.toStageValue(stageState.height) / cellSize); // 行数
29
+ const startX = -Math.ceil(this.render.toStageValue(stageState.x - this.option.size) / cellSize);
30
+ const startY = -Math.ceil(this.render.toStageValue(stageState.y - this.option.size) / cellSize);
31
+ const group = new Konva.Group();
32
+ // 比例尺 - 上
33
+ const groupTop = new Konva.Group({
34
+ x: this.render.toStageValue(-stageState.x + this.option.size),
35
+ y: this.render.toStageValue(-stageState.y),
36
+ width: this.render.toStageValue(stageState.width - this.option.size + this.render.rulerSize),
37
+ height: this.render.toStageValue(this.option.size)
38
+ });
39
+ // 比例尺 - 左
40
+ const groupLeft = new Konva.Group({
41
+ x: this.render.toStageValue(-stageState.x),
42
+ y: this.render.toStageValue(-stageState.y + this.option.size),
43
+ width: this.render.toStageValue(this.option.size),
44
+ height: this.render.toStageValue(stageState.height - this.option.size + this.render.rulerSize)
45
+ });
46
+ {
47
+ groupTop.add(
48
+ // 上
49
+ new Konva.Rect({
50
+ name: this.constructor.name,
51
+ x: 0,
52
+ y: 0,
53
+ width: groupTop.width(),
54
+ height: groupTop.height(),
55
+ fill: '#ddd'
56
+ })
57
+ );
58
+ for (let x = lenX + startX - 1; x >= startX; x--) {
59
+ const nx = -groupTop.x() + cellSize * x;
60
+ const long = (this.render.toStageValue(this.option.size) / 5) * 4;
61
+ const short = (this.render.toStageValue(this.option.size) / 5) * 3;
62
+ if (nx >= 0) {
63
+ groupTop.add(
64
+ new Konva.Line({
65
+ name: this.constructor.name,
66
+ points: [
67
+ [nx, x % 5 ? long : short],
68
+ [nx, this.render.toStageValue(this.option.size)]
69
+ ].flat(),
70
+ stroke: '#999',
71
+ strokeWidth: this.render.toStageValue(1),
72
+ listening: false
73
+ })
74
+ );
75
+ if (x % 5 === 0) {
76
+ let fontSize = fontSizeMax;
77
+ const text = new Konva.Text({
78
+ name: this.constructor.name,
79
+ y: this.render.toStageValue(this.option.size / 2 - fontSize),
80
+ text: (x * cellSize).toString(),
81
+ fontSize: this.render.toStageValue(fontSize),
82
+ fill: '#999',
83
+ align: 'center',
84
+ verticalAlign: 'middle',
85
+ lineHeight: 1.6
86
+ });
87
+ while (this.render.toStageValue(text.width()) > this.render.toStageValue(cellSize) * 4.6) {
88
+ fontSize -= 1;
89
+ text.fontSize(this.render.toStageValue(fontSize));
90
+ text.y(this.render.toStageValue(this.option.size / 2 - fontSize));
91
+ }
92
+ text.x(nx - text.width() / 2);
93
+ groupTop.add(text);
94
+ }
95
+ }
96
+ }
97
+ }
98
+ {
99
+ groupLeft.add(
100
+ // 左
101
+ new Konva.Rect({
102
+ name: this.constructor.name,
103
+ x: 0,
104
+ y: 0,
105
+ width: groupLeft.width(),
106
+ height: groupLeft.height(),
107
+ fill: '#ddd'
108
+ })
109
+ );
110
+ for (let y = lenY + startY - 1; y >= startY; y--) {
111
+ const ny = -groupLeft.y() + cellSize * y;
112
+ const long = (this.render.toStageValue(this.option.size) / 5) * 4;
113
+ const short = (this.render.toStageValue(this.option.size) / 5) * 3;
114
+ if (ny >= 0) {
115
+ groupLeft.add(
116
+ new Konva.Line({
117
+ name: this.constructor.name,
118
+ points: [
119
+ [y % 5 ? long : short, ny],
120
+ [this.render.toStageValue(this.option.size), ny]
121
+ ].flat(),
122
+ stroke: '#999',
123
+ strokeWidth: this.render.toStageValue(1),
124
+ listening: false
125
+ })
126
+ );
127
+ if (y % 5 === 0) {
128
+ let fontSize = fontSizeMax;
129
+ const text = new Konva.Text({
130
+ name: this.constructor.name,
131
+ x: 0,
132
+ y: ny,
133
+ text: (y * cellSize).toString(),
134
+ fontSize: this.render.toStageValue(fontSize),
135
+ fill: '#999',
136
+ align: 'right',
137
+ verticalAlign: 'bottom',
138
+ lineHeight: 1.6,
139
+ wrap: 'none'
140
+ });
141
+ while (text.width() > short * 0.8) {
142
+ fontSize -= 1;
143
+ text.fontSize(this.render.toStageValue(fontSize));
144
+ }
145
+ text.y(ny - text.height() / 2);
146
+ text.width(short - this.render.toStageValue(1));
147
+ groupLeft.add(text);
148
+ }
149
+ }
150
+ }
151
+ }
152
+ group.add(
153
+ // 角
154
+ new Konva.Rect({
155
+ name: this.constructor.name,
156
+ x: this.render.toStageValue(-stageState.x),
157
+ y: this.render.toStageValue(-stageState.y),
158
+ width: this.render.toStageValue(this.option.size),
159
+ height: this.render.toStageValue(this.option.size),
160
+ fill: '#ddd'
161
+ })
162
+ );
163
+ group.add(groupTop);
164
+ group.add(groupLeft);
165
+ this.group.add(group);
166
+ }
167
+ }