@lytjs/renderer 3.1.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.
Files changed (48) hide show
  1. package/dist/index.cjs +8 -0
  2. package/dist/index.d.mts +5 -0
  3. package/dist/index.mjs +8 -0
  4. package/dist/types/create-renderer.d.ts +20 -0
  5. package/dist/types/create-renderer.d.ts.map +1 -0
  6. package/dist/types/dom/dom-ops.d.ts +74 -0
  7. package/dist/types/dom/dom-ops.d.ts.map +1 -0
  8. package/dist/types/dom/dom-renderer.d.ts +243 -0
  9. package/dist/types/dom/dom-renderer.d.ts.map +1 -0
  10. package/dist/types/dom/patch-events.d.ts +123 -0
  11. package/dist/types/dom/patch-events.d.ts.map +1 -0
  12. package/dist/types/dom/patch-props.d.ts +148 -0
  13. package/dist/types/dom/patch-props.d.ts.map +1 -0
  14. package/dist/types/index.d.ts +48 -0
  15. package/dist/types/index.d.ts.map +1 -0
  16. package/dist/types/miniapp/index.d.ts +6 -0
  17. package/dist/types/miniapp/index.d.ts.map +1 -0
  18. package/dist/types/miniapp/miniapp-renderer.d.ts +269 -0
  19. package/dist/types/miniapp/miniapp-renderer.d.ts.map +1 -0
  20. package/dist/types/mount.d.ts +32 -0
  21. package/dist/types/mount.d.ts.map +1 -0
  22. package/dist/types/native/index.d.ts +6 -0
  23. package/dist/types/native/index.d.ts.map +1 -0
  24. package/dist/types/native/native-renderer.d.ts +249 -0
  25. package/dist/types/native/native-renderer.d.ts.map +1 -0
  26. package/dist/types/patch.d.ts +23 -0
  27. package/dist/types/patch.d.ts.map +1 -0
  28. package/dist/types/props.d.ts +19 -0
  29. package/dist/types/props.d.ts.map +1 -0
  30. package/dist/types/renderer-interfaces.d.ts +157 -0
  31. package/dist/types/renderer-interfaces.d.ts.map +1 -0
  32. package/dist/types/ssr/hydration.d.ts +282 -0
  33. package/dist/types/ssr/hydration.d.ts.map +1 -0
  34. package/dist/types/ssr/ssr-renderer.d.ts +292 -0
  35. package/dist/types/ssr/ssr-renderer.d.ts.map +1 -0
  36. package/dist/types/unmount.d.ts +16 -0
  37. package/dist/types/unmount.d.ts.map +1 -0
  38. package/dist/types/vapor/vapor-compiler.d.ts +67 -0
  39. package/dist/types/vapor/vapor-compiler.d.ts.map +1 -0
  40. package/dist/types/vapor/vapor-component.d.ts +48 -0
  41. package/dist/types/vapor/vapor-component.d.ts.map +1 -0
  42. package/dist/types/vapor/vapor-reactive.d.ts +109 -0
  43. package/dist/types/vapor/vapor-reactive.d.ts.map +1 -0
  44. package/dist/types/vapor/vapor-renderer.d.ts +133 -0
  45. package/dist/types/vapor/vapor-renderer.d.ts.map +1 -0
  46. package/dist/types/vnode.d.ts +134 -0
  47. package/dist/types/vnode.d.ts.map +1 -0
  48. package/package.json +43 -0
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Lyt.js SSR 字符串渲染器
3
+ *
4
+ * 将 VNode 树渲染为 HTML 字符串,用于服务端渲染(SSR)场景。
5
+ * 纯原生零依赖实现,不依赖任何外部库。
6
+ *
7
+ * 核心功能:
8
+ * - renderToString(vnode) — 将 VNode 树同步序列化为完整 HTML 字符串
9
+ * - renderToStream(vnode, options?) — 将 VNode 树异步流式序列化(逐步输出 HTML)
10
+ * - createElement(tag) — 创建轻量描述对象(SSR 环境无真实 DOM)
11
+ * - createText(text) — 创建文本描述对象
12
+ * - insert(parent, child) — 将子节点添加到父节点的 children 数组
13
+ *
14
+ * 支持的 VNode 类型:
15
+ * - Element VNode:输出 HTML 标签 + 属性 + 子节点
16
+ * - Text VNode:输出转义后的文本内容
17
+ * - Comment VNode:输出 HTML 注释 <!-- -->
18
+ * - Fragment VNode:只输出子节点(无包裹标签)
19
+ * - Component VNode(函数式/有状态):递归渲染组件 render 函数输出
20
+ * - Slot VNode:渲染插槽内容
21
+ * - Null/Undefined:不输出任何内容
22
+ *
23
+ * 特殊处理:
24
+ * - class/style/event 属性的序列化
25
+ * - 自闭合标签(br/hr/img/input 等)
26
+ * - HTML 转义(防 XSS)
27
+ * - Fragment 多根节点支持
28
+ * - data-* 自定义属性
29
+ * - aria-* 无障碍属性
30
+ * - dangerouslySetInnerHTML 支持
31
+ * - Suspense 组件集成(流式渲染 fallback → resolved)
32
+ * - Islands Architecture(Partial Hydration)标记支持
33
+ */
34
+ /** SSR 轻量元素描述对象 */
35
+ export interface SSRVNode {
36
+ /** 标签名 */
37
+ tag: string;
38
+ /** 属性 */
39
+ props: Record<string, any>;
40
+ /** 子节点 */
41
+ children: (SSRVNode | SSRTextVNode)[];
42
+ }
43
+ /** SSR 文本描述对象 */
44
+ export interface SSRTextVNode {
45
+ /** 类型标记 */
46
+ type: 'text';
47
+ /** 文本内容 */
48
+ value: string;
49
+ }
50
+ /** VNode 兼容类型(与 @lytjs/vdom 和 @lytjs/renderer 的 VNode 对齐) */
51
+ export interface VNode {
52
+ type: string | object | symbol;
53
+ props: Record<string, any> | null;
54
+ children: string | VNode[] | Record<string, any> | null;
55
+ key: string | number | null;
56
+ ref: any;
57
+ shapeFlag: number;
58
+ patchFlag: number;
59
+ dynamicChildren: VNode[] | null;
60
+ dynamicProps: string[] | null;
61
+ component: any;
62
+ el: any;
63
+ anchor: any;
64
+ [key: string]: any;
65
+ }
66
+ /** 组件类型接口(有状态组件) */
67
+ export interface ComponentOptions {
68
+ /** 组件名称 */
69
+ name?: string;
70
+ /** setup 函数 */
71
+ setup?: (...args: any[]) => any;
72
+ /** render 函数 */
73
+ render?: (...args: any[]) => VNode;
74
+ /** props 定义 */
75
+ props?: Record<string, any>;
76
+ /** slots */
77
+ slots?: Record<string, any>;
78
+ /** 其他组件选项 */
79
+ [key: string]: any;
80
+ }
81
+ /** renderToStream 选项 */
82
+ export interface RenderToStreamOptions {
83
+ /** Suspense 边界 ID 前缀,默认 'suspense' */
84
+ suspenseIdPrefix?: string;
85
+ }
86
+ /**
87
+ * HTML 转义 — 将特殊字符替换为 HTML 实体
88
+ *
89
+ * 防止 XSS 攻击,确保用户输入的内容不会被当作 HTML 解析。
90
+ *
91
+ * @param str 需要转义的字符串
92
+ * @returns 转义后的安全字符串
93
+ *
94
+ * @example
95
+ * escapeHTML('<script>alert("xss")</script>')
96
+ * // → '&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;'
97
+ */
98
+ export declare function escapeHTML(str: string): string;
99
+ /**
100
+ * 序列化属性值为字符串
101
+ *
102
+ * 对不同类型的属性值进行特殊处理:
103
+ * - class:支持字符串、数组、对象形式
104
+ * - style:支持字符串、对象形式
105
+ * - 事件(on*):SSR 环境下不序列化事件
106
+ * - ref/key:内部属性,不序列化
107
+ * - innerHTML/dangerouslySetInnerHTML:特殊处理
108
+ * - data-* 属性:直接序列化
109
+ * - aria-* 属性:直接序列化
110
+ * - 布尔属性:值为 true 时只输出属性名
111
+ * - 其他:直接转为字符串
112
+ *
113
+ * @param key 属性名
114
+ * @param value 属性值
115
+ * @returns 序列化后的属性字符串(格式:key="value"),不需要序列化时返回空字符串
116
+ */
117
+ export declare function serializeProp(key: string, value: any): string;
118
+ /**
119
+ * 标准化 class 值
120
+ *
121
+ * 支持多种形式的 class 输入:
122
+ * - 字符串:'foo bar'
123
+ * - 数组:['foo', 'bar']
124
+ * - 对象:{ foo: true, bar: false }
125
+ * - 混合:['foo', { bar: true }]
126
+ *
127
+ * @param value class 值
128
+ * @returns 标准化后的 class 字符串
129
+ */
130
+ export declare function normalizeClass(value: any): string;
131
+ /**
132
+ * 标准化 style 值
133
+ *
134
+ * 支持两种形式的 style 输入:
135
+ * - 字符串:'color: red; font-size: 14px'
136
+ * - 对象:{ color: 'red', fontSize: '14px' }
137
+ *
138
+ * @param value style 值
139
+ * @returns 标准化后的 style 字符串
140
+ */
141
+ export declare function normalizeStyle(value: any): string;
142
+ /**
143
+ * 序列化所有属性
144
+ *
145
+ * 将 props 对象转换为 HTML 属性字符串
146
+ *
147
+ * @param props 属性对象
148
+ * @returns HTML 属性字符串(如 'class="foo" id="bar"')
149
+ */
150
+ export declare function serializeProps(props: Record<string, any> | null): string;
151
+ /**
152
+ * SSR 字符串渲染器
153
+ *
154
+ * 将 VNode 树渲染为 HTML 字符串。实现了 LytRenderer 接口的 SSR 版本。
155
+ * 在 SSR 环境中,没有真实 DOM,所有操作都是基于轻量描述对象。
156
+ *
157
+ * @example
158
+ * const renderer = new StringRenderer()
159
+ * const parent = renderer.createElement('div')
160
+ * const child = renderer.createText('Hello')
161
+ * renderer.insert(parent, child)
162
+ * // parent.children = [{ type: 'text', value: 'Hello' }]
163
+ */
164
+ export declare class StringRenderer {
165
+ /**
166
+ * 创建元素节点
167
+ *
168
+ * SSR 环境中没有真实 DOM,返回轻量描述对象。
169
+ *
170
+ * @param tag 标签名(如 'div', 'span')
171
+ * @returns 轻量元素描述对象
172
+ */
173
+ createElement(tag: string): SSRVNode;
174
+ /**
175
+ * 创建文本节点
176
+ *
177
+ * @param text 文本内容
178
+ * @returns 文本描述对象
179
+ */
180
+ createText(text: string): SSRTextVNode;
181
+ /**
182
+ * 创建注释节点
183
+ *
184
+ * SSR 中注释节点用文本描述对象表示
185
+ *
186
+ * @param text 注释内容
187
+ * @returns 注释描述对象
188
+ */
189
+ createComment(text: string): SSRTextVNode;
190
+ /**
191
+ * 插入子节点到父节点
192
+ *
193
+ * SSR 中简单地将子节点添加到父节点的 children 数组。
194
+ *
195
+ * @param parent 父节点
196
+ * @param child 子节点
197
+ * @param _ref 参考节点(SSR 中忽略)
198
+ */
199
+ insert(parent: SSRVNode, child: SSRVNode | SSRTextVNode, _ref?: any): void;
200
+ /**
201
+ * 将 VNode 渲染为 HTML 字符串(同步)
202
+ *
203
+ * 递归遍历 VNode 树,将每个节点序列化为对应的 HTML 字符串。
204
+ *
205
+ * @param vnode VNode 节点
206
+ * @returns 完整的 HTML 字符串
207
+ *
208
+ * @example
209
+ * const vnode = {
210
+ * type: 'div',
211
+ * props: { class: 'app', id: 'root' },
212
+ * children: [
213
+ * { type: 'span', props: null, children: 'Hello', shapeFlag: 8 },
214
+ * ],
215
+ * shapeFlag: 17, // ELEMENT | ARRAY_CHILDREN
216
+ * }
217
+ * renderToString(vnode)
218
+ * // → '<div class="app" id="root"><span>Hello</span></div>'
219
+ */
220
+ renderToString(vnode: VNode): string;
221
+ /**
222
+ * 将 VNode 渲染为异步生成器(流式渲染)
223
+ *
224
+ * 逐步输出 HTML 字符串片段,适用于大页面或需要尽早发送响应的场景。
225
+ * 每个节点渲染完成后立即 yield,而不是等待整棵树渲染完成。
226
+ *
227
+ * @param vnode VNode 节点
228
+ * @returns 异步生成器,逐步产出 HTML 字符串片段
229
+ *
230
+ * @example
231
+ * for await (const chunk of renderer.renderToStream(vnode)) {
232
+ * res.write(chunk)
233
+ * }
234
+ * res.end()
235
+ */
236
+ renderToStream(vnode: VNode): AsyncGenerator<string>;
237
+ }
238
+ /**
239
+ * 将 VNode 树渲染为完整 HTML 字符串(同步)
240
+ *
241
+ * 独立函数形式,方便直接调用而无需实例化 StringRenderer。
242
+ *
243
+ * @param vnode VNode 节点
244
+ * @returns 完整的 HTML 字符串
245
+ *
246
+ * @example
247
+ * const html = renderToString(vnode)
248
+ * // → '<div>Hello</div>'
249
+ */
250
+ export declare function renderToString(vnode: VNode): string;
251
+ /**
252
+ * 将 VNode 树异步流式渲染为 ReadableStream
253
+ *
254
+ * 返回一个 Node.js ReadableStream,逐步输出 HTML 字符串片段。
255
+ * 支持与 Suspense 集成:遇到 Suspense 边界时,先输出 fallback 内容,
256
+ * 异步组件解析完成后再输出真实内容(通过占位注释标记实现替换)。
257
+ *
258
+ * @param vnode VNode 节点
259
+ * @param options 流式渲染选项
260
+ * @returns ReadableStream<string>,逐步产出 HTML 字符串片段
261
+ *
262
+ * @example
263
+ * const stream = renderToStream(vnode)
264
+ * // 在 Node.js HTTP 响应中使用
265
+ * Readable.fromWeb(stream).pipe(res)
266
+ *
267
+ * // 或手动消费
268
+ * for await (const chunk of stream) {
269
+ * process.stdout.write(chunk)
270
+ * }
271
+ */
272
+ export declare function renderToStream(vnode: VNode, options?: RenderToStreamOptions): ReadableStream<string>;
273
+ /**
274
+ * 将 VNode 树异步流式渲染为异步生成器
275
+ *
276
+ * 与 renderToStream 类似,但返回 AsyncGenerator 而非 ReadableStream。
277
+ * 更轻量级,适合直接在 async 函数中使用 for-await-of 消费。
278
+ *
279
+ * @param vnode VNode 节点
280
+ * @param options 流式渲染选项
281
+ * @yields HTML 字符串片段
282
+ *
283
+ * @example
284
+ * for await (const chunk of renderToStreamGenerator(vnode)) {
285
+ * res.write(chunk)
286
+ * }
287
+ * res.end()
288
+ */
289
+ export declare function renderToStreamGenerator(vnode: VNode, options?: RenderToStreamOptions): AsyncGenerator<string>;
290
+ /** 默认渲染器实例 */
291
+ export declare const ssrRenderer: StringRenderer;
292
+ //# sourceMappingURL=ssr-renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr-renderer.d.ts","sourceRoot":"","sources":["../../../src/ssr/ssr-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAMH,mBAAmB;AACnB,MAAM,WAAW,QAAQ;IACvB,UAAU;IACV,GAAG,EAAE,MAAM,CAAA;IACX,SAAS;IACT,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1B,UAAU;IACV,QAAQ,EAAE,CAAC,QAAQ,GAAG,YAAY,CAAC,EAAE,CAAA;CACtC;AAED,iBAAiB;AACjB,MAAM,WAAW,YAAY;IAC3B,WAAW;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW;IACX,KAAK,EAAE,MAAM,CAAA;CACd;AAED,6DAA6D;AAC7D,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IACjC,QAAQ,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IA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,WAAW,gBAAuB,CAAA"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Lyt.js 渲染器 — 卸载逻辑
3
+ *
4
+ * 本模块包含 VNode 卸载相关的函数。
5
+ */
6
+ import type { LytRenderer } from './renderer-interfaces';
7
+ import type { VNode } from './vnode';
8
+ /**
9
+ * 卸载 VNode
10
+ */
11
+ export declare function unmount(renderer: LytRenderer, unmountFn: (vnode: VNode, container?: any) => void, vnode: VNode, container?: any): void;
12
+ /**
13
+ * 批量卸载子节点
14
+ */
15
+ export declare function unmountChildren(unmountFn: (vnode: VNode, container?: any) => void, children: VNode[]): void;
16
+ //# sourceMappingURL=unmount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unmount.d.ts","sourceRoot":"","sources":["../../src/unmount.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAGpC;;GAEG;AACH,wBAAgB,OAAO,CACrB,QAAQ,EAAE,WAAW,EACrB,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,KAAK,IAAI,EAClD,KAAK,EAAE,KAAK,EACZ,SAAS,CAAC,EAAE,GAAG,GACd,IAAI,CA4BN;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,KAAK,IAAI,EAClD,QAAQ,EAAE,KAAK,EAAE,GAChB,IAAI,CAIN"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Lyt.js Vapor Mode - 模板编译器
3
+ *
4
+ * 将 HTML 模板编译为直接 DOM 操作的渲染函数。
5
+ * 编译后的函数直接创建 DOM 元素并绑定信号,无需 VDOM 中间层。
6
+ *
7
+ * 支持的语法:
8
+ * - 文本插值: {{ expression }}
9
+ * - 事件绑定: on:event="handler"
10
+ * - 属性绑定: :prop="expression"
11
+ * - 条件渲染: v-if="expression"
12
+ * - 列表渲染: v-each="item in expression"
13
+ */
14
+ import type { VaporElement } from './vapor-reactive';
15
+ /** 编译后的渲染函数 */
16
+ export type VaporRenderFunction = (ctx: Record<string, any>) => VaporElement;
17
+ /** AST 节点类型 */
18
+ type ASTNodeType = 'element' | 'text' | 'interpolation' | 'fragment';
19
+ /** AST 节点 */
20
+ interface ASTNode {
21
+ type: ASTNodeType;
22
+ tag?: string;
23
+ text?: string;
24
+ expression?: string;
25
+ props?: Record<string, string>;
26
+ events?: Record<string, string>;
27
+ directives?: {
28
+ if?: string;
29
+ each?: {
30
+ item: string;
31
+ expression: string;
32
+ };
33
+ };
34
+ children?: ASTNode[];
35
+ }
36
+ /** 编译结果 */
37
+ export interface VaporCompileResult {
38
+ /** 渲染函数 */
39
+ render: VaporRenderFunction;
40
+ /** AST(调试用) */
41
+ ast: ASTNode;
42
+ }
43
+ /**
44
+ * 简单的 HTML 模板解析器
45
+ *
46
+ * 将模板字符串解析为 AST 树。
47
+ */
48
+ declare function parseTemplate(template: string): ASTNode;
49
+ /**
50
+ * 将 AST 节点编译为渲染函数
51
+ *
52
+ * @param template HTML 模板字符串
53
+ * @returns 编译结果
54
+ */
55
+ export declare function compileToVapor(template: string): VaporCompileResult;
56
+ /**
57
+ * 递归渲染 AST 节点为 DOM 元素
58
+ */
59
+ declare function renderASTNode(node: ASTNode, ctx: Record<string, any>, factory: (tag: string) => VaporElement): VaporElement;
60
+ /**
61
+ * 从上下文中解析表达式
62
+ *
63
+ * 支持简单属性访问和点号路径。
64
+ */
65
+ declare function resolveExpression(ctx: Record<string, any>, expression: string): any;
66
+ export { parseTemplate, renderASTNode, resolveExpression };
67
+ //# sourceMappingURL=vapor-compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vapor-compiler.d.ts","sourceRoot":"","sources":["../../../src/vapor/vapor-compiler.ts"],"names":[],"mappings":"AAAA;;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KAAK,YAAY,GACrC,YAAY,CAiId;AAED;;;;GAIG;AACH,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,GAAG,CAwB5E;AAMD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAA"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Lyt.js Vapor Mode - 组件系统
3
+ *
4
+ * 提供 Vapor Mode 的组件定义和 App 创建功能。
5
+ * 与标准 defineComponent 类似,但使用 Vapor 渲染器(无 VDOM)。
6
+ */
7
+ import type { VaporComponentOptions, VaporApp } from './vapor-renderer';
8
+ import type { VaporElement } from './vapor-reactive';
9
+ /** Vapor 组件实例 */
10
+ export interface VaporComponentInstance {
11
+ /** 组件选项 */
12
+ options: VaporComponentOptions;
13
+ /** 组件上下文(setup 返回值) */
14
+ ctx: Record<string, any>;
15
+ /** 根 DOM 元素 */
16
+ el: VaporElement | null;
17
+ /** 是否已挂载 */
18
+ isMounted: boolean;
19
+ /** 卸载函数 */
20
+ _unmount?: () => void;
21
+ }
22
+ /**
23
+ * 定义 Vapor 组件
24
+ *
25
+ * 与 defineComponent 类似,但使用 Vapor Mode 渲染。
26
+ * 不创建 VDOM,直接操作 DOM。
27
+ *
28
+ * @param options 组件选项
29
+ * @returns 组件构造函数
30
+ */
31
+ export declare function defineVaporComponent(options: VaporComponentOptions): VaporComponentOptions;
32
+ /**
33
+ * 创建 Vapor Mode 应用
34
+ *
35
+ * 类似 createApp,但使用 Vapor 渲染器。
36
+ *
37
+ * @param rootComponent 根组件选项
38
+ * @returns VaporApp 实例
39
+ */
40
+ export declare function createVaporApp(rootComponent: VaporComponentOptions): VaporApp;
41
+ /**
42
+ * 渲染 Vapor 组件为 DOM 元素
43
+ *
44
+ * @param component 组件选项
45
+ * @returns 渲染后的 DOM 元素
46
+ */
47
+ export declare function renderVaporComponent(component: VaporComponentOptions): VaporElement;
48
+ //# sourceMappingURL=vapor-component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vapor-component.d.ts","sourceRoot":"","sources":["../../../src/vapor/vapor-component.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAa,qBAAqB,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAA;AAElG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAOpD,iBAAiB;AACjB,MAAM,WAAW,sBAAsB;IACrC,WAAW;IACX,OAAO,EAAE,qBAAqB,CAAA;IAC9B,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACxB,eAAe;IACf,EAAE,EAAE,YAAY,GAAG,IAAI,CAAA;IACvB,YAAY;IACZ,SAAS,EAAE,OAAO,CAAA;IAClB,WAAW;IACX,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AAMD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,qBAAqB,CAE1F;AAMD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,qBAAqB,GAAG,QAAQ,CAoD7E;AAMD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,qBAAqB,GAAG,YAAY,CAgCnF"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Lyt.js Vapor Mode - 响应式绑定
3
+ *
4
+ * 在 Vapor Mode 中,响应式信号直接绑定到 DOM 属性上,
5
+ * 无需虚拟 DOM 中间层。当信号值变化时,直接更新对应的 DOM 节点。
6
+ *
7
+ * 每个绑定函数返回一个清理函数,用于在卸载时取消订阅。
8
+ */
9
+ import type { Signal } from '@lytjs/reactivity/signal';
10
+ /** DOM 元素接口(兼容真实 DOM 和 Mock DOM) */
11
+ export interface VaporElement {
12
+ tagName: string;
13
+ nodeType: number;
14
+ textContent: string;
15
+ className: string;
16
+ childNodes: VaporElement[];
17
+ parentNode: VaporElement | null;
18
+ style: Record<string, string> | CSSStyleDeclaration;
19
+ setAttribute(key: string, value: string): void;
20
+ removeAttribute(key: string): void;
21
+ addEventListener(event: string, handler: Function): void;
22
+ removeEventListener(event: string, handler: Function): void;
23
+ appendChild(child: VaporElement): void;
24
+ insertBefore(child: VaporElement, ref: VaporElement | null): void;
25
+ removeChild(child: VaporElement): void;
26
+ nextSibling: VaporElement | null;
27
+ firstChild: VaporElement | null;
28
+ innerHTML?: string;
29
+ hidden?: boolean;
30
+ value?: string;
31
+ checked?: boolean;
32
+ disabled?: boolean;
33
+ [key: string]: any;
34
+ }
35
+ /** 绑定清理函数 */
36
+ export type BindingCleanup = () => void;
37
+ /**
38
+ * 将信号值绑定到元素的 textContent
39
+ *
40
+ * @param el 目标 DOM 元素
41
+ * @param sig 响应式信号
42
+ * @returns 清理函数
43
+ */
44
+ export declare function bindText(el: VaporElement, sig: Signal<any>): BindingCleanup;
45
+ /**
46
+ * 将信号值绑定到元素的 DOM 属性(如 value, checked, disabled 等)
47
+ *
48
+ * @param el 目标 DOM 元素
49
+ * @param prop 属性名
50
+ * @param sig 响应式信号
51
+ * @returns 清理函数
52
+ */
53
+ export declare function bindProp(el: VaporElement, prop: string, sig: Signal<any>): BindingCleanup;
54
+ /**
55
+ * 将信号值绑定到元素的 HTML 属性(通过 setAttribute)
56
+ *
57
+ * @param el 目标 DOM 元素
58
+ * @param attr 属性名
59
+ * @param sig 响应式信号
60
+ * @returns 清理函数
61
+ */
62
+ export declare function bindAttr(el: VaporElement, attr: string, sig: Signal<any>): BindingCleanup;
63
+ /**
64
+ * 将信号值绑定到元素的 className
65
+ *
66
+ * 支持三种形式:
67
+ * - 字符串:直接设置为 className
68
+ * - 对象:{ active: true, disabled: false } -> "active"
69
+ * - 数组:["class-a", "class-b"] -> "class-a class-b"
70
+ *
71
+ * @param el 目标 DOM 元素
72
+ * @param sig 响应式信号
73
+ * @returns 清理函数
74
+ */
75
+ export declare function bindClass(el: VaporElement, sig: Signal<any>): BindingCleanup;
76
+ /**
77
+ * 将事件处理器绑定到元素
78
+ *
79
+ * @param el 目标 DOM 元素
80
+ * @param event 事件名
81
+ * @param handler 事件处理函数
82
+ * @returns 清理函数
83
+ */
84
+ export declare function bindEvent(el: VaporElement, event: string, handler: Function): BindingCleanup;
85
+ /**
86
+ * 根据信号值控制元素的显示/隐藏
87
+ *
88
+ * 当信号值为真值时显示元素,假值时隐藏元素。
89
+ * 使用 display: none 方式隐藏,保留 DOM 结构。
90
+ *
91
+ * @param el 目标 DOM 元素
92
+ * @param sig 响应式信号
93
+ * @returns 清理函数
94
+ */
95
+ export declare function bindIf(el: VaporElement, sig: Signal<any>): BindingCleanup;
96
+ /**
97
+ * 根据信号数组渲染列表
98
+ *
99
+ * 当数组变化时,智能 diff 并更新 DOM。
100
+ * 使用 key 进行高效的增删改操作。
101
+ *
102
+ * @param container 容器元素
103
+ * @param sig 响应式信号(返回数组)
104
+ * @param renderItem 渲染单项的函数,接收 (item, index) 返回 VaporElement
105
+ * @param keyFn 可选的 key 提取函数,用于高效 diff
106
+ * @returns 清理函数
107
+ */
108
+ export declare function bindEach<T>(container: VaporElement, sig: Signal<T[]>, renderItem: (item: T, index: number) => VaporElement, keyFn?: (item: T, index: number) => string | number): BindingCleanup;
109
+ //# sourceMappingURL=vapor-reactive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vapor-reactive.d.ts","sourceRoot":"","sources":["../../../src/vapor/vapor-reactive.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAOtD,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,YAAY,EAAE,CAAA;IAC1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