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.
Files changed (166) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +627 -0
  3. package/femo2host/__init__.py +4 -0
  4. package/femo2host/femoToolcall/chronica.py +156 -0
  5. package/femo2host/femoToolcall/femo-chat.mjs +69 -0
  6. package/femo2host/femoToolcall/femo_debugger.py +1515 -0
  7. package/femo2host/femo_api.py +437 -0
  8. package/femo2host/femo_gen_api.jsx +77 -0
  9. package/femoBridges/ContextExample.py +555 -0
  10. package/femoBridges/MemoryExample.py +163 -0
  11. package/femoBridges/__init__.py +1 -0
  12. package/femoBridges/getDir/get_dir.py +56 -0
  13. 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
  14. package/femoBridges/llmBridge.py +247 -0
  15. package/femoBridges/llmProviders.py +308 -0
  16. package/femoCompiler/FEMO_CLIrenderer.py +198 -0
  17. package/femoCompiler/FEMO_config.py +35 -0
  18. package/femoCompiler/FEMO_errors.py +278 -0
  19. package/femoCompiler/FEMO_interpreter.py +163 -0
  20. package/femoCompiler/FEMO_normalizer.py +396 -0
  21. package/femoCompiler/FEMO_parser.py +2468 -0
  22. package/femoCompiler/FEMO_runtime.py +3630 -0
  23. package/femoCompiler/FEMO_scope_resolver.py +209 -0
  24. package/femoCompiler/__init__.py +1 -0
  25. package/femoCompiler/actor_resolver.py +86 -0
  26. package/femoCompiler/block_collector.py +441 -0
  27. package/femoCompiler/db_utils.py +485 -0
  28. package/femoCompiler/femoAsync.py +401 -0
  29. package/femoCompiler/host_manifest.py +68 -0
  30. package/femoCompiler/job_manager.py +767 -0
  31. package/femoCompiler/protocol.py +126 -0
  32. package/femoCompiler/save_dialog.py +402 -0
  33. package/femoCompiler/task_world.py +544 -0
  34. package/femoCompiler/vars/__init__.py +19 -0
  35. package/femoCompiler/vars/checkpoint.py +113 -0
  36. package/femoCompiler/vars/env.py +686 -0
  37. package/femoCompiler/vars/evaluator.py +567 -0
  38. package/femoCompiler/vars/join.py +303 -0
  39. package/femoCompiler/vars/merge.py +157 -0
  40. package/femoCompiler/vars/model.py +245 -0
  41. 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
  42. package/femoExamples/AI/350/201/212/345/244/251/345/256/244/group-chat.femo +42 -0
  43. package/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +10 -0
  44. package/femoExamples/LuxFiat/luxfiat.femo +38 -0
  45. package/femoExamples/LuxFiat/wait.py +29 -0
  46. package/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +222 -0
  47. package/femoExamples/discussion.femo +70 -0
  48. package/femoExamples/goal-mode.femo +23 -0
  49. package/femoExamples//345/270/270/347/224/250/345/267/245/345/205/267python/wait.py +29 -0
  50. package/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils.py +205 -0
  51. package/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils2.py +324 -0
  52. 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
  53. package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +331 -0
  54. package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225/undercover_utils.py +683 -0
  55. 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
  56. 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
  57. package/femoGen/document_ch.html +2352 -0
  58. package/femoGen/document_en.html +2279 -0
  59. package/femoGen/index.html +19 -0
  60. package/femoGen/intro_ch.html +942 -0
  61. package/femoGen/intro_en.html +932 -0
  62. package/femoGen/package-lock.json +1698 -0
  63. package/femoGen/package.json +19 -0
  64. package/femoGen/public/character_need.ttf +0 -0
  65. package/femoGen/public/favicon.ico +0 -0
  66. package/femoGen/public/femo-logo-slogan.svg +83 -0
  67. package/femoGen/public/femo-logo.svg +55 -0
  68. package/femoGen/public/logo-fullsize.ico +0 -0
  69. package/femoGen/src/FemoWorAuto.jsx +5444 -0
  70. package/femoGen/src/actionModal.jsx +358 -0
  71. package/femoGen/src/bubbleOverlay.jsx +701 -0
  72. package/femoGen/src/canvasNodes.jsx +608 -0
  73. package/femoGen/src/common.jsx +715 -0
  74. package/femoGen/src/debugPanel.jsx +530 -0
  75. package/femoGen/src/faIcons.jsx +84 -0
  76. package/femoGen/src/femoDiagnostics.js +122 -0
  77. package/femoGen/src/femoFileList.jsx +357 -0
  78. package/femoGen/src/femoGenerator.jsx +1198 -0
  79. package/femoGen/src/femoLog.js +107 -0
  80. package/femoGen/src/femoParser.jsx +2255 -0
  81. package/femoGen/src/femoPreview.jsx +297 -0
  82. package/femoGen/src/graphBuilder.jsx +358 -0
  83. package/femoGen/src/libPanel.jsx +519 -0
  84. package/femoGen/src/main.jsx +22 -0
  85. package/femoGen/src/mobileView.jsx +2796 -0
  86. package/femoGen/src/projectPanel.jsx +529 -0
  87. package/femoGen/src/soulModal.jsx +162 -0
  88. package/femoGen/src/styles/font.css +10 -0
  89. package/femoGen/src/themes.js +465 -0
  90. package/femoGen/src/useCanvasInteraction.jsx +319 -0
  91. package/femoGen/vite.config.js +28 -0
  92. package/femoGen//347/222/207/345/255/230/346/247/221.txt +15 -0
  93. package/hostAdapter/dshAdapter/README.md +68 -0
  94. package/hostAdapter/dshAdapter/build.mjs +75 -0
  95. package/hostAdapter/dshAdapter/client/client-ui/chat-node.tsx +339 -0
  96. package/hostAdapter/dshAdapter/client/client-ui/composer.tsx +997 -0
  97. package/hostAdapter/dshAdapter/client/client-ui/editor-page.tsx +726 -0
  98. package/hostAdapter/dshAdapter/client/client-ui/editor-view.tsx +88 -0
  99. package/hostAdapter/dshAdapter/client/client-ui/femo-stream-live.tsx +264 -0
  100. package/hostAdapter/dshAdapter/client/client-ui/proj2/frame-router.ts +282 -0
  101. package/hostAdapter/dshAdapter/client/client-ui/proj2/index.ts +44 -0
  102. package/hostAdapter/dshAdapter/client/client-ui/proj2/ledger.ts +329 -0
  103. package/hostAdapter/dshAdapter/client/client-ui/proj2/turn-view.tsx +211 -0
  104. package/hostAdapter/dshAdapter/client/client-ui/proj2/window-id.ts +28 -0
  105. package/hostAdapter/dshAdapter/client/client-ui/stream-store.ts +550 -0
  106. package/hostAdapter/dshAdapter/client/client-ui/styles.ts +144 -0
  107. package/hostAdapter/dshAdapter/client/client-ui/view-button.tsx +572 -0
  108. package/hostAdapter/dshAdapter/client/client-ui/view-state.ts +61 -0
  109. package/hostAdapter/dshAdapter/client/client.tsx +518 -0
  110. package/hostAdapter/dshAdapter/client/fa-icons.tsx +112 -0
  111. package/hostAdapter/dshAdapter/client/femo-reasoning-row.tsx +103 -0
  112. package/hostAdapter/dshAdapter/client/lineage-fork-native.jsx +624 -0
  113. package/hostAdapter/dshAdapter/client/lineage-fork.jsx +585 -0
  114. package/hostAdapter/dshAdapter/cordis.patch.yml +8 -0
  115. package/hostAdapter/dshAdapter/dshPatch/DSH-0.1.2-fork/344/277/256/346/224/271/351/234/200/346/261/202.md +184 -0
  116. package/hostAdapter/dshAdapter/dshPatch/MEOW_MODIFICATIONS.md +3105 -0
  117. package/hostAdapter/dshAdapter/dshPatch/patch-dsh-0.1.2-alpha.1.py +313 -0
  118. package/hostAdapter/dshAdapter/host/api-retry.ts +141 -0
  119. package/hostAdapter/dshAdapter/host/bridge.ts +224 -0
  120. package/hostAdapter/dshAdapter/host/config.ts +124 -0
  121. package/hostAdapter/dshAdapter/host/debug-log.ts +29 -0
  122. package/hostAdapter/dshAdapter/host/debug-run.ts +793 -0
  123. package/hostAdapter/dshAdapter/host/diag-feed.ts +56 -0
  124. package/hostAdapter/dshAdapter/host/engine-events.ts +891 -0
  125. package/hostAdapter/dshAdapter/host/engine-transcript.ts +122 -0
  126. package/hostAdapter/dshAdapter/host/femo-files.ts +210 -0
  127. package/hostAdapter/dshAdapter/host/god-mirror.ts +234 -0
  128. package/hostAdapter/dshAdapter/host/host-log.ts +101 -0
  129. package/hostAdapter/dshAdapter/host/http.ts +66 -0
  130. package/hostAdapter/dshAdapter/host/index.ts +633 -0
  131. package/hostAdapter/dshAdapter/host/list-cache.ts +183 -0
  132. package/hostAdapter/dshAdapter/host/main-actor.ts +853 -0
  133. package/hostAdapter/dshAdapter/host/main-delivery-queue.ts +115 -0
  134. package/hostAdapter/dshAdapter/host/native-state.ts +21 -0
  135. package/hostAdapter/dshAdapter/host/node-retry.ts +246 -0
  136. package/hostAdapter/dshAdapter/host/persona.ts +146 -0
  137. package/hostAdapter/dshAdapter/host/pre-step-gate.ts +95 -0
  138. package/hostAdapter/dshAdapter/host/proj-trace.ts +49 -0
  139. package/hostAdapter/dshAdapter/host/projection-input.ts +238 -0
  140. package/hostAdapter/dshAdapter/host/projection.ts +742 -0
  141. package/hostAdapter/dshAdapter/host/routes.ts +1196 -0
  142. package/hostAdapter/dshAdapter/host/run-control.ts +641 -0
  143. package/hostAdapter/dshAdapter/host/safe-steer.ts +33 -0
  144. package/hostAdapter/dshAdapter/host/section-gate.ts +108 -0
  145. package/hostAdapter/dshAdapter/host/session-events.ts +45 -0
  146. package/hostAdapter/dshAdapter/host/state-files.ts +301 -0
  147. package/hostAdapter/dshAdapter/host/stream-frames.ts +229 -0
  148. package/hostAdapter/dshAdapter/host/subagent-native.ts +997 -0
  149. package/hostAdapter/dshAdapter/host/subagent.ts +1205 -0
  150. package/hostAdapter/dshAdapter/host/tools.ts +486 -0
  151. package/hostAdapter/dshAdapter/host/windowing-native.ts +294 -0
  152. package/hostAdapter/dshAdapter/host.manifest.json +6 -0
  153. package/hostAdapter/dshAdapter/lib/client.js +19161 -0
  154. package/hostAdapter/dshAdapter/lib/client.js.map +7 -0
  155. package/hostAdapter/dshAdapter/lib/index.js +8173 -0
  156. package/hostAdapter/dshAdapter/lib/index.js.map +7 -0
  157. package/hostAdapter/dshAdapter/package-lock.json +500 -0
  158. package/hostAdapter/dshAdapter/package.json +55 -0
  159. package/hostAdapter/dshAdapter/pnpm-lock.yaml +596 -0
  160. package/hostAdapter/dshAdapter/pnpm-workspace.yaml +2 -0
  161. package/hostAdapter/dshAdapter/python/dev-bridge-test.py +43 -0
  162. package/hostAdapter/dshAdapter/python/femo_bridge.py +533 -0
  163. package/hostAdapter/dshAdapter/tsconfig.host.json +9 -0
  164. package/hostAdapter/dshAdapter/tsconfig.json +21 -0
  165. package/package.json +40 -0
  166. package//350/257/255/346/263/225/346/226/207/346/241/243.md +1136 -0
@@ -0,0 +1,2796 @@
1
+ // ═══════════════════════════════════════════════════════════════
2
+ // ═══ mobileView.jsx ─── 手机端统一视图管理
3
+ // ═══════════════════════════════════════════════════════════════
4
+ //
5
+ // 布局(固定,不可整体滚动/缩放):
6
+ // ┌─────────────────────────────────┐
7
+ // │ TitleBar (5vh) │
8
+ // ├─────────────────────────────────┤
9
+ // │ │
10
+ // │ Canvas (75vh) │
11
+ // │ │
12
+ // ├─────────────────────────────────┤
13
+ // │ BottomPanel (20vh) │
14
+ // │ [Library | Project | Props] │
15
+ // └─────────────────────────────────┘
16
+ //
17
+ // 手势:
18
+ // 单指拖动 → 平移画布
19
+ // 双指捏合 → 缩放画布
20
+ // 单击 → 选中节点/边
21
+ // 双击 → 打开节点编辑
22
+ // 长按 → 调出节点上下文菜单(预留)
23
+ //
24
+ // ═══════════════════════════════════════════════════════════════
25
+
26
+ import React, {
27
+ useState,
28
+ useRef,
29
+ useCallback,
30
+ useEffect,
31
+ useMemo,
32
+ } from 'react';
33
+ import { ti, inp, btnP, btnS, getNodeSize, applyForLinkage } from './common';
34
+ import { LibPanel } from './libPanel';
35
+ import { ProjPanel, useModelList, sourceOptions } from './projectPanel';
36
+ import { BubbleOverlay } from './bubbleOverlay';
37
+ import { FemoPreview } from './femoPreview';
38
+ import { DebugPanel } from './debugPanel';
39
+ import { FaPlay, FaPause, FaForward, FaPalette, FaUserPlus, FaTerminal, FaFolderOpen, FaFloppyDisk, IconPanelLeftOutline, FaSquareOutline } from './faIcons';
40
+
41
+ // ─────────────────────────────────────────────
42
+ // 颜色 / 主题 token
43
+ // ─────────────────────────────────────────────
44
+ const T = {
45
+ bg: 'var(--femo-mobile-bg)',
46
+ surface: 'var(--femo-mobile-surface)',
47
+ surfaceHover: 'var(--femo-mobile-surface-hover)',
48
+ border: 'var(--femo-mobile-border)',
49
+ borderLight: 'var(--femo-mobile-border-light)',
50
+ accent: 'var(--femo-primary)',
51
+ accentGlow: 'var(--femo-primary-glow)',
52
+ textPrimary: 'var(--femo-mobile-text-1)',
53
+ textSecondary: 'var(--femo-text-3)',
54
+ textMuted: 'var(--femo-mobile-text-3)',
55
+ tabActive: 'var(--femo-primary)',
56
+ tabInactive: 'var(--femo-mobile-border)',
57
+ danger: 'var(--femo-danger)',
58
+ success: 'var(--femo-success)',
59
+ warning: 'var(--femo-warning)',
60
+ };
61
+
62
+ // ─────────────────────────────────────────────
63
+ // 全局样式注入(仅手机端追加)
64
+ // ─────────────────────────────────────────────
65
+ const MobileGlobalStyle = () => (
66
+ <style>{`
67
+ /* round44:全局 touch-action:none 是仓库卡片无法滚动的元凶——
68
+ Chrome 从触点向上累积 touch-action,body 的 none 污染整条链。
69
+ 画布区自有独立规则(.femo-canvas-zone),此处不再全局禁触。 */
70
+ html, body {
71
+ overscroll-behavior: none;
72
+ }
73
+ /* round50:防拖拽误选只作用于 femo 自己的容器,不再挂 html/body——
74
+ user-select 沿树继承,全局 none 会把 dsh 聊天正文的选择一起杀掉
75
+ (2026-08-28 猫猫报 3081 手机端无法选中 AI/用户消息文字的根因)。
76
+ 画布区拖节点/连线的手势保护保留在自身容器上。 */
77
+ .femo-canvas-zone,
78
+ .femo-bottom-scroll {
79
+ user-select: none;
80
+ -webkit-user-select: none;
81
+ }
82
+ /* 画布区禁止浏览器默认触摸行为(拖节点/连线/平移全走自定义手势)。
83
+ round55:-webkit-touch-callout 掐掉 iOS 长按呼出的放大镜/菜单。
84
+ Android 长按选字由 useMobileCanvasGesture 里的 non-passive
85
+ preventDefault 在手势层根治——React 17+ 的合成 touchstart/touchmove
86
+ 一律 passive 挂载,组件里 e.preventDefault() 是无效调用;
87
+ CSS user-select:none(round50)只能定义"谁不可选",拦不住
88
+ 浏览器原生长按选择流程本身,只有取消 touchstart 默认行为这一条路。 */
89
+ .femo-canvas-zone {
90
+ touch-action: none;
91
+ -webkit-touch-callout: none;
92
+ }
93
+ /* 底部面板允许垂直滚动 */
94
+ .femo-bottom-scroll {
95
+ touch-action: pan-y;
96
+ overflow-y: auto;
97
+ -webkit-overflow-scrolling: touch;
98
+ }
99
+ /* 输入框恢复 touch */
100
+ .femo-bottom-scroll input,
101
+ .femo-bottom-scroll textarea,
102
+ .femo-bottom-scroll select {
103
+ touch-action: auto;
104
+ user-select: text;
105
+ -webkit-user-select: text;
106
+ }
107
+ /* 侧边菜单遮罩淡入 */
108
+ @keyframes fadeInOverlay {
109
+ from { opacity: 0; }
110
+ to { opacity: 1; }
111
+ }
112
+ /* 侧边菜单滑入 */
113
+ @keyframes slideInMenu {
114
+ from { transform: translateX(-100%); }
115
+ to { transform: translateX(0); }
116
+ }
117
+ /* FEMO 面板滑入 */
118
+ @keyframes slideInFemo {
119
+ from { transform: translateX(100%); }
120
+ to { transform: translateX(0); }
121
+ }
122
+ /* 底部面板切换淡入 */
123
+ @keyframes fadePanel {
124
+ from { opacity: 0; transform: translateY(6px); }
125
+ to { opacity: 1; transform: translateY(0); }
126
+ }
127
+ /* 气泡弹出 */
128
+ @keyframes popIn {
129
+ from { opacity: 0; transform: translate(-50%, -46%) scale(0.92); }
130
+ to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
131
+ }
132
+ /* 标题栏闪光扫描 */
133
+ @keyframes scanLine {
134
+ 0% { left: -60%; }
135
+ 100% { left: 110%; }
136
+ }
137
+ /* 状态指示灯脉冲 */
138
+ @keyframes pulse {
139
+ 0%, 100% { opacity: 1; transform: scale(1); }
140
+ 50% { opacity: 0.6; transform: scale(0.85); }
141
+ }
142
+ /* round27:仓库拖拽 ghost 弹出(弹性放大+淡入,只动 opacity/transform) */
143
+ @keyframes ghostPopIn {
144
+ from { opacity: 0; transform: scale(0.7); }
145
+ to { opacity: 1; transform: scale(1.05); }
146
+ }
147
+ /* round27:ghost 光晕呼吸(只动 box-shadow,与 popIn 属性不相交可同列) */
148
+ @keyframes ghostBreath {
149
+ from { box-shadow: 0 4px 16px var(--femo-primary-glow); }
150
+ to { box-shadow: 0 6px 26px var(--femo-primary-glow-x); }
151
+ }
152
+ /* round27:画布"可放置"提示浮现 */
153
+ @keyframes dropHintIn {
154
+ from { opacity: 0; transform: scale(0.985); }
155
+ to { opacity: 1; transform: scale(1); }
156
+ }
157
+ /* 流式光标 */
158
+ .mob-cursor { animation: blink 0.75s step-end infinite; }
159
+ @keyframes blink { 50% { opacity: 0; } }
160
+ /* 运行控制图标按钮(2026-09-06 统一重造):手机无 hover,反馈走按压
161
+ 回缩 + 提亮;顺手掐掉移动端点按灰闪(tap-highlight)。 */
162
+ .femo-mob-icon-btn {
163
+ transition: transform 0.12s ease, filter 0.12s ease;
164
+ -webkit-tap-highlight-color: transparent;
165
+ touch-action: manipulation;
166
+ }
167
+ .femo-mob-icon-btn:active {
168
+ transform: scale(0.88);
169
+ filter: brightness(1.3);
170
+ }
171
+ /* 设置面板三键(2026-09-08):同款按压反馈语言(回缩+提亮),宽幅文字按钮
172
+ 幅度比 32px 图标芯片温和;同样掐移动端点按灰闪。 */
173
+ .femo-mob-setting-btn {
174
+ transition: transform 0.12s ease, filter 0.12s ease;
175
+ -webkit-tap-highlight-color: transparent;
176
+ touch-action: manipulation;
177
+ }
178
+ .femo-mob-setting-btn:active {
179
+ transform: scale(0.97);
180
+ filter: brightness(1.15);
181
+ }
182
+ `}</style>
183
+ );
184
+
185
+ // ─────────────────────────────────────────────
186
+ // TitleBar
187
+ // ─────────────────────────────────────────────
188
+ function MobileTitleBar({
189
+ projName,
190
+ flowStatus,
191
+ femoVisible,
192
+ onBack,
193
+ onExpand,
194
+ onToggleFemo,
195
+ onRun,
196
+ onPause,
197
+ onResume,
198
+ hasActiveRunningNodes,
199
+ // 文件读写(2026-09-11 手机端补齐):与桌面工具栏「导入 .femo / 导出 .femo」
200
+ // 同源回调(插件=host 系统对话框 / 独立=浏览器 file input + 下载)。
201
+ onImport,
202
+ onExport,
203
+ exportBusy,
204
+ // Module 子画布层级(2026-09-06):非主流程时显示「‹ 模块名」返回键。
205
+ locationPath,
206
+ onNavigatePath,
207
+ }) {
208
+ const statusDot = {
209
+ idle: { c: T.textMuted, label: '' },
210
+ running: { c: T.success, label: '运行中' },
211
+ paused: { c: T.warning, label: '已挂起,可续跑' },
212
+ }[flowStatus] || { c: T.textMuted, label: '' };
213
+
214
+ return (
215
+ <div
216
+ style={{
217
+ position: 'relative',
218
+ height: '5vh',
219
+ minHeight: 40,
220
+ maxHeight: 56,
221
+ background: T.surface,
222
+ borderBottom: `var(--femo-border-w) solid ${T.border}`,
223
+ display: 'flex',
224
+ alignItems: 'center',
225
+ justifyContent: 'space-between',
226
+ padding: '0 12px',
227
+ flexShrink: 0,
228
+ zIndex: 100,
229
+ overflow: 'hidden',
230
+ }}
231
+ >
232
+ {/* 扫光效果 */}
233
+ <div
234
+ style={{
235
+ position: 'absolute',
236
+ top: 0,
237
+ width: '60%',
238
+ height: '100%',
239
+ background:
240
+ 'linear-gradient(90deg,transparent,var(--femo-primary-glow-weak),transparent)',
241
+ pointerEvents: 'none',
242
+ animation: 'scanLine 4s linear infinite',
243
+ }}
244
+ />
245
+
246
+ {/* 左侧:插件模式开边栏(全屏态,退出沉浸并开 dsh 边栏)/ 最大化(容器态,
247
+ 回沉浸)。2026-09-11 用户点名两次改这套图标:①←/→ 箭头→FA 窗口控件
248
+ (箭头暗示左右移动,与「窗口状态切换」的真实语义无关);②FA 的
249
+ fa-maximize 是四角括号各带一支对角箭头,看着像「移动窗口」,遂定案——
250
+ 左=宿主同款边栏图标 IconPanelLeftOutline,右=FA regular 描边方块
251
+ FaSquareOutline(solid 方块原是隔壁「停止」键的图形故取描边;该键
252
+ 2026-09-12 已改名「暂停」换 ⏸ 双竖条,描边方块继续沿用)。 */}
253
+ <div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0 }}>
254
+ {onExpand ? (
255
+ <button
256
+ onClick={onExpand}
257
+ aria-label="全屏沉浸"
258
+ style={{
259
+ background: 'none',
260
+ border: 'none',
261
+ cursor: 'pointer',
262
+ padding: '6px 10px 6px 2px',
263
+ display: 'flex',
264
+ alignItems: 'center',
265
+ color: T.textSecondary,
266
+ lineHeight: 1,
267
+ flexShrink: 0,
268
+ }}
269
+ >
270
+ <FaSquareOutline size={19} />
271
+ </button>
272
+ ) : onBack ? (
273
+ <button
274
+ onClick={onBack}
275
+ aria-label="退出全屏,打开 dsh 边栏"
276
+ style={{
277
+ background: 'none',
278
+ border: 'none',
279
+ cursor: 'pointer',
280
+ padding: '6px 10px 6px 2px',
281
+ display: 'flex',
282
+ alignItems: 'center',
283
+ color: T.textSecondary,
284
+ lineHeight: 1,
285
+ flexShrink: 0,
286
+ }}
287
+ >
288
+ <IconPanelLeftOutline size={19} />
289
+ </button>
290
+ ) : null}
291
+ </div>
292
+
293
+ {/* 中间:完整路径面包屑(2026-09-07 对齐桌面端语义)——文件名=主流程
294
+ 入口(点击回主画布),每级模块名=定位到该模块子画布(点击跳到那一
295
+ 层)。文件名与模块名是同一条 path 的段,UI 同款芯片(用户反馈);
296
+ 主流程层级下文件名显示为普通大字标题(无可去之处)。当前层为末段。 */}
297
+ <div
298
+ style={{
299
+ flex: 1,
300
+ display: 'flex',
301
+ alignItems: 'center',
302
+ gap: 6,
303
+ overflow: 'hidden',
304
+ padding: '0 8px',
305
+ }}
306
+ >
307
+ {(() => {
308
+ const inModule = locationPath !== undefined && locationPath.length > 1;
309
+ const crumbChip = (isCurrent) => ({
310
+ background: `color-mix(in srgb, ${T.textSecondary} ${isCurrent ? 14 : 8}%, transparent)`,
311
+ border: `var(--femo-border-w) solid color-mix(in srgb, ${T.textSecondary} ${isCurrent ? 40 : 28}%, transparent)`,
312
+ borderRadius: 'var(--femo-radius-sm)',
313
+ height: 24,
314
+ padding: '0 8px',
315
+ display: 'flex',
316
+ alignItems: 'center',
317
+ cursor: 'pointer',
318
+ color: T.textSecondary,
319
+ lineHeight: 1,
320
+ fontSize: 10.5,
321
+ fontWeight: 800,
322
+ fontFamily: 'var(--femo-font-sans)',
323
+ maxWidth: 108,
324
+ overflow: 'hidden',
325
+ flexShrink: 0,
326
+ });
327
+ const ellipsis = { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' };
328
+ return (
329
+ <>
330
+ {inModule && onNavigatePath ? (
331
+ <button
332
+ onClick={() => onNavigatePath(['mainflow'])}
333
+ title="回到主画布"
334
+ style={crumbChip(false)}
335
+ >
336
+ <span style={ellipsis}>{projName || 'FEMO Flow'}</span>
337
+ </button>
338
+ ) : (
339
+ <span
340
+ style={{
341
+ fontSize: 13,
342
+ fontWeight: 800,
343
+ color: T.textPrimary,
344
+ fontFamily: 'var(--femo-font-sans)',
345
+ overflow: 'hidden',
346
+ textOverflow: 'ellipsis',
347
+ whiteSpace: 'nowrap',
348
+ letterSpacing: '0.01em',
349
+ flexShrink: 0,
350
+ }}
351
+ >
352
+ {projName || 'FEMO Flow'}
353
+ </span>
354
+ )}
355
+ {inModule && onNavigatePath && locationPath.slice(1).map((seg, idx) => {
356
+ const depth = idx + 1; // locationPath 内的层级(0=mainflow)
357
+ const isCurrent = depth === locationPath.length - 1;
358
+ return (
359
+ <React.Fragment key={depth}>
360
+ <span style={{ color: T.textMuted, fontSize: 12, flexShrink: 0 }}>›</span>
361
+ <button
362
+ onClick={() => onNavigatePath(locationPath.slice(0, depth + 1))}
363
+ title={isCurrent ? `当前所在模块 ${seg}` : `定位到模块 ${seg}`}
364
+ style={crumbChip(isCurrent)}
365
+ >
366
+ <span style={ellipsis}>{seg}</span>
367
+ </button>
368
+ </React.Fragment>
369
+ );
370
+ })}
371
+ </>
372
+ );
373
+ })()}
374
+ {flowStatus !== 'idle' && (
375
+ <div style={{ display: 'flex', alignItems: 'center', gap: 4, flexShrink: 0 }}>
376
+ <span
377
+ style={{
378
+ width: 6,
379
+ height: 6,
380
+ borderRadius: 'var(--femo-radius-pill)',
381
+ background: statusDot.c,
382
+ display: 'block',
383
+ animation: flowStatus === 'running' ? 'pulse 1.2s ease-in-out infinite' : 'none',
384
+ flexShrink: 0,
385
+ }}
386
+ />
387
+ <span style={{ fontSize: 10, color: statusDot.c, fontWeight: 700, fontFamily: 'var(--femo-font-mono)' }}>
388
+ {statusDot.label}
389
+ </span>
390
+ </div>
391
+ )}
392
+ </div>
393
+
394
+ {/* 右侧:运行控制 + 文件读写 + FEMO 切换
395
+ (2026-09-11 用户点名调序:播放/暂停/继续这组放最左,文件读写(导入/导出)
396
+ 在其右,FEMO 视图开关仍居最右——控制键与视图开关夹住文件读写。) */}
397
+ <div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0 }}>
398
+ {/* 运行控制(2026-09-11 定型:**按钮恒定,只变展示**)——三枚芯片各自钉死
399
+ 一个动作/一套样式/一句 title,从生到死不变;运行阶段只决定渲染哪几枚:
400
+ 绿▶「运行」 = fresh start(onRun:reset 从头开演)——未开跑与挂起态都出现
401
+ 红⏸「暂停」 = pause(onPause)——只在跑的时候出现(2026-09-12
402
+ 用户点名 stop→pause 全链路改名:原「停止」键,语义即挂起可续跑)
403
+ 琥珀⏩「继续」= resume(onResume:从断点续跑)——只在暂停之后的挂起态出现
404
+ 挂起态顺序=常驻的运行键在前、挂起专属的继续键在后。(引擎无独立
405
+ 硬暂停语义——pause=suspended 可续跑)。同款 FA 图标芯片底
406
+ (色 13% 底 + 38% 边),只靠语义色区分。 */}
407
+ {(flowStatus === 'idle' || flowStatus === 'paused') && (
408
+ <MobileIconBtn
409
+ onClick={onRun}
410
+ icon={FaPlay}
411
+ color={T.success}
412
+ title="运行(从头开演)"
413
+ />
414
+ )}
415
+ {flowStatus === 'running' && (
416
+ <MobileIconBtn
417
+ onClick={onPause}
418
+ icon={FaPause}
419
+ color={T.danger}
420
+ title="暂停(可续跑)"
421
+ />
422
+ )}
423
+ {flowStatus === 'paused' && (
424
+ <MobileIconBtn
425
+ onClick={onResume}
426
+ icon={FaForward}
427
+ color={T.warning}
428
+ title="继续(从断点续跑)"
429
+ />
430
+ )}
431
+ {/* 文件读写(2026-09-11 手机端补齐;同日顺位调整=移到运行键右侧):与桌面
432
+ 工具栏「导入 .femo / 导出 .femo」同源,收成两枚同款 32×32 图标芯片——
433
+ 打开(导入)/保存(导出)。中性灰(textSecondary)以示与运行控制的语义色
434
+ (绿/红/琥珀、强调色)分属两族。
435
+ 回调非函数时不渲染(独立模式被裁掉 onImport/onExport 的宿主)。 */}
436
+ {typeof onImport === 'function' && (
437
+ <MobileIconBtn
438
+ onClick={onImport}
439
+ icon={FaFolderOpen}
440
+ color={T.textSecondary}
441
+ title="导入 .femo"
442
+ />
443
+ )}
444
+ {typeof onExport === 'function' && (
445
+ <MobileIconBtn
446
+ onClick={onExport}
447
+ icon={FaFloppyDisk}
448
+ color={T.textSecondary}
449
+ title={exportBusy ? '保存中…' : '导出 .femo'}
450
+ disabled={exportBusy}
451
+ />
452
+ )}
453
+
454
+ {/* FEMO 预览切换(2026-09-06 与运行控制键同族化):同款 32×32 芯片
455
+ 造型(圆角/底+边公式/按压反馈全同),但走「视图开关」自己的颜色
456
+ ——开=主题强调色(浅底+细边+微光晕),关=中性灰。与运行键的
457
+ 绿/红/琥珀(从头跑·运行 / 暂停 / 继续)既同族又一眼可辨;颜色全部走主题 CSS
458
+ var,深浅两主题自动换值保持和谐可辨。 */}
459
+ <button
460
+ onClick={onToggleFemo}
461
+ title="FEMO 预览"
462
+ aria-label="FEMO 预览"
463
+ className="femo-mob-icon-btn"
464
+ style={{
465
+ background: femoVisible
466
+ ? `color-mix(in srgb, ${T.accent} 16%, transparent)`
467
+ : `color-mix(in srgb, ${T.textSecondary} 10%, transparent)`,
468
+ border: `var(--femo-border-w) solid ${
469
+ femoVisible
470
+ ? `color-mix(in srgb, ${T.accent} 45%, transparent)`
471
+ : `color-mix(in srgb, ${T.textSecondary} 32%, transparent)`
472
+ }`,
473
+ borderRadius: 'var(--femo-radius-sm)',
474
+ width: 32,
475
+ height: 32,
476
+ display: 'flex',
477
+ alignItems: 'center',
478
+ justifyContent: 'center',
479
+ cursor: 'pointer',
480
+ padding: 0,
481
+ lineHeight: 0,
482
+ fontSize: 9,
483
+ fontWeight: 800,
484
+ color: femoVisible ? T.accent : T.textSecondary,
485
+ fontFamily: 'var(--femo-font-mono)',
486
+ letterSpacing: '0.02em',
487
+ boxShadow: femoVisible ? '0 0 9px var(--femo-primary-glow-weak, transparent)' : 'none',
488
+ // 内联 transition 会整体覆盖 .femo-mob-icon-btn 的类级 transition,
489
+ // 故按压回缩/提亮(transform/filter)必须在此一并声明。
490
+ transition: 'transform 0.12s ease, filter 0.12s ease, background 0.15s, color 0.15s, box-shadow 0.15s',
491
+ }}
492
+ >
493
+ FEMO
494
+ </button>
495
+ </div>
496
+ </div>
497
+ );
498
+ }
499
+
500
+ // 运行控制图标按钮(2026-09-06 统一重造):三个状态键(跑/暂停/从头)同款
501
+ // 芯片造型——32×32 圆角方、色 13% 浅底 + 38% 细边、居中 FA 图标(继承按钮
502
+ // 文字色)。此前 label 文本符号(▶⏹⟲)字号基线各异,且 color+'22' 拼在
503
+ // CSS var 上是非法值、底/边从未渲染过——裸符号随手一摆就是「风格差太远」。
504
+ // FA 图标按 viewBox 等比渲染,三个图标光学尺寸天然一致。
505
+ function MobileIconBtn({ onClick, icon: Icon, color, title, disabled = false }) {
506
+ return (
507
+ <button
508
+ onClick={disabled ? undefined : onClick}
509
+ disabled={disabled}
510
+ title={title}
511
+ aria-label={title}
512
+ className="femo-mob-icon-btn"
513
+ style={{
514
+ background: `color-mix(in srgb, ${color} 13%, transparent)`,
515
+ border: `var(--femo-border-w) solid color-mix(in srgb, ${color} 38%, transparent)`,
516
+ borderRadius: 'var(--femo-radius-sm)',
517
+ width: 32,
518
+ height: 32,
519
+ display: 'flex',
520
+ alignItems: 'center',
521
+ justifyContent: 'center',
522
+ // 禁用(导出保存中):与桌面导出键同款——降透明度 + wait 光标,
523
+ // 防重复提交(onClick 已摘掉,双保险)。
524
+ cursor: disabled ? 'wait' : 'pointer',
525
+ opacity: disabled ? 0.55 : 1,
526
+ color: color,
527
+ flexShrink: 0,
528
+ padding: 0,
529
+ lineHeight: 0,
530
+ }}
531
+ >
532
+ <Icon size={12} />
533
+ </button>
534
+ );
535
+ }
536
+
537
+ // ─────────────────────────────────────────────
538
+ // FEMO 预览侧板(右侧全高滑出)
539
+ // ─────────────────────────────────────────────
540
+ function MobileFemoPanel({ visible, femoText, onChange, femoError, femoDirty, onApply, onRestore, onGraphToFemo, onClose }) {
541
+ // 头排按钮回执状态(2026-09-07 与桌面端同款设计语言)。hooks 必须在
542
+ // `!visible` 早退之前——条件挂载会打乱 hooks 顺序。
543
+ const [copied, setCopied] = useState(false);
544
+ const [g2tFlash, setG2tFlash] = useState(false);
545
+ const [applyFlash, setApplyFlash] = useState(false);
546
+ const copyTimerRef = useRef(null);
547
+ const g2tTimerRef = useRef(null);
548
+ const applyTimerRef = useRef(null);
549
+
550
+ useEffect(() => () => {
551
+ if (copyTimerRef.current) clearTimeout(copyTimerRef.current);
552
+ if (g2tTimerRef.current) clearTimeout(g2tTimerRef.current);
553
+ if (applyTimerRef.current) clearTimeout(applyTimerRef.current);
554
+ }, []);
555
+
556
+ const flash = (setter, timerRef, ms = 1600) => {
557
+ if (timerRef.current) clearTimeout(timerRef.current);
558
+ setter(true);
559
+ timerRef.current = setTimeout(() => setter(false), ms);
560
+ };
561
+
562
+ const handleCopy = useCallback(async () => {
563
+ let ok = false;
564
+ try {
565
+ if (navigator.clipboard && window.isSecureContext) {
566
+ await navigator.clipboard.writeText(femoText || '');
567
+ ok = true;
568
+ } else {
569
+ const ta = document.createElement('textarea');
570
+ ta.value = femoText || '';
571
+ ta.style.position = 'fixed';
572
+ ta.style.opacity = '0';
573
+ document.body.appendChild(ta);
574
+ ta.select();
575
+ ok = document.execCommand('copy');
576
+ document.body.removeChild(ta);
577
+ }
578
+ } catch {
579
+ ok = false;
580
+ }
581
+ if (copyTimerRef.current) clearTimeout(copyTimerRef.current);
582
+ setCopied(ok);
583
+ copyTimerRef.current = setTimeout(() => setCopied(false), 1600);
584
+ }, [femoText]);
585
+
586
+ if (!visible) return null;
587
+ return (
588
+ <>
589
+ <div
590
+ onClick={onClose}
591
+ style={{
592
+ position: 'fixed',
593
+ inset: 0,
594
+ background: 'var(--femo-mask)',
595
+ zIndex: 300,
596
+ animation: 'fadeInOverlay 0.18s ease',
597
+ }}
598
+ />
599
+ <div
600
+ style={{
601
+ position: 'fixed',
602
+ right: 0,
603
+ top: 0,
604
+ bottom: 0,
605
+ width: '88vw',
606
+ maxWidth: 420,
607
+ background: 'var(--femo-mobile-bg-2)',
608
+ borderLeft: `var(--femo-border-w) solid ${T.border}`,
609
+ zIndex: 301,
610
+ display: 'flex',
611
+ flexDirection: 'column',
612
+ animation: 'slideInFemo 0.22s cubic-bezier(0.4,0,0.2,1)',
613
+ boxShadow: '-8px 0 32px var(--femo-mask)',
614
+ }}
615
+ >
616
+ {/* 头部 */}
617
+ <div
618
+ style={{
619
+ padding: '14px 16px 10px',
620
+ borderBottom: 'var(--femo-border-w) solid var(--femo-mobile-border-strong)',
621
+ display: 'flex',
622
+ justifyContent: 'space-between',
623
+ alignItems: 'center',
624
+ flexShrink: 0,
625
+ }}
626
+ >
627
+ <span style={{ fontSize: 10, fontWeight: 800, color: 'var(--femo-neutral)', textTransform: 'uppercase', letterSpacing: '0.1em', fontFamily: 'var(--femo-font-mono)' }}>
628
+ FEMO 预览
629
+ </span>
630
+ <div style={{ display: 'flex', gap: 6, alignItems: 'center' }}>
631
+ {femoError && (
632
+ <button onClick={onRestore} style={mobChip(T.warning, true)}>恢复</button>
633
+ )}
634
+ <button
635
+ onClick={handleCopy}
636
+ style={mobChip(copied ? T.success : T.accent, copied)}
637
+ >
638
+ {copied ? '✓ 已复制' : '复制'}
639
+ </button>
640
+ <button
641
+ onClick={() => { onGraphToFemo?.(); flash(setG2tFlash, g2tTimerRef); }}
642
+ style={mobChip(g2tFlash ? T.success : T.accent, g2tFlash)}
643
+ >
644
+ {g2tFlash ? '✓ 已生成' : '图→文'}
645
+ </button>
646
+ <button
647
+ onClick={() => { onApply?.(); flash(setApplyFlash, applyTimerRef); }}
648
+ style={mobChip(
649
+ applyFlash ? (femoError ? T.danger : T.success) : T.accent,
650
+ applyFlash || femoDirty,
651
+ )}
652
+ >
653
+ {applyFlash ? (femoError ? '✕ 失败' : '✓ 已应用') : '文→图'}
654
+ </button>
655
+ <button
656
+ onClick={onClose}
657
+ style={{
658
+ background: 'var(--femo-mobile-border-strong)',
659
+ border: 'none',
660
+ borderRadius: 'var(--femo-radius-sm)',
661
+ width: 28,
662
+ height: 28,
663
+ display: 'flex',
664
+ alignItems: 'center',
665
+ justifyContent: 'center',
666
+ cursor: 'pointer',
667
+ color: 'var(--femo-neutral)',
668
+ fontSize: 14,
669
+ }}
670
+ >
671
+ ✕
672
+ </button>
673
+ </div>
674
+ </div>
675
+
676
+ {/* 错误提示 */}
677
+ {femoError && (
678
+ <div style={{ margin: '8px 12px 0', padding: '6px 10px', background: 'var(--femo-mobile-danger-soft)', border: 'var(--femo-border-w) solid var(--femo-mobile-danger-border)', borderRadius: 'var(--femo-radius-sm)', fontSize: 10, color: 'var(--femo-danger-weak)', lineHeight: 1.5 }}>
679
+ {femoError}
680
+ </div>
681
+ )}
682
+
683
+ {/* 编辑器 */}
684
+ <textarea
685
+ value={femoText}
686
+ onChange={(e) => onChange(e.target.value)}
687
+ spellCheck={false}
688
+ style={{
689
+ flex: 1,
690
+ background: 'transparent',
691
+ border: 'none',
692
+ outline: 'none',
693
+ resize: 'none',
694
+ padding: '12px 14px',
695
+ fontFamily: 'var(--femo-font-mono)',
696
+ fontSize: 10.5,
697
+ lineHeight: 1.8,
698
+ color: 'var(--femo-mobile-text-2-alt)',
699
+ touchAction: 'auto',
700
+ userSelect: 'text',
701
+ WebkitUserSelect: 'text',
702
+ }}
703
+ />
704
+ </div>
705
+ </>
706
+ );
707
+ }
708
+
709
+ // ─────────────────────────────────────────────
710
+ // Bottom Panel — Library / Project / Properties
711
+ // ─────────────────────────────────────────────
712
+
713
+ // Tab 定义
714
+ const BOTTOM_TABS = [
715
+ { id: 'library', label: '仓库' },
716
+ { id: 'project', label: '项目' },
717
+ { id: 'props', label: '属性' },
718
+ { id: 'settings', label: '设置' },
719
+ ];
720
+
721
+ function MobileBottomPanel({
722
+ activeTab,
723
+ onTabChange,
724
+ // Library props
725
+ lib,
726
+ mode,
727
+ locationPath,
728
+ allNames,
729
+ onNew,
730
+ onAdd,
731
+ onAddModule,
732
+ onAddSpecial,
733
+ onAddPosition,
734
+ onEdit,
735
+ onEditModule,
736
+ onDragStart,
737
+ // round49:四个触摸处理器全部面板级(挂在滚动容器上),落点无关——
738
+ // touchstart 用 closest('[data-femo-lib-drag]') 找拖拽目标;move/end 负责仲裁与拖拽。
739
+ onPanelTouchStart,
740
+ onLibTouchMove,
741
+ onLibTouchEnd,
742
+ onLibTouchCancel = null,
743
+ libArmedKey, // round27:长按激活拖拽的条目 key(点亮被按卡片)
744
+ htmlDraggable = false, // 手机端恒 false——draggable 卡片阻止触摸滚动
745
+ onSelectLib,
746
+ onNewModule,
747
+ // Project props
748
+ proj,
749
+ actorNames,
750
+ onProjChange,
751
+ // Props
752
+ sel,
753
+ selNode,
754
+ selEdge,
755
+ selAction,
756
+ nodes,
757
+ edges,
758
+ backEdges,
759
+ nodeStates,
760
+ actionStore,
761
+ onDeleteNode,
762
+ onDeleteEdge,
763
+ onCondChange,
764
+ onEditAction,
765
+ onEnterModuleNode,
766
+ libSel,
767
+ // Settings(设置 tab:主题切换 + 新建 SOUL + 调试窗口)
768
+ themeName,
769
+ onCycleTheme,
770
+ onOpenSoul,
771
+ // Debug(调试窗口:与桌面端共用 debugLog 数据面)
772
+ debugLog = [],
773
+ onClearDebug,
774
+ compilerLog = [],
775
+ onClearCompiler,
776
+ femogenLog = [],
777
+ onClearFemogen,
778
+ hostLog = [],
779
+ onClearHost,
780
+ onCompileDebug,
781
+ compilingDebug = false,
782
+ }) {
783
+ const scrollRef = useRef(null);
784
+ // 调试浮层开关(面板内 absolute inset:0 —— 与面板同高,不挡画布)
785
+ const [debugOpen, setDebugOpen] = useState(false);
786
+ const WIN_H = typeof window !== 'undefined' ? window.innerHeight : 700;
787
+ const MIN_H = 100;
788
+ const MAX_H = Math.round(WIN_H * 0.72);
789
+ const DEFAULT_H = Math.round(WIN_H * 0.28);
790
+ const [panelH, setPanelH] = useState(DEFAULT_H);
791
+ const dragHandleRef = useRef(null);
792
+ const dragStartRef = useRef(null); // { y, h }
793
+
794
+ // 切换 tab 时滚回顶部
795
+ useEffect(() => {
796
+ if (scrollRef.current) scrollRef.current.scrollTop = 0; }, [activeTab]);
797
+
798
+ // round46/49:仓库触摸四事件全挂**原生**监听——React 根级委派是 passive 的,
799
+ // armed 状态的 preventDefault 在那里无效。touchstart 用 passive:true(我们从不
800
+ // 在 start 阶段拦截,主动向 WebKit 声明"不挡滚动",换取最快滚动启动路径);
801
+ // move/end 保持非 passive(armed 拖拽需要 preventDefault)。
802
+ useEffect(() => {
803
+ const el = scrollRef.current;
804
+ if (!el || !onLibTouchMove || !onLibTouchEnd) return;
805
+ if (onPanelTouchStart) el.addEventListener('touchstart', onPanelTouchStart, { passive: true });
806
+ el.addEventListener('touchmove', onLibTouchMove, { passive: false });
807
+ el.addEventListener('touchend', onLibTouchEnd, { passive: false });
808
+ el.addEventListener('touchcancel', onLibTouchCancel || (() => {}), { passive: true });
809
+ return () => {
810
+ if (onPanelTouchStart) el.removeEventListener('touchstart', onPanelTouchStart);
811
+ el.removeEventListener('touchmove', onLibTouchMove);
812
+ el.removeEventListener('touchend', onLibTouchEnd);
813
+ el.removeEventListener('touchcancel', onLibTouchCancel || (() => {}));
814
+ };
815
+ }, [onPanelTouchStart, onLibTouchMove, onLibTouchEnd, onLibTouchCancel]);
816
+
817
+ // 鼠标拖拽(桌面调试用)
818
+ const onHandleMouseDown = useCallback((e) => {
819
+ e.preventDefault();
820
+ dragStartRef.current = { y: e.clientY, h: panelH };
821
+ const onMove = (mv) => {
822
+ const delta = dragStartRef.current.y - mv.clientY;
823
+ setPanelH(Math.max(MIN_H, Math.min(MAX_H, dragStartRef.current.h + delta)));
824
+ };
825
+ const onUp = () => {
826
+ window.removeEventListener('mousemove', onMove);
827
+ window.removeEventListener('mouseup', onUp);
828
+ };
829
+ window.addEventListener('mousemove', onMove);
830
+ window.addEventListener('mouseup', onUp);
831
+ }, [panelH]);
832
+
833
+ // 触摸拖拽
834
+ const onHandleTouchStart = useCallback((e) => {
835
+ e.stopPropagation();
836
+ const t = e.touches[0];
837
+ dragStartRef.current = { y: t.clientY, h: panelH };
838
+ }, [panelH]);
839
+
840
+ const onHandleTouchMove = useCallback((e) => {
841
+ e.stopPropagation();
842
+ e.preventDefault();
843
+ const t = e.touches[0];
844
+ const delta = dragStartRef.current.y - t.clientY;
845
+ setPanelH(Math.max(MIN_H, Math.min(MAX_H, dragStartRef.current.h + delta)));
846
+ }, []);
847
+
848
+ const onHandleTouchEnd = useCallback((e) => {
849
+ e.stopPropagation();
850
+ dragStartRef.current = null;
851
+ }, []);
852
+
853
+ return (
854
+ <div
855
+ style={{
856
+ height: panelH,
857
+ background: T.surface,
858
+ borderTop: `var(--femo-border-w) solid ${T.border}`,
859
+ display: 'flex',
860
+ flexDirection: 'column',
861
+ flexShrink: 0,
862
+ position: 'relative',
863
+ zIndex: 50,
864
+ transition: dragStartRef.current ? 'none' : 'height 0.12s ease',
865
+ }}
866
+ >
867
+ {/* 拖拽手柄 */}
868
+ <div
869
+ ref={dragHandleRef}
870
+ onMouseDown={onHandleMouseDown}
871
+ onTouchStart={onHandleTouchStart}
872
+ onTouchMove={onHandleTouchMove}
873
+ onTouchEnd={onHandleTouchEnd}
874
+ style={{
875
+ position: 'absolute',
876
+ top: 0,
877
+ left: 0,
878
+ right: 0,
879
+ height: 20,
880
+ display: 'flex',
881
+ alignItems: 'center',
882
+ justifyContent: 'center',
883
+ cursor: 'ns-resize',
884
+ zIndex: 10,
885
+ touchAction: 'none',
886
+ userSelect: 'none',
887
+ }}
888
+ >
889
+ <div
890
+ style={{
891
+ width: 36,
892
+ height: 4,
893
+ borderRadius: 'var(--femo-radius-xs)',
894
+ background: T.borderLight,
895
+ opacity: 0.7,
896
+ marginTop: 6,
897
+ }}
898
+ />
899
+ </div>
900
+
901
+ {/* Tab bar(留出手柄空间)*/}
902
+ <div
903
+ style={{
904
+ display: 'flex',
905
+ borderBottom: `var(--femo-border-w) solid ${T.border}`,
906
+ flexShrink: 0,
907
+ background: T.bg,
908
+ marginTop: 18,
909
+ }}
910
+ >
911
+ {BOTTOM_TABS.map((t) => (
912
+ <button
913
+ key={t.id}
914
+ onClick={() => onTabChange(t.id)}
915
+ style={{
916
+ flex: 1,
917
+ background: 'none',
918
+ border: 'none',
919
+ borderBottom: activeTab === t.id ? `var(--femo-border-w-selected) solid ${T.accent}` : 'var(--femo-border-w-selected) solid transparent',
920
+ padding: '7px 0',
921
+ fontSize: 11.5,
922
+ fontWeight: activeTab === t.id ? 800 : 500,
923
+ color: activeTab === t.id ? T.accent : T.textMuted,
924
+ cursor: 'pointer',
925
+ fontFamily: 'var(--femo-font-sans)',
926
+ letterSpacing: '0.02em',
927
+ transition: 'color 0.15s, border-color 0.15s',
928
+ }}
929
+ >
930
+ {t.label}
931
+ {t.id === 'props' && (sel || libSel) && (
932
+ <span style={{ display: 'inline-block', width: 5, height: 5, borderRadius: 'var(--femo-radius-pill)', background: T.accent, marginLeft: 4, verticalAlign: 'middle' }} />
933
+ )}
934
+ </button>
935
+ ))}
936
+ </div>
937
+
938
+ {/* Scrollable content — 直接复用桌面端原有组件 */}
939
+ <div
940
+ ref={scrollRef}
941
+ className="femo-bottom-scroll"
942
+ style={{
943
+ flex: 1,
944
+ overflowY: 'auto',
945
+ padding: '10px 14px 12px',
946
+ animation: 'fadePanel 0.15s ease',
947
+ minHeight: 0,
948
+ // 让桌面端组件在深色背景下可读
949
+ '--text-primary': T.textPrimary,
950
+ color: 'var(--femo-text-1)',
951
+ background: 'transparent', /* round12/15:去掉圆角卡片底,融入壳背景 */
952
+ }}
953
+ >
954
+ {activeTab === 'library' && (
955
+ <LibPanel
956
+ cardLayout="grid3"
957
+ lib={lib}
958
+ mode={mode}
959
+ locationPath={locationPath}
960
+ allNames={allNames}
961
+ onNew={onNew}
962
+ onAdd={onAdd}
963
+ onAddModule={onAddModule}
964
+ onAddSpecial={onAddSpecial}
965
+ onAddPosition={onAddPosition}
966
+ onEdit={onEdit}
967
+ onEditModule={onEditModule}
968
+ onDragStart={onDragStart}
969
+ armedKey={libArmedKey}
970
+ htmlDraggable={htmlDraggable}
971
+ onSelectLib={onSelectLib}
972
+ onNewModule={onNewModule}
973
+ />
974
+ )}
975
+ {activeTab === 'project' && (
976
+ <ProjPanel
977
+ proj={proj}
978
+ actorNames={actorNames}
979
+ onChange={onProjChange}
980
+ />
981
+ )}
982
+ {activeTab === 'props' && (
983
+ <MobilePropsPanel
984
+ sel={sel}
985
+ selNode={selNode}
986
+ selEdge={selEdge}
987
+ selAction={selAction}
988
+ nodes={nodes}
989
+ edges={edges}
990
+ backEdges={backEdges}
991
+ nodeStates={nodeStates}
992
+ actionStore={actionStore}
993
+ onDeleteNode={onDeleteNode}
994
+ onDeleteEdge={onDeleteEdge}
995
+ onCondChange={onCondChange}
996
+ onEditAction={onEditAction}
997
+ onEnterModuleNode={onEnterModuleNode}
998
+ libSel={libSel}
999
+ lib={lib}
1000
+ />
1001
+ )}
1002
+ {activeTab === 'settings' && (
1003
+ <div>
1004
+ <div style={sectionLabel}>设置</div>
1005
+ {/* 三键同构(2026-09-08 r2):等宽 flex:1 均衡排布 + FA 图标 + 32px 芯片高度
1006
+ (对齐标题栏 MobileIconBtn 家族);图标 flexShrink:0、文字省略号兜底,
1007
+ 长主题名(跟随 DSH)不挤爆布局。红点内移(overflow:hidden 会裁掉出界
1008
+ 部分):调试键有错时按钮右上角提示。 */}
1009
+ <div style={{ display: 'flex', alignItems: 'stretch', gap: 8, marginTop: 8 }}>
1010
+ <button
1011
+ onClick={onCycleTheme}
1012
+ title={`主题:点击切换(当前 ${themeName})`}
1013
+ style={mobSettingBtn}
1014
+ className="femo-mob-setting-btn"
1015
+ >
1016
+ <FaPalette size={12} style={{ flexShrink: 0 }} />
1017
+ <span style={mobSettingBtnText}>{themeName}</span>
1018
+ </button>
1019
+ <button
1020
+ onClick={onOpenSoul}
1021
+ title="新建 SOUL"
1022
+ style={mobSettingBtn}
1023
+ className="femo-mob-setting-btn"
1024
+ >
1025
+ <FaUserPlus size={12} style={{ flexShrink: 0 }} />
1026
+ <span style={mobSettingBtnText}>新建 SOUL</span>
1027
+ </button>
1028
+ <button
1029
+ onClick={() => setDebugOpen(true)}
1030
+ title="调试窗口:后端运行信息与报错的常驻日志流"
1031
+ style={mobSettingBtn}
1032
+ className="femo-mob-setting-btn"
1033
+ >
1034
+ <FaTerminal size={12} style={{ flexShrink: 0 }} />
1035
+ <span style={mobSettingBtnText}>调试</span>
1036
+ {debugLog.some((e) => e.level === 'error') && (
1037
+ <span
1038
+ style={{
1039
+ position: 'absolute',
1040
+ top: 3,
1041
+ right: 3,
1042
+ width: 8,
1043
+ height: 8,
1044
+ borderRadius: 'var(--femo-radius-pill)',
1045
+ background: 'var(--femo-danger)',
1046
+ border: '1.5px solid var(--femo-bg)',
1047
+ }}
1048
+ />
1049
+ )}
1050
+ </button>
1051
+ </div>
1052
+ </div>
1053
+ )}
1054
+ </div>
1055
+
1056
+ {/* ── 调试窗口浮层:从拖动手柄下方开始(top:20)——盖住 tab 栏与内容区,
1057
+ 但手柄保持可见可拖:调试开着也能调整底部面板高度(2026-09-08)。── */}
1058
+ {debugOpen && (
1059
+ <div style={{ position: 'absolute', inset: '20px 0 0 0', zIndex: 60 }}>
1060
+ <DebugPanel
1061
+ entries={debugLog}
1062
+ onClose={() => setDebugOpen(false)}
1063
+ onClear={onClearDebug}
1064
+ compilerEntries={compilerLog}
1065
+ onClearCompiler={onClearCompiler}
1066
+ femogenEntries={femogenLog}
1067
+ onClearFemogen={onClearFemogen}
1068
+ hostEntries={hostLog}
1069
+ onClearHost={onClearHost}
1070
+ onCompile={onCompileDebug}
1071
+ compiling={compilingDebug}
1072
+ />
1073
+ </div>
1074
+ )}
1075
+ </div>
1076
+ );
1077
+ }
1078
+
1079
+ // ─────────────────────────────────────────────
1080
+ // MobileLibPanel — 仓库面板(横向卡片列表)
1081
+ // ─────────────────────────────────────────────
1082
+ function MobileLibPanel({ lib, mode, locationPath, allNames, onNew, onAdd, onAddModule, onAddSpecial, onAddPosition, onEdit, onEditModule, onSelectLib, onNewModule }) {
1083
+ const [newModName, setNewModName] = useState('');
1084
+
1085
+ const displayActions = (lib.actions || []).filter((a) => {
1086
+ if (!a.path) return false;
1087
+ if (a.path.length === 1 && a.path[0] === 'mainflow') return true;
1088
+ return locationPath.every((seg, i) => a.path[i] === seg);
1089
+ });
1090
+ const displayModules = (lib.modules || []).filter(
1091
+ (m) =>
1092
+ m.path &&
1093
+ locationPath.every((seg, i) => m.path[i] === seg) &&
1094
+ m.path.length === locationPath.length + 1
1095
+ );
1096
+ const specialNodes =
1097
+ mode === 'mainflow'
1098
+ ? [
1099
+ { t: 'FOR', c: 'var(--femo-primary-strong)' },
1100
+ { t: 'PAR', c: 'var(--femo-special-par)' },
1101
+ { t: 'END', c: 'var(--femo-danger)' },
1102
+ ]
1103
+ : [
1104
+ { t: 'FOR', c: 'var(--femo-primary-strong)' },
1105
+ { t: 'PAR', c: 'var(--femo-special-par)' },
1106
+ { t: 'BREAK', c: 'var(--femo-warning)' },
1107
+ { t: 'OUT', c: 'var(--femo-danger)' },
1108
+ ];
1109
+
1110
+ return (
1111
+ <div>
1112
+ {/* Actions 行 */}
1113
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
1114
+ <span style={sectionLabel}>Actions</span>
1115
+ <button onClick={onNew} style={{ ...mobBtnP, padding: '3px 10px', fontSize: 10 }}>+ 新建</button>
1116
+ </div>
1117
+ <div style={{ display: 'flex', gap: 7, overflowX: 'auto', paddingBottom: 4, WebkitOverflowScrolling: 'touch', touchAction: 'pan-x' }}>
1118
+ {displayActions.length === 0 ? (
1119
+ <div style={{ fontSize: 11, color: T.textMuted, padding: '4px 0' }}>暂无 Action</div>
1120
+ ) : displayActions.map((a) => {
1121
+ const { c, bg } = ti(a.executorType);
1122
+ return (
1123
+ <div
1124
+ key={a.id}
1125
+ onClick={() => onSelectLib?.('action', a.id)}
1126
+ style={{
1127
+ background: 'var(--femo-node-bg)',
1128
+ borderRadius: 'var(--femo-radius-md)',
1129
+ border: `var(--femo-node-border-w) solid var(--femo-node-border)`,
1130
+ borderLeft: `var(--femo-border-w-accent) solid ${c}`,
1131
+ padding: '6px 9px',
1132
+ minWidth: 100,
1133
+ maxWidth: 140,
1134
+ flexShrink: 0,
1135
+ cursor: 'pointer',
1136
+ }}
1137
+ >
1138
+ <div style={{ fontSize: 11.5, fontWeight: 700, color: T.textPrimary, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', marginBottom: 3 }}>
1139
+ {a.name}
1140
+ </div>
1141
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 4 }}>
1142
+ <span style={{ fontSize: 9.5, fontWeight: 700, color: c, fontFamily: 'var(--femo-font-mono)' }}>@{a.executorType}</span>
1143
+ <button
1144
+ onClick={(e) => { e.stopPropagation(); onAdd(a); }}
1145
+ style={{ background: 'var(--femo-btn-primary)', border: 'none', borderRadius: 'var(--femo-radius-sm)', color: 'var(--femo-on-accent)', fontSize: 9, fontWeight: 700, padding: '1px 6px', cursor: 'pointer' }}
1146
+ >
1147
+ +
1148
+ </button>
1149
+ </div>
1150
+ </div>
1151
+ );
1152
+ })}
1153
+ </div>
1154
+
1155
+ {/* Modules */}
1156
+ {displayModules.length > 0 && (
1157
+ <>
1158
+ <div style={{ ...sectionLabel, marginTop: 10, marginBottom: 6 }}>Modules</div>
1159
+ <div style={{ display: 'flex', gap: 7, overflowX: 'auto', paddingBottom: 4, touchAction: 'pan-x' }}>
1160
+ {displayModules.map((m) => (
1161
+ <div
1162
+ key={m.id}
1163
+ onClick={() => onSelectLib?.('module', m.id)}
1164
+ style={{
1165
+ background: 'var(--femo-node-bg)',
1166
+ borderRadius: 'var(--femo-radius-md)',
1167
+ border: `var(--femo-node-border-w) solid var(--femo-node-border)`,
1168
+ borderLeft: 'var(--femo-border-w-accent) solid var(--femo-tag-bg)',
1169
+ padding: '6px 9px',
1170
+ minWidth: 100,
1171
+ flexShrink: 0,
1172
+ cursor: 'pointer',
1173
+ }}
1174
+ >
1175
+ <div style={{ fontSize: 11, fontWeight: 700, color: T.textPrimary, marginBottom: 5 }}>&{m.name}</div>
1176
+ <div style={{ display: 'flex', gap: 4 }}>
1177
+ <button
1178
+ onClick={(e) => { e.stopPropagation(); onAddModule(m); }}
1179
+ style={{ background: 'var(--femo-btn-primary)', border: 'none', borderRadius: 'var(--femo-radius-sm)', color: 'var(--femo-on-accent)', fontSize: 9, fontWeight: 700, padding: '2px 6px', cursor: 'pointer', flex: 1 }}
1180
+ >
1181
+ +画布
1182
+ </button>
1183
+ <button
1184
+ onClick={(e) => { e.stopPropagation(); onEditModule?.(m); }}
1185
+ style={{ background: 'var(--femo-primary)', border: 'none', borderRadius: 'var(--femo-radius-sm)', color: 'var(--femo-on-accent)', fontSize: 9, fontWeight: 700, padding: '2px 6px', cursor: 'pointer', flex: 1 }}
1186
+ >
1187
+ 进入
1188
+ </button>
1189
+ </div>
1190
+ </div>
1191
+ ))}
1192
+ </div>
1193
+ </>
1194
+ )}
1195
+
1196
+ {/* 新建模块 */}
1197
+ <div style={{ display: 'flex', gap: 6, marginTop: 10, alignItems: 'center' }}>
1198
+ <input
1199
+ value={newModName}
1200
+ onChange={(e) => setNewModName(e.target.value)}
1201
+ placeholder="新模块名"
1202
+ style={{ ...mobInp, flex: 1, fontSize: 11 }}
1203
+ />
1204
+ <button
1205
+ onClick={() => {
1206
+ const name = newModName.trim();
1207
+ if (name && (!allNames?.has || !allNames.has(name))) {
1208
+ onNewModule(name);
1209
+ setNewModName('');
1210
+ }
1211
+ }}
1212
+ style={{ ...mobBtnP, padding: '5px 10px', fontSize: 10, flexShrink: 0 }}
1213
+ >
1214
+ 创建
1215
+ </button>
1216
+ </div>
1217
+
1218
+ {/* 特殊节点 + POSITION */}
1219
+ <div style={{ marginTop: 10 }}>
1220
+ <div style={sectionLabel}>特殊节点</div>
1221
+ <div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', marginTop: 6 }}>
1222
+ {specialNodes.map((s) => {
1223
+ const spKey = { START: 'start', IN: 'start', END: 'end', OUT: 'end', BREAK: 'break', FOR: 'for', PAR: 'par' }[s.t] || 'for';
1224
+ return (
1225
+ <button
1226
+ key={s.t}
1227
+ onClick={() => onAddSpecial(s.t)}
1228
+ style={{
1229
+ background: `var(--femo-sp-${spKey}-bg)`,
1230
+ border: `var(--femo-border-w) solid color-mix(in srgb, ${s.c} 50%, var(--femo-node-bg))`,
1231
+ borderRadius: 'var(--femo-radius-sm)',
1232
+ padding: '4px 10px',
1233
+ fontSize: 10.5,
1234
+ fontWeight: 800,
1235
+ color: s.c,
1236
+ cursor: 'pointer',
1237
+ fontFamily: 'var(--femo-font-mono)',
1238
+ }}
1239
+ >
1240
+ [{s.t}]
1241
+ </button>
1242
+ );
1243
+ })}
1244
+ <button
1245
+ onClick={onAddPosition}
1246
+ style={{
1247
+ background: 'var(--femo-neutral-faint)',
1248
+ border: 'var(--femo-border-w) solid var(--femo-neutral-border)',
1249
+ borderRadius: 'var(--femo-radius-sm)',
1250
+ padding: '4px 10px',
1251
+ fontSize: 10.5,
1252
+ fontWeight: 700,
1253
+ color: 'var(--femo-neutral)',
1254
+ cursor: 'pointer',
1255
+ fontFamily: 'var(--femo-font-mono)',
1256
+ }}
1257
+ >
1258
+ POSITION
1259
+ </button>
1260
+ </div>
1261
+ </div>
1262
+ </div>
1263
+ );
1264
+ }
1265
+
1266
+ // ─────────────────────────────────────────────
1267
+ // MobileProjPanel — 精简项目信息
1268
+ // ─────────────────────────────────────────────
1269
+ function MobileProjPanel({ proj, actorNames, onChange }) {
1270
+ if (!proj) return null;
1271
+ const u = (x) => onChange({ ...proj, ...x });
1272
+ // dsh 可用模型列表(source 下拉数据源)
1273
+ const [models, modelErr] = useModelList();
1274
+ return (
1275
+ <div>
1276
+ <div style={{ display: 'flex', gap: 8, marginBottom: 8 }}>
1277
+ <div style={{ flex: 2 }}>
1278
+ <div style={fieldLabel}>项目名称</div>
1279
+ <input value={proj.name || ''} onChange={(e) => u({ name: e.target.value })} style={mobInp} />
1280
+ </div>
1281
+ <div style={{ flex: 1 }}>
1282
+ <div style={fieldLabel}>Version</div>
1283
+ <input value={proj.version || ''} onChange={(e) => u({ version: e.target.value })} placeholder="1.0" style={mobInp} />
1284
+ </div>
1285
+ </div>
1286
+ <div style={{ display: 'flex', gap: 8, marginBottom: 8 }}>
1287
+ <div style={{ flex: 1 }}>
1288
+ <div style={fieldLabel}>Database</div>
1289
+ <input value={proj.database || ''} onChange={(e) => u({ database: e.target.value })} placeholder="memory/..." style={mobInp} />
1290
+ </div>
1291
+ <div style={{ flex: 1 }}>
1292
+ <div style={fieldLabel}>Session</div>
1293
+ <input value={proj.session || ''} onChange={(e) => u({ session: e.target.value })} placeholder="new" style={mobInp} />
1294
+ </div>
1295
+ </div>
1296
+
1297
+ {/* Actors */}
1298
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
1299
+ <span style={sectionLabel}>Actors</span>
1300
+ <button
1301
+ onClick={() => u({ actors: [...(proj.actors || []), { name: '', type: 'ai', soul: '', source: '', tools: null, thinking: '' }] })}
1302
+ style={{ ...mobBtnP, padding: '2px 8px', fontSize: 10 }}
1303
+ >
1304
+ +
1305
+ </button>
1306
+ </div>
1307
+ {(proj.actors || []).map((a, i) => {
1308
+ const upd = (x) => u({ actors: proj.actors.map((p, j) => (j === i ? { ...p, ...x } : p)) });
1309
+ return (
1310
+ <div key={i} style={{ display: 'flex', gap: 5, marginBottom: 5, alignItems: 'center' }}>
1311
+ <select value={a.type} onChange={(e) => upd({ type: e.target.value })} style={{ ...mobInp, width: 60, fontSize: 10 }}>
1312
+ <option value="ai">ai</option>
1313
+ <option value="human">human</option>
1314
+ </select>
1315
+ <input
1316
+ value={a.name}
1317
+ onChange={(e) => { let v = e.target.value.trim(); if (v && !v.startsWith('@')) v = '@' + v; upd({ name: v }); }}
1318
+ placeholder="@Alice"
1319
+ style={{ ...mobInp, flex: 1, fontSize: 11 }}
1320
+ />
1321
+ {a.type === 'ai' && models ? (
1322
+ <select
1323
+ value={a.source || ''}
1324
+ onChange={(e) => upd({ source: e.target.value })}
1325
+ style={{ ...mobInp, flex: 1, fontSize: 10 }}
1326
+ >
1327
+ {sourceOptions(models, a.source).map((o) => (
1328
+ <option key={o.value} value={o.value}>
1329
+ {o.label}
1330
+ </option>
1331
+ ))}
1332
+ </select>
1333
+ ) : (
1334
+ <input
1335
+ value={a.source}
1336
+ onChange={(e) => upd({ source: e.target.value })}
1337
+ placeholder={a.type === 'ai' ? (modelErr || 'deepseek') : '数字ID'}
1338
+ style={{ ...mobInp, flex: 1, fontSize: 11 }}
1339
+ />
1340
+ )}
1341
+ <button onClick={() => u({ actors: proj.actors.filter((_, j) => j !== i) })} style={{ background: 'none', border: 'none', color: 'var(--femo-danger-weak)', fontSize: 16, cursor: 'pointer', flexShrink: 0, padding: 2 }}>×</button>
1342
+ </div>
1343
+ );
1344
+ })}
1345
+
1346
+ {/* Vars */}
1347
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6, marginTop: 8 }}>
1348
+ <span style={sectionLabel}>Vars</span>
1349
+ <button onClick={() => u({ vars: [...(proj.vars || []), { name: '', defaultValue: '' }] })} style={{ ...mobBtnP, padding: '2px 8px', fontSize: 10 }}>+</button>
1350
+ </div>
1351
+ {(proj.vars || []).map((v, i) => (
1352
+ <div key={i} style={{ display: 'flex', gap: 5, marginBottom: 5, alignItems: 'center' }}>
1353
+ <input value={v.name} onChange={(e) => { const upd = [...proj.vars]; upd[i] = { ...upd[i], name: e.target.value }; u({ vars: upd }); }} placeholder="变量名" style={{ ...mobInp, flex: 1 }} />
1354
+ <input value={v.defaultValue} onChange={(e) => { const upd = [...proj.vars]; upd[i] = { ...upd[i], defaultValue: e.target.value }; u({ vars: upd }); }} placeholder="默认值" style={{ ...mobInp, flex: 2 }} />
1355
+ <button onClick={() => u({ vars: proj.vars.filter((_, j) => j !== i) })} style={{ background: 'none', border: 'none', color: 'var(--femo-danger-weak)', fontSize: 16, cursor: 'pointer', flexShrink: 0, padding: 2 }}>×</button>
1356
+ </div>
1357
+ ))}
1358
+ </div>
1359
+ );
1360
+ }
1361
+
1362
+ // ─────────────────────────────────────────────
1363
+ // MobilePropsPanel — 节点/边属性
1364
+ // ─────────────────────────────────────────────
1365
+ function MobilePropsPanel({ sel, selNode, selEdge, selAction, nodes, edges, backEdges, nodeStates, actionStore, onDeleteNode, onDeleteEdge, onCondChange, onEditAction, onEnterModuleNode, libSel, lib }) {
1366
+ if (sel?.type === 'node' && selNode) {
1367
+ const ns = nodeStates?.[selNode.id] || {};
1368
+ const action = selAction;
1369
+ const isModuleNode = selNode.type === 'module' && !!selNode.modDef;
1370
+ const { c } = action ? ti(action.executorType) : { c: 'var(--femo-neutral)' };
1371
+ return (
1372
+ <div>
1373
+ <div style={{ display: 'flex', alignItems: 'center', gap: 7, marginBottom: 10 }}>
1374
+ {action && (
1375
+ <span style={{ background: `var(--femo-badge-bg-${['ai','human','mind','func','assign','notice'].includes(action.executorType) ? action.executorType : 'ai'})`, color: `var(--femo-badge-fg-${['ai','human','mind','func','assign','notice'].includes(action.executorType) ? action.executorType : 'ai'})`, borderRadius: 'var(--femo-radius-sm)', padding: '2px 7px', fontSize: 10, fontWeight: 800, fontFamily: 'var(--femo-font-mono)' }}>
1376
+ @{action.executorType}
1377
+ </span>
1378
+ )}
1379
+ <span style={{ fontSize: 13.5, fontWeight: 800, color: T.textPrimary }}>{action?.name || selNode.specialType || selNode.label || '节点'}</span>
1380
+ </div>
1381
+ {selNode.label && <MobPropRow k="节点名" v={String(selNode.label).replace(/[\[\]]/g, '')} />}
1382
+ {action && (
1383
+ <>
1384
+ {action.executorActor && <MobPropRow k="执行者" v={action.executorActor} />}
1385
+ {action.scope && <MobPropRow k="Scope" v={action.scope} />}
1386
+ {action.outVars && <MobPropRow k="出参" v={String(action.outVars)} />}
1387
+ </>
1388
+ )}
1389
+ {ns.status && <MobPropRow k="状态" v={ns.status} />}
1390
+ <div style={{ display: 'flex', gap: 7, marginTop: 10 }}>
1391
+ {action && (
1392
+ <button onClick={onEditAction} style={{ ...mobBtnP, flex: 1, fontSize: 11, padding: '6px 0' }}>编辑 Action</button>
1393
+ )}
1394
+ {isModuleNode && (
1395
+ <button
1396
+ onClick={() => onEnterModuleNode?.(selNode.id)}
1397
+ style={{ ...mobBtnP, flex: 1, fontSize: 11, padding: '6px 0', background: 'var(--femo-primary)' }}
1398
+ >进入子画布</button>
1399
+ )}
1400
+ <button onClick={onDeleteNode} style={{ ...mobBtnDanger, flex: 1, fontSize: 11, padding: '6px 0' }}>删除节点</button>
1401
+ </div>
1402
+ </div>
1403
+ );
1404
+ }
1405
+ if (sel?.type === 'edge' && selEdge) {
1406
+ const isBack = backEdges?.has(selEdge.id);
1407
+ const inEdges = edges.filter((e) => e.tgt === selEdge.tgt && !backEdges?.has(e.id));
1408
+ return (
1409
+ <div>
1410
+ <div style={{ fontSize: 12, fontWeight: 700, color: T.textPrimary, marginBottom: 8 }}>连线属性</div>
1411
+ {isBack && <div style={{ fontSize: 10, color: 'var(--femo-primary-strong)', fontWeight: 700, background: 'var(--femo-primary-soft-faint)', borderRadius: 'var(--femo-radius-sm)', padding: '3px 7px', marginBottom: 6 }}>回环检测</div>}
1412
+ {inEdges.length > 1 && <div style={{ fontSize: 10, color: T.warning, fontWeight: 700, marginBottom: 6 }}>Join 节点 ({inEdges.length} 入口)</div>}
1413
+ <div style={fieldLabel}>if 条件</div>
1414
+ <input
1415
+ value={selEdge.cond || ''}
1416
+ onChange={(e) => onCondChange(e.target.value)}
1417
+ placeholder="留空 = 无条件"
1418
+ style={{ ...mobInp, marginBottom: 10 }}
1419
+ />
1420
+ <button onClick={onDeleteEdge} style={{ ...mobBtnDanger, width: '100%', fontSize: 11, padding: '6px 0' }}>删除连线</button>
1421
+ </div>
1422
+ );
1423
+ }
1424
+ if (libSel) {
1425
+ let item = null;
1426
+ if (libSel.type === 'action') item = lib?.actions?.find((a) => a.id === libSel.id);
1427
+ else if (libSel.type === 'module') item = lib?.modules?.find((m) => m.id === libSel.id);
1428
+ if (item) {
1429
+ return (
1430
+ <div>
1431
+ <div style={{ fontSize: 13, fontWeight: 700, color: T.textPrimary, marginBottom: 8 }}>
1432
+ {libSel.type === 'module' ? `&${item.name}` : item.name}
1433
+ </div>
1434
+ {libSel.type === 'action' && (
1435
+ <>
1436
+ <MobPropRow k="类型" v={`@${item.executorType}`} />
1437
+ {item.executorActor && <MobPropRow k="执行者" v={item.executorActor} />}
1438
+ </>
1439
+ )}
1440
+ </div>
1441
+ );
1442
+ }
1443
+ }
1444
+ return (
1445
+ <div style={{ color: T.textMuted, fontSize: 12, lineHeight: 1.8, paddingTop: 4 }}>
1446
+ 点击节点或连线查看属性
1447
+ <br />
1448
+ <span style={{ fontSize: 10.5, color: T.textMuted }}>双击节点可编辑;双击模块节点进入其子画布</span>
1449
+ </div>
1450
+ );
1451
+ }
1452
+
1453
+ function MobPropRow({ k, v }) {
1454
+ return (
1455
+ <div style={{ display: 'flex', gap: 8, fontSize: 11.5, marginBottom: 5 }}>
1456
+ <span style={{ color: T.textMuted, minWidth: 44, flexShrink: 0 }}>{k}</span>
1457
+ <span style={{ color: T.textPrimary, fontFamily: 'var(--femo-font-mono)', fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{v}</span>
1458
+ </div>
1459
+ );
1460
+ }
1461
+
1462
+ // ─────────────────────────────────────────────
1463
+ // BubbleOverlay 手机适配版
1464
+ // ─────────────────────────────────────────────
1465
+ function MobileBubbleOverlay({ bubbleOverlay, nodes, nodeStates, actionStore, onClose, submitHumanInput }) {
1466
+ if (!bubbleOverlay) return null;
1467
+ const node = nodes.find((n) => n.id === bubbleOverlay.nodeId);
1468
+ if (!node || node.type !== 'action') return null;
1469
+ const action = actionStore?.find((a) => a.id === node.actionId);
1470
+ const ns = nodeStates[node.id] || {};
1471
+ // mind 节点按运行时 node_type 判断(node_start 事件写入 ns.type):
1472
+ // 执行者运行时才确定(可能是变量赋值),静态 executorType 无法预判;
1473
+ // 未运行(ns.type 空)时回退到静态 executorType。
1474
+ const runType = ns.type || action?.executorType;
1475
+ const isAI = runType === 'ai';
1476
+ const isHuman = runType === 'human';
1477
+ const isStreaming = ns.status === 'ai_streaming';
1478
+ const { c } = ti(action?.executorType) || { c: 'var(--femo-neutral)' };
1479
+ const scrollRef = useRef(null);
1480
+
1481
+ useEffect(() => {
1482
+ const el = scrollRef.current;
1483
+ if (!el) return;
1484
+ el.scrollTop = el.scrollHeight;
1485
+ }, [ns.streamingText, ns.output]);
1486
+
1487
+ return (
1488
+ <>
1489
+ <div
1490
+ onClick={onClose}
1491
+ style={{ position: 'fixed', inset: 0, background: 'var(--femo-mask-heavy)', zIndex: 500, animation: 'fadeInOverlay 0.18s ease' }}
1492
+ />
1493
+ <div
1494
+ style={{
1495
+ position: 'fixed',
1496
+ top: '50%',
1497
+ left: '50%',
1498
+ transform: 'translate(-50%, -50%)',
1499
+ width: 'min(92vw, 460px)',
1500
+ maxHeight: '78vh',
1501
+ background: 'var(--femo-surface)',
1502
+ borderRadius: 'var(--femo-radius-xl)',
1503
+ boxShadow: '0 24px 64px var(--femo-mask-soft)',
1504
+ border: `var(--femo-border-w-selected) solid ${c}`,
1505
+ fontFamily: 'var(--femo-font-sans)',
1506
+ zIndex: 501,
1507
+ display: 'flex',
1508
+ flexDirection: 'column',
1509
+ overflow: 'hidden',
1510
+ animation: 'popIn 0.2s cubic-bezier(0.34,1.56,0.64,1)',
1511
+ }}
1512
+ >
1513
+ {/* 头部 */}
1514
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '14px 16px', borderBottom: 'var(--femo-border-w) solid var(--femo-border)', flexShrink: 0 }}>
1515
+ <div style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
1516
+ <span style={{ background: c + '18', color: c, borderRadius: 'var(--femo-radius-sm)', padding: '2px 7px', fontSize: 10, fontWeight: 800, fontFamily: 'var(--femo-font-mono)' }}>
1517
+ @{action?.executorType || '?'}
1518
+ </span>
1519
+ <span style={{ fontWeight: 800, color: 'var(--femo-text-1)', fontSize: 15 }}>{action?.name || 'Node'}</span>
1520
+ </div>
1521
+ <button onClick={(e) => { e.stopPropagation(); onClose(); }} style={{ background: 'var(--femo-bg-2)', border: 'none', fontSize: 15, cursor: 'pointer', color: 'var(--femo-text-2-alt)', borderRadius: 'var(--femo-radius-md)', width: 30, height: 30, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>✕</button>
1522
+ </div>
1523
+
1524
+ {/* 内容 */}
1525
+ <div ref={scrollRef} style={{ flex: 1, overflowY: 'auto', padding: '14px 16px', lineHeight: 1.65, fontSize: 13, color: 'var(--femo-text-1)', touchAction: 'auto', WebkitOverflowScrolling: 'touch' }}>
1526
+ {ns.context && <div style={{ whiteSpace: 'pre-wrap', marginBottom: 10 }}>{ns.context}</div>}
1527
+ {ns.showprompt && (
1528
+ <div style={{ marginBottom: 10, background: 'var(--femo-bg)', padding: '8px 10px', borderRadius: 'var(--femo-radius-md)' }}>
1529
+ <div style={{ fontWeight: 700, color: 'var(--femo-text-3)', marginBottom: 3, fontSize: 10.5 }}>[节点提示]</div>
1530
+ <div style={{ whiteSpace: 'pre-wrap', fontSize: 12 }}>{ns.showprompt}</div>
1531
+ </div>
1532
+ )}
1533
+ {isHuman && ns.prompt && (
1534
+ <div style={{ marginBottom: 10, background: 'var(--femo-bg)', padding: '8px 10px', borderRadius: 'var(--femo-radius-md)' }}>
1535
+ <div style={{ fontWeight: 700, color: 'var(--femo-text-3)', marginBottom: 3, fontSize: 10.5 }}>[提示]</div>
1536
+ <div style={{ whiteSpace: 'pre-wrap', fontSize: 12 }}>{ns.prompt}</div>
1537
+ </div>
1538
+ )}
1539
+ {runType === 'notice' && (ns.output || ns.prompt) && (
1540
+ <div style={{ marginBottom: 10, background: 'var(--femo-bg)', padding: '8px 10px', borderRadius: 'var(--femo-radius-md)' }}>
1541
+ <div style={{ fontWeight: 700, color: 'var(--femo-text-3)', marginBottom: 3, fontSize: 10.5 }}>[公告]</div>
1542
+ <div style={{ whiteSpace: 'pre-wrap', fontSize: 12 }}>{ns.output || ns.prompt}</div>
1543
+ </div>
1544
+ )}
1545
+ {isAI && (
1546
+ <div>
1547
+ <div style={{ fontWeight: 700, marginBottom: 4, fontSize: 12 }}>[{ns.ai_name || 'AI'}]:</div>
1548
+ {isStreaming ? (
1549
+ <div style={{ whiteSpace: 'pre-wrap', fontSize: 12 }}>
1550
+ {ns.streamingText || ''}
1551
+ <span className="mob-cursor" style={{ fontWeight: 'bold', color: c }}>|</span>
1552
+ </div>
1553
+ ) : (
1554
+ <div style={{ whiteSpace: 'pre-wrap', fontSize: 12 }}>{ns.output || '(等待输出)'}</div>
1555
+ )}
1556
+ </div>
1557
+ )}
1558
+ </div>
1559
+
1560
+ {/* 人类输入 */}
1561
+ {isHuman && ns.status === 'human_wait' && (
1562
+ <MobileHumanInput nodeId={node.id} onSubmit={submitHumanInput} outVars={ns.outVars || []} />
1563
+ )}
1564
+ </div>
1565
+ </>
1566
+ );
1567
+ }
1568
+
1569
+ function MobileHumanInput({ nodeId, onSubmit, outVars }) {
1570
+ const [chatText, setChatText] = useState('');
1571
+ const [varValues, setVarValues] = useState({});
1572
+
1573
+ const handleSend = () => {
1574
+ if (!chatText.trim() && !Object.values(varValues).some((v) => v?.trim())) return;
1575
+ const assignments = {};
1576
+ for (const [k, v] of Object.entries(varValues)) {
1577
+ if (v?.trim()) assignments[k] = v.trim();
1578
+ }
1579
+ onSubmit(nodeId, chatText.trim(), assignments);
1580
+ setChatText('');
1581
+ setVarValues({});
1582
+ };
1583
+
1584
+ return (
1585
+ <div style={{ flexShrink: 0, padding: '10px 14px 16px', borderTop: 'var(--femo-border-w) solid var(--femo-border)' }}>
1586
+ <div style={{ fontSize: 10, fontWeight: 700, color: 'var(--femo-warning)', marginBottom: 6 }}>⏳ 等待人类输入</div>
1587
+ <textarea
1588
+ value={chatText}
1589
+ onChange={(e) => setChatText(e.target.value)}
1590
+ placeholder="输入回复..."
1591
+ rows={3}
1592
+ style={{
1593
+ ...inp,
1594
+ resize: 'none',
1595
+ width: '100%',
1596
+ boxSizing: 'border-box',
1597
+ fontSize: 13,
1598
+ touchAction: 'auto',
1599
+ userSelect: 'text',
1600
+ WebkitUserSelect: 'text',
1601
+ }}
1602
+ />
1603
+ <div style={{ display: 'flex', gap: 7, marginTop: 7, flexWrap: 'wrap', alignItems: 'center' }}>
1604
+ <button onClick={handleSend} style={{ ...mobBtnP, padding: '7px 18px', fontSize: 12 }}>发送</button>
1605
+ {outVars.map((varName) => (
1606
+ <div key={varName} style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
1607
+ <span style={{ fontSize: 10, fontWeight: 700, color: 'var(--femo-text-3)', fontFamily: 'var(--femo-font-mono)' }}>{varName}:</span>
1608
+ <input
1609
+ value={varValues[varName] || ''}
1610
+ onChange={(e) => setVarValues((p) => ({ ...p, [varName]: e.target.value }))}
1611
+ placeholder="值"
1612
+ style={{ ...inp, width: 90, fontSize: 11, padding: '4px 7px' }}
1613
+ />
1614
+ </div>
1615
+ ))}
1616
+ </div>
1617
+ </div>
1618
+ );
1619
+ }
1620
+
1621
+ // ─────────────────────────────────────────────
1622
+ // useMobileCanvasGesture — round56 触摸仲裁 v3
1623
+ // 状态机:idle → pending → nodeDrag / conn / canvasPan / pinch
1624
+ //
1625
+ // v2 的三个硬伤(2026-09-08 CDP 真实触摸管线实测,脚本在 _diag-femogen-pinch/):
1626
+ // ① pinch 配对取 e.touches[0]/[1]——那是「全页面最老的两根触点」,不是
1627
+ // 「本次捏合的两指」。画布外多任何第三触点(搭在面板上的手指、握机
1628
+ // 手掌误触)都配错对:一根手指被完全无视、缩放几乎不动、画布随
1629
+ // 「静态触点↔手指」中点大幅漂移(实测 scale 1.00→1.07,应到 1.76)。
1630
+ // ② 双指之一落在面板/标题栏时,其 touchstart 不经画布冒泡,phase 永远
1631
+ // 进不了 pinch;画布上那根手指 200ms 后转 canvasPan,move 又因
1632
+ // ts.length!==1 直接 return——缩放平移全死(实测 0 次缩放提交)。
1633
+ // ③ 无 touchcancel 处理:浏览器接管手势(原生滚动等)发 cancel 后状态机
1634
+ // 残留,直到所有手指抬起才能恢复。
1635
+ //
1636
+ // v3 方案:
1637
+ // - 登记制:只有落点在画布内的触点进 canvasTouchesRef(Set 保持落屏序,
1638
+ // 值为 touch.identifier)。面板/标题栏触点从根上不参与画布手势,
1639
+ // 也不会毒化状态机。
1640
+ // - pinch 锁定最近落下的两根画布触点的 id;move 只按这两个 id 从
1641
+ // e.touches 取实时坐标,第三根手指彻底无视。丢指按剩余画布触点降级:
1642
+ // 2→重锁续捏、1→转平移、0→复位。
1643
+ // - touchcancel 一律清场(清计时器/选中环/连线预览),不产生轻点选择
1644
+ // 等副作用。
1645
+ // - 捏合/平移帧 transform ref 直写 DOM(round47 ghost 同款思路),
1646
+ // 手势结束才 flush 回 React state——此前每个 touchmove 都 setPan+
1647
+ // setScale 触发 FemoWorAuto 整树重渲染(canvasContent 无 memo),是
1648
+ // 手机端捏合掉帧的主因。
1649
+ // ─────────────────────────────────────────────
1650
+ const LONG_PRESS_MS = 200;
1651
+ // ── round49 仓库触摸仲裁 v2 常量:落点不参与裁决,只认位移与静止 ──
1652
+ const LIB_LONG_PRESS_MS = 300; // 长按武装时限(比画布略长,区分"点选"与"拖"意图)
1653
+ const LIB_SCROLL_COMMIT_PX = 8; // 位移防抖阈值:任一轴累计 ≥8px → 永判滚动,本手势绝不再拦截
1654
+ const LIB_DRAG_SLOP_PX = 4; // 武装允许的累计漂移上限
1655
+ const LIB_STILL_MS = 120; // 武装前要求最近 N ms 完全没动——慢速滚动必然被拒,根治"滑着滑着被劫持"
1656
+ const LIB_ARM_RECHECK_MS = 150; // 未达静止条件的顺延复查间隔
1657
+ const LIB_ARM_MAX_WAIT_MS = 900; // 顺延武装总上限(超时放弃,交还原生滚动)
1658
+ const MOVE_THRESHOLD = 5;
1659
+ const NODE_TOUCH_PAD = 12; // 画布节点命中判定外扩(屏幕像素)——小节点更好碰
1660
+
1661
+ function useMobileCanvasGesture({
1662
+ cvRef, tfRef,
1663
+ pan, setPan, scale, setScale,
1664
+ handlePortDown, handlePortUp, setConn,
1665
+ nodes, setNodes, setDrag, setSel,
1666
+ onBubbleClick,
1667
+ onNodeDoubleTap,
1668
+ }) {
1669
+ const stateRef = useRef({ phase: 'idle' });
1670
+ const pinchRef = useRef({ dist: 0, x: 0, y: 0 });
1671
+ const startRef = useRef({ x: 0, y: 0 });
1672
+ const timerRef = useRef(null);
1673
+ // 双击检测:记录上次轻点的节点与时刻——同节点 300ms 内两次轻点=双击
1674
+ // (对齐桌面端 onDoubleClick 语义:module 进子画布 / action 开编辑弹窗)。
1675
+ const lastTapRef = useRef(null);
1676
+ const [dragReady, setDragReady] = useState(null);
1677
+ // round56:画布内活跃触点登记(touch.identifier,Set 迭代序=落屏序)
1678
+ const canvasTouchesRef = useRef(new Set());
1679
+
1680
+ // 用 ref 持有最新 pan/scale/nodes,彻底避免闭包陈旧。
1681
+ // round56:手势进行中(pinch/canvasPan 直写 DOM 时)ref 是唯一事实源,
1682
+ // 不再被 props 回写——否则手势中途任何一次无关渲染都会把手势内部的
1683
+ // 基线拖回旧值,画面回跳一帧。
1684
+ const panRef = useRef(pan);
1685
+ const scaleRef = useRef(scale);
1686
+ const nodesRef = useRef(nodes);
1687
+ useEffect(() => { if (stateRef.current.phase === 'idle') panRef.current = pan; }, [pan]);
1688
+ useEffect(() => { if (stateRef.current.phase === 'idle') scaleRef.current = scale; }, [scale]);
1689
+ useEffect(() => { nodesRef.current = nodes; }, [nodes]);
1690
+
1691
+ // 回调经 ref 中转:原生监听只挂一次,不随 props 身份变化重挂/漏更新
1692
+ const apiRef = useRef({});
1693
+ useEffect(() => {
1694
+ apiRef.current = { setPan, setScale, setSel, setNodes, setConn, setDrag, handlePortDown, handlePortUp, onBubbleClick, onNodeDoubleTap };
1695
+ });
1696
+
1697
+ const dist2 = (a, b) => Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY);
1698
+ const mid2 = (a, b) => ({ x: (a.clientX + b.clientX) / 2, y: (a.clientY + b.clientY) / 2 });
1699
+ const findTouch = (list, id) => {
1700
+ for (let i = 0; i < list.length; i += 1) if (list[i].identifier === id) return list[i];
1701
+ return null;
1702
+ };
1703
+ const clearTimer = () => { clearTimeout(timerRef.current); timerRef.current = null; };
1704
+
1705
+ // round56:捏合/平移帧直写 DOM(transform),手势结束 flush
1706
+ // (2026-09-11:缩放比例徽标已按用户点名摘除,此处不再直写任何徽标文案)
1707
+ const applyTransform = (x, y, s) => {
1708
+ panRef.current = { x, y };
1709
+ scaleRef.current = s;
1710
+ if (tfRef?.current) tfRef.current.style.transform = `translate(${x}px, ${y}px) scale(${s})`;
1711
+ };
1712
+ const flushTransform = () => {
1713
+ apiRef.current.setPan(panRef.current);
1714
+ apiRef.current.setScale(scaleRef.current);
1715
+ };
1716
+
1717
+ // DOM hit-test:找节点体、端口、连线热区或运行时小气泡
1718
+ const hitTest = (cx, cy) => {
1719
+ const el = document.elementFromPoint(cx, cy);
1720
+ if (el) {
1721
+ const portEl = el.closest('[data-port-node]');
1722
+ if (portEl) return {
1723
+ type: 'port',
1724
+ nodeId: portEl.dataset.portNode,
1725
+ portDir: portEl.dataset.portDir || 'right',
1726
+ portX: portEl.dataset.portX ? parseFloat(portEl.dataset.portX) : undefined,
1727
+ portY: portEl.dataset.portY ? parseFloat(portEl.dataset.portY) : undefined,
1728
+ };
1729
+ // 运行时小气泡(节点上方)——须在 node 之前判(气泡是节点的 DOM 后代,closest 都会命中 node-id)
1730
+ const bubbleEl = el.closest('[data-bubble-node]');
1731
+ if (bubbleEl) return { type: 'bubble', nodeId: bubbleEl.dataset.bubbleNode };
1732
+ const nodeEl = el.closest('[data-node-id]');
1733
+ if (nodeEl) return { type: 'node', nodeId: nodeEl.dataset.nodeId };
1734
+ // round26:连线热区路径带 data-edge-id,手机端点边不再依赖合成 click
1735
+ const edgeEl = el.closest('[data-edge-id]');
1736
+ if (edgeEl) return { type: 'edge', id: edgeEl.dataset.edgeId };
1737
+ }
1738
+ // round25:扩大命中——节点矩形外扩 NODE_TOUCH_PAD(屏幕像素转画布坐标),小节点更好碰
1739
+ const rect = cvRef.current?.getBoundingClientRect();
1740
+ if (!rect) return null;
1741
+ const s = scaleRef.current || 1;
1742
+ const p = panRef.current;
1743
+ const wx = (cx - rect.left - p.x) / s;
1744
+ const wy = (cy - rect.top - p.y) / s;
1745
+ const pad = NODE_TOUCH_PAD / s;
1746
+ for (let i = nodesRef.current.length - 1; i >= 0; i--) {
1747
+ const n = nodesRef.current[i];
1748
+ const { w, h } = getNodeSize(n);
1749
+ if (wx >= n.x - pad && wx <= n.x + w + pad && wy >= n.y - pad && wy <= n.y + h + pad) {
1750
+ return { type: 'node', nodeId: n.id };
1751
+ }
1752
+ }
1753
+ return null;
1754
+ };
1755
+
1756
+ const fakeEv = (cx, cy) => ({
1757
+ clientX: cx, clientY: cy, button: 0,
1758
+ stopPropagation: () => {}, preventDefault: () => {}, target: null,
1759
+ });
1760
+
1761
+ // 锁定「最近落下的两根仍存活的画布触点」进入 pinch(基线取当前间距/中点)
1762
+ const enterPinch = (e) => {
1763
+ const ids = [...canvasTouchesRef.current].filter((id) => findTouch(e.touches, id));
1764
+ if (ids.length < 2) return false;
1765
+ const [idA, idB] = ids.slice(-2);
1766
+ const ta = findTouch(e.touches, idA);
1767
+ const tb = findTouch(e.touches, idB);
1768
+ if (!ta || !tb) return false;
1769
+ stateRef.current = { phase: 'pinch', idA, idB };
1770
+ pinchRef.current = { dist: dist2(ta, tb), ...mid2(ta, tb) };
1771
+ setDragReady(null);
1772
+ return true;
1773
+ };
1774
+
1775
+ useEffect(() => {
1776
+ const el = cvRef.current;
1777
+ if (!el) return undefined;
1778
+
1779
+ const onTouchStart = (e) => {
1780
+ // round55 语义收编:画布触点在源头取消默认行为(原生长按选字/放大镜/
1781
+ // 合成鼠标事件),顺手把已聚焦输入框收起来;非画布触点零干预,
1782
+ // 面板原生滚动完全不受影响。React 17+ 根级合成 touch 事件是 passive
1783
+ // 的,preventDefault 必须走这条原生非 passive 监听。
1784
+ let canvasChanged = null;
1785
+ for (let i = 0; i < e.changedTouches.length; i += 1) {
1786
+ if (el.contains(e.changedTouches[i].target)) { canvasChanged = e.changedTouches[i]; break; }
1787
+ }
1788
+ if (!canvasChanged) return; // 面板/标题栏触点:画布手势层不参与也不干扰
1789
+ const ae = document.activeElement;
1790
+ if (ae && (ae.tagName === 'TEXTAREA' || ae.tagName === 'INPUT' || ae.tagName === 'SELECT')) ae.blur();
1791
+ e.preventDefault();
1792
+ for (let i = 0; i < e.changedTouches.length; i += 1) {
1793
+ const t = e.changedTouches[i];
1794
+ if (el.contains(t.target)) canvasTouchesRef.current.add(t.identifier);
1795
+ }
1796
+
1797
+ const st = stateRef.current;
1798
+ // —— 双指缩放入口:画布内触点 ≥2 即锁双指,无论落屏先后、无论当前
1799
+ // 处于 pending/nodeDrag/conn/canvasPan 哪个相位(长按到一半也能
1800
+ // 直接改捏合,这正是真机最常见的起手式)——
1801
+ if (canvasTouchesRef.current.size >= 2) {
1802
+ clearTimer();
1803
+ if (st.phase === 'conn') apiRef.current.setConn(null); // 连线预览不残留
1804
+ enterPinch(e);
1805
+ return;
1806
+ }
1807
+ if (st.phase !== 'idle') return; // 单指手势在途,新触点不重入
1808
+
1809
+ // —— 单指起手:只认画布内触点 ——
1810
+ const t = canvasChanged;
1811
+ startRef.current = { x: t.clientX, y: t.clientY };
1812
+ stateRef.current = { phase: 'pending', id: t.identifier, cx: t.clientX, cy: t.clientY };
1813
+ setDragReady(null);
1814
+
1815
+ // 长按计时:判断命中目标后切换阶段
1816
+ timerRef.current = setTimeout(() => {
1817
+ const s0 = stateRef.current;
1818
+ if (s0.phase !== 'pending') return;
1819
+ const { cx, cy } = s0;
1820
+ const hit = hitTest(cx, cy);
1821
+
1822
+ if (hit?.type === 'port') {
1823
+ stateRef.current = { phase: 'conn', id: s0.id, srcNodeId: hit.nodeId };
1824
+ navigator.vibrate?.(12);
1825
+ apiRef.current.handlePortDown(fakeEv(cx, cy), hit.nodeId, hit.portDir, hit.portX, hit.portY);
1826
+
1827
+ // 长按在节点体或其小气泡上 = 拖动该节点(气泡视觉上属于节点,桌面端按住气泡同样触发节点拖拽)
1828
+ } else if (hit?.type === 'node' || hit?.type === 'bubble') {
1829
+ const node = nodesRef.current.find((n) => n.id === hit.nodeId);
1830
+ if (!node) return;
1831
+ navigator.vibrate?.(18);
1832
+ setDragReady(hit.nodeId);
1833
+ apiRef.current.setSel({ type: 'node', id: hit.nodeId });
1834
+ stateRef.current = {
1835
+ phase: 'nodeDrag',
1836
+ id: s0.id,
1837
+ nodeId: hit.nodeId,
1838
+ startCx: cx, startCy: cy,
1839
+ startNx: node.x, startNy: node.y,
1840
+ };
1841
+
1842
+ } else {
1843
+ stateRef.current = { phase: 'canvasPan', id: s0.id, cx, cy };
1844
+ }
1845
+ }, LONG_PRESS_MS);
1846
+ };
1847
+
1848
+ const onTouchMove = (e) => {
1849
+ // 能到达本监听的 touchmove 目标必在画布内(监听挂画布元素上),
1850
+ // preventDefault 与 round55 语义一致
1851
+ e.preventDefault();
1852
+ const st = stateRef.current;
1853
+
1854
+ // 双指捏合缩放 + 平移:只看锁定的两根手指,页面上其他手指彻底无视
1855
+ if (st.phase === 'pinch') {
1856
+ const ta = findTouch(e.touches, st.idA);
1857
+ const tb = findTouch(e.touches, st.idB);
1858
+ if (!ta || !tb) return; // 参与者少了一根:等 end/cancel 统一收尾
1859
+ const d = dist2(ta, tb);
1860
+ const m = mid2(ta, tb);
1861
+ const ratio = d / (pinchRef.current.dist || d);
1862
+ const rect = el.getBoundingClientRect();
1863
+ const p = panRef.current, s = scaleRef.current;
1864
+ const mxr = m.x - rect.left, myr = m.y - rect.top;
1865
+ const wx = (mxr - p.x) / s, wy = (myr - p.y) / s;
1866
+ const ns = Math.min(3, Math.max(0.2, s * ratio));
1867
+ applyTransform(
1868
+ mxr - wx * ns + (m.x - pinchRef.current.x),
1869
+ myr - wy * ns + (m.y - pinchRef.current.y),
1870
+ ns,
1871
+ );
1872
+ pinchRef.current = { dist: d, x: m.x, y: m.y };
1873
+ return;
1874
+ }
1875
+
1876
+ // 其余相位只跟随「起手那根手指」,其他手指的 move 一律无视
1877
+ const t = st.id !== undefined ? findTouch(e.touches, st.id) : null;
1878
+ if (!t) return;
1879
+
1880
+ // pending:快速滑动直接进入平移,不等长按
1881
+ if (st.phase === 'pending') {
1882
+ const dx = t.clientX - startRef.current.x;
1883
+ const dy = t.clientY - startRef.current.y;
1884
+ if (Math.abs(dx) > MOVE_THRESHOLD || Math.abs(dy) > MOVE_THRESHOLD) {
1885
+ clearTimer();
1886
+ stateRef.current = { phase: 'canvasPan', id: st.id, cx: t.clientX, cy: t.clientY };
1887
+ }
1888
+ return;
1889
+ }
1890
+
1891
+ // 节点拖拽:直接算 delta,调 setNodes(FOR↔for_out 联动与桌面端共用一份定义)
1892
+ if (st.phase === 'nodeDrag') {
1893
+ setDragReady(null);
1894
+ const sc = scaleRef.current;
1895
+ const newX = st.startNx + (t.clientX - st.startCx) / sc;
1896
+ const newY = st.startNy + (t.clientY - st.startCy) / sc;
1897
+ apiRef.current.setNodes((prev) => {
1898
+ const draggedNode = prev.find((n) => n.id === st.nodeId);
1899
+ if (!draggedNode) return prev;
1900
+ return applyForLinkage(prev, draggedNode, newX, newY);
1901
+ });
1902
+ return;
1903
+ }
1904
+
1905
+ // 连线:更新 conn.mx/my
1906
+ if (st.phase === 'conn') {
1907
+ const p = panRef.current;
1908
+ const sc = scaleRef.current;
1909
+ const rect = el.getBoundingClientRect();
1910
+ const mx = (t.clientX - rect.left - p.x) / sc;
1911
+ const my = (t.clientY - rect.top - p.y) / sc;
1912
+ apiRef.current.setConn((prev) => (prev ? { ...prev, mx, my } : prev));
1913
+ return;
1914
+ }
1915
+
1916
+ // 画布平移:直写 DOM,不起 React 渲染
1917
+ if (st.phase === 'canvasPan') {
1918
+ applyTransform(
1919
+ panRef.current.x + (t.clientX - st.cx),
1920
+ panRef.current.y + (t.clientY - st.cy),
1921
+ scaleRef.current,
1922
+ );
1923
+ st.cx = t.clientX;
1924
+ st.cy = t.clientY;
1925
+ return;
1926
+ }
1927
+ };
1928
+
1929
+ const finishGesture = (e) => {
1930
+ const cancelled = e.type === 'touchcancel';
1931
+ clearTimer();
1932
+ setDragReady(null);
1933
+
1934
+ // 登记表摘除已结束触点;统计仍存活的画布触点(e.touches 为准)
1935
+ for (let i = 0; i < e.changedTouches.length; i += 1) {
1936
+ canvasTouchesRef.current.delete(e.changedTouches[i].identifier);
1937
+ }
1938
+ const alive = [];
1939
+ for (let i = 0; i < e.touches.length; i += 1) {
1940
+ if (canvasTouchesRef.current.has(e.touches[i].identifier)) alive.push(e.touches[i]);
1941
+ }
1942
+ const removedIds = new Set();
1943
+ for (let i = 0; i < e.changedTouches.length; i += 1) removedIds.add(e.changedTouches[i].identifier);
1944
+
1945
+ const st = stateRef.current;
1946
+
1947
+ // —— pinch 收尾 ——
1948
+ if (st.phase === 'pinch') {
1949
+ if (removedIds.has(st.idA) || removedIds.has(st.idB)) {
1950
+ if (cancelled) {
1951
+ // 系统收走手势:直接复位(手指重新起手即可恢复),flush 定格
1952
+ flushTransform();
1953
+ stateRef.current = { phase: 'idle' };
1954
+ } else if (alive.length >= 2) {
1955
+ // 三指捏合抬一指:重锁最近两根继续
1956
+ enterPinch(e);
1957
+ } else if (alive.length === 1) {
1958
+ flushTransform();
1959
+ stateRef.current = { phase: 'canvasPan', id: alive[0].identifier, cx: alive[0].clientX, cy: alive[0].clientY };
1960
+ } else {
1961
+ flushTransform();
1962
+ stateRef.current = { phase: 'idle' };
1963
+ }
1964
+ }
1965
+ // 抬的是第三指:pinch 继续,不动
1966
+ return;
1967
+ }
1968
+
1969
+ // —— 单指相位:只有起手手指的 end 才收尾 ——
1970
+ const mine = cancelled ? null : Array.from(e.changedTouches).find((t) => t.identifier === st.id);
1971
+
1972
+ if (st.phase === 'conn') {
1973
+ if (cancelled) {
1974
+ apiRef.current.setConn(null); // 系统收走:放弃连线预览
1975
+ } else if (mine) {
1976
+ const hit = hitTest(mine.clientX, mine.clientY);
1977
+ if (hit?.nodeId && hit.nodeId !== st.srcNodeId) {
1978
+ apiRef.current.handlePortUp(fakeEv(mine.clientX, mine.clientY), hit.nodeId, hit.portDir || 'left');
1979
+ } else {
1980
+ apiRef.current.setConn(null);
1981
+ }
1982
+ }
1983
+ if (cancelled || mine) stateRef.current = { phase: 'idle' };
1984
+ return;
1985
+ }
1986
+
1987
+ if (st.phase === 'nodeDrag') {
1988
+ apiRef.current.setDrag(null);
1989
+ stateRef.current = { phase: 'idle' };
1990
+ return;
1991
+ }
1992
+
1993
+ // pending 抬手 = 短按(点击):开气泡 / 选中节点/连线 / 取消选中;
1994
+ // touchcancel 是系统收走,绝不产生选择副作用
1995
+ if (st.phase === 'pending') {
1996
+ if (cancelled) {
1997
+ stateRef.current = { phase: 'idle' };
1998
+ return;
1999
+ }
2000
+ if (!mine) return;
2001
+ const hit = hitTest(mine.clientX, mine.clientY);
2002
+ if (hit?.type === 'bubble') {
2003
+ // 轻点运行时小气泡 = 打开气泡弹层(对齐桌面端 onClick→onBubbleClick;不改 sel,与桌面一致)
2004
+ apiRef.current.onBubbleClick?.(hit.nodeId);
2005
+ } else if (hit?.type === 'node') {
2006
+ // 双击判定:同节点 300ms 内两次轻点 → 双击回调(module 进子画布 /
2007
+ // action 开编辑弹窗,由宿主分发);否则记为首次轻点并照常选中。
2008
+ const now = performance.now();
2009
+ const lt = lastTapRef.current;
2010
+ if (lt && lt.nodeId === hit.nodeId && now - lt.t < 300) {
2011
+ lastTapRef.current = null;
2012
+ apiRef.current.onNodeDoubleTap?.(hit.nodeId);
2013
+ } else {
2014
+ lastTapRef.current = { nodeId: hit.nodeId, t: now };
2015
+ apiRef.current.setSel({ type: 'node', id: hit.nodeId });
2016
+ }
2017
+ } else if (hit?.type === 'edge') {
2018
+ apiRef.current.setSel({ type: 'edge', id: hit.id });
2019
+ } else {
2020
+ apiRef.current.setSel(null);
2021
+ }
2022
+ stateRef.current = { phase: 'idle' };
2023
+ return;
2024
+ }
2025
+
2026
+ if (st.phase === 'canvasPan') {
2027
+ flushTransform();
2028
+ if (!cancelled && mine && alive.length >= 1) {
2029
+ // 换指续平移(旧版语义)
2030
+ const t0 = alive[0];
2031
+ stateRef.current = { phase: 'canvasPan', id: t0.identifier, cx: t0.clientX, cy: t0.clientY };
2032
+ } else {
2033
+ stateRef.current = { phase: 'idle' };
2034
+ }
2035
+ }
2036
+ };
2037
+
2038
+ el.addEventListener('touchstart', onTouchStart, { passive: false });
2039
+ el.addEventListener('touchmove', onTouchMove, { passive: false });
2040
+ el.addEventListener('touchend', finishGesture, { passive: false });
2041
+ el.addEventListener('touchcancel', finishGesture, { passive: false });
2042
+ return () => {
2043
+ el.removeEventListener('touchstart', onTouchStart);
2044
+ el.removeEventListener('touchmove', onTouchMove);
2045
+ el.removeEventListener('touchend', finishGesture);
2046
+ el.removeEventListener('touchcancel', finishGesture);
2047
+ canvasTouchesRef.current.clear();
2048
+ stateRef.current = { phase: 'idle' };
2049
+ };
2050
+ }, [cvRef]);
2051
+
2052
+ return { dragReady };
2053
+ }
2054
+
2055
+
2056
+ // ─────────────────────────────────────────────
2057
+ // MobileLayout — 根组件,接收桌面端所有 props
2058
+ // ─────────────────────────────────────────────
2059
+ /**
2060
+ * 用法(在 FemoWorAuto.jsx 内检测 isMobile 后替换渲染):
2061
+ *
2062
+ * <MobileLayout
2063
+ * // 项目
2064
+ * proj={proj}
2065
+ * actorNames={actorNames}
2066
+ * onProjChange={setProj}
2067
+ * // 画布
2068
+ * cvRef={cvRef}
2069
+ * pan={pan} setPan={setPan}
2070
+ * scale={scale} setScale={setScale}
2071
+ * nodes={nodes} edges={edges}
2072
+ * canvasContent={<> {svgLayer} {nodeLayer} </>}
2073
+ * // 交互
2074
+ * sel={sel} setSel={setSel}
2075
+ * drag={drag} conn={conn} isPanning={isPanning}
2076
+ onMM={onMM}
2077
+ onMU={onMU}
2078
+ onCanvasDown={onCanvasDown}
2079
+ handleWheel={handleWheel}
2080
+ handlePortDown={handlePortDown}
2081
+ handlePortUp={handlePortUp}
2082
+ handleBodyMouseUp={handleBodyMouseUp}
2083
+ setDrag={setDrag}
2084
+ setConn={setConn}
2085
+ setNodes={setNodes}
2086
+ handleCanvasDragOver={handleCanvasDragOver}
2087
+ handleCanvasDrop={handleCanvasDrop}
2088
+ * // 库
2089
+ * lib={lib} mode={mode} locationPath={locationPath} allNames={allNames}
2090
+ * onNew={...} onAdd={...} ... (所有 LibPanel 的 props)
2091
+ * // 运行
2092
+ * flowStatus={flowStatus} hasActiveRunningNodes={hasActiveRunningNodes}
2093
+ * onRun={handleRunWorkflow(恒定 reset:从头)} onPause={handlePauseWorkflow} onResume={handleResumeWorkflow}
2094
+ * nodeStates={nodeStates} actionStore={actionStore} activeNodeIds={activeNodeIds}
2095
+ * // 气泡
2096
+ * bubbleOverlay={bubbleOverlay} onBubbleClose={handleBubbleClose} submitHumanInput={submitHumanInput}
2097
+ * // FEMO
2098
+ * femoText={femoText} onFemoChange={...} femoError={femoError} femoDirty={femoDirty}
2099
+ * onApplyFemo={handleApplyFemo} onRestoreFemo={handleRestoreFemo} onGraphToFemo={handleGraphToFemo}
2100
+ * // 模态框触发
2101
+ * onOpenApiKey={() => setApiKeyModalOpen(true)}
2102
+ * onOpenSoul={() => setSoulModalOpen(true)}
2103
+ * // 画布内容透明度
2104
+ * canvasOpacity={canvasOpacity}
2105
+ * />
2106
+ */
2107
+ function MobileLayout({
2108
+ // Theme
2109
+ theme = 'dsh',
2110
+ // 全屏层(插件模式手机端全屏沉浸用):fixedMode=false 时降级为容器内 absolute
2111
+ zIndex,
2112
+ fixedMode = true,
2113
+ // 返回键(插件模式:打开 dsh 边栏;独立模式不传)
2114
+ onBack,
2115
+ // 全屏键(插件模式容器内态:回全屏沉浸;独立模式不传)
2116
+ onExpand,
2117
+ // Project
2118
+ proj, actorNames, onProjChange,
2119
+ // Canvas core
2120
+ cvRef, pan, setPan, scale, setScale,
2121
+ nodes, edges, sel, setSel,
2122
+ drag, setDrag, conn, setConn, isPanning, setNodes,
2123
+ onMM, onMU, onCanvasDown, handleWheel,
2124
+ handlePortDown, handlePortUp, handleBodyMouseUp,
2125
+ handleCanvasDragOver, handleCanvasDrop,
2126
+ canvasContent, canvasOpacity,
2127
+ // Library
2128
+ lib, mode, locationPath, allNames,
2129
+ onNew, onAdd, onAddModule, onAddSpecial, onAddPosition,
2130
+ onEdit, onEditModule, onDragStart, onSelectLib, onNewModule,
2131
+ libSel,
2132
+ // Runtime
2133
+ flowStatus, hasActiveRunningNodes,
2134
+ onRun, onPause, onResume,
2135
+ nodeStates, actionStore, activeNodeIds, errorNodeIds,
2136
+ // Bubble
2137
+ bubbleOverlay, onBubbleClose, submitHumanInput, humanWaits,
2138
+ onBubbleClick,
2139
+ // FEMO
2140
+ femoText, onFemoChange, femoError, FEMOrnings, femoDirty,
2141
+ onApplyFemo, onRestoreFemo, onGraphToFemo,
2142
+ // 文件读写(2026-09-11 手机端补齐):导入/导出回调 + 导出进行中/成功回执。
2143
+ // 与桌面工具栏同源(FemoWorAuto 的 handleToolbarImport / handleToolbarExport),
2144
+ // 手机端只换呈现(图标芯片 + 标题栏下方 toast),行为完全一致。
2145
+ onImport, onExport, exportBusy, exportToast,
2146
+ // Modals
2147
+ onOpenSoul,
2148
+ // 设置(设置 tab:主题切换 + 新建 SOUL)
2149
+ themeName, onCycleTheme,
2150
+ // 调试窗口(设置 tab 打开;数据面与桌面端同源)
2151
+ debugLog, onClearDebug,
2152
+ compilerLog, onClearCompiler,
2153
+ femogenLog, onClearFemogen,
2154
+ hostLog, onClearHost,
2155
+ onCompileDebug, compilingDebug,
2156
+ // Selection helpers
2157
+ backEdges,
2158
+ onDeleteNode, onDeleteEdge, onCondChange, onEditAction,
2159
+ // Module 子画布导航(2026-09-06 手机端补齐):双击节点分发 / 返回上级 /
2160
+ // 属性面板「进入子画布」。
2161
+ onNodeDoubleTap, onNavigatePath, onEnterModuleNode,
2162
+ }) {
2163
+ const [femoVisible, setFemoVisible] = useState(false);
2164
+ const [bottomTab, setBottomTab] = useState('library');
2165
+ // round56:捏合/平移帧 transform 直写 DOM 的挂点(手势结束才 flush 回 state)
2166
+ const tfRef = useRef(null);
2167
+
2168
+ // 当选中节点/边时,自动切换到属性 tab
2169
+ useEffect(() => {
2170
+ if (sel) setBottomTab('props');
2171
+ }, [sel]);
2172
+
2173
+ // 触摸手势(round56:钩子内部自挂原生监听,不再经 React 合成事件)
2174
+ const { dragReady } = useMobileCanvasGesture({
2175
+ cvRef, tfRef, pan, setPan, scale, setScale,
2176
+ handlePortDown, handlePortUp, setConn,
2177
+ nodes, setNodes, setDrag, setSel,
2178
+ onBubbleClick,
2179
+ onNodeDoubleTap,
2180
+ });
2181
+ // ── 从仓库触摸拖拽放置节点(round49 仲裁 v2:落点不参与裁决) ──
2182
+ // 手势状态机:pending →(任一轴累计 ≥8px)scroll:彻底放手给原生 pan-y,绝不再拦截
2183
+ // →(静止满 300ms:累计 ≤4px 且最近 120ms 无位移)drag:preventDefault 拖 ghost
2184
+ // 落点仅用于 touchstart 时 closest('[data-femo-lib-drag]') 找"拖哪个";
2185
+ // 空白处/输入框/按钮落点连计时器都不启动,行为与纯原生滚动完全一致。
2186
+ // 根因注记(v1 卡死):旧版按落点逐卡挂监听,300ms 内位移 ≤4px 即武装——轻缓起手的
2187
+ // 滚动被误判成长按,armed 后 preventDefault 把进行中的原生滚动当场掐死(列表冻结)。
2188
+ const libDragRef = useRef(null); // { phase:'pending'|'drag', type, item, startX, startY, lastX, lastY, lastMoveAt, bornAt }
2189
+ const libTimerRef = useRef(null);
2190
+ // round47:ghost 改为 **ref 直写 DOM**——touchmove 里 setState 会重渲染
2191
+ // 整棵编辑器树(主线程卡死,WebKit 来不及启动滚动=卡片滑不动的重要共犯)。
2192
+ // 只有"armed 开关"保留 state 变更(驱动画布放置提示 + 抓起卡片高亮)。
2193
+ const [libDragActive, setLibDragActive] = useState(false);
2194
+ const ghostRef = useRef(null);
2195
+ const ghostLabelRef = useRef(null);
2196
+ // round27:长按激活视觉反馈——当前被抓起条目的 key("type:id"),null=无。
2197
+ // 激活瞬间 set,touchEnd/取消清;透传 LibPanel 点亮被按卡片 + 画布浮现可放置提示。
2198
+ const [libArmedKey, setLibArmedKey] = useState(null);
2199
+ // round49:item 对象经 ref 解析(lib 数组常变,避免闭包陈旧)
2200
+ const libRef = useRef(lib);
2201
+ useEffect(() => { libRef.current = lib; }, [lib]);
2202
+
2203
+ // 面板级 touchstart(passive,绝不 preventDefault):
2204
+ // 找拖拽候选并启动长按武装计时;非候选落点零干预。
2205
+ const handlePanelTouchStart = useCallback((e) => {
2206
+ if (libDragRef.current) return; // 已有手势在途(多指),不覆盖
2207
+ const t = e.touches[0];
2208
+ if (!t || !t.target) return;
2209
+ // 打字/按钮落点:与拖拽无关,保持纯原生行为
2210
+ if (t.target.closest && t.target.closest('input, textarea, select, button')) return;
2211
+ const card = t.target.closest ? t.target.closest('[data-femo-lib-drag]') : null;
2212
+ if (!card) return; // 空白处:无候选,纯滚动路径
2213
+ const raw = card.getAttribute('data-femo-lib-drag') || '';
2214
+ const sep = raw.indexOf(':');
2215
+ if (sep <= 0) return;
2216
+ const type = raw.slice(0, sep);
2217
+ const id = raw.slice(sep + 1);
2218
+ let item = null;
2219
+ if (type === 'action') item = (libRef.current?.actions || []).find((x) => x.id === id);
2220
+ else if (type === 'module') item = (libRef.current?.modules || []).find((x) => x.id === id);
2221
+ else if (type === 'special' || type === 'position') item = id; // 特殊节点/POSITION 的 item 是字符串
2222
+ if (!item) return;
2223
+ clearTimeout(libTimerRef.current);
2224
+ libDragRef.current = {
2225
+ phase: 'pending', type, item,
2226
+ startX: t.clientX, startY: t.clientY,
2227
+ lastX: t.clientX, lastY: t.clientY,
2228
+ lastMoveAt: performance.now(), bornAt: performance.now(),
2229
+ };
2230
+ // 长按武装判定(可顺延):到点复核"漂移小 + 最近确实没动",慢速滚动会被正确拒绝
2231
+ const tryArm = () => {
2232
+ const st = libDragRef.current;
2233
+ if (!st || st.phase !== 'pending') return;
2234
+ const now = performance.now();
2235
+ const driftX = Math.abs(st.lastX - st.startX);
2236
+ const driftY = Math.abs(st.lastY - st.startY);
2237
+ const stillLongEnough = now - st.lastMoveAt >= LIB_STILL_MS;
2238
+ if (driftX > LIB_DRAG_SLOP_PX || driftY > LIB_DRAG_SLOP_PX || !stillLongEnough) {
2239
+ if (now - st.bornAt < LIB_ARM_MAX_WAIT_MS) {
2240
+ libTimerRef.current = setTimeout(tryArm, LIB_ARM_RECHECK_MS);
2241
+ } else {
2242
+ libDragRef.current = null; // 放弃武装,交还原生滚动(本手势不再有拖拽)
2243
+ }
2244
+ return;
2245
+ }
2246
+ st.phase = 'drag';
2247
+ navigator.vibrate?.(15); // iOS Safari 不支持 vibrate;iPhone 靠下方视觉反馈
2248
+ const label = typeof st.item === 'string' ? st.item : (st.item?.name || st.type);
2249
+ setLibArmedKey(`${st.type}:${typeof st.item === 'string' ? st.item : st.item?.id}`);
2250
+ setLibDragActive(true); // round49:补回 round47 丢失的调用——画布虚线放置提示恢复
2251
+ if (ghostRef.current && ghostLabelRef.current) {
2252
+ ghostLabelRef.current.textContent = label;
2253
+ ghostRef.current.style.display = 'block';
2254
+ ghostRef.current.style.left = `${st.startX - 50}px`;
2255
+ ghostRef.current.style.top = `${st.startY - 20}px`;
2256
+ }
2257
+ };
2258
+ libTimerRef.current = setTimeout(tryArm, LIB_LONG_PRESS_MS);
2259
+ }, []);
2260
+
2261
+ // 面板级 touchmove(非 passive):
2262
+ // drag 相位才 preventDefault;pending 相位只记账,≥8px 即承诺滚动并永久放手。
2263
+ const handleLibTouchMove = useCallback((e) => {
2264
+ const st = libDragRef.current;
2265
+ if (!st) return;
2266
+ const t = e.touches[0];
2267
+ if (st.phase === 'drag') {
2268
+ e.preventDefault();
2269
+ e.stopPropagation();
2270
+ if (ghostRef.current) {
2271
+ ghostRef.current.style.left = `${t.clientX - 50}px`;
2272
+ ghostRef.current.style.top = `${t.clientY - 20}px`;
2273
+ }
2274
+ return;
2275
+ }
2276
+ // pending:零拦截记账。任一轴累计 ≥LIB_SCROLL_COMMIT_PX → 判滚动意图,
2277
+ // 清掉一切拖拽状态,本手势剩余时间与原生 pan-y 完全无关。
2278
+ st.lastX = t.clientX; st.lastY = t.clientY;
2279
+ st.lastMoveAt = performance.now();
2280
+ const dx = Math.abs(t.clientX - st.startX);
2281
+ const dy = Math.abs(t.clientY - st.startY);
2282
+ if (dx >= LIB_SCROLL_COMMIT_PX || dy >= LIB_SCROLL_COMMIT_PX) {
2283
+ clearTimeout(libTimerRef.current);
2284
+ libDragRef.current = null;
2285
+ }
2286
+ }, []);
2287
+
2288
+ const handleLibTouchCancel = useCallback((e) => {
2289
+ // 浏览器接管手势(原生滚动/系统语义),JS 事件流到此终止——全量复位
2290
+ clearTimeout(libTimerRef.current);
2291
+ if (ghostRef.current) ghostRef.current.style.display = 'none';
2292
+ setLibArmedKey(null);
2293
+ setLibDragActive(false);
2294
+ libDragRef.current = null;
2295
+ }, []);
2296
+
2297
+ const handleLibTouchEnd = useCallback((e) => {
2298
+ clearTimeout(libTimerRef.current);
2299
+ setLibArmedKey(null); // 无论放置/取消,抓起态视觉必须回落
2300
+ setLibDragActive(false);
2301
+ if (ghostRef.current) ghostRef.current.style.display = 'none';
2302
+ const st = libDragRef.current;
2303
+ libDragRef.current = null;
2304
+ if (!st || st.phase !== 'drag') return;
2305
+ const t = e.changedTouches[0];
2306
+ // 判断落点是否在画布区域内
2307
+ const cvRect = cvRef.current?.getBoundingClientRect();
2308
+ if (!cvRect) return;
2309
+ if (t.clientX < cvRect.left || t.clientX > cvRect.right || t.clientY < cvRect.top || t.clientY > cvRect.bottom) {
2310
+ return;
2311
+ }
2312
+ // 转换为画布世界坐标
2313
+ const worldX = (t.clientX - cvRect.left - pan.x) / scale - 50;
2314
+ const worldY = (t.clientY - cvRect.top - pan.y) / scale - 20;
2315
+ const { type, item } = st;
2316
+ if (type === 'action') onAdd(item, worldX, worldY);
2317
+ else if (type === 'module') onAddModule(item, worldX, worldY);
2318
+ else if (type === 'special') onAddSpecial(item, worldX, worldY); // item 此时是字符串如 'OUT'
2319
+ else if (type === 'position') onAddPosition(worldX, worldY); // position 不需要 item
2320
+ }, [pan, scale, cvRef, onAdd, onAddModule, onAddSpecial, onAddPosition]);
2321
+
2322
+ // 当前选中实体
2323
+ const selNode = sel?.type === 'node' ? nodes.find((n) => n.id === sel.id) : null;
2324
+ const selEdge = sel?.type === 'edge' ? edges.find((e) => e.id === sel.id) : null;
2325
+ const selAction = selNode?.type === 'action' ? actionStore?.find((a) => a.id === selNode.actionId) : null;
2326
+
2327
+ return (
2328
+ <div
2329
+ data-femo-theme={theme}
2330
+ style={{
2331
+ position: fixedMode ? 'fixed' : 'absolute',
2332
+ inset: 0,
2333
+ zIndex: zIndex,
2334
+ display: 'flex',
2335
+ flexDirection: 'column',
2336
+ background: T.bg,
2337
+ fontFamily: 'var(--femo-font-sans)',
2338
+ overflow: 'hidden',
2339
+ }}
2340
+ >
2341
+ <MobileGlobalStyle />
2342
+
2343
+ {/* ── 标题栏 ── */}
2344
+ <MobileTitleBar
2345
+ projName={proj?.name}
2346
+ flowStatus={flowStatus}
2347
+ femoVisible={femoVisible}
2348
+ onBack={fixedMode ? onBack : undefined}
2349
+ onExpand={fixedMode ? undefined : onExpand}
2350
+ onToggleFemo={() => setFemoVisible((v) => !v)}
2351
+ onRun={onRun}
2352
+ onPause={onPause}
2353
+ onResume={onResume}
2354
+ hasActiveRunningNodes={hasActiveRunningNodes}
2355
+ onImport={onImport}
2356
+ onExport={onExport}
2357
+ exportBusy={exportBusy}
2358
+ // Module 子画布层级:非主流程时显示「‹ 模块名」返回键(此前手机端
2359
+ // 进入子画布后无任何返回入口,只能重载会话)。
2360
+ locationPath={locationPath}
2361
+ onNavigatePath={onNavigatePath}
2362
+ />
2363
+
2364
+ {/* 导出保存回执(2026-09-11 手机端补齐):锚在标题栏正下方右侧,与桌面
2365
+ 工具栏同款(4s 自动消失,见 FemoWorAuto.showExportToast)。top 用与
2366
+ 标题栏同源的 clamp(5vh,40~56 clamped),任意屏高都紧贴标题栏下沿;
2367
+ key=id 使连续两次导出重放浮现动画。 */}
2368
+ {exportToast !== null && (
2369
+ <div
2370
+ key={exportToast.id}
2371
+ style={{
2372
+ position: 'absolute',
2373
+ top: 'clamp(40px, 5vh, 56px)',
2374
+ right: 12,
2375
+ marginTop: 6,
2376
+ zIndex: 150,
2377
+ maxWidth: 'min(560px, calc(100% - 24px))',
2378
+ padding: '7px 12px',
2379
+ borderRadius: 8,
2380
+ fontSize: 12,
2381
+ lineHeight: 1.5,
2382
+ fontWeight: 600,
2383
+ wordBreak: 'break-all',
2384
+ boxShadow: '0 4px 14px rgba(0,0,0,0.18)',
2385
+ background: 'var(--femo-panel-bg)',
2386
+ border: '1px solid var(--femo-success, #3ca050)',
2387
+ color: 'var(--femo-success, #3ca050)',
2388
+ animation: 'dropHintIn 0.2s ease',
2389
+ }}
2390
+ >
2391
+ {exportToast.text}
2392
+ </div>
2393
+ )}
2394
+
2395
+ {/* ── 画布 ── */}
2396
+ <div
2397
+ ref={cvRef}
2398
+ className="femo-canvas-zone"
2399
+ style={{
2400
+ flex: 1,
2401
+ position: 'relative',
2402
+ overflow: 'hidden',
2403
+ backgroundImage: 'var(--femo-mobile-canvas-dots)',
2404
+ backgroundSize: '22px 22px',
2405
+ cursor: isPanning ? 'grabbing' : conn ? 'crosshair' : 'default',
2406
+ minHeight: 0,
2407
+ }}
2408
+ // Mouse events (桌面兼容)。触摸手势 round56 起由 useMobileCanvasGesture
2409
+ // 内部的原生监听接管(登记制 + identifier 锁定),不再走 React 合成事件。
2410
+ onMouseMove={onMM}
2411
+ onMouseUp={onMU}
2412
+ onMouseDown={onCanvasDown}
2413
+ onWheel={handleWheel}
2414
+ onMouseLeave={onMU}
2415
+ // Drag-drop
2416
+ onDragOver={handleCanvasDragOver}
2417
+ onDrop={handleCanvasDrop}
2418
+ >
2419
+ <div
2420
+ data-canvas-bg="true"
2421
+ style={{
2422
+ opacity: canvasOpacity,
2423
+ transition: 'opacity 0.2s ease',
2424
+ position: 'absolute',
2425
+ inset: 0,
2426
+ }}
2427
+ >
2428
+ <div
2429
+ ref={tfRef}
2430
+ data-canvas-bg="true"
2431
+ style={{
2432
+ transform: `translate(${pan.x}px, ${pan.y}px) scale(${scale})`,
2433
+ transformOrigin: '0 0',
2434
+ position: 'absolute',
2435
+ inset: 0,
2436
+ }}
2437
+ >
2438
+ {canvasContent}
2439
+ </div>
2440
+ </div>
2441
+
2442
+ {/* 空状态提示(zIndex 极低,永远不遮节点)*/}
2443
+ {nodes.filter((n) => n.type !== 'special').length === 0 && !conn && (
2444
+ <div
2445
+ style={{
2446
+ position: 'absolute',
2447
+ inset: 0,
2448
+ display: 'flex',
2449
+ flexDirection: 'column',
2450
+ alignItems: 'center',
2451
+ justifyContent: 'center',
2452
+ pointerEvents: 'none',
2453
+ zIndex: 0,
2454
+ }}
2455
+ >
2456
+ <div style={{ fontSize: 13, color: 'var(--femo-mobile-border-light)', fontWeight: 600 }}>从仓库添加 Action</div>
2457
+ <div style={{ fontSize: 11, color: 'var(--femo-mobile-border)', marginTop: 5 }}>长按节点拖动 · 长按端口连线 · 双指缩放</div>
2458
+ </div>
2459
+ )}
2460
+
2461
+ {/* round27:仓库拖拽激活中——画布浮现虚线可放置提示 + 顶部胶囊 */}
2462
+ {libDragActive && (
2463
+ <>
2464
+ <div style={{
2465
+ position: 'absolute',
2466
+ inset: 8,
2467
+ borderRadius: 'var(--femo-radius-lg)',
2468
+ border: 'var(--femo-border-w-selected) dashed var(--femo-primary-glow-x)',
2469
+ background: 'var(--femo-primary-soft-faint)',
2470
+ pointerEvents: 'none',
2471
+ zIndex: 150,
2472
+ animation: 'dropHintIn 0.22s ease-out',
2473
+ }} />
2474
+ <div style={{
2475
+ position: 'absolute',
2476
+ top: 18,
2477
+ left: '50%',
2478
+ transform: 'translateX(-50%)',
2479
+ background: 'var(--femo-primary-overlay)',
2480
+ color: 'var(--femo-on-accent)',
2481
+ padding: '3px 11px',
2482
+ borderRadius: 'var(--femo-radius-md)',
2483
+ fontSize: 10.5,
2484
+ fontWeight: 700,
2485
+ letterSpacing: '0.02em',
2486
+ pointerEvents: 'none',
2487
+ zIndex: 151,
2488
+ whiteSpace: 'nowrap',
2489
+ boxShadow: '0 4px 14px var(--femo-primary-glow-strong)',
2490
+ animation: 'dropHintIn 0.25s ease-out',
2491
+ }}>
2492
+ 松手放置到画布
2493
+ </div>
2494
+ </>
2495
+ )}
2496
+
2497
+ {/* 长按就绪视觉反馈:在 dragReady 节点上方显示小环 */}
2498
+ {dragReady && (() => {
2499
+ const n = nodes.find(nd => nd.id === dragReady);
2500
+ if (!n) return null;
2501
+ const { w, h } = { w: 200, h: 80 }; // 估算节点中心,不引入 getNodeSize
2502
+ const cx = (n.x + w / 2) * scale + pan.x;
2503
+ const cy = (n.y + h / 2) * scale + pan.y;
2504
+ return (
2505
+ <div style={{
2506
+ position: 'absolute',
2507
+ left: cx - 28,
2508
+ top: cy - 28,
2509
+ width: 56,
2510
+ height: 56,
2511
+ borderRadius: 'var(--femo-radius-pill)',
2512
+ border: 'var(--femo-border-w-selected) solid var(--femo-primary-glow-x)',
2513
+ boxShadow: '0 0 12px 4px var(--femo-primary-glow)',
2514
+ pointerEvents: 'none',
2515
+ zIndex: 200,
2516
+ animation: 'pulse 0.6s ease-out',
2517
+ }} />
2518
+ );
2519
+ })()}
2520
+
2521
+ {/* 缩放比例徽标(round56 加于右下角)2026-09-11 用户点名摘除:手机端画布
2522
+ 不再显示 XX%——捏合缩放无需实时数字反馈(transform 照旧直写,手感不变)。
2523
+ 连手势层的直写与 scaleBadgeRef 挂点一并拆除,勿再补回。 */}
2524
+ </div>
2525
+
2526
+ {/* 拖拽幽灵预览(round27:弹出动画 + 光晕呼吸,明确"已激活")——round47 改常驻+ref 直写 */}
2527
+ <div
2528
+ ref={ghostRef}
2529
+ style={{
2530
+ display: 'none',
2531
+ position: 'fixed',
2532
+ background: 'var(--femo-primary-overlay)',
2533
+ color: 'var(--femo-on-accent)',
2534
+ borderRadius: 'var(--femo-radius-md)',
2535
+ padding: '6px 12px',
2536
+ fontSize: 12,
2537
+ fontWeight: 700,
2538
+ pointerEvents: 'none',
2539
+ zIndex: 999,
2540
+ whiteSpace: 'nowrap',
2541
+ boxShadow: '0 4px 16px var(--femo-primary-glow-strong)',
2542
+ }}
2543
+ >
2544
+ <span ref={ghostLabelRef} />
2545
+ </div>
2546
+
2547
+ {/* ── 底部面板 ── */}
2548
+ <MobileBottomPanel
2549
+ activeTab={bottomTab}
2550
+ onTabChange={setBottomTab}
2551
+ lib={lib}
2552
+ mode={mode}
2553
+ locationPath={locationPath}
2554
+ allNames={allNames}
2555
+ onNew={onNew}
2556
+ onAdd={onAdd}
2557
+ onAddModule={onAddModule}
2558
+ onAddSpecial={onAddSpecial}
2559
+ onAddPosition={onAddPosition}
2560
+ onEdit={onEdit}
2561
+ onEditModule={onEditModule}
2562
+ onDragStart={onDragStart}
2563
+ onPanelTouchStart={handlePanelTouchStart}
2564
+ onLibTouchMove={handleLibTouchMove}
2565
+ onLibTouchEnd={handleLibTouchEnd}
2566
+ onLibTouchCancel={handleLibTouchCancel}
2567
+ libArmedKey={libArmedKey}
2568
+ onSelectLib={(type, id) => {
2569
+ onSelectLib?.(type, id);
2570
+ setBottomTab('props');
2571
+ }}
2572
+ onNewModule={onNewModule}
2573
+ proj={proj}
2574
+ actorNames={actorNames}
2575
+ onProjChange={onProjChange}
2576
+ sel={sel}
2577
+ selNode={selNode}
2578
+ selEdge={selEdge}
2579
+ selAction={selAction}
2580
+ nodes={nodes}
2581
+ edges={edges}
2582
+ backEdges={backEdges}
2583
+ nodeStates={nodeStates}
2584
+ actionStore={actionStore}
2585
+ onDeleteNode={onDeleteNode}
2586
+ onDeleteEdge={onDeleteEdge}
2587
+ onCondChange={onCondChange}
2588
+ onEditAction={onEditAction}
2589
+ onEnterModuleNode={onEnterModuleNode}
2590
+ libSel={libSel}
2591
+ themeName={themeName}
2592
+ onCycleTheme={onCycleTheme}
2593
+ onOpenSoul={onOpenSoul}
2594
+ debugLog={debugLog}
2595
+ onClearDebug={onClearDebug}
2596
+ compilerLog={compilerLog}
2597
+ onClearCompiler={onClearCompiler}
2598
+ femogenLog={femogenLog}
2599
+ onClearFemogen={onClearFemogen}
2600
+ hostLog={hostLog}
2601
+ onClearHost={onClearHost}
2602
+ onCompileDebug={onCompileDebug}
2603
+ compilingDebug={compilingDebug}
2604
+ htmlDraggable={false}
2605
+ />
2606
+
2607
+ {/* ── FEMO 预览面板 — 直接复用桌面原版,包裹在滑出容器里 ── */}
2608
+ {femoVisible && (
2609
+ <>
2610
+ <div
2611
+ onClick={() => setFemoVisible(false)}
2612
+ style={{ position: 'fixed', inset: 0, background: 'var(--femo-mask)', zIndex: 300 }}
2613
+ />
2614
+ <div style={{
2615
+ position: 'fixed', right: 0, top: 0, bottom: 0,
2616
+ width: '88vw', maxWidth: 460,
2617
+ background: 'var(--femo-mobile-bg-2)',
2618
+ borderLeft: `var(--femo-border-w) solid ${T.border}`,
2619
+ zIndex: 301,
2620
+ display: 'flex', flexDirection: 'column',
2621
+ animation: 'slideInFemo 0.22s cubic-bezier(0.4,0,0.2,1)',
2622
+ boxShadow: '-8px 0 32px var(--femo-mask)',
2623
+ }}>
2624
+ <FemoPreview
2625
+ value={femoText}
2626
+ onChange={onFemoChange}
2627
+ error={femoError}
2628
+ warnings={FEMOrnings}
2629
+ dirty={femoDirty}
2630
+ onApply={onApplyFemo}
2631
+ onRestore={onRestoreFemo}
2632
+ onGraphToFemo={onGraphToFemo}
2633
+ />
2634
+ </div>
2635
+ </>
2636
+ )}
2637
+
2638
+ {/* ── 气泡弹层 — 直接复用桌面原版 ── */}
2639
+ <BubbleOverlay
2640
+ bubbleOverlay={bubbleOverlay}
2641
+ nodes={nodes}
2642
+ nodeStates={nodeStates}
2643
+ humanWaits={humanWaits}
2644
+ actionStore={actionStore}
2645
+ onClose={onBubbleClose}
2646
+ submitHumanInput={submitHumanInput}
2647
+ />
2648
+ </div>
2649
+ );
2650
+ }
2651
+
2652
+ // ─────────────────────────────────────────────
2653
+ // 共享样式 token(模块内)
2654
+ // ─────────────────────────────────────────────
2655
+ const sectionLabel = {
2656
+ fontSize: 9.5,
2657
+ fontWeight: 800,
2658
+ color: T.textMuted,
2659
+ textTransform: 'uppercase',
2660
+ letterSpacing: '0.1em',
2661
+ fontFamily: 'var(--femo-font-sans)',
2662
+ };
2663
+
2664
+ // 设置面板三键同构配方(2026-09-08 r2):等宽 flex:1 均衡 + 32px 最小高度(对齐
2665
+ // MobileIconBtn 芯片家族)+ 同 padding/字号/边框,仅图标与文字区分语义
2666
+ // (FaPalette 主题 / FaUserPlus 新建SOUL / FaTerminal 调试)。overflow:hidden
2667
+ // 配合文字 span 省略号,长主题名不撑破等宽布局;按压反馈走 femo-mob-setting-btn。
2668
+ const mobSettingBtn = {
2669
+ display: 'flex',
2670
+ alignItems: 'center',
2671
+ justifyContent: 'center',
2672
+ gap: 6,
2673
+ padding: '8px 6px',
2674
+ minHeight: 32,
2675
+ boxSizing: 'border-box',
2676
+ borderRadius: 'var(--femo-radius-md)',
2677
+ fontSize: 11.5,
2678
+ fontWeight: 600,
2679
+ fontFamily: 'var(--femo-font-sans)',
2680
+ cursor: 'pointer',
2681
+ border: 'var(--femo-border-w) solid var(--femo-border-strong)',
2682
+ background: 'var(--femo-bg)',
2683
+ color: 'var(--femo-text-2)',
2684
+ flex: 1,
2685
+ minWidth: 0,
2686
+ position: 'relative',
2687
+ whiteSpace: 'nowrap',
2688
+ overflow: 'hidden',
2689
+ };
2690
+
2691
+ // 三键文字 span:省略号兜底(minWidth:0 让 flex 子项可收缩)。
2692
+ const mobSettingBtnText = {
2693
+ overflow: 'hidden',
2694
+ textOverflow: 'ellipsis',
2695
+ minWidth: 0,
2696
+ };
2697
+
2698
+ const fieldLabel = {
2699
+ fontSize: 10,
2700
+ fontWeight: 700,
2701
+ color: T.textSecondary,
2702
+ marginBottom: 4,
2703
+ };
2704
+
2705
+ const mobInp = {
2706
+ width: '100%',
2707
+ padding: '6px 9px',
2708
+ borderRadius: 'var(--femo-radius-sm)',
2709
+ border: `var(--femo-border-w-strong) solid ${T.border}`,
2710
+ fontSize: 11.5,
2711
+ color: T.textPrimary,
2712
+ background: 'var(--femo-mobile-bg)',
2713
+ outline: 'none',
2714
+ fontFamily: 'var(--femo-font-sans)',
2715
+ transition: 'border-color 0.15s',
2716
+ boxSizing: 'border-box',
2717
+ touchAction: 'auto',
2718
+ userSelect: 'text',
2719
+ WebkitUserSelect: 'text',
2720
+ };
2721
+
2722
+ const mobBtnP = {
2723
+ padding: '6px 14px',
2724
+ borderRadius: 'var(--femo-radius-sm)',
2725
+ background: 'var(--femo-btn-primary)',
2726
+ color: 'var(--femo-on-accent)',
2727
+ border: 'none',
2728
+ cursor: 'pointer',
2729
+ fontSize: 11.5,
2730
+ fontWeight: 700,
2731
+ fontFamily: 'var(--femo-font-sans)',
2732
+ };
2733
+
2734
+ const mobBtnS = {
2735
+ padding: '5px 12px',
2736
+ borderRadius: 'var(--femo-radius-sm)',
2737
+ background: 'transparent',
2738
+ color: T.textSecondary,
2739
+ border: `var(--femo-border-w-strong) solid ${T.border}`,
2740
+ cursor: 'pointer',
2741
+ fontSize: 11.5,
2742
+ fontWeight: 600,
2743
+ fontFamily: 'var(--femo-font-sans)',
2744
+ };
2745
+
2746
+ // FEMO 面板头排统一芯片配方(2026-09-07 与桌面端 femoPreview 同构):浅色
2747
+ // 同系底 + 1px 同色细边,仅用颜色区分语义。可点击态用主题强调色(灰底像
2748
+ // 禁用);不再混用 mobBtnS 粗描边与 mobBtnP 无边填充。
2749
+ const mobChip = (color, active = false) => ({
2750
+ padding: '4px 10px',
2751
+ borderRadius: 'var(--femo-radius-sm)',
2752
+ background: `color-mix(in srgb, ${color} ${active ? 15 : 10}%, transparent)`,
2753
+ border: `1px solid color-mix(in srgb, ${color} ${active ? 45 : 35}%, transparent)`,
2754
+ color,
2755
+ cursor: 'pointer',
2756
+ fontSize: 10,
2757
+ fontWeight: 700,
2758
+ fontFamily: 'var(--femo-font-sans)',
2759
+ transition: 'background 0.15s, color 0.15s, border-color 0.15s',
2760
+ });
2761
+
2762
+ const mobBtnDanger = {
2763
+ padding: '6px 14px',
2764
+ borderRadius: 'var(--femo-radius-sm)',
2765
+ background: 'transparent',
2766
+ color: T.danger,
2767
+ border: `var(--femo-border-w-strong) solid ${T.danger}44`,
2768
+ cursor: 'pointer',
2769
+ fontSize: 11.5,
2770
+ fontWeight: 700,
2771
+ fontFamily: 'var(--femo-font-sans)',
2772
+ };
2773
+
2774
+ // ─────────────────────────────────────────────
2775
+ // Hook:检测是否为手机端
2776
+ // ─────────────────────────────────────────────
2777
+ function useMobile(breakpoint = 768) {
2778
+ const [isMobile, setIsMobile] = useState(() => window.innerWidth < breakpoint);
2779
+ useEffect(() => {
2780
+ const handler = () => setIsMobile(window.innerWidth < breakpoint);
2781
+ window.addEventListener('resize', handler);
2782
+ return () => window.removeEventListener('resize', handler);
2783
+ }, [breakpoint]);
2784
+ return isMobile;
2785
+ }
2786
+
2787
+ export {
2788
+ MobileLayout,
2789
+ MobileFemoPanel,
2790
+ MobileBubbleOverlay,
2791
+ MobileHumanInput,
2792
+ MobileTitleBar,
2793
+ MobileBottomPanel,
2794
+ useMobileCanvasGesture,
2795
+ useMobile,
2796
+ };