apptify 0.2.0 → 0.5.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 (73) hide show
  1. package/README.md +40 -239
  2. package/dist/apptify.css +1 -1
  3. package/dist/apptify.js +4153 -2177
  4. package/dist/components/button.d.ts +1 -1
  5. package/dist/components/content.d.ts +73 -362
  6. package/dist/components/date-picker.d.ts +10 -0
  7. package/dist/components/forms.d.ts +77 -18
  8. package/dist/components/foundation.d.ts +2061 -111
  9. package/dist/components/gallery-scrollbar.d.ts +46 -0
  10. package/dist/components/mobile-image-viewer.d.ts +166 -0
  11. package/dist/components/navibar.d.ts +80 -0
  12. package/dist/components/overlays.d.ts +127 -158
  13. package/dist/components/tabs.d.ts +117 -0
  14. package/dist/core/context.d.ts +573 -9
  15. package/dist/core/desktop-image-enter.d.ts +6 -0
  16. package/dist/core/desktop-image-return.d.ts +1 -0
  17. package/dist/core/device.d.ts +5 -0
  18. package/dist/core/image-gallery-motion.d.ts +2 -0
  19. package/dist/core/image-geometry.d.ts +28 -0
  20. package/dist/core/image-motion.d.ts +18 -0
  21. package/dist/core/layers.d.ts +2 -0
  22. package/dist/core/motion.d.ts +2 -0
  23. package/dist/core/popup-motion.d.ts +12 -0
  24. package/dist/core/popup-placement.d.ts +31 -0
  25. package/dist/core/preview-navigation.d.ts +5 -0
  26. package/dist/index.d.ts +1214 -339
  27. package/docs/COMPONENTS.md +18 -16
  28. package/docs/PLAYGROUND-TEMPLATE.md +51 -0
  29. package/docs/VALIDATION.md +25 -1
  30. package/package.json +35 -7
  31. package/templates/playground/README.md +21 -0
  32. package/templates/playground/gitignore +3 -0
  33. package/templates/playground/index.html +26 -0
  34. package/templates/playground/package.json +26 -0
  35. package/templates/playground/playground/App.vue +73 -0
  36. package/templates/playground/playground/ComponentDemo.vue +234 -0
  37. package/templates/playground/playground/catalog.ts +80 -0
  38. package/templates/playground/playground/components/ComponentIndex.vue +62 -0
  39. package/templates/playground/playground/components/PageFooter.vue +3 -0
  40. package/templates/playground/playground/components/UserMenu.vue +132 -0
  41. package/templates/playground/playground/components/not-found-paper-scene.vue +210 -0
  42. package/templates/playground/playground/components/not-found-paper-story.ts +149 -0
  43. package/templates/playground/playground/env.d.ts +1 -0
  44. package/templates/playground/playground/main.ts +8 -0
  45. package/templates/playground/playground/router/index.ts +24 -0
  46. package/templates/playground/playground/style.css +228 -0
  47. package/templates/playground/playground/views/[...all].vue +68 -0
  48. package/templates/playground/playground/views/components.vue +126 -0
  49. package/templates/playground/playground/views/index.vue +75 -0
  50. package/templates/playground/playground/views/settings.vue +98 -0
  51. package/templates/playground/public/images/SOURCES.md +21 -0
  52. package/templates/playground/public/images/airpods-max-orange.jpg +0 -0
  53. package/templates/playground/public/images/architecture.jpg +0 -0
  54. package/templates/playground/public/images/city.jpg +0 -0
  55. package/templates/playground/public/images/coast.jpg +0 -0
  56. package/templates/playground/public/images/desert.jpg +0 -0
  57. package/templates/playground/public/images/food.jpg +0 -0
  58. package/templates/playground/public/images/forest.jpg +0 -0
  59. package/templates/playground/public/images/lake.jpg +0 -0
  60. package/templates/playground/public/images/mountains.jpg +0 -0
  61. package/templates/playground/public/images/snow.jpg +0 -0
  62. package/templates/playground/public/images/sunset.jpg +0 -0
  63. package/templates/playground/public/images/waterfall.jpg +0 -0
  64. package/templates/playground/source-snapshot.json +111 -0
  65. package/templates/playground/tsconfig.json +24 -0
  66. package/templates/playground/vite.config.ts +9 -0
  67. package/tooling/create-playground.mjs +35 -0
  68. package/tooling/prepare-package.mjs +35 -0
  69. package/tooling/prepare-playground.mjs +103 -0
  70. package/tooling/test-create-apptify.mjs +76 -0
  71. package/tooling/test-playground-package.mjs +188 -0
  72. package/tooling/vite.d.ts +5 -0
  73. package/tooling/vite.js +10 -0
package/README.md CHANGED
@@ -1,43 +1,18 @@
1
1
  # Apptify
2
2
 
3
- 面向桌面与移动端的个人 Vue 3 组件库。统一使用 `<apple-*>` 前缀,保留 Vuetify 的 Ripple 指令,而不继承它的整套 Material 组件外观。
3
+ 面向桌面与移动端的 Vue 3 组件库,采用 Apple 风格设计,统一使用 `<apple-*>` 标签。支持主题切换、减少动效、表单、图片预览与多层弹窗;支持 JavaScript、TypeScript 和 Options API。
4
4
 
5
- 设计借鉴 Apple 网站的排版、留白、层次与交互节奏;不是 Apple 官方产品,也不声称全部控件都与 Apple 网站逐像素一致。表格、级联选择、验证码、下拉刷新等能力是在同一套视觉语言下的扩展。
5
+ [npm](https://www.npmjs.com/package/apptify) · [组件 API](docs/COMPONENTS.md) · [应用模板](docs/PLAYGROUND-TEMPLATE.md)
6
6
 
7
- 当前导出并注册 **68 个组件**:基础 9 个、表单 18 个、内容与移动交互 29 个、弹层 10 个、动效 2 个。其中 `AppleOverlayHost` 是由 Provider 自动挂载的基础设施,通常直接使用其余 67 个即可。完整实际 API 见 [组件参考](docs/COMPONENTS.md)。
8
-
9
- ## 本地运行与安装
10
-
11
- 项目尚未发布到 npm。不要把 `npm install apptify` 当成已发布包的安装方式。
12
-
13
- 建议使用 Node.js 22 LTS 或 24 LTS;测试工具不支持奇数版本的 Node.js。
14
-
15
- 在本仓库执行:
16
-
17
- ```sh
18
- npm ci
19
- npm run dev
20
- ```
21
-
22
- 开发服务器地址以终端输出为准。开发页面是可交互的组件工作台,不是组件库的业务页面模板。
23
-
24
- 在另一个项目中使用本地包:
7
+ ## 安装
25
8
 
26
9
  ```sh
27
- # 在本仓库构建并生成 apptify-0.1.0.tgz
28
- npm run build
29
- npm pack
30
-
31
- # 在消费项目执行,将路径替换为实际包路径
32
- npm install /absolute/path/apptify/apptify-0.1.0.tgz
33
- npm install vue@^3.5 vuetify@^3.9
10
+ npm install apptify vue@^3.5 vuetify@^3.9
34
11
  ```
35
12
 
36
- Vue 与 Vuetify 是 peer dependencies。图标使用 `lucide-vue-next`,图片预览的缩放与手势使用 `@panzoom/panzoom`。本库没有要求安装 Vuetify 插件或导入其完整样式,也不需要 `<v-app>`。
37
-
38
- ## 接入应用
13
+ Vue 与 Vuetify 是 peer dependencies。Vuetify 仅用于 Ripple,无需安装其插件、导入完整样式或使用 `<v-app>`。
39
14
 
40
- JavaScript 和 TypeScript 项目都可直接使用。消费项目不需要 TypeScript、`tsconfig.json` 或 `<script setup>`;普通 `<script>` 与 Options API 是完整支持的用法。随包提供的类型声明也可以为 JavaScript 编辑器提供补全。
15
+ ## 快速接入
41
16
 
42
17
  ```js
43
18
  // src/main.js
@@ -46,30 +21,23 @@ import { createAppleUI } from 'apptify'
46
21
  import 'apptify/style.css'
47
22
  import App from './App.vue'
48
23
 
49
- const apple = createAppleUI({
50
- theme: 'system',
51
- motion: 'auto',
52
- persist: true,
53
- storageKey: 'my-app:appearance',
54
- })
55
-
56
- createApp(App).use(apple).mount('#app')
24
+ createApp(App)
25
+ .use(createAppleUI({ theme: 'system', motion: 'auto', persist: true }))
26
+ .mount('#app')
57
27
  ```
58
28
 
59
29
  ```vue
60
30
  <!-- App.vue -->
61
31
  <template>
62
32
  <apple-provider>
63
- <main>
64
- <apple-container>
65
- <apple-card title="个人资料" subtitle="保持联系。">
66
- <apple-input v-model="name" label="姓名" autocomplete="name" />
67
- <template #actions>
68
- <apple-button @click="save">保存</apple-button>
69
- </template>
70
- </apple-card>
71
- </apple-container>
72
- </main>
33
+ <apple-container>
34
+ <apple-card title="个人资料">
35
+ <apple-input v-model="name" label="姓名" />
36
+ <template #actions>
37
+ <apple-button @click="save">保存</apple-button>
38
+ </template>
39
+ </apple-card>
40
+ </apple-container>
73
41
  </apple-provider>
74
42
  </template>
75
43
 
@@ -85,210 +53,43 @@ export default {
85
53
  </script>
86
54
  ```
87
55
 
88
- 这是 Options API 用法。插件注册 PascalCase 名称,Vue 模板同时支持 `<AppleCard>` 和 `<apple-card>`。所有组件也可命名导入并局部注册。
89
-
90
- `AppleProvider` 应包住业务 UI。它应用主题变量、监听系统偏好、提供同主题的 Teleport 目标,并自动渲染 `AppleOverlayHost`。**不要在同一上下文再额外渲染一份 Host。** 根 Provider 不传属性时复用插件上下文;嵌套 Provider 或显式指定 `theme` / `motion` 的 Provider 会建立局部上下文。嵌套 Provider 未指定的主题与动效属性跟随父级更新。
91
-
92
- `this.$apple` 始终指向插件级上下文。局部 Provider 内的组件如需使用局部主题、通知或弹层,使用 Options API 注入:
93
-
94
- ```js
95
- import { appleKey } from 'apptify'
96
-
97
- export default {
98
- inject: { apple: { from: appleKey } },
99
- methods: {
100
- showMessage() {
101
- this.apple.notify('使用当前 Provider 的通知')
102
- },
103
- },
104
- }
105
- ```
106
-
107
- 也导出 `useApple()` 供 Composition API 的 `setup()` 使用,但不需要为接入组件库重写现有 Options API 页面。
108
-
109
- ## 主题与动效
110
-
111
- 内置主题为 `light`、`dark`、`graphite`、`rose`;`system` 表示跟随系统浅深色。主题即时生效,不需要刷新页面。设置 `persist: true` 才会保存主题名称、动效等级并同步其他标签页的同名存储设置;自定义主题定义应通过初始化 `themes` 配置或启动时的 `register()` 再次提供。
112
-
113
- ```js
114
- this.$apple.theme.set('dark')
115
- this.$apple.theme.register('forest', {
116
- accent: '#237047',
117
- 'accent-text': '#ffffff',
118
- bg: '#f4f7f5',
119
- surface: '#ffffff',
120
- }, 'light')
121
- this.$apple.theme.set('forest')
122
- this.$apple.motion.set('reduced')
123
- ```
124
-
125
- `register(name, tokens, scheme)` 自动补齐对应浅色或深色主题的默认 token。可覆盖 `bg`、`surface`、`surface-alt`、`text`、`secondary`、`border`、`accent`、`accent-text`、`danger`、`success`、`warning`、`shadow`、`radius`,对应 `--apple-*` CSS 变量。注册后先调用 `set()` 才会切换;`system` 是保留名称。
126
-
127
- | 动效值 | 行为 |
128
- | --- | --- |
129
- | `auto` | 自动遵循系统减少动态效果偏好。 |
130
- | `full` | 在全局策略与系统偏好允许时使用完整动效。 |
131
- | `reduced` | 减少位移、缩放和持续动态,保留必要状态反馈。 |
132
- | `none` | 关闭动效,包括按钮 Ripple。 |
133
- | `inherit` | 组件默认值,继承当前 Provider 的策略;不是全局配置值。 |
134
-
135
- 全局 `none` / `reduced` 是动效上限,安全优先。组件可以再降低动效,但 `motion="full"` 不能越过全局限制或系统的减少动态效果偏好。支持 `motion` 的组件以 [API 表](docs/COMPONENTS.md) 为准;静态布局组件不需要动效属性。
136
-
137
- ```vue
138
- <apple-card motion="none" zoom="none" title="静态内容" />
139
- <apple-button :ripple="false">仅关闭这个按钮的波纹</apple-button>
140
- ```
56
+ `AppleProvider` 提供主题与弹层宿主,无需额外添加 `AppleOverlayHost`。插件全局注册组件,也支持命名导入并局部注册。嵌套 Provider 内可用 `appleKey` 注入局部上下文,或在 `setup()` 中使用 `useApple()`。
141
57
 
142
- ## Dialog 与反向通道
58
+ ## 常用 API
143
59
 
144
60
  ```js
145
- const dialog = this.$apple.dialog({
146
- title: '删除文件?',
147
- message: '此操作不能撤销。',
148
- confirmText: '删除',
149
- cancelText: '取消',
150
- tone: 'danger',
151
- })
61
+ this.$apple.theme.value.set('dark')
62
+ this.$apple.motion.value.set('reduced')
63
+ this.$apple.notify('保存成功', { tone: 'success' })
152
64
 
153
- const confirmed = await dialog.result
154
- // 默认确认返回 true,取消返回 false,关闭按钮 / Escape 返回 undefined。
155
- if (confirmed === true) this.$apple.notify('文件已删除', { tone: 'success' })
65
+ const dialog = this.$apple.dialog({ title: '保存修改?', cancelText: '取消' })
66
+ const confirmed = await dialog.result // 确认 true,取消 false,关闭 undefined
156
67
  ```
157
68
 
158
- 每次调用创建独立层。`dialog` 句柄含 `id`、`close(value?)`、`update(patch)` 与 `result` Promise。`this.$apple.overlays.closeTop()` 只关闭最上面的非通知弹层;已有层不会被新层覆盖。声明式 `<apple-dialog v-model="opened">` 与命令式弹层共享焦点栈和滚动锁。
69
+ 内置主题:`light`、`dark`、`graphite`、`rose`;`system` 跟随系统。全局动效:`auto`、`full`、`reduced`、`none`。共享状态使用 ref,在 JavaScript 中通过 `.value` 访问。
159
70
 
160
- 自定义弹层组件接收 `close`、`sendMessage` 两个 prop。下面的编辑组件通过反向通道请求父调用方保存,父调用方再打开第二层确认。
71
+ Props、事件、插槽、自定义主题与弹层消息回传见[组件 API](docs/COMPONENTS.md)。
161
72
 
162
- ```vue
163
- <!-- ProfileEditor.vue -->
164
- <template>
165
- <apple-input v-model="name" label="姓名" />
166
- <apple-button :loading="saving" @click="save">保存资料</apple-button>
167
- </template>
73
+ ## 创建完整应用
168
74
 
169
- <script>
170
- export default {
171
- props: {
172
- initialName: { type: String, default: '' },
173
- close: { type: Function, required: true },
174
- sendMessage: { type: Function, required: true },
175
- },
176
- data() { return { name: this.initialName, saving: false } },
177
- methods: {
178
- async save() {
179
- this.saving = true
180
- try {
181
- const result = await this.sendMessage('profile:save', { name: this.name })
182
- if (result?.saved) this.close(result)
183
- } finally {
184
- this.saving = false
185
- }
186
- },
187
- },
188
- }
189
- </script>
190
- ```
191
-
192
- ```js
193
- import ProfileEditor from './ProfileEditor.vue'
194
-
195
- export default {
196
- methods: {
197
- async editProfile() {
198
- const editor = this.$apple.dialog({
199
- title: '编辑资料',
200
- component: ProfileEditor,
201
- props: { initialName: '小明' },
202
- confirmText: '',
203
- cancelText: '取消',
204
- onMessage: async (channel, payload) => {
205
- if (channel !== 'profile:save') return
206
- const confirmation = this.$apple.dialog({
207
- title: '保存修改?',
208
- message: `将姓名更新为 ${payload.name}。`,
209
- })
210
- if (await confirmation.result !== true) return { saved: false }
211
- // 在这里执行实际业务请求;该示例只返回结果。
212
- return { saved: true, name: payload.name }
213
- },
214
- })
215
- const result = await editor.result
216
- if (result?.saved) this.$apple.notify('资料已保存', { tone: 'success' })
217
- },
218
- },
219
- }
220
- ```
221
-
222
- 通用消息总线也有真实的返回值通道,而不只是单向通知:
223
-
224
- ```js
225
- const unsubscribe = this.$apple.onMessage('profile:read', () => ({ name: '小明' }))
226
- const responses = this.$apple.sendMessage('profile:read')
227
- console.log(responses[0].name)
228
- unsubscribe()
229
- ```
230
-
231
- `sendMessage()` 同步调用监听器,返回所有监听器返回值组成的数组;异步监听器返回 Promise,可用 `Promise.all()` 等待。动态弹层的 `sendMessage()` 若有专属 `onMessage`,直接返回该回调结果;未设置时才回退到当前上下文消息总线。长期监听请在 `beforeUnmount` 中调用取消订阅函数。
232
-
233
- ## 通知与图片
234
-
235
- ```js
236
- const notice = this.$apple.notify('正在同步', { duration: 0 })
237
- notice.update({ message: '同步完成', tone: 'success', duration: 2500 })
238
- // 或 notice.close()
239
- ```
240
-
241
- 通知独立堆叠,默认 4 秒,`duration: 0` 常驻,悬停或键盘焦点进入时暂停倒计时。需要动作按钮时直接使用 `<apple-snackbar action="撤销" @action="undo" />`;命令式 `notify()` 当前没有 action 配置。
242
-
243
- ```vue
244
- <apple-image
245
- src="/images/workspace.webp"
246
- alt="桌面工作区"
247
- :gallery="['/images/workspace.webp', '/images/detail.webp']"
248
- :index="0"
249
- />
250
-
251
- <apple-image-viewer
252
- v-model="previewOpen"
253
- v-model:index="previewIndex"
254
- :images="[{ src: '/images/workspace.webp', alt: '桌面工作区' }]"
255
- loop
256
- />
75
+ ```sh
76
+ npm create apptify@latest ./my-app
77
+ cd my-app
78
+ npm install
79
+ npm run dev
257
80
  ```
258
81
 
259
- 示例图片路径需要替换为业务资源。`AppleImage` 默认支持点击预览,可用 `:preview="false"` 关闭。独立 Viewer 支持图库、缩放、拖动、旋转、触屏手势、键盘切换和有标签的工具按钮;核心图片交互由已有图库引擎处理。
260
-
261
- ## 移动端与边界
262
-
263
- - 弹层、抽屉、底部面板和通知考虑安全区;布局基于可用宽度,而不是把屏幕横竖方向等同于设备类型。
264
- - 提供下拉刷新、无限加载、侧滑操作、验证码、级联选择、ActionSheet 等组件,保留桌面按钮或键盘入口。
265
- - 日期、时间、颜色和基础 Select 使用浏览器原生选择能力;弹出界面随操作系统变化,不宣称它们在所有平台都长得完全一样。
266
- - Upload 负责本地文件选择、拖放与限制校验,不自动上传文件;Table 支持客户端排序、分页、固定行高虚拟滚动与列宽拖拽,不含服务端分页协议。
267
- - 导入阶段避免直接访问浏览器全局;这不等于已完成 SSR 全部组件的服务端渲染、hydration、跨请求隔离和主题首屏验证。SSR 接入时每个请求创建独立实例,并自行验证水合行为。
268
- - 本项目不是浏览器、屏幕阅读器和实体设备兼容矩阵认证。即使桌面/移动视口检查通过,也不代表已覆盖 iOS Safari、Android WebView、触控笔、软键盘与所有真机组合。
82
+ 也可运行 `npx --package=apptify apptify-playground ./my-app`。
269
83
 
270
- ## 从旧项目迁移
84
+ 目标目录需为空。模板含导航、设置、账号表单、404 和组件示例,可直接编辑;账号功能需接入自己的后端。复制项目携带库归档,可独立安装。页面开发与部署见[应用模板](docs/PLAYGROUND-TEMPLATE.md)。
271
85
 
272
- | 旧方式 | 新方式与差异 |
273
- | --- | --- |
274
- | `<apple-card title subtitle text icon icon-color>` | 保留这些属性与默认 slot,并增加 `media`、`title`、`icon`、`actions` slots。 |
275
- | `zoom="big/small/none"`、`shadow="normal/static/focused/none"` | 继续支持;新默认 `zoom="small"`,不保证旧尺寸和缩放数值完全一致。 |
276
- | `icon="mdi-home"` | 不再识别 MDI 字符串。导入 Lucide 组件并通过 `:icon="Home"` 传入;Card 的字符串 icon 被当作图片 URL。 |
277
- | `globalTheme` / `fancyAnimation` 模块常量 | 改用响应式 `theme.set()` / `motion.set()`;不需要刷新,也不要再直接读写旧 localStorage 键。 |
278
- | `sendMessage('showSnackbar', { type, text })` | 在 `this.$apple.sendMessage()` 或当前注入上下文上兼容;`showSnackBar`、`showMessage` 别名也保留。 |
279
- | `sendMessage('showDiag', { title, message })` | 仍可通过当前上下文发送;推荐使用返回独立句柄与 Promise 的 `dialog()`。 |
280
- | `btn: [{ bgColor, text, clickEvent }]` | **不直接兼容**。简单对话框用 `confirmText` / `cancelText`,复杂交互用声明式 `#footer` 或动态组件。 |
281
- | `sendMessage('closeDiag')` | 关闭当前上下文最上面的非通知弹层;不会一次关闭全部层。 |
282
- | `<e-img src squared gallery index>` | 改为 `<apple-image>`,并补上必需的 `alt`;不注册旧 `e-img` 名称。 |
283
-
284
- ## 验证命令
86
+ ## 本地开发
285
87
 
286
88
  ```sh
287
- npm run typecheck
288
- npm test
289
- npm run build
290
- npm run test:e2e
291
- npm run test:package
89
+ npm ci
90
+ npm run dev
292
91
  ```
293
92
 
294
- 命令是否通过以当前执行结果为准。`build` 生成组件库 `dist/`、类型声明与工作台 `site/`。源码中的行为测试不代替消费项目的业务测试与真机验证。
93
+ 建议 Node.js 22 或 24 LTS。检查使用 `npm run typecheck`、`npm test`、`npm run build`、`npm run test:e2e` 和 `npm run test:package`;`npm pack` 自动构建并准备模板。生成器位于 [`packages/create-apptify`](packages/create-apptify/README.md),使用 `npm run test:create` 验证。历史验证记录见[验证文档](docs/VALIDATION.md)。
94
+
95
+ MIT 许可。Apptify 不是 Apple 官方产品。