dsh-deck-touch 0.0.0-stage → 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/LICENSE +202 -0
- package/NOTICE +6 -0
- package/lib/client.js +392 -0
- package/lib/index.js +3 -0
- package/package.json +33 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/lib/client.js
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-deck-touch — Deck WebShell 的前端导航路由。
|
|
3
|
+
*
|
|
4
|
+
* 原生 EdgeGestureHost 只识别"横向滑动",具体做什么全部由这里决定:
|
|
5
|
+
* swipe("right") = 左边的 tab → 页面返回 → 左侧栏
|
|
6
|
+
* swipe("left") = 右边的 tab → 右侧栏
|
|
7
|
+
* back() = 关设置 → 页面返回 → 关侧栏(DeckShell.back)
|
|
8
|
+
*
|
|
9
|
+
* 设置页是例外:只切设置分区,切到两端就停;系统返回优先关设置,绝不退回桌面。
|
|
10
|
+
*
|
|
11
|
+
* 对外契约 window.DeckShellNav 保持 v1(原生只读 version/ready/swipe/back):
|
|
12
|
+
* handled = 做了动作;none = 没有可做的(原生静默);error = 意外异常(原生提示重载)。
|
|
13
|
+
* 探测、决策、执行三段分开写,任何 DOM 查询失败都不允许冒泡成页面错误。
|
|
14
|
+
*
|
|
15
|
+
* 横向拖动的"领取"(scrubber / slider / 横向滚动容器)在 document-start 的
|
|
16
|
+
* deck-shell.js 里完成,不在本插件;本插件只处理已经确认要导航的手势。
|
|
17
|
+
*/
|
|
18
|
+
window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
|
|
19
|
+
const inject = [];
|
|
20
|
+
|
|
21
|
+
const CONTRACT_VERSION = '1';
|
|
22
|
+
const PLUGIN_VERSION = '0.1.1';
|
|
23
|
+
|
|
24
|
+
// ---- probe:只读 DOM ----
|
|
25
|
+
|
|
26
|
+
function isVisible(el) {
|
|
27
|
+
if (!el) return false;
|
|
28
|
+
try {
|
|
29
|
+
const style = window.getComputedStyle(el);
|
|
30
|
+
const rect = el.getBoundingClientRect();
|
|
31
|
+
return !!el.offsetParent && style.display !== 'none' && style.visibility !== 'hidden' &&
|
|
32
|
+
rect.width > 0 && rect.height > 0;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function insideSidebar(node) {
|
|
39
|
+
let current = node;
|
|
40
|
+
while (current && current !== document.body) {
|
|
41
|
+
if (current.hasAttribute &&
|
|
42
|
+
(current.hasAttribute('data-sidebar') || current.hasAttribute('data-sidebar-panel') ||
|
|
43
|
+
current.tagName === 'ASIDE')) return true;
|
|
44
|
+
current = current.parentElement;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 最靠上的可见 tab 组:ARIA tabs 优先,设置弹窗的 nav 兜底。 */
|
|
50
|
+
function visibleTabs() {
|
|
51
|
+
const lists = document.querySelectorAll('[role="tablist"]');
|
|
52
|
+
let best = null;
|
|
53
|
+
for (let i = 0; i < lists.length; i += 1) {
|
|
54
|
+
const list = lists[i];
|
|
55
|
+
if (!isVisible(list) || insideSidebar(list)) continue;
|
|
56
|
+
// 对话页的 对话/轨迹 是页面切换,不参与左右滑切 tab。
|
|
57
|
+
if (list.hasAttribute('data-conversation-tabs') ||
|
|
58
|
+
(typeof list.closest === 'function' && list.closest('[data-conversation-tabs]') !== null)) continue;
|
|
59
|
+
const tabs = Array.prototype.filter.call(list.querySelectorAll('[role="tab"]'), isVisible);
|
|
60
|
+
if (tabs.length < 2) continue;
|
|
61
|
+
const top = list.getBoundingClientRect().top;
|
|
62
|
+
if (best === null || top < best.top) best = { tabs, top };
|
|
63
|
+
}
|
|
64
|
+
if (best !== null) return best;
|
|
65
|
+
return visibleSettingsTabs();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 这个容器里有没有一组可切的设置分区(至少 2 个可见按钮)。 */
|
|
69
|
+
function hasSettingsNav(node) {
|
|
70
|
+
const navs = node.querySelectorAll('nav');
|
|
71
|
+
for (let j = 0; j < navs.length; j += 1) {
|
|
72
|
+
if (!isVisible(navs[j])) continue;
|
|
73
|
+
const tabs = Array.prototype.filter.call(
|
|
74
|
+
navs[j].querySelectorAll('button, [role="tab"], [role="button"], a'),
|
|
75
|
+
isVisible,
|
|
76
|
+
);
|
|
77
|
+
if (tabs.length >= 2) return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 设置页的根。优先认 data-shortcut-modal="settings" 这个精确标记:
|
|
84
|
+
* 设置打开时侧栏 dialog 也在 DOM 里(aria-label=导航),先扫 role=dialog 会把它误当成设置。
|
|
85
|
+
*/
|
|
86
|
+
function settingsRoot() {
|
|
87
|
+
const marked = document.querySelectorAll('[data-shortcut-modal="settings"]');
|
|
88
|
+
for (let i = 0; i < marked.length; i += 1) {
|
|
89
|
+
if (isVisible(marked[i])) return marked[i];
|
|
90
|
+
}
|
|
91
|
+
const nodes = document.querySelectorAll('[role="dialog"]');
|
|
92
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
93
|
+
const node = nodes[i];
|
|
94
|
+
if (!isVisible(node) || insideSidebar(node)) continue;
|
|
95
|
+
const label = (node.getAttribute('aria-label') || '').trim();
|
|
96
|
+
if (label === '导航' || /^nav(igation)?$/i.test(label)) continue;
|
|
97
|
+
if (hasSettingsNav(node)) return node;
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 设置页把分区渲染成 nav 按钮,不是 role=tab。 */
|
|
103
|
+
function visibleSettingsTabs() {
|
|
104
|
+
const container = settingsRoot();
|
|
105
|
+
if (container === null) return null;
|
|
106
|
+
let best = null;
|
|
107
|
+
const navs = container.querySelectorAll('nav');
|
|
108
|
+
for (let j = 0; j < navs.length; j += 1) {
|
|
109
|
+
const nav = navs[j];
|
|
110
|
+
if (!isVisible(nav)) continue;
|
|
111
|
+
const tabs = Array.prototype.filter.call(
|
|
112
|
+
nav.querySelectorAll('button, [role="tab"], [role="button"], a'),
|
|
113
|
+
isVisible,
|
|
114
|
+
);
|
|
115
|
+
if (tabs.length < 2) continue;
|
|
116
|
+
const top = nav.getBoundingClientRect().top;
|
|
117
|
+
if (best === null || top < best.top) best = { tabs, top };
|
|
118
|
+
}
|
|
119
|
+
return best;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function activeTabIndex(tabs) {
|
|
123
|
+
for (let i = 0; i < tabs.length; i += 1) {
|
|
124
|
+
if (tabs[i].getAttribute('aria-selected') === 'true') return i;
|
|
125
|
+
const current = tabs[i].getAttribute('aria-current');
|
|
126
|
+
if (current !== null && current !== 'false') return i;
|
|
127
|
+
if (tabs[i].getAttribute('aria-pressed') === 'true') return i;
|
|
128
|
+
if (tabs[i].getAttribute('data-active') === 'true') return i;
|
|
129
|
+
const classes = String(tabs[i].className || '');
|
|
130
|
+
if (/(^|[ _-])(active|selected|current)([ _-]|$)/i.test(classes)) return i;
|
|
131
|
+
}
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
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]');
|
|
207
|
+
let best = null;
|
|
208
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
209
|
+
const node = nodes[i];
|
|
210
|
+
const label = (node.getAttribute('aria-label') || '').trim();
|
|
211
|
+
const isBack = node.hasAttribute('data-page-back') || /^(返回|Back)/i.test(label);
|
|
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;
|
|
216
|
+
const top = node.getBoundingClientRect().top;
|
|
217
|
+
if (best === null || top < best.top) best = { node, top };
|
|
218
|
+
}
|
|
219
|
+
return best === null ? null : best.node;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function clickPageBack(root) {
|
|
223
|
+
const button = pageBackButton(root);
|
|
224
|
+
if (button === null) return false;
|
|
225
|
+
button.click();
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 设置页里的关闭控件。
|
|
231
|
+
* 先找 data 标记和 class 含 close 的按钮;aria-label 只接受“以关闭/close 开头”,
|
|
232
|
+
* 避免把 “... command-feedback ...”(feedback 里有 back)当成返回/关闭。
|
|
233
|
+
*/
|
|
234
|
+
function closeSettings(root) {
|
|
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];
|
|
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
|
+
}
|
|
253
|
+
const label = (node.getAttribute('aria-label') || '').trim();
|
|
254
|
+
if (candidate === null && /^(关闭|close|dismiss|返回|back)(\s|$|[::,,])/i.test(label)) {
|
|
255
|
+
candidate = node;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (candidate === null) return false;
|
|
259
|
+
candidate.click();
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** 设置弹窗一般监听 Escape;找不到关闭按钮时用它兜底。 */
|
|
264
|
+
function pressEscape() {
|
|
265
|
+
try {
|
|
266
|
+
document.dispatchEvent(new KeyboardEvent('keydown', {
|
|
267
|
+
key: 'Escape', code: 'Escape', bubbles: true, cancelable: true,
|
|
268
|
+
}));
|
|
269
|
+
return true;
|
|
270
|
+
} catch (error) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ---- bridge:只碰 window.DeckShell,返回值统一归一 ----
|
|
276
|
+
|
|
277
|
+
/** 调用 deck-shell.js 暴露的能力;返回契约见 bridgeStatus。 */
|
|
278
|
+
function callShell(name) {
|
|
279
|
+
const api = window.DeckShell;
|
|
280
|
+
if (!api || typeof api[name] !== 'function') return 'unavailable';
|
|
281
|
+
try {
|
|
282
|
+
return api[name]();
|
|
283
|
+
} catch (error) {
|
|
284
|
+
return 'error';
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function bridgeStatus(result) {
|
|
289
|
+
if (result === 'ok' || result === 'handled') return 'handled';
|
|
290
|
+
if (result === 'missing' || result === 'none' || result === 'unavailable') return 'none';
|
|
291
|
+
return 'error';
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// ---- act:唯一的副作用段 ----
|
|
295
|
+
|
|
296
|
+
function swipe(direction) {
|
|
297
|
+
try {
|
|
298
|
+
const settings = settingsRoot();
|
|
299
|
+
const group = settings !== null ? visibleSettingsTabs() : visibleTabs();
|
|
300
|
+
if (group !== null) {
|
|
301
|
+
const index = activeTabIndex(group.tabs);
|
|
302
|
+
// 右滑去左边的 tab,左滑去右边的 tab。
|
|
303
|
+
const next = direction === 'right' ? index - 1 : index + 1;
|
|
304
|
+
if (next >= 0 && next < group.tabs.length) {
|
|
305
|
+
const target = group.tabs[next];
|
|
306
|
+
target.click();
|
|
307
|
+
try {
|
|
308
|
+
revealTab(target);
|
|
309
|
+
} catch (error) {
|
|
310
|
+
// 分区已经切过去了;露出来只是锦上添花,不能影响 handled 契约。
|
|
311
|
+
}
|
|
312
|
+
return 'handled';
|
|
313
|
+
}
|
|
314
|
+
// 设置页没有侧栏/页面返回入口,切到头就停住。
|
|
315
|
+
if (settings !== null) return 'none';
|
|
316
|
+
} else if (settings !== null) {
|
|
317
|
+
// 设置页刚打开、nav 还没渲染出来时也不要碰后台会话的 tab 或侧栏。
|
|
318
|
+
return 'none';
|
|
319
|
+
}
|
|
320
|
+
if (direction === 'right') {
|
|
321
|
+
if (clickPageBack()) return 'handled';
|
|
322
|
+
return bridgeStatus(callShell('openLeftSidebar'));
|
|
323
|
+
}
|
|
324
|
+
return bridgeStatus(callShell('openRightSidebar'));
|
|
325
|
+
} catch (error) {
|
|
326
|
+
return 'error';
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function back() {
|
|
331
|
+
try {
|
|
332
|
+
const settings = settingsRoot();
|
|
333
|
+
if (settings !== null) {
|
|
334
|
+
if (clickPageBack(settings)) return 'handled';
|
|
335
|
+
if (closeSettings(settings)) return 'handled';
|
|
336
|
+
pressEscape();
|
|
337
|
+
// 设置页还开着就不把 Activity 退回桌面;交给 DSH 的 Escape 处理。
|
|
338
|
+
return 'handled';
|
|
339
|
+
}
|
|
340
|
+
if (clickPageBack()) return 'handled';
|
|
341
|
+
return bridgeStatus(callShell('back'));
|
|
342
|
+
} catch (error) {
|
|
343
|
+
return 'error';
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// ---- install:幂等;已存在完整契约就保留,半安装则替换 ----
|
|
348
|
+
|
|
349
|
+
function installNavigation() {
|
|
350
|
+
const existing = window.DeckShellNav;
|
|
351
|
+
if (existing && typeof existing.swipe === 'function' && typeof existing.back === 'function') {
|
|
352
|
+
if (existing.version !== CONTRACT_VERSION && window.console && window.console.error) {
|
|
353
|
+
window.console.error('dsh-deck-touch: DeckShellNav version ' + existing.version + ' already installed');
|
|
354
|
+
}
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
try {
|
|
358
|
+
Object.defineProperty(window, 'DeckShellNav', {
|
|
359
|
+
value: Object.freeze({
|
|
360
|
+
version: CONTRACT_VERSION,
|
|
361
|
+
ready: true,
|
|
362
|
+
swipe,
|
|
363
|
+
back
|
|
364
|
+
}),
|
|
365
|
+
configurable: true,
|
|
366
|
+
writable: false,
|
|
367
|
+
enumerable: false
|
|
368
|
+
});
|
|
369
|
+
Object.defineProperty(window, 'DeckDeckTouch', {
|
|
370
|
+
value: Object.freeze({
|
|
371
|
+
plugin: 'dsh-deck-touch',
|
|
372
|
+
version: PLUGIN_VERSION,
|
|
373
|
+
contract: CONTRACT_VERSION
|
|
374
|
+
}),
|
|
375
|
+
configurable: true,
|
|
376
|
+
writable: false,
|
|
377
|
+
enumerable: false
|
|
378
|
+
});
|
|
379
|
+
} catch (error) {
|
|
380
|
+
if (window.console && window.console.error) window.console.error('dsh-deck-touch navigation', error);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function apply() {
|
|
385
|
+
installNavigation();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// 模块一加载就安装,满足原生 verifyNavigationPlugin 的早期探测。
|
|
389
|
+
installNavigation();
|
|
390
|
+
|
|
391
|
+
return { apply, inject };
|
|
392
|
+
}});
|
package/lib/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-deck-touch",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "DSH Deck touch navigation: swipe/back routing for the Deck WebShell",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"default": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./client": {
|
|
12
|
+
"default": "./lib/client.js"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"dsh": {
|
|
17
|
+
"client": {
|
|
18
|
+
"platform": "web",
|
|
19
|
+
"inject": []
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib/index.js",
|
|
24
|
+
"lib/client.js",
|
|
25
|
+
"package.json",
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"NOTICE"
|
|
28
|
+
],
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/MeiXu6693/dsh-deck.git",
|
|
33
|
+
"directory": "app/src/main/assets/harness/plugins/dsh-deck-touch"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/README.md
DELETED