@weitc/dfy-awesome-sidebar 0.0.0-stage → 1.0.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 (120) hide show
  1. package/CHANGELOG.md +4540 -0
  2. package/FEASIBILITY.md +250 -0
  3. package/INSTALL.md +93 -0
  4. package/LICENSE +43 -0
  5. package/README.md +170 -2
  6. package/assets/backgrounds/sidebar-default.jpg +0 -0
  7. package/assets/eggs/325/avatar.png +0 -0
  8. package/assets/eggs/325/baka-65-105-40s.webm +0 -0
  9. package/assets/eggs/325/stage.jpg +0 -0
  10. package/assets/eggs/347/avatar.png +0 -0
  11. package/assets/eggs/347/stage.jpg +0 -0
  12. package/assets/eggs/347/track-10-50-40s.webm +0 -0
  13. package/assets/themes/glass/actions-frame.css +90 -0
  14. package/assets/themes/glass/brand-frame.css +64 -0
  15. package/assets/themes/glass/footer-frame.css +111 -0
  16. package/assets/themes/glass/header-frame.css +285 -0
  17. package/assets/themes/glass/options-frame.css +129 -0
  18. package/assets/themes/glass/sidebar-outer.css +66 -0
  19. package/assets/themes/glass/topbar-frame.css +91 -0
  20. package/assets/themes/metal/actions-frame.css +90 -0
  21. package/assets/themes/metal/brand-frame.css +64 -0
  22. package/assets/themes/metal/footer-frame.css +111 -0
  23. package/assets/themes/metal/header-frame.css +300 -0
  24. package/assets/themes/metal/options-frame.css +129 -0
  25. package/assets/themes/metal/sidebar-outer.css +66 -0
  26. package/assets/themes/metal/topbar-frame.css +91 -0
  27. package/assets/themes/minimal/actions-frame.css +90 -0
  28. package/assets/themes/minimal/brand-frame.css +64 -0
  29. package/assets/themes/minimal/footer-frame.css +115 -0
  30. package/assets/themes/minimal/header-frame.css +271 -0
  31. package/assets/themes/minimal/options-frame.css +129 -0
  32. package/assets/themes/minimal/sidebar-outer.css +66 -0
  33. package/assets/themes/minimal/topbar-frame.css +91 -0
  34. package/assets/themes/neon/actions-frame.css +90 -0
  35. package/assets/themes/neon/brand-frame.css +64 -0
  36. package/assets/themes/neon/footer-frame.css +111 -0
  37. package/assets/themes/neon/header-frame.css +286 -0
  38. package/assets/themes/neon/options-frame.css +129 -0
  39. package/assets/themes/neon/sidebar-outer.css +66 -0
  40. package/assets/themes/neon/topbar-frame.css +91 -0
  41. package/assets/themes/ocean/actions-frame.css +90 -0
  42. package/assets/themes/ocean/brand-frame.css +64 -0
  43. package/assets/themes/ocean/footer-frame.css +111 -0
  44. package/assets/themes/ocean/header-frame.css +287 -0
  45. package/assets/themes/ocean/options-frame.css +129 -0
  46. package/assets/themes/ocean/sidebar-outer.css +66 -0
  47. package/assets/themes/ocean/topbar-frame.css +91 -0
  48. package/assets/themes/oldday/actions-frame.css +90 -0
  49. package/assets/themes/oldday/brand-frame.css +43 -0
  50. package/assets/themes/oldday/footer-frame.css +116 -0
  51. package/assets/themes/oldday/header-frame.css +142 -0
  52. package/assets/themes/oldday/options-frame.css +129 -0
  53. package/assets/themes/oldday/sidebar-outer.css +69 -0
  54. package/assets/themes/oldday/topbar-frame.css +91 -0
  55. package/assets/themes/pop/actions-frame.css +3 -0
  56. package/assets/themes/pop/brand-frame.css +3 -0
  57. package/assets/themes/pop/footer-frame.css +3 -0
  58. package/assets/themes/pop/header-frame.css +289 -0
  59. package/assets/themes/pop/options-frame.css +3 -0
  60. package/assets/themes/pop/pop-dust.css +37 -0
  61. package/assets/themes/pop/sidebar-outer.css +3 -0
  62. package/assets/themes/pop/topbar-frame.css +3 -0
  63. package/assets/themes/vaporwave/actions-frame.css +3 -0
  64. package/assets/themes/vaporwave/brand-frame.css +3 -0
  65. package/assets/themes/vaporwave/footer-frame.css +3 -0
  66. package/assets/themes/vaporwave/header-frame.css +436 -0
  67. package/assets/themes/vaporwave/options-frame.css +3 -0
  68. package/assets/themes/vaporwave/sidebar-outer.css +3 -0
  69. package/assets/themes/vaporwave/topbar-frame.css +3 -0
  70. package/assets/themes/vaporwave/vapor-dust.css +40 -0
  71. package/client.js +8116 -0
  72. package/cordis.patch.yml +6 -0
  73. package/docs/ACCEPTANCE-/345/244/264/345/203/217/351/242/204/350/247/210-20261201.md +42 -0
  74. package/docs/DETAIL.md +1 -0
  75. package/docs/DETAIL.zh.md +1 -0
  76. package/docs/pin-compare.png +0 -0
  77. package/docs/pin-modes.png +0 -0
  78. package/docs/preview.svg +84 -0
  79. package/docs/shot-fix7.png +0 -0
  80. package/docs/shot-frame-ocean.png +0 -0
  81. package/docs/shot-metal.png +0 -0
  82. package/docs/shot-stars.png +0 -0
  83. package/docs/shot-zones.png +0 -0
  84. package/icon.svg +5 -0
  85. package/index.js +2015 -0
  86. package/locale/en.json +7 -0
  87. package/locale/zh.json +7 -0
  88. package/package.json +58 -3
  89. package/pin.ps1 +172 -0
  90. package/rollback.ps1 +196 -0
  91. package/tools/__pycache__/pack-release.cpython-312.pyc +0 -0
  92. package/tools/_slice.txt +9 -0
  93. package/tools/boot.cjs +16 -0
  94. package/tools/build-frame-css.cjs +33 -0
  95. package/tools/check-docs.ps1 +41 -0
  96. package/tools/check-names.ps1 +35 -0
  97. package/tools/extract.cjs +28 -0
  98. package/tools/find-in-asar.cjs +43 -0
  99. package/tools/list-dir.cjs +21 -0
  100. package/tools/list-pkgs.cjs +10 -0
  101. package/tools/probe-delay.cjs +109 -0
  102. package/tools/probe-star-icon.cjs +164 -0
  103. package/tools/proof-glow-persist.cjs +102 -0
  104. package/tools/proof-migration.cjs +88 -0
  105. package/tools/proof-opacity.cjs +153 -0
  106. package/tools/proof-race.cjs +103 -0
  107. package/tools/run-asar.ps1 +53 -0
  108. package/tools/run.cmd +8 -0
  109. package/tools/scan.cjs +24 -0
  110. package/tools/smoke.cjs +179 -0
  111. package/tools/source-health.cjs +165 -0
  112. package/tools/splice.cjs +20 -0
  113. package/tools/test-account.cjs +74 -0
  114. package/tools/test-client.cjs +265 -0
  115. package/tools/test-dom.cjs +258 -0
  116. package/tools/test-host.cjs +500 -0
  117. package/tools/test-menu.cjs +591 -0
  118. package/tools/test-recharge.cjs +111 -0
  119. package/tools/test-v20.cjs +1793 -0
  120. package/workspace-pin.cmd +8 -0
@@ -0,0 +1,265 @@
1
+ // test-client.cjs — 用假 ModuleLoader / 假 React / 假 ctx 跑 client.js(v2 规格)
2
+ // 无浏览器环境:只验证注册结构、菜单项行为、请求形状、状态回灌与降级。
3
+ // 用法:run-asar.ps1 test-client.cjs <client.js 绝对路径>
4
+ module.exports = async function (args) {
5
+ const fs = require('node:fs');
6
+ const vm = require('node:vm');
7
+
8
+ const file = args[0];
9
+ const source = fs.readFileSync(file, 'utf8');
10
+
11
+ const problems = [];
12
+ const expect = (condition, message) => { if (!condition) problems.push(message); return condition; };
13
+
14
+ const entries = [];
15
+ const requests = [];
16
+ let remote = {
17
+ pinnedWorkspaceId: null,
18
+ starredWorkspaces: [],
19
+ starredSessions: [],
20
+ workspaceIds: ['w-a', 'w-b'],
21
+ };
22
+ let hostDown = false;
23
+
24
+ const reply = (value) => ({ ok: true, status: 200, json: async () => value });
25
+
26
+ const sandbox = {
27
+ console,
28
+ URL,
29
+ setTimeout,
30
+ clearTimeout,
31
+ setInterval: () => 1,
32
+ clearInterval: () => {},
33
+ window: {
34
+ __ModuleLoader__: { load(entry) { entries.push(entry); } },
35
+ location: { href: 'http://127.0.0.1:49696/?token=test' },
36
+ },
37
+ fetch: async (url, init) => {
38
+ const method = (init && init.method) || 'GET';
39
+ const body = init && init.body ? JSON.parse(init.body) : undefined;
40
+ requests.push({ url, method, body });
41
+ if (hostDown) return { ok: false, status: 503, json: async () => ({}) };
42
+ if (url.endsWith('/workspace-pin/state')) return reply(remote);
43
+ if (url.endsWith('/workspace-pin/pin')) {
44
+ remote = { ...remote, pinnedWorkspaceId: body.workspaceId };
45
+ return reply(remote);
46
+ }
47
+ if (url.endsWith('/workspace-pin/star')) {
48
+ if (body.kind === 'workspace') {
49
+ const others = remote.starredWorkspaces.filter(id => id !== body.id);
50
+ remote = { ...remote, starredWorkspaces: body.starred ? [...others, body.id] : others };
51
+ } else {
52
+ const others = remote.starredSessions.filter(id => id !== body.id);
53
+ remote = { ...remote, starredSessions: body.starred ? [...others, body.id] : others };
54
+ }
55
+ return reply(remote);
56
+ }
57
+ return { ok: false, status: 404, json: async () => ({}) };
58
+ },
59
+ };
60
+ sandbox.document = undefined;
61
+
62
+ vm.createContext(sandbox);
63
+ vm.runInContext(source, sandbox, { filename: file });
64
+
65
+ expect(entries.length === 1, `应注册 1 个 client entry,实际 ${entries.length}`);
66
+ if (entries.length !== 1) {
67
+ console.log('FAIL');
68
+ for (const p of problems) console.log(' - ' + p);
69
+ return 1;
70
+ }
71
+ expect(entries[0].id === '@local/workspace-pin', 'entry id 应为 @local/workspace-pin');
72
+
73
+ const React = {
74
+ createElement: (type, props, ...children) => ({ type, props, children }),
75
+ useState: (initial) => [initial, () => {}],
76
+ useEffect: () => {},
77
+ };
78
+ const plugin = entries[0].factory((name) => {
79
+ if (name === 'react') return React;
80
+ throw new Error('意外的 require(' + name + ')');
81
+ });
82
+ expect(Array.isArray(plugin.inject) && plugin.inject.includes('contextMenus') && plugin.inject.includes('slots'),
83
+ 'plugin.inject 应包含 contextMenus / slots');
84
+
85
+ /* ---------- 假 ctx ---------- */
86
+ const dict = {
87
+ pin: '置顶工作区', unpin: '取消置顶', star: '星标工作区', unstar: '取消星标',
88
+ starSession: '星标会话', unstarSession: '取消星标',
89
+ pinnedToast: '已置顶「{title}」', unpinnedToast: '已取消置顶「{title}」',
90
+ starredToast: '已星标「{title}」', unstarredToast: '已取消星标「{title}」',
91
+ pinFailed: '置顶失败,请稍后重试', unpinFailed: '取消置顶失败,请稍后重试',
92
+ starFailed: '星标失败,请稍后重试', unstarFailed: '取消星标失败,请稍后重试',
93
+ unavailable: '置顶服务不可用',
94
+ };
95
+ const interpolate = (template, params) => (params
96
+ ? template.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match))
97
+ : template);
98
+
99
+ const effects = [];
100
+ const contributions = [];
101
+ const slotRegistrations = [];
102
+ const notices = [];
103
+ let localeRegistered = null;
104
+
105
+ const ctx = {
106
+ effect(fn, label) {
107
+ const disposer = fn();
108
+ effects.push({ label, hasDisposer: typeof disposer === 'function' });
109
+ return () => {};
110
+ },
111
+ on() { return () => {}; },
112
+ get() { return undefined; },
113
+ locale: {
114
+ register(ns, dicts) { localeRegistered = { ns, locales: Object.keys(dicts) }; return () => {}; },
115
+ bind() { return (key, params) => interpolate(dict[key] !== undefined ? dict[key] : key, params); },
116
+ },
117
+ slots: {
118
+ inject(name, factory) {
119
+ slotRegistrations.push({ step: 'inject', name });
120
+ const produced = factory();
121
+ if (produced && typeof produced.next === 'function') { for (const _ of produced) { /* 消费 generator */ } }
122
+ return () => {};
123
+ },
124
+ register(options, component) {
125
+ slotRegistrations.push({ step: 'register', options, component });
126
+ return () => {};
127
+ },
128
+ },
129
+ contextMenus: {
130
+ register(contribution) { contributions.push(contribution); return () => {}; },
131
+ notify(text, success) { notices.push({ text, success }); },
132
+ },
133
+ };
134
+
135
+ plugin.apply(ctx);
136
+ await new Promise(resolve => setTimeout(resolve, 20)); // 初次 GET /state
137
+
138
+ expect(localeRegistered && localeRegistered.locales.includes('zh') && localeRegistered.locales.includes('en'),
139
+ '应注册 zh/en 字典');
140
+ expect(effects.length >= 3 && effects.every(e => e.hasDisposer), '每个 ctx.effect 都应返回 disposer');
141
+
142
+ const workspaceMenu = contributions.find(c => c.target === 'workspace');
143
+ const sessionMenu = contributions.find(c => c.target === 'session');
144
+ expect(workspaceMenu && workspaceMenu.id === 'workspace-pin.workspace' && workspaceMenu.order === 150,
145
+ '工作区菜单贡献应为 workspace-pin.workspace / order 150');
146
+ expect(sessionMenu && sessionMenu.id === 'workspace-pin.session', '会话菜单贡献应为 workspace-pin.session');
147
+
148
+ // v0.3 起会话星标改成"常亮"的 DOM 注入(官方 slot 只在 hover 时显示),不再注册 slot。
149
+ expect(!slotRegistrations.some(r => r.step === 'register' && r.options.name === 'sidebar.workspaces.session.row.action'),
150
+ '不应再注册会话行 hover slot(改由常亮注入实现)');
151
+
152
+ const iconKeys = slotRegistrations
153
+ .filter(r => r.step === 'register' && r.options.name === 'contextMenu.icon')
154
+ .map(r => r.options.key);
155
+ for (const key of ['workspace-pin.mountain', 'workspace-pin.mountain-on', 'workspace-pin.star', 'workspace-pin.star-on']) {
156
+ expect(iconKeys.includes(key), `应注册菜单图标 ${key}`);
157
+ }
158
+ // v0.20.2:会话星标必须是独立的四芒 sparkle 图标(不能再复用工作区的五角星 key)
159
+ for (const key of ['workspace-pin.sparkle', 'workspace-pin.sparkle-on']) {
160
+ expect(iconKeys.includes(key), `应注册会话星标图标 ${key}`);
161
+ }
162
+
163
+ /* ---------- v0.20.2:菜单星标 = 行上星标(同形状、同颜色变量) ---------- */
164
+ const renderIcon = (key) => {
165
+ const reg = slotRegistrations.filter(r => r.step === 'register' && r.options.name === 'contextMenu.icon' && r.options.key === key)[0];
166
+ if (!reg) return null;
167
+ let node = { type: reg.component, props: {}, children: [] };
168
+ for (let i = 0; i < 6 && node && typeof node.type === 'function'; i += 1) node = node.type(node.props);
169
+ return node;
170
+ };
171
+ const styleOf = (node) => (node && node.props && node.props.style) || {};
172
+ const pathD = (node) => {
173
+ const kid = node && node.children && node.children[0];
174
+ return kid && kid.props ? String(kid.props.d || '') : '';
175
+ };
176
+ {
177
+ const sparkleOn = renderIcon('workspace-pin.sparkle-on');
178
+ const sparkleOff = renderIcon('workspace-pin.sparkle');
179
+ const starOn = renderIcon('workspace-pin.star-on');
180
+ const starOff = renderIcon('workspace-pin.star');
181
+ expect(sparkleOn && sparkleOn.props['data-wp-icon'] === 'sparkle', '会话星标应标记 data-wp-icon=sparkle');
182
+ expect(pathD(sparkleOn).indexOf('M8 0.5 C8.7 4.8 11.2 7.3 15.5 8') !== -1, '会话星标应是四芒 sparkle 路径');
183
+ expect(pathD(sparkleOff).indexOf('M8 0.5 C8.7 4.8 11.2 7.3 15.5 8') !== -1, '未星标会话也应是四芒 sparkle(同一形状)');
184
+ expect(starOn && starOn.props['data-wp-icon'] === 'star', '工作区星标应标记 data-wp-icon=star');
185
+ expect(pathD(starOn).indexOf('L9.9 5.5') !== -1, '工作区星标应是五角星路径');
186
+ expect(String(styleOf(sparkleOn).fill).indexOf('var(--wp-ss-star') === 0, '会话星标颜色必须走 --wp-ss-star,实际 ' + styleOf(sparkleOn).fill);
187
+ expect(String(styleOf(sparkleOff).fill) === 'none', '未星标会话星标不填充');
188
+ expect(String(styleOf(sparkleOff).stroke) === 'var(--dsw-alias-text-tertiary,#8a8f98)',
189
+ '未星标会话星标的灰显应与行上同源(tertiary 令牌),实际 ' + styleOf(sparkleOff).stroke);
190
+ expect(String(styleOf(starOn).fill).indexOf('var(--wp-ws-star') === 0, '工作区星标颜色必须走 --wp-ws-star,实际 ' + styleOf(starOn).fill);
191
+ expect(String(styleOf(starOff).stroke) === 'var(--dsw-alias-text-tertiary,#8a8f98)', '未星标工作区星标同样走 tertiary 令牌');
192
+ }
193
+
194
+ const signal = new AbortController().signal;
195
+ const target = { workspaceId: 'w-a', path: 'D:\\a', displayTitle: '工作区 A' };
196
+
197
+ /* ---------- 工作区菜单:未置顶/未星标 ---------- */
198
+ let actions = await workspaceMenu.resolve(target, signal);
199
+ expect(actions.length === 2, "工作区菜单应有 2 项(置顶/星标)");
200
+
201
+ expect(actions[0].label === '置顶工作区' && actions[0].id === 'workspace-pin.pin', '第一项应为置顶');
202
+ expect(actions[1].label === '星标工作区' && actions[1].id === 'workspace-pin.star', '第二项应为星标');
203
+ expect(actions[0].icon.key === 'workspace-pin.mountain' && actions[1].icon.key === 'workspace-pin.star', '图标应按状态取 key');
204
+
205
+ await actions[0].run();
206
+ expect(requests.some(r => r.url.endsWith('/workspace-pin/pin') && r.body.workspaceId === 'w-a'), '置顶应 POST /pin {workspaceId:w-a}');
207
+ expect(notices.length === 1 && notices[0].text.indexOf('已置顶') === 0, `应提示已置顶,实际 ${JSON.stringify(notices)}`);
208
+
209
+ /* ---------- 再次打开:已置顶 → 取消置顶;星标 → 取消星标 ---------- */
210
+ actions = await workspaceMenu.resolve(target, signal);
211
+ expect(actions[0].label === '取消置顶' && actions[0].id === 'workspace-pin.unpin', '已置顶时第一项应为取消置顶');
212
+ expect(actions[0].icon.key === 'workspace-pin.mountain-on', '已置顶应用实心山图标');
213
+
214
+ await actions[1].run();
215
+ expect(requests.some(r => r.url.endsWith('/workspace-pin/star') && r.body.kind === 'workspace' && r.body.id === 'w-a' && r.body.starred === true),
216
+ '星标应 POST /star {kind:workspace}');
217
+
218
+ actions = await workspaceMenu.resolve(target, signal);
219
+ expect(actions[1].label === '取消星标' && actions[1].id === 'workspace-pin.unstar', '已星标时第二项应为取消星标');
220
+ expect(actions[1].icon.key === 'workspace-pin.star-on', '已星标应用实心星图标');
221
+
222
+ await actions[0].run(); // 取消置顶
223
+ expect(requests.some(r => r.url.endsWith('/workspace-pin/pin') && r.body.workspaceId === null), '取消置顶应 POST /pin {workspaceId:null}');
224
+
225
+ /* ---------- 会话菜单:置顶 + 星标 ---------- */
226
+ const sessionTarget = { sessionId: 'session-1', displayTitle: '会话一' };
227
+ let sessionActions = await sessionMenu.resolve(sessionTarget, signal);
228
+ expect(sessionActions.length === 2, "会话菜单应有 2 项(置顶/星标)");
229
+ expect(sessionActions[0].id === 'workspace-pin.pin-session', `第一项应为会话置顶,实际 ${sessionActions[0].id}`);
230
+ expect(sessionActions[1].id === 'workspace-pin.star-session', `第二项应为会话星标,实际 ${sessionActions[1].id}`);
231
+ expect(sessionActions[1].icon.key === 'workspace-pin.sparkle',
232
+ `未星标会话应使用四芒 sparkle 图标 key,实际 ${sessionActions[1].icon.key}`);
233
+ await sessionActions[1].run();
234
+ expect(requests.some(r => r.url.endsWith('/workspace-pin/star') && r.body.kind === 'session' && r.body.id === 'session-1'),
235
+ '会话星标应 POST /star {kind:session}');
236
+ sessionActions = await sessionMenu.resolve(sessionTarget, signal);
237
+ expect(sessionActions[1].label === '取消星标', '已星标会话应显示取消星标');
238
+ expect(sessionActions[1].icon.key === 'workspace-pin.sparkle-on',
239
+ `已星标会话应使用实心四芒 sparkle 图标 key,实际 ${sessionActions[1].icon.key}`);
240
+
241
+ /* ---------- Host 不可用:工作区菜单留禁用项,会话菜单安静跳过 ---------- */
242
+ hostDown = true;
243
+ const offline = await workspaceMenu.resolve(target, signal);
244
+ expect(offline.length === 1 && offline[0].disabled === true, 'Host 不可用时工作区菜单应留一个禁用项');
245
+ const offlineSession = await sessionMenu.resolve(sessionTarget, signal);
246
+ expect(offlineSession.length === 0, 'Host 不可用时会话菜单应安静跳过');
247
+ hostDown = false;
248
+
249
+ /* ---------- 无 document 时不崩(DOM 注入器降级) ---------- */
250
+ expect(true, 'mountWorkspaceButtons 在无 document 时应静默返回');
251
+
252
+ if (problems.length > 0) {
253
+ console.log('FAIL');
254
+ for (const p of problems) console.log(' - ' + p);
255
+ return 1;
256
+ }
257
+ console.log('PASS client.js(v2 规格)');
258
+ console.log(' menus : workspace(pin+star, order 150) / session(star)');
259
+ console.log(' slot : 不注册 row.action 槽(行上星标由常亮 CSS 伪元素实现)');
260
+ console.log(' icons : mountain / mountain-on / star / star-on / sparkle / sparkle-on');
261
+ console.log(' 星标一致 : 会话四芒 sparkle + var(--wp-ss-star),工作区五角星 + var(--wp-ws-star)');
262
+ console.log(' requests : GET /state → POST /pin → POST /star(kind=workspace|session)');
263
+ console.log(' degrade : Host 503 → 菜单禁用项 / 无 document → 不注入');
264
+ return 0;
265
+ };
@@ -0,0 +1,258 @@
1
+ // test-dom.cjs — v0.8:图标由"按 data-row-key 生成的 CSS"驱动,行上零属性、零节点。
2
+ module.exports = async function (args) {
3
+ const fs = require('node:fs');
4
+ const vm = require('node:vm');
5
+ const src = fs.readFileSync(args[0], 'utf8');
6
+ const problems = [];
7
+ const expect = (ok, msg) => { if (!ok) problems.push(msg); return ok; };
8
+
9
+ const DOC = { isDocument: true };
10
+ const observers = [];
11
+ const listeners = [];
12
+ const intervals = new Map();
13
+ let intervalSeq = 0;
14
+
15
+ class ClassList {
16
+ constructor(n) { this.n = n; }
17
+ _l() { return (this.n.attrs.class || '').split(/\s+/).filter(Boolean); }
18
+ _s(l) { this.n.attrs.class = l.join(' '); }
19
+ add(c) { const l = this._l(); if (!l.includes(c)) l.push(c); this._s(l); }
20
+ remove(c) { this._s(this._l().filter(x => x !== c)); }
21
+ toggle(c, f) { const has = this._l().includes(c); const want = f === undefined ? !has : !!f; if (want) this.add(c); else this.remove(c); return want; }
22
+ contains(c) { return this._l().includes(c); }
23
+ }
24
+ class Style { constructor() { this.v = {}; } setProperty(k, x) { this.v[k] = String(x); } removeProperty(k) { delete this.v[k]; } getPropertyValue(k) { return this.v[k] || ''; } }
25
+ const splitSel = s => String(s).split(',').map(x => x.trim()).filter(Boolean);
26
+ function m1(node, sel) {
27
+ if (String(sel).trim() === '*') return true;
28
+ let m = /^\[([\w-]+)\]$/.exec(sel); if (m) return node.hasAttribute(m[1]);
29
+ m = /^\[([\w-]+)\^="([^"]*)"\]$/.exec(sel); if (m) { const v = node.getAttribute(m[1]); return typeof v === 'string' && v.indexOf(m[2]) === 0; }
30
+ m = /^\[([\w-]+)\*="([^"]*)"\]$/.exec(sel); if (m) { const v = node.getAttribute(m[1]); return typeof v === 'string' && v.indexOf(m[2]) !== -1; }
31
+ m = /^\[([\w-]+)="([^"]*)"\]$/.exec(sel); if (m) return node.getAttribute(m[1]) === m[2];
32
+ m = /^#([\w-]+)$/.exec(sel); if (m) return node.getAttribute('id') === m[1];
33
+ m = /^([a-zA-Z][\w-]*)$/.exec(sel); if (m) return m[1] === '*' || node.tagName === m[1].toUpperCase();
34
+ return false;
35
+ }
36
+ function matchesComplex(node, sel) {
37
+ const parts = String(sel).trim().split(/\s+/).filter(Boolean);
38
+ if (parts.length === 1) return m1(node, parts[0]);
39
+ if (!m1(node, parts[parts.length - 1])) return false;
40
+ let current = node.parentNode;
41
+ let index = parts.length - 2;
42
+ while (current && current !== DOC && index >= 0) {
43
+ if (m1(current, parts[index])) index -= 1;
44
+ current = current.parentNode;
45
+ }
46
+ return index < 0;
47
+ }
48
+ const matches = (n, s) => splitSel(s).some(p => matchesComplex(n, p));
49
+ class Node {
50
+ constructor(t) {
51
+ this.tagName = String(t).toUpperCase(); this.children = []; this.attrs = {}; this.parentNode = null;
52
+ this.style = new Style(); this.listeners = {}; this.text = ''; this.nodeType = 1;
53
+ this.classList = new ClassList(this);
54
+ this.rect = { top: 100, bottom: 132, height: 32, width: 250, left: 0, right: 250 };
55
+ }
56
+ get isConnected() { let n = this; while (n) { if (n === DOC) return true; n = n.parentNode; } return false; }
57
+ appendChild(c) { if (c.parentNode) c.remove(); c.parentNode = this; this.children.push(c); return c; }
58
+ removeChild(c) { const i = this.children.indexOf(c); if (i !== -1) this.children.splice(i, 1); c.parentNode = null; }
59
+ remove() { if (this.parentNode) this.parentNode.removeChild(this); }
60
+ setAttribute(k, v) { this.attrs[k] = String(v); }
61
+ getAttribute(k) { return k in this.attrs ? this.attrs[k] : null; }
62
+ hasAttribute(k) { return k in this.attrs; }
63
+ removeAttribute(k) { delete this.attrs[k]; }
64
+ addEventListener(t, h) { (this.listeners[t] = this.listeners[t] || []).push(h); }
65
+ getBoundingClientRect() { return this.rect; }
66
+ get id() { return this.attrs.id || ''; } set id(v) { this.attrs.id = String(v); }
67
+ get textContent() { return this.text || this.children.map(c => c.textContent).join(''); } set textContent(v) { this.text = String(v); this.children = []; }
68
+ walk(o) { for (const c of this.children) { o.push(c); c.walk(o); } return o; }
69
+ querySelectorAll(s) { return this.walk([]).filter(n => matches(n, s)); }
70
+ querySelector(s) { return this.querySelectorAll(s)[0] || null; }
71
+ }
72
+ class MO { constructor(cb) { this.cb = cb; observers.push(this); } observe() {} disconnect() {} }
73
+
74
+ const html = new Node('html');
75
+ const body = new Node('body'); html.appendChild(body); html.parentNode = DOC;
76
+ const document = {
77
+ body, head: html, documentElement: html,
78
+ createElement: t => new Node(t), createElementNS: (_n, t) => new Node(t), createTextNode: v => { const n = new Node('#text'); n.nodeType = 3; n.text = String(v); return n; },
79
+ querySelector: s => html.querySelector(s), querySelectorAll: s => html.querySelectorAll(s),
80
+ getElementById: id => html.querySelectorAll('[id]').find(n => n.getAttribute('id') === id) || null,
81
+ addEventListener(type, handler, capture) { listeners.push({ type, handler, capture }); },
82
+ removeEventListener(type, handler) { const i = listeners.findIndex(l => l.type === type && l.handler === handler); if (i !== -1) listeners.splice(i, 1); },
83
+ };
84
+ const list = new Node('div'); list.setAttribute('data-sidebar-list-area', ''); body.appendChild(list);
85
+ function makeRow(kind, id, title) {
86
+ const r = new Node('div');
87
+ r.setAttribute('data-row-key', kind + ':' + id);
88
+ r.setAttribute('aria-label', title); r.text = title;
89
+ const titleEl = new Node('span');
90
+ titleEl.setAttribute('class', 'Rows_title__x');
91
+ titleEl.text = title;
92
+ r.appendChild(titleEl);
93
+ list.appendChild(r); return r;
94
+ }
95
+ const wsA = makeRow('workspace', 'w-a', '工作区 A');
96
+ const wsB = makeRow('workspace', 'w-b', '工作区 B');
97
+ const s1 = makeRow('session', 's-1', '会话 1');
98
+ const s2 = makeRow('session', 's-2', '会话 2');
99
+
100
+ let remote = {
101
+ pinnedWorkspaceId: 'w-a', starredWorkspaces: ['w-b'], starredSessions: ['s-2'],
102
+ workspaceIds: ['w-a', 'w-b'], pinnedSessionByWorkspace: {}, sessionOwner: { 's-1': 'w-a', 's-2': 'w-a' },
103
+ settings: { nativeSessionPin: 'plugin', workspaceStarColor: '#E5484D', sessionStarColor: '#E8B93B' },
104
+ };
105
+ const entries = [];
106
+ const requests = [];
107
+ const workspacesService = {
108
+ list: { getSnapshot: () => ({ items: [{ workspaceId: 'w-a', sessionIds: ['s-1', 's-2'] }], pinnedSessionIds: [] }), subscribe: () => () => {} },
109
+ pinSession: async () => {}, unpinSession: async () => {},
110
+ };
111
+ const reply = v => ({ ok: true, status: 200, json: async () => v });
112
+ const sandbox = {
113
+ console, URL, setTimeout, clearTimeout,
114
+ setInterval: (fn) => { const id = ++intervalSeq; intervals.set(id, fn); return id; },
115
+ clearInterval: (id) => intervals.delete(id),
116
+ queueMicrotask: fn => Promise.resolve().then(fn),
117
+ requestAnimationFrame: fn => setTimeout(fn, 0),
118
+ MutationObserver: MO, document,
119
+ window: { __ModuleLoader__: { load: e => entries.push(e) }, location: { href: 'http://127.0.0.1:49696/?t=1' }, innerHeight: 800, addEventListener() {}, removeEventListener() {} },
120
+ fetch: async (url, init) => {
121
+ const b = init && init.body ? JSON.parse(init.body) : undefined;
122
+ requests.push({ url, body: b });
123
+ if (url.endsWith('/state')) return reply(remote);
124
+ if (url.endsWith('/session-pin')) {
125
+ const map = Object.assign({}, remote.pinnedSessionByWorkspace);
126
+ if (b.sessionId) map[b.workspaceId] = b.sessionId; else delete map[b.workspaceId];
127
+ remote = Object.assign({}, remote, { pinnedSessionByWorkspace: map });
128
+ return reply(remote);
129
+ }
130
+ if (url.endsWith('/pin')) { remote = Object.assign({}, remote, { pinnedWorkspaceId: b.workspaceId }); return reply(remote); }
131
+ if (url.endsWith('/star')) {
132
+ if (b.kind === 'workspace') { const o = remote.starredWorkspaces.filter(x => x !== b.id); remote = Object.assign({}, remote, { starredWorkspaces: b.starred ? [...o, b.id] : o }); }
133
+ else { const o = remote.starredSessions.filter(x => x !== b.id); remote = Object.assign({}, remote, { starredSessions: b.starred ? [...o, b.id] : o }); }
134
+ return reply(remote);
135
+ }
136
+ if (url.endsWith('/setting')) { remote = Object.assign({}, remote, { settings: Object.assign({}, remote.settings, { [b.key]: b.value }) }); return reply(remote); }
137
+ return reply(remote);
138
+ },
139
+ };
140
+ vm.createContext(sandbox);
141
+ vm.runInContext(src, sandbox, { filename: args[0] });
142
+ const React = { createElement: () => null };
143
+ const plugin = entries[0].factory(n => { if (n === 'react') return React; throw new Error(n); });
144
+ const ctx = {
145
+ effect(fn) { fn(); return () => {}; }, on() { return () => {}; },
146
+ get(name) { return name === 'workspaces' ? workspacesService : undefined; },
147
+ locale: { register: () => () => {}, bind: () => (k) => String(k) },
148
+ slots: { inject(_n, f) { const p = f(); if (p && p.next) { for (const _ of p) { /* generator */ } } return () => {}; }, register() { return () => {}; } },
149
+ contextMenus: { register() { return () => {}; }, notify() {} },
150
+ };
151
+ plugin.apply(ctx);
152
+ await new Promise(r => setTimeout(r, 30));
153
+
154
+ const sheet = () => (document.getElementById('wp-style') || {}).textContent || '';
155
+
156
+ /* 1. 行上没有插件写的属性/节点 */
157
+ expect(!wsA.hasAttribute('data-wp-kind') && !wsA.hasAttribute('data-wp-pin') && !wsA.hasAttribute('data-wp-star'), '行上不应有插件写的属性');
158
+ expect(wsA.querySelectorAll('[data-wp],[data-wp-host]').length === 0, '行内不应有插件注入节点');
159
+
160
+ /* 1.9 标题按字数截断(默认 7 字 + 省略号) */
161
+ expect(s1.querySelector('[class*="title"]').textContent === '会话 1', '短标题不应截断');
162
+ const longRow = makeRow('session', 's-3', '一二三四五六七八九十', 260);
163
+ sandbox.window.__workspacePin.sync();
164
+ await new Promise(r => setTimeout(r, 20));
165
+ expect(longRow.querySelector('[class*="title"]').textContent === '一二三四五六七…', '应为 7 字 + 省略号,实际 ' + longRow.querySelector('[class*="title"]').textContent);
166
+
167
+ /* 2. 样式按 data-row-key 生成 */
168
+ expect(sheet().indexOf('[data-row-key="workspace:w-a"]::before') !== -1, '置顶工作区应有 ::before 规则');
169
+ expect(sheet().indexOf('[data-row-key="workspace:w-b"]::after') !== -1, '星标工作区应有 ::after 规则');
170
+ expect(sheet().indexOf('[data-row-key="session:s-2"]::after') !== -1, '星标会话应有 ::after 规则');
171
+ expect(sheet().indexOf('[data-row-key="session:s-1"]::before') === -1, '未登记 map 的会话不应有图钉规则');
172
+ expect(sheet().indexOf('color:#4D6BFE!important') !== -1, '置顶山应为品牌蓝');
173
+
174
+ expect(sheet().indexOf('--wp-ws-star') !== -1 && sheet().indexOf('--wp-ss-star') !== -1, '星标颜色走变量');
175
+ expect(html.style.getPropertyValue('--wp-ws-star') === '#E5484D', '工作区星默认红');
176
+ expect(html.style.getPropertyValue('--wp-ss-star') === '#E8B93B', '会话星默认黄');
177
+ const hoverAfterRule = /\[data-row-key\]:hover::after\{([^}]*)\}/.exec(sheet());
178
+ expect(!hoverAfterRule || hoverAfterRule[1].indexOf('display') === -1, '星标位常驻占位;hover 只允许改透明度(v0.13 REQ-1)');
179
+
180
+ expect(sheet().indexOf('4.4em') !== -1, '时间文本应固定宽度 4.4em');
181
+ expect(sheet().indexOf('margin-left:auto') !== -1, '时间块应 margin-left:auto 顶右');
182
+ expect(sheet().indexOf('display:none;width:22px') !== -1, 'unlit icons must not occupy space');
183
+ // v0.20:裁切弹层自己用 position:fixed(全屏遮罩),这里守的是「行图标不得用 fixed 定位」。
184
+ expect(!/\[data-row-key[^{}]*\{[^{}]*position:\s*fixed/.test(sheet()), '行图标的规则不应使用 fixed 定位');
185
+
186
+ /* 3. 行重建不影响命中(样式不依赖行节点实例) */
187
+ const before = sheet();
188
+ list.removeChild(s1);
189
+ makeRow('session', 's-1', '会话 1');
190
+ await new Promise(r => setTimeout(r, 20));
191
+ expect(sheet() === before, '行重建后样式表不变(规则按 data-row-key 命中,无需补属性)');
192
+
193
+ /* 4. 行右端点击不再切换(v0.11.3:伪元素图标不是按钮,切换一律走右键菜单) */
194
+ const fireClick = (row, x) => {
195
+ const event = { target: row, clientX: x, defaultPrevented: false, propagationStopped: false, preventDefault() { this.defaultPrevented = true; }, stopPropagation() { this.propagationStopped = true; } };
196
+ for (const l of listeners.filter(l => l.type === 'click')) l.handler(event);
197
+ return event;
198
+ };
199
+ const click = fireClick(wsB, 250 - 10);
200
+ await new Promise(r => setTimeout(r, 30));
201
+ expect(!click.defaultPrevented && !click.propagationStopped, '行右端点击不应再被插件拦截(不再是命中区)');
202
+ expect(!requests.some(r => r.url.endsWith('/star')), '行右端点击不应再触发星标(改走右键菜单)');
203
+
204
+ /* 5. 菜单隐藏(plugin)与恢复(native) */
205
+ const sessionMenu = new Node('div'); sessionMenu.setAttribute('role', 'menu');
206
+ const nativePin = new Node('div'); nativePin.setAttribute('role', 'menuitem');
207
+ const nativeLabel = new Node('span'); nativeLabel.text = '置顶会话'; nativePin.appendChild(nativeLabel);
208
+ const nativeIcon = new Node('svg'); const nativeIconPath = new Node('path'); nativeIconPath.setAttribute('d', 'M8 1.7 L9.9 5.5'); nativeIcon.appendChild(nativeIconPath); nativePin.appendChild(nativeIcon);
209
+ const ourPin = new Node('div'); ourPin.setAttribute('role', 'menuitem');
210
+ const ourLabel = new Node('span'); ourLabel.text = '置顶会话'; ourPin.appendChild(ourLabel);
211
+ const ourSvg = new Node('svg'); const ourPath = new Node('path'); ourPath.setAttribute('d', 'M9.828.722a.5.5 0 0 1 .354.146'); ourSvg.appendChild(ourPath); ourPin.appendChild(ourSvg);
212
+ const ourStar = new Node('div'); ourStar.setAttribute('role', 'menuitem'); ourStar.text = '星标会话';
213
+ sessionMenu.appendChild(nativePin); sessionMenu.appendChild(ourPin); sessionMenu.appendChild(ourStar); body.appendChild(sessionMenu);
214
+ const wsMenu = new Node('div'); wsMenu.setAttribute('role', 'menu');
215
+ const wsPin = new Node('div'); wsPin.setAttribute('role', 'menuitem'); wsPin.text = '取消置顶';
216
+ const wsStarItem = new Node('div'); wsStarItem.setAttribute('role','menuitem'); wsStarItem.text = '星标工作区';
217
+ wsMenu.appendChild(wsPin); wsMenu.appendChild(wsStarItem); body.appendChild(wsMenu);
218
+ sessionMenu.remove();
219
+ for (const o of observers) if (!o.disconnected) o.cb([{ addedNodes: [wsMenu], removedNodes: [] }]);
220
+ await new Promise(r => setTimeout(r, 20));
221
+ expect(nativeLabel.style.display !== 'none' && nativeLabel.textContent === '置顶会话', '原生行文字不应被清空(整行隐藏即可)');
222
+ expect(ourPin.style.display !== 'none' && ourLabel.textContent === '置顶会话', '插件行文字应完整保留');
223
+ expect(ourPin.style.display !== 'none', '插件自己的「置顶会话」必须保留');
224
+ expect(wsPin.style.display !== 'none', '工作区菜单不应被误伤');
225
+ remote = Object.assign({}, remote, { settings: Object.assign({}, remote.settings, { nativeSessionPin: 'native' }) });
226
+ for (const id of [...intervals.keys()]) intervals.get(id)();
227
+ await new Promise(r => setTimeout(r, 40));
228
+ expect(nativePin.style.display !== 'none', 'native 模式应恢复原生菜单项');
229
+
230
+ const nativePinnedItem = new Node('div');
231
+ nativePinnedItem.setAttribute('role', 'menuitem');
232
+ const npLabel = new Node('span'); npLabel.text = '取消置顶'; nativePinnedItem.appendChild(npLabel);
233
+ const otherWrap = new Node('div'); otherWrap.appendChild(nativePinnedItem); sessionMenu.appendChild(otherWrap);
234
+ const ourPinnedItem = new Node('div'); ourPinnedItem.setAttribute('role', 'menuitem');
235
+ const opLabel = new Node('span'); opLabel.text = '取消置顶会话'; ourPinnedItem.appendChild(opLabel);
236
+ const opSvg = new Node('svg'); const opPath = new Node('path'); opPath.setAttribute('d', 'M9.828.722a.5.5'); opSvg.appendChild(opPath); ourPinnedItem.appendChild(opSvg);
237
+ body.appendChild(ourPinnedItem);
238
+ for (const o of observers) if (!o.disconnected) o.cb([{ addedNodes: [otherWrap, ourPinnedItem], removedNodes: [] }]);
239
+ await new Promise(r => setTimeout(r, 20));
240
+ expect(ourPinnedItem.style.display !== 'none' && opLabel.textContent === '取消置顶会话', '插件「取消置顶会话」应保留且文字完整');
241
+ /* 6. dispose 移除样式表与变量 */
242
+ sandbox.window.__workspacePin.dispose();
243
+ expect(!document.getElementById('wp-style'), 'dispose 应移除样式表');
244
+ expect(html.style.getPropertyValue('--wp-ws-star') === '', 'dispose 应清掉 CSS 变量');
245
+
246
+ if (problems.length > 0) {
247
+ console.log('FAIL');
248
+ for (const p of problems) console.log(' - ' + p);
249
+ return 1;
250
+ }
251
+ console.log('PASS client.js(v0.8 按 data-row-key 生成的 CSS)');
252
+ console.log(' 行上 : 无插件属性、无注入节点');
253
+ console.log(' 样式 : 按 [data-row-key="…"] 生成 ::before/::after');
254
+ console.log(' 行重建 : 样式表不变,规则照样命中');
255
+ console.log(' 图标 : 只做状态指示(无 hover 显现、无点击命中区)');
256
+ console.log(' 菜单 : plugin 隐藏会话置顶项;native 恢复');
257
+ return 0;
258
+ };