dsh-deck-touch 0.1.2 → 0.1.3

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/NOTICE ADDED
@@ -0,0 +1,6 @@
1
+ DSH Deck
2
+ Copyright 2026 MeiXu6693
3
+
4
+ This product includes software developed by wangzan101
5
+ (https://github.com/wangzan101/Mika), licensed under the Apache
6
+ License, Version 2.0.
package/lib/client.js CHANGED
@@ -19,7 +19,7 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
19
19
  const inject = [];
20
20
 
21
21
  const CONTRACT_VERSION = '1';
22
- const PLUGIN_VERSION = '0.1.0';
22
+ const PLUGIN_VERSION = '0.1.1';
23
23
 
24
24
  // ---- probe:只读 DOM ----
25
25
 
@@ -132,41 +132,132 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
132
132
  return 0;
133
133
  }
134
134
 
135
- /** 可见的页面级返回入口(插件详情返回、设置子页返回、弹窗返回)。 */
136
- function pageBackButton() {
137
- const nodes = document.querySelectorAll('[data-page-back], button[aria-label], [role="button"][aria-label], a[aria-label]');
135
+ /** tab 最近的滚动祖先:窄屏设置页是顶部横向条,宽屏是竖排 rail;没有就返回 null。 */
136
+ function scrollContainer(node) {
137
+ let current = node ? node.parentElement : null;
138
+ while (current && current.nodeType === 1 && current !== document.body) {
139
+ try {
140
+ const style = window.getComputedStyle(current);
141
+ const overflowX = String(style.overflowX || 'visible').trim();
142
+ const overflowY = String(style.overflowY || 'visible').trim();
143
+ const scrollsX = (overflowX === 'auto' || overflowX === 'scroll') &&
144
+ current.scrollWidth > current.clientWidth + 1;
145
+ const scrollsY = (overflowY === 'auto' || overflowY === 'scroll') &&
146
+ current.scrollHeight > current.clientHeight + 1;
147
+ if (scrollsX || scrollsY) return current;
148
+ } catch (error) {
149
+ // 样式读不到就继续往上找,不能因为一次查询失败决定滚谁。
150
+ }
151
+ current = current.parentElement;
152
+ }
153
+ return null;
154
+ }
155
+
156
+ function prefersReducedMotion() {
157
+ try {
158
+ return typeof window.matchMedia === 'function' &&
159
+ window.matchMedia('(prefers-reduced-motion: reduce)').matches === true;
160
+ } catch (error) {
161
+ return false;
162
+ }
163
+ }
164
+
165
+ /**
166
+ * 把刚选中的 tab 放进它所在 tab 条的可视区。
167
+ * 程序化 click() 不会移动焦点,DSH 的 onFocus 滚动因此不触发,窄屏设置页
168
+ * 就会停在旧位置、把新选中的分区标题甩到屏幕外。
169
+ * 已经完整可见时不动(避免每切一次都居中跳动);block 用 nearest,
170
+ * 内容列不是 tab 的祖先,所以不会被带着滚。
171
+ */
172
+ function revealTab(tab) {
173
+ const scroller = scrollContainer(tab);
174
+ if (scroller === null) return false;
175
+ const seen = scroller.getBoundingClientRect();
176
+ const rect = tab.getBoundingClientRect();
177
+ const inside = rect.left >= seen.left && rect.right <= seen.right &&
178
+ rect.top >= seen.top && rect.bottom <= seen.bottom;
179
+ if (inside) return false;
180
+ // 页面不可见时浏览器不会推进平滑滚动(后台 WebView/PiP),退回瞬时滚动。
181
+ const instant = document.hidden === true || prefersReducedMotion();
182
+ const options = {
183
+ block: 'nearest',
184
+ inline: 'center',
185
+ behavior: instant ? 'auto' : 'smooth',
186
+ };
187
+ try {
188
+ tab.scrollIntoView(options);
189
+ } catch (error) {
190
+ // 老 WebView 不认 options 对象或没有这个方法:宁可不动,也不能抛出去。
191
+ try {
192
+ tab.scrollIntoView();
193
+ } catch (fallback) {
194
+ return false;
195
+ }
196
+ }
197
+ return true;
198
+ }
199
+
200
+ /**
201
+ * 可见的页面级返回入口(插件详情返回、设置子页返回、弹窗返回)。
202
+ * [root] 用来限制搜索范围:设置页打开时只找设置面板里的返回,避免点到背后会话的按钮。
203
+ */
204
+ function pageBackButton(root) {
205
+ const scope = root && typeof root.querySelectorAll === 'function' ? root : document;
206
+ const nodes = scope.querySelectorAll('[data-page-back], button[aria-label], [role="button"][aria-label], a[aria-label]');
138
207
  let best = null;
139
208
  for (let i = 0; i < nodes.length; i += 1) {
140
209
  const node = nodes[i];
141
210
  const label = (node.getAttribute('aria-label') || '').trim();
142
211
  const isBack = node.hasAttribute('data-page-back') || /^(返回|Back)/i.test(label);
143
212
  if (!isBack || !isVisible(node) || insideSidebar(node)) continue;
213
+ // 插件卡片的标题按钮也能带 aria-label,别把它当返回。
214
+ if (node.hasAttribute('aria-expanded') || node.hasAttribute('data-plugin-entry')) continue;
215
+ if (node.getAttribute('role') === 'tab') continue;
144
216
  const top = node.getBoundingClientRect().top;
145
217
  if (best === null || top < best.top) best = { node, top };
146
218
  }
147
219
  return best === null ? null : best.node;
148
220
  }
149
221
 
150
- function clickPageBack() {
151
- const button = pageBackButton();
222
+ function clickPageBack(root) {
223
+ const button = pageBackButton(root);
152
224
  if (button === null) return false;
153
225
  button.click();
154
226
  return true;
155
227
  }
156
228
 
157
- /** 设置页的关闭入口:aria-label 里带关闭/close/dismiss/返回/back 的按钮。 */
229
+ /**
230
+ * 设置页里的关闭控件。
231
+ * 先找 data 标记和 class 含 close 的按钮;aria-label 只接受“以关闭/close 开头”,
232
+ * 避免把 “... command-feedback ...”(feedback 里有 back)当成返回/关闭。
233
+ */
158
234
  function closeSettings(root) {
159
- const nodes = root.querySelectorAll('[data-dismiss], button[aria-label], [role="button"][aria-label]');
160
- for (let i = 0; i < nodes.length; i += 1) {
161
- const node = nodes[i];
235
+ const direct = root.querySelector('[data-dismiss], [data-modal-close]');
236
+ if (isVisible(direct)) {
237
+ direct.click();
238
+ return true;
239
+ }
240
+ const buttons = root.querySelectorAll('button, [role="button"]');
241
+ let candidate = null;
242
+ for (let i = 0; i < buttons.length; i += 1) {
243
+ const node = buttons[i];
162
244
  if (!isVisible(node)) continue;
245
+ // 可展开的插件卡片、标签页不是关闭按钮。
246
+ if (node.hasAttribute('aria-expanded') || node.hasAttribute('data-plugin-entry')) continue;
247
+ if (node.getAttribute('role') === 'tab') continue;
248
+ const classes = String(node.className || '');
249
+ if (candidate === null && /(^|[ _-])close([ _-]|$)/i.test(classes)) {
250
+ candidate = node;
251
+ continue;
252
+ }
163
253
  const label = (node.getAttribute('aria-label') || '').trim();
164
- if (node.hasAttribute('data-dismiss') || /关闭|close|dismiss|返回|back/i.test(label)) {
165
- node.click();
166
- return true;
254
+ if (candidate === null && /^(关闭|close|dismiss|返回|back)(\s|$|[::,,])/i.test(label)) {
255
+ candidate = node;
167
256
  }
168
257
  }
169
- return false;
258
+ if (candidate === null) return false;
259
+ candidate.click();
260
+ return true;
170
261
  }
171
262
 
172
263
  /** 设置弹窗一般监听 Escape;找不到关闭按钮时用它兜底。 */
@@ -211,7 +302,13 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
211
302
  // 右滑去左边的 tab,左滑去右边的 tab。
212
303
  const next = direction === 'right' ? index - 1 : index + 1;
213
304
  if (next >= 0 && next < group.tabs.length) {
214
- group.tabs[next].click();
305
+ const target = group.tabs[next];
306
+ target.click();
307
+ try {
308
+ revealTab(target);
309
+ } catch (error) {
310
+ // 分区已经切过去了;露出来只是锦上添花,不能影响 handled 契约。
311
+ }
215
312
  return 'handled';
216
313
  }
217
314
  // 设置页没有侧栏/页面返回入口,切到头就停住。
@@ -234,7 +331,7 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
234
331
  try {
235
332
  const settings = settingsRoot();
236
333
  if (settings !== null) {
237
- if (clickPageBack()) return 'handled';
334
+ if (clickPageBack(settings)) return 'handled';
238
335
  if (closeSettings(settings)) return 'handled';
239
336
  pressEscape();
240
337
  // 设置页还开着就不把 Activity 退回桌面;交给 DSH 的 Escape 处理。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-deck-touch",
3
- "version": "0.1.2",
4
- "description": "DSH Deck touch navigation: swipe and back routing for the Deck WebShell",
3
+ "version": "0.1.3",
4
+ "description": "DSH Deck touch navigation: swipe/back routing for the Deck WebShell",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -22,31 +22,14 @@
22
22
  "files": [
23
23
  "lib/index.js",
24
24
  "lib/client.js",
25
- "README.md",
26
- "README.en.md",
27
- "CHANGELOG.md",
28
- "LICENSE"
29
- ],
30
- "scripts": {
31
- "test": "node test/nav.test.mjs"
32
- },
33
- "keywords": [
34
- "dsh",
35
- "deepseek-harness",
36
- "deck",
37
- "webshell",
38
- "navigation",
39
- "swipe",
40
- "android"
25
+ "package.json",
26
+ "LICENSE",
27
+ "NOTICE"
41
28
  ],
29
+ "license": "Apache-2.0",
42
30
  "repository": {
43
31
  "type": "git",
44
- "url": "git+https://github.com/MeiXu6693/dsh-deck-touch.git"
45
- },
46
- "homepage": "https://github.com/MeiXu6693/dsh-deck-touch#readme",
47
- "bugs": {
48
- "url": "https://github.com/MeiXu6693/dsh-deck-touch/issues"
49
- },
50
- "license": "Apache-2.0",
51
- "author": "MeiXu6693"
32
+ "url": "git+https://github.com/MeiXu6693/dsh-deck.git",
33
+ "directory": "app/src/main/assets/harness/plugins/dsh-deck-touch"
34
+ }
52
35
  }
package/CHANGELOG.md DELETED
@@ -1,16 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.1.2
4
-
5
- - README rewritten in plain language (no implementation details).
6
-
7
- ## 0.1.1
8
-
9
- - README simplified; Chinese is now the primary README.
10
-
11
- ## 0.1.0
12
-
13
- - Initial release: tab switching, page back, sidebar routing for the Deck WebShell.
14
- - Right swipe goes to the previous (left) tab; left swipe goes to the next (right) tab.
15
- - Settings dialog is isolated: only its own nav switches, ends clamp, sidebars are untouched.
16
- - System back closes the settings dialog (close button or Escape) instead of backgrounding the app.
package/README.en.md DELETED
@@ -1,29 +0,0 @@
1
- English | [简体中文](README.md)
2
-
3
- # dsh-deck-touch
4
-
5
- Makes swiping and the system Back button feel right in DSH Deck.
6
-
7
- ## What it does
8
-
9
- - Swipe left or right in DSH to move between pages or open the sidebars.
10
- - In Settings, swipes only move between settings sections and stop at the ends;
11
- they never open a sidebar by accident.
12
- - Back in Settings closes Settings and returns to the conversation instead of
13
- leaving the app.
14
- - Back anywhere else goes to the previous page, then closes a sidebar.
15
-
16
- It only decides what happens after a swipe or Back; it does not change DSH itself.
17
-
18
- ## Install
19
-
20
- Included in Deck; no separate install needed. Other DSH setups can use it as a
21
- web client plugin.
22
-
23
- ## Development
24
-
25
- ```sh
26
- npm test
27
- ```
28
-
29
- Apache-2.0
package/README.md DELETED
@@ -1,26 +0,0 @@
1
- [English](README.en.md) | 简体中文
2
-
3
- # dsh-deck-touch
4
-
5
- 让 DSH Deck 的左右滑动和系统返回键用起来更顺手。
6
-
7
- ## 它能做什么
8
-
9
- - 在 DSH 里左右滑,可以在页面之间切换,也可以打开左右侧栏。
10
- - 在设置里左右滑,只在设置分类之间切换;滑到头就停,不会误把侧栏打开。
11
- - 在设置里按返回键,会关掉设置回到会话,不会直接退出 App。
12
- - 在其它页面按返回键,先返回上一页;没有上一页时再关侧栏。
13
-
14
- 它只管“滑一下、按返回”之后发生什么,不改变 DSH 本身的功能。
15
-
16
- ## 安装
17
-
18
- Deck 已经自带,不需要单独安装。其它 DSH 环境可以把它当作网页端插件使用。
19
-
20
- ## 开发
21
-
22
- ```sh
23
- npm test
24
- ```
25
-
26
- Apache-2.0