aldehyde 0.2.473 → 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 (113) hide show
  1. package/lib/controls/entry-control.js +2 -2
  2. package/lib/controls/entry-control.js.map +1 -1
  3. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  4. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +12 -12
  5. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js.map +1 -1
  6. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  7. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  8. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  9. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  10. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts +5 -0
  11. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts.map +1 -0
  12. package/lib/draw-canvas/edit/components/asset-bar/index.js +78 -0
  13. package/lib/draw-canvas/edit/components/asset-bar/index.js.map +1 -0
  14. package/lib/draw-canvas/edit/components/asset-bar/index.less +36 -0
  15. package/lib/draw-canvas/edit/components/main-header/index.d.ts +14 -0
  16. package/lib/draw-canvas/edit/components/main-header/index.d.ts.map +1 -0
  17. package/lib/draw-canvas/edit/components/main-header/index.js +163 -0
  18. package/lib/draw-canvas/edit/components/main-header/index.js.map +1 -0
  19. package/lib/draw-canvas/edit/components/main-header/index.less +21 -0
  20. package/lib/draw-canvas/edit/components/render/index.d.ts +86 -0
  21. package/lib/draw-canvas/edit/components/render/index.d.ts.map +1 -0
  22. package/lib/draw-canvas/edit/components/render/index.js +686 -0
  23. package/lib/draw-canvas/edit/components/render/index.js.map +1 -0
  24. package/lib/draw-canvas/edit/components/render/types.d.ts +243 -0
  25. package/lib/draw-canvas/edit/components/render/types.d.ts.map +1 -0
  26. package/lib/draw-canvas/edit/components/render/types.js +66 -0
  27. package/lib/draw-canvas/edit/components/render/types.js.map +1 -0
  28. package/lib/draw-canvas/edit/components/setting-form/index.d.ts +19 -0
  29. package/lib/draw-canvas/edit/components/setting-form/index.d.ts.map +1 -0
  30. package/lib/draw-canvas/edit/components/setting-form/index.js +164 -0
  31. package/lib/draw-canvas/edit/components/setting-form/index.js.map +1 -0
  32. package/lib/draw-canvas/edit/index.d.ts +5 -0
  33. package/lib/draw-canvas/edit/index.d.ts.map +1 -0
  34. package/lib/draw-canvas/edit/index.js +112 -0
  35. package/lib/draw-canvas/edit/index.js.map +1 -0
  36. package/lib/draw-canvas/edit/index.less +34 -0
  37. package/lib/form/form-Item-group.d.ts.map +1 -1
  38. package/lib/form/form-Item-group.js +1 -1
  39. package/lib/form/form-Item-group.js.map +1 -1
  40. package/lib/icon/local-aliIcon/iconfont.js +5 -5
  41. package/lib/icon/local-aliIcon/iconfont.js.map +1 -1
  42. package/lib/table/relation-table.d.ts +4 -0
  43. package/lib/table/relation-table.d.ts.map +1 -1
  44. package/lib/tmpl/hcservice-v3.d.ts +1 -0
  45. package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
  46. package/lib/tmpl/hcservice-v3.js +27 -0
  47. package/lib/tmpl/hcservice-v3.js.map +1 -1
  48. package/lib/tmpl/interface.d.ts +4 -0
  49. package/lib/tmpl/interface.d.ts.map +1 -1
  50. package/lib/tmpl/interface.js.map +1 -1
  51. package/lib/units/index.d.ts +1 -0
  52. package/lib/units/index.d.ts.map +1 -1
  53. package/lib/units/index.js +16 -0
  54. package/lib/units/index.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/aldehyde/controls/entry-control.tsx +2 -2
  57. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  58. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +1 -1
  59. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  60. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  61. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  62. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  63. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.less +36 -0
  64. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.tsx +93 -0
  65. package/src/aldehyde/draw-canvas/edit/components/main-header/index.less +21 -0
  66. package/src/aldehyde/draw-canvas/edit/components/main-header/index.tsx +187 -0
  67. package/src/aldehyde/draw-canvas/edit/components/render/draws/bg-draw.ts +98 -0
  68. package/src/aldehyde/draw-canvas/edit/components/render/draws/contextmenu-draw.ts +307 -0
  69. package/src/aldehyde/draw-canvas/edit/components/render/draws/graph-draw.ts +251 -0
  70. package/src/aldehyde/draw-canvas/edit/components/render/draws/index.ts +7 -0
  71. package/src/aldehyde/draw-canvas/edit/components/render/draws/link-draw.ts +1416 -0
  72. package/src/aldehyde/draw-canvas/edit/components/render/draws/preview-draw.ts +257 -0
  73. package/src/aldehyde/draw-canvas/edit/components/render/draws/ref-line-draw.ts +72 -0
  74. package/src/aldehyde/draw-canvas/edit/components/render/draws/ruler-draw.ts +167 -0
  75. package/src/aldehyde/draw-canvas/edit/components/render/graphs/base-graph.ts +241 -0
  76. package/src/aldehyde/draw-canvas/edit/components/render/graphs/bezier.ts +542 -0
  77. package/src/aldehyde/draw-canvas/edit/components/render/graphs/circle.ts +700 -0
  78. package/src/aldehyde/draw-canvas/edit/components/render/graphs/curve.ts +501 -0
  79. package/src/aldehyde/draw-canvas/edit/components/render/graphs/index.ts +6 -0
  80. package/src/aldehyde/draw-canvas/edit/components/render/graphs/line.ts +494 -0
  81. package/src/aldehyde/draw-canvas/edit/components/render/graphs/rect.ts +681 -0
  82. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-handlers.ts +69 -0
  83. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-outside-handlers.ts +162 -0
  84. package/src/aldehyde/draw-canvas/edit/components/render/handlers/graph-handlers.ts +108 -0
  85. package/src/aldehyde/draw-canvas/edit/components/render/handlers/index.ts +9 -0
  86. package/src/aldehyde/draw-canvas/edit/components/render/handlers/key-move-handlers.ts +50 -0
  87. package/src/aldehyde/draw-canvas/edit/components/render/handlers/link-handlers.ts +46 -0
  88. package/src/aldehyde/draw-canvas/edit/components/render/handlers/selection-handlers.ts +385 -0
  89. package/src/aldehyde/draw-canvas/edit/components/render/handlers/shutcut-handlers.ts +46 -0
  90. package/src/aldehyde/draw-canvas/edit/components/render/handlers/text-handlers.ts +82 -0
  91. package/src/aldehyde/draw-canvas/edit/components/render/handlers/zoom-handlers.ts +60 -0
  92. package/src/aldehyde/draw-canvas/edit/components/render/index.ts +768 -0
  93. package/src/aldehyde/draw-canvas/edit/components/render/tools/align-tool.ts +91 -0
  94. package/src/aldehyde/draw-canvas/edit/components/render/tools/asset-tool.ts +142 -0
  95. package/src/aldehyde/draw-canvas/edit/components/render/tools/attract-tool.ts +440 -0
  96. package/src/aldehyde/draw-canvas/edit/components/render/tools/copy-tool.ts +269 -0
  97. package/src/aldehyde/draw-canvas/edit/components/render/tools/import-export-tool.ts +603 -0
  98. package/src/aldehyde/draw-canvas/edit/components/render/tools/index.ts +9 -0
  99. package/src/aldehyde/draw-canvas/edit/components/render/tools/link-tool.ts +225 -0
  100. package/src/aldehyde/draw-canvas/edit/components/render/tools/position-tool.ts +212 -0
  101. package/src/aldehyde/draw-canvas/edit/components/render/tools/selection-tool.ts +132 -0
  102. package/src/aldehyde/draw-canvas/edit/components/render/tools/z-index-tool.ts +227 -0
  103. package/src/aldehyde/draw-canvas/edit/components/render/types.ts +287 -0
  104. package/src/aldehyde/draw-canvas/edit/components/render/utils/a-star.ts +116 -0
  105. package/src/aldehyde/draw-canvas/edit/components/render/utils/bezier-scene-func.ts +73 -0
  106. package/src/aldehyde/draw-canvas/edit/components/setting-form/index.tsx +200 -0
  107. package/src/aldehyde/draw-canvas/edit/index.less +34 -0
  108. package/src/aldehyde/draw-canvas/edit/index.tsx +138 -0
  109. package/src/aldehyde/form/form-Item-group.tsx +1 -0
  110. package/src/aldehyde/icon/local-aliIcon/iconfont.js +1 -1
  111. package/src/aldehyde/tmpl/hcservice-v3.tsx +14 -0
  112. package/src/aldehyde/tmpl/interface.tsx +2 -0
  113. package/src/aldehyde/units/index.tsx +15 -0
@@ -0,0 +1,686 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as _ from 'lodash';
11
+ import Konva from 'konva';
12
+ import { GraphDraw, LinkDraw, RulerDraw, PreviewDraw, RefLineDraw, BgDraw, ContextmenuDraw } from './draws';
13
+ import { AssetType, ImageType } from './types';
14
+ import { DragHandlers, ZoomHandlers, DragOutsideHandlers, SelectionHandlers, KeyMoveHandlers, ShutcutHandlers, LinkHandlers, GraphHandlers, TextHandlers } from './handlers';
15
+ import { AssetTool, SelectionTool, CopyTool, PositionTool, ZIndexTool, ImportExportTool, AlignTool, LinkTool, AttractTool } from './tools';
16
+ // 简单的事件系统替代 mitt
17
+ class SimpleEventEmitter {
18
+ constructor() {
19
+ this.listeners = new Map();
20
+ }
21
+ on(event, handler) {
22
+ if (!this.listeners.has(event)) {
23
+ this.listeners.set(event, new Set());
24
+ }
25
+ this.listeners.get(event).add(handler);
26
+ return () => this.off(event, handler);
27
+ }
28
+ off(event, handler) {
29
+ var _a;
30
+ (_a = this.listeners.get(event)) === null || _a === void 0 ? void 0 : _a.delete(handler);
31
+ }
32
+ emit(event, ...args) {
33
+ var _a;
34
+ (_a = this.listeners.get(event)) === null || _a === void 0 ? void 0 : _a.forEach(handler => handler(...args));
35
+ }
36
+ }
37
+ // 渲染器
38
+ export class Render {
39
+ constructor(stageEle, config) {
40
+ this.layer = new Konva.Layer({ id: 'main' }); // 主要层
41
+ this.layerFloor = new Konva.Layer(); // 辅助层 - 背景
42
+ this.layerCover = new Konva.Layer({ id: 'cover' }); // 辅助层 - 连接线、对齐线
43
+ this.draws = {}; // 附加工具
44
+ this.groupTransformer = new Konva.Group(); // 多选器层
45
+ // 多选器
46
+ this.transformer = new Konva.Transformer({
47
+ shouldOverdrawWholeArea: true,
48
+ borderDash: [4, 4],
49
+ padding: 1,
50
+ rotationSnaps: [0, 45, 90, 135, 180, 225, 270, 315, 360],
51
+ flipEnabled: false
52
+ });
53
+ // 选择框
54
+ this.selectRect = new Konva.Rect({
55
+ id: 'selectRect',
56
+ fill: 'rgba(0,0,255,0.1)',
57
+ visible: false
58
+ });
59
+ // 事件处理
60
+ this.handlers = {};
61
+ // 参数
62
+ this.bgSize = 20;
63
+ this.rulerSize = 0;
64
+ this.previewSize = 0.2; // 预览框大小(比例)
65
+ this.pointSize = 6;
66
+ this.history = [];
67
+ this.historyIndex = -1;
68
+ this.graphType = undefined; // 画图类型
69
+ this.texting = false; // 添加文字中
70
+ // 事件发射器(替代 mitt)
71
+ this.emitter = new SimpleEventEmitter();
72
+ this.config = config;
73
+ // 绑定事件方法
74
+ this.on = this.emitter.on.bind(this.emitter);
75
+ this.off = this.emitter.off.bind(this.emitter);
76
+ this.emit = this.emitter.emit.bind(this.emitter);
77
+ if (this.config.showRuler) {
78
+ this.rulerSize = 40;
79
+ }
80
+ this.stage = new Konva.Stage({
81
+ container: stageEle,
82
+ x: this.rulerSize,
83
+ y: this.rulerSize,
84
+ width: config.width,
85
+ height: config.height
86
+ });
87
+ // 辅助层 - 顶层
88
+ this.groupTransformer.add(this.transformer);
89
+ this.groupTransformer.add(this.selectRect);
90
+ this.layerCover.add(this.groupTransformer);
91
+ // 附加工具
92
+ if (!this.config.readonly && this.config.showBg) {
93
+ this.draws[BgDraw.name] = new BgDraw(this, this.layerFloor, {
94
+ size: this.bgSize
95
+ });
96
+ }
97
+ this.draws[LinkDraw.name] = new LinkDraw(this, this.layerCover, {
98
+ size: this.pointSize
99
+ });
100
+ if (!this.config.readonly && this.config.showRuler) {
101
+ this.draws[RulerDraw.name] = new RulerDraw(this, this.layerCover, {
102
+ size: this.rulerSize
103
+ });
104
+ }
105
+ if (!this.config.readonly && this.config.showRefLine) {
106
+ this.draws[RefLineDraw.name] = new RefLineDraw(this, this.layerCover, {
107
+ padding: this.rulerSize
108
+ });
109
+ }
110
+ if (this.config.showContextmenu) {
111
+ this.draws[ContextmenuDraw.name] = new ContextmenuDraw(this, this.layerCover, {});
112
+ }
113
+ if (!this.config.readonly && this.config.showPreview) {
114
+ this.draws[PreviewDraw.name] = new PreviewDraw(this, this.layerCover, {
115
+ size: this.previewSize
116
+ });
117
+ }
118
+ this.draws[GraphDraw.name] = new GraphDraw(this, this.layerCover, {});
119
+ this.assetTool = new AssetTool(this); // 素材工具
120
+ this.selectionTool = new SelectionTool(this); // 选择工具
121
+ this.copyTool = new CopyTool(this); // 复制工具
122
+ this.positionTool = new PositionTool(this); // 定位工具
123
+ this.zIndexTool = new ZIndexTool(this); // 定位工具
124
+ this.importExportTool = new ImportExportTool(this); // 导入导出
125
+ this.alignTool = new AlignTool(this); // 对齐工具
126
+ this.linkTool = new LinkTool(this); // 对齐工具
127
+ this.attractTool = new AttractTool(this); // 磁贴工具
128
+ // 事件处理
129
+ this.handlers[DragHandlers.name] = new DragHandlers(this);
130
+ this.handlers[ZoomHandlers.name] = new ZoomHandlers(this);
131
+ if (!this.config.readonly) {
132
+ this.handlers[DragOutsideHandlers.name] = new DragOutsideHandlers(this);
133
+ this.handlers[SelectionHandlers.name] = new SelectionHandlers(this);
134
+ this.handlers[KeyMoveHandlers.name] = new KeyMoveHandlers(this);
135
+ this.handlers[LinkHandlers.name] = new LinkHandlers(this);
136
+ this.handlers[GraphHandlers.name] = new GraphHandlers(this);
137
+ this.handlers[TextHandlers.name] = new TextHandlers(this);
138
+ }
139
+ if (!this.config.readonly && this.config.showRefLine) {
140
+ if (this.draws[RefLineDraw.name] !== void 0) {
141
+ this.handlers[RefLineDraw.name] = this.draws[RefLineDraw.name];
142
+ }
143
+ }
144
+ this.handlers[ShutcutHandlers.name] = new ShutcutHandlers(this);
145
+ // 初始化
146
+ this.init();
147
+ }
148
+ // 初始化
149
+ init() {
150
+ var _a, _b, _c, _d, _e, _f;
151
+ this.stage.add(this.layerFloor);
152
+ (_a = this.draws[BgDraw.name]) === null || _a === void 0 ? void 0 : _a.init();
153
+ this.stage.add(this.layer);
154
+ this.stage.add(this.layerCover);
155
+ (_b = this.draws[LinkDraw.name]) === null || _b === void 0 ? void 0 : _b.init();
156
+ (_c = this.draws[RulerDraw.name]) === null || _c === void 0 ? void 0 : _c.init();
157
+ (_d = this.draws[RefLineDraw.name]) === null || _d === void 0 ? void 0 : _d.init();
158
+ (_e = this.draws[ContextmenuDraw.name]) === null || _e === void 0 ? void 0 : _e.init();
159
+ (_f = this.draws[PreviewDraw.name]) === null || _f === void 0 ? void 0 : _f.init();
160
+ // 事件绑定
161
+ this.eventBind();
162
+ // 更新历史
163
+ this.updateHistory();
164
+ }
165
+ // 更新 stage 尺寸
166
+ resize(width, height) {
167
+ this.stage.setAttrs({
168
+ width: width,
169
+ height: height
170
+ });
171
+ // 重绘
172
+ this.redraw();
173
+ }
174
+ // 移除元素
175
+ remove(nodes) {
176
+ for (const node of nodes) {
177
+ if (node instanceof Konva.Transformer) {
178
+ // 移除已选择的节点
179
+ this.remove(this.selectionTool.selectingNodes);
180
+ }
181
+ else {
182
+ // 移除相关联系线信息
183
+ const groupId = node.id();
184
+ for (const rn of this.layer.getChildren()) {
185
+ if (rn.id() !== groupId && Array.isArray(rn.attrs.points)) {
186
+ for (const point of rn.attrs.points) {
187
+ if (Array.isArray(point.pairs)) {
188
+ // 移除拐点记录
189
+ if (rn.attrs.manualPointsMap) {
190
+ point.pairs
191
+ .filter((pair) => pair.from.groupId === groupId || pair.to.groupId === groupId)
192
+ .forEach((pair) => {
193
+ rn.attrs.manualPointsMap[pair.id] = undefined;
194
+ });
195
+ }
196
+ // 连接线信息
197
+ point.pairs = point.pairs.filter((pair) => pair.from.groupId !== groupId && pair.to.groupId !== groupId);
198
+ }
199
+ }
200
+ rn.setAttrs({ points: rn.attrs.points });
201
+ }
202
+ }
203
+ // 移除未选择的节点
204
+ node.destroy();
205
+ }
206
+ }
207
+ if (nodes.length > 0) {
208
+ // 清除选择
209
+ this.selectionTool.selectingClear();
210
+ this.linkTool.selectingClear();
211
+ // 更新历史
212
+ this.updateHistory();
213
+ // 重绘
214
+ this.redraw();
215
+ }
216
+ }
217
+ // 撤销
218
+ prevHistory() {
219
+ const record = this.history[this.historyIndex - 1];
220
+ if (record) {
221
+ this.importExportTool.restore(record, true);
222
+ this.historyIndex--;
223
+ // 历史变化事件
224
+ this.emit('history-change', {
225
+ records: _.clone(this.history),
226
+ index: this.historyIndex
227
+ });
228
+ }
229
+ }
230
+ // 恢复
231
+ nextHistory() {
232
+ const record = this.history[this.historyIndex + 1];
233
+ if (record) {
234
+ this.importExportTool.restore(record, true);
235
+ this.historyIndex++;
236
+ // 历史变化事件
237
+ this.emit('history-change', {
238
+ records: _.clone(this.history),
239
+ index: this.historyIndex
240
+ });
241
+ }
242
+ }
243
+ updateHistory() {
244
+ this.history.splice(this.historyIndex + 1);
245
+ this.history.push(this.importExportTool.save());
246
+ this.historyIndex = this.history.length - 1;
247
+ // 历史变化事件
248
+ this.emit('history-change', {
249
+ records: _.clone(this.history),
250
+ index: this.historyIndex
251
+ });
252
+ }
253
+ // 事件绑定
254
+ eventBind() {
255
+ var _a, _b;
256
+ for (const event of [
257
+ 'mousedown',
258
+ 'mouseup',
259
+ 'mousemove',
260
+ 'wheel',
261
+ 'contextmenu',
262
+ 'pointerclick'
263
+ ]) {
264
+ this.stage.on(event, (e) => {
265
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
266
+ (_a = e === null || e === void 0 ? void 0 : e.evt) === null || _a === void 0 ? void 0 : _a.preventDefault();
267
+ for (const k in this.draws) {
268
+ (_e = (_d = (_c = (_b = this.draws[k]) === null || _b === void 0 ? void 0 : _b.handlers) === null || _c === void 0 ? void 0 : _c.stage) === null || _d === void 0 ? void 0 : _d[event]) === null || _e === void 0 ? void 0 : _e.call(_d, e);
269
+ }
270
+ for (const k in this.handlers) {
271
+ (_j = (_h = (_g = (_f = this.handlers[k]) === null || _f === void 0 ? void 0 : _f.handlers) === null || _g === void 0 ? void 0 : _g.stage) === null || _h === void 0 ? void 0 : _h[event]) === null || _j === void 0 ? void 0 : _j.call(_h, e);
272
+ }
273
+ });
274
+ }
275
+ const container = this.stage.container();
276
+ container.tabIndex = 1;
277
+ container.focus();
278
+ for (const event of [
279
+ 'mouseenter',
280
+ 'dragenter',
281
+ 'mousemove',
282
+ 'mouseout',
283
+ 'dragenter',
284
+ 'dragover',
285
+ 'drop',
286
+ 'keydown',
287
+ 'keyup'
288
+ ]) {
289
+ container.addEventListener(event, (e) => {
290
+ var _a, _b, _c, _d, _e, _f, _g, _h;
291
+ e === null || e === void 0 ? void 0 : e.preventDefault();
292
+ if (['mouseenter', 'dragenter'].includes(event)) {
293
+ // 激活 dom 事件
294
+ this.stage.container().focus();
295
+ }
296
+ for (const k in this.draws) {
297
+ (_d = (_c = (_b = (_a = this.draws[k]) === null || _a === void 0 ? void 0 : _a.handlers) === null || _b === void 0 ? void 0 : _b.dom) === null || _c === void 0 ? void 0 : _c[event]) === null || _d === void 0 ? void 0 : _d.call(_c, e);
298
+ }
299
+ for (const k in this.handlers) {
300
+ (_h = (_g = (_f = (_e = this.handlers[k]) === null || _e === void 0 ? void 0 : _e.handlers) === null || _f === void 0 ? void 0 : _f.dom) === null || _g === void 0 ? void 0 : _g[event]) === null || _h === void 0 ? void 0 : _h.call(_g, e);
301
+ }
302
+ });
303
+ }
304
+ for (const event of [
305
+ 'mousedown',
306
+ 'transformstart',
307
+ 'transform',
308
+ 'transformend',
309
+ 'dragstart',
310
+ 'dragmove',
311
+ 'dragend',
312
+ 'mousemove',
313
+ 'mouseleave',
314
+ 'dblclick'
315
+ ]) {
316
+ this.transformer.on(event, (e) => {
317
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
318
+ (_a = e === null || e === void 0 ? void 0 : e.evt) === null || _a === void 0 ? void 0 : _a.preventDefault();
319
+ for (const k in this.draws) {
320
+ (_e = (_d = (_c = (_b = this.draws[k]) === null || _b === void 0 ? void 0 : _b.handlers) === null || _c === void 0 ? void 0 : _c.transformer) === null || _d === void 0 ? void 0 : _d[event]) === null || _e === void 0 ? void 0 : _e.call(_d, e);
321
+ }
322
+ for (const k in this.handlers) {
323
+ (_j = (_h = (_g = (_f = this.handlers[k]) === null || _f === void 0 ? void 0 : _f.handlers) === null || _g === void 0 ? void 0 : _g.transformer) === null || _h === void 0 ? void 0 : _h[event]) === null || _j === void 0 ? void 0 : _j.call(_h, e);
324
+ }
325
+ });
326
+ }
327
+ ((_b = (_a = this.handlers[SelectionHandlers.name]) === null || _a === void 0 ? void 0 : _a.transformerConfig) === null || _b === void 0 ? void 0 : _b.anchorDragBoundFunc) &&
328
+ this.transformer.anchorDragBoundFunc(this.handlers[SelectionHandlers.name].transformerConfig.anchorDragBoundFunc);
329
+ }
330
+ // 获取 stage 状态
331
+ getStageState() {
332
+ return {
333
+ width: this.stage.width() - this.rulerSize,
334
+ height: this.stage.height() - this.rulerSize,
335
+ scale: this.stage.scaleX(),
336
+ x: this.stage.x(),
337
+ y: this.stage.y()
338
+ };
339
+ }
340
+ // 相对大小(基于 stage,且无视 scale)
341
+ toStageValue(boardPos) {
342
+ return boardPos / this.stage.scaleX();
343
+ }
344
+ // 绝对大小(基于可视区域像素)
345
+ toBoardValue(stagePos) {
346
+ return stagePos * this.stage.scaleX();
347
+ }
348
+ // 忽略非素材
349
+ ignore(node) {
350
+ // 素材有各自根 group
351
+ const isGroup = node instanceof Konva.Group;
352
+ return !isGroup || this.ignoreSelect(node) || this.ignoreDraw(node) || this.ignoreLink(node);
353
+ }
354
+ // 忽略 选择时 辅助元素
355
+ ignoreSelect(node) {
356
+ return node.id() === 'selectRect' || node.id() === 'hoverRect';
357
+ }
358
+ // 忽略各 draw 的根 group
359
+ ignoreDraw(node) {
360
+ return [BgDraw.name, RulerDraw.name, RefLineDraw.name, ContextmenuDraw.name, PreviewDraw.name, LinkDraw.name, GraphDraw.name].includes(node.name());
361
+ }
362
+ // 忽略各 draw 的根 group
363
+ ignoreLink(node) {
364
+ return ["link-anchor", "linking-line", "link-point", "link-line", "link-manual-point"].includes(node.name());
365
+ }
366
+ // 重绘(可选择)
367
+ redraw(drawNames) {
368
+ var _a, _b;
369
+ const all = [
370
+ // layerFloor
371
+ BgDraw.name, // 更新背景
372
+ // layerCover(按先后顺序)
373
+ GraphDraw.name, // 更新图形调整点
374
+ LinkDraw.name, // 更新连线
375
+ RulerDraw.name, // 更新比例尺
376
+ RefLineDraw.name, // 更新参考线
377
+ PreviewDraw.name, // 更新预览
378
+ ContextmenuDraw.name // 更新右键菜单
379
+ ];
380
+ // 可以以此发现缺失的 draw
381
+ // console.log('redraw', drawNames)
382
+ if (Array.isArray(drawNames)) {
383
+ // 选择性 draw 也要保持顺序
384
+ for (const name of all) {
385
+ if (drawNames.includes(name)) {
386
+ (_a = this.draws[name]) === null || _a === void 0 ? void 0 : _a.draw();
387
+ }
388
+ }
389
+ }
390
+ else {
391
+ for (const name of all) {
392
+ (_b = this.draws[name]) === null || _b === void 0 ? void 0 : _b.draw();
393
+ }
394
+ }
395
+ }
396
+ changeDraggable(disabled) {
397
+ this.layer.children.forEach((asset) => {
398
+ asset.draggable(disabled);
399
+ });
400
+ }
401
+ // 改变画图类型
402
+ changeGraphType(type) {
403
+ if (type) {
404
+ this.texting = false;
405
+ this.emit('texting-change', this.texting);
406
+ }
407
+ this.graphType = type;
408
+ this.emit('graph-type-change', this.graphType);
409
+ // 绘制 Graph 的时候,不允许直接拖动其他素材
410
+ this.changeDraggable(!this.config.readonly && this.graphType === void 0);
411
+ }
412
+ // 添加文字状态
413
+ changeTexting(texting) {
414
+ if (texting) {
415
+ this.graphType = undefined;
416
+ this.emit('graph-type-change', this.graphType);
417
+ }
418
+ this.texting = texting;
419
+ this.emit('texting-change', this.texting);
420
+ document.body.style.cursor = this.texting ? 'text' : 'default';
421
+ }
422
+ // 获取页面设置
423
+ getPageSettings() {
424
+ var _a;
425
+ return (_a = this.stage.attrs.pageSettings) !== null && _a !== void 0 ? _a : Object.assign({}, Render.PageSettingsDefault);
426
+ }
427
+ // 更新页面设置
428
+ setPageSettings(settings, update = false) {
429
+ this.stage.setAttr('pageSettings', settings);
430
+ // 更新背景
431
+ this.updateBackground();
432
+ if (update) {
433
+ // 更新历史
434
+ this.updateHistory();
435
+ }
436
+ }
437
+ // 获取背景
438
+ getBackground() {
439
+ var _a;
440
+ return (_a = this.draws[BgDraw.name]) === null || _a === void 0 ? void 0 : _a.layer.findOne(`.${BgDraw.name}__background`);
441
+ }
442
+ // 更新背景
443
+ updateBackground() {
444
+ var _a, _b, _c, _d, _e;
445
+ const background = this.getBackground();
446
+ if (background) {
447
+ background.fill((_a = this.getPageSettings().background) !== null && _a !== void 0 ? _a : 'transparent');
448
+ }
449
+ (_b = this.draws[BgDraw.name]) === null || _b === void 0 ? void 0 : _b.draw();
450
+ (_c = this.draws[GraphDraw.name]) === null || _c === void 0 ? void 0 : _c.draw();
451
+ (_d = this.draws[LinkDraw.name]) === null || _d === void 0 ? void 0 : _d.draw();
452
+ (_e = this.draws[PreviewDraw.name]) === null || _e === void 0 ? void 0 : _e.draw();
453
+ }
454
+ // 获取素材设置
455
+ getAssetSettings(asset) {
456
+ var _a, _b, _c, _d;
457
+ const base = (_a = asset === null || asset === void 0 ? void 0 : asset.attrs.assetSettings) !== null && _a !== void 0 ? _a : Object.assign({}, Render.AssetSettingsDefault);
458
+ return Object.assign(Object.assign({}, base), {
459
+ // 继承全局
460
+ stroke: base.stroke || this.getPageSettings().stroke, strokeWidth: base.strokeWidth || this.getPageSettings().strokeWidth, fontSize: base.fontSize || this.getPageSettings().fontSize, textFill: base.textFill || this.getPageSettings().textFill,
461
+ // 绘制图形,默认不填充
462
+ fill: base.fill ||
463
+ ((asset === null || asset === void 0 ? void 0 : asset.attrs.assetType) === AssetType.Graph
464
+ ? 'transparent'
465
+ : this.getPageSettings().fill), x: parseFloat(((_b = asset === null || asset === void 0 ? void 0 : asset.position().x) !== null && _b !== void 0 ? _b : 0).toFixed(1)), y: parseFloat(((_c = asset === null || asset === void 0 ? void 0 : asset.position().y) !== null && _c !== void 0 ? _c : 0).toFixed(1)), rotation: parseFloat(((_d = asset === null || asset === void 0 ? void 0 : asset.rotation()) !== null && _d !== void 0 ? _d : 0).toFixed(1)), tension: (asset === null || asset === void 0 ? void 0 : asset.attrs.assetType) === AssetType.Graph &&
466
+ (asset === null || asset === void 0 ? void 0 : asset.attrs.graphType) === "Curve"
467
+ ? base.tension
468
+ : undefined });
469
+ }
470
+ // 设置 svgXML 样式(部分)
471
+ setSvgXMLSettings(xml, settings) {
472
+ const reg = /<(circle|ellipse|line|path|polygon|rect|text|textPath|tref|tspan)[^>/]*\/?>/g;
473
+ const shapes = xml.match(reg);
474
+ const regStroke = / stroke="([^"]*)"/;
475
+ const regFill = / fill="([^"]*)"/;
476
+ for (const shape of shapes !== null && shapes !== void 0 ? shapes : []) {
477
+ let result = shape;
478
+ if (settings.stroke) {
479
+ if (regStroke.test(shape)) {
480
+ result = result.replace(regStroke, ` stroke="${settings.stroke}"`);
481
+ }
482
+ else {
483
+ result = result.replace(/(<[^>/]*)(\/?>)/, `$1 stroke="${settings.stroke}" $2`);
484
+ }
485
+ }
486
+ if (settings.fill) {
487
+ if (regFill.test(shape)) {
488
+ result = result.replace(regFill, ` fill="${settings.fill}"`);
489
+ }
490
+ else {
491
+ result = result.replace(/(<[^>/]*)(\/?>)/, `$1 fill="${settings.fill}" $2`);
492
+ }
493
+ }
494
+ xml = xml.replace(shape, result);
495
+ }
496
+ return xml;
497
+ }
498
+ rotatePoint({ x, y }, rad) {
499
+ const rCos = Math.cos(rad);
500
+ const rSin = Math.sin(rad);
501
+ return { x: x * rCos - y * rSin, y: y * rCos + x * rSin };
502
+ }
503
+ rotateAroundCenter(node, rotation) {
504
+ const topLeft = { x: -node.width() / 2, y: -node.height() / 2 };
505
+ const current = this.rotatePoint(topLeft, Konva.getAngle(node.rotation()));
506
+ const rotated = this.rotatePoint(topLeft, Konva.getAngle(rotation));
507
+ const dx = rotated.x - current.x;
508
+ const dy = rotated.y - current.y;
509
+ node.rotation(rotation);
510
+ node.x(node.x() + dx);
511
+ node.y(node.y() + dy);
512
+ }
513
+ // 更新素材设置
514
+ setAssetSettings(asset_1, settings_1) {
515
+ return __awaiter(this, arguments, void 0, function* (asset, settings, update = false) {
516
+ var _a, _b, _c, _d, _e;
517
+ asset.setAttr('assetSettings', settings);
518
+ if (asset instanceof Konva.Group) {
519
+ if (asset.attrs.imageType === ImageType.svg) {
520
+ const node = asset.children[0];
521
+ if (node instanceof Konva.Image) {
522
+ if (node.attrs.svgXML) {
523
+ const n = yield this.assetTool.loadSvgXML(this.setSvgXMLSettings(node.attrs.svgXML, settings));
524
+ (_a = node.parent) === null || _a === void 0 ? void 0 : _a.add(n);
525
+ node.remove();
526
+ node.destroy();
527
+ n.zIndex(0);
528
+ }
529
+ }
530
+ }
531
+ else if (asset.attrs.assetType === AssetType.Graph) {
532
+ const node = asset.findOne('.graph');
533
+ if (node instanceof Konva.Shape) {
534
+ node.strokeWidth(settings.strokeWidth);
535
+ node.stroke(settings.stroke);
536
+ if (node instanceof Konva.Arrow) {
537
+ // 箭头跟随 stroke
538
+ node.fill(settings.stroke);
539
+ }
540
+ else {
541
+ node.fill(settings.fill);
542
+ }
543
+ if (node instanceof Konva.Arrow) {
544
+ node.pointerAtBeginning(settings.arrowStart);
545
+ node.pointerAtEnding(settings.arrowEnd);
546
+ }
547
+ if (node instanceof Konva.Arrow && asset.attrs.graphType === "Curve") {
548
+ node.tension(settings.tension);
549
+ }
550
+ }
551
+ }
552
+ else if (asset.attrs.assetType === AssetType.Text) {
553
+ const node = asset.findOne('Text');
554
+ const rect = asset.findOne('Rect');
555
+ if (node instanceof Konva.Text && rect instanceof Konva.Rect) {
556
+ let sizeChanged = false;
557
+ if (node.fontSize() !== settings.fontSize || node.text() !== settings.text) {
558
+ sizeChanged = true;
559
+ }
560
+ node.fill(settings.textFill);
561
+ node.fontSize(settings.fontSize);
562
+ node.text(settings.text);
563
+ // 内容为空时,给一个半透明背景色
564
+ rect.fill(node.text().trim() ? '' : 'rgba(0,0,0,0.1)');
565
+ rect.width(Math.max(node.width(), settings.fontSize));
566
+ rect.height(Math.max(node.height(), settings.fontSize));
567
+ // 刷新 transformer 大小
568
+ if (sizeChanged) {
569
+ this.selectionTool.select([asset]);
570
+ }
571
+ }
572
+ }
573
+ // rotate 会影响 position,不能同时改变
574
+ // 区分属性面板正在调整
575
+ if (Math.abs(settings.rotation - asset.rotation()) >= 0.1) {
576
+ this.rotateAroundCenter(asset, settings.rotation);
577
+ // 同步 position 的变化
578
+ this.emit('asset-position-change', [asset]);
579
+ }
580
+ else {
581
+ const prevSettings = this.getAssetSettings(asset);
582
+ asset.position({
583
+ x: parseFloat(settings.x.toFixed(1)),
584
+ y: parseFloat(settings.y.toFixed(1))
585
+ });
586
+ // 外部调用变化同步
587
+ if (settings.x !== prevSettings.x || settings.y !== prevSettings.y) {
588
+ this.emit('asset-position-change', [asset]);
589
+ }
590
+ }
591
+ }
592
+ if (update) {
593
+ // 更新历史
594
+ this.updateHistory();
595
+ }
596
+ (_b = this.draws[BgDraw.name]) === null || _b === void 0 ? void 0 : _b.draw();
597
+ (_c = this.draws[GraphDraw.name]) === null || _c === void 0 ? void 0 : _c.draw();
598
+ (_d = this.draws[LinkDraw.name]) === null || _d === void 0 ? void 0 : _d.draw();
599
+ (_e = this.draws[PreviewDraw.name]) === null || _e === void 0 ? void 0 : _e.draw();
600
+ });
601
+ }
602
+ // 连接线设置
603
+ setLinkSettings(link_1, settings_1) {
604
+ return __awaiter(this, arguments, void 0, function* (link, settings, update = false) {
605
+ var _a, _b, _c, _d, _e;
606
+ const group = this.layer.findOne(`#${link.attrs.groupId}`);
607
+ if (Array.isArray(group === null || group === void 0 ? void 0 : group.attrs.points)) {
608
+ const point = (group === null || group === void 0 ? void 0 : group.attrs.points).find((o) => o.id === link.attrs.pointId);
609
+ if (point) {
610
+ const pair = point.pairs.find((o) => o.id === link.attrs.pairId);
611
+ if (pair) {
612
+ pair.style = Object.assign(Object.assign(Object.assign({}, pair.style), settings), { strokeWidth: Number((_a = settings.strokeWidth) !== null && _a !== void 0 ? _a : pair.style.strokeWidth) });
613
+ group.setAttr('points', group === null || group === void 0 ? void 0 : group.attrs.points);
614
+ }
615
+ }
616
+ }
617
+ if (update) {
618
+ // 更新历史
619
+ this.updateHistory();
620
+ }
621
+ (_b = this.draws[BgDraw.name]) === null || _b === void 0 ? void 0 : _b.draw();
622
+ (_c = this.draws[GraphDraw.name]) === null || _c === void 0 ? void 0 : _c.draw();
623
+ (_d = this.draws[LinkDraw.name]) === null || _d === void 0 ? void 0 : _d.draw();
624
+ (_e = this.draws[PreviewDraw.name]) === null || _e === void 0 ? void 0 : _e.draw();
625
+ });
626
+ }
627
+ // 获取连接线设置
628
+ getLinkSettings(link) {
629
+ let settings = undefined;
630
+ if (link) {
631
+ const group = this.layer.findOne(`#${link.attrs.groupId}`);
632
+ if (Array.isArray(group === null || group === void 0 ? void 0 : group.attrs.points)) {
633
+ const point = (group === null || group === void 0 ? void 0 : group.attrs.points).find((o) => o.id === link.attrs.pointId);
634
+ if (point) {
635
+ const pair = point.pairs.find((o) => o.id === link.attrs.pairId);
636
+ if (pair) {
637
+ settings = pair.style;
638
+ }
639
+ }
640
+ }
641
+ }
642
+ const base = settings !== null && settings !== void 0 ? settings : Object.assign({}, Render.LinkSettingsDefault);
643
+ return Object.assign(Object.assign({}, base), {
644
+ // 继承全局
645
+ stroke: base.stroke || this.getPageSettings().linkStroke, strokeWidth: base.strokeWidth || this.getPageSettings().linkStrokeWidth });
646
+ }
647
+ }
648
+ // 页面设置 默认值
649
+ Render.PageSettingsDefault = {
650
+ // 画布默认尺寸
651
+ pageWidth: 1280,
652
+ pageHeight: 720,
653
+ // 样式默认值
654
+ background: undefined,
655
+ stroke: 'rgb(0,0,0)',
656
+ strokeWidth: 1,
657
+ fill: 'rgb(0,0,0)',
658
+ linkStroke: 'rgb(0,0,0)',
659
+ linkStrokeWidth: 1,
660
+ fontSize: 24,
661
+ textFill: 'rgb(0,0,0)'
662
+ };
663
+ // 素材设置 默认值
664
+ Render.AssetSettingsDefault = {
665
+ stroke: '',
666
+ strokeWidth: 0,
667
+ fill: '',
668
+ arrowStart: false,
669
+ arrowEnd: false,
670
+ fontSize: 0,
671
+ textFill: '',
672
+ text: 'Text',
673
+ x: 0,
674
+ y: 0,
675
+ rotation: 0,
676
+ tension: 0
677
+ };
678
+ // 连接线设置 默认值
679
+ Render.LinkSettingsDefault = {
680
+ stroke: '',
681
+ strokeWidth: 0,
682
+ arrowStart: false,
683
+ arrowEnd: false,
684
+ tension: 0
685
+ };
686
+ //# sourceMappingURL=index.js.map