dsbot-starboard 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +175 -2
- package/client.js +2800 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +10 -0
- package/index.js +2 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +72 -6
- package/ui/index.js +2866 -0
- package/ui/manifest.json +5 -0
package/client.js
ADDED
|
@@ -0,0 +1,2800 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsbot-starboard',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
|
|
6
|
+
// 星轨蜂巢设计令牌。深浅两套 CSS 变量,统一挂在 .dsb-root 上。
|
|
7
|
+
// 颜色只在角色身份色与状态色上做区分,UI chrome 保持中性。
|
|
8
|
+
|
|
9
|
+
const HIVE_FONT = '"Segoe UI Variable Text", "Segoe UI", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif'
|
|
10
|
+
const HIVE_MONO = '"Cascadia Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace'
|
|
11
|
+
|
|
12
|
+
const HIVE_VARS = {
|
|
13
|
+
dark: {
|
|
14
|
+
'--dsb-font': HIVE_FONT,
|
|
15
|
+
'--dsb-mono': HIVE_MONO,
|
|
16
|
+
'--dsb-stage-0': '#080a0f',
|
|
17
|
+
'--dsb-stage-1': '#0d1017',
|
|
18
|
+
'--dsb-stage-2': '#161b28',
|
|
19
|
+
'--dsb-panel': '#12151c',
|
|
20
|
+
'--dsb-card': 'rgba(255,255,255,.035)',
|
|
21
|
+
'--dsb-card-hi': 'rgba(255,255,255,.07)',
|
|
22
|
+
'--dsb-card-border': 'rgba(255,255,255,.09)',
|
|
23
|
+
'--dsb-hair': 'rgba(255,255,255,.075)',
|
|
24
|
+
'--dsb-text-1': '#f3f5f9',
|
|
25
|
+
'--dsb-text-2': 'rgba(243,245,249,.72)',
|
|
26
|
+
'--dsb-text-3': 'rgba(243,245,249,.48)',
|
|
27
|
+
'--dsb-accent': '#4d6bfe',
|
|
28
|
+
'--dsb-accent-2': '#8b9bff',
|
|
29
|
+
'--dsb-cyan': '#62d6ff',
|
|
30
|
+
'--dsb-wait': '#f2b84b',
|
|
31
|
+
'--dsb-fail': '#ff6b72',
|
|
32
|
+
'--dsb-ok': '#2bd98a',
|
|
33
|
+
'--dsb-pod-bg': 'radial-gradient(circle at 50% 28%, rgba(255,255,255,.16), rgba(255,255,255,.04) 66%, rgba(255,255,255,.012) 100%)',
|
|
34
|
+
'--dsb-pod-shadow': '0 12px 28px -10px rgba(0,0,0,.78), inset 0 1px 0 rgba(255,255,255,.16)',
|
|
35
|
+
'--dsb-pod-ring': 'rgba(255,255,255,.15)',
|
|
36
|
+
'--dsb-star': 'rgba(255,255,255,.55)',
|
|
37
|
+
'--dsb-orbit': 'rgba(255,255,255,.13)',
|
|
38
|
+
'--dsb-dock': 'rgba(18,21,28,.84)',
|
|
39
|
+
'--dsb-shadow-card': '0 20px 44px -22px rgba(0,0,0,.78)',
|
|
40
|
+
'--dsb-name-shadow': '0 1px 3px rgba(0,0,0,.55)',
|
|
41
|
+
'--dsb-scroll': 'rgba(255,255,255,.16)',
|
|
42
|
+
},
|
|
43
|
+
light: {
|
|
44
|
+
'--dsb-font': HIVE_FONT,
|
|
45
|
+
'--dsb-mono': HIVE_MONO,
|
|
46
|
+
'--dsb-stage-0': '#e6ebf4',
|
|
47
|
+
'--dsb-stage-1': '#f2f5fb',
|
|
48
|
+
'--dsb-stage-2': '#ffffff',
|
|
49
|
+
'--dsb-panel': '#ffffff',
|
|
50
|
+
'--dsb-card': 'rgba(255,255,255,.94)',
|
|
51
|
+
'--dsb-card-hi': '#ffffff',
|
|
52
|
+
'--dsb-card-border': 'rgba(24,32,60,.10)',
|
|
53
|
+
'--dsb-hair': 'rgba(24,32,60,.09)',
|
|
54
|
+
'--dsb-text-1': '#12151c',
|
|
55
|
+
'--dsb-text-2': 'rgba(18,21,28,.74)',
|
|
56
|
+
'--dsb-text-3': 'rgba(18,21,28,.52)',
|
|
57
|
+
'--dsb-accent': '#3a56e8',
|
|
58
|
+
'--dsb-accent-2': '#4d6bfe',
|
|
59
|
+
'--dsb-cyan': '#0b8fce',
|
|
60
|
+
'--dsb-wait': '#b26b00',
|
|
61
|
+
'--dsb-fail': '#d92d3d',
|
|
62
|
+
'--dsb-ok': '#008f52',
|
|
63
|
+
'--dsb-pod-bg': 'radial-gradient(circle at 50% 28%, #ffffff, #f2f5fb 66%, #e6ebf6 100%)',
|
|
64
|
+
'--dsb-pod-shadow': '0 12px 26px -12px rgba(24,36,80,.40), inset 0 1px 0 #ffffff',
|
|
65
|
+
'--dsb-pod-ring': 'rgba(24,32,60,.16)',
|
|
66
|
+
'--dsb-star': 'rgba(24,36,80,.28)',
|
|
67
|
+
'--dsb-orbit': 'rgba(24,36,80,.16)',
|
|
68
|
+
'--dsb-dock': 'rgba(255,255,255,.88)',
|
|
69
|
+
'--dsb-shadow-card': '0 18px 40px -24px rgba(24,36,80,.45)',
|
|
70
|
+
'--dsb-name-shadow': 'none',
|
|
71
|
+
'--dsb-scroll': 'rgba(24,32,60,.18)',
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// 角色数据必须在工厂顶层:boardViewModule 和 globalData 都要读它。
|
|
77
|
+
// 由 .extract-characters.cjs 从 ds-bot 0.4.3 的 client.js 抽取,勿手改。
|
|
78
|
+
const CHARACTERS = {"whale":{"label":"Whale","body":"M65.3 20.9l5.1 .1 4.8 .9 4.8 1.7 4.3 2.3 3.8 3.1 3 3.4 2.3 3.8 1.6 4.3 .9 4.3 0 4.8-.8 4.8-1.4 4.3-2.3 4.3-3.2 4.3-3.4 3.3-4.3 3.1-7.2 3.5-7.6 1.7-7.2 .1-9.6-1.6-3.3-1-2.9-1.7-8.8-8.9-6-4.7-3.3-.5-7.7 1.1-4.8-.1-4.7-1.2-1.9-1.2-1-1-.5-1.5 .4-1.4 1.1-1.3 1.9-1.3 4.7-1.5 7.7-.6 1.1-.5 .7-1 0-1.4-2.8-7.2-1.2-5.3-.1-4.3 .4-1.4 .9-1.2 1.9-.2 2 1 2.2 2.3 2.2 3.4 3.2 7.6 1.9 9.7 .5-.1 1.1-7.2 1.8-4.8 3.2-5.2 3.9-4.3 4.9-3.9 5.6-2.9 5.8-1.9z","eyes":[[72.5,48.4,9.3,23,-15.8],[85.6,43.4,7,22.9,-21.2]],"paints":[["M93.3 55.8l1-.3 .1 1.2-2.4 5.3-3.4 4.8-3.8 3.8-4.8 3.4-5.7 2.8-4.8 1.5-4.8 .4 20.1-17.4 5.2-3.7z","#fff",1]],"shade":"M88.6 29.5l2.4 2.9 1.9 2.8 2.4 6.3 .5 3.3 .1 5.3-1.5 6.6-1.9 4.3-2 3.3-4.8 5.4-5.7 4.3-7.2 3.3-6.2 1.5-6.7 .1-3.3-.2-9.6-1.8-3.3-1.5-2.4-1.9-8.6-8.9-5.3-3.9-3.3-.1-2.9 .2-3.3 .8-5.8 0-4.3-1-2.9-1.9 .6-.6 3.8-1.3 10.5-2.5 4.3 .9 1.4-.1 2.2-1.7 .5-1.4-.3-1.5-1.2-1.4-2.2-1.4-1.2-1.9-.6-12 .4-3.3 .5-.5 2.9 3.8 2.4 4.8 1.9 5.7 .7 5.8 .7 2.8 2.1 2.4 2.7 5.5 3.8 4.3 2.9 2.2 3.3 1 3.4-.4 6.2-3 7.1-4.5 7.3-5.6 6.6-5.9 5.9-6.5 3.7-5.3 1.7-4.2 .1-2.9z","light":"M55.6 22.8l1.9-.3 1.5 .3 .6 1 .1 .9-2 4.3-3.8 5.3-5.8 6.2-5.4 4.4-4.8 2.3-1.4 0-1.2-.5-.8-1.9 .5-3.3 2.5-4.8 3.3-4.3 2.4-2.4 5.3-3.9zM19.3 28.1l-1.4 2 .3-1.1zM21.7 49.1l.6 .5-.3 .5-.8 0zM35.8 52l1.2-.4 .9 .7 .7 1.6-.4 .9-1.2 .1-2.6-.5zM7.2 52.9l-2.9 2.9 1.2-1.6z"},"star":{"label":"Star","body":"M40.1 4.4l1.5-.4 1.9 .1 5.2 1.1 1.9 .9 13.2 14.9 17.1-.8 5.2 1.1 1.8 .9 1.7 1.6 .7 2.4-.4 1.9-9.7 23.6 5.6 23.7 .1 1.9-.6 1.4-2.1 1.8-2.3 .5-19.9-1.8-16.6 15.5-1.9 1-1.9 .3-7-1.5-2.6-2.1-.9-2.4-2.8-24.1-16-13.6-1.1-1.5-.5-1.9 .4-1.9 1.2-1.5 18.9-13.6 7.1-24.6 1-1.7z","eyes":[[53.9,53.4,7.2,18.8,-10],[65.1,49.2,7.2,18.8,-10]]},"moon":{"label":"Moon","body":"M44.4 4.3l8-.1 11.7 2.5 6.6 2.6 5.6 3.8 5.6 5.7 4.4 7.1 3.1 7.9 1.5 8.5 .1 9.4-1.6 9.4-3.2 8.9-4.9 8.4-5.9 6.8-7 5.4-7.5 3.6-8 1.7-7.5-.2-10.7-2.3-5.8-2.1-5-3-5.3-4.7-4.7-6.1-3.4-7.1-1.6-6.1 .3-4.2 .5-.9 .9-.4 7.5 1.7 6.1 5.3 1.5 0 2.8-1.1 2.5-1.8 2.3-2.3 2.2-3.1 2.7-6.3 .9-7-.9-6.6-1.3-3.1-1.6-2.5-1.8-1.9-1.3-.7-2.8 .9-6.1 3.1-1.9 .4-7-1.6-.7-1.2 .1-1.9 1.1-3.7 2.2-3.8 3.9-4.8 4.3-4.1 4.6-3.2 4.7-2.5 4.7-1.7z","eyes":[[61.3,54.8,6.9,18.1,-10],[72.4,50.7,6.9,18.1,-10]]},"cloud":{"label":"Cloud","body":"M43.6 11.6l6.7 .1 6.6 1.9 5.3 3.4 7.7 7.9 11.3 2.5 3.6 1.6 3.6 2.5 4.1 4.7 2.6 5.7 .9 6.6-1.1 6.5-1.5 3.6-1.9 2.9-4.9 5.3-17 11.4-6.8 3.5-8.9 2.8-9.5 1.3-13.1 2.5-6.5 .2-5.9-1.1-4.2-1.8-3.6-2.6-2.7-3-2.2-3.6-1.5-4.2-.7-4.1 .2-4.2 1-4.1 1.5-3.6 2.4-3.6 8.6-8.8 1.8-2.5 1.3-2.9 2.5-10.7 1.7-3.6 2.2-3.2 3.5-3.6 3.9-2.7 4.5-1.9z","eyes":[[55.7,62.2,8.5,20.1,-10.7],[74.4,55.5,6.8,20,-11.5]]},"spark":{"label":"Spark","body":"M32.9 4.3l2.9-.2 2.3 1 21.5 19.1 1.5-.7 2.4-2.3 1.9-1.1 2.3-.1 2.1 1.2 1.2 1.7 3.1 7.6 8.4 13.9 2.6 6.5 1.2 6.2-.2 7-1.6 7-3.1 6.4-4.4 5.8-5.3 4.8-6.3 3.9-6.4 2.4-7 1.4-7 .1-6.9-1.2-6.4-2.4-5.8-3.7-5-4.8-3.7-5.5-2.4-6.1-.9-4-.3-4.1 .3-4.6 .8-4.1 2.5-7 6-11 1.8-4.1 .9-3.4 3.4-21.5 1.2-2.5z","eyes":[[60.7,67.1,8.3,19.7,-11.2],[76.9,61,6.2,19.6,-12.1]]},"bear":{"label":"Bear","body":"M63.8 4.5l5.2-.4 4.9 1.4 3.9 2.8 2.9 4.4 1 3.2 .1 3.9-.5 2.7-1.7 4.4-.2 2.1 .9 2.2 3.8 4.4 2.6 3.8 1.9 3.9 1.3 3.8 1 4.4 .3 4.9-.3 4.9-1.1 4.9-2.8 7.1-4.3 6.7-5.7 5.9-6.9 4.7-7.6 3.3-7.7 1.8-8.2 .2-7.6-1.3-7.1-2.7-6.6-4.3-5.4-5.5-3.6-6.1-2.5-7.1-.8-7.1 .6-7.1 2.1-7.1-3.5-3.3-2.3-3.8-1.1-4.3 .5-5 1.3-3.2 2.5-3.3 2.9-2.2 3.8-1.5 4.4-.4 3.9 .8 3.8 2 3.2 3.3 7.1-2.9 8.2-2 1.1-.7 .9-1.3 1.3-6.1 2.2-4 3.3-3.1z","eyes":[[62.1,63.9,9,21.4,-11.5],[80.4,57,6.7,21.3,-13.3]]},"puppy":{"label":"Puppy","body":"M48.2 13.7l4.1 0 4.3 .5 7.7 2.3 3.8-2.2 3.9-.5 3.2 .8 2.8 1.7 2.2 2.7 15 26.4 .8 4.4-.3 2.2-.9 2.2-2.6 3.1-3.8 1.9-3.8 .2-3.9-1.3-3.8 6.5-4.9 5.5-5.5 4.2-6.6 3.2-4.4 1.3-4.3 .8-5 .2-4.3-.4-4.4-1-4.4-1.6-3.8-2-3.9-2.8-.4 .8-1.4 7.1-1.2 2.2-1.9 2-2.7 1.6-2.8 .6-2.7-.1-2.7-.9-2.3-1.5-1.8-2.2-1.2-2.8-.3-2.7 5.5-34.5 1.1-3.2 1.3-1.7 1.8-1.7 4.1-1.6 5.4-7.7 3.4-3.3 3.8-2.8 4.3-2.4 4.4-1.8 4.4-1.1z","eyes":[[58,51.9,8.8,20.6,-11.1],[74.8,45.6,6.3,20.5,-12.6]]},"kitty":{"label":null,"body":"M62.4 4.2l1.6-.1 1.5 1.2 7.4 21.3 3.7 6.4 6.2 7.4 3.1 5.9 1.5 4.8 .7 5.3-.2 5.4-1.1 5.3-3 7.4-4.4 6.4-5.3 5.4-6.9 4.6-7.5 3.1-8 1.7-8 .2-7.4-1.4-4.3-1.5-3.7-1.8-3.8-2.5-3.1-2.7-2.7-3-2.5-3.7-1.9-3.7-1.4-4.3-.9-5.3 .1-5.8 1.4-7 1.6-4.2 2-3.8 .8-3.2 .2-20.2 1.1-1.4 1.1-.3 1.1 .3 12.2 9.7 5.9-2.5 8-2.1 3.2-1.8 2.3-2.4 8.3-16z","eyes":[[59.6,65.1,9.4,22.6,-11.9],[77.5,58.4,7,22.5,-14]]},"bunny":{"label":null,"body":"M49.3 4.4l1.5-.4 2 1.2 1.6 2.7 1.2 3.4 1.6 8.9 .2 6-.2 6.4 .6 3 2.4 2.5 5.4 3 3.4 2.4 5.1 5.5 2.4 3.9 1.7 4 1.1 4.4 .4 4.5-.5 5.9-1.6 5.5-2.8 5.4-3.6 4.5-4.6 3.8-4.9 2.7-5.5 1.7-5.9 .7-6-.5-5.4-1.7-4.9-2.5-4.7-3.7-3.8-4.5-2.7-4.9-1.8-5.5-.7-5.9 .6-6.5 1.9-5.9 3.1-5.4 4.6-5.5-.4-2-3.4-8.4-1.8-6.9-.6-6.9 .3-3 .6-2 1.3-1.4 2-.1 2.5 1.5 2.1 2.5 4 6.9 2.1 5.5 1.7 5.9 1.5 2.1 1.8-1.6 .7-2-.4-12.4 1-8.9 1.6-4.9z","eyes":[[59.2,69.2,8.2,19.3,-12],[72.9,64,5.6,19.1,-15.4]]},"octopus":{"label":"Octopus","body":"M41.9 4.2l4.4-.2 4.5 .3 8 2 4 1.7 3.5 2.1 3.4 2.7 2.8 3 2.4 3.3 1.9 3.4 1.5 4 .8 4 .3 4-.3 4.5-.9 4-1.4 4 1.4 1.5 9.8 5.7 1.7 1.5 1.2 1.6 .9 2.3 .4 2.3-.2 2.3-.8 2.3-1.6 2.2-2.2 1.8-2.9 1.1-2.3 .1-2.2-.3-6.6-3.2 2.7 6.2 .2 4-.6 2.3-1.4 2.3-1.8 1.7-1.7 1-4 .8-4-.9-2.8-2-2.3-3.6-.3 .7 .2 5.7-1.6 3.8-1.7 1.8-2 1.3-2.6 .8-2.3 .1-3.4-.9-3-2.3-1.7-2.8-1.3-5.2-.3-.6-.6 .1-3.1 7.9-2 2.9-1.7 1.3-2.3 1-2.3 .4-2.3-.2-2.4-.8-2.4-1.7-1.7-2.3-.9-2.3-.3-2.3 .3-2.2 4.8-13.8 .4-3.4-1.2-3.4-6.9-7.9-3.4-6.4-1.2-4-.6-4 0-4 .5-4.5 1.6-5.2 2.5-5.1 3.2-4.6 4.3-4.3 5-3.7 5.3-2.7 5.7-1.9z","eyes":[[53.6,44.1,8.6,19.9,-10],[71.1,37.5,6.1,19.9,-10]]},"sprout":{"label":"Sprout","body":"M63.2 4.1l3 .2 1.2 .8 .7 1.1 .3 1.6-.2 2.1-1.6 4.2-3.6 5-4.7 4.4-4.8 3-5.4 1.7-.3 1.1 .4 2.6 .6 .5 4.7-.1 4.3 .5 6.3 1.7 6.3 3.2 5.7 4.9 4.4 6.1 2.6 6.8 .8 7.4-1.1 7.4-2.4 6.3-3.7 5.7-4.8 5-5.7 4-6.3 2.8-6.9 1.6-6.8 .2-6.8-1-4.8-1.6-4.7-2.5-4.1-3.2-3.5-3.7-2.7-4.2-2-4.7-1.1-4.7-.4-5.3 .6-4.7 1.2-4.8 2.1-4.7 2.8-4.2 3.4-3.9 4.2-3.5 4.8-2.9 5.4-2.3 0-1.6-.2-.4-3.1 1.6-3.7 .7-3.7-.2-3.7-.9-3.1-1.5-2.6-2.1-1.4-2.4 0-2.1 .9-1.6 1.5-1.2 2.6-1 2.7-.4 5.7 .5 6.3 2.6 .3-3.1 1.3-1.9 2.1-.7 2.6 .9 4-5.7 4.4-4.5 5.1-3.3z","eyes":[[59.4,69.3,8.7,20.6,-11.1],[75.5,63.2,6.3,20.6,-12.6]]},"bloom":{"label":"Blossom","body":"M45 4.1l3-.1 2.9 .4 2.9 .9 2.8 1.5 2.4 1.9 2.1 2.3 3 5.3 4-1.3 4.6-.4 4.6 .9 4 2 3.7 3.3 2.7 4 1.5 4.6 .4 4.6-.7 4.6-1.9 4.6-2.2 3.3-4.1 3.6-.5 1.1 3.1 4.1 1.6 2.8 1.2 3.5 .6 3.4-.1 4.1-.8 3.4-1.4 3.5-1.9 2.9-2.3 2.5-2.8 2-3 1.5-2.8 .9-3.5 .3-2.8-.2-6.4-2-2.8 4.9-4.1 3.9-5.1 2.5-5.8 .8-4-.6-4-1.7-3.5-2.6-2.5-3.1-2.3-4.6-.9-4.6 .3-5.1 1.4-4.6-6.3-2.6-2.7-2-2.2-2.3-1.8-2.9-1.2-2.9-.8-3.4-.2-3.5 .4-3.4 1.1-3.5 1.8-3.4 2.2-2.9 2.8-2.4 2.9-1.7 3.4-1.2 4.1-.5 .3-.5-.9-5.2 .3-4.6 1.3-4.6 2.4-4.1 2.6-2.8 3.1-2.3 3.5-1.5z","eyes":[[54.2,55.2,8,18.1,-10],[69.4,49.5,5.1,18.1,-10]]},"acorn":{"label":null,"body":"M47.6 4l2.1 .6 1.3 1.5 .4 1.5-.4 5.2 .3 .3 8.8-.1 7.7 1 7.3 2.1 5.7 2.9 3.6 2.9 2.6 3 1.8 3.4 .9 3.7 0 4.1-1 3.6-1.7 2.2-3.9 3 2.9 8.3 .9 8.3-.9 8.3-2.7 7.7-4.2 6.8-2.9 3.1-3.2 2.6-6.7 3.8-3.7 1.2-4.1 .8-7.2 0-7.3-1.7-7-3.6-5.9-5.1-4.8-6.3-3.3-7.3-1.8-7.7-.1-8.3-4.5-1.5-2.6-1.7-2.6-4.1-1.1-4.1 0-4.2 1.2-4.1 2.2-4.1 2.8-3.7 5.2-4.6 6.3-3.8 7.2-3.2 8.3-2.3 .9-8.3 1.2-1.4z","eyes":[[63.6,63.3,9.6,22.7,-11.9],[79.5,57.3,6.5,22.5,-15.5]]},"squircle":{"label":"Squircle","body":"M54.5 4.2l3.9-.2 3.7 .3 11.6 2.7 3.1 1.6 2.8 1.9 2.6 2.7 2.2 3.1 2.4 4.8 1.9 5.8 3.7 19.4 .8 11.1-.4 4.7-1 4.7-1.3 3.5-1.8 3.4-4.8 5.8-6.4 4.7-8 4-14.2 5.3-9.5 2.2-7.4 .1-10.5-2.2-5.3-2.5-4.3-3.7-3.3-4.8-2.7-6.3-2.4-9.5-2.8-17.9-.2-7.8 1.3-7.9 2.2-5.3 2.8-4.2 4.1-4.2 4.3-3.1 6.3-3.4 11.6-4.6 7.9-2.7z","eyes":[[52.6,52.4,8.4,22.1,-10],[67.3,46.9,8.4,22.1,-10]]},"gumdrop":{"label":null,"body":"M38.7 4.5l4.4-.5 4.6 .8 4.1 1.9 3.7 3.2 23.2 36.6 2.3 5 1.4 5.1 .7 6.4-.7 6.4-1.8 6.1-3.1 5.7-4.1 5.1-5.2 4.2-5.8 3.1-6 1.8-6.4 .6-6.4-.6-6-1.8-5.9-3.1-5.1-4.2-4.1-5.1-3-5.4-1.9-6.4-.7-6 .5-5.9 9-41.6 2-4.1 2.6-3.2 3.4-2.5z","eyes":[[52.1,40.3,9.7,22.9,-15.2],[64.8,35.6,6.3,23,-27]]},"peanut":{"label":null,"body":"M43.5 4l6.6 .7 5.8 2.2 5.4 3.8 4.1 4.7 2 3.8 1.4 4.3 1.3 11.9 1 4.3 1.6 3.8 5.8 10.5 1.4 3.8 .8 4.3 .1 6.2-1 5.7-2.1 5.5-3.2 4.9-4.1 4.3-4.8 3.4-5.6 2.4-5.7 1.3-6.1 .1-5.8-1.1-5.7-2.2-4.7-3.1-4.3-4.1-3.3-4.8-2.5-5.7-1.2-5.7-.1-6.7 1.7-9 .4-4.3-.5-4.7-2.5-9.6-.6-3.8 .2-5.2 1.2-5.2 1.5-3.4 2.2-3.3 2.5-2.9 2.8-2.3 3.4-2.1 3.4-1.4 3.8-.9z","eyes":[[50.9,31.5,8.7,20.5,-11.9],[64.2,26.5,5.7,20.3,-16.3]]},"saucer":{"label":null,"body":"M45 22.7l6.7 .1 6.7 1.9 4.3 2.5 3.5 3.1 2.8 3.5 2.5 4.5 6.8 .9 5.6 1.2 4.5 1.6 3.5 2.1 2.8 2.8 1.3 3.5-.5 3.5-2 3.5-2.6 2.8-3.5 2.8-4.5 2.8-5.1 2.6-12 4.4-13.6 3.1-13.6 1.5-12.6-.3-5.5-.7-5-1.2-4.1-1.6-3.5-2-2.8-3.1-1.1-3 .5-3.5 2-3.6 2.7-3 3.7-2.9 10.3-5.6 .7-5.1 1.5-4.5 2.6-4.5 3.1-3.5 3-2.4 3.5-2 3.5-1.4z","eyes":[[53.6,45,7.8,18.4,-14.5],[66.2,40.3,5,18.3,-25.1]]},"beacon":{"label":null,"body":"M40 4.1l2.7 0 2.5 .9 2 1.7 1.1 2.1 .5 2-.2 2.1-2.1 4.1-.4 1.6 1.5 7.7 9-3.1 4.1-.2 18.5 4 3.1 1.6 2.4 2.3 1.3 2.1 .9 2.6 5.8 33.4-.4 3.1-1.3 3.1-2 2.5-2.6 1.9-41.7 15.7-4.1 .7-19.6-4-3.5-1.9-2.5-2.5-1.2-2.1-.8-2.6-5.7-32.9 .4-3.1 1-2.7 1.7-2.5 2.4-1.9 28.4-10.9-1.5-9.3-.7-1-3.5-3.3-.9-1.9-.4-2 .5-2.6 1.1-2.1 1.7-1.5z","eyes":[[55.5,65.3,8.4,22.1,-10],[74.2,58.3,8.4,22.1,-10]]},"pebbles":{"label":null,"body":"M47.3 4.5l2.7-.4 2.7 .1 13.7 3 4.3 2.1 3.3 3.4 1.3 2.2 1 2.8 2 12-.5 4.3-3.1 7.7 .2 .5 8.4 1.9 2.7 1 3.3 2.1 2.7 2.8 2.4 4.3 1.4 6.5 .1 4.4-.8 3.8-1.3 2.7-2 2.8-2.4 2.2-2.7 1.6-45.5 17-3.3 .6-3.2-.2-19.2-4.2-4.9-2.8-3.4-3.8-1.9-4.4-1.3-7.7 .2-3.2 .8-2.8 1.3-2.7 2-2.7 3.2-2.8 7.9-3.8 2.5-2.2-.4-1.6-5.4-6.1-1.8-3.8-2.3-12.5 .2-3.3 .7-2.7 2.6-4.4 2.2-2 2.2-1.4z","eyes":[[51.2,34.1,6.9,18.1,-10],[66.4,28.4,6.9,18.1,-10]]},"plus":{"label":null,"body":"M44.6 4.3l3.3-.1 11.9 2.5 2.5 1.3 1.3 1.4 .7 1.6 2.1 11.4 4.1-1.2 2.1 0 12.3 2.6 2.8 1.6 1.2 1.5 .7 1.5 3.8 21.6-.5 3.1-1 1.5-1.3 1.3-17 6.6 3.4 20.4-.4 2.5-1.2 2.1-2.3 1.6-19 6.9-2-.2-11.9-2.5-2.5-1.3-1.3-1.4-.7-1.6-2.1-11.4-4.1 1.2-2.1 0-12.3-2.6-2.8-1.6-1.2-1.5-.7-1.5-3.8-21.6 .5-3.1 1-1.5 1.3-1.3 17-6.6-3.4-20.4 .2-2 1.1-2.2 2.6-2z","eyes":[[54.5,53.1,6.1,15.9,-10],[64.5,49.4,6.1,15.9,-10]]},"magnet":{"label":null,"body":"M71.9 4.2l1.2-.2 12.1 2.6 .5 .3 .6 1 6.2 35.6 .6 5.8-.1 5.7-.7 5.8-1.5 5.7-2.2 5.8-4.2 7.3-5.5 6.5-6.5 5-7.1 3.4-6.3 1.3-6.3 0-15.2-3.1-5.2-1.8-5.2-3-4.6-4.1-4-5.2-2.9-5.8-2.4-7.8-6.4-36.2 25-9.5 13.1 2.9 .5 .9 6.3 35.3 1.8-3.9 .5-4.7-6.3-36.1 .4-.6z","eyes":[[59.6,82.1,6.1,15.9,-10],[72,77.5,6.1,15.9,-10]]},"ring":{"label":null,"body":"M48.1 4.3l8-.1 7.8 1.8 7.3 3.5 6.7 5.4 5.2 6.7 4.1 8.3 2.3 8.9 .7 9-1 9.5-2.5 8.9-4.1 8.3-5.3 7.3-6.6 6.1-7.3 4.5-7.8 2.7-8.4 .9-7.2-.8-7.3-2.5-6.7-4.1-5.6-5.3-4.5-6.5-3.5-7.8-2-8.4-.6-8.4 .9-8.9 2.2-8.4 3.5-7.8 4.9-7.2 5.8-6.1 6.3-4.5 7.1-3.3zM50.5 33.8l2.3-.3 1.7 .4 1.6 1.1 2 2.2 1.3 2.8 .8 2.7 .4 3.4-.1 3.3-1.4 6.2-3 5.6-2.2 2.4-2.2 1.6-2.3 1-2.2 .3-1.7-.4-1.6-1.1-2.8-3.7-1.5-5.2-.1-5.5 1.2-5.6 2.4-5 3.6-4z","eyes":[[56.2,84.6,5.3,13.3,-6.8],[71.7,78.8,5.1,13.4,-6.5]]},"gem":{"label":null,"body":"M57 9.3l2.9-.4 14.9 3.5 19.6 14.1 1 1.4 .6 1.6-.5 2.6-27.1 56.5-1.6 1.8-2.1 .7-15.9-3.4-42.9-30.7-1.3-1.6-.6-1.6 .5-2.6 12-25.2 1.1-1.5 1.5-1z","eyes":[[51.4,42.9,6.7,17.7,-10],[66.1,37.4,6.7,17.7,-10]]}}
|
|
79
|
+
const GRADIENTS = {"aurora":[[0,"#A4FFB0"],[0.42,"#00F0E4"],[1,"#2E9EF7"]]}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
// 视图 + 角色渲染 + 样式文本各自一个作用域,避免同名工具函数互相覆盖。
|
|
83
|
+
const boardViewModule = (function () {
|
|
84
|
+
// Starboard 角色渲染与画布样式。由 .build-client.cjs 内联;不能有 import/export。
|
|
85
|
+
|
|
86
|
+
function characterMarkupOf(shapeId, size) {
|
|
87
|
+
const id = characterShapeId(shapeId)
|
|
88
|
+
const def = id ? CHARACTERS[id] : null
|
|
89
|
+
if (!def || !def.body) return null
|
|
90
|
+
const scale = size / 100
|
|
91
|
+
return { id, def, scale }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function characterShapeId(value) {
|
|
95
|
+
const raw = String(value || '')
|
|
96
|
+
const alias = {
|
|
97
|
+
zed: 'bear', wave: 'octopus', hex: 'bloom', cushion: 'squircle',
|
|
98
|
+
dolphin: 'whale', turtle: 'acorn', crab: 'octopus', puffer: 'cloud',
|
|
99
|
+
jelly: 'octopus', starfish: 'star', seahorse: 'whale',
|
|
100
|
+
}
|
|
101
|
+
const id = alias[raw] || raw
|
|
102
|
+
return Object.prototype.hasOwnProperty.call(CHARACTERS, id) ? id : null
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// DS Bot 原生 Bot 色映射成角色渐变。UI chrome 不使用这些颜色,身份色只留在角色上。
|
|
106
|
+
const BOT_GRADIENTS = {
|
|
107
|
+
deepseek: [[0, '#7c8cf8'], [1, '#4d5df5']],
|
|
108
|
+
blue: [[0, '#63b3ff'], [1, '#2f80ed']],
|
|
109
|
+
violet: [[0, '#c08cff'], [1, '#7c4dff']],
|
|
110
|
+
orange: [[0, '#ffb36b'], [1, '#f2803c']],
|
|
111
|
+
green: [[0, '#6fe0a8'], [1, '#2fae74']],
|
|
112
|
+
magenta: [[0, '#ff8cc6'], [1, '#d4408f']],
|
|
113
|
+
cyan: [[0, '#6fd8e8'], [1, '#2b93a8']],
|
|
114
|
+
red: [[0, '#ff8f8f'], [1, '#d64545']],
|
|
115
|
+
yellow: [[0, '#ffd76b'], [1, '#d9a021']],
|
|
116
|
+
brown: [[0, '#c9a27a'], [1, '#8b6a45']],
|
|
117
|
+
gray: [[0, '#b6bfcc'], [1, '#7d8794']],
|
|
118
|
+
black: [[0, '#5a626e'], [1, '#2b3038']],
|
|
119
|
+
aurora: [[0, '#A4FFB0'], [0.42, '#00F0E4'], [1, '#2E9EF7']],
|
|
120
|
+
rose: [[0, '#ffa8c0'], [1, '#d95477']],
|
|
121
|
+
sky: [[0, '#9ccfff'], [1, '#4f9bd9']],
|
|
122
|
+
tangerine: [[0, '#ffc078'], [1, '#ef8a2b']],
|
|
123
|
+
cobalt: [[0, '#8fa8ff'], [1, '#3f5ed6']],
|
|
124
|
+
charcoal: [[0, '#767d88'], [1, '#3b4048']],
|
|
125
|
+
graphite: [[0, '#8a9099'], [1, '#4c525b']],
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function gradientOf(color, seed) {
|
|
129
|
+
const key = String(color || '')
|
|
130
|
+
if (BOT_GRADIENTS[key]) return BOT_GRADIENTS[key]
|
|
131
|
+
if (GRADIENTS[key]) return GRADIENTS[key]
|
|
132
|
+
if (/^#[0-9a-f]{6}$/i.test(key)) return [[0, key], [1, shadeHex(key, -0.35)]]
|
|
133
|
+
let hash = 0
|
|
134
|
+
const text = String(seed || key || 'x')
|
|
135
|
+
for (let i = 0; i < text.length; i++) hash = (hash * 31 + text.charCodeAt(i)) >>> 0
|
|
136
|
+
const hue = hash % 360
|
|
137
|
+
return [[0, 'hsl(' + hue + ' 62% 62%)'], [1, 'hsl(' + ((hue + 28) % 360) + ' 58% 44%)']]
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function shadeHex(hex, amount) {
|
|
141
|
+
const value = parseInt(String(hex).slice(1), 16)
|
|
142
|
+
const clampByte = (channel) => Math.max(0, Math.min(255, Math.round(channel)))
|
|
143
|
+
const red = clampByte(((value >> 16) & 255) * (1 + amount))
|
|
144
|
+
const green = clampByte(((value >> 8) & 255) * (1 + amount))
|
|
145
|
+
const blue = clampByte((value & 255) * (1 + amount))
|
|
146
|
+
return '#' + ((1 << 24) + (red << 16) + (green << 8) + blue).toString(16).slice(1)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ── 与 ds-bot 宿主逐字一致的默认头像派生 ────────────────────────────────
|
|
150
|
+
// 宿主 lookOf(bot):bot 没配 avatar.shape / color 时,按 bot.id 做 FNV-1a 哈希派生角色与颜色。
|
|
151
|
+
// 看板以前自己按名字派生 + localStorage 注册表避让,导致同一个 bot 在宿主列表和看板里长成两只,
|
|
152
|
+
// 所以这里必须照抄宿主算法(常量与 ds-bot/client.js 的 DEFAULT_SHAPES / DEFAULT_COLORS 对齐)。
|
|
153
|
+
// DEFAULT_COLORS = CHARACTER_COLORS 去掉 black/gray/brown,再去掉 GRADIENTS 里有的 aurora。
|
|
154
|
+
const HOST_DEFAULT_SHAPES = ['star', 'moon', 'cloud', 'octopus', 'spark', 'bear', 'puppy', 'sprout', 'bloom', 'squircle', 'gumdrop', 'peanut', 'bunny', 'kitty', 'acorn']
|
|
155
|
+
const HOST_FALLBACK_SHAPE = 'gumdrop'
|
|
156
|
+
const HOST_DEFAULT_COLORS = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'violet', 'magenta']
|
|
157
|
+
|
|
158
|
+
function hostFnv1a(text) {
|
|
159
|
+
let value = 2166136261
|
|
160
|
+
for (let index = 0; index < text.length; index += 1) value = Math.imul(value ^ text.charCodeAt(index), 16777619)
|
|
161
|
+
return value >>> 0
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function hostDefaultColor(id) {
|
|
165
|
+
const seed = hostFnv1a(id) + 1831565813 | 0
|
|
166
|
+
let mixed = Math.imul(seed ^ seed >>> 15, 1 | seed)
|
|
167
|
+
mixed = mixed + Math.imul(mixed ^ mixed >>> 7, 61 | mixed) ^ mixed
|
|
168
|
+
return HOST_DEFAULT_COLORS[Math.floor(((mixed ^ mixed >>> 14) >>> 0) / 4294967296 * HOST_DEFAULT_COLORS.length)]
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function hostDefaultShape(id) {
|
|
172
|
+
let value = hostFnv1a(id) | 0
|
|
173
|
+
value = Math.imul(value ^ value >>> 16, 73244475)
|
|
174
|
+
value = Math.imul(value ^ value >>> 13, 3266489909)
|
|
175
|
+
return HOST_DEFAULT_SHAPES[((value ^ value >>> 16) >>> 0) % HOST_DEFAULT_SHAPES.length]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function hostIsColor(color) {
|
|
179
|
+
const key = String(color || '')
|
|
180
|
+
return /^#[0-9a-f]{6}$/i.test(key)
|
|
181
|
+
|| Object.prototype.hasOwnProperty.call(BOT_GRADIENTS, key)
|
|
182
|
+
|| Object.prototype.hasOwnProperty.call(GRADIENTS, key)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 宿主 lookOf(bot) 的等价实现:shape / color / image 三件套,看板任何地方画 bot 都走它。
|
|
186
|
+
function hostLookOf(bot) {
|
|
187
|
+
const avatar = (bot && bot.avatar) || {}
|
|
188
|
+
const stored = characterShapeId(avatar.shape)
|
|
189
|
+
return {
|
|
190
|
+
shape: stored || (bot && bot.id ? hostDefaultShape(String(bot.id)) : HOST_FALLBACK_SHAPE),
|
|
191
|
+
image: typeof avatar.image === 'string' && avatar.image.length > 0 ? avatar.image : null,
|
|
192
|
+
color: hostIsColor(bot && bot.color) ? bot.color : (bot && bot.id ? hostDefaultColor(String(bot.id)) : 'black'),
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function renderCharacter(h, opts) {
|
|
197
|
+
const { def, id, r, color, uid, status, reducedMotion, active, seed, blinkDelay, nodeKey, simple } = opts
|
|
198
|
+
const identity = String(nodeKey || seed || id).replace(/[^a-z0-9]/gi, '')
|
|
199
|
+
const gradId = uid + '-cg-' + id + '-' + identity
|
|
200
|
+
const maskId = uid + '-cm-' + id + '-' + identity
|
|
201
|
+
const stops = gradientOf(color, seed)
|
|
202
|
+
const scale = (r * 2) / 100
|
|
203
|
+
const canBlink = !reducedMotion
|
|
204
|
+
const group = {
|
|
205
|
+
'aria-hidden': 'true',
|
|
206
|
+
// Starboard里角色放大到 29–57px,曲线要抗锯齿才干净(旧像素风的 crispEdges 会出锯齿)
|
|
207
|
+
shapeRendering: 'geometricPrecision',
|
|
208
|
+
transform: 'translate(' + (-r) + ' ' + (-r) + ') scale(' + scale + ')',
|
|
209
|
+
}
|
|
210
|
+
const eyes = def.eyes
|
|
211
|
+
? h('g', { fill: '#0b1220' }, def.eyes.map(([cx, cy, width, height, tilt], index) => h('g', {
|
|
212
|
+
key: index,
|
|
213
|
+
transform: 'translate(' + cx + ' ' + cy + ') rotate(' + tilt + ')',
|
|
214
|
+
}, h('g', {
|
|
215
|
+
className: canBlink ? 'dsb-eye-blink' : undefined,
|
|
216
|
+
style: canBlink ? { animationDelay: (blinkDelay == null ? -index * 0.37 : blinkDelay) + 's' } : undefined,
|
|
217
|
+
}, h('rect', { x: -width / 2, y: -height / 2, width, height, rx: width / 2 })))))
|
|
218
|
+
: null
|
|
219
|
+
|
|
220
|
+
// 极简模式(待机坞 18px):纯色身体 + 眼睛,不建渐变与遮罩。
|
|
221
|
+
// 宿主里 url(#id) 引用偶发失效时,渐变身体会整块不画、只剩眼睛;小尺寸下纯色看不出差别。
|
|
222
|
+
if (simple) {
|
|
223
|
+
return h('g', group,
|
|
224
|
+
h('path', { d: def.body, fill: stops[0][1] }),
|
|
225
|
+
eyes)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return h('g', group,
|
|
229
|
+
h('defs', null,
|
|
230
|
+
h('linearGradient', {
|
|
231
|
+
id: gradId, gradientUnits: 'userSpaceOnUse', x1: 18, y1: 10, x2: 78, y2: 92,
|
|
232
|
+
}, stops.map(([offset, value], index) => h('stop', { key: index, offset, stopColor: value }))),
|
|
233
|
+
h('mask', {
|
|
234
|
+
id: maskId, maskUnits: 'userSpaceOnUse', x: 0, y: 0, width: 100, height: 100,
|
|
235
|
+
}, h('path', { d: def.body, fill: '#fff' }))),
|
|
236
|
+
h('g', { mask: 'url(#' + maskId + ')' },
|
|
237
|
+
h('path', { d: def.body, fill: 'url(#' + gradId + ')' }),
|
|
238
|
+
(def.paints || []).map((paint, index) => Array.isArray(paint)
|
|
239
|
+
? h('path', {
|
|
240
|
+
key: 'p' + index, d: paint[0], fill: paint[1] || '#fff',
|
|
241
|
+
opacity: typeof paint[2] === 'number' ? paint[2] : 1,
|
|
242
|
+
})
|
|
243
|
+
: null),
|
|
244
|
+
def.shade ? h('path', { d: def.shade, fill: '#000', opacity: 0.14 }) : null,
|
|
245
|
+
def.light ? h('path', { d: def.light, fill: '#fff', opacity: 0.5 }) : null),
|
|
246
|
+
eyes)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// 角色眨眼动效的 CSS 由 board-view.js 的 hiveStyleText() 提供(.dsb-eye-blink)。
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
// Starboard · 星轨蜂巢视图。由 .build-client.cjs 内联;不能有 import/export。
|
|
253
|
+
// 宿主只提供 React.createElement,所以整份视图用 h() 手写,不依赖 JSX。
|
|
254
|
+
//
|
|
255
|
+
// 关系 edgesOf 最后一条真实消息的 @ = 派活;synthetic = 等待
|
|
256
|
+
// 布局 layoutHive 主控居中,其余绕椭圆星轨;环上放不下时自动缩小舱体
|
|
257
|
+
// layoutStrip 主控在左、团队在右一到两排(多任务同屏、纵向不够时)
|
|
258
|
+
// 布线 routeBeam 径向走直线;环上互连走外弧/内弧,避开舱体与名字
|
|
259
|
+
// 渲染 HiveStage / HiveCard / HiveCanvas / HiveHud / HiveTabs / HiveDock / HiveEmpty
|
|
260
|
+
|
|
261
|
+
const HIVE_STATUS_TEXT = { working: '工作中', thinking: '思考中', waiting: '等回执', failed: '失败', user: '你' }
|
|
262
|
+
|
|
263
|
+
// DS Bot 原生 Bot 色 → 身份辉光(rgb 分量,CSS 里用 rgba(var(--dsb-tint), a))
|
|
264
|
+
const HIVE_TINT = {
|
|
265
|
+
deepseek: '124,141,255', blue: '99,179,255', violet: '192,140,255', orange: '255,179,107',
|
|
266
|
+
green: '111,224,168', cyan: '111,216,232', magenta: '255,140,198', rose: '255,168,192',
|
|
267
|
+
tangerine: '255,192,120', sky: '156,207,255', cobalt: '143,168,255', yellow: '255,215,107',
|
|
268
|
+
red: '255,143,143', brown: '201,162,122', charcoal: '150,158,170', graphite: '138,144,153',
|
|
269
|
+
gray: '182,191,204', black: '120,130,145', aurora: '120,240,220',
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// 三档密度:单任务大舱体、双任务、三个及以上任务同屏
|
|
273
|
+
// beam = 主控到卫星之间「光束」的基准长度。线优先于图标:舞台不够宽时先缩舱体,光束只缩到 BEAM_FLOOR 为止。
|
|
274
|
+
const HIVE_MODES = {
|
|
275
|
+
solo: { pod: 68, coord: 84, name: 38, padT: 18, padB: 22, padX: 40, beam: 72 },
|
|
276
|
+
duo: { pod: 50, coord: 60, name: 34, padT: 12, padB: 16, padX: 32, beam: 52 },
|
|
277
|
+
crowd: { pod: 42, coord: 50, name: 18, padT: 10, padB: 12, padX: 34, beam: 44 },
|
|
278
|
+
}
|
|
279
|
+
const BEAM_FLOOR = 34 // 再窄的面板也至少留这么长一截光束
|
|
280
|
+
const LABEL_MIN_READABLE = 46 // 名字块宽度低于这个值就只剩「DS…」这种残桩,不如整个收起(悬停可看)
|
|
281
|
+
|
|
282
|
+
// 一档密度的「最小舒适宽度」:主控 + 两颗卫星 + 两侧光束 + 左右留白。
|
|
283
|
+
// 舞台比它窄就整体等比收紧(舱体 / 名字块 / 留白一起缩),宽了保持标准尺寸——侧栏拖窄时自动变小。
|
|
284
|
+
function naturalWidthOf(modeKey) {
|
|
285
|
+
const M = HIVE_MODES[modeKey] || HIVE_MODES.duo
|
|
286
|
+
return M.coord + 2 * M.pod + 2 * M.beam + 2 * M.padX
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function densityOf(modeKey, W) {
|
|
290
|
+
if (!W) return 1
|
|
291
|
+
return Math.max(0.55, Math.min(1, (W - 8) / naturalWidthOf(modeKey)))
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// 面板宽度 → 外围 chrome(HUD / 页签 / 待机坞 / 卡片圆角)的密度系数,1 = 标准
|
|
295
|
+
function chromeDensityOf(width) {
|
|
296
|
+
if (!width) return 1
|
|
297
|
+
return Math.max(0.7, Math.min(1, width / 460))
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const HIVE_HEAD_H = 28 // 任务卡头部高度,与 .dsb-task__head 的盒模型一致
|
|
301
|
+
const HIVE_GAP = 12 // 卡片间距
|
|
302
|
+
const HIVE_PAD_X = 12 // 画布左右内边距
|
|
303
|
+
const HIVE_PAD_Y = 16 // 画布上下内边距合计
|
|
304
|
+
|
|
305
|
+
function singleTaskFills(naturalTotal, canvasHeight) {
|
|
306
|
+
return naturalTotal <= canvasHeight - HIVE_PAD_Y + 1
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function hiveStyleText() {
|
|
310
|
+
return [
|
|
311
|
+
'.dsb-root { position: relative; height: 100%; min-height: 0; display: flex; flex-direction: column; overflow: hidden;',
|
|
312
|
+
' font-family: var(--dsb-font); color: var(--dsb-text-1); -webkit-font-smoothing: antialiased;',
|
|
313
|
+
' background: radial-gradient(130% 80% at 50% -10%, var(--dsb-stage-2) 0%, var(--dsb-stage-1) 46%, var(--dsb-stage-0) 100%); }',
|
|
314
|
+
'.dsb-root *, .dsb-root *::before, .dsb-root *::after { box-sizing: border-box; }',
|
|
315
|
+
'.dsb-root::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;',
|
|
316
|
+
' background-image: radial-gradient(var(--dsb-star) .8px, transparent 1.1px), radial-gradient(var(--dsb-star) .6px, transparent 1px);',
|
|
317
|
+
' background-size: 58px 58px, 97px 97px; background-position: 0 0, 31px 47px;',
|
|
318
|
+
' -webkit-mask-image: radial-gradient(120% 90% at 50% 30%, #000 0%, transparent 78%);',
|
|
319
|
+
' mask-image: radial-gradient(120% 90% at 50% 30%, #000 0%, transparent 78%); }',
|
|
320
|
+
|
|
321
|
+
// ── HUD ──(--dsb-k = 面板密度:侧栏拖窄时外围 chrome 一起收紧)
|
|
322
|
+
'.dsb-hud { position: relative; z-index: 1; flex: 0 0 auto; padding: calc(12px * var(--dsb-k, 1)) calc(14px * var(--dsb-k, 1)) calc(10px * var(--dsb-k, 1)); display: grid;',
|
|
323
|
+
' grid-template-columns: auto 1fr auto; column-gap: calc(10px * var(--dsb-k, 1)); row-gap: calc(9px * var(--dsb-k, 1)); align-items: center; }',
|
|
324
|
+
'.dsb-hud__brand { width: calc(34px * var(--dsb-k, 1)); height: calc(34px * var(--dsb-k, 1)); border-radius: calc(11px * var(--dsb-k, 1)); display: grid; place-items: center; color: #fff;',
|
|
325
|
+
' background: linear-gradient(140deg, #6f80ff 0%, #4d6bfe 45%, #2f49d8 100%);',
|
|
326
|
+
' box-shadow: 0 0 0 1px rgba(255,255,255,.14) inset, 0 8px 22px -8px rgba(77,107,254,.9); }',
|
|
327
|
+
'.dsb-hud__title { display: flex; align-items: center; gap: calc(8px * var(--dsb-k, 1)); font-size: max(12px, calc(15px * var(--dsb-k, 1))); font-weight: 700; letter-spacing: .01em; }',
|
|
328
|
+
'.dsb-hud__live { width: 7px; height: 7px; border-radius: 50%; background: var(--dsb-ok);',
|
|
329
|
+
' box-shadow: 0 0 0 3px rgba(43,217,138,.18); animation: dsb-pulse 2.4s ease-in-out infinite; }',
|
|
330
|
+
'.dsb-hud__live[data-stale="true"] { background: var(--dsb-wait); box-shadow: 0 0 0 3px rgba(242,184,75,.18); animation: none; }',
|
|
331
|
+
'.dsb-hud__sub { margin-top: 2px; font-size: max(10px, calc(11.5px * var(--dsb-k, 1))); color: var(--dsb-text-3); display: flex; gap: 6px; align-items: center; white-space: nowrap; }',
|
|
332
|
+
'.dsb-hud__sub b { font-family: var(--dsb-mono); font-weight: 600; color: var(--dsb-text-2); }',
|
|
333
|
+
'.dsb-hud__sub .dsb-amber { color: var(--dsb-wait); }',
|
|
334
|
+
'.dsb-hud__actions { display: flex; gap: calc(6px * var(--dsb-k, 1)); }',
|
|
335
|
+
'.dsb-hud__btn { width: calc(30px * var(--dsb-k, 1)); height: calc(30px * var(--dsb-k, 1)); border-radius: calc(9px * var(--dsb-k, 1)); border: 1px solid var(--dsb-hair); padding: 0;',
|
|
336
|
+
' background: var(--dsb-card); color: var(--dsb-text-2); display: grid; place-items: center; cursor: pointer;',
|
|
337
|
+
' transition: background-color .15s ease, border-color .15s ease, color .15s ease; }',
|
|
338
|
+
'.dsb-hud__btn:hover { color: var(--dsb-text-1); border-color: var(--dsb-card-border); }',
|
|
339
|
+
'.dsb-hud__btn[data-active="true"] { color: var(--dsb-accent-2); border-color: rgba(124,141,255,.45); background: rgba(77,107,254,.14); }',
|
|
340
|
+
'.dsb-hud__btn:focus-visible, .dsb-tab:focus-visible, .dsb-retry:focus-visible, .dsb-dock__item:focus-visible { outline: 2px solid var(--dsb-accent-2); outline-offset: 2px; }',
|
|
341
|
+
'.dsb-hud__meter { grid-column: 1 / -1; height: 4px; border-radius: 99px; display: flex; gap: 3px; }',
|
|
342
|
+
'.dsb-hud__meter i { display: block; height: 100%; border-radius: 99px; }',
|
|
343
|
+
'.dsb-hud__meter .dsb-m-work { background: linear-gradient(90deg, var(--dsb-accent), var(--dsb-cyan)); box-shadow: 0 0 12px rgba(98,214,255,.45); }',
|
|
344
|
+
'.dsb-hud__meter .dsb-m-wait { background: var(--dsb-wait); }',
|
|
345
|
+
'.dsb-hud__meter .dsb-m-idle { background: var(--dsb-orbit); }',
|
|
346
|
+
|
|
347
|
+
// ── 任务页签 ──
|
|
348
|
+
'.dsb-tabs { position: relative; z-index: 1; flex: 0 0 auto; display: flex; gap: calc(6px * var(--dsb-k, 1)); padding: 0 calc(14px * var(--dsb-k, 1)) calc(10px * var(--dsb-k, 1)); overflow-x: auto; scrollbar-width: none; }',
|
|
349
|
+
'.dsb-tabs::-webkit-scrollbar { display: none; }',
|
|
350
|
+
'.dsb-tab { flex: 0 0 auto; height: calc(26px * var(--dsb-k, 1)); padding: 0 calc(11px * var(--dsb-k, 1)) 0 calc(9px * var(--dsb-k, 1)); border-radius: 99px; display: inline-flex; align-items: center; gap: calc(6px * var(--dsb-k, 1));',
|
|
351
|
+
' font: inherit; font-size: max(10.5px, calc(11.5px * var(--dsb-k, 1))); font-weight: 600; color: var(--dsb-text-2); background: var(--dsb-card);',
|
|
352
|
+
' border: 1px solid var(--dsb-hair); white-space: nowrap; cursor: pointer;',
|
|
353
|
+
' transition: background-color .15s ease, border-color .15s ease, color .15s ease; }',
|
|
354
|
+
'.dsb-tab i { width: 6px; height: 6px; border-radius: 50%; background: rgb(var(--dsb-tint, 124,141,255)); box-shadow: 0 0 8px rgb(var(--dsb-tint, 124,141,255)); }',
|
|
355
|
+
'.dsb-tab:hover { color: var(--dsb-text-1); }',
|
|
356
|
+
'.dsb-tab[aria-pressed="true"] { color: var(--dsb-text-1); background: rgba(77,107,254,.16); border-color: rgba(124,141,255,.5); }',
|
|
357
|
+
|
|
358
|
+
// ── 画布与任务卡 ──
|
|
359
|
+
'.dsb-canvas { position: relative; z-index: 1; flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto;',
|
|
360
|
+
' padding: 2px 12px 14px; display: grid; grid-template-columns: 1fr; grid-auto-rows: max-content; gap: 12px;',
|
|
361
|
+
' align-content: start; align-items: stretch; scrollbar-width: thin; scrollbar-color: var(--dsb-scroll) transparent; }',
|
|
362
|
+
'.dsb-canvas[data-cols="2"] { grid-template-columns: 1fr 1fr; }',
|
|
363
|
+
'.dsb-canvas[data-empty="true"] { align-content: center; }',
|
|
364
|
+
'.dsb-canvas[data-center="true"] { align-content: center; }',
|
|
365
|
+
'.dsb-canvas[data-fill="true"] { grid-auto-rows: minmax(0, 1fr); }',
|
|
366
|
+
'.dsb-canvas::-webkit-scrollbar { width: 6px; }',
|
|
367
|
+
'.dsb-canvas::-webkit-scrollbar-thumb { background: var(--dsb-scroll); border-radius: 99px; }',
|
|
368
|
+
'.dsb-canvas::-webkit-scrollbar-track { background: transparent; }',
|
|
369
|
+
'.dsb-task { position: relative; display: flex; flex-direction: column; border-radius: calc(18px * var(--dsb-k, 1)); border: 1px solid var(--dsb-card-border);',
|
|
370
|
+
' background: var(--dsb-card); box-shadow: var(--dsb-shadow-card), inset 0 1px 0 var(--dsb-card-hi); overflow: hidden; }',
|
|
371
|
+
'.dsb-task::before { content: ""; position: absolute; inset: 0; pointer-events: none;',
|
|
372
|
+
' background: radial-gradient(120% 90% at 50% -20%, rgba(var(--dsb-card-tint, 124,141,255), .22), transparent 62%); }',
|
|
373
|
+
'.dsb-task__head { position: relative; display: flex; align-items: center; gap: calc(8px * var(--dsb-k, 1)); padding: calc(10px * var(--dsb-k, 1)) calc(12px * var(--dsb-k, 1)) 0; height: 28px; flex: 0 0 auto; }',
|
|
374
|
+
'.dsb-task__dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: rgb(var(--dsb-card-tint, 124,141,255));',
|
|
375
|
+
' box-shadow: 0 0 10px rgb(var(--dsb-card-tint, 124,141,255)); }',
|
|
376
|
+
'.dsb-task__name { font-size: max(11px, calc(12.5px * var(--dsb-k, 1))); font-weight: 700; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }',
|
|
377
|
+
'.dsb-task__stats { margin-left: auto; font-size: max(10px, calc(11px * var(--dsb-k, 1))); color: var(--dsb-text-3); display: flex; gap: 6px; align-items: center; white-space: nowrap; flex: 0 0 auto; }',
|
|
378
|
+
'.dsb-task__stats b { font-family: var(--dsb-mono); font-weight: 600; color: var(--dsb-text-2); }',
|
|
379
|
+
'.dsb-task__stats .dsb-amber { color: var(--dsb-wait); }',
|
|
380
|
+
'.dsb-stage { position: relative; flex: 1 1 auto; min-height: 0; }',
|
|
381
|
+
'.dsb-beams { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }',
|
|
382
|
+
'.dsb-orbit { fill: none; stroke: var(--dsb-orbit); stroke-width: 1; stroke-dasharray: 2 7; stroke-linecap: round; }',
|
|
383
|
+
|
|
384
|
+
// ── 角色舱(玻璃舱) ──
|
|
385
|
+
// .dsb-pod 的原点 = 舱体圆心;名字块绝对定位在圆心下方或上方,光束端点才能对准。
|
|
386
|
+
'.dsb-pod { position: absolute; width: 0; height: 0; margin: 0; padding: 0; border: 0; background: none;',
|
|
387
|
+
' font: inherit; color: inherit; text-align: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }',
|
|
388
|
+
'.dsb-pod--static { cursor: default; }',
|
|
389
|
+
'.dsb-pod:focus { outline: none; }',
|
|
390
|
+
'.dsb-pod:focus-visible .dsb-pod__body { box-shadow: 0 0 0 2px var(--dsb-accent-2), var(--dsb-pod-shadow); }',
|
|
391
|
+
'.dsb-pod:hover .dsb-pod__body { filter: brightness(1.08); }',
|
|
392
|
+
'.dsb-pod__glow { position: absolute; top: calc(var(--dsb-pod) / -2 - 10px); left: calc(var(--dsb-pod) / -2 - 10px);',
|
|
393
|
+
' width: calc(var(--dsb-pod) + 20px); height: calc(var(--dsb-pod) + 20px); border-radius: 50%; pointer-events: none;',
|
|
394
|
+
' background: radial-gradient(circle, rgba(var(--dsb-tint), .34) 0%, rgba(var(--dsb-tint), .10) 44%, transparent 70%); }',
|
|
395
|
+
'.dsb-pod__body { position: absolute; top: calc(var(--dsb-pod) / -2); left: calc(var(--dsb-pod) / -2); width: var(--dsb-pod); height: var(--dsb-pod);',
|
|
396
|
+
' border-radius: 50%; display: grid; place-items: center; background: var(--dsb-pod-bg); box-shadow: var(--dsb-pod-shadow);',
|
|
397
|
+
' transition: filter .15s ease; }',
|
|
398
|
+
'.dsb-pod__body::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 1px solid var(--dsb-pod-ring); pointer-events: none; }',
|
|
399
|
+
'.dsb-pod__char { position: relative; display: grid; place-items: center; filter: drop-shadow(0 3px 6px rgba(0,0,0,.45));',
|
|
400
|
+
' animation: dsb-ava-work 2.4s ease-in-out infinite; animation-delay: var(--dsb-ava-delay, 0s); }',
|
|
401
|
+
// 头像动效:按状态换动作,幅度都压得很小,别抢光束的戏
|
|
402
|
+
'.dsb-pod--thinking .dsb-pod__char { animation: dsb-ava-think 3.4s ease-in-out infinite; }',
|
|
403
|
+
'.dsb-pod--waiting .dsb-pod__char { animation: dsb-ava-breathe 2.2s ease-in-out infinite; }',
|
|
404
|
+
'.dsb-pod--failed .dsb-pod__char { animation: dsb-ava-shake 6s ease-in-out infinite; }',
|
|
405
|
+
'.dsb-pod--user .dsb-pod__char { animation: none; }',
|
|
406
|
+
'.dsb-pod__char img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }',
|
|
407
|
+
'.dsb-pod__user { display: grid; place-items: center; color: var(--dsb-text-2); }',
|
|
408
|
+
'.dsb-pod__letter { font-size: 12px; font-weight: 700; color: var(--dsb-text-2); }',
|
|
409
|
+
'.dsb-pod__ring { position: absolute; inset: -5px; width: calc(100% + 10px); height: calc(100% + 10px); pointer-events: none; overflow: visible; }',
|
|
410
|
+
'.dsb-pod__ring circle { fill: none; stroke-width: 2; }',
|
|
411
|
+
'.dsb-pod__ring .dsb-halo, .dsb-pod__ring .dsb-tick { opacity: 0; }',
|
|
412
|
+
'.dsb-pod__ring .dsb-gold { stroke: #f2c96b; stroke-width: 1.3; opacity: .9; }',
|
|
413
|
+
'.dsb-pod--working .dsb-pod__ring .dsb-arc { stroke: var(--dsb-accent-2); stroke-linecap: round; stroke-dasharray: 34 96; transform-origin: 50% 50%; animation: dsb-spin 2.6s linear infinite; }',
|
|
414
|
+
'.dsb-pod--thinking .dsb-pod__ring .dsb-arc { stroke: var(--dsb-cyan); stroke-linecap: round; stroke-dasharray: 12 20; transform-origin: 50% 50%; animation: dsb-spin 3.4s linear infinite; }',
|
|
415
|
+
'.dsb-pod--waiting .dsb-pod__ring .dsb-arc { stroke: var(--dsb-wait); stroke-linecap: round; stroke-dasharray: 5 7; transform-origin: 50% 50%; animation: dsb-breathe 2.2s ease-in-out infinite; }',
|
|
416
|
+
'.dsb-pod--failed .dsb-pod__ring .dsb-arc { stroke: var(--dsb-fail); stroke-linecap: round; stroke-dasharray: 96 0; }',
|
|
417
|
+
'.dsb-pod--user .dsb-pod__ring .dsb-arc { stroke: var(--dsb-text-3); stroke-linecap: round; stroke-dasharray: 2 6; }',
|
|
418
|
+
'.dsb-pod__pulse { position: absolute; top: calc(var(--dsb-pod) / -2 - 5px); left: calc(var(--dsb-pod) / -2 - 5px);',
|
|
419
|
+
' width: calc(var(--dsb-pod) + 10px); height: calc(var(--dsb-pod) + 10px); border-radius: 50%; border: 1.5px solid var(--dsb-wait);',
|
|
420
|
+
' opacity: 0; animation: dsb-ripple 2.2s ease-out infinite; pointer-events: none; }',
|
|
421
|
+
// 标签宽度由布局算好(--dsb-label-w),不用 max-content:标签绝对定位在 0 宽的舱体里,
|
|
422
|
+
// 内在尺寸在宿主里会被算成随机宽度(出现过「Software En…」这种误截断)。
|
|
423
|
+
// 名字块字号固定 12px / 10.5px:窄面板里只缩舱体与留白,字号再小会截断且难读
|
|
424
|
+
'.dsb-pod__label { position: absolute; left: 0; top: calc(var(--dsb-pod) / 2 + 7px); transform: translateX(calc(-50% + var(--dsb-shift, 0px)));',
|
|
425
|
+
' display: flex; flex-direction: column; align-items: center; pointer-events: none; width: var(--dsb-label-w, max-content); }',
|
|
426
|
+
'.dsb-pod--up .dsb-pod__label { top: auto; bottom: calc(var(--dsb-pod) / 2 + 7px); flex-direction: column-reverse; }',
|
|
427
|
+
'.dsb-pod__name { font-size: 12px; font-weight: 650; line-height: 1.15; text-align: center; max-width: var(--dsb-name-max, 112px); overflow: hidden;',
|
|
428
|
+
' text-shadow: var(--dsb-name-shadow); white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 5px; width: 100%; }',
|
|
429
|
+
'.dsb-pod__name > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }',
|
|
430
|
+
'.dsb-pod--coord .dsb-pod__name { max-width: 156px; }',
|
|
431
|
+
'.dsb-pod__meta { margin-top: 2px; font-size: 10.5px; line-height: 1.1; color: var(--dsb-text-3); display: flex; align-items: center; gap: 4px; white-space: nowrap; }',
|
|
432
|
+
'.dsb-pod--up .dsb-pod__meta { margin-top: 0; margin-bottom: 2px; }',
|
|
433
|
+
'.dsb-pod__meta i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }',
|
|
434
|
+
'.dsb-pod--working .dsb-pod__meta { color: var(--dsb-accent-2); }',
|
|
435
|
+
'.dsb-pod--thinking .dsb-pod__meta { color: var(--dsb-cyan); }',
|
|
436
|
+
'.dsb-pod--waiting .dsb-pod__meta { color: var(--dsb-wait); }',
|
|
437
|
+
'.dsb-pod--failed .dsb-pod__meta { color: var(--dsb-fail); }',
|
|
438
|
+
'.dsb-pod__crown { flex: 0 0 auto; height: 13px; padding: 0 5px; border-radius: 99px;',
|
|
439
|
+
' font-size: 9px; font-weight: 700; letter-spacing: .04em; display: inline-flex; align-items: center; color: #0b1020; white-space: nowrap;',
|
|
440
|
+
' text-shadow: none; background: linear-gradient(180deg, #ffe9a8, #f2b84b); box-shadow: 0 3px 8px -4px rgba(242,184,75,.8); }',
|
|
441
|
+
'.dsb-pod--user .dsb-pod__name { color: var(--dsb-text-2); }',
|
|
442
|
+
'.dsb-pod--user .dsb-pod__body { background: radial-gradient(circle at 50% 28%, rgba(255,255,255,.12), rgba(255,255,255,.03) 70%); }',
|
|
443
|
+
|
|
444
|
+
// 紧凑模式(多任务同屏):只留名字,状态靠环与色
|
|
445
|
+
'.dsb-task[data-mode="crowd"] .dsb-pod__label { top: calc(var(--dsb-pod) / 2 + 5px); }',
|
|
446
|
+
'.dsb-task[data-mode="crowd"] .dsb-pod--up .dsb-pod__label { top: auto; bottom: calc(var(--dsb-pod) / 2 + 5px); }',
|
|
447
|
+
'.dsb-task[data-mode="crowd"] .dsb-pod__name { font-size: 11px; }',
|
|
448
|
+
'.dsb-task[data-mode="crowd"] .dsb-pod__meta { display: none; }',
|
|
449
|
+
'.dsb-task[data-mode="crowd"] .dsb-pod__crown { height: 12px; font-size: 8.5px; padding: 0 4px; }',
|
|
450
|
+
|
|
451
|
+
// 传送带模式(多任务同屏且纵向不够):只留名字,名字过长省略
|
|
452
|
+
'.dsb-task[data-mode="strip"] .dsb-pod__label { top: calc(var(--dsb-pod) / 2 + 5px); }',
|
|
453
|
+
'.dsb-task[data-mode="strip"] .dsb-pod--up .dsb-pod__label { top: auto; bottom: calc(var(--dsb-pod) / 2 + 5px); }',
|
|
454
|
+
'.dsb-task[data-mode="strip"] .dsb-pod__meta { display: none; }',
|
|
455
|
+
'.dsb-task[data-mode="strip"] .dsb-pod__name { font-size: 11px; }',
|
|
456
|
+
'.dsb-task[data-mode="strip"] .dsb-pod__name > span:last-child { display: inline-block; max-width: var(--dsb-name-max, 74px); overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }',
|
|
457
|
+
'.dsb-root .dsb-pod__name > span:last-child { max-width: var(--dsb-name-max, 112px); }',
|
|
458
|
+
'.dsb-task[data-mode="strip"] .dsb-pod__crown { height: 12px; font-size: 8.5px; padding: 0 4px; }',
|
|
459
|
+
|
|
460
|
+
// ── 待机坞 ──(格子与头像跟着面板密度缩,窄侧栏里不再是一排 30px 大圆)
|
|
461
|
+
'.dsb-dock { position: relative; z-index: 1; flex: 0 0 auto; margin: 0 calc(12px * var(--dsb-k, 1)) calc(12px * var(--dsb-k, 1)); padding: calc(8px * var(--dsb-k, 1)) calc(10px * var(--dsb-k, 1)) calc(9px * var(--dsb-k, 1)); border-radius: calc(14px * var(--dsb-k, 1));',
|
|
462
|
+
' background: var(--dsb-dock); border: 1px solid var(--dsb-hair); backdrop-filter: blur(8px); box-shadow: inset 0 1px 0 var(--dsb-card-hi); }',
|
|
463
|
+
'.dsb-dock__head { display: flex; align-items: center; gap: 6px; font-size: max(9.5px, calc(10.5px * var(--dsb-k, 1))); font-weight: 650; color: var(--dsb-text-3); letter-spacing: .06em; }',
|
|
464
|
+
'.dsb-dock__head b { font-family: var(--dsb-mono); color: var(--dsb-text-2); }',
|
|
465
|
+
'.dsb-dock__row { margin-top: calc(7px * var(--dsb-k, 1)); display: flex; gap: calc(7px * var(--dsb-k, 1)); flex-wrap: wrap; }',
|
|
466
|
+
'.dsb-dock__item { position: relative; width: calc(30px * var(--dsb-k, 1)); height: calc(30px * var(--dsb-k, 1)); padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center;',
|
|
467
|
+
' background: var(--dsb-pod-bg); box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 0 0 1px var(--dsb-pod-ring); opacity: .62; cursor: pointer;',
|
|
468
|
+
' animation: dsb-float 5.6s ease-in-out infinite; transition: opacity .15s ease, transform .15s ease; }',
|
|
469
|
+
'.dsb-dock__item:nth-child(2n) { animation-delay: -1.7s; }',
|
|
470
|
+
'.dsb-dock__item:nth-child(3n) { animation-delay: -3.1s; }',
|
|
471
|
+
'.dsb-dock__item:hover { opacity: 1; }',
|
|
472
|
+
// 头像要显式给尺寸:宿主里有 button > svg 之类的全局规则会把只带 width/height 属性的 svg 压成几像素
|
|
473
|
+
'.dsb-dock__glyph { display: grid; place-items: center; width: calc(20px * var(--dsb-k, 1)); height: calc(20px * var(--dsb-k, 1)); flex: 0 0 auto;',
|
|
474
|
+
' animation: dsb-ava-idle 4.2s ease-in-out infinite; }',
|
|
475
|
+
'.dsb-dock__glyph > svg { display: block; width: calc(18px * var(--dsb-k, 1)); height: calc(18px * var(--dsb-k, 1)); flex: 0 0 auto; }',
|
|
476
|
+
'.dsb-dock__item:nth-child(2n) .dsb-dock__glyph { animation-delay: -1.4s; }',
|
|
477
|
+
'.dsb-dock__item:nth-child(3n) .dsb-dock__glyph { animation-delay: -2.8s; }',
|
|
478
|
+
'.dsb-dock__item:nth-child(5n) .dsb-dock__glyph { animation-delay: -3.6s; }',
|
|
479
|
+
'.dsb-dock__letter { font-size: 11px; font-weight: 700; color: var(--dsb-text-2); }',
|
|
480
|
+
|
|
481
|
+
// ── 空状态 ──
|
|
482
|
+
'.dsb-empty { grid-column: 1 / -1; position: relative; display: grid; place-items: center; text-align: center; padding: 40px 20px; min-height: 260px; }',
|
|
483
|
+
'.dsb-empty__orbit { position: absolute; width: 220px; height: 220px; border-radius: 50%; border: 1px dashed var(--dsb-orbit); animation: dsb-spin 40s linear infinite; }',
|
|
484
|
+
'.dsb-empty__orbit::after { content: ""; position: absolute; top: -4px; left: 50%; width: 8px; height: 8px; border-radius: 50%;',
|
|
485
|
+
' background: var(--dsb-accent-2); box-shadow: 0 0 12px var(--dsb-accent-2); }',
|
|
486
|
+
'.dsb-empty__core { position: relative; margin: 0 auto; width: 54px; height: 54px; border-radius: 50%; background: var(--dsb-pod-bg);',
|
|
487
|
+
' box-shadow: var(--dsb-pod-shadow); display: grid; place-items: center; color: var(--dsb-text-3); }',
|
|
488
|
+
'.dsb-empty__title { position: relative; margin-top: 16px; font-size: 13.5px; font-weight: 650; color: var(--dsb-text-2); }',
|
|
489
|
+
'.dsb-empty__sub { position: relative; margin-top: 6px; font-size: 11.5px; color: var(--dsb-text-3); }',
|
|
490
|
+
|
|
491
|
+
// ── 局部提示 / 骨架 / 错误 ──
|
|
492
|
+
'.dsb-banner { position: relative; z-index: 1; flex: 0 0 auto; display: flex; align-items: center; gap: 6px; margin: 0 calc(12px * var(--dsb-k, 1)) calc(8px * var(--dsb-k, 1)); padding: 6px 10px;',
|
|
493
|
+
' border-radius: 10px; border: 1px solid rgba(242,184,75,.28); background: rgba(242,184,75,.10); color: var(--dsb-wait); font-size: 11px; }',
|
|
494
|
+
'.dsb-skeleton { position: relative; z-index: 1; flex: 1 1 auto; min-height: 0; padding: 16px; display: flex; flex-direction: column; gap: 12px; }',
|
|
495
|
+
'.dsb-skeleton__row, .dsb-skeleton__dot { background: linear-gradient(100deg, var(--dsb-card) 20%, var(--dsb-card-hi) 45%, var(--dsb-card) 70%);',
|
|
496
|
+
' background-size: 220% 100%; animation: dsb-skeleton-flow 1.4s ease-in-out infinite; border-radius: 10px; }',
|
|
497
|
+
'.dsb-skeleton__stage { position: relative; flex: 1 1 auto; min-height: 180px; }',
|
|
498
|
+
'.dsb-skeleton__dot { position: absolute; border-radius: 50%; }',
|
|
499
|
+
'.dsb-error { position: relative; z-index: 1; flex: 1 1 auto; min-height: 0; display: grid; place-items: center; padding: 24px; }',
|
|
500
|
+
'.dsb-error__box { max-width: 280px; text-align: center; }',
|
|
501
|
+
'.dsb-error__icon { display: flex; justify-content: center; color: var(--dsb-fail); margin-bottom: 12px; }',
|
|
502
|
+
'.dsb-error__title { font-size: 12.5px; font-weight: 650; margin-bottom: 4px; }',
|
|
503
|
+
'.dsb-error__msg { font-size: 11px; line-height: 1.7; color: var(--dsb-text-2); font-family: var(--dsb-mono); word-break: break-word; }',
|
|
504
|
+
'.dsb-retry { margin-top: 16px; display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px;',
|
|
505
|
+
' border: 1px solid var(--dsb-card-border); background: var(--dsb-card); color: var(--dsb-text-1); font: inherit; font-size: 11px; cursor: pointer; }',
|
|
506
|
+
'.dsb-retry:hover { border-color: var(--dsb-accent-2); }',
|
|
507
|
+
|
|
508
|
+
'@keyframes dsb-pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }',
|
|
509
|
+
'@keyframes dsb-spin { to { transform: rotate(360deg) } }',
|
|
510
|
+
'@keyframes dsb-breathe { 0%,100% { opacity: 1 } 50% { opacity: .45 } }',
|
|
511
|
+
'@keyframes dsb-ripple { 0% { transform: scale(1); opacity: .55 } 100% { transform: scale(1.34); opacity: 0 } }',
|
|
512
|
+
'@keyframes dsb-float { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-1.5px) } }',
|
|
513
|
+
'@keyframes dsb-skeleton-flow { from { background-position: 120% 0 } to { background-position: -120% 0 } }',
|
|
514
|
+
'@keyframes dsb-eye-blink { 0%,90%,100% { transform: scaleY(1) } 95% { transform: scaleY(.08) } }',
|
|
515
|
+
'.dsb-root .dsb-eye-blink { transform-box: fill-box; transform-origin: center; animation: dsb-eye-blink 4.6s ease-in-out infinite; }',
|
|
516
|
+
// 头像动效:干活=点头、思考=歪头晃、等待=呼吸、失败=偶尔抖一下、待命=慢呼吸
|
|
517
|
+
'@keyframes dsb-ava-work { 0%,100% { transform: translateY(0) rotate(0deg) } 30% { transform: translateY(-1.6px) rotate(-2.5deg) } 65% { transform: translateY(-.6px) rotate(2deg) } }',
|
|
518
|
+
'@keyframes dsb-ava-think { 0%,100% { transform: rotate(-5deg) translateY(0) } 50% { transform: rotate(5deg) translateY(-1px) } }',
|
|
519
|
+
'@keyframes dsb-ava-breathe { 0%,100% { transform: scale(1) } 50% { transform: scale(1.07) } }',
|
|
520
|
+
'@keyframes dsb-ava-shake { 0%,84%,100% { transform: translateX(0) } 88% { transform: translateX(-2px) } 92% { transform: translateX(2px) } 96% { transform: translateX(-1px) } }',
|
|
521
|
+
'@keyframes dsb-ava-idle { 0%,100% { transform: scale(1) } 50% { transform: scale(1.08) } }',
|
|
522
|
+
|
|
523
|
+
// 动效开关与系统 reduced-motion:CSS 动画全部停掉(SMIL 由组件按 motion 开关决定是否渲染)
|
|
524
|
+
'.dsb-motion-off .dsb-pod__ring .dsb-arc, .dsb-motion-off .dsb-pod__pulse, .dsb-motion-off .dsb-hud__live,',
|
|
525
|
+
'.dsb-motion-off .dsb-dock__item, .dsb-motion-off .dsb-empty__orbit, .dsb-motion-off .dsb-skeleton__row,',
|
|
526
|
+
'.dsb-motion-off .dsb-skeleton__dot, .dsb-motion-off .dsb-eye-blink,',
|
|
527
|
+
'.dsb-motion-off .dsb-pod__char, .dsb-motion-off .dsb-dock__glyph { animation: none !important; }',
|
|
528
|
+
'.dsb-motion-off .dsb-skeleton__row, .dsb-motion-off .dsb-skeleton__dot { background: var(--dsb-card); }',
|
|
529
|
+
'@media (prefers-reduced-motion: reduce) {',
|
|
530
|
+
' .dsb-root .dsb-pod__ring .dsb-arc, .dsb-root .dsb-pod__pulse, .dsb-root .dsb-hud__live, .dsb-root .dsb-dock__item,',
|
|
531
|
+
' .dsb-root .dsb-empty__orbit, .dsb-root .dsb-skeleton__row, .dsb-root .dsb-skeleton__dot, .dsb-root .dsb-eye-blink,',
|
|
532
|
+
' .dsb-root .dsb-pod__char, .dsb-root .dsb-dock__glyph { animation: none !important; }',
|
|
533
|
+
' .dsb-root .dsb-skeleton__row, .dsb-root .dsb-skeleton__dot { background: var(--dsb-card); }',
|
|
534
|
+
'}',
|
|
535
|
+
].join('\n')
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function createBoardView(React) {
|
|
539
|
+
const h = React.createElement
|
|
540
|
+
const Fragment = React.Fragment
|
|
541
|
+
const { useState, useLayoutEffect, useMemo, useRef, useEffect } = React
|
|
542
|
+
|
|
543
|
+
const tintOf = (color) => HIVE_TINT[color] || '124,141,255'
|
|
544
|
+
|
|
545
|
+
// ── 关系:最后一条真实消息的 @ = 派活;synthetic = 等待 ──
|
|
546
|
+
function edgesOf(group) {
|
|
547
|
+
const byName = {}
|
|
548
|
+
for (const node of group.nodes) byName[node.name] = node
|
|
549
|
+
const out = []
|
|
550
|
+
const seen = {}
|
|
551
|
+
const waits = group.messages.filter((m) => m.synthetic)
|
|
552
|
+
for (const m of waits) {
|
|
553
|
+
const target = byName[(m.to || [])[0]]
|
|
554
|
+
if (!target || !m.botId) continue
|
|
555
|
+
const key = m.botId + '>' + target.id
|
|
556
|
+
if (seen[key]) continue
|
|
557
|
+
seen[key] = 1
|
|
558
|
+
out.push({ from: m.botId, to: target.id, kind: 'wait' })
|
|
559
|
+
}
|
|
560
|
+
const real = group.messages.filter((m) => !m.synthetic)
|
|
561
|
+
const last = real[real.length - 1]
|
|
562
|
+
if (last) {
|
|
563
|
+
const fromId = last.botId || (last.who === 'User' ? '__user__' : '')
|
|
564
|
+
for (const name of last.to || []) {
|
|
565
|
+
const target = byName[name]
|
|
566
|
+
if (!target || !fromId || target.id === fromId) continue
|
|
567
|
+
const key = fromId + '>' + target.id
|
|
568
|
+
if (seen[key]) continue
|
|
569
|
+
seen[key] = 1
|
|
570
|
+
out.push({ from: fromId, to: target.id, kind: 'cur' })
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return out
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// ── 布局:主控居中,其余绕椭圆星轨 ──
|
|
577
|
+
// 环上角度:先给等角基准,再按椭圆弧长均匀重排(高瘦椭圆上等角会让上下挤、两侧空)
|
|
578
|
+
function anglesFor(n) {
|
|
579
|
+
if (n <= 0) return []
|
|
580
|
+
if (n === 1) return [0]
|
|
581
|
+
if (n === 2) return [180, 0]
|
|
582
|
+
const out = []
|
|
583
|
+
for (let i = 0; i < n; i++) out.push(-90 + (i * 360) / n)
|
|
584
|
+
return out
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function evenAngles(rx, ry, n) {
|
|
588
|
+
if (n < 3) return anglesFor(n)
|
|
589
|
+
const STEPS = 360
|
|
590
|
+
const cum = [0]
|
|
591
|
+
let px = rx * Math.cos(-Math.PI / 2)
|
|
592
|
+
let py = ry * Math.sin(-Math.PI / 2)
|
|
593
|
+
for (let i = 1; i <= STEPS; i++) {
|
|
594
|
+
const a = -Math.PI / 2 + (i / STEPS) * 2 * Math.PI
|
|
595
|
+
const x = rx * Math.cos(a)
|
|
596
|
+
const y = ry * Math.sin(a)
|
|
597
|
+
cum.push(cum[i - 1] + Math.hypot(x - px, y - py))
|
|
598
|
+
px = x
|
|
599
|
+
py = y
|
|
600
|
+
}
|
|
601
|
+
const total = cum[STEPS]
|
|
602
|
+
const out = []
|
|
603
|
+
for (let k = 0; k < n; k++) {
|
|
604
|
+
const target = (k / n) * total
|
|
605
|
+
let i = 1
|
|
606
|
+
while (i < STEPS && cum[i] < target) i++
|
|
607
|
+
const span = Math.max(1e-6, cum[i] - cum[i - 1])
|
|
608
|
+
const t = (target - cum[i - 1]) / span
|
|
609
|
+
out.push((-90 + ((i - 1 + t) / STEPS) * 360))
|
|
610
|
+
}
|
|
611
|
+
return out
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function minSpacing(rx, ry, angles) {
|
|
615
|
+
const n = angles.length
|
|
616
|
+
if (n < 2) return Infinity
|
|
617
|
+
let min = Infinity
|
|
618
|
+
for (let i = 0; i < n; i++) {
|
|
619
|
+
const a = (angles[i] * Math.PI) / 180
|
|
620
|
+
const b = (angles[(i + 1) % n] * Math.PI) / 180
|
|
621
|
+
min = Math.min(min, Math.hypot(rx * (Math.cos(b) - Math.cos(a)), ry * (Math.sin(b) - Math.sin(a))))
|
|
622
|
+
}
|
|
623
|
+
return min
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// 名字块宽度估算(按 12px 字号算,d = 舞台密度:窄面板里字号一起缩)
|
|
627
|
+
function estimateLabelWidth(node, d) {
|
|
628
|
+
const k = d == null ? 1 : d
|
|
629
|
+
const name = String(node.name || '')
|
|
630
|
+
let w = 0
|
|
631
|
+
for (const ch of name) w += ch.charCodeAt(0) > 0x2e7f ? 12 : 6.7
|
|
632
|
+
if (node.coord) w += 33
|
|
633
|
+
return Math.min(node.coord ? 156 : 112, Math.max(26, w)) * k
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// 标签避让:名字块不能压到别的舱体、别的名字块或舞台边界。
|
|
637
|
+
// 候选顺序 = 先原位、再向外侧平移、最后翻到舱体另一侧;取冲突最少的一个。
|
|
638
|
+
// lockUp = 传送带两排布局:顶排标签必须在上、底排必须在下,中间留给光束走廊。
|
|
639
|
+
function resolveLabels(pos, nodes, W, H, labelH, gap, center, lockUp, d) {
|
|
640
|
+
const items = []
|
|
641
|
+
for (const node of nodes) {
|
|
642
|
+
const p = pos[node.id]
|
|
643
|
+
if (!p) continue
|
|
644
|
+
items.push({ id: node.id, node, p, hw: Math.min(estimateLabelWidth(node, d), p.labelMax || 999) / 2 })
|
|
645
|
+
}
|
|
646
|
+
const circles = items.map((it) => ({ id: it.id, x: it.p.x, y: it.p.y, r: it.p.pod / 2 }))
|
|
647
|
+
const rectOf = (it, up, shift) => {
|
|
648
|
+
const cx = it.p.x + shift
|
|
649
|
+
const y0 = up ? it.p.y - it.p.pod / 2 - gap - labelH : it.p.y + it.p.pod / 2 + gap
|
|
650
|
+
return { x0: cx - it.hw, x1: cx + it.hw, y0, y1: y0 + labelH }
|
|
651
|
+
}
|
|
652
|
+
const countHits = (rect, selfId, placed) => {
|
|
653
|
+
let hits = 0
|
|
654
|
+
if (rect.x0 < 4 || rect.x1 > W - 4 || rect.y0 < 2 || rect.y1 > H - 2) hits += 2
|
|
655
|
+
for (const c of circles) {
|
|
656
|
+
if (c.id === selfId) continue
|
|
657
|
+
const nx = Math.max(rect.x0, Math.min(c.x, rect.x1))
|
|
658
|
+
const ny = Math.max(rect.y0, Math.min(c.y, rect.y1))
|
|
659
|
+
if (Math.hypot(nx - c.x, ny - c.y) < c.r + 5) hits += 1
|
|
660
|
+
}
|
|
661
|
+
for (const other of placed) {
|
|
662
|
+
if (other.id === selfId) continue
|
|
663
|
+
if (rect.x0 < other.rect.x1 + 2 && rect.x1 > other.rect.x0 - 2 &&
|
|
664
|
+
rect.y0 < other.rect.y1 + 1 && rect.y1 > other.rect.y0 - 1) hits += 1
|
|
665
|
+
}
|
|
666
|
+
return hits
|
|
667
|
+
}
|
|
668
|
+
const placed = []
|
|
669
|
+
let total = 0
|
|
670
|
+
items.sort((a, b) => (b.p.isCenter ? 1 : 0) - (a.p.isCenter ? 1 : 0))
|
|
671
|
+
for (const it of items) {
|
|
672
|
+
const out = it.p.x >= center.x ? 1 : -1
|
|
673
|
+
const shifts = [0]
|
|
674
|
+
for (let s = 6; s <= 78; s += 6) { shifts.push(out * s); shifts.push(-out * s) }
|
|
675
|
+
const ups = lockUp ? [!!it.p.labelUp] : (it.p.labelUp ? [true, false] : [false, true])
|
|
676
|
+
let best = null
|
|
677
|
+
for (const up of ups) {
|
|
678
|
+
for (const shift of shifts) {
|
|
679
|
+
// 平移后若越出舞台左右边界,就地夹回边界内(只改标签位置,不改舱体)
|
|
680
|
+
const lo = 4 + it.hw
|
|
681
|
+
const hi = W - 4 - it.hw
|
|
682
|
+
const cx = hi > lo ? Math.min(hi, Math.max(lo, it.p.x + shift)) : it.p.x
|
|
683
|
+
const real = cx - it.p.x
|
|
684
|
+
const rect = rectOf(it, up, real)
|
|
685
|
+
const hits = countHits(rect, it.id, placed)
|
|
686
|
+
if (!best || hits < best.hits) best = { up, shift: real, rect, hits }
|
|
687
|
+
if (hits === 0) break
|
|
688
|
+
}
|
|
689
|
+
if (best && best.hits === 0) break
|
|
690
|
+
}
|
|
691
|
+
it.p.labelUp = best.up
|
|
692
|
+
it.p.nameShift = best.shift
|
|
693
|
+
total += best.hits
|
|
694
|
+
placed.push({ id: it.id, rect: best.rect })
|
|
695
|
+
}
|
|
696
|
+
return total
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, dense, fill, cap, density, noLabels) {
|
|
700
|
+
const base0 = HIVE_MODES[modeKey] || HIVE_MODES.duo
|
|
701
|
+
// 舞台密度:窄面板里舱体 / 名字块 / 留白一起等比收紧(侧栏拖窄时自动变小)
|
|
702
|
+
const d = density == null ? 1 : density
|
|
703
|
+
const base = d === 1 ? base0 : {
|
|
704
|
+
...base0,
|
|
705
|
+
pod: Math.round(base0.pod * d),
|
|
706
|
+
coord: Math.round(base0.coord * d),
|
|
707
|
+
name: Math.round(base0.name * d),
|
|
708
|
+
padT: Math.round(base0.padT * d),
|
|
709
|
+
padB: Math.round(base0.padB * d),
|
|
710
|
+
padX: Math.round(base0.padX * d),
|
|
711
|
+
}
|
|
712
|
+
const M = scale === 1
|
|
713
|
+
? base
|
|
714
|
+
: { ...base, pod: Math.round(base.pod * scale), coord: Math.round(base.coord * scale) }
|
|
715
|
+
// 光束优先于图标:先给线留够长度(不低于 BEAM_FLOOR),舱体放不下就由 layoutHive 缩舱体让位
|
|
716
|
+
const beam = Math.max(BEAM_FLOOR, Math.round(base0.beam * d))
|
|
717
|
+
const seg = Math.round(beam * 0.6) // 纵向绕行时至少露出这么一截光束
|
|
718
|
+
// 紧凑标签:只留名字(11px),不给状态文字留位;环太挤时自动切换
|
|
719
|
+
// 名字块字号不跟密度缩(12px 已经是可读下限,再小会截断),只缩舱体与留白
|
|
720
|
+
const compact = dense || modeKey === 'crowd'
|
|
721
|
+
const nameH = compact ? 18 : base0.name
|
|
722
|
+
// noLabels:卫星名字块整个收起来(悬停仍可看),纵向不再给它留位——省下的空间全给光束
|
|
723
|
+
const satLabelH = noLabels ? 0 : nameH
|
|
724
|
+
const coord = nodes.find((n) => n.coord) || nodes[0]
|
|
725
|
+
const others = nodes.filter((n) => n !== coord)
|
|
726
|
+
const n = others.length
|
|
727
|
+
const rx = Math.max(M.coord / 2 + M.pod / 2 + beam, W / 2 - M.pod / 2 - M.padX)
|
|
728
|
+
// 纵向净空:按「标签框 / 舱体框是否真的相交」判断,而不是按 sin 一刀切
|
|
729
|
+
let ryNeed = 0
|
|
730
|
+
for (const deg of anglesFor(n)) {
|
|
731
|
+
const rad = (deg * Math.PI) / 180
|
|
732
|
+
const s = Math.sin(rad)
|
|
733
|
+
const dx = Math.abs(Math.cos(rad)) * rx
|
|
734
|
+
let need = 0
|
|
735
|
+
if (s < -0.3) {
|
|
736
|
+
// 名字在舱体上方:只需让开主控本体与一段可见光束
|
|
737
|
+
need = !noLabels && dx < M.coord / 2 + M.pod / 2 + Math.round(seg * 0.5) ? M.coord / 2 + M.pod / 2 + 8 * d + seg : 0
|
|
738
|
+
} else if (s > 0.02) {
|
|
739
|
+
// 下方:主控自己的名字块永远要留出(主控不收名字),卫星名字收起时只让开主控字块
|
|
740
|
+
if (dx - M.pod / 2 < Math.round(beam * 0.8)) need = M.coord / 2 + nameH + 8 * d + M.pod / 2 + (noLabels ? 6 : seg)
|
|
741
|
+
else if (dx < Math.round(beam * 1.5)) need = M.coord / 2 + nameH + 8 * d - M.pod / 2
|
|
742
|
+
}
|
|
743
|
+
if (need > 0) ryNeed = Math.max(ryNeed, need / Math.max(Math.abs(s), 0.2))
|
|
744
|
+
}
|
|
745
|
+
// 椭圆高度:先按周长需求拉高;标签还挤就吃满纵向预算(fill),再不行由 layoutHive 缩小舱体
|
|
746
|
+
const needLen = n * (M.pod + 14 * d)
|
|
747
|
+
const ryCap2 = needLen > 0 ? Math.sqrt(Math.max(0, 2 * Math.pow(needLen / (2 * Math.PI), 2) - rx * rx)) : 0
|
|
748
|
+
const ryFloor = 56 * d
|
|
749
|
+
const ryCap = Math.max(ryFloor, availH / 2 - M.pod / 2 - satLabelH - 8 * d - (M.padT + M.padB) / 2 - 1)
|
|
750
|
+
const ry = fill
|
|
751
|
+
? Math.max(ryNeed, ryCap, ryFloor)
|
|
752
|
+
: Math.max(ryNeed, Math.min(ryCap, Math.max(rx * 0.84, ryCap2)), ryFloor)
|
|
753
|
+
const angles = evenAngles(rx, ry, n)
|
|
754
|
+
let top = M.coord / 2 + 20 * d // 顶部留一条绕行弧线的通道
|
|
755
|
+
let bottom = M.coord / 2 + nameH + 8 * d
|
|
756
|
+
for (const deg of angles) {
|
|
757
|
+
const s = Math.sin((deg * Math.PI) / 180)
|
|
758
|
+
const up = s < -0.3
|
|
759
|
+
top = Math.max(top, -s * ry + M.pod / 2 + (up ? satLabelH + 8 * d : 0) + 2)
|
|
760
|
+
bottom = Math.max(bottom, s * ry + M.pod / 2 + (up ? 0 : satLabelH + 8 * d))
|
|
761
|
+
}
|
|
762
|
+
let cy = M.padT + top
|
|
763
|
+
const height = Math.round(cy + bottom + M.padB)
|
|
764
|
+
if (viewH && height < viewH) cy += (viewH - height) / 2
|
|
765
|
+
const pos = {}
|
|
766
|
+
pos[coord.id] = { x: W / 2, y: cy, pod: M.coord, isCenter: true, angle: null, labelUp: false }
|
|
767
|
+
others.forEach((node, i) => {
|
|
768
|
+
const rad = (angles[i] * Math.PI) / 180
|
|
769
|
+
pos[node.id] = {
|
|
770
|
+
x: W / 2 + rx * Math.cos(rad),
|
|
771
|
+
y: cy + ry * Math.sin(rad),
|
|
772
|
+
pod: M.pod,
|
|
773
|
+
isCenter: false,
|
|
774
|
+
angle: angles[i],
|
|
775
|
+
labelUp: Math.sin(rad) < -0.3,
|
|
776
|
+
labelMax: cap || 0,
|
|
777
|
+
}
|
|
778
|
+
})
|
|
779
|
+
// 整簇水平居中(单侧节点时避免半边空)
|
|
780
|
+
let minX = Infinity
|
|
781
|
+
let maxX = -Infinity
|
|
782
|
+
for (const id of Object.keys(pos)) {
|
|
783
|
+
minX = Math.min(minX, pos[id].x - pos[id].pod / 2)
|
|
784
|
+
maxX = Math.max(maxX, pos[id].x + pos[id].pod / 2)
|
|
785
|
+
}
|
|
786
|
+
const shift = (W - (maxX - minX)) / 2 - minX
|
|
787
|
+
for (const id of Object.keys(pos)) pos[id].x += shift
|
|
788
|
+
const center = { x: W / 2 + shift, y: cy }
|
|
789
|
+
const labelHits = noLabels
|
|
790
|
+
? 0
|
|
791
|
+
: resolveLabels(pos, nodes, W, Math.max(height, viewH || 0), compact ? 16 : 28, compact ? 5 : 7, center, false, 1)
|
|
792
|
+
return {
|
|
793
|
+
pos, center, rx, ry, height, angles, mode: M, coordId: coord.id, ringCount: n,
|
|
794
|
+
strip: false, hideMeta: compact, labelHits, density: d, hideLabels: !!noLabels,
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// 依次尝试:纵向富余就先放大一档 → 原尺寸 → 紧凑标签(去掉状态文字)→ 椭圆吃满纵向 → 缩小舱体 → 名字截断
|
|
799
|
+
function layoutHive(nodes, W, availH, modeKey, viewH, density) {
|
|
800
|
+
const d = density == null ? 1 : density
|
|
801
|
+
// 宽度预算:放大后的簇宽不能超过舞台宽度——窄面板里纵向再富余也不许把舱体撑回原尺寸
|
|
802
|
+
const growCap = (W - 8) / (naturalWidthOf(modeKey) * d)
|
|
803
|
+
let scale = 1
|
|
804
|
+
let dense = false
|
|
805
|
+
let fill = false
|
|
806
|
+
let cap = 0
|
|
807
|
+
let L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, 1, false, false, 0, d)
|
|
808
|
+
// 单任务铺满一屏时星团容易缩在中间:纵向明显富余就把舱体放大一档(最多 1.35 倍)
|
|
809
|
+
const outOfBounds = (L) => Object.keys(L.pos).some((id) => {
|
|
810
|
+
const p = L.pos[id]
|
|
811
|
+
return p.x - p.pod / 2 < -0.5 || p.x + p.pod / 2 > W + 0.5
|
|
812
|
+
})
|
|
813
|
+
if (availH && L.ringCount >= 1 && L.height < availH * 0.6) {
|
|
814
|
+
const grow = Math.min(1.35, (availH * 0.6) / L.height, growCap)
|
|
815
|
+
if (grow > 1.06) {
|
|
816
|
+
const G = layoutHiveRaw(nodes, W, availH, modeKey, viewH, grow, false, false, 0, d)
|
|
817
|
+
if (!outOfBounds(G) && G.labelHits === 0 && (G.ringCount < 2 || minSpacing(G.rx, G.ry, G.angles) >= G.mode.pod + 8)) {
|
|
818
|
+
scale = grow
|
|
819
|
+
L = G
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
for (let i = 0; i < 12; i++) {
|
|
824
|
+
const have = L.ringCount >= 2 ? minSpacing(L.rx, L.ry, L.angles) : Infinity
|
|
825
|
+
const need = L.mode.pod + 8
|
|
826
|
+
if (have < need || outOfBounds(L)) {
|
|
827
|
+
// 环上放不下:按「实际弦长 / 需要的弦长」缩小舱体,单次最多缩 25%;横向出界则每次缩 6%
|
|
828
|
+
if (scale <= 0.42) break
|
|
829
|
+
const k = have < need ? Math.max(0.75, Math.min(0.98, have / need)) : 0.94
|
|
830
|
+
scale = Math.max(0.42, scale * k)
|
|
831
|
+
L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, dense, fill, cap, d)
|
|
832
|
+
continue
|
|
833
|
+
}
|
|
834
|
+
if (L.labelHits > 0) {
|
|
835
|
+
if (!dense) dense = true
|
|
836
|
+
else if (!fill) fill = true
|
|
837
|
+
else if (scale > 0.42) scale = Math.max(0.42, scale * 0.88)
|
|
838
|
+
else cap = Math.max(Math.round(40 * d), Math.round(have - 4)) // 实在放不下就把名字截断
|
|
839
|
+
L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, dense, fill, cap, d)
|
|
840
|
+
continue
|
|
841
|
+
}
|
|
842
|
+
break
|
|
843
|
+
}
|
|
844
|
+
// 收尾:名字块只能截成「DS…」这种残桩,或者循环跑完还在冲突——干脆把卫星名字整个收起来
|
|
845
|
+
// (悬停仍可看),省下的横向 / 纵向空间全部让给光束,环能撑得更大,舱体也不用再为躲字而缩。
|
|
846
|
+
const haveNow = L.ringCount >= 2 ? minSpacing(L.rx, L.ry, L.angles) : Infinity
|
|
847
|
+
const tight = L.labelHits > 0 ? Math.max(26, Math.round(haveNow - 4)) : (cap || 999)
|
|
848
|
+
if (L.labelHits > 0) L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, true, true, tight, d)
|
|
849
|
+
if (L.labelHits > 0 || tight < LABEL_MIN_READABLE) {
|
|
850
|
+
L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, true, true, 0, d, true)
|
|
851
|
+
}
|
|
852
|
+
return L
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// ── 紧凑「传送带」布局:主控在左,其余在右侧一到两排 ──
|
|
856
|
+
function layoutStrip(nodes, W, viewH, modeKey, density) {
|
|
857
|
+
const d = density == null ? 1 : density
|
|
858
|
+
const base0 = HIVE_MODES[modeKey] || HIVE_MODES.duo
|
|
859
|
+
const M = d === 1 ? base0 : { ...base0, pod: Math.round(base0.pod * d), coord: Math.round(base0.coord * d) }
|
|
860
|
+
const coord = nodes.find((n) => n.coord) || nodes[0]
|
|
861
|
+
const others = nodes.filter((n) => n !== coord)
|
|
862
|
+
const n = others.length
|
|
863
|
+
let rows = n >= 2 ? 2 : 1
|
|
864
|
+
const padX = Math.round(16 * d)
|
|
865
|
+
const labelH = 18
|
|
866
|
+
const labelBlock = 6 + labelH
|
|
867
|
+
// 光束优先:主控与卫星之间的走廊、以及两排之间的走廊都按 beam 给,舱体放不下就缩舱体
|
|
868
|
+
const beamX = Math.max(BEAM_FLOOR, Math.round(base0.beam * 0.8 * d))
|
|
869
|
+
const corridor = Math.max(26, Math.round(base0.beam * 0.6 * d)) // 两排之间的光束走廊高度
|
|
870
|
+
const coordSize = M.coord
|
|
871
|
+
const xa = padX + coordSize / 2
|
|
872
|
+
// 横向放不下(舱体会互相压)才拆成三排,三排没有光束走廊
|
|
873
|
+
const rawPod = (r) => {
|
|
874
|
+
const per = Math.ceil(n / r)
|
|
875
|
+
if (per <= 1) return M.pod
|
|
876
|
+
const x0 = xa + coordSize / 2 + beamX + M.pod / 2
|
|
877
|
+
const xb = W - 22 * d - M.pod / 2
|
|
878
|
+
return Math.min(M.pod, Math.floor((xb - x0) / (per - 1)) - 8)
|
|
879
|
+
}
|
|
880
|
+
let pod = rawPod(rows)
|
|
881
|
+
if (rows < 3) {
|
|
882
|
+
const wide = rawPod(3)
|
|
883
|
+
if (pod < 22 && wide > pod + 6) { rows = 3; pod = wide }
|
|
884
|
+
}
|
|
885
|
+
pod = Math.max(18, pod)
|
|
886
|
+
const perRow = Math.ceil(n / rows)
|
|
887
|
+
const x0 = xa + coordSize / 2 + beamX + pod / 2
|
|
888
|
+
const xb = W - 22 * d - pod / 2
|
|
889
|
+
const rowH = pod + labelBlock
|
|
890
|
+
// 纵向:两排时顶排标签在上、底排标签在下,中间留一条光束走廊;单排/三排标签都在下方
|
|
891
|
+
const rowY = []
|
|
892
|
+
let height
|
|
893
|
+
if (rows === 2) {
|
|
894
|
+
const y0 = 10 + labelBlock + pod / 2
|
|
895
|
+
rowY.push(y0, y0 + pod + corridor)
|
|
896
|
+
height = Math.round(rowY[1] + pod / 2 + labelBlock + 10)
|
|
897
|
+
} else if (rows === 1) {
|
|
898
|
+
const y = 22 + pod / 2 // 上方留出绕行弧线的余量
|
|
899
|
+
rowY.push(y)
|
|
900
|
+
height = Math.round(y + pod / 2 + labelBlock + 10)
|
|
901
|
+
} else {
|
|
902
|
+
const y0 = 12 + pod / 2
|
|
903
|
+
for (let r = 0; r < rows; r++) rowY.push(y0 + r * (rowH + 10))
|
|
904
|
+
height = Math.round(rowY[rows - 1] + pod / 2 + labelBlock + 10)
|
|
905
|
+
}
|
|
906
|
+
const cy = rows === 2 ? (rowY[0] + rowY[1]) / 2 : rowY[Math.floor(rows / 2)]
|
|
907
|
+
const shiftY = viewH && viewH > height ? (viewH - height) / 2 : 0
|
|
908
|
+
// 名字宽度上限跟着舱体间距走,长名字用省略号收尾,避免相邻标签互相压
|
|
909
|
+
const spacing = perRow > 1 ? (xb - x0) / (perRow - 1) : xb - x0
|
|
910
|
+
const labelMax = Math.max(38, Math.min(74, Math.floor(spacing + 4)))
|
|
911
|
+
const pos = {}
|
|
912
|
+
pos[coord.id] = { x: xa, y: cy + shiftY, pod: coordSize, isCenter: true, angle: null, labelUp: false }
|
|
913
|
+
others.forEach((node, i) => {
|
|
914
|
+
const row = Math.floor(i / perRow)
|
|
915
|
+
const col = i % perRow
|
|
916
|
+
const cnt = Math.min(perRow, n - perRow * row)
|
|
917
|
+
// 单排只放一个舱体时(两个组员),错开一点,别叠成一条竖线
|
|
918
|
+
const t = cnt === 1 ? (rows === 2 ? (row === 0 ? 0.38 : 0.62) : 0.5) : col / (cnt - 1)
|
|
919
|
+
pos[node.id] = {
|
|
920
|
+
x: x0 + (xb - x0) * t,
|
|
921
|
+
y: rowY[Math.min(row, rowY.length - 1)] + shiftY,
|
|
922
|
+
pod,
|
|
923
|
+
isCenter: false,
|
|
924
|
+
angle: null,
|
|
925
|
+
labelUp: rows === 2 && row === 0,
|
|
926
|
+
labelMax,
|
|
927
|
+
}
|
|
928
|
+
})
|
|
929
|
+
const center = { x: xa, y: cy + shiftY }
|
|
930
|
+
resolveLabels(pos, nodes, W, Math.max(height, viewH || 0), 16, 5, center, rows === 2, 1)
|
|
931
|
+
return {
|
|
932
|
+
pos, center, rx: 0, ry: 0, height, mode: M, coordId: coord.id, ringCount: n,
|
|
933
|
+
strip: true, hideMeta: false, labelHits: 0, density: d,
|
|
934
|
+
corridor: rows === 2 ? cy + shiftY : null,
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// ── 布线:径向走直线,环上互连走外弧/内弧,传送带走中间走廊;全部避开舱体与名字 ──
|
|
939
|
+
function curve(s, c, e) {
|
|
940
|
+
return {
|
|
941
|
+
d: 'M' + s.x.toFixed(1) + ' ' + s.y.toFixed(1) + ' Q' + c.x.toFixed(1) + ' ' + c.y.toFixed(1) + ' ' + e.x.toFixed(1) + ' ' + e.y.toFixed(1),
|
|
942
|
+
sx: s.x, sy: s.y, cx: c.x, cy: c.y, ex: e.x, ey: e.y,
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
function cubic(s, c1, c2, e) {
|
|
947
|
+
return {
|
|
948
|
+
d: 'M' + s.x.toFixed(1) + ' ' + s.y.toFixed(1) + ' C' + c1.x.toFixed(1) + ' ' + c1.y.toFixed(1) + ' ' + c2.x.toFixed(1) + ' ' + c2.y.toFixed(1) + ' ' + e.x.toFixed(1) + ' ' + e.y.toFixed(1),
|
|
949
|
+
sx: s.x, sy: s.y, c1x: c1.x, c1y: c1.y, c2x: c2.x, c2y: c2.y, ex: e.x, ey: e.y,
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function pointAt(p, t) {
|
|
954
|
+
const u = 1 - t
|
|
955
|
+
if (p.c1x != null) {
|
|
956
|
+
return {
|
|
957
|
+
x: u * u * u * p.sx + 3 * u * u * t * p.c1x + 3 * u * t * t * p.c2x + t * t * t * p.ex,
|
|
958
|
+
y: u * u * u * p.sy + 3 * u * u * t * p.c1y + 3 * u * t * t * p.c2y + t * t * t * p.ey,
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
return {
|
|
962
|
+
x: u * u * p.sx + 2 * u * t * p.cx + t * t * p.ex,
|
|
963
|
+
y: u * u * p.sy + 2 * u * t * p.cy + t * t * p.ey,
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function curveLength(p) {
|
|
968
|
+
let len = 0
|
|
969
|
+
let prev = pointAt(p, 0)
|
|
970
|
+
for (let i = 1; i <= 24; i++) {
|
|
971
|
+
const cur = pointAt(p, i / 24)
|
|
972
|
+
len += Math.hypot(cur.x - prev.x, cur.y - prev.y)
|
|
973
|
+
prev = cur
|
|
974
|
+
}
|
|
975
|
+
return len
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function collides(p, pods, skipA, skipB, W, H) {
|
|
979
|
+
for (let i = 1; i <= 20; i++) {
|
|
980
|
+
const t = i / 20
|
|
981
|
+
const q = pointAt(p, t)
|
|
982
|
+
const x = q.x
|
|
983
|
+
const y = q.y
|
|
984
|
+
if (x < 3 || x > W - 3 || y < 3 || y > H - 3) return true
|
|
985
|
+
for (const pod of pods) {
|
|
986
|
+
const isA = pod.id === skipA
|
|
987
|
+
const isB = pod.id === skipB
|
|
988
|
+
if (isA || isB) {
|
|
989
|
+
// 起点 / 终点的舱体圆必须跳过(线就是从它们边缘出发的);
|
|
990
|
+
// 但两端自己的名字块要避开——终点整条路径都不许压字,起点只放行开头一小段。
|
|
991
|
+
if (!pod.rect) continue
|
|
992
|
+
if (isB || t > 0.25) {
|
|
993
|
+
const rc = pod.rect
|
|
994
|
+
if (x > rc.x0 && x < rc.x1 && y > rc.y0 && y < rc.y1) return true
|
|
995
|
+
}
|
|
996
|
+
continue
|
|
997
|
+
}
|
|
998
|
+
if (Math.hypot(x - pod.x, y - pod.y) < pod.pod / 2 + 10) return true
|
|
999
|
+
const rc = pod.rect
|
|
1000
|
+
if (rc && x > rc.x0 && x < rc.x1 && y > rc.y0 && y < rc.y1) return true
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
return false
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
function routeBeam(a, b, L, pods, W, H) {
|
|
1007
|
+
const ra = a.pod / 2
|
|
1008
|
+
const rb = b.pod / 2
|
|
1009
|
+
const dx = b.x - a.x
|
|
1010
|
+
const dy = b.y - a.y
|
|
1011
|
+
const len = Math.hypot(dx, dy) || 1
|
|
1012
|
+
const ux = dx / len
|
|
1013
|
+
const uy = dy / len
|
|
1014
|
+
const s = { x: a.x + ux * (ra + 8), y: a.y + uy * (ra + 8) }
|
|
1015
|
+
const e = { x: b.x - ux * (rb + 8), y: b.y - uy * (rb + 8) }
|
|
1016
|
+
const mid = { x: (s.x + e.x) / 2, y: (s.y + e.y) / 2 }
|
|
1017
|
+
const chord = Math.hypot(e.x - s.x, e.y - s.y)
|
|
1018
|
+
const nx = -uy
|
|
1019
|
+
const ny = ux
|
|
1020
|
+
const cands = []
|
|
1021
|
+
if (L.strip && L.corridor != null) {
|
|
1022
|
+
// 传送带:从舱体边缘进出,中间贴着两排之间的走廊走,像一条总线
|
|
1023
|
+
const cy = L.corridor
|
|
1024
|
+
const s2 = a.isCenter
|
|
1025
|
+
? { x: a.x + (b.x >= a.x ? 1 : -1) * (ra + 8), y: a.y }
|
|
1026
|
+
: { x: a.x, y: a.y + (cy > a.y ? 1 : -1) * (ra + 8) }
|
|
1027
|
+
const e2 = b.isCenter
|
|
1028
|
+
? { x: b.x - (b.x >= a.x ? 1 : -1) * (rb + 8), y: b.y }
|
|
1029
|
+
: { x: b.x, y: b.y + (cy > b.y ? 1 : -1) * (rb + 8) }
|
|
1030
|
+
const span = e2.x - s2.x
|
|
1031
|
+
for (const k of [0.16, 0.3, 0.46]) {
|
|
1032
|
+
cands.push(cubic(s2, { x: s2.x + span * k, y: cy }, { x: e2.x - span * k, y: cy }, e2))
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
if (a.isCenter || b.isCenter) {
|
|
1036
|
+
if (L.strip) {
|
|
1037
|
+
// 传送带(无走廊时):优先走两排之间的空档,绕开近处舱体与名字
|
|
1038
|
+
const toMid = mid.y - L.center.y > 0 ? -1 : 1
|
|
1039
|
+
for (const k of [0.14, 0.28, 0.42, 0.6]) {
|
|
1040
|
+
cands.push({ x: mid.x, y: mid.y + toMid * chord * k })
|
|
1041
|
+
cands.push({ x: mid.x, y: mid.y - toMid * chord * k })
|
|
1042
|
+
}
|
|
1043
|
+
} else {
|
|
1044
|
+
cands.push({ x: mid.x + nx * chord * 0.1, y: mid.y + ny * chord * 0.1 })
|
|
1045
|
+
cands.push({ x: mid.x - nx * chord * 0.1, y: mid.y - ny * chord * 0.1 })
|
|
1046
|
+
}
|
|
1047
|
+
} else {
|
|
1048
|
+
let ox = mid.x - L.center.x
|
|
1049
|
+
let oy = mid.y - L.center.y
|
|
1050
|
+
let ol = Math.hypot(ox, oy)
|
|
1051
|
+
if (ol < 10) { ox = nx; oy = ny; ol = 1 }
|
|
1052
|
+
ox /= ol
|
|
1053
|
+
oy /= ol
|
|
1054
|
+
// 先小弧度,撞到舱体/名字再加大(对径两点的连线必须绕开主控;超宽弦需要的弧度很小)
|
|
1055
|
+
for (let k = 0.06; k <= 0.96; k += 0.03) {
|
|
1056
|
+
cands.push({ x: mid.x + ox * chord * k, y: mid.y + oy * chord * k })
|
|
1057
|
+
cands.push({ x: mid.x - ox * chord * k, y: mid.y - oy * chord * k })
|
|
1058
|
+
cands.push({ x: mid.x + nx * chord * k, y: mid.y + ny * chord * k })
|
|
1059
|
+
cands.push({ x: mid.x - nx * chord * k, y: mid.y - ny * chord * k })
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
let picked = null
|
|
1063
|
+
// 箭头落在目标名字上时,改从侧面切入(±60° / ±92°),避免箭头压字
|
|
1064
|
+
const target = pods.find((p) => p.id === b.id)
|
|
1065
|
+
const ends = [e]
|
|
1066
|
+
if (target && target.rect && e.x > target.rect.x0 && e.x < target.rect.x1 && e.y > target.rect.y0 && e.y < target.rect.y1) {
|
|
1067
|
+
const base = Math.atan2(e.y - b.y, e.x - b.x)
|
|
1068
|
+
for (const d of [1.05, -1.05, 1.6, -1.6]) {
|
|
1069
|
+
ends.push({ x: b.x + Math.cos(base + d) * (rb + 8), y: b.y + Math.sin(base + d) * (rb + 8) })
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
for (const cand of cands) {
|
|
1073
|
+
if (cand.d) {
|
|
1074
|
+
if (!collides(cand, pods, a.id, b.id, W, H)) { picked = cand; break }
|
|
1075
|
+
continue
|
|
1076
|
+
}
|
|
1077
|
+
for (const end of ends) {
|
|
1078
|
+
const p = curve(s, cand, end)
|
|
1079
|
+
if (!collides(p, pods, a.id, b.id, W, H)) { picked = p; break }
|
|
1080
|
+
}
|
|
1081
|
+
if (picked) break
|
|
1082
|
+
}
|
|
1083
|
+
if (!picked) picked = curve(s, mid, e)
|
|
1084
|
+
picked.len = curveLength(picked)
|
|
1085
|
+
const tx = picked.ex - (picked.c1x != null ? picked.c2x : picked.cx)
|
|
1086
|
+
const ty = picked.ey - (picked.c1y != null ? picked.c2y : picked.cy)
|
|
1087
|
+
const tl = Math.hypot(tx, ty) || 1
|
|
1088
|
+
picked.angle = (Math.atan2(ty / tl, tx / tl) * 180) / Math.PI
|
|
1089
|
+
return picked
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
// ── 图标 ──
|
|
1093
|
+
function strokeProps() {
|
|
1094
|
+
return { fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' }
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
function HudIcon({ name, size = 16 }) {
|
|
1098
|
+
const common = strokeProps()
|
|
1099
|
+
let body = null
|
|
1100
|
+
if (name === 'sun') {
|
|
1101
|
+
body = h(Fragment, null,
|
|
1102
|
+
h('circle', { cx: 12, cy: 12, r: 4, ...common }),
|
|
1103
|
+
h('path', { d: 'M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4', ...common }))
|
|
1104
|
+
} else if (name === 'moon') {
|
|
1105
|
+
body = h('path', { d: 'M20.5 14.2A8.5 8.5 0 0 1 9.8 3.5 8.5 8.5 0 1 0 20.5 14.2Z', ...common })
|
|
1106
|
+
} else if (name === 'motion') {
|
|
1107
|
+
body = h('path', { d: 'M3 12h4l2.5-6 5 12 2.5-6h4', ...common })
|
|
1108
|
+
} else if (name === 'still') {
|
|
1109
|
+
body = h('path', { d: 'M8 5v14M16 5v14', ...common })
|
|
1110
|
+
} else if (name === 'refresh') {
|
|
1111
|
+
body = h(Fragment, null,
|
|
1112
|
+
h('path', { d: 'M20 7v5h-5M4 17v-5h5', ...common }),
|
|
1113
|
+
h('path', { d: 'M6.1 8a7 7 0 0 1 11.6-2L20 8M4 16l2.3 2A7 7 0 0 0 18 16', ...common }))
|
|
1114
|
+
} else if (name === 'alert') {
|
|
1115
|
+
body = h(Fragment, null,
|
|
1116
|
+
h('path', { d: 'M12 8v5M12 16h.01', ...common }),
|
|
1117
|
+
h('path', { d: 'M10.3 4.1 2.6 17.2A2 2 0 0 0 4.3 20h15.4a2 2 0 0 0 1.7-2.8L13.7 4.1a2 2 0 0 0-3.4 0Z', ...common }))
|
|
1118
|
+
}
|
|
1119
|
+
return h('svg', { width: size, height: size, viewBox: '0 0 24 24', 'aria-hidden': 'true', focusable: 'false', style: { display: 'block' } }, body)
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
function BrandGlyph({ size = 18, stroke = 1.9 }) {
|
|
1123
|
+
return h('svg', {
|
|
1124
|
+
viewBox: '0 0 24 24', width: size, height: size, fill: 'none', stroke: 'currentColor',
|
|
1125
|
+
strokeWidth: stroke, strokeLinecap: 'round', 'aria-hidden': 'true', focusable: 'false', style: { display: 'block' },
|
|
1126
|
+
},
|
|
1127
|
+
h('path', { d: 'M12 6.5v5M12 11.5l-5 4M12 11.5l5 4' }),
|
|
1128
|
+
h('circle', { cx: 12, cy: 5, r: 2.4, fill: 'currentColor', stroke: 'none' }),
|
|
1129
|
+
h('circle', { cx: 7, cy: 17.5, r: 2.1, fill: 'currentColor', stroke: 'none' }),
|
|
1130
|
+
h('circle', { cx: 17, cy: 17.5, r: 2.1, fill: 'currentColor', stroke: 'none' }))
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
function UserGlyph({ size = 20 }) {
|
|
1134
|
+
return h('svg', {
|
|
1135
|
+
viewBox: '0 0 24 24', width: size, height: size, fill: 'none', stroke: 'currentColor',
|
|
1136
|
+
strokeWidth: 1.6, strokeLinecap: 'round', 'aria-hidden': 'true', focusable: 'false', style: { display: 'block' },
|
|
1137
|
+
},
|
|
1138
|
+
h('circle', { cx: 12, cy: 8.5, r: 3.6 }),
|
|
1139
|
+
h('path', { d: 'M4.6 20c1.2-3.6 4-5.4 7.4-5.4s6.2 1.8 7.4 5.4' }))
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
// ── 元素:光束(彗尾三层 + 头点)与舱体 ──
|
|
1143
|
+
function beamElements(edge, p, id, motion, filterId) {
|
|
1144
|
+
const isWait = edge.kind === 'wait'
|
|
1145
|
+
const dur = isWait ? 3.4 : 2.1
|
|
1146
|
+
const color = isWait ? 'var(--dsb-wait)' : 'var(--dsb-cyan)'
|
|
1147
|
+
const gradId = 'dsb-bg-' + id
|
|
1148
|
+
const out = []
|
|
1149
|
+
out.push(h('defs', { key: 'defs' },
|
|
1150
|
+
h('linearGradient', {
|
|
1151
|
+
id: gradId, gradientUnits: 'userSpaceOnUse',
|
|
1152
|
+
x1: p.sx.toFixed(1), y1: p.sy.toFixed(1), x2: p.ex.toFixed(1), y2: p.ey.toFixed(1),
|
|
1153
|
+
},
|
|
1154
|
+
isWait
|
|
1155
|
+
? [
|
|
1156
|
+
h('stop', { key: 0, offset: 0, stopColor: '#f2b84b', stopOpacity: 0.16 }),
|
|
1157
|
+
h('stop', { key: 1, offset: 1, stopColor: '#f2b84b', stopOpacity: 0.7 }),
|
|
1158
|
+
]
|
|
1159
|
+
: [
|
|
1160
|
+
h('stop', { key: 0, offset: 0, stopColor: '#4d6bfe', stopOpacity: 0.3 }),
|
|
1161
|
+
h('stop', { key: 1, offset: 1, stopColor: '#62d6ff', stopOpacity: 0.95 }),
|
|
1162
|
+
])))
|
|
1163
|
+
out.push(h('path', {
|
|
1164
|
+
key: 'base', d: p.d, fill: 'none', stroke: 'url(#' + gradId + ')',
|
|
1165
|
+
strokeWidth: isWait ? 2 : 2.6, strokeLinecap: 'round',
|
|
1166
|
+
strokeDasharray: isWait ? '2 6' : undefined,
|
|
1167
|
+
filter: 'url(#' + filterId + ')',
|
|
1168
|
+
}))
|
|
1169
|
+
if (motion) {
|
|
1170
|
+
for (const layer of [[42, 2.2, 0.26], [24, 3.2, 0.48], [10, 4.2, 0.85]]) {
|
|
1171
|
+
const dash = layer[0]
|
|
1172
|
+
out.push(h('path', {
|
|
1173
|
+
key: 'c' + dash, d: p.d, fill: 'none', stroke: color, strokeWidth: layer[1],
|
|
1174
|
+
strokeLinecap: 'round', opacity: layer[2],
|
|
1175
|
+
strokeDasharray: dash + ' 9999', strokeDashoffset: dash,
|
|
1176
|
+
},
|
|
1177
|
+
h('animate', {
|
|
1178
|
+
attributeName: 'stroke-dashoffset', from: dash, to: (dash - p.len).toFixed(1),
|
|
1179
|
+
dur: dur + 's', repeatCount: 'indefinite',
|
|
1180
|
+
})))
|
|
1181
|
+
}
|
|
1182
|
+
out.push(h('circle', {
|
|
1183
|
+
key: 'head', r: isWait ? 3 : 3.6, fill: isWait ? '#ffe2a6' : '#e8fbff',
|
|
1184
|
+
filter: 'url(#' + filterId + ')',
|
|
1185
|
+
},
|
|
1186
|
+
h('animateMotion', {
|
|
1187
|
+
dur: dur + 's', repeatCount: 'indefinite', path: p.d,
|
|
1188
|
+
calcMode: 'linear', keyPoints: '0;1', keyTimes: '0;1',
|
|
1189
|
+
})))
|
|
1190
|
+
}
|
|
1191
|
+
out.push(h('path', {
|
|
1192
|
+
key: 'arrow', d: 'M-5 -4 L1 0 L-5 4', fill: 'none', stroke: color, strokeWidth: 2,
|
|
1193
|
+
strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
1194
|
+
transform: 'translate(' + p.ex.toFixed(1) + ' ' + p.ey.toFixed(1) + ') rotate(' + p.angle.toFixed(1) + ')',
|
|
1195
|
+
}))
|
|
1196
|
+
return out
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// 头像图片:加载失败时回退到形状/字母,避免宿主里出现破图占位
|
|
1200
|
+
function AvatarImg({ src, alt, style, fallback }) {
|
|
1201
|
+
const [bad, setBad] = useState(false)
|
|
1202
|
+
useEffect(() => { setBad(false) }, [src])
|
|
1203
|
+
if (!src || bad) return fallback || null
|
|
1204
|
+
return h('img', { src, alt: alt || '', style, onError: () => { setBad(true) } })
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
function podElement(node, p, modeKey, ctx) {
|
|
1208
|
+
const status = node.isUser ? 'user' : (node.failed ? 'failed' : (node.activeStatus || 'working'))
|
|
1209
|
+
const statusText = HIVE_STATUS_TEXT[status] || '工作中'
|
|
1210
|
+
const size = Math.round(p.pod * 0.62)
|
|
1211
|
+
const mark = node.shape ? characterMarkupOf(node.shape, size) : null
|
|
1212
|
+
const glyph = mark
|
|
1213
|
+
? h('svg', {
|
|
1214
|
+
width: size, height: size, viewBox: '-50 -50 100 100', 'aria-hidden': 'true', focusable: 'false',
|
|
1215
|
+
// 尺寸写进 style:宿主里的全局 svg 规则可能压掉 width/height 属性
|
|
1216
|
+
style: { width: size, height: size, display: 'block', flex: '0 0 auto' },
|
|
1217
|
+
},
|
|
1218
|
+
renderCharacter(h, {
|
|
1219
|
+
def: mark.def, id: mark.id, r: 50, color: node.color,
|
|
1220
|
+
uid: ctx.uid + '-' + node.id, status,
|
|
1221
|
+
reducedMotion: !ctx.motion, active: true, seed: node.name, nodeKey: node.id,
|
|
1222
|
+
}))
|
|
1223
|
+
: h('span', { className: 'dsb-pod__letter' }, String(node.name || '?').slice(0, 1))
|
|
1224
|
+
let inner
|
|
1225
|
+
if (node.isUser) {
|
|
1226
|
+
inner = h('span', { className: 'dsb-pod__user' }, h(UserGlyph, { size: Math.round(p.pod * 0.42) }))
|
|
1227
|
+
} else if (node.avatar && node.avatar.image) {
|
|
1228
|
+
const box = Math.round(p.pod * 0.74)
|
|
1229
|
+
inner = h('span', { className: 'dsb-pod__char', style: { width: box, height: box } },
|
|
1230
|
+
h(AvatarImg, { src: node.avatar.image, alt: '', fallback: glyph }))
|
|
1231
|
+
} else {
|
|
1232
|
+
inner = h('span', { className: 'dsb-pod__char' }, glyph)
|
|
1233
|
+
}
|
|
1234
|
+
const ring = h('svg', { className: 'dsb-pod__ring', viewBox: '0 0 100 100', 'aria-hidden': 'true', focusable: 'false' },
|
|
1235
|
+
h('circle', { className: 'dsb-halo', cx: 50, cy: 50, r: 47 }),
|
|
1236
|
+
h('circle', { className: 'dsb-tick', cx: 50, cy: 50, r: 47 }),
|
|
1237
|
+
node.coord ? h('circle', { className: 'dsb-gold', cx: 50, cy: 50, r: 52 }) : null,
|
|
1238
|
+
h('circle', { className: 'dsb-arc', cx: 50, cy: 50, r: 47 }))
|
|
1239
|
+
const label = ctx.hideLabels && !node.coord
|
|
1240
|
+
? null
|
|
1241
|
+
: h('div', { className: 'dsb-pod__label' },
|
|
1242
|
+
h('div', { className: 'dsb-pod__name' },
|
|
1243
|
+
node.coord ? h('span', { className: 'dsb-pod__crown' }, '主控') : null,
|
|
1244
|
+
h('span', { title: node.name }, node.name)),
|
|
1245
|
+
modeKey === 'crowd' || modeKey === 'strip'
|
|
1246
|
+
? null
|
|
1247
|
+
: h('div', { className: 'dsb-pod__meta' }, h('i'), statusText))
|
|
1248
|
+
const labelW = Math.min(estimateLabelWidth(node), p.labelMax || 999)
|
|
1249
|
+
// 名字文字的上限:主控要把「主控」冠标 + 间距让出来,否则传送带里会被压成 74px 截断
|
|
1250
|
+
const nameMax = node.coord ? Math.max(40, Math.round(labelW - 33)) : (p.labelMax || 0)
|
|
1251
|
+
// 头像动效错峰:按 id 散开,别让一整圈头像同步点头
|
|
1252
|
+
let avaSeed = 0
|
|
1253
|
+
const seedText = String(node.id || node.name || '')
|
|
1254
|
+
for (let i = 0; i < seedText.length; i++) avaSeed = (avaSeed * 31 + seedText.charCodeAt(i)) >>> 0
|
|
1255
|
+
const style = {
|
|
1256
|
+
left: p.x.toFixed(1) + 'px',
|
|
1257
|
+
top: p.y.toFixed(1) + 'px',
|
|
1258
|
+
'--dsb-pod': p.pod + 'px',
|
|
1259
|
+
'--dsb-tint': tintOf(node.color),
|
|
1260
|
+
'--dsb-shift': (p.nameShift || 0).toFixed(1) + 'px',
|
|
1261
|
+
'--dsb-name-max': nameMax ? nameMax + 'px' : undefined,
|
|
1262
|
+
'--dsb-label-w': labelW + 'px',
|
|
1263
|
+
'--dsb-ava-delay': (-((avaSeed % 30) / 10)).toFixed(1) + 's',
|
|
1264
|
+
}
|
|
1265
|
+
const cls = 'dsb-pod dsb-pod--' + status + (node.coord ? ' dsb-pod--coord' : '') + (p.labelUp ? ' dsb-pod--up' : '')
|
|
1266
|
+
const body = h('div', { className: 'dsb-pod__body' }, ring, inner)
|
|
1267
|
+
if (node.isUser) {
|
|
1268
|
+
return h('div', { key: node.id, className: cls + ' dsb-pod--static', style, 'aria-hidden': 'true' },
|
|
1269
|
+
h('div', { className: 'dsb-pod__glow' }), body, label)
|
|
1270
|
+
}
|
|
1271
|
+
return h('button', {
|
|
1272
|
+
key: node.id,
|
|
1273
|
+
type: 'button',
|
|
1274
|
+
className: cls,
|
|
1275
|
+
style,
|
|
1276
|
+
title: node.name + ' · ' + statusText,
|
|
1277
|
+
'aria-label': '打开 ' + node.name + ' 的会话(' + statusText + ')',
|
|
1278
|
+
onClick: () => { if (ctx.onOpenSession) ctx.onOpenSession({ botId: node.id, key: node.key, name: node.name }) },
|
|
1279
|
+
},
|
|
1280
|
+
h('div', { className: 'dsb-pod__glow' }),
|
|
1281
|
+
status === 'waiting' ? h('div', { className: 'dsb-pod__pulse' }) : null,
|
|
1282
|
+
body,
|
|
1283
|
+
label)
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
function stageElements(group, L, W, H, modeKey, ctx) {
|
|
1287
|
+
const effMode = L.strip ? 'strip' : (L.hideMeta ? 'crowd' : modeKey)
|
|
1288
|
+
const compact = effMode !== modeKey || modeKey === 'crowd'
|
|
1289
|
+
const d = L.density == null ? 1 : L.density
|
|
1290
|
+
const labelH = compact ? 16 : 28
|
|
1291
|
+
const gap = compact ? 5 : 7
|
|
1292
|
+
const pods = []
|
|
1293
|
+
for (const node of group.nodes) {
|
|
1294
|
+
const p = L.pos[node.id]
|
|
1295
|
+
if (!p) continue
|
|
1296
|
+
const sh = p.nameShift || 0
|
|
1297
|
+
const half = Math.min(estimateLabelWidth(node), p.labelMax || 999) / 2
|
|
1298
|
+
// 名字收起的卫星不占障碍物,光束不必再绕一块不存在的字;
|
|
1299
|
+
// 绕行时给文字留 5px 呼吸:光束带辉光,贴着字边走还是会被看成压字
|
|
1300
|
+
const pad = 5
|
|
1301
|
+
const rect = ctx.hideLabels && !node.coord
|
|
1302
|
+
? null
|
|
1303
|
+
: (p.labelUp
|
|
1304
|
+
? { x0: p.x - half - pad + sh, x1: p.x + half + pad + sh, y0: p.y - p.pod / 2 - gap - labelH - 2, y1: p.y - p.pod / 2 - 3 }
|
|
1305
|
+
: { x0: p.x - half - pad + sh, x1: p.x + half + pad + sh, y0: p.y + p.pod / 2 + 3, y1: p.y + p.pod / 2 + gap + labelH + 2 })
|
|
1306
|
+
pods.push({ id: node.id, x: p.x, y: p.y, pod: p.pod, rect })
|
|
1307
|
+
}
|
|
1308
|
+
const filterId = 'dsb-soft-' + ctx.uid
|
|
1309
|
+
const beams = []
|
|
1310
|
+
edgesOf(group).forEach((edge, i) => {
|
|
1311
|
+
const a = L.pos[edge.from]
|
|
1312
|
+
const b = L.pos[edge.to]
|
|
1313
|
+
if (!a || !b) return
|
|
1314
|
+
const route = routeBeam(
|
|
1315
|
+
{ id: edge.from, x: a.x, y: a.y, pod: a.pod, isCenter: a.isCenter },
|
|
1316
|
+
{ id: edge.to, x: b.x, y: b.y, pod: b.pod, isCenter: b.isCenter },
|
|
1317
|
+
L, pods, W, H,
|
|
1318
|
+
)
|
|
1319
|
+
beams.push(h(Fragment, { key: edge.from + '>' + edge.to + ':' + edge.kind + ':' + i },
|
|
1320
|
+
beamElements(edge, route, ctx.uid + '-' + i, ctx.motion, filterId)))
|
|
1321
|
+
})
|
|
1322
|
+
const orbit = !L.strip && (L.ringCount > 2 || (modeKey === 'solo' && L.ringCount > 0))
|
|
1323
|
+
? h('ellipse', { key: 'orbit', className: 'dsb-orbit', cx: L.center.x.toFixed(1), cy: L.center.y.toFixed(1), rx: L.rx.toFixed(1), ry: L.ry.toFixed(1) })
|
|
1324
|
+
: null
|
|
1325
|
+
const svg = h('svg', {
|
|
1326
|
+
key: 'beams', className: 'dsb-beams', viewBox: '0 0 ' + W + ' ' + H,
|
|
1327
|
+
'aria-hidden': 'true', focusable: 'false',
|
|
1328
|
+
},
|
|
1329
|
+
h('defs', null,
|
|
1330
|
+
h('filter', { id: filterId, x: '-40%', y: '-40%', width: '180%', height: '180%' },
|
|
1331
|
+
h('feGaussianBlur', { stdDeviation: 3.2, result: 'b' }),
|
|
1332
|
+
h('feMerge', null, h('feMergeNode', { in: 'b' }), h('feMergeNode', { in: 'SourceGraphic' })))),
|
|
1333
|
+
orbit,
|
|
1334
|
+
beams)
|
|
1335
|
+
return [svg].concat(group.nodes.map((node) => {
|
|
1336
|
+
const p = L.pos[node.id]
|
|
1337
|
+
return p ? podElement(node, p, effMode, ctx) : null
|
|
1338
|
+
}))
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// ── 组件:任务卡 ──
|
|
1342
|
+
function HiveCard({ group, index, stageW, availH, budget, fill, modeKey, density, motion, onOpenSession }) {
|
|
1343
|
+
const natural = useMemo(
|
|
1344
|
+
() => (stageW ? layoutHive(group.nodes, stageW, availH, modeKey, 0, density).height : 0),
|
|
1345
|
+
[group, stageW, availH, modeKey, density],
|
|
1346
|
+
)
|
|
1347
|
+
const strip = !fill && budget != null && budget < natural + HIVE_HEAD_H
|
|
1348
|
+
const probe = useMemo(
|
|
1349
|
+
() => (strip && stageW ? layoutStrip(group.nodes, stageW, 0, modeKey, density).height : natural),
|
|
1350
|
+
[strip, group, stageW, modeKey, natural, density],
|
|
1351
|
+
)
|
|
1352
|
+
const stageH = fill ? null : (strip ? Math.max(probe, budget - HIVE_HEAD_H) : natural)
|
|
1353
|
+
const [box, setBox] = useState(null)
|
|
1354
|
+
const ref = useRef(null)
|
|
1355
|
+
useLayoutEffect(() => {
|
|
1356
|
+
const el = ref.current
|
|
1357
|
+
if (!el) return
|
|
1358
|
+
const w = Math.round(el.clientWidth)
|
|
1359
|
+
const hgt = Math.round(el.clientHeight)
|
|
1360
|
+
if (hgt <= 0) return
|
|
1361
|
+
setBox((prev) => (prev && Math.abs(prev.w - w) <= 1 && Math.abs(prev.h - hgt) <= 1 ? prev : { w, h: hgt }))
|
|
1362
|
+
})
|
|
1363
|
+
const W = box ? box.w : stageW
|
|
1364
|
+
const H = box ? box.h : (stageH || availH)
|
|
1365
|
+
const L = useMemo(
|
|
1366
|
+
() => (W ? (strip ? layoutStrip(group.nodes, W, H, modeKey, density) : layoutHive(group.nodes, W, availH, modeKey, H, density)) : null),
|
|
1367
|
+
[group, W, H, availH, modeKey, strip, density],
|
|
1368
|
+
)
|
|
1369
|
+
if (!L) return null
|
|
1370
|
+
const coord = group.nodes.find((n) => n.coord) || group.nodes[0]
|
|
1371
|
+
const botCount = group.nodes.filter((n) => !n.isUser).length
|
|
1372
|
+
const waitCount = group.nodes.filter((n) => n.activeStatus === 'waiting').length
|
|
1373
|
+
return h('section', {
|
|
1374
|
+
className: 'dsb-task',
|
|
1375
|
+
'data-mode': strip ? 'strip' : (L.hideMeta ? 'crowd' : modeKey),
|
|
1376
|
+
'data-active-group': group.id,
|
|
1377
|
+
style: { '--dsb-card-tint': tintOf(coord && coord.color) },
|
|
1378
|
+
},
|
|
1379
|
+
h('div', { className: 'dsb-task__head' },
|
|
1380
|
+
h('span', { className: 'dsb-task__dot' }),
|
|
1381
|
+
h('span', { className: 'dsb-task__name', title: group.label }, group.label),
|
|
1382
|
+
h('span', { className: 'dsb-task__stats' },
|
|
1383
|
+
h('b', null, String(botCount)), 'Bot',
|
|
1384
|
+
waitCount ? h(Fragment, null, ' · ', h('b', { className: 'dsb-amber' }, String(waitCount)), '等待') : null)),
|
|
1385
|
+
h('div', {
|
|
1386
|
+
className: 'dsb-stage',
|
|
1387
|
+
ref,
|
|
1388
|
+
// 舞台密度:名字块字号 / 冠标 / 标签间距跟着舱体一起缩
|
|
1389
|
+
style: Object.assign({ '--dsb-pk': String(density) }, stageH != null ? { height: stageH } : null),
|
|
1390
|
+
},
|
|
1391
|
+
stageElements(group, L, W, H, strip ? 'strip' : modeKey, { motion, uid: 'dsb' + index, density, hideLabels: !!L.hideLabels, onOpenSession })))
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
// ── 组件:画布(量宽高 → 算自然高度 → 放不下时按预算分给各卡) ──
|
|
1395
|
+
function HiveCanvas({ groups, modeKey, motion, onOpenSession }) {
|
|
1396
|
+
const ref = useRef(null)
|
|
1397
|
+
const [size, setSize] = useState({ w: 0, h: 0 })
|
|
1398
|
+
useLayoutEffect(() => {
|
|
1399
|
+
const el = ref.current
|
|
1400
|
+
if (!el) return undefined
|
|
1401
|
+
const measure = () => {
|
|
1402
|
+
const w = Math.round(el.clientWidth)
|
|
1403
|
+
const hgt = Math.round(el.clientHeight)
|
|
1404
|
+
setSize((prev) => (prev.w === w && prev.h === hgt ? prev : { w, h: hgt }))
|
|
1405
|
+
}
|
|
1406
|
+
measure()
|
|
1407
|
+
if (typeof ResizeObserver === 'undefined') return undefined
|
|
1408
|
+
const ro = new ResizeObserver(measure)
|
|
1409
|
+
ro.observe(el)
|
|
1410
|
+
return () => ro.disconnect()
|
|
1411
|
+
}, [])
|
|
1412
|
+
const cols = size.w >= 760 && groups.length > 1 ? 2 : 1
|
|
1413
|
+
const rows = Math.max(1, Math.ceil(groups.length / cols))
|
|
1414
|
+
const stageW = size.w ? Math.max(140, Math.floor((size.w - HIVE_PAD_X * 2 - HIVE_GAP * (cols - 1)) / cols) - 2) : 0
|
|
1415
|
+
const availH = size.h ? Math.max(120, Math.floor((size.h - HIVE_PAD_Y - HIVE_GAP * (rows - 1)) / rows) - HIVE_HEAD_H) : 0
|
|
1416
|
+
// 舞台密度:窄侧栏里舱体 / 名字块 / 留白整体等比收紧,宽面板保持标准尺寸
|
|
1417
|
+
const density = stageW ? densityOf(modeKey, stageW) : 1
|
|
1418
|
+
const naturals = useMemo(
|
|
1419
|
+
() => (stageW ? groups.map((g) => layoutHive(g.nodes, stageW, availH, modeKey, 0, density).height + HIVE_HEAD_H) : []),
|
|
1420
|
+
[groups, stageW, availH, modeKey, density],
|
|
1421
|
+
)
|
|
1422
|
+
// 单任务 + 窄面板 + 星团远小于舞台:卡片贴着星团、垂直居中,别让一整块玻璃舱里只飘着两三颗舱体。
|
|
1423
|
+
// (宽面板不启用:那里舱体还能按纵向富余放大一档,卡片铺满更气派。)
|
|
1424
|
+
const compact = groups.length === 1 && density < 0.999 && !!size.h && naturals.length === 1 && naturals[0] < (size.h - HIVE_PAD_Y) * 0.62
|
|
1425
|
+
const fill = groups.length === 1 && !compact && singleTaskFills(naturals[0], size.h)
|
|
1426
|
+
const cardAvailH = compact ? Math.max(120, naturals[0] - HIVE_HEAD_H) : availH
|
|
1427
|
+
const budget = useMemo(() => {
|
|
1428
|
+
if (fill || !size.h || groups.length < 2 || !naturals.length) return null
|
|
1429
|
+
const rowNeed = []
|
|
1430
|
+
for (let r = 0; r < rows; r++) {
|
|
1431
|
+
let m = 0
|
|
1432
|
+
for (let c = 0; c < cols; c++) {
|
|
1433
|
+
const i = r * cols + c
|
|
1434
|
+
if (i < groups.length) m = Math.max(m, naturals[i])
|
|
1435
|
+
}
|
|
1436
|
+
rowNeed.push(m)
|
|
1437
|
+
}
|
|
1438
|
+
const need = rowNeed.reduce((a, b) => a + b, 0) + (rows - 1) * HIVE_GAP
|
|
1439
|
+
if (need <= size.h - HIVE_PAD_Y + 1) return null
|
|
1440
|
+
const free = size.h - HIVE_PAD_Y - (rows - 1) * HIVE_GAP
|
|
1441
|
+
if (cols === 1) {
|
|
1442
|
+
const weights = groups.map((g) => Math.pow(g.nodes.length, 0.7))
|
|
1443
|
+
const total = weights.reduce((a, b) => a + b, 0)
|
|
1444
|
+
return weights.map((w) => Math.floor((free * w) / total))
|
|
1445
|
+
}
|
|
1446
|
+
return groups.map(() => Math.floor(free / rows))
|
|
1447
|
+
}, [fill, size.h, groups, naturals, rows, cols])
|
|
1448
|
+
|
|
1449
|
+
return h('div', {
|
|
1450
|
+
className: 'dsb-canvas',
|
|
1451
|
+
ref,
|
|
1452
|
+
'data-cols': String(cols),
|
|
1453
|
+
'data-fill': fill ? 'true' : 'false',
|
|
1454
|
+
'data-center': compact ? 'true' : 'false',
|
|
1455
|
+
'data-empty': groups.length ? 'false' : 'true',
|
|
1456
|
+
},
|
|
1457
|
+
groups.length
|
|
1458
|
+
? groups.map((group, i) => h(HiveCard, {
|
|
1459
|
+
key: group.id,
|
|
1460
|
+
group,
|
|
1461
|
+
index: i,
|
|
1462
|
+
stageW,
|
|
1463
|
+
availH: cardAvailH,
|
|
1464
|
+
budget: budget ? budget[i] : null,
|
|
1465
|
+
fill,
|
|
1466
|
+
modeKey,
|
|
1467
|
+
density,
|
|
1468
|
+
motion,
|
|
1469
|
+
onOpenSession,
|
|
1470
|
+
}))
|
|
1471
|
+
: h(HiveEmpty))
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
function HiveEmpty() {
|
|
1475
|
+
return h('div', { className: 'dsb-empty' },
|
|
1476
|
+
h('div', { className: 'dsb-empty__orbit' }),
|
|
1477
|
+
h('div', null,
|
|
1478
|
+
h('div', { className: 'dsb-empty__core' }, h(BrandGlyph, { size: 22, stroke: 1.6 })),
|
|
1479
|
+
h('div', { className: 'dsb-empty__title' }, '全员待命'),
|
|
1480
|
+
h('div', { className: 'dsb-empty__sub' }, '在会话里 @ 一个 Bot,星轨就会亮起来')))
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
// ── 组件:HUD / 页签 / 待机坞 ──
|
|
1484
|
+
function HiveHud({ groups, botTotal, waiting, idleCount, stale, themeName, motionOn, onToggleTheme, onToggleMotion }) {
|
|
1485
|
+
const working = Math.max(0, botTotal - waiting)
|
|
1486
|
+
return h('div', { className: 'dsb-hud' },
|
|
1487
|
+
h('div', { className: 'dsb-hud__brand' }, h(BrandGlyph, { size: 18 })),
|
|
1488
|
+
h('div', null,
|
|
1489
|
+
h('div', { className: 'dsb-hud__title' },
|
|
1490
|
+
'Starboard',
|
|
1491
|
+
h('span', {
|
|
1492
|
+
className: 'dsb-hud__live',
|
|
1493
|
+
'data-stale': stale ? 'true' : 'false',
|
|
1494
|
+
title: stale ? '数据已陈旧,下一轮自动重试' : '数据已同步',
|
|
1495
|
+
})),
|
|
1496
|
+
h('div', { className: 'dsb-hud__sub', 'aria-live': 'polite', 'aria-atomic': 'true' },
|
|
1497
|
+
h('b', null, String(groups)), ' 个任务 · ',
|
|
1498
|
+
h('b', null, String(botTotal)), ' Bot 在岗',
|
|
1499
|
+
waiting ? h(Fragment, null, ' · ', h('b', { className: 'dsb-amber' }, String(waiting)), ' 等待') : null)),
|
|
1500
|
+
h('div', { className: 'dsb-hud__actions' },
|
|
1501
|
+
h('button', {
|
|
1502
|
+
type: 'button', className: 'dsb-hud__btn', onClick: onToggleTheme,
|
|
1503
|
+
title: themeName === 'dark' ? '切换浅色' : '切换深色',
|
|
1504
|
+
'aria-label': themeName === 'dark' ? '切换浅色' : '切换深色',
|
|
1505
|
+
}, h(HudIcon, { name: themeName === 'dark' ? 'sun' : 'moon', size: 15 })),
|
|
1506
|
+
h('button', {
|
|
1507
|
+
type: 'button', className: 'dsb-hud__btn', onClick: onToggleMotion,
|
|
1508
|
+
title: motionOn ? '暂停动效' : '开启动效',
|
|
1509
|
+
'aria-label': motionOn ? '暂停动效' : '开启动效',
|
|
1510
|
+
'aria-pressed': motionOn ? 'true' : 'false',
|
|
1511
|
+
'data-active': motionOn ? 'true' : 'false',
|
|
1512
|
+
}, h(HudIcon, { name: motionOn ? 'motion' : 'still', size: 15 }))),
|
|
1513
|
+
h('div', { className: 'dsb-hud__meter', 'aria-hidden': 'true' },
|
|
1514
|
+
working ? h('i', { className: 'dsb-m-work', style: { flex: working } }) : null,
|
|
1515
|
+
waiting ? h('i', { className: 'dsb-m-wait', style: { flex: waiting } }) : null,
|
|
1516
|
+
h('i', { className: 'dsb-m-idle', style: { flex: Math.max(1, idleCount) } })))
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
function HiveTabs({ options, scope, onSelect }) {
|
|
1520
|
+
return h('div', { className: 'dsb-tabs', role: 'group', 'aria-label': '按活跃任务筛选' },
|
|
1521
|
+
h('button', {
|
|
1522
|
+
type: 'button', className: 'dsb-tab', onClick: () => onSelect('all'),
|
|
1523
|
+
'aria-pressed': scope === 'all' ? 'true' : 'false',
|
|
1524
|
+
style: { '--dsb-tint': '124,141,255' },
|
|
1525
|
+
}, h('i'), '全部'),
|
|
1526
|
+
options.map((item) => h('button', {
|
|
1527
|
+
key: item.id, type: 'button', className: 'dsb-tab', onClick: () => onSelect(item.id),
|
|
1528
|
+
'aria-pressed': scope === item.id ? 'true' : 'false',
|
|
1529
|
+
title: item.label,
|
|
1530
|
+
style: { '--dsb-tint': item.tint || '124,141,255' },
|
|
1531
|
+
}, h('i'), item.label)))
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
function HiveDock({ bots, motion, density, onOpenSession }) {
|
|
1535
|
+
// 待机坞跟着面板密度缩:窄侧栏里头像与格子一起变小(默认 30px 格子 / 18px 头像)
|
|
1536
|
+
const d = density == null ? 1 : density
|
|
1537
|
+
const glyphSize = Math.round(18 * d)
|
|
1538
|
+
const boxSize = Math.round(20 * d)
|
|
1539
|
+
return h('div', { className: 'dsb-dock', 'data-dsbot-board-dock': '' },
|
|
1540
|
+
h('div', { className: 'dsb-dock__head' }, '待命 ', h('b', null, String(bots.length)), ' · 随时可派活'),
|
|
1541
|
+
h('div', { className: 'dsb-dock__row' }, bots.map((bot, i) => {
|
|
1542
|
+
const avatar = bot.avatar || {}
|
|
1543
|
+
const mark = avatar.shape ? characterMarkupOf(avatar.shape, glyphSize) : null
|
|
1544
|
+
const glyph = mark
|
|
1545
|
+
? h('svg', {
|
|
1546
|
+
width: glyphSize, height: glyphSize, viewBox: '-50 -50 100 100', 'aria-hidden': 'true', focusable: 'false',
|
|
1547
|
+
// 尺寸写进 style:宿主里有 button > svg 之类的全局规则,只带 width/height 属性会被压成几像素
|
|
1548
|
+
style: { width: glyphSize, height: glyphSize, display: 'block', flex: '0 0 auto' },
|
|
1549
|
+
},
|
|
1550
|
+
renderCharacter(h, {
|
|
1551
|
+
def: mark.def, id: mark.id, r: 50, color: bot.color,
|
|
1552
|
+
uid: 'dsbdock' + i, status: 'idle', reducedMotion: !motion, active: false,
|
|
1553
|
+
blinkDelay: -((i * 0.73) % 3.1), seed: bot.name, nodeKey: bot.id,
|
|
1554
|
+
// 待机坞 18px 走极简:纯色身体,不建渐变/遮罩,宿主里 url(#id) 偶发失效时不会只剩眼睛
|
|
1555
|
+
simple: true,
|
|
1556
|
+
}))
|
|
1557
|
+
: h('span', { className: 'dsb-dock__letter' }, String(bot.name || '?').slice(0, 1))
|
|
1558
|
+
const inner = avatar.image
|
|
1559
|
+
? h(AvatarImg, {
|
|
1560
|
+
src: avatar.image,
|
|
1561
|
+
alt: '',
|
|
1562
|
+
style: { width: boxSize, height: boxSize, borderRadius: '50%', objectFit: 'cover', display: 'block' },
|
|
1563
|
+
fallback: glyph,
|
|
1564
|
+
})
|
|
1565
|
+
: glyph
|
|
1566
|
+
return h('button', {
|
|
1567
|
+
key: bot.id,
|
|
1568
|
+
type: 'button',
|
|
1569
|
+
className: 'dsb-dock__item',
|
|
1570
|
+
title: bot.name,
|
|
1571
|
+
'aria-label': '打开 ' + bot.name + ' 的会话',
|
|
1572
|
+
onClick: () => { if (onOpenSession) onOpenSession({ botId: bot.id, key: bot.id, name: bot.name }) },
|
|
1573
|
+
}, h('span', { className: 'dsb-dock__glyph' }, inner))
|
|
1574
|
+
})))
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
function HiveSkeleton() {
|
|
1578
|
+
return h('div', { className: 'dsb-skeleton', 'data-dsbot-board-skeleton': '' },
|
|
1579
|
+
h('div', { className: 'dsb-skeleton__row', style: { width: '42%', height: 14 } }),
|
|
1580
|
+
h('div', { className: 'dsb-skeleton__row', style: { width: '100%', height: 1, opacity: 0.5 } }),
|
|
1581
|
+
h('div', { className: 'dsb-skeleton__stage' },
|
|
1582
|
+
h('div', { className: 'dsb-skeleton__dot', style: { left: '18%', top: '22%', width: 72, height: 72 } }),
|
|
1583
|
+
h('div', { className: 'dsb-skeleton__dot', style: { right: '16%', top: '48%', width: 88, height: 88 } }),
|
|
1584
|
+
h('div', { className: 'dsb-skeleton__dot', style: { left: '46%', top: '68%', width: 64, height: 64 } })),
|
|
1585
|
+
h('div', { className: 'dsb-skeleton__row', style: { width: '100%', height: 44 } }))
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
function HiveError({ message, onRetry }) {
|
|
1589
|
+
return h('div', { className: 'dsb-error' },
|
|
1590
|
+
h('div', { className: 'dsb-error__box' },
|
|
1591
|
+
h('div', { className: 'dsb-error__icon' }, h(HudIcon, { name: 'alert', size: 24 })),
|
|
1592
|
+
h('div', { className: 'dsb-error__title' }, '数据通道没通'),
|
|
1593
|
+
h('div', { className: 'dsb-error__msg' }, message),
|
|
1594
|
+
h('button', { type: 'button', className: 'dsb-retry', onClick: onRetry },
|
|
1595
|
+
h(HudIcon, { name: 'refresh', size: 14 }), '重试')))
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
// ── 根组件 ──
|
|
1599
|
+
function BoardView(props) {
|
|
1600
|
+
const {
|
|
1601
|
+
phase, message, board, bots, failed, lastChecked, lastUpdated,
|
|
1602
|
+
themeName, themeVars, onToggleTheme, motionOn, onToggleMotion,
|
|
1603
|
+
scope, onSelectScope, onRetry, onOpenSession,
|
|
1604
|
+
} = props
|
|
1605
|
+
const vars = Object.assign({}, HIVE_VARS[themeName] || HIVE_VARS.dark, themeVars || {})
|
|
1606
|
+
// 面板宽度 → 外围 chrome 密度:侧栏拖窄时 HUD / 页签 / 待机坞 / 卡片圆角一起收紧
|
|
1607
|
+
const rootRef = useRef(null)
|
|
1608
|
+
const [panelW, setPanelW] = useState(0)
|
|
1609
|
+
useLayoutEffect(() => {
|
|
1610
|
+
const el = rootRef.current
|
|
1611
|
+
if (!el) return undefined
|
|
1612
|
+
const measure = () => {
|
|
1613
|
+
const w = Math.round(el.clientWidth)
|
|
1614
|
+
setPanelW((prev) => (prev === w ? prev : w))
|
|
1615
|
+
}
|
|
1616
|
+
measure()
|
|
1617
|
+
if (typeof ResizeObserver === 'undefined') return undefined
|
|
1618
|
+
const ro = new ResizeObserver(measure)
|
|
1619
|
+
ro.observe(el)
|
|
1620
|
+
return () => ro.disconnect()
|
|
1621
|
+
}, [])
|
|
1622
|
+
const chromeK = chromeDensityOf(panelW)
|
|
1623
|
+
const reduced = useMemo(() => {
|
|
1624
|
+
try { return !!(window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) } catch (error) { return false }
|
|
1625
|
+
}, [])
|
|
1626
|
+
const motion = motionOn !== false && !reduced
|
|
1627
|
+
const groups = (board && board.groups) || []
|
|
1628
|
+
const visible = scope === 'all' ? groups : groups.filter((g) => g.id === scope)
|
|
1629
|
+
const modeKey = visible.length >= 3 ? 'crowd' : visible.length === 2 ? 'duo' : 'solo'
|
|
1630
|
+
const activeIds = useMemo(() => {
|
|
1631
|
+
const set = {}
|
|
1632
|
+
for (const g of groups) for (const n of g.nodes) if (!n.isUser) set[n.id] = 1
|
|
1633
|
+
return set
|
|
1634
|
+
}, [groups])
|
|
1635
|
+
const idle = useMemo(() => {
|
|
1636
|
+
const list = (bots || []).filter((b) => !activeIds[b.id])
|
|
1637
|
+
try {
|
|
1638
|
+
// 待机坞头像也走 hostLookOf:必须和宿主会话列表、和舱体里那只完全是同一个角色。
|
|
1639
|
+
return list.map((b) => {
|
|
1640
|
+
const look = hostLookOf(b)
|
|
1641
|
+
return { ...b, color: look.color, avatar: { ...(b.avatar || {}), shape: look.shape } }
|
|
1642
|
+
})
|
|
1643
|
+
} catch (error) {
|
|
1644
|
+
return list
|
|
1645
|
+
}
|
|
1646
|
+
}, [bots, activeIds])
|
|
1647
|
+
const botTotal = board ? board.activeCount : 0
|
|
1648
|
+
const waiting = board ? board.waitingCount : 0
|
|
1649
|
+
const stale = phase === 'ok' && (failed > 0 || Date.now() - (lastChecked || lastUpdated || 0) > 15000)
|
|
1650
|
+
const tabOptions = groups.map((g) => {
|
|
1651
|
+
const coord = g.nodes.find((n) => n.coord) || g.nodes[0]
|
|
1652
|
+
return { id: g.id, label: g.label, tint: tintOf(coord && coord.color) }
|
|
1653
|
+
})
|
|
1654
|
+
|
|
1655
|
+
let content
|
|
1656
|
+
if (phase === 'loading') {
|
|
1657
|
+
content = h(HiveSkeleton)
|
|
1658
|
+
} else if (phase === 'error') {
|
|
1659
|
+
content = h(HiveError, { message, onRetry })
|
|
1660
|
+
} else {
|
|
1661
|
+
content = h(HiveCanvas, { groups: visible, modeKey, motion, onOpenSession })
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
return h('div', {
|
|
1665
|
+
className: 'dsb-root' + (motion ? '' : ' dsb-motion-off'),
|
|
1666
|
+
ref: rootRef,
|
|
1667
|
+
style: Object.assign({}, vars, { '--dsb-k': String(chromeK) }),
|
|
1668
|
+
'data-dsbot-board-shell': '',
|
|
1669
|
+
},
|
|
1670
|
+
phase === 'ok'
|
|
1671
|
+
? h(HiveHud, {
|
|
1672
|
+
groups: groups.length,
|
|
1673
|
+
botTotal,
|
|
1674
|
+
waiting,
|
|
1675
|
+
idleCount: idle.length,
|
|
1676
|
+
stale,
|
|
1677
|
+
themeName,
|
|
1678
|
+
motionOn: motionOn !== false,
|
|
1679
|
+
onToggleTheme,
|
|
1680
|
+
onToggleMotion,
|
|
1681
|
+
})
|
|
1682
|
+
: null,
|
|
1683
|
+
phase === 'ok' && groups.length > 1
|
|
1684
|
+
? h(HiveTabs, { options: tabOptions, scope, onSelect: onSelectScope })
|
|
1685
|
+
: null,
|
|
1686
|
+
phase === 'ok' && failed
|
|
1687
|
+
? h('div', { className: 'dsb-banner', role: 'status' },
|
|
1688
|
+
h(HudIcon, { name: 'alert', size: 13 }), '部分空间读取失败,正在自动重试')
|
|
1689
|
+
: null,
|
|
1690
|
+
content,
|
|
1691
|
+
phase === 'ok' && idle.length ? h(HiveDock, { bots: idle, motion, density: chromeK, onOpenSession }) : null)
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
// 供回归测试直接驱动纯布局/布线函数(不依赖 DOM)
|
|
1695
|
+
BoardView.__hive = {
|
|
1696
|
+
HIVE_MODES, naturalWidthOf, densityOf, chromeDensityOf,
|
|
1697
|
+
edgesOf, anglesFor, evenAngles, minSpacing, estimateLabelWidth,
|
|
1698
|
+
resolveLabels, layoutHive, layoutStrip, routeBeam, curveLength, pointAt, collides, singleTaskFills,
|
|
1699
|
+
}
|
|
1700
|
+
return BoardView
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
return { createBoardView, hiveStyleText, hostLookOf }
|
|
1704
|
+
})()
|
|
1705
|
+
// hostLookOf 要给数据层用:节点和待机坞的头像必须跟宿主 ds-bot 的 lookOf() 同一套派生
|
|
1706
|
+
const { createBoardView, hiveStyleText, hostLookOf } = boardViewModule
|
|
1707
|
+
|
|
1708
|
+
// 全局聚合(群 + 私聊)
|
|
1709
|
+
const listOf = (v) => (Array.isArray(v) ? v : v && typeof v === 'object' ? Object.values(v) : [])
|
|
1710
|
+
const pick = (obj, keys, fallback) => {
|
|
1711
|
+
for (const key of keys) {
|
|
1712
|
+
const value = obj ? obj[key] : undefined
|
|
1713
|
+
if (value !== undefined && value !== null && value !== '') return value
|
|
1714
|
+
}
|
|
1715
|
+
return fallback
|
|
1716
|
+
}
|
|
1717
|
+
// 全局聚合:把「所有群」+「所有 Bot 私聊」的协作拼成一条统一事件流。
|
|
1718
|
+
// 由 .build-client.cjs 内联;不能有 import/export。
|
|
1719
|
+
|
|
1720
|
+
// 一个会话的一条消息 → 统一事件。
|
|
1721
|
+
// source 字段来自 room-chat / chat 的行:{ id, kind, botId, name, text, time, sessionId, turn, messageId }
|
|
1722
|
+
function toBoardEvent(row, ctx) {
|
|
1723
|
+
const kind = String(pick(row, ['kind'], 'message'))
|
|
1724
|
+
const text = String(pick(row, ['text', 'body'], ''))
|
|
1725
|
+
const botId = String(pick(row, ['botId', 'bot', 'fromId'], '') || '')
|
|
1726
|
+
const name = pick(row, ['name', 'who'], '') || ''
|
|
1727
|
+
const seq = pick(row, ['seq'], null)
|
|
1728
|
+
const mid = pick(row, ['messageId', 'id'], null)
|
|
1729
|
+
const isUser = kind === 'user' || (!botId && /^user$/i.test(name))
|
|
1730
|
+
return {
|
|
1731
|
+
key: ctx.scope + '|' + (mid == null ? ctx.i : mid),
|
|
1732
|
+
scope: ctx.scope, // 'room:<id>' 或 'bot:<id>'
|
|
1733
|
+
scopeLabel: ctx.scopeLabel,
|
|
1734
|
+
kind,
|
|
1735
|
+
botId,
|
|
1736
|
+
name: isUser ? 'User' : name,
|
|
1737
|
+
isUser,
|
|
1738
|
+
text,
|
|
1739
|
+
time: pick(row, ['time', 'at'], null),
|
|
1740
|
+
turn: pick(row, ['turn'], null),
|
|
1741
|
+
messageId: mid,
|
|
1742
|
+
seq: seq == null ? ctx.i : seq,
|
|
1743
|
+
order: ctx.order + ctx.i, // 跨会话的稳定排序:先群后私聊,各自按行序
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
// @ 提及:从文本里解析出被叫到的名字,供画边使用。
|
|
1748
|
+
// 关键:名字允许含空格(Lead Bot、Software Engineer),所以不能按空白切词。
|
|
1749
|
+
// 做法是「长名字优先」在原文里直接找 @名字,找到多长的就吃多长,剩下才按短名匹配。
|
|
1750
|
+
function mentionsOf(text, names) {
|
|
1751
|
+
const out = []
|
|
1752
|
+
const source = String(text || '')
|
|
1753
|
+
const list = (names || []).filter(Boolean)
|
|
1754
|
+
if (!list.length) return out
|
|
1755
|
+
// 长的排前面:@Software Engineer 必须先于 @Software 被吃掉。
|
|
1756
|
+
const ordered = list.slice().sort((a, b) => b.length - a.length)
|
|
1757
|
+
let rest = source
|
|
1758
|
+
for (const name of ordered) {
|
|
1759
|
+
const token = '@' + name
|
|
1760
|
+
if (!rest.includes(token)) continue
|
|
1761
|
+
// 还要求后面不是紧跟一个会把它变成更长名字的字符。
|
|
1762
|
+
let idx = rest.indexOf(token)
|
|
1763
|
+
let taken = 0
|
|
1764
|
+
while (idx >= 0) {
|
|
1765
|
+
const after = rest.charAt(idx + token.length)
|
|
1766
|
+
const isBoundary = !after || /[\s@,,。::;;!!??、.]/.test(after)
|
|
1767
|
+
if (isBoundary) {
|
|
1768
|
+
out.push(name)
|
|
1769
|
+
taken++
|
|
1770
|
+
rest = rest.slice(0, idx) + rest.slice(idx + token.length)
|
|
1771
|
+
}
|
|
1772
|
+
idx = rest.indexOf(token, idx + 1)
|
|
1773
|
+
if (idx < 0) break
|
|
1774
|
+
}
|
|
1775
|
+
if (taken) continue
|
|
1776
|
+
}
|
|
1777
|
+
return out
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
// 头像派生统一走 characters-view.js 的 hostLookOf()(与宿主 ds-bot 的 lookOf() 同一套 id 哈希),
|
|
1781
|
+
// 以前那套"按名字派生 + localStorage 注册表避让"会让同一个 bot 在看板和宿主列表里长成两只,已整体废弃。
|
|
1782
|
+
|
|
1783
|
+
// 全局快照 → 组件输入(nodes + messages)。
|
|
1784
|
+
// snapshot: { bots, rooms, roomItems: {roomId: rows}, botItems: {botId: rows} }
|
|
1785
|
+
function buildGlobalBoard(snapshot, opts) {
|
|
1786
|
+
const options = opts || {}
|
|
1787
|
+
const includePrivate = options.includePrivate !== false
|
|
1788
|
+
const bots = listOf(snapshot.bots)
|
|
1789
|
+
const rooms = listOf(snapshot.rooms)
|
|
1790
|
+
const roomItems = snapshot.roomItems || {}
|
|
1791
|
+
const botItems = snapshot.botItems || {}
|
|
1792
|
+
|
|
1793
|
+
const botById = new Map(bots.map((b) => [b.id, b]))
|
|
1794
|
+
const events = []
|
|
1795
|
+
let order = 0
|
|
1796
|
+
|
|
1797
|
+
for (const room of rooms) {
|
|
1798
|
+
const rows = listOf(roomItems[room.id])
|
|
1799
|
+
const label = room.name || room.id
|
|
1800
|
+
rows.forEach((row, i) => {
|
|
1801
|
+
events.push(toBoardEvent(row, { scope: 'room:' + room.id, scopeLabel: label, order, i }))
|
|
1802
|
+
})
|
|
1803
|
+
order += rows.length
|
|
1804
|
+
}
|
|
1805
|
+
if (includePrivate) {
|
|
1806
|
+
for (const bot of bots) {
|
|
1807
|
+
const rows = listOf(botItems[bot.id])
|
|
1808
|
+
if (!rows.length) continue
|
|
1809
|
+
const label = (bot.name || bot.id) + ' · 私聊'
|
|
1810
|
+
rows.forEach((row, i) => {
|
|
1811
|
+
events.push(toBoardEvent(row, { scope: 'bot:' + bot.id, scopeLabel: label, order, i }))
|
|
1812
|
+
})
|
|
1813
|
+
order += rows.length
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
// 排序必须按消息时间,不能按「先群后私聊」的遍历顺序:
|
|
1817
|
+
// 否则一条更旧的私聊会拿到更大的下标,被当成当前消息,回放和状态全错。
|
|
1818
|
+
// 没有时间戳的(或时间相同)才用遍历顺序兜底。
|
|
1819
|
+
const timeOf = (e) => {
|
|
1820
|
+
const t = e.time
|
|
1821
|
+
if (typeof t === 'number' && Number.isFinite(t)) return t
|
|
1822
|
+
if (typeof t === 'string') {
|
|
1823
|
+
const parsed = Date.parse(t)
|
|
1824
|
+
if (Number.isFinite(parsed)) return parsed
|
|
1825
|
+
}
|
|
1826
|
+
return null
|
|
1827
|
+
}
|
|
1828
|
+
events.sort((a, b) => {
|
|
1829
|
+
const ta = timeOf(a), tb = timeOf(b)
|
|
1830
|
+
if (ta != null && tb != null && ta !== tb) return ta - tb
|
|
1831
|
+
// 一方没有时间:保持遍历顺序(不能把未知时间当成最早)。
|
|
1832
|
+
if (ta == null && tb != null) return a.order - b.order
|
|
1833
|
+
if (tb == null && ta != null) return a.order - b.order
|
|
1834
|
+
return a.order - b.order
|
|
1835
|
+
})
|
|
1836
|
+
|
|
1837
|
+
// 节点:所有发过言或只被提及的 Bot + User。空会话且未被提及的 Bot 不占版面。
|
|
1838
|
+
const seen = new Set()
|
|
1839
|
+
for (const event of events) if (event.botId) seen.add(event.botId)
|
|
1840
|
+
const hasUser = events.some((event) => event.isUser)
|
|
1841
|
+
// 提及候选必须包含 User:Bot 回 @User 也是一条协作边,漏了它这条边就消失了。
|
|
1842
|
+
const names = bots.map((bot) => bot.name).filter(Boolean)
|
|
1843
|
+
if (hasUser) names.push('User')
|
|
1844
|
+
const mentionedNames = new Set()
|
|
1845
|
+
for (const event of events) {
|
|
1846
|
+
for (const target of mentionsOf(event.text, names)) mentionedNames.add(target)
|
|
1847
|
+
}
|
|
1848
|
+
for (const bot of bots) {
|
|
1849
|
+
if (bot.name && mentionedNames.has(bot.name)) seen.add(bot.id)
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
const nodes = []
|
|
1853
|
+
for (const id of seen) {
|
|
1854
|
+
const bot = botById.get(id)
|
|
1855
|
+
if (!bot) continue
|
|
1856
|
+
// 头像三件套一律走 hostLookOf:跟宿主 ds-bot 的 lookOf() 同一套派生。
|
|
1857
|
+
const look = hostLookOf(bot)
|
|
1858
|
+
const botName = bot.name || String(id).slice(0, 8)
|
|
1859
|
+
nodes.push({
|
|
1860
|
+
id, key: id,
|
|
1861
|
+
name: botName,
|
|
1862
|
+
color: look.color,
|
|
1863
|
+
shape: look.shape,
|
|
1864
|
+
failed: bot.blocked !== undefined || bot.failed === true,
|
|
1865
|
+
...(look.image ? { avatar: { image: look.image } } : {}),
|
|
1866
|
+
coord: false,
|
|
1867
|
+
})
|
|
1868
|
+
}
|
|
1869
|
+
if (hasUser) nodes.push({ id: '__user__', key: '__user__', name: 'User', isUser: true })
|
|
1870
|
+
|
|
1871
|
+
// 主控:发出最多跨 Bot 指令的那个,标 coord。
|
|
1872
|
+
const askCount = new Map()
|
|
1873
|
+
for (const e of events) {
|
|
1874
|
+
if (!e.botId) continue
|
|
1875
|
+
const targets = mentionsOf(e.text, names)
|
|
1876
|
+
if (targets.length) askCount.set(e.botId, (askCount.get(e.botId) || 0) + targets.length)
|
|
1877
|
+
}
|
|
1878
|
+
let topId = null, topCount = 0
|
|
1879
|
+
for (const [id, count] of askCount) if (count > topCount) { topId = id; topCount = count }
|
|
1880
|
+
for (const node of nodes) node.coord = node.id === topId
|
|
1881
|
+
|
|
1882
|
+
// 消息:seq 必须是全局顺序,不能沿用会话内序号——否则新私聊的 seq=0 会排到老群 seq=100 前面,
|
|
1883
|
+
// 回放和当前边都会错。原始序号另存 sourceSeq。
|
|
1884
|
+
const messages = events.map((e, i) => ({
|
|
1885
|
+
seq: i,
|
|
1886
|
+
sourceSeq: e.seq,
|
|
1887
|
+
who: e.name,
|
|
1888
|
+
botId: e.botId,
|
|
1889
|
+
text: e.text,
|
|
1890
|
+
// @ 解析对所有人一视同仁:User 也在候选里,Bot 回 @User 才不会丢边。
|
|
1891
|
+
to: mentionsOf(e.text, names),
|
|
1892
|
+
scope: e.scope,
|
|
1893
|
+
scopeLabel: e.scopeLabel,
|
|
1894
|
+
time: e.time,
|
|
1895
|
+
}))
|
|
1896
|
+
|
|
1897
|
+
const scopeOptions = []
|
|
1898
|
+
const scopeIds = new Set()
|
|
1899
|
+
for (const event of events) {
|
|
1900
|
+
if (scopeIds.has(event.scope)) continue
|
|
1901
|
+
scopeIds.add(event.scope)
|
|
1902
|
+
scopeOptions.push({ id: event.scope, label: event.scopeLabel })
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
return {
|
|
1906
|
+
nodes,
|
|
1907
|
+
messages,
|
|
1908
|
+
scopes: [...new Set(events.map((event) => event.scopeLabel))],
|
|
1909
|
+
scopeOptions,
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
|
|
1914
|
+
// 活跃任务聚合:只把正在工作或等待协作的 Bot 放进看板,并按任务连成独立图簇。
|
|
1915
|
+
// 数据来自 state.work / state.activity;聊天记录只取活跃空间最近的上下文。
|
|
1916
|
+
|
|
1917
|
+
function activeBoardTime(value) {
|
|
1918
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value
|
|
1919
|
+
if (typeof value === 'string') {
|
|
1920
|
+
const parsed = Date.parse(value)
|
|
1921
|
+
if (Number.isFinite(parsed)) return parsed
|
|
1922
|
+
}
|
|
1923
|
+
return null
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
function activeRoomIdsOf(work) {
|
|
1927
|
+
const ids = new Set(Object.keys(work.rooms || {}))
|
|
1928
|
+
for (const info of Object.values(work.bots || {})) if (info.roomId) ids.add(info.roomId)
|
|
1929
|
+
for (const roomId of listOf(work.activeRooms)) ids.add(roomId)
|
|
1930
|
+
for (const info of Object.values(work.waiting || {})) {
|
|
1931
|
+
for (const item of listOf(info.waits)) if (item.room) ids.add(item.room)
|
|
1932
|
+
}
|
|
1933
|
+
return [...ids]
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
function activeBotIdsOf(work, activity) {
|
|
1937
|
+
const ids = new Set(Object.keys(work.bots || {}))
|
|
1938
|
+
for (const items of Object.values(work.rooms || {})) {
|
|
1939
|
+
for (const item of listOf(items)) if (item.botId) ids.add(item.botId)
|
|
1940
|
+
}
|
|
1941
|
+
for (const [botId, status] of Object.entries(activity || {})) {
|
|
1942
|
+
if (status === 'working' || status === 'thinking' || status === 'waiting' || status === 'alert') ids.add(botId)
|
|
1943
|
+
}
|
|
1944
|
+
for (const [ownerId, info] of Object.entries(work.waiting || {})) {
|
|
1945
|
+
ids.add(ownerId)
|
|
1946
|
+
for (const targetId of listOf(info.bots)) ids.add(targetId)
|
|
1947
|
+
for (const callerId of listOf(info.for)) ids.add(callerId)
|
|
1948
|
+
}
|
|
1949
|
+
return [...ids]
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
function boardBotIdAliases(bots) {
|
|
1953
|
+
const aliases = new Map()
|
|
1954
|
+
for (const bot of listOf(bots)) {
|
|
1955
|
+
const id = String(bot.id || '')
|
|
1956
|
+
if (!id) continue
|
|
1957
|
+
aliases.set(id, id)
|
|
1958
|
+
aliases.set(id.replace(/^session-/, ''), id)
|
|
1959
|
+
}
|
|
1960
|
+
return aliases
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
function resolveBoardBotId(id, aliases) {
|
|
1964
|
+
if (id == null) return null
|
|
1965
|
+
return aliases.get(String(id)) || null
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
// `state` 的 unchanged 回答只带实时 work/activity,不再重复 bots/rooms。
|
|
1969
|
+
// 看板必须沿用上一次完整回答的清单,否则活跃 ID 会被误判为未知 Bot。
|
|
1970
|
+
function boardBaseFromState(state, cached) {
|
|
1971
|
+
if (state && state.unchanged === true && cached) return cached
|
|
1972
|
+
return { bots: listOf(state && state.bots), rooms: listOf(state && state.rooms) }
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
function buildActiveBoard(snapshot, opts) {
|
|
1976
|
+
const options = opts || {}
|
|
1977
|
+
const bots = listOf(snapshot.bots)
|
|
1978
|
+
const rooms = listOf(snapshot.rooms)
|
|
1979
|
+
const roomItems = snapshot.roomItems || {}
|
|
1980
|
+
const botItems = snapshot.botItems || {}
|
|
1981
|
+
const work = snapshot.work || {}
|
|
1982
|
+
const activity = snapshot.activity || {}
|
|
1983
|
+
const waiting = work.waiting || {}
|
|
1984
|
+
const botById = new Map(bots.map((bot) => [bot.id, bot]))
|
|
1985
|
+
const botAliases = boardBotIdAliases(bots)
|
|
1986
|
+
const roomById = new Map(rooms.map((room) => [room.id, room]))
|
|
1987
|
+
const active = new Map()
|
|
1988
|
+
|
|
1989
|
+
function markActive(botId, info, preserveStatus = false, authoritative = false) {
|
|
1990
|
+
const canonicalId = resolveBoardBotId(botId, botAliases)
|
|
1991
|
+
if (!canonicalId || !botById.has(canonicalId)) return
|
|
1992
|
+
const previous = active.get(canonicalId)
|
|
1993
|
+
const previousAuthoritative = previous && previous.authoritative === true
|
|
1994
|
+
const next = { ...(previous || {}) }
|
|
1995
|
+
for (const [key, value] of Object.entries(info)) {
|
|
1996
|
+
if (value !== undefined) next[key] = value
|
|
1997
|
+
}
|
|
1998
|
+
if (preserveStatus && previousAuthoritative) next.status = previous.status
|
|
1999
|
+
else if (info.status !== undefined) next.status = info.status
|
|
2000
|
+
else if (!next.status) next.status = 'working'
|
|
2001
|
+
next.authoritative = authoritative || previousAuthoritative
|
|
2002
|
+
active.set(canonicalId, next)
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
for (const [botId, info] of Object.entries(work.bots || {})) {
|
|
2006
|
+
markActive(botId, {
|
|
2007
|
+
status: 'working',
|
|
2008
|
+
roomId: info.roomId,
|
|
2009
|
+
since: info.since,
|
|
2010
|
+
tool: info.tool,
|
|
2011
|
+
note: info.note,
|
|
2012
|
+
})
|
|
2013
|
+
}
|
|
2014
|
+
for (const [roomId, items] of Object.entries(work.rooms || {})) {
|
|
2015
|
+
for (const item of listOf(items)) {
|
|
2016
|
+
markActive(item.botId, {
|
|
2017
|
+
status: 'working',
|
|
2018
|
+
roomId,
|
|
2019
|
+
since: item.since,
|
|
2020
|
+
tool: item.tool,
|
|
2021
|
+
note: item.note,
|
|
2022
|
+
})
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
for (const [botId, status] of Object.entries(activity)) {
|
|
2026
|
+
if (status !== 'working' && status !== 'thinking' && status !== 'waiting' && status !== 'alert') continue
|
|
2027
|
+
markActive(botId, { status: status === 'alert' ? 'failed' : status }, false, true)
|
|
2028
|
+
}
|
|
2029
|
+
for (const [ownerId, info] of Object.entries(waiting)) {
|
|
2030
|
+
markActive(ownerId, { status: 'waiting' }, false, true)
|
|
2031
|
+
for (const targetId of listOf(info.bots)) markActive(targetId, { status: 'working' }, true)
|
|
2032
|
+
for (const callerId of listOf(info.for)) markActive(callerId, { status: 'working' }, true)
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
if (active.size === 0) {
|
|
2036
|
+
return {
|
|
2037
|
+
groups: [], nodes: [], messages: [], scopeOptions: [], activeCount: 0, waitingCount: 0,
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
const parent = new Map([...active.keys()].map((id) => [id, id]))
|
|
2042
|
+
function find(id) {
|
|
2043
|
+
let current = id
|
|
2044
|
+
while (parent.get(current) !== current) current = parent.get(current)
|
|
2045
|
+
return current
|
|
2046
|
+
}
|
|
2047
|
+
function union(a, b) {
|
|
2048
|
+
if (!active.has(a) || !active.has(b) || a === b) return
|
|
2049
|
+
const rootA = find(a)
|
|
2050
|
+
const rootB = find(b)
|
|
2051
|
+
if (rootA !== rootB) parent.set(rootB, rootA)
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
const roomGroups = new Map()
|
|
2055
|
+
for (const [roomId, items] of Object.entries(work.rooms || {})) {
|
|
2056
|
+
const ids = listOf(items)
|
|
2057
|
+
.map((item) => resolveBoardBotId(item.botId, botAliases))
|
|
2058
|
+
.filter((id) => id && active.has(id))
|
|
2059
|
+
if (!ids.length) continue
|
|
2060
|
+
roomGroups.set(roomId, ids)
|
|
2061
|
+
for (const id of ids) union(ids[0], id)
|
|
2062
|
+
}
|
|
2063
|
+
for (const [botId, info] of active) {
|
|
2064
|
+
if (!info.roomId) continue
|
|
2065
|
+
const ids = roomGroups.get(info.roomId) || []
|
|
2066
|
+
if (!ids.includes(botId)) ids.push(botId)
|
|
2067
|
+
roomGroups.set(info.roomId, ids)
|
|
2068
|
+
for (const id of ids) union(ids[0], id)
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
const waitLinks = []
|
|
2072
|
+
for (const [rawOwnerId, info] of Object.entries(waiting)) {
|
|
2073
|
+
const ownerId = resolveBoardBotId(rawOwnerId, botAliases)
|
|
2074
|
+
if (!ownerId) continue
|
|
2075
|
+
for (const rawTargetId of listOf(info.bots)) {
|
|
2076
|
+
const targetId = resolveBoardBotId(rawTargetId, botAliases)
|
|
2077
|
+
if (!targetId || !active.has(targetId)) continue
|
|
2078
|
+
union(ownerId, targetId)
|
|
2079
|
+
waitLinks.push({ from: ownerId, to: targetId, scope: active.get(ownerId).roomId || 'bot:' + ownerId })
|
|
2080
|
+
}
|
|
2081
|
+
for (const rawCallerId of listOf(info.for)) {
|
|
2082
|
+
const callerId = resolveBoardBotId(rawCallerId, botAliases)
|
|
2083
|
+
if (!callerId || !active.has(callerId)) continue
|
|
2084
|
+
union(callerId, ownerId)
|
|
2085
|
+
waitLinks.push({ from: callerId, to: ownerId, scope: active.get(ownerId).roomId || 'bot:' + ownerId })
|
|
2086
|
+
}
|
|
2087
|
+
for (const item of listOf(info.waits)) {
|
|
2088
|
+
if (!item.room) continue
|
|
2089
|
+
for (const targetId of roomGroups.get(item.room) || []) {
|
|
2090
|
+
union(ownerId, targetId)
|
|
2091
|
+
waitLinks.push({ from: ownerId, to: targetId, scope: 'room:' + item.room })
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
const events = []
|
|
2097
|
+
const activeRoomIds = new Set([...roomGroups.keys(), ...listOf(work.activeRooms)])
|
|
2098
|
+
for (const roomId of activeRoomIds) {
|
|
2099
|
+
const label = roomById.get(roomId)?.name || roomId
|
|
2100
|
+
listOf(roomItems[roomId]).slice(-60).forEach((row, index) => {
|
|
2101
|
+
events.push(toBoardEvent(row, { scope: 'room:' + roomId, scopeLabel: label, order: events.length, i: index }))
|
|
2102
|
+
})
|
|
2103
|
+
}
|
|
2104
|
+
for (const botId of active.keys()) {
|
|
2105
|
+
if (active.get(botId).roomId) continue
|
|
2106
|
+
const bot = botById.get(botId)
|
|
2107
|
+
const label = (bot?.name || botId) + ' · 私聊'
|
|
2108
|
+
listOf(botItems[botId]).slice(-60).forEach((row, index) => {
|
|
2109
|
+
events.push(toBoardEvent(row, { scope: 'bot:' + botId, scopeLabel: label, order: events.length, i: index }))
|
|
2110
|
+
})
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
for (const event of events) {
|
|
2114
|
+
if (event.botId) event.botId = resolveBoardBotId(event.botId, botAliases) || event.botId
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
const botNames = bots.map((bot) => bot.name).filter(Boolean)
|
|
2118
|
+
const activeNameToId = new Map()
|
|
2119
|
+
for (const botId of active.keys()) {
|
|
2120
|
+
const name = botById.get(botId)?.name
|
|
2121
|
+
if (name) activeNameToId.set(name, botId)
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
function eventBelongsToCurrentWork(event) {
|
|
2125
|
+
const time = activeBoardTime(event.time)
|
|
2126
|
+
if (time == null) return true
|
|
2127
|
+
const senderStart = event.botId ? activeBoardTime(active.get(event.botId)?.since) : null
|
|
2128
|
+
if (senderStart != null) return time >= senderStart
|
|
2129
|
+
const participantIds = [event.botId]
|
|
2130
|
+
for (const name of mentionsOf(event.text, botNames)) {
|
|
2131
|
+
const botId = activeNameToId.get(name)
|
|
2132
|
+
if (botId) participantIds.push(botId)
|
|
2133
|
+
}
|
|
2134
|
+
const startTimes = participantIds
|
|
2135
|
+
.map((botId) => activeBoardTime(active.get(botId)?.since))
|
|
2136
|
+
.filter((value) => value != null)
|
|
2137
|
+
if (!startTimes.length) return true
|
|
2138
|
+
return startTimes.some((start) => time >= start)
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
const relevantEvents = events.filter((event) => {
|
|
2142
|
+
if (!eventBelongsToCurrentWork(event)) return false
|
|
2143
|
+
if (event.isUser) return true
|
|
2144
|
+
if (active.has(event.botId)) return true
|
|
2145
|
+
return mentionsOf(event.text, botNames).some((name) => activeNameToId.has(name))
|
|
2146
|
+
})
|
|
2147
|
+
for (const event of relevantEvents) {
|
|
2148
|
+
if (!active.has(event.botId)) continue
|
|
2149
|
+
for (const name of mentionsOf(event.text, botNames)) {
|
|
2150
|
+
const targetId = activeNameToId.get(name)
|
|
2151
|
+
if (targetId) union(event.botId, targetId)
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
const components = new Map()
|
|
2156
|
+
for (const botId of active.keys()) {
|
|
2157
|
+
const root = find(botId)
|
|
2158
|
+
if (!components.has(root)) components.set(root, [])
|
|
2159
|
+
components.get(root).push(botId)
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
function makeNode(botId) {
|
|
2163
|
+
const bot = botById.get(botId)
|
|
2164
|
+
// 头像三件套一律走 hostLookOf:跟宿主 ds-bot 的 lookOf() 同一套派生,看板和宿主列表必须是同一只。
|
|
2165
|
+
const look = hostLookOf(bot)
|
|
2166
|
+
const name = bot?.name || botId
|
|
2167
|
+
return {
|
|
2168
|
+
id: botId,
|
|
2169
|
+
key: botId,
|
|
2170
|
+
name,
|
|
2171
|
+
color: look.color,
|
|
2172
|
+
shape: look.shape,
|
|
2173
|
+
failed: bot?.blocked !== undefined || bot?.failed === true || active.get(botId).status === 'failed',
|
|
2174
|
+
activeStatus: active.get(botId).status,
|
|
2175
|
+
...(look.image ? { avatar: { image: look.image } } : {}),
|
|
2176
|
+
coord: false,
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
const groups = []
|
|
2181
|
+
for (const component of components.values()) {
|
|
2182
|
+
const memberIds = new Set(component)
|
|
2183
|
+
const memberNames = new Set(component.map((id) => botById.get(id)?.name).filter(Boolean))
|
|
2184
|
+
const roomIds = [...roomGroups.entries()]
|
|
2185
|
+
.filter(([, ids]) => ids.some((id) => memberIds.has(id)))
|
|
2186
|
+
.map(([roomId]) => roomId)
|
|
2187
|
+
let label = ''
|
|
2188
|
+
if (roomIds.length === 1) label = roomById.get(roomIds[0])?.name || roomIds[0]
|
|
2189
|
+
else if (roomIds.length > 1) label = (roomById.get(roomIds[0])?.name || roomIds[0]) + ' +' + (roomIds.length - 1)
|
|
2190
|
+
else {
|
|
2191
|
+
const primary = component.map((id) => botById.get(id)).filter(Boolean)
|
|
2192
|
+
.sort((a, b) => a.name.localeCompare(b.name))[0]
|
|
2193
|
+
label = (primary?.name || component[0]) + ' · 协作'
|
|
2194
|
+
}
|
|
2195
|
+
const groupId = roomIds.length === 1 ? 'room:' + roomIds[0] : 'task:' + component.slice().sort()[0]
|
|
2196
|
+
|
|
2197
|
+
const groupEvents = relevantEvents.filter((event) => {
|
|
2198
|
+
if (event.isUser) return mentionsOf(event.text, [...memberNames]).some((name) => memberNames.has(name))
|
|
2199
|
+
if (memberIds.has(event.botId)) return true
|
|
2200
|
+
return mentionsOf(event.text, [...memberNames]).some((name) => memberNames.has(name))
|
|
2201
|
+
})
|
|
2202
|
+
const syntheticWaits = waitLinks
|
|
2203
|
+
.filter((link) => memberIds.has(link.from) && memberIds.has(link.to))
|
|
2204
|
+
.map((link, index) => ({
|
|
2205
|
+
seq: index,
|
|
2206
|
+
who: botById.get(link.from)?.name || link.from,
|
|
2207
|
+
botId: link.from,
|
|
2208
|
+
text: '',
|
|
2209
|
+
to: [botById.get(link.to)?.name || link.to],
|
|
2210
|
+
scope: groupId,
|
|
2211
|
+
scopeLabel: label,
|
|
2212
|
+
time: Date.now(),
|
|
2213
|
+
synthetic: true,
|
|
2214
|
+
}))
|
|
2215
|
+
const allEvents = groupEvents.concat(syntheticWaits).sort((a, b) => {
|
|
2216
|
+
const timeA = activeBoardTime(a.time)
|
|
2217
|
+
const timeB = activeBoardTime(b.time)
|
|
2218
|
+
if (timeA != null && timeB != null && timeA !== timeB) return timeA - timeB
|
|
2219
|
+
return a.seq - b.seq
|
|
2220
|
+
})
|
|
2221
|
+
|
|
2222
|
+
const nodes = component.map(makeNode)
|
|
2223
|
+
if (groupEvents.some((event) => event.isUser)) {
|
|
2224
|
+
nodes.push({ id: '__user__', key: '__user__', name: 'User', isUser: true, activeStatus: 'user' })
|
|
2225
|
+
}
|
|
2226
|
+
const rawAdminId = roomIds.length === 1 ? roomById.get(roomIds[0])?.admin : null
|
|
2227
|
+
const roomAdminId = resolveBoardBotId(rawAdminId, botAliases)
|
|
2228
|
+
const coordId = roomAdminId && memberIds.has(roomAdminId)
|
|
2229
|
+
? roomAdminId
|
|
2230
|
+
: component.find((id) => waitLinks.some((link) => link.from === id)) || component[0]
|
|
2231
|
+
for (const node of nodes) node.coord = node.id === coordId
|
|
2232
|
+
|
|
2233
|
+
const messages = allEvents.map((event, index) => ({
|
|
2234
|
+
seq: index,
|
|
2235
|
+
sourceSeq: event.seq,
|
|
2236
|
+
who: event.name,
|
|
2237
|
+
botId: event.botId,
|
|
2238
|
+
text: event.text,
|
|
2239
|
+
to: event.synthetic ? event.to : mentionsOf(event.text, [...memberNames, 'User']),
|
|
2240
|
+
scope: groupId,
|
|
2241
|
+
scopeLabel: label,
|
|
2242
|
+
time: event.time,
|
|
2243
|
+
synthetic: event.synthetic === true,
|
|
2244
|
+
}))
|
|
2245
|
+
groups.push({ id: groupId, label, nodes, messages, coordId })
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
groups.sort((a, b) => a.label.localeCompare(b.label))
|
|
2249
|
+
const scopeOptions = groups.map((group) => ({ id: group.id, label: group.label }))
|
|
2250
|
+
const nodes = groups.flatMap((group) => group.nodes)
|
|
2251
|
+
const messages = groups.flatMap((group) => group.messages)
|
|
2252
|
+
const waitingCount = nodes.filter((node) => node.activeStatus === 'waiting').length
|
|
2253
|
+
return {
|
|
2254
|
+
groups, nodes, messages, scopeOptions, activeCount: active.size, waitingCount,
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
|
|
2259
|
+
// Starboard 外壳与数据接线。由 .build-client.cjs 内联进宿主模块工厂。
|
|
2260
|
+
// 这里不能用 import/export:整段会原样内联。
|
|
2261
|
+
|
|
2262
|
+
const mark = (text) => {
|
|
2263
|
+
try { window.localStorage.setItem('__dsbotBoardProbe', String(text)) } catch {}
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
const REQUEST_TIMEOUT_MS = 8000
|
|
2267
|
+
|
|
2268
|
+
async function askApi(endpoint, payload) {
|
|
2269
|
+
const controller = new AbortController()
|
|
2270
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS)
|
|
2271
|
+
try {
|
|
2272
|
+
const res = await fetch('/api/bot', {
|
|
2273
|
+
method: 'POST',
|
|
2274
|
+
credentials: 'same-origin',
|
|
2275
|
+
headers: { 'content-type': 'application/json' },
|
|
2276
|
+
body: JSON.stringify({ endpoint, payload: payload || {} }),
|
|
2277
|
+
signal: controller.signal,
|
|
2278
|
+
})
|
|
2279
|
+
const body = await res.json()
|
|
2280
|
+
if (!body || body.ok !== true) {
|
|
2281
|
+
const err = body && body.error ? body.error.code + ': ' + body.error.message : 'HTTP ' + res.status
|
|
2282
|
+
throw new Error(err)
|
|
2283
|
+
}
|
|
2284
|
+
return body.value || {}
|
|
2285
|
+
} catch (error) {
|
|
2286
|
+
if (error && error.name === 'AbortError') throw new Error('请求超时(' + REQUEST_TIMEOUT_MS / 1000 + 's)')
|
|
2287
|
+
throw error
|
|
2288
|
+
} finally {
|
|
2289
|
+
clearTimeout(timer)
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
let BoardView = null
|
|
2294
|
+
function ensureBoardView() {
|
|
2295
|
+
if (!BoardView) BoardView = createBoardView(React)
|
|
2296
|
+
return BoardView
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
function BrandMark({ size = 18 }) {
|
|
2300
|
+
return React.createElement('svg', {
|
|
2301
|
+
viewBox: '0 0 64 64', width: size, height: size,
|
|
2302
|
+
'aria-hidden': 'true', focusable: 'false', fill: 'none',
|
|
2303
|
+
stroke: 'currentColor', strokeWidth: 5.5, strokeLinecap: 'round',
|
|
2304
|
+
style: { display: 'block' },
|
|
2305
|
+
},
|
|
2306
|
+
React.createElement('path', { d: 'M32 17v13M32 30l-13 10M32 30l13 10' }),
|
|
2307
|
+
React.createElement('circle', { cx: 32, cy: 13, r: 7, fill: 'currentColor', stroke: 'none' }),
|
|
2308
|
+
React.createElement('circle', { cx: 18, cy: 50, r: 6, fill: 'currentColor', stroke: 'none' }),
|
|
2309
|
+
React.createElement('circle', { cx: 46, cy: 50, r: 6, fill: 'currentColor', stroke: 'none' }))
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
// 入口按钮与页签标题跟随宿主变量;面板样式全部来自 board-view.js 的 hiveStyleText()。
|
|
2313
|
+
function ensureBoardChromeStyle() {
|
|
2314
|
+
if (typeof document === 'undefined' || document.getElementById('dsbot-board-chrome-style')) return
|
|
2315
|
+
const style = document.createElement('style')
|
|
2316
|
+
style.id = 'dsbot-board-chrome-style'
|
|
2317
|
+
style.textContent = [
|
|
2318
|
+
hiveStyleText(),
|
|
2319
|
+
'.dsb-entry { background: transparent; color: var(--dsw-alias-text-secondary, rgba(20,20,20,.70)); transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .15s ease; }',
|
|
2320
|
+
'.dsb-entry:hover { background: var(--dsw-alias-surface-hover, rgba(119,119,119,.09)); color: var(--dsw-alias-text-primary, #141414); }',
|
|
2321
|
+
'.dsb-entry:active { transform: translateY(1px); }',
|
|
2322
|
+
'.dsb-entry:focus-visible { outline: 2px solid #4d6bfe; outline-offset: 2px; }',
|
|
2323
|
+
'html.dsbot-board-motion-off .dsb-entry { transition: none !important; }',
|
|
2324
|
+
'@media (prefers-reduced-motion: reduce) { .dsb-entry { transition: none !important; } }',
|
|
2325
|
+
].join('\n')
|
|
2326
|
+
document.head.appendChild(style)
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
async function askState(args) {
|
|
2330
|
+
try {
|
|
2331
|
+
return await askApi('state', args)
|
|
2332
|
+
} catch (error) {
|
|
2333
|
+
if (args && args.since != null) {
|
|
2334
|
+
mark('state since fallback')
|
|
2335
|
+
return askApi('state', {})
|
|
2336
|
+
}
|
|
2337
|
+
throw error
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
async function fetchActiveContext(activeRoomIds, privateBotIds, failed) {
|
|
2342
|
+
const pendingRooms = new Map()
|
|
2343
|
+
const pendingBots = new Map()
|
|
2344
|
+
const jobs = []
|
|
2345
|
+
|
|
2346
|
+
for (const roomId of activeRoomIds) {
|
|
2347
|
+
jobs.push(askApi('room-chat', { roomId }).then(
|
|
2348
|
+
(value) => { pendingRooms.set(roomId, listOf(value.items)) },
|
|
2349
|
+
() => { failed.add('room:' + roomId); mark('room-chat fail ' + roomId) },
|
|
2350
|
+
))
|
|
2351
|
+
}
|
|
2352
|
+
for (const botId of privateBotIds) {
|
|
2353
|
+
jobs.push(askApi('chat', { botId }).then(
|
|
2354
|
+
(value) => { pendingBots.set(botId, listOf(value.items)) },
|
|
2355
|
+
() => { failed.add('bot:' + botId); mark('chat fail ' + botId) },
|
|
2356
|
+
))
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
await Promise.all(jobs)
|
|
2360
|
+
return { pendingRooms, pendingBots }
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
// 活跃取数:state 轻查询带 work/activity;只有活跃空间才拉 room-chat / chat。
|
|
2364
|
+
function useGlobalBoard(active) {
|
|
2365
|
+
const [snap, setSnap] = React.useState({ phase: 'loading' })
|
|
2366
|
+
const revRef = React.useRef(null)
|
|
2367
|
+
const roomCache = React.useRef(new Map())
|
|
2368
|
+
const botCache = React.useRef(new Map())
|
|
2369
|
+
const baseCache = React.useRef({ bots: [], rooms: [] })
|
|
2370
|
+
const [tick, setTick] = React.useState(0)
|
|
2371
|
+
|
|
2372
|
+
React.useEffect(() => {
|
|
2373
|
+
if (!active) return undefined
|
|
2374
|
+
let alive = true
|
|
2375
|
+
let inFlight = false
|
|
2376
|
+
let seq = 0
|
|
2377
|
+
|
|
2378
|
+
const pull = async () => {
|
|
2379
|
+
if (inFlight) return
|
|
2380
|
+
inFlight = true
|
|
2381
|
+
const mySeq = ++seq
|
|
2382
|
+
const failed = new Set()
|
|
2383
|
+
|
|
2384
|
+
try {
|
|
2385
|
+
const args = {}
|
|
2386
|
+
if (revRef.current != null) args.since = revRef.current
|
|
2387
|
+
const state = await askState(args)
|
|
2388
|
+
if (!alive || mySeq !== seq) return
|
|
2389
|
+
|
|
2390
|
+
const base = boardBaseFromState(state, baseCache.current)
|
|
2391
|
+
const rooms = base.rooms
|
|
2392
|
+
const bots = base.bots
|
|
2393
|
+
const work = state.work || {}
|
|
2394
|
+
const activity = state.activity || {}
|
|
2395
|
+
const revision = state.revision
|
|
2396
|
+
if (state.unchanged !== true) baseCache.current = base
|
|
2397
|
+
const changed = state.unchanged !== true || revRef.current == null
|
|
2398
|
+
const activeRoomIds = activeRoomIdsOf(work)
|
|
2399
|
+
const botAliases = boardBotIdAliases(bots)
|
|
2400
|
+
const activeBotIds = activeBotIdsOf(work, activity)
|
|
2401
|
+
.map((botId) => resolveBoardBotId(botId, botAliases))
|
|
2402
|
+
.filter(Boolean)
|
|
2403
|
+
const privateBotIds = activeBotIds.filter((botId) => {
|
|
2404
|
+
const shortId = botId.replace(/^session-/, '')
|
|
2405
|
+
const info = (work.bots && work.bots[botId]) || (work.bots && work.bots[shortId])
|
|
2406
|
+
return !(info && info.roomId)
|
|
2407
|
+
})
|
|
2408
|
+
|
|
2409
|
+
if (!changed) {
|
|
2410
|
+
const missingRoomIds = activeRoomIds.filter((roomId) => !roomCache.current.has(roomId))
|
|
2411
|
+
const missingBotIds = privateBotIds.filter((botId) => !botCache.current.has(botId))
|
|
2412
|
+
if (missingRoomIds.length > 0 || missingBotIds.length > 0) {
|
|
2413
|
+
const loaded = await fetchActiveContext(
|
|
2414
|
+
missingRoomIds,
|
|
2415
|
+
missingBotIds,
|
|
2416
|
+
failed,
|
|
2417
|
+
)
|
|
2418
|
+
if (!alive || mySeq !== seq) return
|
|
2419
|
+
for (const [id, rows] of loaded.pendingRooms) roomCache.current.set(id, rows)
|
|
2420
|
+
for (const [id, rows] of loaded.pendingBots) botCache.current.set(id, rows)
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
const roomItems = Object.fromEntries(roomCache.current)
|
|
2424
|
+
const botItems = Object.fromEntries(botCache.current)
|
|
2425
|
+
const board = buildActiveBoard({ bots, rooms, roomItems, botItems, work, activity })
|
|
2426
|
+
setSnap((prev) => (prev.phase === 'ok'
|
|
2427
|
+
? { ...prev, board, work, activity, lastChecked: Date.now(), failed: failed.size, error: failed.size > 0 ? prev.error : undefined }
|
|
2428
|
+
: prev))
|
|
2429
|
+
mark('active unchanged rev=' + revision + ' groups=' + board.groups.length + ' nodes=' + board.nodes.length + ' failed=' + failed.size)
|
|
2430
|
+
return
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
const loaded = await fetchActiveContext(
|
|
2434
|
+
activeRoomIds,
|
|
2435
|
+
privateBotIds,
|
|
2436
|
+
failed,
|
|
2437
|
+
)
|
|
2438
|
+
if (!alive || mySeq !== seq) return
|
|
2439
|
+
|
|
2440
|
+
for (const [id, rows] of loaded.pendingRooms) roomCache.current.set(id, rows)
|
|
2441
|
+
for (const [id, rows] of loaded.pendingBots) botCache.current.set(id, rows)
|
|
2442
|
+
|
|
2443
|
+
const roomItems = Object.fromEntries(roomCache.current)
|
|
2444
|
+
const botItems = Object.fromEntries(botCache.current)
|
|
2445
|
+
const board = buildActiveBoard({ bots, rooms, roomItems, botItems, work, activity })
|
|
2446
|
+
|
|
2447
|
+
setSnap({
|
|
2448
|
+
phase: 'ok',
|
|
2449
|
+
rooms,
|
|
2450
|
+
bots,
|
|
2451
|
+
revision,
|
|
2452
|
+
board,
|
|
2453
|
+
work,
|
|
2454
|
+
activity,
|
|
2455
|
+
failed: failed.size,
|
|
2456
|
+
lastUpdated: Date.now(),
|
|
2457
|
+
})
|
|
2458
|
+
if (failed.size === 0) revRef.current = revision
|
|
2459
|
+
mark('active ok rooms=' + activeRoomIds.length + ' bots=' + activeBotIds.length +
|
|
2460
|
+
' groups=' + board.groups.length + ' nodes=' + board.nodes.length +
|
|
2461
|
+
' rev=' + revision + ' failed=' + failed.size)
|
|
2462
|
+
} catch (error) {
|
|
2463
|
+
if (!alive || mySeq !== seq) return
|
|
2464
|
+
const message = String(error && error.message ? error.message : error)
|
|
2465
|
+
setSnap((prev) => {
|
|
2466
|
+
if (prev.phase === 'ok') return { ...prev, failed: (prev.failed || 0) + 1, error: message }
|
|
2467
|
+
return { phase: 'error', message }
|
|
2468
|
+
})
|
|
2469
|
+
mark('active error ' + message)
|
|
2470
|
+
} finally {
|
|
2471
|
+
if (mySeq === seq) inFlight = false
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
pull()
|
|
2476
|
+
const timer = setInterval(pull, 6000)
|
|
2477
|
+
return () => { alive = false; clearInterval(timer) }
|
|
2478
|
+
}, [active, tick])
|
|
2479
|
+
|
|
2480
|
+
return [snap, () => setTick((value) => value + 1)]
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
const KIND = 'dsbot-starboard:main'
|
|
2484
|
+
const THEME_KEY = '__dsbotBoardTheme'
|
|
2485
|
+
const MOTION_KEY = '__dsbotBoardMotion'
|
|
2486
|
+
const SCOPE_KEY = '__dsbotBoardScope'
|
|
2487
|
+
|
|
2488
|
+
const themeUi = { name: 'dark', manual: false }
|
|
2489
|
+
const themeListeners = new Set()
|
|
2490
|
+
|
|
2491
|
+
function hostTheme() {
|
|
2492
|
+
try {
|
|
2493
|
+
const root = document.documentElement
|
|
2494
|
+
const attr = (root.getAttribute('data-theme') || root.getAttribute('data-dsw-theme') || '').toLowerCase()
|
|
2495
|
+
if (attr === 'light' || attr === 'dark') return attr
|
|
2496
|
+
if (root.classList.contains('dark') || root.classList.contains('dsw-dark')) return 'dark'
|
|
2497
|
+
if (root.classList.contains('light') || root.classList.contains('dsw-light')) return 'light'
|
|
2498
|
+
if (document.body && document.body.hasAttribute('data-ds-dark-theme')) return 'dark'
|
|
2499
|
+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) return 'light'
|
|
2500
|
+
} catch (error) { /* 读不到就按深色 */ }
|
|
2501
|
+
return 'dark'
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
function readTheme() {
|
|
2505
|
+
try {
|
|
2506
|
+
const saved = window.localStorage.getItem(THEME_KEY)
|
|
2507
|
+
if (saved === 'light' || saved === 'dark') return { name: saved, manual: true }
|
|
2508
|
+
} catch (error) { /* 忽略存储失败 */ }
|
|
2509
|
+
return { name: hostTheme(), manual: false }
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
function setBoardTheme(next, persist = true) {
|
|
2513
|
+
themeUi.name = next
|
|
2514
|
+
themeUi.manual = persist
|
|
2515
|
+
if (persist) {
|
|
2516
|
+
try { window.localStorage.setItem(THEME_KEY, next) } catch (error) { /* 忽略存储失败 */ }
|
|
2517
|
+
}
|
|
2518
|
+
for (const listener of themeListeners) {
|
|
2519
|
+
try { listener(next) } catch (error) { /* 忽略单个订阅者 */ }
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
const initialTheme = readTheme()
|
|
2524
|
+
themeUi.name = initialTheme.name
|
|
2525
|
+
themeUi.manual = initialTheme.manual
|
|
2526
|
+
|
|
2527
|
+
function useBoardTheme() {
|
|
2528
|
+
const [themeName, setThemeName] = React.useState(themeUi.name)
|
|
2529
|
+
React.useEffect(() => {
|
|
2530
|
+
const listener = (value) => setThemeName(value)
|
|
2531
|
+
themeListeners.add(listener)
|
|
2532
|
+
setThemeName(themeUi.name)
|
|
2533
|
+
|
|
2534
|
+
const media = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null
|
|
2535
|
+
const followHost = () => {
|
|
2536
|
+
let saved = null
|
|
2537
|
+
try { saved = window.localStorage.getItem(THEME_KEY) } catch (error) { /* 忽略 */ }
|
|
2538
|
+
if (saved === 'light' || saved === 'dark') return
|
|
2539
|
+
setBoardTheme(hostTheme(), false)
|
|
2540
|
+
}
|
|
2541
|
+
const observer = typeof MutationObserver !== 'undefined'
|
|
2542
|
+
? new MutationObserver(followHost)
|
|
2543
|
+
: null
|
|
2544
|
+
if (observer) {
|
|
2545
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'data-theme', 'data-dsw-theme'] })
|
|
2546
|
+
if (document.body) observer.observe(document.body, { attributes: true, attributeFilter: ['class', 'data-theme', 'data-ds-dark-theme'] })
|
|
2547
|
+
}
|
|
2548
|
+
if (media && media.addEventListener) media.addEventListener('change', followHost)
|
|
2549
|
+
|
|
2550
|
+
return () => {
|
|
2551
|
+
themeListeners.delete(listener)
|
|
2552
|
+
if (observer) observer.disconnect()
|
|
2553
|
+
if (media && media.removeEventListener) media.removeEventListener('change', followHost)
|
|
2554
|
+
}
|
|
2555
|
+
}, [])
|
|
2556
|
+
const toggle = React.useCallback(() => {
|
|
2557
|
+
setBoardTheme(themeUi.name === 'dark' ? 'light' : 'dark')
|
|
2558
|
+
}, [])
|
|
2559
|
+
return [themeName, toggle, themeUi.manual]
|
|
2560
|
+
}
|
|
2561
|
+
|
|
2562
|
+
function useBoardMotion() {
|
|
2563
|
+
const [motionOn, setMotionOn] = React.useState(() => {
|
|
2564
|
+
try { return window.localStorage.getItem(MOTION_KEY) !== 'off' } catch (error) { return true }
|
|
2565
|
+
})
|
|
2566
|
+
const toggle = React.useCallback(() => {
|
|
2567
|
+
setMotionOn((prev) => {
|
|
2568
|
+
const next = !prev
|
|
2569
|
+
try { window.localStorage.setItem(MOTION_KEY, next ? 'on' : 'off') } catch (error) { /* 忽略 */ }
|
|
2570
|
+
return next
|
|
2571
|
+
})
|
|
2572
|
+
}, [])
|
|
2573
|
+
return [motionOn, toggle]
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
function readScope() {
|
|
2577
|
+
try { return window.localStorage.getItem(SCOPE_KEY) || 'all' } catch (error) { return 'all' }
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
// 薄壳:只负责取数、主题/动效/筛选状态与宿主接线,视觉全部交给 BoardView。
|
|
2581
|
+
function BoardBody({ active, themeName, onToggleTheme, themeVars, onOpenSession }) {
|
|
2582
|
+
const [snap, refresh] = useGlobalBoard(active)
|
|
2583
|
+
const [motionOn, toggleMotion] = useBoardMotion()
|
|
2584
|
+
const [scope, setScope] = React.useState(readScope)
|
|
2585
|
+
|
|
2586
|
+
React.useEffect(() => {
|
|
2587
|
+
document.documentElement.classList.toggle('dsbot-board-motion-off', !motionOn)
|
|
2588
|
+
return () => { document.documentElement.classList.remove('dsbot-board-motion-off') }
|
|
2589
|
+
}, [motionOn])
|
|
2590
|
+
|
|
2591
|
+
React.useEffect(() => {
|
|
2592
|
+
if (scope === 'all') return
|
|
2593
|
+
if (snap.phase === 'ok' && !snap.board.scopeOptions.some((item) => item.id === scope)) {
|
|
2594
|
+
setScope('all')
|
|
2595
|
+
try { window.localStorage.setItem(SCOPE_KEY, 'all') } catch (error) { /* 忽略 */ }
|
|
2596
|
+
}
|
|
2597
|
+
}, [scope, snap])
|
|
2598
|
+
|
|
2599
|
+
const selectScope = (next) => {
|
|
2600
|
+
setScope(next)
|
|
2601
|
+
try { window.localStorage.setItem(SCOPE_KEY, next) } catch (error) { /* 忽略 */ }
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
return React.createElement(BoardView, {
|
|
2605
|
+
phase: snap.phase,
|
|
2606
|
+
message: snap.message,
|
|
2607
|
+
board: snap.board,
|
|
2608
|
+
bots: snap.bots,
|
|
2609
|
+
failed: snap.failed || 0,
|
|
2610
|
+
lastChecked: snap.lastChecked,
|
|
2611
|
+
lastUpdated: snap.lastUpdated,
|
|
2612
|
+
themeName,
|
|
2613
|
+
themeVars,
|
|
2614
|
+
onToggleTheme,
|
|
2615
|
+
motionOn,
|
|
2616
|
+
onToggleMotion: toggleMotion,
|
|
2617
|
+
scope,
|
|
2618
|
+
onSelectScope: selectScope,
|
|
2619
|
+
onRetry: refresh,
|
|
2620
|
+
onOpenSession: onOpenSession || openBotSession,
|
|
2621
|
+
})
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
function NativeTabBody(props) {
|
|
2625
|
+
const [themeName, toggleTheme] = useBoardTheme()
|
|
2626
|
+
const visible = props && typeof props.visible === 'boolean' ? props.visible : true
|
|
2627
|
+
return React.createElement(BoardBody, { active: visible, themeName, onToggleTheme: toggleTheme })
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2630
|
+
function NativeTabTitle(props) {
|
|
2631
|
+
const visible = props && typeof props.visible === 'boolean' ? props.visible : true
|
|
2632
|
+
return React.createElement('div', {
|
|
2633
|
+
'data-dsbot-board-title': '',
|
|
2634
|
+
style: {
|
|
2635
|
+
display: 'flex', alignItems: 'center', gap: 6, height: '100%',
|
|
2636
|
+
padding: '0 4px', fontSize: 11,
|
|
2637
|
+
color: 'var(--dsw-alias-text-primary, #141414)', opacity: visible ? 1 : 0.6,
|
|
2638
|
+
},
|
|
2639
|
+
},
|
|
2640
|
+
React.createElement('span', { style: { display: 'inline-flex', color: 'var(--dsw-alias-text-secondary, rgba(20,20,20,.70))' } },
|
|
2641
|
+
React.createElement(BrandMark, { size: 13 })),
|
|
2642
|
+
React.createElement('span', { style: { fontWeight: 600 } }, 'Starboard'))
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
function makeEntry() {
|
|
2646
|
+
return function BoardEntry() {
|
|
2647
|
+
return React.createElement('button', {
|
|
2648
|
+
type: 'button',
|
|
2649
|
+
title: '打开Starboard',
|
|
2650
|
+
'aria-label': 'Starboard',
|
|
2651
|
+
'data-dsbot-board-entry': '1',
|
|
2652
|
+
onClick: () => {
|
|
2653
|
+
try {
|
|
2654
|
+
const service = window.__dsbotBoard__ || null
|
|
2655
|
+
if (service && typeof service.open === 'function') {
|
|
2656
|
+
service.open()
|
|
2657
|
+
mark('entry:clicked')
|
|
2658
|
+
} else {
|
|
2659
|
+
mark('entry:no-service')
|
|
2660
|
+
}
|
|
2661
|
+
} catch (error) {
|
|
2662
|
+
mark('entry:fail ' + String(error && error.message ? error.message : error))
|
|
2663
|
+
}
|
|
2664
|
+
},
|
|
2665
|
+
className: 'dsb-entry',
|
|
2666
|
+
style: {
|
|
2667
|
+
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
2668
|
+
width: 28, height: 28, padding: 0, borderRadius: 9,
|
|
2669
|
+
border: '1px solid transparent', cursor: 'pointer', flex: '0 0 auto',
|
|
2670
|
+
},
|
|
2671
|
+
}, React.createElement(BrandMark, { size: 16 }))
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
function makeOpener() {
|
|
2676
|
+
return {
|
|
2677
|
+
open() {
|
|
2678
|
+
const right = opener.right
|
|
2679
|
+
if (!right) { mark('open:no-right'); return false }
|
|
2680
|
+
try {
|
|
2681
|
+
if (typeof right.openTab === 'function') { right.openTab(KIND); return true }
|
|
2682
|
+
} catch (error) {
|
|
2683
|
+
mark('open:openTab-fail ' + String(error && error.message ? error.message : error))
|
|
2684
|
+
}
|
|
2685
|
+
try {
|
|
2686
|
+
if (typeof right.focus === 'function') { right.focus(KIND); return true }
|
|
2687
|
+
} catch (error) {
|
|
2688
|
+
mark('open:focus-fail ' + String(error && error.message ? error.message : error))
|
|
2689
|
+
}
|
|
2690
|
+
return false
|
|
2691
|
+
},
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
const opener = makeOpener()
|
|
2696
|
+
const BoardEntry = makeEntry()
|
|
2697
|
+
let openBotSession = (detail) => { mark('open-session pending ' + JSON.stringify(detail || {})) }
|
|
2698
|
+
|
|
2699
|
+
const boardPlugin = {
|
|
2700
|
+
inject: ['slots'],
|
|
2701
|
+
apply(ctx) {
|
|
2702
|
+
mark('apply')
|
|
2703
|
+
ensureBoardChromeStyle()
|
|
2704
|
+
ensureBoardView()
|
|
2705
|
+
|
|
2706
|
+
const workspace = (() => {
|
|
2707
|
+
try { return ctx.get('uiWorkspace') } catch (error) { return undefined }
|
|
2708
|
+
})()
|
|
2709
|
+
openBotSession = (detail) => {
|
|
2710
|
+
const info = detail || {}
|
|
2711
|
+
const botId = info.botId || info.key || ''
|
|
2712
|
+
try {
|
|
2713
|
+
if (workspace && typeof workspace.openSession === 'function') {
|
|
2714
|
+
workspace.openSession(botId)
|
|
2715
|
+
mark('open-session ok ' + botId)
|
|
2716
|
+
return
|
|
2717
|
+
}
|
|
2718
|
+
} catch (error) {
|
|
2719
|
+
mark('open-session fail ' + String(error && error.message ? error.message : error))
|
|
2720
|
+
}
|
|
2721
|
+
mark('open-session unavailable ' + botId)
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
for (const slot of ['conversation.session.header.utilities', 'conversation.input.right']) {
|
|
2725
|
+
try {
|
|
2726
|
+
ctx.slots.inject(slot, () => ctx.slots.register({
|
|
2727
|
+
name: slot, id: 'dsbot-board:entry', order: 30,
|
|
2728
|
+
registrant: 'dsbot-starboard', inject: () => ({}),
|
|
2729
|
+
}, BoardEntry))
|
|
2730
|
+
} catch (error) {
|
|
2731
|
+
mark('apply:entry-fail ' + slot + ' ' + String(error && error.message ? error.message : error))
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
mark('apply:entry')
|
|
2735
|
+
|
|
2736
|
+
try {
|
|
2737
|
+
ctx.inject(['sidebarRightTabs', 'sidebarRight'], (injected) => {
|
|
2738
|
+
const tabs = injected.get('sidebarRightTabs')
|
|
2739
|
+
const right = injected.get('sidebarRight')
|
|
2740
|
+
opener.right = right
|
|
2741
|
+
window.__dsbotBoard__ = opener
|
|
2742
|
+
if (!tabs || typeof tabs.register !== 'function') {
|
|
2743
|
+
mark('apply:tabs-unavailable')
|
|
2744
|
+
return
|
|
2745
|
+
}
|
|
2746
|
+
|
|
2747
|
+
const disposers = []
|
|
2748
|
+
try {
|
|
2749
|
+
disposers.push(tabs.register({
|
|
2750
|
+
id: KIND,
|
|
2751
|
+
kind: KIND,
|
|
2752
|
+
keepMounted: true,
|
|
2753
|
+
priority: 'extension',
|
|
2754
|
+
title: () => 'Starboard',
|
|
2755
|
+
guide: [{
|
|
2756
|
+
id: KIND,
|
|
2757
|
+
order: 45,
|
|
2758
|
+
title: () => 'Starboard',
|
|
2759
|
+
description: () => '全局查看谁派活给谁、谁在等回执,以及当前消息走到哪',
|
|
2760
|
+
icon: (props) => BrandMark({ size: props && props.size ? props.size : 16 }),
|
|
2761
|
+
}],
|
|
2762
|
+
}))
|
|
2763
|
+
disposers.push(ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
|
|
2764
|
+
name: 'sidebar.right.pane.tab', key: KIND, inject: (sessionId) => ({ sessionId }),
|
|
2765
|
+
}, NativeTabBody)))
|
|
2766
|
+
disposers.push(ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
|
|
2767
|
+
name: 'sidebar.right.pane.tab.title', key: KIND, inject: (sessionId) => ({ sessionId }),
|
|
2768
|
+
}, NativeTabTitle)))
|
|
2769
|
+
mark('apply:native-tab-ok')
|
|
2770
|
+
} catch (error) {
|
|
2771
|
+
mark('apply:native-tab-fail ' + String(error && error.message ? error.message : error))
|
|
2772
|
+
for (const dispose of disposers) { try { dispose() } catch (e) { /* 忽略清理失败 */ } }
|
|
2773
|
+
return
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
try {
|
|
2777
|
+
if (window.localStorage.getItem('__dsbotBoardNativeOpened:v4') !== '1') {
|
|
2778
|
+
window.localStorage.setItem('__dsbotBoardNativeOpened:v4', '1')
|
|
2779
|
+
opener.open()
|
|
2780
|
+
mark('apply:native-open-ok')
|
|
2781
|
+
}
|
|
2782
|
+
} catch (error) {
|
|
2783
|
+
mark('apply:native-open-fail ' + String(error && error.message ? error.message : error))
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
return () => {
|
|
2787
|
+
opener.right = null
|
|
2788
|
+
for (const dispose of disposers) { try { dispose() } catch (e) { /* 忽略清理失败 */ } }
|
|
2789
|
+
}
|
|
2790
|
+
})
|
|
2791
|
+
} catch (error) {
|
|
2792
|
+
mark('apply:native-inject-fail ' + String(error && error.message ? error.message : error))
|
|
2793
|
+
}
|
|
2794
|
+
},
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
|
|
2798
|
+
return boardPlugin
|
|
2799
|
+
},
|
|
2800
|
+
})
|