dsh-deck-touch 0.1.2 → 0.1.4

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.
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: dsh-deck-touch
3
+ name: dsh-deck-touch
package/lib/client.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * swipe("left") = 右边的 tab → 右侧栏
7
7
  * back() = 关设置 → 页面返回 → 关侧栏(DeckShell.back)
8
8
  *
9
- * 设置页是例外:只切设置分区,切到两端就停;系统返回优先关设置,绝不退回桌面。
9
+ * 设置页只在分区之间滑动;有确认弹窗时优先关闭弹窗。
10
10
  *
11
11
  * 对外契约 window.DeckShellNav 保持 v1(原生只读 version/ready/swipe/back):
12
12
  * handled = 做了动作;none = 没有可做的(原生静默);error = 意外异常(原生提示重载)。
@@ -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.4';
23
23
 
24
24
  // ---- probe:只读 DOM ----
25
25
 
@@ -99,6 +99,15 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
99
99
  return null;
100
100
  }
101
101
 
102
+ function settingsPrompt(settings) {
103
+ const dialogs = document.querySelectorAll('[role="dialog"][aria-modal="true"], [role="alertdialog"]');
104
+ for (let i = dialogs.length - 1; i >= 0; i -= 1) {
105
+ const dialog = dialogs[i];
106
+ if (dialog !== settings && !dialog.contains(settings) && isVisible(dialog)) return dialog;
107
+ }
108
+ return null;
109
+ }
110
+
102
111
  /** 设置页把分区渲染成 nav 按钮,不是 role=tab。 */
103
112
  function visibleSettingsTabs() {
104
113
  const container = settingsRoot();
@@ -132,41 +141,132 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
132
141
  return 0;
133
142
  }
134
143
 
135
- /** 可见的页面级返回入口(插件详情返回、设置子页返回、弹窗返回)。 */
136
- function pageBackButton() {
137
- const nodes = document.querySelectorAll('[data-page-back], button[aria-label], [role="button"][aria-label], a[aria-label]');
144
+ /** tab 最近的滚动祖先:窄屏设置页是顶部横向条,宽屏是竖排 rail;没有就返回 null。 */
145
+ function scrollContainer(node) {
146
+ let current = node ? node.parentElement : null;
147
+ while (current && current.nodeType === 1 && current !== document.body) {
148
+ try {
149
+ const style = window.getComputedStyle(current);
150
+ const overflowX = String(style.overflowX || 'visible').trim();
151
+ const overflowY = String(style.overflowY || 'visible').trim();
152
+ const scrollsX = (overflowX === 'auto' || overflowX === 'scroll') &&
153
+ current.scrollWidth > current.clientWidth + 1;
154
+ const scrollsY = (overflowY === 'auto' || overflowY === 'scroll') &&
155
+ current.scrollHeight > current.clientHeight + 1;
156
+ if (scrollsX || scrollsY) return current;
157
+ } catch (error) {
158
+ // 样式读不到就继续往上找,不能因为一次查询失败决定滚谁。
159
+ }
160
+ current = current.parentElement;
161
+ }
162
+ return null;
163
+ }
164
+
165
+ function prefersReducedMotion() {
166
+ try {
167
+ return typeof window.matchMedia === 'function' &&
168
+ window.matchMedia('(prefers-reduced-motion: reduce)').matches === true;
169
+ } catch (error) {
170
+ return false;
171
+ }
172
+ }
173
+
174
+ /**
175
+ * 把刚选中的 tab 放进它所在 tab 条的可视区。
176
+ * 程序化 click() 不会移动焦点,DSH 的 onFocus 滚动因此不触发,窄屏设置页
177
+ * 就会停在旧位置、把新选中的分区标题甩到屏幕外。
178
+ * 已经完整可见时不动(避免每切一次都居中跳动);block 用 nearest,
179
+ * 内容列不是 tab 的祖先,所以不会被带着滚。
180
+ */
181
+ function revealTab(tab) {
182
+ const scroller = scrollContainer(tab);
183
+ if (scroller === null) return false;
184
+ const seen = scroller.getBoundingClientRect();
185
+ const rect = tab.getBoundingClientRect();
186
+ const inside = rect.left >= seen.left && rect.right <= seen.right &&
187
+ rect.top >= seen.top && rect.bottom <= seen.bottom;
188
+ if (inside) return false;
189
+ // 页面不可见时浏览器不会推进平滑滚动(后台 WebView/PiP),退回瞬时滚动。
190
+ const instant = document.hidden === true || prefersReducedMotion();
191
+ const options = {
192
+ block: 'nearest',
193
+ inline: 'center',
194
+ behavior: instant ? 'auto' : 'smooth',
195
+ };
196
+ try {
197
+ tab.scrollIntoView(options);
198
+ } catch (error) {
199
+ // 老 WebView 不认 options 对象或没有这个方法:宁可不动,也不能抛出去。
200
+ try {
201
+ tab.scrollIntoView();
202
+ } catch (fallback) {
203
+ return false;
204
+ }
205
+ }
206
+ return true;
207
+ }
208
+
209
+ /**
210
+ * 可见的页面级返回入口(插件详情返回、设置子页返回、弹窗返回)。
211
+ * [root] 用来限制搜索范围:设置页打开时只找设置面板里的返回,避免点到背后会话的按钮。
212
+ */
213
+ function pageBackButton(root) {
214
+ const scope = root && typeof root.querySelectorAll === 'function' ? root : document;
215
+ const nodes = scope.querySelectorAll('[data-page-back], button[aria-label], [role="button"][aria-label], a[aria-label]');
138
216
  let best = null;
139
217
  for (let i = 0; i < nodes.length; i += 1) {
140
218
  const node = nodes[i];
141
219
  const label = (node.getAttribute('aria-label') || '').trim();
142
220
  const isBack = node.hasAttribute('data-page-back') || /^(返回|Back)/i.test(label);
143
221
  if (!isBack || !isVisible(node) || insideSidebar(node)) continue;
222
+ // 插件卡片的标题按钮也能带 aria-label,别把它当返回。
223
+ if (node.hasAttribute('aria-expanded') || node.hasAttribute('data-plugin-entry')) continue;
224
+ if (node.getAttribute('role') === 'tab') continue;
144
225
  const top = node.getBoundingClientRect().top;
145
226
  if (best === null || top < best.top) best = { node, top };
146
227
  }
147
228
  return best === null ? null : best.node;
148
229
  }
149
230
 
150
- function clickPageBack() {
151
- const button = pageBackButton();
231
+ function clickPageBack(root) {
232
+ const button = pageBackButton(root);
152
233
  if (button === null) return false;
153
234
  button.click();
154
235
  return true;
155
236
  }
156
237
 
157
- /** 设置页的关闭入口:aria-label 里带关闭/close/dismiss/返回/back 的按钮。 */
238
+ /**
239
+ * 设置页里的关闭控件。
240
+ * 先找 data 标记和 class 含 close 的按钮;aria-label 只接受“以关闭/close 开头”,
241
+ * 避免把 “... command-feedback ...”(feedback 里有 back)当成返回/关闭。
242
+ */
158
243
  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];
244
+ const direct = root.querySelector('[data-dismiss], [data-modal-close]');
245
+ if (isVisible(direct)) {
246
+ direct.click();
247
+ return true;
248
+ }
249
+ const buttons = root.querySelectorAll('button, [role="button"]');
250
+ let candidate = null;
251
+ for (let i = 0; i < buttons.length; i += 1) {
252
+ const node = buttons[i];
162
253
  if (!isVisible(node)) continue;
254
+ // 可展开的插件卡片、标签页不是关闭按钮。
255
+ if (node.hasAttribute('aria-expanded') || node.hasAttribute('data-plugin-entry')) continue;
256
+ if (node.getAttribute('role') === 'tab') continue;
257
+ const classes = String(node.className || '');
258
+ if (candidate === null && /(^|[ _-])close([ _-]|$)/i.test(classes)) {
259
+ candidate = node;
260
+ continue;
261
+ }
163
262
  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;
263
+ if (candidate === null && /^(关闭|close|dismiss|返回|back)(\s|$|[::,,])/i.test(label)) {
264
+ candidate = node;
167
265
  }
168
266
  }
169
- return false;
267
+ if (candidate === null) return false;
268
+ candidate.click();
269
+ return true;
170
270
  }
171
271
 
172
272
  /** 设置弹窗一般监听 Escape;找不到关闭按钮时用它兜底。 */
@@ -205,13 +305,20 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
205
305
  function swipe(direction) {
206
306
  try {
207
307
  const settings = settingsRoot();
308
+ if (settings !== null && settingsPrompt(settings) !== null) return 'none';
208
309
  const group = settings !== null ? visibleSettingsTabs() : visibleTabs();
209
310
  if (group !== null) {
210
311
  const index = activeTabIndex(group.tabs);
211
312
  // 右滑去左边的 tab,左滑去右边的 tab。
212
313
  const next = direction === 'right' ? index - 1 : index + 1;
213
314
  if (next >= 0 && next < group.tabs.length) {
214
- group.tabs[next].click();
315
+ const target = group.tabs[next];
316
+ target.click();
317
+ try {
318
+ revealTab(target);
319
+ } catch (error) {
320
+ // 分区已经切过去了;露出来只是锦上添花,不能影响 handled 契约。
321
+ }
215
322
  return 'handled';
216
323
  }
217
324
  // 设置页没有侧栏/页面返回入口,切到头就停住。
@@ -234,7 +341,12 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
234
341
  try {
235
342
  const settings = settingsRoot();
236
343
  if (settings !== null) {
237
- if (clickPageBack()) return 'handled';
344
+ const prompt = settingsPrompt(settings);
345
+ if (prompt !== null) {
346
+ if (!closeSettings(prompt)) pressEscape();
347
+ return 'handled';
348
+ }
349
+ if (clickPageBack(settings)) return 'handled';
238
350
  if (closeSettings(settings)) return 'handled';
239
351
  pressEscape();
240
352
  // 设置页还开着就不把 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.4",
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": {
@@ -17,6 +17,9 @@
17
17
  "client": {
18
18
  "platform": "web",
19
19
  "inject": []
20
+ },
21
+ "bundle": {
22
+ "patch": "./cordis.patch.yml"
20
23
  }
21
24
  },
22
25
  "files": [
@@ -25,7 +28,10 @@
25
28
  "README.md",
26
29
  "README.en.md",
27
30
  "CHANGELOG.md",
28
- "LICENSE"
31
+ "LICENSE",
32
+ "package.json",
33
+ "cordis.patch.yml",
34
+ "NOTICE"
29
35
  ],
30
36
  "scripts": {
31
37
  "test": "node test/nav.test.mjs"