dsh-deck-touch 0.1.6 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - 不再只等宿主调用:新增 hostBack / history / gestures 三个输入适配器,装到任意 DSH 网页壳都能生效。
6
+ - 自持手势只在确认没有其它手势系统时启用(Deck 原生壳、dsh-mobile-apk 页面控制器都会让它自动让路)。
7
+ - 新增 window.__deckTouch(含 config/dispose)与 DeckShellNav.capabilities,向后兼容 v1 契约。
8
+ - 可用 window.__deckTouchConfig 覆盖选择器、手势开关与浏览器返回拦截;html[data-deck-touch-gestures=off] 可关掉自持手势。
9
+ - 新增适配器单测与包清单测试,测试脚本同时跑 nav / package / adapters。
10
+ - README 补全三种安装方式、兼容性与配置说明。
11
+
3
12
  ## 0.1.2
4
13
 
5
14
  - README rewritten in plain language (no implementation details).
package/README.en.md CHANGED
@@ -2,28 +2,61 @@ English | [简体中文](README.md)
2
2
 
3
3
  # dsh-deck-touch
4
4
 
5
- Makes swiping and the system Back button feel right in DSH Deck.
5
+ Page-aware swipe and Back handling for DSH. Works anywhere DSH runs: Deck, other Android shells, and DSH in a browser.
6
6
 
7
7
  ## What it does
8
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.
9
+ - Swipe left or right to move between pages or settings sections; it stops at the ends and never opens a sidebar by accident.
10
+ - Back closes Settings first, then walks pages back instead of leaving the app.
11
+ - When the host has no gesture handling (for example a browser), the plugin takes over touch swipes itself.
15
12
 
16
13
  It only decides what happens after a swipe or Back; it does not change DSH itself.
17
14
 
18
15
  ## Install
19
16
 
20
- Included in Deck; no separate install needed. Other DSH setups can use it as a
21
- web client plugin.
17
+ Deck and other DSH shells (npm):
18
+
19
+ dsh plugin add dsh-deck-touch
20
+
21
+ DSH web in a browser (web profile):
22
+
23
+ dsh plugin --profile web add dsh-deck-touch
24
+
25
+ Reload the page afterwards. Deck only needs the 0.2.0 upgrade; no host changes.
26
+
27
+ ## Compatibility
28
+
29
+ | Environment | Swipe | Back |
30
+ |---|---|---|
31
+ | Deck | Native gestures call the plugin | Native Back calls the plugin |
32
+ | dsh-mobile-apk and similar shells | Left to their own drawer gestures | Wraps their page back contract |
33
+ | Browser (touch devices) | Plugin handles touch swipes | Off by default, opt-in |
34
+ | Other shells with their own gestures | Steps aside | Wraps a page back contract when present |
35
+
36
+ ## Configuration
37
+
38
+ Set this before the page loads (host injection script or plugin init):
39
+
40
+ window.__deckTouchConfig = {
41
+ gestures: 'auto', // 'auto' | true | false
42
+ back: true, // wrap the host __dshNavigationBack
43
+ browserBack: 'off', // 'off' | 'trap'
44
+ selectors: { // override when upstream DOM changes
45
+ tabs: '[role="tablist"]',
46
+ settings: '[data-shortcut-modal="settings"]',
47
+ },
48
+ }
49
+
50
+ You can also disable self-managed gestures with data-deck-touch-gestures="off" on <html>.
51
+
52
+ ## Known limits
53
+
54
+ - dsh-mobile-apk keeps its own drawer gestures; the plugin steps aside and only wraps Back. Drags inside its settings sheet are still handled by that shell.
55
+ - Trackpad two-finger swipes in desktop browsers are browser back/forward; not taken over by default. Set gestures: true to use mouse drags.
56
+ - Browser back interception (browserBack: 'trap') is off by default; when enabled it consumes one back and closes the current layer.
22
57
 
23
58
  ## Development
24
59
 
25
- ```sh
26
- npm test
27
- ```
60
+ npm test
28
61
 
29
- Apache-2.0
62
+ Apache-2.0
package/README.md CHANGED
@@ -1,26 +1,62 @@
1
- [English](README.en.md) | 简体中文
1
+ English | 简体中文
2
2
 
3
3
  # dsh-deck-touch
4
4
 
5
- 让 DSH Deck 的左右滑动和系统返回键用起来更顺手。
5
+ 让 DSH 里的左右滑动和系统返回键按页面层级工作。装在任何 DSH 上都能用:Deck、其它 Android 壳、浏览器里的 DSH。
6
6
 
7
7
  ## 它能做什么
8
8
 
9
- - 在 DSH 里左右滑,可以在页面之间切换,也可以打开左右侧栏。
10
- - 在设置里左右滑,只在设置分类之间切换;滑到头就停,不会误把侧栏打开。
11
- - 在设置里按返回键,会关掉设置回到会话,不会直接退出 App。
12
- - 在其它页面按返回键,先返回上一页;没有上一页时再关侧栏。
9
+ - 左右滑动:在页面之间切换、在设置分区之间切换;滑到头就停,不会误开侧栏。
10
+ - 系统返回:先关设置、再退页面,不会直接退出应用。
11
+ - 没有宿主手势的环境(比如浏览器):插件自己接管触摸滑动。
13
12
 
14
- 它只管“滑一下、按返回”之后发生什么,不改变 DSH 本身的功能。
13
+ 它只决定“滑一下、按返回”之后发生什么,不改变 DSH 本身的功能。
15
14
 
16
15
  ## 安装
17
16
 
18
- Deck 已经自带,不需要单独安装。其它 DSH 环境可以把它当作网页端插件使用。
17
+ Deck 与其它 DSH 壳(走 npm):
18
+
19
+ dsh plugin add dsh-deck-touch
20
+
21
+ 浏览器里的 DSH web(装进 web profile):
22
+
23
+ dsh plugin --profile web add dsh-deck-touch
24
+
25
+ 装完刷新页面。Deck 升级到 0.2.0 即可,不需要改动宿主代码。
26
+
27
+ ## 兼容性
28
+
29
+ | 环境 | 滑动切 tab / 分区 | 系统返回 |
30
+ |---|---|---|
31
+ | Deck | 原生手势调用插件 | 原生返回调用插件 |
32
+ | dsh-mobile-apk / 类似壳 | 让给它自己的抽屉手势 | 接管它的页面返回契约 |
33
+ | 浏览器(触摸设备) | 插件自己接管 | 默认不接管,可配置开启 |
34
+ | 其它带宿主手势的壳 | 自动让路 | 有 page-back 契约时接管 |
35
+
36
+ ## 配置
37
+
38
+ 在页面加载前(宿主注入脚本或插件 init 里)设置:
39
+
40
+ window.__deckTouchConfig = {
41
+ gestures: 'auto', // 'auto' | true | false
42
+ back: true, // 是否接管宿主的 __dshNavigationBack
43
+ browserBack: 'off', // 'off' | 'trap'
44
+ selectors: { // 上游 DOM 变化时可覆盖
45
+ tabs: '[role="tablist"]',
46
+ settings: '[data-shortcut-modal="settings"]',
47
+ },
48
+ }
49
+
50
+ 也可以在 <html> 上加 data-deck-touch-gestures="off" 关掉自持手势。
51
+
52
+ ## 已知限制
53
+
54
+ - dsh-mobile-apk 自带抽屉手势,插件会让路,只接管返回键;设置弹窗内的拖动仍由它处理。
55
+ - 桌面浏览器的双指手势是浏览器前进/后退,默认不接管;需要时设 gestures: true 用鼠标拖动。
56
+ - 浏览器返回键拦截(browserBack: 'trap')默认关闭,开启后会吞掉一次返回并关闭当前层。
19
57
 
20
58
  ## 开发
21
59
 
22
- ```sh
23
- npm test
24
- ```
60
+ npm test
25
61
 
26
- Apache-2.0
62
+ Apache-2.0
package/lib/client.js CHANGED
@@ -19,7 +19,49 @@ 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.6';
22
+ const PLUGIN_VERSION = '0.2.0';
23
+
24
+ // ---- config:宿主可在加载前用 window.__deckTouchConfig 覆盖,读一次后冻结 ----
25
+
26
+ const DEFAULT_SELECTORS = Object.freeze({
27
+ tabs: '[role="tablist"]',
28
+ settings: '[data-shortcut-modal="settings"]',
29
+ });
30
+
31
+ function readConfig() {
32
+ const config = {
33
+ gestures: 'auto',
34
+ back: true,
35
+ browserBack: 'off',
36
+ selectors: { tabs: DEFAULT_SELECTORS.tabs, settings: DEFAULT_SELECTORS.settings },
37
+ };
38
+ let raw = null;
39
+ try {
40
+ raw = window.__deckTouchConfig;
41
+ } catch (error) {
42
+ raw = null;
43
+ }
44
+ if (raw && typeof raw === 'object') {
45
+ if (raw.gestures === true || raw.gestures === false || raw.gestures === 'auto') config.gestures = raw.gestures;
46
+ if (typeof raw.back === 'boolean') config.back = raw.back;
47
+ if (raw.browserBack === 'trap' || raw.browserBack === 'off') config.browserBack = raw.browserBack;
48
+ if (raw.selectors && typeof raw.selectors === 'object') {
49
+ if (typeof raw.selectors.tabs === 'string' && raw.selectors.tabs.length > 0) config.selectors.tabs = raw.selectors.tabs;
50
+ if (typeof raw.selectors.settings === 'string' && raw.selectors.settings.length > 0) config.selectors.settings = raw.selectors.settings;
51
+ }
52
+ }
53
+ return Object.freeze({ ...config, selectors: Object.freeze(config.selectors) });
54
+ }
55
+
56
+ const CONFIG = readConfig();
57
+
58
+ function queryAll(selector) {
59
+ try {
60
+ return document.querySelectorAll(selector);
61
+ } catch (error) {
62
+ return [];
63
+ }
64
+ }
23
65
 
24
66
  // ---- probe:只读 DOM ----
25
67
 
@@ -49,7 +91,7 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
49
91
 
50
92
  /** 最靠上的可见 tab 组:ARIA tabs 优先,设置弹窗的 nav 兜底。 */
51
93
  function visibleTabs() {
52
- const lists = document.querySelectorAll('[role="tablist"]');
94
+ const lists = queryAll(CONFIG.selectors.tabs);
53
95
  let best = null;
54
96
  for (let i = 0; i < lists.length; i += 1) {
55
97
  const list = lists[i];
@@ -85,7 +127,7 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
85
127
  * 设置打开时侧栏 dialog 也在 DOM 里(aria-label=导航),先扫 role=dialog 会把它误当成设置。
86
128
  */
87
129
  function settingsRoot() {
88
- const marked = document.querySelectorAll('[data-shortcut-modal="settings"]');
130
+ const marked = queryAll(CONFIG.selectors.settings);
89
131
  for (let i = 0; i < marked.length; i += 1) {
90
132
  if (isVisible(marked[i])) return marked[i];
91
133
  }
@@ -362,6 +404,292 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
362
404
  }
363
405
  }
364
406
 
407
+ // ---- adapters:输入层。每个适配器独立、可开关、可还原,互不依赖。 ----
408
+
409
+ const state = {
410
+ hostBack: null,
411
+ history: null,
412
+ gestures: null,
413
+ disposed: false,
414
+ };
415
+
416
+ function hostBackPresent() {
417
+ try {
418
+ return typeof window.__dshNavigationBack === 'function';
419
+ } catch (error) {
420
+ return false;
421
+ }
422
+ }
423
+
424
+ /**
425
+ * 页面级返回契约(dsh-mobile-apk 等壳):包装宿主已有的 window.__dshNavigationBack。
426
+ * 只有我们真正处理了才返回 'handled';其余一律透传宿主原函数的返回值。
427
+ */
428
+ function installHostBack() {
429
+ if (!CONFIG.back || state.hostBack || !hostBackPresent()) return;
430
+ const previous = window.__dshNavigationBack;
431
+ const wrapped = function deckTouchHostBack() {
432
+ let result = 'error';
433
+ try {
434
+ result = back();
435
+ } catch (error) {
436
+ result = 'error';
437
+ }
438
+ if (result === 'handled') return 'handled';
439
+ return previous.apply(this, arguments);
440
+ };
441
+ try {
442
+ window.__dshNavigationBack = wrapped;
443
+ state.hostBack = { previous, wrapped };
444
+ } catch (error) {
445
+ state.hostBack = null;
446
+ }
447
+ }
448
+
449
+ function restoreHostBack() {
450
+ const installed = state.hostBack;
451
+ if (!installed) return;
452
+ try {
453
+ if (window.__dshNavigationBack === installed.wrapped) window.__dshNavigationBack = installed.previous;
454
+ } catch (error) {
455
+ // 宿主在包装后又改写了函数:不覆盖它的选择。
456
+ }
457
+ state.hostBack = null;
458
+ }
459
+
460
+ /** 浏览器返回键(可选):只有真正处理了才补一条历史,避免把用户带离页面。 */
461
+ function installHistoryBack() {
462
+ if (CONFIG.browserBack !== 'trap' || state.history) return;
463
+ const onPopState = function deckTouchPopState() {
464
+ if (state.disposed) return;
465
+ let result = 'error';
466
+ try {
467
+ result = back();
468
+ } catch (error) {
469
+ result = 'error';
470
+ }
471
+ if (result !== 'handled') return;
472
+ try {
473
+ window.history.pushState(window.history.state, '');
474
+ } catch (error) {
475
+ // 没有 history API 的壳:什么都不做。
476
+ }
477
+ };
478
+ try {
479
+ window.addEventListener('popstate', onPopState);
480
+ state.history = onPopState;
481
+ } catch (error) {
482
+ state.history = null;
483
+ }
484
+ }
485
+
486
+ // ---- gestures:只有确认没有别的宿主手势时才自持 ----
487
+
488
+ const GESTURE_EDGE = 24;
489
+ const GESTURE_MIN = 48;
490
+ const GESTURE_RATIO = 1.5;
491
+ const GESTURE_BLOCKED = 'input[type="range"], [role="slider"], .xterm, ' +
492
+ '[contenteditable=""], [contenteditable="true"]';
493
+
494
+ function gesturesDisabled() {
495
+ if (CONFIG.gestures === false) return true;
496
+ if (CONFIG.gestures === true) return false;
497
+ try {
498
+ if (window.__DECK_SHELL_PORT__) return true;
499
+ // Deck 的 deck-shell.js 会在页面注入 window.DeckShell;见到它就说明有原生手势。
500
+ if (window.DeckShell && typeof window.DeckShell === 'object') return true;
501
+ if (typeof window.__dshNavigationBack === 'function') return true;
502
+ } catch (error) {
503
+ return true;
504
+ }
505
+ const root = document.documentElement;
506
+ return !!(root && root.dataset && root.dataset.deckTouchGestures === 'off');
507
+ }
508
+
509
+ function scrollsHorizontally(node) {
510
+ let current = node;
511
+ while (current && current.nodeType === 1 && current !== document.body) {
512
+ try {
513
+ const style = window.getComputedStyle(current);
514
+ const overflowX = String(style.overflowX || 'visible').trim();
515
+ if ((overflowX === 'auto' || overflowX === 'scroll') &&
516
+ current.scrollWidth > current.clientWidth + 1) return true;
517
+ } catch (error) {
518
+ // 读不到样式就继续往上找。
519
+ }
520
+ current = current.parentElement;
521
+ }
522
+ return false;
523
+ }
524
+
525
+ function gestureSurface(node) {
526
+ if (!node || node.nodeType !== 1) return false;
527
+ if (typeof node.closest === 'function' && node.closest(GESTURE_BLOCKED)) return false;
528
+ if (scrollsHorizontally(node)) return false;
529
+ try {
530
+ const selection = window.getSelection && window.getSelection();
531
+ if (selection && String(selection.toString()).length > 0) return false;
532
+ } catch (error) {
533
+ // 选区 API 不可用时按“没有选中”处理。
534
+ }
535
+ return true;
536
+ }
537
+
538
+ function installGestures() {
539
+ if (state.gestures || state.disposed) return;
540
+ if (gesturesDisabled()) return;
541
+ let touch = false;
542
+ try {
543
+ touch = 'ontouchstart' in window;
544
+ } catch (error) {
545
+ touch = false;
546
+ }
547
+ if (!touch && CONFIG.gestures !== true) return;
548
+ const drag = { id: null, x: 0, y: 0, claimed: false, active: false };
549
+
550
+ function resetDrag() {
551
+ drag.id = null;
552
+ drag.x = 0;
553
+ drag.y = 0;
554
+ drag.claimed = false;
555
+ drag.active = false;
556
+ }
557
+
558
+ function changedTouch(event) {
559
+ const list = event && event.touches && event.touches.length > 0 ? event.touches : event && event.changedTouches;
560
+ if (!list) return null;
561
+ for (let i = 0; i < list.length; i += 1) {
562
+ if (list[i].identifier === drag.id) return list[i];
563
+ }
564
+ return null;
565
+ }
566
+
567
+ function onTouchStart(event) {
568
+ if (state.disposed) return;
569
+ if (gesturesDisabled()) {
570
+ teardownGestures();
571
+ return;
572
+ }
573
+ if (!event.touches || event.touches.length !== 1) {
574
+ resetDrag();
575
+ return;
576
+ }
577
+ const point = event.touches[0];
578
+ const width = window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || 0;
579
+ if (point.clientX < GESTURE_EDGE || (width > 0 && point.clientX > width - GESTURE_EDGE)) {
580
+ resetDrag();
581
+ return;
582
+ }
583
+ if (!gestureSurface(event.target)) {
584
+ resetDrag();
585
+ return;
586
+ }
587
+ drag.id = point.identifier;
588
+ drag.x = point.clientX;
589
+ drag.y = point.clientY;
590
+ drag.claimed = false;
591
+ drag.active = true;
592
+ }
593
+
594
+ function onTouchMove(event) {
595
+ if (!drag.active || state.disposed) return;
596
+ const point = changedTouch(event);
597
+ if (!point) {
598
+ resetDrag();
599
+ return;
600
+ }
601
+ const dx = point.clientX - drag.x;
602
+ const dy = point.clientY - drag.y;
603
+ if (!drag.claimed) {
604
+ if (Math.abs(dx) < 10) return;
605
+ if (Math.abs(dx) < Math.abs(dy) * GESTURE_RATIO) {
606
+ resetDrag();
607
+ return;
608
+ }
609
+ drag.claimed = true;
610
+ }
611
+ if (event.cancelable) {
612
+ try {
613
+ event.preventDefault();
614
+ } catch (error) {
615
+ // 某些 WebView 的合成事件不可取消,忽略。
616
+ }
617
+ }
618
+ }
619
+
620
+ function onTouchEnd(event) {
621
+ if (!drag.active) return;
622
+ const point = changedTouch(event);
623
+ const dx = (point ? point.clientX : drag.x) - drag.x;
624
+ const claimed = drag.claimed;
625
+ resetDrag();
626
+ if (!claimed || Math.abs(dx) < GESTURE_MIN) return;
627
+ swipe(dx > 0 ? 'right' : 'left');
628
+ }
629
+
630
+ function onTouchCancel() {
631
+ resetDrag();
632
+ }
633
+
634
+ // 显式开启时补一个鼠标拖动(桌面浏览器调试用),不影响触摸路径。
635
+ const mouse = { active: false, x: 0, claimed: false };
636
+ function onMouseDown(event) {
637
+ if (CONFIG.gestures !== true || drag.active || event.button !== 0) return;
638
+ if (!gestureSurface(event.target)) return;
639
+ mouse.active = true;
640
+ mouse.x = event.clientX;
641
+ mouse.claimed = false;
642
+ }
643
+ function onMouseMove(event) {
644
+ if (!mouse.active) return;
645
+ const dx = event.clientX - mouse.x;
646
+ if (!mouse.claimed && Math.abs(dx) < 10) return;
647
+ mouse.claimed = true;
648
+ }
649
+ function onMouseUp(event) {
650
+ if (!mouse.active) return;
651
+ const dx = event.clientX - mouse.x;
652
+ const claimed = mouse.claimed;
653
+ mouse.active = false;
654
+ mouse.claimed = false;
655
+ if (!claimed || Math.abs(dx) < GESTURE_MIN) return;
656
+ swipe(dx > 0 ? 'right' : 'left');
657
+ }
658
+
659
+ const listeners = [
660
+ ['touchstart', onTouchStart, { passive: true }],
661
+ ['touchmove', onTouchMove, { passive: false }],
662
+ ['touchend', onTouchEnd, { passive: true }],
663
+ ['touchcancel', onTouchCancel, { passive: true }],
664
+ ];
665
+ if (CONFIG.gestures === true) {
666
+ listeners.push(['mousedown', onMouseDown, undefined]);
667
+ listeners.push(['mousemove', onMouseMove, undefined]);
668
+ listeners.push(['mouseup', onMouseUp, undefined]);
669
+ }
670
+ try {
671
+ for (let i = 0; i < listeners.length; i += 1) {
672
+ document.addEventListener(listeners[i][0], listeners[i][1], listeners[i][2]);
673
+ }
674
+ state.gestures = { listeners };
675
+ } catch (error) {
676
+ state.gestures = null;
677
+ }
678
+ }
679
+
680
+ function teardownGestures() {
681
+ const installed = state.gestures;
682
+ state.gestures = null;
683
+ if (!installed) return;
684
+ try {
685
+ for (let i = 0; i < installed.listeners.length; i += 1) {
686
+ document.removeEventListener(installed.listeners[i][0], installed.listeners[i][1], installed.listeners[i][2]);
687
+ }
688
+ } catch (error) {
689
+ // 卸载期失败不阻塞其他适配器还原。
690
+ }
691
+ }
692
+
365
693
  // ---- install:幂等;已存在完整契约就保留,半安装则替换 ----
366
694
 
367
695
  function installNavigation() {
@@ -378,18 +706,28 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
378
706
  version: CONTRACT_VERSION,
379
707
  ready: true,
380
708
  swipe,
381
- back
709
+ back,
710
+ capabilities: Object.freeze({ swipe: true, back: true, gestures: CONFIG.gestures })
382
711
  }),
383
712
  configurable: true,
384
713
  writable: false,
385
714
  enumerable: false
386
715
  });
716
+ const info = Object.freeze({
717
+ plugin: 'dsh-deck-touch',
718
+ version: PLUGIN_VERSION,
719
+ contract: CONTRACT_VERSION,
720
+ config: CONFIG,
721
+ dispose
722
+ });
723
+ Object.defineProperty(window, '__deckTouch', {
724
+ value: info,
725
+ configurable: true,
726
+ writable: false,
727
+ enumerable: false
728
+ });
387
729
  Object.defineProperty(window, 'DeckDeckTouch', {
388
- value: Object.freeze({
389
- plugin: 'dsh-deck-touch',
390
- version: PLUGIN_VERSION,
391
- contract: CONTRACT_VERSION
392
- }),
730
+ value: info,
393
731
  configurable: true,
394
732
  writable: false,
395
733
  enumerable: false
@@ -399,12 +737,32 @@ window.__ModuleLoader__.load({id:`dsh-deck-touch`,factory:require=>{
399
737
  }
400
738
  }
401
739
 
740
+ function dispose() {
741
+ if (state.disposed) return;
742
+ state.disposed = true;
743
+ teardownGestures();
744
+ if (state.history) {
745
+ try {
746
+ window.removeEventListener('popstate', state.history);
747
+ } catch (error) {
748
+ // 宿主已卸载 window:无需处理。
749
+ }
750
+ state.history = null;
751
+ }
752
+ restoreHostBack();
753
+ }
754
+
402
755
  function apply() {
403
756
  installNavigation();
757
+ installHostBack();
758
+ installHistoryBack();
759
+ installGestures();
760
+ return dispose;
404
761
  }
405
762
 
406
- // 模块一加载就安装,满足原生 verifyNavigationPlugin 的早期探测。
407
- installNavigation();
763
+ // 模块一加载就安装,满足原生 verifyNavigationPlugin 的早期探测;
764
+ // 适配器随加载一起生效,未调用 apply() 的宿主(浏览器)也能用。
765
+ apply();
408
766
 
409
767
  return { apply, inject };
410
768
  }});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-deck-touch",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "DSH Deck touch navigation: swipe/back routing for the Deck WebShell",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -36,7 +36,7 @@
36
36
  "locale"
37
37
  ],
38
38
  "scripts": {
39
- "test": "node test/nav.test.mjs"
39
+ "test": "node test/nav.test.mjs && node test/package.test.mjs && node test/adapters.test.mjs"
40
40
  },
41
41
  "keywords": [
42
42
  "dsh",