@lytjs/core-vnode 6.0.0

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/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # @lytjs/core-vnode
2
+
3
+ > LytJS 核心应用 API(VNode 渲染模式),适合传统模板渲染场景
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @lytjs/core-vnode
9
+ ```
10
+
11
+ ## 与 @lytjs/core 的区别
12
+
13
+ | 特性 | @lytjs/core-vnode | @lytjs/core |
14
+ | -------- | ----------------- | --------------------- |
15
+ | 渲染模式 | 仅 VNode | VNode + Signal 双模式 |
16
+ | 包体积 | 更小 | 完整功能 |
17
+ | 适用场景 | 传统模板应用 | 需要双模式切换的应用 |
18
+
19
+ ## 核心 API
20
+
21
+ ### createApp
22
+
23
+ 创建 VNode 模式应用实例:
24
+
25
+ ```typescript
26
+ import { createApp, defineComponent, ref, h } from '@lytjs/core-vnode';
27
+
28
+ const App = defineComponent({
29
+ setup() {
30
+ const count = ref(0);
31
+
32
+ const increment = () => {
33
+ count.value++;
34
+ };
35
+
36
+ return () =>
37
+ h('div', [h('p', `Count: ${count.value}`), h('button', { onClick: increment }, 'Increment')]);
38
+ },
39
+ });
40
+
41
+ const app = createApp(App);
42
+ app.mount('#app');
43
+ ```
44
+
45
+ ### 使用模板
46
+
47
+ ```typescript
48
+ import { createApp, defineComponent, ref } from '@lytjs/core-vnode';
49
+
50
+ const App = defineComponent({
51
+ template: `
52
+ <div>
53
+ <p>Count: {{ count }}</p>
54
+ <button @click="increment">Increment</button>
55
+ </div>
56
+ `,
57
+ setup() {
58
+ const count = ref(0);
59
+ const increment = () => count.value++;
60
+ return { count, increment };
61
+ },
62
+ });
63
+
64
+ createApp(App).mount('#app');
65
+ ```
66
+
67
+ ### 生命周期钩子
68
+
69
+ ```typescript
70
+ import {
71
+ onMounted,
72
+ onUnmounted,
73
+ onUpdated,
74
+ onBeforeMount,
75
+ onBeforeUnmount,
76
+ onBeforeUpdate,
77
+ onErrorCaptured,
78
+ } from '@lytjs/core-vnode';
79
+
80
+ const App = defineComponent({
81
+ setup() {
82
+ onMounted(() => {
83
+ console.log('组件已挂载');
84
+ });
85
+
86
+ onUnmounted(() => {
87
+ console.log('组件已卸载');
88
+ });
89
+
90
+ onErrorCaptured((err, instance, info) => {
91
+ console.error('捕获到错误:', err, info);
92
+ return false; // 阻止错误传播
93
+ });
94
+ },
95
+ });
96
+ ```
97
+
98
+ ### 内置组件
99
+
100
+ ```typescript
101
+ import {
102
+ KeepAlive,
103
+ Suspense,
104
+ Transition,
105
+ TransitionGroup,
106
+ Teleport,
107
+ ErrorBoundary,
108
+ } from '@lytjs/core-vnode';
109
+
110
+ // KeepAlive 缓存组件
111
+ // Suspense 处理异步组件
112
+ // Transition/TransitionGroup 过渡动画
113
+ // Teleport 传送内容
114
+ // ErrorBoundary 错误边界
115
+ ```
116
+
117
+ ## 响应式 API
118
+
119
+ 从 @lytjs/reactivity 重导出:
120
+
121
+ ```typescript
122
+ import {
123
+ // 基础响应式
124
+ ref,
125
+ reactive,
126
+ computed,
127
+ watch,
128
+ watchEffect,
129
+ // 工具函数
130
+ toRef,
131
+ toRefs,
132
+ unref,
133
+ toValue,
134
+ // 类型守卫
135
+ isRef,
136
+ isReactive,
137
+ isReadonly,
138
+ isProxy,
139
+ } from '@lytjs/core-vnode';
140
+ ```
141
+
142
+ ## 组合式 API
143
+
144
+ ```typescript
145
+ import {
146
+ useSlots,
147
+ useAttrs,
148
+ useModel,
149
+ useTemplateRef,
150
+ useId,
151
+ useCssModule,
152
+ useCssVars,
153
+ } from '@lytjs/core-vnode';
154
+ ```
155
+
156
+ ## 类型定义
157
+
158
+ ```typescript
159
+ import type {
160
+ App,
161
+ AppConfig,
162
+ Component,
163
+ ComponentOptions,
164
+ ComponentPublicInstance,
165
+ VNode,
166
+ VNodeChildren,
167
+ } from '@lytjs/core-vnode';
168
+ ```
169
+
170
+ ## 相关包
171
+
172
+ - [@lytjs/core](../core) - 完整核心(支持双模式)
173
+ - [@lytjs/core-signal](../core-signal) - 仅 Signal 模式
174
+ - [@lytjs/vdom](../vdom) - 虚拟 DOM 实现