@capyclaw/caption-map 0.0.0-stage → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +321 -2
  2. package/client/client.chat.js +441 -0
  3. package/client/client.js +1519 -0
  4. package/cordis.patch.yml +14 -0
  5. package/index.js +47 -0
  6. package/node_modules/@capyclaw/foundation/README.md +51 -0
  7. package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
  8. package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
  9. package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
  10. package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
  11. package/node_modules/@capyclaw/foundation/abi/loader.mjs +352 -0
  12. package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
  13. package/node_modules/@capyclaw/foundation/abi/spec.mjs +258 -0
  14. package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
  15. package/node_modules/@capyclaw/foundation/abi/version.mjs +140 -0
  16. package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
  17. package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
  18. package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
  19. package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
  20. package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
  21. package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
  22. package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
  23. package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
  24. package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
  25. package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
  26. package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
  27. package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
  28. package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
  29. package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
  30. package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
  31. package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
  32. package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
  33. package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +187 -0
  34. package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
  35. package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
  36. package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
  37. package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
  38. package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
  39. package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +198 -0
  40. package/node_modules/@capyclaw/foundation/package.json +53 -0
  41. package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
  42. package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
  43. package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
  44. package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
  45. package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
  46. package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
  47. package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
  48. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
  49. package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +60 -0
  50. package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
  51. package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
  52. package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
  53. package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
  54. package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
  55. package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
  56. package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
  57. package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
  58. package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
  59. package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
  60. package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
  61. package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
  62. package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
  63. package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
  64. package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
  65. package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
  66. package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
  67. package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
  68. package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
  69. package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
  70. package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
  71. package/node_modules/@capyclaw/window-kit/README.md +91 -0
  72. package/node_modules/@capyclaw/window-kit/client/client.js +531 -0
  73. package/node_modules/@capyclaw/window-kit/cordis.patch.yml +9 -0
  74. package/node_modules/@capyclaw/window-kit/icon.svg +8 -0
  75. package/node_modules/@capyclaw/window-kit/index.js +11 -0
  76. package/node_modules/@capyclaw/window-kit/package.json +62 -0
  77. package/options.mjs +27 -0
  78. package/package.json +67 -4
@@ -0,0 +1,1519 @@
1
+ /**
2
+ * @capyclaw/caption-map · 浏览器半
3
+ *
4
+ * 区域映射:把「底部入口行」「侧栏面板列表」「工作区列表」搬进 Windows 标题栏行。
5
+ * 1. 底部入口行(更多/设置 launcher + 手机/电脑远程等 footer 席位)→ 标题栏,
6
+ * 排「应用/编辑」菜单右侧;
7
+ * 2. 侧栏面板列表(插件 / 离线 ddr0 / 自动化任务 / 更多 …)→ 收进标题栏一枚
8
+ * 「其他」分组按钮,点开是这些面板的一行行选项;
9
+ * 3. 工作区列表(sidebar.workspaces 席位,WorkspaceBrowser)→ 收进「其他」右侧
10
+ * 一枚「工作区」收藏夹按钮,点开是独立浮窗:原生组头/会话行/搜索/添加原样
11
+ * 可用,点会话行打开会话并收起(浏览器书签行为)。
12
+ *
13
+ * 本包另一件事:侧栏底部的**聊天窗停靠**(`client/client.chat.js`,包内分块、按需加载)——
14
+ * 把会话面板(「标题 + 页签 + 正文 + 输入框」那一整块)搬进侧栏列底部的槽里。它是真·DOM
15
+ * 搬迁(输入框、菜单层叠要求同层),和上面的纯 CSS 映射是两条独立路径、两套门控:
16
+ * 映射只在 Windows 标题栏下生效,聊天窗停靠跨平台常驻。聊天窗停靠走 @capyclaw/window-kit
17
+ * 的页面账本;区域映射不依赖 window-kit(window-kit 被禁用时映射仍要工作)。停用插件即还原。
18
+ *
19
+ * 为什么是几何映射而不是插槽镜像:
20
+ * - 顶栏那一行不是 web 插槽。侧栏开关由 ui-sidebar 固定到标题栏左上
21
+ * (html[data-windows-titlebar]),「应用/编辑」菜单栏是 preload 直接注入
22
+ * document 的 fixed menubar(host 带 data-windows-menu 属性,见安装版
23
+ * lib/preload-app.cjs installWindowsMenu)。catalog 里没有任何落在标题栏行
24
+ * 的可注入席位(shell.leading 只在 drawer/darwin 折叠态挂载)。
25
+ * - 底部入口行 = ui-sidebar 的 foot:settings.launcher(更多/账户入口)与
26
+ * sidebar.footer.action 席位(手机/电脑远程等注册项)的公共容器行。
27
+ * - 面板列表 = SidebarRoot 的 nav.panelList,行来自 usePanels(各插件用
28
+ * ctx.slots.register({name:'sidebar.panellist'}) 注册),「更多」是
29
+ * PanelMoreMenu(sidebar.panellist.actions 席位)。它是侧栏内的普通流内块,
30
+ * 所以整块 position:fixed 到标题栏下方即成下拉,行本身仍是 React 节点。
31
+ * - 新会话按钮:展开态整格收起(侧栏整条「+ 新会话」不再占位,顶栏也不放
32
+ * ⊕——鲸鱼兼作新会话入口,用户选定);折叠态交给外壳自己钉⊕到 left:48px,
33
+ * 不插手。纯 CSS、卸载还原。
34
+ * - 品牌行(logoRow,deepseek HARNESS):标题栏模式下整行 height:0 收起
35
+ * (不能 display:none——Windows 的侧栏开关渲染在 logoRow 里,fixed 子级
36
+ * 需要行留在 DOM)。展开态鲸鱼图标钉顶栏 left:12px、只留图标;侧栏开关
37
+ * 让位到 48px、菜单栏起点 84px,左起两枚 12/48。折叠态交外壳原布局
38
+ * (开关 12 / 新会话 48,鲸鱼随行收起);drawer 不插手。门控与 active()
39
+ * 同条件,纯 web 不受影响。
40
+ *
41
+ * 做法(满足「不改占用方代码 + 未来注册自动跟随」):
42
+ * 1. 运行时按 data-slot / class 前缀找到席位 host、行、面板列表;
43
+ * 2. 只改 CSS(position:fixed 进标题栏行),不移动 DOM 节点——React 仍拥有
44
+ * 这些节点,卸载/重挂载不受影响;席位里未来新增的注册项渲染在同一容器
45
+ * 内,自动一起上顶栏/进「其他」;
46
+ * 3. 原位置因节点脱离文档流而自然收起,另把原父容器的 padding/边框收掉;
47
+ * 4. 左偏移运行时量 menubar 右缘,侧栏折叠(--dsh-windows-menu-start 变化)、
48
+ * 窗口 resize、语言切换(menubar 宽度变化)都会重算;
49
+ * 5. 仅 html[data-windows-titlebar] 且 menubar 在场时生效;纯 web / macOS
50
+ * 自动 no-op。禁用插件即还原全部内联样式并移除自己注入的按钮。
51
+ *
52
+ * 「其他」分组:顶栏没有可注入的插槽,所以触发按钮由本插件注入(document.body
53
+ * 下的 fixed 按钮),点开时把 nav.panelList 的显隐交给 html[data-capyclaw-others-
54
+ * open] 一条 CSS;行仍是原来的 React 按钮,点一下走原来的 selectPanel,
55
+ * active 高亮、更多菜单、未来新注册的面板全部自动生效。
56
+ *
57
+ * 「工作区」收藏夹:同一套注入按钮 + html[data-capyclaw-workspaces-open] 显隐
58
+ * 机制,把 WorkspaceBrowser 根(div:has(> [data-sidebar-workspace-header]))
59
+ * fixed 成独立浮窗。根用独立标记 data-capyclaw-workspaces-map——通用 [MARK]>*
60
+ * 横排规则会毁掉它的纵向布局。折叠/drawer 态列表内容卸载,整块交还原生 rail。
61
+ *
62
+ * 护栏:公共祖先若大到装进了会话列表/面板列表/输入框(说明两席位不在同一行),
63
+ * 放弃整行映射,退化为逐席位映射(手机/电脑仍上顶栏),绝不把整条侧栏搬走。
64
+ * drawer(侧栏当浮层)时面板列表留在抽屉里,不搬。
65
+ *
66
+ * ── 内部结构(方便拓展)─────────────────────────────────────────────
67
+ * 区域映射这条 effect 内部按「共享底座 + 特性模块 + 编排器」组织:
68
+ * · 共享底座 kit:门控谓词、样式账本 makeLedger、原父级收零 markSrc/releaseSrc、
69
+ * 容器隔离兜底 escapeContainment、左夹取 clampLeft、触发按钮工厂、下拉开合
70
+ * 状态 makeOpenState(自带互斥注册表)、样式表 styleTag。重复实现只此一份。
71
+ * · 特性模块:brand / newSession / seats / others / workspaces,各自持有自己的
72
+ * 样式账本与注入按钮,暴露 pass(…)(本轮摆好)与 yield()(让位还原)。彼此
73
+ * 不共享映射表,编排器不再需要「跳过哪些选择器」的耦合清单。
74
+ * · 编排器 pass():只算一次几何(capH/cursor),按序调各特性;让位时统一 yieldAll。
75
+ * · 点空白/Esc 收起:按特性注册的策略分发(dropdownFeatures),加新下拉不用改
76
+ * 一个巨大的 onClick。
77
+ * 新增一个「搬进标题栏」的特性:写一个 makeXxxFeature()(自己的账本 + pass/yield),
78
+ * 在编排器里调它的 pass,在 yieldAll 里调它的 yield;若是下拉,再注册开合状态与
79
+ * 点击/Esc 策略即可。新增底部席位:往 SEATS 加一行。
80
+ *
81
+ * 装载协议与 DSH 其它客户端插件一致:window.__ModuleLoader__.load({ id, factory })。
82
+ */
83
+ window.__ModuleLoader__.load({
84
+ id: '@capyclaw/caption-map',
85
+ factory: function (require) {
86
+ var PACKAGE_ID = '@capyclaw/caption-map'
87
+ var MARK = 'data-capyclaw-caption-map'
88
+ var SRC_MARK = 'data-capyclaw-caption-map-src'
89
+ /** 底部区域的席位清单(顺序即顶栏排布顺序)。新增底部席位时往这里加一行。 */
90
+ var SEATS = ['settings.launcher', 'sidebar.footer.action']
91
+ var GAP = 6
92
+ /** 标题栏右侧原生 min/max/close 按钮预留宽度。 */
93
+ var CAPTION_RIGHT_RESERVE = 150
94
+ /** foot 竖排堆叠的高度上限;超过说明公共祖先取大了。 */
95
+ var ROW_MAX_HEIGHT = 240
96
+ /** 新会话整条按钮:CSS module 哈希前缀随版本变,后缀稳定;row/content 等不是 button,不会误中。 */
97
+ var NS_BTN = 'button[class*="newSession"]'
98
+ /** 品牌元素(鲸鱼图标载体,button 或 span):logoRow 的直接子级。 */
99
+ var BRAND_SEL = '[class*="logoRow"] > [class*="brand"]'
100
+ /** 展开态顶栏左起两枚:鲸鱼 12 / 侧栏开关 48(各 28px,菜单栏 84 起);
101
+ 新会话整条按钮展开态整格收起(鲸鱼兼作新会话入口)。
102
+ 折叠态不插手:外壳原布局 开关 12 / 新会话 48,鲸鱼随 logoRow 收起。 */
103
+ var BRAND_LEFT = 12
104
+ var TOGGLE_LEFT = 48
105
+ /** 面板列表:nav.panelList(module 哈希前缀,后缀稳定)。 */
106
+ var NAV_SEL = 'nav[class*="panelList"]'
107
+ /** 「其他」分组:注入的触发按钮 id / 展开态属性 / 文案 / 下拉宽度。 */
108
+ var TRIGGER_ID = 'capyclaw-others-trigger'
109
+ var TRIGGER_MARK = 'data-capyclaw-others-trigger'
110
+ var OPEN_ATTR = 'data-capyclaw-others-open'
111
+ var OTHERS_LABEL = '其他'
112
+ var NAV_WIDTH = 224
113
+ var CHEVRON = '<svg width="12" height="12" viewBox="0 0 12 12" aria-hidden="true">'
114
+ + '<path d="M3 4.5 6 7.5 9 4.5" fill="none" stroke="currentColor" stroke-width="1.3"'
115
+ + ' stroke-linecap="round" stroke-linejoin="round"/></svg>'
116
+ /** 预留栏位:「其他」右侧一枚占位场(内容待定,现为虚线占位盒)。 */
117
+ var EXTRA_SLOT_ID = 'capyclaw-extra-slot'
118
+ var EXTRA_SLOT_MARK = 'data-capyclaw-extra-slot'
119
+ var EXTRA_SLOT_MOUNT_MARK = 'data-capyclaw-extra-slot-mount'
120
+ var EXTRA_SLOT_LABEL = '预留栏位'
121
+ /** 工作区收藏夹:sidebar.workspaces 区域(WorkspaceBrowser 根)收成顶栏下拉。
122
+ 根节点没有稳定属性,用「header 的直接父级」定位;header/listArea 有稳定 data 属性。
123
+ 独立标记(不复用 MARK):通用 '[MARK] > *' 横排规则会毁掉根的纵向布局。
124
+ 每个工作区分组一枚文件夹按钮(组头 data-row-key="workspace:…"),点开只显该组会话。 */
125
+ var WS_ROOT_SEL = 'div:has(> [data-sidebar-workspace-header])'
126
+ var WS_MARK = 'data-capyclaw-workspaces-map'
127
+ var WS_TRIGGER_MARK = 'data-capyclaw-workspaces-trigger'
128
+ var WS_BTN_PREFIX = 'capyclaw-ws-trigger-'
129
+ var WS_FILTER_ID = 'capyclaw-ws-filter'
130
+ var WS_OPEN_ATTR = 'data-capyclaw-workspaces-open'
131
+ var WS_WIDTH = 360
132
+ /** 第二行:文件夹按钮独占一行;frame 的 padding-top 加一行高,把下方画面整体挤下去 */
133
+ var WS_ROW_H = 36
134
+ var WS_ROW_ATTR = 'data-capyclaw-ws-row'
135
+ var WS_ROW_LEFT = 12
136
+ var FOLDER_ICON = '<svg width="12" height="12" viewBox="0 0 12 12" aria-hidden="true">'
137
+ + '<path d="M1.5 3.2c0-.4.3-.7.7-.7h2.6l1 1.2h4c.4 0 .7.3.7.7v4.4c0 .4-.3.7-.7.7H2.2c-.4 0-.7-.3-.7-.7V3.2z"'
138
+ + ' fill="none" stroke="currentColor" stroke-width="1.1" stroke-linejoin="round"/></svg>'
139
+
140
+ /** 「更多」收拢(展开态):把鲸鱼 / 侧栏开关 / 应用·编辑菜单栏 / 底部入口行
141
+ (Maple 账户 + 手机/电脑)/ 面板列表整簇收进标题栏左起一枚「更多」按钮,
142
+ 点开是一枚统一浮窗,自上而下:新会话 / 折叠侧栏 / 应用·编辑 / 账户·设备 /
143
+ 面板列表。原生菜单栏 host 与底部入口行整块 fixed 进浮窗(弹出菜单按可见
144
+ 位置量锚点,行为不变);新会话/折叠侧栏是注入行,程序点真按钮。
145
+ 折叠/drawer 态交还原布局(more 让位,brand/seats/others 照旧)。
146
+ 独立标记(不复用 MARK):通用 [MARK] 横排/显隐规则会干扰浮窗纵向布局。 */
147
+ var MORE_TRIGGER_ID = 'capyclaw-more-trigger'
148
+ var MORE_OPEN_ATTR = 'data-capyclaw-more-open'
149
+ var MORE_LABEL = '更多'
150
+ var MORE_PANEL_MARK = 'data-capyclaw-more-panel'
151
+ var MORE_ITEM_MARK = 'data-capyclaw-more-item'
152
+ var MORE_ROW_MARK = 'data-capyclaw-more-row'
153
+ var MORE_SEATS_MARK = 'data-capyclaw-more-seats'
154
+ var MORE_LEFT = 12
155
+ var MORE_WIDTH = 240
156
+ var MORE_PAD = 6
157
+ var MORE_GAP = 2
158
+ var MORE_ROW_H = 32
159
+ var MORE_SEATS_H = 40
160
+ var PLUS_ICON = '<svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">'
161
+ + '<path d="M7 2.5v9M2.5 7h9" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/></svg>'
162
+ var SIDEBAR_ICON = '<svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">'
163
+ + '<rect x="1.8" y="2.5" width="10.4" height="9" rx="1.6" fill="none" stroke="currentColor" stroke-width="1.2"/>'
164
+ + '<path d="M5.2 2.5v9" fill="none" stroke="currentColor" stroke-width="1.2"/></svg>'
165
+
166
+ var CSS = [
167
+ /* 映射容器内部一律横排、撑满标题栏行高 */
168
+ '[' + MARK + '] > *,',
169
+ '[' + MARK + '] [data-slot="sidebar.footer.action"],',
170
+ '[' + MARK + '] [data-slot="sidebar.footer.action"] > * {',
171
+ 'display:flex!important;flex-direction:row!important;align-items:center!important;',
172
+ 'gap:2px!important;width:auto!important;height:100%!important;',
173
+ 'margin:0!important;padding:0!important;min-height:0!important;',
174
+ '}',
175
+ '[' + MARK + '] button,[' + MARK + '] [role="button"]{flex:none!important}',
176
+ /* 标题栏整行是窗口拖拽区(frame::before app-region:drag)。Electron 的
177
+ app-region 是几何相减而非层叠:映射行必须声明 no-drag 把自己的盒子从
178
+ 拖拽区里减掉,否则落在里面的按钮点击会被当成拖窗口而失效。 */
179
+ '[' + MARK + '],[' + MARK +'] *{-webkit-app-region:no-drag!important}',
180
+ /* 原父容器:节点脱流后收掉残留留白与分隔线 */
181
+ '[' + SRC_MARK + ']{padding:0!important;gap:0!important;min-height:0!important;border-top-width:0!important;margin:0!important}',
182
+ /* 新会话按钮若只留图标:文字/快捷键徽标隐藏,内容盒收拢。
183
+ 注意 Label 选择器必须限定在 Content 的直接子级——[class*="newSessionLabel"]
184
+ 会连带匹配 newSessionLabelMask(装图层的容器),把图标一起藏掉。 */
185
+ '[' + MARK + '][class*="newSession"] [class*="newSessionContent"] > [class*="newSessionLabel"],',
186
+ '[' + MARK + '][class*="newSession"] [class*="newSessionShortcut"]{display:none!important}',
187
+ '[' + MARK + '][class*="newSession"] [class*="newSessionContent"]{width:auto!important;gap:0!important}',
188
+ '[' + MARK + '][class*="newSession"]{border-radius:var(--dsw-radius-sm)!important}',
189
+ '@media (hover:hover){[' + MARK + '][class*="newSession"]:hover{background:var(--dsw-alias-interactive-bg-hover)!important}}',
190
+ /* 品牌行(deepseek HARNESS):标题栏模式下整行收起,侧栏顶部 40px 让位。
191
+ 不能 display:none——Windows 的侧栏开关渲染在 logoRow 里(fixed 子级需要
192
+ 行留在 DOM);height:0+overflow:hidden 收掉行,fixed 子级不受裁切。
193
+ 门控与 active() 同条件;:has 外壳自己也在用(--dsh-windows-menu-start)。 */
194
+ 'html[data-windows-titlebar]:has([data-windows-menu]) [class*="logoRow"]{height:0!important;min-height:0!important;margin:0!important;padding:0!important;overflow:hidden!important}',
195
+ /* 鲸鱼钉顶栏时只留图标:品牌名/版本徽标隐藏 */
196
+ '[' + MARK + '][class*="brand"] [class*="brandName"]{display:none!important}',
197
+ '[' + MARK + '][class*="brand"] [class*="brandIdentity"]{gap:0!important}',
198
+ '[' + MARK + '][class*="brand"]{border-radius:var(--dsw-radius-sm)!important}',
199
+ '@media (hover:hover){[' + MARK + '][class*="brand"]:hover{background:var(--dsw-alias-interactive-bg-hover)!important}}',
200
+ /* 展开态(非 drawer)左起两枚 12/48:开关让位到 48,菜单栏 84 起。
201
+ 折叠态不覆盖:外壳原布局 12/48 + menu-start 84。 */
202
+ 'html[data-windows-titlebar]:has([data-windows-menu]):not(:has([data-sidebar-collapsed="true"])):not(:has([data-sidebar-drawer])) [data-sidebar-toggle]{left:' + TOGGLE_LEFT + 'px!important}',
203
+ 'html[data-windows-titlebar]:has([data-windows-menu]):not(:has([data-sidebar-collapsed="true"])):not(:has([data-sidebar-drawer])){--dsh-windows-menu-start:84px!important}',
204
+
205
+ /* ── 「其他」/「工作区」分组:标题栏触发按钮(两枚同款) ───────── */
206
+ /* 层级契约:宿主 dock≤70 / modal 1000 / 右键菜单 1100 / 子菜单 1101。caption 浮层一律 <1100:
207
+ 触发/预留/席位 1080、更多背板 1088、下拉/浮窗/注入行 1090,避免压住宿主右键菜单及子菜单。 */
208
+ '[' + TRIGGER_MARK + '],[' + WS_TRIGGER_MARK + ']{position:fixed!important;z-index:1080!important;box-sizing:border-box!important;',
209
+ 'display:inline-flex!important;align-items:center!important;gap:4px!important;',
210
+ 'height:28px!important;width:auto!important;max-width:160px!important;margin:0!important;padding:0 8px!important;',
211
+ 'border:0!important;border-radius:var(--dsw-radius-sm,6px)!important;background:transparent!important;',
212
+ 'color:inherit!important;font:inherit!important;font-size:12px!important;line-height:1!important;',
213
+ 'white-space:nowrap!important;cursor:pointer!important;-webkit-app-region:no-drag!important}',
214
+ '[' + TRIGGER_MARK + '] span,[' + WS_TRIGGER_MARK + '] span{overflow:hidden!important;text-overflow:ellipsis!important}',
215
+ '[' + TRIGGER_MARK + '] svg,[' + WS_TRIGGER_MARK + '] svg{display:block!important;flex:none!important;opacity:.55!important;transition:transform .12s ease!important}',
216
+ '[' + TRIGGER_MARK + '][aria-expanded="true"] svg:last-child,[' + WS_TRIGGER_MARK + '][aria-expanded="true"] svg:last-child{transform:rotate(180deg)!important;opacity:.9!important}',
217
+ /* 第二行占位:外壳 frame 靠 padding-top 给标题栏让位(AppFrame.module.css),
218
+ 加一行高 = 下方侧栏/主区/右栏整体下移;frame 背景与标题栏条同色,第二行
219
+ 天然融入 chrome。只覆盖 CSS,不碰 React 的内联轨道值;摘属性即还原。 */
220
+ 'html[' + WS_ROW_ATTR + '] div:has(> [data-shell-bottom]){padding-top:calc(var(--dsh-windows-titlebar-height) + ' + WS_ROW_H + 'px)!important}',
221
+ '@media (hover:hover){[' + TRIGGER_MARK + ']:hover,[' + WS_TRIGGER_MARK + ']:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.06))!important}}',
222
+ '[' + TRIGGER_MARK + '][aria-expanded="true"],[' + WS_TRIGGER_MARK + '][aria-expanded="true"]{background:var(--dsw-alias-interactive-bg-active,rgba(0,0,0,.08))!important}',
223
+
224
+ /* ── 预留栏位:「其他」后的占位场(内容待定,虚线盒示意) ─────── */
225
+ '[' + EXTRA_SLOT_MARK + ']{position:fixed!important;z-index:1080!important;box-sizing:border-box!important;',
226
+ 'display:inline-flex!important;align-items:center!important;gap:4px!important;',
227
+ 'height:28px!important;width:auto!important;right:auto!important;max-width:160px!important;margin:0!important;padding:0 8px!important;',
228
+ 'border:1px dashed var(--dsw-alias-border-l2,rgba(0,0,0,.25))!important;border-radius:var(--dsw-radius-sm,6px)!important;',
229
+ 'background:transparent!important;color:var(--dsw-alias-label-secondary,inherit)!important;font:inherit!important;font-size:12px!important;line-height:1!important;',
230
+ 'white-space:nowrap!important}',
231
+ '[' + EXTRA_SLOT_MARK + '] span{overflow:hidden!important;text-overflow:ellipsis!important;opacity:.75!important}',
232
+ /* 被占用(挂载锚有消费者):去虚线/限宽;left 由编排器钉在「其他」右侧、right 钉在
233
+ 窗口控件预留区左缘 ⇒ width:auto 的 fixed 盒拉伸占满标题栏剩余宽度(Edge 式标签
234
+ 条填满到末尾,不再内容自撑半截停住);内层 mount 均分槽宽承载消费者 React 根。
235
+ 未占用时 right:auto 回到虚线占位盒自撑。 */
236
+ '[' + EXTRA_SLOT_MARK + '][data-occupied]{border:none!important;max-width:calc(100vw - ' + CAPTION_RIGHT_RESERVE + 'px)!important;padding:0!important;gap:0!important;',
237
+ 'right:' + CAPTION_RIGHT_RESERVE + 'px!important}',
238
+ '[' + EXTRA_SLOT_MOUNT_MARK + ']{display:flex!important;align-items:center!important;height:28px!important;',
239
+ 'flex:1 1 0!important;min-width:0!important;max-width:100%!important;overflow:hidden!important}',
240
+
241
+ /* ── 「其他」分组:把 sidebar.panellist 收成下拉 ─────────────── */
242
+ 'nav[' + MARK + ']{position:fixed!important;z-index:1090!important;box-sizing:border-box!important;',
243
+ 'display:flex!important;flex-direction:column!important;gap:2px!important;',
244
+ 'margin:0!important;padding:6px!important;width:' + NAV_WIDTH + 'px!important;',
245
+ 'max-height:min(70vh,480px)!important;overflow-x:hidden!important;overflow-y:auto!important;',
246
+ 'background:var(--dsw-menu-surface-fill,var(--dsw-alias-bg-layer-2,#fff))!important;',
247
+ 'border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08))!important;',
248
+ 'border-radius:var(--dsw-radius-lg,12px)!important;',
249
+ 'box-shadow:var(--dsw-elevation-panel,0 8px 24px rgba(0,0,0,.14))!important;',
250
+ 'opacity:0!important;visibility:hidden!important;pointer-events:none!important;transform:translateY(-4px)!important;',
251
+ 'transition:opacity .12s ease,transform .12s ease!important;-webkit-app-region:no-drag!important}',
252
+ 'html[' + OPEN_ATTR + '] nav[' + MARK + ']{opacity:1!important;visibility:visible!important;pointer-events:auto!important;transform:none!important}',
253
+ 'nav[' + MARK + '] > *{flex:none!important}',
254
+ /* 行:入口层负责 hover/active 底色,按钮本身满宽左对齐 */
255
+ 'nav[' + MARK + '] [class*="panelEntry"]{border-inline:0!important;border-radius:var(--dsw-radius-sm,6px)!important}',
256
+ 'nav[' + MARK + '] button[class*="panelRow"],',
257
+ 'nav[' + MARK + '] [class*="moreAnchor"] button{display:flex!important;align-items:center!important;justify-content:flex-start!important;',
258
+ 'gap:8px!important;width:100%!important;height:30px!important;min-height:30px!important;margin:0!important;padding:0 8px!important;',
259
+ 'border:0!important;background:transparent!important;color:inherit!important;font:inherit!important;font-size:13px!important;',
260
+ 'line-height:1!important;text-align:left!important;cursor:pointer!important}',
261
+ '@media (hover:hover){nav[' + MARK + '] button[class*="panelRow"]:hover,',
262
+ 'nav[' + MARK + '] [class*="moreAnchor"] button:hover{background:transparent!important}}',
263
+ /* 折叠态不渲染 panelTitle,标签统一由 aria-label 补上;展开态的 panelTitle 让位 */
264
+ 'nav[' + MARK + '] [class*="panelTitle"]{display:none!important}',
265
+ 'nav[' + MARK + '] button[class*="panelRow"]::after,',
266
+ 'nav[' + MARK + '] [class*="moreAnchor"] button::after{content:attr(aria-label);flex:1 1 auto!important;min-width:0!important;',
267
+ 'overflow:hidden!important;text-overflow:ellipsis!important;white-space:nowrap!important}',
268
+ 'nav[' + MARK + '] [class*="panelGlyph"]{width:16px!important;height:16px!important;flex:none!important;',
269
+ 'color:var(--dsw-alias-menu-icon,currentColor)!important}',
270
+ /* 下拉里不给行内「取消固定」小图标留位:固定与否仍由「更多」菜单管 */
271
+ 'nav[' + MARK + '] [class*="panelUnpin"]{display:none!important}',
272
+
273
+ /* ── 工作区收藏夹:把 sidebar.workspaces 区域收成独立浮窗 ─────── */
274
+ 'div[' + WS_MARK + ']{position:fixed!important;z-index:1090!important;box-sizing:border-box!important;',
275
+ 'display:flex!important;flex-direction:column!important;height:auto!important;',
276
+ 'margin:0!important;padding:6px!important;width:' + WS_WIDTH + 'px!important;',
277
+ 'max-height:min(70vh,560px)!important;',
278
+ 'background:var(--dsw-menu-surface-fill,var(--dsw-alias-bg-layer-2,#fff))!important;',
279
+ 'border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08))!important;',
280
+ 'border-radius:var(--dsw-radius-lg,12px)!important;',
281
+ 'box-shadow:var(--dsw-elevation-panel,0 8px 24px rgba(0,0,0,.14))!important;',
282
+ 'opacity:0!important;visibility:hidden!important;pointer-events:none!important;transform:translateY(-4px)!important;',
283
+ 'transition:opacity .12s ease,transform .12s ease!important;-webkit-app-region:no-drag!important}',
284
+ 'html[' + WS_OPEN_ATTR + '] div[' + WS_MARK + ']{opacity:1!important;visibility:visible!important;pointer-events:auto!important;transform:none!important}',
285
+ 'div[' + WS_MARK + '] *{-webkit-app-region:no-drag!important}',
286
+ /* 列表席位:浮窗内独立滚动。原生 overflow-y 受 @container scroll-state 管辖,
287
+ 脱离侧栏容器后该查询失效,这里强制 auto 兜底;负 margin 是贴合侧栏滚动条的,收掉。 */
288
+ 'div[' + WS_MARK + '] [data-sidebar-list-area]{flex:1 1 auto!important;min-height:0!important;',
289
+ 'overflow-x:hidden!important;overflow-y:auto!important;margin:0!important;padding:0 2px!important}',
290
+ /* 工具条(工作区标题/搜索/视图选项/添加):保持原生 36px 高,收掉负 margin */
291
+ 'div[' + WS_MARK + '] [data-sidebar-workspace-header]{flex:none!important;margin:0!important}',
292
+
293
+ /* ── 「更多」收拢浮窗(展开态):一枚按钮收整簇 ─────────────────── */
294
+ /* 浮窗背板:菜单表面,overflow:visible 让账户/设备弹出菜单逃出去 */
295
+ '[' + MORE_PANEL_MARK + ']{position:fixed!important;z-index:1088!important;box-sizing:border-box!important;',
296
+ 'background:var(--dsw-menu-surface-fill,var(--dsw-alias-bg-layer-2,#fff))!important;',
297
+ 'border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08))!important;',
298
+ 'border-radius:var(--dsw-radius-lg,12px)!important;',
299
+ 'box-shadow:var(--dsw-elevation-panel,0 8px 24px rgba(0,0,0,.14))!important;',
300
+ 'overflow:visible!important;-webkit-app-region:no-drag!important;',
301
+ 'opacity:0!important;visibility:hidden!important;pointer-events:none!important;transform:translateY(-4px)!important;',
302
+ 'transition:opacity .12s ease,transform .12s ease!important}',
303
+ 'html[' + MORE_OPEN_ATTR + '] [' + MORE_PANEL_MARK + ']{opacity:1!important;visibility:visible!important;pointer-events:auto!important;transform:none!important}',
304
+ /* 收进浮窗的宿主节点(菜单栏/底部入口行/面板列表)与注入行:收起时隐形 */
305
+ '[' + MORE_ITEM_MARK + '],[' + MORE_ROW_MARK + ']{-webkit-app-region:no-drag!important;',
306
+ 'opacity:0!important;visibility:hidden!important;pointer-events:none!important}',
307
+ 'html[' + MORE_OPEN_ATTR + '] [' + MORE_ITEM_MARK + '],html[' + MORE_OPEN_ATTR + '] [' + MORE_ROW_MARK + ']{opacity:1!important;visibility:visible!important;pointer-events:auto!important}',
308
+ '[' + MORE_ITEM_MARK + '] *{-webkit-app-region:no-drag!important}',
309
+ /* 注入动作行(新会话 / 折叠侧栏):菜单行样式 */
310
+ '[' + MORE_ROW_MARK + ']{position:fixed!important;z-index:1090!important;box-sizing:border-box!important;',
311
+ 'display:flex!important;align-items:center!important;gap:8px!important;',
312
+ 'height:' + MORE_ROW_H + 'px!important;margin:0!important;padding:0 8px!important;',
313
+ 'border:0!important;border-radius:var(--dsw-radius-sm,6px)!important;background:transparent!important;',
314
+ 'color:inherit!important;font:inherit!important;font-size:13px!important;line-height:1!important;',
315
+ 'text-align:left!important;cursor:pointer!important;white-space:nowrap!important}',
316
+ '[' + MORE_ROW_MARK + '] svg{flex:none!important;opacity:.7!important}',
317
+ '@media (hover:hover){[' + MORE_ROW_MARK + ']:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.06))!important}}',
318
+ /* 底部入口行(Maple 账户 + 手机/电脑)在浮窗内横排 */
319
+ '[' + MORE_ITEM_MARK + '][' + MORE_SEATS_MARK + ']{display:flex!important;flex-direction:row!important;align-items:center!important;gap:2px!important}',
320
+ '[' + MORE_ITEM_MARK + '][' + MORE_SEATS_MARK + '] > *{flex:0 1 auto!important;min-width:0!important;display:flex!important;align-items:center!important}',
321
+ /* 面板列表收进浮窗:去掉自身表面(背板统一提供),保留滚动 */
322
+ 'nav[' + MORE_ITEM_MARK + ']{position:fixed!important;z-index:1090!important;box-sizing:border-box!important;',
323
+ 'display:flex!important;flex-direction:column!important;gap:2px!important;height:auto!important;',
324
+ 'background:transparent!important;border:0!important;box-shadow:none!important;',
325
+ 'padding:0!important;margin:0!important;max-height:min(60vh,420px)!important;',
326
+ 'overflow-x:hidden!important;overflow-y:auto!important;transform:none!important}',
327
+ 'nav[' + MORE_ITEM_MARK + '] > *{flex:none!important}',
328
+ /* 面板行样式(复刻 nav[MARK] 那份,标记不同故独立一份) */
329
+ 'nav[' + MORE_ITEM_MARK + '] [class*="panelEntry"]{border-inline:0!important;border-radius:var(--dsw-radius-sm,6px)!important}',
330
+ 'nav[' + MORE_ITEM_MARK + '] button[class*="panelRow"],',
331
+ 'nav[' + MORE_ITEM_MARK + '] [class*="moreAnchor"] button{display:flex!important;align-items:center!important;justify-content:flex-start!important;gap:8px!important;',
332
+ 'width:100%!important;height:30px!important;min-height:30px!important;margin:0!important;padding:0 8px!important;',
333
+ 'border:0!important;background:transparent!important;color:inherit!important;font:inherit!important;font-size:13px!important;line-height:1!important;',
334
+ 'text-align:left!important;cursor:pointer!important}',
335
+ '@media (hover:hover){nav[' + MORE_ITEM_MARK + '] button[class*="panelRow"]:hover,',
336
+ 'nav[' + MORE_ITEM_MARK + '] [class*="moreAnchor"] button:hover{background:transparent!important}}',
337
+ 'nav[' + MORE_ITEM_MARK + '] [class*="panelTitle"]{display:none!important}',
338
+ 'nav[' + MORE_ITEM_MARK + '] button[class*="panelRow"]::after,',
339
+ 'nav[' + MORE_ITEM_MARK + '] [class*="moreAnchor"] button::after{content:attr(aria-label);flex:1 1 auto!important;min-width:0!important;',
340
+ 'overflow:hidden!important;text-overflow:ellipsis!important;white-space:nowrap!important}',
341
+ 'nav[' + MORE_ITEM_MARK + '] [class*="panelGlyph"]{width:16px!important;height:16px!important;flex:none!important;',
342
+ 'color:var(--dsw-alias-menu-icon,currentColor)!important}',
343
+ 'nav[' + MORE_ITEM_MARK + '] [class*="panelUnpin"]{display:none!important}',
344
+ ].join('')
345
+
346
+ /** 注入一张归属本插件的样式表(卸载时调用方 remove)。id 可选(动态过滤表用)。 */
347
+ function styleTag(css, id) {
348
+ var t = document.createElement('style')
349
+ t.dataset.plugin = PACKAGE_ID
350
+ if (id) t.id = id
351
+ t.textContent = css
352
+ document.head.appendChild(t)
353
+ return t
354
+ }
355
+
356
+ return {
357
+ name: 'caption-map',
358
+ apply: function (ctx) {
359
+ /* macOS 让位:宿主 preload 在页面脚本前钉死 html[data-platform]。darwin 上
360
+ * 区域映射 / 挂载锚 / 固定侧栏 / 聊天停靠整体交给 @capyclaw/caption-map-macos
361
+ * (它只在 darwin 生效),本包四条 effect 全部早退、不设 owner 标记,避免双
362
+ * provide captionExtra / 双 owner / 双 fixed-sidebar 冲突。win32 / 纯 web 照旧。 */
363
+ var IS_DARWIN = document.documentElement.getAttribute('data-platform') === 'darwin'
364
+
365
+ /* 让位标记:聊天窗停靠由本包接管。老的 @capyclaw/chat-dock 见到它就自己退出,
366
+ * 两个包同时启用时不会各有一个人去搬同一块面板。darwin 上由 mac 包设标记。 */
367
+ if (!IS_DARWIN) {
368
+ try { window.__CAPYCLAW_CHAT_DOCK_OWNER__ = PACKAGE_ID } catch (error) { /* 忽略 */ }
369
+ }
370
+
371
+ /** 预留栏位 = 显式挂载锚:「其他」右侧一枚场。无消费者时是虚线占位盒;
372
+ 消费者经 ctx.captionExtra 服务 acquire 后,内层 mount 节点交给它挂 React 根,
373
+ 占位 span 隐藏、外盒去虚线自撑。纯自有节点:pass 注入/排布、yield 移除,
374
+ 不需要样式账本(不钉宿主节点)。编排器把「其他」排布后的 cursor 传进来,故永远接在其右侧。
375
+ 多租约可拓展:acquire/release/getMount 接受可选 owner 键,每个 owner 一枚独立
376
+ mount 子节点按 acquire 序横排;无参调用等价 owner='default'(向后兼容)。
377
+ 服务在 apply 作用域创建(早于 region-map effect),保证消费者 inject 能尽早解析。 */
378
+ var extraSlot = (function () {
379
+ var el = null
380
+ var leases = [] /* 有序租约 [{key, el}],acquire 序即横排序 */
381
+ var dirty = false
382
+ var listeners = []
383
+ function norm(owner) { return owner || 'default' }
384
+ function find(key) { for (var i = 0; i < leases.length; i++) if (leases[i].key === key) return leases[i]; return null }
385
+ function notify() { dirty = false; for (var i = 0; i < listeners.length; i++) listeners[i]() }
386
+ function placeholder() { return el ? el.querySelector('span') : null }
387
+ function mountId(key) { return key === 'default' ? EXTRA_SLOT_ID + '-mount' : EXTRA_SLOT_ID + '-mount-' + key }
388
+ /** 外盒在场时,为每个租约保证一枚连着的 mount 子节点(让位重建后补建)。 */
389
+ function syncMounts() {
390
+ if (!el || !el.isConnected) return
391
+ for (var i = 0; i < leases.length; i++) {
392
+ var L = leases[i]
393
+ if (L.el && L.el.isConnected && L.el.parentNode === el) continue
394
+ var m = document.createElement('div')
395
+ m.id = mountId(L.key)
396
+ m.setAttribute(EXTRA_SLOT_MOUNT_MARK, '')
397
+ m.setAttribute('data-owner', L.key)
398
+ el.appendChild(m)
399
+ L.el = m
400
+ dirty = true
401
+ }
402
+ }
403
+ function visuals() {
404
+ if (!el) return
405
+ var ph = placeholder()
406
+ if (ph) ph.style.display = leases.length ? 'none' : ''
407
+ if (leases.length) { el.setAttribute('data-occupied', ''); el.setAttribute('role', 'group') }
408
+ else { el.removeAttribute('data-occupied'); el.setAttribute('role', 'status') }
409
+ }
410
+ function ensure() {
411
+ if (el && el.isConnected) { syncMounts(); return el }
412
+ var node = document.getElementById(EXTRA_SLOT_ID)
413
+ if (!node) {
414
+ node = document.createElement('div')
415
+ node.id = EXTRA_SLOT_ID
416
+ node.setAttribute(EXTRA_SLOT_MARK, '')
417
+ node.setAttribute('role', 'status')
418
+ node.setAttribute('aria-label', EXTRA_SLOT_LABEL)
419
+ node.title = EXTRA_SLOT_LABEL
420
+ node.innerHTML = '<span>' + EXTRA_SLOT_LABEL + '</span>'
421
+ document.body.appendChild(node)
422
+ }
423
+ el = node
424
+ syncMounts()
425
+ visuals()
426
+ return node
427
+ }
428
+ return {
429
+ pass: function (left, capH) {
430
+ var node = ensure()
431
+ var s = node.style
432
+ s.position = 'fixed'
433
+ s.top = ((capH - 28) / 2) + 'px'
434
+ s.left = left + 'px'
435
+ s.zIndex = '1080'
436
+ s.webkitAppRegion = '' /* 槽盒不挖拖拽区:空白尾继承宿主 drag;标签/按钮自带 no-drag 仍可点 */
437
+ /* 不挤占右侧原生 min/max/close 预留区:放不下整枚隐藏。
438
+ 占用态靠 left+right 拉伸、宽恒等于剩余空间,只看 left 是否已越过预留区
439
+ 左缘(若再累加 rect 宽,亚像素舍入会把拉伸盒误判成挤占而整枚隐藏);
440
+ 未占用占位盒仍按内容宽判断。 */
441
+ var w = node.getBoundingClientRect().width
442
+ var over = leases.length
443
+ ? left >= window.innerWidth - CAPTION_RIGHT_RESERVE
444
+ : left + w > window.innerWidth - CAPTION_RIGHT_RESERVE
445
+ s.display = over ? 'none' : ''
446
+ if (dirty) notify()
447
+ return left + w + GAP
448
+ },
449
+ yield: function () { if (el) { el.remove(); el = null } dirty = true; notify() },
450
+ /* 唯一对外契约:挂载锚(多租约)。消费者只拿自己的 mount 节点,不读 caption-map 任何其它 DOM。 */
451
+ service: {
452
+ acquire: function (owner) {
453
+ var key = norm(owner)
454
+ if (find(key)) return true /* 幂等 */
455
+ leases.push({ key: key, el: null })
456
+ syncMounts()
457
+ visuals()
458
+ dirty = true
459
+ notify()
460
+ return true
461
+ },
462
+ release: function (owner) {
463
+ var key = norm(owner)
464
+ var L = find(key)
465
+ if (!L) return false
466
+ if (L.el) L.el.remove()
467
+ leases.splice(leases.indexOf(L), 1)
468
+ visuals()
469
+ dirty = true
470
+ notify()
471
+ return true
472
+ },
473
+ getMount: function (owner) {
474
+ var L = find(norm(owner))
475
+ return (L && el && el.isConnected && L.el && L.el.isConnected && L.el.parentNode === el) ? L.el : null
476
+ },
477
+ subscribe: function (fn) { listeners.push(fn); return function () { var i = listeners.indexOf(fn); if (i >= 0) listeners.splice(i, 1) } }
478
+ }
479
+ }
480
+ })()
481
+
482
+ /* 挂载锚服务:cordis provide,卸载对称 unprovide(消费者 inject 随之失效)。 */
483
+ ctx.effect(function () {
484
+ if (IS_DARWIN) return function () {} /* darwin 由 caption-map-macos 提供 */
485
+ var svc = extraSlot.service
486
+ var un = (typeof ctx.provide === 'function') ? ctx.provide('captionExtra', svc)
487
+ : (ctx.reflect && typeof ctx.reflect.provide === 'function') ? ctx.reflect.provide('captionExtra', svc) : null
488
+ return function () { if (typeof un === 'function') un() }
489
+ }, 'caption-map: extra slot mount service')
490
+
491
+ ctx.effect(function () {
492
+ if (IS_DARWIN) return function () {} /* darwin 区域映射由 caption-map-macos 接管 */
493
+ var tag = styleTag(CSS)
494
+
495
+ /* ── 共享底座 kit ─────────────────────────────────────────── */
496
+
497
+ function menubar() { return document.querySelector('[data-windows-menu]') }
498
+ function active() { return document.documentElement.hasAttribute('data-windows-titlebar') && !!menubar() }
499
+ function drawer() { return !!document.querySelector('[data-sidebar-drawer]') }
500
+ function collapsed() { return !!document.querySelector('[data-sidebar-collapsed="true"]') }
501
+
502
+ /** 每特性一份样式账本:adopt 记下原内联样式并打标记,restore 逐字还原。
503
+ 各特性互不共享映射表——编排器无需「跳过哪些选择器」的耦合清单。 */
504
+ function makeLedger(mark) {
505
+ var saved = new Map()
506
+ var ledger = {
507
+ has: function (el) { return saved.has(el) },
508
+ adopt: function (el) {
509
+ if (!saved.has(el)) saved.set(el, el.style.cssText)
510
+ el.setAttribute(mark, '')
511
+ },
512
+ restore: function (el) {
513
+ var s = saved.get(el)
514
+ if (s === undefined) return
515
+ el.style.cssText = s
516
+ el.removeAttribute(mark)
517
+ saved.delete(el)
518
+ },
519
+ restoreAll: function () { saved.forEach(function (_s, el) { ledger.restore(el) }) },
520
+ /* 还原匹配 sel 的旧节点(侧栏重挂载后的残留),keep 除外。
521
+ 已断连的节点无条件还原:带父级组合符的选择器(如 BRAND_SEL)
522
+ 在节点脱 DOM 后 matches 永不命中,不兜底会留下带钉子的孤儿。 */
523
+ stale: function (keep, sel) {
524
+ saved.forEach(function (_s, el) {
525
+ if (el === keep) return
526
+ if (!el.isConnected || (el.matches && el.matches(sel))) ledger.restore(el)
527
+ })
528
+ },
529
+ /* 还原不再是 targets 或已断连的节点(席位/整行用) */
530
+ reconcile: function (targets) {
531
+ saved.forEach(function (_s, el) {
532
+ if (targets.indexOf(el) === -1 || !el.isConnected) ledger.restore(el)
533
+ })
534
+ },
535
+ }
536
+ return ledger
537
+ }
538
+
539
+ /** 原父容器收零(节点脱流后的留白/分隔线)。共享记账,卸载统一还原。 */
540
+ var markedParents = new Set()
541
+ function markSrc(el) {
542
+ var p = el.parentElement
543
+ if (!p || p === document.body) return null
544
+ if (!markedParents.has(p)) { p.setAttribute(SRC_MARK, ''); markedParents.add(p) }
545
+ return p
546
+ }
547
+ function releaseSrc(p) {
548
+ if (!p) return
549
+ p.removeAttribute(SRC_MARK)
550
+ markedParents.delete(p)
551
+ }
552
+
553
+ /** 被容器隔离的祖先(container-type 让 fixed 相对它定位)→ 原值。 */
554
+ var uncontained = new Map()
555
+ /** 容器隔离兜底:量出来 fixed 没落在期望位置,就把建立包含块的那层还原成
556
+ normal 再重排一次。paintNav / paintWs 共用这一份。 */
557
+ function escapeContainment(el, expectLeft, expectTop) {
558
+ var box = el.getBoundingClientRect()
559
+ if (Math.abs(box.left - expectLeft) <= 2 && Math.abs(box.top - expectTop) <= 2) return
560
+ var node = el.parentElement
561
+ while (node && node !== document.body) {
562
+ var ct = getComputedStyle(node).containerType
563
+ if (ct && ct !== 'normal') {
564
+ if (!uncontained.has(node)) uncontained.set(node, node.style.containerType)
565
+ node.style.containerType = 'normal'
566
+ schedule()
567
+ break
568
+ }
569
+ node = node.parentElement
570
+ }
571
+ }
572
+
573
+ /** 左夹取:下拉/浮窗不越过窗口右缘(留 8px)。 */
574
+ function clampLeft(left, width) {
575
+ if (left + width > window.innerWidth - 8) return Math.max(8, window.innerWidth - 8 - width)
576
+ return left
577
+ }
578
+
579
+ /** 触发按钮定位(「其他」与文件夹按钮同款)。top 缺省 = 标题栏行垂直居中。 */
580
+ function paintTrigger(btn, left, capH, top) {
581
+ var s = btn.style
582
+ s.position = 'fixed'
583
+ s.top = (top != null ? top : (capH - 28) / 2) + 'px'
584
+ s.left = left + 'px'
585
+ s.zIndex = '1080'
586
+ }
587
+ /** 注入一枚我们拥有的触发按钮(卸载时移除)。 */
588
+ function makeTriggerButton(opts) {
589
+ var btn = document.createElement('button')
590
+ btn.type = 'button'
591
+ if (opts.id) btn.id = opts.id
592
+ btn.setAttribute(opts.mark, '')
593
+ if (opts.group != null) btn.setAttribute('data-ws-group', opts.group)
594
+ btn.setAttribute('aria-haspopup', 'menu')
595
+ if (opts.expanded != null) btn.setAttribute('aria-expanded', opts.expanded)
596
+ btn.innerHTML = opts.html
597
+ btn.addEventListener('click', opts.onClick)
598
+ document.body.appendChild(btn)
599
+ return btn
600
+ }
601
+
602
+ /** 下拉开合状态 + 互斥注册表:开一个自动收其它。onChange 承接各特性的
603
+ aria 同步 / 过滤清理等副作用。新增下拉只需再 makeOpenState 一枚。 */
604
+ var dropdowns = []
605
+ function makeOpenState(attr, onChange) {
606
+ var state = {
607
+ isOpen: function () { return document.documentElement.hasAttribute(attr) },
608
+ set: function (open) {
609
+ if (open) {
610
+ for (var i = 0; i < dropdowns.length; i++) if (dropdowns[i] !== state) dropdowns[i].set(false)
611
+ document.documentElement.setAttribute(attr, '')
612
+ } else {
613
+ document.documentElement.removeAttribute(attr)
614
+ }
615
+ if (onChange) onChange(open)
616
+ },
617
+ clear: function () { document.documentElement.removeAttribute(attr) },
618
+ }
619
+ dropdowns.push(state)
620
+ return state
621
+ }
622
+
623
+ /* 点空白/Esc 收起的策略分发:每个下拉特性注册自己的 onClick/onEsc。 */
624
+ var dropdownFeatures = []
625
+
626
+ var timer = 0
627
+ var lastMode = ''
628
+
629
+ /* ── 特性模块 ─────────────────────────────────────────────── */
630
+
631
+ /** 鲸鱼图标:展开态钉顶栏 left:12 只留图标;折叠/drawer 交外壳。 */
632
+ var brand = (function () {
633
+ var ledger = makeLedger(MARK)
634
+ function target() {
635
+ var el = document.querySelector(BRAND_SEL)
636
+ if (!el || !el.isConnected || !active()) return null
637
+ if (drawer() || collapsed()) return null
638
+ var st = getComputedStyle(el)
639
+ if (!ledger.has(el) && (st.display === 'none' || st.visibility === 'hidden')) return null
640
+ return el
641
+ }
642
+ function paint(el) {
643
+ ledger.adopt(el)
644
+ var s = el.style
645
+ s.display = 'flex'
646
+ s.position = 'fixed'
647
+ s.left = BRAND_LEFT + 'px'
648
+ s.top = 'calc((var(--dsh-windows-titlebar-height, 40px) - 28px) / 2)'
649
+ s.width = '28px'
650
+ s.height = '28px'
651
+ s.margin = '0'
652
+ s.padding = '0'
653
+ s.border = 'none'
654
+ s.background = 'transparent'
655
+ s.alignItems = 'center'
656
+ s.justifyContent = 'center'
657
+ s.flex = 'none'
658
+ s.zIndex = '30'
659
+ s.webkitAppRegion = 'no-drag'
660
+ }
661
+ return {
662
+ pass: function () {
663
+ var el = target()
664
+ ledger.stale(el, BRAND_SEL)
665
+ if (el) paint(el)
666
+ },
667
+ yield: function () { ledger.restoreAll() },
668
+ }
669
+ })()
670
+
671
+ /** 新会话按钮:展开态整格收起(鲸鱼兼作入口);折叠/drawer 交外壳。 */
672
+ var newSession = (function () {
673
+ var ledger = makeLedger(MARK)
674
+ var parent = null
675
+ function target() {
676
+ var btn = document.querySelector(NS_BTN)
677
+ if (!btn || !btn.isConnected || !active()) return null
678
+ /* drawer 模式 shell.leading 自带 ⊕;折叠态外壳自己钉——都不插手 */
679
+ if (drawer() || collapsed()) return null
680
+ var st = getComputedStyle(btn)
681
+ /* 被外壳隐藏(visibility 等)不钉;我们自己藏的(账本里)要继续管 */
682
+ if (!ledger.has(btn) && (st.display === 'none' || st.visibility === 'hidden')) return null
683
+ return btn
684
+ }
685
+ function paint(btn) {
686
+ ledger.adopt(btn)
687
+ btn.style.display = 'none'
688
+ parent = markSrc(btn)
689
+ }
690
+ function release() { releaseSrc(parent); parent = null }
691
+ return {
692
+ pass: function () {
693
+ var btn = target()
694
+ ledger.stale(btn, NS_BTN)
695
+ if (btn) { paint(btn); return }
696
+ /* 不插手时把原父容器的留白压缩还回去(折叠态 rail 间距归外壳管) */
697
+ release()
698
+ },
699
+ yield: function () { ledger.restoreAll(); release() },
700
+ }
701
+ })()
702
+
703
+ /** 底部入口行 / 逐席位:fixed 进标题栏第一行,返回排布后的 cursor。 */
704
+ var seats = (function () {
705
+ var ledger = makeLedger(MARK)
706
+ function paint(el, left, capH, maxW) {
707
+ ledger.adopt(el)
708
+ var s = el.style
709
+ s.position = 'fixed'
710
+ s.top = '0px'
711
+ s.left = left + 'px'
712
+ s.height = capH + 'px'
713
+ s.width = 'auto'
714
+ s.maxWidth = maxW + 'px'
715
+ s.margin = '0'
716
+ s.padding = '0 2px'
717
+ s.display = 'flex'
718
+ s.flexDirection = 'row'
719
+ s.alignItems = 'center'
720
+ s.justifyContent = 'flex-start'
721
+ s.gap = '2px'
722
+ s.zIndex = '1080'
723
+ s.background = 'transparent'
724
+ s.border = '0'
725
+ s.boxShadow = 'none'
726
+ s.transform = 'none'
727
+ /* 不裁切:席位里的下拉/弹出菜单要能溢出映射行显示(overflow:hidden
728
+ 会把菜单裁掉,表现为「按钮点了没反应」)。 */
729
+ s.overflow = 'visible'
730
+ s.flex = 'none'
731
+ s.webkitAppRegion = 'no-drag'
732
+ markSrc(el)
733
+ }
734
+ return {
735
+ owns: function (el) { return ledger.has(el) },
736
+ pass: function (targets, cursor, capH) {
737
+ ledger.reconcile(targets)
738
+ for (var i = 0; i < targets.length; i++) {
739
+ var maxW = Math.max(80, window.innerWidth - cursor - CAPTION_RIGHT_RESERVE)
740
+ paint(targets[i], cursor, capH, maxW)
741
+ cursor += targets[i].getBoundingClientRect().width + GAP
742
+ }
743
+ return cursor
744
+ },
745
+ yield: function () { ledger.restoreAll() },
746
+ }
747
+ })()
748
+
749
+ /** 「其他」分组:一枚触发按钮 + nav.panelList 下拉。 */
750
+ var others = (function () {
751
+ var ledger = makeLedger(MARK)
752
+ var trigger = null
753
+ var open = makeOpenState(OPEN_ATTR, function (isOpen) {
754
+ if (trigger) trigger.setAttribute('aria-expanded', isOpen ? 'true' : 'false')
755
+ })
756
+ function ensureTrigger() {
757
+ if (trigger && trigger.isConnected) return trigger
758
+ var btn = document.getElementById(TRIGGER_ID)
759
+ if (!btn) {
760
+ btn = makeTriggerButton({
761
+ id: TRIGGER_ID, mark: TRIGGER_MARK,
762
+ html: '<span>' + OTHERS_LABEL + '</span>' + CHEVRON,
763
+ onClick: function (event) {
764
+ /* 顶栏是拖拽区:别让事件继续冒到窗口拖动逻辑上 */
765
+ event.preventDefault()
766
+ event.stopPropagation()
767
+ open.set(!open.isOpen())
768
+ },
769
+ })
770
+ }
771
+ trigger = btn
772
+ if (btn.getAttribute('aria-expanded') === null) btn.setAttribute('aria-expanded', open.isOpen() ? 'true' : 'false')
773
+ return btn
774
+ }
775
+ function paintNav(el, left, capH) {
776
+ ledger.adopt(el)
777
+ var clamped = clampLeft(left, NAV_WIDTH)
778
+ var s = el.style
779
+ s.position = 'fixed'
780
+ s.top = (capH + 4) + 'px'
781
+ s.left = clamped + 'px'
782
+ s.width = NAV_WIDTH + 'px'
783
+ s.zIndex = '1090'
784
+ s.webkitAppRegion = 'no-drag'
785
+ escapeContainment(el, clamped, capH + 4)
786
+ }
787
+ return {
788
+ isOpen: open.isOpen,
789
+ pass: function (navEl, left, capH) {
790
+ if (!navEl) {
791
+ if (trigger) { open.set(false); trigger.remove(); trigger = null }
792
+ open.clear()
793
+ return left
794
+ }
795
+ /* 侧栏重挂载后旧 nav 会留在账本里:还原它,别留一枚隐藏的 fixed 空盒 */
796
+ ledger.stale(navEl, NAV_SEL)
797
+ var btn = ensureTrigger()
798
+ paintTrigger(btn, left, capH)
799
+ paintNav(navEl, left, capH)
800
+ return left + btn.getBoundingClientRect().width + GAP
801
+ },
802
+ yield: function () {
803
+ if (trigger) { trigger.remove(); trigger = null }
804
+ open.clear()
805
+ ledger.restoreAll()
806
+ },
807
+ onClick: function (target) {
808
+ if (!open.isOpen()) return
809
+ if (target.closest('#' + TRIGGER_ID)) return /* 触发按钮自己 toggle */
810
+ /* 「更多」自己弹菜单:让菜单按可见位置量锚点,别提前把列表藏起来 */
811
+ if (target.closest('nav[' + MARK + '] [aria-haspopup="menu"]')) return
812
+ open.set(false)
813
+ },
814
+ onEsc: function () { if (open.isOpen()) open.set(false) },
815
+ }
816
+ })()
817
+
818
+ /** 工作区收藏夹:每个分组一枚文件夹按钮 + 各自下拉浮窗。 */
819
+ var workspaces = (function () {
820
+ var ledger = makeLedger(WS_MARK)
821
+ var buttons = new Map() /* 分组 key → 注入的文件夹按钮 */
822
+ var openGroup = null /* 当前展开下拉的分组 key */
823
+ var filterTag = null /* 动态过滤样式:浮窗里只显目标分组的会话 */
824
+ var parent = null
825
+ var open = makeOpenState(WS_OPEN_ATTR, function (isOpen) {
826
+ if (!isOpen) {
827
+ openGroup = null
828
+ if (filterTag) filterTag.textContent = ''
829
+ }
830
+ buttons.forEach(function (btn, key) {
831
+ btn.setAttribute('aria-expanded', isOpen && key === openGroup ? 'true' : 'false')
832
+ })
833
+ })
834
+ /** 原生组头列表(DOM 序):key / 标签 / 组头节点。 */
835
+ function groups(root) {
836
+ var out = []
837
+ var heads = root.querySelectorAll('[data-row-key^="workspace:"]')
838
+ for (var i = 0; i < heads.length; i++) {
839
+ var h = heads[i]
840
+ var key = h.getAttribute('data-row-key').slice('workspace:'.length)
841
+ var text = h.querySelector('[class*="projectText"]')
842
+ out.push({ key: key, label: text ? text.textContent : key, header: h })
843
+ }
844
+ return out
845
+ }
846
+ /** 过滤样式:组头全藏(按钮已带组名),会话行只留目标分组的;
847
+ 搜索结果行是全局搜索,照常显示。规则后写覆盖先写(同特异性)。 */
848
+ function applyFilter(root, key) {
849
+ if (!filterTag) filterTag = styleTag('', WS_FILTER_ID)
850
+ var show = []
851
+ var cur = null
852
+ var rows = root.querySelectorAll('[data-row-key]')
853
+ for (var i = 0; i < rows.length; i++) {
854
+ var rk = rows[i].getAttribute('data-row-key')
855
+ if (rk.indexOf('workspace:') === 0) { cur = rk.slice('workspace:'.length); continue }
856
+ if (cur !== key) continue
857
+ if (rk.indexOf('session:') === 0 || rk === 'overflow:' + key) show.push(rk)
858
+ }
859
+ var css = 'div[' + WS_MARK + '] [data-row-key^="workspace:"]{display:none!important}'
860
+ + 'div[' + WS_MARK + '] [data-row-key^="session:"]{display:none!important}'
861
+ + 'div[' + WS_MARK + '] [data-row-key^="overflow:"]{display:none!important}'
862
+ + 'div[' + WS_MARK + '] [data-row-key="empty"]{display:none!important}'
863
+ + 'div[' + WS_MARK + '] [class*="searchResultRow"]{display:flex!important}'
864
+ for (var j = 0; j < show.length; j++) {
865
+ css += 'div[' + WS_MARK + '] [data-row-key=' + JSON.stringify(show[j]) + ']{display:flex!important}'
866
+ }
867
+ filterTag.textContent = css
868
+ }
869
+ function paintWs(el, left, capH) {
870
+ ledger.adopt(el)
871
+ var clamped = clampLeft(left, WS_WIDTH)
872
+ var s = el.style
873
+ s.position = 'fixed'
874
+ s.top = (capH + WS_ROW_H + 4) + 'px'
875
+ s.left = clamped + 'px'
876
+ s.width = WS_WIDTH + 'px'
877
+ s.zIndex = '1090'
878
+ s.webkitAppRegion = 'no-drag'
879
+ escapeContainment(el, clamped, capH + WS_ROW_H + 4)
880
+ }
881
+ /** 文件夹按钮点击:开/关/切换该分组的下拉,浮窗锚在按钮下方。 */
882
+ function click(key) {
883
+ return function (event) {
884
+ event.preventDefault()
885
+ event.stopPropagation()
886
+ if (open.isOpen() && openGroup === key) { open.set(false); return }
887
+ openGroup = key
888
+ open.set(true) /* 互斥注册表顺带收起「其他」 */
889
+ var root = wsRoot()
890
+ if (!root) { open.set(false); return }
891
+ var head = null
892
+ var heads = root.querySelectorAll('[data-row-key^="workspace:"]')
893
+ for (var i = 0; i < heads.length; i++) {
894
+ if (heads[i].getAttribute('data-row-key') === 'workspace:' + key) { head = heads[i]; break }
895
+ }
896
+ /* 收起的分组原生不挂载会话行:替用户点一下组头展开(状态归 React 管) */
897
+ if (head && head.getAttribute('aria-expanded') === 'false') head.click()
898
+ var btn = buttons.get(key)
899
+ var mr = menubar().getBoundingClientRect()
900
+ paintWs(root, btn ? btn.getBoundingClientRect().left : 0, mr.height || 40)
901
+ applyFilter(root, key)
902
+ }
903
+ }
904
+ function release() { releaseSrc(parent); parent = null }
905
+ function dropButtons() { buttons.forEach(function (btn) { btn.remove() }); buttons.clear() }
906
+ function dropFilter() { if (filterTag) { filterTag.remove(); filterTag = null } }
907
+ return {
908
+ isOpen: open.isOpen,
909
+ pass: function (wsEl, left, capH) {
910
+ if (!wsEl) {
911
+ open.set(false)
912
+ document.documentElement.removeAttribute(WS_ROW_ATTR)
913
+ dropButtons()
914
+ dropFilter()
915
+ ledger.restoreAll()
916
+ /* 原父容器(regionArea)的留白压缩还回去 */
917
+ release()
918
+ return
919
+ }
920
+ /* 侧栏重挂载后旧根会留在账本里:还原它,别留一枚隐藏的 fixed 空盒 */
921
+ ledger.stale(wsEl, WS_ROOT_SEL)
922
+ document.documentElement.setAttribute(WS_ROW_ATTR, '')
923
+ var gs = groups(wsEl)
924
+ /* 搜索态原生树整棵卸载(组头没了):按钮保持上一轮,浮窗里走全局搜索结果 */
925
+ if (!gs.length && wsEl.querySelector('[class*="searchExpanded"]')) {
926
+ var ob = openGroup ? buttons.get(openGroup) : null
927
+ paintWs(wsEl, ob ? parseFloat(ob.style.left) || left : left, capH)
928
+ if (open.isOpen() && openGroup) applyFilter(wsEl, openGroup)
929
+ parent = markSrc(wsEl)
930
+ return
931
+ }
932
+ var seen = new Set()
933
+ var cursor = left
934
+ var anchorLeft = left
935
+ for (var i = 0; i < gs.length; i++) {
936
+ var g = gs[i]
937
+ seen.add(g.key)
938
+ var btn = buttons.get(g.key)
939
+ if (!btn) {
940
+ btn = makeTriggerButton({
941
+ id: WS_BTN_PREFIX + g.key, mark: WS_TRIGGER_MARK, group: g.key, expanded: 'false',
942
+ html: FOLDER_ICON + '<span></span>' + CHEVRON,
943
+ onClick: click(g.key),
944
+ })
945
+ buttons.set(g.key, btn)
946
+ }
947
+ var labelSpan = btn.querySelector('span')
948
+ if (labelSpan && labelSpan.textContent !== g.label) labelSpan.textContent = g.label
949
+ paintTrigger(btn, cursor, capH, capH + (WS_ROW_H - 28) / 2)
950
+ if (openGroup === g.key) anchorLeft = cursor
951
+ cursor += btn.getBoundingClientRect().width + GAP
952
+ }
953
+ buttons.forEach(function (btn, key) {
954
+ if (!seen.has(key)) { btn.remove(); buttons.delete(key) }
955
+ })
956
+ if (openGroup && !seen.has(openGroup)) open.set(false)
957
+ paintWs(wsEl, anchorLeft, capH)
958
+ /* 开着时每次重排都刷新过滤:会话增删/搜索切换/自动展开后的挂载都能跟上 */
959
+ if (open.isOpen() && openGroup) applyFilter(wsEl, openGroup)
960
+ parent = markSrc(wsEl)
961
+ },
962
+ yield: function () {
963
+ open.set(false)
964
+ document.documentElement.removeAttribute(WS_ROW_ATTR)
965
+ dropButtons()
966
+ dropFilter()
967
+ ledger.restoreAll()
968
+ release()
969
+ },
970
+ onClick: function (target) {
971
+ if (!open.isOpen()) return
972
+ if (target.closest('[' + WS_TRIGGER_MARK + ']')) return /* 文件夹按钮自己 toggle */
973
+ var box = target.closest('div[' + WS_MARK + ']')
974
+ if (!box) { open.set(false); return }
975
+ /* 浮窗内:点会话行/搜索结果行 = 打开会话,收起(书签行为);
976
+ 行内操作条(固定/归档/菜单)、组头折叠、搜索、添加、视图选项、
977
+ overflow 加载更多都保持开。 */
978
+ if (target.closest('[class*="rowActions"]')) return
979
+ if (target.closest('[data-row-key^="session:"]') || target.closest('[class*="searchResultRow"]')) open.set(false)
980
+ },
981
+ onEsc: function (target) {
982
+ if (!open.isOpen()) return
983
+ /* 搜索展开时 Esc 先交给原生输入框收搜索,第二次才收浮窗 */
984
+ if (target instanceof Element && target.closest('div[' + WS_MARK + '] [class*="searchExpanded"]')) return
985
+ open.set(false)
986
+ },
987
+ }
988
+ })()
989
+
990
+ /** 「更多」收拢(展开态):标题栏左起一枚按钮,点开统一浮窗,自上而下
991
+ 新会话 / 折叠侧栏 / 应用·编辑 / 账户·设备 / 面板列表。菜单栏 host 与
992
+ 底部入口行整块 fixed 进浮窗(弹出菜单按可见位置量锚点,行为不变);
993
+ 新会话/折叠侧栏是注入行,程序点真按钮。鲸鱼/侧栏开关本体藏起。 */
994
+ var more = (function () {
995
+ var ledger = makeLedger(MORE_ITEM_MARK)
996
+ var trigger = null
997
+ var panel = null
998
+ var rowNew = null
999
+ var rowSidebar = null
1000
+ var parents = []
1001
+ var open = makeOpenState(MORE_OPEN_ATTR, function (isOpen) {
1002
+ if (trigger) trigger.setAttribute('aria-expanded', isOpen ? 'true' : 'false')
1003
+ })
1004
+ function ensureTrigger() {
1005
+ if (trigger && trigger.isConnected) return trigger
1006
+ var btn = document.getElementById(MORE_TRIGGER_ID)
1007
+ if (!btn) {
1008
+ btn = makeTriggerButton({
1009
+ id: MORE_TRIGGER_ID, mark: TRIGGER_MARK,
1010
+ html: '<span>' + MORE_LABEL + '</span>' + CHEVRON,
1011
+ onClick: function (event) {
1012
+ event.preventDefault()
1013
+ event.stopPropagation()
1014
+ open.set(!open.isOpen())
1015
+ },
1016
+ })
1017
+ }
1018
+ trigger = btn
1019
+ if (btn.getAttribute('aria-expanded') === null) btn.setAttribute('aria-expanded', open.isOpen() ? 'true' : 'false')
1020
+ return btn
1021
+ }
1022
+ /** 宿主所在的堆叠上下文祖先:背板必须挂进同一上下文,
1023
+ 否则宿主的 z1150 被侧栏 fixed 上下文困住,背板(z1140)反盖住宿主、抢点击。 */
1024
+ function stackAnchor(el) {
1025
+ var n = el && el.parentElement
1026
+ while (n && n !== document.body && n !== document.documentElement) {
1027
+ var cs = getComputedStyle(n)
1028
+ if (cs.position === 'fixed' || cs.position === 'sticky' ||
1029
+ ((cs.position === 'absolute' || cs.position === 'relative') && cs.zIndex !== 'auto') ||
1030
+ cs.transform !== 'none' || cs.filter !== 'none' || cs.opacity !== '1' ||
1031
+ cs.containerType !== 'normal' || cs.isolation === 'isolate' ||
1032
+ cs.mixBlendMode !== 'normal' || /transform|filter|opacity|container/.test(cs.willChange)) return n
1033
+ n = n.parentElement
1034
+ }
1035
+ return document.body
1036
+ }
1037
+ function ensurePanel(anchor) {
1038
+ if (panel && panel.isConnected) {
1039
+ if (anchor && panel.parentElement !== anchor) anchor.appendChild(panel)
1040
+ return panel
1041
+ }
1042
+ panel = document.createElement('div')
1043
+ panel.setAttribute(MORE_PANEL_MARK, '')
1044
+ rowNew = document.createElement('button')
1045
+ rowNew.type = 'button'
1046
+ rowNew.setAttribute(MORE_ROW_MARK, '')
1047
+ rowNew.innerHTML = PLUS_ICON + '<span>新会话</span>'
1048
+ rowNew.addEventListener('click', function (event) {
1049
+ event.preventDefault()
1050
+ var ns = document.querySelector(NS_BTN)
1051
+ if (ns) ns.click()
1052
+ open.set(false)
1053
+ })
1054
+ rowSidebar = document.createElement('button')
1055
+ rowSidebar.type = 'button'
1056
+ rowSidebar.setAttribute(MORE_ROW_MARK, '')
1057
+ rowSidebar.innerHTML = SIDEBAR_ICON + '<span>折叠侧栏</span>'
1058
+ rowSidebar.addEventListener('click', function (event) {
1059
+ event.preventDefault()
1060
+ var tg = document.querySelector('[data-sidebar-toggle]')
1061
+ if (tg) tg.click()
1062
+ open.set(false)
1063
+ })
1064
+ panel.appendChild(rowNew)
1065
+ panel.appendChild(rowSidebar)
1066
+ ;(anchor || document.body).appendChild(panel)
1067
+ return panel
1068
+ }
1069
+ /** 只摆位置(不记账):注入行 / 背板用。 */
1070
+ function box(el, left, top, width, height) {
1071
+ var s = el.style
1072
+ s.position = 'fixed'
1073
+ s.top = top + 'px'
1074
+ s.left = left + 'px'
1075
+ s.width = width + 'px'
1076
+ if (height != null) s.height = height + 'px'
1077
+ s.margin = '0'
1078
+ s.zIndex = '1090'
1079
+ s.webkitAppRegion = 'no-drag'
1080
+ }
1081
+ /** 宿主节点:记账 + 摆位 + 破容器隔离。 */
1082
+ function place(el, left, top, width, height) {
1083
+ ledger.adopt(el)
1084
+ box(el, left, top, width, height)
1085
+ escapeContainment(el, left, top)
1086
+ }
1087
+ function hideEl(el) {
1088
+ if (!el || !el.isConnected) return
1089
+ ledger.adopt(el)
1090
+ el.style.display = 'none'
1091
+ }
1092
+ function releaseParents() {
1093
+ for (var i = 0; i < parents.length; i++) releaseSrc(parents[i])
1094
+ parents = []
1095
+ }
1096
+ return {
1097
+ owns: function (el) { return ledger.has(el) },
1098
+ isOpen: open.isOpen,
1099
+ pass: function (targets, navEl, capH) {
1100
+ var btn = ensureTrigger()
1101
+ paintTrigger(btn, MORE_LEFT, capH)
1102
+ var pnl = ensurePanel(stackAnchor(navEl || targets[0] || menubar()))
1103
+ var panelLeft = clampLeft(MORE_LEFT, MORE_WIDTH)
1104
+ var panelTop = capH + 4
1105
+ var innerLeft = panelLeft + MORE_PAD
1106
+ var innerWidth = MORE_WIDTH - 2 * MORE_PAD
1107
+ /* 本轮要收进浮窗/藏起的宿主节点清单:reconcile 还原重挂载残留 */
1108
+ var whale = document.querySelector(BRAND_SEL)
1109
+ var toggle = document.querySelector('[data-sidebar-toggle]')
1110
+ var mb = menubar()
1111
+ var keep = []
1112
+ if (whale) keep.push(whale)
1113
+ if (toggle) keep.push(toggle)
1114
+ if (mb) keep.push(mb)
1115
+ for (var k = 0; k < targets.length; k++) keep.push(targets[k])
1116
+ if (navEl) keep.push(navEl)
1117
+ ledger.reconcile(keep)
1118
+ /* 鲸鱼 / 侧栏开关本体藏起(入口改由浮窗注入行提供) */
1119
+ hideEl(whale)
1120
+ hideEl(toggle)
1121
+ var y = panelTop + MORE_PAD
1122
+ /* ① 新会话 ② 折叠侧栏(注入行) */
1123
+ box(rowNew, innerLeft, y, innerWidth, MORE_ROW_H); y += MORE_ROW_H + MORE_GAP
1124
+ box(rowSidebar, innerLeft, y, innerWidth, MORE_ROW_H); y += MORE_ROW_H + MORE_GAP
1125
+ /* ③ 应用/编辑菜单栏 host:height 保持 capH,编排器量 capH 不漂移 */
1126
+ if (mb) { place(mb, innerLeft, y, innerWidth, capH); y += capH + MORE_GAP }
1127
+ /* ④ 底部入口行(Maple 账户 + 手机/电脑):横排,overflow 放行弹出菜单 */
1128
+ var seatsTop = y
1129
+ var sx = innerLeft
1130
+ for (var i = 0; i < targets.length; i++) {
1131
+ var el = targets[i]
1132
+ ledger.adopt(el)
1133
+ el.setAttribute(MORE_SEATS_MARK, '')
1134
+ var s = el.style
1135
+ s.position = 'fixed'
1136
+ s.top = seatsTop + 'px'
1137
+ s.left = sx + 'px'
1138
+ s.height = MORE_SEATS_H + 'px'
1139
+ s.width = 'auto'
1140
+ s.maxWidth = 'none'
1141
+ s.margin = '0'
1142
+ s.padding = '0 2px'
1143
+ s.zIndex = '1090'
1144
+ s.background = 'transparent'
1145
+ s.border = '0'
1146
+ s.boxShadow = 'none'
1147
+ s.transform = 'none'
1148
+ s.overflow = 'visible'
1149
+ s.flex = 'none'
1150
+ s.webkitAppRegion = 'no-drag'
1151
+ var p = markSrc(el)
1152
+ if (p && parents.indexOf(p) === -1) parents.push(p)
1153
+ escapeContainment(el, sx, seatsTop)
1154
+ sx += el.getBoundingClientRect().width + MORE_GAP
1155
+ }
1156
+ /* 浮窗宽度跟随底部入口行自适应(上限 320),保证第④行不撑出框外 */
1157
+ var seatsInner = sx - MORE_GAP - innerLeft
1158
+ if (seatsInner > innerWidth) innerWidth = Math.min(seatsInner, 308)
1159
+ if (targets.length === 1) targets[0].style.width = innerWidth + 'px'
1160
+ var panelWidth = innerWidth + 2 * MORE_PAD
1161
+ y = seatsTop + MORE_SEATS_H + MORE_GAP
1162
+ /* ⑤ 面板列表:去自身表面(背板统一提供),保留滚动 */
1163
+ if (navEl) {
1164
+ place(navEl, innerLeft, y, innerWidth, null)
1165
+ y += navEl.offsetHeight
1166
+ }
1167
+ /* 背板尺寸贴合内容 */
1168
+ pnl.style.position = 'fixed'
1169
+ pnl.style.top = panelTop + 'px'
1170
+ pnl.style.left = panelLeft + 'px'
1171
+ pnl.style.width = panelWidth + 'px'
1172
+ pnl.style.height = (y - panelTop + MORE_PAD) + 'px'
1173
+ pnl.style.zIndex = '1088'
1174
+ pnl.style.webkitAppRegion = 'no-drag'
1175
+ escapeContainment(pnl, panelLeft, panelTop)
1176
+ return MORE_LEFT + btn.getBoundingClientRect().width + GAP
1177
+ },
1178
+ yield: function () {
1179
+ if (trigger) { trigger.remove(); trigger = null }
1180
+ if (panel) { panel.remove(); panel = null; rowNew = null; rowSidebar = null }
1181
+ open.clear()
1182
+ ledger.restoreAll()
1183
+ var seatsEls = document.querySelectorAll('[' + MORE_SEATS_MARK + ']')
1184
+ for (var i = 0; i < seatsEls.length; i++) seatsEls[i].removeAttribute(MORE_SEATS_MARK)
1185
+ releaseParents()
1186
+ },
1187
+ onClick: function (target) {
1188
+ if (!open.isOpen()) return
1189
+ if (target.closest('#' + MORE_TRIGGER_ID)) return /* 触发按钮自己 toggle */
1190
+ if (target.closest('[data-windows-menu]')) return /* 应用/编辑弹原生菜单,保持开 */
1191
+ if (target.closest('[' + MORE_ITEM_MARK + ']')) {
1192
+ /* 面板列表:选中行收起;「更多」菜单锚点保持开。账户/设备保持开。 */
1193
+ if (target.closest('nav[' + MORE_ITEM_MARK + ']')) {
1194
+ if (target.closest('[aria-haspopup="menu"]')) return
1195
+ open.set(false)
1196
+ }
1197
+ return
1198
+ }
1199
+ if (target.closest('[' + MORE_PANEL_MARK + ']')) return /* 注入行自行收起 */
1200
+ open.set(false)
1201
+ },
1202
+ onEsc: function () { if (open.isOpen()) open.set(false) },
1203
+ }
1204
+ })()
1205
+
1206
+ dropdownFeatures.push(others, workspaces, more)
1207
+
1208
+ /* ── 探针:本轮哪些区域归我们管 ───────────────────────────── */
1209
+
1210
+ function seatHosts() {
1211
+ var out = []
1212
+ for (var i = 0; i < SEATS.length; i++) {
1213
+ var host = document.querySelector('[data-slot="' + SEATS[i] + '"]')
1214
+ if (host) out.push(host)
1215
+ }
1216
+ return out
1217
+ }
1218
+ /** 面板列表本轮是否归我们管;null = 不搬(drawer / 已卸载)。 */
1219
+ function panelNav() {
1220
+ var el = document.querySelector(NAV_SEL)
1221
+ if (!el || !el.isConnected) return null
1222
+ /* drawer 是把侧栏当浮层:面板列表留在抽屉里照常使用 */
1223
+ if (drawer()) return null
1224
+ return el
1225
+ }
1226
+ /** 工作区区域本轮是否归我们管;null = 不搬。
1227
+ 折叠态 WorkspaceBrowser 走 rail(列表内容卸载),drawer 留在抽屉里——都交还原生。 */
1228
+ function wsRoot() {
1229
+ var el = document.querySelector(WS_ROOT_SEL)
1230
+ if (!el || !el.isConnected) return null
1231
+ if (drawer() || collapsed()) return null
1232
+ return el
1233
+ }
1234
+ /** 最近公共祖先行 + 护栏;取不到合法行返回 null(调用方退化为逐席位)。 */
1235
+ function findRow(hosts) {
1236
+ if (hosts.length < 2) return null
1237
+ var node = hosts[0].parentElement
1238
+ while (node && node !== document.body) {
1239
+ var all = true
1240
+ for (var i = 0; i < hosts.length; i++) if (!node.contains(hosts[i])) { all = false; break }
1241
+ if (all) break
1242
+ node = node.parentElement
1243
+ }
1244
+ if (!node || node === document.body || node === document.documentElement) return null
1245
+ if (node.querySelector('textarea,[data-slot="conversation.composer.bar"],[data-slot="sidebar.panellist"],[data-slot="sidebar.workspaces"],[data-slot="sidebar.session.action"],[data-windows-menu]')) return null
1246
+ if (node.hasAttribute('data-shell-bottom')) return null
1247
+ var rect = node.getBoundingClientRect()
1248
+ if (rect.height === 0) return null /* 祖先 display:none:本轮不映射 */
1249
+ if (rect.height > ROW_MAX_HEIGHT) return null
1250
+ return node
1251
+ }
1252
+
1253
+ /* ── 编排器 ───────────────────────────────────────────────── */
1254
+
1255
+ /** 让位/卸载:各特性还原自己的账本与按钮,再清共享的父级收零/容器隔离。 */
1256
+ function yieldAll() {
1257
+ brand.yield()
1258
+ newSession.yield()
1259
+ seats.yield()
1260
+ others.yield()
1261
+ more.yield()
1262
+ extraSlot.yield()
1263
+ workspaces.yield()
1264
+ markedParents.forEach(function (p) { p.removeAttribute(SRC_MARK) })
1265
+ markedParents.clear()
1266
+ uncontained.forEach(function (value, el) { el.style.containerType = value })
1267
+ uncontained.clear()
1268
+ }
1269
+ function pass() {
1270
+ timer = 0
1271
+ if (!active()) { yieldAll(); lastMode = ''; return }
1272
+ var hosts = seatHosts()
1273
+ var navEl = panelNav()
1274
+ var wsEl = wsRoot()
1275
+ if (!hosts.length && !navEl && !wsEl) { yieldAll(); lastMode = ''; return }
1276
+ var row = findRow(hosts)
1277
+ var targets = row ? [row] : hosts
1278
+ var mode = row ? 'row' : 'seats'
1279
+ /* 展开态走「更多」收拢;折叠/drawer 交还原布局 */
1280
+ var moreMode = !drawer() && !collapsed()
1281
+ /* 祖先隐藏(drawer 收起等)时整轮不映射,避免悬空 fixed 空盒 */
1282
+ if (targets.length && targets[0].getBoundingClientRect().width === 0 && !seats.owns(targets[0]) && !more.owns(targets[0]) && !navEl && !wsEl) {
1283
+ yieldAll(); lastMode = ''; return
1284
+ }
1285
+ var mr = menubar().getBoundingClientRect()
1286
+ var capH = mr.height || 40
1287
+ var cursor
1288
+ if (moreMode) {
1289
+ /* 「更多」接管鲸鱼/底部入口行/面板列表/菜单栏;让位特性幂等还原 */
1290
+ brand.yield()
1291
+ seats.yield()
1292
+ others.yield()
1293
+ newSession.pass()
1294
+ cursor = more.pass(targets, navEl, capH)
1295
+ } else {
1296
+ more.yield()
1297
+ brand.pass()
1298
+ newSession.pass()
1299
+ cursor = mr.right + GAP
1300
+ cursor = seats.pass(targets, cursor, capH)
1301
+ /* 「其他」接在底部入口行右侧(第一行);预留栏位再接「其他」右侧;
1302
+ 文件夹按钮独占第二行,从窗左起排 */
1303
+ cursor = others.pass(navEl, cursor, capH)
1304
+ }
1305
+ if (navEl) extraSlot.pass(cursor, capH)
1306
+ else extraSlot.yield()
1307
+ workspaces.pass(wsEl, WS_ROW_LEFT, capH)
1308
+ if (mode !== lastMode) {
1309
+ lastMode = mode
1310
+ console.info('[caption-map] 底部入口行已映射到标题栏(' + mode + ' 模式,' + targets.length + ' 个容器)')
1311
+ }
1312
+ }
1313
+ function schedule() {
1314
+ if (timer) return
1315
+ timer = setTimeout(pass, 120)
1316
+ }
1317
+
1318
+ /* 点空白处 / Esc 收起下拉;点行本身让 React 先跑完选择再收。
1319
+ 冒泡阶段:先让 React 的 selectPanel/菜单跑完,再收起,避免点在悬空节点上。 */
1320
+ function onClick(event) {
1321
+ var target = event.target
1322
+ if (!(target instanceof Element)) {
1323
+ for (var i = 0; i < dropdowns.length; i++) dropdowns[i].set(false)
1324
+ return
1325
+ }
1326
+ for (var j = 0; j < dropdownFeatures.length; j++) dropdownFeatures[j].onClick(target)
1327
+ }
1328
+ function onKeydown(event) {
1329
+ if (event.key !== 'Escape') return
1330
+ for (var i = 0; i < dropdownFeatures.length; i++) dropdownFeatures[i].onEsc(event.target)
1331
+ }
1332
+ document.addEventListener('click', onClick)
1333
+ document.addEventListener('keydown', onKeydown, true)
1334
+
1335
+ var mo = new MutationObserver(schedule)
1336
+ /* 不观察 style:自己的内联写入会触发死循环;class 变化覆盖侧栏折叠/路由 */
1337
+ mo.observe(document.body, {
1338
+ childList: true, subtree: true, characterData: true,
1339
+ attributes: true, attributeFilter: ['class', 'data-slot', 'data-windows-titlebar', 'data-sidebar-drawer', 'data-sidebar-collapsed'],
1340
+ })
1341
+ var ro = typeof ResizeObserver === 'function' ? new ResizeObserver(schedule) : null
1342
+ var mb = menubar()
1343
+ if (ro && mb) ro.observe(mb)
1344
+ window.addEventListener('resize', schedule)
1345
+ pass()
1346
+
1347
+ return function () {
1348
+ if (timer) clearTimeout(timer)
1349
+ mo.disconnect()
1350
+ if (ro) ro.disconnect()
1351
+ window.removeEventListener('resize', schedule)
1352
+ document.removeEventListener('click', onClick)
1353
+ document.removeEventListener('keydown', onKeydown, true)
1354
+ yieldAll()
1355
+ tag.remove()
1356
+ }
1357
+ }, 'caption-map: region map')
1358
+
1359
+ /* 侧栏宽度固定:config.fixedSidebarWidth(默认开)。宽度锁到外壳拖拽
1360
+ * 上限(dsh-client-ui-layout columns.ts SIDEBAR_MAX = 420),拖拽手柄藏掉。
1361
+ *
1362
+ * 做法不跟 React 抢内联样式:frame 的 gridTemplateColumns /
1363
+ * --dsh-windows-sidebar-width 由外壳每次渲染重写,直接改写会在折叠/
1364
+ * 卸载时留下脏值。这里只用 CSS !important 覆盖首轨与变量,其余两轨
1365
+ * (center/rightbar,随右栏开合动态变化)由 observer 从外壳内联值里
1366
+ * 镜像成 frame 上的两枚 CSS 变量供 !important 规则引用——外壳从不写
1367
+ * 这两枚变量,无死循环、无还原冲突。卸载 = 摘属性/变量/样式表,外壳
1368
+ * 内联值立即重新生效。
1369
+ *
1370
+ * 门控:折叠(rail/全隐)、drawer(浮层)、折叠屏横屏居中侧栏都不插手,
1371
+ * 交还原外壳布局。 */
1372
+ ctx.effect(function () {
1373
+ if (IS_DARWIN) return function () {} /* darwin 固定侧栏由 caption-map-macos 接管 */
1374
+ var opts = window.__DSH_CAPTION_MAP__ || {}
1375
+ if (opts.fixedSidebarWidth === false) return function () {}
1376
+
1377
+ var FIXED_ATTR = 'data-capyclaw-fixed-sidebar'
1378
+ /** 外壳 columns.ts SIDEBAR_MAX:拖拽能拉到的最宽值。 */
1379
+ var FIXED_WIDTH = 420
1380
+ var VAR_CENTER = '--capyclaw-cm-center'
1381
+ var VAR_RIGHT = '--capyclaw-cm-right'
1382
+ var FIXED_CSS = [
1383
+ /* 首轨锁死 420;其余两轨引用镜像变量(缺省兜底右栏关闭形态)。 */
1384
+ 'html[' + FIXED_ATTR + '] div:has(> [data-shell-bottom]){',
1385
+ 'grid-template-columns:' + FIXED_WIDTH + 'px var(' + VAR_CENTER + ',minmax(0px,1fr)) var(' + VAR_RIGHT + ',minmax(0px,0px))!important;',
1386
+ '--dsh-windows-sidebar-width:' + FIXED_WIDTH + 'px!important}',
1387
+ /* 侧栏根节点内联 width 是外壳存的偏好值:撑满被锁定的列宽。
1388
+ 新版外壳在列与根之间包了一层 display:contents 的插槽 host
1389
+ (div[data-slot="sidebar"]),`> *` 会打在无盒子的 host 上失效,
1390
+ 故两条选择器并存:旧壳直接子级、新壳经 host 取 occupant。 */
1391
+ 'html[' + FIXED_ATTR + '] div:has(> [data-shell-bottom]) > div[class*="sidebarCol"] > *,',
1392
+ 'html[' + FIXED_ATTR + '] div:has(> [data-shell-bottom]) > div[class*="sidebarCol"] [data-slot="sidebar"] > *{width:100%!important}',
1393
+ /* 拖拽手柄:宽度固定后不再提供调整入口。 */
1394
+ 'html[' + FIXED_ATTR + '] div:has(> [data-shell-bottom]) > div[data-side="sidebar"]{display:none!important}',
1395
+ ].join('')
1396
+
1397
+ var tag = styleTag(FIXED_CSS)
1398
+
1399
+ var frame = null
1400
+ var moFrame = null
1401
+ var folded = typeof window.matchMedia === 'function'
1402
+ ? window.matchMedia('(device-posture: folded) and (orientation: landscape)')
1403
+ : null
1404
+
1405
+ /** 按顶层空格切 grid 轨道(minmax(...) 内部的空格不切)。 */
1406
+ function splitTracks(value) {
1407
+ var out = []
1408
+ var depth = 0
1409
+ var cur = ''
1410
+ for (var i = 0; i < value.length; i++) {
1411
+ var ch = value.charAt(i)
1412
+ if (ch === '(') depth++
1413
+ else if (ch === ')') depth--
1414
+ if (ch === ' ' && depth === 0) {
1415
+ if (cur) { out.push(cur); cur = '' }
1416
+ continue
1417
+ }
1418
+ cur += ch
1419
+ }
1420
+ if (cur) out.push(cur)
1421
+ return out
1422
+ }
1423
+ function setVar(el, name, value) {
1424
+ /* 等值守卫:自己的写入触发 observer 时一拍收敛,不死循环。 */
1425
+ if (el.style.getPropertyValue(name) !== value) el.style.setProperty(name, value)
1426
+ }
1427
+ function clearVars(el) {
1428
+ el.style.removeProperty(VAR_CENTER)
1429
+ el.style.removeProperty(VAR_RIGHT)
1430
+ }
1431
+ /** 本轮是否归我们管;null = 折叠/drawer/居中侧栏/ frame 不在场。 */
1432
+ function target() {
1433
+ var bottom = document.querySelector('[data-shell-bottom]')
1434
+ var f = bottom && bottom.parentElement
1435
+ if (!f || !f.isConnected) return null
1436
+ if (f.hasAttribute('data-sidebar-collapsed')) return null
1437
+ if (f.hasAttribute('data-sidebar-drawer')) return null
1438
+ if (folded && folded.matches && f.getBoundingClientRect().width >= 768) return null
1439
+ return f
1440
+ }
1441
+ function watch(f) {
1442
+ if (moFrame) { moFrame.disconnect(); moFrame = null }
1443
+ if (!f) return
1444
+ /* 盯外壳自己的写入:gtc 重写(store 变化)与折叠/drawer 属性。 */
1445
+ moFrame = new MutationObserver(pass)
1446
+ moFrame.observe(f, { attributes: true, attributeFilter: ['style', 'data-sidebar-collapsed', 'data-sidebar-drawer'] })
1447
+ }
1448
+ function pass() {
1449
+ var f = target()
1450
+ if (f && f !== frame) {
1451
+ if (frame) clearVars(frame)
1452
+ frame = f
1453
+ watch(f)
1454
+ }
1455
+ if (!f) {
1456
+ /* 让位:摘开关、清变量。frame 的 observer 留着——再展开时它先知道。 */
1457
+ document.documentElement.removeAttribute(FIXED_ATTR)
1458
+ if (frame) clearVars(frame)
1459
+ return
1460
+ }
1461
+ var tracks = splitTracks(f.style.gridTemplateColumns || '')
1462
+ if (tracks.length >= 3) {
1463
+ setVar(f, VAR_CENTER, tracks[1])
1464
+ setVar(f, VAR_RIGHT, tracks[2])
1465
+ }
1466
+ document.documentElement.setAttribute(FIXED_ATTR, '')
1467
+ }
1468
+
1469
+ /* frame 挂载/重建(childList);observer 回调同步跑完,先于绘制不闪。 */
1470
+ var moBody = new MutationObserver(pass)
1471
+ moBody.observe(document.body, { childList: true, subtree: true })
1472
+ if (folded) {
1473
+ if (typeof folded.addEventListener === 'function') folded.addEventListener('change', pass)
1474
+ else if (typeof folded.addListener === 'function') folded.addListener(pass)
1475
+ }
1476
+ window.addEventListener('resize', pass)
1477
+ pass()
1478
+
1479
+ return function () {
1480
+ moBody.disconnect()
1481
+ if (moFrame) moFrame.disconnect()
1482
+ if (folded) {
1483
+ if (typeof folded.removeEventListener === 'function') folded.removeEventListener('change', pass)
1484
+ else if (typeof folded.removeListener === 'function') folded.removeListener(pass)
1485
+ }
1486
+ window.removeEventListener('resize', pass)
1487
+ document.documentElement.removeAttribute(FIXED_ATTR)
1488
+ if (frame) clearVars(frame)
1489
+ frame = null
1490
+ tag.remove()
1491
+ }
1492
+ }, 'caption-map: fixed sidebar')
1493
+
1494
+ /* 聊天窗停靠:包内分块按需加载,与标题栏映射互不依赖(跨平台常驻)。
1495
+ * 独立一条 effect 管它的生命周期:分块还没到就卸载时,回来也不能再装。 */
1496
+ ctx.effect(function () {
1497
+ if (IS_DARWIN) return function () {} /* darwin 聊天停靠由 caption-map-macos 接管 */
1498
+ var dead = false
1499
+ var dock = null
1500
+ if (typeof require === 'function' && typeof require.async === 'function') {
1501
+ require.async('./client.chat.js').then(function (part) {
1502
+ if (dead || !part || typeof part.install !== 'function') return
1503
+ dock = part.install(ctx)
1504
+ }, function (error) {
1505
+ console.warn('[caption-map] 聊天窗停靠加载失败:', error && error.message)
1506
+ })
1507
+ }
1508
+ return function () {
1509
+ dead = true
1510
+ if (typeof dock === 'function') {
1511
+ try { dock() } catch (error) { /* 单个收尾出错不影响别的 */ }
1512
+ }
1513
+ dock = null
1514
+ }
1515
+ }, 'caption-map: chat dock')
1516
+ },
1517
+ }
1518
+ },
1519
+ })