femo-plugin 1.0.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.
- package/LICENSE +201 -0
- package/README.md +627 -0
- package/femo2host/__init__.py +4 -0
- package/femo2host/femoToolcall/chronica.py +156 -0
- package/femo2host/femoToolcall/femo-chat.mjs +69 -0
- package/femo2host/femoToolcall/femo_debugger.py +1515 -0
- package/femo2host/femo_api.py +437 -0
- package/femo2host/femo_gen_api.jsx +77 -0
- package/femoBridges/ContextExample.py +555 -0
- package/femoBridges/MemoryExample.py +163 -0
- package/femoBridges/__init__.py +1 -0
- package/femoBridges/getDir/get_dir.py +56 -0
- package/femoBridges/getDir//344/275/240/345/217/257/344/273/245/350/256/276/345/256/232/344/273/273/346/204/217/346/226/207/344/273/266/345/244/271/344/270/272/347/224/250/346/210/267/346/225/260/346/215/256/346/226/207/344/273/266/345/244/271.txt +10 -0
- package/femoBridges/llmBridge.py +247 -0
- package/femoBridges/llmProviders.py +308 -0
- package/femoCompiler/FEMO_CLIrenderer.py +198 -0
- package/femoCompiler/FEMO_config.py +35 -0
- package/femoCompiler/FEMO_errors.py +278 -0
- package/femoCompiler/FEMO_interpreter.py +163 -0
- package/femoCompiler/FEMO_normalizer.py +396 -0
- package/femoCompiler/FEMO_parser.py +2468 -0
- package/femoCompiler/FEMO_runtime.py +3630 -0
- package/femoCompiler/FEMO_scope_resolver.py +209 -0
- package/femoCompiler/__init__.py +1 -0
- package/femoCompiler/actor_resolver.py +86 -0
- package/femoCompiler/block_collector.py +441 -0
- package/femoCompiler/db_utils.py +485 -0
- package/femoCompiler/femoAsync.py +401 -0
- package/femoCompiler/host_manifest.py +68 -0
- package/femoCompiler/job_manager.py +767 -0
- package/femoCompiler/protocol.py +126 -0
- package/femoCompiler/save_dialog.py +402 -0
- package/femoCompiler/task_world.py +544 -0
- package/femoCompiler/vars/__init__.py +19 -0
- package/femoCompiler/vars/checkpoint.py +113 -0
- package/femoCompiler/vars/env.py +686 -0
- package/femoCompiler/vars/evaluator.py +567 -0
- package/femoCompiler/vars/join.py +303 -0
- package/femoCompiler/vars/merge.py +157 -0
- package/femoCompiler/vars/model.py +245 -0
- package/femoExamples/AI/345/211/252/350/247/206/351/242/221/AI/345/211/252/350/247/206/351/242/221.femo +192 -0
- package/femoExamples/AI/350/201/212/345/244/251/345/256/244/group-chat.femo +42 -0
- package/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +10 -0
- package/femoExamples/LuxFiat/luxfiat.femo +38 -0
- package/femoExamples/LuxFiat/wait.py +29 -0
- package/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +222 -0
- package/femoExamples/discussion.femo +70 -0
- package/femoExamples/goal-mode.femo +23 -0
- package/femoExamples//345/270/270/347/224/250/345/267/245/345/205/267python/wait.py +29 -0
- package/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils.py +205 -0
- package/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils2.py +324 -0
- package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200-/350/255/246/351/225/277/347/211/210.femo +544 -0
- package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +331 -0
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225/undercover_utils.py +683 -0
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225-/350/217/234/345/270/202/345/234/272/345/261/200.femo +348 -0
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225.femo +392 -0
- package/femoGen/document_ch.html +2352 -0
- package/femoGen/document_en.html +2279 -0
- package/femoGen/index.html +19 -0
- package/femoGen/intro_ch.html +942 -0
- package/femoGen/intro_en.html +932 -0
- package/femoGen/package-lock.json +1698 -0
- package/femoGen/package.json +19 -0
- package/femoGen/public/character_need.ttf +0 -0
- package/femoGen/public/favicon.ico +0 -0
- package/femoGen/public/femo-logo-slogan.svg +83 -0
- package/femoGen/public/femo-logo.svg +55 -0
- package/femoGen/public/logo-fullsize.ico +0 -0
- package/femoGen/src/FemoWorAuto.jsx +5444 -0
- package/femoGen/src/actionModal.jsx +358 -0
- package/femoGen/src/bubbleOverlay.jsx +701 -0
- package/femoGen/src/canvasNodes.jsx +608 -0
- package/femoGen/src/common.jsx +715 -0
- package/femoGen/src/debugPanel.jsx +530 -0
- package/femoGen/src/faIcons.jsx +84 -0
- package/femoGen/src/femoDiagnostics.js +122 -0
- package/femoGen/src/femoFileList.jsx +357 -0
- package/femoGen/src/femoGenerator.jsx +1198 -0
- package/femoGen/src/femoLog.js +107 -0
- package/femoGen/src/femoParser.jsx +2255 -0
- package/femoGen/src/femoPreview.jsx +297 -0
- package/femoGen/src/graphBuilder.jsx +358 -0
- package/femoGen/src/libPanel.jsx +519 -0
- package/femoGen/src/main.jsx +22 -0
- package/femoGen/src/mobileView.jsx +2796 -0
- package/femoGen/src/projectPanel.jsx +529 -0
- package/femoGen/src/soulModal.jsx +162 -0
- package/femoGen/src/styles/font.css +10 -0
- package/femoGen/src/themes.js +465 -0
- package/femoGen/src/useCanvasInteraction.jsx +319 -0
- package/femoGen/vite.config.js +28 -0
- package/femoGen//347/222/207/345/255/230/346/247/221.txt +15 -0
- package/hostAdapter/dshAdapter/README.md +68 -0
- package/hostAdapter/dshAdapter/build.mjs +75 -0
- package/hostAdapter/dshAdapter/client/client-ui/chat-node.tsx +339 -0
- package/hostAdapter/dshAdapter/client/client-ui/composer.tsx +997 -0
- package/hostAdapter/dshAdapter/client/client-ui/editor-page.tsx +726 -0
- package/hostAdapter/dshAdapter/client/client-ui/editor-view.tsx +88 -0
- package/hostAdapter/dshAdapter/client/client-ui/femo-stream-live.tsx +264 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/frame-router.ts +282 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/index.ts +44 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/ledger.ts +329 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/turn-view.tsx +211 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/window-id.ts +28 -0
- package/hostAdapter/dshAdapter/client/client-ui/stream-store.ts +550 -0
- package/hostAdapter/dshAdapter/client/client-ui/styles.ts +144 -0
- package/hostAdapter/dshAdapter/client/client-ui/view-button.tsx +572 -0
- package/hostAdapter/dshAdapter/client/client-ui/view-state.ts +61 -0
- package/hostAdapter/dshAdapter/client/client.tsx +518 -0
- package/hostAdapter/dshAdapter/client/fa-icons.tsx +112 -0
- package/hostAdapter/dshAdapter/client/femo-reasoning-row.tsx +103 -0
- package/hostAdapter/dshAdapter/client/lineage-fork-native.jsx +624 -0
- package/hostAdapter/dshAdapter/client/lineage-fork.jsx +585 -0
- package/hostAdapter/dshAdapter/cordis.patch.yml +8 -0
- package/hostAdapter/dshAdapter/dshPatch/DSH-0.1.2-fork/344/277/256/346/224/271/351/234/200/346/261/202.md +184 -0
- package/hostAdapter/dshAdapter/dshPatch/MEOW_MODIFICATIONS.md +3105 -0
- package/hostAdapter/dshAdapter/dshPatch/patch-dsh-0.1.2-alpha.1.py +313 -0
- package/hostAdapter/dshAdapter/host/api-retry.ts +141 -0
- package/hostAdapter/dshAdapter/host/bridge.ts +224 -0
- package/hostAdapter/dshAdapter/host/config.ts +124 -0
- package/hostAdapter/dshAdapter/host/debug-log.ts +29 -0
- package/hostAdapter/dshAdapter/host/debug-run.ts +793 -0
- package/hostAdapter/dshAdapter/host/diag-feed.ts +56 -0
- package/hostAdapter/dshAdapter/host/engine-events.ts +891 -0
- package/hostAdapter/dshAdapter/host/engine-transcript.ts +122 -0
- package/hostAdapter/dshAdapter/host/femo-files.ts +210 -0
- package/hostAdapter/dshAdapter/host/god-mirror.ts +234 -0
- package/hostAdapter/dshAdapter/host/host-log.ts +101 -0
- package/hostAdapter/dshAdapter/host/http.ts +66 -0
- package/hostAdapter/dshAdapter/host/index.ts +633 -0
- package/hostAdapter/dshAdapter/host/list-cache.ts +183 -0
- package/hostAdapter/dshAdapter/host/main-actor.ts +853 -0
- package/hostAdapter/dshAdapter/host/main-delivery-queue.ts +115 -0
- package/hostAdapter/dshAdapter/host/native-state.ts +21 -0
- package/hostAdapter/dshAdapter/host/node-retry.ts +246 -0
- package/hostAdapter/dshAdapter/host/persona.ts +146 -0
- package/hostAdapter/dshAdapter/host/pre-step-gate.ts +95 -0
- package/hostAdapter/dshAdapter/host/proj-trace.ts +49 -0
- package/hostAdapter/dshAdapter/host/projection-input.ts +238 -0
- package/hostAdapter/dshAdapter/host/projection.ts +742 -0
- package/hostAdapter/dshAdapter/host/routes.ts +1196 -0
- package/hostAdapter/dshAdapter/host/run-control.ts +641 -0
- package/hostAdapter/dshAdapter/host/safe-steer.ts +33 -0
- package/hostAdapter/dshAdapter/host/section-gate.ts +108 -0
- package/hostAdapter/dshAdapter/host/session-events.ts +45 -0
- package/hostAdapter/dshAdapter/host/state-files.ts +301 -0
- package/hostAdapter/dshAdapter/host/stream-frames.ts +229 -0
- package/hostAdapter/dshAdapter/host/subagent-native.ts +997 -0
- package/hostAdapter/dshAdapter/host/subagent.ts +1205 -0
- package/hostAdapter/dshAdapter/host/tools.ts +486 -0
- package/hostAdapter/dshAdapter/host/windowing-native.ts +294 -0
- package/hostAdapter/dshAdapter/host.manifest.json +6 -0
- package/hostAdapter/dshAdapter/lib/client.js +19161 -0
- package/hostAdapter/dshAdapter/lib/client.js.map +7 -0
- package/hostAdapter/dshAdapter/lib/index.js +8173 -0
- package/hostAdapter/dshAdapter/lib/index.js.map +7 -0
- package/hostAdapter/dshAdapter/package-lock.json +500 -0
- package/hostAdapter/dshAdapter/package.json +55 -0
- package/hostAdapter/dshAdapter/pnpm-lock.yaml +596 -0
- package/hostAdapter/dshAdapter/pnpm-workspace.yaml +2 -0
- package/hostAdapter/dshAdapter/python/dev-bridge-test.py +43 -0
- package/hostAdapter/dshAdapter/python/femo_bridge.py +533 -0
- package/hostAdapter/dshAdapter/tsconfig.host.json +9 -0
- package/hostAdapter/dshAdapter/tsconfig.json +21 -0
- package/package.json +40 -0
- package//350/257/255/346/263/225/346/226/207/346/241/243.md +1136 -0
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════
|
|
2
|
+
// ═══ common.jsx ═══
|
|
3
|
+
// ═══════════════════════════════════════════════════════════════
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { THEME_CSS } from './themes';
|
|
7
|
+
|
|
8
|
+
class ErrorBoundary extends React.Component {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.state = { error: null, errorInfo: null };
|
|
12
|
+
}
|
|
13
|
+
static getDerivedStateFromError(error) {
|
|
14
|
+
return { error };
|
|
15
|
+
}
|
|
16
|
+
componentDidCatch(error, errorInfo) {
|
|
17
|
+
this.setState({ error, errorInfo });
|
|
18
|
+
console.error('ErrorBoundary caught:', error, errorInfo);
|
|
19
|
+
}
|
|
20
|
+
render() {
|
|
21
|
+
if (this.state.error) {
|
|
22
|
+
return (
|
|
23
|
+
<div
|
|
24
|
+
style={{
|
|
25
|
+
padding: 30,
|
|
26
|
+
fontFamily: 'var(--femo-font-sans)',
|
|
27
|
+
color: 'var(--femo-danger)',
|
|
28
|
+
background: 'var(--femo-danger-soft)',
|
|
29
|
+
minHeight: '100vh',
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
<h2>发生错误</h2>
|
|
33
|
+
<pre style={{ whiteSpace: 'pre-wrap', fontSize: 13 }}>
|
|
34
|
+
{this.state.error?.toString()}
|
|
35
|
+
</pre>
|
|
36
|
+
<details style={{ marginTop: 16 }}>
|
|
37
|
+
<summary>组件堆栈</summary>
|
|
38
|
+
<pre style={{ fontSize: 11 }}>
|
|
39
|
+
{this.state.errorInfo?.componentStack}
|
|
40
|
+
</pre>
|
|
41
|
+
</details>
|
|
42
|
+
<button
|
|
43
|
+
onClick={() => this.setState({ error: null, errorInfo: null })}
|
|
44
|
+
style={{ marginTop: 16, padding: '8px 16px' }}
|
|
45
|
+
>
|
|
46
|
+
重试
|
|
47
|
+
</button>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return this.props.children;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ═══ FONTS ═══
|
|
56
|
+
// scoped=true(dsh 插件模式):跳过 body/* 全局规则,避免污染宿主主题;
|
|
57
|
+
// 画布动画(呼吸灯/流光)与编辑器内 class 始终保留。
|
|
58
|
+
const FontStyle = ({ scoped = false }) => (
|
|
59
|
+
<style>{`
|
|
60
|
+
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap');
|
|
61
|
+
/* MiSans(小米,免费商用):中文主字体,unicode-range 子集按需加载;字重为官方新刻度 330-700。
|
|
62
|
+
round12:去掉 Heavy——用户反馈加粗中文太粗,800/900 就近落到 Bold(630)。 */
|
|
63
|
+
@import url('https://cdn.jsdelivr.net/npm/misans@4.1.0/lib/Normal/MiSans-Regular.min.css');
|
|
64
|
+
@import url('https://cdn.jsdelivr.net/npm/misans@4.1.0/lib/Normal/MiSans-Medium.min.css');
|
|
65
|
+
@import url('https://cdn.jsdelivr.net/npm/misans@4.1.0/lib/Normal/MiSans-Demibold.min.css');
|
|
66
|
+
@import url('https://cdn.jsdelivr.net/npm/misans@4.1.0/lib/Normal/MiSans-Semibold.min.css');
|
|
67
|
+
@import url('https://cdn.jsdelivr.net/npm/misans@4.1.0/lib/Normal/MiSans-Bold.min.css');
|
|
68
|
+
${THEME_CSS}
|
|
69
|
+
${scoped ? '' : '* { box-sizing: border-box; }\n body { margin: 0; }'}
|
|
70
|
+
::-webkit-scrollbar { width: var(--femo-scrollbar-w); height: var(--femo-scrollbar-w); }
|
|
71
|
+
::-webkit-scrollbar-track { background: transparent; }
|
|
72
|
+
::-webkit-scrollbar-thumb { background: var(--femo-scrollbar); border-radius: 3px; }
|
|
73
|
+
input:focus, textarea:focus, select:focus { border-color: var(--femo-primary) !important; box-shadow: 0 0 0 3px var(--femo-primary-glow-weak) !important; }
|
|
74
|
+
/* 窄视口(手机):iOS Safari 对 <16px 输入控件聚焦会整页自动放大;
|
|
75
|
+
聚焦时临时提到 16px 抑制缩放(meta user-scalable 自 iOS 10 起被忽略,
|
|
76
|
+
这是唯一可靠路径),失焦自动恢复。仅限 femoGen 容器(data-femo-theme)。 */
|
|
77
|
+
@media (max-width: 767px) {
|
|
78
|
+
[data-femo-theme] input:focus, [data-femo-theme] textarea:focus, [data-femo-theme] select:focus { font-size: 16px !important; }
|
|
79
|
+
}
|
|
80
|
+
.node-drag { cursor: grabbing !important; }
|
|
81
|
+
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
|
|
82
|
+
@keyframes nodeGlow {
|
|
83
|
+
0%, 100% { box-shadow: 0 0 8px 2px var(--femo-primary-glow), 0 0 16px 4px var(--femo-primary-glow-weak); }
|
|
84
|
+
50% { box-shadow: 0 0 16px 6px var(--femo-primary-glow-strong), 0 0 32px 10px var(--femo-primary-glow); }
|
|
85
|
+
}
|
|
86
|
+
@keyframes nodeGlowError {
|
|
87
|
+
0%, 100% { box-shadow: 0 0 8px 2px var(--femo-danger-glow), 0 0 16px 4px var(--femo-danger-glow-weak); }
|
|
88
|
+
50% { box-shadow: 0 0 16px 6px var(--femo-danger-glow-strong), 0 0 32px 10px var(--femo-danger-glow); }
|
|
89
|
+
}
|
|
90
|
+
.streaming-cursor { animation: blink 0.8s infinite; font-weight: bold; color: var(--femo-primary-strong); }
|
|
91
|
+
/* 桌面端底部三键(2026-09-08):与手机端设置三键同族的反馈语言——hover 提亮
|
|
92
|
+
(accent 微底 + 边框点亮),按压回缩。transition 由按钮内联 all 0.12s 承担。 */
|
|
93
|
+
.femo-setting-btn:hover {
|
|
94
|
+
background: color-mix(in srgb, var(--femo-primary) 8%, var(--femo-bg));
|
|
95
|
+
border-color: color-mix(in srgb, var(--femo-primary) 35%, var(--femo-border-strong));
|
|
96
|
+
color: var(--femo-text-1);
|
|
97
|
+
}
|
|
98
|
+
.femo-setting-btn:active {
|
|
99
|
+
transform: scale(0.98);
|
|
100
|
+
filter: brightness(1.12);
|
|
101
|
+
}
|
|
102
|
+
`}</style>
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// ═══ CONSTANTS ═══
|
|
106
|
+
const NW = 100,
|
|
107
|
+
NH = 56; // Action node size(round10:两行文字 64→56,更扁更精致)
|
|
108
|
+
const MW = 110,
|
|
109
|
+
MH = 66; // Module node size on canvas(同步 -8)
|
|
110
|
+
const SPW = 90,
|
|
111
|
+
SPH = 36; // Special node size
|
|
112
|
+
const PSW = 90,
|
|
113
|
+
PSH = 36; // Position node size
|
|
114
|
+
|
|
115
|
+
const TYPES = [
|
|
116
|
+
{ t: 'ai', lbl: '@ai', c: 'var(--femo-primary-strong)', bg: 'var(--femo-type-ai-bg)' },
|
|
117
|
+
{ t: 'human', lbl: '@human', c: 'var(--femo-type-human)', bg: 'var(--femo-success-soft)' },
|
|
118
|
+
{ t: 'mind', lbl: '@mind', c: 'var(--femo-type-mind)', bg: 'var(--femo-type-mind-bg)' },
|
|
119
|
+
{ t: 'func', lbl: '@func', c: 'var(--femo-type-func)', bg: 'var(--femo-warning-soft)' },
|
|
120
|
+
{ t: 'assign', lbl: '@assign', c: 'var(--femo-type-assign)', bg: 'var(--femo-type-assign-bg)' },
|
|
121
|
+
{ t: 'notice', lbl: '@notice', c: 'var(--femo-type-notice)', bg: 'var(--femo-type-notice-bg)' },
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
const ti = (t) => TYPES.find((x) => x.t === t) || TYPES[0];
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
const SPECIAL_COLORS = {
|
|
128
|
+
START: { c: 'var(--femo-success-strong)', bg: 'var(--femo-sp-start-bg)' },
|
|
129
|
+
END: { c: 'var(--femo-danger)', bg: 'var(--femo-sp-end-bg)' },
|
|
130
|
+
IN: { c: 'var(--femo-success-strong)', bg: 'var(--femo-sp-start-bg)' },
|
|
131
|
+
OUT: { c: 'var(--femo-danger)', bg: 'var(--femo-sp-end-bg)' },
|
|
132
|
+
BREAK: { c: 'var(--femo-warning)', bg: 'var(--femo-sp-break-bg)' },
|
|
133
|
+
FOR: { c: 'var(--femo-primary-strong)', bg: 'var(--femo-sp-for-bg)' },
|
|
134
|
+
PAR: { c: 'var(--femo-special-par)', bg: 'var(--femo-sp-par-bg)' },
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// Nodes that can only receive connections, not send
|
|
138
|
+
const SINK_ONLY = new Set(['END', 'OUT', 'BREAK']);
|
|
139
|
+
|
|
140
|
+
let _n = 0,
|
|
141
|
+
_e = 0,
|
|
142
|
+
_a = 0,
|
|
143
|
+
|
|
144
|
+
_m = 0;
|
|
145
|
+
|
|
146
|
+
const nid = () => `n${++_n}`;
|
|
147
|
+
const eid = () => `e${++_e}`;
|
|
148
|
+
const aid = () => `a${++_a}`;
|
|
149
|
+
const mid = () => `m${++_m}`;
|
|
150
|
+
const actionId = (path, name) => `a:${path.join('/')}:${name}`;
|
|
151
|
+
|
|
152
|
+
// ═══ NODE SIZE HELPER ═══
|
|
153
|
+
|
|
154
|
+
function getNodeSize(node) {
|
|
155
|
+
if (node.type === 'special') return { w: SPW, h: SPH };
|
|
156
|
+
if (node.type === 'for_out') return { w: 22, h: 22 };
|
|
157
|
+
if (node.type === 'par_out') return { w: SPW, h: SPH }; // 和 PAR 节点一样大
|
|
158
|
+
if (node.type === 'module') return { w: MW, h: MH };
|
|
159
|
+
if (node.type === 'position') return { w: PSW, h: PSH };
|
|
160
|
+
return { w: NW, h: NH };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
// ═══ SMART PORT CALCULATION ═══
|
|
165
|
+
function getSmartPorts(srcNode, tgtNode, preferDifferent = false, occupiedSrcDirs = new Set(), occupiedTgtDirs = new Set()) {
|
|
166
|
+
const ss = getNodeSize(srcNode);
|
|
167
|
+
const ts = getNodeSize(tgtNode);
|
|
168
|
+
const srcCx = srcNode.x + ss.w / 2;
|
|
169
|
+
const srcCy = srcNode.y + ss.h / 2;
|
|
170
|
+
const tgtCx = tgtNode.x + ts.w / 2;
|
|
171
|
+
const tgtCy = tgtNode.y + ts.h / 2;
|
|
172
|
+
|
|
173
|
+
const srcPorts = [
|
|
174
|
+
{ dir: 'top', x: srcCx, y: srcNode.y },
|
|
175
|
+
{ dir: 'bottom', x: srcCx, y: srcNode.y + ss.h },
|
|
176
|
+
{ dir: 'left', x: srcNode.x, y: srcCy },
|
|
177
|
+
{ dir: 'right', x: srcNode.x + ss.w, y: srcCy },
|
|
178
|
+
];
|
|
179
|
+
const tgtPorts = [
|
|
180
|
+
{ dir: 'top', x: tgtCx, y: tgtNode.y },
|
|
181
|
+
{ dir: 'bottom', x: tgtCx, y: tgtNode.y + ts.h },
|
|
182
|
+
{ dir: 'left', x: tgtNode.x, y: tgtCy },
|
|
183
|
+
{ dir: 'right', x: tgtNode.x + ts.w, y: tgtCy },
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
const allSrcFull = occupiedSrcDirs.size >= 4;
|
|
187
|
+
const allTgtFull = occupiedTgtDirs.size >= 4;
|
|
188
|
+
|
|
189
|
+
// 收集所有端口对,并评分
|
|
190
|
+
const pairs = [];
|
|
191
|
+
for (const sp of srcPorts) {
|
|
192
|
+
for (const tp of tgtPorts) {
|
|
193
|
+
const dx = sp.x - tp.x;
|
|
194
|
+
const dy = sp.y - tp.y;
|
|
195
|
+
pairs.push({
|
|
196
|
+
sp, tp,
|
|
197
|
+
dist: dx * dx + dy * dy,
|
|
198
|
+
srcDir: sp.dir,
|
|
199
|
+
tgtDir: tp.dir,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 评分:srcDir/tgtDir 未被占用的得 0 分,被占用的得 1 分(全满时视为未占用)
|
|
205
|
+
pairs.forEach(p => {
|
|
206
|
+
const srcPenalty = (allSrcFull || !occupiedSrcDirs.has(p.srcDir)) ? 0 : 1;
|
|
207
|
+
const tgtPenalty = (allTgtFull || !occupiedTgtDirs.has(p.tgtDir)) ? 0 : 1;
|
|
208
|
+
p.score = srcPenalty + tgtPenalty;
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// 先按评分升序(分数越低越优),再按距离升序
|
|
212
|
+
pairs.sort((a, b) => a.score - b.score || a.dist - b.dist);
|
|
213
|
+
const best = pairs[0];
|
|
214
|
+
|
|
215
|
+
if (preferDifferent && pairs.length > 1) {
|
|
216
|
+
// 找第一个和 best 方向不同的对
|
|
217
|
+
for (const p of pairs) {
|
|
218
|
+
if (p.srcDir !== best.srcDir || p.tgtDir !== best.tgtDir) {
|
|
219
|
+
return {
|
|
220
|
+
srcPort: { x: p.sp.x, y: p.sp.y },
|
|
221
|
+
tgtPort: { x: p.tp.x, y: p.tp.y },
|
|
222
|
+
srcDir: p.srcDir,
|
|
223
|
+
tgtDir: p.tgtDir,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
srcPort: { x: best.sp.x, y: best.sp.y },
|
|
231
|
+
tgtPort: { x: best.tp.x, y: best.tp.y },
|
|
232
|
+
srcDir: best.srcDir,
|
|
233
|
+
tgtDir: best.tgtDir,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ═══ SMART BEZIER — 控制点提取 ═══
|
|
238
|
+
function getControlPoints(x1, y1, dir1, x2, y2, dir2) {
|
|
239
|
+
const dist = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
|
|
240
|
+
const offset = Math.max(40, Math.min(dist * 0.4, 120));
|
|
241
|
+
let cx1 = x1, cy1 = y1, cx2 = x2, cy2 = y2;
|
|
242
|
+
switch (dir1) {
|
|
243
|
+
case 'right': cx1 = x1 + offset; break;
|
|
244
|
+
case 'left': cx1 = x1 - offset; break;
|
|
245
|
+
case 'bottom': cy1 = y1 + offset; break;
|
|
246
|
+
case 'top': cy1 = y1 - offset; break;
|
|
247
|
+
}
|
|
248
|
+
switch (dir2) {
|
|
249
|
+
case 'left': cx2 = x2 - offset; break;
|
|
250
|
+
case 'right': cx2 = x2 + offset; break;
|
|
251
|
+
case 'top': cy2 = y2 - offset; break;
|
|
252
|
+
case 'bottom': cy2 = y2 + offset; break;
|
|
253
|
+
}
|
|
254
|
+
return { p0: { x: x1, y: y1 }, p1: { x: cx1, y: cy1 }, p2: { x: cx2, y: cy2 }, p3: { x: x2, y: y2 } };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ═══ SMART BEZIER — 路径字符串(向后兼容) ═══
|
|
258
|
+
function smartBezier(x1, y1, dir1, x2, y2, dir2) {
|
|
259
|
+
const { p0, p1, p2, p3 } = getControlPoints(x1, y1, dir1, x2, y2, dir2);
|
|
260
|
+
return `M${p0.x},${p0.y} C${p1.x},${p1.y} ${p2.x},${p2.y} ${p3.x},${p3.y}`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ═══ 贝塞尔曲线中点(t=0.5 处精确坐标) ═══
|
|
264
|
+
// C(0.5) = (P0 + 3*P1 + 3*P2 + P3) / 8
|
|
265
|
+
function bezierMidpoint(x1, y1, dir1, x2, y2, dir2) {
|
|
266
|
+
const { p0, p1, p2, p3 } = getControlPoints(x1, y1, dir1, x2, y2, dir2);
|
|
267
|
+
//console.log('[bezierMidpoint]', { p0, p1, p2, p3 });
|
|
268
|
+
return {
|
|
269
|
+
x: (p0.x + 3 * p1.x + 3 * p2.x + p3.x) / 8,
|
|
270
|
+
y: (p0.y + 3 * p1.y + 3 * p2.y + p3.y) / 8,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// ═══ 端口偏移计算(同方向多边分流) ═══
|
|
275
|
+
function applyPortOffset(port, dir, nodeObj, edgeId, portEdgeGroupMap) {
|
|
276
|
+
if (!port) return port;
|
|
277
|
+
// for_out 节点不平移(par_out 不在 portEdgeGroupMap 中,自然不偏移)
|
|
278
|
+
if (nodeObj && nodeObj.type === 'for_out') return port;
|
|
279
|
+
const key = `${nodeObj.id}:${dir}`;
|
|
280
|
+
const group = portEdgeGroupMap[key];
|
|
281
|
+
if (!group || group.count <= 1) return port;
|
|
282
|
+
const idx = group.indices[edgeId] ?? 0;
|
|
283
|
+
const total = group.count;
|
|
284
|
+
const gap = 6;
|
|
285
|
+
const offsetAmount = (idx - (total - 1) / 2) * gap;
|
|
286
|
+
if (dir === 'top' || dir === 'bottom') {
|
|
287
|
+
return { x: port.x + offsetAmount, y: port.y };
|
|
288
|
+
}
|
|
289
|
+
return { x: port.x, y: port.y + offsetAmount };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ═══ PAR 平行线端口生成 ═══
|
|
293
|
+
function generateParallelPorts(port, dir, count, gap) {
|
|
294
|
+
if (!port || port.x == null || port.y == null) return [];
|
|
295
|
+
if (count <= 1) return [port];
|
|
296
|
+
const result = [];
|
|
297
|
+
for (let i = 0; i < count; i++) {
|
|
298
|
+
const off = (i - (count - 1) / 2) * gap;
|
|
299
|
+
if (dir === 'top' || dir === 'bottom') {
|
|
300
|
+
result.push({ x: port.x + off, y: port.y });
|
|
301
|
+
} else {
|
|
302
|
+
result.push({ x: port.x, y: port.y + off });
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ═══ 统一边几何计算 ═══
|
|
309
|
+
// 输出:{ pathDs, labelPos, srcPorts, tgtPorts, midIdx, srcDir, tgtDir }
|
|
310
|
+
// 不含样式判定(颜色/marker/dashArray 留在渲染层)
|
|
311
|
+
function computeEdgeGeometry(edge, srcNode, tgtNode, options) {
|
|
312
|
+
const {
|
|
313
|
+
isCycleEdge = false,
|
|
314
|
+
isParEdge = false,
|
|
315
|
+
parLineCount = 5,
|
|
316
|
+
parGap = 6,
|
|
317
|
+
portEdgeGroupMap = {},
|
|
318
|
+
} = options;
|
|
319
|
+
|
|
320
|
+
// console.log('[computeEdgeGeometry] edge.id=', edge.id, 'src=', srcNode.id, 'tgt=', tgtNode.id,
|
|
321
|
+
// 'isCycleEdge=', isCycleEdge, 'isParEdge=', isParEdge);
|
|
322
|
+
|
|
323
|
+
// 1. 智能端口选择
|
|
324
|
+
let { srcPort, tgtPort, srcDir, tgtDir } = getSmartPorts(srcNode, tgtNode, isCycleEdge);
|
|
325
|
+
// console.log('[computeEdgeGeometry] getSmartPorts:', { srcPort, tgtPort, srcDir, tgtDir });
|
|
326
|
+
|
|
327
|
+
// 2. for_out 特殊端口:强制为节点中心
|
|
328
|
+
if (srcNode.type === 'for_out') {
|
|
329
|
+
srcPort = { x: srcNode.x + 11, y: srcNode.y + 11 };
|
|
330
|
+
srcDir = 'center';
|
|
331
|
+
}
|
|
332
|
+
if (tgtNode.type === 'for_out') {
|
|
333
|
+
tgtPort = { x: tgtNode.x + 11, y: tgtNode.y + 11 };
|
|
334
|
+
tgtDir = 'center';
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 3. 端口偏移(多边同向分组)
|
|
338
|
+
const adjustedSrcPort = applyPortOffset(srcPort, srcDir, srcNode, edge.id, portEdgeGroupMap);
|
|
339
|
+
const adjustedTgtPort = applyPortOffset(tgtPort, tgtDir, tgtNode, edge.id, portEdgeGroupMap);
|
|
340
|
+
// console.log('[computeEdgeGeometry] adjusted:', { adjustedSrcPort, adjustedTgtPort });
|
|
341
|
+
|
|
342
|
+
// 4. PAR 平行线
|
|
343
|
+
const srcPorts = isParEdge
|
|
344
|
+
? generateParallelPorts(adjustedSrcPort, srcDir, parLineCount, parGap)
|
|
345
|
+
: [adjustedSrcPort].filter(p => p && p.x != null && p.y != null);
|
|
346
|
+
const tgtPorts = isParEdge
|
|
347
|
+
? generateParallelPorts(adjustedTgtPort, tgtDir, parLineCount, parGap)
|
|
348
|
+
: [adjustedTgtPort].filter(p => p && p.x != null && p.y != null);
|
|
349
|
+
|
|
350
|
+
if (srcPorts.length === 0 || tgtPorts.length === 0) {
|
|
351
|
+
// console.warn('[computeEdgeGeometry] 端口为空, edge.id=', edge.id);
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// 5. 生成路径数组
|
|
356
|
+
const pathDs = srcPorts.map((sp, i) => {
|
|
357
|
+
const tp = tgtPorts[i];
|
|
358
|
+
return smartBezier(sp.x, sp.y, srcDir, tp.x, tp.y, tgtDir);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// 6. 标签位置:中间那条线的贝塞尔 t=0.5 中点
|
|
362
|
+
const midIdx = isParEdge ? Math.floor(parLineCount / 2) : 0;
|
|
363
|
+
const midSrc = srcPorts[midIdx];
|
|
364
|
+
const midTgt = tgtPorts[midIdx];
|
|
365
|
+
const labelPos = bezierMidpoint(midSrc.x, midSrc.y, srcDir, midTgt.x, midTgt.y, tgtDir);
|
|
366
|
+
// console.log('[computeEdgeGeometry] labelPos:', labelPos, 'midIdx:', midIdx, 'pathDs count:', pathDs.length);
|
|
367
|
+
|
|
368
|
+
return {
|
|
369
|
+
pathDs,
|
|
370
|
+
labelPos,
|
|
371
|
+
srcPorts,
|
|
372
|
+
tgtPorts,
|
|
373
|
+
midIdx,
|
|
374
|
+
srcDir,
|
|
375
|
+
tgtDir,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
// ═══ BACK EDGE DETECTION ═══
|
|
381
|
+
function findBackEdges(nodes, edges) {
|
|
382
|
+
const adj = new Map();
|
|
383
|
+
edges.forEach((e) => {
|
|
384
|
+
if (!adj.has(e.src)) adj.set(e.src, []);
|
|
385
|
+
adj.get(e.src).push(e);
|
|
386
|
+
});
|
|
387
|
+
const vis = new Set(),
|
|
388
|
+
stk = new Set(),
|
|
389
|
+
back = new Set();
|
|
390
|
+
function dfs(id) {
|
|
391
|
+
vis.add(id);
|
|
392
|
+
stk.add(id);
|
|
393
|
+
for (const e of adj.get(id) || []) {
|
|
394
|
+
if (!vis.has(e.tgt)) dfs(e.tgt);
|
|
395
|
+
else if (stk.has(e.tgt)) back.add(e.id);
|
|
396
|
+
}
|
|
397
|
+
stk.delete(id);
|
|
398
|
+
}
|
|
399
|
+
// 强制从入口节点(START/IN)开始 DFS,确保回边检测正确
|
|
400
|
+
const entryNodes = nodes.filter(n =>
|
|
401
|
+
n.type === 'special' && (n.specialType === 'START' || n.specialType === 'IN')
|
|
402
|
+
);
|
|
403
|
+
if (entryNodes.length === 0) {
|
|
404
|
+
console.warn('[findBackEdges] 未找到入口节点 (START/IN), 返回空 back 集合。nodes:', nodes.map(n => `${n.id}:${n.type}:${n.specialType || ''}`));
|
|
405
|
+
} else {
|
|
406
|
+
entryNodes.forEach(n => {
|
|
407
|
+
if (!vis.has(n.id)) dfs(n.id);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
//console.log('[findBackEdges] 完成, back 边数:', back.size, '节点数:', nodes.length, '边数:', edges.length);
|
|
411
|
+
return back;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// 新增:获取环上所有边(用于渲染)—— 按 FOR 节点分组
|
|
415
|
+
|
|
416
|
+
function findAllCycleEdges(nodes, edges) {
|
|
417
|
+
const adj = new Map();
|
|
418
|
+
edges.forEach((e) => {
|
|
419
|
+
if (!adj.has(e.src)) adj.set(e.src, []);
|
|
420
|
+
adj.get(e.src).push(e);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const forNodeIds = new Set(
|
|
424
|
+
nodes.filter((n) => n.specialType === 'FOR' || n.specialType === 'PAR').map((n) => n.id)
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
// 为 PAR 建立 par_out 目标映射
|
|
428
|
+
const parOutTargetMap = new Map();
|
|
429
|
+
nodes.forEach((n) => {
|
|
430
|
+
if (n.specialType === 'PAR' && n.forOutNodeId) {
|
|
431
|
+
parOutTargetMap.set(n.id, n.forOutNodeId);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const cycleMap = new Map();
|
|
436
|
+
|
|
437
|
+
for (const startId of forNodeIds) {
|
|
438
|
+
const visitedEdges = new Set();
|
|
439
|
+
const pathEdges = [];
|
|
440
|
+
const collected = new Set();
|
|
441
|
+
const recStack = new Set(); // 防止非目标子环导致无限递归
|
|
442
|
+
|
|
443
|
+
function dfs(currentId) {
|
|
444
|
+
if (recStack.has(currentId)) {
|
|
445
|
+
// console.log('[findAllCycleEdges] recStack 命中非目标节点:', currentId, 'startId:', startId, '当前路径边数:', pathEdges.length, '停止深入');
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
recStack.add(currentId);
|
|
449
|
+
|
|
450
|
+
for (const e of adj.get(currentId) || []) {
|
|
451
|
+
if (visitedEdges.has(e.id)) continue;
|
|
452
|
+
visitedEdges.add(e.id);
|
|
453
|
+
pathEdges.push(e.id);
|
|
454
|
+
|
|
455
|
+
// FOR 环回到自身,PAR 环回到对应的 par_out 节点
|
|
456
|
+
const isCycle =
|
|
457
|
+
e.tgt === startId ||
|
|
458
|
+
(parOutTargetMap.has(startId) &&
|
|
459
|
+
parOutTargetMap.get(startId) != null &&
|
|
460
|
+
e.tgt === parOutTargetMap.get(startId));
|
|
461
|
+
|
|
462
|
+
if (isCycle) {
|
|
463
|
+
pathEdges.forEach((id) => collected.add(id));
|
|
464
|
+
// console.log('[findAllCycleEdges] 找到环! startId:', startId, '路径边数:', pathEdges.length, '累计收集:', collected.size);
|
|
465
|
+
} else if (recStack.has(e.tgt)) {
|
|
466
|
+
// ★ 回指上游节点:收录当前路径所有边(含此回指边自身),不递归
|
|
467
|
+
const beforeSize = collected.size;
|
|
468
|
+
pathEdges.forEach((id) => collected.add(id));
|
|
469
|
+
// console.log('[findAllCycleEdges] 回指边收录, startId:', startId, 'currentId:', currentId, 'e.id:', e.id, 'e.tgt:', e.tgt, 'pathEdges:', [...pathEdges], '新增边数:', collected.size - beforeSize);
|
|
470
|
+
} else {
|
|
471
|
+
dfs(e.tgt);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
pathEdges.pop();
|
|
475
|
+
visitedEdges.delete(e.id);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
recStack.delete(currentId);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
dfs(startId);
|
|
482
|
+
//console.log('[findAllCycleEdges] startId:', startId, '收集边数:', collected.size);
|
|
483
|
+
if (collected.size > 0) {
|
|
484
|
+
cycleMap.set(startId, collected);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return cycleMap;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
// ═══ SHARED STYLES ═══
|
|
493
|
+
const inp = {
|
|
494
|
+
width: '100%',
|
|
495
|
+
boxSizing: 'border-box',
|
|
496
|
+
padding: '7px 10px',
|
|
497
|
+
borderRadius: 'var(--femo-radius-md)',
|
|
498
|
+
border: 'var(--femo-border-w-strong) solid var(--femo-border-strong)',
|
|
499
|
+
fontSize: 12.5,
|
|
500
|
+
color: 'var(--femo-text-1)',
|
|
501
|
+
background: 'var(--femo-bg)',
|
|
502
|
+
outline: 'none',
|
|
503
|
+
fontFamily: 'var(--femo-font-sans)',
|
|
504
|
+
transition: 'border-color 0.15s, box-shadow 0.15s',
|
|
505
|
+
};
|
|
506
|
+
const btnP = {
|
|
507
|
+
padding: '8px 16px',
|
|
508
|
+
borderRadius: 'var(--femo-radius-md)',
|
|
509
|
+
background: 'var(--femo-btn-primary)',
|
|
510
|
+
color: 'var(--femo-on-accent)',
|
|
511
|
+
border: 'none',
|
|
512
|
+
cursor: 'pointer',
|
|
513
|
+
fontSize: 12.5,
|
|
514
|
+
fontWeight: 700,
|
|
515
|
+
fontFamily: 'var(--femo-font-sans)',
|
|
516
|
+
transition: 'opacity 0.12s',
|
|
517
|
+
};
|
|
518
|
+
const btnS = {
|
|
519
|
+
padding: '8px 16px',
|
|
520
|
+
borderRadius: 'var(--femo-radius-md)',
|
|
521
|
+
background: 'var(--femo-surface)',
|
|
522
|
+
color: 'var(--femo-text-2)',
|
|
523
|
+
border: 'var(--femo-border-w-strong) solid var(--femo-border-strong)',
|
|
524
|
+
cursor: 'pointer',
|
|
525
|
+
fontSize: 12.5,
|
|
526
|
+
fontWeight: 600,
|
|
527
|
+
fontFamily: 'var(--femo-font-sans)',
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
// ═══ FIELD ═══
|
|
532
|
+
function F({ label, hint, children }) {
|
|
533
|
+
return (
|
|
534
|
+
// flex: 1 + minWidth: 0:并排字段(如 Version/Owner)在 flex 行里自动
|
|
535
|
+
// 平分宽度;block 父级下 flex 属性不生效,单列布局不受影响。
|
|
536
|
+
<div style={{ marginBottom: 13, flex: 1, minWidth: 0 }}>
|
|
537
|
+
<div
|
|
538
|
+
style={{
|
|
539
|
+
fontSize: 11,
|
|
540
|
+
fontWeight: 700,
|
|
541
|
+
color: 'var(--femo-text-3)',
|
|
542
|
+
marginBottom: 5,
|
|
543
|
+
display: 'flex',
|
|
544
|
+
alignItems: 'center',
|
|
545
|
+
gap: 5,
|
|
546
|
+
}}
|
|
547
|
+
>
|
|
548
|
+
{label}
|
|
549
|
+
{hint && (
|
|
550
|
+
<span style={{ fontWeight: 400, color: 'var(--femo-text-4)', fontSize: 10.5 }}>
|
|
551
|
+
{hint}
|
|
552
|
+
</span>
|
|
553
|
+
)}
|
|
554
|
+
</div>
|
|
555
|
+
{children}
|
|
556
|
+
</div>
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// ═══ PORT CIRCLE ═══
|
|
561
|
+
function PortCircle({ x, y, color, onMouseDown, onMouseUp, nodeId, portDir, portX, portY }) {
|
|
562
|
+
return (
|
|
563
|
+
<div
|
|
564
|
+
data-port-node={nodeId}
|
|
565
|
+
data-port-dir={portDir}
|
|
566
|
+
data-port-x={portX}
|
|
567
|
+
data-port-y={portY}
|
|
568
|
+
onMouseDown={
|
|
569
|
+
onMouseDown
|
|
570
|
+
? (e) => {
|
|
571
|
+
e.stopPropagation();
|
|
572
|
+
onMouseDown(e);
|
|
573
|
+
}
|
|
574
|
+
: undefined
|
|
575
|
+
}
|
|
576
|
+
onMouseUp={
|
|
577
|
+
onMouseUp
|
|
578
|
+
? (e) => {
|
|
579
|
+
e.stopPropagation();
|
|
580
|
+
onMouseUp(e);
|
|
581
|
+
}
|
|
582
|
+
: undefined
|
|
583
|
+
}
|
|
584
|
+
style={{
|
|
585
|
+
position: 'absolute',
|
|
586
|
+
left: x - 12,
|
|
587
|
+
top: y - 12,
|
|
588
|
+
width: 24,
|
|
589
|
+
height: 24,
|
|
590
|
+
borderRadius: 'var(--femo-radius-pill)',
|
|
591
|
+
display: 'flex',
|
|
592
|
+
alignItems: 'center',
|
|
593
|
+
justifyContent: 'center',
|
|
594
|
+
cursor: 'crosshair',
|
|
595
|
+
zIndex: 30,
|
|
596
|
+
}}
|
|
597
|
+
>
|
|
598
|
+
<div style={{
|
|
599
|
+
width: 14,
|
|
600
|
+
height: 14,
|
|
601
|
+
borderRadius: 'var(--femo-radius-pill)',
|
|
602
|
+
background: 'var(--femo-surface)',
|
|
603
|
+
border: `var(--femo-border-w-selected) solid ${color}`,
|
|
604
|
+
pointerEvents: 'none',
|
|
605
|
+
}} />
|
|
606
|
+
</div>
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
// ═══ PROP ROW ═══
|
|
612
|
+
function PR({ k, v }) {
|
|
613
|
+
return (
|
|
614
|
+
<div style={{ display: 'flex', gap: 8, fontSize: 11.5, marginBottom: 5 }}>
|
|
615
|
+
<span style={{ color: 'var(--femo-neutral)', minWidth: 48, flexShrink: 0 }}>{k}</span>
|
|
616
|
+
<span
|
|
617
|
+
style={{
|
|
618
|
+
color: 'var(--femo-text-1)',
|
|
619
|
+
fontFamily: 'var(--femo-font-mono)',
|
|
620
|
+
fontWeight: 600,
|
|
621
|
+
overflow: 'hidden',
|
|
622
|
+
textOverflow: 'ellipsis',
|
|
623
|
+
whiteSpace: 'nowrap',
|
|
624
|
+
}}
|
|
625
|
+
>
|
|
626
|
+
{v}
|
|
627
|
+
</span>
|
|
628
|
+
</div>
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
// ═══ DEFAULT CANVAS NODES ═══
|
|
634
|
+
function makeDefaultNodes(mode) {
|
|
635
|
+
if (mode === 'mainflow') {
|
|
636
|
+
return [
|
|
637
|
+
{
|
|
638
|
+
id: nid(),
|
|
639
|
+
type: 'special',
|
|
640
|
+
specialType: 'START',
|
|
641
|
+
x: 80,
|
|
642
|
+
y: 200,
|
|
643
|
+
label: '[START]',
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
id: nid(),
|
|
647
|
+
type: 'special',
|
|
648
|
+
specialType: 'END',
|
|
649
|
+
x: 600,
|
|
650
|
+
y: 200,
|
|
651
|
+
label: '[END]',
|
|
652
|
+
},
|
|
653
|
+
];
|
|
654
|
+
}
|
|
655
|
+
return [
|
|
656
|
+
{
|
|
657
|
+
id: nid(),
|
|
658
|
+
type: 'special',
|
|
659
|
+
specialType: 'IN',
|
|
660
|
+
x: 80,
|
|
661
|
+
y: 200,
|
|
662
|
+
label: '[IN]',
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
id: nid(),
|
|
666
|
+
type: 'special',
|
|
667
|
+
specialType: 'OUT',
|
|
668
|
+
x: 600,
|
|
669
|
+
y: 200,
|
|
670
|
+
label: '[OUT]',
|
|
671
|
+
},
|
|
672
|
+
];
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// ═══ NAME UNIQUENESS HELPER ═══
|
|
676
|
+
function getAllNames(lib, proj) {
|
|
677
|
+
const names = new Set();
|
|
678
|
+
(lib?.actions || []).forEach((a) => names.add(a.name));
|
|
679
|
+
(lib?.modules || []).forEach((m) => names.add(m.name));
|
|
680
|
+
(proj?.actors || []).forEach((a) => {
|
|
681
|
+
const n = a.name?.replace('@', '');
|
|
682
|
+
if (n) names.add(n);
|
|
683
|
+
});
|
|
684
|
+
return names;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// ═══ FOR ↔ for_out 拖拽位置联动(桌面端 onMM 与手机端 nodeDrag 共用一份定义) ═══
|
|
688
|
+
// nodes=全量节点数组,draggedNode=被拖节点(含最新引用),(newX,newY)=被拖节点新位置。
|
|
689
|
+
// 返回联动后的新数组:拖 FOR → for_out 小圆点跟随;拖 for_out → FOR 反向跟随;
|
|
690
|
+
// par_out 完全自由移动,不做任何联动(两个条件天然不命中)。
|
|
691
|
+
function applyForLinkage(nodes, draggedNode, newX, newY) {
|
|
692
|
+
return nodes.map((n) => {
|
|
693
|
+
if (n.id === draggedNode.id) {
|
|
694
|
+
return { ...n, x: newX, y: newY };
|
|
695
|
+
}
|
|
696
|
+
// 拖拽 FOR 节点 → 联动 for_out 小圆点(PAR 不联动)
|
|
697
|
+
if (draggedNode.specialType === 'FOR' && n.type === 'for_out' && n.id === draggedNode.forOutNodeId) {
|
|
698
|
+
return { ...n, x: newX + SPW - 22, y: newY + (SPH - 22) / 2 };
|
|
699
|
+
}
|
|
700
|
+
// 拖拽 for_out 小圆点 → 联动 FOR 节点(par_out 不联动)
|
|
701
|
+
if (draggedNode.type === 'for_out' && n.id === draggedNode.forNodeId) {
|
|
702
|
+
return { ...n, x: newX - SPW + 22, y: newY - (SPH - 22) / 2 };
|
|
703
|
+
}
|
|
704
|
+
return n;
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
export {
|
|
709
|
+
ErrorBoundary, FontStyle, TYPES, ti, SPECIAL_COLORS, SINK_ONLY,
|
|
710
|
+
nid, eid, aid, mid, actionId, NW, NH, MW, MH, SPW, SPH, PSW, PSH,
|
|
711
|
+
getNodeSize, getSmartPorts, smartBezier, getControlPoints, bezierMidpoint,
|
|
712
|
+
computeEdgeGeometry,
|
|
713
|
+
findBackEdges, findAllCycleEdges, inp, btnP, btnS, F as Field,
|
|
714
|
+
PortCircle, PR, makeDefaultNodes, getAllNames, applyForLinkage,
|
|
715
|
+
};
|