@flowgram-vue/renderer 0.2.0

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 (50) hide show
  1. package/LICENSE +22 -0
  2. package/dist/index.cjs +2933 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +721 -0
  5. package/dist/index.js +2918 -0
  6. package/dist/index.js.map +1 -0
  7. package/index.module.less +167 -0
  8. package/package.json +64 -0
  9. package/src/components/Adder.ts +107 -0
  10. package/src/components/BranchDraggableRenderer.ts +77 -0
  11. package/src/components/Collapse.ts +87 -0
  12. package/src/components/CollapseAdder.ts +94 -0
  13. package/src/components/CustomLine.ts +35 -0
  14. package/src/components/LabelsRenderer.ts +162 -0
  15. package/src/components/LinesRenderer.ts +99 -0
  16. package/src/components/MarkerActivatedArrow.ts +44 -0
  17. package/src/components/MarkerArrow.ts +44 -0
  18. package/src/components/RoundedTurningLine.ts +165 -0
  19. package/src/components/StraightLine.ts +31 -0
  20. package/src/components/utils.ts +295 -0
  21. package/src/entities/README.md +3 -0
  22. package/src/entities/flow-drag-entity.ts +267 -0
  23. package/src/entities/flow-select-config-entity.ts +114 -0
  24. package/src/entities/index.ts +8 -0
  25. package/src/entities/selector-box-config-entity.ts +88 -0
  26. package/src/env.d.ts +10 -0
  27. package/src/flow-renderer-container-module.ts +14 -0
  28. package/src/flow-renderer-contribution.ts +12 -0
  29. package/src/flow-renderer-registry.ts +155 -0
  30. package/src/flow-renderer-resize-observer.ts +56 -0
  31. package/src/hooks/use-base-color.ts +26 -0
  32. package/src/index.ts +16 -0
  33. package/src/layer-vue-provide.ts +44 -0
  34. package/src/layers/flow-context-menu-layer.ts +153 -0
  35. package/src/layers/flow-debug-layer.ts +227 -0
  36. package/src/layers/flow-drag-layer.ts +413 -0
  37. package/src/layers/flow-labels-layer.ts +100 -0
  38. package/src/layers/flow-lines-layer.ts +111 -0
  39. package/src/layers/flow-nodes-content-layer.ts +155 -0
  40. package/src/layers/flow-nodes-transform-layer.ts +151 -0
  41. package/src/layers/flow-scroll-bar-layer.ts +401 -0
  42. package/src/layers/flow-scroll-limit-layer.ts +36 -0
  43. package/src/layers/flow-selector-bounds-layer.ts +191 -0
  44. package/src/layers/flow-selector-box-layer.ts +244 -0
  45. package/src/layers/index.ts +16 -0
  46. package/src/utils/element.ts +36 -0
  47. package/src/utils/find-selected-nodes.ts +80 -0
  48. package/src/utils/index.ts +7 -0
  49. package/src/utils/scroll-bar-events.ts +13 -0
  50. package/src/utils/scroll-limit.ts +58 -0
package/dist/index.js ADDED
@@ -0,0 +1,2918 @@
1
+ import { Point, Rectangle, Compare, Disposable, domUtils, Cache } from '@flowgram-vue/utils';
2
+ import { DEFAULT_SPACING, DefaultSpacingKey, FlowDocument, FlowDocumentTransformerEntity, FlowNodeEntity, FlowNodeTransformData, FlowNodeRenderData, FlowDragService, FlowRendererStateEntity, FlowNodeTransitionData, FlowDocumentOptions, FlowTransitionLabelEnum, LABEL_SIDE_TYPE, FlowTransitionLineEnum, ConstantKeys, getDefaultSpacing, FlowNodeBaseType } from '@flowgram-vue/document';
3
+ import { observeEntity, observeEntityDatas, PlaygroundVueContainerKey, PlaygroundVueRefKey, Playground, PipelineRegistry, PlaygroundContainerFactory, useService, PlaygroundConfigEntity, EditorStateConfigEntity, ContextMenuService, SelectionService, CommandRegistry, ConfigEntity, Layer, PlaygroundEntityContextKey, PlaygroundDrag, EditorState, PipelineLayerPriority } from '@flowgram-vue/core';
4
+ import { isNil, uniq, throttle, groupBy } from 'lodash-es';
5
+ import { injectable, inject, multiInject, optional, ContainerModule } from 'inversify';
6
+ import { defineComponent, provide, h, inject as inject$1, computed, ref, onMounted, Teleport, Fragment } from 'vue';
7
+ import { I18n } from '@flowgram-vue/i18n';
8
+
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __decorateClass = (decorators, target, key, kind) => {
12
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
13
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
14
+ if (decorator = decorators[i])
15
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
16
+ if (kind && result) __defProp(target, key, result);
17
+ return result;
18
+ };
19
+ var BASE_DEFAULT_COLOR = "#BBBFC4";
20
+ var BASE_DEFAULT_ACTIVATED_COLOR = "#82A7FC";
21
+ function getBaseColor(options) {
22
+ return {
23
+ baseColor: options?.constants?.[ConstantKeys.BASE_COLOR] || BASE_DEFAULT_COLOR,
24
+ baseActivatedColor: options?.constants?.[ConstantKeys.BASE_ACTIVATED_COLOR] || BASE_DEFAULT_ACTIVATED_COLOR
25
+ };
26
+ }
27
+ function useBaseColor() {
28
+ const options = useService(FlowDocumentOptions);
29
+ return getBaseColor(options);
30
+ }
31
+
32
+ // src/components/utils.ts
33
+ var DEFAULT_LINE_ATTRS = {
34
+ stroke: BASE_DEFAULT_COLOR,
35
+ fill: "transparent",
36
+ strokeLinecap: "round",
37
+ strokeLinejoin: "round"
38
+ };
39
+ var DEFAULT_RADIUS = DEFAULT_SPACING[DefaultSpacingKey.ROUNDED_LINE_RADIUS];
40
+ var DEFAULT_LABEL_ACTIVATE_HEIGHT = 32;
41
+ function getHorizontalVertices(line, xRadius = 16, yRadius = 20) {
42
+ const { from, to, type } = line || {};
43
+ const deltaY = Math.abs(to.y - from.y);
44
+ const deltaX = Math.abs(to.x - from.x);
45
+ const radiusXCount = deltaX / xRadius;
46
+ const radiusYCount = deltaY / yRadius;
47
+ let res = [];
48
+ if (radiusXCount < 1) {
49
+ return [];
50
+ }
51
+ switch (type) {
52
+ case FlowTransitionLineEnum.DIVERGE_LINE:
53
+ case FlowTransitionLineEnum.DRAGGING_LINE:
54
+ if (radiusXCount <= 1) {
55
+ return [
56
+ {
57
+ x: to.x,
58
+ y: from.y,
59
+ radiusX: deltaX
60
+ }
61
+ ];
62
+ }
63
+ res = [
64
+ {
65
+ x: from.x + yRadius,
66
+ y: from.y
67
+ },
68
+ {
69
+ x: from.x + yRadius,
70
+ y: to.y
71
+ }
72
+ ];
73
+ if (radiusXCount < 2) {
74
+ const firstRadius = deltaX - yRadius;
75
+ res = [
76
+ {
77
+ x: from.x + firstRadius,
78
+ y: from.y,
79
+ // 第一个圆角收缩 y 半径
80
+ radiusX: firstRadius
81
+ },
82
+ {
83
+ x: from.x + firstRadius,
84
+ y: to.y
85
+ }
86
+ ];
87
+ }
88
+ if (radiusYCount < 2) {
89
+ res[0].moveY = deltaY / 2;
90
+ res[1].moveY = deltaY / 2;
91
+ }
92
+ return res;
93
+ case FlowTransitionLineEnum.MERGE_LINE:
94
+ if (radiusXCount < 2) {
95
+ return [
96
+ {
97
+ x: to.x,
98
+ y: from.y
99
+ }
100
+ ];
101
+ }
102
+ res = [
103
+ {
104
+ x: to.x - yRadius,
105
+ y: from.y
106
+ },
107
+ {
108
+ x: to.x - yRadius,
109
+ y: to.y
110
+ }
111
+ ];
112
+ if (radiusYCount < 2) {
113
+ res[0].moveY = deltaY / 2;
114
+ res[1].moveY = deltaY / 2;
115
+ }
116
+ return res;
117
+ }
118
+ return [];
119
+ }
120
+ function getVertices(line, xRadius = 16, yRadius = 20) {
121
+ const { from, to, type } = line || {};
122
+ const deltaY = Math.abs(to.y - from.y);
123
+ const deltaX = Math.abs(to.x - from.x);
124
+ const radiusYCount = deltaY / yRadius;
125
+ const radiusXCount = deltaX / xRadius;
126
+ let res = [];
127
+ if (radiusYCount < 1) {
128
+ return [];
129
+ }
130
+ switch (type) {
131
+ case FlowTransitionLineEnum.DIVERGE_LINE:
132
+ case FlowTransitionLineEnum.DRAGGING_LINE:
133
+ if (radiusYCount <= 1) {
134
+ return [
135
+ {
136
+ x: to.x,
137
+ y: from.y,
138
+ radiusY: deltaY
139
+ }
140
+ ];
141
+ }
142
+ res = [
143
+ {
144
+ x: from.x,
145
+ y: from.y + yRadius
146
+ },
147
+ {
148
+ x: to.x,
149
+ y: from.y + yRadius
150
+ }
151
+ ];
152
+ if (radiusYCount < 2) {
153
+ const firstRadius = deltaY - yRadius;
154
+ res = [
155
+ {
156
+ x: from.x,
157
+ y: from.y + firstRadius,
158
+ // 第一个圆角收缩 y 半径
159
+ radiusY: firstRadius
160
+ },
161
+ {
162
+ x: to.x,
163
+ y: from.y + firstRadius
164
+ }
165
+ ];
166
+ }
167
+ if (radiusXCount < 2) {
168
+ res[0].moveX = deltaX / 2;
169
+ res[1].moveX = deltaX / 2;
170
+ }
171
+ return res;
172
+ case FlowTransitionLineEnum.MERGE_LINE:
173
+ if (radiusYCount < 2) {
174
+ return [
175
+ {
176
+ x: from.x,
177
+ y: to.y
178
+ }
179
+ ];
180
+ }
181
+ res = [
182
+ {
183
+ x: from.x,
184
+ y: to.y - yRadius
185
+ },
186
+ {
187
+ x: to.x,
188
+ y: to.y - yRadius
189
+ }
190
+ ];
191
+ if (radiusXCount < 2) {
192
+ res[0].moveX = deltaX / 2;
193
+ res[1].moveX = deltaX / 2;
194
+ }
195
+ return res;
196
+ }
197
+ return [];
198
+ }
199
+ function getTransitionLabelHoverWidth(data) {
200
+ const { isVertical } = data.entity;
201
+ if (isVertical) {
202
+ const nextWidth = data.entity.next?.firstChild && !data.entity.next.isInlineBlocks ? data.entity.next.firstChild.getData(FlowNodeTransformData).size.width : data.entity.next?.getData(FlowNodeTransformData).size.width;
203
+ const maxWidth = Math.max(
204
+ data.entity.getData(FlowNodeTransformData)?.size.width ?? DEFAULT_SPACING[DefaultSpacingKey.HOVER_AREA_WIDTH],
205
+ nextWidth || 0
206
+ );
207
+ return maxWidth;
208
+ }
209
+ if (data.transform.next) {
210
+ return data.transform.next.inputPoint.x - data.transform.outputPoint.x;
211
+ }
212
+ return DEFAULT_LABEL_ACTIVATE_HEIGHT;
213
+ }
214
+ function getTransitionLabelHoverHeight(data) {
215
+ const { isVertical } = data.entity;
216
+ if (isVertical) {
217
+ if (data.transform.next) {
218
+ return data.transform.next.inputPoint.y - data.transform.outputPoint.y;
219
+ }
220
+ return DEFAULT_LABEL_ACTIVATE_HEIGHT;
221
+ }
222
+ const nextHeight = data.entity.next?.firstChild && !data.entity.next.isInlineBlocks ? data.entity.next.firstChild.getData(FlowNodeTransformData).size.height : data.entity.next?.getData(FlowNodeTransformData).size.height;
223
+ const maxHeight = Math.max(
224
+ data.entity.getData(FlowNodeTransformData)?.size.height || 280,
225
+ nextHeight || 0
226
+ );
227
+ return maxHeight;
228
+ }
229
+
230
+ // src/entities/flow-drag-entity.ts
231
+ var BRANCH_HOVER_HEIGHT = 64;
232
+ var SCROLL_DELTA = 4;
233
+ var SCROLL_INTERVAL = 20;
234
+ var SCROLL_BOUNDING = 20;
235
+ var EDITOR_LEFT_BAR_WIDTH = 60;
236
+ var FlowDragEntity = class extends ConfigEntity {
237
+ constructor(conf) {
238
+ super(conf);
239
+ this.containerX = 0;
240
+ this.containerY = 0;
241
+ this.playgroundConfigEntity = this.entityManager.getEntity(
242
+ PlaygroundConfigEntity,
243
+ true
244
+ );
245
+ }
246
+ get hasScroll() {
247
+ return Boolean(this._scrollXInterval || this._scrollYInterval);
248
+ }
249
+ isCollision(transition, rect, isBranch) {
250
+ const scale = this.playgroundConfigEntity.finalScale || 0;
251
+ if (isBranch) {
252
+ return this.isBranchCollision(transition, rect, scale);
253
+ }
254
+ return this.isNodeCollision(transition, rect, scale);
255
+ }
256
+ // 检测节点维度碰撞方法
257
+ isNodeCollision(transition, rect, scale) {
258
+ const { labels } = transition;
259
+ const { isVertical } = transition.entity;
260
+ const hasCollision = labels.some((label) => {
261
+ if (!label || ![
262
+ FlowTransitionLabelEnum.ADDER_LABEL,
263
+ FlowTransitionLabelEnum.COLLAPSE_ADDER_LABEL
264
+ ].includes(label.type)) {
265
+ return false;
266
+ }
267
+ const hoverWidth = isVertical ? transition.transform.bounds.width : DEFAULT_LABEL_ACTIVATE_HEIGHT;
268
+ const hoverHeight = isVertical ? DEFAULT_LABEL_ACTIVATE_HEIGHT : transition.transform.bounds.height;
269
+ const labelRect = new Rectangle(
270
+ (label.offset.x - hoverWidth / 2) * scale,
271
+ (label.offset.y - hoverHeight / 2) * scale,
272
+ hoverWidth * scale,
273
+ hoverHeight * scale
274
+ );
275
+ return Rectangle.intersects(labelRect, rect);
276
+ });
277
+ return {
278
+ hasCollision,
279
+ // 节点不关心 offsetType
280
+ labelOffsetType: void 0
281
+ };
282
+ }
283
+ // 检测分支维度碰撞
284
+ isBranchCollision(transition, rect, scale) {
285
+ const { labels } = transition;
286
+ const { isVertical } = transition.entity;
287
+ let labelOffsetType = LABEL_SIDE_TYPE.NORMAL_BRANCH;
288
+ const hasCollision = labels.some((label) => {
289
+ if (!label || label.type !== FlowTransitionLabelEnum.BRANCH_DRAGGING_LABEL) {
290
+ return false;
291
+ }
292
+ const hoverHeight = isVertical ? BRANCH_HOVER_HEIGHT : label.width || 0;
293
+ const hoverWidth = isVertical ? label.width || 0 : BRANCH_HOVER_HEIGHT;
294
+ const labelRect = new Rectangle(
295
+ (label.offset.x - hoverWidth / 2) * scale,
296
+ (label.offset.y - hoverHeight / 2) * scale,
297
+ hoverWidth * scale,
298
+ hoverHeight * scale
299
+ );
300
+ const collision = Rectangle.intersects(labelRect, rect);
301
+ if (collision) {
302
+ labelOffsetType = label.props.side;
303
+ }
304
+ return collision;
305
+ });
306
+ return {
307
+ hasCollision,
308
+ labelOffsetType
309
+ };
310
+ }
311
+ _startScrollX(origin, added) {
312
+ if (this._scrollXInterval) {
313
+ return;
314
+ }
315
+ const interval = window.setInterval(() => {
316
+ const current = this._scrollXInterval;
317
+ if (!current) return;
318
+ const scrollX = current.origin = added ? current.origin + SCROLL_DELTA : current.origin - SCROLL_DELTA;
319
+ this.playgroundConfigEntity.updateConfig({
320
+ scrollX
321
+ });
322
+ const playgroundConfig = this.playgroundConfigEntity.config;
323
+ if (playgroundConfig?.scrollX === scrollX) {
324
+ if (added) {
325
+ this.containerX += SCROLL_DELTA;
326
+ } else {
327
+ this.containerX -= SCROLL_DELTA;
328
+ }
329
+ }
330
+ }, SCROLL_INTERVAL);
331
+ this._scrollXInterval = { interval, origin };
332
+ }
333
+ _stopScrollX() {
334
+ if (this._scrollXInterval) {
335
+ clearInterval(this._scrollXInterval.interval);
336
+ this._scrollXInterval = void 0;
337
+ }
338
+ }
339
+ _startScrollY(origin, added) {
340
+ if (this._scrollYInterval) {
341
+ return;
342
+ }
343
+ const interval = window.setInterval(() => {
344
+ const current = this._scrollYInterval;
345
+ if (!current) return;
346
+ const scrollY = current.origin = added ? current.origin + SCROLL_DELTA : current.origin - SCROLL_DELTA;
347
+ this.playgroundConfigEntity.updateConfig({
348
+ scrollY
349
+ });
350
+ const playgroundConfig = this.playgroundConfigEntity.config;
351
+ if (playgroundConfig?.scrollY === scrollY) {
352
+ if (added) {
353
+ this.containerY += SCROLL_DELTA;
354
+ } else {
355
+ this.containerY -= SCROLL_DELTA;
356
+ }
357
+ }
358
+ }, SCROLL_INTERVAL);
359
+ this._scrollYInterval = { interval, origin };
360
+ }
361
+ _stopScrollY() {
362
+ if (this._scrollYInterval) {
363
+ clearInterval(this._scrollYInterval.interval);
364
+ this._scrollYInterval = void 0;
365
+ }
366
+ }
367
+ stopAllScroll() {
368
+ this._stopScrollX();
369
+ this._stopScrollY();
370
+ }
371
+ scrollDirection(e, x, y) {
372
+ const playgroundConfig = this.playgroundConfigEntity.config;
373
+ const currentScrollX = playgroundConfig.scrollX;
374
+ const currentScrollY = playgroundConfig.scrollY;
375
+ this.containerX = x;
376
+ this.containerY = y;
377
+ const clientRect = this.playgroundConfigEntity.playgroundDomNode.getBoundingClientRect();
378
+ const mouseToBottom = playgroundConfig.height + clientRect.y - e.clientY;
379
+ if (mouseToBottom < SCROLL_BOUNDING) {
380
+ this._startScrollY(currentScrollY, true);
381
+ return 1 /* BOTTOM */;
382
+ }
383
+ const mouseToTop = e.clientY - clientRect.y;
384
+ if (mouseToTop < SCROLL_BOUNDING) {
385
+ this._startScrollY(currentScrollY, false);
386
+ return 0 /* TOP */;
387
+ }
388
+ this._stopScrollY();
389
+ const mouseToRight = playgroundConfig.width + clientRect.x - e.clientX;
390
+ if (mouseToRight < SCROLL_BOUNDING) {
391
+ this._startScrollX(currentScrollX, true);
392
+ return 3 /* RIGHT */;
393
+ }
394
+ const mouseToLeft = e.clientX - clientRect.x;
395
+ if (mouseToLeft < SCROLL_BOUNDING + EDITOR_LEFT_BAR_WIDTH) {
396
+ this._startScrollX(currentScrollX, false);
397
+ return 2 /* LEFT */;
398
+ }
399
+ this._stopScrollX();
400
+ return void 0;
401
+ }
402
+ dispose() {
403
+ this.toDispose.dispose();
404
+ }
405
+ };
406
+ FlowDragEntity.type = "FlowDragEntity";
407
+ function getNodePath(node) {
408
+ const path = [node];
409
+ node = node.parent;
410
+ while (node) {
411
+ path.push(node);
412
+ node = node.parent;
413
+ }
414
+ return path.reverse();
415
+ }
416
+ function findRealEntity(entity) {
417
+ while (entity.originParent) {
418
+ entity = entity.originParent;
419
+ }
420
+ return entity;
421
+ }
422
+ function findSelectedNodes(nodes) {
423
+ if (nodes.length === 0) return [];
424
+ const nodePathList = nodes.map((n) => getNodePath(n));
425
+ const minLength = Math.min(...nodePathList.map((n) => n.length));
426
+ let index = 0;
427
+ let selectedItems = [];
428
+ while (index < minLength) {
429
+ selectedItems = uniq(nodePathList.map((p) => p[index]));
430
+ if (selectedItems.length > 1) {
431
+ break;
432
+ }
433
+ index += 1;
434
+ }
435
+ return uniq(selectedItems.map((item) => findRealEntity(item)));
436
+ }
437
+
438
+ // src/entities/flow-select-config-entity.ts
439
+ var BOUNDS_PADDING_DEFAULT = 10;
440
+ var FlowSelectConfigEntity = class extends ConfigEntity {
441
+ constructor() {
442
+ super(...arguments);
443
+ this.boundsPadding = BOUNDS_PADDING_DEFAULT;
444
+ }
445
+ getDefaultConfig() {
446
+ return {
447
+ selectedNodes: []
448
+ };
449
+ }
450
+ get selectedNodes() {
451
+ return this.config.selectedNodes;
452
+ }
453
+ /**
454
+ * 选中节点
455
+ * @param nodes
456
+ */
457
+ set selectedNodes(nodes) {
458
+ nodes = findSelectedNodes(nodes);
459
+ if (nodes.length !== this.config.selectedNodes.length || nodes.some((n) => !this.config.selectedNodes.includes(n))) {
460
+ this.config.selectedNodes.forEach((oldNode) => {
461
+ if (!nodes.includes(oldNode)) {
462
+ oldNode.getData(FlowNodeRenderData).activated = false;
463
+ }
464
+ });
465
+ nodes.forEach((node) => {
466
+ node.getData(FlowNodeRenderData).activated = true;
467
+ });
468
+ if (Compare.isArrayShallowChanged(this.config.selectedNodes, nodes)) {
469
+ this.updateConfig({
470
+ selectedNodes: nodes
471
+ });
472
+ }
473
+ }
474
+ }
475
+ /**
476
+ * 清除选中节点
477
+ */
478
+ clearSelectedNodes() {
479
+ if (this.config.selectedNodes.length === 0) return;
480
+ this.config.selectedNodes.forEach((node) => {
481
+ node.getData(FlowNodeRenderData).activated = false;
482
+ });
483
+ this.updateConfig({
484
+ selectedNodes: []
485
+ });
486
+ }
487
+ /**
488
+ * 通过选择框选中节点
489
+ * @param rect
490
+ * @param transforms
491
+ */
492
+ selectFromBounds(rect, transforms) {
493
+ const selectedNodes = [];
494
+ transforms.forEach((transform) => {
495
+ if (Rectangle.intersects(rect, transform.bounds)) {
496
+ if (transform.entity.originParent) {
497
+ selectedNodes.push(transform.entity.originParent);
498
+ } else {
499
+ selectedNodes.push(transform.entity);
500
+ }
501
+ }
502
+ });
503
+ this.selectedNodes = selectedNodes;
504
+ }
505
+ /**
506
+ * 获取选中节点外围的最大边框
507
+ */
508
+ getSelectedBounds() {
509
+ const nodes = this.selectedNodes;
510
+ if (nodes.length === 0) {
511
+ return Rectangle.EMPTY;
512
+ }
513
+ return Rectangle.enlarge(nodes.map((n) => n.getData(FlowNodeTransformData).bounds)).pad(
514
+ this.boundsPadding
515
+ );
516
+ }
517
+ };
518
+ FlowSelectConfigEntity.type = "FlowSelectConfigEntity";
519
+ var SelectorBoxConfigEntity = class extends ConfigEntity {
520
+ get dragInfo() {
521
+ return this.config;
522
+ }
523
+ setDragInfo(info) {
524
+ this.updateConfig(info);
525
+ }
526
+ get disabled() {
527
+ return this.config && !!this.config.disabled;
528
+ }
529
+ set disabled(disabled) {
530
+ this.updateConfig({
531
+ disabled
532
+ });
533
+ }
534
+ get isStart() {
535
+ return this.dragInfo.isStart;
536
+ }
537
+ get isMoving() {
538
+ return this.dragInfo.isMoving;
539
+ }
540
+ get position() {
541
+ const { dragInfo } = this;
542
+ return {
543
+ x: dragInfo.startPos.x < dragInfo.endPos.x ? dragInfo.startPos.x : dragInfo.endPos.x,
544
+ y: dragInfo.startPos.y < dragInfo.endPos.y ? dragInfo.startPos.y : dragInfo.endPos.y
545
+ };
546
+ }
547
+ get size() {
548
+ const { dragInfo } = this;
549
+ return {
550
+ width: Math.abs(dragInfo.startPos.x - dragInfo.endPos.x),
551
+ height: Math.abs(dragInfo.startPos.y - dragInfo.endPos.y)
552
+ };
553
+ }
554
+ get collapsed() {
555
+ const { size } = this;
556
+ return size.width === 0 && size.height === 0;
557
+ }
558
+ collapse() {
559
+ this.setDragInfo({
560
+ ...this.dragInfo,
561
+ isMoving: false,
562
+ isStart: false
563
+ });
564
+ }
565
+ toRectangle(scale) {
566
+ const { position, size } = this;
567
+ return new Rectangle(
568
+ position.x / scale,
569
+ position.y / scale,
570
+ size.width / scale,
571
+ size.height / scale
572
+ );
573
+ }
574
+ };
575
+ SelectorBoxConfigEntity.type = "SelectorBoxConfigEntity";
576
+ var isHidden = (dom) => {
577
+ if (!dom || isNil(dom?.offsetParent)) {
578
+ return true;
579
+ }
580
+ const style = window.getComputedStyle(dom);
581
+ if (style?.display === "none") {
582
+ return true;
583
+ }
584
+ return false;
585
+ };
586
+ var isRectInit = (rect) => {
587
+ if (!rect) {
588
+ return false;
589
+ }
590
+ if (rect.bottom === 0 && rect.height === 0 && rect.left === 0 && rect.right === 0 && rect.top === 0 && rect.width === 0 && rect.x === 0 && rect.y === 0) {
591
+ return false;
592
+ }
593
+ return true;
594
+ };
595
+
596
+ // src/flow-renderer-resize-observer.ts
597
+ var FlowRendererResizeObserver = class {
598
+ /**
599
+ * 监听元素 size,并同步到 transform
600
+ * @param el
601
+ * @param transform
602
+ */
603
+ observe(el, transform) {
604
+ const observer = new ResizeObserver((entries) => {
605
+ window.requestAnimationFrame(() => {
606
+ if (!Array.isArray(entries) || !entries.length) {
607
+ return;
608
+ }
609
+ const entry = entries[0];
610
+ const { contentRect, target } = entry;
611
+ const isContentRectInit = isRectInit(contentRect);
612
+ const isLeaveDOMTree = !target.parentNode;
613
+ const isHiddenElement = isHidden(target.parentNode);
614
+ if (isContentRectInit && !isLeaveDOMTree && !isHiddenElement) {
615
+ transform.size = {
616
+ width: Math.round(contentRect.width * 10) / 10,
617
+ height: Math.round(contentRect.height * 10) / 10
618
+ };
619
+ }
620
+ });
621
+ });
622
+ observer.observe(el);
623
+ return Disposable.create(() => {
624
+ observer.unobserve(el);
625
+ });
626
+ }
627
+ };
628
+ FlowRendererResizeObserver = __decorateClass([
629
+ injectable()
630
+ ], FlowRendererResizeObserver);
631
+
632
+ // src/layers/flow-nodes-transform-layer.ts
633
+ var FlowNodesTransformLayer = class extends Layer {
634
+ constructor() {
635
+ super(...arguments);
636
+ this.node = domUtils.createDivWithClass("gedit-flow-nodes-layer");
637
+ // onViewportChange() {
638
+ // this.throttleUpdate()
639
+ // }
640
+ // throttleUpdate = throttle(() => {
641
+ // this.renderCache.getFromCache().forEach((cache) => cache.updateBounds())
642
+ // }, 100)
643
+ this.renderCache = Cache.create(
644
+ (transform) => {
645
+ const { renderState } = transform;
646
+ const { node } = renderState;
647
+ const { entity } = transform;
648
+ node.id = entity.id;
649
+ let resizeDispose;
650
+ const append = () => {
651
+ if (resizeDispose) return;
652
+ this.renderElement.appendChild(node);
653
+ if (!entity.getNodeMeta().autoResizeDisable) {
654
+ resizeDispose = this.resizeObserver.observe(node, transform);
655
+ }
656
+ };
657
+ const dispose = () => {
658
+ if (!resizeDispose) return;
659
+ if (node.parentElement) {
660
+ this.renderElement.removeChild(node);
661
+ }
662
+ resizeDispose.dispose();
663
+ resizeDispose = void 0;
664
+ };
665
+ append();
666
+ return {
667
+ dispose,
668
+ updateBounds: () => {
669
+ const { bounds } = transform;
670
+ const rawX = parseFloat(node.style.left);
671
+ const rawY = parseFloat(node.style.top);
672
+ if (!this.isCoordEqual(rawX, bounds.x) || !this.isCoordEqual(rawY, bounds.y)) {
673
+ node.style.left = `${bounds.x}px`;
674
+ node.style.top = `${bounds.y}px`;
675
+ }
676
+ }
677
+ };
678
+ }
679
+ );
680
+ }
681
+ get transformVisibles() {
682
+ return this.document.getRenderDatas(FlowNodeTransformData, false);
683
+ }
684
+ /**
685
+ * 监听缩放,目前采用整体缩放
686
+ * @param scale
687
+ */
688
+ onZoom(scale) {
689
+ this.node.style.transform = `scale(${scale})`;
690
+ }
691
+ dispose() {
692
+ this.renderCache.dispose();
693
+ super.dispose();
694
+ }
695
+ isCoordEqual(a, b) {
696
+ const browserCoordEpsilon = 0.05;
697
+ return Math.abs(a - b) < browserCoordEpsilon;
698
+ }
699
+ onReady() {
700
+ this.node.style.zIndex = "10";
701
+ }
702
+ get visibeBounds() {
703
+ return this.transformVisibles.map((transform) => transform.bounds);
704
+ }
705
+ /**
706
+ * 更新节点的 bounds 数据
707
+ */
708
+ updateNodesBounds() {
709
+ this.renderCache.getMoreByItems(this.transformVisibles).forEach((render) => render.updateBounds());
710
+ }
711
+ autorun() {
712
+ if (this.documentTransformer.loading) return;
713
+ this.documentTransformer.refresh();
714
+ this.updateNodesBounds();
715
+ }
716
+ get renderElement() {
717
+ if (typeof this.options.renderElement === "function") {
718
+ const element = this.options.renderElement();
719
+ if (element) {
720
+ return element;
721
+ }
722
+ } else if (typeof this.options.renderElement !== "undefined") {
723
+ return this.options.renderElement;
724
+ }
725
+ return this.node;
726
+ }
727
+ };
728
+ __decorateClass([
729
+ inject(FlowDocument)
730
+ ], FlowNodesTransformLayer.prototype, "document", 2);
731
+ __decorateClass([
732
+ inject(FlowRendererResizeObserver)
733
+ ], FlowNodesTransformLayer.prototype, "resizeObserver", 2);
734
+ __decorateClass([
735
+ observeEntity(FlowDocumentTransformerEntity)
736
+ ], FlowNodesTransformLayer.prototype, "documentTransformer", 2);
737
+ __decorateClass([
738
+ observeEntityDatas(FlowNodeEntity, FlowNodeTransformData)
739
+ ], FlowNodesTransformLayer.prototype, "_transforms", 2);
740
+ FlowNodesTransformLayer = __decorateClass([
741
+ injectable()
742
+ ], FlowNodesTransformLayer);
743
+ var LayerVueProvide = defineComponent({
744
+ name: "LayerVueProvide",
745
+ props: {
746
+ factory: {
747
+ type: Object,
748
+ required: true
749
+ }
750
+ },
751
+ setup(props) {
752
+ const factory = props.factory;
753
+ provide(PlaygroundVueContainerKey, factory);
754
+ try {
755
+ provide(PlaygroundVueRefKey, factory.get(Playground));
756
+ } catch {
757
+ }
758
+ },
759
+ render() {
760
+ return this.$slots.default?.();
761
+ }
762
+ });
763
+ function wrapLayerRender(factory, children) {
764
+ return h(LayerVueProvide, { factory }, () => children);
765
+ }
766
+
767
+ // src/flow-renderer-contribution.ts
768
+ var FlowRendererContribution = /* @__PURE__ */ Symbol("FlowRendererContribution");
769
+
770
+ // src/flow-renderer-registry.ts
771
+ var FlowRendererComponentType = /* @__PURE__ */ ((FlowRendererComponentType2) => {
772
+ FlowRendererComponentType2[FlowRendererComponentType2["VUE"] = 0] = "VUE";
773
+ FlowRendererComponentType2[FlowRendererComponentType2["DOM"] = 1] = "DOM";
774
+ FlowRendererComponentType2[FlowRendererComponentType2["TEXT"] = 2] = "TEXT";
775
+ return FlowRendererComponentType2;
776
+ })(FlowRendererComponentType || {});
777
+ var FlowRendererKey = /* @__PURE__ */ ((FlowRendererKey2) => {
778
+ FlowRendererKey2["NODE_RENDER"] = "node-render";
779
+ FlowRendererKey2["ADDER"] = "adder";
780
+ FlowRendererKey2["COLLAPSE"] = "collapse";
781
+ FlowRendererKey2["BRANCH_ADDER"] = "branch-adder";
782
+ FlowRendererKey2["TRY_CATCH_COLLAPSE"] = "try-catch-collapse";
783
+ FlowRendererKey2["DRAG_NODE"] = "drag-node";
784
+ FlowRendererKey2["DRAGGABLE_ADDER"] = "draggable-adder";
785
+ FlowRendererKey2["DRAG_HIGHLIGHT_ADDER"] = "drag-highlight-adder";
786
+ FlowRendererKey2["DRAG_BRANCH_HIGHLIGHT_ADDER"] = "drag-branch-highlight-adder";
787
+ FlowRendererKey2["SELECTOR_BOX_POPOVER"] = "selector-box-popover";
788
+ FlowRendererKey2["CONTEXT_MENU_POPOVER"] = "context-menu-popover";
789
+ FlowRendererKey2["SUB_CANVAS"] = "sub-canvas";
790
+ FlowRendererKey2["SLOT_ADDER"] = "slot-adder";
791
+ FlowRendererKey2["SLOT_LABEL"] = "slot-label";
792
+ FlowRendererKey2["SLOT_COLLAPSE"] = "slot-collapse";
793
+ FlowRendererKey2["ARROW_RENDERER"] = "arrow-renderer";
794
+ FlowRendererKey2["MARKER_ARROW"] = "marker-arrow";
795
+ FlowRendererKey2["MARKER_ACTIVATE_ARROW"] = "marker-active-arrow";
796
+ return FlowRendererKey2;
797
+ })(FlowRendererKey || {});
798
+ var FlowTextKey = /* @__PURE__ */ ((FlowTextKey2) => {
799
+ FlowTextKey2["LOOP_END_TEXT"] = "loop-end-text";
800
+ FlowTextKey2["LOOP_TRAVERSE_TEXT"] = "loop-traverse-text";
801
+ FlowTextKey2["LOOP_WHILE_TEXT"] = "loop-while-text";
802
+ FlowTextKey2["TRY_START_TEXT"] = "try-start-text";
803
+ FlowTextKey2["TRY_END_TEXT"] = "try-end-text";
804
+ FlowTextKey2["CATCH_TEXT"] = "catch-text";
805
+ return FlowTextKey2;
806
+ })(FlowTextKey || {});
807
+ var FlowRendererCommandCategory = /* @__PURE__ */ ((FlowRendererCommandCategory2) => {
808
+ FlowRendererCommandCategory2["SELECTOR_BOX"] = "SELECTOR_BOX";
809
+ return FlowRendererCommandCategory2;
810
+ })(FlowRendererCommandCategory || {});
811
+ var FlowRendererRegistry = class {
812
+ constructor() {
813
+ this.componentsMap = /* @__PURE__ */ new Map();
814
+ this.textMap = /* @__PURE__ */ new Map();
815
+ this.contribs = [];
816
+ }
817
+ init() {
818
+ this.contribs.forEach((contrib) => contrib.registerRenderer?.(this));
819
+ }
820
+ /**
821
+ * 注册 组件数据
822
+ */
823
+ registerRendererComponents(renderKey, comp) {
824
+ this.componentsMap.set(renderKey, comp);
825
+ }
826
+ registerVueComponent(renderKey, renderer) {
827
+ this.componentsMap.set(renderKey, {
828
+ type: 0 /* VUE */,
829
+ renderer
830
+ });
831
+ }
832
+ /**
833
+ * 注册文案
834
+ */
835
+ registerText(configs) {
836
+ Object.entries(configs).forEach(([key, value]) => {
837
+ this.textMap.set(key, value);
838
+ });
839
+ }
840
+ getText(textKey) {
841
+ return I18n.t(textKey, { defaultValue: "" }) || this.textMap.get(textKey);
842
+ }
843
+ /**
844
+ * TODO: support memo
845
+ */
846
+ getRendererComponent(renderKey) {
847
+ const comp = this.componentsMap.get(renderKey);
848
+ if (!comp) {
849
+ throw new Error(`Unknown render key ${renderKey}`);
850
+ }
851
+ return comp;
852
+ }
853
+ tryToGetRendererComponent(renderKey) {
854
+ return this.componentsMap.get(renderKey);
855
+ }
856
+ /**
857
+ * 注册画布层
858
+ */
859
+ registerLayers(...layerRegistries) {
860
+ layerRegistries.forEach((layer) => this.pipeline.registerLayer(layer));
861
+ }
862
+ /**
863
+ * 根据配置注册画布
864
+ * @param layerRegistry
865
+ * @param options
866
+ */
867
+ registerLayer(layerRegistry, options) {
868
+ this.pipeline.registerLayer(layerRegistry, options);
869
+ }
870
+ };
871
+ __decorateClass([
872
+ multiInject(FlowRendererContribution),
873
+ optional()
874
+ ], FlowRendererRegistry.prototype, "contribs", 2);
875
+ __decorateClass([
876
+ inject(PipelineRegistry)
877
+ ], FlowRendererRegistry.prototype, "pipeline", 2);
878
+ FlowRendererRegistry = __decorateClass([
879
+ injectable()
880
+ ], FlowRendererRegistry);
881
+
882
+ // src/layers/flow-nodes-content-layer.ts
883
+ var FlowNodesContentLayer = class extends Layer {
884
+ constructor() {
885
+ super(...arguments);
886
+ this.renderMemoCache = /* @__PURE__ */ new WeakMap();
887
+ this.node = domUtils.createDivWithClass("gedit-flow-nodes-layer");
888
+ this.vuePortals = Cache.create(
889
+ (data) => {
890
+ const { node, entity } = data;
891
+ const { config } = this;
892
+ const PortalRenderer = this.getPortalRenderer(data);
893
+ const Portal = defineComponent({
894
+ name: "FlowNodePortal",
895
+ setup() {
896
+ provide(PlaygroundEntityContextKey, entity);
897
+ onMounted(() => {
898
+ if (!entity.getNodeMeta().autoResizeDisable && node.clientWidth && node.clientHeight) {
899
+ const transform = entity.getData(FlowNodeTransformData);
900
+ if (transform)
901
+ transform.size = {
902
+ width: node.clientWidth,
903
+ height: node.clientHeight
904
+ };
905
+ }
906
+ });
907
+ return () => h(Teleport, { to: node }, [
908
+ h(PortalRenderer, {
909
+ node: entity,
910
+ version: data?.version,
911
+ activated: data?.activated,
912
+ readonly: config.readonly,
913
+ disabled: config.disabled
914
+ })
915
+ ]);
916
+ }
917
+ });
918
+ return {
919
+ id: node.id || entity.id,
920
+ dispose: () => {
921
+ },
922
+ Portal
923
+ };
924
+ }
925
+ );
926
+ }
927
+ get renderStatesVisible() {
928
+ return this.document.getRenderDatas(FlowNodeRenderData, false);
929
+ }
930
+ getPortalRenderer(data) {
931
+ const meta = data.entity.getNodeMeta();
932
+ const renderer = this.rendererRegistry.getRendererComponent(
933
+ meta.renderKey || "node-render" /* NODE_RENDER */
934
+ );
935
+ const vueRenderer = renderer.renderer;
936
+ let memoCache = this.renderMemoCache.get(vueRenderer);
937
+ if (!memoCache) {
938
+ memoCache = vueRenderer;
939
+ this.renderMemoCache.set(vueRenderer, memoCache);
940
+ }
941
+ return memoCache;
942
+ }
943
+ /**
944
+ * 监听缩放,目前采用整体缩放
945
+ * @param scale
946
+ */
947
+ onZoom(scale) {
948
+ this.node.style.transform = `scale(${scale})`;
949
+ }
950
+ dispose() {
951
+ this.vuePortals.dispose();
952
+ super.dispose();
953
+ }
954
+ onReady() {
955
+ this.node.style.zIndex = "10";
956
+ }
957
+ /**
958
+ * 监听readonly和 disabled 状态 并刷新layer, 并刷新节点
959
+ */
960
+ onReadonlyOrDisabledChange() {
961
+ this.render();
962
+ }
963
+ getPortals() {
964
+ return this.vuePortals.getMoreByItems(this.renderStatesVisible);
965
+ }
966
+ render() {
967
+ if (this.documentTransformer.loading) return null;
968
+ this.documentTransformer.refresh();
969
+ return wrapLayerRender(
970
+ this.playgroundContainer,
971
+ h(
972
+ Fragment,
973
+ null,
974
+ this.getPortals().map((portal) => h(portal.Portal, { key: portal.id }))
975
+ )
976
+ );
977
+ }
978
+ };
979
+ __decorateClass([
980
+ inject(FlowDocument)
981
+ ], FlowNodesContentLayer.prototype, "document", 2);
982
+ __decorateClass([
983
+ inject(FlowRendererRegistry)
984
+ ], FlowNodesContentLayer.prototype, "rendererRegistry", 2);
985
+ __decorateClass([
986
+ inject(PlaygroundContainerFactory)
987
+ ], FlowNodesContentLayer.prototype, "playgroundContainer", 2);
988
+ __decorateClass([
989
+ observeEntity(FlowDocumentTransformerEntity)
990
+ ], FlowNodesContentLayer.prototype, "documentTransformer", 2);
991
+ __decorateClass([
992
+ observeEntityDatas(FlowNodeEntity, FlowNodeRenderData)
993
+ ], FlowNodesContentLayer.prototype, "_renderStates", 2);
994
+ FlowNodesContentLayer = __decorateClass([
995
+ injectable()
996
+ ], FlowNodesContentLayer);
997
+ var StraightLine = defineComponent({
998
+ name: "StraightLine",
999
+ inheritAttrs: false,
1000
+ setup(_, { attrs }) {
1001
+ const line = attrs;
1002
+ const { baseColor, baseActivatedColor } = useBaseColor();
1003
+ return () => {
1004
+ const { from, to, activated, style } = line;
1005
+ return h("path", {
1006
+ "data-line-id": line.lineId,
1007
+ d: `M ${from.x} ${from.y} L ${to.x} ${to.y}`,
1008
+ ...DEFAULT_LINE_ATTRS,
1009
+ stroke: activated ? baseActivatedColor : baseColor,
1010
+ style
1011
+ });
1012
+ };
1013
+ }
1014
+ });
1015
+ var StraightLine_default = StraightLine;
1016
+ var MARK_ARROW_ID = "$marker_arrow$";
1017
+ var MarkerArrow = defineComponent({
1018
+ name: "MarkerArrow",
1019
+ props: {
1020
+ id: {
1021
+ type: String,
1022
+ required: true
1023
+ }
1024
+ },
1025
+ setup(props) {
1026
+ const { baseColor } = useBaseColor();
1027
+ return () => h(
1028
+ "marker",
1029
+ {
1030
+ "data-line-id": props.id,
1031
+ id: props.id || MARK_ARROW_ID,
1032
+ markerWidth: "11",
1033
+ markerHeight: "14",
1034
+ refX: "10",
1035
+ refY: "7",
1036
+ orient: "auto"
1037
+ },
1038
+ [
1039
+ h("path", {
1040
+ d: "M9.6 5.2C10.8 6.1 10.8 7.9 9.6 8.8L3.6 13.3C2.11672 14.4125 0 13.3541 0 11.5L0 2.5C0 0.645898 2.11672 -0.412461 3.6 0.7L9.6 5.2Z",
1041
+ fill: baseColor
1042
+ })
1043
+ ]
1044
+ );
1045
+ }
1046
+ });
1047
+ var MarkerArrow_default = MarkerArrow;
1048
+ var MARK_ACTIVATED_ARROW_ID = "$marker_arrow_activated$";
1049
+ var MarkerActivatedArrow = defineComponent({
1050
+ name: "MarkerActivatedArrow",
1051
+ props: {
1052
+ id: {
1053
+ type: String,
1054
+ default: void 0
1055
+ }
1056
+ },
1057
+ setup(props) {
1058
+ const { baseActivatedColor } = useBaseColor();
1059
+ return () => h(
1060
+ "marker",
1061
+ {
1062
+ "data-line-id": props.id,
1063
+ id: props.id || MARK_ACTIVATED_ARROW_ID,
1064
+ markerWidth: "11",
1065
+ markerHeight: "14",
1066
+ refX: "10",
1067
+ refY: "7",
1068
+ orient: "auto"
1069
+ },
1070
+ [
1071
+ h("path", {
1072
+ d: "M9.6 5.2C10.8 6.1 10.8 7.9 9.6 8.8L3.6 13.3C2.11672 14.4125 0 13.3541 0 11.5L0 2.5C0 0.645898 2.11672 -0.412461 3.6 0.7L9.6 5.2Z",
1073
+ fill: baseActivatedColor
1074
+ })
1075
+ ]
1076
+ );
1077
+ }
1078
+ });
1079
+ var MarkerActivatedArrow_default = MarkerActivatedArrow;
1080
+
1081
+ // src/components/RoundedTurningLine.ts
1082
+ var MarkerDefs = defineComponent({
1083
+ name: "MarkerDefs",
1084
+ props: {
1085
+ id: { type: String, required: true },
1086
+ activated: { type: Boolean, default: false }
1087
+ },
1088
+ setup(props) {
1089
+ const container = inject$1(PlaygroundVueContainerKey, null);
1090
+ return () => {
1091
+ const renderRegistry = container?.get?.(FlowRendererRegistry);
1092
+ const ArrowRenderer = renderRegistry?.tryToGetRendererComponent(
1093
+ props.activated ? "marker-active-arrow" /* MARKER_ACTIVATE_ARROW */ : "marker-arrow" /* MARKER_ARROW */
1094
+ );
1095
+ if (ArrowRenderer) {
1096
+ return h(ArrowRenderer.renderer, { id: props.id, activated: props.activated });
1097
+ }
1098
+ if (props.activated) {
1099
+ return h("defs", null, [h(MarkerActivatedArrow_default, { id: props.id })]);
1100
+ }
1101
+ return h("defs", null, [h(MarkerArrow_default, { id: props.id })]);
1102
+ };
1103
+ }
1104
+ });
1105
+ var RoundedTurningLine = defineComponent({
1106
+ name: "RoundedTurningLine",
1107
+ inheritAttrs: false,
1108
+ setup(_, { attrs }) {
1109
+ const props = attrs;
1110
+ const { baseActivatedColor, baseColor } = useBaseColor();
1111
+ const realVertices = computed(() => {
1112
+ const { vertices, xRadius, yRadius } = props;
1113
+ return vertices || (props.isHorizontal ? getHorizontalVertices(props, xRadius, yRadius) : getVertices(props, xRadius, yRadius));
1114
+ });
1115
+ const middleStr = computed(() => {
1116
+ const { radius = DEFAULT_RADIUS, from, to } = props;
1117
+ const vertices = realVertices.value;
1118
+ return vertices.map((point, idx) => {
1119
+ const prev = vertices[idx - 1] || from;
1120
+ const next = vertices[idx + 1] || to;
1121
+ const prevDelta = { x: Math.abs(prev.x - point.x), y: Math.abs(prev.y - point.y) };
1122
+ const nextDelta = { x: Math.abs(next.x - point.x), y: Math.abs(next.y - point.y) };
1123
+ const isRightAngleX = prevDelta.x === 0 && nextDelta.y === 0;
1124
+ const isRightAngleY = prevDelta.y === 0 && nextDelta.x === 0;
1125
+ const isRightAngle = isRightAngleX || isRightAngleY;
1126
+ if (!isRightAngle) {
1127
+ console.error(`vertex ${point.x},${point.y} is not right angle`);
1128
+ }
1129
+ const inPoint = new Point().copyFrom(point);
1130
+ const outPoint = new Point().copyFrom(point);
1131
+ const radiusX = isNil(point.radiusX) ? radius : point.radiusX;
1132
+ const radiusY = isNil(point.radiusY) ? radius : point.radiusY;
1133
+ let rx = radiusX;
1134
+ let ry = radiusY;
1135
+ if (isRightAngleX) {
1136
+ ry = Math.min(prevDelta.y, radiusY);
1137
+ const moveY = isNil(point.moveY) ? ry : point.moveY;
1138
+ inPoint.y += from.y < point.y ? -moveY : +moveY;
1139
+ rx = Math.min(nextDelta.x, radiusX);
1140
+ const moveX = isNil(point.moveX) ? rx : point.moveX;
1141
+ outPoint.x += to.x < point.x ? -moveX : +moveX;
1142
+ }
1143
+ if (isRightAngleY) {
1144
+ rx = Math.min(prevDelta.x, radiusX);
1145
+ const moveX = isNil(point.moveX) ? rx : point.moveX;
1146
+ inPoint.x += from.x < point.x ? -moveX : +moveX;
1147
+ ry = Math.min(nextDelta.y, radiusY);
1148
+ const moveY = isNil(point.moveY) ? ry : point.moveY;
1149
+ outPoint.y += to.y < point.y ? -moveY : +moveY;
1150
+ }
1151
+ if (point.radiusOverflow === "truncate") {
1152
+ rx = radiusX;
1153
+ ry = radiusY;
1154
+ }
1155
+ const crossProduct = (point.x - inPoint.x) * (outPoint.y - inPoint.y) - (point.y - inPoint.y) * (outPoint.x - inPoint.x);
1156
+ const isClockWise = crossProduct > 0;
1157
+ return `L ${inPoint.x} ${inPoint.y} A ${rx} ${ry} 0 0 ${isClockWise ? 1 : 0} ${outPoint.x} ${outPoint.y}`;
1158
+ }).join(" ");
1159
+ });
1160
+ return () => {
1161
+ const { hide, from, to, arrow, activated, style } = props;
1162
+ if (hide) {
1163
+ return null;
1164
+ }
1165
+ const pathStr = `M ${from.x} ${from.y} ${middleStr.value} L ${to.x} ${to.y}`;
1166
+ const markerId = activated ? `${MARK_ACTIVATED_ARROW_ID}${props.lineId}` : `${MARK_ARROW_ID}${props.lineId}`;
1167
+ return [
1168
+ arrow ? h(MarkerDefs, { id: markerId, activated }) : null,
1169
+ h("path", {
1170
+ "data-line-id": props.lineId,
1171
+ d: pathStr,
1172
+ ...DEFAULT_LINE_ATTRS,
1173
+ stroke: activated ? baseActivatedColor : baseColor,
1174
+ ...arrow ? {
1175
+ markerEnd: `url(#${markerId})`
1176
+ } : {},
1177
+ style
1178
+ })
1179
+ ];
1180
+ };
1181
+ }
1182
+ });
1183
+ var RoundedTurningLine_default = RoundedTurningLine;
1184
+ var CustomLine = defineComponent({
1185
+ name: "CustomLine",
1186
+ inheritAttrs: false,
1187
+ setup(_, { attrs }) {
1188
+ return () => {
1189
+ const props = attrs;
1190
+ const { renderKey, rendererRegistry, ...line } = props;
1191
+ if (!renderKey) {
1192
+ return null;
1193
+ }
1194
+ const renderer = rendererRegistry.getRendererComponent(renderKey);
1195
+ if (!renderer) {
1196
+ return null;
1197
+ }
1198
+ return h(renderer.renderer, { lineId: props.lineId, ...line });
1199
+ };
1200
+ }
1201
+ });
1202
+ var CustomLine_default = CustomLine;
1203
+
1204
+ // src/components/LinesRenderer.ts
1205
+ function createLines(props) {
1206
+ const { data, rendererRegistry, linesSave, dragService } = props;
1207
+ const { lines, entity } = data || {};
1208
+ const radius = getDefaultSpacing(entity, DefaultSpacingKey.ROUNDED_LINE_RADIUS);
1209
+ const xRadius = getDefaultSpacing(entity, DefaultSpacingKey.ROUNDED_LINE_X_RADIUS);
1210
+ const yRadius = getDefaultSpacing(entity, DefaultSpacingKey.ROUNDED_LINE_Y_RADIUS);
1211
+ const renderLine = (line, index) => {
1212
+ const { renderData } = data;
1213
+ const { isVertical } = data.entity;
1214
+ const { lineActivated } = renderData || {};
1215
+ const draggingLineHide = (line.type === FlowTransitionLineEnum.DRAGGING_LINE || line.isDraggingLine) && !dragService.isDroppableBranch(data.entity, line.side);
1216
+ const draggingLineActivated = (line.type === FlowTransitionLineEnum.DRAGGING_LINE || line.isDraggingLine) && data.entity?.id === dragService.dropNodeId && line.side === dragService.labelSide;
1217
+ switch (line.type) {
1218
+ case FlowTransitionLineEnum.STRAIGHT_LINE:
1219
+ return h(StraightLine_default, {
1220
+ key: `${data.entity.id}_${index}`,
1221
+ lineId: data.entity.id,
1222
+ activated: lineActivated,
1223
+ ...line
1224
+ });
1225
+ case FlowTransitionLineEnum.DIVERGE_LINE:
1226
+ case FlowTransitionLineEnum.DRAGGING_LINE:
1227
+ case FlowTransitionLineEnum.MERGE_LINE:
1228
+ case FlowTransitionLineEnum.ROUNDED_LINE:
1229
+ return h(RoundedTurningLine_default, {
1230
+ key: `${data.entity.id}_${index}`,
1231
+ lineId: data.entity.id,
1232
+ isHorizontal: !isVertical,
1233
+ activated: lineActivated || draggingLineActivated,
1234
+ radius,
1235
+ ...line,
1236
+ xRadius,
1237
+ yRadius,
1238
+ hide: draggingLineHide
1239
+ });
1240
+ case FlowTransitionLineEnum.CUSTOM_LINE:
1241
+ return h(CustomLine_default, {
1242
+ key: `${data.entity.id}_${index}`,
1243
+ lineId: data.entity.id,
1244
+ ...line,
1245
+ rendererRegistry
1246
+ });
1247
+ }
1248
+ return void 0;
1249
+ };
1250
+ lines.forEach((line, index) => {
1251
+ const bounds = Rectangle.createRectangleWithTwoPoints(line.from, line.to).pad(10);
1252
+ if (props.isViewportVisible(bounds)) {
1253
+ const vnode = renderLine(line, index);
1254
+ if (vnode) linesSave.push(vnode);
1255
+ }
1256
+ });
1257
+ }
1258
+
1259
+ // src/layers/flow-lines-layer.ts
1260
+ var FlowLinesLayer = class extends Layer {
1261
+ constructor() {
1262
+ super(...arguments);
1263
+ this.node = domUtils.createDivWithClass("gedit-flow-lines-layer");
1264
+ /**
1265
+ * 可视区域变化
1266
+ */
1267
+ this.onViewportChange = throttle(() => {
1268
+ this.render();
1269
+ }, 100);
1270
+ }
1271
+ get transitions() {
1272
+ return this.document.getRenderDatas(FlowNodeTransitionData);
1273
+ }
1274
+ onZoom() {
1275
+ const svgContainer = this.node.querySelector("svg.flow-lines-container");
1276
+ svgContainer?.setAttribute?.("viewBox", this.viewBox);
1277
+ }
1278
+ onReady() {
1279
+ this.node.style.zIndex = "1";
1280
+ }
1281
+ get viewBox() {
1282
+ const ratio = 1e3 / this.config.finalScale;
1283
+ return `0 0 ${ratio} ${ratio}`;
1284
+ }
1285
+ render() {
1286
+ const allLines = [];
1287
+ const isViewportVisible = this.config.isViewportVisible.bind(this.config);
1288
+ if (this.documentTransformer.loading) return null;
1289
+ this.documentTransformer.refresh();
1290
+ this.transitions.forEach((transition) => {
1291
+ createLines({
1292
+ data: transition,
1293
+ rendererRegistry: this.rendererRegistry,
1294
+ isViewportVisible,
1295
+ linesSave: allLines,
1296
+ dragService: this.dragService
1297
+ });
1298
+ });
1299
+ const { activateLines = [], normalLines = [] } = groupBy(
1300
+ allLines,
1301
+ (line) => line.props?.activated ? "activateLines" : "normalLines"
1302
+ );
1303
+ const resultLines = [...normalLines, ...activateLines];
1304
+ return wrapLayerRender(
1305
+ this.playgroundContainer,
1306
+ h(
1307
+ "svg",
1308
+ {
1309
+ class: "flow-lines-container",
1310
+ width: "1000",
1311
+ height: "1000",
1312
+ overflow: "visible",
1313
+ viewBox: this.viewBox,
1314
+ xmlns: "http://www.w3.org/2000/svg"
1315
+ },
1316
+ resultLines
1317
+ )
1318
+ );
1319
+ }
1320
+ };
1321
+ __decorateClass([
1322
+ inject(FlowDocument)
1323
+ ], FlowLinesLayer.prototype, "document", 2);
1324
+ __decorateClass([
1325
+ inject(FlowDragService)
1326
+ ], FlowLinesLayer.prototype, "dragService", 2);
1327
+ __decorateClass([
1328
+ inject(FlowRendererRegistry)
1329
+ ], FlowLinesLayer.prototype, "rendererRegistry", 2);
1330
+ __decorateClass([
1331
+ inject(PlaygroundContainerFactory)
1332
+ ], FlowLinesLayer.prototype, "playgroundContainer", 2);
1333
+ __decorateClass([
1334
+ observeEntity(FlowDocumentTransformerEntity)
1335
+ ], FlowLinesLayer.prototype, "documentTransformer", 2);
1336
+ __decorateClass([
1337
+ observeEntity(FlowRendererStateEntity)
1338
+ ], FlowLinesLayer.prototype, "flowRenderState", 2);
1339
+ __decorateClass([
1340
+ observeEntityDatas(FlowNodeEntity, FlowNodeTransitionData)
1341
+ ], FlowLinesLayer.prototype, "_transitions", 2);
1342
+ FlowLinesLayer = __decorateClass([
1343
+ injectable()
1344
+ ], FlowLinesLayer);
1345
+ var Collapse = defineComponent({
1346
+ name: "Collapse",
1347
+ inheritAttrs: false,
1348
+ setup(_, { attrs }) {
1349
+ const hoverActivated = ref(false);
1350
+ return () => {
1351
+ const props = attrs;
1352
+ const {
1353
+ data,
1354
+ rendererRegistry,
1355
+ forceVisible,
1356
+ hoverHeight = getTransitionLabelHoverHeight(data),
1357
+ hoverWidth = getTransitionLabelHoverWidth(data),
1358
+ wrapperStyle,
1359
+ ...restProps
1360
+ } = props;
1361
+ const { activateNode } = restProps;
1362
+ const activateData = activateNode?.getData(FlowNodeRenderData);
1363
+ const handleMouseEnter = () => {
1364
+ hoverActivated.value = true;
1365
+ activateData?.toggleMouseEnter();
1366
+ };
1367
+ const handleMouseLeave = () => {
1368
+ hoverActivated.value = false;
1369
+ activateData?.toggleMouseLeave();
1370
+ };
1371
+ const collapseOpener = rendererRegistry.getRendererComponent("collapse" /* COLLAPSE */);
1372
+ const node = data.entity;
1373
+ const child = h(collapseOpener.renderer, {
1374
+ node,
1375
+ collapseNode: node,
1376
+ ...restProps,
1377
+ hoverActivated: hoverActivated.value
1378
+ });
1379
+ const isChildVisible = data.collapsed || activateData?.hovered || hoverActivated.value || forceVisible;
1380
+ return h(
1381
+ "div",
1382
+ {
1383
+ class: "flow-canvas-collapse",
1384
+ onMouseenter: handleMouseEnter,
1385
+ onMouseleave: handleMouseLeave,
1386
+ style: {
1387
+ width: `${hoverWidth}px`,
1388
+ height: `${hoverHeight}px`,
1389
+ display: "flex",
1390
+ justifyContent: "center",
1391
+ alignItems: "center",
1392
+ ...wrapperStyle
1393
+ }
1394
+ },
1395
+ [isChildVisible ? child : null]
1396
+ );
1397
+ };
1398
+ }
1399
+ });
1400
+ var Collapse_default = Collapse;
1401
+ var getFlowRenderKey = (node, { dragService }) => {
1402
+ if (dragService && dragService.dragging && dragService.isDroppableNode(node)) {
1403
+ if (dragService.dropNodeId === node.id) {
1404
+ return "drag-highlight-adder" /* DRAG_HIGHLIGHT_ADDER */;
1405
+ }
1406
+ return "draggable-adder" /* DRAGGABLE_ADDER */;
1407
+ }
1408
+ return "adder" /* ADDER */;
1409
+ };
1410
+ var Adder = defineComponent({
1411
+ name: "Adder",
1412
+ inheritAttrs: false,
1413
+ setup(_, { attrs }) {
1414
+ const props = attrs;
1415
+ const hoverActivated = ref(false);
1416
+ const dragService = useService(FlowDragService);
1417
+ const handleMouseEnter = () => {
1418
+ hoverActivated.value = true;
1419
+ };
1420
+ const handleMouseLeave = () => {
1421
+ hoverActivated.value = false;
1422
+ };
1423
+ return () => {
1424
+ const {
1425
+ data,
1426
+ rendererRegistry,
1427
+ hoverHeight = getTransitionLabelHoverHeight(data),
1428
+ hoverWidth = getTransitionLabelHoverWidth(data),
1429
+ ...restProps
1430
+ } = props;
1431
+ const node = data.entity;
1432
+ const flowRenderKey = getFlowRenderKey(node, { dragService });
1433
+ const adder = rendererRegistry.getRendererComponent(flowRenderKey);
1434
+ const from = node;
1435
+ const to = data.entity.document.renderTree.getOriginInfo(node).next;
1436
+ const renderTo = node.next;
1437
+ const child = h(adder.renderer, {
1438
+ node,
1439
+ from,
1440
+ to,
1441
+ renderTo,
1442
+ hoverActivated: hoverActivated.value,
1443
+ setHoverActivated: (v) => {
1444
+ hoverActivated.value = v;
1445
+ },
1446
+ hoverWidth,
1447
+ hoverHeight,
1448
+ ...restProps
1449
+ });
1450
+ return h(
1451
+ "div",
1452
+ {
1453
+ class: "flow-canvas-adder",
1454
+ "data-testid": "sdk.flowcanvas.line.adder",
1455
+ "data-from": from.id,
1456
+ "data-to": to?.id ?? "",
1457
+ onMouseenter: handleMouseEnter,
1458
+ onMouseleave: handleMouseLeave,
1459
+ style: {
1460
+ width: `${hoverWidth}px`,
1461
+ height: `${hoverHeight}px`,
1462
+ display: "flex",
1463
+ justifyContent: "center",
1464
+ alignItems: "center"
1465
+ }
1466
+ },
1467
+ [child]
1468
+ );
1469
+ };
1470
+ }
1471
+ });
1472
+ var Adder_default = Adder;
1473
+
1474
+ // src/components/CollapseAdder.ts
1475
+ var CollapseAdder = defineComponent({
1476
+ name: "CollapseAdder",
1477
+ inheritAttrs: false,
1478
+ setup(_, { attrs }) {
1479
+ const hoverActivated = ref(false);
1480
+ const handleMouseEnter = () => {
1481
+ hoverActivated.value = true;
1482
+ };
1483
+ const handleMouseLeave = () => {
1484
+ hoverActivated.value = false;
1485
+ };
1486
+ return () => {
1487
+ const props = attrs;
1488
+ const { data, activateNode } = props;
1489
+ const activateData = activateNode?.getData(FlowNodeRenderData);
1490
+ const isVertical = activateNode?.isVertical;
1491
+ const activated = activateData?.hovered || hoverActivated.value;
1492
+ if (isVertical) {
1493
+ return h(
1494
+ "div",
1495
+ {
1496
+ class: "flow-canvas-collapse-adder",
1497
+ onMouseenter: handleMouseEnter,
1498
+ onMouseleave: handleMouseLeave
1499
+ },
1500
+ [
1501
+ activated || data.collapsed ? h(Collapse_default, {
1502
+ ...props,
1503
+ forceVisible: true,
1504
+ wrapperStyle: { alignItems: "flex-end" },
1505
+ hoverHeight: 20
1506
+ }) : null,
1507
+ !data.collapsed ? h(Adder_default, { ...props, hoverHeight: activated ? 20 : 40, hoverActivated: activated }) : null
1508
+ ]
1509
+ );
1510
+ }
1511
+ return h(
1512
+ "div",
1513
+ {
1514
+ class: "flow-canvas-collapse-adder",
1515
+ onMouseenter: handleMouseEnter,
1516
+ onMouseleave: handleMouseLeave,
1517
+ style: {
1518
+ display: data.collapsed ? "block" : "flex"
1519
+ }
1520
+ },
1521
+ [
1522
+ activated || data.collapsed ? h(Collapse_default, {
1523
+ ...props,
1524
+ forceVisible: true,
1525
+ wrapperStyle: { justifyContent: "flex-end" },
1526
+ hoverWidth: 20
1527
+ }) : null,
1528
+ !data.collapsed ? h(Adder_default, { ...props, hoverWidth: activated ? 20 : 40, hoverActivated: activated }) : null
1529
+ ]
1530
+ );
1531
+ };
1532
+ }
1533
+ });
1534
+ var CollapseAdder_default = CollapseAdder;
1535
+ var getFlowRenderKey2 = (node, { dragService, side }) => {
1536
+ if (dragService.isDragBranch && side && dragService.labelSide === side && dragService.isDroppableBranch(node, side)) {
1537
+ if (dragService.dropNodeId === node.id) {
1538
+ return "drag-branch-highlight-adder" /* DRAG_BRANCH_HIGHLIGHT_ADDER */;
1539
+ }
1540
+ return "draggable-adder" /* DRAGGABLE_ADDER */;
1541
+ }
1542
+ return "";
1543
+ };
1544
+ var BranchDraggableRenderer = defineComponent({
1545
+ name: "BranchDraggableRenderer",
1546
+ inheritAttrs: false,
1547
+ setup(_, { attrs }) {
1548
+ const dragService = useService(FlowDragService);
1549
+ return () => {
1550
+ const props = attrs;
1551
+ const { data, rendererRegistry, side, ...restProps } = props;
1552
+ const node = data.entity;
1553
+ const flowRenderKey = getFlowRenderKey2(node, { side, dragService });
1554
+ if (!flowRenderKey) {
1555
+ return null;
1556
+ }
1557
+ const adder = rendererRegistry.getRendererComponent(flowRenderKey);
1558
+ const from = node;
1559
+ const to = data.entity.document.renderTree.getOriginInfo(node).next;
1560
+ const renderTo = node.next;
1561
+ const child = h(adder.renderer, {
1562
+ node,
1563
+ from,
1564
+ to,
1565
+ renderTo,
1566
+ ...restProps
1567
+ });
1568
+ return h("div", { class: "flow-canvas-branch-draggable-adder" }, [child]);
1569
+ };
1570
+ }
1571
+ });
1572
+ var BranchDraggableRenderer_default = BranchDraggableRenderer;
1573
+
1574
+ // src/components/LabelsRenderer.ts
1575
+ var TEXT_LABEL_STYLE = {
1576
+ fontSize: "12px",
1577
+ color: "#8F959E",
1578
+ textAlign: "center",
1579
+ whiteSpace: "nowrap",
1580
+ backgroundColor: "var(--g-editor-background)",
1581
+ lineHeight: "20px"
1582
+ };
1583
+ var LABEL_MAX_WIDTH = 150;
1584
+ var LABEL_MAX_HEIGHT = 60;
1585
+ function getLabelBounds(offset) {
1586
+ return new Rectangle(
1587
+ offset.x - LABEL_MAX_WIDTH / 2,
1588
+ offset.y - LABEL_MAX_HEIGHT / 2,
1589
+ LABEL_MAX_WIDTH,
1590
+ LABEL_MAX_HEIGHT
1591
+ );
1592
+ }
1593
+ function createLabels(labelProps) {
1594
+ const { data, rendererRegistry, labelsSave, getLabelColor } = labelProps;
1595
+ const { labels, renderData } = data || {};
1596
+ const { activated } = renderData || {};
1597
+ const renderLabel = (label, index) => {
1598
+ const { offset, renderKey, props, rotate, origin, type } = label || {};
1599
+ const offsetX = offset.x;
1600
+ const offsetY = offset.y;
1601
+ let child = null;
1602
+ switch (type) {
1603
+ case FlowTransitionLabelEnum.BRANCH_DRAGGING_LABEL:
1604
+ child = h(BranchDraggableRenderer_default, {
1605
+ labelId: label.labelId || labelProps.data.entity.id,
1606
+ rendererRegistry,
1607
+ data,
1608
+ ...props
1609
+ });
1610
+ break;
1611
+ case FlowTransitionLabelEnum.ADDER_LABEL:
1612
+ child = h(Adder_default, {
1613
+ labelId: label.labelId || labelProps.data.entity.id,
1614
+ rendererRegistry,
1615
+ data,
1616
+ ...props
1617
+ });
1618
+ break;
1619
+ case FlowTransitionLabelEnum.COLLAPSE_LABEL:
1620
+ child = h(Collapse_default, {
1621
+ labelId: label.labelId || labelProps.data.entity.id,
1622
+ rendererRegistry,
1623
+ data,
1624
+ ...props
1625
+ });
1626
+ break;
1627
+ case FlowTransitionLabelEnum.COLLAPSE_ADDER_LABEL:
1628
+ child = h(CollapseAdder_default, {
1629
+ labelId: label.labelId || labelProps.data.entity.id,
1630
+ rendererRegistry,
1631
+ data,
1632
+ ...props
1633
+ });
1634
+ break;
1635
+ case FlowTransitionLabelEnum.TEXT_LABEL:
1636
+ if (!renderKey) {
1637
+ return null;
1638
+ }
1639
+ const text = rendererRegistry.getText(renderKey) || renderKey;
1640
+ child = h(
1641
+ "div",
1642
+ {
1643
+ "data-label-id": label.labelId || labelProps.data.entity.id,
1644
+ style: {
1645
+ ...TEXT_LABEL_STYLE,
1646
+ ...props?.style,
1647
+ color: getLabelColor(activated),
1648
+ transform: rotate ? `rotate(${rotate})` : void 0
1649
+ }
1650
+ },
1651
+ text
1652
+ );
1653
+ break;
1654
+ case FlowTransitionLabelEnum.CUSTOM_LABEL:
1655
+ if (!renderKey) {
1656
+ return null;
1657
+ }
1658
+ try {
1659
+ const renderer = rendererRegistry.getRendererComponent(renderKey);
1660
+ child = h(renderer.renderer, {
1661
+ node: data.entity,
1662
+ labelId: label.labelId || labelProps.data.entity.id,
1663
+ ...props
1664
+ });
1665
+ } catch (err) {
1666
+ console.error(err);
1667
+ child = renderKey;
1668
+ }
1669
+ break;
1670
+ }
1671
+ const originX = typeof origin?.[0] === "number" ? origin?.[0] : 0.5;
1672
+ const originY = typeof origin?.[1] === "number" ? origin?.[1] : 0.5;
1673
+ return h(
1674
+ "div",
1675
+ {
1676
+ key: `${data.entity.id}${index}`,
1677
+ "data-label-id": label.labelId || labelProps.data.entity.id,
1678
+ style: {
1679
+ position: "absolute",
1680
+ left: `${offsetX}px`,
1681
+ top: `${offsetY}px`,
1682
+ transform: `translate(-${originX * 100}%, -${originY * 100}%)`
1683
+ }
1684
+ },
1685
+ [child]
1686
+ );
1687
+ };
1688
+ labels.forEach((label, index) => {
1689
+ if (labelProps.isViewportVisible(getLabelBounds(label.offset))) {
1690
+ const vnode = renderLabel(label, index);
1691
+ if (vnode) labelsSave.push(vnode);
1692
+ }
1693
+ });
1694
+ }
1695
+
1696
+ // src/layers/flow-labels-layer.ts
1697
+ var FlowLabelsLayer = class extends Layer {
1698
+ constructor() {
1699
+ super(...arguments);
1700
+ this.node = domUtils.createDivWithClass("gedit-flow-labels-layer");
1701
+ /**
1702
+ * 可视区域变化
1703
+ */
1704
+ this.onViewportChange = throttle(() => {
1705
+ this.render();
1706
+ }, 100);
1707
+ }
1708
+ get transitions() {
1709
+ return this.document.getRenderDatas(FlowNodeTransitionData);
1710
+ }
1711
+ /**
1712
+ * 监听缩放,目前采用整体缩放
1713
+ * @param scale
1714
+ */
1715
+ onZoom(scale) {
1716
+ this.node.style.transform = `scale(${scale})`;
1717
+ }
1718
+ onReady() {
1719
+ this.node.style.zIndex = "9";
1720
+ }
1721
+ /**
1722
+ * 监听readonly和 disabled 状态 并刷新layer, 并刷新
1723
+ */
1724
+ onReadonlyOrDisabledChange() {
1725
+ this.render();
1726
+ }
1727
+ render() {
1728
+ const labels = [];
1729
+ if (this.documentTransformer?.loading) return null;
1730
+ this.documentTransformer?.refresh?.();
1731
+ const { baseActivatedColor, baseColor } = getBaseColor(this.documentOptions);
1732
+ const isViewportVisible = this.config.isViewportVisible.bind(this.config);
1733
+ this.transitions.forEach((transition) => {
1734
+ createLabels({
1735
+ data: transition,
1736
+ rendererRegistry: this.rendererRegistry,
1737
+ isViewportVisible,
1738
+ labelsSave: labels,
1739
+ getLabelColor: (activated) => activated ? baseActivatedColor : baseColor
1740
+ });
1741
+ });
1742
+ return wrapLayerRender(this.playgroundContainer, h(Fragment, null, labels));
1743
+ }
1744
+ };
1745
+ __decorateClass([
1746
+ inject(FlowDocument)
1747
+ ], FlowLabelsLayer.prototype, "document", 2);
1748
+ __decorateClass([
1749
+ inject(FlowRendererRegistry)
1750
+ ], FlowLabelsLayer.prototype, "rendererRegistry", 2);
1751
+ __decorateClass([
1752
+ inject(PlaygroundContainerFactory)
1753
+ ], FlowLabelsLayer.prototype, "playgroundContainer", 2);
1754
+ __decorateClass([
1755
+ optional(),
1756
+ inject(FlowDocumentOptions)
1757
+ ], FlowLabelsLayer.prototype, "documentOptions", 2);
1758
+ __decorateClass([
1759
+ observeEntity(FlowDocumentTransformerEntity)
1760
+ ], FlowLabelsLayer.prototype, "documentTransformer", 2);
1761
+ __decorateClass([
1762
+ observeEntity(FlowRendererStateEntity)
1763
+ ], FlowLabelsLayer.prototype, "flowRenderState", 2);
1764
+ __decorateClass([
1765
+ observeEntityDatas(FlowNodeEntity, FlowNodeTransitionData)
1766
+ ], FlowLabelsLayer.prototype, "_transitions", 2);
1767
+ FlowLabelsLayer = __decorateClass([
1768
+ injectable()
1769
+ ], FlowLabelsLayer);
1770
+ var SCROLL_LIMIT_PADDING = -120;
1771
+ function getScrollViewport(scrollData, config) {
1772
+ const scale = config.finalScale;
1773
+ return new Rectangle(
1774
+ scrollData.scrollX / scale,
1775
+ scrollData.scrollY / scale,
1776
+ config.config.width / scale,
1777
+ config.config.height / scale
1778
+ ).pad(SCROLL_LIMIT_PADDING / scale, SCROLL_LIMIT_PADDING / scale);
1779
+ }
1780
+ function scrollLimit(scroll, boundsList, config, initScroll) {
1781
+ scroll = { ...scroll };
1782
+ const configData = config.config;
1783
+ const oldScroll = { scrollX: configData.scrollX, scrollY: configData.scrollY };
1784
+ if (boundsList.length === 0 || configData.width === 0 || configData.height === 0) return scroll;
1785
+ const viewport = getScrollViewport(scroll, config);
1786
+ const isVisible = boundsList.find((bounds) => Rectangle.isViewportVisible(bounds, viewport));
1787
+ if (!isVisible) {
1788
+ const oldViewport = getScrollViewport(oldScroll, config);
1789
+ const isOldVisible = boundsList.find(
1790
+ (bounds) => Rectangle.isViewportVisible(bounds, oldViewport)
1791
+ );
1792
+ if (!isOldVisible) {
1793
+ return initScroll();
1794
+ }
1795
+ return oldScroll;
1796
+ }
1797
+ return scroll;
1798
+ }
1799
+
1800
+ // src/utils/scroll-bar-events.ts
1801
+ var ScrollBarEvents = /* @__PURE__ */ Symbol("ScrollBarEvents");
1802
+
1803
+ // src/layers/flow-debug-layer.ts
1804
+ var rgbTimes = 0;
1805
+ function randomColor(percent) {
1806
+ const max = Math.min(percent / 10 * 255, 255);
1807
+ rgbTimes += 1;
1808
+ const rgb = rgbTimes % 3;
1809
+ const random = () => Math.floor(Math.random() * max);
1810
+ return `rgb(${rgb === 0 ? random() : 0}, ${rgb === 1 ? random() : 0}, ${rgb === 2 ? random() : 0})`;
1811
+ }
1812
+ var FlowDebugLayer = class extends Layer {
1813
+ constructor() {
1814
+ super(...arguments);
1815
+ this.node = document.createElement("div");
1816
+ this.viewport = domUtils.createDivWithClass("gedit-flow-debug-bounds");
1817
+ this.boundsNodes = domUtils.createDivWithClass("gedit-flow-debug-bounds");
1818
+ this.pointsNodes = domUtils.createDivWithClass("gedit-flow-debug-points");
1819
+ this.versionNodes = domUtils.createDivWithClass("gedit-flow-debug-versions gedit-hidden");
1820
+ /**
1821
+ * ?debug=xxxx, 则返回 xxxx
1822
+ */
1823
+ this.filterKey = window.location.search.match(/debug=([^&]+)/)?.[1] || "";
1824
+ this.originLine = document.createElement("div");
1825
+ this.domCache = /* @__PURE__ */ new WeakMap();
1826
+ }
1827
+ get transforms() {
1828
+ return this.document.getRenderDatas(FlowNodeTransformData);
1829
+ }
1830
+ onReady() {
1831
+ this.node.style.zIndex = "20";
1832
+ domUtils.setStyle(this.originLine, {
1833
+ position: "absolute",
1834
+ width: 1,
1835
+ height: "100%",
1836
+ left: this.pipelineNode.style.left,
1837
+ top: 0,
1838
+ borderLeft: "1px dashed rgba(255, 0, 0, 0.5)"
1839
+ });
1840
+ this.pipelineNode.parentElement.appendChild(this.originLine);
1841
+ this.node.appendChild(this.viewport);
1842
+ this.node.appendChild(this.versionNodes);
1843
+ this.node.appendChild(this.boundsNodes);
1844
+ this.node.appendChild(this.pointsNodes);
1845
+ this.renderScrollViewportBounds();
1846
+ }
1847
+ onScroll() {
1848
+ this.originLine.style.left = this.pipelineNode.style.left;
1849
+ this.renderScrollViewportBounds();
1850
+ }
1851
+ onResize() {
1852
+ this.renderScrollViewportBounds();
1853
+ }
1854
+ onZoom(scale) {
1855
+ this.node.style.transform = `scale(${scale})`;
1856
+ this.renderScrollViewportBounds();
1857
+ }
1858
+ createBounds(transform, color, depth) {
1859
+ if (this.filterKey && transform.key.indexOf(this.filterKey) === -1) return;
1860
+ let cache = this.domCache.get(transform);
1861
+ const { bounds, inputPoint, outputPoint } = transform;
1862
+ if (!cache) {
1863
+ const bbox = domUtils.createDivWithClass("");
1864
+ const input = domUtils.createDivWithClass("");
1865
+ const output = domUtils.createDivWithClass("");
1866
+ const version = domUtils.createDivWithClass("");
1867
+ bbox.title = transform.key;
1868
+ input.title = transform.key + "(input)";
1869
+ output.title = transform.key + "(output)";
1870
+ version.title = transform.key;
1871
+ this.boundsNodes.appendChild(bbox);
1872
+ this.pointsNodes.appendChild(input);
1873
+ this.pointsNodes.appendChild(output);
1874
+ this.versionNodes.appendChild(version);
1875
+ transform.onDispose(() => {
1876
+ bbox.remove();
1877
+ input.remove();
1878
+ output.remove();
1879
+ });
1880
+ cache = { bbox, input, output, version, color };
1881
+ this.domCache.set(transform, cache);
1882
+ }
1883
+ domUtils.setStyle(cache.version, {
1884
+ position: "absolute",
1885
+ marginLeft: "-9px",
1886
+ marginTop: "-10px",
1887
+ borderRadius: 12,
1888
+ background: "#f54a45",
1889
+ padding: 4,
1890
+ color: "navajowhite",
1891
+ display: transform.renderState.hidden ? "none" : "block",
1892
+ zIndex: depth + 1e3,
1893
+ left: bounds.center.x,
1894
+ top: bounds.center.y
1895
+ });
1896
+ cache.version.innerHTML = transform.version.toString();
1897
+ domUtils.setStyle(cache.input, {
1898
+ position: "absolute",
1899
+ width: 10,
1900
+ height: 10,
1901
+ marginLeft: -5,
1902
+ marginTop: -5,
1903
+ borderRadius: 5,
1904
+ left: inputPoint.x,
1905
+ top: inputPoint.y,
1906
+ opacity: 0.4,
1907
+ zIndex: depth,
1908
+ backgroundColor: cache.color,
1909
+ whiteSpace: "nowrap",
1910
+ overflow: "visible"
1911
+ });
1912
+ cache.input.innerHTML = `${inputPoint.x},${inputPoint.y}`;
1913
+ domUtils.setStyle(cache.output, {
1914
+ position: "absolute",
1915
+ width: 10,
1916
+ height: 10,
1917
+ marginLeft: -5,
1918
+ marginTop: -5,
1919
+ borderRadius: 5,
1920
+ left: outputPoint.x,
1921
+ top: outputPoint.y,
1922
+ opacity: 0.4,
1923
+ zIndex: depth,
1924
+ backgroundColor: cache.color,
1925
+ whiteSpace: "nowrap",
1926
+ overflow: "visible"
1927
+ });
1928
+ cache.output.innerHTML = `${outputPoint.x},${outputPoint.y}`;
1929
+ domUtils.setStyle(cache.bbox, {
1930
+ position: "absolute",
1931
+ width: bounds.width,
1932
+ height: bounds.height,
1933
+ left: bounds.left,
1934
+ top: bounds.top,
1935
+ opacity: `${depth / 30}`,
1936
+ backgroundColor: cache.color
1937
+ });
1938
+ }
1939
+ /**
1940
+ * 显示 viewport 可滚动区域
1941
+ */
1942
+ renderScrollViewportBounds() {
1943
+ const viewportBounds = getScrollViewport(
1944
+ {
1945
+ scrollX: this.config.config.scrollX,
1946
+ scrollY: this.config.config.scrollY
1947
+ },
1948
+ this.config
1949
+ );
1950
+ domUtils.setStyle(this.viewport, {
1951
+ position: "absolute",
1952
+ width: viewportBounds.width - 2,
1953
+ height: viewportBounds.height - 2,
1954
+ left: viewportBounds.left + 1,
1955
+ top: viewportBounds.top + 1,
1956
+ border: "1px solid rgba(200, 200, 255, 0.5)"
1957
+ });
1958
+ }
1959
+ autorun() {
1960
+ if (this.documentTransformer.loading) return;
1961
+ this.documentTransformer.refresh();
1962
+ let color = randomColor(0);
1963
+ this.document.traverse((entity, depth) => {
1964
+ const transform = entity.getData(FlowNodeTransformData);
1965
+ color = randomColor(depth);
1966
+ this.createBounds(transform, color, depth);
1967
+ });
1968
+ this.renderScrollViewportBounds();
1969
+ }
1970
+ };
1971
+ __decorateClass([
1972
+ inject(FlowDocument)
1973
+ ], FlowDebugLayer.prototype, "document", 2);
1974
+ __decorateClass([
1975
+ observeEntity(FlowDocumentTransformerEntity)
1976
+ ], FlowDebugLayer.prototype, "documentTransformer", 2);
1977
+ __decorateClass([
1978
+ observeEntityDatas(FlowNodeEntity, FlowNodeTransformData)
1979
+ ], FlowDebugLayer.prototype, "_transforms", 2);
1980
+ FlowDebugLayer = __decorateClass([
1981
+ injectable()
1982
+ ], FlowDebugLayer);
1983
+ var BORDER_WIDTH = 2;
1984
+ var BLOCK_OFFSET = 11;
1985
+ var SCROLL_BAR_WIDTH = "7px";
1986
+ var FlowScrollBarLayer = class extends Layer {
1987
+ constructor() {
1988
+ super(...arguments);
1989
+ // @observeEntity(FlowDocumentTransformerEntity) readonly documentTransformer: FlowDocumentTransformerEntity
1990
+ // 右滚动区域
1991
+ this.rightScrollBar = domUtils.createDivWithClass("gedit-playground-scroll-right");
1992
+ // 右滚动条
1993
+ this.rightScrollBarBlock = domUtils.createDivWithClass("gedit-playground-scroll-right-block");
1994
+ // 底滚动区域
1995
+ this.bottomScrollBar = domUtils.createDivWithClass("gedit-playground-scroll-bottom");
1996
+ // 底滚动条
1997
+ this.bottomScrollBarBlock = domUtils.createDivWithClass(
1998
+ "gedit-playground-scroll-bottom-block"
1999
+ );
2000
+ // 总滚动距离
2001
+ this.sum = 0;
2002
+ // 初始 x 轴滚动距离
2003
+ this.initialScrollX = 0;
2004
+ // 初始 y 轴滚动距离
2005
+ this.initialScrollY = 0;
2006
+ this.bottomGrabDragger = new PlaygroundDrag({
2007
+ onDragStart: (e) => {
2008
+ this.config.updateCursor("grabbing");
2009
+ this.sum = 0;
2010
+ this.initialScrollX = this.config.getViewport().x;
2011
+ this.onBoardingToast();
2012
+ },
2013
+ onDrag: (e) => {
2014
+ this.sum += e.movingDelta.x;
2015
+ this.playgroundConfigEntity.scroll(
2016
+ {
2017
+ scrollX: (this.initialScrollX + this.sum * this.viewportFullWidth / (this.clientViewportWidth - this.scrollBottomWidth)) * this.scale
2018
+ },
2019
+ false
2020
+ );
2021
+ },
2022
+ onDragEnd: (e) => {
2023
+ this.config.updateCursor("default");
2024
+ }
2025
+ });
2026
+ this.rightGrabDragger = new PlaygroundDrag({
2027
+ onDragStart: (e) => {
2028
+ this.config.updateCursor("grabbing");
2029
+ this.sum = 0;
2030
+ this.initialScrollY = this.config.getViewport().y;
2031
+ this.onBoardingToast();
2032
+ },
2033
+ onDrag: (e) => {
2034
+ this.sum += e.movingDelta.y;
2035
+ this.playgroundConfigEntity.scroll(
2036
+ {
2037
+ scrollY: (this.initialScrollY + this.sum * this.viewportFullHeight / (this.clientViewportHeight - this.scrollRightHeight)) * this.scale
2038
+ },
2039
+ false
2040
+ );
2041
+ },
2042
+ onDragEnd: (e) => {
2043
+ this.config.updateCursor("default");
2044
+ }
2045
+ });
2046
+ }
2047
+ // 浏览器视图宽度
2048
+ get clientViewportWidth() {
2049
+ return this.viewportWidth * this.scale - BLOCK_OFFSET;
2050
+ }
2051
+ // 浏览器视图高度
2052
+ get clientViewportHeight() {
2053
+ return this.viewportHeight * this.scale - BLOCK_OFFSET;
2054
+ }
2055
+ // 视图的完整宽度
2056
+ get viewportFullWidth() {
2057
+ return this.mostLeft - this.mostRight;
2058
+ }
2059
+ // 视图的完整高度
2060
+ get viewportFullHeight() {
2061
+ return this.mostTop - this.mostBottom;
2062
+ }
2063
+ // 视图的可移动宽度
2064
+ get viewportMoveWidth() {
2065
+ return this.mostLeft - this.mostRight + this.width;
2066
+ }
2067
+ // 视图的可移动高度
2068
+ get viewportMoveHeight() {
2069
+ return this.mostTop - this.mostBottom + this.height;
2070
+ }
2071
+ getToLeft(scrollX) {
2072
+ return (scrollX - this.mostRight) / this.viewportMoveWidth * this.clientViewportWidth;
2073
+ }
2074
+ getToTop(scrollY) {
2075
+ return (scrollY - this.mostBottom) / this.viewportMoveHeight * this.clientViewportHeight;
2076
+ }
2077
+ clickRightScrollBar(e) {
2078
+ e.preventDefault();
2079
+ e.stopPropagation();
2080
+ const ratio = 1 - (e?.y || 0) / this.clientViewportHeight;
2081
+ const scrollY = (this.mostTop - this.viewportFullHeight * ratio) * this.scale;
2082
+ this.playgroundConfigEntity.scroll(
2083
+ {
2084
+ scrollY
2085
+ },
2086
+ false
2087
+ );
2088
+ }
2089
+ clickBottomScrollBar(e) {
2090
+ e.preventDefault();
2091
+ e.stopPropagation();
2092
+ const ratio = 1 - (e?.x || 0) / this.clientViewportWidth;
2093
+ const scrollX = (this.mostLeft - this.viewportFullWidth * ratio) * this.scale;
2094
+ this.playgroundConfigEntity.scroll(
2095
+ {
2096
+ scrollX
2097
+ },
2098
+ false
2099
+ );
2100
+ }
2101
+ onBoardingToast() {
2102
+ this.events?.dragStart();
2103
+ }
2104
+ changeScrollBarVisibility(scrollBar, status) {
2105
+ const addClassName = status === "show" /* Show */ ? "gedit-playground-scroll-show" : "gedit-playground-scroll-hidden";
2106
+ const delClassName = status === "show" /* Show */ ? "gedit-playground-scroll-hidden" : "gedit-playground-scroll-show";
2107
+ domUtils.addClass(scrollBar, addClassName);
2108
+ domUtils.delClass(scrollBar, delClassName);
2109
+ }
2110
+ onReady() {
2111
+ if (!this.options.getBounds) {
2112
+ this.options = {
2113
+ getBounds: () => {
2114
+ const document2 = this.flowDocument;
2115
+ if (!document2) return Rectangle.EMPTY;
2116
+ document2.transformer.refresh();
2117
+ return document2.root.getData(FlowNodeTransformData).bounds;
2118
+ },
2119
+ showScrollBars: "whenScrolling"
2120
+ };
2121
+ }
2122
+ this.pipelineNode.parentNode.appendChild(this.rightScrollBar);
2123
+ this.pipelineNode.parentNode.appendChild(this.rightScrollBarBlock);
2124
+ this.pipelineNode.parentNode.appendChild(this.bottomScrollBar);
2125
+ this.pipelineNode.parentNode.appendChild(this.bottomScrollBarBlock);
2126
+ this.rightScrollBar.onclick = this.clickRightScrollBar.bind(this);
2127
+ this.bottomScrollBar.onclick = this.clickBottomScrollBar.bind(this);
2128
+ if (this.options.showScrollBars === "whenScrolling") {
2129
+ this.rightScrollBar.addEventListener("mouseenter", (e) => {
2130
+ this.changeScrollBarVisibility(this.rightScrollBarBlock, "show" /* Show */);
2131
+ });
2132
+ this.rightScrollBar.addEventListener("mouseleave", (e) => {
2133
+ this.changeScrollBarVisibility(this.rightScrollBarBlock, "hidden" /* Hidden */);
2134
+ });
2135
+ this.bottomScrollBar.addEventListener("mouseenter", (e) => {
2136
+ this.changeScrollBarVisibility(this.bottomScrollBarBlock, "show" /* Show */);
2137
+ });
2138
+ this.bottomScrollBar.addEventListener("mouseleave", (e) => {
2139
+ this.changeScrollBarVisibility(this.bottomScrollBarBlock, "hidden" /* Hidden */);
2140
+ });
2141
+ }
2142
+ this.bottomScrollBarBlock.addEventListener("mousedown", (e) => {
2143
+ this.bottomGrabDragger.start(e.clientX, e.clientY);
2144
+ e.stopPropagation();
2145
+ });
2146
+ this.rightScrollBarBlock.addEventListener("mousedown", (e) => {
2147
+ this.rightGrabDragger.start(e.clientX, e.clientY);
2148
+ e.stopPropagation();
2149
+ });
2150
+ }
2151
+ autorun() {
2152
+ if (this.hideTimeout) {
2153
+ clearTimeout(this.hideTimeout);
2154
+ }
2155
+ const viewportBounds = getScrollViewport(
2156
+ {
2157
+ scrollX: this.config.config.scrollX,
2158
+ scrollY: this.config.config.scrollY
2159
+ },
2160
+ this.config
2161
+ );
2162
+ const viewport = this.config.getViewport();
2163
+ this.viewportWidth = viewport.width;
2164
+ this.viewportHeight = viewport.height;
2165
+ const rootBounds = this.options.getBounds();
2166
+ this.width = rootBounds?.width || 0;
2167
+ this.height = rootBounds?.height || 0;
2168
+ const paddingLeftRight = (this.viewportWidth - viewportBounds.width) / 2 - BORDER_WIDTH;
2169
+ const paddingTopBottom = (this.viewportHeight - viewportBounds.height) / 2 - BORDER_WIDTH;
2170
+ const canvasTotalWidth = this.width + viewportBounds.width;
2171
+ const canvasTotalHeight = this.height + viewportBounds.height;
2172
+ const initialOffsetX = rootBounds.x;
2173
+ const initialOffsetY = rootBounds.y;
2174
+ this.mostLeft = this.width + initialOffsetX - paddingLeftRight;
2175
+ this.mostRight = this.mostLeft - canvasTotalWidth;
2176
+ this.mostTop = this.height + initialOffsetY - paddingTopBottom;
2177
+ this.mostBottom = this.mostTop - canvasTotalHeight;
2178
+ this.scale = this.config.finalScale;
2179
+ const calcViewportWidth = this.clientViewportWidth;
2180
+ const calcViewportHeight = this.clientViewportHeight;
2181
+ this.scrollBottomWidth = calcViewportWidth - calcViewportWidth * (this.mostLeft - this.mostRight) / this.viewportMoveWidth;
2182
+ this.scrollRightHeight = calcViewportHeight - calcViewportHeight * (this.mostTop - this.mostBottom) / this.viewportMoveHeight;
2183
+ const bottomBarToLeft = this.getToLeft(viewport.x);
2184
+ const rightBarToTop = this.getToTop(viewport.y);
2185
+ domUtils.setStyle(this.rightScrollBarBlock, {
2186
+ right: 2,
2187
+ top: rightBarToTop,
2188
+ background: "#1F2329",
2189
+ zIndex: 10,
2190
+ height: this.scrollRightHeight,
2191
+ width: SCROLL_BAR_WIDTH
2192
+ });
2193
+ domUtils.setStyle(this.bottomScrollBarBlock, {
2194
+ left: bottomBarToLeft,
2195
+ bottom: 2,
2196
+ background: "#1F2329",
2197
+ zIndex: 10,
2198
+ height: SCROLL_BAR_WIDTH,
2199
+ width: this.scrollBottomWidth
2200
+ });
2201
+ this.changeScrollBarVisibility(this.rightScrollBarBlock, "show" /* Show */);
2202
+ this.changeScrollBarVisibility(this.bottomScrollBarBlock, "show" /* Show */);
2203
+ if (this.options.showScrollBars === "whenScrolling") {
2204
+ this.hideTimeout = window.setTimeout(() => {
2205
+ this.changeScrollBarVisibility(this.rightScrollBarBlock, "hidden" /* Hidden */);
2206
+ this.changeScrollBarVisibility(this.bottomScrollBarBlock, "hidden" /* Hidden */);
2207
+ this.hideTimeout = void 0;
2208
+ }, 1e3);
2209
+ }
2210
+ }
2211
+ };
2212
+ __decorateClass([
2213
+ optional(),
2214
+ inject(ScrollBarEvents)
2215
+ ], FlowScrollBarLayer.prototype, "events", 2);
2216
+ __decorateClass([
2217
+ inject(FlowDocument),
2218
+ optional()
2219
+ ], FlowScrollBarLayer.prototype, "flowDocument", 2);
2220
+ __decorateClass([
2221
+ observeEntity(PlaygroundConfigEntity)
2222
+ ], FlowScrollBarLayer.prototype, "playgroundConfigEntity", 2);
2223
+ FlowScrollBarLayer = __decorateClass([
2224
+ injectable()
2225
+ ], FlowScrollBarLayer);
2226
+ var DRAG_OFFSET = 10;
2227
+ var DEFAULT_DRAG_OFFSET_X = 8;
2228
+ var DEFAULT_DRAG_OFFSET_Y = 8;
2229
+ var FlowDragLayer = class extends Layer {
2230
+ constructor() {
2231
+ super(...arguments);
2232
+ this.disableDragScroll = false;
2233
+ this.dragOffset = {
2234
+ x: DEFAULT_DRAG_OFFSET_X,
2235
+ y: DEFAULT_DRAG_OFFSET_Y
2236
+ };
2237
+ this.containerRef = { current: null };
2238
+ this.draggingNodeMask = document.createElement("div");
2239
+ this._dragger = new PlaygroundDrag({
2240
+ onDrag: (e) => {
2241
+ this.handleMouseMove(e);
2242
+ },
2243
+ onDragEnd: () => {
2244
+ this.handleMouseUp();
2245
+ },
2246
+ stopGlobalEventNames: ["contextmenu"]
2247
+ });
2248
+ }
2249
+ get transitions() {
2250
+ const result = [];
2251
+ this.document.traverse((entity) => {
2252
+ result.push(entity.getData(FlowNodeTransitionData));
2253
+ });
2254
+ return result;
2255
+ }
2256
+ get dragStartEntity() {
2257
+ return this.flowRenderStateEntity.getDragStartEntity();
2258
+ }
2259
+ set dragStartEntity(entity) {
2260
+ this.flowRenderStateEntity.setDragStartEntity(entity);
2261
+ }
2262
+ get dragEntities() {
2263
+ return this.flowRenderStateEntity.getDragEntities();
2264
+ }
2265
+ set dragEntities(entities) {
2266
+ this.flowRenderStateEntity.setDragEntities(entities);
2267
+ }
2268
+ isGrab() {
2269
+ const currentState = this.editorStateConfig.getCurrentState();
2270
+ return currentState === EditorState.STATE_GRAB;
2271
+ }
2272
+ setDraggingStatus(status) {
2273
+ if (this.flowDragService.nodeDragIdsWithChildren.length) {
2274
+ this.flowDragService.nodeDragIdsWithChildren.forEach((_id) => {
2275
+ const node = this.entityManager.getEntityById(_id);
2276
+ const data = node?.getData(FlowNodeRenderData);
2277
+ data.dragging = status;
2278
+ });
2279
+ }
2280
+ this.flowRenderStateEntity.setDragging(status);
2281
+ }
2282
+ dragEnable(e) {
2283
+ return Math.abs(e.clientX - this.initialPosition.x) > DRAG_OFFSET || Math.abs(e.clientY - this.initialPosition.y) > DRAG_OFFSET;
2284
+ }
2285
+ handleMouseMove(event) {
2286
+ if ((this.dragJSON || this.dragStartEntity) && this.dragEnable(event)) {
2287
+ this.setDraggingStatus(true);
2288
+ const scale = this.playgroundConfigEntity.finalScale;
2289
+ if (this.containerRef.current) {
2290
+ const dragNode = this.containerRef.current.children?.[0];
2291
+ if (!dragNode) {
2292
+ return;
2293
+ }
2294
+ const clientBounds = this.playgroundConfigEntity.getClientBounds();
2295
+ const dragBlockX = event.clientX - (this.pipelineNode.offsetLeft || 0) - clientBounds.x - (dragNode.clientWidth - this.dragOffset.x) * scale;
2296
+ const dragBlockY = event.clientY - (this.pipelineNode.offsetTop || 0) - clientBounds.y - (dragNode.clientHeight - this.dragOffset.y) * scale;
2297
+ const isBranch = this.flowDragService.isDragBranch;
2298
+ const draggingRect = new Rectangle(
2299
+ dragBlockX,
2300
+ dragBlockY,
2301
+ dragNode.clientWidth * scale,
2302
+ dragNode.clientHeight * scale
2303
+ );
2304
+ let side;
2305
+ const collisionTransition = this.transitions.find((transition) => {
2306
+ if (transition?.entity?.parent?.collapsed) {
2307
+ return false;
2308
+ }
2309
+ const { hasCollision, labelOffsetType } = this.flowDragConfigEntity.isCollision(
2310
+ transition,
2311
+ draggingRect,
2312
+ isBranch
2313
+ );
2314
+ side = labelOffsetType;
2315
+ return hasCollision;
2316
+ });
2317
+ if (collisionTransition && (isBranch ? this.flowDragService.isDroppableBranch(collisionTransition.entity, side) : this.flowDragService.isDroppableNode(collisionTransition.entity)) && (!this.options.canDrop || this.options.canDrop({
2318
+ dragNodes: this.dragEntities,
2319
+ dropNode: collisionTransition.entity,
2320
+ isBranch
2321
+ }))) {
2322
+ this.flowRenderStateEntity.setNodeDroppingId(collisionTransition.entity.id);
2323
+ } else {
2324
+ this.flowRenderStateEntity.setNodeDroppingId("");
2325
+ }
2326
+ this.flowRenderStateEntity.setDragLabelSide(side);
2327
+ this.containerRef.current.style.visibility = "visible";
2328
+ this.pipelineNode.parentElement.appendChild(this.draggingNodeMask);
2329
+ this.containerRef.current.style.left = `${dragBlockX + this.pipelineNode.offsetLeft + clientBounds.x + window.scrollX}px`;
2330
+ this.containerRef.current.style.top = `${dragBlockY + this.pipelineNode.offsetTop + clientBounds.y + window.scrollY}px`;
2331
+ this.containerRef.current.style.transformOrigin = "top left";
2332
+ this.containerRef.current.style.transform = `scale(${scale})`;
2333
+ if (!this.disableDragScroll) {
2334
+ this.flowDragConfigEntity.scrollDirection(event, dragBlockX, dragBlockY);
2335
+ }
2336
+ }
2337
+ }
2338
+ }
2339
+ async handleMouseUp() {
2340
+ this.setDraggingStatus(false);
2341
+ if (this.dragStartEntity || this.dragJSON) {
2342
+ const activatedNodeId = this.flowDragService.dropNodeId;
2343
+ if (activatedNodeId) {
2344
+ if (this.flowDragService.isDragBranch) {
2345
+ if (this.dragJSON) {
2346
+ await this.flowDragService.dropCreateNode(this.dragJSON, this.onCreateNode);
2347
+ } else {
2348
+ this.flowDragService.dropBranch();
2349
+ }
2350
+ } else {
2351
+ if (this.dragJSON) {
2352
+ await this.flowDragService.dropCreateNode(this.dragJSON, this.onCreateNode);
2353
+ } else {
2354
+ this.flowDragService.dropNode();
2355
+ }
2356
+ this.selectConfigEntity.clearSelectedNodes();
2357
+ }
2358
+ }
2359
+ this.flowRenderStateEntity.setNodeDroppingId("");
2360
+ this.flowRenderStateEntity.setDragLabelSide();
2361
+ this.flowRenderStateEntity.setIsBranch(false);
2362
+ this.dragStartEntity = void 0;
2363
+ this.dragEntities = [];
2364
+ this.flowDragConfigEntity.stopAllScroll();
2365
+ }
2366
+ this.disableDragScroll = false;
2367
+ this.dragJSON = void 0;
2368
+ if (this.containerRef.current) {
2369
+ this.containerRef.current.style.visibility = "hidden";
2370
+ if (this.pipelineNode.parentElement.contains(this.draggingNodeMask)) {
2371
+ this.pipelineNode.parentElement.removeChild(this.draggingNodeMask);
2372
+ }
2373
+ }
2374
+ }
2375
+ /**
2376
+ * 开始拖拽事件
2377
+ * @param e
2378
+ */
2379
+ async startDrag(e, {
2380
+ dragStartEntity: startEntityFromProps,
2381
+ dragEntities,
2382
+ dragJSON,
2383
+ isBranch,
2384
+ onCreateNode
2385
+ }, options) {
2386
+ if (this.isGrab() || this.config.disabled || this.config.readonly) {
2387
+ return;
2388
+ }
2389
+ this.disableDragScroll = Boolean(options?.disableDragScroll);
2390
+ this.dragJSON = dragJSON;
2391
+ this.onCreateNode = onCreateNode;
2392
+ this.flowRenderStateEntity.setIsBranch(Boolean(isBranch));
2393
+ this.dragOffset.x = options?.dragOffsetX || DEFAULT_DRAG_OFFSET_X;
2394
+ this.dragOffset.y = options?.dragOffsetY || DEFAULT_DRAG_OFFSET_Y;
2395
+ const type = startEntityFromProps?.flowNodeType || dragJSON?.type;
2396
+ const isIcon = type === FlowNodeBaseType.BLOCK_ICON;
2397
+ const isOrderIcon = type === FlowNodeBaseType.BLOCK_ORDER_ICON;
2398
+ const dragStartEntity = isIcon || isOrderIcon ? startEntityFromProps.parent : startEntityFromProps;
2399
+ if (dragStartEntity && !dragStartEntity.getData(FlowNodeRenderData).draggable) {
2400
+ return;
2401
+ }
2402
+ this.initialPosition = {
2403
+ x: e.clientX,
2404
+ y: e.clientY
2405
+ };
2406
+ this.dragStartEntity = dragStartEntity;
2407
+ this.dragEntities = dragEntities || (this.dragStartEntity ? [this.dragStartEntity] : []);
2408
+ return this._dragger.start(e.clientX, e.clientY);
2409
+ }
2410
+ onReady() {
2411
+ this.draggingNodeMask.style.width = "100%";
2412
+ this.draggingNodeMask.style.height = "100%";
2413
+ this.draggingNodeMask.style.position = "absolute";
2414
+ this.draggingNodeMask.classList.add("dragging-node");
2415
+ this.draggingNodeMask.style.zIndex = "99";
2416
+ this.draggingNodeMask.style.cursor = "pointer";
2417
+ this.dragNodeComp = this.rendererRegistry.getRendererComponent("drag-node" /* DRAG_NODE */);
2418
+ if (this.options.onDrop) {
2419
+ this.toDispose.push(this.flowDragService.onDrop(this.options.onDrop));
2420
+ }
2421
+ }
2422
+ dispose() {
2423
+ this._dragger.dispose();
2424
+ super.dispose();
2425
+ }
2426
+ render() {
2427
+ const DragComp = this.dragNodeComp?.renderer;
2428
+ return wrapLayerRender(
2429
+ this.playgroundContainer,
2430
+ h(Teleport, { to: "body" }, [
2431
+ h(
2432
+ "div",
2433
+ {
2434
+ ref: (el) => {
2435
+ this.containerRef.current = el || null;
2436
+ },
2437
+ style: { position: "absolute", zIndex: 99999, visibility: "hidden" },
2438
+ onMouseenter: (e) => e.stopPropagation()
2439
+ },
2440
+ [
2441
+ DragComp ? h(DragComp, {
2442
+ dragJSON: this.dragJSON,
2443
+ dragStart: this.dragStartEntity,
2444
+ dragNodes: this.dragEntities
2445
+ }) : null
2446
+ ]
2447
+ )
2448
+ ])
2449
+ );
2450
+ }
2451
+ };
2452
+ __decorateClass([
2453
+ inject(FlowDocument)
2454
+ ], FlowDragLayer.prototype, "document", 2);
2455
+ __decorateClass([
2456
+ inject(FlowDragService)
2457
+ ], FlowDragLayer.prototype, "flowDragService", 2);
2458
+ __decorateClass([
2459
+ inject(PlaygroundContainerFactory)
2460
+ ], FlowDragLayer.prototype, "playgroundContainer", 2);
2461
+ __decorateClass([
2462
+ observeEntityDatas(FlowNodeEntity, FlowNodeTransformData)
2463
+ ], FlowDragLayer.prototype, "transforms", 2);
2464
+ __decorateClass([
2465
+ observeEntity(EditorStateConfigEntity)
2466
+ ], FlowDragLayer.prototype, "editorStateConfig", 2);
2467
+ __decorateClass([
2468
+ observeEntity(PlaygroundConfigEntity)
2469
+ ], FlowDragLayer.prototype, "playgroundConfigEntity", 2);
2470
+ __decorateClass([
2471
+ observeEntity(FlowDragEntity)
2472
+ ], FlowDragLayer.prototype, "flowDragConfigEntity", 2);
2473
+ __decorateClass([
2474
+ observeEntity(FlowRendererStateEntity)
2475
+ ], FlowDragLayer.prototype, "flowRenderStateEntity", 2);
2476
+ __decorateClass([
2477
+ observeEntity(FlowSelectConfigEntity)
2478
+ ], FlowDragLayer.prototype, "selectConfigEntity", 2);
2479
+ __decorateClass([
2480
+ inject(FlowRendererRegistry)
2481
+ ], FlowDragLayer.prototype, "rendererRegistry", 2);
2482
+ FlowDragLayer = __decorateClass([
2483
+ injectable()
2484
+ ], FlowDragLayer);
2485
+ var FlowSelectorBoxLayer = class extends Layer {
2486
+ constructor() {
2487
+ super(...arguments);
2488
+ this.node = domUtils.createDivWithClass("gedit-selector-box-layer");
2489
+ /**
2490
+ * 选择框
2491
+ */
2492
+ this.selectorBox = this.createDOMCache("gedit-selector-box");
2493
+ /**
2494
+ * 用于遮挡鼠标,避免触发 hover
2495
+ */
2496
+ this.selectorBoxBlock = this.createDOMCache("gedit-selector-box-block");
2497
+ /**
2498
+ * 拖动选择框
2499
+ */
2500
+ this.selectboxDragger = new PlaygroundDrag({
2501
+ onDragStart: (e) => {
2502
+ this.selectConfigEntity.clearSelectedNodes();
2503
+ const mousePos = this.playgroundConfigEntity.getPosFromMouseEvent(e);
2504
+ this.transformVisibles = this.flowDocument.getRenderDatas(FlowNodeTransformData, false).filter((transform) => {
2505
+ const { entity } = transform;
2506
+ if (entity.originParent) {
2507
+ return this.nodeSelectable(entity, mousePos) && this.nodeSelectable(entity.originParent, mousePos);
2508
+ }
2509
+ return this.nodeSelectable(entity, mousePos);
2510
+ });
2511
+ this.selectorBoxConfigEntity.setDragInfo(e);
2512
+ this.updateSelectorBox(this.selectorBoxConfigEntity);
2513
+ },
2514
+ onDrag: (e) => {
2515
+ this.selectorBoxConfigEntity.setDragInfo(e);
2516
+ this.selectConfigEntity.selectFromBounds(
2517
+ this.selectorBoxConfigEntity.toRectangle(this.playgroundConfigEntity.finalScale),
2518
+ this.transformVisibles
2519
+ );
2520
+ this.updateSelectorBox(this.selectorBoxConfigEntity);
2521
+ },
2522
+ onDragEnd: (e) => {
2523
+ this.selectorBoxConfigEntity.setDragInfo(e);
2524
+ this.transformVisibles.length = 0;
2525
+ this.updateSelectorBox(this.selectorBoxConfigEntity);
2526
+ }
2527
+ });
2528
+ }
2529
+ onReady() {
2530
+ if (!this.options.canSelect) {
2531
+ this.options.canSelect = (e) => {
2532
+ const target = e.target;
2533
+ return target === this.pipelineNode || target === this.playgroundNode;
2534
+ };
2535
+ }
2536
+ this.toDispose.pushAll([
2537
+ this.selectConfigEntity.onConfigChanged(() => {
2538
+ this.selectionService.selection = this.selectConfigEntity.selectedNodes;
2539
+ }),
2540
+ this.selectionService.onSelectionChanged(() => {
2541
+ const selectedNodes = this.selectionService.selection.filter(
2542
+ (entity) => entity instanceof FlowNodeEntity
2543
+ );
2544
+ this.selectConfigEntity.selectedNodes = selectedNodes;
2545
+ })
2546
+ ]);
2547
+ this.listenPlaygroundEvent(
2548
+ "mousedown",
2549
+ (e) => {
2550
+ if (!this.isEnabled()) return;
2551
+ if (this.options.canSelect && !this.options.canSelect(e, this.selectorBoxConfigEntity)) {
2552
+ return;
2553
+ }
2554
+ const currentState = this.editorStateConfig.getCurrentState();
2555
+ if (currentState === EditorState.STATE_MOUSE_FRIENDLY_SELECT) {
2556
+ this.selectConfigEntity.clearSelectedNodes();
2557
+ }
2558
+ this.selectboxDragger.start(e.clientX, e.clientY, this.config);
2559
+ return true;
2560
+ },
2561
+ PipelineLayerPriority.BASE_LAYER
2562
+ );
2563
+ }
2564
+ isEnabled() {
2565
+ const currentState = this.editorStateConfig.getCurrentState();
2566
+ const isMouseFriendly = currentState === EditorState.STATE_MOUSE_FRIENDLY_SELECT;
2567
+ return !this.config.disabled && !this.config.readonly && // 鼠标友好模式下,需要按下 shift 启动框选
2568
+ (isMouseFriendly && this.editorStateConfig.isPressingShift || currentState === EditorState.STATE_SELECT) && !this.selectorBoxConfigEntity.disabled;
2569
+ }
2570
+ /**
2571
+ * Destroy
2572
+ */
2573
+ dispose() {
2574
+ this.selectorBox.dispose();
2575
+ this.selectorBoxBlock.dispose();
2576
+ super.dispose();
2577
+ }
2578
+ updateSelectorBox(selector) {
2579
+ const node = this.selectorBox.get();
2580
+ const block = this.selectorBoxBlock.get();
2581
+ if (!this.isEnabled() && selector.isMoving) {
2582
+ this.selectorBoxConfigEntity.collapse();
2583
+ }
2584
+ if (!this.isEnabled() || !selector.isMoving) {
2585
+ node.setStyle({
2586
+ display: "none"
2587
+ });
2588
+ block.setStyle({
2589
+ display: "none"
2590
+ });
2591
+ } else {
2592
+ node.setStyle({
2593
+ display: "block",
2594
+ left: selector.position.x,
2595
+ top: selector.position.y,
2596
+ width: selector.size.width,
2597
+ height: selector.size.height
2598
+ });
2599
+ block.setStyle({
2600
+ display: "block",
2601
+ left: selector.position.x - 10,
2602
+ top: selector.position.y - 10,
2603
+ width: selector.size.width + 20,
2604
+ height: selector.size.height + 20
2605
+ });
2606
+ }
2607
+ }
2608
+ nodeSelectable(node, mousePos) {
2609
+ const selectable = node.getNodeMeta().selectable;
2610
+ if (typeof selectable === "function") {
2611
+ return selectable(node, mousePos);
2612
+ } else {
2613
+ return selectable;
2614
+ }
2615
+ }
2616
+ // autorun(): void {
2617
+ // this.updateSelectorBox(this.selectorBoxConfigEntity);
2618
+ // }
2619
+ };
2620
+ __decorateClass([
2621
+ inject(FlowDocument)
2622
+ ], FlowSelectorBoxLayer.prototype, "flowDocument", 2);
2623
+ __decorateClass([
2624
+ inject(ContextMenuService)
2625
+ ], FlowSelectorBoxLayer.prototype, "contextMenuService", 2);
2626
+ __decorateClass([
2627
+ observeEntity(PlaygroundConfigEntity)
2628
+ ], FlowSelectorBoxLayer.prototype, "playgroundConfigEntity", 2);
2629
+ __decorateClass([
2630
+ inject(SelectionService)
2631
+ ], FlowSelectorBoxLayer.prototype, "selectionService", 2);
2632
+ __decorateClass([
2633
+ observeEntity(SelectorBoxConfigEntity)
2634
+ ], FlowSelectorBoxLayer.prototype, "selectorBoxConfigEntity", 2);
2635
+ __decorateClass([
2636
+ observeEntity(FlowSelectConfigEntity)
2637
+ ], FlowSelectorBoxLayer.prototype, "selectConfigEntity", 2);
2638
+ __decorateClass([
2639
+ observeEntity(EditorStateConfigEntity)
2640
+ ], FlowSelectorBoxLayer.prototype, "editorStateConfig", 2);
2641
+ FlowSelectorBoxLayer = __decorateClass([
2642
+ injectable()
2643
+ ], FlowSelectorBoxLayer);
2644
+ var FlowSelectorBoundsLayer = class extends Layer {
2645
+ constructor() {
2646
+ super(...arguments);
2647
+ this.node = domUtils.createDivWithClass("gedit-selector-bounds-layer");
2648
+ this.selectBoundsBackground = domUtils.createDivWithClass("gedit-selector-bounds-background");
2649
+ }
2650
+ onReady() {
2651
+ this.node.style.zIndex = "20";
2652
+ const { firstChild } = this.pipelineNode;
2653
+ if (this.options.boundsPadding !== void 0) {
2654
+ this.flowSelectConfigEntity.boundsPadding = this.options.boundsPadding;
2655
+ }
2656
+ if (this.options.backgroundClassName) {
2657
+ this.selectBoundsBackground.classList.add(this.options.backgroundClassName);
2658
+ }
2659
+ const selectorBoundsLayer = domUtils.createDivWithClass(
2660
+ "gedit-selector-bounds-background-layer gedit-playground-layer"
2661
+ );
2662
+ selectorBoundsLayer.appendChild(this.selectBoundsBackground);
2663
+ this.pipelineNode.insertBefore(selectorBoundsLayer, firstChild);
2664
+ }
2665
+ onZoom(scale) {
2666
+ this.node.style.transform = `scale(${scale})`;
2667
+ this.selectBoundsBackground.parentElement.style.transform = `scale(${scale})`;
2668
+ }
2669
+ onViewportChange() {
2670
+ this.render();
2671
+ }
2672
+ isEnabled() {
2673
+ const currentState = this.editorStateConfig.getCurrentState();
2674
+ return currentState === EditorState.STATE_SELECT;
2675
+ }
2676
+ render() {
2677
+ const {
2678
+ ignoreOneSelect,
2679
+ ignoreChildrenLength,
2680
+ SelectorBoxPopover: SelectorBoxPopoverFromOpts,
2681
+ disableBackground,
2682
+ CustomBoundsRenderer
2683
+ } = this.options;
2684
+ const bounds = this.flowSelectConfigEntity.getSelectedBounds();
2685
+ const selectedNodes = this.flowSelectConfigEntity.selectedNodes;
2686
+ const bg = this.selectBoundsBackground;
2687
+ const isDragging = !this.selectorBoxConfigEntity.isStart;
2688
+ if (bounds.width === 0 || bounds.height === 0 || ignoreOneSelect && selectedNodes.length === 1 && (ignoreChildrenLength || selectedNodes[0].childrenLength <= 1)) {
2689
+ domUtils.setStyle(bg, {
2690
+ display: "none"
2691
+ });
2692
+ return null;
2693
+ }
2694
+ if (CustomBoundsRenderer) {
2695
+ return wrapLayerRender(
2696
+ this.playgroundContainer,
2697
+ h(CustomBoundsRenderer, {
2698
+ bounds,
2699
+ config: this.config,
2700
+ flowSelectConfig: this.flowSelectConfigEntity,
2701
+ commandRegistry: this.commandRegistry
2702
+ })
2703
+ );
2704
+ }
2705
+ const style = {
2706
+ display: "block",
2707
+ left: `${bounds.left}px`,
2708
+ top: `${bounds.top}px`,
2709
+ width: `${bounds.width}px`,
2710
+ height: `${bounds.height}px`
2711
+ };
2712
+ if (!disableBackground) {
2713
+ domUtils.setStyle(bg, {
2714
+ display: "block",
2715
+ left: bounds.left,
2716
+ top: bounds.top,
2717
+ width: bounds.width,
2718
+ height: bounds.height
2719
+ });
2720
+ }
2721
+ let foregroundClassName = "gedit-selector-bounds-foreground";
2722
+ if (this.options.foregroundClassName) {
2723
+ foregroundClassName += ` ${this.options.foregroundClassName}`;
2724
+ }
2725
+ const SelectorBoxPopover = SelectorBoxPopoverFromOpts || this.rendererRegistry.tryToGetRendererComponent("selector-box-popover" /* SELECTOR_BOX_POPOVER */)?.renderer;
2726
+ if (!isDragging || !SelectorBoxPopover) {
2727
+ return wrapLayerRender(
2728
+ this.playgroundContainer,
2729
+ h("div", { class: foregroundClassName, style })
2730
+ );
2731
+ }
2732
+ return wrapLayerRender(
2733
+ this.playgroundContainer,
2734
+ h(
2735
+ SelectorBoxPopover,
2736
+ {
2737
+ bounds,
2738
+ config: this.config,
2739
+ flowSelectConfig: this.flowSelectConfigEntity,
2740
+ commandRegistry: this.commandRegistry
2741
+ },
2742
+ () => h("div", { class: foregroundClassName, style })
2743
+ )
2744
+ );
2745
+ }
2746
+ };
2747
+ __decorateClass([
2748
+ inject(FlowRendererRegistry)
2749
+ ], FlowSelectorBoundsLayer.prototype, "rendererRegistry", 2);
2750
+ __decorateClass([
2751
+ inject(CommandRegistry)
2752
+ ], FlowSelectorBoundsLayer.prototype, "commandRegistry", 2);
2753
+ __decorateClass([
2754
+ inject(PlaygroundContainerFactory)
2755
+ ], FlowSelectorBoundsLayer.prototype, "playgroundContainer", 2);
2756
+ __decorateClass([
2757
+ observeEntity(FlowSelectConfigEntity)
2758
+ ], FlowSelectorBoundsLayer.prototype, "flowSelectConfigEntity", 2);
2759
+ __decorateClass([
2760
+ observeEntity(EditorStateConfigEntity)
2761
+ ], FlowSelectorBoundsLayer.prototype, "editorStateConfig", 2);
2762
+ __decorateClass([
2763
+ observeEntity(SelectorBoxConfigEntity)
2764
+ ], FlowSelectorBoundsLayer.prototype, "selectorBoxConfigEntity", 2);
2765
+ __decorateClass([
2766
+ observeEntityDatas(FlowNodeEntity, FlowNodeRenderData)
2767
+ ], FlowSelectorBoundsLayer.prototype, "renderStates", 2);
2768
+ __decorateClass([
2769
+ observeEntityDatas(FlowNodeEntity, FlowNodeTransformData)
2770
+ ], FlowSelectorBoundsLayer.prototype, "_transforms", 2);
2771
+ FlowSelectorBoundsLayer = __decorateClass([
2772
+ injectable()
2773
+ ], FlowSelectorBoundsLayer);
2774
+ var FlowContextMenuLayer = class extends Layer {
2775
+ constructor() {
2776
+ super(...arguments);
2777
+ this.node = domUtils.createDivWithClass("gedit-context-menu-layer");
2778
+ this.nodeRef = { current: null };
2779
+ }
2780
+ isEnabled() {
2781
+ const currentState = this.editorStateConfig.getCurrentState();
2782
+ return !this.config.disabled && !this.config.readonly && currentState === EditorState.STATE_SELECT && !this.selectorBoxConfigEntity.disabled;
2783
+ }
2784
+ onReady() {
2785
+ this.node.style.zIndex = "30";
2786
+ this.node.style.display = "block";
2787
+ this.toDispose.pushAll([
2788
+ this.listenPlaygroundEvent(
2789
+ "contextmenu",
2790
+ (e) => {
2791
+ if (!this.isEnabled()) return;
2792
+ this.contextMenuService.rightPanelVisible = true;
2793
+ const bounds = this.flowSelectConfigEntity.getSelectedBounds();
2794
+ if (bounds.width === 0 || bounds.height === 0) {
2795
+ return;
2796
+ }
2797
+ e.stopPropagation();
2798
+ e.preventDefault();
2799
+ this.nodeRef.current?.setVisible(true);
2800
+ const clientBounds = this.playgroundConfigEntity.getClientBounds();
2801
+ const dragBlockX = e.clientX - (this.pipelineNode.offsetLeft || 0) - clientBounds.x;
2802
+ const dragBlockY = e.clientY - (this.pipelineNode.offsetTop || 0) - clientBounds.y;
2803
+ this.node.style.left = `${dragBlockX}px`;
2804
+ this.node.style.top = `${dragBlockY}px`;
2805
+ },
2806
+ PipelineLayerPriority.BASE_LAYER
2807
+ ),
2808
+ this.listenPlaygroundEvent("mousedown", () => {
2809
+ this.nodeRef.current?.setVisible(false);
2810
+ this.contextMenuService.rightPanelVisible = false;
2811
+ })
2812
+ ]);
2813
+ }
2814
+ onScroll() {
2815
+ this.nodeRef.current?.setVisible(false);
2816
+ }
2817
+ onZoom() {
2818
+ this.nodeRef.current?.setVisible(false);
2819
+ }
2820
+ /**
2821
+ * Destroy
2822
+ */
2823
+ dispose() {
2824
+ super.dispose();
2825
+ }
2826
+ /**
2827
+ * 渲染工具栏
2828
+ */
2829
+ renderCommandMenus() {
2830
+ return this.commandRegistry.commands.filter((cmd) => cmd.category === "SELECTOR_BOX" /* SELECTOR_BOX */).map((cmd) => {
2831
+ const CommandRenderer = this.rendererRegistry.getRendererComponent(
2832
+ cmd.icon || cmd.id
2833
+ )?.renderer;
2834
+ return h(CommandRenderer, {
2835
+ key: cmd.id,
2836
+ command: cmd,
2837
+ isContextMenu: true,
2838
+ disabled: !this.commandRegistry.isEnabled(cmd.id),
2839
+ onClick: (e) => this.commandRegistry.executeCommand(cmd.id, e)
2840
+ });
2841
+ }).filter((c) => c);
2842
+ }
2843
+ render() {
2844
+ const SelectorBoxPopover = this.rendererRegistry.getRendererComponent(
2845
+ "context-menu-popover" /* CONTEXT_MENU_POPOVER */
2846
+ ).renderer;
2847
+ return wrapLayerRender(
2848
+ this.playgroundContainer,
2849
+ h(SelectorBoxPopover, {
2850
+ ref: (inst) => {
2851
+ this.nodeRef.current = inst;
2852
+ },
2853
+ content: this.renderCommandMenus()
2854
+ })
2855
+ );
2856
+ }
2857
+ };
2858
+ __decorateClass([
2859
+ inject(CommandRegistry)
2860
+ ], FlowContextMenuLayer.prototype, "commandRegistry", 2);
2861
+ __decorateClass([
2862
+ inject(FlowRendererRegistry)
2863
+ ], FlowContextMenuLayer.prototype, "rendererRegistry", 2);
2864
+ __decorateClass([
2865
+ inject(ContextMenuService)
2866
+ ], FlowContextMenuLayer.prototype, "contextMenuService", 2);
2867
+ __decorateClass([
2868
+ inject(PlaygroundContainerFactory)
2869
+ ], FlowContextMenuLayer.prototype, "playgroundContainer", 2);
2870
+ __decorateClass([
2871
+ observeEntity(FlowSelectConfigEntity)
2872
+ ], FlowContextMenuLayer.prototype, "flowSelectConfigEntity", 2);
2873
+ __decorateClass([
2874
+ inject(SelectionService)
2875
+ ], FlowContextMenuLayer.prototype, "selectionService", 2);
2876
+ __decorateClass([
2877
+ observeEntity(PlaygroundConfigEntity)
2878
+ ], FlowContextMenuLayer.prototype, "playgroundConfigEntity", 2);
2879
+ __decorateClass([
2880
+ observeEntity(EditorStateConfigEntity)
2881
+ ], FlowContextMenuLayer.prototype, "editorStateConfig", 2);
2882
+ __decorateClass([
2883
+ observeEntity(SelectorBoxConfigEntity)
2884
+ ], FlowContextMenuLayer.prototype, "selectorBoxConfigEntity", 2);
2885
+ FlowContextMenuLayer = __decorateClass([
2886
+ injectable()
2887
+ ], FlowContextMenuLayer);
2888
+ var FlowScrollLimitLayer = class extends Layer {
2889
+ getInitScroll() {
2890
+ return this.document.layout.getInitScroll(this.pipelineNode.getBoundingClientRect());
2891
+ }
2892
+ onReady() {
2893
+ const initScroll = () => this.getInitScroll();
2894
+ this.config.updateConfig(initScroll());
2895
+ this.config.addScrollLimit(
2896
+ (scroll) => scrollLimit(
2897
+ scroll,
2898
+ [this.document.root.getData(FlowNodeTransformData).bounds],
2899
+ this.config,
2900
+ initScroll
2901
+ )
2902
+ );
2903
+ }
2904
+ };
2905
+ __decorateClass([
2906
+ inject(FlowDocument)
2907
+ ], FlowScrollLimitLayer.prototype, "document", 2);
2908
+ FlowScrollLimitLayer = __decorateClass([
2909
+ injectable()
2910
+ ], FlowScrollLimitLayer);
2911
+ var FlowRendererContainerModule = new ContainerModule((bind) => {
2912
+ bind(FlowRendererRegistry).toSelf().inSingletonScope();
2913
+ bind(FlowRendererResizeObserver).toSelf().inSingletonScope();
2914
+ });
2915
+
2916
+ export { FlowContextMenuLayer, FlowDebugLayer, FlowDragEntity, FlowDragLayer, FlowLabelsLayer, FlowLinesLayer, FlowNodesContentLayer, FlowNodesTransformLayer, FlowRendererCommandCategory, FlowRendererComponentType, FlowRendererContainerModule, FlowRendererContribution, FlowRendererKey, FlowRendererRegistry, FlowScrollBarLayer, FlowScrollLimitLayer, FlowSelectConfigEntity, FlowSelectorBoundsLayer, FlowSelectorBoxLayer, FlowTextKey, MARK_ACTIVATED_ARROW_ID, MARK_ARROW_ID, ScrollBarEvents, SelectorBoxConfigEntity, createLines, useBaseColor };
2917
+ //# sourceMappingURL=index.js.map
2918
+ //# sourceMappingURL=index.js.map