@capyclaw/caption-map 0.3.1 → 0.4.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/README.md +34 -7
- package/client/client.chat.js +146 -1
- package/client/client.js +81 -24
- package/index.js +1 -1
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +3 -1
- package/node_modules/@capyclaw/foundation/abi/index.mjs +15 -0
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +21 -4
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +5 -1
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +5 -2
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +4 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +13 -3
- package/node_modules/@capyclaw/plugin-kit/package.json +2 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +5 -2
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +13 -5
- package/node_modules/@capyclaw/window-kit/client/client.js +160 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -15,6 +15,30 @@
|
|
|
15
15
|
下方画面整体挤下去),每枚点开是只显该组会话的独立下拉浮窗。区域级映射:占用方代码
|
|
16
16
|
零改动,未来注册进底部席位或面板列表的项自动跟随。
|
|
17
17
|
|
|
18
|
+
## 跨平台(macOS 适配,单一真源)
|
|
19
|
+
|
|
20
|
+
本包是单一真源:Windows 与 macOS 共用同一套区域映射 / 挂载锚 / 固定侧栏 / 聊天窗停靠
|
|
21
|
+
代码,只在两系统真正不兼容的少数处分流,靠 `html[data-platform]`(preload 先于页面
|
|
22
|
+
脚本钉死,工厂作用域算一次 `IS_DARWIN`)判定:
|
|
23
|
+
|
|
24
|
+
- **标题栏壳(仅 darwin 的 effect)**:macOS 宿主没有原生 `windows-titlebar`。壳给
|
|
25
|
+
`<html>` 设 `data-windows-titlebar` + `--dsh-windows-titlebar-height:40px`,注入一枚
|
|
26
|
+
零宽假 `[data-windows-menu]`(带 `data-capyclaw-macos-fake-menu` 标记,不参与排布),
|
|
27
|
+
并注入 `SHELL_CSS` 藏 topStrip / 侧栏开关、logoRow 收零、frame 顶部刷标题栏底色。
|
|
28
|
+
此后区域映射 `active()` 与聊天停靠 `FILL_SEL` 两平台共用同一套门控——不为 darwin
|
|
29
|
+
另写一套选择器。拆卸还原属性 / 变量 / 假菜单 / owner。
|
|
30
|
+
- **几何常量**:`CAPTION_RIGHT_RESERVE` win 150px(原生 min/max/close 预留)/ darwin 12px
|
|
31
|
+
(无系统按钮预留);`MORE_LEFT` win 12px / darwin 80px(避开左上角红绿灯)。
|
|
32
|
+
- **预留栏位**:win 占用态是拉伸盒(`right` 钉预留区左缘 + 限宽 + mount 均分),darwin
|
|
33
|
+
自撑(`max-width:none`、mount `max-width:46vw`),槽整体 `-webkit-app-region:no-drag`。
|
|
34
|
+
- **让位**:darwin drawer / 折叠态整块让位给宿主原生前导座(侧栏是浮层或 0 宽轨);win
|
|
35
|
+
折叠态仍由本包在标题栏摆 brand+others+seats。聊天停靠 darwin 折叠态把面板搬回原父并
|
|
36
|
+
撤槽(否则整块看不见)、首装无会话时兜底搬欢迎页整块;win 不做这两搬(行为不变)。
|
|
37
|
+
- **聊天窗底座**:优先外部 `@capyclaw/window-kit`;macOS 缺失时回退包内内联最小面(同判据)。
|
|
38
|
+
|
|
39
|
+
旧的独立 `@capyclaw/caption-map-macos` 已并入本包并废弃(保留空壳避免老配置报错);
|
|
40
|
+
darwin 上由本包直接接管,无需再单独启用 macos 包。
|
|
41
|
+
|
|
18
42
|
## 为什么不是插槽镜像
|
|
19
43
|
|
|
20
44
|
顶栏那一行**没有可注入的 web 插槽**:
|
|
@@ -86,8 +110,9 @@ DOM 节点**——React 仍拥有这些节点;席位内未来新增注册项
|
|
|
86
110
|
`require.async('./client.chat.js')` 按需加载(模块系统支持
|
|
87
111
|
`chunk: 'client.chat.js'` 的包内分块,服务端 `/plugins/<id>/<file>` 现取);
|
|
88
112
|
- 拆卸:整段挂在 `WINDOW_KIT.effect(ctx, 'caption-map: 聊天窗停靠', mount)` 上,
|
|
89
|
-
停用插件即搬回原位、删槽、撤监听、摘 `<style
|
|
90
|
-
|
|
113
|
+
停用插件即搬回原位、删槽、撤监听、摘 `<style>`。优先外部 `@capyclaw/window-kit`;
|
|
114
|
+
缺失时(macOS boot graph 不含它)回退包内内联最小面(同判据),不再整半缺席;
|
|
115
|
+
标题栏映射不依赖 window-kit,照常。
|
|
91
116
|
|
|
92
117
|
老的 `@capyclaw/chat-dock` 做的是同一件事,但带了一套自己的窗口/停靠/动画机制。
|
|
93
118
|
它现在见到 `window.__CAPYCLAW_CHAT_DOCK_OWNER__` 就让位(`apply` 直接返回 null),
|
|
@@ -218,8 +243,10 @@ toggleSidebar 等,没有 setSidebar;而外壳的内联 `grid-template-column
|
|
|
218
243
|
|
|
219
244
|
## 行为与护栏
|
|
220
245
|
|
|
221
|
-
- 仅 `html[data-windows-titlebar]` 且 menubar 在场时生效;纯 web
|
|
222
|
-
|
|
246
|
+
- 仅 `html[data-windows-titlebar]` 且 menubar 在场时生效;纯 web no-op,底部保持原样。
|
|
247
|
+
macOS 无原生 windows-titlebar,由本包「标题栏壳」effect 先把宿主归一成同形(设属性 +
|
|
248
|
+
40px 高度变量 + 注入零宽假 menubar),同一套门控随之生效(见「跨平台」节)。
|
|
249
|
+
禁用插件即逐字还原内联样式。
|
|
223
250
|
- 公共祖先护栏:若祖先行装进了会话列表 / 面板列表 / 输入框 / menubar(说明两席位
|
|
224
251
|
不在同一行),放弃整行映射,退化为**逐席位映射**(手机/电脑仍上顶栏),
|
|
225
252
|
绝不把整条侧栏搬走。
|
|
@@ -286,8 +313,8 @@ renderSlot 统一带上,无需占用方配合。
|
|
|
286
313
|
不占服务;吞 `E_DUP_PLUGIN` 保证 bundle 重复启用幂等。
|
|
287
314
|
- `options.mjs`:两半共享的设定面——`BOOT_GLOBAL`、`DEFAULTS`、`normalizeConfig`。
|
|
288
315
|
新设定键加在这里,宿主/浏览器/测试三方共用同一份收敛逻辑。
|
|
289
|
-
- `client/client.js
|
|
290
|
-
|
|
316
|
+
- `client/client.js`:浏览器半入口,四条 `ctx.effect`:标题栏壳(仅 darwin,把宿主归一成
|
|
317
|
+
windows-titlebar 形态)、标题栏映射(纯 CSS、卸载还原)、侧栏宽度固定(CSS 覆盖 + 镜像变量,见上节)、聊天窗停靠的加载器
|
|
291
318
|
(`require.async('./client.chat.js')`,卸载时先置 `dead` 再调子半的 disposer)。
|
|
292
319
|
标题栏映射 effect 内部 = 共享底座(门控 / 样式账本 / SRC_MARK 记账 /
|
|
293
320
|
容器隔离兜底 / 触发按钮工厂 / 开合互斥注册表)+ 六个特性模块
|
|
@@ -316,7 +343,7 @@ renderSlot 统一带上,无需占用方配合。
|
|
|
316
343
|
预留栏位挂载锚契约(acquire 交 mount/隐占位/去虚线、release 对称还原、卸载 unprovide)、
|
|
317
344
|
多租约可拓展(第二消费者独立 mount 共存/按序横排/同键幂等/单独 release 不影响他人/全释放回占位)、
|
|
318
345
|
**三插件链路集成**(真源同沙箱装配 caption-map 锚 + session-keeper 服务 + session-tabs 薄 UI:
|
|
319
|
-
标签挂进真实 mount
|
|
346
|
+
标签挂进真实 mount、规则先行(心跳不自动纳入,仅 manage 合法来源加入并落盘 v4);门控循环 8 次 mount/React 根收支平衡、单 mount、
|
|
320
347
|
样式不泄漏、卸载后无僵尸根;命名租约共存与交接;全卸载清空注册表/释放 retain 后重新装配仍工作),
|
|
321
348
|
假 DOM 带最小选择器引擎(`:has` / 属性前缀 / 类包含 / 后代与子组合)与带 hook deps 比较的 React stub。
|
|
322
349
|
- `cordis.patch.yml`:一行插件本体 + `fixedSidebarWidth` 设定。
|
package/client/client.chat.js
CHANGED
|
@@ -52,7 +52,119 @@ window.__ModuleLoader__.load({
|
|
|
52
52
|
* 留一条明确告警,不牵连 caption-map 自己的标题栏映射。 */
|
|
53
53
|
var WINDOW_KIT = null
|
|
54
54
|
try { WINDOW_KIT = require('@capyclaw/window-kit') } catch (error) {
|
|
55
|
-
|
|
55
|
+
/* macOS 的 boot graph 不含 window-kit(dsh.client.external 只负责排序、不会把模块加进去)→
|
|
56
|
+
* 回退到内联最小面(与 window-kit 同判据:largestVisible / mainPanel / sidebarPanel /
|
|
57
|
+
* conversationRoot / effect)。win32 / 纯 web 外部模块在场,此分支永不触发;单一真源。 */
|
|
58
|
+
WINDOW_KIT = (function () {
|
|
59
|
+
function largestVisible(selector, minWidth, minHeight, map) {
|
|
60
|
+
var list = []
|
|
61
|
+
try { list = document.querySelectorAll ? Array.prototype.slice.call(document.querySelectorAll(selector)) : [] } catch (error) { list = [] }
|
|
62
|
+
if (!list.length) {
|
|
63
|
+
var one = null
|
|
64
|
+
try { one = document.querySelector(selector) } catch (error) { one = null }
|
|
65
|
+
if (one) list = [one]
|
|
66
|
+
}
|
|
67
|
+
var best = null
|
|
68
|
+
for (var i = 0; i < list.length; i += 1) {
|
|
69
|
+
var node = null
|
|
70
|
+
try { node = map ? map(list[i]) : list[i] } catch (error) { node = null }
|
|
71
|
+
if (!node) continue
|
|
72
|
+
var box = null
|
|
73
|
+
try { box = node.getBoundingClientRect() } catch (error) { box = null }
|
|
74
|
+
if (!box || !isFinite(box.width) || !isFinite(box.height) || box.width < minWidth || box.height < minHeight) continue
|
|
75
|
+
var area = box.width * box.height
|
|
76
|
+
if (!best || area > best.area) best = { node: node, box: box, area: area }
|
|
77
|
+
}
|
|
78
|
+
return best
|
|
79
|
+
}
|
|
80
|
+
function mainPanel() {
|
|
81
|
+
var hit = largestVisible('[class*="_mainPanel"]', 160, 120)
|
|
82
|
+
return hit ? hit.node : null
|
|
83
|
+
}
|
|
84
|
+
/* 侧栏列(footer 的父级)。与 window-kit 同判据:折叠轨 / 底行全藏时算不在。 */
|
|
85
|
+
function sidebarPanel() {
|
|
86
|
+
var foot = null
|
|
87
|
+
try { foot = document.querySelector('[class*="_footArea"]') } catch (error) { foot = null }
|
|
88
|
+
if (!foot || typeof foot.getBoundingClientRect !== 'function') return null
|
|
89
|
+
var col = foot.parentElement
|
|
90
|
+
if (!col || typeof col.getBoundingClientRect !== 'function') return null
|
|
91
|
+
try {
|
|
92
|
+
var r = col.getBoundingClientRect()
|
|
93
|
+
var fr = foot.getBoundingClientRect()
|
|
94
|
+
if (!r || !fr || !isFinite(r.width) || !isFinite(r.height) ||
|
|
95
|
+
!isFinite(fr.width) || !isFinite(fr.height) ||
|
|
96
|
+
r.width < 120 || r.height < 160) return null
|
|
97
|
+
if (fr.width <= 0 && fr.height <= 0) return null
|
|
98
|
+
var pos = ''
|
|
99
|
+
try { pos = getComputedStyle(foot).position } catch (e) { pos = '' }
|
|
100
|
+
var inFlow = pos !== 'fixed' && pos !== 'absolute'
|
|
101
|
+
var anchorTop = inFlow ? fr.top : r.bottom
|
|
102
|
+
var anchorH = inFlow ? fr.height : 0
|
|
103
|
+
if (!isFinite(anchorTop) || anchorTop < r.top - 1 || anchorTop > r.bottom + 1) anchorTop = r.bottom
|
|
104
|
+
return {
|
|
105
|
+
el: col, foot: foot, rect: r,
|
|
106
|
+
footRect: { top: anchorTop, bottom: anchorTop + anchorH, height: anchorH,
|
|
107
|
+
width: fr.width > 0 ? fr.width : r.width, left: r.left, right: r.right },
|
|
108
|
+
footRelocated: !inFlow,
|
|
109
|
+
}
|
|
110
|
+
} catch (error) { return null }
|
|
111
|
+
}
|
|
112
|
+
function conversationRoot() {
|
|
113
|
+
var hit = largestVisible('[data-conversation-content]', 120, 80, function (body) {
|
|
114
|
+
return body.parentElement || body
|
|
115
|
+
})
|
|
116
|
+
return hit ? hit.node : null
|
|
117
|
+
}
|
|
118
|
+
/* 页面账本最小面:只提供 style(卸载摘自己那条)与 mount 收尾。 */
|
|
119
|
+
function pageEffect(ctx, label, mount) {
|
|
120
|
+
var dispose = function () {}
|
|
121
|
+
function run() {
|
|
122
|
+
var styles = []
|
|
123
|
+
var sealed = false
|
|
124
|
+
var extra = null
|
|
125
|
+
var page = {
|
|
126
|
+
alive: function () { return !sealed },
|
|
127
|
+
style: function (id, css) {
|
|
128
|
+
var el = document.getElementById(id)
|
|
129
|
+
if (!el || el.parentElement !== document.head) {
|
|
130
|
+
el = document.createElement('style')
|
|
131
|
+
el.id = id
|
|
132
|
+
document.head.appendChild(el)
|
|
133
|
+
}
|
|
134
|
+
if (el.textContent !== css) el.textContent = css
|
|
135
|
+
styles.push(el)
|
|
136
|
+
return el
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
try { extra = mount(page) } catch (error) {
|
|
140
|
+
console.warn('[caption-map] 聊天窗停靠装填失败:', error && error.message)
|
|
141
|
+
}
|
|
142
|
+
return function () {
|
|
143
|
+
if (sealed) return
|
|
144
|
+
sealed = true
|
|
145
|
+
try { if (typeof extra === 'function') extra() } catch (error) { /* 忽略 */ }
|
|
146
|
+
for (var i = 0; i < styles.length; i += 1) {
|
|
147
|
+
try { if (styles[i].parentElement) styles[i].parentElement.removeChild(styles[i]) } catch (error) { /* 忽略 */ }
|
|
148
|
+
}
|
|
149
|
+
styles.length = 0
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (ctx && typeof ctx.effect === 'function') {
|
|
153
|
+
try { ctx.effect(run, label) } catch (error) { run() }
|
|
154
|
+
} else {
|
|
155
|
+
var teardown = run()
|
|
156
|
+
dispose = function () { teardown() }
|
|
157
|
+
}
|
|
158
|
+
return { dispose: function () { dispose() } }
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
largestVisible: largestVisible,
|
|
162
|
+
mainPanel: mainPanel,
|
|
163
|
+
sidebarPanel: sidebarPanel,
|
|
164
|
+
conversationRoot: conversationRoot,
|
|
165
|
+
effect: pageEffect,
|
|
166
|
+
}
|
|
167
|
+
})()
|
|
56
168
|
}
|
|
57
169
|
|
|
58
170
|
var SLOT_ATTR = 'data-capyclaw-chat-slot'
|
|
@@ -205,6 +317,26 @@ window.__ModuleLoader__.load({
|
|
|
205
317
|
return best ? best.node : chat
|
|
206
318
|
}
|
|
207
319
|
|
|
320
|
+
/** 欢迎页兜底根:没开会话时主区是「探索未至之境 + 选择工作区输入框」,没有
|
|
321
|
+
* [data-conversation-content],conversationRoot() 落空 → 整块不搬(mac 真机
|
|
322
|
+
* 首装即此态)。从输入框座位向上爬到主区容器(_mainPanel)的直接子级 = 欢迎页
|
|
323
|
+
* 整块;爬不到(主区探针漂移)就返回 null,宁可不搬不乱搬。仅 darwin 调用。 */
|
|
324
|
+
function welcomeRoot() {
|
|
325
|
+
if (!WINDOW_KIT || typeof WINDOW_KIT.largestVisible !== 'function') return null
|
|
326
|
+
var seat = null
|
|
327
|
+
try { seat = WINDOW_KIT.largestVisible('[data-composer-seat]', 120, 60) } catch (error) { seat = null }
|
|
328
|
+
if (!seat || !seat.node) return null
|
|
329
|
+
var main = null
|
|
330
|
+
try { main = WINDOW_KIT.mainPanel() } catch (error) { main = null }
|
|
331
|
+
if (!main) return null
|
|
332
|
+
var node = seat.node
|
|
333
|
+
while (node && node.parentElement && node.parentElement !== document.body) {
|
|
334
|
+
if (node.parentElement === main) return node
|
|
335
|
+
node = node.parentElement
|
|
336
|
+
}
|
|
337
|
+
return null
|
|
338
|
+
}
|
|
339
|
+
|
|
208
340
|
/** 把聊天面板搬进侧栏底部的唯一实现;返回卸载函数。 */
|
|
209
341
|
function mount(page) {
|
|
210
342
|
page.style(STYLE_ID, CSS)
|
|
@@ -314,14 +446,27 @@ window.__ModuleLoader__.load({
|
|
|
314
446
|
function place() {
|
|
315
447
|
if (!WINDOW_KIT || typeof document === 'undefined') return
|
|
316
448
|
var root = document.documentElement
|
|
449
|
+
var isDarwin = !!(root && typeof root.getAttribute === 'function' && root.getAttribute('data-platform') === 'darwin')
|
|
317
450
|
/* drawer 形态:侧栏是一层临时浮层,这时候别往里搬(收起后列就没了)。 */
|
|
318
451
|
if (root && typeof root.hasAttribute === 'function' && root.hasAttribute('data-sidebar-drawer')) return
|
|
319
452
|
|
|
453
|
+
/* darwin 折叠态:侧栏收成 0 宽轨,槽里留着面板会整块看不见 → 搬回原父并撤槽。
|
|
454
|
+
* win 折叠态侧栏仍有宽度,聊天留在轨里照旧(单一真源,不改 win 行为)。 */
|
|
455
|
+
if (isDarwin && document.querySelector('[data-sidebar-collapsed="true"]')) {
|
|
456
|
+
if (panel) { if (panel.__capyclawChatSwallowed) detach(panel); else returnHome(panel) }
|
|
457
|
+
if (slot && slot.parentElement) { try { slot.parentElement.removeChild(slot) } catch (error) { /* 忽略 */ } }
|
|
458
|
+
slot = null
|
|
459
|
+
prevPanel = null
|
|
460
|
+
return
|
|
461
|
+
}
|
|
462
|
+
|
|
320
463
|
/* 同层守卫:列被整体卸掉(面板连槽脱离文档)→ 先搬回原父保住会话节点,
|
|
321
464
|
* 再交给下面的重钉逻辑。 */
|
|
322
465
|
if (panel && typeof document.contains === 'function' && !document.contains(panel)) returnHome(panel)
|
|
323
466
|
|
|
324
467
|
var chat = preferLivePanel(WINDOW_KIT.conversationRoot())
|
|
468
|
+
/* darwin 首装无会话:conversationRoot 落空时兜底搬欢迎页整块(win 不做此搬)。 */
|
|
469
|
+
if (!chat && isDarwin) chat = welcomeRoot()
|
|
325
470
|
/* React 换树有短暂空档:这一拍找不到就等下一拍,别动槽里的面板。 */
|
|
326
471
|
if (!chat) return
|
|
327
472
|
|
package/client/client.js
CHANGED
|
@@ -86,11 +86,16 @@ window.__ModuleLoader__.load({
|
|
|
86
86
|
var PACKAGE_ID = '@capyclaw/caption-map'
|
|
87
87
|
var MARK = 'data-capyclaw-caption-map'
|
|
88
88
|
var SRC_MARK = 'data-capyclaw-caption-map-src'
|
|
89
|
+
/** 平台分流:宿主 preload 在页面脚本前钉死 html[data-platform],工厂作用域即可据此
|
|
90
|
+
常量分流。win32 / 纯 web 走原生标题栏映射;darwin 由本包自带的「标题栏壳」effect
|
|
91
|
+
把宿主归一成 windows-titlebar 形态,四条 effect 两平台共用同一套代码(单一真源)。 */
|
|
92
|
+
var IS_DARWIN = !!(document.documentElement && typeof document.documentElement.getAttribute === 'function'
|
|
93
|
+
&& document.documentElement.getAttribute('data-platform') === 'darwin')
|
|
89
94
|
/** 底部区域的席位清单(顺序即顶栏排布顺序)。新增底部席位时往这里加一行。 */
|
|
90
95
|
var SEATS = ['settings.launcher', 'sidebar.footer.action']
|
|
91
96
|
var GAP = 6
|
|
92
|
-
/** 标题栏右侧原生 min/max/close
|
|
93
|
-
var CAPTION_RIGHT_RESERVE = 150
|
|
97
|
+
/** 标题栏右侧原生 min/max/close 按钮预留宽度(win32 150;darwin 无系统按钮,仅留 12)。 */
|
|
98
|
+
var CAPTION_RIGHT_RESERVE = IS_DARWIN ? 12 : 150
|
|
94
99
|
/** foot 竖排堆叠的高度上限;超过说明公共祖先取大了。 */
|
|
95
100
|
var ROW_MAX_HEIGHT = 240
|
|
96
101
|
/** 新会话整条按钮:CSS module 哈希前缀随版本变,后缀稳定;row/content 等不是 button,不会误中。 */
|
|
@@ -151,7 +156,10 @@ window.__ModuleLoader__.load({
|
|
|
151
156
|
var MORE_ITEM_MARK = 'data-capyclaw-more-item'
|
|
152
157
|
var MORE_ROW_MARK = 'data-capyclaw-more-row'
|
|
153
158
|
var MORE_SEATS_MARK = 'data-capyclaw-more-seats'
|
|
154
|
-
|
|
159
|
+
/** 「更多」按钮左缘:win32 12;darwin 80(让开左上角红黄绿交通灯,约 16,18)。 */
|
|
160
|
+
var MORE_LEFT = IS_DARWIN ? 80 : 12
|
|
161
|
+
/** darwin 标题栏壳注入的零宽假菜单栏标记(拆卸时据此只摘自己注入的那枚)。 */
|
|
162
|
+
var FAKE_MENU_ATTR = 'data-capyclaw-macos-fake-menu'
|
|
155
163
|
var MORE_WIDTH = 240
|
|
156
164
|
var MORE_PAD = 6
|
|
157
165
|
var MORE_GAP = 2
|
|
@@ -224,7 +232,7 @@ window.__ModuleLoader__.load({
|
|
|
224
232
|
/* ── 预留栏位:「其他」后的占位场(内容待定,虚线盒示意) ─────── */
|
|
225
233
|
'[' + EXTRA_SLOT_MARK + ']{position:fixed!important;z-index:1080!important;box-sizing:border-box!important;',
|
|
226
234
|
'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;',
|
|
235
|
+
'height:28px!important;width:auto!important;' + (IS_DARWIN ? '' : 'right:auto!important;') + 'max-width:160px!important;margin:0!important;padding:0 8px!important;' + (IS_DARWIN ? '-webkit-app-region:no-drag!important;' : ''),
|
|
228
236
|
'border:1px dashed var(--dsw-alias-border-l2,rgba(0,0,0,.25))!important;border-radius:var(--dsw-radius-sm,6px)!important;',
|
|
229
237
|
'background:transparent!important;color:var(--dsw-alias-label-secondary,inherit)!important;font:inherit!important;font-size:12px!important;line-height:1!important;',
|
|
230
238
|
'white-space:nowrap!important}',
|
|
@@ -233,10 +241,12 @@ window.__ModuleLoader__.load({
|
|
|
233
241
|
窗口控件预留区左缘 ⇒ width:auto 的 fixed 盒拉伸占满标题栏剩余宽度(Edge 式标签
|
|
234
242
|
条填满到末尾,不再内容自撑半截停住);内层 mount 均分槽宽承载消费者 React 根。
|
|
235
243
|
未占用时 right:auto 回到虚线占位盒自撑。 */
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
244
|
+
IS_DARWIN
|
|
245
|
+
? '[' + EXTRA_SLOT_MARK + '][data-occupied]{border:none!important;max-width:none!important;padding:0!important;gap:0!important}'
|
|
246
|
+
: '[' + EXTRA_SLOT_MARK + '][data-occupied]{border:none!important;max-width:calc(100vw - ' + CAPTION_RIGHT_RESERVE + 'px)!important;padding:0!important;gap:0!important;right:' + CAPTION_RIGHT_RESERVE + 'px!important}',
|
|
247
|
+
IS_DARWIN
|
|
248
|
+
? '[' + EXTRA_SLOT_MOUNT_MARK + ']{display:flex!important;align-items:center!important;height:28px!important;min-width:0!important;max-width:46vw!important;overflow:hidden!important;-webkit-app-region:no-drag!important}'
|
|
249
|
+
: '[' + EXTRA_SLOT_MOUNT_MARK + ']{display:flex!important;align-items:center!important;height:28px!important;flex:1 1 0!important;min-width:0!important;max-width:100%!important;overflow:hidden!important}',
|
|
240
250
|
|
|
241
251
|
/* ── 「其他」分组:把 sidebar.panellist 收成下拉 ─────────────── */
|
|
242
252
|
'nav[' + MARK + ']{position:fixed!important;z-index:1090!important;box-sizing:border-box!important;',
|
|
@@ -343,6 +353,21 @@ window.__ModuleLoader__.load({
|
|
|
343
353
|
'nav[' + MORE_ITEM_MARK + '] [class*="panelUnpin"]{display:none!important}',
|
|
344
354
|
].join('')
|
|
345
355
|
|
|
356
|
+
/* darwin 标题栏壳样式(仅 darwin 注入):宿主原生没有 windows-titlebar,壳把侧栏顶部
|
|
357
|
+
归一成与 win32 同形——topStrip / 侧栏开关藏起、logoRow 收零、frame 顶部刷一条标题栏底色,
|
|
358
|
+
工作区第二行 / 折叠态各自让位。区域映射与聊天停靠的门控因此两平台共用同一套。 */
|
|
359
|
+
var SHELL_CSS = [
|
|
360
|
+
'html[data-platform="darwin"][data-windows-titlebar] [data-slot="sidebar"] [class*="topStrip"]{display:none!important}',
|
|
361
|
+
'html[data-platform="darwin"][data-windows-titlebar] [data-slot="sidebar"] [data-sidebar-toggle]{display:none!important}',
|
|
362
|
+
'html[data-platform="darwin"][data-windows-titlebar] [data-slot="sidebar"] [class*="logoRow"]{height:0!important;min-height:0!important;margin:0!important;padding:0!important;overflow:hidden!important}',
|
|
363
|
+
'html[data-platform="darwin"][data-windows-titlebar] [data-slot="sidebar"] [class*="newSessionRow"]{margin-top:0!important}',
|
|
364
|
+
'html[data-platform="darwin"][data-windows-titlebar] div:has(> [data-shell-bottom]){background-image:linear-gradient(var(--dsw-specific-sidebar-fill),var(--dsw-specific-sidebar-fill))!important;background-repeat:no-repeat!important;background-position:top!important;background-size:100% var(--dsh-windows-titlebar-height)!important}',
|
|
365
|
+
'html[data-platform="darwin"][data-windows-titlebar][data-capyclaw-ws-row] div:has(> [data-shell-bottom]){background-size:100% calc(var(--dsh-windows-titlebar-height) + ' + WS_ROW_H + 'px)!important}',
|
|
366
|
+
'html[data-platform="darwin"][data-windows-titlebar]:has([data-sidebar-collapsed="true"]) div:has(> [data-shell-bottom]){padding-top:0!important;background-image:none!important}',
|
|
367
|
+
'html[data-platform="darwin"][data-windows-titlebar]:has([data-sidebar-collapsed="true"]){--dsh-frame-top-clearance:48px!important;--dsh-frame-chrome-top:0px!important}',
|
|
368
|
+
'html[data-platform="darwin"][data-windows-titlebar][data-capyclaw-ws-row]{--dsh-frame-top-clearance:calc(var(--dsh-windows-titlebar-height) + ' + WS_ROW_H + 'px)!important;--dsh-frame-chrome-top:calc(var(--dsh-windows-titlebar-height) + ' + WS_ROW_H + 'px)!important}',
|
|
369
|
+
].join('')
|
|
370
|
+
|
|
346
371
|
/** 注入一张归属本插件的样式表(卸载时调用方 remove)。id 可选(动态过滤表用)。 */
|
|
347
372
|
function styleTag(css, id) {
|
|
348
373
|
var t = document.createElement('style')
|
|
@@ -356,18 +381,47 @@ window.__ModuleLoader__.load({
|
|
|
356
381
|
return {
|
|
357
382
|
name: 'caption-map',
|
|
358
383
|
apply: function (ctx) {
|
|
359
|
-
/*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
var IS_DARWIN = document.documentElement.getAttribute('data-platform') === 'darwin'
|
|
384
|
+
/* 平台分流:IS_DARWIN 在工厂作用域算好(preload 先于页面脚本钉死 data-platform)。
|
|
385
|
+
* darwin 由本包自带的「标题栏壳」effect 把宿主归一成 windows-titlebar 形态,
|
|
386
|
+
* 区域映射 / 挂载锚 / 固定侧栏 / 聊天停靠四条 effect 两平台共用同一套代码(单一真源),
|
|
387
|
+
* 不再让位给独立的 caption-map-macos 包。win32 / 纯 web 照旧原生形态。 */
|
|
364
388
|
|
|
365
389
|
/* 让位标记:聊天窗停靠由本包接管。老的 @capyclaw/chat-dock 见到它就自己退出,
|
|
366
|
-
* 两个包同时启用时不会各有一个人去搬同一块面板。
|
|
390
|
+
* 两个包同时启用时不会各有一个人去搬同一块面板。win32 / 纯 web 在此设标记;
|
|
391
|
+
* darwin 由标题栏壳 effect 设(含拆卸还原)。 */
|
|
367
392
|
if (!IS_DARWIN) {
|
|
368
393
|
try { window.__CAPYCLAW_CHAT_DOCK_OWNER__ = PACKAGE_ID } catch (error) { /* 忽略 */ }
|
|
369
394
|
}
|
|
370
395
|
|
|
396
|
+
/* darwin 标题栏壳:把 macOS 宿主归一成 windows-titlebar 形态(设属性 + 40px 高度变量 +
|
|
397
|
+
* 注入零宽假菜单栏),让区域映射 active() 与聊天停靠 FILL_SEL 两平台共用同一套门控。
|
|
398
|
+
* 仅 darwin 生效;win32 / 纯 web 早退。拆卸还原属性 / 变量 / 假菜单 / owner。 */
|
|
399
|
+
ctx.effect(function () {
|
|
400
|
+
if (!IS_DARWIN) return function () {}
|
|
401
|
+
var ROOT = document.documentElement
|
|
402
|
+
var prevHeight = ROOT.style.getPropertyValue('--dsh-windows-titlebar-height')
|
|
403
|
+
ROOT.setAttribute('data-windows-titlebar', '')
|
|
404
|
+
ROOT.style.setProperty('--dsh-windows-titlebar-height', '40px')
|
|
405
|
+
var menu = document.querySelector('[data-windows-menu]')
|
|
406
|
+
if (!menu) {
|
|
407
|
+
menu = document.createElement('div')
|
|
408
|
+
menu.setAttribute('data-windows-menu', '')
|
|
409
|
+
menu.setAttribute(FAKE_MENU_ATTR, '')
|
|
410
|
+
menu.style.cssText = 'position:fixed;top:0;left:' + MORE_LEFT + 'px;width:0;height:40px;visibility:hidden;pointer-events:none;z-index:0'
|
|
411
|
+
document.body.appendChild(menu)
|
|
412
|
+
}
|
|
413
|
+
var tag = styleTag(SHELL_CSS, 'capyclaw-macos-titlebar-shell')
|
|
414
|
+
try { window.__CAPYCLAW_CHAT_DOCK_OWNER__ = PACKAGE_ID } catch (error) { /* 忽略 */ }
|
|
415
|
+
return function () {
|
|
416
|
+
try { if (menu && menu.hasAttribute(FAKE_MENU_ATTR) && menu.parentElement) menu.parentElement.removeChild(menu) } catch (error) { /* 忽略 */ }
|
|
417
|
+
ROOT.removeAttribute('data-windows-titlebar')
|
|
418
|
+
if (prevHeight) ROOT.style.setProperty('--dsh-windows-titlebar-height', prevHeight)
|
|
419
|
+
else ROOT.style.removeProperty('--dsh-windows-titlebar-height')
|
|
420
|
+
try { tag.remove() } catch (error) { /* 忽略 */ }
|
|
421
|
+
try { if (window.__CAPYCLAW_CHAT_DOCK_OWNER__ === PACKAGE_ID) delete window.__CAPYCLAW_CHAT_DOCK_OWNER__ } catch (error) { /* 忽略 */ }
|
|
422
|
+
}
|
|
423
|
+
}, 'caption-map: titlebar shell')
|
|
424
|
+
|
|
371
425
|
/** 预留栏位 = 显式挂载锚:「其他」右侧一枚场。无消费者时是虚线占位盒;
|
|
372
426
|
消费者经 ctx.captionExtra 服务 acquire 后,内层 mount 节点交给它挂 React 根,
|
|
373
427
|
占位 span 隐藏、外盒去虚线自撑。纯自有节点:pass 注入/排布、yield 移除,
|
|
@@ -433,15 +487,19 @@ window.__ModuleLoader__.load({
|
|
|
433
487
|
s.top = ((capH - 28) / 2) + 'px'
|
|
434
488
|
s.left = left + 'px'
|
|
435
489
|
s.zIndex = '1080'
|
|
436
|
-
s.webkitAppRegion = '' /*
|
|
490
|
+
s.webkitAppRegion = IS_DARWIN ? 'no-drag' : '' /* darwin 槽盒整体 no-drag(壳没有可拖标题栏);win 空白尾继承宿主 drag,标签/按钮自带 no-drag 仍可点 */
|
|
437
491
|
/* 不挤占右侧原生 min/max/close 预留区:放不下整枚隐藏。
|
|
438
492
|
占用态靠 left+right 拉伸、宽恒等于剩余空间,只看 left 是否已越过预留区
|
|
439
493
|
左缘(若再累加 rect 宽,亚像素舍入会把拉伸盒误判成挤占而整枚隐藏);
|
|
440
494
|
未占用占位盒仍按内容宽判断。 */
|
|
441
495
|
var w = node.getBoundingClientRect().width
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
496
|
+
/* darwin 槽盒自撑(无 right 钉),用简单越界判定;win 占用态是拉伸盒,
|
|
497
|
+
* 有租约时 left 已钉到预留区左缘,用 left>=阈值 防亚像素抖动。 */
|
|
498
|
+
var over = IS_DARWIN
|
|
499
|
+
? left + w > window.innerWidth - CAPTION_RIGHT_RESERVE
|
|
500
|
+
: (leases.length
|
|
501
|
+
? left >= window.innerWidth - CAPTION_RIGHT_RESERVE
|
|
502
|
+
: left + w > window.innerWidth - CAPTION_RIGHT_RESERVE)
|
|
445
503
|
s.display = over ? 'none' : ''
|
|
446
504
|
if (dirty) notify()
|
|
447
505
|
return left + w + GAP
|
|
@@ -481,7 +539,6 @@ window.__ModuleLoader__.load({
|
|
|
481
539
|
|
|
482
540
|
/* 挂载锚服务:cordis provide,卸载对称 unprovide(消费者 inject 随之失效)。 */
|
|
483
541
|
ctx.effect(function () {
|
|
484
|
-
if (IS_DARWIN) return function () {} /* darwin 由 caption-map-macos 提供 */
|
|
485
542
|
var svc = extraSlot.service
|
|
486
543
|
var un = (typeof ctx.provide === 'function') ? ctx.provide('captionExtra', svc)
|
|
487
544
|
: (ctx.reflect && typeof ctx.reflect.provide === 'function') ? ctx.reflect.provide('captionExtra', svc) : null
|
|
@@ -489,7 +546,6 @@ window.__ModuleLoader__.load({
|
|
|
489
546
|
}, 'caption-map: extra slot mount service')
|
|
490
547
|
|
|
491
548
|
ctx.effect(function () {
|
|
492
|
-
if (IS_DARWIN) return function () {} /* darwin 区域映射由 caption-map-macos 接管 */
|
|
493
549
|
var tag = styleTag(CSS)
|
|
494
550
|
|
|
495
551
|
/* ── 共享底座 kit ─────────────────────────────────────────── */
|
|
@@ -1123,7 +1179,7 @@ window.__ModuleLoader__.load({
|
|
|
1123
1179
|
box(rowNew, innerLeft, y, innerWidth, MORE_ROW_H); y += MORE_ROW_H + MORE_GAP
|
|
1124
1180
|
box(rowSidebar, innerLeft, y, innerWidth, MORE_ROW_H); y += MORE_ROW_H + MORE_GAP
|
|
1125
1181
|
/* ③ 应用/编辑菜单栏 host:height 保持 capH,编排器量 capH 不漂移 */
|
|
1126
|
-
if (mb) { place(mb, innerLeft, y, innerWidth, capH); y += capH + MORE_GAP }
|
|
1182
|
+
if (mb && !mb.hasAttribute(FAKE_MENU_ATTR)) { place(mb, innerLeft, y, innerWidth, capH); y += capH + MORE_GAP }
|
|
1127
1183
|
/* ④ 底部入口行(Maple 账户 + 手机/电脑):横排,overflow 放行弹出菜单 */
|
|
1128
1184
|
var seatsTop = y
|
|
1129
1185
|
var sx = innerLeft
|
|
@@ -1269,6 +1325,9 @@ window.__ModuleLoader__.load({
|
|
|
1269
1325
|
function pass() {
|
|
1270
1326
|
timer = 0
|
|
1271
1327
|
if (!active()) { yieldAll(); lastMode = ''; return }
|
|
1328
|
+
/* darwin 抽屉 / 折叠态让位给宿主原生前导座(侧栏是浮层或 0 宽轨);
|
|
1329
|
+
* win 折叠态仍由本包在标题栏摆 brand+others+seats,不让位。 */
|
|
1330
|
+
if (IS_DARWIN && (drawer() || collapsed())) { yieldAll(); lastMode = ''; return }
|
|
1272
1331
|
var hosts = seatHosts()
|
|
1273
1332
|
var navEl = panelNav()
|
|
1274
1333
|
var wsEl = wsRoot()
|
|
@@ -1370,8 +1429,7 @@ window.__ModuleLoader__.load({
|
|
|
1370
1429
|
* 门控:折叠(rail/全隐)、drawer(浮层)、折叠屏横屏居中侧栏都不插手,
|
|
1371
1430
|
* 交还原外壳布局。 */
|
|
1372
1431
|
ctx.effect(function () {
|
|
1373
|
-
|
|
1374
|
-
var opts = window.__DSH_CAPTION_MAP__ || {}
|
|
1432
|
+
var opts = window.__DSH_CAPTION_MAP__ || window.__DSH_CAPTION_MAP_MACOS__ || {}
|
|
1375
1433
|
if (opts.fixedSidebarWidth === false) return function () {}
|
|
1376
1434
|
|
|
1377
1435
|
var FIXED_ATTR = 'data-capyclaw-fixed-sidebar'
|
|
@@ -1494,7 +1552,6 @@ window.__ModuleLoader__.load({
|
|
|
1494
1552
|
/* 聊天窗停靠:包内分块按需加载,与标题栏映射互不依赖(跨平台常驻)。
|
|
1495
1553
|
* 独立一条 effect 管它的生命周期:分块还没到就卸载时,回来也不能再装。 */
|
|
1496
1554
|
ctx.effect(function () {
|
|
1497
|
-
if (IS_DARWIN) return function () {} /* darwin 聊天停靠由 caption-map-macos 接管 */
|
|
1498
1555
|
var dead = false
|
|
1499
1556
|
var dock = null
|
|
1500
1557
|
if (typeof require === 'function' && typeof require.async === 'function') {
|
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import { BOOT_GLOBAL, normalizeConfig } from './options.mjs'
|
|
|
17
17
|
|
|
18
18
|
const plugin = createPlugin({
|
|
19
19
|
name: 'caption-map',
|
|
20
|
-
description: '
|
|
20
|
+
description: '把底部入口行区域映射到标题栏行(Windows 原生 / macOS 经标题栏壳归一,占用方零改动,新注册自动跟随);侧栏宽度固定为拖拽上限',
|
|
21
21
|
implements: [
|
|
22
22
|
/* 设定经 bootGlobals 注入页面(每次 index 渲染重放,改 config 刷新页面生效)。 */
|
|
23
23
|
clientPanel({
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 资产引用契约的单一真源(公共 ABI 常量)。
|
|
3
|
+
*
|
|
4
|
+
* 互操作标准里资产有两副面孔,前缀在这里定义一次,内核门面与资产服务都引用它,
|
|
5
|
+
* 避免「路由实现」与「URL 门面」各写一份 '/assets/' 而漂移:
|
|
6
|
+
* - 字节仓 HTTP 路由前缀 ASSET_URL_PREFIX = '/assets/' (asset-service 挂 GET/HEAD)
|
|
7
|
+
* - 结构化正文里的引用前缀 ASSET_REF_PREFIX = '@asset/' (work-store 信封/正文只存引用)
|
|
8
|
+
*
|
|
9
|
+
* 这是契约常量,不是宿主服务名——放 ABI 层,应用与驱动都可 import。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** 资产字节仓的 HTTP 路由前缀(asset-service 实现,内核 os.assets.url 复用)。 */
|
|
13
|
+
export const ASSET_URL_PREFIX = '/assets/'
|
|
14
|
+
|
|
15
|
+
/** 结构化正文/产物信封里的内容寻址引用前缀(@asset/<sha256>)。 */
|
|
16
|
+
export const ASSET_REF_PREFIX = '@asset/'
|
|
17
|
+
|
|
18
|
+
/** 由资产 id 生成可加载 URL:/assets/<id>(id 做 URI 编码)。 */
|
|
19
|
+
export function assetUrl(id) {
|
|
20
|
+
return `${ASSET_URL_PREFIX}${encodeURIComponent(String(id))}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 由资产 id 生成规范引用:@asset/<id>。 */
|
|
24
|
+
export function assetRef(id) {
|
|
25
|
+
return `${ASSET_REF_PREFIX}${String(id)}`
|
|
26
|
+
}
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* doc.model —— 插件提供文档模型(稳定 ID / 清单 / 定位 / 编辑计划 / 校验)
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { AbiError, ERROR_CODES } from './errors.mjs'
|
|
18
|
+
|
|
17
19
|
/** 桥协议版本:端点集合与状态机语义的主版本。不兼容变更才升 major。 */
|
|
18
20
|
export const BRIDGE_PROTOCOL_VERSION = '1.0.0'
|
|
19
21
|
|
|
@@ -40,7 +42,7 @@ export function declareBridge(input = {}) {
|
|
|
40
42
|
if (!VERSION_RE.test(protocol)) errors.push(`protocol 版本非法:${protocol}`)
|
|
41
43
|
if (model !== null && !VERSION_RE.test(model)) errors.push(`model 版本非法:${model}`)
|
|
42
44
|
if (editor !== 'required' && editor !== 'optional') errors.push(`editor 只能是 required/optional:${editor}`)
|
|
43
|
-
if (errors.length) throw new
|
|
45
|
+
if (errors.length) throw new AbiError(ERROR_CODES.E_SCHEMA, `桥声明非法:${errors.join(';')}`, { errors })
|
|
44
46
|
return Object.freeze({ id, protocol, model, editor })
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -17,6 +17,8 @@ export {
|
|
|
17
17
|
defineDriver,
|
|
18
18
|
rawPlugin,
|
|
19
19
|
} from './spec.mjs'
|
|
20
|
+
/* createLoader 是宿主/测试侧装配 API(内核 createKernel 与一致性测试用),虽从 abi 导出,
|
|
21
|
+
* 应用插件不应直接调用——应用只用 createPlugin + 接口 builders(见 plugin-abi.md §二)。 */
|
|
20
22
|
export { createLoader } from './loader.mjs'
|
|
21
23
|
export {
|
|
22
24
|
BRIDGE_CAPABILITY,
|
|
@@ -29,6 +31,19 @@ export {
|
|
|
29
31
|
bridgeConsumerRequirements,
|
|
30
32
|
declareBridge,
|
|
31
33
|
} from './bridge.mjs'
|
|
34
|
+
export {
|
|
35
|
+
SURFACE_LIFECYCLE_VERSION,
|
|
36
|
+
SURFACE_LIFECYCLE_CAPABILITY_SUFFIX,
|
|
37
|
+
VISIBILITY_ACK_MESSAGE,
|
|
38
|
+
VISIBILITY_DEFAULTS,
|
|
39
|
+
VISIBILITY_MESSAGE,
|
|
40
|
+
VISIBILITY_STATES,
|
|
41
|
+
assertSurfaceLifecycle,
|
|
42
|
+
isVisibilityState,
|
|
43
|
+
normalizeVisibilityState,
|
|
44
|
+
surfaceLifecycleCapability,
|
|
45
|
+
} from './visibility.mjs'
|
|
46
|
+
export { ASSET_URL_PREFIX, ASSET_REF_PREFIX, assetUrl, assetRef } from './assets.mjs'
|
|
32
47
|
export { validateInterface } from './validate.mjs'
|
|
33
48
|
export { AbiError, ERROR_CODES, isAbiError, toAbiError } from './errors.mjs'
|
|
34
49
|
export { validateSchema } from './schema.mjs'
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表面生命周期(surface lifecycle)的标准声明。
|
|
3
|
+
*
|
|
4
|
+
* 与 bridge.mjs 同层:只放「协议常量 + 声明校验」,不放运行时。
|
|
5
|
+
* 依据 docs/SURFACE-LIFECYCLE-STANDARD.md:
|
|
6
|
+
* - 宿主(portal-hud + window-kit)是表面可见性的唯一真源,经统一 postMessage
|
|
7
|
+
* 信号通道下发给 iframe;iframe 内 document.hidden 只反映顶层 tab,不能用来
|
|
8
|
+
* 推断「被宿主藏起来」,所以表面可见性必须宿主显式告知。
|
|
9
|
+
* - 只有渲染面响应可见性;权威/数据面与桥接/仲裁面(租约心跳、apply/ack)
|
|
10
|
+
* 永远在线,与可见性无关。
|
|
11
|
+
*
|
|
12
|
+
* 消费方:
|
|
13
|
+
* - 宿主侧:@capyclaw/window-kit 的 visibility 驱动器(CJS 自包含叶子,无法
|
|
14
|
+
* import 本 ESM 模块,内联同名常量,由 parity 测试钉死一致)。
|
|
15
|
+
* - iframe 侧:@capyclaw/document-workbench/client 的 visibility 订阅器,
|
|
16
|
+
* 以及各编辑器前端(ppt/canvas/browser)。
|
|
17
|
+
* - 注册面:suite 清单 provides.capabilities 的 <ns>.surfaceLifecycle。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { AbiError, ERROR_CODES } from './errors.mjs'
|
|
21
|
+
|
|
22
|
+
/** 表面生命周期契约版本:状态机语义与信号形状的主版本。不兼容变更才升 major。 */
|
|
23
|
+
export const SURFACE_LIFECYCLE_VERSION = '1.0.0'
|
|
24
|
+
|
|
25
|
+
/** 宿主 → iframe 的可见性信号:{ type, state, sid },targetOrigin 同源。 */
|
|
26
|
+
export const VISIBILITY_MESSAGE = 'capyclaw:workbench:visibility'
|
|
27
|
+
|
|
28
|
+
/** iframe → 宿主 的回执:{ type, state, sid }。detached 由宿主直接卸载,无需回执。 */
|
|
29
|
+
export const VISIBILITY_ACK_MESSAGE = 'capyclaw:workbench:visibility-ack'
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 可见性状态(标准 §3):
|
|
33
|
+
* foreground 前台可见全速;background 可见非焦点(降速,SHOULD 档);
|
|
34
|
+
* hidden 不再绘制(渲染面必须挂起);detached 久藏卸载(影子编辑器接管)。
|
|
35
|
+
*/
|
|
36
|
+
export const VISIBILITY_STATES = Object.freeze(['foreground', 'background', 'hidden', 'detached'])
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 节奏/预算默认值(标准 §3/§4/§5)。运行时经 tuning 单一真源可调;
|
|
40
|
+
* 这里是协议默认,不是各插件私设的第二份。
|
|
41
|
+
* detachAfterMs hidden 持续多久才卸载 iframe(编辑器权威型可更长)
|
|
42
|
+
* visibilityAckTimeoutMs 信号发出后多久没回执算半挂起(宿主可强制重载)
|
|
43
|
+
* hiddenGraceMs shown→hidden 的去抖宽限,避免快速切换抖动
|
|
44
|
+
*/
|
|
45
|
+
export const VISIBILITY_DEFAULTS = Object.freeze({
|
|
46
|
+
detachAfterMs: 120000,
|
|
47
|
+
visibilityAckTimeoutMs: 1500,
|
|
48
|
+
hiddenGraceMs: 250,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
/** 能力名后缀:与 suite 清单 provides.capabilities 的 <ns>.surfaceLifecycle 对应。 */
|
|
52
|
+
export const SURFACE_LIFECYCLE_CAPABILITY_SUFFIX = 'surfaceLifecycle'
|
|
53
|
+
|
|
54
|
+
const STATE_SET = new Set(VISIBILITY_STATES)
|
|
55
|
+
|
|
56
|
+
/** 是否合法状态。 */
|
|
57
|
+
export function isVisibilityState(value) {
|
|
58
|
+
return typeof value === 'string' && STATE_SET.has(value)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 归一化:非法/缺省一律退回 foreground(宁可多渲染,不可假挂起)。 */
|
|
62
|
+
export function normalizeVisibilityState(value) {
|
|
63
|
+
return isVisibilityState(value) ? value : 'foreground'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 注册声明 → suite 清单 provides.capabilities(标准 §6)。 */
|
|
67
|
+
export function surfaceLifecycleCapability(ns, version = SURFACE_LIFECYCLE_VERSION) {
|
|
68
|
+
if (typeof ns !== 'string' || !/^[a-z0-9][a-z0-9-]*$/.test(ns)) {
|
|
69
|
+
throw new AbiError(ERROR_CODES.E_SCHEMA, `surfaceLifecycle 命名空间必须是 kebab-case:${ns}`)
|
|
70
|
+
}
|
|
71
|
+
return Object.freeze({ [`${ns}.${SURFACE_LIFECYCLE_CAPABILITY_SUFFIX}`]: version })
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 校验一份表面生命周期声明(注册契约,标准 §6)。
|
|
76
|
+
* 渲染面四钩子必须齐;editor-gated 观察必须声明无头兜底。
|
|
77
|
+
* @param {{ hooks?: string[], headlessObservation?: boolean }} input
|
|
78
|
+
*/
|
|
79
|
+
export function assertSurfaceLifecycle(input = {}) {
|
|
80
|
+
const required = ['onVisibility', 'suspendRender', 'resumeRender', 'rehydrate']
|
|
81
|
+
const hooks = Array.isArray(input.hooks) ? input.hooks : []
|
|
82
|
+
const issues = []
|
|
83
|
+
for (const hook of required) {
|
|
84
|
+
if (!hooks.includes(hook)) issues.push(`缺少渲染面钩子 ${hook}`)
|
|
85
|
+
}
|
|
86
|
+
if (input.headlessObservation !== true) {
|
|
87
|
+
issues.push('editor-gated 观察必须声明无头兜底(headlessObservation:true)')
|
|
88
|
+
}
|
|
89
|
+
return { ok: issues.length === 0, issues }
|
|
90
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* lifecycle-hook@1 的适配器。
|
|
3
3
|
*
|
|
4
|
-
* 运行时只执行 onStart / onStop
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 运行时只执行 onStart / onStop。onInstall / onUpgrade 属于安装与升级流程:
|
|
5
|
+
* 这里把它们登记进 hook 注册表(os.hooks),保证「声明了就找得到」。
|
|
6
|
+
* 截至本版本仓内尚无自动 fire 它们的安装/升级消费者(见 plugin-abi.md §4.6)——
|
|
7
|
+
* 这是已声明的集成点,不是已落地的自动钩子。安装器可经 os.hooks.run('install'|'upgrade', args)
|
|
8
|
+
* 主动触发;run() 只提供调用 API,是否/何时调用由安装器决定。
|
|
7
9
|
*/
|
|
10
|
+
import { AbiError, ERROR_CODES } from '../../abi/errors.mjs'
|
|
11
|
+
|
|
8
12
|
export const kind = 'lifecycle-hook@1'
|
|
9
13
|
|
|
10
14
|
export function createHookRegistry() {
|
|
@@ -12,7 +16,7 @@ export function createHookRegistry() {
|
|
|
12
16
|
install: [],
|
|
13
17
|
upgrade: [],
|
|
14
18
|
register(phase, entry) {
|
|
15
|
-
if (!this[phase]) throw new
|
|
19
|
+
if (!this[phase]) throw new AbiError(ERROR_CODES.E_SCHEMA, `未知生命周期阶段 ${phase}`)
|
|
16
20
|
this[phase].push(entry)
|
|
17
21
|
return () => {
|
|
18
22
|
const index = this[phase].indexOf(entry)
|
|
@@ -25,6 +29,19 @@ export function createHookRegistry() {
|
|
|
25
29
|
upgrade: this.upgrade.map((entry) => entry.plugin),
|
|
26
30
|
}
|
|
27
31
|
},
|
|
32
|
+
/**
|
|
33
|
+
* 安装/升级集成点:按登记顺序触发某阶段全部钩子,逐个 await。
|
|
34
|
+
* 仓内暂无自动调用方(见头注);这是给安装器(plugin-sync / plugin-drop / publisher)
|
|
35
|
+
* 预留的调用 API。未知阶段抛稳定错误码 E_SCHEMA。
|
|
36
|
+
*/
|
|
37
|
+
async run(phase, args = {}) {
|
|
38
|
+
if (!this[phase]) throw new AbiError(ERROR_CODES.E_SCHEMA, `未知生命周期阶段 ${phase}`)
|
|
39
|
+
const results = []
|
|
40
|
+
for (const entry of [...this[phase]]) {
|
|
41
|
+
results.push({ plugin: entry.plugin, result: await entry.run(args) })
|
|
42
|
+
}
|
|
43
|
+
return results
|
|
44
|
+
},
|
|
28
45
|
}
|
|
29
46
|
}
|
|
30
47
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* editorHost)的地方——它们属于 dsh 适配层,不属于 ABI。
|
|
7
7
|
*/
|
|
8
8
|
import { getService } from '../ctx-service.mjs'
|
|
9
|
+
import { HOST_SERVICE_CONTRACT } from './contract.mjs'
|
|
9
10
|
|
|
10
11
|
export const BASE_CAPABILITIES = Object.freeze({
|
|
11
12
|
'os.events': '1.0.0',
|
|
@@ -26,9 +27,12 @@ export function detectDshCapabilities(ctx) {
|
|
|
26
27
|
&& hasMethods(getService(ctx, 'tools'), 'register')) capabilities['os.tools'] = '1.0.0'
|
|
27
28
|
if (hasMethods(getService(ctx, 'serviceBroker'), 'start', 'stop')) capabilities['os.proc'] = '1.0.0'
|
|
28
29
|
if (capabilities['os.net'] && hasMethods(getService(ctx, 'editorHost'), 'createEditorHost')) capabilities['os.ui'] = '1.0.0'
|
|
29
|
-
if (hasMethods(getService(ctx, 'pluginManager'), '
|
|
30
|
+
if (hasMethods(getService(ctx, 'pluginManager'), ...HOST_SERVICE_CONTRACT['os.plugins'][1])) {
|
|
30
31
|
capabilities['os.plugins'] = '1.0.0'
|
|
31
32
|
}
|
|
32
33
|
if (hasMethods(getService(ctx, 'assets'), 'put', 'get')) capabilities['os.assets'] = '1.0.0'
|
|
34
|
+
// work-store 是可选持久化层(不在 core 六件内):探测到才 advertise os.works,
|
|
35
|
+
// 应用用 os.caps.has('os.works') 判断降级,不再 safeGet(ctx, 'workStore') 裸摸。
|
|
36
|
+
if (hasMethods(getService(ctx, 'workStore'), 'backendFor')) capabilities['os.works'] = '1.0.0'
|
|
33
37
|
return capabilities
|
|
34
38
|
}
|
|
@@ -3,7 +3,9 @@ import { parseVersion } from '../../abi/version.mjs'
|
|
|
3
3
|
import { AbiError, ERROR_CODES } from '../../abi/errors.mjs'
|
|
4
4
|
|
|
5
5
|
const ACCESSORS = ['capabilities', 'log', 'skills', 'tools', 'http', 'proc', 'ui']
|
|
6
|
-
|
|
6
|
+
/** Host v1 能力→[访问器, 必需方法] 契约。导出为单一真源:内核门面与能力探测都引用它,
|
|
7
|
+
* 不再各自硬编码 os.plugins 的 dsh 方法名(listBundles/setPluginEnabled…)。 */
|
|
8
|
+
export const HOST_SERVICE_CONTRACT = {
|
|
7
9
|
'os.skills': ['skills', ['registerProvider']],
|
|
8
10
|
'os.tools': ['tools', ['register']],
|
|
9
11
|
'os.net': ['http', ['createApp', 'createSharedHost']],
|
|
@@ -12,6 +14,7 @@ const SERVICES = {
|
|
|
12
14
|
'os.ui': ['ui', ['createEditorHost']],
|
|
13
15
|
'os.plugins': ['plugins', ['listBundles', 'listPlugins', 'setBundleEnabled', 'setPluginEnabled']],
|
|
14
16
|
'os.assets': ['assets', ['put', 'get']],
|
|
17
|
+
'os.works': ['works', ['backendFor']],
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
function invalid(path, expectation) {
|
|
@@ -68,7 +71,7 @@ export function assertHostContract(host) {
|
|
|
68
71
|
if (typeof logger[method] !== 'function') invalid(`host.log().${method}`, 'must be a function')
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
|
-
for (const [capability, [accessor, methods]] of Object.entries(
|
|
74
|
+
for (const [capability, [accessor, methods]] of Object.entries(HOST_SERVICE_CONTRACT)) {
|
|
72
75
|
if (!Object.hasOwn(capabilities, capability)) continue
|
|
73
76
|
if (typeof host[accessor] !== 'function') {
|
|
74
77
|
invalid(`host.${accessor}`, `must be a function when advertising ${capability}`)
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
* web() { register({kind, path, handler}) => dispose, port } | undefined
|
|
16
16
|
* proc() { start(serviceSpec) => Promise<{errors?}>, stop(id) }
|
|
17
17
|
* ui() { createEditorHost({ id, dir, basePath, index }) }
|
|
18
|
+
* assets() { put, get, ... } | undefined —— 资产字节仓(asset-service)
|
|
19
|
+
* works() { backendFor, claimSessionMode, ... } | undefined —— 作品目录(work-store,
|
|
20
|
+
* 可选持久化层:缺席时内核 os.works 返回 null,应用自行降级内存态)
|
|
18
21
|
*
|
|
19
22
|
* `web()` 是宿主网页端口本身(dsh 即 ctx.webServer)。拿到它时,内核一律把 HTTP
|
|
20
23
|
* 挂到该端口的路径前缀下,不再另起端口;拿不到才退回 os.net 的独立监听。
|
|
@@ -46,5 +49,6 @@ export function createDshHost(ctx) {
|
|
|
46
49
|
ui: () => getService(ctx, 'editorHost'),
|
|
47
50
|
plugins: () => getService(ctx, 'pluginManager'),
|
|
48
51
|
assets: () => getService(ctx, 'assets'),
|
|
52
|
+
works: () => getService(ctx, 'workStore'),
|
|
49
53
|
}
|
|
50
54
|
}
|
|
@@ -13,7 +13,8 @@ import { AbiError, ERROR_CODES, toAbiError } from '../abi/errors.mjs'
|
|
|
13
13
|
import { createLoader } from '../abi/loader.mjs'
|
|
14
14
|
import { BASE_CAPABILITIES, detectDshCapabilities } from './host/caps.mjs'
|
|
15
15
|
import { createDshHost } from './host/dsh.mjs'
|
|
16
|
-
import { assertHostContract } from './host/contract.mjs'
|
|
16
|
+
import { assertHostContract, HOST_SERVICE_CONTRACT } from './host/contract.mjs'
|
|
17
|
+
import { assetUrl } from '../abi/assets.mjs'
|
|
17
18
|
import { createSkillAdapter } from './adapters/skill-provider.mjs'
|
|
18
19
|
import { createToolProviderAdapter } from './adapters/tool-provider.mjs'
|
|
19
20
|
import { createRuntimeDriverAdapter } from './adapters/runtime-driver.mjs'
|
|
@@ -88,7 +89,8 @@ export function createKernel(ctx, config = {}, options = {}) {
|
|
|
88
89
|
|
|
89
90
|
function pluginManager() {
|
|
90
91
|
const service = hostService('plugins', 'os.plugins')
|
|
91
|
-
|
|
92
|
+
// 方法名单一真源 = Host 契约(contract.mjs),内核不再硬编码 dsh 方法名。
|
|
93
|
+
for (const method of HOST_SERVICE_CONTRACT['os.plugins'][1]) {
|
|
92
94
|
if (typeof service[method] !== 'function') {
|
|
93
95
|
throw new AbiError(ERROR_CODES.E_CAP_MISSING,
|
|
94
96
|
`os.plugins 不可用:pluginManager 缺少 ${method}`, { capability: 'os.plugins', method })
|
|
@@ -143,7 +145,15 @@ export function createKernel(ctx, config = {}, options = {}) {
|
|
|
143
145
|
assets: {
|
|
144
146
|
put: (value, contentType) => hostService('assets', 'os.assets').put(value, contentType),
|
|
145
147
|
get: (id) => hostService('assets', 'os.assets').get(id),
|
|
146
|
-
url: (id) =>
|
|
148
|
+
url: (id) => assetUrl(id),
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
/** 作品目录门面(可选持久化层):work-store 缺席时返回 null,应用自行降级内存态。
|
|
152
|
+
* 与 os.assets(必需字节仓,缺席抛 E_CAP_MISSING)不同——works 是可选增强,
|
|
153
|
+
* 不在 core 六件内。用 os.caps.has('os.works') 探测可用性,不再 safeGet(ctx,'workStore') 裸摸。 */
|
|
154
|
+
get works() {
|
|
155
|
+
const service = typeof host.works === 'function' ? host.works() : null
|
|
156
|
+
return service && typeof service.then !== 'function' ? service : null
|
|
147
157
|
},
|
|
148
158
|
|
|
149
159
|
/** 能力检查与自报。 */
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"./service/mcp-http": "./src/service/mcp-http.mjs",
|
|
11
11
|
"./service/server": "./src/service/server.mjs",
|
|
12
12
|
"./service/api": "./src/service/api.mjs",
|
|
13
|
+
"./service/static": "./src/service/static.mjs",
|
|
13
14
|
"./tools/validate": "./src/tools/validate.mjs",
|
|
14
15
|
"./tools/result": "./src/tools/result.mjs",
|
|
15
16
|
"./skills/provider": "./src/skills/provider.mjs",
|
|
16
17
|
"./editor/transport": "./src/editor/transport.js",
|
|
17
18
|
"./editor/lease": "./src/editor/lease.mjs",
|
|
19
|
+
"./editor/heartbeat": "./src/editor/heartbeat.mjs",
|
|
18
20
|
"./editor/shadow": "./src/editor/shadow.mjs",
|
|
19
21
|
"./store/journal-store": "./src/store/journal-store.mjs",
|
|
20
22
|
"./store/blob-store": "./src/store/blob-store.mjs",
|
|
@@ -45,7 +45,10 @@ self.onmessage = function(e) {
|
|
|
45
45
|
function startHeartbeat() {
|
|
46
46
|
if (intervalHandle) clearInterval(intervalHandle);
|
|
47
47
|
|
|
48
|
-
//
|
|
48
|
+
// 心跳节奏统一为 3s:单一真源是 editor/heartbeat.mjs 的 HEARTBEAT_INTERVAL_MS。
|
|
49
|
+
// 本文件是原样拷贝的经典 Worker,运行时不能 import npm 模块,故以字面量承载节奏,
|
|
50
|
+
// 由 test/heartbeat-constants.test.mjs 钉死与常量一致,防止再次漂移。
|
|
51
|
+
// 心跳对象是编辑器「在场租约」(editor-host /claim);两层租约语义见 heartbeat.mjs 头注。
|
|
49
52
|
intervalHandle = setInterval(() => {
|
|
50
53
|
if (!active) return;
|
|
51
54
|
|
|
@@ -66,7 +69,7 @@ function startHeartbeat() {
|
|
|
66
69
|
});
|
|
67
70
|
}
|
|
68
71
|
});
|
|
69
|
-
},
|
|
72
|
+
}, 3000);
|
|
70
73
|
|
|
71
74
|
// 立即发送第一次
|
|
72
75
|
sendClaim().catch(() => {});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 编辑器「在场租约」心跳节奏常量单一真源(P2-13b)。
|
|
3
|
+
*
|
|
4
|
+
* 背景:心跳节奏曾在两处手工对齐而漂移——plugin-kit 的 heartbeat-worker.js 写死
|
|
5
|
+
* 4000ms(还留着「避免 5 秒判过期」的过期注释),document-workbench 客户端却是
|
|
6
|
+
* 3000ms。两者必须同拍,否则编辑器判活与文档 owner 判活快慢不一。这里把节奏收敛
|
|
7
|
+
* 成一个常量,客户端直接 import;worker 是原样拷贝的经典 Web Worker(运行时不能
|
|
8
|
+
* import npm 模块),其 setInterval 字面量由 test/heartbeat-constants.test.mjs 钉死
|
|
9
|
+
* 等于本常量,防止再次漂移。统一取架构审查建议的 3s。
|
|
10
|
+
*
|
|
11
|
+
* 两层租约语义不同,都要保留(本常量只统一「心跳节奏」,不合并两层租约):
|
|
12
|
+
* 1. 在场租约(presence)——@capyclaw/plugin-kit/editor/lease.mjs 的 createEditorLease,
|
|
13
|
+
* 由 editor-host 的 /claim 消费,「显示即连接」:新窗口强制抢占、旧窗口静默待命;
|
|
14
|
+
* TTL 10s、无 epoch,靠客户端每 HEARTBEAT_INTERVAL_MS 心跳续租。
|
|
15
|
+
* 2. 所有权租约(owner)——@capyclaw/document-workbench/session 的 claimOwner/OWNER_TTL,
|
|
16
|
+
* deck/文档级所有权,带 epoch fencing(换人 +1、旧 owner 回执被丢弃)。PPT 的
|
|
17
|
+
* A/projects/ppt/src/server/store/lease.mjs 只是它的兼容再导出。此为套件领域件,
|
|
18
|
+
* 不在本次改造范围,仅在此说清两层,避免误把在场租约当成所有权租约。
|
|
19
|
+
* 两条租约线共用「心跳 3s、TTL 10s」的并发协议;TTL 的运行时真源仍是 lease.mjs 的
|
|
20
|
+
* DEFAULT_TTL 与 document-workbench 的 OWNER_TTL(均已为 10s,未漂移,不在本次改动范围)。
|
|
21
|
+
*
|
|
22
|
+
* 本文件零依赖、browser-safe(无 node:*),可被编辑器客户端 bundle 直接 import。
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** 心跳间隔(毫秒):在场租约与文档 owner 租约共用的续租节奏,单一真源。 */
|
|
26
|
+
export const HEARTBEAT_INTERVAL_MS = 3000
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 静态文件服务公共核心(P2-13a)。
|
|
3
|
+
*
|
|
4
|
+
* service-host 与 editor-host 各有一套静态文件服务,其中「路径穿越防护 / 挂载前缀
|
|
5
|
+
* 归一与命中 / 相对路径解码 / files 显式映射 / 基础响应头」这几段逻辑逐字重复。
|
|
6
|
+
* 这里把它们收敛成一组纯函数作为单一真源,两个宿主都 import 本文件,不再各写一份。
|
|
7
|
+
*
|
|
8
|
+
* 边界(刻意不收敛的部分):本文件只做「无 IO 的路径/头部计算」,不碰响应政策。
|
|
9
|
+
* 两宿主的行为差异必须各自保留——
|
|
10
|
+
* - 畸形百分号编码:service-host 回 400,editor-host 交还路由链(return false);
|
|
11
|
+
* - 目录入口补尾斜杠 301、ETag/gzip/304/vary:仅 editor-host;
|
|
12
|
+
* - content-type 取值:service-host 用 mimeFor(请求 rel) + explicitType,
|
|
13
|
+
* editor-host 用 mimeFor(落盘文件路径);
|
|
14
|
+
* - 读盘策略:service-host 每次 readFileSync,editor-host 走 (size,mtime) 缓存。
|
|
15
|
+
* 因此 decodeStaticRel 畸形时返回 null(而非抛错/替宿主回响应),由调用方决定 400 还是放行。
|
|
16
|
+
*
|
|
17
|
+
* 只依赖 node 内置(node:path),不 import 本包其它文件,不成环(与 util/http.mjs 同风格)。
|
|
18
|
+
*/
|
|
19
|
+
import path from 'node:path'
|
|
20
|
+
|
|
21
|
+
/** 路径穿越防护:只允许落在 root 内(含 root 自身),越界返回 null。两宿主共用。 */
|
|
22
|
+
export function safeJoin(root, rel) {
|
|
23
|
+
const target = path.resolve(root, `.${path.sep}${rel}`)
|
|
24
|
+
const base = path.resolve(root)
|
|
25
|
+
return target === base || target.startsWith(base + path.sep) ? target : null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 挂载前缀归一:'/' → ''(挂全部);其余去掉尾斜杠。空/缺省按 '' 处理。 */
|
|
29
|
+
export function cleanStaticPrefix(prefix) {
|
|
30
|
+
return prefix === '/' ? '' : String(prefix || '').replace(/\/+$/, '')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 前缀命中:空前缀命中一切;非空须精确等于前缀或其子路径。 */
|
|
34
|
+
export function staticPrefixHit(pathname, prefix) {
|
|
35
|
+
return !prefix || pathname === prefix || pathname.startsWith(prefix + '/')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 去掉挂载前缀后的原始相对路径(未解码)。 */
|
|
39
|
+
export function staticRelRaw(pathname, prefix) {
|
|
40
|
+
return prefix ? pathname.slice(prefix.length) : pathname
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 解码相对路径:空/'/' 落到 index;其余去掉 leading 斜杠后 decodeURIComponent。
|
|
45
|
+
* 畸形百分号编码(URIError)返回 null——由宿主决定回 400(service-host)还是
|
|
46
|
+
* 交还路由链(editor-host),本核心不替宿主做响应政策。
|
|
47
|
+
*/
|
|
48
|
+
export function decodeStaticRel(relRaw, index = 'index.html') {
|
|
49
|
+
try {
|
|
50
|
+
return relRaw === '' || relRaw === '/' ? index : decodeURIComponent(relRaw.replace(/^\/+/, ''))
|
|
51
|
+
} catch {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** files 显式映射查表:relRaw 为空时用 '/' 键;未命中返回 null(宿主交还路由链)。 */
|
|
57
|
+
export function staticFileHit(files, relRaw) {
|
|
58
|
+
if (!files) return null
|
|
59
|
+
return files[relRaw === '' ? '/' : relRaw] || files[relRaw] || null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 映射条目 → [文件名, 显式 content-type(可空)]。字符串条目无显式 type。 */
|
|
63
|
+
export function staticHitNameType(hit) {
|
|
64
|
+
return Array.isArray(hit) ? [hit[0], hit[1]] : [hit, undefined]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 静态 200 基础响应头:content-type/length + 安全与缓存政策(两宿主一致的五项)。
|
|
69
|
+
* no-cache = 允许缓存但每次回源校验;editor-host 会在此之上追加 etag/vary。
|
|
70
|
+
*/
|
|
71
|
+
export function staticBaseHeaders(type, length) {
|
|
72
|
+
return {
|
|
73
|
+
'content-type': type,
|
|
74
|
+
'content-length': length,
|
|
75
|
+
'x-content-type-options': 'nosniff',
|
|
76
|
+
'referrer-policy': 'no-referrer',
|
|
77
|
+
'cache-control': 'no-cache',
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -575,7 +575,7 @@ export class WorkspaceClient {
|
|
|
575
575
|
|
|
576
576
|
/** 插件的 JournalStore 持久化接口 → 中间层 workspace。 */
|
|
577
577
|
export class WorkspaceBackend {
|
|
578
|
-
constructor({ client, workId = 'main', journalPath = null }) {
|
|
578
|
+
constructor({ client, workId = 'main', journalPath = null, project = null }) {
|
|
579
579
|
/* 结构化契约:workspace-service 可能来自另一份 kit 快照。 */
|
|
580
580
|
if (!client || typeof client.put !== 'function' || typeof client.getJson !== 'function') {
|
|
581
581
|
throw new Error('WorkspaceBackend 需要 WorkspaceClient 兼容实现')
|
|
@@ -583,6 +583,9 @@ export class WorkspaceBackend {
|
|
|
583
583
|
this.client = client
|
|
584
584
|
this.workId = workId
|
|
585
585
|
this.journalPath = journalPath || null
|
|
586
|
+
/* checkpoint 列表投影(形状声明):内核只产出通用信封,业务字段(如 PPT 的 slides)
|
|
587
|
+
* 由套件适配层传入 project(payload, base) 叠加。缺省纯信封,不硬编码任何业务名词。 */
|
|
588
|
+
this.project = typeof project === 'function' ? project : null
|
|
586
589
|
this.stateKey = 'state.json'
|
|
587
590
|
this.journalKey = 'journal.jsonl'
|
|
588
591
|
this.checkpointPrefix = 'checkpoints/'
|
|
@@ -624,23 +627,27 @@ export class WorkspaceBackend {
|
|
|
624
627
|
return { name, createdAt: payload.createdAt, meta: payload.meta || {} }
|
|
625
628
|
}
|
|
626
629
|
|
|
627
|
-
listCheckpoints() {
|
|
630
|
+
listCheckpoints(opts = {}) {
|
|
631
|
+
const project = typeof opts.project === 'function' ? opts.project : this.project
|
|
628
632
|
return this.client.list(this.workId)
|
|
629
633
|
.filter((item) => item.key.startsWith(this.checkpointPrefix) && item.key.endsWith('.json'))
|
|
630
634
|
.map((item) => {
|
|
631
635
|
try {
|
|
632
636
|
const payload = this.client.getJson(this.workId, item.key)
|
|
633
637
|
if (!payload) return null
|
|
634
|
-
|
|
638
|
+
/* 通用会话信封:不含任何业务名词(slides/deck 等)。业务字段经 project 叠加。
|
|
639
|
+
* 约定与 document-workbench projectCheckpoint 一致:project(payload, base) 只返回
|
|
640
|
+
* 「扩展字段」,由 backend 合并 base({...base, ...extra}),保证 name/createdAt/meta 不丢。 */
|
|
641
|
+
const base = {
|
|
635
642
|
name: payload.name,
|
|
636
643
|
seq: payload.seq,
|
|
637
644
|
appliedSeq: payload.appliedSeq,
|
|
638
645
|
pending: !!payload.pending,
|
|
639
646
|
title: payload.title,
|
|
640
|
-
slides: payload.slides,
|
|
641
647
|
createdAt: payload.createdAt,
|
|
642
648
|
meta: payload.meta || {},
|
|
643
649
|
}
|
|
650
|
+
return project ? { ...base, ...project(payload, base) } : base
|
|
644
651
|
} catch { return null }
|
|
645
652
|
})
|
|
646
653
|
.filter(Boolean)
|
|
@@ -650,7 +657,8 @@ export class WorkspaceBackend {
|
|
|
650
657
|
readCheckpoint(name) {
|
|
651
658
|
const key = `${this.checkpointPrefix}${name}.json`
|
|
652
659
|
const payload = this.client.getJson(this.workId, key, null)
|
|
653
|
-
|
|
660
|
+
/* 只校验载荷存在;业务形状(如 PPT 的 deck)由套件适配层 / DocumentSession 的 documentKey 校验。 */
|
|
661
|
+
if (!payload) throw new Error('checkpoint 内容损坏: ' + name)
|
|
654
662
|
return payload
|
|
655
663
|
}
|
|
656
664
|
}
|
|
@@ -525,6 +525,166 @@ window.__ModuleLoader__.load({
|
|
|
525
525
|
WINDOW_KIT.inject = []
|
|
526
526
|
WINDOW_KIT.apply = function () {}
|
|
527
527
|
|
|
528
|
+
/* ── 可见性驱动器:表面生命周期标准的宿主侧真源 ────────────────────────
|
|
529
|
+
* 依据 docs/SURFACE-LIFECYCLE-STANDARD.md §3/§4/§5:宿主是表面可见性的唯一真源,
|
|
530
|
+
* 聚合三路探针 —— (a) 表面是否当前主内容 shown、(b) 顶层 tab 是否隐藏 tabHidden、
|
|
531
|
+
* (c) 窗口是否焦点 focused —— 算出四态经统一信号通道下发。iframe 内 document.hidden
|
|
532
|
+
* 只反映顶层 tab,探不到「被宿主藏起来」,所以表面可见性必须宿主显式告知。
|
|
533
|
+
*
|
|
534
|
+
* 协议常量与 C/packages/capyclaw-foundation/abi/visibility.mjs 逐字段一致:
|
|
535
|
+
* 本文件是 CJS 自包含叶子,无法 import 那份 ESM,只能内联同名常量,
|
|
536
|
+
* 由 test/visibility.test.mjs 的 parity 用例钉死漂移。改协议先改 abi 再同步这里。
|
|
537
|
+
*
|
|
538
|
+
* 边界:驱动器只管「算状态 + 发信号 + 预算计时」;display/卸载 iframe 的动作、
|
|
539
|
+
* postMessage 的具体投递由 portal-hud 拿 send/onDetach 回调去做。权威/桥接面
|
|
540
|
+
* (租约心跳、apply/ack)不受这里任何状态影响 —— 只有渲染面响应可见性。
|
|
541
|
+
*/
|
|
542
|
+
WINDOW_KIT.visibility = {
|
|
543
|
+
/* 宿主 → iframe:{ type, state, sid },targetOrigin 同源。 */
|
|
544
|
+
MESSAGE: 'capyclaw:workbench:visibility',
|
|
545
|
+
/* iframe → 宿主 的回执;detached 由宿主直接卸载,无需回执。 */
|
|
546
|
+
ACK_MESSAGE: 'capyclaw:workbench:visibility-ack',
|
|
547
|
+
STATES: ['foreground', 'background', 'hidden', 'detached'],
|
|
548
|
+
DEFAULTS: { detachAfterMs: 120000, visibilityAckTimeoutMs: 1500, hiddenGraceMs: 250 },
|
|
549
|
+
|
|
550
|
+
/* 纯函数:三路探针 → 目标态。!shown||tabHidden→hidden;可见非焦点→background;否则 foreground。 */
|
|
551
|
+
computeState: function (input) {
|
|
552
|
+
var p = input || {}
|
|
553
|
+
if (!p.shown || p.tabHidden) return 'hidden'
|
|
554
|
+
if (!p.focused) return 'background'
|
|
555
|
+
return 'foreground'
|
|
556
|
+
},
|
|
557
|
+
|
|
558
|
+
/*
|
|
559
|
+
* 状态机驱动器。opts = { probe, send, onDetach, onAckTimeout, now, timers, defaults, pollMs }:
|
|
560
|
+
* probe() 宿主探针,返回 { shown, tabHidden, focused }
|
|
561
|
+
* send(state) 状态变化时调用(含 start 的初始状态);投递 postMessage 是宿主的事
|
|
562
|
+
* onDetach() hidden 持续 detachAfterMs 后卸载回调,一次
|
|
563
|
+
* onAckTimeout(s) send(s) 后 visibilityAckTimeoutMs 内没 notifyAck(s),一次
|
|
564
|
+
* now / timers 可注入的时钟与定时器面(确定性测试用);默认 Date.now 与全局四件套
|
|
565
|
+
* defaults 覆盖 DEFAULTS 的个别预算;pollMs 轮询节奏,默认 200
|
|
566
|
+
*
|
|
567
|
+
* 行为契约:
|
|
568
|
+
* - 可见→hidden 去抖 hiddenGraceMs(宽限内回可见即取消);回可见态立即;
|
|
569
|
+
* - hidden 起算 detachAfterMs(now 计时,随 tick 检查)→ detached + onDetach 一次;
|
|
570
|
+
* - 每次 send(除 detached)挂一个 ack 等待,新 send 取代旧的等待;
|
|
571
|
+
* - start/stop 幂等;stop 清掉 interval/去抖/ack 全部定时器,无泄漏。
|
|
572
|
+
*/
|
|
573
|
+
createDriver: function (opts) {
|
|
574
|
+
var o = opts || {}
|
|
575
|
+
var base = WINDOW_KIT.visibility.DEFAULTS
|
|
576
|
+
var d = o.defaults || {}
|
|
577
|
+
var defaults = {
|
|
578
|
+
detachAfterMs: typeof d.detachAfterMs === 'number' ? d.detachAfterMs : base.detachAfterMs,
|
|
579
|
+
visibilityAckTimeoutMs: typeof d.visibilityAckTimeoutMs === 'number' ? d.visibilityAckTimeoutMs : base.visibilityAckTimeoutMs,
|
|
580
|
+
hiddenGraceMs: typeof d.hiddenGraceMs === 'number' ? d.hiddenGraceMs : base.hiddenGraceMs
|
|
581
|
+
}
|
|
582
|
+
var probe = typeof o.probe === 'function' ? o.probe : function () { return { shown: true, tabHidden: false, focused: true } }
|
|
583
|
+
var send = typeof o.send === 'function' ? o.send : function () {}
|
|
584
|
+
var onDetach = typeof o.onDetach === 'function' ? o.onDetach : function () {}
|
|
585
|
+
var onAckTimeout = typeof o.onAckTimeout === 'function' ? o.onAckTimeout : function () {}
|
|
586
|
+
var now = typeof o.now === 'function' ? o.now : Date.now
|
|
587
|
+
var timers = o.timers || { setTimeout: setTimeout, clearTimeout: clearTimeout, setInterval: setInterval, clearInterval: clearInterval }
|
|
588
|
+
var pollMs = typeof o.pollMs === 'number' ? o.pollMs : 200
|
|
589
|
+
|
|
590
|
+
var running = false
|
|
591
|
+
var current = null
|
|
592
|
+
/* hidden 起算时刻(now 计时);离开 hidden 即清。detached 预算随 tick 检查,
|
|
593
|
+
* 不另挂定时器 —— 少一个要对称清理的定时器,账目更干净。 */
|
|
594
|
+
var hiddenSince = null
|
|
595
|
+
var pollId = null
|
|
596
|
+
var graceId = null
|
|
597
|
+
var ackId = null
|
|
598
|
+
var ackState = null
|
|
599
|
+
|
|
600
|
+
function clearGrace() {
|
|
601
|
+
if (graceId !== null) { timers.clearTimeout(graceId); graceId = null }
|
|
602
|
+
}
|
|
603
|
+
function clearAck() {
|
|
604
|
+
if (ackId !== null) { timers.clearTimeout(ackId); ackId = null }
|
|
605
|
+
ackState = null
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/* 提交一个新状态:发信号、按状态挂/清预算。同态重复提交是空操作。 */
|
|
609
|
+
function commit(state) {
|
|
610
|
+
if (state === current) return
|
|
611
|
+
clearGrace()
|
|
612
|
+
current = state
|
|
613
|
+
hiddenSince = state === 'hidden' ? now() : null
|
|
614
|
+
send(state)
|
|
615
|
+
/* 新信号取代旧的回执等待;detached 由宿主直接卸载,无需回执。 */
|
|
616
|
+
clearAck()
|
|
617
|
+
if (state === 'detached') {
|
|
618
|
+
onDetach()
|
|
619
|
+
return
|
|
620
|
+
}
|
|
621
|
+
ackState = state
|
|
622
|
+
ackId = timers.setTimeout(function () {
|
|
623
|
+
ackId = null
|
|
624
|
+
var s = ackState
|
|
625
|
+
ackState = null
|
|
626
|
+
if (s !== null) onAckTimeout(s)
|
|
627
|
+
}, defaults.visibilityAckTimeoutMs)
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/* 一次探针 + 状态迁移。start 后的 interval 与手动 tick 都走这里。 */
|
|
631
|
+
function tick() {
|
|
632
|
+
if (!running) return
|
|
633
|
+
var target = WINDOW_KIT.visibility.computeState(probe())
|
|
634
|
+
if (target === 'hidden') {
|
|
635
|
+
if (current === 'hidden') {
|
|
636
|
+
/* 久藏卸载:hidden 持续 detachAfterMs 才进 detached(标准 §3 预算)。 */
|
|
637
|
+
if (hiddenSince !== null && now() - hiddenSince >= defaults.detachAfterMs) commit('detached')
|
|
638
|
+
return
|
|
639
|
+
}
|
|
640
|
+
/* 已 detached 就停在 detached,等回可见再重建,不重复卸载。 */
|
|
641
|
+
if (current === 'detached') return
|
|
642
|
+
/* 初始即 hidden:没有「可见→hidden」的抖动可言,直接提交。 */
|
|
643
|
+
if (current === null) { commit('hidden'); return }
|
|
644
|
+
/* 可见→hidden 去抖:宽限内回可见即取消;已在宽限中不重置截止。 */
|
|
645
|
+
if (graceId === null) {
|
|
646
|
+
graceId = timers.setTimeout(function () {
|
|
647
|
+
graceId = null
|
|
648
|
+
commit('hidden')
|
|
649
|
+
}, defaults.hiddenGraceMs)
|
|
650
|
+
}
|
|
651
|
+
return
|
|
652
|
+
}
|
|
653
|
+
/* 目标是可见态:取消去抖,回 foreground/background 立即(回来即重建,P4)。 */
|
|
654
|
+
clearGrace()
|
|
655
|
+
if (target !== current) commit(target)
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function start() {
|
|
659
|
+
if (running) return
|
|
660
|
+
running = true
|
|
661
|
+
current = null
|
|
662
|
+
hiddenSince = null
|
|
663
|
+
/* 初始状态当场发一次(契约:send 含 start 时的初始状态)。 */
|
|
664
|
+
tick()
|
|
665
|
+
pollId = timers.setInterval(tick, pollMs)
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function stop() {
|
|
669
|
+
if (!running) return
|
|
670
|
+
running = false
|
|
671
|
+
if (pollId !== null) { timers.clearInterval(pollId); pollId = null }
|
|
672
|
+
clearGrace()
|
|
673
|
+
clearAck()
|
|
674
|
+
hiddenSince = null
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/* iframe 回执:取消对应状态的回执等待(别的状态的等待不动)。 */
|
|
678
|
+
function notifyAck(state) {
|
|
679
|
+
if (ackId !== null && ackState === state) clearAck()
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
var driver = { notifyAck: notifyAck, tick: tick, start: start, stop: stop }
|
|
683
|
+
Object.defineProperty(driver, 'state', { enumerable: true, get: function () { return current } })
|
|
684
|
+
return driver
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
528
688
|
module.exports = WINDOW_KIT
|
|
529
689
|
return module.exports
|
|
530
690
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capyclaw/caption-map",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "区域映射 + 侧栏宽度固定 +
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "区域映射 + 侧栏宽度固定 + 聊天窗停靠:把侧栏底部入口行与面板列表映射到标题栏(Windows 原生 / macOS 经标题栏壳归一,单一真源按系统自适应);侧栏宽度锁定为拖拽上限(可配置);并把会话面板整块搬进侧栏底部的槽里(跨平台常驻)。纯页面改动,停用即还原。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"exports": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"meta": {
|
|
32
32
|
"title": "底栏映射 + 固定侧栏 + 侧栏聊天窗",
|
|
33
|
-
"description": "把底部入口行(更多 + 手机/电脑远程等 sidebar.footer.action
|
|
33
|
+
"description": "把底部入口行(更多 + 手机/电脑远程等 sidebar.footer.action 注册项)几何映射到标题栏行(Windows 原生 / macOS 经标题栏壳归一);侧栏面板列表收成标题栏「其他」分组;侧栏宽度固定为拖拽上限 420px(fixedSidebarWidth 可关);会话面板整块停靠在侧栏底部(含输入框)。占用方零改动,所有页面改动可撤销,停用立即还原。"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"index.js",
|