@lytjs/core 6.5.0 → 6.7.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 CHANGED
@@ -1,328 +1,328 @@
1
- # @lytjs/core
2
-
3
- > LytJS 框架核心入口,整合响应式、编译器、虚拟 DOM、渲染器和组件系统
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm install @lytjs/core
9
- ```
10
-
11
- ## 核心 API
12
-
13
- ### createApp
14
-
15
- 创建应用实例,挂载根组件
16
-
17
- ```typescript
18
- import { createApp, defineComponent } from '@lytjs/core';
19
-
20
- const RootComponent = defineComponent({
21
- setup() {
22
- const count = ref(0);
23
- return () => h('div', count.value);
24
- },
25
- });
26
-
27
- const app = createApp(RootComponent);
28
- app.mount('#app');
29
- ```
30
-
31
- ### h / createElement
32
-
33
- 创建虚拟节点(JSX 工厂函数)
34
-
35
- ```typescript
36
- import { h } from '@lytjs/core';
37
-
38
- // 创建元素
39
- const div = h('div', { class: 'container' }, 'Hello');
40
-
41
- // 创建组件
42
- const component = h(MyComponent, { prop: 'value' });
43
-
44
- // 嵌套子节点
45
- const nested = h('div', null, [h('span', null, 'Child 1'), h('span', null, 'Child 2')]);
46
- ```
47
-
48
- ### defineComponent / defineAsyncComponent
49
-
50
- 定义组件和异步组件
51
-
52
- ```typescript
53
- import { defineComponent, defineAsyncComponent } from '@lytjs/core';
54
-
55
- // 同步组件
56
- const MyComponent = defineComponent({
57
- name: 'MyComponent',
58
- props: {
59
- title: String,
60
- },
61
- setup(props) {
62
- return () => h('div', props.title);
63
- },
64
- });
65
-
66
- // 异步组件
67
- const AsyncComponent = defineAsyncComponent(() => import('./HeavyComponent.vue'));
68
- ```
69
-
70
- ### nextTick
71
-
72
- 在下一个 DOM 更新周期后执行回调
73
-
74
- ```typescript
75
- import { nextTick, ref } from '@lytjs/core';
76
-
77
- const count = ref(0);
78
- count.value++;
79
-
80
- // 等待 DOM 更新
81
- await nextTick();
82
- // 或使用回调
83
- nextTick(() => {
84
- console.log('DOM updated');
85
- });
86
- ```
87
-
88
- ## 响应式 API
89
-
90
- 从 @lytjs/reactivity 重导出
91
-
92
- ```typescript
93
- import {
94
- ref,
95
- reactive,
96
- shallowRef,
97
- shallowReactive,
98
- readonly,
99
- shallowReadonly,
100
- computed,
101
- watch,
102
- watchEffect,
103
- watchPostEffect,
104
- watchSyncEffect,
105
- effect,
106
- stop,
107
- toRef,
108
- toRefs,
109
- unref,
110
- toValue,
111
- customRef,
112
- isRef,
113
- isReactive,
114
- isReadonly,
115
- isProxy,
116
- toRaw,
117
- markRaw,
118
- triggerRef,
119
- provide,
120
- inject,
121
- // Signal API
122
- signal,
123
- computed as signalComputed,
124
- writableComputedSignal,
125
- readonlySignal,
126
- set,
127
- update,
128
- valueOf,
129
- signalBatch,
130
- signalUntrack,
131
- // 类型守卫
132
- isShallowRef,
133
- isComputedRef,
134
- } from '@lytjs/core';
135
- ```
136
-
137
- ## 生命周期钩子
138
-
139
- ```typescript
140
- import {
141
- onMounted,
142
- onUnmounted,
143
- onUpdated,
144
- onBeforeMount,
145
- onBeforeUpdate,
146
- onBeforeUnmount,
147
- onErrorCaptured,
148
- onActivated,
149
- onDeactivated,
150
- onRenderTracked,
151
- onRenderTriggered,
152
- } from '@lytjs/core';
153
- ```
154
-
155
- ## 编译 API
156
-
157
- 从 @lytjs/compiler 重导出
158
-
159
- ```typescript
160
- import { compile, parse, transform, generate } from '@lytjs/core';
161
-
162
- const { code, ast } = compile('<div>{{ message }}</div>');
163
- ```
164
-
165
- ## 内置组件
166
-
167
- ```typescript
168
- import {
169
- KeepAlive,
170
- Suspense,
171
- Transition,
172
- TransitionGroup,
173
- Teleport,
174
- ErrorBoundary,
175
- } from '@lytjs/core';
176
- ```
177
-
178
- ### KeepAlive
179
-
180
- 缓存非活动组件实例
181
-
182
- ```typescript
183
- import { KeepAlive, ref } from '@lytjs/core';
184
-
185
- const current = ref('ComponentA');
186
-
187
- <KeepAlive include="ComponentA,ComponentB" :max="10">
188
- <component :is="current" />
189
- </KeepAlive>
190
- ```
191
-
192
- ### Suspense
193
-
194
- 处理异步组件加载
195
-
196
- ```typescript
197
- import { Suspense, defineAsyncComponent } from '@lytjs/core';
198
-
199
- const AsyncComponent = defineAsyncComponent(() => import('./Heavy.vue'));
200
-
201
- <Suspense>
202
- <template #default>
203
- <AsyncComponent />
204
- </template>
205
- <template #fallback>
206
- <div>Loading...</div>
207
- </template>
208
- </Suspense>
209
- ```
210
-
211
- ### Transition / TransitionGroup
212
-
213
- 过渡动画
214
-
215
- ```typescript
216
- import { Transition, TransitionGroup } from '@lytjs/core';
217
-
218
- <Transition name="fade" mode="out-in">
219
- <div :key="id">Content</div>
220
- </Transition>
221
-
222
- <TransitionGroup name="list" tag="ul">
223
- <li v-for="item in items" :key="item.id">{{ item.name }}</li>
224
- </TransitionGroup>
225
- ```
226
-
227
- ### Teleport
228
-
229
- 传送内容到指定位置
230
-
231
- ```typescript
232
- import { Teleport } from '@lytjs/core';
233
-
234
- <Teleport to="body">
235
- <div class="modal">Modal content</div>
236
- </Teleport>
237
- ```
238
-
239
- ### ErrorBoundary
240
-
241
- 错误边界,捕获子组件错误
242
-
243
- ```typescript
244
- import { ErrorBoundary } from '@lytjs/core';
245
-
246
- <ErrorBoundary :on-error="handleError" :capture-promise-rejections="true">
247
- <MyComponent />
248
- <template #fallback="{ error }">
249
- <div>Error: {{ error?.message }}</div>
250
- </template>
251
- </ErrorBoundary>
252
- ```
253
-
254
- ## 渲染 API
255
-
256
- ```typescript
257
- import {
258
- createRenderer,
259
- createDOMRenderer,
260
- renderToString,
261
- renderToStream,
262
- createSignalRenderer,
263
- createVaporRenderer,
264
- createVaporApp,
265
- defineVaporComponent,
266
- } from '@lytjs/core';
267
- ```
268
-
269
- ## 工具函数
270
-
271
- ```typescript
272
- import {
273
- mergeProps,
274
- cloneVNode,
275
- normalizeClass,
276
- normalizeStyle,
277
- normalizeProps,
278
- } from '@lytjs/core';
279
- ```
280
-
281
- ## 类型定义
282
-
283
- ```typescript
284
- import type {
285
- // 组件类型
286
- ComponentOptions,
287
- ComponentPublicInstance,
288
- ComponentInternalInstance,
289
- SetupContext,
290
- PropOptions,
291
- // VNode 类型
292
- VNode,
293
- VNodeTypes,
294
- VNodeChildren,
295
- // 响应式类型
296
- Ref,
297
- ShallowRef,
298
- ComputedRef,
299
- ReactiveEffectRunner,
300
- WatchOptions,
301
- WatchCallback,
302
- WatchHandle,
303
- // 编译类型
304
- CompilerOptions,
305
- CodegenResult,
306
- // 渲染类型
307
- RendererOptions,
308
- RendererPlugin,
309
- } from '@lytjs/core';
310
- ```
311
-
312
- ## 子包
313
-
314
- @lytjs/core 整合以下子包:
315
-
316
- | 包名 | 说明 |
317
- | ---------------------------------- | ---------------- |
318
- | [@lytjs/reactivity](../reactivity) | 响应式系统 |
319
- | [@lytjs/vdom](../vdom) | 虚拟 DOM 实现 |
320
- | [@lytjs/compiler](../compiler) | 模板编译器 |
321
- | [@lytjs/renderer](../renderer) | DOM/SSR 渲染后端 |
322
- | [@lytjs/component](../component) | 组件系统 |
323
- | [@lytjs/common](../common) | 公共工具库 |
324
-
325
- ## 相关包
326
-
327
- - [@lytjs/adapter-web](../adapter-web) - Web 平台适配器
328
- - [@lytjs/host-contract](../host-contract) - 渲染器宿主抽象
1
+ # @lytjs/core
2
+
3
+ > LytJS 框架核心入口,整合响应式、编译器、虚拟 DOM、渲染器和组件系统
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @lytjs/core
9
+ ```
10
+
11
+ ## 核心 API
12
+
13
+ ### createApp
14
+
15
+ 创建应用实例,挂载根组件
16
+
17
+ ```typescript
18
+ import { createApp, defineComponent } from '@lytjs/core';
19
+
20
+ const RootComponent = defineComponent({
21
+ setup() {
22
+ const count = ref(0);
23
+ return () => h('div', count.value);
24
+ },
25
+ });
26
+
27
+ const app = createApp(RootComponent);
28
+ app.mount('#app');
29
+ ```
30
+
31
+ ### h / createElement
32
+
33
+ 创建虚拟节点(JSX 工厂函数)
34
+
35
+ ```typescript
36
+ import { h } from '@lytjs/core';
37
+
38
+ // 创建元素
39
+ const div = h('div', { class: 'container' }, 'Hello');
40
+
41
+ // 创建组件
42
+ const component = h(MyComponent, { prop: 'value' });
43
+
44
+ // 嵌套子节点
45
+ const nested = h('div', null, [h('span', null, 'Child 1'), h('span', null, 'Child 2')]);
46
+ ```
47
+
48
+ ### defineComponent / defineAsyncComponent
49
+
50
+ 定义组件和异步组件
51
+
52
+ ```typescript
53
+ import { defineComponent, defineAsyncComponent } from '@lytjs/core';
54
+
55
+ // 同步组件
56
+ const MyComponent = defineComponent({
57
+ name: 'MyComponent',
58
+ props: {
59
+ title: String,
60
+ },
61
+ setup(props) {
62
+ return () => h('div', props.title);
63
+ },
64
+ });
65
+
66
+ // 异步组件
67
+ const AsyncComponent = defineAsyncComponent(() => import('./HeavyComponent.vue'));
68
+ ```
69
+
70
+ ### nextTick
71
+
72
+ 在下一个 DOM 更新周期后执行回调
73
+
74
+ ```typescript
75
+ import { nextTick, ref } from '@lytjs/core';
76
+
77
+ const count = ref(0);
78
+ count.value++;
79
+
80
+ // 等待 DOM 更新
81
+ await nextTick();
82
+ // 或使用回调
83
+ nextTick(() => {
84
+ console.log('DOM updated');
85
+ });
86
+ ```
87
+
88
+ ## 响应式 API
89
+
90
+ 从 @lytjs/reactivity 重导出
91
+
92
+ ```typescript
93
+ import {
94
+ ref,
95
+ reactive,
96
+ shallowRef,
97
+ shallowReactive,
98
+ readonly,
99
+ shallowReadonly,
100
+ computed,
101
+ watch,
102
+ watchEffect,
103
+ watchPostEffect,
104
+ watchSyncEffect,
105
+ effect,
106
+ stop,
107
+ toRef,
108
+ toRefs,
109
+ unref,
110
+ toValue,
111
+ customRef,
112
+ isRef,
113
+ isReactive,
114
+ isReadonly,
115
+ isProxy,
116
+ toRaw,
117
+ markRaw,
118
+ triggerRef,
119
+ provide,
120
+ inject,
121
+ // Signal API
122
+ signal,
123
+ computed as signalComputed,
124
+ writableComputedSignal,
125
+ readonlySignal,
126
+ set,
127
+ update,
128
+ valueOf,
129
+ signalBatch,
130
+ signalUntrack,
131
+ // 类型守卫
132
+ isShallowRef,
133
+ isComputedRef,
134
+ } from '@lytjs/core';
135
+ ```
136
+
137
+ ## 生命周期钩子
138
+
139
+ ```typescript
140
+ import {
141
+ onMounted,
142
+ onUnmounted,
143
+ onUpdated,
144
+ onBeforeMount,
145
+ onBeforeUpdate,
146
+ onBeforeUnmount,
147
+ onErrorCaptured,
148
+ onActivated,
149
+ onDeactivated,
150
+ onRenderTracked,
151
+ onRenderTriggered,
152
+ } from '@lytjs/core';
153
+ ```
154
+
155
+ ## 编译 API
156
+
157
+ 从 @lytjs/compiler 重导出
158
+
159
+ ```typescript
160
+ import { compile, parse, transform, generate } from '@lytjs/core';
161
+
162
+ const { code, ast } = compile('<div>{{ message }}</div>');
163
+ ```
164
+
165
+ ## 内置组件
166
+
167
+ ```typescript
168
+ import {
169
+ KeepAlive,
170
+ Suspense,
171
+ Transition,
172
+ TransitionGroup,
173
+ Teleport,
174
+ ErrorBoundary,
175
+ } from '@lytjs/core';
176
+ ```
177
+
178
+ ### KeepAlive
179
+
180
+ 缓存非活动组件实例
181
+
182
+ ```typescript
183
+ import { KeepAlive, ref } from '@lytjs/core';
184
+
185
+ const current = ref('ComponentA');
186
+
187
+ <KeepAlive include="ComponentA,ComponentB" :max="10">
188
+ <component :is="current" />
189
+ </KeepAlive>
190
+ ```
191
+
192
+ ### Suspense
193
+
194
+ 处理异步组件加载
195
+
196
+ ```typescript
197
+ import { Suspense, defineAsyncComponent } from '@lytjs/core';
198
+
199
+ const AsyncComponent = defineAsyncComponent(() => import('./Heavy.vue'));
200
+
201
+ <Suspense>
202
+ <template #default>
203
+ <AsyncComponent />
204
+ </template>
205
+ <template #fallback>
206
+ <div>Loading...</div>
207
+ </template>
208
+ </Suspense>
209
+ ```
210
+
211
+ ### Transition / TransitionGroup
212
+
213
+ 过渡动画
214
+
215
+ ```typescript
216
+ import { Transition, TransitionGroup } from '@lytjs/core';
217
+
218
+ <Transition name="fade" mode="out-in">
219
+ <div :key="id">Content</div>
220
+ </Transition>
221
+
222
+ <TransitionGroup name="list" tag="ul">
223
+ <li v-for="item in items" :key="item.id">{{ item.name }}</li>
224
+ </TransitionGroup>
225
+ ```
226
+
227
+ ### Teleport
228
+
229
+ 传送内容到指定位置
230
+
231
+ ```typescript
232
+ import { Teleport } from '@lytjs/core';
233
+
234
+ <Teleport to="body">
235
+ <div class="modal">Modal content</div>
236
+ </Teleport>
237
+ ```
238
+
239
+ ### ErrorBoundary
240
+
241
+ 错误边界,捕获子组件错误
242
+
243
+ ```typescript
244
+ import { ErrorBoundary } from '@lytjs/core';
245
+
246
+ <ErrorBoundary :on-error="handleError" :capture-promise-rejections="true">
247
+ <MyComponent />
248
+ <template #fallback="{ error }">
249
+ <div>Error: {{ error?.message }}</div>
250
+ </template>
251
+ </ErrorBoundary>
252
+ ```
253
+
254
+ ## 渲染 API
255
+
256
+ ```typescript
257
+ import {
258
+ createRenderer,
259
+ createDOMRenderer,
260
+ renderToString,
261
+ renderToStream,
262
+ createSignalRenderer,
263
+ createVaporRenderer,
264
+ createVaporApp,
265
+ defineVaporComponent,
266
+ } from '@lytjs/core';
267
+ ```
268
+
269
+ ## 工具函数
270
+
271
+ ```typescript
272
+ import {
273
+ mergeProps,
274
+ cloneVNode,
275
+ normalizeClass,
276
+ normalizeStyle,
277
+ normalizeProps,
278
+ } from '@lytjs/core';
279
+ ```
280
+
281
+ ## 类型定义
282
+
283
+ ```typescript
284
+ import type {
285
+ // 组件类型
286
+ ComponentOptions,
287
+ ComponentPublicInstance,
288
+ ComponentInternalInstance,
289
+ SetupContext,
290
+ PropOptions,
291
+ // VNode 类型
292
+ VNode,
293
+ VNodeTypes,
294
+ VNodeChildren,
295
+ // 响应式类型
296
+ Ref,
297
+ ShallowRef,
298
+ ComputedRef,
299
+ ReactiveEffectRunner,
300
+ WatchOptions,
301
+ WatchCallback,
302
+ WatchHandle,
303
+ // 编译类型
304
+ CompilerOptions,
305
+ CodegenResult,
306
+ // 渲染类型
307
+ RendererOptions,
308
+ RendererPlugin,
309
+ } from '@lytjs/core';
310
+ ```
311
+
312
+ ## 子包
313
+
314
+ @lytjs/core 整合以下子包:
315
+
316
+ | 包名 | 说明 |
317
+ | ---------------------------------- | ---------------- |
318
+ | [@lytjs/reactivity](../reactivity) | 响应式系统 |
319
+ | [@lytjs/vdom](../vdom) | 虚拟 DOM 实现 |
320
+ | [@lytjs/compiler](../compiler) | 模板编译器 |
321
+ | [@lytjs/renderer](../renderer) | DOM/SSR 渲染后端 |
322
+ | [@lytjs/component](../component) | 组件系统 |
323
+ | [@lytjs/common](../common) | 公共工具库 |
324
+
325
+ ## 相关包
326
+
327
+ - [@lytjs/adapter-web](../adapter-web) - Web 平台适配器
328
+ - [@lytjs/host-contract](../host-contract) - 渲染器宿主抽象