@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 0.0.2

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 (122) hide show
  1. package/README.md +439 -2
  2. package/README_en.md +415 -0
  3. package/bin/build.js +271 -0
  4. package/bin/cli.js +96 -0
  5. package/bin/lib.js +349 -0
  6. package/bin/manifest-gen.js +327 -0
  7. package/bin/package.js +151 -0
  8. package/bin/scaffold.js +299 -0
  9. package/dev-shell/README.md +151 -0
  10. package/dev-shell/index.html +27 -0
  11. package/dev-shell/package.json +27 -0
  12. package/dev-shell/pnpm-workspace.yaml +9 -0
  13. package/dev-shell/postcss.config.js +6 -0
  14. package/dev-shell/src/App.vue +90 -0
  15. package/dev-shell/src/apps/mock-terminal/MockTerminalSlotCard.vue +43 -0
  16. package/dev-shell/src/apps/mock-terminal/MockTerminalView.vue +168 -0
  17. package/dev-shell/src/apps/mock-terminal/index.ts +50 -0
  18. package/dev-shell/src/components/DevToolbar.vue +100 -0
  19. package/dev-shell/src/components/DialogHost.vue +119 -0
  20. package/dev-shell/src/components/LogPanel.vue +80 -0
  21. package/dev-shell/src/i18n.ts +22 -0
  22. package/dev-shell/src/loader.ts +239 -0
  23. package/dev-shell/src/locale.ts +29 -0
  24. package/dev-shell/src/locales/en-shell.ts +332 -0
  25. package/dev-shell/src/locales/index.ts +70 -0
  26. package/dev-shell/src/locales/shell.ts +331 -0
  27. package/dev-shell/src/main.ts +58 -0
  28. package/dev-shell/src/mock/dialog-service.ts +58 -0
  29. package/dev-shell/src/mock/file-transfer.ts +390 -0
  30. package/dev-shell/src/mock/mobile-api.ts +369 -0
  31. package/dev-shell/src/mock/preset-tasks.ts +186 -0
  32. package/dev-shell/src/mock/session.ts +121 -0
  33. package/dev-shell/src/mock-context.ts +374 -0
  34. package/dev-shell/src/registry.ts +151 -0
  35. package/dev-shell/src/shared-runtime.ts +44 -0
  36. package/dev-shell/src/shell/ShellView.vue +52 -0
  37. package/dev-shell/src/shell/adapters/devAppSource.ts +144 -0
  38. package/dev-shell/src/shell/components/PluginContextHost.vue +40 -0
  39. package/dev-shell/src/shell/components/ShellAppCell.vue +75 -0
  40. package/dev-shell/src/shell/components/ShellAppIcon.vue +111 -0
  41. package/dev-shell/src/shell/components/ShellAppSurface.vue +46 -0
  42. package/dev-shell/src/shell/components/ShellBrandTile.vue +27 -0
  43. package/dev-shell/src/shell/components/ShellCapsuleMenu.vue +123 -0
  44. package/dev-shell/src/shell/components/ShellChip.vue +49 -0
  45. package/dev-shell/src/shell/components/ShellGroupCard.vue +17 -0
  46. package/dev-shell/src/shell/components/ShellHost.vue +75 -0
  47. package/dev-shell/src/shell/components/ShellNotificationShade.vue +501 -0
  48. package/dev-shell/src/shell/components/ShellPermissionPrompt.vue +127 -0
  49. package/dev-shell/src/shell/components/ShellPlaceholderSurface.vue +33 -0
  50. package/dev-shell/src/shell/components/ShellSection.vue +27 -0
  51. package/dev-shell/src/shell/components/ShellSheet.vue +74 -0
  52. package/dev-shell/src/shell/components/ShellStatusbar.vue +84 -0
  53. package/dev-shell/src/shell/components/screens/PluginRoutePage.vue +98 -0
  54. package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +359 -0
  55. package/dev-shell/src/shell/components/screens/ShellAppRunScreen.vue +90 -0
  56. package/dev-shell/src/shell/components/screens/ShellAppsScreen.vue +195 -0
  57. package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +357 -0
  58. package/dev-shell/src/shell/components/screens/ShellPermissionsScreen.vue +376 -0
  59. package/dev-shell/src/shell/components/screens/ShellSettingsScreen.vue +240 -0
  60. package/dev-shell/src/shell/components/screens/ShellSwitcherScreen.vue +559 -0
  61. package/dev-shell/src/shell/components/ui/ConfirmDialog.vue +137 -0
  62. package/dev-shell/src/shell/components/ui/Toggle.vue +53 -0
  63. package/dev-shell/src/shell/composables/useShellApps.ts +417 -0
  64. package/dev-shell/src/shell/composables/useShellNavigation.ts +197 -0
  65. package/dev-shell/src/shell/composables/useShellNotifications.ts +115 -0
  66. package/dev-shell/src/shell/composables/useShellOpen.ts +44 -0
  67. package/dev-shell/src/shell/composables/useShellOverlays.ts +101 -0
  68. package/dev-shell/src/shell/composables/useShellPreferences.ts +143 -0
  69. package/dev-shell/src/shell/composables/useShellRecent.ts +84 -0
  70. package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
  71. package/dev-shell/src/shell/composables/useToast.ts +33 -0
  72. package/dev-shell/src/shell/index.ts +88 -0
  73. package/dev-shell/src/shell/logger.ts +45 -0
  74. package/dev-shell/src/shell/permissions.ts +145 -0
  75. package/dev-shell/src/shell/registry.ts +220 -0
  76. package/dev-shell/src/shell/slotCards.ts +47 -0
  77. package/dev-shell/src/shell/styles/shell.css +1155 -0
  78. package/dev-shell/src/shell/surfaceIntent.ts +107 -0
  79. package/dev-shell/src/shell/types.ts +152 -0
  80. package/dev-shell/src/shell/utils.ts +54 -0
  81. package/dev-shell/src/styles/main.css +153 -0
  82. package/dev-shell/src/styles/mobile.css +981 -0
  83. package/dev-shell/src/styles/wallpaper.css +130 -0
  84. package/dev-shell/src/theme.ts +71 -0
  85. package/dev-shell/src/vite-env.d.ts +20 -0
  86. package/dev-shell/tailwind.config.js +101 -0
  87. package/dev-shell/tsconfig.json +16 -0
  88. package/dev-shell/vite.config.ts +130 -0
  89. package/dist/index.d.ts +124 -0
  90. package/dist/index.js +229 -0
  91. package/dist/types.d.ts +738 -0
  92. package/dist/types.js +0 -0
  93. package/dist/vite-plugin.d.ts +16 -0
  94. package/dist/vite-plugin.js +95 -0
  95. package/package.json +88 -3
  96. package/src/constants.ts +6 -0
  97. package/src/global-dialog.ts +168 -0
  98. package/src/index.ts +96 -0
  99. package/src/runtime.ts +44 -0
  100. package/src/types.ts +822 -0
  101. package/src/ui/AppUpdateSection.d.ts +44 -0
  102. package/src/ui/AppUpdateSection.vue +253 -0
  103. package/src/ui/PluginGlobalDialog.vue +388 -0
  104. package/src/ui/QuickCard.d.ts +33 -0
  105. package/src/ui/QuickCard.vue +167 -0
  106. package/src/ui/Select.d.ts +37 -0
  107. package/src/ui/Select.vue +307 -0
  108. package/src/ui/plugin-global-dialog.d.ts +11 -0
  109. package/src/ui/useSwipeTabs.d.ts +20 -0
  110. package/src/ui/useSwipeTabs.ts +53 -0
  111. package/src/update.ts +123 -0
  112. package/src/vite-plugin.ts +132 -0
  113. package/template/.gitignore +4 -0
  114. package/template/README.md +46 -0
  115. package/template/package.json +23 -0
  116. package/template/plugin.json +13 -0
  117. package/template/rust/Cargo.toml +19 -0
  118. package/template/rust/src/lib.rs +33 -0
  119. package/template/src/env.d.ts +24 -0
  120. package/template/src/index.ts +37 -0
  121. package/template/tsconfig.json +17 -0
  122. package/template/vite.config.ts +21 -0
@@ -0,0 +1,75 @@
1
+ <template>
2
+ <!-- 高度用 h-full 而非 100dvh:壳挂在 ShellView 的 100dvh 容器内(该容器已承担
3
+ 顶部安全区),再用 100dvh 会多出一段安全区高度的溢出 -->
4
+ <div
5
+ class="shell-ui flex flex-col h-full overflow-hidden bg-[var(--mobile-bg-primary)] text-[var(--mobile-text-primary)]"
6
+ >
7
+ <ShellStatusbar />
8
+
9
+ <!-- 屏幕栈容器:进出场期间两屏共存(CSS 里 leave-active 用绝对定位),
10
+ 因此这里必须 overflow-hidden + relative,否则会被撑高 -->
11
+ <div class="relative flex-1 min-h-0 overflow-hidden">
12
+ <Transition :name="`shell-screen-${nav.direction.value}`">
13
+ <!-- key 带 appId:切换应用时强制重挂载,避免复用上一个应用的运行面 -->
14
+ <component :is="screenComponent" :key="screenKey" />
15
+ </Transition>
16
+ </div>
17
+
18
+ <!-- 平台级覆盖层:固定在壳根渲染,与当前屏幕无关 -->
19
+ <ShellCapsuleMenu />
20
+ <ShellPermissionPrompt />
21
+ <ShellNotificationShade />
22
+ </div>
23
+ </template>
24
+
25
+ <script setup lang="ts">
26
+ /**
27
+ * Dev Shell 宿主壳根组件(宿主 ShellHost.vue 的同形实现)
28
+ * -----------------------------------------------------------------------------
29
+ * 职责:状态条 + 屏幕栈 + 平台级覆盖层。就这些。
30
+ *
31
+ * 底部系统条(返回 / 主屏 / 多任务)已于 2026-10-14 在宿主整条退役:常驻导航条
32
+ * 会永久占掉一截应用可视高度,且与 Android 系统手势条重复;导航入口改为
33
+ * ① 各非根屏页头自持返回键 ② 应用运行页胶囊里的多任务 / 回主屏。
34
+ * dev-shell 与宿主同形,不再画底部 Tab 条。
35
+ *
36
+ * 不含的东西(都是刻意的):
37
+ * · 不含任何应用业务——应用界面由其 surface 组件自持(见 ShellAppSurface)
38
+ * · 不含应用清单的获取逻辑——由 ShellView 注册数据源后 refresh
39
+ * · 不含主题配置——沿用既有 --mobile-* token 与设置页
40
+ * · 不含宿主事件桥(useShellHostEvents):dev-shell 没有后端事件总线,
41
+ * 通知只来自壳动作结果(启动 / 停止 / 审批 / 安装 / 卸载)
42
+ *
43
+ * 屏幕表是「屏幕 id → 组件」的纯映射:新增一个屏只需在表里加一行,
44
+ * 导航与过渡机制不动。
45
+ */
46
+ import { computed, type Component } from 'vue'
47
+ import { useShellNavigation, type ShellScreenId } from '../composables/useShellNavigation'
48
+ import ShellCapsuleMenu from './ShellCapsuleMenu.vue'
49
+ import ShellNotificationShade from './ShellNotificationShade.vue'
50
+ import ShellPermissionPrompt from './ShellPermissionPrompt.vue'
51
+ import ShellStatusbar from './ShellStatusbar.vue'
52
+ import ShellAppRunScreen from './screens/ShellAppRunScreen.vue'
53
+ import ShellAppDetailScreen from './screens/ShellAppDetailScreen.vue'
54
+ import ShellAppsScreen from './screens/ShellAppsScreen.vue'
55
+ import ShellHomeScreen from './screens/ShellHomeScreen.vue'
56
+ import ShellPermissionsScreen from './screens/ShellPermissionsScreen.vue'
57
+ import ShellSettingsScreen from './screens/ShellSettingsScreen.vue'
58
+ import ShellSwitcherScreen from './screens/ShellSwitcherScreen.vue'
59
+
60
+ /** 屏幕表:新增屏幕只改这里 */
61
+ const SCREENS: Record<ShellScreenId, Component> = {
62
+ home: ShellHomeScreen,
63
+ apps: ShellAppsScreen,
64
+ 'app-detail': ShellAppDetailScreen,
65
+ 'app-run': ShellAppRunScreen,
66
+ switcher: ShellSwitcherScreen,
67
+ permissions: ShellPermissionsScreen,
68
+ settings: ShellSettingsScreen,
69
+ }
70
+
71
+ const nav = useShellNavigation()
72
+
73
+ const screenComponent = computed<Component>(() => SCREENS[nav.current.value.id] ?? ShellHomeScreen)
74
+ const screenKey = computed(() => `${nav.current.value.id}:${nav.params.value.appId ?? ''}`)
75
+ </script>
@@ -0,0 +1,501 @@
1
+ <template>
2
+ <Teleport to="body">
3
+ <!-- 遮罩:点任意处关闭(Android 通知栏的同一语义:下拉面之外的区域即「收起」) -->
4
+ <Transition name="shell-scrim">
5
+ <div
6
+ v-if="open"
7
+ class="fixed inset-0 z-[60]"
8
+ style="background: var(--mobile-overlay)"
9
+ @click="close"
10
+ />
11
+ </Transition>
12
+
13
+ <!-- 通知栏面板:自顶部滑下(独立面,覆盖壳内一切屏幕与覆盖层) -->
14
+ <Transition name="shell-shade">
15
+ <section
16
+ v-if="open"
17
+ ref="panelEl"
18
+ class="shell-ui fixed inset-x-0 top-0 z-[60] flex flex-col max-h-[85dvh] rounded-b-[20px] border-b border-[var(--mobile-border)] bg-[var(--mobile-bg-card)]"
19
+ :style="{ paddingTop: `calc(${topInset}px + 6px)` }"
20
+ role="dialog"
21
+ aria-modal="true"
22
+ :aria-label="t('shell.notify.title')"
23
+ tabindex="-1"
24
+ @keydown.esc="close"
25
+ >
26
+ <!-- ==================== 头部 ==================== -->
27
+ <div class="flex items-center gap-2 px-4 pt-2 pb-2 flex-shrink-0">
28
+ <div class="flex-1 min-w-0">
29
+ <h2 class="text-[var(--font-size-lg)] font-semibold text-[var(--mobile-text-primary)] truncate">
30
+ {{ t('shell.notify.title') }}
31
+ </h2>
32
+ <p class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] truncate">
33
+ {{ t('shell.notify.count', { count: totalCount }) }}
34
+ </p>
35
+ </div>
36
+ <!-- 清除全部:面板右上角的扫除图标(2026-11-01 用户裁决,底部整行文字按钮退役)。
37
+ 图标按钮无可见文字,可访问名走 aria-label;没有可清条目时不渲染。 -->
38
+ <button
39
+ v-if="hasClearable"
40
+ type="button"
41
+ class="flex items-center justify-center rounded-[10px] min-w-[var(--mobile-touch-target-min)] min-h-[var(--mobile-touch-target-min)] transition-colors duration-200 active:bg-[var(--mobile-accent-muted)] disabled:opacity-40"
42
+ :aria-label="t('shell.notify.clearAll')"
43
+ :disabled="clearingAll"
44
+ @click="clearAllCascade"
45
+ >
46
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
47
+ <path d="M20.5 3.5 13 11" />
48
+ <path d="M10.9 8.9 15.1 13.1" />
49
+ <path d="M10.8 9.6 5.6 15.4" />
50
+ <path d="M12.4 11.2 8.2 17.4" />
51
+ <path d="M14 12.8 11 18.8" />
52
+ </svg>
53
+ </button>
54
+ <button
55
+ type="button"
56
+ class="flex items-center justify-center rounded-[10px] min-w-[var(--mobile-touch-target-min)] min-h-[var(--mobile-touch-target-min)] transition-colors duration-200 active:bg-[var(--mobile-accent-muted)]"
57
+ :aria-label="t('shell.notify.close')"
58
+ @click="close"
59
+ >
60
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
61
+ <path d="M6 6l12 12M18 6L6 18" />
62
+ </svg>
63
+ </button>
64
+ </div>
65
+
66
+ <!-- ==================== 内容 ==================== -->
67
+ <div class="min-h-0 overflow-y-auto pb-4">
68
+ <!-- 待处理:待审批应用(由应用状态派生,批准后自然消失,无独立生命周期) -->
69
+ <template v-if="pendingApps.length > 0">
70
+ <ShellSection :title="t('shell.notify.pending')" :note="t('shell.notify.pendingNote')" />
71
+ <div class="px-4 pb-1 flex flex-col gap-2">
72
+ <div
73
+ v-for="app in pendingApps"
74
+ :key="app.id"
75
+ class="flex items-center gap-3 rounded-[12px] border border-[var(--mobile-border)] bg-[var(--mobile-bg-elevated)] px-3 py-3"
76
+ >
77
+ <ShellAppIcon :app="app" :size="32" />
78
+ <div class="flex-1 min-w-0">
79
+ <div class="text-[var(--font-size-base)] font-medium text-[var(--mobile-text-primary)] truncate">
80
+ {{ app.name }}
81
+ </div>
82
+ <div class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] truncate">
83
+ {{ t('shell.notify.pendingBody', { count: app.permissions.length }) }}
84
+ </div>
85
+ </div>
86
+ <ShellChip
87
+ :label="t('shell.notify.pendingAction')"
88
+ tone="warn"
89
+ clickable
90
+ @click="openApproval(app.id)"
91
+ />
92
+ </div>
93
+ </div>
94
+ </template>
95
+
96
+ <!-- 通知列表:壳动作 + 宿主引擎事件(文案由来源方给出) -->
97
+ <ShellSection
98
+ v-if="notifications.length > 0"
99
+ :title="t('shell.notify.list')"
100
+ :note="t('shell.notify.listNote', { count: notifications.length })"
101
+ />
102
+ <TransitionGroup
103
+ v-if="notifications.length > 0"
104
+ name="notify-list"
105
+ tag="div"
106
+ class="px-4 flex flex-col gap-2"
107
+ >
108
+ <div
109
+ v-for="(item, index) in notifications"
110
+ :key="item.id"
111
+ class="notify-card-wrap relative overflow-hidden rounded-[12px]"
112
+ :class="{ 'notify-card--flee': clearingAll && !item.sticky }"
113
+ :style="clearingAll && !item.sticky ? { animationDelay: `${index * 48}ms` } : undefined"
114
+ >
115
+ <!-- 滑动删除指示层:卡片滑开时露出红底 + 垃圾桶——手势的删除表达,
116
+ 不给驻留项(它们不响应滑动)。跟随卡片圆角被外层裁切。 -->
117
+ <div
118
+ v-if="!item.sticky"
119
+ class="absolute inset-0 flex items-center justify-end pr-5"
120
+ :style="{ background: 'var(--mobile-error)', color: 'var(--mobile-text-on-accent)' }"
121
+ aria-hidden="true"
122
+ >
123
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
124
+ <path d="M3 6h18 M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2 M19 6l-.8 13.1a2 2 0 0 1-2 1.9H7.8a2 2 0 0 1-2-1.9L5 6 M10 11v6 M14 11v6" />
125
+ </svg>
126
+ </div>
127
+ <article
128
+ class="notify-card relative overflow-hidden rounded-[12px] border border-[var(--mobile-border-hover)] bg-[var(--mobile-bg-card)] px-3 py-2.5"
129
+ :class="{ 'notify-card--dragging': cardDragState(item.id)?.dragging }"
130
+ :style="cardStyle(item)"
131
+ :role="item.appId ? 'button' : undefined"
132
+ :tabindex="item.appId ? 0 : undefined"
133
+ :aria-label="item.appId ? t('shell.notify.openByTap', { title: item.title }) : undefined"
134
+ @pointerdown="onCardPointerDown($event, item)"
135
+ @pointermove="onCardPointerMove($event, item)"
136
+ @pointerup="onCardPointerUp($event, item)"
137
+ @pointercancel="resetCardDrag(item.id)"
138
+ @click="onCardClick(item)"
139
+ @keydown.enter="item.appId && openApp(item.appId)"
140
+ @keydown.space.prevent="item.appId && openApp(item.appId)"
141
+ >
142
+ <!-- 类型色条:progress=进行中(强调色左条);信息/事件卡不画条,保持克制的纯卡片 -->
143
+ <span
144
+ v-if="item.kind === 'progress'"
145
+ class="absolute left-0 top-0 bottom-0 w-[3px]"
146
+ :style="{ background: 'var(--mobile-accent)' }"
147
+ aria-hidden="true"
148
+ />
149
+ <div class="flex items-start gap-2.5">
150
+ <!-- 图标块:圆角方块(Android 13 通知形态),progress 强调色高亮,普通态描边中性 -->
151
+ <span
152
+ class="flex items-center justify-center w-8 h-8 rounded-[10px] border flex-shrink-0"
153
+ :style="
154
+ item.kind === 'progress'
155
+ ? { background: 'var(--mobile-accent-muted)', color: 'var(--mobile-accent)', borderColor: 'transparent' }
156
+ : {
157
+ background: 'var(--mobile-bg-elevated)',
158
+ color: 'var(--mobile-text-secondary)',
159
+ borderColor: 'var(--mobile-border)',
160
+ }
161
+ "
162
+ aria-hidden="true"
163
+ >
164
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
165
+ <path :d="item.icon" />
166
+ </svg>
167
+ </span>
168
+ <!-- 扁平布局:标题行右侧嵌「来源 · 时间」,不单占一行;正文可有可无 -->
169
+ <div class="flex-1 min-w-0">
170
+ <div class="flex items-center gap-2 min-w-0">
171
+ <span class="flex-1 min-w-0 text-[var(--font-size-base)] font-medium text-[var(--mobile-text-primary)] truncate">
172
+ {{ item.title }}
173
+ </span>
174
+ <span class="flex-shrink-0 flex items-center gap-1 text-[var(--font-size-xs)] text-[var(--mobile-text-muted)]">
175
+ <span class="max-w-[96px] truncate">{{ item.source }}</span>
176
+ <span aria-hidden="true">·</span>
177
+ <span class="tabular-nums">{{ relativeTime(item.at) }}</span>
178
+ </span>
179
+ </div>
180
+ <div v-if="item.body" class="mt-0.5 text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] break-words">
181
+ {{ item.body }}
182
+ </div>
183
+ <!-- 进度类通知:进度条(无进度值的进度通知不渲染,避免空条) -->
184
+ <div
185
+ v-if="item.kind === 'progress' && typeof item.progress === 'number'"
186
+ class="mt-1.5 h-1 rounded-full overflow-hidden"
187
+ :style="{ background: 'var(--mobile-accent-muted)' }"
188
+ role="progressbar"
189
+ :aria-valuenow="item.progress"
190
+ aria-valuemin="0"
191
+ aria-valuemax="100"
192
+ >
193
+ <span
194
+ class="block h-full rounded-full"
195
+ :style="{ width: `${item.progress}%`, background: 'var(--mobile-accent)' }"
196
+ />
197
+ </div>
198
+ </div>
199
+ <!-- 驻留项没有单条关闭:它表示「需要处理」而不是「看过就算」。
200
+ X 是滑动删除的可达性替代(键盘 / 读屏 / 不支持手势时)。 -->
201
+ <button
202
+ v-if="!item.sticky"
203
+ type="button"
204
+ class="flex items-center justify-center flex-shrink-0 rounded-[8px] min-w-[var(--mobile-touch-target-min)] min-h-[var(--mobile-touch-target-min)] -mr-1 transition-colors duration-200 active:bg-[var(--mobile-accent-muted)]"
205
+ :aria-label="t('shell.notify.dismissOne', { title: item.title })"
206
+ @click.stop="dismiss(item.id)"
207
+ >
208
+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" :style="{ color: 'var(--mobile-text-secondary)' }" aria-hidden="true">
209
+ <path d="M6 6l12 12M18 6L6 18" />
210
+ </svg>
211
+ </button>
212
+ </div>
213
+ </article>
214
+ </div>
215
+ </TransitionGroup>
216
+
217
+ <!-- 空态:说明「通知从哪来」,而不是只丢一句「暂无通知」 -->
218
+ <div v-if="pendingApps.length === 0 && notifications.length === 0" class="px-6 pt-8 text-center">
219
+ <span
220
+ class="inline-flex items-center justify-center w-14 h-14 rounded-[18px]"
221
+ :style="{ background: 'var(--mobile-bg-elevated)', color: 'var(--mobile-text-secondary)' }"
222
+ aria-hidden="true"
223
+ >
224
+ <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
225
+ <path d="M18 8a6 6 0 1 0-12 0c0 7-3 8-3 8h18s-3-1-3-8" />
226
+ <path d="M10.3 21a2 2 0 0 0 3.4 0" />
227
+ </svg>
228
+ </span>
229
+ <p class="mt-3 text-[var(--font-size-base)] text-[var(--mobile-text-primary)]">
230
+ {{ t('shell.notify.empty') }}
231
+ </p>
232
+ <p class="mt-1 text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]">
233
+ {{ t('shell.notify.emptyHint') }}
234
+ </p>
235
+ </div>
236
+ </div>
237
+ </section>
238
+ </Transition>
239
+ </Teleport>
240
+ </template>
241
+
242
+ <script setup lang="ts">
243
+ /**
244
+ * 通知栏(Android 式独立通知面)
245
+ * -----------------------------------------------------------------------------
246
+ * 打开入口在状态条与主屏铃铛(见 ShellStatusbar / ShellHomeScreen),本组件只负责
247
+ * 面板本身:待处理(审批派生)+ 通知(壳动作 / 宿主引擎事件);「清除全部」是面板
248
+ * 右上角的扫除图标按钮(2026-11-01 用户裁决),不再占一条底部动作栏。
249
+ *
250
+ * 为什么不接管「顶部边缘下拉」手势:Android 上从屏幕最顶端下拉属于**系统**手势
251
+ * (拉出系统通知栏),应用层再实现一次会与之冲突(ui-ux-pro-max `--domain ux`
252
+ * Gesture Conflicts:不要覆盖系统手势)。因此入口做成显式点击,拖拽不是唯一路径。
253
+ *
254
+ * 焦点:打开时聚焦面板(键盘 Esc 可关),关闭时焦点回到打开它的元素——
255
+ * 覆盖层不管理焦点会让键盘/读屏用户迷失在背景内容里。
256
+ */
257
+ import { computed, inject, nextTick, onMounted, onUnmounted, ref, watch, type Ref } from 'vue'
258
+ import { useI18n } from 'vue-i18n'
259
+ import { i18n } from '../../i18n'
260
+ import { useShellApps } from '../composables/useShellApps'
261
+ import {
262
+ useShellNotifications,
263
+ type ShellNotification,
264
+ } from '../composables/useShellNotifications'
265
+ import { useShellOverlays } from '../composables/useShellOverlays'
266
+ import { useShellNavigation } from '../composables/useShellNavigation'
267
+ import { openShellApp } from '../composables/useShellOpen'
268
+ import ShellAppIcon from './ShellAppIcon.vue'
269
+ import ShellChip from './ShellChip.vue'
270
+ import ShellSection from './ShellSection.vue'
271
+
272
+ const { t } = useI18n()
273
+ const overlays = useShellOverlays()
274
+ const nav = useShellNavigation()
275
+ const { apps } = useShellApps()
276
+ const { notifications, notificationCount, dismissNotification, clearNotifications } =
277
+ useShellNotifications()
278
+
279
+ const open = computed(() => overlays.shadeOpen.value)
280
+ const pendingApps = computed(() => apps.value.filter((a) => a.state === 'approval'))
281
+ const totalCount = computed(() => notificationCount.value + pendingApps.value.length)
282
+ /** 只剩驻留项时「清除全部」是 no-op:不渲染入口(与宿主同一口径) */
283
+ const hasClearable = computed(() => notifications.value.some((n) => !n.sticky))
284
+
285
+ /** 相对时间随面板打开而刷新:否则「3 分钟前」会一直停在打开那一刻的读数 */
286
+ const now = ref(Date.now())
287
+ let ticker: ReturnType<typeof setInterval> | null = null
288
+
289
+ function startTicker(): void {
290
+ if (ticker !== null) return
291
+ now.value = Date.now()
292
+ ticker = setInterval(() => {
293
+ now.value = Date.now()
294
+ }, 30_000)
295
+ }
296
+
297
+ function stopTicker(): void {
298
+ if (ticker === null) return
299
+ clearInterval(ticker)
300
+ ticker = null
301
+ }
302
+
303
+ /** 相对时间:分钟 / 小时 / 天三档,够用且不引入日期库 */
304
+ function relativeTime(at: number): string {
305
+ const minutes = Math.max(0, Math.round((now.value - at) / 60_000))
306
+ if (minutes < 1) return i18n.global.t('shell.notify.justNow')
307
+ if (minutes < 60) return i18n.global.t('shell.notify.minutesAgo', { count: minutes })
308
+ const hours = Math.round(minutes / 60)
309
+ if (hours < 24) return i18n.global.t('shell.notify.hoursAgo', { count: hours })
310
+ return i18n.global.t('shell.notify.daysAgo', { count: Math.round(hours / 24) })
311
+ }
312
+
313
+ // 安全区由 App.vue 注入(面板贴顶渲染,必须自己让开系统状态栏);缺省 0 =
314
+ // 浏览器预览 / 单测没有系统状态栏。
315
+ const safeArea = inject<Ref<{ top: number; bottom: number; navigationBar?: number }> | undefined>(
316
+ 'safeArea',
317
+ undefined,
318
+ )
319
+ const topInset = computed(() => safeArea?.value.top ?? 0)
320
+
321
+ /** 面板元素:打开时聚焦(键盘 Esc 可关) */
322
+ const panelEl = ref<HTMLElement | null>(null)
323
+
324
+ /** 打开它的元素:关闭时把焦点还回去(键盘/读屏用户的上下文恢复) */
325
+ let lastFocused: HTMLElement | null = null
326
+
327
+ watch(open, async (value) => {
328
+ if (value) {
329
+ lastFocused = (document.activeElement as HTMLElement | null) ?? null
330
+ startTicker()
331
+ await nextTick()
332
+ panelEl.value?.focus()
333
+ } else {
334
+ stopTicker()
335
+ lastFocused?.focus?.()
336
+ lastFocused = null
337
+ }
338
+ })
339
+
340
+ onMounted(() => {
341
+ if (open.value) startTicker()
342
+ })
343
+
344
+ onUnmounted(() => {
345
+ stopTicker()
346
+ if (clearCascadeTimer !== null) {
347
+ window.clearTimeout(clearCascadeTimer)
348
+ clearCascadeTimer = null
349
+ }
350
+ })
351
+
352
+ function close(): void {
353
+ overlays.closeShade()
354
+ }
355
+
356
+ function dismiss(id: string): void {
357
+ dismissNotification(id)
358
+ }
359
+
360
+ // ==================== 通知卡:左右滑动删除 + 点击打开 ====================
361
+ // 滑动是增强(Android 通知同款手势),X 按钮保留为无障碍/键盘替代;
362
+ // 驻留项(sticky = 需要处理)不响应滑动与关闭。点击打开只对有关联应用的
363
+ // 通知生效;滑动中抑制点击,避免「滑到一半松手」误触发打开。
364
+
365
+ /** 拖动阈值(px):超过即删除,未超回弹 */
366
+ const SWIPE_DISMISS_PX = 88
367
+
368
+ /** 正在拖动的卡片 id 与位移 x(拖动中无过渡,跟手) */
369
+ const dragId = ref<string | null>(null)
370
+ const dragX = ref(0)
371
+ /** 已释放但正在滑出动画的卡片(位移定格在屏外,动画结束 dismiss) */
372
+ const swipeOut = ref<{ id: string; x: number } | null>(null)
373
+
374
+ let dragStartX = 0
375
+ let dragStartY = 0
376
+ let dragAxis: 'x' | 'y' | null = null
377
+ let suppressTap = false
378
+
379
+ /** 拖动中状态(模板据此关过渡) */
380
+ function cardDragState(id: string): { dragging: boolean } {
381
+ return { dragging: dragId.value === id }
382
+ }
383
+
384
+ /** 卡片位移样式:拖动跟手(由 cardDragState 关过渡),滑出动画定格屏外,其余静止 */
385
+ function cardStyle(item: ShellNotification): Record<string, string> {
386
+ const style: Record<string, string> = {
387
+ boxShadow: 'var(--mobile-card-shadow)',
388
+ touchAction: 'pan-y',
389
+ }
390
+ if (dragId.value === item.id) {
391
+ style.transform = `translateX(${dragX.value}px)`
392
+ } else if (swipeOut.value?.id === item.id) {
393
+ style.transform = `translateX(${swipeOut.value.x}px)`
394
+ }
395
+ return style
396
+ }
397
+
398
+ /** 起点在按钮上(X)不开始滑动;驻留项不响应 */
399
+ function onCardPointerDown(e: PointerEvent, item: ShellNotification): void {
400
+ if (item.sticky) return
401
+ if ((e.target as HTMLElement).closest('button')) return
402
+ dragId.value = item.id
403
+ dragX.value = 0
404
+ dragStartX = e.clientX
405
+ dragStartY = e.clientY
406
+ dragAxis = null
407
+ suppressTap = false
408
+ }
409
+
410
+ function onCardPointerMove(e: PointerEvent, item: ShellNotification): void {
411
+ if (dragId.value !== item.id) return
412
+ const dx = e.clientX - dragStartX
413
+ const dy = e.clientY - dragStartY
414
+ // 首帧定轴:水平位移占优才开始拖(超过 8px);垂直交给列表滚动
415
+ if (dragAxis === null) {
416
+ if (Math.abs(dx) < 8 && Math.abs(dy) < 8) return
417
+ dragAxis = Math.abs(dx) > Math.abs(dy) ? 'x' : 'y'
418
+ if (dragAxis === 'y') {
419
+ resetCardDrag(item.id)
420
+ return
421
+ }
422
+ }
423
+ if (dragAxis !== 'x') return
424
+ e.preventDefault()
425
+ dragX.value = dx
426
+ suppressTap = true
427
+ }
428
+
429
+ function onCardPointerUp(_e: PointerEvent, item: ShellNotification): void {
430
+ if (dragId.value !== item.id) return
431
+ const x = dragX.value
432
+ dragId.value = null
433
+ if (Math.abs(x) > SWIPE_DISMISS_PX) {
434
+ // 滑出动画(notify-card 的 transform 过渡生效)后移除;x 定格在屏外
435
+ swipeOut.value = { id: item.id, x: x > 0 ? window.innerWidth : -window.innerWidth }
436
+ window.setTimeout(() => {
437
+ swipeOut.value = null
438
+ dismiss(item.id)
439
+ }, 220)
440
+ return
441
+ }
442
+ // 回弹:dragX 归零,由卡片 transition 负责动画
443
+ dragX.value = 0
444
+ }
445
+
446
+ function resetCardDrag(id: string): void {
447
+ if (dragId.value === id) {
448
+ dragId.value = null
449
+ dragX.value = 0
450
+ }
451
+ }
452
+
453
+ /** 整卡点击打开(有关联应用时);纯滑动的松手不触发放开 */
454
+ function onCardClick(item: ShellNotification): void {
455
+ if (!item.appId || suppressTap) return
456
+ void openApp(item.appId)
457
+ }
458
+
459
+ function clearAll(): void {
460
+ clearNotifications()
461
+ }
462
+
463
+ // ==================== 全部删除(级联飞离动画) ====================
464
+ // 点「清除全部」:非驻留卡按 index 等差延迟(48ms/张)依次加速右飞,
465
+ // 最后一张飞出后才清空 store——删除有可见表达而不是瞬间消失(prefers-reduced-motion
466
+ // 下动画被 CSS 禁用,仍以完整时长走 clear 逻辑,行为不受动画影响)。
467
+ const FLEE_STEP_MS = 48
468
+ const FLEE_DURATION_MS = 360 /* 与 CSS .notify-card--flee 动画时长一致 + 余量 */
469
+
470
+ /** 级联飞离进行中(防重入;动画结束时清空 store) */
471
+ const clearingAll = ref(false)
472
+ let clearCascadeTimer: number | null = null
473
+
474
+ function clearAllCascade(): void {
475
+ if (clearingAll.value) return
476
+ const fleeCount = notifications.value.filter((n) => !n.sticky).length
477
+ if (fleeCount === 0) {
478
+ clearAll()
479
+ return
480
+ }
481
+ clearingAll.value = true
482
+ const totalMs = (fleeCount - 1) * FLEE_STEP_MS + FLEE_DURATION_MS
483
+ clearCascadeTimer = window.setTimeout(() => {
484
+ clearCascadeTimer = null
485
+ clearingAll.value = false
486
+ clearAll()
487
+ }, totalMs)
488
+ }
489
+
490
+ /** 去审批:关面板 + 进应用详情(那里有「批准并启动」) */
491
+ function openApproval(appId: string): void {
492
+ close()
493
+ nav.openDetail(appId)
494
+ }
495
+
496
+ /** 打开通知关联的应用(走统一打开口径:待审批会落到详情页) */
497
+ async function openApp(appId: string): Promise<void> {
498
+ close()
499
+ await openShellApp(appId)
500
+ }
501
+ </script>