@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,137 @@
1
+ /**
2
+ * Dev Shell 宿主壳契约
3
+ * -----------------------------------------------------------------------------
4
+ * 本文件是 dev-shell 内置 mini 壳与「应用形态」之间的唯一契约面,字段与宿主
5
+ * `wasmnest-mobile/src/shell/types.ts` **逐字段一致**(同构要求:插件在 dev-shell
6
+ * 里跑通就必须能在真机壳里跑通,两边形态不同就没有调试价值)。
7
+ *
8
+ * 贡献描述符(surface / slot / capsuleItem / settingsEntry)不在这里重定义,
9
+ * 直接复用 SDK 的 `src/types.ts`——那是插件侧契约的真源,宿主壳与 dev-shell
10
+ * 都只是它的消费方。重定义一份只会制造第三处可能漂移的地方。
11
+ *
12
+ * 漂移防线:`__tests__/shell/contractDrift.test.ts` 比对本文件与宿主 types.ts
13
+ * 的字段集,宿主新增字段而这里没跟随时直接测红。
14
+ *
15
+ * 边界纪律(与 docs/architecture.md §1 同源):壳只回答「平台怎么组织应用」,不回答
16
+ * 「某个应用做什么业务」。应用内部的业务由其 surface 组件自持。
17
+ */
18
+
19
+ import type { Component } from 'vue'
20
+ import type {
21
+ ShellCapsuleItem,
22
+ ShellSlotContribution,
23
+ ShellSurfaceContribution,
24
+ } from '../../../src/types'
25
+
26
+ export type {
27
+ ShellCapsuleItem,
28
+ ShellSlotContribution,
29
+ ShellSurfaceContribution,
30
+ }
31
+
32
+ /** 可释放句柄:注册扩展点的返回值,dispose 即摘除该注册 */
33
+ export interface Disposable {
34
+ dispose(): void
35
+ }
36
+
37
+ /** 应用在壳内的运行态(壳语义,与宿主 union 逐字一致) */
38
+ export type ShellAppState =
39
+ /** 前台/后台运行中 */
40
+ | 'running'
41
+ /** 已安装但未启动 */
42
+ | 'stopped'
43
+ /** 待人工审批(权限整单批准 + 内容哈希钉扎):批准前不可启动 */
44
+ | 'approval'
45
+ /** 被用户或平台停用(启用后才可启动) */
46
+ | 'disabled'
47
+ /** 上次启动失败(保留数据,可重试) */
48
+ | 'error'
49
+
50
+ /** 单条权限的授予情况 */
51
+ export interface ShellPermissionGrant {
52
+ /** 权限词(与移动端权限词汇真源一致,如 terminal:output / fs:write / bus) */
53
+ key: string
54
+ /** 是否已授予 */
55
+ granted: boolean
56
+ /** 默认授予且不可关闭(storage 等底座能力):置灰并标注,不隐藏 */
57
+ locked?: boolean
58
+ /** 授予范围补充说明 */
59
+ scope?: string
60
+ }
61
+
62
+ /** 应用对宿主壳的全部贡献(可随清单下发,也可运行时逐项注册) */
63
+ export interface ShellAppContributions {
64
+ slots?: ShellSlotContribution[]
65
+ surface?: ShellSurfaceContribution
66
+ capsuleItems?: ShellCapsuleItem[]
67
+ }
68
+
69
+ /** 宿主壳中的应用模型 */
70
+ export interface ShellApp {
71
+ id: string
72
+ name: string
73
+ version: string
74
+ description?: string
75
+ author?: string
76
+ /** 图标:emoji / SVG path d / 相对插件目录的图片路径(如 icon.svg);都取不到时壳生成首字母回退 */
77
+ icon?: string
78
+ /**
79
+ * 图片图标的已解析地址(asset protocol URL):数据源能解析时必须给出,否则首字母回退。
80
+ * dev-shell 的浏览器预览读不到插件包内资源(adapters/devAppSource.ts 的 resolveIcon 会把
81
+ * 图片路径换成通用 path 图形),因此调试数据源当前不产出该字段;保留字段是为与宿主
82
+ * ShellApp 契约逐字一致(dev-shell/__tests__/shell/contractDrift.test.ts 钉住)。
83
+ */
84
+ iconUrl?: string
85
+ /** 官方应用标记 */
86
+ official?: boolean
87
+ /** 装配角色(manifest kind;系统服务分区判据) */
88
+ kind?: string
89
+ state: ShellAppState
90
+ permissions: ShellPermissionGrant[]
91
+ /** 应用数据占用(字节);未统计时 undefined,UI 显示「—」而非伪造 0 */
92
+ sizeBytes?: number
93
+ /** 上一次失败的简短原因(state === 'error' 时展示) */
94
+ error?: string
95
+ contributions: ShellAppContributions
96
+ }
97
+
98
+ /**
99
+ * 应用数据源:壳与具体应用形态之间的唯一耦合面
100
+ *
101
+ * 能力可选:不支持的能力不实现该方法,壳据此不渲染对应入口,不做静默降级。
102
+ */
103
+ export interface ShellAppSource {
104
+ /** 数据源标识(日志与诊断用) */
105
+ readonly id: string
106
+ /** 拉取应用清单(全量覆盖该数据源此前的记录) */
107
+ list(): Promise<ShellApp[]>
108
+ /** 启动应用(幂等:已运行直接返回) */
109
+ launch(appId: string): Promise<void>
110
+ /** 停止应用(幂等:未运行直接返回) */
111
+ stop(appId: string): Promise<void>
112
+ /** 逐项变更权限授予;@returns true 已生效,false 不支持(壳据此置灰并说明) */
113
+ setPermissionGrant?(
114
+ appId: string,
115
+ permissionKey: string,
116
+ granted: boolean,
117
+ ): Promise<boolean>
118
+ /**
119
+ * 批准应用的权限申请(整单:批准全部声明权限 + 内容哈希钉扎)。
120
+ * 未实现时壳不渲染「批准」入口——不提供点了没反应的按钮。
121
+ */
122
+ approve?(appId: string): Promise<void>
123
+ /** 延迟解析运行面组件;未实现时壳回退到应用自带的 contributions.surface */
124
+ resolveSurface?(appId: string): Component | undefined
125
+ /**
126
+ * 安装本地应用包(数据源自行完成选包与校验)。
127
+ *
128
+ * @returns 安装后的应用 id;`null` = 用户取消选包(不是失败)。
129
+ * 未实现时壳不渲染「安装本地包」入口——不提供点了没反应的按钮。
130
+ */
131
+ installFromLocalPackage?(): Promise<string | null>
132
+ /** 卸载应用并删除其数据;未实现时壳不渲染「卸载」入口 */
133
+ remove?(appId: string): Promise<boolean>
134
+ /** 查询 / 设置「启动时自动激活」偏好(未实现时壳不渲染自启开关) */
135
+ isAutostart?(appId: string): Promise<boolean>
136
+ setAutostart?(appId: string, autostart: boolean): Promise<void>
137
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Dev Shell 壳展示层小工具(纯函数,与宿主 shell/utils.ts 同构)
3
+ *
4
+ * 只放无状态纯函数,方便单测与复用。
5
+ */
6
+
7
+ /** 字节数格式化(1024 进制,保留 1 位小数;<1KB 直接给 B) */
8
+ export function formatBytes(bytes: number | undefined): string {
9
+ if (bytes === undefined || bytes === null || Number.isNaN(bytes)) return '—'
10
+ if (bytes < 1024) return `${bytes} B`
11
+ const units = ['KB', 'MB', 'GB', 'TB']
12
+ let value = bytes / 1024
13
+ let unitIndex = 0
14
+ while (value >= 1024 && unitIndex < units.length - 1) {
15
+ value /= 1024
16
+ unitIndex += 1
17
+ }
18
+ return `${value.toFixed(1)} ${units[unitIndex]}`
19
+ }
20
+
21
+ /**
22
+ * 首字母回退(无图标应用用)
23
+ *
24
+ * 取首个字符而非首字母:中文名取首字比取不到拉丁字母更可读。
25
+ */
26
+ export function initialOf(name: string): string {
27
+ const trimmed = (name ?? '').trim()
28
+ return trimmed ? trimmed.slice(0, 1).toUpperCase() : '?'
29
+ }
30
+
31
+ /** 图标形态:emoji / SVG path d / 图片路径 / 无 */
32
+ export type IconKind = 'emoji' | 'path' | 'image' | 'none'
33
+
34
+ /**
35
+ * 图片图标的扩展名判据(与宿主 shell/utils.ts 同源)
36
+ *
37
+ * 调试数据源读不到插件包内资源,会把图片路径换成通用 path 图形(见 adapters/devAppSource.ts
38
+ * 的 resolveIcon),因此壳内当前不会从 `icon` 命中 image;保留判据是为了与宿主同构——
39
+ * 数据源给出已解析 iconUrl 时,两种运行环境走同一条渲染分支。
40
+ */
41
+ const IMAGE_ICON_RE = /\.(png|jpe?g|webp|gif|svg)$/i
42
+
43
+ /**
44
+ * 判断图标形态
45
+ *
46
+ * 与宿主 utils.iconKindOf 同构,判据顺序一致:图片路径必须先于 path 判定——「icon.svg」
47
+ * 这类值不含路径指令字符,漏掉这一步会被当 emoji 字面量渲染。
48
+ */
49
+ export function iconKindOf(icon: string | undefined): IconKind {
50
+ if (!icon) return 'none'
51
+ if (IMAGE_ICON_RE.test(icon.trim())) return 'image'
52
+ if (/^[MmLlHhVvCcSsQqTtAaZz0-9\s.,+-]+$/.test(icon)) return 'path'
53
+ return 'emoji'
54
+ }
@@ -0,0 +1,153 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ :root {
6
+ /* 手机框最大高度:844px 真机尺寸,视口矮时收窄保证整体可见(底部导航不被裁切) */
7
+ --dev-shell-frame-h: min(844px, calc(100vh - 7rem));
8
+ }
9
+
10
+ @supports (height: 1dvh) {
11
+ :root {
12
+ /* 动态视口:浏览器工具条收起/展开时高度不闪变 */
13
+ --dev-shell-frame-h: min(844px, calc(100dvh - 7rem));
14
+ }
15
+ }
16
+
17
+ /* ===== 基础(与宿主 style.css 对齐的最小集合) ===== */
18
+ :root {
19
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
20
+ line-height: 1.5;
21
+ font-weight: 400;
22
+ font-synthesis: none;
23
+ text-rendering: optimizeLegibility;
24
+ -webkit-font-smoothing: antialiased;
25
+ -moz-osx-font-smoothing: grayscale;
26
+
27
+ /* 安全区域(浏览器中恒为 0,保留变量兼容插件安全区逻辑) */
28
+ --safe-area-inset-top: env(safe-area-inset-top, 0px);
29
+ --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
30
+ --safe-area-inset-left: env(safe-area-inset-left, 0px);
31
+ --safe-area-inset-right: env(safe-area-inset-right, 0px);
32
+ --safe-area-top: var(--safe-area-inset-top);
33
+ --safe-area-bottom: var(--safe-area-inset-bottom);
34
+ --keyboard-height: 0px;
35
+ --keyboard-visible: 0;
36
+ }
37
+
38
+ :root {
39
+ color-scheme: light;
40
+ }
41
+ :root.dark {
42
+ color-scheme: dark;
43
+ }
44
+
45
+ :root {
46
+ --font-size-xs: 10px;
47
+ --font-size-sm: 12px;
48
+ --font-size-base: 14px;
49
+ --font-size-lg: 16px;
50
+ --font-size-xl: 18px;
51
+ }
52
+
53
+ body {
54
+ margin: 0;
55
+ min-width: 320px;
56
+ min-height: 100vh;
57
+ background: #14141a;
58
+ }
59
+
60
+ /* ===== 移动端字体规则(与宿主一致) ===== */
61
+ .mobile-ui {
62
+ font-size: var(--font-size-base);
63
+ line-height: 1.5;
64
+ }
65
+ .mobile-ui h1,
66
+ .mobile-ui .text-xl,
67
+ .mobile-ui .title-xl {
68
+ font-size: var(--font-size-xl);
69
+ font-weight: 600;
70
+ line-height: 1.3;
71
+ }
72
+ .mobile-ui h2,
73
+ .mobile-ui .text-lg,
74
+ .mobile-ui .title-lg {
75
+ font-size: var(--font-size-lg);
76
+ font-weight: 600;
77
+ line-height: 1.4;
78
+ }
79
+ .mobile-ui .text-sm,
80
+ .mobile-ui small {
81
+ font-size: var(--font-size-sm);
82
+ line-height: 1.5;
83
+ }
84
+ .mobile-ui .text-xs {
85
+ font-size: var(--font-size-xs);
86
+ line-height: 1.4;
87
+ }
88
+ .mobile-ui button,
89
+ .mobile-ui .btn {
90
+ font-size: var(--font-size-base);
91
+ font-weight: 500;
92
+ }
93
+ .mobile-ui input,
94
+ .mobile-ui textarea,
95
+ .mobile-ui select {
96
+ font-size: var(--font-size-base);
97
+ }
98
+
99
+ .text-xs {
100
+ font-size: var(--font-size-xs);
101
+ }
102
+ .text-sm {
103
+ font-size: var(--font-size-sm);
104
+ }
105
+ .text-base {
106
+ font-size: var(--font-size-base);
107
+ }
108
+ .text-lg {
109
+ font-size: var(--font-size-lg);
110
+ }
111
+ .text-xl {
112
+ font-size: var(--font-size-xl);
113
+ }
114
+
115
+ /* ===== 移动端容器 ===== */
116
+ .mobile-app {
117
+ min-height: 100vh;
118
+ min-height: 100dvh;
119
+ transition: padding-top 0.25s cubic-bezier(0.4, 0, 0.2, 1);
120
+ }
121
+ .mobile-nav-safe {
122
+ padding-bottom: var(--safe-area-bottom, 0px);
123
+ }
124
+ .mobile-header-safe {
125
+ padding-top: var(--safe-area-top, 0px);
126
+ }
127
+ .mobile-input-bar {
128
+ margin-bottom: env(keyboard-inset-bottom, 0px);
129
+ transition: margin-bottom 0.25s cubic-bezier(0.4, 0, 0.2, 1);
130
+ }
131
+
132
+ /* ===== 滚动条(token 驱动,深浅色自适应) ===== */
133
+ ::-webkit-scrollbar {
134
+ width: 8px;
135
+ height: 8px;
136
+ }
137
+ ::-webkit-scrollbar-track {
138
+ background: transparent;
139
+ }
140
+ ::-webkit-scrollbar-thumb {
141
+ background: color-mix(in srgb, var(--mobile-text-muted) 35%, transparent);
142
+ border-radius: 4px;
143
+ }
144
+ ::-webkit-scrollbar-thumb:hover {
145
+ background: color-mix(in srgb, var(--mobile-text-muted) 55%, transparent);
146
+ }
147
+
148
+ /* ===== 终端输出 ===== */
149
+ .terminal-output {
150
+ font-family: Consolas, Monaco, monospace;
151
+ white-space: pre-wrap;
152
+ word-break: break-word;
153
+ }