@binblink/wasmnest-plugin-sdk-mobile 0.0.1 → 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 (34) hide show
  1. package/README.md +78 -2
  2. package/README_en.md +64 -2
  3. package/bin/build.js +4 -2
  4. package/bin/manifest-gen.js +3 -0
  5. package/bin/package.js +2 -1
  6. package/bin/scaffold.js +22 -8
  7. package/dev-shell/README.md +1 -1
  8. package/dev-shell/src/apps/mock-terminal/MockTerminalSlotCard.vue +13 -21
  9. package/dev-shell/src/locales/en-shell.ts +6 -2
  10. package/dev-shell/src/locales/shell.ts +5 -2
  11. package/dev-shell/src/mock-context.ts +28 -5
  12. package/dev-shell/src/shell/adapters/devAppSource.ts +2 -13
  13. package/dev-shell/src/shell/components/ShellNotificationShade.vue +22 -17
  14. package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +16 -35
  15. package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +58 -17
  16. package/dev-shell/src/shell/composables/useShellApps.ts +5 -3
  17. package/dev-shell/src/shell/composables/useShellOpen.ts +12 -3
  18. package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
  19. package/dev-shell/src/shell/slotCards.ts +47 -0
  20. package/dev-shell/src/shell/styles/shell.css +340 -26
  21. package/dev-shell/src/shell/surfaceIntent.ts +107 -0
  22. package/dev-shell/src/shell/types.ts +17 -2
  23. package/dev-shell/src/styles/mobile.css +981 -884
  24. package/dist/index.d.ts +44 -4
  25. package/dist/index.js +69 -1
  26. package/dist/types.d.ts +107 -6
  27. package/package.json +9 -1
  28. package/src/index.ts +9 -0
  29. package/src/types.ts +822 -715
  30. package/src/ui/AppUpdateSection.d.ts +44 -0
  31. package/src/ui/AppUpdateSection.vue +253 -0
  32. package/src/ui/QuickCard.d.ts +33 -0
  33. package/src/ui/QuickCard.vue +167 -0
  34. package/src/update.ts +123 -0
@@ -78,7 +78,9 @@
78
78
  </ShellGroupCard>
79
79
  </div>
80
80
 
81
- <!-- ==================== 权限 ==================== -->
81
+ <!-- ==================== 权限 ====================
82
+ 与移动端宿主 / 桌面端同口径:权限随应用包声明,由宿主整单裁决,
83
+ 详情页只读呈现,不提供逐项开关。 -->
82
84
  <ShellSection :title="t('shell.detail.permissions')" :note="permissionsNote" />
83
85
  <div class="px-4 pb-1">
84
86
  <ShellGroupCard v-if="permissionGroups.length > 0">
@@ -109,14 +111,8 @@
109
111
  {{ grant.scope }}
110
112
  </div>
111
113
  </div>
112
- <!-- 锁定项:不给开关,只标徽标——隐藏会让用户误以为应用没有该能力 -->
114
+ <!-- 锁定项:只标徽标——隐藏会让用户误以为应用没有该能力 -->
113
115
  <ShellChip v-if="grant.locked" :label="t('shell.detail.permissionLocked')" tone="neutral" />
114
- <Toggle
115
- v-else
116
- :model-value="grant.granted"
117
- :disabled="!permissionControlEnabled"
118
- @update:model-value="(next: boolean) => handleToggle(grant.key, next)"
119
- />
120
116
  </div>
121
117
  </template>
122
118
  </ShellGroupCard>
@@ -126,15 +122,16 @@
126
122
  >
127
123
  {{ t('mobile.plugin.noPermissions') }}
128
124
  </p>
129
- <!-- 能力缺失要显性说明:把开关置灰却不解释,用户会以为是应用的问题 -->
125
+ <!-- 只读说明:权限松紧由 manifest 声明与宿主整单裁决决定,详情页不提供开关 -->
130
126
  <p
131
- v-if="!permissionControlEnabled"
127
+ v-if="permissionGroups.length > 0"
132
128
  class="mt-2 px-1 text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]"
133
129
  >
134
- {{ t('shell.detail.permissionUnsupported') }}
130
+ {{ t('shell.detail.permissionsReadonly') }}
135
131
  </p>
136
- <p v-if="toggleError" class="mt-2 px-1 text-[var(--font-size-xs)]" :style="{ color: 'var(--mobile-error)' }">
137
- {{ toggleError }}
132
+ <!-- 审批失败等动作错误:不伪造成功态 -->
133
+ <p v-if="actionError" class="mt-2 px-1 text-[var(--font-size-xs)]" :style="{ color: 'var(--mobile-error)' }">
134
+ {{ actionError }}
138
135
  </p>
139
136
  </div>
140
137
 
@@ -216,14 +213,13 @@
216
213
  /**
217
214
  * 应用详情与权限
218
215
  *
219
- * 权限开关是 UX,裁决在 Rust 端(docs/security.md §1)。因此:
220
- * · 后端不支持逐项授予时,开关置灰并显式说明,不做「点了就算通过」的假成功
221
- * · 授权记录区没有后端真源,渲染空态而不是编造几条示例
216
+ * 权限清单只读(与移动端宿主 / 桌面端对齐):裁决在宿主端——审批整单 +
217
+ * 内容哈希钉扎,没有逐项授权命令。详情页只呈现声明事实,不提供开关。
218
+ * 授权记录区没有后端真源,渲染空态而不是编造几条示例。
222
219
  */
223
220
  import { computed, ref, watch } from 'vue'
224
221
  import { useI18n } from 'vue-i18n'
225
222
  import ConfirmDialog from '../ui/ConfirmDialog.vue'
226
- import Toggle from '../ui/Toggle.vue'
227
223
  import { useToast } from '../../composables/useToast'
228
224
  import { useShellApps } from '../../composables/useShellApps'
229
225
  import { useShellNavigation } from '../../composables/useShellNavigation'
@@ -239,8 +235,6 @@ const toast = useToast()
239
235
  const nav = useShellNavigation()
240
236
  const {
241
237
  getApp,
242
- supportsPermissionControl,
243
- setPermissionGrant,
244
238
  supportsRemove,
245
239
  removeApp,
246
240
  stop,
@@ -252,9 +246,6 @@ const {
252
246
  const appId = computed(() => nav.params.value.appId ?? '')
253
247
  const app = computed(() => getApp(appId.value))
254
248
 
255
- const permissionControlEnabled = computed(() =>
256
- appId.value ? supportsPermissionControl(appId.value) : false,
257
- )
258
249
  const canRemove = computed(() => (appId.value ? supportsRemove(appId.value) : false))
259
250
 
260
251
  /** 权限按能力域分组;未归类的新权限进「其他」组,保证不会因未归类而消失 */
@@ -324,24 +315,14 @@ const stateDot = computed(() => {
324
315
  }
325
316
  })
326
317
 
327
- const toggleError = ref<string | null>(null)
318
+ const actionError = ref<string | null>(null)
328
319
  /** 卸载二次确认(复用平台 ConfirmDialog,见模板) */
329
320
  const confirmRemove = ref(false)
330
321
  // 切换应用时清掉上一条的失败提示,避免张冠李戴
331
322
  watch(appId, () => {
332
- toggleError.value = null
323
+ actionError.value = null
333
324
  })
334
325
 
335
- async function handleToggle(key: string, next: boolean): Promise<void> {
336
- if (!appId.value) return
337
- const ok = await setPermissionGrant(appId.value, key, next)
338
- if (!ok) {
339
- toggleError.value = t('shell.detail.permissionToggleFailed', {
340
- reason: t('shell.detail.permissionUnsupported'),
341
- })
342
- }
343
- }
344
-
345
326
  async function handleStop(): Promise<void> {
346
327
  if (!appId.value) return
347
328
  await stop(appId.value)
@@ -357,7 +338,7 @@ async function handleApprove(): Promise<void> {
357
338
  if (!app.value) return
358
339
  const approved = await approveApp(app.value.id)
359
340
  if (!approved) {
360
- toggleError.value = t('shell.permissions.approveFailed')
341
+ actionError.value = t('shell.permissions.approveFailed')
361
342
  return
362
343
  }
363
344
  const started = await launch(app.value.id)
@@ -108,14 +108,36 @@
108
108
  </template>
109
109
 
110
110
  <!-- ======== 快捷卡片(应用贡献,横向轮播) ========
111
- 定宽卡片 + 原生 scroll-snap 横向滚动(原型 .slots 同形态):拍一屏只露一张,
112
- 滑动切下一张。定宽而非 flex-1 是刻意的——卡片内容由应用自持,等宽拉伸会让
113
- 单行信息量不同的卡片看起来参差。 -->
111
+ 与宿主同构:定宽卡片 + 原生 scroll-snap,多张时自动轮播(触摸 / 聚焦 /
112
+ 切后台 / 减少动效时停走);整张卡是宿主按钮,点击打开贡献方应用。 -->
114
113
  <template v-if="slotCards.length > 0">
115
- <ShellSection :title="t('shell.home.slotsTitle')" class="shell-reveal" :style="{ animationDelay: '80ms' }" />
116
- <div class="shell-slot-track shell-reveal" role="list" :style="{ animationDelay: '120ms' }">
114
+ <ShellSection :title="t('shell.home.slotsTitle')" class="shell-reveal" :style="{ animationDelay: '80ms' }">
115
+ <template v-if="slotCards.length > 1 && !reducedMotion" #action>
116
+ <button
117
+ type="button"
118
+ class="shell-icon-action"
119
+ :aria-label="playing ? t('shell.home.slotPause') : t('shell.home.slotPlay')"
120
+ @click="toggleAutoplay()"
121
+ >
122
+ <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
123
+ <template v-if="playing">
124
+ <path d="M9 5v14M15 5v14" />
125
+ </template>
126
+ <template v-else>
127
+ <path d="M8 5.5v13l10-6.5Z" />
128
+ </template>
129
+ </svg>
130
+ </button>
131
+ </template>
132
+ </ShellSection>
133
+ <div ref="slotTrack" class="shell-slot-track shell-reveal" role="list" :style="{ animationDelay: '120ms' }">
117
134
  <div v-for="card in slotCards" :key="card.key" class="shell-slot-item" role="listitem">
118
- <component :is="card.component" :app="card.app" />
135
+ <!-- 可访问名 = 隐藏动作前缀「打开 <应用>」+ 卡片内容:不覆盖应用自持的读数。
136
+ 点击除打开应用外,还把应用现算的入口意图投递给它(与宿主同构)。 -->
137
+ <button type="button" class="shell-slot-card" @click="openSlotCard(card)">
138
+ <span class="sr-only">{{ t('shell.home.slotOpen', { name: card.app.name }) }}</span>
139
+ <component :is="card.component" :app="card.app" />
140
+ </button>
119
141
  </div>
120
142
  </div>
121
143
  </template>
@@ -199,7 +221,7 @@
199
221
  * 正文案纪律(2026-10-14 修订):分组标题行只留标题与计数,不再写「平台自带」
200
222
  * 「由应用提供」「最近使用在前」这类方案期解释——用户看得到事实,不需要旁白。
201
223
  */
202
- import { computed } from 'vue'
224
+ import { computed, ref } from 'vue'
203
225
  import { useI18n } from 'vue-i18n'
204
226
  import { useShellApps } from '../../composables/useShellApps'
205
227
  import { useShellNavigation } from '../../composables/useShellNavigation'
@@ -208,6 +230,10 @@ import { useShellOpen } from '../../composables/useShellOpen'
208
230
  import { useShellOverlays } from '../../composables/useShellOverlays'
209
231
  import { useShellPreferences } from '../../composables/useShellPreferences'
210
232
  import { useShellRecent } from '../../composables/useShellRecent'
233
+ import { useSlotCarousel } from '../../composables/useSlotCarousel'
234
+ import { selectSlotCards, type ShellSlotCard } from '../../slotCards'
235
+ import { logger } from '../../logger'
236
+ import type { ShellSurfaceIntent } from '../../../../src/types'
211
237
  // dev-shell 无 asset protocol:自定义壁纸图恒不可达(wallpaperImage 恒 null),该导入宿主独有
212
238
  import type { ShellApp } from '../../types'
213
239
  import ShellAppCell from '../ShellAppCell.vue'
@@ -265,16 +291,31 @@ const runningOrdered = computed<ShellApp[]>(() => {
265
291
  })
266
292
  })
267
293
 
268
- /** 应用贡献的快捷卡片(按应用顺序展开,排序在 registry 侧完成) */
269
- const slotCards = computed(() =>
270
- apps.value.flatMap((app) =>
271
- (app.contributions.slots ?? []).map((slot) => ({
272
- key: `${app.id}:${slot.id}`,
273
- component: slot.component,
274
- app,
275
- })),
276
- ),
277
- )
294
+ /** 应用贡献的快捷卡片(注册顺序,超过展示上限的部分不渲染;与宿主同构) */
295
+ const slotCards = computed(() => selectSlotCards(apps.value))
296
+
297
+ /**
298
+ * 点击快捷卡片:打开应用 + 投递应用现算的入口意图(与宿主同构)
299
+ *
300
+ * `onPress` 抛错不阻断「打开应用」主路径,只落一条壳日志。
301
+ */
302
+ function openSlotCard(card: ShellSlotCard): void {
303
+ let intent: ShellSurfaceIntent | null | undefined
304
+ try {
305
+ intent = card.onPress?.()
306
+ } catch (e) {
307
+ logger.warn(`[shell] 快捷卡片入口意图计算失败 appId=${card.app.id}`, e)
308
+ }
309
+ void open(card.app.id, intent)
310
+ }
311
+
312
+ /** 轨道轮播(与宿主同构:自动播放 / 触摸停走 / 减少动效停走) */
313
+ const slotTrack = ref<HTMLElement | null>(null)
314
+ const {
315
+ playing,
316
+ reducedMotion,
317
+ toggle: toggleAutoplay,
318
+ } = useSlotCarousel(slotTrack, computed(() => slotCards.value.length))
278
319
 
279
320
  /** 系统宫格:平台自有面(应用管理 / 权限管理 / 设置),全部 push 进栈以便返回。
280
321
  * 每个入口一个档案色(tile*),色相用于入口辨识而非危险等级;
@@ -16,7 +16,7 @@ import { computed, ref, type Component, type ComputedRef, type Ref } from 'vue'
16
16
  import { i18n } from '../../i18n'
17
17
  import { logger } from '../logger'
18
18
  import { getShellRegistry } from '../registry'
19
- import type { ShellApp, ShellAppSource } from '../types'
19
+ import type { ShellApp, ShellAppSource, ShellInstallRestoreDecider } from '../types'
20
20
  import { pushRecent } from './useShellRecent'
21
21
  import { useShellNavigation } from './useShellNavigation'
22
22
  import { useShellNotifications } from './useShellNotifications'
@@ -307,7 +307,9 @@ function supportsInstall(): boolean {
307
307
  * @returns 安装后的应用 id;null = 用户取消(调用方不弹错误)。
308
308
  * 失败由 catch 抛出,错误已由 lastError 暴露。
309
309
  */
310
- async function installFromLocalPackage(): Promise<string | null> {
310
+ async function installFromLocalPackage(
311
+ decideRestore?: ShellInstallRestoreDecider,
312
+ ): Promise<string | null> {
311
313
  const source = registry
312
314
  .listSources()
313
315
  .find((s): s is ShellAppSource & Required<Pick<ShellAppSource, 'installFromLocalPackage'>> =>
@@ -318,7 +320,7 @@ async function installFromLocalPackage(): Promise<string | null> {
318
320
  return null
319
321
  }
320
322
  try {
321
- const installedId = await source.installFromLocalPackage()
323
+ const installedId = await source.installFromLocalPackage(decideRestore)
322
324
  if (installedId !== null) {
323
325
  await refresh()
324
326
  // 安装成功的新应用名要到刷新后的清单里取(安装前注册表里还没有它)
@@ -7,17 +7,25 @@
7
7
  *
8
8
  * 待审批应用是例外:它**不能启动**,点击直接进详情页走审批(那里有「批准并启动」),
9
9
  * 否则用户只会看到一条启动失败。
10
+ *
11
+ * 入口意图:快捷卡片可以在打开时带一个应用自定义的入口意图;意图在启动成功后
12
+ * 才入队,投递与消费都由应用自持(`context.ui.onSurfaceIntent`)。
10
13
  */
11
14
 
15
+ import type { ShellSurfaceIntent } from '../../../../src/types'
12
16
  import { useShellApps } from './useShellApps'
13
17
  import { useShellNavigation } from './useShellNavigation'
18
+ import { queueSurfaceIntent } from '../surfaceIntent'
14
19
 
15
20
  /** 启动并进入运行面;启动失败返回 false(由调用方决定是否提示) */
16
- export async function openShellApp(appId: string): Promise<boolean> {
21
+ export async function openShellApp(
22
+ appId: string,
23
+ intent?: ShellSurfaceIntent | null,
24
+ ): Promise<boolean> {
17
25
  const { launch, getApp } = useShellApps()
18
26
  const nav = useShellNavigation()
19
27
 
20
- // 待审批:进详情页审批,不尝试启动(启动必被后端拒绝)
28
+ // 待审批:进详情页审批,不尝试启动(启动必被后端拒绝);此时也无从进入应用内部
21
29
  if (getApp(appId)?.state === 'approval') {
22
30
  nav.openDetail(appId)
23
31
  return true
@@ -25,6 +33,7 @@ export async function openShellApp(appId: string): Promise<boolean> {
25
33
 
26
34
  const ok = await launch(appId)
27
35
  if (!ok) return false
36
+ queueSurfaceIntent(appId, intent)
28
37
  nav.openApp(appId)
29
38
  return true
30
39
  }
@@ -32,4 +41,4 @@ export async function openShellApp(appId: string): Promise<boolean> {
32
41
  /** 组合式入口(组件内使用) */
33
42
  export function useShellOpen(): { open: typeof openShellApp } {
34
43
  return { open: openShellApp }
35
- }
44
+ }
@@ -0,0 +1,238 @@
1
+ /**
2
+ * 首页快捷卡片轮播
3
+ * -----------------------------------------------------------------------------
4
+ * 轨道本身是原生 scroll-snap(一张一拍屏),本组合式只负责「自动往前走」:
5
+ * - 间隔 5s 推进一张,到末尾回到第一张;
6
+ * - 用户触摸 / 滚轮 / 键盘聚焦时停表,停手 8s 后恢复(不改变用户显式暂停);
7
+ * - 系统「减少动效」开启时默认不自动播放,且不渲染暂停 / 播放控件
8
+ * (否则就是一个点了没反应的按钮);
9
+ * - 页面不可见(切后台 / 打开其它应用)时停表。
10
+ *
11
+ * 动效判据:ui-ux-pro-max `--domain ux / Auto-Rotating Content Controls`——
12
+ * 自动轮播必须给用户暂停控制,并在 reduced motion 下停走;滚动定位在
13
+ * reduced motion 下降级为瞬时跳转。
14
+ */
15
+ import { onBeforeUnmount, onMounted, ref, watch, type Ref } from 'vue'
16
+
17
+ /** 自动轮播步进间隔 */
18
+ export const SLOT_AUTOPLAY_INTERVAL_MS = 5000
19
+ /** 用户操作后恢复自动轮播的空闲等待 */
20
+ export const SLOT_AUTOPLAY_RESUME_MS = 8000
21
+
22
+ /** 系统是否要求减少动效(真机 / dev-shell 统一口径;取不到按不需要处理) */
23
+ export function prefersReducedMotion(): boolean {
24
+ return (
25
+ typeof window !== 'undefined' &&
26
+ typeof window.matchMedia === 'function' &&
27
+ window.matchMedia('(prefers-reduced-motion: reduce)').matches
28
+ )
29
+ }
30
+
31
+ /** 首页快捷卡片轮播句柄 */
32
+ export interface SlotCarousel {
33
+ /** 当前定格卡序号(0 起;用户滑动时随滚动同步) */
34
+ activeIndex: Ref<number>
35
+ /** 用户是否开启自动轮播(暂停按钮状态;临时触摸暂停不改变它) */
36
+ playing: Ref<boolean>
37
+ /** 系统要求减少动效时为 true,此时不自动播放也不提供播放控件 */
38
+ reducedMotion: Ref<boolean>
39
+ /** 暂停 / 恢复自动轮播 */
40
+ toggle(): void
41
+ }
42
+
43
+ /**
44
+ * @param track 横向轨道元素(子元素 = 卡片 item,顺序与卡片一致)
45
+ * @param count 当前卡片数(清单异步到达时自动起表 / 停表)
46
+ */
47
+ export function useSlotCarousel(
48
+ track: Ref<HTMLElement | null>,
49
+ count: Ref<number>,
50
+ ): SlotCarousel {
51
+ const activeIndex = ref(0)
52
+ const reducedMotion = ref(prefersReducedMotion())
53
+ const playing = ref(!reducedMotion.value)
54
+ /** 触摸 / 聚焦期间的临时停表(不写回 playing) */
55
+ let holding = false
56
+
57
+ let timer: ReturnType<typeof setInterval> | null = null
58
+ let resumeTimer: ReturnType<typeof setTimeout> | null = null
59
+ let scrollFrame = 0
60
+ let media: MediaQueryList | null = null
61
+
62
+ function total(): number {
63
+ return Math.max(0, count.value)
64
+ }
65
+
66
+ function stopTimer(): void {
67
+ if (timer !== null) {
68
+ clearInterval(timer)
69
+ timer = null
70
+ }
71
+ }
72
+
73
+ function canPlay(): boolean {
74
+ return (
75
+ playing.value &&
76
+ !holding &&
77
+ !reducedMotion.value &&
78
+ total() > 1 &&
79
+ !(typeof document !== 'undefined' && document.hidden)
80
+ )
81
+ }
82
+
83
+ function startTimer(): void {
84
+ stopTimer()
85
+ if (canPlay()) timer = setInterval(advance, SLOT_AUTOPLAY_INTERVAL_MS)
86
+ }
87
+
88
+ function cardElement(index: number): HTMLElement | null {
89
+ const el = track.value
90
+ const child = el?.children[index]
91
+ return child instanceof HTMLElement ? child : null
92
+ }
93
+
94
+ function paddingStart(el: HTMLElement): number {
95
+ const value = parseFloat(getComputedStyle(el).paddingInlineStart)
96
+ return Number.isFinite(value) ? value : 0
97
+ }
98
+
99
+ /** 定位到某张卡:对齐 scroll-snap 的 start 锚点(扣除轨道起始内边距) */
100
+ function goTo(index: number): void {
101
+ const limit = total()
102
+ if (limit === 0) return
103
+ const next = Math.min(Math.max(index, 0), limit - 1)
104
+ activeIndex.value = next
105
+
106
+ const el = track.value
107
+ const item = cardElement(next)
108
+ if (!el || !item) return
109
+ const left = Math.max(
110
+ 0,
111
+ item.getBoundingClientRect().left - el.getBoundingClientRect().left + el.scrollLeft - paddingStart(el),
112
+ )
113
+ const behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth'
114
+ if (typeof el.scrollTo === 'function') el.scrollTo({ left, behavior })
115
+ else el.scrollLeft = left
116
+ }
117
+
118
+ function advance(): void {
119
+ const limit = total()
120
+ if (limit <= 1) return
121
+ goTo((activeIndex.value + 1) % limit)
122
+ }
123
+
124
+ /** 用户滑动后把序号对齐到最近一张(自动轮播从可见卡继续) */
125
+ function syncActiveIndex(): void {
126
+ const el = track.value
127
+ if (!el || el.children.length === 0) return
128
+ const base = el.getBoundingClientRect().left + paddingStart(el)
129
+ let nearest = 0
130
+ let best = Number.POSITIVE_INFINITY
131
+ for (let i = 0; i < el.children.length; i += 1) {
132
+ const child = el.children[i]
133
+ if (!(child instanceof HTMLElement)) continue
134
+ const distance = Math.abs(child.getBoundingClientRect().left - base)
135
+ if (distance < best) {
136
+ best = distance
137
+ nearest = i
138
+ }
139
+ }
140
+ if (nearest !== activeIndex.value) activeIndex.value = nearest
141
+ }
142
+
143
+ function onScroll(): void {
144
+ if (scrollFrame) return
145
+ scrollFrame = requestAnimationFrame(() => {
146
+ scrollFrame = 0
147
+ syncActiveIndex()
148
+ })
149
+ }
150
+
151
+ /** 用户开始操作:临时停表,停手一段时间后自动恢复 */
152
+ function holdTemporarily(): void {
153
+ holding = true
154
+ stopTimer()
155
+ if (resumeTimer !== null) clearTimeout(resumeTimer)
156
+ resumeTimer = setTimeout(() => {
157
+ resumeTimer = null
158
+ holding = false
159
+ startTimer()
160
+ }, SLOT_AUTOPLAY_RESUME_MS)
161
+ }
162
+
163
+ /** 焦点离开轨道:立刻恢复(键盘用户不该等空闲计时) */
164
+ function releaseHold(): void {
165
+ if (resumeTimer !== null) {
166
+ clearTimeout(resumeTimer)
167
+ resumeTimer = null
168
+ }
169
+ holding = false
170
+ startTimer()
171
+ }
172
+
173
+ function toggle(): void {
174
+ if (reducedMotion.value) return
175
+ playing.value = !playing.value
176
+ if (playing.value) startTimer()
177
+ else stopTimer()
178
+ }
179
+
180
+ function onVisibilityChange(): void {
181
+ if (document.hidden) stopTimer()
182
+ else startTimer()
183
+ }
184
+
185
+ function onMotionPreferenceChange(event: MediaQueryListEvent): void {
186
+ reducedMotion.value = event.matches
187
+ if (event.matches) stopTimer()
188
+ else startTimer()
189
+ }
190
+
191
+ watch(count, () => {
192
+ const last = Math.max(0, total() - 1)
193
+ if (activeIndex.value > last) activeIndex.value = last
194
+ startTimer()
195
+ })
196
+
197
+ onMounted(() => {
198
+ const el = track.value
199
+ el?.addEventListener('pointerdown', holdTemporarily, { passive: true })
200
+ el?.addEventListener('wheel', holdTemporarily, { passive: true })
201
+ el?.addEventListener('focusin', holdTemporarily)
202
+ el?.addEventListener('focusout', releaseHold)
203
+ el?.addEventListener('scroll', onScroll, { passive: true })
204
+ if (typeof document !== 'undefined') {
205
+ document.addEventListener('visibilitychange', onVisibilityChange)
206
+ }
207
+ if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
208
+ media = window.matchMedia('(prefers-reduced-motion: reduce)')
209
+ media.addEventListener?.('change', onMotionPreferenceChange)
210
+ }
211
+ startTimer()
212
+ })
213
+
214
+ onBeforeUnmount(() => {
215
+ stopTimer()
216
+ if (resumeTimer !== null) {
217
+ clearTimeout(resumeTimer)
218
+ resumeTimer = null
219
+ }
220
+ if (scrollFrame) {
221
+ cancelAnimationFrame(scrollFrame)
222
+ scrollFrame = 0
223
+ }
224
+ const el = track.value
225
+ el?.removeEventListener('pointerdown', holdTemporarily)
226
+ el?.removeEventListener('wheel', holdTemporarily)
227
+ el?.removeEventListener('focusin', holdTemporarily)
228
+ el?.removeEventListener('focusout', releaseHold)
229
+ el?.removeEventListener('scroll', onScroll)
230
+ if (typeof document !== 'undefined') {
231
+ document.removeEventListener('visibilitychange', onVisibilityChange)
232
+ }
233
+ media?.removeEventListener?.('change', onMotionPreferenceChange)
234
+ media = null
235
+ })
236
+
237
+ return { activeIndex, playing, reducedMotion, toggle }
238
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 首页快捷卡片选择
3
+ * -----------------------------------------------------------------------------
4
+ * 应用贡献的卡片可能远多于首页轨道能承载的量(每张一拍屏),宿主按注册顺序
5
+ * 取前 N 张并自动轮播;超出部分不展示,也不做「无限滚动」——轨道不是应用列表,
6
+ * 用户找完整应用入口走下方宫格 / 应用管理页。
7
+ *
8
+ * 顺序口径:应用注册顺序(壳清单顺序)→ 应用内槽位 order(registry 已排序)。
9
+ * 不按最近使用重排:卡片是应用自持内容的读数,位置漂移会让用户每次都要重新找。
10
+ */
11
+ import type { Component } from 'vue'
12
+ import type { ShellSurfaceIntent } from '../../../src/types'
13
+ import type { ShellApp } from './types'
14
+
15
+ /** 首页最多展示的快捷卡片数(一拍屏一张,5 张即一轮完整轮播) */
16
+ export const SHELL_SLOT_MAX_CARDS = 5
17
+
18
+ /** 首页轨道上的一张卡片视图 */
19
+ export interface ShellSlotCard {
20
+ /** 稳定 key:appId + 槽位 id(同一应用可贡献多张) */
21
+ key: string
22
+ component: Component
23
+ app: ShellApp
24
+ /** 点击时要投递给应用的入口意图(按点击时刻现算;缺省 = 只打开应用) */
25
+ onPress?: () => ShellSurfaceIntent | null | undefined
26
+ }
27
+
28
+ /** 按注册顺序摊平并截断到展示上限 */
29
+ export function selectSlotCards(
30
+ apps: readonly ShellApp[],
31
+ max: number = SHELL_SLOT_MAX_CARDS,
32
+ ): ShellSlotCard[] {
33
+ if (max <= 0) return []
34
+ const cards: ShellSlotCard[] = []
35
+ for (const app of apps) {
36
+ for (const slot of app.contributions.slots ?? []) {
37
+ if (cards.length >= max) return cards
38
+ cards.push({
39
+ key: `${app.id}:${slot.id}`,
40
+ component: slot.component,
41
+ app,
42
+ onPress: slot.onPress,
43
+ })
44
+ }
45
+ }
46
+ return cards
47
+ }