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

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 (114) hide show
  1. package/README.md +363 -2
  2. package/README_en.md +353 -0
  3. package/bin/build.js +269 -0
  4. package/bin/cli.js +96 -0
  5. package/bin/lib.js +349 -0
  6. package/bin/manifest-gen.js +324 -0
  7. package/bin/package.js +150 -0
  8. package/bin/scaffold.js +285 -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 +51 -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 +328 -0
  25. package/dev-shell/src/locales/index.ts +70 -0
  26. package/dev-shell/src/locales/shell.ts +328 -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 +351 -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 +155 -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 +496 -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 +378 -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 +316 -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 +415 -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 +35 -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/useToast.ts +33 -0
  71. package/dev-shell/src/shell/index.ts +88 -0
  72. package/dev-shell/src/shell/logger.ts +45 -0
  73. package/dev-shell/src/shell/permissions.ts +145 -0
  74. package/dev-shell/src/shell/registry.ts +220 -0
  75. package/dev-shell/src/shell/styles/shell.css +841 -0
  76. package/dev-shell/src/shell/types.ts +137 -0
  77. package/dev-shell/src/shell/utils.ts +54 -0
  78. package/dev-shell/src/styles/main.css +153 -0
  79. package/dev-shell/src/styles/mobile.css +884 -0
  80. package/dev-shell/src/styles/wallpaper.css +130 -0
  81. package/dev-shell/src/theme.ts +71 -0
  82. package/dev-shell/src/vite-env.d.ts +20 -0
  83. package/dev-shell/tailwind.config.js +101 -0
  84. package/dev-shell/tsconfig.json +16 -0
  85. package/dev-shell/vite.config.ts +130 -0
  86. package/dist/index.d.ts +84 -0
  87. package/dist/index.js +161 -0
  88. package/dist/types.d.ts +637 -0
  89. package/dist/types.js +0 -0
  90. package/dist/vite-plugin.d.ts +16 -0
  91. package/dist/vite-plugin.js +95 -0
  92. package/package.json +80 -3
  93. package/src/constants.ts +6 -0
  94. package/src/global-dialog.ts +168 -0
  95. package/src/index.ts +87 -0
  96. package/src/runtime.ts +44 -0
  97. package/src/types.ts +715 -0
  98. package/src/ui/PluginGlobalDialog.vue +388 -0
  99. package/src/ui/Select.d.ts +37 -0
  100. package/src/ui/Select.vue +307 -0
  101. package/src/ui/plugin-global-dialog.d.ts +11 -0
  102. package/src/ui/useSwipeTabs.d.ts +20 -0
  103. package/src/ui/useSwipeTabs.ts +53 -0
  104. package/src/vite-plugin.ts +132 -0
  105. package/template/.gitignore +4 -0
  106. package/template/README.md +46 -0
  107. package/template/package.json +23 -0
  108. package/template/plugin.json +13 -0
  109. package/template/rust/Cargo.toml +19 -0
  110. package/template/rust/src/lib.rs +33 -0
  111. package/template/src/env.d.ts +24 -0
  112. package/template/src/index.ts +37 -0
  113. package/template/tsconfig.json +17 -0
  114. package/template/vite.config.ts +21 -0
@@ -0,0 +1,155 @@
1
+ /**
2
+ * dev-shell 数据源:调试对象 → 壳内应用
3
+ * -----------------------------------------------------------------------------
4
+ * 这是「壳」与「被调试对象」之间的唯一耦合面,与宿主 `src/shell/adapters/pluginAppSource.ts`
5
+ * 同位置同职责:宿主把插件运行时投影成 ShellApp,本文件把 dev-shell 的调试记录
6
+ * (内置应用 + 被调试插件)投影成 ShellApp。壳内 UI 对两者无感。
7
+ *
8
+ * 两处与宿主不同,都是浏览器环境的必然结果,不是偷懒:
9
+ * 1. 启动 = `loader.activatePlugin`(重新跑插件 activate),停止 = `deactivatePlugin`;
10
+ * 没有 WASM 后端,也就没有宿主那套 runtime 生命周期。
11
+ * 2. 权限授予是纯展示:dev-shell 全程跳过权限检查(README「Mock 边界」已声明),
12
+ * 因此 setPermissionGrant 明确返回 false,壳据此把开关置灰并说明原因——
13
+ * 不做「本地写一下就假装生效」的降级。
14
+ */
15
+
16
+ import { plugins, type DevPluginRecord } from '../../registry'
17
+ import { isLockedPermission } from '../permissions'
18
+ import { getShellRegistry } from '../registry'
19
+ import type {
20
+ ShellApp,
21
+ ShellAppSource,
22
+ ShellAppState,
23
+ ShellPermissionGrant,
24
+ } from '../types'
25
+
26
+ /** 数据源标识 */
27
+ export const DEV_APP_SOURCE_ID = 'dev-shell'
28
+
29
+ /** 无可用图标时的通用图形(24×24 path d,与壳内 path 图标同风格) */
30
+ const FALLBACK_ICON_PATH = 'M9.5 3a6.5 6.5 0 100 13 6.5 6.5 0 000-13z M14.5 12.5l6 6'
31
+
32
+ /**
33
+ * manifest 里的 icon 是**文件名**(如 `icon.svg`),不是 emoji 也不是 path d。
34
+ *
35
+ * 壳的图标契约只有 emoji / path d 两态,直接透传会被判成 emoji 并把 "icon.svg"
36
+ * 当字面量渲染出来。预览环境读不到包内资源(插件未打包),因此统一回退到通用图形;
37
+ * 真机上由宿主数据源解析真实图标,这条只影响 dev-shell。
38
+ */
39
+ function resolveIcon(icon: unknown): string | undefined {
40
+ if (typeof icon !== 'string' || !icon) return undefined
41
+ if (/\.(svg|png|webp|jpe?g)$/i.test(icon)) return FALLBACK_ICON_PATH
42
+ return icon
43
+ }
44
+
45
+ /** 调试记录状态 → 壳内运行态(口径对齐宿主 adapter 的映射表) */
46
+ function mapState(record: DevPluginRecord): ShellAppState {
47
+ switch (record.state) {
48
+ case 'activated':
49
+ return 'running'
50
+ case 'error':
51
+ return 'error'
52
+ case 'deactivated':
53
+ return 'disabled'
54
+ default:
55
+ return 'stopped'
56
+ }
57
+ }
58
+
59
+ /** 权限清单 → 授予项 */
60
+ function mapPermissions(record: DevPluginRecord): ShellPermissionGrant[] {
61
+ const manifest = record.manifest as Record<string, unknown>
62
+ const declared = Array.isArray(manifest.permissions) ? manifest.permissions : []
63
+ const errored = record.state === 'error'
64
+ return declared
65
+ .filter((key): key is string => typeof key === 'string')
66
+ .map((key) => ({
67
+ key,
68
+ // dev-shell 跳过权限检查(全部视为授予);加载失败的应用显示为未授予,
69
+ // 免得「明明没起来」却在列表里显示成满权限在跑
70
+ granted: !errored,
71
+ locked: isLockedPermission(key),
72
+ }))
73
+ }
74
+
75
+ /** 单条调试记录 → 壳内应用模型 */
76
+ export function toShellApp(record: DevPluginRecord): ShellApp {
77
+ const manifest = record.manifest as Record<string, unknown>
78
+ const str = (key: string): string | undefined =>
79
+ typeof manifest[key] === 'string' ? (manifest[key] as string) : undefined
80
+
81
+ return {
82
+ id: record.id,
83
+ name: record.name,
84
+ version: str('version') ?? '0.0.0',
85
+ description: str('description'),
86
+ author: str('author'),
87
+ icon: resolveIcon(manifest.icon),
88
+ official: record.builtin === true,
89
+ state: mapState(record),
90
+ // 失败原因随状态一起投影:应用列表与详情页都靠它说明「为什么启动失败」,
91
+ // 只给一个「启动失败」徽标等于让用户自己猜
92
+ error: record.error,
93
+ permissions: mapPermissions(record),
94
+ // 运行面不从清单下发:插件在 activate 时才注册 surface,因此走 resolveSurface
95
+ contributions: {},
96
+ }
97
+ }
98
+
99
+ /**
100
+ * 数据源对「怎么启动/停止一个调试对象」不做假设,只接受注入
101
+ *
102
+ * 依赖倒置的好处:适配器因此可以在没有加载器(及其 SFC 依赖链)的环境里被测,
103
+ * 且换启动策略不必改壳内任何代码。
104
+ */
105
+ export interface DevAppSourceDeps {
106
+ activate: (appId: string) => Promise<void>
107
+ deactivate: (appId: string) => Promise<void>
108
+ }
109
+
110
+ /**
111
+ * dev-shell 数据源
112
+ *
113
+ * 清单 = 内置应用 + 被调试插件,两者同构并列:内置的「模拟终端」不再是壳的调试页,
114
+ * 而是一个真正的应用(自持运行面),这样它与被调试插件走的是同一条加载与渲染路径。
115
+ */
116
+ export function createDevAppSource(deps: DevAppSourceDeps): ShellAppSource {
117
+ return {
118
+ id: DEV_APP_SOURCE_ID,
119
+
120
+ async list(): Promise<ShellApp[]> {
121
+ return plugins.value.map(toShellApp)
122
+ },
123
+
124
+ async launch(appId: string): Promise<void> {
125
+ await deps.activate(appId)
126
+ },
127
+
128
+ async stop(appId: string): Promise<void> {
129
+ await deps.deactivate(appId)
130
+ },
131
+
132
+ /**
133
+ * 逐项权限开关:dev-shell 全程跳过权限检查,没有可写的真源
134
+ *
135
+ * 明确返回 false,让壳把开关置灰并说明——「点了就通过」的假成功会让插件开发者
136
+ * 误以为权限逻辑已验证。
137
+ */
138
+ async setPermissionGrant(): Promise<boolean> {
139
+ return false
140
+ },
141
+
142
+ /**
143
+ * 延迟解析运行面
144
+ *
145
+ * 与宿主同口径:应用未注册 surface 就返回 undefined,运行屏渲染「该应用尚未提供
146
+ * 运行面」空态并写明原因,绝不静默找替代面。
147
+ *
148
+ * 这里刻意不记日志:本方法被运行屏的 computed 响应式反复调用,一次「没有运行面」
149
+ * 会刷出成百上千条重复日志,把真正有用的 warn 淹掉。空态本身已经把原因写清楚。
150
+ */
151
+ resolveSurface(appId: string) {
152
+ return getShellRegistry().getApp(appId)?.contributions.surface?.component
153
+ },
154
+ }
155
+ }
@@ -0,0 +1,40 @@
1
+ <template>
2
+ <div class="plugin-context-host h-full min-h-0">
3
+ <component :is="component" v-if="component" />
4
+ <div v-else class="flex items-center justify-center h-full text-[var(--mobile-text-disabled)] text-sm">
5
+ {{ t('devshell.plugin.loadFailed') }}
6
+ </div>
7
+ </div>
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ /**
12
+ * PluginContextHost — 插件运行面容器(宿主 PluginViewHost 的 dev-shell 同形)
13
+ * -----------------------------------------------------------------------------
14
+ * provide('pluginContext') 给插件组件树(与宿主 `src/plugin/components/PluginViewHost.vue`
15
+ * 行为一致),插件组件经 inject('pluginContext') 取上下文。
16
+ *
17
+ * 存在的理由与宿主相同:壳直渲染应用运行面,不认识插件,因此「上下文注入」这件事
18
+ * 必须由插件侧自己包一层——壳里不能出现任何插件形态的细节。
19
+ */
20
+ import { provide, watch } from 'vue'
21
+ import { useI18n } from 'vue-i18n'
22
+ import { getPluginRecord } from '../../registry'
23
+
24
+ const props = defineProps<{
25
+ pluginId: string
26
+ component: any
27
+ }>()
28
+
29
+ const { t } = useI18n()
30
+
31
+ function syncContext(): void {
32
+ const record = getPluginRecord(props.pluginId)
33
+ if (record?.context) provide('pluginContext', record.context)
34
+ }
35
+
36
+ // 双保险:壳复用本组件实例(pluginId 变化但 setup 不重跑)时重新 provide,
37
+ // 否则子组件会 inject 到上一个插件的 context
38
+ syncContext()
39
+ watch(() => props.pluginId, syncContext)
40
+ </script>
@@ -0,0 +1,75 @@
1
+ <template>
2
+ <button
3
+ type="button"
4
+ class="flex flex-col items-center gap-1.5 py-2 rounded-[12px] transition-colors duration-200 active:bg-[var(--mobile-accent-muted)] active:opacity-70"
5
+ :aria-label="label"
6
+ @click="$emit('open', app.id)"
7
+ >
8
+ <span class="relative flex-shrink-0">
9
+ <ShellAppIcon :app="app" :size="44" />
10
+ <!-- 状态标记锚定图标右上角(随图标,不随名称宽度漂移)。
11
+ 待审批用「!」而不是小圆点:它需要用户动作,不是纯状态读数 -->
12
+ <span
13
+ v-if="app.state === 'approval'"
14
+ class="absolute -top-1 -right-1 flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-bold leading-none"
15
+ :style="{ background: 'var(--mobile-warning)', color: 'var(--mobile-text-on-accent)' }"
16
+ aria-hidden="true"
17
+ >
18
+ !
19
+ </span>
20
+ <span
21
+ v-else
22
+ class="absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full"
23
+ :style="{ background: stateDot }"
24
+ aria-hidden="true"
25
+ />
26
+ </span>
27
+ <span class="w-full text-center text-[var(--font-size-xs)] text-[var(--mobile-text-primary)] truncate">
28
+ {{ app.name }}
29
+ </span>
30
+ </button>
31
+ </template>
32
+
33
+ <script setup lang="ts">
34
+ /**
35
+ * 应用宫格单元(主屏应用宫格)
36
+ *
37
+ * 状态标记三档:待审批(! 角标,需要动作)/ 运行中(绿点)/ 失败(红点);
38
+ * 其余(已停止、已停用)不占角标——宫格里绝大多数应用是静默状态,全画标记
39
+ * 反而让真正需要注意的那个看不出来。
40
+ */
41
+ import { computed } from 'vue'
42
+ import { useI18n } from 'vue-i18n'
43
+ import type { ShellApp } from '../types'
44
+ import ShellAppIcon from './ShellAppIcon.vue'
45
+
46
+ const props = defineProps<{ app: ShellApp }>()
47
+ defineEmits<{ open: [appId: string] }>()
48
+
49
+ const { t } = useI18n()
50
+
51
+ const stateDot = computed(() => {
52
+ switch (props.app.state) {
53
+ case 'running':
54
+ return 'var(--mobile-success)'
55
+ case 'error':
56
+ return 'var(--mobile-error)'
57
+ default:
58
+ return 'transparent'
59
+ }
60
+ })
61
+
62
+ /** 可访问名称带上状态:读屏用户看不到角标与颜色 */
63
+ const label = computed(() => {
64
+ const state = props.app.state
65
+ const stateLabel =
66
+ state === 'approval'
67
+ ? t('shell.common.approval')
68
+ : state === 'running'
69
+ ? t('shell.common.running')
70
+ : state === 'error'
71
+ ? t('shell.common.error')
72
+ : t('shell.common.stopped')
73
+ return t('shell.home.appAria', { name: props.app.name, state: stateLabel })
74
+ })
75
+ </script>
@@ -0,0 +1,111 @@
1
+ <template>
2
+ <span
3
+ class="inline-flex items-center justify-center flex-shrink-0 overflow-hidden border"
4
+ :class="toneClass"
5
+ :style="boxStyle"
6
+ role="img"
7
+ :aria-label="app.name"
8
+ >
9
+ <!-- 图片图标:清单里写的是相对插件目录的路径(icon.svg / icon.png …),
10
+ 经 asset protocol 取图;加载失败退回首字母,不留空白格 -->
11
+ <img
12
+ v-if="kind === 'image' && app.iconUrl && !imageFailed"
13
+ :src="app.iconUrl"
14
+ :alt="app.name"
15
+ class="w-full h-full object-cover"
16
+ @error="imageFailed = true"
17
+ />
18
+ <!-- SVG path d(应用自带图标,24×24 视框 stroke 风格) -->
19
+ <svg
20
+ v-else-if="kind === 'path'"
21
+ :width="innerSize"
22
+ :height="innerSize"
23
+ viewBox="0 0 24 24"
24
+ fill="none"
25
+ stroke="currentColor"
26
+ stroke-width="1.8"
27
+ stroke-linecap="round"
28
+ stroke-linejoin="round"
29
+ aria-hidden="true"
30
+ >
31
+ <path :d="app.icon" />
32
+ </svg>
33
+ <!-- emoji 图标 -->
34
+ <span
35
+ v-else-if="kind === 'emoji'"
36
+ :style="{ fontSize: `${innerSize}px`, lineHeight: '1' }"
37
+ aria-hidden="true"
38
+ >{{ app.icon }}</span
39
+ >
40
+ <!-- 无图标 / 图片加载失败:首字母回退(中文名取首字比取不到拉丁字母更可读) -->
41
+ <span
42
+ v-else
43
+ :style="{ fontSize: `${Math.round(size * 0.42)}px`, fontWeight: 600 }"
44
+ aria-hidden="true"
45
+ >{{ initial }}</span
46
+ >
47
+ </span>
48
+ </template>
49
+
50
+ <script setup lang="ts">
51
+ /**
52
+ * 应用图标
53
+ *
54
+ * 四种形态归一:图片路径 / emoji / SVG path d / 首字母回退。判据集中在 utils.iconKindOf,
55
+ * 避免各屏各写一份「这是不是 path」的判断。
56
+ */
57
+ import { computed, ref, watch } from 'vue'
58
+ import type { ShellApp } from '../types'
59
+ import { iconKindOf, initialOf } from '../utils'
60
+
61
+ const props = withDefaults(
62
+ defineProps<{
63
+ app: ShellApp
64
+ /** 图标盒边长(px) */
65
+ size?: number
66
+ /** 色调:accent(强调底)/ plain(中性底)/ ghost(幽灵框,用于「更多」占位) */
67
+ tone?: 'accent' | 'plain' | 'ghost'
68
+ }>(),
69
+ { size: 44, tone: 'accent' },
70
+ )
71
+
72
+ const kind = computed(() => iconKindOf(props.app.icon))
73
+ const initial = computed(() => initialOf(props.app.name))
74
+ /** 图形占盒子的比例:emoji 顶格显小,path 留白更协调 */
75
+ const innerSize = computed(() => Math.round(props.size * (kind.value === 'emoji' ? 0.62 : 0.55)))
76
+
77
+ /** 图片加载失败标记:插件换图标后重置,避免停在首字母回退 */
78
+ const imageFailed = ref(false)
79
+ watch(
80
+ () => [props.app.icon, props.app.iconUrl],
81
+ () => {
82
+ imageFailed.value = false
83
+ },
84
+ )
85
+
86
+ /** 圆角随尺寸线性放大并钳制:小盒(列表行)接近方形角,大可盒(预览位)过渡到拟 Windows/Android 大圆角,避免同一图标在 12/16 两档间跳变 */
87
+ const borderRadius = computed(() => {
88
+ const r = Math.round(props.size * 0.25)
89
+ return `${Math.min(18, Math.max(10, r))}px`
90
+ })
91
+
92
+ const boxStyle = computed(() => ({
93
+ width: `${props.size}px`,
94
+ height: `${props.size}px`,
95
+ borderRadius: borderRadius.value,
96
+ }))
97
+
98
+ const toneClass = computed(() => {
99
+ switch (props.tone) {
100
+ case 'plain':
101
+ return 'bg-[var(--mobile-bg-elevated)] text-[var(--mobile-text-secondary)] border-[var(--mobile-border)]'
102
+ case 'ghost':
103
+ return 'bg-transparent text-[var(--mobile-text-secondary)] border-dashed border-[var(--mobile-border-hover)]'
104
+ default:
105
+ // emoji 与图片自带颜色,不再叠加前景色,否则会出现双色描边
106
+ return kind.value === 'emoji' || kind.value === 'image'
107
+ ? 'bg-[var(--mobile-bg-elevated)] border-[var(--mobile-border)]'
108
+ : 'bg-[var(--mobile-accent-muted)] text-[var(--mobile-accent)] border-[var(--mobile-border)]'
109
+ }
110
+ })
111
+ </script>
@@ -0,0 +1,46 @@
1
+ <template>
2
+ <div class="flex flex-col flex-1 min-h-0">
3
+ <!-- 应用运行面:组件由应用提供(或经数据源延迟解析),壳只负责挂载 -->
4
+ <component :is="surface" v-if="surface" :app="app" class="flex-1 min-h-0" />
5
+
6
+ <!-- 尚未注册运行面:渲染预留位并写明原因(应用内页面属于应用自己,
7
+ 平台不实现;应用注册 surface 后自动顶掉这里) -->
8
+ <ShellPlaceholderSurface v-else-if="app" :app="app" />
9
+
10
+ <!-- 应用不存在:给出原因,不留白屏 -->
11
+ <div v-else class="flex flex-1 items-center justify-center px-8 text-center">
12
+ <p class="text-[var(--font-size-base)] text-[var(--mobile-text-secondary)]">
13
+ {{ t('shell.run.notFound') }}
14
+ </p>
15
+ </div>
16
+ </div>
17
+ </template>
18
+
19
+ <script setup lang="ts">
20
+ /**
21
+ * 应用运行面容器(应用自持界面的挂载点)
22
+ *
23
+ * 壳在这里与「应用内部」划清边界:壳提供挂载点、生命周期与空态,应用自持全部业务 UI。
24
+ * 渲染优先级:
25
+ * ① 应用注册的 surface 组件(正路)
26
+ * ② 数据源延迟解析的运行面(应用 activate 之后才注册面时的兜底)
27
+ * ③ 预留位 + 空态说明
28
+ *
29
+ * 刻意没有第三条路:早期宿主壳曾按「工具箱页 → 导航 Tab → 终端主视图 → 插件路由」
30
+ * 回退,那等于让壳去认识四种插件形态,与「应用只自持一种运行面」的形态相悖;
31
+ * 找不到面就显式说没有(§5.1.3 fail-visible 形态 ①)。
32
+ */
33
+ import { computed } from 'vue'
34
+ import { useI18n } from 'vue-i18n'
35
+ import { useShellApps } from '../composables/useShellApps'
36
+ import ShellPlaceholderSurface from './ShellPlaceholderSurface.vue'
37
+
38
+ const props = defineProps<{ appId: string }>()
39
+
40
+ const { t } = useI18n()
41
+ const { getApp, resolveSurface } = useShellApps()
42
+
43
+ const app = computed(() => getApp(props.appId))
44
+ /** 用 appId 而非 app 对象做依赖:应用停止/启动后对象会换,但解析入口不变 */
45
+ const surface = computed(() => resolveSurface(props.appId))
46
+ </script>
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <span
3
+ class="inline-flex items-center justify-center flex-shrink-0 rounded-[12px] border border-[var(--mobile-border)]"
4
+ :style="{ width: `${size}px`, height: `${size}px`, background: 'var(--shell-brand-ink)' }"
5
+ role="img"
6
+ :aria-label="BRAND_NAME"
7
+ >
8
+ <svg :width="size * 0.62" :height="size * 0.62" viewBox="0 0 24 24" aria-hidden="true">
9
+ <!-- 品牌核心色:固定琥珀(深底 8.99:1)。不随用户色板变化,也不用于可点击控件 -->
10
+ <path d="M12 3 L18.5 12 L12 21 L5.5 12 Z" fill="var(--shell-brand-ember)" />
11
+ <path d="M12 8 L14.8 12 L12 16 L9.2 12 Z" fill="var(--shell-brand-ink)" />
12
+ </svg>
13
+ </span>
14
+ </template>
15
+
16
+ <script setup lang="ts">
17
+ /**
18
+ * 品牌标志底板
19
+ *
20
+ * 品牌层与 UI 层分离(brand-spec-mobile.md §1):底板恒为品牌深墨,图形恒为琥珀,
21
+ * 两者都不跟 --mobile-accent / data-palette 走。用户把主色换成海蓝时标志仍是琥珀。
22
+ */
23
+ withDefaults(defineProps<{ size?: number }>(), { size: 38 })
24
+
25
+ /** 品牌名是专有名词,不做本地化 */
26
+ const BRAND_NAME = 'WasmApp'
27
+ </script>
@@ -0,0 +1,123 @@
1
+ <template>
2
+ <ShellSheet
3
+ :open="appId !== null"
4
+ :title="app?.name ?? t('shell.capsule.title')"
5
+ @close="overlays.closeCapsule()"
6
+ >
7
+ <ShellGroupCard>
8
+ <button
9
+ v-for="item in items"
10
+ :key="item.id"
11
+ type="button"
12
+ class="flex items-center gap-3 w-full px-3 py-3 text-left transition-colors duration-200 min-h-[var(--mobile-touch-target-min)]"
13
+ :class="item.danger ? 'active:bg-[var(--mobile-error-muted)]' : 'active:bg-[var(--mobile-group-row-active)]'"
14
+ @click="select(item)"
15
+ >
16
+ <svg class="flex-shrink-0" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" :style="{ color: item.danger ? 'var(--mobile-error)' : 'var(--mobile-text-secondary)' }">
17
+ <path :d="item.icon" />
18
+ </svg>
19
+ <span class="flex-1 min-w-0 text-[var(--font-size-base)] truncate" :class="item.danger ? 'text-[var(--mobile-error)]' : 'text-[var(--mobile-text-primary)]'">
20
+ {{ item.label }}
21
+ </span>
22
+ </button>
23
+ </ShellGroupCard>
24
+
25
+ <template #footer>
26
+ <button
27
+ type="button"
28
+ class="w-full rounded-[10px] border border-[var(--mobile-border)] px-4 py-3 text-[var(--font-size-base)] text-[var(--mobile-text-secondary)] transition-colors duration-200 active:bg-[var(--mobile-accent-muted)] min-h-[var(--mobile-touch-target-min)]"
29
+ @click="overlays.closeCapsule()"
30
+ >
31
+ {{ t('shell.common.cancel') }}
32
+ </button>
33
+ </template>
34
+ </ShellSheet>
35
+ </template>
36
+
37
+ <script setup lang="ts">
38
+ /**
39
+ * 胶囊菜单
40
+ *
41
+ * 平台项与应用项在同一张卡里按 order 混排:平台项自带 order(权限 10 / 停用 30),
42
+ * 应用可用中间值插入。这是平台控制项与应用自定义项唯一的协作面。
43
+ *
44
+ * 标题用应用名而不是「应用」:菜单已经画在该应用的胶囊下方,再写一遍「应用」
45
+ * 等于没说;也不写「与小程序胶囊一致」这类方案期说明(2026-10-14 修订:宿主
46
+ * 文案只留事实与后果)。
47
+ *
48
+ * 自读覆盖层状态(不接 props):胶囊只有一个实例、由壳根统一渲染,
49
+ * 再往下传 appId 只是把同一份状态抄一遍。
50
+ */
51
+ import { computed } from 'vue'
52
+ import { useI18n } from 'vue-i18n'
53
+ import { useShellApps } from '../composables/useShellApps'
54
+ import { useShellNavigation } from '../composables/useShellNavigation'
55
+ import { useShellOverlays } from '../composables/useShellOverlays'
56
+ import ShellGroupCard from './ShellGroupCard.vue'
57
+ import ShellSheet from './ShellSheet.vue'
58
+
59
+ interface CapsuleEntry {
60
+ id: string
61
+ label: string
62
+ icon: string
63
+ order: number
64
+ /** 破坏性项(停用):红字 + 红按压底,与普通菜单项视觉区分 */
65
+ danger?: boolean
66
+ run: () => void | Promise<void>
67
+ }
68
+
69
+ const { t } = useI18n()
70
+ const nav = useShellNavigation()
71
+ const overlays = useShellOverlays()
72
+ const { getApp, stop } = useShellApps()
73
+
74
+ const appId = computed(() => overlays.capsuleAppId.value)
75
+ const app = computed(() => (appId.value ? getApp(appId.value) : undefined))
76
+
77
+ const items = computed<CapsuleEntry[]>(() => {
78
+ const id = appId.value
79
+ if (!id) return []
80
+
81
+ const platformItems: CapsuleEntry[] = [
82
+ {
83
+ id: 'platform:permissions',
84
+ label: t('shell.capsule.permissions'),
85
+ icon: 'M12 3l8 3v6c0 4.5-3.2 7.6-8 9-4.8-1.4-8-4.5-8-9V6l8-3z M9 12l2 2 4-4',
86
+ order: 10,
87
+ run: () => {
88
+ overlays.closeCapsule()
89
+ nav.openDetail(id)
90
+ },
91
+ },
92
+ {
93
+ id: 'platform:disable',
94
+ label: t('shell.capsule.disable'),
95
+ icon: 'M12 4V2m0 20v-2M4 12H2m20 0h-2 M12 7a5 5 0 100 10 5 5 0 000-10z M15.5 8.5L20 4M8.5 15.5L4 20',
96
+ order: 30,
97
+ danger: true,
98
+ run: async () => {
99
+ overlays.closeCapsule()
100
+ await stop(id)
101
+ },
102
+ },
103
+ ]
104
+
105
+ // 应用贡献项:wasm-app 可用 order 插在平台项之间(如 20 即位于权限与停用之间)
106
+ const appItems: CapsuleEntry[] = (app.value?.contributions.capsuleItems ?? []).map((item) => ({
107
+ id: `app:${item.id}`,
108
+ label: item.label,
109
+ icon: item.icon ?? 'M12 8h.01 M12 11v5 M12 21a9 9 0 100-18 9 9 0 000 18z',
110
+ order: item.order ?? 100,
111
+ run: async () => {
112
+ overlays.closeCapsule()
113
+ await item.onSelect?.(id)
114
+ },
115
+ }))
116
+
117
+ return [...platformItems, ...appItems].sort((a, b) => a.order - b.order)
118
+ })
119
+
120
+ async function select(item: CapsuleEntry): Promise<void> {
121
+ await item.run()
122
+ }
123
+ </script>
@@ -0,0 +1,49 @@
1
+ <template>
2
+ <component
3
+ :is="clickable ? 'button' : 'span'"
4
+ :type="clickable ? 'button' : undefined"
5
+ class="inline-flex items-center gap-1.5 rounded-[999px] border px-2.5 text-[var(--font-size-xs)] transition-colors duration-200"
6
+ :class="[toneClass, clickable ? 'min-h-[32px] hover:bg-[var(--mobile-accent-muted)] active:opacity-80' : 'py-1']"
7
+ @click="clickable && $emit('click', $event)"
8
+ >
9
+ <slot name="icon" />
10
+ <span class="truncate">{{ label }}</span>
11
+ </component>
12
+ </template>
13
+
14
+ <script setup lang="ts">
15
+ /**
16
+ * 状态胶囊
17
+ *
18
+ * 可点击与不可点击共用一套视觉(点击态额外补 hover/active 反馈,
19
+ * 保证触屏上有按压反馈——hover-only 在移动端等于没有反馈)。
20
+ */
21
+ import { computed } from 'vue'
22
+
23
+ const props = withDefaults(
24
+ defineProps<{
25
+ label: string
26
+ /** neutral 中性 / accent 强调 / success / warn / danger */
27
+ tone?: 'neutral' | 'accent' | 'success' | 'warn' | 'danger'
28
+ clickable?: boolean
29
+ }>(),
30
+ { tone: 'neutral', clickable: false },
31
+ )
32
+
33
+ defineEmits<{ click: [event: MouseEvent] }>()
34
+
35
+ const toneClass = computed(() => {
36
+ switch (props.tone) {
37
+ case 'accent':
38
+ return 'bg-[var(--mobile-accent-muted)] border-[var(--mobile-border-active)] text-[var(--mobile-accent)]'
39
+ case 'success':
40
+ return 'bg-[var(--mobile-success-muted)] border-transparent text-[var(--mobile-success)]'
41
+ case 'warn':
42
+ return 'bg-[var(--mobile-warning-muted)] border-transparent text-[var(--mobile-warning)]'
43
+ case 'danger':
44
+ return 'bg-[var(--mobile-error-muted)] border-transparent text-[var(--mobile-error)]'
45
+ default:
46
+ return 'bg-[var(--mobile-bg-elevated)] border-[var(--mobile-border)] text-[var(--mobile-text-secondary)]'
47
+ }
48
+ })
49
+ </script>
@@ -0,0 +1,17 @@
1
+ <template>
2
+ <div
3
+ class="overflow-hidden rounded-[12px] border border-[var(--mobile-group-border)] bg-[var(--mobile-bg-card)] divide-y divide-[var(--mobile-group-divider)]"
4
+ :style="{ boxShadow: 'var(--mobile-card-shadow)' }"
5
+ >
6
+ <slot />
7
+ </div>
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ /**
12
+ * 分组卡片
13
+ *
14
+ * 只提供容器形状(圆角/描边/分隔线),不含外边距——外边距由各屏的
15
+ * 内容区统一给,避免卡片自带间距后在窄屏上左右不对称。
16
+ */
17
+ </script>