@weapp-vite/web 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ice breaker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # @weapp-vite/web
2
+
3
+ 实验性的 H5 运行时与工具集,为 `weapp-vite` 工程提供最小化的浏览器适配能力:
4
+
5
+ - 将 `wxml` 模板编译为渲染函数,并在 Web Components 中渲染
6
+ - 支持 `wx:if` / `wx:elif` / `wx:else`、`wx:for`、插值语法等常见语法糖
7
+ - 将小程序 `Page` / `Component` 映射为自定义元素,Shadow DOM 隔离样式与事件
8
+ - 事件桥接(如 `bindtap` → `click`),保留 `this.setData`、`this.triggerEvent` 等调用体验
9
+ - `wx.navigateTo` / `wx.navigateBack` / `getCurrentPages` 等路由 API,以及 `onLoad`、`onShow`、`onHide`、`onUnload` 生命周期
10
+ - `App` 级别的 `onLaunch` / `onShow` 回调、`getApp` 全局实例访问
11
+ - `wxss` → `css` 的基础转换,默认按 `1rpx = 0.5px`
12
+ - 提供 Vite 插件,自动把 `.wxml` / `.wxss` 转换为 Web 侧模块
13
+
14
+ > ⚠️ 当前阶段为 POC,功能与兼容性都较有限,只适合验证思路。
15
+
16
+ ## 快速开始
17
+
18
+ ```ts
19
+ import { defineComponent } from '@weapp-vite/web'
20
+ import template from './index.wxml'
21
+ import style from './index.wxss'
22
+
23
+ defineComponent('wv-hello-world', {
24
+ template,
25
+ style,
26
+ component: {
27
+ properties: {
28
+ title: { type: String, value: 'Hello weapp-vite' },
29
+ },
30
+ data: () => ({
31
+ description: '欢迎使用 weapp-vite 模板。',
32
+ }),
33
+ methods: {
34
+ copyLink(event) {
35
+ const url = event.currentTarget.dataset.url
36
+ this.setData({ url })
37
+ this.triggerEvent('copied', { url })
38
+ },
39
+ },
40
+ },
41
+ })
42
+
43
+ document.body.innerHTML = '<wv-hello-world title="文档地址"></wv-hello-world>'
44
+ ```
45
+
46
+ ## TODO
47
+
48
+ - 更全面的模板语法(`slot`、`wx:import` 等)
49
+ - 丰富组件属性系统、支持 behaviors / observers
50
+ - 全局 API 兼容层与更精细的样式适配
51
+ - SSR、SEO 友好的页面容器与首屏优化